Path: Integrate 4th-axis feature to PathPocketShape and 3D Surface ops (#2114)
* PathSurface: Add StepDown support Add StepDown support for PathSurface operation. A low-level optimization algorithm is included. * Update PageOpSurfaceEdit.ui * PathSurface: Activate CompletionMode input Update code to use CompletionMode selection from user. * PathSurfaceGui: Add Completion Mode selection box Add Completion Mode selection box for user input. * PathSurface: Use depth_params() for step control Implemented PathUtils.depth_params() for control of step downs to maintain consistency throughout PathWB. Suggested by Sliptonic. * PathSurface: Improve stability - Rev3 Organized code better, improved path optimization algorithm * PathSurface: Add XY rotational surfacing Add options to perform 3D surfacing by rotating object around X or Y axis. * PathSurface: update setup function Add properties to setup function * PathSurface: Remove extraneous code removed commented lines that consume processing time * PathSurface: Correct nxt.z point assignment Corrected error in nxt.z value assignment. Was assigning value to pnt.z instead of nxt.z * PathSurface: Update 4th axis operation Provided both parallel and perpendicular to axis scans when performing rotational operation. * PathSurface: Corrected Y-axis rotation to gcode Inverted Y-axis scan values in gcode to produce correct result * PathSurface: Adjust gcode feed rates Adjust feed rates for axial rotations * PathSurface: Implement waterline alternative Used OCL dropcutter scan as data base for python algorithm to extract a waterline. Waterline also incorporates step down feature. * PathSurface: Update to 3m-Usable stability improvements fixed step on multi-pass 4th axis scans initiate code to accommodate cut modes: zigzag, line initiate code to accommodate offset cutter on 4th axis scans to simulate a tilted cutter for ball end mills * PathSurface: Update 3m-Usable_r1 change instantiated static class attributes from value None, to 0.0 * PathSurface: Revert to 3i-Usable_r1 Further testing needed for 3m-Usable release * PathSurface: Update to Rev. 3s Usable fixed step over in rotational scans start/stop indexes tilt cutter adaptation for ball end mill cut pattern: zigzag, line partially implemented ignore waste option initiated for planar scans cut mode partially implemented: conventional & climb * PathSurface: Update to Rev. 3t Usable Corrected rotational errors corrected cutter tilt rotation added "ignore waste" feature for planar surface operation * Implement 4th-axis feature Implement 4th-axis feature: add gcode commands for rotation re-compute operation heights, to consider rotation radii * Deleted reference to undeclared variable * Added missing class attributes/variables * Added missing class variables/attributes * Relocate class variables to higher class * Remove references to undeclared variables relocated class variables here delete references to undeclared variables * Correct rotation direction for normal-to-Y faces * Remove X oriented 180 degree rotation adjustment Probable error in FreeCAD gcode renderer, producing incorrect B axis rotation * Update 4th-axis integration Address FC error with B axis rotation rendering: user input to override error for visual alignment with model. Correct pocket depths with Final Depth input enforced. Add Reverse Direction flag input for reversing direction of pocket: necessary in some use cases. NOTE: 4th-axis throws errors with Extension Corners feature. EC feature needs 4th-axis rotation integration when calculating extensions for a particular part feature/face. General testing needed. * PathSurface: Add StepDown support Add StepDown support for PathSurface operation. A low-level optimization algorithm is included. * Update PageOpSurfaceEdit.ui * PathSurface: Activate CompletionMode input Update code to use CompletionMode selection from user. * PathSurfaceGui: Add Completion Mode selection box Add Completion Mode selection box for user input. * PathSurface: Use depth_params() for step control Implemented PathUtils.depth_params() for control of step downs to maintain consistency throughout PathWB. Suggested by Sliptonic. * PathSurface: Improve stability - Rev3 Organized code better, improved path optimization algorithm * PathSurface: Add XY rotational surfacing Add options to perform 3D surfacing by rotating object around X or Y axis. * PathSurface: update setup function Add properties to setup function * PathSurface: Remove extraneous code removed commented lines that consume processing time * PathSurface: Correct nxt.z point assignment Corrected error in nxt.z value assignment. Was assigning value to pnt.z instead of nxt.z * PathSurface: Update 4th axis operation Provided both parallel and perpendicular to axis scans when performing rotational operation. * PathSurface: Corrected Y-axis rotation to gcode Inverted Y-axis scan values in gcode to produce correct result * PathSurface: Adjust gcode feed rates Adjust feed rates for axial rotations * PathSurface: Implement waterline alternative Used OCL dropcutter scan as data base for python algorithm to extract a waterline. Waterline also incorporates step down feature. * PathSurface: Update to 3m-Usable stability improvements fixed step on multi-pass 4th axis scans initiate code to accommodate cut modes: zigzag, line initiate code to accommodate offset cutter on 4th axis scans to simulate a tilted cutter for ball end mills * PathSurface: Update 3m-Usable_r1 change instantiated static class attributes from value None, to 0.0 * PathSurface: Revert to 3i-Usable_r1 Further testing needed for 3m-Usable release * PathSurface: Update to Rev. 3s Usable fixed step over in rotational scans start/stop indexes tilt cutter adaptation for ball end mill cut pattern: zigzag, line partially implemented ignore waste option initiated for planar scans cut mode partially implemented: conventional & climb * PathSurface: Update to Rev. 3t Usable Corrected rotational errors corrected cutter tilt rotation added "ignore waste" feature for planar surface operation * Implement 4th-axis feature Implement 4th-axis feature: add gcode commands for rotation re-compute operation heights, to consider rotation radii * Deleted reference to undeclared variable * Added missing class attributes/variables * Added missing class variables/attributes * Relocate class variables to higher class * Remove references to undeclared variables relocated class variables here delete references to undeclared variables * Remove X oriented 180 degree rotation adjustment Probable error in FreeCAD gcode renderer, producing incorrect B axis rotation * Correct rotation direction for normal-to-Y faces * Update 4th-axis integration Address FC error with B axis rotation rendering: user input to override error for visual alignment with model. Correct pocket depths with Final Depth input enforced. Add Reverse Direction flag input for reversing direction of pocket: necessary in some use cases. NOTE: 4th-axis throws errors with Extension Corners feature. EC feature needs 4th-axis rotation integration when calculating extensions for a particular part feature/face. General testing needed. * Apply XYZ Model translations to paths; Add rotation axis selection property * Spelling correction ln 110 * Geometry list box: shrink height 560 to 400 height * Update 4th-axis integration Clean up code Add comments for visionary elements Apply axis selection to opHeights rotational calculations * Update 4th-axis integration Prepare sorting of vertical faces per axis_angle grouping, just as horizontal faces are sorted, for analysis as connected shapes * Reset to FreeCAD master current * Reset to current FreeCAD master version * Update PathPocketBase.py * Reset to current FreeCAD master * Corrected __created__ date * Convert all print() to PathLog.debug() * Convert print() to PathLog.debug(); Clean up code Use PathLog.debug over print() for troubleshooting Clean up large commented sections of code. * Convert print() to PathLog.debug(); combine duplicate methods * Update last modified stamp * Update last mofified timestamp Also, removed commented-out code * Typo corrected: "selt." to "self." Discovered in https://api.travis-ci.org/v3/job/526456071/log.txt on 30 April 2019 while searching for errors related to failure of PR #2114 * Restore initialization of self.depthparams PR is failing Travis CI build test. Previous deletion of this code appears to be the reason. See report at: https://api.travis-ci.org/v3/job/526492709/log.txt * Convert tuple sizes from other PathWB ops * B-axis rotation: render correction * Revert "rebase to FC master 2019-05-02" * Correct depthparams opOnDocumentRestored() issue * Relocate "UseRotation" property from PathAreaOp.py * Improve meshFromShape() calculation per @sliptonic faster mesh creation helps smooth jagged lines in path results * Part: Make 3rd party libraries into PCH * PartDesign: 3rdParty to PCH * Sketcher: PCH * PartDesign: PCH GUI * Sketcher: GUI PCH * Travis windows build (#2110) Travis windows build * Travis: enable clcache debug * disable travis clcache debug * respect user settings for dialog used in merge-document command * msbuild verbose and logo * Travis force wait 60 minutes * Travis: Use & between vars sourcing and msbuild * Travis: Move building to external batch script (#2131) * Travis: Move building to external batch script * Travis: double quotes to escape route * Travis: use cmd.exe to call batch file * Crowdin: fix grammatical error + whitespace https://crowdin.com/translate/freecad/569/en-fi#6498705 * Crowdin: experiment to fix crowdin 'ghost' strings The following translation strings still perpetuate after updating crowdin translations. This commit experiments with removing their source counterparts in the FC .ts files. I'm not sure why they are not rendered obsolete by the normal operations. * https://crowdin.com/translate/freecad/6766/en-en#6499472 * https://crowdin.com/translate/freecad/6766/en-en#6573450 * fix for edit tracker draw styles * deleted commented code * Travis: filter out * AddonManager: allow to add custom repositories * Revert "rebase to FC master 2019-05-02" * Draft: Fixed Draft text justification * Arch: Fixed bug in arch windows creation * Arch: Fixed export of windows colors to IFC * Draft: Fixed 0.18.1 bug in DXF importer * Arch: Fixed wrong exported objects in IFC export * Arch: Fixed export of sites to IFC * Start: Fixed bad default icon in start page * Correct depthparams opOnDocumentRestored() issue * Relocate "UseRotation" property from PathAreaOp.py * Improve meshFromShape() calculation per @sliptonic faster mesh creation helps smooth jagged lines in path results * Relocate "UseRotation" property in PathAreaOp.py * Syntax correction Travis CI python 3.7 build test fails regularly due to syntax error at this point * Correct rebase issue: PR #2114 * Correct rebase issue: PR #2114 * Correct rebase issue: PR #2114 * Correct rebase issue: PR #2114 * Correct rebase issue: PR #2114 * Correct rebase issue: PR #2114 * path pep8 cleanup * Multi-face geometry selection repaired Previous version broke ability to select process multiple faces selected by user in geometry tab in operation task window. Also performed some syntax cleaning per PEP8 linter * Update script version info
This commit is contained in:
committed by
sliptonic
parent
2d2b5f3e19
commit
aaae829704
16000
gitlog.log
16000
gitlog.log
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>560</height>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
||||
@@ -107,7 +107,7 @@
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonDisable">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Diisable the currently selected pocket extension.</p></body></html></string>
|
||||
<string><html><head/><body><p>Disable the currently selected pocket extension.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Disable</string>
|
||||
|
||||
@@ -427,7 +427,7 @@ Base::Vector3d compensateRotation(const Base::Vector3d &pt, const Base::Rotation
|
||||
Base::Rotation yawPitchRoll(double a, double b, double c)
|
||||
{
|
||||
Base::Rotation rot;
|
||||
rot.setYawPitchRoll(-c, b, -a);
|
||||
rot.setYawPitchRoll(-c, -b, -a);
|
||||
return rot;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,19 +22,30 @@
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
# SCRIPT NOTES:
|
||||
# - Need to add "UseRotation" property to task window UI, and attach appropriate onChange event handler
|
||||
# - Consult FC community about wording for "UseRotation" property
|
||||
# - FUTURE: Relocate rotational calculations to Job setup tool, creating a Machine section
|
||||
# with axis & rotation toggles and associated min/max values
|
||||
|
||||
import FreeCAD
|
||||
import Path
|
||||
import PathScripts.PathLog as PathLog
|
||||
import PathScripts.PathOp as PathOp
|
||||
import PathScripts.PathUtils as PathUtils
|
||||
|
||||
from PathScripts.PathUtils import waiting_effects
|
||||
# from PathScripts.PathUtils import waiting_effects
|
||||
from PySide import QtCore
|
||||
import math
|
||||
|
||||
__title__ = "Base class for PathArea based operations."
|
||||
__author__ = "sliptonic (Brad Collette)"
|
||||
__url__ = "http://www.freecadweb.org"
|
||||
__doc__ = "Base class and properties for Path.Area based operations."
|
||||
__contributors__ = "mlampert [FreeCAD], russ4262 (Russell Johnson)"
|
||||
__createdDate__ = "2017"
|
||||
__scriptVersion__ = "1h testing"
|
||||
__lastModified__ = "2019-05-03 10:52 CST"
|
||||
|
||||
if False:
|
||||
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
|
||||
@@ -42,10 +53,12 @@ if False:
|
||||
else:
|
||||
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
|
||||
|
||||
|
||||
# Qt tanslation handling
|
||||
def translate(context, text, disambig=None):
|
||||
return QtCore.QCoreApplication.translate(context, text, disambig)
|
||||
|
||||
|
||||
class ObjectOp(PathOp.ObjectOp):
|
||||
'''Base class for all Path.Area based operations.
|
||||
Provides standard features including debugging properties AreaParams,
|
||||
@@ -54,6 +67,12 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
to Path.Area so subclasses only have to provide the shapes for the
|
||||
operations.'''
|
||||
|
||||
# These are static while document is open, if it contains a 3D Surface Op
|
||||
initFinalDepth = None
|
||||
initOpFinalDepth = None
|
||||
initOpStartDepth = None
|
||||
docRestored = False
|
||||
|
||||
def opFeatures(self, obj):
|
||||
'''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().
|
||||
@@ -77,6 +96,9 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
obj.setEditorMode('PathParams', 2) # hide
|
||||
obj.addProperty("Part::PropertyPartShape", "removalshape", "Path")
|
||||
obj.setEditorMode('removalshape', 2) # hide
|
||||
if not hasattr(obj, 'UseRotation'):
|
||||
obj.addProperty("App::PropertyEnumeration", "UseRotation", "Path", QtCore.QT_TRANSLATE_NOOP("App::Property", "Use rotation to gain access to pockets/areas."))
|
||||
obj.UseRotation = ['Off', 'A(x)', 'B(y)', 'A & B']
|
||||
|
||||
self.initAreaOp(obj)
|
||||
|
||||
@@ -108,7 +130,7 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
The base implementation takes a stab at determining Heights and Depths if the operations's Base
|
||||
changes.
|
||||
Do not overwrite, overwrite areaOpOnChanged(obj, prop) instead.'''
|
||||
#PathLog.track(obj.Label, prop)
|
||||
# PathLog.track(obj.Label, prop)
|
||||
if prop in ['AreaParams', 'PathParams', 'removalshape']:
|
||||
obj.setEditorMode(prop, 2)
|
||||
|
||||
@@ -130,6 +152,8 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
for prop in ['AreaParams', 'PathParams', 'removalshape']:
|
||||
if hasattr(obj, prop):
|
||||
obj.setEditorMode(prop, 2)
|
||||
self.docRestored = True
|
||||
|
||||
self.areaOpOnDocumentRestored(obj)
|
||||
|
||||
def areaOpOnDocumentRestored(self, obj):
|
||||
@@ -148,13 +172,39 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
except:
|
||||
shape = None
|
||||
|
||||
if shape:
|
||||
bb = shape.BoundBox
|
||||
obj.OpStartDepth = bb.ZMax
|
||||
obj.OpFinalDepth = bb.ZMin
|
||||
maxDep = 1.0
|
||||
minDep = 0.0
|
||||
|
||||
if obj.UseRotation == 'Off':
|
||||
bb = job.Stock.Shape.BoundBox
|
||||
maxDep = bb.ZMax
|
||||
minDep = bb.ZMin
|
||||
else:
|
||||
obj.OpStartDepth = 1.0
|
||||
obj.OpFinalDepth = 0.0
|
||||
opHeights = self.opDetermineRotationRadii(obj) # return is list with tuples [(xRotRad, yRotRad, zRotRad), (clrOfst, safOfst)]
|
||||
(xRotRad, yRotRad, zRotRad) = opHeights[0]
|
||||
# (clrOfst, safOfset) = opHeights[1]
|
||||
|
||||
maxDep = xRotRad
|
||||
if yRotRad > xRotRad:
|
||||
maxDep = yRotRad
|
||||
minDep = -1 * maxDep
|
||||
|
||||
# Manage operation start and final depths
|
||||
if self.docRestored is True:
|
||||
PathLog.debug("doc restored")
|
||||
obj.FinalDepth.Value = obj.OpFinalDepth.Value
|
||||
else:
|
||||
PathLog.debug("new operation")
|
||||
obj.OpFinalDepth.Value = minDep
|
||||
obj.OpStartDepth.Value = maxDep
|
||||
if self.initOpFinalDepth is None and self.initFinalDepth is None:
|
||||
self.initFinalDepth = minDep
|
||||
self.initOpFinalDepth = minDep
|
||||
else:
|
||||
PathLog.debug("-initFinalDepth" + str(self.initFinalDepth))
|
||||
PathLog.debug("-initOpFinalDepth" + str(self.initOpFinalDepth))
|
||||
|
||||
obj.UseRotation = 'Off'
|
||||
|
||||
self.areaOpSetDefaultValues(obj, job)
|
||||
|
||||
@@ -231,39 +281,108 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
instead.'''
|
||||
PathLog.track()
|
||||
self.endVector = None
|
||||
PathLog.debug("opExecute() in PathAreaOp.py")
|
||||
|
||||
# Instantiate class variables for operation reference
|
||||
self.rotateFlag = False
|
||||
self.modelName = None
|
||||
self.leadIn = 2.0 # safOfset / 2.0
|
||||
|
||||
# Initialize depthparams
|
||||
finish_step = obj.FinishDepth.Value if hasattr(obj, "FinishDepth") else 0.0
|
||||
self.depthparams = PathUtils.depth_params(
|
||||
clearance_height=obj.ClearanceHeight.Value,
|
||||
safe_height=obj.SafeHeight.Value,
|
||||
start_depth=obj.StartDepth.Value,
|
||||
step_down=obj.StepDown.Value,
|
||||
z_finish_step=finish_step,
|
||||
final_depth=obj.FinalDepth.Value,
|
||||
user_depths=None)
|
||||
clearance_height=obj.ClearanceHeight.Value,
|
||||
safe_height=obj.SafeHeight.Value,
|
||||
start_depth=obj.StartDepth.Value,
|
||||
step_down=obj.StepDown.Value,
|
||||
z_finish_step=finish_step,
|
||||
final_depth=obj.FinalDepth.Value,
|
||||
user_depths=None)
|
||||
|
||||
# Recalculate operation heights for rotational operation
|
||||
if obj.UseRotation != 'Off':
|
||||
# Calculate operation heights based upon rotation radii
|
||||
opHeights = self.opDetermineRotationRadii(obj) # return is [(xRotRad, yRotRad, zRotRad), (clrOfst, safOfst)]
|
||||
(xRotRad, yRotRad, zRotRad) = opHeights[0]
|
||||
(clrOfst, safOfset) = opHeights[1]
|
||||
# self.leadIn = 0.0 #safOfset / 2.0
|
||||
|
||||
# Set clearnance and safe heights based upon rotation radii
|
||||
obj.ClearanceHeight.Value = xRotRad + clrOfst
|
||||
obj.SafeHeight.Value = xRotRad + safOfset
|
||||
if yRotRad > xRotRad:
|
||||
obj.ClearanceHeight.Value = yRotRad + clrOfst
|
||||
obj.SafeHeight.Value = yRotRad + safOfset
|
||||
|
||||
# Set axial feed rates based upon horizontal feed rates
|
||||
safeCircum = 2 * math.pi * obj.SafeHeight.Value
|
||||
self.axialFeed = 360 / safeCircum * self.horizFeed
|
||||
self.axialRapid = 360 / safeCircum * self.horizRapid
|
||||
|
||||
# Set start point
|
||||
if PathOp.FeatureStartPoint & self.opFeatures(obj) and obj.UseStartPoint:
|
||||
start = obj.StartPoint
|
||||
else:
|
||||
start = None
|
||||
|
||||
shapes = self.areaOpShapes(obj)
|
||||
aOS = self.areaOpShapes(obj) # list of tuples (shape, isHole, sub, angle, axis, tag)
|
||||
|
||||
jobs = [{
|
||||
'x': s[0].BoundBox.XMax,
|
||||
'y': s[0].BoundBox.YMax,
|
||||
'shape': s
|
||||
} for s in shapes]
|
||||
# Adjust tuples length received from other PathWB tools/operations beside PathPocketShape
|
||||
shapes = []
|
||||
for shp in aOS:
|
||||
if len(shp) == 2:
|
||||
(fc, iH) = shp
|
||||
tup = fc, iH, 'notPocket', 0.0, 'X'
|
||||
shapes.append(tup)
|
||||
else:
|
||||
shapes.append(shp)
|
||||
|
||||
jobs = PathUtils.sort_jobs(jobs, ['x', 'y'])
|
||||
if len(shapes) > 1:
|
||||
jobs = [{
|
||||
'x': s[0].BoundBox.XMax,
|
||||
'y': s[0].BoundBox.YMax,
|
||||
'shape': s
|
||||
} for s in shapes]
|
||||
|
||||
shapes = [j['shape'] for j in jobs]
|
||||
jobs = PathUtils.sort_jobs(jobs, ['x', 'y'])
|
||||
|
||||
shapes = [j['shape'] for j in jobs]
|
||||
|
||||
sims = []
|
||||
for (shape, isHole) in shapes:
|
||||
for (shape, isHole, sub, angle, axis) in shapes:
|
||||
startDep = obj.StartDepth.Value # + safOfset
|
||||
safeDep = obj.SafeHeight.Value
|
||||
clearDep = obj.ClearanceHeight.Value
|
||||
finalDep = obj.FinalDepth.Value # finDep
|
||||
|
||||
finish_step = obj.FinishDepth.Value if hasattr(obj, "FinishDepth") else 0.0
|
||||
self.depthparams = PathUtils.depth_params(
|
||||
clearance_height=clearDep, # obj.ClearanceHeight.Value
|
||||
safe_height=safeDep, # obj.SafeHeight.Value
|
||||
start_depth=startDep,
|
||||
step_down=obj.StepDown.Value,
|
||||
z_finish_step=finish_step, # obj.FinalDepth.Value
|
||||
final_depth=finalDep,
|
||||
user_depths=None)
|
||||
|
||||
try:
|
||||
(pp, sim) = self._buildPathArea(obj, shape, isHole, start, getsim)
|
||||
self.commandlist.extend(pp.Commands)
|
||||
ppCmds = pp.Commands
|
||||
if obj.UseRotation != 'Off' and self.rotateFlag is True:
|
||||
# Rotate model to index for cut
|
||||
axisOfRot = 'A'
|
||||
if axis == 'Y':
|
||||
axisOfRot = 'B'
|
||||
# Reverse angle temporarily to match model. Error in FreeCAD render of B axis rotations
|
||||
if obj.B_AxisErrorOverride is True:
|
||||
angle = -1 * angle
|
||||
# Rotate Model to correct angle
|
||||
ppCmds.insert(0, Path.Command('G0', {axisOfRot: angle, 'F': self.axialFeed}))
|
||||
# Raise cutter to safe depth and return index to starting position
|
||||
ppCmds.append(Path.Command('G0', {'Z': safeDep, 'F': self.vertRapid}))
|
||||
ppCmds.append(Path.Command('G0', {axisOfRot: 0.0, 'F': self.axialFeed}))
|
||||
# Save gcode commands to object command list
|
||||
self.commandlist.extend(ppCmds)
|
||||
sims.append(sim)
|
||||
except Exception as e:
|
||||
FreeCAD.Console.PrintError(e)
|
||||
@@ -272,6 +391,14 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
if self.areaOpRetractTool(obj):
|
||||
self.endVector = None
|
||||
|
||||
# Raise cutter to safe height and rotate back to original orientation
|
||||
if self.rotateFlag is True:
|
||||
self.commandlist.append(Path.Command('G0', {'Z': obj.SafeHeight.Value, 'F': self.vertRapid}))
|
||||
self.commandlist.append(Path.Command('G0', {'A': 0.0, 'F': self.axialFeed}))
|
||||
self.commandlist.append(Path.Command('G0', {'B': 0.0, 'F': self.axialFeed}))
|
||||
FreeCAD.ActiveDocument.getObject(self.modelName).purgeTouched()
|
||||
|
||||
PathLog.debug("obj.Name: " + str(obj.Name))
|
||||
return sims
|
||||
|
||||
def areaOpRetractTool(self, obj):
|
||||
@@ -283,16 +410,177 @@ class ObjectOp(PathOp.ObjectOp):
|
||||
Note that the resulting parameters are stored in the property AreaParams.
|
||||
Must be overwritten by subclasses.'''
|
||||
pass
|
||||
|
||||
def areaOpPathParams(self, obj, isHole):
|
||||
'''areaOpPathParams(obj, isHole) ... return operation specific path parameters in a dictionary.
|
||||
Note that the resulting parameters are stored in the property PathParams.
|
||||
Must be overwritten by subclasses.'''
|
||||
pass
|
||||
|
||||
def areaOpShapes(self, obj):
|
||||
'''areaOpShapes(obj) ... return all shapes to be processed by Path.Area for this op.
|
||||
Must be overwritten by subclasses.'''
|
||||
pass
|
||||
|
||||
def areaOpUseProjection(self, obj):
|
||||
'''areaOpUseProcjection(obj) ... return True if the operation can use procjection, defaults to False.
|
||||
Can safely be overwritten by subclasses.'''
|
||||
return False
|
||||
|
||||
def opDetermineRotationRadii(self, obj):
|
||||
'''opDetermineRotationRadii(self, obj)
|
||||
Determine rotational radii for 4th-axis rotations, for clearance/safe heights '''
|
||||
|
||||
parentJob = PathUtils.findParentJob(obj)
|
||||
bb = parentJob.Stock.Shape.BoundBox
|
||||
xlim = 0.0
|
||||
ylim = 0.0
|
||||
zlim = 0.0
|
||||
|
||||
# Determine boundbox radius based upon xzy limits data
|
||||
if math.fabs(bb.ZMin) > math.fabs(bb.ZMax):
|
||||
zlim = bb.ZMin
|
||||
else:
|
||||
zlim = bb.ZMax
|
||||
|
||||
if obj.UseRotation != 'B(y)':
|
||||
# Rotation is around X-axis, cutter moves along same axis
|
||||
if math.fabs(bb.YMin) > math.fabs(bb.YMax):
|
||||
ylim = bb.YMin
|
||||
else:
|
||||
ylim = bb.YMax
|
||||
|
||||
if obj.UseRotation != 'A(x)':
|
||||
# Rotation is around Y-axis, cutter moves along same axis
|
||||
if math.fabs(bb.XMin) > math.fabs(bb.XMax):
|
||||
xlim = bb.XMin
|
||||
else:
|
||||
xlim = bb.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.ClearanceHeightOffset.Value
|
||||
|
||||
return [(xRotRad, yRotRad, zRotRad), (clrOfst, safOfst)]
|
||||
|
||||
def pocketRotationAnalysis(self, obj, objRef, sub, prnt):
|
||||
'''pocketRotationAnalysis(self, obj, objRef, sub, prnt)
|
||||
Determine X and Y independent rotation necessary to make normalAt = Z=1 (0,0,1) '''
|
||||
|
||||
rtn = False
|
||||
axis = 'X'
|
||||
orientation = 'X'
|
||||
angle = 500.0
|
||||
zTol = 1.0E-9
|
||||
rndTol = 1.0 - zTol
|
||||
testId = "pocketRotationAnalysis() in PathAreaOp.py"
|
||||
|
||||
def roundRoughValues(val, zTol, rndTol):
|
||||
# Convert VALxe-15 numbers to zero
|
||||
if math.fabs(val) <= zTol:
|
||||
return 0.0
|
||||
# Convert VAL.99999999 to next integer
|
||||
elif math.fabs(val % 1) > rndTol:
|
||||
return round(val)
|
||||
else:
|
||||
return val
|
||||
|
||||
face = objRef.Shape.getElement(sub)
|
||||
|
||||
norm = face.normalAt(0, 0)
|
||||
nX = roundRoughValues(norm.x, zTol, rndTol)
|
||||
nY = roundRoughValues(norm.y, zTol, rndTol)
|
||||
nZ = roundRoughValues(norm.z, zTol, rndTol)
|
||||
testId += "\n -normalAt(0,0): " + str(nX) + ", " + str(nY) + ", " + str(nZ)
|
||||
|
||||
surf = face.Surface.Axis
|
||||
saX = roundRoughValues(surf.x, zTol, rndTol)
|
||||
saY = roundRoughValues(surf.y, zTol, rndTol)
|
||||
saZ = roundRoughValues(surf.z, zTol, rndTol)
|
||||
testId += "\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:
|
||||
testId += "_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:
|
||||
testId += "_else_X" + str(saX)
|
||||
else:
|
||||
orientation = "X"
|
||||
ratio = saX / saZ
|
||||
angle = math.degrees(math.atan(ratio))
|
||||
if ratio < 0.0:
|
||||
testId += " NEG-ratio"
|
||||
angle -= 90
|
||||
else:
|
||||
testId += " 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
|
||||
|
||||
if orientation == 'Y':
|
||||
axis = 'X'
|
||||
if obj.UseRotation == 'B(y)': # Axis disabled
|
||||
angle = 500.0
|
||||
else:
|
||||
axis = 'Y'
|
||||
if obj.UseRotation == 'A(x)': # Axis disabled
|
||||
angle = 500.0
|
||||
|
||||
if angle != 500.0 and angle != 0.0:
|
||||
self.rotateFlag = True
|
||||
rtn = True
|
||||
if obj.ReverseDirection is True:
|
||||
if angle < 180.0:
|
||||
angle = angle + 180.0
|
||||
else:
|
||||
angle = angle - 180.0
|
||||
testId += "\n - ... rotation triggered"
|
||||
else:
|
||||
testId += "\n - ... NO rotation triggered"
|
||||
|
||||
testId += "\n -Suggested rotation: angle: " + str(angle) + ", axis: " + str(axis)
|
||||
if prnt is True:
|
||||
PathLog.debug("testId: " + testId)
|
||||
return (rtn, angle, axis)
|
||||
|
||||
@@ -22,17 +22,28 @@
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
# SCRIPT NOTES:
|
||||
# - Need test models for testing vertical faces scenarios. Currently, I think they will fail with rotation.
|
||||
# - Need to group VERTICAL faces per axis_angle tag just like horizontal faces.
|
||||
# Then, need to run each grouping through
|
||||
# PathGeom.combineConnectedShapes(vertical) algorithm grouping
|
||||
# - Need to add face boundbox analysis code to vertical axis_angle
|
||||
# section to identify highest zMax for all faces included in group
|
||||
# - Need to implement judgeStartDepth() within rotational depth calculations
|
||||
# - FUTURE: Re-iterate PathAreaOp.py need to relocate rotational settings
|
||||
# to Job setup, under Machine settings tab
|
||||
|
||||
import FreeCAD
|
||||
import Part
|
||||
import PathScripts.PathGeom as PathGeom
|
||||
import PathScripts.PathLog as PathLog
|
||||
import PathScripts.PathOp as PathOp
|
||||
import PathScripts.PathPocketBase as PathPocketBase
|
||||
import PathScripts.PathUtil as PathUtil
|
||||
import PathScripts.PathUtils as PathUtils
|
||||
# import PathScripts.PathUtil as PathUtil
|
||||
# import PathScripts.PathUtils as PathUtils
|
||||
import TechDraw
|
||||
import math
|
||||
import sys
|
||||
# import sys
|
||||
|
||||
from PySide import QtCore
|
||||
|
||||
@@ -40,6 +51,10 @@ __title__ = "Path Pocket Shape Operation"
|
||||
__author__ = "sliptonic (Brad Collette)"
|
||||
__url__ = "http://www.freecadweb.org"
|
||||
__doc__ = "Class and implementation of shape based Pocket operation."
|
||||
__contributors__ = "russ4262 (Russell Johnson)"
|
||||
__created__ = "2017"
|
||||
__scriptVersion__ = "1i testing"
|
||||
__lastModified__ = "2019-05-06 16:55 CST"
|
||||
|
||||
if False:
|
||||
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
|
||||
@@ -47,14 +62,16 @@ if False:
|
||||
else:
|
||||
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
|
||||
|
||||
|
||||
# Qt tanslation 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):
|
||||
edges = edgeOrWire.Edges
|
||||
# edges = edgeOrWire.Edges
|
||||
pts = [e.valueAt(e.FirstParameter) for e in edgeOrWire.Edges]
|
||||
pts.extend([e.valueAt(e.LastParameter) for e in edgeOrWire.Edges])
|
||||
unique = []
|
||||
@@ -65,6 +82,7 @@ def endPoints(edgeOrWire):
|
||||
return unique
|
||||
return [e.valueAt(edgeOrWire.FirstParameter), e.valueAt(edgeOrWire.LastParameter)]
|
||||
|
||||
|
||||
def includesPoint(p, pts):
|
||||
'''includesPoint(p, pts) ... answer True if the collection of pts includes the point p'''
|
||||
for pt in pts:
|
||||
@@ -72,6 +90,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
|
||||
@@ -79,36 +98,44 @@ def selectOffsetWire(feature, wires):
|
||||
dist = feature.distToShape(w)[0]
|
||||
if closest is None or dist > closest[0]:
|
||||
closest = (dist, w)
|
||||
if not closest is None:
|
||||
if closest is not None:
|
||||
return closest[1]
|
||||
return None
|
||||
|
||||
|
||||
def extendWire(feature, wire, length):
|
||||
'''extendWire(wire, length) ... return a closed Wire which extends wire by length'''
|
||||
off2D = wire.makeOffset2D(length)
|
||||
endPts = endPoints(wire)
|
||||
edges = [e for e in off2D.Edges if Part.Circle != type(e.Curve) or not includesPoint(e.Curve.Center, endPts)]
|
||||
wires = [Part.Wire(e) for e in Part.sortEdges(edges)]
|
||||
offset = selectOffsetWire(feature, wires)
|
||||
ePts = endPoints(offset)
|
||||
l0 = (ePts[0] - endPts[0]).Length
|
||||
l1 = (ePts[1] - endPts[0]).Length
|
||||
edges = wire.Edges
|
||||
if l0 < l1:
|
||||
edges.append(Part.Edge(Part.LineSegment(endPts[0], ePts[0])))
|
||||
edges.extend(offset.Edges)
|
||||
edges.append(Part.Edge(Part.LineSegment(endPts[1], ePts[1])))
|
||||
try:
|
||||
off2D = wire.makeOffset2D(length)
|
||||
except Exception as e:
|
||||
msg = "\nThe selected face cannot be used.\nYou must select the bottom face of the pocket area.\nextendWire() in PathPocketShape.py"
|
||||
PathLog.error(e)
|
||||
PathLog.error(msg)
|
||||
return False
|
||||
else:
|
||||
edges.append(Part.Edge(Part.LineSegment(endPts[1], ePts[0])))
|
||||
edges.extend(offset.Edges)
|
||||
edges.append(Part.Edge(Part.LineSegment(endPts[0], ePts[1])))
|
||||
return Part.Wire(edges)
|
||||
endPts = endPoints(wire)
|
||||
edges = [e for e in off2D.Edges if Part.Circle != type(e.Curve) or not includesPoint(e.Curve.Center, endPts)]
|
||||
wires = [Part.Wire(e) for e in Part.sortEdges(edges)]
|
||||
offset = selectOffsetWire(feature, wires)
|
||||
ePts = endPoints(offset)
|
||||
l0 = (ePts[0] - endPts[0]).Length
|
||||
l1 = (ePts[1] - endPts[0]).Length
|
||||
edges = wire.Edges
|
||||
if l0 < l1:
|
||||
edges.append(Part.Edge(Part.LineSegment(endPts[0], ePts[0])))
|
||||
edges.extend(offset.Edges)
|
||||
edges.append(Part.Edge(Part.LineSegment(endPts[1], ePts[1])))
|
||||
else:
|
||||
edges.append(Part.Edge(Part.LineSegment(endPts[1], ePts[0])))
|
||||
edges.extend(offset.Edges)
|
||||
edges.append(Part.Edge(Part.LineSegment(endPts[0], ePts[1])))
|
||||
return Part.Wire(edges)
|
||||
|
||||
|
||||
class Extension(object):
|
||||
DirectionNormal = 0
|
||||
DirectionX = 1
|
||||
DirectionY = 2
|
||||
DirectionNormal = 0
|
||||
DirectionX = 1
|
||||
DirectionY = 2
|
||||
|
||||
def __init__(self, obj, feature, sub, length, direction):
|
||||
self.obj = obj
|
||||
@@ -149,7 +176,7 @@ class Extension(object):
|
||||
midparam = e0.FirstParameter + 0.5 * (e0.LastParameter - e0.FirstParameter)
|
||||
tangent = e0.tangentAt(midparam)
|
||||
normal = tangent.cross(FreeCAD.Vector(0, 0, 1)).normalize()
|
||||
poffPlus = e0.valueAt(midparam) + 0.01 * normal
|
||||
poffPlus = e0.valueAt(midparam) + 0.01 * normal
|
||||
poffMinus = e0.valueAt(midparam) - 0.01 * normal
|
||||
if not self.obj.Shape.isInside(poffPlus, 0.005, True):
|
||||
return normal
|
||||
@@ -191,6 +218,12 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
|
||||
if not hasattr(obj, 'ExtensionCorners'):
|
||||
obj.addProperty('App::PropertyBool', 'ExtensionCorners', 'Extension', QtCore.QT_TRANSLATE_NOOP('PathPocketShape', 'When enabled connected extension edges are combined to wires.'))
|
||||
obj.ExtensionCorners = True
|
||||
if not hasattr(obj, 'B_AxisErrorOverride'):
|
||||
obj.addProperty('App::PropertyBool', 'B_AxisErrorOverride', 'Path', QtCore.QT_TRANSLATE_NOOP('PathPocketShape', 'Match B rotations to model (error in FreeCAD rendering).'))
|
||||
obj.B_AxisErrorOverride = False
|
||||
if not hasattr(obj, 'ReverseDirection'):
|
||||
obj.addProperty('App::PropertyBool', 'ReverseDirection', 'Path', QtCore.QT_TRANSLATE_NOOP('PathPocketShape', 'Reverse direction of pocket operation.'))
|
||||
obj.ReverseDirection = False
|
||||
|
||||
obj.setEditorMode('ExtensionFeature', 2)
|
||||
|
||||
@@ -204,46 +237,231 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
|
||||
def areaOpShapes(self, obj):
|
||||
'''areaOpShapes(obj) ... return shapes representing the solids to be removed.'''
|
||||
PathLog.track()
|
||||
PathLog.debug("areaOpShapes() in PathPocketShape.py")
|
||||
|
||||
def judgeFinalDepth(obj, fD):
|
||||
if obj.FinalDepth.Value >= fD:
|
||||
return obj.FinalDepth.Value
|
||||
else:
|
||||
return fD
|
||||
|
||||
def judgeStartDepth(obj, sD):
|
||||
if obj.StartDepth.Value >= sD:
|
||||
return obj.StartDepth.Value
|
||||
else:
|
||||
return sD
|
||||
|
||||
def analyzeVerticalFaces(self, obj, vertTuples):
|
||||
hT = []
|
||||
# base = FreeCAD.ActiveDocument.getObject(self.modelName)
|
||||
|
||||
# Separate elements, regroup by orientation (axis_angle combination)
|
||||
vTags = ['X34.2']
|
||||
vGrps = [[(2.3, 3.4, 'X')]]
|
||||
for tup in vertTuples:
|
||||
(face, sub, angle, axis, tag, strDep, finDep, trans) = tup
|
||||
if tag in vTags:
|
||||
# Determine index of found string
|
||||
i = 0
|
||||
for orn in vTags:
|
||||
if orn == tag:
|
||||
break
|
||||
i += 1
|
||||
vGrps[i].append(tup)
|
||||
else:
|
||||
vTags.append(tag) # add orientation entry
|
||||
vGrps.append([tup]) # add orientation entry
|
||||
# Remove temp elements
|
||||
vTags.pop(0)
|
||||
vGrps.pop(0)
|
||||
|
||||
# check all faces in each axis_angle group
|
||||
shpList = []
|
||||
zmaxH = 0.0
|
||||
for o in range(0, len(vTags)):
|
||||
shpList = []
|
||||
zmaxH = vGrps[o][0].BoundBox.ZMax
|
||||
for (face, sub, angle, axis, tag, strDep, finDep, trans) in vGrps[o]:
|
||||
shpList.append(face)
|
||||
# Identify tallest face to use as zMax
|
||||
if face.BoundBox.ZMax > zmaxH:
|
||||
zmaxH = face.BoundBox.ZMax
|
||||
# check all faces and see if they are touching/overlapping and combine those into a compound
|
||||
# Original Code in For loop
|
||||
self.vertical = PathGeom.combineConnectedShapes(shpList)
|
||||
self.vWires = [TechDraw.findShapeOutline(shape, 1, FreeCAD.Vector(0, 0, 1)) for shape in self.vertical]
|
||||
for wire in self.vWires:
|
||||
w = PathGeom.removeDuplicateEdges(wire)
|
||||
face = Part.Face(w)
|
||||
face.tessellate(0.05)
|
||||
if PathGeom.isRoughly(face.Area, 0):
|
||||
PathLog.error(translate('PathPocket', 'Vertical faces do not form a loop - ignoring'))
|
||||
else:
|
||||
strDep = zmaxH + self.leadIn # base.Shape.BoundBox.ZMax
|
||||
finDep = judgeFinalDepth(obj, face.BoundBox.ZMin)
|
||||
tup = face, sub, angle, axis, tag, strDep, finDep, trans
|
||||
hT.append(tup)
|
||||
# Eol
|
||||
return hT
|
||||
|
||||
if obj.Base:
|
||||
PathLog.debug('base items exist. Processing...')
|
||||
self.removalshapes = []
|
||||
self.horiz = []
|
||||
vertical = []
|
||||
horizTuples = []
|
||||
vertTuples = []
|
||||
axis = 'X'
|
||||
angle = 0.0
|
||||
reset = False
|
||||
resetPlacement = None
|
||||
trans = FreeCAD.Vector(0.0, 0.0, 0.0)
|
||||
|
||||
for o in obj.Base:
|
||||
PathLog.debug('Base item: {}'.format(o))
|
||||
base = o[0]
|
||||
|
||||
# Limit sub faces to children of single Model object.
|
||||
if self.modelName is None:
|
||||
self.modelName = base.Name
|
||||
else:
|
||||
if base.Name != self.modelName:
|
||||
for sub in o[1]:
|
||||
PathLog.error(sub + " is not a part of Model object: " + self.modelName)
|
||||
o[1] = []
|
||||
PathLog.error("Only processing faces on a single Model object per operation.")
|
||||
PathLog.error("You will need to separate faces per Model object within the Job.")
|
||||
|
||||
startBase = FreeCAD.Vector(base.Placement.Base.x, base.Placement.Base.y, base.Placement.Base.z)
|
||||
startAngle = base.Placement.Rotation.Angle
|
||||
startAxis = base.Placement.Rotation.Axis
|
||||
startRotation = FreeCAD.Rotation(startAxis, startAngle)
|
||||
resetPlacement = FreeCAD.Placement(startBase, startRotation)
|
||||
for sub in o[1]:
|
||||
if 'Face' in sub:
|
||||
PathLog.debug('sub: {}'.format(sub))
|
||||
# Determine angle of rotation needed to make normal vector = (0,0,1)
|
||||
strDep = obj.StartDepth.Value
|
||||
finDep = obj.FinalDepth.Value
|
||||
trans = FreeCAD.Vector(0.0, 0.0, 0.0)
|
||||
rtn = False
|
||||
|
||||
if obj.UseRotation != 'Off':
|
||||
(rtn, angle, axis) = self.pocketRotationAnalysis(obj, base, sub, prnt=True)
|
||||
|
||||
if rtn is True:
|
||||
reset = True
|
||||
PathLog.debug(str(sub) + ": rotating model to make face normal at (0,0,1) ...")
|
||||
if axis == 'X':
|
||||
bX = 0.0
|
||||
bY = 0.0
|
||||
bZ = math.sin(math.radians(angle)) * base.Placement.Base.y
|
||||
vect = FreeCAD.Vector(1, 0, 0)
|
||||
elif axis == 'Y':
|
||||
bX = 0.0
|
||||
bY = 0.0
|
||||
bZ = math.sin(math.radians(angle)) * base.Placement.Base.x
|
||||
if obj.B_AxisErrorOverride is True:
|
||||
bZ = -1 * bZ
|
||||
vect = FreeCAD.Vector(0, 1, 0)
|
||||
# Rotate base to such that Surface.Axis of pocket bottom is Z=1
|
||||
base.Placement.Rotation = FreeCAD.Rotation(vect, angle)
|
||||
base.recompute()
|
||||
trans = FreeCAD.Vector(bX, bY, bZ)
|
||||
else:
|
||||
axis = 'X'
|
||||
angle = 0.0
|
||||
tag = axis + str(round(angle, 7))
|
||||
face = base.Shape.getElement(sub)
|
||||
|
||||
if type(face.Surface) == Part.Plane and PathGeom.isVertical(face.Surface.Axis):
|
||||
# it's a flat horizontal face
|
||||
self.horiz.append(face)
|
||||
PathLog.debug(" == Part.Plane: isVertical")
|
||||
# Adjust start and finish depths for pocket
|
||||
strDep = base.Shape.BoundBox.ZMax + self.leadIn
|
||||
finDep = judgeFinalDepth(obj, face.BoundBox.ZMin)
|
||||
# Over-write default final depth value, leaves manual override by user
|
||||
obj.StartDepth.Value = trans.z + strDep
|
||||
obj.FinalDepth.Value = trans.z + finDep
|
||||
|
||||
tup = face, sub, angle, axis, tag, strDep, finDep, trans
|
||||
horizTuples.append(tup)
|
||||
elif type(face.Surface) == Part.Cylinder and PathGeom.isVertical(face.Surface.Axis):
|
||||
PathLog.debug("== Part.Cylinder")
|
||||
# vertical cylinder wall
|
||||
if any(e.isClosed() for e in face.Edges):
|
||||
PathLog.debug("e.isClosed()")
|
||||
# complete cylinder
|
||||
circle = Part.makeCircle(face.Surface.Radius, face.Surface.Center)
|
||||
disk = Part.Face(Part.Wire(circle))
|
||||
self.horiz.append(disk)
|
||||
|
||||
# Adjust start and finish depths for pocket
|
||||
strDep = face.BoundBox.ZMax + self.leadIn # base.Shape.BoundBox.ZMax + self.leadIn
|
||||
finDep = judgeFinalDepth(obj, face.BoundBox.ZMin)
|
||||
# Over-write default final depth value, leaves manual override by user
|
||||
obj.StartDepth.Value = trans.z + strDep
|
||||
obj.FinalDepth.Value = trans.z + finDep
|
||||
|
||||
tup = disk, sub, angle, axis, tag, strDep, finDep, trans
|
||||
horizTuples.append(tup)
|
||||
else:
|
||||
# partial cylinder wall
|
||||
vertical.append(face)
|
||||
|
||||
# Adjust start and finish depths for pocket
|
||||
strDep = face.BoundBox.ZMax + self.leadIn # base.Shape.BoundBox.ZMax + self.leadIn
|
||||
finDep = judgeFinalDepth(obj, face.BoundBox.ZMin)
|
||||
# Over-write default final depth value, leaves manual override by user
|
||||
obj.StartDepth.Value = trans.z + strDep
|
||||
obj.FinalDepth.Value = trans.z + finDep
|
||||
tup = face, sub, angle, axis, tag, strDep, finDep, trans
|
||||
vertTuples.append(tup)
|
||||
|
||||
PathLog.debug(sub + "is vertical after rotation.")
|
||||
elif type(face.Surface) == Part.Plane and PathGeom.isHorizontal(face.Surface.Axis):
|
||||
vertical.append(face)
|
||||
|
||||
# Adjust start and finish depths for pocket
|
||||
strDep = face.BoundBox.ZMax + self.leadIn # base.Shape.BoundBox.ZMax + self.leadIn
|
||||
finDep = judgeFinalDepth(obj, face.BoundBox.ZMin)
|
||||
# Over-write default final depth value, leaves manual override by user
|
||||
obj.StartDepth.Value = trans.z + strDep
|
||||
obj.FinalDepth.Value = trans.z + finDep
|
||||
tup = face, sub, angle, axis, tag, strDep, finDep, trans
|
||||
vertTuples.append(tup)
|
||||
PathLog.debug(sub + "is vertical after rotation.")
|
||||
else:
|
||||
PathLog.error(translate('PathPocket', 'Pocket does not support shape %s.%s') % (base.Label, sub))
|
||||
|
||||
if reset is True:
|
||||
base.Placement.Rotation = startRotation
|
||||
base.recompute()
|
||||
reset = False
|
||||
# End IF
|
||||
# End FOR
|
||||
base.Placement = resetPlacement
|
||||
base.recompute()
|
||||
# End FOR
|
||||
|
||||
# Analyze vertical faces via PathGeom.combineConnectedShapes()
|
||||
# hT = analyzeVerticalFaces(self, obj, vertTuples)
|
||||
# horizTuples.extend(hT)
|
||||
|
||||
# This section will be replaced analyzeVerticalFaces(self, obj, vertTuples) above
|
||||
self.vertical = PathGeom.combineConnectedShapes(vertical)
|
||||
self.vWires = [TechDraw.findShapeOutline(shape, 1, FreeCAD.Vector(0, 0, 1)) for shape in self.vertical]
|
||||
self.vWires = [TechDraw.findShapeOutline(shape, 1, FreeCAD.Vector(0.0, 0.0, 1.0)) for shape in self.vertical]
|
||||
for wire in self.vWires:
|
||||
w = PathGeom.removeDuplicateEdges(wire)
|
||||
face = Part.Face(w)
|
||||
face.tessellate(0.1)
|
||||
face.tessellate(0.05)
|
||||
if PathGeom.isRoughly(face.Area, 0):
|
||||
PathLog.error(translate('PathPocket', 'Vertical faces do not form a loop - ignoring'))
|
||||
else:
|
||||
self.horiz.append(face)
|
||||
# self.horiz.append(face)
|
||||
strDep = base.Shape.BoundBox.ZMax + self.leadIn
|
||||
finDep = judgeFinalDepth(obj, face.BoundBox.ZMin)
|
||||
tup = face, 'vertFace', 0.0, 'X', 'X0.0', strDep, finDep, FreeCAD.Vector(0.0, 0.0, 0.0)
|
||||
horizTuples.append(tup)
|
||||
|
||||
# add faces for extensions
|
||||
self.exts = []
|
||||
@@ -251,33 +469,92 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
|
||||
wire = Part.Face(ext.getWire())
|
||||
if wire:
|
||||
face = Part.Face(wire)
|
||||
self.horiz.append(face)
|
||||
# self.horiz.append(face)
|
||||
strDep = base.Shape.BoundBox.ZMax + self.leadIn
|
||||
finDep = judgeFinalDepth(obj, face.BoundBox.ZMin)
|
||||
tup = face, 'vertFace', 0.0, 'X', 'X0.0', strDep, finDep, FreeCAD.Vector(0.0, 0.0, 0.0)
|
||||
horizTuples.append(tup)
|
||||
self.exts.append(face)
|
||||
|
||||
# move all horizontal faces to FinalDepth
|
||||
for f in self.horiz:
|
||||
f.translate(FreeCAD.Vector(0, 0, obj.FinalDepth.Value - f.BoundBox.ZMin))
|
||||
|
||||
# check all faces and see if they are touching/overlapping and combine those into a compound
|
||||
self.horizontal = []
|
||||
for shape in PathGeom.combineConnectedShapes(self.horiz):
|
||||
shape.sewShape()
|
||||
shape.tessellate(0.1)
|
||||
if obj.UseOutline:
|
||||
wire = TechDraw.findShapeOutline(shape, 1, FreeCAD.Vector(0, 0, 1))
|
||||
wire.translate(FreeCAD.Vector(0, 0, obj.FinalDepth.Value - wire.BoundBox.ZMin))
|
||||
self.horizontal.append(Part.Face(wire))
|
||||
for (face, sub, angle, axis, tag, strDep, finDep, trans) in horizTuples:
|
||||
# face.translate(FreeCAD.Vector(0, 0, obj.FinalDepth.Value - face.BoundBox.ZMin))
|
||||
if angle <= 0.0:
|
||||
if axis == 'X':
|
||||
face.translate(FreeCAD.Vector(0, trans.z, trans.z + finDep - face.BoundBox.ZMin))
|
||||
elif axis == 'Y':
|
||||
face.translate(FreeCAD.Vector(-1 * trans.z, 0, trans.z + finDep - face.BoundBox.ZMin))
|
||||
else:
|
||||
self.horizontal.append(shape)
|
||||
if axis == 'X':
|
||||
face.translate(FreeCAD.Vector(0, -1 * trans.z, trans.z + finDep - face.BoundBox.ZMin))
|
||||
elif axis == 'Y':
|
||||
face.translate(FreeCAD.Vector(trans.z, 0, trans.z + finDep - face.BoundBox.ZMin))
|
||||
|
||||
# Separate elements, regroup by orientation (axis_angle combination)
|
||||
hTags = ['X34.2']
|
||||
hGrps = [[(2.3, 3.4, 'X')]]
|
||||
for tup in horizTuples:
|
||||
(face, sub, angle, axis, tag, strDep, finDep, trans) = tup
|
||||
if tag in hTags:
|
||||
# Determine index of found string
|
||||
i = 0
|
||||
for orn in hTags:
|
||||
if orn == tag:
|
||||
break
|
||||
i += 1
|
||||
hGrps[i].append(tup)
|
||||
else:
|
||||
hTags.append(tag) # add orientation entry
|
||||
hGrps.append([tup]) # add orientation entry
|
||||
# Remove temp elements
|
||||
hTags.pop(0)
|
||||
hGrps.pop(0)
|
||||
|
||||
# check all faces in each axis_angle group
|
||||
self.horizontal = []
|
||||
shpList = []
|
||||
for o in range(0, len(hTags)):
|
||||
PathLog.debug('hTag: {}'.format(hTags[o]))
|
||||
shpList = []
|
||||
for (face, sub, angle, axis, tag, strDep, finDep, trans) in hGrps[o]:
|
||||
shpList.append(face)
|
||||
# check all faces and see if they are touching/overlapping and combine those into a compound
|
||||
# Original Code in For loop
|
||||
for shape in PathGeom.combineConnectedShapes(shpList):
|
||||
shape.sewShape()
|
||||
# shape.tessellate(0.05) # Russ4262 0.1 original
|
||||
if obj.UseOutline:
|
||||
wire = TechDraw.findShapeOutline(shape, 1, FreeCAD.Vector(0, 0, 1))
|
||||
wire.translate(FreeCAD.Vector(0, 0, obj.FinalDepth.Value - wire.BoundBox.ZMin))
|
||||
PathLog.debug(" -obj.UseOutline: obj.FinalDepth.Value" + str(obj.FinalDepth.Value))
|
||||
PathLog.debug(" -obj.UseOutline: wire.BoundBox.ZMin" + str(wire.BoundBox.ZMin))
|
||||
# shape.tessellate(0.05) # Russ4262 0.1 original
|
||||
face = Part.Face(wire)
|
||||
tup = face, sub, angle, axis, tag, strDep, finDep, trans
|
||||
self.horizontal.append(tup)
|
||||
else:
|
||||
# Re-pair shape to tuple set
|
||||
for (face, sub, angle, axis, tag, strDep, finDep, trans) in hGrps[o]:
|
||||
if shape is face:
|
||||
tup = face, sub, angle, axis, tag, strDep, finDep, trans
|
||||
self.horizontal.append(tup)
|
||||
break
|
||||
# Eol
|
||||
|
||||
# extrude all faces up to StartDepth and those are the removal shapes
|
||||
extent = FreeCAD.Vector(0, 0, obj.StartDepth.Value - obj.FinalDepth.Value)
|
||||
self.removalshapes = [(face.removeSplitter().extrude(extent), False) for face in self.horizontal]
|
||||
for (face, sub, angle, axis, tag, strDep, finDep, trans) in self.horizontal:
|
||||
# extent = FreeCAD.Vector(0, 0, obj.StartDepth.Value - obj.FinalDepth.Value)
|
||||
extent = FreeCAD.Vector(0, 0, strDep - finDep)
|
||||
shp = face.removeSplitter().extrude(extent)
|
||||
# tup = shp, False, sub, angle, axis, tag, strDep, finDep, trans
|
||||
tup = shp, False, sub, angle, axis # shape, isHole, sub, angle, axis
|
||||
self.removalshapes.append(tup)
|
||||
|
||||
else: # process the job base object as a whole
|
||||
PathLog.debug("processing the whole job base object")
|
||||
self.outlines = [Part.Face(TechDraw.findShapeOutline(base.Shape, 1, FreeCAD.Vector(0, 0, 1))) for base in self.model]
|
||||
stockBB = self.stock.Shape.BoundBox
|
||||
PathLog.debug(" -Using outlines; no obj.Base")
|
||||
|
||||
self.removalshapes = []
|
||||
self.bodies = []
|
||||
@@ -285,10 +562,10 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
|
||||
outline.translate(FreeCAD.Vector(0, 0, stockBB.ZMin - 1))
|
||||
body = outline.extrude(FreeCAD.Vector(0, 0, stockBB.ZLength + 2))
|
||||
self.bodies.append(body)
|
||||
self.removalshapes.append((self.stock.Shape.cut(body), False))
|
||||
self.removalshapes.append((self.stock.Shape.cut(body), False, 'outline', 0.0, 'X'))
|
||||
|
||||
for (shape,hole) in self.removalshapes:
|
||||
shape.tessellate(0.1)
|
||||
for (shape, isHole, sub, angle, axis) in self.removalshapes:
|
||||
shape.tessellate(0.05)
|
||||
|
||||
if self.removalshapes:
|
||||
obj.removalshape = self.removalshapes[0][0]
|
||||
@@ -296,12 +573,11 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
|
||||
|
||||
def areaOpSetDefaultValues(self, obj, job):
|
||||
'''areaOpSetDefaultValues(obj, job) ... set default values'''
|
||||
|
||||
obj.StepOver = 100
|
||||
obj.ZigZagAngle = 45
|
||||
if job and job.Stock:
|
||||
bb = job.Stock.Shape.BoundBox
|
||||
obj.OpFinalDepth = bb.ZMin
|
||||
obj.OpStartDepth = bb.ZMax
|
||||
obj.B_AxisErrorOverride = False
|
||||
obj.ReverseDirection = False
|
||||
obj.setExpression('ExtensionLengthDefault', 'OpToolDiameter / 2')
|
||||
|
||||
def createExtension(self, obj, extObj, extFeature, extSub):
|
||||
@@ -310,7 +586,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))
|
||||
@@ -321,10 +597,12 @@ class ObjectPocket(PathPocketBase.ObjectPocket):
|
||||
PathLog.track(obj.Label, len(extensions))
|
||||
obj.ExtensionFeature = [(ext.obj, ext.getSubLink()) for ext in extensions]
|
||||
|
||||
def SetupProperties():
|
||||
return PathPocketBase.SetupProperties() + [ 'UseOutline', 'ExtensionCorners' ]
|
||||
|
||||
def Create(name, obj = None):
|
||||
def SetupProperties():
|
||||
return PathPocketBase.SetupProperties() + ['UseOutline', 'ExtensionCorners']
|
||||
|
||||
|
||||
def Create(name, obj=None):
|
||||
'''Create(name) ... Creates and returns a Pocket operation.'''
|
||||
if obj is None:
|
||||
obj = FreeCAD.ActiveDocument.addObject('Path::FeaturePython', name)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -24,7 +24,8 @@ def temporary_exec(text, globals, locals):
|
||||
def ensureDir(path,mode=0o777):
|
||||
try:
|
||||
os.makedirs(path,mode)
|
||||
except OSError(err):
|
||||
except OSError as err:
|
||||
# https://docs.python.org/3/tutorial/errors.html
|
||||
# raise an error unless it's about an already existing directory
|
||||
print("Dir Exist")
|
||||
#if errno != 17 or not os.path.isdir(path):
|
||||
|
||||
Reference in New Issue
Block a user