Render_alternate.cpp 39.5 KB
Newer Older
1 2 3 4 5 6 7 8
/*
** This file is part of the ViTE project.
**
** This software is governed by the CeCILL-A license under French law
** and abiding by the rules of distribution of free software. You can
** use, modify and/or redistribute the software under the terms of the
** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following
** URL: "http://www.cecill.info".
Thibault Soucarre's avatar
Thibault Soucarre committed
9
**
10 11 12 13 14
** As a counterpart to the access to the source code and rights to copy,
** modify and redistribute granted by the license, users are provided
** only with a limited warranty and the software's author, the holder of
** the economic rights, and the successive licensors have only limited
** liability.
Thibault Soucarre's avatar
Thibault Soucarre committed
15
**
16 17 18 19 20 21 22 23 24 25
** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software,
** that may mean that it is complicated to manipulate, and that also
** therefore means that it is reserved for developers and experienced
** professionals having in-depth computer knowledge. Users are therefore
** encouraged to load and test the software's suitability as regards
** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security.
Thibault Soucarre's avatar
Thibault Soucarre committed
26
**
27 28 29 30 31 32 33 34 35 36 37 38 39
** The fact that you are presently reading this means that you have had
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
** ViTE developers are (for version 0.* to 1.0):
**
**        - COULOMB Kevin
**        - FAVERGE Mathieu
**        - JAZEIX Johnny
**        - LAGRASSE Olivier
**        - MARCOUEILLE Jule
**        - NOISETTE Pascal
**        - REDONDY Arthur
Thibault Soucarre's avatar
Thibault Soucarre committed
40
**        - VUCHENER Clément
41 42 43 44 45 46
**
*/
/*!
 *\file Render_alternate.cpp
 */
#include "common/common.hpp"
47
#include "common/Info.hpp"
48
#include "common/Message.hpp"
49
/* -- */
50
//#include "render/GanttDiagram.hpp"
51 52 53

#include <GL/glew.h>
/* -- */
54 55 56 57
#include <QFile> // For loading the wait image
#include <QDate>
#include <QTimer>
/* -- */
58
#include "interface/resource.hpp"
59 60 61 62 63 64 65 66
#include "interface/Interface.hpp"
/* -- */
#include "common/common.hpp"
#include "common/Info.hpp"
#include "common/Message.hpp"
/* -- */
#include "render/Ruler.hpp"
#include "render/Render_alternate.hpp"
67
#include "render/GanttDiagram.hpp"
68
#include "render/Shader.hpp"
69
/* -- */
70 71
#include "core/Core.hpp"
#include "render/vbo.hpp"
72
#include "trace/EntityValue.hpp"
73
#include <iostream>
74
#define PI 3.14159265
Thibault Soucarre's avatar
Thibault Soucarre committed
75
#define NB_STEPS 20
76 77 78 79 80 81 82

using namespace std;


#define message *Message::get_instance() << "(" << __FILE__ << " l." << __LINE__ << "): "

static bool _draw_container;
Thibault Soucarre's avatar
Thibault Soucarre committed
83
static bool _draw_states;
84 85 86
static bool _draw_ruler;
static bool _draw_arrow;
static bool _draw_event;
Thibault Soucarre's avatar
Thibault Soucarre committed
87
static bool _draw_counter;
88
//const int Render_alternate::DRAWING_TIMER_DEFAULT = 10;
89 90 91 92 93 94 95 96 97 98 99 100

/***********************************
 *
 *
 *
 * Constructor and destructor.
 *
 *
 *
 **********************************/

Render_alternate::Render_alternate(Core* core, QWidget *parent, const QGLFormat& format)
101
    : Hook_event(this, core, parent, format), _containers(GL_QUADS), /*_states(GL_QUADS),*/ _events(GL_POINTS), _events2(GL_LINES), _arrows(GL_LINE), _arrows2(GL_TRIANGLES), _counters(GL_LINE), _ruler(GL_QUADS), /*_shader("vertexshader.vertexshader", "fragmentshader.fragmentshader"),*/ _modelview(glm::mat4(1.0)), _projection(glm::mat4(1.0)), _container_height(_DRAWING_CONTAINER_HEIGHT_DEFAULT){
102 103 104 105
}


Render_alternate::~Render_alternate(){
106
    delete _shader;
107 108 109 110 111 112 113 114 115 116 117 118 119
}

/***********************************
 *
 *
 *
 * Default QGLWidget functions.
 *
 *
 *
 **********************************/

void  Render_alternate::initializeGL() {
120 121
    glewExperimental = GL_TRUE;
    GLenum err = glewInit();
122
    if(err!=GLEW_OK){
123
        std::cout << "ERROR : GlewInit failed" << std::endl;
124
    }
125
    //_shader.charger();
126
    glClearColor(0.5f, 0.5f, 0.55f, 0.0f);
127 128
    glEnable(GL_DEPTH_TEST);
    glClearStencil(0);
129
    std::cout << "init" << std::endl;
130 131 132 133 134 135 136 137
    const GLubyte * version = glGetString(GL_SHADING_LANGUAGE_VERSION);
    if (version==NULL)
        std::cout << "ERROR : could not detect your GLSL version" << std::endl;
    else
        std::cout << "Version GLSL : " << version << std::endl;
    _glsl = (version[0]-'0')*100 + (version[2]-'0')*10 + version[3]-'0';
    std::cout << _glsl << std::endl;
    _shader = new Shader(_glsl);
Thibault Soucarre's avatar
Thibault Soucarre committed
138
    _wait_shader = new Shader(_glsl, 0);
139
    _shader->charger();
Thibault Soucarre's avatar
Thibault Soucarre committed
140 141
    _wait_shader->charger();
    draw_wait();
142 143 144
    //std::cout << version[2] << std::endl;
    //std::cout << version[3] << std::endl;
    setAutoFillBackground(false);
145 146 147 148
    if(_core == NULL)
        std::cout << "_core = NULL" << std::endl;
    _core->waitGUIInit->quit();
    std::cout << "init ok" << std::endl;
149 150
    _modelview = glm::scale(_modelview, glm::vec3(1,-1,1));
    _modelview = glm::translate(_modelview, glm::vec3(0,-Info::Render::height, 0));
151 152 153 154
}

