Path: Contour works on clones and other objects with proxy and shape.

This commit is contained in:
sliptonic
2017-06-15 14:42:30 -03:00
committed by Yorik van Havre
parent e169085959
commit 1065dc5d97
4 changed files with 41 additions and 42 deletions
+9 -13
View File
@@ -34,7 +34,7 @@ from PathScripts.PathUtils import waiting_effects
from PathScripts.PathUtils import makeWorkplane
LOG_MODULE = 'PathContour'
PathLog.setLevel(PathLog.Level.DEBUG, LOG_MODULE)
PathLog.setLevel(PathLog.Level.INFO, LOG_MODULE)
PathLog.trackModule('PathContour')
FreeCAD.setLogLevel('Path.Area', 0)
@@ -42,6 +42,7 @@ if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtGui
# Qt tanslation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
@@ -77,9 +78,6 @@ class ObjectContour:
obj.addProperty("App::PropertyEnumeration", "Direction", "Contour", QtCore.QT_TRANSLATE_NOOP("App::Property", "The direction that the toolpath should go around the part ClockWise CW or CounterClockWise CCW"))
obj.Direction = ['CW', 'CCW'] # this is the direction that the Contour runs
obj.addProperty("App::PropertyBool", "UseComp", "Contour", QtCore.QT_TRANSLATE_NOOP("App::Property", "make True, if using Cutter Radius Compensation"))
# obj.addProperty("App::PropertyEnumeration", "Side", "Contour", QtCore.QT_TRANSLATE_NOOP("App::Property", "Side of edge that tool should cut"))
# obj.Side = ['Left', 'Right'] # side of profile that cutter is on in relation to direction of profile
# obj.setEditorMode('Side', 2) # hide
obj.addProperty("App::PropertyDistance", "OffsetExtra", "Contour", QtCore.QT_TRANSLATE_NOOP("App::Property", "Extra value to stay away from final Contour- good for roughing toolpath"))
@@ -98,11 +96,6 @@ class ObjectContour:
def onChanged(self, obj, prop):
pass
# if prop == "UseComp":
# if not obj.UseComp:
# obj.setEditorMode('Side', 2)
# else:
# obj.setEditorMode('Side', 0)
def setDepths(proxy, obj):
PathLog.track()
@@ -133,7 +126,7 @@ class ObjectContour:
profile.add(baseobject)
profileparams = {'Fill': 0,
'Coplanar': 0}
'Coplanar': 2}
if obj.UseComp is False:
profileparams['Offset'] = 0.0
@@ -244,8 +237,10 @@ class ObjectContour:
# Let's always start by rapid to clearance...just for safety
commandlist.append(Path.Command("G0", {"Z": obj.ClearanceHeight.Value}))
isPanel = False
if hasattr(baseobject, "Proxy"):
if isinstance(baseobject.Proxy, ArchPanel.PanelSheet): # process the sheet
isPanel = True
baseobject.Proxy.execute(baseobject)
shapes = baseobject.Proxy.getOutlines(baseobject, transform=True)
for shape in shapes:
@@ -255,15 +250,16 @@ class ObjectContour:
try:
commandlist.extend(self._buildPathArea(obj, contourshape, start=obj.StartPoint).Commands)
except Exception as e:
print(e)
FreeCAD.Console.PrintError(e)
FreeCAD.Console.PrintError("Something unexpected happened. Unable to generate a contour path. Check project and tool config.")
else:
if hasattr(baseobject, "Shape") and not isPanel:
bb = baseobject.Shape.BoundBox
env = PathUtils.getEnvelope(partshape=baseobject.Shape, subshape=None, stockheight=bb.ZLength + (obj.StartDepth.Value-bb.ZMax))
try:
commandlist.extend(self._buildPathArea(obj, env, start=obj.StartPoint).Commands)
except Exception as e:
print(e)
FreeCAD.Console.PrintError(e)
FreeCAD.Console.PrintError("Something unexpected happened. Unable to generate a contour path. Check project and tool config.")
path = Path.Path(commandlist)
+1 -1
View File
@@ -178,7 +178,7 @@ class ObjectFace:
'Angle': obj.ZigZagAngle,
'FromCenter': (obj.StartAt == "Center"),
'PocketStepover': stepover,
'PocketExtraOffset': obj.PassExtension.Value}
'PocketExtraOffset': 0 - obj.PassExtension.Value}
Pattern = ['ZigZag', 'Offset', 'Spiral', 'ZigZagOffset', 'Line', 'Grid', 'Triangle']
pocketparams['PocketMode'] = Pattern.index(obj.OffsetPattern) + 1
+21 -13
View File
@@ -38,9 +38,10 @@ from PySide import QtGui
LOG_MODULE = 'PathUtils'
PathLog.setLevel(PathLog.Level.INFO, LOG_MODULE)
#PathLog.trackModule('PathUtils')
# PathLog.trackModule('PathUtils')
FreeCAD.setLogLevel('Path.Area', 0)
def waiting_effects(function):
def new_function(*args, **kwargs):
if not FreeCAD.GuiUp:
@@ -147,6 +148,11 @@ def isDrillable(obj, candidate, tooldiameter=None):
PathLog.debug("Has Radius, Circle")
if tooldiameter is not None:
drillable = edge.Curve.Radius >= tooldiameter/2
if not drillable:
FreeCAD.Console.PrintMessage(
"Found a drillable hole with diameter: {}: "
"too small for the current tool with "
"diameter: {}".format(edge.Curve.Radius*2, tooldiameter))
else:
drillable = True
PathLog.debug("candidate is drillable: {}".format(drillable))
@@ -277,10 +283,11 @@ def getEnvelope(partshape, subshape=None, stockheight=None):
else:
envelopeshape = sec.extrude(FreeCAD.Vector(0, 0, partshape.BoundBox.ZLength))
if PathLog.getLevel(PathLog.thisModule()) == PathLog.Level.DEBUG:
removalshape=FreeCAD.ActiveDocument.addObject("Part::Feature","Envelope")
removalshape = FreeCAD.ActiveDocument.addObject("Part::Feature", "Envelope")
removalshape.Shape = envelopeshape
return envelopeshape
def reverseEdge(e):
if geomType(e) == "Circle":
arcstpt = e.valueAt(e.FirstParameter)
@@ -610,6 +617,7 @@ def rampPlunge(edge, rampangle, destZ, startZ):
return rampCmds
def sort_jobs(locations, keys, attractors=[]):
""" sort holes by the nearest neighbor method
keys: two-element list of keys for X and Y coordinates. for example ['x','y']
@@ -624,7 +632,7 @@ def sort_jobs(locations, keys, attractors=[]):
""" square Euclidean distance """
d = 0
for k in keys:
d += (a[k] - b[k]) ** 2
d += (a[k] - b[k]) ** 2
return d
@@ -646,7 +654,6 @@ def sort_jobs(locations, keys, attractors=[]):
return result
out = []
zero = defaultdict(lambda: 0)
@@ -744,15 +751,16 @@ class depth_params:
else:
return [stop] + depths.tolist()
class CollisionTester:
def compareBBSpace(self, bb1, bb2):
if ( bb1.XMin == bb2.XMin and
bb1.XMax == bb2.XMax and
bb1.YMin == bb2.YMin and
bb1.YMax == bb2.YMax and
bb1.ZMin == bb2.ZMin and
bb1.ZMax == bb2.ZMax ) :
if (bb1.XMin == bb2.XMin and
bb1.XMax == bb2.XMax and
bb1.YMin == bb2.YMin and
bb1.YMax == bb2.YMax and
bb1.ZMin == bb2.ZMin and
bb1.ZMax == bb2.ZMax):
return True
return False
@@ -774,13 +782,13 @@ class CollisionTester:
if self.compareBBSpace(i.BoundBox, j.BoundBox):
match = True
if match is True:
#print ("Need to highlight Face{}".format(idx+1))
# print ("Need to highlight Face{}".format(idx+1))
colorassignment.append(intersecColor)
else:
colorassignment.append(baseColor)
collisionSim = FreeCAD.ActiveDocument.addObject("Part::Feature","Collision")
collisionSim = FreeCAD.ActiveDocument.addObject("Part::Feature", "Collision")
collisionSim.Shape = gougedShape
collisionSim.ViewObject.DiffuseColor=colorassignment
collisionSim.ViewObject.DiffuseColor = colorassignment
return collisionSim
else:
return None