Print deburr tool info only once.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
import FreeCAD
|
||||
import PathScripts.PathEngraveBase as PathEngraveBase
|
||||
import PathScripts.PathGeom as PathGeom
|
||||
import PathScripts.PathLog as PathLog
|
||||
import PathScripts.PathOp as PathOp
|
||||
import PathScripts.PathOpTools as PathOpTools
|
||||
@@ -48,35 +49,44 @@ def translate(context, text, disambig=None):
|
||||
return QtCore.QCoreApplication.translate(context, text, disambig)
|
||||
|
||||
|
||||
def toolDepthAndOffset(width, extraDepth, tool):
|
||||
def toolDepthAndOffset(width, extraDepth, tool, printInfo):
|
||||
'''toolDepthAndOffset(width, extraDepth, tool) ... return tuple for given\n
|
||||
parameters.'''
|
||||
|
||||
if not hasattr(tool, 'Diameter'):
|
||||
raise ValueError('Deburr requires tool with diameter\n')
|
||||
|
||||
if not hasattr(tool, 'CuttingEdgeAngle'):
|
||||
angle = 180
|
||||
FreeCAD.Console.PrintMessage('The selected tool has No CuttingEdgeAngle property. Assuming Endmill\n')
|
||||
else:
|
||||
suppressInfo = False
|
||||
if hasattr(tool, 'CuttingEdgeAngle'):
|
||||
angle = float(tool.CuttingEdgeAngle)
|
||||
|
||||
if not hasattr(tool, 'FlatRadius'):
|
||||
toolOffset = float(tool.Diameter / 2)
|
||||
FreeCAD.Console.PrintMessage('The selected tool has no FlatRadius property. Using Diameter\n')
|
||||
if PathGeom.isRoughly(angle, 180) or PathGeom.isRoughly(angle, 0):
|
||||
angle = 180
|
||||
toolOffset = float(tool.Diameter) / 2
|
||||
else:
|
||||
if hasattr(tool, 'TipDiameter'):
|
||||
toolOffset = float(tool.TipDiameter) / 2
|
||||
elif hasattr(tool, 'FlatRadius'):
|
||||
toolOffset = float(tool.FlatRadius)
|
||||
else:
|
||||
toolOffset = 0.0
|
||||
if printInfo and not suppressInfo:
|
||||
FreeCAD.Console.PrintMessage(translate('PathDeburr', "The selected tool has no FlatRadius and no TipDiameter property. Assuming {}\n").format("Endmill" if angle == 180 else "V-Bit"))
|
||||
suppressInfo = True
|
||||
else:
|
||||
toolOffset = float(tool.FlatRadius)
|
||||
|
||||
if angle == 0:
|
||||
angle = 180
|
||||
toolOffset = float(tool.Diameter) / 2
|
||||
if printInfo:
|
||||
FreeCAD.Console.PrintMessage(translate('PathDeburr', 'The selected tool has no CuttingEdgeAngle property. Assuming Endmill\n'))
|
||||
suppressInfo = True
|
||||
|
||||
tan = math.tan(math.radians(angle / 2))
|
||||
|
||||
toolDepth = 0 if 0 == tan else width / tan
|
||||
toolDepth = 0 if PathGeom.isRoughly(tan, 0) else width / tan
|
||||
depth = toolDepth + extraDepth
|
||||
extraOffset = float(tool.Diameter) / 2 - width if angle == 180 else extraDepth / tan
|
||||
extraOffset = -width if angle == 180 else (extraDepth / tan)
|
||||
offset = toolOffset + extraOffset
|
||||
|
||||
return (depth, offset)
|
||||
return (depth, offset, suppressInfo)
|
||||
|
||||
|
||||
class ObjectDeburr(PathEngraveBase.ObjectOp):
|
||||
@@ -110,8 +120,11 @@ class ObjectDeburr(PathEngraveBase.ObjectOp):
|
||||
|
||||
def opExecute(self, obj):
|
||||
PathLog.track(obj.Label)
|
||||
if not hasattr(self, 'printInfo'):
|
||||
self.printInfo = True
|
||||
try:
|
||||
(depth, offset) = toolDepthAndOffset(obj.Width.Value, obj.ExtraDepth.Value, self.tool)
|
||||
(depth, offset, suppressInfo) = toolDepthAndOffset(obj.Width.Value, obj.ExtraDepth.Value, self.tool, self.printInfo)
|
||||
self.printInfo = not suppressInfo
|
||||
except ValueError as e:
|
||||
msg = "{} \n No path will be generated".format(e)
|
||||
raise ValueError(msg)
|
||||
|
||||
@@ -38,16 +38,18 @@ class TestPathDeburr(PathTestUtils.PathTestBase):
|
||||
tool.FlatRadius = 0
|
||||
tool.CuttingEdgeAngle = 180
|
||||
|
||||
(depth, offset) = PathDeburr.toolDepthAndOffset(1, 0.01, tool)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(1, 0.01, tool, True)
|
||||
self.assertRoughly(0.01, depth)
|
||||
self.assertRoughly(9, offset)
|
||||
self.assertFalse(info)
|
||||
|
||||
# legacy tools - no problem, same result
|
||||
tool.CuttingEdgeAngle = 0
|
||||
|
||||
(depth, offset) = PathDeburr.toolDepthAndOffset(1, 0.01, tool)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(1, 0.01, tool, True)
|
||||
self.assertRoughly(0.01, depth)
|
||||
self.assertRoughly(9, offset)
|
||||
self.assertFalse(info)
|
||||
|
||||
def test01(self):
|
||||
'''Verify chamfer depth and offset for a 90° v-bit.'''
|
||||
@@ -55,13 +57,15 @@ class TestPathDeburr(PathTestUtils.PathTestBase):
|
||||
tool.FlatRadius = 0
|
||||
tool.CuttingEdgeAngle = 90
|
||||
|
||||
(depth, offset) = PathDeburr.toolDepthAndOffset(1, 0, tool)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(1, 0, tool, True)
|
||||
self.assertRoughly(1, depth)
|
||||
self.assertRoughly(0, offset)
|
||||
self.assertFalse(info)
|
||||
|
||||
(depth, offset) = PathDeburr.toolDepthAndOffset(1, 0.2, tool)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(1, 0.2, tool, True)
|
||||
self.assertRoughly(1.2, depth)
|
||||
self.assertRoughly(0.2, offset)
|
||||
self.assertFalse(info)
|
||||
|
||||
def test02(self):
|
||||
'''Verify chamfer depth and offset for a 90° v-bit with non 0 flat radius.'''
|
||||
@@ -69,13 +73,15 @@ class TestPathDeburr(PathTestUtils.PathTestBase):
|
||||
tool.FlatRadius = 0.3
|
||||
tool.CuttingEdgeAngle = 90
|
||||
|
||||
(depth, offset) = PathDeburr.toolDepthAndOffset(1, 0, tool)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(1, 0, tool, True)
|
||||
self.assertRoughly(1, depth)
|
||||
self.assertRoughly(0.3, offset)
|
||||
self.assertFalse(info)
|
||||
|
||||
(depth, offset) = PathDeburr.toolDepthAndOffset(2, 0.2, tool)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(2, 0.2, tool, True)
|
||||
self.assertRoughly(2.2, depth)
|
||||
self.assertRoughly(0.5, offset)
|
||||
self.assertFalse(info)
|
||||
|
||||
def test03(self):
|
||||
'''Verify chamfer depth and offset for a 60° v-bit with non 0 flat radius.'''
|
||||
@@ -85,10 +91,55 @@ class TestPathDeburr(PathTestUtils.PathTestBase):
|
||||
|
||||
td = 1.73205
|
||||
|
||||
(depth, offset) = PathDeburr.toolDepthAndOffset(1, 0, tool)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(1, 0, tool, True)
|
||||
self.assertRoughly(td, depth)
|
||||
self.assertRoughly(10, offset)
|
||||
self.assertFalse(info)
|
||||
|
||||
(depth, offset) = PathDeburr.toolDepthAndOffset(3, 1, tool)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(3, 1, tool, True)
|
||||
self.assertRoughly(td * 3 + 1, depth)
|
||||
self.assertRoughly(10 + td, offset)
|
||||
self.assertFalse(info)
|
||||
|
||||
def test10(self):
|
||||
'''Verify missing cutting endge angle info prints only once.'''
|
||||
|
||||
class FakeEndmill(object):
|
||||
def __init__(self, dia):
|
||||
self.Diameter = dia
|
||||
|
||||
tool = FakeEndmill(10)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(1, 0.1, tool, True)
|
||||
self.assertRoughly(0.1, depth)
|
||||
self.assertRoughly(4, offset)
|
||||
self.assertTrue(info)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(1, 0.1, tool, not info)
|
||||
self.assertRoughly(0.1, depth)
|
||||
self.assertRoughly(4, offset)
|
||||
self.assertTrue(info)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(1, 0.1, tool, not info)
|
||||
self.assertRoughly(0.1, depth)
|
||||
self.assertRoughly(4, offset)
|
||||
self.assertTrue(info)
|
||||
|
||||
def test11(self):
|
||||
'''Verify missing tip diameter info prints only once.'''
|
||||
|
||||
class FakePointyBit(object):
|
||||
def __init__(self, dia, angle):
|
||||
self.Diameter = dia
|
||||
self.CuttingEdgeAngle = angle
|
||||
|
||||
tool = FakePointyBit(10, 90)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(1, 0.1, tool, True)
|
||||
self.assertRoughly(1.1, depth)
|
||||
self.assertRoughly(0.1, offset)
|
||||
self.assertTrue(info)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(1, 0.1, tool, not info)
|
||||
self.assertRoughly(1.1, depth)
|
||||
self.assertRoughly(0.1, offset)
|
||||
self.assertTrue(info)
|
||||
(depth, offset, info) = PathDeburr.toolDepthAndOffset(1, 0.1, tool, not info)
|
||||
self.assertRoughly(1.1, depth)
|
||||
self.assertRoughly(0.1, offset)
|
||||
self.assertTrue(info)
|
||||
|
||||
Reference in New Issue
Block a user