Core.cpp 37.3 KB
Newer Older
Mathieu Faverge's avatar
Mathieu Faverge committed
1
/*
Mathieu Faverge's avatar
Mathieu Faverge committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
 ** 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".
 **
 ** 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.
 **
 ** 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.
 **
 ** 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
 **        - VUCHENER Clément
 **
 */
43
/*!
44
 *\file Core.cpp
45 46
 *\brief This is the console interface C source code.
 */
47 48 49 50
#include <queue>
#include <string>
#include <iostream>
#include <fstream>
51
#include <sstream>
52 53 54 55
#include <list>
#include <map>
#include <vector>
#include <stack>
Augustin Degomme's avatar
Augustin Degomme committed
56
#ifndef WIN32
Mathieu Faverge's avatar
Mathieu Faverge committed
57 58 59 60 61
#include <cmath>
#include <unistd.h>
#if defined(HAVE_GETOPT_H)
#include <getopt.h>
#endif  /* defined(HAVE_GETOPT_H) */
Augustin Degomme's avatar
Augustin Degomme committed
62 63

#else
64 65 66
#if !defined (__MINGW32__)
#define sscanf sscanf_s
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
67
#include <core/getopt.h>
Augustin Degomme's avatar
Augustin Degomme committed
68 69
#endif

70 71
/* -- */
#include <QObject>
72 73 74 75 76
//#include <QtUiTools>/* for the run-time loading .ui file */
#include <QTextCodec>
#include <QTime>
#include <QDir>
#include <QGLWidget>/* for the OpenGL Widget */
77 78
#include <QMutex>
#include <QThread>
79 80
#include <QProcess>

81
/* -- */
82
#include "interface/Interface.hpp"
83
#include "common/common.hpp"
84
#include "common/Info.hpp"
85 86
#include "common/Errors.hpp"
#include "common/Tools.hpp"
Mathieu Faverge's avatar
Mathieu Faverge committed
87
#include "common/Session.hpp"
88
#include "common/Message.hpp"
Mathieu Faverge's avatar
Mathieu Faverge committed
89
#include "common/Palette.hpp"
90
#include "common/Session.hpp"
91
/* -- */
92 93 94
#include "render/Geometry.hpp"
#include "render/Hook_event.hpp"
#include "render/Ruler.hpp"
95
#include "render/GanttDiagram.hpp"
96
#include "render/Render.hpp"
97
#include "render/Render_svg.hpp"
98 99 100 101 102 103 104 105 106 107 108 109 110
/* -- */
#include "trace/values/Values.hpp"
#include "trace/tree/Interval.hpp"
#include "trace/tree/Node.hpp"
#include "trace/tree/BinaryTree.hpp"
#include "trace/EntityValue.hpp"
#include "trace/EntityTypes.hpp"
#include "trace/Entitys.hpp"
#include "trace/Trace.hpp"
#include "trace/DrawTree.hpp"
#include "trace/DrawTrace.hpp"
/* -- */
#include "parser/Parser.hpp"
111 112
#include "parser/ParserFactory.hpp"
#include "parser/ParsingThread.hpp"
113 114 115
/* -- */
#include "statistics/Stats_window.hpp"
/* -- */
Augustin Degomme's avatar
Augustin Degomme committed
116
#include "interface/Node_select.hpp"
117 118
#include "interface/Interface_graphic.hpp"
#include "core/Core.hpp"
119
/* -- */
120
#ifdef VITE_ENABLE_VBO
121 122 123 124 125
#include "render/Render_alternate.hpp"
#else
#include "render/Render_opengl.hpp"
#endif

126 127 128 129 130 131 132
#ifdef WIN32
#include <direct.h>
#else
#include <sys/stat.h>
#include <sys/types.h>

#endif
133

Augustin Degomme's avatar
Augustin Degomme committed
134 135 136 137 138
#ifdef USE_MPI
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#endif

139
using namespace std;
140

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

143 144 145 146 147 148 149 150 151 152
/***********************************
 *
 *
 *
 * Constructor and destructor.
 *
 *
 *
 **********************************/

153 154
Core::Core(int &argc, char ** argv)
{
Mathieu Faverge's avatar
Mathieu Faverge committed
155 156
    /*
     * graphic_app is used if a graphical interface is used
157 158
     * console_app is used if we only care about the console interface
     */
159 160
    graphic_app = nullptr;
    console_app = nullptr;
161

162
    /* Qt uses the default system encoding for QString (used when opening a file) */
François Trahay's avatar
François Trahay committed
163
#if QT_VERSION < 0x050000
164
    QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
François Trahay's avatar
François Trahay committed
165
#endif
166
    /*
Mathieu Faverge's avatar
Mathieu Faverge committed
167
     * Store application name and current directory
168 169 170
     */
    _run_env[0] = new QString(QDir::currentPath().toStdString().c_str());
    _run_env[1] = new QString(argv[0]);
171

172
    /* Initialize global variable */
173 174 175
    _main_window   = nullptr;
    _render_opengl = nullptr;
    _trace         = nullptr;
176 177
    _is_window_displayed = false;
    _is_trace_loaded     = false;
178

179 180 181
    /* Define the visible interval */
    _time_start = 0.;
    _time_end   = 0.;
182

183 184 185
    /* define which interface will receive messages */
    /* MathieuTOmyself: No idea what is this */
    Message::set_interface(this);
186

187
    /* Set the options according to the parameters given
Mathieu Faverge's avatar
Mathieu Faverge committed
188 189
     * Warning: Work on a copy of argv to keep parameter
     * that could be usefull to boost or Qt, as psn
190
     * on Mac for example */
191
    _state = get_options(argc, argv);
Mathieu Faverge's avatar
Mathieu Faverge committed
192

Mathieu Faverge's avatar
Mathieu Faverge committed
193 194 195
#ifdef USE_MPI
    boost::mpi::environment env(argc, argv);
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
196

197
    /* Create the Qt application */
Mathieu Faverge's avatar
Mathieu Faverge committed
198
    if ( (_state != _STATE_SPLITTING  ) &&
199 200 201 202 203
         (_state != _STATE_EXPORT_FILE) ) {
        graphic_app = new QApplication(argc, argv);
    }
    else {
        console_app = new QCoreApplication(argc, argv);
204
    }
Mathieu Faverge's avatar
Mathieu Faverge committed
205

Mathieu Faverge's avatar
Mathieu Faverge committed
206 207 208
    /* Trick to avoid problems with menus not showing up in Qt5 */
    QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar);

