diff --git a/opmap/mapwidget/mapwidget.pro b/opmap/mapwidget/mapwidget.pro index 12c7358..1733e14 100644 --- a/opmap/mapwidget/mapwidget.pro +++ b/opmap/mapwidget/mapwidget.pro @@ -66,6 +66,24 @@ FORMS += \ INCLUDEPATH += $$PWD/../../thirdpart/include +#添加mavlink目录 +INCLUDEPATH += $$PWD/../../mavlink \ + $$PWD/../../mavlink/ardupilotmega \ + $$PWD/../../mavlink/common \ + $$PWD/../../mavlink/icarous \ + $$PWD/../../mavlink/uAvionix \ + $$PWD/../../mavlink/XYK \ + $$PWD/../../mavlink/message_definitions + + + + + + + + + + LIBS += -L$$PWD/../../thirdpart/lib -lcore LIBS += -L$$PWD/../../thirdpart/lib -linternals diff --git a/opmap/mapwidget/waypointcircle.cpp b/opmap/mapwidget/waypointcircle.cpp index fbf0a95..60ac7c6 100644 --- a/opmap/mapwidget/waypointcircle.cpp +++ b/opmap/mapwidget/waypointcircle.cpp @@ -105,7 +105,6 @@ void WayPointCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *op dashes << 4 << 8; myPen.setDashPattern(dashes); } - qreal arrowSize = 10; painter->setPen(myPen); QBrush brush = painter->brush(); painter->setBrush(myColor); @@ -114,23 +113,7 @@ void WayPointCircle::paint(QPainter *painter, const QStyleOptionGraphicsItem *op angle += M_PI; } - /* QPointF arrowP1 = p1 + QPointF(sin(angle + M_PI / 3) * arrowSize, - cos(angle + M_PI / 3) * arrowSize); - QPointF arrowP2 = p1 + QPointF(sin(angle + M_PI - M_PI / 3) * arrowSize, - cos(angle + M_PI - M_PI / 3) * arrowSize); - QPointF arrowP21 = p2 + QPointF(sin(angle + M_PI + M_PI / 3) * arrowSize, - cos(angle + M_PI + M_PI / 3) * arrowSize); - QPointF arrowP22 = p2 + QPointF(sin(angle + M_PI + M_PI - M_PI / 3) * arrowSize, - cos(angle + M_PI + M_PI - M_PI / 3) * arrowSize); - - arrowHead.clear(); - arrowHead << p1 << arrowP1 << arrowP2; - painter->drawPolygon(arrowHead); - arrowHead.clear(); - arrowHead << p2 << arrowP21 << arrowP22; - painter->drawPolygon(arrowHead); - */ painter->translate(-line.length(), -line.length()); painter->setBrush(brush); painter->drawEllipse(this->rect()); diff --git a/opmap/mapwidget/waypointitem.cpp b/opmap/mapwidget/waypointitem.cpp index fa210ac..d1a7544 100644 --- a/opmap/mapwidget/waypointitem.cpp +++ b/opmap/mapwidget/waypointitem.cpp @@ -31,18 +31,18 @@ namespace mapcontrol { WayPointItem::WayPointItem(const internals::PointLatLng &coord, int const & altitude, MapGraphicItem *map, wptype type) : coord(coord), reached(false), description(""), shownumber(true), isDragging(false), altitude(altitude), map(map), myType(type) { - text = 0; numberI = 0; isMagic = false; - picture.load(QString::fromUtf8(":/markers/images/marker.png")); number = WayPointItem::snumber; ++WayPointItem::snumber; this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); SetShowNumber(shownumber); - RefreshToolTip(); RefreshPos(); + + SetDefault(coord.Lat(),coord.Lng(),altitude,number); + myHome = NULL; QList list = map->childItems(); foreach(QGraphicsItem * obj, list) { @@ -72,21 +72,21 @@ WayPointItem::WayPointItem(MapGraphicItem *map, bool magicwaypoint) : reached(fa myType = relative; if (magicwaypoint) { isMagic = true; - picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker3.png")); number = -1; } else { isMagic = false; number = WayPointItem::snumber; ++WayPointItem::snumber; } - text = 0; numberI = 0; this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); SetShowNumber(shownumber); - RefreshToolTip(); RefreshPos(); + + SetDefault(coord.Lat(),coord.Lng(),altitude,number); + myHome = NULL; QList list = map->childItems(); foreach(QGraphicsItem * obj, list) { @@ -109,18 +109,19 @@ WayPointItem::WayPointItem(MapGraphicItem *map, bool magicwaypoint) : reached(fa } WayPointItem::WayPointItem(const internals::PointLatLng &coord, int const & altitude, const QString &description, MapGraphicItem *map, wptype type) : coord(coord), reached(false), description(description), shownumber(true), isDragging(false), altitude(altitude), map(map), myType(type) { - text = 0; numberI = 0; isMagic = false; - picture.load(QString::fromUtf8(":/markers/images/marker.png")); + //picture.load(QString::fromUtf8(":/markers/images/marker.png")); number = WayPointItem::snumber; ++WayPointItem::snumber; this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); SetShowNumber(shownumber); - RefreshToolTip(); RefreshPos(); + + SetDefault(coord.Lat(),coord.Lng(),altitude,number); + myHome = NULL; QList list = map->childItems(); foreach(QGraphicsItem * obj, list) { @@ -158,18 +159,18 @@ WayPointItem::WayPointItem(const distBearingAltitude &relativeCoordenate, const SetAltitude(myHome->Altitude() + relativeCoord.altitudeRelative); } myType = relative; - text = 0; numberI = 0; isMagic = false; - picture.load(QString::fromUtf8(":/markers/images/marker.png")); number = WayPointItem::snumber; ++WayPointItem::snumber; this->setFlag(QGraphicsItem::ItemIsMovable, true); this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true); this->setFlag(QGraphicsItem::ItemIsSelectable, true); SetShowNumber(shownumber); - RefreshToolTip(); RefreshPos(); + + SetDefault(coord.Lat(),coord.Lng(),altitude,number); + connect(this, SIGNAL(waypointdoubleclick(WayPointItem *)), map, SIGNAL(wpdoubleclicked(WayPointItem *))); emit manualCoordChange(this); connect(map, SIGNAL(childRefreshPosition()), this, SLOT(RefreshPos())); @@ -181,11 +182,11 @@ void WayPointItem::setWPType(wptype type) myType = type; emit WPValuesChanged(this); RefreshPos(); - RefreshToolTip(); + this->update(); } -QRectF WayPointItem::boundingRect() const +QRectF WayPointItem::boundingRect() const //鼠标可以操作的大小 { return QRectF(-10,-10,20,20); } @@ -193,13 +194,15 @@ void WayPointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti { Q_UNUSED(option); Q_UNUSED(widget); - //painter->drawPixmap(-picture.width() / 2, -picture.height(), picture); + painter->setPen(Qt::green); painter->drawRect(-6,-6,12,12); painter->drawLine(-6,-6,6,6); painter->drawLine(-6,6,6,-6); + + if (this->isSelected()) { painter->setPen(Qt::red); painter->drawRect(QRectF(-10,-10,20,20)); @@ -208,6 +211,7 @@ void WayPointItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti void WayPointItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { + qInfo() << "DoubleClickEvent"; emit waypointdoubleclick(this); } } @@ -215,16 +219,7 @@ void WayPointItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) void WayPointItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - text = new QGraphicsSimpleTextItem(this); - textBG = new QGraphicsRectItem(this); - - textBG->setBrush(Qt::white); - - text->setPen(QPen(Qt::black)); - text->setPos(10, -picture.height()); - textBG->setPos(10, -picture.height()); - text->setZValue(3); - RefreshToolTip(); + qInfo() << "PressEvent"; isDragging = true; } QGraphicsItem::mousePressEvent(event); @@ -232,44 +227,34 @@ void WayPointItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void WayPointItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { if (event->button() == Qt::LeftButton) { - if (text) { - delete text; - text = NULL; - } - if (textBG) { - delete textBG; - textBG = NULL; - } - + qInfo() << "ReleaseEvent"; isDragging = false; - RefreshToolTip(); - - emit manualCoordChange(this); emit localPositionChanged(this->pos(), this); emit WPValuesChanged(this); coord = map->FromLocalToLatLng(this->pos().x(), this->pos().y()); + + SetLat(coord.Lat()); + SetLng(coord.Lng()); + emit WPChanged(this->Number(),Coord().Lat(),Coord().Lng()); } QGraphicsItem::mouseReleaseEvent(event); } void WayPointItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + if (isDragging) { - coord = map->FromLocalToLatLng(this->pos().x(), this->pos().y()); - QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6); - if (myHome) { - map->Projection()->offSetFromLatLngs(myHome->Coord(), coord, relativeCoord.distance, relativeCoord.bearing); - } - QString relativeCoord_str =QString::number(relativeCoord.distance) + "m " + QString::number(relativeCoord.bearing * 180 / M_PI) + "deg"; - text->setText(coord_str + "\n" + relativeCoord_str); - textBG->setRect(text->boundingRect()); emit localPositionChanged(this->pos(), this); emit WPValuesChanged(this); } QGraphicsItem::mouseMoveEvent(event); } + + + + void WayPointItem::SetAltitude(const float &value) { if (altitude == value) { @@ -279,7 +264,6 @@ void WayPointItem::SetAltitude(const float &value) if (myHome) { relativeCoord.altitudeRelative = altitude - myHome->Altitude(); } - RefreshToolTip(); emit WPValuesChanged(this); this->update(); } @@ -296,7 +280,6 @@ void WayPointItem::setRelativeCoord(distBearingAltitude value) SetAltitude(myHome->Altitude() + relativeCoord.altitudeRelative); } RefreshPos(); - RefreshToolTip(); emit WPValuesChanged(this); this->update(); } @@ -316,7 +299,6 @@ void WayPointItem::SetCoord(const internals::PointLatLng &value) } emit WPValuesChanged(this); RefreshPos(); - RefreshToolTip(); this->update(); } void WayPointItem::SetDescription(const QString &value) @@ -325,7 +307,6 @@ void WayPointItem::SetDescription(const QString &value) return; } description = value; - RefreshToolTip(); emit WPValuesChanged(this); this->update(); } @@ -334,7 +315,6 @@ void WayPointItem::SetNumber(const int &value) int oldnumber = number; number = value; - RefreshToolTip(); numberI->setText(QString::number(numberAdjusted())); this->update(); emit WPNumberChanged(oldnumber, value, this); @@ -344,16 +324,16 @@ void WayPointItem::SetReached(const bool &value) reached = value; emit WPValuesChanged(this); if (value) { - picture.load(QString::fromUtf8(":/markers/images/bigMarkerGreen.png")); + //picture.load(QString::fromUtf8(":/markers/images/bigMarkerGreen.png")); } else { if (!isMagic) { if ((this->flags() & QGraphicsItem::ItemIsMovable) == QGraphicsItem::ItemIsMovable) { - picture.load(QString::fromUtf8(":/markers/images/marker.png")); + //picture.load(QString::fromUtf8(":/markers/images/marker.png")); } else { - picture.load(QString::fromUtf8(":/markers/images/waypoint_marker2.png")); + //picture.load(QString::fromUtf8(":/markers/images/waypoint_marker2.png")); } } else { - picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker3.png")); + //picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker3.png")); } } this->update(); @@ -408,7 +388,6 @@ void WayPointItem::onHomePositionChanged(internals::PointLatLng homepos, float h SetAltitude(relativeCoord.altitudeRelative + homeAltitude); emit WPValuesChanged(this); RefreshPos(); - RefreshToolTip(); this->update(); } else { if (myHome) { @@ -455,24 +434,7 @@ void WayPointItem::setOpacitySlot(qreal opacity) { setOpacity(opacity); } -void WayPointItem::RefreshToolTip() -{ - QString type_str; - if (myType == relative) { - type_str = "Relative"; - } else { - type_str = "Absolute"; - } - QString coord_str = " " + QString::number(coord.Lat(), 'f', 6) + " " + QString::number(coord.Lng(), 'f', 6); - QString relativeCoord_str = " Distance:" + QString::number(relativeCoord.distance) + " Bearing:" + QString::number(relativeCoord.bearing * 180 / M_PI); - QString relativeAltitude_str = QString::number(relativeCoord.altitudeRelative); - if (Number() != -1) { - setToolTip(QString("WayPoint Number:%1\nDescription:%2\nCoordinate:%4\nFrom Home:%5\nRelative altitude:%6\nAltitude:%7\nType:%8\n%9").arg(QString::number(numberAdjusted())).arg(description).arg(coord_str).arg(relativeCoord_str).arg(relativeAltitude_str).arg(QString::number(altitude)).arg(type_str).arg(myCustomString)); - } else { - setToolTip(QString("Magic WayPoint\nCoordinate:%1\nFrom Home:%2\nAltitude:%3\nType:%4\n%5").arg(coord_str).arg(relativeCoord_str).arg(QString::number(altitude)).arg(type_str).arg(myCustomString)); - } -} void WayPointItem::setFlag(QGraphicsItem::GraphicsItemFlag flag, bool enabled) { @@ -481,14 +443,82 @@ void WayPointItem::setFlag(QGraphicsItem::GraphicsItemFlag flag, bool enabled) return; } else if (flag == QGraphicsItem::ItemIsMovable) { if (enabled) { - picture.load(QString::fromUtf8(":/markers/images/marker.png")); + //picture.load(QString::fromUtf8(":/markers/images/marker.png")); } else { - picture.load(QString::fromUtf8(":/markers/images/waypoint_marker2.png")); + //picture.load(QString::fromUtf8(":/markers/images/waypoint_marker2.png")); } } QGraphicsItem::setFlag(flag, enabled); } +//=============属性设置================= + +void WayPointItem::SetDefault(double lat,double lng,float alt,uint16_t seq) +{ + property.param1 = 100; + property.param2 = 50; + property.param3 = 50; + property.param4 = 0; + property.x = lat * 10e5; + property.y = lng * 10e5; + property.z = alt; + property.seq = seq; + property.command = MAV_CMD::MAV_CMD_NAV_WAYPOINT; + //... +} + +void WayPointItem::SetParam1(float value) +{ + property.param1 = value; +} + +void WayPointItem::SetParam2(float value) +{ + property.param2 = value; +} + +void WayPointItem::SetParam3(float value) +{ + property.param3 = value; +} + +void WayPointItem::SetParam4(float value) +{ + property.param4 = value; +} + +void WayPointItem::SetLat(double value) +{ + property.x = value * 10e5; +} + +void WayPointItem::SetLng(double value) +{ + property.y = value * 10e5; +} + +void WayPointItem::SetAlt(float value) +{ + property.z = value; +} + +void WayPointItem::SetSeq(uint16_t value) +{ + property.seq = value; +} + +void WayPointItem::SetCommand(uint16_t value) +{ + property.command = value; +} + +void WayPointItem::SetGroup(uint16_t value) +{ + property.group = value; +} + + +//==============全局计数=================== int WayPointItem::snumber = 0; } @@ -497,29 +527,6 @@ int WayPointItem::snumber = 0; -/* - - float param1; - float param2; - float param3; - float param4; - int32_t x; PARAM5 / local: x position in meters * 1e4, global: latitude in degrees * 10^7* - int32_t y; PARAM6 / y position: local: x position in meters * 1e4, global: longitude in degrees *10^7 - float z; PARAM7 / z position: global: altitude in meters (relative or absolute, depending on frame. - uint16_t seq; Waypoint ID (sequence number). Starts at zero. Increases monotonically for each waypoint, no gaps in the sequence (0,1,2,3,4) - uint16_t command; /*< The scheduled action for the waypoint. - uint8_t target_system; /*< System ID* - uint8_t target_component; /*< Component ID* - uint8_t frame; /*< The coordinate system of the waypoint. - uint8_t current; /*< false:0, true:1 - uint8_t autocontinue; /*< Autocontinue to next waypoint - uint8_t mission_type; /*< Mission type. - -*/ - - - - diff --git a/opmap/mapwidget/waypointitem.h b/opmap/mapwidget/waypointitem.h index 7968eac..ad94fba 100644 --- a/opmap/mapwidget/waypointitem.h +++ b/opmap/mapwidget/waypointitem.h @@ -35,6 +35,9 @@ #include #include +#include "mavlink.h" + + namespace mapcontrol { struct distBearingAltitude { double distance; @@ -99,62 +102,23 @@ public: _property property; - /** - * @brief Constructer - * - * @param coord coordinates in LatLng of the Waypoint - * @param altitude altitude of the WayPoint - * @param map pointer to map to use - * @return - */ WayPointItem(internals::PointLatLng const & coord, int const & altitude, MapGraphicItem *map, wptype type = absolute); WayPointItem(MapGraphicItem *map, bool magicwaypoint); - /** - * @brief Constructer - * - * @param coord coordinates in LatLng of the WayPoint - * @param altitude altitude of the WayPoint - * @param description description fo the WayPoint - * @param map pointer to map to use - * @return - */ 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); - /** - * @brief Returns the WayPoint description - * - * @return QString - */ QString Description() { return description; } - /** - * @brief Sets the WayPoint description - * - * @param value - */ void SetDescription(QString const & value); - /** - * @brief Returns true if WayPoint is Reached - * - * @return bool - */ + bool Reached() { return reached; } - /** - * @brief Sets if WayPoint is Reached - * - * @param value - */ void SetReached(bool const & value); - /** - * @brief Returns the WayPoint number - * - */ + int Number() { return number; @@ -163,54 +127,27 @@ public: { return number + 1; } - /** - * @brief Sets WayPoint number - * - * @param value - */ void SetNumber(int const & value); - /** - * @brief Returns WayPoint LatLng coordinate - * - */ + internals::PointLatLng Coord() { return coord; } - /** - * @brief Sets WayPoint LatLng coordinate - * - * @param value - */ + void SetCoord(internals::PointLatLng const & value); - /** - * @brief Used if WayPoint number is to be drawn on screen - * - */ + bool ShowNumber() { return shownumber; } - /** - * @brief Used to set if WayPoint number is to be drawn on screen - * - * @param value - */ + void SetShowNumber(bool const & value); - /** - * @brief Returns the WayPoint altitude - * - * @return int - */ + float Altitude() { return altitude; } - /** - * @brief Sets the WayPoint Altitude - * - * @param value - */ + void SetAltitude(const float &value); void setRelativeCoord(distBearingAltitude value); distBearingAltitude getRelativeCoord() @@ -221,7 +158,6 @@ public: QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - void RefreshToolTip(); QPixmap picture; QString customString() { @@ -240,24 +176,94 @@ public: { 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; + } + + uint16_t Group(void) + { + return property.group; + } + + + + + + + + protected: void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); private: + + bool isEdit = false; + internals::PointLatLng coord; // coordinates of this WayPoint - typedef struct { - float altitude;//相对海拔 - float velocity;//当前点速度 - float radiu;//半径 - qint8 action;//动作 - }_waypoint; - - - - distBearingAltitude relativeCoord; bool reached; QString description; @@ -268,8 +274,6 @@ private: int number; bool isMagic; - QGraphicsSimpleTextItem *text; - QGraphicsRectItem *textBG; QGraphicsSimpleTextItem *numberI; QTransform transf; HomeItem *myHome; @@ -277,56 +281,17 @@ private: QString myCustomString; public slots: - /** - * @brief Called when a WayPoint is deleted - * - * @param number number of the WayPoint that was deleted - */ - void WPDeleted(int const & number, WayPointItem *waypoint); - /** - * @brief Called when a WayPoint is renumbered - * - * @param oldnumber the old WayPoint number - * @param newnumber the new WayPoint number - * @param waypoint a pointer to the WayPoint renumbered - */ - void WPRenumbered(int const & oldnumber, int const & newnumber, WayPointItem *waypoint); - /** - * @brief Called when a WayPoint is inserted - * - * @param number the number of the WayPoint - * @param waypoint a pointer to the WayPoint inserted - */ - void WPInserted(int const & number, WayPointItem *waypoint); + 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); signals: - /** - * - * @brief fires when this WayPoint Value changes - * - */ void WPChanged(int Number,double Lat,double Lng); - - - /** - * @brief fires when this WayPoint number changes (not fired if due to a auto-renumbering) - * - * @param oldnumber this WayPoint old number - * @param newnumber this WayPoint new number - * @param waypoint a pointer to this WayPoint - */ void WPNumberChanged(int const & oldnumber, int const & newnumber, WayPointItem *waypoint); - - /** - * @brief Fired when the description, altitude or coordinates change - * - * @param waypoint a pointer to this WayPoint - */ - void WPValuesChanged(WayPointItem *waypoint); void waypointdoubleclick(WayPointItem *waypoint); void localPositionChanged(QPointF point, WayPointItem *waypoint); diff --git a/opmap/opmap.pro b/opmap/opmap.pro index b7efc0b..19edab3 100644 --- a/opmap/opmap.pro +++ b/opmap/opmap.pro @@ -9,6 +9,12 @@ TEMPLATE = subdirs CONFIG += ordered + + + + + + SUBDIRS += internals SUBDIRS += core SUBDIRS += mapwidget