From 9886cb4c72d791ac2d3076243ce8f71b28c1d42f Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 6 Mar 2012 16:52:55 +0000
Subject: [PATCH] more 2d graph fine-tuning

---
 Common/DefaultOptions.h  |  5 ++++-
 Common/Options.cpp       | 21 +++++++++++++++++++-
 Common/Options.h         |  1 +
 Fltk/FlGui.cpp           |  1 +
 Fltk/onelabWindow.cpp    |  5 +++--
 Fltk/optionWindow.cpp    |  4 ++++
 Graphics/drawGraph2d.cpp | 41 +++++++++++++++++++++++-----------------
 Post/PView.cpp           |  4 ++--
 Post/PViewOptions.h      |  6 +++---
 9 files changed, 62 insertions(+), 26 deletions(-)

diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index f07b71fdaf..363ea7ad1a 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -1128,7 +1128,7 @@ StringXNumber ViewOptions_Number[] = {
     "Minimum display size of arrows (in pixels)" },
   { F|O, "AutoPosition" , opt_view_auto_position , 1. ,
     "Position the scale or 2D plot automatically (0: manual, 1: automatic, 2: top left, "
-    "3: top right, 4: bottom left, 5: bottom right)" },
+    "3: top right, 4: bottom left, 5: bottom right, 6: top, 7: bottom, 8: left, 9: right)" },
   { F|O, "Axes" , opt_view_axes , 0 ,
     "Axes (0=none, 1=simple axes, 2=box, 3=full grid, 4=open grid, 5=ruler)" },
   { F|O, "AxesMikado" , opt_view_axes_mikado , 0. ,
@@ -1662,6 +1662,9 @@ StringXColor ViewOptions_Color[] = {
   { F|O, "Text2D" , opt_view_color_text2d , ELECOL, "2D text color" },
   { F|O, "Text3D" , opt_view_color_text3d , ELECOL, "3D text color" },
   { F|O, "Axes" , opt_view_color_axes , ELECOL, "Axes color" },
+  { F|O, "Background2D" , opt_view_color_background2d ,
+    {255, 255, 255, 160}, {255, 255, 255, 160}, {255, 255, 255, 160},
+    "Bacground color for 2D plots" },
   { 0, 0 , 0 , {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0} , 0 }
 } ;
 
diff --git a/Common/Options.cpp b/Common/Options.cpp
index ed9d51a500..33f4f651c8 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -6445,7 +6445,7 @@ double opt_view_auto_position(OPT_ARGS_NUM)
   GET_VIEW(0.);
   if(action & GMSH_SET) {
     opt->autoPosition = (int)val;
-    if(opt->autoPosition < 0 || opt->autoPosition > 5)
+    if(opt->autoPosition < 0 || opt->autoPosition > 9)
       opt->autoPosition = 0;
   }
 #if defined(HAVE_FLTK)
@@ -8639,3 +8639,22 @@ unsigned int opt_view_color_axes(OPT_ARGS_COL)
   return 0;
 #endif
 }
+
+unsigned int opt_view_color_background2d(OPT_ARGS_COL)
+{
+#if defined(HAVE_POST)
+  GET_VIEW(0);
+  if(action & GMSH_SET) {
+    opt->color.background2d = val;
+  }
+#if defined(HAVE_FLTK)
+  if(_gui_action_valid(action, num)){
+    CCC(opt->color.background2d, FlGui::instance()->options->view.color[13]);
+    drawContext::global()->resetFontTextures();
+  }
+#endif
+  return opt->color.background2d;
+#else
+  return 0;
+#endif
+}
diff --git a/Common/Options.h b/Common/Options.h
index da13f2a027..f782e9329a 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -673,6 +673,7 @@ unsigned int opt_view_color_normals(OPT_ARGS_COL);
 unsigned int opt_view_color_text2d(OPT_ARGS_COL);
 unsigned int opt_view_color_text3d(OPT_ARGS_COL);
 unsigned int opt_view_color_axes(OPT_ARGS_COL);
+unsigned int opt_view_color_background2d(OPT_ARGS_COL);
 
 // Data structures and global functions
 
diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp
index edc7f8fdf8..1c410b80dc 100644
--- a/Fltk/FlGui.cpp
+++ b/Fltk/FlGui.cpp
@@ -360,6 +360,7 @@ int FlGui::testGlobalShortcuts(int event)
   int status = 0;
 
   if(Fl::test_shortcut('0')) {
+    // FIXME: here we should also reset all onelab variables that depend on Gmsh
     geometry_reload_cb(0, 0);
     mod_geometry_cb(0, 0);
     status = 1;
diff --git a/Fltk/onelabWindow.cpp b/Fltk/onelabWindow.cpp
index f093761e7e..a9dc741ffd 100644
--- a/Fltk/onelabWindow.cpp
+++ b/Fltk/onelabWindow.cpp
@@ -652,6 +652,7 @@ static void runGmshClient(const std::string &action)
     // first pass is special to prevent model reload, as well as
     // remeshing if a mesh file already exists on disk
     modelName = GModel::current()->getName();
+    importPhysicalGroups(c, GModel::current());
     if(!StatFile(mshFileName))
       onelab::server::instance()->setChanged(false, "Gmsh");
   }
@@ -663,6 +664,7 @@ static void runGmshClient(const std::string &action)
       // the model name has changed
       modelName = GModel::current()->getName();
       geometry_reload_cb(0, 0);
+      importPhysicalGroups(c, GModel::current());
     }
   }
   else if(action == "compute"){
@@ -673,6 +675,7 @@ static void runGmshClient(const std::string &action)
       // changed
       modelName = GModel::current()->getName();
       geometry_reload_cb(0, 0);
+      importPhysicalGroups(c, GModel::current());
       if(FlGui::instance()->onelab->meshAuto()){
         mesh_3d_cb(0, 0);
         CreateOutputFile(mshFileName, CTX::instance()->mesh.fileFormat);
@@ -687,8 +690,6 @@ static void runGmshClient(const std::string &action)
     }
     onelab::server::instance()->setChanged(false, "Gmsh");
   }
-
-  importPhysicalGroups(c, GModel::current());
 }
 
 void onelab_cb(Fl_Widget *w, void *data)
diff --git a/Fltk/optionWindow.cpp b/Fltk/optionWindow.cpp
index fa831e915a..ecd397fe4e 100644
--- a/Fltk/optionWindow.cpp
+++ b/Fltk/optionWindow.cpp
@@ -103,6 +103,10 @@ static Fl_Menu_Item menu_position[] = {
   {"Top right",    0, 0, 0},
   {"Bottom left",  0, 0, 0},
   {"Bottom right", 0, 0, 0},
+  {"Top",          0, 0, 0},
+  {"Bottom",       0, 0, 0},
+  {"Left",         0, 0, 0},
+  {"Right",        0, 0, 0},
   {0}
 };
 
diff --git a/Graphics/drawGraph2d.cpp b/Graphics/drawGraph2d.cpp
index e04a32a632..8139942135 100644
--- a/Graphics/drawGraph2d.cpp
+++ b/Graphics/drawGraph2d.cpp
@@ -168,19 +168,22 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop,
   PViewData *data = p->getData();
   PViewOptions *opt = p->getOptions();
 
-  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-  glEnable(GL_BLEND);
-  glColor4f(0.5, 0.5, 0.5, 0.5);
-  glBegin(GL_QUADS);
-  glVertex2d(xleft, ytop);
-  glVertex2d(xleft + width, ytop);
-  glVertex2d(xleft + width, ytop - height);
-  glVertex2d(xleft, ytop - height);
-  glEnd();
-  glDisable(GL_BLEND);
-
   if(!opt->axes) return;
 
+  int alpha = CTX::instance()->unpackAlpha(opt->color.background2d);
+  if(alpha != 0){
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+    glEnable(GL_BLEND);
+    glColor4ubv((GLubyte *) & opt->color.background2d);
+    glBegin(GL_QUADS);
+    glVertex2d(xleft, ytop);
+    glVertex2d(xleft + width, ytop);
+    glVertex2d(xleft + width, ytop - height);
+    glVertex2d(xleft, ytop - height);
+    glEnd();
+    glDisable(GL_BLEND);
+  }
+
   // total font height
   double font_h = drawContext::global()->getStringHeight() ?
     drawContext::global()->getStringHeight() : 1;
