KiCad PCB EDA Suite
Loading...
Searching...
No Matches
progress_reporter_base.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 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * Author: Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#ifndef GENERIC_PROGRESS_REPORTER_H
28#define GENERIC_PROGRESS_REPORTER_H
29
30#include <mutex>
31#include <atomic>
32#include <progress_reporter.h>
33
38{
39public:
40
41 PROGRESS_REPORTER_BASE( int aNumPhases );
43
45 {
46 }
47
51 void SetNumPhases( int aNumPhases ) override;
52 void AddPhases( int aNumPhases ) override;
53
57 virtual void BeginPhase( int aPhase ) override;
58
62 virtual void AdvancePhase() override;
63
67 virtual void AdvancePhase( const wxString& aMessage ) override;
68
72 virtual void Report( const wxString& aMessage ) override;
73
77 virtual void SetCurrentProgress( double aProgress ) override;
78
83 void SetMaxProgress( int aMaxProgress ) override;
84
88 void AdvanceProgress() override;
89
97 bool KeepRefreshing( bool aWait = false ) override;
98
106 void SetTitle( const wxString& aTitle ) override { }
107
108 bool IsCancelled() const override { return m_cancelled; }
109
110protected:
111 int currentProgress() const;
112
113 virtual bool updateUI() = 0;
114
115 wxString m_rptMessage;
116
117 mutable std::mutex m_mutex;
118 std::atomic_int m_phase;
119 std::atomic_int m_numPhases;
120 std::atomic_int m_progress;
121 std::atomic_int m_maxProgress;
122 std::atomic_bool m_cancelled;
123
124 // True if the displayed message has changed,
125 // so perhaps there is a need to resize the window
126 // Note the resize is made only if the size of the new message
127 // is bigger than the old message
128 std::atomic_bool m_messageChanged;
129};
130
131
132#endif
This implements all the tricky bits for thread safety, but the GUI is left to derived classes.
virtual bool updateUI()=0
void AdvanceProgress() override
Increment the progress bar length (inside the current virtual zone).
virtual void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
void SetTitle(const wxString &aTitle) override
Change the title displayed on the window caption.
virtual void SetCurrentProgress(double aProgress) override
Set the progress value to aProgress (0..1).
void SetMaxProgress(int aMaxProgress) override
Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).
PROGRESS_REPORTER_BASE(const PROGRESS_REPORTER_BASE &)=delete
virtual void Report(const wxString &aMessage) override
Display aMessage in the progress bar dialog.
void AddPhases(int aNumPhases) override
bool IsCancelled() const override
void SetNumPhases(int aNumPhases) override
Set the number of phases.
bool KeepRefreshing(bool aWait=false) override
Update the UI dialog.
virtual void BeginPhase(int aPhase) override
Initialize the aPhase virtual zone of the dialog progress bar.
A progress reporter interface for use in multi-threaded environments.