Commit a13157a3 authored by Olivier Lagrasse's avatar Olivier Lagrasse
Browse files

reorganisation dans l'ordre croissant des conteneurs + correction bug encodage...

reorganisation dans l'ordre croissant des conteneurs + correction bug encodage + correction bug reecriture du texte des conteneurs + remplacement des barres temporaires de deplacement et de zoom + affichage nom fichier dans barre titre + reorganisation code : en cours de separation du dessin de la trace avec l'algorithme de parcours
parent bb356348
......@@ -22,11 +22,24 @@ using namespace std;
Interface_console::Interface_console(int argc, char ** argv){
int state;
bool useGUI;/* if window interface can be displayed */
useGUI = true;
app = new QApplication(argc, argv, useGUI);/* create the Qt application */
/* Qt uses the default system encoding for QString (used when opening a file) */
QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
if (!useGUI){
cerr << "Error: Graphical window cannot be displayed." << endl;
exit(EXIT_FAILURE);
}
_main_window=NULL;
state = get_state(argc, argv);
launch_action(state);
}
......@@ -40,6 +53,24 @@ Interface_console::~Interface_console(){
/***********************************
*
*
*
* Running function.
*
*
*
**********************************/
int Interface_console::run(){
return app->exec();
}
/***********************************
*
......
......@@ -36,6 +36,7 @@ protected:
*/
Interface_graphic* _main_window;
QApplication* app;
/***********************************
......@@ -125,6 +126,19 @@ protected:
/***********************************
*
* Running function.
*
**********************************/
/*!
* \brief This function launch Qt event loop.
*/
int run();
/***********************************
*
* Informative message functions.
......
......@@ -24,11 +24,13 @@ Interface_graphic::Interface_graphic(QWidget *parent):QWidget(parent){
_is_rendering_trace = false;
load_windows();
}
Interface_graphic::Interface_graphic(const string file_path, QWidget *parent):QWidget(parent){
_is_rendering_trace = false;
load_windows();
......@@ -158,10 +160,12 @@ void Interface_graphic::opening_file(string const &path){
if (build(&trace)==false)
error("Open file : an error occured with wait screen releasing.");
_is_rendering_trace = true;
_ui_render_area->update();
}
......@@ -203,7 +207,6 @@ void Interface_graphic::on_open_triggered(){
*/
QString filename = QFileDialog::getOpenFileName(_ui_main_window);
if (!filename.isEmpty()){
if(_is_rendering_trace == true){/* Realease the previous trace */
......@@ -211,13 +214,49 @@ void Interface_graphic::on_open_triggered(){
warning("Cannot opening an other file");
}
else
else{
opening_file(filename.toStdString());
_ui_main_window->setWindowTitle(QString("ViTE :: ")+filename);
}
}
}
void Interface_graphic::on_export_triggered(){
QString filename = QFileDialog::getSaveFileName(_ui_main_window, tr("Export File"),
"",
tr("Images (*.svg)"));
if (!filename.isEmpty()){
/* QApplication::setOverrideCursor(Qt::WaitCursor);
out << textEdit->toPlainText();
QApplication::restoreOverrideCursor();
*/
information(string("Exporting trace to ")+filename.toStdString());
}
else
error("No file specified for exportation");
}
void Interface_graphic::on_close_triggered(){
if(_is_rendering_trace == false)
......@@ -232,6 +271,8 @@ void Interface_graphic::on_close_triggered(){
_ui_render_area->update();
_ui_main_window->setWindowTitle(QString("ViTE"));
}
......@@ -306,6 +347,7 @@ void Interface_graphic::on_translate_state_valueChanged(int new_value){
}
void Interface_graphic::on_main_window_hide(){
cerr << "GoodBye"<<endl;
......
......@@ -224,6 +224,11 @@ protected slots:
*/
void on_open_triggered();
/*!
*\brief A slot which called when 'export' in the menu is clicked.
*/
void on_export_triggered();
/*!
*\brief A slot which called when 'close' in the menu is clicked.
*/
......@@ -256,6 +261,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_main_window_hide();
};
......
......@@ -40,12 +40,15 @@
</widget>
</item>
<item>
<widget class="QSlider" name="translate_state" >
<property name="maximum" >
<number>10000</number>
<widget class="QScrollBar" name="translate_state" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="singleStep" >
<number>1</number>
<property name="maximum" >
<number>100000</number>
</property>
<property name="pageStep" >
<number>1</number>
......@@ -67,25 +70,22 @@
</widget>
</item>
<item>
<widget class="QSlider" name="scale_state" >
<property name="minimum" >
<number>1</number>
<widget class="QScrollBar" name="scale_state" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum" >
<number>100000</number>
</property>
<property name="singleStep" >
<number>1</number>
</property>
<property name="pageStep" >
<number>1</number>
</property>
<property name="value" >
<number>10</number>
</property>
<property name="sliderPosition" >
<number>10</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
......@@ -109,6 +109,7 @@
<string>&amp;File</string>
</property>
<addaction name="open" />
<addaction name="export" />
<addaction name="separator" />
<addaction name="close" />
<addaction name="separator" />
......@@ -215,6 +216,14 @@
<string>Show infos window</string>
</property>
</action>
<action name="export" >
<property name="text" >
<string>&amp;Export</string>
</property>
<property name="shortcut" >
<string>Ctrl+E</string>
</property>
</action>
</widget>
<resources>
<include location="vite.qrc" />
......
......@@ -55,15 +55,13 @@ Render_area::Render_area(QWidget *parent)
_container_x_max = 0;
_container_y_max = 0;
_state_x_max = 0;
_state_x_min = 1000;/* bad values ! */
/* attributes */
list_containers =0;
list_states = 0;
_list_containers =0;
_list_states = 0;
_state_scale = 1;/* temporary, for states scaling */
_state_translate = 0;/* temporary, for states translation */
_container_view_size = 50;/* temporary, for container view */
setAutoFillBackground(false);
......@@ -139,12 +137,13 @@ void Render_area::paintGL(){
list<Element_pos>::iterator it_pos;
list<string>::iterator it_txt;
Element_pos buf_rot;
Element_pos buf_x;
Element_pos buf_y;
string buf_txt;
int j=0.6;
resizeGL(width(), height());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
......@@ -173,7 +172,7 @@ void Render_area::paintGL(){
case DRAWING_STATE_DRAWING:/* A trace is drawn */
if (glIsList(list_states)==GL_FALSE)
if (glIsList(_list_states)==GL_FALSE)
_parent->error("ERROR LIST not exist for states.");
glMatrixMode(GL_MODELVIEW);
......@@ -182,9 +181,11 @@ void Render_area::paintGL(){
/* Draw containers */
glPushMatrix();
glTranslatef(0.0f, 40.0f, -1.0f);
glScalef(10.0f/_container_x_max, 50.0f/_container_y_max, 0.0f);
#ifdef DEBUG_MODE_RENDER_AREA
......@@ -192,7 +193,19 @@ void Render_area::paintGL(){
cerr << "Default container position (before translation and scaling) : (x_max = " << _container_x_max << ", y_max = " << _container_y_max << ")" << endl << endl;
#endif
glCallList(list_containers);
glBegin(GL_QUADS);/* create a quads */
{
glColor3d(0, 0, j);glVertex2d(0, 10);
glColor3d(0, 0, j-0.1);glVertex2d(0, 5);
glColor3d(0, 0, j-0.1);glVertex2d(-5, 5);
glColor3d(0, 0, j);glVertex2d(-5, 10);
}
glEnd();
glCallList(_list_containers);
glPopMatrix();
......@@ -200,9 +213,6 @@ void Render_area::paintGL(){
/* Draw container texts */
for (it_txt=_text_value.begin(), it_pos=_text_pos.begin() ; it_txt!=_text_value.end(); it_txt++, it_pos++ ){
buf_rot = *it_pos;
it_pos++;
buf_x = *it_pos;
it_pos++;
......@@ -211,7 +221,8 @@ void Render_area::paintGL(){
buf_txt = *it_txt;
glPushMatrix();
glTranslatef(0.0f, 40.0f, 0.0f);
glScalef(10.0f/_container_x_max, 50.0f/_container_y_max, 0.0f);
......@@ -242,7 +253,7 @@ void Render_area::paintGL(){
glCallList(list_states);
glCallList(_list_states);
glPopMatrix();
......@@ -281,6 +292,13 @@ void Render_area::change_translate(int translate){
}
void Render_area::change_container_view(int view_size){
_container_view_size = view_size*(width()/100);
updateGL();
}
/***********************************
*
......@@ -457,318 +475,103 @@ GLuint Render_area::draw_wait() {
GLuint Render_area::draw_trace(){//Trace trace)
GLuint object;
// GLuint list_containers;
//GLuint list_states;
stack<EntityList *> stack_states;
list_containers = glGenLists(1);/* create the list */
if (list_containers==0){
_parent->warning("Error when creating list");
}
DrawTrace<Render_area> drawing;
list_states = glGenLists(1);/* create the list */
if (list_states==0){
drawing.build(this, _trace);
_parent->warning("Error when creating list");
}
GLuint object; /* Must be delete */
/* Must be delete */
object = glGenLists(2);/* create the list */
if (object==0){
_parent->warning("Error when creating list");
}
/* end Must be delete */
return object; /* Must be delete */
}
glNewList(list_containers, GL_COMPILE);/* open the list */
{
/*** Drawing containers ***/
/*
* Start with the root containers.
* if a container has more than one child, it will be draw
* vertically, else horizontally.
*/
stack<Element_count> position_stack;
stack<Element_pos> 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 */
const Container* container;
const list<Container *> *trace_container = _trace->get_root_containers();
list<Container *>::iterator it;
bool isAnotherContainer = true;/* use to stop the loop */
inline void Render_area::start_draw(){
/* clear lists to store container texts */
_text_pos.clear();
_text_value.clear();
}
position_stack.push(0);
height_stack.push(0);
inline void Render_area::start_draw_containers(){
container = get_container(trace_container, 0);
_list_containers = glGenLists(1);/* create the list */
if (_list_containers==0){
_parent->warning("Error when creating list");
}
if (number_of_children(container) <= 1)
x = _container_width;
else
x = _container_height;
y = 0;
y_buf = 0;
height_buf = 0;
glNewList(_list_containers, GL_COMPILE);/* open the list */
}
while (isAnotherContainer == true){
Element_pos buf_pos;
buf_pos = return_last_visited_child(position_stack);
inline void Render_area::draw_container(const Element_pos x, const Element_pos y, const Element_pos w, const Element_pos h) {
/* 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 */
container = get_container(container->get_children(), buf_pos);
// 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 */
height_buf = 0;
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;
/* Then, we store the list of entity */
stack_states.push(container->get_states());
height_buf = _container_height;
}else
height_buf = height_stack.top()-_container_v_space;/* take the child's height */
draw_container(x, y, _container_width, height_buf);
_text_pos.push_back(height_buf);
_text_pos.push_back(x- _container_width+_container_h_space);
_text_pos.push_back(y-height_buf/2);
_text_value.push_back(container->get_name().to_string());
x -= (_container_width + _container_h_space);
}
else{ /* Should be drawn vertically */
height_buf = 0;
for (int i = 0 ; i < number_of_children(container) ; i ++){
height_buf += height_stack.top();
height_stack.pop();
}
height_stack.push(height_buf);/* push the sum of child heights */
height_buf -= _container_v_space;
draw_container(x, y, _container_width, height_buf);/* Vertically, it is drawn as higher as it has children */
_text_pos.push_back(height_buf);
_text_pos.push_back(x-_container_width+_container_h_space);
_text_pos.push_back(y- height_buf/2);
_text_value.push_back(container->get_name().to_string());
x -= (_container_width + _container_h_space);
}
if (x>_container_x_max)
_container_x_max = x;
if (y>_container_y_max)
_container_y_max = y;
/* 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){
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 */
}
else{
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 */
float j=0.6;
glNewList(list_states, GL_COMPILE);/* open the list */
glBegin(GL_QUADS);/* create a quads */
{
EntityList *buf_list;
State* buf_entity;
Element_count i;/* for the level (y axis) of the states */
i=0;
while (!stack_states.empty()){
buf_list = stack_states.top();
for (buf_list->go_beginning() ; buf_list->has_next() ; buf_list->next() ) {