KiCad PCB EDA Suite
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 <stambaughw@gmail.com>
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 
44 class wxString;
45 class wxStatusBar;
46 class wxTextCtrl;
48 class WX_INFOBAR;
49 
50 
70 class REPORTER
71 {
72 public:
79  enum LOCATION {
80  LOC_HEAD = 0,
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 {
139 public:
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 
155 private:
156  wxTextCtrl* m_textCtrl;
157 };
158 
159 
164 {
165 public:
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 
180 private:
181  wxString* m_string;
182 };
183 
184 
189 {
190 public:
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 
212 private:
214 };
215 
216 
222 class NULL_REPORTER : public REPORTER
223 {
224 public:
226  {
227  }
228 
229  virtual ~NULL_REPORTER()
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 
245 class STDOUT_REPORTER : public REPORTER
246 {
247 public:
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 
264 class WXLOG_REPORTER : public REPORTER
265 {
266 public:
268  {
269  }
270 
271  virtual ~WXLOG_REPORTER()
272  {
273  }
274 
275  static REPORTER& GetInstance();
276 
277  REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
278 
279  bool HasMessage() const override { return false; }
280 };
281 
282 
287 {
288 public:
289  STATUSBAR_REPORTER( wxStatusBar* aStatusBar, int aPosition = 0 )
290  : REPORTER(),
291  m_statusBar( aStatusBar ),
292  m_position( aPosition )
293  {
294  }
295 
296  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
297 
298  bool HasMessage() const override;
299 
300 private:
301  wxStatusBar* m_statusBar;
303 };
304 
305 
316 {
317 public:
319  : REPORTER(),
320  m_messageSet( false ),
321  m_infoBar( aInfoBar ),
323  {
324  }
325 
326  virtual ~INFOBAR_REPORTER();
327 
328  REPORTER& Report( const wxString& aText,
329  SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
330 
331  bool HasMessage() const override;
332 
336  void Finalize();
337 
338 private:
341  std::unique_ptr<wxString> m_message;
343 };
344 
345 #endif // _REPORTER_H_
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:219
A wrapper for reporting to a specific text location in a statusbar.
Definition: reporter.h:286
wxTextCtrl * m_textCtrl
Definition: reporter.h:156
static REPORTER & GetInstance()
Definition: reporter.cpp:175
virtual bool HasMessage() const =0
Returns true if the reporter client is non-empty.
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:158
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
virtual EDA_UNITS GetUnits() const
Definition: reporter.h:123
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.h:279
virtual ~WX_TEXT_CTRL_REPORTER()
Definition: reporter.h:146
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
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
virtual ~WX_STRING_REPORTER()
Definition: reporter.h:172
WX_HTML_PANEL_REPORTER(WX_HTML_REPORT_PANEL *aPanel)
Definition: reporter.h:191
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:105
WX_TEXT_CTRL_REPORTER(wxTextCtrl *aTextCtrl)
Definition: reporter.h:140
WX_HTML_REPORT_PANEL * m_panel
Definition: reporter.h:213
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:75
virtual ~STDOUT_REPORTER()
Definition: reporter.h:252
Debug type reporter, forwarding messages to std::cout.
Definition: reporter.h:245
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:70
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:69
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.h:260
virtual ~NULL_REPORTER()
Definition: reporter.h:229
A wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:137
A singleton reporter that reports to nowhere.
Definition: reporter.h:222
SEVERITY m_severity
Definition: reporter.h:342
virtual ~REPORTER()
Definition: reporter.h:128
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:128
INFOBAR_REPORTER(WX_INFOBAR *aInfoBar)
Definition: reporter.h:318
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:43
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:111
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:186
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:209
void Finalize()
Update the infobar with the reported text.
Definition: reporter.cpp:225
SEVERITY
A wrapper for reporting to a wxString object.
Definition: reporter.h:163
A wrapper for reporting to a wx HTML window.
Definition: reporter.h:188
LOCATION
Location where the message is to be reported.
Definition: reporter.h:79
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
EDA_UNITS
Definition: eda_units.h:38
static REPORTER & GetInstance()
Definition: reporter.cpp:147
virtual ~INFOBAR_REPORTER()
Definition: reporter.cpp:204
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:73
REPORTER & operator<<(const wxString &aText)
Definition: reporter.h:116
virtual ~WXLOG_REPORTER()
Definition: reporter.h:271
WX_INFOBAR * m_infoBar
Definition: reporter.h:340
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:59
WX_STRING_REPORTER(wxString *aString)
Definition: reporter.h:166
virtual ~WX_HTML_PANEL_REPORTER()
Definition: reporter.h:197
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.h:238
wxString * m_string
Definition: reporter.h:181
STATUSBAR_REPORTER(wxStatusBar *aStatusBar, int aPosition=0)
Definition: reporter.h:289
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:53
static REPORTER & GetInstance()
Definition: reporter.cpp:117
A wrapper for reporting to a WX_INFOBAR UI element.
Definition: reporter.h:315
wxStatusBar * m_statusBar
Definition: reporter.h:301
A widget for browsing a rich text error/status report.
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:195
std::unique_ptr< wxString > m_message
Definition: reporter.h:341