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-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 
25 
26 #ifndef _DIALOG_DRCLISTBOX_H_
27 #define _DIALOG_DRCLISTBOX_H_
28 
29 #include <wx/htmllbox.h>
30 #include <fctsys.h>
31 #include <pcbnew.h>
32 #include <tools/drc.h>
33 #include <class_marker_pcb.h>
34 #include <class_board.h>
35 #include <dialog_drc_base.h>
36 
37 
45 {
47 
48 public:
49 
50  DRC_LIST_MARKERS( BOARD* aBoard ) :
51  m_board(aBoard)
52  {
53  }
54 
55  /* no destructor since we do not own anything to delete, not even the BOARD.
56  ~DRC_LIST_MARKERS() {}
57  */
58 
59 
60  //-----<Interface DRC_ITEM_LIST>---------------------------------------
61 
62  void DeleteAllItems() override
63  {
65  }
66 
67 
68  const DRC_ITEM* GetItem( int aIndex ) override
69  {
70  const MARKER_PCB* marker = m_board->GetMARKER( aIndex );
71  if( marker )
72  return &marker->GetReporter();
73  return NULL;
74  }
75 
76  void DeleteItem( int aIndex ) override
77  {
78  MARKER_PCB* marker = m_board->GetMARKER( aIndex );
79  if( marker )
80  m_board->Delete( marker );
81  }
82 
83 
88  int GetCount() override
89  {
90  return m_board->GetMARKERCount();
91  }
92 
93  //-----</Interface DRC_ITEM_LIST>--------------------------------------
94 
95 };
96 
97 
105 {
107 
108 public:
109 
111  m_vector(aList)
112  {
113  }
114 
115  /* no destructor since we do not own anything to delete, not even the BOARD.
116  ~DRC_LIST_GENERIC() {}
117  */
118 
119 
120  //-----<Interface DRC_ITEM_LIST>---------------------------------------
121 
122  void DeleteAllItems() override
123  {
124  if( m_vector )
125  {
126  for( unsigned i=0; i<m_vector->size(); ++i )
127  delete (*m_vector)[i];
128 
129  m_vector->clear();
130  }
131  }
132 
133 
134  const DRC_ITEM* GetItem( int aIndex ) override
135  {
136  if( m_vector && (unsigned)aIndex < m_vector->size() )
137  {
138  const DRC_ITEM* item = (*m_vector)[aIndex];
139  return item;
140  }
141  return NULL;
142  }
143 
144  void DeleteItem( int aIndex ) override
145  {
146  if( m_vector && (unsigned)aIndex < m_vector->size() )
147  {
148  delete (*m_vector)[aIndex];
149  m_vector->erase( m_vector->begin()+aIndex );
150  }
151  }
152 
153 
158  int GetCount() override
159  {
160  if( m_vector )
161  {
162  return m_vector->size();
163  }
164  return 0;
165  }
166 
167  //-----</Interface DRC_ITEM_LIST>--------------------------------------
168 
169 };
170 
171 
172 
177 class DRCLISTBOX : public wxHtmlListBox
178 {
179 private:
182 
183 public:
184  DRCLISTBOX( wxWindow* parent, wxWindowID id = wxID_ANY,
185  const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
186  long style = 0, const wxString choices[] = NULL, int unused = 0)
187  : wxHtmlListBox( parent, id, pos, size, style )
188  {
190  m_list = 0;
191  }
192 
193 
195  {
196  delete m_list; // I own it, I destroy it.
197  }
198 
199 
207  void SetList( EDA_UNITS aUnits, DRC_ITEM_LIST* aList )
208  {
209  delete m_list;
210 
211  m_units = aUnits;
212  m_list = aList;
213  SetItemCount( aList->GetCount() );
214  Refresh();
215  }
216 
217 
222  const DRC_ITEM* GetItem( int aIndex )
223  {
224  if( m_list )
225  {
226  return m_list->GetItem( aIndex );
227  }
228  return NULL;
229  }
230 
231 
238  wxString OnGetItem( size_t n ) const override
239  {
240  if( m_list )
241  {
242  const DRC_ITEM* item = m_list->GetItem( (int) n );
243  if( item )
244  {
245  wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
246 
247  return wxString::Format( wxT( "<font color='%s'>%s</font>" ),
248  color.GetAsString( wxC2S_HTML_SYNTAX ),
249  item->ShowHtml( m_units ) );
250  }
251  }
252  return wxString();
253  }
254 
255 
262  wxString OnGetItemMarkup( size_t n ) const override
263  {
264  return OnGetItem( n );
265  }
266 
267 
273  void DeleteItem( int aIndex )
274  {
275  if( m_list )
276  {
277  int selection = GetSelection();
278 
279  m_list->DeleteItem( aIndex );
280  int count = m_list->GetCount();
281  SetItemCount( count );
282 
283  // if old selection >= new count
284  if( selection >= count )
285  SetSelection( count-1 ); // -1 is "no selection"
286  Refresh();
287  }
288  }
289 
290 
296  {
297  if( m_list )
298  {
300  SetItemCount(0);
301  SetSelection( -1 ); // -1 is no selection
302  Refresh();
303  }
304  }
305 };
306 
307 #endif // _DIALOG_DRCLISTBOX_H_
308 
EDA_UNITS
Definition: common.h:72
void DeleteItem(int aIndex)
Function DeleteElement will delete one of the items in the list.
const DRC_ITEM * GetItem(int aIndex) override
Function GetItem retrieves a DRC_ITEM by pointer.
int GetMARKERCount() const
Function GetMARKERCount.
Definition: class_board.h:343
const DRC_ITEM & GetReporter() const
Function GetReporter returns the DRC_ITEM held within this MARKER so that its interface may be used.
Definition: marker_base.h:241
DRC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item.
Definition: drc_item.h:48
virtual const DRC_ITEM * GetItem(int aIndex)=0
Function GetItem retrieves a DRC_ITEM by pointer.
int color
Definition: DXF_plotter.cpp:61
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)
DRC_LIST_GENERIC(DRC_LIST *aList)
void SetList(EDA_UNITS aUnits, DRC_ITEM_LIST *aList)
Function SetList sets the DRC_ITEM_LIST for this listbox.
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.
#define NULL
int GetCount() override
Function GetCount returns the number of items in the list.
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void DeleteMARKERs()
Function DeleteMARKERs deletes ALL MARKERS from the board.
void DeleteAllItems()
Function DeleteAllItems deletes all items in the list.
const DRC_ITEM * GetItem(int aIndex)
Function GetItem returns a requested DRC_ITEM* or NULL.
DRC_LIST_MARKERS is an implementation of the interface named DRC_ITEM_LIST which uses a BOARD instanc...
DRC_LIST_GENERIC is an implementation of the interface named DRC_ITEM_LIST which uses a vector of poi...
const DRC_ITEM * GetItem(int aIndex) override
Function GetItem retrieves a DRC_ITEM by pointer.
std::vector< DRC_ITEM * > DRC_LIST
Definition: drc.h:175
wxString ShowHtml(EDA_UNITS aUnits) const
Function ShowHtml translates this object into a fragment of HTML suitable for the wxWidget's wxHtmlLi...
void DeleteItem(int aIndex) override
Function DeleteAllItems removes and deletes desired item from the list.
MARKER_PCB * GetMARKER(int index) const
Function GetMARKER returns the MARKER at a given index.
Definition: class_board.h:331
void DeleteAllItems() override
Function DeleteAllItems removes and deletes all the items in the list.
DRCLISTBOX is used to display a DRC_ITEM_LIST.
DRC_ITEM_LIST * m_list
wxHtmlListBox does not own the list, I do
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:160
EDA_UNITS m_units
virtual void DeleteAllItems()=0
Function DeleteAllItems removes and deletes all the items in the list.
Provide an abstract interface of a DRC_ITEM* list manager.
Definition: drc.h:138
virtual void Delete(BOARD_ITEM *aItem)
Removes an item from the container and deletes it.
void DeleteItem(int aIndex) override
Function DeleteAllItems removes and deletes desired item from the list.
virtual int GetCount()=0
Function GetCount returns the number of items in the list.
int GetCount() override
Function GetCount returns the number of items in the list.