Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+230
@@ -0,0 +1,230 @@
|
||||
/**
|
||||
* Handler for the HMI language
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "object_booby_trap.h"
|
||||
#include "meteo_data_provider.h"
|
||||
#include "Utils/polygons.h"
|
||||
|
||||
#include <QPolygonF>
|
||||
#include <QTimer>
|
||||
|
||||
namespace AreaEffectSimulation
|
||||
{
|
||||
|
||||
ObjectBoobyTrap::ObjectBoobyTrap(MainHandler *mainHandler,
|
||||
QObject *parent)
|
||||
: ObjectBaseTmpl(mainHandler, QStringLiteral("BoobyTrap"), parent)
|
||||
, m_aivUpdateTimer(new QTimer(this))
|
||||
{
|
||||
m_aivUpdateTimer->setInterval(1 * 1000); // every second - really needed?
|
||||
m_aivUpdateTimer->setTimerType(Qt::VeryCoarseTimer);
|
||||
connect(m_aivUpdateTimer, &QTimer::timeout,
|
||||
this, &ObjectBoobyTrap::onUpdateAiv);
|
||||
}
|
||||
|
||||
ObjectBoobyTrap::~ObjectBoobyTrap()
|
||||
{
|
||||
removeTopics();
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ObjectBoobyTrap::createObject(const Database::AesBoobyTrap &data)
|
||||
{
|
||||
return ObjectBaseTmpl::createObject(data);
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ObjectBoobyTrap::updateObject(const Database::AesBoobyTrap &data)
|
||||
{
|
||||
Core::FunctionReplyObject ret = ObjectBaseTmpl::updateObject(data);
|
||||
Database::AesBoobyTrap tmpData(m_data);
|
||||
if (ret.error())
|
||||
return ret;
|
||||
|
||||
if (data.triggered && !m_data.triggered)
|
||||
{
|
||||
tmpData.triggered = data.triggered;
|
||||
tmpData.effectStateId = data.effectStateId;
|
||||
tmpData.effectDuration = data.effectDuration;
|
||||
tmpData.properties = data.properties;
|
||||
}
|
||||
else if (isOnlyObjectNameModifiable() && (data.id > 0)) // data.id > 0 -> negative values from oc always get a full update)
|
||||
return ret;
|
||||
else
|
||||
{
|
||||
// only allow some fields
|
||||
tmpData.id = std::abs(data.id);
|
||||
tmpData.name = data.name;
|
||||
tmpData.effectStart = data.effectStart;
|
||||
tmpData.effectDuration = data.effectDuration;
|
||||
tmpData.impactPosition = data.impactPosition;
|
||||
tmpData.impactRadius = data.impactRadius;
|
||||
tmpData.triggerRadius = data.triggerRadius;
|
||||
tmpData.rotationAngle = data.rotationAngle;
|
||||
tmpData.centralAngle = data.centralAngle;
|
||||
tmpData.participantId = data.participantId;
|
||||
tmpData.partyId = data.partyId;
|
||||
tmpData.chargeTypeId = data.chargeTypeId;
|
||||
tmpData.effectStateId = data.effectStateId; // overwrite for oc
|
||||
tmpData.triggered = data.triggered;
|
||||
tmpData.properties = data.properties;
|
||||
}
|
||||
|
||||
if (!m_mainHandler->db()->update(tmpData))
|
||||
return Core::FunctionReplyObject(data.id, tr_lts("dds", "Error updating booby trap 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
|
||||
}
|
||||
|
||||
bool ObjectBoobyTrap::removeObjectFromDb()
|
||||
{
|
||||
return m_mainHandler->db()->removeAesBoobyTrap(m_data.id);
|
||||
|
||||
}
|
||||
|
||||
void ObjectBoobyTrap::setEffectState(AesEffectState newState)
|
||||
{
|
||||
if (newState == AesEffectState::EsActivated)
|
||||
{
|
||||
m_aivUpdateTimer->start();
|
||||
}
|
||||
else
|
||||
m_aivUpdateTimer->stop();
|
||||
|
||||
ObjectBaseTmpl::setEffectState(newState);
|
||||
}
|
||||
|
||||
ProjectDataManagement::VolatilityType ObjectBoobyTrap::volatilityType() const
|
||||
{
|
||||
return m_mainHandler->dds()->pdmDtc()->volatilityTypeId(m_data.chargeTypeId, m_data.igniterTypeId, m_data.igniterFunctionId);
|
||||
}
|
||||
|
||||
void ObjectBoobyTrap::onUpdateAiv()
|
||||
{
|
||||
if (effectState() != AesEffectState::EsActivated)
|
||||
{
|
||||
m_aivUpdateTimer->stop();
|
||||
return;
|
||||
}
|
||||
publishAiv();
|
||||
}
|
||||
|
||||
|
||||
void ObjectBoobyTrap::onPublishData()
|
||||
{
|
||||
ObjectBaseTmpl::onPublishData();
|
||||
|
||||
if (!m_mainHandler->db()->update(m_data))
|
||||
ERROR_LOG(m_logger) << "Error updating AesBoobyTrap-data in database";
|
||||
|
||||
BoobyTrap 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.impactRadius,
|
||||
m_data.triggerRadius,
|
||||
toOptional(m_data.rotationAngle),
|
||||
toOptional(m_data.centralAngle),
|
||||
m_data.triggered);
|
||||
m_mainHandler->dds()->dts()->publish(ddsData);
|
||||
publishAiv();
|
||||
}
|
||||
|
||||
void ObjectBoobyTrap::publishAiv()
|
||||
{
|
||||
DEBUG_LOG(m_logger)<<LOGFUNCTION
|
||||
<<" trigger: "<<data().triggerRadius
|
||||
<<" impact: "<<data().impactRadius
|
||||
<<" position: "<<data().impactPosition.x()<<","<<data().impactPosition.y()
|
||||
<<"| angle:"<<data().centralAngle
|
||||
<<" rotation:"<<data().rotationAngle;
|
||||
// BoobyTrap Trigger
|
||||
{
|
||||
const QPolygonF poly = Polygons::boobyTrapCake(data(), data().triggerRadius);
|
||||
const QRectF bounds(poly.boundingRect());
|
||||
|
||||
AesItemView aiv(m_aiv);
|
||||
aiv.aesItemId(m_data.id);
|
||||
aiv.effectStart(toMSec(m_data.effectStart));
|
||||
aiv.chargeStruct().chargeTypeId(m_data.chargeTypeId);
|
||||
ddsVecFromPoly(poly, aiv.form());
|
||||
aiv.boundingBoxBottomLeft(Core::GeoPosition2D(bounds.bottomLeft().x(), bounds.bottomLeft().y()));
|
||||
aiv.boundingBoxTopRight(Core::GeoPosition2D(bounds.topRight().x(), bounds.topRight().y()));
|
||||
aiv.aesTypeId(AesType::AtBoobyTrap);
|
||||
aiv.effectStateId(data().effectStateId);
|
||||
aiv.id(1000 * m_data.id + AesType::AtBoobyTrap);
|
||||
|
||||
if (m_data.partyId != 0)
|
||||
aiv.partyId(m_data.partyId);
|
||||
|
||||
if (aiv != m_aiv)
|
||||
{
|
||||
aiv.sampleTime(partitionTimeMSec());
|
||||
m_aiv = aiv;
|
||||
m_mainHandler->dds()->dts()->publish(aiv);
|
||||
emit newAiv(m_aiv);
|
||||
}
|
||||
}
|
||||
|
||||
// BoobyTrap Impact
|
||||
{
|
||||
const QPolygonF poly = Polygons::boobyTrapCake(data(), data().impactRadius);
|
||||
const QRectF bounds(poly.boundingRect());
|
||||
AesItemView aiv2(m_aiv2);
|
||||
aiv2.aesItemId(m_data.id);
|
||||
aiv2.effectStart(toMSec(m_data.effectStart));
|
||||
aiv2.chargeStruct().chargeTypeId(m_data.chargeTypeId);
|
||||
ddsVecFromPoly(poly, aiv2.form());
|
||||
aiv2.boundingBoxBottomLeft(Core::GeoPosition2D(bounds.bottomLeft().x(), bounds.bottomLeft().y()));
|
||||
aiv2.boundingBoxTopRight(Core::GeoPosition2D(bounds.topRight().x(), bounds.topRight().y()));
|
||||
aiv2.aesTypeId(AesType::AtBoobyTrapSecondary);
|
||||
aiv2.effectStateId(data().effectStateId);
|
||||
aiv2.id(1000 * m_data.id + AesType::AtBoobyTrapSecondary);
|
||||
|
||||
if (m_data.partyId != 0)
|
||||
aiv2.partyId(m_data.partyId);
|
||||
if (aiv2 != m_aiv2)
|
||||
{
|
||||
aiv2.sampleTime(partitionTimeMSec());
|
||||
m_aiv2 = aiv2;
|
||||
m_mainHandler->dds()->dts()->publish(aiv2);
|
||||
emit newAiv(aiv2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ObjectBoobyTrap::removeTopics()
|
||||
{
|
||||
auto dts = m_mainHandler->dds()->dts();
|
||||
dts->removeBoobyTrapByKey(m_data.id);
|
||||
dts->removeAesItemViewByKey(1000 * m_data.id + AesType::AtBoobyTrap);
|
||||
emit removeAiv(m_data.id);
|
||||
}
|
||||
|
||||
QPolygonF ObjectBoobyTrap::generateForm()
|
||||
{
|
||||
// BoobyTrap is default isCentral
|
||||
return QPolygonF();
|
||||
}
|
||||
} // Namespace AreaEffectSimulation
|
||||
Reference in new issue
Block a user