diff --git a/Common/Gmsh.cpp b/Common/Gmsh.cpp index 2628b3d73e8a6d989f33887b27d970c19333cea4..cf3799412d3c85845480688e1379f83fcc7bd18f 100644 --- a/Common/Gmsh.cpp +++ b/Common/Gmsh.cpp @@ -254,7 +254,7 @@ int GmshFLTK(int argc, char **argv) #if defined(HAVE_ONELAB) if(CTX::instance()->solver.listen){ onelab::localNetworkClient *c = new onelab::localNetworkClient("Listen", ""); - c->run(""); + c->run(); } #endif diff --git a/Common/onelab.h b/Common/onelab.h index 1c8a0c23da47e7b4d485f5067370604448ac7323..17511aad9298f2f2045c55f708e7c2353fd9276d 100644 --- a/Common/onelab.h +++ b/Common/onelab.h @@ -91,6 +91,19 @@ namespace onelab{ const std::string &getName() const { return _name; } const std::string &getShortHelp() const { return _shortHelp; } const std::string &getHelp() const { return _help; } + std::string getShortName() const + { + if(_shortHelp.size()) return _shortHelp; + std::string s = _name; + // remove path + std::string::size_type last = _name.find_last_of('/'); + if(last != std::string::npos) + s = _name.substr(last + 1); + // remove starting numbers + while(s.size() && s[0] >= '0' && s[0] <= '9') + s = s.substr(1); + return s; + } bool getChanged() const { return _changed; } bool getVisible() const { return _visible; } std::string getAttribute(const std::string &key) const @@ -567,7 +580,7 @@ namespace onelab{ int getId(){ return _id; } void setIndex(int index){ _index = index; } int getIndex(){ return _index; } - virtual bool run(const std::string &what){ return false; } + virtual bool run(){ return false; } virtual bool isNetworkClient(){ return false; } virtual bool kill(){ return false; } virtual void sendInfo(const std::string &msg){ std::cout << msg << std::endl; } @@ -700,7 +713,7 @@ namespace onelab{ void setPid(int pid){ _pid = pid; } GmshServer *getGmshServer(){ return _gmshServer; } void setGmshServer(GmshServer *server){ _gmshServer = server; } - virtual bool run(const std::string &what); + virtual bool run(); virtual bool kill(); }; diff --git a/Fltk/menuWindow.cpp b/Fltk/menuWindow.cpp index c22b25c226d5d91caadb9d5e52c451f67175528f..99e63d1ac6fd5a90ae0f0f291af77d7a836a770f 100644 --- a/Fltk/menuWindow.cpp +++ b/Fltk/menuWindow.cpp @@ -197,7 +197,7 @@ static void file_remote_cb(Fl_Widget *w, void *data) return; } c->setCommandLine(connectionChooser()); - if(c->getCommandLine().size()) c->run(""); + if(c->getCommandLine().size()) c->run(); } else{ if(!server){ diff --git a/Fltk/onelabWindow.cpp b/Fltk/onelabWindow.cpp index 0c7359dc196627a13a76f9a1ed6d8820f8e29f92..03a375acc20c4354d4f05876085f643bd5948efc 100644 --- a/Fltk/onelabWindow.cpp +++ b/Fltk/onelabWindow.cpp @@ -83,7 +83,7 @@ class onelabGmshServer : public GmshServer{ } }; -bool onelab::localNetworkClient::run(const std::string &what) +bool onelab::localNetworkClient::run() { new_connection: _pid = 0; @@ -109,7 +109,17 @@ bool onelab::localNetworkClient::run(const std::string &what) std::string command = FixWindowsPath(_commandLine); if(command.size()){ - command += " " + what + " " + _socketSwitch + " "; + // FIXME hack for getdp: this should be removed + std::vector<onelab::string> ps; + get(ps, getName() + "/1ModelName"); + if(ps.size()) command += " " + ps[0].getValue(); + get(ps, getName() + "/Action"); + if(ps.size() && ps[0].getValue() == "compute"){ + get(ps, getName() + "/9Compute"); + if(ps.size()) command += " " + ps[0].getValue(); + } + // end hack for getdp + command += " " + _socketSwitch + " "; } else{ Msg::Info("Listening on socket '%s'", sockname.c_str()); @@ -181,7 +191,7 @@ bool onelab::localNetworkClient::run(const std::string &what) set(p); } else - Msg::Error("FIXME not done for this parameter types: %s", type.c_str()); + Msg::Error("FIXME not done for this parameter type: %s", type.c_str()); } break; case GmshSocket::GMSH_PARAMETER_QUERY: @@ -199,7 +209,7 @@ bool onelab::localNetworkClient::run(const std::string &what) if(par.size() == 1) reply = par[0].toChar(); } else - Msg::Fatal("FIXME query not done for this parameter type"); + Msg::Error("FIXME not done for this parameter type: %s", type.c_str()); if(reply.size()){ server->SendMessage(GmshSocket::GMSH_PARAMETER, reply.size(), &reply[0]); } @@ -339,21 +349,19 @@ static std::string getMshFileName(onelab::client *c) } } -static std::string getModelName(onelab::client *c) +static void guessModelName(onelab::client *c) { std::vector<onelab::string> ps; c->get(ps, c->getName() + "/1ModelName"); - if(ps.size()){ - return ps[0].getValue(); - } - else{ + if(ps.empty()){ std::vector<std::string> split = SplitFileName(GModel::current()->getFileName()); - std::string ext = FlGui::instance()->onelab->getModelExtension(); + std::string ext = ""; + onelab::server::instance()->get(ps, c->getName() + "/FileExtension"); + if(ps.size()) ext = ps[0].getValue(); std::string name(split[0] + split[1] + ext); onelab::string o(c->getName() + "/1ModelName", name, "Model name"); o.setKind("file"); c->set(o); - return name; } } @@ -463,20 +471,6 @@ static std::vector<double> getRange(onelab::number &p) return v; } -static std::string getShortName(const std::string &name, const std::string &ok="") -{ - if(ok.size()) return ok; - std::string s = name; - // remove path - std::string::size_type last = name.find_last_of('/'); - if(last != std::string::npos) - s = name.substr(last + 1); - // remove starting numbers - while(s.size() && s[0] >= '0' && s[0] <= '9') - s = s.substr(1); - return s; -} - static bool updateOnelabGraph(int num) { bool changed = false; @@ -497,11 +491,11 @@ static bool updateOnelabGraph(int num) v.resize(8, '0'); if(v[2 * num] == '1'){ x = getRange(numbers[i]); - xName = getShortName(numbers[i].getName(), numbers[i].getShortHelp()); + xName = numbers[i].getShortName(); } if(v[2 * num + 1] == '1'){ y = getRange(numbers[i]); - yName = getShortName(numbers[i].getName(), numbers[i].getShortHelp()); + yName = numbers[i].getShortName(); } } if(x.empty()){ @@ -532,6 +526,7 @@ static void updateOnelabGraphs() static void runGmshClient(const std::string &action) { + if(action == "initialize") return; onelab::server::citer it = onelab::server::instance()->findClient("Gmsh"); if(it == onelab::server::instance()->lastClient()) return; @@ -646,7 +641,7 @@ void onelab_cb(Fl_Widget *w, void *data) FlGui::instance()->onelab->checkForErrors("Gmsh"); if(FlGui::instance()->onelab->stop()) break; - // iterate over all other clients + // iterate over all other clients (there should narmally only be one) for(onelab::server::citer it = onelab::server::instance()->firstClient(); it != onelab::server::instance()->lastClient(); it++){ onelab::client *c = it->second; @@ -654,31 +649,11 @@ void onelab_cb(Fl_Widget *w, void *data) c->getName() == "Listen" || // unknown client connecting through "-listen" c->getName() == "GmshRemote") // distant post-processing Gmsh client continue; - std::string what = getModelName(c); - //onelab::string o(c->getName() + "/action", action); - //o.setVisible(false); - //onelab::server::instance()->set(o); - // FIXME this should be uniformized (probably just be setting a onelab - // variable to "check" or "compute", and letting the client decide what to - // do) - if(action == "check"){ - if(c->getName() == "GetDP") // client name as defined in getdp/Common/Message.cpp::InitializeOnelab() - c->run(what); - else - c->run(what + " -a "); // '-a' for 'analyse only' - } - else if(action == "compute"){ - if(c->getName() == "GetDP"){ - // get command line from the server - std::vector<onelab::string> ps; - onelab::server::instance()->get(ps, c->getName() + "/9Compute"); - if(ps.size()) what += " " + ps[0].getValue(); - c->run(what); - } - else - c->run(what); - } - + if(action != "initialize") guessModelName(c); + onelab::string o(c->getName() + "/Action", action); + o.setVisible(false); + onelab::server::instance()->set(o); + c->run(); if(action == "compute") FlGui::instance()->onelab->checkForErrors(c->getName()); if(FlGui::instance()->onelab->stop()) break; @@ -859,7 +834,7 @@ void onelabWindow::rebuildTree() for(unsigned int i = 0; i < numbers.size(); i++){ Fl_Tree_Item *n = _tree->add(numbers[i].getName().c_str()); n->labelsize(FL_NORMAL_SIZE + 5); - std::string label = getShortName(numbers[i].getName(), numbers[i].getShortHelp()); + std::string label = numbers[i].getShortName(); _tree->begin(); if(numbers[i].getChoices().size() == 2 && numbers[i].getChoices()[0] == 0 && numbers[i].getChoices()[1] == 1){ @@ -895,7 +870,7 @@ void onelabWindow::rebuildTree() for(unsigned int i = 0; i < strings.size(); i++){ Fl_Tree_Item *n = _tree->add(strings[i].getName().c_str()); n->labelsize(FL_NORMAL_SIZE + 5); - std::string label = getShortName(strings[i].getName(), strings[i].getShortHelp()); + std::string label = strings[i].getShortName(); _tree->begin(); Fl_Input_Choice *but = new Fl_Input_Choice(1, 1, width, 1); _treeWidgets.push_back(but); @@ -930,7 +905,8 @@ void onelabWindow::rebuildTree() Fl_Box *but = new Fl_Box(1, 1, width, 1); but->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); _treeWidgets.push_back(but); - but->copy_label(getShortName(n->label()).c_str()); + onelab::string o(n->label()); + but->copy_label(o.getShortName().c_str()); n->widget(but); _tree->end(); } @@ -1029,8 +1005,6 @@ void onelabWindow::addSolver(const std::string &name, const std::string &command opt_solver_name(index, GMSH_SET, name); if(commandLine.empty()) onelab_choose_executable_cb(0, (void *)c); - if(name == "GetDP") - setModelExtension(".pro"); } FlGui::instance()->onelab->rebuildSolverList(); } @@ -1057,10 +1031,18 @@ void solver_cb(Fl_Widget *w, void *data) int num = (intptr_t)data; if(num >= 0){ - // FIXME: unregister any non-local clients from the onelab::server + // unregister all non-local clients + for(onelab::server::citer it = onelab::server::instance()->firstClient(); + it != onelab::server::instance()->lastClient(); it++){ + onelab::client *c = it->second; + if(c->isNetworkClient()) + onelab::server::instance()->unregisterClient(c); + } + // register new client std::string name = opt_solver_name(num, GMSH_GET, ""); std::string exe = opt_solver_executable(num, GMSH_GET, ""); FlGui::instance()->onelab->addSolver(name, exe, num); + onelab_cb(0, (void*)"initialize"); } else FlGui::instance()->onelab->rebuildSolverList(); @@ -1071,7 +1053,8 @@ void solver_cb(Fl_Widget *w, void *data) #else #if defined(HAVE_ONELAB) -bool onelab::localNetworkClient::run(const std::string &what) + +bool onelab::localNetworkClient::run() { Msg::Error("The solver interface requires OneLab and FLTK 1.3"); return false; diff --git a/Fltk/onelabWindow.h b/Fltk/onelabWindow.h index 9e05992cef07aedb9801f2019db206a0733278f8..55a9c09493c5f405cb76e8d4bc0567fd85d2b587 100644 --- a/Fltk/onelabWindow.h +++ b/Fltk/onelabWindow.h @@ -26,7 +26,6 @@ class onelabWindow{ int _gearFrozenMenuSize; std::vector<Fl_Widget*> _treeWidgets; std::string _title; - std::string _modelExtension; int _deltaFontSize; bool _stop; public: @@ -39,8 +38,6 @@ class onelabWindow{ void setButtonMode(const std::string &mode); void show(){ _win->show(); } int shown(){ return _win->shown(); } - std::string getModelExtension(){ return _modelExtension; } - void setModelExtension(const std::string &ext){ _modelExtension = ext; } int meshAuto(){ return _gear->menu()[2].value(); } int hideNewViews(){ return _gear->menu()[3].value(); } std::string getPath(Fl_Tree_Item *item) diff --git a/Fltk/optionWindow.cpp b/Fltk/optionWindow.cpp index a935f391a838bc9bffd5108542bb91eacb6b0ba6..0b0c7dd73f6abfbdf929fb4af3e98c0f87a714b9 100644 --- a/Fltk/optionWindow.cpp +++ b/Fltk/optionWindow.cpp @@ -525,10 +525,10 @@ static void solver_options_ok_cb(Fl_Widget *w, void *data) onelab::server::citer it = onelab::server::instance()->findClient("Listen"); if(it == onelab::server::instance()->lastClient()){ onelab::localNetworkClient *c = new onelab::localNetworkClient("Listen", ""); - c->run(""); + c->run(); } else - it->second->run(""); + it->second->run(); } #endif