Commit 85d5dd82 authored by Olivier Lagrasse's avatar Olivier Lagrasse

-Deplacement de certaines fonctions de l'interface graphique vers

l'interface console.
-L'interface graphique ne manipule plus de render area mais des 
QGLWidget.
-Ajout du menu "no warning" pour desactiver l'affichage des warnings et 
des erreurs qui peuvent faire bugger s'ils sont envoyes en trop grand 
nombre.
- Changement du menu "About".

Ameliorations cosmetiques :
-la barre de position est alignee avec la barre de redimensionnement 
containers/états.
- Zoom et translation faisable avec la souris. (cliquer et deplacer 
horizontalement pour la translation, verticale pour le zoom)
parent faf2cf8b
......@@ -6,8 +6,11 @@
#include "interface_console.hpp"
using namespace std;
#define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): "
/***********************************
*
*
......@@ -52,6 +55,7 @@ Interface_console::Interface_console(int argc, char ** argv){
}
_main_window = NULL;
_render_opengl = NULL;
// Init of the times
_time_start = 0;
......@@ -69,7 +73,7 @@ Interface_console::Interface_console(int argc, char ** argv){
Interface_console::~Interface_console(){
/* Qt desallocates _main_window automatically */
/* Qt desallocates _main_window and _render_opengl automatically */
free(_run_env[0]);
......@@ -88,13 +92,19 @@ Interface_console::~Interface_console(){
**********************************/
bool Interface_console::draw_trace(const string & filename, Render_area* render_area){
bool Interface_console::draw_trace(const string & filename){//, Render_area* render_area){
if (_render_opengl==NULL){
message << "Error, no render area bound to the main window" << Message::ende;
return false;
}
Trace trace;
ParserPaje parser;
DrawTrace<Render_area> drawing;
QApplication::setOverrideCursor(Qt::WaitCursor);
try{
parser.parse(filename, trace);
}
catch (const string &error){
......@@ -102,7 +112,15 @@ bool Interface_console::draw_trace(const string & filename, Render_area* render_
*Message::get_instance() << "Reason : " << error << Message::ende;
return false;
}
drawing.build(render_area, &trace);
drawing.build(_render_opengl, &trace);
_render_opengl->build();
_render_opengl->updateGL();
QApplication::restoreOverrideCursor();
return true;
}
......@@ -115,7 +133,7 @@ bool Interface_console::draw_trace(const string & filename, Svg* svg){
ParserPaje parser;
DrawTrace<Svg> drawing;
QApplication::setOverrideCursor(Qt::WaitCursor);
try{
parser.parse(filename, trace);
}
......@@ -127,6 +145,8 @@ bool Interface_console::draw_trace(const string & filename, Svg* svg){
drawing.build(svg, &trace);
QApplication::restoreOverrideCursor();
return true;
}
......@@ -244,7 +264,7 @@ void Interface_console::extract_times(const char *name){
}
}
void Interface_console::launch_action(int state){
void Interface_console::launch_action(int state, void* arg){
switch(state) {
......@@ -258,13 +278,23 @@ void Interface_console::launch_action(int state){
_main_window = new Interface_graphic(this);/* launch the window interface */
Message::set_interface(_main_window);/* define which interface will receive messages */
break;
_render_opengl = new Render_area(_main_window);
_main_window->bind_render_area((QGLWidget*)_render_opengl);
break;
case _STATE_OPEN_FILE:
information(string("Opening the file: ")+string(_file_opened));
_main_window = new Interface_graphic(this, _file_opened);/* launch the window interface and open a file */
_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_area(_main_window);
_main_window->bind_render_area((QGLWidget*)_render_opengl);
_main_window->opening_file(_file_opened);/* Must be called after binding the render area to the main window */
if(false==draw_trace(_file_opened))
message << "Draw trace failed" << Message::ende;
break;
......@@ -318,6 +348,25 @@ void Interface_console::launch_action(int state){
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;
_render_opengl->updateGL();
break;
case _STATE_RENDER_AREA_CHANGE_TRANSLATE:
_render_opengl->change_translate( *((int*)arg) );
break;
case _STATE_RENDER_AREA_CHANGE_SCALE:
_render_opengl->change_scale( *((int*)arg) );
break;
case _STATE_RENDER_AREA_CHANGE_CONTAINER_SCALE:
_render_opengl->change_scale_container_state( *((int*)arg) );
break;
default:/* like _STATE_UNKNOWN */
display_help();
warning(string("Cannot determine the arguments past. Please check the correct syntax."));
......
......@@ -8,6 +8,7 @@
class Interface_console;
#include <QtGui>
#include <QApplication>
#include "interface.hpp"
#include "interface_graphic.hpp"
......@@ -22,6 +23,8 @@ class Interface_console;
#include "resource.hpp"
#include <pthread.h>
/*!
*\brief This class is an terminal interface, it inherited from the Interface interface.
......@@ -30,31 +33,7 @@ class Interface_console : public Interface{
protected:
/***********************************
*
* Window interface instance.
*
**********************************/
/*!
* \brief Contains the instance of the window class.
*/
Interface_graphic* _main_window;
/*!
* \brief Contains the render area instance.
*/
Render_area* _render_opengl;
/*!
* \brief Contains the main Qt application instance.
*/
QApplication* app;
public:
/***********************************
*
......@@ -97,12 +76,71 @@ protected:
*/
static const int _STATE_EXPORT_FILE_IN_INTERVAL = 5;
/*!
*\brief A state which corresponds to release the OpenGL render area (display the wait screen).
*/
static const int _STATE_RELEASE_RENDER_AREA = 6;
/*!
*\brief A state which corresponds to release the OpenGL render area (display the wait screen).
*/
static const int _STATE_RENDER_AREA_CHANGE_TRANSLATE = 7;
/*!
*\brief A state which corresponds to release the OpenGL render area (display the wait screen).
*/
static const int _STATE_RENDER_AREA_CHANGE_SCALE = 8;
/*!
*\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 The size max (hoped) for the current directory name.
* Used for opening a new window with a new trace.
*/
static const int _CURRENT_DIR_SIZE = 256;
/*!
* \brief Launch an action according to the argument state value.
* \arg state : an integer corresponding to a kind of action which must be executed.
*
* This functions triggers an action of ViTE according to its argument. state can takes some values :
* <ul><li><b>STATE_DISPLAY_HELP</b> -> this value means that the console interface must be displayed
* in the terminal the help text, then wait until user specify an other command.</li>
* <li><b>STATE_LAUNCH_GRAPHICAL_INTERFACE</b> -> this value means that the console interface will let
* user to use the graphical interface: in that case, ViTE displays the window and all
* of the warning or error messages will be displayed in dialog boxes.</li>
* </ul>
*/
void launch_action(int state, void* arg = NULL);
protected:
/***********************************
*
* Window interface instance.
*
**********************************/
/*!
* \brief Contains the instance of the window class.
*/
Interface_graphic* _main_window;
/*!
* \brief Contains the OpenGL render area instance.
*/
Render_area* _render_opengl;
/*!
* \brief Contains the main Qt application instance.
*/
QApplication* app;
/*!
*\brief This attributes contains the launching current directory (_run_env[0]) and the first argument of the running command (_run_env[1]).
*/
......@@ -128,6 +166,11 @@ protected:
*/
int _time_end;
/*!
*\brief The parser thread.
*/
// pthread_t _thread_parser;
/*!
* \brief Return the state of ViTE according to the arguments.
......@@ -145,20 +188,6 @@ protected:
void extract_times(const char *name);
/*!
* \brief Launch an action according to the argument state value.
* \arg state : an integer corresponding to a kind of action which must be executed.
*
* This functions triggers an action of ViTE according to its argument. state can takes some values :
* <ul><li><b>STATE_DISPLAY_HELP</b> -> this value means that the console interface must be displayed
* in the terminal the help text, then wait until user specify an other command.</li>
* <li><b>STATE_LAUNCH_GRAPHICAL_INTERFACE</b> -> this value means that the console interface will let
* user to use the graphical interface: in that case, ViTE displays the window and all
* of the warning or error messages will be displayed in dialog boxes.</li>
* </ul>
*/
void launch_action(int state);
/*!
* \brief Displays in the terminal the help text.
......@@ -186,7 +215,7 @@ protected:
/*!
* \brief The destructor.
*/
~Interface_console();
virtual ~Interface_console();
......@@ -203,7 +232,7 @@ protected:
*
* \return true if no errors occurs.
*/
bool draw_trace(const std::string & filename, Render_area* render_area);
bool draw_trace(const std::string & filename);//, Render_area* render_area);
/*!
......
......@@ -26,24 +26,12 @@ Interface_graphic::Interface_graphic(Interface_console* core, QWidget *parent):Q
_core = core;
_is_rendering_trace = false;
_no_warning = false;/* display warnings */
load_windows();
}
Interface_graphic::Interface_graphic(Interface_console* core, const string file_path, QWidget *parent):QMainWindow(parent){
setupUi(this);
_core = core;
_is_rendering_trace = false;
load_windows();
opening_file(file_path);
}
Interface_graphic::~Interface_graphic(){
......@@ -88,10 +76,7 @@ void Interface_graphic::load_windows(){
CKFP(_ui_toolbar_check = qFindChild<QAction*>(this, "toolbar_menu"), "Cannot find the tool bar checker in the .ui file");
CKFP(_ui_toolbar = qFindChild<QToolBar*>(this, "toolBar"), "Cannot find the tool bar in the .ui file");
/* Create the render area and bind it to a layout (_ui_render_area_layout) */
_ui_render_area = new Render_area(this);
_ui_render_area_layout->addWidget(_ui_render_area);
/*
Special function of Qt which allows methods declared as slots and which name are 'on_[widget]_[action]()' to be called when the 'widget' triggered the signal corresponding to 'action'.
......@@ -116,8 +101,10 @@ void Interface_graphic::load_windows(){
**********************************/
void Interface_graphic::error(const string s) const{
if ( true==_no_warning ) return;/* do not display error messages */
QString buf = s.c_str();
_ui_info_trace_text->moveCursor(QTextCursor::End);/* Insert the new text on the beginning */
_ui_info_trace_text->moveCursor(QTextCursor::End);/* Insert the new text on the end */
_ui_info_trace_text->insertHtml("<font color='red'>"+buf+"</font><br /><br />");
_ui_info_window->show();/* show info_window */
......@@ -125,8 +112,10 @@ void Interface_graphic::error(const string s) const{
void Interface_graphic::warning(const string s) const{
if ( true==_no_warning ) return;/* do not display warning messages */
QString buf = s.c_str();
_ui_info_trace_text->moveCursor(QTextCursor::End);/* Insert the new text on the beginning */
_ui_info_trace_text->moveCursor(QTextCursor::End);/* Insert the new text on the end */
_ui_info_trace_text->insertHtml("<font color='orange'>"+buf+"</font><br /><br />");
_ui_info_window->show();/* show info_window */
......@@ -135,7 +124,7 @@ void Interface_graphic::warning(const string s) const{
void Interface_graphic::information(const string s) const{
QString buf = s.c_str();
_ui_info_trace_text->moveCursor(QTextCursor::End);/* Insert the new text on the beginning */
_ui_info_trace_text->moveCursor(QTextCursor::End);/* Insert the new text on the end */
_ui_info_trace_text->insertHtml("<font color='green'>"+buf+"</font><br /><br />");
}
......@@ -161,19 +150,27 @@ void Interface_graphic::opening_file(const string &path){
QApplication::setOverrideCursor(Qt::WaitCursor);
_core->draw_trace(path, _ui_render_area);
/* if (_core->draw_trace(path)==false){
error("Draw trace failed");
}*/
_ui_render_area->build();
// _ui_render_area->build();
_is_rendering_trace = true;
_ui_render_area->updateGL();
// _ui_render_area->updateGL();
QApplication::restoreOverrideCursor();
}
void Interface_graphic::bind_render_area(QGLWidget* render_area){
/* Bind the render area to a layout (_ui_render_area_layout) */
_ui_render_area = render_area;
_ui_render_area_layout->addWidget(_ui_render_area);
}
/***********************************
*
*
......@@ -196,7 +193,7 @@ void Interface_graphic::on_open_triggered(){
if (!filename.isEmpty()){
if (_is_rendering_trace == true){/* Realease the previous trace */
QStringList arguments = (QStringList() << filename);
QString program;
char const* const* run_env = _core->get_runenv();
......@@ -213,9 +210,12 @@ void Interface_graphic::on_open_triggered(){
}
else{
opening_file(filename.toStdString());
if(false==_core->draw_trace(filename.toStdString()))
error("Draw trace failed");
}/* end else of if (_is_rendering_trace == true) */
}
}
}/* end if (!filename.isEmpty()) */
}
......@@ -233,12 +233,12 @@ void Interface_graphic::on_export_file_triggered(){
{
Svg svg;
QApplication::setOverrideCursor(Qt::WaitCursor);
svg.init(filename.toStdString().c_str());
_core->draw_trace(_trace_path, &svg);
QApplication::restoreOverrideCursor();
}
}
......@@ -253,14 +253,15 @@ void Interface_graphic::on_close_triggered(){
if(_is_rendering_trace == false)
return;
if (_ui_render_area->unbuild()==false)
error("Close file : an error occured with trace releasing.");
_core->launch_action(Interface_console::_STATE_RELEASE_RENDER_AREA);
_is_rendering_trace = false;
information(string("File closed."));
_ui_render_area->update();
this->setWindowTitle(QString("ViTE"));
......@@ -268,7 +269,7 @@ void Interface_graphic::on_close_triggered(){
void Interface_graphic::on_quit_triggered(){
((QWidget*)this)->close();
}
......@@ -327,14 +328,20 @@ void Interface_graphic::on_about_triggered(){
"It is licensed under <i>CECILL-A</i>."));*/
QMessageBox::about(this, tr("About ViTE"),
tr("<b>ViTE</b> version 0.3"
"ViTE is under the CeCILL A licence. The content can be found <a href=\"http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt\">here</a>."
"<p><b>Developers :</b><ul><li>Kevin COULOMB</li><li>Johnny JAZEIX</li><li>Olivier LAGRASSE</li><li>Jule MARCOUEILLE</li><li>Pascal NOISETTE</li><li>Arthur REDONDY</li><li>Cl&eacute;ment VUCHENER</li></ul></p>"
"This software was made for a school engineering project for INRIA searchers."
"The page project is : <a href=\"https://gforge.inria.fr/projects/vite/\">https://gforge.inria.fr/projects/vite/</a>."
"<h6>ViTE is for : ViTE isn't True English (not yet approved by the developpers and INRIA ^^)</h6>"));
tr("<h2>ViTE</h2>"
"the <b>Vi</b><i>sual </i><b>T</b><i>race</i> <b>E</b><i>xplorer</i> - <i>version 0.3</i> - <i>March 2009</i>.<br /><br />"
"Under the CeCILL A licence. The content can be found <a href=\"http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt\">here</a>."
"<p><b>Developers:</b><ul><li>Kevin COULOMB</li><li>Johnny JAZEIX</li><li>Olivier LAGRASSE</li><li>Jule MARCOUEILLE</li><li>Pascal NOISETTE</li><li>Arthur REDONDY</li><li>Cl&eacute;ment VUCHENER</li></ul></p>"
"This software was made for a school engineering project for INRIA researchers.<br />"
"The main page project is: <a href=\"https://gforge.inria.fr/projects/vite/\">https://gforge.inria.fr/projects/vite/</a>.<br /><br />"));
}
void Interface_graphic::on_no_warning_triggered(){
_no_warning = !_no_warning;
}
void Interface_graphic::on_zoom_in_triggered(){
cout << "zoom in" << endl;
}
......@@ -356,28 +363,22 @@ void Interface_graphic::on_show_all_trace_triggered(){
}
void Interface_graphic::on_scale_state_valueChanged(int new_value){
_ui_render_area->change_scale(new_value);
_core->launch_action(Interface_console::_STATE_RENDER_AREA_CHANGE_SCALE, &new_value);
}
void Interface_graphic::on_translate_state_valueChanged(int new_value){
_ui_render_area->change_translate(new_value);
_core->launch_action(Interface_console::_STATE_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);
_core->launch_action(Interface_console::_STATE_RENDER_AREA_CHANGE_CONTAINER_SCALE, &new_value);
}
void Interface_graphic::closeEvent(QCloseEvent *event){
event->accept();/* accept to hide the window for a further destruction */
}
......
......@@ -9,14 +9,13 @@
class Interface_graphic;
#include <QtGui>
#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"
#include "interface_console.hpp"
#include "render_area.hpp"
#include "resource.hpp"
......@@ -56,7 +55,7 @@ class Interface_graphic : public QMainWindow, protected Ui::main_window, public
/*!
* \brief This variable contains the main window of the application.
*/
// QWidget* _ui_main_window;
//QWidget* _ui_main_window;
/*!
* \brief This variable contains the action to switch in fullscreen mode.
......@@ -76,7 +75,7 @@ class Interface_graphic : public QMainWindow, protected Ui::main_window, public
/*!
* \brief This variable contains the OpenGL render area.
*/
Render_area* _ui_render_area;
QGLWidget* _ui_render_area;
/*!
* \brief Layout which will contain the render area.
......@@ -123,6 +122,12 @@ class Interface_graphic : public QMainWindow, protected Ui::main_window, public
bool _is_rendering_trace;
/*!
* \brief Prevent warnings to be displayed (used with malformed traces to prevent Qt spending too much time).
*/
bool _no_warning;
public:
......@@ -139,13 +144,6 @@ public:
*/
Interface_graphic(Interface_console* core, QWidget *parent = 0);
/*!
* \brief The constructor which open a file
* \arg file_path: the file which be parsed then displayed.
* \arg parent: the parent widget of the graphical interface. Should be ignored.
*/
Interface_graphic(Interface_console* core, std::string file_path, QWidget *parent = 0);
/*!
* \brief The destructor
......@@ -203,6 +201,12 @@ public:
*/
void opening_file(const std::string &path);
/*!
* \brief Bind a render area to the main window.
* \param render_area A pointer to a QGLWidget.
*/
void bind_render_area(QGLWidget* render_area);
protected slots:
......@@ -259,6 +263,11 @@ protected slots:
*/
void on_about_triggered();
/*!
*\brief A slot which called when 'no_warning' in the menu is clicked.
*/
void on_no_warning_triggered();
/*!
*\brief A slot which called when 'zoom_in' in the menu is clicked.
*/
......
......@@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1170</width>
<height>683</height>
<width>1060</width>
<height>702</height>
</rect>
</property>
<property name="sizePolicy" >
......@@ -26,14 +26,6 @@
<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>64</y>
<width>1170</width>
<height>619</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" >
<item>
<layout class="QVBoxLayout" name="render_area_layout" />
......@@ -64,22 +56,12 @@
</widget>
</item>
<item>
<spacer name="horizontalSpacer" >
<widget class="Line" name="line" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
......@@ -154,7 +136,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1170</width>
<width>1060</width>
<height>26</height>
</rect>
</property>
......@@ -180,6 +162,8 @@
<addaction name="goto_end" />
<addaction name="separator" />
<addaction name="fullscreen" />
<addaction name="separator" />
<addaction name="no_warning" />
</widget>
<widget class="QMenu" name="menuFile" >
<property name="title" >
......@@ -197,14 +181,6 @@
<addaction name="menuHelp" />
</widget>
<widget class="QToolBar" name="toolBar" >
<property name="geometry" >
<rect>
<x>0</x>
<y>26</y>
<width>1170</width>
<height>38</height>
</rect>
</property>
<property name="windowTitle" >
<string>toolBar</string>
</property>
......@@ -405,6 +381,14 @@
<string>Ctrl+Shift+A</string>
</property>
</action>
<action name="no_warning" >
<property name="checkable" >
<bool>true</bool>
<