Skip to content

Commit

Permalink
Merge pull request #13172 from Roy-043/Draft-add-Fuse-property-to-poi…
Browse files Browse the repository at this point in the history
…ntarray

Draft: add Fuse property to pointarray
  • Loading branch information
Roy-043 committed Mar 27, 2024
2 parents aa38aec + 723d68f commit ef16eca
Showing 1 changed file with 23 additions and 34 deletions.
57 changes: 23 additions & 34 deletions src/Mod/Draft/draftobjects/pointarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ class PointArray(DraftLink):
"""The Draft Point Array object."""

def __init__(self, obj):
super(PointArray, self).__init__(obj, "PointArray")
super().__init__(obj, "PointArray")

def attach(self, obj):
"""Set up the properties when the object is attached."""
self.set_properties(obj)
super(PointArray, self).attach(obj)
super().attach(obj)

def linkSetup(self, obj):
"""Set up the object as a link object."""
super(PointArray, self).linkSetup(obj)
super().linkSetup(obj)
obj.configLinkProperty(ElementCount='Count')

def set_properties(self, obj):
Expand All @@ -78,6 +78,17 @@ def set_properties(self, obj):
_tip)
obj.PointObject = 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:
_tip = QT_TRANSLATE_NOOP("App::Property", "Number of copies in the array.\nThis property is read-only, as the number depends on the points in 'Point Object'.")

Check warning on line 93 in src/Mod/Draft/draftobjects/pointarray.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Line too long (171/100) (line-too-long)
obj.addProperty("App::PropertyInteger",
Expand Down Expand Up @@ -120,40 +131,18 @@ def execute(self, obj):
return (not self.use_link)

Check warning on line 131 in src/Mod/Draft/draftobjects/pointarray.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Unnecessary parens after 'return' keyword (superfluous-parens)

def onDocumentRestored(self, obj):
"""Execute code when the document is restored.
Add properties that don't exist and migrate old properties.
"""
# If the ExtraPlacement property has never been added before
# it will add it first, and set it to the base object's position
# in order to produce the same displacement as before.
# Then all the other properties will be processed.
properties = obj.PropertiesList

if "ExtraPlacement" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property", "Additional placement, shift and rotation, that will be applied to each copy")
obj.addProperty("App::PropertyPlacement",
"ExtraPlacement",
"Objects",
_tip)
obj.ExtraPlacement.Base = obj.Base.Placement.Base
_wrn("v0.19, " + obj.Label + ", " + translate("draft","added property 'ExtraPlacement'"))

super().onDocumentRestored(obj)
# Fuse property was added in v0.22, obj should be OK if it is present:
if hasattr(obj, "Fuse"):
return
if not hasattr(obj, "ExtraPlacement"):
_wrn("v0.19, " + obj.Label + ", " + translate("draft", "added 'ExtraPlacement' property"))

Check warning on line 139 in src/Mod/Draft/draftobjects/pointarray.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Line too long (102/100) (line-too-long)
self.set_properties(obj)
self.migrate_properties_0v19(obj)
super(PointArray, self).onDocumentRestored(obj)

def migrate_properties_0v19(self, obj):
"""Migrate properties."""
# If the old name still exists, migrate it to the new
# name and delete the old property
properties = obj.PropertiesList

if "PointList" in properties:
if hasattr(obj, "PointList"):
_wrn("v0.19, " + obj.Label + ", " + translate("draft", "migrated 'PointList' property to 'PointObject'"))

Check warning on line 142 in src/Mod/Draft/draftobjects/pointarray.py

View workflow job for this annotation

GitHub Actions / Lint / Lint

Line too long (117/100) (line-too-long)
obj.PointObject = obj.PointList
obj.removeProperty("PointList")
_info = "'PointList' property will be migrated to 'PointObject'"
_wrn("v0.19, " + obj.Label + ", " + translate("draft","added property 'ExtraPlacement'"))
_wrn("v0.22, " + obj.Label + ", " + translate("draft", "added 'Fuse' property"))


def remove_equal_vecs (vec_list):
Expand Down

0 comments on commit ef16eca

Please sign in to comment.