From 07fcf551d0908ded54fe0309027664252a4fcf98 Mon Sep 17 00:00:00 2001 From: Paul Lee Date: Sun, 23 Mar 2025 12:06:27 +0800 Subject: [PATCH] [Draft-Faces] Bind: Improve fuse and warning 1. Face fuse per segment (original code has a whole face/segment disappear when a face is self-intersecting or reversed) 2. Return warning if face is self-intersecting Or reversed Github Issue: - https://github.com/FreeCAD/FreeCAD/issues/19721#issuecomment-2744738019 FreeCAD Forum: - https://forum.freecad.org/viewtopic.php?p=816758#p816758 - https://forum.freecad.org/viewtopic.php?p=813062#p813062 --- src/Mod/Draft/draftgeoutils/faces.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Mod/Draft/draftgeoutils/faces.py b/src/Mod/Draft/draftgeoutils/faces.py index 60b8a8faa5..1c329f0fc8 100644 --- a/src/Mod/Draft/draftgeoutils/faces.py +++ b/src/Mod/Draft/draftgeoutils/faces.py @@ -120,15 +120,21 @@ def bind(w1, w2, per_segment=False): """ def create_face(w1, w2): + try: w3 = Part.LineSegment(w1.Vertexes[0].Point, w2.Vertexes[0].Point).toShape() w4 = Part.LineSegment(w1.Vertexes[-1].Point, w2.Vertexes[-1].Point).toShape() - return Part.Face(Part.Wire(w1.Edges + [w3] + w2.Edges + [w4])) except Part.OCCError: print("DraftGeomUtils: unable to bind wires") return None + 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: print("DraftGeomUtils: unable to bind wires") @@ -164,6 +170,7 @@ def bind(w1, w2, per_segment=False): if face is None: return None faces.append(face) + # Usually there is last series of face after above 'for' routine, # EXCEPT when the last edge pair touch, faces had been appended # to faces_list, and reset faces =[] @@ -185,14 +192,25 @@ def bind(w1, w2, per_segment=False): faces_fused_list = [] for faces in faces_list: if len(faces) > 1 : - faces_fused = faces[0].fuse(faces[1:]).removeSplitter().Faces[0] - faces_fused_list.append(faces_fused) + # 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] + 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: - return faces[0].fuse(faces[1:]).removeSplitter().Faces[0] + # 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] + return rf elif w1.isClosed() and w2.isClosed(): d1 = w1.BoundBox.DiagonalLength