Skip to content

Commit

Permalink
Path: LGTM cleanup and PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
Russ4262 committed May 22, 2020
1 parent 562b834 commit 49853d5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 48 deletions.
7 changes: 2 additions & 5 deletions src/Mod/Path/PathScripts/PathSurface.py
Expand Up @@ -907,7 +907,6 @@ def _planarPerformOclScan(self, obj, pdc, pathGeom, offsetPoints=False):
return SCANS

def _planarDropCutScan(self, pdc, A, B):
#PNTS = list()
(x1, y1) = A
(x2, y2) = B
path = ocl.Path() # create an empty path object
Expand All @@ -918,11 +917,10 @@ def _planarDropCutScan(self, pdc, A, B):
pdc.setPath(path)
pdc.run() # run dropcutter algorithm on path
CLP = pdc.getCLPoints()
PNTS = [FreeCAD.Vector(p.x, p.y, p.z) for p in CLP]
return PNTS # pdc.getCLPoints()
# Convert OCL object data to FreeCAD vectors
return [FreeCAD.Vector(p.x, p.y, p.z) for p in CLP]

def _planarCircularDropCutScan(self, pdc, Arc, cMode):
PNTS = list()
path = ocl.Path() # create an empty path object
(sp, ep, cp) = Arc

Expand Down Expand Up @@ -1029,7 +1027,6 @@ def _planarSinglepassProcess(self, obj, PNTS):
output = []
optimize = obj.OptimizeLinearPaths
lenPNTS = len(PNTS)
lop = None
onLine = False

# Initialize first three points
Expand Down
64 changes: 33 additions & 31 deletions src/Mod/Path/PathScripts/PathSurfaceSupport.py
Expand Up @@ -100,10 +100,10 @@ def __init__(self, obj, shape, pattern):

def _prepareConstants(self):
# Apply drop cutter extra offset and set the max and min XY area of the operation
xmin = self.shape.BoundBox.XMin
xmax = self.shape.BoundBox.XMax
ymin = self.shape.BoundBox.YMin
ymax = self.shape.BoundBox.YMax
# xmin = self.shape.BoundBox.XMin
# xmax = self.shape.BoundBox.XMax
# ymin = self.shape.BoundBox.YMin
# ymax = self.shape.BoundBox.YMax

# Compute weighted center of mass of all faces combined
if self.pattern in ['Circular', 'CircularZigZag', 'Spiral']:
Expand Down Expand Up @@ -233,17 +233,17 @@ def _Line(self):
cAng = math.atan(self.deltaX / self.deltaY) # BoundaryBox angle

# Determine end points and create top lines
x1 = centRot.x - self.halfDiag
x2 = centRot.x + self.halfDiag
diag = None
if self.obj.CutPatternAngle == 0 or self.obj.CutPatternAngle == 180:
diag = self.deltaY
elif self.obj.CutPatternAngle == 90 or self.obj.CutPatternAngle == 270:
diag = self.deltaX
else:
perpDist = math.cos(cAng - math.radians(self.obj.CutPatternAngle)) * self.deltaC
diag = perpDist
y1 = centRot.y + diag
# x1 = centRot.x - self.halfDiag
# x2 = centRot.x + self.halfDiag
# diag = None
# if self.obj.CutPatternAngle == 0 or self.obj.CutPatternAngle == 180:
# diag = self.deltaY
# elif self.obj.CutPatternAngle == 90 or self.obj.CutPatternAngle == 270:
# diag = self.deltaX
# else:
# perpDist = math.cos(cAng - math.radians(self.obj.CutPatternAngle)) * self.deltaC
# diag = perpDist
# y1 = centRot.y + diag
# y2 = y1

# Create end points for set of lines to intersect with cross-section face
Expand Down Expand Up @@ -410,6 +410,7 @@ def _extractOffsetFaces(self):
if not ofstArea:
# FreeCAD.Console.PrintWarning('PGG: No offset clearing area returned.\n')
cont = False
True if cont else False # cont used for LGTM
break
for F in ofstArea.Faces:
faces.append(F)
Expand Down Expand Up @@ -956,6 +957,7 @@ def getExtrudedShape(wire):
SHP = Part.makeSolid(shell)
return SHP


def getShapeSlice(shape):
PathLog.debug('getShapeSlice()')

Expand Down Expand Up @@ -1003,6 +1005,7 @@ def getShapeSlice(shape):

return False


def getProjectedFace(tempGroup, wire):
import Draft
PathLog.debug('getProjectedFace()')
Expand All @@ -1027,6 +1030,7 @@ def getProjectedFace(tempGroup, wire):
slc.translate(FreeCAD.Vector(0.0, 0.0, 0.0 - slc.BoundBox.ZMin))
return slc


