From 50eea4f487c136175dda2243d12385024e1cfe64 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 24 Jun 2021 00:21:11 +0100 Subject: [PATCH] Import progress dialog for FabMaster. Fixes https://gitlab.com/kicad/code/kicad/issues/5315 --- pcbnew/plugins/fabmaster/fabmaster_plugin.cpp | 13 ++++- pcbnew/plugins/fabmaster/import_fabmaster.cpp | 50 +++++++++++++++++-- pcbnew/plugins/fabmaster/import_fabmaster.h | 9 +++- 3 files changed, 66 insertions(+), 6 deletions(-) diff --git a/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp b/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp index 09312909b0..03a381ec9d 100644 --- a/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp +++ b/pcbnew/plugins/fabmaster/fabmaster_plugin.cpp @@ -29,7 +29,7 @@ #include "fabmaster_plugin.h" #include - +#include #include #include @@ -70,6 +70,14 @@ BOARD* FABMASTER_PLUGIN::Load( const wxString &aFileName, BOARD *aAppendToMe, if( !aAppendToMe ) m_board->SetFileName( aFileName ); + if( aProgressReporter ) + { + aProgressReporter->Report( wxString::Format( _( "Loading %s..." ), aFileName ) ); + + if( !aProgressReporter->KeepRefreshing() ) + THROW_IO_ERROR( ( "Open cancelled by user." ) ); + } + if( !m_fabmaster.Read( aFileName.ToStdString() ) ) { std::string readerr; @@ -79,6 +87,7 @@ BOARD* FABMASTER_PLUGIN::Load( const wxString &aFileName, BOARD *aAppendToMe, } m_fabmaster.Process(); - m_fabmaster.LoadBoard( m_board ); + m_fabmaster.LoadBoard( m_board, aProgressReporter ); + return m_board; } diff --git a/pcbnew/plugins/fabmaster/import_fabmaster.cpp b/pcbnew/plugins/fabmaster/import_fabmaster.cpp index 2eb1fdf6ec..4a1cf8726f 100644 --- a/pcbnew/plugins/fabmaster/import_fabmaster.cpp +++ b/pcbnew/plugins/fabmaster/import_fabmaster.cpp @@ -53,11 +53,30 @@ #include #include #include -#include +#include #include #include +void FABMASTER::checkpoint() +{ + const unsigned PROGRESS_DELTA = 250; + + if( m_progressReporter ) + { + if( ++m_doneCount > m_lastProgressCount + PROGRESS_DELTA ) + { + m_progressReporter->SetCurrentProgress(( (double) m_doneCount ) / m_totalCount ); + + if( !m_progressReporter->KeepRefreshing() ) + THROW_IO_ERROR( ( "Open cancelled by user." ) ); + + m_lastProgressCount = m_doneCount; + } + } +} + + double FABMASTER::readDouble( const std::string aStr ) const { std::istringstream istr( aStr ); @@ -1804,11 +1823,14 @@ bool FABMASTER::Process() bool FABMASTER::loadZones( BOARD* aBoard ) { - for( auto& zone : zones ) { + checkpoint(); + if( IsCopperLayer( getLayer( zone->layer ) ) || zone->layer == "ALL" ) + { loadZone( aBoard, zone ); + } else { if( zone->layer == "OUTLINE" || zone->layer == "DESIGN_OUTLINE" ) @@ -1915,6 +1937,8 @@ bool FABMASTER::loadFootprints( BOARD* aBoard ) for( auto& mod : components ) { + checkpoint(); + bool has_multiple = mod.second.size() > 1; for( int i = 0; i < mod.second.size(); ++i ) @@ -2362,6 +2386,8 @@ bool FABMASTER::loadLayers( BOARD* aBoard ) for( auto& layer : layers ) { + checkpoint(); + if( layer.second.layerid >= PCBNEW_LAYER_ID_START ) layer_set.set( layer.second.layerid ); } @@ -2388,6 +2414,8 @@ bool FABMASTER::loadVias( BOARD* aBoard ) for( auto& via : vias ) { + checkpoint(); + auto net_it = netinfo.find( via->net ); auto padstack = pads.find( via->padstack ); @@ -2430,6 +2458,8 @@ bool FABMASTER::loadNets( BOARD* aBoard ) { for( auto& net : netnames ) { + checkpoint(); + NETINFO_ITEM *newnet = new NETINFO_ITEM( aBoard, net ); aBoard->Add( newnet, ADD_MODE::APPEND ); } @@ -2769,6 +2799,8 @@ bool FABMASTER::loadGraphics( BOARD* aBoard ) for( auto& geom : board_graphics ) { + checkpoint(); + PCB_LAYER_ID layer; // The pin numbers are not useful for us outside of the footprints @@ -2911,9 +2943,19 @@ bool FABMASTER::orderZones( BOARD* aBoard ) } -bool FABMASTER::LoadBoard( BOARD* aBoard ) +bool FABMASTER::LoadBoard( BOARD* aBoard, PROGRESS_REPORTER* aProgressReporter ) { aBoard->SetFileName( m_filename.GetFullPath() ); + m_progressReporter = aProgressReporter; + + m_totalCount = netnames.size() + + layers.size() + + vias.size() + + components.size() + + zones.size() + + board_graphics.size() + + traces.size(); + m_doneCount = 0; loadNets( aBoard ); loadLayers( aBoard ); @@ -2924,6 +2966,8 @@ bool FABMASTER::LoadBoard( BOARD* aBoard ) for( auto& track : traces ) { + checkpoint(); + if( track->lclass == "ETCH" ) { loadEtch( aBoard, track); diff --git a/pcbnew/plugins/fabmaster/import_fabmaster.h b/pcbnew/plugins/fabmaster/import_fabmaster.h index 82f1f8000c..73fc3eb72e 100644 --- a/pcbnew/plugins/fabmaster/import_fabmaster.h +++ b/pcbnew/plugins/fabmaster/import_fabmaster.h @@ -45,6 +45,7 @@ enum PCB_LAYER_ID : int; class BOARD; +class PROGRESS_REPORTER; class FABMASTER { @@ -60,7 +61,7 @@ public: bool Process(); - bool LoadBoard( BOARD* aBoard ); + bool LoadBoard( BOARD* aBoard, PROGRESS_REPORTER* aProgressReporter ); private: @@ -497,6 +498,8 @@ private: section_type detectType( size_t aOffset ); + void checkpoint(); + int execute_recordbuffer( int filetype ); int getColFromName( size_t aRow, const std::string& aStr ); SYMTYPE parseSymType( const std::string& aSymType ); @@ -572,6 +575,10 @@ private: SHAPE_POLY_SET loadShapePolySet( const graphic_element& aLine); + PROGRESS_REPORTER* m_progressReporter; ///< optional; may be nullptr + unsigned m_doneCount; + unsigned m_lastProgressCount; + unsigned m_totalCount; ///< for progress reporting };