make deburr check for tool attributes fixes #4327

This commit is contained in:
sliptonic
2020-10-07 21:28:17 -05:00
parent d76124b61e
commit b5f37f06aa

View File

@@ -30,7 +30,7 @@ import PathScripts.PathOp as PathOp
import PathScripts.PathOpTools as PathOpTools
import math
from PySide import QtCore
from PySide import QtCore, QtGui
# lazily loaded modules
from lazy_loader.lazy_loader import LazyLoader
@@ -42,7 +42,7 @@ __url__ = "http://www.freecadweb.org"
__doc__ = "Deburr operation."
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
#PathLog.trackModule(PathLog.thisModule())
# PathLog.trackModule(PathLog.thisModule())
# Qt translation handling
@@ -51,7 +51,14 @@ def translate(context, text, disambig=None):
def toolDepthAndOffset(width, extraDepth, tool):
'''toolDepthAndOffset(width, extraDepth, tool) ... return tuple for given parameters.'''
'''toolDepthAndOffset(width, extraDepth, tool) ... return tuple for given\n
parameters.'''
if not (hasattr(tool, 'CuttingEdgeAngle')
and hasattr(tool, 'FlatRadius')
and hasattr(tool, 'Diameter')):
raise ValueError('Deburr requires tool with flatradius, diameter, and CuttingEdgeAngle\n')
angle = float(tool.CuttingEdgeAngle)
if 0 == angle:
angle = 180
@@ -62,7 +69,7 @@ def toolDepthAndOffset(width, extraDepth, tool):
toolOffset = float(tool.FlatRadius)
extraOffset = float(tool.Diameter) / 2 - width if 180 == angle else extraDepth / tan
offset = toolOffset + extraOffset
return (depth, offset)
@@ -70,32 +77,44 @@ class ObjectDeburr(PathEngraveBase.ObjectOp):
'''Proxy class for Deburr operation.'''
def opFeatures(self, obj):
return PathOp.FeatureTool | PathOp.FeatureHeights | PathOp.FeatureStepDown | PathOp.FeatureBaseEdges | PathOp.FeatureBaseFaces | PathOp.FeatureCoolant
return PathOp.FeatureTool | PathOp.FeatureHeights | PathOp.FeatureStepDown | PathOp.FeatureBaseEdges | PathOp.FeatureBaseFaces | PathOp.FeatureCoolant
def initOperation(self, obj):
PathLog.track(obj.Label)
obj.addProperty('App::PropertyDistance', 'Width', 'Deburr', QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'The desired width of the chamfer'))
obj.addProperty('App::PropertyDistance', 'ExtraDepth', 'Deburr', QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'The additional depth of the tool path'))
obj.addProperty('App::PropertyEnumeration', 'Join', 'Deburr', QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'How to join chamfer segments'))
obj.addProperty('App::PropertyDistance', 'Width', 'Deburr',
QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'The desired width of the chamfer'))
obj.addProperty('App::PropertyDistance', 'ExtraDepth', 'Deburr',
QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'The additional depth of the tool path'))
obj.addProperty('App::PropertyEnumeration', 'Join', 'Deburr',
QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'How to join chamfer segments'))
obj.Join = ['Round', 'Miter']
obj.setEditorMode('Join', 2) # hide for now
obj.addProperty('App::PropertyEnumeration', 'Direction', 'Deburr', QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'Direction of Operation'))
obj.addProperty('App::PropertyEnumeration', 'Direction', 'Deburr',
QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'Direction of Operation'))
obj.Direction = ['CW', 'CCW']
obj.addProperty('App::PropertyEnumeration', 'Side', 'Deburr', QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'Side of Operation'))
obj.addProperty('App::PropertyEnumeration', 'Side', 'Deburr',
QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'Side of Operation'))
obj.Side = ['Outside', 'Inside']
obj.setEditorMode('Side', 2) # Hide property, it's calculated by op
obj.addProperty('App::PropertyInteger', 'EntryPoint', 'Deburr', QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'Select the segment, there the operations starts'))
obj.setEditorMode('Side', 2) # Hide property, it's calculated by op
obj.addProperty('App::PropertyInteger', 'EntryPoint', 'Deburr',
QtCore.QT_TRANSLATE_NOOP('PathDeburr', 'Select the segment, there the operations starts'))
def opOnDocumentRestored(self, obj):
obj.setEditorMode('Join', 2) # hide for now
def opExecute(self, obj):
PathLog.track(obj.Label)
(depth, offset) = toolDepthAndOffset(obj.Width.Value, obj.ExtraDepth.Value, self.tool)
try:
(depth, offset) = toolDepthAndOffset(obj.Width.Value, obj.ExtraDepth.Value, self.tool)
except ValueError as e:
msg = "{} \n No path will be generated".format(e)
QtGui.QMessageBox.information(None, "Tool Error", msg)
return
PathLog.track(obj.Label, depth, offset)
self.basewires = [] # pylint: disable=attribute-defined-outside-init
self.adjusted_basewires = [] # pylint: disable=attribute-defined-outside-init
self.basewires = [] # pylint: disable=attribute-defined-outside-init
self.adjusted_basewires = [] # pylint: disable=attribute-defined-outside-init
wires = []
for base, subs in obj.Base:
edges = []
@@ -108,29 +127,29 @@ class ObjectDeburr(PathEngraveBase.ObjectOp):
basewires.extend(sub.Wires)
else:
basewires.append(Part.Wire(sub.Edges))
self.edges = edges # pylint: disable=attribute-defined-outside-init
self.edges = edges # pylint: disable=attribute-defined-outside-init
for edgelist in Part.sortEdges(edges):
basewires.append(Part.Wire(edgelist))
self.basewires.extend(basewires)
# Set default value
side = ["Outside"]
for w in basewires:
self.adjusted_basewires.append(w)
wire = PathOpTools.offsetWire(w, base.Shape, offset, True, side)
if wire:
wires.append(wire)
# Save Outside or Inside
obj.Side = side[0]
# Set direction of op
forward = True
if obj.Direction == 'CCW':
forward = False
zValues = []
z = 0
if obj.StepDown.Value != 0:
@@ -139,13 +158,12 @@ class ObjectDeburr(PathEngraveBase.ObjectOp):
zValues.append(z)
zValues.append(depth)
PathLog.track(obj.Label, depth, zValues)
if obj.EntryPoint < 0:
obj.EntryPoint = 0;
self.wires = wires # pylint: disable=attribute-defined-outside-init
obj.EntryPoint = 0
self.wires = wires # pylint: disable=attribute-defined-outside-init
self.buildpathocc(obj, wires, zValues, True, forward, obj.EntryPoint)
def opRejectAddBase(self, obj, base, sub):
'''The chamfer op can only deal with features of the base model, all others are rejected.'''
@@ -160,7 +178,7 @@ class ObjectDeburr(PathEngraveBase.ObjectOp):
obj.StepDown = '0 mm'
obj.Direction = 'CW'
obj.Side = "Outside"
obj.EntryPoint = 0;
obj.EntryPoint = 0
def SetupProperties():