From 2bd1d7147d74abef5571729d8b6a51f505332293 Mon Sep 17 00:00:00 2001
From: Philippe Geuzaine <philippe.geuzaine@gmail.com>
Date: Tue, 9 Aug 2005 08:50:12 +0000
Subject: [PATCH] - added option (to the mesh panel) to tune the display
 frequency of the labels

---
 Common/Context.h        |  1 +
 Common/DefaultOptions.h |  3 +++
 Common/Options.cpp      | 14 +++++++++-
 Common/Options.h        |  1 +
 Fltk/Callbacks.cpp      |  3 ++-
 Fltk/GUI.cpp            |  8 +++++-
 Graphics/Mesh.cpp       | 58 +++++++++++++++++++++++++++++++++++------
 7 files changed, 77 insertions(+), 11 deletions(-)

diff --git a/Common/Context.h b/Common/Context.h
index 9ad991d3de..e55a127546 100644
--- a/Common/Context.h
+++ b/Common/Context.h
@@ -170,6 +170,7 @@ public :
     int draw;
     int points, lines, surfaces_edges, surfaces_faces, volumes_edges, volumes_faces;
     int points_num, lines_num, surfaces_num, volumes_num;
+    double label_frequency;
     int point_type, line_type; // flat or 3D
     double point_size, line_width;
     int points_per_element;
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index de943f1374..1addfdc9ae 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -977,6 +977,9 @@ StringXNumber MeshOptions_Number[] = {
   { F|O, "VolumeNumbers" , opt_mesh_volumes_num , 0. , 
     "Display volume mesh element numbers?" },
 
+  { F|O, "LabelsFrequency" , opt_mesh_label_frequency , 100. , 
+    "Labels display frequency?" },
+
   { 0, NULL , NULL , 0. , NULL }
 } ;
 
diff --git a/Common/Options.cpp b/Common/Options.cpp
index a0af6db4b2..18fb677d9d 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.252 2005-08-04 14:04:07 colignon Exp $
+// $Id: Options.cpp,v 1.253 2005-08-09 08:50:11 pgeuzain Exp $
 //
 // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
 //
@@ -4286,6 +4286,18 @@ double opt_mesh_line_width(OPT_ARGS_NUM)
   return CTX.mesh.line_width;
 }
 
