From 63df9aa7dc41e3fe1e0703f2247f8998b480001f Mon Sep 17 00:00:00 2001 From: vocx-fc Date: Fri, 12 Jun 2020 20:00:24 -0500 Subject: [PATCH] Draft: clean up the internal DraftAnnotation class Add a function to clarify the added properties, and clean up the PEP8 style of the code. --- .../Draft/draftobjects/draft_annotation.py | 68 +++++++++++++------ 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/src/Mod/Draft/draftobjects/draft_annotation.py b/src/Mod/Draft/draftobjects/draft_annotation.py index 16ef0ecb91..ff6f12f433 100644 --- a/src/Mod/Draft/draftobjects/draft_annotation.py +++ b/src/Mod/Draft/draftobjects/draft_annotation.py @@ -1,5 +1,6 @@ # *************************************************************************** -# * (c) 2020 Carlo Pavan * +# * Copyright (c) 2020 Carlo Pavan * +# * Copyright (c) 2020 Eliud Cabrera Castillo * # * * # * 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