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.

145 lines
5.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 CERN
  5. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  6. * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  7. *
  8. * This program is free software: you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation, either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #pragma once
  22. #include <reporter.h>
  23. #include <vector>
  24. #include "wx_html_report_panel_base.h"
  25. class WX_HTML_REPORT_PANEL;
  26. /**
  27. * A wrapper for reporting to a wx HTML window.
  28. */
  29. class KICOMMON_API WX_HTML_PANEL_REPORTER : public REPORTER
  30. {
  31. public:
  32. WX_HTML_PANEL_REPORTER( WX_HTML_REPORT_PANEL* aPanel ) :
  33. REPORTER(),
  34. m_panel( aPanel )
  35. {}
  36. virtual ~WX_HTML_PANEL_REPORTER() {}
  37. REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
  38. REPORTER& ReportTail( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
  39. REPORTER& ReportHead( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override;
  40. bool HasMessage() const override;
  41. bool HasMessageOfSeverity( int aSeverityMask ) const override;
  42. private:
  43. WX_HTML_REPORT_PANEL* m_panel;
  44. };
  45. /**
  46. * A widget for browsing a rich text error/status report.
  47. *
  48. * Used in numerous dialogs in Eeschema and Pcbnew. Provides error filtering functionality
  49. * and saving report files. The messages are reported through a #REPORTER object
  50. */
  51. class KICOMMON_API WX_HTML_REPORT_PANEL : public WX_HTML_REPORT_PANEL_BASE
  52. {
  53. public:
  54. WX_HTML_REPORT_PANEL( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition,
  55. const wxSize& size = wxSize( 500, 300 ), long style = wxTAB_TRAVERSAL );
  56. ~WX_HTML_REPORT_PANEL();
  57. /// Set the min size of the area which displays html messages.
  58. void MsgPanelSetMinSize( const wxSize& aMinSize );
  59. /// Return the reporter object that reports to this panel.
  60. REPORTER& Reporter();
  61. /**
  62. * Report the string.
  63. *
  64. * @param aText string message to report.
  65. * @param aSeverity string classification level bitfield.
  66. * @param aLocation REPORTER::LOCATION enum for placement of message.
  67. */
  68. void Report( const wxString& aText, SEVERITY aSeverity, REPORTER::LOCATION aLocation = REPORTER::LOC_BODY );
  69. /// Clears the report panel.
  70. void Clear();
  71. /// Return the number of messages matching the given severity mask.
  72. int Count( int severityMask );
  73. /// Set the frame label.
  74. void SetLabel( const wxString& aLabel ) override;
  75. /// Set the lazy update. If this mode is on, messages are stored but the display
  76. /// is not updated (Updating display can be very time consuming if there are many messages)
  77. /// A call to Flush() will be needed after build the report
  78. void SetLazyUpdate( bool aLazyUpdate ) { m_lazyUpdate = aLazyUpdate; }
  79. /// Force updating the HTML page, after the report is built in lazy mode
  80. /// If aSort = true, the body messages will be ordered by severity
  81. void Flush( bool aSort = false );
  82. /// @return the visible severity filter.
  83. /// If the m_showAll option is set, the mask is < 0
  84. int GetVisibleSeverities() const;
  85. /// Set the report full file name to the string.
  86. void SetFileName( const wxString& aReportFileName ) { m_reportFileName = aReportFileName; }
  87. /// @return reference to the current report fill file name string.
  88. wxString& GetFileName( void ) { return m_reportFileName; }
  89. private:
  90. struct REPORT_LINE
  91. {
  92. SEVERITY severity;
  93. wxString message;
  94. };
  95. typedef std::vector<REPORT_LINE> REPORT_LINES;
  96. wxString generateHtml( const REPORT_LINE& aLine );
  97. wxString generatePlainText( const REPORT_LINE& aLine );
  98. void updateBadges();
  99. void scrollToBottom();
  100. void onRightClick( wxMouseEvent& event ) override;
  101. void onMenuEvent( wxMenuEvent& event );
  102. void onCheckBox( wxCommandEvent& event ) override;
  103. void onBtnSaveToFile( wxCommandEvent& event ) override;
  104. void onThemeChanged( wxSysColourChangedEvent &aEvent );
  105. private:
  106. WX_HTML_PANEL_REPORTER m_reporter;
  107. REPORT_LINES m_report; ///< copy of the report, stored for filtering
  108. REPORT_LINES m_reportTail; ///< Lines to print at the end, regardless of sorting
  109. REPORT_LINES m_reportHead; ///< ... and at the beginning, regardless of sorting
  110. bool m_lazyUpdate;
  111. wxString m_reportFileName; ///< defaults to the not very useful /bin/report.txt
  112. };