Added save and save as menu to ToolBit
This commit is contained in:
@@ -113,7 +113,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", "Path_ToolBitCreate", "Separator"] + toolcmdlist +["Separator"] + twodopcmdlist + engravecmdlist +["Separator"] +threedopcmdlist +["Separator"])
|
||||
self.appendMenu([QtCore.QT_TRANSLATE_NOOP("Path", "&Path")], projcmdlist +["Path_ExportTemplate", "Separator"] + PathToolBitCmd.CommandList + ["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(
|
||||
@@ -156,7 +156,7 @@ class PathWorkbench (Workbench):
|
||||
if "Job" in selectedName:
|
||||
self.appendContextMenu("", ["Path_ExportTemplate"])
|
||||
menuAppended = True
|
||||
if isinstance (obj.Proxy, PathScripts.PathOp.ObjectOp):
|
||||
if isinstance(obj.Proxy, PathScripts.PathOp.ObjectOp):
|
||||
self.appendContextMenu("", ["Path_OperationCopy", "Path_OpActiveToggle"])
|
||||
menuAppended = True
|
||||
if obj.isDerivedFrom("Path::Feature"):
|
||||
@@ -167,6 +167,9 @@ class PathWorkbench (Workbench):
|
||||
for cmd in self.dressupcmds:
|
||||
self.appendContextMenu("", [cmd])
|
||||
menuAppended = True
|
||||
if isinstance(obj.Proxy, PathScripts.PathToolBit.ToolBit):
|
||||
self.appendContextMenu("", ["Path_ToolBitSave", "Path_ToolBitSaveAs"])
|
||||
menuAppended = True
|
||||
if menuAppended:
|
||||
self.appendContextMenu("", "Separator")
|
||||
|
||||
|
||||
@@ -23,6 +23,10 @@
|
||||
# ***************************************************************************
|
||||
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
import PathScripts
|
||||
import os
|
||||
|
||||
from PySide import QtCore
|
||||
|
||||
class CommandToolBitCreate:
|
||||
@@ -35,8 +39,8 @@ class CommandToolBitCreate:
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap': 'Path-ToolBit',
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_Tool", "Create Tool"),
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_Job", "Creates a new ToolBit object")}
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("PathToolBit", "Create Tool"),
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathToolBit", "Creates a new ToolBit object")}
|
||||
|
||||
def IsActive(self):
|
||||
return FreeCAD.ActiveDocument is not None
|
||||
@@ -46,8 +50,64 @@ class CommandToolBitCreate:
|
||||
obj = PathToolBitGui.Create()
|
||||
obj.ViewObject.Proxy.setCreate(obj.ViewObject)
|
||||
|
||||
class CommandToolBitSave:
|
||||
'''
|
||||
Command used to save an existing Tool to a file.
|
||||
'''
|
||||
|
||||
def __init__(self, saveAs):
|
||||
self.saveAs = saveAs
|
||||
|
||||
def GetResources(self):
|
||||
if self.saveAs:
|
||||
menuTxt = QtCore.QT_TRANSLATE_NOOP("PathToolBit", "Save Tool as...")
|
||||
else:
|
||||
menuTxt = QtCore.QT_TRANSLATE_NOOP("PathToolBit", "Save Tool")
|
||||
return {'Pixmap': 'Path-ToolBit',
|
||||
'MenuText': menuTxt,
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathToolBit", "Save an existing ToolBit object to a file")}
|
||||
|
||||
def selectedTool(self):
|
||||
sel = FreeCADGui.Selection.getSelectionEx()
|
||||
if 1 == len(sel) and isinstance(sel[0].Object.Proxy, PathScripts.PathToolBit.ToolBit):
|
||||
return sel[0].Object
|
||||
return None
|
||||
|
||||
def IsActive(self):
|
||||
tool = self.selectedTool()
|
||||
if tool:
|
||||
if tool.File:
|
||||
return True
|
||||
return self.saveAs
|
||||
return False
|
||||
|
||||
def Activated(self):
|
||||
from PySide import QtGui
|
||||
tool = self.selectedTool()
|
||||
if tool:
|
||||
path = None
|
||||
if not tool.File or self.saveAs:
|
||||
if tool.File:
|
||||
fname = tool.File
|
||||
else:
|
||||
fname = os.path.join(PathScripts.PathPreferences.lastPathToolBit(), tool.Label + '.fctb')
|
||||
foo = QtGui.QFileDialog.getSaveFileName(QtGui.QApplication.activeWindow(), "Tool", fname, "*.fctb")
|
||||
if foo:
|
||||
path = foo[0]
|
||||
else:
|
||||
path = tool.File
|
||||
|
||||
if path:
|
||||
if not path.endswith('.fctb'):
|
||||
path += '.fctb'
|
||||
tool.Proxy.saveToFile(tool, path)
|
||||
PathScripts.PathPreferences.setLastPathToolBit(os.path.dirname(path))
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui
|
||||
FreeCADGui.addCommand('Path_ToolBitCreate', CommandToolBitCreate())
|
||||
FreeCADGui.addCommand('Path_ToolBitSave', CommandToolBitSave(False))
|
||||
FreeCADGui.addCommand('Path_ToolBitSaveAs', CommandToolBitSave(True))
|
||||
|
||||
CommandList = ['Path_ToolBitCreate', 'Path_ToolBitSave', 'Path_ToolBitSaveAs']
|
||||
|
||||
FreeCAD.Console.PrintLog("Loading PathToolBitCmd... done\n")
|
||||
|
||||
Reference in New Issue
Block a user