From 62c9bcc39aafe7d49bfde8163ba81659576bf034 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Thu, 10 Aug 2017 16:34:44 -0700 Subject: [PATCH] Added support for baseobject into PathOp, used by almost all ops anyway. --- .../Path/PathScripts/PathCircularHoleBase.py | 19 ++++++-------- src/Mod/Path/PathScripts/PathMillFace.py | 8 ++---- src/Mod/Path/PathScripts/PathOp.py | 8 ++++++ src/Mod/Path/PathScripts/PathPocket.py | 13 +++------- .../Path/PathScripts/PathProfileContour.py | 22 ++++++---------- src/Mod/Path/PathScripts/PathProfileEdges.py | 7 +----- src/Mod/Path/PathScripts/PathProfileFaces.py | 25 ++++++++----------- 7 files changed, 39 insertions(+), 63 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathCircularHoleBase.py b/src/Mod/Path/PathScripts/PathCircularHoleBase.py index 5758a91e5a..1854cee103 100644 --- a/src/Mod/Path/PathScripts/PathCircularHoleBase.py +++ b/src/Mod/Path/PathScripts/PathCircularHoleBase.py @@ -104,29 +104,24 @@ class ObjectOp(PathOp.ObjectOp): PathLog.track() if len(obj.Base) == 0: - job = PathUtils.findParentJob(obj) - if not job or not job.Base: - return - baseobject = job.Base - # Arch PanelSheet features = [] - if self.baseIsArchPanel(obj, baseobject): - holeshapes = baseobject.Proxy.getHoles(baseobject, transform=True) + if self.baseIsArchPanel(obj, self.baseobject): + holeshapes = self.baseobject.Proxy.getHoles(self.baseobject, transform=True) tooldiameter = obj.ToolController.Proxy.getTool(obj.ToolController).Diameter for holeNr, hole in enumerate(holeshapes): PathLog.debug('Entering new HoleShape') for wireNr, wire in enumerate(hole.Wires): PathLog.debug('Entering new Wire') for edgeNr, edge in enumerate(wire.Edges): - if PathUtils.isDrillable(baseobject, edge, tooldiameter): + if PathUtils.isDrillable(self.baseobject, edge, tooldiameter): PathLog.debug('Found drillable hole edges: {}'.format(edge)) - features.append((baseobject, "%d.%d.%d" % (holeNr, wireNr, edgeNr))) + features.append((self.baseobject, "%d.%d.%d" % (holeNr, wireNr, edgeNr))) - self.setDepths(obj, None, None, baseobject.Shape.BoundBox) + self.setDepths(obj, None, None, self.baseobject.Shape.BoundBox) else: - features = self.findHoles(obj, baseobject) - self.setupDepthsFrom(obj, features, baseobject) + features = self.findHoles(obj, self.baseobject) + self.setupDepthsFrom(obj, features, self.baseobject) obj.Base = features obj.Disabled = [] diff --git a/src/Mod/Path/PathScripts/PathMillFace.py b/src/Mod/Path/PathScripts/PathMillFace.py index f3c2985a63..46d14c0bc5 100644 --- a/src/Mod/Path/PathScripts/PathMillFace.py +++ b/src/Mod/Path/PathScripts/PathMillFace.py @@ -145,12 +145,8 @@ class ObjectFace(PathAreaOp.ObjectOp): # If no base object, do planing of top surface of entire model else: - job = PathUtils.findParentJob(obj) - if not job or not job.Base: - return - baseobject = job.Base - planeshape = baseobject.Shape - PathLog.debug("Working on a shape {}".format(baseobject.Name)) + planeshape = self.baseobject.Shape + PathLog.debug("Working on a shape {}".format(self.baseobject.Name)) # if user wants the boundbox, calculate that PathLog.debug("Boundary Shape: {}".format(obj.BoundaryShape)) diff --git a/src/Mod/Path/PathScripts/PathOp.py b/src/Mod/Path/PathScripts/PathOp.py index f604a90c68..bb17c3f0d1 100644 --- a/src/Mod/Path/PathScripts/PathOp.py +++ b/src/Mod/Path/PathScripts/PathOp.py @@ -143,6 +143,14 @@ class ObjectOp(object): obj.ViewObject.Visibility = False return + if not job: + PathLog.error(translate("Path", "No parent job found for operation.")) + return + if not job.Base: + PathLog.error(translate("Path", "Parent job %s doesn't have a base object") % job.Label) + return + self.baseobject = job.Base + if FeatureTool & self.opFeatures(obj): tc = obj.ToolController if tc is None or tc.ToolNumber == 0: diff --git a/src/Mod/Path/PathScripts/PathPocket.py b/src/Mod/Path/PathScripts/PathPocket.py index 240305f8ba..612327bd02 100644 --- a/src/Mod/Path/PathScripts/PathPocket.py +++ b/src/Mod/Path/PathScripts/PathPocket.py @@ -96,11 +96,6 @@ class ObjectPocket(PathAreaOp.ObjectOp): def areaOpShapes(self, obj): PathLog.track() - job = PathUtils.findParentJob(obj) - if not job or not job.Base: - return - baseobject = job.Base - if obj.Base: PathLog.debug("base items exist. Processing...") removalshapes = [] @@ -113,14 +108,14 @@ class ObjectPocket(PathAreaOp.ObjectOp): edges = [getattr(b[0].Shape, sub) for sub in b[1]] shape = Part.makeFace(edges, 'Part::FaceMakerSimple') - env = PathUtils.getEnvelope(baseobject.Shape, subshape=shape, depthparams=self.depthparams) - obj.removalshape = env.cut(baseobject.Shape) + env = PathUtils.getEnvelope(self.baseobject.Shape, subshape=shape, depthparams=self.depthparams) + obj.removalshape = env.cut(self.baseobject.Shape) removalshapes.append((obj.removalshape, False)) else: # process the job base object as a whole PathLog.debug("processing the whole job base object") - env = PathUtils.getEnvelope(baseobject.Shape, subshape=None, depthparams=self.depthparams) - obj.removalshape = env.cut(baseobject.Shape) + env = PathUtils.getEnvelope(self.baseobject.Shape, subshape=None, depthparams=self.depthparams) + obj.removalshape = env.cut(self.baseobject.Shape) removalshapes = [(obj.removalshape, False)] return removalshapes diff --git a/src/Mod/Path/PathScripts/PathProfileContour.py b/src/Mod/Path/PathScripts/PathProfileContour.py index a4bbb3b49b..10084d60cf 100644 --- a/src/Mod/Path/PathScripts/PathProfileContour.py +++ b/src/Mod/Path/PathScripts/PathProfileContour.py @@ -76,27 +76,19 @@ class ObjectContour(PathProfileBase.ObjectProfile): else: self.commandlist.append(Path.Command("(Uncompensated Tool Path)")) - job = PathUtils.findParentJob(obj) - - if job is None: - return - baseobject = job.Base - if baseobject is None: - return - isPanel = False - if hasattr(baseobject, "Proxy"): - if isinstance(baseobject.Proxy, ArchPanel.PanelSheet): # process the sheet + if hasattr(self.baseobject, "Proxy"): + if isinstance(self.baseobject.Proxy, ArchPanel.PanelSheet): # process the sheet isPanel = True - baseobject.Proxy.execute(baseobject) - shapes = baseobject.Proxy.getOutlines(baseobject, transform=True) + self.baseobject.Proxy.execute(self.baseobject) + shapes = self.baseobject.Proxy.getOutlines(self.baseobject, transform=True) for shape in shapes: f = Part.makeFace([shape], 'Part::FaceMakerSimple') - thickness = baseobject.Group[0].Source.Thickness + thickness = self.baseobject.Group[0].Source.Thickness return [(f.extrude(FreeCAD.Vector(0, 0, thickness)), False)] - if hasattr(baseobject, "Shape") and not isPanel: - return [(PathUtils.getEnvelope(partshape=baseobject.Shape, subshape=None, depthparams=self.depthparams), False)] + if hasattr(self.baseobject, "Shape") and not isPanel: + return [(PathUtils.getEnvelope(partshape=self.baseobject.Shape, subshape=None, depthparams=self.depthparams), False)] def areaOpAreaParams(self, obj, isHole): params = self.baseObject().areaOpAreaParams(obj, isHole) diff --git a/src/Mod/Path/PathScripts/PathProfileEdges.py b/src/Mod/Path/PathScripts/PathProfileEdges.py index 025f7ac6b0..aca05c4817 100644 --- a/src/Mod/Path/PathScripts/PathProfileEdges.py +++ b/src/Mod/Path/PathScripts/PathProfileEdges.py @@ -69,11 +69,6 @@ class ObjectProfile(PathProfileBase.ObjectProfile): def areaOpShapes(self, obj): PathLog.track() - job = PathUtils.findParentJob(obj) - if not job or not job.Base: - return - baseobject = job.Base - if obj.UseComp: self.commandlist.append(Path.Command("(Compensated Tool Path. Diameter: " + str(self.radius * 2) + ")")) else: @@ -97,7 +92,7 @@ class ObjectProfile(PathProfileBase.ObjectProfile): zShift = b[0].Shape.BoundBox.ZMin - f.BoundBox.ZMin newPlace = FreeCAD.Placement(FreeCAD.Vector(0, 0, zShift), f.Placement.Rotation) f.Placement = newPlace - env = PathUtils.getEnvelope(baseobject.Shape, subshape=f, depthparams=self.depthparams) + env = PathUtils.getEnvelope(self.baseobject.Shape, subshape=f, depthparams=self.depthparams) shapes.append((env, False)) return shapes diff --git a/src/Mod/Path/PathScripts/PathProfileFaces.py b/src/Mod/Path/PathScripts/PathProfileFaces.py index 7ec188f32c..44446849b1 100644 --- a/src/Mod/Path/PathScripts/PathProfileFaces.py +++ b/src/Mod/Path/PathScripts/PathProfileFaces.py @@ -79,11 +79,6 @@ class ObjectProfile(PathProfileBase.ObjectProfile): else: self.commandlist.append(Path.Command("(Uncompensated Tool Path)")) - job = PathUtils.findParentJob(obj) - if not job or not job.Base: - return - - baseobject = job.Base shapes = [] if obj.Base: # The user has selected subobjects from the base. Process each. @@ -102,35 +97,35 @@ class ObjectProfile(PathProfileBase.ObjectProfile): for wire in holes: f = Part.makeFace(wire, 'Part::FaceMakerSimple') - drillable = PathUtils.isDrillable(baseobject.Shape, wire) + drillable = PathUtils.isDrillable(self.baseobject.Shape, wire) if (drillable and obj.processCircles) or (not drillable and obj.processHoles): - env = PathUtils.getEnvelope(baseobject.Shape, subshape=f, depthparams=self.depthparams) + env = PathUtils.getEnvelope(self.baseobject.Shape, subshape=f, depthparams=self.depthparams) shapes.append((env, True)) if len(faces) > 0: profileshape = Part.makeCompound(faces) if obj.processPerimeter: - env = PathUtils.getEnvelope(baseobject.Shape, subshape=profileshape, depthparams=self.depthparams) + env = PathUtils.getEnvelope(self.baseobject.Shape, subshape=profileshape, depthparams=self.depthparams) shapes.append((env, False)) else: # Try to build targets from the job base - if hasattr(baseobject, "Proxy"): - if isinstance(baseobject.Proxy, ArchPanel.PanelSheet): # process the sheet + if hasattr(self.baseobject, "Proxy"): + if isinstance(self.baseobject.Proxy, ArchPanel.PanelSheet): # process the sheet if obj.processCircles or obj.processHoles: - for shape in baseobject.Proxy.getHoles(baseobject, transform=True): + for shape in self.baseobject.Proxy.getHoles(self.baseobject, transform=True): for wire in shape.Wires: - drillable = PathUtils.isDrillable(baseobject.Proxy, wire) + drillable = PathUtils.isDrillable(self.baseobject.Proxy, wire) if (drillable and obj.processCircles) or (not drillable and obj.processHoles): f = Part.makeFace(wire, 'Part::FaceMakerSimple') - env = PathUtils.getEnvelope(baseobject.Shape, subshape=f, depthparams=self.depthparams) + env = PathUtils.getEnvelope(self.baseobject.Shape, subshape=f, depthparams=self.depthparams) shapes.append((env, True)) if obj.processPerimeter: - for shape in baseobject.Proxy.getOutlines(baseobject, transform=True): + for shape in self.baseobject.Proxy.getOutlines(self.baseobject, transform=True): for wire in shape.Wires: f = Part.makeFace(wire, 'Part::FaceMakerSimple') - env = PathUtils.getEnvelope(baseobject.Shape, subshape=f, depthparams=self.depthparams) + env = PathUtils.getEnvelope(self.baseobject.Shape, subshape=f, depthparams=self.depthparams) shapes.append((env, False)) return shapes