From aa7d6e1bab27e29e8415b5a443400d6675dd2ef1 Mon Sep 17 00:00:00 2001 From: Markus Lampert Date: Mon, 18 Sep 2017 18:01:39 -0700 Subject: [PATCH] Allow passing in additional face names to horizontalFaceLoop to further constrain the solution. --- src/Mod/Path/PathCommands.py | 19 +++++++++---------- src/Mod/Path/PathScripts/PathUtils.py | 13 ++++++------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Mod/Path/PathCommands.py b/src/Mod/Path/PathCommands.py index 1b15394e79..a21671c2c6 100644 --- a/src/Mod/Path/PathCommands.py +++ b/src/Mod/Path/PathCommands.py @@ -58,7 +58,7 @@ class _CommandSelectLoop: sel = FreeCADGui.Selection.getSelectionEx()[0] sub1 = sel.SubElementNames[0] if sub1[0:4] != 'Edge': - if len(sel.SubElementNames) == 1 and sub1[0:4] == 'Face' and horizontalFaceLoop(sel.Object, sel.SubObjects[0]): + if sub1[0:4] == 'Face' and horizontalFaceLoop(sel.Object, sel.SubObjects[0], sel.SubElementNames): return True return False if len(sel.SubElementNames) == 1 and horizontalEdgeLoop(sel.Object, sel.SubObjects[0]): @@ -74,15 +74,14 @@ class _CommandSelectLoop: sel = FreeCADGui.Selection.getSelectionEx()[0] obj = sel.Object edge1 = sel.SubObjects[0] - if len(sel.SubObjects) == 1: - if 'Face' in sel.SubElementNames[0]: - loop = horizontalFaceLoop(sel.Object, sel.SubObjects[0]) - if loop: - FreeCADGui.Selection.clearSelection() - FreeCADGui.Selection.addSelection(sel.Object, loop) - loopwire = [] - else: - loopwire = horizontalEdgeLoop(obj, edge1) + if 'Face' in sel.SubElementNames[0]: + loop = horizontalFaceLoop(sel.Object, sel.SubObjects[0], sel.SubElementNames) + if loop: + FreeCADGui.Selection.clearSelection() + FreeCADGui.Selection.addSelection(sel.Object, loop) + loopwire = [] + elif len(sel.SubObjects) == 1: + loopwire = horizontalEdgeLoop(obj, edge1) else: edge2 = sel.SubObjects[1] loopwire = loopdetect(obj, edge1, edge2) diff --git a/src/Mod/Path/PathScripts/PathUtils.py b/src/Mod/Path/PathScripts/PathUtils.py index b392500acb..5152315c90 100644 --- a/src/Mod/Path/PathScripts/PathUtils.py +++ b/src/Mod/Path/PathScripts/PathUtils.py @@ -226,13 +226,9 @@ def horizontalEdgeLoop(obj, edge): return loops[0] return None -def horizontalFaceLoop(obj, face): - '''horizontalFaceLoop(obj, face) ... returns a list of face names which form the walls of a vertical hole face is a part of.''' - - if not face and not obj: - sel = FreeCADGui.Selection.getSelectionEx()[0] - obj = sel.Object - face = sel.SubObjects[0] +def horizontalFaceLoop(obj, face, faceList=None): + '''horizontalFaceLoop(obj, face, faceList=None) ... returns a list of face names which form the walls of a vertical hole face is a part of. + All face names listed in faceList must be part of the hole for the solution to be returned.''' wires = [horizontalEdgeLoop(obj, e) for e in face.Edges] # Not sure if sorting by Area is a premature optimization - but it seems @@ -245,6 +241,9 @@ def horizontalFaceLoop(obj, face): #find all faces that share a an edge with the wire and are vertical faces = ["Face%d"%(i+1) for i,f in enumerate(obj.Shape.Faces) if any(e.hashCode() in hashes for e in f.Edges) and PathGeom.isVertical(f)] + if faceList and not all(f in faces for f in faceList): + continue + # verify they form a valid hole by getting the outline and comparing # the resulting XY footprint with that of the faces comp = Part.makeCompound([obj.Shape.getElement(f) for f in faces])