diff --git a/Common/onelab.h b/Common/onelab.h index cfd5c3097839e216bcb00285ae30e25566083740..81d30acb6692bc7abd6fc5503f9f3a6c5b31457e 100644 --- a/Common/onelab.h +++ b/Common/onelab.h @@ -196,6 +196,7 @@ namespace onelab{ _defaultValue(defaultValue) { } + void setValue(const std::string &value){ _value = value; } std::string getType() const { return "region"; } const std::string &getValue() const { return _value; } const std::string &getDefaultValue() const { return _defaultValue; } @@ -281,22 +282,21 @@ namespace onelab{ std::set<region*, parameterLessThan> _regions; std::set<function*, parameterLessThan> _functions; // set a parameter in the parameter space; if it already exists, - // use the new value but make sure to add 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 - template <class T> bool _set(T &p, std::set<T*, parameterLessThan> ¶meters) + // add 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 + template <class T> bool _set(T &p, std::set<T*, parameterLessThan> ¶meters, + bool value=true) { - std::set<std::string> clients; typename std::set<T*, parameterLessThan>::iterator it = parameters.find(&p); if(it != parameters.end()){ - parameters.erase(it); - T* oldp = *it; - clients = oldp->getClients(); - delete oldp; + std::set<std::string> clients = p.getClients(); + (*it)->addClients(clients); + if(value) (*it)->setValue(p.getValue()); + } + else{ + parameters.insert(new T(p)); } - T* newp = new T(p); - newp->addClients(clients); - parameters.insert(newp); return true; } // get the parameter matching the given name, or all the @@ -334,10 +334,10 @@ namespace onelab{ it != _functions.end(); it++) delete *it; } - bool set(number &p){ return _set(p, _numbers); } - bool set(string &p){ return _set(p, _strings); } - bool set(region &p){ return _set(p, _regions); } - bool set(function &p){ return _set(p, _functions); } + bool set(number &p, bool value=true){ return _set(p, _numbers, value); } + bool set(string &p, bool value=true){ return _set(p, _strings, value); } + bool set(region &p, bool value=true){ return _set(p, _regions, value); } + bool set(function &p, bool value=true){ return _set(p, _functions, value); } bool get(std::vector<number> &p, const std::string &name="") { return _get(p, name, _numbers); @@ -401,9 +401,9 @@ namespace onelab{ if(!_server) _server = new server(address); return _server; } - template <class T> bool set(T &p) + template <class T> bool set(T &p, bool value=true) { - return _parameterSpace.set(p); + return _parameterSpace.set(p, value); } template <class T> bool get(std::vector<T> &p, const std::string &name="") { @@ -434,10 +434,10 @@ namespace onelab{ _server->registerClient(this); } virtual ~localClient(){} - template <class T> bool set(T ¶meter) + template <class T> bool set(T ¶meter, bool value=true) { parameter.addClient(_name); - _server->set(parameter); + _server->set(parameter, value); return true; } template <class T> bool get(std::vector<T> ¶meters, diff --git a/Fltk/onelabWindow.cpp b/Fltk/onelabWindow.cpp index 62abd4cbf9169a4e068ce634134083691263953c..690bd11bb6f160dd9871b43c99dfea55d84ba4e6 100644 --- a/Fltk/onelabWindow.cpp +++ b/Fltk/onelabWindow.cpp @@ -15,6 +15,8 @@ #include "menuWindow.h" #include "onelabWindow.h" +#include <FL/Fl_Value_Input.H> + // This file contains the Gmsh/FLTK specific parts of the ONELAB // interface. You'll need to reimplement this if you plan to build // a different ONELAB server. @@ -122,7 +124,7 @@ bool onelab::localNetworkClient::run(const std::string &what) if(type == "number"){ onelab::number par; par.fromChar(message); - set(par); + set(par, false); printf("gmsh got '%s' from %s\n", par.toChar().c_str(), _name.c_str()); } } @@ -201,6 +203,7 @@ void onelab_cb(Fl_Widget *w, void *data) onelab::client *c = it->second; c->run("/Users/geuzaine/src/getdp/demos/test.pro"); } + FlGui::instance()->onelab->rebuildTree(); FlGui::instance()->onelab->show(); } @@ -239,3 +242,47 @@ onelabWindow::onelabWindow(int deltaFontSize) onelab::server::instance()->registerClient(new onelab::localNetworkClient ("getdp", "/Users/geuzaine/src/getdp/bin/getdp")); } + +void number_cb(Fl_Widget *w, void *data) +{ + Fl_Value_Input *v = (Fl_Value_Input*)w; + std::vector<onelab::number> numbers; + onelab::server::instance()->get(numbers, v->label()); + if(numbers.size()){ + numbers[0].setValue(v->value()); + onelab::server::instance()->set(numbers[0]); + } + FlGui::instance()->onelab->redrawTree(); +} + +void onelabWindow::rebuildTree() +{ + _tree->clear(); + + std::vector<onelab::number> numbers; + onelab::server::instance()->get(numbers); + + for(unsigned int i = 0; i < numbers.size(); i++){ + Fl_Tree_Item *n = _tree->add(numbers[i].getName().c_str()); + _tree->begin(); + Fl_Value_Input *but = new Fl_Value_Input(1,1,IW,1); + but->copy_label(numbers[i].getName().c_str()); + but->value(numbers[i].getValue()); + but->minimum(0.); + but->maximum(10.); + but->step(0.1); + but->align(FL_ALIGN_RIGHT); + but->callback(number_cb); + n->widget(but); + _tree->end(); + } + + _tree->redraw(); + //n->user_data((void*)gv); + //n->close(); +} + +void onelabWindow::redrawTree() +{ + _tree->redraw(); +} diff --git a/Fltk/onelabWindow.h b/Fltk/onelabWindow.h index c723229c028b80bfaffce364bff1c2e54410b20b..284c32c1c5201fb6eba03aa1c239df78a6ba7448 100644 --- a/Fltk/onelabWindow.h +++ b/Fltk/onelabWindow.h @@ -19,6 +19,8 @@ class onelabWindow{ Fl_Button *_run; public: onelabWindow(int deltaFontSize=0); + void rebuildTree(); + void redrawTree(); void show(){ _win->show(); } };