From de6045ed2872695e6ffb914b5eb942a73fa7284f Mon Sep 17 00:00:00 2001 From: sliptonic Date: Fri, 21 Jan 2022 17:17:50 -0600 Subject: [PATCH] Black --- src/Mod/Path/PathScripts/PathPocketBase.py | 170 +++++++++++++----- src/Mod/Path/PathScripts/PathPocketBaseGui.py | 60 ++++--- 2 files changed, 158 insertions(+), 72 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathPocketBase.py b/src/Mod/Path/PathScripts/PathPocketBase.py index 9563470a25..7fec82667c 100644 --- a/src/Mod/Path/PathScripts/PathPocketBase.py +++ b/src/Mod/Path/PathScripts/PathPocketBase.py @@ -42,44 +42,108 @@ def translate(context, text, disambig=None): class ObjectPocket(PathAreaOp.ObjectOp): - '''Base class for proxy objects of all pocket operations.''' + """Base class for proxy objects of all pocket operations.""" def areaOpFeatures(self, obj): - '''areaOpFeatures(obj) ... Pockets have a FinishDepth and work on Faces''' - return PathOp.FeatureBaseFaces | PathOp.FeatureFinishDepth | self.pocketOpFeatures(obj) + """areaOpFeatures(obj) ... Pockets have a FinishDepth and work on Faces""" + return ( + PathOp.FeatureBaseFaces + | PathOp.FeatureFinishDepth + | self.pocketOpFeatures(obj) + ) def pocketOpFeatures(self, obj): # pylint: disable=unused-argument return 0 def initPocketOp(self, obj): - '''initPocketOp(obj) ... overwrite to initialize subclass. - Can safely be overwritten by subclass.''' - pass # pylint: disable=unnecessary-pass + """initPocketOp(obj) ... overwrite to initialize subclass. + Can safely be overwritten by subclass.""" + pass # pylint: disable=unnecessary-pass def pocketInvertExtraOffset(self): - '''pocketInvertExtraOffset() ... return True if ExtraOffset's direction is inward. - Can safely be overwritten by subclass.''' + """pocketInvertExtraOffset() ... return True if ExtraOffset's direction is inward. + Can safely be overwritten by subclass.""" return False def initAreaOp(self, obj): - '''initAreaOp(obj) ... create pocket specific properties. - Do not overwrite, implement initPocketOp(obj) instead.''' + """initAreaOp(obj) ... create pocket specific properties. + Do not overwrite, implement initPocketOp(obj) instead.""" PathLog.track() # Pocket Properties - obj.addProperty("App::PropertyEnumeration", "CutMode", "Pocket", QtCore.QT_TRANSLATE_NOOP("App::Property", "The direction that the toolpath should go around the part ClockWise (CW) or CounterClockWise (CCW)")) - obj.addProperty("App::PropertyDistance", "ExtraOffset", "Pocket", QtCore.QT_TRANSLATE_NOOP("App::Property", "Extra offset to apply to the operation. Direction is operation dependent.")) - obj.addProperty("App::PropertyEnumeration", "StartAt", "Pocket", QtCore.QT_TRANSLATE_NOOP("App::Property", "Start pocketing at center or boundary")) - obj.addProperty("App::PropertyPercent", "StepOver", "Pocket", QtCore.QT_TRANSLATE_NOOP("App::Property", "Percent of cutter diameter to step over on each pass")) - obj.addProperty("App::PropertyFloat", "ZigZagAngle", "Pocket", QtCore.QT_TRANSLATE_NOOP("App::Property", "Angle of the zigzag pattern")) - obj.addProperty("App::PropertyEnumeration", "OffsetPattern", "Face", QtCore.QT_TRANSLATE_NOOP("App::Property", "Clearing pattern to use")) - obj.addProperty("App::PropertyBool", "MinTravel", "Pocket", QtCore.QT_TRANSLATE_NOOP("App::Property", "Use 3D Sorting of Path")) - obj.addProperty("App::PropertyBool", "KeepToolDown", "Pocket", QtCore.QT_TRANSLATE_NOOP("App::Property", "Attempts to avoid unnecessary retractions.")) + obj.addProperty( + "App::PropertyEnumeration", + "CutMode", + "Pocket", + QtCore.QT_TRANSLATE_NOOP( + "App::Property", + "The direction that the toolpath should go around the part ClockWise (CW) or CounterClockWise (CCW)", + ), + ) + obj.addProperty( + "App::PropertyDistance", + "ExtraOffset", + "Pocket", + QtCore.QT_TRANSLATE_NOOP( + "App::Property", + "Extra offset to apply to the operation. Direction is operation dependent.", + ), + ) + obj.addProperty( + "App::PropertyEnumeration", + "StartAt", + "Pocket", + QtCore.QT_TRANSLATE_NOOP( + "App::Property", "Start pocketing at center or boundary" + ), + ) + obj.addProperty( + "App::PropertyPercent", + "StepOver", + "Pocket", + QtCore.QT_TRANSLATE_NOOP( + "App::Property", "Percent of cutter diameter to step over on each pass" + ), + ) + obj.addProperty( + "App::PropertyFloat", + "ZigZagAngle", + "Pocket", + QtCore.QT_TRANSLATE_NOOP("App::Property", "Angle of the zigzag pattern"), + ) + obj.addProperty( + "App::PropertyEnumeration", + "OffsetPattern", + "Face", + QtCore.QT_TRANSLATE_NOOP("App::Property", "Clearing pattern to use"), + ) + obj.addProperty( + "App::PropertyBool", + "MinTravel", + "Pocket", + QtCore.QT_TRANSLATE_NOOP("App::Property", "Use 3D Sorting of Path"), + ) + obj.addProperty( + "App::PropertyBool", + "KeepToolDown", + "Pocket", + QtCore.QT_TRANSLATE_NOOP( + "App::Property", "Attempts to avoid unnecessary retractions." + ), + ) - obj.CutMode = ['Climb', 'Conventional'] - obj.StartAt = ['Center', 'Edge'] - obj.OffsetPattern = ['ZigZag', 'Offset', 'Spiral', 'ZigZagOffset', 'Line', 'Grid', 'Triangle'] + obj.CutMode = ["Climb", "Conventional"] + obj.StartAt = ["Center", "Edge"] + obj.OffsetPattern = [ + "ZigZag", + "Offset", + "Spiral", + "ZigZagOffset", + "Line", + "Grid", + "Triangle", + ] self.initPocketOp(obj) @@ -88,40 +152,48 @@ class ObjectPocket(PathAreaOp.ObjectOp): return not obj.KeepToolDown def areaOpUseProjection(self, obj): - '''areaOpUseProjection(obj) ... return False''' + """areaOpUseProjection(obj) ... return False""" return False def areaOpAreaParams(self, obj, isHole): - '''areaOpAreaParams(obj, isHole) ... return dictionary with pocket's area parameters''' + """areaOpAreaParams(obj, isHole) ... return dictionary with pocket's area parameters""" params = {} - params['Fill'] = 0 - params['Coplanar'] = 0 - params['PocketMode'] = 1 - params['SectionCount'] = -1 - params['Angle'] = obj.ZigZagAngle - params['FromCenter'] = (obj.StartAt == "Center") - params['PocketStepover'] = (self.radius * 2) * (float(obj.StepOver)/100) + params["Fill"] = 0 + params["Coplanar"] = 0 + params["PocketMode"] = 1 + params["SectionCount"] = -1 + params["Angle"] = obj.ZigZagAngle + params["FromCenter"] = obj.StartAt == "Center" + params["PocketStepover"] = (self.radius * 2) * (float(obj.StepOver) / 100) extraOffset = obj.ExtraOffset.Value if self.pocketInvertExtraOffset(): extraOffset = 0 - extraOffset - params['PocketExtraOffset'] = extraOffset - params['ToolRadius'] = self.radius + params["PocketExtraOffset"] = extraOffset + params["ToolRadius"] = self.radius - Pattern = ['ZigZag', 'Offset', 'Spiral', 'ZigZagOffset', 'Line', 'Grid', 'Triangle'] - params['PocketMode'] = Pattern.index(obj.OffsetPattern) + 1 + Pattern = [ + "ZigZag", + "Offset", + "Spiral", + "ZigZagOffset", + "Line", + "Grid", + "Triangle", + ] + params["PocketMode"] = Pattern.index(obj.OffsetPattern) + 1 if obj.SplitArcs: - params['Explode'] = True - params['FitArcs'] = False + params["Explode"] = True + params["FitArcs"] = False return params def areaOpPathParams(self, obj, isHole): - '''areaOpAreaParams(obj, isHole) ... return dictionary with pocket's path parameters''' + """areaOpAreaParams(obj, isHole) ... return dictionary with pocket's path parameters""" params = {} - CutMode = ['Conventional', 'Climb'] - params['orientation'] = CutMode.index(obj.CutMode) + CutMode = ["Conventional", "Climb"] + params["orientation"] = CutMode.index(obj.CutMode) # if MinTravel is turned on, set path sorting to 3DSort # 3DSort shouldn't be used without a valid start point. Can cause @@ -133,19 +205,19 @@ class ObjectPocket(PathAreaOp.ObjectOp): # any problem # if obj.MinTravel and obj.UseStartPoint and obj.StartPoint is not None: - params['sort_mode'] = 3 - params['threshold'] = self.radius * 2 + params["sort_mode"] = 3 + params["threshold"] = self.radius * 2 return params def SetupProperties(): setup = PathAreaOp.SetupProperties() - setup.append('CutMode') - setup.append('ExtraOffset') - setup.append('StepOver') - setup.append('ZigZagAngle') - setup.append('OffsetPattern') - setup.append('StartAt') - setup.append('MinTravel') - setup.append('KeepToolDown') + setup.append("CutMode") + setup.append("ExtraOffset") + setup.append("StepOver") + setup.append("ZigZagAngle") + setup.append("OffsetPattern") + setup.append("StartAt") + setup.append("MinTravel") + setup.append("KeepToolDown") return setup diff --git a/src/Mod/Path/PathScripts/PathPocketBaseGui.py b/src/Mod/Path/PathScripts/PathPocketBaseGui.py index abb39c5f26..386f9087c8 100644 --- a/src/Mod/Path/PathScripts/PathPocketBaseGui.py +++ b/src/Mod/Path/PathScripts/PathPocketBaseGui.py @@ -22,41 +22,44 @@ import FreeCAD import FreeCADGui -import PathGui as PGui # ensure Path/Gui/Resources are loaded +import PathGui as PGui # ensure Path/Gui/Resources are loaded import PathScripts.PathGui as PathGui import PathScripts.PathOpGui as PathOpGui -from PySide import QtCore #, QtGui +from PySide import QtCore # , QtGui __title__ = "Path Pocket Base Operation UI" __author__ = "sliptonic (Brad Collette)" __url__ = "https://www.freecadweb.org" __doc__ = "Base page controller and command implementation for path pocket operations." + def translate(context, text, disambig=None): return QtCore.QCoreApplication.translate(context, text, disambig) -FeaturePocket = 0x01 -FeatureFacing = 0x02 -FeatureOutline = 0x04 + +FeaturePocket = 0x01 +FeatureFacing = 0x02 +FeatureOutline = 0x04 + class TaskPanelOpPage(PathOpGui.TaskPanelPage): - '''Page controller class for pocket operations, supports: - FeaturePocket ... used for pocketing operation - FeatureFacing ... used for face milling operation - FeatureOutline ... used for pocket-shape operation - ''' + """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. + """pocketFeatures() ... return which features of the UI are supported by the operation. FeaturePocket ... used for pocketing operation FeatureFacing ... used for face milling operation FeatureOutline ... used for pocket-shape operation - Must be overwritten by subclasses''' - pass # pylint: disable=unnecessary-pass + Must be overwritten by subclasses""" + pass # pylint: disable=unnecessary-pass def getForm(self): - '''getForm() ... returns UI, adapted to the results from pocketFeatures()''' + """getForm() ... returns UI, adapted to the results from pocketFeatures()""" form = FreeCADGui.PySideUic.loadUi(":/panels/PageOpPocketFullEdit.ui") if not FeatureFacing & self.pocketFeatures(): @@ -65,7 +68,12 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage): if FeaturePocket & self.pocketFeatures(): form.extraOffset_label.setText(translate("PathPocket", "Pass Extension")) - form.extraOffset.setToolTip(translate("PathPocket", "The distance the facing operation will extend beyond the boundary shape.")) + form.extraOffset.setToolTip( + translate( + "PathPocket", + "The distance the facing operation will extend beyond the boundary shape.", + ) + ) if not (FeatureOutline & self.pocketFeatures()): form.useOutline.hide() @@ -87,16 +95,16 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage): obj.MinTravel = self.form.minTravel.isChecked() def updateZigZagAngle(self, obj, setModel=True): - if obj.OffsetPattern in ['Offset', 'Spiral']: + if obj.OffsetPattern in ["Offset", "Spiral"]: self.form.zigZagAngle.setEnabled(False) else: self.form.zigZagAngle.setEnabled(True) if setModel: - PathGui.updateInputField(obj, 'ZigZagAngle', self.form.zigZagAngle) + PathGui.updateInputField(obj, "ZigZagAngle", self.form.zigZagAngle) def getFields(self, obj): - '''getFields(obj) ... transfers values from UI to obj's proprties''' + """getFields(obj) ... transfers values from UI to obj's proprties""" if obj.CutMode != str(self.form.cutMode.currentText()): obj.CutMode = str(self.form.cutMode.currentText()) if obj.StepOver != self.form.stepOverPercent.value(): @@ -104,7 +112,7 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage): if obj.OffsetPattern != str(self.form.offsetPattern.currentText()): obj.OffsetPattern = str(self.form.offsetPattern.currentText()) - PathGui.updateInputField(obj, 'ExtraOffset', self.form.extraOffset) + PathGui.updateInputField(obj, "ExtraOffset", self.form.extraOffset) self.updateToolController(obj, self.form.toolController) self.updateCoolant(obj, self.form.coolantController) self.updateZigZagAngle(obj) @@ -125,14 +133,20 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage): obj.ClearEdges = self.form.clearEdges.isChecked() def setFields(self, obj): - '''setFields(obj) ... transfers obj's property values to UI''' + """setFields(obj) ... transfers obj's property values to UI""" self.form.stepOverPercent.setValue(obj.StepOver) - self.form.extraOffset.setText(FreeCAD.Units.Quantity(obj.ExtraOffset.Value, FreeCAD.Units.Length).UserString) + self.form.extraOffset.setText( + FreeCAD.Units.Quantity( + obj.ExtraOffset.Value, FreeCAD.Units.Length + ).UserString + ) self.form.useStartPoint.setChecked(obj.UseStartPoint) if FeatureOutline & self.pocketFeatures(): self.form.useOutline.setChecked(obj.UseOutline) - self.form.zigZagAngle.setText(FreeCAD.Units.Quantity(obj.ZigZagAngle, FreeCAD.Units.Angle).UserString) + self.form.zigZagAngle.setText( + FreeCAD.Units.Quantity(obj.ZigZagAngle, FreeCAD.Units.Angle).UserString + ) self.updateZigZagAngle(obj, False) self.form.minTravel.setChecked(obj.MinTravel) @@ -148,7 +162,7 @@ class TaskPanelOpPage(PathOpGui.TaskPanelPage): self.form.clearEdges.setChecked(obj.ClearEdges) def getSignalsForUpdate(self, obj): - '''getSignalsForUpdate(obj) ... return list of signals for updating obj''' + """getSignalsForUpdate(obj) ... return list of signals for updating obj""" signals = [] signals.append(self.form.cutMode.currentIndexChanged)