MainWindow.cc 38.8 KB
Newer Older
1
/*===================================================================
pixhawk's avatar
pixhawk committed
2 3 4 5
======================================================================*/

/**
 * @file
6
 *   @brief Implementation of class MainWindow
7
 *   @author Lorenz Meier <mail@qgroundcontrol.org>
pixhawk's avatar
pixhawk committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 */

#include <QSettings>
#include <QDockWidget>
#include <QNetworkInterface>
#include <QMessageBox>
#include <QDebug>
#include <QTimer>
#include <QHostInfo>

#include "MG.h"
#include "MAVLinkSimulationLink.h"
#include "SerialLink.h"
#include "UDPLink.h"
#include "MAVLinkProtocol.h"
#include "CommConfigurationWindow.h"
#include "WaypointList.h"
#include "MainWindow.h"
#include "JoystickWidget.h"
pixhawk's avatar
pixhawk committed
27
#include "GAudioOutput.h"
28

29
#ifdef QGC_OSG_ENABLED
30
#include "Q3DWidgetFactory.h"
31
#endif
pixhawk's avatar
pixhawk committed
32

lm's avatar
lm committed
33 34 35 36
// FIXME Move
#include "PxQuadMAV.h"
#include "SlugsMAV.h"

pixhawk's avatar
pixhawk committed
37 38 39 40 41 42 43 44 45 46

#include "LogCompressor.h"

/**
* Create new mainwindow. The constructor instantiates all parts of the user
* interface. It does NOT show the mainwindow. To display it, call the show()
* method.
*
* @see QMainWindow::show()
**/
47
MainWindow::MainWindow(QWidget *parent) :
pixhawk's avatar
pixhawk committed
48 49
        QMainWindow(parent),
        settings()
pixhawk's avatar
pixhawk committed
50
{
51 52 53
    this->hide();
    this->setVisible(false);

pixhawk's avatar
pixhawk committed
54 55 56
    // Setup user interface
    ui.setupUi(this);

57 58 59 60 61 62 63
    buildWidgets();

    connectWidgets();

    arrangeCenterStack();

    configureWindowName();
pixhawk's avatar
pixhawk committed
64 65

    // Add status bar
66
    //setStatusBar(createStatusBar());
pixhawk's avatar
pixhawk committed
67 68 69 70

    // Set the application style (not the same as a style sheet)
    // Set the style to Plastique
    qApp->setStyle("plastique");
71

pixhawk's avatar
pixhawk committed
72 73 74 75
    // Set style sheet as last step
    reloadStylesheet();


76 77 78
    // Create actions
    connectActions();

79
    // Load widgets and show application windowa
80 81 82 83
    loadWidgets();

    // Adjust the size
    adjustSize();
pixhawk's avatar
pixhawk committed
84 85
}

pixhawk's avatar
pixhawk committed
86
MainWindow::~MainWindow()
pixhawk's avatar
pixhawk committed
87 88 89 90 91
{
    delete statusBar;
    statusBar = NULL;
}

92 93 94

void MainWindow::buildWidgets()
{
pixhawk's avatar
pixhawk committed
95 96 97 98 99 100 101 102
    //FIXME: memory of acceptList will never be freed again
    QStringList* acceptList = new QStringList();
    acceptList->append("roll IMU");
    acceptList->append("pitch IMU");
    acceptList->append("yaw IMU");
    acceptList->append("rollspeed IMU");
    acceptList->append("pitchspeed IMU");
    acceptList->append("yawspeed IMU");
103

pixhawk's avatar
pixhawk committed
104 105 106 107
    //FIXME: memory of acceptList2 will never be freed again
    QStringList* acceptList2 = new QStringList();
    acceptList2->append("Battery");
    acceptList2->append("Pressure");
108

pixhawk's avatar
pixhawk committed
109 110
    //TODO:  move protocol outside UI
    mavlink     = new MAVLinkProtocol();
111

pixhawk's avatar
pixhawk committed
112 113
    // Center widgets
    linechartWidget   = new Linecharts(this);
114
    hudWidget         = new HUD(320, 240, this);
pixhawk's avatar
pixhawk committed
115 116 117
    mapWidget         = new MapWidget(this);
    protocolWidget    = new XMLCommProtocolWidget(this);
    dataplotWidget    = new QGCDataPlot2D(this);
118
#ifdef QGC_OSG_ENABLED
119
    _3DWidget         = Q3DWidgetFactory::get("PIXHAWK");
120
#endif
121

122 123 124
#ifdef QGC_OSGEARTH_ENABLED
    _3DMapWidget = Q3DWidgetFactory::get("MAP3D");
#endif
125
#if (defined Q_OS_WIN) | (defined Q_OS_MAC)
pixhawk's avatar
pixhawk committed
126
    gEarthWidget = new QGCGoogleEarthView(this);
127
#endif
128

pixhawk's avatar
pixhawk committed
129 130 131
    // Dock widgets
    controlDockWidget = new QDockWidget(tr("Control"), this);
    controlDockWidget->setWidget( new UASControlWidget(this) );
132

pixhawk's avatar
pixhawk committed
133 134
    listDockWidget = new QDockWidget(tr("Unmanned Systems"), this);
    listDockWidget->setWidget( new UASListWidget(this) );
135

pixhawk's avatar
pixhawk committed
136 137
    waypointsDockWidget = new QDockWidget(tr("Waypoint List"), this);
    waypointsDockWidget->setWidget( new WaypointList(this, NULL) );
138

pixhawk's avatar
pixhawk committed
139 140
    infoDockWidget = new QDockWidget(tr("Status Details"), this);
    infoDockWidget->setWidget( new UASInfoWidget(this) );
141

pixhawk's avatar
pixhawk committed
142 143
    detectionDockWidget = new QDockWidget(tr("Object Recognition"), this);
    detectionDockWidget->setWidget( new ObjectDetectionView("images/patterns", this) );
144

pixhawk's avatar
pixhawk committed
145 146
    debugConsoleDockWidget = new QDockWidget(tr("Communication Console"), this);
    debugConsoleDockWidget->setWidget( new DebugConsole(this) );
147

pixhawk's avatar
pixhawk committed
148 149
    parametersDockWidget = new QDockWidget(tr("Onboard Parameters"), this);
    parametersDockWidget->setWidget( new ParameterInterface(this) );
150

pixhawk's avatar
pixhawk committed
151 152
    watchdogControlDockWidget = new QDockWidget(tr("Process Control"), this);
    watchdogControlDockWidget->setWidget( new WatchdogControl(this) );
153

pixhawk's avatar
pixhawk committed
154 155
    hsiDockWidget = new QDockWidget(tr("Horizontal Situation Indicator"), this);
    hsiDockWidget->setWidget( new HSIDisplay(this) );
156

pixhawk's avatar
pixhawk committed
157 158
    headDown1DockWidget = new QDockWidget(tr("Primary Flight Display"), this);
    headDown1DockWidget->setWidget( new HDDisplay(acceptList, this) );
159

pixhawk's avatar
pixhawk committed
160 161
    headDown2DockWidget = new QDockWidget(tr("Payload Status"), this);
    headDown2DockWidget->setWidget( new HDDisplay(acceptList2, this) );
162

pixhawk's avatar
pixhawk committed
163 164
    rcViewDockWidget = new QDockWidget(tr("Radio Control"), this);
    rcViewDockWidget->setWidget( new QGCRemoteControlView(this) );
165

166 167 168
    headUpDockWidget = new QDockWidget(tr("Control Indicator"), this);
    headUpDockWidget->setWidget( new HUD(320, 240, this));

pixhawk's avatar
pixhawk committed
169 170 171
    // Dialogue widgets
    //FIXME: free memory in destructor
    joystick    = new JoystickInput();
172

173 174 175
    slugsDataWidget = new QDockWidget(tr("Slugs Data"), this);
    slugsDataWidget->setWidget( new SlugsDataSensorView(this));

176 177 178
    slugsPIDControlWidget = new QDockWidget(tr("PID Control"), this);
    slugsPIDControlWidget->setWidget(new SlugsPIDControl(this));

179 180
    slugsHilSimWidget = new QDockWidget(tr("Slugs Hil Sim"), this);
    slugsHilSimWidget->setWidget( new SlugsHilSim(this));
181

182 183 184
    slugsCamControlWidget = new QDockWidget(tr("Video Camera Control"), this);
    slugsCamControlWidget->setWidget(new SlugsVideoCamControl(this));

185 186
}

