Use progress reporting in more places when loading a board

Prevents application-not-responding events while opening large designs
This commit is contained in:
Jon Evans 2021-11-25 11:19:03 -05:00
parent b4342d813b
commit 8026863d4c
13 changed files with 35 additions and 23 deletions

View File

@ -62,6 +62,7 @@ class FP_LIB_TABLE;
class PCBNEW_SETTINGS;
class FOOTPRINT_EDITOR_SETTINGS;
struct MAGNETIC_SETTINGS;
class PROGRESS_REPORTER;
wxDECLARE_EVENT( BOARD_CHANGED, wxCommandEvent );
@ -201,7 +202,7 @@ public:
*
* @param aBoard is the #BOARD to put into the frame.
*/
virtual void SetBoard( BOARD* aBoard );
virtual void SetBoard( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr );
BOARD* GetBoard() const
{

View File

@ -134,9 +134,9 @@ BOARD::~BOARD()
}
void BOARD::BuildConnectivity()
void BOARD::BuildConnectivity( PROGRESS_REPORTER* aReporter )
{
GetConnectivity()->Build( this );
GetConnectivity()->Build( this, aReporter );
}

View File

@ -58,6 +58,7 @@ class SHAPE_POLY_SET;
class CONNECTIVITY_DATA;
class COMPONENT;
class PROJECT;
class PROGRESS_REPORTER;
// Forward declare endpoint from class_track.h
enum ENDPOINT_T : int;
@ -348,7 +349,7 @@ public:
* especially the list of connected items, list of nets and rastnest data
* Needed after loading a board to have the connectivity database updated.
*/
void BuildConnectivity();
void BuildConnectivity( PROGRESS_REPORTER* aReporter = nullptr );
/**
* Delete all MARKERS from the board.

View File

@ -418,7 +418,7 @@ void reportProgress( PROGRESS_REPORTER* aReporter, int aCount, int aSize, int aD
void CN_CONNECTIVITY_ALGO::Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
{
const int delta = 100; // Number of additions between 2 calls to the progress bar
int delta = 100; // Number of additions between 2 calls to the progress bar
int ii = 0;
int size = 0;
@ -430,6 +430,8 @@ void CN_CONNECTIVITY_ALGO::Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
size *= 2; // Our caller us gets the other half of the progress bar
delta = std::max( delta, size / 50 );
for( ZONE* zone : aBoard->Zones() )
{
Add( zone );

View File

@ -129,7 +129,7 @@ void CONNECTIVITY_DATA::updateRatsnest()
[] ( RN_NET* aNet ) { return aNet->IsDirty() && aNet->GetNodeCount() > 0; } );
// We don't want to spin up a new thread for fewer than 8 nets (overhead costs)
size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency(),
size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency() - 1,
( dirty_nets.size() + 7 ) / 8 );
std::atomic<size_t> nextNet( 0 );

View File

@ -748,7 +748,7 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
Raise();
// Skip (possibly expensive) connectivity build here; we build it below after load
SetBoard( loadedBoard, false );
SetBoard( loadedBoard, false, &progressReporter );
if( GFootprintList.GetCount() == 0 )
GFootprintList.ReadCacheFromFile( Prj().GetProjectPath() + "fp-info-cache" );
@ -911,7 +911,8 @@ bool PCB_EDIT_FRAME::OpenProjectFiles( const std::vector<wxString>& aFileSet, in
UpdateFileHistory( GetBoard()->GetFileName() );
// Rebuild list of nets (full ratsnest rebuild)
GetBoard()->BuildConnectivity();
progressReporter.Report( _( "Updating nets" ) );
GetBoard()->BuildConnectivity( &progressReporter );
// Load project settings after setting up board; some of them depend on the nets list
LoadProjectSettings();

View File

@ -137,7 +137,7 @@ void PCB_BASE_EDIT_FRAME::ActivateGalCanvas()
}
void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard )
void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
{
bool new_board = ( aBoard != m_pcb );
@ -150,7 +150,7 @@ void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard )
GetCanvas()->GetView()->InitPreview();
}
PCB_BASE_FRAME::SetBoard( aBoard );
PCB_BASE_FRAME::SetBoard( aBoard, aReporter );
GetCanvas()->GetGAL()->SetGridOrigin( VECTOR2D( aBoard->GetDesignSettings().GetGridOrigin() ) );
@ -163,7 +163,7 @@ void PCB_BASE_EDIT_FRAME::SetBoard( BOARD* aBoard )
// update the tool manager with the new board and its view.
if( m_toolManager )
{
GetCanvas()->DisplayBoard( aBoard );
GetCanvas()->DisplayBoard( aBoard, aReporter );
GetCanvas()->UpdateColors();
m_toolManager->SetEnvironment( aBoard, GetCanvas()->GetView(),

View File

@ -173,7 +173,7 @@ public:
void ActivateGalCanvas() override;
///< @copydoc PCB_BASE_FRAME::SetBoard()
virtual void SetBoard( BOARD* aBoard ) override;
virtual void SetBoard( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr ) override;
COLOR_SETTINGS* GetColorSettings() const override;

View File

@ -160,7 +160,7 @@ FP_LIB_TABLE* PROJECT::PcbFootprintLibs()
}
void PCB_BASE_FRAME::SetBoard( BOARD* aBoard )
void PCB_BASE_FRAME::SetBoard( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
{
if( m_pcb != aBoard )
{

View File

@ -43,6 +43,7 @@
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <confirm.h>
#include <progress_reporter.h>
#include <gal/graphics_abstraction_layer.h>
#include <zoom_defines.h>
@ -177,15 +178,14 @@ PCB_DRAW_PANEL_GAL::~PCB_DRAW_PANEL_GAL()
}
void PCB_DRAW_PANEL_GAL::DisplayBoard( BOARD* aBoard )
void PCB_DRAW_PANEL_GAL::DisplayBoard( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
{
m_view->Clear();
auto zones = aBoard->Zones();
std::atomic<size_t> next( 0 );
std::atomic<size_t> count_done( 0 );
size_t parallelThreadCount = std::max<size_t>( std::thread::hardware_concurrency(), 2 );
size_t parallelThreadCount = std::max<size_t>( std::thread::hardware_concurrency() - 1, 2 );
for( size_t ii = 0; ii < parallelThreadCount; ++ii )
{
@ -221,7 +221,12 @@ void PCB_DRAW_PANEL_GAL::DisplayBoard( BOARD* aBoard )
// Finalize the triangulation threads
while( count_done < parallelThreadCount )
std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
{
if( aReporter )
aReporter->KeepRefreshing();
std::this_thread::sleep_for( std::chrono::milliseconds( 30 ) );
}
// Load zones
for( ZONE* zone : aBoard->Zones() )

View File

@ -33,6 +33,7 @@
class DS_PROXY_VIEW_ITEM;
class RATSNEST_VIEW_ITEM;
class PROGRESS_REPORTER;
class PCB_DRAW_PANEL_GAL : public EDA_DRAW_PANEL_GAL
{
@ -48,7 +49,7 @@ public:
*
* @param aBoard is the PCB to be loaded.
*/
void DisplayBoard( BOARD* aBoard );
void DisplayBoard( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr );
/**
* Sets (or updates) drawing-sheet used by the draw panel.

View File

@ -387,12 +387,13 @@ PCB_EDIT_FRAME::~PCB_EDIT_FRAME()
}
void PCB_EDIT_FRAME::SetBoard( BOARD* aBoard, bool aBuildConnectivity )
void PCB_EDIT_FRAME::SetBoard( BOARD* aBoard, bool aBuildConnectivity,
PROGRESS_REPORTER* aReporter )
{
if( m_pcb )
m_pcb->ClearProject();
PCB_BASE_EDIT_FRAME::SetBoard( aBoard );
PCB_BASE_EDIT_FRAME::SetBoard( aBoard, aReporter );
aBoard->SetProject( &Prj() );

View File

@ -398,12 +398,12 @@ public:
bool Clear_Pcb( bool aQuery, bool aFinal = false );
///< @copydoc PCB_BASE_FRAME::SetBoard()
void SetBoard( BOARD* aBoard ) override
void SetBoard( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr ) override
{
SetBoard( aBoard, true );
SetBoard( aBoard, true, aReporter );
}
void SetBoard( BOARD* aBoard, bool aBuildConnectivity );
void SetBoard( BOARD* aBoard, bool aBuildConnectivity, PROGRESS_REPORTER* aReporter = nullptr );
///< @copydoc PCB_BASE_FRAME::GetModel()
BOARD_ITEM_CONTAINER* GetModel() const override;