def getCrossSection(shape):
PathLog.debug('getCrossSection()')
wires = list()
Expand All @@ -1051,6 +1055,7 @@ def getCrossSection(shape):

return False


def getShapeEnvelope(shape):
PathLog.debug('getShapeEnvelope()')

Expand All @@ -1069,6 +1074,7 @@ def getShapeEnvelope(shape):
else:
return env


def getSliceFromEnvelope(env):
PathLog.debug('getSliceFromEnvelope()')
eBB = env.BoundBox
Expand Down Expand Up @@ -1155,12 +1161,13 @@ def _prepareModelSTLs(self, JOB, obj, m, ocl):
stl = ocl.STLSurf()
for tri in facets:
t = ocl.Triangle(ocl.Point(tri[0][0], tri[0][1], tri[0][2]),
ocl.Point(tri[1][0], tri[1][1], tri[1][2]),
ocl.Point(tri[2][0], tri[2][1], tri[2][2]))
ocl.Point(tri[1][0], tri[1][1], tri[1][2]),
ocl.Point(tri[2][0], tri[2][1], tri[2][2]))
stl.addTriangle(t)
self.modelSTLs[m] = stl
return


def _makeSafeSTL(self, JOB, obj, mdlIdx, faceShapes, voidShapes, ocl):
'''_makeSafeSTL(JOB, obj, mdlIdx, faceShapes, voidShapes)...
Creates and OCL.stl object with combined data with waste stock,
Expand Down Expand Up @@ -1317,13 +1324,15 @@ def pathGeomToLinesPointSet(obj, compGeoShp, cutClimb, toolDiam, closedGap, gaps
(vA, vB) = inLine.pop() # pop off previous line segment for combining with current
tup = (vA, tup[1])
closedGap = True
True if closedGap else False # used closedGap for LGTM
else:
# PathLog.debug('---- Gap: {} mm'.format(gap))
gap = round(gap, 6)
if gap < gaps[0]:
gaps.insert(0, gap)
gaps.pop()
inLine.append(tup)

# Efor
lnCnt += 1
if cutClimb is True:
Expand Down Expand Up @@ -1363,11 +1372,10 @@ def pathGeomToZigzagPointSet(obj, compGeoShp, cutClimb, toolDiam, closedGap, gap
lnCnt = 0
chkGap = False
ec = len(compGeoShp.Edges)
dirFlg = 1

if cutClimb is True:
if cutClimb:
dirFlg = -1
else:
dirFlg = 1

edg0 = compGeoShp.Edges[0]
p1 = (edg0.Vertexes[0].X, edg0.Vertexes[0].Y)
Expand All @@ -1389,17 +1397,15 @@ def pathGeomToZigzagPointSet(obj, compGeoShp, cutClimb, toolDiam, closedGap, gap

cp = FreeCAD.Vector(v1[0], v1[1], 0.0) # check point (start point of segment)
ep = FreeCAD.Vector(v2[0], v2[1], 0.0) # end point
# iC = sp.isOnLineSegment(ep, cp)
iC = cp.isOnLineSegment(sp, ep)
if iC is True:
if iC:
inLine.append('BRK')
chkGap = True
gap = abs(toolDiam - lst.sub(cp).Length)
else:
chkGap = False
if dirFlg == -1:
inLine.reverse()
# LINES.append((dirFlg, inLine))
LINES.append(inLine)
lnCnt += 1
dirFlg = -1 * dirFlg # Change zig to zag
Expand All @@ -1412,7 +1418,7 @@ def pathGeomToZigzagPointSet(obj, compGeoShp, cutClimb, toolDiam, closedGap, gap
else:
tup = (v2, v1)

if chkGap is True:
if chkGap:
if gap < obj.GapThreshold.Value:
b = inLine.pop() # pop off 'BRK' marker
(vA, vB) = inLine.pop() # pop off previous line segment for combining with current
Expand All @@ -1437,8 +1443,8 @@ def pathGeomToZigzagPointSet(obj, compGeoShp, cutClimb, toolDiam, closedGap, gap
else:
PathLog.debug('Line count is ODD.')
dirFlg = -1 * dirFlg
if obj.CutPatternReversed is False:
if cutClimb is True:
if not obj.CutPatternReversed:
if cutClimb:
dirFlg = -1 * dirFlg

if obj.CutPatternReversed:
Expand Down Expand Up @@ -1466,11 +1472,8 @@ def pathGeomToZigzagPointSet(obj, compGeoShp, cutClimb, toolDiam, closedGap, gap
rev2.append((p2, p1))
rev2.reverse()
rev = rev2

# LINES.append((dirFlg, rev))
LINES.append(rev)
else:
# LINES.append((dirFlg, inLine))
LINES.append(inLine)

return LINES
Expand Down Expand Up @@ -1696,7 +1699,6 @@ def pathGeomToSpiralPointSet(obj, compGeoShp):
p2 = FreeCAD.Vector(edg1.Vertexes[1].X, edg1.Vertexes[1].Y, 0.0)
tup = ((p1.x, p1.y), (p2.x, p2.y))
inLine.append(tup)
lst = p2

for ei in range(start, ec): # Skipped first edge, started with second edge above as edg1
edg = compGeoShp.Edges[ei] # Get edge for vertexes
Expand All @@ -1711,7 +1713,7 @@ def pathGeomToSpiralPointSet(obj, compGeoShp):
lnCnt += 1
inLine = list() # reset container
inLine.append(tup)
p1 = sp
# p1 = sp
p2 = ep
# Efor

Expand Down
22 changes: 10 additions & 12 deletions src/Mod/Path/PathScripts/PathWaterline.py
Expand Up @@ -815,16 +815,11 @@ def _oclWaterlineOp(self, JOB, obj, mdlIdx, subShp=None):
if self.layerEndPnt is None:
self.layerEndPnt = FreeCAD.Vector(0.0, 0.0, 0.0)

# Set extra offset to diameter of cutter to allow cutter to move around perimeter of model
toolDiam = self.cutter.getDiameter()

if subShp is None:
# Get correct boundbox
if obj.BoundBox == 'Stock':
BS = JOB.Stock
bb = BS.Shape.BoundBox
bb = JOB.Stock.Shape.BoundBox
elif obj.BoundBox == 'BaseBoundBox':
BS = base
bb = base.Shape.BoundBox

xmin = bb.XMin
Expand Down Expand Up @@ -869,7 +864,9 @@ def _oclWaterlineOp(self, JOB, obj, mdlIdx, subShp=None):
scanLines[L].append(oclScan[pi])
lenSL = len(scanLines)
pntsPerLine = len(scanLines[0])
PathLog.debug("--OCL scan: " + str(lenSL * pntsPerLine) + " points, with " + str(numScanLines) + " lines and " + str(pntsPerLine) + " pts/line")
msg = "--OCL scan: " + str(lenSL * pntsPerLine) + " points, with "
msg += str(numScanLines) + " lines and " + str(pntsPerLine) + " pts/line"
PathLog.debug(msg)

# Extract Wl layers per depthparams
lyr = 0
Expand Down Expand Up @@ -1156,6 +1153,7 @@ def _loopToGcode(self, obj, layDep, loop):

# Save layer end point for use in transitioning to next layer
self.layerEndPnt = pnt
True if prev else False # Use prev for LGTM

return output

Expand Down Expand Up @@ -1224,7 +1222,7 @@ def _experimentalWaterlineOp(self, JOB, obj, mdlIdx, subShp=None):
caCnt += 1
if area.Area > 0.0:
cont = True
caWireCnt = len(area.Wires) - 1 # first wire is boundFace wire
# caWireCnt = len(area.Wires) - 1 # first wire is boundFace wire
if self.showDebugObjects:
CA = FreeCAD.ActiveDocument.addObject('Part::Feature', 'cutArea_{}'.format(caCnt))
CA.Shape = area
Expand All @@ -1238,7 +1236,7 @@ def _experimentalWaterlineOp(self, JOB, obj, mdlIdx, subShp=None):
if cont:
area.translate(FreeCAD.Vector(0.0, 0.0, 0.0 - area.BoundBox.ZMin))
activeArea = area.cut(trimFace)
activeAreaWireCnt = len(activeArea.Wires) # first wire is boundFace wire
# activeAreaWireCnt = len(activeArea.Wires) # first wire is boundFace wire
if self.showDebugObjects:
CA = FreeCAD.ActiveDocument.addObject('Part::Feature', 'activeArea_{}'.format(caCnt))
CA.Shape = activeArea
Expand Down Expand Up @@ -1448,7 +1446,7 @@ def _clearGeomToPaths(self, JOB, obj, safePDC, stpOVRS, cutPattern):
tolrnc = JOB.GeometryTolerance.Value
lenstpOVRS = len(stpOVRS)
lstSO = lenstpOVRS - 1
lstStpOvr = False
# lstStpOvr = False
gDIR = ['G3', 'G2']

if self.CutClimb is True:
Expand All @@ -1468,8 +1466,8 @@ def _clearGeomToPaths(self, JOB, obj, safePDC, stpOVRS, cutPattern):
first = PRTS[0][0] # first point of arc/line stepover group
last = None
cmds.append(Path.Command('N (Begin step {}.)'.format(so), {}))
if so == lstSO:
lstStpOvr = True
# if so == lstSO:
# lstStpOvr = True

if so > 0:
if cutPattern == 'CircularZigZag':
Expand Down

0 comments on commit 49853d5

Please sign in to comment.