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

two-level "abort" : first try to gently "stop", then "kill"

parent 10c09cb3
No related branches found
No related tags found
No related merge requests found
...@@ -410,19 +410,6 @@ static bool incrementLoop() ...@@ -410,19 +410,6 @@ static bool incrementLoop()
return ret; return ret;
} }
static bool stopOnError(const std::string &client)
{
if(Msg::GetErrorCount() > 0 && !CTX::instance()->expertMode){
Msg::ResetErrorCounter();
std::string msg
(client + " reported an error: do you really want to continue?\n\n"
"(To disable this warning in the future, select `Enable expert mode'\n"
"in the option dialog.)");
if(Msg::GetAnswer(msg.c_str(), 1, "Stop", "Continue") == 0) return true;
}
return false;
}
static std::vector<double> getRange(onelab::number &p) static std::vector<double> getRange(onelab::number &p)
{ {
std::vector<double> v; std::vector<double> v;
...@@ -505,6 +492,11 @@ void onelab_cb(Fl_Widget *w, void *data) ...@@ -505,6 +492,11 @@ void onelab_cb(Fl_Widget *w, void *data)
if(!data) return; if(!data) return;
std::string action((const char*)data); std::string action((const char*)data);
if(action == "stop"){
FlGui::instance()->onelab->deactivate("kill");
return;
}
if(action == "reset"){ if(action == "reset"){
// clear everything except model names // clear everything except model names
std::vector<onelab::string> modelNames; std::vector<onelab::string> modelNames;
...@@ -524,12 +516,10 @@ void onelab_cb(Fl_Widget *w, void *data) ...@@ -524,12 +516,10 @@ void onelab_cb(Fl_Widget *w, void *data)
action = "check"; action = "check";
} }
FlGui::instance()->onelab->deactivate(); FlGui::instance()->onelab->deactivate("stop");
if(action == "compute") initializeLoop(); if(action == "compute") initializeLoop();
bool stop = false;
do{ // enter computation loop do{ // enter computation loop
// the Gmsh client is special: it always gets executed first. (The // the Gmsh client is special: it always gets executed first. (The
...@@ -579,8 +569,9 @@ void onelab_cb(Fl_Widget *w, void *data) ...@@ -579,8 +569,9 @@ void onelab_cb(Fl_Widget *w, void *data)
onelab::server::instance()->setChanged(false, "Gmsh"); onelab::server::instance()->setChanged(false, "Gmsh");
} }
} }
stop = stopOnError("Gmsh");
if(stop) break; FlGui::instance()->onelab->checkForErrors("Gmsh");
if(FlGui::instance()->onelab->stop()) break;
// Iterate over all other clients // Iterate over all other clients
for(onelab::server::citer it = onelab::server::instance()->firstClient(); for(onelab::server::citer it = onelab::server::instance()->firstClient();
...@@ -605,14 +596,15 @@ void onelab_cb(Fl_Widget *w, void *data) ...@@ -605,14 +596,15 @@ void onelab_cb(Fl_Widget *w, void *data)
c->kill(); c->kill();
} }
stop = stopOnError(c->getName()); FlGui::instance()->onelab->checkForErrors(c->getName());
if(stop) break; if(FlGui::instance()->onelab->stop()) break;
} }
updateOnelabGraphs(); updateOnelabGraphs();
FlGui::instance()->onelab->rebuildTree(); FlGui::instance()->onelab->rebuildTree();
} while(action == "compute" && incrementLoop() && !stop); } while(!FlGui::instance()->onelab->stop() && action == "compute" &&
incrementLoop());
FlGui::instance()->onelab->activate(); FlGui::instance()->onelab->activate();
FlGui::instance()->onelab->show(); FlGui::instance()->onelab->show();
...@@ -708,7 +700,7 @@ static void onelab_dump_cb(Fl_Widget *w, void *data) ...@@ -708,7 +700,7 @@ static void onelab_dump_cb(Fl_Widget *w, void *data)
printf("ONELAB dump:\n%s\n", onelab::server::instance()->toChar().c_str()); printf("ONELAB dump:\n%s\n", onelab::server::instance()->toChar().c_str());
} }
onelabWindow::onelabWindow(int deltaFontSize) onelabWindow::onelabWindow(int deltaFontSize) : _stop(false)
{ {
FL_NORMAL_SIZE -= deltaFontSize; FL_NORMAL_SIZE -= deltaFontSize;
...@@ -869,17 +861,32 @@ void onelabWindow::rebuildSolverList() ...@@ -869,17 +861,32 @@ void onelabWindow::rebuildSolverList()
_win->label(_title.c_str()); _win->label(_title.c_str());
} }
void onelabWindow::checkForErrors(const std::string &client)
{
if(Msg::GetErrorCount() > 0 && !CTX::instance()->expertMode){
Msg::ResetErrorCounter();
std::string msg
(client + " reported an error: do you really want to continue?\n\n"
"(To disable this warning in the future, select `Enable expert mode'\n"
"in the option dialog.)");
if(Msg::GetAnswer(msg.c_str(), 1, "Stop", "Continue") == 0)
_stop = true;
}
}
void onelabWindow::activate() void onelabWindow::activate()
{ {
_stop = false;
_butt[0]->label("Compute"); _butt[0]->label("Compute");
_butt[0]->callback(onelab_cb, (void*)"compute"); _butt[0]->callback(onelab_cb, (void*)"compute");
_butt[1]->activate(); _butt[1]->activate();
} }
void onelabWindow::deactivate() void onelabWindow::deactivate(const std::string &how)
{ {
_butt[0]->label("Kill"); _stop = (how == "stop") ? false : true;
_butt[0]->callback(onelab_cb, (void*)"kill"); _butt[0]->label((how == "stop") ? "Stop" : "Kill");
_butt[0]->callback(onelab_cb, (how == "stop") ? (void*)"stop" : (void*)"kill");
_butt[1]->deactivate(); _butt[1]->deactivate();
} }
......
...@@ -26,6 +26,7 @@ class onelabWindow{ ...@@ -26,6 +26,7 @@ class onelabWindow{
std::vector<Fl_Widget*> _treeWidgets; std::vector<Fl_Widget*> _treeWidgets;
std::string _title; std::string _title;
std::string _modelExtension; std::string _modelExtension;
bool _stop;
public: public:
onelabWindow(int deltaFontSize=0); onelabWindow(int deltaFontSize=0);
int x(){ return _win->x(); } int x(){ return _win->x(); }
...@@ -34,7 +35,7 @@ class onelabWindow{ ...@@ -34,7 +35,7 @@ class onelabWindow{
void rebuildTree(); void rebuildTree();
void redrawTree(){ _tree->redraw(); } void redrawTree(){ _tree->redraw(); }
void activate(); void activate();
void deactivate(); void deactivate(const std::string &how);
void show(){ _win->show(); } void show(){ _win->show(); }
int shown(){ return _win->shown(); } int shown(){ return _win->shown(); }
std::string getModelExtension(){ return _modelExtension; } std::string getModelExtension(){ return _modelExtension; }
...@@ -49,6 +50,8 @@ class onelabWindow{ ...@@ -49,6 +50,8 @@ class onelabWindow{
void addSolver(const std::string &name, const std::string &commandLine, void addSolver(const std::string &name, const std::string &commandLine,
int index); int index);
void removeSolver(const std::string &name); void removeSolver(const std::string &name);
void checkForErrors(const std::string &client);
bool stop(){ return _stop; }
}; };
void onelab_cb(Fl_Widget *w, void *data); void onelab_cb(Fl_Widget *w, void *data);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment