158 lines
4.6 KiB
C++
Executable File
158 lines
4.6 KiB
C++
Executable File
/**
|
|
* Object from database for technical areas
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* created by: Philipp Dassow, SLEA, 2017-06-06
|
|
*/
|
|
|
|
#include "object_technical_area.h"
|
|
#include "special_area_provider.h"
|
|
|
|
#include "Utils/polygons.h"
|
|
#include "handler_charge_administration.h"
|
|
#include <QPolygonF>
|
|
#include <QTimer>
|
|
|
|
namespace AreaEffectSimulation
|
|
{
|
|
|
|
ObjectTechnicalArea::ObjectTechnicalArea(MainHandler *mainHandler,
|
|
QObject *parent)
|
|
: ObjectBaseTmpl(mainHandler, QStringLiteral("TechnicalArea"), parent)
|
|
{
|
|
}
|
|
|
|
ObjectTechnicalArea::~ObjectTechnicalArea()
|
|
{
|
|
removeTopics();
|
|
}
|
|
|
|
Core::FunctionReplyObject ObjectTechnicalArea::createObject(const Database::AesTechnicalArea &data)
|
|
{
|
|
Core::FunctionReplyObject ret;
|
|
|
|
if (ret.error())
|
|
return ret;
|
|
|
|
ret = ObjectBaseTmpl::createObject(data);
|
|
return ret;
|
|
}
|
|
|
|
Core::FunctionReplyObject ObjectTechnicalArea::updateObject(const Database::AesTechnicalArea &data)
|
|
{
|
|
Core::FunctionReplyObject ret = ObjectBaseTmpl::updateObject(data);
|
|
if (ret.error())
|
|
return ret;
|
|
|
|
// only allow some fields
|
|
auto tmpData(m_data);
|
|
tmpData.name = data.name;
|
|
tmpData.typeId = data.typeId;
|
|
tmpData.position = data.position;
|
|
tmpData.width = data.width;
|
|
tmpData.length = data.length;
|
|
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 technical 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 ObjectTechnicalArea::removeObject()
|
|
{
|
|
Core::FunctionReplyObject ret = ObjectBaseTmpl::removeObject();
|
|
return ret;
|
|
}
|
|
|
|
void ObjectTechnicalArea::setEffectState(AesEffectState newState)
|
|
{
|
|
ObjectBaseTmpl::setEffectState(newState);
|
|
}
|
|
|
|
void ObjectTechnicalArea::onPublishData()
|
|
{
|
|
ObjectBaseTmpl::onPublishData();
|
|
|
|
if (!m_mainHandler->db()->update(m_data))
|
|
ERROR_LOG(m_logger) << "Error updating AesTechnicalArea-data in database";
|
|
|
|
TechnicalArea 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(),
|
|
AreaEffectSimulation::AesTechnicalAreaType(m_data.typeId),
|
|
Area(Core::GeoPosition2D(m_data.position.x(),
|
|
m_data.position.y()),
|
|
m_data.width,
|
|
m_data.length,
|
|
0.0)
|
|
);
|
|
m_mainHandler->dds()->dts()->publish(ddsData);
|
|
publishAiv();
|
|
}
|
|
|
|
void ObjectTechnicalArea::publishAiv()
|
|
{
|
|
// Todo: calculate unique id.
|
|
// Better than aiv.id(1000 * aesItemId + AesType::AtFunctionalArea);
|
|
|
|
const QPolygonF poly = Polygons::technicalArea(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::AtTechnicalArea);
|
|
aiv.effectStateId(effectState());
|
|
aiv.id(1000 * m_data.id + AesType::AtTechnicalArea);
|
|
|
|
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 ObjectTechnicalArea::removeTopics()
|
|
{
|
|
auto dts = m_mainHandler->dds()->dts();
|
|
dts->removeTechnicalAreaByKey(m_data.id);
|
|
dts->removeAesItemViewByKey(1000 * m_data.id + AesType::AtTechnicalArea);
|
|
emit removeAiv(m_data.id);
|
|
}
|
|
|
|
QPolygonF ObjectTechnicalArea::generateForm()
|
|
{
|
|
return Polygons::technicalArea(m_data);
|
|
}
|
|
|
|
} // Namespace AreaEffectSimulation
|
|
|