206 lines
5.5 KiB
C++
Executable File
206 lines
5.5 KiB
C++
Executable File
/**
|
|
* Handling of PDM-Data so we dont call the DTC more than once
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Philipp Dassow, SLST, 2017-09-25
|
|
*/
|
|
|
|
#include "pdm_handler.h"
|
|
#include <ProjectDataManagement/pdm_dtc.h>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
|
|
namespace SituationMap
|
|
{
|
|
|
|
QString toString(SpecialChargeType value)
|
|
{
|
|
switch (value)
|
|
{
|
|
case SpecialChargeType::NoneSpecial:
|
|
return QStringLiteral("SpecialChargeType:NoneSpecial");
|
|
case SpecialChargeType::LRF:
|
|
return QStringLiteral("SpecialChargeType:LRF");
|
|
case SpecialChargeType::LTD:
|
|
return QStringLiteral("SpecialChargeType:LTD");
|
|
} // switch
|
|
Q_ASSERT(false);
|
|
return QStringLiteral("SpecialChargeTypeERROR");
|
|
}
|
|
|
|
PdmHandler::PdmHandler(const std::shared_ptr<ProjectDataManagement::Interface::Dtc> &dtcPdm)
|
|
: m_dtcPdm(dtcPdm)
|
|
, m_logger(getLogger("PdmHandler"))
|
|
{}
|
|
|
|
|
|
void PdmHandler::initializePdm()
|
|
{
|
|
if (m_dtcPdm == nullptr)
|
|
return;
|
|
|
|
if (m_bPdmInitialized)
|
|
return;
|
|
m_bPdmInitialized = true;
|
|
|
|
connect(m_dtcPdm.get(), &ProjectDataManagement::Interface::Dtc::chargeTypeChanged,
|
|
this, &PdmHandler::onChargeTypeChanged);
|
|
connect(m_dtcPdm.get(), &ProjectDataManagement::Interface::Dtc::gearTypeChargeTypeChanged,
|
|
this, &PdmHandler::onGearTypeChargeTypeChanged);
|
|
|
|
m_chargeTypes = m_dtcPdm->chargeTypes();
|
|
m_gearTypeChargeTypes = m_dtcPdm->gearTypeChargeTypes();
|
|
}
|
|
|
|
void PdmHandler::onChargeTypeChanged(const ProjectDataManagement::ChargeType &data, DataModification mod)
|
|
{
|
|
switch (mod)
|
|
{
|
|
case DataModification::eAdded:
|
|
case DataModification::eModified:
|
|
m_chargeTypes[data.id()] = data;
|
|
break;
|
|
case DataModification::eRemoved:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void PdmHandler::onGearTypeChargeTypeChanged(const ProjectDataManagement::GearTypeChargeType &data, DataModification mod)
|
|
{
|
|
switch (mod)
|
|
{
|
|
case DataModification::eAdded:
|
|
case DataModification::eModified:
|
|
m_gearTypeChargeTypes[data.id()] = data;
|
|
break;
|
|
case DataModification::eRemoved:
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
ProjectDataManagement::ChargeType PdmHandler::chargeTypeFromId(int chargeTypeId)
|
|
{
|
|
if (chargeTypeId <= 0)
|
|
return ProjectDataManagement::ChargeType();
|
|
|
|
initializePdm();
|
|
|
|
auto it = m_chargeTypes.constFind(chargeTypeId);
|
|
if (it == m_chargeTypes.cend())
|
|
{
|
|
WARNING_LOG(m_logger) << "Could not find charge type with id " << chargeTypeId;
|
|
return ProjectDataManagement::ChargeType();
|
|
}
|
|
return it.value();
|
|
}
|
|
|
|
int PdmHandler::maxRangeFromGearTypeIdAndChargeTypeId(int gearTypeId, int chargeTypeId)
|
|
{
|
|
if (gearTypeId < 0)
|
|
return -1;
|
|
if (chargeTypeId < 0)
|
|
return -1;
|
|
|
|
initializePdm();
|
|
|
|
// [NLDEVCTRL-926]: honor gearTypeId also
|
|
for (const auto &entry : qAsConst(m_gearTypeChargeTypes))
|
|
if ((entry.gearTypeId() == gearTypeId) &&
|
|
(entry.chargeTypeId() == chargeTypeId))
|
|
return entry.maxRange();
|
|
|
|
// [NLDEVCTRL-926]: Not found? Try with gearTypeId == 1000; // suggested by Malte Diers, Aug 2021
|
|
for (const auto &entry : qAsConst(m_gearTypeChargeTypes))
|
|
if ((entry.gearTypeId() == 1000) &&
|
|
(entry.chargeTypeId() == chargeTypeId))
|
|
return entry.maxRange();
|
|
|
|
return -1;
|
|
}
|
|
|
|
double PdmHandler::impactRadius(const AreaEffectSimulation::ChargeStruct &chargeStruct, double defaultValue)
|
|
{
|
|
if (chargeStruct.chargeTypeId() < 0)
|
|
return defaultValue;
|
|
|
|
initializePdm();
|
|
if (!m_dtcPdm)
|
|
return defaultValue;
|
|
|
|
return m_dtcPdm->impactRadius(chargeStruct.chargeTypeId(), chargeStruct.igniterTypeId(), chargeStruct.igniterFunctionId());
|
|
}
|
|
|
|
bool PdmHandler::isSmart(const AreaEffectSimulation::ChargeStruct &chargeStruct)
|
|
{
|
|
if (chargeStruct.chargeTypeId() < 0)
|
|
return false;
|
|
|
|
initializePdm();
|
|
if (!m_dtcPdm)
|
|
return false;
|
|
|
|
return m_dtcPdm->isSmart(chargeStruct.chargeTypeId(), chargeStruct.igniterTypeId(), chargeStruct.igniterFunctionId());
|
|
}
|
|
|
|
QString PdmHandler::trChargeTypeShortName(int chargeTypeId)
|
|
{
|
|
if (!m_dtcPdm)
|
|
return QString();
|
|
|
|
return m_dtcPdm->trChargeTypeShortName(chargeTypeId);
|
|
}
|
|
|
|
bool PdmHandler::isLRFChargeType(int chargeTypeId)
|
|
{
|
|
return isSpecialChargeType(chargeTypeId) == SpecialChargeType::LRF;
|
|
}
|
|
|
|
bool PdmHandler::isLTDChargeType(int chargeTypeId)
|
|
{
|
|
return isSpecialChargeType(chargeTypeId) == SpecialChargeType::LTD;
|
|
}
|
|
|
|
bool PdmHandler::isChargeTypeLtdOrLrf(SpecialChargeType sct)
|
|
{
|
|
return ((sct == SpecialChargeType::LRF) || (sct == SpecialChargeType::LTD));
|
|
}
|
|
|
|
ProjectDataManagement::GearClass PdmHandler::gearClassFromChargeTypeId(int chargeTypeId)
|
|
{
|
|
if (!m_dtcPdm)
|
|
return ProjectDataManagement::GearClass_def::Unknown;
|
|
return m_dtcPdm->gearClassFromChargeTypeId(chargeTypeId);
|
|
}
|
|
|
|
QVector<ProjectDataManagement::CasEffect> PdmHandler::casEffects(const AreaEffectSimulation::ChargeStruct &chargeStruct)
|
|
{
|
|
if (!m_dtcPdm)
|
|
return {};
|
|
return m_dtcPdm->casEffects(chargeStruct.chargeTypeId(), chargeStruct.igniterTypeId(), chargeStruct.igniterFunctionId());
|
|
}
|
|
|
|
bool PdmHandler::isChargeTypeLtdOrLrf(int chargeTypeId)
|
|
{
|
|
const SpecialChargeType specialChargeTypeId = isSpecialChargeType(chargeTypeId);
|
|
return isChargeTypeLtdOrLrf(specialChargeTypeId);
|
|
}
|
|
|
|
|
|
SpecialChargeType PdmHandler::isSpecialChargeType(int chargeTypeId)
|
|
{
|
|
// NOTE: igniterType/IgniterFunciton = 0 as long as does not contain values
|
|
ProjectDataManagement::ChargeTypeProperty ret = m_dtcPdm->getChargeTypeSpecialProperty(chargeTypeId, 0,0);
|
|
|
|
if (ret == ProjectDataManagement::ChargeTypeProperty::LRF)
|
|
return SpecialChargeType::LRF;
|
|
if (ret == ProjectDataManagement::ChargeTypeProperty::LTD)
|
|
return SpecialChargeType::LTD;
|
|
|
|
|
|
return SpecialChargeType::NoneSpecial;
|
|
}
|
|
|
|
} // namespace SituationMap
|