KiCad PCB EDA Suite
DIALOG_PCM_PROGRESS Class Reference

Progress dialog for PCM system. More...

#include <dialog_pcm_progress.h>

Inheritance diagram for DIALOG_PCM_PROGRESS:
DIALOG_PCM_PROGRESS_BASE PROGRESS_REPORTER_BASE PROGRESS_REPORTER

Public Member Functions

 DIALOG_PCM_PROGRESS (wxWindow *parent, bool aShowDownloadSection=true)
 Constructor. More...
 
void Report (const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
 Safe to call from non-UI thread. Sets the download progress of the current zip entry. More...
 
void SetDownloadProgress (uint64_t aDownloaded, uint64_t aTotal)
 Safe to call from non-UI thread. Sets the download prgress of the current package. More...
 
void SetPackageProgress (uint64_t aProgress, uint64_t aTotal)
 Safe to call from non-UI thread. Advances to the next package. More...
 
void AdvancePhase () override
 Safe to call from non-UI thread. Disables cancel button, enables close button. More...
 
void SetFinished ()
 
void SetNumPhases (int aNumPhases) override
 Set the number of phases. More...
 
void AddPhases (int aNumPhases) override
 
virtual void BeginPhase (int aPhase) override
 Initialize the aPhase virtual zone of the dialog progress bar. More...
 
virtual void AdvancePhase (const wxString &aMessage) override
 Use the next available virtual zone of the dialog progress bar and updates the message. More...
 
virtual void Report (const wxString &aMessage) override
 Display aMessage in the progress bar dialog. More...
 
virtual void SetCurrentProgress (double aProgress) override
 Set the progress value to aProgress (0..1). More...
 
void SetMaxProgress (int aMaxProgress) override
 Fix the value that gives the 100 percent progress bar length (inside the current virtual zone). More...
 
void AdvanceProgress () override
 Increment the progress bar length (inside the current virtual zone). More...
 
bool KeepRefreshing (bool aWait=false) override
 Update the UI dialog. More...
 
void SetTitle (const wxString &aTitle) override
 Change the title displayed on the window caption. More...
 
bool IsCancelled () const override
 

Protected Member Functions

void OnCancelClicked (wxCommandEvent &event) override
 
void OnCloseClicked (wxCommandEvent &event) override
 
int currentProgress () const
 

Protected Attributes

wxPanel * m_panelDownload
 
wxStaticText * m_downloadText
 
wxGauge * m_downloadGauge
 
wxPanel * m_panel2
 
wxGauge * m_overallGauge
 
WX_HTML_REPORT_BOXm_reporter
 
wxButton * m_buttonCancel
 
wxButton * m_buttonClose
 
wxString m_rptMessage
 
bool m_msgChanged
 
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

bool updateUI () override
 

Static Private Member Functions

static uint64_t toKb (uint64_t aValue)
 

Private Attributes

std::atomic_int64_t m_downloaded
 
std::atomic_int64_t m_downloadTotal
 
std::atomic_int64_t m_currentProgress
 
std::atomic_int64_t m_currentProgressTotal
 
std::atomic_bool m_finished
 
std::vector< std::pair< wxString, SEVERITY > > m_reports
 

Detailed Description

Progress dialog for PCM system.

This dialog is designed to work with PCM_TASK_MANAGER's threading system. Some of it's methods are safe to call from a non-UI thread.

Definition at line 40 of file dialog_pcm_progress.h.

Constructor & Destructor Documentation

◆ DIALOG_PCM_PROGRESS()

DIALOG_PCM_PROGRESS::DIALOG_PCM_PROGRESS ( wxWindow *  parent,
bool  aShowDownloadSection = true 
)

Constructor.

Safe to call from non-UI thread. Adds a message to detailed report window.

Definition at line 27 of file dialog_pcm_progress.cpp.

27  :
28  DIALOG_PCM_PROGRESS_BASE( parent ),
30  m_downloaded( 0 ),
31  m_downloadTotal( 0 ),
32  m_currentProgress( 0 ),
34  m_finished( false )
35 #if wxCHECK_VERSION( 3, 1, 0 )
36  ,
37  m_appProgressIndicator( parent->GetParent(), GAUGE_RANGE )
38 #endif
39 {
40 #if wxCHECK_VERSION( 3, 1, 0 )
41  m_appProgressIndicator.Pulse();
42 #endif
43 
45  m_downloadGauge->SetRange( GAUGE_RANGE );
46  m_overallGauge->SetRange( GAUGE_RANGE );
47 
48  if( !aShowDownloadSection )
49  m_panelDownload->Hide();
50 }
DIALOG_PCM_PROGRESS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Applying Package Changes"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(600, 500), long style=wxCAPTION)
std::atomic_int64_t m_currentProgressTotal
void SetImmediateMode()
In immediate mode, messages are flushed as they are added.
std::atomic_int64_t m_downloaded
#define GAUGE_RANGE
PROGRESS_REPORTER_BASE(int aNumPhases)
std::atomic_int64_t m_downloadTotal
std::atomic_bool m_finished
std::atomic_int64_t m_currentProgress

References GAUGE_RANGE, DIALOG_PCM_PROGRESS_BASE::m_downloadGauge, DIALOG_PCM_PROGRESS_BASE::m_overallGauge, DIALOG_PCM_PROGRESS_BASE::m_panelDownload, DIALOG_PCM_PROGRESS_BASE::m_reporter, and WX_HTML_REPORT_BOX::SetImmediateMode().

Member Function Documentation

◆ AddPhases()

void PROGRESS_REPORTER_BASE::AddPhases ( int  aNumPhases)
overridevirtualinherited

Implements PROGRESS_REPORTER.

Definition at line 97 of file progress_reporter_base.cpp.

98 {
99  m_numPhases += aNumPhases;
100 }

References PROGRESS_REPORTER_BASE::m_numPhases.

◆ AdvancePhase() [1/2]

void DIALOG_PCM_PROGRESS::AdvancePhase ( )
overridevirtual

Safe to call from non-UI thread. Disables cancel button, enables close button.

Reimplemented from PROGRESS_REPORTER_BASE.

Definition at line 97 of file dialog_pcm_progress.cpp.

98 {
100  m_currentProgress.store( 0 );
101 }
virtual void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
std::atomic_int64_t m_currentProgress

References PROGRESS_REPORTER_BASE::AdvancePhase(), and m_currentProgress.

◆ AdvancePhase() [2/2]

void PROGRESS_REPORTER_BASE::AdvancePhase ( const wxString &  aMessage)
overridevirtualinherited

Use the next available virtual zone of the dialog progress bar and updates the message.

Implements PROGRESS_REPORTER.

Reimplemented in DIALOG_DRC, and DIALOG_ERC.

Definition at line 57 of file progress_reporter_base.cpp.

58 {
59  AdvancePhase();
60  Report( aMessage );
61 }
virtual void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
virtual void Report(const wxString &aMessage) override
Display aMessage in the progress bar dialog.

References PROGRESS_REPORTER_BASE::AdvancePhase(), and PROGRESS_REPORTER_BASE::Report().

◆ AdvanceProgress()

void PROGRESS_REPORTER_BASE::AdvanceProgress ( )
overridevirtualinherited

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

Implements PROGRESS_REPORTER.

Definition at line 85 of file progress_reporter_base.cpp.

86 {
87  m_progress.fetch_add( 1 );
88 }

References PROGRESS_REPORTER_BASE::m_progress.

◆ BeginPhase()

void PROGRESS_REPORTER_BASE::BeginPhase ( int  aPhase)
overridevirtualinherited

Initialize the aPhase virtual zone of the dialog progress bar.

Implements PROGRESS_REPORTER.

Definition at line 43 of file progress_reporter_base.cpp.

44 {
45  m_phase.store( aPhase );
46  m_progress.store( 0 );
47 }

References PROGRESS_REPORTER_BASE::m_phase, and PROGRESS_REPORTER_BASE::m_progress.

◆ currentProgress()

int PROGRESS_REPORTER_BASE::currentProgress ( ) const
protectedinherited

Definition at line 103 of file progress_reporter_base.cpp.

104 {
105  double current = ( 1.0 / (double) m_numPhases ) *
106  ( (double) m_phase + ( (double) m_progress.load() / (double) m_maxProgress ) );
107 
108  return (int)( current * 1000 );
109 }

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

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

◆ IsCancelled()

bool PROGRESS_REPORTER_BASE::IsCancelled ( ) const
inlineoverridevirtualinherited

◆ KeepRefreshing()

bool PROGRESS_REPORTER_BASE::KeepRefreshing ( bool  aWait = false)
overridevirtualinherited

Update the UI dialog.

Warning
This should only be called from the main thread.
Returns
false if the user clicked Cancel.

Implements PROGRESS_REPORTER.

Definition at line 112 of file progress_reporter_base.cpp.

113 {
114  if( aWait )
115  {
116  while( m_progress.load() < m_maxProgress && m_maxProgress > 0 )
117  {
118  if( !updateUI() )
119  {
120  m_cancelled.store( true );
121  return false;
122  }
123 
124  wxMilliSleep( 33 /* 30 FPS refresh rate */ );
125  }
126 
127  return true;
128  }
129  else
130  {
131  if( !updateUI() )
132  {
133  m_cancelled.store( true );
134  return false;
135  }
136 
137  return true;
138  }
139 }
virtual bool updateUI()=0

References PROGRESS_REPORTER_BASE::m_cancelled, PROGRESS_REPORTER_BASE::m_maxProgress, PROGRESS_REPORTER_BASE::m_progress, and PROGRESS_REPORTER_BASE::updateUI().

Referenced by PLUGIN_CONTENT_MANAGER::DownloadToStream().

◆ OnCancelClicked()

void DIALOG_PCM_PROGRESS::OnCancelClicked ( wxCommandEvent &  event)
overrideprotectedvirtual

Reimplemented from DIALOG_PCM_PROGRESS_BASE.

Definition at line 53 of file dialog_pcm_progress.cpp.

54 {
55  SetNumPhases( 1 );
56  SetPackageProgress( 1, 1 );
57  m_reporter->Report( _( "Aborting remaining tasks." ) );
58 
59  m_cancelled.store( true );
60  m_finished.store( true );
61 }
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
void SetPackageProgress(uint64_t aProgress, uint64_t aTotal)
Safe to call from non-UI thread. Advances to the next package.
void SetNumPhases(int aNumPhases) override
Set the number of phases.
#define _(s)
std::atomic_bool m_finished

References _, PROGRESS_REPORTER_BASE::m_cancelled, m_finished, DIALOG_PCM_PROGRESS_BASE::m_reporter, WX_HTML_REPORT_BOX::Report(), PROGRESS_REPORTER_BASE::SetNumPhases(), and SetPackageProgress().

◆ OnCloseClicked()

void DIALOG_PCM_PROGRESS::OnCloseClicked ( wxCommandEvent &  event)
overrideprotectedvirtual

Reimplemented from DIALOG_PCM_PROGRESS_BASE.

Definition at line 64 of file dialog_pcm_progress.cpp.

65 {
66  m_progress.store( m_maxProgress );
67 }

References PROGRESS_REPORTER_BASE::m_maxProgress, and PROGRESS_REPORTER_BASE::m_progress.

◆ Report() [1/2]

void DIALOG_PCM_PROGRESS::Report ( const wxString &  aText,
SEVERITY  aSeverity = RPT_SEVERITY_UNDEFINED 
)

Safe to call from non-UI thread. Sets the download progress of the current zip entry.

Definition at line 70 of file dialog_pcm_progress.cpp.

71 {
72  std::lock_guard<std::mutex> guard( m_mutex );
73  m_reports.push_back( std::make_pair( aText, aSeverity ) );
74 }
std::vector< std::pair< wxString, SEVERITY > > m_reports

References PROGRESS_REPORTER_BASE::m_mutex, and m_reports.

◆ Report() [2/2]

void PROGRESS_REPORTER_BASE::Report ( const wxString &  aMessage)
overridevirtualinherited

Display aMessage in the progress bar dialog.

Implements PROGRESS_REPORTER.

Reimplemented in DIALOG_ERC.

Definition at line 64 of file progress_reporter_base.cpp.

65 {
66  std::lock_guard<std::mutex> guard( m_mutex );
67  m_rptMessage = aMessage;
68  m_msgChanged = true;
69 }

References PROGRESS_REPORTER_BASE::m_msgChanged, PROGRESS_REPORTER_BASE::m_mutex, and PROGRESS_REPORTER_BASE::m_rptMessage.

Referenced by PROGRESS_REPORTER_BASE::AdvancePhase(), PLUGIN_CONTENT_MANAGER::DownloadToStream(), and PCB_EDIT_FRAME::OpenProjectFiles().

◆ SetCurrentProgress()

void PROGRESS_REPORTER_BASE::SetCurrentProgress ( double  aProgress)
overridevirtualinherited

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

Implements PROGRESS_REPORTER.

Reimplemented in CONSOLE_PROGRESS_REPORTER.

Definition at line 78 of file progress_reporter_base.cpp.

79 {
80  m_maxProgress.store( 1000 );
81  m_progress.store( (int) ( aProgress * 1000.0 ) );
82 }

References PROGRESS_REPORTER_BASE::m_maxProgress, and PROGRESS_REPORTER_BASE::m_progress.

Referenced by DIALOG_ERC::AdvancePhase(), DIALOG_DRC::AdvancePhase(), PLUGIN_CONTENT_MANAGER::DownloadToStream(), and CONSOLE_PROGRESS_REPORTER::SetCurrentProgress().

◆ SetDownloadProgress()

void DIALOG_PCM_PROGRESS::SetDownloadProgress ( uint64_t  aDownloaded,
uint64_t  aTotal 
)

Safe to call from non-UI thread. Sets the download prgress of the current package.

Definition at line 77 of file dialog_pcm_progress.cpp.

78 {
79  m_downloaded.store( std::min( aDownloaded, aTotal ) );
80  m_downloadTotal.store( aTotal );
81 }
std::atomic_int64_t m_downloaded
std::atomic_int64_t m_downloadTotal

References m_downloaded, and m_downloadTotal.

◆ SetFinished()

void DIALOG_PCM_PROGRESS::SetFinished ( )

Definition at line 104 of file dialog_pcm_progress.cpp.

105 {
106  m_finished.store( true );
107 }
std::atomic_bool m_finished

References m_finished.

◆ SetMaxProgress()

void PROGRESS_REPORTER_BASE::SetMaxProgress ( int  aMaxProgress)
overridevirtualinherited

Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).