pixhawk's avatar
pixhawk committed
187 188 189
/**
 * Connect all signals and slots of the main window widgets
 */
190 191
void MainWindow::connectWidgets()
{
pixhawk's avatar
pixhawk committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
    if (linechartWidget)
    {
        connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)),
                linechartWidget, SLOT(addSystem(UASInterface*)));
        connect(UASManager::instance(), SIGNAL(activeUASSet(int)),
                linechartWidget, SLOT(selectSystem(int)));
        connect(linechartWidget, SIGNAL(logfileWritten(QString)),
                this, SLOT(loadDataView(QString)));
    }
    if (infoDockWidget && infoDockWidget->widget())
    {
        connect(mavlink, SIGNAL(receiveLossChanged(int, float)),
                infoDockWidget->widget(), SLOT(updateSendLoss(int, float)));
    }
    if (mapWidget && waypointsDockWidget->widget())
    {
        // clear path create on the map
        connect(waypointsDockWidget->widget(), SIGNAL(clearPathclicked()), mapWidget, SLOT(clearPath()));
        // add Waypoint widget in the WaypointList widget when mouse clicked
        connect(mapWidget, SIGNAL(captureMapCoordinateClick(QPointF)), waypointsDockWidget->widget(), SLOT(addWaypointMouse(QPointF)));
        // it notifies that a waypoint global goes to do create
213 214
        //connect(mapWidget, SIGNAL(createGlobalWP(bool, QPointF)), waypointsDockWidget->widget(), SLOT(setIsWPGlobal(bool, QPointF)));
        //connect(mapWidget, SIGNAL(sendGeometryEndDrag(QPointF,int)), waypointsDockWidget->widget(), SLOT(waypointGlobalChanged(QPointF,int)) );
215 216 217

        // it notifies that a waypoint global goes to do create and a map graphic too
        connect(waypointsDockWidget->widget(), SIGNAL(createWaypointAtMap(QPointF)), mapWidget, SLOT(createWaypointGraphAtMap(QPointF)));
218
        // it notifies that a waypoint global change it¥s position by spinBox on Widget WaypointView
219
        //connect(waypointsDockWidget->widget(), SIGNAL(changePositionWPGlobalBySpinBox(int,float,float)), mapWidget, SLOT(changeGlobalWaypointPositionBySpinBox(int,float,float)));
220
       // connect(waypointsDockWidget->widget(), SIGNAL(changePositionWPGlobalBySpinBox(int,float,float)), mapWidget, SLOT(changeGlobalWaypointPositionBySpinBox(int,float,float)));
221 222 223

        connect(slugsCamControlWidget->widget(),SIGNAL(viewCamBorderAtMap(bool)),mapWidget,SLOT(drawBorderCamAtMap(bool)));
         connect(slugsCamControlWidget->widget(),SIGNAL(changeCamPosition(double,double,QString)),mapWidget,SLOT(updateCameraPosition(double,double, QString)));
pixhawk's avatar
pixhawk committed
224
    }
225

226 227 228 229 230 231 232 233
    if (slugsHilSimWidget && slugsHilSimWidget->widget()){
      connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)),
              slugsHilSimWidget->widget(), SLOT(activeUasSet(UASInterface*)));
    }

    if (slugsDataWidget && slugsDataWidget->widget()){
      connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)),
              slugsDataWidget->widget(), SLOT(setActiveUAS(UASInterface*)));
234 235
    }

236

237 238
}

239 240
void MainWindow::arrangeCenterStack()
{
241

pixhawk's avatar
pixhawk committed
242 243 244 245 246
    QStackedWidget *centerStack = new QStackedWidget(this);
    if (!centerStack) return;
    if (linechartWidget) centerStack->addWidget(linechartWidget);
    if (protocolWidget) centerStack->addWidget(protocolWidget);
    if (mapWidget) centerStack->addWidget(mapWidget);
247
#ifdef QGC_OSG_ENABLED
248
    if (_3DWidget) centerStack->addWidget(_3DWidget);
249
#endif
250
#ifdef QGC_OSGEARTH_ENABLED
251
    if (_3DMapWidget) centerStack->addWidget(_3DMapWidget);
252 253
#endif
#if (defined Q_OS_WIN) | (defined Q_OS_MAC)
pixhawk's avatar
pixhawk committed
254
    if (gEarthWidget) centerStack->addWidget(gEarthWidget);
255
#endif
pixhawk's avatar
pixhawk committed
256 257
    if (hudWidget) centerStack->addWidget(hudWidget);
    if (dataplotWidget) centerStack->addWidget(dataplotWidget);
258

pixhawk's avatar
pixhawk committed
259
    setCentralWidget(centerStack);
260 261
}