209
    /* Start to launch actions */
210
    launch_action(_state, nullptr);
211 212 213
}


214
Core::~Core(){
215

216
    if( _trace != nullptr )
217
        delete _trace;
218

219
    if ( _run_env[0] != nullptr )
220 221
        delete _run_env[0];

222
    if ( _run_env[1] != nullptr )
223 224
        delete _run_env[1];

225
    if ( _render_opengl != nullptr ) {
226
        _render_opengl->release();
227 228
        delete _render_opengl;
    }
229

230
    /* Qt desallocates _main_window and _render_opengl automatically */
Olivier Lagrasse's avatar
Olivier Lagrasse committed
231
    Message::kill();
232 233
    if ( console_app != nullptr ) delete console_app;
    if ( graphic_app != nullptr ) delete graphic_app;
234 235
}

236 237 238 239 240 241 242 243 244
/***********************************
 *
 * The command line parameter processing functions.
 *
 **********************************/
#define GETOPT_STRING "t:e:c:i:s:h"

#if defined(HAVE_GETOPT_LONG)
static struct option long_options[] =
Mathieu Faverge's avatar
Mathieu Faverge committed
245 246 247 248 249 250 251 252 253
{
    {"interval",    required_argument,  0, 't'},
    {"export",      required_argument,  0, 'e'},
    {"load_containers_config",    required_argument,  0, 'c'},
    {"input",       required_argument,  0, 'i'},
    {"split",       required_argument,  0, 's'},
    {"help",        no_argument,        0, 'h'},
    {0, 0, 0, 0}
};
254 255 256 257 258 259 260 261 262
#endif

int Core::get_options(int &argc, char **argv)
{
    int state = 0;
    int opt = 0;
    int c;
    int largc;
    char **largv;
Mathieu Faverge's avatar
Mathieu Faverge committed
263

264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
    /* Ignore any -psn_%d_%d argument, which is Mac OS specific */
    largc = 0;
    largv = (char**)calloc(argc+1, sizeof(char**));
    for(c = 0; c < argc; c++) {
        if( strncmp(argv[c], "-psn", 4) )
            largv[largc++] = argv[c];
    }

    // No parameters, launch the window interface
    if( largc == 1 ){
        state = _STATE_LAUNCH_GRAPHICAL_INTERFACE;
        goto cleanup;
    }

    do
Mathieu Faverge's avatar
Mathieu Faverge committed
279
    {
280
#if defined(HAVE_GETOPT_LONG)
Mathieu Faverge's avatar
Mathieu Faverge committed
281 282
        c = getopt_long_only(largc, largv, "",
                             long_options, &opt);
283
#else
Mathieu Faverge's avatar
Mathieu Faverge committed
284 285
        c = getopt(largc, largv, GETOPT_STRING);
        (void) opt;
286 287
#endif  // defined(HAVE_GETOPT_LONG)

Mathieu Faverge's avatar
Mathieu Faverge committed
288 289 290 291 292 293 294
        switch(c) {
        case 't' :
            double t1, t2;
            // Only the end
            if( optarg[0] == ':' ) {
                if ( sscanf( optarg, ":%lf", &t2) == 1 ) {
                    _time_end   = t2;
295
                } else {
Mathieu Faverge's avatar
Mathieu Faverge committed
296 297 298
                    cerr << QObject::tr("Interval is not in the correct format [%d:%d]").toStdString() << endl;
                    state=_STATE_DISPLAY_HELP;
                    goto cleanup;
299
                }
Mathieu Faverge's avatar
Mathieu Faverge committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
            } else {
                int ret = sscanf( optarg, "%lf:%lf", &t1, &t2);
                switch( ret ) {
                case 2:
                    _time_end   = t2;
                case 1 :
                    _time_start = t1;
                    break;
                case 0:
                    cerr << QObject::tr("Interval is not in the correct format [%d:%d]").toStdString() << endl;
                    state=_STATE_DISPLAY_HELP;
                    goto cleanup;
                }
            }
            break;
315

Mathieu Faverge's avatar
Mathieu Faverge committed
316 317 318 319
        case 'e' :
            _path_to_export = optarg;
            state = _STATE_EXPORT_FILE;
            break;
320

Mathieu Faverge's avatar
Mathieu Faverge committed
321 322
        case 'i' :
            _file_opened = optarg;
323 324
            if (state == 0)
                state = _STATE_OPEN_FILE;
Mathieu Faverge's avatar
Mathieu Faverge committed
325
            break;
326

Mathieu Faverge's avatar
Mathieu Faverge committed
327 328 329 330 331 332
        case 's' :
            // We want to split the file and save its parts
            _file_opened = optarg;
            Info::Splitter::split=true;
            if (state == 0) state = _STATE_SPLITTING ;
            break;
333

Mathieu Faverge's avatar
Mathieu Faverge committed
334 335 336
        case 'h' :
            state=_STATE_DISPLAY_HELP;
            goto cleanup;
337

Mathieu Faverge's avatar
Mathieu Faverge committed
338 339 340
        case 'c' :
            _xml_config_file = optarg;
            break;
341

Mathieu Faverge's avatar
Mathieu Faverge committed
342 343 344 345
        default:
            continue;
        }
    } while(-1 != c);
346 347

    if(optind < argc)
Mathieu Faverge's avatar
Mathieu Faverge committed
348 349 350 351
    {
        _file_opened = largv[optind];
        if (state == 0) state = _STATE_OPEN_FILE;
    }
352

Mathieu Faverge's avatar
Mathieu Faverge committed
353
  cleanup:
354 355 356
    free(largv);
    return state;
}
357

358 359 360 361 362 363 364 365 366 367
/***********************************
 *
 *
 *
 * Running function.
 *
 *
 *
 **********************************/

