From 0709522790a1123066291ba4344fde0616a72c46 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Tue, 24 May 2011 11:12:11 +0000
Subject: [PATCH] Shift+1:1 button now resets the bounding box around the
 visible entities

---
 Common/OpenFile.cpp    |  8 +++++---
 Common/OpenFile.h      |  2 +-
 Fltk/graphicWindow.cpp |  8 +++++++-
 Fltk/optionWindow.cpp  |  2 +-
 Geo/GModel.cpp         | 14 ++++++++------
 Geo/GModel.h           |  2 +-
 Mesh/HighOrder.cpp     |  9 +++------
 7 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp
index 1a3c451364..6e10a12314 100644
--- a/Common/OpenFile.cpp
+++ b/Common/OpenFile.cpp
@@ -30,6 +30,7 @@
 #if defined(HAVE_POST)
 #include "PView.h"
 #include "PViewData.h"
+#include "PViewOptions.h"
 #endif
 
 #if defined(HAVE_FLTK)
@@ -91,17 +92,18 @@ void SetBoundingBox(double xmin, double xmax,
     CTX::instance()->cg[i] = 0.5 * (CTX::instance()->min[i] + CTX::instance()->max[i]);
 }
 
-void SetBoundingBox()
+void SetBoundingBox(bool aroundVisible)
 {
   if(CTX::instance()->forcedBBox) return;
 
-  SBoundingBox3d bb = GModel::current()->bounds();
+  SBoundingBox3d bb = GModel::current()->bounds(aroundVisible);
   
 #if defined(HAVE_POST)
   if(bb.empty()) {
     for(unsigned int i = 0; i < PView::list.size(); i++)
       if(!PView::list[i]->getData()->getBoundingBox().empty())
-        bb += PView::list[i]->getData()->getBoundingBox();
+        if(!aroundVisible || PView::list[i]->getOptions()->visible)
+          bb += PView::list[i]->getData()->getBoundingBox();
   }
 #endif
   
diff --git a/Common/OpenFile.h b/Common/OpenFile.h
index 40fae6b73c..ec0f236137 100644
--- a/Common/OpenFile.h
+++ b/Common/OpenFile.h
@@ -18,7 +18,7 @@ void ClearProject();
 void SetBoundingBox(double xmin, double xmax,
                     double ymin, double ymax, 
                     double zmin, double zmax);
-void SetBoundingBox();
+void SetBoundingBox(bool aroundVisible=false);
 void AddToTemporaryBoundingBox(double x, double y, double z);
 
 #endif
diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp
index 73a17a7d8f..ddb1bc108e 100644
--- a/Fltk/graphicWindow.cpp
+++ b/Fltk/graphicWindow.cpp
@@ -17,6 +17,7 @@
 #include "PView.h"
 #include "PViewData.h"
 #include "OS.h"
+#include "OpenFile.h"
 #include "Options.h"
 #include "Context.h"
 
@@ -180,6 +181,10 @@ void status_xyz1p_cb(Fl_Widget *w, void *data)
       }
     }
     else if(!strcmp(str, "1:1")){
+      // if Shift is pressed, reset bounding box around visible
+      // entities
+      if(Fl::event_state(FL_SHIFT))
+        SetBoundingBox(true);
       // reset translation and scaling, or sync translation and
       // scaling with the first window (alt)
       if (CTX::instance()->camera) {
@@ -493,7 +498,8 @@ graphicWindow::graphicWindow(bool main, int numTiles)
   x += sw;  
   butt[3] = new Fl_Button(x, glheight + 2, 2 * FL_NORMAL_SIZE, sht, "1:1");
   butt[3]->callback(status_xyz1p_cb, (void *)"1:1");
-  butt[3]->tooltip("Set unit scale, or sync scale (Alt)");
+  butt[3]->tooltip("Set unit scale, sync scale between viewports (Alt), "
+                   "or reset bounding box around visible entities (Shift)");
   x += 2 * FL_NORMAL_SIZE;  
   butt[8] = new Fl_Button(x, glheight + 2, sw, sht, "@-1gmsh_ortho");
   butt[8]->callback(status_options_cb, (void *)"p");
diff --git a/Fltk/optionWindow.cpp b/Fltk/optionWindow.cpp
index 2573a9dbd8..b17eb4b5a8 100644
--- a/Fltk/optionWindow.cpp
+++ b/Fltk/optionWindow.cpp
@@ -2886,7 +2886,7 @@ optionWindow::optionWindow(int deltaFontSize)
 
       view.butt[10] = new Fl_Check_Button
         (L + 2 * WB, 2 * WB + 4 * BH, BW / 2, BH, "Draw element outlines");
-      view.butt[10]->tooltip("(Alt+e)");
+      view.butt[10]->tooltip("(Alt+Shift+e)");
       view.butt[10]->type(FL_TOGGLE_BUTTON);
       view.butt[10]->callback(view_options_ok_cb);
 
diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp
index 7f645e1903..29c1b80723 100644
--- a/Geo/GModel.cpp
+++ b/Geo/GModel.cpp
@@ -474,18 +474,20 @@ void GModel::setSelection(int val)
   }
 }
 
