/** ****************************************************************************** * * @file opmapwidget.h * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief The Map Widget, this is the part exposed to the user * @see The GNU Public License (GPL) Version 3 * @defgroup OPMapWidget * @{ * *****************************************************************************/ /* * This program is free software; you can redistribute it and/or modify * 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. * * This program is distributed in the hope that it will be useful, 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 along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef OPMAPWIDGET_H #define OPMAPWIDGET_H #include "mapgraphicitem.h" #include "geodecoderstatus.h" #include "maptype.h" #include "languagetype.h" #include "diagnostics.h" #include "configuration.h" #include #include #include "waypointitem.h" #include "QtSvg/QGraphicsSvgItem" #include "QGraphicsView" #include "uavitem.h" #include "gpsitem.h" #include "homeitem.h" #include "mapripper.h" #include "waypointline.h" #include "waypointcircle.h" #include "waypointitem.h" #include "AltitudeItem.h" #include "VirtualMargin.h" #include "VirtualMarginLine.h" #include #include "QTextStream" #include #include "QDir" #include "QFileDialog" namespace mapcontrol { #ifdef QtopmapWidget #include class OPMAPWIDGETSHARED_EXPORT UAVItem; class OPMAPWIDGETSHARED_EXPORT GPSItem; class OPMAPWIDGETSHARED_EXPORT HomeItem; #else class UAVItem; class GPSItem; class HomeItem; #endif /** * @brief Collection of static functions to help dealing with various enums used * Contains functions for enumToString conversio, StringToEnum, QStringList of enum values... * * @class Helper opmapwidget.h "opmapwidget.h" */ #ifdef QtopmapWidget #include class OPMAPWIDGETSHARED_EXPORT Helper { #else class Helper { #endif public: static MapType::Types MapTypeFromString(QString const & value) { return MapType::TypeByStr(value); } static QString StrFromMapType(MapType::Types const & value) { return MapType::StrByType(value); } static QStringList MapTypes() { return MapType::TypesList(); } static GeoCoderStatusCode::Types GeoCoderStatusCodeFromString(QString const & value) { return GeoCoderStatusCode::TypeByStr(value); } static QString StrFromGeoCoderStatusCode(GeoCoderStatusCode::Types const & value) { return GeoCoderStatusCode::StrByType(value); } static QStringList GeoCoderTypes() { return GeoCoderStatusCode::TypesList(); } static internals::MouseWheelZoomType::Types MouseWheelZoomTypeFromString(QString const & value) { return internals::MouseWheelZoomType::TypeByStr(value); } static QString StrFromMouseWheelZoomType(internals::MouseWheelZoomType::Types const & value) { return internals::MouseWheelZoomType::StrByType(value); } static QStringList MouseWheelZoomTypes() { return internals::MouseWheelZoomType::TypesList(); } static core::LanguageType::Types LanguageTypeFromString(QString const & value) { return core::LanguageType::TypeByStr(value); } static QString StrFromLanguageType(core::LanguageType::Types const & value) { return core::LanguageType::StrByType(value); } static QStringList LanguageTypes() { return core::LanguageType::TypesList(); } static core::AccessMode::Types AccessModeFromString(QString const & value) { return core::AccessMode::TypeByStr(value); } static QString StrFromAccessMode(core::AccessMode::Types const & value) { return core::AccessMode::StrByType(value); } static QStringList AccessModeTypes() { return core::AccessMode::TypesList(); } static UAVMapFollowType::Types UAVMapFollowFromString(QString const & value) { return UAVMapFollowType::TypeByStr(value); } static QString StrFromUAVMapFollow(UAVMapFollowType::Types const & value) { return UAVMapFollowType::StrByType(value); } static QStringList UAVMapFollowTypes() { return UAVMapFollowType::TypesList(); } static UAVTrailType::Types UAVTrailTypeFromString(QString const & value) { return UAVTrailType::TypeByStr(value); } static QString StrFromUAVTrailType(UAVTrailType::Types const & value) { return UAVTrailType::StrByType(value); } static QStringList UAVTrailTypes() { return UAVTrailType::TypesList(); } }; #ifdef QtopmapWidget #include class OPMAPWIDGETSHARED_EXPORT OPMapWidget : public QGraphicsView { #else class OPMapWidget : public QGraphicsView { #endif Q_OBJECT // Q_PROPERTY(int MaxZoom READ MaxZoom WRITE SetMaxZoom) Q_PROPERTY(int MinZoom READ MinZoom WRITE SetMinZoom) Q_PROPERTY(bool ShowTileGridLines READ ShowTileGridLines WRITE SetShowTileGridLines) Q_PROPERTY(double Zoom READ ZoomTotal WRITE SetZoom) Q_PROPERTY(qreal Rotate READ Rotate WRITE SetRotate) Q_ENUMS(internals::MouseWheelZoomType::Types) Q_ENUMS(core::GeoCoderStatusCode::Types) public: QSize sizeHint() const; /** * @brief Constructor * * @param parent parent widget * @param config pointer to configuration classed to be used * @return */ OPMapWidget(QWidget *parent = 0, Configuration *config = new Configuration); ~OPMapWidget(); bool ShowTileGridLines() const { return map->showTileGridLines; } void SetShowTileGridLines(bool const & value) { map->showTileGridLines = value; map->update(); } int MaxZoom() const { return map->MaxZoom(); } // void SetMaxZoom(int const& value){map->maxZoom = value;} int MinZoom() const { return map->minZoom; } void SetMinZoom(int const & value) { map->minZoom = value; } internals::MouseWheelZoomType::Types GetMouseWheelZoomType() { return map->core->GetMouseWheelZoomType(); } void SetMouseWheelZoomType(internals::MouseWheelZoomType::Types const & value) { map->core->SetMouseWheelZoomType(value); } // void SetMouseWheelZoomTypeByStr(const QString &value){map->core->SetMouseWheelZoomType(internals::MouseWheelZoomType::TypeByStr(value));} // QString GetMouseWheelZoomTypeStr(){return map->GetMouseWheelZoomTypeStr();} internals::RectLatLng SelectedArea() const { return map->selectedArea; } void SetSelectedArea(internals::RectLatLng const & value) { map->selectedArea = value; this->update(); } bool CanDragMap() const { return map->CanDragMap(); } void SetCanDragMap(bool const & value) { map->SetCanDragMap(value); } internals::PointLatLng CurrentPosition() const { return map->core->CurrentPosition(); } void SetCurrentPosition(); void SetCurrentPosition(internals::PointLatLng const & value); double ZoomReal() { return map->Zoom(); } double ZoomDigi() { return map->ZoomDigi(); } double ZoomTotal() { return map->ZoomTotal(); } void SetZoom(double const & value) { map->SetZoom(value); } qreal Rotate() { return map->rotation; } void SetRotate(qreal const & value); void ReloadMap() { map->ReloadMap(); map->resize(); } GeoCoderStatusCode::Types SetCurrentPositionByKeywords(QString const & keys) { return map->SetCurrentPositionByKeywords(keys); } bool UseOpenGL() { return useOpenGL; } void SetUseOpenGL(bool const & value); MapType::Types GetMapType() { return map->core->GetMapType(); } void SetMapType(MapType::Types const & value) { map->lastimage = QImage(); map->core->SetMapType(value); } bool isStarted() { return map->core->isStarted(); } int getUAVCurrent(void); Configuration *configuration; internals::PointLatLng currentMousePosition(); void SetFollowMouse(bool const & value) { followmouse = value; this->setMouseTracking(followmouse); } bool FollowMouse() { return followmouse; } internals::PointLatLng GetFromLocalToLatLng(QPointF p) { return map->FromLocalToLatLng(p.x(), p.y()); } WayPointItem *WPCreate(); void WPCreate(WayPointItem *item); WayPointItem *WPCreate(internals::PointLatLng const & coord, int const & altitude); WayPointItem *WPCreate(internals::PointLatLng const & coord, int const & altitude, QString const & description); WayPointItem *WPCreate(const distBearingAltitude &relativeCoord, const QString &description); void WPRenumber(WayPointItem *item, int const & newnumber); void SetShowCompass(bool const & value); void setOverlayOpacity(qreal value); UAVItem *UAV; GPSItem *GPS; HomeItem *Home; AltitudeItem *altitudeitem; void SetShowUAV(bool const & value); bool ShowUAV() const { return showuav; } void SetShowHome(bool const & value); bool ShowHome() const { return showhome; } void SetShowDiagnostics(bool const & value); void SetUavPic(QString UAVPic); WayPointLine *WPLineCreate(WayPointItem *from, WayPointItem *to, QColor color, bool dashed = false, int width = -1); WayPointLine *WPLineCreate(HomeItem *from, WayPointItem *to, QColor color, bool dashed = false, int width = -1); WayPointCircle *WPCircleCreate(WayPointItem *center, double radius, bool clockwise, QColor color, bool dashed = false, int width = -1); WayPointCircle *WPCircleCreate(HomeItem *center, double radius, bool clockwise, QColor color, bool dashed = false, int width = -1); void deleteAllOverlays(); void WPSetVisibleAll(bool value); WayPointItem *magicWPCreate(); bool WPPresent(); WayPointItem *WPFind(int number); QList WPSelected(); void setSelectedWP(QList list); void setSelectedWP(int number); void setSelectedWP(WayPointItem *item); bool WPLock() const { return isWPLock; } void setWPLock(bool const & lock); bool WPCreate() const { return isWPCreate; } void setWPCreate(bool const & value); void setUAVPos(int sysid,int compid,double x,double y,double z); void setUAVHeading(int sysid,int compid,float Heading); void DeleteTrail(void); double TotalDistance(void) { return totalDistance; } private: internals::Core *core; MapGraphicItem *map; QGraphicsScene mscene; bool useOpenGL; GeoCoderStatusCode x; MapType y; core::AccessMode xx; internals::PointLatLng currentmouseposition; bool followmouse; void ConnectWP(WayPointItem *item); QGraphicsSvgItem *compass; bool showuav; bool showhome; QTimer *diagTimer; QGraphicsTextItem *diagGraphItem; bool showDiag; qreal overlayOpacity; bool isWPCreate; bool isWPLock; bool isLNOP = false; QString waypointMessage; double totalDistance = 0; QTimer *NoOperationTimer = nullptr; QMap> VirtualMarginPoints;//type index point QMap> VirtualMarginlinemapLines;//type index line QMap virtualmarginmap_red; QMap virtualmarginlinemap_red; QMap virtualmarginmap_orange; QMap virtualmarginlinemap_orange; QColor WarningColor = QColor("#F64034"); QColor NoticeColor = QColor("#F1B243"); QColor Drop1Color = QColor("#0000FF"); QColor Drop2Color = QColor("#0000FF"); private slots: void diagRefresh(); // WayPointItem* item;//apagar void NOPTimeout(); protected: void resizeEvent(QResizeEvent *event); void showEvent(QShowEvent *event); void closeEvent(QCloseEvent *event); void mouseMoveEvent(QMouseEvent *event); void mouseDoubleClickEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); // private slots: signals: void showMessage(const QString &message,int TimeOut = 0); //map property void MapTypes(QStringList list); void TotalDistanceUpdate(double); void WPNeedToUpdata(int number); void WPChanged(int Number,double Lat,double Lng); void EmitCurrentMousePosition(internals::PointLatLng); void zoomChanged(double zoomt, double zoom, double zoomd); void WPNumberChanged(int const & oldnumber, int const & newnumber, WayPointItem *waypoint); void WPValuesChanged(WayPointItem *waypoint); void WPReached(WayPointItem *waypoint); void WPCreated(int const & number, WayPointItem *waypoint); void WPInserted(int const & number, WayPointItem *waypoint); void WPDeleted(int const & number, WayPointItem *waypoint); void WPLocalPositionChanged(QPointF, WayPointItem *); void WPManualCoordChange(WayPointItem *); void UAVReachedWayPoint(int const & waypointnumber, WayPointItem *waypoint); void UAVLeftSafetyBouble(internals::PointLatLng const & position); void OnCurrentPositionChanged(internals::PointLatLng point); void OnTileLoadComplete(); void OnTileLoadStart(); void OnMapDrag(); void OnMapZoomChanged(); void OnMapTypeChanged(MapType::Types type); void OnEmptyTileError(int zoom, core::Point pos); void OnTilesStillToLoad(int number); void OnWayPointDoubleClicked(WayPointItem *waypoint); void selectedWPChanged(QList); void MousePressEvent(QMouseEvent *event); void MouseReleaseEvent(QMouseEvent *event); void MouseDoubleClickEvent(QMouseEvent *event); void PointNumber(QList nums); void setWPProperty(float param1,float param2,float param3,float param4, int32_t x,int32_t y,float z, uint16_t seq, uint16_t group, uint16_t command, uint8_t target_system, uint8_t target_component, uint8_t frame, uint8_t current, uint8_t autocontinue, uint8_t mission_type); void WPProperty(float param1,float param2,float param3,float param4, int32_t x,int32_t y,float z, uint16_t seq, uint16_t group, uint16_t command, uint8_t target_system, uint8_t target_component, uint8_t frame, uint8_t current, uint8_t autocontinue, uint8_t mission_type); void allPoint(QMap list); void signal_WPDownload(uint8_t m_sysid, uint8_t m_compid); void signal_WPUpload(uint8_t m_sysid, uint8_t m_compid, uint32_t count); void transmitPoint(float param1,float param2,float param3,float param4, int32_t x,int32_t y,float z, uint16_t seq, uint16_t group, uint16_t command, uint8_t target_system, uint8_t target_component, uint8_t frame, uint8_t current, uint8_t autocontinue, uint8_t mission_type); void uav_selected(int sys,int comp); void setCurrent(int seq); public slots: void report(QString path); void find_PointNumber(); void updateMessage(void); void addUAV(int sysid, int compid); void getMapTypes(void); void setMapTypes(QVariant value); void AddVirtualMargin(int type, int index, double lat, double lng, double alt, QColor color); void CloseVirtualMargin(int type); void RemoveVirtualMargin(int type); void FlushVirtualMargin(int type); void ElevationChanged(int seq,double value); void AltitudeChanged(int seq,double value); void setCurrentPoint(int value); void receivedPoint(float param1,float param2,float param3,float param4, int32_t x,int32_t y,float z, uint16_t seq, uint16_t group, uint16_t command, uint8_t target_system, uint8_t target_component, uint8_t frame, uint8_t current, uint8_t autocontinue, uint8_t mission_type); void WPLineDelete(WayPointItem *from, WayPointItem *to); WayPointLine *WPLineFind(WayPointItem *from, WayPointItem *to); void WPDelete(WayPointItem *item); void WPDelete(int number); void WPDeleteAll(); void WPInsert(int const & position); void WPInsert(WayPointItem *item, int const & position); WayPointItem *WPInsert(internals::PointLatLng const & coord, int const & altitude, int const & position); WayPointItem *WPInsert(internals::PointLatLng const & coord, int const & altitude, QString const & description, int const & position); WayPointItem *WPInsert(const distBearingAltitude &relative, const QString &description, const int &position); void WPLocalChanged(QPointF p, WayPointItem *w); void WPFollowPrevious(bool flag,WayPointItem *waypoint); void WPSetCurrent(int seq); void WPLoad(QString path); void WPSave(QString path); void WPDownload(void); void WPUpload(void); void WPotherPoint(int number); void WPsearchall(void); void WPSendItemOK(uint16_t seq,bool flag); void RipMap(); void OnSelectionChanged(); }; } #endif // OPMAPWIDGET_H