From e7f6747032b33e4decb3f335b2c99392429a6723 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 30 Jan 2007 08:56:36 +0000
Subject: [PATCH] - temporary fix for creation of second order vertices on
 periodic   curves and periodic surfaces

- speedup 2nd order vertex creation

- never create MFaceVertices if we don't know the parametric
  coordinates (this will screw up the 2nd order algo!): create
  MVertices instead

- fixed u,v coords of vertices after elliptic smoother in
  meshGFaceTransfinite

- added "-format msh1" and "-format msh2" shortcuts to quickly
  select the version of the msh format from the command line +
  added "med" and "cgns" formats

- moved gui guidelines in separate file
---
 Common/CommandLine.cpp        | 30 +++++++++----
 Common/DefaultOptions.h       |  2 +-
 Fltk/GUI.cpp                  | 51 ++--------------------
 Mesh/SecondOrder.cpp          | 80 +++++++++++++++++++++++++++--------
 Mesh/meshGFaceTransfinite.cpp | 11 ++++-
 Mesh/meshGRegion.cpp          |  5 +--
 doc/README.gui                | 42 ++++++++++++++++++
 doc/TODO                      |  7 +--
 doc/gmsh.1                    |  4 +-
 doc/texinfo/command_line.texi |  2 +-
 10 files changed, 145 insertions(+), 89 deletions(-)
 create mode 100644 doc/README.gui

diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp
index ca9c9a1e91..5054b7d693 100644
--- a/Common/CommandLine.cpp
+++ b/Common/CommandLine.cpp
@@ -1,4 +1,4 @@
-// $Id: CommandLine.cpp,v 1.93 2007-01-29 17:16:02 geuzaine Exp $
+// $Id: CommandLine.cpp,v 1.94 2007-01-30 08:56:36 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -81,7 +81,7 @@ void Print_Usage(char *name){
   Msg(DIRECT, "  -1, -2, -3            Perform 1D, 2D or 3D mesh generation, then exit");
   Msg(DIRECT, "  -saveall              Save all elements (discard physical group definitions)");
   Msg(DIRECT, "  -o file               Specify mesh output file name");
-  Msg(DIRECT, "  -format string        Set output mesh format (msh, unv, bdf, mesh, stl, vrml)");
+  Msg(DIRECT, "  -format string        Set output mesh format (msh, unv, vrml, stl, mesh, bdf, cgns, med)");
   Msg(DIRECT, "  -algo string          Select mesh algorithm (iso, netgen, tetgen)");
   Msg(DIRECT, "  -smooth int           Set number of mesh smoothing steps");
   Msg(DIRECT, "  -optimize             Optimize quality of tetrahedral elements");
