175 lines
6.8 KiB
C++
Executable File
175 lines
6.8 KiB
C++
Executable File
/**
|
|
* Handler for all indirect fire single objects
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "handler_explosion_single_central.h"
|
|
#include "main_handler.h"
|
|
|
|
#include <LtsCoordTrans/lts_coord_trans.h>
|
|
|
|
#include <QPolygonF>
|
|
#include <QTransform>
|
|
#include <QFileInfo>
|
|
|
|
|
|
namespace AreaEffectSimulation
|
|
{
|
|
|
|
HandlerExplosionSingleCentral::HandlerExplosionSingleCentral(MainHandler *mainHandler)
|
|
: HandlerBaseTmpl<ObjectExplosionSingleCentral>(mainHandler, QStringLiteral("ExplosionSingleCentral"), s_areaCount[AesType::AtExplosionSingleCentral], s_areaCountCentral[AesType::AtExplosionAreaSingleExplosions])
|
|
, Interface::Fts::ExplosionSingleCentralModifyRequestHandler(mainHandler->dds()->fts())
|
|
, Interface::Fts::ExplosionSingleCentralRemoveRequestHandler(mainHandler->dds()->fts())
|
|
, m_elevationMap(new SituationMap::ElevationMap(QFileInfo(QStringLiteral("/usr/share/arcgis/resources/elevation/srtm_38_02.tif"))))
|
|
{}
|
|
|
|
bool HandlerExplosionSingleCentral::init()
|
|
{
|
|
QVector<Database::AesExplosionSingleCentral> dataVec;
|
|
// read all indirect fire single from database
|
|
if (!m_mainHandler->db()->select(dataVec))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error reading data from database!";
|
|
return true;
|
|
}
|
|
// create indirect fire single objects
|
|
for (const Database::AesExplosionSingleCentral &dbData : qAsConst(dataVec))
|
|
{
|
|
ObjectExplosionSingleCentral *ifs(new ObjectExplosionSingleCentral(m_mainHandler, this));
|
|
connect(ifs, &ObjectExplosionSingleCentral::effectStateChanged, this, &HandlerExplosionSingleCentral::onEffectStateChanged);
|
|
Core::FunctionReplyObject ret = ifs->createObject(dbData);
|
|
if (ret.error())
|
|
{
|
|
delete ifs;
|
|
ERROR_LOG(m_logger) << ret();
|
|
return false;
|
|
}
|
|
if (ifs->isObjectInTrainingArea())
|
|
++m_areaCount;
|
|
m_objectMap.insert(ifs->id(), ifs);
|
|
connect(ifs, &ObjectExplosionSingleCentral::newAiv, this, &HandlerExplosionSingleCentral::newAiv);
|
|
connect(ifs, &ObjectExplosionSingleCentral::removeAiv, this, &HandlerExplosionSingleCentral::removeAiv);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
static void fillGeometryData(const ExplosionSingleCentralModifyRequest &src, Database::AesExplosionSingleCentral &dst)
|
|
{
|
|
dst.impactPosition.rx() = src.impactPosition().lon();
|
|
dst.impactPosition.ry() = src.impactPosition().lat();
|
|
}
|
|
|
|
static void fillData(const ExplosionSingleCentralModifyRequest &src, Database::AesExplosionSingleCentral &dst)
|
|
{
|
|
if (src.id() < 0) // is the id given as negative? set id -> used by OC-Laptop
|
|
dst.id = src.id();
|
|
|
|
fillGeometryData(src, dst);
|
|
dst.name = QString::fromStdString(src.name());
|
|
dst.effectStart = src.effectStart().is_set() && src.effectStart().get() > 0 ? QDateTime::fromMSecsSinceEpoch(src.effectStart().get()) : QDateTime();
|
|
dst.effectDuration = 1000; // 1sec
|
|
dst.chargeTypeId = src.chargeTypeId();
|
|
dst.altitude = src.altitude();
|
|
dst.firePurpose = QString::fromStdString(src.purpose());
|
|
dst.fireRequestTime = QDateTime::fromMSecsSinceEpoch(src.fireRequestTime());
|
|
dst.effectMarkingInTa = src.effectMarkingInTa();
|
|
dst.externalId = src.externalId().is_set() ? src.externalId().get() : 0;
|
|
dst.angle = src.angle();
|
|
dst.fuseTypeId = src.fuseType().underlying();
|
|
dst.participantId = src.participantId();
|
|
}
|
|
|
|
void HandlerExplosionSingleCentral::onExplosionSingleCentralModifyRequest(const rti::core::SampleIdentity &cookie,
|
|
const ExplosionSingleCentralModifyRequest &request)
|
|
{
|
|
DEBUG_LOG(m_logger) << "onExplosionSingleCentralModifyRequest: " << request;
|
|
Core::FunctionReplyObject ret = explosionSingleCentralModifyRequest(request);
|
|
if (ret.error())
|
|
WARNING_LOG(m_logger) << ret();
|
|
m_mainHandler->dds()->fts()->explosionSingleCentralModifyReply(cookie, ret);
|
|
}
|
|
|
|
Core::FunctionReplyObject HandlerExplosionSingleCentral::explosionSingleCentralCreateRequest(const ExplosionSingleCentralModifyRequest &request)
|
|
{
|
|
Database::AesExplosionSingleCentral newData;
|
|
fillData(request, newData);
|
|
|
|
// check: effectStart > time(NULL) ?
|
|
|
|
ObjectExplosionSingleCentral *ifs(new ObjectExplosionSingleCentral(m_mainHandler, this));
|
|
connect(ifs, &ObjectExplosionSingleCentral::effectStateChanged, this, &HandlerExplosionSingleCentral::onEffectStateChanged);
|
|
|
|
const Core::FunctionReplyObject ret = ifs->createObject(newData);
|
|
if (ret.error())
|
|
{
|
|
delete ifs;
|
|
return ret;
|
|
}
|
|
|
|
m_objectMap.insert(ifs->id(), ifs);
|
|
if (ifs->isObjectInTrainingArea())
|
|
{
|
|
++m_areaCount;
|
|
DEBUG_LOG(m_logger) << "s_areaCount[AesType::AtExplosionSingleCentral] = " << m_areaCount;
|
|
}
|
|
connect(ifs, &ObjectExplosionSingleCentral::newAiv, this, &HandlerExplosionSingleCentral::newAiv);
|
|
connect(ifs, &ObjectExplosionSingleCentral::removeAiv, this, &HandlerExplosionSingleCentral::removeAiv);
|
|
return ret;
|
|
}
|
|
|
|
Core::FunctionReplyObject HandlerExplosionSingleCentral::explosionSingleCentralModifyRequest(const ExplosionSingleCentralModifyRequest &request)
|
|
{
|
|
Core::FunctionReplyObject ret;
|
|
if (request.id() == 0 || ((request.id() < 0) && !getObjectFromMap(m_objectMap, std::abs(request.id()), ret)))
|
|
return explosionSingleCentralCreateRequest(request);
|
|
|
|
ObjectExplosionSingleCentral *ifs = getObjectFromMap(m_objectMap, std::abs(request.id()), ret);
|
|
if (!ifs)
|
|
return ret;
|
|
|
|
Database::AesExplosionSingleCentral aes(ifs->data());
|
|
fillData(request, aes);
|
|
if (request.id() < 0 && checkStateForSfm(ifs))
|
|
{
|
|
DEBUG_LOG(m_logger) << "Overwrite single explostion Effect State for OC";
|
|
aes.effectStateId = AesEffectState::EsPrepared;
|
|
}
|
|
|
|
return ifs->updateObject(aes);
|
|
}
|
|
|
|
Core::FunctionReplyObject HandlerExplosionSingleCentral::explosionSingleCentralModifyGeometryRequest(const ExplosionSingleCentralModifyRequest &request)
|
|
{
|
|
Core::FunctionReplyObject ret;
|
|
ObjectExplosionSingleCentral *ifs = getObjectFromMap(m_objectMap, request.id(), ret);
|
|
if (!ifs)
|
|
return ret;
|
|
|
|
Database::AesExplosionSingleCentral aes(ifs->data());
|
|
fillGeometryData(request, aes);
|
|
|
|
return ifs->updateObject(aes);
|
|
}
|
|
|
|
void HandlerExplosionSingleCentral::onExplosionSingleCentralRemoveRequest(const rti::core::SampleIdentity &cookie,
|
|
const Core::RemoveElementRequest &request)
|
|
{
|
|
m_mainHandler->dds()->fts()->explosionSingleCentralRemoveReply(cookie, removeReply(&DatabaseInterface::removeAesExplosionSingleCentral, request));
|
|
}
|
|
|
|
Core::FunctionReplyObject HandlerExplosionSingleCentral::modifyPartyParticipant(qint32 itemId, qint32 partyId, qint32 participantId)
|
|
{
|
|
ObjectExplosionSingleCentral *ifs = m_objectMap.value(itemId);
|
|
if (!ifs)
|
|
return Core::FunctionReplyObject(itemId, tr_lts("dds", "SingleCentral Explosion with id %1 not found.")).arg(itemId);
|
|
AreaEffectSimulation::Database::AesExplosionSingleCentral aea(ifs->data());
|
|
aea.partyId = partyId;
|
|
aea.participantId= participantId;
|
|
return ifs->updateObject(aea);
|
|
}
|
|
|
|
} // namespace AreaEffectSimulation
|