diff --git a/Common/onelab.h b/Common/onelab.h index 81d30acb6692bc7abd6fc5503f9f3a6c5b31457e..edb6f27d93c56b4e6181ef21faac11caeefa8002 100644 --- a/Common/onelab.h +++ b/Common/onelab.h @@ -379,6 +379,21 @@ namespace onelab{ std::string getName(){ return _name; } virtual bool run(const std::string &what){ return false; } virtual bool kill(){ return false; } + virtual void print(){} + virtual void sendInfo(const std::string &msg){ std::cout << msg << std::endl; } + virtual void sendWarning(const std::string &msg){ std::cerr << msg << std::endl; } + virtual void sendError(const std::string &msg){ std::cerr << msg << std::endl; } + virtual void sendProgress(const std::string &msg){ std::cout << msg << std::endl; } + virtual void sendMergeFileRequest(const std::string &msg){} + virtual void sendParseStringRequest(const std::string &msg){} + virtual bool set(number ¶meter, bool value=true){ return false; } + virtual bool set(string ¶meter, bool value=true){ return false; } + virtual bool set(region ¶meter, bool value=true){ return false; } + virtual bool set(function ¶meter, bool value=true){ return false; } + virtual bool get(std::vector<number> ¶meters, const std::string &name=""){ return false; } + virtual bool get(std::vector<string> ¶meters, const std::string &name=""){ return false; } + virtual bool get(std::vector<region> ¶meters, const std::string &name=""){ return false; } + virtual bool get(std::vector<function> ¶meters, const std::string &name=""){ return false; } }; // The onelab server: a singleton that stores the parameter space @@ -427,26 +442,34 @@ namespace onelab{ protected: // the pointer to the server server *_server; - public: - localClient(const std::string &name) : client(name) - { - _server = server::instance(); - _server->registerClient(this); - } - virtual ~localClient(){} - template <class T> bool set(T ¶meter, bool value=true) + template <class T> bool _set(T ¶meter, bool value=true) { parameter.addClient(_name); _server->set(parameter, value); return true; } - template <class T> bool get(std::vector<T> ¶meters, - const std::string &name="") + template <class T> bool _get(std::vector<T> ¶meters, + const std::string &name="") { _server->get(parameters, name); return true; } - void print(){ _server->print(); } + public: + localClient(const std::string &name) : client(name) + { + _server = server::instance(); + _server->registerClient(this); + } + virtual ~localClient(){} + virtual bool set(number &p, bool value=true){ return _set(p, value); } + virtual bool set(string &p, bool value=true){ return _set(p, value); } + virtual bool set(function &p, bool value=true){ return _set(p, value); } + virtual bool set(region &p, bool value=true){ return _set(p, value); } + virtual bool get(std::vector<number> &p, const std::string &name=""){ return _get(p, name); } + virtual bool get(std::vector<string> &p, const std::string &name=""){ return _get(p, name); } + virtual bool get(std::vector<function> &p, const std::string &name=""){ return _get(p, name); } + virtual bool get(std::vector<region> &p, const std::string &name=""){ return _get(p, name); } + virtual void print(){ _server->print(); } }; class localNetworkClient : public localClient{ @@ -470,29 +493,7 @@ namespace onelab{ std::string _serverAddress; // underlying GmshClient GmshClient *_gmshClient; - public: - remoteNetworkClient(const std::string &name, const std::string &serverAddress) - : client(name), _serverAddress(serverAddress) - { - _gmshClient = new GmshClient(); - if(_gmshClient->Connect(_serverAddress.c_str()) < 0){ - delete _gmshClient; - _gmshClient = 0; - } - else{ - _gmshClient->Start(); - } - } - virtual ~remoteNetworkClient() - { - if(_gmshClient){ - _gmshClient->Stop(); - _gmshClient->Disconnect(); - delete _gmshClient; - _gmshClient = 0; - } - } - template <class T> bool set(T ¶meter) + template <class T> bool _set(T ¶meter) { if(!_gmshClient) return false; parameter.addClient(_name); @@ -500,8 +501,8 @@ namespace onelab{ _gmshClient->SendMessage(GmshSocket::GMSH_PARAMETER, msg.size(), &msg[0]); return true; } - template <class T> bool get(std::vector<T> ¶meters, - const std::string &name="") + template <class T> bool _get(std::vector<T> ¶meters, + const std::string &name="") { if(!_gmshClient) return false; T parameter(name); @@ -535,6 +536,10 @@ namespace onelab{ parameters.push_back(p); return true; } + else if(type == GmshSocket::GMSH_INFO){ + // parameter not found + return true; + } else{ _gmshClient->Error("Unknown message type: aborting remote get"); return false; @@ -542,6 +547,36 @@ namespace onelab{ } return true; } + public: + remoteNetworkClient(const std::string &name, const std::string &serverAddress) + : client(name), _serverAddress(serverAddress) + { + _gmshClient = new GmshClient(); + if(_gmshClient->Connect(_serverAddress.c_str()) < 0){ + delete _gmshClient; + _gmshClient = 0; + } + else{ + _gmshClient->Start(); + } + } + virtual ~remoteNetworkClient() + { + if(_gmshClient){ + _gmshClient->Stop(); + _gmshClient->Disconnect(); + delete _gmshClient; + _gmshClient = 0; + } + } + virtual bool set(number &p, bool value=true){ return _set(p); } + virtual bool set(string &p, bool value=true){ return _set(p); } + virtual bool set(function &p, bool value=true){ return _set(p); } + virtual bool set(region &p, bool value=true){ return _set(p); } + virtual bool get(std::vector<number> &p, const std::string &name=""){ return _get(p, name); } + virtual bool get(std::vector<string> &p, const std::string &name=""){ return _get(p, name); } + virtual bool get(std::vector<function> &p, const std::string &name=""){ return _get(p, name); } + virtual bool get(std::vector<region> &p, const std::string &name=""){ return _get(p, name); } void sendInfo(const std::string &msg){ _gmshClient->Info(msg.c_str()); } void sendWarning(const std::string &msg){ _gmshClient->Warning(msg.c_str()); } void sendError(const std::string &msg){ _gmshClient->Error(msg.c_str()); } diff --git a/Fltk/onelabWindow.cpp b/Fltk/onelabWindow.cpp index 0ca9fdd8d5d5d2d2e7f07cf5d0fcdbf9041c3644..b3c028fe06d23a56e2537f4043fcb64a176d94b5 100644 --- a/Fltk/onelabWindow.cpp +++ b/Fltk/onelabWindow.cpp @@ -136,10 +136,14 @@ bool onelab::localNetworkClient::run(const std::string &what) if(type == "number"){ std::vector<onelab::number> par; get(par, name); - std::string reply; - if(par.size() == 1) reply = par[0].toChar(); - else reply = message; - server->SendMessage(GmshSocket::GMSH_PARAMETER, reply.size(), &reply[0]); + if(par.size() == 1){ + std::string reply = par[0].toChar(); + server->SendMessage(GmshSocket::GMSH_PARAMETER, reply.size(), &reply[0]); + } + else{ + std::string reply = "Parameter " + name + " not found"; + server->SendMessage(GmshSocket::GMSH_INFO, reply.size(), &reply[0]); + } } } break; @@ -203,12 +207,19 @@ void onelab_cb(Fl_Widget *w, void *data) onelab::client *c = it->second; c->run("/Users/geuzaine/src/getdp/demos/test.pro"); } + printf("**** ONELAB DB DUMP:\n"); + onelab::server::instance()->print(); + printf("**** \n"); FlGui::instance()->onelab->rebuildTree(); FlGui::instance()->onelab->show(); } void onelab_compute_cb(Fl_Widget *w, void *data) { + printf("**** ONELAB DB DUMP:\n"); + onelab::server::instance()->print(); + printf("**** \n"); + for(onelab::server::citer it = onelab::server::instance()->firstClient(); it != onelab::server::instance()->lastClient(); it++){ onelab::client *c = it->second; @@ -256,7 +267,11 @@ void number_cb(Fl_Widget *w, void *data) void onelabWindow::rebuildTree() { + printf("rebulding tree\n"); _tree->clear(); + for(unsigned int i = 0; i < _treeWidgets.size(); i++) + delete _treeWidgets[i]; + _treeWidgets.clear(); std::vector<onelab::number> numbers; onelab::server::instance()->get(numbers); @@ -265,6 +280,7 @@ void onelabWindow::rebuildTree() 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); + _treeWidgets.push_back(but); but->copy_label(numbers[i].getName().c_str()); but->value(numbers[i].getValue()); but->minimum(0.); diff --git a/Fltk/onelabWindow.h b/Fltk/onelabWindow.h index 6c694cbb22376a31e089f902499b4234ef406e57..2d35d82b76e8c7e6df5275bf8bb311b94a404bdf 100644 --- a/Fltk/onelabWindow.h +++ b/Fltk/onelabWindow.h @@ -19,6 +19,7 @@ class onelabWindow{ Fl_Window *_win; Fl_Tree *_tree; Fl_Button *_run; + std::vector<Fl_Widget*> _treeWidgets; public: onelabWindow(int deltaFontSize=0); void rebuildTree();