368
bool Core::draw_trace(const string & filename, const int format) {
369
    parser = nullptr;
370
    DrawTrace  drawing_ogl;
371
    bool killed=false;
François Trahay's avatar
François Trahay committed
372

373
    QTime         time_elapsed;
374
    ostringstream buf_txt;
375
    int           time_buf = 0;
376

377
    // Select the Parser in function of the file's extension
François Trahay's avatar
François Trahay committed
378
    if(! ParserFactory::create(&parser, filename)){
Mathieu Faverge's avatar
Mathieu Faverge committed
379 380 381
        *Message::get_instance() << QObject::tr("Error : parser not found for input file").toStdString() << Message::ende;
        return false;
    }
382

383
    // Set application in working state
384 385
    if (_DRAW_OPENGL == format)
        QApplication::setOverrideCursor(Qt::WaitCursor);
386

387 388
    if (_DRAW_SVG == format) {
    }
389
    else if(_STATE_SPLITTING!=format){
390
        // We add the filename to the recent files opened list
391
        Session::add_recent_file(QFileInfo(filename.c_str()).absoluteFilePath());
392 393
        _main_window->update_recent_files_menu();
    }
François Trahay's avatar
François Trahay committed
394

395
    if (nullptr == _trace) { /* no trace is loaded, parse the file */
François Trahay's avatar
François Trahay committed
396

397 398 399 400 401
        /* Init data */
        Info::Entity::x_min          = 0;
        Info::Entity::x_max          = 0;
        Info::Render::_x_min_visible = 0;
        Info::Render::_x_max_visible = 0;
Mathieu Faverge's avatar
Mathieu Faverge committed
402

403
        _trace = new Trace();
Mathieu Faverge's avatar
Mathieu Faverge committed
404

405
        // Init of the thread
Mathieu Faverge's avatar
Mathieu Faverge committed
406 407 408
        _finished = new QWaitCondition();
        _closed   = new QWaitCondition();
        _mutex    = new QMutex();
Mathieu Faverge's avatar
Mathieu Faverge committed
409

410
        QThread thread;
Mathieu Faverge's avatar
Mathieu Faverge committed
411

412
        ParsingThread pt(parser, _trace, _finished,_closed, _mutex);
Mathieu Faverge's avatar
Mathieu Faverge committed
413

414 415
        pt.moveToThread(&thread);
        qRegisterMetaType<std::string>("std::string");
Mathieu Faverge's avatar
Mathieu Faverge committed
416 417 418 419 420 421 422 423 424 425 426 427
        pt.connect((const QObject*)this,
                   SIGNAL(run_parsing()),
                   SLOT(run()));

        pt.connect((const QObject*)this,
                   SIGNAL(build_finished(bool)),
                   SLOT(finish_build(bool)));
        //in case of splitting
        pt.connect((const QObject*)this,
                   SIGNAL(dump(std::string,std::string)),
                   SLOT(dump(std::string,std::string)));

428
        int loaded = 0;
429
        float loaded_f = 0.0f;/* floating value of the loading file state. (between 0 and 1) */
Mathieu Faverge's avatar
Mathieu Faverge committed
430

431
        if(_main_window != nullptr) { // If we have a window we show a progress bar
432
            _main_window->init_parsing(filename);
433
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
434 435

#if defined(USE_ITC) && defined(BOOST_SERIALIZE)
Augustin Degomme's avatar
Augustin Degomme committed
436 437
        if(Info::Splitter::path.empty())Info::Splitter::path=QFileInfo(_file_opened.c_str()).dir().path().toStdString();
        if(Info::Splitter::filename.empty())Info::Splitter::filename=QFileInfo(_file_opened.c_str()).baseName().toStdString();
Mathieu Faverge's avatar
Mathieu Faverge committed
438

Augustin Degomme's avatar
Augustin Degomme committed
439
        if(Info::Splitter::xml_filename.empty() && !_xml_config_file.empty())Info::Splitter::xml_filename=_xml_config_file;
440 441 442
        if(Info::Splitter::split==true){
            std::stringstream str;
            str<<Info::Splitter::path<<"/"<<Info::Splitter::filename;
Mathieu Faverge's avatar
Mathieu Faverge committed
443
#ifdef WIN32
444
            _mkdir(str.str().c_str());
Mathieu Faverge's avatar
Mathieu Faverge committed
445 446 447
#else
            mkdir(str.str().c_str(), 01777);
#endif
448
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
449

Augustin Degomme's avatar
Augustin Degomme committed
450
        if((Info::Splitter::_x_max==0.0)&&(Info::Splitter::_x_min==0.0)){
Mathieu Faverge's avatar
Mathieu Faverge committed
451

452
#if defined(USE_MPI)
Mathieu Faverge's avatar
Mathieu Faverge committed
453

Augustin Degomme's avatar
Augustin Degomme committed
454
            if (_world.rank() == 0) {
Mathieu Faverge's avatar
Mathieu Faverge committed
455

Augustin Degomme's avatar
Augustin Degomme committed
456 457 458 459 460 461 462 463
                double min = _time_start;
                double max = 0;
                if(_time_end == 0.) {
                    max = _trace->get_max_date().get_value();
                }
                else {
                    max =_time_end;
                }
Mathieu Faverge's avatar
Mathieu Faverge committed
464

Augustin Degomme's avatar
Augustin Degomme committed
465 466 467
                double interval = (max-min)/ _world.size();
                for(int i=1;i<_world.size(); i++){
                    //send the new working interval for each node
Mathieu Faverge's avatar
Mathieu Faverge committed
468
                    // double out_msg[2]={min+i*interval,min+(i+1)*interval};
Augustin Degomme's avatar
Augustin Degomme committed
469 470
                    _world.send(i, 0,min+i*interval );
                    _world.send(i, 1,min+(i+1)*interval );
Mathieu Faverge's avatar
Mathieu Faverge committed
471 472 473

                }
                //0 displays the first interval
Augustin Degomme's avatar
Augustin Degomme committed
474 475 476 477 478 479 480
                _time_start=min;
                _time_end=min+interval;

            } else {
                double msg[2];
                _world.recv(0, 0, msg[0]);
                _world.recv(0, 1, msg[1]);
481 482
                _time_start = msg[0];
                _time_end   = msg[1];
Augustin Degomme's avatar
Augustin Degomme committed
483
            }
484
#endif /* defined(USE_MPI) */
Mathieu Faverge's avatar
Mathieu Faverge committed
485

Augustin Degomme's avatar
Augustin Degomme committed
486
            Info::Splitter::_x_min = _time_start;
487

Augustin Degomme's avatar
Augustin Degomme committed
488 489 490 491 492 493
            if(_time_end == 0.) {
                Info::Splitter::_x_max = _trace->get_max_date().get_value();
            }
            else {
                Info::Splitter::_x_max =_time_end;
            }
494
        }
495
#endif /* defined(USE_ITC) && defined(BOOST_SERIALIZE) */
Mathieu Faverge's avatar
Mathieu Faverge committed
496

497
        thread.start();
498 499
        time_elapsed.start();
        buf_txt.str("");
500
        bool parsing_finished=false;
501
        emit run_parsing();
Mathieu Faverge's avatar
Mathieu Faverge committed
502

503
        while( !parsing_finished && !killed) {
Mathieu Faverge's avatar
Mathieu Faverge committed
504

505
            if(!parser->is_end_of_parsing()){
Mathieu Faverge's avatar
Mathieu Faverge committed
506 507
                //locks the mutex and automatically unlocks it when going out of scope
                QMutexLocker locker(_mutex);
508
                // We wait 1 second
Mathieu Faverge's avatar
Mathieu Faverge committed
509 510 511 512 513
                _finished->wait(_mutex, 1000);
            }
            killed=pt.is_killed();
            if(killed)break;
            loaded_f = parser->get_percent_loaded();
514
            loaded   = (int)(loaded_f*100.0f);
515

516
            if(parser->is_end_of_parsing() && !killed){
Mathieu Faverge's avatar
Mathieu Faverge committed
517
                if(!_xml_config_file.empty() && _trace->get_view_root_containers()->empty()){//if we have a partial loading, process it here, but only once
518
                    launch_action(_DRAW_OPENGL_PARTIAL,nullptr);
Mathieu Faverge's avatar
Mathieu Faverge committed
519
                }
520

Mathieu Faverge's avatar
Mathieu Faverge committed
521 522
                QMutexLocker locker(_mutex);
                if(format != _STATE_SPLITTING)   {
523 524 525
                    emit build_finished(true);
                }
                else{
Mathieu Faverge's avatar
Mathieu Faverge committed
526
#if defined(USE_ITC) && defined(BOOST_SERIALIZE)
527
                    emit dump(Info::Splitter::path, Info::Splitter::filename);
Mathieu Faverge's avatar
Mathieu Faverge committed
528 529 530 531 532 533

#elif defined(USE_ITC)
                    *Message::get_instance() << QObject::tr("Splitting was asked but BOOST_SERIALIZE flag was not set ").toStdString() << Message::ende;
#elif defined(BOOST_SERIALIZE)
                    *Message::get_instance() << QObject::tr("Splitting was asked but USE_ITC flag was not set ").toStdString() << Message::ende;
#else
534
                    *Message::get_instance() << QObject::tr("Splitting was asked but neither USE_ITC nor BOOST_SERIALIZE flags were set ").toStdString() << Message::ende;
Mathieu Faverge's avatar
Mathieu Faverge committed
535
#endif
536 537 538
                }
                _closed->wait(_mutex);

539
                parsing_finished=true;
540
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
541 542 543

            cout << QObject::tr("Loading of the trace : ").toStdString() << loaded << "%" ;

544 545 546 547
            if (loaded_f>0.0f){
                // divided by to have in second 1000 since time_elapsed.elapsed() returns ms */
                time_buf = (int)(time_elapsed.elapsed() * (1.0 / loaded_f - 1.0) / 1000);
                buf_txt.str(""); // Reinitialisation
Mathieu Faverge's avatar
Mathieu Faverge committed
548

549
                if (time_buf>=3600){ /* convert second in hour and min */
550
                    buf_txt << "Parsing... Remaining: " <<  time_buf/3600 << " h " << (time_buf%3600)/60 << " min " << time_buf%60 << " s";
551 552
                }
                else if (time_buf>=60){/* convert second in min */
553
                    buf_txt << "Parsing... Remaining: " << time_buf/60 << " min " << time_buf%60 << " s";
554 555
                }
                else{
556 557
                    buf_txt << "Parsing... Remaining: " << time_buf << " s";
                }
Mathieu Faverge's avatar
Mathieu Faverge committed
558

559
                cout << "  ~  " << buf_txt.str();
560
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
561

562
            cout << endl;
Mathieu Faverge's avatar
Mathieu Faverge committed
563 564


565
            if(_main_window != nullptr) { // If we have a window we show a progress bar
566
                _main_window->update_progress_bar(QString(buf_txt.str().c_str()), loaded);
567
                QApplication::processEvents();
Mathieu Faverge's avatar
Mathieu Faverge committed
568

569
                if(_main_window->is_parsing_canceled()) {
Mathieu Faverge's avatar
Mathieu Faverge committed
570 571 572
                    cout << QObject::tr("Canceled at ").toStdString() << loaded << "%" << endl;
                    parser->set_canceled();
                    *Message::get_instance() << QObject::tr("The trace opening was canceled by the user at ").toStdString() << loaded << "%" << Message::ende;
573
                    //locks the mutex and automatically unlocks it when going out of scope
574 575 576

                    emit build_finished(true);
                    QMutexLocker locker(_mutex);
Mathieu Faverge's avatar
Mathieu Faverge committed
577
                    _closed->wait(_mutex);
578 579 580
                    break; // Quit the loop
                }
            }
581
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
582
        delete parser;
583
        parser=nullptr;
584
        thread.quit();
585 586
        thread.wait();

587
        Error::print_numbers();
François Trahay's avatar
François Trahay committed
588
        Error::flush("log.txt");
589

590
        // Wait for the end of the thread
591 592
        //while(!thread.wait()) {
        //}
593

594
        if(_main_window != nullptr) { // If we have a window we show a progress bar
595 596 597
            _main_window->end_parsing();
        }

598
        delete parser;
599
        parser=nullptr;
François Trahay's avatar
François Trahay committed
600 601 602 603
    }
    else if ( _file_opened != filename) {/* just check if execution is normal */
        *Message::get_instance() << "Try to use file: " << filename << " instead of a previous parsed file: " << _file_opened << Message::ende;
    }
604
    if(_trace!=nullptr && !killed){
605
        if (Info::Render::_x_min_visible == Info::Render::_x_max_visible){ // first time
606 607
            _trace->set_interval_constrained(new Interval(0,_trace->get_max_date()));
        }else{
Mathieu Faverge's avatar
Mathieu Faverge committed
608
            _trace->set_interval_constrained(new Interval(Info::Render::_x_min_visible, Info::Render::_x_max_visible));
609
        }
Augustin Degomme's avatar
Augustin Degomme committed
610

Mathieu Faverge's avatar
Mathieu Faverge committed
611
        if(!_xml_config_file.empty() && _trace->get_view_root_containers()->empty()){//if we have a partial loading, process it here, but only once
612
            launch_action(_DRAW_OPENGL_PARTIAL,nullptr);
Mathieu Faverge's avatar
Mathieu Faverge committed
613
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
614
        if (_DRAW_OPENGL == format) {
615
            GanttDiagram render(_render_opengl);
616
            drawing_ogl.build(&render, _trace);
617 618 619 620 621 622
            _render_opengl->build();
            // _render_opengl->updateGL();
            _render_opengl->refresh_scroll_bars();
            _file_opened = filename;/* store filename for a future export */
        }
        else if (_DRAW_SVG == format) {
623

624
            Render_svg *rsvg = new Render_svg(&_path_to_export);
625
            Element_pos buf_min, buf_max;
626

627 628 629
            /* Store current view */
            buf_min = Info::Entity::x_min;
            buf_max = Info::Entity::x_max;
630

631 632
            /* Change current view to fit the user zoom */
            Info::Render::_x_min_visible = _time_start;
633

634 635 636 637 638
            if(_time_end == 0.) {
                Info::Render::_x_max_visible = _trace->get_max_date().get_value();
                Info::Entity::x_max = Info::Render::_x_max_visible;
            }
            else {
Mathieu Faverge's avatar
Mathieu Faverge committed
639
                Info::Render::_x_max_visible = _time_end;
640
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
641

642 643 644 645 646 647 648
            if(Info::Entity::x_max >= Info::Render::_x_min_visible) {
                Info::Entity::x_min = Info::Render::_x_min_visible;
            }
            if(_time_end > _time_start && _time_end <= Info::Entity::x_max) {
                Info::Entity::x_max = _time_end;
            }
            cout << "Exporting trace to " << _path_to_export<<" ... Please Wait " << endl ;
649
            GanttDiagram render(rsvg);
650
            drawing_ogl.build(&render, _trace);
651

652
            delete(rsvg);/* Release the svg render */
653

654 655 656
            /* Restore previous view */
            Info::Entity::x_min = buf_min;
            Info::Entity::x_max = buf_max;
657

658 659 660 661 662
        }else if (_STATE_SPLITTING != format){/* error */
            *Message::get_instance() << "No kind of render recognized" << Message::ende;
            return false;
        }
        //   std::cout << _trace->get_max_date().get_value() << __FILE__ << __LINE__ << std::endl;
663 664


665 666
        _is_trace_loaded = true;
        if (_DRAW_OPENGL == format)QApplication::restoreOverrideCursor();
667

668 669
        return true;
    }else{
Mathieu Faverge's avatar
Mathieu Faverge committed
670 671 672
        // *Message::get_instance() << "Parsing was not finished properly" << Message::ende;
        _is_window_displayed=false;
        emit close_windows();
673
        return false;
Mathieu Faverge's avatar
Mathieu Faverge committed
674
    }
675 676 677
}


678
int Core::run(){
679 680 681
    /*
     * If a window is displayed, enter in the Qt event loop.
     */
Johnny Jazeix's avatar
Johnny Jazeix committed
682
    if (_is_window_displayed){
683
        return graphic_app->exec();
684 685 686 687
    }
    else{/* else, quit the application */
        return EXIT_SUCCESS;
    }
688 689
}

François Trahay's avatar
François Trahay committed
690 691


692

693
void Core::launch_action(int state, void* arg) {
694

Olivier Lagrasse's avatar
Olivier Lagrasse committed
695
    DrawTrace buf;
696
    QGLFormat format (QGL::HasOverlay);
697
#ifdef USE_QT5
698 699 700 701 702 703
    /* Use compatibility profile for renderText function from QGLWidget, that need deprecated function.
     It should be replaced so we can use Core Profile.
     Version 3.0 is the minimum. If would be better to find a function giving the most recent version available. */
    format.setVersion(3,0);
    //format.setProfile(QGLFormat::CoreProfile);
    format.setProfile(QGLFormat::CompatibilityProfile);
704
#endif
705
    switch(state) {
706 707

    case _STATE_DISPLAY_HELP :
708
        display_help ();
709
        break;
710

Olivier Lagrasse's avatar
Olivier Lagrasse committed
711
    case _STATE_OPEN_FILE:
712 713
        message << QObject::tr("Opening the file: ").toStdString ()+_file_opened
                << Message::endi;
714

715
    case _STATE_LAUNCH_GRAPHICAL_INTERFACE :
716

Thomaas Herault's avatar
Thomaas Herault committed
717 718
        waitGUIInit = new QEventLoop(this);

Olivier Lagrasse's avatar
Olivier Lagrasse committed
719 720
        _main_window = new Interface_graphic (this);/* launch the window interface */
        Message::set_interface (_main_window);/* define which interface will receive messages */
721

722
        _main_window->connect((const QObject*)this,
Mathieu Faverge's avatar
Mathieu Faverge committed
723 724
                              SIGNAL(close_windows()),
                              SLOT(on_quit_triggered()));
Olivier Lagrasse's avatar
Olivier Lagrasse committed
725
        //   format.setOverlay(true);
726
#ifdef VITE_ENABLE_VBO
727 728
        _render_opengl = new Render_alternate (this, _main_window, format);
#else
Olivier Lagrasse's avatar
Olivier Lagrasse committed
729
        _render_opengl = new Render_opengl (this, _main_window, format);
730
#endif
731

732
        if ( nullptr == _render_opengl){
733 734
            message << QObject::tr("Cannot allocate memory for an OpengGL instance").toStdString ()
                    << Message::ende;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
735 736
            break;
        }
737

738
        if (nullptr == _render_opengl->context()){
739 740
            message << QObject::tr("Cannot allocate an OpengGL context").toStdString ()
                    << Message::ende;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
741 742
            break;
        }
743

Olivier Lagrasse's avatar
Olivier Lagrasse committed
744
        if (false == _render_opengl->isValid()){
745 746
            message << QObject::tr("Invalid context: OpenGL is not supported on your system").toStdString ()
                    << Message::ende;
Mathieu Faverge's avatar
Mathieu Faverge committed
747
        }
748

Olivier Lagrasse's avatar
Olivier Lagrasse committed
749 750
        // if (false == _render_opengl->format().hasOverlay ()){
        //     /* If no overlay was created, check the original format */
751

Olivier Lagrasse's avatar
Olivier Lagrasse committed
752 753 754 755 756
        //     if (false == _render_opengl->context()->requestedFormat().hasOverlay())
        //         message <<  QObject::tr("No overlay format originally created").toStdString () << Message::endw;
        //     else
        //         message <<  QObject::tr("An overlay format was originally asked, but was not created").toStdString () << Message::endw;
        // }
757 758
        _main_window->bind_render_area((QGLWidget*)_render_opengl);

Thomaas Herault's avatar
Thomaas Herault committed
759 760
        /* Wait that the open gl renderer calls waitGUIInit->quit() to load the file */
        waitGUIInit->exec();
761
        if ( _STATE_OPEN_FILE == state ){
Olivier Lagrasse's avatar
Olivier Lagrasse committed
762
            _main_window->opening_file(_file_opened);/* Must be called after binding the render area to the main window */
763
            if( false == draw_trace(_file_opened, _DRAW_OPENGL) ){
764 765
                message << QObject::tr("Draw trace failed").toStdString ()
                        << Message::ende;
Mathieu Faverge's avatar
Mathieu Faverge committed
766 767
                break;
            }
Olivier Lagrasse's avatar
Olivier Lagrasse committed
768
        }
769

770 771 772 773 774 775
        // If -t has been set, we define the interval to zoom in
        if ( _time_start != 0 && _time_end == 0. )
            _time_end = _trace->get_max_date().get_value();

        if ( _time_end != 0. ) {
            _render_opengl->apply_zoom_on_interval(_time_start, _time_end);
Mathieu Faverge's avatar
Mathieu Faverge committed
776
        }
777

778
        _is_window_displayed = true;
779
        break;
780

Mathieu Faverge's avatar
Mathieu Faverge committed
781
    case _STATE_SPLITTING:
782 783 784
        *Message::get_instance() << "Splitting " << _file_opened << Message::endi;
        draw_trace(_file_opened, _STATE_SPLITTING);
        break;
Mathieu Faverge's avatar
Mathieu Faverge committed
785

786

787
    case _STATE_OPEN_FILE_IN_AN_INTERVAL:
788
        launch_action(_STATE_OPEN_FILE, nullptr);
789 790
        break;

Mathieu Faverge's avatar
Mathieu Faverge committed
791
    case _STATE_RELEASE_RENDER_AREA:
Mathieu Faverge's avatar
Mathieu Faverge committed
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
    {
        /*if(parser!=NULL ){
         parser->set_canceled();
         //locks the mutex and automatically unlocks it when going out of scope
         QMutexLocker locker(_mutex);
         emit build_finished(false);
         emit close_windows();
         while(parser!=NULL)
         _closed->wait(_mutex,100);
         }*/

        if (_render_opengl->unbuild()==false)
            message << "Close file : an error occured with trace releasing." << Message::ende;
        _file_opened.clear();


        if (false == _is_trace_loaded) {
            *Message::get_instance() << "Try to release a render area whereas no file was loaded" << Message::ende;
        } else {
            _is_trace_loaded = false;
        }
813

814
        if (nullptr == _trace) {
Mathieu Faverge's avatar
Mathieu Faverge committed
815 816 817
            *Message::get_instance() << "Try to release a render area whereas no trace is loaded" << Message::ende;
        } else {
            delete _trace;
818
            _trace = nullptr;
Mathieu Faverge's avatar
Mathieu Faverge committed
819
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
820 821 822 823 824 825
        _render_opengl->updateGL();

        /* Release all data */
        Info::release_all();
    }
    break;
826

827
    case _STATE_EXPORT_FILE:
828
    case _STATE_EXPORT_FILE_IN_INTERVAL:
Mathieu Faverge's avatar
Mathieu Faverge committed
829 830 831 832 833
    {
        if (_file_opened.empty()) {
            *Message::get_instance() << "Please to previously open a trace." << Message::endw;
            return;
        }
834

Mathieu Faverge's avatar
Mathieu Faverge committed
835 836 837 838 839 840 841 842 843 844 845 846
        cout << "export of " << _file_opened << " to " << _path_to_export << " between ";
        if(_time_start == 0){
            cout << "the beginning of the trace to ";
        }
        else{
            cout << _time_start << " seconds to ";
        }
        if(_time_end != 0){
            cout << _time_end << " seconds." << endl;
        }
        else{
            cout << "the end of the trace." << endl;
Mathieu Faverge's avatar
Mathieu Faverge committed
847
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
848 849 850 851

        draw_trace(_file_opened, _DRAW_SVG);
    }
    break;
Olivier Lagrasse's avatar
Olivier Lagrasse committed
852

853 854 855
    case _STATE_RENDER_AREA_CHANGE_TRANSLATE:
        _render_opengl->change_translate( *((int*)arg) );
        break;
856

857
    case _STATE_RENDER_AREA_CHANGE_SCALE:
858
        _render_opengl->change_scale( *((Element_pos*)arg) );
859 860
        break;

861 862 863 864
    case _STATE_RENDER_AREA_CHANGE_SCALE_Y:
        _render_opengl->change_scale_y( *((Element_pos*)arg) );
        break;

865 866 867 868
    case _STATE_RENDER_AREA_CHANGE_CONTAINER_SCALE:
        _render_opengl->change_scale_container_state( *((int*)arg) );
        break;

869 870
    case _STATE_RENDER_AREA_REPLACE_SCALE:
        _render_opengl->replace_scale( *((Element_pos*)arg) );
871
        _render_opengl->replace_scale_y( *((Element_pos*)arg) );
872 873 874 875 876 877
        break;

    case _STATE_RENDER_AREA_REPLACE_TRANSLATE:
        _render_opengl->replace_translate( *((Element_pos*)arg) );
        break;

878 879 880 881
    case _STATE_RENDER_AREA_REPLACE_TRANSLATE_Y:
        _render_opengl->replace_translate_y( *((Element_pos*)arg) );
        break;

882 883 884
    case _STATE_RENDER_AREA_REGISTERED_TRANSLATE:
        _render_opengl->registered_translate( *((int*)arg) );
        break;
885

886
    case _STATE_AJUST_SCROLL_BARS:
887 888 889 890
        //        cerr << "console: x_max " << ((Element_pos*)arg)[0] << " | y_max " << ((Element_pos*)arg)[1] << endl;
        _main_window->set_scroll_bars_length( ((Element_pos*)arg)[0], ((Element_pos*)arg)[1] );
        break;

891
    case _STATE_REFRESH_SCROLL_BARS:
892 893 894
        _main_window->linking_scroll_bars( ((Element_pos*)arg)[0], ((Element_pos*)arg)[1] );
        break;

895 896 897 898
    case _STATE_ZOOM_BOX_VALUE:
        _main_window->change_zoom_box_value( *((int*)arg) );
        break;

899
    case _STATE_RENDER_DISPLAY_INFORMATION:
900
        if(_trace != nullptr){
901 902
            buf.display_information(_trace, Info::Render::_info_x, Info::Render::_info_y, Info::Render::_info_accurate);
        }
903
        break;
904

905
    case _STATE_RENDER_UPDATE:
906
        _render_opengl->updateGL();
907
        break;
Mathieu Faverge's avatar
Mathieu Faverge committed
908

Augustin Degomme's avatar
Augustin Degomme committed
909
    case _STATE_CLEAN_RENDER_AREA:
Mathieu Faverge's avatar
Mathieu Faverge committed
910 911 912 913 914 915 916 917 918
    {
        Info::Render::_x_min_visible = 0.0;
        Info::Render::_x_max_visible = 0.0;
        if (_render_opengl->unbuild() == false)
            message << "Close file : an error occured while cleaning the render." << Message::ende;
        _render_opengl->release();
        _render_opengl->updateGL();
    }
    break;
919

920 921 922 923
    case _STATE_RENDER_SHOW_MINIMAP:
        _render_opengl->show_minimap();
        break;

924
    case _STATE_SWITCH_CONTAINERS:
Mathieu Faverge's avatar
Mathieu Faverge committed
925 926 927
    {
        Element_pos yr = ((Element_pos*)arg)[0];
        Element_pos yr2 = ((Element_pos*)arg)[1];
928 929
        const Container* container=nullptr;
        const Container* container2=nullptr;
Mathieu Faverge's avatar
Mathieu Faverge committed
930 931 932
        const Container::Vector *root_containers = _trace->get_view_root_containers();
        if(root_containers->empty())root_containers= _trace->get_root_containers();
        if (!root_containers->empty()){
933 934
            for (const auto &root_container : *root_containers)
                if ((container = buf.search_container_by_position(root_container, yr)))
Mathieu Faverge's avatar
Mathieu Faverge committed
935 936
                    break;

937 938
            for (const auto &root_container : *root_containers)
                if ((container2 = buf.search_container_by_position(root_container, yr2)))
Mathieu Faverge's avatar
Mathieu Faverge committed
939
                    break;
Mathieu Faverge's avatar
Mathieu Faverge committed
940 941


Mathieu Faverge's avatar
Mathieu Faverge committed
942
        }
943

Mathieu Faverge's avatar
Mathieu Faverge committed
944 945 946 947 948
        // If the clic is out
        if (!container)
            return;
        if (!container2)
            return;
Mathieu Faverge's avatar
Mathieu Faverge committed
949

Mathieu Faverge's avatar
Mathieu Faverge committed
950 951 952
        //we found the two children containers, we have to know the depth
        Element_pos xr = ((Element_pos*)arg)[2] * (_trace->get_depth()+1);
        if(xr<0)return;
953

Mathieu Faverge's avatar
Mathieu Faverge committed
954 955 956 957 958
        Element_pos xr2 = ((Element_pos*)arg)[3] * (_trace->get_depth()+1);
        if(xr2<0)return;
        for(int i=0; i < (const_cast<Container*>(container)->get_depth() - xr); i++){
            container= container->get_parent();
        }
959

Mathieu Faverge's avatar
Mathieu Faverge committed
960 961 962
        for(int i=0; i < (const_cast<Container*>(container2)->get_depth() - xr2); i++){
            container2=container2->get_parent();
        }
963

Mathieu Faverge's avatar
Mathieu Faverge committed
964 965 966
        //we cannot switch when containers' parents are not the same
        if( container->get_parent() != container2->get_parent() )
            return;
967

Mathieu Faverge's avatar
Mathieu Faverge committed
968 969
        if( container == container2 )
            return;
970

Mathieu Faverge's avatar
Mathieu Faverge committed
971
        Container* parent= const_cast<Container*>(container->get_parent());
972

Mathieu Faverge's avatar
Mathieu Faverge committed
973
        //printf("we ask to switch %s and %s \n", container->get_name().to_string().c_str(), container2->get_name().to_string().c_str());
974

975
        const std::list<Container*>* children=nullptr;
Mathieu Faverge's avatar
Mathieu Faverge committed
976

977
        if(parent==nullptr){//we switch top level containers
Mathieu Faverge's avatar
Mathieu Faverge committed
978 979 980 981 982 983
            children = _trace->get_view_root_containers();
            if(children->empty()) children = _trace->get_root_containers();
        }else{
            children = new std::list<Container*>(*parent->get_view_children());
            if(children->empty()) children = parent->get_children();
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
984

Mathieu Faverge's avatar
Mathieu Faverge committed
985 986
        std::list<Container*>::const_iterator it= children->begin();
        const std::list<Container*>::const_iterator it_end= children->end();
987
        if(parent!=nullptr){
Mathieu Faverge's avatar
Mathieu Faverge committed
988 989 990 991 992 993 994 995 996 997 998
            parent->clear_view_children();
            for(; it!=it_end; it++){
                if((*it)==container) parent->add_view_child(const_cast<Container*>(container2));
                else if((*it)==container2) parent->add_view_child(const_cast<Container*>(container));
                else parent->add_view_child(*it);
            }
        }else{//for root containers we have to build a new list and fill it
            std::list<Container*>* new_list= new std::list<Container*> ();
            for(; it!=it_end; it++){
                if((*it)==container){
                    new_list->push_back(const_cast<Container*>(container2));
Mathieu Faverge's avatar
Mathieu Faverge committed
999
                }
Mathieu Faverge's avatar
Mathieu Faverge committed
1000 1001
                else if((*it)==container2) new_list->push_back(const_cast<Container*>(container));
                else new_list->push_back(*it);
1002
            }
Mathieu Faverge's avatar
Mathieu Faverge committed
1003 1004
            _trace->set_view_root_containers(*new_list);
        }
1005

Mathieu Faverge's avatar
Mathieu Faverge committed
1006 1007 1008
        Element_pos zoom[2]={Info::Render::_x_min, Info::Render::_x_max};
        Info::Render::_x_min_visible = 0.0;
        Info::Render::_x_max_visible = 0.0;
1009

Mathieu Faverge's avatar
Mathieu Faverge committed
1010
        launch_action(Core:: _STATE_CLEAN_RENDER_AREA);
Mathieu Faverge's avatar
Mathieu Faverge committed
1011
#if defined(USE_ITC) && defined(BOOST_SERIALIZE)
Mathieu Faverge's avatar
Mathieu Faverge committed
1012
        _trace->updateTrace(new Interval(zoom[0], zoom[1]));
Mathieu Faverge's avatar
Mathieu Faverge committed
1013
#endif
Mathieu Faverge's avatar
Mathieu Faverge committed
1014 1015 1016
        draw_trace(get_filename(),Core::_DRAW_OPENGL);
        launch_action(Core:: _STATE_ZOOM_IN_AN_INTERVAL, &zoom);
        launch_action(Core:: _STATE_RENDER_UPDATE);
1017

Mathieu Faverge's avatar
Mathieu Faverge committed
1018 1019
        break;
    }
1020

Mathieu Faverge's avatar
Mathieu Faverge committed
1021
    case _DRAW_OPENGL_PARTIAL:
Mathieu Faverge's avatar
Mathieu Faverge committed
1022 1023 1024 1025 1026 1027 1028 1029 1030
    {
        //_main_window->get_node_select()->set_trace(_trace);
        bool xml_success = _trace->load_config_from_xml(QString(_xml_config_file.c_str()));
        if(!xml_success){
            //std::list<Container *> displayed_containers;
            //_main_window->get_node_select()->build_displayed_nodes(displayed_containers);
            //_trace->set_view_root_containers(displayed_containers);
            //}else{
            message << "Error while parsing" << _xml_config_file << Message::ende;
Mathieu Faverge's avatar
Mathieu Faverge committed
1031 1032
        }
        break;
Mathieu Faverge's avatar
Mathieu Faverge committed
1033 1034 1035 1036 1037 1038
    }
    case _STATE_ZOOM_IN_AN_INTERVAL:
    {
        _render_opengl->apply_zoom_on_interval(((Element_pos*)arg)[0], ((Element_pos*)arg)[1]);
    }
    break;
1039

Mathieu Faverge's avatar
Mathieu Faverge committed
1040
    case _STATE_UPDATE_VARVALUES:
Mathieu Faverge's avatar
Mathieu Faverge committed
1041
    {
1042
        if( nullptr != _trace ) {
Mathieu Faverge's avatar
Mathieu Faverge committed
1043 1044
            std::map<long int, double> var_map = _trace->update_text_variable_values(((Element_pos*)arg)[0]);
            buf.draw_text_variable_values(_render_opengl,&var_map,((Element_pos*)arg)[0]);
Mathieu Faverge's avatar
Mathieu Faverge committed
1045
        }
Mathieu Faverge's avatar
Mathieu Faverge committed
1046 1047
    }
    break;
Mathieu Faverge's avatar
Mathieu Faverge committed
1048 1049

    case _LOAD_DATA:
Mathieu Faverge's avatar
Mathieu Faverge committed
1050
    {
Mathieu Faverge's avatar
Mathieu Faverge committed
1051 1052 1053 1054
        //case where data has to be loaded from serialized files, after a zoom in the preview
        //by default, we do that in another window
        _time_start=Info::Splitter::_x_min;
        _time_end=Info::Splitter::_x_max;
1055
        //_trace->finish();
Mathieu Faverge's avatar
Mathieu Faverge committed
1056

1057 1058 1059 1060 1061
        char args[512];
        sprintf(args,"-t %lf:%lf", _time_start, _time_end);
        QStringList arguments = (QStringList() << args);
        arguments << _file_opened.c_str();
        QString program;
Mathieu Faverge's avatar
Mathieu Faverge committed
1062

1063 1064
        QDir::setCurrent(*_run_env[0]);
        QString run_cmd = *_run_env[1];
Mathieu Faverge's avatar
Mathieu Faverge committed
1065

1066 1067 1068 1069 1070

        if (run_cmd.startsWith("."))
            program = *_run_env[0]+(run_cmd.remove(0,1));
        else
            program = run_cmd;
Mathieu Faverge's avatar
Mathieu Faverge committed
1071

1072 1073 1074 1075 1076
        QProcess new_process;
        new_process.startDetached(program, arguments);

        break;
    }
1077
    default:/* like _STATE_UNKNOWN */
Johnny Jazeix's avatar
Johnny Jazeix committed
1078 1079
        display_help();
        warning(string("Cannot determine the arguments past. Please check the correct syntax."));
François Trahay's avatar
François Trahay committed
1080

1081 1082 1083
    }
}

François Trahay's avatar
François Trahay committed
1084

1085
void Core::display_help(){
1086
    cout << endl
Mathieu Faverge's avatar
Mathieu Faverge committed
1087 1088 1089 1090 1091
         << "Usage: vite [OPTION...] [[-f] inputfile] [-e outputfile] " << endl
         << endl
         << "  -h                 display this help                  " << endl
         << "  -f inputfile       open the inputfile                 " << endl
         << "  -a                 display all the inputfile (Default)" << endl
1092
         << "  -t [T0]:[T1]       display the interval [T0:T1] (Default: T0 = 0 and T1 = Tmax)" << endl
Mathieu Faverge's avatar
Mathieu Faverge committed
1093
         << "  -e outputfile      export the trace file in the svg format to outpufile"        << endl
Mathieu Faverge's avatar
Mathieu Faverge committed
1094
         << "  -c xmlfile         import a list of containers to display from an xml file"        << endl
1095
         << endl;
1096 1097
}

1098

1099 1100 1101 1102 1103 1104 1105 1106 1107
/***********************************
 *
 *
 *
 * Informative message functions.
 *
 *
 *
 **********************************/
1108

1109
void Core::error(const string &s) const{
Olivier Lagrasse's avatar
Olivier Lagrasse committed
1110
    cerr << "ERROR: " << s <<endl;
1111 1112 1113
}


1114
void Core::warning(const string &s) const{
Olivier Lagrasse's avatar
Olivier Lagrasse committed
1115
    cerr << "Warning: "<< s <<endl;
1116 1117
}

1118
void Core::information(const string &s) const{
1119
    cerr << s <<endl;
1120
}
1121

1122
const string Core::get_filename() const{
1123 1124
    return _file_opened;
}
1125

1126
void Core::set_path_to_export(const string& path){
1127 1128 1129
    _path_to_export = path;
}

1130 1131
const QString** Core::get_runenv() const{
    return (const QString**)_run_env;
1132
}