From d69631fbb7606ec331d6a57026ea7599692142e2 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Fri, 18 Aug 2006 21:11:43 +0000
Subject: [PATCH] changed default hover+selection mode as follows:

- by default, mouse hover+selection is ON for the geometry, but only
  mouse selection is ON for the mesh

- with Shift+Escape, one can activate "full" selection mode, i.e., also
  allow mouse hover for the mesh

I've disabled the hover over mesh stuff due to slow performance on both
of the Windows machines I have access to over here.

With these new settings I get interactive performance (about 4 frames
per second) when visualization a 6 million tetrahedra mesh, with all the
edges inside visible, lights turned on, etc. This takes about 600Mb of
RAM.
---
 Common/DefaultOptions.h |  4 ++--
 Common/Options.cpp      | 10 +++++-----
 Fltk/Callbacks.cpp      | 12 +++++++-----
 Fltk/GUI.cpp            |  4 ++--
 Fltk/Opengl.cpp         |  4 ++--
 Fltk/Opengl_Window.cpp  |  7 ++++---
 Graphics/Draw.cpp       | 23 ++++++++++++-----------
 Graphics/Draw.h         |  2 +-
 Graphics/Post.cpp       |  5 +----
 9 files changed, 36 insertions(+), 35 deletions(-)

diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index 381230b240..c2c15e5050 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -657,8 +657,8 @@ StringXNumber GeneralOptions_Number[] = {
     "Height (in pixels) of the message window" }, 
   { F|S, "MessageWidth" , opt_general_message_size0 , 450. , 
     "Width (in pixels) of the message window" }, 
-  { F|O, "MouseSelection" , opt_general_mouse_selection , 2. ,
-    "Mouse selection mode (0=none, 1=no hover, 2=full)" },
+  { F|O, "MouseSelection" , opt_general_mouse_selection , 1. ,
+    "Mouse hover and selection mode (0=none, 1=hover and select geometry but only select mesh, 2=hover and select geometry and mesh)" },
 
   { F|O, "NoPopup" , opt_general_nopopup , 0. , 
     "Disable interactive dialog windows in scripts (and use default values instead)" },
diff --git a/Common/Options.cpp b/Common/Options.cpp
index d2b651efd1..047b9a06f7 100644
--- a/Common/Options.cpp
+++ b/Common/Options.cpp
@@ -1,4 +1,4 @@
-// $Id: Options.cpp,v 1.298 2006-08-17 21:28:34 geuzaine Exp $
+// $Id: Options.cpp,v 1.299 2006-08-18 21:11:42 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -2778,13 +2778,13 @@ double opt_general_mouse_selection(OPT_ARGS_NUM)
       WID->g_status_butt[9]->color(FL_RED);
     }
     else if(CTX.enable_mouse_selection == 1){
-      if(!CTX.batch) Msg(STATUS2N, "Mouse hover OFF");
-      WID->g_status_butt[9]->color(FL_GREEN);
-    }
-    else{
       if(!CTX.batch) Msg(STATUS2N, "Mouse selection ON");
       WID->g_status_butt[9]->color(FL_BACKGROUND_COLOR);
     }
+    else{
+      if(!CTX.batch) Msg(STATUS2N, "Full mouse selection ON");
+      WID->g_status_butt[9]->color(FL_GREEN);
+    }
     WID->g_status_butt[9]->redraw();
   }
 #endif
diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index b7c90bae31..f0474239f8 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.440 2006-08-18 15:41:58 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.441 2006-08-18 21:11:42 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -467,8 +467,8 @@ void status_xyz1p_cb(CALLBACK_ARGS)
   }
   else if(!strcmp(str, "S")){ // mouse selection
     if(Fl::event_state(FL_SHIFT)){
-      // mouse selection only (no hover)
-      opt_general_mouse_selection(0, GMSH_SET | GMSH_GUI, 1);
+      // full mouse hover and select for geometry and mesh
+      opt_general_mouse_selection(0, GMSH_SET | GMSH_GUI, 2);
     }
     else if(CTX.enable_mouse_selection){
       // mouse does nothing
@@ -476,8 +476,9 @@ void status_xyz1p_cb(CALLBACK_ARGS)
       WID->g_opengl_window->cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE);      
     }
     else{
-      // mouse hover and select (default)
-      opt_general_mouse_selection(0, GMSH_SET | GMSH_GUI, 2);
+      // mouse hover and select for geometry, but mouse select only
+      // for mesh (default)
+      opt_general_mouse_selection(0, GMSH_SET | GMSH_GUI, 1);
     }
   }
   WID->update_manip_window();
