Core.hpp 12.8 KB
Newer Older
Mathieu Faverge's avatar
Mathieu Faverge committed
1 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
/*
** 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.
**
**
Mathieu Faverge's avatar
Mathieu Faverge committed
31
** ViTE developers are (for version 0.* to 1.0):
Mathieu Faverge's avatar
Mathieu Faverge committed
32 33 34 35 36 37 38 39 40 41 42
**
**        - COULOMB Kevin
**        - FAVERGE Mathieu
**        - JAZEIX Johnny
**        - LAGRASSE Olivier
**        - MARCOUEILLE Jule
**        - NOISETTE Pascal
**        - REDONDY Arthur
**        - VUCHENER Clément 
**
*/
43
/*!
44
 *\file interface_console.hpp
45 46
 */

47 48
#ifndef CORE_HPP
#define CORE_HPP
49

50 51 52

//#define WITH_VBO

53 54
class Core;
class Interface_graphic;
55 56 57 58

#ifdef WITH_VBO
class Render_alternate;
#else
59
class Render_opengl;
60 61
#endif

62
class Render_svg;
63
class Trace;
64
#include "render/Render.hpp"
Mathieu Faverge's avatar
Mathieu Faverge committed
65
class Variable;
66

67

68
#include "interface/Interface.hpp"
69

70
/*!
71
 *\brief This class is an terminal interface, it inherited from the Interface interface.
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
72
 */
73
class Core : public Interface{
74

75

76

77
public:
78 79 80 81 82 83

    /***********************************
     *
     * The command line parameter processing functions.
     *
     **********************************/
84
  
85 86 87
    /*!
     *\brief An error state.
     */
88
    static const int _STATE_UNKNOWN = -1;
89 90 91 92
    
    /*!
     *\brief A state which corresponds to display a help text.
     */
93
    static const int _STATE_DISPLAY_HELP = 0;
94 95

    /*!
Johnny Jazeix's avatar
Johnny Jazeix committed
96
     *\brief A state which corresponds to display the trace within a time.
97
     */
98
    static const int _STATE_IN_AN_INTERVAL = 1; // 2^0
99

100 101 102
    /*!
     *\brief A state which corresponds to display a the ViTE window and opening a file.
     */
103
    static const int _STATE_OPEN_FILE = 2; // 2^1
104 105 106 107 108 109 110 111 112

    /*!
     *\brief A state which corresponds to display the trace within a time.
     */
    static const int _STATE_OPEN_FILE_IN_AN_INTERVAL = 3;

    /*!
     *\brief A state which corresponds to an export of file.
     */
113
    static const int _STATE_EXPORT_FILE = 4; // 2^2
114 115 116 117 118

    /*!
     *\brief A state which corresponds to an export of file.
     */
    static const int _STATE_EXPORT_FILE_IN_INTERVAL = 5;
Jule Marcoueille's avatar
Jule Marcoueille committed
119
    
120 121 122 123 124 125
    /*!
     *\brief A state which corresponds to release the OpenGL render area (display the wait screen).
     */
    static const int _STATE_RELEASE_RENDER_AREA = 6;

    /*!
126
     *\brief A state which corresponds to change the render area translation.
127 128 129 130
     */
    static const int _STATE_RENDER_AREA_CHANGE_TRANSLATE = 7;

    /*!
131
     *\brief A state which corresponds to change the render area scale.
132 133 134 135
     */
    static const int _STATE_RENDER_AREA_CHANGE_SCALE = 8;

    /*!
136
     *\brief A state which corresponds to change the render area container/state scale.
137 138
     */
    static const int _STATE_RENDER_AREA_CHANGE_CONTAINER_SCALE = 9;
139 140

    /*!
141
     *\brief Informs that a trace has to be parsed and displayed in the main window.
142 143 144 145 146 147 148
     */
    static const int _DRAW_OPENGL = 10;

    /*!
     *\brief  Informs that a trace has to be exported in svg format.
     */
    static const int _DRAW_SVG = 11;
149
    
Johnny Jazeix's avatar
Johnny Jazeix committed
150 151 152
    /*!
     *\brief A state which corresponds to display the ViTE window.
     */
153 154 155 156 157 158 159 160 161 162 163
    static const int _STATE_LAUNCH_GRAPHICAL_INTERFACE = 12;

    /*!
     *\brief A state which corresponds to replace the render area scale.
     */
    static const int _STATE_RENDER_AREA_REPLACE_SCALE = 13;

    /*!
     *\brief A state which corresponds to replace the render area translate.
     */
    static const int _STATE_RENDER_AREA_REPLACE_TRANSLATE = 14;
164 165 166 167 168
    
