KiCad PCB EDA Suite
PROGRESS_REPORTER Class Referenceabstract

A progress reporter for use in multi-threaded environments. More...

#include <progress_reporter.h>

Inheritance diagram for PROGRESS_REPORTER:
CONSOLE_PROGRESS_REPORTER DIALOG_DRC DIALOG_ERC GAUGE_PROGRESS_REPORTER WX_PROGRESS_REPORTER

Public Member Functions

 PROGRESS_REPORTER (int aNumPhases)
 
 PROGRESS_REPORTER (const PROGRESS_REPORTER &)=delete
 
virtual ~PROGRESS_REPORTER ()
 
void SetNumPhases (int aNumPhases)
 Set the number of phases. More...
 
void AddPhases (int aNumPhases)
 
virtual void BeginPhase (int aPhase)
 Initialize the aPhase virtual zone of the dialog progress bar. More...
 
virtual void AdvancePhase ()
 Use the next available virtual zone of the dialog progress bar. More...
 
virtual void AdvancePhase (const wxString &aMessage)
 Use the next available virtual zone of the dialog progress bar and updates the message. More...
 
virtual void Report (const wxString &aMessage)
 Display aMessage in the progress bar dialog. More...
 
virtual void SetCurrentProgress (double aProgress)
 Set the progress value to aProgress (0..1). More...
 
void SetMaxProgress (int aMaxProgress)
 Fix the value that gives the 100 percent progress bar length (inside the current virtual zone). More...
 
void AdvanceProgress ()
 Increment the progress bar length (inside the current virtual zone). More...
 
bool KeepRefreshing (bool aWait=false)
 Update the UI dialog. More...
 
virtual void SetTitle (const wxString &aTitle)
 Change the title displayed on the window caption. More...
 
bool IsCancelled () const
 

Protected Member Functions

int currentProgress () const
 
virtual bool updateUI ()=0
 

Protected Attributes

wxString m_rptMessage
 
bool m_msgChanged
 
std::mutex m_mutex
 
std::atomic_int m_phase
 
std::atomic_int m_numPhases
 
std::atomic_int m_progress
 
std::atomic_int m_maxProgress
 
std::atomic_bool m_cancelled
 

Detailed Description

A progress reporter for use in multi-threaded environments.

