Add support for ToolBit to ToolController

This commit is contained in:
Markus Lampert
2019-10-17 20:15:38 -07:00
parent 54390967c6
commit f8887d5e12
2 changed files with 52 additions and 34 deletions

View File

@@ -61,21 +61,24 @@ class ToolControllerTemplate:
VertRapid = 'vrapid'
class ToolController:
def __init__(self, obj, tool=1):
PathLog.track('tool: {}'.format(tool))
obj.addProperty("App::PropertyIntegerConstraint", "ToolNumber", "Tool", QtCore.QT_TRANSLATE_NOOP("App::Property", "The active tool"))
def __init__(self, obj, cTool=False):
PathLog.track('tool: {}'.format(cTool))
obj.addProperty("App::PropertyIntegerConstraint", "ToolNumber", "Tool", QtCore.QT_TRANSLATE_NOOP("PathToolController", "The active tool"))
obj.ToolNumber = (0, 0, 10000, 1)
obj.addProperty("Path::PropertyTool", "Tool", "Base", QtCore.QT_TRANSLATE_NOOP("App::Property", "The tool used by this controller"))
if cTool:
obj.addProperty("Path::PropertyTool", "Tool", "Base", QtCore.QT_TRANSLATE_NOOP("PathToolController", "The tool used by this controller"))
else:
obj.addProperty("App::PropertyLink", "Tool", "Base", QtCore.QT_TRANSLATE_NOOP("PathToolController", "The tool used by this controller"))
obj.addProperty("App::PropertyFloat", "SpindleSpeed", "Tool", QtCore.QT_TRANSLATE_NOOP("App::Property", "The speed of the cutting spindle in RPM"))
obj.addProperty("App::PropertyEnumeration", "SpindleDir", "Tool", QtCore.QT_TRANSLATE_NOOP("App::Property", "Direction of spindle rotation"))
obj.addProperty("App::PropertyFloat", "SpindleSpeed", "Tool", QtCore.QT_TRANSLATE_NOOP("PathToolController", "The speed of the cutting spindle in RPM"))
obj.addProperty("App::PropertyEnumeration", "SpindleDir", "Tool", QtCore.QT_TRANSLATE_NOOP("PathToolController", "Direction of spindle rotation"))
obj.SpindleDir = ['Forward', 'Reverse']
obj.addProperty("App::PropertySpeed", "VertFeed", "Feed", QtCore.QT_TRANSLATE_NOOP("App::Property", "Feed rate for vertical moves in Z"))
obj.addProperty("App::PropertySpeed", "HorizFeed", "Feed", QtCore.QT_TRANSLATE_NOOP("App::Property", "Feed rate for horizontal moves"))
obj.addProperty("App::PropertySpeed", "VertRapid", "Rapid", QtCore.QT_TRANSLATE_NOOP("App::Property", "Rapid rate for vertical moves in Z"))
obj.addProperty("App::PropertySpeed", "HorizRapid", "Rapid", QtCore.QT_TRANSLATE_NOOP("App::Property", "Rapid rate for horizontal moves"))
obj.Proxy = self
obj.addProperty("App::PropertySpeed", "VertFeed", "Feed", QtCore.QT_TRANSLATE_NOOP("PathToolController", "Feed rate for vertical moves in Z"))
obj.addProperty("App::PropertySpeed", "HorizFeed", "Feed", QtCore.QT_TRANSLATE_NOOP("PathToolController", "Feed rate for horizontal moves"))
obj.addProperty("App::PropertySpeed", "VertRapid", "Rapid", QtCore.QT_TRANSLATE_NOOP("PathToolController", "Rapid rate for vertical moves in Z"))
obj.addProperty("App::PropertySpeed", "HorizRapid", "Rapid", QtCore.QT_TRANSLATE_NOOP("PathToolController", "Rapid rate for horizontal moves"))
obj.setEditorMode('Placement', 2)
def onDocumentRestored(self, obj):
@@ -157,15 +160,17 @@ class ToolController:
PathLog.track()
return obj.Tool
def usesLegacyTool(self, obj):
'''returns True if the tool being controlled is a legacy tool'''
return isinstance(obj.Tool, Path.Tool)
def Create(name = 'Default Tool', tool=None, toolNumber=1, assignViewProvider=True):
PathLog.track(tool, toolNumber)
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name)
obj.Label = name
obj.Proxy = ToolController(obj, tool is None or isinstance(tool, Path.Tool))
ToolController(obj)
if FreeCAD.GuiUp and assignViewProvider:
ViewProvider(obj.ViewObject)
@@ -176,6 +181,7 @@ def Create(name = 'Default Tool', tool=None, toolNumber=1, assignViewProvider=Tr
tool.CuttingEdgeHeight = 15.0
tool.ToolType = "EndMill"
tool.Material = "HighSpeedSteel"
obj.Tool = tool
obj.ToolNumber = toolNumber
return obj
@@ -184,12 +190,8 @@ def FromTemplate(template, assignViewProvider=True):
PathLog.track()
name = template.get(ToolControllerTemplate.Name, ToolControllerTemplate.Label)
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name)
tc = ToolController(obj)
if FreeCAD.GuiUp and assignViewProvider:
ViewProvider(obj.ViewObject)
tc.setFromTemplate(obj, template)
obj = Create(name, assignViewProvider=True)
obj.Proxy.setFromTemplate(obj, template)
return obj

