KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_progress_reporters.cpp
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, 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
#include <wx/evtloop.h>
28
#include <thread>
29
#include <
widgets/wx_progress_reporters.h
>
30
31
32
WX_PROGRESS_REPORTER::WX_PROGRESS_REPORTER
( wxWindow* aParent,
const
wxString& aTitle,
33
int
aNumPhases,
int
aCanAbort,
34
bool
aReserveSpaceForMessage ) :
35
PROGRESS_REPORTER_BASE
( aNumPhases ),
36
WX_PROGRESS_REPORTER_BASE
( aTitle,
37
( aReserveSpaceForMessage ? wxT(
" "
) : wxT(
""
) ),
38
1, aParent,
39
// wxPD_APP_MODAL | // Don't use; messes up OSX when called from
40
// quasi-modal dialog
41
wxPD_AUTO_HIDE |
// *MUST* use; otherwise wxWidgets will spin
42
// up another event loop on completion which
43
// causes all sorts of grief
44
aCanAbort | wxPD_ELAPSED_TIME ),
45
m_appProgressIndicator
( aParent ),
46
m_messageWidth
( 0 )
47
{
48
// wxAppProgressIndicator doesn't like value > max, ever. However there are some risks
49
// with multithreaded setting of those values making a mess
50
// the cop out is just to set the progress to "indeterminate"
51
m_appProgressIndicator
.Pulse();
52
}
53
54
55
WX_PROGRESS_REPORTER::~WX_PROGRESS_REPORTER
()
56
{
57
}
58
59
60
bool
WX_PROGRESS_REPORTER::updateUI
()
61
{
62
int
cur =
CurrentProgress
();
63
64
if
( cur < 0 || cur > 1000 )
65
cur = 0;
66
67
SetRange( 1000 );
68
69
wxString message;
70
71
{
72
std::lock_guard<std::mutex> guard(
m_mutex
);
73
message =
m_rptMessage
;
74
}
75
76
// Perhaps the window size is too small if the new message to display is bigger
77
// than the previous message. in this case, resize the WX_PROGRESS_REPORTER window
78
// GetTextExtent has probably bugs in wxWidgets < 3.1.6, so calling it only when
79
// the message has changed is mandatory
80
if
(
m_messageChanged
)
81
{
82
int
newWidth = GetTextExtent(
m_rptMessage
).x;
83
84
if
( newWidth >
m_messageWidth
)
85
{
86
m_messageWidth
= newWidth;
87
Fit();
88
}
89
90
Raise();
91
92
m_messageChanged
=
false
;
93
}
94
95
// Returns false when cancelled (if it's a cancellable dialog)
96
bool
diag = WX_PROGRESS_REPORTER_BASE::Update( cur, message );
97
98
return
diag;
99
}
100
101
102
GAUGE_PROGRESS_REPORTER::GAUGE_PROGRESS_REPORTER
( wxWindow* aParent,
int
aNumPhases ) :
103
PROGRESS_REPORTER_BASE
( aNumPhases ),
104
wxGauge( aParent, wxID_ANY, 1000, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL,
105
wxDefaultValidator, wxGaugeNameStr )
106
{
107
}
108
109
110
bool
GAUGE_PROGRESS_REPORTER::updateUI
()
111
{
112
int
cur =
CurrentProgress
();
113
114
if
( cur < 0 || cur > 1000 )
115
cur = 0;
116
117
wxGauge::SetValue( cur );
118
wxEventLoopBase::GetActive()->YieldFor( wxEVT_CATEGORY_UI );
119
120
return
true
;
// No cancel button on a wxGauge
121
}
GAUGE_PROGRESS_REPORTER::GAUGE_PROGRESS_REPORTER
GAUGE_PROGRESS_REPORTER(wxWindow *aParent, int aNumPhases)
Definition
wx_progress_reporters.cpp:102
GAUGE_PROGRESS_REPORTER::updateUI
bool updateUI() override
Definition
wx_progress_reporters.cpp:110
PROGRESS_REPORTER_BASE::m_messageChanged
std::atomic_bool m_messageChanged
Definition
progress_reporter_base.h:129
PROGRESS_REPORTER_BASE::m_rptMessage
wxString m_rptMessage
Definition
progress_reporter_base.h:116
PROGRESS_REPORTER_BASE::PROGRESS_REPORTER_BASE
PROGRESS_REPORTER_BASE(int aNumPhases)
Definition
progress_reporter_base.cpp:31
PROGRESS_REPORTER_BASE::CurrentProgress
int CurrentProgress() const
Definition
progress_reporter_base.cpp:104
PROGRESS_REPORTER_BASE::m_mutex
std::mutex m_mutex
Definition
progress_reporter_base.h:118
WX_PROGRESS_REPORTER::updateUI
bool updateUI() override
Definition
wx_progress_reporters.cpp:60
WX_PROGRESS_REPORTER::m_appProgressIndicator
wxAppProgressIndicator m_appProgressIndicator
Definition
wx_progress_reporters.h:87
WX_PROGRESS_REPORTER::WX_PROGRESS_REPORTER
WX_PROGRESS_REPORTER(wxWindow *aParent, const wxString &aTitle, int aNumPhases, int aCanAbort, bool aReserveSpaceForMessage=true)
The PROGRESS_REPORTER will stay on top of aParent.
Definition
wx_progress_reporters.cpp:32
WX_PROGRESS_REPORTER::m_messageWidth
int m_messageWidth
Definition
wx_progress_reporters.h:88
WX_PROGRESS_REPORTER::~WX_PROGRESS_REPORTER
~WX_PROGRESS_REPORTER()
Definition
wx_progress_reporters.cpp:55
wx_progress_reporters.h
WX_PROGRESS_REPORTER_BASE
#define WX_PROGRESS_REPORTER_BASE
Definition
wx_progress_reporters.h:44
src
common
widgets
wx_progress_reporters.cpp
Generated on Sun Sep 21 2025 01:05:22 for KiCad PCB EDA Suite by
1.13.2