The various advancement and message methods can be called from sub-threads. The KeepRefreshing method MUST be called only from the main thread (primarily a MSW requirement, which won't allow access to UI objects allocated from a separate thread).

Definition at line 45 of file progress_reporter.h.

Constructor & Destructor Documentation

◆ PROGRESS_REPORTER() [1/2]

PROGRESS_REPORTER::PROGRESS_REPORTER ( int  aNumPhases)

Definition at line 31 of file progress_reporter.cpp.

31  :
32  m_msgChanged( false ),
33  m_phase( 0 ),
34  m_numPhases( aNumPhases ),
35  m_progress( 0 ),
36  m_maxProgress( 1000 ),
37  m_cancelled( false )
38 {
39 }
std::atomic_int m_phase
std::atomic_int m_progress
std::atomic_int m_numPhases
std::atomic_bool m_cancelled
std::atomic_int m_maxProgress

◆ PROGRESS_REPORTER() [2/2]

PROGRESS_REPORTER::PROGRESS_REPORTER ( const PROGRESS_REPORTER )
delete

◆ ~PROGRESS_REPORTER()

virtual PROGRESS_REPORTER::~PROGRESS_REPORTER ( )
inlinevirtual

Definition at line 52 of file progress_reporter.h.

53  {
54  }

Member Function Documentation

◆ AddPhases()

void PROGRESS_REPORTER::AddPhases ( int  aNumPhases)

Definition at line 95 of file progress_reporter.cpp.

96 {
97  m_numPhases += aNumPhases;
98 }
std::atomic_int m_numPhases

References m_numPhases.

◆ AdvancePhase() [1/2]

void PROGRESS_REPORTER::AdvancePhase ( )
virtual

Use the next available virtual zone of the dialog progress bar.

Definition at line 49 of file progress_reporter.cpp.

50 {
51  m_phase.fetch_add( 1 );
52  m_progress.store( 0 );
53 }
std::atomic_int m_phase
std::atomic_int m_progress

References m_phase, and m_progress.

Referenced by DIALOG_ERC::AdvancePhase(), AdvancePhase(), DIALOG_DRC::AdvancePhase(), ZONE_FILLER::Fill(), FOOTPRINT_LIST_IMPL::ReadFootprintFiles(), DRC_ENGINE::ReportPhase(), DRC_TOOL::RunTests(), DIALOG_ERC::testErc(), and SYMBOL_ASYNC_LOADER::worker().

◆ AdvancePhase() [2/2]

void PROGRESS_REPORTER::AdvancePhase ( const wxString &  aMessage)
virtual

Use the next available virtual zone of the dialog progress bar and updates the message.

Reimplemented in DIALOG_DRC, and DIALOG_ERC.

Definition at line 56 of file progress_reporter.cpp.

57 {
58  AdvancePhase();
59  Report( aMessage );
60 }
virtual void AdvancePhase()
Use the next available virtual zone of the dialog progress bar.
virtual void Report(const wxString &aMessage)
Display aMessage in the progress bar dialog.

References AdvancePhase(), and Report().

◆ AdvanceProgress()

void PROGRESS_REPORTER::AdvanceProgress ( )

Increment the progress bar length (inside the current virtual zone).

Definition at line 83 of file progress_reporter.cpp.

84 {
85  m_progress.fetch_add( 1 );
86 }
std::atomic_int m_progress

References m_progress.

Referenced by AR_AUTOPLACER::AutoplaceFootprints(), ZONE_FILLER::Fill(), FOOTPRINT_LIST_IMPL::joinWorkers(), and FOOTPRINT_LIST_IMPL::loader_job().

◆ BeginPhase()

void PROGRESS_REPORTER::BeginPhase ( int  aPhase)
virtual

Initialize the aPhase virtual zone of the dialog progress bar.

Definition at line 42 of file progress_reporter.cpp.

43 {
44  m_phase.store( aPhase );
45  m_progress.store( 0 );
46 }
std::atomic_int m_phase
std::atomic_int m_progress

References m_phase, and m_progress.

◆ currentProgress()

int PROGRESS_REPORTER::currentProgress ( ) const
protected

Definition at line 101 of file progress_reporter.cpp.

102 {
103  double current = ( 1.0 / (double) m_numPhases ) *
104  ( (double) m_phase + ( (double) m_progress.load() / (double) m_maxProgress ) );
105 
106  return (int)( current * 1000 );
107 }
std::atomic_int m_phase
std::atomic_int m_progress
std::atomic_int m_numPhases
std::atomic_int m_maxProgress

References m_maxProgress, m_numPhases, m_phase, and m_progress.

Referenced by WX_PROGRESS_REPORTER::updateUI(), and GAUGE_PROGRESS_REPORTER::updateUI().

◆ IsCancelled()

bool PROGRESS_REPORTER::IsCancelled ( ) const
inline

◆ KeepRefreshing()

bool PROGRESS_REPORTER::KeepRefreshing ( bool  aWait = false)

Update the UI dialog.

Warning
This should only be called from the main thread.
Returns
false if the user clicked Cancel.

Definition at line 110 of file progress_reporter.cpp.

111 {
112  if( aWait )
113  {
114  while( m_progress.load() < m_maxProgress && m_maxProgress > 0 )
115  {
116  if( !updateUI() )
117  {
118  m_cancelled.store( true );
119  return false;
120  }
121 
122  wxMilliSleep( 20 );
123  }
124 
125  return true;
126  }
127  else
128  {
129  if( !updateUI() )
130  {
131  m_cancelled.store( true );
132  return false;
133  }
134 
135  return true;
136  }
137 }
std::atomic_int m_progress
std::atomic_bool m_cancelled
virtual bool updateUI()=0
std::atomic_int m_maxProgress

References m_cancelled, m_maxProgress, m_progress, and updateUI().

Referenced by AR_AUTOPLACER::AutoplaceFootprints(), SCH_SEXPR_PARSER::checkpoint(), SCH_EAGLE_PLUGIN::checkpoint(), LEGACY_PLUGIN::checkpoint(), ALTIUM_PCB::checkpoint(), SCH_LEGACY_PLUGIN::checkpoint(), EAGLE_PLUGIN::checkpoint(), FABMASTER::checkpoint(), ZONE_FILLER::Fill(), FOOTPRINT_LIST_IMPL::joinWorkers(), FABMASTER_PLUGIN::Load(), LEGACY_PLUGIN::Load(), SCH_EAGLE_PLUGIN::Load(), EAGLE_PLUGIN::Load(), PCB_IO::Load(), SCH_SEXPR_PLUGIN::loadFile(), SCH_LEGACY_PLUGIN::loadFile(), SYMBOL_LIBRARY_MANAGER::Preload(), FOOTPRINT_LIST_IMPL::ReadFootprintFiles(), DRC_ENGINE::ReportPhase(), DRC_ENGINE::ReportProgress(), reportProgress(), and CN_CONNECTIVITY_ALGO::searchConnections().

◆ Report()

void PROGRESS_REPORTER::Report ( const wxString &  aMessage)
virtual

◆ SetCurrentProgress()

void PROGRESS_REPORTER::SetCurrentProgress ( double  aProgress)
virtual

◆ SetMaxProgress()

void PROGRESS_REPORTER::SetMaxProgress ( int  aMaxProgress)

Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).

