diff --git a/src/interface/interface_console.cpp b/src/interface/interface_console.cpp index 6d0bbe631efa645f72e48ccf3a19d8e8db6d35ba..ed4f186f98c85a961a03053121b12983c087b95b 100644 --- a/src/interface/interface_console.cpp +++ b/src/interface/interface_console.cpp @@ -4,9 +4,12 @@ */ + + #include "interface_console.hpp" + using namespace std; #define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): " @@ -23,9 +26,6 @@ using namespace std; Interface_console::Interface_console(int argc, char ** argv){ - - - int state; bool useGUI;/* if window interface can be displayed */ QString current_path; @@ -33,6 +33,7 @@ Interface_console::Interface_console(int argc, char ** argv){ app = new QApplication(argc, argv);/* create the Qt application */ current_path = QDir::currentPath(); _run_env[0] = new char[current_path.length()+1]; + if (!strcpy(_run_env[0], current_path.toStdString().c_str())) { cerr << "Error : in " << __FILE__ << " at line " << __LINE__ << "." << endl; cerr << "Reason : Copy of the current path directory failed." << endl; @@ -44,8 +45,8 @@ Interface_console::Interface_console(int argc, char ** argv){ Message::set_interface(this);/* define which interface will receive messages */ useGUI = true; - // argc = 1; + glutInit(&argc, argv);/* use for OpenGL text */ /* Qt uses the default system encoding for QString (used when opening a file) */ QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale()); @@ -68,7 +69,6 @@ Interface_console::Interface_console(int argc, char ** argv){ - } @@ -92,59 +92,66 @@ Interface_console::~Interface_console(){ * **********************************/ - -bool Interface_console::draw_trace(const string & filename){//, Render_opengl* render_area){ - - if (_render_opengl==NULL){ - message << "Error, no render area bound to the main window" << Message::ende; - return false; - } +bool Interface_console::draw_trace(const string & filename, const int format){ Trace trace; ParserPaje parser; - DrawTrace<Render_opengl> drawing; - - QApplication::setOverrideCursor(Qt::WaitCursor); - try{ - - parser.parse(filename, trace); - } - catch (const string &error){ - //message << "unable to parse " << filename << ende; - *Message::get_instance() << "Reason : " << error << Message::ende; - return false; - } - - drawing.build(_render_opengl, &trace); - - _render_opengl->build(); - - _render_opengl->updateGL(); - - QApplication::restoreOverrideCursor(); - - return true; -} + QApplication::setOverrideCursor(Qt::WaitCursor); + switch(format){ + /******************* + * OpenGL render + *******************/ + case _DRAW_OPENGL: + { + DrawTrace<Render_opengl> drawing_ogl; + + try{ + parser.parse(filename, trace); + } + catch (const string &error){ + *Message::get_instance() << "Reason : " << error << Message::ende; + return false; + } + + drawing_ogl.build(_render_opengl, &trace); + _render_opengl->build(); + _render_opengl->updateGL(); + } -bool Interface_console::draw_trace(const string & filename, Svg* svg){ + _file_opened = filename;/* store filename for a future export */ - Trace trace; - ParserPaje parser; - DrawTrace<Svg> drawing; - - QApplication::setOverrideCursor(Qt::WaitCursor); - try{ - parser.parse(filename, trace); - } - catch (const string &error){ - //message << "unable to parse " << filename << ende; - *Message::get_instance() << "Reason : " << error << Message::ende; + break; + /******************* + * SVG render + *******************/ + case _DRAW_SVG: + { + Svg svg; + svg.init(_path_to_export.c_str()); + DrawTrace<Svg> drawing_svg; + + try{ + parser.parse(filename, trace); + } + catch (const string &error){ + *Message::get_instance() << "Reason : " << error << Message::ende; + return false; + } + + drawing_svg.build(&svg, &trace); + svg.end(); + } + break; + /******************* + * Error + *******************/ + default: + *Message::get_instance() << "No kind of render recognized" << Message::ende; return false; } - - drawing.build(svg, &trace); + QApplication::restoreOverrideCursor(); @@ -226,74 +233,6 @@ int Interface_console::get_state(int argc, char** argv){ } return state; - - //////////////////////////////////////////////////////////////// -// switch(argc){ -// case 1: /* just the name of the program, launch the window interface */ -// return _STATE_LAUNCH_GRAPHICAL_INTERFACE; - -// case 2: /* There is one argument */ -// if (strncmp(argv[1], "-h", 2) == 0){ -// /* display the help message */ -// return _STATE_DISPLAY_HELP; -// } -// else{ -// /* should be a path of a file */ -// _file_opened = argv[1];/* store the path of the file */ -// return _STATE_OPEN_FILE; -// } - -// case 3: // open a file -// if (strncmp(argv[1], "-f", 2) == 0 || strncmp(argv[1], "-a", 2) == 0){ -// /* should be a path of a file */ -// _file_opened = argv[2];/* store the path of the file */ -// return _STATE_OPEN_FILE; -// } -// else{ -// return _STATE_DISPLAY_HELP; -// } - -// case 4: // open a file in an interval -// if(strncmp(argv[2], "-t", 2) == 0){ -// _file_opened = argv[1];/* store the path of the file */ - -// extract_times(argv[3]); -// return _STATE_OPEN_FILE_IN_AN_INTERVAL; -// } -// else{ -// return _STATE_DISPLAY_HELP; -// } -// case 5: // export a file -// if (strncmp(argv[1], "-f", 2) == 0){ -// /* should be a path of a file */ -// _file_opened = argv[2];/* store the path of the file */ - -// if(strncmp(argv[3], "-e", 2) == 0){ -// _path_to_export = argv[4]; -// } -// else{ -// return _STATE_DISPLAY_HELP; -// } -// return _STATE_EXPORT_FILE; -// } -// else{ -// return _STATE_DISPLAY_HELP; -// } -// case 7: // export a piece of trace -// if (strncmp(argv[1], "-f", 2) == 0 && strncmp(argv[3], "-e", 2) == 0 && strncmp(argv[5], "-t", 2) == 0) { -// /* should be a path of a file */ -// _file_opened = argv[2];/* store the path of the file */ -// _path_to_export = argv[4]; -// extract_times(argv[6]); -// return _STATE_EXPORT_FILE_IN_INTERVAL; -// } -// else{ -// return _STATE_DISPLAY_HELP; -// } -// default: -// break; -// } -// return _STATE_UNKNOWN; } void Interface_console::extract_times(const char *name){ @@ -328,7 +267,6 @@ void Interface_console::launch_action(int state, void* arg){ case _STATE_DISPLAY_HELP : display_help(); - exit(EXIT_SUCCESS); break; case _STATE_LAUNCH_GRAPHICAL_INTERFACE : @@ -341,7 +279,7 @@ void Interface_console::launch_action(int state, void* arg){ break; case _STATE_OPEN_FILE: - information(string("Opening the file: ")+string(_file_opened)); + 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 */ _render_opengl = new Render_opengl(_main_window); @@ -349,23 +287,25 @@ void Interface_console::launch_action(int state, void* arg){ _main_window->opening_file(_file_opened);/* Must be called after binding the render area to the main window */ - if(false==draw_trace(_file_opened)) + if(false==draw_trace(_file_opened, _DRAW_OPENGL)) message << "Draw trace failed" << Message::ende; break; case _STATE_EXPORT_FILE: + if (true == _file_opened.empty()){ + *Message::get_instance() << "Please to previously open a trace." << Message::endw; + return; + } + *Message::get_instance() << "export of " << _file_opened << " to " << _path_to_export << Message::endi; ///// Do the export ///// { - Svg svg; - svg.init(_path_to_export); - draw_trace(_file_opened, &svg); - svg.end(); + draw_trace(_file_opened, _DRAW_SVG); } ///////////////////////// - exit(EXIT_SUCCESS); + break; case _STATE_EXPORT_FILE_IN_INTERVAL: @@ -385,7 +325,7 @@ void Interface_console::launch_action(int state, void* arg){ ///// Do the export ///// ///////////////////////// - exit(EXIT_SUCCESS); + break; case _STATE_OPEN_FILE_IN_AN_INTERVAL: @@ -402,13 +342,13 @@ void Interface_console::launch_action(int state, void* arg){ else{ cout << "the end of the trace."; } - exit(EXIT_SUCCESS); + break; case _STATE_RELEASE_RENDER_AREA: if (_render_opengl->unbuild()==false) message << "Close file : an error occured with trace releasing." << Message::ende; - + _file_opened.clear(); _render_opengl->updateGL(); break; @@ -427,7 +367,7 @@ void Interface_console::launch_action(int state, void* arg){ default:/* like _STATE_UNKNOWN */ display_help(); warning(string("Cannot determine the arguments past. Please check the correct syntax.")); - exit(EXIT_SUCCESS); + } } @@ -477,6 +417,10 @@ const string Interface_console::get_filename() const{ return _file_opened; } +void Interface_console::set_path_to_export(const string& path){ + _path_to_export = path; +} + char const* const* Interface_console::get_runenv() const{ return _run_env; } diff --git a/src/interface/interface_console.hpp b/src/interface/interface_console.hpp index de44791554ed0e41806e83bf888c4f12faf01fbc..e5a60c0c9db11ac33ba16b42ecc2ca8a180b0bc0 100644 --- a/src/interface/interface_console.hpp +++ b/src/interface/interface_console.hpp @@ -8,8 +8,7 @@ class Interface_console; -#include <QtGui> -#include <QApplication> + #include "interface.hpp" #include "interface_graphic.hpp" #include "../render/render_opengl.hpp" @@ -95,6 +94,16 @@ public: *\brief A state which corresponds to release the OpenGL render area (display the wait screen). */ static const int _STATE_RENDER_AREA_CHANGE_CONTAINER_SCALE = 9; + + /*! + *\brief Informs that a trace has to be parsed and diplayed in the main window. + */ + static const int _DRAW_OPENGL = 10; + + /*! + *\brief Informs that a trace has to be exported in svg format. + */ + static const int _DRAW_SVG = 11; /*! *\brief A state which corresponds to display the ViTE window. @@ -154,12 +163,12 @@ protected: /*! *\brief If a file must be opened, this attributes contains its path. */ - char* _file_opened; + std::string _file_opened; /*! *\brief If a file must be exported, this attributes contains its path. */ - char* _path_to_export; + std::string _path_to_export; /*! *\brief The time where we start to watch the trace. @@ -233,22 +242,11 @@ protected: /*! * \brief This function launch trace drawing. * \param filename Path of the trace file. - * \param render_area Pointer to the render area. + * \param format Format of the render output between: Interface_console::_DRAW_OPENGL and Interface_console::_DRAW_SVG. * * \return true if no errors occurs. */ - bool draw_trace(const std::string & filename);//, Render_opengl* render_area); - - - /*! - * \brief This function launch SVG drawing. - * \param filename Path of the trace file. - * \param svg Pointer to the svg instance. - * - * \return true if no errors occurs. - */ - bool draw_trace(const std::string & filename, Svg* svg); - + bool draw_trace(const std::string & filename, const int format); /*! * \brief This function launch Qt event loop. @@ -262,6 +260,13 @@ protected: */ const std::string get_filename() const; + /*! + * \brief Set the name of the output file for SVG export. + * \param path Path of the output file. + * + */ + void set_path_to_export(const std::string& path); + /*! * \brief Get the _run_env matrix. * diff --git a/src/interface/interface_graphic.cpp b/src/interface/interface_graphic.cpp index cd5171fc857c41edf944628cb0dbb1fb58309600..5e77eecdce2df1056d24c8c72813dfde793bc1c3 100644 --- a/src/interface/interface_graphic.cpp +++ b/src/interface/interface_graphic.cpp @@ -211,7 +211,7 @@ void Interface_graphic::on_open_triggered(){ else{ opening_file(filename.toStdString()); - if(false==_core->draw_trace(filename.toStdString())) + if(false==_core->draw_trace(filename.toStdString(), Interface_console::_DRAW_OPENGL)) error("Draw trace failed"); }/* end else of if (_is_rendering_trace == true) */ @@ -230,17 +230,10 @@ void Interface_graphic::on_export_file_triggered(){ if (!filename.isEmpty()){ information(string("Exporting trace to ")+filename.toStdString()); - { - Svg svg; - - - - svg.init(filename.toStdString().c_str()); - _core->draw_trace(_trace_path, &svg); - - - } - + + _core->set_path_to_export(filename.toStdString()); + // _core->draw_trace(_trace_path, Interface_console::_DRAW_SVG); + _core->launch_action(Interface_console::_STATE_EXPORT_FILE); } else error("No file specified for exportation"); diff --git a/src/interface/interface_graphic.hpp b/src/interface/interface_graphic.hpp index 12c12e9e5bb48ca69d9e48a17c74537a5f193c99..2058ce17e4a09fda5a43da6fac8f2f0fe5b69227 100644 --- a/src/interface/interface_graphic.hpp +++ b/src/interface/interface_graphic.hpp @@ -9,9 +9,6 @@ class Interface_graphic; -#include <QtUiTools>/* for the run-time loading .ui file */ -#include <QGLWidget>/* for the OpenGL Widget */ - #include "../ui_main_window.h"/* the main window graphical interface */ #include "interface.hpp" diff --git a/src/interface/resource.hpp b/src/interface/resource.hpp index 6cb28cb6499ff0fd57324ad26d8c7d993eabfd0e..ef2e2c8baf0db70731635dcf0fbfe31c3dc901a5 100644 --- a/src/interface/resource.hpp +++ b/src/interface/resource.hpp @@ -5,19 +5,35 @@ -#ifndef RESOURCE_HPP -#define RESOURCE_HPP +#ifndef INTERFACE_RESOURCE_HPP +#define INTERFACE_RESOURCE_HPP #include "../main_resource.hpp" +/* + * + * WARNING : Take care that GL/glew.h MUST be included before others OpenGL includes (like GL/glut.h or QGLWidget). + * + */ + +#include <GL/glew.h>/* For OpenGL VBO and shaders */ +#include <GL/glut.h>/* For OpenGL text rendering */ + +#include <QtGui> +#include <QApplication> +#include <QtUiTools>/* for the run-time loading .ui file */ + +#include <QGLWidget>/* for the OpenGL Widget */ + #include <cmath> #include <stack> #include <list> -/* For OpenGL text rendering */ -#include <GL/glut.h> + + + @@ -66,9 +82,5 @@ exit(EXIT_FAILURE); \ } -/* Define the unity of time */ -typedef double Times; - - #endif diff --git a/src/main.cpp b/src/main.cpp index 3ae357f020864f2a8305c5f1a637950d90d24b6e..93531a3842df9c821be594bc9902c402d2527d19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,15 +8,19 @@ * \brief The main launcher. */ + +#include <QApplication> #include "interface/interface_console.hpp" /*! *\brief The main function of ViTE. */ + int main(int argc, char **argv) { + + Q_INIT_RESOURCE(vite); - glutInit(&argc, argv); - + Interface_console console(argc, argv); return console.run(); diff --git a/src/main_resource.hpp b/src/main_resource.hpp index 43d2554cefbb6f9a6f5d9a48d77479ff1f5e09f4..c47e59d6cc0ad15f847e5c716ed5c37b2bbc6722 100644 --- a/src/main_resource.hpp +++ b/src/main_resource.hpp @@ -13,6 +13,10 @@ #include <cstdlib> /* for macros EXIT_SUCCESS and EXIT_FAILURE */ + + + + /*! * \brief unity for count elements such as number of states or events... NOT USED YET */ @@ -26,6 +30,10 @@ typedef double Element_pos; */ typedef double Element_col; +/* Define the unity of time */ +typedef double Times; + + /* Message management */ diff --git a/src/message/Message.cpp b/src/message/Message.cpp index 67067d3138693a7536fe445b4b86ed6efd2cba72..a4dce0960624b814a7568ad0ede2e42faaedfc54 100644 --- a/src/message/Message.cpp +++ b/src/message/Message.cpp @@ -59,7 +59,7 @@ std::ostream &operator<<(std::ostream &out, Message::end_information_t) { Interface *interface = Message::get_interface(); if (interface) { - interface->warning(message->str()); + interface->information(message->str()); message->str(""); // flush the stream } else { std::cerr << "Warning: no interface designed to display messages." << std::endl; diff --git a/src/render/render_opengl.cpp b/src/render/render_opengl.cpp index 09c8326080fd7d8a5acd669fefdbe613371b76f4..db52a288d8210728be9dfae0eae393239c127daa 100644 --- a/src/render/render_opengl.cpp +++ b/src/render/render_opengl.cpp @@ -25,6 +25,18 @@ using namespace std; Render_opengl::Render_opengl(QWidget *parent) : QGLWidget(parent){ + GLenum glew_code; + + if (!QGLFormat::hasOpenGL()){ + QMessageBox::information(0, "ViTE: Fatal OpenGL error","This system does not support OpenGL."); + } + + + + + + + _state = DRAWING_STATE_WAINTING;/* At the beginning, no trace is drawing */ /* init the wait animation */ @@ -101,6 +113,19 @@ Render_opengl::Render_opengl(QWidget *parent) setMouseTracking (true);/* to catch mouse events */ updateGL(); + + + glew_code = glewInit();/* use for VBO and shaders */ + + if(GLEW_OK != glew_code){ + message << "Cannot initialize GLEW: " << glewGetErrorString(glew_code) << Message::ende; + } + + /*Check if VBO is supported */ + if (GL_FALSE == glewIsSupported("GL_ARB_vertex_buffer_object")){ + message << "VBO OpenGL extension is not supported by your graphic card." << Message::ende; + } + } @@ -136,6 +161,8 @@ void Render_opengl::initializeGL(){ glClearStencil(0); _wait_list = draw_wait(); + + } void Render_opengl::resizeGL(int width, int height){ @@ -297,7 +324,7 @@ void Render_opengl::paintGL(){ const char letter = buf_txt.c_str()[i]; length += glutBitmapWidth(GLUT_BITMAP_HELVETICA_10, letter); if(length > size_of_container){ - cout << "break" << endl; + break; } glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, letter); @@ -311,7 +338,7 @@ void Render_opengl::paintGL(){ glTranslated( _default_entity_x_translate - _state_translate , 0.0f, _z_state); - glScalef(_state_scale*(_render_width/_state_x_max), (_render_height-_rule_height)/_state_y_max, 0.0f); + glScalef(_state_scale*(_render_width/_state_x_max), (_render_height-_rule_height)/_container_y_max, 0.0f); @@ -746,6 +773,144 @@ void Render_opengl::create_rule(){ } */ } + +// void Render_opengl::create_rule(){ + +// ostringstream buf_txt; +// Element_pos rule_width; + +// Element_pos entity_width; +// Element_pos graduation_distance; +// Element_pos x_min; +// Element_pos start_delay; +// Element_pos coeff; +// Element_pos buf_number; +// Element_pos graduation_distance_per_5; + +// int units; +// int ten_units; +// Element_pos buf_g_d; + +// units = 0;//3; +// ten_units = 1;//1000; + +// coeff = (_state_x_max - _state_x_min)/_render_width;/* from [0;100] to [_state_x_min;_state_x_max], used to obtain correct coordinate texts */ + +// entity_width = _render_width*_state_scale;/* the render width from a given scale */ + +// graduation_distance = entity_width/ceil(entity_width/_rule_distance);/* distance between two graduations calculated from a desire distance */ + +// x_min = _default_entity_x_translate-_state_translate;/* received the first integer inside render width */ + +// start_delay = x_min - graduation_distance*floor(x_min/graduation_distance);/* delaying rule start at 0.0 x coordinate to fit with graduation distance */ + +// graduation_distance_per_5 = graduation_distance/5.0; + + +// rule_width = (_render_width*_state_scale+x_min)/_rule_distance; + + +// /* Calculate the rule unit (cm, mm, um, nm, ...) */ +// buf_g_d = _state_x_max/((double)_state_scale); + +// /* cerr << buf_g_d << endl; +// while( (buf_g_d > 0.0) && (buf_g_d <= 1.0) ){ +// buf_g_d *= 10.0; +// units ++; +// ten_units *= 10; +// }*/ + +// /* Draw the rule top line */ +// glColor3d(1.0, 1.0, 1.0); +// glBegin(GL_LINES); +// { +// glVertex3d(max(x_min, 0.0), _rule_y, _z_rule); +// glVertex3d(entity_width+x_min, _rule_y, _z_rule); +// } +// glEnd(); + + + +// if ( (x_min<0.0) && ((entity_width+x_min)>graduation_distance)){/* we are not viewing the beginning of the trace (i.e. the 0.0 coordinate) but we still viewing the trace (not after the end) */ + +// /* draw previous small graduations */ +// for (char k=1 ; k<5 ; k++){ +// glBegin(GL_LINES); +// { +// glColor3d(1.0, 1.0, 1.0);glVertex3d(start_delay-k*graduation_distance_per_5, _rule_y, _z_rule); +// glColor3d(1.0, 0.6, 0.6);glVertex3d(start_delay-k*graduation_distance_per_5, _rule_y+_rule_height/3.0, _z_rule); +// } +// glEnd(); +// } +// } + + +// /* Draw spaced graduation of _rule_distance */ +// for (Element_pos i=max(x_min, start_delay) ; i<=min(entity_width+x_min, _render_width) ; i+=graduation_distance){ + + +// if (i != min(entity_width+x_min, _render_width) ){/* prepare small graduations between the current and the next main graduation */ + +// /* draw small graduations */ +// for (char k=1 ; k<5 ; k++){ +// glBegin(GL_LINES); +// { +// glColor3d(1.0, 1.0, 1.0);glVertex3d(i+k*graduation_distance_per_5, _rule_y, _z_rule); +// glColor3d(1.0, 0.6, 0.6);glVertex3d(i+k*graduation_distance_per_5, _rule_y+_rule_height/3.0, _z_rule); +// } +// glEnd(); +// } +// } + + +// /* Draw the main graduation line */ +// glBegin(GL_LINES); +// { +// glColor3d(1.0, 1.0, 1.0);glVertex3d(i, _rule_y, _z_rule); +// glColor3d(1.0, 0.6, 0.6);glVertex3d(i, _rule_y+_rule_height, _z_rule); +// } +// glEnd(); + +// /* Draw the graduation text */ +// glColor3d(1.0, 1.0, 1.0); +// glRasterPos2f(i, _rule_y+_rule_height); + + +// buf_number = (i - x_min)*coeff/_state_scale; + + +// /* trunc numbers */ +// buf_number = floor(buf_number*ten_units); + + +// buf_txt << buf_number; + +// for(unsigned int j=0;j<buf_txt.str().length();j++){ +// glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]); +// } + +// buf_txt.str("");/* flush the buffer */ +// } + +// /* Draw the ended graduation line */ +// glBegin(GL_LINES); +// { +// glColor3d(1.0, 1.0, 1.0);glVertex3d(rule_width*_rule_distance, _rule_y, _z_rule); +// glColor3d(1.0, 0.6, 0.6);glVertex3d(rule_width*_rule_distance, _rule_y+_rule_height, _z_rule); +// } +// glEnd(); + +// /* Indicate the unit */ +// glColor3d(1.0, 1.0, 1.0); +// glRasterPos2f(0, _rule_y+_rule_height); + +// buf_txt << "10^-" << units; + +// for(unsigned int j=0;j<buf_txt.str().length();j++){ +// glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, buf_txt.str().c_str()[j]); +// } + +// } void Render_opengl::set_total_width(Element_pos w){} diff --git a/src/render/render_opengl.hpp b/src/render/render_opengl.hpp index 5325f536e9b3b726dd725a87c58f5cbb93267f33..ad8d1085ced38b09ab32bafd8aded8008d8db329 100644 --- a/src/render/render_opengl.hpp +++ b/src/render/render_opengl.hpp @@ -6,17 +6,19 @@ #define RENDER_OPENGL_HPP -class Render_opengl; -#include <QtGui> -#include <QGLWidget>/* for the OpenGL Widget */ + + +class Render_opengl; #include "render.hpp" #include "resource.hpp" + + /*! * \brief Structure used to store event information. */ @@ -40,19 +42,19 @@ struct Event_{ */ struct Arrow_{ /*! - * \brief time when the arrow starts + * \brief time when the arrow starts. */ Element_pos start_time; /*! - * \brief time when the arrow ends + * \brief time when the arrow ends. */ Element_pos end_time; /*! - * \brief ? + * \brief The start height of the arrow. */ Element_pos start_height; /*! - * \brief ? + * \brief The end height of the arrow. */ Element_pos end_height; }; diff --git a/src/render/resource.hpp b/src/render/resource.hpp index 2530620e3b70968550dbc6f467a99774cc8b8df8..7367b91e5d8e98ab1575306d58b383ac4ae6e4e4 100644 --- a/src/render/resource.hpp +++ b/src/render/resource.hpp @@ -5,55 +5,13 @@ -#ifndef RESOURCE_HPP -#define RESOURCE_HPP +#ifndef RENDER_RESOURCE_HPP +#define RENDER_RESOURCE_HPP -#include "../main_resource.hpp" - - -#include <cmath> -#include <stack> -#include <list> - -/* For OpenGL text rendering */ -#include <GL/glut.h> - -/*! - * \brief PI with a precision of 8. - */ -#define PI 3.14159265 -/* Now, two checkers are defined (the first for integer return value, the other - for pointer return value). Their body can be empty to enhance program speed. - To pass multi arguments for m, use "<<" between each arguments. -*/ - -/*! - * \brief Checks if a function return -1 as a value. - * - * This macro is used with C functions to check them if an error occurs. Thus, it display the file, the line and some informations (with m variable) of the error than exit the program. - */ -#define CKF(f, m) if((f)==-1) { \ - cerr << "File " << __FILE__ <<" - line : " << __LINE__ <<endl; \ - cerr << m <<endl; \ - exit(EXIT_FAILURE); \ - } - -/*! - * \brief Checks if a function return NULL as a value. - * - * This macro is used with C functions to check them if an error occurs. Thus, it display the file, the line and some informations (with m variable) of the error than exit the program. - */ -#define CKFP(f, m) if((f)==NULL) { \ - cerr << "File " << __FILE__ <<" - line : " << __LINE__ <<endl; \ - cerr << m <<endl; \ - exit(EXIT_FAILURE); \ - } - -/* Define the unity of time */ -typedef double Times; +#include "../main_resource.hpp" diff --git a/src/render/vbo.cpp b/src/render/vbo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b606641a6f24405b40a7afe3b624768ba884f93 --- /dev/null +++ b/src/render/vbo.cpp @@ -0,0 +1,54 @@ +/*! + *\file vbo.cpp + */ + + +#include "vbo.hpp" + + + + +using namespace std; +#define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): " + + + + + +/*********************************** + * + * + * + * Constructor and destructor. + * + * + * + **********************************/ + +Vbo::Vbo(){ + + + /* init class attributes */ + + _cur = 0; + + + /* init OpenGL */ + + // glGenBuffers(1, &_id);/* create the buffer an put its value to _id */ + +// glBindBuffer(GL_ARRAY_BUFFER, _id);/* select our vbo */ + +// glBufferData(GL_ARRAY_BUFFER, _size, NULL, GL_STATIC_DRAW);/* allocate memory space inside graphic card */ + +// glBindBuffer(GL_ARRAY_BUFFER, 0);/* deselect our vbo */ + +} + + +Vbo::~Vbo(){ + //glDeleteBuffers(1, &_id);/* release the buffer and free its memory inside graphic card */ +} + + + diff --git a/src/render/vbo.hpp b/src/render/vbo.hpp new file mode 100644 index 0000000000000000000000000000000000000000..26c491b9502cd32d7f7b9ff5f591f7777b128667 --- /dev/null +++ b/src/render/vbo.hpp @@ -0,0 +1,114 @@ +/*! + *\file vbo.hpp + */ + +#ifndef VBO_HPP +#define VBO_HPP + + + +class Vbo; + + + +#include "resource.hpp" + + +/*! + * \brief Manage the Vertex Buffer Object. + */ +class Vbo{ + +protected: + + /*! + * \brief The vbo instance identity. + */ + GLuint _id; + + /*! + * \brief The size of the vbo buffer. (10 000 verteces) + */ + static const int _size = 100; + + /*! + * \brief Define the position indicator inside the VBO buffer. Must be lesser than _size ! + */ + int _cur; + +public: + + /*********************************** + * + * Constructor and destructor. + * + **********************************/ + + /*! + * \brief The default constructor. + */ + Vbo(); + + /*! + * \brief The destructor. + */ + virtual ~Vbo(); + + + + /*********************************** + * + * Buffer filling. + * + **********************************/ + + /*! + * \brief Used to inform that data have been successfully added to graphic card. + */ + static const int VBO_OK = 0; + + /*! + * \brief Used to inform that the buffer is full and another VBO must be create. + */ + static const int VBO_OUT_OF_MEMORY = 1; + + /*! + * \brief Used to inform that an unidentified error occurs. + */ + static const int VBO_UNDEFINED_ERROR = 2; + + /*! + * \brief Fill the vertex buffer object. + * \return The state of the buffer. + * + * This function is called for each vertex, so it is an inline function. It can return several number : + * <ul> + * <li><b>VBO_OK</b>: data have been added to graphic card. No error. + * <li><b>VBO_OUT_OF_MEMORY</b>: buffer is full. Another VBO must be create. + * <li><b>VBO_UNDEFINED_ERROR</b>: an error occurs but has not been identified. + * </ul> + */ + virtual int fill_buffer() = 0; + + + + /*********************************** + * + * Buffer display. + * + **********************************/ + + /*! + * \brief Display the VBO list inside the OpenGL area. + */ + virtual void display_buffer() = 0; + +}; + + + + + + + + #endif diff --git a/src/src.pro b/src/src.pro index 8246459f9efbe662a178e8bc19a355176c3a2fa7..2c95d194eee36a31d76e072f954b3537836e86ed 100644 --- a/src/src.pro +++ b/src/src.pro @@ -7,7 +7,7 @@ OBJECTS_DIR=../bin DESTDIR=../bin CONFIG+=uitools debug QT+=opengl -LIBS += -lglut +LIBS += -lglut -lGLEW TEMPLATE = app TARGET = vite DEPENDPATH += . interface message parser trace trace/values @@ -17,13 +17,18 @@ INCLUDEPATH += . interface message trace trace/values parser HEADERS += message/Message.hpp \ message/Errors.hpp \ main_resource.hpp \ +# Interface headers interface/interface.hpp \ interface/interface_console.hpp \ interface/interface_graphic.hpp \ + interface/resource.hpp \ +# Render headers render/render.hpp \ render/render_opengl.hpp \ render/render_svg.hpp \ - interface/resource.hpp \ + render/vbo.hpp \ + render/vbo_container.hpp \ +# Parser headers parser/Definition.hpp \ parser/Line.hpp \ parser/Parser.hpp \ @@ -31,6 +36,7 @@ HEADERS += message/Message.hpp \ parser/ParserEventDecoder.hpp \ parser/ParserPaje.hpp \ parser/TokenSource.hpp \ +# Data structure headers trace/Container.hpp \ trace/ContainerType.hpp \ trace/DrawTrace.hpp \ @@ -58,18 +64,24 @@ HEADERS += message/Message.hpp \ trace/values/Values.hpp FORMS += interface/info_window.ui interface/main_window.ui interface/maquette.ui SOURCES += message/Message.cpp \ + message/Errors.cpp \ main.cpp \ +# Interface code files interface/interface_console.cpp \ interface/interface_graphic.cpp \ +# Render code files render/render_opengl.cpp \ render/render_svg.cpp \ + render/vbo.cpp \ + render/vbo_container.cpp \ +# Parser code files parser/Definition.cpp \ - message/Errors.cpp \ parser/Line.cpp \ parser/ParserDefinitionDecoder.cpp \ parser/ParserEventDecoder.cpp \ parser/ParserPaje.cpp \ parser/TokenSource.cpp \ +# Data structure code files trace/Container.cpp \ trace/ContainerType.cpp \ trace/Entity.cpp \ diff --git a/src/trace/DrawTrace.hpp b/src/trace/DrawTrace.hpp index d0b3d88af2e6ae4e43d3c1d72776280e2049cc95..6e4cdc7a7b5c48f43324e3506df75165ad89fd50 100644 --- a/src/trace/DrawTrace.hpp +++ b/src/trace/DrawTrace.hpp @@ -245,7 +245,8 @@ public: field = state->get_value()->get_extra_fields()->find(std::string("Color")); // Search the color // Mind the map, may be the source of a bug - if (!state->get_value()->get_extra_fields()->empty() && + if ( + !state->get_value()->get_extra_fields()->empty() && state->get_value() && (field != extra_fields->end())) { /* Call the object state drawing function with the state color */ diff --git a/tests/message/Makefile b/tests/message/Makefile index 33ba7d6d1814632d8cb08d82fb7673ea2327e669..499fa331db5ebbe9bccb2300a56c29dcacf578e0 100644 --- a/tests/message/Makefile +++ b/tests/message/Makefile @@ -1,7 +1,7 @@ CXX=g++ CXXFLAGS = -Wall -g -BIN_DIR = ../bin/ -SRC_DIR = ../src/ +BIN_DIR = ../../bin/ +SRC_DIR = ../../src/message/ OBJECT_FILE_BIN = $(BIN_DIR)enderror.o $(BIN_DIR)endwarning.o $(BIN_DIR)endinformation.o $(BIN_DIR)message.o $(BIN_DIR)message_ns.o OBJECT_FILE = enderror.o endwarning.o endinformation.o message.o message_ns.o TEST_FLAGS = -DTEST_MESSAGE