KiCad PCB EDA Suite
WX_PROGRESS_REPORTER Class Reference

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

virtual bool updateUI () override
 

Detailed Description

Definition at line 102 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 
)

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

Definition at line 100 of file progress_reporter.cpp.

101  :
102  PROGRESS_REPORTER( aNumPhases ),
103  wxProgressDialog( aTitle, wxT( "" ), 1, aParent,
104  // wxPD_APP_MODAL | // Don't use; messes up OSX when called from
105  // quasi-modal dialog
106  wxPD_AUTO_HIDE | // *MUST* use; otherwise wxWidgets will spin
107  // up another event loop on completion which
108  // causes all sorts of grief
109  ( aCanAbort ? wxPD_CAN_ABORT : 0 ) |
110  wxPD_ELAPSED_TIME )
111 {
112 }
PROGRESS_REPORTER(int aNumPhases)

◆ ~WX_PROGRESS_REPORTER()

WX_PROGRESS_REPORTER::~WX_PROGRESS_REPORTER ( )

Definition at line 115 of file progress_reporter.cpp.

116 {
117  Destroy();
118 }

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

66 {
67  m_progress.fetch_add( 1 );
68 }
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 71 of file progress_reporter.cpp.

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

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

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

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

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

◆ 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 WX_PROGRESS_REPORTER::SetTitle ( const wxString &  aTitle)
inlineoverridevirtual

change the title displayed on the window caption

Reimplemented from PROGRESS_REPORTER.

Definition at line 122 of file progress_reporter.h.

123  {
124  wxProgressDialog::SetTitle( aTitle );
125  }

◆ updateUI()

bool WX_PROGRESS_REPORTER::updateUI ( )
overrideprivatevirtual

Implements PROGRESS_REPORTER.

Definition at line 121 of file progress_reporter.cpp.

122 {
123  int cur = currentProgress();
124 
125  if( cur < 0 || cur > 1000 )
126  cur = 0;
127 
128  wxString message;
129  {
130  std::lock_guard<std::mutex> guard( m_mutex );
131  message = m_rptMessage;
132  }
133 
134  SetRange( 1000 );
135  return wxProgressDialog::Update( cur, message );
136 }
int currentProgress() const

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

Member Data Documentation

◆ m_maxProgress

std::atomic_int PROGRESS_REPORTER::m_maxProgress
protectedinherited

◆ m_mutex

std::mutex PROGRESS_REPORTER::m_mutex
mutableprotectedinherited

Definition at line 94 of file progress_reporter.h.

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

◆ m_numPhases

std::atomic_int PROGRESS_REPORTER::m_numPhases
protectedinherited

Definition at line 96 of file progress_reporter.h.

Referenced by PROGRESS_REPORTER::currentProgress().

◆ m_phase

std::atomic_int PROGRESS_REPORTER::m_phase
protectedinherited

◆ m_progress

std::atomic_int PROGRESS_REPORTER::m_progress
protectedinherited

◆ m_rptMessage

wxString PROGRESS_REPORTER::m_rptMessage
protectedinherited

Definition at line 93 of file progress_reporter.h.

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


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