Import progress dialog for FabMaster.

Fixes https://gitlab.com/kicad/code/kicad/issues/5315
This commit is contained in:
Jeff Young 2021-06-24 00:21:11 +01:00
parent 5fa5a73c6d
commit 50eea4f487
3 changed files with 66 additions and 6 deletions

View File

@ -29,7 +29,7 @@
#include "fabmaster_plugin.h"
#include <board.h>
#include <widgets/progress_reporter.h>
#include <common.h>
#include <macros.h>
@ -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;
}

View File

@ -53,11 +53,30 @@
#include <common.h>
#include <geometry/shape_arc.h>
#include <kicad_string.h>
#include <convert_to_biu.h>
#include <widgets/progress_reporter.h>
#include <math/util.h>
#include <wx/filename.h>
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);

View File

@ -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
};