Skip to content

Commit

Permalink
Fix deburr CW/CCW calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
sliptonic committed Oct 12, 2020
1 parent ed61873 commit ffd7693
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 28 deletions.
43 changes: 24 additions & 19 deletions src/Mod/Path/PathScripts/PathDeburr.py
Expand Up @@ -30,7 +30,7 @@
import PathScripts.PathOpTools as PathOpTools
import math

from PySide import QtCore, QtGui
from PySide import QtCore

# lazily loaded modules
from lazy_loader.lazy_loader import LazyLoader
Expand All @@ -54,20 +54,28 @@ def toolDepthAndOffset(width, extraDepth, tool):
'''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')
if not hasattr(tool, 'Diameter'):
raise ValueError('Deburr requires tool with diameter\n')

angle = float(tool.CuttingEdgeAngle)
if 0 == angle:
if not hasattr(tool, 'CuttingEdgeAngle'):
angle = 180
FreeCAD.Console.PrintMessage('The selected tool has No CuttingEdgeAngle property. Assuming Endmill\n')
else:
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')
else:
toolOffset = float(tool.FlatRadius)

if angle == 0:
angle = 180
tan = math.tan(math.radians(angle / 2))

toolDepth = 0 if 0 == tan else width / tan
depth = toolDepth + extraDepth
toolOffset = float(tool.FlatRadius)
extraOffset = float(tool.Diameter) / 2 - width if 180 == angle else extraDepth / tan
extraOffset = float(tool.Diameter) / 2 - width if angle == 180 else extraDepth / tan
offset = toolOffset + extraOffset

return (depth, offset)
Expand Down Expand Up @@ -108,8 +116,9 @@ def opExecute(self, obj):
(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
raise ValueError(msg)
# QtGui.QMessageBox.information(None, "Tool Error", msg)
# return

PathLog.track(obj.Label, depth, offset)

Expand All @@ -133,22 +142,18 @@ def opExecute(self, obj):

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)
wire = PathOpTools.offsetWire(w, base.Shape, offset, True) #, obj.Side)
if wire:
wires.append(wire)

# Save Outside or Inside
obj.Side = side[0]
# # Save Outside or Inside
# obj.Side = side[0]

# Set direction of op
forward = True
if obj.Direction == 'CCW':
forward = False
forward = (obj.Direction == 'CCW')

zValues = []
z = 0
Expand Down
3 changes: 1 addition & 2 deletions src/Mod/Path/PathScripts/PathDeburrGui.py
Expand Up @@ -62,7 +62,7 @@ def addBaseGeometry(self, selection):
for sub in sel.SubObjects:
if isinstance(sub, Part.Face):
if sub.normalAt(0, 0) != FreeCAD.Vector(0, 0, 1):
PathLog.info(translate("Path", "Ignoring non-vertical Face"))
PathLog.info(translate("Path", "Ignoring non-horizontal Face"))
return

self.super().addBaseGeometry(selection)
Expand Down Expand Up @@ -131,7 +131,6 @@ def registerSignalHandlers(self, obj):

def taskPanelBaseGeometryPage(self, obj, features):
'''taskPanelBaseGeometryPage(obj, features) ... return page for adding base geometries.'''
print(features)
return TaskPanelBaseGeometryPage(obj, features)


Expand Down
9 changes: 7 additions & 2 deletions src/Mod/Path/PathScripts/PathEngraveBase.py
Expand Up @@ -77,16 +77,20 @@ def buildpathocc(self, obj, wires, zValues, relZ=False, forward=True, start_idx=
last = None

for z in zValues:
PathLog.debug(z)
if last:
self.appendCommand(Path.Command('G1', {'X': last.x, 'Y': last.y, 'Z': last.z}), z, relZ, self.vertFeed)

first = True
if start_idx > len(edges)-1:
start_idx = len(edges)-1

edges = edges[start_idx:] + edges[:start_idx]
for edge in edges:
PathLog.debug("points: {} -> {}".format(edge.Vertexes[0].Point, edge.Vertexes[-1].Point))
PathLog.debug("valueat {} -> {}".format(edge.valueAt(edge.FirstParameter), edge.valueAt(edge.LastParameter)))
if first and (not last or not wire.isClosed()):
PathLog.debug('processing first edge entry')
# we set the first move to our first point
last = edge.Vertexes[0].Point

Expand All @@ -96,7 +100,8 @@ def buildpathocc(self, obj, wires, zValues, relZ=False, forward=True, start_idx=
self.appendCommand(Path.Command('G1', {'X': last.x, 'Y': last.y, 'Z': last.z}), z, relZ, self.vertFeed)
first = False

if PathGeom.pointsCoincide(last, edge.Vertexes[0].Point):
if PathGeom.pointsCoincide(last, edge.valueAt(edge.FirstParameter)):
#if PathGeom.pointsCoincide(last, edge.Vertexes[0].Point):
for cmd in PathGeom.cmdsForEdge(edge):
self.appendCommand(cmd, z, relZ, self.horizFeed)
last = edge.Vertexes[-1].Point
Expand Down
11 changes: 6 additions & 5 deletions src/Mod/Path/PathScripts/PathOpTools.py
Expand Up @@ -136,6 +136,7 @@ def orientWire(w, forward=True):
If forward = True (the default) the wire is oriented clockwise, looking down the negative Z axis.
If forward = False the wire is oriented counter clockwise.
If forward = None the orientation is determined by the order in which the edges appear in the wire.'''
PathLog.debug('orienting forward: {}'.format(forward))
wire = Part.Wire(_orientEdges(w.Edges))
if forward is not None:
if forward != _isWireClockwise(wire):
Expand All @@ -144,7 +145,7 @@ def orientWire(w, forward=True):
PathLog.track('orientWire - ok')
return wire

def offsetWire(wire, base, offset, forward, Side = None):
def offsetWire(wire, base, offset, forward):#, Side = None):
'''offsetWire(wire, base, offset, forward) ... offsets the wire away from base and orients the wire accordingly.
The function tries to avoid most of the pitfalls of Part.makeOffset2D which is possible because all offsetting
happens in the XY plane.
Expand Down Expand Up @@ -198,12 +199,12 @@ def offsetWire(wire, base, offset, forward, Side = None):
if wire.isClosed():
if not base.isInside(owire.Edges[0].Vertexes[0].Point, offset/2, True):
PathLog.track('closed - outside')
if Side:
Side[0] = "Outside"
# if Side:
# Side[0] = "Outside"
return orientWire(owire, forward)
PathLog.track('closed - inside')
if Side:
Side[0] = "Inside"
# if Side:
# Side[0] = "Inside"
try:
owire = wire.makeOffset2D(-offset)
except Exception: # pylint: disable=broad-except
Expand Down

0 comments on commit ffd7693

Please sign in to comment.