QGCMapWidget.h 7.13 KB
Newer Older
lm's avatar
lm committed
1 2 3
#ifndef QGCMAPWIDGET_H
#define QGCMAPWIDGET_H

4
#include <QMap>
5
#include <QTimer>
6

Don Gagne's avatar
Don Gagne committed
7
#include "opmapcontrol.h"
8
#include "Vehicle.h"
lm's avatar
lm committed
9

10
// Choose one default map type
Lorenz Meier's avatar
Lorenz Meier committed
11 12
//#define MAP_DEFAULT_TYPE_BING
#define MAP_DEFAULT_TYPE_GOOGLE
13 14
//#define MAP_DEFAULT_TYPE_OSM

lm's avatar
lm committed
15
class UASInterface;
16
class UASWaypointManager;
17
class MissionItem;
18
typedef mapcontrol::WayPointItem WayPointItem;
lm's avatar
lm committed
19

20 21 22
/**
 * @brief Class representing a 2D map using aerial imagery
 */
lm's avatar
lm committed
23
class QGCMapWidget : public mapcontrol::OPMapWidget
lm's avatar
lm committed
24 25 26 27
{
    Q_OBJECT
public:
    explicit QGCMapWidget(QWidget *parent = 0);
lm's avatar
lm committed
28
    ~QGCMapWidget();
29 30 31 32
//    /** @brief Convert meters to pixels */
//    float metersToPixels(double meters);
//    double headingP1P2(internals::PointLatLng p1, internals::PointLatLng p2);
//    internals::PointLatLng targetLatLon(internals::PointLatLng source, double heading, double dist);
lm's avatar
lm committed
33

34 35
    /** @brief Map centered on current active system */
    bool getFollowUAVEnabled() { return followUAVEnabled; }
36
    /** @brief The maximum map update rate */
37 38 39 40 41
    float getUpdateRateLimit() { return maxUpdateInterval; }
    /** @brief Get the trail type */
    int getTrailType() { return static_cast<int>(trailType); }
    /** @brief Get the trail interval */
    float getTrailInterval() { return trailInterval; }
42

lm's avatar
lm committed
43
signals:
44
    void homePositionChanged(double latitude, double longitude, double altitude);
45
    /** @brief Signal for newly created map waypoints */
46 47
    void waypointCreated(MissionItem* wp);
    void waypointChanged(MissionItem* wp);
lm's avatar
lm committed
48 49

public slots:
50 51 52 53
    /** @brief Action triggered when guided action is selected from the context menu */
    void guidedActionTriggered();
    /** @brief Action triggered when guided action is selected from the context menu, allows for altitude selection */
    bool guidedAltActionTriggered();
54 55
    /** @brief Action triggered when set home action is selected from the context menu. */
    bool setHomeActionTriggered();
56
    /** @brief Update the global position of a system */
57
    void updateGlobalPosition(UASInterface* uas, double lat, double lon, double altAMSL, double altWGS84, quint64 usec);
58 59
    /** @brief Update the global position of all systems */
    void updateGlobalPosition();
60 61 62 63
    /** @brief Update the local position and draw it converted to GPS reference */
    void updateLocalPosition();
    /** @brief Update the local position estimates (individual sensors) and draw it converted to GPS reference */
    void updateLocalPositionEstimates();
64 65
    /** @brief Update the type, size, etc. of this system */
    void updateSystemSpecs(int uas);
66 67
    /** @brief Show a dialog to jump to given GPS coordinates */
    void showGoToDialog();
68 69
    /** @brief Jump to the home position on the map */
    void goHome();
70
    /** @brief Update this waypoint for this UAS */
71
    void updateWaypoint(int uas, MissionItem* wp);
72 73 74 75
    /** @brief Update the whole waypoint */
    void updateWaypointList(int uas);
    /** @brief Update the home position on the map */
    void updateHomePosition(double latitude, double longitude, double altitude);
76 77
    /** @brief Set update rate limit */
    void setUpdateRateLimit(float seconds);
78 79 80 81
    /** @brief Cache visible region to harddisk */
    void cacheVisibleRegion();
    /** @brief Set follow mode */
    void setFollowUAVEnabled(bool enabled) { followUAVEnabled = enabled; }
82
    /** @brief Set trail to time mode and set time @param seconds The minimum time between trail dots in seconds. If set to a value < 0, trails will be disabled*/
83 84 85 86
    void setTrailModeTimed(int seconds)
    {
        foreach(mapcontrol::UAVItem* uav, GetUAVS())
        {
87 88 89 90 91 92 93 94 95
            if (seconds >= 0)
            {
                uav->SetTrailTime(seconds);
                uav->SetTrailType(mapcontrol::UAVTrailType::ByTimeElapsed);
            }
            else
            {
                uav->SetTrailType(mapcontrol::UAVTrailType::NoTrail);
            }
96 97
        }
    }
98
    /** @brief Set trail to distance mode and set time @param meters The minimum distance between trail dots in meters. The actual distance depends on the MAV's update rate as well. If set to a value < 0, trails will be disabled*/
99 100 101 102
    void setTrailModeDistance(int meters)
    {
        foreach(mapcontrol::UAVItem* uav, GetUAVS())
        {
103 104 105 106 107 108 109 110 111
            if (meters >= 0)
            {
                uav->SetTrailDistance(meters);
                uav->SetTrailType(mapcontrol::UAVTrailType::ByDistance);
            }
            else
            {
                uav->SetTrailType(mapcontrol::UAVTrailType::NoTrail);
            }
112 113
        }
    }
lm's avatar
lm committed
114 115 116 117 118 119 120 121
    /** @brief Delete all trails */
    void deleteTrails()
    {
        foreach(mapcontrol::UAVItem* uav, GetUAVS())
        {
            uav->DeleteTrail();
        }
    }
122

123 124 125 126 127
    void setZoomBlocked(bool blocked)
    {
        zoomBlocked = blocked;
    }

128
    /** @brief Load the settings for this widget from disk */
129
    void loadSettings(bool changePosition=true);
130
    /** @brief Store the settings for this widget to disk */
131 132
    void storeSettings();

133 134 135 136
protected slots:
    /** @brief Convert a map edit into a QGC waypoint event */
    void handleMapWaypointEdit(WayPointItem* waypoint);

137
protected:
138 139
    /** @brief Update the highlighting of the currently controlled system */
    void updateSelectedSystem(int uas);
140 141 142
    /** @brief Initialize */
    void showEvent(QShowEvent* event);
    void hideEvent(QHideEvent* event);
143
    void wheelEvent(QWheelEvent* event);
144 145
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
146
    void mouseDoubleClickEvent(QMouseEvent* event);
147

148 149
    //void contextMenuEvent(QContextMenuEvent *);

150
    UASWaypointManager* currWPManager; ///< The current waypoint manager
151
    bool offlineMode;
152 153 154
    QMap<MissionItem* , mapcontrol::WayPointItem*> waypointsToIcons;
    QMap<mapcontrol::WayPointItem*, MissionItem*> iconsToWaypoints;
    MissionItem* firingWaypointChange;
155 156
    QTimer updateTimer;
    float maxUpdateInterval;
157 158 159 160 161 162 163 164 165
    enum editMode {
        EDIT_MODE_NONE,
        EDIT_MODE_WAYPOINTS,
        EDIT_MODE_SWEEP,
        EDIT_MODE_UAVS,
        EDIT_MODE_HOME,
        EDIT_MODE_SAFE_AREA,
        EDIT_MODE_CACHING
    };
166
    editMode currEditMode;              ///< The current edit mode on the map
167
    bool followUAVEnabled;              ///< Does the map follow the UAV?
168 169
    mapcontrol::UAVTrailType::Types trailType; ///< Time or distance based trail dots
    float trailInterval;                ///< Time or distance between trail items
170
    int followUAVID;                    ///< Which UAV should be tracked?
171
    bool mapInitialized;                ///< Map initialized?
172
    bool mapPositionInitialized;        ///< The position on the map has a reasonable value?
173
    float homeAltitude;                 ///< Home altitude
174
    QPoint mousePressPos;               ///< Mouse position when the button is released.
175
    QPoint contextMousePressPos;        ///< Mouse position when context menu activated.
176
    int defaultGuidedAlt;               ///< Default altitude for guided mode
177
    bool zoomBlocked;                   ///< Wether zooming is blocked
178
    UASInterface* _uas;                 ///< Currently selected UAS.
lm's avatar
lm committed
179

180 181 182
private slots:
    void _vehicleAdded(Vehicle* vehicle);
    void _activeVehicleChanged(Vehicle* vehicle);
lm's avatar
lm committed
183 184 185
};

#endif // QGCMAPWIDGET_H