Implements PROGRESS_REPORTER.

Definition at line 72 of file progress_reporter_base.cpp.

73 {
74  m_maxProgress.store( aMaxProgress );
75 }

References PROGRESS_REPORTER_BASE::m_maxProgress.

◆ SetNumPhases()

void PROGRESS_REPORTER_BASE::SetNumPhases ( int  aNumPhases)
overridevirtualinherited

Set the number of phases.

Implements PROGRESS_REPORTER.

Definition at line 91 of file progress_reporter_base.cpp.

92 {
93  m_numPhases = aNumPhases;
94 }

References PROGRESS_REPORTER_BASE::m_numPhases.

Referenced by OnCancelClicked().

◆ SetPackageProgress()

void DIALOG_PCM_PROGRESS::SetPackageProgress ( uint64_t  aProgress,
uint64_t  aTotal 
)

Safe to call from non-UI thread. Advances to the next package.

Definition at line 90 of file dialog_pcm_progress.cpp.

91 {
92  m_currentProgress.store( std::min( aProgress, aTotal ) );
93  m_currentProgressTotal.store( aTotal );
94 }
std::atomic_int64_t m_currentProgressTotal
std::atomic_int64_t m_currentProgress

References m_currentProgress, and m_currentProgressTotal.

Referenced by OnCancelClicked().

