QGCGoogleEarthView.cc 3.73 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),
21 22 23 24
#if (defined Q_OS_MAC)
        webViewMac(new QWebView(this)),
#endif
#if (defined Q_OS_WIN) & !(defined __MINGW32__)
25 26 27 28
        webViewWin(new QGCWebAxWidget(this)),
#else
        ui(new Ui::QGCGoogleEarthView)
#endif
pixhawk's avatar
pixhawk committed
29
{
30
#if (defined Q_OS_WIN) & !(defined __MINGW32__)
31 32
    // Create layout and attach webViewWin
#else
33 34
#endif

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

37 38 39 40 41 42 43 44 45 46 47 48
#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__)))
49 50 51 52 53 54 55 56 57 58 59 60
    connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*)));
    connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateState()));
    updateTimer->start(200);
#endif

    // Get list of available 3D models

    // Load HTML file

    // Parse for model links

    // Populate model list
pixhawk's avatar
pixhawk committed
61 62 63 64 65 66 67
}

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

68 69 70 71 72
void QGCGoogleEarthView::setActiveUAS(UASInterface* uas)
{
    mav = uas;
}

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
void QGCGoogleEarthView::showTrail(int state)
{

}

void QGCGoogleEarthView::showWaypoints(int state)
{

}

void QGCGoogleEarthView::follow(bool follow)
{

}

88 89
void QGCGoogleEarthView::updateState()
{
lm's avatar
lm committed
90
#ifdef Q_OS_MAC
91
    if (webViewMac->page()->currentFrame()->evaluateJavaScript("isInitialized();").toBool())
92 93 94 95
    {
        static bool initialized = false;
        if (!initialized)
        {
96
            webViewMac->page()->currentFrame()->evaluateJavaScript("setGCSHome(22.679833,8.549444, 470);");
97 98 99 100 101 102 103 104 105 106 107 108 109 110
            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
111 112 113
            lat = mav->getLatitude();
            lon = mav->getLongitude();
            alt = mav->getAltitude();
114 115 116 117
            roll = mav->getRoll();
            pitch = mav->getPitch();
            yaw = mav->getYaw();
        }
118
        webViewMac->page()->currentFrame()->evaluateJavaScript(QString("setAircraftPositionAttitude(%1, %2, %3, %4, %6, %7, %8);")
pixhawk's avatar
pixhawk committed
119 120 121 122 123 124 125
                                                                .arg(uasId)
                                                                .arg(lat)
                                                                .arg(lon)
                                                                .arg(alt+500)
                                                                .arg(roll)
                                                                .arg(pitch)
                                                                .arg(yaw));
126 127 128

        if (followCamera)
        {
129
             webViewMac->page()->currentFrame()->evaluateJavaScript(QString("updateFollowAircraft()"));
130 131
        }
    }
lm's avatar
lm committed
132
#endif
133 134
}

pixhawk's avatar
pixhawk committed
135 136 137 138 139 140 141 142 143 144 145
void QGCGoogleEarthView::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}