/** * @RDE_HEADER@ * Handler for ParticipantData * $Id$ * $HeadURL$ * $Author$ * Created by Norbert Thoden, NLE, 2020-06-29 */ #include "tgt_participant_handler.h" #include #include #include #include // pixelMetric namespace TargetManagement { //--------------------------------- // ParticipantHandler //--------------------------------- ParticipantHandler::ParticipantHandler(QObject *parent) : BaseClass(parent) , m_logger(getLogger("ParticipantHandler")) {} bool ParticipantHandler::init(const std::shared_ptr &tgt_dtc, const std::shared_ptr &ppmDtc, const std::shared_ptr &ppmGuiCbxIfc) { m_tgt_dtc = tgt_dtc; m_ppm_dtc = ppmDtc; m_ppmGuiCbxIfc = ppmGuiCbxIfc; // init if (m_tgt_dtc) { connect(m_tgt_dtc.get(), &TargetManagement::Interface::Dtc::shootbackTargetChanged, this, &ParticipantHandler::onShootbackTargetChanged); auto cb = [this](const TargetManagement::ShootbackTarget & d) { onShootbackTargetChanged(d, DataModification::eAdded); }; m_tgt_dtc->shootbackTargets(cb); } if (m_ppm_dtc) { { connect(m_ppm_dtc.get(), &ParticipantManagement::Interface::Dtc::typeChanged, this, &ParticipantHandler::onTypeChanged); auto cb = [this](const ParticipantManagement::Type & d) { onTypeChanged(d, DataModification::eAdded); }; m_ppm_dtc->types(cb); } { connect(m_ppm_dtc.get(), &ParticipantManagement::Interface::Dtc::participantChanged, this, &ParticipantHandler::onParticipantChanged); auto cb = [this](const ParticipantManagement::Participant & d) { onParticipantChanged(d, DataModification::eAdded); }; m_ppm_dtc->participants(cb); } } return true; } int ParticipantHandler::getParticipantIdToTargetId(int participantId) const { return m_participantIdToTargetId.value(participantId, -1); } QString ParticipantHandler::getParticipantHierarchie(int participantId) const { return m_participantHierarchies.value(participantId, tr("No participant name available")); } QString ParticipantHandler::target_wmsTypeClassToString(const ParticipantManagement::WmsTypeClass &wmsTypeClass) { switch (wmsTypeClass.underlying()) { case ParticipantManagement::WmsTypeClass_def::TargetHuman: return QStringLiteral("Human"); case ParticipantManagement::WmsTypeClass_def::TargetVehicle: return QStringLiteral("Vehicle"); break; default: { // empty } } //switch return QStringLiteral("-"); } void ParticipantHandler::onShootbackTargetChanged(const TargetManagement::ShootbackTarget &data, const DataModification modType) { INFO_LOG(m_logger) << "onShootbackTargetChanged: " << data << ", " << modType; switch (modType) { case DataModification::eRemoved: m_participantIdToTargetId.remove(data.targetParticipantId()); break; case DataModification::eModified: case DataModification::eAdded: m_participantIdToTargetId.insert(data.targetParticipantId(), data.id()); break; } } void ParticipantHandler::onTypeChanged(const ParticipantManagement::Type &data, const DataModification modType) { INFO_LOG(m_logger) << "onTypeChanged:" << data << ", " << modType; switch (modType) { case DataModification::eRemoved: m_typeToTypeClass.remove(data.id()); break; case DataModification::eModified: case DataModification::eAdded: m_typeToTypeClass.insert(data.id(), data.typeClass()); break; } } void ParticipantHandler::onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType) { TRACE_LOG(m_logger) << "onParticipantChanged: " << data << ", " << modType; if (data.isDeleted()) modType = DataModification::eRemoved; const int dataId = data.id(); switch (modType) { case DataModification::eRemoved: m_participantHierarchies.remove(dataId); m_participantIdToEq.remove(dataId); m_participantIdToWmsTypeClass.remove(dataId); break; case DataModification::eModified: case DataModification::eAdded: { DEBUG_LOG(m_logger) << "DataModification::eAdded Participant" << " Id=" << dataId << " TypeId=" << data.typeId() << " eqId=" << (data.equipmentNumber().is_set() ? data.equipmentNumber().get() : -1) << " " << data.name(); const int typeId = data.typeId(); const ParticipantManagement::Type &type = m_ppm_dtc->type(typeId); if (type.id() != typeId) return; const int equipmentTypeId = type.equipmentTypeId(); const ParticipantManagement::EquipmentType &eqType = m_ppm_dtc->equipmentType(equipmentTypeId); if (eqType.id() != equipmentTypeId) return; m_participantIdToWmsTypeClass.insert(dataId, eqType.wmsTypeClass()); bool bIsTarget{false}; switch (eqType.wmsTypeClass().underlying()) { case ParticipantManagement::WmsTypeClass::None: case ParticipantManagement::WmsTypeClass::Building: case ParticipantManagement::WmsTypeClass::Vehicle: case ParticipantManagement::WmsTypeClass::Human: case ParticipantManagement::WmsTypeClass::Airborne: case ParticipantManagement::WmsTypeClass::VehicleMarker: bIsTarget = false; break; case ParticipantManagement::WmsTypeClass::TargetVehicle: case ParticipantManagement::WmsTypeClass::TargetHuman: bIsTarget = true; break; default: break; } // switch if (!bIsTarget) return; // m_participantIdToEq : int eqId = -1; if (data.equipmentNumber().is_set()) eqId = data.equipmentNumber().get(); if (eqId >= 0) m_participantIdToEq[dataId] = eqId; else m_participantIdToEq.remove(dataId); // : m_participantIdToEq // hierarchy... const QString hierarchy = m_ppm_dtc->hierarchyFromParticipant(dataId); if (data.equipmentNumber().is_set()) m_participantHierarchies.insert(dataId, hierarchy + QString(QStringLiteral(" (%1)")).arg(data.equipmentNumber().get())); else m_participantHierarchies.insert(dataId, hierarchy); if (m_ppmGuiCbxIfc) { // afterwards, render sidc: AdvancedSymbology::SymbolDictionary &dictionary = AdvancedSymbology::SymbolDictionary::dictionary(AdvancedSymbology::SymbologyType::APP6D); if (!m_participantDecorations.contains(dataId)) { // for very first view, use simple squares of partyColor: const auto party = m_ppm_dtc->party(data.partyId()); const QRgb col = QRgb(party.color()); m_participantDecorations.insert(dataId, m_ppmGuiCbxIfc->pixmapFromParty(col)); AdvancedSymbology::SymbolDataToRender symDataToRender(QString::fromStdString(data.symbol())); symDataToRender.fillColor = m_ppm_dtc->party(data.partyId()).color(); symDataToRender.fillColorReplace = true; AdvancedSymbology::SymbolResultWatcher *srw = new AdvancedSymbology::SymbolResultWatcher(this); connect(srw, &AdvancedSymbology::SymbolResultWatcher::resultReady, this, [this, dataId, srw]() { if (srw->symbolResult()) { m_participantDecorations[dataId] = QPixmap::fromImage(srw->symbolResult()->symbolImage().image()); emit signalParticipantChanged(dataId); // update(); } }); srw->setSymbolResult(dictionary.fetchSymbol(symDataToRender)); } } break; } } emit signalParticipantNamesChanged(); emit signalParticipantChanged(dataId); // emit dataChanged(index(0, rowCount() -1), index(0, columnCount() - 1)); } } // namespace TargetManagement