From 7d04aa502827ddcc160bb6f0ee7a4d378db14c67 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Mon, 16 Mar 2020 12:28:16 -0500 Subject: [PATCH] checkpoint --- .../Gui/Resources/panels/ToolBitEditor.ui | 30 +++----- .../Resources/panels/ToolBitLibraryEdit.ui | 65 ++++++----------- .../Path/Gui/Resources/preferences/PathJob.ui | 2 +- src/Mod/Path/PathScripts/PathPreferences.py | 5 +- .../PathScripts/PathPreferencesPathJob.py | 4 +- .../PathScripts/PathSetupSheetOpPrototype.py | 8 +++ src/Mod/Path/PathScripts/PathToolBit.py | 20 +++++- src/Mod/Path/PathScripts/PathToolBitEdit.py | 1 + .../Path/PathScripts/PathToolBitLibraryCmd.py | 10 ++- .../Path/PathScripts/PathToolBitLibraryGui.py | 71 ++++++++++++++----- 10 files changed, 127 insertions(+), 89 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/ToolBitEditor.ui b/src/Mod/Path/Gui/Resources/panels/ToolBitEditor.ui index f3acf73a58..42a5e98364 100644 --- a/src/Mod/Path/Gui/Resources/panels/ToolBitEditor.ui +++ b/src/Mod/Path/Gui/Resources/panels/ToolBitEditor.ui @@ -15,20 +15,12 @@ - + 0 - - - - 0 - 0 - 571 - 670 - - - + + Shape @@ -180,16 +172,8 @@ - - - - 0 - 0 - 571 - 670 - - - + + Attributes @@ -228,6 +212,8 @@
Gui/InputField.h
- + + + diff --git a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui index 989438c8f1..496dfb4285 100644 --- a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui +++ b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui @@ -16,27 +16,13 @@ - - - - <html><head/><body><p>Create a New Toolbit and add it to the library</p></body></html> - - - Create Toolbit - - - - :/icons/document-new.svg:/icons/document-new.svg - - - <html><head/><body><p>Add another Tool Bit to this library.</p><p><br/></p></body></html> - Add Existing ... + Add Toolbit ... @@ -121,23 +107,16 @@
- - - - Add Selected as Tool Controllers in the Job - - - - :/icons/edit-undo.svg:/icons/edit-undo.svg - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + Add Selected as Tool Controllers in the Job + + + + :/icons/edit_OK.svg:/icons/edit_OK.svg @@ -154,24 +133,13 @@ - - - - Open - - - - :/icons/document-open.svg:/icons/document-open.svg - - - <html><head/><body><p>Close the Tool Bit Library Editor</p></body></html> - Close + Cancel @@ -179,13 +147,24 @@ + + + + Open Table + + + + :/icons/document-open.svg:/icons/document-open.svg + + + <html><head/><body><p>Save the current Library</p></body></html> - Save + Save Table @@ -199,7 +178,7 @@ <html><head/><body><p>Save the library to a new file</p></body></html> - Save As... + Save Table As... diff --git a/src/Mod/Path/Gui/Resources/preferences/PathJob.ui b/src/Mod/Path/Gui/Resources/preferences/PathJob.ui index 45cc88e64b..9e1b6f7fcc 100644 --- a/src/Mod/Path/Gui/Resources/preferences/PathJob.ui +++ b/src/Mod/Path/Gui/Resources/preferences/PathJob.ui @@ -654,7 +654,7 @@ - + Remember last library diff --git a/src/Mod/Path/PathScripts/PathPreferences.py b/src/Mod/Path/PathScripts/PathPreferences.py index 5d2c882d08..2283e4f1f0 100644 --- a/src/Mod/Path/PathScripts/PathPreferences.py +++ b/src/Mod/Path/PathScripts/PathPreferences.py @@ -47,6 +47,7 @@ LastPathToolShape = "LastPathToolShape" UseLegacyTools = "UseLegacyTools" UseAbsoluteToolPaths = "UseAbsoluteToolPaths" +OpenLastLibrary = "OpenLastLibrary" # Linear tolerance to use when generating Paths, eg when tessellating geometry GeometryTolerance = "GeometryTolerance" @@ -161,11 +162,11 @@ def toolsStoreAbsolutePaths(): def toolsOpenLastLibrary(): return preferences().GetBool(OpenLastLibrary, False) -def setToolsSettings(legacy, relative): +def setToolsSettings(legacy, relative, lastlibrary): pref = preferences() pref.SetBool(UseLegacyTools, legacy) pref.SetBool(UseAbsoluteToolPaths, relative) - pref.SetBool(OpenLastLibrary, False) + pref.SetBool(OpenLastLibrary, lastlibrary) def defaultJobTemplate(): template = preferences().GetString(DefaultJobTemplate) diff --git a/src/Mod/Path/PathScripts/PathPreferencesPathJob.py b/src/Mod/Path/PathScripts/PathPreferencesPathJob.py index 0782efd67b..a6d1a392e1 100644 --- a/src/Mod/Path/PathScripts/PathPreferencesPathJob.py +++ b/src/Mod/Path/PathScripts/PathPreferencesPathJob.py @@ -109,7 +109,9 @@ class JobPreferencesPage: PathPreferences.setDefaultStockTemplate('') def saveToolsSettings(self): - PathPreferences.setToolsSettings(self.form.toolsUseLegacy.isChecked(), self.form.toolsAbsolutePaths.isChecked()) + PathPreferences.setToolsSettings(self.form.toolsUseLegacy.isChecked(), + self.form.toolsAbsolutePaths.isChecked(), + self.form.toolsOpenLastLibrary.isChecked()) def selectComboEntry(self, widget, text): index = widget.findText(text, QtCore.Qt.MatchFixedString) diff --git a/src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py b/src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py index d089dd7f7a..5f169d3df5 100644 --- a/src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py +++ b/src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py @@ -142,6 +142,13 @@ class PropertyString(Property): def typeString(self): return "String" +class PropertyMap(Property): + def typeString(self) + return "Map" + + def displayString(self, value): + return str(value) + class OpPrototype(object): PropertyType = { @@ -159,6 +166,7 @@ class OpPrototype(object): 'App::PropertyLink': Property, 'App::PropertyLinkList': Property, 'App::PropertyLinkSubListGlobal': Property, + 'App::PropertyMap': PropertyMap, 'App::PropertyPercent': PropertyPercent, 'App::PropertyString': PropertyString, 'App::PropertyStringList': Property, diff --git a/src/Mod/Path/PathScripts/PathToolBit.py b/src/Mod/Path/PathScripts/PathToolBit.py index eeae4a70ae..6f596e191b 100644 --- a/src/Mod/Path/PathScripts/PathToolBit.py +++ b/src/Mod/Path/PathScripts/PathToolBit.py @@ -195,6 +195,7 @@ class ToolBit(object): def onDelete(self, obj, arg2=None): PathLog.track(obj.Label) self.unloadBitBody(obj) + obj.Document.removeObject(obj.Name) def _updateBitShape(self, obj, properties=None): if not obj.BitBody is None: @@ -230,6 +231,7 @@ class ToolBit(object): return (doc, docOpened) def _removeBitBody(self, obj): + print('in _removebitbody') if obj.BitBody: obj.BitBody.removeObjectsFromDocument() obj.Document.removeObject(obj.BitBody.Name) @@ -326,6 +328,7 @@ class ToolBit(object): attrs['parameter'] = params params = {} for name in self.propertyNamesAttribute(obj): + print(f"shapeattr {name}") params[name] = PathUtil.getPropertyValueString(obj, name) attrs['attribute'] = params return attrs @@ -343,6 +346,7 @@ class AttributePrototype(PathSetupSheetOpPrototype.OpPrototype): self.addProperty('App::PropertyDistance', 'LengthOffset', PropertyGroupAttribute, translate('PathToolBit', 'Length offset in Z direction')) self.addProperty('App::PropertyInteger', 'Flutes', PropertyGroupAttribute, translate('PathToolBit', 'The number of flutes')) self.addProperty('App::PropertyDistance', 'ChipLoad', PropertyGroupAttribute, translate('PathToolBit', 'Chipload as per manufacturer')) + # self.addProperty('App::PropertyMap', 'UserAttributes', PropertyGroupAttribute, translate('PathTooolBit', 'User Defined Values')) class ToolBitFactory(object): @@ -358,11 +362,21 @@ class ToolBitFactory(object): obj.Proxy.unloadBitBody(obj) params = attrs['attribute'] proto = AttributePrototype() + uservals = {} for pname in params: - prop = proto.getProperty(pname) - val = prop.valueFromString(params[pname]) + try: + prop = proto.getProperty(pname) + val = prop.valueFromString(params[pname]) + prop.setupProperty(obj, pname, PropertyGroupAttribute, prop.valueFromString(params[pname])) + except: + prop = obj.addProperty('App::PropertyString', pname, "Attribute", translate('PathTooolBit', 'User Defined Value')) + setattr(obj, pname, params[pname]) + #prop = proto.getProperty("UserAttributes") + #uservals.update({pname: params[pname]}) + #prop = .setupPropertyobj, pname, "UserAttributes", prop.valueFromString(params[pname])) + print("prop[%s] = %s (%s)" % (pname, params[pname], type(val))) - prop.setupProperty(obj, pname, PropertyGroupAttribute, prop.valueFromString(params[pname])) + #prop.setupProperty(obj, pname, PropertyGroupAttribute, prop.valueFromString(params[pname])) return obj def CreateFrom(self, path, name='ToolBit'): diff --git a/src/Mod/Path/PathScripts/PathToolBitEdit.py b/src/Mod/Path/PathScripts/PathToolBitEdit.py index fdea4e672a..2f95d60216 100644 --- a/src/Mod/Path/PathScripts/PathToolBitEdit.py +++ b/src/Mod/Path/PathScripts/PathToolBitEdit.py @@ -88,6 +88,7 @@ class ToolBitEditor(object): self.model.setHorizontalHeaderLabels(['Set', 'Property', 'Value']) for i, name in enumerate(self.props): + print(f"propname: {name}") prop = self.proto.getProperty(name) isset = hasattr(tool, name) if isset: diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py b/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py index ae5573013b..471e73a1df 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py @@ -25,6 +25,7 @@ import FreeCAD import FreeCADGui import PySide.QtCore as QtCore +import PathScripts.PathPreferences as PathPreferences class CommandToolBitLibraryOpen: ''' @@ -45,7 +46,13 @@ class CommandToolBitLibraryOpen: def Activated(self): import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui library = PathToolBitLibraryGui.ToolBitLibrary() - library.open() + + lastlib = PathPreferences.lastPathToolLibrary() + + if PathPreferences.toolsOpenLastLibrary() and lastlib.endswith('.fctl'): + library.open(lastlib) + else: + library.open() class CommandToolBitLibraryLoad: ''' @@ -83,6 +90,7 @@ class CommandToolBitLibraryLoad: import PathScripts.PathToolControllerGui as PathToolControllerGui library = PathToolBitLibraryGui.ToolBitLibrary() + if 1 == library.open(dialog=True) and job: for nr, tool in library.selectedOrAllTools(): tc = PathToolControllerGui.Create("TC: {}".format(tool.Label), tool, nr) diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index 91352201ef..a000540516 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -30,6 +30,8 @@ import PathScripts.PathPreferences as PathPreferences import PathScripts.PathToolBit as PathToolBit import PathScripts.PathToolBitGui as PathToolBitGui import PathScripts.PathToolBitEdit as PathToolBitEdit +import PathScripts.PathToolControllerGui as PathToolControllerGui +import PathScripts.PathUtilsGui as PathUtilsGui import PySide import json import os @@ -192,6 +194,17 @@ class ToolBitLibrary(object): tools.append((toolNr, PathToolBit.Factory.CreateFrom(toolPath))) return tools + def selectedOrAllToolControllers(self): + tools = self.selectedOrAllTools() + + userinput = PathUtilsGui.PathUtilsUserInput() + job = userinput.chooseJob(PathUtilsGui.PathUtils.GetJobs()) + for tool in tools: + print(tool) + tc = PathToolControllerGui.Create(tool[1].Label, tool[1], tool[0]) + job.Proxy.addToolController(tc) + FreeCAD.ActiveDocument.recompute() + def toolDelete(self): PathLog.track() selectedRows = set([index.row() for index in self.toolTableView.selectedIndexes()]) @@ -205,7 +218,17 @@ class ToolBitLibrary(object): def toolSelect(self, selected, deselected): # pylint: disable=unused-argument - self.form.toolDelete.setEnabled(len(self.toolTableView.selectedIndexes()) > 0) + sel = len(self.toolTableView.selectedIndexes()) > 0 + self.form.toolDelete.setEnabled(sel) + + addTCSelectedText = translate("PathToolLibraryManager", "Add SELECTED as Tool Controllers in the Job") + addTCAllText = translate("PathToolLibraryManager", "Add ALL as Tool Controllers in the Job") + + if sel: + self.form.addToolController.setText(addTCSelectedText) + else: + self.form.addToolController.setText(addTCAllText) + def open(self, path=None, dialog=False): '''open(path=None, dialog=False) ... load library stored in path and bring up ui. @@ -230,11 +253,14 @@ class ToolBitLibrary(object): PathLog.track() filename = PySide.QtGui.QFileDialog.getOpenFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl') if filename and filename[0]: + print(filename) + print(filename[0]) path = filename[0] PathPreferences.setLastPathToolLibrary(filename[0]) if not PathPreferences.toolsOpenLastLibrary(): - path = os.path.dirname(path) + PathPreferences.setLastPathToolLibrary(os.path.dirname(filename[0])) + #path = os.path.dirname(path) self.libraryLoad(path) @@ -264,20 +290,20 @@ class ToolBitLibrary(object): def libraryNew(self): self.libraryLoad(None) - def createToolBit(self): - tool = PathToolBit.ToolBitFactory().Create() + #def createToolBit(self): + # tool = PathToolBit.ToolBitFactory().Create() - #self.dialog = PySide.QtGui.QDialog(self.form) - #layout = PySide.QtGui.QVBoxLayout(self.dialog) - self.editor = PathToolBitEdit.ToolBitEditor(tool, self.form.toolTableGroup) - self.editor.setupUI() - self.buttons = PySide.QtGui.QDialogButtonBox( - PySide.QtGui.QDialogButtonBox.Ok | PySide.QtGui.QDialogButtonBox.Cancel, - PySide.QtCore.Qt.Horizontal, self.dialog) - layout.addWidget(self.buttons) - #self.buttons.accepted.connect(accept) - #self.buttons.rejected.connect(reject) - print(self.dialog.exec_()) + # #self.dialog = PySide.QtGui.QDialog(self.form) + # #layout = PySide.QtGui.QVBoxLayout(self.dialog) + # self.editor = PathToolBitEdit.ToolBitEditor(tool, self.form.toolTableGroup) + # self.editor.setupUI() + # self.buttons = PySide.QtGui.QDialogButtonBox( + # PySide.QtGui.QDialogButtonBox.Ok | PySide.QtGui.QDialogButtonBox.Cancel, + # PySide.QtCore.Qt.Horizontal, self.dialog) + # layout.addWidget(self.buttons) + # #self.buttons.accepted.connect(accept) + # #self.buttons.rejected.connect(reject) + # print(self.dialog.exec_()) def librarySave(self): library = {} @@ -367,12 +393,22 @@ class ToolBitLibrary(object): self.librarySave() self.updateToolbar() + + def libraryCancel(self): self.form.close() def columnNames(self): return ['Nr', 'Tool', 'Shape', 'Diameter'] + def toolEdit(self, selected): + print('here') + print(selected) + if selected.column() == 0: + print('nope') + else: + print('yep') + def setupUI(self): PathLog.track('+') self.model = PySide.QtGui.QStandardItemModel(0, len(self.columnNames()), self.toolTableView) @@ -381,11 +417,12 @@ class ToolBitLibrary(object): self.toolTableView.setModel(self.model) self.toolTableView.resizeColumnsToContents() self.toolTableView.selectionModel().selectionChanged.connect(self.toolSelect) + self.toolTableView.doubleClicked.connect(self.toolEdit) self.form.toolAdd.clicked.connect(self.toolAdd) self.form.toolDelete.clicked.connect(self.toolDelete) self.form.toolEnumerate.clicked.connect(self.toolEnumerate) - self.form.createToolBit.clicked.connect(self.createToolBit) + # self.form.createToolBit.clicked.connect(self.createToolBit) #self.form.libraryNew.clicked.connect(self.libraryNew) self.form.libraryOpen.clicked.connect(self.libraryOpen) @@ -393,6 +430,8 @@ class ToolBitLibrary(object): self.form.librarySaveAs.clicked.connect(self.librarySaveAs) self.form.libraryCancel.clicked.connect(self.libraryCancel) + self.form.addToolController.clicked.connect(self.selectedOrAllToolControllers) + self.toolSelect([], []) self.updateToolbar() PathLog.track('-')