Assembly: Joint creation UI : add advanced offset handling.
This commit is contained in:
@@ -82,52 +82,121 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="hLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="offsetLabel">
|
||||
<property name="text">
|
||||
<string>Offset</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::QuantitySpinBox" name="offsetSpinbox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true">mm</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="hLayoutRotation">
|
||||
<item>
|
||||
<widget class="QLabel" name="rotationLabel">
|
||||
<property name="text">
|
||||
<string>Rotation</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::QuantitySpinBox" name="rotationSpinbox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true">deg</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QGroupBox" name="groupBox_offsets">
|
||||
<property name="title">
|
||||
<string>Attachement offsets</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="layout_offset_group">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="offsetTabs">
|
||||
<widget class="QWidget" name="tabSimple">
|
||||
<attribute name="title">
|
||||
<string>Simple</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="layout_tabSimple">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="hLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="offsetLabel">
|
||||
<property name="text">
|
||||
<string>Offset</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::QuantitySpinBox" name="offsetSpinbox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true">mm</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="hLayoutRotation">
|
||||
<item>
|
||||
<widget class="QLabel" name="rotationLabel">
|
||||
<property name="text">
|
||||
<string>Rotation</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Gui::QuantitySpinBox" name="rotationSpinbox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="unit" stdset="0">
|
||||
<string notr="true">deg</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tabAdvanced">
|
||||
<attribute name="title">
|
||||
<string>Advanced</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="layout_tabAdvanced">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="hLayoutOffset1">
|
||||
<item>
|
||||
<widget class="QLabel" name="offset1Label">
|
||||
<property name="text">
|
||||
<string>Offset1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="offset1Button">
|
||||
<property name="toolTip">
|
||||
<string>By clicking this button, you can set the attachement offset of the first marker (coordinate system) of the joint.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="hLayoutOffset2">
|
||||
<item>
|
||||
<widget class="QLabel" name="offset2Label">
|
||||
<property name="text">
|
||||
<string>Offset2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="offset2Button">
|
||||
<property name="toolTip">
|
||||
<string>By clicking this button, you can set the attachement offset of the second marker (coordinate system) of the joint.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0">
|
||||
<widget class="QToolButton" name="PushButtonReverse">
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user