void  Render_alternate::resizeGL(int width, int height) {
    glViewport(0, 0, width, height);
Thibault Soucarre's avatar
Thibault Soucarre committed
155

156 157 158
    /* update informations about widget size */
    Info::Screen::width  = width;
    Info::Screen::height = height;
159 160 161
    if(_state == DRAWING_STATE_WAITING)
        _projection = glm::ortho(-50, 50, -50, 50);//, 0, 1);
    else if(_state == DRAWING_STATE_DRAWING)
162
        _projection = glm::ortho(0.f, Info::Render::width, 0.f, Info::Render::height, 0.f, 100.f);
163 164 165 166
    else{
     message << tr("Undefined value for the drawing state attribute - Render area").toStdString() << Message::ende;
     }

167 168
}

169

170
void  Render_alternate::paintGL(){
Thibault Soucarre's avatar
Thibault Soucarre committed
171 172
    glClearDepth(1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
173
    /*Do not call paintGL before rendering the trace*/
Thibault Soucarre's avatar
Thibault Soucarre committed
174 175 176 177 178 179 180 181 182 183 184
    if(DRAWING_STATE_WAITING == _state){
        glUseProgram(_wait_shader->getProgramID());
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        _wait.lock();
        glBindTexture(GL_TEXTURE_2D, _textureID);
        std::cout << "draw wait\n";
        glDrawArrays(GL_QUADS, 0, _wait.getNbVertex());
        glBindTexture(GL_TEXTURE_2D, 0);
        _wait.unlock();
        glUseProgram(0);
185
        return;
Thibault Soucarre's avatar
Thibault Soucarre committed
186
    }
Thibault Soucarre's avatar
Thibault Soucarre committed
187

188
    resizeGL(Render_alternate::QGLWidget::width(), Render_alternate::QGLWidget::height());
189 190
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    //select shader program
191
    glUseProgram(_shader->getProgramID());
192
    std::cout << "paintGL" << std::endl;
193
    glm::mat4 tmp = _modelview;
194 195
    glm::mat4 tmp2 = _modelview;
    glm::mat4 mvp;
196 197 198
    start_ruler();
    call_ruler();
    end_ruler();
199
    _ruler.config(_glsl);
Thibault Soucarre's avatar
Thibault Soucarre committed
200
    _ruler.lock();
Thibault Soucarre's avatar
Thibault Soucarre committed
201
    _modelview = glm::translate(_modelview, glm::vec3(0.0, 0.0, _z_ruler));
202 203 204
    mvp = _projection * _modelview;
    //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
    //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
205
    glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
206
    glDrawArrays(GL_QUADS, 0, 8);
Thibault Soucarre's avatar
Thibault Soucarre committed
207 208
    _modelview = tmp;
    _modelview = glm::translate(_modelview, glm::vec3(0.0, 0.0, _z_ruler_over));
209
    mvp = _projection * _modelview;
210
    glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
211
    //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
212
    glDrawArrays(GL_LINES, 8, _ruler.getNbVertex());
Thibault Soucarre's avatar
Thibault Soucarre committed
213
    _ruler.unlock();
Thibault Soucarre's avatar
Thibault Soucarre committed
214 215
    _modelview = tmp;

216
    /* drawing containers*/
217
    _containers.lock();
Thibault Soucarre's avatar
Thibault Soucarre committed
218
    _modelview = glm::translate(_modelview, glm::vec3(0.0, _ruler_y + _ruler_height - _y_state_translate, _z_container));
Thibault Soucarre's avatar
Thibault Soucarre committed
219
    _modelview = glm::scale(_modelview, glm::vec3(_x_scale_container_state/0.20, _y_state_scale, 1.0));
220
    mvp = _projection * _modelview;
221
    glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
222 223
    //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
    //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
224 225
    glDrawArrays(GL_QUADS, 0, _containers.getNbVertex());
    _containers.unlock();
226
    _modelview = tmp;
227
    glUseProgram(0);
228
    /*drawing states*/
Thibault Soucarre's avatar
Thibault Soucarre committed
229
    _modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate, _z_state));
230
    _modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1));
231
    mvp = _projection * _modelview;
232
    std::map<const EntityValue*, Vbo*>::iterator it_state;
233 234
    it_state = _states.begin();
    while(it_state!=_states.end()){
235
        //std::cout << "drawing states" << std::endl;
236
        Shader *s = _states_shaders[it_state->first];
237
        glUseProgram(s->getProgramID());
238
        //glUniform1i(glGetUniformLocation(s->getProgramID(), "i"), 0);
239
        it_state->second->lock();
240 241 242
        //_states.lock();
        //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
        //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
243 244
        //glBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0 , sizeof(GLuint), a);
        glUniformMatrix4fv(glGetUniformLocation(s->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
245 246
        glDrawArrays(GL_QUADS, 0, it_state->second->getNbVertex());
        it_state->second->unlock();
247 248 249
        it_state++;
        //_modelview = tmp;
    }
250 251
    glUseProgram(_shader->getProgramID());
    glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
Thibault Soucarre's avatar
Thibault Soucarre committed
252 253 254 255
    /*drawing counters*/
    _counters.lock();
    glDrawArrays(GL_LINES, 0, _counters.getNbVertex());
    _counters.unlock();
256 257
    _modelview = tmp;
    /*drawing links*/
258
    //int n = _links.size()/4;
Thibault Soucarre's avatar
Thibault Soucarre committed
259
    if(false == Info::Render::_no_arrows){
260 261 262
        //necessary for each link
        _modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate , _z_arrow));
        _modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1.0));
263 264 265
        //_modelview = tmp2;
        //mvp = _projection * _modelview;
        //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
266
        //save current modelview
267
        //tmp2 = _modelview;
268
        _arrows.lock();
269
        /*for(int i=0; i<n ; i++) {
270
            //change matrix to draw the current arrow
Thibault Soucarre's avatar
Thibault Soucarre committed
271 272
            _modelview = glm::translate(_modelview, glm::vec3(_links[4*i+2], _links[4*i+3], 0));
            _modelview = glm::rotate(_modelview, (float) _links[4*i], glm::vec3(0,0,1));
273
         _modelview = glm::scale(_modelview, glm::vec3(_links[4*i+1], _links[4*i+1/10], 1));*/
Thibault Soucarre's avatar
Thibault Soucarre committed
274
            //draw the arrow
275
        mvp = _projection * _modelview;
276
        glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
277 278
            //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
            //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
279
        glDrawArrays(GL_LINES, 0, _arrows.getNbVertex());
280 281
            //_modelview = tmp2;
            //}
282
        _arrows.unlock();
283 284 285 286 287 288 289 290 291 292
        int n = _links.size()/4;
        switch(Info::Render::_arrows_shape){
        case 0: //triangles
            _arrows3.lock();
            _modelview = glm::scale(_modelview, glm::vec3(1/_x_state_scale, 1/_y_state_scale, 1));
            tmp2 = _modelview;
            for(int i=0; i<n ; i++) {
                _modelview = glm::translate(_modelview, glm::vec3(_x_state_scale*_links[4*i+2], _y_state_scale*_links[4*i+3], 0));
                _modelview = glm::rotate(_modelview, (float) _links[4*i], glm::vec3(0,0,1));
                mvp = _projection * _modelview;
293
                glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
294 295 296 297
                glDrawArrays(GL_TRIANGLES, 0, _arrows3.getNbVertex());
                _modelview = tmp2;
        }
            _arrows3.unlock();
298 299
            //  _modelview = tmp2;
            //}
300 301 302 303 304 305 306 307 308 309
            _arrows2.unlock();
            break;
        case 1: //points
            _arrows2.lock();
            glDrawArrays(GL_POINTS, 0, _arrows2.getNbVertex());
            _arrows2.unlock();
            break;
        default: //no head
            break;
        }
310
        _modelview = tmp;
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
            //_arrows.unlock();
            //restore matrix with changes needed for all links

            //}
            //_arrows.unlock();
        //_modelview = tmp2;
        //_modelview = glm::translate(_modelview, glm::vec3(_x_state_scale*(_default_entity_x_translate - _x_state_translate), _y_state_scale*(_ruler_y + _ruler_height - _y_state_translate), _z_arrow));
        //mvp = _projection * _modelview;
        //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
        /*_modelview = tmp2;
        for (int i=0; i<n;i++){
            _modelview = glm::translate(_modelview, glm::vec3(_x_state_scale*_links[3*i+1], _y_state_scale*_links[3*i+2], 0));
            _modelview = glm::rotate(_modelview, (float) _links[3*i], glm::vec3(0,0,1));
            mvp = _projection * _modelview;
            glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
            _arrows2.lock();
            glDrawArrays(GL_TRIANGLES, 0, _arrows2.getNbVertex());
            _arrows2.unlock();
            //restore basic matrix
         _modelview = tmp2;*/
        }
    //}
Thibault Soucarre's avatar
Thibault Soucarre committed
333 334
    /*drawing events*/
    if(false == Info::Render::_no_events){
335 336 337
        //necessary for each event
        _modelview = glm::translate(_modelview, glm::vec3(_default_entity_x_translate - _x_state_translate, _ruler_y + _ruler_height - _y_state_translate , _z_event));
        _modelview = glm::scale(_modelview, glm::vec3(_x_state_scale, _y_state_scale, 1.0));
338 339
        _events.lock();
        mvp = _projection * _modelview;
340
        glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
341 342 343 344 345 346 347 348 349 350
        //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
        //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
        glEnable(GL_PROGRAM_POINT_SIZE);
        glEnable(GL_POINT_SMOOTH);
        glPointSize(5);
        glDrawArrays(GL_POINTS, 0, _events.getNbVertex());
        _events.unlock();
        _events2.lock();
        glDrawArrays(GL_LINES, 0, _events2.getNbVertex());
        _events2.unlock();
351
    }
352

353 354 355 356
    //restore basic matrix
    _modelview = tmp;


357 358
    /*draw selection if necessary*/
    if (_mouse_pressed && (Info::Render::_key_ctrl == false) && !_mouse_pressed_inside_container){
Thibault Soucarre's avatar
Thibault Soucarre committed
359 360 361
        //allow transparency
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
362 363 364 365 366
        Element_pos x0, x1, y0, y1;
        x0 = screen_to_render_x(_mouse_x);
        y0 = /*Info::Render::height -*/ screen_to_render_y(_mouse_y);
        x1 = screen_to_render_x(_new_mouse_x);
        y1 = /*Info::Render::height -*/ screen_to_render_y(_new_mouse_y);
Thibault Soucarre's avatar
Thibault Soucarre committed
367 368
        float selection[12] = {x0, y0, x0, y1, x1, y1, x1, y0};
        float selection_colors[16] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
369
        mvp = _projection * _modelview;
370
        glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
371 372
        //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
        //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
373 374 375 376 377 378 379
        glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, selection);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, selection_colors);
        glEnableVertexAttribArray(1);
        glDrawArrays(GL_QUADS, 0, 4);
        glDisableVertexAttribArray(0);
        glDisableVertexAttribArray(1);
Thibault Soucarre's avatar
Thibault Soucarre committed
380
        glDisable(GL_BLEND);
381
        _modelview = tmp;
382
 }
Thibault Soucarre's avatar
Thibault Soucarre committed
383
    draw_vertical_line();
Thibault Soucarre's avatar
Thibault Soucarre committed
384

385 386
    //deselect shader
    glUseProgram(0);
Thibault Soucarre's avatar
Thibault Soucarre committed
387 388
    QFont arial_font = QFont("Arial", 10);
    const QFontMetrics metric(arial_font);
389 390 391 392 393 394 395
    QString t =QString().setNum(vertical_line);
    // draw time corresponding to the vertical line position
    qglColor(Qt::red);
    renderText ( render_to_screen_x(trace_to_render_x(vertical_line))-metric.size(Qt::TextSingleLine,t).width() -5,
              metric.height()-1,
               t,
               arial_font);
Thibault Soucarre's avatar
Thibault Soucarre committed
396

