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:
GAUGE_PROGRESS_REPORTER WX_PROGRESS_REPORTER

Public Member Functions

 PROGRESS_REPORTER (int aNumPhases)
 
 PROGRESS_REPORTER (const PROGRESS_REPORTER &)=delete
 
void BeginPhase (int aPhase)
 initialize the aPhase virtual zone of the dialog progress bar More...
 
void AdvancePhase ()
 Uses the next vailable virtual zone of the dialog progress bar. More...
 
void Report (const wxString &aMessage)
 Display aMessage in the progress bar dialog. 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...
 

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
 

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 40 of file progress_reporter.h.

Constructor & Destructor Documentation

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( 1 )
34 {
35 }
std::atomic_int m_phase
std::atomic_int m_progress
std::atomic_int m_numPhases
std::atomic_int m_maxProgress
PROGRESS_REPORTER::PROGRESS_REPORTER ( const PROGRESS_REPORTER )
delete

Member Function Documentation

void PROGRESS_REPORTER::AdvancePhase ( )

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

Definition at line 45 of file progress_reporter.cpp.

References m_phase, and m_progress.

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

46 {
47  m_phase.fetch_add( 1 );
48  m_progress.store( 0 );
49 }
std::atomic_int m_phase
std::atomic_int m_progress
void PROGRESS_REPORTER::AdvanceProgress ( )

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

Definition at line 65 of file progress_reporter.cpp.

References m_progress.

Referenced by AR_AUTOPLACER::AutoplaceModules(), ZONE_FILLER::Fill(), FOOTPRINT_LIST_IMPL::JoinWorkers(), and FOOTPRINT_LIST_IMPL::loader_job().

66 {
67  m_progress.fetch_add( 1 );
68 }
std::atomic_int m_progress
void PROGRESS_REPORTER::BeginPhase ( int  aPhase)

initialize the aPhase virtual zone of the dialog progress bar

Definition at line 38 of file progress_reporter.cpp.

References m_phase, and m_progress.

39 {
40  m_phase.store( aPhase );
41  m_progress.store( 0 );
42 }
std::atomic_int m_phase
std::atomic_int m_progress
int PROGRESS_REPORTER::currentProgress ( ) const
protected

Definition at line 71 of file progress_reporter.cpp.

References m_maxProgress, m_numPhases, m_phase, and m_progress.

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

72 {
73  double current = ( 1.0 / (double) m_numPhases ) *
74  ( (double) m_phase + ( (double) m_progress.load() / (double) m_maxProgress ) );
75 
76  return (int)( current * 1000 );
77 }
std::atomic_int m_phase
std::atomic_int m_progress
std::atomic_int m_numPhases
std::atomic_int m_maxProgress
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 80 of file progress_reporter.cpp.

References updateUI().

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

81 {
82  if( aWait )
83  {
84  while( m_progress < m_maxProgress && m_maxProgress > 0 )
85  {
86  if( !updateUI() )
87  return false;
88 
89  wxMilliSleep( 20 );
90  }
91  return true;
92  }
93  else
94  {
95  return updateUI();
96  }
97 }
virtual bool updateUI()=0
void PROGRESS_REPORTER::Report ( const wxString &  aMessage)

Display aMessage in the progress bar dialog.

Definition at line 52 of file progress_reporter.cpp.

References m_mutex, and m_rptMessage.

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

53 {
54  std::lock_guard<std::mutex> guard( m_mutex );
55  m_rptMessage = aMessage;
56 }
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 59 of file progress_reporter.cpp.

References m_maxProgress.

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

60 {
61  m_maxProgress.store( aMaxProgress );
62 }
std::atomic_int m_maxProgress
virtual bool PROGRESS_REPORTER::updateUI ( )
protectedpure virtual

Implemented in GAUGE_PROGRESS_REPORTER, and WX_PROGRESS_REPORTER.

Referenced by KeepRefreshing().

Member Data Documentation

std::atomic_int PROGRESS_REPORTER::m_maxProgress
protected

Definition at line 90 of file progress_reporter.h.

Referenced by currentProgress(), and SetMaxProgress().

std::mutex PROGRESS_REPORTER::m_mutex
mutableprotected

Definition at line 86 of file progress_reporter.h.

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

std::atomic_int PROGRESS_REPORTER::m_numPhases
protected

Definition at line 88 of file progress_reporter.h.

Referenced by currentProgress().

std::atomic_int PROGRESS_REPORTER::m_phase
protected

Definition at line 87 of file progress_reporter.h.

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

std::atomic_int PROGRESS_REPORTER::m_progress
protected

Definition at line 89 of file progress_reporter.h.

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

wxString PROGRESS_REPORTER::m_rptMessage
protected

Definition at line 85 of file progress_reporter.h.

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


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