added attribute to Toolbit for spindlepower
setting this to false will suppress M3 commands. User can configure a toolbit to never have the spindle turn on this is to prevent accidental powering of the spindle with unpowered tools like dragknife and probe
This commit is contained in:
@@ -42,8 +42,8 @@ __author__ = "sliptonic (Brad Collette)"
|
||||
__url__ = "https://www.freecadweb.org"
|
||||
__doc__ = "Class to deal with and represent a tool bit."
|
||||
|
||||
# PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
|
||||
# PathLog.trackModule()
|
||||
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
|
||||
PathLog.trackModule()
|
||||
|
||||
|
||||
def translate(context, text, disambig=None):
|
||||
@@ -363,6 +363,7 @@ class ToolBit(object):
|
||||
|
||||
|
||||
def Declaration(path):
|
||||
print(path)
|
||||
with open(path, 'r') as fp:
|
||||
return json.load(fp)
|
||||
|
||||
@@ -388,12 +389,13 @@ class AttributePrototype(PathSetupSheetOpPrototype.OpPrototype):
|
||||
self.addProperty('App::PropertyMap', 'UserAttributes',
|
||||
PropertyGroupAttribute, translate('PathToolBit',
|
||||
'User Defined Values'))
|
||||
|
||||
self.addProperty('App::PropertyBool', 'SpindlePower',
|
||||
PropertyGroupAttribute, translate('PathToolBit',
|
||||
'Whether Spindle Power should be allowed'))
|
||||
|
||||
class ToolBitFactory(object):
|
||||
|
||||
def CreateFromAttrs(self, attrs, name='ToolBit'):
|
||||
# pylint: disable=protected-access
|
||||
obj = Factory.Create(name, attrs['shape'])
|
||||
obj.Label = attrs['name']
|
||||
params = attrs['parameter']
|
||||
|
||||
@@ -169,14 +169,16 @@ class ToolBitEditor(object):
|
||||
|
||||
# get the attributes
|
||||
for i, name in enumerate(self.props):
|
||||
print('in accept: {}'.format(name))
|
||||
prop = self.proto.getProperty(name)
|
||||
enabled = self.model.item(i, 0).checkState() == QtCore.Qt.Checked
|
||||
if enabled and not prop.getValue() is None:
|
||||
prop.setupProperty(self.tool, name,
|
||||
PathToolBit.PropertyGroupAttribute,
|
||||
prop.getValue())
|
||||
elif hasattr(self.tool, name):
|
||||
self.tool.removeProperty(name)
|
||||
if self.model.item(i, 0) is not None:
|
||||
enabled = self.model.item(i, 0).checkState() == QtCore.Qt.Checked
|
||||
if enabled and not prop.getValue() is None:
|
||||
prop.setupProperty(self.tool, name,
|
||||
PathToolBit.PropertyGroupAttribute,
|
||||
prop.getValue())
|
||||
elif hasattr(self.tool, name):
|
||||
self.tool.removeProperty(name)
|
||||
|
||||
def reject(self):
|
||||
PathLog.track()
|
||||
|
||||
@@ -30,16 +30,17 @@ import PathScripts.PathToolBit as PathToolBit
|
||||
|
||||
from PySide import QtCore
|
||||
|
||||
#PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
|
||||
#PathLog.trackModule(PathLog.thisModule())
|
||||
# PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
|
||||
# PathLog.trackModule(PathLog.thisModule())
|
||||
|
||||
|
||||
# Qt translation handling
|
||||
def translate(context, text, disambig=None):
|
||||
return QtCore.QCoreApplication.translate(context, text, disambig)
|
||||
|
||||
|
||||
class ToolControllerTemplate:
|
||||
'''Attribute and sub element strings for template export/import.'''
|
||||
# pylint: disable=no-init
|
||||
|
||||
Expressions = 'xengine'
|
||||
ExprExpr = 'expr'
|
||||
@@ -56,21 +57,36 @@ class ToolControllerTemplate:
|
||||
VertFeed = 'vfeed'
|
||||
VertRapid = 'vrapid'
|
||||
|
||||
|
||||
class ToolController:
|
||||
|
||||
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.addProperty("App::PropertyIntegerConstraint", "ToolNumber",
|
||||
"Tool", QtCore.QT_TRANSLATE_NOOP("PathToolController",
|
||||
"The active tool"))
|
||||
obj.ToolNumber = (0, 0, 10000, 1)
|
||||
self.ensureUseLegacyTool(obj, cTool)
|
||||
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.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("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.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):
|
||||
@@ -85,7 +101,10 @@ class ToolController:
|
||||
obj.Document.removeObject(obj.Tool.Name)
|
||||
|
||||
def setFromTemplate(self, obj, template):
|
||||
'''setFromTemplate(obj, xmlItem) ... extract properties from xmlItem and assign to receiver.'''
|
||||
'''
|
||||
setFromTemplate(obj, xmlItem) ... extract properties from xmlItem
|
||||
and assign to receiver.
|
||||
'''
|
||||
PathLog.track(obj.Name, template)
|
||||
version = 0
|
||||
if template.get(ToolControllerTemplate.Version):
|
||||
@@ -158,10 +177,22 @@ class ToolController:
|
||||
commands += "(" + obj.Label + ")"+'\n'
|
||||
commands += 'M6 T'+str(obj.ToolNumber)+'\n'
|
||||
|
||||
if obj.SpindleDir == 'Forward':
|
||||
commands += 'M3 S' + str(obj.SpindleSpeed) + '\n'
|
||||
else:
|
||||
commands += 'M4 S' + str(obj.SpindleSpeed) + '\n'
|
||||
|
||||
# If a toolbit is used, check to see if spindlepower is allowed.
|
||||
# This is to prevent accidentally spinning the spindle with an
|
||||
# unpowered tool like probe or dragknife
|
||||
|
||||
allowSpindlePower = True
|
||||
if (not isinstance(obj.Tool, Path.Tool) and
|
||||
hasattr(obj.Tool, "SpindlePower")):
|
||||
allowSpindlePower = obj.Tool.SpindlePower
|
||||
|
||||
if allowSpindlePower:
|
||||
PathLog.debug('selected tool preventing spindle power')
|
||||
if obj.SpindleDir == 'Forward':
|
||||
commands += 'M3 S' + str(obj.SpindleSpeed) + '\n'
|
||||
else:
|
||||
commands += 'M4 S' + str(obj.SpindleSpeed) + '\n'
|
||||
|
||||
if commands == "":
|
||||
commands += "(No commands processed)"
|
||||
@@ -195,7 +226,8 @@ class ToolController:
|
||||
else:
|
||||
obj.addProperty("App::PropertyLink", "Tool", "Base", QtCore.QT_TRANSLATE_NOOP("PathToolController", "The tool used by this controller"))
|
||||
|
||||
def Create(name = 'Default Tool', tool=None, toolNumber=1, assignViewProvider=True):
|
||||
|
||||
def Create(name='Default Tool', tool=None, toolNumber=1, assignViewProvider=True):
|
||||
legacyTool = PathPreferences.toolsReallyUseLegacyTools() if tool is None else isinstance(tool, Path.Tool)
|
||||
|
||||
PathLog.track(tool, toolNumber, legacyTool)
|
||||
@@ -224,6 +256,7 @@ def Create(name = 'Default Tool', tool=None, toolNumber=1, assignViewProvider=Tr
|
||||
obj.ToolNumber = toolNumber
|
||||
return obj
|
||||
|
||||
|
||||
def FromTemplate(template, assignViewProvider=True):
|
||||
# pylint: disable=unused-argument
|
||||
PathLog.track()
|
||||
@@ -234,6 +267,7 @@ def FromTemplate(template, assignViewProvider=True):
|
||||
|
||||
return obj
|
||||
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
# need ViewProvider class in this file to support loading of old files
|
||||
from PathScripts.PathToolControllerGui import ViewProvider
|
||||
|
||||
Reference in New Issue
Block a user