Added ToolBit library commands

This commit is contained in:
Markus Lampert
2019-10-28 21:05:22 -07:00
parent 3fdd505e3f
commit adc5aec98f
4 changed files with 122 additions and 8 deletions

View File

@@ -105,6 +105,8 @@ SET(PathScripts_SRCS
PathScripts/PathToolBitCmd.py
PathScripts/PathToolBitEdit.py
PathScripts/PathToolBitGui.py
PathScripts/PathToolBitLibraryCmd.py
PathScripts/PathToolBitLibraryGui.py
PathScripts/PathToolController.py
PathScripts/PathToolControllerGui.py
PathScripts/PathToolEdit.py
@@ -150,6 +152,7 @@ SET(Tools_Bit_SRCS
)
SET(Tools_Library_SRCS
Tools/Library/endmills.fctl
)
SET(Tools_Template_SRCS

View File

@@ -72,6 +72,7 @@ class PathWorkbench (Workbench):
from PathScripts import PathGuiInit
from PathScripts import PathJobCmd
from PathScripts import PathToolBitCmd
from PathScripts import PathToolBitLibraryCmd
import PathCommands
PathGuiInit.Startup()
@@ -113,7 +114,7 @@ class PathWorkbench (Workbench):
if extracmdlist:
self.appendToolbar(QtCore.QT_TRANSLATE_NOOP("Path", "Helpful Tools"), extracmdlist)
self.appendMenu([QtCore.QT_TRANSLATE_NOOP("Path", "&Path")], projcmdlist +["Path_ExportTemplate", "Separator"] + PathToolBitCmd.CommandList + ["Path_ToolController", "Separator"] + toolcmdlist +["Separator"] + twodopcmdlist + engravecmdlist +["Separator"] +threedopcmdlist +["Separator"])
self.appendMenu([QtCore.QT_TRANSLATE_NOOP("Path", "&Path")], projcmdlist +["Path_ExportTemplate", "Separator"] + PathToolBitCmd.CommandList + ["Separator"] + PathToolBitLibraryCmd.CommandList + ["Path_ToolController", "Separator"] + toolcmdlist +["Separator"] + twodopcmdlist + engravecmdlist +["Separator"] +threedopcmdlist +["Separator"])
self.appendMenu([QtCore.QT_TRANSLATE_NOOP("Path", "&Path"), QtCore.QT_TRANSLATE_NOOP(
"Path", "Path Dressup")], dressupcmdlist)
self.appendMenu([QtCore.QT_TRANSLATE_NOOP("Path", "&Path"), QtCore.QT_TRANSLATE_NOOP(
@@ -154,7 +155,7 @@ class PathWorkbench (Workbench):
if "Remote" in selectedName:
self.appendContextMenu("", ["Refresh_Path"])
if "Job" in selectedName:
self.appendContextMenu("", ["Path_ExportTemplate"])
self.appendContextMenu("", ["Path_ExportTemplate", "Path_ToolBitLibraryLoad", "Path_ToolController"])
menuAppended = True
if isinstance(obj.Proxy, PathScripts.PathOp.ObjectOp):
self.appendContextMenu("", ["Path_OperationCopy", "Path_OpActiveToggle"])

View File

@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2019 sliptonic <shopinthewoods@gmail.com> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
import FreeCAD
import FreeCADGui
import PySide.QtCore as QtCore
class CommandToolBitLibraryOpen:
'''
Command to ToolBitLibrary editor.
'''
def __init__(self):
pass
def GetResources(self):
return {'Pixmap': 'Path-ToolTable',
'MenuText': QtCore.QT_TRANSLATE_NOOP("PathToolBitLibrary", "Open ToolBit Library editor"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathToolBitLibrary", "Open an editor to manage ToolBit libraries")}
def IsActive(self):
return True
def Activated(self):
import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui
library = PathToolBitLibraryGui.ToolBitLibrary()
library.open()
class CommandToolBitLibraryLoad:
'''
Command used to load an entire ToolBitLibrary (or part of it) from a file into a job.
'''
def __init__(self):
pass
def GetResources(self):
return {'Pixmap': 'Path-ToolTable',
'MenuText': QtCore.QT_TRANSLATE_NOOP("PathToolBitLibrary", "Load ToolBit Library"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathToolBitLibrary", "Load an entire ToolBit library or part of it into a job")}
def selectedJob(self):
if FreeCAD.ActiveDocument:
sel = FreeCADGui.Selection.getSelectionEx()
if sel and sel[0].Object.Name[:3] == 'Job':
return sel[0].Object
jobs = [o for o in FreeCAD.ActiveDocument.Objects if o.Name[:3] == 'Job']
if 1 == len(jobs):
return jobs[0]
return None
def IsActive(self):
return not self.selectedJob() is None
def Activated(self):
import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui
import PathScripts.PathToolControllerGui as PathToolControllerGui
job = self.selectedJob()
library = PathToolBitLibraryGui.ToolBitLibrary()
if 1 == library.open(dialog=True):
for nr, tool in library.selectedOrAllTools():
tc = PathToolControllerGui.Create("TC: {}".format(tool.Label), tool, nr)
job.Proxy.addToolController(tc)
FreeCAD.ActiveDocument.recompute()
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Path_ToolBitLibraryOpen', CommandToolBitLibraryOpen())
FreeCADGui.addCommand('Path_ToolBitLibraryLoad', CommandToolBitLibraryLoad())
CommandList = ['Path_ToolBitLibraryOpen', 'Path_ToolBitLibraryLoad']
FreeCAD.Console.PrintLog("Loading PathToolBitLibraryCmd... done\n")

View File

@@ -40,7 +40,8 @@ PathLog.trackModule(PathLog.thisModule())
_UuidRole = PySide.QtCore.Qt.UserRole + 1
_PathRole = PySide.QtCore.Qt.UserRole + 2
class TableView(PySide.QtGui.QTableView):
class _TableView(PySide.QtGui.QTableView):
'''Subclass of QTableView to support rearrange and copying of ToolBits'''
def __init__(self, parent):
PySide.QtGui.QTableView.__init__(self, parent)
@@ -78,6 +79,8 @@ class TableView(PySide.QtGui.QTableView):
model.setData(model.index(dstRow, col), srcItem.data(PySide.QtCore.Qt.EditRole), PySide.QtCore.Qt.EditRole)
if col == 0:
model.setData(model.index(dstRow, col), srcItem.data(_PathRole), _PathRole)
# Even a clone of a tool gets its own uuid so it can be identified when
# rearranging the order or inserting/deleting rows
model.setData(model.index(dstRow, col), uuid.uuid4(), _UuidRole)
else:
model.item(dstRow, col).setEditable(False)
@@ -120,15 +123,13 @@ class TableView(PySide.QtGui.QTableView):
for uuid in srcUuids:
model.removeRow(self._rowWithUuid(uuid))
#class ToolTableModel(PySide.QtGui.QStandardItemModel):
class ToolBitLibrary(object):
'''ToolBitLibrary is the controller for displaying/selecting/creating/editing a collection of ToolBits.'''
def __init__(self, path=None):
self.path = path
self.form = FreeCADGui.PySideUic.loadUi(':/panels/ToolBitLibraryEdit.ui')
self.toolTableView = TableView(self.form.toolTableGroup)
self.toolTableView = _TableView(self.form.toolTableGroup)
self.form.toolTableGroup.layout().replaceWidget(self.form.toolTable, self.toolTableView)
self.form.toolTable.hide()
self.setupUI()
@@ -173,6 +174,18 @@ class ToolBitLibrary(object):
PathLog.error('something happened')
PathLog.error(traceback.print_exc())
def selectedOrAllTools(self):
selectedRows = set([index.row() for index in self.toolTableView.selectedIndexes()])
if not selectedRows:
selectedRows = list(range(self.model.rowCount()))
tools = []
for row in selectedRows:
item = self.model.item(row, 0)
toolNr = int(item.data(PySide.QtCore.Qt.EditRole))
toolPath = item.data(_PathRole)
tools.append((toolNr, PathToolBitGui.CreateFrom(toolPath)))
return tools
def toolDelete(self):
PathLog.track()
selectedRows = set([index.row() for index in self.toolTableView.selectedIndexes()])
@@ -187,13 +200,17 @@ class ToolBitLibrary(object):
def toolSelect(self, selected, deselected):
self.form.toolDelete.setEnabled(len(self.toolTableView.selectedIndexes()) > 0)
def open(self, path=None):
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()
elif dialog:
self.libraryOpen()
return self.form.exec_()
def updateToolbar(self):