236 lines
6.3 KiB
C++
Executable File
236 lines
6.3 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Dialog to edit drone Simulation
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Steve Kemayou, ESZS, 2025-04-08
|
|
*/
|
|
|
|
|
|
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
|
|
#include <LtsUtilsSettings/settings.h>
|
|
#include <ProjectDataManagement/pdm_translation.h>
|
|
|
|
#include "mission_plan_model.h"
|
|
|
|
|
|
namespace CentralEffectSimulation
|
|
{
|
|
/*!
|
|
* \brief MissionPlanModel::MissionPlanModel
|
|
* \param parent
|
|
*/
|
|
MissionPlanModel::MissionPlanModel(QObject *parent)
|
|
: LtsWidgets::LtsAbstractTableModel<ParticipantManagement::MissionPlan>(
|
|
{tr("Name"),
|
|
tr("Mission Start"),
|
|
tr("Actions [fulfilled / Count]"),
|
|
tr("Fulfilled"),
|
|
tr("Participant"),
|
|
tr("UAS State"),
|
|
tr("Current Mission"),
|
|
tr("Aborted")},
|
|
parent)
|
|
, m_ppmDtc(nullptr)
|
|
, m_logger(getLogger("MissionPlanModel"))
|
|
{
|
|
|
|
}
|
|
/*!
|
|
* \brief MissionPlanModel::data
|
|
* \param index
|
|
* \param role
|
|
* \return
|
|
*/
|
|
QVariant MissionPlanModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if (role != Qt::DisplayRole || !indexIsValid(index))
|
|
return QVariant();
|
|
|
|
const ParticipantManagement::MissionPlan &mp = m_vecData.at(index.row());
|
|
switch (index.column())
|
|
{
|
|
|
|
case Columns::Name:
|
|
return QString::fromStdString(mp.name());
|
|
case Columns::MissionStart:
|
|
return QDateTime::fromMSecsSinceEpoch(mp.missionStart());
|
|
case Columns::Fulfilled:
|
|
return QDateTime::fromMSecsSinceEpoch(mp.fulfilled());
|
|
case Columns::ItemsCountAndFulfilled:
|
|
{
|
|
int actionsFulfilled = 0;
|
|
int actionsCount = 0;
|
|
for (const auto &item : mp.items())
|
|
{
|
|
actionsFulfilled += item.actionsFulfilled();
|
|
actionsCount += item.actions().size();
|
|
}
|
|
return QStringLiteral("%1/%2").arg(actionsFulfilled).arg(actionsCount);// item fulfilled / item count;
|
|
}
|
|
case Columns::Participant:
|
|
{
|
|
const auto &participant = m_ppmDtc->participant(mp.participantId());
|
|
return QString::number(mp.participantId());//QString::fromStdString(participant.designator());
|
|
}
|
|
case Columns::UasState:
|
|
{
|
|
const auto &uas = m_ppmDtc->getUasByParticipantId(mp.participantId(), m_exerciseId);
|
|
return ProjectDataManagement::toString(uas.uasState());
|
|
}
|
|
case Columns::CurrentMission:
|
|
{
|
|
return currentJob2String(mp);
|
|
}
|
|
case Columns::Aborted:
|
|
{
|
|
return mp.aborted();
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
/*!
|
|
* \brief MissionPlanModel::initModel
|
|
* \param ppmDtc
|
|
* \return
|
|
*/
|
|
bool MissionPlanModel::initModel(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc, int exerciseId)
|
|
{
|
|
m_ppmDtc = ppmDtc;
|
|
m_ppmDtc->enableMissionPlan(true);
|
|
|
|
m_exerciseId = exerciseId;
|
|
|
|
if (!m_ppmDtc->isUASEnabled())
|
|
m_ppmDtc->enableUAS();
|
|
|
|
m_ppmDtc->waitForHistoricalDataUAS(1000);
|
|
|
|
connect(m_ppmDtc.get(), &ParticipantManagement::Interface::Dtc::missionPlanChanged,
|
|
this, &MissionPlanModel::onMissionPlanChanged);
|
|
|
|
auto cb = [this](const ParticipantManagement::MissionPlan &msp)
|
|
{
|
|
onMissionPlanChanged(msp, DataModification::eAdded);
|
|
};
|
|
m_ppmDtc->missionPlans(cb);
|
|
|
|
return true;
|
|
}
|
|
|
|
QString MissionPlanModel::currentJob2String(const ParticipantManagement::MissionPlan &missionPlan) const
|
|
{
|
|
// get current action
|
|
// get latest actionType
|
|
ParticipantManagement::MissionAction currAction = m_ppmDtc->currentMissionAction(missionPlan.id());
|
|
if (currAction.planId() == 0 ||
|
|
static_cast<int>(missionPlan.items().size()) == missionPlan.itemsFulfilled())
|
|
return tr(" Mission Complete ");
|
|
|
|
switch (currAction.actionType().underlying())
|
|
{
|
|
case ParticipantManagement::MissionActionType::MoveTo:
|
|
{
|
|
return tr("Move to WP %1").arg(currAction.itemNumber()+1);
|
|
}
|
|
case ParticipantManagement::MissionActionType::Loiter:
|
|
{
|
|
return tr("WP %1: Loiter %2 sec.").arg(currAction.itemNumber()+1).arg(currAction.duration());
|
|
}
|
|
case ParticipantManagement::MissionActionType::Attack:
|
|
{
|
|
return tr("WP %1: Drop Charge").arg(currAction.itemNumber()+1);
|
|
}
|
|
default:
|
|
return tr("Unknown");
|
|
}
|
|
}
|
|
|
|
/*!
|
|
* \brief MissionPlanModel::onParticipantUASChanged
|
|
* \param data
|
|
* \param modType
|
|
*/
|
|
void MissionPlanModel::onMissionPlanChanged(const ParticipantManagement::MissionPlan &data, const DataModification modType)
|
|
{
|
|
const int id = data.id();
|
|
int row = findRowForId(id);
|
|
DEBUG_LOG(m_logger)<<"MISSION PLAN CHANGED id ( "<<data.id()<<" ) "<< modType;
|
|
switch (modType)
|
|
{
|
|
case DataModification::eModified:
|
|
{
|
|
if (row < 0)
|
|
return;
|
|
setRowData(row, data);
|
|
break;
|
|
}
|
|
case DataModification::eAdded:
|
|
{
|
|
if (row != -1)
|
|
return;
|
|
else
|
|
insertRow(data);
|
|
break;
|
|
}
|
|
case DataModification::eRemoved:
|
|
removeRow(row);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/// #####################################
|
|
/// PARTICIPANT_UAS-POXYMODEL
|
|
/// #####################################
|
|
///
|
|
|
|
/*!
|
|
* \brief ParticipantUASProxyModel::setSourceModel
|
|
* \param sourceModel
|
|
*/
|
|
void MissionPlanProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
|
|
{
|
|
m_sourceModel = qobject_cast<MissionPlanModel*>(sourceModel);
|
|
LtsWidgets::LtsColumnFilterProxyModel::setSourceModel(sourceModel);
|
|
}
|
|
|
|
/*!
|
|
* \brief ParticipantUASProxyModel::setShowExpired
|
|
* \param show
|
|
*/
|
|
void MissionPlanProxyModel::setShowExpired(bool show)
|
|
{
|
|
m_showExpired = show;
|
|
}
|
|
|
|
/*!
|
|
* \brief ParticipantUASProxyModel::filterAcceptsRow
|
|
* \param source_row
|
|
* \param sourceParent
|
|
* \return
|
|
*/
|
|
bool MissionPlanProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
|
{
|
|
Q_UNUSED(sourceParent)
|
|
return checkFilter(sourceRow);
|
|
}
|
|
|
|
/*!
|
|
* \brief ParticipantUASProxyModel::checkFilter
|
|
* \param sourceRow
|
|
* \return
|
|
*/
|
|
bool MissionPlanProxyModel::checkFilter(int sourceRow) const
|
|
{
|
|
Q_UNUSED(sourceRow)
|
|
//const auto uas = m_sourceModel->getRowData(sourceRow);
|
|
return true;
|
|
}
|
|
|
|
}// namespace CentralEffectSimulation
|