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) 1992-2013 KiCad Developers, see change_log.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 <wx/string.h>
29 #include <widgets/ui_common.h>
30 
38 class wxStatusBar;
39 class wxTextCtrl;
40 class wxHtmlListbox;
42 class WX_INFOBAR;
43 
44 
64 class REPORTER {
65 
66 public:
73  enum LOCATION {
74  LOC_HEAD = 0,
77  };
78 
88  virtual REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) = 0;
89 
94  virtual REPORTER& ReportTail( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
95  {
96  return Report( aText, aSeverity );
97  }
98 
103  virtual REPORTER& ReportHead( const wxString& aText, 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 
119  virtual bool HasMessage() const = 0;
120 
121  virtual ~REPORTER()
122  {
123  }
124 };
125 
126 
132 {
133  wxTextCtrl* m_textCtrl;
134 
135 public:
136  WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
137  REPORTER(),
138  m_textCtrl( aTextCtrl )
139  {
140  }
141 
143  {
144  }
145 
146  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
147 
148  bool HasMessage() const override;
149 };
150 
151 
157 {
158  wxString* m_string;
159 
160 public:
161  WX_STRING_REPORTER( wxString* aString ) :
162  REPORTER(),
163  m_string( aString )
164  {
165  }
166 
168  {
169  }
170 
171  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
172 
173  bool HasMessage() const override;
174 };
175 
176 
182 {
184 
185 public:
187  REPORTER(),
188  m_panel( aPanel )
189  {
190  }
191 
193  {
194  }
195 
196  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
197 
198  REPORTER& ReportTail( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
199 
200  REPORTER& ReportHead( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
201 
202  bool HasMessage() const override;
203 };
204 
205 
212 class NULL_REPORTER : public REPORTER
213 {
214 public:
216  {
217  }
218 
219  virtual ~NULL_REPORTER()
220  {
221  }
222 
223  static REPORTER& GetInstance();
224 
225  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
226 
227  bool HasMessage() const override { return false; }
228 };
229 
230 
236 class STDOUT_REPORTER : public REPORTER
237 {
238 public:
240  {
241  }
242 
244  {
245  }
246 
247  static REPORTER& GetInstance();
248 
249  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
250 
251  bool HasMessage() const override { return false; }
252 };
253 
254 
260 {
261 private:
262  wxStatusBar* m_statusBar;
264 
265 public:
266  STATUSBAR_REPORTER( wxStatusBar* aStatusBar, int aPosition = 0 )
267  : REPORTER(), m_statusBar( aStatusBar ), m_position( aPosition )
268  {
269  }
270 
271  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
272 
273  bool HasMessage() const override;
274 };
275 
276 
288 {
289 private:
292  wxString m_message;
294 
295 public:
297  : REPORTER(),
298  m_messageSet( false ),
299  m_infoBar( aInfoBar ),
300  m_message( wxEmptyString ),
302  {
303  }
304 
305  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
306 
307  bool HasMessage() const override;
308 
312  void Finalize();
313 };
314 
315 #endif // _REPORTER_H_
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:173
STATUSBAR_REPORTER is a wrapper for reporting to a specific text location in a statusbar.
Definition: reporter.h:259
wxTextCtrl * m_textCtrl
Definition: reporter.h:133
virtual bool HasMessage() const =0
Function HasMessage Returns true if the reporter client is non-empty.
REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function ReportTail Places the report at the end of the list, for objects that support report orderin...
Definition: reporter.cpp:77
SEVERITY
Definition: ui_common.h:45
virtual ~WX_TEXT_CTRL_REPORTER()
Definition: reporter.h:142
virtual REPORTER & ReportTail(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Function ReportTail Places the report at the end of the list, for objects that support report orderin...
Definition: reporter.h:94
REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function ReportHead 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:167
WX_HTML_PANEL_REPORTER(WX_HTML_REPORT_PANEL *aPanel)
Definition: reporter.h:186
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:95
WX_TEXT_CTRL_REPORTER(wxTextCtrl *aTextCtrl)
Definition: reporter.h:136
WX_HTML_REPORT_PANEL * m_panel
Definition: reporter.h:183
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:68
virtual ~STDOUT_REPORTER()
Definition: reporter.h:243
STDOUT_REPORTER.
Definition: reporter.h:236
REPORTER is 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
Function Report is a pure virtual function to override in the derived object.
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:63
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.h:251
virtual ~NULL_REPORTER()
Definition: reporter.h:219
WX_TEXT_CTRL_REPORTER is wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:131
NULL_REPORTER.
Definition: reporter.h:212
SEVERITY m_severity
Definition: reporter.h:293
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:116
virtual ~REPORTER()
Definition: reporter.h:121
INFOBAR_REPORTER(WX_INFOBAR *aInfoBar)
Definition: reporter.h:296
wxString m_message
Definition: reporter.h:292
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:40
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
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
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:146
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:163
void Finalize()
Update the infobar with the reported text.
Definition: reporter.cpp:179
WX_STRING_REPORTER is a wrapper for reporting to a wxString object.
Definition: reporter.h:156
WX_HTML_PANEL_REPORTER is a wrapper for reporting to a wx HTML window.
Definition: reporter.h:181
LOCATION
Location where the message is to be reported.
Definition: reporter.h:73
virtual REPORTER & ReportHead(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Function ReportHead Places the report at the beginning of the list for objects that support ordering.
Definition: reporter.h:103
static REPORTER & GetInstance()
Definition: reporter.cpp:135
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:68
REPORTER & operator<<(const wxString &aText)
Definition: reporter.h:110
WX_INFOBAR * m_infoBar
Definition: reporter.h:291
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Function Report is a pure virtual function to override in the derived object.
Definition: reporter.cpp:54
WX_STRING_REPORTER(wxString *aString)
Definition: reporter.h:161
virtual ~WX_HTML_PANEL_REPORTER()
Definition: reporter.h:192
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.h:227
wxString * m_string
Definition: reporter.h:158
STATUSBAR_REPORTER(wxStatusBar *aStatusBar, int aPosition=0)
Definition: reporter.h:266
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:49
static REPORTER & GetInstance()
Definition: reporter.cpp:105
INFOBAR_REPORTER is a wrapper for reporting to a WX_INFOBAR UI element.
Definition: reporter.h:287
wxStatusBar * m_statusBar
Definition: reporter.h:262
WX_HTML_REPORT_PANEL.
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:154