Refactored Commmand and ViewProvider to be data driven and moved imlementation into PathAreaOpGui.
This commit is contained in:
committed by
Yorik van Havre
parent
0617d360d0
commit
89da621869
@@ -61,7 +61,7 @@ class ObjectOp(object):
|
||||
PathLog.track()
|
||||
|
||||
obj.addProperty("App::PropertyBool", "Active", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "Make False, to prevent operation from generating code"))
|
||||
obj.addProperty("App::PropertyString", "Comment", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "An optional comment for this Contour"))
|
||||
obj.addProperty("App::PropertyString", "Comment", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "An optional comment for this Operation"))
|
||||
obj.addProperty("App::PropertyString", "UserLabel", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "User Assigned Label"))
|
||||
|
||||
if FeatureBaseGeometry & self.opFeatures(obj):
|
||||
|
||||
@@ -26,9 +26,9 @@ import FreeCAD
|
||||
import FreeCADGui
|
||||
import Path
|
||||
import PathScripts.PathAreaOp as PathAreaOp
|
||||
import PathScripts.PathContour as PathContour
|
||||
import PathScripts.PathLog as PathLog
|
||||
import PathScripts.PathSelection as PathSelection
|
||||
import importlib
|
||||
|
||||
from PathScripts import PathUtils
|
||||
from PySide import QtCore, QtGui
|
||||
@@ -49,10 +49,14 @@ def translate(context, text, disambig=None):
|
||||
|
||||
class ViewProvider(object):
|
||||
|
||||
def __init__(self, vobj):
|
||||
def __init__(self, vobj, resources):
|
||||
PathLog.track()
|
||||
vobj.Proxy = self
|
||||
self.deleteOnReject = True
|
||||
self.OpIcon = ":/icons/%s.svg" % resources.pixmap
|
||||
self.OpName = resources.name
|
||||
self.OpPageModule = resources.opPageClass.__module__
|
||||
self.OpPageClass = resources.opPageClass.__name__
|
||||
|
||||
def attach(self, vobj):
|
||||
PathLog.track()
|
||||
@@ -74,16 +78,31 @@ class ViewProvider(object):
|
||||
self.deleteOnReject = False
|
||||
return True
|
||||
|
||||
def getIcon(self):
|
||||
return ":/icons/Path-Contour.svg"
|
||||
|
||||
def __getstate__(self):
|
||||
PathLog.track()
|
||||
return None
|
||||
state = {}
|
||||
state['OpName'] = self.OpName
|
||||
state['OpIcon'] = self.OpIcon
|
||||
state['OpPageModule'] = self.OpPageModule
|
||||
state['OpPageClass'] = self.OpPageClass
|
||||
return state
|
||||
|
||||
def __setstate__(self, state):
|
||||
PathLog.track()
|
||||
return None
|
||||
self.OpName = state['OpName']
|
||||
self.OpIcon = state['OpIcon']
|
||||
self.OpPageModule = state['OpPageModule']
|
||||
self.OpPageClass = state['OpPageClass']
|
||||
|
||||
def getIcon(self):
|
||||
return self.OpIcon
|
||||
|
||||
def getTaskPanelOpPage(self, obj):
|
||||
mod = importlib.import_module(self.OpPageModule)
|
||||
cls = getattr(mod, self.OpPageClass)
|
||||
return cls(obj)
|
||||
|
||||
def getSelectionFactory(self):
|
||||
return PathSelection.select(self.OpName)
|
||||
|
||||
class TaskPanelPage(object):
|
||||
|
||||
@@ -462,6 +481,57 @@ class _CommandSetStartPoint:
|
||||
def Activated(self):
|
||||
FreeCADGui.Snapper.getPoint(callback=self.setpoint)
|
||||
|
||||
def Create(res):
|
||||
FreeCAD.ActiveDocument.openTransaction("Create %s" % res.name)
|
||||
obj = res.objFactory(res.name)
|
||||
vobj = ViewProvider(obj.ViewObject, res)
|
||||
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
obj.ViewObject.startEditing()
|
||||
return obj
|
||||
|
||||
class CommandPathOp:
|
||||
def __init__(self, resources):
|
||||
self.res = resources
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap': self.res.pixmap,
|
||||
'MenuText': self.res.menuText,
|
||||
'Accel': self.res.accelKey,
|
||||
'ToolTip': self.res.toolTip}
|
||||
|
||||
def IsActive(self):
|
||||
if FreeCAD.ActiveDocument is not None:
|
||||
for o in FreeCAD.ActiveDocument.Objects:
|
||||
if o.Name[:3] == "Job":
|
||||
return True
|
||||
return False
|
||||
|
||||
def Activated(self):
|
||||
return Create(self.res)
|
||||
|
||||
class CommandResources:
|
||||
def __init__(self, name, objFactory, opPageClass, pixmap, menuText, accelKey, toolTip):
|
||||
self.name = name
|
||||
self.objFactory = objFactory
|
||||
self.opPageClass = opPageClass
|
||||
self.pixmap = pixmap
|
||||
self.menuText = menuText
|
||||
self.accelKey = accelKey
|
||||
self.toolTip = toolTip
|
||||
|
||||
def SetupOperation(name,
|
||||
objFactory,
|
||||
opPageClass,
|
||||
pixmap,
|
||||
menuText,
|
||||
accelKey,
|
||||
toolTip):
|
||||
res = CommandResources(name, objFactory, opPageClass, pixmap, menuText, accelKey, toolTip)
|
||||
|
||||
FreeCADGui.addCommand("Path_%s" % name, CommandPathOp(res))
|
||||
|
||||
|
||||
FreeCADGui.addCommand('Set_StartPoint', _CommandSetStartPoint())
|
||||
|
||||
FreeCAD.Console.PrintLog("Loading PathAreaOpGui... done\n")
|
||||
|
||||
@@ -80,9 +80,11 @@ class ObjectContour(PathAreaOp.ObjectOp):
|
||||
|
||||
def opOnChanged(self, obj, prop):
|
||||
PathLog.track('prop: {} state: {}'.format(prop, obj.State))
|
||||
obj.setEditorMode('MiterLimit', 2)
|
||||
if obj.JoinType == 'Miter':
|
||||
obj.setEditorMode('MiterLimit', 0)
|
||||
if prop == 'JoinType':
|
||||
if obj.JoinType == 'Miter':
|
||||
obj.setEditorMode('MiterLimit', 0)
|
||||
else:
|
||||
obj.setEditorMode('MiterLimit', 2)
|
||||
|
||||
def opShapeForDepths(self, obj):
|
||||
job = PathUtils.findParentJob(obj)
|
||||
|
||||
@@ -70,44 +70,12 @@ class TaskPanelOpPage(PathAreaOpGui.TaskPanelPage):
|
||||
signals.append(self.form.extraOffset.editingFinished)
|
||||
return signals
|
||||
|
||||
class ViewProviderContour(PathAreaOpGui.ViewProvider):
|
||||
|
||||
def getTaskPanelOpPage(self, obj):
|
||||
return TaskPanelOpPage(obj)
|
||||
|
||||
def getIcon(self):
|
||||
return ":/icons/Path-Contour.svg"
|
||||
|
||||
def getSelectionFactory(self):
|
||||
return PathSelection.contourselect
|
||||
|
||||
def Create(name):
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("Path", "Create a Contour"))
|
||||
obj = PathContour.Create(name)
|
||||
vobj = ViewProviderContour(obj.ViewObject)
|
||||
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
obj.ViewObject.startEditing()
|
||||
return obj
|
||||
|
||||
class CommandPathContour:
|
||||
def GetResources(self):
|
||||
return {'Pixmap': 'Path-Contour',
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("PathContour", "Contour"),
|
||||
'Accel': "P, C",
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathContour", "Creates a Contour Path for the Base Object ")}
|
||||
|
||||
def IsActive(self):
|
||||
if FreeCAD.ActiveDocument is not None:
|
||||
for o in FreeCAD.ActiveDocument.Objects:
|
||||
if o.Name[:3] == "Job":
|
||||
return True
|
||||
return False
|
||||
|
||||
def Activated(self):
|
||||
return Create("Contour")
|
||||
|
||||
# register the FreeCAD command
|
||||
FreeCADGui.addCommand('Path_Contour', CommandPathContour())
|
||||
PathAreaOpGui.SetupOperation('Contour',
|
||||
PathContour.Create,
|
||||
TaskPanelOpPage,
|
||||
'Path-Contour',
|
||||
QtCore.QT_TRANSLATE_NOOP("PathContour", "Contour"),
|
||||
"P, C",
|
||||
QtCore.QT_TRANSLATE_NOOP("PathContour", "Creates a Contour Path for the Base Object "))
|
||||
|
||||
FreeCAD.Console.PrintLog("Loading PathContourGui... done\n")
|
||||
|
||||
@@ -76,43 +76,12 @@ class TaskPanelOpPage(PathAreaOpGui.TaskPanelPage):
|
||||
signals.append(self.form.toolController.currentIndexChanged)
|
||||
return signals
|
||||
|
||||
class ViewProviderPocket(PathAreaOpGui.ViewProvider):
|
||||
PathAreaOpGui.SetupOperation('Pocket',
|
||||
PathPocket.Create,
|
||||
TaskPanelOpPage,
|
||||
'Path-Pocket',
|
||||
QtCore.QT_TRANSLATE_NOOP("PathPocket", "Pocket"),
|
||||
"P, O",
|
||||
QtCore.QT_TRANSLATE_NOOP("PathPocket", "Creates a Path Pocket object from a face or faces"))
|
||||
|
||||
def getTaskPanelOpPage(self, obj):
|
||||
return TaskPanelOpPage(obj)
|
||||
|
||||
def getIcon(self):
|
||||
return ":/icons/Path-Pocket.svg"
|
||||
|
||||
def getSelectionFactory(self):
|
||||
return PathSelection.pocketselect
|
||||
|
||||
def Create(name):
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("PathPocket", "Create Pocket"))
|
||||
obj = PathPocket.Create(name)
|
||||
vobj = ViewProviderPocket(obj.ViewObject)
|
||||
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
obj.ViewObject.startEditing()
|
||||
return obj
|
||||
|
||||
class CommandPathPocket:
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap': 'Path-Pocket',
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("PathPocket", "Pocket"),
|
||||
'Accel': "P, O",
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathPocket", "Creates a Path Pocket object from a face or faces")}
|
||||
|
||||
def IsActive(self):
|
||||
if FreeCAD.ActiveDocument is not None:
|
||||
for o in FreeCAD.ActiveDocument.Objects:
|
||||
if o.Name[:3] == "Job":
|
||||
return True
|
||||
return False
|
||||
|
||||
def Activated(self):
|
||||
return Create("Pocket")
|
||||
|
||||
FreeCADGui.addCommand('Path_Pocket', CommandPathPocket())
|
||||
FreeCAD.Console.PrintLog("Loading PathPocketGui... done\n")
|
||||
|
||||
@@ -78,43 +78,12 @@ class TaskPanelOpPage(PathAreaOpGui.TaskPanelPage):
|
||||
signals.append(self.form.processCircles.clicked)
|
||||
return signals
|
||||
|
||||
class ViewProviderProfile(PathAreaOpGui.ViewProvider):
|
||||
PathAreaOpGui.SetupOperation('Profile',
|
||||
PathProfile.Create,
|
||||
TaskPanelOpPage,
|
||||
'Path-Profile',
|
||||
QtCore.QT_TRANSLATE_NOOP("PathProfile", "Face Profile"),
|
||||
"P, F",
|
||||
QtCore.QT_TRANSLATE_NOOP("PathProfile", "Profile based on face or faces"))
|
||||
|
||||
def getTaskPanelOpPage(self, obj):
|
||||
return TaskPanelOpPage(obj)
|
||||
|
||||
def getIcon(self):
|
||||
return ":/icons/Path-Profile-Face.svg"
|
||||
|
||||
def getSelectionFactory(self):
|
||||
return PathSelection.profileselect
|
||||
|
||||
|
||||
def Create(name):
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("Path", "Create a Profile"))
|
||||
obj = PathProfile.Create(name)
|
||||
vobj = ViewProviderProfile(obj.ViewObject)
|
||||
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
obj.ViewObject.startEditing()
|
||||
return obj
|
||||
|
||||
class CommandPathProfile:
|
||||
def GetResources(self):
|
||||
return {'Pixmap': 'Path-Profile-Face',
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("PathProfile", "Face Profile"),
|
||||
'Accel': "P, F",
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathProfile", "Profile based on face or faces")}
|
||||
|
||||
def IsActive(self):
|
||||
if FreeCAD.ActiveDocument is not None:
|
||||
for o in FreeCAD.ActiveDocument.Objects:
|
||||
if o.Name[:3] == "Job":
|
||||
return True
|
||||
return False
|
||||
|
||||
def Activated(self):
|
||||
return Create('Profile')
|
||||
|
||||
FreeCADGui.addCommand('Path_Profile', CommandPathProfile())
|
||||
FreeCAD.Console.PrintLog("Loading PathProfileGui... done\n")
|
||||
|
||||
@@ -160,6 +160,14 @@ def surfaceselect():
|
||||
FreeCADGui.Selection.addSelectionGate(MESHGate())
|
||||
FreeCAD.Console.PrintWarning("Surfacing Select Mode\n")
|
||||
|
||||
def select(op):
|
||||
opsel = {}
|
||||
opsel['Profile'] = profileselect
|
||||
opsel['Pocket'] = pocketselect
|
||||
opsel['Contour'] = contourselect
|
||||
opsel['Surface'] = surfaceselect
|
||||
return opsel[op]
|
||||
|
||||
def clear():
|
||||
FreeCADGui.Selection.removeSelectionGate()
|
||||
FreeCAD.Console.PrintWarning("Free Select\n")
|
||||
|
||||
Reference in New Issue
Block a user