KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pns_index.h
Go to the documentation of this file.
1/*
2 * KiRouter - a push-and-(sometimes-)shove PCB router
3 *
4 * Copyright (C) 2013-2014 CERN
5 * Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 * Author: Tomasz Wlostowski <[email protected]>
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef __PNS_INDEX_H
23#define __PNS_INDEX_H
24
25#include <deque>
26#include <list>
27#include <map>
28#include <unordered_set>
29
30#include <layer_ids.h>
32
33#include "pns_item.h"
34#include "pns_node.h"
35
36namespace PNS {
37
38
46class INDEX
47{
48public:
49 typedef std::list<ITEM*> NET_ITEMS_LIST;
51 typedef std::unordered_set<ITEM*> ITEM_SET;
52
53 INDEX(){};
54
58 void Add( ITEM* aItem );
59
63 void Remove( ITEM* aItem );
64
68 void Replace( ITEM* aOldItem, ITEM* aNewItem );
69
81 template<class Visitor>
82 int Query( const ITEM* aItem, int aMinDistance, Visitor& aVisitor ) const;
83
95 template<class Visitor>
96 int Query( const SHAPE* aShape, int aMinDistance, Visitor& aVisitor ) const;
97
102
108 bool Contains( ITEM* aItem ) const
109 {
110 return m_allItems.find( aItem ) != m_allItems.end();
111 }
112
116 int Size() const { return m_allItems.size(); }
117
118 ITEM_SET::iterator begin() { return m_allItems.begin(); }
119 ITEM_SET::iterator end() { return m_allItems.end(); }
120
121private:
122 template <class Visitor>
123 int querySingle( std::size_t aIndex, const SHAPE* aShape, int aMinDistance, Visitor& aVisitor ) const;
124
125private:
126 std::deque<std::unique_ptr<ITEM_SHAPE_INDEX>> m_subIndices;
127 std::map<NET_HANDLE, NET_ITEMS_LIST> m_netMap;
129};
130
131
132template<class Visitor>
133int INDEX::querySingle( std::size_t aIndex, const SHAPE* aShape, int aMinDistance, Visitor& aVisitor ) const
134{
135 if( aIndex >= m_subIndices.size() )
136 return 0;
137
138 LAYER_CONTEXT_SETTER layerContext( aVisitor, aIndex );
139 return m_subIndices[aIndex]->Query( aShape, aMinDistance, aVisitor);
140}
141
142template<class Visitor>
143int INDEX::Query( const ITEM* aItem, int aMinDistance, Visitor& aVisitor ) const
144{
145 int total = 0;
146
147 wxCHECK( aItem->Kind() != ITEM::INVALID_T, 0 );
148
149 const PNS_LAYER_RANGE& layers = aItem->Layers();
150
151 for( int i = layers.Start(); i <= layers.End(); ++i )
152 total += querySingle( i, aItem->Shape( i ), aMinDistance, aVisitor );
153
154 return total;
155}
156
157template<class Visitor>
158int INDEX::Query( const SHAPE* aShape, int aMinDistance, Visitor& aVisitor ) const
159{
160 int total = 0;
161
162 for( std::size_t i = 0; i < m_subIndices.size(); ++i )
163 total += querySingle( i, aShape, aMinDistance, aVisitor );
164
165 return total;
166}
167
168};
169
170#endif
INDEX.
Definition: pns_index.h:47
std::deque< std::unique_ptr< ITEM_SHAPE_INDEX > > m_subIndices
Definition: pns_index.h:126
void Replace(ITEM *aOldItem, ITEM *aNewItem)
Replaces one item with another.
Definition: pns_index.cpp:69
int querySingle(std::size_t aIndex, const SHAPE *aShape, int aMinDistance, Visitor &aVisitor) const
Definition: pns_index.h:133
std::unordered_set< ITEM * > ITEM_SET
Definition: pns_index.h:51
ITEM_SET m_allItems
Definition: pns_index.h:128
void Remove(ITEM *aItem)
Removes an item from the spatial index.
Definition: pns_index.cpp:50
bool Contains(ITEM *aItem) const
Function Contains()
Definition: pns_index.h:108
std::list< ITEM * > NET_ITEMS_LIST
Definition: pns_index.h:49
SHAPE_INDEX< ITEM * > ITEM_SHAPE_INDEX
Definition: pns_index.h:50
int Size() const
Returns number of items stored in the index.
Definition: pns_index.h:116
ITEM_SET::iterator end()
Definition: pns_index.h:119
ITEM_SET::iterator begin()
Definition: pns_index.h:118
void Add(ITEM *aItem)
Adds item to the spatial index.
Definition: pns_index.cpp:28
int Query(const ITEM *aItem, int aMinDistance, Visitor &aVisitor) const
Searches items in the index that are in proximity of aItem.
Definition: pns_index.h:143
NET_ITEMS_LIST * GetItemsForNet(NET_HANDLE aNet)
Returns list of all items in a given net.
Definition: pns_index.cpp:76
std::map< NET_HANDLE, NET_ITEMS_LIST > m_netMap
Definition: pns_index.h:127
Base class for PNS router board items.
Definition: pns_item.h:97
virtual const SHAPE * Shape(int aLayer) const
Return the geometrical shape of the item.
Definition: pns_item.h:229
const PNS_LAYER_RANGE & Layers() const
Definition: pns_item.h:199
PnsKind Kind() const
Return the type (kind) of the item.
Definition: pns_item.h:170
@ INVALID_T
Definition: pns_item.h:102
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:32
int Start() const
Definition: pns_layerset.h:86
int End() const
Definition: pns_layerset.h:91
An abstract shape on 2D plane.
Definition: shape.h:126
Push and Shove diff pair dimensions (gap) settings dialog.
void * NET_HANDLE
Definition: pns_item.h:54