From df8020058f3a8e83a94d9c3b02644397da8ce370 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 15 Feb 2016 09:50:00 +0000
Subject: [PATCH] only run onelab(check) if some solvers are present

---
 Common/onelabUtils.cpp | 14 ++++++++++++++
 Common/onelabUtils.h   |  1 +
 Fltk/graphicWindow.cpp | 32 ++++++++++++--------------------
 3 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/Common/onelabUtils.cpp b/Common/onelabUtils.cpp
index 7b5b5f40c0..6b808fd7e9 100644
--- a/Common/onelabUtils.cpp
+++ b/Common/onelabUtils.cpp
@@ -460,6 +460,20 @@ namespace onelabUtils {
     return val;
   }
 
+  bool haveSolverToRun()
+  {
+    for(onelab::server::citer it = onelab::server::instance()->firstClient();
+	it != onelab::server::instance()->lastClient(); it++){
+      onelab::client *c = *it;
+      if(c->getName() != "Gmsh" &&
+	 c->getName() != "Listen" &&
+	 c->getName() != "GmshRemote" &&
+         c->getName().find("NoAutoRun") == std::string::npos)
+	return true;
+    }
+    return false;
+  }
+
   // update x using y, giving priority to any settings in x that can be set in
   // the GUI. The value of x is only changed if y is read-only.
   std::string updateString(onelab::string &x, onelab::string &y)
diff --git a/Common/onelabUtils.h b/Common/onelabUtils.h
index 211d3880af..daae074d15 100644
--- a/Common/onelabUtils.h
+++ b/Common/onelabUtils.h
@@ -22,6 +22,7 @@ namespace onelabUtils {
   bool runGmshClient(const std::string &action, int meshAuto);
   bool getFirstComputationFlag();
   void setFirstComputationFlag(bool val);
+  bool haveSolverToRun();
 
   double updateNumber(onelab::number &x, onelab::number &y, const bool readOnlyRange=false);
   std::string updateString(onelab::string &x, onelab::string &y);
diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp
index 7ecadfc989..07f964b59b 100644
--- a/Fltk/graphicWindow.cpp
+++ b/Fltk/graphicWindow.cpp
@@ -54,6 +54,7 @@ typedef unsigned long intptr_t;
 #include "Generator.h"
 #include "HighOrder.h"
 #include "OS.h"
+#include "onelabUtils.h"
 #if defined(HAVE_3M)
 #include "3M.h"
 #endif
@@ -150,12 +151,10 @@ static void file_open_merge_cb(Fl_Widget *w, void *data)
   }
   if(n != (int)PView::list.size())
     FlGui::instance()->openModule("Post-processing");
-  if(CTX::instance()->launchSolverAtStartup >= 0){
+  if(CTX::instance()->launchSolverAtStartup >= 0)
     solver_cb(0, (void*)CTX::instance()->launchSolverAtStartup);
-  }
-  else{
+  else if(onelabUtils::haveSolverToRun())
     onelab_cb(0, (void*)"check");
-  }
 }
 
 static void file_open_recent_cb(Fl_Widget *w, void *data)
@@ -167,12 +166,10 @@ static void file_open_recent_cb(Fl_Widget *w, void *data)
   drawContext::global()->draw();
   if(n != (int)PView::list.size())
     FlGui::instance()->openModule("Post-processing");
-  if(CTX::instance()->launchSolverAtStartup >= 0){
+  if(CTX::instance()->launchSolverAtStartup >= 0)
     solver_cb(0, (void*)CTX::instance()->launchSolverAtStartup);
-  }
-  else{
+  else if(onelabUtils::haveSolverToRun())
     onelab_cb(0, (void*)"check");
-  }
 }
 
 static void file_clear_cb(Fl_Widget *w, void *data)
@@ -182,7 +179,10 @@ static void file_clear_cb(Fl_Widget *w, void *data)
     return;
   }
   ClearProject();
-  onelab_cb(0, (void*)"reset"); // this will call OpenProject
+  if(onelabUtils::haveSolverToRun())
+    onelab_cb(0, (void*)"reset"); // this will call OpenProject
+  else
+    OpenProject(GModel::current()->getFileName());
   drawContext::global()->draw();
 }
 
@@ -502,7 +502,8 @@ static void file_rename_cb(Fl_Widget *w, void *data)
     rename(GModel::current()->getFileName().c_str(), name.c_str());
     GModel::current()->setFileName(name);
     GModel::current()->setName(SplitFileName(name)[1]);
-    onelab_cb(0, (void*)"check");
+    if(onelabUtils::haveSolverToRun())
+      onelab_cb(0, (void*)"check");
     drawContext::global()->draw();
   }
 }
@@ -589,16 +590,7 @@ void onelab_reload_cb(Fl_Widget *w, void *data)
 
 void geometry_reload_cb(Fl_Widget *w, void *data)
 {
-  bool haveNonGmshClients = false;
-  for(onelab::server::citer it = onelab::server::instance()->firstClient();
-      it != onelab::server::instance()->lastClient(); it++){
-    onelab::client *c = *it;
-    if(c->getName() != "Gmsh"){
-      haveNonGmshClients = true;
-      break;
-    }
-  }
-  if(haveNonGmshClients)
+  if(onelabUtils::haveSolverToRun())
     onelab_cb(0, (void*)"check"); // will call OpenProject
   else
     OpenProject(GModel::current()->getFileName());
-- 
GitLab