From 929797c6ef3615e3078da3872a1f98064e4c91b4 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Wed, 11 Mar 2020 21:45:21 -0500 Subject: [PATCH 01/11] revise library editor --- .../Resources/panels/ToolBitLibraryEdit.ui | 312 +++++++----------- .../Path/PathScripts/PathToolBitLibraryGui.py | 20 +- 2 files changed, 142 insertions(+), 190 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui index b5cfdae83c..616fe0393a 100644 --- a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui +++ b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui @@ -15,105 +15,61 @@ - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - <html><head/><body><p>Create a new library with an empty list of Tool Bits.</p></body></html> - - - ... - - - - :/icons/document-new.svg:/icons/document-new.svg - - - - - - - <html><head/><body><p>Open an existing Tool Bit library.</p></body></html> - - - ... - - - - :/icons/document-open.svg:/icons/document-open.svg - - - - - - - <html><head/><body><p>Save Tool Bit library.</p></body></html> - - - ... - - - - :/icons/document-save.svg:/icons/document-save.svg - - - - - - - <html><head/><body><p>Save Tool Bit library under new name.</p></body></html> - - - ... - - - - :/icons/document-save-as.svg:/icons/document-save-as.svg - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - <html><head/><body><p>Edit Tool Bit library editor settings.</p></body></html> - - - ... - - - - :/icons/preferences-system.svg:/icons/preferences-system.svg - - - - - + + + + + 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 ... + + + + :/icons/list-add.svg:/icons/list-add.svg + + + + + + + <html><head/><body><p>Delete selected Tool Bit(s) from the library.</p><p><br/></p></body></html> + + + Remove Selected + + + + :/icons/list-remove.svg:/icons/list-remove.svg + + + + + + + <html><head/><body><p>Assigne numbers to each Tool Bit according to its current position in the library. The first Tool Bit is assigned the ID 1.</p></body></html> + + + Enumerate + + + + :/icons/button_sort.svg:/icons/button_sort.svg + + + + @@ -167,57 +123,6 @@ 0 - - - - <html><head/><body><p>Add another Tool Bit to this library.</p><p><br/></p></body></html> - - - Add ... - - - - :/icons/list-add.svg:/icons/list-add.svg - - - - - - - <html><head/><body><p>Delete selected Tool Bit(s) from the library.</p><p><br/></p></body></html> - - - Delete - - - - :/icons/list-remove.svg:/icons/list-remove.svg - - - - - - - <html><head/><body><p>Assigned numbers to each Tool Bit according to its current position in the library. The first Tool Bit is assigned the ID 1.</p></body></html> - - - Enumerate - - - - - - - Qt::Vertical - - - - 20 - 115 - - - - @@ -225,52 +130,81 @@ - - - Qt::Horizontal + + + Add Selected as Tool Controllers in the Job - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + :/icons/edit-undo.svg:/icons/edit-undo.svg + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Open + + + + :/icons/document-open.svg:/icons/document-open.svg + + + + + + + Cancel + + + + :/icons/button_invalid.svg:/icons/button_invalid.svg + + + + + + + Save + + + + :/icons/document-save.svg:/icons/document-save.svg + + + + + + + Save As... + + + + :/icons/document-save-as.svg:/icons/document-save-as.svg + + + + + - - - buttonBox - accepted() - Dialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - Dialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - + diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index 17b12638a2..de837062f7 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -28,6 +28,7 @@ import PathScripts.PathLog as PathLog import PathScripts.PathPreferences as PathPreferences import PathScripts.PathToolBit as PathToolBit import PathScripts.PathToolBitGui as PathToolBitGui +import PathScripts.PathToolBitEdit as PathToolBitEdit import PySide import json import os @@ -255,6 +256,21 @@ class ToolBitLibrary(object): def libraryNew(self): self.libraryLoad(None) + 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.dialog) + 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 = {} tools = [] @@ -295,11 +311,13 @@ class ToolBitLibrary(object): 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.libraryNew.clicked.connect(self.libraryNew) + #self.form.libraryNew.clicked.connect(self.libraryNew) self.form.libraryOpen.clicked.connect(self.libraryOpen) self.form.librarySave.clicked.connect(self.librarySave) self.form.librarySaveAs.clicked.connect(self.librarySaveAs) + #self.form.libraryCancel.clicked.connect(self.cancel) self.toolSelect([], []) self.updateToolbar() From e26f57b48f1d8aa1e7fe44e73c56010252f527c7 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Sun, 15 Mar 2020 16:07:19 -0500 Subject: [PATCH 02/11] linuxcnc tool table exporter --- .../Gui/Resources/panels/ToolBitEditor.ui | 10 +- .../Resources/panels/ToolBitLibraryEdit.ui | 72 ++++++------ .../Path/Gui/Resources/preferences/PathJob.ui | 23 ++-- src/Mod/Path/PathScripts/PathPreferences.py | 4 + .../Path/PathScripts/PathToolBitLibraryGui.py | 104 +++++++++++++++--- 5 files changed, 153 insertions(+), 60 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/ToolBitEditor.ui b/src/Mod/Path/Gui/Resources/panels/ToolBitEditor.ui index 1ffb408a8a..f3acf73a58 100644 --- a/src/Mod/Path/Gui/Resources/panels/ToolBitEditor.ui +++ b/src/Mod/Path/Gui/Resources/panels/ToolBitEditor.ui @@ -24,8 +24,8 @@ 0 0 - 559 - 626 + 571 + 670 @@ -61,7 +61,7 @@ - Type + Shape File @@ -185,8 +185,8 @@ 0 0 - 559 - 626 + 571 + 670 diff --git a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui index 616fe0393a..989438c8f1 100644 --- a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui +++ b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui @@ -6,18 +6,21 @@ 0 0 - 958 - 508 + 954 + 587 ToolBit Library - - + + + + <html><head/><body><p>Create a New Toolbit and add it to the library</p></body></html> + Create Toolbit @@ -55,6 +58,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -71,15 +87,9 @@ - + - - 0 - - - 0 - @@ -108,28 +118,10 @@ - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - + Add Selected as Tool Controllers in the Job @@ -140,8 +132,15 @@ - + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + @@ -168,8 +167,11 @@ + + <html><head/><body><p>Close the Tool Bit Library Editor</p></body></html> + - Cancel + Close @@ -179,6 +181,9 @@ + + <html><head/><body><p>Save the current Library</p></body></html> + Save @@ -190,6 +195,9 @@ + + <html><head/><body><p>Save the library to a new file</p></body></html> + Save As... diff --git a/src/Mod/Path/Gui/Resources/preferences/PathJob.ui b/src/Mod/Path/Gui/Resources/preferences/PathJob.ui index 4b458788e5..45cc88e64b 100644 --- a/src/Mod/Path/Gui/Resources/preferences/PathJob.ui +++ b/src/Mod/Path/Gui/Resources/preferences/PathJob.ui @@ -24,8 +24,8 @@ 0 0 - 467 - 448 + 424 + 537 @@ -142,8 +142,8 @@ 0 0 - 665 - 449 + 424 + 537 @@ -348,8 +348,8 @@ 0 0 - 431 - 718 + 407 + 570 @@ -625,8 +625,8 @@ 0 0 - 412 - 461 + 424 + 537 @@ -653,6 +653,13 @@ + + + + Remember last library + + + diff --git a/src/Mod/Path/PathScripts/PathPreferences.py b/src/Mod/Path/PathScripts/PathPreferences.py index 0525a3b3f5..5d2c882d08 100644 --- a/src/Mod/Path/PathScripts/PathPreferences.py +++ b/src/Mod/Path/PathScripts/PathPreferences.py @@ -158,10 +158,14 @@ def toolsReallyUseLegacyTools(): def toolsStoreAbsolutePaths(): return preferences().GetBool(UseAbsoluteToolPaths, False) +def toolsOpenLastLibrary(): + return preferences().GetBool(OpenLastLibrary, False) + def setToolsSettings(legacy, relative): pref = preferences() pref.SetBool(UseLegacyTools, legacy) pref.SetBool(UseAbsoluteToolPaths, relative) + pref.SetBool(OpenLastLibrary, False) def defaultJobTemplate(): template = preferences().GetString(DefaultJobTemplate) diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index de837062f7..91352201ef 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -23,6 +23,7 @@ # *************************************************************************** +import FreeCAD import FreeCADGui import PathScripts.PathLog as PathLog import PathScripts.PathPreferences as PathPreferences @@ -41,6 +42,9 @@ import uuid as UUID _UuidRole = PySide.QtCore.Qt.UserRole + 1 _PathRole = PySide.QtCore.Qt.UserRole + 2 +def translate(context, text, disambig=None): + return PySide.QtCore.QCoreApplication.translate(context, text, disambig) + class _TableView(PySide.QtGui.QTableView): '''Subclass of QTableView to support rearrange and copying of ToolBits''' @@ -224,10 +228,14 @@ class ToolBitLibrary(object): def libraryOpen(self): PathLog.track() - foo = PySide.QtGui.QFileDialog.getOpenFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl') - if foo and foo[0]: - path = foo[0] - PathPreferences.setLastPathToolLibrary(os.path.dirname(path)) + filename = PySide.QtGui.QFileDialog.getOpenFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl') + if filename and filename[0]: + path = filename[0] + PathPreferences.setLastPathToolLibrary(filename[0]) + + if not PathPreferences.toolsOpenLastLibrary(): + path = os.path.dirname(path) + self.libraryLoad(path) def libraryLoad(self, path): @@ -259,9 +267,9 @@ class ToolBitLibrary(object): 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.dialog) + #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, @@ -287,14 +295,80 @@ class ToolBitLibrary(object): with open(self.path, 'w') as fp: json.dump(library, fp, sort_keys=True, indent=2) + def libararySaveLinuxCNC(self, path): + with open(path, 'w') as fp: + fp.write(";\n") + + for row in range(self.model.rowCount()): + toolNr = self.model.data(self.model.index(row, 0), PySide.QtCore.Qt.EditRole) + toolPath = self.model.data(self.model.index(row, 0), _PathRole) + + bit = PathToolBit.Factory.CreateFrom(toolPath) + if bit: + PathLog.track(bit) + + pocket = bit.Pocket if hasattr(bit, "Pocket") else "" + xoffset = bit.Xoffset if hasattr(bit, "Xoffset") else "0" + yoffset = bit.Yoffset if hasattr(bit, "Yoffset") else "0" + zoffset = bit.Zoffset if hasattr(bit, "Zoffset") else "0" + aoffset = bit.Aoffset if hasattr(bit, "Aoffset") else "0" + boffset = bit.Boffset if hasattr(bit, "Boffset") else "0" + coffset = bit.Coffset if hasattr(bit, "Coffset") else "0" + uoffset = bit.Uoffset if hasattr(bit, "Uoffset") else "0" + voffset = bit.Voffset if hasattr(bit, "Voffset") else "0" + woffset = bit.Woffset if hasattr(bit, "Woffset") else "0" + + diameter = bit.Diameter if hasattr(bit, "Diameter") else "0" + frontangle = bit.FrontAngle if hasattr(bit, "FrontAngle") else "0" + backangle = bit.BackAngle if hasattr(bit, "BackAngle") else "0" + orientation = bit.Orientation if hasattr(bit, "Orientation") else "0" + remark = bit.Label + + fp.write(f"T{toolNr} "\ + f"P{pocket} "\ + f"X{xoffset} "\ + f"Y{yoffset} "\ + f"Z{zoffset} "\ + f"A{aoffset} "\ + f"B{boffset} "\ + f"C{coffset} "\ + f"U{uoffset} "\ + f"V{voffset} "\ + f"W{woffset} "\ + f"D{diameter} "\ + f"I{frontangle} "\ + f"J{backangle} "\ + f"Q{orientation} ;"\ + f"{remark}\n") + + FreeCAD.ActiveDocument.removeObject(bit.Name) + + else: + PathLog.error("Could not find tool #{}: {}".format(nr, library['tools'][nr])) + def librarySaveAs(self): - foo = PySide.QtGui.QFileDialog.getSaveFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl') - if foo and foo[0]: - path = foo[0] if foo[0].endswith('.fctl') else "{}.fctl".format(foo[0]) - PathPreferences.setLastPathToolLibrary(os.path.dirname(path)) - self.path = path - self.librarySave() - self.updateToolbar() + TooltableTypeJSON = translate("PathToolLibraryManager", "Tooltable JSON (*.fctl)") + TooltableTypeLinuxCNC = translate("PathToolLibraryManager", "LinuxCNC tooltable (*.tbl)") + + filename = PySide.QtGui.QFileDialog.getSaveFileName(self.form, \ + translate("TooltableEditor", "Save toolbit library", None), \ + None, "{};;{}".format(TooltableTypeJSON, \ + TooltableTypeLinuxCNC)) + # filename = PySide.QtGui.QFileDialog.getSaveFileName(self.form, \ + # 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl') + if filename and filename[0]: + if filename[1] == TooltableTypeLinuxCNC: + path = filename[0] if filename[0].endswith('.tbl') else "{}.tbl".format(filename[0]) + self.libararySaveLinuxCNC(path) + else: + path = filename[0] if filename[0].endswith('.fctl') else "{}.fctl".format(filename[0]) + PathPreferences.setLastPathToolLibrary(os.path.dirname(path)) + self.path = path + self.librarySave() + self.updateToolbar() + + def libraryCancel(self): + self.form.close() def columnNames(self): return ['Nr', 'Tool', 'Shape', 'Diameter'] @@ -317,7 +391,7 @@ class ToolBitLibrary(object): self.form.libraryOpen.clicked.connect(self.libraryOpen) self.form.librarySave.clicked.connect(self.librarySave) self.form.librarySaveAs.clicked.connect(self.librarySaveAs) - #self.form.libraryCancel.clicked.connect(self.cancel) + self.form.libraryCancel.clicked.connect(self.libraryCancel) self.toolSelect([], []) self.updateToolbar() From 7d04aa502827ddcc160bb6f0ee7a4d378db14c67 Mon Sep 17 00:00:00 2001 From: sliptonic Date: Mon, 16 Mar 2020 12:28:16 -0500 Subject: [PATCH 03/11] 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('-') From b48d67976ffe25a28be3f2702db16d78aeacec5f Mon Sep 17 00:00:00 2001 From: sliptonic Date: Sat, 4 Apr 2020 19:09:39 -0500 Subject: [PATCH 04/11] user attributes kinda works. Hacked. --- .../PathScripts/PathSetupSheetOpPrototype.py | 2 +- src/Mod/Path/PathScripts/PathToolBit.py | 29 ++++++---- src/Mod/Path/PathScripts/PathToolBitEdit.py | 58 ++++++++++++++----- .../Path/PathScripts/PathToolBitLibraryGui.py | 1 + 4 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py b/src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py index 5f169d3df5..a162bb4e04 100644 --- a/src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py +++ b/src/Mod/Path/PathScripts/PathSetupSheetOpPrototype.py @@ -143,7 +143,7 @@ class PropertyString(Property): return "String" class PropertyMap(Property): - def typeString(self) + def typeString(self): return "Map" def displayString(self, value): diff --git a/src/Mod/Path/PathScripts/PathToolBit.py b/src/Mod/Path/PathScripts/PathToolBit.py index 6f596e191b..5f40fc6219 100644 --- a/src/Mod/Path/PathScripts/PathToolBit.py +++ b/src/Mod/Path/PathScripts/PathToolBit.py @@ -41,8 +41,8 @@ __author__ = "sliptonic (Brad Collette)" __url__ = "http://www.freecadweb.org" __doc__ = "Class to deal with and represent a tool bit." -#PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) -#PathLog.trackModule() +# PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) +# PathLog.trackModule() def translate(context, text, disambig=None): return PySide.QtCore.QCoreApplication.translate(context, text, disambig) @@ -304,6 +304,7 @@ class ToolBit(object): return None def saveToFile(self, obj, path, setFile=True): + print('were saving now') try: with open(path, 'w') as fp: json.dump(self.shapeAttrs(obj), fp, indent=' ') @@ -329,7 +330,11 @@ class ToolBit(object): params = {} for name in self.propertyNamesAttribute(obj): print(f"shapeattr {name}") - params[name] = PathUtil.getPropertyValueString(obj, name) + if name == "UserAttributes": + for key, value in obj.UserAttributes.items(): + params[key] = value + else: + params[name] = PathUtil.getPropertyValueString(obj, name) attrs['attribute'] = params return attrs @@ -346,7 +351,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')) + self.addProperty('App::PropertyMap', 'UserAttributes', PropertyGroupAttribute, translate('PathTooolBit', 'User Defined Values')) class ToolBitFactory(object): @@ -364,18 +369,22 @@ class ToolBitFactory(object): proto = AttributePrototype() uservals = {} for pname in params: + print(f"pname: {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])) + # 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.setupProperty(obj, pname, "UserAttributes", prop.valueFromString(params[pname])) - print("prop[%s] = %s (%s)" % (pname, params[pname], type(val))) + if len(uservals.items()) > 0: + prop.setupProperty(obj, "UserAttributes", PropertyGroupAttribute, uservals) + + # print("prop[%s] = %s (%s)" % (pname, params[pname], type(val))) #prop.setupProperty(obj, pname, PropertyGroupAttribute, prop.valueFromString(params[pname])) return obj diff --git a/src/Mod/Path/PathScripts/PathToolBitEdit.py b/src/Mod/Path/PathScripts/PathToolBitEdit.py index 2f95d60216..d6928b8bf5 100644 --- a/src/Mod/Path/PathScripts/PathToolBitEdit.py +++ b/src/Mod/Path/PathScripts/PathToolBitEdit.py @@ -84,33 +84,59 @@ class ToolBitEditor(object): self.proto = PathToolBit.AttributePrototype() self.props = sorted(self.proto.properties) self.delegate = PathSetupSheetGui.Delegate(self.form) - self.model = QtGui.QStandardItemModel(len(self.props), 3, self.form) + self.model = QtGui.QStandardItemModel(len(self.props)-1, 3, self.form) 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: prop.setValue(getattr(tool, name)) - self.model.setData(self.model.index(i, 0), isset, QtCore.Qt.EditRole) - self.model.setData(self.model.index(i, 1), name, QtCore.Qt.EditRole) - self.model.setData(self.model.index(i, 2), prop, PathSetupSheetGui.Delegate.PropertyRole) - self.model.setData(self.model.index(i, 2), prop.displayString(), QtCore.Qt.DisplayRole) + if name == "UserAttributes": + continue - self.model.item(i, 0).setCheckable(True) - self.model.item(i, 0).setText('') - self.model.item(i, 1).setEditable(False) - self.model.item(i, 1).setToolTip(prop.info) - self.model.item(i, 2).setToolTip(prop.info) - - if isset: - self.model.item(i, 0).setCheckState(QtCore.Qt.Checked) else: - self.model.item(i, 0).setCheckState(QtCore.Qt.Unchecked) - self.model.item(i, 1).setEnabled(False) - self.model.item(i, 2).setEnabled(False) + + self.model.setData(self.model.index(i, 0), isset, QtCore.Qt.EditRole) + self.model.setData(self.model.index(i, 1), name, QtCore.Qt.EditRole) + self.model.setData(self.model.index(i, 2), prop, PathSetupSheetGui.Delegate.PropertyRole) + self.model.setData(self.model.index(i, 2), prop.displayString(), QtCore.Qt.DisplayRole) + + self.model.item(i, 0).setCheckable(True) + self.model.item(i, 0).setText('') + self.model.item(i, 1).setEditable(False) + self.model.item(i, 1).setToolTip(prop.info) + self.model.item(i, 2).setToolTip(prop.info) + + if isset: + self.model.item(i, 0).setCheckState(QtCore.Qt.Checked) + else: + self.model.item(i, 0).setCheckState(QtCore.Qt.Unchecked) + self.model.item(i, 1).setEnabled(False) + self.model.item(i, 2).setEnabled(False) + + if hasattr(tool, "UserAttributes"): + for key, value in tool.UserAttributes.items(): + print(key, value) + c1 = QtGui.QStandardItem() + c1.setCheckable(False) + c1.setEditable(False) + c1.setCheckState(QtCore.Qt.CheckState.Checked) + + c1.setText('') + c2 = QtGui.QStandardItem(key) + c2.setEditable(False) + c3 = QtGui.QStandardItem(value) + c3.setEditable(False) + + self.model.appendRow([c1, c2, c3]) + #QtGui.QStandardItem([True, key, value])) + self.form.attrTable.setModel(self.model) self.form.attrTable.setItemDelegateForColumn(2, self.delegate) diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index a000540516..ac9febbd0e 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -269,6 +269,7 @@ class ToolBitLibrary(object): self.model.clear() self.model.setHorizontalHeaderLabels(self.columnNames()) if path: + print(f"Path: {path}") with open(path) as fp: library = json.load(fp) for toolBit in library['tools']: From 901d2f90aa8005e28a881ecf1a82a1774abcf1c9 Mon Sep 17 00:00:00 2001 From: Patrick F Date: Fri, 10 Apr 2020 22:10:35 +0200 Subject: [PATCH 05/11] Add tool table list to UI --- .../Resources/panels/ToolBitLibraryEdit.ui | 283 ++++++++++++------ src/Mod/Path/PathScripts/PathPreferences.py | 3 +- .../Path/PathScripts/PathToolBitLibraryCmd.py | 2 +- .../Path/PathScripts/PathToolBitLibraryGui.py | 130 +++++++- 4 files changed, 313 insertions(+), 105 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui index 496dfb4285..e4a1ec9845 100644 --- a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui +++ b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui @@ -14,95 +14,147 @@ ToolBit Library - - - - - - <html><head/><body><p>Add another Tool Bit to this library.</p><p><br/></p></body></html> - - - Add Toolbit ... - - - - :/icons/list-add.svg:/icons/list-add.svg - - - - - - - <html><head/><body><p>Delete selected Tool Bit(s) from the library.</p><p><br/></p></body></html> - - - Remove Selected - - - - :/icons/list-remove.svg:/icons/list-remove.svg - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - <html><head/><body><p>Assigne numbers to each Tool Bit according to its current position in the library. The first Tool Bit is assigned the ID 1.</p></body></html> - - - Enumerate - - - - :/icons/button_sort.svg:/icons/button_sort.svg - - - - - + + 0 + + + 0 + + + 0 + + + 0 + - - - true + + + 0 - - <html><head/><body><p>Table of Tool Bits of the library.</p></body></html> - - - true - - - QAbstractItemView::InternalMove - - - Qt::MoveAction - - - QAbstractItemView::SelectRows - - - true - - - false - - + + + + + 226 + 16777215 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + Tool Table + + + + + + + + 32 + 32 + + + + + + + + :/icons/edit-edit.svg:/icons/edit-edit.svg + + + + + + + + 32 + 32 + + + + + + + + :/icons/list-add.svg:/icons/list-add.svg + + + + + + + + 32 + 32 + + + + + + + + :/icons/list-remove.svg:/icons/list-remove.svg + + + + + + + + + + + + + + + true + + + <html><head/><body><p>Table of Tool Bits of the library.</p></body></html> + + + true + + + QAbstractItemView::InternalMove + + + Qt::MoveAction + + + QAbstractItemView::SelectRows + + + true + + + false + + + + @@ -112,7 +164,7 @@ - Add Selected as Tool Controllers in the Job + Add Tool Controller(s) to Job @@ -150,7 +202,7 @@ - Open Table + Open Library @@ -188,6 +240,65 @@
+ + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + <html><head/><body><p>Add another Tool Bit to this library.</p><p><br/></p></body></html> + + + Add Toolbit ... + + + + :/icons/list-add.svg:/icons/list-add.svg + + + + + + + <html><head/><body><p>Delete selected Tool Bit(s) from the library.</p><p><br/></p></body></html> + + + Remove Selected + + + + :/icons/list-remove.svg:/icons/list-remove.svg + + + + + + + <html><head/><body><p>Assigne numbers to each Tool Bit according to its current position in the library. The first Tool Bit is assigned the ID 1.</p></body></html> + + + Enumerate + + + + :/icons/button_sort.svg:/icons/button_sort.svg + + + + + diff --git a/src/Mod/Path/PathScripts/PathPreferences.py b/src/Mod/Path/PathScripts/PathPreferences.py index 2283e4f1f0..87d8889c22 100644 --- a/src/Mod/Path/PathScripts/PathPreferences.py +++ b/src/Mod/Path/PathScripts/PathPreferences.py @@ -84,7 +84,6 @@ def allEnabledPostProcessors(include = None): return l return enabled - def defaultPostProcessor(): pref = preferences() return pref.GetString(PostProcessorDefault, "") @@ -195,7 +194,6 @@ def setPostProcessorDefaults(processor, args, blacklist): pref.SetString(PostProcessorDefaultArgs, args) pref.SetString(PostProcessorBlacklist, "%s" % (blacklist)) - def setOutputFileDefaults(fileName, policy): pref = preferences() pref.SetString(PostProcessorOutputFile, fileName) @@ -216,6 +214,7 @@ def setDefaultStockTemplate(template): def defaultTaskPanelLayout(): return preferences().GetInt(DefaultTaskPanelLayout, 0) + def setDefaultTaskPanelLayout(style): preferences().SetInt(DefaultTaskPanelLayout, style) diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py b/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py index 471e73a1df..90f38fb896 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py @@ -49,7 +49,7 @@ class CommandToolBitLibraryOpen: lastlib = PathPreferences.lastPathToolLibrary() - if PathPreferences.toolsOpenLastLibrary() and lastlib.endswith('.fctl'): + if PathPreferences.toolsOpenLastLibrary(): library.open(lastlib) else: library.open() diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index ac9febbd0e..cabedf4739 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -3,6 +3,7 @@ # *************************************************************************** # * * # * Copyright (c) 2019 sliptonic * +# * Copyright (c) 2020 Schildkroet * # * * # * This program is free software; you can redistribute it and/or modify * # * it under the terms of the GNU Lesser General Public License (LGPL) * @@ -32,11 +33,13 @@ import PathScripts.PathToolBitGui as PathToolBitGui import PathScripts.PathToolBitEdit as PathToolBitEdit import PathScripts.PathToolControllerGui as PathToolControllerGui import PathScripts.PathUtilsGui as PathUtilsGui +from PySide import QtCore, QtGui import PySide import json import os import traceback import uuid as UUID +import glob #PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) #PathLog.trackModule(PathLog.thisModule()) @@ -141,8 +144,11 @@ class ToolBitLibrary(object): self.form.toolTable.hide() self.setupUI() self.title = self.form.windowTitle() + self.LibFiles = [] if path: self.libraryLoad(path) + + self.form.addToolController.setEnabled(False) def _toolAdd(self, nr, tool, path): toolNr = PySide.QtGui.QStandardItem() @@ -210,6 +216,12 @@ class ToolBitLibrary(object): selectedRows = set([index.row() for index in self.toolTableView.selectedIndexes()]) for row in sorted(list(selectedRows), key = lambda r: -r): self.model.removeRows(row, 1) + + def libraryDelete(self): + PathLog.track() + if len(self.path) > 0: + os.remove(self.path) + self.libraryOpen(False) def toolEnumerate(self): PathLog.track() @@ -225,10 +237,14 @@ class ToolBitLibrary(object): addTCAllText = translate("PathToolLibraryManager", "Add ALL as Tool Controllers in the Job") if sel: - self.form.addToolController.setText(addTCSelectedText) + self.form.addToolController.setEnabled(True) else: - self.form.addToolController.setText(addTCAllText) + self.form.addToolController.setEnabled(False) + def tableSelected(self, index): + ''' loads the tools for the selected tool table ''' + name = self.form.TableList.itemWidget(self.form.TableList.itemFromIndex(index)).getTableName() + self.libraryLoad(PathPreferences.lastPathToolLibrary() + '/' + name) def open(self, path=None, dialog=False): '''open(path=None, dialog=False) ... load library stored in path and bring up ui. @@ -249,29 +265,50 @@ class ToolBitLibrary(object): else: self.form.librarySave.setEnabled(False) - def libraryOpen(self): + def libraryOpen(self, filedialog=True): 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 filedialog: + path = PySide.QtGui.QFileDialog.getExistingDirectory(self.form, 'Tool Library Path', PathPreferences.lastPathToolLibrary(), 1) + if len(path) > 0: + PathPreferences.setLastPathToolLibrary(path) + else: + return + else: + path = PathPreferences.lastPathToolLibrary() - if not PathPreferences.toolsOpenLastLibrary(): - PathPreferences.setLastPathToolLibrary(os.path.dirname(filename[0])) - #path = os.path.dirname(path) + self.form.TableList.clear() + self.LibFiles.clear() - self.libraryLoad(path) + # Find all tool tables in directory + for file in glob.glob(path + '/*.fctl'): + self.LibFiles.append(file) + + self.LibFiles.sort() + + for table in self.LibFiles: + listWidgetItem = QtGui.QListWidgetItem() + listItem = ToolTableListWidgetItem() + listItem.setTableName(os.path.basename(table)) + listItem.setIcon(QtGui.QPixmap(':/icons/Path-ToolTable.svg')) + #listItem.toolMoved.connect(self.reloadReset) + listWidgetItem.setSizeHint(QtCore.QSize(0,40)) + self.form.TableList.addItem(listWidgetItem) + self.form.TableList.setItemWidget(listWidgetItem, listItem) + + if len(self.LibFiles) > 0: + self.libraryLoad(self.LibFiles[0]) + self.form.TableList.setCurrentRow(0) def libraryLoad(self, path): self.toolTableView.setUpdatesEnabled(False) self.model.clear() self.model.setHorizontalHeaderLabels(self.columnNames()) + if path: - print(f"Path: {path}") + #print(f"Path: {path}") with open(path) as fp: library = json.load(fp) + for toolBit in library['tools']: nr = toolBit['nr'] bit = PathToolBit.findBit(toolBit['path']) @@ -281,7 +318,9 @@ class ToolBitLibrary(object): self._toolAdd(nr, tool, bit) else: PathLog.error("Could not find tool #{}: {}".format(nr, library['tools'][nr])) + self.toolTableView.resizeColumnsToContents() + self.toolTableView.setUpdatesEnabled(True) self.form.setWindowTitle("{} - {}".format(self.title, os.path.basename(path) if path else '')) @@ -290,6 +329,14 @@ class ToolBitLibrary(object): def libraryNew(self): self.libraryLoad(None) + self.librarySaveAs() + + def renameLibrary(self): + name = self.form.TableList.itemWidget(self.form.TableList.currentItem()).getTableName() + newName, ok = QtGui.QInputDialog.getText(None, translate("TooltableEditor","Rename Tooltable"),translate("TooltableEditor","Enter Name:"),QtGui.QLineEdit.Normal,name) + if ok and newName: + os.rename(PathPreferences.lastPathToolLibrary() + '/' + name, PathPreferences.lastPathToolLibrary() + '/' + newName) + self.libraryOpen(False) #def createToolBit(self): # tool = PathToolBit.ToolBitFactory().Create() @@ -393,8 +440,7 @@ class ToolBitLibrary(object): self.path = path self.librarySave() self.updateToolbar() - - + self.libraryOpen(False) def libraryCancel(self): self.form.close() @@ -425,6 +471,10 @@ class ToolBitLibrary(object): self.form.toolEnumerate.clicked.connect(self.toolEnumerate) # self.form.createToolBit.clicked.connect(self.createToolBit) + self.form.ButtonAddToolTable.clicked.connect(self.libraryNew) + self.form.ButtonRemoveToolTable.clicked.connect(self.libraryDelete) + self.form.ButtonRenameToolTable.clicked.connect(self.renameLibrary) + #self.form.libraryNew.clicked.connect(self.libraryNew) self.form.libraryOpen.clicked.connect(self.libraryOpen) self.form.librarySave.clicked.connect(self.librarySave) @@ -433,6 +483,54 @@ class ToolBitLibrary(object): self.form.addToolController.clicked.connect(self.selectedOrAllToolControllers) + self.form.TableList.clicked.connect(self.tableSelected) + self.toolSelect([], []) self.updateToolbar() PathLog.track('-') + + +class ToolTableListWidgetItem(QtGui.QWidget): + + toolMoved = QtCore.Signal() + + def __init__(self): + super(ToolTableListWidgetItem, self).__init__() + + #self.tlm = TLM + self.setAcceptDrops(True) + + self.mainLayout = QtGui.QHBoxLayout() + self.iconQLabel = QtGui.QLabel() + self.tableNameLabel = QtGui.QLabel() + self.mainLayout.addWidget(self.iconQLabel, 0) + self.mainLayout.addWidget(self.tableNameLabel, 1) + self.setLayout(self.mainLayout) + + def setTableName (self, text): + self.tableNameLabel.setText(text) + + def getTableName(self): + return self.tableNameLabel.text() + + def setIcon (self, icon): + icon = icon.scaled(22, 22) + self.iconQLabel.setPixmap(icon) + + def dragEnterEvent(self, e): + #currentToolTable = self.tlm.getCurrentTableName() + thisToolTable = self.getTableName() + + #if not currentToolTable == thisToolTable: + # e.accept() + #else: + # e.ignore() + + def dropEvent(self, e): + selectedTools = e.source().selectedIndexes() + if selectedTools: + toolData = selectedTools[1].data() + + if toolData: + #self.tlm.moveToTable(int(toolData), self.getTableName()) + self.toolMoved.emit() From cb293618cf6e4c1fb1da26bc4230f23d588f3ede Mon Sep 17 00:00:00 2001 From: Patrick F Date: Sat, 11 Apr 2020 19:27:37 +0200 Subject: [PATCH 06/11] Improved error handling --- .../Resources/panels/ToolBitLibraryEdit.ui | 29 +++++++++++++++++-- .../Path/PathScripts/PathToolBitLibraryGui.py | 29 ++++++++++++------- 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui index e4a1ec9845..77d528cbd5 100644 --- a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui +++ b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui @@ -75,6 +75,9 @@ 32 + + <html><head/><body><p>Rename Tool Table</p></body></html> + @@ -92,6 +95,9 @@ 32 + + <html><head/><body><p>Add New Tool Table</p></body></html> + @@ -109,6 +115,9 @@ 32 + + <html><head/><body><p>Remove Tool Table from Disc</p></body></html> + @@ -161,6 +170,19 @@
+ + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -173,13 +195,16 @@ - + Qt::Horizontal + + QSizePolicy::Fixed + - 40 + 14 20 diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index cabedf4739..9a7e9c55d9 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -39,7 +39,7 @@ import json import os import traceback import uuid as UUID -import glob +from functools import partial #PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) #PathLog.trackModule(PathLog.thisModule()) @@ -149,6 +149,7 @@ class ToolBitLibrary(object): self.libraryLoad(path) self.form.addToolController.setEnabled(False) + self.form.ButtonRemoveToolTable.setEnabled(False) def _toolAdd(self, nr, tool, path): toolNr = PySide.QtGui.QStandardItem() @@ -233,8 +234,8 @@ class ToolBitLibrary(object): 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") + #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.setEnabled(True) @@ -245,16 +246,13 @@ class ToolBitLibrary(object): ''' loads the tools for the selected tool table ''' name = self.form.TableList.itemWidget(self.form.TableList.itemFromIndex(index)).getTableName() self.libraryLoad(PathPreferences.lastPathToolLibrary() + '/' + name) + self.form.ButtonRemoveToolTable.setEnabled(True) def open(self, path=None, dialog=False): '''open(path=None, dialog=False) ... load library stored in path and bring up ui. Returns 1 if user pressed OK, 0 otherwise.''' if path: - fullPath = PathToolBit.findLibrary(path) - if fullPath: - self.libraryLoad(fullPath) - else: - self.libraryOpen() + self.libraryOpen(False) elif dialog: self.libraryOpen() return self.form.exec_() @@ -266,7 +264,9 @@ class ToolBitLibrary(object): self.form.librarySave.setEnabled(False) def libraryOpen(self, filedialog=True): + import glob PathLog.track() + if filedialog: path = PySide.QtGui.QFileDialog.getExistingDirectory(self.form, 'Tool Library Path', PathPreferences.lastPathToolLibrary(), 1) if len(path) > 0: @@ -295,9 +295,19 @@ class ToolBitLibrary(object): self.form.TableList.addItem(listWidgetItem) self.form.TableList.setItemWidget(listWidgetItem, listItem) + self.path = [] + self.form.ButtonRemoveToolTable.setEnabled(False) + + self.toolTableView.setUpdatesEnabled(False) + self.model.clear() + self.model.setHorizontalHeaderLabels(self.columnNames()) + self.toolTableView.resizeColumnsToContents() + self.toolTableView.setUpdatesEnabled(True) + if len(self.LibFiles) > 0: self.libraryLoad(self.LibFiles[0]) self.form.TableList.setCurrentRow(0) + self.form.ButtonRemoveToolTable.setEnabled(True) def libraryLoad(self, path): self.toolTableView.setUpdatesEnabled(False) @@ -305,7 +315,6 @@ class ToolBitLibrary(object): self.model.setHorizontalHeaderLabels(self.columnNames()) if path: - #print(f"Path: {path}") with open(path) as fp: library = json.load(fp) @@ -476,7 +485,7 @@ class ToolBitLibrary(object): self.form.ButtonRenameToolTable.clicked.connect(self.renameLibrary) #self.form.libraryNew.clicked.connect(self.libraryNew) - self.form.libraryOpen.clicked.connect(self.libraryOpen) + self.form.libraryOpen.clicked.connect(partial(self.libraryOpen, True)) self.form.librarySave.clicked.connect(self.librarySave) self.form.librarySaveAs.clicked.connect(self.librarySaveAs) self.form.libraryCancel.clicked.connect(self.libraryCancel) From 322e637cc86977852688c46f69964689160b963c Mon Sep 17 00:00:00 2001 From: Patrick F Date: Sun, 12 Apr 2020 00:49:09 +0200 Subject: [PATCH 07/11] Added confirm dialog for table delete --- src/Mod/Path/PathScripts/PathToolBitLibraryGui.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index 9a7e9c55d9..e3a3dfcc64 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -150,6 +150,7 @@ class ToolBitLibrary(object): self.form.addToolController.setEnabled(False) self.form.ButtonRemoveToolTable.setEnabled(False) + self.form.ButtonRenameToolTable.setEnabled(False) def _toolAdd(self, nr, tool, path): toolNr = PySide.QtGui.QStandardItem() @@ -220,7 +221,8 @@ class ToolBitLibrary(object): def libraryDelete(self): PathLog.track() - if len(self.path) > 0: + reply = QtGui.QMessageBox.question(self.form, 'Warning', "Delete " + os.path.basename(self.path) + "?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel) + if reply == QtGui.QMessageBox.Yes and len(self.path) > 0: os.remove(self.path) self.libraryOpen(False) @@ -234,9 +236,6 @@ class ToolBitLibrary(object): 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.setEnabled(True) else: @@ -247,6 +246,7 @@ class ToolBitLibrary(object): name = self.form.TableList.itemWidget(self.form.TableList.itemFromIndex(index)).getTableName() self.libraryLoad(PathPreferences.lastPathToolLibrary() + '/' + name) self.form.ButtonRemoveToolTable.setEnabled(True) + self.form.ButtonRenameToolTable.setEnabled(True) def open(self, path=None, dialog=False): '''open(path=None, dialog=False) ... load library stored in path and bring up ui. @@ -297,6 +297,7 @@ class ToolBitLibrary(object): self.path = [] self.form.ButtonRemoveToolTable.setEnabled(False) + self.form.ButtonRenameToolTable.setEnabled(False) self.toolTableView.setUpdatesEnabled(False) self.model.clear() @@ -308,6 +309,7 @@ class ToolBitLibrary(object): self.libraryLoad(self.LibFiles[0]) self.form.TableList.setCurrentRow(0) self.form.ButtonRemoveToolTable.setEnabled(True) + self.form.ButtonRenameToolTable.setEnabled(True) def libraryLoad(self, path): self.toolTableView.setUpdatesEnabled(False) From 5df3bd337e3b568d7884e88e461d9d2feaa84ad1 Mon Sep 17 00:00:00 2001 From: Patrick Felixberger Date: Tue, 21 Apr 2020 23:01:17 +0200 Subject: [PATCH 08/11] Rearranged UI and improved library handling --- .../Resources/panels/ToolBitLibraryEdit.ui | 245 +++++++++--------- src/Mod/Path/PathScripts/PathPreferences.py | 10 + .../Path/PathScripts/PathToolBitLibraryCmd.py | 2 +- .../Path/PathScripts/PathToolBitLibraryGui.py | 45 ++-- 4 files changed, 170 insertions(+), 132 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui index 77d528cbd5..80bb90c3ca 100644 --- a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui +++ b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui @@ -63,7 +63,7 @@ - Tool Table + Tool Tables @@ -130,100 +130,145 @@ - + + + QFrame::Box + +
- - - true + + + 0 - - <html><head/><body><p>Table of Tool Bits of the library.</p></body></html> + + 0 - - true - - - QAbstractItemView::InternalMove - - - Qt::MoveAction - - - QAbstractItemView::SelectRows - - - true - - - false - - + + + + true + + + <html><head/><body><p>Table of Tool Bits of the library.</p></body></html> + + + QFrame::Box + + + QFrame::Sunken + + + 1 + + + 0 + + + true + + + QAbstractItemView::InternalMove + + + Qt::MoveAction + + + QAbstractItemView::SelectRows + + + true + + + false + + + + + + + + + Add Tool(s) to Job + + + + :/icons/edit_OK.svg:/icons/edit_OK.svg + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 140 + 20 + + + + + + + + <html><head/><body><p>Close the Tool Bit Library Editor</p></body></html> + + + Cancel + + + + :/icons/button_invalid.svg:/icons/button_invalid.svg + + + + + + + <html><head/><body><p>Save the current Library</p></body></html> + + + Save Table + + + + :/icons/document-save.svg:/icons/document-save.svg + + + + + + + <html><head/><body><p>Save the library to a new file</p></body></html> + + + Save Table As... + + + + :/icons/document-save-as.svg:/icons/document-save-as.svg + + + + + + - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Add Tool Controller(s) to Job - - - - :/icons/edit_OK.svg:/icons/edit_OK.svg - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 14 - 20 - - - - - - - - <html><head/><body><p>Close the Tool Bit Library Editor</p></body></html> - - - Cancel - - - - :/icons/button_invalid.svg:/icons/button_invalid.svg - - - + + @@ -235,38 +280,6 @@ - - - - <html><head/><body><p>Save the current Library</p></body></html> - - - Save Table - - - - :/icons/document-save.svg:/icons/document-save.svg - - - - - - - <html><head/><body><p>Save the library to a new file</p></body></html> - - - Save Table As... - - - - :/icons/document-save-as.svg:/icons/document-save-as.svg - - - - - - - @@ -286,7 +299,7 @@ <html><head/><body><p>Add another Tool Bit to this library.</p><p><br/></p></body></html> - Add Toolbit ... + Add Toolbit @@ -300,7 +313,7 @@ <html><head/><body><p>Delete selected Tool Bit(s) from the library.</p><p><br/></p></body></html> - Remove Selected + Remove diff --git a/src/Mod/Path/PathScripts/PathPreferences.py b/src/Mod/Path/PathScripts/PathPreferences.py index 87d8889c22..65eeefad59 100644 --- a/src/Mod/Path/PathScripts/PathPreferences.py +++ b/src/Mod/Path/PathScripts/PathPreferences.py @@ -44,6 +44,7 @@ PostProcessorOutputPolicy = "PostProcessorOutputPolicy" LastPathToolBit = "LastPathToolBit" LastPathToolLibrary = "LastPathToolLibrary" LastPathToolShape = "LastPathToolShape" +LastPathToolTable ="LastPathToolTable" UseLegacyTools = "UseLegacyTools" UseAbsoluteToolPaths = "UseAbsoluteToolPaths" @@ -209,6 +210,7 @@ def defaultOutputPolicy(): def defaultStockTemplate(): return preferences().GetString(DefaultStockTemplate, "") + def setDefaultStockTemplate(template): preferences().SetString(DefaultStockTemplate, template) @@ -223,16 +225,24 @@ def experimentalFeaturesEnabled(): def lastPathToolBit(): return preferences().GetString(LastPathToolBit, pathDefaultToolsPath('Bit')) + def setLastPathToolBit(path): return preferences().SetString(LastPathToolBit, path) def lastPathToolLibrary(): return preferences().GetString(LastPathToolLibrary, pathDefaultToolsPath('Library')) + def setLastPathToolLibrary(path): return preferences().SetString(LastPathToolLibrary, path) def lastPathToolShape(): return preferences().GetString(LastPathToolShape, pathDefaultToolsPath('Shape')) + def setLastPathToolShape(path): return preferences().SetString(LastPathToolShape, path) +def lastPathToolTable(): + return preferences().GetString(LastPathToolTable, "") + +def setLastPathToolTable(table): + return preferences().SetString(LastPathToolTable, table) diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py b/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py index 90f38fb896..e418192b60 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryCmd.py @@ -91,7 +91,7 @@ class CommandToolBitLibraryLoad: library = PathToolBitLibraryGui.ToolBitLibrary() - if 1 == library.open(dialog=True) and job: + if 1 == library.open() and job: for nr, tool in library.selectedOrAllTools(): tc = PathToolControllerGui.Create("TC: {}".format(tool.Label), tool, nr) job.Proxy.addToolController(tc) diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index e3a3dfcc64..c9e509a3a8 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -224,7 +224,8 @@ class ToolBitLibrary(object): reply = QtGui.QMessageBox.question(self.form, 'Warning', "Delete " + os.path.basename(self.path) + "?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel) if reply == QtGui.QMessageBox.Yes and len(self.path) > 0: os.remove(self.path) - self.libraryOpen(False) + PathPreferences.setLastPathToolTable("") + self.libraryOpen(filedialog=False) def toolEnumerate(self): PathLog.track() @@ -252,9 +253,11 @@ class ToolBitLibrary(object): '''open(path=None, dialog=False) ... load library stored in path and bring up ui. Returns 1 if user pressed OK, 0 otherwise.''' if path: - self.libraryOpen(False) + self.libraryOpen(path, filedialog=False) elif dialog: - self.libraryOpen() + self.libraryOpen(None, True) + else: + self.libraryOpen(None, False) return self.form.exec_() def updateToolbar(self): @@ -263,22 +266,23 @@ class ToolBitLibrary(object): else: self.form.librarySave.setEnabled(False) - def libraryOpen(self, filedialog=True): + def libraryOpen(self, path = None, filedialog=True): import glob PathLog.track() - if filedialog: + path = PathPreferences.lastPathToolLibrary() + + if filedialog or len(path) == 0: path = PySide.QtGui.QFileDialog.getExistingDirectory(self.form, 'Tool Library Path', PathPreferences.lastPathToolLibrary(), 1) + #p = PySide.QtGui.QFileDialog.getOpenFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl') if len(path) > 0: PathPreferences.setLastPathToolLibrary(path) else: return - else: - path = PathPreferences.lastPathToolLibrary() self.form.TableList.clear() self.LibFiles.clear() - + # Find all tool tables in directory for file in glob.glob(path + '/*.fctl'): self.LibFiles.append(file) @@ -304,10 +308,17 @@ class ToolBitLibrary(object): self.model.setHorizontalHeaderLabels(self.columnNames()) self.toolTableView.resizeColumnsToContents() self.toolTableView.setUpdatesEnabled(True) - + if len(self.LibFiles) > 0: - self.libraryLoad(self.LibFiles[0]) - self.form.TableList.setCurrentRow(0) + for idx in range(len(self.LibFiles)): + if PathPreferences.lastPathToolTable() == os.path.basename(self.LibFiles[idx]): + break + + if idx >= len(self.LibFiles): + idx = 0 + + self.libraryLoad(self.LibFiles[idx]) + self.form.TableList.setCurrentRow(idx) self.form.ButtonRemoveToolTable.setEnabled(True) self.form.ButtonRenameToolTable.setEnabled(True) @@ -318,6 +329,7 @@ class ToolBitLibrary(object): if path: with open(path) as fp: + PathPreferences.setLastPathToolTable(os.path.basename(path)) library = json.load(fp) for toolBit in library['tools']: @@ -333,6 +345,8 @@ class ToolBitLibrary(object): self.toolTableView.resizeColumnsToContents() self.toolTableView.setUpdatesEnabled(True) + + #PathPreferences.setLastPathToolLibrary(path) self.form.setWindowTitle("{} - {}".format(self.title, os.path.basename(path) if path else '')) self.path = path @@ -347,7 +361,7 @@ class ToolBitLibrary(object): newName, ok = QtGui.QInputDialog.getText(None, translate("TooltableEditor","Rename Tooltable"),translate("TooltableEditor","Enter Name:"),QtGui.QLineEdit.Normal,name) if ok and newName: os.rename(PathPreferences.lastPathToolLibrary() + '/' + name, PathPreferences.lastPathToolLibrary() + '/' + newName) - self.libraryOpen(False) + self.libraryOpen(filedialog=False) #def createToolBit(self): # tool = PathToolBit.ToolBitFactory().Create() @@ -437,7 +451,7 @@ class ToolBitLibrary(object): filename = PySide.QtGui.QFileDialog.getSaveFileName(self.form, \ translate("TooltableEditor", "Save toolbit library", None), \ - None, "{};;{}".format(TooltableTypeJSON, \ + PathPreferences.lastPathToolLibrary(), "{};;{}".format(TooltableTypeJSON, \ TooltableTypeLinuxCNC)) # filename = PySide.QtGui.QFileDialog.getSaveFileName(self.form, \ # 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl') @@ -451,7 +465,8 @@ class ToolBitLibrary(object): self.path = path self.librarySave() self.updateToolbar() - self.libraryOpen(False) + PathPreferences.setLastPathToolTable(os.path.basename(path)) + self.libraryOpen(None, False) def libraryCancel(self): self.form.close() @@ -487,7 +502,7 @@ class ToolBitLibrary(object): self.form.ButtonRenameToolTable.clicked.connect(self.renameLibrary) #self.form.libraryNew.clicked.connect(self.libraryNew) - self.form.libraryOpen.clicked.connect(partial(self.libraryOpen, True)) + self.form.libraryOpen.clicked.connect(partial(self.libraryOpen, filedialog=True)) self.form.librarySave.clicked.connect(self.librarySave) self.form.librarySaveAs.clicked.connect(self.librarySaveAs) self.form.libraryCancel.clicked.connect(self.libraryCancel) From e960d0af0cf16a4dcf3a93c05f6afec37296b81e Mon Sep 17 00:00:00 2001 From: Patrick Felixberger Date: Wed, 22 Apr 2020 23:41:10 +0200 Subject: [PATCH 09/11] Updated Toolbits UI --- .../Resources/panels/ToolBitLibraryEdit.ui | 32 ++++++++++++++++--- .../Path/PathScripts/PathToolBitLibraryGui.py | 4 ++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui index 80bb90c3ca..f9cdfec269 100644 --- a/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui +++ b/src/Mod/Path/Gui/Resources/panels/ToolBitLibraryEdit.ui @@ -63,7 +63,7 @@ - Tool Tables + Tool Libraries @@ -192,7 +192,7 @@ - Add Tool(s) to Job + Add Tool Controller(s) to Job @@ -269,10 +269,32 @@ + + + + + 0 + 0 + + + + + 420 + 0 + + + + true + + + + + <html><head/><body><p>Select the folder with the tool libraries to load.</p></body></html> + - Open Library + @@ -287,7 +309,7 @@ - 40 + 20 20 @@ -296,7 +318,7 @@ - <html><head/><body><p>Add another Tool Bit to this library.</p><p><br/></p></body></html> + <html><head/><body><p>Add existing Tool Bit to this library.</p><p><br/></p></body></html> Add Toolbit diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index c9e509a3a8..26e4b8eff1 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -273,7 +273,7 @@ class ToolBitLibrary(object): path = PathPreferences.lastPathToolLibrary() if filedialog or len(path) == 0: - path = PySide.QtGui.QFileDialog.getExistingDirectory(self.form, 'Tool Library Path', PathPreferences.lastPathToolLibrary(), 1) + path = PySide.QtGui.QFileDialog.getExistingDirectory(self.form, 'Tool Library Path', PathPreferences.lastPathToolLibrary()) #p = PySide.QtGui.QFileDialog.getOpenFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl') if len(path) > 0: PathPreferences.setLastPathToolLibrary(path) @@ -282,6 +282,8 @@ class ToolBitLibrary(object): self.form.TableList.clear() self.LibFiles.clear() + self.form.lineLibPath.clear() + self.form.lineLibPath.insert(path) # Find all tool tables in directory for file in glob.glob(path + '/*.fctl'): From 9335078fc1e63c3898513a3306f01225050067d5 Mon Sep 17 00:00:00 2001 From: Patrick F Date: Sat, 25 Apr 2020 22:45:43 +0200 Subject: [PATCH 10/11] Added some comments --- .../Path/PathScripts/PathToolBitLibraryGui.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py index 26e4b8eff1..455183cf04 100644 --- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py +++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py @@ -270,16 +270,17 @@ class ToolBitLibrary(object): import glob PathLog.track() + # Load default search path path = PathPreferences.lastPathToolLibrary() if filedialog or len(path) == 0: path = PySide.QtGui.QFileDialog.getExistingDirectory(self.form, 'Tool Library Path', PathPreferences.lastPathToolLibrary()) - #p = PySide.QtGui.QFileDialog.getOpenFileName(self.form, 'Tool Library', PathPreferences.lastPathToolLibrary(), '*.fctl') if len(path) > 0: PathPreferences.setLastPathToolLibrary(path) else: return + # Clear view self.form.TableList.clear() self.LibFiles.clear() self.form.lineLibPath.clear() @@ -291,6 +292,7 @@ class ToolBitLibrary(object): self.LibFiles.sort() + # Add all tables to list for table in self.LibFiles: listWidgetItem = QtGui.QListWidgetItem() listItem = ToolTableListWidgetItem() @@ -311,14 +313,16 @@ class ToolBitLibrary(object): self.toolTableView.resizeColumnsToContents() self.toolTableView.setUpdatesEnabled(True) + # Search last selected table if len(self.LibFiles) > 0: for idx in range(len(self.LibFiles)): if PathPreferences.lastPathToolTable() == os.path.basename(self.LibFiles[idx]): break - + # Not found, select first entry if idx >= len(self.LibFiles): idx = 0 + # Load selected table self.libraryLoad(self.LibFiles[idx]) self.form.TableList.setCurrentRow(idx) self.form.ButtonRemoveToolTable.setEnabled(True) @@ -347,8 +351,6 @@ class ToolBitLibrary(object): self.toolTableView.resizeColumnsToContents() self.toolTableView.setUpdatesEnabled(True) - - #PathPreferences.setLastPathToolLibrary(path) self.form.setWindowTitle("{} - {}".format(self.title, os.path.basename(path) if path else '')) self.path = path @@ -519,7 +521,6 @@ class ToolBitLibrary(object): class ToolTableListWidgetItem(QtGui.QWidget): - toolMoved = QtCore.Signal() def __init__(self): @@ -556,9 +557,10 @@ class ToolTableListWidgetItem(QtGui.QWidget): def dropEvent(self, e): selectedTools = e.source().selectedIndexes() - if selectedTools: - toolData = selectedTools[1].data() + print("Drop: {}, {}".format(selectedTools, selectedTools[1].data())) + #if selectedTools: + #toolData = selectedTools[1].data() - if toolData: + #if toolData: #self.tlm.moveToTable(int(toolData), self.getTableName()) - self.toolMoved.emit() + #self.toolMoved.emit() From d44beb2eb464408336684cbb342b699442fb4773 Mon Sep 17 00:00:00 2001 From: Patrick Felixberger Date: Tue, 28 Apr 2020 16:11:28 +0200 Subject: [PATCH 11/11] Removed some printf --- src/Mod/Path/PathScripts/PathToolBit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathToolBit.py b/src/Mod/Path/PathScripts/PathToolBit.py index 82612f8608..1286349fd4 100644 --- a/src/Mod/Path/PathScripts/PathToolBit.py +++ b/src/Mod/Path/PathScripts/PathToolBit.py @@ -332,7 +332,7 @@ class ToolBit(object): attrs['parameter'] = params params = {} for name in self.propertyNamesAttribute(obj): - print(f"shapeattr {name}") + #print(f"shapeattr {name}") if name == "UserAttributes": for key, value in obj.UserAttributes.items(): params[key] = value @@ -372,7 +372,7 @@ class ToolBitFactory(object): proto = AttributePrototype() uservals = {} for pname in params: - print(f"pname: {pname}") + #print(f"pname: {pname}") try: prop = proto.getProperty(pname) val = prop.valueFromString(params[pname])