From a79664d3e39e471a6dd8915cd6a944e0e0806d5b Mon Sep 17 00:00:00 2001 From: vocx-fc Date: Wed, 6 May 2020 14:12:41 -0500 Subject: [PATCH] Draft: small updates to the Annotation class This annotation class implements `onDocumentRestored` in order to add the `ScaleMultiplier` property to older `Dimension`, `Label`, and `Text` objects. --- .../Draft/draftobjects/draft_annotation.py | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/Mod/Draft/draftobjects/draft_annotation.py b/src/Mod/Draft/draftobjects/draft_annotation.py index 49274b0c96..52e1a47133 100644 --- a/src/Mod/Draft/draftobjects/draft_annotation.py +++ b/src/Mod/Draft/draftobjects/draft_annotation.py @@ -26,60 +26,61 @@ # \ingroup DRAFT # \brief This module provides the object code for Draft Annotation. -import FreeCAD as App from PySide.QtCore import QT_TRANSLATE_NOOP -from draftutils import gui_utils + +from draftutils.messages import _wrn +from draftutils.translate import _tr + class DraftAnnotation(object): """The Draft Annotation Base object. This class is not used directly, but inherited by all Draft annotation objects. - + LinearDimension through DimensionBase AngularDimension through DimensionBase Label Text """ - def __init__(self, obj, tp="Annotation"): - """Add general Annotation properties to the object""" + def __init__(self, obj, tp="Annotation"): self.Type = tp - def onDocumentRestored(self, obj): - '''Check if new properties are present after object is recreated.''' + """Run when the document that is using this class is restored. + + Check if new properties are present after the object is restored + in order to migrate older objects. + """ if hasattr(obj, "ViewObject") and obj.ViewObject: - if not 'ScaleMultiplier' in obj.ViewObject.PropertiesList: + if not hasattr(obj.ViewObject, 'ScaleMultiplier'): # annotation properties - _msg = QT_TRANSLATE_NOOP("Draft", - "Adding property ScaleMultiplier to ") - App.Console.PrintMessage(_msg + obj.Name + "\n") - obj.ViewObject.addProperty("App::PropertyFloat","ScaleMultiplier", - "Annotation",QT_TRANSLATE_NOOP("App::Property", - "Dimension size overall multiplier")) - obj.ViewObject.ScaleMultiplier = 1.00 + vobj = obj.ViewObject + _tip = "Dimension size overall multiplier" + vobj.addProperty("App::PropertyFloat", + "ScaleMultiplier", + "Annotation", + QT_TRANSLATE_NOOP("App::Property", _tip)) + vobj.ScaleMultiplier = 1.00 + + _info = "added view property 'ScaleMultiplier'" + _wrn("v0.19, " + obj.Label + ", " + _tr(_info)) def __getstate__(self): return self.Type - - def __setstate__(self,state): + def __setstate__(self, state): if state: - if isinstance(state,dict) and ("Type" in state): + if isinstance(state, dict) and ("Type" in state): self.Type = state["Type"] else: self.Type = state - - def execute(self,obj): - '''Do something when recompute object''' - + def execute(self, obj): + """Do something when recompute object.""" return - def onChanged(self, obj, prop): - '''Do something when a property has changed''' - + """Do something when a property has changed.""" return -