diff --git a/src/Mod/Path/PathScripts/PathContour.py b/src/Mod/Path/PathScripts/PathContour.py index 6cbe457d3c..34f2e48d4a 100644 --- a/src/Mod/Path/PathScripts/PathContour.py +++ b/src/Mod/Path/PathScripts/PathContour.py @@ -171,6 +171,23 @@ class ObjectContour: PathLog.debug('pp: {}, end vector: {}'.format(pp, end_vector)) self.endVector = end_vector + if True: + from PathScripts.PathUtils import CollisionTester + parentJob = PathUtils.findParentJob(obj) + if parentJob is None: + pass + base = parentJob.Base + if base is None: + pass + + profileparams['Thicken'] = True #{'Fill':0, 'Coplanar':0, 'Project':True, 'SectionMode':2, 'Thicken':True} + profileparams['ToolRadius']= self.radius - self.radius *.005 + profile.setParams(**profileparams) + sec = profile.makeSections(heights=[0.0])[0].getShape() + cutPath = sec.extrude(FreeCAD.Vector(0,0,baseobject.BoundBox.ZMax)) + c = CollisionTester() + c.getCollisionSim(base.Shape, cutPath) + return pp def execute(self, obj): @@ -227,7 +244,7 @@ class ObjectContour: FreeCAD.Console.PrintError("Something unexpected happened. Unable to generate a contour path. Check project and tool config.") else: bb = baseobject.Shape.BoundBox - env = PathUtils.getEnvelope(baseobject.Shape, bb.ZLength + (obj.StartDepth.Value-bb.ZMax)) + env = PathUtils.getEnvelope(partshape=baseobject.Shape, stockheight=bb.ZLength + (obj.StartDepth.Value-bb.ZMax)) try: commandlist.extend(self._buildPathArea(obj, env, start=obj.StartPoint).Commands) except Exception as e: diff --git a/src/Mod/Path/PathScripts/PathMillFace.py b/src/Mod/Path/PathScripts/PathMillFace.py index 82ec975a2b..b221dd2a46 100644 --- a/src/Mod/Path/PathScripts/PathMillFace.py +++ b/src/Mod/Path/PathScripts/PathMillFace.py @@ -206,7 +206,22 @@ class ObjectFace: PathLog.debug("Generating Path with params: {}".format(params)) pp = Path.fromShapes(**params) + # if True: + # from PathScripts.PathUtils import CollisionTester + # parentJob = PathUtils.findParentJob(obj) + # if parentJob is None: + # pass + # base = parentJob.Base + # if base is None: + # pass + # pocketparams['Thicken'] = True #{'Fill':0, 'Coplanar':0, 'Project':True, 'SectionMode':2, 'Thicken':True} + # pocketparams['ToolRadius']= self.radius - self.radius *.005 + # boundary.setParams(**pocketparams) + # sec = boundary.makeSections(heights=[0.0])[0].getShape() + # cutPath = sec.extrude(FreeCAD.Vector(0,0,baseobject.BoundBox.ZMax)) + # c = CollisionTester() + # c.getCollisionSim(base.Shape, cutPath) return pp def execute(self, obj): @@ -266,9 +281,9 @@ class ObjectFace: bb = planeshape.BoundBox if obj.BoundaryShape == 'Boundbox': bbperim = Part.makeBox(bb.XLength, bb.YLength, 1, Vector(bb.XMin, bb.YMin, bb.ZMin), Vector(0, 0, 1)) - env = PathUtils.getEnvelope(bbperim, bb.ZLength + (obj.StartDepth.Value-bb.ZMax)) + env = PathUtils.getEnvelope(partshape=bbperim, stockheight=bb.ZLength + (obj.StartDepth.Value-bb.ZMax)) else: - env = PathUtils.getEnvelope(planeshape, bb.ZLength + (obj.StartDepth.Value-bb.ZMax)) + env = PathUtils.getEnvelope(partshape=planeshape, stockheight=bb.ZLength + (obj.StartDepth.Value-bb.ZMax)) try: commandlist.extend(self._buildPathArea(obj, env).Commands) diff --git a/src/Mod/Path/PathScripts/PathProfileEdges.py b/src/Mod/Path/PathScripts/PathProfileEdges.py index ed7cd099fb..4add9e0148 100644 --- a/src/Mod/Path/PathScripts/PathProfileEdges.py +++ b/src/Mod/Path/PathScripts/PathProfileEdges.py @@ -189,6 +189,22 @@ class ObjectProfile: PathLog.debug("Generating Path with params: {}".format(params)) PathLog.debug(pp) + if True: + from PathScripts.PathUtils import CollisionTester + parentJob = PathUtils.findParentJob(obj) + if parentJob is None: + pass + base = parentJob.Base + if base is None: + pass + + profileparams['Thicken'] = True #{'Fill':0, 'Coplanar':0, 'Project':True, 'SectionMode':2, 'Thicken':True} + profileparams['ToolRadius']= self.radius - self.radius *.005 + profile.setParams(**profileparams) + sec = profile.makeSections(heights=[0.0])[0].getShape() + cutPath = sec.extrude(FreeCAD.Vector(0,0,baseobject.BoundBox.ZMax)) + c = CollisionTester() + c.getCollisionSim(base.Shape, cutPath) return pp diff --git a/src/Mod/Path/PathScripts/PathUtils.py b/src/Mod/Path/PathScripts/PathUtils.py index 7a4924d03a..54b8e5cb1f 100644 --- a/src/Mod/Path/PathScripts/PathUtils.py +++ b/src/Mod/Path/PathScripts/PathUtils.py @@ -726,3 +726,44 @@ class depth_params: return depths.tolist() 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 ) : + return True + return False + + def getCollisionSim(self, baseobject, cutterPath): + + baseColor = (0.800000011920929, 0.800000011920929, 0.800000011920929, 00.0) + intersecColor = (1.0, 0.0, 0.0, 0.0) + cVol = baseobject.common(cutterPath) + + if cVol.Volume > 1e-12: + colorassignment = [] + gougedShape = baseobject.cut(cutterPath) + # gougeSim = FreeCAD.ActiveDocument.addObject("Part::Feature","Gouge") + # gougeSim.Shape = gougedShape + + for idx, i in enumerate(gougedShape.Faces): + match = False + for jdx, j in enumerate(cVol.Faces): + if self.compareBBSpace(i.BoundBox, j.BoundBox): + match = True + if match is True: + #print ("Need to highlight Face{}".format(idx+1)) + colorassignment.append(intersecColor) + else: + colorassignment.append(baseColor) + collisionSim = FreeCAD.ActiveDocument.addObject("Part::Feature","Collision") + collisionSim.Shape = gougedShape + collisionSim.ViewObject.DiffuseColor=colorassignment + return collisionSim + else: + return None