From 20219c7e2812eeff90b461ef80f23521ddfb7135 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Sat, 31 Aug 2024 09:26:54 +0200 Subject: [PATCH] Assembly: Replace Offset and Rotation properties by Offset1 and Offset2, giving full control over JCS positions. --- src/Mod/Assembly/JointObject.py | 100 +++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/src/Mod/Assembly/JointObject.py b/src/Mod/Assembly/JointObject.py index 6d04c7afd1..110ed3676e 100644 --- a/src/Mod/Assembly/JointObject.py +++ b/src/Mod/Assembly/JointObject.py @@ -200,6 +200,7 @@ class Joint: def createProperties(self, joint): self.migrationScript(joint) self.migrationScript2(joint) + self.migrationScript3(joint) # First Joint Connector if not hasattr(joint, "Reference1"): @@ -232,6 +233,17 @@ class Joint: ), ) + if not hasattr(joint, "Offset1"): + joint.addProperty( + "App::PropertyPlacement", + "Offset1", + "Joint Connector 1", + QT_TRANSLATE_NOOP( + "App::Property", + "This is the attachment offset of the first connector of the joint.", + ), + ) + # Second Joint Connector if not hasattr(joint, "Reference2"): joint.addProperty( @@ -263,6 +275,17 @@ class Joint: ), ) + if not hasattr(joint, "Offset2"): + joint.addProperty( + "App::PropertyPlacement", + "Offset2", + "Joint Connector 2", + QT_TRANSLATE_NOOP( + "App::Property", + "This is the attachment offset of the second connector of the joint.", + ), + ) + # Other properties if not hasattr(joint, "Distance"): joint.addProperty( @@ -286,28 +309,6 @@ class Joint: ), ) - if not hasattr(joint, "Rotation"): - joint.addProperty( - "App::PropertyFloat", - "Rotation", - "Joint", - QT_TRANSLATE_NOOP( - "App::Property", - "This is the rotation of the joint.", - ), - ) - - if not hasattr(joint, "Offset"): - joint.addProperty( - "App::PropertyVector", - "Offset", - "Joint", - QT_TRANSLATE_NOOP( - "App::Property", - "This is the offset vector of the joint.", - ), - ) - if not hasattr(joint, "Activated"): joint.addProperty( "App::PropertyBool", @@ -499,6 +500,36 @@ class Joint: joint.Reference2 = [obj, [elt, vtx]] + def migrationScript3(self, joint): + if hasattr(joint, "Offset"): + current_offset = joint.Offset # App.Vector + current_rotation = joint.Rotation # float + + joint.removeProperty("Offset") + joint.removeProperty("Rotation") + + joint.addProperty( + "App::PropertyPlacement", + "Offset1", + "Joint Connector 1", + QT_TRANSLATE_NOOP( + "App::Property", + "This is the attachment offset of the first connector of the joint.", + ), + ) + + joint.addProperty( + "App::PropertyPlacement", + "Offset2", + "Joint Connector 2", + QT_TRANSLATE_NOOP( + "App::Property", + "This is the attachment offset of the second connector of the joint.", + ), + ) + + joint.Offset2 = App.Placement(current_offset, App.Rotation(current_rotation, 0, 0)) + def dumps(self): return None @@ -523,7 +554,7 @@ class Joint: if App.isRestoring(): return - if prop == "Rotation" or prop == "Offset": + if prop == "Offset1" or prop == "Offset2": if joint.Reference1 is None or joint.Reference2 is None: return @@ -604,12 +635,11 @@ class Joint: ignoreVertex = joint.JointType == "Distance" plc = UtilsAssembly.findPlacement(ref, ignoreVertex) - # We apply rotation / reverse / offset it necessary, but only to the second JCS. - if index == 1: - if joint.Offset.Length != 0.0: - plc = UtilsAssembly.applyOffsetToPlacement(plc, joint.Offset) - if joint.Rotation != 0.0: - plc = UtilsAssembly.applyRotationToPlacement(plc, joint.Rotation) + # We apply the attachment offsets. + if index == 0: + plc = plc * joint.Offset1 + else: + plc = plc * joint.Offset2 return plc @@ -1482,10 +1512,12 @@ class TaskAssemblyCreateJoint(QtCore.QObject): self.joint.Distance2 = self.form.distanceSpinbox2.property("rawValue") def onOffsetChanged(self, quantity): - self.joint.Offset = App.Vector(0, 0, self.form.offsetSpinbox.property("rawValue")) + self.joint.Offset2.Base = App.Vector(0, 0, self.form.offsetSpinbox.property("rawValue")) def onRotationChanged(self, quantity): - self.joint.Rotation = self.form.rotationSpinbox.property("rawValue") + yaw = self.form.rotationSpinbox.property("rawValue") + ypr = self.joint.Offset2.Rotation.getYawPitchRoll() + self.joint.Offset2.Rotation.setYawPitchRoll(yaw, ypr[1], ypr[2]) def onLimitLenMinChanged(self, quantity): if self.form.limitCheckbox1.isChecked(): @@ -1638,8 +1670,10 @@ class TaskAssemblyCreateJoint(QtCore.QObject): self.form.distanceSpinbox.setProperty("rawValue", self.joint.Distance) self.form.distanceSpinbox2.setProperty("rawValue", self.joint.Distance2) - self.form.offsetSpinbox.setProperty("rawValue", self.joint.Offset.z) - self.form.rotationSpinbox.setProperty("rawValue", self.joint.Rotation) + self.form.offsetSpinbox.setProperty("rawValue", self.joint.Offset2.Base.z) + self.form.rotationSpinbox.setProperty( + "rawValue", self.joint.Offset2.Rotation.getYawPitchRoll()[0] + ) self.form.limitCheckbox1.setChecked(self.joint.EnableLengthMin) self.form.limitCheckbox2.setChecked(self.joint.EnableLengthMax)