@@ -509,18 +512,22 @@ void drawContext::drawGraph2d()
         drawGraph(this, p, x + 0.95 * xsep, viewport[3] - (y + 0.4 * ysep), w, h);
       }
     }
-    else if(opt->autoPosition >= 2 && opt->autoPosition <= 5){
-      // top left (2), top right (3), bottom left (4), bottom right (5)
+    else if(opt->autoPosition >= 2 && opt->autoPosition <= 9){
+      // top left (2), top right (3), bottom left (4), bottom right (5), top
+      // half (6), bottom half (7), left half (8), right half (9)
       double winw = viewport[2] - viewport[0];
       double winh = viewport[3] - viewport[1];
       double fracw = 0.85, frach = 0.85;
-      double w = fracw * winw / 2. - xsep;
-      double h = frach * winh / 2. - ysep;
+      int a = opt->autoPosition;
+      double wd = (a <= 5 || a == 8 || a == 9) ? 2. : 1.;
+      double w = fracw * winw / wd - xsep;
+      double hd = (a <= 5 || a == 6 || a == 7) ? 2. : 1.;
+      double h = frach * winh / hd - ysep;
       double x = viewport[0] + (1 - fracw) / 3. * winw;
-      if(opt->autoPosition == 3 || opt->autoPosition == 5)
+      if(a == 3 || a == 5 || a == 9)
         x += (w + xsep + (1 - fracw) / 3. * winw);
       double y = viewport[1] + (1 - frach) / 3. * winh;
-      if(opt->autoPosition == 4 || opt->autoPosition == 5)
+      if(a == 4 || a == 5 || a == 7)
         y += (h + ysep + (1 - frach) / 3. * winh);
       drawGraph(this, p, x + 0.95 * xsep, viewport[3] - (y + 0.4 * ysep), w, h);
     }
diff --git a/Post/PView.cpp b/Post/PView.cpp
index f8491948d8..f89816ca69 100644
--- a/Post/PView.cpp
+++ b/Post/PView.cpp
@@ -91,8 +91,8 @@ PView::PView(const std::string &xname, const std::string &yname,
   _options = new PViewOptions(PViewOptions::reference);
   _options->type = PViewOptions::Plot2D;
   _options->axes = 2;
-  _options->lineWidth = 2.;
-  _options->pointSize = 4.;
+  //_options->lineWidth = 2.;
+  //_options->pointSize = 4.;
   _options->axesLabel[0] = xname;
 }
 
diff --git a/Post/PViewOptions.h b/Post/PViewOptions.h
index 5990b66f84..24f09a4cfe 100644
--- a/Post/PViewOptions.h
+++ b/Post/PViewOptions.h
@@ -100,7 +100,7 @@ class PViewOptions {
     unsigned int point, line, triangle, quadrangle;
     unsigned int tetrahedron, hexahedron, prism, pyramid;
     unsigned int tangents, normals;
-    unsigned int text2d, text3d, axes;
+    unsigned int text2d, text3d, axes, background2d;
   } color;
  public:
   // static reference container that contains default values
@@ -112,11 +112,11 @@ class PViewOptions {
   double getScaleValue(int iso, int numIso, double min, double max);
   // return an integer in [0, numIso - 1] corresponding to the
   // floating point value val in [min, max]
-  int getScaleIndex(double val, int numIso, double min, double max, 
+  int getScaleIndex(double val, int numIso, double min, double max,
                     bool forceLinear=false);
   // get color for val in [min, max] (only use numColors if > 0
   // instead of all available colors)
-  unsigned int getColor(double val, double min, double max, 
+  unsigned int getColor(double val, double min, double max,
                         bool forceLinear=false, int numColors=-1);
   // get i-th color amongst nb (i in [0, nb - 1])
   unsigned int getColor(int i, int nb);
-- 
GitLab