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 
31 #include <fctsys.h>
32 #include <pcbnew.h>
33 #include <class_drawpanel.h>
34 #include <drc.h>
35 #include <class_marker_pcb.h>
36 #include <class_board.h>
37 
38 #include <dialog_drc_base.h>
39 
40 
41 // outside @end control identifiers since wxFormBuilder knows not DRCLISTBOX
42 #define ID_DRCLISTCTRL 14000
43 #define ID_POPUP_UNCONNECTED_A 14001
44 #define ID_POPUP_UNCONNECTED_B 14002
45 #define ID_POPUP_MARKERS_A 14003
46 #define ID_POPUP_MARKERS_B 14004
47 
48 
56 {
58 
59 public:
60 
61  DRC_LIST_MARKERS( BOARD* aBoard ) :
62  m_board(aBoard)
63  {
64  }
65 
66  /* no destructor since we do not own anything to delete, not even the BOARD.
67  ~DRC_LIST_MARKERS() {}
68  */
69 
70 
71  //-----<Interface DRC_ITEM_LIST>---------------------------------------
72 
73  void DeleteAllItems() override
74  {
75  m_board->DeleteMARKERs();
76  }
77 
78 
79  const DRC_ITEM* GetItem( int aIndex ) override
80  {
81  const MARKER_PCB* marker = m_board->GetMARKER( aIndex );
82  if( marker )
83  return &marker->GetReporter();
84  return NULL;
85  }
86 
87  void DeleteItem( int aIndex ) override
88  {
89  MARKER_PCB* marker = m_board->GetMARKER( aIndex );
90  if( marker )
91  m_board->Delete( marker );
92  }
93 
94 
99  int GetCount() override
100  {
101  return m_board->GetMARKERCount();
102  }
103 
104  //-----</Interface DRC_ITEM_LIST>--------------------------------------
105 
106 };
107 
108 
116 {
118 
119 public:
120 
122  m_vector(aList)
123  {
124  }
125 
126  /* no destructor since we do not own anything to delete, not even the BOARD.
127  ~DRC_LIST_UNCONNECTED() {}
128  */
129 
130 
131  //-----<Interface DRC_ITEM_LIST>---------------------------------------
132 
133  void DeleteAllItems() override
134  {
135  if( m_vector )
136  {
137  for( unsigned i=0; i<m_vector->size(); ++i )
138  delete (*m_vector)[i];
139 
140  m_vector->clear();
141  }
142  }
143 
144 
145  const DRC_ITEM* GetItem( int aIndex ) override
146  {
147  if( m_vector && (unsigned)aIndex < m_vector->size() )
148  {
149  const DRC_ITEM* item = (*m_vector)[aIndex];
150  return item;
151  }
152  return NULL;
153  }
154 
155  void DeleteItem( int aIndex ) override
156  {
157  if( m_vector && (unsigned)aIndex < m_vector->size() )
158  {
159  delete (*m_vector)[aIndex];
160  m_vector->erase( m_vector->begin()+aIndex );
161  }
162  }
163 
164 
169  int GetCount() override
170  {
171  if( m_vector )
172  {
173  return m_vector->size();
174  }
175  return 0;
176  }
177 
178  //-----</Interface DRC_ITEM_LIST>--------------------------------------
179 
180 };
181 
182 
183 
188 class DRCLISTBOX : public wxHtmlListBox
189 {
190 private:
192 
193 public:
194  DRCLISTBOX( wxWindow* parent, wxWindowID id = wxID_ANY,
195  const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
196  long style = 0, const wxString choices[] = NULL, int unused = 0)
197  : wxHtmlListBox( parent, id, pos, size, style )
198  {
199  m_list = 0;
200  }
201 
202 
204  {
205  delete m_list; // I own it, I destroy it.
206  }
207 
208 
216  void SetList( DRC_ITEM_LIST* aList )
217  {
218  delete m_list;
219 
220  m_list = aList;
221  SetItemCount( aList->GetCount() );
222  Refresh();
223  }
224 
225 
230  const DRC_ITEM* GetItem( int aIndex )
231  {
232  if( m_list )
233  {
234  return m_list->GetItem( aIndex );
235  }
236  return NULL;
237  }
238 
239 
246  wxString OnGetItem( size_t n ) const override
247  {
248  if( m_list )
249  {
250  const DRC_ITEM* item = m_list->GetItem( (int) n );
251  if( item )
252  {
253  wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
254 
255  return wxString::Format( wxT( "<font color='%s'>%s</font>" ),
256  color.GetAsString( wxC2S_HTML_SYNTAX ),
257  item->ShowHtml() );
258  }
259  }
260  return wxString();
261  }
262 
263 
270  wxString OnGetItemMarkup( size_t n ) const override
271  {
272  return OnGetItem( n );
273  }
274 
275 
281  void DeleteItem( int aIndex )
282  {
283  if( m_list )
284  {
285  int selection = GetSelection();
286 
287  m_list->DeleteItem( aIndex );
288  int count = m_list->GetCount();
289  SetItemCount( count );
290 
291  // if old selection >= new count
292  if( selection >= count )
293  SetSelection( count-1 ); // -1 is "no selection"
294  Refresh();
295  }
296  }
297 
298 
304  {
305  if( m_list )
306  {
307  m_list->DeleteAllItems();
308  SetItemCount(0);
309  SetSelection( -1 ); // -1 is no selection
310  Refresh();
311  }
312  }
313 };
314 
315 #endif // _DIALOG_DRCLISTBOX_H_
316 
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:324
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. ...
Definition: drc_item.h:45
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.
int color
Definition: DXF_plotter.cpp:62
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 &#39;n&#39;...
wxString OnGetItemMarkup(size_t n) const override
Function OnGetItem returns the html text associated with the given index &#39;n&#39;.
Markers used to show a drc problem on boards.
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 & GetReporter() const
Function GetReporter returns the DRC_ITEM held within this MARKER so that its interface may be used...
Definition: marker_base.h:203
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...
std::vector< DRC_ITEM * > DRC_LIST
Definition: drc.h:151
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
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
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.
size_t i
Definition: json11.cpp:597
Provide an abstract interface of a DRC_ITEM* list manager.
Definition: drc.h:114
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&#39;s wxHtmlLi...
Definition: drc_item.h:157
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:336
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.