KiCad PCB EDA Suite
drc_item.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) 2007 Dick Hollenbeck, dick@softplc.com
5  * Copyright (C) 2018-2020 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 #ifndef DRC_ITEM_H
26 #define DRC_ITEM_H
27 
28 #include <macros.h>
29 #include <base_struct.h>
30 #include <rc_item.h>
31 #include <marker_base.h>
32 #include <class_board.h>
33 #include <class_marker_pcb.h>
34 #include <pcb_base_frame.h>
35 
36 
37 class DRC_ITEM : public RC_ITEM
38 {
39 public:
44  wxString GetErrorText() const override;
45 
51  wxString ShowHtml( EDA_UNITS aUnits ) const;
52 };
53 
54 
61 {
62 private:
64 
66  std::vector<MARKER_PCB*> m_filteredMarkers;
67 
68 public:
70  m_board( aBoard ),
71  m_severities( 0 )
72  {
73  }
74 
75  void SetSeverities( int aSeverities ) override
76  {
77  m_severities = aSeverities;
78 
80 
81  m_filteredMarkers.clear();
82 
83  for( MARKER_PCB* marker : m_board->Markers() )
84  {
85  int markerSeverity;
86 
87  if( marker->IsExcluded() )
88  markerSeverity = RPT_SEVERITY_EXCLUSION;
89  else
90  markerSeverity = bds.GetSeverity( marker->GetRCItem()->GetErrorCode() );
91 
92  if( markerSeverity & m_severities )
93  m_filteredMarkers.push_back( marker );
94  }
95  }
96 
97  int GetCount( int aSeverity = -1 ) override
98  {
99  if( aSeverity < 0 )
100  return m_filteredMarkers.size();
101 
103 
104  int count = 0;
105 
106  for( MARKER_PCB* marker : m_board->Markers() )
107  {
108  int markerSeverity;
109 
110  if( marker->IsExcluded() )
111  markerSeverity = RPT_SEVERITY_EXCLUSION;
112  else
113  markerSeverity = bds.GetSeverity( marker->GetRCItem()->GetErrorCode() );
114 
115  if( markerSeverity == aSeverity )
116  count++;
117  }
118 
119  return count;
120  }
121 
122  DRC_ITEM* GetItem( int aIndex ) override
123  {
124  MARKER_PCB* marker = m_filteredMarkers[ aIndex ];
125 
126  return marker ? static_cast<DRC_ITEM*>( marker->GetRCItem() ) : nullptr;
127  }
128 
129  void DeleteItem( int aIndex, bool aDeep ) override
130  {
131  MARKER_PCB* marker = m_filteredMarkers[ aIndex ];
132  m_filteredMarkers.erase( m_filteredMarkers.begin() + aIndex );
133 
134  if( aDeep )
135  m_board->Delete( marker );
136  }
137 
138  void DeleteAllItems() override
139  {
141  m_filteredMarkers.clear();
142  }
143 };
144 
145 
153 {
155  std::vector<DRC_ITEM*>* m_sourceVector; // owns its DRC_ITEMs
156 
158  std::vector<DRC_ITEM*> m_filteredVector; // does not own its DRC_ITEMs
159 
160 public:
161 
162  VECTOR_DRC_ITEMS_PROVIDER( PCB_BASE_FRAME* aFrame, std::vector<DRC_ITEM*>* aList ) :
163  m_frame( aFrame ),
164  m_sourceVector( aList ),
165  m_severities( 0 )
166  {
167  }
168 
169  void SetSeverities( int aSeverities ) override
170  {
171  m_severities = aSeverities;
172 
174 
175  m_filteredVector.clear();
176 
177  if( m_sourceVector )
178  {
179  for( DRC_ITEM* item : *m_sourceVector )
180  {
181  if( bds.GetSeverity( item->GetErrorCode() ) & aSeverities )
182  m_filteredVector.push_back( item );
183  }
184  }
185  }
186 
187  int GetCount( int aSeverity = -1 ) override
188  {
189  if( aSeverity < 0 )
190  return m_filteredVector.size();
191 
192  int count = 0;
194 
195  if( m_sourceVector )
196  {
197  for( DRC_ITEM* item : *m_sourceVector )
198  {
199  if( bds.GetSeverity( item->GetErrorCode() ) == aSeverity )
200  count++;
201  }
202  }
203 
204  return count;
205  }
206 
207  DRC_ITEM* GetItem( int aIndex ) override
208  {
209  return (m_filteredVector)[aIndex];
210  }
211 
212  void DeleteItem( int aIndex, bool aDeep ) override
213  {
214  DRC_ITEM* item = m_filteredVector[aIndex];
215  m_filteredVector.erase( m_filteredVector.begin() + aIndex );
216 
217  if( aDeep )
218  {
219  for( size_t i = 0; i < m_sourceVector->size(); ++i )
220  {
221  if( m_sourceVector->at( i ) == item )
222  {
223  delete item;
224  m_sourceVector->erase( m_sourceVector->begin() + i );
225  break;
226  }
227  }
228  }
229  }
230 
231  void DeleteAllItems() override
232  {
233  if( m_sourceVector )
234  {
235  for( DRC_ITEM* item : *m_sourceVector )
236  delete item;
237 
238  m_sourceVector->clear();
239  }
240 
241  m_filteredVector.clear(); // no ownership of DRC_ITEM pointers
242  }
243 };
244 
245 
250 {
251  // TODO: for now this is just a vector, but we need to map it to some board-level
252  // data-structure so that deleting/excluding things can do a deep delete/exclusion
253  // which will be reflected in the ratsnest....
254 public:
255  RATSNEST_DRC_ITEMS_PROVIDER( PCB_BASE_FRAME* aFrame, std::vector<DRC_ITEM*>* aList ) :
256  VECTOR_DRC_ITEMS_PROVIDER( aFrame, aList )
257  { }
258 };
259 
260 
261 #endif // DRC_ITEM_H
EDA_UNITS
Definition: common.h:184
void SetSeverities(int aSeverities) override
Definition: drc_item.h:169
RATSNEST_DRC_ITEMS_PROVIDER.
Definition: drc_item.h:249
void DeleteAllItems() override
Function DeleteAllItems removes and deletes all the items in the list.
Definition: drc_item.h:138
RC_ITEM * GetRCItem()
Function GetReporter returns the DRC_ITEM held within this MARKER so that its interface may be used.
Definition: marker_base.h:181
std::vector< DRC_ITEM * > m_filteredVector
Definition: drc_item.h:158
BOARD_DRC_ITEMS_PROVIDER(BOARD *aBoard)
Definition: drc_item.h:69
RC_ITEM is a holder for a DRC (in Pcbnew) or ERC (in Eeschema) error item.
Definition: rc_item.h:82
MARKERS & Markers()
Definition: class_board.h:248
DRC_ITEM * GetItem(int aIndex) override
Function GetItem retrieves a RC_ITEM by pointer.
Definition: drc_item.h:122
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:512
wxString GetErrorText() const override
Function GetErrorText returns the string form of a drc error code.
Definition: drc_item.cpp:35
This file contains miscellaneous commonly used macros and functions.
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:42
Classes used in Pcbnew, CvPcb and GerbView.
RATSNEST_DRC_ITEMS_PROVIDER(PCB_BASE_FRAME *aFrame, std::vector< DRC_ITEM * > *aList)
Definition: drc_item.h:255
int GetCount(int aSeverity=-1) override
Definition: drc_item.h:187
void DeleteItem(int aIndex, bool aDeep) override
Function DeleteItems removes and deletes desired item from the list.
Definition: drc_item.h:212
std::vector< MARKER_PCB * > m_filteredMarkers
Definition: drc_item.h:66
Markers used to show a drc problem on boards.
VECTOR_DRC_ITEMS_PROVIDER(PCB_BASE_FRAME *aFrame, std::vector< DRC_ITEM * > *aList)
Definition: drc_item.h:162
void DeleteMARKERs()
Function DeleteMARKERs deletes ALL MARKERS from the board.
BOARD_DRC_ITEMS_PROVIDER is an implementation of the interface named DRC_ITEM_LIST which uses a BOARD...
Definition: drc_item.h:60
void DeleteItem(int aIndex, bool aDeep) override
Function DeleteItems removes and deletes desired item from the list.
Definition: drc_item.h:129
DRC_ITEM * GetItem(int aIndex) override
Function GetItem retrieves a RC_ITEM by pointer.
Definition: drc_item.h:207
void SetSeverities(int aSeverities) override
Definition: drc_item.h:75
wxString ShowHtml(EDA_UNITS aUnits) const
Function ShowHtml translates this object into a fragment of HTML suitable for the wxHtmlListBox class...
Definition: drc_item.cpp:175
void DeleteAllItems() override
Function DeleteAllItems removes and deletes all the items in the list.
Definition: drc_item.h:231
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
std::vector< DRC_ITEM * > * m_sourceVector
Definition: drc_item.h:155
PCB_BASE_FRAME * m_frame
Definition: drc_item.h:154
virtual void Delete(BOARD_ITEM *aItem)
Removes an item from the container and deletes it.
BOARD * GetBoard() const
int GetSeverity(int aDRCErrorCode)
VECTOR_DRC_ITEMS_PROVIDER is an implementation of the interface named DRC_ITEMS_PROVIDER which uses a...
Definition: drc_item.h:152
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
int GetCount(int aSeverity=-1) override
Definition: drc_item.h:97
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.