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)
 sets 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 ()
 Uses the next vailable virtual zone of the dialog progress bar. More...
 
virtual void AdvancePhase (const wxString &aMessage)
 Uses the next vailable 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 thar gives the 100 precent 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 MUST only be called from the main thread. More...
 
bool IsCancelled () const
 

Protected Member Functions

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

Protected Attributes

wxString m_rptMessage
 
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 43 of file progress_reporter.h.

Constructor & Destructor Documentation

◆ PROGRESS_REPORTER() [1/2]

PROGRESS_REPORTER::PROGRESS_REPORTER ( int  aNumPhases)

Definition at line 29 of file progress_reporter.cpp.

29  :
30  m_phase( 0 ),
31  m_numPhases( aNumPhases ),
32  m_progress( 0 ),
33  m_maxProgress( 1000 ),
34  m_cancelled( false )
35 {
36 }
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 50 of file progress_reporter.h.

51  {
52  }

Member Function Documentation

◆ AddPhases()

void PROGRESS_REPORTER::AddPhases ( int  aNumPhases)

Definition at line 91 of file progress_reporter.cpp.

92 {
93  m_numPhases += aNumPhases;
94 }
std::atomic_int m_numPhases

References m_numPhases.

Referenced by DRC_ENGINE::RunTests().

◆ AdvancePhase() [1/2]

void PROGRESS_REPORTER::AdvancePhase ( )
virtual

Uses the next vailable virtual zone of the dialog progress bar.

Definition at line 46 of file progress_reporter.cpp.

47 {
48  m_phase.fetch_add( 1 );
49  m_progress.store( 0 );
50 }
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(), and DIALOG_ERC::testErc().

◆ AdvancePhase() [2/2]

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

Uses the next vailable virtual zone of the dialog progress bar and updates the message.

Reimplemented in DIALOG_DRC, and DIALOG_ERC.

Definition at line 53 of file progress_reporter.cpp.

54 {
55  AdvancePhase();
56  Report( aMessage );
57 }
virtual void AdvancePhase()
Uses the next vailable 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 79 of file progress_reporter.cpp.

80 {
81  m_progress.fetch_add( 1 );
82 }
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 39 of file progress_reporter.cpp.

40 {
41  m_phase.store( aPhase );
42  m_progress.store( 0 );
43 }
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 97 of file progress_reporter.cpp.

98 {
99  double current = ( 1.0 / (double) m_numPhases ) *
100  ( (double) m_phase + ( (double) m_progress.load() / (double) m_maxProgress ) );
101 
102  return (int)( current * 1000 );
103 }
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.

MUST only be called from the main thread. Returns false if the user clicked Cancel.

Definition at line 106 of file progress_reporter.cpp.

107 {
108  if( aWait )
109  {
110  while( m_progress.load() < m_maxProgress && m_maxProgress > 0 )
111  {
112  if( !updateUI() )
113  {
114  m_cancelled.store( true );
115  return false;
116  }
117 
118  wxMilliSleep( 20 );
119  }
120  return true;
121  }
122  else
123  {
124  if( !updateUI() )
125  {
126  m_cancelled.store( true );
127  return false;
128  }
129 
130  return true;
131  }
132 }
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(), ZONE_FILLER::Fill(), FOOTPRINT_LIST_IMPL::joinWorkers(), 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

Display aMessage in the progress bar dialog.

Reimplemented in DIALOG_ERC.

Definition at line 60 of file progress_reporter.cpp.

61 {
62  std::lock_guard<std::mutex> guard( m_mutex );
63  m_rptMessage = aMessage;
64 }

References m_mutex, and m_rptMessage.

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

◆ SetCurrentProgress()

void PROGRESS_REPORTER::SetCurrentProgress ( double  aProgress)
virtual

Set the progress value to aProgress (0..1)

Reimplemented in CONSOLE_PROGRESS_REPORTER.

Definition at line 72 of file progress_reporter.cpp.

73 {
74  m_maxProgress.store( 1000 );
75  m_progress.store( (int) (aProgress * 1000.0) );
76 }
std::atomic_int m_progress
std::atomic_int m_maxProgress

References m_maxProgress, and m_progress.

Referenced by DIALOG_ERC::AdvancePhase(), DIALOG_DRC::AdvancePhase(), DRC_ENGINE::ReportProgress(), reportProgress(), and CONSOLE_PROGRESS_REPORTER::SetCurrentProgress().

◆ SetMaxProgress()

void PROGRESS_REPORTER::SetMaxProgress ( int  aMaxProgress)

Fix the value thar gives the 100 precent progress bar length (inside the current virtual zone)

Definition at line 67 of file progress_reporter.cpp.

68 {
69  m_maxProgress.store( aMaxProgress );
70 }
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)

sets the number of phases

Definition at line 85 of file progress_reporter.cpp.

86 {
87  m_numPhases = aNumPhases;
88 }
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 MUST only be called from the main thread.

Has meaning only for some reporters. Do nothing for others

Reimplemented in WX_PROGRESS_REPORTER.

Definition at line 108 of file progress_reporter.h.

108 {}

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_mutex

std::mutex PROGRESS_REPORTER::m_mutex
mutableprotected

Definition at line 119 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 121 of file progress_reporter.h.

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

◆ m_phase

std::atomic_int PROGRESS_REPORTER::m_phase
protected

Definition at line 120 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: