diff --git a/Common/Context.h b/Common/Context.h
index b42bfd5bc50044a79e8e34e1a6c6aaa1ef7ea7ca..2f71d3b91d7fdec07c3ed1d67359ef9d22816a2b 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -173,7 +173,8 @@ public :
     int dual, interactive, renumber_nodes_continuous;
     int light, light_two_side, light_lines;
     int format, nbPartitions, nb_smoothing, algo2d, algo3d, order, algo_recombine;
-    int point_insertion, speed_max, min_circ_points, constrained_bgmesh;
+    int point_insertion, speed_max, min_circ_points;
+    int bgmesh_type, constrained_bgmesh;
     int histogram, initial_only;
     double normals, tangents, explode;
     int color_carousel;
diff --git a/Common/Options.cpp b/Common/Options.cpp
index def9af6d9cb34d0e75f4e959a3db5251b6ccbac6..3dbf968f2f1293f96e51bc30164d75444e1a1358 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.281 2006-08-05 10:05:44 geuzaine Exp $
+// $Id: Options.cpp,v 1.282 2006-08-05 13:31:28 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -148,6 +148,7 @@ void Init_Options(int num)
   CTX.mesh.changed = 1;
   CTX.mesh.oldxtrude = CTX.mesh.oldxtrude_recombine = 0; // old extrusion mesh generator
   CTX.mesh.check_duplicates = 0; // check for duplicate nodes in Read_Mesh
+  CTX.mesh.bgmesh_type = WITHPOINTS;
   CTX.post.combine_time = 0; // try to combine_time views at startup
   CTX.post.plugin_draw_function = NULL;
 #if defined(HAVE_FLTK)
diff --git a/Geo/GEdge.h b/Geo/GEdge.h
index 71a5fecbb14e6c4cca9dbce25f29bf24d6cab2b7..e7d87cf53f42bd63824630f13c17a3272a089fdb 100644
--- a/Geo/GEdge.h
+++ b/Geo/GEdge.h
@@ -59,10 +59,10 @@ class GEdge : public GEntity {
   virtual int minimumMeshSegments () const {return 1;}
   virtual int minimumDrawSegments () const {return 1;}
 
-  virtual std::string getInfoString()
+  virtual std::string getSpecificInfoString()
   {
     char tmp[256];
-    sprintf(tmp, "%s %d {%d,%d}", getTypeString().c_str(), tag(), v0->tag(), v1->tag());
+    sprintf(tmp, "{%d,%d}", v0->tag(), v1->tag());
     return std::string(tmp);
   }
 
diff --git a/Geo/GEntity.h b/Geo/GEntity.h
index 07abdbb5e6851352065ccdb5451a0822b5c5d4b3..681b47197eb7c1913b42ed055797b794a2fdef43 100644
--- a/Geo/GEntity.h
+++ b/Geo/GEntity.h
@@ -55,16 +55,16 @@ class GEntity {
       "Line",
       "Circle",
       "Ellipse",
-      "ParametricCurve",
-      "DiscreteCurve",
+      "Parametric curve",
+      "Discrete curve",
       "Plane",
       "Nurb",
       "Cylinder",
       "Sphere",
       "Cone",
       "Torus",
-      "ParametricSurface",
-      "DiscreteSurface",
+      "Parametric surface",
+      "Discrete surface",
       "Volume"
     };
     unsigned int type = (unsigned int)geomType();
@@ -74,11 +74,32 @@ class GEntity {
       return name[type];
   }
 
+  virtual std::string getSpecificInfoString() 
+  {
+    return "";
+  }
+
   virtual std::string getInfoString() 
   {
-    char tmp[256];
-    sprintf(tmp, "%s %d", getTypeString().c_str(), tag());
-    return std::string(tmp);
+    char str[256];
+    sprintf(str, "%s %d", getTypeString().c_str(), tag());
+    std::string specific = getSpecificInfoString();
+    if(specific.size()){
+      strcat(str, " ");
+      strcat(str, specific.c_str());
+    }
+    if(physicals.size()){
+      char str2[256] = " [";
+      for(unsigned int i = 0; i < physicals.size(); i++){
+	char str3[256];
+	sprintf(str3, "%d", physicals[i]);
+	if(i) strcat(str2, " ");
+	strcat(str2, str3);
+      }
+      strcat(str2, "]");
+      strcat(str, str2);
+    }
+    return std::string(str);
   }
 
   GEntity(GModel *m, int t) : _model(m), _tag(t)
diff --git a/Geo/GModelIO.cpp b/Geo/GModelIO.cpp
index 1e2fefe38656e35d24aad6ed6f9cdd2a9a560ca4..09f0509a2d4ab4fdd41e356d87d62a7d2ea8d5be 100644
--- a/Geo/GModelIO.cpp
+++ b/Geo/GModelIO.cpp
@@ -59,7 +59,7 @@ static void storeElementsInEntities(GModel *m, int type,
 	  e = new gmshEdge(m, it->first);
 	  m->add(e);
 	}
-	if(type == LGN1) copyElements(e->lines, it->second);
+	copyElements(e->lines, it->second);
       }
       break;
     case TRI1: case QUA1: 
diff --git a/Geo/GVertex.h b/Geo/GVertex.h
index 123c95667c76c37812a2608e83dac0e30703476d..1d53a12ee2d1bd87bfce7a6191b3a5e8e37b7aff 100644
--- a/Geo/GVertex.h
+++ b/Geo/GVertex.h
@@ -26,11 +26,10 @@ public:
   virtual int dim() const {return 0;}
   virtual GeomType geomType() const {return Point;}
   virtual double prescribedMeshSizeAtVertex() const {return 0;}
-  virtual std::string getInfoString()
+  virtual std::string getSpecificInfoString()
   {
     char tmp[256];
-    sprintf(tmp, "%s %d {%g,%g,%g}", getTypeString().c_str(), 
-	    tag(), x(), y(), z());
+    sprintf(tmp, "{%g,%g,%g}", x(), y(), z());
     return std::string(tmp);
   }
 
diff --git a/Mesh/1D_Mesh.cpp b/Mesh/1D_Mesh.cpp
index 26e5de0ab502f669b6980a316076d36fc53345bc..9aab2f951da2dca819a6442d76425aee33d28532 100644
--- a/Mesh/1D_Mesh.cpp
+++ b/Mesh/1D_Mesh.cpp
@@ -1,4 +1,4 @@
-// $Id: 1D_Mesh.cpp,v 1.49 2006-08-05 10:05:45 geuzaine Exp $
+// $Id: 1D_Mesh.cpp,v 1.50 2006-08-05 13:31:28 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -106,7 +106,7 @@ double F_Lc(double t)
   Vertex der, point;
   double Lc, d;
 
-  if(THEM->BackgroundMeshType == ONFILE) {
+  if(CTX.mesh.bgmesh_type == ONFILE) {
     der = InterpolateCurve(THEC, t, 1);
     point = InterpolateCurve(THEC, t, 0);
     Lc = BGMXYZ(point.Pos.X, point.Pos.Y, point.Pos.Z);
diff --git a/Mesh/2D_Mesh.cpp b/Mesh/2D_Mesh.cpp
index b4a54fe64102b8922e32b4f4c08d0343ac944cc6..0ed8e1e2e14687d5ef7165710a50c2bdd6e45b9e 100644
--- a/Mesh/2D_Mesh.cpp
+++ b/Mesh/2D_Mesh.cpp
@@ -1,4 +1,4 @@
-// $Id: 2D_Mesh.cpp,v 1.85 2006-08-05 10:05:45 geuzaine Exp $
+// $Id: 2D_Mesh.cpp,v 1.86 2006-08-05 13:31:28 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -305,7 +305,7 @@ int mesh_domain(ContourPeek * ListContours, int numcontours,
   Conversion(doc);
   remove_all_dlist(doc->numPoints, doc->points);
 
-  if(THEM->BackgroundMeshType != ONFILE || CTX.mesh.constrained_bgmesh)
+  if(CTX.mesh.bgmesh_type != ONFILE || CTX.mesh.constrained_bgmesh)
     BGMESH = doc;
   else
     BGMESH = NULL;
@@ -720,7 +720,7 @@ void filldel(Delaunay * deladd, int aa, int bb, int cc,
   pt2.h = deladd->t.xc;
   pt2.v = deladd->t.yc;
 
-  if(THEM->BackgroundMeshType == ONFILE) {
+  if(CTX.mesh.bgmesh_type == ONFILE) {
     v = Create_Vertex(-1, pt2.h, pt2.v, 0.0, 0.0, 0.0);
     Calcule_Z_Plan(&v, &dum);
     Projette_Inverse(&v, &dum);
diff --git a/Mesh/2D_Mesh_Aniso.cpp b/Mesh/2D_Mesh_Aniso.cpp
index 3d83c46578ab79718d084d3fc3062e788b8004a6..89a4993621a41626cbb421876bf205b012e74d92 100644
--- a/Mesh/2D_Mesh_Aniso.cpp
+++ b/Mesh/2D_Mesh_Aniso.cpp
@@ -1,4 +1,4 @@
-// $Id: 2D_Mesh_Aniso.cpp,v 1.54 2006-08-05 10:05:45 geuzaine Exp $
+// $Id: 2D_Mesh_Aniso.cpp,v 1.55 2006-08-05 13:31:28 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -61,7 +61,7 @@ double Interpole_lcTriangle(Simplex * s, Vertex * vv)
 {
   double Xp, Yp, X[3], Y[3], det, u, v, q1, q2, q3;
 
-  if(THEM->BackgroundMeshType == ONFILE){
+  if(CTX.mesh.bgmesh_type == ONFILE){
     Vertex *v2 = Create_Vertex(-1, vv->Pos.X, vv->Pos.Y, 0.0, 0.0, 0.0);
     Vertex *dum;
     Calcule_Z_Plan(&v2, &dum);
diff --git a/Mesh/2D_Mesh_Triangle.cpp b/Mesh/2D_Mesh_Triangle.cpp
index f058875d92bd448ebb1e843395fe9d21bd06a990..ea481819e345ead3be34ebe0ec81c28f9223317e 100644
--- a/Mesh/2D_Mesh_Triangle.cpp
+++ b/Mesh/2D_Mesh_Triangle.cpp
@@ -1,4 +1,4 @@
-// $Id: 2D_Mesh_Triangle.cpp,v 1.15 2006-01-29 22:53:41 geuzaine Exp $
+// $Id: 2D_Mesh_Triangle.cpp,v 1.16 2006-08-05 13:31:28 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -213,7 +213,7 @@ int Mesh_Triangle(Surface * s)
   mid.trianglearealist =
     (REAL *) Malloc(mid.numberoftriangles * sizeof(REAL));
   for(i = 0; i < mid.numberoftriangles; i++) {
-    if(THEM->BackgroundMeshType == ONFILE) {
+    if(CTX.mesh.bgmesh_type == ONFILE) {
       double xx = 0.0, yy = 0.0;
       for(j = 0; j < mid.numberofcorners; j++) {
 	k = mid.trianglelist[i * mid.numberofcorners + j];
diff --git a/Mesh/2D_Util.cpp b/Mesh/2D_Util.cpp
index b87f7139aac72436404815757ebfcd1aa322e638..3c5eb39d2ca8b23be93f2002a8483a44536d3d63 100644
--- a/Mesh/2D_Util.cpp
+++ b/Mesh/2D_Util.cpp
@@ -1,4 +1,4 @@
-// $Id: 2D_Util.cpp,v 1.25 2006-01-29 22:53:41 geuzaine Exp $
+// $Id: 2D_Util.cpp,v 1.26 2006-08-05 13:31:28 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -95,7 +95,7 @@ int Insert_Point(MPoint pt, int *numpoints, int *numalloc,
   gPointArray[*numpoints].where.v = pt.v;
   gPointArray[*numpoints].numcontour = -1;
   gPointArray[*numpoints].initial = -1;
-  if(THEM->BackgroundMeshType == ONFILE){
+  if(CTX.mesh.bgmesh_type == ONFILE){
     v = Create_Vertex(-1, pt.h, pt.v, 0.0, 0.0, 0.0);
     Calcule_Z_Plan(&v, &dum);
     Projette_Inverse(&v, &dum);
diff --git a/Mesh/3D_BGMesh.cpp b/Mesh/3D_BGMesh.cpp
index 2858cd000548c6a78c0562f4b0db76f3039870f2..23bebdae89eb169559fa17b6cd04ae9ec803efb4 100644
--- a/Mesh/3D_BGMesh.cpp
+++ b/Mesh/3D_BGMesh.cpp
@@ -1,4 +1,4 @@
-// $Id: 3D_BGMesh.cpp,v 1.47 2006-08-05 10:05:45 geuzaine Exp $
+// $Id: 3D_BGMesh.cpp,v 1.48 2006-08-05 13:31:28 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -38,7 +38,7 @@ int BGMWithView(Post_View * ErrView)
   if(BGM_OCTREE) delete BGM_OCTREE;
   BGM_OCTREE = new OctreePost(ErrView);
   BGM_MAX = ErrView->Max;
-  THEM->BackgroundMeshType = ONFILE;
+  CTX.mesh.bgmesh_type = ONFILE;
   return 1 ;
 }
 
@@ -46,7 +46,7 @@ double BGMXYZ(double X, double Y, double Z)
 {
   if(!BGM_OCTREE){
     Msg(GERROR, "Missing background mesh");
-    THEM->BackgroundMeshType = WITHPOINTS;
+    CTX.mesh.bgmesh_type = WITHPOINTS;
     return 1.;
   }
 
diff --git a/Mesh/3D_Mesh_Netgen.cpp b/Mesh/3D_Mesh_Netgen.cpp
index 47e734c4ff919f5f1f5f48c324ff0173615a8b96..9a86926c3c89d086181010b655274c2aec5bad92 100644
--- a/Mesh/3D_Mesh_Netgen.cpp
+++ b/Mesh/3D_Mesh_Netgen.cpp
@@ -1,4 +1,4 @@
-// $Id: 3D_Mesh_Netgen.cpp,v 1.24 2006-08-05 10:05:45 geuzaine Exp $
+// $Id: 3D_Mesh_Netgen.cpp,v 1.25 2006-08-05 13:31:28 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -280,7 +280,7 @@ int Mesh_Netgen(Volume * v)
   if(CTX.mesh.algo3d != FRONTAL_NETGEN)
     return 0;
 
-  if(THEM->BackgroundMeshType == ONFILE){
+  if(CTX.mesh.bgmesh_type == ONFILE){
     Msg(GERROR, "Netgen is not ready to be used with a background mesh");
     return 0;
   }
@@ -318,7 +318,7 @@ void Optimize_Netgen()
 
   // make sure we don't have ONFILE (so that when we create simplices
   // we don't try to compute the quality from the bgmesh)
-  THEM->BackgroundMeshType = WITHPOINTS; 
+  CTX.mesh.bgmesh_type = WITHPOINTS; 
 
   List_T *list = Tree2List(THEM->Volumes);
   for(int i = 0; i < List_Nbr(list); i++){
diff --git a/Mesh/3D_Mesh_Tetgen.cpp b/Mesh/3D_Mesh_Tetgen.cpp
index 32a86c3d99ba27209476c0dc865c53930837f571..81d0d75ea967c2e951fce5e6f064a6b49e927702 100644
--- a/Mesh/3D_Mesh_Tetgen.cpp
+++ b/Mesh/3D_Mesh_Tetgen.cpp
@@ -1,4 +1,4 @@
-// $Id: 3D_Mesh_Tetgen.cpp,v 1.8 2006-08-05 10:05:45 geuzaine Exp $
+// $Id: 3D_Mesh_Tetgen.cpp,v 1.9 2006-08-05 13:31:28 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -51,7 +51,7 @@ int Mesh_Tetgen(Volume * vol) {
   if(CTX.mesh.algo3d != DELAUNAY_TETGEN)
     return 0;
 
-  if(THEM->BackgroundMeshType == ONFILE){
+  if(CTX.mesh.bgmesh_type == ONFILE){
     Msg(GERROR, "Tetgen is not ready to be used with a background mesh");
     return 0;
   }
diff --git a/Mesh/Generator.cpp b/Mesh/Generator.cpp
index 551b1c5e0195225f61eb76f34e25acfe93a4bb5a..8a30482cd74a1c11ffc9217e1524db107c766d0d 100644
--- a/Mesh/Generator.cpp
+++ b/Mesh/Generator.cpp
@@ -1,4 +1,4 @@
-// $Id: Generator.cpp,v 1.87 2006-08-05 10:05:45 geuzaine Exp $
+// $Id: Generator.cpp,v 1.88 2006-08-05 13:31:28 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -464,7 +464,6 @@ void Init_Mesh()
   THEM->normals = new smooth_normals(CTX.mesh.angle_smooth_normals);
 
   THEM->status = 0;
-  THEM->BackgroundMeshType = WITHPOINTS;
 
   for(int i = 0; i < 3; i++){
     THEM->timing[i] = 0.0;
@@ -472,6 +471,8 @@ void Init_Mesh()
     THEM->quality_eta[i] = 0.0;
     THEM->quality_rho[i] = 0.0;
   }
+
+  CTX.mesh.bgmesh_type = WITHPOINTS;
   CTX.mesh.changed = 1;
 }
 
diff --git a/Mesh/Mesh.h b/Mesh/Mesh.h
index f76a30c05689dae5d97b7911c07d0995c4ab57dd..58b039877b50918acbffdcaea8abb49c0d4eeb51 100644
--- a/Mesh/Mesh.h
+++ b/Mesh/Mesh.h
@@ -330,7 +330,6 @@ struct _Mesh{
   Tree_T *EdgeLoops;
   List_T *PhysicalGroups;
   List_T *Partitions;
-  int BackgroundMeshType;
   smooth_normals *normals; // container for smooth normals
   double timing[3]; // timing for 1d, 2d and 3d mesh
   double quality_gamma[3]; // mesh quality statistics
diff --git a/Mesh/Simplex.cpp b/Mesh/Simplex.cpp
index 2e2b4258b554a2635d0082639b4dd2c3df2b8ce3..def18accd9caaa9058b0ceaa4a9a904318f453c8 100644
--- a/Mesh/Simplex.cpp
+++ b/Mesh/Simplex.cpp
@@ -1,4 +1,4 @@
-// $Id: Simplex.cpp,v 1.48 2006-08-05 10:05:45 geuzaine Exp $
+// $Id: Simplex.cpp,v 1.49 2006-08-05 13:31:28 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -394,12 +394,12 @@ void Simplex::Fourre_Simplexe(Vertex * v1, Vertex * v2, Vertex * v3,
 
   Center_Circum();
 
-  if(N == 4 && THEM && THEM->BackgroundMeshType == ONFILE){
+  if(N == 4 && CTX.mesh.bgmesh_type == ONFILE){
     Quality = fabs(4. * Radius / BGMXYZ(Center.X, Center.Y, Center.Z));
   }
   else{
-    Quality = (double)N *Radius / (V[0]->lc + V[1]->lc + V[2]->lc + 
-				   ((V[3]) ? V[3]->lc : 0.0));
+    Quality = (double)N * Radius / (V[0]->lc + V[1]->lc + V[2]->lc + 
+				    ((V[3]) ? V[3]->lc : 0.0));
   }
 
   for(i = 0; i < N; i++)
diff --git a/Mesh/meshGEdge.cpp b/Mesh/meshGEdge.cpp
index 4ecd35737e029eb559257e78e0cc6cb1fa1663b7..9e5acaeb4a0c517cf5f5cf8b3aa9f3a1cb3e2915 100644
--- a/Mesh/meshGEdge.cpp
+++ b/Mesh/meshGEdge.cpp
@@ -6,12 +6,11 @@
 #include "Context.h"
 #include "Message.h"
 
+extern Context_T CTX;
+
 static GEdge * _myGEdge;
 static double  _myGEdgeLength, t_begin, t_end, lc_begin, lc_end;
 static Range<double> _myGEdgeBounds;
-// boooooooh !!!!!!
-extern Mesh *THEM;
-extern Context_T CTX;
 
 double F_Lc_bis(double t)
 {
@@ -20,7 +19,7 @@ double F_Lc_bis(double t)
   SVector3 der = _myGEdge -> firstDer(t) ;
   const double d = norm(der);
 
-  if(THEM->BackgroundMeshType == ONFILE) {
+  if(CTX.mesh.bgmesh_type == ONFILE) {
     GPoint point = _myGEdge -> point(t) ;      
     const double Lc = BGMXYZ(point.x(), point.y(), point.z());
     if(CTX.mesh.constrained_bgmesh)
@@ -144,7 +143,7 @@ void meshGEdge :: operator() (GEdge *ge)
   else{
     a = Integration(_myGEdgeBounds.low(), _myGEdgeBounds.high(), 
 		    F_Lc_bis, Points, 1.e-4);
-    N = std::max (ge->minimumMeshSegments()+1, (int)(a + 1.));      
+    N = std::max(ge->minimumMeshSegments() + 1, (int)(a + 1.));
   }
   const double b = a / (double)(N - 1);
 
@@ -154,28 +153,33 @@ void meshGEdge :: operator() (GEdge *ge)
   // do not consider the first and the last vertex 
   // those are not classified on this mesh edge
 
-  if (N>2)
-    {
-      ge->mesh_vertices.resize(N-2);
-      
-      while(NUMP < N - 1) {
-	List_Read(Points, count - 1, &P1);
-	List_Read(Points, count, &P2);
-	const double d = (double)NUMP *b;
-	
-	if((fabs(P2.p) >= fabs(d)) && (fabs(P1.p) < fabs(d))) {
-	  double dt = P2.t - P1.t;
-	  double dp = P2.p - P1.p;
-	  double t = P1.t + dt / dp * (d - P1.p);      
-	  GPoint V = ge -> point(t) ;      
-	  MEdgeVertex *ev = new MEdgeVertex ( V.x(), V.y(), V.z(), ge, t );     
-	  ge->mesh_vertices [NUMP-1] = ev;
-	  NUMP++;
-	}
-	else {
-	  count++;
-	}
+  if(N > 2){
+    ge->mesh_vertices.resize(N - 2);
+    while(NUMP < N - 1) {
+      List_Read(Points, count - 1, &P1);
+      List_Read(Points, count, &P2);
+      const double d = (double)NUMP *b;
+      if((fabs(P2.p) >= fabs(d)) && (fabs(P1.p) < fabs(d))) {
+	double dt = P2.t - P1.t;
+	double dp = P2.p - P1.p;
+	double t = P1.t + dt / dp * (d - P1.p);
+	GPoint V = ge->point(t);
+	ge->mesh_vertices[NUMP - 1] = new MEdgeVertex(V.x(), V.y(), V.z(), ge, t);
+	NUMP++;
+      }
+      else {
+	count++;
       }
     }
+  }
   List_Delete(Points);
-}  
+
+  for(unsigned int i = 0; i < ge->mesh_vertices.size() + 1; i++){
+    MVertex *v0 = (i == 0) ? 
+      ge->getBeginVertex()->mesh_vertices[0] : ge->mesh_vertices[i - 1];
+    MVertex *v1 = (i == ge->mesh_vertices.size()) ? 
+      ge->getEndVertex()->mesh_vertices[0] : ge->mesh_vertices[i];
+    ge->lines.push_back(new MLine(v0, v1));
+  }
+}
+