diff --git a/Common/onelab.h b/Common/onelab.h index 5700dfb54ff168a97aeba702f31657ebeab30f78..45d4b3f852a9ed20a863d8ea567f7c829914fb83 100644 --- a/Common/onelab.h +++ b/Common/onelab.h @@ -134,7 +134,7 @@ namespace onelab{ const std::set<std::string> &getClients() const { return _clients; } static char charSep() { return '\0'; } static double maxNumber() { return 1e200; } - static std::string version() { return "1.03"; } + static std::string version() { return "1.04"; } static std::string getNextToken(const std::string &msg, std::string::size_type &first, char separator=charSep()) @@ -268,8 +268,8 @@ namespace onelab{ class number : public parameter{ private: double _value, _min, _max, _step; - // when in a loop, indicates current index in the vector _choices - // is -1 when not in a loop + // when in a loop, indicates current index in the vector _choices; is -1 + // when not in a loop int _index; std::vector<double> _choices; std::map<double, std::string> _valueLabels; @@ -410,6 +410,7 @@ namespace onelab{ setChanged(true); } setChoices(p.getChoices()); + // FIXME: this will be handled differently if(getName().find("/Action") != std::string::npos) setChanged(false); } @@ -611,8 +612,6 @@ 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) { diff --git a/Common/onelabUtils.cpp b/Common/onelabUtils.cpp index 7e7f40be2d75d1844fac15e0ab08aff7e80184b7..94873ed5a82404813e594915e2ab7c2839dab86e 100644 --- a/Common/onelabUtils.cpp +++ b/Common/onelabUtils.cpp @@ -141,30 +141,15 @@ namespace onelabUtils { loop = true; if(numbers[i].getChoices().size() > 1){ - int j=numbers[i].getIndex(); - if((j>=0) && (j < numbers[i].getChoices().size())){ + int j = numbers[i].getIndex() + 1; + if(j >= 0 && j < numbers[i].getChoices().size()){ numbers[i].setValue(numbers[i].getChoices()[j]); - numbers[i].setIndex(j+1); + numbers[i].setIndex(j); onelab::server::instance()->set(numbers[i]); Msg::Info("Recomputing with %dth choice %s=%g", j, numbers[i].getName().c_str(), numbers[i].getValue()); recompute = true; } - - // FIXME should store loopVariable attribute in the parameter - // -- the following test will loop forever if 2 values are - // identical in the list of choices - // std::vector<double> choices(numbers[i].getChoices()); - // for(unsigned int j = 0; j < choices.size() - 1; j++){ - // if(numbers[i].getValue() == choices[j]){ - // numbers[i].setValue(choices[j + 1]); - // onelab::server::instance()->set(numbers[i]); - // Msg::Info("Recomputing with new choice %s=%g", - // numbers[i].getName().c_str(), numbers[i].getValue()); - // recompute = true; - // break; - // } - // } } else if(numbers[i].getStep() > 0){ if(numbers[i].getMax() != onelab::parameter::maxNumber() && diff --git a/Fltk/onelabWindow.cpp b/Fltk/onelabWindow.cpp index 90c767b2b00cf7eaf41d276911e58ffc0b6fb4c0..2518585f94b984614c37c6428e6c86161580e029 100644 --- a/Fltk/onelabWindow.cpp +++ b/Fltk/onelabWindow.cpp @@ -689,20 +689,15 @@ onelabWindow::onelabWindow(int deltaFontSize) _gearOptionsStart = _gear->menu()->size(); _gear->add("Save database automatically", 0, onelab_option_cb, (void*)"save", - FL_MENU_TOGGLE | - (CTX::instance()->solver.autoSaveDatabase ? FL_MENU_VALUE : 0)); + FL_MENU_TOGGLE); _gear->add("Remesh automatically", 0, onelab_option_cb, (void*)"mesh", - FL_MENU_TOGGLE | - (CTX::instance()->solver.autoMesh ? FL_MENU_VALUE : 0)); + FL_MENU_TOGGLE); _gear->add("Merge results automatically", 0, onelab_option_cb, (void*)"merge", - FL_MENU_TOGGLE | - (CTX::instance()->solver.autoMergeFile ? FL_MENU_VALUE : 0)); + FL_MENU_TOGGLE); _gear->add("Hide new views", 0, onelab_option_cb, (void*)"hide", - FL_MENU_TOGGLE | - (CTX::instance()->solver.autoHideNewViews ? FL_MENU_VALUE : 0)); + FL_MENU_TOGGLE); _gear->add("_Always show last step", 0, onelab_option_cb, (void*)"step", - FL_MENU_TOGGLE | - (CTX::instance()->solver.autoShowLastStep ? FL_MENU_VALUE : 0)); + FL_MENU_TOGGLE); _gearOptionsEnd = _gear->menu()->size(); @@ -1175,7 +1170,20 @@ void onelabWindow::rebuildSolverList() { // update OneLab window title and gear menu _title = "OneLab"; - for(int i = _gear->menu()->size(); i >= _gearOptionsEnd - 1; i--) + Fl_Menu_Item* menu = (Fl_Menu_Item*)_gear->menu(); + int values[5] = {CTX::instance()->solver.autoSaveDatabase, + CTX::instance()->solver.autoMesh, + CTX::instance()->solver.autoMergeFile, + CTX::instance()->solver.autoHideNewViews, + CTX::instance()->solver.autoShowLastStep}; + for(int i = 0; i < 5; i++){ + int idx = _gearOptionsStart - 1 + i; + if(values[i]) + menu[idx].set(); + else + menu[idx].clear(); + } + for(int i = menu->size(); i >= _gearOptionsEnd - 1; i--) _gear->remove(i); for(onelab::server::citer it = onelab::server::instance()->firstClient(); it != onelab::server::instance()->lastClient(); it++){ diff --git a/utils/solvers/c++/onelab.h b/utils/solvers/c++/onelab.h index b3ec2a9d0122c1eeaffac6edb68d1bbf6bf927a3..45d4b3f852a9ed20a863d8ea567f7c829914fb83 100644 --- a/utils/solvers/c++/onelab.h +++ b/utils/solvers/c++/onelab.h @@ -100,6 +100,11 @@ namespace onelab{ const std::string &getName() const { return _name; } const std::string &getLabel() const { return _label; } const std::string &getHelp() const { return _help; } + std::string getPath() const + { + std::string::size_type last = _name.find_last_of('/'); + return _name.substr(0, last); + } std::string getShortName() const { if(_label.size()) return _label; @@ -129,7 +134,7 @@ namespace onelab{ const std::set<std::string> &getClients() const { return _clients; } static char charSep() { return '\0'; } static double maxNumber() { return 1e200; } - static std::string version() { return "1.03"; } + static std::string version() { return "1.04"; } static std::string getNextToken(const std::string &msg, std::string::size_type &first, char separator=charSep()) @@ -263,17 +268,21 @@ namespace onelab{ class number : public parameter{ private: double _value, _min, _max, _step; + // when in a loop, indicates current index in the vector _choices; is -1 + // when not in a loop + int _index; std::vector<double> _choices; std::map<double, std::string> _valueLabels; public: number(const std::string &name="", double value=0., const std::string &label="", const std::string &help="") : parameter(name, label, help), _value(value), - _min(-maxNumber()), _max(maxNumber()), _step(0.) {} + _min(-maxNumber()), _max(maxNumber()), _step(0.), _index(0) {} void setValue(double value){ _value = value; } void setMin(double min){ _min = min; } void setMax(double max){ _max = max; } void setStep(double step){ _step = step; } + void setIndex(int index){ _index = index; } void setChoices(const std::vector<double> &choices){ _choices = choices; } void setChoiceLabels(const std::vector<std::string> &labels) { @@ -294,6 +303,7 @@ namespace onelab{ double getMin() const { return _min; } double getMax() const { return _max; } double getStep() const { return _step; } + int getIndex() const { return _index; } const std::vector<double> &getChoices() const { return _choices; } const std::map<double, std::string> &getValueLabels() const { @@ -320,6 +330,7 @@ namespace onelab{ setMin(p.getMin()); setMax(p.getMax()); setStep(p.getStep()); + setIndex(p.getIndex()); setChoices(p.getChoices()); setValueLabels(p.getValueLabels()); } @@ -328,6 +339,7 @@ namespace onelab{ std::ostringstream sstream; sstream << parameter::toChar() << _value << charSep() << _min << charSep() << _max << charSep() << _step << charSep() + << _index << charSep() << _choices.size() << charSep(); for(unsigned int i = 0; i < _choices.size(); i++) sstream << _choices[i] << charSep(); @@ -347,6 +359,7 @@ namespace onelab{ setMin(atof(getNextToken(msg, pos).c_str())); setMax(atof(getNextToken(msg, pos).c_str())); setStep(atof(getNextToken(msg, pos).c_str())); + setIndex(atoi(getNextToken(msg, pos).c_str())); _choices.resize(atoi(getNextToken(msg, pos).c_str())); for(unsigned int i = 0; i < _choices.size(); i++) _choices[i] = atof(getNextToken(msg, pos).c_str()); @@ -397,6 +410,9 @@ namespace onelab{ setChanged(true); } setChoices(p.getChoices()); + // FIXME: this will be handled differently + if(getName().find("/Action") != std::string::npos) + setChanged(false); } std::string toChar() const { @@ -692,8 +708,9 @@ namespace onelab{ std::set<parameter*> ps; _getAllParameters(ps); for(std::set<parameter*>::iterator it = ps.begin(); it != ps.end(); it++){ - if((client.empty() || (*it)->hasClient(client)) && (*it)->getChanged()) + if((client.empty() || (*it)->hasClient(client)) && (*it)->getChanged()){ return true; + } } return false; }