diff --git a/ground/src/plugins/opmap/images/center_wp.png b/ground/src/plugins/opmap/images/center_wp.png new file mode 100644 index 000000000..6fb38866f Binary files /dev/null and b/ground/src/plugins/opmap/images/center_wp.png differ diff --git a/ground/src/plugins/opmap/images/home_wp.png b/ground/src/plugins/opmap/images/home_wp.png new file mode 100644 index 000000000..b6ad7d2b1 Binary files /dev/null and b/ground/src/plugins/opmap/images/home_wp.png differ diff --git a/ground/src/plugins/opmap/opmap.qrc b/ground/src/plugins/opmap/opmap.qrc index 8b2185656..bba4e5405 100644 --- a/ground/src/plugins/opmap/opmap.qrc +++ b/ground/src/plugins/opmap/opmap.qrc @@ -22,5 +22,7 @@ images/minus.png images/plus.png images/waypoint_marker3.png + images/center_wp.png + images/home_wp.png diff --git a/ground/src/plugins/opmap/opmap_widget.ui b/ground/src/plugins/opmap/opmap_widget.ui index 5221122a5..08fe2a479 100644 --- a/ground/src/plugins/opmap/opmap_widget.ui +++ b/ground/src/plugins/opmap/opmap_widget.ui @@ -82,6 +82,23 @@ color: rgb(255, 255, 255); border-radius: 0px; /*border-radius: 3px;*/ } +QToolButton:disabled { +background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(128, 128, 128, 128), stop:1 rgba(128, 128, 128, 128)); +color: rgba(255, 255, 255, 128); + +/*height: 24px;*/ + +border: none; +border-radius: 0px; +/* +border: 1px solid rgb(255, 255, 255); +border-radius: 0px; +border-top-color: rgba(0, 0, 0, 64); +border-right-color: rgba(0, 0, 0, 64); +border-bottom-color: rgba(255, 255, 255, 64); +border-left-color: rgba(255, 255, 255, 64); +*/ +} QToolButton:hover { background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(255, 255, 255,128), stop:1 rgba(180, 180, 180, 128)); color: rgb(255, 255, 255); @@ -128,6 +145,62 @@ border-left-color: rgba(255, 255, 255, 64); */ } +QPushButton { +background-color: transparent; +color: rgb(255, 255, 255); + +/*height: 24px;*/ + +/*border-style: none;*/ +/* border: 1px solid rgba(0, 0, 0, 64); */ +/* border: 0px; */ +border-radius: 0px; +/*border-radius: 3px;*/ +} +QPushButton:disabled { +background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(128, 128, 128, 128), stop:1 rgba(128, 128, 128, 128)); +color: rgb(255, 255, 255); + +/*height: 24px;*/ + +border: none; +border-radius: 0px; +/* +border: 1px solid rgb(255, 255, 255); +border-radius: 0px; +border-top-color: rgba(0, 0, 0, 64); +border-right-color: rgba(0, 0, 0, 64); +border-bottom-color: rgba(255, 255, 255, 64); +border-left-color: rgba(255, 255, 255, 64); +*/ +} +QPushButton:hover { +background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(255, 255, 255,128), stop:1 rgba(180, 180, 180, 128)); +color: rgb(255, 255, 255); + +/*height: 24px;*/ + +border: 0px; +border-radius: 0px; +/*border-radius: 3px;*/ +} +QPushButton:pressed { +background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(48, 48, 48, 255), stop:1 rgba(64, 64, 64, 255)); +color: rgb(255, 255, 255); + +/*height: 24px;*/ + +border: none; +border-radius: 0px; +/* +border: 1px solid rgb(255, 255, 255); +border-radius: 0px; +border-top-color: rgba(0, 0, 0, 64); +border-right-color: rgba(0, 0, 0, 64); +border-bottom-color: rgba(255, 255, 255, 64); +border-left-color: rgba(255, 255, 255, 64); +*/ +} QComboBox { background-color: qlineargradient(spread:pad, x1:0.5, y1:0, x2:0.5, y2:1, stop:0 rgba(48, 48, 48, 255), stop:1 rgba(120, 120, 120, 255)); @@ -199,9 +272,12 @@ border-radius: 2px; - 9 + 8 + + Normal Map Mode + Normal @@ -251,6 +327,9 @@ border-radius: 2px; 8 + + Magic Waypoint Map Mode + Magic Waypoint @@ -291,6 +370,68 @@ border-radius: 2px; + + + + QFrame::Plain + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + Move the magic waypoint to the home position + + + Home WP + + + + :/opmap/images/home_wp.png:/opmap/images/home_wp.png + + + + 28 + 28 + + + + + + + + + 0 + 0 + + + + Move the magic waypoint to center of map + + + Center WP + + + + :/opmap/images/center_wp.png:/opmap/images/center_wp.png + + + + 28 + 28 + + + + @@ -312,9 +453,6 @@ border-radius: 2px; Center map over home position - - - Home @@ -350,9 +488,6 @@ border-radius: 2px; Center map over UAV position - - - UAV @@ -391,9 +526,6 @@ border-radius: 2px; Map rotation follows UAV heading - - - Heading @@ -432,9 +564,6 @@ border-radius: 2px; Show/Hide the UAV trail - - - Trail diff --git a/ground/src/plugins/opmap/opmapgadgetwidget.cpp b/ground/src/plugins/opmap/opmapgadgetwidget.cpp index 4d2d56dc1..850de57c3 100644 --- a/ground/src/plugins/opmap/opmapgadgetwidget.cpp +++ b/ground/src/plugins/opmap/opmapgadgetwidget.cpp @@ -68,21 +68,34 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent) m_map_mode = Normal_MapMode; - // default magic waypoint params - magic_waypoint.map_wp_item = NULL; - magic_waypoint.coord = internals::PointLatLng(0.0, 0.0); - magic_waypoint.altitude = 0.0; - magic_waypoint.description = "Magic waypoint"; - magic_waypoint.locked = false; - magic_waypoint.time_seconds = 0; - magic_waypoint.hold_time_seconds = 0; - // ************** // fetch required UAVObjects m_plugin_manager = ExtensionSystem::PluginManager::instance(); m_objManager = m_plugin_manager->getObject(); + // current position + QPointF pos = getLatLon(); + internals::PointLatLng pos_lat_lon = internals::PointLatLng(pos.x(), pos.y()); + + // ************** + // default home position + + home_position.coord = pos_lat_lon; + home_position.altitude = 0.0; + home_position.locked = false; + + // ************** + // default magic waypoint params + + magic_waypoint.map_wp_item = NULL; + magic_waypoint.coord = home_position.coord; + magic_waypoint.altitude = 0.0; + magic_waypoint.description = "Magic waypoint"; + magic_waypoint.locked = false; + magic_waypoint.time_seconds = 0; + magic_waypoint.hold_time_seconds = 0; + // ************** // create the widget that holds the user controls and the map @@ -163,17 +176,20 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent) case Normal_MapMode: m_widget->toolButtonMagicWaypointMapMode->setChecked(false); m_widget->toolButtonNormalMapMode->setChecked(true); + m_widget->toolButtonCenterWaypoint->setEnabled(false); break; case MagicWaypoint_MapMode: m_widget->toolButtonNormalMapMode->setChecked(false); m_widget->toolButtonMagicWaypointMapMode->setChecked(true); + m_widget->toolButtonCenterWaypoint->setEnabled(true); break; default: m_map_mode = Normal_MapMode; m_widget->toolButtonMagicWaypointMapMode->setChecked(false); m_widget->toolButtonNormalMapMode->setChecked(true); + m_widget->toolButtonCenterWaypoint->setEnabled(false); break; } @@ -317,8 +333,9 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent) connect(m_map, SIGNAL(WPInserted(int const&, WayPointItem*)), this, SLOT(WPInserted(int const&, WayPointItem*))); connect(m_map, SIGNAL(WPDeleted(int const&)), this, SLOT(WPDeleted(int const&))); - QPointF pos = getLatLon(); - m_map->SetCurrentPosition(internals::PointLatLng(pos.x(), pos.y())); // set the default map position + m_map->SetCurrentPosition(home_position.coord); // set the map position + m_map->Home->SetCoord(home_position.coord); // set the HOME position + m_map->UAV->SetUAVPos(home_position.coord, 0.0); // set the UAV position // ************** // create various context menu (mouse right click menu) actions @@ -328,8 +345,6 @@ OPMapGadgetWidget::OPMapGadgetWidget(QWidget *parent) : QWidget(parent) // ************** // create the desired timers - // Pip .. I don't like polling, I prefer an efficient event driven system (signal/slot) but this will do for now - m_updateTimer = new QTimer(); m_updateTimer->setInterval(200); connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updatePosition())); @@ -503,6 +518,7 @@ void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event) menu.addSeparator()->setText(tr("HOME")); + menu.addAction(setHomeAct); menu.addAction(showHomeAct); menu.addAction(goHomeAct); @@ -518,29 +534,37 @@ void OPMapGadgetWidget::contextMenuEvent(QContextMenuEvent *event) // ********* - if (m_map_mode == Normal_MapMode) - { // only show the waypoint stuff if not in 'magic waypoint' mode + switch (m_map_mode) + { + case Normal_MapMode: // only show the waypoint stuff if not in 'magic waypoint' mode + menu.addSeparator()->setText(tr("Waypoints")); - menu.addSeparator()->setText(tr("Waypoints")); + menu.addAction(wayPointEditorAct); + menu.addAction(addWayPointAct); - menu.addAction(wayPointEditorAct); - menu.addAction(addWayPointAct); + if (m_mouse_waypoint) + { // we have a waypoint under the mouse + menu.addAction(editWayPointAct); - if (m_mouse_waypoint) - { // we have a waypoint under the mouse - menu.addAction(editWayPointAct); + lockWayPointAct->setChecked(waypoint_locked); + menu.addAction(lockWayPointAct); - lockWayPointAct->setChecked(waypoint_locked); - menu.addAction(lockWayPointAct); + if (!waypoint_locked) + menu.addAction(deleteWayPointAct); + } - if (!waypoint_locked) - menu.addAction(deleteWayPointAct); - } + m_waypoint_list_mutex.lock(); + if (m_waypoint_list.count() > 0) + menu.addAction(clearWayPointsAct); // we have waypoints + m_waypoint_list_mutex.unlock(); - m_waypoint_list_mutex.lock(); - if (m_waypoint_list.count() > 0) - menu.addAction(clearWayPointsAct); // we have waypoints - m_waypoint_list_mutex.unlock(); + break; + + case MagicWaypoint_MapMode: + menu.addSeparator()->setText(tr("Waypoints")); + menu.addAction(homeMagicWaypointAct); + menu.addAction(centerMagicWaypointAct); + break; } // ********* @@ -608,9 +632,9 @@ void OPMapGadgetWidget::updatePosition() QPointF pos = getLatLon(); internals::PointLatLng uav_pos = internals::PointLatLng(pos.x(), pos.y()); // current UAV position - float uav_heading = 0; //data.Heading; // current UAV heading - float uav_altitude_meters = 0; //data.Altitude; // current UAV height - float uav_ground_speed_meters_per_second = 0; //data.Groundspeed; // current UAV ground speed + float uav_heading = 0; //data.Heading; // current UAV heading + float uav_altitude_meters = 0; //data.Altitude; // current UAV height + float uav_ground_speed_meters_per_second = 0; //data.Groundspeed; // current UAV ground speed // display the UAV lat/lon position QString str = "lat: " + QString::number(uav_pos.Lat(), 'f', 7) + @@ -620,7 +644,7 @@ void OPMapGadgetWidget::updatePosition() " " + QString::number(uav_ground_speed_meters_per_second, 'f', 1) + "m/s"; m_widget->labelUAVPos->setText(str); - m_map->UAV->SetUAVPos(uav_pos, uav_altitude_meters); // set the maps UAV position + m_map->UAV->SetUAVPos(uav_pos, uav_altitude_meters); // set the maps UAV position m_map->UAV->SetUAVHeading(uav_heading); // set the maps UAV heading } @@ -1008,9 +1032,38 @@ void OPMapGadgetWidget::on_toolButtonMagicWaypointMapMode_clicked() setMapMode(MagicWaypoint_MapMode); } +void OPMapGadgetWidget::on_toolButtonHomeWaypoint_clicked() +{ + homeMagicWaypoint(); +} + +void OPMapGadgetWidget::on_toolButtonCenterWaypoint_clicked() +{ + centerMagicWaypoint(); +} + // ************************************************************************************* // public functions +void OPMapGadgetWidget::setHome(QPointF pos) +{ + if (!m_widget || !m_map) + return; + + setHome(internals::PointLatLng(pos.x(), pos.y())); +} + +void OPMapGadgetWidget::setHome(internals::PointLatLng pos_lat_lon) +{ + if (!m_widget || !m_map) + return; + + home_position.coord = pos_lat_lon; + + m_map->Home->SetCoord(home_position.coord); + m_map->Home->RefreshPos(); +} + void OPMapGadgetWidget::goHome() { if (!m_widget || !m_map) @@ -1018,8 +1071,8 @@ void OPMapGadgetWidget::goHome() followUAVpositionAct->setChecked(false); - internals::PointLatLng home_pos = m_map->Home->Coord(); // get the home location - m_map->SetCurrentPosition(home_pos); // center the map onto the home location + internals::PointLatLng home_pos = home_position.coord; // get the home location + m_map->SetCurrentPosition(home_pos); // center the map onto the home location } @@ -1162,6 +1215,8 @@ void OPMapGadgetWidget::setMapMode(opMapModeType mode) m_widget->toolButtonMagicWaypointMapMode->setChecked(false); m_widget->toolButtonNormalMapMode->setChecked(true); + m_widget->toolButtonCenterWaypoint->setEnabled(false); + // delete the magic waypoint from the map if (magic_waypoint.map_wp_item) { @@ -1196,6 +1251,8 @@ void OPMapGadgetWidget::setMapMode(opMapModeType mode) m_widget->toolButtonNormalMapMode->setChecked(false); m_widget->toolButtonMagicWaypointMapMode->setChecked(true); + m_widget->toolButtonCenterWaypoint->setEnabled(true); + // delete the normal waypoints from the map m_waypoint_list_mutex.lock(); foreach (t_waypoint *wp, m_waypoint_list) @@ -1289,6 +1346,10 @@ void OPMapGadgetWidget::createActions() goMouseClickAct->setStatusTip(tr("Center the map onto where you right clicked the mouse")); connect(goMouseClickAct, SIGNAL(triggered()), this, SLOT(onGoMouseClickAct_triggered())); + setHomeAct = new QAction(tr("Set the home location"), this); + setHomeAct->setStatusTip(tr("Set the home location to where you clicked")); + connect(setHomeAct, SIGNAL(triggered()), this, SLOT(onSetHomeAct_triggered())); + goHomeAct = new QAction(tr("Go to &Home location"), this); goHomeAct->setShortcut(tr("Ctrl+H")); goHomeAct->setStatusTip(tr("Center the map onto the home location")); @@ -1355,6 +1416,14 @@ void OPMapGadgetWidget::createActions() clearWayPointsAct->setStatusTip(tr("Clear waypoints")); connect(clearWayPointsAct, SIGNAL(triggered()), this, SLOT(onClearWayPointsAct_triggered())); + homeMagicWaypointAct = new QAction(tr("Home magic waypoint"), this); + homeMagicWaypointAct->setStatusTip(tr("Move the magic waypoint to the home position")); + connect(homeMagicWaypointAct, SIGNAL(triggered()), this, SLOT(onHomeMagicWaypointAct_triggered())); + + centerMagicWaypointAct = new QAction(tr("Center magic waypoint"), this); + centerMagicWaypointAct->setStatusTip(tr("Move the magic waypoint to the center of the map")); + connect(centerMagicWaypointAct, SIGNAL(triggered()), this, SLOT(onCenterMagicWaypointAct_triggered())); + mapModeActGroup = new QActionGroup(this); connect(mapModeActGroup, SIGNAL(triggered(QAction *)), this, SLOT(onMapModeActGroup_triggered(QAction *))); mapModeAct.clear(); @@ -1504,6 +1573,14 @@ void OPMapGadgetWidget::onGoMouseClickAct_triggered() m_map->SetCurrentPosition(m_map->currentMousePosition()); // center the map onto the mouse position } +void OPMapGadgetWidget::onSetHomeAct_triggered() +{ + if (!m_widget || !m_map) + return; + + setHome(mouse_lat_lon); +} + void OPMapGadgetWidget::onGoHomeAct_triggered() { if (!m_widget || !m_map) @@ -1724,6 +1801,52 @@ void OPMapGadgetWidget::onClearWayPointsAct_triggered() m_waypoint_list.clear(); } +void OPMapGadgetWidget::onHomeMagicWaypointAct_triggered() +{ + // center the magic waypoint on the home position + homeMagicWaypoint(); +} + +void OPMapGadgetWidget::onCenterMagicWaypointAct_triggered() +{ + // center the magic waypoint on the map + centerMagicWaypoint(); +} + +// ************************************************************************************* +// move the magic waypoint to the home position + +void OPMapGadgetWidget::homeMagicWaypoint() +{ + if (!m_widget || !m_map) + return; + + if (m_map_mode != MagicWaypoint_MapMode) + return; + + magic_waypoint.coord = home_position.coord; + + if (magic_waypoint.map_wp_item) + magic_waypoint.map_wp_item->SetCoord(magic_waypoint.coord); +} + +// ************************************************************************************* +// move the magic waypoint to the center of the map + +void OPMapGadgetWidget::centerMagicWaypoint() +{ + if (!m_widget || !m_map) + return; + + if (m_map_mode != MagicWaypoint_MapMode) + return; + + magic_waypoint.coord = m_map->CurrentPosition(); + + if (magic_waypoint.map_wp_item) + magic_waypoint.map_wp_item->SetCoord(magic_waypoint.coord); +} + // ************************************************************************************* // temporary until an object is created for managing the save/restore diff --git a/ground/src/plugins/opmap/opmapgadgetwidget.h b/ground/src/plugins/opmap/opmapgadgetwidget.h index 11c209478..6642fb6d7 100644 --- a/ground/src/plugins/opmap/opmapgadgetwidget.h +++ b/ground/src/plugins/opmap/opmapgadgetwidget.h @@ -65,6 +65,13 @@ using namespace mapcontrol; // ****************************************************** +typedef struct t_home +{ + internals::PointLatLng coord; + double altitude; + bool locked; +} t_home; + // local waypoint list item structure typedef struct t_waypoint { @@ -97,6 +104,8 @@ public: * * @param */ + void setHome(QPointF pos); + void setHome(internals::PointLatLng pos_lat_lon); void goHome(); void setZoom(int zoom); void setPosition(QPointF pos); @@ -147,6 +156,8 @@ private slots: void on_toolButtonGo_clicked(); void on_toolButtonMagicWaypointMapMode_clicked(); void on_toolButtonNormalMapMode_clicked(); + void on_toolButtonHomeWaypoint_clicked(); + void on_toolButtonCenterWaypoint_clicked(); /** * @brief signals received from the map object @@ -183,6 +194,7 @@ private slots: void onGoZoomInAct_triggered(); void onGoZoomOutAct_triggered(); void onGoMouseClickAct_triggered(); + void onSetHomeAct_triggered(); void onGoHomeAct_triggered(); void onGoUAVAct_triggered(); void onFollowUAVpositionAct_toggled(bool checked); @@ -197,6 +209,8 @@ private slots: void onClearWayPointsAct_triggered(); void onMapModeActGroup_triggered(QAction *action); void onZoomActGroup_triggered(QAction *action); + void onHomeMagicWaypointAct_triggered(); + void onCenterMagicWaypointAct_triggered(); private: int min_zoom; @@ -210,6 +224,10 @@ private: opMapModeType m_map_mode; + t_home home_position; + + t_waypoint magic_waypoint; + QStringList findPlaceWordList; QCompleter *findPlaceCompleter; @@ -241,8 +259,6 @@ private: QList m_waypoint_list; QMutex m_waypoint_list_mutex; - t_waypoint magic_waypoint; - QMutex m_map_mutex; void createActions(); @@ -259,6 +275,7 @@ private: QAction *zoomInAct; QAction *zoomOutAct; QAction *goMouseClickAct; + QAction *setHomeAct; QAction *goHomeAct; QAction *goUAVAct; QAction *followUAVpositionAct; @@ -271,6 +288,8 @@ private: QAction *lockWayPointAct; QAction *deleteWayPointAct; QAction *clearWayPointsAct; + QAction *homeMagicWaypointAct; + QAction *centerMagicWaypointAct; QActionGroup *mapModeActGroup; QList mapModeAct; @@ -278,6 +297,9 @@ private: QActionGroup *zoomActGroup; QList zoomAct; + void homeMagicWaypoint(); + void centerMagicWaypoint(); + void loadComboBoxLines(QComboBox *comboBox, QString filename); void saveComboBoxLines(QComboBox *comboBox, QString filename);