@@ -375,18 +375,30 @@ void Get_Options(int argc, char *argv[])
       else if(!strcmp(argv[i] + 1, "format") || !strcmp(argv[i] + 1, "f")) {
         i++;
         if(argv[i] != NULL) {
-          if(!strcmp(argv[i], "msh"))
+          if(!strcmp(argv[i], "msh1")){
+            CTX.mesh.format = FORMAT_MSH;
+	    CTX.mesh.msh_file_version = 1.0;
+	  }
+          else if(!strcmp(argv[i], "msh2")){
+            CTX.mesh.format = FORMAT_MSH;
+	    CTX.mesh.msh_file_version = 2.0;
+	  }
+          else if(!strcmp(argv[i], "msh"))
             CTX.mesh.format = FORMAT_MSH;
           else if(!strcmp(argv[i], "unv"))
             CTX.mesh.format = FORMAT_UNV;
-          else if(!strcmp(argv[i], "bdf"))
-            CTX.mesh.format = FORMAT_BDF;
-          else if(!strcmp(argv[i], "mesh"))
-            CTX.mesh.format = FORMAT_MESH;
-	  else if(!strcmp(argv[i], "stl"))
-            CTX.mesh.format = FORMAT_STL;
           else if(!strcmp(argv[i], "vrml"))
             CTX.mesh.format = FORMAT_VRML;
+	  else if(!strcmp(argv[i], "stl"))
+            CTX.mesh.format = FORMAT_STL;
+          else if(!strcmp(argv[i], "mesh"))
+            CTX.mesh.format = FORMAT_MESH;
+          else if(!strcmp(argv[i], "bdf"))
+            CTX.mesh.format = FORMAT_BDF;
+          else if(!strcmp(argv[i], "cgns"))
+            CTX.mesh.format = FORMAT_CGNS;
+          else if(!strcmp(argv[i], "med"))
+            CTX.mesh.format = FORMAT_MED;
           else {
             fprintf(stderr, ERROR_STR "Unknown mesh format\n");
             exit(1);
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index db0baaa058..66883f0b02 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -893,7 +893,7 @@ StringXNumber MeshOptions_Number[] = {
     "Element shrinking factor (between 0 and 1)" },
 
   { F|O, "Format" , opt_mesh_format , FORMAT_MSH , 
-    "Mesh output format (1=msh, 2=unv, 19=vrml, 27=stl, 30=mesh, 31=bdf)" },
+    "Mesh output format (1=msh, 2=unv, 19=vrml, 27=stl, 30=mesh, 31=bdf, 32=cgns, 33=med)" },
 
   { F|O, "Hexahedra" , opt_mesh_hexahedra , 1. , 
     "Display mesh hexahedra?" },
diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index 55fdf98c77..efbd09bba7 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -1,4 +1,4 @@
-// $Id: GUI.cpp,v 1.596 2007-01-29 08:22:33 geuzaine Exp $
+// $Id: GUI.cpp,v 1.597 2007-01-30 08:56:36 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -19,52 +19,6 @@
 // 
 // Please report all bugs and problems to <gmsh@geuz.org>.
 
-// Some GUI guidelines:
-//
-// 1) To make the interface as visually consistent as possible, please:
-// - use the IW, BB, BH, BW and WB values
-// - examine what's already done before adding something new...
-//
-// 2) Use the following rule for buttons on dialog windows:
-// - "OK" is to agree with what is in the dialog *AND* close the dialog
-// - "Apply" is to apply the current values selected in the dialog, but
-//   leave the dialog open
-// - "Cancel" is to close (hide) the dialog and *NOT* apply the
-//   changes that might have been made in the dialog
-// The "Cancel" button, if present, should always be the last (-> at
-// right)
-//
-// 3) Only 'title-capitalize' titles and menus (Rules: 1. Always
-// capitalize the first and the last word. 2. Capitalize all nouns,
-// pronouns, adjectives, verbs, adverbs, and subordinate
-// conjunctions. 3. Lowercase all articles, coordinate conjunctions,
-// and prepositions, when they are other than the first or last
-// word. 4. Lowercase the "to" in an infinitive.) Capitalize everything
-// else like normal english sentences
-//
-// 4) Use an ellipsis character in a menu item for
-// - an action that requires further user input to complete or
-//   presents an alert allowing the user to cancel the action
-//   Examples: Find, Go To, Open, Page Setup, and Print.
-// - an action that opens a settings window. Examples: Set Title,
-//   Preferences, and Options.
-// Don't use en allipsis for:
-// - an action that requires no further user input to complete and
-//   does not present an alert.
-// - an action that opens an informational, accessory, or tool window.
-//   These windows can be implemented as either utility windows (as 
-//   in the case of a color palette) or modeless windows. These windows
-//   provide tools that help create or manage the content in the main
-//   window and are frequently left open to assist in accomplishing the
-//   task of the main window. Examples: Info and Show Tools.
-//
-// 5) The title of a window opened from a meny should be exactly the
-// same as the label of the menu item (without the ellipsis character if
-// there is one)
-
-// Don't indent this file
-// *INDENT-OFF*
-
 #include "Gmsh.h"
 #include "GmshUI.h"
 #include "GmshDefines.h"
@@ -169,6 +123,7 @@ Fl_Menu_Item m_sys_menubar_table[] = {
     {0},
   {0}
 };
+
 #endif
 
 Fl_Menu_Item m_module_table[] = {
@@ -1071,7 +1026,7 @@ void GUI::create_menu_window()
   m_window->size(width, MH);
   m_window->position(CTX.position[0], CTX.position[1]);
   
-  // force always on on top
+  // force always on top
   //m_window->set_non_modal();
 
   m_window->end();
diff --git a/Mesh/SecondOrder.cpp b/Mesh/SecondOrder.cpp
index 284db1f71b..d9900ce7ce 100644
--- a/Mesh/SecondOrder.cpp
+++ b/Mesh/SecondOrder.cpp
@@ -1,4 +1,4 @@
-// $Id: SecondOrder.cpp,v 1.51 2007-01-28 17:26:53 geuzaine Exp $
+// $Id: SecondOrder.cpp,v 1.52 2007-01-30 08:56:36 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -29,6 +29,38 @@
 
 extern GModel *GMODEL;
 
+bool reparamOnFace(MVertex *v, GFace *gf, SPoint2 &param)
+{
+  if(v->onWhat()->dim() == 0){
+    GVertex *gv = (GVertex*)v->onWhat();
+
+    // abort if we could be on a seam
+    std::list<GEdge*> ed = gv->edges();
+    for(std::list<GEdge*>::iterator it = ed.begin(); it != ed.end(); it++)
+      if((*it)->isSeam(gf)) return false;
+
+    param = gv->reparamOnFace(gf, 1);
+  }
+  else if(v->onWhat()->dim() == 1){
+    GEdge *ge = (GEdge*)v->onWhat();
+
+    // abort if we are on a seam (todo: try dir=-1 and compare)
+    if(ge->isSeam(gf)) return false;
+
+    double UU;
+    v->getParameter(0, UU);
+    param = ge->reparamOnFace(gf, UU, 1);
+  }
+  else{
+    double UU, VV;
+    if(v->onWhat() == gf && v->getParameter(0, UU) && v->getParameter(1, VV))
+      param = SPoint2(UU, VV);
+    else
+      param = gf->parFromPoint(SPoint3(v->x(), v->y(), v->z()));
+  }
+  return true;
+}
+
 void getEdgeVertices(GEdge *ge, MElement *ele, std::vector<MVertex*> &ve,
 		     std::map<std::pair<MVertex*,MVertex*>, MVertex* > &edgeVertices,
 		     bool linear)
@@ -60,13 +92,14 @@ void getEdgeVertices(GEdge *ge, MElement *ele, std::vector<MVertex*> &ve,
 	  u1 = bounds.high();
 	else 
 	  v1->getParameter(0, u1);
-	if(u0 < 1e6 && u1 < 1e6){
-	  double uc = 0.5 * (u0 + u1);
+	double uc = 0.5 * (u0 + u1);
+	if(u0 < 1e6 && u1 < 1e6 && uc > u0 && uc < u1){
 	  GPoint pc = ge->point(uc);
 	  v = new MEdgeVertex(pc.x(), pc.y(), pc.z(), ge, uc);
 	}
 	else{
-	  // we should normally never end up here
+	  // normally never here, but we don't treat periodic curves
+	  // properly, so we can get uc < u0 or uc > u1...
 	  SPoint3 pc = edge.barycenter();
 	  v = new MVertex(pc.x(), pc.y(), pc.z(), ge);
 	}
@@ -95,12 +128,18 @@ void getEdgeVertices(GFace *gf, MElement *ele, std::vector<MVertex*> &ve,
 	v = new MVertex(pc.x(), pc.y(), pc.z(), gf);
       }
       else{
-	SPoint2 p0 = gf->parFromPoint(SPoint3(v0->x(), v0->y(), v0->z()));
-	SPoint2 p1 = gf->parFromPoint(SPoint3(v1->x(), v1->y(), v1->z()));
-	double uc = 0.5 * (p0[0] + p1[0]);
-	double vc = 0.5 * (p0[1] + p1[1]);
-	GPoint pc = gf->point(uc, vc);
-	v = new MFaceVertex(pc.x(), pc.y(), pc.z(), gf, uc, vc);
+	SPoint2 p0, p1;
+	if(reparamOnFace(v0, gf, p0) && reparamOnFace(v1, gf, p1)){
+	  double uc = 0.5 * (p0[0] + p1[0]);
+	  double vc = 0.5 * (p0[1] + p1[1]);
+	  GPoint pc = gf->point(uc, vc);
+	  v = new MFaceVertex(pc.x(), pc.y(), pc.z(), gf, uc, vc);
+	}
+	else{
+	  // need to treat seams correctly!
+	  SPoint3 pc = edge.barycenter();
+	  v = new MVertex(pc.x(), pc.y(), pc.z(), gf);
+	}
       }
       edgeVertices[p] = v;
       gf->mesh_vertices.push_back(v);
@@ -148,14 +187,19 @@ void getFaceVertices(GFace *gf, MElement *ele, std::vector<MVertex*> &vf,
 	v = new MVertex(pc.x(), pc.y(), pc.z(), gf);
       }
       else{
-	SPoint2 p0 = gf->parFromPoint(SPoint3(p[0]->x(), p[0]->y(), p[0]->z()));
-	SPoint2 p1 = gf->parFromPoint(SPoint3(p[1]->x(), p[1]->y(), p[1]->z()));
-	SPoint2 p2 = gf->parFromPoint(SPoint3(p[2]->x(), p[2]->y(), p[2]->z()));
-	SPoint2 p3 = gf->parFromPoint(SPoint3(p[3]->x(), p[3]->y(), p[3]->z()));
-	double uc = 0.25 * (p0[0] + p1[0] + p2[0] + p3[0]);
-	double vc = 0.25 * (p0[1] + p1[1] + p2[1] + p3[1]);
-	GPoint pc = gf->point(uc, vc);
-	v = new MFaceVertex(pc.x(), pc.y(), pc.z(), gf, uc, vc);
+	SPoint2 p0, p1, p2, p3;
+	if(reparamOnFace(p[0], gf, p0) && reparamOnFace(p[1], gf, p1) &&
+	   reparamOnFace(p[2], gf, p2) && reparamOnFace(p[3], gf, p3)){
+	  double uc = 0.25 * (p0[0] + p1[0] + p2[0] + p3[0]);
+	  double vc = 0.25 * (p0[1] + p1[1] + p2[1] + p3[1]);
+	  GPoint pc = gf->point(uc, vc);
+	  v = new MFaceVertex(pc.x(), pc.y(), pc.z(), gf, uc, vc);
+	}
+	else{
+	  // need to treat seams correctly!
+	  SPoint3 pc = face.barycenter();
+	  v = new MVertex(pc.x(), pc.y(), pc.z(), gf);
+	}
       }
       faceVertices[p] = v;
       gf->mesh_vertices.push_back(v);
diff --git a/Mesh/meshGFaceTransfinite.cpp b/Mesh/meshGFaceTransfinite.cpp
index 1d2be97757..7bb986fb54 100644
--- a/Mesh/meshGFaceTransfinite.cpp
+++ b/Mesh/meshGFaceTransfinite.cpp
@@ -1,4 +1,4 @@
-// $Id: meshGFaceTransfinite.cpp,v 1.16 2007-01-07 10:52:46 geuzaine Exp $
+// $Id: meshGFaceTransfinite.cpp,v 1.17 2007-01-30 08:56:36 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -331,6 +331,15 @@ int MeshTransfiniteSurface(GFace *gf)
 	}
       }
     }
+    // recompute corresponding u,v coordinates (necessary e.g. for 2nd order algo)
+    for(int i = 1; i < L; i++){
+      for(int j = 1; j < H; j++){
+	MVertex *v = tab[std::make_pair(i,j)];
+	SPoint2 param = gf->parFromPoint(SPoint3(v->x(), v->y(), v->z()));
+	v->setParameter(0, param[0]);
+	v->setParameter(1, param[1]);
+      }
+    }
   }
 
   if(corners.size() == 4){ 
diff --git a/Mesh/meshGRegion.cpp b/Mesh/meshGRegion.cpp
index 8a0ee3d091..ac05211b00 100644
--- a/Mesh/meshGRegion.cpp
+++ b/Mesh/meshGRegion.cpp
@@ -1,4 +1,4 @@
-// $Id: meshGRegion.cpp,v 1.26 2007-01-25 20:41:40 geuzaine Exp $
+// $Id: meshGRegion.cpp,v 1.27 2007-01-30 08:56:36 geuzaine Exp $
 //
 // Copyright (C) 1997-2007 C. Geuzaine, J.-F. Remacle
 //
@@ -161,8 +161,7 @@ void TransferTetgenMesh(GRegion *gr,
 	  (std::find(v[j]->onWhat()->mesh_vertices.begin(),
 		     v[j]->onWhat()->mesh_vertices.end(),
 		     v[j]));
-	MFaceVertex *v1b = new MFaceVertex(v[j]->x(), v[j]->y(), v[j]->z(), 
-					   gf, 0., 0.);
+	MVertex *v1b = new MVertex(v[j]->x(), v[j]->y(), v[j]->z(), gf);
 	gf->mesh_vertices.push_back(v1b);
 	numberedV[out.trifacelist[i * 3 + j] - 1] = v1b;
 	delete v[j];
diff --git a/doc/README.gui b/doc/README.gui
new file mode 100644
index 0000000000..3fa50c816b
--- /dev/null
+++ b/doc/README.gui
@@ -0,0 +1,42 @@
+Some GUI guidelines:
+
+1) To make the interface as visually consistent as possible, please:
+- use the IW, BB, BH, BW and WB values
+- examine what's already done before adding something new...
+
+2) Use the following rule for buttons on dialog windows:
+- "OK" is to agree with what is in the dialog *AND* close the dialog
+- "Apply" is to apply the current values selected in the dialog, but
+  leave the dialog open
+- "Cancel" is to close (hide) the dialog and *NOT* apply the
+  changes that might have been made in the dialog
+The "Cancel" button, if present, should always be the last (-> at
+right)
+
+3) Only 'title-capitalize' titles and menus (Rules: 1. Always
+capitalize the first and the last word. 2. Capitalize all nouns,
+pronouns, adjectives, verbs, adverbs, and subordinate
+conjunctions. 3. Lowercase all articles, coordinate conjunctions,
+and prepositions, when they are other than the first or last
+word. 4. Lowercase the "to" in an infinitive.) Capitalize everything
+else like normal english sentences
+
+4) Use an ellipsis character in a menu item for
+- an action that requires further user input to complete or
+  presents an alert allowing the user to cancel the action
+  Examples: Find, Go To, Open, Page Setup, and Print.
+- an action that opens a settings window. Examples: Set Title,
+  Preferences, and Options.
+Don't use en allipsis for:
+- an action that requires no further user input to complete and
+  does not present an alert.
+- an action that opens an informational, accessory, or tool window.
+  These windows can be implemented as either utility windows (as 
+  in the case of a color palette) or modeless windows. These windows
+  provide tools that help create or manage the content in the main
+  window and are frequently left open to assist in accomplishing the
+  task of the main window. Examples: Info and Show Tools.
+
+5) The title of a window opened from a meny should be exactly the
+same as the label of the menu item (without the ellipsis character if
+there is one)
diff --git a/doc/TODO b/doc/TODO
index 0d6cc4f76f..f1d63d9aff 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -1,4 +1,4 @@
-$Id: TODO,v 1.42 2007-01-29 17:16:03 geuzaine Exp $
+$Id: TODO,v 1.43 2007-01-30 08:56:36 geuzaine Exp $
 
 ********************************************************************
 