262 263
void MainWindow::configureWindowName()
{
pixhawk's avatar
pixhawk committed
264 265 266
    QList<QHostAddress> hostAddresses = QNetworkInterface::allAddresses();
    QString windowname = qApp->applicationName() + " " + qApp->applicationVersion();
    bool prevAddr = false;
267

pixhawk's avatar
pixhawk committed
268
    windowname.append(" (" + QHostInfo::localHostName() + ": ");
269

pixhawk's avatar
pixhawk committed
270 271 272 273 274 275 276 277 278 279
    for (int i = 0; i < hostAddresses.size(); i++)
    {
        // Exclude loopback IPv4 and all IPv6 addresses
        if (hostAddresses.at(i) != QHostAddress("127.0.0.1") && !hostAddresses.at(i).toString().contains(":"))
        {
            if(prevAddr) windowname.append("/");
            windowname.append(hostAddresses.at(i).toString());
            prevAddr = true;
        }
    }
280

pixhawk's avatar
pixhawk committed
281
    windowname.append(")");
282

pixhawk's avatar
pixhawk committed
283
    setWindowTitle(windowname);
284 285

#ifndef Q_WS_MAC
pixhawk's avatar
pixhawk committed
286
    //qApp->setWindowIcon(QIcon(":/core/images/qtcreator_logo_128.png"));
287 288 289
#endif
}

pixhawk's avatar
pixhawk committed
290
QStatusBar* MainWindow::createStatusBar()
pixhawk's avatar
pixhawk committed
291 292 293 294 295 296 297 298
{
    QStatusBar* bar = new QStatusBar();
    /* Add status fields and messages */
    /* Enable resize grip in the bottom right corner */
    bar->setSizeGripEnabled(true);
    return bar;
}

pixhawk's avatar
pixhawk committed
299
void MainWindow::startVideoCapture()
pixhawk's avatar
pixhawk committed
300 301 302 303 304 305 306 307 308 309 310
{
    QString format = "bmp";
    QString initialPath = QDir::currentPath() + tr("/untitled.") + format;

    QString screenFileName = QFileDialog::getSaveFileName(this, tr("Save As"),
                                                          initialPath,
                                                          tr("%1 Files (*.%2);;All Files (*)")
                                                          .arg(format.toUpper())
                                                          .arg(format));
    delete videoTimer;
    videoTimer = new QTimer(this);
311 312 313
    //videoTimer->setInterval(40);
    //connect(videoTimer, SIGNAL(timeout()), this, SLOT(saveScreen()));
    //videoTimer->stop();
pixhawk's avatar
pixhawk committed
314 315
}

pixhawk's avatar
pixhawk committed
316
void MainWindow::stopVideoCapture()
pixhawk's avatar
pixhawk committed
317 318 319 320 321 322
{
    videoTimer->stop();

    // TODO Convert raw images to PNG
}

pixhawk's avatar
pixhawk committed
323
void MainWindow::saveScreen()
pixhawk's avatar
pixhawk committed
324 325 326 327 328 329 330 331 332 333
{
    QPixmap window = QPixmap::grabWindow(this->winId());
    QString format = "bmp";

    if (!screenFileName.isEmpty())
    {
        window.save(screenFileName, format.toAscii());
    }
}

334 335 336 337 338 339
/**
 * Reload the style sheet from disk. The function tries to load "qgroundcontrol.css" from the application
 * directory (which by default does not exist). If it fails, it will load the bundled default CSS
 * from memory.
 * To customize the application, just create a qgroundcontrol.css file in the application directory
 */
pixhawk's avatar
pixhawk committed
340
void MainWindow::reloadStylesheet()
pixhawk's avatar
pixhawk committed
341 342
{
    // Load style sheet
343 344 345 346 347
    QFile* styleSheet = new QFile(QCoreApplication::applicationDirPath() + "/qgroundcontrol.css");
    if (!styleSheet->exists())
    {
        styleSheet = new QFile(":/images/style-mission.css");
    }
348 349
    if (styleSheet->open(QIODevice::ReadOnly | QIODevice::Text))
    {
350 351
        QString style = QString(styleSheet->readAll());
        style.replace("ICONDIR", QCoreApplication::applicationDirPath()+ "/images/");
pixhawk's avatar
pixhawk committed
352
        qApp->setStyleSheet(style);
353 354 355
    }
    else
    {
356
        qDebug() << "Style not set:" << styleSheet->fileName() << "opened: " << styleSheet->isOpen();
pixhawk's avatar
pixhawk committed
357
    }
358
    delete styleSheet;
pixhawk's avatar
pixhawk committed
359 360
}

pixhawk's avatar
pixhawk committed
361
void MainWindow::showStatusMessage(const QString& status, int timeout)
pixhawk's avatar
pixhawk committed
362
{
lm's avatar
lm committed
363 364
    Q_UNUSED(status);
    Q_UNUSED(timeout);
365
    //statusBar->showMessage(status, timeout);
pixhawk's avatar
pixhawk committed
366 367
}

368
void MainWindow::showStatusMessage(const QString& status)
pixhawk's avatar
pixhawk committed
369
{
lm's avatar
lm committed
370
    Q_UNUSED(status);
371
    //statusBar->showMessage(status, 5);
pixhawk's avatar
pixhawk committed
372 373 374 375 376 377
}

/**
* @brief Create all actions associated to the main window
*
**/
pixhawk's avatar
pixhawk committed
378
void MainWindow::connectActions()
pixhawk's avatar
pixhawk committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
{
    // Connect actions from ui
    connect(ui.actionAdd_Link, SIGNAL(triggered()), this, SLOT(addLink()));

    // Connect internal actions
    connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(UASCreated(UASInterface*)));

    // Connect user interface controls
    connect(ui.actionLiftoff, SIGNAL(triggered()), UASManager::instance(), SLOT(launchActiveUAS()));
    connect(ui.actionLand, SIGNAL(triggered()), UASManager::instance(), SLOT(returnActiveUAS()));
    connect(ui.actionEmergency_Land, SIGNAL(triggered()), UASManager::instance(), SLOT(stopActiveUAS()));
    connect(ui.actionEmergency_Kill, SIGNAL(triggered()), UASManager::instance(), SLOT(killActiveUAS()));

    connect(ui.actionConfiguration, SIGNAL(triggered()), UASManager::instance(), SLOT(configureActiveUAS()));

    // User interface actions
    connect(ui.actionPilotView, SIGNAL(triggered()), this, SLOT(loadPilotView()));
    connect(ui.actionEngineerView, SIGNAL(triggered()), this, SLOT(loadEngineerView()));
    connect(ui.actionOperatorView, SIGNAL(triggered()), this, SLOT(loadOperatorView()));
