LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / opmap / opmapgadgetwidget.h
blob7b6d1c3614800054b798bb04148ceab4553a6e10
1 /**
2 ******************************************************************************
4 * @file opmapgadgetwidget.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup OPMapPlugin OpenPilot Map Plugin
9 * @{
10 * @brief The OpenPilot Map plugin
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef OPMAP_GADGETWIDGET_H_
29 #define OPMAP_GADGETWIDGET_H_
31 // ******************************************************
34 #include "flightdatamodel.h"
35 #include "pathplanner.h"
36 #include "modelmapproxy.h"
37 #include "modeluavoproxy.h"
39 #include <QWidget>
40 #include <QMenu>
41 #include <QStringList>
42 #include <QStandardItemModel>
43 #include <QList>
44 #include <QMutex>
45 #include <QMutexLocker>
46 #include <QPointF>
48 #include "opmapcontrol/opmapcontrol.h"
50 #include "opmap_zoom_slider_widget.h"
51 #include "opmap_statusbar_widget.h"
53 #include "utils/coordinateconversions.h"
55 #include "extensionsystem/pluginmanager.h"
56 #include "uavobjectutilmanager.h"
57 #include "uavobjectmanager.h"
58 #include "uavobject.h"
59 #include "objectpersistence.h"
60 #include <QItemSelectionModel>
61 #include "opmap_edit_waypoint_dialog.h"
63 #include "homeeditor.h"
65 // ******************************************************
67 namespace Ui {
68 class OPMap_Widget;
71 using namespace mapcontrol;
73 // ******************************************************
75 typedef struct t_home {
76 internals::PointLatLng coord;
77 double altitude;
78 bool locked;
79 } t_home;
81 // ******************************************************
83 enum opMapModeType { Normal_MapMode = 0,
84 MagicWaypoint_MapMode = 1 };
86 // ******************************************************
88 class OPMapGadgetWidget : public QWidget {
89 Q_OBJECT
91 public:
92 OPMapGadgetWidget(QWidget *parent = 0);
93 ~OPMapGadgetWidget();
95 /**
96 * @brief public functions
98 * @param
100 void setHome(QPointF pos);
101 void setHome(internals::PointLatLng pos_lat_lon, double altitude);
102 void goHome();
103 void setZoom(int zoom);
104 void setPosition(QPointF pos);
105 void setMapProvider(QString provider);
106 void setUseOpenGL(bool useOpenGL);
107 void setShowTileGridLines(bool showTileGridLines);
108 void setAccessMode(QString accessMode);
109 void setUseMemoryCache(bool useMemoryCache);
110 void setCacheLocation(QString cacheLocation);
111 void setMapMode(opMapModeType mode);
112 void SetUavPic(QString UAVPic);
113 void setMaxUpdateRate(int update_rate);
114 void setHomePosition(QPointF pos);
115 void setOverlayOpacity(qreal value);
116 bool getGPSPositionSensor(double &latitude, double &longitude, double &altitude);
117 signals:
118 void defaultLocationAndZoomChanged(double lng, double lat, double zoom);
119 void overlayOpacityChanged(qreal);
121 public slots:
122 void homePositionUpdated(UAVObject *);
123 void onTelemetryConnect();
124 void onTelemetryDisconnect();
126 protected:
127 void resizeEvent(QResizeEvent *event);
128 void mouseMoveEvent(QMouseEvent *event);
129 void contextMenuEvent(QContextMenuEvent *event);
130 void closeEvent(QCloseEvent *);
131 private slots:
132 void wpDoubleClickEvent(WayPointItem *wp);
133 void updatePosition();
135 void updateMousePos();
137 void zoomIn();
138 void zoomOut();
141 * @brief signals received from the various map plug-in widget user controls
143 * Some are currently disabled for the v1.0 plugin version.
145 void on_toolButtonZoomM_clicked();
146 void on_toolButtonZoomP_clicked();
147 void on_toolButtonMapHome_clicked();
148 void on_toolButtonMapUAV_clicked();
149 void on_toolButtonMapUAVheading_clicked();
150 void on_horizontalSliderZoom_sliderMoved(int position);
151 void on_toolButtonMagicWaypointMapMode_clicked();
152 void on_toolButtonNormalMapMode_clicked();
153 void on_toolButtonHomeWaypoint_clicked();
154 void on_toolButtonMoveToWP_clicked();
157 * @brief signals received from the map object
159 void zoomChanged(double zoomt, double zoom, double zoomd);
160 void OnCurrentPositionChanged(internals::PointLatLng point);
161 void OnTileLoadComplete();
162 void OnTileLoadStart();
163 void OnTilesStillToLoad(int number);
166 * @brief mouse right click context menu signals
168 void onReloadAct_triggered();
169 void onRipAct_triggered();
170 void onCopyMouseLatLonToClipAct_triggered();
171 void onCopyMouseLatToClipAct_triggered();
172 void onCopyMouseLonToClipAct_triggered();
173 void onShowCompassAct_toggled(bool show);
174 void onShowDiagnostics_toggled(bool show);
175 void onShowUAVInfo_toggled(bool show);
176 void onShowUAVAct_toggled(bool show);
177 void onShowHomeAct_toggled(bool show);
178 void onShowTrailLineAct_toggled(bool show);
179 void onShowTrailAct_toggled(bool show);
180 void onGoZoomInAct_triggered();
181 void onGoZoomOutAct_triggered();
182 void onGoMouseClickAct_triggered();
183 void onSetHomeAct_triggered();
184 void onGoHomeAct_triggered();
185 void onGoUAVAct_triggered();
186 void onFollowUAVpositionAct_toggled(bool checked);
187 void onFollowUAVheadingAct_toggled(bool checked);
189 void onOpenWayPointEditorAct_triggered();
190 void onAddWayPointAct_triggeredFromContextMenu();
191 void onAddWayPointAct_triggeredFromThis();
192 void onAddWayPointAct_triggered(internals::PointLatLng coord);
193 void onEditWayPointAct_triggered();
194 void onLockWayPointAct_triggered();
195 void onDeleteWayPointAct_triggered();
196 void onClearWayPointsAct_triggered();
198 void onMapModeActGroup_triggered(QAction *action);
199 void onZoomActGroup_triggered(QAction *action);
200 void onHomeMagicWaypointAct_triggered();
201 void onShowSafeAreaAct_toggled(bool show);
202 void onSafeAreaActGroup_triggered(QAction *action);
203 void onUAVTrailTypeActGroup_triggered(QAction *action);
204 void onClearUAVtrailAct_triggered();
205 void onUAVTrailTimeActGroup_triggered(QAction *action);
206 void onUAVTrailDistanceActGroup_triggered(QAction *action);
207 void onMaxUpdateRateActGroup_triggered(QAction *action);
208 void onChangeDefaultLocalAndZoom();
209 void on_tbFind_clicked();
210 void onHomeDoubleClick(HomeItem *);
211 void onOverlayOpacityActGroup_triggered(QAction *action);
212 void on_leFind_returnPressed();
214 private:
215 int m_min_zoom;
216 int m_max_zoom;
217 double m_heading; // uav heading
218 internals::PointLatLng m_mouse_lat_lon;
219 internals::PointLatLng m_context_menu_lat_lon;
220 int m_prev_tile_number;
221 opMapModeType m_map_mode;
222 int m_maxUpdateRate;
223 t_home m_home_position;
224 QStringList findPlaceWordList;
225 QCompleter *findPlaceCompleter;
226 QTimer *m_updateTimer;
227 QTimer *m_statusUpdateTimer;
228 Ui::OPMap_Widget *m_widget;
229 mapcontrol::OPMapWidget *m_map;
230 ExtensionSystem::PluginManager *pm;
231 UAVObjectManager *obm;
232 UAVObjectUtilManager *obum;
233 QPointer<opmap_edit_waypoint_dialog> waypoint_edit_dialog;
234 QStandardItemModel wayPoint_treeView_model;
235 mapcontrol::WayPointItem *m_mouse_waypoint;
236 QPointer<ModelUavoProxy> UAVProxy;
237 QMutex m_map_mutex;
238 bool m_telemetry_connected;
239 QAction *reloadAct;
240 QAction *ripAct;
241 QAction *copyMouseLatLonToClipAct;
242 QAction *copyMouseLatToClipAct;
243 QAction *copyMouseLonToClipAct;
244 QAction *showCompassAct;
245 QAction *showDiagnostics;
246 QAction *showUAVInfo;
247 QAction *showHomeAct;
248 QAction *showUAVAct;
249 QAction *zoomInAct;
250 QAction *zoomOutAct;
251 QAction *goMouseClickAct;
252 QAction *setHomeAct;
253 QAction *goHomeAct;
254 QAction *goUAVAct;
255 QAction *followUAVpositionAct;
256 QAction *followUAVheadingAct;
258 QAction *wayPointEditorAct;
259 QAction *addWayPointActFromThis;
260 QAction *addWayPointActFromContextMenu;
261 QAction *editWayPointAct;
262 QAction *lockWayPointAct;
263 QAction *deleteWayPointAct;
264 QAction *clearWayPointsAct;
266 QAction *homeMagicWaypointAct;
268 QAction *showSafeAreaAct;
269 QAction *changeDefaultLocalAndZoom;
270 QActionGroup *safeAreaActGroup;
271 QList<QAction *> safeAreaAct;
273 QActionGroup *uavTrailTypeActGroup;
274 QList<QAction *> uavTrailTypeAct;
275 QAction *clearUAVtrailAct;
276 QActionGroup *uavTrailTimeActGroup;
277 QAction *showTrailLineAct;
278 QAction *showTrailAct;
279 QList<QAction *> uavTrailTimeAct;
280 QActionGroup *uavTrailDistanceActGroup;
281 QList<QAction *> uavTrailDistanceAct;
283 QActionGroup *mapModeActGroup;
284 QList<QAction *> mapModeAct;
286 QActionGroup *zoomActGroup;
287 QActionGroup *overlayOpacityActGroup;
288 QList<QAction *> zoomAct;
289 QList<QAction *> overlayOpacityAct;
291 QActionGroup *maxUpdateRateActGroup;
292 QList<QAction *> maxUpdateRateAct;
294 void createActions();
295 void homeMagicWaypoint();
296 void moveToMagicWaypointPosition();
297 void hideMagicWaypointControls();
298 void showMagicWaypointControls();
299 void keepMagicWaypointWithInSafeArea();
301 double distance(internals::PointLatLng from, internals::PointLatLng to);
302 double bearing(internals::PointLatLng from, internals::PointLatLng to);
303 internals::PointLatLng destPoint(internals::PointLatLng source, double bear, double dist);
305 bool getUAVPosition(double &latitude, double &longitude, double &altitude);
306 double getUAV_Yaw();
308 void setMapFollowingMode();
310 bool setHomeLocationObject();
311 internals::PointLatLng lastLatLngMouse;
312 WayPointItem *magicWayPoint;
314 QPointer<flightDataModel> model;
315 QPointer<pathPlanner> table;
316 QPointer<modelMapProxy> mapProxy;
317 QPointer<QItemSelectionModel> selectionModel;
320 #endif /* OPMAP_GADGETWIDGET_H_ */