MainWindow.cpp 59.3 KB
Newer Older
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1
/**
2
 * @file MainWindow.cpp
Ulrich Kemloh's avatar
Ulrich Kemloh committed
3 4 5 6 7
 * @author   Ulrich Kemloh <kemlohulrich@gmail.com>
 * @version 0.1
 * Copyright (C) <2009-2010>
 *
 * @section LICENSE
Mohcine Chraibi's avatar
Mohcine Chraibi committed
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 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
 * 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
 * along with OpenPedSim. If not, see <http://www.gnu.org/licenses/>.
 *
 * @section DESCRIPTION
 *
 * \brief main program class
 *
 *
 *  Created on: 11.05.2009
 *
 */


#include "MainWindow.h"
#include "SaxParser.h"
#include "SystemSettings.h"
#include "./forms/Settings.h"


#include "extern_var.h"
#include "TrajectoryPoint.h"
#include "Frame.h"
#include "Debug.h"
#include "ThreadVisualisation.h"
#include "ThreadDataTransfert.h"
#include "SimpleVisualisationWindow.h"

#include "geometry/FacilityGeometry.h"

#include <QMessageBox>
#include <QtXml/QDomDocument>
#include <QTime>
#include <QApplication>
#include <QCloseEvent>
#include <QThread>
#include <QIODevice>
#include <QDir>
#include <QFile>
#include <QFileDialog>
#include <QInputDialog>
#include <QString>
#include <QColorDialog>
#include <QtXml>
63
#include <QTemporaryFile>
64 65 66 67 68 69
#include <QListView>
#include <QFileSystemModel>
#include <QTableView>
#include <QSplitter>
#include <QStandardItemModel>

70

Ulrich Kemloh's avatar
Ulrich Kemloh committed
71 72 73 74 75 76 77
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

78 79 80 81 82 83 84 85 86 87 88 89

#ifdef __APPLE__
#include <thread>
#include <dispatch/dispatch.h>
#include "fix/osx_thread_fix.h"

std::thread::id main_thread_id = std::this_thread::get_id();
dispatch_queue_t main_q = dispatch_get_main_queue();

void is_main_thread() {

    if ( main_thread_id == std::this_thread::get_id() )
Mohcine Chraibi's avatar
Mohcine Chraibi committed
90 91 92
    {
         std::cout << "This is the main thread.\n";
    }
93 94 95 96 97 98
    else
        std::cout << "This is not the main thread.\n";
}
#endif


Ulrich Kemloh's avatar
Ulrich Kemloh committed
99
MainWindow::MainWindow(QWidget *parent) :
Ulrich Kemloh's avatar
Ulrich Kemloh committed
100 101
    QMainWindow(parent)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
102 103 104 105
    ui.setupUi(this);
    this->setWindowTitle("JPSvis");

    //disable the maximize Button
106 107 108
    setWindowFlags( Qt::Window | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);

    //used for saving the settings in a persistant way
Mohcine Chraibi's avatar
Mohcine Chraibi committed
109
    QCoreApplication::setOrganizationName("Forschungszentrum_Juelich_GmbH");
110 111
    QCoreApplication::setOrganizationDomain("jupedsim.org");
    QCoreApplication::setApplicationName("jupedsim");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
112 113 114

    //create the 2 threads and connect them
    dataTransferThread = new ThreadDataTransfer(this);
115
    _visualisationThread = new ThreadVisualisation(this);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
116 117 118 119 120 121 122 123 124


    travistoOptions = new Settings(this);
    travistoOptions->setWindowTitle("Settings");
    travistoOptions->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint);


    if(!QObject::connect(dataTransferThread,
                         SIGNAL(signal_controlSequence(const char*)), this,
Ulrich Kemloh's avatar
Ulrich Kemloh committed
125
                         SLOT(slotControlSequence(const char *)))) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
126 127 128 129 130
        Debug::Error("dataTransferThread Thread: control sequence could not be connected");
    }

    if(!QObject::connect(dataTransferThread,
                         SIGNAL(signal_startVisualisationThread(QString,int,float )), this,
Ulrich Kemloh's avatar
Ulrich Kemloh committed
131
                         SLOT(slotStartVisualisationThread(QString,int,float )))) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
132 133 134 135 136
        Debug::Error(" signal_startVisualisationThread not connected");
    }

    if(!QObject::connect(dataTransferThread,
                         SIGNAL(signal_stopVisualisationThread(bool )), this,
Ulrich Kemloh's avatar
Ulrich Kemloh committed
137
                         SLOT(slotShutdownVisualisationThread(bool )))) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
138 139 140 141 142
        Debug::Error(" signal_stopVisualisationThread not connected ");
    }

    if(!QObject::connect(dataTransferThread,
                         SIGNAL(signal_errorMessage(QString)), this,
Ulrich Kemloh's avatar
Ulrich Kemloh committed
143
                         SLOT(slotErrorOutput(QString)))) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
144 145 146
        Debug::Error("signal_errorMessage  not connected ");
    }

147
    QObject::connect(_visualisationThread,
Ulrich Kemloh's avatar
Ulrich Kemloh committed
148 149 150 151 152 153 154 155 156 157 158 159 160
                     SIGNAL(signal_controlSequences(const char*)), this,
                     SLOT(slotControlSequence(const char *)));

    QObject::connect(&extern_trajectories_firstSet,
                     SIGNAL(signal_controlSequences(const char*)), this,
                     SLOT(slotControlSequence(const char *)));

    QObject::connect(dataTransferThread, SIGNAL(signal_CurrentAction(QString)),
                     this, SLOT(slotCurrentAction(QString)));

    QObject::connect(this, SIGNAL(signal_controlSequence(QString)),
                     travistoOptions, SLOT(slotControlSequence(QString)));

