From 5d6b447149bbb20148d6ec4af722b533ff2cfe70 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Sat, 11 Feb 2023 17:09:02 +0100 Subject: [PATCH] [Draft] some arrays did not have a Count property (#8433) --- src/Mod/Draft/draftobjects/array.py | 42 ++++++++++++++++--------- src/Mod/Draft/draftobjects/draftlink.py | 6 ++-- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/Mod/Draft/draftobjects/array.py b/src/Mod/Draft/draftobjects/array.py index 284c7de8ee..39bae428f1 100644 --- a/src/Mod/Draft/draftobjects/array.py +++ b/src/Mod/Draft/draftobjects/array.py @@ -39,6 +39,9 @@ from PySide.QtCore import QT_TRANSLATE_NOOP import FreeCAD as App import DraftVecUtils +from draftutils.messages import _wrn +from draftutils.translate import translate + from draftobjects.draftlink import DraftLink @@ -60,6 +63,17 @@ class Array(DraftLink): self.set_properties(obj) super(Array, self).attach(obj) + def onDocumentRestored(self, obj): + if hasattr(obj, "Count"): + return + self.update_properties_0v21(obj) + + def update_properties_0v21(self, obj): + self.set_general_properties(obj) + self.execute(obj) # Required to update Count to the correct value. + _wrn("v0.21, " + obj.Label + ", " + + translate("draft", "added property 'Count'")) + def set_properties(self, obj): """Set properties only if they don't exist.""" self.set_ortho_properties(obj) @@ -112,6 +126,20 @@ class Array(DraftLink): _tip) obj.Fuse = False + if "Count" not in properties: + _tip = QT_TRANSLATE_NOOP("App::Property", + "Total number of elements " + "in the array.\n" + "This property is read-only, " + "as the number depends " + "on the parameters of the array.") + obj.addProperty("App::PropertyInteger", + "Count", + "Objects", + _tip) + obj.Count = 0 + obj.setEditorMode("Count", 1) # Read only + def set_ortho_properties(self, obj): """Set orthogonal properties only if they don't exist.""" properties = obj.PropertiesList @@ -299,20 +327,6 @@ class Array(DraftLink): properties = obj.PropertiesList if self.use_link: - if "Count" not in properties: - _tip = QT_TRANSLATE_NOOP("App::Property", - "Total number of elements " - "in the array.\n" - "This property is read-only, " - "as the number depends " - "on the parameters of the array.") - obj.addProperty("App::PropertyInteger", - "Count", - "Objects", - _tip) - obj.Count = 0 - obj.setEditorMode("Count", 1) # Read only - if "ExpandArray" not in properties: _tip = QT_TRANSLATE_NOOP("App::Property", "Show the individual array elements " diff --git a/src/Mod/Draft/draftobjects/draftlink.py b/src/Mod/Draft/draftobjects/draftlink.py index 99aaefb1cf..47b51b77e5 100644 --- a/src/Mod/Draft/draftobjects/draftlink.py +++ b/src/Mod/Draft/draftobjects/draftlink.py @@ -186,12 +186,14 @@ class DraftLink(DraftObject): def buildShape(self, obj, pl, pls): """Build the shape of the link object.""" + if obj.Count != len(pls): + obj.Count = len(pls) + if self.use_link: - if not getattr(obj, 'ExpandArray', False) or obj.Count != len(pls): + if not getattr(obj, 'ExpandArray', False): obj.setPropertyStatus('PlacementList', '-Immutable') obj.PlacementList = pls obj.setPropertyStatus('PlacementList', 'Immutable') - obj.Count = len(pls) if getattr(obj, 'ExpandArray', False) \ and getattr(obj, 'AlwaysSyncPlacement', False): for pla,child in zip(pls,obj.ElementList):