MainToolBarController.cc 5.37 KB
Newer Older
dogmaphobic's avatar
dogmaphobic committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief QGC Main Tool Bar
 *   @author Gus Grubba <mavlink@grubba.com>
 */

#include <QQmlContext>
#include <QQmlEngine>

33
#include "MainToolBarController.h"
Don Gagne's avatar
Don Gagne committed
34
#include "ScreenToolsController.h"
35
#include "MainWindow.h"
dogmaphobic's avatar
dogmaphobic committed
36
#include "UASMessageView.h"
37 38
#include "UASMessageHandler.h"
#include "QGCApplication.h"
39
#include "MultiVehicleManager.h"
40
#include "UAS.h"
dogmaphobic's avatar
dogmaphobic committed
41

42 43
MainToolBarController::MainToolBarController(QObject* parent)
    : QObject(parent)
44
    , _vehicle(NULL)
Don Gagne's avatar
Don Gagne committed
45
    , _mav(NULL)
46
    , _progressBarValue(0.0f)
47 48
    , _telemetryRRSSI(0)
    , _telemetryLRSSI(0)
49
    , _toolbarMessageVisible(false)
dogmaphobic's avatar
dogmaphobic committed
50
{
51
    _activeVehicleChanged(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle());
dogmaphobic's avatar
dogmaphobic committed
52

53
    // RSSI (didn't like standard connection)
54
    connect(qgcApp()->toolbox()->mavlinkProtocol(),
55 56
        SIGNAL(radioStatusChanged(LinkInterface*, unsigned, unsigned, int, int, unsigned, unsigned, unsigned)), this,
        SLOT(_telemetryChanged(LinkInterface*, unsigned, unsigned, int, int, unsigned, unsigned, unsigned)));
dogmaphobic's avatar
dogmaphobic committed
57

58
    connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &MainToolBarController::_activeVehicleChanged);
dogmaphobic's avatar
dogmaphobic committed
59 60
}

61
MainToolBarController::~MainToolBarController()
dogmaphobic's avatar
dogmaphobic committed
62 63 64 65
{

}

66
void MainToolBarController::onSetupView()
67
{
68
    MainWindow::instance()->showSetupView();
69 70
}

71
void MainToolBarController::onPlanView()
72
{
73
    MainWindow::instance()->showPlanView();
74 75
}

76
void MainToolBarController::onFlyView()
dogmaphobic's avatar
dogmaphobic committed
77
{
78
    MainWindow::instance()->showFlyView();
dogmaphobic's avatar
dogmaphobic committed
79 80
}

81
void MainToolBarController::_activeVehicleChanged(Vehicle* vehicle)
82
{
83 84
    // Disconnect the previous one (if any)
    if (_vehicle) {
85
        disconnect(_vehicle->autopilotPlugin(), &AutoPilotPlugin::parameterListProgress, this, &MainToolBarController::_setProgressBarValue);
86
        _mav = NULL;
87
        _vehicle = NULL;
88
    }
dogmaphobic's avatar
dogmaphobic committed
89

dogmaphobic's avatar
dogmaphobic committed
90
    // Connect new system
91
    if (vehicle)
dogmaphobic's avatar
dogmaphobic committed
92
    {
93 94
        _vehicle = vehicle;
        _mav = vehicle->uas();
95
        connect(_vehicle->autopilotPlugin(), &AutoPilotPlugin::parameterListProgress, this, &MainToolBarController::_setProgressBarValue);
dogmaphobic's avatar
dogmaphobic committed
96
    }
97 98
}

dogmaphobic's avatar
dogmaphobic committed
99
void MainToolBarController::_telemetryChanged(LinkInterface*, unsigned rxerrors, unsigned fixed, int rssi, int remrssi, unsigned txbuf, unsigned noise, unsigned remnoise)
100
{
101 102
    if(_telemetryLRSSI != rssi) {
        _telemetryLRSSI = rssi;
103
        emit telemetryLRSSIChanged(_telemetryLRSSI);
104
    }
105 106
    if(_telemetryRRSSI != remrssi) {
        _telemetryRRSSI = remrssi;
Don Gagne's avatar
Don Gagne committed
107
        emit telemetryRRSSIChanged(_telemetryRRSSI);
108
    }
dogmaphobic's avatar
dogmaphobic committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    if(_telemetryRXErrors != rxerrors) {
        _telemetryRXErrors = rxerrors;
        emit telemetryRXErrorsChanged(_telemetryRXErrors);
    }
    if(_telemetryFixed != fixed) {
        _telemetryFixed = fixed;
        emit telemetryFixedChanged(_telemetryFixed);
    }
    if(_telemetryTXBuffer != txbuf) {
        _telemetryTXBuffer = txbuf;
        emit telemetryTXBufferChanged(_telemetryTXBuffer);
    }
    if(_telemetryLNoise != noise) {
        _telemetryLNoise = noise;
        emit telemetryLNoiseChanged(_telemetryLNoise);
    }
    if(_telemetryRNoise != remnoise) {
        _telemetryRNoise = remnoise;
        emit telemetryRNoiseChanged(_telemetryRNoise);
    }
dogmaphobic's avatar
dogmaphobic committed
129 130
}

131
void MainToolBarController::_setProgressBarValue(float value)
132 133 134 135
{
    _progressBarValue = value;
    emit progressBarValueChanged(value);
}
Don Gagne's avatar
Don Gagne committed
136

137
void MainToolBarController::showToolBarMessage(const QString& message)
138 139
{
    _toolbarMessageQueueMutex.lock();
dogmaphobic's avatar
dogmaphobic committed
140

141
    if (_toolbarMessageQueue.count() == 0 && !_toolbarMessageVisible) {
142
        QTimer::singleShot(500, this, &MainToolBarController::_delayedShowToolBarMessage);
143
    }
dogmaphobic's avatar
dogmaphobic committed
144

145
    _toolbarMessageQueue += message;
dogmaphobic's avatar
dogmaphobic committed
146

147 148 149
    _toolbarMessageQueueMutex.unlock();
}

150
void MainToolBarController::_delayedShowToolBarMessage(void)
151 152
{
    QString messages;
dogmaphobic's avatar
dogmaphobic committed
153

154 155
    if (!_toolbarMessageVisible) {
        _toolbarMessageQueueMutex.lock();
dogmaphobic's avatar
dogmaphobic committed
156

157 158 159 160
        foreach (QString message, _toolbarMessageQueue) {
            messages += message + "\n";
        }
        _toolbarMessageQueue.clear();
dogmaphobic's avatar
dogmaphobic committed
161

162
        _toolbarMessageQueueMutex.unlock();
dogmaphobic's avatar
dogmaphobic committed
163

164 165 166 167 168 169 170
        if (!messages.isEmpty()) {
            _toolbarMessageVisible = true;
            emit showMessage(messages);
        }
    }
}

171
void MainToolBarController::onToolBarMessageClosed(void)
172 173 174
{
    _toolbarMessageVisible = false;
    _delayedShowToolBarMessage();
Don Gagne's avatar
Don Gagne committed
175
}
Don Gagne's avatar
Don Gagne committed
176 177 178 179 180

void MainToolBarController::showSettings(void)
{
    MainWindow::instance()->showSettings();
}
Don Gagne's avatar
Don Gagne committed
181 182 183 184 185

void MainToolBarController::manageLinks(void)
{
    MainWindow::instance()->manageLinks();
}