Core: Add getPlacementOf replacing previous getGlobalPlacement logic. (#26059)

* Core: Add getPlacementOf replacing previous getGlobalPlacement logic.

* Update src/App/DocumentObject.cpp

Co-authored-by: Kacper Donat <kadet1090@gmail.com>

* Update DocumentObject.cpp

* Fix error when called from python with targetObj == None

---------

Co-authored-by: Kacper Donat <kadet1090@gmail.com>
This commit is contained in:
PaddleStroke
2025-12-10 22:47:20 +01:00
committed by GitHub
parent c12ca7b3ba
commit 7a8135d863
11 changed files with 368 additions and 35 deletions

View File

@@ -383,7 +383,7 @@ def getGlobalPlacement(ref, targetObj=None):
rootObj = ref[0]
subName = ref[1][0]
return App.GeoFeature.getGlobalPlacementOf(targetObj, rootObj, subName)
return rootObj.getPlacementOf(subName, targetObj)
def isThereOneRootAssembly():

View File

@@ -253,6 +253,54 @@ class DraftLink(DraftObject):
else:
obj.setPropertyStatus("PlacementList", "Immutable")
def getPlacementOf(self, fp, subname, targetObj=None):
"""
Return the placement of the sub-object relative to the link object.
"""
# _getShowElementValue is mapped to ExpandArray.
if getattr(fp, "ExpandArray", False):
# Return None to fall back to the C++ implementation
return None
# We start with the object's own placement.
plc = fp.Placement
if not subname:
return plc
names = subname.split(".")
linked_obj = getattr(fp, "Base", None)
if not names or fp == targetObj or not linked_obj:
return plc
doc = linked_obj.Document
try:
i = int(names[0])
except ValueError:
return None
# Check bounds in PlacementList
plcs = fp.PlacementList
if i < 0 or i >= len(plcs):
return plc
# Accumulate the element placement
plc = plc * plcs[i]
if len(names) < 2:
return plc
subObj = doc.getObject(names[1])
if not subObj:
return plc
newSub = ".".join(names[2:])
return plc * subObj.getPlacementOf(newSub, targetObj)
# Alias for compatibility with old versions of v0.19
_DraftLink = DraftLink