Skip to content

Commit

Permalink
Merge pull request #297 from sebastien-rosset/on_stop
Browse files Browse the repository at this point in the history
Ability to stop computation of selected route
  • Loading branch information
seandepagnier authored Jul 2, 2024
2 parents 0509073 + 9847b8d commit 9a9f57e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
7 changes: 5 additions & 2 deletions include/WeatherRouting.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,13 @@ class WeatherRouting : public WeatherRoutingBase
RouteMap *SelectedRouteMap();
void Export(RouteMapOverlay &routemapoverlay);
void ExportRoute(RouteMapOverlay &routemapoverlay);

/* Start the computation of the specified route. */
void Start(RouteMapOverlay *routemapoverlay);
void StartAll();
void Stop();
/* Stop the computation of the specified route. */
void Stop(RouteMapOverlay *routemapoverlay);
/* Stop the computation of all routes. */
void StopAll();

void DeleteRouteMaps(std::list<RouteMapOverlay *>routemapoverlays);
RouteMapConfiguration DefaultConfiguration();
Expand Down
24 changes: 18 additions & 6 deletions src/WeatherRouting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1290,7 +1290,10 @@ void WeatherRouting::OnComputeAll ( wxCommandEvent& event )

void WeatherRouting::OnStop( wxCommandEvent& event )
{
Stop();
std::list<RouteMapOverlay*> currentroutemaps = CurrentRouteMaps();
for(auto it = currentroutemaps.begin();it != currentroutemaps.end(); it++)
Stop(*it);
UpdateComputeState();
}

#define FAIL(X) do { error = X; goto failed; } while(0)
Expand Down Expand Up @@ -1706,7 +1709,7 @@ void WeatherRouting::OnComputationTimer( wxTimerEvent & )
return;
}

Stop();
StopAll();
}

void WeatherRouting::OnHideConfigurationTimer( wxTimerEvent & )
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -2764,7 +2776,7 @@ void WeatherRouting::Stop()
void WeatherRouting::Reset()
{
if(m_bRunning)
Stop();
StopAll();

for(int i=0; i<m_panel->m_lWeatherRoutes->GetItemCount(); i++) {
WeatherRoute *weatherroute =
Expand Down

0 comments on commit 9a9f57e

Please sign in to comment.