398
#ifdef QGC_OSG_ENABLED
399
    connect(ui.action3DView, SIGNAL(triggered()), this, SLOT(load3DView()));
400 401 402 403 404
#else
    ui.menuWindow->removeAction(ui.action3DView);
#endif

#ifdef QGC_OSGEARTH_ENABLED
405
    connect(ui.action3DMapView, SIGNAL(triggered()), this, SLOT(load3DMapView()));
406 407 408
#else
    ui.menuWindow->removeAction(ui.action3DMapView);
#endif
409
    connect(ui.actionShow_full_view, SIGNAL(triggered()), this, SLOT(loadAllView()));
410
    connect(ui.actionShow_MAVLink_view, SIGNAL(triggered()), this, SLOT(loadMAVLinkView()));
411
    connect(ui.actionShow_data_analysis_view, SIGNAL(triggered()), this, SLOT(loadDataView()));
pixhawk's avatar
pixhawk committed
412
    connect(ui.actionStyleConfig, SIGNAL(triggered()), this, SLOT(reloadStylesheet()));
413
    connect(ui.actionGlobalOperatorView, SIGNAL(triggered()), this, SLOT(loadGlobalOperatorView()));
414 415 416
    connect(ui.actionOnline_documentation, SIGNAL(triggered()), this, SLOT(showHelp()));
    connect(ui.actionCredits_Developers, SIGNAL(triggered()), this, SLOT(showCredits()));
    connect(ui.actionProject_Roadmap, SIGNAL(triggered()), this, SLOT(showRoadMap()));
417
#if (defined Q_OS_WIN) | (defined Q_OS_MAC)
pixhawk's avatar
pixhawk committed
418
    connect(ui.actionGoogleEarthView, SIGNAL(triggered()), this, SLOT(loadGoogleEarthView()));
419 420 421
#else
    ui.menuWindow->removeAction(ui.actionGoogleEarthView);
#endif
422

pixhawk's avatar
pixhawk committed
423 424
    // Joystick configuration
    connect(ui.actionJoystickSettings, SIGNAL(triggered()), this, SLOT(configure()));
425

426 427
    // Slugs View
    connect(ui.actionShow_Slugs_View, SIGNAL(triggered()), this, SLOT(loadSlugsView()));
428

429 430 431
    //GlobalOperatorView
   // connect(ui.actionGlobalOperatorView,SIGNAL(triggered()),waypointsDockWidget->widget(),SLOT())

pixhawk's avatar
pixhawk committed
432 433
}

434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
void MainWindow::showHelp()
{
    if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/user_guide")))
    {
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Critical);
        msgBox.setText("Could not open help in browser");
        msgBox.setInformativeText("To get to the online help, please open http://qgroundcontrol.org/user_guide in a browser.");
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        msgBox.exec();
    }
}

void MainWindow::showCredits()
{
    if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/credits")))
    {
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Critical);
        msgBox.setText("Could not open credits in browser");
        msgBox.setInformativeText("To get to the online help, please open http://qgroundcontrol.org/credits in a browser.");
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        msgBox.exec();
    }
}

void MainWindow::showRoadMap()
{
    if(!QDesktopServices::openUrl(QUrl("http://qgroundcontrol.org/roadmap")))
    {
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Critical);
        msgBox.setText("Could not open roadmap in browser");
        msgBox.setInformativeText("To get to the online help, please open http://qgroundcontrol.org/roadmap in a browser.");
        msgBox.setStandardButtons(QMessageBox::Ok);
        msgBox.setDefaultButton(QMessageBox::Ok);
        msgBox.exec();
    }
}

pixhawk's avatar
pixhawk committed
476
void MainWindow::configure()
pixhawk's avatar
pixhawk committed
477 478 479 480
{
    joystickWidget = new JoystickWidget(joystick, this);
}

pixhawk's avatar
pixhawk committed
481
void MainWindow::addLink()
pixhawk's avatar
pixhawk committed
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
{
    SerialLink* link = new SerialLink();
    // TODO This should be only done in the dialog itself

    LinkManager::instance()->addProtocol(link, mavlink);

    CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, this);

    ui.menuNetwork->addAction(commWidget->getAction());

    commWidget->show();

    // TODO Implement the link removal!
}

pixhawk's avatar
pixhawk committed
497 498
void MainWindow::addLink(LinkInterface *link)
{
499
    LinkManager::instance()->addProtocol(link, mavlink);
pixhawk's avatar
pixhawk committed
500 501 502 503 504 505 506
    CommConfigurationWindow* commWidget = new CommConfigurationWindow(link, mavlink, this);
    ui.menuNetwork->addAction(commWidget->getAction());

    // Special case for simulationlink
    MAVLinkSimulationLink* sim = dynamic_cast<MAVLinkSimulationLink*>(link);
    if (sim)
    {
507
        //connect(sim, SIGNAL(valueChanged(int,QString,double,quint64)), linechart, SLOT(appendData(int,QString,double,quint64)));
pixhawk's avatar
pixhawk committed
508 509 510 511
        connect(ui.actionSimulate, SIGNAL(triggered(bool)), sim, SLOT(connectLink(bool)));
    }
}

