From 16659ba0f77e7af78a991a09b9cf8ee3eb93e430 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Mon, 1 Jul 2024 17:14:15 -0700 Subject: [PATCH 1/3] Ability to stop selected running routes. --- include/WeatherRouting.h | 3 ++- src/WeatherRouting.cpp | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/include/WeatherRouting.h b/include/WeatherRouting.h index e6852450..d7e83a44 100644 --- a/include/WeatherRouting.h +++ b/include/WeatherRouting.h @@ -203,7 +203,8 @@ class WeatherRouting : public WeatherRoutingBase void Start(RouteMapOverlay *routemapoverlay); void StartAll(); - void Stop(); + void Stop(RouteMapOverlay *routemapoverlay); + void StopAll(); void DeleteRouteMaps(std::listroutemapoverlays); RouteMapConfiguration DefaultConfiguration(); diff --git a/src/WeatherRouting.cpp b/src/WeatherRouting.cpp index c5efadd4..01218753 100644 --- a/src/WeatherRouting.cpp +++ b/src/WeatherRouting.cpp @@ -346,7 +346,7 @@ WeatherRouting::~WeatherRouting( ) m_panel->m_bExport->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WeatherRouting::OnExport ), NULL, this ); m_panel->m_bExportRoute->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( WeatherRouting::OnExportRoute ), NULL, this ); - Stop(); + StopAll(); m_SettingsDialog.SaveSettings(); @@ -1140,7 +1140,7 @@ void WeatherRouting::OnDelete( wxCommandEvent& event ) // Probably could do better to stop only the computation of selected configuration // But stopping all is safer. // Sess: https://github.com/rgleason/weather_routing_pi/issues/103 - Stop(); + StopAll(); long index = m_panel->m_lWeatherRoutes->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (index < 0) return; @@ -1290,7 +1290,10 @@ void WeatherRouting::OnComputeAll ( wxCommandEvent& event ) void WeatherRouting::OnStop( wxCommandEvent& event ) { - Stop(); + std::list currentroutemaps = CurrentRouteMaps(); + for(auto it = currentroutemaps.begin();it != currentroutemaps.end(); it++) + Stop(*it); + UpdateComputeState(); } #define FAIL(X) do { error = X; goto failed; } while(0) @@ -1706,7 +1709,7 @@ void WeatherRouting::OnComputationTimer( wxTimerEvent & ) return; } - Stop(); + StopAll(); } void WeatherRouting::OnHideConfigurationTimer( wxTimerEvent & ) @@ -2722,7 +2725,16 @@ void WeatherRouting::StartAll() } } -void WeatherRouting::Stop() +void WeatherRouting::Stop(RouteMapOverlay *routemapoverlay) { + routemapoverlay->Stop(); + // Wait for threads to finish + while(routemapoverlay->Running()) + wxThread::Sleep(100); + routemapoverlay->ResetFinished(); + routemapoverlay->DeleteThread(); +} + +void WeatherRouting::StopAll() { /* stop all the threads at once, rather than waiting for each one before telling the next to stop */ @@ -2764,7 +2776,7 @@ void WeatherRouting::Stop() void WeatherRouting::Reset() { if(m_bRunning) - Stop(); + StopAll(); for(int i=0; im_lWeatherRoutes->GetItemCount(); i++) { WeatherRoute *weatherroute = From a06f5bc513fac1b65444734f58e6e7ba4bd68107 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Mon, 1 Jul 2024 17:17:52 -0700 Subject: [PATCH 2/3] Ability to stop selected running routes. --- include/WeatherRouting.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/WeatherRouting.h b/include/WeatherRouting.h index d7e83a44..88c9028d 100644 --- a/include/WeatherRouting.h +++ b/include/WeatherRouting.h @@ -200,10 +200,12 @@ class WeatherRouting : public WeatherRoutingBase RouteMap *SelectedRouteMap(); void Export(RouteMapOverlay &routemapoverlay); void ExportRoute(RouteMapOverlay &routemapoverlay); - + /* Start the computation of the selected route. */ void Start(RouteMapOverlay *routemapoverlay); void StartAll(); + /* Stop the computation of the selected routes. */ void Stop(RouteMapOverlay *routemapoverlay); + /* Stop the computation of all routes. */ void StopAll(); void DeleteRouteMaps(std::listroutemapoverlays); From 9847b8dc4c705d2e0f628267f806bd5cce269b91 Mon Sep 17 00:00:00 2001 From: "Sebastien Rosset (serosset)" Date: Mon, 1 Jul 2024 17:20:09 -0700 Subject: [PATCH 3/3] Ability to stop selected running routes. --- include/WeatherRouting.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/WeatherRouting.h b/include/WeatherRouting.h index 88c9028d..17b511e2 100644 --- a/include/WeatherRouting.h +++ b/include/WeatherRouting.h @@ -200,10 +200,10 @@ class WeatherRouting : public WeatherRoutingBase RouteMap *SelectedRouteMap(); void Export(RouteMapOverlay &routemapoverlay); void ExportRoute(RouteMapOverlay &routemapoverlay); - /* Start the computation of the selected route. */ + /* Start the computation of the specified route. */ void Start(RouteMapOverlay *routemapoverlay); void StartAll(); - /* Stop the computation of the selected routes. */ + /* Stop the computation of the specified route. */ void Stop(RouteMapOverlay *routemapoverlay); /* Stop the computation of all routes. */ void StopAll();