From 712d35bd890b28af7ca74219b206cb274250055e Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 6 Nov 2008 07:48:55 +0000
Subject: [PATCH] delFreeEdge

---
 Fltk/Callbacks.cpp         |  2 +-
 Geo/GEdgeLoop.h            |  1 +
 Geo/GFace.cpp              | 29 ++++++++++++++
 Geo/GFace.h                |  4 ++
 Geo/GModelIO_OCC.cpp       |  3 ++
 Geo/GeoStringInterface.cpp | 19 ++++++----
 Geo/OCCFace.cpp            | 77 ++++++++++++++++----------------------
 Geo/OCCIncludes.h          |  1 -
 8 files changed, 82 insertions(+), 54 deletions(-)

diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index 44415810df..58631e5eee 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -3979,7 +3979,7 @@ static void _add_transfinite(int dim)
           if(ib == 'e') {
             switch (dim) {
             case 2:
-              if(p.size() == 3 + 1 || p.size() == 4 + 1)
+              if(p.size() == 0 + 1 || p.size() == 3 + 1 || p.size() == 4 + 1)
                 add_trsfsurf(p, CTX.filename,
                              WID->context_mesh_choice[1]->text());
               else
diff --git a/Geo/GEdgeLoop.h b/Geo/GEdgeLoop.h
index e086c7b202..7e7ce636e1 100644
--- a/Geo/GEdgeLoop.h
+++ b/Geo/GEdgeLoop.h
@@ -37,6 +37,7 @@ class GEdgeLoop
   inline iter end() { return loop.end(); }
   inline citer begin() const { return loop.begin(); }
   inline citer end() const { return loop.end(); }
+  inline void erase(iter it){ loop.erase(it); }
   int count(GEdge*) const;
   int count() const { return loop.size(); }
 };
diff --git a/Geo/GFace.cpp b/Geo/GFace.cpp
index a36735c2ae..6dfaf1e5d1 100644
--- a/Geo/GFace.cpp
+++ b/Geo/GFace.cpp
@@ -53,6 +53,35 @@ GFace::~GFace()
     delete va_geom_triangles;
 }
 
+void GFace::delFreeEdge(GEdge *e)
+{ 
+  // delete the edge from the edge list and the orientation list
+  std::list<GEdge*>::iterator ite = l_edges.begin();
+  std::list<int>::iterator itd = l_dirs.begin();
+  while(ite != l_edges.end()){
+    if(e == *ite){
+      Msg::Debug("Erasing edge %d from edge list in face %d", e->tag(), tag());
+      l_edges.erase(ite);
+      if(itd != l_dirs.end()) l_dirs.erase(itd);
+      break;
+    }
+    ite++; 
+    if(itd != l_dirs.end()) itd++;
+  }
+
+  // delete the edge from the edge loops
+  for(std::list<GEdgeLoop>::iterator it = edgeLoops.begin(); 
+      it != edgeLoops.end(); it++){
+    for(GEdgeLoop::iter it2 = it->begin(); it2 != it->end(); it2++){
+      if(e == it2->ge){
+        Msg::Debug("Erasing edge %d from edge loop in face %d", e->tag(), tag());
+        it->erase(it2);
+        break;
+      }
+    }
+  }
+}
+
 void GFace::deleteMesh()
 {
   for(unsigned int i = 0; i < mesh_vertices.size(); i++) delete mesh_vertices[i];
diff --git a/Geo/GFace.h b/Geo/GFace.h
index d58780d47b..3cd5497d2f 100644
--- a/Geo/GFace.h
+++ b/Geo/GFace.h
@@ -67,6 +67,10 @@ class GFace : public GEntity
   void addEmbeddedVertex(GVertex *v){ embedded_vertices.push_back(v); }
   void addEmbeddedEdge(GEdge *e){ embedded_edges.push_back(e); }
   
+  // delete the edge from the face (the edge is supposed to be a free
+  // edge in the face, not part of any edge loops--use with caution!)
+  void delFreeEdge(GEdge *e);
+
   // edge orientations
   virtual std::list<int> orientations() const { return l_dirs; }
 
diff --git a/Geo/GModelIO_OCC.cpp b/Geo/GModelIO_OCC.cpp
index 478816d790..a5c489df28 100644
--- a/Geo/GModelIO_OCC.cpp
+++ b/Geo/GModelIO_OCC.cpp
@@ -670,6 +670,9 @@ static void applyOCCMeshConstraints(GModel *m, const void *constraints)
           if(shape.IsSame(*shape2)){
             Msg::Debug("... embedding edge in face %d", gf->tag());
             gf->addEmbeddedEdge(ge);
+            // the surface might have this edge as an open wire: make
+            // sure to remove it
+            gf->delFreeEdge(ge);
           }
         }
       }
