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
 
virtual ~PROGRESS_REPORTER ()
 
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 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 40 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( 1 ),
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 47 of file progress_reporter.h.

48  {
49  }

Member Function Documentation

◆ AdvancePhase()

void PROGRESS_REPORTER::AdvancePhase ( )

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 ZONE_FILLER::Fill(), and FOOTPRINT_LIST_IMPL::ReadFootprintFiles().

◆ AdvanceProgress()

void PROGRESS_REPORTER::AdvanceProgress ( )

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

Definition at line 72 of file progress_reporter.cpp.

73 {
74  m_progress.fetch_add( 1 );
75 }
std::atomic_int m_progress

References m_progress.

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

◆ BeginPhase()

void PROGRESS_REPORTER::BeginPhase ( int  aPhase)

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 78 of file progress_reporter.cpp.

79 {
80  double current = ( 1.0 / (double) m_numPhases ) *
81  ( (double) m_phase + ( (double) m_progress.load() / (double) m_maxProgress ) );
82 
83  return (int)( current * 1000 );
84 }
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

Definition at line 95 of file progress_reporter.h.

95 { return m_cancelled.load(); }
std::atomic_bool m_cancelled

References m_cancelled.

Referenced by ZONE_FILLER::computeRawFilledArea(), ZONE_FILLER::Fill(), and ZONE_FILLER::fillSingleZone().

◆ 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 87 of file progress_reporter.cpp.

88 {
89  if( aWait )
90  {
91  while( m_progress < m_maxProgress && m_maxProgress > 0 )
92  {
93  if( !updateUI() )
94  {
95  m_cancelled.store( true );
96  return false;
97  }
98 
99  wxMilliSleep( 20 );
100  }
101  return true;
102  }
103  else
104  {
105  if( !updateUI() )
106  {
107  m_cancelled.store( true );
108  return false;
109  }
110 
111  return true;
112  }
113 }
std::atomic_bool m_cancelled
virtual bool updateUI()=0

References m_cancelled, and updateUI().

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

◆ Report()

void PROGRESS_REPORTER::Report ( const wxString &  aMessage)

Display aMessage in the progress bar dialog.

Definition at line 53 of file progress_reporter.cpp.

54 {
55  std::lock_guard<std::mutex> guard( m_mutex );
56  m_rptMessage = aMessage;
57 }

References m_mutex, and m_rptMessage.

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

◆ SetCurrentProgress()

void PROGRESS_REPORTER::SetCurrentProgress ( double  aProgress)

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

Definition at line 65 of file progress_reporter.cpp.

66 {
67  m_maxProgress.store( 10000 );
68  m_progress.store( (int) (aProgress * 10000.0) );
69 }
std::atomic_int m_progress
std::atomic_int m_maxProgress

References m_maxProgress, and m_progress.

◆ 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 60 of file progress_reporter.cpp.

61 {
62  m_maxProgress.store( aMaxProgress );
63 }
std::atomic_int m_maxProgress

References m_maxProgress.

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

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

93 {}

Referenced by AR_AUTOPLACER::AutoplaceModules().

◆ updateUI()

virtual bool PROGRESS_REPORTER::updateUI ( )
protectedpure virtual

Implemented in GAUGE_PROGRESS_REPORTER, and WX_PROGRESS_REPORTER.

Referenced by KeepRefreshing().

Member Data Documentation

◆ m_cancelled

std::atomic_bool PROGRESS_REPORTER::m_cancelled
protected

Definition at line 109 of file progress_reporter.h.

Referenced by IsCancelled(), and KeepRefreshing().

◆ m_maxProgress

std::atomic_int PROGRESS_REPORTER::m_maxProgress
protected

Definition at line 108 of file progress_reporter.h.

Referenced by currentProgress(), SetCurrentProgress(), and SetMaxProgress().

◆ m_mutex

std::mutex PROGRESS_REPORTER::m_mutex
mutableprotected

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

Referenced by currentProgress().

◆ m_phase

std::atomic_int PROGRESS_REPORTER::m_phase
protected

Definition at line 105 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

Definition at line 103 of file progress_reporter.h.

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


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