◆ SetTitle()

void PROGRESS_REPORTER_BASE::SetTitle ( const wxString &  aTitle)
inlineoverridevirtualinherited

Change the title displayed on the window caption.

Has meaning only for some reporters. Does nothing for others.

Warning
This should only be called from the main thread.

Implements PROGRESS_REPORTER.

Reimplemented in WX_PROGRESS_REPORTER.

Definition at line 106 of file progress_reporter_base.h.

106 { }

◆ toKb()

uint64_t DIALOG_PCM_PROGRESS::toKb ( uint64_t  aValue)
staticprivate

Definition at line 84 of file dialog_pcm_progress.cpp.

85 {
86  return ( aValue + 1023 ) / 1024;
87 }

Referenced by updateUI().

◆ updateUI()

bool DIALOG_PCM_PROGRESS::updateUI ( )
overrideprivatevirtual

Implements PROGRESS_REPORTER_BASE.

Definition at line 110 of file dialog_pcm_progress.cpp.

111 {
112  bool finished = m_finished.load();
113  int phase = m_phase.load();
114  int phases = m_numPhases.load();
115  long cp = m_currentProgress.load();
116  long total = m_currentProgressTotal.load();
117  double current = ( total > 0 ) ? ( double( cp ) / double( total ) ) : 0;
118 
119  if( phases > 0 )
120  current = ( phase + current ) / phases;
121 
122  if( current > 1.0 || finished )
123  current = 1.0;
124 
125  m_overallGauge->SetValue( current * GAUGE_RANGE );
126 #if wxCHECK_VERSION( 3, 1, 0 )
127  m_appProgressIndicator.SetValue( current * GAUGE_RANGE );
128 #endif
129 
130  if( m_downloadTotal.load() == 0 )
131  {
132  m_downloadText->SetLabel( wxEmptyString );
133  m_downloadGauge->SetValue( 0 );
134  }
135  else
136  {
137  m_downloadText->SetLabel( wxString::Format( _( "Downloaded %lld/%lld Kb" ),
138  toKb( m_downloaded.load() ),
139  toKb( m_downloadTotal.load() ) ) );
140 
141  current = m_downloaded.load() / (double) m_downloadTotal.load();
142 
143  if( current > 1.0 || finished )
144  current = 1.0;
145 
146  m_downloadGauge->SetValue( current * GAUGE_RANGE );
147  }
148 
149  std::lock_guard<std::mutex> guard( m_mutex );
150 
151  for( const std::pair<wxString, SEVERITY>& pair : m_reports )
152  m_reporter->Report( pair.first, pair.second );
153 
154  m_reports.clear();
155 
156  if( finished )
157  {
158  m_buttonCancel->Disable();
159  m_buttonClose->Enable();
160  }
161 
162  wxYield();
163 
164  return true;
165 }
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
std::vector< std::pair< wxString, SEVERITY > > m_reports
std::atomic_int64_t m_currentProgressTotal
static uint64_t toKb(uint64_t aValue)
std::atomic_int64_t m_downloaded
#define _(s)
#define GAUGE_RANGE
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
std::atomic_int64_t m_downloadTotal
std::atomic_bool m_finished
std::atomic_int64_t m_currentProgress

