Commit 97100bba authored by Augustin Degomme's avatar Augustin Degomme
Browse files

small corrections, warnings removed

slight render optimizations for events and links drawing 
colors are now stored on floats and no longer on double for rendering
parent 85c12356
......@@ -94,7 +94,7 @@ typedef double Element_pos;
/*!
* \brief Unity for colors
*/
typedef double Element_col;
typedef float Element_col;
/*!
* \brief Define the unity of time.
......
......@@ -173,7 +173,7 @@ Core::Core(int &argc, char ** argv){
*/
_is_trace_loaded = false;
launch_action(_state);
launch_action(_state, NULL);
}
......@@ -445,7 +445,7 @@ static struct option long_options[] =
};
#endif
int Core::get_state(int argc, char** argv){
int Core::get_state(int& argc, char** argv){
int state = 0;
int opt = 0;
int c;
......@@ -474,7 +474,7 @@ int Core::get_state(int argc, char** argv){
if ( sscanf( optarg, ":%lf", &t2) == 1 ) {
_time_end = t2;
} else {
cerr << QObject::tr("Interval is not in the correct format [\%d:\%d]").toStdString() << endl;
cerr << QObject::tr("Interval is not in the correct format [%d:%d]").toStdString() << endl;
return _STATE_DISPLAY_HELP;
}
} else {
......@@ -486,7 +486,7 @@ int Core::get_state(int argc, char** argv){
_time_start = t1;
break;
case 0:
cerr << QObject::tr("Interval is not in the correct format [\%d:\%d]").toStdString() << endl;
cerr << QObject::tr("Interval is not in the correct format [%d:%d]").toStdString() << endl;
return _STATE_DISPLAY_HELP;
}
}
......
......@@ -339,7 +339,7 @@ protected:
* \param argv A set of strings which contains each parameter.
* \return An integer corresponding to a command which will be processed by ViTE.
*/
int get_state(int argc, char** argv);
int get_state(int& argc, char** argv);
/*!
* \brief Extracts the times of start and end in the string.
......
......@@ -725,6 +725,8 @@ void Interface_graphic::on_close_triggered(){
void Interface_graphic::on_quit_triggered(){
((QWidget*)_ui_node_selection)->close();
((QWidget*)_ui_help_window)->close();
((QWidget*)this)->close();
}
......@@ -999,6 +1001,9 @@ void Interface_graphic::closeEvent(QCloseEvent *event){
}
if(_ui_settings)
_ui_settings->close();
if(_ui_node_selection)
_ui_node_selection->close();
}
const std::string Interface_graphic::get_filename() const{
......
......@@ -67,6 +67,36 @@ using namespace std;
#define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): "
#define NB_STEPS 20
const double angle = M_PI/2.0;
const double delta_angle = 2.0*M_PI/NB_STEPS;
const double radius = .5;
template <int N> void Render_opengl::cos_table_builder(double table[]){
cos_table_builder<N-1>(table);
table[N-1]=cos(angle+delta_angle*(N-1))*radius;
}
template <> void Render_opengl::cos_table_builder<0>(double table[]){
table[0]=cos(angle*radius);
}
template <int N> void Render_opengl::sin_table_builder(double table[]){
sin_table_builder<N-1>(table);
table[N-1]=sin(angle+delta_angle*(N-1))*(radius);
}
template <> void Render_opengl::sin_table_builder<0>(double table[]){
table[0]=sin(angle)*(radius);
}
static double cos_table[NB_STEPS];
static double sin_table[NB_STEPS];
const int Render_opengl::DRAWING_TIMER_DEFAULT = 10;
......@@ -103,7 +133,13 @@ Render_opengl::Render_opengl(Core* core, QWidget *parent, const QGLFormat& forma
_wait_timer->start(_wait_spf);
#endif // SPINNING_LOGO
vertical_line=0;
vertical_line=0;
setAutoFillBackground(false);
cos_table_builder<NB_STEPS>(cos_table);
sin_table_builder<NB_STEPS>(sin_table);
}
......@@ -171,7 +207,7 @@ void Render_opengl::paintGL(){
resizeGL(Render_opengl::QGLWidget::width(), Render_opengl::QGLWidget::height());
Render_opengl::QGLWidget::setFocus(Qt::ActiveWindowFocusReason);/* give the focus to the render area for mouse and keyboard events */
makeCurrent();
static int arrows_drawn=0;
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
......@@ -200,7 +236,6 @@ void Render_opengl::paintGL(){
}else if (DRAWING_STATE_DRAWING == _state){/* A trace is drawn */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
{
glTranslated(0.0, Info::Render::height, 100.0);
......@@ -230,20 +265,34 @@ void Render_opengl::paintGL(){
else{
glCallList(_list_states);
glCallList(_list_counters);
// if( (false == Info::Render::_no_arrows) && arrows_drawn!=0 ) glCallList(_list_arrows);
}
}
glPopMatrix();
if (false == Info::Render::_no_arrows)/* display arrows */
draw_stored_arrows();
_minimap.update( ( ( (_x_state_translate - _default_entity_x_translate)/ (Info::Render::width*_x_state_scale) ) + (_default_entity_x_translate/Info::Render::width) )*_minimap.width(),
( (_y_state_translate - _ruler_height) / (Info::Render::height*_y_state_scale) + (_ruler_height/Info::Render::height) )*_minimap.height(),
_minimap.width()/_x_state_scale,
_minimap.height()/_y_state_scale
);
//initialize the minimap if it hasn't been done yet
if(!_minimap.is_initialized()){
QImage buf = grabFrameBuffer(true);
_minimap.init(buf);
}
if(false == Info::Render::_no_arrows){
draw_stored_arrows();
}
if (false == Info::Render::_no_events)/* display events */
draw_stored_circles();
if (Info::Render::_vertical_line){
draw_vertical_line();
}
/* Untranslate ruler */
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
......@@ -277,6 +326,7 @@ void Render_opengl::paintGL(){
cerr << __FILE__ << " l." << __LINE__ << ":" << endl;
cerr << "Selection rectangle position: (" << old_x << ", " << old_y << ") - (" << new_x << ", " << new_y << ")" << endl;
#endif
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
......@@ -284,10 +334,10 @@ void Render_opengl::paintGL(){
/* Square for selection */
glBegin(GL_QUADS);
{
glColor4d(0.9, 1.0, 0.9, _selection_rectangle_alpha);glVertex2d(old_x, old_y);
glColor4d(0.9, 0.9, 0.9, _selection_rectangle_alpha);glVertex2d(old_x, new_y);
glColor4d(0.9, 0.9, 0.9, _selection_rectangle_alpha);glVertex2d(new_x, new_y);
glColor4d(0.9, 0.9, 0.9, _selection_rectangle_alpha);glVertex2d(new_x, old_y);
glColor4f(0.9f, 1.0f, 0.9f, _selection_rectangle_alpha);glVertex2d(old_x, old_y);
glColor4f(0.9f, 0.9f, 0.9f, _selection_rectangle_alpha);glVertex2d(old_x, new_y);
glColor4f(0.9f, 0.9f, 0.9f, _selection_rectangle_alpha);glVertex2d(new_x, new_y);
glColor4f(0.9f, 0.9f, 0.9f, _selection_rectangle_alpha);glVertex2d(new_x, old_y);
}
glEnd();
......@@ -337,6 +387,8 @@ void Render_opengl::paintGL(){
arial_font);
}
/* Draw ruler text */
std::ostringstream buf_txt;
......@@ -387,14 +439,15 @@ void Render_opengl::paintGL(){
render_to_screen_y(8),
buf_txt.str().c_str(),
arial_font);
}
// update_minimap();
_minimap.update( ( ( (_x_state_translate - _default_entity_x_translate)/ (Info::Render::width*_x_state_scale) ) + (_default_entity_x_translate/Info::Render::width) )*_minimap.width(),
( (_y_state_translate - _ruler_height) / (Info::Render::height*_y_state_scale) + (_ruler_height/Info::Render::height) )*_minimap.height(),
_minimap.width()/_x_state_scale,
_minimap.height()/_y_state_scale
);
}
// update_minimap();
//initialize the minimap if it hasn't been done yet
if(!_minimap.is_initialized()){
QImage buf = grabFrameBuffer(true);
......@@ -427,7 +480,6 @@ bool Render_opengl::build(){
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
replace_scale(1);/* for states scaling */
init_geometry();/* Initialize geometry */
......@@ -445,6 +497,10 @@ bool Render_opengl::build(){
// updateGL();
// QImage buf = grabFrameBuffer(true);
// _minimap.init(buf);
//updateGL();
// QImage buf = grabFrameBuffer(true);
// _minimap.init(buf);
......@@ -472,7 +528,7 @@ bool Render_opengl::unbuild(){
glEnable(GL_BLEND);/* enable blending for the alpha color */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor3d(1.0, 1.0, 1.0);/* init color to white */
glColor3f(1.0, 1.0, 1.0);/* init color to white */
/*****************************
......@@ -629,7 +685,7 @@ void Render_opengl::call_ruler(){
glBegin(GL_QUADS);
{
glColor4d(0.0, 0.0, 1.0, 0.8);
glColor4f(0.0f, 0.0f, 1.0f, 0.8f);
glVertex3d(trace_to_render_x(Info::Render::_x_min_visible) , 3, _z_ruler_under );
glVertex3d(trace_to_render_x(Info::Render::_x_min_visible) , 8, _z_ruler_under );
glVertex3d(trace_to_render_x(Info::Render::_x_max_visible) , 8, _z_ruler_under );
......@@ -639,7 +695,7 @@ void Render_opengl::call_ruler(){
glBegin(GL_QUADS);
{
glColor4d(0.0, 0.0, 0.0, 1.0);
glColor4f(0.0, 0.0, 0.0, 1.0);
glVertex3d(trace_to_render_x(Info::Render::_x_min_visible) , 0, _z_ruler_over );
glVertex3d(trace_to_render_x(Info::Render::_x_min_visible) , 3, _z_ruler_over );
glVertex3d(trace_to_render_x(Info::Render::_x_max_visible) , 3, _z_ruler_over );
......@@ -673,6 +729,7 @@ void Render_opengl::draw_text(const Element_pos x, const Element_pos y, const El
void Render_opengl::draw_quad(Element_pos x, Element_pos y, Element_pos /*z*/, Element_pos w, Element_pos h){
Element_pos offset_x;
const Element_pos offset_y = -_ruler_y - _ruler_height;
......@@ -686,19 +743,19 @@ void Render_opengl::draw_quad(Element_pos x, Element_pos y, Element_pos /*z*/, E
glBegin(GL_QUADS);
{
glColor3d(_red, _green, _blue);
glColor3f(_red, _green, _blue);
glVertex2d(x + offset_x , y + offset_y);
glVertex2d(x + offset_x , y + h + offset_y);
if (Info::Render::_shaded_states){/* State color is shaded */
glColor3d(_red*0.6, _green*0.6, _blue*0.6);
glColor3f(_red*0.6, _green*0.6, _blue*0.6);
glVertex2d(x + w + offset_x, y + h + offset_y);
glVertex2d(x + w + offset_x, y + offset_y);
}else{/* State color must be uniform */
glColor3d(_red, _green, _blue);
glColor3f(_red, _green, _blue);
/* Multiply by 0.98 to allow distinction between two States with the same color. Temporary solution
before using a border.
......@@ -726,7 +783,7 @@ void Render_opengl::draw_line(Element_pos x1, Element_pos y1, Element_pos x2, El
glBegin(GL_LINES);
{
glColor3d(_red, _green, _blue);
glColor3f(_red, _green, _blue);
glVertex3d(x1 + offset_x, y1 + offset_y, z);
glVertex3d(x2 + offset_x, y2 + offset_y, z);
}
......@@ -752,7 +809,7 @@ void Render_opengl::start_draw(){
void Render_opengl::start_draw_containers(){
_list_containers = glGenLists(1);/* create the list */
if (_list_containers == 0) {
*Message::get_instance() << tr("Error when creating list.").toStdString() << Message::endw;
*Message::get_instance() << tr("Error when creating containers list.").toStdString() << Message::endw;
}
_draw_container = true;
......@@ -774,7 +831,7 @@ void Render_opengl::end_draw_containers(){
void Render_opengl::start_draw_states(){
_list_states = glGenLists(1);/* create the list */
if (_list_states == 0) {
*Message::get_instance() << tr("Error when creating list.").toStdString() << Message::endw;
*Message::get_instance() << tr("Error when creating states list.").toStdString() << Message::endw;
}
_draw_state = true;
......@@ -808,6 +865,7 @@ void Render_opengl::draw_arrow(const Element_pos start_time, const Element_pos e
buf.blue = blue;
_arrows.push_back(buf);
//printf("sizeof eventlist : %d %d %d %d\n",_circles.size(), _circles.size()*sizeof(Event_),_arrows.size(),_arrows.size()*sizeof(Arrow_));
}
void Render_opengl::end_draw_arrows(){
......@@ -831,17 +889,19 @@ void Render_opengl::draw_event(const Element_pos time, const Element_pos height,
buf.blue = _blue;
_circles.push_back(buf);
//printf("sizeof eventlist : %d %d\n", _circles.size()*sizeof(Event_),_arrows.size()*sizeof(Arrow_));
}
void Render_opengl::end_draw_events(){
_draw_event = false;
// printf("sizeof eventlist : %d %d %d %d\n",_circles.size(), _circles.size()*sizeof(Event_),_arrows.size(),_arrows.size()*sizeof(Arrow_));
}
void Render_opengl::start_draw_counter(){
_list_counters = glGenLists(1);/* create the list */
if (_list_counters == 0) {
*Message::get_instance() << tr("Error when creating list").toStdString() << Message::ende;
*Message::get_instance() << tr("Error when creating counters list").toStdString() << Message::ende;
}
glNewList(_list_counters, GL_COMPILE);/* open the list */
......@@ -863,6 +923,7 @@ void Render_opengl::end_ruler(){
}
void Render_opengl::end_draw(){
//printf("sizeof eventlist : %d %d %d %d %d %d\n",_circles.size(), _circles.size()*sizeof(Event_),_arrows.size(),_arrows.size()*sizeof(Arrow_), _texts.size(), _texts.size()*sizeof(Container_text_));
}
......@@ -872,7 +933,7 @@ void Render_opengl::draw_stored_texts(){
void Render_opengl::draw_stored_arrows(){
/* Only draw triangle. Lines are already in a display list */
const Element_pos coeff = 180.0f/M_PI;
const Element_pos coeff = 180.0/M_PI;
Element_pos angle;
Element_pos start_time, end_time, start_height, end_height;
Element_pos scaled_start_time, scaled_end_time, scaled_start_height, scaled_end_height;
......@@ -887,7 +948,7 @@ void Render_opengl::draw_stored_arrows(){
start_height = _arrows[i].start_height;
end_height = _arrows[i].end_height;
glColor3d(_arrows[i].red, _arrows[i].green, _arrows[i].blue);
glColor3f(_arrows[i].red, _arrows[i].green, _arrows[i].blue);
scaled_start_time = start_time * _x_state_scale;
scaled_end_time = end_time * _x_state_scale;
......@@ -899,14 +960,18 @@ void Render_opengl::draw_stored_arrows(){
glTranslated(_default_entity_x_translate + _x_state_scale*end_time - _x_state_translate,
_ruler_y + _ruler_height + _y_state_scale*end_height - _y_state_translate,
_z_arrow);
_z_arrow);/*
glTranslated( _x_state_scale*end_time,
_y_state_scale*end_height ,
0);*/
if (start_time != end_time){
angle = atan2((scaled_end_height - scaled_start_height), (scaled_end_time - scaled_start_time))*coeff;/* arc tangent */
glRotatef(angle, 0, 0, 1);
glRotated(angle, 0, 0, 1);
}
else
glRotatef(90, 0, 0, 1);/* vertical alignment */
glRotated(90, 0, 0, 1);/* vertical alignment */
glBegin(GL_TRIANGLES);
{
......@@ -919,14 +984,24 @@ void Render_opengl::draw_stored_arrows(){
}
glPopMatrix();
}
for (unsigned int i=0 ; i<arrow_size ; i++){
start_time = _arrows[i].start_time;// + _x_state_scale*_x_state_translate;
end_time = _arrows[i].end_time;// + _x_state_scale*_x_state_translate;
start_height = _arrows[i].start_height;
end_height = _arrows[i].end_height;
glColor3f(_arrows[i].red, _arrows[i].green, _arrows[i].blue);
glPushMatrix();
{
glTranslated(_default_entity_x_translate - _x_state_translate,
glTranslated(_default_entity_x_translate - _x_state_translate,
_ruler_y + _ruler_height - _y_state_translate,
_z_arrow);
glScalef(_x_state_scale, _y_state_scale, 1.0);
glScaled(_x_state_scale, _y_state_scale, 1.0);
glBegin(GL_LINES);
{
......@@ -939,12 +1014,19 @@ void Render_opengl::draw_stored_arrows(){
}
}
void Render_opengl::draw_stored_circles(){
const int step = 20;/* 20 polygons for the circle */
const float angle = M_PI/2.0f;
const float delta_angle = 2*M_PI/step;
const float radius = .5f;
//tables to store values used for circles drawings, with run-time data (zoom, size of the window), using pre-generated tables
double cos_table2[NB_STEPS];
double sin_table2[NB_STEPS];
for(int j = 0 ; j < NB_STEPS ; j ++){
cos_table2[j]= cos_table[j]/_x_state_scale;
sin_table2[j]= (sin_table[j]*Info::Screen::width)/(_y_state_scale*Info::Screen::height);
}
const unsigned int size = _circles.size();
for (unsigned int i=0 ; i<size ; i++){
......@@ -952,55 +1034,81 @@ void Render_opengl::draw_stored_circles(){
glPushMatrix();
{
glColor3d(1.0 - _circles[i].red, 1.0 - _circles[i].green, 1.0 - _circles[i].blue);
glColor3f(1.0 - _circles[i].red, 1.0 - _circles[i].green, 1.0 - _circles[i].blue);
glTranslated(_default_entity_x_translate - _x_state_translate,
_ruler_y + _ruler_height - _y_state_translate,
_z_arrow);
glScalef(_x_state_scale, _y_state_scale, 1.0);
glScalef(_x_state_scale, _y_state_scale, 1.0);
/* Draw the circle */
// Draw the outer circle
glBegin(GL_POLYGON);
{
for(int j = 0 ; j < step ; j ++){
glVertex2d(_circles[i].time + cos(angle+delta_angle*j)*radius/_x_state_scale,
_circles[i].height + sin(angle+delta_angle*j)*(radius/_y_state_scale)*Info::Screen::width/Info::Screen::height);
for(int j = 0 ; j < NB_STEPS ; j ++){
glVertex2d(_circles[i].time + cos_table2[j],
_circles[i].height + sin_table2[j]);
}
}
glEnd();
}
glPopMatrix();
}
glColor3d(_circles[i].red, _circles[i].green, _circles[i].blue);
for (unsigned int i=0 ; i<size ; i++){
glPushMatrix();
{
glColor3f(_circles[i].red, _circles[i].green, _circles[i].blue);
glTranslated(_default_entity_x_translate - _x_state_translate,
_ruler_y + _ruler_height - _y_state_translate,
_z_arrow);
glScalef(_x_state_scale, _y_state_scale, 1.0);
/* Draw the sub-circle */
// Draw the sub-circle
glBegin(GL_POLYGON);
{
for(int j = 0 ; j < step ; j ++){
glVertex3d(_circles[i].time + cos(angle+delta_angle*j)*radius/(1.2*_x_state_scale) ,
_circles[i].height + sin(angle+delta_angle*j)*radius/(1.2*_y_state_scale)*Info::Screen::width/Info::Screen::height ,
for(int j = 0 ; j < NB_STEPS ; j ++){
glVertex3d(_circles[i].time + cos_table2[j]/1.2 ,
_circles[i].height + sin_table2[j]/1.2 ,
0.1);
}
}
glEnd();
}
glPopMatrix();
}
//draw the line in another loop for better performance
for (unsigned int i=0 ; i<size ; i++){
glPushMatrix();
{
glColor3f(_circles[i].red, _circles[i].green, _circles[i].blue);
glTranslated(_default_entity_x_translate - _x_state_translate,
_ruler_y + _ruler_height - _y_state_translate,
_z_arrow);
glScalef(_x_state_scale, _y_state_scale, 1.0);
glLineWidth( 3.0 );
/* Draw the line */
//Draw the line
glBegin(GL_LINES);
{
glVertex2d(_circles[i].time, _circles[i].height-_circles[i].container_height);
glVertex2d(_circles[i].time, _circles[i].height);
glVertex2d(_circles[i].time, _circles[i].height+_circles[i].container_height);
}
glEnd();
glLineWidth( 1.0 );
}
glPopMatrix();
}
glLineWidth( 1.0 );
}
void Render_opengl::update_vertical_line(){
......
......@@ -67,6 +67,20 @@
#include "render/Render.hpp"
struct Container_text_;
/*template<typename T>
class CSingleton
{
public:
static T& Instance()
{
static T me;
return me;
}
};
*/
/*!
* \brief Structure used to store arrow information.
......@@ -144,6 +158,12 @@ protected:
* \brief The counter GLu list.
*/
GLuint _list_counters;
/*!
* \brief The arrows GLu list.
*/
GLuint _list_arrows;
/*!
......@@ -194,8 +214,7 @@ protected:
* \brief Timer to animate the wait.
*/
QTimer* _wait_timer;
/*!
* \brief QLabel to display minimap.
*/
......@@ -256,7 +275,8 @@ public:
*/
void display_time_scale(){}
// void set_vertical_line(int l){}
// void draw_vertical_line();
/***********************************
*
* Default QGLWidget functions.
......@@ -602,7 +622,8 @@ public:
* \param r the circle radius.
*/
void draw_circle(Element_pos x, Element_pos y, Element_pos z, Element_pos r);
template <int N> void cos_table_builder(double table[]);
template <int N> void sin_table_builder(double table[]);
/* Temporary methods. Use to draw stored arrows and circles. It is to prevent scaling */
void draw_stored_arrows();
void draw_stored_circles();
......