From d8118a4b110ce96b3b2b4d678ca641cf95a115ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20B=C3=A4hr?= Date: Mon, 9 Jan 2023 22:22:35 +0100 Subject: [PATCH] PD: Refactor InvoluteGear's property creation This is a pure refactor, without any change in visibile functionality. However, the new structure allows easy addition of new properties without breaking existing documents. --- src/Mod/PartDesign/InvoluteGearFeature.py | 38 ++++++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/Mod/PartDesign/InvoluteGearFeature.py b/src/Mod/PartDesign/InvoluteGearFeature.py index 22d9f0f0ab..7789b4dd92 100644 --- a/src/Mod/PartDesign/InvoluteGearFeature.py +++ b/src/Mod/PartDesign/InvoluteGearFeature.py @@ -76,20 +76,34 @@ class _InvoluteGear: "The InvoluteGear object" def __init__(self,obj): self.Type = "InvoluteGear" - obj.addProperty("App::PropertyInteger","NumberOfTeeth","Gear","Number of gear teeth") - obj.addProperty("App::PropertyLength","Modules","Gear","Modules of the gear") - obj.addProperty("App::PropertyAngle","PressureAngle","Gear","Pressure angle of gear teeth") - obj.addProperty("App::PropertyBool","HighPrecision","Gear","True=2 curves with each 3 control points False=1 curve with 4 control points ") - obj.addProperty("App::PropertyBool","ExternalGear","Gear","True=external Gear False=internal Gear ") - - obj.NumberOfTeeth = 26 - obj.Modules = "2.5 mm" - obj.PressureAngle = "20 deg" - obj.HighPrecision = True - obj.ExternalGear = True - + self._ensure_properties(obj) obj.Proxy = self + def onDocumentRestored(self, obj): + """hook used to migrate older versions of this object""" + self._ensure_properties(obj) + + def _ensure_properties(self, obj): + def ensure_property(type_, name, doc, default): + if not hasattr(obj, name): + obj.addProperty(type_, name, "Gear", doc) + setattr(obj, name, default) + + ensure_property("App::PropertyInteger", "NumberOfTeeth", + doc="Number of gear teeth", + default=26) + ensure_property("App::PropertyLength", "Modules", + doc="Modules of the gear", + default="2.5 mm") + ensure_property("App::PropertyAngle", "PressureAngle", + doc="Pressure angle of gear teeth", + default="20 deg") + ensure_property("App::PropertyBool", "HighPrecision", + doc="True=2 curves with each 3 control points False=1 curve with 4 control points.", + default=True) + ensure_property("App::PropertyBool", "ExternalGear", + doc="True=external Gear False=internal Gear", + default=True) def execute(self,obj): #print "_InvoluteGear.execute()"