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 
27 {
28  memset( m_subIndices, 0, sizeof( m_subIndices ) );
29 }
30 
31 
33 {
34  Clear();
35 }
36 
37 
39 {
40  int idx_n = -1;
41 
42  const LAYER_RANGE l = aItem->Layers();
43 
44  switch( aItem->Kind() )
45  {
46  case ITEM::VIA_T:
47  idx_n = SI_Multilayer;
48  break;
49 
50  case ITEM::SOLID_T:
51  {
52  if( l.IsMultilayer() )
53  idx_n = SI_Multilayer;
54  else if( l.Start() == B_Cu ) // fixme: use kicad layer codes
55  idx_n = SI_PadsTop;
56  else if( l.Start() == F_Cu )
57  idx_n = SI_PadsBottom;
58  else
59  idx_n = SI_Traces + 2 * l.Start() + SI_SegStraight;
60  }
61  break;
62 
63  case ITEM::SEGMENT_T:
64  case ITEM::LINE_T:
65  idx_n = SI_Traces + 2 * l.Start() + SI_SegStraight;
66  break;
67 
68  default:
69  break;
70  }
71 
72  if( idx_n < 0 || idx_n >= MaxSubIndices )
73  {
74  wxASSERT( idx_n >= 0 );
75  wxASSERT( idx_n < MaxSubIndices );
76  return nullptr;
77  }
78 
79  if( !m_subIndices[idx_n] )
80  m_subIndices[idx_n] = new ITEM_SHAPE_INDEX;
81 
82  return m_subIndices[idx_n];
83 }
84 
85 void INDEX::Add( ITEM* aItem )
86 {
87  ITEM_SHAPE_INDEX* idx = getSubindex( aItem );
88 
89  if( !idx )
90  return;
91 
92  idx->Add( aItem );
93  m_allItems.insert( aItem );
94  int net = aItem->Net();
95 
96  if( net >= 0 )
97  {
98  m_netMap[net].push_back( aItem );
99  }
100 }
101 
102 void INDEX::Remove( ITEM* aItem )
103 {
104  ITEM_SHAPE_INDEX* idx = getSubindex( aItem );
105 
106  if( !idx )
107  return;
108 
109  idx->Remove( aItem );
110  m_allItems.erase( aItem );
111  int net = aItem->Net();
112 
113  if( net >= 0 && m_netMap.find( net ) != m_netMap.end() )
114  m_netMap[net].remove( aItem );
115 }
116 
117 void INDEX::Replace( ITEM* aOldItem, ITEM* aNewItem )
118 {
119  Remove( aOldItem );
120  Add( aNewItem );
121 }
122 
123 
125 {
126  for( int i = 0; i < MaxSubIndices; ++i )
127  {
129 
130  if( idx )
131  delete idx;
132 
133  m_subIndices[i] = NULL;
134  }
135 }
136 
137 
139 {
140  if( m_netMap.find( aNet ) == m_netMap.end() )
141  return NULL;
142 
143  return &m_netMap[aNet];
144 }
145 
146 };
Class ITEM.
Definition: pns_item.h:53
std::list< ITEM * > NET_ITEMS_LIST
Definition: pns_index.h:49
static const int SI_Traces
Definition: pns_index.h:148
bool IsMultilayer() const
Definition: pns_layerset.h:78
void Add(T aShape)
Function Add()
Definition: shape_index.h:310
int Start() const
Definition: pns_layerset.h:83
SHAPE_INDEX< ITEM * > ITEM_SHAPE_INDEX
Definition: pns_index.h:50
int Net() const
Definition: pns_item.h:148
void Remove(T aShape)
Function Remove()
Definition: shape_index.h:320
void Clear()
Function Clear()
Definition: pns_index.cpp:124
static const int SI_SegStraight
Definition: pns_index.h:147
ITEM_SHAPE_INDEX * m_subIndices[MaxSubIndices]
Definition: pns_index.h:157
ITEM_SET m_allItems
Definition: pns_index.h:159
static const int SI_PadsBottom
Definition: pns_index.h:150
NET_ITEMS_LIST * GetItemsForNet(int aNet)
Function GetItemsForNet()
Definition: pns_index.cpp:138
void Replace(ITEM *aOldItem, ITEM *aNewItem)
Function Add()
Definition: pns_index.cpp:117
std::map< int, NET_ITEMS_LIST > m_netMap
Definition: pns_index.h:158
static const int SI_Multilayer
Definition: pns_index.h:145
size_t i
Definition: json11.cpp:597
static const int SI_PadsTop
Definition: pns_index.h:149
void Add(ITEM *aItem)
Function Add()
Definition: pns_index.cpp:85
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:122
static const int MaxSubIndices
Definition: pns_index.h:144
ITEM_SHAPE_INDEX * getSubindex(const ITEM *aItem)
Definition: pns_index.cpp:38
Push and Shove diff pair dimensions (gap) settings dialog.
void Remove(ITEM *aItem)
Function Remove()
Definition: pns_index.cpp:102
Class LAYER_RANGE.
Definition: pns_layerset.h:32
const LAYER_RANGE & Layers() const
Definition: pns_item.h:150