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  {
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_GENERIC() {}
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:
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  {
201  m_list = 0;
202  }
203 
204 
206  {
207  delete m_list; // I own it, I destroy it.
208  }
209 
210 
218  void SetList( EDA_UNITS_T aUnits, DRC_ITEM_LIST* aList )
219  {
220  delete m_list;
221 
222  m_units = aUnits;
223  m_list = aList;
224  SetItemCount( aList->GetCount() );
225  Refresh();
226  }
227 
228 
233  const DRC_ITEM* GetItem( int aIndex )
234  {
235  if( m_list )
236  {
237  return m_list->GetItem( aIndex );
238  }
239  return NULL;
240  }
241 
242 
249  wxString OnGetItem( size_t n ) const override
250  {
251  if( m_list )
252  {
253  const DRC_ITEM* item = m_list->GetItem( (int) n );
254  if( item )
255  {
256  wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
257 
258  return wxString::Format( wxT( "<font color='%s'>%s</font>" ),
259  color.GetAsString( wxC2S_HTML_SYNTAX ),
260  item->ShowHtml( m_units ) );
261  }
262  }
263  return wxString();
264  }
265 
266 
273  wxString OnGetItemMarkup( size_t n ) const override
274  {
275  return OnGetItem( n );
276  }
277 
278 
284  void DeleteItem( int aIndex )
285  {
286  if( m_list )
287  {
288  int selection = GetSelection();
289 
290  m_list->DeleteItem( aIndex );
291  int count = m_list->GetCount();
292  SetItemCount( count );
293 
294  // if old selection >= new count
295  if( selection >= count )
296  SetSelection( count-1 ); // -1 is "no selection"
297  Refresh();
298  }
299  }
300 
301 
307  {
308  if( m_list )
309  {
311  SetItemCount(0);
312  SetSelection( -1 ); // -1 is no selection
313  Refresh();
314  }
315  }
316 };
317 
318 #endif // _DIALOG_DRCLISTBOX_H_
319 
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:335
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:243
Class 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.
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)
DRC_LIST_GENERIC(DRC_LIST *aList)
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 SetList(EDA_UNITS_T aUnits, DRC_ITEM_LIST *aList)
Function SetList sets the DRC_ITEM_LIST for this listbox.
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.
Class DRC_LIST_MARKERS is an implementation of the interface named DRC_ITEM_LIST which uses a BOARD i...
Class DRC_LIST_GENERIC is an implementation of the interface named DRC_ITEM_LIST which uses a vector ...
const DRC_ITEM * GetItem(int aIndex) override
Function GetItem retrieves a DRC_ITEM by pointer.
std::vector< DRC_ITEM * > DRC_LIST
Definition: drc.h:177
EDA_UNITS_T m_units
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:323
void DeleteAllItems() override
Function DeleteAllItems removes and deletes all the 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:170
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:140
virtual void Delete(BOARD_ITEM *aItem)
Removes an item from the containter and deletes it.
wxString ShowHtml(EDA_UNITS_T aUnits) const
Function ShowHtml translates this object into a fragment of HTML suitable for the wxWidget's wxHtmlLi...
Definition: drc_item.cpp:182
EDA_UNITS_T
Definition: common.h:157
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.