Draft: improve setting of properties of dimensions, labels, and texts

Add view properties of dimensions, labels, and text objects
through methods, calling the parent classes, and `ViewProviderDraftAnnotation`
when needed.
This commit is contained in:
vocx-fc
2020-06-16 21:09:03 -05:00
committed by Yorik van Havre
parent 245fa7af0f
commit bed3dd2372
4 changed files with 331 additions and 174 deletions

View File

@@ -397,10 +397,10 @@ from draftmake.make_dimension import (make_dimension,
makeAngularDimension)
if FreeCAD.GuiUp:
from draftviewproviders.view_dimension import ViewProviderLinearDimension
from draftviewproviders.view_dimension import ViewProviderAngularDimension
_ViewProviderDimension = ViewProviderLinearDimension
_ViewProviderAngularDimension = ViewProviderAngularDimension
from draftviewproviders.view_dimension import (ViewProviderLinearDimension,
_ViewProviderDimension,
ViewProviderAngularDimension,
_ViewProviderAngularDimension)
from draftobjects.label import (Label,
DraftLabel)
@@ -408,9 +408,9 @@ from draftobjects.label import (Label,
from draftmake.make_label import (make_label,
makeLabel)
if gui:
from draftviewproviders.view_label import ViewProviderLabel
ViewProviderDraftLabel = ViewProviderLabel
if FreeCAD.GuiUp:
from draftviewproviders.view_label import (ViewProviderLabel,
ViewProviderDraftLabel)
from draftobjects.text import (Text,
DraftText)

View File

@@ -86,92 +86,179 @@ class ViewProviderDimensionBase(ViewProviderDraftAnnotation):
"""
def __init__(self, vobj):
super(ViewProviderDimensionBase, self).__init__(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"))
self.set_properties(vobj)
self.Object = vobj.Object
vobj.Proxy = self
# 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"))
def set_properties(self, vobj):
"""Set the properties only if they don't already exist."""
super(ViewProviderDimensionBase, self).set_properties(vobj)
# 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
properties = vobj.PropertiesList
self.set_text_properties(vobj, properties)
self.set_units_properties(vobj, properties)
self.set_graphics_properties(vobj, properties)
def set_text_properties(self, vobj, properties):
"""Set text properties only if they don't already exist."""
if "FontName" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Font name")
vobj.addProperty("App::PropertyFont",
"FontName",
"Text",
_tip)
vobj.FontName = utils.get_param("textfont", "")
if "FontSize" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Font size")
vobj.addProperty("App::PropertyLength",
"FontSize",
"Text",
_tip)
vobj.FontSize = utils.get_param("textheight", 0.20)
if "TextSpacing" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Spacing between text and dimension line")
vobj.addProperty("App::PropertyLength",
"TextSpacing",
"Text",
_tip)
vobj.TextSpacing = utils.get_param("dimspacing", 0.05)
if "FlipText" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Rotate the dimension text 180 degrees")
vobj.addProperty("App::PropertyBool",
"FlipText",
"Text",
_tip)
vobj.FlipText = False
if "TextPosition" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Text Position.\n"
"Leave '(0,0,0)' for automatic position")
vobj.addProperty("App::PropertyVectorDistance",
"TextPosition",
"Text",
_tip)
vobj.TextPosition = App.Vector(0, 0, 0)
if "Override" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Text override.\n"
"Use '$dim' so that it is replaced by "
"the dimension length.")
vobj.addProperty("App::PropertyString",
"Override",
"Text",
_tip)
vobj.Override = ''
def set_units_properties(self, vobj, properties):
"""Set unit properties only if they don't already exist."""
if "Decimals" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"The number of decimals to show")
vobj.addProperty("App::PropertyInteger",
"Decimals",
"Units",
_tip)
vobj.Decimals = utils.get_param("dimPrecision", 2)
if "ShowUnit" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Show the unit suffix")
vobj.addProperty("App::PropertyBool",
"ShowUnit",
"Units",
_tip)
vobj.ShowUnit = utils.get_param("showUnit", True)
if "UnitOverride" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"A unit to express the measurement.\n"
"Leave blank for system default")
vobj.addProperty("App::PropertyString",
"UnitOverride",
"Units",
_tip)
def set_graphics_properties(self, vobj, properties):
"""Set graphics properties only if they don't already exist."""
super(ViewProviderDimensionBase, self).set_graphics_properties(vobj, properties)
if "ArrowSize" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Arrow size")
vobj.addProperty("App::PropertyLength",
"ArrowSize",
"Graphics",
_tip)
vobj.ArrowSize = utils.get_param("arrowsize", 1)
if "ArrowType" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Arrow type")
vobj.addProperty("App::PropertyEnumeration",
"ArrowType",
"Graphics",
_tip)
vobj.ArrowType = utils.ARROW_TYPES
vobj.ArrowType = utils.ARROW_TYPES[utils.get_param("dimsymbol", 0)]
if "FlipArrows" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Rotate the dimension arrows 180 degrees")
vobj.addProperty("App::PropertyBool",
"FlipArrows",
"Graphics",
_tip)
vobj.FlipArrows = False
if "DimOvershoot" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"The distance the dimension line "
"is extended\n"
"past the extension lines")
vobj.addProperty("App::PropertyDistance",
"DimOvershoot",
"Graphics",
_tip)
vobj.DimOvershoot = utils.get_param("dimovershoot", 0)
if "ExtLines" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Length of the extension lines")
vobj.addProperty("App::PropertyDistance",
"ExtLines",
"Graphics",
_tip)
vobj.ExtLines = utils.get_param("extlines", 0.3)
if "ExtOvershoot" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Length of the extension line\n"
"above the dimension line")
vobj.addProperty("App::PropertyDistance",
"ExtOvershoot",
"Graphics",
_tip)
vobj.ExtOvershoot = utils.get_param("extovershoot", 0)
if "ShowLine" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Shows the dimension line and arrows")
vobj.addProperty("App::PropertyBool",
"ShowLine",
"Graphics",
_tip)
vobj.ShowLine = True
def updateData(self, obj, prop):
"""called when the base object is changed"""
@@ -216,9 +303,9 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
A View Provider for the Draft Linear Dimension object
"""
def __init__(self, vobj):
super(ViewProviderLinearDimension, self).__init__(vobj)
super(ViewProviderLinearDimension, self).set_properties(vobj)
self.Object = vobj.Object
vobj.Proxy = self
@@ -658,16 +745,16 @@ class ViewProviderLinearDimension(ViewProviderDimensionBase):
return ":/icons/Draft_Dimension_Tree.svg"
# Alias for compatibility with v0.18 and earlier
_ViewProviderDimension = ViewProviderLinearDimension
class ViewProviderAngularDimension(ViewProviderDimensionBase):
"""A View Provider for the Draft Angular Dimension object"""
def __init__(self, vobj):
super(ViewProviderAngularDimension, self).__init__(vobj)
super(ViewProviderAngularDimension, self).set_properties(vobj)
vobj.addProperty("App::PropertyBool","FlipArrows",
"Graphics",QT_TRANSLATE_NOOP("App::Property",
"Rotate the dimension arrows 180 degrees"))
self.Object = vobj.Object
vobj.Proxy = self
@@ -926,3 +1013,7 @@ class ViewProviderAngularDimension(ViewProviderDimensionBase):
def getIcon(self):
return ":/icons/Draft_DimensionAngular.svg"
# Alias for compatibility with v0.18 and earlier
_ViewProviderAngularDimension = ViewProviderAngularDimension

View File

@@ -45,79 +45,123 @@ class ViewProviderLabel(ViewProviderDraftAnnotation):
"""A View Provider for the Label annotation object"""
def __init__(self,vobj):
super(ViewProviderLabel, self).__init__(vobj)
self.set_properties(vobj)
self.Object = vobj.Object
vobj.Proxy = self
def set_properties(self, vobj):
"""Set the properties only if they don't already exist."""
super(ViewProviderLabel, self).set_properties(vobj)
# Text properties
properties = vobj.PropertiesList
self.set_text_properties(vobj, properties)
self.set_graphics_properties(vobj, properties)
vobj.addProperty("App::PropertyLength","TextSize",
"Text",QT_TRANSLATE_NOOP("App::Property",
"The size of the text"))
def set_text_properties(self, vobj, properties):
"""Set text properties only if they don't already exist."""
if "TextSize" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"The size of the text")
vobj.addProperty("App::PropertyLength",
"TextSize",
"Text",
_tip)
vobj.TextSize = utils.get_param("textheight", 1)
vobj.addProperty("App::PropertyFont","TextFont",
"Text",QT_TRANSLATE_NOOP("App::Property",
"The font of the text"))
if "TextFont" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"The font of the text")
vobj.addProperty("App::PropertyFont",
"TextFont",
"Text",
_tip)
vobj.TextFont = utils.get_param("textfont")
vobj.addProperty("App::PropertyEnumeration","TextAlignment",
"Text",QT_TRANSLATE_NOOP("App::Property",
"The vertical alignment of the text"))
if "TextAlignment" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"The vertical alignment of the text")
vobj.addProperty("App::PropertyEnumeration",
"TextAlignment",
"Text",
_tip)
vobj.TextAlignment = ["Top", "Middle", "Bottom"]
vobj.TextAlignment = "Bottom"
vobj.addProperty("App::PropertyColor","TextColor",
"Text",QT_TRANSLATE_NOOP("App::Property",
"Text color"))
if "TextColor" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Text color")
vobj.addProperty("App::PropertyColor",
"TextColor",
"Text",
_tip)
vobj.addProperty("App::PropertyInteger","MaxChars",
"Text",QT_TRANSLATE_NOOP("App::Property",
"The maximum number of characters on each line of the text box"))
if "MaxChars" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"The maximum number of characters "
"on each line of the text box")
vobj.addProperty("App::PropertyInteger",
"MaxChars",
"Text",
_tip)
# Graphics properties
def set_graphics_properties(self, vobj, properties):
"""Set graphics properties only if they don't already exist."""
if "ArrowSize" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"The size of the arrow")
vobj.addProperty("App::PropertyLength",
"ArrowSize",
"Graphics",
_tip)
vobj.ArrowSize = utils.get_param("arrowsize", 1)
vobj.addProperty("App::PropertyLength","ArrowSize",
"Graphics",QT_TRANSLATE_NOOP("App::Property",
"The size of the arrow"))
if "ArrowType" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"The type of arrow of this label")
vobj.addProperty("App::PropertyEnumeration",
"ArrowType",
"Graphics",
_tip)
vobj.ArrowType = utils.ARROW_TYPES
vobj.ArrowType = utils.ARROW_TYPES[utils.get_param("dimsymbol")]
vobj.addProperty("App::PropertyEnumeration","ArrowType",
"Graphics",QT_TRANSLATE_NOOP("App::Property",
"The type of arrow of this label"))
if "Frame" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"The type of frame around the text "
"of this object")
vobj.addProperty("App::PropertyEnumeration",
"Frame",
"Graphics",
_tip)
vobj.Frame = ["None", "Rectangle"]
vobj.addProperty("App::PropertyEnumeration","Frame",
"Graphics",QT_TRANSLATE_NOOP("App::Property",
"The type of frame around the text of this object"))
if "Line" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Display a leader line or not")
vobj.addProperty("App::PropertyBool",
"Line",
"Graphics",
_tip)
vobj.Line = True
vobj.addProperty("App::PropertyBool","Line",
"Graphics",QT_TRANSLATE_NOOP("App::Property",
"Display a leader line or not"))
vobj.addProperty("App::PropertyFloat","LineWidth",
"Graphics",QT_TRANSLATE_NOOP("App::Property",
"Line width"))
vobj.addProperty("App::PropertyColor","LineColor",
"Graphics",QT_TRANSLATE_NOOP("App::Property",
"Line color"))
self.Object = vobj.Object
vobj.TextAlignment = ["Top","Middle","Bottom"]
vobj.TextAlignment = "Middle"
vobj.LineWidth = utils.get_param("linewidth",1)
vobj.TextFont = utils.get_param("textfont")
vobj.TextSize = utils.get_param("textheight",1)
vobj.ArrowSize = utils.get_param("arrowsize",1)
vobj.ArrowType = utils.ARROW_TYPES
vobj.ArrowType = utils.ARROW_TYPES[utils.get_param("dimsymbol")]
vobj.Frame = ["None","Rectangle"]
vobj.Line = True
param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
annotation_scale = param.GetFloat("DraftAnnotationScale", 1.0)
vobj.ScaleMultiplier = 1 / annotation_scale
if "LineWidth" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Line width")
vobj.addProperty("App::PropertyFloat",
"LineWidth",
"Graphics",
_tip)
vobj.LineWidth = utils.get_param("linewidth", 1)
if "LineColor" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Line color")
vobj.addProperty("App::PropertyColor",
"LineColor",
"Graphics",
_tip)
def getIcon(self):
return ":/icons/Draft_Label.svg"
@@ -322,3 +366,7 @@ class ViewProviderLabel(ViewProviderDraftAnnotation):
pos = vobj.Object.Placement.Base.add(v)
self.textpos.translation.setValue(pos)
self.textpos.rotation.setValue(vobj.Object.Placement.Rotation.Q)
# Alias for compatibility with v0.18 and earlier
ViewProviderDraftLabel = ViewProviderLabel

