Files
qt5-legatus-legacy/Lts/Services/AreaEffectSimulation/aes_dtc_impl_custom.cpp
T
2026-08-13 18:33:10 +02:00

420 lines
10 KiB
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @RDE_HEADER@
* Custom aes dtc functions (extends aes_dtc_impl.cpp/.h)
* $Id$
* $HeadURL$
* $Author$
*/
#include "aes_dtc_impl_custom.h"
#include <DDS/DTC/generic_dtc.h>
#include <DDS/Generic/generic_data_reader.h>
#include <QElapsedTimer>
#include <nglsettings/nglsettings_settings.h>
#include <ngltools/ngltools_filesystem.h>
namespace AreaEffectSimulation
{
namespace Interface
{
bool DtcImplCustom::aesItemViewFromEntityId(int entityId, AesType aesType, AesItemView &aesItemView)
{
if (!m_dtcAesItemView)
return false;
if (!isAesItemViewEnabled())
{
enableAesItemView();
waitForHistoricalDataAesItemView(2000);
}
for (const auto &sample : m_dtcAesItemView->readAlive())
{
if ( (sample.data().aesItemId() == entityId) &&
( (sample.data().aesTypeId() == aesType) || (aesType==AesType_def::AtUnknown) )
)
{
aesItemView = sample.data();
return true;
}
}
return false;
}
bool DtcImplCustom::aesItemFromId(int aesId, AesItem &aesItem)
{
aesItem = nContamination(aesId);
if (aesItem.id() > 0)
return true;
aesItem = bCContamination(aesId);
if (aesItem.id() > 0)
return true;
aesItem = explosionArea(aesId);
if (aesItem.id() > 0)
return true;
aesItem = explosionCluster(aesId);
if (aesItem.id() > 0)
return true;
aesItem = explosionSingle(aesId);
if (aesItem.id() > 0)
return true;
aesItem = mineArea(aesId);
if (aesItem.id() > 0)
return true;
aesItem = dangerArea(aesId);
if (aesItem.id() > 0)
return true;
aesItem = functionalArea(aesId);
if (aesItem.id() > 0)
return true;
aesItem = mineCorridor(aesId);
if (aesItem.id() > 0)
return true;
aesItem = borderline(aesId);
if (aesItem.id() > 0)
return true;
aesItem = technicalArea(aesId);
if (aesItem.id() > 0)
return true;
aesItem = airSupportImpact(aesId);
if (aesItem.id() > 0)
return true;
aesItem = gasPipe(aesId);
if (aesItem.id() > 0)
return true;
aesItem = boobyTrap(aesId);
if (aesItem.id() > 0)
return true;
aesItem = dusSingleMine(aesId);
if (aesItem.id() > 0)
return true;
aesItem = offRouteMine(aesId);
if (aesItem.id() > 0)
return true;
aesItem = effectCluster(aesId);
if (aesItem.id() > 0)
return true;
DEBUG_LOG(m_logger) << "No aesItem for aesId=" << aesId << " found";
return false;
}
AreaEffectSimulation::AesType DtcImplCustom::aesItemIdFromExternalId(long long externalId, int &aesItemId)
{
// Only regard the last 2 Bytes of the EIS:
// externalId = externalId & 0xffff;
QMap<qint32, AreaEffectSimulation::BCContamination> bcConts = bCContaminations();
aesItemId = 0;
for (const AreaEffectSimulation::BCContamination &bcCont : qAsConst(bcConts))
{
if (bcCont.externalId() == externalId)
{
if (bcCont.id() > aesItemId)
aesItemId = bcCont.id();
}
}
if (aesItemId > 0)
return AreaEffectSimulation::AesType_def::AtBCContamination;
QMap<qint32, AreaEffectSimulation::NContamination> nConts = nContaminations();
for (const AreaEffectSimulation::NContamination &nCont: qAsConst(nConts))
{
if (nCont.externalId() == externalId)
{
if (nCont.id() > aesItemId)
aesItemId = nCont.id();
}
}
if (aesItemId > 0)
return AreaEffectSimulation::AesType_def::AtNContamination;
QMap<qint32, AreaEffectSimulation::ExplosionArea> explAreas = explosionAreas();
for (const AreaEffectSimulation::ExplosionArea &explArea : qAsConst(explAreas))
{
if (explArea.externalId() == externalId)
{
if (explArea.id() > aesItemId)
aesItemId = explArea.id();
}
}
if (aesItemId > 0)
return AreaEffectSimulation::AesType_def::AtExplosionArea;
QMap<qint32, AreaEffectSimulation::ExplosionSingle> explSingles = explosionSingles();
for (const AreaEffectSimulation::ExplosionSingle &explSingle : qAsConst(explSingles))
{
if (explSingle.externalId() == externalId)
{
if (explSingle.id() > aesItemId)
aesItemId = explSingle.id();
}
}
if (aesItemId > 0)
return AreaEffectSimulation::AesType_def::AtExplosionSingle;
QMap<qint32, AreaEffectSimulation::MineArea> mAreas = mineAreas();
for(const AreaEffectSimulation::MineArea &mArea : qAsConst(mAreas))
{
if (mArea.externalId() == externalId)
{
if (mArea.id() > aesItemId)
aesItemId = mArea.id();
}
}
if (aesItemId > 0)
return AreaEffectSimulation::AesType_def::AtMineArea;
QMap<qint32, AreaEffectSimulation::MineCorridor> mCorridors = mineCorridors();
for (const AreaEffectSimulation::MineCorridor &mCorridor : qAsConst(mCorridors))
{
if (mCorridor.externalId() == externalId)
{
if (mCorridor.id() > aesItemId)
aesItemId = mCorridor.id();
}
}
if (aesItemId > 0)
return AreaEffectSimulation::AesType_def::AtMineCorridor;
return AreaEffectSimulation::AesType_def::AtUnknown;
}
bool DtcImplCustom::triggeredImpactsFromEntityId(int entityId, AesType aesType, TriggeredImpacts &triggeredImpacts)
{
if (!m_dtcAesItemView)
return false;
if (!isTriggeredImpactsEnabled())
{
enableTriggeredImpacts();
waitForHistoricalDataTriggeredImpacts(2000);
}
for (const auto &sample : m_dtcTriggeredImpacts->readAlive())
{
if ( (sample.data().aesItemId() == entityId) &&
( (sample.data().aesTypeId() == aesType) || (aesType==AesType_def::AtUnknown) )
)
{
triggeredImpacts = sample.data();
return true;
}
}
return false;
}
bool DtcImplCustom::effectsFromEntityId(int entityId, AesType aesType, Effects &effects)
{
if (!m_dtcEffects)
return false;
if (!isEffectsEnabled())
{
enableEffects();
waitForHistoricalDataEffects(2000);
}
for (const auto &sample : m_dtcEffects->readAlive())
{
if ( (sample.data().aesItemId() == entityId) &&
( (sample.data().aesTypeId() == aesType) || (aesType==AesType_def::AtUnknown) )
)
{
effects = sample.data();
return true;
}
}
return false;
}
int DtcImplCustom::partyForDusMine(int dusMineId) const
{
for (const auto &dms : m_dusMineStateCont)
{
for (const DusMine &dm : dms.mines())
{
if (dm.eqId() == dusMineId)
{
auto it = m_mineAreaCont.find(dms.id());
if (it == m_mineAreaCont.end())
return 1;
return it.value().partyId().is_set() ? it.value().partyId().get() : 1;
}
}
}
return -1;
}
QString DtcImplCustom::aesItemNameFromEntityId(int entityId)
{
AreaEffectSimulation::AesItem aesItem;
aesItemFromId(entityId, aesItem);
if (!aesItem.name().empty())
return QString::fromStdString(aesItem.name());
//else use DAO
if (!m_dao)
initDAO();
for (const auto &item : m_explosionClusters)
{
if (item.id == entityId)
{
return item.name;
}
}
for (const auto &item : m_bcContaminations)
{
if (item.id == entityId)
{
return item.name;
}
}
for (const auto &item : m_nContaminations)
{
if (item.id == entityId)
{
return item.name;
}
}
for (const auto &item : m_boobyTraps)
{
if (item.id == entityId)
{
return item.name;
}
}
for (const auto &item : m_dangerAreas)
{
if (item.id == entityId)
{
return item.name;
}
}
for (const auto &item : m_mineAreas)
{
if (item.id == entityId)
{
return item.name;
}
}
for (const auto &item : m_offRouteMines)
{
if (item.id == entityId)
{
return item.name;
}
}
for (const auto &item : m_technicalAreas)
{
if (item.id == entityId)
return item.name;
}
for (const auto &item : m_functionalAreas)
{
if (item.id == entityId)
{
return item.name;
}
}
ERROR_LOG(m_logger) << " aesItem for aesId=" << entityId << "NOT found in in DAO or DDS";
return QString();
}
QVector<TrajectoryTimeAware> DtcImplCustom::trajectoriesTimeAwareFromOriginatorIdAndType(int originatorId, ProjectDataManagement::StateChangeOriginator originatorTypeId)
{
QVector<TrajectoryTimeAware> foundTrajectories;
const QMap<qint32, AreaEffectSimulation::TrajectoryTimeAware> &trajectoryTimeAwareMap = trajectoryTimeAwares();
for (const AreaEffectSimulation::TrajectoryTimeAware &trajectoryTimeAware : qAsConst(trajectoryTimeAwareMap))
{
// be aware of: [E01562-259] use originatorId, originatorTypeId (instead of aesItemId, aesTypeId)
if ((trajectoryTimeAware.originatorId() == originatorId) &&
(trajectoryTimeAware.originatorTypeId() == originatorTypeId))
foundTrajectories.append(trajectoryTimeAware);
}
return foundTrajectories;
}
void DtcImplCustom::initDAO()
{
DEBUG_LOG(m_logger) << "INIT DAO " << m_ddsConnector->getExerciseId();
NGL::Settings *s = new NGL::Settings(NGL::findProjectConfigFile());
QElapsedTimer timer;
timer.start();
m_dao = new Dao(m_ddsConnector->getExerciseId());
if(!m_dao->init(QStringLiteral("postgres"),
QStringLiteral("postgres"),
s->databaseDriver(),
s->databaseHostname(),
s->databaseName()))
{
ERROR_LOG(m_logger) << "ERROR INIT DAO AFTER: " << timer.elapsed();
return;
}
m_dao->select(m_explosionClusters);
m_dao->select(m_offRouteMines);
m_dao->select(m_boobyTraps);
m_dao->select(m_technicalAreas);
m_dao->select(m_functionalAreas);
m_dao->select(m_dangerAreas);
m_dao->select(m_mineAreas);
m_dao->select(m_bcContaminations);
m_dao->select(m_nContaminations);
DEBUG_LOG(m_logger) << "TOOK: " << timer.elapsed();
}
//QVector<TrajectoryTimeAware> DtcImplCustom::trajectoryTimeAwaresFromAesId(int aesId)
//{
// const QMap<qint32, AreaEffectSimulation::TrajectoryTimeAware> &trajectoryTimeAwareMap = trajectoryTimeAwares();
// QVector<TrajectoryTimeAware> trajectoriesFromAesIdVec;
// // We don´t realy know, how many to reserve:
// trajectoriesFromAesIdVec.reserve(120); // 2024-09 N.Thoden: 120 ist maximum per area
// for (const AreaEffectSimulation::TrajectoryTimeAware &trajectoryTimeAware : qAsConst(trajectoryTimeAwareMap))
// {
// if (trajectoryTimeAware.aesItemId() == aesId)
// trajectoriesFromAesIdVec.push_back(trajectoryTimeAware);
// }
// // free unused memory:
// trajectoriesFromAesIdVec.squeeze();
// return trajectoriesFromAesIdVec;
//}
}//Interface
}//namespace AreaEffectSimulation