Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #3916 from Russ4262/fix_PocketShape
Path: Pocket_Shape - Improved fixes for FinalDepth and rotational issues
  • Loading branch information
sliptonic committed Nov 17, 2020
2 parents 2cfd04d + d3c3a11 commit 48d5ab5
Show file tree
Hide file tree
Showing 2 changed files with 414 additions and 329 deletions.
81 changes: 50 additions & 31 deletions src/Mod/Path/PathScripts/PathAreaOp.py
Expand Up @@ -290,7 +290,6 @@ def _buildProfileOpenEdges(self, obj, edgeList, isHole, start, getsim):
paths = []
heights = [i for i in self.depthparams]
PathLog.debug('depths: {}'.format(heights))
lstIdx = len(heights) - 1
for i in range(0, len(heights)):
for baseShape in edgeList:
hWire = Part.Wire(Part.__sortEdges__(baseShape.Edges))
Expand Down Expand Up @@ -323,14 +322,8 @@ def _buildProfileOpenEdges(self, obj, edgeList, isHole, start, getsim):
paths.extend(pp.Commands)
PathLog.debug('pp: {}, end vector: {}'.format(pp, end_vector))

self.endVector = end_vector # pylint: disable=attribute-defined-outside-init

self.endVector = end_vector
simobj = None
if getsim and False:
areaParams['ToolRadius'] = self.radius - self.radius * .005
area.setParams(**areaParams)
sec = area.makeSections(mode=0, project=False, heights=heights)[-1].getShape()
simobj = sec.extrude(FreeCAD.Vector(0, 0, baseobject.BoundBox.ZMax))

return paths, simobj

Expand All @@ -356,6 +349,8 @@ def opExecute(self, obj, getsim=False): # pylint: disable=arguments-differ
self.useTempJobClones('Delete') # Clear temporary group and recreate for temp job clones
self.rotStartDepth = None # pylint: disable=attribute-defined-outside-init

start_depth = obj.StartDepth.Value
final_depth = obj.FinalDepth.Value
if obj.EnableRotation != 'Off':
# Calculate operation heights based upon rotation radii
opHeights = self.opDetermineRotationRadii(obj)
Expand All @@ -364,28 +359,28 @@ def opExecute(self, obj, getsim=False): # pylint: disable=arguments-differ

# Set clearance and safe heights based upon rotation radii
if obj.EnableRotation == 'A(x)':
strDep = self.xRotRad
start_depth = self.xRotRad
elif obj.EnableRotation == 'B(y)':
strDep = self.yRotRad
start_depth = self.yRotRad
else:
strDep = max(self.xRotRad, self.yRotRad)
finDep = -1 * strDep
start_depth = max(self.xRotRad, self.yRotRad)
final_depth = -1 * start_depth

self.rotStartDepth = strDep
obj.ClearanceHeight.Value = strDep + self.clrOfset
obj.SafeHeight.Value = strDep + self.safOfst
self.rotStartDepth = start_depth
# The next two lines are improper code.
# The ClearanceHeight and SafeHeight need to be set in opSetDefaultValues() method.
# They should not be redefined here, so this entire `if...:` statement needs relocated.
obj.ClearanceHeight.Value = start_depth + self.clrOfset
obj.SafeHeight.Value = start_depth + self.safOfst

# Create visual axes when debugging.
if PathLog.getLevel(PathLog.thisModule()) == 4:
self.visualAxis()
else:
strDep = obj.StartDepth.Value
finDep = obj.FinalDepth.Value

# Set axial feed rates based upon horizontal feed rates
safeCircum = 2 * math.pi * obj.SafeHeight.Value
self.axialFeed = 360 / safeCircum * self.horizFeed # pylint: disable=attribute-defined-outside-init
self.axialRapid = 360 / safeCircum * self.horizRapid # pylint: disable=attribute-defined-outside-init
# Set axial feed rates based upon horizontal feed rates
safeCircum = 2 * math.pi * obj.SafeHeight.Value
self.axialFeed = 360 / safeCircum * self.horizFeed # pylint: disable=attribute-defined-outside-init
self.axialRapid = 360 / safeCircum * self.horizRapid # pylint: disable=attribute-defined-outside-init

# Initiate depthparams and calculate operation heights for rotational operation
self.depthparams = self._customDepthParams(obj, obj.StartDepth.Value, obj.FinalDepth.Value)
Expand All @@ -403,8 +398,8 @@ def opExecute(self, obj, getsim=False): # pylint: disable=arguments-differ
for shp in aOS:
if len(shp) == 2:
(fc, iH) = shp
# fc, iH, sub, angle, axis, strtDep, finDep
tup = fc, iH, 'otherOp', 0.0, 'S', obj.StartDepth.Value, obj.FinalDepth.Value
# fc, iH, sub, angle, axis, strtDep, finDep
tup = fc, iH, 'otherOp', 0.0, 'S', start_depth, final_depth
shapes.append(tup)
else:
shapes.append(shp)
Expand Down Expand Up @@ -985,19 +980,43 @@ def warnDisabledAxis(self, obj, axis, sub=''):
return False

def isFaceUp(self, base, face):
'''isFaceUp(base, face) ...
When passed a base object and face shape, returns True if face is up.
This method is used to identify correct rotation of a model.
'''
# verify face is normal to Z+-
(norm, surf) = self.getFaceNormAndSurf(face)
if round(abs(norm.z), 8) != 1.0 or round(abs(surf.z), 8) != 1.0:
PathLog.debug('isFaceUp - face not oriented normal to Z+-')
return False

up = face.extrude(FreeCAD.Vector(0.0, 0.0, 5.0))
dwn = face.extrude(FreeCAD.Vector(0.0, 0.0, -5.0))
upCmn = base.Shape.common(up)
dwnCmn = base.Shape.common(dwn)

# Identify orientation based on volumes of common() results
if len(upCmn.Edges) > 0 and round(upCmn.Volume, 6) == 0.0:
return True
elif len(dwnCmn.Edges) > 0 and round(dwnCmn.Volume, 6) == 0.0:
return False
if (len(upCmn.Edges) > 0 and len(dwnCmn.Edges) > 0 and
round(dwnCmn.Volume, 6) > round(upCmn.Volume, 6)):
if len(upCmn.Edges) > 0:
PathLog.debug('isFaceUp - HAS up edges\n')
if len(dwnCmn.Edges) > 0:
PathLog.debug('isFaceUp - up and dwn edges\n')
dVol = round(dwnCmn.Volume, 6)
uVol = round(upCmn.Volume, 6)
if uVol > dVol:
return False
return True
else:
if round(upCmn.Volume, 6) == 0.0:
return True
return False
elif len(dwnCmn.Edges) > 0:
PathLog.debug('isFaceUp - HAS dwn edges only\n')
dVol = round(dwnCmn.Volume, 6)
if dVol == 0.0:
return False
return True
return False
PathLog.debug('isFaceUp - exit True\n')
return True

def _customDepthParams(self, obj, strDep, finDep):
finish_step = obj.FinishDepth.Value if hasattr(obj, "FinishDepth") else 0.0
Expand Down

0 comments on commit 48d5ab5

Please sign in to comment.