KiCad PCB EDA Suite
reporter.cpp
Go to the documentation of this file.
1 
4 /*
5  * This program source code file is part of KiCad, a free EDA CAD application.
6  *
7  * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
8  * Copyright (C) 1992-2015 KiCad Developers, see change_log.txt for contributors.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23  * or you may search the http://www.gnu.org website for the version 2 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #include <macros.h>
29 #include <reporter.h>
30 #include <widgets/infobar.h>
31 #include <wx_html_report_panel.h>
32 
33 REPORTER& REPORTER::Report( const char* aText, SEVERITY aSeverity )
34 {
35  Report( FROM_UTF8( aText ) );
36  return *this;
37 }
38 
39 
40 REPORTER& WX_TEXT_CTRL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
41 {
42  wxCHECK_MSG( m_textCtrl != NULL, *this,
43  wxT( "No wxTextCtrl object defined in WX_TEXT_CTRL_REPORTER." ) );
44 
45  m_textCtrl->AppendText( aText );
46  return *this;
47 }
48 
50 {
51  return !m_textCtrl->IsEmpty();
52 }
53 
54 REPORTER& WX_STRING_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
55 {
56  wxCHECK_MSG( m_string != NULL, *this,
57  wxT( "No wxString object defined in WX_STRING_REPORTER." ) );
58 
59  *m_string << aText;
60  return *this;
61 }
62 
64 {
65  return !m_string->IsEmpty();
66 }
67 
68 REPORTER& WX_HTML_PANEL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
69 {
70  wxCHECK_MSG( m_panel != NULL, *this,
71  wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
72 
73  m_panel->Report( aText, aSeverity );
74  return *this;
75 }
76 
77 REPORTER& WX_HTML_PANEL_REPORTER::ReportTail( const wxString& aText, SEVERITY aSeverity )
78 {
79  wxCHECK_MSG( m_panel != NULL, *this,
80  wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
81 
82  m_panel->Report( aText, aSeverity, LOC_TAIL );
83  return *this;
84 }
85 
86 REPORTER& WX_HTML_PANEL_REPORTER::ReportHead( const wxString& aText, SEVERITY aSeverity )
87 {
88  wxCHECK_MSG( m_panel != NULL, *this,
89  wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
90 
91  m_panel->Report( aText, aSeverity, LOC_HEAD );
92  return *this;
93 }
94 
96 {
98 }
99 
100 REPORTER& NULL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
101 {
102  return *this;
103 }
104 
106 {
107  static REPORTER* s_nullReporter = NULL;
108 
109  if( !s_nullReporter )
110  s_nullReporter = new NULL_REPORTER();
111 
112  return *s_nullReporter;
113 }
114 
115 
116 REPORTER& STDOUT_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
117 {
118  switch( aSeverity )
119  {
120  case RPT_SEVERITY_UNDEFINED: std::cout << "SEVERITY_UNDEFINED: "; break;
121  case RPT_SEVERITY_INFO: std::cout << "SEVERITY_INFO: "; break;
122  case RPT_SEVERITY_WARNING: std::cout << "SEVERITY_WARNING: "; break;
123  case RPT_SEVERITY_ERROR: std::cout << "SEVERITY_ERROR: "; break;
124  case RPT_SEVERITY_ACTION: std::cout << "SEVERITY_ACTION: "; break;
126  case RPT_SEVERITY_IGNORE: break;
127  }
128 
129  std::cout << aText << std::endl;
130 
131  return *this;
132 }
133 
134 
136 {
137  static REPORTER* s_stdoutReporter = nullptr;
138 
139  if( !s_stdoutReporter )
140  s_stdoutReporter = new STDOUT_REPORTER();
141 
142  return *s_stdoutReporter;
143 }
144 
145 
146 REPORTER& STATUSBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
147 {
148  if( m_statusBar )
149  m_statusBar->SetStatusText( aText, m_position );
150 
151  return *this;
152 }
153 
155 {
156  if( m_statusBar )
157  return m_statusBar->GetStatusText().IsEmpty();
158 
159  return false;
160 }
161 
162 
163 REPORTER& INFOBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
164 {
165  m_message = aText;
166  m_severity = aSeverity;
167  m_messageSet = true;
168 
169  return *this;
170 }
171 
172 
174 {
175  return !m_message.IsEmpty();
176 }
177 
178 
180 {
181  // Don't do anything if no message was ever given
182  if( !m_infoBar || !m_messageSet )
183  return;
184 
185  // Short circuit if the message is empty and it is already hidden
186  if( !HasMessage() && !m_infoBar->IsShown() )
187  return;
188 
189  int icon = wxICON_NONE;
190 
191  switch( m_severity )
192  {
193  case RPT_SEVERITY_UNDEFINED: icon = wxICON_INFORMATION; break;
194  case RPT_SEVERITY_INFO: icon = wxICON_INFORMATION; break;
195  case RPT_SEVERITY_EXCLUSION: icon = wxICON_WARNING; break;
196  case RPT_SEVERITY_ACTION: icon = wxICON_WARNING; break;
197  case RPT_SEVERITY_WARNING: icon = wxICON_WARNING; break;
198  case RPT_SEVERITY_ERROR: icon = wxICON_ERROR; break;
199  case RPT_SEVERITY_IGNORE: icon = wxICON_INFORMATION; break;
200  }
201 
202  if( HasMessage() )
204  else
206 }
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:173
wxTextCtrl * m_textCtrl
Definition: reporter.h:133
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:114
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
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
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:95
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
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
This file contains miscellaneous commonly used macros and functions.
SEVERITY m_severity
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:116
#define NULL
wxString m_message
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: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
int Count(int severityMask)
return the number of messages matching the given severity mask.
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
void Report(const wxString &aText, SEVERITY aSeverity, REPORTER::LOCATION aLocation=REPORTER::LOC_BODY)
Reports the string.
void QueueShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION)
Send the infobar an event telling it to show a message.
Definition: infobar.cpp:89
static REPORTER & GetInstance()
Definition: reporter.cpp:135
void QueueDismiss()
Send the infobar an event telling it to hide itself.
Definition: infobar.cpp:100
WX_INFOBAR * m_infoBar
Definition: reporter.h:290
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
wxString * m_string
Definition: reporter.h:158
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
wxStatusBar * m_statusBar
Definition: reporter.h:261
bool HasMessage() const override
Function HasMessage Returns true if the reporter client is non-empty.
Definition: reporter.cpp:154