QGCGoogleEarthView.cc 4.11 KB
Newer Older
1 2 3 4 5
#include <QWebFrame>
#include <QWebPage>

#include <QDebug>

pixhawk's avatar
pixhawk committed
6
#include "QGCGoogleEarthView.h"
7 8
#include "QGCWebPage.h"
#include "UASManager.h"
9
#include "ui_QGCGoogleEarthControls.h"
10
#if (defined Q_OS_WIN) && !(defined __MINGW32__)
11
#include "ui_QGCGoogleEarthViewWin.h"
12
#else
pixhawk's avatar
pixhawk committed
13
#include "ui_QGCGoogleEarthView.h"
14
#endif
pixhawk's avatar
pixhawk committed
15 16

QGCGoogleEarthView::QGCGoogleEarthView(QWidget *parent) :
17 18 19 20
        QWidget(parent),
        updateTimer(new QTimer(this)),
        mav(NULL),
        followCamera(true),
pixhawk's avatar
pixhawk committed
21
        trailEnabled(true),
22 23 24 25
#if (defined Q_OS_MAC)
        webViewMac(new QWebView(this)),
#endif
#if (defined Q_OS_WIN) & !(defined __MINGW32__)
26 27 28 29
        webViewWin(new QGCWebAxWidget(this)),
#else
        ui(new Ui::QGCGoogleEarthView)
#endif
pixhawk's avatar
pixhawk committed
30
{
31
#if (defined Q_OS_WIN) & !(defined __MINGW32__)
32 33
    // Create layout and attach webViewWin
#else
34 35
#endif

pixhawk's avatar
pixhawk committed
36
    ui->setupUi(this);
37

38 39 40 41 42 43 44 45 46 47 48 49
#if (defined Q_OS_MAC)
    ui->webViewLayout->addWidget(webViewMac);
    webViewMac->setPage(new QGCWebPage(webViewMac));
    webViewMac->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
    webViewMac->load(QUrl("earth.html"));
#endif

#if (defined Q_OS_WIN) & !(defined __MINGW32__)
    webViewWin->load(QUrl("earth.html"));
#endif

#if ((defined Q_OS_MAC) | ((defined Q_OS_WIN) & !(defined __MINGW32__)))
50 51 52 53 54
    connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*)));
    connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateState()));
    updateTimer->start(200);
#endif

pixhawk's avatar
pixhawk committed
55 56 57 58 59 60 61 62
    // Follow checkbox
    ui->followAirplaneCheckbox->setChecked(followCamera);
    connect(ui->followAirplaneCheckbox, SIGNAL(toggled(bool)), this, SLOT(follow(bool)));

    // Trail checkbox
    ui->trailCheckbox->setChecked(trailEnabled);
    connect(ui->trailCheckbox, SIGNAL(toggled(bool)), this, SLOT(showTrail(bool)));

63 64 65 66 67 68 69
    // Get list of available 3D models

    // Load HTML file

    // Parse for model links

    // Populate model list
pixhawk's avatar
pixhawk committed
70 71 72 73 74 75 76
}

QGCGoogleEarthView::~QGCGoogleEarthView()
{
    delete ui;
}

77 78 79 80 81
void QGCGoogleEarthView::setActiveUAS(UASInterface* uas)
{
    mav = uas;
}

pixhawk's avatar
pixhawk committed
82
void QGCGoogleEarthView::showTrail(bool state)
83 84 85 86
{

}

pixhawk's avatar
pixhawk committed
87
void QGCGoogleEarthView::showWaypoints(bool state)
88 89 90 91 92 93
{

}

void QGCGoogleEarthView::follow(bool follow)
{
pixhawk's avatar
pixhawk committed
94
    followCamera = follow;
95 96
}

97 98
void QGCGoogleEarthView::updateState()
{
lm's avatar
lm committed
99
#ifdef Q_OS_MAC
100
    if (webViewMac->page()->currentFrame()->evaluateJavaScript("isInitialized();").toBool())
101 102 103 104
    {
        static bool initialized = false;
        if (!initialized)
        {
105
            webViewMac->page()->currentFrame()->evaluateJavaScript("setGCSHome(22.679833,8.549444, 470);");
106 107 108 109 110 111 112 113 114 115 116 117 118 119
            initialized = true;
        }
        int uasId = 0;
        double lat = 22.679833;
        double lon = 8.549444;
        double alt = 470.0;

        float roll = 0.0f;
        float pitch = 0.0f;
        float yaw = 0.0f;

        if (mav)
        {
            uasId = mav->getUASID();
pixhawk's avatar
pixhawk committed
120 121 122
            lat = mav->getLatitude();
            lon = mav->getLongitude();
            alt = mav->getAltitude();
123 124 125 126
            roll = mav->getRoll();
            pitch = mav->getPitch();
            yaw = mav->getYaw();
        }
127
        webViewMac->page()->currentFrame()->evaluateJavaScript(QString("setAircraftPositionAttitude(%1, %2, %3, %4, %6, %7, %8);")
pixhawk's avatar
pixhawk committed
128 129 130 131 132 133 134
                                                                .arg(uasId)
                                                                .arg(lat)
                                                                .arg(lon)
                                                                .arg(alt+500)
                                                                .arg(roll)
                                                                .arg(pitch)
                                                                .arg(yaw));
135 136 137

        if (followCamera)
        {
138
             webViewMac->page()->currentFrame()->evaluateJavaScript(QString("updateFollowAircraft()"));
139 140
        }
    }
lm's avatar
lm committed
141
#endif
142 143
}

pixhawk's avatar
pixhawk committed
144 145 146 147 148 149 150 151 152 153 154
void QGCGoogleEarthView::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}