References _, Format(), GAUGE_RANGE, DIALOG_PCM_PROGRESS_BASE::m_buttonCancel, DIALOG_PCM_PROGRESS_BASE::m_buttonClose, m_currentProgress, m_currentProgressTotal, m_downloaded, DIALOG_PCM_PROGRESS_BASE::m_downloadGauge, DIALOG_PCM_PROGRESS_BASE::m_downloadText, m_downloadTotal, m_finished, PROGRESS_REPORTER_BASE::m_mutex, PROGRESS_REPORTER_BASE::m_numPhases, DIALOG_PCM_PROGRESS_BASE::m_overallGauge, PROGRESS_REPORTER_BASE::m_phase, DIALOG_PCM_PROGRESS_BASE::m_reporter, m_reports, WX_HTML_REPORT_BOX::Report(), and toKb().

Member Data Documentation

◆ m_buttonCancel

wxButton* DIALOG_PCM_PROGRESS_BASE::m_buttonCancel
protectedinherited

◆ m_buttonClose

wxButton* DIALOG_PCM_PROGRESS_BASE::m_buttonClose
protectedinherited

◆ m_cancelled

std::atomic_bool PROGRESS_REPORTER_BASE::m_cancelled
protectedinherited

◆ m_currentProgress

std::atomic_int64_t DIALOG_PCM_PROGRESS::m_currentProgress
private

