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-2021 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  int GetCount( int aSeverity = -1 ) const override;
59 
60  std::shared_ptr<RC_ITEM> GetItem( int aIndex ) const override
61  {
62  PCB_MARKER* marker = m_filteredMarkers[ aIndex ];
63 
64  return marker ? marker->GetRCItem() : nullptr;
65  }
66 
67  void DeleteItem( int aIndex, bool aDeep ) override
68  {
69  PCB_MARKER* marker = m_filteredMarkers[ aIndex ];
70  m_filteredMarkers.erase( m_filteredMarkers.begin() + aIndex );
71 
72  if( aDeep )
73  m_board->Delete( marker );
74  }
75 
76  void DeleteAllItems( bool aIncludeExclusions, bool aDeep ) override
77  {
78  // Filtered list was already handled through DeleteItem() by the tree control
79 
80  if( aDeep )
81  m_board->DeleteMARKERs( true, aIncludeExclusions );
82  }
83 };
84 
85 
93 {
95  std::vector<std::shared_ptr<DRC_ITEM> >* m_sourceVector; // owns its DRC_ITEMs
96 
98  std::vector<std::shared_ptr<DRC_ITEM> > m_filteredVector; // does not own its DRC_ITEMs
99 
100 public:
101 
102  VECTOR_DRC_ITEMS_PROVIDER( PCB_BASE_FRAME* aFrame, std::vector<std::shared_ptr<DRC_ITEM> >* aList ) :
103  m_frame( aFrame ),
104  m_sourceVector( aList ),
105  m_severities( 0 )
106  {
107  }
108 
109  void SetSeverities( int aSeverities ) override;
110 
111  int GetCount( int aSeverity = -1 ) const override;
112 
113  std::shared_ptr<RC_ITEM> GetItem( int aIndex ) const override
114  {
115  return (m_filteredVector)[aIndex];
116  }
117 
118  void DeleteItem( int aIndex, bool aDeep ) override
119  {
120  auto item = m_filteredVector[aIndex];
121  m_filteredVector.erase( m_filteredVector.begin() + aIndex );
122 
123  if( aDeep )
124  {
125  for( size_t i = 0; i < m_sourceVector->size(); ++i )
126  {
127  if( m_sourceVector->at( i ) == item )
128  {
129  m_sourceVector->erase( m_sourceVector->begin() + i );
130  break;
131  }
132  }
133  }
134  }
135 
136  void DeleteAllItems( bool aIncludeExclusions, bool aDeep ) override
137  {
138  if( aDeep )
139  {
140  m_sourceVector->clear();
141  }
142 
143  m_filteredVector.clear(); // no ownership of DRC_ITEM pointers
144  }
145 };
146 
147 
152 {
153  // TODO: for now this is just a vector, but we need to map it to some board-level
154  // data-structure so that deleting/excluding things can do a deep delete/exclusion
155  // which will be reflected in the ratsnest....
156 public:
157  RATSNEST_DRC_ITEMS_PROVIDER( PCB_BASE_FRAME* aFrame, std::vector<std::shared_ptr<DRC_ITEM> >* aList ) :
158  VECTOR_DRC_ITEMS_PROVIDER( aFrame, aList )
159  { }
160 };
161 
162 
163 #endif // DRC_PROVIDER__H
void SetSeverities(int aSeverities) override
RATSNEST_DRC_ITEMS_PROVIDER.
int GetCount(int aSeverity=-1) const override
BOARD_DRC_ITEMS_PROVIDER(BOARD *aBoard)
std::vector< PCB_MARKER * > m_filteredMarkers
void DeleteAllItems(bool aIncludeExclusions, bool aDeep) override
Provide an abstract interface of a RC_ITEM* list manager.
Definition: rc_item.h:45
Classes used in Pcbnew, CvPcb and GerbView.
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:804
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.
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:191
int GetCount(int aSeverity=-1) const override
virtual void Delete(BOARD_ITEM *aItem)
Removes an item from the container and deletes it.
std::shared_ptr< RC_ITEM > GetItem(int aIndex) const 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
std::shared_ptr< RC_ITEM > GetItem(int aIndex) const override
Retrieve a RC_ITEM by index.