/** ****************************************************************************** * * @file waypointitem.h * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012. * @brief A graphicsItem representing a WayPoint * @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 WAYPOINTITEM_H #define WAYPOINTITEM_H #include #include #include #include "pointlatlng.h" #include "mapgraphicitem.h" #include #include #include "QDebug" #include "mavlink.h" //#include "propertyui.h" namespace mapcontrol { struct distBearingAltitude { double distance; double bearing; float altitudeRelative; double bearingToDegrees() { return bearing * 180 / M_PI; } void setBearingFromDegrees(double degrees) { bearing = degrees * M_PI / 180; } }; #ifdef QtopmapWidget #include class OPMAPWIDGETSHARED_EXPORT HomeItem; #else class HomeItem; #endif /** * @brief A QGraphicsItem representing a WayPoint * * @class WayPointItem waypointitem.h "waypointitem.h" */ #ifdef QtopmapWidget #include class OPMAPWIDGETSHARED_EXPORT WayPointItem : public QObject, public QGraphicsItem { #else class WayPointItem : public QObject, public QGraphicsItem { #endif Q_OBJECT Q_INTERFACES(QGraphicsItem) public: enum { Type = UserType + 1 }; enum wptype { absolute, relative }; typedef struct{ 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; }_property; WayPointItem(internals::PointLatLng const & coord, int const & altitude, MapGraphicItem *map, wptype type = absolute); WayPointItem(MapGraphicItem *map, bool magicwaypoint); WayPointItem(internals::PointLatLng const & coord, int const & altitude, QString const & description, MapGraphicItem *map, wptype type = absolute); WayPointItem(distBearingAltitude const & relativeCoord, QString const & description, MapGraphicItem *map); QString Description() { return description; } void SetDescription(QString const & value); bool Reached() { return reached; } void SetReached(bool const & value); int Number() { return property.seq; } int numberAdjusted() { return property.seq + 1; } void SetNumber(int const & value); internals::PointLatLng Coord() { return coord; } void SetCoord(internals::PointLatLng const & value); bool ShowNumber() { return shownumber; } void SetShowNumber(bool const & value); float Altitude() { return altitude; } void SetAltitude(const float &value); void setRelativeCoord(distBearingAltitude value); distBearingAltitude getRelativeCoord() { return relativeCoord; } int type() const; QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); QPixmap picture; QString customString() { return myCustomString; } void setCustomString(QString arg) { myCustomString = arg; } void setFlag(GraphicsItemFlag flag, bool enabled); ~WayPointItem(); static int snumber; void setWPType(wptype type); wptype WPType() { return myType; } //=============属性================= void SetDefault(double lat, double lng, float alt, uint16_t seq);//默认属性 void SetParam1(float value); void SetParam2(float value); void SetParam3(float value); void SetParam4(float value); void SetLat(double value); void SetLng(double value); void SetAlt(float value); void SetSeq(uint16_t value); void SetCommand(uint16_t value); void SetGroup(uint16_t value); float Param1(void) { return property.param1; } float Param2(void) { return property.param2; } float Param3(void) { return property.param3; } float Param4(void) { return property.param4; } int32_t Lat(void) { return property.x; } int32_t Lng(void) { return property.y; } float Alt(void) { return property.z; } uint16_t Seq(void) { return property.seq; } uint16_t Command(void) { return property.command; } uint8_t Frame(void) { return property.frame; } uint8_t AutoContinue(void) { return property.autocontinue; } uint16_t Group(void) { return property.group; } bool FollowPrevious(void) { return isFollowPrevious; } double getElevation(void) { return Elevation; } protected: void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); private: _property property; bool isSimple = false; bool isEdit = false; bool isFollowPrevious = false; bool isCurrent = false; internals::PointLatLng coord; // coordinates of this WayPoint distBearingAltitude relativeCoord; bool reached; QString description; bool shownumber; bool isDragging; float altitude; MapGraphicItem *map; int number; bool isMagic; QGraphicsSimpleTextItem *numberI; QTransform transf; HomeItem *myHome; wptype myType; QString myCustomString; double Elevation = 0; bool isElevationRequest = false; bool isElevationLock = false; public slots: //这个地方还需要好好思考 void WPSetEdit(bool value) { this->setFlag(QGraphicsItem::ItemIsMovable, value); isEdit = value; } void WPSetCurrent(bool value) { if(isEdit == false) { if(isCurrent != value) { isCurrent = value; update(); } } //update(); } void setPosition(QPointF p); void WPDeleted(int const & number, WayPointItem *waypoint); void WPRenumbered(int const & oldnumber, int const & newnumber, WayPointItem *waypoint); void WPInserted(int const & number, WayPointItem *waypoint); void onHomePositionChanged(internals::PointLatLng, float altitude); void RefreshPos(); void setOpacitySlot(qreal opacity); void emitWPProperty(void); 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 ElevationTrig(void); void ElevationUpdate(QNetworkReply *reply); signals: void SetCurrent(int seq); void WPFollowPrevious(bool flag,WayPointItem *waypoint); 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 WPChanged(int Number,double Lat,double Lng); void WPNumberChanged(int const & oldnumber, int const & newnumber, WayPointItem *waypoint); void WPValuesChanged(WayPointItem *waypoint); void waypointdoubleclick(WayPointItem *waypoint); void localPositionChanged(QPointF point, WayPointItem *waypoint); void manualCoordChange(WayPointItem *); void aboutToBeDeleted(WayPointItem *); void ElevationChanged(int seq,double value); void AltitudeChanged(int seq,double value); void setCurrentPoint(int value); friend class propertyui; }; } #endif // WAYPOINTITEM_H