Commit 86c8a54c authored by Olivier Lagrasse's avatar Olivier Lagrasse

- Correction bug lors du recentrage de la trace. (decalee au niveau des x)

- Ajout de PageUp et PageDown pour faire translation d'un ecran vers la droite et la gauche. (idem vers le haut et le bas avec ALT)
- Modification de la regle.
- Liage de la visualisation d'un intervalle pour OpenGL. (à partir de la ligne de commande)
- La trace n'est plus detruite lors de l'ouverture d'un fichier, ce qui permet de ne plus reparser lors d'un export.
- Debut gestion de l'affichage d'information des entites par clic de souris. (l'affichage n'est pas encore actif)
parent 1bdccca5
......@@ -12,7 +12,11 @@ int Info::Entity::x_max = 0;
bool Info::Render::_key_alt = false;
bool Info::Render::_key_ctrl = false;
Element_pos Info::Render::_x_min_visible = 0;;
Element_pos Info::Render::_x_max_visible = 0.;
Element_pos Info::Render::_x_min_visible = 0.0;
Element_pos Info::Render::_x_max_visible = 0.0;
Element_pos Info::Render::_info_x = 0.0;
Element_pos Info::Render::_info_y = 0.0;
Element_pos Info::Render::_info_accurate = 0.0;
bool Info::Render::_no_arrows_and_events = false;
......@@ -100,6 +100,21 @@ public:
*/
static Element_pos _x_max_visible;
/*!
* \brief Contains the x position of selection.
*/
static Element_pos _info_x;
/*!
* \brief Contains the y position of selection.
*/
static Element_pos _info_y;
/*!
* \brief Contains the accurate position of selection.
*/
static Element_pos _info_accurate;
/*!
* \brief To show the x beginning of the trace.
*/
......
......@@ -53,6 +53,7 @@ Interface_console::Interface_console(int argc, char ** argv){
_main_window = NULL;
_render_opengl = NULL;
_trace = NULL;
/* Init of the times */
_time_start = 0;
......@@ -64,6 +65,11 @@ Interface_console::Interface_console(int argc, char ** argv){
* Suppose that no window will be displayed.
*/
_is_window_displayed = false;
/*
* No trace loaded
*/
_is_trace_loaded = false;
launch_action(_state);
}
......@@ -90,7 +96,7 @@ Interface_console::~Interface_console(){
**********************************/
bool Interface_console::draw_trace(const string & filename, const int format){
Trace trace;
// Trace trace;
ParserPaje parser;
......@@ -114,23 +120,35 @@ bool Interface_console::draw_trace(const string & filename, const int format){
// _progress_dialog->show();
// thread.start();
try{
parser.parse(filename, trace);
}
catch (const string &error) {
Error::print_numbers();
Error::flush_in_file("log.txt");
//delete _progress_dialog;
*Message::get_instance() << "Reason : " << error << Message::ende;
QApplication::restoreOverrideCursor();
return false;
if (NULL == _trace){/* no trace is loaded, parse the file */
_trace = new Trace();
try{
parser.parse(filename, *_trace);
}
catch (const string &error) {
Error::print_numbers();
Error::flush_in_file("log.txt");
//delete _progress_dialog;
*Message::get_instance() << "Reason : " << error << Message::ende;
QApplication::restoreOverrideCursor();
return false;
}
}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;
}
//delete _progress_dialog;
Interval interval(0, trace.get_max_date());
drawing_ogl.build(_render_opengl, &trace, 0, interval);
Interval interval(_time_start, ((0==_time_end)?_trace->get_max_date():_time_end) );
drawing_ogl.build(_render_opengl, _trace, 0, interval);
_render_opengl->build();
_render_opengl->updateGL();
_render_opengl->refresh_scroll_bars();
_is_trace_loaded = true;
}
_file_opened = filename;/* store filename for a future export */
......@@ -145,17 +163,28 @@ bool Interface_console::draw_trace(const string & filename, const int format){
svg.init(_path_to_export.c_str());
DrawTrace<Svg> drawing_svg;
try{
parser.parse(filename, trace);
}
catch (const string &error){
*Message::get_instance() << "Reason : " << error << Message::ende;
QApplication::restoreOverrideCursor();
return false;
if (NULL == _trace){/* no trace is loaded, parse the file */
_trace = new Trace();
try{
parser.parse(filename, *_trace);
}
catch (const string &error){
*Message::get_instance() << "Reason : " << error << Message::ende;
QApplication::restoreOverrideCursor();
return false;
}
}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(0, trace.get_max_date());
drawing_svg.build(&svg, &trace, 0, interval);
Interval interval(_time_start, ((0==_time_end)?_trace->get_max_date():_time_end));
drawing_svg.build(&svg, _trace, 0, interval);
svg.end();
_is_trace_loaded = true;
}
break;
/*******************
......@@ -386,6 +415,8 @@ void Interface_console::extract_times(const char *name) {
void Interface_console::launch_action(int state, void* arg){
DrawTrace<Render_opengl> buf;
switch(state) {
case _STATE_DISPLAY_HELP :
......@@ -468,12 +499,30 @@ void Interface_console::launch_action(int state, void* arg){
cout << "the end of the trace.";
}
launch_action(_STATE_LAUNCH_GRAPHICAL_INTERFACE, NULL);
draw_trace(_file_opened, _DRAW_OPENGL);
break;
case _STATE_RELEASE_RENDER_AREA:
if (_render_opengl->unbuild()==false)
message << "Close file : an error occured with trace releasing." << Message::ende;
_file_opened.clear();
if (false == _is_trace_loaded){
*Message::get_instance() << "Try to release a render area whereas no file was loaded" << Message::ende;
}else{
_is_trace_loaded = false;
}
if (NULL == _trace){
*Message::get_instance() << "Try to release a render area whereas no trace is loaded" << Message::ende;
}else{
delete _trace;
_trace = NULL;
}
_render_opengl->updateGL();
break;
......@@ -522,6 +571,13 @@ void Interface_console::launch_action(int state, void* arg){
_main_window->change_zoom_box_value( *((int*)arg) );
break;
case _STATE_RENDER_DISPLAY_INFORMATION:
buf.display_information(_trace, Info::Render::_info_x, Info::Render::_info_y, Info::Render::_info_accurate);
break;
default:/* like _STATE_UNKNOWN */
display_help();
warning(string("Cannot determine the arguments past. Please check the correct syntax."));
......
......@@ -153,6 +153,11 @@ public:
*/
static const int _STATE_ZOOM_BOX_VALUE = 20;
/*!
*\brief Display information about a selected entity.
*/
static const int _STATE_RENDER_DISPLAY_INFORMATION = 21;
/*!
* \brief Launch an action according to the argument state value.
* \param state An integer corresponding to a kind of action which must be executed.
......@@ -185,6 +190,14 @@ protected:
* are processed. (exportation for example)
*/
bool _is_window_displayed;
/*!
* \brief Use to know if a trace is loaded.
*
* This attributes is used to know for an export if a trace has already be parsed.
*/
bool _is_trace_loaded;
......@@ -209,6 +222,11 @@ protected:
*/
QApplication* app;
/*!
* \brief Contains the trace instance.
*/
Trace* _trace;
/*!
*\brief This attributes contains the launching current directory (_run_env[0]) and the first argument of the running command (_run_env[1]).
*/
......
......@@ -61,8 +61,7 @@ Interface_graphic::~Interface_graphic(){
void Interface_graphic::load_windows(){
QUiLoader loader;
QFile file_main(UI_MAIN_WINDOW_NAME);
QFile file_info(UI_INFO_WINDOW_NAME);
QFile file_info( ":/window/info_window.ui");
QFile file_selection_export(":/window/option_export_window.ui");
......@@ -71,7 +70,7 @@ void Interface_graphic::load_windows(){
/* Load the informative window from a .ui file */
file_info.open(QFile::ReadOnly);
CKFP(_ui_info_window = loader.load(&file_info, this), "Cannot open the .ui file : " << UI_MAIN_WINDOW_NAME);
CKFP(_ui_info_window = loader.load(&file_info, this), "Cannot open the .ui file : " << ":/window/info_window.ui");
file_info.close();
/* Load the _option_export_window from a .ui file */
......
......@@ -43,18 +43,12 @@ class Interface_graphic : public QMainWindow, protected Ui::main_window, public
void load_windows();
/***********************************
*
* Main window widget attributes.
*
**********************************/
/*!
* \brief This variable contains the main window of the application.
*/
//QWidget* _ui_main_window;
/*!
* \brief This variable contains the action to switch in fullscreen mode.
*/
......
......@@ -39,27 +39,6 @@
/* These paths corresponding to the path in the resource file ('vite.qrc' in the 'bin' folder) */
/*!
* \brief The main window ui file.
*/
#define UI_MAIN_WINDOW_NAME ":/window/main_window.ui"
/*!
* \brief The info window ui file.
*/
#define UI_INFO_WINDOW_NAME ":/window/info_window.ui"
/*!
* \brief PI with a precision of 8.
*/
#define PI 3.14159265
/* Now, two checkers are defined (the first for integer return value, the other
for pointer return value). Their body can be empty to enhance program speed.
To pass multi arguments for m, use "<<" between each arguments.
......
......@@ -457,7 +457,7 @@ void Render_opengl::paintGL(){
void Render_opengl::mousePressEvent(QMouseEvent * event){
Element_pos x_click, y_click;/* Store the OpenGL scene point where user had clicked */
Element_pos x_result;//, y_result;/* The click coordinates for the Data Structure. */
Element_pos x_result, y_result;/* The click coordinates for the Data Structure. */
......@@ -537,7 +537,7 @@ void Render_opengl::mousePressEvent(QMouseEvent * event){
/* Work out the y value in Data Structure coordinates */
// y_result = y_click/((Element_pos)_container_height + v_space);
y_result = y_click;///((Element_pos)_container_height + v_space);
/*
* Second, check the x position if user click on the container or other
......@@ -563,6 +563,12 @@ void Render_opengl::mousePressEvent(QMouseEvent * event){
x_result *= (_state_x_max - _state_x_min)/(_render_width*_state_scale);
// message << "Click entity" << x_result << Message::endsi;
Info::Render::_info_x = x_result;
Info::Render::_info_y = y_result;
Info::Render::_info_accurate = _state_x_max/_render_width;
_core->launch_action(Interface_console::_STATE_RENDER_DISPLAY_INFORMATION);
}
}
......@@ -780,13 +786,21 @@ void Render_opengl::keyPressEvent(QKeyEvent * event) {
/*
* Key 'Page Up' pressed.
*/
change_translate_y(-1*ctrl_factor);
// change_translate_y(-1*ctrl_factor);
if (true == Info::Render::_key_alt)
change_translate_y(-_render_height);
else
change_translate(_render_width);
break;
case Qt::Key_PageDown:
/*
* Key 'Page Down' pressed.
*/
change_translate_y(1*ctrl_factor);
// change_translate_y(1*ctrl_factor);
if (true == Info::Render::_key_alt)
change_translate_y(_render_height);
else
change_translate(-_render_width);
break;
default:
......@@ -945,7 +959,7 @@ void Render_opengl::registered_translate(int id){
break;
case Info::Render::X_TRACE_ENTIRE:/* show the entire entities */
_state_translate = 0;
replace_scale(1);
_state_scale = 1;
break;
case Info::Render::Y_TRACE_ENTIRE:/* show the entire entities */
_y_state_translate = 0;
......@@ -1224,7 +1238,21 @@ void Render_opengl::create_ruler(){
Element_pos coeff;
Element_pos buf_number;
Element_pos graduation_distance_per_5;
Element_pos accuracy;/* n */
unsigned int coeff_mul_10;/* n */
Element_pos greatest_graduation;/* n */
unsigned int degree;/* n */
Element_pos _ruler_accuracy_width;/* n */
Element_pos _ruler_accuracy_x;/* n */
unsigned int entire_part;
unsigned int degree_mul_3;
Element_pos coeff_mul_10_3;
_ruler_accuracy_x = 0;
_ruler_accuracy_width = 0;
double ruler_bg_r, ruler_bg_g, ruler_bg_b;/* the ruler background color (in RGB mode)*/
......@@ -1247,12 +1275,78 @@ void Render_opengl::create_ruler(){
graduation_distance_per_5 = graduation_distance/5.0;
_ruler_width = (_render_width*_state_scale+x_min)/_ruler_distance;
/*
* Try to distinct the common number part of each graduation and the distinct part from the left.
* For example, between 3.67834 and 3.67854,
* the common part is: 3.678 and the distinct part is 0.000xx (xx = {34,54})
*
* Work out the bigger difference in the rule among graduations
*/
greatest_graduation = Info::Render::_x_max_visible - Info::Render::_x_min_visible;//max(Info::Render::_x_max_visible, Info::Render::_x_min_visible);
/* Now, determine how many we need to multiply to get a number more than 0.1 */
if (0.0 != greatest_graduation){
degree=0;
for (int i=1 ; greatest_graduation*i < 0.1 ; i*=10){
degree++;
}
coeff_mul_10 = pow(10, degree);
}else{
coeff_mul_10 = 1;
}
/* Then, store the entire part (it is the common part of each graduation number) */
entire_part = floor( Info::Render::_x_max_visible*coeff_mul_10 );
degree_mul_3 = degree+1;
coeff_mul_10_3 = 10;/* 10 -> distinct part will be now between 0<X<1 instead of 0<X<0.1 */
/* Determine the nearest multiple of 3 of degree variable */
while (0 != (degree_mul_3 % 3)){
coeff_mul_10_3*=10;
degree_mul_3++;
}
/* Now, correct to complete graduation numbers if they have 1 or 2 digit in their entire part */
for (unsigned int i = (3 - (degree_mul_3 - degree) ) ; i>0 ; i--){
entire_part = ((int)entire_part)/10;
coeff_mul_10 = ((int)coeff_mul_10)/10;
coeff_mul_10_3 *= 10;
}
if ( (floor( Info::Render::_x_max_visible*coeff_mul_10 ) - floor( Info::Render::_x_min_visible*coeff_mul_10 ) ) != 0 )
coeff_mul_10 = ((int)coeff_mul_10)/10;
/* Draw the accuracy (on the top-left corner) */
glColor3d(1.0, 1.0, 1.0);
glRasterPos2f(_ruler_accuracy_x, _ruler_y+_ruler_height);
buf_txt << entire_part << "Xe-" << degree_mul_3;
for(unsigned int j = 0 ; j < buf_txt.str().length() ; j ++){
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
_ruler_accuracy_width += glutBitmapWidth(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
}
buf_txt.str("");/* flush the buffer */
_ruler_accuracy_width *= _render_width/_screen_width;
/* Now, number is like:
* entire_part * 10^(-degree) + XXX * 10^(-degree_mul_3)
*
* We have to determine the distinct part XXX which is a multiple of 10^(-3).
*/
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
......@@ -1269,6 +1363,18 @@ void Render_opengl::create_ruler(){
glEnd();
/* Draw the ruler foreground */
glBegin(GL_QUADS);
{
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_ruler_accuracy_x, _ruler_y+_ruler_height, _z_ruler_over);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_ruler_accuracy_x, _ruler_y, _z_ruler_over);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_ruler_accuracy_x + _ruler_accuracy_width, _ruler_y, _z_ruler_over);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_ruler_accuracy_x + _ruler_accuracy_width, _ruler_y+_ruler_height, _z_ruler_over);
}
glEnd();
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
......@@ -1301,6 +1407,7 @@ void Render_opengl::create_ruler(){
/* Draw spaced graduation of _ruler_distance */
for (Element_pos i = max(x_min, start_delay) ; i<=min(entity_width+x_min, _render_width) ; i+=graduation_distance){
//for (Element_pos i = Info::Render::_x_min_visible ; i<= Info::Render::_x_max_visible ; i+=graduation_distance){
if (i != min(entity_width+x_min, _render_width) ){/* prepare small graduations between the current and the next main graduation */
......@@ -1329,22 +1436,29 @@ void Render_opengl::create_ruler(){
glColor3d(1.0, 1.0, 1.0);
glRasterPos2f(i, _ruler_y+_ruler_height);
buf_number = (i - x_min)*coeff/_state_scale;
/* trunc numbers to a maximum of 4 digits */
buf_number = floor(buf_number*1000.0)/1000.0;
/* trunc numbers to a maximum of 3 digits */
buf_number = buf_number*coeff_mul_10 - floor( Info::Render::_x_min_visible*coeff_mul_10 );//floor(buf_number*coeff_mul_10);/* Get the distinct part */
buf_number*=coeff_mul_10_3;/* Mul the distinct part to be a multiple of 10^3 */
buf_number = floor(buf_number);
buf_txt << buf_number;
for(unsigned int j = 0 ; j < buf_txt.str().length() ; j ++){
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
if ( max(_x_scale_container_state*_render_width, _ruler_accuracy_x + _ruler_accuracy_width) < (i+1) )
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
}
buf_txt.str("");/* flush the buffer */
}
/* Draw the ended graduation line */
glBegin(GL_LINES);
{
......@@ -1352,156 +1466,8 @@ void Render_opengl::create_ruler(){
glColor3d(0.6, 0.6, 1.0);glVertex3d(_ruler_width*_ruler_distance, _ruler_y+_ruler_height, _z_ruler);
}
glEnd();
/* Draw the ended graduation text */
/* glColor3d(1.0, 1.0, 1.0);
glRasterPos2f(entity_width, _ruler_y+_ruler_height);
buf_txt << (_ruler_width*_ruler_distance-x_min)*coeff;
for(unsigned int j=0;j<buf_txt.str().length();j++){
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
}
*/
}
// void Render_opengl::create_ruler(){
// ostringstream buf_txt;
// Element_pos _ruler_width;
// Element_pos entity_width;
// Element_pos graduation_distance;
// Element_pos x_min;
// Element_pos start_delay;
// Element_pos coeff;
// Element_pos buf_number;
// Element_pos graduation_distance_per_5;
// int units;
// int ten_units;
// Element_pos buf_g_d;
// units = 0;//3;
// ten_units = 1;//1000;
// coeff = (_state_x_max - _state_x_min)/_render_width;/* from [0;100] to [_state_x_min;_state_x_max], used to obtain correct coordinate texts */
// entity_width = _render_width*_state_scale;/* the render width from a given scale */
// graduation_distance = entity_width/ceil(entity_width/_ruler_distance);/* distance between two graduations calculated from a desire distance */
// x_min = _default_entity_x_translate-_state_translate;/* received the first integer inside render width */
// start_delay = x_min - graduation_distance*floor(x_min/graduation_distance);/* delaying ruler start at 0.0 x coordinate to fit with graduation distance */
// graduation_distance_per_5 = graduation_distance/5.0;
// _ruler_width = (_render_width*_state_scale+x_min)/_ruler_distance;
// /* Calculate the ruler unit (cm, mm, um, nm, ...) */
// buf_g_d = _state_x_max/((double)_state_scale);
// /* cerr << buf_g_d << endl;
// while( (buf_g_d > 0.0) && (buf_g_d <= 1.0) ){
// buf_g_d *= 10.0;
// units ++;
// ten_units *= 10;
// }*/
// /* Draw the ruler top line */
// glColor3d(1.0, 1.0, 1.0);
// glBegin(GL_LINES);
// {
// glVertex3d(max(x_min, 0.0), _ruler_y, _z_ruler);
// glVertex3d(entity_width+x_min, _ruler_y, _z_ruler);
// }
// glEnd();
// if ( (x_min<0.0) && ((entity_width+x_min)>graduation_distance)){/* we are not viewing the beginning of the trace (i.e. the 0.0 coordinate) but we still viewing the trace (not after the end) */
// /* draw previous small graduations */
// for (char k=1 ; k<5 ; k++){
// glBegin(GL_LINES);
// {
// glColor3d(1.0, 1.0, 1.0);glVertex3d(start_delay-k*graduation_distance_per_5, _ruler_y, _z_ruler);
// glColor3d(1.0, 0.6, 0.6);glVertex3d(start_delay-k*graduation_distance_per_5, _ruler_y+_ruler_height/3.0, _z_ruler);
// }
// glEnd();
// }
// }
// /* Draw spaced graduation of _ruler_distance */
// for (Element_pos i=max(x_min, start_delay) ; i<=min(entity_width+x_min, _render_width) ; i+=graduation_distance){
// if (i != min(entity_width+x_min, _render_width) ){/* prepare small graduations between the current and the next main graduation */
// /* draw small graduations */
// for (char k=1 ; k<5 ; k++){
// glBegin(GL_LINES);
// {
// glColor3d(1.0, 1.0, 1.0);glVertex3d(i+k*graduation_distance_per_5, _ruler_y, _z_ruler);
// glColor3d(1.0, 0.6, 0.6);glVertex3d(i+k*graduation_distance_per_5, _ruler_y+_ruler_height/3.0, _z_ruler);
// }
// glEnd();
// }
// }
// /* Draw the main graduation line */
// glBegin(GL_LINES);
// {
// glColor3d(1.0, 1.0, 1.0);glVertex3d(i, _ruler_y, _z_ruler);
// glColor3d(1.0, 0.6, 0.6);glVertex3d(i, _ruler_y+_ruler_height, _z_ruler);
// }
// glEnd();
// /* Draw the graduation text */
// glColor3d(1.0, 1.0, 1.0);
// glRasterPos2f(i, _ruler_y+_ruler_height);
// buf_number = (i - x_min)*coeff/_state_scale;
// /* trunc numbers */
// buf_number = floor(buf_number*ten_units);
// buf_txt << buf_number;
// for(unsigned int j=0;j<buf_txt.str().length();j++){
// glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
// }
// buf_txt.str("");/* flush the buffer */
// }
// /* Draw the ended graduation line */
// glBegin(GL_LINES);
// {
// glColor3d(1.0, 1.0, 1.0);glVertex3d(_ruler_width*_ruler_distance, _ruler_y, _z_ruler);
// glColor3d(1.0, 0.6, 0.6);glVertex3d(_ruler_width*_ruler_distance, _ruler_y+_ruler_height, _z_ruler);
// }
// glEnd();
// /* Indicate the unit */
// glColor3d(1.0, 1.0, 1.0);
// glRasterPos2f(0, _ruler_y+_ruler_height);
// buf_txt << "10^-" << units;
// for(unsigned int j=0;j<buf_txt.str().length();j++){
// glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
// }
// }
void Render_opengl::set_total_width(Element_pos){}
......
<