+double opt_mesh_label_frequency(OPT_ARGS_NUM)
+{
+  if(action & GMSH_SET) {
+    CTX.mesh.label_frequency = val;
+  }
+#if defined(HAVE_FLTK)
+  if(WID && (action & GMSH_GUI))
+    WID->mesh_value[12]->value(CTX.mesh.label_frequency);
+#endif
+  return CTX.mesh.label_frequency;
+}
+
 double opt_mesh_line_type(OPT_ARGS_NUM)
 {
   if(action & GMSH_SET) {
diff --git a/Common/Options.h b/Common/Options.h
index 15fbfe4443..4496f08d84 100644
--- a/Common/Options.h
+++ b/Common/Options.h
@@ -391,6 +391,7 @@ double opt_geometry_point_size(OPT_ARGS_NUM);
 double opt_geometry_point_sel_size(OPT_ARGS_NUM);
 double opt_geometry_point_type(OPT_ARGS_NUM);
 double opt_geometry_line_width(OPT_ARGS_NUM);
+double opt_mesh_label_frequency(OPT_ARGS_NUM);
 double opt_geometry_line_sel_width(OPT_ARGS_NUM);
 double opt_geometry_line_type(OPT_ARGS_NUM);
 double opt_geometry_light(OPT_ARGS_NUM);
diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index 899c4295ea..88109418c4 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.365 2005-08-06 02:32:36 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.366 2005-08-09 08:50:11 pgeuzain Exp $
 //
 // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
 //
@@ -1178,6 +1178,7 @@ void mesh_options_ok_cb(CALLBACK_ARGS)
   opt_mesh_tangents(0, GMSH_SET, WID->mesh_value[13]->value());
   opt_mesh_point_size(0, GMSH_SET, WID->mesh_value[10]->value());
   opt_mesh_line_width(0, GMSH_SET, WID->mesh_value[11]->value());
+  opt_mesh_label_frequency(0, GMSH_SET, WID->mesh_value[12]->value());
   opt_mesh_cut_planea(0, GMSH_SET, WID->mesh_value[14]->value());
   opt_mesh_cut_planeb(0, GMSH_SET, WID->mesh_value[15]->value());
   opt_mesh_cut_planec(0, GMSH_SET, WID->mesh_value[16]->value());
diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index a482bee75b..9cb280d0a9 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -1,4 +1,4 @@
-// $Id: GUI.cpp,v 1.452 2005-08-04 14:04:08 colignon Exp $
+// $Id: GUI.cpp,v 1.453 2005-08-09 08:50:11 pgeuzain Exp $
 //
 // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
 //
@@ -2426,6 +2426,12 @@ void GUI::create_option_window()
       mesh_choice[7]->menu(menu_label_type);
       mesh_choice[7]->align(FL_ALIGN_RIGHT);
 
+      mesh_value[12] = new Fl_Value_Input(L + width / 2, 2 * WB + 6 * BH, IW / 2, BH, "Labels frequency");
+      mesh_value[12]->minimum(0.0);
+      mesh_value[12]->maximum(100.0);
+      mesh_value[12]->step(0.1);
+      mesh_value[12]->align(FL_ALIGN_RIGHT);
+
       mesh_value[4] = new Fl_Value_Input(L + 2 * WB, 2 * WB + 7 * BH, IW / 2, BH);
       mesh_value[4]->minimum(0);
       mesh_value[4]->maximum(1);
diff --git a/Graphics/Mesh.cpp b/Graphics/Mesh.cpp
index f5c9fbef4a..ebfb53be1a 100644
--- a/Graphics/Mesh.cpp
+++ b/Graphics/Mesh.cpp
@@ -1,4 +1,4 @@
-// $Id: Mesh.cpp,v 1.135 2005-08-02 17:02:09 geuzaine Exp $
+// $Id: Mesh.cpp,v 1.136 2005-08-09 08:50:12 pgeuzain Exp $
 //
 // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
 //
@@ -50,6 +50,8 @@ static int thePhysical = 0;
 static Curve *theCurve = NULL;
 static Surface *theSurface = NULL;
 static Volume *theVolume = NULL;
+static int numLabelsDisplayed = 0;
+static int stepLabelsDisplayed = 1;
 
 void draw_polygon_2d(double r, double g, double b, int n,
                      double *x, double *y, double *z)
@@ -321,6 +323,15 @@ void Draw_Mesh_Volume(void *a, void *b)
   if(!(v->Visible & VIS_MESH))
     return;
 
+  if (CTX.mesh.volumes_num) {
+    int numLabels = Tree_Nbr(v->Simplexes) + Tree_Nbr(v->SimplexesBase) 
+      + Tree_Nbr(v->Hexahedra) + Tree_Nbr(v->Prisms) + Tree_Nbr(v->Pyramids);
+    numLabelsDisplayed = 0;
+    if (CTX.mesh.label_frequency == 0.0) stepLabelsDisplayed = numLabels;
+    else stepLabelsDisplayed = 100.0 / CTX.mesh.label_frequency;
+    if (stepLabelsDisplayed > numLabels) stepLabelsDisplayed = numLabels;
+  }
+
   theVolume = v;
   theColor = v->Color;
 
@@ -385,6 +396,15 @@ void Draw_Mesh_Surface(void *a, void *b)
   if(!(s->Visible & VIS_MESH))
     return;
 
+  if (CTX.mesh.surfaces_num) {
+    int numLabels = Tree_Nbr(s->Simplexes) + Tree_Nbr(s->SimplexesBase) 
+      + Tree_Nbr(s->Quadrangles);
+    numLabelsDisplayed = 0;
+    if (CTX.mesh.label_frequency == 0.0) stepLabelsDisplayed = numLabels;
+    else stepLabelsDisplayed = 100.0 / CTX.mesh.label_frequency;
+    if (stepLabelsDisplayed > numLabels) stepLabelsDisplayed = numLabels;
+  }
+
   theSurface = s;
   theColor = s->Color;
 
@@ -468,6 +488,14 @@ void Draw_Mesh_Curve(void *a, void *b)
   if(!(c->Visible & VIS_MESH))
     return;
 
+  if (CTX.mesh.lines_num) {
+    int numLabels = Tree_Nbr(c->Simplexes) + Tree_Nbr(c->SimplexesBase);
+    numLabelsDisplayed = 0;
+    if (CTX.mesh.label_frequency == 0.0) stepLabelsDisplayed = numLabels;
+    else stepLabelsDisplayed = 100.0 / CTX.mesh.label_frequency;
+    if (stepLabelsDisplayed > numLabels) stepLabelsDisplayed = numLabels;
+  }
+
   theCurve = c;
   theColor = c->Color;
 
@@ -630,7 +658,9 @@ void Draw_Mesh_Line(void *a, void *b)
     }
   }
 
