162 lines
4.7 KiB
C++
Executable File
162 lines
4.7 KiB
C++
Executable File
/**
|
|
* Object from database for technical areas
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* created by: Philipp Dassow, SLEA, 2017-06-06
|
|
*/
|
|
|
|
#include "object_recon_area.h"
|
|
#include "special_area_provider.h"
|
|
|
|
#include "Utils/polygons.h"
|
|
#include <QPolygonF>
|
|
#include <QTimer>
|
|
|
|
namespace AreaEffectSimulation
|
|
{
|
|
|
|
ObjectReconArea::ObjectReconArea(MainHandler *mainHandler,
|
|
QObject *parent)
|
|
: ObjectBaseTmpl(mainHandler, QStringLiteral("ReconArea"), parent)
|
|
{
|
|
}
|
|
|
|
ObjectReconArea::~ObjectReconArea()
|
|
{
|
|
removeTopics();
|
|
}
|
|
|
|
Core::FunctionReplyObject ObjectReconArea::createObject(const Database::AesReconArea &data)
|
|
{
|
|
Core::FunctionReplyObject ret;
|
|
|
|
if (ret.error())
|
|
return ret;
|
|
|
|
ret = ObjectBaseTmpl::createObject(data);
|
|
return ret;
|
|
}
|
|
|
|
Core::FunctionReplyObject ObjectReconArea::updateObject(const Database::AesReconArea &data)
|
|
{
|
|
Core::FunctionReplyObject ret = ObjectBaseTmpl::updateObject(data);
|
|
if (ret.error() || isOnlyObjectNameModifiable())
|
|
return ret;
|
|
|
|
// only allow some fields
|
|
auto tmpData(m_data);
|
|
tmpData.name = data.name;
|
|
tmpData.position = data.position;
|
|
tmpData.width = data.width;
|
|
tmpData.height = data.height;
|
|
tmpData.rotationAngle = data.rotationAngle;
|
|
tmpData.participantId = data.participantId;
|
|
tmpData.partyId = data.partyId;
|
|
tmpData.chargeTypeId = data.chargeTypeId;
|
|
tmpData.effectDuration = data.effectDuration;
|
|
tmpData.effectMarkingInTa = data.effectMarkingInTa;
|
|
tmpData.purpose = data.purpose;
|
|
tmpData.effectStateId = data.effectStateId; // overwrite for oc
|
|
tmpData.properties = data.properties;
|
|
|
|
if (!m_mainHandler->db()->update(tmpData))
|
|
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "Error updating recon area with id %1 in database.")).arg(m_data.id);
|
|
|
|
m_data = std::move(tmpData);
|
|
|
|
m_publishDataTimer->start();
|
|
|
|
return Core::FunctionReplyObject(m_data.id);
|
|
}
|
|
|
|
Core::FunctionReplyObject ObjectReconArea::removeObject()
|
|
{
|
|
return ObjectBaseTmpl::removeObject();
|
|
}
|
|
|
|
void ObjectReconArea::setEffectState(AesEffectState newState)
|
|
{
|
|
ObjectBaseTmpl::setEffectState(newState);
|
|
}
|
|
|
|
void ObjectReconArea::onPublishData()
|
|
{
|
|
ObjectBaseTmpl::onPublishData();
|
|
|
|
if (!m_mainHandler->db()->update(m_data))
|
|
ERROR_LOG(m_logger) << "Error updating AesReconArea-data in database";
|
|
|
|
ReconArea 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,
|
|
dds::core::optional<int32_t>(),
|
|
dds::core::optional<int32_t>(),
|
|
m_data.effectMarkingInTa,
|
|
m_data.externalId,
|
|
m_data.isCentral,
|
|
m_data.properties.toStdString(),
|
|
Area(Core::GeoPosition2D(m_data.position.x(),
|
|
m_data.position.y()),
|
|
m_data.width,
|
|
m_data.height,
|
|
m_data.rotationAngle),
|
|
m_data.purpose.toStdString()
|
|
);
|
|
m_mainHandler->dds()->dts()->publish(ddsData);
|
|
publishAiv();
|
|
}
|
|
|
|
void ObjectReconArea::publishAiv()
|
|
{
|
|
// Todo: calculate unique id.
|
|
// Better than aiv.id(1000 * aesItemId + AesType::AtFunctionalArea);
|
|
|
|
const QPolygonF poly = Polygons::reconArea(m_data);
|
|
const QRectF bounds(poly.boundingRect());
|
|
|
|
AesItemView aiv(m_aiv);
|
|
aiv.aesItemId(m_data.id);
|
|
aiv.chargeStruct().chargeTypeId(m_data.chargeTypeId);
|
|
aiv.effectStart(toMSec(m_data.effectStart));
|
|
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::AtReconArea);
|
|
aiv.effectStateId(effectState());
|
|
aiv.id(1000 * m_data.id + AesType::AtReconArea);
|
|
|
|
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 ObjectReconArea::removeTopics()
|
|
{
|
|
auto dts = m_mainHandler->dds()->dts();
|
|
dts->removeReconAreaByKey(m_data.id);
|
|
dts->removeAesItemViewByKey(1000 * m_data.id + AesType::AtReconArea);
|
|
emit removeAiv(m_data.id);
|
|
}
|
|
|
|
QPolygonF ObjectReconArea::generateForm()
|
|
{
|
|
return Polygons::reconArea(m_data);
|
|
}
|
|
|
|
} // Namespace AreaEffectSimulation
|
|
|