[Draft] Annotation refactor and Cleanup

.


.
This commit is contained in:
carlopav
2020-03-22 09:40:33 +01:00
committed by Yorik van Havre
parent 530e8b6c58
commit 6d8fe07312
8 changed files with 193 additions and 227 deletions

View File

@@ -260,7 +260,6 @@ _Dimension = LinearDimension
from draftviewproviders.view_dimension import ViewProviderLinearDimension
_ViewProviderDimension = ViewProviderLinearDimension
return obj
def makeAngularDimension(center,angles,p3,normal=None):
"""makeAngularDimension(center,angle1,angle2,p3,[normal]): creates an angular Dimension

View File

@@ -96,8 +96,7 @@ class GuiCommandDimensionStyle(gui_base.GuiCommandSimplest):
The command creates a dimension style object
"""
def __init__(self):
super().__init__()
self.command_name = "DimensionStyle"
super().__init__(name="Dimension style")
def GetResources(self):
_msg = ("Creates a new dimension style.\n"

View File

@@ -30,9 +30,11 @@
import FreeCAD as App
import math
from PySide.QtCore import QT_TRANSLATE_NOOP
import DraftGeomUtils
import draftutils.gui_utils as gui_utils
import draftutils.utils as utils
from draftobjects.draft_annotation import DimensionBase
from draftobjects.draft_annotation import DraftAnnotation
from draftviewproviders.view_dimension import ViewProviderDimensionBase
from draftviewproviders.view_dimension import ViewProviderLinearDimension
def make_dimension(p1,p2,p3=None,p4=None):
@@ -111,10 +113,40 @@ def make_dimension(p1,p2,p3=None,p4=None):
return obj
class DimensionBase(DraftAnnotation):
"""
The Draft Dimension Base object
This class is not used directly, but inherited by all dimension
objects.
"""
def __init__(self, obj, tp = "Dimension"):
"Initialize common properties for dimension objects"
DraftAnnotation.__init__(self,obj, tp)
# Annotation
obj.addProperty("App::PropertyLink","DimensionStyle",
"Annotation",
QT_TRANSLATE_NOOP("App::Property",
"Link dimension style"))
def onChanged(self,obj,prop):
if prop == "DimensionStyle":
if hasattr(obj, "DimensionStyle"):
gui_utils.format_object(target = obj, origin = obj.DimensionStyle)
def execute(self, obj):
return
class LinearDimension(DimensionBase):
"""The Draft Dimension object"""
"""The Draft Linear Dimension object"""
def __init__(self, obj):
DimensionBase.__init__(self,obj,"Dimension")
super().__init__(obj, "Dimension")
# Draft
obj.addProperty("App::PropertyVectorDistance","Start",
@@ -179,7 +211,6 @@ class LinearDimension(DimensionBase):
def execute(self, obj):
import DraftGeomUtils
# set start point and end point according to the linked geometry
if obj.LinkedGeometry:
if len(obj.LinkedGeometry) == 1:

View File

@@ -30,10 +30,10 @@
import FreeCAD as App
from draftobjects.draft_annotation import DraftAnnotation
from PySide.QtCore import QT_TRANSLATE_NOOP
from draftviewproviders.view_dimensionstyle import ViewProviderDraftDimensionStyle
if App.GuiUp:
import FreeCADGui as Gui
from draftviewproviders.view_dimensionstyle import ViewProviderDraftDimensionStyle
def make_dimension_style(existing_dimension = None):
"""
@@ -50,4 +50,4 @@ def make_dimension_style(existing_dimension = None):
class DimensionStyle(DraftAnnotation):
def __init__(self, obj):
DraftAnnotation.__init__(self, obj, "DimensionStyle")
super().__init__(obj, "DimensionStyle")

View File

@@ -32,8 +32,11 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
from draftutils import gui_utils
class DraftAnnotation:
"""The Draft Annotation Base object"""
def __init__(self,obj,tp="Unknown"):
"""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
self.Type = tp
@@ -49,30 +52,4 @@ class DraftAnnotation:
pass
def onChanged(self, obj, prop):
pass
class DimensionBase(DraftAnnotation):
"""The Draft Dimension Base object"""
def __init__(self, obj, tp = "Dimension"):
"Initialize common properties for dimension objects"
DraftAnnotation.__init__(self,obj, tp)
# Annotation
obj.addProperty("App::PropertyLink","DimensionStyle",
"Annotation",
QT_TRANSLATE_NOOP("App::Property",
"Link dimension style"))
def onChanged(self,obj,prop):
if prop == "DimensionStyle":
if hasattr(obj, "DimensionStyle"):
gui_utils.format_object(target = obj, origin = obj.DimensionStyle)
def execute(self, obj):
return
pass

View File

@@ -30,16 +30,19 @@
import FreeCAD as App
import FreeCADGui as Gui
import DraftVecUtils
from pivy import coin
from PySide.QtCore import QT_TRANSLATE_NOOP
import draftutils.utils as utils
import draftutils.gui_utils as gui_utils
from draftviewproviders.view_draft_annotation import ViewProviderDimensionBase
from draftviewproviders.view_draft_annotation import ViewProviderDraftAnnotation
class ViewProviderLinearDimension(ViewProviderDimensionBase):
class ViewProviderDimensionBase(ViewProviderDraftAnnotation):
"""
A View Provider for the Draft Dimension object
DIMENSION VIEW PROVIDER:
This class is not used directly, but inherited by all dimension
view providers.
DIMENSION VIEW PROVIDER NOMENCLATURE:
| txt | e
----o--------------------------------o-----
@@ -56,7 +59,7 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
e = ExtOvershoot (vobj)
txt = label (vobj)
STRUCTURE:
COIN OBJECT STRUCTURE:
vobj.node.color
.drawstyle
.lineswitch1.coords
@@ -82,12 +85,141 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
.text3d
"""
def __init__(self, vobj):
ViewProviderDimensionBase.__init__(self,vobj)
def __init__(self, vobj):
# text properties
vobj.addProperty("App::PropertyFont","FontName",
"Text",
QT_TRANSLATE_NOOP("App::Property","Font name"))
vobj.addProperty("App::PropertyLength","FontSize",
"Text",
QT_TRANSLATE_NOOP("App::Property","Font size"))
vobj.addProperty("App::PropertyLength","TextSpacing",
"Text",
QT_TRANSLATE_NOOP("App::Property",
"Spacing between text and dimension line"))
vobj.addProperty("App::PropertyBool","FlipText",
"Text",
QT_TRANSLATE_NOOP("App::Property",
"Rotate the dimension text 180 degrees"))
vobj.addProperty("App::PropertyVectorDistance","TextPosition",
"Text",
QT_TRANSLATE_NOOP("App::Property",
"Text Position. \n"
"Leave (0,0,0) for automatic position"))
vobj.addProperty("App::PropertyString","Override",
"Text",
QT_TRANSLATE_NOOP("App::Property",
"Text override. \n"
"Use $dim to insert the dimension length"))
# units properties
vobj.addProperty("App::PropertyInteger","Decimals",
"Units",
QT_TRANSLATE_NOOP("App::Property",
"The number of decimals to show"))
vobj.addProperty("App::PropertyBool","ShowUnit",
"Units",
QT_TRANSLATE_NOOP("App::Property",
"Show the unit suffix"))
vobj.addProperty("App::PropertyString","UnitOverride",
"Units",
QT_TRANSLATE_NOOP("App::Property",
"A unit to express the measurement. \n"
"Leave blank for system default"))
# graphics properties
vobj.addProperty("App::PropertyLength","ArrowSize",
"Graphics",
QT_TRANSLATE_NOOP("App::Property","Arrow size"))
vobj.addProperty("App::PropertyEnumeration","ArrowType",
"Graphics",
QT_TRANSLATE_NOOP("App::Property","Arrow type"))
vobj.addProperty("App::PropertyBool","FlipArrows",
"Graphics",
QT_TRANSLATE_NOOP("App::Property",
"Rotate the dimension arrows 180 degrees"))
vobj.addProperty("App::PropertyDistance","DimOvershoot",
"Graphics",
QT_TRANSLATE_NOOP("App::Property",
"The distance the dimension line is extended\n"
"past the extension lines"))
vobj.addProperty("App::PropertyDistance","ExtLines",
"Graphics",
QT_TRANSLATE_NOOP("App::Property",
"Length of the extension lines"))
vobj.addProperty("App::PropertyDistance","ExtOvershoot",
"Graphics",
QT_TRANSLATE_NOOP("App::Property",
"Length of the extension line \n"
"above the dimension line"))
vobj.addProperty("App::PropertyBool","ShowLine",
"Graphics",
QT_TRANSLATE_NOOP("App::Property",
"Shows the dimension line and arrows"))
vobj.FontSize = utils.get_param("textheight",0.20)
vobj.TextSpacing = utils.get_param("dimspacing",0.05)
vobj.FontName = utils.get_param("textfont","")
vobj.ArrowSize = utils.get_param("arrowsize",0.1)
vobj.ArrowType = utils.ARROW_TYPES
vobj.ArrowType = utils.ARROW_TYPES[utils.get_param("dimsymbol",0)]
vobj.ExtLines = utils.get_param("extlines",0.3)
vobj.DimOvershoot = utils.get_param("dimovershoot",0)
vobj.ExtOvershoot = utils.get_param("extovershoot",0)
vobj.Decimals = utils.get_param("dimPrecision",2)
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
def onChanged(self, vobj, prop):
"""called when a view property has changed"""
return
def doubleClicked(self,vobj):
self.setEdit(vobj)
def getDisplayModes(self,vobj):
return ["2D","3D"]
def getDefaultDisplayMode(self):
if hasattr(self,"defaultmode"):
return self.defaultmode
else:
return ["2D","3D"][utils.get_param("dimstyle",0)]
def setDisplayMode(self,mode):
return mode
def getIcon(self):
if self.is_linked_to_circle():
return ":/icons/Draft_DimensionRadius.svg"
return ":/icons/Draft_Dimension_Tree.svg"
def __getstate__(self):
return self.Object.ViewObject.DisplayMode
def __setstate__(self,state):
if state:
self.defaultmode = state
self.setDisplayMode(state)
class ViewProviderLinearDimension(ViewProviderDimensionBase):
"""
A View Provider for the Draft Linear Dimension object
"""
def __init__(self, vobj):
super().__init__(vobj)
def attach(self, vobj):
"""called on object creation"""
from pivy import coin
self.Object = vobj.Object
self.color = coin.SoBaseColor()
self.font = coin.SoFont()
@@ -506,22 +638,6 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
self.node.insertChild(self.marksExtOvershoot,2)
self.node3d.insertChild(self.marksExtOvershoot,2)
def doubleClicked(self,vobj):
self.setEdit(vobj)
def getDisplayModes(self,vobj):
return ["2D","3D"]
def getDefaultDisplayMode(self):
if hasattr(self,"defaultmode"):
return self.defaultmode
else:
return ["2D","3D"][utils.get_param("dimstyle",0)]
def setDisplayMode(self,mode):
return mode
def is_linked_to_circle(self):
_obj = self.Object
if _obj.LinkedGeometry and len(_obj.LinkedGeometry) == 1:
@@ -537,13 +653,4 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
def getIcon(self):
if self.is_linked_to_circle():
return ":/icons/Draft_DimensionRadius.svg"
return ":/icons/Draft_Dimension_Tree.svg"
def __getstate__(self):
return self.Object.ViewObject.DisplayMode
def __setstate__(self,state):
if state:
self.defaultmode = state
self.setDisplayMode(state)
return ":/icons/Draft_Dimension_Tree.svg"

View File

@@ -153,7 +153,7 @@ class ViewProviderDraftDimensionStyle(_ViewProviderDraft):
self.init_properties(vobj, existing_dimension)
_ViewProviderDraft.__init__(self,vobj)
super().__init__(vobj)
def init_properties(self, vobj, existing_dimension):
"""

View File

@@ -20,21 +20,24 @@
# * USA *
# * *
# ***************************************************************************
"""This module provides the Draft Annotations view provider base classes
"""This module provides the Draft Annotations view provider base class
"""
## @package polararray
# \ingroup DRAFT
# \brief This module provides the view provider code for Draft PolarArray.
# \brief This module provides the Draft Annotations view provider base class
import FreeCAD as App
import FreeCADGui as Gui
from PySide.QtCore import QT_TRANSLATE_NOOP
import draftutils.utils as utils
class ViewProviderDraftAnnotation:
"""The base class for Draft Annotation Viewproviders"""
"""
The base class for Draft Annotation Viewproviders
This class is not used directly, but inherited by all annotation
view providers.
"""
def __init__(self, vobj):
vobj.Proxy = self
@@ -111,153 +114,3 @@ class ViewProviderDraftAnnotation:
return objs
class ViewProviderDimensionBase(ViewProviderDraftAnnotation):
"""
A View Provider for the Draft Dimension object
DIMENSION VIEW PROVIDER:
| txt | e
----o--------------------------------o-----
| |
| | d
| |
a b c b a
a = DimOvershoot (vobj)
b = Arrows (vobj)
c = Dimline (obj)
d = ExtLines (vobj)
e = ExtOvershoot (vobj)
txt = label (vobj)
STRUCTURE:
vobj.node.color
.drawstyle
.lineswitch1.coords
.line
.marks
.marksDimOvershoot
.marksExtOvershoot
.label.textpos
.color
.font
.text
vobj.node3d.color
.drawstyle
.lineswitch3.coords
.line
.marks
.marksDimOvershoot
.marksExtOvershoot
.label3d.textpos
.color
.font3d
.text3d
"""
def __init__(self, vobj):
# text properties
vobj.addProperty("App::PropertyFont","FontName",
"Text",QT_TRANSLATE_NOOP("App::Property","Font name"))
vobj.addProperty("App::PropertyLength","FontSize",
"Text",QT_TRANSLATE_NOOP("App::Property","Font size"))
vobj.addProperty("App::PropertyLength","TextSpacing",
"Text",QT_TRANSLATE_NOOP("App::Property",
"The spacing between the text and the dimension line"))
vobj.addProperty("App::PropertyBool","FlipText",
"Text",QT_TRANSLATE_NOOP("App::Property",
"Rotate the dimension text 180 degrees"))
vobj.addProperty("App::PropertyVectorDistance","TextPosition",
"Text",QT_TRANSLATE_NOOP("App::Property",
"The position of the text. Leave (0,0,0) for automatic position"))
vobj.addProperty("App::PropertyString","Override",
"Text",QT_TRANSLATE_NOOP("App::Property",
"Text override. Use $dim to insert the dimension length"))
# units properties
vobj.addProperty("App::PropertyInteger","Decimals",
"Units",QT_TRANSLATE_NOOP("App::Property",
"The number of decimals to show"))
vobj.addProperty("App::PropertyBool","ShowUnit",
"Units",QT_TRANSLATE_NOOP("App::Property",
"Show the unit suffix"))
vobj.addProperty("App::PropertyString","UnitOverride",
"Units",QT_TRANSLATE_NOOP("App::Property",
"A unit to express the measurement. Leave blank for system default"))
# graphics properties
vobj.addProperty("App::PropertyLength","ArrowSize",
"Graphics",QT_TRANSLATE_NOOP("App::Property","Arrow size"))
vobj.addProperty("App::PropertyEnumeration","ArrowType",
"Graphics",QT_TRANSLATE_NOOP("App::Property","Arrow type"))
vobj.addProperty("App::PropertyBool","FlipArrows",
"Graphics",QT_TRANSLATE_NOOP("App::Property",
"Rotate the dimension arrows 180 degrees"))
vobj.addProperty("App::PropertyDistance","DimOvershoot",
"Graphics",QT_TRANSLATE_NOOP("App::Property",
"The distance the dimension line is extended past the extension lines"))
vobj.addProperty("App::PropertyDistance","ExtLines",
"Graphics",QT_TRANSLATE_NOOP("App::Property",
"Length of the extension lines"))
vobj.addProperty("App::PropertyDistance","ExtOvershoot",
"Graphics",QT_TRANSLATE_NOOP("App::Property",
"Length of the extension line above the dimension line"))
vobj.addProperty("App::PropertyBool","ShowLine",
"Graphics",QT_TRANSLATE_NOOP("App::Property",
"Shows the dimension line and arrows"))
vobj.FontSize = utils.get_param("textheight",0.20)
vobj.TextSpacing = utils.get_param("dimspacing",0.05)
vobj.FontName = utils.get_param("textfont","")
vobj.ArrowSize = utils.get_param("arrowsize",0.1)
vobj.ArrowType = utils.ARROW_TYPES
vobj.ArrowType = utils.ARROW_TYPES[utils.get_param("dimsymbol",0)]
vobj.ExtLines = utils.get_param("extlines",0.3)
vobj.DimOvershoot = utils.get_param("dimovershoot",0)
vobj.ExtOvershoot = utils.get_param("extovershoot",0)
vobj.Decimals = utils.get_param("dimPrecision",2)
vobj.ShowUnit = utils.get_param("showUnit",True)
vobj.ShowLine = True
ViewProviderDraftAnnotation.__init__(self,vobj)
def attach(self, vobj):
"""called on object creation"""
return
def updateData(self, obj, prop):
"""called when the base object is changed"""
return
def onChanged(self, vobj, prop):
"""called when a view property has changed"""
return
def doubleClicked(self,vobj):
self.setEdit(vobj)
def getDisplayModes(self,vobj):
return ["2D","3D"]
def getDefaultDisplayMode(self):
if hasattr(self,"defaultmode"):
return self.defaultmode
else:
return ["2D","3D"][utils.get_param("dimstyle",0)]
def setDisplayMode(self,mode):
return mode
def getIcon(self):
if self.is_linked_to_circle():
return ":/icons/Draft_DimensionRadius.svg"
return ":/icons/Draft_Dimension_Tree.svg"
def __getstate__(self):
return self.Object.ViewObject.DisplayMode
def __setstate__(self,state):
if state:
self.defaultmode = state
self.setDisplayMode(state)