/** * Handler for infrastructure data * $Id$ * $HeadURL$ * $Author: * Created by hjl, SLSE, 2016-09-21 */ #include "handler_infrastructure_data.h" #include #include #include using namespace MeteoDataManagement; HandlerInfrastructureData::HandlerInfrastructureData(const std::shared_ptr &ddsHandler, const std::shared_ptr &handlerMeteoDataUnits, QObject *parent) : QObject(parent) , m_ddsHandler(ddsHandler) , m_handlerMeteoDataUnits(handlerMeteoDataUnits) , m_logger(getLogger("HandlerInfrastructureData")) { } // end of ctor() //----------------------------------------------------------------------------- bool HandlerInfrastructureData::init() { INFO_LOG(m_logger) << "start init() DTC InfrastructureManagement "; // DTC InfrastructureManagement m_dtc = InfrastructureManagement::Interface::Dtc::create(m_ddsHandler->dds()); if (m_dtc == nullptr) { ERROR_LOG(m_logger) << "Could not create DTC InfrastructureManagement"; return false; } if (!m_dtc->enableMountingPointAsset() || !m_dtc->enableMainStructureElement()) { ERROR_LOG(m_logger) << "init() DTC InfrastructureManagement failed"; return false; } { // InstrumentationAsset mit ContentFilter const dds::topic::Filter filter("mountingPointTypeId = 'MeteoDataUnit'"); m_dtcInstrumentationAssetCF.reset(m_ddsHandler->dds()->createDTC(filter)); if (!m_dtcInstrumentationAssetCF) { ERROR_LOG(m_logger) << "init() DTC InfrastructureManagement failed"; return false; } m_dtcInstrumentationAssetCF->setSubscriberCallback([this](const InfrastructureManagement::InstrumentationAsset &data, DataModification modType) { onAssetChanged(data, modType); }); using DATA = InfrastructureManagement::InstrumentationAsset; using LOANED_DATA = rti::sub::LoanedSample; for (const LOANED_DATA &sample : m_dtcInstrumentationAssetCF->readAlive()) onAssetChanged(sample.data(), DataModification::eAdded); } // Subsribe for MountingPointChanged (um ueber StructureElementId die Position der meteo data units zu ermitteln) connect(m_dtc.get(), &InfrastructureManagement::Interface::Dtc::mountingPointAssetChanged, this, &HandlerInfrastructureData::onMountingPointAssetChanged); // Subsribe for MainStructureElementChanged (Postion der Gebäude) connect(m_dtc.get(), &InfrastructureManagement::Interface::Dtc::mainStructureElementChanged, this, &HandlerInfrastructureData::onMainStructureElementChanged); m_dtc->mountingPointAssets([this](const InfrastructureManagement::MountingPointAsset &mpa) { onMountingPointAssetChanged(mpa); }); m_dtc->mainStructureElements([this](const InfrastructureManagement::MainStructureElement &mse) { onMainStructureElementChanged(mse); }); return true; } // end of init() //----------------------------------------------------------------------------- void HandlerInfrastructureData::onAssetChanged(const InfrastructureManagement::InstrumentationAsset &data, DataModification modType) { // nur die MountingPointType::MeteoDataUnit bearbeiten... if (data.mountingPointTypeId != InfrastructureManagement::MountingPointType::MeteoDataUnit) return; INFO_LOG(m_logger) << "onAssetChanged()" << " assetId: " << data.id << " mountingPointTypeId: " << data.mountingPointTypeId << " name: " << data.name; switch (modType) { case DataModification::eAdded: case DataModification::eModified: m_handlerMeteoDataUnits->addMeteoDataUnit(data); break; case DataModification::eRemoved: m_handlerMeteoDataUnits->removeMeteoDataUnit(data); break; } } // end of onAssetChanged() //----------------------------------------------------------------------------- void HandlerInfrastructureData::onMountingPointAssetChanged(const InfrastructureManagement::MountingPointAsset &data, DataModification modType) { // zugehoerige StructureElementId ablegen switch (modType) { case DataModification::eAdded: case DataModification::eModified: m_mountingPointAssetsMap.insert(data.assetId, data.structureElementId); break; case DataModification::eRemoved: m_mountingPointAssetsMap.remove(data.assetId); break; } } // end of onMountingPointAssetChanged() //----------------------------------------------------------------------------- void HandlerInfrastructureData::onMainStructureElementChanged(const InfrastructureManagement::MainStructureElement &data, DataModification modType) { switch (modType) { case DataModification::eAdded: case DataModification::eModified: m_mainStructureElements.insert(data.id, data); break; case DataModification::eRemoved: m_mainStructureElements.remove(data.id); break; } } // end of onMountingPointAssetChanged() //----------------------------------------------------------------------------- Core::GeoPosition HandlerInfrastructureData::getStructureElementPosition(int assetId) const { const int seId = m_mountingPointAssetsMap.value(assetId); if (seId <= 0) { WARNING_LOG(m_logger) << "Could not find mountingPointAsset for asset id " << assetId; return Core::GeoPosition(); } // Go through all MainStructureElements and search structureElementId for (const InfrastructureManagement::MainStructureElement &mse : m_mainStructureElements) { for (const InfrastructureManagement::StructureElement &se : mse.elements) { if (se.id == seId) return mse.geoPosition; } } return Core::GeoPosition(); } // end of getStructureElementPosition() //-----------------------------------------------------------------------------