Basic stock preferences and usage if no job template is specified.

This commit is contained in:
Markus Lampert
2017-09-28 22:47:59 -07:00
committed by wmayer
parent a5d1e619f5
commit 1790737841
4 changed files with 317 additions and 11 deletions

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<height>609</height>
<width>440</width>
<height>515</height>
</rect>
</property>
<property name="windowTitle">
@@ -17,15 +17,15 @@
<item>
<widget class="QToolBox" name="toolBox">
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="page">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>542</width>
<height>519</height>
<width>422</width>
<height>404</height>
</rect>
</property>
<attribute name="label">
@@ -100,7 +100,7 @@
</widget>
</item>
<item>
<widget class="Gui::InputField" name="geometryTolerance" native="true">
<widget class="Gui::InputField" name="geometryTolerance">
<property name="toolTip">
<string>Default value for new Jobs, used for computing Paths. Smaller increases accuracy, but slows down computation</string>
</property>
@@ -132,8 +132,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>542</width>
<height>519</height>
<width>422</width>
<height>404</height>
</rect>
</property>
<attribute name="label">
@@ -333,6 +333,193 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page_3">
<attribute name="label">
<string>Setup</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="stockGroup">
<property name="title">
<string>Stock</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="stock">
<property name="currentIndex">
<number>2</number>
</property>
<item>
<property name="text">
<string>Create Box</string>
</property>
</item>
<item>
<property name="text">
<string>Create Cylinder</string>
</property>
</item>
<item>
<property name="text">
<string>Extend Base Bound Box</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>6</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="stockFromBase">
<layout class="QGridLayout" name="gridLayout_9">
<item row="1" column="3">
<widget class="Gui::InputField" name="stockExtYpos"/>
</item>
<item row="0" column="1">
<widget class="QLabel" name="stockExtXLabel">
<property name="text">
<string>Ext. X</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="Gui::InputField" name="stockExtXpos">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="stockExtYLabel">
<property name="text">
<string>Ext. Y</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="Gui::InputField" name="stockExtXneg"/>
</item>
<item row="2" column="1">
<widget class="QLabel" name="stockExtZLabel">
<property name="text">
<string>Ext. Z</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="Gui::InputField" name="stockExtZneg"/>
</item>
<item row="2" column="3">
<widget class="Gui::InputField" name="stockExtZpos"/>
</item>
<item row="1" column="2">
<widget class="Gui::InputField" name="stockExtYneg"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="stockCreateCylinder">
<layout class="QGridLayout" name="gridLayout_10">
<item row="0" column="2">
<widget class="Gui::InputField" name="stockCylinderRadius"/>
</item>
<item row="1" column="2">
<widget class="Gui::InputField" name="stockCylinderHeight"/>
</item>
<item row="0" column="1">
<widget class="QLabel" name="stockCylinderRadiusLabel">
<property name="text">
<string>Radius</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="stockCylinderHeightLabel">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="stockCreateBox">
<layout class="QGridLayout" name="gridLayout_11">
<item row="0" column="1">
<widget class="QLabel" name="stockBoxLengthLabel">
<property name="text">
<string>Length</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="stockBoxWidthLabel">
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="Gui::InputField" name="stockBoxLength"/>
</item>
<item row="2" column="2">
<widget class="Gui::InputField" name="stockBoxHeight"/>
</item>
<item row="1" column="2">
<widget class="Gui::InputField" name="stockBoxWidth"/>
</item>
<item row="2" column="1">
<widget class="QLabel" name="stockBoxHeightLabel">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>8</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
@@ -342,10 +529,36 @@
<customwidgets>
<customwidget>
<class>Gui::InputField</class>
<extends>QWidget</extends>
<header>gui::inputfield.h</header>
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>leDefaultFilePath</tabstop>
<tabstop>tbDefaultFilePath</tabstop>
<tabstop>leDefaultJobTemplate</tabstop>
<tabstop>tbDefaultJobTemplate</tabstop>
<tabstop>geometryTolerance</tabstop>
<tabstop>leOutputFile</tabstop>
<tabstop>tbOutputFile</tabstop>
<tabstop>cboOutputPolicy</tabstop>
<tabstop>postProcessorList</tabstop>
<tabstop>defaultPostProcessor</tabstop>
<tabstop>defaultPostProcessorArgs</tabstop>
<tabstop>stockGroup</tabstop>
<tabstop>stock</tabstop>
<tabstop>stockExtXneg</tabstop>
<tabstop>stockExtXpos</tabstop>
<tabstop>stockExtYneg</tabstop>
<tabstop>stockExtYpos</tabstop>
<tabstop>stockExtZneg</tabstop>
<tabstop>stockExtZpos</tabstop>
<tabstop>stockCylinderRadius</tabstop>
<tabstop>stockCylinderHeight</tabstop>
<tabstop>stockBoxLength</tabstop>
<tabstop>stockBoxWidth</tabstop>
<tabstop>stockBoxHeight</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@@ -125,7 +125,11 @@ class ObjectJob:
self.setFromTemplateFile(obj, templateFile)
if not obj.Stock:
obj.Stock = PathStock.CreateFromBase(obj)
stockTemplate = PathPreferences.defaultStockTemplate()
if stockTemplate:
obj.Stock = PathStock.CreateFromTemplate(obj, json.loads(stockTemplate))
if not obj.Stock:
obj.Stock = PathStock.CreateFromBase(obj)
if obj.Stock.ViewObject:
obj.Stock.ViewObject.Visibility = False

