From e0cae49c4961dc643df2ef9abbdc55a7095bfcfb Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Fri, 17 Aug 2018 20:57:52 -0700 Subject: [PATCH] Add UseOutline property to PocketShape in order to mill full pockets and not have to add all sub-shapes. --- .../Resources/panels/PageOpPocketFullEdit.ui | 31 ++++++++++--------- src/Mod/Path/PathScripts/PathOp.py | 7 +++++ src/Mod/Path/PathScripts/PathPocketBase.py | 2 +- src/Mod/Path/PathScripts/PathPocketBaseGui.py | 25 +++++++++------ src/Mod/Path/PathScripts/PathPocketShape.py | 18 +++++++++-- .../Path/PathScripts/PathPocketShapeGui.py | 2 +- 6 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/Mod/Path/Gui/Resources/panels/PageOpPocketFullEdit.ui b/src/Mod/Path/Gui/Resources/panels/PageOpPocketFullEdit.ui index 2ba652d231..d2048c522d 100644 --- a/src/Mod/Path/Gui/Resources/panels/PageOpPocketFullEdit.ui +++ b/src/Mod/Path/Gui/Resources/panels/PageOpPocketFullEdit.ui @@ -214,6 +214,23 @@ + + + + Min Travel + + + + + + + <html><head/><body><p>If selected the operation uses the outline of the selected base geometry and ignores all holes and islands.</p></body></html> + + + Use Outline + + + @@ -224,20 +241,6 @@ - - - - Keep tool down - - - - - - - Min Travel - - - diff --git a/src/Mod/Path/PathScripts/PathOp.py b/src/Mod/Path/PathScripts/PathOp.py index b3077228c1..4d768c8aab 100644 --- a/src/Mod/Path/PathScripts/PathOp.py +++ b/src/Mod/Path/PathScripts/PathOp.py @@ -177,6 +177,8 @@ class ObjectOp(object): if FeatureNoFinalDepth & features: obj.setEditorMode('OpFinalDepth', 2) + self.opOnDocumentRestored(obj) + def __getstate__(self): '''__getstat__(self) ... called when receiver is saved. Can safely be overwritten by subclasses.''' @@ -198,6 +200,11 @@ class ObjectOp(object): Should be overwritten by subclasses.''' pass + def opOnDocumentRestored(self, obj): + '''opOnDocumentRestored(obj) ... implement if an op needs special handling like migrating the data model. + Should be overwritten by subclasses.''' + pass + def opOnChanged(self, obj, prop): '''opOnChanged(obj, prop) ... overwrite to process property changes. This is a callback function that is invoked each time a property of the diff --git a/src/Mod/Path/PathScripts/PathPocketBase.py b/src/Mod/Path/PathScripts/PathPocketBase.py index 94e3dc763d..ec5e15999d 100644 --- a/src/Mod/Path/PathScripts/PathPocketBase.py +++ b/src/Mod/Path/PathScripts/PathPocketBase.py @@ -79,7 +79,7 @@ class ObjectPocket(PathAreaOp.ObjectOp): obj.addProperty("App::PropertyEnumeration", "OffsetPattern", "Face", QtCore.QT_TRANSLATE_NOOP("App::Property", "Clearing pattern to use")) obj.OffsetPattern = ['ZigZag', 'Offset', 'Spiral', 'ZigZagOffset', 'Line', 'Grid', 'Triangle'] obj.addProperty("App::PropertyBool", "MinTravel", "Pocket", QtCore.QT_TRANSLATE_NOOP("App::Property", "Use 3D Sorting of Path")) - obj.addProperty("App::PropertyBool", "KeepToolDown", "Face", QtCore.QT_TRANSLATE_NOOP("App::Property", "Attempts to avoid unnecessary retractions.")) + obj.addProperty("App::PropertyBool", "KeepToolDown", "Pocket", QtCore.QT_TRANSLATE_NOOP("App::Property", "Attempts to avoid unnecessary retractions.")) self.initPocketOp(obj) diff --git a/src/Mod/Path/PathScripts/PathPocketBaseGui.py b/src/Mod/Path/PathScripts/PathPocketBaseGui.py index 4c5118a93c..8e1615aa34 100644 --- a/src/Mod/Path/PathScripts/PathPocketBaseGui.py +++ b/src/Mod/Path/PathScripts/PathPocketBaseGui.py @@ -40,20 +40,22 @@ __doc__ = "Base page controller and command implementation for path pocket opera def translate(context, text, disambig=None): return QtCore.QCoreApplication.translate(context, text, disambig) -FeaturePocket = 0x01 -FeatureFacing = 0x02 +FeaturePocket = 0x01 +FeatureFacing = 0x02 +FeatureOutline = 0x04 class TaskPanelOpPage(PathOpGui.TaskPanelPage): - '''Page controller class for pocket operations, supports two different features: + '''Page controller class for pocket operations, supports: FeaturePocket ... used for pocketing operation FeatureFacing ... used for face milling operation + FeatureOutline ... used for pocket-shape operation ''' def pocketFeatures(self): '''pocketFeatures() ... return which features of the UI are supported by the operation. - Typically one of the following is enabled: FeaturePocket ... used for pocketing operation FeatureFacing ... used for face milling operation + FeatureOutline ... used for pocket-shape operation Must be overwritten by subclasses''' pass @@ -68,9 +70,11 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage): form.extraOffsetLabel.setText(translate("PathPocket", "Pass Extension")) form.extraOffset.setToolTip(translate("PathPocket", "The distance the facing operation will extend beyond the boundary shape.")) + if not (FeatureOutline & self.pocketFeatures()): + form.useOutline.hide() + if True: # currently doesn't have an effect or is experimental - form.keepToolDown.hide() form.minTravel.hide() return form @@ -109,8 +113,10 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage): if obj.UseStartPoint != self.form.useStartPoint.isChecked(): obj.UseStartPoint = self.form.useStartPoint.isChecked() - if obj.KeepToolDown != self.form.keepToolDown.isChecked(): - obj.KeepToolDown = self.form.keepToolDown.isChecked() + + if FeatureOutline & self.pocketFeatures(): + if obj.UseOutline != self.form.useOutline.isChecked(): + obj.UseOutline = self.form.useOutline.isChecked() self.updateMinTravel(obj) @@ -123,7 +129,8 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage): self.form.stepOverPercent.setValue(obj.StepOver) self.form.extraOffset.setText(FreeCAD.Units.Quantity(obj.ExtraOffset.Value, FreeCAD.Units.Length).UserString) self.form.useStartPoint.setChecked(obj.UseStartPoint) - self.form.keepToolDown.setChecked(obj.KeepToolDown) + if FeatureOutline & self.pocketFeatures(): + self.form.useOutline.setChecked(obj.UseOutline) self.form.zigZagAngle.setText(FreeCAD.Units.Quantity(obj.ZigZagAngle, FreeCAD.Units.Angle).UserString) self.updateZigZagAngle(obj, False) @@ -149,7 +156,7 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage): signals.append(self.form.toolController.currentIndexChanged) signals.append(self.form.extraOffset.editingFinished) signals.append(self.form.useStartPoint.clicked) - signals.append(self.form.keepToolDown.clicked) + signals.append(self.form.useOutline.clicked) signals.append(self.form.minTravel.clicked) if FeatureFacing & self.pocketFeatures(): diff --git a/src/Mod/Path/PathScripts/PathPocketShape.py b/src/Mod/Path/PathScripts/PathPocketShape.py index 5a8efb0a65..a5604489fb 100644 --- a/src/Mod/Path/PathScripts/PathPocketShape.py +++ b/src/Mod/Path/PathScripts/PathPocketShape.py @@ -55,7 +55,13 @@ class ObjectPocket(PathPocketBase.ObjectPocket): def initPocketOp(self, obj): '''initPocketOp(obj) ... setup receiver''' - pass + obj.addProperty("App::PropertyBool", "UseOutline", "Pocket", QtCore.QT_TRANSLATE_NOOP("App::Property", "Uses the outline of the base geometry.")) + obj.UseOutline = False + + def opOnDocumentRestored(self, obj): + '''opOnDocumentRestored(obj) ... adds the UseOutline property if it doesn't exist.''' + if not hasattr(obj, 'UseOutline'): + self.initPocketOp(obj) def pocketInvertExtraOffset(self): return False @@ -110,10 +116,16 @@ class ObjectPocket(PathPocketBase.ObjectPocket): f.translate(FreeCAD.Vector(0, 0, obj.FinalDepth.Value - f.BoundBox.ZMin)) # check all faces and see if they are touching/overlapping and combine those into a compound - self.horizontal = PathGeom.combineConnectedShapes(self.horiz) - for shape in self.horizontal: + self.horizontal = [] + for shape in PathGeom.combineConnectedShapes(self.horiz): shape.sewShape() shape.tessellate(0.1) + if obj.UseOutline: + wire = TechDraw.findShapeOutline(shape, 1, FreeCAD.Vector(0, 0, 1)) + wire.translate(FreeCAD.Vector(0, 0, obj.FinalDepth.Value - wire.BoundBox.ZMin)) + self.horizontal.append(Part.Face(wire)) + else: + self.horizontal.append(shape) # extrude all faces up to StartDepth and those are the removal shapes extent = FreeCAD.Vector(0, 0, obj.StartDepth.Value - obj.FinalDepth.Value) diff --git a/src/Mod/Path/PathScripts/PathPocketShapeGui.py b/src/Mod/Path/PathScripts/PathPocketShapeGui.py index 53093921ff..c49cb99625 100644 --- a/src/Mod/Path/PathScripts/PathPocketShapeGui.py +++ b/src/Mod/Path/PathScripts/PathPocketShapeGui.py @@ -39,7 +39,7 @@ class TaskPanelOpPage(PathPocketBaseGui.TaskPanelOpPage): def pocketFeatures(self): '''pocketFeatures() ... return FeaturePocket (see PathPocketBaseGui)''' - return PathPocketBaseGui.FeaturePocket + return PathPocketBaseGui.FeaturePocket | PathPocketBaseGui.FeatureOutline Command = PathOpGui.SetupOperation('Pocket Shape', PathPocketShape.Create,