161

162
    QObject::connect(&_visualisationThread->getGeometry().GetModel(),
163 164
                     SIGNAL(itemChanged(QStandardItem*)),this,SLOT(slotOnGeometryItemChanged(QStandardItem*)));

Ulrich Kemloh's avatar
Ulrich Kemloh committed
165 166 167 168 169
    isPlaying = false;
    isPaused = false;
    numberOfDatasetLoaded=0;
    frameSliderHold=false;

Ulrich Kemloh's avatar
Ulrich Kemloh committed
170 171
    //some hand made stuffs
    ui.BtFullscreen->setVisible(false);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198

    labelCurrentAction = new QLabel();
    labelCurrentAction->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    labelCurrentAction->setText("   Idle   ");
    statusBar()->addPermanentWidget(labelCurrentAction);

    labelFrameNumber = new QLabel();
    labelFrameNumber->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    labelFrameNumber->setText("fps:");
    statusBar()->addPermanentWidget(labelFrameNumber);

    labelRecording = new QLabel();
    labelRecording->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    labelRecording->setText(" rec: off ");
    statusBar()->addPermanentWidget(labelRecording);

    labelMode = new QLabel();
    labelMode->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    labelMode->setText(" Offline ");
    statusBar()->addPermanentWidget(labelMode);


    ui.BtNextFrame->setVisible(false);
    ui.BtPreviousFrame->setVisible(false);
    //TODO: Maybe this is not longer needed
    ui.framePerSecondSliderLabel->setVisible(false);
    ui.contrastSettingSlider->setVisible(false);
199 200
    //restore the settings
    loadAllSettings();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
201 202 203 204 205

    QStringList arguments =QApplication::arguments();
    int group=1; // there are max 3 groups of pedestrians
    bool mayPlay=false;

206 207
    //arguments.append("-online");
    //arguments.append("-caption");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
208 209 210
    arguments.append("-2D");
    // parse arguments list
    if(arguments.size()>1)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
211
        for(int argCount=1; argCount<arguments.size(); argCount++) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
212 213 214 215

            QString argument=arguments[argCount];

            if(argument.compare("help")==0) {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
216
                Debug::Messages("Usage: jpsvis [file1] [-2D] [-caption] [-online [port]]");
Mohcine Chraibi's avatar
Mohcine Chraibi committed
217
                exit(0);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
218
            } else if(argument.compare("-2D")==0) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
219 220
                ui.action2_D->setChecked(true);
                slotToogle2D();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
221
            } else if(argument.compare("-caption")==0) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
222 223 224
                ui.actionShow_Captions->setChecked(true);
                slotShowPedestrianCaption();

Ulrich Kemloh's avatar
Ulrich Kemloh committed
225
            } else if(argument.compare("-online")==0) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
226
                slotSetOnlineMode(true);
227
                Debug::Messages("Online option parsed");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
228
                // checking for other possible options [ port...]
Ulrich Kemloh's avatar
Ulrich Kemloh committed
229
                if(argCount!=arguments.size()-1) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
230 231
                    bool ok=false;
                    int port = arguments[++argCount].toInt(&ok);
232
                    Debug::Messages(" listening port: %d",port);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
233 234

                    if (ok) {
235
                        SystemSettings::setListeningPort(port);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
236
                    } else { // maybe that wasnt the port
Ulrich Kemloh's avatar
Ulrich Kemloh committed
237 238 239
                        argCount--; // to ensure that the "option" will be checked
                    }
                }
240
                //mayPlay=true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
241

Ulrich Kemloh's avatar
Ulrich Kemloh committed
242
            } else if(argument.startsWith("-")) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
243
                const char* std=argument.toStdString().c_str();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
244
                Debug::Error("unknown options: %s",std);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
245
                Debug::Error("Usage: jpsvis [file1] [-2D] [-caption] [-online [port] ]");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
246
            } else if(addPedestrianGroup(group,argument)) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
247
                //slotHelpAbout();
248
                 Debug::Messages("group: %d, arg: %s", group, argument.toStdString().c_str());
Ulrich Kemloh's avatar
Ulrich Kemloh committed
249 250 251 252 253
                group++;
                mayPlay=true;
            }

        }
254
    Debug::Messages("MayPlay: %s", mayPlay?"True":"False");
255 256 257 258 259 260 261
    // was call from the command line with a file.
    // disable the online mode if it was enabled
    if(mayPlay)
    {
        slotSetOfflineMode(true);
        slotStartPlaying();
    }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
262 263
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
264 265
MainWindow::~MainWindow()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
266 267 268
    extern_shutdown_visual_thread=true;
    extern_recording_enable=false;

269
    //save all settings for the next session
270 271 272
    if(ui.actionRemember_Settings->isChecked())
    {
        saveAllSettings();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
273
        Debug::Messages("saving all settings");
274 275 276 277 278 279 280 281
    }
    else
    {
        //first clear everyting
        QSettings settings;
        settings.clear();
        //then remember that we do not want any settings saved
        settings.setValue("options/rememberSettings", false);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
282
        Debug::Messages("clearing all settings");
283
    }
284

Ulrich Kemloh's avatar
Ulrich Kemloh committed
285

286
    if (_visualisationThread->isRunning()) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
287 288 289 290 291 292 293 294 295 296 297
        //std::Debug::Messages("Thread  visualisation is still running" << std::endl;
        waitForVisioThread();
    }

    if (dataTransferThread->isRunning()) {
        //std::Debug::Messages("Thread  visualisation is still running" << std::endl;
        //it is your own fault if you were still recording something
        waitForDataThread();
    }

    delete dataTransferThread;
