From 84b681eb2bc24bf75e56cb83b03b14a27b0b7480 Mon Sep 17 00:00:00 2001 From: markus Date: Wed, 29 Aug 2018 14:42:38 -0700 Subject: [PATCH] PathEdit integration of the setup-sheet editor. --- src/Mod/Path/Gui/Resources/panels/PathEdit.ui | 1089 +++++++++++------ .../Path/Gui/Resources/panels/SetupGlobal.ui | 24 +- src/Mod/Path/PathScripts/PathJobGui.py | 17 +- src/Mod/Path/PathScripts/PathSetupSheetGui.py | 159 ++- 4 files changed, 843 insertions(+), 446 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/PathEdit.ui b/src/Mod/Path/Gui/Resources/panels/PathEdit.ui index 1a57ae079b..19f4482cd5 100644 --- a/src/Mod/Path/Gui/Resources/panels/PathEdit.ui +++ b/src/Mod/Path/Gui/Resources/panels/PathEdit.ui @@ -6,7 +6,7 @@ 0 0 - 400 + 432 673 @@ -14,56 +14,98 @@ Job Edit - 2 + 0 General - - - - - - - - Label + + + + + 0 + + + + 0 + 0 + 412 + 549 + + + + Job + + + + + + Label + + + + + + + + + + Model + + + + + + + + 0 + 0 + + + + + + + + Description + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + 0 + 0 + 100 + 30 + + + + Template Export + + - - - - Model - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Description - - - - - - @@ -137,279 +179,445 @@ - - - Stock + + + 0 - - - 0 + + + + 0 + 0 + 414 + 762 + - - - - - - - - 0 - 0 - - - - 2 - - - - Create Box + + Layout + + + + + + Stock + + + + 0 + + + + + + + + 2 + + + + Create Box + + + + + Create Cylinder + + + + + Extend Model's Bound Box + + + + + Use Existing Solid + + + + + + + + New + + + + + + + + + + Qt::Horizontal - - - - Create Cylinder + + + 40 + 6 + - - + + + + + + + + + + + + + + + + + + + + + Ext. X + + + + + + + + 0 + 0 + + + + + + + + Ext. Y + + + + + + + + + + Ext. Z + + + + + + + + + + + + + + + + + + + + + + + + + + + + Radius + + + + + + + Height + + + + + + + + + + + + + Length + + + + + + + Width + + + + + + + + + + + + + + + + Height + + + + + + + + + + + + + Orientation + + + + - Extend Model's Bound Box + X-Axis - - + + + + - Use Existing Solid + Y-Axis - - - - - - - New - - - - - - - - - - Qt::Horizontal - - - - 40 - 6 - - - - - - - - - - - - - - - - - - - - - - - Ext. X - - - - - - - - 0 - 0 - - - - - - - - Ext. Y - - - - - - - - - - Ext. Z - - - - - - - - - - - - - - - - - - - - - - - - - - - - Radius - - - - - - - Height - - - - - - - - - - - - - Length - - - - - - - Width - - - - - - - - - - - - - - - - Height - - - - - - - + + + + + + Z-Axis + + + + + + + + + + Alignment + + + + + + Set Origin + + + + + + + Move to Origin + + + + + + + Center in Stock + + + + + + + XY in Stock + + + + + + + + + + Qt::Vertical + + + + 20 + 195 + + + + + + + + + + 0 + 0 + 352 + 350 + + + + Default Values + + + + + + Depths + + + + + + Start Depth + + + + + + + <html><head/><body><p>Expression set as the StartDepth of a newly created operation.</p><p><br/></p><p>Default: OpStartDepth</p></body></html> + + + + + + + Final Depth + + + + + + + <html><head/><body><p>Expression set as the FinalDepth for a newly created operation.</p><p><br/></p><p>Default: OpFinalDepth</p></body></html> + + + + + + + Step Down + + + + + + + <html><head/><body><p>Expression set as the StepDown of a newly created operation.</p><p><br/></p><p>Default: OpToolDiameter</p></body></html> + + + + + + + + + + Heights + + + + + + Safe + + + + + + + Clearance + + + + + + + <html><head/><body><p>Expression set as SafeHeight for new operations.</p><p><br/></p><p>Default: &quot;OpStockZMax+SetupSheet.SafeHeightOffset&quot;</p></body></html> + + + + + + + <html><head/><body><p>Expression set as ClearanceHeight for new operations.</p><p><br/></p><p>Default: &quot;OpStockZMax+SetupSheet.ClearanceHeightOffset&quot;</p></body></html> + + + + + + + <html><head/><body><p>ClearanceHeightOffset - can be used by expressions to set the default ClearanceHeight for new operations.</p><p><br/></p><p>Default: &quot;3 mm&quot;</p></body></html> + + + + + + + Offset + + + Qt::AlignCenter + + + + + + + Expression + + + Qt::AlignCenter + + + + + + + <html><head/><body><p>SafeHeightOffset can be for expressions to set the SafeHeight for new operations.</p><p><br/></p><p>Default: &quot;5 mm&quot;</p></body></html> + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + - - - - Orientation - - - - - - X-Axis - - - - - - - Y-Axis - - - - - - - Z-Axis - - - - - - - - - - Alignment - - - - - - Set Origin - - - - - - - Move to Origin - - - - - - - Center in Stock - - - - - - - XY in Stock - - - - - - - - - - Qt::Vertical - - - - 20 - 195 - - - - @@ -418,90 +626,192 @@ - - - QFrame::StyledPanel + + + 0 - - QFrame::Raised - - - - - - false - - - - Name + + + + 0 + 0 + 412 + 549 + + + + Tools + + + + + + QFrame::StyledPanel - - - - Nr. + + QFrame::Raised - - - - Feed + + + + + false + + + + Name + + + + + Nr. + + + + + Feed + + + + + + + + + + Feed + + + + + + + + + + Spindle + + + + + + + + + + + false + + + Edit + + + + + + + Add + + + + + + + false + + + Remove + + + + + + + + + + + + + + + 0 + 0 + 244 + 145 + + + + Default Values + + + + + + Rapid Speeds - - - - + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Horizontal + + + + + + + + 0 + 0 + + + + <html><head/><body><p>Rapid horizontal speed assigned as HorizRapid to new ToolController.</p></body></html> + + + + + + + Vertical + + + + + + + + 0 + 0 + + + + <html><head/><body><p>Rapid vertical speed assigne to VertRapid of new ToolController.</p></body></html> + + + + + + + + + + Qt::Vertical - - - - Feed + + + 20 + 40 + - - - - - - - - - Spindle - - - - - - - - - - - false - - - Edit - - - - - - - Add - - - - - - - false - - - Remove - - - - - - - + + + + @@ -635,6 +945,12 @@ + + + Op Defaults + + + @@ -642,6 +958,11 @@ QLineEdit
Gui/InputField.h
+ + Gui::QuantitySpinBox + QDoubleSpinBox +
gui_quantityspinbox.h
+
jobLabel diff --git a/src/Mod/Path/Gui/Resources/panels/SetupGlobal.ui b/src/Mod/Path/Gui/Resources/panels/SetupGlobal.ui index 49ed83717f..822d909472 100644 --- a/src/Mod/Path/Gui/Resources/panels/SetupGlobal.ui +++ b/src/Mod/Path/Gui/Resources/panels/SetupGlobal.ui @@ -6,7 +6,7 @@ 0 0 - 642 + 500 721 @@ -19,7 +19,7 @@ 0 - + Operation @@ -38,7 +38,7 @@ - + <html><head/><body><p>Expression set as the StartDepth of a newly created operation.</p><p><br/></p><p>Default: OpStartDepth</p></body></html> @@ -52,7 +52,7 @@ - + <html><head/><body><p>Expression set as the FinalDepth for a newly created operation.</p><p><br/></p><p>Default: OpFinalDepth</p></body></html> @@ -66,7 +66,7 @@ - + <html><head/><body><p>Expression set as the StepDown of a newly created operation.</p><p><br/></p><p>Default: OpToolDiameter</p></body></html> @@ -96,21 +96,21 @@ - + <html><head/><body><p>Expression set as SafeHeight for new operations.</p><p><br/></p><p>Default: &quot;OpStockZMax+SetupSheet.SafeHeightOffset&quot;</p></body></html> - + <html><head/><body><p>Expression set as ClearanceHeight for new operations.</p><p><br/></p><p>Default: &quot;OpStockZMax+SetupSheet.ClearanceHeightOffset&quot;</p></body></html> - + <html><head/><body><p>ClearanceHeightOffset - can be used by expressions to set the default ClearanceHeight for new operations.</p><p><br/></p><p>Default: &quot;3 mm&quot;</p></body></html> @@ -137,7 +137,7 @@ - + <html><head/><body><p>SafeHeightOffset can be for expressions to set the SafeHeight for new operations.</p><p><br/></p><p>Default: &quot;5 mm&quot;</p></body></html> @@ -161,7 +161,7 @@ - + Tool Controller @@ -180,7 +180,7 @@ - + 0 @@ -200,7 +200,7 @@ - + 0 diff --git a/src/Mod/Path/PathScripts/PathJobGui.py b/src/Mod/Path/PathScripts/PathJobGui.py index ddc0244cc1..2d03e731ab 100644 --- a/src/Mod/Path/PathScripts/PathJobGui.py +++ b/src/Mod/Path/PathScripts/PathJobGui.py @@ -31,6 +31,7 @@ import PathScripts.PathGeom as PathGeom import PathScripts.PathGui as PathGui import PathScripts.PathLog as PathLog import PathScripts.PathPreferences as PathPreferences +import PathScripts.PathSetupSheetGui as PathSetupSheetGui import PathScripts.PathStock as PathStock import PathScripts.PathToolController as PathToolController import PathScripts.PathToolLibraryManager as PathToolLibraryManager @@ -489,6 +490,9 @@ class TaskPanel: self.stockCreateCylinder = None self.stockEdit = None + self.setupGlobal = PathSetupSheetGui.GlobalEditor(self.obj.SetupSheet, self.form) + self.setupOps = PathSetupSheetGui.OpsDefaultEditor(self.obj.SetupSheet, self.form.tabOpDefaults) + def preCleanup(self): PathLog.track() FreeCADGui.Selection.removeObserver(self) @@ -499,12 +503,16 @@ class TaskPanel: PathLog.track() self.preCleanup() self.getFields() + self.setupGlobal.accept() + self.setupOps.accept() FreeCAD.ActiveDocument.commitTransaction() self.cleanup(resetEdit) def reject(self, resetEdit=True): PathLog.track() self.preCleanup() + self.setupGlobal.reject() + self.setupOps.reject() FreeCAD.ActiveDocument.abortTransaction() if self.deleteOnReject: PathLog.info("Uncreate Job") @@ -557,6 +565,9 @@ class TaskPanel: self.obj.Proxy.execute(self.obj) + self.setupGlobal.getFields() + self.setupOps.getFields() + def selectComboBoxText(self, widget, text): index = widget.findText(text, QtCore.Qt.MatchFixedString) if index >= 0: @@ -652,6 +663,8 @@ class TaskPanel: self.updateToolController() self.stockEdit.setFields(self.obj) + self.setupGlobal.setFields() + self.setupOps.setFields() def setPostProcessorOutputFile(self): filename = QtGui.QFileDialog.getSaveFileName(self.form, translate("Path_Job", "Select Output File"), None, translate("Path_Job", "All Files (*.*)")) @@ -948,6 +961,8 @@ class TaskPanel: def setupUi(self, activate): + self.setupGlobal.setupUi() + self.setupOps.setupUi() self.updateStockEditor(-1) self.setFields() @@ -1035,6 +1050,6 @@ def Create(base, template=None): return obj except Exception as exc: PathLog.error(sys.exc_info()) - #traceback.print_exc(exc) + traceback.print_exc(exc) FreeCAD.ActiveDocument.abortTransaction() diff --git a/src/Mod/Path/PathScripts/PathSetupSheetGui.py b/src/Mod/Path/PathScripts/PathSetupSheetGui.py index b148752890..7cda923cdc 100644 --- a/src/Mod/Path/PathScripts/PathSetupSheetGui.py +++ b/src/Mod/Path/PathScripts/PathSetupSheetGui.py @@ -131,7 +131,7 @@ class OpTaskPanel: self.obj = obj self.op = op self.form = FreeCADGui.PySideUic.loadUi(":/panels/SetupOp.ui") - self.form.setWindowTitle(self.name) + self.form.setWindowTitle("Op {}".format(self.name)) self.props = sorted(op.properties()) self.prototype = op.prototype(name) @@ -200,39 +200,60 @@ class OpTaskPanel: return propertiesCreatedRemoved -class TaskPanel: - DataIds = QtCore.Qt.ItemDataRole.UserRole - DataKey = QtCore.Qt.ItemDataRole.UserRole + 1 +class OpsDefaultEditor: - def __init__(self, vobj): - self.vobj = vobj - self.obj = vobj.Object - PathLog.track(self.obj.Label) - self.globalForm = FreeCADGui.PySideUic.loadUi(":/panels/SetupGlobal.ui") + def __init__(self, obj, parent): + self.obj = obj self.ops = sorted([OpTaskPanel(self.obj, name, op) for name, op in PathUtil.keyValueIter(PathSetupSheet._RegisteredOps)], key = lambda op: op.name) - self.form = [self.globalForm] + [op.form for op in self.ops] - FreeCAD.ActiveDocument.openTransaction(translate("Path_SetupSheet", "Edit SetupSheet")) + if parent: + self.toolbox = QtGui.QToolBox(parent) + for op in self.ops: + self.toolbox.addItem(op.form, op.form.windowTitle()) + self.toolbox.setParent(parent) + parent.layout().addWidget(self.toolbox) def reject(self): - FreeCAD.ActiveDocument.abortTransaction() - FreeCADGui.Control.closeDialog() - FreeCAD.ActiveDocument.recompute() + pass def accept(self): - self.getFields() - [op.accept() for op in self.ops] if any([op.accept() for op in self.ops]): PathLog.track() #sel = FreeCADGui.Selection.getSelection() #FreeCADGui.Selection.clearSelection() #for o in sel: # FreeCADGui.Selection.addSelection(o) - FreeCAD.ActiveDocument.commitTransaction() - FreeCADGui.ActiveDocument.resetEdit() - FreeCADGui.Control.closeDialog() - FreeCAD.ActiveDocument.recompute() - #FreeCADGui.Selection.removeObserver(self.s) - #FreeCAD.ActiveDocument.recompute() + + def getFields(self): + pass + + def updateUI(self): + pass + + def updateModel(self, recomp = True): + PathLog.track() + self.getFields() + self.updateUI() + if recomp: + FreeCAD.ActiveDocument.recompute() + + def setFields(self): + self.updateUI() + + def setupUi(self): + for op in self.ops: + op.setupUi() + +class GlobalEditor(object): + + def __init__(self, obj, form): + self.form = form + self.obj = obj + + def reject(self): + pass + + def accept(self): + self.getFields() def getFields(self): def updateExpression(name, widget): @@ -241,11 +262,11 @@ class TaskPanel: if val != value: PathGui.setProperty(self.obj, name, value) - updateExpression('StartDepthExpression', self.globalForm.startDepthExpr) - updateExpression('FinalDepthExpression', self.globalForm.finalDepthExpr) - updateExpression('StepDownExpression', self.globalForm.stepDownExpr) - updateExpression('ClearanceHeightExpression', self.globalForm.clearanceHeightExpr) - updateExpression('SafeHeightExpression', self.globalForm.safeHeightExpr) + updateExpression('StartDepthExpression', self.form.setupStartDepthExpr) + updateExpression('FinalDepthExpression', self.form.setupFinalDepthExpr) + updateExpression('StepDownExpression', self.form.setupStepDownExpr) + updateExpression('ClearanceHeightExpression', self.form.setupClearanceHeightExpr) + updateExpression('SafeHeightExpression', self.form.setupSafeHeightExpr) self.clearanceHeightOffs.updateProperty() self.safeHeightOffs.updateProperty() self.rapidVertical.updateProperty() @@ -253,43 +274,83 @@ class TaskPanel: def updateUI(self): PathLog.track() - self.globalForm.startDepthExpr.setText( self.obj.StartDepthExpression) - self.globalForm.finalDepthExpr.setText( self.obj.FinalDepthExpression) - self.globalForm.stepDownExpr.setText( self.obj.StepDownExpression) - self.globalForm.clearanceHeightExpr.setText( self.obj.ClearanceHeightExpression) - self.globalForm.safeHeightExpr.setText( self.obj.SafeHeightExpression) + self.form.setupStartDepthExpr.setText( self.obj.StartDepthExpression) + self.form.setupFinalDepthExpr.setText( self.obj.FinalDepthExpression) + self.form.setupStepDownExpr.setText( self.obj.StepDownExpression) + self.form.setupClearanceHeightExpr.setText( self.obj.ClearanceHeightExpression) + self.form.setupSafeHeightExpr.setText( self.obj.SafeHeightExpression) self.clearanceHeightOffs.updateSpinBox() self.safeHeightOffs.updateSpinBox() self.rapidVertical.updateSpinBox() self.rapidHorizontal.updateSpinBox() - def updateModel(self): + def updateModel(self, recomp = True): PathLog.track() self.getFields() self.updateUI() - FreeCAD.ActiveDocument.recompute() - - def setupCombo(self, combo, text, items): - if items and len(items) > 0: - for i in range(combo.count(), -1, -1): - combo.removeItem(i) - combo.addItems(items) - index = combo.findText(text, QtCore.Qt.MatchFixedString) - if index >= 0: - combo.setCurrentIndex(index) + if recomp: + FreeCAD.ActiveDocument.recompute() def setFields(self): self.updateUI() def setupUi(self): - self.clearanceHeightOffs = PathGui.QuantitySpinBox(self.globalForm.clearanceHeightOffs, self.obj, 'ClearanceHeightOffset') - self.safeHeightOffs = PathGui.QuantitySpinBox(self.globalForm.safeHeightOffs, self.obj, 'SafeHeightOffset') - self.rapidHorizontal = PathGui.QuantitySpinBox(self.globalForm.rapidHorizontal, self.obj, 'HorizRapid') - self.rapidVertical = PathGui.QuantitySpinBox(self.globalForm.rapidVertical, self.obj, 'VertRapid') + self.clearanceHeightOffs = PathGui.QuantitySpinBox(self.form.setupClearanceHeightOffs, self.obj, 'ClearanceHeightOffset') + self.safeHeightOffs = PathGui.QuantitySpinBox(self.form.setupSafeHeightOffs, self.obj, 'SafeHeightOffset') + self.rapidHorizontal = PathGui.QuantitySpinBox(self.form.setupRapidHorizontal, self.obj, 'HorizRapid') + self.rapidVertical = PathGui.QuantitySpinBox(self.form.setupRapidVertical, self.obj, 'VertRapid') self.setFields() - for op in self.ops: - op.setupUi() +class TaskPanel: + + def __init__(self, vobj): + self.vobj = vobj + self.obj = vobj.Object + PathLog.track(self.obj.Label) + self.globalForm = FreeCADGui.PySideUic.loadUi(":/panels/SetupGlobal.ui") + self.globalEditor = GlobalEditor(self.obj, self.globalForm) + self.opsEditor = OpsDefaultEditor(self.obj, None) + self.form = [op.form for op in self.opsEditor.ops] + [self.globalForm] + FreeCAD.ActiveDocument.openTransaction(translate("Path_SetupSheet", "Edit SetupSheet")) + + def reject(self): + self.globalEditor.reject() + self.opsEditor.reject() + FreeCAD.ActiveDocument.abortTransaction() + FreeCADGui.Control.closeDialog() + FreeCAD.ActiveDocument.recompute() + + def accept(self): + self.globalEditor.accept() + self.opsEditor.accept() + + FreeCAD.ActiveDocument.commitTransaction() + FreeCADGui.ActiveDocument.resetEdit() + FreeCADGui.Control.closeDialog() + FreeCAD.ActiveDocument.recompute() + #FreeCADGui.Selection.removeObserver(self.s) + #FreeCAD.ActiveDocument.recompute() + + def getFields(self): + self.globalEditor.getFields() + self.opsEditor.getFields() + + def updateUI(self): + self.globalEditor.updateUI() + self.opsEditor.updateUI() + + def updateModel(self): + self.globalEditor.updateModel(False) + self.opsEditor.updateModel(False) + FreeCAD.ActiveDocument.recompute() + + def setFields(self): + self.globalEditor.setFields() + self.opsEditor.setFields() + + def setupUi(self): + self.globalEditor.setupUi() + self.opsEditor.setupUi() def Create(name = 'SetupSheet'): '''Create(name = 'SetupSheet') ... creates a new setup sheet'''