Commit aa098514 authored by Olivier Lagrasse's avatar Olivier Lagrasse

- Ajout du temps restant lorsqu'un fichier est parse. (en mode

console et graphique)
parent ba3f990b
......@@ -102,6 +102,10 @@ bool Interface_console::draw_trace(const string & filename, const int format){
Svg svg;
DrawTrace<Render_opengl> drawing_ogl;
DrawTrace<Svg> drawing_svg;
QTime time_elapsed;
ostringstream buf_txt;
int time_buf;
time_buf = 0;
parser.set_file_to_parse(filename);
......@@ -119,6 +123,7 @@ bool Interface_console::draw_trace(const string & filename, const int format){
thread.init(&parser, _trace, filename);
int loaded = 0;
float loaded_f = 0.0f;/* floating value of the loading file state. (between 0 and 1) */
if(_main_window != NULL) { // If we have a window we show a progress bar
_progress_dialog = new QProgressDialog("Parsing", "Cancel", 0, 100, _main_window);
......@@ -130,18 +135,45 @@ bool Interface_console::draw_trace(const string & filename, const int format){
}
thread.start();
time_elapsed.start();
buf_txt.str("");
while(!parser.is_end_of_parsing()) {
loaded = parser.get_size_loaded();
loaded_f = parser.get_size_loaded();/* value between 0 and 1. Should be multiplied by 100 to obtain a percentage */
loaded = (int)(loaded_f*100.0f);
#ifdef WIN32
Sleep(1000);
#else
sleep(1); // We wait 1 second
#endif
cout << "Loading of the trace : " << loaded << "%" << endl;
cout << "Loading of the trace : " << loaded << "%" ;
if (loaded_f>0.0f){
time_buf = (time_elapsed.elapsed()/loaded_f - time_elapsed.elapsed())/1000;/* divided by to have in second 1000 since time_elapsed.elapsed() returns ms */
if (time_buf>=3600){/* convert second in hour and min */
buf_txt << "Parsing... Remaining: " << time_buf/3600 << " h " << (time_buf%3600)/60 << " min " << time_buf%60 << " s";
}else if (time_buf>=60){/* convert second in min */
buf_txt << "Parsing... Remaining: " << time_buf/60 << " min " << time_buf%60 << " s";
}else{
buf_txt << "Parsing... Remaining: " << time_buf << " s";
}
cout << " ~ " << buf_txt.str();
if ( (NULL!=_main_window) && (NULL!=_progress_dialog) )
_progress_dialog->setLabelText(QString( buf_txt.str().c_str()));
buf_txt.str("");
}
cout << endl;
if(_main_window != NULL) { // If we have a window we show a progress bar
if(_main_window != NULL) { // If we have a window we show a progress bar
update_progress_bar(loaded);
QApplication::processEvents();
......
......@@ -35,9 +35,9 @@ public:
/*!
* \fn const int get_size_loaded() const = 0;
* \return the size already loaded of the file by the parser
* \return the scale of the size already loaded of the file by the parser. (between 0 and 1)
*/
virtual int get_size_loaded() const = 0;
virtual float get_size_loaded() const = 0;
/*!
* \fn is_end_of_parsing() const
......
......@@ -64,7 +64,7 @@ void ParserPaje::set_file_to_parse(const string filename){
}
int ParserPaje::get_size_loaded() const{
float ParserPaje::get_size_loaded() const{
return (TokenSource::get_size_loaded());
}
......
......@@ -61,9 +61,9 @@ public:
/*!
* \fn get_size_loaded() const
* \brief return the size of the file already read.
* \return the size already loaded of the file by the parser
* \return the scale of the size already loaded of the file by the parser. (between 0 and 1)
*/
int get_size_loaded() const;
float get_size_loaded() const;
/*!
......
......@@ -222,24 +222,24 @@ std::string *TokenSource::read_token() {
return &_token;
}
int TokenSource::get_size_loaded() {
float TokenSource::get_size_loaded() {
#if defined (WIN32) || !defined(_POSIX_MAPPED_FILES)
if (_file == NULL)
return 1;
return 1.0f;
if (!_file.is_open())
return 2;
return 2.0f;
if (_file.bad())
return 3;
return 3.0f;
return (_file.tellg()*100.)/TokenSource::_filesize;
return ((float)_file.tellg())/(float)TokenSource::_filesize;
#else
if(_filesize == 0) {
return 1;
return 1.0f;
}
return (_cursor*100.0)/_filesize;
return ((float)_cursor)/(float)_filesize;
#endif
}
......
......@@ -108,9 +108,9 @@ public:
/*!
* \fn get_size_loaded()
* \brief get the size already parsed.
* \return the size already parsed
* \return the scale of the size already parsed. (between 0 and 1)
*/
static int get_size_loaded();
static float get_size_loaded();
/*!
* \fn reinit_cursor()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment