From 0651883feb60c4cd64617c746ca15cee8ca485f4 Mon Sep 17 00:00:00 2001 From: Roy-043 Date: Thu, 28 Mar 2024 12:03:46 +0100 Subject: [PATCH] Draft: add Fuse property to patharray and pathtwistedarray See #13172. --- src/Mod/Draft/draftobjects/patharray.py | 51 ++++++++++--------- .../Draft/draftobjects/pathtwistedarray.py | 28 +++++++--- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/Mod/Draft/draftobjects/patharray.py b/src/Mod/Draft/draftobjects/patharray.py index 86cfa58bc6..be49d37af3 100644 --- a/src/Mod/Draft/draftobjects/patharray.py +++ b/src/Mod/Draft/draftobjects/patharray.py @@ -135,7 +135,7 @@ class PathArray(DraftLink): """ def __init__(self, obj): - super(PathArray, self).__init__(obj, "PathArray") + super().__init__(obj, "PathArray") def attach(self, obj): """Set up the properties when the object is attached. @@ -155,7 +155,7 @@ class PathArray(DraftLink): to attach the proxy before creating the C++ view provider. """ self.set_properties(obj) - super(PathArray, self).attach(obj) + super().attach(obj) def set_properties(self, obj): """Set properties only if they don't exist.""" @@ -203,6 +203,17 @@ class PathArray(DraftLink): _tip) obj.PathSubelements = [] + if "Fuse" not in properties: + _tip = QT_TRANSLATE_NOOP("App::Property", + "Specifies if the copies " + "should be fused together " + "if they touch each other (slower)") + obj.addProperty("App::PropertyBool", + "Fuse", + "Objects", + _tip) + obj.Fuse = False + if "Count" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property","Number of copies to create") obj.addProperty("App::PropertyInteger", @@ -291,7 +302,7 @@ class PathArray(DraftLink): def linkSetup(self, obj): """Set up the object as a link object.""" - super(PathArray, self).linkSetup(obj) + super().linkSetup(obj) obj.configLinkProperty(ElementCount='Count') def execute(self, obj): @@ -361,7 +372,7 @@ class PathArray(DraftLink): def onChanged(self, obj, prop): """Execute when a property is changed.""" - super(PathArray, self).onChanged(obj, prop) + super().onChanged(obj, prop) self.show_and_hide(obj, prop) def show_and_hide(self, obj, prop): @@ -400,34 +411,24 @@ class PathArray(DraftLink): obj.setPropertyStatus(pr, "Hidden") def onDocumentRestored(self, obj): - """Execute code when the document is restored. - - Add properties that don't exist. - """ + super().onDocumentRestored(obj) + # Fuse property was added in v0.22, obj should be OK if it is present: + if hasattr(obj, "Fuse"): + return self.set_properties(obj) - self.migrate_properties_0v19(obj) - super(PathArray, self).onDocumentRestored(obj) - - def migrate_properties_0v19(self, obj): - """Migrate properties of this class, not from the parent class.""" - properties = obj.PropertiesList - - if "PathObj" in properties: + if hasattr(obj, "PathObj"): + _wrn("v0.19, " + obj.Label + ", " + translate("draft", "migrated 'PathObj' property to 'PathObject'")) obj.PathObject = obj.PathObj obj.removeProperty("PathObj") - _wrn("v0.19, " + obj.Label + ", " + translate("draft","'PathObj' property will be migrated to 'PathObject'")) - - if "PathSubs" in properties: + if hasattr(obj, "PathSubs"): + _wrn("v0.19, " + obj.Label + ", " + translate("draft", "migrated 'PathSubs' property to 'PathSubelements'")) obj.PathSubelements = obj.PathSubs obj.removeProperty("PathSubs") - _info = "'PathSubs' property will be migrated to 'PathSubelements'" - _wrn("v0.19, " + obj.Label + ", " + translate("draft","'PathObj' property will be migrated to 'PathObject'")) - - if "Xlate" in properties: + if hasattr(obj, "Xlate"): + _wrn("v0.19, " + obj.Label + ", " + translate("draft", "migrated 'Xlate' property to 'ExtraTranslation'")) obj.ExtraTranslation = obj.Xlate obj.removeProperty("Xlate") - _info = "'Xlate' property will be migrated to 'ExtraTranslation'" - _wrn("v0.19, " + obj.Label + ", " + translate("draft","'PathObj' property will be migrated to 'PathObject'")) + _wrn("v0.22, " + obj.Label + ", " + translate("draft", "added 'Fuse' property")) # Alias for compatibility with v0.18 and earlier diff --git a/src/Mod/Draft/draftobjects/pathtwistedarray.py b/src/Mod/Draft/draftobjects/pathtwistedarray.py index efdec97a69..4496806dbe 100644 --- a/src/Mod/Draft/draftobjects/pathtwistedarray.py +++ b/src/Mod/Draft/draftobjects/pathtwistedarray.py @@ -48,6 +48,7 @@ object in the Arch Workbench. # \brief Provides the object code for the TwistedArray object. import draftgeoutils.geo_arrays as geo +from draftutils.messages import _wrn from draftutils.translate import translate def QT_TRANSLATE_NOOP(ctx,txt): return txt from draftobjects.draftlink import DraftLink @@ -65,12 +66,12 @@ class PathTwistedArray(DraftLink): """ def __init__(self, obj): - super(PathTwistedArray, self).__init__(obj, "PathTwistedArray") + super().__init__(obj, "PathTwistedArray") def attach(self, obj): """Set up the properties when the object is attached.""" self.set_properties(obj) - super(PathTwistedArray, self).attach(obj) + super().attach(obj) def set_properties(self, obj): """Set properties only if they don't exist.""" @@ -93,6 +94,17 @@ class PathTwistedArray(DraftLink): QT_TRANSLATE_NOOP("App::Property","The object along which the copies will be distributed. It must contain 'Edges'.")) obj.PathObject = None + if "Fuse" not in properties: + _tip = QT_TRANSLATE_NOOP("App::Property", + "Specifies if the copies " + "should be fused together " + "if they touch each other (slower)") + obj.addProperty("App::PropertyBool", + "Fuse", + "Objects", + _tip) + obj.Fuse = False + if "Count" not in properties: obj.addProperty("App::PropertyInteger", "Count", @@ -117,16 +129,16 @@ class PathTwistedArray(DraftLink): def linkSetup(self, obj): """Set up the object as a link object.""" - super(PathTwistedArray, self).linkSetup(obj) + super().linkSetup(obj) obj.configLinkProperty(ElementCount='Count') def onDocumentRestored(self, obj): - """Execute code when the document is restored. - - Add properties that don't exist. - """ + super().onDocumentRestored(obj) + # Fuse property was added in v0.22, obj should be OK if it is present: + if hasattr(obj, "Fuse"): + return self.set_properties(obj) - super(PathTwistedArray, self).onDocumentRestored(obj) + _wrn("v0.22, " + obj.Label + ", " + translate("draft", "added 'Fuse' property")) def execute(self, obj): """Execute when the object is created or recomputed."""