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