DisplayMode of Text was not updated. Some houskeeping
This commit is contained in:
@@ -124,11 +124,6 @@ class DimensionBase(DraftAnnotation):
|
||||
objects.
|
||||
"""
|
||||
|
||||
def __init__(self, obj, tp="Dimension"):
|
||||
super().__init__(obj, tp)
|
||||
self.set_properties(obj)
|
||||
obj.Proxy = self
|
||||
|
||||
def set_properties(self, obj):
|
||||
"""Set basic properties only if they don't exist."""
|
||||
properties = obj.PropertiesList
|
||||
@@ -197,8 +192,7 @@ class DimensionBase(DraftAnnotation):
|
||||
obj.Dimline = App.Vector(0, 1, 0)
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Execute code when the document is restored.
|
||||
"""
|
||||
"""Execute code when the document is restored."""
|
||||
super().onDocumentRestored(obj)
|
||||
|
||||
if not hasattr(obj, "ViewObject"):
|
||||
@@ -208,13 +202,17 @@ class DimensionBase(DraftAnnotation):
|
||||
return
|
||||
if hasattr(vobj, "TextColor"):
|
||||
return
|
||||
|
||||
self.update_properties_0v21(obj, vobj)
|
||||
|
||||
def update_properties_0v21(self, obj, vobj):
|
||||
"""Update view properties."""
|
||||
vobj.Proxy.set_text_properties(vobj, vobj.PropertiesList)
|
||||
vobj.TextColor = vobj.LineColor
|
||||
_wrn("v0.21, " + obj.Label + ", " + translate("draft", "added view property 'TextColor'"))
|
||||
_wrn("v0.21, " + obj.Label + ", "
|
||||
+ translate("draft", "added view property 'TextColor'"))
|
||||
_wrn("v0.21, " + obj.Label + ", "
|
||||
+ translate("draft", "renamed 'DisplayMode' options to 'World/Screen'"))
|
||||
|
||||
|
||||
class LinearDimension(DimensionBase):
|
||||
"""The linear dimension object.
|
||||
@@ -227,7 +225,9 @@ class LinearDimension(DimensionBase):
|
||||
"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super().__init__(obj, "LinearDimension")
|
||||
obj.Proxy = self
|
||||
self.set_properties(obj)
|
||||
self.Type = "LinearDimension"
|
||||
|
||||
def set_properties(self, obj):
|
||||
"""Set basic properties only if they don't exist."""
|
||||
@@ -304,6 +304,11 @@ class LinearDimension(DimensionBase):
|
||||
_tip)
|
||||
obj.Diameter = False
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Execute code when the document is restored."""
|
||||
super().onDocumentRestored(obj)
|
||||
self.Type = "LinearDimension"
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
"""Execute when a property is changed.
|
||||
|
||||
@@ -493,7 +498,9 @@ class AngularDimension(DimensionBase):
|
||||
"""
|
||||
|
||||
def __init__(self, obj):
|
||||
super().__init__(obj, "AngularDimension")
|
||||
obj.Proxy = self
|
||||
self.set_properties(obj)
|
||||
self.Type = "AngularDimension"
|
||||
|
||||
def set_properties(self, obj):
|
||||
"""Set basic properties only if they don't exist."""
|
||||
@@ -552,6 +559,11 @@ class AngularDimension(DimensionBase):
|
||||
_tip)
|
||||
obj.Angle = 0
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Execute code when the document is restored."""
|
||||
super().onDocumentRestored(obj)
|
||||
self.Type = "AngularDimension"
|
||||
|
||||
def execute(self, obj):
|
||||
"""Execute when the object is created or recomputed.
|
||||
|
||||
|
||||
@@ -37,8 +37,6 @@ through Coin (pivy).
|
||||
|
||||
## \addtogroup draftobjects
|
||||
# @{
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
from draftutils.messages import _wrn
|
||||
from draftutils.translate import translate
|
||||
|
||||
@@ -55,10 +53,6 @@ class DraftAnnotation(object):
|
||||
Text
|
||||
"""
|
||||
|
||||
def __init__(self, obj, typ="Annotation"):
|
||||
self.Type = typ
|
||||
obj.Proxy = self
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Execute code when the document is restored.
|
||||
|
||||
@@ -72,7 +66,6 @@ class DraftAnnotation(object):
|
||||
return
|
||||
if hasattr(vobj, "ScaleMultiplier") and hasattr(vobj, "AnnotationStyle"):
|
||||
return
|
||||
|
||||
self.add_missing_properties_0v19(obj, vobj)
|
||||
|
||||
def add_missing_properties_0v19(self, obj, vobj):
|
||||
@@ -80,51 +73,22 @@ class DraftAnnotation(object):
|
||||
multiplier = None
|
||||
if not hasattr(vobj, "ScaleMultiplier"):
|
||||
multiplier = 1.00
|
||||
_wrn("v0.19, " + obj.Label + ", " + translate("draft", "added view property 'ScaleMultiplier'"))
|
||||
_wrn("v0.19, " + obj.Label + ", "
|
||||
+ translate("draft", "added view property 'ScaleMultiplier'"))
|
||||
if not hasattr(vobj, "AnnotationStyle"):
|
||||
_wrn("v0.19, " + obj.Label + ", " + translate("draft", "added view property 'AnnotationStyle'"))
|
||||
_wrn("v0.19, " + obj.Label + ", "
|
||||
+ translate("draft", "added view property 'AnnotationStyle'"))
|
||||
vobj.Proxy.set_annotation_properties(vobj, vobj.PropertiesList)
|
||||
if multiplier is not None:
|
||||
vobj.ScaleMultiplier = multiplier
|
||||
|
||||
def __getstate__(self):
|
||||
"""Return a tuple of objects to save or None.
|
||||
|
||||
Save the Type.
|
||||
"""
|
||||
return self.Type
|
||||
|
||||
def __setstate__(self, state):
|
||||
"""Set the internal properties from the restored state.
|
||||
|
||||
Restore the Type of the object.
|
||||
"""
|
||||
if state:
|
||||
if isinstance(state, dict) and ("Type" in state):
|
||||
# During the migration of the classes
|
||||
# the 'DraftText' type was changed to 'Text' type
|
||||
if state["Type"] == "DraftText":
|
||||
state["Type"] = "Text"
|
||||
_wrn("v0.19, " + translate("draft","migrated 'DraftText' type to 'Text'"))
|
||||
self.Type = state["Type"]
|
||||
else:
|
||||
if state == "DraftText":
|
||||
state = "Text"
|
||||
_wrn("v0.19, " + translate("draft","migrated 'DraftText' type to 'Text'"))
|
||||
self.Type = state
|
||||
|
||||
def execute(self, obj):
|
||||
"""Execute when the object is created or recomputed.
|
||||
|
||||
Does nothing.
|
||||
"""
|
||||
return
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
"""Execute when a property is changed.
|
||||
def __setstate__(self,state):
|
||||
|
||||
Does nothing.
|
||||
"""
|
||||
return
|
||||
|
||||
|
||||
## @}
|
||||
|
||||
@@ -45,9 +45,9 @@ class Label(DraftAnnotation):
|
||||
"""The Draft Label object."""
|
||||
|
||||
def __init__(self, obj):
|
||||
super().__init__(obj, "Label")
|
||||
self.set_properties(obj)
|
||||
obj.Proxy = self
|
||||
self.set_properties(obj)
|
||||
self.Type = "Label"
|
||||
|
||||
def set_properties(self, obj):
|
||||
"""Set properties only if they don't exist."""
|
||||
@@ -223,9 +223,9 @@ class Label(DraftAnnotation):
|
||||
obj.LabelType = get_label_types()
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
"""Execute code when the document is restored.
|
||||
"""
|
||||
"""Execute code when the document is restored."""
|
||||
super().onDocumentRestored(obj)
|
||||
self.Type = "Label"
|
||||
|
||||
if not hasattr(obj, "ViewObject"):
|
||||
return
|
||||
@@ -234,10 +234,10 @@ class Label(DraftAnnotation):
|
||||
return
|
||||
if hasattr(vobj, "FontName") and hasattr(vobj, "FontSize"):
|
||||
return
|
||||
|
||||
self.update_properties_0v21(obj, vobj)
|
||||
|
||||
def update_properties_0v21(self, obj, vobj):
|
||||
"""Update view properties."""
|
||||
old_fontname = vobj.TextFont
|
||||
old_fontsize = vobj.TextSize
|
||||
vobj.removeProperty("TextFont")
|
||||
@@ -250,12 +250,15 @@ class Label(DraftAnnotation):
|
||||
# switched: "2D text" becomes "World" and "3D text" becomes "Screen".
|
||||
# It should be the other way around:
|
||||
vobj.DisplayMode = "World" if vobj.DisplayMode == "Screen" else "Screen"
|
||||
_wrn("v0.21, " + obj.Label + ", " + translate("draft", "updated view property 'TextFont' to 'FontName'"))
|
||||
_wrn("v0.21, " + obj.Label + ", " + translate("draft", "updated view property 'TextSize' to 'FontSize'"))
|
||||
_wrn("v0.21, " + obj.Label + ", "
|
||||
+ translate("draft", "renamed view property 'TextFont' to 'FontName'"))
|
||||
_wrn("v0.21, " + obj.Label + ", "
|
||||
+ translate("draft", "renamed view property 'TextSize' to 'FontSize'"))
|
||||
_wrn("v0.21, " + obj.Label + ", "
|
||||
+ translate("draft", "renamed 'DisplayMode' options to 'World/Screen'"))
|
||||
|
||||
def onChanged(self, obj, prop):
|
||||
"""Execute when a property is changed."""
|
||||
super().onChanged(obj, prop)
|
||||
self.show_and_hide(obj, prop)
|
||||
|
||||
def show_and_hide(self, obj, prop):
|
||||
|
||||
@@ -32,6 +32,9 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
import FreeCAD as App
|
||||
|
||||
from draftutils.messages import _wrn
|
||||
from draftutils.translate import translate
|
||||
|
||||
from draftobjects.draft_annotation import DraftAnnotation
|
||||
|
||||
|
||||
@@ -39,9 +42,9 @@ class Text(DraftAnnotation):
|
||||
"""The Draft Text object."""
|
||||
|
||||
def __init__(self, obj):
|
||||
super().__init__(obj, "Text")
|
||||
self.set_properties(obj)
|
||||
obj.Proxy = self
|
||||
self.set_properties(obj)
|
||||
self.Type = "Text"
|
||||
|
||||
def set_properties(self, obj):
|
||||
"""Add properties to the object and set them."""
|
||||
@@ -69,6 +72,32 @@ class Text(DraftAnnotation):
|
||||
_tip)
|
||||
obj.Text = []
|
||||
|
||||
def onDocumentRestored(self,obj):
|
||||
"""Execute code when the document is restored."""
|
||||
super().onDocumentRestored(obj)
|
||||
|
||||
# See __setstate__: self.Type is None for new objects.
|
||||
if self.Type is not None \
|
||||
and hasattr(obj, "ViewObject") \
|
||||
and obj.ViewObject:
|
||||
self.update_properties_0v21(obj, obj.ViewObject)
|
||||
|
||||
self.Type = "Text"
|
||||
|
||||
def update_properties_0v21(self, obj, vobj):
|
||||
"""Update view properties."""
|
||||
# The DisplayMode is updated automatically but the new values are
|
||||
# switched: "2D text" becomes "World" and "3D text" becomes "Screen".
|
||||
# It should be the other way around:
|
||||
vobj.DisplayMode = "World" if vobj.DisplayMode == "Screen" else "Screen"
|
||||
_wrn("v0.21, " + obj.Label + ", "
|
||||
+ translate("draft", "renamed 'DisplayMode' options to 'World/Screen'"))
|
||||
|
||||
def __setstate__(self,state):
|
||||
# Before update_properties_0v21 the self.Type value was stored.
|
||||
# We use this to identify older objects that need to be updated.
|
||||
self.Type = state
|
||||
|
||||
|
||||
# Alias for compatibility with v0.18 and earlier
|
||||
DraftText = Text
|
||||
|
||||
Reference in New Issue
Block a user