@@ -1577,6 +1578,7 @@ void help_short_cb(CALLBACK_ARGS)
   Msg(DIRECT, "  Shift+p       Show post-processing options");
   Msg(DIRECT, "  Shift+s       Show solver options"); 
   Msg(DIRECT, "  Shift+w       Show post-processing view options");
+  Msg(DIRECT, "  Shift+Escape  Enable full mouse selection");
   Msg(DIRECT, " ");
   Msg(DIRECT, "  " CC("i") "        Show statistics window"); 
   Msg(DIRECT, "  " CC("l") "        Show message console");
diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index fec93c0782..3b068dc7b6 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -1,4 +1,4 @@
-// $Id: GUI.cpp,v 1.531 2006-08-18 17:49:35 geuzaine Exp $
+// $Id: GUI.cpp,v 1.532 2006-08-18 21:11:42 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -1405,7 +1405,7 @@ void GUI::create_graphic_window()
   g_status_butt[9] = new Fl_Button(x, glheight + 2, sw, sht, "S");
   x += sw;
   g_status_butt[9]->callback(status_xyz1p_cb, (void *)"S");
-  g_status_butt[9]->tooltip("Toggle mouse selection ON/OFF (Escape)");
+  g_status_butt[9]->tooltip("Toggle mouse selection ON/OFF (Escape or Shift+Escape)");
 
   g_status_butt[5] = new Fl_Button(x, glheight + 2, sw, sht, "?");
   x += sw;
