BIM: Improve onChanged Placement code

* Switched Component code to new Comp=True version of code.
* Made the Placement code in both files identical. This also solves that Rotating a BuildingPart was not propagated to children.
This commit is contained in:
Roy-043
2024-12-08 17:32:45 +01:00
committed by Yorik van Havre
parent 5532001e8b
commit 8d0efd4b21
2 changed files with 34 additions and 53 deletions

View File

@@ -315,36 +315,27 @@ class Component(ArchIFC.IfcProduct):
prop: string
The name of the property that has changed.
"""
import math
ArchIFC.IfcProduct.onChanged(self, obj, prop)
if prop == "Placement":
if hasattr(self,"oldPlacement"):
if self.oldPlacement:
deltap = obj.Placement.Base.sub(self.oldPlacement.Base)
if deltap.Length == 0:
deltap = None
deltar = obj.Placement.Rotation * self.oldPlacement.Rotation.inverted()
if deltar.Angle < 0.0001:
deltar = None
for child in self.getMovableChildren(obj):
if deltar:
import math
# Code for V1.0:
# child.Placement.rotate(self.oldPlacement.Base,
# deltar.Axis,
# math.degrees(deltar.Angle),
# comp=True)
# Workaround solution for V0.20.3 backport:
# See: https://forum.freecad.org/viewtopic.php?p=613196#p613196
offset_rotation = FreeCAD.Placement(FreeCAD.Vector(0, 0, 0),
FreeCAD.Rotation(deltar.Axis, math.degrees(deltar.Angle)),
self.oldPlacement.Base)
child.Placement = offset_rotation * child.Placement
# End workaround solution.
if deltap:
child.Placement.move(deltap)
if hasattr(self,"oldPlacement") and self.oldPlacement != obj.Placement:
deltap = obj.Placement.Base.sub(self.oldPlacement.Base)
if deltap.Length == 0:
deltap = None
deltar = obj.Placement.Rotation * self.oldPlacement.Rotation.inverted()
if deltar.Angle < 0.0001:
deltar = None
for child in self.getMovableChildren(obj):
if deltar:
child.Placement.rotate(self.oldPlacement.Base,
deltar.Axis,
math.degrees(deltar.Angle),
comp=True)
if deltap:
child.Placement.move(deltap)
def getMovableChildren(self,obj):
"""Find the component's children set to move with their host.