pixhawk's avatar
pixhawk committed
512
void MainWindow::UASCreated(UASInterface* uas)
pixhawk's avatar
pixhawk committed
513 514 515
{
    // Connect the UAS to the full user interface

516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
    if (uas != NULL)
    {
        QIcon icon;
        // Set matching icon
        switch (uas->getSystemType())
        {
        case 0:
            icon = QIcon(":/images/mavs/generic.svg");
            break;
        case 1:
            icon = QIcon(":/images/mavs/fixed-wing.svg");
            break;
        case 2:
            icon = QIcon(":/images/mavs/quadrotor.svg");
            break;
        case 3:
            icon = QIcon(":/images/mavs/coaxial.svg");
            break;
        case 4:
            icon = QIcon(":/images/mavs/helicopter.svg");
            break;
        case 5:
            icon = QIcon(":/images/mavs/groundstation.svg");
            break;
        default:
            icon = QIcon(":/images/mavs/unknown.svg");
            break;
        }

        ui.menuConnected_Systems->addAction(icon, tr("Select %1 for control").arg(uas->getUASName()), uas, SLOT(setSelected()));

        // FIXME Should be not inside the mainwindow
548 549
        if (debugConsoleDockWidget)
        {
pixhawk's avatar
pixhawk committed
550 551 552 553 554 555
            DebugConsole *debugConsole = dynamic_cast<DebugConsole*>(debugConsoleDockWidget->widget());
            if (debugConsole)
            {
                connect(uas, SIGNAL(textMessageReceived(int,int,int,QString)),
                        debugConsole, SLOT(receiveTextMessage(int,int,int,QString)));
            }
556
        }
557 558

        // Health / System status indicator
559 560
        if (infoDockWidget)
        {
pixhawk's avatar
pixhawk committed
561 562 563 564 565
            UASInfoWidget *infoWidget = dynamic_cast<UASInfoWidget*>(infoDockWidget->widget());
            if (infoWidget)
            {
                infoWidget->addUAS(uas);
            }
566
        }
567 568

        // UAS List
569 570
        if (listDockWidget)
        {
pixhawk's avatar
pixhawk committed
571 572 573 574 575
            UASListWidget *listWidget = dynamic_cast<UASListWidget*>(listDockWidget->widget());
            if (listWidget)
            {
                listWidget->addUAS(uas);
            }
576
        }
577 578 579 580 581 582 583 584 585 586 587

        // Camera view
        //camera->addUAS(uas);

        // Revalidate UI
        // TODO Stylesheet reloading should in theory not be necessary
        reloadStylesheet();

        // Check which type this UAS is of
        PxQuadMAV* mav = dynamic_cast<PxQuadMAV*>(uas);
        if (mav) loadPixhawkView();
588

589 590 591
        if (slugsDataWidget) {
          SlugsDataSensorView* dataWidget = dynamic_cast<SlugsDataSensorView*>(slugsDataWidget->widget());
          if (dataWidget) {
592
        SlugsMAV* mav2 = dynamic_cast<SlugsMAV*>(uas);
593 594
            if (mav2) {
              dataWidget->addUAS(uas);
595 596
              //loadSlugsView();
              loadGlobalOperatorView();
597 598
            }
          }
599
        }
600
    }
pixhawk's avatar
pixhawk committed
601 602
}

603 604 605
/**
 * Clears the current view completely
 */
pixhawk's avatar
pixhawk committed
606
void MainWindow::clearView()
pixhawk's avatar
pixhawk committed
607 608
{ 
    // Halt HUD
609 610 611 612 613 614 615 616 617
    if (hudWidget) hudWidget->stop();
    // Disable linechart
    if (linechartWidget) linechartWidget->setActive(false);
    // Halt HDDs
    if (headDown1DockWidget)
    {
        HDDisplay* hddWidget = dynamic_cast<HDDisplay*>( headDown1DockWidget->widget() );
        if (hddWidget) hddWidget->stop();
    }
pixhawk's avatar
pixhawk committed
618
    if (headDown2DockWidget)
619 620 621 622 623 624 625 626 627 628
    {
        HDDisplay* hddWidget = dynamic_cast<HDDisplay*>( headDown2DockWidget->widget() );
        if (hddWidget) hddWidget->stop();
    }
    // Halt HSI
    if (hsiDockWidget)
    {
        HSIDisplay* hsi = dynamic_cast<HSIDisplay*>( hsiDockWidget->widget() );
        if (hsi) hsi->stop();
    }
pixhawk's avatar
pixhawk committed
629

630 631
    // Remove all dock widgets from main window
    QObjectList childList( this->children() );
pixhawk's avatar
pixhawk committed
632

633 634 635
    QObjectList::iterator i;
    QDockWidget* dockWidget;
    for (i = childList.begin(); i != childList.end(); ++i)
pixhawk's avatar
pixhawk committed
636
    {
637 638
        dockWidget = dynamic_cast<QDockWidget*>(*i);
        if (dockWidget)
pixhawk's avatar
pixhawk committed
639
        {
640 641 642 643 644
            // Remove dock widget from main window
            this->removeDockWidget(dockWidget);
            // Deletion of dockWidget would also delete all child
            // widgets of dockWidget
            // Is there a way to unset a widget from QDockWidget?
pixhawk's avatar
pixhawk committed
645 646 647 648
        }
    }
}

lm's avatar
lm committed
649 650 651 652 653 654
void MainWindow::loadSlugsView()
{
    clearView();
    // Engineer view, used in EMAV2009

    // LINE CHART
655 656 657 658 659 660 661 662 663
    if (linechartWidget)
    {
        QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
        if (centerStack)
        {
            linechartWidget->setActive(true);
            centerStack->setCurrentWidget(linechartWidget);
        }
    }
lm's avatar
lm committed
664 665

    // UAS CONTROL
666 667 668 669 670
    if (controlDockWidget)
    {
        addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget);
        controlDockWidget->show();
    }
lm's avatar
lm committed
671 672

    // UAS LIST
673 674 675 676 677
    if (listDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, listDockWidget);
        listDockWidget->show();
    }
lm's avatar
lm committed
678 679

    // UAS STATUS
680 681 682 683 684
    if (infoDockWidget)
    {
        addDockWidget(Qt::LeftDockWidgetArea, infoDockWidget);
        infoDockWidget->show();
    }
lm's avatar
lm committed
685 686 687


    // WAYPOINT LIST
688 689 690 691 692
    if (waypointsDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget);
        waypointsDockWidget->show();
    }
lm's avatar
lm committed
693 694

    // DEBUG CONSOLE
695 696 697 698 699
    if (debugConsoleDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, debugConsoleDockWidget);
        debugConsoleDockWidget->show();
    }
lm's avatar
lm committed
700

701 702
    // Slugs Data View
    if (slugsDataWidget)
703
    {
704 705
        addDockWidget(Qt::RightDockWidgetArea, slugsDataWidget);
        slugsDataWidget->show();
706
    }
lm's avatar
lm committed
707

708 709 710 711 712 713
    // Slugs Data View
    if (slugsHilSimWidget)
    {
        addDockWidget(Qt::LeftDockWidgetArea, slugsHilSimWidget);
        slugsHilSimWidget->show();
    }
lm's avatar
lm committed
714 715 716 717 718 719 720 721
    this->show();
}

void MainWindow::loadPixhawkView()
{
    clearView();
    // Engineer view, used in EMAV2009

722
#ifdef QGC_OSG_ENABLED
723
    // 3D map
724
    if (_3DWidget)
725 726 727 728
    {
        QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
        if (centerStack)
        {
729
            //map3DWidget->setActive(true);
730
            centerStack->setCurrentWidget(_3DWidget);
731 732
        }
    }
733
#endif
lm's avatar
lm committed
734 735

    // UAS CONTROL
736 737 738 739 740
    if (controlDockWidget)
    {
        addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget);
        controlDockWidget->show();
    }
lm's avatar
lm committed
741

