Fixed pylint warnings for PathDressupTag
This commit is contained in:
@@ -36,8 +36,6 @@ from PathScripts.PathDressupTagPreferences import HoldingTagPreferences
|
||||
from PathScripts.PathUtils import waiting_effects
|
||||
from PySide import QtCore
|
||||
|
||||
"""Holding Tags Dressup object and FreeCAD command"""
|
||||
|
||||
LOGLEVEL = False
|
||||
|
||||
if LOGLEVEL:
|
||||
@@ -100,9 +98,9 @@ def debugCone(vector, r1, r2, height, label, color=None):
|
||||
|
||||
|
||||
class Tag:
|
||||
def __init__(self, id, x, y, width, height, angle, radius, enabled=True):
|
||||
def __init__(self, nr, x, y, width, height, angle, radius, enabled=True):
|
||||
PathLog.track("%.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d" % (x, y, width, height, angle, radius, enabled))
|
||||
self.id = id
|
||||
self.nr = nr
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.width = math.fabs(width)
|
||||
@@ -113,6 +111,14 @@ class Tag:
|
||||
self.enabled = enabled
|
||||
self.isSquare = False
|
||||
|
||||
# initialized later
|
||||
self.toolRadius = None
|
||||
self.realRadius = None
|
||||
self.r1 = None
|
||||
self.r2 = None
|
||||
self.solid = None
|
||||
self.z = None
|
||||
|
||||
def fullWidth(self):
|
||||
return 2 * self.toolRadius + self.width
|
||||
|
||||
@@ -177,13 +183,13 @@ class Tag:
|
||||
def filterIntersections(self, pts, face):
|
||||
if type(face.Surface) == Part.Cone or type(face.Surface) == Part.Cylinder or type(face.Surface) == Part.Toroid:
|
||||
PathLog.track("it's a cone/cylinder, checking z")
|
||||
return list(filter(lambda pt: pt.z >= self.bottom() and pt.z <= self.top(), pts))
|
||||
return list([pt for pt in pts if pt.z >= self.bottom() and pt.z <= self.top()])
|
||||
if type(face.Surface) == Part.Plane:
|
||||
PathLog.track("it's a plane, checking R")
|
||||
c = face.Edges[0].Curve
|
||||
if (type(c) == Part.Circle):
|
||||
return list(filter(lambda pt: (pt - c.Center).Length <= c.Radius or PathGeom.isRoughly((pt - c.Center).Length, c.Radius), pts))
|
||||
print("==== we got a %s" % face.Surface)
|
||||
return list([pt for pt in pts if (pt - c.Center).Length <= c.Radius or PathGeom.isRoughly((pt - c.Center).Length, c.Radius)])
|
||||
PathLog.error("==== we got a %s" % face.Surface)
|
||||
|
||||
def isPointOnEdge(self, pt, edge):
|
||||
param = edge.Curve.parameter(pt)
|
||||
@@ -268,6 +274,18 @@ class MapWireToTag:
|
||||
self.complete = False
|
||||
self.haveProblem = False
|
||||
|
||||
# initialized later
|
||||
self.edgePoints = None
|
||||
self.edgesCleanup = None
|
||||
self.edgesOrder = None
|
||||
self.entryEdges = None
|
||||
self.exit = None
|
||||
self.exitEdges = None
|
||||
self.finalEdge = None
|
||||
self.offendingEdge = None
|
||||
self.realEntry = None
|
||||
self.realExit = None
|
||||
|
||||
def addEdge(self, edge):
|
||||
debugEdge(edge, '..........')
|
||||
self.edges.append(edge)
|
||||
@@ -324,16 +342,16 @@ class MapWireToTag:
|
||||
# if there are no edges connected to entry/exit, it means the plunge in/out is vertical
|
||||
# we need to add in the missing segment and collect the new entry/exit edges.
|
||||
if not self.entryEdges:
|
||||
print("fill entryEdges ...")
|
||||
PathLog.debug("fill entryEdges ...")
|
||||
self.realEntry = sorted(self.edgePoints, key=lambda p: (p - self.entry).Length)[0]
|
||||
self.entryEdges = list(filter(lambda e: PathGeom.edgeConnectsTo(e, self.realEntry), edges))
|
||||
self.entryEdges = list([e for e in edges if PathGeom.edgeConnectsTo(e, self.realEntry)])
|
||||
edges.append(Part.Edge(Part.LineSegment(self.entry, self.realEntry)))
|
||||
else:
|
||||
self.realEntry = None
|
||||
if not self.exitEdges:
|
||||
print("fill exitEdges ...")
|
||||
PathLog.debug("fill exitEdges ...")
|
||||
self.realExit = sorted(self.edgePoints, key=lambda p: (p - self.exit).Length)[0]
|
||||
self.exitEdges = list(filter(lambda e: PathGeom.edgeConnectsTo(e, self.realExit), edges))
|
||||
self.exitEdges = list([e for e in edges if PathGeom.edgeConnectsTo(e, self.realExit)])
|
||||
edges.append(Part.Edge(Part.LineSegment(self.realExit, self.exit)))
|
||||
else:
|
||||
self.realExit = None
|
||||
@@ -407,13 +425,13 @@ class MapWireToTag:
|
||||
if lastP == p0:
|
||||
self.edgesOrder.append(outputEdges)
|
||||
self.edgesOrder.append(edges)
|
||||
print('input edges:')
|
||||
PathLog.debug('input edges:')
|
||||
for e in inputEdges:
|
||||
debugEdge(e, ' ', False)
|
||||
print('ordered edges:')
|
||||
PathLog.debug('ordered edges:')
|
||||
for e, flip in outputEdges:
|
||||
debugEdge(e, ' %c ' % ('<' if flip else '>'), False)
|
||||
print('remaining edges:')
|
||||
PathLog.debug('remaining edges:')
|
||||
for e in edges:
|
||||
debugEdge(e, ' ', False)
|
||||
raise ValueError("No connection to %s" % (p0))
|
||||
@@ -449,13 +467,13 @@ class MapWireToTag:
|
||||
wire.add(edge)
|
||||
|
||||
shell = wire.extrude(FreeCAD.Vector(0, 0, self.tag.height + 1))
|
||||
nullFaces = list(filter(lambda f: PathGeom.isRoughly(f.Area, 0), shell.Faces))
|
||||
nullFaces = list([f for f in shell.Faces if PathGeom.isRoughly(f.Area, 0)])
|
||||
if nullFaces:
|
||||
return shell.removeShape(nullFaces)
|
||||
return shell
|
||||
|
||||
def commandsForEdges(self):
|
||||
global failures
|
||||
global failures # pylint: disable=global-statement
|
||||
if self.edges:
|
||||
try:
|
||||
shape = self.shell().common(self.tag.solid)
|
||||
@@ -476,7 +494,7 @@ class MapWireToTag:
|
||||
commands.append(Path.Command('G0', {'X': rapid.x, 'Y': rapid.y, 'Z': rapid.z}))
|
||||
rapid = None
|
||||
return commands
|
||||
except Exception as e:
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
PathLog.error("Exception during processing tag @(%.2f, %.2f) (%s) - disabling the tag" % (self.tag.x, self.tag.y, e.args[0]))
|
||||
#if sys.version_info.major < 3:
|
||||
# traceback.print_exc(e)
|
||||
@@ -501,7 +519,7 @@ class MapWireToTag:
|
||||
self.offendingEdge = edge
|
||||
debugEdge(edge, 'offending Edge:', False)
|
||||
o = self.tag.originAt(self.tag.z)
|
||||
print('originAt: (%.2f, %.2f, %.2f)' % (o.x, o.y, o.z))
|
||||
PathLog.debug('originAt: (%.2f, %.2f, %.2f)' % (o.x, o.y, o.z))
|
||||
i = edge.valueAt(edge.FirstParameter)
|
||||
if PathGeom.pointsCoincide(i, edge.valueAt(edge.FirstParameter)):
|
||||
self.tail = edge
|
||||
@@ -552,7 +570,7 @@ class PathData:
|
||||
wire = Part.Wire(bottom)
|
||||
if wire.isClosed():
|
||||
return wire
|
||||
except Exception:
|
||||
except Exception: # pylint: disable=broad-except
|
||||
#if sys.version_info.major < 3:
|
||||
# traceback.print_exc(e)
|
||||
#else:
|
||||
@@ -581,6 +599,7 @@ class PathData:
|
||||
return (edges[0], edges[-1])
|
||||
|
||||
def generateTags(self, obj, count, width=None, height=None, angle=None, radius=None, spacing=None):
|
||||
# pylint: disable=unused-argument
|
||||
PathLog.track(count, width, height, angle, spacing)
|
||||
# for e in self.baseWire.Edges:
|
||||
# debugMarker(e.Vertexes[0].Point, 'base', (0.0, 1.0, 1.0), 0.2)
|
||||
@@ -683,7 +702,7 @@ class PathData:
|
||||
ordered = []
|
||||
for edge in self.bottomEdges:
|
||||
ts = [t for t in tags if PathGeom.isRoughly(0, Part.Vertex(t.originAt(self.minZ)).distToShape(edge)[0], 0.1)]
|
||||
for t in sorted(ts, key=lambda t: (t.originAt(self.minZ) - edge.valueAt(edge.FirstParameter)).Length):
|
||||
for t in sorted(ts, key=lambda t, edge=edge: (t.originAt(self.minZ) - edge.valueAt(edge.FirstParameter)).Length):
|
||||
tags.remove(t)
|
||||
ordered.append(t)
|
||||
# disable all tags that are not on the base wire.
|
||||
@@ -725,6 +744,10 @@ class ObjectTagDressup:
|
||||
|
||||
self.obj = obj
|
||||
self.solids = []
|
||||
self.tags = []
|
||||
self.pathData = None
|
||||
self.toolRadius = None
|
||||
self.mappers = []
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
@@ -733,13 +756,13 @@ class ObjectTagDressup:
|
||||
return None
|
||||
|
||||
def supportsTagGeneration(self, obj):
|
||||
if not hasattr(self, 'pathData'):
|
||||
if not self.pathData:
|
||||
self.setup(obj)
|
||||
return self.pathData.supportsTagGeneration()
|
||||
|
||||
def generateTags(self, obj, count):
|
||||
if self.supportsTagGeneration(obj):
|
||||
if hasattr(self, "pathData"):
|
||||
if self.pathData:
|
||||
self.tags = self.pathData.generateTags(obj, count, obj.Width.Value, obj.Height.Value, obj.Angle, obj.Radius.Value, None)
|
||||
obj.Positions = [tag.originAt(self.pathData.minZ) for tag in self.tags]
|
||||
obj.Disabled = []
|
||||
@@ -836,7 +859,7 @@ class ObjectTagDressup:
|
||||
return Path.Path(commands)
|
||||
|
||||
def problems(self):
|
||||
return list(filter(lambda m: m.haveProblem, self.mappers))
|
||||
return list([m for m in self.mappers if m.haveProblem])
|
||||
|
||||
def createTagsPositionDisabled(self, obj, positionsIn, disabledIn):
|
||||
rawTags = []
|
||||
@@ -869,7 +892,7 @@ class ObjectTagDressup:
|
||||
PathLog.debug("previousTag = %d [%s]" % (i, prev))
|
||||
else:
|
||||
disabled.append(i)
|
||||
tag.id = i # assigne final id
|
||||
tag.nr = i # assigne final nr
|
||||
tags.append(tag)
|
||||
positions.append(tag.originAt(self.pathData.minZ))
|
||||
return (tags, positions, disabled)
|
||||
@@ -894,7 +917,7 @@ class ObjectTagDressup:
|
||||
|
||||
pathData = self.setup(obj)
|
||||
if not pathData:
|
||||
print("execute - no pathData")
|
||||
PathLog.debug("execute - no pathData")
|
||||
return
|
||||
|
||||
self.tags = []
|
||||
@@ -906,13 +929,13 @@ class ObjectTagDressup:
|
||||
obj.Disabled = disabled
|
||||
|
||||
if not self.tags:
|
||||
print("execute - no tags")
|
||||
PathLog.debug("execute - no tags")
|
||||
obj.Path = obj.Base.Path
|
||||
return
|
||||
|
||||
try:
|
||||
self.processTags(obj)
|
||||
except Exception as e:
|
||||
except Exception as e: # pylint: disable=broad-except
|
||||
PathLog.error("processing tags failed clearing all tags ... '%s'" % (e.args[0]))
|
||||
#if sys.version_info.major < 3:
|
||||
# traceback.print_exc(e)
|
||||
@@ -925,15 +948,15 @@ class ObjectTagDressup:
|
||||
solids = []
|
||||
for tag in self.tags:
|
||||
solids.append(tag.solid)
|
||||
if not tag.enabled and tag.id not in disabled:
|
||||
disabled.append(tag.id)
|
||||
if not tag.enabled and tag.nr not in disabled:
|
||||
disabled.append(tag.nr)
|
||||
self.solids = solids
|
||||
if obj.Disabled != disabled:
|
||||
obj.Disabled = disabled
|
||||
|
||||
@waiting_effects
|
||||
def processTags(self, obj):
|
||||
global failures
|
||||
global failures # pylint: disable=global-statement
|
||||
failures = []
|
||||
tagID = 0
|
||||
if PathLog.getLevel(PathLog.thisModule()) == PathLog.Level.DEBUG:
|
||||
@@ -975,7 +998,7 @@ class ObjectTagDressup:
|
||||
|
||||
def setXyEnabled(self, triples):
|
||||
PathLog.track()
|
||||
if not hasattr(self, 'pathData'):
|
||||
if not self.pathData:
|
||||
self.setup(self.obj)
|
||||
positions = []
|
||||
disabled = []
|
||||
@@ -988,12 +1011,12 @@ class ObjectTagDressup:
|
||||
self.processTags(self.obj)
|
||||
|
||||
def pointIsOnPath(self, obj, point):
|
||||
if not hasattr(self, 'pathData'):
|
||||
if not self.pathData:
|
||||
self.setup(obj)
|
||||
return self.pathData.pointIsOnPath(point)
|
||||
|
||||
def pointAtBottom(self, obj, point):
|
||||
if not hasattr(self, 'pathData'):
|
||||
if not self.pathData:
|
||||
self.setup(obj)
|
||||
return self.pathData.pointAtBottom(point)
|
||||
|
||||
@@ -1010,7 +1033,7 @@ def Create(baseObject, name='DressupTag'):
|
||||
PathLog.error(translate('Path_DressupTag', 'Please select a Profile object'))
|
||||
return None
|
||||
|
||||
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "TagDressup")
|
||||
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name)
|
||||
dbo = ObjectTagDressup(obj, baseObject)
|
||||
job = PathUtils.findParentJob(baseObject)
|
||||
job.Proxy.addOperation(obj, baseObject)
|
||||
|
||||
@@ -127,6 +127,14 @@ class ObjectDressup:
|
||||
self.obj = obj
|
||||
self.solids = []
|
||||
|
||||
# initialized later
|
||||
self.edges = None
|
||||
self.masterSolid = None
|
||||
self.ptMax = None
|
||||
self.ptMin = None
|
||||
self.tagSolid = None
|
||||
self.wire = None
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
|
||||
@@ -187,7 +195,7 @@ class ObjectDressup:
|
||||
self.solids = [self.masterSolid.cloneAt(pos) for pos in self.obj.Positions]
|
||||
self.tagSolid = Part.Compound(self.solids)
|
||||
|
||||
self.wire, rapid = PathGeom.wireForPath(obj.Base.Path)
|
||||
self.wire, rapid = PathGeom.wireForPath(obj.Base.Path) # pylint: disable=unused-variable
|
||||
self.edges = self.wire.Edges
|
||||
|
||||
maxTagZ = minZ + obj.Height.Value
|
||||
@@ -220,9 +228,11 @@ class ObjectDressup:
|
||||
obj.Shape = solid
|
||||
|
||||
def supportsTagGeneration(self, obj):
|
||||
# pylint: disable=unused-argument
|
||||
return False
|
||||
|
||||
def pointIsOnPath(self, obj, p):
|
||||
# pylint: disable=unused-argument
|
||||
for e in self.edges:
|
||||
if DraftGeomUtils.isPtOnEdge(p, e):
|
||||
return True
|
||||
@@ -241,7 +251,7 @@ def Create(baseObject, name='DressupTag'):
|
||||
PathLog.error(translate('Path_DressupTag', 'Please select a Profile object'))
|
||||
return None
|
||||
|
||||
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", "TagDressup")
|
||||
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name)
|
||||
dbo = ObjectDressup(obj, baseObject)
|
||||
job = PathUtils.findParentJob(baseObject)
|
||||
job.adddOperation(obj)
|
||||
|
||||
@@ -69,6 +69,11 @@ class PathDressupTagTaskPanel:
|
||||
self.pt = FreeCAD.Vector(0, 0, 0)
|
||||
|
||||
self.isDirty = True
|
||||
self.buttonBox = None
|
||||
self.tags = None
|
||||
self.Positions = None
|
||||
self.Disabled = None
|
||||
self.editItem = None
|
||||
|
||||
def getStandardButtons(self):
|
||||
return int(QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Apply | QtGui.QDialogButtonBox.Cancel)
|
||||
@@ -322,12 +327,17 @@ class PathDressupTagViewProvider:
|
||||
|
||||
def __init__(self, vobj):
|
||||
PathLog.track()
|
||||
vobj.Proxy = self
|
||||
self.vobj = vobj
|
||||
self.panel = None
|
||||
|
||||
self.debugDisplay()
|
||||
|
||||
# initialized later
|
||||
self.obj = None
|
||||
self.tags = None
|
||||
self.switch = None
|
||||
self.colors = None
|
||||
|
||||
def debugDisplay(self):
|
||||
# if False and addDebugDisplay():
|
||||
# if not hasattr(self.vobj, 'Debug'):
|
||||
@@ -385,8 +395,9 @@ class PathDressupTagViewProvider:
|
||||
return [self.obj.Base]
|
||||
|
||||
def onDelete(self, arg1=None, arg2=None):
|
||||
PathLog.track()
|
||||
'''this makes sure that the base operation is added back to the job and visible'''
|
||||
# pylint: disable=unused-argument
|
||||
PathLog.track()
|
||||
if self.obj.Base.ViewObject:
|
||||
self.obj.Base.ViewObject.Visibility = True
|
||||
job = PathUtils.findParentJob(self.obj)
|
||||
@@ -428,11 +439,13 @@ class PathDressupTagViewProvider:
|
||||
# tag.purgeTouched()
|
||||
|
||||
def setEdit(self, vobj, mode=0):
|
||||
# pylint: disable=unused-argument
|
||||
panel = PathDressupTagTaskPanel(vobj.Object, self)
|
||||
self.setupTaskPanel(panel)
|
||||
return True
|
||||
|
||||
def unsetEdit(self, vobj, mode):
|
||||
# pylint: disable=unused-argument
|
||||
if hasattr(self, 'panel') and self.panel:
|
||||
self.panel.abort()
|
||||
|
||||
@@ -470,11 +483,13 @@ class PathDressupTagViewProvider:
|
||||
return -1
|
||||
|
||||
def allow(self, doc, obj, sub):
|
||||
# pylint: disable=unused-argument
|
||||
if obj == self.obj:
|
||||
return True
|
||||
return False
|
||||
|
||||
def addSelection(self, doc, obj, sub, point):
|
||||
# pylint: disable=unused-argument
|
||||
PathLog.track(doc, obj, sub, point)
|
||||
if self.panel:
|
||||
i = self.tagAtPoint(point, sub is None)
|
||||
@@ -489,13 +504,14 @@ def Create(baseObject, name='DressupTag'):
|
||||
'''
|
||||
FreeCAD.ActiveDocument.openTransaction(translate("Path_DressupTag", "Create a Tag dressup"))
|
||||
obj = PathDressupTag.Create(baseObject, name)
|
||||
vp = PathDressupTagViewProvider(obj.ViewObject)
|
||||
obj.ViewObject.Proxy = PathDressupTagViewProvider(obj.ViewObject)
|
||||
FreeCAD.ActiveDocument.commitTransaction()
|
||||
obj.ViewObject.Document.setEdit(obj.ViewObject, 0)
|
||||
return obj
|
||||
|
||||
|
||||
class CommandPathDressupTag:
|
||||
# pylint: disable=no-init
|
||||
|
||||
def GetResources(self):
|
||||
return {'Pixmap': 'Path-Dressup',
|
||||
@@ -506,7 +522,7 @@ class CommandPathDressupTag:
|
||||
if FreeCAD.ActiveDocument is not None:
|
||||
for o in FreeCAD.ActiveDocument.Objects:
|
||||
if o.Name[:3] == 'Job':
|
||||
return True
|
||||
return True
|
||||
return False
|
||||
|
||||
def Activated(self):
|
||||
|
||||
Reference in New Issue
Block a user