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()