Skip to content

Commit

Permalink
Draft: update ViewProviderDraft properties
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vocx-fc authored and yorikvanhavre committed May 12, 2020
1 parent de9c9a6 commit be14128
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/Mod/Draft/draftviewproviders/view_base.py
Expand Up @@ -93,18 +93,28 @@ def __init__(self, vobj):
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.
Expand Down Expand Up @@ -138,7 +148,7 @@ def __setstate__(self, state):
so nothing needs to be done here, and it returns `None`.
Parameters
---------
----------
state : state
A serialized object.
Expand Down Expand Up @@ -167,7 +177,7 @@ def attach(self, vobj):
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.
Expand Down Expand Up @@ -241,7 +251,7 @@ def setDisplayMode(self, mode):
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
Expand Down Expand Up @@ -334,7 +344,7 @@ def _update_pattern_size(self, vobj):
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.
Expand Down

0 comments on commit be14128

Please sign in to comment.