Skip to content
Snippets Groups Projects
Commit faf88978 authored by Francois Henrotte's avatar Francois Henrotte
Browse files

loop index stored in onelab::number

parent c4b47a4d
No related branches found
No related tags found
No related merge requests found
...@@ -268,17 +268,21 @@ namespace onelab{ ...@@ -268,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)
{ {
...@@ -299,6 +303,7 @@ namespace onelab{ ...@@ -299,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
{ {
...@@ -325,6 +330,7 @@ namespace onelab{ ...@@ -325,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());
} }
...@@ -333,6 +339,7 @@ namespace onelab{ ...@@ -333,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();
...@@ -352,6 +359,7 @@ namespace onelab{ ...@@ -352,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());
...@@ -402,6 +410,8 @@ namespace onelab{ ...@@ -402,6 +410,8 @@ namespace onelab{
setChanged(true); setChanged(true);
} }
setChoices(p.getChoices()); setChoices(p.getChoices());
if(getName().find("/Action") != std::string::npos)
setChanged(false);
} }
std::string toChar() const std::string toChar() const
{ {
......
...@@ -100,8 +100,10 @@ namespace onelabUtils { ...@@ -100,8 +100,10 @@ namespace onelabUtils {
std::vector<onelab::number> numbers; std::vector<onelab::number> numbers;
onelab::server::instance()->get(numbers); onelab::server::instance()->get(numbers);
for(unsigned int i = 0; i < numbers.size(); i++){ for(unsigned int i = 0; i < numbers.size(); i++){
if(numbers[i].getAttribute("Loop") == level){ if(numbers[i].getAttribute("Loop") == level){
if(numbers[i].getChoices().size() > 1){ if(numbers[i].getChoices().size() > 1){
numbers[i].setIndex(0);
numbers[i].setValue(numbers[i].getChoices()[0]); numbers[i].setValue(numbers[i].getChoices()[0]);
onelab::server::instance()->set(numbers[i]); onelab::server::instance()->set(numbers[i]);
changed = true; changed = true;
...@@ -139,20 +141,30 @@ namespace onelabUtils { ...@@ -139,20 +141,30 @@ namespace onelabUtils {
loop = true; loop = true;
if(numbers[i].getChoices().size() > 1){ if(numbers[i].getChoices().size() > 1){
// FIXME should store loopVariable attribute in the parameter int j=numbers[i].getIndex();
// -- the following test will loop forever if 2 values are if((j>=0) && (j < numbers[i].getChoices().size())){
// identical in the list of choices numbers[i].setValue(numbers[i].getChoices()[j]);
std::vector<double> choices(numbers[i].getChoices()); numbers[i].setIndex(j+1);
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]); onelab::server::instance()->set(numbers[i]);
Msg::Info("Recomputing with new choice %s=%g", 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;
break;
}
} }
// 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() &&
......
...@@ -530,9 +530,13 @@ void onelab_cb(Fl_Widget *w, void *data) ...@@ -530,9 +530,13 @@ void onelab_cb(Fl_Widget *w, void *data)
o.setVisible(false); o.setVisible(false);
onelab::server::instance()->set(o); onelab::server::instance()->set(o);
c->run(); c->run();
if(action == "compute") if(action == "compute"){
FlGui::instance()->onelab->checkForErrors(c->getName()); FlGui::instance()->onelab->checkForErrors(c->getName());
if(metamodel)
onelab::server::instance()->setChanged(false,c->getName());
}
if(FlGui::instance()->onelab->stop()) break; if(FlGui::instance()->onelab->stop()) break;
} }
// update geometry which might have been changed by the metamodel // update geometry which might have been changed by the metamodel
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment