Commit 0633b3f2 authored by Pascal Noisette's avatar Pascal Noisette

arguments en tout genre : interval epsilon wide grow

parent 7db09a54
......@@ -173,6 +173,14 @@ int Interface_console::run(){
**********************************/
int Interface_console::get_state(int argc, char** argv){
/*The folowing statics must be initialised in case their are not overrided by a command line request*/
Svg::set_height_factor (20);
Svg::set_wide_factor (100);
Svg::set_interval(0,0);
Svg::set_accuracy(0.1);
//Error::set_priority_min_printable(Error::_EVERYTHING);
if(argc == 1){
......@@ -182,6 +190,10 @@ int Interface_console::get_state(int argc, char** argv){
int state = _STATE_DISPLAY_HELP;
for(int i = 1 ; i < argc ; i ++){
if(strncmp(argv[i], "-h", 2) == 0){
......@@ -200,7 +212,7 @@ int Interface_console::get_state(int argc, char** argv){
return _STATE_UNKNOWN;
}
}
else if(strncmp(argv[i], "-e", 2) == 0){
else if(strncmp(argv[i], "-e", 3) == 0){
// We want to export the file which follow this argument
i ++;
if(i < argc){
......@@ -219,9 +231,90 @@ int Interface_console::get_state(int argc, char** argv){
}
else if(argv[i][0] == '-'){
// This is here where we put new options !! (for filters for example or export)
return _STATE_UNKNOWN;
}
else{ // This is a file to open
if(strncmp(argv[i],"-epsilon",8) == 0){
if (!(i + 1 < argc)) {
cerr << "epsilon argc" << endl;
return _STATE_UNKNOWN;
}
if (!(argv[i +1 ][0] != '-')){
cerr << "epsilon -" << endl;
return _STATE_UNKNOWN;
}
Svg::set_accuracy(atof(argv[i+1]));
}
else if(strncmp(argv[i],"-interval",9) == 0){
if (!(i +2 < argc) ) {
cerr << "interval argc" << endl;
return _STATE_UNKNOWN;
}
if (!(argv[i+1][0] != '-')) {
cerr << "interval -" << endl;
return _STATE_UNKNOWN;
}
if (!(argv[i+2][0] != '-')) {
cerr << "interval -" << endl;
return _STATE_UNKNOWN;
}
double t1 = atof(argv[i+1]);
double t2 = atof(argv[i+2]);
if ((t1>=t2)) {
cerr << "interval neg" << endl;
return _STATE_UNKNOWN;
}
Svg::set_interval(t1,t2);
}
else if(strncmp(argv[i],"-wide",5) == 0){
if (!(i + 1 < argc)) {
cerr << "wide argc" << endl;
return _STATE_UNKNOWN;
}
if (!(argv[i + 1 ][0] != '-')) {
cerr << "wide -" << endl;
return _STATE_UNKNOWN;
}
Svg::set_wide_factor(atof(argv[i+1]));
}
else if(strncmp(argv[i],"-grow",5) == 0){
if (!(i + 1 < argc)) {
cerr << "grow argc" << endl;
return _STATE_UNKNOWN;
}
if (!(argv[i + 1 ][0] != '-')){
cerr << "grow -" << endl;
return _STATE_UNKNOWN;
}
Svg::set_height_factor(atof(argv[i+1]));
}
else
{
cerr << "any" << endl;
return _STATE_UNKNOWN;
}
}
else{ // This is a file to open
_file_opened = argv[i];
state |= _STATE_OPEN_FILE;
}
......@@ -379,7 +472,8 @@ void Interface_console::display_help(){
<< "[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 << 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][-interval (lower|0) (upper|0) ][-wide float_values][-grow float_values]"<< endl << endl;
}
......
......@@ -3,11 +3,35 @@
using namespace std;
void Svg::init(const char *path){
_container_width_max = 0;
_debug_svg_already_closed_once = false;
std::cerr<< "interval : [";
std::cerr<< _start_interval_time;
if ( _end_interval_time==0)
std::cerr<<"+oo" << endl;
else
std::cerr<<_end_interval_time << endl;
std::cerr<< "wide factor :";
std::cerr<<_wide_factor << endl;
std::cerr<< "height factor : ";
std::cerr<< _height_factor << endl;
std::cerr<< "accuracy : ";
std::cerr<< _epsilon << endl;
_container_width_max = 0;
_container_height_min = 1280;
_epsilon = 0.1;
_svg_file.open(path , std::ofstream::out | std::ofstream::trunc);
......@@ -69,6 +93,15 @@ void Svg::init(const char *path){
void Svg::end(){
if (_debug_svg_already_closed_once)
{
std::cerr<<"Svg::end() a deja été appellé";
return;
}
else
{
_debug_svg_already_closed_once = true;
}
_svg_file.write(_buffer.str().c_str(), _buffer.str().size());
_buffer.flush();
......@@ -90,7 +123,7 @@ void Svg::end(){
_svg_file.close();
std::cout<< "output written" << endl;
#ifdef TEST_SVG_MODE
std::cout<< "output written" << endl;
#else
......@@ -100,15 +133,13 @@ void Svg::end(){
}
void Svg::set_accuracy(double epsilon){
_epsilon = epsilon;
}
void Svg::display_time_scale()
{
Element_pos w = _total_width*WIDE;
Element_pos w = _total_width*_wide_factor;
Element_pos h = MARGINTOP;
Element_pos x = _container_width_max + MARGINSTATE;
Element_pos y = 0;
......@@ -129,5 +160,36 @@ void Svg::set_accuracy(double epsilon){
}
void Svg::set_total_width(Element_pos w){}
void Svg::set_total_time(Times t){}
void Svg::set_height_factor (Element_pos w){
_height_factor = w;
}
void Svg::set_wide_factor (Element_pos w){
_wide_factor = w;
}
void Svg::set_interval(Times t1,Times t2){
_start_interval_time = t1;
_end_interval_time = t2;
}
void Svg::set_accuracy(double epsilon){
_epsilon = epsilon;
}
void Svg::set_total_width(Element_pos){
}
void Svg::set_total_time(Times){
}
Svg::~Svg(){
}
......@@ -9,12 +9,7 @@
#include <sstream>
#include <fstream>
/*
*\brief height of containers
*/
#define LEVEL 20
/*
*\brief Distance between two container
......@@ -26,10 +21,6 @@
*/
#define ARROWSIZE 2
/*
*\brief Default width of an element
*/
#define WIDE 1000
/*
*\brief Distance between two states
......@@ -65,6 +56,40 @@
#define max(a,b) (a>b?a:b);
#define min(a,b) (a>b?b:a);
/*!
* \brief Trace can be exported on a selected period of time, beginning with _start_interval_time, default 0 and command line changed with -t _start_interval_time _end_interval_time or the static svg::set_interval(Times t1,Times t2)
*/
static Times _start_interval_time;
/*!
* \brief Trace can be exported on a selected period of time, 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 Times _end_interval_time;
/*!
* \brief Svg display is widden by _wide_factor (in pixel/second), default 100, and command line changed with -w _wide_factor
*/
static Element_pos _wide_factor;
/*
*\brief Svg display is grown by _height_factor (in pixel/second), default 20, and command line changed with -w _wide_factor
It corresponds to the height of a containers in pixel
*/
static Element_pos _height_factor;
/*!
* \brief accuracy required : an element less wide than _epsilon will not be printed
*/
static double _epsilon;
/*!
* \brief This class provides a SVG display ,it inherited from the Render interface.
*/
......@@ -113,45 +138,86 @@ private:
*/
Element_pos _container_height_min;
/*!
* \brief accuracy required : an element less wide than _epsilon will not be printed
*/
double _epsilon;
/*!
* \brief Statistics and Informations about input trace
* \brief Statistics and Informations about input trace computed in live
*/
Element_pos _total_width;
/*!
* \brief Statistics and Informations about input trace
* \brief Statistics and Informations about input trace computed in live
*/
Times _total_time;
/*!
* \brief Statistics and Informations about input trace computed in live
*/
bool _debug_svg_already_closed_once;
/*!
* \brief flush the buffer containing svg element on the file
*/
inline void print();
/*!
* \brief add a rectangle to the buffer of drawing
*/
inline void rectangle(const char* name,Element_pos w, Element_pos h,Element_pos x1,Element_pos y1, unsigned int r, unsigned int g, unsigned int b );
/*!
* \brief add a line to the buffer of drawing
*/
inline void line(const char* name, Element_pos x1, Element_pos y1, Element_pos x2, Element_pos y2);
/*!
* \brief add a triangle shape to the buffer of drawing
*/
inline void triangle(const char* name,Element_pos x1,Element_pos y1,Element_pos x2,Element_pos y2, Element_pos x3,Element_pos y3);
public:
/*STATIC : allows commands line parameter*/
/*!
* \brief display the scale
* \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)
*/
void display_time_scale();
static void set_interval(Times t1,Times t2);
/*!
* \brief Set the precision of SVG display.
* \param epsilon Precision
*/
static void set_accuracy(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);
/*!
* \brief Svg display is grown by _height
*/
static void set_height_factor (Element_pos w);
/*Statistics : not yet implemented*/
/*!
* \brief Set Statistics and Informations about input trace
*/
void set_total_width(Element_pos w);
* \brief The width of the trace
*/
void set_total_width(Element_pos);
/*!
* \brief The time span of the trace
*/
void set_total_time(Times);
/*drawing functions*/
/*!
* \brief Set Statistics and Informations about input trace
*/
void set_total_time(Times t);
/*!
* \brief SVG header buiding
*/
......@@ -163,12 +229,12 @@ public:
void end();
/*!
/*!
* \brief unused
*/
void start_draw();
/*!
/*!
* \brief unused
*/
void start_draw_containers();
......@@ -186,12 +252,12 @@ public:
* \brief Draw associated container name
*/
void draw_container_text(const Element_pos x, const Element_pos y, const std::string value);
/*!
/*!
* \brief unused
*/
void end_draw_containers();
/*!
/*!
* \brief unused
*/
void start_draw_states();
......@@ -224,44 +290,47 @@ public:
*/
void end_draw_arrows();
/*!
/*!
* \brief unused
*/
void end_draw_states();
/*!
* \brief not yet implemented
/*!
* \brief warning : not yet implemented
*/
void draw_event(const Element_pos time, const Element_pos height, const Element_pos container_height);
/*!
/*!
* \brief initialise drawer automaton
*/
void start_draw_counter();
/*!
/*!
* \brief add a point or switch chronogramme drawing
*/
void draw_counter(const Element_pos x, const Element_pos y);
/*!
/*!
* \brief close drawer automaton
*/
void end_draw_counter();
/*!
/*!
* \brief display the scale
*/
void display_time_scale();
/*!
* \brief unused
*/
void end_draw();
/*!
* \brief Set the precision of SVG display.
* \param epsilon Precision
*/
void set_accuracy(double epsilon);
~Svg();
};
......@@ -287,8 +356,8 @@ inline void Svg::draw_container_text(const Element_pos x, const Element_pos y, c
Element_pos xprime,yprime;
yprime = LEVEL*y + MARGINTOP;
xprime = LEVEL*x;
yprime = _height_factor*y + MARGINTOP;
xprime = _height_factor*x;
_thin_element_buffer << "<text x='" << xprime <<"' y='" << yprime << "'> ";
_thin_element_buffer << value;
......@@ -321,8 +390,8 @@ inline void Svg::start_draw_counter(){
inline void Svg::draw_counter(const Element_pos x, const Element_pos y){
Element_pos xprime = x*WIDE + _container_width_max ;
Element_pos yprime = y*LEVEL + MARGINTOP;
Element_pos xprime = x*_wide_factor + _container_width_max ;
Element_pos yprime = y* _height_factor + MARGINTOP;
Element_pos switchvalue = _container_width_max;
......@@ -381,7 +450,7 @@ inline void Svg::end_draw_counter(){
inline void Svg::end_draw(){
Svg::end();
}
void Svg::rectangle(const char* name,Element_pos w, Element_pos h,Element_pos x1,Element_pos y1, unsigned int r, unsigned int g, unsigned int b ){
......@@ -432,10 +501,10 @@ inline void Svg::draw_arrow(const Element_pos start_time, const Element_pos end_
Element_pos x1=(start_time )*WIDE + _container_width_max ;
Element_pos y1=start_height*LEVEL + MARGINTOP;
Element_pos x2=(end_time)*WIDE+ _container_width_max;
Element_pos y2=end_height*LEVEL + MARGINTOP;
Element_pos x1=(start_time )*_wide_factor + _container_width_max ;
Element_pos y1=start_height* _height_factor + MARGINTOP;
Element_pos x2=(end_time)*_wide_factor+ _container_width_max;
Element_pos y2=end_height* _height_factor + MARGINTOP;
Svg::line("arrow",x1 ,y1 ,x2,y2);
......@@ -451,10 +520,10 @@ inline void Svg::draw_container(const Element_pos x, const Element_pos y, const
Element_pos xprime,yprime,wprime,hprime;
wprime = LEVEL*w;
hprime = LEVEL*h;
yprime = LEVEL*y + MARGINTOP;
xprime = LEVEL*x;
wprime = _height_factor*w;
hprime = _height_factor*h;
yprime = _height_factor*y + MARGINTOP;
xprime = _height_factor*x;
......@@ -471,10 +540,10 @@ inline void Svg::draw_state(const Element_pos start , const Element_pos end, con
Element_pos w =end*WIDE-start*WIDE;
Element_pos w =end*_wide_factor-start*_wide_factor;
Element_pos h = _container_height_min;
Element_pos x = (start )*WIDE+ _container_width_max + MARGINSTATE;
Element_pos y = level*LEVEL + MARGINTOP;
Element_pos x = (start )*_wide_factor+ _container_width_max + MARGINSTATE;
Element_pos y = level* _height_factor + MARGINTOP;
if(w<_epsilon){
......
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