From 29a3d5001a8967752eee8f9452fb34f993019343 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sun, 4 Jan 2009 10:21:55 +0000
Subject: [PATCH] finish multi-model stuff: File->Open now simply adds a new
 model to the stack

(To avoid having many empty models in the stack, we reuse the current
model if it's empty. Maybe we shouldn't try to be this clever: not
sure...)
---
 Common/OpenFile.cpp       | 41 ++++++++++++++++++++++-----------------
 Fltk/Main.cpp             |  6 +++---
 Fltk/menuWindow.cpp       |  5 +++--
 Fltk/solverWindow.cpp     |  2 +-
 doc/TODO.txt              | 31 +----------------------------
 utils/misc/variables.msvc |  2 +-
 6 files changed, 32 insertions(+), 55 deletions(-)

diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp
index 4d8cdf2a6a..bd6de222e5 100644
--- a/Common/OpenFile.cpp
+++ b/Common/OpenFile.cpp
@@ -398,11 +398,9 @@ void ClearProject()
 #if !defined(HAVE_NO_PARSER)
   gmsh_yysymbols.clear();
 #endif
-  for(int i = GModel::list.size() - 1; i >= 1; i--)
+  for(int i = GModel::list.size() - 1; i >= 0; i--)
     delete GModel::list[i];
-  GModel::current(0);
-  GModel::current()->destroy();
-  GModel::current()->getGEOInternals()->destroy();
+  new GModel();
 #if defined(HAVE_FLTK)
   if(GUI::available()){
     GUI::instance()->resetVisibility();
@@ -421,26 +419,33 @@ void OpenProject(const char *name)
   }
   CTX.threads_lock = 1;
 
-  // FIXME: this will change once we clarify Open/Merge/Clear
-#if !defined(HAVE_NO_POST)
-  for(int i = PView::list.size() - 1; i >= 0; i--)
-    if(PView::list[i]->getData()->hasModel(GModel::current()))
-      delete PView::list[i];
-#endif
+  if(!GModel::current()){
+    // if there's no model, add a new one and make it the current
+    new GModel();
+    GModel::current(GModel::list.size() - 1);
+  }
+  else if(GModel::current()->empty()){
+    // if the current model is empty, make sure it's reaaally
+    // cleaned-up, and reuse it
+    GModel::current()->destroy();
+    GModel::current()->getGEOInternals()->destroy();
+  }
+  else{
+    // if the current model is not empty make it invisible, clear the
+    // parser variables (if it's empty it probably means we just
+    // launched gmsh, and we don't want to delete variables set
+    // e.g. using the -string command line option) and add a new model
+    GModel::current()->setVisibility(0);
 #if !defined(HAVE_NO_PARSER)
-  // reinitialize the variables defined in the parser (only if the
-  // current model is not empty: if it's empty it probably means we
-  // just launched gmsh, and we don't want to delete variables set
-  // e.g. using the -string command line option)
-  if(GModel::current()->getNumVertices()) gmsh_yysymbols.clear();
+    gmsh_yysymbols.clear();
 #endif
-  GModel::current()->destroy();
-  GModel::current()->getGEOInternals()->destroy();
+    new GModel();
+    GModel::current(GModel::list.size() - 1);
+  }
 
   // temporary hack until we fill the current GModel on the fly during
   // parsing
   ResetTemporaryBoundingBox();
-
   MergeFile(name);
 
   CTX.threads_lock = 0;
diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp
index 9e14b64881..e785ffd8f1 100644
--- a/Fltk/Main.cpp
+++ b/Fltk/Main.cpp
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
   if(argc == 2 && std::string(argv[1]) == "-doc"){
     Init_Options(0);
     GMSH_PluginManager::instance()->registerDefaultPlugins();
-    GModel *dummy = new GModel;
+    GModel *dummy = new GModel();
     Print_OptionsDoc();
     delete dummy;
     exit(0);
@@ -43,7 +43,7 @@ int main(int argc, char *argv[])
   if(CTX.batch) CTX.terminal = 1;
 
   // Create a new model
-  new GModel;
+  new GModel();
 
   // Non-interactive Gmsh
   if(CTX.batch) {
@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
   OpenProject(CTX.filename);
   for(unsigned int i = 1; i < CTX.files.size(); i++){
     if(CTX.files[i] == "-new")
-      new GModel;
+      new GModel();
     else
       MergeFile(CTX.files[i].c_str());
   }
diff --git a/Fltk/menuWindow.cpp b/Fltk/menuWindow.cpp
index 39330dc42d..e78c1b2e30 100644
--- a/Fltk/menuWindow.cpp
+++ b/Fltk/menuWindow.cpp
@@ -71,8 +71,7 @@ static void file_new_cb(Fl_Widget *w, void *data)
     time(&now);
     fprintf(fp, "// Gmsh project created on %s", ctime(&now));
     fclose(fp);
-    new GModel();
-    MergeFile(name.c_str());
+    OpenProject(name.c_str());
     Draw();
   }
 }
@@ -330,6 +329,7 @@ static void file_rename_cb(Fl_Widget *w, void *data)
           goto test;
     }
     rename(CTX.filename, name.c_str());
+    ClearProject();
     OpenProject(name.c_str());
     Draw();
   }
@@ -536,6 +536,7 @@ static void geometry_edit_cb(Fl_Widget *w, void *data)
 
 void geometry_reload_cb(Fl_Widget *w, void *data)
 {
+  ClearProject();
   OpenProject(CTX.filename);
   Draw();
 }
diff --git a/Fltk/solverWindow.cpp b/Fltk/solverWindow.cpp
index 09771ca19b..a69f43626d 100644
--- a/Fltk/solverWindow.cpp
+++ b/Fltk/solverWindow.cpp
@@ -199,7 +199,7 @@ solverWindow::solverWindow(int solverIndex, int deltaFontSize)
   int BBS = (width - 8 * WB) / 5;
   
   win = new dialogWindow
-    (width, height, CTX.non_modal_windows);
+    (width, height, CTX.non_modal_windows, "Solver");
   win->box(GMSH_WINDOW_BOX);
   {
     Fl_Tabs *o = new Fl_Tabs
diff --git a/doc/TODO.txt b/doc/TODO.txt
index 382416202b..19b8719105 100644
--- a/doc/TODO.txt
+++ b/doc/TODO.txt
@@ -1,4 +1,4 @@
-$Id: TODO.txt,v 1.12 2008-12-21 19:11:21 geuzaine Exp $
+$Id: TODO.txt,v 1.13 2009-01-04 10:21:55 geuzaine Exp $
 
 ********************************************************************
 
@@ -9,41 +9,12 @@ Surface(1)={...});
 
 ********************************************************************
 
-Introduce keyword "All" or "*" in ListOfShapes so that we can apply an
-operator (e.g Recombine) on all defined entities (instead of doing
-"{1:N}")
-
-********************************************************************
-
 Read all the components from postpro datasets, even if > 9. Provide a
 "interpretation" option allowing to select which components to draw
 and to force their interpretation as scalar, vector or tensor
 
 ********************************************************************
 
-Streamline OpenFile to deal with multiple models: basically, we need 3
-functions: NewModel (create a new model and add it to the model list,
-and make it the current model), Merge(Merge CAD or mesh data in the
-current model, or create post-processing data associated with the
-current model) and Clear(Destroys all models and post-processing
-views).
-
-main() always creates an initial empty model. Thus
-
-"gmsh a b c" == NewModel() Merge(a) Merge(b) Merge(c)
-
-"gmsh a b -new c" == NewModel() Merge(a) Merge(b) NewModel() Merge(c)
-
-File->Open(a) == Clear() NewModel() Merge(a) ?
-
-File->Merge(a) == Merge(a)
-
-Or should we just bite the bullet and follow what all other software
-tools do, i.e., if no input file is given present a File->New or Open
-dialog and refuse to continue until a model is given...
-
-********************************************************************
-
 Add a global "transparency slider" for the mesh; if value != 1, fill a
 global triangle vertex array in GModel instead of in each separate
 entity, and sort like in post-processing.
diff --git a/utils/misc/variables.msvc b/utils/misc/variables.msvc
index cc870b6845..6eaa635600 100644
--- a/utils/misc/variables.msvc
+++ b/utils/misc/variables.msvc
@@ -93,7 +93,7 @@ SYSINCLUDE=/I"${INCLUDE}"
 OPTIM=/O2
 
 # Gmsh subdirectories
-GMSH_DIRS=Common Geo Mesh Numeric contrib/ANN contrib/MathEval contrib/NR
+GMSH_DIRS=Common Geo Mesh Numeric contrib/ANN contrib/MathEval
 
 # Optional stuff
 ifeq (${ENABLE_GSL},1)
-- 
GitLab