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

4
#include <QMap>
5
#include <QTimer>
6
#include "../../../libs/opmapcontrol/opmapcontrol.h"
lm's avatar
lm committed
7

lm's avatar
lm committed
8
class UASInterface;
9 10
class UASWaypointManager;
class Waypoint;
11
typedef mapcontrol::WayPointItem WayPointItem;
lm's avatar
lm committed
12

13 14 15
/**
 * @brief Class representing a 2D map using aerial imagery
 */
lm's avatar
lm committed
16
class QGCMapWidget : public mapcontrol::OPMapWidget
lm's avatar
lm committed
17 18 19 20
{
    Q_OBJECT
public:
    explicit QGCMapWidget(QWidget *parent = 0);
lm's avatar
lm committed
21
    ~QGCMapWidget();
22 23 24 25
//    /** @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
26

27 28
    /** @brief Map centered on current active system */
    bool getFollowUAVEnabled() { return followUAVEnabled; }
29
    /** @brief The maximum map update rate */
30 31 32 33 34
    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; }
35

lm's avatar
lm committed
36
signals:
37
    void homePositionChanged(double latitude, double longitude, double altitude);
38 39 40
    /** @brief Signal for newly created map waypoints */
    void waypointCreated(Waypoint* wp);
    void waypointChanged(Waypoint* wp);
lm's avatar
lm committed
41 42

public slots:
43 44
    /** @brief Action triggered with point-camera action is selected from the context menu */
    void cameraActionTriggered();
45 46 47 48
    /** @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();
49
    /** @brief Add system to map view */
lm's avatar
lm committed
50
    void addUAS(UASInterface* uas);
51
    /** @brief Update the global position of a system */
lm's avatar
lm committed
52
    void updateGlobalPosition(UASInterface* uas, double lat, double lon, double alt, quint64 usec);
53 54
    /** @brief Update the global position of all systems */
    void updateGlobalPosition();
55 56 57 58
    /** @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();
59 60
    /** @brief Update the type, size, etc. of this system */
    void updateSystemSpecs(int uas);
61 62 63 64
    /** @brief Change current system in focus / editing */
    void activeUASSet(UASInterface* uas);
    /** @brief Show a dialog to jump to given GPS coordinates */
    void showGoToDialog();
65 66
    /** @brief Jump to the home position on the map */
    void goHome();
67 68 69 70 71 72
    /** @brief Update this waypoint for this UAS */
    void updateWaypoint(int uas, Waypoint* wp);
    /** @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);
73 74
    /** @brief Set update rate limit */
    void setUpdateRateLimit(float seconds);
75 76 77 78
    /** @brief Cache visible region to harddisk */
    void cacheVisibleRegion();
    /** @brief Set follow mode */
    void setFollowUAVEnabled(bool enabled) { followUAVEnabled = enabled; }
79
    /** @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*/
80 81 82 83
    void setTrailModeTimed(int seconds)
    {
        foreach(mapcontrol::UAVItem* uav, GetUAVS())
        {
84 85 86 87 88 89 90 91 92
            if (seconds >= 0)
            {
                uav->SetTrailTime(seconds);
                uav->SetTrailType(mapcontrol::UAVTrailType::ByTimeElapsed);
            }
            else
            {
                uav->SetTrailType(mapcontrol::UAVTrailType::NoTrail);
            }
93 94
        }
    }
95
    /** @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*/
96 97 98 99
    void setTrailModeDistance(int meters)
    {
        foreach(mapcontrol::UAVItem* uav, GetUAVS())
        {
100 101 102 103 104 105 106 107 108
            if (meters >= 0)
            {
                uav->SetTrailDistance(meters);
                uav->SetTrailType(mapcontrol::UAVTrailType::ByDistance);
            }
            else
            {
                uav->SetTrailType(mapcontrol::UAVTrailType::NoTrail);
            }
109 110
        }
    }
lm's avatar
lm committed
111 112 113 114 115 116 117 118
    /** @brief Delete all trails */
    void deleteTrails()
    {
        foreach(mapcontrol::UAVItem* uav, GetUAVS())
        {
            uav->DeleteTrail();
        }
    }
119

120
    /** @brief Load the settings for this widget from disk */
121
    void loadSettings(bool changePosition=true);
122
    /** @brief Store the settings for this widget to disk */
123 124
    void storeSettings();

125 126 127 128
protected slots:
    /** @brief Convert a map edit into a QGC waypoint event */
    void handleMapWaypointEdit(WayPointItem* waypoint);

129
protected:
130 131
    /** @brief Update the highlighting of the currently controlled system */
    void updateSelectedSystem(int uas);
132 133 134
    /** @brief Initialize */
    void showEvent(QShowEvent* event);
    void hideEvent(QHideEvent* event);
135 136
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
137
    void mouseDoubleClickEvent(QMouseEvent* event);
138 139 140 141

    UASWaypointManager* currWPManager; ///< The current waypoint manager
    QMap<Waypoint* , mapcontrol::WayPointItem*> waypointsToIcons;
    QMap<mapcontrol::WayPointItem*, Waypoint*> iconsToWaypoints;
142
    Waypoint* firingWaypointChange;
143 144
    QTimer updateTimer;
    float maxUpdateInterval;
145 146 147 148 149 150 151 152 153
    enum editMode {
        EDIT_MODE_NONE,
        EDIT_MODE_WAYPOINTS,
        EDIT_MODE_SWEEP,
        EDIT_MODE_UAVS,
        EDIT_MODE_HOME,
        EDIT_MODE_SAFE_AREA,
        EDIT_MODE_CACHING
    };
154
    editMode currEditMode;              ///< The current edit mode on the map
155
    bool followUAVEnabled;              ///< Does the map follow the UAV?
156 157
    mapcontrol::UAVTrailType::Types trailType; ///< Time or distance based trail dots
    float trailInterval;                ///< Time or distance between trail items
158
    int followUAVID;                    ///< Which UAV should be tracked?
159
    bool mapInitialized;                ///< Map initialized?
160
    float homeAltitude;                 ///< Home altitude
161 162
    QPoint mousePressPos;               ///< Mouse position when the button is released.
    int defaultGuidedAlt;               ///< Default altitude for guided mode
163
    UASInterface *uas;                  ///< Currently selected UAS.
lm's avatar
lm committed
164 165 166 167

};

#endif // QGCMAPWIDGET_H