Commit 7ddc3b0a authored by Olivier Lagrasse's avatar Olivier Lagrasse

correction de bug + debut implementation dessin de trace

parent f04ae6a8
......@@ -68,21 +68,21 @@ Interface_graphic::~Interface_graphic(){
void Interface_graphic::error(const string s) const{
QString buf = s.c_str();
_ui_info_trace_text->moveCursor(QTextCursor::Start);/* Insert the new text on the beginning */
_ui_info_trace_text->insertHtml("<font color='red'>"+buf+"</font><br />");
_ui_info_trace_text->insertHtml("<font color='red'>"+buf+"</font><br /><br />");
}
void Interface_graphic::warning(const string s) const{
QString buf = s.c_str();
_ui_info_trace_text->moveCursor(QTextCursor::Start);/* Insert the new text on the beginning */
_ui_info_trace_text->insertHtml("<font color='orange'>"+buf+"</font><br />");
_ui_info_trace_text->insertHtml("<font color='orange'>"+buf+"</font><br /><br />");
}
void Interface_graphic::information(const string s) const{
QString buf = s.c_str();
_ui_info_trace_text->moveCursor(QTextCursor::Start);/* Insert the new text on the beginning */
_ui_info_trace_text->insertHtml("<font color='green'>"+buf+"</font><br />");
_ui_info_trace_text->insertHtml("<font color='green'>"+buf+"</font><br /><br />");
}
......@@ -106,17 +106,18 @@ void Interface_graphic::on_open_triggered(){
it's an interface class (Interface_graphic*). The real window is _ui_main_window.
If 'this' is put, the application closes after the getOpenFilename() dialog box closes.
*/
QString filename = QFileDialog::getOpenFileName(_ui_main_window);
if (!filename.isEmpty()){
// QString filename = QFileDialog::getOpenFileName(_ui_main_window);
//if (!filename.isEmpty()){
/*******************************************************/
/* Not Yet Implemented -> Send file path to the parser */
/*******************************************************/
_ui_render_area->build();
if (_ui_render_area->build()==false)
error("Open file : an error occured with wait screen releasing.");
error("Open : not yet implemented");
information(string("Open file : ")+ filename.toStdString());
// information(string("Open file : ")+ filename.toStdString());
/*
_trace = new Trace();
_parser = new Parser();
......@@ -126,7 +127,7 @@ void Interface_graphic::on_open_triggered(){
_list_container = _trace->get_root_containers();
*/
}
// }
}
......@@ -137,7 +138,8 @@ void Interface_graphic::on_close_triggered(){
/* Not Yet Implemented -> Stop the parser and the data structure if they are still implemented */
/***********************************************************************************************/
_ui_render_area->unbuild();
if (_ui_render_area->unbuild()==false)
error("Close file : an error occured with trace releasing.");
error("Close : not yet implemented");
}
......
......@@ -26,9 +26,10 @@ Render_area::Render_area(QWidget *parent)
_wait_list = 0;/* init list */
_wait_angle=0.0f;/* begin with 0 rad angle */
_wait_timer = NULL;
_wait_spf=10;/* 10 milliseconds per frame */
_wait_spf=DRAWING_TIMER_DEFAULT;/* DRAWING_TIMER_DEFAULT milliseconds per frame */
_drawing_list=0;
_drawing_height = DRAWING_HEIGHT_DEFAULT;
}
......@@ -39,9 +40,26 @@ Render_area::Render_area(QWidget *parent)
if (glIsList(_drawing_list)==GL_TRUE)
glDeleteLists(_drawing_list, 1);
if (_wait_timer!=NULL){
delete _wait_timer;
_wait_timer=NULL;
}
}
/***********************************
*
*
*
* Default QGLWidget functions.
*
*
*
**********************************/
void Render_area::initializeGL()
{
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
......@@ -58,8 +76,7 @@ void Render_area::resizeGL(int width, int height)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// gluPerspective(45,(double)640/480,0.1,1000);
glOrtho(0, 200, 0, 200, 0, 1000);
glMatrixMode(GL_MODELVIEW);
}
......@@ -69,6 +86,7 @@ void Render_area::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0,0,60,0,0,0,0,1,0);
......@@ -94,95 +112,29 @@ void Render_area::paintGL()
default:
_parent->error("Undefined value for the drawing state attribute - Render area");
}
glFlush();
}
GLuint Render_area::draw_wait()
{
GLuint object;
GLuint texture;
object = glGenLists(1);/* create the list */
if (object==0){
_parent->warning("Error when creating list");
}
glGenTextures(1, &texture);/* create the texture and link it with the list previously created */
texture = bindTexture(QPixmap(":/img/img/logo.png"), GL_TEXTURE_2D);
glNewList(object, GL_COMPILE);/* open the list */
{
glBindTexture(GL_TEXTURE_2D, texture);/* load texture for drawing */
glBegin(GL_QUADS);/* draw a square */
{
glTexCoord2d(0,0); glVertex2f(-15, -8);
glTexCoord2d(1,0); glVertex2f(15, -8);
glTexCoord2d(1,1); glVertex2f(15, 8);
glTexCoord2d(0,1); glVertex2f(-15, 8);
}
glEnd();
}
glEndList();/* close the list */
/* apply some parameters on the texture */
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);/* enable blending for the alpha color */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glFlush();
/* Now, timer is set */
_wait_angle = 0.0f;
_wait_timer = new QTimer(this);
connect(_wait_timer, SIGNAL(timeout()), this, SLOT(updateGL()));
_wait_timer->start(_wait_spf);
return object;
/* Check the errors */
GLenum glerror;
glerror = glGetError();
if( glerror != GL_NO_ERROR)
_parent->warning(string("Render area : the following OpengGL error occured: ") + string((char *)gluErrorString(glerror)));
}
GLuint Render_area::draw_trace()
{
GLuint object;
object = glGenLists(1);/* create the list */
if (object==0){
_parent->warning("Error when creating list");
}
glNewList(object, GL_COMPILE);/* open the list */
{
glBegin(GL_QUADS);/* create a quads */
{
glVertex2f(-15, -8);
glVertex2f(15, -8);
glVertex2f(15, 8);
glVertex2f(-15, 8);
}
glEnd();
}
glEndList();/* close the list */
return object;
}
/***********************************
*
*
*
* Building functions.
*
*
*
**********************************/
......@@ -190,7 +142,7 @@ bool Render_area::build(){
if (glIsList(_wait_list)==GL_TRUE)/* if the list exists */
glDeleteLists(_wait_list, 1);
if (_wait_timer->isActive()==true)/* if timer for the wait animation is running */
_wait_timer->stop();
......@@ -203,7 +155,7 @@ bool Render_area::build(){
}
/* if there is an error, do not display the trace an return immediatly */
if (_drawing_list!=0)
if (glIsList(_drawing_list)==GL_FALSE)
{
_parent->warning("Cannot create the trace.");
return false;
......@@ -215,17 +167,21 @@ bool Render_area::build(){
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
updateGL();
return true;
}
bool Render_area::unbuild(){
if (glIsList(_drawing_list)==GL_TRUE)/* if the list exists */
glDeleteLists(_drawing_list, 1);
if (_wait_timer->isActive()==true)/* if timer for the wait animation is running */
_wait_timer->stop();
if (_wait_timer->isActive()==false)/* if timer for the wait animation is not running */
_wait_timer->start(_wait_spf);
if (glIsList(_wait_list)==GL_FALSE)
_wait_list = draw_wait();/* create the wait draw */
......@@ -236,7 +192,7 @@ bool Render_area::unbuild(){
}
/* if there is an error, do not display the wait an return immediatly */
if (_wait_list!=0)
if (glIsList(_wait_list)==GL_FALSE)
{
_parent->warning("Cannot create the wait draw.");
return false;
......@@ -256,38 +212,144 @@ bool Render_area::unbuild(){
glEnable(GL_BLEND);/* enable blending for the alpha color */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
updateGL();
return true;
}
/***********************************
*
*
*
* Drawing function for the wait screen.
*
*
*
**********************************/
GLuint Render_area::draw_wait()
{
GLuint object;
GLuint texture;
object = glGenLists(1);/* create the list */
if (object==0){
_parent->warning("Error when creating list");
}
glGenTextures(1, &texture);/* create the texture and link it with the list previously created */
texture = bindTexture(QPixmap(":/img/img/logo.png"), GL_TEXTURE_2D);
glNewList(object, GL_COMPILE);/* open the list */
{
glBindTexture(GL_TEXTURE_2D, texture);/* load texture for drawing */
glBegin(GL_QUADS);/* draw a square */
{
glTexCoord2d(0,0); glVertex2f(-11, -8);
glTexCoord2d(1,0); glVertex2f(11, -8);
glTexCoord2d(1,1); glVertex2f(11, 8);
glTexCoord2d(0,1); glVertex2f(-11, 8);
}
glEnd();
}
glEndList();/* close the list */
/* apply some parameters on the texture */
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);/* enable blending for the alpha color */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
/* Now, timer is set */
if (_wait_timer==NULL){
_wait_angle = 0.0f;
_wait_timer = new QTimer(this);
connect(_wait_timer, SIGNAL(timeout()), this, SLOT(updateGL()));
_wait_timer->start(_wait_spf);
}
return object;
}
/***********************************
*
*
*
* Drawing function for the trace.
*
*
*
**********************************/
GLuint Render_area::draw_trace()
{
GLuint object;
object = glGenLists(1);/* create the list */
if (object==0){
_parent->warning("Error when creating list");
}
glNewList(object, GL_COMPILE);/* open the list */
{
draw_container(1, "AZZ");
draw_container(2, "B");
draw_state(0, 67.89, 20);
}
glEndList();/* close the list */
return object;
}
void draw_container(const Level level, const string &name){
void Render_area::draw_container(const Level level, const string &name) const{
/* QPainter painter(this);
qreal a = 100;
painter.drawText(QRectF::QRectF(a, a, a, a), Qt::AlignCenter, tr("coucou"));
*/
glBegin(GL_QUADS);/* create a quads */
{
glVertex2f(0, level);
glVertex2f(0, level+10);
glVertex2f(name.size(), level+10);
glVertex2f(name.size(), level);
glVertex2f(0, level*_drawing_height);
glVertex2f(0, (level+1)*_drawing_height);
glVertex2f(name.size(), (level+1)*_drawing_height);
glVertex2f(name.size(), level*_drawing_height);
}
glEnd();
}
/*void draw_state(const Date start, const Date end, const Level level) const{
void Render_area::draw_state(const Date start, const Date end, const Level level) const{
glBegin(GL_QUADS);
glBegin(GL_QUADS);/* create a quads */
{
glVertex2f(start, level);
glVertex2f(end, level+10);
glVertex2f(end, level+10);
glVertex2f(start, level);
glVertex2f(start, level*_drawing_height);
glVertex2f(end, (level+1)*_drawing_height);
glVertex2f(end, (level+1)*_drawing_height);
glVertex2f(start, level*_drawing_height);
}
glEnd();
}*/
}
......@@ -31,6 +31,19 @@ typedef double Date;
#define DRAWING_STATE_DRAWING 2
/*!
* \brief Time in ms between two frames for the waiting screen.
*/
#define DRAWING_TIMER_DEFAULT 10
/*!
* \brief The default height for containers and others trace elements.
*/
#define DRAWING_HEIGHT_DEFAULT 20
class QDESIGNER_WIDGET_EXPORT Render_area : public QGLWidget
{
Q_OBJECT
......@@ -42,6 +55,18 @@ class QDESIGNER_WIDGET_EXPORT Render_area : public QGLWidget
*/
GLuint _wait_list;
/*!
* \brief The trace Glu list.
*/
GLuint _drawing_list;
/*!
* \brief Define the trace height.
*/
double _drawing_height;
/*!
* \brief Rotation angle for the wait.
*/
......@@ -57,7 +82,7 @@ class QDESIGNER_WIDGET_EXPORT Render_area : public QGLWidget
*/
int _wait_spf;
GLuint _drawing_list;
Interface_graphic* _parent;
int _drawing_state;
......@@ -91,8 +116,8 @@ class QDESIGNER_WIDGET_EXPORT Render_area : public QGLWidget
GLuint draw_trace();
void draw_container(const Level level, const string &name);
// void draw_state(const Date start, const Date end, const Level level) const;
void draw_container(const Level level, const string &name) const;
void draw_state(const Date start, const Date end, const Level level) const;
public:
......
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