From a857530832d23a72df13b7928e82af199c701fdf Mon Sep 17 00:00:00 2001 From: James Cotton Date: Wed, 9 May 2012 10:58:24 -0500 Subject: [PATCH] Update the MagicWaypoint gadget to use PathDesired instead of PositionDesired --- .../magicwaypointgadgetwidget.cpp | 63 ++++++++++--------- .../magicwaypoint/magicwaypointgadgetwidget.h | 7 ++- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/magicwaypoint/magicwaypointgadgetwidget.cpp b/ground/openpilotgcs/src/plugins/magicwaypoint/magicwaypointgadgetwidget.cpp index 9d8bd32c3..b15bf2063 100644 --- a/ground/openpilotgcs/src/plugins/magicwaypoint/magicwaypointgadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/magicwaypoint/magicwaypointgadgetwidget.cpp @@ -47,7 +47,7 @@ MagicWaypointGadgetWidget::MagicWaypointGadgetWidget(QWidget *parent) : QLabel(p m_magicwaypoint->setupUi(this); // Connect object updated event from UAVObject to also update check boxes - connect(getPositionDesired(), SIGNAL(objectUpdated(UAVObject*)), this, SLOT(positionObjectChanged(UAVObject*))); + connect(getPathDesired(), SIGNAL(objectUpdated(UAVObject*)), this, SLOT(positionObjectChanged(UAVObject*))); connect(getPositionActual(), SIGNAL(objectUpdated(UAVObject*)), this, SLOT(positionObjectChanged(UAVObject*))); // Connect updates from the position widget to this widget @@ -57,6 +57,9 @@ MagicWaypointGadgetWidget::MagicWaypointGadgetWidget(QWidget *parent) : QLabel(p // Catch changes in scale for visualization connect(m_magicwaypoint->horizontalSliderScale, SIGNAL(valueChanged(int)), this, SLOT(scaleChanged(int))); + + // Make sure the scale is correctly visualized + m_magicwaypoint->horizontalSliderScale->setValue(10); } MagicWaypointGadgetWidget::~MagicWaypointGadgetWidget() @@ -67,11 +70,12 @@ MagicWaypointGadgetWidget::~MagicWaypointGadgetWidget() /*! \brief Returns the @ref PositionDesired UAVObject */ -PositionDesired* MagicWaypointGadgetWidget::getPositionDesired() +PathDesired* MagicWaypointGadgetWidget::getPathDesired() { ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager *objManager = pm->getObject(); - PositionDesired* obj = dynamic_cast( objManager->getObject(QString("PositionDesired")) ); + PathDesired* obj = PathDesired::GetInstance(objManager); + Q_ASSERT(obj != NULL); // Save crashes later return obj; } @@ -82,7 +86,8 @@ PositionActual* MagicWaypointGadgetWidget::getPositionActual() { ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager *objManager = pm->getObject(); - PositionActual* obj = dynamic_cast( objManager->getObject(QString("PositionActual")) ); + PositionActual *obj = PositionActual::GetInstance(objManager); + Q_ASSERT(obj != NULL); return obj; } @@ -91,45 +96,45 @@ PositionActual* MagicWaypointGadgetWidget::getPositionActual() */ void MagicWaypointGadgetWidget::scaleChanged(int scale) { Q_UNUSED(scale); - positionObjectChanged(getPositionDesired()); - positionObjectChanged(getPositionActual()); + pathDesiredChanged(getPathDesired()); + positionActualChanged(getPositionActual()); } /** - * Emit a position changed signal when @ref PositionDesired or @ref PositionActual object is changed + * Emit a position changed signal when @ref PositionActual object is changed */ -void MagicWaypointGadgetWidget::positionObjectChanged(UAVObject* obj) +void MagicWaypointGadgetWidget::positionActualChanged(UAVObject *) { + PositionActual::DataFields positionActual = getPositionActual()->getData(); double scale = m_magicwaypoint->horizontalSliderScale->value(); - double north = obj->getField("North")->getDouble() / scale; - double east = obj->getField("East")->getDouble() / scale; - - if(obj->getName().compare("PositionDesired")) { - emit positionDesiredObjectChanged(north,east); - } else { - emit positionActualObjectChanged(north,east); - } + emit positionActualObjectChanged(positionActual.North / scale, + positionActual.East / scale); } /** - * Slot called by visualization when a new @ref PositionDesired is requested + * Emit a position changed signal when @ref PathDesired is changed + */ +void MagicWaypointGadgetWidget::pathDesiredChanged(UAVObject *) +{ + PathDesired::DataFields pathDesired = getPathDesired()->getData(); + double scale = m_magicwaypoint->horizontalSliderScale->value(); + + emit positionDesiredObjectChanged(pathDesired.End[PathDesired::END_NORTH] / scale, + pathDesired.End[PathDesired::END_EAST] / scale); +} + +/** + * Slot called by visualization when a new @ref PathDesired is requested */ void MagicWaypointGadgetWidget::positionSelected(double north, double east) { double scale = m_magicwaypoint->horizontalSliderScale->value(); - PositionDesired * posDesired = getPositionDesired(); - if(posDesired) { - UAVObjectField * field = posDesired->getField("North"); - if(field) - field->setDouble(north * scale); - - field = posDesired->getField("East"); - if(field) - field->setDouble(east * scale); - - posDesired->updated(); - } + PathDesired::DataFields pathDesired = getPathDesired()->getData(); + pathDesired.End[PathDesired::END_NORTH] = north * scale; + pathDesired.End[PathDesired::END_EAST] = east * scale; + pathDesired.Mode = PathDesired::MODE_ENDPOINT; + getPathDesired()->setData(pathDesired); } /** diff --git a/ground/openpilotgcs/src/plugins/magicwaypoint/magicwaypointgadgetwidget.h b/ground/openpilotgcs/src/plugins/magicwaypoint/magicwaypointgadgetwidget.h index 388b32088..94fa32fdd 100644 --- a/ground/openpilotgcs/src/plugins/magicwaypoint/magicwaypointgadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/magicwaypoint/magicwaypointgadgetwidget.h @@ -29,7 +29,7 @@ #define MagicWaypointGADGETWIDGET_H_ #include -#include "positiondesired.h" +#include "pathdesired.h" #include "positionactual.h" class Ui_MagicWaypoint; @@ -48,11 +48,12 @@ signals: protected slots: void scaleChanged(int scale); - void positionObjectChanged(UAVObject *); + void positionActualChanged(UAVObject *); + void pathDesiredChanged(UAVObject *); void positionSelected(double north, double east); private: - PositionDesired * getPositionDesired(); + PathDesired * getPathDesired(); PositionActual * getPositionActual(); Ui_MagicWaypoint * m_magicwaypoint; };