Skip to content
Snippets Groups Projects
Commit 37af624f authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

- increment onelab version

- fix loop index (off by one)
- reset options in menu everytime we rebuild the menu
parent b89dd4df
No related branches found
No related tags found
No related merge requests found
...@@ -134,7 +134,7 @@ namespace onelab{ ...@@ -134,7 +134,7 @@ namespace onelab{
const std::set<std::string> &getClients() const { return _clients; } const std::set<std::string> &getClients() const { return _clients; }
static char charSep() { return '\0'; } static char charSep() { return '\0'; }
static double maxNumber() { return 1e200; } 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, static std::string getNextToken(const std::string &msg,
std::string::size_type &first, std::string::size_type &first,
char separator=charSep()) char separator=charSep())
...@@ -268,8 +268,8 @@ namespace onelab{ ...@@ -268,8 +268,8 @@ namespace onelab{
class number : public parameter{ class number : public parameter{
private: private:
double _value, _min, _max, _step; double _value, _min, _max, _step;
// when in a loop, indicates current index in the vector _choices // when in a loop, indicates current index in the vector _choices; is -1
// is -1 when not in a loop // when not in a loop
int _index; int _index;
std::vector<double> _choices; std::vector<double> _choices;
std::map<double, std::string> _valueLabels; std::map<double, std::string> _valueLabels;
...@@ -410,6 +410,7 @@ namespace onelab{ ...@@ -410,6 +410,7 @@ namespace onelab{
setChanged(true); setChanged(true);
} }
setChoices(p.getChoices()); setChoices(p.getChoices());
// FIXME: this will be handled differently
if(getName().find("/Action") != std::string::npos) if(getName().find("/Action") != std::string::npos)
setChanged(false); setChanged(false);
} }
...@@ -611,8 +612,6 @@ namespace onelab{ ...@@ -611,8 +612,6 @@ namespace onelab{
// set a parameter in the parameter space; if it already exists, update it // 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 // (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. // 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, template <class T> bool _set(const T &p, const std::string &client,
std::set<T*, parameterLessThan> &ps) std::set<T*, parameterLessThan> &ps)
{ {
... ...
......
...@@ -141,30 +141,15 @@ namespace onelabUtils { ...@@ -141,30 +141,15 @@ namespace onelabUtils {
loop = true; loop = true;
if(numbers[i].getChoices().size() > 1){ if(numbers[i].getChoices().size() > 1){
int j=numbers[i].getIndex(); int j = numbers[i].getIndex() + 1;
if((j>=0) && (j < numbers[i].getChoices().size())){ if(j >= 0 && j < numbers[i].getChoices().size()){
numbers[i].setValue(numbers[i].getChoices()[j]); numbers[i].setValue(numbers[i].getChoices()[j]);
numbers[i].setIndex(j+1); numbers[i].setIndex(j);
onelab::server::instance()->set(numbers[i]); onelab::server::instance()->set(numbers[i]);
Msg::Info("Recomputing with %dth choice %s=%g", j, Msg::Info("Recomputing with %dth choice %s=%g", j,
numbers[i].getName().c_str(), numbers[i].getValue()); numbers[i].getName().c_str(), numbers[i].getValue());
recompute = true; 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){ else if(numbers[i].getStep() > 0){
if(numbers[i].getMax() != onelab::parameter::maxNumber() && if(numbers[i].getMax() != onelab::parameter::maxNumber() &&
... ...
......
...@@ -689,20 +689,15 @@ onelabWindow::onelabWindow(int deltaFontSize) ...@@ -689,20 +689,15 @@ onelabWindow::onelabWindow(int deltaFontSize)
_gearOptionsStart = _gear->menu()->size(); _gearOptionsStart = _gear->menu()->size();
_gear->add("Save database automatically", 0, onelab_option_cb, (void*)"save", _gear->add("Save database automatically", 0, onelab_option_cb, (void*)"save",
FL_MENU_TOGGLE | FL_MENU_TOGGLE);
(CTX::instance()->solver.autoSaveDatabase ? FL_MENU_VALUE : 0));
_gear->add("Remesh automatically", 0, onelab_option_cb, (void*)"mesh", _gear->add("Remesh automatically", 0, onelab_option_cb, (void*)"mesh",
FL_MENU_TOGGLE | FL_MENU_TOGGLE);
(CTX::instance()->solver.autoMesh ? FL_MENU_VALUE : 0));
_gear->add("Merge results automatically", 0, onelab_option_cb, (void*)"merge", _gear->add("Merge results automatically", 0, onelab_option_cb, (void*)"merge",
FL_MENU_TOGGLE | FL_MENU_TOGGLE);
(CTX::instance()->solver.autoMergeFile ? FL_MENU_VALUE : 0));
_gear->add("Hide new views", 0, onelab_option_cb, (void*)"hide", _gear->add("Hide new views", 0, onelab_option_cb, (void*)"hide",
FL_MENU_TOGGLE | FL_MENU_TOGGLE);
(CTX::instance()->solver.autoHideNewViews ? FL_MENU_VALUE : 0));
_gear->add("_Always show last step", 0, onelab_option_cb, (void*)"step", _gear->add("_Always show last step", 0, onelab_option_cb, (void*)"step",
FL_MENU_TOGGLE | FL_MENU_TOGGLE);
(CTX::instance()->solver.autoShowLastStep ? FL_MENU_VALUE : 0));
_gearOptionsEnd = _gear->menu()->size(); _gearOptionsEnd = _gear->menu()->size();
...@@ -1175,7 +1170,20 @@ void onelabWindow::rebuildSolverList() ...@@ -1175,7 +1170,20 @@ void onelabWindow::rebuildSolverList()
{ {
// update OneLab window title and gear menu // update OneLab window title and gear menu
_title = "OneLab"; _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); _gear->remove(i);
for(onelab::server::citer it = onelab::server::instance()->firstClient(); for(onelab::server::citer it = onelab::server::instance()->firstClient();
it != onelab::server::instance()->lastClient(); it++){ it != onelab::server::instance()->lastClient(); it++){
... ...
......
...@@ -100,6 +100,11 @@ namespace onelab{ ...@@ -100,6 +100,11 @@ namespace onelab{
const std::string &getName() const { return _name; } const std::string &getName() const { return _name; }
const std::string &getLabel() const { return _label; } const std::string &getLabel() const { return _label; }
const std::string &getHelp() const { return _help; } 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 std::string getShortName() const
{ {
if(_label.size()) return _label; if(_label.size()) return _label;
...@@ -129,7 +134,7 @@ namespace onelab{ ...@@ -129,7 +134,7 @@ namespace onelab{
const std::set<std::string> &getClients() const { return _clients; } const std::set<std::string> &getClients() const { return _clients; }
static char charSep() { return '\0'; } static char charSep() { return '\0'; }
static double maxNumber() { return 1e200; } 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, static std::string getNextToken(const std::string &msg,
std::string::size_type &first, std::string::size_type &first,
char separator=charSep()) char separator=charSep())
...@@ -263,17 +268,21 @@ namespace onelab{ ...@@ -263,17 +268,21 @@ namespace onelab{
class number : public parameter{ class number : public parameter{
private: private:
double _value, _min, _max, _step; 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::vector<double> _choices;
std::map<double, std::string> _valueLabels; std::map<double, std::string> _valueLabels;
public: public:
number(const std::string &name="", double value=0., number(const std::string &name="", double value=0.,
const std::string &label="", const std::string &help="") const std::string &label="", const std::string &help="")
: parameter(name, label, help), _value(value), : 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 setValue(double value){ _value = value; }
void setMin(double min){ _min = min; } void setMin(double min){ _min = min; }
void setMax(double max){ _max = max; } void setMax(double max){ _max = max; }
void setStep(double step){ _step = step; } void setStep(double step){ _step = step; }
void setIndex(int index){ _index = index; }
void setChoices(const std::vector<double> &choices){ _choices = choices; } void setChoices(const std::vector<double> &choices){ _choices = choices; }
void setChoiceLabels(const std::vector<std::string> &labels) void setChoiceLabels(const std::vector<std::string> &labels)
{ {
...@@ -294,6 +303,7 @@ namespace onelab{ ...@@ -294,6 +303,7 @@ namespace onelab{
double getMin() const { return _min; } double getMin() const { return _min; }
double getMax() const { return _max; } double getMax() const { return _max; }
double getStep() const { return _step; } double getStep() const { return _step; }
int getIndex() const { return _index; }
const std::vector<double> &getChoices() const { return _choices; } const std::vector<double> &getChoices() const { return _choices; }
const std::map<double, std::string> &getValueLabels() const const std::map<double, std::string> &getValueLabels() const
{ {
...@@ -320,6 +330,7 @@ namespace onelab{ ...@@ -320,6 +330,7 @@ namespace onelab{
setMin(p.getMin()); setMin(p.getMin());
setMax(p.getMax()); setMax(p.getMax());
setStep(p.getStep()); setStep(p.getStep());
setIndex(p.getIndex());
setChoices(p.getChoices()); setChoices(p.getChoices());
setValueLabels(p.getValueLabels()); setValueLabels(p.getValueLabels());
} }
...@@ -328,6 +339,7 @@ namespace onelab{ ...@@ -328,6 +339,7 @@ namespace onelab{
std::ostringstream sstream; std::ostringstream sstream;
sstream << parameter::toChar() << _value << charSep() sstream << parameter::toChar() << _value << charSep()
<< _min << charSep() << _max << charSep() << _step << charSep() << _min << charSep() << _max << charSep() << _step << charSep()
<< _index << charSep()
<< _choices.size() << charSep(); << _choices.size() << charSep();
for(unsigned int i = 0; i < _choices.size(); i++) for(unsigned int i = 0; i < _choices.size(); i++)
sstream << _choices[i] << charSep(); sstream << _choices[i] << charSep();
...@@ -347,6 +359,7 @@ namespace onelab{ ...@@ -347,6 +359,7 @@ namespace onelab{
setMin(atof(getNextToken(msg, pos).c_str())); setMin(atof(getNextToken(msg, pos).c_str()));
setMax(atof(getNextToken(msg, pos).c_str())); setMax(atof(getNextToken(msg, pos).c_str()));
setStep(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())); _choices.resize(atoi(getNextToken(msg, pos).c_str()));
for(unsigned int i = 0; i < _choices.size(); i++) for(unsigned int i = 0; i < _choices.size(); i++)
_choices[i] = atof(getNextToken(msg, pos).c_str()); _choices[i] = atof(getNextToken(msg, pos).c_str());
...@@ -397,6 +410,9 @@ namespace onelab{ ...@@ -397,6 +410,9 @@ namespace onelab{
setChanged(true); setChanged(true);
} }
setChoices(p.getChoices()); setChoices(p.getChoices());
// FIXME: this will be handled differently
if(getName().find("/Action") != std::string::npos)
setChanged(false);
} }
std::string toChar() const std::string toChar() const
{ {
...@@ -692,9 +708,10 @@ namespace onelab{ ...@@ -692,9 +708,10 @@ namespace onelab{
std::set<parameter*> ps; std::set<parameter*> ps;
_getAllParameters(ps); _getAllParameters(ps);
for(std::set<parameter*>::iterator it = ps.begin(); it != ps.end(); it++){ 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 true;
} }
}
return false; return false;
} }
// set the changed flag for all parameters (optionnally only affect those // set the changed flag for all parameters (optionnally only affect those
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment