Commit d8952e48 authored by Olivier Lagrasse's avatar Olivier Lagrasse
Browse files

- Change rule. (but some visual bugs need to be fix)

parent 12c725a6
......@@ -90,3 +90,6 @@ Element_pos Info::Render::_info_accurate = 0.0;
bool Info::Render::_no_arrows = false;
bool Info::Render::_no_events = false;
QLabel* Info::Render::_ui_render_min_value = NULL;
QLabel* Info::Render::_ui_render_max_value = NULL;
......@@ -50,6 +50,7 @@
#include "../main_resource.hpp"
class Interface_console;
class QLabel;
/*!
* \brief Class used to store informations.
......@@ -341,6 +342,19 @@ public:
* \brief To show the right screen of the current view.
*/
static const int X_SCREEN_RIGHT_MOVE = 7;
/*!
* \brief This attribute is used to update the label which indicates
* the minimum visible trace value.
*/
static QLabel* _ui_render_min_value;
/*!
* \brief This attribute is used to update the label which indicates
* the maximum visible trace value.
*/
static QLabel* _ui_render_max_value;
};
......
......@@ -142,6 +142,7 @@ void Interface_graphic::load_windows(){
/* Load widget from the .ui file */
CKFP(_ui_render_area_layout = qFindChild<QVBoxLayout*>(this, "render_area_layout"), "Cannot find the render_area layout in the .ui file");
CKFP(_ui_fullscreen_menu = qFindChild<QAction*>(this, "fullscreen"), "Cannot find the fullscreen menu in the .ui file");
CKFP(_ui_info_trace_text = qFindChild<QTextEdit*>(_ui_info_window, "info_trace_text"), "Cannot find the info_trace_text QTextEdit widget in the .ui file");
CKFP(_ui_info_selection_text = qFindChild<QTextEdit*>(_ui_info_window, "info_selection_text"), "Cannot find the info_selection_text QTextEdit widget in the .ui file");
......@@ -153,6 +154,9 @@ void Interface_graphic::load_windows(){
CKFP(_ui_zoom_box = qFindChild<QComboBox*>(this, "zoom_box"), "Cannot find the zoom box in the .ui file");
CKFP(Info::Render::_ui_render_min_value = qFindChild<QLabel*>(this, "render_min_value"), "Cannot find the render_min_value label in the .ui file");
CKFP(Info::Render::_ui_render_max_value = qFindChild<QLabel*>(this, "render_max_value"), "Cannot find the render_max_value label in the .ui file");
/* Export window */
CKFP(_ui_export_ok_button = qFindChild<QPushButton*>(_ui_time_selection_export, "option_export_ok"), "Cannot find the ok push button in the export dialog .ui file");
CKFP(_ui_min_time_export = qFindChild<QLineEdit*>(_ui_time_selection_export, "min_time"), "Cannot find the ok push button in the export dialog .ui file");
......@@ -354,10 +358,10 @@ void Interface_graphic::change_zoom_box_value(int new_value){
ostringstream int_to_string;
int index;
int max_value = -2147483648L;
int max_value = INT_MIN;
if (max_value == new_value)/* prevent overflow value */
new_value = 2147483647;
new_value = INT_MAX;
int_to_string << new_value;
......
......@@ -109,12 +109,12 @@ class Interface_graphic : public QMainWindow, protected Ui::main_window, public
* \brief This variable contains the OpenGL render area.
*/
QGLWidget* _ui_render_area;
/*!
* \brief Layout which will contain the render area.
*/
QVBoxLayout* _ui_render_area_layout;
/*!
* \brief This variable contains the instance of the horizontal scroll bar.
*/
......
......@@ -28,6 +28,55 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="render_min_value">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="render_max_value">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
......
......@@ -813,7 +813,7 @@ Element_pos Hook_event::render_to_screen_y(Element_pos e){
Element_pos Hook_event::trace_to_render_x(Element_pos e){
return e * ((_render_width-_default_entity_x_translate)*_x_state_scale) / (_state_x_max - _state_x_min) +
return e * coeff_trace_render_x() +
_default_entity_x_translate - _x_state_translate;
}
......@@ -824,4 +824,6 @@ Element_pos Hook_event::trace_to_render_y(Element_pos e){
}
Element_pos Hook_event::coeff_trace_render_x(){
return ((_render_width-_default_entity_x_translate)*_x_state_scale) / (_state_x_max - _state_x_min);
}
......@@ -730,6 +730,12 @@ public:
*/
Element_pos trace_to_render_y(Element_pos e);
/*!
* \brief Return the coefficient used to pass from horizontal trace coordinates to the horizontal render coordinates by multiplication.
* \return A number with which an horizontal trace coordinate number must be multiply to get its horizontal render coordinates.
*/
Element_pos coeff_trace_render_x();
};
......
......@@ -334,6 +334,9 @@ bool Render_opengl::unbuild(){
_container_x_min = 0;
_container_y_min = 0;
Info::Render::_ui_render_min_value->setText("");
Info::Render::_ui_render_max_value->setText("");
_state_x_max = 0;
_state_y_max = 0;
_state_x_min = 0;
......@@ -435,10 +438,10 @@ GLuint Render_opengl::draw_ruler() {
Element_pos graduation_distance_per_5;
double ruler_bg_r, ruler_bg_g, ruler_bg_b;/* the ruler background color (in RGB mode)*/
/* light blue color */
/* background color */
{
ruler_bg_r = 0.5;
ruler_bg_g = 0.5;
ruler_bg_r = 1.0;
ruler_bg_g = 1.0;
ruler_bg_b = 1.0;
}
......@@ -451,10 +454,12 @@ GLuint Render_opengl::draw_ruler() {
*/
_ruler_distance = 1.0/20.0;
/*
* Graduation number.
*/
nb_graduation = (unsigned int)ceil(_render_width/_ruler_distance);
nb_graduation = 20;
/*
* Distance between 2 small consecutive graduations.
......@@ -484,8 +489,8 @@ GLuint Render_opengl::draw_ruler() {
for (char k = 1 ; k < 5 ; k ++){
glBegin(GL_LINES);
{
glColor3d(1.0, 1.0, 1.0);glVertex2d(i*_ruler_distance+k*graduation_distance_per_5, _ruler_y);
glColor3d(0.6, 0.6, 1.0);glVertex2d(i*_ruler_distance+k*graduation_distance_per_5, _ruler_y+_ruler_height/3.0);
glColor3d(0.2, 0.2, 1.0);glVertex2d(i*_ruler_distance+k*graduation_distance_per_5, _ruler_y);
glColor3d(0.2, 0.2, 1.0);glVertex2d(i*_ruler_distance+k*graduation_distance_per_5, _ruler_y+_ruler_height/3.0);
}
glEnd();
}/* end for( k ) */
......@@ -496,8 +501,8 @@ GLuint Render_opengl::draw_ruler() {
*/
glBegin(GL_LINES);
{
glColor3d(1.0, 1.0, 1.0);glVertex2d(i*_ruler_distance, _ruler_y);
glColor3d(0.6, 0.6, 1.0);glVertex2d(i*_ruler_distance, _ruler_y+_ruler_height);
glColor3d(0.0, 0.0, 1.0);glVertex2d(i*_ruler_distance, _ruler_y);
glColor3d(0.0, 0.0, 1.0);glVertex2d(i*_ruler_distance, _ruler_y+_ruler_height);
}
glEnd();
......@@ -506,10 +511,10 @@ GLuint Render_opengl::draw_ruler() {
/* Draw the background */
glBegin(GL_QUADS);
{
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex2d(0, _ruler_y+_ruler_height);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex2d(0, _ruler_y+_ruler_height+1);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.5);glVertex2d(0, _ruler_y);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.5);glVertex2d(0 + nb_graduation*_ruler_distance, _ruler_y);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex2d(0 + nb_graduation*_ruler_distance, _ruler_y+_ruler_height);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex2d(0 + nb_graduation*_ruler_distance, _ruler_y+_ruler_height+1);
}
glEnd();
......@@ -527,53 +532,16 @@ GLuint Render_opengl::draw_ruler() {
void Render_opengl::call_ruler(){
Element_pos nb_graduation;
Element_pos graduation_distance_per_5;
Element_pos buf_time;
Element_pos _info_degree_x;
Element_pos _info_degree_width;
ostringstream buf_txt;
unsigned int difference;
unsigned int step;
Element_pos adjustement;
char loop_count;/* counter to prevent infinity loop */
unsigned int distance_between_render_graduation;
Element_pos entire_part_d;
Element_pos degree_d;
Element_pos pow_10_degree_d;
ostringstream buf_txt;
Element_pos buf_min;
Element_pos buf_max;
Element_pos buf_d;
double ruler_bg_r, ruler_bg_g, ruler_bg_b;/* the ruler background color (in RGB mode)*/
/* light blue color */
{
ruler_bg_r = 0.5;
ruler_bg_g = 0.5;
ruler_bg_b = 1.0;
}
/* Contains the degree scale to get a number from 0.01 to 100 */
const Element_pos mul_scale_d = 4;
/* Contains the scale to get a number from 0.01 to 100 (equals to 10^mul_scale_d) */
const Element_pos mul_scale = 10000;
/* The ruler accurate */
const Element_pos limit_d = 0.00000000001;
/* Graduation number. */
nb_graduation = ceil(_render_width/_ruler_distance);
/* Distance between 2 small consecutive graduations. */
graduation_distance_per_5 = _ruler_distance/5.0;
/* Use to temporary store the graduation time value. */
buf_time = 0;
/* The info degree x beginning position. */
_info_degree_x = 0;
/* The info degree width: dynamically computed to fit its value. Default size: 1. */
_info_degree_width = 0;
/* Use to temporary store the graduation time value text. */
buf_txt.str("");
......@@ -593,21 +561,45 @@ void Render_opengl::call_ruler(){
/* Update Info::Render::_x_min_visible and Info::Render::_x_max_visible values */
update_visible_interval_value();
/* Contains the common left part of each graduate values */
entire_part_d = 0;
/*
* Work out the graduation time value degree.
*/
/* Contains the degree used to know how many we need to multiply to get
the uncommon right part of each graduate values more than 0.01 */
degree_d = 0;
buf_max = Info::Render::_x_max_visible;
buf_min = Info::Render::_x_min_visible;
/* Contains 10^degree_d */
pow_10_degree_d = 1;
adjustement = 1;
loop_count = 0;
difference = ((int)buf_max) - ((int)buf_min);
while ( (difference <= 10) && (loop_count<20)){
buf_max *= 10.0;
buf_min *= 10.0;
adjustement *= 10;
difference = ((int)buf_max) - ((int)buf_min);
loop_count++;
}
/* Just a buffer for intermediate computations */
buf_d = 0;
if (loop_count>20){
message << tr("Cannot create the rule due to infinity loop: the maximum trace value is equal to the minimum!").toStdString() << Message::endw;
return;
}
while (difference > 10){
difference /= 10;/* integer division */
}
/* Check within ] 7 ; 10 ] */
if (difference > 7){
step = 10;/* 10 trace units between each graduation */
}else if (difference > 3){/* Check within ] 3 ; 7 ] */
step = 5;/* 5 trace units between each graduation */
}else if (difference > 1){/* Check within ] 1 ; 3 ] */
step = 2;/* 2 trace units between each graduation */
}else if (difference != 0){
step = 1;/* 1 trace unit between each graduation */
}else{/* cannot draw the rule! */
return;
}
/*
* Draw ruler
......@@ -617,129 +609,57 @@ void Render_opengl::call_ruler(){
}
else{
glPushMatrix();
/*
* Just translate for ruler follows the entity translate.
*/
glTranslated( - (int)_x_state_translate % (int)_ruler_distance, 0, _z_ruler);
buf_min = ((int)buf_min) - ((int)buf_min)%step;
distance_between_render_graduation = (coeff_trace_render_x()*step*20)/adjustement;
glTranslated( trace_to_render_x(buf_min/adjustement), 0, _z_ruler);
glScaled(distance_between_render_graduation, 1.0, 1.0);
glCallList(_list_ruler);
glPopMatrix();
}
/*
* Work out the graduation time value degree.
*/
buf_max = Info::Render::_x_max_visible;
buf_min = Info::Render::_x_min_visible;
if (buf_max>limit_d){
while (buf_max>1){
buf_max/=10.0;
buf_min/=10.0;
degree_d--;
pow_10_degree_d /= 10.0;
}
}
buf_d = 0;/* to secure */
while ( (floor(buf_max) == floor(buf_min)) && (buf_d<10) ){/* buf<10 means that buf_max if greater than limit_d ! */
buf_max *= 10;
buf_min *= 10;
pow_10_degree_d *= 10;
degree_d++;
buf_d++;
}
/* ignore the last figure */
// if (degree_d >= 0){
pow_10_degree_d /= 10;
degree_d--;
//}
entire_part_d = floor( Info::Render::_x_max_visible * pow_10_degree_d );
/*
* Draw the current ruler degree
*/
/* Draw the text */
glColor3d(1.0, 1.0, 1.0);/* text color */
glRasterPos2f( 0, _ruler_y+_ruler_height);
buf_txt << entire_part_d << "Xe-" << degree_d+mul_scale_d;
/* Write text in label (the min and the max of the visible trace values) */
buf_txt.str("");/* flush the buffer */
buf_txt << "<b>" << ((int)buf_min - (int)buf_min%100)/adjustement << "</b>" << ((int)buf_min%100);
for(unsigned int j = 0 ; j < buf_txt.str().length() ; j ++){
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
_info_degree_width += glutBitmapWidth(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
}
_info_degree_width = screen_to_render_x(_info_degree_width);
buf_txt.str("");/* flush the buffer */
/* Draw the foreground */
glBegin(GL_QUADS);
{
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x, _ruler_y+_ruler_height, _z_ruler_over);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x, _ruler_y, _z_ruler_over);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x + _info_degree_width, _ruler_y, _z_ruler_over);
glColor4d(ruler_bg_r, ruler_bg_g, ruler_bg_b, 0.8);glVertex3d(_info_degree_x + _info_degree_width, _ruler_y+_ruler_height, _z_ruler_over);
}
glEnd();
/*
* Draw coordinates
*/
glColor3d(1.0, 1.0, 1.0);/* text color */
for (unsigned int i = 0 ; i<=nb_graduation ; i++){
/*
* Work out the graduation time value.
*/
buf_time = render_to_trace_x(i*_ruler_distance);
if (Info::Render::_ui_render_min_value != NULL){
Info::Render::_ui_render_min_value->setText(buf_txt.str().c_str());
}
glRasterPos2f( _render_width-10, _ruler_y+_ruler_height/2);
if (buf_time < 0) continue;/* do not display negative time values */
buf_txt.str("");/* flush the buffer */
buf_txt << "<b>" << ((int)buf_max - (int)buf_max%100)/adjustement << "</b>" << ((int)buf_max%100);
/* Now, convert (XXX,XXXXXXXXX) to (YYY * 10^ZZ and a common part WWWWWW * 10^TT) */
if (Info::Render::_ui_render_max_value != NULL){
Info::Render::_ui_render_max_value->setText(buf_txt.str().c_str());
}
glColor3d(0.0, 0.0, 0.5);/* text color */
/* trunc the common part of each number */
buf_d = buf_time*pow_10_degree_d;
buf_d = buf_d - floor( buf_d );
/* Mul buf_time to belongs to ]1000;0[ */
buf_d *= mul_scale;
for (int i=(int)buf_min;i<=(int)buf_max;i+=step){
/* Keep the entire part only */
buf_d = floor(buf_d);
buf_txt.str("");/* flush the buffer */
buf_txt << i%100;
/* Finally, fill the text buffer to display the graduate value */
buf_txt << buf_d;
/*
* Display the graduation time value.
*/
/*
* Display the graduation time value.
*/
glRasterPos2f( - (int)_x_state_translate % (int)_ruler_distance + i*_ruler_distance, _ruler_y+_ruler_height);/* set position */
glRasterPos2f(trace_to_render_x(i/adjustement)+0.2, _ruler_y+_ruler_height);/* set position */
if ( _info_degree_width < ( i*_ruler_distance - ((int)_x_state_translate % (int)_ruler_distance)) ){
for(unsigned int j = 0 ; j < buf_txt.str().length() ; j ++){
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
if ( _render_width*_x_scale_container_state <= trace_to_render_x(i/adjustement) ){/* Do not write if graduation is inside container area */
for(unsigned int j = 0 ; j < buf_txt.str().length() ; j ++){
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]);
}
}
}/* end for ( i ) */
buf_txt.str("");/* flush the buffer */
}/* end for ( i ) */
}
}
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