From f17bba3124b4d898287f8246bbd6f869c311d4ec Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Sun, 24 Jun 2012 09:37:09 +0000 Subject: [PATCH] better progress messages --- Common/GmshMessage.cpp | 16 ++++++++-------- Common/GmshMessage.h | 2 +- Fltk/FlGui.cpp | 13 +++++++++++++ Fltk/FlGui.h | 2 ++ Fltk/graphicWindow.cpp | 5 +++-- Fltk/graphicWindow.h | 3 ++- Fltk/onelabWindow.cpp | 2 ++ 7 files changed, 31 insertions(+), 12 deletions(-) diff --git a/Common/GmshMessage.cpp b/Common/GmshMessage.cpp index 97a999ea10..9f230f0209 100644 --- a/Common/GmshMessage.cpp +++ b/Common/GmshMessage.cpp @@ -408,20 +408,19 @@ void Msg::ProgressMeter(int n, int N, const char *fmt, ...) if(strlen(fmt)) strcat(str, " "); char str2[1024]; - sprintf(str2, "(%d %%)", _progressMeterCurrent); - strcat(str, str2); + sprintf(str2, "%s(%d %%)", _progressMeterCurrent); - if(_client) _client->Progress(str); + if(_client) _client->Progress(str2); #if defined(HAVE_FLTK) - if(FlGui::available()){ - if(_verbosity > 4) FlGui::instance()->setStatus(str, 1); + if(FlGui::available() && _verbosity > 4){ FlGui::instance()->check(); + FlGui::instance()->setProgress(str, n, N); } #endif if(CTX::instance()->terminal){ - fprintf(stdout, "%s \r", str); + fprintf(stdout, "%s \r", str2); fflush(stdout); } @@ -433,8 +432,9 @@ void Msg::ProgressMeter(int n, int N, const char *fmt, ...) if(_client) _client->Progress("Done!"); #if defined(HAVE_FLTK) - if(FlGui::available()){ - if(_verbosity > 4) FlGui::instance()->setStatus("", 1); + if(FlGui::available() && _verbosity > 4){ + FlGui::instance()->check(); + FlGui::instance()->setProgress("", 0, N); } #endif diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h index 18dafee6d3..a17853ff50 100644 --- a/Common/GmshMessage.h +++ b/Common/GmshMessage.h @@ -71,7 +71,7 @@ class Msg { static void Debug(const char *fmt, ...); static void ProgressMeter(int n, int N, const char *fmt, ...); static void ProgressMeter(int n, int N){ ProgressMeter(n, N, ""); } - static void SetProgressMeterStep(int step){ _progressMeterStep = step; } + static void SetProgressMeterStep(int step){ _progressMeterStep = (step > 0) ? step : 1; } static void ResetProgressMeter(){ if(!_commRank) _progressMeterCurrent = 0; } static double &Timer(std::string str){ return _timers[str]; } static void PrintTimers(); diff --git a/Fltk/FlGui.cpp b/Fltk/FlGui.cpp index 8c18de758f..d8b45ae430 100644 --- a/Fltk/FlGui.cpp +++ b/Fltk/FlGui.cpp @@ -810,6 +810,19 @@ void FlGui::setStatus(const char *msg, int num) } } +void FlGui::setProgress(const char *msg, int n, int N) +{ + for(unsigned int i = 0; i < FlGui::instance()->graph.size(); i++){ + if(FlGui::instance()->graph[i]->label[1]->minimum() != 0) + FlGui::instance()->graph[i]->label[1]->minimum(0); + if(FlGui::instance()->graph[i]->label[1]->maximum() != N) + FlGui::instance()->graph[i]->label[1]->maximum(N); + if(FlGui::instance()->graph[i]->label[1]->value() != n) + FlGui::instance()->graph[i]->label[1]->value(n); + } + setStatus(msg, 1); +} + void FlGui::storeCurrentWindowsInfo() { CTX::instance()->menuPosition[0] = menu->win->x(); diff --git a/Fltk/FlGui.h b/Fltk/FlGui.h index 7e08c61aa9..a52131318b 100644 --- a/Fltk/FlGui.h +++ b/Fltk/FlGui.h @@ -108,6 +108,8 @@ class FlGui{ char selectEntity(int type); // display status message void setStatus(const char *msg, int num); + // display status message and update progress bar + void setProgress(const char *msg, int n, int N); // create the window for physical context dependant definitions void callForSolverPlugin(int dim); // add line in message console(s) diff --git a/Fltk/graphicWindow.cpp b/Fltk/graphicWindow.cpp index b0a005f934..311a3721e6 100644 --- a/Fltk/graphicWindow.cpp +++ b/Fltk/graphicWindow.cpp @@ -632,11 +632,12 @@ graphicWindow::graphicWindow(bool main, int numTiles) : _autoScrollMessages(true int wleft = (width - x) / 3 - 1; int wright = (width - x) - (width - x) / 3 - 1; - label[0] = new Fl_Box(x, glheight + mheight + 2, wleft, sht); - label[1] = new Fl_Box(x + (width - x) / 3, glheight + mheight + 2, wright, sht); + label[0] = new Fl_Progress(x, glheight + mheight + 2, wleft, sht); + label[1] = new Fl_Progress(x + (width - x) / 3, glheight + mheight + 2, wright, sht); for(int i = 0; i < 2; i++) { label[i]->box(FL_THIN_DOWN_BOX); label[i]->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP); + label[i]->color(FL_BACKGROUND_COLOR, FL_DARK2); // FL_DARK_GREEN } // dummy resizable box diff --git a/Fltk/graphicWindow.h b/Fltk/graphicWindow.h index e60d9513d6..a5abb931dc 100644 --- a/Fltk/graphicWindow.h +++ b/Fltk/graphicWindow.h @@ -14,6 +14,7 @@ #include <FL/Fl_Box.H> #include <FL/Fl_Tile.H> #include <FL/Fl_Browser.H> +#include <FL/Fl_Progress.H> #include "openglWindow.h" class graphicWindow{ @@ -28,7 +29,7 @@ class graphicWindow{ Fl_Browser *browser; Fl_Box *bottom; Fl_Button *butt[14]; - Fl_Box *label[2]; + Fl_Progress *label[2]; int minWidth, minHeight; public: graphicWindow(bool main=true, int numTiles=1); diff --git a/Fltk/onelabWindow.cpp b/Fltk/onelabWindow.cpp index a6a7c18565..6320d17a55 100644 --- a/Fltk/onelabWindow.cpp +++ b/Fltk/onelabWindow.cpp @@ -277,6 +277,8 @@ bool onelab::localNetworkClient::run() } else if(type == "number"){ onelab::number p; p.fromChar(message); set(p); + if(p.getName() == getName() + "/Progress") + FlGui::instance()->setProgress(p.getLabel().c_str(), p.getValue(), p.getMax()); } else if(type == "string"){ onelab::string p; p.fromChar(message); set(p); -- GitLab