KiCad PCB EDA Suite
WX_PROGRESS_REPORTER Class Reference

Multi-thread safe progress reporter dialog, intended for use of tasks that paralleize reporting back of work status See PROGRESS_REPORTER. More...

#include <progress_reporter.h>

Inheritance diagram for WX_PROGRESS_REPORTER:
PROGRESS_REPORTER

Public Member Functions

 WX_PROGRESS_REPORTER (wxWindow *aParent, const wxString &aTitle, int aNumPhases, bool aCanAbort=true, bool aReserveSpaceForMessage=true)
 Ctor: the PROGRESS_REPORTER will stay on top of aParent. More...
 
 ~WX_PROGRESS_REPORTER ()
 
virtual void SetTitle (const wxString &aTitle) override
 change the title displayed on the window caption More...
 
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...
 
bool IsCancelled () const
 

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
 
std::atomic_bool m_cancelled
 

Private Member Functions

virtual bool updateUI () override
 

Detailed Description

Multi-thread safe progress reporter dialog, intended for use of tasks that paralleize reporting back of work status See PROGRESS_REPORTER.

Definition at line 131 of file progress_reporter.h.

Constructor & Destructor Documentation

◆ WX_PROGRESS_REPORTER()

WX_PROGRESS_REPORTER::WX_PROGRESS_REPORTER ( wxWindow *  aParent,
const wxString &  aTitle,
int  aNumPhases,
bool  aCanAbort = true,
bool  aReserveSpaceForMessage = true 
)

Ctor: the PROGRESS_REPORTER will stay on top of aParent.

the style is wxPD_AUTO_HIDE | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME

Parameters
aParentis the wxDialog of Frame that manage this.
aTitleis the dialog progress title
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
aCanAbortis true if the abort button should be shown
aReserveSpaceForMessagewill ensure that the dialog is laid out for status messages, preventing layout issues on Windows when reporting a message after the initial layout

Definition at line 135 of file progress_reporter.cpp.

137  :
138  PROGRESS_REPORTER( aNumPhases ),
139  wxProgressDialog( aTitle, ( aReserveSpaceForMessage ? wxT( " " ) : wxT( "" ) ), 1, aParent,
140  // wxPD_APP_MODAL | // Don't use; messes up OSX when called from
141  // quasi-modal dialog
142  wxPD_AUTO_HIDE | // *MUST* use; otherwise wxWidgets will spin
143  // up another event loop on completion which
144  // causes all sorts of grief
145  ( aCanAbort ? wxPD_CAN_ABORT : 0 ) |
146  wxPD_ELAPSED_TIME )
147 #if wxCHECK_VERSION( 3, 1, 0 )
148  ,
149  m_appProgressIndicator( aParent )
150 #endif
151 {
152 #if wxCHECK_VERSION( 3, 1, 0 )
153  // wxAppProgressIndicator doesn't like value > max, ever. However there are some risks
154  // with multithreaded setting of those values making a mess
155  // the cop out is just to set the progress to "indeterminate"
156  m_appProgressIndicator.Pulse();
157 #endif
158 }
PROGRESS_REPORTER(int aNumPhases)

◆ ~WX_PROGRESS_REPORTER()

WX_PROGRESS_REPORTER::~WX_PROGRESS_REPORTER ( )

Definition at line 161 of file progress_reporter.cpp.

162 {
163 }

Member Function Documentation

◆ AddPhases()

void PROGRESS_REPORTER::AddPhases ( int  aNumPhases)
inherited

Definition at line 91 of file progress_reporter.cpp.

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

References PROGRESS_REPORTER::m_numPhases.

◆ AdvancePhase() [1/2]

void PROGRESS_REPORTER::AdvancePhase ( )
virtualinherited

◆ AdvancePhase() [2/2]

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

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 PROGRESS_REPORTER::AdvancePhase(), and PROGRESS_REPORTER::Report().

◆ AdvanceProgress()

void PROGRESS_REPORTER::AdvanceProgress ( )
inherited

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

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 PROGRESS_REPORTER::m_phase, and PROGRESS_REPORTER::m_progress.

◆ currentProgress()

int PROGRESS_REPORTER::currentProgress ( ) const
protectedinherited

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 PROGRESS_REPORTER::m_maxProgress, PROGRESS_REPORTER::m_numPhases, PROGRESS_REPORTER::m_phase, and PROGRESS_REPORTER::m_progress.

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

◆ IsCancelled()

bool PROGRESS_REPORTER::IsCancelled ( ) const
inlineinherited

◆ 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 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 PROGRESS_REPORTER::m_cancelled, PROGRESS_REPORTER::m_maxProgress, PROGRESS_REPORTER::m_progress, and PROGRESS_REPORTER::updateUI().

Referenced by AR_AUTOPLACER::AutoplaceFootprints(), ZONE_FILLER::Fill(), FOOTPRINT_LIST_IMPL::joinWorkers(), SYMBOL_LIBRARY_MANAGER::Preload(), FOOTPRINT_LIST_IMPL::ReadFootprintFiles(), DRC_ENGINE::ReportPhase(), DRC_ENGINE::ReportProgress(), reportProgress(), and CN_CONNECTIVITY_ALGO::searchConnections().

◆ Report()

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

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 PROGRESS_REPORTER::m_mutex, and PROGRESS_REPORTER::m_rptMessage.

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

◆ SetCurrentProgress()

void PROGRESS_REPORTER::SetCurrentProgress ( double  aProgress)
virtualinherited

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

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

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 PROGRESS_REPORTER::m_numPhases.

◆ SetTitle()

virtual void WX_PROGRESS_REPORTER::SetTitle ( const wxString &  aTitle)
inlineoverridevirtual

change the title displayed on the window caption

Reimplemented from PROGRESS_REPORTER.

Definition at line 153 of file progress_reporter.h.

154  {
155  wxProgressDialog::SetTitle( aTitle );
156  }

◆ updateUI()

bool WX_PROGRESS_REPORTER::updateUI ( )
overrideprivatevirtual

Implements PROGRESS_REPORTER.

Definition at line 166 of file progress_reporter.cpp.

167 {
168  int cur = currentProgress();
169 
170  if( cur < 0 || cur > 1000 )
171  cur = 0;
172 
173  wxString message;
174  {
175  std::lock_guard<std::mutex> guard( m_mutex );
176  message = m_rptMessage;
177  }
178 
179  SetRange( 1000 );
180  return wxProgressDialog::Update( cur, message );
181 }
int currentProgress() const

References PROGRESS_REPORTER::currentProgress(), PROGRESS_REPORTER::m_mutex, and PROGRESS_REPORTER::m_rptMessage.

Member Data Documentation

◆ m_cancelled

std::atomic_bool PROGRESS_REPORTER::m_cancelled
protectedinherited

◆ m_maxProgress

◆ m_mutex

std::mutex PROGRESS_REPORTER::m_mutex
mutableprotectedinherited

Definition at line 119 of file progress_reporter.h.

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

◆ m_numPhases

std::atomic_int PROGRESS_REPORTER::m_numPhases
protectedinherited

◆ 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: