/** * Calculate the focal point for units based on it's superiors * $Id$ * $HeadURL$ * $Author$ * Created by Christian Ehrlicher, SLSE, 2017-09-05 */ #pragma once #include #include #include #include #include "participant_handler.h" class QTimer; namespace ParticipantManagement { namespace ParticipantHandling { class UnitPositionCalculator : public QObject { Q_OBJECT public: explicit UnitPositionCalculator(ParticipantHandler *participantHandler, QObject *parent = nullptr); ~UnitPositionCalculator(); void startCalculation(); void stopCalculation(); // also clear all participants void waitForCalculationFinished(); void onParticipantDeleted(int participantId); void onPositionChanged(int participantId, int64_t positionTime, const Core::GeoPosition &pos); void onSuperiorChanged(int participantId, int superiorId); void onInferiorChanged(int participantId, const std::vector &inferiorIds); private: struct CalculatedUnitPosition : public ParticipantManagement::UnitPosition { int superiorId = 0; std::vector inferiorIds; }; private: CalculatedUnitPosition &getParticipant(int participantId); void calculate(); // no const ref - must be a copy since this is running in a different thread using Result = std::vector; static Result doCalculation(std::unordered_map &participantData, qint64 currentTime, NGL::INGLLogger &logger); static void calculatePosition(int participantId, std::unordered_map &participantData, qint64 currentTime, int level, NGL::INGLLogger &logger, Result &result); private Q_SLOTS: void onCalculationDone(); private: std::unordered_map m_participantData; std::unordered_map m_publishedPositionData; QFutureWatcher m_calculationWatcher; ParticipantHandler *m_participantHandler; bool m_bSomethingChangedSinceLastCalculation; QTimer *m_timer; bool m_bRunning; NGL::INGLLogger &m_logger; }; } // namespace ParticipantHandling } // namespace ParticipantManagement