From be1412831bc5d7d8241be89d26acf426cf4b3c20 Mon Sep 17 00:00:00 2001 From: vocx-fc Date: Wed, 6 May 2020 13:11:44 -0500 Subject: [PATCH] Draft: update ViewProviderDraft properties The improvements are done to `ViewProviderDraft` which propagates to the majority of the Draft objects by derived classes like `ViewProviederWire`. The initialization of the properties is moved to a method `_set_properties`. The properties `Pattern` and `PatternSize` are created only if they do not exist. This allows calling `ViewProviderDraft(obj.ViewObject)` to migrate an older object to this viewprovider but without adding duplicated properties. In particular, this is done to support the migration of the older `Fillet` object. --- src/Mod/Draft/draftviewproviders/view_base.py | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Mod/Draft/draftviewproviders/view_base.py b/src/Mod/Draft/draftviewproviders/view_base.py index 466ffe0180..287740678a 100644 --- a/src/Mod/Draft/draftviewproviders/view_base.py +++ b/src/Mod/Draft/draftviewproviders/view_base.py @@ -93,18 +93,28 @@ class ViewProviderDraft(object): self.texture = None self.texcoords = None - vobj.addProperty("App::PropertyEnumeration", "Pattern", "Draft", - QT_TRANSLATE_NOOP("App::Property", - "Defines a hatch pattern")) - vobj.addProperty("App::PropertyFloat", "PatternSize", "Draft", - QT_TRANSLATE_NOOP("App::Property", - "Sets the size of the pattern")) - vobj.Pattern = ["None"] + list(utils.svg_patterns().keys()) - vobj.PatternSize = 1 - + self._set_properties(vobj) # This class is assigned to the Proxy attribute vobj.Proxy = self + def _set_properties(self, vobj): + """Set the properties of objects if they don't exist.""" + if not hasattr(vobj, "Pattern"): + _tip = "Defines a hatch pattern." + vobj.addProperty("App::PropertyEnumeration", + "Pattern", + "Draft", + QT_TRANSLATE_NOOP("App::Property", _tip)) + vobj.Pattern = ["None"] + list(utils.svg_patterns().keys()) + + if not hasattr(vobj, "PatternSize"): + _tip = "Defines the size of the hatch pattern." + vobj.addProperty("App::PropertyFloat", + "PatternSize", + "Draft", + QT_TRANSLATE_NOOP("App::Property", _tip)) + vobj.PatternSize = 1 + def __getstate__(self): """Return a tuple of all serializable objects or None. @@ -138,7 +148,7 @@ class ViewProviderDraft(object): so nothing needs to be done here, and it returns `None`. Parameters - --------- + ---------- state : state A serialized object. @@ -167,7 +177,7 @@ class ViewProviderDraft(object): return def updateData(self, obj, prop): - """This method is run when an object property is changed. + """Run when an object property is changed. Override this method to handle the behavior of the view provider depending on changes that occur to the real object's properties. @@ -241,7 +251,7 @@ class ViewProviderDraft(object): return mode def onChanged(self, vobj, prop): - """This method is run when a view property is changed. + """Run when a view property is changed. Override this method to handle the behavior of the view provider depending on changes that occur to its properties @@ -334,7 +344,7 @@ class ViewProviderDraft(object): self.texcoords.directionT.setValue(vT.x, vT.y, vT.z) def execute(self, vobj): - """This method is run when the object is created or recomputed. + """Run when the object is created or recomputed. Override this method to produce effects when the object is newly created, and whenever the document is recomputed.