Definition at line 71 of file progress_reporter.cpp.

72 {
73  m_maxProgress.store( aMaxProgress );
74 }
std::atomic_int m_maxProgress

References m_maxProgress.

Referenced by AR_AUTOPLACER::AutoplaceFootprints(), ZONE_FILLER::Fill(), FOOTPRINT_LIST_IMPL::ReadFootprintFiles(), and CN_CONNECTIVITY_ALGO::searchConnections().

◆ SetNumPhases()

void PROGRESS_REPORTER::SetNumPhases ( int  aNumPhases)

Set the number of phases.

Definition at line 89 of file progress_reporter.cpp.

90 {
91  m_numPhases = aNumPhases;
92 }
std::atomic_int m_numPhases

References m_numPhases.

◆ SetTitle()

virtual void PROGRESS_REPORTER::SetTitle ( const wxString &  aTitle)
inlinevirtual

Change the title displayed on the window caption.

Has meaning only for some reporters. Does nothing for others.

Warning
This should only be called from the main thread.

Reimplemented in WX_PROGRESS_REPORTER.

Definition at line 115 of file progress_reporter.h.

115 {}

Referenced by AR_AUTOPLACER::AutoplaceFootprints().

◆ updateUI()

virtual bool PROGRESS_REPORTER::updateUI ( )
protectedpure virtual

Member Data Documentation

◆ m_cancelled

std::atomic_bool PROGRESS_REPORTER::m_cancelled
protected

◆ m_maxProgress

std::atomic_int PROGRESS_REPORTER::m_maxProgress
protected

◆ m_msgChanged

bool PROGRESS_REPORTER::m_msgChanged
protected

Definition at line 126 of file progress_reporter.h.

Referenced by Report(), and WX_PROGRESS_REPORTER::updateUI().

◆ m_mutex

std::mutex PROGRESS_REPORTER::m_mutex
mutableprotected

Definition at line 128 of file progress_reporter.h.

Referenced by Report(), and WX_PROGRESS_REPORTER::updateUI().

◆ m_numPhases

std::atomic_int PROGRESS_REPORTER::m_numPhases
protected

Definition at line 130 of file progress_reporter.h.

Referenced by AddPhases(), currentProgress(), and SetNumPhases().

◆ m_phase

std::atomic_int PROGRESS_REPORTER::m_phase
protected

Definition at line 129 of file progress_reporter.h.

Referenced by AdvancePhase(), BeginPhase(), and currentProgress().

◆ m_progress

std::atomic_int PROGRESS_REPORTER::m_progress
protected

◆ m_rptMessage

wxString PROGRESS_REPORTER::m_rptMessage
protected

The documentation for this class was generated from the following files: