Draft: clean up the internal DraftAnnotation class

Add a function to clarify the added properties,
and clean up the PEP8 style of the code.
This commit is contained in:
vocx-fc
2020-06-12 20:00:24 -05:00
committed by Yorik van Havre
parent b30b31ccb6
commit 63df9aa7dc

View File

@@ -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. *
# * *
@@ -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
@@ -44,31 +53,46 @@ 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
self.add_missing_properties_0v19(obj)
_info = "added view property 'ScaleMultiplier'"
_wrn("v0.19, " + obj.Label + ", " + _tr(_info))
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"]
@@ -76,9 +100,15 @@ class DraftAnnotation(object):
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