MapWidget.h 6 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2
/*=====================================================================

3
QGroundControl Open Source Ground Control Station
pixhawk's avatar
pixhawk committed
4

5
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
pixhawk's avatar
pixhawk committed
6

7
This file is part of the QGROUNDCONTROL project
pixhawk's avatar
pixhawk committed
8

9
    QGROUNDCONTROL is free software: you can redistribute it and/or modify
pixhawk's avatar
pixhawk committed
10 11 12 13
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

14
    QGROUNDCONTROL is distributed in the hope that it will be useful,
pixhawk's avatar
pixhawk committed
15 16 17 18 19
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
20
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
pixhawk's avatar
pixhawk committed
21 22 23 24 25

======================================================================*/

/**
 * @file
pixhawk's avatar
pixhawk committed
26
 *   @brief Definition of MapWidget
pixhawk's avatar
pixhawk committed
27 28
 *
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
lm's avatar
lm committed
29
 *   @author Mariano Lizarraga
pixhawk's avatar
pixhawk committed
30 31 32 33 34 35 36
 *
 */

#ifndef MAPWIDGET_H
#define MAPWIDGET_H

#include <QtGui/QWidget>
pixhawk's avatar
pixhawk committed
37
#include <QMap>
pixhawk's avatar
pixhawk committed
38
#include "qmapcontrol.h"
lm's avatar
lm committed
39
#include "UASInterface.h"
40 41 42
#include "QPointF"

#include <qmath.h>
lm's avatar
lm committed
43 44


pixhawk's avatar
pixhawk committed
45

lm's avatar
lm committed
46
class QMenu;
47
class Waypoint;
pixhawk's avatar
pixhawk committed
48
class Waypoint2DIcon;
lm's avatar
lm committed
49

50 51 52
namespace Ui
{
class MapWidget;
pixhawk's avatar
pixhawk committed
53 54
}

55
using namespace qmapcontrol;
56

lm's avatar
lm committed
57 58 59 60 61 62
/**
 * @brief 2D Moving map
 *
 * This map displays street maps, aerial images and the MAV position,
 * waypoints and trails on top.
 */
63 64
class MapWidget : public QWidget
{
pixhawk's avatar
pixhawk committed
65 66 67 68 69 70
    Q_OBJECT
public:
    MapWidget(QWidget *parent = 0);
    ~MapWidget();

public slots:
lm's avatar
lm committed
71
    void addUAS(UASInterface* uas);
72
    void activeUASSet(UASInterface* uas);
73 74
    /** @brief Update the system specs of one system */
    void updateSystemSpecs(int uas);
75 76
    /** @brief Update the selected system */
    void updateSelectedSystem(int uas);
77 78
    /** @brief Update the attitude */
    void updateAttitude(UASInterface* uas, double roll, double pitch, double yaw, quint64 usec);
lm's avatar
lm committed
79 80
    void updateGlobalPosition(UASInterface* uas, double lat, double lon, double alt, quint64 usec);
    void updatePosition(float time, double lat, double lon);
lm's avatar
lm committed
81 82
    void updateCameraPosition(double distance, double bearing, QString dir);
    QPointF getPointxBearing_Range(double lat1, double lon1, double bearing, double distance);
pixhawk's avatar
pixhawk committed
83

84
    /** @brief Clear the waypoints overlay layer */
85
    void clearWaypoints(int uas=0);
86
    /** @brief Clear the UAV tracks on the map */
87 88 89 90 91 92 93 94 95
    void clearPath(int uas=0);

    /** @brief Update waypoint list */
    void updateWaypointList(int uas);
    /** @brief Clear all waypoints and re-add them from updated list */
    void redoWaypoints(int uas=0);