742 743 744 745 746 747 748 749 750 751 752 753
    // HORIZONTAL SITUATION INDICATOR
    if (hsiDockWidget)
    {
        HSIDisplay* hsi = dynamic_cast<HSIDisplay*>( hsiDockWidget->widget() );
        if (hsi)
        {
            hsi->start();
            addDockWidget(Qt::LeftDockWidgetArea, hsiDockWidget);
            hsiDockWidget->show();
        }
    }

lm's avatar
lm committed
754
    // UAS LIST
755 756 757 758 759
    if (listDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, listDockWidget);
        listDockWidget->show();
    }
lm's avatar
lm committed
760 761

    // UAS STATUS
762 763 764 765 766
    if (infoDockWidget)
    {
        addDockWidget(Qt::LeftDockWidgetArea, infoDockWidget);
        infoDockWidget->show();
    }
lm's avatar
lm committed
767 768

    // WAYPOINT LIST
769 770 771 772 773
    if (waypointsDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget);
        waypointsDockWidget->show();
    }
lm's avatar
lm committed
774 775

    // DEBUG CONSOLE
776 777 778 779 780
    if (debugConsoleDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, debugConsoleDockWidget);
        debugConsoleDockWidget->show();
    }
lm's avatar
lm committed
781 782

    // ONBOARD PARAMETERS
783 784 785 786 787
    if (parametersDockWidget)
    {
        addDockWidget(Qt::RightDockWidgetArea, parametersDockWidget);
        parametersDockWidget->show();
    }
lm's avatar
lm committed
788 789 790 791

    this->show();
}

792 793 794
void MainWindow::loadDataView()
{
    clearView();
795 796 797 798 799 800 801 802

    // DATAPLOT
    if (dataplotWidget)
    {
        QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
        if (centerStack)
            centerStack->setCurrentWidget(dataplotWidget);
    }
803 804
}

805 806 807
void MainWindow::loadDataView(QString fileName)
{
    clearView();
pixhawk's avatar
pixhawk committed
808

809 810 811 812 813 814 815 816 817 818
    // DATAPLOT
    if (dataplotWidget)
    {
        QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
        if (centerStack)
        {
            centerStack->setCurrentWidget(dataplotWidget);
            dataplotWidget->loadFile(fileName);
        }
    }
819 820
}

pixhawk's avatar
pixhawk committed
821
void MainWindow::loadPilotView()
pixhawk's avatar
pixhawk committed
822 823 824 825
{
    clearView();

    // HEAD UP DISPLAY
826 827 828 829 830 831 832 833 834
    if (hudWidget)
    {
        QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
        if (centerStack)
        {
            centerStack->setCurrentWidget(hudWidget);
            hudWidget->start();
        }
    }
pixhawk's avatar
pixhawk committed
835 836

    //connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), pfd, SLOT(setActiveUAS(UASInterface*)));
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
    if (headDown1DockWidget)
    {
        HDDisplay *hdd = dynamic_cast<HDDisplay*>(headDown1DockWidget->widget());
        if (hdd)
        {
            addDockWidget(Qt::RightDockWidgetArea, headDown1DockWidget);
            headDown1DockWidget->show();
            hdd->start();
        }
        
    }
    if (headDown2DockWidget)
    {
        HDDisplay *hdd = dynamic_cast<HDDisplay*>(headDown2DockWidget->widget());
        if (hdd)
        {
            addDockWidget(Qt::RightDockWidgetArea, headDown2DockWidget);
            headDown2DockWidget->show();
            hdd->start();
        }
    }
pixhawk's avatar
pixhawk committed
858

pixhawk's avatar
pixhawk committed
859 860 861
    this->show();
}

pixhawk's avatar
pixhawk committed
862
void MainWindow::loadOperatorView()
pixhawk's avatar
pixhawk committed
863 864 865
{
    clearView();

866
    // MAP
867 868 869 870 871 872 873 874
    if (mapWidget)
    {
        QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
        if (centerStack)
        {
            centerStack->setCurrentWidget(mapWidget);
        }
    }
pixhawk's avatar
pixhawk committed
875 876

    // UAS CONTROL
877 878 879 880 881
    if (controlDockWidget)
    {
        addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget);
        controlDockWidget->show();
    }
pixhawk's avatar
pixhawk committed
882 883

    // UAS LIST
884 885 886 887 888
    if (listDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, listDockWidget);
        listDockWidget->show();
    }
pixhawk's avatar
pixhawk committed
889 890

    // UAS STATUS
891 892 893 894 895
    if (infoDockWidget)
    {
        addDockWidget(Qt::LeftDockWidgetArea, infoDockWidget);
        infoDockWidget->show();
    }
pixhawk's avatar
pixhawk committed
896 897

    // WAYPOINT LIST
898 899 900 901 902
    if (waypointsDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget);
        waypointsDockWidget->show();
    }
pixhawk's avatar
pixhawk committed
903

lm's avatar
lm committed
904
    // HORIZONTAL SITUATION INDICATOR
905 906 907 908 909 910 911 912 913 914
    if (hsiDockWidget)
    {
        HSIDisplay* hsi = dynamic_cast<HSIDisplay*>( hsiDockWidget->widget() );
        if (hsi)
        {
            addDockWidget(Qt::BottomDockWidgetArea, hsiDockWidget);
            hsiDockWidget->show();
            hsi->start();
        }
    }
pixhawk's avatar
pixhawk committed
915 916

    // OBJECT DETECTION
917 918 919 920 921
    if (detectionDockWidget)
    {
        addDockWidget(Qt::RightDockWidgetArea, detectionDockWidget);
        detectionDockWidget->show();
    }
pixhawk's avatar
pixhawk committed
922

pixhawk's avatar
pixhawk committed
923
    // PROCESS CONTROL
924 925 926 927 928 929
    if (watchdogControlDockWidget)
    {
        addDockWidget(Qt::RightDockWidgetArea, watchdogControlDockWidget);
        watchdogControlDockWidget->show();
    }

pixhawk's avatar
pixhawk committed
930 931 932
    this->show();
}

933 934 935 936 937
void MainWindow::loadGlobalOperatorView()
{
    clearView();

    // MAP
938 939 940 941 942 943 944 945
    if (mapWidget)
    {
        QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
        if (centerStack)
        {
            centerStack->setCurrentWidget(mapWidget);
        }
    }
946

tecnosapiens's avatar
tecnosapiens committed
947 948
    // WAYPOINT LIST
    if (waypointsDockWidget)
949
    {
tecnosapiens's avatar
tecnosapiens committed
950 951
        addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget);
        waypointsDockWidget->show();
952

953
    }
954