298
    delete _visualisationThread;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
299 300 301 302 303 304 305
    delete travistoOptions;
    delete labelCurrentAction;
    delete labelFrameNumber;
    delete labelRecording;
    delete labelMode;
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
306 307
void MainWindow::slotHelpAbout()
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
308
     Debug::Messages("About jpsvis");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
309
    QMessageBox::about(
310 311
                this,
                "About JPSVis",
Mohcine Chraibi's avatar
Mohcine Chraibi committed
312
                "Version 0.8.2 built with  QT 4.8 and VTK 5.10\n\n"
313 314 315
                "JPSvis is part of the Juelich Pedestrian Simulator (JuPedsim)"
                "It is a tool for visualizing pedestrians motion\n"
                "developped at the Forschungszentrum Juelich GmbH, Germany\n\n"
Mohcine Chraibi's avatar
Mohcine Chraibi committed
316
                "Copyright 2009-2018.\n"
317
                "Authors: Ulrich Kemloh\n\n"
Mohcine Chraibi's avatar
Mohcine Chraibi committed
318
                "Issue tracker: https://gitlab.version.fz-juelich.de/jupedsim/jpsvis/issues \n");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
319 320 321 322 323 324 325
}


/**
 *setup the network port to bind
 *
 */
Ulrich Kemloh's avatar
Ulrich Kemloh committed
326 327
void MainWindow::slotNetworkSettings()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
328 329
    bool ok;
    int port = QInputDialog::getInt(this, tr("input a port "), tr(
Ulrich Kemloh's avatar
Ulrich Kemloh committed
330
                                        "port(default to 8989):"), 8989, 5000, 65355, 1, &ok);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
331
    if (ok) {
332
        SystemSettings::setListeningPort(port);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
333 334 335
    }
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
336 337
void MainWindow::slotStartPlaying()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
338 339 340 341 342 343 344 345 346 347

    //first reset this variable. just for the case
    // the thread was shutdown from the reset option
    extern_shutdown_visual_thread = false;

    if (!isPlaying) {
        statusBar()->showMessage(QString::fromUtf8("waiting for data"));
        //only start the visualisation thread if in offline modus
        // otherwise both threads should be started
        if (extern_offline_mode) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
348
            if(anyDatasetLoaded()) { //at least one dataset was loaded, restarting the playback
Ulrich Kemloh's avatar
Ulrich Kemloh committed
349 350 351 352 353 354 355

                // starting the playback from the beginning
                extern_trajectories_firstSet.resetFrameCursor();

            } else if (!slotAddDataSet()) { //else load a dataset
                return;//could not read any data
            }
356 357 358 359 360
#ifdef __APPLE__
            //std::thread::id main_thread_id = std::this_thread::get_id();
            dispatch_queue_t main_q = dispatch_get_main_queue();
            dispatch_async(main_q, ^(void){
                               //visualisationThread->moveToThread(QApplication::instance()->thread());
361
                               _visualisationThread->run();
362
                           });
Ulrich Kemloh's avatar
Ulrich Kemloh committed
363
#else
364
            _visualisationThread->start();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
365

366 367
#endif

Ulrich Kemloh's avatar
Ulrich Kemloh committed
368
        } else { /*if (extern_online_mode)*/  //live visualisation
369 370 371 372 373

#ifdef __APPLE__
            dispatch_async(main_q, ^(void){
                               dataTransferThread->run();
                           });
Ulrich Kemloh's avatar
Ulrich Kemloh committed
374
#else
Ulrich Kemloh's avatar
Ulrich Kemloh committed
375
            dataTransferThread->start();
376 377 378

#endif
            //dataTransferThread->start();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
            //visualisationThread->start();
        }

        //enable recording
        ui.BtRecord->setEnabled(true);
        labelCurrentAction->setText("   playing   ");

        //change Icon to Pause
        QIcon icon1;
        icon1.addPixmap(QPixmap(QString::fromUtf8(
                                    ":/new/iconsS/icons/PauseHot.png")), QIcon::Normal, QIcon::Off);
        ui.BtStart->setToolTip("pause the visualisation");
        ui.BtStart->setIcon(icon1);

        //anyDataLoaded=true;
        isPlaying = true;
        extern_is_pause = false;

    } else if (isPaused) { //resume playing
        isPaused = false;
        extern_is_pause = false;
        //restore the play Icon
        QIcon icon1;
        icon1.addPixmap(QPixmap(QString::fromUtf8(
                                    ":/new/iconsS/icons/PauseHot.png")), QIcon::Normal, QIcon::Off);
        ui.BtStart->setIcon(icon1);
        labelCurrentAction->setText("   playing   ");
        ui.BtStart->setToolTip("pause the visualisation");

    } else { //call pause
        isPaused = true;
        extern_is_pause = true;
        QIcon icon1;
        icon1.addPixmap(QPixmap(QString::fromUtf8(
                                    ":/new/iconsS/icons/Play1Hot.png")), QIcon::Normal, QIcon::Off);
        ui.BtStart->setIcon(icon1);
        ui.BtStart->setToolTip("resume the visualisation");
        labelCurrentAction->setText("   paused   ");
    }

    //no matter what, the stop button should be enabled
    ui.BtStop->setEnabled(true);
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
423 424
void MainWindow::slotStopPlaying()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444

    if (extern_recording_enable) {
        int res = QMessageBox::question(this, "action",
                                        "do you wish to stop the recording?", QMessageBox::Discard
                                        | QMessageBox::Yes, QMessageBox::Yes);
        if (res == QMessageBox::Yes) {
            extern_recording_enable = false;
            //currentAction->setText("   Idle   ");
            labelRecording->setText("rec: OFF");

        } else {
            return;
        }
    }

    //shutdown the threads
    //fixme: shut the network thread as well
    // maybe this is a feature !
    extern_shutdown_visual_thread=true;
    waitForVisioThread();
