From 179073784166bcf1b5d24b545f2cb5b2146d221e Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Thu, 28 Sep 2017 22:47:59 -0700 Subject: [PATCH] Basic stock preferences and usage if no job template is specified. --- .../Path/Gui/Resources/preferences/PathJob.ui | 233 +++++++++++++++++- src/Mod/Path/PathScripts/PathJob.py | 6 +- src/Mod/Path/PathScripts/PathPreferences.py | 8 + .../PathScripts/PathPreferencesPathJob.py | 81 ++++++ 4 files changed, 317 insertions(+), 11 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/preferences/PathJob.ui b/src/Mod/Path/Gui/Resources/preferences/PathJob.ui index 8bd0781282..5659614d31 100644 --- a/src/Mod/Path/Gui/Resources/preferences/PathJob.ui +++ b/src/Mod/Path/Gui/Resources/preferences/PathJob.ui @@ -6,8 +6,8 @@ 0 0 - 560 - 609 + 440 + 515 @@ -17,15 +17,15 @@ - 0 + 2 0 0 - 542 - 519 + 422 + 404 @@ -100,7 +100,7 @@ - + Default value for new Jobs, used for computing Paths. Smaller increases accuracy, but slows down computation @@ -132,8 +132,8 @@ 0 0 - 542 - 519 + 422 + 404 @@ -333,6 +333,193 @@ + + + Setup + + + + + + Stock + + + true + + + false + + + + 0 + + + + + 2 + + + + Create Box + + + + + Create Cylinder + + + + + Extend Base Bound Box + + + + + + + + Qt::Horizontal + + + + 40 + 6 + + + + + + + + + + + + + + Ext. X + + + + + + + + 0 + 0 + + + + + + + + Ext. Y + + + + + + + + + + Ext. Z + + + + + + + + + + + + + + + + + + + + + + + + + + + + Radius + + + + + + + Height + + + + + + + + + + + + + Length + + + + + + + Width + + + + + + + + + + + + + + + + Height + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 8 + + + + + + @@ -342,10 +529,36 @@ Gui::InputField - QWidget -
gui::inputfield.h
+ QLineEdit +
Gui/InputField.h
+ + leDefaultFilePath + tbDefaultFilePath + leDefaultJobTemplate + tbDefaultJobTemplate + geometryTolerance + leOutputFile + tbOutputFile + cboOutputPolicy + postProcessorList + defaultPostProcessor + defaultPostProcessorArgs + stockGroup + stock + stockExtXneg + stockExtXpos + stockExtYneg + stockExtYpos + stockExtZneg + stockExtZpos + stockCylinderRadius + stockCylinderHeight + stockBoxLength + stockBoxWidth + stockBoxHeight + diff --git a/src/Mod/Path/PathScripts/PathJob.py b/src/Mod/Path/PathScripts/PathJob.py index c6a267d104..54251134ec 100644 --- a/src/Mod/Path/PathScripts/PathJob.py +++ b/src/Mod/Path/PathScripts/PathJob.py @@ -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 diff --git a/src/Mod/Path/PathScripts/PathPreferences.py b/src/Mod/Path/PathScripts/PathPreferences.py index 2c1f336d60..d8cde7f3bc 100644 --- a/src/Mod/Path/PathScripts/PathPreferences.py +++ b/src/Mod/Path/PathScripts/PathPreferences.py @@ -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) + diff --git a/src/Mod/Path/PathScripts/PathPreferencesPathJob.py b/src/Mod/Path/PathScripts/PathPreferencesPathJob.py index 34e4a0934b..80d12ebd51 100644 --- a/src/Mod/Path/PathScripts/PathPreferencesPathJob.py +++ b/src/Mod/Path/PathScripts/PathPreferencesPathJob.py @@ -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)