tecnosapiens's avatar
tecnosapiens committed
955 956
    // Slugs Data View
    if (slugsDataWidget)
957
    {
tecnosapiens's avatar
tecnosapiens committed
958 959
        addDockWidget(Qt::RightDockWidgetArea, slugsDataWidget);
        slugsDataWidget->show();
960
    }
961

962 963 964 965 966 967 968
    // Slugs Data View
    if (slugsPIDControlWidget)
    {
        addDockWidget(Qt::LeftDockWidgetArea, slugsPIDControlWidget);
        slugsPIDControlWidget->show();
    }

969 970
    if (slugsCamControlWidget)
    {
971
        addDockWidget(Qt::BottomDockWidgetArea, slugsCamControlWidget);
972 973 974
        slugsCamControlWidget->show();
    }

975

tecnosapiens's avatar
tecnosapiens committed
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997

//    // UAS CONTROL
//    if (controlDockWidget)
//    {
//        addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget);
//        controlDockWidget->show();
//    }

//    // UAS LIST
//    if (listDockWidget)
//    {
//        addDockWidget(Qt::BottomDockWidgetArea, listDockWidget);
//        listDockWidget->show();
//    }

//    // UAS STATUS
//    if (infoDockWidget)
//    {
//        addDockWidget(Qt::LeftDockWidgetArea, infoDockWidget);
//        infoDockWidget->show();
//    }

998

999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
//    // HORIZONTAL SITUATION INDICATOR
//    if (hsiDockWidget)
//    {
//        HSIDisplay* hsi = dynamic_cast<HSIDisplay*>( hsiDockWidget->widget() );
//        if (hsi)
//        {
//            addDockWidget(Qt::BottomDockWidgetArea, hsiDockWidget);
//            hsiDockWidget->show();
//            hsi->start();
//        }
//    }
1010 1011

    // PROCESS CONTROL
tecnosapiens's avatar
tecnosapiens committed
1012 1013 1014 1015 1016
//    if (watchdogControlDockWidget)
//    {
//        addDockWidget(Qt::RightDockWidgetArea, watchdogControlDockWidget);
//        watchdogControlDockWidget->show();
//    }
pixhawk's avatar
pixhawk committed
1017

1018
    // HEAD UP DISPLAY
tecnosapiens's avatar
tecnosapiens committed
1019 1020 1021 1022 1023
//    if (headUpDockWidget)
//    {
//        addDockWidget(Qt::RightDockWidgetArea, headUpDockWidget);
//        // FIXME Replace with default ->show() call
//        HUD* hud = dynamic_cast<HUD*>(headUpDockWidget->widget());
pixhawk's avatar
pixhawk committed
1024

tecnosapiens's avatar
tecnosapiens committed
1025 1026 1027 1028 1029 1030
//        if (hud)
//        {
//            headUpDockWidget->show();
//            hud->start();
//        }
//    }
pixhawk's avatar
pixhawk committed
1031 1032 1033

}

1034
void MainWindow::load3DMapView()
pixhawk's avatar
pixhawk committed
1035
{
1036
#ifdef QGC_OSGEARTH_ENABLED
1037
            clearView();
pixhawk's avatar
pixhawk committed
1038

1039
            // 3D map
1040
            if (_3DMapWidget)
1041 1042 1043 1044 1045
            {
                QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
                if (centerStack)
                {
                    //map3DWidget->setActive(true);
1046
                    centerStack->setCurrentWidget(_3DMapWidget);
1047 1048
                }
            }
pixhawk's avatar
pixhawk committed
1049

1050 1051 1052 1053 1054 1055
            // UAS CONTROL
            if (controlDockWidget)
            {
                addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget);
                controlDockWidget->show();
            }
pixhawk's avatar
pixhawk committed
1056

1057 1058 1059 1060 1061 1062
            // UAS LIST
            if (listDockWidget)
            {
                addDockWidget(Qt::BottomDockWidgetArea, listDockWidget);
                listDockWidget->show();
            }
1063

1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
            // WAYPOINT LIST
            if (waypointsDockWidget)
            {
                addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget);
                waypointsDockWidget->show();
            }

            // HORIZONTAL SITUATION INDICATOR
            if (hsiDockWidget)
            {
                HSIDisplay* hsi = dynamic_cast<HSIDisplay*>( hsiDockWidget->widget() );
                if (hsi)
                {
                    hsi->start();
                    addDockWidget(Qt::LeftDockWidgetArea, hsiDockWidget);
                    hsiDockWidget->show();
                }
            }
1082 1083
#endif
            this->show();
1084
}
1085

pixhawk's avatar
pixhawk committed
1086 1087
void MainWindow::loadGoogleEarthView()
{
1088
    #if (defined Q_OS_WIN) | (defined Q_OS_MAC)
pixhawk's avatar
pixhawk committed
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132
            clearView();

            // 3D map
            if (gEarthWidget)
            {
                QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
                if (centerStack)
                {
                    centerStack->setCurrentWidget(gEarthWidget);
                }
            }

            // UAS CONTROL
            if (controlDockWidget)
            {
                addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget);
                controlDockWidget->show();
            }

            // UAS LIST
            if (listDockWidget)
            {
                addDockWidget(Qt::BottomDockWidgetArea, listDockWidget);
                listDockWidget->show();
            }

            // WAYPOINT LIST
            if (waypointsDockWidget)
            {
                addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget);
                waypointsDockWidget->show();
            }

            // HORIZONTAL SITUATION INDICATOR
            if (hsiDockWidget)
            {
                HSIDisplay* hsi = dynamic_cast<HSIDisplay*>( hsiDockWidget->widget() );
                if (hsi)
                {
                    hsi->start();
                    addDockWidget(Qt::LeftDockWidgetArea, hsiDockWidget);
                    hsiDockWidget->show();
                }
            }
1133
            this->show();
1134
#endif
1135

1136
}
1137 1138


1139
void MainWindow::load3DView()
pixhawk's avatar
pixhawk committed
1140
{
1141
#ifdef QGC_OSG_ENABLED
1142
            clearView();
pixhawk's avatar
pixhawk committed
1143

1144
            // 3D map
1145
            if (_3DWidget)
1146 1147 1148 1149 1150
            {
                QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
                if (centerStack)
                {
                    //map3DWidget->setActive(true);
1151
                    centerStack->setCurrentWidget(_3DWidget);
1152 1153
                }
            }
pixhawk's avatar
pixhawk committed
1154

1155 1156 1157 1158 1159 1160
            // UAS CONTROL
            if (controlDockWidget)
            {
                addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget);
                controlDockWidget->show();
            }
pixhawk's avatar
pixhawk committed
1161