445
    //waitForDataThread();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461

    //reset all frames cursors
    resetAllFrameCursor();

    //disable/reset all graphical elements
    isPlaying = false;
    isPaused = false;
    resetGraphicalElements();
    labelCurrentAction->setText(" Idle ");
}

/**
 * open a file containing visualisation data, parse them
 * and initialize the visualization
 *
 */
Ulrich Kemloh's avatar
Ulrich Kemloh committed
462 463
bool MainWindow::slotLoadFile()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
464 465 466 467
    return slotAddDataSet();
}

// This function is only used in online Mode
468
void MainWindow::parseGeometry(const QDomNode &geoNode)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
469
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
470 471

     Debug::Messages("parsing the geo");
472
    if(geoNode.isNull()) return ;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
473 474 475

    //check if there is a tag 'file' there in
    QString fileName = geoNode.toElement().elementsByTagName("file").item(0).toElement().attribute("location");
476
    auto&& geometry = _visualisationThread->getGeometry();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
477

Ulrich Kemloh's avatar
Ulrich Kemloh committed
478 479
    if(!fileName.isEmpty()) {
        if (fileName.endsWith(".xml",Qt::CaseInsensitive)) {
480
            //parsing the file
481
            SaxParser::parseGeometryJPS(fileName,geometry);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
482
        } else if (fileName.endsWith(".trav",Qt::CaseInsensitive)) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
483 484 485 486 487 488
            //must not be a file name
            SaxParser::parseGeometryTRAV(fileName,geometry);
        }
    }
    // I assume it is a trav format node,
    //which is the only one which can directly be inserted into a file
Ulrich Kemloh's avatar
Ulrich Kemloh committed
489
    else {
490 491 492 493
        //cout<<"online geo: "<<geoNode.toDocument().toString().toStdString()<<endl; exit(0);
        //geoNode.toText().toComment().toDocument().toString()
        QDomDocument doc("");
        QDomNode geoNode;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
494
        if(!geoNode.isNull()) {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
495
             std::cout << "online geo: "<<geoNode.toElement().toDocument().toString().toStdString();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
496
            exit(0);
497 498
        }

Ulrich Kemloh's avatar
Ulrich Kemloh committed
499 500 501
        //must not be a file name
        SaxParser::parseGeometryTRAV(fileName,geometry,geoNode);
    }
502
    //return geometry;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
503 504
}

505
// This function is only used in online Mode
506
void MainWindow::parseGeometry(const QString& geometryString)
507 508
{
    QFile file("_geometry_tmp_file.xml");
509
    if (file.open(QIODevice::ReadWrite | QIODevice::Text)) {
510 511 512 513 514 515 516 517 518 519 520
        QTextStream stream(&file);
        stream << geometryString << endl;
    }

    QString tmpFileName = file.fileName();

    //check if there is a tag 'file' there in
    QString geofileName = SaxParser::extractGeometryFilename(tmpFileName);

    //cout<<"filename: "<<geofileName.toStdString()<<endl;exit(0);

521
    auto&& geometry = _visualisationThread->getGeometry();
522

Ulrich Kemloh's avatar
Ulrich Kemloh committed
523
    if(!geofileName.isEmpty()) {
524
        SystemSettings::CreateLogfile();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
525
        if (geofileName.endsWith(".xml",Qt::CaseInsensitive)) {
526
            //parsing the file
Ulrich Kemloh's avatar
Ulrich Kemloh committed
527 528
            if(!SaxParser::parseGeometryJPS(geofileName,geometry)) {
                SaxParser::parseGeometryXMLV04(geofileName,geometry);
529
            }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
530
        } else if (geofileName.endsWith(".trav",Qt::CaseInsensitive)) {
531 532 533
            //must not be a file name
            SaxParser::parseGeometryTRAV(geofileName,geometry);
        }
534
        SystemSettings::DeleteLogfile();
535 536 537
    }
    // I assume it is a trav format node,
    //which is the only one which can directly be inserted into a file
Ulrich Kemloh's avatar
Ulrich Kemloh committed
538
    else {
539

540
        QDomNode geoNode;
541 542 543 544
        //must not be a file name
        SaxParser::parseGeometryTRAV(geometryString,geometry,geoNode);
    }

545 546 547 548 549 550 551 552 553 554 555 556 557 558
    //workaround. In some cases there are still hlines in the input files which are not parsed.
    if(geofileName.endsWith(".xml",Qt::CaseInsensitive))
    {
        QXmlInputSource source;
        source.setData(geometryString);
        QXmlSimpleReader reader;

        SyncData dummy;
        double fps;
        SaxParser handler(geometry,dummy,&fps);
        reader.setContentHandler(&handler);
        reader.parse(source);
    }

559 560 561 562
    //delete the file
    file.remove();
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
563
// TODO: still used?
Mohcine Chraibi's avatar
Mohcine Chraibi committed
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
// bool MainWindow::parsePedestrianShapes(QDomNode shapeNode, int groupID)
// {

//     if(shapeNode.isNull()) return false;
//     QStringList heights;
//     QStringList colors;

//     QDomNodeList agents = shapeNode.toElement().elementsByTagName("agentInfo");

//     for (int i = 0; i < agents.length(); i++) {

//         bool ok=false;
//         int id=agents.item(i).toElement().attribute("ID").toInt(&ok);
//         if(!ok) continue; // invalid ID
//         double height=agents.item(i).toElement().attribute("height").toDouble(&ok);
//         if(!ok)height=std::numeric_limits<double>::quiet_NaN();

//         int color=agents.item(i).toElement().attribute("color").toDouble(&ok);
//         if(!ok)color=std::numeric_limits<int>::quiet_NaN();
//         Debug::Messages("id= %d height= %lf color =%d",id,height,color);

//         if(height!=height) {
//             heights.append(QString::number(id));
//             heights.append(QString::number(height));
//         }
//         if(color!=color) {
//             colors.append(QString::number(id));
//             colors.append(QString::number(color));
//         }

//     }
//     switch (groupID) {

//     case 1:
//         extern_trajectories_firstSet.setInitialHeights(heights);
//         extern_trajectories_firstSet.setInitialColors(colors);
//         break;
//     }
//     return true;
// }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
604 605

/// add a new dataset
Ulrich Kemloh's avatar
Ulrich Kemloh committed
606 607
bool MainWindow::slotAddDataSet()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
608 609

    // just continue
610
    numberOfDatasetLoaded=1;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
611
    if(addPedestrianGroup(numberOfDatasetLoaded)==false) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
612 613 614 615 616 617 618 619 620
        numberOfDatasetLoaded--;
        return false;
    }

    QString stre(numberOfDatasetLoaded);
    stre.setNum(numberOfDatasetLoaded);
    stre.append(" dataset loaded");
    statusBar()->showMessage(stre);

