fixes offset problems with OCC pocketing Bug #2604

This commit is contained in:
sliptonic 2016-07-02 16:57:44 -05:00 committed by Yorik van Havre
parent ee5bb83a38
commit 4d28fff8ee

View File

@ -60,7 +60,7 @@ class ObjectPocket:
obj.ToolNumber = (0, 0, 1000, 0) obj.ToolNumber = (0, 0, 1000, 0)
obj.setEditorMode('ToolNumber', 1) # make this read only obj.setEditorMode('ToolNumber', 1) # make this read only
obj.addProperty("App::PropertyString", "ToolDescription", "Tool", "The description of the tool ") obj.addProperty("App::PropertyString", "ToolDescription", "Tool", "The description of the tool ")
obj.setEditorMode('ToolDescription', 1) # make this read onlyt obj.setEditorMode('ToolDescription', 1) # make this read only
# Depth Properties # Depth Properties
obj.addProperty("App::PropertyDistance", "ClearanceHeight", "Depth", "The height needed to clear clamps and obstructions") obj.addProperty("App::PropertyDistance", "ClearanceHeight", "Depth", "The height needed to clear clamps and obstructions")
@ -78,7 +78,7 @@ class ObjectPocket:
obj.addProperty("App::PropertyEnumeration", "StartAt", "Pocket", "Start pocketing at center or boundary") obj.addProperty("App::PropertyEnumeration", "StartAt", "Pocket", "Start pocketing at center or boundary")
obj.StartAt = ['Center', 'Edge'] obj.StartAt = ['Center', 'Edge']
obj.addProperty("App::PropertyPercent", "StepOver", "Pocket", "Percent of cutter diameter to step over on each pass") obj.addProperty("App::PropertyPercent", "StepOver", "Pocket", "Percent of cutter diameter to step over on each pass")
#obj.StepOver = (0.0, 0.01, 100.0, 0.5) # obj.StepOver = (0.0, 0.01, 100.0, 0.5)
obj.addProperty("App::PropertyBool", "KeepToolDown", "Pocket", "Attempts to avoid unnecessary retractions.") obj.addProperty("App::PropertyBool", "KeepToolDown", "Pocket", "Attempts to avoid unnecessary retractions.")
obj.addProperty("App::PropertyBool", "ZigUnidirectional", "Pocket", "Lifts tool at the end of each pass to respect cut mode.") obj.addProperty("App::PropertyBool", "ZigUnidirectional", "Pocket", "Lifts tool at the end of each pass to respect cut mode.")
obj.addProperty("App::PropertyBool", "UseZigZag", "Pocket", "Use Zig Zag pattern to clear area.") obj.addProperty("App::PropertyBool", "UseZigZag", "Pocket", "Use Zig Zag pattern to clear area.")
@ -113,7 +113,6 @@ class ObjectPocket:
if prop == "UserLabel": if prop == "UserLabel":
obj.Label = obj.UserLabel + " :" + obj.ToolDescription obj.Label = obj.UserLabel + " :" + obj.ToolDescription
def __getstate__(self): def __getstate__(self):
return None return None
@ -126,7 +125,6 @@ class ObjectPocket:
baselist = [] baselist = []
if len(baselist) == 0: # When adding the first base object, guess at heights if len(baselist) == 0: # When adding the first base object, guess at heights
try: try:
bb = ss.Shape.BoundBox # parent boundbox bb = ss.Shape.BoundBox # parent boundbox
subobj = ss.Shape.getElement(sub) subobj = ss.Shape.getElement(sub)
@ -143,15 +141,13 @@ class ObjectPocket:
obj.FinalDepth = fbb.ZMin obj.FinalDepth = fbb.ZMin
elif fbb.ZMax == fbb.ZMin and fbb.ZMax > bb.ZMin: # face/shelf elif fbb.ZMax == fbb.ZMin and fbb.ZMax > bb.ZMin: # face/shelf
obj.FinalDepth = fbb.ZMin obj.FinalDepth = fbb.ZMin
else: #catch all else: # catch all
obj.FinalDepth = bb.ZMin obj.FinalDepth = bb.ZMin
except: except:
obj.StartDepth = 5.0 obj.StartDepth = 5.0
obj.ClearanceHeight = 10.0 obj.ClearanceHeight = 10.0
obj.SafeHeight = 8.0 obj.SafeHeight = 8.0
item = (ss, sub) item = (ss, sub)
if item in baselist: if item in baselist:
FreeCAD.Console.PrintWarning(translate("Path", "this object already in the list" + "\n")) FreeCAD.Console.PrintWarning(translate("Path", "this object already in the list" + "\n"))
@ -227,17 +223,19 @@ class ObjectPocket:
"""Build pocket Path using Native OCC algorithm.""" """Build pocket Path using Native OCC algorithm."""
import Part import Part
import DraftGeomUtils import DraftGeomUtils
from PathScripts.PathUtils import fmt, helicalPlunge, rampPlunge from PathScripts.PathUtils import fmt, helicalPlunge, rampPlunge, depth_params
FreeCAD.Console.PrintMessage(translate("PathPocket", "Generating toolpath with OCC native offsets.\n")) FreeCAD.Console.PrintMessage(translate("PathPocket", "Generating toolpath with OCC native offsets.\n"))
extraoffset = obj.MaterialAllowance.Value
# Build up the offset loops # Build up the offset loops
output = "" output = ""
if obj.Comment != "": if obj.Comment != "":
output += '(' + str(obj.Comment)+')\n' output += '(' + str(obj.Comment)+')\n'
output += 'G0 Z' + fmt(obj.ClearanceHeight.Value) + "\n"
offsets = [] offsets = []
nextradius = (self.radius * 2) * (float(obj.StepOver)/100) nextradius = self.radius + extraoffset
result = DraftGeomUtils.pocket2d(shape, nextradius) result = DraftGeomUtils.pocket2d(shape, nextradius)
print "did we get something: " + str(result) print "did we get something: " + str(result)
while result: while result:
@ -286,21 +284,25 @@ class ObjectPocket:
# print "Neither edge works: " + str(offsets[0].Edges[0]) + ", " + str(offsets[0].Edges[-1]) # print "Neither edge works: " + str(offsets[0].Edges[0]) + ", " + str(offsets[0].Edges[-1])
# FIXME: There's got to be a smarter way to find a place to ramp # FIXME: There's got to be a smarter way to find a place to ramp
fastZPos = obj.ClearanceHeight.Value
# For helix-ing/ramping, know where we were last time # For helix-ing/ramping, know where we were last time
# FIXME: Can probably get this from the "machine"? # FIXME: Can probably get this from the "machine"?
lastZ = fastZPos lastZ = obj.ClearanceHeight.Value
startPoint = None startPoint = None
for vpos in PathUtils.frange(obj.StartDepth.Value, depthparams = depth_params(
obj.FinalDepth.Value, obj.StepDown, obj.ClearanceHeight.Value,
obj.FinishDepth.Value): obj.SafeHeight.Value,
obj.StartDepth.Value,
obj.StepDown,
obj.FinishDepth.Value,
obj.FinalDepth.Value)
for vpos in depthparams.get_depths():
first = True first = True
# loop over successive wires # loop over successive wires
for currentWire in offsets: for currentWire in offsets:
#output += PathUtils.convert(currentWire.Edges, "on", 1)
last = None last = None
for edge in currentWire.Edges: for edge in currentWire.Edges:
if not last: if not last:
@ -309,7 +311,6 @@ class ObjectPocket:
# If we can helix, do so # If we can helix, do so
if plungePos: if plungePos:
output += helicalPlunge(plungePos, obj.RampAngle, vpos, lastZ, self.radius*2, obj.HelixSize, self.horizFeed) output += helicalPlunge(plungePos, obj.RampAngle, vpos, lastZ, self.radius*2, obj.HelixSize, self.horizFeed)
# print output
lastZ = vpos lastZ = vpos
# Otherwise, see if we can ramp # Otherwise, see if we can ramp
# FIXME: This could be a LOT smarter (eg, searching for a longer leg of the edge to ramp along) # FIXME: This could be a LOT smarter (eg, searching for a longer leg of the edge to ramp along)
@ -321,13 +322,13 @@ class ObjectPocket:
else: else:
print "WARNING: Straight-plunging... probably not good, but we didn't find a place to helix or ramp" print "WARNING: Straight-plunging... probably not good, but we didn't find a place to helix or ramp"
startPoint = edge.Vertexes[0].Point startPoint = edge.Vertexes[0].Point
output += "G0 Z" + fmt(obj.ClearanceHeight.Value) + "\n"
output += "G0 X" + fmt(startPoint.x) + " Y" + fmt(startPoint.y) +\ output += "G0 X" + fmt(startPoint.x) + " Y" + fmt(startPoint.y) +\
" Z" + fmt(fastZPos) + "\n" " Z" + fmt(obj.ClearanceHeight.Value) + "\n"
first = False first = False
# then move slow down to our starting point for our profile # then move slow down to our starting point for our profile
last = edge.Vertexes[0].Point last = edge.Vertexes[0].Point
output += "G1 X" + fmt(last.x) + " Y" + fmt(last.y) + " Z" + fmt(vpos) + "\n" output += "G1 X" + fmt(last.x) + " Y" + fmt(last.y) + " Z" + fmt(vpos) + "\n"
# if isinstance(edge.Curve,Part.Circle):
if DraftGeomUtils.geomType(edge) == "Circle": if DraftGeomUtils.geomType(edge) == "Circle":
point = edge.Vertexes[-1].Point point = edge.Vertexes[-1].Point
if point == last: # edges can come flipped if point == last: # edges can come flipped
@ -352,7 +353,7 @@ class ObjectPocket:
last = point last = point
# move back up # move back up
output += "G1 Z" + fmt(fastZPos) + "\n" output += "G0 Z" + fmt(obj.ClearanceHeight.Value) + "\n"
return output return output
# To reload this from FreeCAD, use: import PathScripts.PathPocket; reload(PathScripts.PathPocket) # To reload this from FreeCAD, use: import PathScripts.PathPocket; reload(PathScripts.PathPocket)
@ -418,23 +419,8 @@ class ObjectPocket:
else: else:
for w in shape.Wires: for w in shape.Wires:
c = PathScripts.PathKurveUtils.makeAreaCurve(w.Edges, 'CW') c = PathScripts.PathKurveUtils.makeAreaCurve(w.Edges, 'CW')
# if w.isSame(shape.OuterWire):
# print "outerwire"
# if c.IsClockwise():
# c.Reverse()
# print "reverse outterwire"
# else:
# print "inner wire"
# if not c.IsClockwise():
# c.Reverse()
# print "reverse inner"
a.append(c) a.append(c)
########
# This puts out some interesting information from libarea
print a.text()
########
a.Reorder() a.Reorder()
output += self.buildpathlibarea(obj, a) output += self.buildpathlibarea(obj, a)
@ -609,8 +595,6 @@ class TaskPanel:
for sub in i[1]: for sub in i[1]:
self.form.baseList.addItem(i[0].Name + "." + sub) self.form.baseList.addItem(i[0].Name + "." + sub)
def open(self): def open(self):
self.s = SelObserver() self.s = SelObserver()
# install the function mode resident # install the function mode resident
@ -633,7 +617,6 @@ class TaskPanel:
for i in sel.SubElementNames: for i in sel.SubElementNames:
self.obj.Proxy.addpocketbase(self.obj, sel.Object, i) self.obj.Proxy.addpocketbase(self.obj, sel.Object, i)
self.setFields() # defaults may have changed. Reload. self.setFields() # defaults may have changed. Reload.
self.form.baseList.clear() self.form.baseList.clear()
@ -720,7 +703,6 @@ class TaskPanel:
self.form.zigZagUnidirectional.clicked.connect(self.getFields) self.form.zigZagUnidirectional.clicked.connect(self.getFields)
self.form.zigZagAngle.editingFinished.connect(self.getFields) self.form.zigZagAngle.editingFinished.connect(self.getFields)
self.setFields() self.setFields()
sel = FreeCADGui.Selection.getSelectionEx() sel = FreeCADGui.Selection.getSelectionEx()