[Draft-Faces] Bind: Improve fuse and warning - Further Fix

Github Discussion:
- Fix problem Roy-043 pointed out https://github.com/FreeCAD/FreeCAD/pull/20395#pullrequestreview-2726624360

FC Forum:
- https://forum.freecad.org/viewtopic.php?p=819121#p819121
This commit is contained in:
Paul Lee
2025-03-30 10:29:36 +08:00
parent 07fcf551d0
commit b05c02b6f1

View File

@@ -132,8 +132,6 @@ def bind(w1, w2, per_segment=False):
if w3.section(w4).Vertexes:
print("DraftGeomUtils: Problem, a segment is self-intersecting, please check!")
f = Part.Face(Part.Wire(w1.Edges + [w3] + w2.Edges + [w4]))
if f.normalAt(0,0).z == -1:
print("DraftGeomUtils: Problem, a segment direction is reversed, please check!")
return f
if not w1 or not w2:
@@ -185,31 +183,53 @@ def bind(w1, w2, per_segment=False):
#
if w1.isClosed() and w2.isClosed() \
and len(faces_list) > 1 and faces_list[0]:
faces_list[0].extend(faces)
faces_list[0].extend(faces) # TODO: To be reviewed, 'afterthought' on 2025.3.29, seems by 'extend', faces in 1st and last faces are not in sequential order
else:
faces_list.append(faces) # Break into separate list
from collections import Counter
if faces_list:
faces_fused_list = []
for faces in faces_list:
dir = []
countDir = None
for f in faces:
dir.append(f.normalAt(0,0).z)
countDir = Counter(dir)
l = len(faces)
m = max(countDir.values()) # max(countDir, key=countDir.get)
if m != l:
print("DraftGeomUtils: Problem, the direction of " + str(l-m) + " out of " + str(l) + " segment is reversed, please check!")
if len(faces) > 1 :
# Below not good if a face is self-intersecting or reversed
#faces_fused = faces[0].fuse(faces[1:]).removeSplitter().Faces[0]
rf = faces[0]
for f in faces[1:]:
rf = rf.fuse(f).removeSplitter().Faces[0]
#rf = rf.fuse(f) # Not working
#rf = rf.removeSplitter().Faces[0] # Not working
faces_fused_list.append(rf)
# faces might be empty list [], see above; skip if empty
elif faces:
faces_fused_list.append(faces[0]) # Only 1 face
return Part.Compound(faces_fused_list)
else:
dir = []
countDir = None
for f in faces:
dir.append(f.normalAt(0,0).z)
countDir = Counter(dir)
l = len(faces)
m = max(countDir.values()) # max(countDir, key=countDir.get)
if m != l:
print("DraftGeomUtils: Problem, the direction of " + str(l-m) + " out of " + str(l) + " segment is reversed, please check!")
# Below not good if a face is self-intersecting or reversed
#return faces[0].fuse(faces[1:]).removeSplitter().Faces[0]
rf = faces[0]
for f in faces[1:]:
rf = rf.fuse(f).removeSplitter().Faces[0]
#rf = rf.fuse(f) # Not working
#rf = rf.removeSplitter().Faces[0] # Not working
return rf
elif w1.isClosed() and w2.isClosed():