Merge pull request #4917 from Russ4262/fix/Adaptive_process_edges

[Path] Adaptive: Correct the processing of selected edges
This commit is contained in:
sliptonic
2021-07-23 12:35:08 -05:00
committed by GitHub
5 changed files with 639 additions and 60 deletions

View File

@@ -42,6 +42,7 @@ Part = LazyLoader('Part', globals(), 'Part')
FeatureExtensions = LazyLoader('PathScripts.PathFeatureExtensions',
globals(),
'PathScripts.PathFeatureExtensions')
DraftGeomUtils = LazyLoader('DraftGeomUtils', globals(), 'DraftGeomUtils')
if FreeCAD.GuiUp:
from pivy import coin
@@ -559,16 +560,16 @@ def Execute(op, obj):
def _get_working_edges(op, obj):
"""_get_working_edges(op, obj)...
'''_get_working_edges(op, obj)...
Compile all working edges from the Base Geometry selection (obj.Base)
for the current operation.
Additional modifications to selected region(face), such as extensions,
should be placed within this function.
"""
regions = list()
'''
all_regions = list()
edge_list = list()
avoidFeatures = list()
rawEdges = list()
# Get extensions and identify faces to avoid
extensions = FeatureExtensions.getExtensions(obj)
@@ -579,20 +580,35 @@ def _get_working_edges(op, obj):
# Get faces selected by user
for base, subs in obj.Base:
for sub in subs:
if sub not in avoidFeatures:
if obj.UseOutline:
face = base.Shape.getElement(sub)
# get outline with wire_A method used in PocketShape, but it does not play nicely later
# wire_A = TechDraw.findShapeOutline(face, 1, FreeCAD.Vector(0.0, 0.0, 1.0))
wire_B = face.Wires[0]
shape = Part.Face(wire_B)
else:
shape = base.Shape.getElement(sub)
regions.append(shape)
if sub.startswith("Face"):
if sub not in avoidFeatures:
if obj.UseOutline:
face = base.Shape.getElement(sub)
# get outline with wire_A method used in PocketShape, but it does not play nicely later
# wire_A = TechDraw.findShapeOutline(face, 1, FreeCAD.Vector(0.0, 0.0, 1.0))
wire_B = face.Wires[0]
shape = Part.Face(wire_B)
else:
shape = base.Shape.getElement(sub)
all_regions.append(shape)
elif sub.startswith("Edge"):
# Save edges for later processing
rawEdges.append(base.Shape.getElement(sub))
# Efor
# Return Extend Outline extension, OR regular edge extension
all_regions = regions
# Process selected edges
if rawEdges:
edgeWires = DraftGeomUtils.findWires(rawEdges)
if edgeWires:
for w in edgeWires:
# Extrude closed wire, take cross-section (flatten), and add area to regions list with faces
if w.isClosed():
extLen = w.BoundBox.ZLength + 10.0
extrudeWire = w.extrude(FreeCAD.Vector(0.0, 0.0, extLen * 5.0))
slices = extrudeWire.slice(FreeCAD.Vector(0.0, 0.0, 1.0), math.floor(w.BoundBox.ZMin + (extLen * 2.5)))
slices[0].translate(FreeCAD.Vector(0.0, 0.0, 0.0 - slices[0].BoundBox.ZMin))
all_regions.append(Part.Face(slices[0])) # Add wire area to all regions for combination with extensions
# Apply regular Extensions
op.exts = [] # pylint: disable=attribute-defined-outside-init
for ext in extensions:
@@ -605,10 +621,12 @@ def _get_working_edges(op, obj):
# Second face-combining method attempted
horizontal = PathGeom.combineHorizontalFaces(all_regions)
for f in horizontal:
for w in f.Wires:
for e in w.Edges:
edge_list.append([discretize(e)])
if horizontal:
obj.removalshape = Part.makeCompound(horizontal)
for f in horizontal:
for w in f.Wires:
for e in w.Edges:
edge_list.append([discretize(e)])
return edge_list
@@ -662,6 +680,9 @@ class PathAdaptive(PathOp.ObjectOp):
obj.addProperty("App::PropertyBool", "UseOutline", "Adaptive", "Uses the outline of the base geometry.")
obj.addProperty("Part::PropertyPartShape", "removalshape", "Path", "")
obj.setEditorMode('removalshape', 2) # hide
FeatureExtensions.initialize_properties(obj)
def opSetDefaultValues(self, obj, job):
@@ -703,6 +724,11 @@ class PathAdaptive(PathOp.ObjectOp):
"UseOutline",
"Adaptive",
"Uses the outline of the base geometry.")
if not hasattr(obj, "removalshape"):
obj.addProperty("Part::PropertyPartShape", "removalshape", "Path", "")
obj.setEditorMode('removalshape', 2) # hide
FeatureExtensions.initialize_properties(obj)