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@verizon.net>
5  * Copyright (C) 2013-2020 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 <eda_units.h>
29 #include <wx/string.h>
30 #include <widgets/ui_common.h>
31 
39 class wxStatusBar;
40 class wxTextCtrl;
42 class WX_INFOBAR;
43 
44 
64 class REPORTER
65 {
66 public:
73  enum LOCATION {
74  LOC_HEAD = 0,
77  };
78 
87  virtual REPORTER& Report( const wxString& aText,
88  SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) = 0;
89 
93  virtual REPORTER& ReportTail( const wxString& aText,
94  SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
95  {
96  return Report( aText, aSeverity );
97  }
98 
102  virtual REPORTER& ReportHead( const wxString& aText,
103  SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
104  {
105  return Report( aText, aSeverity );
106  }
107 
108  REPORTER& Report( const char* aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED );
109 
110  REPORTER& operator <<( const wxString& aText ) { return Report( aText ); }
111  REPORTER& operator <<( const wxChar* aText ) { return Report( wxString( aText ) ); }
112  REPORTER& operator <<( wxChar aChar ) { return Report( wxString( aChar ) ); }
113  REPORTER& operator <<( const char* aText ) { return Report( aText ); }
114 
118  virtual bool HasMessage() const = 0;
119 
120  virtual EDA_UNITS GetUnits() const
121  {
122  return EDA_UNITS::MILLIMETRES;
123  }
124 
125  virtual ~REPORTER()
126  {
127  }
128 };
129 
130 
135 {
136  wxTextCtrl* m_textCtrl;
137 
138 public:
139  WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
140  REPORTER(),
141  m_textCtrl( aTextCtrl )
142  {
143  }
144 
146  {
147  }
148 
149  REPORTER& Report( const wxString& aText,
150  SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
151 
152  bool HasMessage() const override;
153 };
154 
155 
160 {
161  wxString* m_string;
162 
163 public:
164  WX_STRING_REPORTER( wxString* aString ) :
165  REPORTER(),
166  m_string( aString )
167  {
168  }
169 
171  {
172  }
173 
174  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
175 
176  bool HasMessage() const override;
177 };
178 
179 
184 {
186 
187 public:
189  REPORTER(),
190  m_panel( aPanel )
191  {
192  }
193 
195  {
196  }
197 
198  REPORTER& Report( const wxString& aText,
199  SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
200 
201  REPORTER& ReportTail( const wxString& aText,
202  SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
203 
204  REPORTER& ReportHead( const wxString& aText,
205  SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
206 
207  bool HasMessage() const override;
208 };
209 
210 
216 class NULL_REPORTER : public REPORTER
217 {
218 public:
220  {
221  }
222 
223  virtual ~NULL_REPORTER()
224  {
225  }
226 
227  static REPORTER& GetInstance();
228 
229  REPORTER& Report( const wxString& aText,
230  SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
231 
232  bool HasMessage() const override { return false; }
233 };
234 
235 
239 class STDOUT_REPORTER : public REPORTER
240 {
241 public:
243  {
244  }
245 
247  {
248  }
249 
250  static REPORTER& GetInstance();
251 
252  REPORTER& Report( const wxString& aText,
253  SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
254 
255  bool HasMessage() const override { return false; }
256 };
257 
258 
263 {
264 public:
265  STATUSBAR_REPORTER( wxStatusBar* aStatusBar, int aPosition = 0 )
266  : REPORTER(),
267  m_statusBar( aStatusBar ),
268  m_position( aPosition )
269  {
270  }
271 
272  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
273 
274  bool HasMessage() const override;
275 
276 private:
277  wxStatusBar* m_statusBar;
279 };
280 
281 
292 {
293 public:
295  : REPORTER(),
296  m_messageSet( false ),
297  m_infoBar( aInfoBar ),
298  m_message( wxEmptyString ),
300  {
301  }
302 
303  REPORTER& Report( const wxString& aText,
304  SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
305 
306  bool HasMessage() const override;
307 
311  void Finalize();
312 
313 private:
316  wxString m_message;
318 };
319 
320 #endif // _REPORTER_H_
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:173
A wrapper for reporting to a specific text location in a statusbar.
Definition: reporter.h:262
wxTextCtrl * m_textCtrl
Definition: reporter.h:136
virtual bool HasMessage() const =0
Returns true if the reporter client is non-empty.
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:77
virtual EDA_UNITS GetUnits() const
Definition: reporter.h:120
SEVERITY
Definition: ui_common.h:83
virtual ~WX_TEXT_CTRL_REPORTER()
Definition: reporter.h:145
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:93
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:86
virtual ~WX_STRING_REPORTER()
Definition: reporter.h:170
WX_HTML_PANEL_REPORTER(WX_HTML_REPORT_PANEL *aPanel)
Definition: reporter.h:188
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:95
WX_TEXT_CTRL_REPORTER(wxTextCtrl *aTextCtrl)
Definition: reporter.h:139
WX_HTML_REPORT_PANEL * m_panel
Definition: reporter.h:185
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:68
virtual ~STDOUT_REPORTER()
Definition: reporter.h:246
Debug type reporter, forwarding messages to std::cout.
Definition: reporter.h:239
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:64
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:63
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.h:255
virtual ~NULL_REPORTER()
Definition: reporter.h:223
A wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:134
A singleton reporter that reports to nowhere.
Definition: reporter.h:216
SEVERITY m_severity
Definition: reporter.h:317
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:116
virtual ~REPORTER()
Definition: reporter.h:125
INFOBAR_REPORTER(WX_INFOBAR *aInfoBar)
Definition: reporter.h:294
wxString m_message
Definition: reporter.h:316
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:40
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:100
Functions to provide common constants and other functions to assist in making a consistent UI.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:146
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:163
void Finalize()
Update the infobar with the reported text.
Definition: reporter.cpp:179
A wrapper for reporting to a wxString object.
Definition: reporter.h:159
A wrapper for reporting to a wx HTML window.
Definition: reporter.h:183
LOCATION
Location where the message is to be reported.
Definition: reporter.h:73
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:102
EDA_UNITS
Definition: eda_units.h:38
static REPORTER & GetInstance()
Definition: reporter.cpp:135
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:71
REPORTER & operator<<(const wxString &aText)
Definition: reporter.h:110
WX_INFOBAR * m_infoBar
Definition: reporter.h:315
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:54
WX_STRING_REPORTER(wxString *aString)
Definition: reporter.h:164
virtual ~WX_HTML_PANEL_REPORTER()
Definition: reporter.h:194
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.h:232
wxString * m_string
Definition: reporter.h:161
STATUSBAR_REPORTER(wxStatusBar *aStatusBar, int aPosition=0)
Definition: reporter.h:265
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:49
static REPORTER & GetInstance()
Definition: reporter.cpp:105
A wrapper for reporting to a WX_INFOBAR UI element.
Definition: reporter.h:291
wxStatusBar * m_statusBar
Definition: reporter.h:277
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:154