    /*!
     *\brief A state which corresponds to replace the render area translate.
     */
    static const int _STATE_RENDER_AREA_REPLACE_TRANSLATE_Y = 15;
Johnny Jazeix's avatar
Johnny Jazeix committed
169

170 171 172 173 174 175 176 177 178
    /*!
     *\brief A state which corresponds to the registered render area translate.
     */
    static const int _STATE_RENDER_AREA_REGISTERED_TRANSLATE = 16;

    /*!
     *\brief A state which corresponds to change the render area scale.
     */
    static const int _STATE_RENDER_AREA_CHANGE_SCALE_Y = 17;
179 180 181 182 183 184 185 186 187 188
    
    /*!
     *\brief A state which corresponds to set new scroll bar length.
     */
    static const int _STATE_AJUST_SCROLL_BARS = 18;
    
    /*!
     *\brief A state which corresponds to a scroll modification of the render area.
     */
    static const int _STATE_REFRESH_SCROLL_BARS = 19;
189

190 191 192
    /*!
     *\brief Allow render area to change the graphical interface zoom box value.
     */
193
    static const int _STATE_ZOOM_BOX_VALUE = 20;
194

195 196 197 198 199
    /*!
     *\brief Display information about a selected entity.
     */
    static const int _STATE_RENDER_DISPLAY_INFORMATION = 21;

200 201 202 203 204
    /*!
     *\brief Update the render area.
     */
    static const int _STATE_RENDER_UPDATE = 22;

205 206 207 208
    /*!
     *\brief To draw a part of the drace (without all the containers)
     */
    static const int _DRAW_OPENGL_PARTIAL = 23;
209

210 211
    /*!
     * \brief Launch an action according to the argument state value.
212 213
     * \param state An integer corresponding to a kind of action which must be executed.
     * \param arg Contains necessary arguments needed for the action to launch.
214 215 216 217 218 219 220 221 222 223 224 225 226 227
     *
     * This functions triggers an action of ViTE according to its argument. state can takes some values :
     * <ul><li><b>STATE_DISPLAY_HELP</b> -> this value means that the console interface must be displayed
     * in the terminal the help text, then wait until user specify an other command.</li>
     * <li><b>STATE_LAUNCH_GRAPHICAL_INTERFACE</b> -> this value means that the console interface will let
     * user to use the graphical interface: in that case, ViTE displays the window and all
     * of the warning or error messages will be displayed in dialog boxes.</li>
     * </ul>
     */
    void launch_action(int state, void* arg = NULL);

protected:


228 229 230 231 232 233 234 235 236 237 238 239 240 241
    /***********************************
     *
     * Control attributes
     *
     **********************************/

    /*!
     * \brief Use to know if a window is displayed or not.
     *
     * This attributes control if the Qt managing event function exec() is executed,
     * or if ViTE must quit after some operations without graphical interface
     * are processed. (exportation for example)
     */
    bool _is_window_displayed;
242 243 244 245 246 247 248 249
    
    
    /*!
     * \brief Use to know if a trace is loaded.
     *
     * This attributes is used to know for an export if a trace has already be parsed.
     */
    bool _is_trace_loaded;
250 251


252 253 254 255 256 257 258 259 260 261 262 263 264

    /***********************************
     *
     * Window interface instance.
     *
     **********************************/

    /*!
     * \brief Contains the instance of the window class.
     */
    Interface_graphic* _main_window;

    /*!
265 266 267
     * \brief Contains the OpenGL render instance.
     */
    /* MOD */
268 269 270 271 272
#ifdef WITH_VBO
    Render_alternate* _render_opengl;
#else
    Render_opengl* _render_opengl;
#endif
273 274 275 276
    //Render<Render_opengl>* _render_opengl;

    /*!
     * \brief Contains the SVG render instance.
277
     */
278
    Render_svg* _render_svg;
279 280 281 282 283 284

    /*!
     * \brief Contains the main Qt application instance.
     */
    QApplication* app;

285 286 287 288 289
    /*!
     * \brief Contains the trace instance.
     */
    Trace* _trace;

Jule Marcoueille's avatar
Jule Marcoueille committed
290 291 292
    /*!
     *\brief This attributes contains the launching current directory (_run_env[0]) and the first argument of the running command (_run_env[1]).
     */
293
    QString* _run_env[2];
294 295

    /*!
296
     *\brief If a file must be opened, this attribute contains its path.
297
     */
298
    std::string _file_opened;
299

300
    /*!
301
     *\brief If a file must be exported, this attribute contains its path.
302
     */
303
    std::string _path_to_export;
304 305 306 307

    /*!
     *\brief The time where we start to watch the trace.
     */
308
    double _time_start;
309 310 311 312