diff --git a/Geo/GeoStringInterface.cpp b/Geo/GeoStringInterface.cpp
index 5cd8176e42..72a8d43cbd 100644
--- a/Geo/GeoStringInterface.cpp
+++ b/Geo/GeoStringInterface.cpp
@@ -162,15 +162,18 @@ void add_trsfline(std::vector<int> &l, std::string filename, std::string type,
 void add_trsfsurf(std::vector<int> &l, std::string filename, std::string dir)
 {
   std::ostringstream sstream;
-  sstream << "Transfinite Surface {" << l[0] << "} = {";
-  for(unsigned int i = 1; i < l.size(); i++) {
-    if(i > 1) sstream << ", ";
-    sstream << l[i];
+  sstream << "Transfinite Surface {" << l[0] << "}";
+  if(l.size() > 1){
+    sstream << " = {";
+    for(unsigned int i = 1; i < l.size(); i++) {
+      if(i > 1) sstream << ", ";
+      sstream << l[i];
+    }
+    sstream << "}";
   }
-  if(dir == "Left")
-    sstream << "};";
-  else
-    sstream << "} " << dir << ";";
+  if(dir != "Left")
+    sstream << " " << dir;
+  sstream << ";";
   add_infile(sstream.str(), filename);
 }
 
diff --git a/Geo/OCCFace.cpp b/Geo/OCCFace.cpp
index 301f6a9afb..3cf99a6c2e 100644
--- a/Geo/OCCFace.cpp
+++ b/Geo/OCCFace.cpp
@@ -33,54 +33,43 @@ OCCFace::OCCFace(GModel *m, TopoDS_Face _s, int num, TopTools_IndexedMapOfShape
   TopExp_Explorer exp2, exp3;
   for(exp2.Init(s, TopAbs_WIRE); exp2.More(); exp2.Next()){
     TopoDS_Wire wire = TopoDS::Wire(exp2.Current());
-    ShapeAnalysis_Wire check(wire, s, 0.);
-    // only add closed wires (yes, the test is correct: CheckClosed
-    // returns false when the wire is closed)
-    if(check.CheckClosed()){
-      Msg::Debug("OCC Face %d - Skipping open Wire", num);
-    }
-    else{
-      Msg::Debug("OCC Face %d - New Wire", num);
-      std::list<GEdge*> l_wire;
-      for(exp3.Init(wire, TopAbs_EDGE); exp3.More(); exp3.Next()){          
-        TopoDS_Edge edge = TopoDS::Edge(exp3.Current());
-        int index = emap.FindIndex(edge);
-        GEdge *e = m->getEdgeByTag(index);
-        if(!e){
-          Msg::Error("Unknown edge %d in face %d", index, num);
-        }
-        else if(std::find(embedded_edges.begin(), embedded_edges.end(), e) != 
-                embedded_edges.end()){
-          Msg::Debug("OCC Face %d - Skipping embedded edge in loop", num);
-        }
-        else{
-          l_wire.push_back(e);
-          Msg::Debug("Edge %d ori %d", e->tag(), edge.Orientation());
-          e->addFace(this);
-          if(!e->is3D()){
-            OCCEdge *occe = (OCCEdge*)e;
-            occe->setTrimmed(this);
-          }
-        }
-      }      
-
-      GEdgeLoop el(l_wire);
-      for(GEdgeLoop::citer it = el.begin(); it != el.end(); ++it){
-        l_edges.push_back(it->ge);
-        l_dirs.push_back(it->_sign);
-        if (el.count() == 2){
-          it->ge->meshAttributes.minimumMeshSegments = 
-            std::max(it->ge->meshAttributes.minimumMeshSegments,2);
-        }
-        if (el.count() == 1){
-          it->ge->meshAttributes.minimumMeshSegments = 
-            std::max(it->ge->meshAttributes.minimumMeshSegments,3);
+    Msg::Debug("OCC Face %d - New Wire", num);
+    std::list<GEdge*> l_wire;
+    for(exp3.Init(wire, TopAbs_EDGE); exp3.More(); exp3.Next()){          
+      TopoDS_Edge edge = TopoDS::Edge(exp3.Current());
+      int index = emap.FindIndex(edge);
+      GEdge *e = m->getEdgeByTag(index);
+      if(!e){
+        Msg::Error("Unknown edge %d in face %d", index, num);
+      }
+      else{
+        l_wire.push_back(e);
+        Msg::Debug("Edge %d ori %d", e->tag(), edge.Orientation());
+        e->addFace(this);
+        if(!e->is3D()){
+          OCCEdge *occe = (OCCEdge*)e;
+          occe->setTrimmed(this);
         }
       }
-      edgeLoops.push_back(el);
+    }      
+    
+    GEdgeLoop el(l_wire);
+    for(GEdgeLoop::citer it = el.begin(); it != el.end(); ++it){
+      l_edges.push_back(it->ge);
+      l_dirs.push_back(it->_sign);
+      if (el.count() == 2){
+        it->ge->meshAttributes.minimumMeshSegments = 
+          std::max(it->ge->meshAttributes.minimumMeshSegments,2);
+      }
+      if (el.count() == 1){
+        it->ge->meshAttributes.minimumMeshSegments = 
+          std::max(it->ge->meshAttributes.minimumMeshSegments,3);
+      }
     }
+    edgeLoops.push_back(el);
   }
-  BRepAdaptor_Surface surface( s );
+
+  BRepAdaptor_Surface surface(s);
   _periodic[0] = surface.IsUPeriodic();
   _periodic[1] = surface.IsVPeriodic();
 
diff --git a/Geo/OCCIncludes.h b/Geo/OCCIncludes.h
index 8afa09a496..43626856dc 100644
--- a/Geo/OCCIncludes.h
+++ b/Geo/OCCIncludes.h
@@ -93,7 +93,6 @@ using std::iostream;
 #include "ShapeAnalysis_ShapeContents.hxx"
 #include "ShapeAnalysis_CheckSmallFace.hxx"
 #include "ShapeAnalysis_DataMapOfShapeListOfReal.hxx"
-#include "ShapeAnalysis_Wire.hxx"
 #include "BRepAlgoAPI_Fuse.hxx"
 #include "BRepCheck_Analyzer.hxx"
 #include "BRepLib.hxx"
-- 
GitLab