-SBoundingBox3d GModel::bounds()
+SBoundingBox3d GModel::bounds(bool aroundVisible)
 {
   std::vector<GEntity*> entities;
   getEntities(entities);
   // using the mesh vertices for now; should use entities[i]->bounds() instead
   SBoundingBox3d bb;
   for(unsigned int i = 0; i < entities.size(); i++)
-    if(entities[i]->dim() == 0)
-      bb += static_cast<GVertex*>(entities[i])->xyz();
-    else
-      for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++)
-        bb += entities[i]->mesh_vertices[j]->point();
+    if(!aroundVisible || entities[i]->getVisibility()){
+      if(entities[i]->dim() == 0)
+        bb += static_cast<GVertex*>(entities[i])->xyz();
+      else
+        for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++)
+          bb += entities[i]->mesh_vertices[j]->point();
+    }
   return bb;
 }
 
diff --git a/Geo/GModel.h b/Geo/GModel.h
index afc0560003..f716e7ad80 100644
--- a/Geo/GModel.h
+++ b/Geo/GModel.h
@@ -281,7 +281,7 @@ class GModel
   void setSelection(int val);
 
   // the bounding box
-  SBoundingBox3d bounds();
+  SBoundingBox3d bounds(bool aroundVisible=false);
 
   // return the mesh status for the entire model
   int getMeshStatus(bool countDiscrete=true);
diff --git a/Mesh/HighOrder.cpp b/Mesh/HighOrder.cpp
index 0e9ec135b7..97431605d8 100644
--- a/Mesh/HighOrder.cpp
+++ b/Mesh/HighOrder.cpp
@@ -215,12 +215,9 @@ static void getEdgeVertices(GEdge *ge, MElement *ele, std::vector<MVertex*> &ve,
       else
         ve.insert(ve.end(), edgeVertices[p].rbegin(), edgeVertices[p].rend());
     }
-    
     else{  
-      
       MVertex *v0 = edge.getVertex(0), *v1 = edge.getVertex(1);
       std::vector<MVertex*> temp;
-        
       double u0 = 0., u1 = 0., US[100];
       bool reparamOK = true;
       if(!linear) {
@@ -248,7 +245,6 @@ static void getEdgeVertices(GEdge *ge, MElement *ele, std::vector<MVertex*> &ve,
       }
       for(int j = 0; j < nPts; j++){
         const double t = (double)(j + 1)/(nPts + 1);
-        
         double uc = (1. - t) * u0 + t * u1; // can be wrong, that's ok
         MVertex *v;
         if(linear || !reparamOK || uc < std::min(u0,u1) || uc > std::max(u0,u1)){ 
@@ -463,8 +459,9 @@ static void reorientTrianglePoints(std::vector<MVertex*> &vtcs, int orientation,
       tmp[pos+2] = vtcs[pos+1];
       for (int i = 0; i < 3*(o-1); i++)
         tmp[pos+3+i] = vtcs[pos+3*o-i-1];
-    } else {
-      for (int i=0; i< 3*o; i++)
+    }
+    else {
+      for (int i = 0; i < 3*o; i++)
         tmp[pos+i] = vtcs[pos+i];
     }
     for (int i = 0; i < 3; i++) {
-- 
GitLab