Added command to create a ToolBit
This commit is contained in:
53
src/Mod/Path/PathScripts/PathToolBitCmd.py
Normal file
53
src/Mod/Path/PathScripts/PathToolBitCmd.py
Normal file
@@ -0,0 +1,53 @@
|
||||
# -*- 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
|
||||
from PySide import QtCore
|
||||
|
||||
class CommandToolBitCreate:
|
||||
'''
|
||||
Command used to create a new Tool.
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
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")}
|
||||
|
||||
def IsActive(self):
|
||||
return FreeCAD.ActiveDocument is not None
|
||||
|
||||
def Activated(self):
|
||||
import PathScripts.PathToolBitGui as PathToolBitGui
|
||||
obj = PathToolBitGui.Create()
|
||||
obj.ViewObject.Proxy.setCreate(obj.ViewObject)
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui
|
||||
FreeCADGui.addCommand('Path_ToolBitCreate', CommandToolBitCreate())
|
||||
|
||||
FreeCAD.Console.PrintLog("Loading PathToolBitCmd... done\n")
|
||||
@@ -67,7 +67,7 @@ class ViewProvider(object):
|
||||
pixmap = QtGui.QPixmap()
|
||||
pixmap.loadFromData(png, "PNG")
|
||||
return QtGui.QIcon(pixmap)
|
||||
return ':/icons/Path-ToolChange.svg'
|
||||
return ':/icons/Path-ToolBit.svg'
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
@@ -80,13 +80,20 @@ class ViewProvider(object):
|
||||
# pylint: disable=unused-argument
|
||||
return 'Default'
|
||||
|
||||
def setEdit(self, vobj, mode=0):
|
||||
# pylint: disable=unused-argument
|
||||
def _openTaskPanel(self, vobj, deleteOnReject):
|
||||
PathLog.track()
|
||||
self.taskPanel = TaskPanel(vobj)
|
||||
self.taskPanel = TaskPanel(vobj, deleteOnReject)
|
||||
FreeCADGui.Control.closeDialog()
|
||||
FreeCADGui.Control.showDialog(self.taskPanel)
|
||||
self.taskPanel.setupUi()
|
||||
|
||||
def setCreate(self, vobj):
|
||||
PathLog.track()
|
||||
self._openTaskPanel(vobj, True)
|
||||
|
||||
def setEdit(self, vobj, mode=0):
|
||||
# pylint: disable=unused-argument
|
||||
self._openTaskPanel(vobj, False)
|
||||
return True
|
||||
|
||||
def unsetEdit(self, vobj, mode):
|
||||
@@ -106,18 +113,24 @@ class ViewProvider(object):
|
||||
class TaskPanel:
|
||||
'''TaskPanel for the SetupSheet - if it is being edited directly.'''
|
||||
|
||||
def __init__(self, vobj):
|
||||
def __init__(self, vobj, deleteOnReject):
|
||||
PathLog.track(vobj.Object.Label)
|
||||
self.vobj = vobj
|
||||
self.obj = vobj.Object
|
||||
self.editor = PathToolBitEdit.ToolBitEditor(self.obj)
|
||||
self.form = self.editor.form
|
||||
self.deleteOnReject = deleteOnReject
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("PathToolBit", "Edit ToolBit"))
|
||||
|
||||
def reject(self):
|
||||
self.editor.reject()
|
||||
FreeCAD.ActiveDocument.abortTransaction()
|
||||
self.editor.reject()
|
||||
FreeCADGui.Control.closeDialog()
|
||||
if self.deleteOnReject:
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("PathToolBit", "Uncreate ToolBit"))
|
||||
self.editor.reject()
|
||||
FreeCAD.ActiveDocument.removeObject(self.obj.Name)
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
def accept(self):
|
||||
|
||||
Reference in New Issue
Block a user