Definition at line 75 of file dialog_pcm_progress.h.

Referenced by AdvancePhase(), SetPackageProgress(), and updateUI().

◆ m_currentProgressTotal

std::atomic_int64_t DIALOG_PCM_PROGRESS::m_currentProgressTotal
private

Definition at line 76 of file dialog_pcm_progress.h.

Referenced by SetPackageProgress(), and updateUI().

◆ m_downloaded

std::atomic_int64_t DIALOG_PCM_PROGRESS::m_downloaded
private

Definition at line 72 of file dialog_pcm_progress.h.

Referenced by SetDownloadProgress(), and updateUI().

◆ m_downloadGauge

wxGauge* DIALOG_PCM_PROGRESS_BASE::m_downloadGauge
protectedinherited

◆ m_downloadText

wxStaticText* DIALOG_PCM_PROGRESS_BASE::m_downloadText
protectedinherited

◆ m_downloadTotal

std::atomic_int64_t DIALOG_PCM_PROGRESS::m_downloadTotal
private

Definition at line 73 of file dialog_pcm_progress.h.

Referenced by SetDownloadProgress(), and updateUI().

◆ m_finished

std::atomic_bool DIALOG_PCM_PROGRESS::m_finished
private

Definition at line 78 of file dialog_pcm_progress.h.

