From 160f70d3aa720cfda7810ecca7060b3a6ab9c84a Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sun, 13 Aug 2006 14:43:56 +0000
Subject: [PATCH] *** empty log message ***

---
 Common/Visibility.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++-
 Common/Visibility.h   |  3 +++
 Fltk/Callbacks.cpp    |  9 ++++++-
 Fltk/Callbacks.h      |  1 +
 Fltk/GUI.cpp          | 17 +++++++------
 Geo/gmshModel.cpp     | 12 +++++----
 6 files changed, 86 insertions(+), 14 deletions(-)

diff --git a/Common/Visibility.cpp b/Common/Visibility.cpp
index b05520528a..c0ea178eb8 100644
--- a/Common/Visibility.cpp
+++ b/Common/Visibility.cpp
@@ -1,4 +1,4 @@
-// $Id: Visibility.cpp,v 1.15 2006-08-12 16:30:12 geuzaine Exp $
+// $Id: Visibility.cpp,v 1.16 2006-08-13 14:43:54 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -120,6 +120,62 @@ std::string VisibilityManager::getBrowserLine(int n)
   return std::string(str);
 }
 
+std::string VisibilityManager::getStringForGEO()
+{
+  std::vector<int> state[4][2];
+
+  for(GModel::viter it = GMODEL->firstVertex(); it != GMODEL->lastVertex(); it++)
+    (*it)->getVisibility() ?
+      state[0][1].push_back((*it)->tag()) : state[0][0].push_back((*it)->tag());
+  for(GModel::eiter it = GMODEL->firstEdge(); it != GMODEL->lastEdge(); it++)
+    (*it)->getVisibility() ? 
+      state[1][1].push_back((*it)->tag()) : state[1][0].push_back((*it)->tag());
+  for(GModel::fiter it = GMODEL->firstFace(); it != GMODEL->lastFace(); it++)
+    (*it)->getVisibility() ? 
+      state[2][1].push_back((*it)->tag()) : state[2][0].push_back((*it)->tag());
+  for(GModel::riter it = GMODEL->firstRegion(); it != GMODEL->lastRegion(); it++)
+    (*it)->getVisibility() ? 
+      state[3][1].push_back((*it)->tag()) : state[3][0].push_back((*it)->tag());
+  
+  char tmp[256], *labels[4] = {"Point", "Line", "Surface", "Volume"};
+  std::string str;
+  int mode;
+
+  int on = 0, off = 0;
+  for(int i = 0; i < 4; i++){
+    on += state[i][1].size();
+    off += state[i][0].size();
+  }
+
+  if(on > off){
+    str = "Show \"*\";\n";
+    if(!off) return str;
+    str += "Hide {\n";
+    mode = 0;
+  }
+  else{
+    str = "Hide \"*\";\n";
+    if(!on) return str;
+    str += "Show {\n";
+    mode = 1;
+  }
+
+  for(int i = 0; i < 4; i++){
+    if(state[i][mode].size()){
+      str += labels[i];
+      str += "{";
+      for(unsigned int j = 0; j < state[i][mode].size(); j++){
+	if(j) str += ",";
+	sprintf(tmp, "%d", state[i][mode][j]);
+	str += tmp;
+      }
+      str += "};\n";
+    }
+  }
+  str += "}\n";
+  return str;
+}
+
 void VisElementary::setVisibility(char val, bool recursive)
 {
   _e->setVisibility(val, recursive);
diff --git a/Common/Visibility.h b/Common/Visibility.h
index c72a264744..e75dd2b7b1 100644
--- a/Common/Visibility.h
+++ b/Common/Visibility.h
@@ -140,6 +140,9 @@ class VisibilityManager {
   // get the browser line for the nth entity in the manager
   std::string getBrowserLine(int n);
 
+  // get the whole visibility information in geo format
+  std::string getStringForGEO();
+
   // set the sort mode
   void setSortMode(int mode){ _sortMode = (_sortMode != mode) ? mode : -mode; }
 
diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp
index 42f690b298..5a76bf2786 100644
--- a/Fltk/Callbacks.cpp
+++ b/Fltk/Callbacks.cpp
@@ -1,4 +1,4 @@
-// $Id: Callbacks.cpp,v 1.428 2006-08-12 16:16:27 geuzaine Exp $
+// $Id: Callbacks.cpp,v 1.429 2006-08-13 14:43:54 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -1350,6 +1350,13 @@ void visibility_ok_cb(CALLBACK_ARGS)
   Draw();
 }
 
+void visibility_save_cb(CALLBACK_ARGS)
+{
+  visibility_ok_cb(NULL, NULL);
+  std::string str = VisibilityManager::instance()->getStringForGEO();
+  add_infile((char*)str.c_str(), CTX.filename);
+}
+
 void visibility_sort_cb(CALLBACK_ARGS)
 {
   char *str = (char*)data;
diff --git a/Fltk/Callbacks.h b/Fltk/Callbacks.h
index 2862b4f2a7..4770ca5fb5 100644
--- a/Fltk/Callbacks.h
+++ b/Fltk/Callbacks.h
@@ -158,6 +158,7 @@ void visibility_cb(CALLBACK_ARGS);
 void visibility_sort_cb(CALLBACK_ARGS);
 void visibility_number_cb(CALLBACK_ARGS);
 void visibility_ok_cb(CALLBACK_ARGS);
+void visibility_save_cb(CALLBACK_ARGS);
 
 // Clipping planes Menu
 
diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp
index 1666487dd5..77eb853ea5 100644
--- a/Fltk/GUI.cpp
+++ b/Fltk/GUI.cpp
@@ -1,4 +1,4 @@
-// $Id: GUI.cpp,v 1.509 2006-08-12 19:34:15 geuzaine Exp $
+// $Id: GUI.cpp,v 1.510 2006-08-13 14:43:55 geuzaine Exp $
 //
 // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
 //
@@ -3728,12 +3728,12 @@ void GUI::create_message_window(bool redraw_only)
   msg_browser->callback(message_copy_cb);
 
   {
-    Fl_Return_Button *o = new Fl_Return_Button(width - 3 * BB - 3 * WB, height - BH - WB, BB, BH, "Save");
-    o->callback(message_save_cb);
+    Fl_Return_Button *o = new Fl_Return_Button(width - 3 * BB - 3 * WB, height - BH - WB, BB, BH, "Clear");
+    o->callback(message_clear_cb);
   }
   {
-    Fl_Button *o = new Fl_Button(width - 2 * BB - 2 * WB, height - BH - WB, BB, BH, "Clear");
-    o->callback(message_clear_cb);
+    Fl_Button *o = new Fl_Button(width - 2 * BB - 2 * WB, height - BH - WB, BB, BH, "Save");
+    o->callback(message_save_cb);
   }
   {
     Fl_Button *o = new Fl_Button(width - BB - WB, height - BH - WB, BB, BH, "Cancel");
@@ -3892,8 +3892,11 @@ void GUI::create_visibility_window()
       Fl_Group::current()->resizable(o);
     }
 
-    Fl_Return_Button *b = new Fl_Return_Button(width - BB - 2 * WB, height - 2 * BH - 3 * WB, BB, BH, "Apply");
-    b->callback(visibility_ok_cb);
+    Fl_Return_Button *b1 = new Fl_Return_Button(width - 2 * BB - 3 * WB, height - 2 * BH - 3 * WB, BB, BH, "Apply");
+    b1->callback(visibility_ok_cb);
+
+    Fl_Button *b2 = new Fl_Button(width - BB - 2 * WB, height - 2 * BH - 3 * WB, BB, BH, "Save");
+    b2->callback(visibility_save_cb);
 
     o->end();
     Fl_Group::current()->resizable(o);
diff --git a/Geo/gmshModel.cpp b/Geo/gmshModel.cpp
index a8879d805f..0d5f97cb64 100644
--- a/Geo/gmshModel.cpp
+++ b/Geo/gmshModel.cpp
@@ -12,6 +12,9 @@ extern Mesh *THEM;
 
 void gmshModel::import()
 {
+  // When en entity that already exists is reimported, we don't do
+  // anything (except making it invisible if we are asked to)
+
   if(Tree_Nbr(THEM->Points)) {
     List_T *points = Tree2List(THEM->Points);
     for(int i = 0; i < List_Nbr(points); i++){
@@ -22,7 +25,7 @@ void gmshModel::import()
 	v = new gmshVertex(this, p);
 	add(v);
       }
-      v->setVisibility(p->Visible);
+      if(!p->Visible) v->setVisibility(0);
     }
     List_Delete(points);
   }
@@ -39,7 +42,7 @@ void gmshModel::import()
 			   vertexByTag(c->end->Num));
 	  add(e);
 	}
-	e->setVisibility(c->Visible);
+	if(!c->Visible) e->setVisibility(0);
       }
     }
     List_Delete(curves);
@@ -54,7 +57,7 @@ void gmshModel::import()
 	f = new gmshFace(this, s);
 	add(f);
       }
-      f->setVisibility(s->Visible);
+      if(!s->Visible) f->setVisibility(0);
     }
     List_Delete(surfaces);
   } 
@@ -68,7 +71,7 @@ void gmshModel::import()
 	r = new gmshRegion(this, v);
 	add(r);
       }
-      r->setVisibility(v->Visible);
+      if(!v->Visible) r->setVisibility(0);
     }
     List_Delete(volumes);
   }
@@ -97,4 +100,3 @@ void gmshModel::import()
   Msg(DEBUG, "%d Faces", faces.size());
   Msg(DEBUG, "%d Regions", regions.size());
 }
-
-- 
GitLab