621 622
    slotStartPlaying();

Ulrich Kemloh's avatar
Ulrich Kemloh committed
623 624 625 626
    return true;
}

///clear all datasets previously entered.
Ulrich Kemloh's avatar
Ulrich Kemloh committed
627 628
void MainWindow::slotClearAllDataset()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
629 630 631 632
    clearDataSet(1);
    numberOfDatasetLoaded=0;
}

633 634
bool MainWindow::addPedestrianGroup(int groupID,QString fileName)
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
635 636
     Debug::Messages("Enter MainWindow::addPedestrianGroup with filename <%s>", fileName.toStdString().c_str());

Ulrich Kemloh's avatar
Ulrich Kemloh committed
637 638 639
    statusBar()->showMessage(tr("Select a file"));
    if(fileName.isEmpty())
        fileName = QFileDialog::getOpenFileName(this,
640
                                                "Select the file containing the data to visualize",
Mohcine Chraibi's avatar
Mohcine Chraibi committed
641 642
                                                QDir::currentPath(),
                                                "Geometry or trajectory files (*.xml);;All Files (*.*)");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
643

644
    //the action was cancelled
Ulrich Kemloh's avatar
Ulrich Kemloh committed
645 646 647
    if (fileName.isNull()) {
        return false;
    }
648 649 650 651

    //get and set the working dir
    QFileInfo fileInfo(fileName);
    QString wd=fileInfo.absoluteDir().absolutePath();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
652
    Debug::Messages("MainWindow::addPedestrianGroup: wd:  <%s>", wd.toStdString().c_str());
653
    SystemSettings::setWorkingDirectory(wd);
654
    SystemSettings::setFilenamePrefix(QFileInfo ( fileName ).baseName()+"_");
655

Ulrich Kemloh's avatar
Ulrich Kemloh committed
656
    //the geometry actor
657
    auto&& geometry = _visualisationThread->getGeometry();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
658
    QString geometry_file;
659
    //try to get a geometry filename
Mohcine Chraibi's avatar
Mohcine Chraibi committed
660 661
    if(fileName.endsWith(".xml",Qt::CaseInsensitive))
    {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
662
         Debug::Messages("1. Extract geometry file from <%s>", fileName.toStdString().c_str());
Mohcine Chraibi's avatar
Mohcine Chraibi committed
663
         geometry_file=SaxParser::extractGeometryFilename(fileName);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
664 665 666
    }
    else
    {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
667
         Debug::Messages("Extract geometry file from <%s>", fileName.toStdString().c_str());
Mohcine Chraibi's avatar
Mohcine Chraibi committed
668
         geometry_file=SaxParser::extractGeometryFilenameTXT(fileName);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
669 670 671
    }


Mohcine Chraibi's avatar
Mohcine Chraibi committed
672
    Debug::Messages("MainWindow::addPedestrianGroup: geometry name: <%s>", geometry_file.toStdString().c_str());
Ulrich Kemloh's avatar
Ulrich Kemloh committed
673
    // if xml is detected, just load and show the geometry then exit
Ulrich Kemloh's avatar
Ulrich Kemloh committed
674
    if(geometry_file.endsWith(".xml",Qt::CaseInsensitive)) {
675 676 677

        //try to parse the correct way
        // fall back to this if it fails
678
        SystemSettings::CreateLogfile();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
679
        Debug::Messages("Calling parseGeometryJPS with <%s>", geometry_file.toStdString().c_str());
Ulrich Kemloh's avatar
Ulrich Kemloh committed
680
        if(! SaxParser::parseGeometryJPS(geometry_file,geometry)) {
681 682 683 684 685 686 687 688 689 690 691 692 693
            int res = QMessageBox::warning(this, "Errors in Geometry. Continue Parsing?",
                                           "JuPedSim has detected an error in the supplied geometry.\n"
                                           "The simulation will likely failed using that geometry.\n"
                                           "Also make sure to validate your file.\n"
                                           "More information are provided in the log file:\n"
                                           +SystemSettings::getLogfile()+
                                           "\n\nShould I try to parse and display what I can ?"
                                           , QMessageBox::Yes
                                           | QMessageBox::No, QMessageBox::No);
            if (res == QMessageBox::No) {
                return false;
            }
            SaxParser::parseGeometryXMLV04(wd+"/"+geometry_file,geometry);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
694 695
        } else {
            //everything was fine. Delete the log file
Mohcine Chraibi's avatar
Mohcine Chraibi committed
696 697
             //std::cout << "won't delete logfile\n";
            SystemSettings::DeleteLogfile();
698
        }
699

700
        //SaxParser::parseGeometryXMLV04(fileName,geometry);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
701 702 703 704
        //slotLoadParseShowGeometry(fileName);
        //return false;
    }