View File

@@ -33,6 +33,7 @@ PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
class PathPreferences:
DefaultFilePath = "DefaultFilePath"
DefaultJobTemplate = "DefaultJobTemplate"
DefaultStockTemplate = "DefaultStockTemplate"
PostProcessorDefault = "PostProcessorDefault"
PostProcessorDefaultArgs = "PostProcessorDefaultArgs"
@@ -163,3 +164,10 @@ class PathPreferences:
pref = cls.preferences()
return pref.GetString(cls.PostProcessorOutputPolicy, "")
@classmethod
def defaultStockTemplate(cls):
return cls.preferences().GetString(cls.DefaultStockTemplate, "")
@classmethod
def setDefaultStockTemplate(cls, template):
cls.preferences().SetString(cls.DefaultStockTemplate, template)

View File

@@ -25,6 +25,8 @@
import FreeCAD
import FreeCADGui
import PathScripts.PathLog as PathLog
import PathScripts.PathStock as PathStock
import json
from FreeCAD import Units
from PySide import QtCore, QtGui
@@ -61,6 +63,31 @@ class JobPreferencesPage:
path = str(self.form.leOutputFile.text())
policy = str(self.form.cboOutputPolicy.currentText())
PathPreferences.setOutputFileDefaults(path, policy)
self.saveStockSettings()
def saveStockSettings(self):
if self.form.stockGroup.isChecked():
attrs = {}
attrs['version'] = 1
typ = [PathStock.StockType.CreateBox, PathStock.StockType.CreateCylinder, PathStock.StockType.FromBase][self.form.stock.currentIndex()]
attrs['create'] = typ
if typ == PathStock.StockType.CreateBox:
attrs['length'] = FreeCAD.Units.Quantity(self.form.stockBoxLength.text()).UserString
attrs['width'] = FreeCAD.Units.Quantity(self.form.stockBoxWidth.text()).UserString
attrs['height'] = FreeCAD.Units.Quantity(self.form.stockBoxHeight.text()).UserString
if typ == PathStock.StockType.CreateCylinder:
attrs['radius'] = FreeCAD.Units.Quantity(self.form.stockCylinderRadius.text()).UserString
attrs['height'] = FreeCAD.Units.Quantity(self.form.stockCylinderHeight.text()).UserString
if typ == PathStock.StockType.FromBase:
attrs['xneg'] = FreeCAD.Units.Quantity(self.form.stockExtXneg.text()).UserString
attrs['xpos'] = FreeCAD.Units.Quantity(self.form.stockExtXpos.text()).UserString
attrs['yneg'] = FreeCAD.Units.Quantity(self.form.stockExtYneg.text()).UserString
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
PathPreferences.setDefaultStockTemplate(json.dumps(attrs))
else:
PathPreferences.setDefaultStockTemplate('')
def selectComboEntry(self, widget, text):
index = widget.findText(text, QtCore.Qt.MatchFixedString)
@@ -120,6 +147,60 @@ class JobPreferencesPage:
self.form.defaultPostProcessor.currentIndexChanged.connect(self.updateDefaultPostProcessorToolTip)
self.form.tbOutputFile.clicked.connect(self.browseOutputFile)
self.loadStockSettings()
def loadStockSettings(self):
stock = PathPreferences.defaultStockTemplate()
index = -1
if stock:
attrs = json.loads(stock)
if attrs.get('version') and 1 == int(attrs['version']):
stockType = attrs.get('create')
if stockType == PathStock.StockType.FromBase:
index = 2
elif stockType == PathStock.StockType.CreateBox:
index = 0
elif stockType == PathStock.StockType.CreateCylinder:
index = 1
else:
index = -1
if -1 == index:
attrs = {}
self.form.stockGroup.setChecked(False)
else:
self.form.stockGroup.setChecked(True)
self.form.stock.setCurrentIndex(index)
# this either sets the default value or the value from the template for each field
self.form.stockExtXneg.setText(attrs.get('xneg', '1 mm'))
self.form.stockExtXpos.setText(attrs.get('xpos', '1 mm'))
self.form.stockExtYneg.setText(attrs.get('yneg', '1 mm'))
self.form.stockExtYpos.setText(attrs.get('ypos', '1 mm'))
self.form.stockExtZneg.setText(attrs.get('zneg', '1 mm'))
self.form.stockExtZpos.setText(attrs.get('zpos', '1 mm'))
self.form.stockBoxLength.setText(attrs.get('length', '10 mm'))
self.form.stockBoxWidth.setText(attrs.get('width', '10 mm'))
self.form.stockBoxHeight.setText(attrs.get('height', '10 mm'))
self.form.stockCylinderRadius.setText(attrs.get('radius', '5 mm'))
self.form.stockCylinderHeight.setText(attrs.get('height', '10 mm'))
self.setupStock(index)
self.form.stock.currentIndexChanged.connect(self.setupStock)
def setupStock(self, index):
if 0 == index:
self.form.stockFromBase.hide()
self.form.stockCreateBox.show()
self.form.stockCreateCylinder.hide()
elif 1 == index:
self.form.stockFromBase.hide()
self.form.stockCreateBox.hide()
self.form.stockCreateCylinder.show()
else:
self.form.stockFromBase.show()
self.form.stockCreateBox.hide()
self.form.stockCreateCylinder.hide()
def getPostProcessor(self, name):
if not name in self.processor.keys():
processor = PostProcessor.load(name)