From fe5c883e4cbcdfa104456416b05e2543e46e1ee8 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Mon, 2 Sep 2024 14:00:27 +0200 Subject: [PATCH] Assembly: Joint creation UI : add advanced offset handling. --- .../panels/TaskAssemblyCreateJoint.ui | 161 +++++++++++++----- src/Mod/Assembly/JointObject.py | 40 ++++- src/Mod/Assembly/UtilsAssembly.py | 21 ++- 3 files changed, 171 insertions(+), 51 deletions(-) diff --git a/src/Mod/Assembly/Gui/Resources/panels/TaskAssemblyCreateJoint.ui b/src/Mod/Assembly/Gui/Resources/panels/TaskAssemblyCreateJoint.ui index 4353934916..2f60f15fb1 100644 --- a/src/Mod/Assembly/Gui/Resources/panels/TaskAssemblyCreateJoint.ui +++ b/src/Mod/Assembly/Gui/Resources/panels/TaskAssemblyCreateJoint.ui @@ -82,52 +82,121 @@ - - - - - Offset - - - - - - - - 0 - 0 - - - - mm - - - - - - - - - - - Rotation - - - - - - - - 0 - 0 - - - - deg - - - - + + + Attachement offsets + + + + + + + Simple + + + + + + + + Offset + + + + + + + + 0 + 0 + + + + mm + + + + + + + + + + + Rotation + + + + + + + + 0 + 0 + + + + deg + + + + + + + + + + Advanced + + + + + + + + Offset1 + + + + + + + By clicking this button, you can set the attachement offset of the first marker (coordinate system) of the joint. + + + + + + + + + + + + + + Offset2 + + + + + + + By clicking this button, you can set the attachement offset of the second marker (coordinate system) of the joint. + + + + + + + + + + + + + + diff --git a/src/Mod/Assembly/JointObject.py b/src/Mod/Assembly/JointObject.py index 13e426fee0..a6756cfb69 100644 --- a/src/Mod/Assembly/JointObject.py +++ b/src/Mod/Assembly/JointObject.py @@ -1288,6 +1288,7 @@ class TaskAssemblyCreateJoint(QtCore.QObject): global activeTask activeTask = self + self.blockOffsetRotation = False self.assembly = UtilsAssembly.activeAssembly() if not self.assembly: @@ -1324,7 +1325,8 @@ class TaskAssemblyCreateJoint(QtCore.QObject): self.form.distanceSpinbox2.valueChanged.connect(self.onDistance2Changed) self.form.offsetSpinbox.valueChanged.connect(self.onOffsetChanged) self.form.rotationSpinbox.valueChanged.connect(self.onRotationChanged) - self.form.PushButtonReverse.clicked.connect(self.onReverseClicked) + self.form.offset1Button.clicked.connect(self.onOffset1Clicked) + self.form.offset2Button.clicked.connect(self.onOffset2Clicked) self.form.limitCheckbox1.stateChanged.connect(self.adaptUi) self.form.limitCheckbox2.stateChanged.connect(self.adaptUi) @@ -1338,6 +1340,8 @@ class TaskAssemblyCreateJoint(QtCore.QObject): self.form.reverseRotCheckbox.setChecked(self.jType == "Gears") self.form.reverseRotCheckbox.stateChanged.connect(self.reverseRotToggled) + self.form.offsetTabs.currentChanged.connect(self.on_offset_tab_changed) + if jointObj: Gui.Selection.clearSelection() self.creating = False @@ -1502,9 +1506,15 @@ class TaskAssemblyCreateJoint(QtCore.QObject): self.joint.Distance2 = self.form.distanceSpinbox2.property("rawValue") def onOffsetChanged(self, quantity): + if self.blockOffsetRotation: + return + self.joint.Offset2.Base = App.Vector(0, 0, self.form.offsetSpinbox.property("rawValue")) def onRotationChanged(self, quantity): + if self.blockOffsetRotation: + return + yaw = self.form.rotationSpinbox.property("rawValue") ypr = self.joint.Offset2.Rotation.getYawPitchRoll() self.joint.Offset2.Rotation.setYawPitchRoll(yaw, ypr[1], ypr[2]) @@ -1645,6 +1655,34 @@ class TaskAssemblyCreateJoint(QtCore.QObject): else: self.form.groupBox_limits.hide() + self.updateOffsetWidgets() + + def updateOffsetWidgets(self): + # Makes sure the values in both the simplified and advanced tabs are sync. + pos = self.joint.Offset1.Base + self.form.offset1Button.setText(f"({pos.x}, {pos.y}, {pos.z})") + + pos = self.joint.Offset2.Base + self.form.offset2Button.setText(f"({pos.x}, {pos.y}, {pos.z})") + + self.blockOffsetRotation = True + self.form.offsetSpinbox.setProperty("rawValue", pos.z) + self.form.rotationSpinbox.setProperty( + "rawValue", self.joint.Offset2.Rotation.getYawPitchRoll()[0] + ) + self.blockOffsetRotation = False + + def on_offset_tab_changed(self): + self.updateOffsetWidgets() + + def onOffset1Clicked(self): + UtilsAssembly.openEditingPlacementDialog(self.joint, "Offset1") + self.updateOffsetWidgets() + + def onOffset2Clicked(self): + UtilsAssembly.openEditingPlacementDialog(self.joint, "Offset2") + self.updateOffsetWidgets() + def updateTaskboxFromJoint(self): self.refs = [] self.presel_ref = None diff --git a/src/Mod/Assembly/UtilsAssembly.py b/src/Mod/Assembly/UtilsAssembly.py index 3c2bdcfee2..8933abe116 100644 --- a/src/Mod/Assembly/UtilsAssembly.py +++ b/src/Mod/Assembly/UtilsAssembly.py @@ -28,12 +28,10 @@ import Part if App.GuiUp: import FreeCADGui as Gui - -import PySide.QtCore as QtCore -import PySide.QtGui as QtGui + from PySide import QtCore, QtGui, QtWidgets -# translate = App.Qt.translate +translate = App.Qt.translate __title__ = "Assembly utilitary functions" __author__ = "Ondsel" @@ -754,6 +752,21 @@ def findCylindersIntersection(obj, surface, edge, elt_index): return surface.Center +def openEditingPlacementDialog(obj, propName): + task_placement = Gui.TaskPlacement() + dialog = task_placement.form + + # Connect to the placement property + task_placement.setPlacement(getattr(obj, propName)) + task_placement.setSelection([obj]) + task_placement.setPropertyName(propName) + task_placement.bindObject() + task_placement.setIgnoreTransactions(True) + + dialog.findChild(QtWidgets.QPushButton, "selectedVertex").hide() + dialog.exec_() + + def applyOffsetToPlacement(plc, offset): plc.Base = plc.Base + plc.Rotation.multVec(offset) return plc