Draft: Implemented annotation styles
This commit is contained in:
@@ -109,8 +109,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>419</width>
|
||||
<height>632</height>
|
||||
<width>420</width>
|
||||
<height>589</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
@@ -168,12 +168,9 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="Gui::InputField" name="LineSpacing">
|
||||
<property name="toolTip">
|
||||
<string>Line spacing in system units</string>
|
||||
</property>
|
||||
<property name="quantity" stdset="0">
|
||||
<double>10.000000000000000</double>
|
||||
<widget class="QDoubleSpinBox" name="LineSpacing">
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -35,7 +35,7 @@ param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||
DEFAULT = {
|
||||
"FontName": ("font", param.GetString("textfont", "Sans")),
|
||||
"FontSize": ("str", str(param.GetFloat("textheight", 100))),
|
||||
"LineSpacing": ("str", "1 cm"),
|
||||
"LineSpacing": ("float", 1),
|
||||
"ScaleMultiplier": ("float", 1),
|
||||
"ShowUnit": ("bool", False),
|
||||
"UnitOverride": ("str", ""),
|
||||
@@ -189,18 +189,34 @@ class AnnotationStyleEditor(gui_base.GuiCommandSimplest):
|
||||
# propagate changes to all annotations
|
||||
for obj in self.get_annotations():
|
||||
vobj = obj.ViewObject
|
||||
if vobj.AnnotationStyle in self.renamed.keys():
|
||||
# temporarily add the new style and switch to it
|
||||
vobj.AnnotationStyle = vobj.AnnotationStyle + [self.renamed[vobj.AnnotationStyle]]
|
||||
vobj.AnnotationStyle = self.renamed[vobj.AnnotationStyle]
|
||||
if vobj.AnnotationStyle in styles.keys():
|
||||
if vobj.AnnotationStyle in changedstyles:
|
||||
for attr, attrvalue in styles[vobj.AnnotationStyle].items():
|
||||
if hasattr(vobj, attr):
|
||||
setattr(vobj, attr, attrvalue)
|
||||
try:
|
||||
curent = vobj.AnnotationStyle
|
||||
except AssertionError:
|
||||
# empty annotation styles list
|
||||
pass
|
||||
else:
|
||||
vobj.AnnotationStyle = ""
|
||||
vobj.AnnotationStyle = [""] + styles.keys()
|
||||
if vobj.AnnotationStyle in self.renamed.keys():
|
||||
# the style has been renamed
|
||||
# temporarily add the new style and switch to it
|
||||
vobj.AnnotationStyle = vobj.AnnotationStyle + [self.renamed[vobj.AnnotationStyle]]
|
||||
vobj.AnnotationStyle = self.renamed[vobj.AnnotationStyle]
|
||||
if vobj.AnnotationStyle in styles.keys():
|
||||
if vobj.AnnotationStyle in changedstyles:
|
||||
# the style has changed
|
||||
for attr, attrvalue in styles[vobj.AnnotationStyle].items():
|
||||
if hasattr(vobj, attr):
|
||||
try:
|
||||
getattr(vobj,attr).setValue(attrvalue)
|
||||
except:
|
||||
try:
|
||||
setattr(vobj,attr,attrvalue)
|
||||
except:
|
||||
unitvalue = FreeCAD.Units.Quantity(attrvalue,FreeCAD.Units.Length).Value
|
||||
setattr(vobj,attr,unitvalue)
|
||||
else:
|
||||
# the style has been removed
|
||||
vobj.AnnotationStyle = ""
|
||||
vobj.AnnotationStyle = [""] + list(styles.keys())
|
||||
|
||||
def on_style_changed(self, index):
|
||||
"""Execute as a callback when the styles combobox changes."""
|
||||
@@ -333,7 +349,7 @@ class AnnotationStyleEditor(gui_base.GuiCommandSimplest):
|
||||
users = []
|
||||
for obj in self.doc.Objects:
|
||||
vobj = obj.ViewObject
|
||||
if hasattr(vobj, "AnnotationStyle"):
|
||||
if "AnnotationStyle" in vobj.PropertiesList:
|
||||
users.append(obj)
|
||||
return users
|
||||
|
||||
|
||||
@@ -48,6 +48,9 @@ class ViewProviderDraftAnnotation(object):
|
||||
vobj.addProperty("App::PropertyFloat","ScaleMultiplier",
|
||||
"Annotation",QT_TRANSLATE_NOOP("App::Property",
|
||||
"Dimension size overall multiplier"))
|
||||
vobj.addProperty("App::PropertyEnumeration", "AnnotationStyle",
|
||||
"Annotation", QT_TRANSLATE_NOOP("App::Property",
|
||||
"Annotation style"))
|
||||
|
||||
# graphics properties
|
||||
vobj.addProperty("App::PropertyFloat","LineWidth",
|
||||
@@ -59,6 +62,8 @@ class ViewProviderDraftAnnotation(object):
|
||||
annotation_scale = param.GetFloat("DraftAnnotationScale", 1.0)
|
||||
if annotation_scale != 0:
|
||||
vobj.ScaleMultiplier = 1 / annotation_scale
|
||||
styles = [key[12:] for key in vobj.Object.Document.Meta.keys() if key.startswith("Draft_Style_")]
|
||||
vobj.AnnotationStyle = [""] + styles
|
||||
|
||||
|
||||
def __getstate__(self):
|
||||
@@ -82,7 +87,31 @@ class ViewProviderDraftAnnotation(object):
|
||||
return mode
|
||||
|
||||
def onChanged(self, vobj, prop):
|
||||
return
|
||||
if (prop == "AnnotationStyle") and hasattr(vobj,"AnnotationStyle"):
|
||||
import gui_annotationstyleeditor
|
||||
if (not vobj.AnnotationStyle) or (vobj.AnnotationStyle == " "):
|
||||
# unset style
|
||||
for visprop in gui_annotationstyleeditor.DEFAULT.keys():
|
||||
if visprop in vobj.PropertiesList:
|
||||
# make property writable
|
||||
vobj.setEditorMode(visprop,0)
|
||||
else:
|
||||
# set style
|
||||
import json
|
||||
styles = {}
|
||||
for key, value in vobj.Object.Document.Meta.items():
|
||||
if key.startswith("Draft_Style_"):
|
||||
styles[key[12:]] = json.loads(value)
|
||||
if prop.AnnotationStyle in styles:
|
||||
style = styles[prop.AnnotationStyle]
|
||||
for visprop in style.keys():
|
||||
if visprop in vobj.PropertiesList:
|
||||
try:
|
||||
getattr(vobj,visprop).setValue(style[visprop])
|
||||
except:
|
||||
setattr(vobj,visprop,style[visprop])
|
||||
# make property read-only
|
||||
vobj.setEditorMode(visprop,1)
|
||||
|
||||
def execute(self,vobj):
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user