KiCad PCB EDA Suite
Loading...
Searching...
No Matches
reporter.h
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) 2013 Wayne Stambaugh <[email protected]>
5 * Copyright (C) 2013-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef _REPORTER_H_
26#define _REPORTER_H_
27
28#include <memory>
29
30#include <eda_units.h>
32
44class wxString;
45class wxStatusBar;
46class wxTextCtrl;
48class WX_INFOBAR;
49
50
71{
72public:
79 enum LOCATION {
83 };
84
93 virtual REPORTER& Report( const wxString& aText,
94 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) = 0;
95
99 virtual REPORTER& ReportTail( const wxString& aText,
100 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
101 {
102 return Report( aText, aSeverity );
103 }
104
108 virtual REPORTER& ReportHead( const wxString& aText,
109 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
110 {
111 return Report( aText, aSeverity );
112 }
113
114 REPORTER& Report( const char* aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED );
115
116 REPORTER& operator <<( const wxString& aText ) { return Report( aText ); }
117
121 virtual bool HasMessage() const = 0;
122
123 virtual EDA_UNITS GetUnits() const
124 {
125 return EDA_UNITS::MILLIMETRES;
126 }
127
128 virtual ~REPORTER()
129 {
130 }
131};
132
133
138{
139public:
140 WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
141 REPORTER(),
142 m_textCtrl( aTextCtrl )
143 {
144 }
145
147 {
148 }
149
150 REPORTER& Report( const wxString& aText,
151 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
152
153 bool HasMessage() const override;
154
155private:
156 wxTextCtrl* m_textCtrl;
157};
158
159
164{
165public:
166 WX_STRING_REPORTER( wxString* aString ) :
167 REPORTER(),
168 m_string( aString )
169 {
170 }
171
173 {
174 }
175
176 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
177
178 bool HasMessage() const override;
179
180private:
181 wxString* m_string;
182};
183
184
189{
190public:
192 REPORTER(),
193 m_panel( aPanel )
194 {
195 }
196
198 {
199 }
200
201 REPORTER& Report( const wxString& aText,
202 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
203
204 REPORTER& ReportTail( const wxString& aText,
205 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
206
207 REPORTER& ReportHead( const wxString& aText,
208 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
209
210 bool HasMessage() const override;
211
212private:
214};
215
216
223{
224public:
226 {
227 }
228
230 {
231 }
232
233 static REPORTER& GetInstance();
234
235 REPORTER& Report( const wxString& aText,
236 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
237
238 bool HasMessage() const override { return false; }
239};
240
241
245class CLI_REPORTER : public REPORTER
246{
247public:
249 {
250 }
251
253 {
254 }
255
256 static REPORTER& GetInstance();
257
258 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
259
260 bool HasMessage() const override { return false; }
261};
262
263
268{
269public:
271 {
272 }
273
275 {
276 }
277
278 static REPORTER& GetInstance();
279
280 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
281
282 bool HasMessage() const override { return false; }
283};
284
285
287{
288public:
290 {
291 }
292
294 {
295 }
296
297 static REPORTER& GetInstance();
298
299 REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
300
301 bool HasMessage() const override { return false; }
302};
303
304
309{
310public:
311 STATUSBAR_REPORTER( wxStatusBar* aStatusBar, int aPosition = 0 )
312 : REPORTER(),
313 m_statusBar( aStatusBar ),
314 m_position( aPosition )
315 {
316 }
317
318 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
319
320 bool HasMessage() const override;
321
322private:
323 wxStatusBar* m_statusBar;
325};
326
327
338{
339public:
341 : REPORTER(),
342 m_messageSet( false ),
343 m_infoBar( aInfoBar ),
345 {
346 }
347
348 virtual ~INFOBAR_REPORTER();
349
350 REPORTER& Report( const wxString& aText,
351 SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
352
353 bool HasMessage() const override;
354
358 void Finalize();
359
360private:
363 std::unique_ptr<wxString> m_message;
365};
366
367#endif // _REPORTER_H_
Reporter forwarding messages to stdout or stderr as appropriate.
Definition: reporter.h:246
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.h:260
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:130
virtual ~CLI_REPORTER()
Definition: reporter.h:252
static REPORTER & GetInstance()
Definition: reporter.cpp:146
A wrapper for reporting to a WX_INFOBAR UI element.
Definition: reporter.h:338
INFOBAR_REPORTER(WX_INFOBAR *aInfoBar)
Definition: reporter.h:340
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
A singleton reporter that reports to nowhere.
Definition: reporter.h:223
static REPORTER & GetInstance()
Definition: reporter.cpp:119
virtual ~NULL_REPORTER()
Definition: reporter.h:229
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:113
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.h:238
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
virtual EDA_UNITS GetUnits() const
Definition: reporter.h:123
REPORTER & operator<<(const wxString &aText)
Definition: reporter.h:116
LOCATION
Location where the message is to be reported.
Definition: reporter.h:79
@ LOC_BODY
Definition: reporter.h:81
@ LOC_TAIL
Definition: reporter.h:82
@ LOC_HEAD
Definition: reporter.h:80
virtual REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the beginning of the list for objects that support ordering.
Definition: reporter.h:108
virtual bool HasMessage() const =0
Returns true if the reporter client is non-empty.
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Places the report at the end of the list, for objects that support report ordering.
Definition: reporter.h:99
virtual ~REPORTER()
Definition: reporter.h:128
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
A wrapper for reporting to a specific text location in a statusbar.
Definition: reporter.h:309
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:214
STATUSBAR_REPORTER(wxStatusBar *aStatusBar, int aPosition=0)
Definition: reporter.h:311
wxStatusBar * m_statusBar
Definition: reporter.h:323
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:223
Debug type reporter, forwarding messages to std::cout.
Definition: reporter.h:268
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
virtual ~STDOUT_REPORTER()
Definition: reporter.h:274
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.h:282
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.h:301
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:185
virtual ~WXLOG_REPORTER()
Definition: reporter.h:293
static REPORTER & GetInstance()
Definition: reporter.cpp:203
A wrapper for reporting to a wx HTML window.
Definition: reporter.h:189
virtual ~WX_HTML_PANEL_REPORTER()
Definition: reporter.h:197
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
WX_HTML_PANEL_REPORTER(WX_HTML_REPORT_PANEL *aPanel)
Definition: reporter.h:191
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
A widget for browsing a rich text error/status report.
A modified version of the wxInfoBar class that allows us to:
Definition: wx_infobar.h:75
A wrapper for reporting to a wxString object.
Definition: reporter.h:164
virtual ~WX_STRING_REPORTER()
Definition: reporter.h:172
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
WX_STRING_REPORTER(wxString *aString)
Definition: reporter.h:166
wxString * m_string
Definition: reporter.h:181
A wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:138
virtual ~WX_TEXT_CTRL_REPORTER()
Definition: reporter.h:146
wxTextCtrl * m_textCtrl
Definition: reporter.h:156
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:55
WX_TEXT_CTRL_REPORTER(wxTextCtrl *aTextCtrl)
Definition: reporter.h:140
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:45
EDA_UNITS
Definition: eda_units.h:46
SEVERITY
@ RPT_SEVERITY_UNDEFINED