You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.0 KiB

  1. /**
  2. * @file reporter.cpp
  3. */
  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. #include <macros.h>
  28. #include <reporter.h>
  29. #include <wx_html_report_panel.h>
  30. REPORTER& REPORTER::Report( const char* aText, REPORTER::SEVERITY aSeverity )
  31. {
  32. Report( FROM_UTF8( aText ) );
  33. return *this;
  34. }
  35. REPORTER& WX_TEXT_CTRL_REPORTER::Report( const wxString& aText, REPORTER::SEVERITY aSeverity )
  36. {
  37. wxCHECK_MSG( m_textCtrl != NULL, *this,
  38. wxT( "No wxTextCtrl object defined in WX_TEXT_CTRL_REPORTER." ) );
  39. m_textCtrl->AppendText( aText );
  40. return *this;
  41. }
  42. bool WX_TEXT_CTRL_REPORTER::HasMessage() const
  43. {
  44. return !m_textCtrl->IsEmpty();
  45. }
  46. REPORTER& WX_STRING_REPORTER::Report( const wxString& aText, REPORTER::SEVERITY aSeverity )
  47. {
  48. wxCHECK_MSG( m_string != NULL, *this,
  49. wxT( "No wxString object defined in WX_STRING_REPORTER." ) );
  50. *m_string << aText;
  51. return *this;
  52. }
  53. bool WX_STRING_REPORTER::HasMessage() const
  54. {
  55. return !m_string->IsEmpty();
  56. }
  57. REPORTER& WX_HTML_PANEL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
  58. {
  59. wxCHECK_MSG( m_panel != NULL, *this,
  60. wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
  61. m_panel->Report( aText, aSeverity );
  62. return *this;
  63. }
  64. REPORTER& WX_HTML_PANEL_REPORTER::ReportTail( const wxString& aText, SEVERITY aSeverity )
  65. {
  66. wxCHECK_MSG( m_panel != NULL, *this,
  67. wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
  68. m_panel->Report( aText, aSeverity, LOC_TAIL );
  69. return *this;
  70. }
  71. REPORTER& WX_HTML_PANEL_REPORTER::ReportHead( const wxString& aText, SEVERITY aSeverity )
  72. {
  73. wxCHECK_MSG( m_panel != NULL, *this,
  74. wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
  75. m_panel->Report( aText, aSeverity, LOC_HEAD );
  76. return *this;
  77. }
  78. bool WX_HTML_PANEL_REPORTER::HasMessage() const
  79. {
  80. return m_panel->Count( REPORTER::RPT_ERROR | REPORTER::RPT_WARNING ) > 0;
  81. }
  82. REPORTER& NULL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
  83. {
  84. return *this;
  85. }
  86. REPORTER& NULL_REPORTER::GetInstance()
  87. {
  88. static REPORTER* s_nullReporter = NULL;
  89. if( !s_nullReporter )
  90. {
  91. s_nullReporter = new NULL_REPORTER();
  92. }
  93. return *s_nullReporter;
  94. }
  95. REPORTER& STDOUT_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
  96. {
  97. switch( aSeverity )
  98. {
  99. case RPT_UNDEFINED: std::cout << "RPT_UNDEFINED: "; break;
  100. case RPT_INFO: std::cout << "RPT_INFO: "; break;
  101. case RPT_WARNING: std::cout << "RPT_WARNING: "; break;
  102. case RPT_ERROR: std::cout << "RPT_ERROR: "; break;
  103. case RPT_ACTION: std::cout << "RPT_ACTION: "; break;
  104. }
  105. std::cout << aText << std::endl;
  106. return *this;
  107. }
  108. REPORTER& STDOUT_REPORTER::GetInstance()
  109. {
  110. static REPORTER* s_stdoutReporter = nullptr;
  111. if( !s_stdoutReporter )
  112. {
  113. s_stdoutReporter = new STDOUT_REPORTER();
  114. }
  115. return *s_stdoutReporter;
  116. }