Commit 301638f6 authored by Johnny Jazeix's avatar Johnny Jazeix
Browse files

window for the choice of the name of the export file and some handling

of errors. Starting of the improvment of the render_svg
parent d111f194
......@@ -406,7 +406,7 @@ void Interface_graphic::option_export_ok_pressed(){
}
else{
_core->set_min_value_for_export(0);
_core->set_max_value_for_export(1000);//TO DO TODO max_size de la trace?
_core->set_max_value_for_export(Info::Entity::x_max);//TO DO TODO max_size de la trace?
}
// We configure the svg exporter
double accuracy = convert_to_double(_ui_accuracy_export->text().toStdString());
......
......@@ -7,7 +7,8 @@ using namespace std;
#define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): "
Render_stats_svg::Render_stats_svg(){
Render_stats_svg::Render_stats_svg(string filename){
_filename = filename;
_y_min = 0;
_y_max = 0;
}
......
......@@ -11,6 +11,7 @@ class Render_stats_svg;
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <string>
#include "render_stats.hpp"
......@@ -27,6 +28,7 @@ private:
* \brief Contains container text coordinates.
*/
std::ofstream _svg_file;
std::string _filename;
static const double _RENDER_WIDTH_DEFAULT = 550.;
static const double _RENDER_HEIGHT_DEFAULT = 300.;
......@@ -55,7 +57,7 @@ public:
/*!
* \brief The default constructor
*/
Render_stats_svg();
Render_stats_svg(std::string filename);
/*!
* \brief The destructor
......@@ -141,8 +143,8 @@ public:
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"
_svg_file.open(_filename.c_str(), std::ofstream::out | std::ofstream::trunc);
_svg_file << "<?xml version=\"1.0\" 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"
;
......@@ -155,9 +157,6 @@ inline void Render_stats_svg::draw_text(const Element_pos x, const Element_pos 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){
......@@ -168,11 +167,6 @@ inline void Render_stats_svg::draw_horizontal_line(const Element_pos x, const El
_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){
......@@ -184,12 +178,6 @@ inline void Render_stats_svg::draw_vertical_line(const Element_pos x, const Elem
_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){
......
......@@ -43,47 +43,29 @@ void Svg::init(const char *path){
_svg_file.open(path, ofstream::out | ofstream::trunc);
if (!_svg_file.is_open()) {
#ifdef TEST_SVG_MODE
cerr<<"unable to open file";
#else
// message_ns::message << "unable to open file " << message_ns::ende;
#endif
*Message::get_instance() << "Unable to open " << path << Message::ende;
}
#ifndef TEST_SVG_MODE
//message_ns::message << "openning " << message_ns::endi;
#endif
#ifdef TEST_SVG_MODE
cout<< "openning " << path << endl;
#else
//message_ns::message << "openning " << message_ns::endi;
#endif
_buffer << "<?xml version='1.0' encoding='utf-8' standalone='no'?>\n"
<< "<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20010904//EN' 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>\n"
<< "<svg xmlns='http://www.w3.org/2000/svg' x='0' y='0' id='svg2' style='background-color:#c1e9ed;' >\n"
_buffer << "<?xml version=\"1.0\" 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"
<< "\t<style type='text/css' id='stylecss' >\n"
<< "\t\t#undef\n"
<< "\t\t\t{\n"
<< "\t\t\t\tfill:url(#Degrade);\n"
<< "\t\t\t}\n"
<< "\t\tline\n"
<< "\t\t\t{\n"
<< "\t\t\t\tstroke:white;stroke-width:1\n"
<< "\t\t\t}\n"
<< "\t\tpolyline\n"
<< "\t\t\t{\n"
<< "\t\t\t\tfill:white;stroke:white;stroke-width:1\n"
<< "\t\t\t}\n"
<< "\t\tpath\n"
<< "\t\t\t{\n"
<< "\t\t\t\tfill:none;stroke:green;stroke-width:1\n"
<< "\t\t\t}\n"
<< "\t\ttext\n"
<< "\t\t\t{\n"
<< "\t\t\t\tfill:black;font-size:8px;\n"
<< "\t\t\t}\n"
<< "\t\t#undef {\n"
<< "\t\t\tfill:url(#Degrade);\n"
<< "\t\t}\n"
<< "\t\tline {\n"
<< "\t\t\tstroke:white;stroke-width:1\n"
<< "\t\t}\n"
<< "\t\tpolyline {\n"
<< "\t\t\tfill:white;stroke:white;stroke-width:1\n"
<< "\t\t}\n"
<< "\t\tpath {\n"
<< "\t\t\tfill:none;stroke:green;stroke-width:1\n"
<< "\t\t}\n"
<< "\t\ttext {\n"
<< "\t\t\tfill:black;font-size:8px;\n"
<< "\t\t}\n"
<< "\t</style>\n"
<< "\t<desc>Rectangles</desc>\n"
<< "<g>"
......@@ -101,26 +83,26 @@ void Svg::init(const char *path){
void Svg::end(){
if (_debug_svg_already_closed_once) {
cerr<<"Svg::end() already called";
*Message::get_instance()<<"Svg::end() already called" << Message::ende;
return;
}
else {
_debug_svg_already_closed_once = true;
}
_svg_file.write(_buffer.str().c_str(), _buffer.str().size());
_svg_file.write(_buffer.str().c_str(), _buffer.str().size());
_buffer.flush();
_buffer.str("");
_svg_file.write(_chronogramme.str().c_str(), _chronogramme.str().size());
_svg_file.write(_chronogramme.str().c_str(), _chronogramme.str().size());
_chronogramme.flush();
_chronogramme.str("");
display_time_scale();
_thin_element_buffer << "\n<line id='cursor' x1='550' y1='0' x2='550' y2='100%' style='display:none;stroke:black;stroke-width:0.5'/><script><![CDATA[var cursor = document.getElementById('cursor');cursor.style.display='';document.onmousemove = function (event){cursor.setAttribute('x1',event.clientX);cursor.setAttribute('x2',event.clientX);}]]> </script></g></svg>";
_thin_element_buffer << "\n<line id='cursor' x1='550' y1='0' x2='550' y2='100%' style='display:none;stroke:black;stroke-width:0.5'/><script><![CDATA[var cursor = document.getElementById('cursor');cursor.style.display='';document.onmousemove = function (event){cursor.setAttribute('x1',event.clientX);cursor.setAttribute('x2',event.clientX);}]]> </script></g></svg>";
_svg_file.write(_thin_element_buffer.str().c_str(), _thin_element_buffer.str().size());
_thin_element_buffer.flush();
_thin_element_buffer.str("");
......@@ -128,7 +110,6 @@ void Svg::end(){
_svg_file.close();
cout<< "output written" << endl;
#ifdef TEST_SVG_MODE
cout<< "output written" << endl;
#else
......@@ -190,8 +171,8 @@ void Svg::display_time_scale() {
}
void Svg::set_height_factor (Element_pos w) {
_height_factor = w;
void Svg::set_height_factor (Element_pos h) {
_height_factor = h;
}
void Svg::set_wide_factor (Element_pos w) {
......@@ -207,23 +188,23 @@ Element_pos Svg::get_wide_factor() {
}
void Svg::set_interval(Times t1, Times t2) {
void Svg::set_interval(const Times t1, const Times t2) {
_start_interval_time = t1;
_end_interval_time = t2;
}
void Svg::set_accuracy(double epsilon) {
void Svg::set_accuracy(const double epsilon) {
_epsilon = epsilon;
}
void Svg::set_scale_frequency(Element_pos w) {
void Svg::set_scale_frequency(const Element_pos w) {
_scale_frequency = w;
}
void Svg::set_total_width(Element_pos) {
void Svg::set_total_width(const Element_pos) {
}
void Svg::set_total_time(Times) {
void Svg::set_total_time(const Times) {
}
Svg::~Svg() {
......
......@@ -11,6 +11,7 @@
#include "render.hpp"
#include "../message/Message.hpp"
#include "resource.hpp"
/*!
......@@ -181,20 +182,20 @@ public:
/*!
* \brief Trace can be exported on a selected period of time, starting with _start_interval_time and endding with _end_interval_time, default 0 (no upper selection) and command line changed with -t _start_interval_time _end_interval_time or the static svg::set_interval(Times t1,Times t2)
*/
static void set_interval(Times t1, Times t2);
static void set_interval(const Times t1, const Times t2);
/*!
* \brief Set the precision of SVG display.
* \param epsilon Precision
*/
static void set_accuracy(double epsilon);
static void set_accuracy(const double epsilon);
/*!
* \brief Svg display is widden by _wide_factor (in pixel/second), default 100, and command line changed with -w _wide_factor
*/
static void set_wide_factor (Element_pos w);
static void set_wide_factor (const Element_pos w);
/*!
* \brief Svg display is grown by _height
*/
static void set_height_factor (Element_pos w);
static void set_height_factor (const Element_pos h);
/*!
* \brief Return the height factor.
......@@ -211,7 +212,7 @@ public:
/*!
* \brief the scale can be more accurate by increasing the _scale_frequency
*/
static void set_scale_frequency(Element_pos w);
static void set_scale_frequency(const Element_pos w);
......@@ -221,11 +222,11 @@ public:
/*!
* \brief The width of the trace
*/
void set_total_width(Element_pos);
void set_total_width(const Element_pos);
/*!
* \brief The time span of the trace
*/
void set_total_time(Times);
void set_total_time(const Times);
......
......@@ -107,6 +107,11 @@ void Stats_window::on_reload_button_clicked() {
set_selected_nodes();
if(_selected_containers.empty()) {
*Message::get_instance() << "You must select at least one container to view the stats" << Message::ende;
return ;
}
Reinit_scroll_bars();
// We get the times
......@@ -142,14 +147,33 @@ void Stats_window::on_export_button_clicked(){
set_selected_nodes();
if(_selected_containers.empty()) {
*Message::get_instance() << "You must select at least one container to export the stats" << Message::ende;
return ;
}
Reinit_scroll_bars();
// We get the times
_start_time = _start_time_widget->text().toDouble();
_end_time = _end_time_widget->text().toDouble();
QString filename = QFileDialog::getSaveFileName(this, tr("Export File"),
QString(),
tr("Images (*.svg)"));
if (filename.isEmpty()) {
*Message::get_instance() << "You must select a name for the file" << Message::ende;
return ;
}
else {
// Adding .svg to the end
if(!filename.endsWith(".svg")) {
filename += ".svg";
}
}
// We create a drawer
Render_stats_svg svg;
Render_stats_svg svg(filename.toStdString());
DrawStats<Render_stats_svg> *drawer;
switch (kind_of_diagram)
{
......
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