136 lines
4.5 KiB
C++
Executable File
136 lines
4.5 KiB
C++
Executable File
/**
|
|
* Handler for one indirect fire single object
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "object_air_support_impact.h"
|
|
#include "special_area_provider.h"
|
|
#include "Utils/polygons.h"
|
|
#include <QPolygonF>
|
|
|
|
namespace AreaEffectSimulation
|
|
{
|
|
|
|
ObjectAirSupportImpact::ObjectAirSupportImpact(MainHandler *mainHandler,
|
|
QObject *parent)
|
|
: ObjectBaseTmpl(mainHandler, QStringLiteral("AirSupportImpact"), parent)
|
|
{}
|
|
|
|
ObjectAirSupportImpact::~ObjectAirSupportImpact()
|
|
{
|
|
removeTopics();
|
|
}
|
|
|
|
Core::FunctionReplyObject ObjectAirSupportImpact::updateObject(const Database::AesAirSupportImpact &data)
|
|
{
|
|
Core::FunctionReplyObject ret = ObjectBaseTmpl::updateObject(data);
|
|
if (ret.error() || (isOnlyObjectNameModifiable() && (data.id > 0))) // data.id > 0 -> negative values from oc always get a full update
|
|
return ret;
|
|
|
|
// only allow some fields
|
|
auto tmpData(m_data);
|
|
tmpData.id = std::abs(data.id);
|
|
tmpData.name = data.name;
|
|
tmpData.effectStart = data.effectStart;
|
|
tmpData.impactPosition = data.impactPosition;
|
|
tmpData.participantId = data.participantId;
|
|
tmpData.partyId = data.partyId;
|
|
tmpData.chargeTypeId = data.chargeTypeId;
|
|
tmpData.flightTime = data.flightTime;
|
|
tmpData.properties = data.properties;
|
|
tmpData.effectStateId = data.effectStateId; // overwrite for oc
|
|
|
|
if (!m_mainHandler->db()->update(tmpData))
|
|
return Core::FunctionReplyObject(data.id, tr_lts("dds", "Error updating air support with id %1 in database.")).arg(m_data.id);
|
|
m_data = std::move(tmpData);
|
|
|
|
m_publishDataTimer->start();
|
|
checkEnterNewState();
|
|
|
|
return Core::FunctionReplyObject(data.id); // data not m_data for the possible negative id in the oc-laptop
|
|
}
|
|
|
|
double ObjectAirSupportImpact::chargeRadius() const
|
|
{
|
|
return m_mainHandler->dds()->pdmDtc()->impactRadius(m_data.chargeTypeId, m_data.igniterTypeId, m_data.igniterFunctionId);
|
|
}
|
|
|
|
void ObjectAirSupportImpact::onPublishData()
|
|
{
|
|
ObjectBaseTmpl::onPublishData();
|
|
|
|
if (!m_mainHandler->db()->update(m_data))
|
|
ERROR_LOG(m_logger) << "Error updating AesAirSupport-data in database";
|
|
|
|
AirSupportImpact ddsData(m_data.id,
|
|
m_data.name.toStdString(),
|
|
effectState() == AesEffectState::EsRemoved,
|
|
false,
|
|
partitionTimeMSec(),
|
|
{m_data.chargeTypeId,0,0},
|
|
m_data.effectDuration,
|
|
toOptional(toMSec(m_data.effectStart)),
|
|
m_data.effectStateId,
|
|
m_data.effectSourceId,
|
|
toOptional(m_data.partyId),
|
|
toOptional(m_data.participantId),
|
|
m_data.effectMarkingInTa,
|
|
m_data.externalId,
|
|
m_data.isCentral,
|
|
m_data.properties.toStdString(),
|
|
Core::GeoPosition2D(m_data.impactPosition.x(),
|
|
m_data.impactPosition.y()),
|
|
m_data.flightTime);
|
|
|
|
m_mainHandler->dds()->dts()->publish(ddsData);
|
|
publishAiv();
|
|
}
|
|
|
|
void ObjectAirSupportImpact::publishAiv()
|
|
{
|
|
const double cr = chargeRadius();
|
|
const QPolygonF poly = Polygons::airSupportImpact(m_data, cr);
|
|
const QRectF bounds(poly.boundingRect());
|
|
|
|
AesItemView aiv(m_aiv);
|
|
aiv.aesItemId(m_data.id);
|
|
aiv.chargeStruct().chargeTypeId(m_data.chargeTypeId);
|
|
ddsVecFromPoly(poly, aiv.form());
|
|
aiv.effectStart(toMSec(m_data.effectStart));
|
|
aiv.boundingBoxBottomLeft(Core::GeoPosition2D(bounds.bottomLeft().x(), bounds.bottomLeft().y()));
|
|
aiv.boundingBoxTopRight(Core::GeoPosition2D(bounds.topRight().x(), bounds.topRight().y()));
|
|
aiv.aesTypeId(AesType::AtAirSupportImpact);
|
|
aiv.effectStateId(effectState());
|
|
aiv.id(1000 * m_data.id + AesType::AtAirSupportImpact);
|
|
if (m_data.partyId != 0)
|
|
aiv.partyId(m_data.partyId);
|
|
|
|
checkIsCentralAndPublish(aiv.form(), m_aiv.form(), m_data.isCentral);
|
|
|
|
if (aiv != m_aiv)
|
|
{
|
|
aiv.sampleTime(partitionTimeMSec());
|
|
m_aiv = aiv;
|
|
m_mainHandler->dds()->dts()->publish(aiv);
|
|
emit newAiv(aiv);
|
|
}
|
|
}
|
|
|
|
void ObjectAirSupportImpact::removeTopics()
|
|
{
|
|
auto dts = m_mainHandler->dds()->dts();
|
|
dts->removeExplosionSingleByKey(m_data.id);
|
|
dts->removeAesItemViewByKey(1000 * m_data.id + AesType::AtAirSupportImpact);
|
|
emit removeAiv(m_data.id);
|
|
}
|
|
|
|
QPolygonF ObjectAirSupportImpact::generateForm()
|
|
{
|
|
const double cr = chargeRadius();
|
|
return Polygons::airSupportImpact(m_data, cr);
|
|
}
|
|
|
|
} // Namespace AreaEffectSimulation
|