addressed pylint warnings for PathPocket family

This commit is contained in:
Markus Lampert
2019-06-29 22:52:53 -07:00
parent 3098d75073
commit 7abb496144
3 changed files with 43 additions and 36 deletions

View File

@@ -53,6 +53,7 @@ class ObjectPocket(PathAreaOp.ObjectOp):
return PathOp.FeatureBaseFaces | PathOp.FeatureFinishDepth | self.pocketOpFeatures(obj)
def pocketOpFeatures(self, obj):
# pylint: disable=unused-argument
return 0
def initPocketOp(self, obj):

View File

@@ -21,6 +21,15 @@
# * USA *
# * *
# ***************************************************************************
# * *
# * Additional modifications and contributions beginning 2019 *
# * Focus: 4th-axis integration *
# * by Russell Johnson <russ4262@gmail.com> *
# * *
# ***************************************************************************
# SCRIPT NOTES:
# - Need test models for testing vertical faces scenarios.
import FreeCAD
import Part
@@ -51,7 +60,6 @@ if LOGLEVEL:
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
@@ -362,7 +370,8 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
if obj.Base:
PathLog.debug('Processing... obj.Base')
self.removalshapes = []
self.removalshapes = [] # pylint: disable=attribute-defined-outside-init
# ----------------------------------------------------------------------
if obj.EnableRotation == 'Off':
stock = PathUtils.findParentJob(obj).Stock
for (base, subList) in obj.Base:
@@ -379,7 +388,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
PathLog.info("Common Surface.Axis or normalAt() value found for loop faces.")
rtn = False
subCount += 1
(rtn, angle, axis, praInfo) = self.faceRotationAnalysis(obj, norm, surf)
(rtn, angle, axis, praInfo) = self.faceRotationAnalysis(obj, norm, surf) # pylint: disable=unused-variable
PathLog.info("angle: {}; axis: {}".format(angle, axis))
if rtn is True:
@@ -420,7 +429,6 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
for sub in subsList:
subCount += 1
if 'Face' in sub:
PathLog.debug(translate('Path', "Base Geometry sub: {}".format(sub)))
rtn = False
face = base.Shape.getElement(sub)
if type(face.Surface) == Part.SurfaceOfExtrusion:
@@ -437,7 +445,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
PathLog.error(translate("Path", "Failed to create a planar face from edges in {}.".format(sub)))
(norm, surf) = self.getFaceNormAndSurf(face)
(rtn, angle, axis, praInfo) = self.faceRotationAnalysis(obj, norm, surf)
(rtn, angle, axis, praInfo) = self.faceRotationAnalysis(obj, norm, surf) # pylint: disable=unused-variable
if rtn is True:
faceNum = sub.replace('Face', '')
@@ -445,7 +453,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
# Verify faces are correctly oriented - InverseAngle might be necessary
faceIA = clnBase.Shape.getElement(sub)
(norm, surf) = self.getFaceNormAndSurf(faceIA)
(rtn, praAngle, praAxis, praInfo) = self.faceRotationAnalysis(obj, norm, surf)
(rtn, praAngle, praAxis, praInfo) = self.faceRotationAnalysis(obj, norm, surf) # pylint: disable=unused-variable
if rtn is True:
PathLog.debug("Face not aligned after initial rotation.")
if obj.AttemptInverseAngle is True and obj.InverseAngle is False:
@@ -471,8 +479,8 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
PathLog.error(translate('Path', "Selected feature is not a Face. Ignoring: {}".format(ignoreSub)))
for o in baseSubsTuples:
self.horiz = []
self.vert = []
self.horiz = [] # pylint: disable=attribute-defined-outside-init
self.vert = [] # pylint: disable=attribute-defined-outside-init
subBase = o[0]
subsList = o[1]
angle = o[2]
@@ -494,8 +502,8 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
if vFace.BoundBox.ZMin > vFinDep:
vFinDep = vFace.BoundBox.ZMin
# Determine if vertical faces for a loop: Extract planar loop wire as new horizontal face.
self.vertical = PathGeom.combineConnectedShapes(self.vert)
self.vWires = [TechDraw.findShapeOutline(shape, 1, FreeCAD.Vector(0, 0, 1)) for shape in self.vertical]
self.vertical = PathGeom.combineConnectedShapes(self.vert) # pylint: disable=attribute-defined-outside-init
self.vWires = [TechDraw.findShapeOutline(shape, 1, FreeCAD.Vector(0, 0, 1)) for shape in self.vertical] # pylint: disable=attribute-defined-outside-init
for wire in self.vWires:
w = PathGeom.removeDuplicateEdges(wire)
face = Part.Face(w)
@@ -528,7 +536,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
f.translate(FreeCAD.Vector(0, 0, finDep - f.BoundBox.ZMin))
# check all faces and see if they are touching/overlapping and combine those into a compound
self.horizontal = []
self.horizontal = [] # pylint: disable=attribute-defined-outside-init
for shape in PathGeom.combineConnectedShapes(self.horiz):
shape.sewShape()
# shape.tessellate(0.1)
@@ -558,18 +566,18 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
PathLog.debug(translate("Path", 'Processing model as a whole ...'))
finDep = obj.FinalDepth.Value
strDep = obj.StartDepth.Value
self.outlines = [Part.Face(TechDraw.findShapeOutline(base.Shape, 1, FreeCAD.Vector(0, 0, 1))) for base in self.model]
self.outlines = [Part.Face(TechDraw.findShapeOutline(base.Shape, 1, FreeCAD.Vector(0, 0, 1))) for base in self.model] # pylint: disable=attribute-defined-outside-init
stockBB = self.stock.Shape.BoundBox
self.removalshapes = []
self.bodies = []
self.removalshapes = [] # pylint: disable=attribute-defined-outside-init
self.bodies = [] # pylint: disable=attribute-defined-outside-init
for outline in self.outlines:
outline.translate(FreeCAD.Vector(0, 0, stockBB.ZMin - 1))
body = outline.extrude(FreeCAD.Vector(0, 0, stockBB.ZLength + 2))
self.bodies.append(body)
self.removalshapes.append((self.stock.Shape.cut(body), False, 'pathPocketShape', 0.0, 'X', strDep, finDep))
for (shape, hole, sub, angle, axis, strDep, finDep) in self.removalshapes:
for (shape, hole, sub, angle, axis, strDep, finDep) in self.removalshapes: # pylint: disable=unused-variable
shape.tessellate(0.05) # originally 0.1
if self.removalshapes:
@@ -682,7 +690,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
if PathGeom.isRoughly(0, saSum.y):
if PathGeom.isRoughly(0, saSum.z):
PathLog.debug("Combined subs suggest loop of faces. Checking ...")
go is True
go = True
if go is True:
lastExtrusion = None
@@ -717,7 +725,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
rnded = FreeCAD.Vector(roundValue(precision, raw.x), roundValue(precision, raw.y), roundValue(precision, raw.z))
if rnded.x == 0.0 or rnded.y == 0.0 or rnded.z == 0.0:
for fc2 in tmpExt.Shape.Faces:
(norm2, raw2) = self.getFaceNormAndSurf(fc2)
(norm2, raw2) = self.getFaceNormAndSurf(fc2) # pylint: disable=unused-variable
rnded2 = FreeCAD.Vector(roundValue(precision, raw2.x), roundValue(precision, raw2.y), roundValue(precision, raw2.z))
if rnded == rnded2:
matchList.append(fc2)
@@ -778,7 +786,7 @@ def SetupProperties():
return setup
def Create(name, obj = None):
def Create(name, obj=None):
'''Create(name) ... Creates and returns a Pocket operation.'''
if obj is None:
obj = FreeCAD.ActiveDocument.addObject('Path::FeaturePython', name)

