KiCad PCB EDA Suite
pns_index.cpp
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 KiCad Developers, see AUTHORS.txt for contributors.
6  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
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 #include "pns_index.h"
23 
24 namespace PNS {
25 
26 
27 void INDEX::Add( ITEM* aItem )
28 {
29  const LAYER_RANGE& range = aItem->Layers();
30 
31  if( m_subIndices.size() <= static_cast<size_t>( range.End() ) )
32  m_subIndices.resize( 2 * range.End() + 1 ); // +1 handles the 0 case
33 
34  for( int i = range.Start(); i <= range.End(); ++i )
35  m_subIndices[i].Add( aItem );
36 
37  m_allItems.insert( aItem );
38  int net = aItem->Net();
39 
40  if( net >= 0 )
41  m_netMap[net].push_back( aItem );
42 }
43 
44 
45 void INDEX::Remove( ITEM* aItem )
46 {
47  const LAYER_RANGE& range = aItem->Layers();
48 
49  if( m_subIndices.size() <= static_cast<size_t>( range.End() ) )
50  return;
51 
52  for( int i = range.Start(); i <= range.End(); ++i )
53  m_subIndices[i].Remove( aItem );
54 
55  m_allItems.erase( aItem );
56  int net = aItem->Net();
57 
58  if( net >= 0 && m_netMap.find( net ) != m_netMap.end() )
59  m_netMap[net].remove( aItem );
60 }
61 
62 
63 void INDEX::Replace( ITEM* aOldItem, ITEM* aNewItem )
64 {
65  Remove( aOldItem );
66  Add( aNewItem );
67 }
68 
69 
71 {
72  if( m_netMap.find( aNet ) == m_netMap.end() )
73  return NULL;
74 
75  return &m_netMap[aNet];
76 }
77 
78 };
ITEM.
Definition: pns_item.h:53
std::list< ITEM * > NET_ITEMS_LIST
Definition: pns_index.h:48
std::deque< ITEM_SHAPE_INDEX > m_subIndices
Definition: pns_index.h:125
int Start() const
Definition: pns_layerset.h:83
int End() const
Definition: pns_layerset.h:88
#define NULL
int Net() const
Definition: pns_item.h:149
ITEM_SET m_allItems
Definition: pns_index.h:127
NET_ITEMS_LIST * GetItemsForNet(int aNet)
Returns list of all items in a given net.
Definition: pns_index.cpp:70
void Replace(ITEM *aOldItem, ITEM *aNewItem)
Replaces one item with another.
Definition: pns_index.cpp:63
std::map< int, NET_ITEMS_LIST > m_netMap
Definition: pns_index.h:126
void Add(ITEM *aItem)
Adds item to the spatial index.
Definition: pns_index.cpp:27
Push and Shove diff pair dimensions (gap) settings dialog.
void Remove(ITEM *aItem)
Removes an item from the spatial index.
Definition: pns_index.cpp:45
LAYER_RANGE.
Definition: pns_layerset.h:32
const LAYER_RANGE & Layers() const
Definition: pns_item.h:151