View File

@@ -113,6 +113,12 @@ class ViewProvider:
action.triggered.connect(self.setEdit)
menu.addAction(action)
def claimChildren(self):
obj = self.vobj.Object
if not obj.Proxy.usesLegacyTool(obj):
return [obj.Tool]
return []
def Create(name = 'Default Tool', tool=None, toolNumber=1):
PathLog.track(tool, toolNumber)
@@ -153,7 +159,12 @@ class ToolControllerEditor(object):
self.vertRapid = PathGui.QuantitySpinBox(self.form.vertRapid, obj, 'VertRapid')
self.horizRapid = PathGui.QuantitySpinBox(self.form.horizRapid, obj, 'HorizRapid')
self.editor = PathToolEdit.ToolEditor(obj.Tool, self.form.toolEditor)
if obj.Proxy.usesLegacyTool(obj):
self.editor = PathToolEdit.ToolEditor(obj.Tool, self.form.toolEditor)
else:
self.editor = None
self.form.toolBox.widget(1).hide()
self.form.toolBox.removeItem(1)
def updateUi(self):
tc = self.obj
@@ -168,7 +179,8 @@ class ToolControllerEditor(object):
if index >= 0:
self.form.spindleDirection.setCurrentIndex(index)
self.editor.updateUI()
if self.editor:
self.editor.updateUI()
def updateToolController(self):
tc = self.obj
@@ -182,8 +194,9 @@ class ToolControllerEditor(object):
tc.SpindleSpeed = self.form.spindleSpeed.value()
tc.SpindleDir = self.form.spindleDirection.currentText()
self.editor.updateTool()
tc.Tool = self.editor.tool
if self.editor:
self.editor.updateTool()
tc.Tool = self.editor.tool
except Exception as e: # pylint: disable=broad-except
PathLog.error(translate("PathToolController", "Error updating TC: %s") % e)
@@ -196,7 +209,8 @@ class ToolControllerEditor(object):
self.form.blockSignals(False)
def setupUi(self):
self.editor.setupUI()
if self.editor:
self.editor.setupUI()
self.form.tcName.editingFinished.connect(self.refresh)
self.form.horizFeed.editingFinished.connect(self.refresh)
@@ -219,13 +233,13 @@ class TaskPanel:
FreeCADGui.ActiveDocument.resetEdit()
FreeCADGui.Control.closeDialog()
if self.toolrep is not None:
if self.toolrep:
FreeCAD.ActiveDocument.removeObject(self.toolrep.Name)
FreeCAD.ActiveDocument.recompute()
def reject(self):
FreeCADGui.Control.closeDialog()
if self.toolrep is not None:
if self.toolrep:
FreeCAD.ActiveDocument.removeObject(self.toolrep.Name)
FreeCAD.ActiveDocument.recompute()
@@ -236,11 +250,12 @@ class TaskPanel:
def setFields(self):
self.editor.updateUi()
tool = self.obj.Tool
radius = tool.Diameter / 2
length = tool.CuttingEdgeHeight
t = Part.makeCylinder(radius, length)
self.toolrep.Shape = t
if self.toolrep:
tool = self.obj.Tool
radius = tool.Diameter / 2
length = tool.CuttingEdgeHeight
t = Part.makeCylinder(radius, length)
self.toolrep.Shape = t
def edit(self, item, column):
# pylint: disable=unused-argument
@@ -253,9 +268,10 @@ class TaskPanel:
FreeCAD.ActiveDocument.recompute()
def setupUi(self):
t = Part.makeCylinder(1, 1)
self.toolrep = FreeCAD.ActiveDocument.addObject("Part::Feature", "tool")
self.toolrep.Shape = t
if self.editor.editor:
t = Part.makeCylinder(1, 1)
self.toolrep = FreeCAD.ActiveDocument.addObject("Part::Feature", "tool")
self.toolrep.Shape = t
self.setFields()
self.editor.setupUi()