KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
8 * Copyright (C) 2013-2021, 2024 KiCad Developers, see AUTHORS.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 <string_utils.h>
31#include <widgets/wx_infobar.h>
32#include <wx/crt.h>
33#include <wx/log.h>
34#include <wx/textctrl.h>
35#include <wx/statusbr.h>
36
37
43static const wxChar traceReporter[] = wxT( "KICAD_REPORTER" );
44
45
46REPORTER& REPORTER::Report( const char* aText, SEVERITY aSeverity )
47{
48 Report( From_UTF8( aText ) );
49 return *this;
50}
51
52
53bool REPORTER::HasMessageOfSeverity( int aSeverityMask ) const
54{
55 wxFAIL_MSG( "HasMessageOfSeverity is not implemented in this reporter" );
56 return HasMessage();
57}
58
59
60REPORTER& WX_TEXT_CTRL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
61{
62 wxCHECK_MSG( m_textCtrl != nullptr, *this,
63 wxT( "No wxTextCtrl object defined in WX_TEXT_CTRL_REPORTER." ) );
64
65 m_textCtrl->AppendText( aText + wxS( "\n" ) );
66 return *this;
67}
68
69
71{
72 return !m_textCtrl->IsEmpty();
73}
74
75
76REPORTER& WX_STRING_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
77{
78 m_severityMask |= aSeverity;
79 m_string << aText << wxS( "\n" );
80 return *this;
81}
82
83
84const wxString& WX_STRING_REPORTER::GetMessages() const
85{
86 return m_string;
87}
88
89
91{
93 m_string.clear();
94}
95
96
98{
99 return !m_string.IsEmpty();
100}
101
102
103bool WX_STRING_REPORTER::HasMessageOfSeverity( int aSeverityMask ) const
104{
105 return ( m_severityMask & aSeverityMask ) != 0;
106}
107
108
109REPORTER& NULL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
110{
111 return *this;
112}
113
114
116{
117 static REPORTER* s_nullReporter = nullptr;
118
119 if( !s_nullReporter )
120 s_nullReporter = new NULL_REPORTER();
121
122 return *s_nullReporter;
123}
124
125
126REPORTER& CLI_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
127{
128 FILE* target = stdout;
129
130 if( aSeverity == RPT_SEVERITY_ERROR )
131 target = stderr;
132
133 if( aMsg.EndsWith( wxS( "\n" ) ) )
134 wxFprintf( target, aMsg );
135 else
136 wxFprintf( target, aMsg + wxS( "\n" ) );
137
138 return *this;
139}
140
141
143{
144 static CLI_REPORTER s_cliReporter;
145
146 return s_cliReporter;
147}
148
149
150REPORTER& STDOUT_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
151{
152 switch( aSeverity )
153 {
154 case RPT_SEVERITY_UNDEFINED: std::cout << "SEVERITY_UNDEFINED: "; break;
155 case RPT_SEVERITY_INFO: std::cout << "SEVERITY_INFO: "; break;
156 case RPT_SEVERITY_WARNING: std::cout << "SEVERITY_WARNING: "; break;
157 case RPT_SEVERITY_ERROR: std::cout << "SEVERITY_ERROR: "; break;
158 case RPT_SEVERITY_ACTION: std::cout << "SEVERITY_ACTION: "; break;
159 case RPT_SEVERITY_DEBUG: std::cout << "SEVERITY_DEBUG: "; break;
161 case RPT_SEVERITY_IGNORE: break;
162 }
163
164 std::cout << aMsg << std::endl;
165
166 return *this;
167}
168
169
171{
172 static REPORTER* s_stdoutReporter = nullptr;
173
174 if( !s_stdoutReporter )
175 s_stdoutReporter = new STDOUT_REPORTER();
176
177 return *s_stdoutReporter;
178}
179
180
181REPORTER& WXLOG_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity )
182{
183 switch( aSeverity )
184 {
185 case RPT_SEVERITY_ERROR: wxLogError( aMsg ); break;
186 case RPT_SEVERITY_WARNING: wxLogWarning( aMsg ); break;
187 case RPT_SEVERITY_UNDEFINED: wxLogMessage( aMsg ); break;
188 case RPT_SEVERITY_INFO: wxLogInfo( aMsg ); break;
189 case RPT_SEVERITY_ACTION: wxLogInfo( aMsg ); break;
190 case RPT_SEVERITY_DEBUG: wxLogTrace( traceReporter, aMsg ); break;
191 case RPT_SEVERITY_EXCLUSION: break;
192 case RPT_SEVERITY_IGNORE: break;
193 }
194
195 return *this;
196}
197
198
200{
201 static REPORTER* s_wxLogReporter = nullptr;
202
203 if( !s_wxLogReporter )
204 s_wxLogReporter = new WXLOG_REPORTER();
205
206 return *s_wxLogReporter;
207}
208
209
210REPORTER& STATUSBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
211{
212 if( m_statusBar )
213 m_statusBar->SetStatusText( aText, m_position );
214
215 return *this;
216}
217
218
220{
221 if( m_statusBar )
222 return !m_statusBar->GetStatusText( m_position ).IsEmpty();
223
224 return false;
225}
Reporter forwarding messages to stdout or stderr as appropriate.
Definition: reporter.h:226
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:126
static REPORTER & GetInstance()
Definition: reporter.cpp:142
static REPORTER & GetInstance()
Definition: reporter.cpp:115
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:109
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
virtual bool HasMessageOfSeverity(int aSeverityMask) const
Returns true if the reporter has one or more messages matching the specified severity mask.
Definition: reporter.cpp:53
virtual bool HasMessage() const =0
Returns true if the reporter client is non-empty.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:210
wxStatusBar * m_statusBar
Definition: reporter.h:303
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:219
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:150
static REPORTER & GetInstance()
Definition: reporter.cpp:170
REPORTER & Report(const wxString &aMsg, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:181
static REPORTER & GetInstance()
Definition: reporter.cpp:199
wxString m_string
Definition: reporter.h:192
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:97
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:76
bool HasMessageOfSeverity(int aSeverityMask) const override
Returns true if the reporter has one or more messages matching the specified severity mask.
Definition: reporter.cpp:103
const wxString & GetMessages() const
Definition: reporter.cpp:84
wxTextCtrl * m_textCtrl
Definition: reporter.h:163
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:70
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition: reporter.cpp:60
static const wxChar traceReporter[]
Flag to enable reporter debugging output.
Definition: reporter.cpp:43
This file contains miscellaneous commonly used macros and functions.
SEVERITY
@ RPT_SEVERITY_WARNING
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
@ RPT_SEVERITY_EXCLUSION
@ RPT_SEVERITY_IGNORE
@ RPT_SEVERITY_DEBUG
@ RPT_SEVERITY_INFO
@ RPT_SEVERITY_ACTION
wxString From_UTF8(const char *cstring)