From f26864a807c45b92f84d0c79e540a1f3098035d0 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Sun, 11 May 2014 18:01:33 +0000
Subject: [PATCH] fine-tune setChanged (the real fix will be to store the
 _changed attribute for each client in the parameter's _clients map)

---
 Common/onelab.h        | 13 ++++++-------
 Common/onelabUtils.cpp |  5 +++++
 Fltk/onelabGroup.cpp   |  3 ++-
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/Common/onelab.h b/Common/onelab.h
index edea591e93..d37b23b4ce 100644
--- a/Common/onelab.h
+++ b/Common/onelab.h
@@ -771,17 +771,16 @@ namespace onelab{
       return false;
     }
     // if no client name is given, set the changed flag for all the parameters;
-    // if a client name is given and "changed" is false, affect only the
-    // parameters that are owned exclusively by the client; if "changed" is
-    // true, affect all parameters that depend on this client
-    bool setChanged(bool changed, const std::string &client="")
+    // if a client name is given, affect parameters that are (exclusively if
+    // "exclusive" is set) owned by the client
+    bool setChanged(bool changed, const std::string &client="", bool exclusive=false)
     {
       std::set<parameter*, parameterLessThan> ps;
       _getAllParameters(ps);
       for(std::set<parameter*, parameterLessThan>::iterator it = ps.begin();
           it != ps.end(); it++)
         if(client.empty() || ((*it)->hasClient(client) &&
-                              (changed || (*it)->getNumClients() == 1)))
+                              (!exclusive || (*it)->getNumClients() == 1)))
           (*it)->setChanged(changed);
       return true;
     }
@@ -958,9 +957,9 @@ namespace onelab{
       c->setId(_clients.size());
     }
     void unregisterClient(client *c){ _clients.erase(c->getName()); }
-    void setChanged(bool changed, const std::string &client="")
+    void setChanged(bool changed, const std::string &client="", bool exclusive=false)
     {
-      _parameterSpace.setChanged(changed, client);
+      _parameterSpace.setChanged(changed, client, exclusive);
     }
     bool getChanged(const std::string &client="")
     {
diff --git a/Common/onelabUtils.cpp b/Common/onelabUtils.cpp
index b152f8df5b..41ccc1f27c 100644
--- a/Common/onelabUtils.cpp
+++ b/Common/onelabUtils.cpp
@@ -349,6 +349,11 @@ namespace onelabUtils {
         }
       }
       setFirstComputationFlag(false);
+      // don't set the "exclusive" flag here: otherwise Gmsh will re-run in a
+      // loop as soon as a shared parameter exists; this is OK because
+      // metamodels don't call runGmshClient, and the solver (e.g. GetDP) will
+      // always run anyway. The correct fix will of course to keep track of
+      // the "changed" status for each client
       onelab::server::instance()->setChanged(false, "Gmsh");
     }
 
diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp
index 9d06327281..597b77f11e 100644
--- a/Fltk/onelabGroup.cpp
+++ b/Fltk/onelabGroup.cpp
@@ -911,7 +911,7 @@ void onelab_cb(Fl_Widget *w, void *data)
       if(action == "compute"){
         // after computing with this solver, mark the parameters exclusively
         // owned by this solver as unchanged
-        onelab::server::instance()->setChanged(false, c->getName());
+        onelab::server::instance()->setChanged(false, c->getName(), true);
 	FlGui::instance()->onelab->checkForErrors(c->getName());
       }
       if(FlGui::instance()->onelab->stop()) break;
@@ -2134,6 +2134,7 @@ void solver_batch_cb(Fl_Widget *w, void *data)
     o.setValue("compute");
     onelab::server::instance()->set(o);
     c->run();
+    onelab::server::instance()->setChanged(false, c->getName(), true);
   } while(incrementLoops());
 
   if(CTX::instance()->solver.autoSaveDatabase ||
-- 
GitLab