    /*!
     *\brief The time where we stop to watch the trace.
     */
313
    double _time_end;
314

315
    /*!
316
     *\brief The interface_console state is specified by a command line arguments combinaison which influence the launch. _state is computed by get_state() and retrieved by int get_status().
317 318 319
     */
    int _state;

320 321 322
    /*!
     *\brief The parser thread.
     */
323
    
324

325 326 327 328
    /*!
     *\brief To show the avancement of parsing.
     */
    QProgressDialog *_progress_dialog;
329

330 331
    /*!
     * \brief Return the state of ViTE according to the arguments.
332 333 334
     * \param argc The number of parameters given when the program was called.
     * \param argv A set of strings which contains each parameter.
     * \return An integer corresponding to a command which will be processed by ViTE.
335
     */
336
    int get_state(int argc, char** argv);
337
  
338

339
    
340 341
    /*!
     * \brief Extracts the times of start and end in the string.
342
     * \param name The string where we extract times.
343
     */
344
    void extract_times(const char* name);
345

346 347 348
    /*!
     * \brief Displays in the terminal the help text.
     */
349 350 351 352
    void display_help();



353

Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
354
public:
Jule Marcoueille's avatar
Jule Marcoueille committed
355 356
    
    
357 358 359 360 361 362
    /***********************************
     *
     * Constructor and destructor.
     *
     **********************************/

363
    /*!
364
     * \brief The default constructor of the class.
365 366
     * \param argc The number of parameters given when the program was called.
     * \param argv A set of strings which contains each parameter.
367
     */
368
    Core(int argc, char** argv);
369
    
370
    /*!
371
     * \brief The destructor.
372
     */
373
    virtual ~Core();
374 375


376

377 378 379 380 381 382
    /***********************************
     *
     * Running function.
     *
     **********************************/

383 384 385
    /*!
     * \brief This function launch trace drawing.
     * \param filename Path of the trace file.
386
     * \param format Format of the render output between: Core::_DRAW_OPENGL and Core::_DRAW_SVG.
387 388
     *
     * \return true if no errors occurs.
389
     */
390
    bool draw_trace(const std::string & filename, const int format);
391

392 393 394 395 396 397
    /*!
     * \brief This function launch Qt event loop.
     */
    int run();


398 399 400 401 402
    /*!
     * \brief Get the name of the current trace file.
     *
     */
    const std::string get_filename() const;
Jule Marcoueille's avatar
Jule Marcoueille committed
403
    
404 405 406 407 408 409 410
    /*!
     * \brief Set the name of the output file for SVG export.
     * \param path Path of the output file.
     *
     */
    void set_path_to_export(const std::string& path);

Jule Marcoueille's avatar
Jule Marcoueille committed
411
    /*!
Jule Marcoueille's avatar
Jule Marcoueille committed
412
     * \brief Get the _run_env matrix.
Jule Marcoueille's avatar
Jule Marcoueille committed
413 414
     *
     */
415
    const QString** get_runenv() const;
416

417

418 419 420 421 422 423
    /***********************************
     *
     * Informative message functions.
     *
     **********************************/
    
424
    /*!
425 426
     * \brief The function takes a string then displayed it into the terminal, then killed the application.
     * \param string The string to be displayed.
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
427
    */
428
    void error(const std::string &string) const;
429 430 431

    
    /*!
432
      \brief The function takes a string then displayed it into the terminal, then the program go on with an indeterminated behaviour.
433
      \param string The string to be displayed.
434
    */
435
    void warning(const std::string &string) const;
436

437 438
 
    /*!
439 440 441
     * \brief The function takes a strings then displayed it into the terminal, then the program go on.
     * \param string The string to be displayed.
     */
442
    void information(const std::string &string) const;
443

444
    /*!
445
     * \brief Only use in graphic interface.
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
446
     */
447
    void selection_information(const std::string &) const{
448
    }
449

450 451

    /*!
452
     *\brief Set the minimum for export
453
     *\param d The double.
Johnny Jazeix's avatar
Normes.  
Johnny Jazeix committed
454
     */
455
    void set_min_value_for_export(const double d);
456

457 458
    /*!
     *\brief Set the minimum for export
459
     *\param d The double.
460 461
     */
    void set_max_value_for_export(const double d);
462 463 464
             

    Trace *get_trace() const;
465

Mathieu Faverge's avatar
Mathieu Faverge committed
466 467 468 469 470
    /*!
     *\brief Export a counter
     * Need to choose a counter, and a filename
     */
    void export_variable(Variable *var, std::string filename);
471
                                                       
472
public slots:
473 474 475 476 477
    
    /*!
     * \brief Update the progress bar value.
     * \param loaded The percentage of trace which is already loaded.
     */
478
    void update_progress_bar(const int loaded);
479
    
480 481 482 483
};


#endif