Path: PEP8 and Proxy changes.

This commit is contained in:
sliptonic
2019-06-17 09:17:38 -05:00
parent 4296df8c3e
commit d4a311de19
3 changed files with 67 additions and 54 deletions

View File

@@ -63,6 +63,8 @@ else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
@@ -106,9 +108,11 @@ class ObjectOp(PathOp.ObjectOp):
obj.setEditorMode('PathParams', 2) # hide
obj.addProperty("Part::PropertyPartShape", "removalshape", "Path")
obj.setEditorMode('removalshape', 2) # hide
# obj.Proxy = self
self.setupAdditionalProperties(obj)
self.initAreaOp(obj)
def setupAdditionalProperties(self, obj):
@@ -166,12 +170,12 @@ class ObjectOp(PathOp.ObjectOp):
for prop in ['AreaParams', 'PathParams', 'removalshape']:
if hasattr(obj, prop):
obj.setEditorMode(prop, 2)
self.initOpFinalDepth = obj.OpFinalDepth.Value
self.initOpStartDepth = obj.OpStartDepth.Value
self.docRestored = True
#PathLog.debug("Imported existing OpFinalDepth of " + str(self.initOpFinalDepth) + " for recompute() purposes.")
#PathLog.debug("Imported existing StartDepth of " + str(self.initOpStartDepth) + " for recompute() purposes.")
# PathLog.debug("Imported existing OpFinalDepth of " + str(self.initOpFinalDepth) + " for recompute() purposes.")
# PathLog.debug("Imported existing StartDepth of " + str(self.initOpStartDepth) + " for recompute() purposes.")
self.setupAdditionalProperties(obj)
self.areaOpOnDocumentRestored(obj)
@@ -186,7 +190,7 @@ class ObjectOp(PathOp.ObjectOp):
areaOpShapeForDepths() return value.
Do not overwrite, overwrite areaOpSetDefaultValues(obj, job) instead.'''
PathLog.debug("opSetDefaultValues(%s, %s)" % (obj.Label, job.Label))
# Initial setting for EnableRotation is taken from Job settings/SetupSheet
# User may override on per-operation basis as needed.
if hasattr(job.SetupSheet, 'SetupEnableRotation'):
@@ -338,7 +342,7 @@ class ObjectOp(PathOp.ObjectOp):
self.rotateFlag = False
self.leadIn = 2.0 # self.safOfst / 2.0
self.cloneNames = []
self.guiMsgs = [] # list of message tuples (title, msg) to be displayed in GUI
self.guiMsgs = [] # list of message tuples (title, msg) to be displayed in GUI
self.stockBB = PathUtils.findParentJob(obj).Stock.Shape.BoundBox
self.useTempJobClones('Delete') # Clear temporary group and recreate for temp job clones
@@ -374,7 +378,7 @@ class ObjectOp(PathOp.ObjectOp):
obj.ClearanceHeight.Value = self.strDep + self.safOfset
obj.SafeHeight.Value = self.strDep + self.safOfst
if self.initWithRotation == False:
if self.initWithRotation is False:
if obj.FinalDepth.Value == obj.OpFinalDepth.Value:
obj.FinalDepth.Value = self.finDep
if obj.StartDepth.Value == obj.OpStartDepth.Value:
@@ -496,7 +500,7 @@ class ObjectOp(PathOp.ObjectOp):
self.commandlist.extend(ppCmds)
sims.append(sim)
# Eif
if self.areaOpRetractTool(obj):
self.endVector = None
@@ -735,7 +739,7 @@ class ObjectOp(PathOp.ObjectOp):
xAx = 'xAxCyl'
yAx = 'yAxCyl'
zAx = 'zAxCyl'
FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup","visualAxis")
FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "visualAxis")
if FreeCAD.GuiUp:
FreeCADGui.ActiveDocument.getObject('visualAxis').Visibility = False
vaGrp = FreeCAD.ActiveDocument.getObject("visualAxis")
@@ -745,11 +749,11 @@ class ObjectOp(PathOp.ObjectOp):
cyl.Label = xAx
cyl.Radius = self.xRotRad
cyl.Height = 0.01
cyl.Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,0),FreeCAD.Rotation(FreeCAD.Vector(0,1,0),90))
cyl.Placement = FreeCAD.Placement(FreeCAD.Vector(0, 0, 0), FreeCAD.Rotation(FreeCAD.Vector(0, 1, 0), 90))
cyl.purgeTouched()
if FreeCAD.GuiUp:
cylGui = FreeCADGui.ActiveDocument.getObject(xAx)
cylGui.ShapeColor = (0.667,0.000,0.000)
cylGui.ShapeColor = (0.667, 0.000, 0.000)
cylGui.Transparency = 85
cylGui.Visibility = False
vaGrp.addObject(cyl)
@@ -759,15 +763,15 @@ class ObjectOp(PathOp.ObjectOp):
cyl.Label = yAx
cyl.Radius = self.yRotRad
cyl.Height = 0.01
cyl.Placement = FreeCAD.Placement(FreeCAD.Vector(0,0,0),FreeCAD.Rotation(FreeCAD.Vector(1,0,0),90))
cyl.Placement = FreeCAD.Placement(FreeCAD.Vector(0, 0, 0), FreeCAD.Rotation(FreeCAD.Vector(1, 0, 0), 90))
cyl.purgeTouched()
if FreeCAD.GuiUp:
cylGui = FreeCADGui.ActiveDocument.getObject(yAx)
cylGui.ShapeColor = (0.000,0.667,0.000)
cylGui.ShapeColor = (0.000, 0.667, 0.000)
cylGui.Transparency = 85
cylGui.Visibility = False
vaGrp.addObject(cyl)
if False:
FreeCAD.ActiveDocument.addObject("Part::Cylinder", zAx)
cyl = FreeCAD.ActiveDocument.getObject(zAx)
@@ -778,7 +782,7 @@ class ObjectOp(PathOp.ObjectOp):
cyl.purgeTouched()
if FreeCAD.GuiUp:
cylGui = FreeCADGui.ActiveDocument.getObject(zAx)
cylGui.ShapeColor = (0.000,0.000,0.498)
cylGui.ShapeColor = (0.000, 0.000, 0.498)
cylGui.Transparency = 85
cylGui.Visibility = False
vaGrp.addObject(cyl)
@@ -798,7 +802,7 @@ class ObjectOp(PathOp.ObjectOp):
FreeCAD.ActiveDocument.removeObject(cln.Name)
FreeCAD.ActiveDocument.removeObject('rotJobClones')
else:
FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup","rotJobClones")
FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "rotJobClones")
if FreeCAD.GuiUp:
FreeCADGui.ActiveDocument.getObject('rotJobClones').Visibility = False
@@ -817,8 +821,8 @@ class ObjectOp(PathOp.ObjectOp):
tag = axis + '_' + axis + '_' + str(math.fabs(rndAng)).replace('.', '_')
else:
tag = axis + str(rndAng).replace('.', '_')
clnNm = obj.Name + '_base_' + '_' + str(subCount) + '_' + tag
stckClnNm = obj.Name + '_stock_' + '_' + str(subCount) + '_' + tag
clnNm = obj.Name + '_base_' + '_' + str(subCount) + '_' + tag
stckClnNm = obj.Name + '_stock_' + '_' + str(subCount) + '_' + tag
if clnNm not in self.cloneNames:
self.cloneNames.append(clnNm)
self.cloneNames.append(stckClnNm)
@@ -829,11 +833,11 @@ class ObjectOp(PathOp.ObjectOp):
FreeCAD.ActiveDocument.addObject('Part::Feature', clnNm).Shape = base.Shape
FreeCAD.ActiveDocument.addObject('Part::Feature', stckClnNm).Shape = PathUtils.findParentJob(obj).Stock.Shape
if FreeCAD.GuiUp:
FreeCADGui.ActiveDocument.getObject(stckClnNm).Transparency=90
FreeCADGui.ActiveDocument.getObject(clnNm).ShapeColor = (1.000,0.667,0.000)
FreeCADGui.ActiveDocument.getObject(stckClnNm).Transparency = 90
FreeCADGui.ActiveDocument.getObject(clnNm).ShapeColor = (1.000, 0.667, 0.000)
self.useTempJobClones(clnNm)
self.useTempJobClones(stckClnNm)
clnBase = FreeCAD.ActiveDocument.getObject(clnNm)
clnBase = FreeCAD.ActiveDocument.getObject(clnNm)
clnStock = FreeCAD.ActiveDocument.getObject(stckClnNm)
tag = base.Name + '_' + tag
return (clnBase, clnStock, tag)

View File

@@ -59,9 +59,12 @@ else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
def endPoints(edgeOrWire):
'''endPoints(edgeOrWire) ... return the first and last point of the wire or the edge, assuming the argument is not a closed wire.'''
if Part.Wire == type(edgeOrWire):
@@ -74,7 +77,8 @@ def endPoints(edgeOrWire):
if 1 == cnt:
unique.append(p)
return unique
return [e.valueAt(edgeOrWire.FirstParameter), e.valueAt(edgeOrWire.LastParameter)]
return [edgeOrWire.valueAt(edgeOrWire.FirstParameter), edgeOrWire.valueAt(edgeOrWire.LastParameter)]
def includesPoint(p, pts):
'''includesPoint(p, pts) ... answer True if the collection of pts includes the point p'''
@@ -83,6 +87,7 @@ def includesPoint(p, pts):
return True
return False
def selectOffsetWire(feature, wires):
'''selectOffsetWire(feature, wires) ... returns the Wire in wires which is does not intersect with feature'''
closest = None
@@ -94,6 +99,7 @@ def selectOffsetWire(feature, wires):
return closest[1]
return None
def extendWire(feature, wire, length):
'''extendWire(wire, length) ... return a closed Wire which extends wire by length'''
try:
@@ -104,7 +110,7 @@ def extendWire(feature, wire, length):
return False
else:
endPts = endPoints(wire)
edges = [e for e in off2D.Edges if Part.Circle != type(e.Curve) or not includesPoint(e.Curve.Center, endPts)]
edges = [e for e in off2D.Edges if not isinstance(e.Curve, Part.Circle) or not includesPoint(e.Curve.Center, endPts)]
wires = [Part.Wire(e) for e in Part.sortEdges(edges)]
offset = selectOffsetWire(feature, wires)
ePts = endPoints(offset)
@@ -127,6 +133,7 @@ def extendWire(feature, wire, length):
edges.append(Part.Edge(Part.LineSegment(endPts[0], ePts[1])))
return Part.Wire(edges)
class Extension(object):
DirectionNormal = 0
DirectionX = 1
@@ -143,7 +150,7 @@ class Extension(object):
return "%s:%s" % (self.feature, self.sub)
def extendEdge(self, feature, e0, direction):
if Part.Line == type(e0.Curve) or Part.LineSegment == type(e0.Curve):
if isinstance(e0.Curve, Part.Line) or isinstance(e0.Curve, Part.LineSegment):
e2 = e0.copy()
off = self.length.Value * direction
e2.translate(off)
@@ -372,9 +379,9 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
faceNums = ""
for f in subsList:
faceNums += '_' + f.replace('Face', '')
(clnBase, angle, clnStock, tag) = self.applyRotationalAnalysis(obj, base, angle, axis, faceNums)
(clnBase, angle, clnStock, tag) = self.applyRotationalAnalysis(obj, base, angle, axis, faceNums)
# Verify faces are correctly oriented - InverseAngle might be necessary
# Verify faces are correctly oriented - InverseAngle might be necessary
PathLog.debug("Checking if faces are oriented correctly after rotation...")
for sub in subsList:
face = clnBase.Shape.getElement(sub)
@@ -387,7 +394,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
(clnBase, clnStock, angle) = self.applyInverseAngle(obj, clnBase, clnStock, axis, angle)
else:
PathLog.info(translate("Path", "Consider toggling the InverseAngle property and recomputing the operation."))
tup = clnBase, subsList, angle, axis, clnStock
else:
if self.warnDisabledAxis(obj, axis) is False:
@@ -413,7 +420,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
# --------------------------------------------------------
if type(face.Surface) == Part.SurfaceOfExtrusion:
# extrusion wall
# extrusion wall
PathLog.debug('analyzing type() == Part.SurfaceOfExtrusion')
# Attempt to extract planar face from surface of extrusion
(planar, useFace) = planarFaceFromExtrusionEdges(face, trans=False)
@@ -427,7 +434,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
# --------------------------------------------------------
(norm, surf) = self.getFaceNormAndSurf(face)
(rtn, angle, axis, praInfo)= self.faceRotationAnalysis(obj, norm, surf)
(rtn, angle, axis, praInfo) = self.faceRotationAnalysis(obj, norm, surf)
if rtn is True:
faceNum = sub.replace('Face', '')
@@ -464,7 +471,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
# Efor
if False:
if False:
(Tags, Grps) = self.sortTuplesByIndex(allTuples, 2) # return (TagList, GroupList)
(Tags, Grps) = self.sortTuplesByIndex(allTuples, 2) # return (TagList, GroupList)
subList = []
for o in range(0, len(Tags)):
subList = []
@@ -478,7 +485,6 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
baseSubsTuples.append(pair)
# ----------------------------------------------------------------------
for o in baseSubsTuples:
self.horiz = []
self.vert = []
@@ -559,7 +565,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
# Adjust obj.FinalDepth.Value as needed.
if len(finalDepths) > 0:
finalDep = min(finalDepths)
finalDepths = min(finalDepths)
if subCount == 1:
obj.FinalDepth.Value = finDep
else:
@@ -580,13 +586,13 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
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:
shape.tessellate(0.05) # originally 0.1
shape.tessellate(0.05) # originally 0.1
if self.removalshapes:
obj.removalshape = self.removalshapes[0][0]
#if PathLog.getLevel(PathLog.thisModule()) != 4:
#if self.delTempNameList > 0:
# if PathLog.getLevel(PathLog.thisModule()) != 4:
# if self.delTempNameList > 0:
# for tmpNm in self.tempNameList:
# FreeCAD.ActiveDocument.removeObject(tmpNm)
@@ -610,7 +616,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
def getExtensions(self, obj):
extensions = []
i = 0
for extObj,features in obj.ExtensionFeature:
for extObj, features in obj.ExtensionFeature:
for sub in features:
extFeature, extSub = sub.split(':')
extensions.append(self.createExtension(obj, extObj, extFeature, extSub))
@@ -681,7 +687,7 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
precision = i
break
# Sub Surface.Axis values of faces
# Sub Surface.Axis values of faces
# Vector of (0, 0, 0) will suggests a loop
for sub in subsList:
if 'Face' in sub:
@@ -793,9 +799,9 @@ 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)
proxy = ObjectPocket(obj, name)
obj.proxy = ObjectPocket(obj, name)
return obj

View File

@@ -32,7 +32,7 @@ import ArchPanel
import FreeCAD
import Part
import Path
import PathScripts.PathAreaOp as PathAreaOp
# import PathScripts.PathAreaOp as PathAreaOp
import PathScripts.PathLog as PathLog
import PathScripts.PathOp as PathOp
import PathScripts.PathProfileBase as PathProfileBase
@@ -58,6 +58,8 @@ else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
@@ -122,7 +124,7 @@ class ObjectProfile(PathProfileBase.ObjectProfile):
if isinstance(shape, Part.Face):
rtn = False
(norm, surf) = self.getFaceNormAndSurf(shape)
(rtn, angle, axis, praInfo)= self.faceRotationAnalysis(obj, norm, surf)
(rtn, angle, axis, praInfo) = self.faceRotationAnalysis(obj, norm, surf)
if rtn is True:
(clnBase, angle, clnStock, tag) = self.applyRotationalAnalysis(obj, base, angle, axis, subCount)
# Verify faces are correctly oriented - InverseAngle might be necessary
@@ -159,9 +161,9 @@ class ObjectProfile(PathProfileBase.ObjectProfile):
msg = translate('Path', "Multiple faces in Base Geometry.") + " "
msg += translate('Path', "Depth settings will be applied to all faces.")
PathLog.warning(msg)
#title = translate("Path", "Depth Warning")
#self.guiMessage(title, msg)
(Tags, Grps) = self.sortTuplesByIndex(allTuples, 2) # return (TagList, GroupList)
# title = translate("Path", "Depth Warning")
# self.guiMessage(title, msg)
(Tags, Grps) = self.sortTuplesByIndex(allTuples, 2) # return (TagList, GroupList)
subList = []
for o in range(0, len(Tags)):
subList = []
@@ -169,7 +171,7 @@ class ObjectProfile(PathProfileBase.ObjectProfile):
subList.append(sub)
pair = base, subList, angle, axis, stock
baseSubsTuples.append(pair)
# Efor
# Efor
else:
PathLog.info(translate("Path", "EnableRotation property is 'Off'."))
stock = PathUtils.findParentJob(obj).Stock
@@ -194,7 +196,7 @@ class ObjectProfile(PathProfileBase.ObjectProfile):
PathLog.error(msg)
FreeCAD.Console.PrintWarning(msg)
# return
for shape, wire in holes:
f = Part.makeFace(wire, 'Part::FaceMakerSimple')
drillable = PathUtils.isDrillable(shape, wire)
@@ -208,10 +210,10 @@ class ObjectProfile(PathProfileBase.ObjectProfile):
self.depthparams = PathUtils.depth_params(
clearance_height=obj.ClearanceHeight.Value,
safe_height=obj.SafeHeight.Value,
start_depth=strDep, #obj.StartDepth.Value,
start_depth=strDep, # obj.StartDepth.Value,
step_down=obj.StepDown.Value,
z_finish_step=finish_step,
final_depth=finDep, #obj.FinalDepth.Value,
final_depth=finDep, # obj.FinalDepth.Value,
user_depths=None)
env = PathUtils.getEnvelope(shape, subshape=f, depthparams=self.depthparams)
# shapes.append((env, True))
@@ -233,17 +235,17 @@ class ObjectProfile(PathProfileBase.ObjectProfile):
self.depthparams = PathUtils.depth_params(
clearance_height=obj.ClearanceHeight.Value,
safe_height=obj.SafeHeight.Value,
start_depth=strDep, #obj.StartDepth.Value,
start_depth=strDep, # obj.StartDepth.Value,
step_down=obj.StepDown.Value,
z_finish_step=finish_step,
final_depth=finDep, #obj.FinalDepth.Value,
final_depth=finDep, # obj.FinalDepth.Value,
user_depths=None)
else:
strDep = obj.StartDepth.Value
finDep = obj.FinalDepth.Value
try:
env = PathUtils.getEnvelope(base.Shape, subshape=profileshape, depthparams=self.depthparams)
except Exception as ee:
except Exception:
# PathUtils.getEnvelope() failed to return an object.
PathLog.error(translate('Path', 'Unable to create path for face(s).'))
else:
@@ -259,10 +261,10 @@ class ObjectProfile(PathProfileBase.ObjectProfile):
self.depthparams = PathUtils.depth_params(
clearance_height=obj.ClearanceHeight.Value,
safe_height=obj.SafeHeight.Value,
start_depth=strDep, #obj.StartDepth.Value,
start_depth=strDep, # obj.StartDepth.Value,
step_down=obj.StepDown.Value,
z_finish_step=finish_step,
final_depth=finDep, #obj.FinalDepth.Value,
final_depth=finDep, # obj.FinalDepth.Value,
user_depths=None)
env = PathUtils.getEnvelope(base.Shape, subshape=shape, depthparams=self.depthparams)
tup = env, False, 'pathProfileFaces', angle, axis, strDep, finDep
@@ -325,9 +327,10 @@ def SetupProperties():
setup.append("AttemptInverseAngle")
return setup
def Create(name, obj = None):
def Create(name, obj=None):
'''Create(name) ... Creates and returns a Profile based on faces operation.'''
if obj is None:
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name)
proxy = ObjectProfile(obj, name)
obj.Proxy = ObjectProfile(obj, name)
return obj