705 706 707 708 709 710 711 712
    //check if it is vtrk file containinf gradient
    if(fileName.endsWith(".vtk",Qt::CaseInsensitive))
    {
        if (false==SaxParser::ParseGradientFieldVTK(fileName,geometry))
            return false;

    }

Ulrich Kemloh's avatar
Ulrich Kemloh committed
713 714
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly)) {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
715
        Debug::Error("parseGeometryJPS:  could not open the File: ",fileName.toStdString().c_str());
Ulrich Kemloh's avatar
Ulrich Kemloh committed
716
        return false;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
717

Ulrich Kemloh's avatar
Ulrich Kemloh committed
718 719 720
    }

    SyncData* dataset=NULL;
721
    extern_trajectories_firstSet.clearFrames();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
722

Ulrich Kemloh's avatar
Ulrich Kemloh committed
723
    switch(groupID) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
724 725 726 727 728 729 730 731 732 733 734
    case 1:
        Debug::Messages("handling first set");
        dataset=&extern_trajectories_firstSet;
        extern_first_dataset_loaded=true;
        extern_first_dataset_visible=true;
        ui.actionFirst_Group->setEnabled(true);
        ui.actionFirst_Group->setChecked(true);
        slotToggleFirstPedestrianGroup();
        break;

    default:
735
        Debug::Error("Only one dataset can be loaded at a time");
736
        //return false;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
737 738 739
        break;
    }

740
    //no other geometry format was detected
Mohcine Chraibi's avatar
Mohcine Chraibi committed
741
    double frameRate=16; //default frame rate
Ulrich Kemloh's avatar
Ulrich Kemloh committed
742 743 744
    statusBar()->showMessage(tr("parsing the file"));


745 746 747 748 749
    //parsing the xml file
    if(fileName.endsWith(".xml",Qt::CaseInsensitive))
    {
        QXmlInputSource source(&file);
        QXmlSimpleReader reader;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
750

751
        SaxParser handler(geometry,*dataset,&frameRate);
752 753 754 755
        reader.setContentHandler(&handler);
        reader.parse(source);
        file.close();
    }
756 757 758 759 760 761 762
    //parsing the vtk file
//    else if(fileName.endsWith(".vtk",Qt::CaseInsensitive))
//    {
//        if (false==SaxParser::ParseGradientFieldVTK(fileName,geometry))
//            return false;

//    }
763
    // try to parse the txt file
764
    else if(fileName.endsWith(".txt",Qt::CaseInsensitive))
765 766 767 768
    {
        if(false==SaxParser::ParseTxtFormat(fileName, dataset,&frameRate))
            return false;
    }
769

770 771

    QString frameRateStr=QString::number(frameRate);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
772
    // set the visualisation window title
773 774
    _visualisationThread->setWindowTitle(fileName);
    _visualisationThread->slotSetFrameRate(frameRate);
775
    //visualisationThread->setGeometry(geometry);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
776 777 778 779 780 781 782 783 784 785 786 787
    //visualisationThread->setWindowTitle(caption);
    labelFrameNumber->setText("fps: " + frameRateStr+"/"+frameRateStr);

    //shutdown the visio thread
    extern_shutdown_visual_thread=true;
    waitForVisioThread();

    statusBar()->showMessage(tr("file loaded and parsed"));

    return true;
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
788 789
void MainWindow::slotRecord()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
790 791 792 793 794 795 796 797 798 799

    if (extern_recording_enable) {
        int res = QMessageBox::warning(this, "action",
                                       "JuPedSim is already recording a video\n"
                                       "do you wish to stop the recording?", QMessageBox::Yes
                                       | QMessageBox::No, QMessageBox::No);
        if (res == QMessageBox::Yes) {
            extern_recording_enable = false;
            ui.BtRecord->setToolTip("Start Recording");
            labelCurrentAction->setText("   Playing   ");
800
            labelRecording->setText(" rec: off ");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
801 802 803 804 805
            return;
        }
    }
    extern_launch_recording = true;
    ui.BtRecord->setToolTip("Stop Recording");
806
    labelRecording->setText(" rec: on ");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
807 808 809 810 811
    //labelCurrentAction->setText("   recording   ");

}

QString MainWindow::getTagValueFromElement(QDomNode node,
812
                                           const char * tagName)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
813
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
814 815 816 817 818 819
    if (node.isNull())
        return "";
    return node.toElement().namedItem(tagName).firstChild().nodeValue();

}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
820 821
void MainWindow::slotFullScreen(bool status)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
822 823

    Debug::Messages("changing full screen status %d",status);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
824
    extern_fullscreen_enable = true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
825 826 827 828
    //dont forget this.
    extern_force_system_update=true;
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
829 830
void MainWindow::slotSetOfflineMode(bool status)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
831 832 833 834 835 836 837 838 839 840 841
    if (status) {
        ui.actionOnline->setChecked(false);
        extern_offline_mode = true;
        labelMode->setText(" Offline ");
    } else {
        ui.actionOnline->setChecked(true);
        extern_offline_mode = false;
        labelMode->setText(" Online ");
    }
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
842 843
void MainWindow::slotSetOnlineMode(bool status)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
844 845 846 847 848 849 850 851 852 853 854 855
    if (status) {
        ui.actionOffline->setChecked(false);
        extern_offline_mode = false;
        labelMode->setText(" Online  ");
    } else {
        ui.actionOffline->setChecked(true);
        extern_offline_mode = true;
        labelMode->setText(" Offline ");

    }
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
856 857
void MainWindow::slotReset()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
858 859 860 861 862 863 864 865 866

    //stop any recording
    if (extern_recording_enable) {
        int res = QMessageBox::question(this, "action",
                                        "do you wish to stop the recording?", QMessageBox::Discard
                                        | QMessageBox::Yes, QMessageBox::Yes);
        if (res == QMessageBox::Yes) {
            extern_recording_enable = false;
            labelCurrentAction->setText("   Playing   ");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
867
        } else {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
868 869 870 871
            return;
        }
    }

