Skip to content

Commit

Permalink
Draft: clean up the internal DraftAnnotation class
Browse files Browse the repository at this point in the history
Add a function to clarify the added properties,
and clean up the PEP8 style of the code.
  • Loading branch information
vocx-fc authored and yorikvanhavre committed Jun 17, 2020
1 parent dd526ef commit 9d0e425
Showing 1 changed file with 50 additions and 20 deletions.
70 changes: 50 additions & 20 deletions src/Mod/Draft/draftobjects/draft_annotation.py
@@ -1,5 +1,6 @@
# ***************************************************************************
# * (c) 2020 Carlo Pavan *
# * Copyright (c) 2020 Carlo Pavan <carlopav@gmail.com> *
# * Copyright (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
Expand All @@ -20,11 +21,19 @@
# * USA *
# * *
# ***************************************************************************
"""This module provides the object code for Draft Annotation.
"""Provide the basic object code for all Draft annotation objects.
This is used by many objects that show dimensions and text created on screen
through Coin (pivy).
- DimensionBase
- LinearDimension
- AngularDimension
- Label
- Text
"""
## @package annotation
## @package draft_annotation
# \ingroup DRAFT
# \brief This module provides the object code for Draft Annotation.
# \brief Provide the basic object code for all Draft annotation objects.

from PySide.QtCore import QT_TRANSLATE_NOOP

Expand All @@ -44,41 +53,62 @@ class DraftAnnotation(object):
Text
"""

def __init__(self, obj, tp="Annotation"):
self.Type = tp
def __init__(self, obj, typ="Annotation"):
self.Type = typ
obj.Proxy = self

def onDocumentRestored(self, obj):
"""Run when the document that is using this class is restored.
"""Execute code when the document 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 hasattr(obj.ViewObject, 'ScaleMultiplier'):
# annotation properties
vobj = obj.ViewObject
_tip = QT_TRANSLATE_NOOP("App::Property",
"Dimension size overall multiplier")
vobj.addProperty("App::PropertyFloat", "ScaleMultiplier", "Annotation", _tip)
vobj.ScaleMultiplier = 1.00

_info = "added view property 'ScaleMultiplier'"
_wrn("v0.19, " + obj.Label + ", " + _tr(_info))
self.add_missing_properties_0v19(obj)

def add_missing_properties_0v19(self, obj):
"""Provide missing annotation properties, if they don't exist."""
if (hasattr(obj, "ViewObject") and obj.ViewObject
and not hasattr(obj.ViewObject, 'ScaleMultiplier')):
vobj = obj.ViewObject
_tip = QT_TRANSLATE_NOOP("App::Property",
"Dimension size overall multiplier")
vobj.addProperty("App::PropertyFloat",
"ScaleMultiplier",
"Annotation",
_tip)
vobj.ScaleMultiplier = 1.00

_info = "added view property 'ScaleMultiplier'"
_wrn("v0.19, " + obj.Label + ", " + _tr(_info))

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):
self.Type = state["Type"]
else:
self.Type = state

def execute(self, obj):
"""Do something when recompute object."""
"""Execute when the object is created or recomputed.
Does nothing.
"""
return

def onChanged(self, obj, prop):
"""Do something when a property has changed."""
"""Execute when a property is changed.
Does nothing.
"""
return

0 comments on commit 9d0e425

Please sign in to comment.