KiCad PCB EDA Suite
reporter.cpp
Go to the documentation of this file.
1
4/*
5 * This program source code file is part of KiCad, a free EDA CAD application.
6 *
7 * Copyright (C) 2013 Wayne Stambaugh <[email protected]>
8 * Copyright (C) 2013-2021 KiCad Developers, see AUTHORS.txt for contributors.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, you may find one here:
22 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23 * or you may search the http://www.gnu.org website for the version 2 license,
24 * or you may write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 */
27
28#include <macros.h>
29#include <reporter.h>
30#include <widgets/infobar.h>
32#include <wx/log.h>
33#include <wx/textctrl.h>
34#include <wx/statusbr.h>
35
36REPORTER& REPORTER::Report( const char* aText, SEVERITY aSeverity )
37{
38 Report( FROM_UTF8( aText ) );
39 return *this;
40}
41
42
43REPORTER& WX_TEXT_CTRL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
44{
45 wxCHECK_MSG( m_textCtrl != nullptr, *this,
46 wxT( "No wxTextCtrl object defined in WX_TEXT_CTRL_REPORTER." ) );
47
48 m_textCtrl->AppendText( aText + wxS( "\n" ) );
49 return *this;
50}
51
52
54{
55 return !m_textCtrl->IsEmpty();
56}
57
58
59REPORTER& WX_STRING_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
60{
61 wxCHECK_MSG( m_string != nullptr, *this,
62 wxT( "No wxString object defined in WX_STRING_REPORTER." ) );
63
64 *m_string << aText << wxS( "\n" );
65 return *this;
66}
67
68
70{
71 return !m_string->IsEmpty();
72}
73
74
75REPORTER& WX_HTML_PANEL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
76{
77 wxCHECK_MSG( m_panel != nullptr, *this,
78 wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
79
80 m_panel->Report( aText, aSeverity );
81 return *this;
82}
83
84
85REPORTER& WX_HTML_PANEL_REPORTER::ReportTail( const wxString& aText, SEVERITY aSeverity )
86{
87 wxCHECK_MSG( m_panel != nullptr, *this,
88 wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
89
90 m_panel->Report( aText, aSeverity, LOC_TAIL );
91 return *this;
92}
93
94
95REPORTER& WX_HTML_PANEL_REPORTER::ReportHead( const wxString& aText, SEVERITY aSeverity )
96{
97 wxCHECK_MSG( m_panel != nullptr, *this,
98 wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
99
100 m_panel->Report( aText, aSeverity, LOC_HEAD );
101 return *this;
102}
103
104
106{
108}
109
110
111REPORTER& NULL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
112{
113 return *this;
114}
115
116
118{
119 static REPORTER* s_nullReporter = nullptr;
120
121 if( !s_nullReporter )
122 s_nullReporter = new NULL_REPORTER();
123
124 return *s_nullReporter;
125}
126
127
128REPORTER& STDOUT_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
129{
130 switch( aSeverity )
131 {
132 case RPT_SEVERITY_UNDEFINED: std::cout << "SEVERITY_UNDEFINED: "; break;
133 case RPT_SEVERITY_INFO: std::cout << "SEVERITY_INFO: "; break;
134 case RPT_SEVERITY_WARNING: std::cout << "SEVERITY_WARNING: "; break;
135 case RPT_SEVERITY_ERROR: std::cout << "SEVERITY_ERROR: "; break;
136 case RPT_SEVERITY_ACTION: std::cout << "SEVERITY_ACTION: "; break;
137 case RPT_SEVERITY_DEBUG: std::cout << "SEVERITY_DEBUG: "; break;
139 case RPT_SEVERITY_IGNORE: break;
140 }
141
142 std::cout << aMsg << std::endl;
143
144 return *this;
145}
146
147
149{
150 static REPORTER* s_stdoutReporter = nullptr;
151
152 if( !s_stdoutReporter )
153 s_stdoutReporter = new STDOUT_REPORTER();
154
155 return *s_stdoutReporter;
156}
157
158
159REPORTER& WXLOG_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
160{
161 switch( aSeverity )
162 {
163 case RPT_SEVERITY_ERROR: wxLogError( aMsg ); break;
164 case RPT_SEVERITY_WARNING: wxLogWarning( aMsg ); break;
165 case RPT_SEVERITY_UNDEFINED: wxLogMessage( aMsg ); break;
166 case RPT_SEVERITY_INFO: wxLogInfo( aMsg ); break;
167 case RPT_SEVERITY_ACTION: wxLogInfo( aMsg ); break;
168 case RPT_SEVERITY_DEBUG: wxLogDebug( aMsg ); break;
169 case RPT_SEVERITY_EXCLUSION: break;
170 case RPT_SEVERITY_IGNORE: break;
171 }
172
173 return *this;
174}
175
176
178{
179 static REPORTER* s_wxLogReporter = nullptr;
180
181 if( !s_wxLogReporter )
182 s_wxLogReporter = new WXLOG_REPORTER();
183
184 return *s_wxLogReporter;
185}
186
187
188REPORTER& STATUSBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
189{
190 if( m_statusBar )
191 m_statusBar->SetStatusText( aText, m_position );
192
193 return *this;
194}
195
196
198{
199 if( m_statusBar )
200 return m_statusBar->GetStatusText().IsEmpty();
201
202 return false;
203}
204
205
207{
208}
209
210
211REPORTER& INFOBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
212{
213 m_message.reset( new wxString( aText ) );
214 m_severity = aSeverity;
215 m_messageSet = true;
216
217 return *this;
218}
219
220
222{
223 return m_message && !m_message->IsEmpty();
224}
225
226
228{
229 // Don't do anything if no message was ever given
230 if( !m_infoBar || !m_messageSet )
231 return;
232
233 // Short circuit if the message is empty and it is already hidden
234 if( !HasMessage() && !m_infoBar->IsShown() )
235 return;
236
237 int icon = wxICON_NONE;
238
239 switch( m_severity )
240 {
241 case RPT_SEVERITY_UNDEFINED: icon = wxICON_INFORMATION; break;
242 case RPT_SEVERITY_INFO: icon = wxICON_INFORMATION; break;
243 case RPT_SEVERITY_EXCLUSION: icon = wxICON_WARNING; break;
244 case RPT_SEVERITY_ACTION: icon = wxICON_WARNING; break;
245 case RPT_SEVERITY_WARNING: icon = wxICON_WARNING; break;
246 case RPT_SEVERITY_ERROR: icon = wxICON_ERROR; break;
247 case RPT_SEVERITY_IGNORE: icon = wxICON_INFORMATION; break;
248 case RPT_SEVERITY_DEBUG: icon = wxICON_INFORMATION; break;
249 }
250
251 if( m_message->EndsWith( "\n" ) )
252 *m_message = m_message->Left( m_message->Length() - 1 );
253
254 if( HasMessage() )
256 else
258}
WX_INFOBAR * m_infoBar
Definition: reporter.h:340
void Finalize()
Update the infobar with the reported text.
Definition: reporter.cpp:227
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:211
SEVERITY m_severity
Definition: reporter.h:342
std::unique_ptr< wxString > m_message
Definition: reporter.h:341
virtual ~INFOBAR_REPORTER()
Definition: reporter.cpp:206
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:221
static REPORTER & GetInstance()
Definition: reporter.cpp:117
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:111
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
@ LOC_TAIL
Definition: reporter.h:82
@ LOC_HEAD
Definition: reporter.h:80
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:188
wxStatusBar * m_statusBar
Definition: reporter.h:301
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:197
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:128
static REPORTER & GetInstance()
Definition: reporter.cpp:148
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:159
static REPORTER & GetInstance()
Definition: reporter.cpp:177
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:105
REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Places the report at the end of the list, for objects that support report ordering.
Definition: reporter.cpp:85
REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Places the report at the beginning of the list for objects that support ordering.
Definition: reporter.cpp:95
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:75
WX_HTML_REPORT_PANEL * m_panel
Definition: reporter.h:213
int Count(int severityMask)
sets the frame label
void Report(const wxString &aText, SEVERITY aSeverity, REPORTER::LOCATION aLocation=REPORTER::LOC_BODY)
Reports the string.
void QueueShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION)
Send the infobar an event telling it to show a message.
Definition: infobar.cpp:109
void QueueDismiss()
Send the infobar an event telling it to hide itself.
Definition: infobar.cpp:120
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:69
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:59
wxString * m_string
Definition: reporter.h:181
wxTextCtrl * m_textCtrl
Definition: reporter.h:156
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:53
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:43
This file contains miscellaneous commonly used macros and functions.
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
SEVERITY
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
@ RPT_SEVERITY_EXCLUSION
@ RPT_SEVERITY_IGNORE
@ RPT_SEVERITY_DEBUG
@ RPT_SEVERITY_INFO
@ RPT_SEVERITY_ACTION