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 The 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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef GENERIC_PROGRESS_REPORTER_H
24#define GENERIC_PROGRESS_REPORTER_H
25
26#include <mutex>
27#include <atomic>
28#include <progress_reporter.h>
29
34{
35public:
36
37 PROGRESS_REPORTER_BASE( int aNumPhases );
39
41 {
42 }
43
47 void SetNumPhases( int aNumPhases ) override;
48 void AddPhases( int aNumPhases ) override;
49
53 virtual void BeginPhase( int aPhase ) override;
54
58 virtual void AdvancePhase() override;
59
63 virtual void AdvancePhase( const wxString& aMessage ) override;
64
68 virtual void Report( const wxString& aMessage ) override;
69
73 virtual void SetCurrentProgress( double aProgress ) override;
74
79 void SetMaxProgress( int aMaxProgress ) override;
80
84 void AdvanceProgress() override;
85
93 bool KeepRefreshing( bool aWait = false ) override;
94
102 void SetTitle( const wxString& aTitle ) override { }
103
104 bool IsCancelled() const override { return m_cancelled; }
105
106 int CurrentProgress() const;
107
108protected:
109
110 virtual bool updateUI() = 0;
111
112 wxString m_rptMessage;
113
114 mutable std::mutex m_mutex;
115 std::atomic_int m_phase;
116 std::atomic_int m_numPhases;
117 std::atomic_int m_progress;
118 std::atomic_int m_maxProgress;
119 std::atomic_bool m_cancelled;
120
121 // True if the displayed message has changed,
122 // so perhaps there is a need to resize the window
123 // Note the resize is made only if the size of the new message
124 // is bigger than the old message
125 std::atomic_bool m_messageChanged;
126};
127
128
129#endif
virtual bool updateUI()=0
void SetTitle(const wxString &aTitle) override
Change the title displayed on the window caption.
PROGRESS_REPORTER_BASE(const PROGRESS_REPORTER_BASE &)=delete
bool IsCancelled() const override
virtual void AddPhases(int aNumPhases)=0
virtual bool KeepRefreshing(bool aWait=false)=0
Update the UI (if any).
virtual void SetNumPhases(int aNumPhases)=0
Set the number of phases.
virtual void Report(const wxString &aMessage)=0
Display aMessage in the progress bar dialog.
virtual void BeginPhase(int aPhase)=0
Initialize the aPhase virtual zone of the dialog progress bar.
virtual void AdvancePhase()=0
Use the next available virtual zone of the dialog progress bar.
virtual void AdvanceProgress()=0
Increment the progress bar length (inside the current virtual zone).
virtual void SetCurrentProgress(double aProgress)=0
Set the progress value to aProgress (0..1).
virtual void SetMaxProgress(int aMaxProgress)=0
Fix the value that gives the 100 percent progress bar length (inside the current virtual zone).
#define KICOMMON_API
Definition kicommon.h:27