Skip to content

Commit

Permalink
Path: PEP8 and Proxy changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sliptonic committed Jun 17, 2019
1 parent 4296df8 commit d4a311d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 54 deletions.
44 changes: 24 additions & 20 deletions src/Mod/Path/PathScripts/PathAreaOp.py
Expand Up @@ -63,6 +63,8 @@
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())

# Qt translation handling


def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)

Expand Down Expand Up @@ -106,9 +108,11 @@ def initOperation(self, obj):
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):
Expand Down Expand Up @@ -166,12 +170,12 @@ def opOnDocumentRestored(self, obj):
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)
Expand All @@ -186,7 +190,7 @@ def opSetDefaultValues(self, obj, job):
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'):
Expand Down Expand Up @@ -338,7 +342,7 @@ def opExecute(self, obj, getsim=False):
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

Expand Down Expand Up @@ -374,7 +378,7 @@ def opExecute(self, obj, getsim=False):
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:
Expand Down Expand Up @@ -496,7 +500,7 @@ def opExecute(self, obj, getsim=False):
self.commandlist.extend(ppCmds)
sims.append(sim)
# Eif

if self.areaOpRetractTool(obj):
self.endVector = None

Expand Down Expand Up @@ -735,7 +739,7 @@ def visualAxis(self):
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")
Expand All @@ -745,11 +749,11 @@ def visualAxis(self):
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)
Expand All @@ -759,15 +763,15 @@ def visualAxis(self):
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)
Expand All @@ -778,7 +782,7 @@ def visualAxis(self):
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)
Expand All @@ -798,7 +802,7 @@ def useTempJobClones(self, cloneName):
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

Expand All @@ -817,8 +821,8 @@ def cloneBaseAndStock(self, obj, base, angle, axis, subCount):
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)
Expand All @@ -829,11 +833,11 @@ def cloneBaseAndStock(self, obj, base, angle, axis, subCount):
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)
Expand Down
42 changes: 24 additions & 18 deletions src/Mod/Path/PathScripts/PathPocketShape.py
Expand Up @@ -59,9 +59,12 @@
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):
Expand All @@ -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'''
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -143,7 +150,7 @@ def getSubLink(self):
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)
Expand Down Expand Up @@ -372,9 +379,9 @@ def clasifySub(self, bs, sub):
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)
Expand All @@ -387,7 +394,7 @@ def clasifySub(self, bs, sub):
(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:
Expand All @@ -413,7 +420,7 @@ def clasifySub(self, bs, sub):

# --------------------------------------------------------
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)
Expand All @@ -427,7 +434,7 @@ def clasifySub(self, bs, sub):
# --------------------------------------------------------

(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', '')
Expand Down Expand Up @@ -464,7 +471,7 @@ def clasifySub(self, bs, sub):
# 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 = []
Expand All @@ -478,7 +485,6 @@ def clasifySub(self, bs, sub):
baseSubsTuples.append(pair)
# ----------------------------------------------------------------------


for o in baseSubsTuples:
self.horiz = []
self.vert = []
Expand Down Expand Up @@ -559,7 +565,7 @@ def clasifySub(self, bs, sub):

# Adjust obj.FinalDepth.Value as needed.
if len(finalDepths) > 0:
finalDep = min(finalDepths)
finalDepths = min(finalDepths)
if subCount == 1:
obj.FinalDepth.Value = finDep
else:
Expand All @@ -580,13 +586,13 @@ def clasifySub(self, bs, sub):
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)

Expand All @@ -610,7 +616,7 @@ def createExtension(self, obj, extObj, extFeature, extSub):
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))
Expand Down Expand Up @@ -681,7 +687,7 @@ def roundValue(precision, val):
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:
Expand Down Expand Up @@ -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

0 comments on commit d4a311d

Please sign in to comment.