@@ -6,11 +6,6 @@ introduce Right/Left/Alternate for extruded meshes
 
 ********************************************************************
 
-make sure to check for zlib in configure for med (even in non-gui
-case)
-
-********************************************************************
-
 fix second order mesh for periodic surfaces
 
 ********************************************************************
diff --git a/doc/gmsh.1 b/doc/gmsh.1
index 025f32b435..5e9243f82e 100644
--- a/doc/gmsh.1
+++ b/doc/gmsh.1
@@ -1,4 +1,4 @@
-.\" $Id: gmsh.1,v 1.76 2007-01-18 09:12:45 geuzaine Exp $
+.\" $Id: gmsh.1,v 1.77 2007-01-30 08:56:36 geuzaine Exp $
 .TH Gmsh 1 "09 March 2006" "Gmsh 2.0" "Gmsh Manual Pages"
 .UC 4
 .\" ********************************************************************
@@ -49,7 +49,7 @@ save all elements (and discard all physical group definitions).
 specify mesh output file name.
 .TP 4
 .B \-format string
-set output mesh format (msh, unv, gref, stl, p3d).
+set output mesh format (msh, unv, vrml, stl, mesh, bdf, cgns, med).
 .TP 4
 .B \-algo string
 select mesh algorithm (iso, netgen, tetgen).
diff --git a/doc/texinfo/command_line.texi b/doc/texinfo/command_line.texi
index bdb95ef951..eb3f229a69 100644
--- a/doc/texinfo/command_line.texi
+++ b/doc/texinfo/command_line.texi
@@ -19,7 +19,7 @@ Save all elements (discard physical group definitions)
 @item -o file
 Specify mesh output file name
 @item -format string
-Set output mesh format (msh, unv, bdf, mesh, stl, vrml)
+Set output mesh format (msh, unv, vrml, stl, mesh, bdf, cgns, med)
 @item -algo string
 Select mesh algorithm (iso, netgen, tetgen)
 @item -smooth int
-- 
GitLab