QGCGoogleEarthView.h 5.18 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4
#ifndef QGCGOOGLEEARTHVIEW_H
#define QGCGOOGLEEARTHVIEW_H

#include <QWidget>
5 6
#include <QTimer>
#include <UASInterface.h>
pixhawk's avatar
pixhawk committed
7

8 9 10 11
#if (defined Q_OS_MAC)
#include <QWebView>
#endif

12
#ifdef _MSC_VER
13
#include <ActiveQt/QAxWidget>
14
#include <ActiveQt/QAxObject>
15 16
#include "windows.h"

17
class QGCWebAxWidget : public QAxWidget
18 19
{
public:
20
    //Q_OBJECT
21
    QGCWebAxWidget(QWidget* parent = 0, Qt::WindowFlags f = 0)
22 23
        : QAxWidget(parent, f)/*,
		_document(NULL)*/
24
    {
25 26 27 28 29 30 31 32
        // Set web browser control
        setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}");
        // WARNING: Makes it impossible to actually debug javascript. But useful in production mode
        setProperty("ScriptErrorsSuppressed", true);
        // see: http://www.codeproject.com/KB/cpp/ExtendedWebBrowser.aspx?fid=285594&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=151#GoalScriptError

        //this->dynamicCall("setProperty(const QString&,
        //QObject::connect(this, SIGNAL(DocumentComplete(IDispatch*, QVariant&)), this, SLOT(setDocument(IDispatch*, QVariant&)));
33

34

35
    }
36
    /*
37 38 39 40
    QAxObject* document()
    {
    	return _document;
    }*/
41

42
protected:
43
    /*
44
    void setDocument(IDispatch* dispatch, QVariant& variant)
45
    {
46 47 48 49
    	_document = this->querySubObject("Document()");
    }
    QAxObject* _document;*/
    virtual bool translateKeyEvent(int message, int keycode) const {
50 51 52 53 54 55 56
        if (message >= WM_KEYFIRST && message <= WM_KEYLAST)
            return true;
        else
            return QAxWidget::translateKeyEvent(message, keycode);
    }

};
57 58
#endif

59 60 61
namespace Ui
{
class QGCGoogleEarthView;
pixhawk's avatar
pixhawk committed
62 63
}

pixhawk's avatar
pixhawk committed
64 65
class Waypoint;

pixhawk's avatar
pixhawk committed
66 67 68 69 70 71 72 73
class QGCGoogleEarthView : public QWidget
{
    Q_OBJECT

public:
    explicit QGCGoogleEarthView(QWidget *parent = 0);
    ~QGCGoogleEarthView();

74
    enum VIEW_MODE {
75
        VIEW_MODE_SIDE = 0, ///< View from above, orientation is free
76 77 78 79 80
        VIEW_MODE_MAP, ///< View from above, orientation is north (map view)
        VIEW_MODE_CHASE_LOCKED, ///< Locked chase camera
        VIEW_MODE_CHASE_FREE, ///< Position is chasing object, but view can rotate around object
    };

81 82 83
public slots:
    /** @brief Update the internal state. Does not trigger a redraw */
    void updateState();
pixhawk's avatar
pixhawk committed
84 85
    /** @brief Add a new MAV/UAS to the visualization */
    void addUAS(UASInterface* uas);
86 87
    /** @brief Set the currently selected UAS */
    void setActiveUAS(UASInterface* uas);
pixhawk's avatar
pixhawk committed
88
    /** @brief Update the global position */
89
    void updateGlobalPosition(UASInterface* uas, double lat, double lon, double alt, quint64 usec);
pixhawk's avatar
pixhawk committed
90 91 92 93
    /** @brief Update a single waypoint */
    void updateWaypoint(int uas, Waypoint* wp);
    /** @brief Update the waypoint list */
    void updateWaypointList(int uas);
94
    /** @brief Show the vehicle trail */
pixhawk's avatar
pixhawk committed
95
    void showTrail(bool state);
96 97
    /** @brief Clear the current vehicle trails and start with new ones */
    void clearTrails();
98
    /** @brief Show the waypoints */
pixhawk's avatar
pixhawk committed
99
    void showWaypoints(bool state);
100 101
    /** @brief Follow the aircraft during flight */
    void follow(bool follow);
pixhawk's avatar
pixhawk committed
102 103 104 105
    /** @brief Go to the home location */
    void goHome();
    /** @brief Set the home location */
    void setHome(double lat, double lon, double alt);
106 107 108 109
    /** @brief Set the home location interactively in the UI */
    void setHome();
    /** @brief Move the view to a latitude / longitude position */
    void moveToPosition();
110 111
    /** @brief Allow waypoint editing */
    void enableEditMode(bool mode);
112 113 114 115
    /** @brief Enable daylight/night */
    void enableDaylight(bool enable);
    /** @brief Enable atmosphere */
    void enableAtmosphere(bool enable);
116 117
    /** @brief Set camera view range to aircraft in meters */
    void setViewRange(float range);
118 119
    /** @brief Set the distance mode - either to ground or to MAV */
    void setDistanceMode(int mode);
120 121 122 123
    /** @brief Set the view mode */
    void setViewMode(VIEW_MODE mode);
    /** @brief Toggle through the different view modes */
    void toggleViewMode();
124 125
    /** @brief Set camera view range to aircraft in centimeters */
    void setViewRangeScaledInt(int range);
pixhawk's avatar
pixhawk committed
126 127
    /** @brief Reset Google Earth View */
    void reloadHTML();
128

pixhawk's avatar
pixhawk committed
129 130
    /** @brief Initialize Google Earth */
    void initializeGoogleEarth();
131 132
    /** @brief Print a Windows exception */
    void printWinException(int no, QString str1, QString str2, QString str3);
133 134

public:
135 136
    /** @brief Execute java script inside the Google Earth window */
    QVariant javaScript(QString javascript);
137 138
    /** @brief Get a document element */
    QVariant documentElement(QString name);
139

pixhawk's avatar
pixhawk committed
140 141
protected:
    void changeEvent(QEvent *e);
142
    QTimer* updateTimer;
pixhawk's avatar
pixhawk committed
143
    int refreshRateMs;
144 145
    UASInterface* mav;
    bool followCamera;
pixhawk's avatar
pixhawk committed
146
    bool trailEnabled;
147
    bool waypointsEnabled;
pixhawk's avatar
pixhawk committed
148
    bool webViewInitialized;
149
    bool jScriptInitialized;
pixhawk's avatar
pixhawk committed
150
    bool gEarthInitialized;
151
    VIEW_MODE currentViewMode;
152 153
#ifdef _MSC_VER
    QGCWebAxWidget* webViewWin;
154
    QAxObject* jScriptWin;
155
    QAxObject* documentWin;
156 157 158 159
#endif
#if (defined Q_OS_MAC)
    QWebView* webViewMac;
#endif
pixhawk's avatar
pixhawk committed
160

161
    /** @brief Start widget updating */
162
    void showEvent(QShowEvent* event);
163 164
    /** @brief Stop widget updating */
    void hideEvent(QHideEvent* event);
165

pixhawk's avatar
pixhawk committed
166
private:
167 168
#ifdef _MSC_VER
    Ui::QGCGoogleEarthView* ui;
169 170
#else
    Ui::QGCGoogleEarthView* ui;
171
#endif
pixhawk's avatar
pixhawk committed
172 173
};

174
#endif // QGCGOOGLEEARTHVIEW_H