MapWidget.h 4.96 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 43 44
#include "QPointF"

#include <qmath.h>


pixhawk's avatar
pixhawk committed
45

lm's avatar
lm committed
46 47
class QMenu;

pixhawk's avatar
pixhawk committed
48 49 50 51
namespace Ui {
    class MapWidget;
}

52 53
    using namespace qmapcontrol;

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

public slots:
lm's avatar
lm committed
67
    void addUAS(UASInterface* uas);
68
    void activeUASSet(UASInterface* uas);
lm's avatar
lm committed
69 70
    void updateGlobalPosition(UASInterface* uas, double lat, double lon, double alt, quint64 usec);
    void updatePosition(float time, double lat, double lon);
71 72
    void updateCameraPosition(double distance, double bearing, QString dir);
    QPointF getPointxBearing_Range(double lat1, double lon1, double bearing, double distance);
pixhawk's avatar
pixhawk committed
73

74 75 76
    /** @brief Clear the waypoints overlay layer */
    void clearWaypoints();
    /** @brief Clear the UAV tracks on the map */
77
    void clearPath();
78
    void changeGlobalWaypointPositionBySpinBox(int index, float lat, float lon);
79
    void drawBorderCamAtMap(bool status);
80

pixhawk's avatar
pixhawk committed
81 82 83 84 85
protected:
    void changeEvent(QEvent* e);
    void wheelEvent(QWheelEvent *event);
    void keyPressEvent(QKeyEvent *event);
    void resizeEvent(QResizeEvent* event);
86 87 88 89
    /** @brief Start widget updating */
    void showEvent(QShowEvent* event);
    /** @brief Stop widget updating */
    void hideEvent(QHideEvent* event);
pixhawk's avatar
pixhawk committed
90

lm's avatar
lm committed
91 92 93 94 95 96 97
    QAction* osmAction;
    QAction* yahooActionMap;
    QAction* yahooActionSatellite;
    QAction* yahooActionOverlay;
    QAction* googleActionMap;
    QAction* googleSatAction;

98

pixhawk's avatar
pixhawk committed
99
    QPushButton* followgps;
100
    QPushButton* createPath;
101
    QPushButton* clearTracking;
pixhawk's avatar
pixhawk committed
102
    QLabel* gpsposition;
lm's avatar
lm committed
103 104 105
    QMenu* mapMenu;
    QPushButton* mapButton;

106 107
    qmapcontrol::MapControl* mc;                   ///< QMapControl widget
    qmapcontrol::MapAdapter* mapadapter;           ///< Adapter to load the map data
lm's avatar
lm committed
108 109
    qmapcontrol::Layer* l;            ///< Current map layer (background)
    qmapcontrol::Layer* overlay;      ///< Street overlay (foreground)
110
    qmapcontrol::Layer* tracks;      ///< Layer for UAV tracks
lm's avatar
lm committed
111
    qmapcontrol::GeometryLayer* geomLayer; ///< Layer for waypoints
112 113 114 115

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

pixhawk's avatar
pixhawk committed
116 117 118
    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
119
    static const int maxZoom = 50;    ///< Maximum zoom level
120

121
    //Layer* gSatLayer;
pixhawk's avatar
pixhawk committed
122

123 124
    QMap<int, qmapcontrol::Point*> uasIcons;
    QMap<int, qmapcontrol::LineString*> uasTrails;
lm's avatar
lm committed
125
    UASInterface* mav;
pixhawk's avatar
pixhawk committed
126
    quint64 lastUpdate;
lm's avatar
lm committed
127

128 129
  protected slots:
    void captureMapClick (const QMouseEvent* event, const QPointF coordinate);
130 131 132
    void captureGeometryClick(Geometry*, QPoint);
    void captureGeometryDrag(Geometry* geom, QPointF coordinate);
    void captureGeometryEndDrag(Geometry* geom, QPointF coordinate);
133

134 135 136 137 138
    void createPathButtonClicked(bool checked);

    void createWaypointGraphAtMap (const QPointF coordinate);
    void mapproviderSelected(QAction* action);

139
  signals:
140
    //void movePoint(QPointF newCoord);
141
    void captureMapCoordinateClick(const QPointF coordinate); //ROCA
142
    void createGlobalWP(bool value, QPointF centerCoordinate);
143
    void sendGeometryEndDrag(const QPointF coordinate, const int index);
144

145

pixhawk's avatar
pixhawk committed
146 147
private:
    Ui::MapWidget *m_ui;
148
    QList<qmapcontrol::Point*> wps;
149
    qmapcontrol::LineString* waypointPath;
150
    QHash <QString, qmapcontrol::Point*> wpIndex;
151
    QPen* pointPen;
152
    int wpExists(const QPointF coordinate);
153
    bool waypointIsDrag;
154 155 156 157 158 159 160 161


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

pixhawk's avatar
pixhawk committed
162 163 164
};

#endif // MAPWIDGET_H