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-2020 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 #include "pns_router.h"
24 
25 namespace PNS {
26 
27 
28 void INDEX::Add( ITEM* aItem )
29 {
30  const LAYER_RANGE& range = aItem->Layers();
31 
32  if( m_subIndices.size() <= static_cast<size_t>( range.End() ) )
33  m_subIndices.resize( 2 * range.End() + 1 ); // +1 handles the 0 case
34 
35  for( int i = range.Start(); i <= range.End(); ++i )
36  m_subIndices[i].Add( aItem );
37 
38  m_allItems.insert( aItem );
39  int net = aItem->Net();
40 
41  if( net >= 0 )
42  m_netMap[net].push_back( aItem );
43 }
44 
45 
46 void INDEX::Remove( ITEM* aItem )
47 {
48  const LAYER_RANGE& range = aItem->Layers();
49 
50  if( m_subIndices.size() <= static_cast<size_t>( range.End() ) )
51  return;
52 
53  for( int i = range.Start(); i <= range.End(); ++i )
54  m_subIndices[i].Remove( aItem );
55 
56  m_allItems.erase( aItem );
57  int net = aItem->Net();
58 
59  if( net >= 0 && m_netMap.find( net ) != m_netMap.end() )
60  m_netMap[net].remove( aItem );
61 }
62 
63 
64 void INDEX::Replace( ITEM* aOldItem, ITEM* aNewItem )
65 {
66  Remove( aOldItem );
67  Add( aNewItem );
68 }
69 
70 
72 {
73  if( m_netMap.find( aNet ) == m_netMap.end() )
74  return NULL;
75 
76  return &m_netMap[aNet];
77 }
78 
79 };
Base class for PNS router board items.
Definition: pns_item.h:55
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:82
int End() const
Definition: pns_layerset.h:87
#define NULL
int Net() const
Definition: pns_item.h:148
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:71
void Replace(ITEM *aOldItem, ITEM *aNewItem)
Replaces one item with another.
Definition: pns_index.cpp:64
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:28
Push and Shove diff pair dimensions (gap) settings dialog.
void Remove(ITEM *aItem)
Removes an item from the spatial index.
Definition: pns_index.cpp:46
Represent a contiguous set of PCB layers.
Definition: pns_layerset.h:31
const LAYER_RANGE & Layers() const
Definition: pns_item.h:150