From 632780ce359f45b4561979433f26ac7a1d7f5145 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Wed, 26 Jun 2024 17:05:04 +0200 Subject: [PATCH] Assembly: Create Joint limit: Moving objects updates the spinboxes values if they are disabled. --- src/Mod/Assembly/JointObject.py | 35 +++++++++++++++++++++++++++---- src/Mod/Assembly/UtilsAssembly.py | 25 ++++++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/Mod/Assembly/JointObject.py b/src/Mod/Assembly/JointObject.py index 63f6d85e5b..87cbfce3ca 100644 --- a/src/Mod/Assembly/JointObject.py +++ b/src/Mod/Assembly/JointObject.py @@ -1482,16 +1482,20 @@ class TaskAssemblyCreateJoint(QtCore.QObject): self.joint.Rotation = self.form.rotationSpinbox.property("rawValue") def onLimitLenMinChanged(self, quantity): - self.joint.LengthMin = self.form.limitLenMinSpinbox.property("rawValue") + if self.form.limitCheckbox1.isChecked(): + self.joint.LengthMin = self.form.limitLenMinSpinbox.property("rawValue") def onLimitLenMaxChanged(self, quantity): - self.joint.LengthMax = self.form.limitLenMaxSpinbox.property("rawValue") + if self.form.limitCheckbox2.isChecked(): + self.joint.LengthMax = self.form.limitLenMaxSpinbox.property("rawValue") def onLimitRotMinChanged(self, quantity): - self.joint.AngleMin = self.form.limitRotMinSpinbox.property("rawValue") + if self.form.limitCheckbox3.isChecked(): + self.joint.AngleMin = self.form.limitRotMinSpinbox.property("rawValue") def onLimitRotMaxChanged(self, quantity): - self.joint.AngleMax = self.form.limitRotMaxSpinbox.property("rawValue") + if self.form.limitCheckbox4.isChecked(): + self.joint.AngleMax = self.form.limitRotMaxSpinbox.property("rawValue") def onReverseClicked(self): self.joint.Proxy.flipOnePart(self.joint) @@ -1587,6 +1591,8 @@ class TaskAssemblyCreateJoint(QtCore.QObject): self.form.limitLenMaxSpinbox.show() self.form.limitLenMinSpinbox.setEnabled(self.joint.EnableLengthMin) self.form.limitLenMaxSpinbox.setEnabled(self.joint.EnableLengthMax) + self.onLimitLenMinChanged(0) # dummy value + self.onLimitLenMaxChanged(0) else: self.form.limitCheckbox1.hide() self.form.limitCheckbox2.hide() @@ -1600,6 +1606,8 @@ class TaskAssemblyCreateJoint(QtCore.QObject): self.form.limitRotMaxSpinbox.show() self.form.limitRotMinSpinbox.setEnabled(self.joint.EnableAngleMin) self.form.limitRotMaxSpinbox.setEnabled(self.joint.EnableAngleMax) + self.onLimitRotMinChanged(0) + self.onLimitRotMaxChanged(0) else: self.form.limitCheckbox3.hide() self.form.limitCheckbox4.hide() @@ -1721,6 +1729,23 @@ class TaskAssemblyCreateJoint(QtCore.QObject): simplified_names.append(sname) self.form.featureList.addItems(simplified_names) + def updateLimits(self): + needLengthLimits = self.jType in JointUsingLimitLength + needAngleLimits = self.jType in JointUsingLimitAngle + if needLengthLimits: + distance = UtilsAssembly.getJointDistance(self.joint) + if not self.form.limitCheckbox1.isChecked(): + self.form.limitLenMinSpinbox.setProperty("rawValue", distance) + if not self.form.limitCheckbox2.isChecked(): + self.form.limitLenMaxSpinbox.setProperty("rawValue", distance) + + if needAngleLimits: + angle = UtilsAssembly.getJointXYAngle(self.joint) / math.pi * 180 + if not self.form.limitCheckbox3.isChecked(): + self.form.limitRotMinSpinbox.setProperty("rawValue", angle) + if not self.form.limitCheckbox4.isChecked(): + self.form.limitRotMaxSpinbox.setProperty("rawValue", angle) + def moveMouse(self, info): if len(self.current_selection) >= 2 or ( len(self.current_selection) == 1 @@ -1730,6 +1755,8 @@ class TaskAssemblyCreateJoint(QtCore.QObject): ) ): self.joint.ViewObject.Proxy.showPreviewJCS(False) + if len(self.current_selection) >= 2: + self.updateLimits() return cursor_pos = self.view.getCursorPos() diff --git a/src/Mod/Assembly/UtilsAssembly.py b/src/Mod/Assembly/UtilsAssembly.py index f6fa9bb15e..8f778d1ba6 100644 --- a/src/Mod/Assembly/UtilsAssembly.py +++ b/src/Mod/Assembly/UtilsAssembly.py @@ -21,6 +21,8 @@ # * # **************************************************************************/ +import math + import FreeCAD as App import Part @@ -1044,3 +1046,26 @@ def getAssemblyShapes(assembly): shapes.append(part.Shape) return shapes + + +def getJointDistance(joint): + plc1 = getJcsGlobalPlc(joint.Placement1, joint.Object1, joint.Part1) + plc2 = getJcsGlobalPlc(joint.Placement2, joint.Object2, joint.Part2) + + # Find the sign + sign = 1 + plc3 = plc1.inverse() * plc2 # plc3 is plc2 relative to plc1 + if plc3.Base.z < 0: + sign = -1 + + return sign * (plc1.Base - plc2.Base).Length + + +def getJointXYAngle(joint): + plc1 = getJcsGlobalPlc(joint.Placement1, joint.Object1, joint.Part1) + plc2 = getJcsGlobalPlc(joint.Placement2, joint.Object2, joint.Part2) + + plc3 = plc1.inverse() * plc2 # plc3 is plc2 relative to plc1 + x_axis = plc3.Rotation.multVec(App.Vector(1, 0, 0)) + + return math.atan2(x_axis.y, x_axis.x)