Thibault Soucarre's avatar
Thibault Soucarre committed
397 398 399 400 401 402 403 404 405 406 407
    //draw texts for variables
    std::map<long int, Variable_text_>::const_iterator it=_variable_texts.begin();
    const std::map<long int, Variable_text_>::const_iterator it_end=_variable_texts.end();

    for(;it!=it_end;it++){
            renderText ( render_to_screen_x(trace_to_render_x(vertical_line))+3,
                         render_to_screen_y( trace_to_render_y((*it).second.y) + 0.5),
                         QString().setNum((*it).second.value),
                         arial_font);
    }

408 409

    qglColor(Qt::white);
Thibault Soucarre's avatar
Thibault Soucarre committed
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
    //we calculate the height of the interline we want : max height of the font + 1 pixel to avoid overlapping (metric.height() returns a bigger value, a bit too much)
    int height = metric.tightBoundingRect("fg").height()+1;

    /* Draw container text */
    const unsigned int texts_size = _texts.size();
    std::map<Element_pos,Element_pos> previous_by_column;


    //int skipped,displayed=0;
        for (unsigned int i=0 ; i<texts_size ; i++){



            if (trace_to_render_y(_texts[i].y) + 0.5 < 9) continue;/* Do not display text if it is on the ruler area */

            //check if ye are not too close to another container to properly display the text
            std::map<Element_pos,Element_pos>::const_iterator it = previous_by_column.find(_texts[i].x);
            const std::map<Element_pos,Element_pos>::const_iterator it_end = previous_by_column.end();

            if (it==it_end || render_to_screen_y(trace_to_render_y(_texts[i].y)) - render_to_screen_y(trace_to_render_y((*it).second))> height ){
                const QString text_elided = metric.elidedText(_texts[i].value.c_str(), Qt::ElideRight, _x_scale_container_state*Info::Screen::width/(Info::Trace::depth+1.));
                renderText ( render_to_screen_x(_texts[i].x * _x_scale_container_state/0.20),
432 433 434
                             render_to_screen_y( trace_to_render_y(_texts[i].y) + 0.5),
                             text_elided,
                             arial_font);
Thibault Soucarre's avatar
Thibault Soucarre committed
435

436
                //push only displayed values in the map
Thibault Soucarre's avatar
Thibault Soucarre committed
437 438 439 440
                previous_by_column[_texts[i].x]=_texts[i].y;
                //displayed++;
            }//else{skipped++;}
        }
Thibault Soucarre's avatar
Thibault Soucarre committed
441
        /*Draw ruler text*/
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
        std::ostringstream buf_txt;
        Element_pos graduation_diff;
        Element_pos coeff_prefix;
        graduation_diff = Ruler::get_graduation_diff(Info::Render::_x_min_visible, Info::Render::_x_max_visible);
        coeff_prefix    = Ruler::get_coeff_for_common_prefix(Info::Render::_x_min_visible, Info::Render::_x_max_visible);

        arial_font.setPointSize(14);

        buf_txt.str("");/* flush the buffer */
        buf_txt << "min: " << (double)Info::Render::_x_min_visible;

        renderText (render_to_screen_x(trace_to_render_x(Info::Render::_x_min_visible)),
                    render_to_screen_y(3),
                    buf_txt.str().c_str(),
                    arial_font);

        buf_txt.str("");/* flush the buffer */
        buf_txt << "max: " << (double)Info::Render::_x_max_visible;

        renderText (render_to_screen_x(trace_to_render_x(Info::Render::_x_max_visible))-130,
                    render_to_screen_y(3),
                    buf_txt.str().c_str(),
                    arial_font);

        buf_txt.str("");
        buf_txt << Ruler::get_common_part_string(Info::Render::_x_min_visible, coeff_prefix) << "--";

        renderText (render_to_screen_x(trace_to_render_x((Info::Render::_x_min_visible +
                                                          Info::Render::_x_max_visible) / 2)),
                    render_to_screen_y(3),
                    buf_txt.str().c_str(),
                    arial_font);

        arial_font.setPointSize(10);

        for (Element_pos i = Info::Render::_x_min_visible ;
             i < Info::Render::_x_max_visible ;
             i+=graduation_diff){

            buf_txt.str("");/* flush the buffer */
            buf_txt << Ruler::get_variable_part(i, coeff_prefix, 2);

            renderText (render_to_screen_x(trace_to_render_x(i)+1),
                        render_to_screen_y(8),
                        buf_txt.str().c_str(),
                        arial_font);

489
    }
490

491 492 493 494 495 496 497 498 499 500 501 502 503 504
}
/***********************************
 *
 *
 *
 * Building functions.
 *
 *
 *
 **********************************/



bool Render_alternate::build(){
Thibault Soucarre's avatar
Thibault Soucarre committed
505

506 507 508 509 510 511 512 513 514 515 516 517
    _state = DRAWING_STATE_DRAWING;/* change the drawing state */

    /* disable some OpenGL features to enhance the rendering */
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);

    replace_scale(1);/* for states scaling */
    _x_state_translate = 0;/* for states translation */
    _y_state_scale = 1;/* for states scaling */
    _y_state_translate = 0;/* for states translation */
    _x_scroll_pos = 0;/* horizontal bar placed on 0 */
    _y_scroll_pos = 0;/* vertical bar placed on 0 */
Thibault Soucarre's avatar
Thibault Soucarre committed
518

519 520 521 522 523 524 525 526 527
    if (NULL == _render_instance)
        return true;

    return true;
}



