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