MainWindow.h 8.98 KB
Newer Older
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1 2 3 4 5 6 7
/**
* @headerfile travisto.h
* @author   Ulrich Kemloh <kemlohulrich@gmail.com>
* @version 0.1
* Copyright (C) <2009-2010>
*
* @section LICENSE
8
* This file is part of JuPedSim.
Ulrich Kemloh's avatar
Ulrich Kemloh committed
9
*
10
* JuPedSim is free software: you can redistribute it and/or modify
Ulrich Kemloh's avatar
Ulrich Kemloh committed
11 12 13 14
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
15
* JuPedSim is distributed in the hope that it will be useful,
Ulrich Kemloh's avatar
Ulrich Kemloh committed
16 17 18 19 20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
21
* along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
Ulrich Kemloh's avatar
Ulrich Kemloh committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
*
* @section DESCRIPTION
*
* \brief main program class
*
*
*
*  Created on: 11.05.2009
*
*/

#ifndef TRAVISTO_H
#define TRAVISTO_H


Ulrich Kemloh's avatar
Ulrich Kemloh committed
37
#include "ui_mainwindow.h"
38
#include <QMainWindow>
39
#include <QSettings>
40 41 42 43
#include <QSplitter>
#include <QTreeView>
#include <QStandardItem>
#include <QTreeWidget>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
44 45 46 47 48 49 50 51 52 53

#include <vector>

class vtkWindowToImageFilter;
class SyncData;
class ThreadDataTransfer;
class ThreadVisualisation;
class QString;
class QDomNode;
class FacilityGeometry;
54
class GeometryFactory;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
class Building;
class Message;
class Settings;


extern int extern_update_step;
extern int extern_screen_contrast;
extern bool extern_is_pause;
extern bool extern_launch_recording;
extern bool extern_recording_enable;
extern bool extern_offline_mode;
extern bool extern_shutdown_visual_thread;
extern bool extern_fullscreen_enable;

extern bool extern_pedestrians_firstSet_visible;

extern SyncData extern_trajectories_firstSet;

//states if the datasets are loaded.
extern bool extern_first_dataset_loaded;

//states whether the loaded datasets are visible
extern bool extern_first_dataset_visible;


Ulrich Kemloh's avatar
Ulrich Kemloh committed
80 81
class MainWindow : public QMainWindow {
    Q_OBJECT
Ulrich Kemloh's avatar
Ulrich Kemloh committed
82 83

public:
Ulrich Kemloh's avatar
Ulrich Kemloh committed
84 85
    MainWindow(QWidget *parent = 0);
    virtual ~MainWindow();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
86 87 88 89


public Q_SLOTS:

Ulrich Kemloh's avatar
Ulrich Kemloh committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
    /// display the help modus
    void slotHelpAbout();
    ///quit the program
    void slotExit();

    /// load a file
    bool slotLoadFile();

    /// output an Error
    void slotErrorOutput(QString err);

    /// output a warning
    //void slotWarningOutput(QString warning);

    /// start the visualisation thread
    /// the signal is emitted when the
    /// data transfer thread the header and at least one data set
    void slotStartVisualisationThread(QString data="",int numberOfAgents=1000,float frameRate=25);

    /// shutdown the visualisation thread
    void slotShutdownVisualisationThread(bool);

    /// add a new dataset to the store.
    /// note that at most three (3) datasets can be loaded for a visualisation round
    bool slotAddDataSet();

    /// clear all previously added/loaded datasets
    void slotClearAllDataset();

    /// set the camera view angle to  TOP/FRONT/SIDE
    // TODO: high priority
    void slotSetCameraPerspectiveToTop();
    void slotSetCameraPerspectiveToFront();
    void slotSetCameraPerspectiveToSide();
    void slotSetCameraPerspectiveToVirtualAgent();

    //controls visualisation
    void slotStartPlaying();
    void slotStopPlaying();
    void slotRecord();
    void slotFullScreen(bool status);
    void slotReset();
    void slotNetworkSettings();
    // void slotToggleVisualisationMode();
    void slotSetOfflineMode(bool status);
    void slotSetOnlineMode(bool status);
    /// take a screenshot of the rendering window
    void slotTakeScreenShot();

    /// update the status message
    void slotCurrentAction(QString msg);
141
     void slotFrameNumber(unsigned long timems, unsigned long minFrame);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
142 143 144 145 146 147
    void slotRunningTime(unsigned long timems);
    void slotRenderingTime(int fps);
    void slotControlSequence(const char *);

    /// load a geometry file and display it
    //void slotLoadGeometry( );
Mohcine Chraibi's avatar
Mohcine Chraibi committed
148
    void slotClearGeometry();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
149 150 151 152 153 154 155 156
    //void slotLoadParseShowGeometry(QString fileName);

    /// load a geometry sent by the data transfer thread
    //void slotLoadGeometryToThread(QString data);


    /// enable/disable the first pedestrian group
    void slotToggleFirstPedestrianGroup();
157

Ulrich Kemloh's avatar
Ulrich Kemloh committed
158 159 160 161 162 163 164 165 166 167

    /// show/hides trajectories (leaving a trail) only
    void slotShowTrajectoryOnly();

    /// shows/hide geometry
    void slotShowGeometry();
    /// shows/hide geometry
    void slotShowHideExits();
    /// shows/hide geometry
    void slotShowHideWalls();
168 169
    /// shows/hide navigation lines
    void slotShowHideNavLines();
170 171
    /// shows/hide navigation lines
    void slotShowHideFloor();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
172 173
    /// shows/hide geometry captions
    void slotShowHideGeometryCaptions();
174 175
    /// show hide the obstacles
    void slotShowHideObstacles();
176 177
    /// show/hide the gradient field
    void slotShowHideGradientField();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
178

Ulrich Kemloh's avatar
Ulrich Kemloh committed
179 180
    /// show pedestrians only without trail
    void slotShowPedestrianOnly();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
181

Ulrich Kemloh's avatar
Ulrich Kemloh committed
182 183
    /// update the playing speed
    void slotUpdateSpeedSlider(int newValue);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
184

Ulrich Kemloh's avatar
Ulrich Kemloh committed
185 186 187 188
    /// update the position slider
    void slotUpdateFrameSlider(int newValue);
    void slotFrameSliderPressed();
    void slotFrameSliderReleased();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
189

Ulrich Kemloh's avatar
Ulrich Kemloh committed
190 191 192 193
    /// handle the frame by frame navigation
    void slotFramesByFramesNavigation();
    void slotNextFrame();
    void slotPreviousFrame();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
194

Ulrich Kemloh's avatar
Ulrich Kemloh committed
195 196
    /// enable/disable the pedestrian captions
    void slotShowPedestrianCaption();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
197

Ulrich Kemloh's avatar
Ulrich Kemloh committed
198 199
    /// update the contrast
    void slotUpdateContrastSlider(int newValue);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
200

Ulrich Kemloh's avatar
Ulrich Kemloh committed
201 202
    /// set visualisation mode to 2D
    void slotToogle2D();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
203

Ulrich Kemloh's avatar
Ulrich Kemloh committed
204 205
    /// set visualisation mode to 3D
    void slotToogle3D();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
206

Ulrich Kemloh's avatar
Ulrich Kemloh committed
207 208
    /// show / hide the legend
    void slotToogleShowLegend();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
209

Ulrich Kemloh's avatar
Ulrich Kemloh committed
210
    void slotToogleShowAxis();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
211

Ulrich Kemloh's avatar
Ulrich Kemloh committed
212 213
    /// change, choose the pedestrian shape
    void slotChangePedestrianShape();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
214

Ulrich Kemloh's avatar
Ulrich Kemloh committed
215 216
    /// start/stop the recording process als png images sequences
    void slotRecordPNGsequence();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
217

Ulrich Kemloh's avatar
Ulrich Kemloh committed
218 219
    /// render a PNG image sequence to an AVI video
    void slotRenderPNG2AVI();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
220

Ulrich Kemloh's avatar
Ulrich Kemloh committed
221 222
    /// adjust the scene background color
    void slotChangeBackgroundColor();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
223

Ulrich Kemloh's avatar
Ulrich Kemloh committed
224 225
    /// change the pedestrian caption mode to automatic
    void slotCaptionColorAuto();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
226

Ulrich Kemloh's avatar
Ulrich Kemloh committed
227 228
    /// change he pedestrian caption color to manual
    void slotCaptionColorCustom();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
229

Ulrich Kemloh's avatar
Ulrich Kemloh committed
230 231
    /// change the wall color
    void slotChangeWallsColor();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
232

Ulrich Kemloh's avatar
Ulrich Kemloh committed
233 234
    /// change the exits color
    void slotChangeExitsColor();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
235

236 237 238
    /// change the navigation lines color
    void slotChangeNavLinesColor();

239 240 241
    /// change the floor color
    void slotChangeFloorColor();

242 243 244
    /// change the obstacle color
    void slotChangeObstacleColor();

Ulrich Kemloh's avatar
Ulrich Kemloh committed
245
    /// show/hide onscreen information
246
    /// information include Time and number pedestrians left in the facility
Ulrich Kemloh's avatar
Ulrich Kemloh committed
247
    void slotShowOnScreenInfos();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
248

249 250 251 252 253
    ///show the detailed structure of the geometry
    void slotShowGeometryStructure();

