Commit bef9fd8d authored by Johnny Jazeix's avatar Johnny Jazeix

Ajout de la barre d'avancement.

Ainsi que d'un fichier Tools regroupant toutes les fonctions qui 
n'appartiennent pas a une classe.
parent 5c33cced
#include "Tools.hpp"
using namespace std;
double convert_to_double(const char *arg){
double value = -1.0; // value returned
string arg_temp = (string)arg + " 3";
int useless;
if(sscanf(arg_temp.c_str(), "%lf %d", &value, &useless) == 2){
return value; // It is the good format
}
else{ // We change the locale to test
bool is_english_system_needed = false; // We have dot as separator of decimal and integer.
if(arg_temp.find('.') != string::npos){
is_english_system_needed = true;
}
// We had dots initially, we need to have the english system
if(is_english_system_needed) {
if(setlocale(LC_NUMERIC, "en_GB.UTF-8") == NULL){
cerr << "The locale en_GB.UTF-8 is unavailable so the decimal pointed will not be printed" << endl;
}
}
else {
if(setlocale(LC_NUMERIC, "fr_FR.UTF-8") == NULL){
cerr << "The locale fr_FR.UTF-8 is unavailable so the decimal with comma will not be printed" << endl;
}
}
if(sscanf(arg_temp.c_str(), "%lf %d", &value, &useless) == 2) {
return value;
}
else{
return -1.;
}
}
}
/*!
*\file Tools.hpp
*\brief This file contains functions that are used in different modules and do not belong to a particular class.
*/
#ifndef TOOLS_HPP
#define TOOLS_HPP
#include <string>
#include <iostream>
/*!
* \brief Convert the string in double
* \arg arg : the string to be doublized.
*/
double convert_to_double(const char *arg);
#endif // TOOLS_HPP
......@@ -7,18 +7,17 @@ void Progress_bar_thread::init(Parser *p, Interface_console *i){
void Progress_bar_thread::run() {
_file_size = _parser->get_total_size_of_file();
_interface_console->get_progress_dialog()->setRange(0, _file_size);
_interface_console->get_progress_dialog()->setRange(0, 100);
int loaded = 0;
while(1) {
std::cout << loaded << " on " << _file_size << std::endl;
loaded += _parser->get_size_loaded();
loaded = _parser->get_size_loaded()*10000/_file_size + 1;
msleep(500); // We wait 500 ms
emit _interface_console->get_progress_dialog()->setValue(loaded);
//QApplication::processEvents();
//std::cout << _interface_console->get_progress_dialog()->minimum() << " " << _interface_console->get_progress_dialog()->maximum() << std::endl;
_interface_console->get_progress_dialog()->setValue(loaded);
QApplication::processEvents();
}
}
......@@ -113,7 +113,6 @@ bool Interface_console::draw_trace(const string & filename, const int format){
_progress_dialog->setLabelText("Parsing");
_progress_dialog->show();
QApplication::processEvents();
thread.start();
try{
......@@ -127,7 +126,6 @@ bool Interface_console::draw_trace(const string & filename, const int format){
return false;
}
thread.terminate();
//cout << _progress_dialog->value() << " " << _progress_dialog->maximum()<< endl;
delete _progress_dialog;
drawing_ogl.build(_render_opengl, &trace);
......@@ -368,13 +366,13 @@ void Interface_console::extract_times(const char *name){
}
if(has_time_start && has_time_end){
sscanf(name, "[%d]:[%d]", &_time_start, &_time_end);
sscanf(name, "[%lf]:[%lf]", &_time_start, &_time_end);
}
else if(has_time_start){
sscanf(name, "[%d]:", &_time_start);
sscanf(name, "[%lf]:", &_time_start);
}
else if(has_time_end){
sscanf(name, ":[%d]", &_time_end);
sscanf(name, ":[%lf]", &_time_end);
}
else{
_time_start = 0;
......@@ -382,35 +380,6 @@ void Interface_console::extract_times(const char *name){
}
}
double Interface_console::convert_to_double(const char *arg){
double value = -1.0; // Value returned
string arg_temp = (string)arg + " 3"; // The same hint as in Date.cpp is used, we simulate a double sscanf
int useless;
if(sscanf(arg_temp.c_str(), "%lf %d", &value, &useless) == 2){
return value; // It is the good format
}
else{ // We change the locale to test
bool is_english_system_needed = false; // We have dot as separator of decimal and integer.
if(arg_temp.find('.') != string::npos){
is_english_system_needed = true;
}
if(is_english_system_needed){ // We had dots initially, we need to have the english system
setlocale(LC_NUMERIC, "en_GB.UTF-8");
}
else{
setlocale(LC_NUMERIC, "fr_FR.UTF-8");
}
if(sscanf(arg_temp.c_str(), "%lf %d", &value, &useless) == 2){
return value;
}
else{
return -1;
}
}
}
void Interface_console::launch_action(int state, void* arg){
......
......@@ -16,14 +16,13 @@ class Interface_console;
#include "../trace/Trace.hpp"
#include "../trace/DrawTrace.hpp"
#include "../parser/ParserPaje.hpp"
#include "resource.hpp"
#include "Progress_bar_thread.hpp"
#include "../Tools.hpp"
#include "Progress_bar_thread.hpp"
//#include <pthread.h>
/*!
*\brief This class is an terminal interface, it inherited from the Interface interface.
......@@ -53,12 +52,12 @@ public:
/*!
*\brief A state which corresponds to display the trace within a time.
*/
static const int _STATE_IN_AN_INTERVAL = 1;// 2^0
static const int _STATE_IN_AN_INTERVAL = 1; // 2^0
/*!
*\brief A state which corresponds to display a the ViTE window and opening a file.
*/
static const int _STATE_OPEN_FILE = 2;// 2^1
static const int _STATE_OPEN_FILE = 2; // 2^1
/*!
*\brief A state which corresponds to display the trace within a time.
......@@ -68,7 +67,7 @@ public:
/*!
*\brief A state which corresponds to an export of file.
*/
static const int _STATE_EXPORT_FILE = 4;// 2^2
static const int _STATE_EXPORT_FILE = 4; // 2^2
/*!
*\brief A state which corresponds to an export of file.
......@@ -208,12 +207,12 @@ protected:
/*!
*\brief The time where we start to watch the trace.
*/
int _time_start;
double _time_start;
/*!
*\brief The time where we stop to watch the trace.
*/
int _time_end;
double _time_end;
/*!
*\brief The interface_console state is specified by a command line arguments combinaison which influence the launch. _state is computed by get_state() and retrieved by int get_status().
......@@ -239,19 +238,13 @@ protected:
int get_state(int argc, char** argv);
/*!
* \brief Extracts the times of start and end in the string.
* \arg name : the string where we extract times.
*/
void extract_times(const char *name);
/*!
* \brief Convert the string in double
* \arg arg : the string to be doublized.
*/
double convert_to_double(const char *arg);
/*!
* \brief Displays in the terminal the help text.
*/
......
......@@ -18,14 +18,21 @@ void ParserPaje::parse(string filename, Trace &trace){
static const string PERCENT = "%";
string event_identity_string;
unsigned int event_identity;
int temp = 0;
while(!line.is_eof()) {
line.newline();
// For the thread of the progress bar
if(temp % 2000 == 0){
QApplication::processEvents();
}
temp ++;
line.newline();
if(line.starts_with(PERCENT)) {
parserdefinition->store_definition(line);
}
else if (!line.item(0, event_identity_string)){
else if (!line.item(0, event_identity_string)) {
continue; // We have \n
}
else {
......
......@@ -16,6 +16,7 @@ INCLUDEPATH += . interface message trace trace/values parser
# Input
HEADERS += message/Message.hpp \
message/Errors.hpp \
Tools.hpp \
main_resource.hpp \
# Info header
info/info.hpp \
......@@ -67,6 +68,7 @@ HEADERS += message/Message.hpp \
FORMS += interface/info_window.ui interface/main_window.ui interface/maquette.ui interface/option_export_window.ui
SOURCES += message/Message.cpp \
message/Errors.cpp \
Tools.cpp \
main.cpp \
# Interface code files
interface/interface_console.cpp \
......
#include "Color.hpp"
using namespace std;
Color::Color() {
_r = 0;
_g = 0;
......@@ -16,29 +18,23 @@ Color::Color(double r, double g, double b) {
bool Color::instantiate(const std::string &in, Color &out) {
double r, g, b;
if(sscanf(in.c_str(), "%lf %lf %lf", &r, &g, &b) == 3){
out = Color(r, g, b);
return true;
}
// The error could occur because this is not the good format for decimal.
// Dots instead of commas or the contrary
bool is_english_system_needed = false; // We have dot as separator of decimal and integer.
if(in.find('.') != std::string::npos){
is_english_system_needed = true;
}
if(is_english_system_needed){ // We had dots initially, we need to have the english system
setlocale(LC_NUMERIC, "en_GB.UTF-8");
}
else{
setlocale(LC_NUMERIC, "fr_FR.UTF-8");
string separated_color[3];
string temp = in;
for(int i = 0 ; i < 3 ; i ++){
int position_of_space = temp.find(' ');
separated_color[i] = temp.substr(0, position_of_space);
temp = temp.substr(position_of_space+1);
}
if(sscanf(in.c_str(), "%lf %lf %lf", &r, &g, &b) != 3){
r = convert_to_double(separated_color[0].c_str());
g = convert_to_double(separated_color[1].c_str());
b = convert_to_double(separated_color[2].c_str());
if((r == -1.) || (g == -1.) || (b == -1.)) {
return false;
}
else{
else {
out = Color(r, g, b);
return true;
}
......
......@@ -12,7 +12,7 @@
#include <sstream>
#include "Value.hpp"
#include "../../Tools.hpp"
/*!
*
* \class Color
......
......@@ -11,40 +11,14 @@ Date::Date(double value){
bool Date::instantiate(const std::string &in, Date &out){
double value = 0.0;
int temp;
// We simule a 2-copy to have the good result with sscanf depending on the language of the computer...
std::string copy = in + " 3";
int test = sscanf(copy.c_str(), "%lf %d", &value, &temp);
value = convert_to_double(in.c_str());
if(test == 2){
if(value != -1.) {
out = Date(value);
return true;
}
else {// The error could occur because this is not the good format for decimal.
// Dots instead of commas or the contrary
bool is_english_system_needed = false; // We have dot as separator of decimal and integer.
if(in.find('.') != std::string::npos){
is_english_system_needed = true;
}// Dots instead of commas or the contrary
if(is_english_system_needed){ // We had dots initially, we need to have the english system
setlocale(LC_NUMERIC, "en_GB.UTF-8");
}
else{
setlocale(LC_NUMERIC, "fr_FR.UTF-8");
}
test = sscanf(copy.c_str(), "%lf %d", &value, &temp);
if(test == 2) {
out = Date(value);
return true;
}
else{
return false;
}
else {
return false;
}
}
......
......@@ -11,6 +11,7 @@
*/
#include "Value.hpp"
#include "../../Tools.hpp"
#include <sstream>
#include <cstdio>
......
......@@ -12,37 +12,14 @@ Double::Double(double value){
bool Double::instantiate(const std::string &in, Double &out){
double value = 0.0;
int temp;
// We simule a 2-copy to have the good result with sscanf depending on the language of the computer...
std::string copy = in + " 3";
int test = sscanf(copy.c_str(), "%lf %d", &value, &temp);
value = convert_to_double(in.c_str());
if(test == 2){
if(value != -1.) {
out = Double(value);
return true;
}
else {// The error could occur because this is not the good format for decimal.
bool is_english_system_needed = false; // We have dot as separator of decimal and integer.
if(in.find('.') != std::string::npos){
is_english_system_needed = true;
}
if(is_english_system_needed){ // We had dots initially, we need to have the english system
setlocale(LC_NUMERIC, "en_GB.UTF-8");
}
else{
setlocale(LC_NUMERIC, "fr_FR.UTF-8");
}
test = sscanf(copy.c_str(), "%lf %d", &value, &temp);
if(test == 2){
out = Double(value);
return true;
}
else{
return false;
}
else {
return false;
}
}
......
......@@ -11,6 +11,7 @@
*/
#include "Value.hpp"
#include "../../Tools.hpp"
#include <sstream>
#include <cstdio>
......
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