Placement preferences for stock.

This commit is contained in:
Markus Lampert
2017-09-29 19:06:25 -07:00
committed by wmayer
parent d436239785
commit 9f9eb42b78
3 changed files with 129 additions and 5 deletions

View File

@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>440</width>
<height>515</height>
<height>669</height>
</rect>
</property>
<property name="windowTitle">
@@ -25,7 +25,7 @@
<x>0</x>
<y>0</y>
<width>422</width>
<height>404</height>
<height>558</height>
</rect>
</property>
<attribute name="label">
@@ -133,7 +133,7 @@
<x>0</x>
<y>0</y>
<width>422</width>
<height>404</height>
<height>558</height>
</rect>
</property>
<attribute name="label">
@@ -502,6 +502,88 @@
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QGroupBox" name="stockPlacementGroup">
<property name="title">
<string>Placement</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="2">
<widget class="Gui::InputField" name="stockAngle"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Position</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Axis</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="Gui::InputField" name="stockPositionX"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Angle</string>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="Gui::InputField" name="stockPositionY"/>
</item>
<item row="4" column="4">
<widget class="Gui::InputField" name="stockPositionZ"/>
</item>
<item row="3" column="2">
<widget class="QDoubleSpinBox" name="stockAxisX">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QDoubleSpinBox" name="stockAxisY">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QDoubleSpinBox" name="stockAxisZ">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
@@ -513,7 +595,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>8</height>
<height>13</height>
</size>
</property>
</spacer>
@@ -558,6 +640,14 @@
<tabstop>stockBoxLength</tabstop>
<tabstop>stockBoxWidth</tabstop>
<tabstop>stockBoxHeight</tabstop>
<tabstop>stockPlacementGroup</tabstop>
<tabstop>stockAngle</tabstop>
<tabstop>stockAxisX</tabstop>
<tabstop>stockAxisY</tabstop>
<tabstop>stockAxisZ</tabstop>
<tabstop>stockPositionX</tabstop>
<tabstop>stockPositionY</tabstop>
<tabstop>stockPositionZ</tabstop>
</tabstops>
<resources/>
<connections/>

View File

@@ -41,7 +41,6 @@ if False:
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
"""Path Job object and FreeCAD command"""

View File

@@ -85,6 +85,17 @@ class JobPreferencesPage:
attrs['ypos'] = FreeCAD.Units.Quantity(self.form.stockExtYpos.text()).UserString
attrs['zneg'] = FreeCAD.Units.Quantity(self.form.stockExtZneg.text()).UserString
attrs['zpos'] = FreeCAD.Units.Quantity(self.form.stockExtZpos.text()).UserString
if self.form.stockPlacementGroup.isChecked():
angle = FreeCAD.Units.Quantity(self.form.stockAngle.text()).Value
axis = FreeCAD.Vector(self.form.stockAxisX.value(), self.form.stockAxisY.value(), self.form.stockAxisZ.value())
rot = FreeCAD.Rotation(axis, angle)
attrs['rotX'] = rot.Q[0]
attrs['rotY'] = rot.Q[1]
attrs['rotZ'] = rot.Q[2]
attrs['rotW'] = rot.Q[3]
attrs['posX'] = FreeCAD.Units.Quantity(self.form.stockPositionX.text()).Value
attrs['posY'] = FreeCAD.Units.Quantity(self.form.stockPositionY.text()).Value
attrs['posZ'] = FreeCAD.Units.Quantity(self.form.stockPositionZ.text()).Value
PathPreferences.setDefaultStockTemplate(json.dumps(attrs))
else:
PathPreferences.setDefaultStockTemplate('')
@@ -184,6 +195,30 @@ class JobPreferencesPage:
self.form.stockCylinderRadius.setText(attrs.get('radius', '5 mm'))
self.form.stockCylinderHeight.setText(attrs.get('height', '10 mm'))
posX = attrs.get('posX')
posY = attrs.get('posY')
posZ = attrs.get('posZ')
rotX = attrs.get('rotX')
rotY = attrs.get('rotY')
rotZ = attrs.get('rotZ')
rotW = attrs.get('rotW')
if posX is not None and posY is not None and posZ is not None and rotX is not None and rotY is not None and rotZ is not None and rotW is not None:
pos = FreeCAD.Vector(float(posX), float(posY), float(posZ))
rot = FreeCAD.Rotation(float(rotX), float(rotY), float(rotZ), float(rotW))
placement = FreeCAD.Placement(pos, rot)
self.form.stockPlacementGroup.setChecked(True)
else:
placement = FreeCAD.Placement()
self.form.stockPlacementGroup.setChecked(False)
self.form.stockAngle.setText(FreeCAD.Units.Quantity("%f rad" % placement.Rotation.Angle).UserString)
self.form.stockAxisX.setValue(placement.Rotation.Axis.x)
self.form.stockAxisY.setValue(placement.Rotation.Axis.y)
self.form.stockAxisZ.setValue(placement.Rotation.Axis.z)
self.form.stockPositionX.setText(FreeCAD.Units.Quantity(placement.Base.x, FreeCAD.Units.Length).UserString)
self.form.stockPositionY.setText(FreeCAD.Units.Quantity(placement.Base.y, FreeCAD.Units.Length).UserString)
self.form.stockPositionZ.setText(FreeCAD.Units.Quantity(placement.Base.z, FreeCAD.Units.Length).UserString)
self.setupStock(index)
self.form.stock.currentIndexChanged.connect(self.setupStock)