Une MAJ de sécurité est nécessaire sur notre version actuelle. Elle sera effectuée lundi 02/08 entre 12h30 et 13h. L'interruption de service devrait durer quelques minutes (probablement moins de 5 minutes).

Commit 3cded88c authored by Olivier Lagrasse's avatar Olivier Lagrasse
Browse files

Restore the ruler

parent 3f1415b1
......@@ -140,10 +140,10 @@ Core::Core(int argc, char ** argv){
if (!useGUI){
/* if (!useGUI){
cerr << QObject::tr("Error: Graphical window cannot be displayed.").toStdString() << endl;
exit(EXIT_FAILURE);
}
}*/
_main_window = NULL;
_render_opengl = NULL;
......@@ -618,7 +618,8 @@ void Core::extract_times(const char *name) {
void Core::launch_action(int state, void* arg) {
DrawTrace/*<Render_opengl>*/ buf;
DrawTrace buf;
QGLFormat format(QGL::HasOverlay);
switch(state) {
......@@ -627,39 +628,52 @@ void Core::launch_action(int state, void* arg) {
break;
case _STATE_LAUNCH_GRAPHICAL_INTERFACE :
case _STATE_OPEN_FILE:
_main_window = new Interface_graphic(this);/* launch the window interface */
Message::set_interface(_main_window);/* define which interface will receive messages */
/* MOD */
// _render_opengl = new Render_opengl_dl(this, _main_window);
_render_opengl = new Render_opengl(this, _main_window);
if ( _STATE_OPEN_FILE == state)
message << QObject::tr("Opening the file: ").toStdString ()+_file_opened << Message::endi;
_main_window->bind_render_area((QGLWidget*)_render_opengl);
_main_window = new Interface_graphic (this);/* launch the window interface */
Message::set_interface (_main_window);/* define which interface will receive messages */
_is_window_displayed = true;
break;
// format.setOverlay(true);
_render_opengl = new Render_opengl (this, _main_window, format);
case _STATE_OPEN_FILE:
information(string("Opening the file: ")+_file_opened);
_main_window = new Interface_graphic(this);/* launch the window interface and open a file */
Message::set_interface(_main_window);/* define which interface will receive messages */
if ( NULL == _render_opengl){
message << QObject::tr("Cannot allocate memory for an OpengGL instance").toStdString () << Message::ende;
break;
}
/* MOD */
// _render_opengl = new Render_opengl_dl(this, _main_window);
_render_opengl = new Render_opengl(this, _main_window);
if (NULL == _render_opengl->context()){
message << QObject::tr("Cannot allocate an OpengGL context").toStdString () << Message::ende;
break;
}
if (false == _render_opengl->isValid()){
message << QObject::tr("Invalid context: OpenGL is not supported on your system").toStdString () << Message::ende;
}
// if (false == _render_opengl->format().hasOverlay ()){
// /* If no overlay was created, check the original format */
// if (false == _render_opengl->context()->requestedFormat().hasOverlay())
// message << QObject::tr("No overlay format originally created").toStdString () << Message::endw;
// else
// message << QObject::tr("An overlay format was originally asked, but was not created").toStdString () << Message::endw;
// }
_main_window->bind_render_area((QGLWidget*)_render_opengl);
_main_window->opening_file(_file_opened);/* Must be called after binding the render area to the main window */
if(false==draw_trace(_file_opened, _DRAW_OPENGL))
message << "Draw trace failed" << Message::ende;
if ( _STATE_OPEN_FILE == state){
_main_window->opening_file(_file_opened);/* Must be called after binding the render area to the main window */
if(false==draw_trace(_file_opened, _DRAW_OPENGL))
message << QObject::tr("Draw trace failed").toStdString () << Message::ende;
}
_is_window_displayed = true;
break;
case _STATE_OPEN_FILE_IN_AN_INTERVAL:
......
......@@ -84,9 +84,9 @@ void Hook_event::updateRender(){
*
**********************************/
Hook_event::Hook_event(Render_opengl* render_instance, Core* core, QWidget *parent)
: QGLWidget(/*QGLFormat(QGL::HasOverlay),*/ parent){
Hook_event::Hook_event(Render_opengl* render_instance, Core* core, QWidget *parent, const QGLFormat& format)
: QGLWidget(format, parent){
// GLenum glew_code;
......
......@@ -327,7 +327,7 @@ public:
* \brief The constructor.
* \param render_instance The instance of a drawing class.
*/
Hook_event(Render_opengl* render_instance, Core* core, QWidget *parent);
Hook_event(Render_opengl* render_instance, Core* core, QWidget *parent, const QGLFormat& format);
/*!
* \brief The destructor
......
......@@ -79,8 +79,8 @@ const int Render_opengl::DRAWING_TIMER_DEFAULT = 10;
*
**********************************/
Render_opengl::Render_opengl(Core* core, QWidget *parent)
: Hook_event(this, core, parent){
Render_opengl::Render_opengl(Core* core, QWidget *parent, const QGLFormat& format)
: Hook_event(this, core, parent, format){
......@@ -274,12 +274,8 @@ void Render_opengl::paintGL(){
}
glPopMatrix();
// glMatrixMode(GL_MODELVIEW);
// glLoadIdentity();
glPushMatrix();
{
// glTranslated(0.0, Info::Container::y_max- 3*_ruler_height, 100.0);/* not accurate */
glTranslated(0.0, 0.0, 100.0);/* not accurate */
if (_mouse_pressed){
......@@ -337,41 +333,12 @@ void Render_opengl::paintGL(){
message << tr("Render area : the following OpengGL error occured: ").toStdString() << (char *)gluErrorString(glerror) << Message::endw;
/*
}
void Render_opengl::initializeOverlayGL(){
cerr << __FILE__ << " " << __LINE__ << " init overlay" << endl;
}
void Render_opengl::resizeOverlayGL(int width, int height){
cerr << __FILE__ << " " << __LINE__ << " resize overlay" << endl;
}
void Render_opengl::paintOverlayGL (){
*/
// cerr << __FILE__ << " " << __LINE__ << " PLOP" << endl;
// QPainter painter(this);
//painter.setPen(Qt::NoPen);
//painter.setBrush(QColor(125, 125, 150));
//painter.drawRect(Info::Screen::width-210, Info::Screen::height-40, 200, 30);
QFont arial_font = QFont("Arial", 10);
qglColor(Qt::white);//QColor(0, 0, 0));
/*
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::white);
painter.setFont(QFont("Arial", 10));
*/
/* Draw container text */
const unsigned int texts_size = _texts.size();
for (unsigned int i=0 ; i<texts_size ; i++){
const QFontMetrics metric(arial_font);
......@@ -380,10 +347,6 @@ void Render_opengl::paintOverlayGL (){
render_to_screen_y( trace_to_render_y(_texts[i].y) + 0.5),
text_elided,
arial_font);
// painter.drawText( render_to_screen_x(_texts[i].x * _x_scale_container_state/0.20),
// render_to_screen_y( trace_to_render_y(_texts[i].y) + 0.5),/* '+ 0.5' is used to center text vertically. */
// _texts[i].value.c_str());/* prvent this, need to construct Qstring every frames for every texts! */
}
/* Draw ruler text */
......@@ -414,7 +377,7 @@ void Render_opengl::paintOverlayGL (){
arial_font);
buf_txt.str("");
buf_txt << render_to_trace_x(screen_to_render_x(_new_mouse_x));//(double)Ruler::get_common_part(Info::Render::_x_min_visible, coeff_prefix) << "--";
buf_txt << Ruler::get_common_part_string(Info::Render::_x_min_visible, coeff_prefix) << "--";
renderText (render_to_screen_x(
trace_to_render_x(
......@@ -423,9 +386,7 @@ void Render_opengl::paintOverlayGL (){
render_to_screen_y(3),
buf_txt.str().c_str(),
arial_font);
// painter.setFont(QFont("Arial", 10));
arial_font.setPointSize(10);
for (Element_pos i = Info::Render::_x_min_visible ;
......@@ -433,25 +394,13 @@ void Render_opengl::paintOverlayGL (){
i+=graduation_diff){
buf_txt.str("");/* flush the buffer */
buf_txt << i;//Ruler::get_variable_part(i, coeff_prefix, 2);
buf_txt << Ruler::get_variable_part(i, coeff_prefix, 2);
renderText (render_to_screen_x(trace_to_render_x(i)+1),
render_to_screen_y(8),
buf_txt.str().c_str(),
arial_font);
}
/* QFont font("Arial", 15);
font.setStyle(QFont::StyleOblique);
painter.setFont(font);
painter.setOpacity(0.5);
painter.drawText(Info::Screen::width-320, Info::Screen::height-10, "Rendering mode - work in progress");
*/
// painter.end();
}
......@@ -660,172 +609,48 @@ GLuint Render_opengl::draw_wait() {
void Render_opengl::call_ruler(){
//return;
/* Now, draw ruler */
// float common_part;
// float variable_part;
Element_pos graduation_diff;
Element_pos coeff_prefix;
// std::ostringstream buf_txt;
const Element_pos offset_x = _default_entity_x_translate;
const Element_pos offset_y = _ruler_y + _ruler_height+3.5;
// QLabel* ui;
// int count;
/*
QPainter painter(this);
painter.setPen(Qt::white);
painter.setFont(QFont("Arial", 10));
*/
// Update Info::Render::_x_min_visible and Info::Render::_x_max_visible values
update_visible_interval_value();
graduation_diff = Ruler::get_graduation_diff(Info::Render::_x_min_visible, Info::Render::_x_max_visible);
coeff_prefix = Ruler::get_coeff_for_common_prefix(Info::Render::_x_min_visible, Info::Render::_x_max_visible);
/*
for (count = 0,
ui = Info::Render::_ui_render_min_value,
buf_txt.str(""),// flush the buffer
common_part = Ruler::get_common_part(Info::Render::_x_min_visible, coeff_prefix),
variable_part = Ruler::get_variable_part(Info::Render::_x_min_visible, coeff_prefix, 2)
;
count!=2
;
count++,
ui = Info::Render::_ui_render_max_value,
buf_txt.str(""),// flush the buffer
common_part = Ruler::get_common_part(Info::Render::_x_max_visible, coeff_prefix),
variable_part = Ruler::get_variable_part(Info::Render::_x_max_visible, coeff_prefix, 2)
){
buf_txt << "<b>";
if (common_part==0.0){
if (variable_part!=0.0){
if (((float)floor(variable_part))==variable_part)
buf_txt << "0.";
buf_txt << "</b>" << variable_part;
}else{
buf_txt << "0";
}
}else{
buf_txt << common_part << "</b>";
if (variable_part!=0.0)
buf_txt << variable_part;
}
// painter.drawText(10,10, buf_txt.str().c_str());
ui->setText(buf_txt.str().c_str());
}
painter.end(); */
// if (Info::Render::_ui_render_min_value != NULL){
// buf_txt.str("");/* flush the buffer */
// common_part = Ruler::get_common_part(Info::Render::_x_min_visible, coeff_prefix);
// variable_part = Ruler::get_variable_part(Info::Render::_x_min_visible, coeff_prefix, 2);
// buf_txt << "<b>";
// if (common_part==0.0){
// if (variable_part!=0.0){
// if (((float)floor(variable_part))==variable_part)
// buf_txt << "0.";
// buf_txt << "</b>" << variable_part;
// }else{
// buf_txt << "0";
// }
// }else{
// buf_txt << common_part << "</b>";
// if (variable_part!=0.0)
// buf_txt << variable_part;
// }
// Info::Render::_ui_render_min_value->setText(buf_txt.str().c_str());
// }
// if (Info::Render::_ui_render_max_value != NULL){
// buf_txt.str("");/* flush the buffer */
// buf_txt << "<b>" << Ruler::get_common_part(Info::Render::_x_max_visible, coeff_prefix)
// << "</b>" << Ruler::get_variable_part(Info::Render::_x_max_visible, coeff_prefix, 2);
// Info::Render::_ui_render_max_value->setText(buf_txt.str().c_str());
// }
for (Element_pos i = Info::Render::_x_min_visible ; i < Info::Render::_x_max_visible ; i+=graduation_diff){
const Element_pos grad_div_by_5 = graduation_diff/5;
for (Element_pos j = (i+grad_div_by_5) ; j<(i+graduation_diff) ; j+= grad_div_by_5){
draw_line( trace_to_render_x(j) + offset_x, offset_y ,
trace_to_render_x(j) + offset_x, 2+offset_y, _z_ruler);
}
// glColor3d(1, 1, 0);
draw_line( trace_to_render_x(i) + offset_x, offset_y-1 ,
trace_to_render_x(i) + offset_x, 4+offset_y, _z_ruler);
// buf_txt.str("");/* flush the buffer */
//buf_txt << Ruler::get_variable_part(i, coeff_prefix, 2);
/* Draw text with GLUT */
//{
// glPushMatrix();
/* painter.drawText(render_to_screen_x(trace_to_render_x(i)+1),
render_to_screen_y(4),
buf_txt.str().c_str());*/
/*
glColor3d(1, 1, 1);
glRasterPos2f(trace_to_render_x(i)+1,
4);
float length = 0;
const unsigned int buf_text_size = buf_txt.str().length();
for(unsigned int j = 0 ; j < buf_text_size ; j ++){
const char letter = buf_txt.str().c_str()[j];
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, letter);
}
// glPopMatrix();
*/
}
glBegin(GL_QUADS);
{
glColor4d(0.0, 0.0, 1.0, 0.8);
glVertex3d(trace_to_render_x(Info::Render::_x_min_visible) , 0, _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 );
glVertex3d(trace_to_render_x(Info::Render::_x_max_visible) , 0, _z_ruler_under );
}
glEnd();
glBegin(GL_QUADS);
{
glColor4d(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 );
glVertex3d(trace_to_render_x(Info::Render::_x_max_visible) , 0, _z_ruler_over );
}
glEnd();
//painter.setPen(Qt::NoPen);
//painter.setBrush(QColor(125, 125, 150));
//painter.drawRect(Info::Screen::width-210, Info::Screen::height-40, 200, 30);
// painter.end();
glBegin(GL_QUADS);
{
glColor4d(0.0, 0.0, 1.0, 0.8);
glVertex3d(trace_to_render_x(Info::Render::_x_min_visible) , 0, _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 );
glVertex3d(trace_to_render_x(Info::Render::_x_max_visible) , 0, _z_ruler_under );
}
glEnd();
glBegin(GL_QUADS);
{
glColor4d(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 );
glVertex3d(trace_to_render_x(Info::Render::_x_max_visible) , 0, _z_ruler_over );
}
glEnd();
return;
}
......@@ -894,17 +719,6 @@ void Render_opengl::draw_line(Element_pos x1, Element_pos y1, Element_pos x2, El
}
void Render_opengl::draw_circle(Element_pos /*x*/, Element_pos /*y*/, Element_pos /*z*/, Element_pos /*r*/){
/* Circle_ buf;
const Element_pos offset_x = -_default_entity_x_translate;
const Element_pos offset_y = -_ruler_y - _ruler_height;
buf.x = x + offset_x;
buf.y = y + offset_y;
buf.z = z;
buf.r = r;
_circles.push_back(buf);*/
}
......@@ -1027,30 +841,6 @@ void Render_opengl::end_draw(){
void Render_opengl::draw_stored_texts(){
// glColor3d(1, 1, 1);
// for (unsigned int i=0 ; i<_texts.size() ; i++){
// glPushMatrix();
// {
// glRasterPos2f(_texts[i].x * _x_scale_container_state/0.20, /* 0.20 is the default value of _x_scale_container_state */
// trace_to_render_y(_texts[i].y));//*_y_state_scale - _y_state_translate);
// // std::cout << __FILE__ << " " << __LINE__ << " " << _texts[i].x << std::endl;
// float length = 0;
// const unsigned int buf_text_size =_texts[i].value.length();
// // const int size_of_container = (const int)(20*_x_scale_container_state*Info::Render::width/Info::Container::x_max);
// for(unsigned int j = 0 ; j < buf_text_size ; j ++){
// const char letter = _texts[i].value.c_str()[j];
// /* length += glutBitmapWidth(GLUT_BITMAP_HELVETICA_10, letter);
// if(length > size_of_container){
// break;
// }*/
// glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, letter);
// }
// }
// glPopMatrix();
// }
}
void Render_opengl::draw_stored_arrows(){
......@@ -1131,21 +921,8 @@ void Render_opengl::draw_stored_circles(){
const unsigned int size = _circles.size();
// std::cerr << __FILE__ << __LINE__<< " " << size << std::endl;
// return;/* Stack overflow... Why? */
for (unsigned int i=0 ; i<size ; i++){
/*
time = _circles[i].time;
height = _circles[i].height;
container_height = _circles[i].container_height;
*/
// std::cerr << __FILE__ << __LINE__<< " " << _circles[i].time << " " << _circles[i].height << std::endl;
glPushMatrix();
{
......
......@@ -182,7 +182,7 @@ public:
/*!
* \brief The default constructor
*/
Render_opengl(Core* core, QWidget *parent);
Render_opengl(Core* core, QWidget *parent, const QGLFormat& format);
/*!
* \brief The destructor
......
......@@ -175,14 +175,10 @@ Element_pos Ruler::get_coeff_for_common_prefix(Element_pos min, Element_pos max)
/* TODO: use cmath::modf() */
float Ruler::get_common_part(const Element_pos n, const Element_pos coeff_for_common_prefix){
const int common_part = floor(n*coeff_for_common_prefix);
const float common_part_without_coeff = common_part/coeff_for_common_prefix;
int common_part = floor(n*coeff_for_common_prefix);
float common_part_without_coeff = common_part/coeff_for_common_prefix;
/* std::cout << __FILE__ << " " << __LINE__ << " >> n:" << n << " coeff: " << coeff_for_common_prefix
<< " common_part: " << common_part << " cpwc: " << common_part_without_coeff << std::endl;*/
if ( (floor(common_part_without_coeff) != common_part_without_coeff)/* there is a comma */
)//&& floor(common_part_without_coeff) != 0 )/* and there is numbers before comma */
if ( (floor(common_part_without_coeff) != common_part_without_coeff) )/* there is a comma */
return common_part_without_coeff;
else
return (float)common_part;
......@@ -192,75 +188,67 @@ float Ruler::get_variable_part(const Element_pos n, const Element_pos coeff_for_
const int common_part = floor( (n*coeff_for_common_prefix - floor(n*coeff_for_common_prefix))*pow(10, nb_digit_after_comma));
const float common_part_without_coeff = common_part/(coeff_for_common_prefix*pow(10, nb_digit_after_comma));
if ( /*(floor(common_part_without_coeff) != common_part_without_coeff) */ /* there is a comma */
/* &&*/ floor(common_part_without_coeff) != 0 )/* and there is numbers before comma */
if ( floor(common_part_without_coeff) != 0 )/* and there is numbers before comma */
return common_part_without_coeff;
else
return (float)common_part;
}
string Ruler::get_common_part_string(const Element_pos n, const Element_pos coeff_for_common_prefix){
ostringstream buf_txt;
float n_with_coeff;
string Ruler::get_common_part_string(const Element_pos n, Element_pos coeff_for_common_prefix){
int i, common_part;
Element_pos buf;
ostringstream buf_txt, result_txt;
string::reverse_iterator rit;
/**
*
* For n = 10.2034 and coeff_for_common_prefix = 100,
* then common_part = 1020
*
*/
common_part = floor(n*coeff_for_common_prefix);
n_with_coeff = n/coeff_for_common_prefix;
buf_txt.str("");
result_txt.str("");
/**
* First case: if n = 0.0234 and common_part is 0.023,
* Put "0.0" and after "23". (Otherwise, common_part will
* be equal to 23, ignoring "0.0"!)
*/
buf = n;
if ( (buf != 0.0) && (floor(buf) == 0) ){
result_txt << "0.";
buf *= 10;
}
if (coeff_for_common_prefix > 1){/* point is in variable part */
while ( (buf != 0.0) && (floor(buf) == 0) ){
result_txt << "0";
buf *= 10;
}
float coeff;
for (i=0 ; common_part > 0 ; common_part = floor(common_part/10)){
buf_txt << common_part%10;
coeff = coeff_for_common_prefix;
/**
* For example 102.34 with common 1**.**
*/
buf_txt << floor(n_with_coeff);
/**
* buf_txt = "1"
*/
for (;
coeff > 1;
coeff /= 10){
/**
* First loop: buf_txt = "1-"
* Second loop: buf_txt = "1--"
*/
buf_txt << "-";
}
buf_txt << ".-";
/**
* buf_txt = "1--.-"
*/
}else if (coeff_for_common_prefix < 1){/* point is in common part */
/**
* For example 10.234 with common 10.2**
*/
buf_txt << floor(n) << ".";
/**
* buf = "10"+"."
*/
buf_txt << floor(n)*coeff_for_common_prefix - n_with_coeff;
/**