KiCad PCB EDA Suite
drc_results_provider.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) 2018-2020 KiCad Developers, see change_log.txt for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 
25 #ifndef DRC_PROVIDER__H
26 #define DRC_PROVIDER__H
27 
28 #include <board.h>
29 #include <pcb_marker.h>
30 #include <pcb_base_frame.h>
31 #include <drc/drc_item.h>
32 #include <widgets/ui_common.h>
33 #include <functional>
34 
35 
42 {
43 private:
45 
47  std::vector<PCB_MARKER*> m_filteredMarkers;
48 
49 public:
51  m_board( aBoard ),
52  m_severities( 0 )
53  {
54  }
55 
56  void SetSeverities( int aSeverities ) override
57  {
58  m_severities = aSeverities;
59 
61 
62  m_filteredMarkers.clear();
63 
64  for( PCB_MARKER* marker : m_board->Markers() )
65  {
66  SEVERITY markerSeverity;
67 
68  if( marker->IsExcluded() )
69  markerSeverity = RPT_SEVERITY_EXCLUSION;
70  else
71  markerSeverity = bds.GetSeverity( marker->GetRCItem()->GetErrorCode() );
72 
73  if( markerSeverity & m_severities )
74  m_filteredMarkers.push_back( marker );
75  }
76  }
77 
78  int GetCount( int aSeverity = -1 ) override
79  {
80  if( aSeverity < 0 )
81  return m_filteredMarkers.size();
82 
84 
85  int count = 0;
86 
87  for( PCB_MARKER* marker : m_board->Markers() )
88  {
89  SEVERITY markerSeverity;
90 
91  if( marker->IsExcluded() )
92  markerSeverity = RPT_SEVERITY_EXCLUSION;
93  else
94  markerSeverity = bds.GetSeverity( marker->GetRCItem()->GetErrorCode() );
95 
96  if( markerSeverity == aSeverity )
97  count++;
98  }
99 
100  return count;
101  }
102 
103  std::shared_ptr<RC_ITEM> GetItem( int aIndex ) override
104  {
105  PCB_MARKER* marker = m_filteredMarkers[ aIndex ];
106 
107  return marker ? marker->GetRCItem() : nullptr;
108  }
109 
110  void DeleteItem( int aIndex, bool aDeep ) override
111  {
112  PCB_MARKER* marker = m_filteredMarkers[ aIndex ];
113  m_filteredMarkers.erase( m_filteredMarkers.begin() + aIndex );
114 
115  if( aDeep )
116  m_board->Delete( marker );
117  }
118 
119  void DeleteAllItems( bool aIncludeExclusions, bool aDeep ) override
120  {
121  // Filtered list was already handled through DeleteItem() by the tree control
122 
123  if( aDeep )
124  m_board->DeleteMARKERs( true, aIncludeExclusions );
125  }
126 };
127 
128 
136 {
138  std::vector<std::shared_ptr<DRC_ITEM> >* m_sourceVector; // owns its DRC_ITEMs
139 
141  std::vector<std::shared_ptr<DRC_ITEM> > m_filteredVector; // does not own its DRC_ITEMs
142 
143 public:
144 
145  VECTOR_DRC_ITEMS_PROVIDER( PCB_BASE_FRAME* aFrame, std::vector<std::shared_ptr<DRC_ITEM> >* aList ) :
146  m_frame( aFrame ),
147  m_sourceVector( aList ),
148  m_severities( 0 )
149  {
150  }
151 
152  void SetSeverities( int aSeverities ) override
153  {
154  m_severities = aSeverities;
155 
157 
158  m_filteredVector.clear();
159 
160  if( m_sourceVector )
161  {
162  for( const std::shared_ptr<DRC_ITEM>& item : *m_sourceVector )
163  {
164  if( bds.GetSeverity( item->GetErrorCode() ) & aSeverities )
165  m_filteredVector.push_back( item );
166  }
167  }
168  }
169 
170  int GetCount( int aSeverity = -1 ) override
171  {
172  if( aSeverity < 0 )
173  return m_filteredVector.size();
174 
175  int count = 0;
177 
178  if( m_sourceVector )
179  {
180  for( const std::shared_ptr<DRC_ITEM>& item : *m_sourceVector )
181  {
182  if( bds.GetSeverity( item->GetErrorCode() ) == aSeverity )
183  count++;
184  }
185  }
186 
187  return count;
188  }
189 
190  std::shared_ptr<RC_ITEM> GetItem( int aIndex ) override
191  {
192  return (m_filteredVector)[aIndex];
193  }
194 
195  void DeleteItem( int aIndex, bool aDeep ) override
196  {
197  auto item = m_filteredVector[aIndex];
198  m_filteredVector.erase( m_filteredVector.begin() + aIndex );
199 
200  if( aDeep )
201  {
202  for( size_t i = 0; i < m_sourceVector->size(); ++i )
203  {
204  if( m_sourceVector->at( i ) == item )
205  {
206  m_sourceVector->erase( m_sourceVector->begin() + i );
207  break;
208  }
209  }
210  }
211  }
212 
213  void DeleteAllItems( bool aIncludeExclusions, bool aDeep ) override
214  {
215  if( aDeep )
216  {
217  m_sourceVector->clear();
218  }
219 
220  m_filteredVector.clear(); // no ownership of DRC_ITEM pointers
221  }
222 };
223 
224 
229 {
230  // TODO: for now this is just a vector, but we need to map it to some board-level
231  // data-structure so that deleting/excluding things can do a deep delete/exclusion
232  // which will be reflected in the ratsnest....
233 public:
234  RATSNEST_DRC_ITEMS_PROVIDER( PCB_BASE_FRAME* aFrame, std::vector<std::shared_ptr<DRC_ITEM> >* aList ) :
235  VECTOR_DRC_ITEMS_PROVIDER( aFrame, aList )
236  { }
237 };
238 
239 
240 #endif // DRC_PROVIDER__H
void SetSeverities(int aSeverities) override
RATSNEST_DRC_ITEMS_PROVIDER.
SEVERITY
Definition: ui_common.h:83
BOARD_DRC_ITEMS_PROVIDER(BOARD *aBoard)
MARKERS & Markers()
Definition: board.h:305
std::vector< PCB_MARKER * > m_filteredMarkers
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:584
std::shared_ptr< RC_ITEM > GetItem(int aIndex) override
Retrieve a RC_ITEM by index.
void DeleteAllItems(bool aIncludeExclusions, bool aDeep) override
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:43
Classes used in Pcbnew, CvPcb and GerbView.
int GetCount(int aSeverity=-1) override
void DeleteItem(int aIndex, bool aDeep) override
Remove (and optionally deletes) the indexed item from the list.
RATSNEST_DRC_ITEMS_PROVIDER(PCB_BASE_FRAME *aFrame, std::vector< std::shared_ptr< DRC_ITEM > > *aList)
void DeleteMARKERs()
Delete all MARKERS from the board.
Definition: board.cpp:760
BOARD_DRC_ITEMS_PROVIDER is an implementation of the RC_ITEMS_PROVIDER interface which uses a BOARD i...
void DeleteItem(int aIndex, bool aDeep) override
Remove (and optionally deletes) the indexed item from the list.
VECTOR_DRC_ITEMS_PROVIDER(PCB_BASE_FRAME *aFrame, std::vector< std::shared_ptr< DRC_ITEM > > *aList)
Functions to provide common constants and other functions to assist in making a consistent UI.
SEVERITY GetSeverity(int aDRCErrorCode)
std::vector< std::shared_ptr< DRC_ITEM > > m_filteredVector
std::vector< std::shared_ptr< DRC_ITEM > > * m_sourceVector
void SetSeverities(int aSeverities) override
void DeleteAllItems(bool aIncludeExclusions, bool aDeep) override
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:189
virtual void Delete(BOARD_ITEM *aItem)
Removes an item from the container and deletes it.
BOARD * GetBoard() const
std::shared_ptr< RC_ITEM > GetItem(int aIndex) override
Retrieve a RC_ITEM by index.
VECTOR_DRC_ITEMS_PROVIDER is an implementation of the interface named DRC_ITEMS_PROVIDER which uses a...
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
std::shared_ptr< RC_ITEM > GetRCItem() const
Definition: marker_base.h:100
int GetCount(int aSeverity=-1) override
Container for design settings for a BOARD object.