diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp index 89992cf7894ff144a32e00626f94c95c48dffc33..cff7a6740c916b1cfcb48b45a1fd0a2df62d529a 100644 --- a/Fltk/FlGui.cpp +++ b/Fltk/FlGui.cpp @@ -31,6 +31,7 @@ typedef unsigned long intptr_t; #include "contextWindow.h" #ifdef HAVE_ONELAB2 #include "onelab2Group.h" +#include "OnelabWindow.h" #else #include "onelabGroup.h" #endif @@ -78,8 +79,7 @@ static int globalShortcut(int event) int FlGui::lock() { _in_main_thread++; - Fl::lock(); - return _in_main_thread; + return Fl::lock(); } void FlGui::unlock() @@ -429,6 +429,9 @@ FlGui::FlGui(int argc, char **argv) // create all other windows options = new optionWindow(CTX::instance()->deltaFontSize); +#if defined(HAVE_ONELAB2) + onelab2 = new onelabWindow(); +#endif fields = new fieldWindow(CTX::instance()->deltaFontSize); plugins = new pluginWindow(CTX::instance()->deltaFontSize); stats = new statisticsWindow(CTX::instance()->deltaFontSize); diff --git a/Fltk/FlGui.h b/Fltk/FlGui.h index 9ac35b56d0bb75499b3ebd91955c9ed763c7e7f8..ce676b00250bd6c9af7fbd1ac151e19d24d66f81 100644 --- a/Fltk/FlGui.h +++ b/Fltk/FlGui.h @@ -22,6 +22,7 @@ class graphicWindow; class openglWindow; class optionWindow; +class onelabWindow; class fieldWindow; class pluginWindow; class statisticsWindow; @@ -59,6 +60,7 @@ class FlGui{ public: std::vector<graphicWindow*> graph; optionWindow *options; + onelabWindow *onelab2; fieldWindow *fields; pluginWindow *plugins; statisticsWindow *stats; diff --git a/Fltk/onelab2Group.cpp b/Fltk/onelab2Group.cpp index 6a30dfe1390ef08fc042e6c9b29dc1f843d84ce9..a53162053728da4de30e2192f66d162346d397de 100644 --- a/Fltk/onelab2Group.cpp +++ b/Fltk/onelab2Group.cpp @@ -23,7 +23,7 @@ static void updateGraphs() { - bool redraw = true;//FIXME false; + bool redraw = true; //FIXME false; for(int i = 0; i < 18; i++){ std::ostringstream tmp; tmp << i; @@ -72,13 +72,19 @@ void onelab_cb(Fl_Widget *w, void *data) if(!data) return; std::string action((const char*)data); - Msg::Info("Try to %s", action.c_str()); if(action == "refresh"){ updateGraphs(); return; } + if(action == "stop"){ // TODO send stop if server is not local + //FlGui::instance()->onelab->stop(true); + FlGui::instance()->onelab->setButtonMode("", ""); // wait for the client to stop + OnelabServer::instance()->stopClients(); + return; + } + if(FlGui::instance()->onelab->isBusy()){ Msg::Info("I'm busy! Ask me that later..."); return; @@ -86,7 +92,10 @@ void onelab_cb(Fl_Widget *w, void *data) if(action == "reset"){ OnelabDatabase::instance()->clear(); // TODO keep persitant - return; + OnelabDatabase::instance()->run(action, "Gmsh"); + FlGui::instance()->onelab->clearTree(true); + + action = "check"; } Msg::ResetErrorCounter(); @@ -95,8 +104,6 @@ void onelab_cb(Fl_Widget *w, void *data) OnelabDatabase::instance()->run(action); drawContext::global()->draw(); - - FlGui::instance()->onelab->setButtonMode("check", "compute"); } void onelab_option_cb(Fl_Widget *w, void *data) @@ -122,7 +129,7 @@ void onelab_option_cb(Fl_Widget *w, void *data) CTX::instance()->solver.autoShowLastStep = val; else if(what == "invisible"){ CTX::instance()->solver.showInvisibleParameters = val; - FlGui::instance()->onelab->rebuildTree(true); + //FlGui::instance()->onelab->rebuildTree(true); } } @@ -135,6 +142,7 @@ void solver_cb(Fl_Widget *w, void *data) int num = (intptr_t)data; if(num >= 0){ + onelab_cb(0, (void*)"reset"); std::string name = opt_solver_name(num, GMSH_GET, ""); if(name.empty()) return;// TODO std::string exe = opt_solver_executable(num, GMSH_GET, ""); @@ -190,7 +198,7 @@ onelabGroup::onelabGroup(int x, int y, int w, int h, const char *l) int dw = Fl::box_dw(box()); int dh = Fl::box_dh(box()); - _tree = new Fl_Tree(x + dx, y + dy + 6*BH, w - dw, h - dh - BH - 2 * WB - 6*BH); + _tree = new Fl_Tree(x + dx, y + dy, w - dw, h - dh - BH - 2 * WB - 6*BH); _tree->color(col); // TODO _tree->callback(onelab_tree_cb); _tree->connectorstyle(FL_TREE_CONNECTOR_SOLID); @@ -200,20 +208,6 @@ onelabGroup::onelabGroup(int x, int y, int w, int h, const char *l) _tree->add("0Post-processing/"); _tree->end(); - - Fl_Check_Button *useServer = new Fl_Check_Button(x+WB, y, w-2*WB, BH, "Use a remote server"); - useServer->callback(useserver_cb, this); - new Fl_Box(x+WB , y+BH, w-2*WB, BH, "Server IP address:"); - server_ip = new Fl_Input(x+WB, y+2*BH, w-2*WB, BH, ""); - server_ip->value("127.0.0.1"); - server_ip->readonly(true); - new Fl_Box(x+WB , y+3*BH, w-2*WB, BH, "Server port:"); - server_port = new Fl_Input(x+WB, y+4*BH, w-2*WB, BH, ""); - server_port->value("1148"); - server_port->readonly(true); - Fl_Button *connect_btn = new Fl_Button(x+WB, y+5*BH, w-2*WB, BH, "Connect"); - connect_btn->callback(connect_cb, this); - _computeWidths(); _widgetLabelRatio = 0.48; @@ -296,6 +290,7 @@ void onelabGroup::clearTree(bool deleteWidgets) for(unsigned int i = 0; i < delStrings.size(); i++) free(delStrings[i]); } + _tree->redraw(); } void onelabGroup::openTreeItem(const std::string &name) @@ -430,7 +425,7 @@ void onelabGroup::rebuildSolverList() } setButtonVisibility(); - rebuildTree(true); + //refreshTree(true); } void onelabGroup::addSolver(const std::string &name, const std::string &executable, @@ -480,6 +475,7 @@ void onelabGroup::addParameter(onelab::parameter &p) Fl_Color c; if(getFlColor(p.getAttribute("Highlight"), c)) highlight = true; Fl_Tree_Item *n = _tree->add(p.getName().c_str()); + if(!n) return; n->labelsize(FL_NORMAL_SIZE + 4); _tree->begin(); int ww = _baseWidth - (n->depth() + 1) * _indent; @@ -533,20 +529,22 @@ static void setGmshOption(T &n) { std::string opt = n.getAttribute("GmshOption"); if(opt.empty()) return; - /*if(opt == "ResetDatabase"){ // special option to reset the onelab db - resetDb(false); - FlGui::instance()->rebuildTree(false); + if(opt == "ResetDatabase"){ // special option to reset the onelab db + OnelabDatabase::instance()->clear(); + //TODO OnelabDatabase::instance()->reset(false); + //FlGui::instance()->rebuildTree(false); return; } if(opt == "Reset"){ // reset db + models except current one - resetDb(false); - for(int i = PView::list.size() - 1; i >= 0; i--) - delete PView::list[i]; - for(int i = GModel::list.size() - 1; i >= 0; i--) - if(GModel::list[i] != GModel::current()) delete GModel::list[i]; - FlGui::instance()->rebuildTree(false); + OnelabDatabase::instance()->clear(); + //TODO OnelabDatabase::instance()->reset(false); + //for(int i = PView::list.size() - 1; i >= 0; i--) + // delete PView::list[i]; + //for(int i = GModel::list.size() - 1; i >= 0; i--) + // if(GModel::list[i] != GModel::current()) delete GModel::list[i]; + //FlGui::instance()->rebuildTree(false); return; - }*/ + } std::string::size_type dot = opt.find('.'); if(dot == std::string::npos) return; GmshSetOption(opt.substr(0, dot), opt.substr(dot + 1), n.getValue()); @@ -1001,10 +999,13 @@ void onelabGroup::_addSolverMenu(int num) void onelabGroup::_addViewMenu(int num) { - // FIXME SEGFAULT in n->depth() with pend.py std::ostringstream path; path << "0Post-processing/View" << num; - Fl_Tree_Item *n = _tree->add(path.str().c_str()); + Fl_Tree_Item *n; + if((n = _tree->find_item(path.str().c_str())) != NULL) { // check if the item already exists + _tree->remove(n); + } + n = _tree->add(path.str().c_str()); int ww = _baseWidth - (n->depth() + 1) * _indent; int hh = n->labelsize() + 4; _tree->begin(); @@ -1028,3 +1029,17 @@ viewButton *onelabGroup::getViewButton(int num) } return 0; } + +void onelabGroup::openCloseViewButton(int num) +{ + //std::string path = getViewPathName(num); + //if(path.empty()) return; + //Fl_Tree_Item *n = _tree->find_item(path.c_str()); + //if(n){ + // if(PView::list[num]->getOptions()->closed) + // n->parent()->close(); + // else + // n->parent()->open(); + // _tree->redraw(); + //} +} diff --git a/Fltk/onelab2Group.h b/Fltk/onelab2Group.h index 7981a28e039aa4db19e121578f71d6422ac7085e..ae56f025d413238b28b2660e0412062672eb4e59 100644 --- a/Fltk/onelab2Group.h +++ b/Fltk/onelab2Group.h @@ -48,7 +48,7 @@ public: void updateGearMenu(); void rebuildSolverList(); void addLastPostProcessing(); - void rebuildTree(bool deleteWidgets){} // useless in ONELAB2 ? + void rebuildTree(bool deleteWidgets) {} void enableTreeWidgetResize(bool value){ _enableTreeWidgetResize = value; } void clearTree(bool deleteWidgets=true); void openTreeItem(const std::string &name); @@ -84,12 +84,12 @@ public: return _manuallyClosed.find(path) != _manuallyClosed.end(); } viewButton *getViewButton(int num); + void openCloseViewButton(int num); }; void connect_cb(Fl_Widget *w, void *arg); void onelab_cb(Fl_Widget *w, void *data); inline void onelab_cb(void *data) {onelab_cb(0, data);} void solver_cb(Fl_Widget *w, void *data); -inline void solver_batch_cb(void *data){} // TODO ? #endif diff --git a/contrib/onelab2/OnelabWindow.cpp b/contrib/onelab2/OnelabWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c2a8198f6e6532768b5a2cad82153fd65843d582 --- /dev/null +++ b/contrib/onelab2/OnelabWindow.cpp @@ -0,0 +1,239 @@ +#include <FL/Fl.H> +#include <FL/Fl_Tabs.H> +#include <FL/Fl_Check_Button.H> +#include <FL/Fl_Button.H> +#include <FL/Fl_Input_Choice.H> +#include <FL/Fl_Choice.H> +#include <FL/Fl_Browser.H> +#include <FL/Fl_Scroll.H> +#include <iostream> + +#include "OnelabWindow.h" +#include "OnelabDatabase.h" +#include "OnelabServer.h" +#include "FlGui.h" +#include "paletteWindow.h" +#include "Context.h" +#include "Options.h" + +void onelab_listen_tcp_cb(Fl_Widget *w, void *data); +void onelab_listen_unix_cb(Fl_Widget *w, void *data); +#ifdef HAVE_UDT +void onelab_listen_udt_cb(Fl_Widget *w, void *data); +#endif +void onelab_connect_remote_server_cb(Fl_Widget *w, void *data); + +onelabWindow::onelabWindow(int deltaFontSize) +{ + FL_NORMAL_SIZE -= deltaFontSize; + + int width = 34 * FL_NORMAL_SIZE + WB; + int height = 12 * BH + 4 * WB; + + win = new paletteWindow(width, height, CTX::instance()->nonModalWindows ? true : false); + win->box(GMSH_WINDOW_BOX); + win->label("ONELAB2"); + + Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 2 * WB); + { + Fl_Group *o = new Fl_Group( + WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Network (server)"); + _listenOnUNIX = new Fl_Check_Button(2*WB, 2*WB + 1*BH, width-2*WB, BH, "Listen on UNIX socket"); + _sockUNIX = new Fl_Input(2*WB, 2*WB + 2*BH, width/2-2*WB, BH, "UNIX base socket name"); + _listenOnUNIX->callback(onelab_listen_unix_cb, _sockUNIX); + _sockUNIX->align(FL_ALIGN_RIGHT); + _listenOnTCP = new Fl_Check_Button(2*WB, 2*WB + 3*BH, width-2*WB, BH, "Listen on TCP socket"); + _sockTCP = new Fl_Input(2*WB, 2*WB + 4*BH, width/2-2*WB, BH, "TCP port (0 to let the system choose)"); + _listenOnTCP->callback(onelab_listen_tcp_cb, _sockTCP); + _sockTCP->align(FL_ALIGN_RIGHT); +#ifdef HAVE_UDT + _listenOnUDT = new Fl_Check_Button(2*WB, 2*WB + 5*BH, width-2*WB, BH, "Listen on UDT (UDP) socket"); + _sockUDT = new Fl_Input(2*WB, 2*WB + 6*BH, width/2-2*WB, BH, "UDP port (0 to let the system choose)"); + _listenOnUDT->callback(onelab_listen_udt_cb, _sockUDT); + _sockUDT->align(FL_ALIGN_RIGHT); +#else + _listenOnUDT = new Fl_Check_Button(2*WB, 2*WB + 5*BH, width-2*WB, BH, "Listen on UDT (UDP) socket"); + _sockUDT = new Fl_Input(2*WB, 2*WB + 6*BH, width/2-2*WB, BH, "UDP port (0 to let the system choose)"); + _sockUDT->align(FL_ALIGN_RIGHT); +#endif + refreshServers(); + o->end(); + } + { + Fl_Group *o = new Fl_Group( + 0, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Clients (server)"); + _solvers = new Fl_Choice(2*WB, 2*WB + 1*BH, width/2-2*WB, BH, "Solver"); + _solvers->align(FL_ALIGN_RIGHT); + rebuildSolverList(); + _clients = new Fl_Browser(2*WB, 2*WB + 3*BH, width/2-2*WB, 5*BH, "Connected clients"); + _clients->align(FL_ALIGN_RIGHT); + o->end(); + } + { + Fl_Group *o = new Fl_Group( + WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Network (client)"); + _remoteServer = new Fl_Input(2*WB, 2*WB + 1*BH, width/2-2*WB, BH, "Server address (IPv4:port)"); + _remoteServer->align(FL_ALIGN_RIGHT); + _connectRemoteServer = new Fl_Button(2*WB, 3*WB + 2*BH, width/2-2*WB, BH, "Connect"); + _connectRemoteServer->callback(onelab_connect_remote_server_cb, _remoteServer); + } +} + +void onelabWindow::refresh(){ + refreshServers(); + rebuildSolverList(); + refreshRemoteServer(); +} + +void onelabWindow::refreshServers() +{ + if(OnelabDatabase::instance()->isNetworkClient()) { + _listenOnUNIX->deactivate(); + _listenOnTCP->deactivate(); + _listenOnUDT->deactivate(); + _sockUNIX->deactivate(); + _sockUDT->deactivate(); + _sockTCP->deactivate(); + return; + } + + _sockUNIX->value(CTX::instance()->onelab.unixSock.c_str()); + _sockTCP->value(CTX::instance()->onelab.tcpSock.c_str()); +#ifdef HAVE_UDT + _sockUDT->value(CTX::instance()->onelab.udtSock.c_str()); +#else + _sockUDT->value("Not compiled with UDT library"); +#endif + if(CTX::instance()->onelab.unixConnected) { + _listenOnUNIX->value(1); + _sockUNIX->deactivate(); + } + else { + _listenOnUNIX->value(0); + _sockUNIX->activate(); + } + + if(CTX::instance()->onelab.tcpConnected) { + _listenOnTCP->value(1); + _sockTCP->deactivate(); + } + else { + _listenOnTCP->value(0); + _sockTCP->activate(); + } + + if(CTX::instance()->onelab.udtConnected) { + _listenOnUDT->value(1); + _sockUDT->deactivate(); + } + else { + _listenOnUDT->value(0); + _sockUDT->activate(); + } +} + +void onelabWindow::rebuildSolverList() +{ + _solvers->clear(); + for(int i = 0; i < NUM_SOLVERS; i++){ + if(opt_solver_name(i, GMSH_GET, "").size()) + _solvers->add(opt_solver_name(i, GMSH_GET, "").c_str()); + } + if(CTX::instance()->solverToRun >= 0) _solvers->value(CTX::instance()->solverToRun); +} + +void onelabWindow::refreshRemoteServer() +{ + if(OnelabDatabase::instance()->isNetworkClient()) { + _remoteServer->value(); + //TODO size_t colon = sockname.find(':'); + //if(colon != std::string::npos) { + // address = ip4_inet_pton(sockname.substr(0,colon).c_str()); + // port = atoi(sockname.substr(colon+1).c_str()); + //} + //GmshNetworkClient *c = OnelabDatabase::instance()->useAsNetworkClient(address, port, name); + //if(c == NULL) { + // Error("Unable to connect ONELAB server (%s)", sockname.c_str()); + // Exit(1); + //} + } +} + +void onelab_listen_tcp_cb(Fl_Widget *w, void *data) +{ + Fl_Check_Button *checkbutton = (Fl_Check_Button *)w; + Fl_Input *sockTCP = (Fl_Input *)data; + if(checkbutton->value() == 1) { + sockTCP->deactivate(); + CTX::instance()->onelab.tcpSock = sockTCP->value(); + std::size_t colon = CTX::instance()->onelab.tcpSock.find(":"); + OnelabServer::instance()->listenOnTcp( + ip4_inet_pton(CTX::instance()->onelab.tcpSock.substr(0, colon).c_str()), + atoi(CTX::instance()->onelab.tcpSock.substr(colon+1, CTX::instance()->onelab.tcpSock.size()-colon-1).c_str())); + } + else { + sockTCP->activate(); + OnelabServer::instance()->stopTcp(); + } +} + +void onelab_listen_unix_cb(Fl_Widget *w, void *data) +{ + Fl_Check_Button *checkbutton = (Fl_Check_Button *)w; + Fl_Input *sockUNIX = (Fl_Input *)data; + if(checkbutton->value() == 1) { + sockUNIX->deactivate(); + CTX::instance()->onelab.unixSock = sockUNIX->value(); + std::size_t colon = CTX::instance()->onelab.unixSock.find(":"); + std::ostringstream tmp; + tmp << CTX::instance()->homeDir << CTX::instance()->onelab.unixSock; + OnelabServer::instance()->listenOnUnix(tmp.str().c_str()); + } + else { + sockUNIX->activate(); + OnelabServer::instance()->stopUnix(); + } +} + +#ifdef HAVE_UDT +void onelab_listen_udt_cb(Fl_Widget *w, void *data) +{ + Fl_Check_Button *checkbutton = (Fl_Check_Button *)w; + Fl_Input *sockUDT = (Fl_Input *)data; + if(checkbutton->value() == 1) { + sockUDT->deactivate(); + CTX::instance()->onelab.udtSock = sockUDT->value(); + std::size_t colon = CTX::instance()->onelab.udtSock.find(":"); + OnelabServer::instance()->listenOnTcp( + ip4_inet_pton(CTX::instance()->onelab.udtSock.substr(0, colon).c_str()), + atoi(CTX::instance()->onelab.udtSock.substr(colon+1, CTX::instance()->onelab.udtSock.size()-colon-1).c_str())); + } + else { + sockUDT->activate(); + OnelabServer::instance()->stopUdt(); + } +} +#endif + +void onelab2_cb(Fl_Widget *w, void *data) +{ + FlGui::instance()->onelab2->refresh(); + FlGui::instance()->onelab2->win->show(); +} + +void onelab_connect_remote_server_cb(Fl_Widget *w, void *data) +{ + Fl_Input *serverAddr = (Fl_Input *)data; + std::string address = serverAddr->value(); + std::size_t colon = address.find(":"); + GmshNetworkClient *c = OnelabDatabase::instance()->useAsNetworkClient( + ip4_inet_pton(address.substr(0, colon).c_str()), + atoi(address.substr(colon+1, address.size()-colon-1).c_str()), + "GUI"); + if(c == NULL) { + Msg::Error("Unable to connect ONELAB server (%s)", address.c_str()); + Msg::Exit(1); + } + else if(FlGui::available()) // FIXME + c->setCallback(FlGui::instance()->onelab); +} diff --git a/contrib/onelab2/OnelabWindow.h b/contrib/onelab2/OnelabWindow.h new file mode 100644 index 0000000000000000000000000000000000000000..3a68f637fe257483caea7b40bf7452bcab3460e1 --- /dev/null +++ b/contrib/onelab2/OnelabWindow.h @@ -0,0 +1,34 @@ +#ifndef _ONELAB_WINDOW_H_ +#define _ONELAB_WINDOW_H_ + +class Fl_Window; +class Fl_Check_Button; +class Fl_Input; +class Fl_Choice; +class Fl_Browser; +class Fl_Button; + +class onelabWindow{ + private: + Fl_Check_Button *_listenOnUNIX, *_listenOnTCP, *_listenOnUDT; + Fl_Input *_sockUNIX, *_sockTCP, *_sockUDT; + + Fl_Choice *_solvers; + Fl_Browser *_clients; + + Fl_Check_Button *_useRemoteServer; + Fl_Input *_remoteServer; + Fl_Button *_connectRemoteServer; + + public: + Fl_Window *win; + + onelabWindow(int deltaFontSize=0); + void refresh(); + void refreshServers(); + void rebuildSolverList(); + void refreshRemoteServer(); +}; + +void onelab2_cb(Fl_Widget *w, void *data); +#endif