Skip to content
Snippets Groups Projects
Commit 9ac206ac authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

solver GUI bullet-proofing

parent 6086868b
Branches
Tags
No related merge requests found
...@@ -70,13 +70,18 @@ void GmshRemote::runCommand(int commandIndex, int optionIndex, int optionChoice) ...@@ -70,13 +70,18 @@ void GmshRemote::runCommand(int commandIndex, int optionIndex, int optionChoice)
return; return;
} }
std::string commandArg;
if(optionValue[optionIndex].size()){
if(optionChoice < 0 || optionChoice >= (int)optionValue[optionIndex].size()){ if(optionChoice < 0 || optionChoice >= (int)optionValue[optionIndex].size()){
Msg::Error("Wrong option choice"); Msg::Error("Wrong option choice");
return; return;
} }
commandArg = ReplacePercentS
std::string commandArg = ReplacePercentS
(buttonSwitch[commandIndex], optionValue[optionIndex][optionChoice]); (buttonSwitch[commandIndex], optionValue[optionIndex][optionChoice]);
}
else{ // no options
commandArg = buttonSwitch[commandIndex];
}
run(inputArg + " " + meshArg + " " + commandArg); run(inputArg + " " + meshArg + " " + commandArg);
} }
......
...@@ -91,22 +91,22 @@ void GmshRemote::run(std::string args) ...@@ -91,22 +91,22 @@ void GmshRemote::run(std::string args)
return; return;
} }
// find solver num // find associated solver window if there is one
int num = -1; solverWindow *window = 0;
for(std::map<int, GmshRemote*>::iterator it = _all.begin(); for(std::map<int, GmshRemote*>::iterator it = _all.begin();
it != _all.end(); it++){ it != _all.end(); it++){
if(this == it->second){ if(this == it->second){
num = it->first; if(it->first >= 0 && it->first < NB_SOLVER_MAX){
window = FlGui::instance()->solver[it->first];
break; break;
} }
} }
}
// make command buttons inactive while running // make command buttons inactive while running
if(num >= 0 && num < NB_SOLVER_MAX){ if(window)
for(unsigned int i = 0; i < buttonName.size(); i++) for(unsigned int i = 0; i < window->command.size(); i++)
if(buttonName[i].size()) window->command[i]->deactivate();
FlGui::instance()->solver[num]->command[i]->deactivate();
}
_pid = 0; _pid = 0;
_server = 0; _server = 0;
...@@ -136,11 +136,9 @@ void GmshRemote::run(std::string args) ...@@ -136,11 +136,9 @@ void GmshRemote::run(std::string args)
server->Shutdown(); server->Shutdown();
delete server; delete server;
// reactivate buttons // reactivate buttons
if(num >= 0 && num < NB_SOLVER_MAX){ if(window)
for(unsigned int i = 0; i < buttonName.size(); i++) for(unsigned int i = 0; i < window->command.size(); i++)
if(buttonName[i].size()) window->command[i]->activate();
FlGui::instance()->solver[num]->command[i]->activate();
}
return; return;
} }
...@@ -237,22 +235,24 @@ void GmshRemote::run(std::string args) ...@@ -237,22 +235,24 @@ void GmshRemote::run(std::string args)
} }
} }
if(num >= 0 && num < NB_SOLVER_MAX){ if(window){
// some options have been changed: refill the menus // some options have been changed: refill the menus
if(!initOption[0] || !initOption[1] || !initOption[2] || !initOption[3] || if(!initOption[0] || !initOption[1] || !initOption[2] ||
!initOption[4]){ !initOption[3] || !initOption[4]){
for(unsigned int i = 0; i < optionName.size(); i++) { for(unsigned int i = 0; i < window->choice.size(); i++) {
if(optionName[i].empty()) break; int old = window->choice[i]->value();
FlGui::instance()->solver[num]->choice[i]->clear(); window->choice[i]->clear();
for(unsigned int j = 0; j < optionValue[i].size(); j++) for(unsigned int j = 0; j < optionValue[i].size(); j++)
FlGui::instance()->solver[num]->choice[i]->add(optionValue[i][j].c_str()); window->choice[i]->add(optionValue[i][j].c_str());
FlGui::instance()->solver[num]->choice[i]->value(0); if(old >= 0 && old < window->choice[i]->size())
window->choice[i]->value(old);
else
window->choice[i]->value(0);
} }
} }
// reactivate buttons // reactivate buttons
for(unsigned int i = 0; i < buttonName.size(); i++) for(unsigned int i = 0; i < window->command.size(); i++)
if(buttonName[i].size()) window->command[i]->activate();
FlGui::instance()->solver[num]->command[i]->activate();
} }
_server = 0; _server = 0;
...@@ -399,7 +399,9 @@ static void solver_command_cb(Fl_Widget *w, void *data) ...@@ -399,7 +399,9 @@ static void solver_command_cb(Fl_Widget *w, void *data)
for(int i = 0; i < idx; i++) for(int i = 0; i < idx; i++)
optionIndex += numPercentS(GmshRemote::get(num)->buttonSwitch[i]); optionIndex += numPercentS(GmshRemote::get(num)->buttonSwitch[i]);
int optionChoice = FlGui::instance()->solver[num]->choice[optionIndex]->value(); int optionChoice = 0;
if(optionIndex >= 0 && optionIndex < FlGui::instance()->solver[num]->choice.size())
optionChoice = FlGui::instance()->solver[num]->choice[optionIndex]->value();
GmshRemote::get(num)->runCommand(idx, optionIndex, optionChoice); GmshRemote::get(num)->runCommand(idx, optionIndex, optionChoice);
} }
...@@ -476,22 +478,24 @@ solverWindow::solverWindow(int num, int deltaFontSize) ...@@ -476,22 +478,24 @@ solverWindow::solverWindow(int num, int deltaFontSize)
} }
for(int i = 0; i < numOptions; i++) { for(int i = 0; i < numOptions; i++) {
choice[i] = new Fl_Choice Fl_Choice *c = new Fl_Choice
(2 * WB, 2 * WB + (4 + i) * BH, LL, BH, (2 * WB, 2 * WB + (4 + i) * BH, LL, BH,
GmshRemote::get(num)->optionName[i].c_str()); GmshRemote::get(num)->optionName[i].c_str());
choice[i]->align(FL_ALIGN_RIGHT); c->align(FL_ALIGN_RIGHT);
choice.push_back(c);
} }
static int arg[NB_SOLVER_MAX][5][2]; static int arg[NB_SOLVER_MAX][5][2];
for(unsigned int i = 0; i < GmshRemote::get(num)->buttonName.size(); i++) { command.resize(GmshRemote::get(num)->buttonName.size());
if(GmshRemote::get(num)->buttonName[i].size()){ for(unsigned int i = 0; i < command.size(); i++) {
arg[num][i][0] = num; arg[num][i][0] = num;
arg[num][i][1] = i; arg[num][i][1] = i;
command[i] = new Fl_Button command[i] = new Fl_Button
((2 + i) * WB + i * BBS, 3 * WB + (4 + numOptions) * BH, ((2 + i) * WB + i * BBS, 3 * WB + (4 + numOptions) * BH,
BBS, BH, GmshRemote::get(num)->buttonName[i].c_str()); BBS, BH, GmshRemote::get(num)->buttonName[i].c_str());
command[i]->callback(solver_command_cb, (void *)arg[num][i]); command[i]->callback(solver_command_cb, (void *)arg[num][i]);
} if(GmshRemote::get(num)->buttonName[i].empty())
command[i]->hide();
} }
{ {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#ifndef _SOLVER_WINDOW_H_ #ifndef _SOLVER_WINDOW_H_
#define _SOLVER_WINDOW_H_ #define _SOLVER_WINDOW_H_
#include <vector>
#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
#include <FL/Fl_Input.H> #include <FL/Fl_Input.H>
#include <FL/Fl_Choice.H> #include <FL/Fl_Choice.H>
...@@ -15,10 +16,10 @@ ...@@ -15,10 +16,10 @@
class solverWindow{ class solverWindow{
public: public:
Fl_Window *win; Fl_Window *win;
Fl_Input *input[50]; Fl_Input *input[5];
Fl_Choice *choice[10];
Fl_Menu_Button *menu; Fl_Menu_Button *menu;
Fl_Button *command[10]; std::vector<Fl_Choice*> choice;
std::vector<Fl_Button*> command;
public: public:
solverWindow(int solverIndex, int deltaFontSize=0); solverWindow(int solverIndex, int deltaFontSize=0);
}; };
......
...@@ -174,6 +174,9 @@ bool PViewDataGModel::writeMSH(std::string fileName, bool binary) ...@@ -174,6 +174,9 @@ bool PViewDataGModel::writeMSH(std::string fileName, bool binary)
int mult = 1; int mult = 1;
if(_type == ElementNodeData) if(_type == ElementNodeData)
mult = e->getNumVertices(); mult = e->getNumVertices();
// Warning: this will not work if the mesh we just saved
// above changed the renumbering of the elements (which is
// usually the case)...
int num = e->getNum(); int num = e->getNum();
if(binary){ if(binary){
fwrite(&num, sizeof(int), 1, fp); fwrite(&num, sizeof(int), 1, fp);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment