Commit 5381dfd5 authored by Olivier Lagrasse's avatar Olivier Lagrasse

Modification render area

parent e28f6ab2
......@@ -345,10 +345,14 @@ void Interface_graphic::on_translate_state_valueChanged(int new_value){
_ui_render_area->change_translate(new_value);
}
void Interface_graphic::on_scale_container_state_valueChanged(int new_value){
_ui_render_area->change_scale_container_state(new_value);
}
void Interface_graphic::on_main_window_hide(){
......
......@@ -274,6 +274,7 @@ protected slots:
void on_scale_state_valueChanged(int new_value);/* temporary slot */
void on_translate_state_valueChanged(int new_value);/* temporary slot */
void on_scale_container_state_valueChanged(int new_value);/* temporary slot */
void on_main_window_hide();
};
......
......@@ -26,18 +26,50 @@
<normaloff>:/icon/icon/vite.png</normaloff>:/icon/icon/vite.png</iconset>
</property>
<widget class="QWidget" name="centralwidget" >
<property name="geometry" >
<rect>
<x>0</x>
<y>26</y>
<width>888</width>
<height>579</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" >
<item>
<layout class="QVBoxLayout" name="render_area_layout" />
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3" >
<item>
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Scale containers/states: </string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="scale_container_state" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="value" >
<number>20</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</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>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
......@@ -56,7 +88,7 @@
</sizepolicy>
</property>
<property name="maximum" >
<number>100000</number>
<number>10000</number>
</property>
<property name="pageStep" >
<number>1</number>
......@@ -88,6 +120,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum" >
<number>1</number>
</property>
<property name="maximum" >
<number>100000</number>
</property>
......
......@@ -38,16 +38,39 @@ Render_area::Render_area(QWidget *parent)
/* init the trace drawing */
_drawing_list=0;
_counter_last_x=0;
_counter_last_y=0;
/* init main informations about OpenGL scene and QGLWidget size */
_screen_width = width();/* get the QGLWidget visibled width (in pixel) */
_screen_height = height();/* get the QGLWidget visibled height (in pixel) */
_render_width = 100;/* 100 OpenGL units for the render scene width */
_render_height = 100;/* 100 OpenGL units for the render scene height */
_container_x_max = 0;
_container_y_max = 0;
/* attributes */
_state_x_max = 0;
_state_y_max = 0;
_x_scale_container_state = 0.2;/* 20% of screen is used for containers then the other part for states */
/* OpenGL lists */
_list_containers =0;
_list_states = 0;
_list_counters = 0;
_state_scale = 1;/* temporary, for states scaling */
_state_translate = 0;/* temporary, for states translation */
_container_view_size = 50;/* temporary, for container view */
//_container_view_size = 50;/* temporary, for container view */
_z_arrow = 1;/* closer to camera than containers or states */
......@@ -97,6 +120,10 @@ void Render_area::initializeGL(){
void Render_area::resizeGL(int width, int height){
glViewport(0, 0, width, height);
/* update informations about widget size */
_screen_width = width;
_screen_height = height;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
......@@ -108,7 +135,7 @@ void Render_area::resizeGL(int width, int height){
glOrtho(-50, 50, -50, 50, 0, 1000);
break;
case DRAWING_STATE_DRAWING:// A trace is drawn
glOrtho(0, 100, 0, 100, 0, 1000);
glOrtho(0, _render_width, 0, _render_height, 0, 1000);
break;
default:
message << "Undefined value for the drawing state attribute - Render area" << ende;
......@@ -166,8 +193,12 @@ void Render_area::paintGL(){
glPushMatrix();
glTranslatef(0.0f, 40.0f, -1.0f);
/* glTranslatef(0.0f, 40.0f, -1.0f);
glScalef(10.0f/_container_x_max, 50.0f/_container_y_max, 0.0f);
*/
glTranslatef(0.0f, 0.0f, -1.0f);
glScalef( (_render_width/_container_x_max)*_x_scale_container_state, _render_height/_container_y_max, 0.0f);
......@@ -199,9 +230,13 @@ void Render_area::paintGL(){
glPushMatrix();
glTranslatef(0.0f, 40.0f, 0.0f);
/* glTranslatef(0.0f, 40.0f, 0.0f);
glScalef(10.0f/_container_x_max, 50.0f/_container_y_max, 0.0f);
*/
glScalef( (_render_width/_container_x_max)*_x_scale_container_state, _render_height/_container_y_max, 0.0f);
glColor3d(1, 1, 1);
glRasterPos2f(buf_x,buf_y);
......@@ -221,9 +256,13 @@ void Render_area::paintGL(){
/* Draw states */
glPushMatrix();
glTranslated(20.0f-_state_translate, 40.0f, -2.0f);
glScalef(_state_scale, 50.0f/_container_y_max, 0.0f);
/* glTranslated(20.0f-_state_translate, 40.0f, -2.0f);
glScalef(_state_scale, 50.0f/_container_y_max, 0.0f);*/
glTranslated( _render_width*_x_scale_container_state-_state_translate , 0.0f, -2.0f);
glScalef( _state_scale*(_render_width/_state_x_max), _render_height/_state_y_max, 0.0f);
if (glIsList(_list_states)==GL_FALSE)
message << "ERROR LIST not exist for states." << ende;
else
......@@ -232,6 +271,9 @@ void Render_area::paintGL(){
glPopMatrix();
//glCallList(_list_counters);
break;
default:
message << "Undefined value for the drawing state attribute - Render area" << ende;
......@@ -266,9 +308,9 @@ void Render_area::change_translate(int translate){
}
void Render_area::change_container_view(int view_size){
void Render_area::change_scale_container_state(int view_size){
_container_view_size = view_size*(width()/100);
_x_scale_container_state = 0.01f * view_size;
updateGL();
}
......
......@@ -178,9 +178,45 @@ class Render_area : public QGLWidget, public Render
GLuint _drawing_list;
Element_pos _counter_last_x;
Element_pos _counter_last_y;
/*!
* \brief The opengl render area width in pixels.
*/
Element_pos _screen_width;
/*!
* \brief The opengl render area height in pixels.
*/
Element_pos _screen_height;
/*!
* \brief The opengl visibled scene width in the OpenGL units.
*/
Element_pos _render_width;
/*!
* \brief The opengl visibled scene height in the OpenGL units.
*/
Element_pos _render_height;
Element_pos _container_x_max;
Element_pos _container_y_max;
Element_pos _state_x_max;
Element_pos _state_y_max;
Element_pos _x_scale_container_state;
Element_pos _z_arrow;/* z position for arrows */
......@@ -196,7 +232,7 @@ class Render_area : public QGLWidget, public Render
int _state_scale;/* temporary */
int _state_translate;/* temporary */
int _container_view_size;/* temporary */
// int _container_view_size;/* temporary */
public:
......@@ -239,7 +275,8 @@ class Render_area : public QGLWidget, public Render
void change_scale(int scale);/* temporary -> to change the scale to view states */
void change_translate(int translate);/* temporary -> to change the translate to view states */
void change_container_view(int view_size);/* temporary -> to change the size of container view */
void change_scale_container_state(int view_size);/* temporary -> to change the size of container view */
void start_draw();
......@@ -402,6 +439,12 @@ inline void Render_area::draw_state(const Element_pos start, const Element_pos e
glColor3d(r*2, g*2, b*2);glVertex2d(end, base);
}
glEnd();
if (end>_state_x_max)
_state_x_max = end;
if ((base+height)>_state_y_max)
_state_y_max = base+height;
}
......@@ -517,19 +560,40 @@ inline void Render_area::start_draw_counter(){
glNewList(_list_counters, GL_COMPILE);/* open the list */
glColor3d(0.7, 0.7, 0.7);
glBegin(GL_LINES);
}
inline void Render_area::draw_counter(const Element_pos x, const Element_pos y){
glVertex2d(x, y);
static bool which_color = true;
float a;
if (which_color==true){/* yellow color */
a = 0.0f;
which_color = false;
}else{/* white color */
a = 1.0f;
which_color = true;
}
glLineWidth(2.5f);
glBegin(GL_QUADS);
{
glColor3d(1.0, 1.0, a);glVertex2d(_counter_last_x, 0);
glColor3d(1.0, 1.0, a);glVertex2d(_counter_last_x, _counter_last_y);
glColor3d(1.0, 1.0, a);glVertex2d(x, y);
glColor3d(1.0, 1.0, a);glVertex2d(x, 0);
}
glEnd();
glLineWidth(1.0f);
_counter_last_x = x;
_counter_last_y = y;
}
inline void Render_area::end_draw_counter(){
glEnd();
glEndList();/* close the list */
}
......
......@@ -50,6 +50,7 @@ void Svg::end(){
_buffer << "\n</svg>";
_svg_file.write(_buffer.str().c_str(), _buffer.str().size());
_buffer.flush();
_buffer.str("");
_svg_file.close();
#ifdef TEST_SVG_MODE
......
......@@ -6,7 +6,7 @@
#include <sstream>
#include <fstream>
#define BUFFER_SIZE 2048 //character number stored before flush the _buffer
#define BUFFER_SIZE 10 //character number stored before flush the _buffer
#define LEVEL 110 //distance between two containers
#define MARGIN 10 //distance between two object
#define ARROWSIZE 4 //spike size
......@@ -136,6 +136,7 @@ inline void Svg::end_draw_counter(){
inline void Svg::end_draw(){
Svg::end();
}
void Svg::rectangle(const char* name,unsigned long w, unsigned long h,unsigned long x1,unsigned long y1, unsigned int r, unsigned int g, unsigned int b ){
......@@ -144,7 +145,7 @@ void Svg::rectangle(const char* name,unsigned long w, unsigned long h,unsigned l
<<"' x='" << x1
<<"' y='" << y1
<<"' fill='rgb("<<r<<","<<g<<","<<b
<<")'/>";
<<")'/>" << std::endl;
print();
}
......@@ -157,16 +158,14 @@ void Svg::triangle(const char* name,unsigned long x1,unsigned long y1,unsigned l
<< x1 << "," << y1
<< " " << x2 << "," << y2
<< " " << x3 << "," << y3
<<"' />";
<<"' />" << std::endl;
print();
}
void Svg::print(){
if (_buffer.str().size()>BUFFER_SIZE){
// if (_buffer.str().size()>BUFFER_SIZE){
_svg_file.write(_buffer.str().c_str(), _buffer.str().size());
_buffer.flush();
_buffer.str("");
}
}
......
......@@ -52,7 +52,8 @@ int main(int argc, char** argv){
r.start_draw_containers();
{
r.draw_container(0, 0, 30, 20);
r.draw_container(0, 22, 30, 20);
r.draw_container(0, 22, 10, 20);
r.draw_container(0, 43, 15, 20);
// r.draw_container(1, 60, 60, 20);
r.draw_container_text(0, 10,"Container 2");
r.draw_container_text(0, 32,"Container 1");
......@@ -74,6 +75,16 @@ int main(int argc, char** argv){
}
r.end_draw_states();
r.start_draw_counter();
{
r.draw_counter(5, 1);
r.draw_counter(17, 2);
r.draw_counter(19.345, 3);
r.draw_counter(21.45, 2);
}
r.end_draw_counter();
}
......
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