From bfa8d4ec539d3c6357d13f528476f59f5f1ffdd5 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Mon, 4 Sep 2017 17:29:07 -0700 Subject: [PATCH] Simplified UI; added support for arbitrary callbacks for edit of icon view provider - use that to open up job editor with appropriate page open (avoids back dependency from stock gui to job gui). --- src/Mod/Path/Gui/Resources/panels/PathEdit.ui | 1394 +++++++---------- .../Path/PathScripts/PathIconViewProvider.py | 27 +- src/Mod/Path/PathScripts/PathJobGui.py | 84 +- 3 files changed, 636 insertions(+), 869 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/PathEdit.ui b/src/Mod/Path/Gui/Resources/panels/PathEdit.ui index 97eac943fb..538f675858 100644 --- a/src/Mod/Path/Gui/Resources/panels/PathEdit.ui +++ b/src/Mod/Path/Gui/Resources/panels/PathEdit.ui @@ -14,537 +14,463 @@ Job Edit - 3 + 4 General - - - - - 0 + + + + + + + + Label - - - - 0 - 0 - 378 - 793 - - - - Info - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Label - - - - - - - - - - Model - - - - - - - false - - - Material - - - - - - - false - - - - - - - - - - - - 0 - 0 - 233 - 135 - - - - Post Processing - - - - - - Output File - - - - - - - <html><head/><body><p>Enter a path and optionally file name (see below) to be used as the default for the post processor export.</p><p>The following substitutions are performed before the name is resolved at the time of the post processing:</p><p>%D ... directory of the active document<br/>%d ... name of the active document (with extension)<br/>%M ... user macro directory<br/>%j ... name of the active Job object</p><p>The following example store all files with the same name as the document the directory /home/freecad (please remove quotes):</p><p>&quot;/home/cnc/%d.g-code&quot;</p><p>See the file save policy below on how to deal with name conflicts.</p></body></html> - - - - - - - ... - - - - - - - Processor - - - - - - - - - - Arguments - - - - - - - <html><head/><body><p>Optional arguments passed to the Post Processor. The arguments are specific for each Post Processor, please see it's documentation for details.</p></body></html> - - - - - - - Qt::Vertical - - - - 20 - 655 - - - - - - + + + + Model + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Description + + + + + + + + + + + Output + + + + + + Output File + + + + + + + <html><head/><body><p>Enter a path and optionally file name (see below) to be used as the default for the post processor export.</p><p>The following substitutions are performed before the name is resolved at the time of the post processing:</p><p>%D ... directory of the active document<br/>%d ... name of the active document (with extension)<br/>%M ... user macro directory<br/>%j ... name of the active Job object</p><p>The following example store all files with the same name as the document the directory /home/freecad (please remove quotes):</p><p>&quot;/home/cnc/%d.g-code&quot;</p><p>See the file save policy below on how to deal with name conflicts.</p></body></html> + + + + + + + ... + + + + + + + Processor + + + + + + + + + + Arguments + + + + + + + <html><head/><body><p>Optional arguments passed to the Post Processor. The arguments are specific for each Post Processor, please see it's documentation for details.</p></body></html> + + + + + + + Qt::Vertical + + + + 20 + 747 + + + + Setup - + - - - true + + + Stock - - 0 - - - - - 0 - 0 - 378 - 830 - + + + 0 - - Layout - - - - - - Stock + + + + 2 + + + + Create Box - - - 0 - - - - - 2 - - - - Create Box - - - - - Create Cylinder - - - - - Extend Base Bound Box - - - - - Use Existing Solid - - - - - - - - Qt::Horizontal - - - - 40 - 6 - - - - - - - - - - - - - - - - - - - - - - - Ext. X - - - - - - - - 0 - 0 - - - - - - - - Ext. Y - - - - - - - - - - Ext. Z - - - - - - - - - - - - - - - - - - - - - - - - - - - - Radius - - - - - - - Height - - - - - - - - - - - - - Length - - - - - - - Width - - - - - - - - - - - - - - - - Height - - - - - - - - - - - - - Orientation + + + + Create Cylinder - - - - - X-Axis - - - - - - - Y-Axis - - - - - - - Z-Axis - - - - - - - - - - Alignment + + + + Extend Base Bound Box - - - - - Set Origin - - - - - - - Move to Origin - - - - - - - Center in Stock - - - - - - - XY in Stock - - - - - - - - - - Qt::Vertical + + + + Use Existing Solid - - - 20 - 40 - - - - - - + + + + + + + Qt::Horizontal + + + + 40 + 6 + + + + + + + + + + + + + + + + + + + + + + + Ext. X + + + + + + + + 0 + 0 + + + + + + + + Ext. Y + + + + + + + + + + Ext. Z + + + + + + + + + + + + + + + + + + + + + + + + + + + + Radius + + + + + + + Height + + + + + + + + + + + + + Length + + + + + + + Width + + + + + + + + + + + + + + + + Height + + + + + + + + + + + Orientation + + + + + + X-Axis + + + + + + + Y-Axis + + + + + + + Z-Axis + + + + + + + + + + Alignment + + + + + + Set Origin + + + + + + + Move to Origin + + + + + + + Center in Stock + + + + + + + XY in Stock + + + + + + + + + + Qt::Vertical + + + + 20 + 195 + + + + Tools - + - - - 0 - - - - - 0 - 0 - 378 - 830 - + + + false + + + + Name - - Tool Controller - - - - - - false - - - - Name - - - - - Nr. - - - - - Feed - - - - - - - - - - Feed - - - - - - - - - - Spindle - - - - - - - - - - - false - - - Edit - - - - - - - Add - - - - - - - false - - - Remove - - - - - - - - + + + + Nr. + + + + + Feed + + + + + + + + + + Feed + + + + + + + + + + Spindle + + + + + + + + + + + false + + + Edit + + + + + + + Add + + + + + + + false + + + Remove + + + + @@ -553,315 +479,127 @@ Workplan - + - - - 0 - - - - - 0 - 0 - 378 - 793 - + + + + QFormLayout::AllNonFixedFieldsGrow - - Operations - - - - - - - QFormLayout::AllNonFixedFieldsGrow - - - - - Active Tool - - - - - - - - - - - - - - - - QAbstractItemView::InternalMove - - - - - - - - 0 - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - ... - - - - :/icons/button_up.svg:/icons/button_up.svg - - - - - - - ... - - - - :/icons/button_down.svg:/icons/button_down.svg - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - - - - - Edit - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Delete - - - - - - - - - - - - 0 - 0 - 395 - 778 - - - - Default Values - - - - - - Heights + + + + Active Tool + + + + + + + + + + + + + + + + QAbstractItemView::InternalMove + + + + + + + + 0 - - true - - - false - - - - - - Safe - - - - - - - - - - - - - Clearance - - - - - - - - - - Depths - - - true - - - false - - - - - - Step Down - - - - - - - - - - - - - Rapid Speed - - - true - - - false - - - - - - Horizontal - - - - - - - - - - - - - Vertical - - - - - - - - - - Operation - - - true - - - false - - - - - - Milling - - - - - - - - conventional - - - - - climb - - - - - - - - Tool Compensated - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + ... + + + + :/icons/button_up.svg:/icons/button_up.svg + + + + + + + ... + + + + :/icons/button_down.svg:/icons/button_down.svg + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + Edit + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Delete + + + + @@ -874,50 +612,6 @@
Gui/InputField.h
- - infoLabel - infoModel - infoMaterial - stock - stockExisting - stockExtXneg - stockExtXpos - stockExtYneg - stockExtYpos - stockExtZneg - stockExtZpos - stockCylinderRadius - stockCylinderHeight - stockBoxLength - stockBoxWidth - stockBoxHeight - orientXAxis - orientYAxis - orientZAxis - setOrigin - moveToOrigin - centerInStock - centerInStockXY - toolControllerList - toolControllerEdit - toolControllerAdd - toolControllerDelete - activeToolController - operationsList - operationEdit - operationDelete - groupBox_5 - defaultSafeHeight - defaultClearanceHeight - groupBox_6 - defaultStepDown - groupBox - lineEdit - lineEdit_2 - groupBox_7 - defaultMillingOp - defaultToolCompensation - diff --git a/src/Mod/Path/PathScripts/PathIconViewProvider.py b/src/Mod/Path/PathScripts/PathIconViewProvider.py index 47b848c1d9..a224bc2d7c 100644 --- a/src/Mod/Path/PathScripts/PathIconViewProvider.py +++ b/src/Mod/Path/PathScripts/PathIconViewProvider.py @@ -22,6 +22,8 @@ # * * # *************************************************************************** +import importlib + __title__ = "Path Icon ViewProvider" __author__ = "sliptonic (Brad Collette)" __url__ = "http://www.freecadweb.org" @@ -39,11 +41,34 @@ class ViewProvider(object): self.obj = vobj.Object def __getstate__(self): - return {'icon': self.icon } + attrs = {'icon': self.icon } + if hasattr(self, 'editModule'): + attrs['editModule'] = self.editModule + attrs['editCallback'] = self.editCallback + return attrs def __setstate__(self, state): self.icon = state['icon'] + if state.get('editModule', None): + self.editModule = state['editModule'] + self.editCallback = state['editCallback'] def getIcon(self): return ":/icons/Path-{}.svg".format(self.icon) + def onEdit(self, callback): + self.editModule = callback.__module__ + self.editCallback = callback.__name__ + + def _onEditCallback(self, edit): + if hasattr(self, 'editModule'): + mod = importlib.import_module(self.editModule) + callback = getattr(mod, self.editCallback) + callback(self.obj, self.vobj, edit) + + def setEdit(self, vobj, mode=0): + self._onEditCallback(True) + + def unsetEdit(self, arg1, arg2): + self._onEditCallback(False) + diff --git a/src/Mod/Path/PathScripts/PathJobGui.py b/src/Mod/Path/PathScripts/PathJobGui.py index a6ee5847b8..5eabb1876d 100644 --- a/src/Mod/Path/PathScripts/PathJobGui.py +++ b/src/Mod/Path/PathScripts/PathJobGui.py @@ -32,6 +32,7 @@ import PathScripts.PathStock as PathStock import PathScripts.PathToolController as PathToolController import PathScripts.PathToolLibraryManager as PathToolLibraryManager import PathScripts.PathUtil as PathUtil +import PathScripts.PathUtils as PathUtils import math import sys @@ -44,12 +45,20 @@ from pivy import coin def translate(context, text, disambig=None): return QtCore.QCoreApplication.translate(context, text, disambig) -if False: +if True: PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) PathLog.trackModule(PathLog.thisModule()) else: PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule()) +def _OpenCloseResourceEditor(obj, vobj, edit): + job = PathUtils.findParentJob(obj) + if job and job.ViewObject and job.ViewObject.Proxy: + if edit: + job.ViewObject.Proxy.editObject(obj) + else: + job.ViewObject.Proxy.uneditObject(obj) + class ViewProvider: def __init__(self, vobj): @@ -104,13 +113,16 @@ class ViewProvider: return hasattr(self, 'deleteOnReject') and self.deleteOnReject def setEdit(self, vobj, mode=0): - self.taskPanel = TaskPanel(vobj, self.deleteObjectsOnReject()) + self.openTaskPanel() + return True + + def openTaskPanel(self, activate=None): + self.taskPanel = TaskPanel(self.vobj, self.deleteObjectsOnReject()) FreeCADGui.Control.closeDialog() FreeCADGui.Control.showDialog(self.taskPanel) - self.taskPanel.setupUi() + self.taskPanel.setupUi(activate) self.deleteOnReject = False self.showOriginAxis(True) - return True def resetTaskPanel(self): self.showOriginAxis(False) @@ -120,6 +132,18 @@ class ViewProvider: if self.taskPanel: self.taskPanel.reject(False) + def editObject(self, obj): + if obj: + if obj == self.obj.Base: + return self.openTaskPanel('Base') + if obj == self.obj.Stock: + return self.openTaskPanel('Stock') + PathLog.info("Expected a specific object to edit - %s not recognized" % obj.Label) + return self.openTaskPanel() + + def uneditObject(self): + self.unsetEdit(None, None) + def getIcon(self): return ":/icons/Path-Job.svg" @@ -137,6 +161,14 @@ class ViewProvider: self.obj.Proxy.onDelete(self.obj, arg2) return True + def updateData(self, obj, prop): + PathLog.track(obj.Label, prop) + # make sure the resource view providers are setup properly + if prop == 'Base' and self.obj.Base and self.obj.Base.ViewObject and self.obj.Base.ViewObject.Proxy: + self.obj.Base.ViewObject.Proxy.onEdit(_OpenCloseResourceEditor) + if prop == 'Stock' and self.obj.Stock and self.obj.Stock.ViewObject and self.obj.Stock.ViewObject.Proxy: + self.obj.Stock.ViewObject.Proxy.onEdit(_OpenCloseResourceEditor) + class StockEdit(object): def __init__(self, obj, form): @@ -168,6 +200,8 @@ class StockEdit(object): if obj.Stock: obj.Document.removeObject(self.obj.Stock.Name) obj.Stock = stock + if stock.ViewObject and stock.ViewObject.Proxy: + stock.ViewObject.Proxy.onEdit(OpenCloseResourceEditor) def setLengthField(self, widget, prop): widget.setText(FreeCAD.Units.Quantity(prop.Value, FreeCAD.Units.Length).UserString) @@ -378,8 +412,8 @@ class TaskPanel: for o in PathJob.ObjectJob.baseCandidates(): if o != self.obj.Base: - self.form.infoModel.addItem(o.Label, o) - self.selectComboBoxText(self.form.infoModel, self.obj.Proxy.baseObject(self.obj).Label) + self.form.jobModel.addItem(o.Label, o) + self.selectComboBoxText(self.form.jobModel, self.obj.Proxy.baseObject(self.obj).Label) self.postProcessorDefaultTooltip = self.form.postProcessor.toolTip() self.postProcessorArgsDefaultTooltip = self.form.postProcessorArguments.toolTip() @@ -470,10 +504,11 @@ class TaskPanel: self.obj.PostProcessorArgs = str(self.form.postProcessorArguments.displayText()) self.obj.PostProcessorOutputFile = str(self.form.postProcessorOutputFile.text()) - self.obj.Label = str(self.form.infoLabel.text()) + self.obj.Label = str(self.form.jobLabel.text()) + self.obj.Description = str(self.form.jobDescription.toPlainText()) self.obj.Operations.Group = [self.form.operationsList.item(i).data(self.DataObject) for i in range(self.form.operationsList.count())] - selObj = self.form.infoModel.itemData(self.form.infoModel.currentIndex()) + selObj = self.form.jobModel.itemData(self.form.jobModel.currentIndex()) if self.obj.Proxy.baseObject(self.obj) != selObj: self.baseObjectRestoreVisibility(self.obj) self.obj.Document.removeObject(self.obj.Base.Name) @@ -551,9 +586,10 @@ class TaskPanel: def setFields(self): '''sets fields in the form to match the object''' - self.form.infoLabel.setText(self.obj.Label) - self.form.postProcessorOutputFile.setText(self.obj.PostProcessorOutputFile) + self.form.jobLabel.setText(self.obj.Label) + self.form.jobDescription.setPlainText(self.obj.Description) + self.form.postProcessorOutputFile.setText(self.obj.PostProcessorOutputFile) self.selectComboBoxText(self.form.postProcessor, self.obj.PostProcessor) self.form.postProcessorArguments.setText(self.obj.PostProcessorArgs) #self.obj.Proxy.onChanged(self.obj, "PostProcessor") @@ -567,12 +603,12 @@ class TaskPanel: baseindex = -1 if self.obj.Base: - baseindex = self.form.infoModel.findText(self.obj.Base.Label, QtCore.Qt.MatchFixedString) + baseindex = self.form.jobModel.findText(self.obj.Base.Label, QtCore.Qt.MatchFixedString) else: for o in FreeCADGui.Selection.getCompleteSelection(): - baseindex = self.form.infoModel.findText(o.Label, QtCore.Qt.MatchFixedString) + baseindex = self.form.jobModel.findText(o.Label, QtCore.Qt.MatchFixedString) if baseindex >= 0: - self.form.infoModel.setCurrentIndex(baseindex) + self.form.jobModel.setCurrentIndex(baseindex) self.updateToolController() self.stockEdit.setFields(self.obj) @@ -857,13 +893,13 @@ class TaskPanel: self.form.centerInStockXY.setEnabled(False) - def setupUi(self): + def setupUi(self, activate): self.updateStockEditor(-1) self.setFields() # Info - self.form.infoLabel.editingFinished.connect(self.getFields) - self.form.infoModel.currentIndexChanged.connect(self.getFields) + self.form.jobLabel.editingFinished.connect(self.getFields) + self.form.jobModel.currentIndexChanged.connect(self.getFields) # Post Processor self.form.postProcessor.currentIndexChanged.connect(self.getFields) @@ -880,8 +916,6 @@ class TaskPanel: self.form.operationEdit.hide() # not supported yet self.form.activeToolGroup.hide() # not supported yet - self.form.tbWorkplan.widget(1).hide() # default values not supported yet - self.form.tbWorkplan.removeItem(1) # default values not supported yet # Tool controller self.form.toolControllerList.itemSelectionChanged.connect(self.toolControllerSelect) @@ -907,6 +941,18 @@ class TaskPanel: self.form.moveToOrigin.clicked.connect(self.alignMoveToOrigin) self.updateSelection() + # set active page + if activate in ['General', 'Base']: + self.form.setCurrentIndex(0) + if activate in ['Output', 'Post Processor']: + self.form.setCurrentIndex(1) + if activate in ['Layout', 'Stock']: + self.form.setCurrentIndex(2) + if activate in ['Tools', 'Tool Controller']: + self.form.setCurrentIndex(3) + if activate in ['Workplan', 'Operations']: + self.form.setCurrentIndex(4) + def open(self): FreeCADGui.Selection.addObserver(self) @@ -929,6 +975,8 @@ def Create(base, template=None): obj = PathJob.Create('Job', base, template) ViewProvider(obj.ViewObject) FreeCAD.ActiveDocument.commitTransaction() + obj.ViewObject.Proxy.editObject(obj.Stock) + return obj except: PathLog.error(sys.exc_info()) FreeCAD.ActiveDocument.abortTransaction()