-  if(CTX.mesh.lines_num) {
+  ++numLabelsDisplayed;
+
+  if(CTX.mesh.lines_num && (numLabelsDisplayed % stepLabelsDisplayed == 0)) {
     glColor4ubv((GLubyte *) & col);
     if(CTX.mesh.label_type == 3)
       sprintf(Num, "%d", iPart);
@@ -982,7 +1012,9 @@ void Draw_Mesh_Triangle(void *a, void *b)
     gl2psDisable(GL2PS_LINE_STIPPLE);
   }
 
-  if(CTX.mesh.surfaces_num) {
+  ++numLabelsDisplayed;
+
+  if(CTX.mesh.surfaces_num && (numLabelsDisplayed % stepLabelsDisplayed == 0)) {
     if(CTX.mesh.surfaces_faces)
       glColor4ubv((GLubyte *) & CTX.color.mesh.line);
     else
@@ -1161,7 +1193,9 @@ void Draw_Mesh_Quadrangle(void *a, void *b)
     gl2psDisable(GL2PS_LINE_STIPPLE);
   }
 
-  if(CTX.mesh.surfaces_num) {
+  ++numLabelsDisplayed;
+
+  if(CTX.mesh.surfaces_num && (numLabelsDisplayed % stepLabelsDisplayed == 0)) {
     if(CTX.mesh.surfaces_faces)
       glColor4ubv((GLubyte *) & CTX.color.mesh.line);
     else
@@ -1359,7 +1393,9 @@ void Draw_Mesh_Tetrahedron(void *a, void *b)
     gl2psDisable(GL2PS_LINE_STIPPLE);
   }
 
-  if(CTX.mesh.volumes_num) {
+  ++numLabelsDisplayed;
+
+  if(CTX.mesh.volumes_num && (numLabelsDisplayed % stepLabelsDisplayed == 0)) {
     if(CTX.mesh.surfaces_faces || faces)
       glColor4ubv((GLubyte *) & CTX.color.mesh.line);
     else
@@ -1557,7 +1593,9 @@ void Draw_Mesh_Hexahedron(void *a, void *b)
     gl2psDisable(GL2PS_LINE_STIPPLE);
   }
 
-  if(CTX.mesh.volumes_num) {
+  ++numLabelsDisplayed;
+
+  if(CTX.mesh.volumes_num && (numLabelsDisplayed % stepLabelsDisplayed == 0)) {
     if(CTX.mesh.surfaces_faces || faces)
       glColor4ubv((GLubyte *) & CTX.color.mesh.line);
     else
@@ -1770,7 +1808,9 @@ void Draw_Mesh_Prism(void *a, void *b)
     gl2psDisable(GL2PS_LINE_STIPPLE);
   }
 
-  if(CTX.mesh.volumes_num) {
+  ++numLabelsDisplayed;
+
+  if(CTX.mesh.volumes_num && (numLabelsDisplayed % stepLabelsDisplayed == 0)) {
     if(CTX.mesh.surfaces_faces || faces)
       glColor4ubv((GLubyte *) & CTX.color.mesh.line);
     else
@@ -1955,7 +1995,9 @@ void Draw_Mesh_Pyramid(void *a, void *b)
     }
   }
 
-  if(CTX.mesh.volumes_num) {
+  ++numLabelsDisplayed;
+
+  if(CTX.mesh.volumes_num && (numLabelsDisplayed % stepLabelsDisplayed == 0)) {
     if(CTX.mesh.surfaces_faces || faces)
       glColor4ubv((GLubyte *) & CTX.color.mesh.line);
     else
-- 
GitLab