View File

@@ -139,8 +139,6 @@ class _Extension(object):
def deselect(self):
self.material.transparency = self.TransparencyDeselected
Page = None
class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
DataObject = QtCore.Qt.ItemDataRole.UserRole
DataSwitch = QtCore.Qt.ItemDataRole.UserRole + 2
@@ -153,18 +151,18 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
def initPage(self, obj):
self.setTitle("Extensions")
self.extensions = obj.Proxy.getExtensions(obj)
self.extensions = obj.Proxy.getExtensions(obj) # pylint: disable=attribute-defined-outside-init
self.defaultLength = PathGui.QuantitySpinBox(self.form.defaultLength, obj, 'ExtensionLengthDefault')
self.defaultLength = PathGui.QuantitySpinBox(self.form.defaultLength, obj, 'ExtensionLengthDefault') # pylint: disable=attribute-defined-outside-init
self.form.extensionTree.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
self.form.extensionTree.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.switch = coin.SoSwitch()
self.switch = coin.SoSwitch() # pylint: disable=attribute-defined-outside-init
self.obj.ViewObject.RootNode.addChild(self.switch)
self.switch.whichChild = coin.SO_SWITCH_ALL
self.model = QtGui.QStandardItemModel(self.form.extensionTree)
self.model = QtGui.QStandardItemModel(self.form.extensionTree) # pylint: disable=attribute-defined-outside-init
self.model.setHorizontalHeaderLabels(['Base', 'Extension'])
if 0 < len(obj.ExtensionFeature):
@@ -174,9 +172,6 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
self.blockUpdateData = False
global Page
Page = self
def cleanupPage(self, obj):
# If the object was already destroyed we can't access obj.Name.
# This is the case if this was a new op and the user hit Cancel.
@@ -196,7 +191,7 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
for modelRow in range(self.model.rowCount()):
model = self.model.item(modelRow, 0)
for featureRow in range(model.rowCount()):
feature = model.child(featureRow, 0);
feature = model.child(featureRow, 0)
for edgeRow in range(feature.rowCount()):
item = feature.child(edgeRow, 0)
ext = item.data(self.DataObject)
@@ -232,7 +227,7 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
if obj.ExtensionCorners != self.form.extendCorners.isChecked():
self.form.extendCorners.toggle()
self.defaultLength.updateSpinBox()
self.extensions = obj.Proxy.getExtensions(obj)
self.extensions = obj.Proxy.getExtensions(obj) # pylint: disable=attribute-defined-outside-init
self.setExtensions(self.extensions)
def createItemForBaseModel(self, base, sub, edges, extensions):
@@ -273,13 +268,13 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
def edgesMatchShape(e0, e1):
return PathGeom.edgesMatch(e0, e1) or PathGeom.edgesMatch(e0, PathGeom.flipEdge(e1))
self.extensionEdges = extensionEdges
self.extensionEdges = extensionEdges # pylint: disable=attribute-defined-outside-init
for edgeList in Part.sortEdges(list(extensionEdges.keys())):
self.edgeList = edgeList
self.edgeList = edgeList # pylint: disable=attribute-defined-outside-init
if len(edgeList) == 1:
label = "Edge%s" % [extensionEdges[keyEdge] for keyEdge in extensionEdges.keys() if edgesMatchShape(keyEdge, edgeList[0])][0]
else:
label = "Wire(%s)" % ','.join(sorted([extensionEdges[keyEdge] for e in edgeList for keyEdge in extensionEdges.keys() if edgesMatchShape(e, keyEdge)], key=lambda s: int(s)))
label = "Wire(%s)" % ','.join(sorted([extensionEdges[keyEdge] for e in edgeList for keyEdge in extensionEdges.keys() if edgesMatchShape(e, keyEdge)], key=lambda s: int(s))) # pylint: disable=unnecessary-lambda
ext0 = _Extension(self.obj, base, sub, label)
createSubItem(label, ext0)
@@ -302,12 +297,13 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
if not self.form.extensionTree.isExpanded(model.index()):
collapsedModels.append(modelName)
for featureRow in range(model.rowCount()):
feature = model.child(featureRow, 0);
feature = model.child(featureRow, 0)
if not self.form.extensionTree.isExpanded(feature.index()):
collapsedFeatures.append("%s.%s" % (modelName, feature.data(QtCore.Qt.EditRole)))
# remove current extensions and all their visuals
def removeItemSwitch(item, ext):
# pylint: disable=unused-argument
ext.hide()
self.switch.removeChild(ext.root)
self.forAllItemsCall(removeItemSwitch)
@@ -334,7 +330,7 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
if modelName in collapsedModels:
self.form.extensionTree.setExpanded(model.index(), False)
for featureRow in range(model.rowCount()):
feature = model.child(featureRow, 0);
feature = model.child(featureRow, 0)
featureName = "%s.%s" % (modelName, feature.data(QtCore.Qt.EditRole))
if featureName in collapsedFeatures:
self.form.extensionTree.setExpanded(feature.index(), False)
@@ -369,6 +365,7 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
FreeCADGui.Selection.clearSelection()
def selectItem(item, ext):
# pylint: disable=unused-argument
for sel in selection:
if ext.base == sel.obj and ext.edge == sel.sub:
return True
@@ -431,6 +428,7 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
def showHideExtension(self):
if self.form.showExtensions.isChecked():
def enableExtensionEdit(item, ext):
# pylint: disable=unused-argument
ext.show()
self.forAllItemsCall(enableExtensionEdit)
else:
@@ -461,7 +459,7 @@ class TaskPanelExtensionPage(PathOpGui.TaskPanelPage):
self.model.itemChanged.connect(self.updateItemEnabled)
self.selectionModel = self.form.extensionTree.selectionModel()
self.selectionModel = self.form.extensionTree.selectionModel() # pylint: disable=attribute-defined-outside-init
self.selectionModel.selectionChanged.connect(self.selectionChanged)
self.selectionChanged()
@@ -474,7 +472,7 @@ class TaskPanelOpPage(PathPocketBaseGui.TaskPanelOpPage):
def taskPanelBaseLocationPage(self, obj, features):
if not hasattr(self, 'extensionsPanel'):
self.extensionsPanel = TaskPanelExtensionPage(obj, features)
self.extensionsPanel = TaskPanelExtensionPage(obj, features) # pylint: disable=attribute-defined-outside-init
return self.extensionsPanel
def pageRegisterSignalHandlers(self):