From 898a4eb303ed10a95f423a748b096ec863e05248 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Mon, 27 Oct 2008 19:38:20 +0000 Subject: [PATCH] - proof of concept for efficient bi-directional client/solver comm. - added "auto-scroll" toggle in msg window --- Common/Context.h | 1 + Common/DefaultOptions.h | 2 ++ Common/GmshDaemon.cpp | 26 ++++++++++++++++++-------- Common/Options.cpp | 11 +++++++++++ Common/Options.h | 1 + Fltk/Callbacks.cpp | 5 +++++ Fltk/Callbacks.h | 1 + Fltk/GUI.cpp | 21 +++++++++++++++++++-- Fltk/GUI.h | 1 + Fltk/Solvers.cpp | 13 ++++++++++--- Fltk/Solvers.h | 3 +++ 11 files changed, 72 insertions(+), 13 deletions(-) diff --git a/Common/Context.h b/Common/Context.h index 0140f048ad..a399fb76fd 100644 --- a/Common/Context.h +++ b/Common/Context.h @@ -50,6 +50,7 @@ class Context_T { int gl_position[2]; // position of the graphic window on the screen int msg_position[2]; // position of the message window on the screen int msg_size[2]; // size of the message window on the screen + int msg_auto_scroll; // scroll automatically to last message int opt_position[2]; // position of the option window on the screen int vis_position[2]; // position of the visibility window on the screen int clip_position[2]; // position of the clipping planes window on the screen diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index 7d242b32f1..5ff3dc5e7e 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -657,6 +657,8 @@ StringXNumber GeneralOptions_Number[] = { "Horizontal position (in pixels) of the upper left corner of the menu window" }, { F|S, "MenuPositionY" , opt_general_menu_position1 , 50. , "Vertical position (in pixels) of the upper left corner of the menu window" }, + { F|S, "MessageAutoScroll" , opt_general_message_auto_scroll , 1. , + "Automatically scroll message window" }, { F|S, "MessagePositionX" , opt_general_message_position0 , 650. , "Horizontal position (in pixels) of the upper left corner of the message window" }, { F|S, "MessagePositionY" , opt_general_message_position1 , 490. , diff --git a/Common/GmshDaemon.cpp b/Common/GmshDaemon.cpp index 3ddb1c3474..051893543e 100644 --- a/Common/GmshDaemon.cpp +++ b/Common/GmshDaemon.cpp @@ -18,21 +18,31 @@ int GmshDaemon(std::string socket) } client.Start(); - int i = 0; while(1){ - if(!client.Select(0, 1000)){ - // data is available to read: deal with it + // wait (at most 10ms) until data is available to read + if(!client.Select(0, 10000)){ int type, length; if(client.ReceiveHeader(&type, &length)){ - printf("received header: %d %d\n", type, length); + Msg::Info("Received header: type=%d length=%d", type, length); char *msg = new char[length]; if(client.ReceiveString(length, msg)){ - printf("received string: %s\n", msg); + Msg::Info("received string: %s", msg); + Msg::Info("replying by sending post data"); + std::ostringstream tmp; + tmp<<"View \"test\" {\n"; + for(int i= 0; i < 100; i++){ + for(int j= 0; j < 100; j++){ + tmp << "SQ("<<i<<","<<j<<",0, "<<i+1<<","<<j<<",0, " + <<i+1<<","<<j+1<<",0, "<<i<<","<<j+1<<",0){" + <<i+j<<","<<i+j<<","<<i+j<<","<<i+j<<"};\n"; + } + } + tmp<<"};BoundingBox;\n"; + client.ParseString(tmp.str().c_str()); } delete [] msg; - - printf("stopping connection!\n"); - break; + //printf("stopping connection!\n"); + //break; } } } diff --git a/Common/Options.cpp b/Common/Options.cpp index 9036103aea..5fedc14b73 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -2549,6 +2549,17 @@ double opt_general_message_size1(OPT_ARGS_NUM) return CTX.msg_size[1]; } +double opt_general_message_auto_scroll(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.msg_auto_scroll = (int)val; +#if defined(HAVE_FLTK) + if(WID && (action & GMSH_GUI)) + WID->msg_butt->value(CTX.msg_auto_scroll); +#endif + return CTX.msg_auto_scroll; +} + double opt_general_option_position0(OPT_ARGS_NUM) { if(action & GMSH_SET) diff --git a/Common/Options.h b/Common/Options.h index d140627999..2beecfcd63 100644 --- a/Common/Options.h +++ b/Common/Options.h @@ -234,6 +234,7 @@ double opt_general_message_position0(OPT_ARGS_NUM); double opt_general_message_position1(OPT_ARGS_NUM); double opt_general_message_size0(OPT_ARGS_NUM); double opt_general_message_size1(OPT_ARGS_NUM); +double opt_general_message_auto_scroll(OPT_ARGS_NUM); double opt_general_option_position0(OPT_ARGS_NUM); double opt_general_option_position1(OPT_ARGS_NUM); double opt_general_plugin_position0(OPT_ARGS_NUM); diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index eb2a4bcf4b..44415810df 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1894,6 +1894,11 @@ void message_cb(CALLBACK_ARGS) WID->create_message_window(); } +void message_auto_scroll_cb(CALLBACK_ARGS) +{ + CTX.msg_auto_scroll = WID->msg_butt->value(); +} + void message_copy_cb(CALLBACK_ARGS) { #define BUFFL 50000 diff --git a/Fltk/Callbacks.h b/Fltk/Callbacks.h index 363b57fc54..d9a199a05d 100644 --- a/Fltk/Callbacks.h +++ b/Fltk/Callbacks.h @@ -143,6 +143,7 @@ void statistics_histogram_cb(CALLBACK_ARGS); // Message Menu void message_cb(CALLBACK_ARGS); +void message_auto_scroll_cb(CALLBACK_ARGS); void message_copy_cb(CALLBACK_ARGS); void message_clear_cb(CALLBACK_ARGS); void message_save_cb(CALLBACK_ARGS); diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp index bbe104116b..864cef904c 100644 --- a/Fltk/GUI.cpp +++ b/Fltk/GUI.cpp @@ -508,6 +508,8 @@ int GetFontSize() // Definition of global shortcuts +#include "GmshSocket.h" + int GUI::global_shortcuts(int event) { // we only handle shortcuts here @@ -519,6 +521,15 @@ int GUI::global_shortcuts(int event) mod_geometry_cb(0, 0); return 1; } + // FIXME TESTING ONLY -- TO REMOVE LATER + else if(Fl::test_shortcut(FL_CTRL + 'p')) { + Msg::Info("TEST DAEMON!"); + if(SINFO[2].server){ + Msg::Info("SENDING COMMAND!"); + SINFO[2].server->SendString(GmshSocket::CLIENT_INFO, "HEY YOU!"); + } + return 1; + } else if(Fl::test_shortcut('1') || Fl::test_shortcut(FL_F + 1)) { mesh_1d_cb(0, 0); mod_mesh_cb(0, 0); @@ -4246,6 +4257,11 @@ void GUI::create_message_window(bool redraw_only) msg_browser->type(FL_MULTI_BROWSER); msg_browser->callback(message_copy_cb); + { + msg_butt = new Fl_Check_Button(width - 4 * BB - 4 * WB, height - BH - WB, BB, BH, "Auto scroll"); + msg_butt->type(FL_TOGGLE_BUTTON); + msg_butt->callback(message_auto_scroll_cb); + } { Fl_Return_Button *o = new Fl_Return_Button(width - 3 * BB - 3 * WB, height - BH - WB, BB, BH, "Clear"); o->callback(message_clear_cb); @@ -4259,7 +4275,7 @@ void GUI::create_message_window(bool redraw_only) o->callback(cancel_cb, (void *)msg_window); } - msg_window->resizable(new Fl_Box(WB, WB, 100, 10)); + msg_window->resizable(new Fl_Box(1, 1, 4, 4)); msg_window->size_range(WB + 100 + 3 * BB + 4 * WB, 100); msg_window->position(CTX.msg_position[0], CTX.msg_position[1]); @@ -4269,7 +4285,8 @@ void GUI::create_message_window(bool redraw_only) void GUI::add_message(const char *msg) { msg_browser->add(msg, 0); - msg_browser->bottomline(msg_browser->size()); + if(CTX.msg_auto_scroll) + msg_browser->bottomline(msg_browser->size()); } void GUI::save_message(const char *filename) diff --git a/Fltk/GUI.h b/Fltk/GUI.h index 62eb30e78f..67fb543162 100644 --- a/Fltk/GUI.h +++ b/Fltk/GUI.h @@ -229,6 +229,7 @@ public: // message window Fl_Window *msg_window; Fl_Browser *msg_browser; + Fl_Check_Button *msg_butt; // visibility window Fl_Window *vis_window; diff --git a/Fltk/Solvers.cpp b/Fltk/Solvers.cpp index d327375e7c..44f92777ff 100644 --- a/Fltk/Solvers.cpp +++ b/Fltk/Solvers.cpp @@ -56,8 +56,10 @@ class myGmshServer : public GmshServer{ } else{ // an error happened - if(num >= 0) + if(num >= 0){ SINFO[num].pid = -1; + SINFO[num].server = 0; + } return 1; } } @@ -165,6 +167,7 @@ int Solver(int num, const char *args) for(int i = 0; i < SINFO[num].nboptions; i++) SINFO[num].nbval[i] = 0; SINFO[num].pid = 0; + SINFO[num].server = 0; } Msg::StatusBar(2, false, "Running '%s'", prog.c_str()); @@ -188,13 +191,17 @@ int Solver(int num, const char *args) if(server->ReceiveString(length, message)){ switch (type) { case GmshServer::CLIENT_START: - if(num >= 0) + if(num >= 0){ SINFO[num].pid = atoi(message); + SINFO[num].server = server; + } break; case GmshServer::CLIENT_STOP: stop = 1; - if(num >= 0) + if(num >= 0){ SINFO[num].pid = -1; + SINFO[num].server = 0; + } break; case GmshServer::CLIENT_PROGRESS: if(num >= 0) diff --git a/Fltk/Solvers.h b/Fltk/Solvers.h index dd8ca5d2f3..e5fcc2cb72 100644 --- a/Fltk/Solvers.h +++ b/Fltk/Solvers.h @@ -8,6 +8,8 @@ #define MAXSOLVERS 5 +class GmshServer; + typedef struct{ char name[256], extension[32], executable_name[256]; char mesh_name[256], mesh_command[256]; @@ -20,6 +22,7 @@ typedef struct{ const char *help; int client_server, popup_messages, merge_views; int pid; + GmshServer *server; } SolverInfo ; extern SolverInfo SINFO[MAXSOLVERS] ; -- GitLab