Path: Remove first-draft rotational code Path
Remove all first-draft rotational-related code from Path workbench to make way for more stable, long-term integration of a rotational indexing capability.
This commit is contained in:
@@ -41,12 +41,11 @@ __title__ = "Base class for PathArea based operations."
|
||||
__author__ = "sliptonic (Brad Collette)"
|
||||
__url__ = "https://www.freecadweb.org"
|
||||
__doc__ = "Base class and properties for Path.Area based operations."
|
||||
__contributors__ = "russ4262 (Russell Johnson)"
|
||||
|
||||
LOGLEVEL = PathLog.Level.INFO
|
||||
PathLog.setLevel(LOGLEVEL, PathLog.thisModule())
|
||||
|
||||
if LOGLEVEL is PathLog.Level.DEBUG:
|
||||
PathLog.trackModule()
|
||||
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
|
||||
# PathLog.trackModule(PathLog.thisModule())
|
||||
|
||||
|
||||
# Qt translation handling
|
||||
@@ -66,7 +65,9 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
'''opFeatures(obj) ... returns the base features supported by all Path.Area based operations.
|
||||
The standard feature list is OR'ed with the return value of areaOpFeatures().
|
||||
Do not overwrite, implement areaOpFeatures(obj) instead.'''
|
||||
return PathOp.FeatureTool | PathOp.FeatureDepths | PathOp.FeatureStepDown | PathOp.FeatureHeights | PathOp.FeatureStartPoint | self.areaOpFeatures(obj) | PathOp.FeatureCoolant
|
||||
return PathOp.FeatureTool | PathOp.FeatureDepths | PathOp.FeatureStepDown \
|
||||
| PathOp.FeatureHeights | PathOp.FeatureStartPoint \
|
||||
| self.areaOpFeatures(obj) | PathOp.FeatureCoolant
|
||||
|
||||
def areaOpFeatures(self, obj):
|
||||
'''areaOpFeatures(obj) ... overwrite to add operation specific features.
|
||||
@@ -79,9 +80,6 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
Do not overwrite, overwrite initAreaOp(obj) instead.'''
|
||||
PathLog.track()
|
||||
|
||||
# These are static while document is open, if it contains a 3D Surface Op
|
||||
self.initWithRotation = False
|
||||
|
||||
# Debugging
|
||||
obj.addProperty("App::PropertyString", "AreaParams", "Path")
|
||||
obj.setEditorMode('AreaParams', 2) # hide
|
||||
@@ -89,16 +87,9 @@ 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):
|
||||
if not hasattr(obj, 'EnableRotation'):
|
||||
obj.addProperty("App::PropertyEnumeration", "EnableRotation", "Rotation", QtCore.QT_TRANSLATE_NOOP("App::Property", "Enable rotation to gain access to pockets/areas not normal to Z axis."))
|
||||
obj.EnableRotation = ['Off', 'A(x)', 'B(y)', 'A & B']
|
||||
|
||||
def initAreaOp(self, obj):
|
||||
'''initAreaOp(obj) ... overwrite if the receiver class needs initialisation.
|
||||
Can safely be overwritten by subclasses.'''
|
||||
@@ -150,7 +141,6 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
if hasattr(obj, prop):
|
||||
obj.setEditorMode(prop, 2)
|
||||
|
||||
self.setupAdditionalProperties(obj)
|
||||
self.areaOpOnDocumentRestored(obj)
|
||||
|
||||
def areaOpOnDocumentRestored(self, obj):
|
||||
@@ -164,14 +154,6 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
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'):
|
||||
obj.EnableRotation = job.SetupSheet.SetupEnableRotation
|
||||
else:
|
||||
obj.EnableRotation = 'Off'
|
||||
PathLog.debug("opSetDefaultValues(): Enable Rotation: {}".format(obj.EnableRotation))
|
||||
|
||||
if PathOp.FeatureDepths & self.opFeatures(obj):
|
||||
try:
|
||||
shape = self.areaOpShapeForDepths(obj, job)
|
||||
@@ -189,26 +171,8 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
startDepth = bb.ZMax
|
||||
finalDepth = bb.ZMin
|
||||
|
||||
# Adjust start and final depths if rotation is enabled
|
||||
if obj.EnableRotation != 'Off':
|
||||
self.initWithRotation = True
|
||||
self.stockBB = PathUtils.findParentJob(obj).Stock.Shape.BoundBox # pylint: disable=attribute-defined-outside-init
|
||||
# Calculate rotational distances/radii
|
||||
opHeights = self.opDetermineRotationRadii(obj) # return is list with tuples [(xRotRad, yRotRad, zRotRad), (clrOfst, safOfset)]
|
||||
(xRotRad, yRotRad, zRotRad) = opHeights[0] # pylint: disable=unused-variable
|
||||
PathLog.debug("opHeights[0]: " + str(opHeights[0]))
|
||||
PathLog.debug("opHeights[1]: " + str(opHeights[1]))
|
||||
|
||||
if obj.EnableRotation == 'A(x)':
|
||||
startDepth = xRotRad
|
||||
if obj.EnableRotation == 'B(y)':
|
||||
startDepth = yRotRad
|
||||
else:
|
||||
startDepth = max(xRotRad, yRotRad)
|
||||
finalDepth = -1 * startDepth
|
||||
|
||||
obj.StartDepth.Value = startDepth
|
||||
obj.FinalDepth.Value = finalDepth
|
||||
# obj.StartDepth.Value = startDepth
|
||||
# obj.FinalDepth.Value = finalDepth
|
||||
obj.OpStartDepth.Value = startDepth
|
||||
obj.OpFinalDepth.Value = finalDepth
|
||||
|
||||
@@ -338,49 +302,9 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
|
||||
# Instantiate class variables for operation reference
|
||||
self.endVector = None # pylint: disable=attribute-defined-outside-init
|
||||
self.rotateFlag = False # pylint: disable=attribute-defined-outside-init
|
||||
self.leadIn = 2.0 # pylint: disable=attribute-defined-outside-init
|
||||
self.cloneNames = [] # pylint: disable=attribute-defined-outside-init
|
||||
self.guiMsgs = [] # pylint: disable=attribute-defined-outside-init
|
||||
self.tempObjectNames = [] # pylint: disable=attribute-defined-outside-init
|
||||
self.stockBB = PathUtils.findParentJob(obj).Stock.Shape.BoundBox # pylint: disable=attribute-defined-outside-init
|
||||
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)
|
||||
(self.xRotRad, self.yRotRad, self.zRotRad) = opHeights[0] # pylint: disable=attribute-defined-outside-init
|
||||
(self.clrOfset, self.safOfst) = opHeights[1] # pylint: disable=attribute-defined-outside-init
|
||||
|
||||
# Set clearance and safe heights based upon rotation radii
|
||||
if obj.EnableRotation == 'A(x)':
|
||||
start_depth = self.xRotRad
|
||||
elif obj.EnableRotation == 'B(y)':
|
||||
start_depth = self.yRotRad
|
||||
else:
|
||||
start_depth = max(self.xRotRad, self.yRotRad)
|
||||
final_depth = -1 * start_depth
|
||||
|
||||
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()
|
||||
|
||||
# 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
|
||||
# Initiate depthparams and calculate operation heights for operation
|
||||
self.depthparams = self._customDepthParams(obj, obj.StartDepth.Value, obj.FinalDepth.Value)
|
||||
|
||||
# Set start point
|
||||
@@ -391,13 +315,13 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
|
||||
aOS = self.areaOpShapes(obj) # pylint: disable=assignment-from-no-return
|
||||
|
||||
# Adjust tuples length received from other PathWB tools/operations beside PathPocketShape
|
||||
# Adjust tuples length received from other PathWB tools/operations
|
||||
shapes = []
|
||||
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', start_depth, final_depth
|
||||
# fc, iH, sub or description
|
||||
tup = fc, iH, 'otherOp'
|
||||
shapes.append(tup)
|
||||
else:
|
||||
shapes.append(shp)
|
||||
@@ -420,23 +344,15 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
shapes = [j['shape'] for j in jobs]
|
||||
|
||||
sims = []
|
||||
numShapes = len(shapes)
|
||||
for ns in range(0, numShapes):
|
||||
for shape, isHole, sub in shapes:
|
||||
profileEdgesIsOpen = False
|
||||
(shape, isHole, sub, angle, axis, strDep, finDep) = shapes[ns] # pylint: disable=unused-variable
|
||||
|
||||
if sub == 'OpenEdge':
|
||||
profileEdgesIsOpen = True
|
||||
if PathOp.FeatureStartPoint & self.opFeatures(obj) and obj.UseStartPoint:
|
||||
osp = obj.StartPoint
|
||||
self.commandlist.append(Path.Command('G0', {'X': osp.x, 'Y': osp.y, 'F': self.horizRapid}))
|
||||
|
||||
if ns < numShapes - 1:
|
||||
nextAxis = shapes[ns + 1][4]
|
||||
else:
|
||||
nextAxis = 'L'
|
||||
|
||||
self.depthparams = self._customDepthParams(obj, strDep, finDep)
|
||||
|
||||
try:
|
||||
if profileEdgesIsOpen:
|
||||
(pp, sim) = self._buildProfileOpenEdges(obj, shape, isHole, start, getsim)
|
||||
@@ -450,28 +366,6 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
ppCmds = pp
|
||||
else:
|
||||
ppCmds = pp.Commands
|
||||
if obj.EnableRotation != 'Off' and self.rotateFlag is True:
|
||||
# Rotate model to index for cut
|
||||
if axis == 'X':
|
||||
axisOfRot = 'A'
|
||||
elif axis == 'Y':
|
||||
axisOfRot = 'B'
|
||||
elif axis == 'Z':
|
||||
axisOfRot = 'C'
|
||||
else:
|
||||
axisOfRot = 'A'
|
||||
# Rotate Model to correct angle
|
||||
ppCmds.insert(0, Path.Command('G0', {axisOfRot: angle, 'F': self.axialRapid}))
|
||||
|
||||
# Raise cutter to safe height
|
||||
ppCmds.insert(0, Path.Command('G0', {'Z': obj.SafeHeight.Value, 'F': self.vertRapid}))
|
||||
|
||||
# Return index to starting position if axis of rotation changes.
|
||||
if numShapes > 1:
|
||||
if ns != numShapes - 1:
|
||||
if axis != nextAxis:
|
||||
ppCmds.append(Path.Command('G0', {axisOfRot: 0.0, 'F': self.axialRapid}))
|
||||
# Eif
|
||||
|
||||
# Save gcode commands to object command list
|
||||
self.commandlist.extend(ppCmds)
|
||||
@@ -482,51 +376,6 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
self.endVector[2] = obj.ClearanceHeight.Value
|
||||
self.commandlist.append(Path.Command('G0', {'Z': obj.ClearanceHeight.Value, 'F': self.vertRapid}))
|
||||
|
||||
# Raise cutter to safe height and rotate back to original orientation
|
||||
# based on next rotational operation in job
|
||||
if self.rotateFlag is True:
|
||||
resetAxis = False
|
||||
lastJobOp = None
|
||||
nextJobOp = None
|
||||
opIdx = 0
|
||||
JOB = PathUtils.findParentJob(obj)
|
||||
jobOps = JOB.Operations.Group
|
||||
numJobOps = len(jobOps)
|
||||
|
||||
for joi in range(0, numJobOps):
|
||||
jo = jobOps[joi]
|
||||
if jo.Name == obj.Name:
|
||||
opIdx = joi
|
||||
lastOpIdx = opIdx - 1
|
||||
nextOpIdx = opIdx + 1
|
||||
if lastOpIdx > -1:
|
||||
lastJobOp = jobOps[lastOpIdx]
|
||||
if nextOpIdx < numJobOps:
|
||||
nextJobOp = jobOps[nextOpIdx]
|
||||
|
||||
if lastJobOp is not None:
|
||||
if hasattr(lastJobOp, 'EnableRotation'):
|
||||
PathLog.debug('Last Op, {}, has `EnableRotation` set to {}'.format(lastJobOp.Label, lastJobOp.EnableRotation))
|
||||
if lastJobOp.EnableRotation != obj.EnableRotation:
|
||||
resetAxis = True
|
||||
# if ns == numShapes - 1: # If last shape, check next op EnableRotation setting
|
||||
if nextJobOp is not None:
|
||||
if hasattr(nextJobOp, 'EnableRotation'):
|
||||
PathLog.debug('Next Op, {}, has `EnableRotation` set to {}'.format(nextJobOp.Label, nextJobOp.EnableRotation))
|
||||
if nextJobOp.EnableRotation != obj.EnableRotation:
|
||||
resetAxis = True
|
||||
|
||||
# Raise to safe height if rotation activated
|
||||
self.commandlist.append(Path.Command('G0', {'Z': obj.SafeHeight.Value, 'F': self.vertRapid}))
|
||||
# reset rotational axes if necessary
|
||||
if resetAxis is True:
|
||||
self.commandlist.append(Path.Command('G0', {'A': 0.0, 'F': self.axialRapid}))
|
||||
self.commandlist.append(Path.Command('G0', {'B': 0.0, 'F': self.axialRapid}))
|
||||
|
||||
self.useTempJobClones('Delete') # Delete temp job clone group and contents
|
||||
self.guiMessage('title', None, show=True) # Process GUI messages to user
|
||||
for ton in self.tempObjectNames: # remove temporary objects by name
|
||||
FreeCAD.ActiveDocument.removeObject(ton)
|
||||
PathLog.debug("obj.Name: " + str(obj.Name) + "\n\n")
|
||||
return sims
|
||||
|
||||
@@ -561,461 +410,7 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
# pylint: disable=unused-argument
|
||||
return False
|
||||
|
||||
# Rotation-related methods
|
||||
def opDetermineRotationRadii(self, obj):
|
||||
'''opDetermineRotationRadii(obj)
|
||||
Determine rotational radii for 4th-axis rotations, for clearance/safe heights '''
|
||||
|
||||
parentJob = PathUtils.findParentJob(obj)
|
||||
xlim = 0.0
|
||||
ylim = 0.0
|
||||
|
||||
# Determine boundbox radius based upon xzy limits data
|
||||
if math.fabs(self.stockBB.ZMin) > math.fabs(self.stockBB.ZMax):
|
||||
zlim = self.stockBB.ZMin
|
||||
else:
|
||||
zlim = self.stockBB.ZMax
|
||||
|
||||
if obj.EnableRotation != 'B(y)':
|
||||
# Rotation is around X-axis, cutter moves along same axis
|
||||
if math.fabs(self.stockBB.YMin) > math.fabs(self.stockBB.YMax):
|
||||
ylim = self.stockBB.YMin
|
||||
else:
|
||||
ylim = self.stockBB.YMax
|
||||
|
||||
if obj.EnableRotation != 'A(x)':
|
||||
# Rotation is around Y-axis, cutter moves along same axis
|
||||
if math.fabs(self.stockBB.XMin) > math.fabs(self.stockBB.XMax):
|
||||
xlim = self.stockBB.XMin
|
||||
else:
|
||||
xlim = self.stockBB.XMax
|
||||
|
||||
xRotRad = math.sqrt(ylim**2 + zlim**2)
|
||||
yRotRad = math.sqrt(xlim**2 + zlim**2)
|
||||
zRotRad = math.sqrt(xlim**2 + ylim**2)
|
||||
|
||||
clrOfst = parentJob.SetupSheet.ClearanceHeightOffset.Value
|
||||
safOfst = parentJob.SetupSheet.SafeHeightOffset.Value
|
||||
|
||||
return [(xRotRad, yRotRad, zRotRad), (clrOfst, safOfst)]
|
||||
|
||||
def faceRotationAnalysis(self, obj, norm, surf):
|
||||
'''faceRotationAnalysis(obj, norm, surf)
|
||||
Determine X and Y independent rotation necessary to make normalAt = Z=1 (0,0,1) '''
|
||||
PathLog.track()
|
||||
|
||||
praInfo = "faceRotationAnalysis()"
|
||||
rtn = True
|
||||
orientation = 'X'
|
||||
angle = 500.0
|
||||
precision = 6
|
||||
|
||||
for i in range(0, 13):
|
||||
if PathGeom.Tolerance * (i * 10) == 1.0:
|
||||
precision = i
|
||||
break
|
||||
|
||||
def roundRoughValues(precision, val):
|
||||
# Convert VALxe-15 numbers to zero
|
||||
if PathGeom.isRoughly(0.0, val) is True:
|
||||
return 0.0
|
||||
# Convert VAL.99999999 to next integer
|
||||
elif math.fabs(val % 1) > 1.0 - PathGeom.Tolerance:
|
||||
return round(val)
|
||||
else:
|
||||
return round(val, precision)
|
||||
|
||||
nX = roundRoughValues(precision, norm.x)
|
||||
nY = roundRoughValues(precision, norm.y)
|
||||
nZ = roundRoughValues(precision, norm.z)
|
||||
praInfo += "\n -normalAt(0,0): " + str(nX) + ", " + str(nY) + ", " + str(nZ)
|
||||
|
||||
saX = roundRoughValues(precision, surf.x)
|
||||
saY = roundRoughValues(precision, surf.y)
|
||||
saZ = roundRoughValues(precision, surf.z)
|
||||
praInfo += "\n -Surface.Axis: " + str(saX) + ", " + str(saY) + ", " + str(saZ)
|
||||
|
||||
# Determine rotation needed and current orientation
|
||||
if saX == 0.0:
|
||||
if saY == 0.0:
|
||||
orientation = "Z"
|
||||
if saZ == 1.0:
|
||||
angle = 0.0
|
||||
elif saZ == -1.0:
|
||||
angle = -180.0
|
||||
else:
|
||||
praInfo += "_else_X" + str(saZ)
|
||||
elif saY == 1.0:
|
||||
orientation = "Y"
|
||||
angle = 90.0
|
||||
elif saY == -1.0:
|
||||
orientation = "Y"
|
||||
angle = -90.0
|
||||
else:
|
||||
if saZ != 0.0:
|
||||
angle = math.degrees(math.atan(saY / saZ))
|
||||
orientation = "Y"
|
||||
elif saY == 0.0:
|
||||
if saZ == 0.0:
|
||||
orientation = "X"
|
||||
if saX == 1.0:
|
||||
angle = -90.0
|
||||
elif saX == -1.0:
|
||||
angle = 90.0
|
||||
else:
|
||||
praInfo += "_else_X" + str(saX)
|
||||
else:
|
||||
orientation = "X"
|
||||
ratio = saX / saZ
|
||||
angle = math.degrees(math.atan(ratio))
|
||||
if ratio < 0.0:
|
||||
praInfo += " NEG-ratio"
|
||||
# angle -= 90
|
||||
else:
|
||||
praInfo += " POS-ratio"
|
||||
angle = -1 * angle
|
||||
if saX < 0.0:
|
||||
angle = angle + 180.0
|
||||
elif saZ == 0.0:
|
||||
# if saY != 0.0:
|
||||
angle = math.degrees(math.atan(saX / saY))
|
||||
orientation = "Y"
|
||||
|
||||
if saX + nX == 0.0:
|
||||
angle = -1 * angle
|
||||
if saY + nY == 0.0:
|
||||
angle = -1 * angle
|
||||
if saZ + nZ == 0.0:
|
||||
angle = -1 * angle
|
||||
|
||||
if saY == -1.0 or saY == 1.0:
|
||||
if nX != 0.0:
|
||||
angle = -1 * angle
|
||||
|
||||
# Enforce enabled rotation in settings
|
||||
praInfo += "\n -Initial orientation: {}".format(orientation)
|
||||
if orientation == 'Y':
|
||||
axis = 'X'
|
||||
if obj.EnableRotation == 'B(y)': # Required axis disabled
|
||||
if angle == 180.0 or angle == -180.0:
|
||||
axis = 'Y'
|
||||
else:
|
||||
rtn = False
|
||||
elif orientation == 'X':
|
||||
axis = 'Y'
|
||||
if obj.EnableRotation == 'A(x)': # Required axis disabled
|
||||
if angle == 180.0 or angle == -180.0:
|
||||
axis = 'X'
|
||||
else:
|
||||
rtn = False
|
||||
elif orientation == 'Z':
|
||||
axis = 'X'
|
||||
|
||||
if math.fabs(angle) == 0.0:
|
||||
angle = 0.0
|
||||
rtn = False
|
||||
|
||||
if angle == 500.0:
|
||||
angle = 0.0
|
||||
rtn = False
|
||||
|
||||
if rtn is False:
|
||||
if orientation == 'Z' and angle == 0.0 and obj.ReverseDirection is True:
|
||||
if obj.EnableRotation == 'B(y)':
|
||||
axis = 'Y'
|
||||
rtn = True
|
||||
|
||||
if rtn is True:
|
||||
self.rotateFlag = True # pylint: disable=attribute-defined-outside-init
|
||||
if obj.ReverseDirection is True:
|
||||
if angle < 180.0:
|
||||
angle = angle + 180.0
|
||||
else:
|
||||
angle = angle - 180.0
|
||||
angle = round(angle, precision)
|
||||
|
||||
praInfo += "\n -Rotation analysis: angle: " + str(angle) + ", axis: " + str(axis)
|
||||
if rtn is True:
|
||||
praInfo += "\n - ... rotation triggered"
|
||||
else:
|
||||
praInfo += "\n - ... NO rotation triggered"
|
||||
|
||||
return (rtn, angle, axis, praInfo)
|
||||
|
||||
def guiMessage(self, title, msg, show=False):
|
||||
'''guiMessage(title, msg, show=False)
|
||||
Handle op related GUI messages to user'''
|
||||
if msg is not None:
|
||||
self.guiMsgs.append((title, msg))
|
||||
if show is True:
|
||||
if len(self.guiMsgs) > 0:
|
||||
if FreeCAD.GuiUp:
|
||||
from PySide.QtGui import QMessageBox
|
||||
for entry in self.guiMsgs:
|
||||
(title, msg) = entry
|
||||
QMessageBox.warning(None, title, msg)
|
||||
self.guiMsgs = [] # pylint: disable=attribute-defined-outside-init
|
||||
return True
|
||||
else:
|
||||
for entry in self.guiMsgs:
|
||||
(title, msg) = entry
|
||||
PathLog.warning("{}:: {}".format(title, msg))
|
||||
self.guiMsgs = [] # pylint: disable=attribute-defined-outside-init
|
||||
return True
|
||||
return False
|
||||
|
||||
def visualAxis(self):
|
||||
'''visualAxis()
|
||||
Create visual X & Y axis for use in orientation of rotational operations
|
||||
Triggered only for PathLog.debug'''
|
||||
|
||||
if not FreeCAD.ActiveDocument.getObject('xAxCyl'):
|
||||
xAx = 'xAxCyl'
|
||||
yAx = 'yAxCyl'
|
||||
# zAx = 'zAxCyl'
|
||||
VA = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "visualAxis")
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.ActiveDocument.getObject('visualAxis').Visibility = False
|
||||
vaGrp = FreeCAD.ActiveDocument.getObject("visualAxis")
|
||||
|
||||
FreeCAD.ActiveDocument.addObject("Part::Cylinder", xAx)
|
||||
cyl = FreeCAD.ActiveDocument.getObject(xAx)
|
||||
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.purgeTouched()
|
||||
if FreeCAD.GuiUp:
|
||||
cylGui = FreeCADGui.ActiveDocument.getObject(xAx)
|
||||
cylGui.ShapeColor = (0.667, 0.000, 0.000)
|
||||
cylGui.Transparency = 85
|
||||
cylGui.Visibility = False
|
||||
vaGrp.addObject(cyl)
|
||||
|
||||
FreeCAD.ActiveDocument.addObject("Part::Cylinder", yAx)
|
||||
cyl = FreeCAD.ActiveDocument.getObject(yAx)
|
||||
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.purgeTouched()
|
||||
if FreeCAD.GuiUp:
|
||||
cylGui = FreeCADGui.ActiveDocument.getObject(yAx)
|
||||
cylGui.ShapeColor = (0.000, 0.667, 0.000)
|
||||
cylGui.Transparency = 85
|
||||
cylGui.Visibility = False
|
||||
vaGrp.addObject(cyl)
|
||||
VA.purgeTouched()
|
||||
|
||||
def useTempJobClones(self, cloneName):
|
||||
'''useTempJobClones(cloneName)
|
||||
Manage use of temporary model clones for rotational operation calculations.
|
||||
Clones are stored in 'rotJobClones' group.'''
|
||||
if FreeCAD.ActiveDocument.getObject('rotJobClones'):
|
||||
if cloneName == 'Start':
|
||||
if PathLog.getLevel(PathLog.thisModule()) < 4:
|
||||
for cln in FreeCAD.ActiveDocument.getObject('rotJobClones').Group:
|
||||
FreeCAD.ActiveDocument.removeObject(cln.Name)
|
||||
elif cloneName == 'Delete':
|
||||
if PathLog.getLevel(PathLog.thisModule()) < 4:
|
||||
for cln in FreeCAD.ActiveDocument.getObject('rotJobClones').Group:
|
||||
FreeCAD.ActiveDocument.removeObject(cln.Name)
|
||||
FreeCAD.ActiveDocument.removeObject('rotJobClones')
|
||||
else:
|
||||
FreeCAD.ActiveDocument.getObject('rotJobClones').purgeTouched()
|
||||
else:
|
||||
FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup", "rotJobClones")
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.ActiveDocument.getObject('rotJobClones').Visibility = False
|
||||
|
||||
if cloneName != 'Start' and cloneName != 'Delete':
|
||||
FreeCAD.ActiveDocument.getObject('rotJobClones').addObject(FreeCAD.ActiveDocument.getObject(cloneName))
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.ActiveDocument.getObject(cloneName).Visibility = False
|
||||
|
||||
def cloneBaseAndStock(self, obj, base, angle, axis, subCount):
|
||||
'''cloneBaseAndStock(obj, base, angle, axis, subCount)
|
||||
Method called to create a temporary clone of the base and parent Job stock.
|
||||
Clones are destroyed after usage for calculations related to rotational operations.'''
|
||||
# Create a temporary clone and stock of model for rotational use.
|
||||
rndAng = round(angle, 8)
|
||||
if rndAng < 0.0: # neg sign is converted to underscore in clone name creation.
|
||||
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
|
||||
if clnNm not in self.cloneNames:
|
||||
self.cloneNames.append(clnNm)
|
||||
self.cloneNames.append(stckClnNm)
|
||||
if FreeCAD.ActiveDocument.getObject(clnNm):
|
||||
FreeCAD.ActiveDocument.getObject(clnNm).Shape = base.Shape
|
||||
else:
|
||||
FreeCAD.ActiveDocument.addObject('Part::Feature', clnNm).Shape = base.Shape
|
||||
self.useTempJobClones(clnNm)
|
||||
if FreeCAD.ActiveDocument.getObject(stckClnNm):
|
||||
FreeCAD.ActiveDocument.getObject(stckClnNm).Shape = PathUtils.findParentJob(obj).Stock.Shape
|
||||
else:
|
||||
FreeCAD.ActiveDocument.addObject('Part::Feature', stckClnNm).Shape = PathUtils.findParentJob(obj).Stock.Shape
|
||||
self.useTempJobClones(stckClnNm)
|
||||
if FreeCAD.GuiUp:
|
||||
FreeCADGui.ActiveDocument.getObject(stckClnNm).Transparency = 90
|
||||
FreeCADGui.ActiveDocument.getObject(clnNm).ShapeColor = (1.000, 0.667, 0.000)
|
||||
clnBase = FreeCAD.ActiveDocument.getObject(clnNm)
|
||||
clnStock = FreeCAD.ActiveDocument.getObject(stckClnNm)
|
||||
tag = base.Name + '_' + tag
|
||||
return (clnBase, clnStock, tag)
|
||||
|
||||
def getFaceNormAndSurf(self, face):
|
||||
'''getFaceNormAndSurf(face)
|
||||
Return face.normalAt(0,0) or face.normal(0,0) and face.Surface.Axis vectors
|
||||
'''
|
||||
norm = FreeCAD.Vector(0.0, 0.0, 0.0)
|
||||
surf = FreeCAD.Vector(0.0, 0.0, 0.0)
|
||||
|
||||
if hasattr(face, 'normalAt'):
|
||||
n = face.normalAt(0, 0)
|
||||
elif hasattr(face, 'normal'):
|
||||
n = face.normal(0, 0)
|
||||
if hasattr(face.Surface, 'Axis'):
|
||||
s = face.Surface.Axis
|
||||
else:
|
||||
s = n
|
||||
norm.x = n.x
|
||||
norm.y = n.y
|
||||
norm.z = n.z
|
||||
surf.x = s.x
|
||||
surf.y = s.y
|
||||
surf.z = s.z
|
||||
return (norm, surf)
|
||||
|
||||
def applyRotationalAnalysis(self, obj, base, angle, axis, subCount):
|
||||
'''applyRotationalAnalysis(obj, base, angle, axis, subCount)
|
||||
Create temp clone and stock and apply rotation to both.
|
||||
Return new rotated clones
|
||||
'''
|
||||
if axis == 'X':
|
||||
vect = FreeCAD.Vector(1, 0, 0)
|
||||
elif axis == 'Y':
|
||||
vect = FreeCAD.Vector(0, 1, 0)
|
||||
|
||||
# Commented out to fix PocketShape InverseAngle rotation problem
|
||||
# if obj.InverseAngle is True:
|
||||
# angle = -1 * angle
|
||||
# if math.fabs(angle) == 0.0:
|
||||
# angle = 0.0
|
||||
|
||||
# Create a temporary clone of model for rotational use.
|
||||
(clnBase, clnStock, tag) = self.cloneBaseAndStock(obj, base, angle, axis, subCount)
|
||||
|
||||
# Rotate base to such that Surface.Axis of pocket bottom is Z=1
|
||||
clnBase = Draft.rotate(clnBase, angle, center=FreeCAD.Vector(0.0, 0.0, 0.0), axis=vect, copy=False)
|
||||
clnStock = Draft.rotate(clnStock, angle, center=FreeCAD.Vector(0.0, 0.0, 0.0), axis=vect, copy=False)
|
||||
|
||||
clnBase.purgeTouched()
|
||||
clnStock.purgeTouched()
|
||||
return (clnBase, angle, clnStock, tag)
|
||||
|
||||
def applyInverseAngle(self, obj, clnBase, clnStock, axis, angle):
|
||||
'''applyInverseAngle(obj, clnBase, clnStock, axis, angle)
|
||||
Apply rotations to incoming base and stock objects.'''
|
||||
if axis == 'X':
|
||||
vect = FreeCAD.Vector(1, 0, 0)
|
||||
elif axis == 'Y':
|
||||
vect = FreeCAD.Vector(0, 1, 0)
|
||||
# Rotate base to inverse of original angle
|
||||
clnBase = Draft.rotate(clnBase, (-2 * angle), center=FreeCAD.Vector(0.0, 0.0, 0.0), axis=vect, copy=False)
|
||||
clnStock = Draft.rotate(clnStock, (-2 * angle), center=FreeCAD.Vector(0.0, 0.0, 0.0), axis=vect, copy=False)
|
||||
clnBase.purgeTouched()
|
||||
clnStock.purgeTouched()
|
||||
# Update property and angle values
|
||||
obj.InverseAngle = True
|
||||
# obj.AttemptInverseAngle = False
|
||||
angle = -1 * angle
|
||||
|
||||
PathLog.debug(translate("Path", "Rotated to inverse angle."))
|
||||
return (clnBase, clnStock, angle)
|
||||
|
||||
def sortTuplesByIndex(self, TupleList, tagIdx):
|
||||
'''sortTuplesByIndex(TupleList, tagIdx)
|
||||
sort list of tuples based on tag index provided
|
||||
return (TagList, GroupList)
|
||||
'''
|
||||
# Separate elements, regroup by orientation (axis_angle combination)
|
||||
TagList = ['X34.2']
|
||||
GroupList = [[(2.3, 3.4, 'X')]]
|
||||
for tup in TupleList:
|
||||
if tup[tagIdx] in TagList:
|
||||
# Determine index of found string
|
||||
i = 0
|
||||
for orn in TagList:
|
||||
if orn == tup[4]:
|
||||
break
|
||||
i += 1
|
||||
GroupList[i].append(tup)
|
||||
else:
|
||||
TagList.append(tup[4]) # add orientation entry
|
||||
GroupList.append([tup]) # add orientation entry
|
||||
# Remove temp elements
|
||||
TagList.pop(0)
|
||||
GroupList.pop(0)
|
||||
return (TagList, GroupList)
|
||||
|
||||
def warnDisabledAxis(self, obj, axis, sub=''):
|
||||
'''warnDisabledAxis(self, obj, axis)
|
||||
Provide user feedback if required axis is disabled'''
|
||||
if axis == 'X' and obj.EnableRotation == 'B(y)':
|
||||
msg = translate('Path', "{}:: {} is inaccessible.".format(obj.Name, sub)) + " "
|
||||
msg += translate('Path', "Selected feature(s) require 'Enable Rotation: A(x)' for access.")
|
||||
PathLog.warning(msg)
|
||||
return True
|
||||
elif axis == 'Y' and obj.EnableRotation == 'A(x)':
|
||||
msg = translate('Path', "{}:: {} is inaccessible.".format(obj.Name, sub)) + " "
|
||||
msg += translate('Path', "Selected feature(s) require 'Enable Rotation: B(y)' for access.")
|
||||
PathLog.warning(msg)
|
||||
return True
|
||||
else:
|
||||
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:
|
||||
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
|
||||
PathLog.debug('isFaceUp - exit True\n')
|
||||
return True
|
||||
|
||||
# Support methods
|
||||
def _customDepthParams(self, obj, strDep, finDep):
|
||||
finish_step = obj.FinishDepth.Value if hasattr(obj, "FinishDepth") else 0.0
|
||||
cdp = PathUtils.depth_params(
|
||||
@@ -1030,5 +425,5 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
# Eclass
|
||||
|
||||
def SetupProperties():
|
||||
setup = ['EnableRotation']
|
||||
setup = []
|
||||
return setup
|
||||
|
||||
Reference in New Issue
Block a user