Commit c555e359 authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

First attempt for the export of statistics in svg.

The output file can not be chosen for the moment but it will come soon.
parent 428fb663
......@@ -513,7 +513,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
INPUT = src/interface/ src/message/ src/parser/ src/render/ src/trace/ src/trace/values/ src/trace/tree/ src/main.cpp src/main_resource.hpp src/statistics/ src/Tools.cpp src/Tools.hpp
INPUT = src/interface/ src/message/ src/parser/ src/render/ src/trace/ src/trace/values/ src/trace/tree/ src/main.cpp src/main_resource.hpp src/statistics/ src/general/
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
......
......@@ -169,7 +169,7 @@
<item>
<widget class="QPushButton" name="export_button" >
<property name="enabled" >
<bool>false</bool>
<bool>true</bool>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Fixed" >
......
/*!
*\file render_stats_svg.cpp
*/
#include "render_stats_svg.hpp"
using namespace std;
#define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): "
Render_stats_svg::Render_stats_svg(){
_y_min = 0;
}
Render_stats_svg::~Render_stats_svg(){
}
void Render_stats_svg::set_total_height(Element_pos h) {
_render_height = h;
}
void Render_stats_svg::set_total_width(Element_pos w) {
_render_width = w;
}
void Render_stats_svg::clear(){
}
void Render_stats_svg::fill_file(){
list<Element_pos>::const_iterator it_pos;
list<string>::const_iterator it_txt;
list<Element_pos>::const_iterator it_line;
list<Element_pos>::const_iterator it_rect;
Element_pos buf_x;
Element_pos buf_y;
string buf_txt;
/* Draw rect */
for (it_rect = _rect_pos.begin() ; it_rect!=_rect_pos.end() ; it_rect ++) {
Element_pos x = *it_rect;
it_rect ++;
Element_pos y = *it_rect;
it_rect ++;
Element_pos w = *it_rect;
it_rect ++;
Element_pos h = *it_rect;
it_rect ++;
Element_pos r = *it_rect;
it_rect ++;
Element_pos g = *it_rect;
it_rect ++;
Element_pos b = *it_rect;
_svg_file << "\n<rect width=\"" << w
<<"\" height=\"" << h
<<"\" x=\"" << x
<<"\" y=\"" << y-_y_min
<<"\" fill=\"rgb("<<(int)(r*255)<<","<<(int)(g*255)<<","<<(int)(b*255)
<<")\"/>\n";
}/* end for(...) */
/* Draw lines */
for (it_line=_line_pos.begin() ; it_line!=_line_pos.end() ; it_line ++) {
Element_pos x = *it_line;
it_line ++;
Element_pos y = *it_line;
it_line ++;
Element_pos size_x = *it_line;
it_line ++;
Element_pos size_y = *it_line;
_svg_file << "<line x1=\"" << x <<
"\" y1=\"" << y-_y_min <<
"\" x2=\"" << x+size_x <<
"\" y2=\"" << y-_y_min+size_y <<
"\" stroke=\"black\" />\n";
}/* end for(...) */
/* Draw texts */
for (it_txt=_text_value.begin(), it_pos=_text_pos.begin() ; it_txt!=_text_value.end() ; it_txt ++, it_pos ++) {
buf_x = *it_pos;
it_pos ++;
buf_y = *it_pos;
buf_txt = *it_txt;
_svg_file << "<text x=\"" << buf_x <<"\" y=\"" << buf_y+10-_y_min << "\"> ";
_svg_file << buf_txt;
_svg_file << "</text>";
}/* end for(...) */
}
/*!
*\file render_stats_svg.hpp
*/
#ifndef RENDER_STATS_SVG_HPP
#define RENDER_STATS_SVG_HPP
class Render_stats_svg;
/* Global informations */
#include <iostream>
#include <sstream>
#include <fstream>
#include <list>
#include <string>
#include "render_stats.hpp"
/*!
* \brief This class redefined the Svg export to display the trace.
*/
class Render_stats_svg : public Render_stats {
private:
/*!
* \brief Contains container text coordinates.
*/
std::ofstream _svg_file;
static const double _RENDER_WIDTH_DEFAULT = 550.;
static const double _RENDER_HEIGHT_DEFAULT = 300.;
double _y_min;
/*!
* \brief Contains container text coordinates.
*/
std::list<Element_pos> _text_pos;
/*!
* \brief Contains container strings.
*/
std::list<std::string> _text_value;
/*!
* \brief Contains line coordinates : x, y, size_x, size_y.
*/
std::list<Element_pos> _line_pos;
/*!
* \brief Contains rect coordinates : x, y, w, h, r, g, b.
*/
std::list<Element_pos> _rect_pos;
public:
/*!
* \brief The default constructor
*/
Render_stats_svg();
/*!
* \brief The destructor
*/
~Render_stats_svg();
/*!
* \brief Proceeds with the initialization of draw functions.
*/
void start_draw();
/*!
* \fn draw_text(const Element_pos x, const Element_pos y, const std::string value)
* \brief Draw the text of a container.
* \param x the x position of the text.
* \param y the y position of the text.
* \param value the string value of the text.
*/
void draw_text(const Element_pos x, const Element_pos y, const std::string value);
/*!
* \fn draw_horizontal_line(const Element_pos x, const Element_pos y, const Element_pos size_x)
* \brief Draw a line.
* \param x the x position of the origin.
* \param y the y position of the origin.
* \param size_x the length of the line.
*/
void draw_horizontal_line(const Element_pos x, const Element_pos y, const Element_pos size_x);
/*!
* \fn draw_vertical_line(const Element_pos x, const Element_pos y, const Element_pos size_y)
* \brief Draw a line.
* \param x the x position of the origin.
* \param y the y position of the origin.
* \param size_y the length of the line.
*/
void draw_vertical_line(const Element_pos x, const Element_pos y, const Element_pos size_y);
/*!
* \fn draw_axis(const Element_pos x, const Element_pos y, const Element_pos size_x, const Element_pos size_y)
* \brief Draw axis.
* \param x the x position of the origin.
* \param y the y position of the origin.
* \param size_x the length for the horizontal axis.
* \param size_y the length for the vertical axis.
*/
void draw_axis(const Element_pos x, const Element_pos y, const Element_pos size_x, const Element_pos size_y);
/*!
* \brief Draw a rectangle.
* \param x the x position of the text.
* \param y the y position of the text.
* \param value the string value of the text.
*/
void draw_rect(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h, const Element_pos r, const Element_pos g, const Element_pos b);
/*!
* \brief Proceeds with the end of draw functions.
*/
void end_draw();
/*!
* \brief Set the height of the render area.
*/
void set_total_height(Element_pos h);
/*!
* \brief Set the width of the render area.
*/
void set_total_width(Element_pos w);
void clear();
inline double height(){return _RENDER_HEIGHT_DEFAULT;}
inline double width(){return _RENDER_WIDTH_DEFAULT;}
void updateGL(){}
/*!
\fn fill_file
\brief fill the svg output file with the data.
*/
void fill_file();
};
inline void Render_stats_svg::start_draw(){
_svg_file.open("test.svg", std::ofstream::out | std::ofstream::trunc);
_svg_file << "<?xml version=\"1.1\" encoding=\"utf-8\" standalone=\"no\"?>\n"
<< "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
<< "<svg xmlns=\"http://www.w3.org/2000/svg\" x=\"0\" y=\"0\" id=\"svg2\" style=\"background-color:#c1e9ed;\" >\n"
;
}
inline void Render_stats_svg::draw_text(const Element_pos x, const Element_pos y, const std::string value) {
if(y < _y_min) {
_y_min = y;
}
_text_pos.push_back(x);
_text_pos.push_back(y);
_text_value.push_back(value);
// _svg_file << "<text x=\"" << x <<"\" y=\"" << y+10 << "\"> ";
// _svg_file << value;
// _svg_file << "</text>";
}
inline void Render_stats_svg::draw_horizontal_line(const Element_pos x, const Element_pos y, const Element_pos size_x){
if(y < _y_min) {
_y_min = y;
}
_line_pos.push_back(x);
_line_pos.push_back(y);
_line_pos.push_back(size_x);
_line_pos.push_back(0);
// _svg_file << "<line x1=\"" << x <<
// "\" y1=\"" << y <<
// "\" x2=\"" << x+size_x <<
// "\" y2=\"" << y <<
// "\" stroke=\"black\" />\n";
}
inline void Render_stats_svg::draw_vertical_line(const Element_pos x, const Element_pos y, const Element_pos size_y){
if(y < _y_min) {
_y_min = y;
}
_line_pos.push_back(x);
_line_pos.push_back(y);
_line_pos.push_back(0);
_line_pos.push_back(size_y);
// _svg_file << "<line x1=\"" << x <<
// "\" y1=\"" << y <<
// "\" x2=\"" << x <<
// "\" y2=\"" << y+size_y <<
// "\" stroke=\"black\" />\n";
}
inline void Render_stats_svg::draw_axis(const Element_pos x, const Element_pos y, const Element_pos size_x, const Element_pos size_y){
draw_horizontal_line(x, y, size_x);
draw_vertical_line(x, y, size_y);
}
inline void Render_stats_svg::draw_rect(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h, const Element_pos r, const Element_pos g, const Element_pos b) {
if(y < _y_min) {
_y_min = y;
}
_rect_pos.push_back(x);
_rect_pos.push_back(y);
_rect_pos.push_back(w);
_rect_pos.push_back(h);
_rect_pos.push_back(r);
_rect_pos.push_back(g);
_rect_pos.push_back(b);
// _svg_file << "\n<rect width=\"" << w
// <<"\" height=\"" << h
// <<"\" x=\"" << x
// <<"\" y=\"" << y
// <<"\" fill=\"rgb("<<(int)(r*255)<<","<<(int)(g*255)<<","<<(int)(b*255)
// <<")\"/>\n";
}
inline void Render_stats_svg::end_draw(){
fill_file();
_svg_file << "</svg>\n";
_svg_file.close();
}
#endif
......@@ -46,6 +46,7 @@ HEADERS += message/Message.hpp \
render/render_svg.hpp \
render/render_stats.hpp \
render/render_stats_opengl.hpp \
render/render_stats_svg.hpp \
# render/vbo.hpp \
# Parser headers
parser/Definition.hpp \
......@@ -109,6 +110,7 @@ SOURCES += message/Message.cpp \
render/Render_opengl.cpp \
render/render_svg.cpp \
render/render_stats_opengl.cpp \
render/render_stats_svg.cpp \
# render/vbo.cpp \
# Parser code files
parser/Definition.cpp \
......
......@@ -78,9 +78,7 @@ void Stats_window::init_window() {
}
void Stats_window::on_reload_button_clicked() {
int kind_of_diagram = _kind_of_diagram_box->currentIndex();
void Stats_window::set_selected_nodes(){
// We delete the previous selected containers
if(!_selected_containers.empty()) {
_selected_containers.clear();
......@@ -101,6 +99,13 @@ void Stats_window::on_reload_button_clicked() {
cout << _selected_containers[i]->get_name().to_string() << endl;
}
#endif
}
void Stats_window::on_reload_button_clicked() {
int kind_of_diagram = _kind_of_diagram_box->currentIndex();
set_selected_nodes();
Reinit_scroll_bars();
......@@ -132,6 +137,41 @@ void Stats_window::on_reload_button_clicked() {
delete drawer;
}
void Stats_window::on_export_button_clicked(){
int kind_of_diagram = _kind_of_diagram_box->currentIndex();
set_selected_nodes();
Reinit_scroll_bars();
// We get the times
_start_time = _start_time_widget->text().toDouble();
_end_time = _end_time_widget->text().toDouble();
// We create a drawer
Render_stats_svg svg;
DrawStats<Render_stats_svg> *drawer;
switch (kind_of_diagram)
{
case _HDIAGRAM_INDEX:
drawer = new DrawHDiagram<Render_stats_svg>();
break;
case _DIAGRAM_INDEX:
drawer = new DrawDiagram<Render_stats_svg>();
break;
case _CHART_INDEX:
default:
*Message::get_instance() << _kind_of_diagram_box->currentText().toStdString()
<< " not yet implemented" << Message::endw;
drawer = new DrawHDiagram<Render_stats_svg>();
}
drawer->set_times(_start_time, _end_time);
drawer->build(&svg, _selected_containers);
delete drawer;
}
void Stats_window::close_window(){
_ui_stats_area->doneCurrent();
hide();
......
......@@ -19,6 +19,7 @@ class Stats_window;
#include "../info/info.hpp"
#include "../message/Message.hpp"
#include "../render/render_stats_opengl.hpp"
#include "../render/render_stats_svg.hpp"
#include "DrawStats.hpp"
#include "DrawDiagram.hpp"
#include "DrawHDiagram.hpp"
......@@ -74,10 +75,15 @@ public:
private:
void set_container_names_rec(QTreeWidgetItem *current_node, Container *current_container);
/*!
* \brief Fill the vector of selected containers depending on the ones chosen in the tree widget
*/
void set_selected_nodes();
private slots:
void on_reload_button_clicked();
void on_export_button_clicked();
void on_y_scroll_valueChanged(int new_value);
void on_x_scroll_valueChanged(int new_value);
};
......
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