diff --git a/Fltk/Solvers.cpp b/Fltk/Solvers.cpp index 50e83968250c023838131491443c1f8899c04879..a7dd4321821d39f3cb4c47f810f50b2a6f7d7c00 100644 --- a/Fltk/Solvers.cpp +++ b/Fltk/Solvers.cpp @@ -165,11 +165,10 @@ int Solver(int num, const char *args) } if(num >= 0){ - for(int i = 0; i < SINFO[num].nboptions; i++) - SINFO[num].nbval[i] = 0; SINFO[num].pid = 0; SINFO[num].server = 0; } + bool initOption[5] = {true, true, true, true, true}; Msg::StatusBar(2, false, "Running '%s'", prog.c_str()); @@ -211,24 +210,44 @@ int Solver(int num, const char *args) Msg::StatusBar(2, false, "%s", message); break; case GmshServer::CLIENT_OPTION_1: + if(initOption[0]){ + SINFO[num].option[0].clear(); + initOption[0] = false; + } if(num >= 0) - SINFO[num].option[0][SINFO[num].nbval[0]++] = message; + SINFO[num].option[0].push_back(message); break; case GmshServer::CLIENT_OPTION_2: + if(initOption[1]){ + SINFO[num].option[1].clear(); + initOption[1] = false; + } if(num >= 0) - SINFO[num].option[1][SINFO[num].nbval[1]++] = message; + SINFO[num].option[1].push_back(message); break; case GmshServer::CLIENT_OPTION_3: + if(initOption[2]){ + SINFO[num].option[2].clear(); + initOption[2] = false; + } if(num >= 0) - SINFO[num].option[2][SINFO[num].nbval[2]++] = message; + SINFO[num].option[2].push_back(message); break; case GmshServer::CLIENT_OPTION_4: + if(initOption[3]){ + SINFO[num].option[3].clear(); + initOption[3] = false; + } if(num >= 0) - SINFO[num].option[3][SINFO[num].nbval[3]++] = message; + SINFO[num].option[3].push_back(message); break; case GmshServer::CLIENT_OPTION_5: + if(initOption[4]){ + SINFO[num].option[4].clear(); + initOption[4] = false; + } if(num >= 0) - SINFO[num].option[4][SINFO[num].nbval[4]++] = message; + SINFO[num].option[4].push_back(message); break; case GmshServer::CLIENT_MERGE_FILE: if(num < 0 || (num >= 0 && SINFO[num].merge_views)) { @@ -281,16 +300,17 @@ int Solver(int num, const char *args) } if(num >= 0){ - for(int i = 0; i < SINFO[num].nboptions; i++) { - if(SINFO[num].nbval[i]) { + if(!initOption[0] || !initOption[1] || !initOption[2] || + !initOption[3] || !initOption[4]){ // some options have been changed + for(int i = 0; i < SINFO[num].nboptions; i++) { GUI::instance()->solver[num]->choice[i]->clear(); - for(int j = 0; j < SINFO[num].nbval[i]; j++) + for(int j = 0; j < SINFO[num].option[i].size(); j++) GUI::instance()->solver[num]->choice[i]->add(SINFO[num].option[i][j].c_str()); GUI::instance()->solver[num]->choice[i]->value(0); } } } - + server->StopClient(); if(num >= 0){ diff --git a/Fltk/Solvers.h b/Fltk/Solvers.h index fe5cfc6c7b3edc2b6467541911bd9f028ed9f26f..30dd61b4120c2cf1496a73a74c71cbcc6c00fe7c 100644 --- a/Fltk/Solvers.h +++ b/Fltk/Solvers.h @@ -7,6 +7,7 @@ #define _SOLVERS_H_ #include <string> +#include <vector> #define MAX_NUM_SOLVERS 5 #define MAX_NUM_SOLVER_OPTIONS 5 @@ -21,8 +22,8 @@ typedef struct{ std::string button_name[MAX_NUM_SOLVER_OPTIONS]; std::string button_command[MAX_NUM_SOLVER_OPTIONS]; std::string option_name[MAX_NUM_SOLVER_OPTIONS], option_command; - std::string option[MAX_NUM_SOLVER_OPTIONS][100]; - int nboptions, nbval[MAX_NUM_SOLVER_OPTIONS]; + std::vector<std::string> option[MAX_NUM_SOLVER_OPTIONS]; + int nboptions; std::string help; int client_server, popup_messages, merge_views; int pid; diff --git a/Fltk/solverWindow.cpp b/Fltk/solverWindow.cpp index ec2cbf6548fe6ad63e6ab6a44fe4432d256399cf..c93f7e5647d595f608d3366e18106e13a5bb73c0 100644 --- a/Fltk/solverWindow.cpp +++ b/Fltk/solverWindow.cpp @@ -110,7 +110,7 @@ static void solver_command_cb(Fl_Widget *w, void *data) char tmp[256], mesh[256], arg[512], command[256]; int num = ((int *)data)[0]; int idx = ((int *)data)[1]; - int i, usedopts = 0; + int usedopts = 0; if(SINFO[num].popup_messages) GUI::instance()->messages->show(true); @@ -125,14 +125,18 @@ static void solver_command_cb(Fl_Widget *w, void *data) } if(nbs(SINFO[num].button_command[idx].c_str())) { - for(i = 0; i < idx; i++) + for(int i = 0; i < idx; i++) usedopts += nbs(SINFO[num].button_command[i].c_str()); if(usedopts > SINFO[num].nboptions) { Msg::Error("Missing options to execute command"); return; } - sprintf(command, SINFO[num].button_command[idx].c_str(), SINFO[num].option - [usedopts][GUI::instance()->solver[num]->choice[usedopts]->value()].c_str()); + int val = GUI::instance()->solver[num]->choice[usedopts]->value(); + if(val < SINFO[num].option[usedopts].size()) + sprintf(command, SINFO[num].button_command[idx].c_str(), + SINFO[num].option[usedopts][val].c_str()); + else + Msg::Error("Invalid option index: missing value"); } else { strcpy(command, SINFO[num].button_command[idx].c_str());