diff --git a/Fltk/Opengl.cpp b/Fltk/Opengl.cpp
index 89fe4f0317..e5ff294630 100644
--- a/Fltk/Opengl.cpp
+++ b/Fltk/Opengl.cpp
@@ -1,4 +1,4 @@
-// $Id: Opengl.cpp,v 1.63 2006-08-18 15:41:58 geuzaine Exp $
+// $Id: Opengl.cpp,v 1.64 2006-08-18 21:11:43 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -236,7 +236,7 @@ char SelectEntity(int type, int *n,
 	return 'c';
       }
       else{
-	*n = Process_SelectionBuffer(WID->selection, multi,
+	*n = Process_SelectionBuffer(WID->selection, multi, true,
 				     WID->try_selection_xywh[0],
 				     WID->try_selection_xywh[1], 
 				     WID->try_selection_xywh[2],
diff --git a/Fltk/Opengl_Window.cpp b/Fltk/Opengl_Window.cpp
index a3de3182fa..b607fc5696 100644
--- a/Fltk/Opengl_Window.cpp
+++ b/Fltk/Opengl_Window.cpp
@@ -1,4 +1,4 @@
-// $Id: Opengl_Window.cpp,v 1.65 2006-08-18 15:41:58 geuzaine Exp $
+// $Id: Opengl_Window.cpp,v 1.66 2006-08-18 21:11:43 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -360,11 +360,12 @@ int Opengl_Window::handle(int event)
       sprintf(str, "%g", point[2]); WID->context_geometry_input[4]->value(str);
       redraw();
     }
-    else if(CTX.enable_mouse_selection >= 2){ // hover mode
+    else{ // hover mode
       if(curr.win[0] != prev.win[0] || curr.win[1] != prev.win[1]){
 	WID->make_opengl_current();
 	v[0] = NULL; c[0] = NULL; s[0] = NULL; r[0] = NULL;
-	Process_SelectionBuffer(WID->selection, 0, 
+	Process_SelectionBuffer(WID->selection, false, 
+				CTX.enable_mouse_selection > 1,
 				(int)curr.win[0], (int)curr.win[1], 5, 5, 
 				v, c, s, r);
 	if((WID->selection == ENT_POINT && v[0]) ||
diff --git a/Graphics/Draw.cpp b/Graphics/Draw.cpp
index e49ddf0397..ad8c81ab45 100644
--- a/Graphics/Draw.cpp
+++ b/Graphics/Draw.cpp
@@ -1,4 +1,4 @@
-// $Id: Draw.cpp,v 1.103 2006-08-13 20:46:54 geuzaine Exp $
+// $Id: Draw.cpp,v 1.104 2006-08-18 21:11:43 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -357,7 +357,7 @@ int fcmp_hit_depth(const void *a, const void *b)
   return ((hit*)a)->depth - ((hit*)b)->depth;
 }
 
-int Process_SelectionBuffer(int type, bool multi,
+int Process_SelectionBuffer(int entityType, bool multi, bool selectMesh,
 			    int x, int y, int w, int h,
 			    GVertex *v[SELECTION_MAX_HITS],
 			    GEdge *c[SELECTION_MAX_HITS],
@@ -377,7 +377,7 @@ int Process_SelectionBuffer(int type, bool multi,
   InitProjection(x, y, w, h);
   InitPosition();
   Draw_Geom();
-  Draw_Mesh();
+  if(selectMesh) Draw_Mesh();
   glPopMatrix();
 
   GLint numhits = glRenderMode(GL_RENDER);
@@ -413,9 +413,10 @@ int Process_SelectionBuffer(int type, bool multi,
     return 0;
   }
 
-  // filter result: if type == ENT_NONE, return the closest entity of
-  // "lowest dimension" (point < line < surface < volume). Otherwise,
-  // return the closest entity of type "type"
+  // filter result: if entityType == ENT_NONE, return the closest
+  // entity of "lowest dimension" (point < line < surface <
+  // volume). Otherwise, return the closest entity of type
+  // "entityType"
 
   unsigned int typmin = 4;
   for(int i = 0; i < numentities; i++) {
@@ -428,11 +429,11 @@ int Process_SelectionBuffer(int type, bool multi,
   
   int j = 0;
   for(int i = 0; i < numentities; i++) {
-    if((type == ENT_NONE && hits[i].type == typmin) ||
-       (type == ENT_POINT && hits[i].type == 0) ||
-       (type == ENT_LINE && hits[i].type == 1) ||
-       (type == ENT_SURFACE && hits[i].type == 2) ||
-       (type == ENT_VOLUME && hits[i].type == 3)){
+    if((entityType == ENT_NONE && hits[i].type == typmin) ||
+       (entityType == ENT_POINT && hits[i].type == 0) ||
+       (entityType == ENT_LINE && hits[i].type == 1) ||
+       (entityType == ENT_SURFACE && hits[i].type == 2) ||
+       (entityType == ENT_VOLUME && hits[i].type == 3)){
       switch (hits[i].type) {
       case 0:
 	if(!(v[j] = GMODEL->vertexByTag(hits[i].ient))){
diff --git a/Graphics/Draw.h b/Graphics/Draw.h
index aed4460a50..efd7f4d8d2 100644
--- a/Graphics/Draw.h
+++ b/Graphics/Draw.h
@@ -43,7 +43,7 @@ void InitProjection(int xpick=0, int ypick=0, int wpick=0, int hpick=0);
 void InitPosition(void);
 void InitRenderModel(void);
 
-int Process_SelectionBuffer(int type, bool multi, 
+int Process_SelectionBuffer(int entityType, bool multi, bool selectMesh,
 			    int x, int y, int w, int h, 
 			    GVertex *v[SELECTION_MAX_HITS], 
 			    GEdge *c[SELECTION_MAX_HITS], 
diff --git a/Graphics/Post.cpp b/Graphics/Post.cpp
index a09552a002..13c9be08ff 100644
--- a/Graphics/Post.cpp
+++ b/Graphics/Post.cpp
@@ -1,4 +1,4 @@
-// $Id: Post.cpp,v 1.110 2006-08-16 05:25:22 geuzaine Exp $
+// $Id: Post.cpp,v 1.111 2006-08-18 21:11:43 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -472,9 +472,6 @@ void Draw_Post(void)
   if(CTX.post.plugin_draw_function)
     (*CTX.post.plugin_draw_function)();
 
-  if(CTX.render_mode == GMSH_SELECT)
-    return;
-
   if(!CTX.post.list)
     return;
 
-- 
GitLab