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:
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( EDA_UNITS_T aUnits, DRC_ITEM_LIST* aList )
218  {
219  delete m_list;
220 
221  m_units = aUnits;
222  m_list = aList;
223  SetItemCount( aList->GetCount() );
224  Refresh();
225  }
226 
227 
232  const DRC_ITEM* GetItem( int aIndex )
233  {
234  if( m_list )
235  {
236  return m_list->GetItem( aIndex );
237  }
238  return NULL;
239  }
240 
241 
248  wxString OnGetItem( size_t n ) const override
249  {
250  if( m_list )
251  {
252  const DRC_ITEM* item = m_list->GetItem( (int) n );
253  if( item )
254  {
255  wxColour color = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
256 
257  return wxString::Format( wxT( "<font color='%s'>%s</font>" ),
258  color.GetAsString( wxC2S_HTML_SYNTAX ),
259  item->ShowHtml( m_units ) );
260  }
261  }
262  return wxString();
263  }
264 
265 
272  wxString OnGetItemMarkup( size_t n ) const override
273  {
274  return OnGetItem( n );
275  }
276 
277 
283  void DeleteItem( int aIndex )
284  {
285  if( m_list )
286  {
287  int selection = GetSelection();
288 
289  m_list->DeleteItem( aIndex );
290  int count = m_list->GetCount();
291  SetItemCount( count );
292 
293  // if old selection >= new count
294  if( selection >= count )
295  SetSelection( count-1 ); // -1 is "no selection"
296  Refresh();
297  }
298  }
299 
300 
306  {
307  if( m_list )
308  {
309  m_list->DeleteAllItems();
310  SetItemCount(0);
311  SetSelection( -1 ); // -1 is no selection
312  Refresh();
313  }
314  }
315 };
316 
317 #endif // _DIALOG_DRCLISTBOX_H_
318 
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:328
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: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)
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 SetList(EDA_UNITS_T aUnits, DRC_ITEM_LIST *aList)
Function SetList sets the DRC_ITEM_LIST for this listbox.
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:220
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:163
EDA_UNITS_T m_units
wxString ShowHtml(EDA_UNITS_T aUnits) const
Function ShowHtml translates this object into a fragment of HTML suitable for the wxWidget&#39;s wxHtmlLi...
Definition: drc_item.cpp:160
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:171
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:126
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...
EDA_UNITS_T
Definition: common.h:159
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:340
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.