From 5aeb5576261c03374a26eac2098dd93d2252f564 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 30 Dec 2004 00:30:04 +0000
Subject: [PATCH] Don't update the views in the GUI directly after each view is
 created. Instead, wait until the whole file is read. This speeds up the
 creation of the interface dramatically when we have a large number of views
 in a single file. (In my code I routinely merge around 1000 views in a single
 file to do animations; with this patch, the GUI creation time goes from 30
 seconds to less than 1 second.)

---
 Common/Views.cpp    | 11 ++++++++---
 Parser/Gmsh.y       | 16 +++++++++++-----
 Parser/OpenFile.cpp | 14 +++++++++++---
 3 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/Common/Views.cpp b/Common/Views.cpp
index 23786f0205..8179eb42e8 100644
--- a/Common/Views.cpp
+++ b/Common/Views.cpp
@@ -1,4 +1,4 @@
-// $Id: Views.cpp,v 1.157 2004-12-29 04:14:27 geuzaine Exp $
+// $Id: Views.cpp,v 1.158 2004-12-30 00:30:04 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -426,7 +426,7 @@ void EndView(Post_View * v, int add_in_gui, char *file_name, char *name)
     v->smooth();
 
 #if defined(HAVE_FLTK)
-  if(!CTX.post.force_num && add_in_gui)
+  if(add_in_gui)
     UpdateViewsInGUI();
 #endif
 
@@ -984,7 +984,8 @@ void ReadView(FILE *file, char *filename)
           List_Nbr(v->T2D), List_Nbr(v->T2C), List_Nbr(v->T3D),
           List_Nbr(v->T3C));
 
-      EndView(v, 1, filename, name);
+      // don't update the ui after each view, but only at the end
+      EndView(v, 0, filename, name); 
     }
 
     do {
@@ -995,6 +996,10 @@ void ReadView(FILE *file, char *filename)
 
   }     /* while 1 ... */
 
+#if defined(HAVE_FLTK)
+  UpdateViewsInGUI();
+#endif
+
   Msg(INFO, "Read post-processing file '%s'", filename);
   Msg(STATUS2N, "Read '%s'", filename);
 }
diff --git a/Parser/Gmsh.y b/Parser/Gmsh.y
index 160a6255ba..a68539e766 100644
--- a/Parser/Gmsh.y
+++ b/Parser/Gmsh.y
@@ -1,5 +1,5 @@
 %{
-// $Id: Gmsh.y,v 1.190 2004-12-27 01:13:57 geuzaine Exp $
+// $Id: Gmsh.y,v 1.191 2004-12-30 00:30:04 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -440,13 +440,15 @@ Printf :
 View :
     tSTRING tBIGSTR '{' Views '}' tEND
     { 
-      if(!strcmp($1, "View") && !CheckViewErrorFlags(View))
-	EndView(View, 1, yyname, $2);
+      if(!strcmp($1, "View") && !CheckViewErrorFlags(View)){
+	EndView(View, 0, yyname, $2);
+      }
     }
   | tSTRING tBIGSTR tSTRING VExpr '{' Views '}' tEND
     {
-      if(!strcmp($1, "View") && !CheckViewErrorFlags(View))
-	EndView(View, 1, yyname, $2);
+      if(!strcmp($1, "View") && !CheckViewErrorFlags(View)){
+	EndView(View, 0, yyname, $2);
+      }
     }  
 ;
 
@@ -2392,6 +2394,10 @@ Delete :
 	  if(v->empty())
 	    RemoveViewByIndex(i);
 	}
+#if defined(HAVE_FLTK)
+	if(!CTX.batch)
+	  UpdateViewsInGUI();
+#endif
       }
       else{
 	yymsg(GERROR, "Unknown command 'Delete %s %s'", $2, $3);
diff --git a/Parser/OpenFile.cpp b/Parser/OpenFile.cpp
index 58d10763c7..e692c0c285 100644
--- a/Parser/OpenFile.cpp
+++ b/Parser/OpenFile.cpp
@@ -1,4 +1,4 @@
-// $Id: OpenFile.cpp,v 1.66 2004-11-25 02:10:40 geuzaine Exp $
+// $Id: OpenFile.cpp,v 1.67 2004-12-30 00:30:04 geuzaine Exp $
 //
 // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
 //
@@ -42,6 +42,7 @@
 #include "Draw.h"
 #include "GUI.h"
 extern GUI *WID;
+void UpdateViewsInGUI();
 #endif
 
 extern Mesh *THEM, M;
@@ -117,7 +118,7 @@ int ParseFile(char *f, int silent, int close, int warn_if_missing)
 {
   char yyname_old[256], tmp[256];
   FILE *yyin_old, *fp;
-  int yylineno_old, yyerrorstate_old, status;
+  int yylineno_old, yyerrorstate_old, numviews_old, status;
 
   if(!(fp = fopen(f, "r"))){
     if(warn_if_missing)
@@ -129,7 +130,8 @@ int ParseFile(char *f, int silent, int close, int warn_if_missing)
   yyin_old = yyin;
   yyerrorstate_old = yyerrorstate;
   yylineno_old = yylineno;
-  
+  numviews_old = List_Nbr(CTX.post.list);
+
   strncpy(yyname, f, 255);
   yyin = fp;
   yyerrorstate = 0;
@@ -171,6 +173,12 @@ int ParseFile(char *f, int silent, int close, int warn_if_missing)
   yyerrorstate = yyerrorstate_old;
   yylineno = yylineno_old;
 
+  if(List_Nbr(CTX.post.list) > numviews_old){
+#if defined(HAVE_FLTK)
+    UpdateViewsInGUI();
+#endif
+  }
+  
   GMSH_Solve_Plugin *sp = GMSH_PluginManager::instance()->findSolverPlugin();
   if(sp) {
     sp->readSolverFile(f);
-- 
GitLab