From 3660c0216b4e807fc589dc459465ff70e96a884c Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sat, 20 Feb 2016 08:03:52 +0000
Subject: [PATCH] cleanup

---
 Common/GmshMessage.cpp | 14 +++++++-------
 Common/OS.cpp          |  6 ------
 Fltk/FlGui.cpp         | 14 --------------
 Fltk/FlGui.h           |  4 ----
 Fltk/drawContextFltk.h |  5 +++--
 Fltk/graphicWindow.cpp |  6 +++---
 tutorial/t8.geo        |  8 +++-----
 7 files changed, 16 insertions(+), 41 deletions(-)

diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp
index 935d53311e..8eadda1e06 100644
--- a/Common/GmshMessage.cpp
+++ b/Common/GmshMessage.cpp
@@ -266,7 +266,7 @@ void Msg::Fatal(const char *fmt, ...)
 
 #if defined(HAVE_FLTK)
   if(FlGui::available()){
-    if(FlGui::instance()->in_main_thread()) FlGui::instance()->check();
+    FlGui::instance()->check();
     std::string tmp = std::string("@C1@.") + "Fatal   : " + str;
     FlGui::instance()->addMessage(tmp.c_str());
     if(_firstError.empty()) _firstError = str;
@@ -314,7 +314,7 @@ void Msg::Error(const char *fmt, ...)
 
 #if defined(HAVE_FLTK)
   if(FlGui::available()){
-    if(FlGui::instance()->in_main_thread()) FlGui::instance()->check();
+    FlGui::instance()->check();
     std::string tmp = std::string(CTX::instance()->guiColorScheme ? "@B72@." : "@C1@.")
       + "Error   : " + str;
     FlGui::instance()->addMessage(tmp.c_str());
@@ -354,7 +354,7 @@ void Msg::Warning(const char *fmt, ...)
 
 #if defined(HAVE_FLTK)
   if(FlGui::available()){
-    if(FlGui::instance()->in_main_thread()) FlGui::instance()->check();
+    FlGui::instance()->check();
     std::string tmp = std::string(CTX::instance()->guiColorScheme ? "@B152@." : "@C5@.")
       + "Warning : " + str;
     FlGui::instance()->addMessage(tmp.c_str());
@@ -395,7 +395,7 @@ void Msg::Info(const char *fmt, ...)
 #endif
   {
     if(FlGui::available()){
-      if(FlGui::instance()->in_main_thread()) FlGui::instance()->check();
+      FlGui::instance()->check();
       std::string tmp = std::string("Info    : ") + str;
       FlGui::instance()->addMessage(tmp.c_str());
     }
@@ -435,7 +435,7 @@ void Msg::Direct(const char *fmt, ...)
 #endif
   {
     if(FlGui::available()){
-      if(FlGui::instance()->in_main_thread()) FlGui::instance()->check();
+      FlGui::instance()->check();
       std::string tmp = std::string(CTX::instance()->guiColorScheme ? "@B136@." : "@C4@.")
         + str;
       FlGui::instance()->addMessage(tmp.c_str());
@@ -475,7 +475,7 @@ void Msg::StatusBar(bool log, const char *fmt, ...)
 #endif
   {
     if(FlGui::available()){
-      if(log && FlGui::instance()->in_main_thread()) FlGui::instance()->check();
+      if(log) FlGui::instance()->check();
       if(!log || _verbosity > 4)
 	FlGui::instance()->setStatus(str);
       if(log){
@@ -566,7 +566,7 @@ void Msg::ProgressMeter(int n, int N, bool log, const char *fmt, ...)
 
 #if defined(HAVE_FLTK)
     if(FlGui::available() && _verbosity > 4){
-      if(FlGui::instance()->in_main_thread()) FlGui::instance()->check();
+      FlGui::instance()->check();
       FlGui::instance()->setProgress(str, (n > N - 1) ? 0 : n, 0, N);
     }
 #endif
diff --git a/Common/OS.cpp b/Common/OS.cpp
index 2c9825286b..f82efdea9a 100644
--- a/Common/OS.cpp
+++ b/Common/OS.cpp
@@ -583,13 +583,7 @@ int SystemCallExe(const std::string &exe, const std::string &argsOrCommand,
     return 1;
   }
   if(!blocking) cmd += " &";
-#if defined(HAVE_FLTK) // FIXME: remove
-  if(FlGui::available()) FlGui::instance()->lock();
-#endif
   Msg::Info("Calling '%s'", cmd.c_str());
-#if defined(HAVE_FLTK) // FIXME: remove
-  if(FlGui::available()) FlGui::instance()->unlock();
-#endif
   if(!system(cmd.c_str())) return 1;
 #endif
   return 0;
diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp
index 4544d9e033..b8b8ad0e13 100644
--- a/Fltk/FlGui.cpp
+++ b/Fltk/FlGui.cpp
@@ -71,18 +71,6 @@ static int globalShortcut(int event)
   return FlGui::instance()->testGlobalShortcuts(event);
 }
 
-int FlGui::lock()
-{
-  _in_main_thread++;
-  return Fl::lock();
-}
-
-void FlGui::unlock()
-{
-  Fl::unlock();
-  _in_main_thread--;
-}
-
 static void simple_right_box_draw(int x, int y, int w, int h, Fl_Color c)
 {
   fl_color(c); fl_rectf(x, y, w, h);
@@ -457,8 +445,6 @@ FlGui::FlGui(int argc, char **argv)
   // init solver plugin stuff
   callForSolverPlugin(-1);
 
-  _in_main_thread = 0;
-
   // draw
   for(unsigned int i = 0; i < graph.size(); i++)
     for(unsigned int j = 0; j < graph[i]->gl.size(); j++)
diff --git a/Fltk/FlGui.h b/Fltk/FlGui.h
index b1c1c04339..a7c015e2e3 100644
--- a/Fltk/FlGui.h
+++ b/Fltk/FlGui.h
@@ -48,7 +48,6 @@ class FlGui{
  private:
   static FlGui *_instance;
   static std::string _openedThroughMacFinder;
-  int _in_main_thread;
   std::string _lastStatus;
  public:
   std::vector<GVertex*> selectedVertices;
@@ -90,9 +89,6 @@ class FlGui{
   static void wait();
   // wait (at most time seconds) for any events, then process them
   static void wait(double time);
-  int lock();
-  void unlock();
-  bool in_main_thread() {return _in_main_thread==0;}
   // is a file opened through the Mac Finder?
   static void setOpenedThroughMacFinder(const std::string &name)
   {
diff --git a/Fltk/drawContextFltk.h b/Fltk/drawContextFltk.h
index a4b079cbee..63fba50486 100644
--- a/Fltk/drawContextFltk.h
+++ b/Fltk/drawContextFltk.h
@@ -28,13 +28,14 @@ class drawContextFltk : public drawContextGlobal{
         for(unsigned int j = 0; j < FlGui::instance()->graph[i]->gl.size(); j++){
           FlGui::instance()->graph[i]->gl[j]->make_current();
           FlGui::instance()->graph[i]->gl[j]->redraw();
-          // FIXME: I don't think this should be done here CG
-          // to initialize the camera distance from model
+          glFlush();
+          // FIXME: I don't think this should be done here
           drawContext *ctx = FlGui::instance()->graph[i]->gl[j]->getDrawContext();
           ctx->camera.update();
         }
       }
     }
+    FlGui::instance()->check();
   }
   void drawCurrentOpenglWindow(bool make_current)
   {
diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp
index 898cc91084..c4adfd1509 100644
--- a/Fltk/graphicWindow.cpp
+++ b/Fltk/graphicWindow.cpp
@@ -2757,7 +2757,7 @@ void show_hide_message_cb(Fl_Widget *w, void *data)
   graphicWindow *g = getGraphicWindow
     (FlGui::instance()->getCurrentOpenglWindow()->parent());
   g->showHideMessages();
-  FlGui::check();
+  FlGui::instance()->check();
 }
 
 void show_hide_menu_cb(Fl_Widget *w, void *data)
@@ -2765,7 +2765,7 @@ void show_hide_menu_cb(Fl_Widget *w, void *data)
   graphicWindow *g = getGraphicWindow
     (FlGui::instance()->getCurrentOpenglWindow()->parent());
   g->showHideMenu();
-  FlGui::check();
+  FlGui::instance()->check();
 }
 
 void attach_detach_menu_cb(Fl_Widget *w, void *data)
@@ -2773,7 +2773,7 @@ void attach_detach_menu_cb(Fl_Widget *w, void *data)
   graphicWindow *g = getGraphicWindow
     (FlGui::instance()->getCurrentOpenglWindow()->parent());
   g->attachDetachMenu();
-  FlGui::check();
+  FlGui::instance()->check();
 }
 
 static void message_menu_scroll_cb(Fl_Widget *w, void *data)
diff --git a/tutorial/t8.geo b/tutorial/t8.geo
index a2283bffb2..ae9da1e8cc 100644
--- a/tutorial/t8.geo
+++ b/tutorial/t8.geo
@@ -93,11 +93,9 @@ For num In {1:3}
     If (num == 3)
       // The `Print' command saves the graphical window; the `Sprintf' function
       // permits to create the file names on the fly:
-      /*
-      Print Sprintf("t8-%02g.gif", num2);
-      Print Sprintf("t8-%02g.ppm", num2);
-      Print Sprintf("t8-%02g.jpg", num2);
-      */
+      //Print Sprintf("t8-%02g.gif", num2);
+      //Print Sprintf("t8-%02g.ppm", num2);
+      //Print Sprintf("t8-%02g.jpg", num2);
     EndIf
 
   EndFor
-- 
GitLab