Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* ISM Object Sound Area
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Filip Biedziak, NLE, 2020-08-05
|
||||
*/
|
||||
|
||||
#include "object_special_area.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QPolygonF>
|
||||
|
||||
namespace InfrastructureManagement
|
||||
{
|
||||
|
||||
ObjectSpecialArea::ObjectSpecialArea(MainHandler *mainHandler)
|
||||
: Base(mainHandler, getLogger("ObjectSpecialArea"))
|
||||
{
|
||||
}
|
||||
|
||||
ObjectSpecialArea::~ObjectSpecialArea()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
Core::FunctionReplyObject ObjectSpecialArea::createObject(const SpecialArea &data)
|
||||
{
|
||||
m_data = data;
|
||||
|
||||
onPublishData(); // publish data via DDS
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id());
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ObjectSpecialArea::updateObject(const SpecialArea &data)
|
||||
{
|
||||
m_data = data;
|
||||
DEBUG_LOG(m_logger) << "Data changed for Id: " << m_data.id();
|
||||
|
||||
onPublishData(); // publish data via DTS
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id());
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ObjectSpecialArea::removeObject()
|
||||
{
|
||||
if (!dts()->removeSpecialAreaByKey(m_data.id()))
|
||||
return Core::FunctionReplyObject(m_data.id(), tr_lts("dds", "SpecialArea with id %1 can not be removed from DDS")).arg(m_data.id());
|
||||
|
||||
return Core::FunctionReplyObject(m_data.id());
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------------------------------------------------------
|
||||
void ObjectSpecialArea::onPublishData()
|
||||
{
|
||||
INFO_LOG(m_logger) << "Publish IsmSpecialArea-data to dds (" << m_data.id() << ") ...";
|
||||
|
||||
if (!dts()->publish(m_data))
|
||||
ERROR_LOG(m_logger) << "Error publishing IsmSpecialArea-data to dds";
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
// Database::IsmSpecialArea => InfrastructureManagement::SpecialArea
|
||||
SpecialArea ObjectSpecialArea::toDdsData(const Database::IsmSpecialArea &dbData)
|
||||
{
|
||||
SpecialArea ddsData;
|
||||
|
||||
ddsData.id(dbData.id);
|
||||
ddsData.name(dbData.name.toStdString());
|
||||
ddsData.specialType(dbData.specialType.underlying());
|
||||
|
||||
const QJsonDocument doc(QJsonDocument::fromJson(dbData.polygon.toUtf8()));
|
||||
const QJsonObject obj(doc.object());
|
||||
const QJsonArray arrPoly = obj.value(QStringLiteral("polygon")).toArray();
|
||||
ddsData.polygon().reserve(arrPoly.size());
|
||||
for (const auto &ele : arrPoly)
|
||||
{
|
||||
const QJsonObject objSeg(ele.toObject());
|
||||
Core::GeoPosition2D element;
|
||||
element.lat(objSeg[QStringLiteral("lat")].toDouble());
|
||||
element.lon(objSeg[QStringLiteral("lon")].toDouble());
|
||||
ddsData.polygon().push_back(std::move(element));
|
||||
}
|
||||
//End elements
|
||||
|
||||
QPolygonF tmp;
|
||||
tmp.reserve(ddsData.polygon().size());
|
||||
for (const Core::GeoPosition2D &pos : qAsConst(ddsData.polygon()))
|
||||
tmp.push_back(QPointF(pos.lon(),pos.lat()));
|
||||
|
||||
QRectF boundingBox = tmp.boundingRect();
|
||||
ddsData.boundingBoxBottomLeft() = Core::GeoPosition2D(boundingBox.bottomLeft().x(), boundingBox.bottomLeft().y());
|
||||
ddsData.boundingBoxTopRight() = Core::GeoPosition2D(boundingBox.topRight().x(), boundingBox.topRight().y());
|
||||
|
||||
// init data not in db
|
||||
ddsData.isDeleted(false);
|
||||
ddsData.isUsed(false);
|
||||
|
||||
return ddsData;
|
||||
}
|
||||
} // namespace InfrastructureManagement
|
||||
|
||||
|
||||
Reference in new issue
Block a user