KiCad PCB EDA Suite
GAUGE_PROGRESS_REPORTER Class Reference

#include <progress_reporter.h>

Inheritance diagram for GAUGE_PROGRESS_REPORTER:
PROGRESS_REPORTER

Public Member Functions

 GAUGE_PROGRESS_REPORTER (wxWindow *aParent, int aNumPhases)
 
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
 

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
 

Private Member Functions

bool updateUI () override
 

Detailed Description

Definition at line 118 of file progress_reporter.h.

Constructor & Destructor Documentation

GAUGE_PROGRESS_REPORTER::GAUGE_PROGRESS_REPORTER ( wxWindow *  aParent,
int  aNumPhases 
)
Parameters
aParentis the parent of the wxGauge control
aNumPhasesis the number of "virtual sections" of the progress bar aNumPhases = 1 is the usual progress bar aNumPhases = n creates n virtual progress bar zones: a 0 to 100 percent width of a virtual zone fills 0 to 1/n progress bar full size of the nth virtual zone index

Definition at line 139 of file progress_reporter.cpp.

139  :
140  PROGRESS_REPORTER( aNumPhases ),
141  wxGauge( aParent, wxID_ANY, 1000, wxDefaultPosition, wxDefaultSize,
142  wxGA_HORIZONTAL, wxDefaultValidator, wxGaugeNameStr )
143 {
144 }
PROGRESS_REPORTER(int aNumPhases)

Member Function Documentation

void PROGRESS_REPORTER::AdvancePhase ( )
inherited

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

Definition at line 45 of file progress_reporter.cpp.

References PROGRESS_REPORTER::m_phase, and PROGRESS_REPORTER::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 ( )
inherited

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

Definition at line 65 of file progress_reporter.cpp.

References PROGRESS_REPORTER::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)
inherited

initialize the aPhase virtual zone of the dialog progress bar

Definition at line 38 of file progress_reporter.cpp.

References PROGRESS_REPORTER::m_phase, and PROGRESS_REPORTER::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
protectedinherited

Definition at line 71 of file progress_reporter.cpp.

References PROGRESS_REPORTER::m_maxProgress, PROGRESS_REPORTER::m_numPhases, PROGRESS_REPORTER::m_phase, and PROGRESS_REPORTER::m_progress.

Referenced by WX_PROGRESS_REPORTER::updateUI(), and 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)
inherited

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 PROGRESS_REPORTER::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)
inherited

Display aMessage in the progress bar dialog.

Definition at line 52 of file progress_reporter.cpp.

References PROGRESS_REPORTER::m_mutex, and PROGRESS_REPORTER::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)
inherited

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 PROGRESS_REPORTER::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
bool GAUGE_PROGRESS_REPORTER::updateUI ( )
overrideprivatevirtual

Implements PROGRESS_REPORTER.

Definition at line 147 of file progress_reporter.cpp.

References PROGRESS_REPORTER::currentProgress().

148 {
149  int cur = currentProgress();
150 
151  if( cur < 0 || cur > 1000 )
152  cur = 0;
153 
154  wxGauge::SetValue( cur );
155  wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI);
156 
157  return true; // No cancel button on a wxGauge
158 }
int currentProgress() const

Member Data Documentation

std::atomic_int PROGRESS_REPORTER::m_maxProgress
protectedinherited
std::mutex PROGRESS_REPORTER::m_mutex
mutableprotectedinherited
std::atomic_int PROGRESS_REPORTER::m_numPhases
protectedinherited

Definition at line 88 of file progress_reporter.h.

Referenced by PROGRESS_REPORTER::currentProgress().

std::atomic_int PROGRESS_REPORTER::m_phase
protectedinherited
std::atomic_int PROGRESS_REPORTER::m_progress
protectedinherited
wxString PROGRESS_REPORTER::m_rptMessage
protectedinherited

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