1162 1163 1164 1165 1166 1167
            // UAS LIST
            if (listDockWidget)
            {
                addDockWidget(Qt::BottomDockWidgetArea, listDockWidget);
                listDockWidget->show();
            }
1168

1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
            // WAYPOINT LIST
            if (waypointsDockWidget)
            {
                addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget);
                waypointsDockWidget->show();
            }

            // HORIZONTAL SITUATION INDICATOR
            if (hsiDockWidget)
            {
                HSIDisplay* hsi = dynamic_cast<HSIDisplay*>( hsiDockWidget->widget() );
                if (hsi)
                {
                    hsi->start();
                    addDockWidget(Qt::LeftDockWidgetArea, hsiDockWidget);
                    hsiDockWidget->show();
                }
            }
1187
#endif
1188
            this->show();
1189

1190
}
pixhawk's avatar
pixhawk committed
1191

pixhawk's avatar
pixhawk committed
1192
void MainWindow::loadEngineerView()
pixhawk's avatar
pixhawk committed
1193 1194 1195 1196 1197
{
    clearView();
    // Engineer view, used in EMAV2009

    // LINE CHART
1198 1199 1200 1201 1202 1203 1204 1205 1206
    if (linechartWidget)
    {
        QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
        if (centerStack)
        {
            linechartWidget->setActive(true);
            centerStack->setCurrentWidget(linechartWidget);
        }
    }
pixhawk's avatar
pixhawk committed
1207 1208

    // UAS CONTROL
1209 1210 1211 1212 1213
    if (controlDockWidget)
    {
        addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget);
        controlDockWidget->show();
    }
pixhawk's avatar
pixhawk committed
1214 1215

    // UAS LIST
1216 1217 1218 1219 1220
    if (listDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, listDockWidget);
        listDockWidget->show();
    }
pixhawk's avatar
pixhawk committed
1221 1222

    // UAS STATUS
1223 1224 1225 1226 1227
    if (infoDockWidget)
    {
        addDockWidget(Qt::LeftDockWidgetArea, infoDockWidget);
        infoDockWidget->show();
    }
pixhawk's avatar
pixhawk committed
1228

lm's avatar
lm committed
1229
    // WAYPOINT LIST
1230 1231 1232 1233 1234
    if (waypointsDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget);
        waypointsDockWidget->show();
    }
pixhawk's avatar
pixhawk committed
1235 1236

    // DEBUG CONSOLE
1237 1238 1239 1240 1241
    if (debugConsoleDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, debugConsoleDockWidget);
        debugConsoleDockWidget->show();
    }
pixhawk's avatar
pixhawk committed
1242

lm's avatar
lm committed
1243
    // ONBOARD PARAMETERS
1244 1245 1246 1247 1248
    if (parametersDockWidget)
    {
        addDockWidget(Qt::RightDockWidgetArea, parametersDockWidget);
        parametersDockWidget->show();
    }
lm's avatar
lm committed
1249

1250 1251 1252 1253 1254 1255 1256
    // RADIO CONTROL VIEW
    if (rcViewDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, rcViewDockWidget);
        rcViewDockWidget->show();
    }

pixhawk's avatar
pixhawk committed
1257 1258 1259
    this->show();
}

1260 1261 1262
void MainWindow::loadMAVLinkView()
{
    clearView();
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272

    if (protocolWidget)
    {
        QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
        if (centerStack)
        {
            centerStack->setCurrentWidget(protocolWidget);
        }
    }

1273
    this->show();
1274 1275
}

1276 1277
void MainWindow::loadAllView()
{
1278 1279
    clearView();

1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
    if (headDown1DockWidget)
    {
        HDDisplay *hdd = dynamic_cast<HDDisplay*>(headDown1DockWidget->widget());
        if (hdd)
        {
            addDockWidget(Qt::RightDockWidgetArea, headDown1DockWidget);
            headDown1DockWidget->show();
            hdd->start();
        }
        
    }
    if (headDown2DockWidget)
    {
        HDDisplay *hdd = dynamic_cast<HDDisplay*>(headDown2DockWidget->widget());
        if (hdd)
        {
            addDockWidget(Qt::RightDockWidgetArea, headDown2DockWidget);
            headDown2DockWidget->show();
            hdd->start();
        }
    }
1301 1302

    // UAS CONTROL
1303 1304 1305 1306 1307
    if (controlDockWidget)
    {
        addDockWidget(Qt::LeftDockWidgetArea, controlDockWidget);
        controlDockWidget->show();
    }
1308 1309

    // UAS LIST
1310 1311 1312 1313 1314
    if (listDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, listDockWidget);
        listDockWidget->show();
    }
1315 1316

    // UAS STATUS
1317 1318 1319 1320 1321
    if (infoDockWidget)
    {
        addDockWidget(Qt::LeftDockWidgetArea, infoDockWidget);
        infoDockWidget->show();
    }
1322 1323

    // WAYPOINT LIST
1324 1325 1326 1327 1328
    if (waypointsDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, waypointsDockWidget);
        waypointsDockWidget->show();
    }
1329 1330

    // DEBUG CONSOLE
1331 1332 1333 1334 1335
    if (debugConsoleDockWidget)
    {
        addDockWidget(Qt::BottomDockWidgetArea, debugConsoleDockWidget);
        debugConsoleDockWidget->show();
    }
1336 1337

    // OBJECT DETECTION
1338 1339
    if (detectionDockWidget)
    {
pixhawk's avatar
pixhawk committed
1340 1341
        addDockWidget(Qt::RightDockWidgetArea, detectionDockWidget);
        detectionDockWidget->show();
1342
    }
1343 1344

    // LINE CHART
1345 1346 1347 1348 1349 1350 1351 1352 1353
    if (linechartWidget)
    {
        QStackedWidget *centerStack = dynamic_cast<QStackedWidget*>(centralWidget());
        if (centerStack)
        {
            linechartWidget->setActive(true);
            centerStack->setCurrentWidget(linechartWidget);
        }
    }
1354 1355

    // ONBOARD PARAMETERS
1356 1357 1358 1359 1360
    if (parametersDockWidget)
    {
        addDockWidget(Qt::RightDockWidgetArea, parametersDockWidget);
        parametersDockWidget->show();
    }
1361 1362

    this->show();
1363 1364
}

pixhawk's avatar
pixhawk committed
1365
void MainWindow::loadWidgets()
pixhawk's avatar
pixhawk committed
1366
{
1367 1368
    //loadOperatorView();
    loadEngineerView();
pixhawk's avatar
pixhawk committed
1369 1370
    //loadPilotView();
}