KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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, 2024 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 <string_utils.h>
31#include <widgets/wx_infobar.h>
33#include <wx/crt.h>
34#include <wx/log.h>
35#include <wx/textctrl.h>
36#include <wx/statusbr.h>
37
38
44static const wxChar traceReporter[] = wxT( "KICAD_REPORTER" );
45
46
47REPORTER& REPORTER::Report( const char* aText, SEVERITY aSeverity )
48{
49 Report( From_UTF8( aText ) );
50 return *this;
51}
52
53
54REPORTER& WX_TEXT_CTRL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
55{
56 wxCHECK_MSG( m_textCtrl != nullptr, *this,
57 wxT( "No wxTextCtrl object defined in WX_TEXT_CTRL_REPORTER." ) );
58
59 m_textCtrl->AppendText( aText + wxS( "\n" ) );
60 return *this;
61}
62
63
65{
66 return !m_textCtrl->IsEmpty();
67}
68
69
70REPORTER& WX_STRING_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
71{
72 wxCHECK_MSG( m_string != nullptr, *this,
73 wxT( "No wxString object defined in WX_STRING_REPORTER." ) );
74
75 *m_string << aText << wxS( "\n" );
76 return *this;
77}
78
79
81{
82 return !m_string->IsEmpty();
83}
84
85
86REPORTER& WX_HTML_PANEL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
87{
88 wxCHECK_MSG( m_panel != nullptr, *this,
89 wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
90
91 m_panel->Report( aText, aSeverity );
92 return *this;
93}
94
95
96REPORTER& WX_HTML_PANEL_REPORTER::ReportTail( const wxString& aText, SEVERITY aSeverity )
97{
98 wxCHECK_MSG( m_panel != nullptr, *this,
99 wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
100
101 m_panel->Report( aText, aSeverity, LOC_TAIL );
102 return *this;
103}
104
105
106REPORTER& WX_HTML_PANEL_REPORTER::ReportHead( const wxString& aText, SEVERITY aSeverity )
107{
108 wxCHECK_MSG( m_panel != nullptr, *this,
109 wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
110
111 m_panel->Report( aText, aSeverity, LOC_HEAD );
112 return *this;
113}
114
115
117{
119}
120
121
122REPORTER& NULL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
123{
124 return *this;
125}
126
127
129{
130 static REPORTER* s_nullReporter = nullptr;
131
132 if( !s_nullReporter )
133 s_nullReporter = new NULL_REPORTER();
134
135 return *s_nullReporter;
136}
137
138
139REPORTER& CLI_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
140{
141 FILE* target = stdout;
142
143 if( aSeverity == RPT_SEVERITY_ERROR )
144 target = stderr;
145
146 if( aMsg.EndsWith( wxS( "\n" ) ) )
147 wxFprintf( target, aMsg );
148 else
149 wxFprintf( target, aMsg + wxS( "\n" ) );
150
151 return *this;
152}
153
154
156{
157 static CLI_REPORTER s_cliReporter;
158
159 return s_cliReporter;
160}
161
162
163REPORTER& STDOUT_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
164{
165 switch( aSeverity )
166 {
167 case RPT_SEVERITY_UNDEFINED: std::cout << "SEVERITY_UNDEFINED: "; break;
168 case RPT_SEVERITY_INFO: std::cout << "SEVERITY_INFO: "; break;
169 case RPT_SEVERITY_WARNING: std::cout << "SEVERITY_WARNING: "; break;
170 case RPT_SEVERITY_ERROR: std::cout << "SEVERITY_ERROR: "; break;
171 case RPT_SEVERITY_ACTION: std::cout << "SEVERITY_ACTION: "; break;
172 case RPT_SEVERITY_DEBUG: std::cout << "SEVERITY_DEBUG: "; break;
174 case RPT_SEVERITY_IGNORE: break;
175 }
176
177 std::cout << aMsg << std::endl;
178
179 return *this;
180}
181
182
184{
185 static REPORTER* s_stdoutReporter = nullptr;
186
187 if( !s_stdoutReporter )
188 s_stdoutReporter = new STDOUT_REPORTER();
189
190 return *s_stdoutReporter;
191}
192
193
194REPORTER& WXLOG_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
195{
196 switch( aSeverity )
197 {
198 case RPT_SEVERITY_ERROR: wxLogError( aMsg ); break;
199 case RPT_SEVERITY_WARNING: wxLogWarning( aMsg ); break;
200 case RPT_SEVERITY_UNDEFINED: wxLogMessage( aMsg ); break;
201 case RPT_SEVERITY_INFO: wxLogInfo( aMsg ); break;
202 case RPT_SEVERITY_ACTION: wxLogInfo( aMsg ); break;
203 case RPT_SEVERITY_DEBUG: wxLogTrace( traceReporter, aMsg ); break;
204 case RPT_SEVERITY_EXCLUSION: break;
205 case RPT_SEVERITY_IGNORE: break;
206 }
207
208 return *this;
209}
210
211
213{
214 static REPORTER* s_wxLogReporter = nullptr;
215
216 if( !s_wxLogReporter )
217 s_wxLogReporter = new WXLOG_REPORTER();
218
219 return *s_wxLogReporter;
220}
221
222
223REPORTER& STATUSBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
224{
225 if( m_statusBar )
226 m_statusBar->SetStatusText( aText, m_position );
227
228 return *this;
229}
230
231
233{
234 if( m_statusBar )
235 return !m_statusBar->GetStatusText( m_position ).IsEmpty();
236
237 return false;
238}
239
240
242{
243}
244
245
246REPORTER& INFOBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
247{
248 m_message.reset( new wxString( aText ) );
249 m_severity = aSeverity;
250 m_messageSet = true;
251
252 return *this;
253}
254
255
257{
258 return m_message && !m_message->IsEmpty();
259}
260
261
263{
264 // Don't do anything if no message was ever given
265 if( !m_infoBar || !m_messageSet )
266 return;
267
268 // Short circuit if the message is empty and it is already hidden
269 if( !HasMessage() && !m_infoBar->IsShownOnScreen() )
270 return;
271
272 int icon = wxICON_NONE;
273
274 switch( m_severity )
275 {
276 case RPT_SEVERITY_UNDEFINED: icon = wxICON_INFORMATION; break;
277 case RPT_SEVERITY_INFO: icon = wxICON_INFORMATION; break;
278 case RPT_SEVERITY_EXCLUSION: icon = wxICON_WARNING; break;
279 case RPT_SEVERITY_ACTION: icon = wxICON_WARNING; break;
280 case RPT_SEVERITY_WARNING: icon = wxICON_WARNING; break;
281 case RPT_SEVERITY_ERROR: icon = wxICON_ERROR; break;
282 case RPT_SEVERITY_IGNORE: icon = wxICON_INFORMATION; break;
283 case RPT_SEVERITY_DEBUG: icon = wxICON_INFORMATION; break;
284 }
285
286 if( m_message->EndsWith( wxS( "\n" ) ) )
287 *m_message = m_message->Left( m_message->Length() - 1 );
288
289 if( HasMessage() )
291 else
293}
Reporter forwarding messages to stdout or stderr as appropriate.
Definition: reporter.h:246
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:139
static REPORTER & GetInstance()
Definition: reporter.cpp:155
WX_INFOBAR * m_infoBar
Definition: reporter.h:362
void Finalize()
Update the infobar with the reported text.
Definition: reporter.cpp:262
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:246
SEVERITY m_severity
Definition: reporter.h:364
std::unique_ptr< wxString > m_message
Definition: reporter.h:363
virtual ~INFOBAR_REPORTER()
Definition: reporter.cpp:241
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:256
static REPORTER & GetInstance()
Definition: reporter.cpp:128
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:122
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:223
wxStatusBar * m_statusBar
Definition: reporter.h:323
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:232
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:163
static REPORTER & GetInstance()
Definition: reporter.cpp:183
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:194
static REPORTER & GetInstance()
Definition: reporter.cpp:212
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:116
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:96
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:106
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:86
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: wx_infobar.cpp:121
void QueueDismiss()
Send the infobar an event telling it to hide itself.
Definition: wx_infobar.cpp:132
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:80
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:70
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:64
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:54
static const wxChar traceReporter[]
Flag to enable reporter debugging output.
Definition: reporter.cpp:44
This file contains miscellaneous commonly used macros and functions.
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
wxString From_UTF8(const char *cstring)