import draftgeoutils.geo_arrays as geo
from draftutils.messages import _log
def QT_TRANSLATE_NOOP(ctx, txt):
return txt
from draftobjects.draftlink import DraftLink
class PathTwistedArray(DraftLink):
def __init__(self, obj):
super().__init__(obj, "PathTwistedArray")
def attach(self, obj):
self.set_properties(obj)
super().attach(obj)
def set_properties(self, obj):
if hasattr(obj, "PropertiesList"):
properties = obj.PropertiesList
else:
properties = []
if "Base" not in properties:
obj.addProperty(
"App::PropertyLink",
"Base",
"Objects",
QT_TRANSLATE_NOOP("App::Property", "The base object that will be duplicated."),
locked=True,
)
obj.Base = None
if "PathObject" not in properties:
obj.addProperty(
"App::PropertyLink",
"PathObject",
"Objects",
QT_TRANSLATE_NOOP(
"App::Property",
"The object along which the copies will be distributed. It must contain 'Edges'.",
),
locked=True,
)
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, locked=True)
obj.Fuse = False
if "Count" not in properties:
obj.addProperty(
"App::PropertyInteger",
"Count",
"Objects",
QT_TRANSLATE_NOOP("App::Property", "Number of copies to create."),
locked=True,
)
obj.Count = 15
if "RotationFactor" not in properties:
obj.addProperty(
"App::PropertyFloat",
"RotationFactor",
"Objects",
QT_TRANSLATE_NOOP("App::Property", "Rotation factor of the twisted array."),
locked=True,
)
obj.RotationFactor = 0.25
if self.use_link and "ExpandArray" not in properties:
obj.addProperty(
"App::PropertyBool",
"ExpandArray",
"Objects",
QT_TRANSLATE_NOOP(
"App::Property", "Show the individual array elements (only for Link arrays)"
),
locked=True,
)
obj.ExpandArray = False
obj.setPropertyStatus("Shape", "Transient")
if not self.use_link:
if "PlacementList" not in properties:
_tip = QT_TRANSLATE_NOOP("App::Property", "The placement for each array element")
obj.addProperty(
"App::PropertyPlacementList", "PlacementList", "Objects", _tip, locked=True
)
obj.PlacementList = []
def linkSetup(self, obj):
super().linkSetup(obj)
obj.configLinkProperty(ElementCount="Count")
def onDocumentRestored(self, obj):
super().onDocumentRestored(obj)
if hasattr(obj, "Fuse") and hasattr(obj, "PlacementList"):
return
if not hasattr(obj, "Fuse"):
_log("v1.0, " + obj.Name + ", added 'Fuse' property")
if not hasattr(obj, "PlacementList"):
_log("v1.1, " + obj.Name + ", added hidden property 'PlacementList'")
self.set_properties(obj)
self.execute(obj)
def execute(self, obj):
if self.props_changed_placement_only(obj) or not obj.Base or not obj.PathObject:
self.props_changed_clear()
return
array_placement = obj.Placement
path = obj.PathObject
count = obj.Count
rot_factor = obj.RotationFactor
copy_placements, _ = geo.get_twisted_placements(path, count=count, rot_factor=rot_factor)
self.buildShape(obj, array_placement, copy_placements)
self.props_changed_clear()
return not self.use_link