179 lines
7.6 KiB
C++
Executable File
179 lines
7.6 KiB
C++
Executable File
/**
|
|
* Handler for the HMI language
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include "object_aes_data.h"
|
|
#include "effect_show_mine_area.h"
|
|
|
|
#include "initialization.h"
|
|
#include <QLineF>
|
|
|
|
namespace EffectShowManagement
|
|
{
|
|
//=============================================================================
|
|
ObjectAesData::ObjectAesData(Initialization *mainHandler,
|
|
QObject *parent)
|
|
: QObject(parent)
|
|
, m_mainHandler(mainHandler)
|
|
, m_logger(getLogger("ObjectAesData"))
|
|
{
|
|
}
|
|
//=============================================================================
|
|
|
|
Core::FunctionReplyObject ObjectAesData::createObject(const Database::EsmAesData &data)
|
|
{
|
|
m_data = data;
|
|
|
|
if (!m_mainHandler->db()->insert(m_data))
|
|
return Core::FunctionReplyObject(m_data.idAes, tr_lts("dds", "Error inserting EsmAesData into database."));
|
|
|
|
DEBUG_LOG(m_logger) << "New EsmAesData Id: " << m_data.idAes;
|
|
return Core::FunctionReplyObject(m_data.idAes);
|
|
}
|
|
//=============================================================================
|
|
Core::FunctionReplyObject ObjectAesData::updateObject(const Database::EsmAesData &data)
|
|
{
|
|
m_data = data;
|
|
|
|
if (!m_mainHandler->db()->update(m_data))
|
|
return Core::FunctionReplyObject(m_data.idAes, tr_lts("dds", "Error updating EsmAesData into database"));
|
|
|
|
DEBUG_LOG(m_logger) << "Data changed for EsmAesData Id: " << m_data.idAes;
|
|
|
|
return Core::FunctionReplyObject(m_data.idAes);
|
|
}
|
|
//=============================================================================
|
|
Core::FunctionReplyObject ObjectAesData::removeObject()
|
|
{
|
|
if (!m_mainHandler->db()->removeEsmAesData(m_data.idAes))
|
|
return Core::FunctionReplyObject(m_data.idAes, tr_lts("dds", "EsmAesData %1 can not be removed")).arg(m_data.idAes);
|
|
|
|
return Core::FunctionReplyObject(m_data.idAes);
|
|
}
|
|
//=============================================================================
|
|
bool ObjectAesData::areaChanged(const Database::EsmAesData &data) const
|
|
{
|
|
return (!qFuzzyCompare(m_data.position.x(), data.position.x()) ||
|
|
!qFuzzyCompare(m_data.position.y(), data.position.y()) ||
|
|
!qFuzzyCompare(m_data.width, data.width) ||
|
|
!qFuzzyCompare(m_data.depth, data.depth) ||
|
|
!qFuzzyCompare(m_data.rotationAngle, data.rotationAngle) ||
|
|
(m_data.volley != data.volley)); //shots change rewrite ?
|
|
}
|
|
|
|
//=============================================================================
|
|
bool ObjectAesData::dataChanged(const Database::EsmAesData &data) const
|
|
{
|
|
if (statusPaused(data) || statusContinued(data) || statusExpired(data))
|
|
return false;
|
|
|
|
if (m_data.nameAes != data.nameAes)
|
|
return true;
|
|
|
|
DEBUG_LOG(m_logger) << "Data Volley: " << data.volley << " old: " << m_data.volley;
|
|
return (m_data.chargeTypeId != data.chargeTypeId)
|
|
|| (m_data.effectStart != data.effectStart)
|
|
|| (m_data.effectStateId == AreaEffectSimulation::AesEffectState::EsFired)
|
|
|| (m_data.effectDuration != data.effectDuration);
|
|
}
|
|
//=============================================================================
|
|
bool ObjectAesData::statusPaused(const Database::EsmAesData &data) const
|
|
{
|
|
return (m_data.effectStateId != AreaEffectSimulation::AesEffectState_def::EsPaused) &&
|
|
(data.effectStateId == AreaEffectSimulation::AesEffectState_def::EsPaused);
|
|
}
|
|
//=============================================================================
|
|
bool ObjectAesData::statusContinued(const Database::EsmAesData &data) const
|
|
{
|
|
return (data.effectStateId == AreaEffectSimulation::AesEffectState_def::EsActivated) &&
|
|
(m_data.effectStart != data.effectStart); // false, if the scheduled start time reached
|
|
}
|
|
bool ObjectAesData::statusExpired(const Database::EsmAesData &data) const
|
|
{
|
|
return (data.effectStateId == AreaEffectSimulation::AesEffectState_def::EsExpired);
|
|
}
|
|
|
|
//=============================================================================
|
|
Database::EsmAesData ObjectAesData::asEsmAesData(const AreaEffectSimulation::ExplosionArea &data)
|
|
{
|
|
Database::EsmAesData res;
|
|
res.idAes = data.id();
|
|
res.nameAes = QString::fromStdString(data.name());
|
|
res.effectStateId = data.effectStateId().underlying();
|
|
res.position = QPointF(data.area().cornerBottomLeft().lon(), data.area().cornerBottomLeft().lat());
|
|
res.rotationAngle = data.area().rotation();
|
|
res.depth = data.area().height();
|
|
res.width = data.area().width();
|
|
res.effectStart = data.effectStart().is_set() ? data.effectStart().get() : 0;
|
|
res.effectDuration = data.effectDuration();
|
|
res.chargeTypeId = data.chargeStruct().chargeTypeId();
|
|
res.volley = data.cannonCount() * data.cannonRounds();
|
|
return res;
|
|
}
|
|
Database::EsmAesData ObjectAesData::asEsmAesData(const AreaEffectSimulation::ExplosionCluster &data)
|
|
{
|
|
Database::EsmAesData res;
|
|
res.idAes = data.id();
|
|
res.nameAes = QString::fromStdString(data.name());
|
|
res.effectStateId = data.effectStateId().underlying();
|
|
res.position = QPointF(data.area().cornerBottomLeft().lon(), data.area().cornerBottomLeft().lat());
|
|
res.rotationAngle = data.area().rotation();
|
|
res.depth = data.area().height();
|
|
res.width = data.area().width();
|
|
res.effectStart = data.effectStart().is_set() ? data.effectStart().get() : 0;
|
|
res.effectDuration = data.effectDuration();
|
|
res.chargeTypeId = data.chargeStruct().chargeTypeId();
|
|
res.volley = data.impactCount(); //cannonCount() * data.cannonRounds();
|
|
return res;
|
|
}
|
|
|
|
Database::EsmAesData ObjectAesData::asEsmAesData(const AreaEffectSimulation::EffectCluster &data)
|
|
{
|
|
Database::EsmAesData res;
|
|
res.idAes = data.id();
|
|
res.nameAes = QString::fromStdString(data.name());
|
|
res.effectStateId = data.effectStateId().underlying();
|
|
res.position = QPointF(data.area().cornerBottomLeft().lon(), data.area().cornerBottomLeft().lat());
|
|
res.rotationAngle = data.area().rotation();
|
|
res.depth = data.area().height();
|
|
res.width = data.area().width();
|
|
res.effectStart = data.effectStart().is_set() ? data.effectStart().get() : 0;
|
|
res.effectDuration = data.effectDuration();
|
|
res.chargeTypeId = data.chargeStruct().chargeTypeId();
|
|
res.volley = 0;
|
|
for (const auto &effector : data.effectors())
|
|
{
|
|
res.volley += effector.chargeAmount();
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
//=============================================================================
|
|
Database::EsmAesData ObjectAesData::asEsmAesData(const AreaEffectSimulation::MineArea &data)
|
|
{
|
|
Database::EsmAesData res;
|
|
const AreaEffectSimulation::MineSegment &segment = EffectShowManagement::EffectShowMineArea::getEffectShowSegment(data);
|
|
LtsCoordTrans::UtmCoordinate startPositionUtm = LtsCoordTrans::UtmCoordinate::fromGeographic({segment.positionStart().lon(), segment.positionStart().lat()});
|
|
LtsCoordTrans::UtmCoordinate endPositionUtm = LtsCoordTrans::UtmCoordinate::fromGeographic({segment.positionEnd().lon(), segment.positionEnd().lat()}, startPositionUtm.zone);
|
|
|
|
const QLineF line({startPositionUtm.x, startPositionUtm.y}, {endPositionUtm.x, endPositionUtm.y});
|
|
res.width = line.length();
|
|
res.idAes = data.id();
|
|
res.nameAes = QString::fromStdString(data.name());
|
|
res.effectStateId = data.effectStateId().underlying();
|
|
res.position = QPointF(segment.positionStart().lon(), segment.positionStart().lat());
|
|
res.depth = data.width();
|
|
res.effectStart = data.effectStart().is_set() ? data.effectStart().get() : 0;
|
|
res.effectDuration = data.effectDuration();
|
|
res.chargeTypeId = data.chargeStruct().chargeTypeId();
|
|
res.volley = 18;
|
|
return res;
|
|
}
|
|
//=============================================================================
|
|
|
|
} // Namespace EffectShowManagement
|