KiCad PCB EDA Suite
dialog_drclistbox.h
Go to the documentation of this file.
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-2012 KiCad Developers, see change_log.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 
25 
26 #ifndef _DIALOG_DRCLISTBOX_H_
27 #define _DIALOG_DRCLISTBOX_H_
28 
29 #include <wx/htmllbox.h>
30 
31 #include <fctsys.h>
32 #include <pcbnew.h>
33 #include <class_drawpanel.h>
34 #include <wxstruct.h>
35 #include <drc_stuff.h>
36 #include <class_marker_pcb.h>
37 #include <class_board.h>
38 
39 #include <dialog_drc_base.h>
40 
41 
42 // outside @end control identifiers since wxFormBuilder knows not DRCLISTBOX
43 #define ID_DRCLISTCTRL 14000
44 #define ID_POPUP_UNCONNECTED_A 14001
45 #define ID_POPUP_UNCONNECTED_B 14002
46 #define ID_POPUP_MARKERS_A 14003
47 #define ID_POPUP_MARKERS_B 14004
48 
49 
57 {
59 
60 public:
61 
62  DRC_LIST_MARKERS( BOARD* aBoard ) :
63  m_board(aBoard)
64  {
65  }
66 
67  /* no destructor since we do not own anything to delete, not even the BOARD.
68  ~DRC_LIST_MARKERS() {}
69  */
70 
71 
72  //-----<Interface DRC_ITEM_LIST>---------------------------------------
73 
74  void DeleteAllItems() override
75  {
76  m_board->DeleteMARKERs();
77  }
78 
79 
80  const DRC_ITEM* GetItem( int aIndex ) override
81  {
82  const MARKER_PCB* marker = m_board->GetMARKER( aIndex );
83  if( marker )
84  return &marker->GetReporter();
85  return NULL;
86  }
87 
88  void DeleteItem( int aIndex ) override
89  {
90  MARKER_PCB* marker = m_board->GetMARKER( aIndex );
91  if( marker )
92  m_board->Delete( marker );
93  }
94 
95 
100  int GetCount() override
101  {
102  return m_board->GetMARKERCount();
103  }
104 
105  //-----</Interface DRC_ITEM_LIST>--------------------------------------
106 
107 };
108 
109 
117 {
119 
120 public:
121 
123  m_vector(aList)
124  {
125  }
126 
127  /* no destructor since we do not own anything to delete, not even the BOARD.
128  ~DRC_LIST_UNCONNECTED() {}
129  */
130 
131 
132  //-----<Interface DRC_ITEM_LIST>---------------------------------------
133 
134  void DeleteAllItems() override
135  {
136  if( m_vector )
137  {
138  for( unsigned i=0; i<m_vector->size(); ++i )
139  delete (*m_vector)[i];
140 
141  m_vector->clear();
142  }
143  }
144 
145 
146  const DRC_ITEM* GetItem( int aIndex ) override
147  {
148  if( m_vector && (unsigned)aIndex < m_vector->size() )
149  {
150  const DRC_ITEM* item = (*m_vector)[aIndex];
151  return item;
152  }
153  return NULL;
154  }
155 
156  void DeleteItem( int aIndex ) override
157  {
158  if( m_vector && (unsigned)aIndex < m_vector->size() )
159  {
160  delete (*m_vector)[aIndex];
161  m_vector->erase( m_vector->begin()+aIndex );
162  }
163  }
164 
165 
170  int GetCount() override
171  {
172  if( m_vector )
173  {
174  return m_vector->size();
175  }
176  return 0;
177  }
178 
179  //-----</Interface DRC_ITEM_LIST>--------------------------------------
180 
181 };
182 
183 
184 
189 class DRCLISTBOX : public wxHtmlListBox
190 {
191 private:
193 
194 public:
195  DRCLISTBOX( wxWindow* parent, wxWindowID id = wxID_ANY,
196  const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
197  long style = 0, const wxString choices[] = NULL, int unused = 0)
198  : wxHtmlListBox( parent, id, pos, size, style )
199  {
200  m_list = 0;
201  }
202 
203 
205  {
206  delete m_list; // I own it, I destroy it.
207  }
208 
209 
217  void SetList( DRC_ITEM_LIST* aList )
218  {
219  delete m_list;
220 
221  m_list = aList;
222  SetItemCount( aList->GetCount() );
223  Refresh();
224  }
225 
226 
231  const DRC_ITEM* GetItem( int aIndex )
232  {
233  if( m_list )
234  {
235  return m_list->GetItem( aIndex );
236  }
237  return NULL;
238  }
239 
240 
247  wxString OnGetItem( size_t n ) const override
248  {
249  if( m_list )
250  {
251  const DRC_ITEM* item = m_list->GetItem( (int) n );
252  if( item )
253  return item->ShowHtml();
254  }
255  return wxString();
256  }
257 
258 
265  wxString OnGetItemMarkup( size_t n ) const override
266  {
267  return OnGetItem( n );
268  }
269 
270 
276  void DeleteItem( int aIndex )
277  {
278  if( m_list )
279  {
280  int selection = GetSelection();
281 
282  m_list->DeleteItem( aIndex );
283  int count = m_list->GetCount();
284  SetItemCount( count );
285 
286  // if old selection >= new count
287  if( selection >= count )
288  SetSelection( count-1 ); // -1 is "no selection"
289  Refresh();
290  }
291  }
292 
293 
299  {
300  if( m_list )
301  {
302  m_list->DeleteAllItems();
303  SetItemCount(0);
304  SetSelection( -1 ); // -1 is no selection
305  Refresh();
306  }
307  }
308 };
309 
310 #endif // _DIALOG_DRCLISTBOX_H_
311 
void DeleteItem(int aIndex)
Function DeleteElement will delete one of the items in the list.
MARKER_PCB * GetMARKER(int index) const
Function GetMARKER returns the MARKER at a given index.
Definition: class_board.h:313
const DRC_ITEM * GetItem(int aIndex) override
Function GetItem retrieves a DRC_ITEM by pointer.
Class DRC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item. ...
virtual const DRC_ITEM * GetItem(int aIndex)=0
Function GetItem retrieves a DRC_ITEM by pointer.
void SetList(DRC_ITEM_LIST *aList)
Function SetList sets the DRC_ITEM_LIST for this listbox.
Class BOARD to handle a board.
DRC_LIST_MARKERS(BOARD *aBoard)
DRCLISTBOX(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString choices[]=NULL, int unused=0)
void DeleteAllItems() override
Function DeleteAllItems removes and deletes all the items in the list.
void DeleteAllItems() override
Function DeleteAllItems removes and deletes all the items in the list.
virtual void DeleteItem(int aIndex)=0
Function DeleteAllItems removes and deletes desired item from the list.
wxString OnGetItem(size_t n) const override
Function OnGetItem returns the html text associated with the DRC_ITEM given by index 'n'...
wxString OnGetItemMarkup(size_t n) const override
Function OnGetItem returns the html text associated with the given index 'n'.
Markers used to show a drc problem on boards.
void Refresh()
void DeleteMARKERs()
Function DeleteMARKERs deletes ALL MARKERS from the board.
void DeleteAllItems()
Function DeleteAllItems deletes all items in the list.
const DRC_ITEM & GetReporter() const
Function GetReporter returns the DRC_ITEM held within this MARKER so that its interface may be used...
Base window classes and related definitions.
const DRC_ITEM * GetItem(int aIndex)
Function GetItem returns a requested DRC_ITEM* or NULL.
Class DRC_LIST_MARKERS is an implementation of the interface named DRC_ITEM_LIST which uses a BOARD i...
void DeleteItem(int aIndex) override
Function DeleteAllItems removes and deletes desired item from the list.
void DeleteItem(int aIndex) override
Function DeleteAllItems removes and deletes desired item from the list.
int GetCount() override
Function GetCount returns the number of items in the list.
Class DRCLISTBOX is used to display a DRC_ITEM_LIST.
DRC_ITEM_LIST * m_list
wxHtmlListBox does not own the list, I do
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
virtual void DeleteAllItems()=0
Function DeleteAllItems removes and deletes all the items in the list.
Class DRC_ITEM_LIST provides an abstract interface of a DRC_ITEM* list manager.
Definition: drc_stuff.h:109
virtual void Delete(BOARD_ITEM *aItem)
Removes an item from the containter and deletes it.
Class DRC_LIST_UNCONNECTED is an implementation of the interface named DRC_ITEM_LIST which uses a vec...
wxString ShowHtml() const
Function ShowHtml translates this object into a fragment of HTML suitable for the wxWidget's wxHtmlLi...
virtual int GetCount()=0
Function GetCount returns the number of items in the list.
DRC_LIST_UNCONNECTED(DRC_LIST *aList)
int GetMARKERCount() const
Function GetMARKERCount.
Definition: class_board.h:325
const DRC_ITEM * GetItem(int aIndex) override
Function GetItem retrieves a DRC_ITEM by pointer.
int GetCount() override
Function GetCount returns the number of items in the list.
std::vector< DRC_ITEM * > DRC_LIST
Definition: drc_stuff.h:146