Allow passing in additional face names to horizontalFaceLoop to further constrain the solution.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user