Ulrich Kemloh's avatar
Ulrich Kemloh committed
872
    if(anyDatasetLoaded()) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
        int res = QMessageBox::question(this, "action",
                                        "This will also clear any dataset if loaded.\n"
                                        "Do you wish to continue?", QMessageBox::Discard
                                        | QMessageBox::Yes, QMessageBox::Yes);
        if (res == QMessageBox::No) {
            return;
        }
    }


    //shutdown the visual thread
    extern_shutdown_visual_thread = true;
    waitForVisioThread();
    waitForDataThread();

    //reset all buttons
    //anyDataLoaded = false;
    slotClearAllDataset();
    isPlaying = false;
    isPaused  = false;
    labelCurrentAction->setText("   Idle   ");
    resetGraphicalElements();

}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
898 899
void MainWindow::slotCurrentAction(QString msg)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
900 901 902 903 904 905
    msg = " " + msg + " ";
    //labelCurrentAction->setText(msg);
    statusBar()->showMessage(msg);
    //	labelMode->setText(msg);
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
906 907
void MainWindow::slotFrameNumber(unsigned long actualFrameCount)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
908 909 910

    //compute the  mamixum framenumber
    int maxFrameCount=1;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
911
    if(extern_first_dataset_loaded) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
912 913 914
        maxFrameCount=extern_trajectories_firstSet.getFramesNumber();
    }

915 916 917 918 919
    if(actualFrameCount>maxFrameCount) actualFrameCount=maxFrameCount;
    QString msg;
    msg.setNum(actualFrameCount);
    ui.frameSliderLabel->setText("Frame: " + msg);

Ulrich Kemloh's avatar
Ulrich Kemloh committed
920
    if(!frameSliderHold)if(maxFrameCount!=0)//TODO WTF, otherwise an arrymtic exeption arises
921
        ui.framesIndicatorSlider->setValue((ui.framesIndicatorSlider->maximum()*actualFrameCount)/maxFrameCount);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
922 923
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
924 925
void MainWindow::slotRunningTime(unsigned long timems)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
926 927 928 929 930 931 932 933 934 935 936 937
    //	QString msg;
    //	msg.setNum(timems);
    //	msg.append(" milsec");
    //labelRunningTime->setText(msg);
    ui.lcdRunningTime->display((int)timems);
}

void MainWindow::slotRenderingTime(int fps)
{
    QString msg =labelFrameNumber->text().replace(QRegExp("[0-9]+/"),QString::number(fps)+"/");
    labelFrameNumber->setText(msg);
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
938 939
void MainWindow::slotExit()
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
940
     Debug::Messages("Exit jpsvis");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
941 942 943 944
    cleanUp();
    qApp->exit();
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
945 946
void MainWindow::closeEvent(QCloseEvent* event)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
947 948 949 950 951
    hide();
    cleanUp();
    event->accept();
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
952 953
void MainWindow::cleanUp()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
954 955 956 957 958 959 960 961 962 963 964 965
    //stop the recording process
    extern_recording_enable = false;
    extern_shutdown_visual_thread = true;

    if(SystemSettings::getRecordPNGsequence())
        slotRecordPNGsequence();

    waitForVisioThread();
    waitForDataThread();

}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
966 967
void MainWindow::slotControlSequence(const char * sex)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
    QString str(sex);

    //todo: check wich stack is empty and disable
    // the correspinding datasets.
    // are all stacks empty? then stop
    // visualisation adn recording if any
    if (str.compare("CONTROL_STACK_EMPTY") == 0) {

        statusBar()->showMessage(tr(" stack empty "));
        extern_recording_enable = false;
        ui.BtRecord->setToolTip("Start Recording");
        labelRecording->setText(" rec: off ");
    } else if (str.compare("CONTROL_RESET") == 0) {
        Debug::Messages("resetting all");
        isPlaying = false;
        isPaused = false;
        labelCurrentAction->setText("   Idle   ");
        extern_update_step=1;
        //extern_screen_contrast=1;

        //reset the frames cursor
        extern_trajectories_firstSet.resetFrameCursor();

        resetGraphicalElements();

Ulrich Kemloh's avatar
Ulrich Kemloh committed
993
    } else if (str.compare("STACK_REACHS_BEGINNING")==0) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
994
        //return to normal speed
Ulrich Kemloh's avatar
Ulrich Kemloh committed
995
        if(extern_update_step<0) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
