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 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...
 

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

Constructor & Destructor Documentation

◆ GAUGE_PROGRESS_REPORTER()

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

144  :
145  PROGRESS_REPORTER( aNumPhases ),
146  wxGauge( aParent, wxID_ANY, 1000, wxDefaultPosition, wxDefaultSize,
147  wxGA_HORIZONTAL, wxDefaultValidator, wxGaugeNameStr )
148 {
149 }
PROGRESS_REPORTER(int aNumPhases)

Member Function Documentation

◆ AdvancePhase()

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.

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

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

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

◆ AdvanceProgress()

void PROGRESS_REPORTER::AdvanceProgress ( )
inherited

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

Definition at line 71 of file progress_reporter.cpp.

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

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

initialize the aPhase virtual zone of the dialog progress bar

Definition at line 38 of file progress_reporter.cpp.

39 {
40  m_phase.store( aPhase );
41  m_progress.store( 0 );
42 }
std::atomic_int m_phase
std::atomic_int m_progress

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

◆ currentProgress()

int PROGRESS_REPORTER::currentProgress ( ) const
protectedinherited

Definition at line 77 of file progress_reporter.cpp.

78 {
79  double current = ( 1.0 / (double) m_numPhases ) *
80  ( (double) m_phase + ( (double) m_progress.load() / (double) m_maxProgress ) );
81 
82  return (int)( current * 1000 );
83 }
std::atomic_int m_phase
std::atomic_int m_progress
std::atomic_int m_numPhases
std::atomic_int m_maxProgress

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().

◆ KeepRefreshing()

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

87 {
88  if( aWait )
89  {
90  while( m_progress < m_maxProgress && m_maxProgress > 0 )
91  {
92  if( !updateUI() )
93  return false;
94 
95  wxMilliSleep( 20 );
96  }
97  return true;
98  }
99  else
100  {
101  return updateUI();
102  }
103 }
virtual bool updateUI()=0

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().

◆ Report()

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

Display aMessage in the progress bar dialog.

Definition at line 52 of file progress_reporter.cpp.

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

References PROGRESS_REPORTER::m_mutex, and PROGRESS_REPORTER::m_rptMessage.

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

◆ SetCurrentProgress()

void PROGRESS_REPORTER::SetCurrentProgress ( double  aProgress)
inherited

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

Definition at line 64 of file progress_reporter.cpp.

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

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

◆ SetMaxProgress()

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.

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

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

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()

bool GAUGE_PROGRESS_REPORTER::updateUI ( )
overrideprivatevirtual

Implements PROGRESS_REPORTER.

Definition at line 152 of file progress_reporter.cpp.

153 {
154  int cur = currentProgress();
155 
156  if( cur < 0 || cur > 1000 )
157  cur = 0;
158 
159  wxGauge::SetValue( cur );
160  wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI);
161 
162  return true; // No cancel button on a wxGauge
163 }
int currentProgress() const

References PROGRESS_REPORTER::currentProgress().

Member Data Documentation

◆ m_maxProgress

std::atomic_int PROGRESS_REPORTER::m_maxProgress
protectedinherited

◆ m_mutex

std::mutex PROGRESS_REPORTER::m_mutex
mutableprotectedinherited

◆ m_numPhases

std::atomic_int PROGRESS_REPORTER::m_numPhases
protectedinherited

Definition at line 105 of file progress_reporter.h.

Referenced by PROGRESS_REPORTER::currentProgress().

◆ m_phase

std::atomic_int PROGRESS_REPORTER::m_phase
protectedinherited

◆ m_progress

◆ m_rptMessage

wxString PROGRESS_REPORTER::m_rptMessage
protectedinherited

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