Referenced by OnCancelClicked(), SetFinished(), and updateUI().

◆ m_maxProgress

◆ m_msgChanged

bool PROGRESS_REPORTER_BASE::m_msgChanged
protectedinherited

◆ m_mutex

std::mutex PROGRESS_REPORTER_BASE::m_mutex
mutableprotectedinherited

◆ m_numPhases

std::atomic_int PROGRESS_REPORTER_BASE::m_numPhases
protectedinherited

◆ m_overallGauge

wxGauge* DIALOG_PCM_PROGRESS_BASE::m_overallGauge
protectedinherited

◆ m_panel2

wxPanel* DIALOG_PCM_PROGRESS_BASE::m_panel2
protectedinherited

◆ m_panelDownload

wxPanel* DIALOG_PCM_PROGRESS_BASE::m_panelDownload
protectedinherited

◆ m_phase

std::atomic_int PROGRESS_REPORTER_BASE::m_phase
protectedinherited

◆ m_progress

◆ m_reporter

WX_HTML_REPORT_BOX* DIALOG_PCM_PROGRESS_BASE::m_reporter
protectedinherited

◆ m_reports

std::vector< std::pair<wxString, SEVERITY> > DIALOG_PCM_PROGRESS::m_reports
private

Definition at line 80 of file dialog_pcm_progress.h.

Referenced by Report(), and updateUI().

◆ m_rptMessage

wxString PROGRESS_REPORTER_BASE::m_rptMessage
protectedinherited

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