Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Proxies/FeedGeoJson/feedGeoJson.cpp
T
torstenandCopilot 7a6be7474e Qt6 migration: Fix BUILD_RTI=OFF build errors in TrainingAreaBase
- training_area_telegrams.cpp: Fixed QJsonObject initializer syntax (Qt6 requires {{}} not ({}))
- training_area_telegrams.cpp: Fixed fromJson() methods to access m_* members directly
- training_area_telegrams.cpp: Fixed brace mismatches in multiple toJson() methods
- training_area_telegrams.h: Changed Header struct to public members for consistency
- tx_mixin.cpp: Fixed getEquipmentNumber() template for direct member access
- lts_coordinate.cpp: Added missing #include <iomanip>
- MIGRATION_STATUS.md: Added migration progress tracking document

C++17 constraint enforced due to RTI Connext DDS 7.7.0 incompatibility with C++20+

Build status: BUILD_RTI=OFF successful (0 errors, warnings only)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-23 20:49:23 +02:00

204 lines
5.3 KiB
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "feedGeoJson.h"
#include <nglapplication/nglcoreapplication.h>
#include <LtsCommandLineParser/LtsCommandLineParser.h>
#include <QtCore/QTimer>
#include <QtCore/QDateTime>
#include <QPolygonF>
#include <QtCore/QDateTime>
namespace FeedGeoJson
{
FeedGeoJson::FeedGeoJson(QObject *parent) : QObject(parent)
, m_bTestsSuccessful(true)
, m_refPos(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD8000090000"))),
m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger()) {}
FeedGeoJson::~FeedGeoJson()
{}
bool FeedGeoJson::init(const int domainId, const int exerciseId, WebSocketServer &webSocketServer)
{
m_websocketServer = &webSocketServer;
bool bRet = true;
INFO_LOG(m_logger) << "init begin";
m_ddsConnector42 = std::make_shared<DDSConnector::DdsConnector>(domainId, IDL::PartitionType::Exercise, exerciseId);
m_ddsConnector42->init();
m_ddsConnector42->initPublisherSubscriber();
m_pdmDtc = ProjectDataManagement::Interface::Dtc::create(m_ddsConnector42);
bRet &= m_pdmDtc->enableChargeType();
m_ppmDtc = ParticipantManagement::Interface::Dtc::create(m_ddsConnector42);
bRet &= m_ppmDtc->enableParticipantPosition();
bRet &= m_ppmDtc->enableParticipant();
bRet &= m_ppmDtc->enableDynamicParticipantData();
bRet &= m_ppmDtc->enableType();
m_aesDtc = AreaEffectSimulation::Interface::Dtc::create(m_ddsConnector42);
bRet &= m_aesDtc->enableExplosionSingle();
bRet &= m_aesDtc->enableAesItemView();
bRet &= m_aesDtc->enableTriggeredImpacts();
connect(m_ppmDtc.get(), &ParticipantManagement::Interface::Dtc::participantPositionChanged,
this, &FeedGeoJson::onParticipantPositionChanged);
NOTICE_LOG(m_logger) << "END init";
return bRet;
}
QString FeedGeoJson::getGeoJsonPosition(const ParticipantManagement::ParticipantPosition &data)
{
NOTICE_LOG(m_logger) << "sendPositionToGeoJson participantId=" << data.participantId();
QString message = QStringLiteral("{ 'type': 'FeatureCollection',\
'features': [\
{ 'type': 'Feature',\
'geometry': {'type': 'Point', 'coordinates': [102.0, 0.5]},\
'properties': {'prop0': 'value0'}\
},\
{ 'type': 'Feature',\
'geometry': {\
'type': 'LineString',\
'coordinates': [\
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]\
]\
},\
'properties': {\
'prop0': 'value0',\
'prop1': 0.0\
}¸\
},\
{ 'type': 'Feature',\
'geometry': {\
'type': 'Polygon',\
'coordinates': [\
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],\
[100.0, 1.0], [100.0, 0.0] ]\
]\
},\
'properties': {\
'prop0': 'value0',\
'prop1': {'this': 'that'}\
}\
}\
]\
}");
return message;
}
void FeedGeoJson::onParticipantPositionChanged(const ParticipantManagement::ParticipantPosition &data, DataModification modType)
{
NOTICE_LOG(m_logger) << "onParticipantPositionChanged: " << data;
DEBUG_LOG(m_logger) << "onParticipantPositionChanged: " << data;
if (modType == DataModification::eRemoved)
{
DEBUG_LOG(m_logger) << "m_participantsOutsideMap.remove participantId: " << data.participantId();
}
else
{
DEBUG_LOG(m_logger) << "Handle ParticipantPosition";
QString posGeoJson = getGeoJsonPosition(data);
m_websocketServer->sendMessage(posGeoJson);
}
}
void FeedGeoJson::onDynamicParticipantDataChanged(const ParticipantManagement::DynamicParticipantData &data, DataModification modType)
{
DEBUG_LOG(m_logger) << "onDynamicParticipantDataChanged";
if (modType == DataModification::eRemoved)
return;
}
void FeedGeoJson::failExit()
{
DEBUG_LOG(m_logger) << "FailExit";
m_bTestsSuccessful = false;
QTimer::singleShot(50, qApp, QCoreApplication::quit);
}
void FeedGeoJson::ExitSuccess()
{
DEBUG_LOG(m_logger) << "ExitSuccess";
m_bTestsSuccessful = true;
QTimer::singleShot(200, qApp, &QCoreApplication::quit);
}
}
class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser
{
public:
CmdLineParser()
: LtsCommandLineParser()
{
addOption({ QStringList() << QLatin1String("p") << QLatin1String("websocket port")
, QLatin1String("Port")
, QLatin1String("Default: 12345 (all tests)")
, QLatin1String("12345")
});
}
int exerciseId() const { return isSet(QLatin1String("e")) ? value(QLatin1String("e")).toInt() : -1; }
int port() const { return isSet(QLatin1String("p")) ? value(QLatin1String("p")).toInt() : -1; }
};
int main(int argc, char **argv)
{
NGLCoreApplication app(argc, argv);
app.createLogger("FGJ", "log4cxx_fgj.props");
fprintf(stderr, "Start Feed GeoJson Service\n");
CmdLineParser options;
if (!options.init())
{
fprintf(stderr, "no exercise ID abailable\n ./feedGeoJson -e <exerciseId>\n");
return -1;
}
fprintf(stderr, "./feedGeoJson -e %d -p %d (exerciseId=%d, Websocket Port=%d)\n", options.exerciseId(),options.port(), options.exerciseId(),options.port());
WebSocketServer webSocketServer(options.port());
int iRet = -1;
{
std::unique_ptr<FeedGeoJson::FeedGeoJson> cesTests(new FeedGeoJson::FeedGeoJson);
if (!cesTests->init(options.domainId(), options.exerciseId(), webSocketServer))
return iRet;
STARTUP_LOG(app.baseLogger());
app.exec();
iRet = cesTests->testsSuccessful() ? 0 : 1;
fprintf(stderr, "%d\n", iRet);
DEBUG_LOG(app.baseLogger()) << "** TEST result = " << iRet;
SHUTDOWN_LOG(app.baseLogger());
}
return iRet;
}