From 57c0463583436435b23d719939b5779bac5a7235 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Sun, 17 Sep 2017 17:24:53 -0700 Subject: [PATCH] Basic pocket generation from horizontal faces. --- src/Mod/Path/PathScripts/PathOp.py | 2 ++ src/Mod/Path/PathScripts/PathPocketShape.py | 33 +++++++++++-------- .../Path/PathScripts/PathPocketShapeGui.py | 4 +-- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathOp.py b/src/Mod/Path/PathScripts/PathOp.py index 8eb6324408..cce3e96dc9 100644 --- a/src/Mod/Path/PathScripts/PathOp.py +++ b/src/Mod/Path/PathScripts/PathOp.py @@ -229,6 +229,7 @@ class ObjectOp(object): It also sets the following instance variables that can and should be safely be used by implementation of opExecute(): self.baseobject ... Base object of the Job itself + self.stock ... Stock object fo the Job itself self.vertFeed ... vertical feed rate of assigned tool self.vertRapid ... vertical rapid rate of assigned tool self.horizFeed ... horizontal feed rate of assigned tool @@ -259,6 +260,7 @@ class ObjectOp(object): PathLog.error(translate("Path", "Parent job %s doesn't have a base object") % job.Label) return self.baseobject = job.Base + self.stock = job.Stock if FeatureTool & self.opFeatures(obj): tc = obj.ToolController diff --git a/src/Mod/Path/PathScripts/PathPocketShape.py b/src/Mod/Path/PathScripts/PathPocketShape.py index f603048c53..90713d82b8 100644 --- a/src/Mod/Path/PathScripts/PathPocketShape.py +++ b/src/Mod/Path/PathScripts/PathPocketShape.py @@ -28,6 +28,7 @@ import PathScripts.PathLog as PathLog import PathScripts.PathOp as PathOp import PathScripts.PathPocketBase as PathPocketBase import PathScripts.PathUtils as PathUtils +import TechDraw import sys from PathScripts.PathGeom import PathGeom @@ -38,7 +39,7 @@ __author__ = "sliptonic (Brad Collette)" __url__ = "http://www.freecadweb.org" __doc__ = "Class and implementation of shape based Pocket operation." -if False: +if True: PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule()) PathLog.trackModule(PathLog.thisModule()) else: @@ -66,24 +67,28 @@ class ObjectPocket(PathPocketBase.ObjectPocket): if obj.Base: PathLog.debug("base items exist. Processing...") removalshapes = [] - for b in obj.Base: - PathLog.debug("Base item: {}".format(b)) - for sub in b[1]: + horizontal = [] + for o in obj.Base: + PathLog.debug("Base item: {}".format(o)) + base = o[0] + for sub in o[1]: if "Face" in sub: - shape = Part.makeCompound([getattr(b[0].Shape, sub)]) - else: - edges = [getattr(b[0].Shape, sub) for sub in b[1]] - shape = Part.makeFace(edges, 'Part::FaceMakerSimple') + face = base.Shape.getElement(sub) + if type(face.Surface) == Part.Plane and PathGeom.pointsCoincide(face.Surface.Axis, FreeCAD.Vector(0, 0, 1)): + horizontal.append(face) + + for face in horizontal: + face.translate(FreeCAD.Vector(0, 0, obj.FinalDepth.Value - face.BoundBox.ZMin)) + removalshapes.append((face.extrude(FreeCAD.Vector(0, 0, obj.StartDepth.Value - obj.FinalDepth.Value)), False)) - env = PathUtils.getEnvelope(self.baseobject.Shape, subshape=shape, depthparams=self.depthparams) - obj.removalshape = env.cut(self.baseobject.Shape) - obj.removalshape.tessellate(0.1) - removalshapes.append((obj.removalshape, False)) else: # process the job base object as a whole PathLog.debug("processing the whole job base object") + self.outline = Part.Face(TechDraw.findShapeOutline(self.baseobject.Shape, 1, FreeCAD.Vector(0, 0, 1))) + stockBB = self.stock.Shape.BoundBox - env = PathUtils.getEnvelope(self.baseobject.Shape, subshape=None, depthparams=self.depthparams) - obj.removalshape = env.cut(self.baseobject.Shape) + self.outline.translate(FreeCAD.Vector(0, 0, stockBB.ZMin - 1)) + self.body = self.outline.extrude(FreeCAD.Vector(0, 0, stockBB.ZLength + 2)) + obj.removalshape = self.stock.Shape.cut(self.body) obj.removalshape.tessellate(0.1) removalshapes = [(obj.removalshape, False)] return removalshapes diff --git a/src/Mod/Path/PathScripts/PathPocketShapeGui.py b/src/Mod/Path/PathScripts/PathPocketShapeGui.py index 399f105f24..53093921ff 100644 --- a/src/Mod/Path/PathScripts/PathPocketShapeGui.py +++ b/src/Mod/Path/PathScripts/PathPocketShapeGui.py @@ -24,7 +24,7 @@ import FreeCAD import PathScripts.PathOpGui as PathOpGui -import PathScripts.PathPocket as PathPocket +import PathScripts.PathPocketShape as PathPocketShape import PathScripts.PathPocketBaseGui as PathPocketBaseGui from PySide import QtCore @@ -42,7 +42,7 @@ class TaskPanelOpPage(PathPocketBaseGui.TaskPanelOpPage): return PathPocketBaseGui.FeaturePocket Command = PathOpGui.SetupOperation('Pocket Shape', - PathPocket.Create, + PathPocketShape.Create, TaskPanelOpPage, 'Path-Pocket', QtCore.QT_TRANSLATE_NOOP("PathPocket", "Pocket Shape"),