Implement a more aggressive zone-fill-cancel.

We now unfill all zones so that the user can clearly see that
things are not in a "finished" state.

Fixes https://gitlab.com/kicad/code/kicad/issues/5035
This commit is contained in:
Jeff Young 2020-08-05 16:50:32 +01:00
parent e2ec9d9f00
commit c30739dff3
2 changed files with 78 additions and 84 deletions

View File

@ -114,7 +114,8 @@ bool ZONE_FILLER::Fill( const std::vector<ZONE_CONTAINER*>& aZones, bool aCheck
if( m_progressReporter )
{
m_progressReporter->Report( aCheck ? _( "Checking zone fills..." ) : _( "Building zone fills..." ) );
m_progressReporter->Report( aCheck ? _( "Checking zone fills..." )
: _( "Building zone fills..." ) );
m_progressReporter->SetMaxProgress( aZones.size() );
}
@ -132,7 +133,7 @@ bool ZONE_FILLER::Fill( const std::vector<ZONE_CONTAINER*>& aZones, bool aCheck
}
}
for( auto zone : aZones )
for( ZONE_CONTAINER* zone : aZones )
{
// Keepout zones are not filled
if( zone->GetIsKeepout() )
@ -158,12 +159,23 @@ bool ZONE_FILLER::Fill( const std::vector<ZONE_CONTAINER*>& aZones, bool aCheck
zone->UnFill();
}
auto cleanupAfterCancel =
[&]()
{
if( m_commit )
m_commit->Revert();
for( ZONE_CONTAINER* zone : aZones )
zone->UnFill();
};
std::atomic<size_t> nextItem( 0 );
size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency(),
aZones.size() );
std::vector<std::future<size_t>> returns( parallelThreadCount );
auto fill_lambda = [&] ( PROGRESS_REPORTER* aReporter ) -> size_t
auto fill_lambda =
[&]( PROGRESS_REPORTER* aReporter ) -> size_t
{
size_t num = 0;
@ -211,13 +223,8 @@ bool ZONE_FILLER::Fill( const std::vector<ZONE_CONTAINER*>& aZones, bool aCheck
do
{
if( m_progressReporter )
{
m_progressReporter->KeepRefreshing();
if( m_progressReporter->IsCancelled() )
break;
}
status = returns[ii].wait_for( std::chrono::milliseconds( 100 ) );
} while( status != std::future_status::ready );
}
@ -226,29 +233,24 @@ bool ZONE_FILLER::Fill( const std::vector<ZONE_CONTAINER*>& aZones, bool aCheck
// Now update the connectivity to check for copper islands
if( m_progressReporter )
{
if( m_progressReporter->IsCancelled() )
{
cleanupAfterCancel();
return false;
}
m_progressReporter->AdvancePhase();
m_progressReporter->Report( _( "Removing insulated copper islands..." ) );
m_progressReporter->KeepRefreshing();
if( m_progressReporter->IsCancelled() )
{
if( m_commit )
m_commit->Revert();
connectivity->SetProgressReporter( nullptr );
return false;
}
}
connectivity->SetProgressReporter( m_progressReporter );
connectivity->FindIsolatedCopperIslands( islandsList );
connectivity->SetProgressReporter( nullptr );
if( m_progressReporter && m_progressReporter->IsCancelled() )
{
if( m_commit )
m_commit->Revert();
connectivity->SetProgressReporter( nullptr );
cleanupAfterCancel();
return false;
}
@ -316,10 +318,7 @@ bool ZONE_FILLER::Fill( const std::vector<ZONE_CONTAINER*>& aZones, bool aCheck
if( m_progressReporter && m_progressReporter->IsCancelled() )
{
if( m_commit )
m_commit->Revert();
connectivity->SetProgressReporter( nullptr );
cleanupAfterCancel();
return false;
}
}
@ -336,10 +335,7 @@ bool ZONE_FILLER::Fill( const std::vector<ZONE_CONTAINER*>& aZones, bool aCheck
if( dlg.ShowModal() == wxID_CANCEL )
{
if( m_commit )
m_commit->Revert();
connectivity->SetProgressReporter( nullptr );
cleanupAfterCancel();
return false;
}
}
@ -353,7 +349,8 @@ bool ZONE_FILLER::Fill( const std::vector<ZONE_CONTAINER*>& aZones, bool aCheck
nextItem = 0;
auto tri_lambda = [&] ( PROGRESS_REPORTER* aReporter ) -> size_t
auto tri_lambda =
[&]( PROGRESS_REPORTER* aReporter ) -> size_t
{
size_t num = 0;
@ -402,18 +399,15 @@ bool ZONE_FILLER::Fill( const std::vector<ZONE_CONTAINER*>& aZones, bool aCheck
if( m_progressReporter )
{
if( m_progressReporter->IsCancelled() )
{
cleanupAfterCancel();
return false;
}
m_progressReporter->AdvancePhase();
m_progressReporter->Report( _( "Committing changes..." ) );
m_progressReporter->KeepRefreshing();
if( m_progressReporter->IsCancelled() )
{
if( m_commit )
m_commit->Revert();
connectivity->SetProgressReporter( nullptr );
return false;
}
}
connectivity->SetProgressReporter( nullptr );

View File

@ -136,7 +136,7 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( ZONE_CONTAINER* aZone )
if( zones_to_refill.size() )
{
ZONE_FILLER filler ( GetBoard() );
ZONE_FILLER filler( GetBoard() );
wxString title = wxString::Format( _( "Refill %d Zones" ), (int) zones_to_refill.size() );
filler.InstallNewProgressReporter( this, title, 4 );
filler.Fill( zones_to_refill );