996 997 998 999 1000 1001 1002 1003
            Debug::Messages("stack reaches beginning, resuming the playback with vel 1");
            extern_update_step=1;
            ui.speedSettingSlider->setValue(1);
        }

    }
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
1004 1005
void MainWindow::resetGraphicalElements()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
    //restore play button
    QIcon icon1;
    icon1.addPixmap(QPixmap(
                        QString::fromUtf8(":/new/iconsS/icons/Play1Hot.png")),
                    QIcon::Normal, QIcon::Off);
    ui.BtStart->setIcon(icon1);

    //disable record button
    ui.BtRecord->setEnabled(false);

    //disable fullscreen
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1017
    //ui.BtFullscreen->setEnabled(false);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039

    //disable stop button

    ui.BtStop->setEnabled(false);
    //reset the slider
    ui.framesIndicatorSlider->setValue(ui.framesIndicatorSlider->minimum());

    //reset the speed cursor
    ui.speedSettingSlider->setValue(1);
    //reset the contrast

    // bla bla
    ui.actionShow_Legend->setEnabled(true);

    //restore the play Icon

    //
    ui.actionShow_Trajectories->setEnabled(true);

    ui.action3_D->setEnabled(true);
    ui.action2_D->setEnabled(true);

1040
    labelRecording->setText("rec: off");
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1041 1042 1043 1044 1045 1046 1047 1048 1049
    statusBar()->showMessage(tr("select a File"));

    //resetting the start/stop recording action
    //check whether the a png recording sequence was playing, stop if the case
    if(SystemSettings::getRecordPNGsequence())
        slotRecordPNGsequence();

}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
1050 1051 1052
void MainWindow::slotToggleFirstPedestrianGroup()
{
    if(ui.actionFirst_Group->isChecked()) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1053
        extern_first_dataset_visible=true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1054
    } else {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1055 1056 1057 1058 1059 1060
        extern_first_dataset_visible=false;
    }
    extern_force_system_update=true;

}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
1061 1062
bool MainWindow::anyDatasetLoaded()
{
1063
    return extern_first_dataset_loaded;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1064 1065
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
1066 1067
void MainWindow::slotShowTrajectoryOnly()
{
1068
    SystemSettings::setShowTrajectories(ui.actionShow_Trajectories->isChecked());
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1069
    extern_force_system_update=true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1070 1071
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
1072 1073 1074
void MainWindow::slotShowPedestrianOnly()
{

Ulrich Kemloh's avatar
Ulrich Kemloh committed
1075
    if(ui.actionShow_Agents->isChecked()) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1076
        SystemSettings::setShowAgents(true);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1077
    } else {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1078 1079 1080
        SystemSettings::setShowAgents(false);
    }
    extern_force_system_update=true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1081 1082
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
1083 1084 1085
void MainWindow::slotShowGeometry()
{
    if (ui.actionShow_Geometry->isChecked()) {
1086
        _visualisationThread->setGeometryVisibility(true);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1087 1088
        ui.actionShow_Exits->setEnabled(true);
        ui.actionShow_Walls->setEnabled(true);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1089
        ui.actionShow_Geometry_Captions->setEnabled(true);
1090
        ui.actionShow_Navigation_Lines->setEnabled(true);
1091
        ui.actionShow_Floor->setEnabled(true);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1092
        SystemSettings::setShowGeometry(true);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1093
    } else {
1094
        _visualisationThread->setGeometryVisibility(false);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1095 1096
        ui.actionShow_Exits->setEnabled(false);
        ui.actionShow_Walls->setEnabled(false);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1097
        ui.actionShow_Geometry_Captions->setEnabled(false);
1098
        ui.actionShow_Navigation_Lines->setEnabled(false);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1099
        ui.actionShow_Floor->setEnabled(false);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1100
        SystemSettings::setShowGeometry(false);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1101
    }
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1102
    extern_force_system_update=true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1103 1104 1105
}

/// shows/hide geometry
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1106 1107
void MainWindow::slotShowHideExits()
{
1108
    bool status = ui.actionShow_Exits->isChecked();
1109
    _visualisationThread->showDoors(status);
1110
    SystemSettings::setShowExits(status);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1111 1112 1113
}

/// shows/hide geometry
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1114 1115
void MainWindow::slotShowHideWalls()
{
1116
    bool status = ui.actionShow_Walls->isChecked();
1117
    _visualisationThread->showWalls(status);
1118
    SystemSettings::setShowWalls(status);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1119 1120
}

1121 1122
void MainWindow::slotShowHideNavLines()
{
1123
    bool status = ui.actionShow_Navigation_Lines->isChecked();
1124
    _visualisationThread->showNavLines(status);
1125
    SystemSettings::setShowNavLines(status);
1126 1127
}

1128 1129 1130 1131
//todo: add to the system settings
void MainWindow::slotShowHideFloor()
{
    bool status = ui.actionShow_Floor->isChecked();
1132
    _visualisationThread->showFloor(status);
1133 1134 1135
    SystemSettings::setShowFloor(status);
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
1136 1137

/// update the playing speed
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1138 1139
void MainWindow::slotUpdateSpeedSlider(int newValue)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1140 1141 1142 1143 1144 1145 1146 1147
    QString msg;
    msg.setNum(newValue);
    extern_update_step=newValue;
    //Debug::Error( " speed updated to: %d", extern_update_step);
    ui.speedSliderLabel->setText("Speed: " + msg + " ");
}

/// update the position slider
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1148 1149
void MainWindow::slotUpdateFrameSlider(int newValue)
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1150 1151 1152

    // first get the correct position
    int maxFrameCount=1;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1153
    if(extern_first_dataset_loaded) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1154 1155 1156 1157 1158 1159 1160
        int t=extern_trajectories_firstSet.getFramesNumber();
        if(maxFrameCount<t) maxFrameCount=t;
    }

    int update = ((maxFrameCount*newValue)/ui.framesIndicatorSlider->maximum());

    // then set the correct position
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1161
    if(extern_first_dataset_loaded) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1162 1163 1164 1165 1166 1167 1168 1169
        extern_trajectories_firstSet.setFrameCursorTo(update);
        //Debug::Error( " first dataset frames update to [1] : " <<update<<endl;

    }
}

/// update the contrast
/// TODO: now known as framePerScond slider