From d5d7cbac72f5609e04122ebdb0bf1caa4c3c40d7 Mon Sep 17 00:00:00 2001 From: Jonnhy Jazeix <jazeix@gmail.com> Date: Thu, 2 Apr 2009 16:10:16 +0000 Subject: [PATCH] Ajout de la barre en couleur ^^ (enfin dans la console directement, les couleurs ne s'affichent pas dans emacs ou dans d'autres trucs surement. D'autres trucs plus intelligents aussi. --- src/interface/Progress_bar_thread.cpp | 50 ++++++++++++++++++++++++--- src/interface/Progress_bar_thread.hpp | 23 ++++++++++++ src/interface/help.hpp | 6 ++++ src/interface/interface_console.cpp | 22 +++++++----- src/interface/interface_console.hpp | 3 +- src/message/Errors.cpp | 6 ---- src/message/Errors.hpp | 5 --- src/parser/Parser.hpp | 2 -- src/parser/ParserPaje.cpp | 16 ++++----- src/parser/TokenSource.cpp | 29 ++++++++++------ src/parser/TokenSource.hpp | 9 ++++- src/trace/Variable.hpp | 2 +- 12 files changed, 125 insertions(+), 48 deletions(-) diff --git a/src/interface/Progress_bar_thread.cpp b/src/interface/Progress_bar_thread.cpp index 9dd24c53..6a7ad6ec 100644 --- a/src/interface/Progress_bar_thread.cpp +++ b/src/interface/Progress_bar_thread.cpp @@ -7,11 +7,53 @@ void Progress_bar_thread::init(Parser *p, Interface_console *i){ void Progress_bar_thread::run() { int loaded = 0; - + int current_color = VIOLET; + int number_of_color = 7; + color("47"); while(loaded < 95) { - loaded = _parser->get_size_loaded() + 1; - msleep(500); // We wait 500 ms + loaded = _parser->get_size_loaded(); + sleep(1); // We wait 1 second QApplication::processEvents(); - _interface_console->update_progress_bar(loaded); + char text[3]; + + std::cout << "Loading of the trace : " ; + + // Choice of the color to do a rainbow ^^, because it is useless + if(loaded < 100 / number_of_color){ + current_color = RED; + } + else if(loaded < 200 / number_of_color){ + current_color = ORANGE; + } + else if(loaded < 300 / number_of_color){ + current_color = YELLOW; + } + else if(loaded < 400 / number_of_color){ + current_color = GREEN; + } + else if(loaded < 500 / number_of_color){ + current_color = CYAN; + } + else if(loaded < 600 / number_of_color){ + current_color = BLUE; + } + else { + current_color = VIOLET; + } + + + sprintf(text, "%2d", current_color); + color(text); + std::cout << loaded << "%" << std::endl; + + // Reinit of the color + color("0"); + color("47"); + color("30"); + + + //_interface_console->update_progress_bar(loaded); } + color("0"); + } diff --git a/src/interface/Progress_bar_thread.hpp b/src/interface/Progress_bar_thread.hpp index ad6e29d3..c74e2beb 100644 --- a/src/interface/Progress_bar_thread.hpp +++ b/src/interface/Progress_bar_thread.hpp @@ -6,6 +6,29 @@ #include "interface_console.hpp" #include <iostream> +/* + * \def couleur + * \param couleur + * \brief print in the console in color ^^ + * useless and temporary + * Color Texte Arrière-plan + * Noir 30 40 + * Rouge 31 41 + * Vert 32 42 + * Jaune 33 43 + * Bleu 34 44 + * Magenta 35 45 + * Cyan 36 46 + * Blanc 37 47 + */ +#define color(param) printf("\033[%sm",param) +#define RED 30 +#define ORANGE 31 +#define YELLOW 33 +#define GREEN 32 +#define CYAN 36 +#define BLUE 34 +#define VIOLET 35 /*! * \class Progress_bar_thread diff --git a/src/interface/help.hpp b/src/interface/help.hpp index b309508f..15bef2b1 100644 --- a/src/interface/help.hpp +++ b/src/interface/help.hpp @@ -7,6 +7,12 @@ #include <QtGui> + +/*! + * \class Help + * \brief Show the help menu + */ + class Help : public QWidget{ private: QTextEdit *_text; diff --git a/src/interface/interface_console.cpp b/src/interface/interface_console.cpp index d9e58bf5..10f16fce 100644 --- a/src/interface/interface_console.cpp +++ b/src/interface/interface_console.cpp @@ -113,12 +113,12 @@ bool Interface_console::draw_trace(const string & filename, const int format){ { DrawTrace<Render_opengl> drawing_ogl; -// // Init of the thread -// Progress_bar_thread thread; -// thread.init(&parser, this); -// _progress_dialog = new QProgressDialog("Parsing", "Cancel", 0, 100, _main_window); -// _progress_dialog->show(); -// thread.start(); + // // Init of the thread + Progress_bar_thread thread; + thread.init(&parser, this); + // _progress_dialog = new QProgressDialog("Parsing", "Cancel", 0, 100, _main_window); + // _progress_dialog->show(); + thread.start(); if (NULL == _trace){/* no trace is loaded, parse the file */ _trace = new Trace(); @@ -134,16 +134,22 @@ bool Interface_console::draw_trace(const string & filename, const int format){ //delete _progress_dialog; *Message::get_instance() << "Reason : " << error << Message::ende; QApplication::restoreOverrideCursor(); + // Wait for the end thread + while(!thread.isFinished()){ + thread.exit(); + } return false; } + //delete _progress_dialog; _main_window->setDisabled (false); + // Wait for the end thread + while(!thread.isFinished()); }else if ( _file_opened != filename){/* just check if execution is normal */ *Message::get_instance() << "Try to use file: " << filename << " instead of a previous parsed file: " << _file_opened << Message::ende; } - //delete _progress_dialog; Interval interval(_time_start, ((0==_time_end)?_trace->get_max_date():_time_end) ); drawing_ogl.build(_render_opengl, _trace, 0, interval); _render_opengl->build(); @@ -233,7 +239,7 @@ int Interface_console::run(){ int Interface_console::get_state(int argc, char** argv){ - /*The folowing statics must be initialised in case their are not overrided by a command line request*/ + /*The following statics must be initialised in case their are not overrided by a command line request*/ Svg::set_height_factor (20); Svg::set_wide_factor (100); Svg::set_interval(0, 0); diff --git a/src/interface/interface_console.hpp b/src/interface/interface_console.hpp index 49352277..726bb728 100644 --- a/src/interface/interface_console.hpp +++ b/src/interface/interface_console.hpp @@ -382,9 +382,8 @@ public: /*! * \brief Only use in graphic interface. - * \param string The string to be displayed. */ - void selection_information(const std::string /*string*/) const{ + void selection_information(const std::string ) const{ } diff --git a/src/message/Errors.cpp b/src/message/Errors.cpp index dca05e2e..2886db33 100644 --- a/src/message/Errors.cpp +++ b/src/message/Errors.cpp @@ -33,8 +33,6 @@ const string Error::_UNKNOWN_VARIABLE_TYPE = "Unknown variable type: "; const string Error::_UNKNOWN_LINK_TYPE = "Unknown link type: "; const string Error::_UNKNOWN_ENTITY_TYPE = "Unknown entity type: "; -int Error::_priority_printable_min; - string Error::_content = ""; @@ -144,7 +142,3 @@ void Error::flush_in_file(const string &filename){ } } - -void Error::set_priority_min_printable(const int priority_min){ - Error::_priority_printable_min = priority_min; -} diff --git a/src/message/Errors.hpp b/src/message/Errors.hpp index 23be2da6..b729055f 100644 --- a/src/message/Errors.hpp +++ b/src/message/Errors.hpp @@ -20,8 +20,6 @@ private: Error(); static int _line_error; - static int _priority_printable_min; - static std::queue<std::string> _errors; static std::queue<std::string> _warnings; static std::string _content; @@ -220,9 +218,6 @@ public: */ static void flush_in_file(const std::string &filename); - - static void set_priority_min_printable(const int priority_min); - }; #endif // ERRORS_HPP diff --git a/src/parser/Parser.hpp b/src/parser/Parser.hpp index ab63e919..a516b2a9 100644 --- a/src/parser/Parser.hpp +++ b/src/parser/Parser.hpp @@ -39,8 +39,6 @@ public: */ virtual int get_size_loaded() const = 0; - - }; #endif // PARSER_HPP diff --git a/src/parser/ParserPaje.cpp b/src/parser/ParserPaje.cpp index e6ca90ec..c1e9170a 100644 --- a/src/parser/ParserPaje.cpp +++ b/src/parser/ParserPaje.cpp @@ -15,19 +15,16 @@ void ParserPaje::parse(string filename, Trace &trace){ Line line(_file_to_parse); + static const string PERCENT = "%"; string event_identity_string; unsigned int event_identity; - int temp = 0; while(!line.is_eof()) { - - // For the thread of the progress bar - if(temp % 2000 == 0){ - QApplication::processEvents(); - } - temp ++; - + + // For the rabbit, else it does not turn :( + QApplication::processEvents(); + line.newline(); if(line.starts_with(PERCENT)) { parserdefinition->store_definition(line); @@ -61,6 +58,8 @@ void ParserPaje::parse(string filename, Trace &trace){ Error::print_numbers(); Error::flush_in_file("log.txt"); + TokenSource::reinit_cursor(); + delete parserdefinition; delete parserevent; } @@ -74,3 +73,4 @@ void ParserPaje::set_file_to_parse(const string filename){ int ParserPaje::get_size_loaded() const{ return (TokenSource::get_size_loaded()); } + diff --git a/src/parser/TokenSource.cpp b/src/parser/TokenSource.cpp index 6419bce2..06a43423 100644 --- a/src/parser/TokenSource.cpp +++ b/src/parser/TokenSource.cpp @@ -13,6 +13,7 @@ TokenSource::TokenSource(){ //no file are opened //you must use open later _is_eof = true; + _cursor = 0; } @@ -27,12 +28,12 @@ TokenSource::~TokenSource(){ if (munmap(_buffer, _filesize) == -1){ Error::set_and_print(Error::_MUNMAP, Error::_WARNING); } + _buffer = NULL; close(_fd); #endif } void TokenSource::open(const char *filename){ - _cursor = 0; _is_eof = false; @@ -201,20 +202,26 @@ std::string *TokenSource::read_token() { } int TokenSource::get_size_loaded() { + + if(_filesize == 0) { + return 1; + } #ifdef WIN32 - - if (_file == NULL) - return 1; + if (_file == NULL) + return 1; - if (!_file.is_open()) - return 2; + if (!_file.is_open()) + return 2; - if (_file.bad()) - return 3; + if (_file.bad()) + return 3; - return _file.tellg(); + return _file.tellg(); #else - //std::cerr<<(int)((_cursor*100.0)/_filesize)<<"%"<<endl; - return (_cursor*100.0)/_filesize; + return (_cursor*100.0)/_filesize; #endif } + +void TokenSource::reinit_cursor() { + _cursor = 0; +} diff --git a/src/parser/TokenSource.hpp b/src/parser/TokenSource.hpp index d1141ede..89a82a94 100644 --- a/src/parser/TokenSource.hpp +++ b/src/parser/TokenSource.hpp @@ -107,7 +107,14 @@ public: * \return the size already parsed */ static int get_size_loaded(); - + + /*! + * \fn reinit_cursor() + * \brief Reinitialise the cursor of the file + */ + static void reinit_cursor(); + + }; #endif // TOKENSOURCE_HPP diff --git a/src/trace/Variable.hpp b/src/trace/Variable.hpp index 9fc9dbb9..6904e2a1 100644 --- a/src/trace/Variable.hpp +++ b/src/trace/Variable.hpp @@ -29,7 +29,7 @@ public: /*! * \brief Constructor * \param container Container of this variable - * \parma type Type of this variable + * \param type Type of this variable */ Variable(Container *container, VariableType *type); -- GitLab