bool Render_alternate::unbuild(){
Thibault Soucarre's avatar
Thibault Soucarre committed
528

529 530 531 532 533 534 535
    /**********************
     *
     * Init OpenGL features
     *
     **********************/

    /* enable some OpenGL features*/
536 537
    // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Thibault Soucarre's avatar
Thibault Soucarre committed
538

539
    // glEnable(GL_TEXTURE_2D);
540

541 542
    // glEnable(GL_BLEND);/* enable blending for the alpha color */
    // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
543

544
    // glColor3d(1.0, 1.0, 1.0);/* init color to white */
545 546


547 548 549 550 551
    // /*****************************
    //  *
    //  * Init render area attributes
    //  *
    //  *****************************/
552

553
    // _state = DRAWING_STATE_WAITING;/* change the drawing state */
554

555 556
    // _wait_angle=0.0f;/* begin with 0 rad angle */
    // _wait_angle_y=0.0f;/* begin with 0 rad angle */
557

558 559 560 561 562
    // /* init measurement attributes */
    // Info::Container::x_max = 0;
    // Info::Container::y_max = 0;
    // Info::Container::x_min = 0;
    // Info::Container::y_min = 0;
563

564 565
    // //    Info::Render::_ui_render_min_value->setText("");
    // // Info::Render::_ui_render_max_value->setText("");
566

567 568 569 570 571 572
    // Info::Entity::x_max = 0;
    // Info::Entity::x_min = 0;
    // //    _state_x_max = 0;
    // _state_y_max = 0;
    // //    _state_x_min = 0;
    // _state_y_min = 0;
573

574 575 576
    // /* clear lists to store container texts */
    // _text_pos.clear();
    // _text_value.clear();
577

578 579 580
    // _arrows.clear();
    // _circles.clear();
    // _texts.clear();
581

582 583 584 585 586 587
    // for (unsigned int i=0 ;
    //      i<_vbos.size()   ;
    //      i++){
    //     delete _vbos[i];
    // }
    // _vbos.clear();
588

589 590
    // /* clear the event vector */
    // // _events.clear();
591

592 593
    // /* clear the arrow vector */
    // // _arrows.clear();
Thibault Soucarre's avatar
Thibault Soucarre committed
594

595 596 597
    // /* empty the selection stack */
    // while(false == _previous_selection.empty())
    //     _previous_selection.pop();
598

599 600
    // if (NULL == _render_instance)
    //     return true;
601

602 603 604
    // /* Now, timer is set */
    // if (_wait_timer == NULL){
    //     _wait_angle = 0.0f;
Thibault Soucarre's avatar
Thibault Soucarre committed
605

606 607 608 609
    //     /*  _wait_timer = new QTimer(this);
    //     connect(_wait_timer, SIGNAL(timeout()), _render_instance, SLOT(updateGL()));
    //     _wait_timer->start(_wait_spf);*/
    // }
610 611


612
    // return true;//_render_instance->display_unbuild();
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
}





/***********************************
 *
 *
 *
 * Drawing function for the wait screen.
 *
 *
 *
 **********************************/



GLuint Render_alternate::draw_wait() {
Thibault Soucarre's avatar
Thibault Soucarre committed
632 633 634 635 636 637 638 639 640 641 642 643
    glGenTextures(1, &_textureID);
    QFile texture_file(QString(":/img/img/logo") +  QDate::currentDate().toString("MMdd") + QString(".png"));
    glBindTexture(GL_TEXTURE_2D, _textureID);
    if (true == texture_file.exists())/* The texture exists */
        _textureID = bindTexture(QPixmap(texture_file.fileName()), GL_TEXTURE_2D);
    else/* use the default picture */
        _textureID = bindTexture(QPixmap(":/img/img/logo.png"), GL_TEXTURE_2D);
    _wait.add(-0.25, -0.25, 0, 0);
    _wait.add( 0.25, -0.25, 1, 0);
    _wait.add( 0.25,  0.25, 1, 1);
    _wait.add(-0.25,  0.25, 0, 1);
    _wait.config(_glsl);
644 645
    // GLuint object;
    // GLuint texture;
646

647
    // glGenTextures(1, &texture);/* create the texture and link it with the list previously created */
Thibault Soucarre's avatar
Thibault Soucarre committed
648

649
    // QFile texture_file(QString(":/img/img/logo") +  QDate::currentDate().toString("MMdd") + QString(".png"));
Thibault Soucarre's avatar
Thibault Soucarre committed
650

651 652 653 654
    // if (true == texture_file.exists())/* The texture exists */
    //     texture = bindTexture(QPixmap(texture_file.fileName()), GL_TEXTURE_2D);
    // else/* use the default picture */
    //     texture = bindTexture(QPixmap(":/img/img/logo.png"), GL_TEXTURE_2D);
655

Thibault Soucarre's avatar
Thibault Soucarre committed
656

657 658 659
    // /* 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);
Thibault Soucarre's avatar
Thibault Soucarre committed
660

661
    // glEnable(GL_TEXTURE_2D);
662

663 664
    // glEnable(GL_BLEND);/* enable blending for the alpha color */
    // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
665

Thibault Soucarre's avatar
Thibault Soucarre committed
666

667 668 669 670 671 672 673 674
    // /* Now, timer is set */
    // if (_wait_timer == NULL){
    //     _wait_angle = 0.0f;
    //     /*
    //     _wait_timer = new QTimer(this);
    //     connect(_wait_timer, SIGNAL(timeout()), _render_instance, SLOT(updateGL()));
    //     _wait_timer->start(_wait_spf);*/
    // }
675

676
    // return object;
677 678 679 680 681
}



void Render_alternate::call_ruler(){
682
    _ruler.setNbVertex(0);
683
    Element_pos graduation_diff;
684
    //Element_pos coeff_prefix;
685 686 687 688
    const Element_pos offset_x = _default_entity_x_translate;
    const Element_pos offset_y = _ruler_y + _ruler_height+3.5;

    update_visible_interval_value();
Thibault Soucarre's avatar
Thibault Soucarre committed
689

690
    graduation_diff = Ruler::get_graduation_diff(Info::Render::_x_min_visible, Info::Render::_x_max_visible);
691
    //coeff_prefix    = Ruler::get_coeff_for_common_prefix(Info::Render::_x_min_visible, Info::Render::_x_max_visible);
692 693
    //draw quads
    set_color(0.0, 0.0, 1.0);
Thibault Soucarre's avatar
Thibault Soucarre committed
694
    _ruler.add(trace_to_render_x(Info::Render::_x_min_visible), 3, _r, _g, _b);
695 696
    _ruler.add(trace_to_render_x(Info::Render::_x_min_visible), 8, _r, _g, _b);
    _ruler.add(trace_to_render_x(Info::Render::_x_max_visible), 8, _r, _g, _b);
Thibault Soucarre's avatar
Thibault Soucarre committed
697
    _ruler.add(trace_to_render_x(Info::Render::_x_max_visible), 3, _r, _g, _b);
698 699 700 701 702 703 704
    set_color(0.0, 0.0, 0.0);
    _ruler.add(trace_to_render_x(Info::Render::_x_min_visible), 0, _r, _g, _b);
    _ruler.add(trace_to_render_x(Info::Render::_x_min_visible), 3, _r, _g, _b);
    _ruler.add(trace_to_render_x(Info::Render::_x_max_visible), 3, _r, _g, _b);
    _ruler.add(trace_to_render_x(Info::Render::_x_max_visible), 0, _r, _g, _b);

    //draw graduations
705
    set_color(1.0, 1.0, 1.0);
Thibault Soucarre's avatar
Thibault Soucarre committed
706

707 708 709 710 711 712 713 714 715 716
    for (Element_pos i = Info::Render::_x_min_visible ; i < Info::Render::_x_max_visible ; i+=graduation_diff){
        const Element_pos grad_div_by_5 = graduation_diff/5;
        for (Element_pos j = (i+grad_div_by_5) ; j<(i+graduation_diff) ; j+= grad_div_by_5){
            draw_line( trace_to_render_x(j) + offset_x, offset_y  ,
                       trace_to_render_x(j) + offset_x, 2+offset_y, _z_ruler);
        }

        draw_line( trace_to_render_x(i) + offset_x, offset_y-1  ,
                   trace_to_render_x(i) + offset_x, 4+offset_y, _z_ruler);
    }
Thibault Soucarre's avatar
Thibault Soucarre committed
717

718
     return;
Thibault Soucarre's avatar
Thibault Soucarre committed
719
}
720 721 722 723



void Render_alternate::set_color(float r, float g, float b){
724 725 726
    _r = r;
    _g = g;
    _b = b;
727 728
}

Thibault Soucarre's avatar
Thibault Soucarre committed
729
void Render_alternate::draw_text(const Element_pos x, const Element_pos y, const Element_pos size, const std::string s){
730
    if (_draw_ruler) return;/* do not draw text for ruler */
Thibault Soucarre's avatar
Thibault Soucarre committed
731 732
    Container_text_ buf;
    buf.x     = x;
Thibault Soucarre's avatar
Thibault Soucarre committed
733
    buf.y     = render_to_trace_y(y);// + offset_y; //render_to_trace_y(y);/* Cancel previous transformation. */
Thibault Soucarre's avatar
Thibault Soucarre committed
734 735 736
    buf.value = s;
    buf.size = size;
    _texts.push_back(buf);
737 738 739 740 741 742 743
}

void Render_alternate::draw_quad(Element_pos x, Element_pos y, Element_pos z, Element_pos w, Element_pos h){
    Element_pos offset_x;
    const Element_pos offset_y = -_ruler_y - _ruler_height;

    offset_x = 0;
744 745 746 747 748 749 750 751
    if(_draw_container){
        std::cout << "container : " << x << " " << y << " " << w << " " << h <<std::endl;
        _containers.add(x+offset_x  , y+offset_y  , _r,_g,_b);
        _containers.add(x+offset_x+w, y+offset_y  , _r,_g,_b);
        _containers.add(x+offset_x+w, y+offset_y+h, _r,_g,_b);
        _containers.add(x+offset_x  , y+offset_y+h, _r,_g,_b);
    }
    else if(_draw_states){
752
        offset_x = -_default_entity_x_translate;
753 754 755 756 757 758 759 760 761 762 763 764 765 766
        if(_glsl<330) {
            _current->add(x+offset_x  , y+offset_y, 2.0f);//  , _r, _g, _b);
            _current->add(x+offset_x+w, y+offset_y, 1.0f);//  , _r/2, _g/2, _b/2);
            _current->add(x+offset_x+w, y+offset_y+h, 1.0f);//, _r/2, _g/2, _b/2);
            _current->add(x+offset_x  , y+offset_y+h, 2.0f);//, _r, _g, _b);
        }
        else{
            char c1 = 1;
            char c2 = 2;
            _current->add(x+offset_x  , y+offset_y, c2);//  , _r, _g, _b);
            _current->add(x+offset_x+w, y+offset_y, c1);//  , _r/2, _g/2, _b/2);
            _current->add(x+offset_x+w, y+offset_y+h, c1);//, _r/2, _g/2, _b/2);
            _current->add(x+offset_x  , y+offset_y+h, c2);//, _r, _g, _b);
        }
Thibault Soucarre's avatar
Thibault Soucarre committed
767 768 769
    }
    else if(_draw_ruler){
    }
770 771 772 773 774 775 776 777 778 779 780 781

}

void Render_alternate::draw_triangle(Element_pos , Element_pos ,
                                  Element_pos , Element_pos ){
}

void Render_alternate::draw_line(Element_pos x1, Element_pos y1, Element_pos x2, Element_pos y2, Element_pos z){

    const Element_pos offset_x = -_default_entity_x_translate;
    const Element_pos offset_y = -_ruler_y - _ruler_height;

782 783 784 785
    if(_draw_counter){
        _counters.add(x1+offset_x,y1+offset_y,_r,_g,_b);
        _counters.add(x2+offset_x,y2+offset_y,_r,_g,_b);
    }
786 787 788 789
    else if(_draw_ruler){
        _ruler.add(x1+offset_x, y1+offset_y, _r, _g, _b);
        _ruler.add(x2+offset_x, y2+offset_y, _r, _g, _b);
    }
790 791 792 793 794 795 796 797 798
    else{

        glBegin(GL_LINES);
        {
            glColor3d(_r, _g, _b);
            glVertex3d(x1 + offset_x, y1 + offset_y, z);
            glVertex3d(x2 + offset_x, y2 + offset_y, z);
        }
        glEnd();
799 800 801 802 803 804 805 806 807
    }
}

void Render_alternate::draw_circle(Element_pos /*x*/, Element_pos /*y*/, Element_pos /*z*/, Element_pos /*r*/){
}


void Render_alternate::start_draw(){
    /* Init GLEW */
808
    //glewInit();
809 810 811 812 813
    _draw_ruler = false;
    _draw_container = false;
    _draw_arrow = false;
    _draw_event = false;

814
    //_current_vbo = NULL;
Thibault Soucarre's avatar
Thibault Soucarre committed
815

816 817 818 819 820 821 822 823 824 825 826 827 828 829
}

void Render_alternate::start_draw_containers(){
    _draw_container = true;
}

void Render_alternate::draw_container(const Element_pos , const Element_pos , const Element_pos , const Element_pos ){
}

void Render_alternate::draw_container_text(const Element_pos , const Element_pos , const std::string ){
}

void Render_alternate::end_draw_containers(){
    _draw_container = false;
830
    _containers.config(_glsl);
831
    cout << "end_draw_containers" << endl;
832 833 834
}

void Render_alternate::start_draw_states(){
835
    _draw_states = true;
836 837
}

838 839
void Render_alternate::draw_state(const Element_pos x, const Element_pos y, const Element_pos z, const Element_pos w, const Element_pos h, const EntityValue* value){
    if(_states.count(value)==0){
840
        Shader *s = new Shader(_glsl, _r, _g, _b);
841
        //Shader *s = new Shader();
842
        s->charger();
843
        std::pair<const EntityValue*, Shader*> p(value, s);
844
        _states_shaders.insert(p);
845
        Vbo *v = new Vbo(GL_QUADS);
846
        std::pair<const EntityValue*, Vbo*> p2(value, v);
847 848
        _states.insert(p2);
    }
849
    _current = _states[value];
850
    draw_quad(x, y, z, w, h);
851 852 853 854
}

void Render_alternate::end_draw_states(){

855
    _draw_states = false;
856
    std::map<const EntityValue*, Vbo*>::iterator it;
857 858
    it = _states.begin();
    while(it!=_states.end()){
859
        it->second->config(_glsl);
860 861
        it++;
    }
862
    //_states.config(_glsl);
863
    cout << "end_draw_states" << endl;
864 865 866 867 868 869 870 871 872 873 874
}

void Render_alternate::start_draw_arrows(){
    _draw_arrow = true;

}

void Render_alternate::draw_arrow(const Element_pos start_time, const Element_pos end_time, const Element_pos start_height, const Element_pos end_height, const Element_col red, const Element_col green, const Element_col blue){

    const Element_pos offset_x = -_default_entity_x_translate;
    const Element_pos offset_y = -_ruler_y - _ruler_height;
875
    Element_pos x0, x1, y0, y1, l, alpha, cosa, sina;
876 877 878 879 880 881 882
    x0 = start_time   + offset_x;
    x1 = end_time     + offset_x;
    y0 = start_height + offset_y;
    y1 = end_height   + offset_y;
    //size of the arrow
    l = sqrt(pow(x1-x0,2)+pow(y1-y0,2));
    //calculate angle beetween arrow and horizontal axe
883
    cosa = (x1-x0)/l;
884
    sina = (y1-y0)/l;
885 886
    alpha = acos(cosa);
    if(sina<0) alpha*= -1;
887 888 889 890 891 892 893 894
    Element_pos cos30 = cos(PI/6.0);
    Element_pos sin30 = sin(PI/6.0);
    cosa*=(_container_height/2.0);
    sina*=(_container_height/2.0);
    _arrows.add(x0, y0, 1, 1, 1);
    _arrows.add(x1, y1, 1, 1, 1);
    //_arrows2.add(x1, y1, 1, 1, 1);
    _arrows2.add(x1, y1, 1, 1, 1);
895 896 897 898 899 900
    //_arrows2.add(x1 - cosa*cos30 - sina*sin30,
    //             y1 + sina*cos30 - cosa*sin30,
    //            1, 1, 1);
//_arrows2.add(x1 - cosa*cos30 + sina*sin30,
    //           y1 + sina*cos30 + cosa*sin(30),
    //1, 1, 1);
901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920
    /*glm::mat4 m(1.0);
    m = glm::translate(m, glm::vec3(x0, y0, 0));
    m = glm::rotate(m, alpha, glm::vec3(0,0,1));
    m = glm::scale(m, glm::vec3(l, l, 1));
    glm::vec4 v1(0,0,0,1); //origin
    glm::vec4 v2(1,0,0,1);
    glm::vec4 v3(cos(PI/8), -sin(PI/8)/10, 0, 1);
    glm::vec4 v4(cos(PI/8), sin(PI/8)/10, 0, 1);
    v1 = m * v1;
    v2 = m * v2;
    v3 = m * v3;
    v4 = m * v4;
    _arrows.add(v2.x, v2.y, 1, 1, 1);
    _arrows.add(v1.x, v1.y, 1, 1, 1);
    //_arrows.add(v2.x, v2.y, 1, 1, 1);
    _arrows2.add(v3.x, v3.y, 1, 1, 1);
    _arrows2.add(v2.x, v2.y, 1, 1, 1);
    _arrows2.add(v4.x, v4.y, 1, 1, 1);
     _arrows.add(x0, y0, 0, 1, 1);
     _arrows.add(x1, y1, 0, 1, 1);*/
921 922 923 924
    _links.push_back(alpha);
    _links.push_back(l);
    _links.push_back(x1);
    _links.push_back(y1);
925 926
    //_arrows.add(x0, y0, 1, 1, 1);
    //_arrows.add(x1, y1, 1, 1, 1);
927 928 929
}

void Render_alternate::end_draw_arrows(){
930
    //coordinates that we use for all arrows, we will change the angle and scale of using the modelview matrix
931 932 933
    _arrows3.add(0,0,1,1,1);
    _arrows3.add(-1.2, -0.4, 1, 1, 1);
    _arrows3.add(-1.2, 0.4, 1, 1, 1);
934 935
    //_arrows.add(0,0,1,1,1);
    //_arrows.add(-1,0,1,1,1);
936
    //_arrows.add(0,0,1,1,1);
937 938
    //_arrows.add(cos(PI/8), -sin(PI/8), 1, 1, 1);
    //_arrows.add(1,0,1,1,1);
939
    //_arrows.add(0,0,1,1,1);
940
    //_arrows.add(cos(PI/8), sin(PI/8), 1, 1, 1);
941 942 943
    _arrows.config(_glsl);
    _arrows2.config(_glsl);
    _arrows3.config(_glsl);
944
    _draw_arrow = false;
945
    cout << "end_draw_arrows " << _links.size() << endl;
946 947 948 949 950 951 952 953 954 955
}

void Render_alternate::start_draw_events(){
    _draw_event = true;
}

void Render_alternate::draw_event(const Element_pos time, const Element_pos height,  const Element_pos container_height){
    const Element_pos offset_x = -_default_entity_x_translate;
    const Element_pos offset_y = -_ruler_y - _ruler_height;

956 957 958 959 960 961
    //_events.push_back(time + offset_x);
    //_events.push_back(height + offset_y);
    //_events.push_back(container_height);
    _events.add(time+offset_x, height + offset_y, 1, 1, 1);
    _events2.add(time+offset_x, height + offset_y, 1, 1, 1);
    _events2.add(time+offset_x, height+offset_y+container_height/2, 1, 1, 1);
962 963 964 965
}


void Render_alternate::end_draw_events(){
Thibault Soucarre's avatar
Thibault Soucarre committed
966 967
    //As for arrows, we use the same coordinates for every events we draw. Position is changed using modelview matrix
    set_color(1.0, 1.0, 1.0);
968
    /*const float angle = 0;
Thibault Soucarre's avatar
Thibault Soucarre committed
969 970 971 972
    const float delta_angle = 2 * PI / NB_STEPS;
    const float radius = 0.5;
    for(int j = 0 ; j < NB_STEPS ; j ++){
        _circles.add(radius*cos(angle + j*delta_angle), radius*sin(angle + j*delta_angle), _r, _g, _b);
973 974 975 976
     }*/
    //_circles.add(0, 0, _r, _g, _b);
    //_circles.add(0, 0.5, _r, _g, _b);
    //_circles.add(0, 0, _r, _g, _b);
Thibault Soucarre's avatar
Thibault Soucarre committed
977 978 979 980
        //_circles.add(cos_table[j]/_x_state_scale, (sin_table[j]*Info::Screen::width)/(_y_state_scale*Info::Screen::height), _r, _g, _b);

    //        cos_table2[2*j]=  cos_table[j]/_x_state_scale;
    //       sin_table2[2*j+1]= (sin_table[j]*Info::Screen::width)/(_y_state_scale*Info::Screen::height);
981 982
    _events.config(_glsl);
    _events2.config(_glsl);
983
    _draw_event = false;
984
    cout << "end_draw_events" << endl;
985 986 987
}

void Render_alternate::start_draw_counter(){
988
    _draw_counter = true;
989 990 991 992 993 994
}

void Render_alternate::draw_counter(const Element_pos , const Element_pos ){
}

void Render_alternate::end_draw_counter(){
995
    _draw_counter = false;
996
    _counters.config(_glsl);
997
    cout << "end_draw_counters" << endl;
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
}

void Render_alternate::start_ruler(){
    _draw_ruler = true;
}

void Render_alternate::end_ruler(){
    _draw_ruler = false;
}

void Render_alternate::end_draw(){
1009
    cout << "end_draw" << endl;
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
}


void Render_alternate::draw_stored_texts(){
}

void Render_alternate::draw_stored_arrows(){
}

void Render_alternate::draw_stored_circles(){
}
1021 1022 1023 1024 1025 1026

void Render_alternate::release(){
    std::cout << "release" << std::endl;
}

void Render_alternate::draw_text_value(long int id,double text, double y){
Thibault Soucarre's avatar
Thibault Soucarre committed
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
    if(y!=-1){
        Variable_text_ buf;
        buf.y=y;
        buf.value=text;
       // printf("adding %f at %f for %p\n", text, y, (void*)id);
        _variable_texts[id]=buf;
    }else{
        //it's an update
        Variable_text_ buf=_variable_texts[id];
        buf.value=text;
        //printf("updating %f at %f for %p\n", text, y, (void*)id);
        _variable_texts[id]=buf;
    }
1040 1041
}

Thibault Soucarre's avatar
Thibault Soucarre committed
1042

1043 1044 1045 1046 1047 1048 1049 1050
void Render_alternate::show_minimap(){
}

/*!
 * \brief draws the vertical helper line
 */

void Render_alternate::draw_vertical_line(){
1051
    glm::mat4 mvp;
Thibault Soucarre's avatar
Thibault Soucarre committed
1052 1053 1054 1055 1056 1057 1058
    if(vertical_line==0)
        return;
    double vertex[4] = {trace_to_render_x(vertical_line),
                        0.0,
                        trace_to_render_x(vertical_line),
                        Info::Render::height};
    double colors[6] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0};
1059 1060 1061
    //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "modelview"), 1, GL_FALSE, glm::value_ptr(_modelview));
    //glUniformMatrix4fv(glGetUniformLocation(_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
    mvp = _projection * _modelview;
1062
    glUniformMatrix4fv(glGetUniformLocation(_shader->getProgramID(), "MVP"), 1, GL_FALSE, glm::value_ptr(mvp));
Thibault Soucarre's avatar
Thibault Soucarre committed
1063 1064 1065 1066 1067 1068 1069
    glVertexAttribPointer(0, 2, GL_DOUBLE, GL_FALSE, 0, vertex);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(1, 3, GL_DOUBLE, GL_FALSE, 0, colors);
    glEnableVertexAttribArray(1);
    glDrawArrays(GL_LINES, 0, 2);
    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);
1070

1071 1072 1073 1074 1075 1076
}

/*!
 * \brief slot connected to the simple click event
 */
void Render_alternate::update_vertical_line(){
Thibault Soucarre's avatar
Thibault Soucarre committed
1077 1078 1079 1080 1081
    if (_mouse_pressed_inside_container)
            set_vertical_line(0);
    else
        set_vertical_line(render_to_trace_x( screen_to_render_x(_mouse_x)));
    updateGL();
1082 1083 1084 1085 1086 1087
}

/*!
     * \brief set the vertical line offset
     * \param l the line offset.
     */
Thibault Soucarre's avatar
Thibault Soucarre committed
1088 1089 1090
void Render_alternate::set_vertical_line(Element_pos new_coord){
    if(new_coord==vertical_line)vertical_line=0;
    else vertical_line=new_coord;
1091
}
Thibault Soucarre's avatar
Thibault Soucarre committed
1092 1093 1094 1095 1096

Element_pos Render_alternate::get_vertical_line(){
        return vertical_line;
}