Commit 4e43592e authored by Olivier Lagrasse's avatar Olivier Lagrasse
Browse files

dessin de container (mode debug)

parent 8875d4be
......@@ -40,6 +40,8 @@ plugins:
@echo " "
#debugs:
#cd ./src && qmake-qt4 -project && qmake-qt4 -makefile -o Makefile "RESOURCES= vite.qrc" "OBJECTS_DIR=../debug" "CONFIG+=uitools debug console" "QT+=opengl" "DESTDIR = ../debug" src.pro && make all
#mv src/*.o bin/
......@@ -48,8 +50,8 @@ plugins:
#@echo " "
tests: build
cd ./tests && qmake-qt4 -project && qmake-qt4 -makefile -o Makefile "RESOURCES= ../src/vite.qrc" "OBJECTS_DIR=../bin" "CONFIG+=uitools" "QT+=opengl" "DESTDIR = ../bin" tests.pro && make all
tests:all
cd ./tests && qmake-qt4 -project && qmake-qt4 -makefile -o Makefile "OBJECTS_DIR=../bin" "CONFIG+=uitools debug" "QT+=opengl" "DESTDIR = ../bin" tests.pro && make all
@echo " "
@echo "Compilation completed! (test)"
@echo " "
......
......@@ -24,7 +24,7 @@ Interface_graphic::Interface_graphic(QWidget *parent):QWidget(parent){
/* Init pointer attributes */
// _parser = NULL;
//_trace = NULL;
_trace = NULL;
load_windows();
}
......@@ -34,7 +34,7 @@ Interface_graphic::Interface_graphic(char* file_path, QWidget *parent):QWidget(p
/* Init pointer attributes */
// _parser = NULL;
//_trace = NULL;
_trace = NULL;
load_windows();
......@@ -148,8 +148,8 @@ void Interface_graphic::information(const string s) const{
**********************************/
bool Interface_graphic::build(){
return _ui_render_area->build();
bool Interface_graphic::build(Trace* trace){
return _ui_render_area->build(trace);
}
......@@ -178,12 +178,13 @@ void Interface_graphic::on_open_triggered(){
/* Not Yet Implemented -> Send file path to the parser */
/*******************************************************/
if (_ui_render_area->build()==false)
error("Open file : an error occured with wait screen releasing.");
if (build(_trace)==false)
error("Open file : an error occured with wait screen releasing.");
error("Open : not yet implemented");
information(string("File opened: ")+ filename.toStdString());
/*
/*
_trace = new Trace();
_parser = new Parser();
_parser->parse(filename.toStdString(), _trace);
......
......@@ -106,7 +106,7 @@ class Interface_graphic : public QWidget, public Interface{
/*!
* \brief The data structure attribute.
*/
//Trace* _trace;
Trace* _trace;
public:
......@@ -176,9 +176,10 @@ public:
**********************************/
/*!
*\brief This function will build the trace sent by the data structure ('_trace').
* \brief This function will build the trace sent by the data structure ('_trace').
* \arg trace The trace which be displayed.
*/
bool build();
bool build(Trace* trace);
......
......@@ -44,6 +44,8 @@ Render_area::Render_area(QWidget *parent)
_container_height = DRAWING_CONTAINER_HEIGHT_DEFAULT;
_container_h_space = DRAWING_CONTAINER_H_SPACE_DEFAULT;
_container_v_space = DRAWING_CONTAINER_V_SPACE_DEFAULT;
_trace = NULL;
}
......@@ -120,6 +122,21 @@ void Render_area::paintGL()
break;
case DRAWING_STATE_DRAWING:/* A trace is drawn */
glBegin(GL_LINES);
{
glColor3d(1, 0, 0);glVertex2d(0, 0);
glColor3d(1, 0, 0);glVertex2d(100, 0);
}
glEnd();
glBegin(GL_LINES);
{
glColor3d(0, 0, 1);glVertex2d(0, 0);
glColor3d(0, 0, 1);glVertex2d(0, 100);
}
glEnd();
glCallList(_drawing_list);
break;
......@@ -152,7 +169,9 @@ void Render_area::paintGL()
bool Render_area::build(){
bool Render_area::build(Trace* trace){
_trace = trace;
if (glIsList(_wait_list)==GL_TRUE)/* if the list exists */
glDeleteLists(_wait_list, 1);
......@@ -191,6 +210,8 @@ bool Render_area::build(){
bool Render_area::unbuild(){
_trace = NULL;
if (glIsList(_drawing_list)==GL_TRUE)/* if the list exists */
glDeleteLists(_drawing_list, 1);
......@@ -314,7 +335,6 @@ GLuint Render_area::draw_wait()
**********************************/
GLuint Render_area::draw_trace()//Trace trace)
{
GLuint object;
......@@ -324,6 +344,7 @@ GLuint Render_area::draw_trace()//Trace trace)
_parent->warning("Error when creating list");
}
glNewList(object, GL_COMPILE);/* open the list */
{
......@@ -335,117 +356,192 @@ GLuint Render_area::draw_trace()//Trace trace)
* vertically, else horizontally.
*/
// stack<Element_count> position_stack;
// stack<Element_count> height_stack;
// Element_pos x;
// Element_pos y;
// Element_pos y_buf;
// list<Container *> * trace_container;
stack<Element_count> position_stack;
stack<Element_count> height_stack;
Element_pos x;
Element_pos y;
Element_pos y_buf;/* buffer for the y position */
Element_pos height_buf;/* buffer for the container height */
Container* container;
list<Container *> trace_container;
// list<Container *>::iterator it;
// bool isAnotherContainer = true;/* use to stop the loop */
list<Container *>::iterator it;
bool isAnotherContainer = true;/* use to stop the loop */
// trace_container = _trace->get_root_containers();
// position_stack.push(0);
// height_stack.push(0);
trace_container = _trace->get_root_containers();
position_stack.push(0);
height_stack.push(0);
// if (trace_container->getChildren().size() <= 1)
// x = _container_width;
// else
// x = _container_height;
container = get_container(trace_container, 0);
// y_buf = 0;
if (container->get_children().size() <= 1)
x = _container_width;
else
x = _container_height;
y = 0;
y_buf = 0;
height_buf = 0;
// while (isAnotherContainer==true){
while (isAnotherContainer==true){
// Element_pos buf_pos;
Element_pos buf_pos;
// buf_pos = position_stack.top();
buf_pos = return_last_visited_child(position_stack);
// /* If all children are not yet visited */
// if (buf_pos < trace_container->getChildren().size()){
// position_stack.top()++;/* add a child */
// position_stack.push(0);/* prepare for the next child */
// y_buf = height_stack.top();
// y += y_buf;
// for (int i = 0, it=trace_container.begin() ; i<buf_pos; it++, i++ );
// trace_container = &it;
// if (trace_container->getChildren().size() == 1)/* Check the child count of the child container */
// x += _container_width+_container_h_space;/* if there is just one child, container can be draw horizontally */
// else
// x += _container_height+_container_h_space;/* With more than 2 children, container should be draw vertically */
/* If all children are not yet visited */
if (buf_pos < number_of_children(container)){
position_stack.top()++;/* add a child */
position_stack.push(0);/* prepare for the next child */
// }else{/* all children have been visited or there is not child, thus it's time to draw ! */
// position_stack.pop();/* remove the information of the container hence it will be drawn */
// if (trace_container->getChildren().size() <= 1){/* Should be drawn horizontally */
// height_stack.push(_container_height + _container_v_space);
// draw_container(x, y, _container_width, _container_height);
// x = x - _container_width - _container_h_space;
// }else{ /* Should be drawn vertically */
// y_buf = 0;
cerr << endl << "EXPLORER "; container->disp();
container = get_container(container->get_children(), buf_pos);
cerr << "EXPLORE NEW CHILD ";container->disp();
if (1 >= number_of_children(container))/* Check the child count of the child container */
x += _container_width+_container_h_space;/* if there is just one child, container can be draw horizontally */
else
x += _container_height+_container_h_space;/* With more than 2 children, container should be draw vertically */
}else{/* all children have been visited or there is not child, thus it's time to draw ! */
position_stack.pop();/* remove the information of the container hence it will be drawn */
if (1 >= number_of_children(container)){/* Should be drawn horizontally */
if (0 == number_of_children(container)){
/* y contains the current height, y_buf the new adding height */
y_buf = _container_height+_container_v_space;
height_stack.push(y_buf);
y += y_buf;
}
draw_container(x, y, _container_width, _container_height);
cerr << "DRAW HORIZ " << x << " " << y <<" : "<<_container_width << " " << _container_height;
container->disp();
x -= (_container_width + _container_h_space);
}else{ /* Should be drawn vertically */
height_buf = 0;
for (unsigned int i=0;i < number_of_children(container);i++){
height_buf += height_stack.top() + _container_v_space;
height_stack.pop();
}
height_buf -= _container_v_space;
height_stack.push(height_buf);/* push the sum of child heights */
// for (int i=0;i<trace_container->getChildren().size();i++){
// y_buf += height_stack.top();
// height_stack.pop();
// }
// height_stack.push(y_buf);
// draw_container(x, y, _container_height, y_buf);/* Vertically, it is drawn as higher as it has children */
// }
// /* Now, container was drawn. It's time to go back up */
// if (trace_container.get_parent()!=NULL){
// if (trace_container.get_parent().get_parent()!=NULL)
// trace_container = trace_container.get_parent().get_parent().getChildren();
// else
// trace_container = _trace->get_root_containers();
// }
// else/* It is the root container */
// isAnotherContainer = false;/* end of the loop */
// }/* end "else" of "if (position_stack < trace_container->getChildren().size())" */
// }/* end "while (isAnotherContainer==true)"*/
draw_container(x, y, _container_height, height_buf);/* Vertically, it is drawn as higher as it has children */
cerr << "DRAW VERT " << x << " " << y <<" : "<<_container_height << " " << height_buf;
container->disp();
x -= (_container_height + _container_h_space);
}
/* Now, container was drawn. It's time to go back up */
if (container->get_parent()!=NULL){
int buf = position_stack.top();
position_stack.pop();
if (container->get_parent()->get_parent()!=NULL){
cerr << "REACH HIS FATHER ";container->disp();
container = get_container( container->get_parent()->get_parent()->get_children(), position_stack.top()-1);/* '-1' because we continu with the same container, not the following */
cerr << "IS -> ";container->disp();
}
else{
cerr << "REACH ROOT ";container->disp();
container = container->get_parent();//get_container(_trace->get_root_containers(), 0);
}
position_stack.push(buf);
}
else/* It is the root container */
isAnotherContainer = false;/* end of the loop */
}/* end "else" of "if (position_stack < trace_container->getChildren().size())" */
}/* end "while (isAnotherContainer==true)"*/
}
glEndList();/* close the list */
return object;
}
inline Element_count Render_area::number_of_children(Container* c){
return c->get_children().size();
}
inline Element_count Render_area::return_last_visited_child(stack<Element_count> &s){
if (s.empty()==true){
_parent->error("The render area position stack is empty.");
return -1;
}
else
return s.top();
}
Container* Render_area::get_container(list <Container*> list_container, int pos) const{
list<Container *>::iterator it;
int i=0;
for (it=list_container.begin() ; i<pos; it++, i++ ){ }
return *it;
}
void Render_area::draw_container(Element_pos x, Element_pos y, Element_pos w, Element_pos h) const{
static float j=0.1;
glPushMatrix();
glTranslatef(20, 40, 0);
glScalef(20, 20, 20);
glBegin(GL_QUADS);/* create a quads */
{
glVertex2d(x, y);
glVertex2d(x, y-h);
glVertex2d(x-w, y-h);
glVertex2d(x-w, y);
glColor3d(j, 0, j);glVertex2d(x, y);
glColor3d(j, j, j);glVertex2d(x, y-h);
glColor3d(j, j, j);glVertex2d(x-w, y-h);
glColor3d(j, j, 0);glVertex2d(x-w, y);
}
glEnd();
glPopMatrix();
j+=0.2;
}
void Render_area::draw_state(const Date start, const Date end, const Level level) const{
......
......@@ -17,7 +17,8 @@ typedef double Date;
#include "resource.hpp"
//#include "interface_graphic.hpp"
......@@ -25,7 +26,7 @@ typedef double Date;
/*!
* \brief This class redefined the OpenGL widget - QGLWidget - to display the trace.
*/
class QDESIGNER_WIDGET_EXPORT Render_area : public QGLWidget
class Render_area : public QGLWidget
{
Q_OBJECT
......@@ -48,6 +49,18 @@ class QDESIGNER_WIDGET_EXPORT Render_area : public QGLWidget
/***********************************
*
* Data structure attributes.
*
**********************************/
/*!
* \brief The data structure attribute.
*/
Trace* _trace;
/***********************************
*
......@@ -167,22 +180,22 @@ class QDESIGNER_WIDGET_EXPORT Render_area : public QGLWidget
/*!
* \brief The default height for containers.
*/
static const float DRAWING_CONTAINER_HEIGHT_DEFAULT = 20.0f;
static const float DRAWING_CONTAINER_HEIGHT_DEFAULT = 1.0f;
/*!
* \brief The default width for containers.
*/
static const float DRAWING_CONTAINER_WIDTH_DEFAULT = 50.0f;
static const float DRAWING_CONTAINER_WIDTH_DEFAULT = 2.0f;
/*!
* \brief The default horizontal space between containers.
*/
static const float DRAWING_CONTAINER_H_SPACE_DEFAULT = 2.0f;
static const float DRAWING_CONTAINER_H_SPACE_DEFAULT = 0.2f;
/*!
* \brief The default vertical space between containers.
*/
static const float DRAWING_CONTAINER_V_SPACE_DEFAULT = 5.0f;
static const float DRAWING_CONTAINER_V_SPACE_DEFAULT = 0.2f;
/*!
* \brief Geometrical informations about the trace shape.
......@@ -203,6 +216,19 @@ class QDESIGNER_WIDGET_EXPORT Render_area : public QGLWidget
*/
GLuint draw_trace();
inline Element_count number_of_children(Container* c);
inline Element_count return_last_visited_child(std::stack<Element_count> &s);
/*!
* \brief Return the pos container of the list
*/
Container* get_container(std::list <Container*> list_container, int pos) const;
/*!
* \brief Draw a container according to the parameters
* \param x the x position of the container
......@@ -252,8 +278,9 @@ class QDESIGNER_WIDGET_EXPORT Render_area : public QGLWidget
/*!
* \brief This function draws the trace.
* \arg trace the trace which be displayed.
*/
bool build();
bool build(Trace* trace);
/*!
* \brief This function releases the trace.
......
......@@ -12,4 +12,6 @@
#include "../../main_resource.hpp"
#endif
......@@ -3,7 +3,7 @@ RESOURCES= vite.qrc
SOURCES+=../../main.cpp
OBJECTS_DIR=../bin
DESTDIR=../../bin
CONFIG+=uitools
CONFIG+=uitools debug
QT+=opengl
TEMPLATE = app
DEPENDPATH += .
......
......@@ -7,10 +7,7 @@
#ifndef RESOURCE_TEST_HPP
#define RESOURCE_TEST_HPP
#include <iostream>
#include "../src/interface_console.hpp"
#include "../src/interface_graphic.hpp"
#include "../../main_resource.hpp"
#define ASSERT_SUCCESS 0
......
/*!
*\file test_window_creation.cpp
*\brief This test simply launch a window directly (without use the terminal interface). User have to close it manually.
*/
#include "resource_test.hpp"
/*!
*\brief The main function which launches the test.
*/
int main(int argc, char ** argv){
cout << "Time to display the window (expected result : immediatly)" << endl;
cout << "Position of the window inside the screen (expected result : center on X and Y)" << endl;
cout << "Size of the window (expected result : all the width, and just 600px (around) on the height)" << endl;
cout << "Icon of the window (expected result : the ViTE logo)" << endl;
cout << "Title of the window (expected result : 'ViTE')" << endl;
cout << "The application size in the computer memory (expected result : ********)";
QApplication app(argc, argv);
Interface_graphic window;
window.show();
return app.exec();
}
......@@ -5,6 +5,8 @@
#ifndef MAIN_RESOURCE_HPP
#define MAIN_RESOURCE_HPP
......@@ -12,7 +14,7 @@
#include <QtGui>/* for all of the Qt's Widgets */
#include <QtUiTools>/* for the run-time loading .ui file */
#include <QGLWidget>/* for the OpenGL Widget */
#include <QtDesigner/QDesignerExportWidget>/* For the render area plugin */
#include <iostream>/* to use the C standard library input output functions */
......@@ -22,6 +24,7 @@
#include <cstdlib> /* for macros EXIT_SUCCESS and EXIT_FAILURE */
#include <cmath>
#include <stack>
#include <list>
/* These paths corresponding to the path in the resource file ('vite.qrc' in the 'bin' folder) */
#define UI_MAIN_WINDOW_NAME ":/window/main_window.ui"/* The main window ui file. */
......@@ -55,12 +58,27 @@ class Interface_graphic;
class Render_area;
#include "interface.hpp"
class Trace;
class Container;
#include "interface/tests/test_trace.hpp"
#include "interface/src/interface.hpp"
#include "interface/src/interface_console.hpp"
#include "interface/src/interface_graphic.hpp"
#include "interface/src/render_area.hpp"
/* */