View File

@@ -43,41 +43,59 @@ class ViewProviderText(ViewProviderDraftAnnotation):
def __init__(self,vobj):
super(ViewProviderText, self).__init__(vobj)
self.set_properties(vobj)
self.Object = vobj.Object
vobj.Proxy = self
def set_properties(self, vobj):
"""Set the properties only if they don't already exist."""
super(ViewProviderText, self).set_properties(vobj)
properties = vobj.PropertiesList
vobj.addProperty("App::PropertyLength","FontSize",
"Text",QT_TRANSLATE_NOOP("App::Property",
"The size of the text"))
vobj.addProperty("App::PropertyFont","FontName",
"Text",QT_TRANSLATE_NOOP("App::Property",
"The font of the text"))
vobj.addProperty("App::PropertyEnumeration","Justification",
"Text",QT_TRANSLATE_NOOP("App::Property",
"The vertical alignment of the text"))
vobj.addProperty("App::PropertyColor","TextColor",
"Text",QT_TRANSLATE_NOOP("App::Property",
"Text color"))
vobj.addProperty("App::PropertyFloat","LineSpacing",
"Text",QT_TRANSLATE_NOOP("App::Property",
"Line spacing (relative to font size)"))
if "FontSize" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"The size of the text")
vobj.addProperty("App::PropertyLength",
"FontSize",
"Text",
_tip)
vobj.FontSize = utils.get_param("textheight", 1)
param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
annotation_scale = param.GetFloat("DraftAnnotationScale", 1.0)
vobj.ScaleMultiplier = 1 / annotation_scale
if "FontName" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"The font of the text")
vobj.addProperty("App::PropertyFont",
"FontName",
"Text",
_tip)
vobj.FontName = utils.get_param("textfont", "sans")
vobj.Justification = ["Left","Center","Right"]
vobj.FontName = utils.get_param("textfont","sans")
vobj.FontSize = utils.get_param("textheight",1)
if "Justification" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"The vertical alignment of the text")
vobj.addProperty("App::PropertyEnumeration",
"Justification",
"Text",
_tip)
vobj.Justification = ["Left", "Center", "Right"]
if "TextColor" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Text color")
vobj.addProperty("App::PropertyColor",
"TextColor",
"Text",
_tip)
if "LineSpacing" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property",
"Line spacing (relative to font size)")
vobj.addProperty("App::PropertyFloat",
"LineSpacing",
"Text",
_tip)
def getIcon(self):
return ":/icons/Draft_Text.svg"