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.

125 lines
3.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef DIALOG_ERC_LISTBOX_H
  24. #define DIALOG_ERC_LISTBOX_H
  25. #include <vector>
  26. #include <fctsys.h>
  27. #include <sch_draw_panel.h>
  28. #include <sch_marker.h>
  29. #include <wx/html/htmlwin.h>
  30. /**
  31. * Class ERC_HTML_LISTFRAME
  32. * is used to display a DRC_ITEM_LIST.
  33. */
  34. class ERC_HTML_LISTFRAME : public wxHtmlWindow
  35. {
  36. private:
  37. std::vector<SCH_MARKER*> m_MarkerListReferences; // The pointers to markers shown in list
  38. public:
  39. ERC_HTML_LISTFRAME( wxWindow* parent, wxWindowID id = wxID_ANY,
  40. const wxPoint& pos = wxDefaultPosition,
  41. const wxSize& size = wxDefaultSize,
  42. long style = 0 ) :
  43. wxHtmlWindow( parent, id, pos, size, style | wxHW_NO_SELECTION )
  44. {
  45. }
  46. ~ERC_HTML_LISTFRAME()
  47. {
  48. }
  49. /**
  50. * Function AppendToList
  51. * @param aMarker is the SCH_MARKER* to add to the current list which will be
  52. * later displayed in the wxHtmlWindow
  53. */
  54. void AppendToList( SCH_MARKER* aMarker )
  55. {
  56. m_MarkerListReferences.push_back( aMarker );
  57. }
  58. /**
  59. * Function DisplayList();
  60. * Build the Html marker list and show it
  61. */
  62. void DisplayList( EDA_UNITS_T aUnits )
  63. {
  64. wxString htmlpage;
  65. wxColour bgcolor = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW );
  66. wxColour fgcolor = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
  67. // for each marker, build a link like:
  68. // <A HREF="marker_index">text to click</A>
  69. // The "text to click" is the error name (first line of the full error text).
  70. wxString marker_text;
  71. wxString href;
  72. for( unsigned ii = 0; ii < m_MarkerListReferences.size(); ii++ )
  73. {
  74. href.Printf( wxT( "href='%d'" ), ii );
  75. marker_text = m_MarkerListReferences[ii]->GetReporter().ShowHtml( aUnits );
  76. marker_text.Replace( wxT( "href=''"), href );
  77. htmlpage += marker_text;
  78. }
  79. SetPage( wxString::Format( wxT( "<html><body bgcolor='%s' text='%s'>%s</body></html>" ),
  80. bgcolor.GetAsString( wxC2S_HTML_SYNTAX ),
  81. fgcolor.GetAsString( wxC2S_HTML_SYNTAX ),
  82. htmlpage ) );
  83. }
  84. /**
  85. * Function GetItem
  86. * returns a requested DRC_ITEM* or NULL.
  87. */
  88. const SCH_MARKER* GetItem( unsigned aIndex )
  89. {
  90. if( m_MarkerListReferences.size() > aIndex )
  91. {
  92. return m_MarkerListReferences[ aIndex ];
  93. }
  94. return NULL;
  95. }
  96. /**
  97. * Function ClearList
  98. * deletes all items shown in the list.
  99. * Does not erase markers in schematic
  100. */
  101. void ClearList()
  102. {
  103. m_MarkerListReferences.clear();
  104. SetPage( wxEmptyString );
  105. }
  106. };
  107. #endif
  108. // DIALOG_ERC_LISTBOX_H