    /** @brief Update waypoint */
    void updateWaypoint(int uas, Waypoint* wp);
96
    void updateWaypoint(int uas, Waypoint* wp, bool updateView);
97

lm's avatar
lm committed
98
    void drawBorderCamAtMap(bool status);
99 100
    /** @brief Bring up dialog to go to a specific location */
    void goTo();
101

pixhawk's avatar
pixhawk committed
102 103 104 105 106
protected:
    void changeEvent(QEvent* e);
    void wheelEvent(QWheelEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void resizeEvent(QResizeEvent* event);
107 108 109 110
    /** @brief Start widget updating */
    void showEvent(QShowEvent* event);
    /** @brief Stop widget updating */
    void hideEvent(QHideEvent* event);
pixhawk's avatar
pixhawk committed
111

lm's avatar
lm committed
112 113 114 115 116 117 118
    QAction* osmAction;
    QAction* yahooActionMap;
    QAction* yahooActionSatellite;
    QAction* yahooActionOverlay;
    QAction* googleActionMap;
    QAction* googleSatAction;

119

pixhawk's avatar
pixhawk committed
120
    QPushButton* followgps;
121
    QPushButton* createPath;
122
    QPushButton* clearTracking;
pixhawk's avatar
pixhawk committed
123
    QLabel* gpsposition;
lm's avatar
lm committed
124 125 126
    QMenu* mapMenu;
    QPushButton* mapButton;

127 128 129 130 131 132
    qmapcontrol::MapControl* mc;            ///< QMapControl widget
    qmapcontrol::MapAdapter* mapadapter;    ///< Adapter to load the map data
    qmapcontrol::Layer* l;                  ///< Current map layer (background)
    qmapcontrol::Layer* overlay;            ///< Street overlay (foreground)
    qmapcontrol::Layer* tracks;             ///< Layer for UAV tracks
    qmapcontrol::GeometryLayer* geomLayer;  ///< Layer for waypoints
lm's avatar
lm committed
133 134 135

    //only for experiment
    qmapcontrol::GeometryLayer* camLayer; ///< Layer for camera indicator
136

pixhawk's avatar
pixhawk committed
137 138 139
    int zoomLevel;
    int detailZoom; ///< Steps zoomed in further than qMapControl allows
    static const int scrollStep = 40; ///< Scroll n pixels per keypress
lm's avatar
lm committed
140
    static const int maxZoom = 50;    ///< Maximum zoom level
141

142
    //Layer* gSatLayer;
pixhawk's avatar
pixhawk committed
143

144 145
    QMap<int, qmapcontrol::Point*> uasIcons;
    QMap<int, qmapcontrol::LineString*> uasTrails;
146
    QMap<int, QPen*> mavPens;
lm's avatar
lm committed
147 148
    //QMap<int, QList<qmapcontrol::Point*> > mavWps;
    //QMap<int, qmapcontrol::LineString*> waypointPaths;
lm's avatar
lm committed
149
    UASInterface* mav;
pixhawk's avatar
pixhawk committed
150
    quint64 lastUpdate;
151 152 153 154
    bool initialized;

    /** @brief Initialize view */
    void init();
lm's avatar
lm committed
155

156
protected slots:
157
    void captureMapClick (const QMouseEvent* event, const QPointF coordinate);
158 159 160
    void captureGeometryClick(Geometry*, QPoint);
    void captureGeometryDrag(Geometry* geom, QPointF coordinate);
    void captureGeometryEndDrag(Geometry* geom, QPointF coordinate);
161

162 163
    void createPathButtonClicked(bool checked);

164 165
    /** @brief Create the graphic representation of the waypoint */
    void createWaypointGraphAtMap(int id, const QPointF coordinate);
166 167
    void mapproviderSelected(QAction* action);

168
signals:
lm's avatar
lm committed
169 170 171
    //void movePoint(QPointF newCoord);
    //void captureMapCoordinateClick(const QPointF coordinate); //ROCA
    //void createGlobalWP(bool value, QPointF centerCoordinate);
172
    void waypointCreated(Waypoint* wp);
173
    void sendGeometryEndDrag(const QPointF coordinate, const int index);
174

lm's avatar
lm committed
175

pixhawk's avatar
pixhawk committed
176 177
private:
    Ui::MapWidget *m_ui;
178
    QList<qmapcontrol::Point*> wps;
pixhawk's avatar
pixhawk committed
179
    QList<Waypoint2DIcon*>wpIcons;
180
    qmapcontrol::LineString* waypointPath;
181
    //QHash <QString, qmapcontrol::Point*> wpIndex;
182
    QPen* pointPen;
183
    int wpExists(const QPointF coordinate);
184
    bool waypointIsDrag;
lm's avatar
lm committed
185 186 187 188 189 190 191 192


    qmapcontrol::LineString* camLine;
    QList<qmapcontrol::Point*> camPoints;
    QPointF lastCamBorderPos;
    bool drawCamBorder;
    int radioCamera;

pixhawk's avatar
pixhawk committed
193 194 195
};

#endif // MAPWIDGET_H