Commit 2026cfee authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

Add counter exports

parent 8a2bfac1
......@@ -122,6 +122,9 @@ SET(VITE_UIS
interface/option_export_window.ui
interface/stats_viewer.ui
interface/global_cmd.ui
interface/global_cmd.ui
interface/kind_of_export.ui
interface/list_of_counter_to_export.ui
)
SET(VITE_SRCS
......
......@@ -53,7 +53,8 @@
#include <iostream>/* to use the C standard library input output functions */
#include <string>
#include <cstdlib> /* for macros EXIT_SUCCESS and EXIT_FAILURE */
#include <math.h> /* for min and max functions */
#include <math.h> /* for M_PI */
#include <algorithm> /* for min and max functions */
#include <sstream>
/* -- */
/* -- */
......
......@@ -28,7 +28,7 @@
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
** ViTE developpers are (for version 0.* to 1.0):
** ViTE developers are (for version 0.* to 1.0):
**
** - COULOMB Kevin
** - FAVERGE Mathieu
......@@ -77,7 +77,6 @@
#include "trace/Trace.hpp"
#include "trace/DrawTree.hpp"
#include "trace/DrawTrace.hpp"
#include "trace/Container.hpp"
/* -- */
#include "parser/File.hpp"
#include "parser/Parser.hpp"
......@@ -132,7 +131,7 @@ Core::Core(int argc, char ** argv){
QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
if (!useGUI){
cerr << "Error: Graphical window cannot be displayed." << endl;
cerr << QObject::tr("Error: Graphical window cannot be displayed.").toStdString() << endl;
exit(EXIT_FAILURE);
}
......@@ -187,7 +186,7 @@ Core::~Core(){
bool Core::draw_trace(const string & filename, const int format){
ParserPaje parser;
Parser *parser;
Svg svg;
DrawTrace<Render_opengl> drawing_ogl;
DrawTrace<Svg> drawing_svg;
......@@ -196,7 +195,32 @@ bool Core::draw_trace(const string & filename, const int format){
int time_buf;
time_buf = 0;
parser.set_file_to_parse(filename);
// Get the parser in function of the extension of the file
const unsigned int position_of_dot = filename.find_last_of('.');
if (position_of_dot != string::npos) {
if(filename.substr(position_of_dot) == ".trace") {
parser = new ParserPaje();
}
#ifdef WITH_OTF
else if(filename.substr(position_of_dot) == ".otf") {
parser = new ParserOTF();
}
#endif //WITH_OTF
else if(filename.substr(position_of_dot) == ".ept") {
parser = new ParserVite();
}
else {
Error::set(Error::_BAD_FILE_EXTENSION, Error::_WARNING);
parser = new ParserPaje();
}
}
else {
Error::set(Error::_BAD_FILE_EXTENSION, Error::_WARNING);
parser = new ParserPaje();
}
parser->set_file_to_parse(filename);
QApplication::setOverrideCursor(Qt::WaitCursor);
......@@ -209,14 +233,14 @@ bool Core::draw_trace(const string & filename, const int format){
// Init of the thread
parsing_thread thread;
thread.init(&parser, _trace, filename);
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);
_progress_dialog->setWindowTitle(QString::fromStdString("Loading of "+filename));
_progress_dialog = new QProgressDialog(QObject::tr("Parsing"), QObject::tr("Cancel"), 0, 100, _main_window);
_progress_dialog->setWindowTitle(QObject::tr("Loading of ")+QString::fromStdString(filename));
_progress_dialog->show();
_main_window->setDisabled(true);
......@@ -227,9 +251,8 @@ bool Core::draw_trace(const string & filename, const int format){
time_elapsed.start();
buf_txt.str("");
while(!parser.is_end_of_parsing()) {
loaded_f = parser.get_size_loaded();/* value between 0 and 1. Should be multiplied by 100 to obtain a percentage */
while(!(parser->is_end_of_parsing() && thread.isFinished())) {
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
......@@ -237,7 +260,8 @@ bool Core::draw_trace(const string & filename, const int format){
#else
sleep(1); // We wait 1 second
#endif
cout << "Loading of the trace : " << loaded << "%" ;
cout << QObject::tr("Loading of the trace : ").toStdString() << loaded << "%" ;
if (loaded_f>0.0f){
/* divided by to have in second 1000 since time_elapsed.elapsed() returns ms */
......@@ -259,7 +283,7 @@ bool Core::draw_trace(const string & filename, const int format){
_progress_dialog->setLabelText(QString( buf_txt.str().c_str()));
buf_txt.str("");
}
}
cout << endl;
......@@ -269,16 +293,14 @@ bool Core::draw_trace(const string & filename, const int format){
QApplication::processEvents();
if(_progress_dialog->wasCanceled()) {
cout << "Canceled at " << loaded << "%" << endl;
parser.set_canceled();
*Message::get_instance() << "The trace opening was canceled by the user at " << loaded << "%" << Message::ende;
cout << QObject::tr("Canceled at ").toStdString() << loaded << "%" << endl;
parser->set_canceled();
*Message::get_instance() << QObject::tr("The trace opening was canceled by the user at ").toStdString() << loaded << "%" << Message::ende;
break; // Quit the loop
}
}
}
// parser.reinit_cursor();
Error::print_numbers();
Error::flush("log.txt");
......@@ -288,15 +310,16 @@ bool Core::draw_trace(const string & filename, const int format){
_main_window->setDisabled (false);
}
// Wait for the end of the thread
while(!thread.isFinished()) {
while(!thread.wait()) {
}
delete parser;
}
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;
}
Interval interval(_time_start, ((0==_time_end)?_trace->get_max_date():_time_end) );
// Interval interval(_time_start, ((0==_time_end)?_trace->get_max_date():_time_end) );
if (_DRAW_OPENGL == format) {
......@@ -378,7 +401,7 @@ int Core::get_state(int argc, char** argv){
state = _STATE_OPEN_FILE;
}
else {
cerr << "no filename to open" << endl;
cerr << QObject::tr("no filename to open").toStdString() << endl;
return _STATE_UNKNOWN;
}
}
......@@ -390,7 +413,7 @@ int Core::get_state(int argc, char** argv){
state = _STATE_EXPORT_FILE;
}
else{
cerr << "no filename for export" << endl;
cerr << QObject::tr("no filename for export").toStdString() << endl;
return _STATE_UNKNOWN;
}
}
......@@ -398,11 +421,11 @@ int Core::get_state(int argc, char** argv){
// We want to export the file which follows this argument
extract_times(argv[++ i]);
if(_time_end == -1 || _time_start == -1){
cerr << "One of the time do not exist" << endl;
cerr << QObject::tr("One of the time do not exist").toStdString() << endl;
state = _STATE_LAUNCH_GRAPHICAL_INTERFACE;
}
else if (_time_end < _time_start){
cerr << "The end time is lower than the start one!" << endl;
cerr << QObject::tr("The end time is lower than the start one!").toStdString() << endl;
state = _STATE_LAUNCH_GRAPHICAL_INTERFACE;
}
state |= _STATE_IN_AN_INTERVAL;
......@@ -413,13 +436,13 @@ int Core::get_state(int argc, char** argv){
if((string)argv[i] == "-epsilon") {
i ++;
if(i > argc) {
cerr << "need an other argument for epsilon" << endl;
cerr << QObject::tr("need an other argument for epsilon").toStdString() << endl;
return _STATE_UNKNOWN;
}
else {
double accuracy = convert_to_double(argv[i]);
if(accuracy < 0.) {
cerr << "need a positive accuracy for epsilon" << endl;
cerr << QObject::tr("need a positive accuracy for epsilon").toStdString() << endl;
return _STATE_UNKNOWN;
}
else {
......@@ -705,19 +728,18 @@ void Core::launch_action(int state, void* arg) {
void Core::display_help(){
cerr << endl
<< " *** ViTE ***" << endl << endl << endl
<< "SYNOPSIS:" << endl
<< "vite [argument list]" << endl << endl
<< "ARGUMENT LIST:" << endl
<< "-h : display the help" << endl
<< "(-f) [file path] : open the trace file and display it." << endl
<< "-a [file path] : open the trace file and display all of it." << endl
<< "[file path] -t ([time_init]):([time_end]) : open the trace file and display it in the interval. There could be no time_init or time_end."
<< " In these cases, the trace will be printed from the start and/or to the end." << endl
<< "-f [path-source] -e [path-dest] : export the trace file in the svg format." << endl
<< "-f [path-source] -e [path-dest] -t ([time_init]):([time_end]) : export the trace file in the svg format in the interval given." << endl
<< "[-epsilon float_values][-wide float_values][-grow float_values]"<< endl << endl;
cout << endl
<< "Usage: vite [OPTION...] [[-f] inputfile] [-e outputfile] " << endl
<< endl
<< " -h display this help " << endl
<< " -f inputfile open the inputfile " << endl
<< " -a display all the inputfile (Default)" << endl
<< " -t [T0]:[T1] display the interval [T0:T1] (Default: T0 = 0 and T1 = Tmax)" << endl
<< " -e outputfile export the trace file in the svg format to outpufile" << endl
<< " -epsilon eps specify the epsilon value for export" << endl
<< " -wide w specify the witdh factor for export" << endl
<< " -grow g specify the height factor for export" << endl
<< endl;
}
......@@ -775,3 +797,30 @@ Trace *Core::get_trace() const {
return _trace;
}
void Core::export_variable(Variable *var, string filename) {
const list<pair<Date, Double> > *variable_values = var->get_values();
ofstream file(filename.c_str(), ios::out | ios::trunc);
if(file) {
double first_value = 0.;
double second_value = 0.;
const double min = var->get_min().get_value();
const double max = var->get_max().get_value();
for(list<pair<Date, Double> >::const_iterator value = variable_values->begin();
value != variable_values->end();
value++) {
first_value = (*value).first.get_value();
second_value =((*value).second.get_value()-min)/(max-min) ;
file << first_value << "\t" << second_value << endl;
}
file.close();
}
else {
// Error
_main_window->error("Unable to open " + filename + " in order to export the counter");
}
}
......@@ -28,7 +28,7 @@
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
** ViTE developpers are (for version 0.* to 1.0):
** ViTE developers are (for version 0.* to 1.0):
**
** - COULOMB Kevin
** - FAVERGE Mathieu
......@@ -51,6 +51,7 @@ class Core;
class Interface_graphic;
class Render_opengl;
class Trace;
class Variable;
#include "interface/Interface.hpp"
......@@ -439,8 +440,11 @@ public:
Trace *get_trace() const;
/*!
*\brief Export a counter
* Need to choose a counter, and a filename
*/
void export_variable(Variable *var, std::string filename);
public slots:
......
......@@ -28,7 +28,7 @@
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
** ViTE developpers are (for version 0.* to 1.0):
** ViTE developers are (for version 0.* to 1.0):
**
** - COULOMB Kevin
** - FAVERGE Mathieu
......
......@@ -28,7 +28,7 @@
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
** ViTE developpers are (for version 0.* to 1.0):
** ViTE developers are (for version 0.* to 1.0):
**
** - COULOMB Kevin
** - FAVERGE Mathieu
......@@ -46,6 +46,7 @@
*/
#include <fstream>
#include <string>
#include <stack>
#include <map>
#include <list>
/* -- */
......@@ -56,6 +57,9 @@
#include "common/Tools.hpp"
/* -- */
#include "trace/values/Values.hpp"
#include "trace/EntityTypes.hpp"
#include "trace/Entitys.hpp"
#include "trace/Trace.hpp"
/* -- */
#include "render/render.hpp"
#include "render/render_svg.hpp"
......@@ -102,7 +106,7 @@ Interface_graphic::Interface_graphic(Core* core, QWidget *parent):QMainWindow(pa
setMouseTracking (true);/* to catch mouse events */
_stats_window = new Stats_window(this);
_stats_window = NULL; // Creation when needed (when it has to be shown)
// _cmd_window = NULL;
_cmd_window = new Command_window(this,this);
......@@ -110,7 +114,8 @@ Interface_graphic::Interface_graphic(Core* core, QWidget *parent):QMainWindow(pa
Interface_graphic::~Interface_graphic(){
delete _stats_window;
if(_stats_window != NULL)
delete _stats_window;
/* Qt desallocates this, _ui_info_window and _render_area automatically */
}
......@@ -133,6 +138,8 @@ void Interface_graphic::load_windows(){
QFile file_info( ":/window/info_window.ui");
QFile file_selection_export(":/window/option_export_window.ui");
QFile file_help(":/window/help_window.ui");
QFile file_kind_of_export(":/window/kind_of_export.ui");
QFile file_counter_to_export(":/window/list_of_counter_to_export.ui");
if (!QGLFormat::hasOpenGL())
qFatal("This system has no OpenGL support");
......@@ -147,11 +154,25 @@ void Interface_graphic::load_windows(){
CKFP(_ui_time_selection_export = loader.load(&file_selection_export, this), "Cannot open the .ui file : " << ":/window/option_export_window.ui");
file_selection_export.close();
/* Load the choice counter for export box */
file_counter_to_export.open(QFile::ReadOnly);
CKFP(_ui_counter_choice_to_export = loader.load(&file_counter_to_export, this), "Cannot open the .ui file : " << ":/window/option_export_window.ui");
CKFP(_counter_list_names = qFindChild<QComboBox*>(_ui_counter_choice_to_export, "combobox"), "Cannot find the svg export button in the .ui file");
file_counter_to_export.close();
/* Load the help dialog box from a .ui file */
file_help.open(QFile::ReadOnly);
CKFP(_ui_help_window = loader.load(&file_help, this), "Cannot open the .ui file : " << ":/window/help_window.ui");
file_help.close();
/* Load the export combo box choice from a .ui file */
file_kind_of_export.open(QFile::ReadOnly);
CKFP(_ui_kind_of_export_choice = loader.load(&file_kind_of_export, this), "Cannot open the .ui file : " << ":/window/kind_of_export.ui");
CKFP(_ui_svg_export_button = qFindChild<QRadioButton*>(_ui_kind_of_export_choice, "svg_export"), "Cannot find the svg export button in the .ui file");
CKFP(_ui_counter_export_button = qFindChild<QRadioButton*>(_ui_kind_of_export_choice, "counter_export"), "Cannot find the svg export button in the .ui file");
file_kind_of_export.close();
/* Set some windows properties */
_ui_info_window->setWindowFlags(_ui_info_window->windowFlags() | Qt::WindowStaysOnTopHint);/* Always display info_window on top */
_ui_time_selection_export->setWindowFlags(_ui_time_selection_export->windowFlags() | Qt::WindowStaysOnTopHint);
......@@ -193,6 +214,11 @@ void Interface_graphic::load_windows(){
CKFP(_ui_help_ok_button = qFindChild<QPushButton*>(_ui_help_window, "help_ok"), "Cannot find the ok push button in the help dialog .ui file");
connect(_ui_counter_choice_to_export, SIGNAL(accepted()),
this, SLOT(counter_choosed_triggered()));
connect(_ui_kind_of_export_choice, SIGNAL(accepted()),
this, SLOT(choice_of_the_export_pressed()));
connect(_ui_export_ok_button, SIGNAL(pressed()),
this, SLOT(option_export_ok_pressed()));
......@@ -448,22 +474,58 @@ void Interface_graphic::on_open_triggered(){
}
void Interface_graphic::choice_of_the_export_pressed() {
if(_ui_svg_export_button->isChecked()) {
ostringstream temp;
temp.str("");
temp << Info::Render::_x_min_visible;
_ui_min_time_export->setText(temp.str().c_str());
temp.str("");
temp << Info::Render::_x_max_visible;
_ui_max_time_export->setText(temp.str().c_str());
_ui_time_selection_export->show();
}
else if (_ui_counter_export_button->isChecked()) {
// In order to easily retrieve the good variable, we store them with an index representing the container name followed by the variabletype name (because a variable has no name)
_all_variables.clear();
_core->get_trace()->get_all_variables(_all_variables);
map<string, Variable *>::const_iterator it_end = _all_variables.end();
_counter_list_names->clear();
for(map<string, Variable *>::const_iterator it = _all_variables.begin();
it != it_end ;
it ++) {
_counter_list_names->addItem(QString::fromStdString((*it).first));
}
if(_counter_list_names->count() == 0) {
error("The trace has no counter");
return;
}
_ui_counter_choice_to_export->show();
}
}
void Interface_graphic::counter_choosed_triggered() {
// Il faut faire choisir le nom du fichier! et enfin on peut lancer l'action !
const QString path_by_default = QString(_trace_path.substr(0, _trace_path.find_last_of('.')).c_str()) + ".txt";
QString filename = QFileDialog::getSaveFileName(this, QObject::tr("Export File"),
path_by_default,
QObject::tr("All files"));
Variable *temp = _all_variables[_counter_list_names->currentText().toStdString()];
_core->export_variable(temp, filename.toStdString());
}
void Interface_graphic::on_export_file_triggered(){
if(_is_rendering_trace == false)
return;
ostringstream temp;
temp.str("");
temp << Info::Render::_x_min_visible;
_ui_min_time_export->setText(temp.str().c_str());
temp.str("");
temp << Info::Render::_x_max_visible;
_ui_max_time_export->setText(temp.str().c_str());
_ui_time_selection_export->show();
_ui_kind_of_export_choice->show();
}
void Interface_graphic::option_export_ok_pressed(){
......@@ -619,14 +681,11 @@ void Interface_graphic::on_help_triggered(){
void Interface_graphic::on_about_triggered(){
/* QMessageBox::about(this, tr("About ViTE"),
tr("<b>ViTE</b> is a trace format visualizer developped "
"by french engineering school students for INRIA researchers (<a href='http://www.inria.fr'>http://www.inria.fr</a>).<br/><br/>"
"It is licensed under <i>CECILL-A</i>."));*/
QMessageBox::about(this, tr("About ViTE"),
tr("<h2>ViTE</h2>"
"the <b>Vi</b><i>sual </i><b>T</b><i>race</i> <b>E</b><i>xplorer</i> - <i>version 1.0</i> - <i>June 2009</i>.<br /><br />"
"the <b>Vi</b><i>sual </i><b>T</b><i>race</i> <b>E</b><i>xplorer</i> - <i>version "
VITE_VERSION
"</i> - <i>June 2009</i>.<br /><br />"
"Under the CeCILL A licence. The content can be found <a href=\"http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt\">here</a>."
"<p><b>Developers:</b><ul><li>Kevin COULOMB</li><li>Mathieu FAVERGE</li><li>Johnny JAZEIX</li><li>Olivier LAGRASSE</li><li>Jule MARCOUEILLE</li><li>Pascal NOISETTE</li><li>Arthur REDONDY</li><li>Cl&eacute;ment VUCHENER</li></ul></p>"
"The main page project is: <a href=\"http://vite.gforge.inria.fr/\">http://vite.gforge.inria.fr/</a>.<br /><br />"));
......@@ -634,6 +693,11 @@ void Interface_graphic::on_about_triggered(){
void Interface_graphic::on_show_stats_triggered(){
if(_core->get_trace() != NULL) {
if(_stats_window == NULL) { //Creation of the window
_stats_window = new Stats_window(this);
}
_stats_window->set_filename(_core->get_filename());
_stats_window->set_trace(_core->get_trace());
_stats_window->init_window();
......
......@@ -28,7 +28,7 @@
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
** ViTE developpers are (for version 0.* to 1.0):
** ViTE developers are (for version 0.* to 1.0):
**
** - COULOMB Kevin
** - FAVERGE Mathieu
......@@ -53,7 +53,7 @@ class Core;
class Stats_window;
class Command_window;
class Svg;
class Variable;
#include "ui_main_window.h"/* the main window graphical interface */
......@@ -260,6 +260,27 @@ class Interface_graphic : public QMainWindow, protected Ui::main_window, public
*/
Command_window * _cmd_window;
/***********************************
*
* Export windows.
*
**********************************/
/*!
* \brief ComboBox which allow the choice between svg export and counter export.
*/
QWidget* _ui_kind_of_export_choice;
QRadioButton* _ui_svg_export_button;
QRadioButton* _ui_counter_export_button;
/*!
* \brief ComboBox which allow the choice between all the counters to be exported.
*/
QWidget* _ui_counter_choice_to_export;
QComboBox *_counter_list_names;
std::map <std::string, Variable *> _all_variables;
/***********************************
*
* Help window.
......@@ -460,6 +481,16 @@ protected slots:
*/
void on_export_file_triggered();
/*!
*\brief A slot called when the choice of the export is done and ok.
*/
void choice_of_the_export_pressed();
/*!
*\brief A slot called when the choice of the counter is done and ok.
*/
void counter_choosed_triggered();
/*!
*\brief A slot called when the options in export are ok.
*/
......
<ui version="4.0" >
<class>kind_of_export</class>
<widget class="QDialog" name="kind_of_export" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>369</width>
<height>255</height>
</rect>
</property>
<property name="windowTitle" >
<string>Kind of export</string>
</property>
<property name="windowIcon" >
<iconset resource="vite.qrc" >
<normaloff>:/icon/icon/vite.png</normaloff>:/icon/icon/vite.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" >
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Choose the kind of export:</string>
</property>
<property name="alignment" >
<set>Qt::AlignCenter</set>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" >
<item>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QRadioButton" name="svg_export" >
<property name="text" >
<string>Svg export of all the trace</string>
</property>
<property name="checked" >
<bool>true</bool>
</property>
</widget>