#include "modeluavoproxy.h" #include "extensionsystem/pluginmanager.h" #include modelUavoProxy::modelUavoProxy(QObject *parent,flightDataModel * model):QObject(parent),myModel(model) { ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); Q_ASSERT(pm != NULL); objManager = pm->getObject(); Q_ASSERT(objManager != NULL); waypointObj = Waypoint::GetInstance(objManager); Q_ASSERT(waypointObj != NULL); pathactionObj=PathAction::GetInstance(objManager); Q_ASSERT(pathactionObj != NULL); /* int instances=objManager->getNumInstances(pathactionObj->getObjID()); PathAction * actionObj=new PathAction; actionObj->initialize(instances,actionObj->getMetaObject()); objManager->registerObject(actionObj); actionObj->updated(); instances=objManager->getNumInstances(pathactionObj->getObjID()); actionObj=new PathAction; actionObj->initialize(instances,actionObj->getMetaObject()); objManager->registerObject(actionObj); actionObj->updated(); instances=objManager->getNumInstances(pathactionObj->getObjID()); actionObj=new PathAction; actionObj->initialize(instances,actionObj->getMetaObject()); objManager->registerObject(actionObj); actionObj->updated(); */ } /*WPDESCRITPTION,LATPOSITION,LNGPOSITION,DISRELATIVE,BEARELATIVE,ISRELATIVE,ALTITUDE, VELOCITY,MODE,MODE_PARAMS0,MODE_PARAMS1,MODE_PARAMS2,MODE_PARAMS3, CONDITION,CONDITION_PARAMS0,CONDITION_PARAMS1,CONDITION_PARAMS2,CONDITION_PARAMS3, COMMAND,JUMPDESTINATION,ERRORDESTINATION,LOCKED */ void modelUavoProxy::modelToObjects() { PathAction * act=NULL; Waypoint * wp=NULL; QModelIndex index; double distance; double bearing; double altitude; int lastaction=-1; for(int x=0;xrowCount();++x) { int instances=objManager->getNumInstances(waypointObj->getObjID()); if(x>instances-1) { wp=new Waypoint; wp->initialize(x,wp->getMetaObject()); objManager->registerObject(wp); } else { wp=Waypoint::GetInstance(objManager,x); } act=new PathAction; Q_ASSERT(act); Q_ASSERT(wp); Waypoint::DataFields waypoint = wp->getData(); PathAction::DataFields action = act->getData(); ///Waypoint object data index=myModel->index(x,flightDataModel::DISRELATIVE); distance=myModel->data(index).toDouble(); index=myModel->index(x,flightDataModel::BEARELATIVE); bearing=myModel->data(index).toDouble(); index=myModel->index(x,flightDataModel::ALTITUDERELATIVE); altitude=myModel->data(index).toFloat(); index=myModel->index(x,flightDataModel::VELOCITY); waypoint.Velocity=myModel->data(index).toFloat(); waypoint.Position[Waypoint::POSITION_NORTH]=distance*cos(bearing/180*M_PI); waypoint.Position[Waypoint::POSITION_EAST]=distance*sin(bearing/180*M_PI); waypoint.Position[Waypoint::POSITION_DOWN]=(-1.0f)*altitude; ///PathAction object data index=myModel->index(x,flightDataModel::MODE); action.Mode=myModel->data(index).toInt(); index=myModel->index(x,flightDataModel::MODE_PARAMS0); action.ModeParameters[0]=myModel->data(index).toFloat(); index=myModel->index(x,flightDataModel::MODE_PARAMS1); action.ModeParameters[1]=myModel->data(index).toFloat(); index=myModel->index(x,flightDataModel::MODE_PARAMS2); action.ModeParameters[2]=myModel->data(index).toFloat(); index=myModel->index(x,flightDataModel::MODE_PARAMS3); action.ModeParameters[3]=myModel->data(index).toFloat(); index=myModel->index(x,flightDataModel::CONDITION); action.EndCondition=myModel->data(index).toInt(); index=myModel->index(x,flightDataModel::CONDITION_PARAMS0); action.ConditionParameters[0]=myModel->data(index).toFloat(); index=myModel->index(x,flightDataModel::CONDITION_PARAMS1); action.ConditionParameters[1]=myModel->data(index).toFloat(); index=myModel->index(x,flightDataModel::CONDITION_PARAMS2); action.ConditionParameters[2]=myModel->data(index).toFloat(); index=myModel->index(x,flightDataModel::CONDITION_PARAMS3); action.ConditionParameters[3]=myModel->data(index).toFloat(); index=myModel->index(x,flightDataModel::COMMAND); action.Command=myModel->data(index).toInt(); index=myModel->index(x,flightDataModel::JUMPDESTINATION); action.JumpDestination=myModel->data(index).toInt(); index=myModel->index(x,flightDataModel::ERRORDESTINATION); action.ErrorDestination=myModel->data(index).toInt(); int actionNumber=addAction(act,action,lastaction); if(actionNumber>lastaction) lastaction=actionNumber; waypoint.Action=actionNumber; wp->setData(waypoint); wp->updated(); } } void modelUavoProxy::objectsToModel() { Waypoint * wp; Waypoint::DataFields wpfields; PathAction * action; QModelIndex index; double distance; double bearing; PathAction::DataFields actionfields; myModel->removeRows(0,myModel->rowCount()); for(int x=0;xgetNumInstances(waypointObj->getObjID());++x) { wp=Waypoint::GetInstance(objManager,x); Q_ASSERT(wp); if(!wp) continue; wpfields=wp->getData(); myModel->insertRow(x); index=myModel->index(x,flightDataModel::VELOCITY); myModel->setData(index,wpfields.Velocity); distance=sqrt(wpfields.Position[Waypoint::POSITION_NORTH]*wpfields.Position[Waypoint::POSITION_NORTH]+ wpfields.Position[Waypoint::POSITION_EAST]*wpfields.Position[Waypoint::POSITION_EAST]); bearing=acos(wpfields.Position[Waypoint::POSITION_NORTH]/wpfields.Position[Waypoint::POSITION_EAST])*180/M_PI; if(bearing!=bearing) bearing=0; index=myModel->index(x,flightDataModel::DISRELATIVE); myModel->setData(index,distance); index=myModel->index(x,flightDataModel::BEARELATIVE); myModel->setData(index,bearing); index=myModel->index(x,flightDataModel::ALTITUDERELATIVE); myModel->setData(index,(-1.0f)*wpfields.Position[Waypoint::POSITION_DOWN]); action=PathAction::GetInstance(objManager,wpfields.Action); Q_ASSERT(action); if(!action) continue; actionfields=action->getData(); index=myModel->index(x,flightDataModel::ISRELATIVE); myModel->setData(index,true); index=myModel->index(x,flightDataModel::COMMAND); myModel->setData(index,actionfields.Command); index=myModel->index(x,flightDataModel::CONDITION_PARAMS0); myModel->setData(index,actionfields.ConditionParameters[0]); index=myModel->index(x,flightDataModel::CONDITION_PARAMS1); myModel->setData(index,actionfields.ConditionParameters[1]); index=myModel->index(x,flightDataModel::CONDITION_PARAMS2); myModel->setData(index,actionfields.ConditionParameters[2]); index=myModel->index(x,flightDataModel::CONDITION_PARAMS3); myModel->setData(index,actionfields.ConditionParameters[3]); index=myModel->index(x,flightDataModel::CONDITION); myModel->setData(index,actionfields.EndCondition); index=myModel->index(x,flightDataModel::ERRORDESTINATION); myModel->setData(index,actionfields.ErrorDestination); index=myModel->index(x,flightDataModel::JUMPDESTINATION); myModel->setData(index,actionfields.JumpDestination); index=myModel->index(x,flightDataModel::MODE); myModel->setData(index,actionfields.Mode); index=myModel->index(x,flightDataModel::MODE_PARAMS0); myModel->setData(index,actionfields.ModeParameters[0]); index=myModel->index(x,flightDataModel::MODE_PARAMS1); myModel->setData(index,actionfields.ModeParameters[1]); index=myModel->index(x,flightDataModel::MODE_PARAMS2); myModel->setData(index,actionfields.ModeParameters[2]); index=myModel->index(x,flightDataModel::MODE_PARAMS3); myModel->setData(index,actionfields.ModeParameters[3]); } } int modelUavoProxy::addAction(PathAction * actionObj,PathAction::DataFields actionFields,int lastaction) { //check if a similar action already exhists int instances=objManager->getNumInstances(pathactionObj->getObjID()); for(int x=0;xgetData(); if(fields.Command==actionFields.Command && fields.ConditionParameters[0]==actionFields.ConditionParameters[0] && fields.ConditionParameters[1]==actionFields.ConditionParameters[1] && fields.ConditionParameters[2]==actionFields.ConditionParameters[2] &&fields.EndCondition==actionFields.EndCondition &&fields.ErrorDestination==actionFields.ErrorDestination &&fields.JumpDestination==actionFields.JumpDestination &&fields.Mode==actionFields.Mode &&fields.ModeParameters[0]==actionFields.ModeParameters[0] &&fields.ModeParameters[1]==actionFields.ModeParameters[1] &&fields.ModeParameters[2]==actionFields.ModeParameters[2]) { qDebug()<<"ModelUAVProxy:"<<"found similar action instance:"<deleteLater(); return x; } } //if we get here it means no similar action was found, we have to create it if(instancesinitialize(instances,actionObj->getMetaObject()); objManager->registerObject(actionObj); actionObj->setData(actionFields); actionObj->updated(); qDebug()<<"ModelUAVProxy:"<<"created new action instance:"<setData(actionFields); action->updated(); actionObj->deleteLater(); qDebug()<<"ModelUAVProxy:"<<"reused action instance:"<