    void slotOnGeometryItemChanged(QStandardItem *item);

Ulrich Kemloh's avatar
Ulrich Kemloh committed
254
private:
Ulrich Kemloh's avatar
Ulrich Kemloh committed
255 256
Q_SIGNALS:
    void signal_controlSequence(QString);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
257 258

protected:
Ulrich Kemloh's avatar
Ulrich Kemloh committed
259 260 261
    virtual void closeEvent(QCloseEvent* event);
    void dragEnterEvent(QDragEnterEvent *event);
    void dropEvent(QDropEvent *event);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
262 263 264

private:

265 266 267 268 269
    /// load settings in the case the remember settings is checked.
    void loadAllSettings();

    /// save all system settings
    void saveAllSettings();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
270

Ulrich Kemloh's avatar
Ulrich Kemloh committed
271 272
    /// performs the necessary cleaning before shutting down the program.
    void cleanUp();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
273

Ulrich Kemloh's avatar
Ulrich Kemloh committed
274 275
    /// reset the system to the very initial state
    //void reset();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
276

Ulrich Kemloh's avatar
Ulrich Kemloh committed
277 278
    /// get the value of the tag <tagName> from a QDomNode
    QString getTagValueFromElement(QDomNode node, const char * tagName);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
279

Ulrich Kemloh's avatar
Ulrich Kemloh committed
280 281
    /// parse the geometry  Node and return a pointer to geometry object
    /// used in online mode only
282 283
    void parseGeometry(const QDomNode& geoNode);
    void parseGeometry(const QString &geometryString);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
284

Ulrich Kemloh's avatar
Ulrich Kemloh committed
285 286 287 288 289 290 291
    /**
     * parse a shape node and get the initials heights and colors of pedestrians.
     *
     * @param shapeNode The node to be parsed
     * @param groupID 1, 2 or 3
     * @return true if success
     */
Mohcine Chraibi's avatar
Mohcine Chraibi committed
292
     //  bool parsePedestrianShapes(QDomNode shapeNode, int groupID);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
293

Ulrich Kemloh's avatar
Ulrich Kemloh committed
294 295
    /// reset all graphic element to their initial(default) state
    void resetGraphicalElements();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
296

Ulrich Kemloh's avatar
Ulrich Kemloh committed
297 298 299
    /// add a second/third dataset to the visualization data
    ///  groupID may be 2 or 3
    /// @return false if something went wrong.
Ulrich Kemloh's avatar
Ulrich Kemloh committed
300

Ulrich Kemloh's avatar
Ulrich Kemloh committed
301
    bool addPedestrianGroup(int groupID, QString fileName="");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
302

Ulrich Kemloh's avatar
Ulrich Kemloh committed
303 304
    ///return true if at least one dataset was loaded
    bool anyDatasetLoaded();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
305

Ulrich Kemloh's avatar
Ulrich Kemloh committed
306 307
    /// clear the corresponding dataset if it exists
    void clearDataSet(int ID);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
308

Ulrich Kemloh's avatar
Ulrich Kemloh committed
309 310
    /// reset all dataset, to the beginning
    void resetAllFrameCursor();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
311

Ulrich Kemloh's avatar
Ulrich Kemloh committed
312 313
    /// wait for visualisation thread to terminate
    void waitForVisioThread();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
314

Ulrich Kemloh's avatar
Ulrich Kemloh committed
315 316
    /// wait for data transfer thread to terminate
    void waitForDataThread();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
317 318 319 320



private:
Ulrich Kemloh's avatar
Ulrich Kemloh committed
321
    Ui::mainwindow ui;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
322

Ulrich Kemloh's avatar
Ulrich Kemloh committed
323 324 325 326 327 328 329
    bool isPlaying;
    bool isPaused;
    bool frameSliderHold;
    int numberOfDatasetLoaded;

    Settings* travistoOptions;
    ThreadDataTransfer* dataTransferThread;
330
    ThreadVisualisation* _visualisationThread;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
331 332 333 334
    QLabel *labelCurrentAction;
    QLabel *labelFrameNumber;
    QLabel *labelRecording;
    QLabel *labelMode;
335 336 337 338
    QSplitter _splitter;
    //QTreeWidget _geoStructure;
    QTreeView _geoStructure;

Ulrich Kemloh's avatar
Ulrich Kemloh committed
339 340 341
};

#endif // TRAVISTO_H