mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-17 02:52:12 +01:00
Dragging and dropping waypoints now works and updates the FC immediately.
This commit is contained in:
parent
302575714f
commit
b4d59d3e3e
@ -95,6 +95,7 @@ namespace mapcontrol
|
||||
}
|
||||
void WayPointItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
QGraphicsItem::mouseReleaseEvent(event);
|
||||
if(event->button()==Qt::LeftButton)
|
||||
{
|
||||
if(text) {
|
||||
@ -110,8 +111,8 @@ namespace mapcontrol
|
||||
RefreshToolTip();
|
||||
|
||||
emit WPValuesChanged(this);
|
||||
emit WPDropped(this);
|
||||
}
|
||||
QGraphicsItem::mouseReleaseEvent(event);
|
||||
}
|
||||
void WayPointItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
|
@ -198,6 +198,7 @@ signals:
|
||||
* @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
|
||||
*
|
||||
@ -205,6 +206,13 @@ signals:
|
||||
*/
|
||||
void WPValuesChanged(WayPointItem* waypoint);
|
||||
|
||||
/**
|
||||
* @brief Fired when the waypoint is dropped somewhere
|
||||
*
|
||||
* @param waypoint a pointer to this WayPoint
|
||||
*/
|
||||
void WPDropped(WayPointItem* waypoint);
|
||||
|
||||
};
|
||||
}
|
||||
#endif // WAYPOINTITEM_H
|
||||
|
@ -887,26 +887,19 @@ void OPMapGadgetWidget::WPNumberChanged(int const &oldnumber, int const &newnumb
|
||||
Q_UNUSED(waypoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever a waypoint item is changed on the mapcontrol. Needs to update
|
||||
* the backend appropriately
|
||||
*/
|
||||
void OPMapGadgetWidget::WPValuesChanged(WayPointItem *waypoint)
|
||||
{
|
||||
// qDebug("opmap: WPValuesChanged");
|
||||
|
||||
switch (m_map_mode)
|
||||
{
|
||||
case Normal_MapMode:
|
||||
m_waypoint_list_mutex.lock();
|
||||
foreach (t_waypoint *wp, m_waypoint_list)
|
||||
{ // search for the waypoint in our own waypoint list and update it
|
||||
if (!wp) continue;
|
||||
if (!wp->map_wp_item) continue;
|
||||
if (wp->map_wp_item != waypoint) continue;
|
||||
// found the waypoint in our list
|
||||
wp->coord = waypoint->Coord();
|
||||
wp->altitude = waypoint->Altitude();
|
||||
wp->description = waypoint->Description();
|
||||
break;
|
||||
}
|
||||
m_waypoint_list_mutex.unlock();
|
||||
{
|
||||
// TODO: We don't parse changes in position here as it's too dense
|
||||
// however a change in something like
|
||||
}
|
||||
break;
|
||||
|
||||
case MagicWaypoint_MapMode:
|
||||
@ -2359,6 +2352,7 @@ void OPMapGadgetWidget::SetUavPic(QString UAVPic)
|
||||
*/
|
||||
void OPMapGadgetWidget::doVisualizationChanged(QList<PathCompiler::waypoint> waypoints)
|
||||
{
|
||||
disconnect(this,SLOT(WPDropped(WayPointItem*)));
|
||||
m_map->WPDeleteAll();
|
||||
int index = 0;
|
||||
foreach (PathCompiler::waypoint waypoint, waypoints) {
|
||||
@ -2371,5 +2365,24 @@ void OPMapGadgetWidget::doVisualizationChanged(QList<PathCompiler::waypoint> way
|
||||
wayPointItem->picture.load(QString::fromUtf8(":/opmap/images/waypoint_marker1.png"));
|
||||
index++;
|
||||
}
|
||||
connect(wayPointItem, SIGNAL(WPDropped(WayPointItem*)), this, SLOT(WPDropped(WayPointItem*)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a waypoint is dropped at a new location. Waypoint changed
|
||||
* can't be used as it is updated too frequently and we don't want to
|
||||
* overload the pathcompiler with unnecessary updates
|
||||
*/
|
||||
void OPMapGadgetWidget::WPDropped(WayPointItem *waypoint)
|
||||
{
|
||||
switch (m_map_mode)
|
||||
{
|
||||
case Normal_MapMode:
|
||||
PathCompiler::waypoint newWaypoint;
|
||||
newWaypoint.latitude = waypoint->Coord().Lat();
|
||||
newWaypoint.longitude = waypoint->Coord().Lng();
|
||||
pathCompiler->doUpdateWaypoints(newWaypoint,waypoint->Number());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -179,6 +179,7 @@ private slots:
|
||||
/**
|
||||
* Unused for now, hooks for future waypoint support
|
||||
*/
|
||||
void WPDropped(WayPointItem *waypoint);
|
||||
void WPNumberChanged(int const& oldnumber,int const& newnumber, WayPointItem* waypoint);
|
||||
void WPValuesChanged(WayPointItem* waypoint);
|
||||
void WPInserted(int const& number, WayPointItem* waypoint);
|
||||
|
@ -140,6 +140,7 @@ void PathCompiler::doAddWaypoint(waypoint newWaypointInternal, int /*position*/)
|
||||
if(waypointData.Action == Waypoint::ACTION_STOP) {
|
||||
waypointData.Action = Waypoint::ACTION_PATHTONEXT;
|
||||
waypoint->setData(waypointData);
|
||||
waypoint->updated();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -169,6 +170,30 @@ void PathCompiler::doAddWaypoint(waypoint newWaypointInternal, int /*position*/)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update waypoint
|
||||
*/
|
||||
void PathCompiler::doUpdateWaypoints(PathCompiler::waypoint changedWaypoint, int position)
|
||||
{
|
||||
int numWaypoints = getObjectManager()->getNumInstances(Waypoint::OBJID);
|
||||
Q_ASSERT(position < numWaypoints);
|
||||
if (position >= numWaypoints)
|
||||
return;
|
||||
|
||||
Waypoint *waypointInst = Waypoint::GetInstance(getObjectManager(), position);
|
||||
Q_ASSERT(waypointInst);
|
||||
|
||||
// Mirror over the updated position. We don't just use the changedWaypoint
|
||||
// because things like action might need to be preserved
|
||||
Waypoint::DataFields changedWaypointUAVO = InternalToUavo(changedWaypoint);
|
||||
Waypoint::DataFields oldWaypointUAVO = waypointInst->getData();
|
||||
oldWaypointUAVO.Position[0] = changedWaypointUAVO.Position[0];
|
||||
oldWaypointUAVO.Position[1] = changedWaypointUAVO.Position[1];
|
||||
oldWaypointUAVO.Position[2] = changedWaypointUAVO.Position[2];
|
||||
waypointInst->setData(oldWaypointUAVO);
|
||||
waypointInst->updated();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a waypoint
|
||||
* @param index which waypoint to delete
|
||||
@ -255,10 +280,6 @@ void PathCompiler::doUpdateFromUAV(UAVObject *obj)
|
||||
if (!objManager)
|
||||
return;
|
||||
|
||||
if(obj) {
|
||||
qDebug() << "Update:" << obj->getInstID();
|
||||
}
|
||||
|
||||
Waypoint *waypointObj = Waypoint::GetInstance(getObjectManager());
|
||||
Q_ASSERT(waypointObj);
|
||||
if (waypointObj == NULL)
|
||||
|
@ -118,7 +118,7 @@ public slots:
|
||||
/**
|
||||
* Update waypoint
|
||||
*/
|
||||
//void doUpdateWaypoints(struct PathCompiler::waypoint, int position);
|
||||
void doUpdateWaypoints(PathCompiler::waypoint, int position);
|
||||
|
||||
/**
|
||||
* Delete a waypoint
|
||||
|
Loading…
x
Reference in New Issue
Block a user