From 6ee6a598f76246b1ac3312e3a4341cac9afcc687 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 17 Nov 2008 10:33:00 +0000
Subject: [PATCH] merge both writeMSH routines

---
 Geo/GModelIO_Mesh.cpp | 11 ++----
 Geo/MVertex.cpp       | 90 +++++++++++++++++++------------------------
 Geo/MVertex.h         |  4 +-
 Mesh/meshGFace.cpp    |  2 +-
 4 files changed, 47 insertions(+), 60 deletions(-)

diff --git a/Geo/GModelIO_Mesh.cpp b/Geo/GModelIO_Mesh.cpp
index d1ffdf7d02..9a6ea54dbf 100644
--- a/Geo/GModelIO_Mesh.cpp
+++ b/Geo/GModelIO_Mesh.cpp
@@ -533,14 +533,11 @@ int GModel::writeMSH(const std::string &name, double version, bool binary,
   std::vector<GEntity*> entities;
   getEntities(entities);
   for(unsigned int i = 0; i < entities.size(); i++)
-    for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++){
-      if (!saveParametric)
-	entities[i]->mesh_vertices[j]->writeMSH(fp, binary, scalingFactor);
-      else
-	entities[i]->mesh_vertices[j]->writeMSH3(fp, binary, scalingFactor);
-    }
+    for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++)
+      entities[i]->mesh_vertices[j]->writeMSH(fp, binary, saveParametric, 
+                                              scalingFactor);
   if(binary) fprintf(fp, "\n");
-
+  
   if(version >= 2.0){
     if(saveParametric)
       fprintf(fp, "$EndParametricNodes\n");
diff --git a/Geo/MVertex.cpp b/Geo/MVertex.cpp
index 19d995c3a9..7bda5e677d 100644
--- a/Geo/MVertex.cpp
+++ b/Geo/MVertex.cpp
@@ -25,69 +25,59 @@ bool MVertexLessThanLexicographic::operator()(const MVertex *v1, const MVertex *
   return false;
 }
 
-void MVertex::writeMSH3(FILE *fp, bool binary, double scalingFactor)
+void MVertex::writeMSH(FILE *fp, bool binary, bool saveParametric, double scalingFactor)
 {
   if(_index < 0) return; // negative index vertices are never saved
-  int myDim = onWhat()->dim(); 
-  int myTag = onWhat()->tag(); 
-  if(!binary){
-    fprintf(fp, "%d %.16g %.16g %.16g %d %d", _index, 
-	    x() * scalingFactor, 
-	    y() * scalingFactor,
-	    z() * scalingFactor,
-	    myDim,myTag);      
-  }
-  else{
-    fwrite(&_index, sizeof(int), 1, fp);
-    double data[3] = {x() * scalingFactor, y() * scalingFactor, z() * scalingFactor};
-    fwrite(data, sizeof(double), 3, fp);
-    fwrite(&myDim, sizeof(int), 1, fp);
-    fwrite(&myTag, sizeof(int), 1, fp);
-  }
 
-  if (myDim == 1){
-    double _u;
-    getParameter(0,_u);
-    if(!binary)
-      fprintf(fp, " %.16g\n", _u); 	    
-    else
-      fwrite(&_u, sizeof(double), 1, fp);
-  }
-  else if (myDim == 2){
-    double _u,_v;
-    getParameter(0,_u);
-    getParameter(1,_v);
-    if(!binary)
-      fprintf(fp, " %.16g %.16g\n", _u,_v); 	    
-    else{
-      fwrite(&_u, sizeof(double), 1, fp);
-      fwrite(&_v, sizeof(double), 1, fp);
-    }
+  int myDim = 0, myTag = 0;
+  if(saveParametric && onWhat()){
+    myDim = onWhat()->dim(); 
+    myTag = onWhat()->tag();
   }
-  else
-    if(!binary)
-      fprintf(fp, "\n"); 	    
-}
-
-
-void MVertex::writeMSH(FILE *fp, bool binary, double scalingFactor)
-{
-  if(_index < 0) return; // negative index vertices are never saved
 
   if(!binary){
-    fprintf(fp, "%d %.16g %.16g %.16g\n", _index, 
-	    x() * scalingFactor, 
-	    y() * scalingFactor,
-	    z() * scalingFactor);      
+    if(!saveParametric)
+      fprintf(fp, "%d %.16g %.16g %.16g\n", _index, x() * scalingFactor, 
+              y() * scalingFactor, z() * scalingFactor);      
+    else
+      fprintf(fp, "%d %.16g %.16g %.16g %d %d", _index, x() * scalingFactor, 
+              y() * scalingFactor, z() * scalingFactor, myDim, myTag);
   }
   else{
     fwrite(&_index, sizeof(int), 1, fp);
     double data[3] = {x() * scalingFactor, y() * scalingFactor, z() * scalingFactor};
     fwrite(data, sizeof(double), 3, fp);
+    if(saveParametric){
+      fwrite(&myDim, sizeof(int), 1, fp);
+      fwrite(&myTag, sizeof(int), 1, fp);
+    }
   }
-}
-
 
+  if(saveParametric){
+    if(myDim == 1){
+      double _u;
+      getParameter(0, _u);
+      if(!binary)
+        fprintf(fp, " %.16g\n", _u); 	    
+      else
+        fwrite(&_u, sizeof(double), 1, fp);
+    }
+    else if (myDim == 2){
+      double _u, _v;
+      getParameter(0, _u);
+      getParameter(1, _v);
+      if(!binary)
+        fprintf(fp, " %.16g %.16g\n", _u, _v);
+      else{
+        fwrite(&_u, sizeof(double), 1, fp);
+        fwrite(&_v, sizeof(double), 1, fp);
+      }
+    }
+    else
+      if(!binary)
+        fprintf(fp, "\n"); 	    
+  }
+}
 
 void MVertex::writeVRML(FILE *fp, double scalingFactor)
 {
diff --git a/Geo/MVertex.h b/Geo/MVertex.h
index 99611dbef9..d058c7dab2 100644
--- a/Geo/MVertex.h
+++ b/Geo/MVertex.h
@@ -106,8 +106,8 @@ class MVertex{
   linearSearch(std::set<MVertex*, MVertexLessThanLexicographic> &pos);
 
   // IO routines
-  void writeMSH(FILE *fp, bool binary=false, double scalingFactor=1.0);
-  void writeMSH3(FILE *fp, bool binary=false, double scalingFactor=1.0);
+  void writeMSH(FILE *fp, bool binary=false, bool saveParametric=false,
+                double scalingFactor=1.0);
   void writeVRML(FILE *fp, double scalingFactor=1.0);
   void writeUNV(FILE *fp, double scalingFactor=1.0);
   void writeVTK(FILE *fp, bool binary=false, double scalingFactor=1.0,
diff --git a/Mesh/meshGFace.cpp b/Mesh/meshGFace.cpp
index fa629ce3b4..e31a90b134 100644
--- a/Mesh/meshGFace.cpp
+++ b/Mesh/meshGFace.cpp
@@ -1279,7 +1279,7 @@ void deMeshGFace::operator() (GFace *gf)
   gf->meshStatistics.nbTriangle = gf->meshStatistics.nbEdge = 0;
 }
 
-const int debugSurface = -100;
+const int debugSurface = -1;
 
 void meshGFace::operator() (GFace *gf)
 {
-- 
GitLab