From f30316d8684cfb5cd2674991ab5c9b0a3b6045d9 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Fri, 6 Jun 2025 20:38:19 +0300 Subject: [PATCH] [traff_assessment_tool] Open TraFF feed Signed-off-by: mvglasow --- map/traffic_manager.cpp | 1 + traffxml/traff_assessment_tool/mainwindow.cpp | 35 ++++++++++++++++--- traffxml/traff_assessment_tool/mainwindow.hpp | 3 ++ .../trafficmodeinitdlg.cpp | 2 +- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/map/traffic_manager.cpp b/map/traffic_manager.cpp index 6d16e4bec..d701f5831 100644 --- a/map/traffic_manager.cpp +++ b/map/traffic_manager.cpp @@ -594,6 +594,7 @@ bool TrafficManager::WaitForRequest() LOG(LINFO, ("nothing to do for now, waiting for timeout or notification")); bool const timeout = !m_condition.wait_for(lock, kUpdateInterval, [this] { + // return true for any condition we want to process immediately return !m_isRunning || (m_activeMwmsChanged && !IsTestMode()) || !m_feedQueue.empty(); }); diff --git a/traffxml/traff_assessment_tool/mainwindow.cpp b/traffxml/traff_assessment_tool/mainwindow.cpp index e9d51da06..c60ba3a5d 100644 --- a/traffxml/traff_assessment_tool/mainwindow.cpp +++ b/traffxml/traff_assessment_tool/mainwindow.cpp @@ -18,6 +18,8 @@ #include "storage/country_parent_getter.hpp" +#include "traffxml/traff_model_xml.hpp" + #include "geometry/mercator.hpp" #include "geometry/point2d.hpp" @@ -350,21 +352,44 @@ void MainWindow::OnOpenTrafficSample() if (dlg.result() != QDialog::DialogCode::Accepted) return; + pugi::xml_document document; + LOG(LINFO, ("Attempting to load:", dlg.GetDataFilePath())); + auto const load_result = document.load_file(dlg.GetDataFilePath().data()); + if (!load_result) + { + QMessageBox::critical(this, "Data loading error", QString::asprintf("Can't load file %s: %s", dlg.GetDataFilePath().data(), load_result.description())); + LOG(LERROR, ("Can't load file", dlg.GetDataFilePath(), ":", load_result.description())); + return; + } + + std::setlocale(LC_ALL, "en_US.UTF-8"); + traffxml::TraffFeed feed; + if (traffxml::ParseTraff(document, feed)) + { + LOG(LINFO, ("TraFF data parsed successfully, pushing")); + m_framework.GetTrafficManager().Push(feed); + LOG(LINFO, ("Push completed")); + } + else + { + QMessageBox::critical(this, "Data loading error", QString("An error occurred parsing the TraFF feed")); + LOG(LWARNING, ("An error occurred parsing the TraFF feed")); + return; + } + +// TODO create traffic panel with TraFF messages +#if 0 try { CreateTrafficPanel(dlg.GetDataFilePath()); } -#ifdef openlr_obsolete catch (TrafficModeError const & e) -#else - // TODO do we need to catch exceptions other than our own here? - catch (RootException const & e) -#endif { QMessageBox::critical(this, "Data loading error", QString("Can't load data file.")); LOG(LERROR, (e.Msg())); return; } +#endif #ifdef openlr_obsolete m_goldifyMatchedPathAction->setEnabled(true /* enabled */); diff --git a/traffxml/traff_assessment_tool/mainwindow.hpp b/traffxml/traff_assessment_tool/mainwindow.hpp index 9ad80e2fa..50101344e 100644 --- a/traffxml/traff_assessment_tool/mainwindow.hpp +++ b/traffxml/traff_assessment_tool/mainwindow.hpp @@ -36,6 +36,9 @@ private: void CreateTrafficPanel(std::string const & dataFilePath); void DestroyTrafficPanel(); + /** + * Called when the user requests to open a sample file. + */ void OnOpenTrafficSample(); void OnCloseTrafficSample(); void OnSaveTrafficSample(); diff --git a/traffxml/traff_assessment_tool/trafficmodeinitdlg.cpp b/traffxml/traff_assessment_tool/trafficmodeinitdlg.cpp index f916d6125..8560ead4a 100644 --- a/traffxml/traff_assessment_tool/trafficmodeinitdlg.cpp +++ b/traffxml/traff_assessment_tool/trafficmodeinitdlg.cpp @@ -9,7 +9,7 @@ namespace { -std::string const kDataFilePath = "LastOpenlrAssessmentDataFilePath"; +std::string const kDataFilePath = "LastTraffAssessmentDataFilePath"; } // namespace namespace traffxml