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.

209 lines
5.8 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 <widgets/infobar.h>
  30. #include <wx_html_report_panel.h>
  31. REPORTER& REPORTER::Report( const char* aText, SEVERITY aSeverity )
  32. {
  33. Report( FROM_UTF8( aText ) );
  34. return *this;
  35. }
  36. REPORTER& WX_TEXT_CTRL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
  37. {
  38. wxCHECK_MSG( m_textCtrl != NULL, *this,
  39. wxT( "No wxTextCtrl object defined in WX_TEXT_CTRL_REPORTER." ) );
  40. m_textCtrl->AppendText( aText );
  41. return *this;
  42. }
  43. bool WX_TEXT_CTRL_REPORTER::HasMessage() const
  44. {
  45. return !m_textCtrl->IsEmpty();
  46. }
  47. REPORTER& WX_STRING_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
  48. {
  49. wxCHECK_MSG( m_string != NULL, *this,
  50. wxT( "No wxString object defined in WX_STRING_REPORTER." ) );
  51. *m_string << aText;
  52. return *this;
  53. }
  54. bool WX_STRING_REPORTER::HasMessage() const
  55. {
  56. return !m_string->IsEmpty();
  57. }
  58. REPORTER& WX_HTML_PANEL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
  59. {
  60. wxCHECK_MSG( m_panel != NULL, *this,
  61. wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
  62. m_panel->Report( aText, aSeverity );
  63. return *this;
  64. }
  65. REPORTER& WX_HTML_PANEL_REPORTER::ReportTail( const wxString& aText, SEVERITY aSeverity )
  66. {
  67. wxCHECK_MSG( m_panel != NULL, *this,
  68. wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
  69. m_panel->Report( aText, aSeverity, LOC_TAIL );
  70. return *this;
  71. }
  72. REPORTER& WX_HTML_PANEL_REPORTER::ReportHead( const wxString& aText, SEVERITY aSeverity )
  73. {
  74. wxCHECK_MSG( m_panel != NULL, *this,
  75. wxT( "No WX_HTML_REPORT_PANEL object defined in WX_HTML_PANEL_REPORTER." ) );
  76. m_panel->Report( aText, aSeverity, LOC_HEAD );
  77. return *this;
  78. }
  79. bool WX_HTML_PANEL_REPORTER::HasMessage() const
  80. {
  81. return m_panel->Count( RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING ) > 0;
  82. }
  83. REPORTER& NULL_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
  84. {
  85. return *this;
  86. }
  87. REPORTER& NULL_REPORTER::GetInstance()
  88. {
  89. static REPORTER* s_nullReporter = NULL;
  90. if( !s_nullReporter )
  91. s_nullReporter = new NULL_REPORTER();
  92. return *s_nullReporter;
  93. }
  94. REPORTER& STDOUT_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
  95. {
  96. switch( aSeverity )
  97. {
  98. case RPT_SEVERITY_UNDEFINED: std::cout << "SEVERITY_UNDEFINED: "; break;
  99. case RPT_SEVERITY_INFO: std::cout << "SEVERITY_INFO: "; break;
  100. case RPT_SEVERITY_WARNING: std::cout << "SEVERITY_WARNING: "; break;
  101. case RPT_SEVERITY_ERROR: std::cout << "SEVERITY_ERROR: "; break;
  102. case RPT_SEVERITY_ACTION: std::cout << "SEVERITY_ACTION: "; break;
  103. case RPT_SEVERITY_EXCLUSION:
  104. case RPT_SEVERITY_IGNORE: break;
  105. }
  106. std::cout << aText << std::endl;
  107. return *this;
  108. }
  109. REPORTER& STDOUT_REPORTER::GetInstance()
  110. {
  111. static REPORTER* s_stdoutReporter = nullptr;
  112. if( !s_stdoutReporter )
  113. s_stdoutReporter = new STDOUT_REPORTER();
  114. return *s_stdoutReporter;
  115. }
  116. REPORTER& STATUSBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
  117. {
  118. if( m_statusBar )
  119. m_statusBar->SetStatusText( aText, m_position );
  120. return *this;
  121. }
  122. bool STATUSBAR_REPORTER::HasMessage() const
  123. {
  124. if( m_statusBar )
  125. return m_statusBar->GetStatusText().IsEmpty();
  126. return false;
  127. }
  128. REPORTER& INFOBAR_REPORTER::Report( const wxString& aText, SEVERITY aSeverity )
  129. {
  130. m_message = aText;
  131. m_severity = aSeverity;
  132. m_messageSet = true;
  133. return *this;
  134. }
  135. bool INFOBAR_REPORTER::HasMessage() const
  136. {
  137. return !m_message.IsEmpty();
  138. }
  139. void INFOBAR_REPORTER::Finalize()
  140. {
  141. // Don't do anything if no message was ever given
  142. if( !m_infoBar || !m_messageSet )
  143. return;
  144. // Short circuit if the message is empty and it is already hidden
  145. if( !HasMessage() && !m_infoBar->IsShown() )
  146. return;
  147. int icon = wxICON_NONE;
  148. switch( m_severity )
  149. {
  150. case RPT_SEVERITY_UNDEFINED: icon = wxICON_INFORMATION; break;
  151. case RPT_SEVERITY_INFO: icon = wxICON_INFORMATION; break;
  152. case RPT_SEVERITY_EXCLUSION: icon = wxICON_WARNING; break;
  153. case RPT_SEVERITY_ACTION: icon = wxICON_WARNING; break;
  154. case RPT_SEVERITY_WARNING: icon = wxICON_WARNING; break;
  155. case RPT_SEVERITY_ERROR: icon = wxICON_ERROR; break;
  156. case RPT_SEVERITY_IGNORE: icon = wxICON_INFORMATION; break;
  157. }
  158. if( m_message.EndsWith( "\n" ) )
  159. m_message = m_message.Left( m_message.Length() - 1 );
  160. if( HasMessage() )
  161. m_infoBar->QueueShowMessage( m_message, icon );
  162. else
  163. m_infoBar->QueueDismiss();
  164. }