Path: Cleanup and simplify code

This commit is contained in:
Russell Johnson
2020-06-01 14:56:14 -05:00
parent 939ac2e115
commit b110ea2818

View File

@@ -41,10 +41,10 @@ ArchPanel = LazyLoader('ArchPanel', globals(), 'ArchPanel')
Part = LazyLoader('Part', globals(), 'Part')
__title__ = "Path Profile Faces Operation"
__title__ = "Path Profile Operation"
__author__ = "sliptonic (Brad Collette)"
__url__ = "http://www.freecadweb.org"
__doc__ = "Path Profile operation based on faces."
__doc__ = "Path Profile operation based on entire model, selected faces or selected edges."
__contributors__ = "Schildkroet"
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
@@ -246,7 +246,7 @@ class ObjectProfile(PathAreaOp.ObjectOp):
params['Coplanar'] = 0
params['SectionCount'] = -1
offset = 0.0
offset = obj.OffsetExtra.Value # 0.0
if obj.UseComp:
offset = self.radius + obj.OffsetExtra.Value
if obj.Side == 'Inside':
@@ -330,11 +330,12 @@ class ObjectProfile(PathAreaOp.ObjectOp):
allTuples = list()
edgeFaces = list()
subCount = 0
self.isDebug = True if PathLog.getLevel(PathLog.thisModule()) == 4 else False
self.inaccessibleMsg = translate('PathProfile', 'The selected edge(s) are inaccessible. If multiple, re-ordering selection might work.')
self.offsetExtra = obj.OffsetExtra.Value
self.expandProfile = None
if PathLog.getLevel(PathLog.thisModule()) == 4:
if self.isDebug:
for grpNm in ['tmpDebugGrp', 'tmpDebugGrp001']:
if hasattr(FreeCAD.ActiveDocument, grpNm):
for go in FreeCAD.ActiveDocument.getObject(grpNm).Group:
@@ -373,7 +374,7 @@ class ObjectProfile(PathAreaOp.ObjectOp):
tup = self._analyzeFace(obj, base, sub, shape, subCount)
allTuples.append(tup)
if subCount > 1:
if subCount > 1 and obj.HandleMultipleFeatures == 'Collectively':
msg = translate('PathProfile', "Multiple faces in Base Geometry.") + " "
msg += translate('PathProfile', "Depth settings will be applied to all faces.")
FreeCAD.Console.PrintWarning(msg)
@@ -389,7 +390,6 @@ class ObjectProfile(PathAreaOp.ObjectOp):
baseSubsTuples.append(pair)
# Efor
else:
PathLog.debug(translate("Path", "EnableRotation property is 'Off'."))
stock = PathUtils.findParentJob(obj).Stock
for (base, subList) in obj.Base:
baseSubsTuples.append((base, subList, 0.0, 'X', stock))
@@ -401,7 +401,6 @@ class ObjectProfile(PathAreaOp.ObjectOp):
holes = []
faces = []
faceDepths = []
startDepths = []
for sub in subsList:
shape = getattr(base.Shape, sub)
@@ -419,12 +418,12 @@ class ObjectProfile(PathAreaOp.ObjectOp):
msg = translate('PathProfile', "Found a selected object which is not a face. Ignoring:")
# FreeCAD.Console.PrintWarning(msg + " {}\n".format(ignoreSub))
# Set initial Start and Final Depths and recalculate depthparams
# Identify initial Start and Final Depths
finDep = obj.FinalDepth.Value
strDep = obj.StartDepth.Value
startDepths.append(strDep)
self.depthparams = self._customDepthParams(obj, strDep, finDep)
for baseShape, wire in holes:
cont = False
f = Part.makeFace(wire, 'Part::FaceMakerSimple')
drillable = PathUtils.isDrillable(baseShape, wire)
ot = self._openingType(obj, baseShape, f, strDep, finDep)
@@ -521,7 +520,7 @@ class ObjectProfile(PathAreaOp.ObjectOp):
if (drillable and obj.processCircles) or (not drillable and obj.processHoles):
f = Part.makeFace(wire, 'Part::FaceMakerSimple')
env = PathUtils.getEnvelope(self.model[0].Shape, subshape=f, depthparams=self.depthparams)
tup = env, True, 'pathProfileFaces', 0.0, 'X', obj.StartDepth.Value, obj.FinalDepth.Value
tup = env, True, 'pathProfile', 0.0, 'X', obj.StartDepth.Value, obj.FinalDepth.Value
shapes.append(tup)
# Process perimeter if requested by user
@@ -544,7 +543,7 @@ class ObjectProfile(PathAreaOp.ObjectOp):
PathLog.debug("%d shapes" % len(shapes))
# Delete the temporary objects
if PathLog.getLevel(PathLog.thisModule()) == 4:
if self.isDebug:
if FreeCAD.GuiUp:
import FreeCADGui
FreeCADGui.ActiveDocument.getObject(tmpGrpNm).Visibility = False
@@ -739,6 +738,8 @@ class ObjectProfile(PathAreaOp.ObjectOp):
for base, wires in basewires:
for wire in wires:
if wire.isClosed():
# Attempt to profile a closed wire
# f = Part.makeFace(wire, 'Part::FaceMakerSimple')
# if planar error, Comment out previous line, uncomment the next two
(origWire, flatWire) = self._flattenWire(obj, wire, obj.FinalDepth.Value)
@@ -772,11 +773,9 @@ class ObjectProfile(PathAreaOp.ObjectOp):
openEdges = list()
passOffsets = [self.ofstRadius]
(origWire, flatWire) = flattened
if PathLog.getLevel(PathLog.thisModule()) == 4:
os = FreeCAD.ActiveDocument.addObject('Part::Feature', 'tmpFlatWire')
os.Shape = flatWire
os.purgeTouched()
self.tmpGrp.addObject(os)
self._addDebugObject('FlatWire', flatWire)
if self.expandProfile:
# Identify list of pass offset values for expanded profile paths
regularOfst = self.ofstRadius
@@ -905,13 +904,7 @@ class ObjectProfile(PathAreaOp.ObjectOp):
# Cut model(selected edges) from extended edges boundbox
cutArea = extBndboxEXT.cut(base.Shape)
if PathLog.getLevel(PathLog.thisModule()) == 4:
CA = FCAD.addObject('Part::Feature', 'tmpCutArea')
CA.Shape = cutArea
CA.recompute()
CA.purgeTouched()
self.tmpGrp.addObject(CA)
self._addDebugObject('CutArea', cutArea)
# Get top and bottom faces of cut area (CA), and combine faces when necessary
topFc = list()
@@ -1032,12 +1025,7 @@ class ObjectProfile(PathAreaOp.ObjectOp):
# Add path stops at ends of wire
cutShp = workShp.cut(pathStops)
if PathLog.getLevel(PathLog.thisModule()) == 4:
cs = FreeCAD.ActiveDocument.addObject('Part::Feature', 'tmpCutShape')
cs.Shape = cutShp
cs.recompute()
cs.purgeTouched()
self.tmpGrp.addObject(cs)
self._addDebugObject('CutShape', cutShp)
return cutShp
@@ -1090,12 +1078,7 @@ class ObjectProfile(PathAreaOp.ObjectOp):
PathLog.error('No area to offset shape returned.\n{}'.format(ee))
return False
if PathLog.getLevel(PathLog.thisModule()) == 4:
os = FreeCAD.ActiveDocument.addObject('Part::Feature', 'tmpOffsetShape')
os.Shape = ofstShp
os.recompute()
os.purgeTouched()
self.tmpGrp.addObject(os)
self._addDebugObject('OffsetShape', ofstShp)
numOSWires = len(ofstShp.Wires)
for w in range(0, numOSWires):
@@ -1111,12 +1094,8 @@ class ObjectProfile(PathAreaOp.ObjectOp):
min0 = N[4]
min0i = n
(w0, vi0, pnt0, vrt0, d0) = NEAR0[0] # min0i
if PathLog.getLevel(PathLog.thisModule()) == 4:
near0 = FreeCAD.ActiveDocument.addObject('Part::Feature', 'tmpNear0')
near0.Shape = Part.makeLine(cent0, pnt0)
near0.recompute()
near0.purgeTouched()
self.tmpGrp.addObject(near0)
near0Shp = Part.makeLine(cent0, pnt0)
self._addDebugObject('Near0', near0Shp)
NEAR1 = self._findNearestVertex(ofstShp, cent1)
min1i = 0
@@ -1127,17 +1106,13 @@ class ObjectProfile(PathAreaOp.ObjectOp):
min1 = N[4]
min1i = n
(w1, vi1, pnt1, vrt1, d1) = NEAR1[0] # min1i
if PathLog.getLevel(PathLog.thisModule()) == 4:
near1 = FreeCAD.ActiveDocument.addObject('Part::Feature', 'tmpNear1')
near1.Shape = Part.makeLine(cent1, pnt1)
near1.recompute()
near1.purgeTouched()
self.tmpGrp.addObject(near1)
near1Shp = Part.makeLine(cent1, pnt1)
self._addDebugObject('Near1', near1Shp)
if w0 != w1:
PathLog.warning('Offset wire endpoint indexes are not equal - w0, w1: {}, {}'.format(w0, w1))
if False and PathLog.getLevel(PathLog.thisModule()) == 4:
if self.isDebug and False:
PathLog.debug('min0i is {}.'.format(min0i))
PathLog.debug('min1i is {}.'.format(min1i))
PathLog.debug('NEAR0[{}] is {}.'.format(w0, NEAR0[w0]))
@@ -1206,12 +1181,13 @@ class ObjectProfile(PathAreaOp.ObjectOp):
PathLog.debug('_extractFaceOffset()')
areaParams = {}
JOB = PathUtils.findParentJob(obj)
tolrnc = JOB.GeometryTolerance.Value
if self.useComp is True:
offset = self.ofstRadius # + tolrnc
else:
offset = self.offsetExtra # + tolrnc
# JOB = PathUtils.findParentJob(obj)
# tolrnc = JOB.GeometryTolerance.Value
# if self.useComp:
# offset = self.ofstRadius # + tolrnc
# else:
# offset = self.offsetExtra # + tolrnc
offset = self.ofstRadius
if isHole is False:
offset = 0 - offset
@@ -1385,7 +1361,8 @@ class ObjectProfile(PathAreaOp.ObjectOp):
# Efor
# Eif
if False and PathLog.getLevel(PathLog.thisModule()) == 4:
# Remove `and False` when debugging open edges, as needed
if self.isDebug and False:
PathLog.debug('grps[0]: {}'.format(grps[0]))
PathLog.debug('grps[1]: {}'.format(grps[1]))
PathLog.debug('wireIdxs[0]: {}'.format(wireIdxs[0]))
@@ -1576,12 +1553,7 @@ class ObjectProfile(PathAreaOp.ObjectOp):
wire = Part.Wire([L1, L2, L3, L4, L5])
# Eif
face = Part.Face(wire)
if PathLog.getLevel(PathLog.thisModule()) == 4:
os = FreeCAD.ActiveDocument.addObject('Part::Feature', 'tmp' + lbl)
os.Shape = face
os.recompute()
os.purgeTouched()
self.tmpGrp.addObject(os)
self._addDebugObject(lbl, face)
return face
@@ -1616,6 +1588,13 @@ class ObjectProfile(PathAreaOp.ObjectOp):
dist += elen
return midPnt
# Method to add temporary debug object
def _addDebugObject(self, objName, objShape):
if self.isDebug:
O = FreeCAD.ActiveDocument.addObject('Part::Feature', 'tmp_' + objName)
O.Shape = objShape
O.purgeTouched()
self.tmpGrp.addObject(O)
def SetupProperties():