diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp index 1e1ad69661c6e03dc4369b9ca5170e11dcd31847..87212ac0255a013433334431cf1261aa88087edd 100644 --- a/Common/GmshMessage.cpp +++ b/Common/GmshMessage.cpp @@ -631,6 +631,35 @@ bool Msg::UseOnelab() #endif } +void Msg::SetOnelabNumber(std::string name, double val, bool visible) +{ + if(_onelabClient){ + std::vector<onelab::number> numbers; + _onelabClient->get(numbers, name); + if(numbers.empty()){ + numbers.resize(1); + numbers[0].setName(name); + } + numbers[0].setValue(val); + numbers[0].setVisible(visible); + _onelabClient->set(numbers[0]); + } +} +void Msg::SetOnelabString(std::string name, std::string val, bool visible) +{ + if(_onelabClient){ + std::vector<onelab::string> strings; + _onelabClient->get(strings, name); + if(strings.empty()){ + strings.resize(1); + strings[0].setName(name); + } + strings[0].setValue(val); + strings[0].setVisible(visible); + _onelabClient->set(strings[0]); + } +} + void Msg::InitializeOnelab(const std::string &name, const std::string &sockname) { #if defined(HAVE_ONELAB) @@ -647,18 +676,10 @@ void Msg::InitializeOnelab(const std::string &name, const std::string &sockname) _onelabClient = c; _client = c->getGmshClient(); - onelab::number o5(name + "/UseCommandLine",1); - o5.setVisible(false); - _onelabClient->set(o5); - onelab::string o(name + "/FileExtension", ".geo"); - o.setVisible(false); - _onelabClient->set(o); - onelab::string o3(name + "/9CheckCommand", "-"); - o3.setVisible(false); - _onelabClient->set(o3); - onelab::string o4(name + "/9ComputeCommand", "-3"); - o4.setVisible(false); - _onelabClient->set(o4); + SetOnelabNumber(name + "/UseCommandLine", 1, false); + SetOnelabString(name + "/FileExtension", ".geo", false); + SetOnelabString(name + "/9CheckCommand", "-", false); + SetOnelabString(name + "/9ComputeCommand", "-3", false); std::vector<onelab::string> ps; _onelabClient->get(ps, name + "/Action"); @@ -783,11 +804,24 @@ void Msg::ImportPhysicalsAsOnelabRegions() ((dim == 3) ? "Volume" : (dim == 2) ? "Surface" : (dim == 1) ? "Line" : "Point") + num.str(); name.insert(0, "Gmsh/Physical groups/"); - onelab::region p(name, num.str()); - p.setDimension(dim); - p.setReadOnly(true); - p.setAttribute("Closed", "1"); - _onelabClient->set(p); + std::vector<onelab::region> regions; + std::set<std::string> val; + val.insert(num.str()); + _onelabClient->get(regions, name); + if(regions.empty()){ + regions.resize(1); + regions[0].setName(name); + regions[0].setValue(val); + regions[0].setReadOnly(true); + regions[0].setAttribute("Closed", "1"); + _onelabClient->set(regions[0]); + } + + // onelab::region p(name, num.str()); + // p.setDimension(dim); + // p.setReadOnly(true); + // p.setAttribute("Closed", "1"); + // _onelabClient->set(p); } } } diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h index 629fe3716cdd86c950117f3a6c0589d3ea40fe7b..a1ee370189015075be8802df9ce5d954d5ff34e7 100644 --- a/Common/GmshMessage.h +++ b/Common/GmshMessage.h @@ -86,6 +86,8 @@ class Msg { static GmshClient *GetGmshClient(){ return _client; } static void FinalizeOnelab(); static bool UseOnelab(); + static void SetOnelabNumber(std::string name, double val, bool visible); + static void SetOnelabString(std::string name, std::string val, bool visible); static void ExchangeOnelabParameter(const std::string &key, std::vector<double> &val, std::map<std::string, std::vector<double> > &fopt, diff --git a/Common/onelab.h b/Common/onelab.h index 532f74c42ac9fc6d4c5aff0bd981786b7112ce52..eb2c0e30b6f36c9cf6eeddec6b0b2c15f1185128 100644 --- a/Common/onelab.h +++ b/Common/onelab.h @@ -315,6 +315,7 @@ namespace onelab{ addClients(p.getClients()); // complete the list of clients setLabel(p.getLabel()); setHelp(p.getHelp()); + setChanged(p.getChanged()); setVisible(p.getVisible()); setReadOnly(p.getReadOnly()); setAttributes(p.getAttributes()); @@ -390,12 +391,13 @@ namespace onelab{ addClients(p.getClients()); setLabel(p.getLabel()); setHelp(p.getHelp()); + setChanged(p.getChanged()); setVisible(p.getVisible()); setReadOnly(p.getReadOnly()); setAttributes(p.getAttributes()); if(p.getValue() != getValue()){ setValue(p.getValue()); - setChanged(true); + setChanged(true); } if(p.getKind() != getKind()){ setKind(p.getKind()); @@ -439,12 +441,15 @@ namespace onelab{ region(const std::string &name="", const std::set<std::string> &value = std::set<std::string>(), const std::string &label="", const std::string &help="") - : parameter(name, label, help), _value(value), _dimension(-1) {} + : parameter(name, label, help), _value(value), _dimension(-1) { + setChanged(false); // FIXME + } region(const std::string &name, const std::string &value, const std::string &label="", const std::string &help="") : parameter(name, label, help), _dimension(-1) { if(value.size()) _value.insert(value); + setChanged(false); // FIXME } void setValue(const std::set<std::string> &value){ _value = value; } void setDimension(int dim){ _dimension = dim; } @@ -464,6 +469,7 @@ namespace onelab{ addClients(p.getClients()); setLabel(p.getLabel()); setHelp(p.getHelp()); + setChanged(p.getChanged()); setAttributes(p.getAttributes()); if(p.getValue() != getValue()){ setValue(p.getValue()); @@ -471,6 +477,7 @@ namespace onelab{ } setDimension(p.getDimension()); setChoices(p.getChoices()); + setChanged(false); // FIXME } std::string toChar() const { @@ -544,6 +551,7 @@ namespace onelab{ addClients(p.getClients()); setLabel(p.getLabel()); setHelp(p.getHelp()); + setChanged(p.getChanged()); setAttributes(p.getAttributes()); if(p.getValue() != getValue()){ setValue(p.getValue()); @@ -601,6 +609,8 @@ namespace onelab{ // set a parameter in the parameter space; if it already exists, update it // (adding new clients if necessary). This needs to be locked to avoid race // conditions when several clients try to set a parameter at the same time. + // One needs to make an exception for parameters "client/Action". + template <class T> bool _set(const T &p, const std::string &client, std::set<T*, parameterLessThan> &ps) { @@ -634,7 +644,7 @@ namespace onelab{ T tmp(name); typename std::set<T*, parameterLessThan>::iterator it = ps.find(&tmp); if(it != ps.end()){ - if(client.size()) (*it)->addClient(client); + if(client.size()) (*it)->addClient(client); p.push_back(**it); } }