mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
Update the MagicWaypoint gadget to use PathDesired instead of PositionDesired
This commit is contained in:
parent
406b5a00f5
commit
a857530832
@ -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<UAVObjectManager>();
|
||||
PositionDesired* obj = dynamic_cast<PositionDesired*>( 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<UAVObjectManager>();
|
||||
PositionActual* obj = dynamic_cast<PositionActual*>( 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@
|
||||
#define MagicWaypointGADGETWIDGET_H_
|
||||
|
||||
#include <QtGui/QLabel>
|
||||
#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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user