/** * @RDE_HEADER@ * The AlarmToMap class handles the transfer from MainStructureElement-DDS-Data to a representation on the map * $Id$ * $HeadURL$ * $Author$ * Created by Norbert Thoden, NLSE, 2018-06-26 */ // Own #include "alarm_to_map.h" #include #include // Qt #include #include using namespace SituationMap; QImage renderEmergencyCallSymbol() { int size = 200; QImage image(size, size, QImage::Format_ARGB32); image.fill(Qt::transparent); QPainter painter(&image); painter.setRenderHint(QPainter::Antialiasing); QPen pen(Qt::white); pen.setWidth(10); painter.setPen(pen); painter.setBrush(QBrush(Qt::red)); painter.drawEllipse(QPointF(image.rect().center()), image.rect().width() * 0.45, image.rect().height() * 0.45); painter.setPen(QPen(Qt::white)); QFont font = painter.font(); font.setBold(true); font.setPixelSize(75); painter.setFont(font); QPointF pos(image.width() * 0.125, image.height() * 0.625); painter.drawText(pos, QLatin1String("SOS")); return image; } bool AlarmToMap::init(PluginProvider *pluginProvider) { if (!pluginProvider) return false; m_pluginProvider = pluginProvider; DEBUG_LOG(m_logger) << LOGFUNCTION << " exerciseId=" << m_pluginProvider->exerciseId(); m_almDtc = m_pluginProvider->almDtc(); // FilterManagement: FilterClass::init(m_pluginProvider); return true; } bool AlarmToMap::run() { DEBUG_LOG(m_logger) << "Starting to run"; this->stop(); if (m_almDtc) { connect(m_almDtc.get(), &AlarmManagement::Interface::Dtc::notificationChanged, this, &AlarmToMap::handleChanged, Qt::UniqueConnection); // get: m_almDtc->notifications([this](const AlarmManagement::Notification & data) { handleChanged(data, DataModification::eAdded); }); } return true; } void AlarmToMap::stop() { DEBUG_LOG(m_logger) << LOGFUNCTION << "Stopping"; if (m_almDtc) m_almDtc->disconnect(this); } /* bool AlarmToMap::unifiedMapObjectData(UniqueMapId uniqueMapId, UnifiedMapObjectData &umodOut) const { if (!m_almDtc) return false; int32_t simIdOut = -1; if (!this->uniqueMapId2SimId(uniqueMapId, simIdOut)) return false; umodOut = UnifiedMapObjectData(); RefPointer mapObj = this->getMapObjectOfUniqueMapId(uniqueMapId); if (mapObj.valid()) umodOut.m_image = mapObj->previewImage(); const auto cb = [simIdOut, &umodOut](const AlarmManagement::Notification & data) -> bool { if (data.id() == simIdOut) { umodOut.m_description1 = QString::fromStdString(data.name()); umodOut.m_participantData.m_typeName = AlarmManagement::Notification::toString(data.structureElementTypeId()); return true; // break loop } return false; }; // sonst kann sich der compiler nicht zwischen bool und void entscheiden... !? std::function cb1 = cb; return m_almDtc->notification(cb1); } */ bool AlarmToMap::isElapsed(const Sim2SituationMap::DDS_T &data) const { // true -> hide // false -> show DEBUG_LOG(m_logger) << " isElapsed"; // if (data.isDeleted()) // return true; if (data.eventType().underlying() != ProjectDataManagement::EventType_def::EmergencyCall) return true; return false; } int32_t AlarmToMap::getSimId(const Sim2SituationMap::DDS_T &ddsData) const { return ddsData.id(); } bool AlarmToMap::updateElementImpl(const Sim2SituationMap::DDS_T &ddsData, RefPointer mapObj) { TRACE_LOG(m_logger) << LOGFUNCTION << ", id " << ddsData.id(); mapObj->setPickable(false); mapObj->setDrawOrder(-1); // Identifier: mapObj->setIdentifier(QStringLiteral("SOS_%1").arg(ddsData.equipmentNumber())); TextStyle textStyle; textStyle.setSize(20); textStyle.setTextColor(Qt::red); textStyle.setTextOutlineColor(Qt::white); textStyle.setTextOutlineWidth(5); mapObj->setTextStyle(textStyle); // Position: const Core::GeoPosition &geoPos = ddsData.position(); mapObj->setOrigin(Point3D(geoPos.lon(), geoPos.lat(), geoPos.z())); // Appearance: mapObj->setProxyImage(renderEmergencyCallSymbol(), QSize(50, 50)); emit alarmUpdated(mapObj->identifier(), Point3D(geoPos.lon(), geoPos.lat(), geoPos.z())); // equipmentNumber contains issi return true; }