2013-05-26 04:36:44 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-08-16 11:49:22 +00:00
|
|
|
* Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
|
|
|
|
* Copyright (C) 2013-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2016-01-12 16:33:33 +00:00
|
|
|
#ifndef _REPORTER_H_
|
|
|
|
#define _REPORTER_H_
|
|
|
|
|
2021-08-16 11:49:22 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2020-10-24 14:45:37 +00:00
|
|
|
#include <eda_units.h>
|
2021-08-16 11:49:22 +00:00
|
|
|
#include <widgets/report_severity.h>
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2016-01-12 16:33:33 +00:00
|
|
|
/**
|
|
|
|
* @file reporter.h
|
|
|
|
* @author Wayne Stambaugh
|
|
|
|
* @note A special thanks to Dick Hollenbeck who came up with the idea that inspired
|
|
|
|
* me to write this.
|
2021-08-16 11:49:22 +00:00
|
|
|
* @warning Do not add any dependencies to wxWidgets (or any other third party UI library )
|
|
|
|
* to the REPORTER object. All wxWidgets objects should be defined by pointer or
|
|
|
|
* reference and forward declared so that using reporters in low level KiCad objects
|
|
|
|
* will not require pulling in wxWidgets to building them.
|
2016-01-12 16:33:33 +00:00
|
|
|
*/
|
2013-05-26 04:36:44 +00:00
|
|
|
|
2021-08-16 11:49:22 +00:00
|
|
|
class wxString;
|
2020-06-03 23:00:40 +00:00
|
|
|
class wxStatusBar;
|
2013-05-26 04:36:44 +00:00
|
|
|
class wxTextCtrl;
|
2015-06-16 12:20:42 +00:00
|
|
|
class WX_HTML_REPORT_PANEL;
|
2020-06-03 23:00:40 +00:00
|
|
|
class WX_INFOBAR;
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* A pure virtual class used to derive REPORTER objects from.
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
2013-06-13 11:43:29 +00:00
|
|
|
* The purpose of the REPORTER object is to offer a way for a procedural function
|
|
|
|
* to report multiple errors without having to:
|
|
|
|
* <ul>
|
2013-06-13 16:09:35 +00:00
|
|
|
* <li> know too much about the caller's UI, i.e. wx. </li>
|
|
|
|
* <li> stop after the first error </li>
|
2013-06-13 11:43:29 +00:00
|
|
|
* </ul>
|
2015-06-16 12:20:42 +00:00
|
|
|
* the reporter has 4 severity levels (flags) tagging the messages:
|
2020-12-21 15:17:52 +00:00
|
|
|
* - information
|
|
|
|
* - warning
|
|
|
|
* - error
|
|
|
|
* - action (i.e. indication of changes - add component, change footprint, etc. )
|
|
|
|
*
|
2015-06-16 12:20:42 +00:00
|
|
|
* They are indicators for the message formatting and displaying code,
|
|
|
|
* filtering is not made here.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
2015-06-16 12:20:42 +00:00
|
|
|
|
2020-12-21 15:17:52 +00:00
|
|
|
class REPORTER
|
|
|
|
{
|
2013-05-26 04:36:44 +00:00
|
|
|
public:
|
2018-05-21 22:28:26 +00:00
|
|
|
/**
|
|
|
|
* Location where the message is to be reported.
|
|
|
|
* LOC_HEAD messages are printed before all others (typically intro messages)
|
|
|
|
* LOC_BODY messages are printed in the middle
|
|
|
|
* LOC_TAIL messages are printed after all others (typically status messages)
|
|
|
|
*/
|
|
|
|
enum LOCATION {
|
|
|
|
LOC_HEAD = 0,
|
|
|
|
LOC_BODY,
|
|
|
|
LOC_TAIL
|
2015-06-16 12:20:42 +00:00
|
|
|
};
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Report a string with a given severity.
|
2013-05-26 04:36:44 +00:00
|
|
|
*
|
|
|
|
* @param aText is the string to report.
|
2020-12-21 15:17:52 +00:00
|
|
|
* @param aSeverity is an indicator ( RPT_UNDEFINED, RPT_INFO, RPT_WARNING, RPT_ERROR,
|
|
|
|
* RPT_ACTION ) used to filter and format messages
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
|
|
|
|
2020-12-21 15:17:52 +00:00
|
|
|
virtual REPORTER& Report( const wxString& aText,
|
|
|
|
SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) = 0;
|
2015-06-16 12:20:42 +00:00
|
|
|
|
2018-05-21 22:28:26 +00:00
|
|
|
/**
|
|
|
|
* Places the report at the end of the list, for objects that support report ordering
|
|
|
|
*/
|
2020-12-21 15:17:52 +00:00
|
|
|
virtual REPORTER& ReportTail( const wxString& aText,
|
|
|
|
SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
|
2018-05-21 22:28:26 +00:00
|
|
|
{
|
|
|
|
return Report( aText, aSeverity );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Places the report at the beginning of the list for objects that support ordering.
|
2018-05-21 22:28:26 +00:00
|
|
|
*/
|
2020-12-21 15:17:52 +00:00
|
|
|
virtual REPORTER& ReportHead( const wxString& aText,
|
|
|
|
SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED )
|
2018-05-21 22:28:26 +00:00
|
|
|
{
|
|
|
|
return Report( aText, aSeverity );
|
|
|
|
}
|
|
|
|
|
2020-03-04 09:48:18 +00:00
|
|
|
REPORTER& Report( const char* aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED );
|
2013-05-26 04:36:44 +00:00
|
|
|
|
|
|
|
REPORTER& operator <<( const wxString& aText ) { return Report( aText ); }
|
2018-02-17 11:43:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the reporter client is non-empty.
|
|
|
|
*/
|
|
|
|
virtual bool HasMessage() const = 0;
|
2020-02-05 22:19:14 +00:00
|
|
|
|
2020-09-10 18:28:00 +00:00
|
|
|
virtual EDA_UNITS GetUnits() const
|
|
|
|
{
|
|
|
|
return EDA_UNITS::MILLIMETRES;
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:19:14 +00:00
|
|
|
virtual ~REPORTER()
|
|
|
|
{
|
|
|
|
}
|
2013-05-26 04:36:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* A wrapper for reporting to a wxTextCtrl object.
|
2013-05-26 04:36:44 +00:00
|
|
|
*/
|
|
|
|
class WX_TEXT_CTRL_REPORTER : public REPORTER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WX_TEXT_CTRL_REPORTER( wxTextCtrl* aTextCtrl ) :
|
|
|
|
REPORTER(),
|
|
|
|
m_textCtrl( aTextCtrl )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:19:14 +00:00
|
|
|
virtual ~WX_TEXT_CTRL_REPORTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:17:52 +00:00
|
|
|
REPORTER& Report( const wxString& aText,
|
|
|
|
SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
|
2018-02-17 11:43:56 +00:00
|
|
|
|
|
|
|
bool HasMessage() const override;
|
2021-08-16 11:49:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
wxTextCtrl* m_textCtrl;
|
2013-05-26 04:36:44 +00:00
|
|
|
};
|
|
|
|
|
2013-09-14 20:33:22 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* A wrapper for reporting to a wxString object.
|
2013-09-14 20:33:22 +00:00
|
|
|
*/
|
|
|
|
class WX_STRING_REPORTER : public REPORTER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WX_STRING_REPORTER( wxString* aString ) :
|
|
|
|
REPORTER(),
|
|
|
|
m_string( aString )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:19:14 +00:00
|
|
|
virtual ~WX_STRING_REPORTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-04 09:48:18 +00:00
|
|
|
REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
|
2018-02-17 11:43:56 +00:00
|
|
|
|
|
|
|
bool HasMessage() const override;
|
2021-08-16 11:49:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
wxString* m_string;
|
2015-06-16 12:20:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* A wrapper for reporting to a wx HTML window.
|
2015-06-16 12:20:42 +00:00
|
|
|
*/
|
|
|
|
class WX_HTML_PANEL_REPORTER : public REPORTER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WX_HTML_PANEL_REPORTER( WX_HTML_REPORT_PANEL* aPanel ) :
|
|
|
|
REPORTER(),
|
|
|
|
m_panel( aPanel )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:19:14 +00:00
|
|
|
virtual ~WX_HTML_PANEL_REPORTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-21 15:17:52 +00:00
|
|
|
REPORTER& Report( const wxString& aText,
|
|
|
|
SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
|
2018-02-17 11:43:56 +00:00
|
|
|
|
2020-12-21 15:17:52 +00:00
|
|
|
REPORTER& ReportTail( const wxString& aText,
|
|
|
|
SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
|
2018-05-21 22:28:26 +00:00
|
|
|
|
2020-12-21 15:17:52 +00:00
|
|
|
REPORTER& ReportHead( const wxString& aText,
|
|
|
|
SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
|
2018-05-21 22:28:26 +00:00
|
|
|
|
2018-02-17 11:43:56 +00:00
|
|
|
bool HasMessage() const override;
|
2021-08-16 11:49:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
WX_HTML_REPORT_PANEL* m_panel;
|
2013-09-14 20:33:22 +00:00
|
|
|
};
|
|
|
|
|
2020-07-30 11:20:55 +00:00
|
|
|
|
2015-07-24 15:47:48 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* A singleton reporter that reports to nowhere.
|
2015-07-24 15:47:48 +00:00
|
|
|
*
|
2020-12-21 15:17:52 +00:00
|
|
|
* Used as to simplify code by avoiding the reportee to check for a non-NULL reporter object.
|
2015-07-24 15:47:48 +00:00
|
|
|
*/
|
|
|
|
class NULL_REPORTER : public REPORTER
|
|
|
|
{
|
2018-02-17 11:43:56 +00:00
|
|
|
public:
|
|
|
|
NULL_REPORTER()
|
|
|
|
{
|
|
|
|
}
|
2015-07-24 15:47:48 +00:00
|
|
|
|
2020-02-05 22:19:14 +00:00
|
|
|
virtual ~NULL_REPORTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-17 11:43:56 +00:00
|
|
|
static REPORTER& GetInstance();
|
|
|
|
|
2020-12-21 15:17:52 +00:00
|
|
|
REPORTER& Report( const wxString& aText,
|
|
|
|
SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
|
2015-07-24 15:47:48 +00:00
|
|
|
|
2018-02-17 11:43:56 +00:00
|
|
|
bool HasMessage() const override { return false; }
|
2015-07-24 15:47:48 +00:00
|
|
|
};
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
|
2023-03-24 10:31:08 +00:00
|
|
|
/**
|
|
|
|
* Reporter forwarding messages to stdout or stderr as appropriate
|
|
|
|
*/
|
|
|
|
class CLI_REPORTER : public REPORTER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CLI_REPORTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~CLI_REPORTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static REPORTER& GetInstance();
|
|
|
|
|
|
|
|
REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
|
|
|
|
|
|
|
|
bool HasMessage() const override { return false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-02-28 10:30:10 +00:00
|
|
|
/**
|
|
|
|
* Debug type reporter, forwarding messages to std::cout.
|
|
|
|
*/
|
|
|
|
class STDOUT_REPORTER : public REPORTER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
STDOUT_REPORTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-02-05 22:19:14 +00:00
|
|
|
virtual ~STDOUT_REPORTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-28 10:30:10 +00:00
|
|
|
static REPORTER& GetInstance();
|
|
|
|
|
2021-03-31 21:33:30 +00:00
|
|
|
REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
|
|
|
|
|
|
|
|
bool HasMessage() const override { return false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class WXLOG_REPORTER : public REPORTER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WXLOG_REPORTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~WXLOG_REPORTER()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static REPORTER& GetInstance();
|
|
|
|
|
|
|
|
REPORTER& Report( const wxString& aMsg, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
|
2018-02-28 10:30:10 +00:00
|
|
|
|
|
|
|
bool HasMessage() const override { return false; }
|
|
|
|
};
|
|
|
|
|
2020-06-03 23:00:40 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* A wrapper for reporting to a specific text location in a statusbar.
|
2020-06-03 23:00:40 +00:00
|
|
|
*/
|
|
|
|
class STATUSBAR_REPORTER : public REPORTER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
STATUSBAR_REPORTER( wxStatusBar* aStatusBar, int aPosition = 0 )
|
2020-12-21 15:17:52 +00:00
|
|
|
: REPORTER(),
|
|
|
|
m_statusBar( aStatusBar ),
|
|
|
|
m_position( aPosition )
|
2020-06-03 23:00:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
|
|
|
|
|
|
|
|
bool HasMessage() const override;
|
2020-12-21 15:17:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
wxStatusBar* m_statusBar;
|
|
|
|
int m_position;
|
2020-06-03 23:00:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* A wrapper for reporting to a #WX_INFOBAR UI element.
|
2020-06-03 23:00:40 +00:00
|
|
|
*
|
|
|
|
* The infobar is not updated until the @c Finalize() method is called. That method will
|
|
|
|
* queue either a show message or a dismiss event for the infobar - so this reporter is
|
|
|
|
* safe to use inside a paint event without causing an infinite paint event loop.
|
|
|
|
*
|
|
|
|
* No action is taken if no message is given to the reporter.
|
|
|
|
*/
|
|
|
|
class INFOBAR_REPORTER : public REPORTER
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
INFOBAR_REPORTER( WX_INFOBAR* aInfoBar )
|
2020-06-05 11:49:32 +00:00
|
|
|
: REPORTER(),
|
|
|
|
m_messageSet( false ),
|
|
|
|
m_infoBar( aInfoBar ),
|
|
|
|
m_severity( RPT_SEVERITY_UNDEFINED )
|
2020-06-03 23:00:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-16 11:49:22 +00:00
|
|
|
virtual ~INFOBAR_REPORTER();
|
|
|
|
|
2020-12-21 15:17:52 +00:00
|
|
|
REPORTER& Report( const wxString& aText,
|
|
|
|
SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
|
2020-06-03 23:00:40 +00:00
|
|
|
|
|
|
|
bool HasMessage() const override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the infobar with the reported text.
|
|
|
|
*/
|
|
|
|
void Finalize();
|
2020-12-21 15:17:52 +00:00
|
|
|
|
|
|
|
private:
|
2021-08-16 11:49:22 +00:00
|
|
|
bool m_messageSet;
|
|
|
|
WX_INFOBAR* m_infoBar;
|
|
|
|
std::unique_ptr<wxString> m_message;
|
|
|
|
SEVERITY m_severity;
|
2020-06-03 23:00:40 +00:00
|
|
|
};
|
|
|
|
|
2013-05-26 04:36:44 +00:00
|
|
|
#endif // _REPORTER_H_
|