From 1e76c9925098bdfd645e1ee392475982c9fac063 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Sat, 5 Aug 2017 20:19:24 -0700 Subject: [PATCH] Renamed PathProfile to PathProfileFaces for consistency; moved common depth calculation for ops with BaseGeometry into PathAreaOp. --- src/Mod/Path/CMakeLists.txt | 4 +- src/Mod/Path/InitGui.py | 2 +- src/Mod/Path/PathScripts/PathAreaOp.py | 45 +++++++++++++++ src/Mod/Path/PathScripts/PathContour.py | 8 --- src/Mod/Path/PathScripts/PathPocket.py | 36 ------------ .../{PathProfile.py => PathProfileFaces.py} | 55 +++---------------- ...thProfileGui.py => PathProfileFacesGui.py} | 4 +- 7 files changed, 59 insertions(+), 95 deletions(-) rename src/Mod/Path/PathScripts/{PathProfile.py => PathProfileFaces.py} (84%) rename src/Mod/Path/PathScripts/{PathProfileGui.py => PathProfileFacesGui.py} (98%) diff --git a/src/Mod/Path/CMakeLists.txt b/src/Mod/Path/CMakeLists.txt index d6df197041..05023311fd 100644 --- a/src/Mod/Path/CMakeLists.txt +++ b/src/Mod/Path/CMakeLists.txt @@ -56,8 +56,8 @@ SET(PathScripts_SRCS PathScripts/PathPreferences.py PathScripts/PathPreferencesPathDressup.py PathScripts/PathPreferencesPathJob.py - PathScripts/PathProfile.py - PathScripts/PathProfileGui.py + PathScripts/PathProfileFaces.py + PathScripts/PathProfileFacesGui.py PathScripts/PathProfileEdges.py PathScripts/PathSanity.py PathScripts/PathSelection.py diff --git a/src/Mod/Path/InitGui.py b/src/Mod/Path/InitGui.py index 2ea2bffebc..ed349176ed 100644 --- a/src/Mod/Path/InitGui.py +++ b/src/Mod/Path/InitGui.py @@ -67,7 +67,7 @@ class PathWorkbench (Workbench): from PathScripts import PathPlane from PathScripts import PathPocketGui from PathScripts import PathPost - from PathScripts import PathProfileGui + from PathScripts import PathProfileFacesGui from PathScripts import PathProfileEdges from PathScripts import PathSanity from PathScripts import PathSimpleCopy diff --git a/src/Mod/Path/PathScripts/PathAreaOp.py b/src/Mod/Path/PathScripts/PathAreaOp.py index 3e7b75104c..05b664e1a6 100644 --- a/src/Mod/Path/PathScripts/PathAreaOp.py +++ b/src/Mod/Path/PathScripts/PathAreaOp.py @@ -110,11 +110,56 @@ class ObjectOp(object): pass def opSetDefaultValues(self, obj): pass + def opShapeForDepths(self, obj): + job = PathUtils.findParentJob(obj) + if job and job.Base: + PathLog.debug("job=%s base=%s shape=%s" % (job, job.Base, job.Base.Shape)) + return job.Base.Shape + PathLog.warning(translate("PathAreaOp", "No job object found (%s), or job has no Base." % job)) + return None + def onChanged(self, obj, prop): #PathLog.track(obj.Label, prop) if prop in ['AreaParams', 'PathParams', 'removalshape']: obj.setEditorMode(prop, 2) + + if FeatureBaseGeometry & self.opFeatures(obj): + if prop == 'Base' and len(obj.Base) == 1: + try: + (base, sub) = obj.Base[0] + bb = base.Shape.BoundBox # parent boundbox + subobj = base.Shape.getElement(sub[0]) + fbb = subobj.BoundBox # feature boundbox + obj.StartDepth = bb.ZMax + obj.ClearanceHeight = bb.ZMax + 5.0 + obj.SafeHeight = bb.ZMax + 3.0 + + if fbb.ZMax == fbb.ZMin and fbb.ZMax == bb.ZMax: # top face + obj.FinalDepth = bb.ZMin + elif fbb.ZMax > fbb.ZMin and fbb.ZMax == bb.ZMax: # vertical face, full cut + obj.FinalDepth = fbb.ZMin + elif fbb.ZMax > fbb.ZMin and fbb.ZMin > bb.ZMin: # internal vertical wall + obj.FinalDepth = fbb.ZMin + elif fbb.ZMax == fbb.ZMin and fbb.ZMax > bb.ZMin: # face/shelf + obj.FinalDepth = fbb.ZMin + else: # catch all + obj.FinalDepth = bb.ZMin + + if hasattr(obj, 'Side'): + if bb.XLength == fbb.XLength and bb.YLength == fbb.YLength: + obj.Side = "Outside" + else: + obj.Side = "Inside" + + except Exception as e: + PathLog.error(translate("PatArea", "Error in calculating depths: %s" % e)) + obj.StartDepth = 5.0 + obj.ClearanceHeight = 10.0 + obj.SafeHeight = 8.0 + if hasattr(obj, 'Side'): + obj.Side = "Outside" + self.opOnChanged(obj, prop) def setDefaultValues(self, obj): diff --git a/src/Mod/Path/PathScripts/PathContour.py b/src/Mod/Path/PathScripts/PathContour.py index 58f88cb044..de8f2a9fbe 100644 --- a/src/Mod/Path/PathScripts/PathContour.py +++ b/src/Mod/Path/PathScripts/PathContour.py @@ -86,14 +86,6 @@ class ObjectContour(PathAreaOp.ObjectOp): else: obj.setEditorMode('MiterLimit', 2) - def opShapeForDepths(self, obj): - job = PathUtils.findParentJob(obj) - if job and job.Base: - PathLog.debug("job=%s base=%s shape=%s" % (job, job.Base, job.Base.Shape)) - return job.Base.Shape - PathLog.warning("No job object found (%s), or job has no Base." % job) - return None - def opSetDefaultValues(self, obj): obj.Direction = "CW" obj.UseComp = True diff --git a/src/Mod/Path/PathScripts/PathPocket.py b/src/Mod/Path/PathScripts/PathPocket.py index 664e72ccca..5d0dbbb9e8 100644 --- a/src/Mod/Path/PathScripts/PathPocket.py +++ b/src/Mod/Path/PathScripts/PathPocket.py @@ -67,14 +67,6 @@ class ObjectPocket(PathAreaOp.ObjectOp): def opUseProjection(self, obj): return False - def opShapeForDepths(self, obj): - job = PathUtils.findParentJob(obj) - if job and job.Base: - PathLog.debug("job=%s base=%s shape=%s" % (job, job.Base, job.Base.Shape)) - return job.Base.Shape - PathLog.warning("No job object found (%s), or job has no Base." % job) - return None - def opAreaParams(self, obj, isHole): params = {} params['Fill'] = 0 @@ -136,34 +128,6 @@ class ObjectPocket(PathAreaOp.ObjectOp): obj.StepOver = 100 obj.ZigZagAngle = 45 - def opOnChanged(self, obj, prop): - #PathLog.track(obj.Label, prop) - if prop == 'Base' and len(obj.Base) == 1: - try: - (base, sub) = obj.Base[0] - bb = base.Shape.BoundBox # parent boundbox - subobj = base.Shape.getElement(sub[0]) - fbb = subobj.BoundBox # feature boundbox - obj.StartDepth = bb.ZMax - obj.ClearanceHeight = bb.ZMax + 5.0 - obj.SafeHeight = bb.ZMax + 3.0 - - if fbb.ZMax == fbb.ZMin and fbb.ZMax == bb.ZMax: # top face - obj.FinalDepth = bb.ZMin - elif fbb.ZMax > fbb.ZMin and fbb.ZMax == bb.ZMax: # vertical face, full cut - obj.FinalDepth = fbb.ZMin - elif fbb.ZMax > fbb.ZMin and fbb.ZMin > bb.ZMin: # internal vertical wall - obj.FinalDepth = fbb.ZMin - elif fbb.ZMax == fbb.ZMin and fbb.ZMax > bb.ZMin: # face/shelf - obj.FinalDepth = fbb.ZMin - else: # catch all - obj.FinalDepth = bb.ZMin - except Exception as e: - PathLog.error(translate("PathPocket", "Error in calculating depths: %s" % e)) - obj.StartDepth = 5.0 - obj.ClearanceHeight = 10.0 - obj.SafeHeight = 8.0 - def Create(name): obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name) diff --git a/src/Mod/Path/PathScripts/PathProfile.py b/src/Mod/Path/PathScripts/PathProfileFaces.py similarity index 84% rename from src/Mod/Path/PathScripts/PathProfile.py rename to src/Mod/Path/PathScripts/PathProfileFaces.py index 5d9db8d8f6..befee9fd57 100644 --- a/src/Mod/Path/PathScripts/PathProfile.py +++ b/src/Mod/Path/PathScripts/PathProfileFaces.py @@ -59,13 +59,15 @@ class ObjectProfile(PathAreaOp.ObjectOp): obj.Direction = ['CW', 'CCW'] # this is the direction that the profile runs obj.addProperty("App::PropertyBool", "UseComp", "Profile", QtCore.QT_TRANSLATE_NOOP("App::Property", "make True, if using Cutter Radius Compensation")) obj.addProperty("App::PropertyDistance", "OffsetExtra", "Profile", QtCore.QT_TRANSLATE_NOOP("App::Property", "Extra value to stay away from final profile- good for roughing toolpath")) - obj.addProperty("App::PropertyBool", "processHoles", "Profile", QtCore.QT_TRANSLATE_NOOP("App::Property", "Profile holes as well as the outline")) - obj.addProperty("App::PropertyBool", "processPerimeter", "Profile", QtCore.QT_TRANSLATE_NOOP("App::Property", "Profile the outline")) - obj.addProperty("App::PropertyBool", "processCircles", "Profile", QtCore.QT_TRANSLATE_NOOP("App::Property", "Profile round holes")) obj.addProperty("App::PropertyEnumeration", "JoinType", "Profile", QtCore.QT_TRANSLATE_NOOP("App::Property", "Controls how tool moves around corners. Default=Round")) obj.JoinType = ['Round', 'Square', 'Miter'] # this is the direction that the Contour runs obj.addProperty("App::PropertyFloat", "MiterLimit", "Profile", QtCore.QT_TRANSLATE_NOOP("App::Property", "Maximum distance before a miter join is truncated")) + # Face specific Properties + obj.addProperty("App::PropertyBool", "processHoles", "Profile", QtCore.QT_TRANSLATE_NOOP("App::Property", "Profile holes as well as the outline")) + obj.addProperty("App::PropertyBool", "processPerimeter", "Profile", QtCore.QT_TRANSLATE_NOOP("App::Property", "Profile the outline")) + obj.addProperty("App::PropertyBool", "processCircles", "Profile", QtCore.QT_TRANSLATE_NOOP("App::Property", "Profile round holes")) + obj.Proxy = self def opSetDefaultValues(self, obj): @@ -73,11 +75,13 @@ class ObjectProfile(PathAreaOp.ObjectOp): obj.OffsetExtra = 0.0 obj.Direction = "CW" obj.UseComp = True - obj.processHoles = False - obj.processPerimeter = True obj.JoinType = "Round" obj.MiterLimit = 0.1 + obj.processHoles = False + obj.processCircles = False + obj.processPerimeter = True + def onOpChanged(self, obj, prop): if prop == "UseComp": if not obj.UseComp: @@ -90,53 +94,12 @@ class ObjectProfile(PathAreaOp.ObjectOp): if obj.JoinType == 'Miter': obj.setEditorMode('MiterLimit', 0) - if prop == 'Base' and len(obj.Base) == 1: - try: - (base, sub) = obj.Base[0] - bb = base.BoundBox # parent boundbox - subobj = base.getElement(sub) - fbb = subobj.BoundBox # feature boundbox - obj.StartDepth = bb.ZMax - obj.ClearanceHeight = bb.ZMax + 5.0 - obj.SafeHeight = bb.ZMax + 3.0 - - if fbb.ZMax == fbb.ZMin and fbb.ZMax == bb.ZMax: # top face - obj.FinalDepth = bb.ZMin - elif fbb.ZMax > fbb.ZMin and fbb.ZMax == bb.ZMax: # vertical face, full cut - obj.FinalDepth = fbb.ZMin - elif fbb.ZMax > fbb.ZMin and fbb.ZMin > bb.ZMin: # internal vertical wall - obj.FinalDepth = fbb.ZMin - elif fbb.ZMax == fbb.ZMin and fbb.ZMax > bb.ZMin: # face/shelf - obj.FinalDepth = fbb.ZMin - else: # catch all - obj.FinalDepth = bb.ZMin - - if bb.XLength == fbb.XLength and bb.YLength == fbb.YLength: - obj.Side = "Outside" - else: - obj.Side = "Inside" - - except Exception as e: - PathLog.error(translate("PathPocket", "Error in calculating depths: %s" % e)) - obj.StartDepth = 5.0 - obj.ClearanceHeight = 10.0 - obj.SafeHeight = 8.0 - obj.Side = "Outside" - def opFeatures(self, obj): return PathAreaOp.FeatureTool | PathAreaOp.FeatureDepths | PathAreaOp.FeatureHeights | PathAreaOp.FeatureStartPoint | PathAreaOp.FeatureBaseFaces def opUseProjection(self, obj): return True - def opShapeForDepths(self, obj): - job = PathUtils.findParentJob(obj) - if job and job.Base: - PathLog.debug("job=%s base=%s shape=%s" % (job, job.Base, job.Base.Shape)) - return job.Base.Shape - PathLog.warning("No job object found (%s), or job has no Base." % job) - return None - def opAreaParams(self, obj, isHole): params = {} params['Fill'] = 0 diff --git a/src/Mod/Path/PathScripts/PathProfileGui.py b/src/Mod/Path/PathScripts/PathProfileFacesGui.py similarity index 98% rename from src/Mod/Path/PathScripts/PathProfileGui.py rename to src/Mod/Path/PathScripts/PathProfileFacesGui.py index 2d0d7b98da..9c3ea19bb5 100644 --- a/src/Mod/Path/PathScripts/PathProfileGui.py +++ b/src/Mod/Path/PathScripts/PathProfileFacesGui.py @@ -27,7 +27,7 @@ import FreeCADGui import Path import PathScripts.PathAreaOpGui as PathAreaOpGui import PathScripts.PathLog as PathLog -import PathScripts.PathProfile as PathProfile +import PathScripts.PathProfileFaces as PathProfileFaces import PathScripts.PathSelection as PathSelection from PathScripts import PathUtils @@ -79,7 +79,7 @@ class TaskPanelOpPage(PathAreaOpGui.TaskPanelPage): return signals PathAreaOpGui.SetupOperation('Profile', - PathProfile.Create, + PathProfileFaces.Create, TaskPanelOpPage, 'Path-Profile', QtCore.QT_TRANSLATE_NOOP("PathProfile", "Face Profile"),