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 <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 
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 EDA_UNITS GetUnits() const
122  {
123  return EDA_UNITS::MILLIMETRES;
124  }
125 
126  virtual ~REPORTER()
127  {
128  }
129 };
130 
131 
137 {
138  wxTextCtrl* m_textCtrl;
139 
140 public:
141  WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
142  REPORTER(),
143  m_textCtrl( aTextCtrl )
144  {
145  }
146 
148  {
149  }
150 
151  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
152 
153  bool HasMessage() const override;
154 };
155 
156 
162 {
163  wxString* m_string;
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 
181 
187 {
189 
190 public:
192  REPORTER(),
193  m_panel( aPanel )
194  {
195  }
196 
198  {
199  }
200 
201  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
202 
203  REPORTER& ReportTail( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
204 
205  REPORTER& ReportHead( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
206 
207  bool HasMessage() const override;
208 };
209 
210 
217 class NULL_REPORTER : public REPORTER
218 {
219 public:
221  {
222  }
223 
224  virtual ~NULL_REPORTER()
225  {
226  }
227 
228  static REPORTER& GetInstance();
229 
230  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
231 
232  bool HasMessage() const override { return false; }
233 };
234 
235 
241 class STDOUT_REPORTER : public REPORTER
242 {
243 public:
245  {
246  }
247 
249  {
250  }
251 
252  static REPORTER& GetInstance();
253 
254  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
255 
256  bool HasMessage() const override { return false; }
257 };
258 
259 
265 {
266 private:
267  wxStatusBar* m_statusBar;
269 
270 public:
271  STATUSBAR_REPORTER( wxStatusBar* aStatusBar, int aPosition = 0 )
272  : REPORTER(), m_statusBar( aStatusBar ), m_position( aPosition )
273  {
274  }
275 
276  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
277 
278  bool HasMessage() const override;
279 };
280 
281 
293 {
294 private:
297  wxString m_message;
299 
300 public:
302  : REPORTER(),
303  m_messageSet( false ),
304  m_infoBar( aInfoBar ),
305  m_message( wxEmptyString ),
307  {
308  }
309 
310  REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
311 
312  bool HasMessage() const override;
313 
317  void Finalize();
318 };
319 
320 #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:264
wxTextCtrl * m_textCtrl
Definition: reporter.h:138
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
virtual EDA_UNITS GetUnits() const
Definition: reporter.h:121
SEVERITY
Definition: ui_common.h:76
virtual ~WX_TEXT_CTRL_REPORTER()
Definition: reporter.h:147
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:172
WX_HTML_PANEL_REPORTER(WX_HTML_REPORT_PANEL *aPanel)
Definition: reporter.h:191
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:141
WX_HTML_REPORT_PANEL * m_panel
Definition: reporter.h:188
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:248
STDOUT_REPORTER.
Definition: reporter.h:241
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:256
virtual ~NULL_REPORTER()
Definition: reporter.h:224
WX_TEXT_CTRL_REPORTER is wrapper for reporting to a wxTextCtrl object.
Definition: reporter.h:136
NULL_REPORTER.
Definition: reporter.h:217
SEVERITY m_severity
Definition: reporter.h:298
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:126
INFOBAR_REPORTER(WX_INFOBAR *aInfoBar)
Definition: reporter.h:301
wxString m_message
Definition: reporter.h:297
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:161
WX_HTML_PANEL_REPORTER is a wrapper for reporting to a wx HTML window.
Definition: reporter.h:186
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
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:70
REPORTER & operator<<(const wxString &aText)
Definition: reporter.h:110
WX_INFOBAR * m_infoBar
Definition: reporter.h:296
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:166
virtual ~WX_HTML_PANEL_REPORTER()
Definition: reporter.h:197
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.h:232
wxString * m_string
Definition: reporter.h:163
STATUSBAR_REPORTER(wxStatusBar *aStatusBar, int aPosition=0)
Definition: reporter.h:271
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:292
wxStatusBar * m_statusBar
Definition: reporter.h:267
WX_HTML_REPORT_PANEL.
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:154