[Draft] Cleanup splitted annotatation objects
- corrected super() methods to be Py2 compatible - further cleanup of the code. further cleanup changed again to avoid super method updated super() functions updated to correct the parent classess targeted by super()
This commit is contained in:
committed by
Yorik van Havre
parent
0745f760a0
commit
131961c2a8
@@ -22,7 +22,6 @@
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
"""This module provides the object code for Draft Dimension.
|
||||
"""
|
||||
## @package dimension
|
||||
@@ -167,9 +166,10 @@ class DimensionBase(DraftAnnotation):
|
||||
"""
|
||||
|
||||
def __init__(self, obj, tp = "Dimension"):
|
||||
"Initialize common properties for dimension objects"
|
||||
DraftAnnotation.__init__(self,obj, tp)
|
||||
"""Add common dimension properties to the object and set them"""
|
||||
|
||||
super(DimensionBase, self).__init__(obj, tp)
|
||||
|
||||
# Draft
|
||||
obj.addProperty("App::PropertyVector",
|
||||
"Normal",
|
||||
@@ -195,17 +195,22 @@ class DimensionBase(DraftAnnotation):
|
||||
QT_TRANSLATE_NOOP("App::Property",
|
||||
"Point on which the dimension \n"
|
||||
"line is placed."))
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
|
||||
return
|
||||
|
||||
obj.Dimline = App.Vector(0,1,0)
|
||||
obj.Normal = App.Vector(0,0,1)
|
||||
|
||||
|
||||
def execute(self, obj):
|
||||
'''Do something when recompute object'''
|
||||
|
||||
return
|
||||
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
'''Do something when a property has changed'''
|
||||
|
||||
return
|
||||
|
||||
|
||||
class LinearDimension(DimensionBase):
|
||||
"""
|
||||
@@ -213,8 +218,17 @@ class LinearDimension(DimensionBase):
|
||||
"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super().__init__(obj, "Dimension")
|
||||
|
||||
|
||||
super(LinearDimension, self).__init__(obj, "LinearDimension")
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
self.init_properties(obj)
|
||||
|
||||
|
||||
def init_properties(self, obj):
|
||||
"""Add Linear Dimension specific properties to the object and set them"""
|
||||
|
||||
# Draft
|
||||
obj.addProperty("App::PropertyVectorDistance",
|
||||
"Start",
|
||||
@@ -248,10 +262,9 @@ class LinearDimension(DimensionBase):
|
||||
|
||||
obj.Start = App.Vector(0,0,0)
|
||||
obj.End = App.Vector(1,0,0)
|
||||
obj.Dimline = App.Vector(0,1,0)
|
||||
obj.Normal = App.Vector(0,0,1)
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
'''Do something when a property has changed'''
|
||||
if hasattr(obj, "Distance"):
|
||||
obj.setEditorMode('Distance', 1)
|
||||
#if hasattr(obj,"Normal"):
|
||||
@@ -261,7 +274,7 @@ class LinearDimension(DimensionBase):
|
||||
|
||||
|
||||
def execute(self, obj):
|
||||
# set start point and end point according to the linked geometry
|
||||
""" Set start point and end point according to the linked geometry"""
|
||||
if obj.LinkedGeometry:
|
||||
if len(obj.LinkedGeometry) == 1:
|
||||
lobj = obj.LinkedGeometry[0][0]
|
||||
@@ -324,7 +337,15 @@ class AngularDimension(DimensionBase):
|
||||
|
||||
def __init__(self, obj):
|
||||
|
||||
super().__init__(obj,"AngularDimension")
|
||||
super(AngularDimension, self).__init__(obj, "AngularDimension")
|
||||
|
||||
self.init_properties(obj)
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
|
||||
def init_properties(self, obj):
|
||||
"""Add Angular Dimension specific properties to the object and set them"""
|
||||
|
||||
obj.addProperty("App::PropertyAngle",
|
||||
"FirstAngle",
|
||||
@@ -356,7 +377,15 @@ class AngularDimension(DimensionBase):
|
||||
obj.Center = App.Vector(0,0,0)
|
||||
obj.Normal = App.Vector(0,0,1)
|
||||
|
||||
|
||||
def execute(self, fp):
|
||||
'''Do something when recompute object'''
|
||||
if fp.ViewObject:
|
||||
fp.ViewObject.update()
|
||||
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
'''Do something when a property has changed'''
|
||||
super().onChanged(obj, prop)
|
||||
if hasattr(obj,"Angle"):
|
||||
obj.setEditorMode('Angle',1)
|
||||
@@ -365,6 +394,4 @@ class AngularDimension(DimensionBase):
|
||||
if hasattr(obj,"Support"):
|
||||
obj.setEditorMode('Support',2)
|
||||
|
||||
def execute(self, fp):
|
||||
if fp.ViewObject:
|
||||
fp.ViewObject.update()
|
||||
|
||||
|
||||
@@ -31,57 +31,34 @@ import FreeCAD as App
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
from draftutils import gui_utils
|
||||
|
||||
class DraftAnnotation:
|
||||
class DraftAnnotation(object):
|
||||
"""The Draft Annotation Base object
|
||||
This class is not used directly, but inherited by all annotation
|
||||
objects.
|
||||
"""
|
||||
def __init__(self, obj, tp="Unknown"):
|
||||
if obj:
|
||||
obj.Proxy = self
|
||||
def __init__(self, obj, tp="Annotation"):
|
||||
"""Add general Annotation properties to the object"""
|
||||
|
||||
self.Type = tp
|
||||
|
||||
|
||||
def __getstate__(self):
|
||||
return self.Type
|
||||
|
||||
|
||||
def __setstate__(self,state):
|
||||
if state:
|
||||
self.Type = state
|
||||
|
||||
|
||||
def execute(self,obj):
|
||||
pass
|
||||
'''Do something when recompute object'''
|
||||
|
||||
return
|
||||
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
pass
|
||||
|
||||
class StylesContainerBase:
|
||||
"""The Base class for Annotation Containers"""
|
||||
|
||||
def __init__(self, obj, tp = "AnnotationContainer"):
|
||||
|
||||
self.Type = tp
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, obj):
|
||||
|
||||
g = obj.Group
|
||||
g.sort(key=lambda o: o.Label)
|
||||
obj.Group = g
|
||||
|
||||
def make_unique_visible(self, obj, active_style):
|
||||
"turn non visible all the concurrent styles"
|
||||
if hasattr(active_style, "Visibility"):
|
||||
for o in obj.Group:
|
||||
if o.Name != active_style.Name:
|
||||
if hasattr(o, "Visibility"):
|
||||
o.Visibility = False
|
||||
|
||||
|
||||
class AnnotationStylesContainer(StylesContainerBase):
|
||||
"""The Annotation Container"""
|
||||
|
||||
def __init__(self, obj):
|
||||
|
||||
self.Type = "AnnotationContainer"
|
||||
obj.Proxy = self
|
||||
'''Do something when a property has changed'''
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -106,9 +106,17 @@ def make_label(targetpoint=None, target=None, direction=None,
|
||||
class Label(DraftAnnotation):
|
||||
"""The Draft Label object"""
|
||||
|
||||
def __init__(self,obj):
|
||||
def __init__(self, obj):
|
||||
|
||||
super().__init__(obj, "Label")
|
||||
super(Label, self).__init__(obj, "Label")
|
||||
|
||||
self.init_properties(obj)
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
|
||||
def init_properties(self, obj):
|
||||
"""Add properties to the object and set them"""
|
||||
|
||||
obj.addProperty("App::PropertyPlacement",
|
||||
"Placement",
|
||||
@@ -174,6 +182,7 @@ class Label(DraftAnnotation):
|
||||
|
||||
|
||||
def execute(self,obj):
|
||||
'''Do something when recompute object'''
|
||||
|
||||
if obj.StraightDirection != "Custom":
|
||||
p1 = obj.Placement.Base
|
||||
@@ -223,12 +232,8 @@ class Label(DraftAnnotation):
|
||||
if hasattr(obj.Target[0].Shape,"Volume"):
|
||||
obj.Text = [App.Units.Quantity(obj.Target[0].Shape.Volume,App.Units.Volume).UserString.replace("^3","³")]
|
||||
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
pass
|
||||
'''Do something when a property has changed'''
|
||||
|
||||
def __getstate__(self):
|
||||
return self.Type
|
||||
|
||||
def __setstate__(self,state):
|
||||
if state:
|
||||
self.Type = state
|
||||
return
|
||||
@@ -42,7 +42,7 @@ if App.GuiUp:
|
||||
|
||||
|
||||
def make_text(stringslist, point=App.Vector(0,0,0), screen=False):
|
||||
"""makeText(strings,[point],[screen])
|
||||
"""makeText(strings, point, screen)
|
||||
|
||||
Creates a Text object containing the given strings.
|
||||
The current color and text height and font
|
||||
@@ -51,22 +51,24 @@ def make_text(stringslist, point=App.Vector(0,0,0), screen=False):
|
||||
Parameters
|
||||
----------
|
||||
stringlist : List
|
||||
Given list of strings, one string by line (strings can also
|
||||
be one single string)
|
||||
Given list of strings, one string by line (strings can also
|
||||
be one single string)
|
||||
|
||||
point : App::Vector
|
||||
|
||||
insert point of the text
|
||||
|
||||
screen : Bool
|
||||
If screen is True, the text always faces the view direction.
|
||||
If screen is True, the text always faces the view direction.
|
||||
|
||||
"""
|
||||
|
||||
if not App.ActiveDocument:
|
||||
App.Console.PrintError("No active document. Aborting\n")
|
||||
return
|
||||
|
||||
utils.type_check([(point, App.Vector)], "makeText")
|
||||
if not isinstance(stringslist,list): stringslist = [stringslist]
|
||||
|
||||
obj = App.ActiveDocument.addObject("App::FeaturePython","Text")
|
||||
Text(obj)
|
||||
obj.Text = stringslist
|
||||
@@ -92,9 +94,17 @@ def make_text(stringslist, point=App.Vector(0,0,0), screen=False):
|
||||
class Text(DraftAnnotation):
|
||||
"""The Draft Text object"""
|
||||
|
||||
def __init__(self,obj):
|
||||
def __init__(self, obj):
|
||||
|
||||
super().__init__(obj, "Text")
|
||||
super(Text, self).__init__(obj, "Text")
|
||||
|
||||
self.init_properties(obj)
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
|
||||
def init_properties(self, obj):
|
||||
"""Add Text specific properties to the object and set them"""
|
||||
|
||||
obj.addProperty("App::PropertyPlacement",
|
||||
"Placement",
|
||||
@@ -108,6 +118,14 @@ class Text(DraftAnnotation):
|
||||
QT_TRANSLATE_NOOP("App::Property",
|
||||
"The text displayed by this object"))
|
||||
|
||||
def execute(self,obj):
|
||||
|
||||
pass
|
||||
def execute(self,obj):
|
||||
'''Do something when recompute object'''
|
||||
|
||||
return
|
||||
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
'''Do something when a property has changed'''
|
||||
|
||||
return
|
||||
|
||||
@@ -87,6 +87,8 @@ class ViewProviderDimensionBase(ViewProviderDraftAnnotation):
|
||||
"""
|
||||
def __init__(self, vobj):
|
||||
|
||||
super(ViewProviderDimensionBase, self).__init__(vobj)
|
||||
|
||||
# text properties
|
||||
vobj.addProperty("App::PropertyFont","FontName",
|
||||
"Text",
|
||||
@@ -171,12 +173,6 @@ class ViewProviderDimensionBase(ViewProviderDraftAnnotation):
|
||||
vobj.ShowUnit = utils.get_param("showUnit",True)
|
||||
vobj.ShowLine = True
|
||||
|
||||
super().__init__(vobj)
|
||||
|
||||
def attach(self, vobj):
|
||||
"""called on object creation"""
|
||||
return
|
||||
|
||||
def updateData(self, obj, prop):
|
||||
"""called when the base object is changed"""
|
||||
return
|
||||
@@ -219,11 +215,16 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
|
||||
"""
|
||||
A View Provider for the Draft Linear Dimension object
|
||||
"""
|
||||
def __init__(self, vobj):
|
||||
super().__init__(vobj)
|
||||
def __init__(self, vobj):
|
||||
|
||||
super(ViewProviderLinearDimension, self).__init__(vobj)
|
||||
|
||||
self.Object = vobj.Object
|
||||
vobj.Proxy = self
|
||||
|
||||
|
||||
def attach(self, vobj):
|
||||
"""called on object creation"""
|
||||
'''Setup the scene sub-graph of the view provider'''
|
||||
self.Object = vobj.Object
|
||||
self.color = coin.SoBaseColor()
|
||||
self.font = coin.SoFont()
|
||||
@@ -664,13 +665,17 @@ class ViewProviderAngularDimension(ViewProviderDimensionBase):
|
||||
"""A View Provider for the Draft Angular Dimension object"""
|
||||
def __init__(self, vobj):
|
||||
|
||||
super(ViewProviderAngularDimension, self).__init__(vobj)
|
||||
|
||||
vobj.addProperty("App::PropertyBool","FlipArrows",
|
||||
"Graphics",QT_TRANSLATE_NOOP("App::Property",
|
||||
"Rotate the dimension arrows 180 degrees"))
|
||||
|
||||
super().__init__(vobj)
|
||||
self.Object = vobj.Object
|
||||
vobj.Proxy = self
|
||||
|
||||
def attach(self, vobj):
|
||||
'''Setup the scene sub-graph of the view provider'''
|
||||
from pivy import coin
|
||||
self.Object = vobj.Object
|
||||
self.color = coin.SoBaseColor()
|
||||
|
||||
@@ -32,46 +32,8 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
if App.GuiUp:
|
||||
import FreeCADGui as Gui
|
||||
|
||||
class ViewProviderStylesContainerBase:
|
||||
"""A Base View Provider for Annotation Styles Containers"""
|
||||
|
||||
def __init__(self, vobj):
|
||||
|
||||
vobj.Proxy = self
|
||||
|
||||
def getIcon(self):
|
||||
|
||||
return ":/icons/Draft_Annotation_Style.svg"
|
||||
|
||||
def attach(self, vobj):
|
||||
|
||||
self.Object = vobj.Object
|
||||
|
||||
def __getstate__(self):
|
||||
|
||||
return None
|
||||
|
||||
def __setstate__(self, state):
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class ViewProviderAnnotationStylesContainer(ViewProviderStylesContainerBase):
|
||||
"""A View Provider for the Annotation Styles Container"""
|
||||
|
||||
def __init__(self, vobj):
|
||||
super().__init__(vobj)
|
||||
|
||||
def getIcon(self):
|
||||
|
||||
return ":/icons/Draft_Annotation_Style.svg"
|
||||
|
||||
def attach(self, vobj):
|
||||
|
||||
self.Object = vobj.Object
|
||||
|
||||
|
||||
class ViewProviderDraftAnnotation:
|
||||
class ViewProviderDraftAnnotation(object):
|
||||
"""
|
||||
The base class for Draft Annotation Viewproviders
|
||||
This class is not used directly, but inherited by all annotation
|
||||
@@ -79,8 +41,8 @@ class ViewProviderDraftAnnotation:
|
||||
"""
|
||||
|
||||
def __init__(self, vobj):
|
||||
vobj.Proxy = self
|
||||
self.Object = vobj.Object
|
||||
#vobj.Proxy = self
|
||||
#self.Object = vobj.Object
|
||||
|
||||
# annotation properties
|
||||
vobj.addProperty("App::PropertyFloat","ScaleMultiplier",
|
||||
@@ -95,7 +57,8 @@ class ViewProviderDraftAnnotation:
|
||||
|
||||
param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||
annotation_scale = param.GetFloat("DraftAnnotationScale", 1.0)
|
||||
vobj.ScaleMultiplier = 1 / annotation_scale
|
||||
if annotation_scale != 0:
|
||||
vobj.ScaleMultiplier = 1 / annotation_scale
|
||||
|
||||
|
||||
def __getstate__(self):
|
||||
|
||||
@@ -46,7 +46,14 @@ class ViewProviderLabel(ViewProviderDraftAnnotation):
|
||||
|
||||
def __init__(self,vobj):
|
||||
|
||||
super().__init__(vobj)
|
||||
super(ViewProviderLabel, self).__init__(vobj)
|
||||
|
||||
self.set_properties(vobj)
|
||||
|
||||
self.Object = vobj.Object
|
||||
vobj.Proxy = self
|
||||
|
||||
def set_properties(self, vobj):
|
||||
|
||||
# Text properties
|
||||
|
||||
@@ -96,7 +103,6 @@ class ViewProviderLabel(ViewProviderDraftAnnotation):
|
||||
"Graphics",QT_TRANSLATE_NOOP("App::Property",
|
||||
"Line color"))
|
||||
|
||||
vobj.Proxy = self
|
||||
self.Object = vobj.Object
|
||||
vobj.TextAlignment = ["Top","Middle","Bottom"]
|
||||
vobj.TextAlignment = "Middle"
|
||||
@@ -120,6 +126,7 @@ class ViewProviderLabel(ViewProviderDraftAnnotation):
|
||||
return []
|
||||
|
||||
def attach(self,vobj):
|
||||
'''Setup the scene sub-graph of the view provider'''
|
||||
self.arrow = coin.SoSeparator()
|
||||
self.arrowpos = coin.SoTransform()
|
||||
self.arrow.addChild(self.arrowpos)
|
||||
|
||||
@@ -41,9 +41,18 @@ from draftviewproviders.view_draft_annotation import ViewProviderDraftAnnotation
|
||||
class ViewProviderText(ViewProviderDraftAnnotation):
|
||||
"""A View Provider for the Draft Text annotation"""
|
||||
|
||||
|
||||
def __init__(self,vobj):
|
||||
|
||||
super().__init__(vobj)
|
||||
super(ViewProviderText, self).__init__(vobj)
|
||||
|
||||
self.set_properties(vobj)
|
||||
|
||||
self.Object = vobj.Object
|
||||
vobj.Proxy = self
|
||||
|
||||
|
||||
def set_properties(self, vobj):
|
||||
|
||||
vobj.addProperty("App::PropertyFloat","ScaleMultiplier",
|
||||
"Annotation",QT_TRANSLATE_NOOP("App::Property",
|
||||
@@ -73,13 +82,17 @@ class ViewProviderText(ViewProviderDraftAnnotation):
|
||||
vobj.FontName = utils.get_param("textfont","sans")
|
||||
vobj.FontSize = utils.get_param("textheight",1)
|
||||
|
||||
|
||||
def getIcon(self):
|
||||
return ":/icons/Draft_Text.svg"
|
||||
|
||||
|
||||
def claimChildren(self):
|
||||
return []
|
||||
|
||||
|
||||
def attach(self,vobj):
|
||||
'''Setup the scene sub-graph of the view provider'''
|
||||
self.mattext = coin.SoMaterial()
|
||||
textdrawstyle = coin.SoDrawStyle()
|
||||
textdrawstyle.style = coin.SoDrawStyle.FILLED
|
||||
@@ -110,12 +123,15 @@ class ViewProviderText(ViewProviderDraftAnnotation):
|
||||
self.onChanged(vobj,"Justification")
|
||||
self.onChanged(vobj,"LineSpacing")
|
||||
|
||||
|
||||
def getDisplayModes(self,vobj):
|
||||
return ["2D text","3D text"]
|
||||
|
||||
|
||||
def setDisplayMode(self,mode):
|
||||
return mode
|
||||
|
||||
|
||||
def updateData(self,obj,prop):
|
||||
if prop == "Text":
|
||||
if obj.Text:
|
||||
@@ -129,6 +145,7 @@ class ViewProviderText(ViewProviderDraftAnnotation):
|
||||
self.trans.translation.setValue(obj.Placement.Base)
|
||||
self.trans.rotation.setValue(obj.Placement.Rotation.Q)
|
||||
|
||||
|
||||
def onChanged(self,vobj,prop):
|
||||
if prop == "ScaleMultiplier":
|
||||
if "ScaleMultiplier" in vobj.PropertiesList and "FontSize" in vobj.PropertiesList:
|
||||
|
||||
Reference in New Issue
Block a user