// update waypoint and path actions UAV objects // // waypoints are unique and each waypoint has an entry in the UAV waypoint list // // a path action can be referenced by multiple waypoints // waypoints reference path action by their index in the UAV path action list // the compression of path actions happens here. // (compression consists in keeping only one instance of similar path actions) // // the UAV waypoint list and path action list are probably not empty, so we try to reuse existing instances bool ModelUavoProxy::modelToObjects() { qDebug() << "ModelUAVProxy::modelToObjects"; // track number of path actions int actionCount = 0; // iterate over waypoints int waypointCount = myModel->rowCount(); for (int i = 0; i < waypointCount; ++i) { // Path Actions // create action to use as a search criteria // this object does not need to be deleted as it will either be added to the managed list or deleted later PathAction *action = new PathAction; // get model data PathAction::DataFields actionData = action->getData(); modelToPathAction(i, actionData); // see if that path action has already been added in this run PathAction *foundAction = findPathAction(actionData, actionCount); // TODO this test needs a consistency check as it is unsafe. // if the find method is buggy and returns false positives then the flight plan sent to the uav is broken! // the find method should do a "binary" compare instead of a field by field compare // if a field is added everywhere and not in the compare method then you can start having false positives if (!foundAction) { // create or reuse an action instance action = createPathAction(actionCount, action); actionCount++; // update UAVObject action->setData(actionData); } else { action->deleteLater(); action = foundAction; qDebug() << "ModelUAVProxy::modelToObjects - found action instance :" << action->getInstID(); } // Waypoints // create or reuse a waypoint instance Waypoint *waypoint = createWaypoint(i, NULL); Q_ASSERT(waypoint); // get model data Waypoint::DataFields waypointData = waypoint->getData(); modelToWaypoint(i, waypointData); // connect waypoint to path action waypointData.Action = action->getInstID(); // update UAVObject waypoint->setData(waypointData); } // Put "safe" values in unused waypoint and path action objects if (waypointCount < objMngr->getNumInstances(Waypoint::OBJID)) { for (int i = waypointCount; i < objMngr->getNumInstances(Waypoint::OBJID); ++i) { // TODO } } if (actionCount < objMngr->getNumInstances(PathAction::OBJID)) { for (int i = actionCount; i < objMngr->getNumInstances(PathAction::OBJID); ++i) { // TODO } } // Update PathPlan PathPlan *pathPlan = PathPlan::GetInstance(objMngr); PathPlan::DataFields pathPlanData = pathPlan->getData(); pathPlanData.WaypointCount = waypointCount; pathPlanData.PathActionCount = actionCount; pathPlanData.Crc = computePathPlanCrc(waypointCount, actionCount); pathPlan->setData(pathPlanData); return true; }