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.

316 lines
7.7 KiB

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2009-2016 Dick Hollenbeck, dick@softplc.com
  5. * Copyright (C) 2004-2018 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef _DIALOG_DRCLISTBOX_H_
  25. #define _DIALOG_DRCLISTBOX_H_
  26. #include <wx/htmllbox.h>
  27. #include <fctsys.h>
  28. #include <pcbnew.h>
  29. #include <class_drawpanel.h>
  30. #include <drc.h>
  31. #include <class_marker_pcb.h>
  32. #include <class_board.h>
  33. #include <dialog_drc_base.h>
  34. // outside @end control identifiers since wxFormBuilder knows not DRCLISTBOX
  35. #define ID_DRCLISTCTRL 14000
  36. #define ID_POPUP_UNCONNECTED_A 14001
  37. #define ID_POPUP_UNCONNECTED_B 14002
  38. #define ID_POPUP_MARKERS_A 14003
  39. #define ID_POPUP_MARKERS_B 14004
  40. /**
  41. * Class DRC_LIST_MARKERS
  42. * is an implementation of the interface named DRC_ITEM_LIST which uses
  43. * a BOARD instance to fulfill the interface. No ownership is taken of the
  44. * BOARD.
  45. */
  46. class DRC_LIST_MARKERS : public DRC_ITEM_LIST
  47. {
  48. BOARD* m_board;
  49. public:
  50. DRC_LIST_MARKERS( BOARD* aBoard ) :
  51. m_board(aBoard)
  52. {
  53. }
  54. /* no destructor since we do not own anything to delete, not even the BOARD.
  55. ~DRC_LIST_MARKERS() {}
  56. */
  57. //-----<Interface DRC_ITEM_LIST>---------------------------------------
  58. void DeleteAllItems() override
  59. {
  60. m_board->DeleteMARKERs();
  61. }
  62. const DRC_ITEM* GetItem( int aIndex ) override
  63. {
  64. const MARKER_PCB* marker = m_board->GetMARKER( aIndex );
  65. if( marker )
  66. return &marker->GetReporter();
  67. return NULL;
  68. }
  69. void DeleteItem( int aIndex ) override
  70. {
  71. MARKER_PCB* marker = m_board->GetMARKER( aIndex );
  72. if( marker )
  73. m_board->Delete( marker );
  74. }
  75. /**
  76. * Function GetCount
  77. * returns the number of items in the list.
  78. */
  79. int GetCount() override
  80. {
  81. return m_board->GetMARKERCount();
  82. }
  83. //-----</Interface DRC_ITEM_LIST>--------------------------------------
  84. };
  85. /**
  86. * Class DRC_LIST_UNCONNECTED
  87. * is an implementation of the interface named DRC_ITEM_LIST which uses
  88. * a vector of pointers to DRC_ITEMs to fulfill the interface. No ownership is taken of the
  89. * vector, which will reside in class DRC
  90. */
  91. class DRC_LIST_UNCONNECTED : public DRC_ITEM_LIST
  92. {
  93. DRC_LIST* m_vector;
  94. public:
  95. DRC_LIST_UNCONNECTED( DRC_LIST* aList ) :
  96. m_vector(aList)
  97. {
  98. }
  99. /* no destructor since we do not own anything to delete, not even the BOARD.
  100. ~DRC_LIST_UNCONNECTED() {}
  101. */
  102. //-----<Interface DRC_ITEM_LIST>---------------------------------------
  103. void DeleteAllItems() override
  104. {
  105. if( m_vector )
  106. {
  107. for( unsigned i=0; i<m_vector->size(); ++i )
  108. delete (*m_vector)[i];
  109. m_vector->clear();
  110. }
  111. }
  112. const DRC_ITEM* GetItem( int aIndex ) override
  113. {
  114. if( m_vector && (unsigned)aIndex < m_vector->size() )
  115. {
  116. const DRC_ITEM* item = (*m_vector)[aIndex];
  117. return item;
  118. }
  119. return NULL;
  120. }
  121. void DeleteItem( int aIndex ) override
  122. {
  123. if( m_vector && (unsigned)aIndex < m_vector->size() )
  124. {
  125. delete (*m_vector)[aIndex];
  126. m_vector->erase( m_vector->begin()+aIndex );
  127. }
  128. }
  129. /**
  130. * Function GetCount
  131. * returns the number of items in the list.
  132. */
  133. int GetCount() override
  134. {
  135. if( m_vector )
  136. {
  137. return m_vector->size();
  138. }
  139. return 0;
  140. }
  141. //-----</Interface DRC_ITEM_LIST>--------------------------------------
  142. };
  143. /**
  144. * Class DRCLISTBOX
  145. * is used to display a DRC_ITEM_LIST.
  146. */
  147. class DRCLISTBOX : public wxHtmlListBox
  148. {
  149. private:
  150. DRC_ITEM_LIST* m_list; ///< wxHtmlListBox does not own the list, I do
  151. public:
  152. DRCLISTBOX( wxWindow* parent, wxWindowID id = wxID_ANY,
  153. const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
  154. long style = 0, const wxString choices[] = NULL, int unused = 0)
  155. : wxHtmlListBox( parent, id, pos, size, style )
  156. {
  157. m_list = 0;
  158. }
  159. ~DRCLISTBOX()
  160. {
  161. delete m_list; // I own it, I destroy it.
  162. }
  163. /**
  164. * Function SetList
  165. * sets the DRC_ITEM_LIST for this listbox. Ownership of the DRC_ITEM_LIST is
  166. * transfered to this DRCLISTBOX.
  167. * @param aList The DRC_ITEM_LIST* containing the DRC_ITEMs which will be
  168. * displayed in the wxHtmlListBox
  169. */
  170. void SetList( DRC_ITEM_LIST* aList )
  171. {
  172. delete m_list;
  173. m_list = aList;
  174. SetItemCount( aList->GetCount() );
  175. Refresh();
  176. }
  177. /**
  178. * Function GetItem
  179. * returns a requested DRC_ITEM* or NULL.
  180. */
  181. const DRC_ITEM* GetItem( int aIndex )
  182. {
  183. if( m_list )
  184. {
  185. return m_list->GetItem( aIndex );
  186. }
  187. return NULL;
  188. }
  189. /**
  190. * Function OnGetItem
  191. * returns the html text associated with the DRC_ITEM given by index 'n'.
  192. * @param n An index into the list.
  193. * @return wxString - the simple html text to show in the listbox.
  194. */
  195. wxString OnGetItem( size_t n ) const override
  196. {
  197. if( m_list )
  198. {
  199. const DRC_ITEM* item = m_list->GetItem( (int) n );
  200. if( item )
  201. {
  202. wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
  203. return wxString::Format( wxT( "<font color='%s'>%s</font>" ),
  204. color.GetAsString( wxC2S_HTML_SYNTAX ),
  205. item->ShowHtml() );
  206. }
  207. }
  208. return wxString();
  209. }
  210. /**
  211. * Function OnGetItem
  212. * returns the html text associated with the given index 'n'.
  213. * @param n An index into the list.
  214. * @return wxString - the simple html text to show in the listbox.
  215. */
  216. wxString OnGetItemMarkup( size_t n ) const override
  217. {
  218. return OnGetItem( n );
  219. }
  220. /**
  221. * Function DeleteElement
  222. * will delete one of the items in the list.
  223. * @param aIndex The index into the list to delete.
  224. */
  225. void DeleteItem( int aIndex )
  226. {
  227. if( m_list )
  228. {
  229. int selection = GetSelection();
  230. m_list->DeleteItem( aIndex );
  231. int count = m_list->GetCount();
  232. SetItemCount( count );
  233. // if old selection >= new count
  234. if( selection >= count )
  235. SetSelection( count-1 ); // -1 is "no selection"
  236. Refresh();
  237. }
  238. }
  239. /**
  240. * Function DeleteAllItems
  241. * deletes all items in the list.
  242. */
  243. void DeleteAllItems()
  244. {
  245. if( m_list )
  246. {
  247. m_list->DeleteAllItems();
  248. SetItemCount(0);
  249. SetSelection( -1 ); // -1 is no selection
  250. Refresh();
  251. }
  252. }
  253. };
  254. #endif // _DIALOG_DRCLISTBOX_H_