KiCad PCB EDA Suite
progress_reporter.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2017 CERN
5  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6 *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef __PROGRESS_REPORTER
26 #define __PROGRESS_REPORTER
27 
28 #include <mutex>
29 #include <atomic>
30 
31 #include <wx/progdlg.h>
32 #include <wx/gauge.h>
33 
41 {
42  public:
43 
44  PROGRESS_REPORTER( int aNumPhases );
45  PROGRESS_REPORTER( const PROGRESS_REPORTER& ) = delete;
46 
50  void BeginPhase( int aPhase );
51 
55  void AdvancePhase();
56 
60  void Report( const wxString& aMessage );
61 
66  void SetMaxProgress( int aMaxProgress );
67 
71  void AdvanceProgress();
72 
77  bool KeepRefreshing( bool aWait = false );
78 
79  protected:
80 
81  int currentProgress() const;
82 
83  virtual bool updateUI() = 0;
84 
85  wxString m_rptMessage;
86  mutable std::mutex m_mutex;
87  std::atomic_int m_phase;
88  std::atomic_int m_numPhases;
89  std::atomic_int m_progress;
90  std::atomic_int m_maxProgress;
91 };
92 
93 
94 class WX_PROGRESS_REPORTER : public PROGRESS_REPORTER, public wxProgressDialog
95 {
96 public:
108  WX_PROGRESS_REPORTER( wxWindow* aParent, const wxString& aTitle, int aNumPhases,
109  bool aCanAbort = true );
111 
112 private:
113 
114  virtual bool updateUI() override;
115 };
116 
117 
118 class GAUGE_PROGRESS_REPORTER : public PROGRESS_REPORTER, public wxGauge
119 {
120 public:
128  GAUGE_PROGRESS_REPORTER( wxWindow* aParent, int aNumPhases );
129 
130 private:
131 
132  bool updateUI() override;
133 };
134 
135 #endif
void AdvancePhase()
Uses the next vailable virtual zone of the dialog progress bar.
void BeginPhase(int aPhase)
initialize the aPhase virtual zone of the dialog progress bar
std::atomic_int m_phase
A progress reporter for use in multi-threaded environments.
std::atomic_int m_progress
void Report(const wxString &aMessage)
Display aMessage in the progress bar dialog.
PROGRESS_REPORTER(int aNumPhases)
std::atomic_int m_numPhases
int currentProgress() const
virtual bool updateUI()=0
bool KeepRefreshing(bool aWait=false)
Update the UI dialog.
std::atomic_int m_maxProgress
void SetMaxProgress(int aMaxProgress)
Fix the value thar gives the 100 precent progress bar length (inside the current virtual zone) ...
void AdvanceProgress()
Increment the progress bar length (inside the current virtual zone)