KiCad PCB EDA Suite
NETINFO_LIST Class Reference

Class NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets. More...

#include <class_netinfo.h>

Classes

class  iterator
 

Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString, NETINFO_ITEM*>

More...
 

Public Member Functions

 NETINFO_LIST (BOARD *aParent)
 
 ~NETINFO_LIST ()
 
NETINFO_ITEMGetNetItem (int aNetCode) const
 Function GetItem. More...
 
NETINFO_ITEMGetNetItem (const wxString &aNetName) const
 Function GetItem. More...
 
unsigned GetNetCount () const
 Function GetNetCount. More...
 
void AppendNet (NETINFO_ITEM *aNewElement)
 Function AppendNet adds aNewElement to the end of the net list. More...
 
void RemoveNet (NETINFO_ITEM *aNet)
 Function RemoveNet Removes a new from the net list. More...
 
unsigned GetPadCount () const
 Function GetPadCount. More...
 
const D_PADS & GetPads () const
 Function GetPads returns a list of all the pads (so long as buildPadsFullList() has been recently called). More...
 
const NETNAMES_MAP & NetsByName () const
 Return the name map, at least for python. More...
 
const NETCODES_MAP & NetsByNetcode () const
 Return the netcode map, at least for python. More...
 
D_PADGetPad (unsigned aIdx) const
 Function GetPad. More...
 
bool DeletePad (D_PAD *aPad)
 
iterator begin () const
 
iterator end () const
 
BOARDGetParent () const
 

Static Public Attributes

static const int UNCONNECTED = 0
 

Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are actually not connected items

More...
 
static const int ORPHANED = -1
 

Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) when calling SetNetCode od board connected items

More...
 
static NETINFO_ITEM ORPHANED_ITEM = NETINFO_ITEM( NULL, wxEmptyString, NETINFO_LIST::UNCONNECTED )
 

NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net list available.

More...
 

Private Member Functions

void clear ()
 Function clear deletes the list of nets (and free memory) More...
 
void buildListOfNets ()
 Function buildListOfNets builds or rebuilds the list of NETINFO_ITEMs The list is sorted by names. More...
 
void buildPadsFullList ()
 Function buildPadsFullList creates the pad list, and initializes: m_Pads (list of pads) set m_Status_Pcb = LISTE_PAD_OK; and clear for all pads in list the m_SubRatsnest member; clear m_Pcb->m_FullRatsnest. More...
 
int getFreeNetCode ()
 Function getFreeNetCode returns the first available net code that is not used by any other net. More...
 

Private Attributes

BOARDm_Parent
 
NETNAMES_MAP m_netNames
 map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner More...
 
NETCODES_MAP m_netCodes
 map of <int, NETINFO_ITEM*> is NOT owner More...
 
D_PADS m_PadsFullList
 contains all pads, sorted by pad's netname. More...
 
int m_newNetCode
 possible value for new net code assignment More...
 

Friends

class BOARD
 

Detailed Description

Class NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.

That makes this class a container for the nets.

Definition at line 498 of file class_netinfo.h.

Constructor & Destructor Documentation

NETINFO_LIST::NETINFO_LIST ( BOARD aParent)

Definition at line 44 of file class_netinfolist.cpp.

References AppendNet(), and m_newNetCode.

44  : m_Parent( aParent )
45 {
46  // Make sure that the unconnected net has number 0
47  AppendNet( new NETINFO_ITEM( aParent, wxEmptyString, 0 ) );
48 
49  m_newNetCode = 0;
50 }
BOARD * m_Parent
void AppendNet(NETINFO_ITEM *aNewElement)
Function AppendNet adds aNewElement to the end of the net list.
int m_newNetCode
possible value for new net code assignment
Class NETINFO_ITEM handles the data for a net.
NETINFO_LIST::~NETINFO_LIST ( )

Definition at line 53 of file class_netinfolist.cpp.

References clear().

54 {
55  clear();
56 }
void clear()
Function clear deletes the list of nets (and free memory)

Member Function Documentation

void NETINFO_LIST::AppendNet ( NETINFO_ITEM aNewElement)

Function AppendNet adds aNewElement to the end of the net list.

Negative net code means it is going to be auto-assigned.

Definition at line 118 of file class_netinfolist.cpp.

References getFreeNetCode(), NETINFO_ITEM::GetNet(), GetNetItem(), NETINFO_ITEM::GetNetname(), NETINFO_ITEM::m_NetCode, m_netCodes, and m_netNames.

Referenced by BOARD::Add(), and NETINFO_LIST().

119 {
120  // if there is a net with such name then just assign the correct number
121  NETINFO_ITEM* sameName = GetNetItem( aNewElement->GetNetname() );
122 
123  if( sameName != NULL )
124  {
125  aNewElement->m_NetCode = sameName->GetNet();
126 
127  return;
128  }
129  // be sure that net codes are consecutive
130  // negative net code means that it has to be auto assigned
131  else if( ( aNewElement->m_NetCode != (int) m_netCodes.size() ) || ( aNewElement->m_NetCode < 0 ) )
132  {
133  aNewElement->m_NetCode = getFreeNetCode();
134  }
135 
136  // net names & codes are supposed to be unique
137  assert( GetNetItem( aNewElement->GetNetname() ) == NULL );
138  assert( GetNetItem( aNewElement->GetNet() ) == NULL );
139 
140  // add an entry for fast look up by a net name using a map
141  m_netNames.insert( std::make_pair( aNewElement->GetNetname(), aNewElement ) );
142  m_netCodes.insert( std::make_pair( aNewElement->GetNet(), aNewElement ) );
143 }
NETINFO_ITEM * GetNetItem(int aNetCode) const
Function GetItem.
NETNAMES_MAP m_netNames
map of , is NETINFO_ITEM owner
int getFreeNetCode()
Function getFreeNetCode returns the first available net code that is not used by any other net...
int m_NetCode
A number equivalent to the net name.
int GetNet() const
Function GetNet.
Class NETINFO_ITEM handles the data for a net.
const wxString & GetNetname() const
Function GetNetname.
NETCODES_MAP m_netCodes
map of is NOT owner
iterator NETINFO_LIST::begin ( ) const
inline

Definition at line 632 of file class_netinfo.h.

References m_netNames.

Referenced by BOARD::BeginNets(), buildListOfNets(), BOARD::SortedNetnamesList(), BOARD::SynchronizeNetsAndNetClasses(), and TestForExistingItem().

633  {
634  return iterator( m_netNames.begin() );
635  }
NETNAMES_MAP m_netNames
map of , is NETINFO_ITEM owner
void NETINFO_LIST::buildListOfNets ( )
private

Function buildListOfNets builds or rebuilds the list of NETINFO_ITEMs The list is sorted by names.

Compute and update the net_codes for PADS et and equipots (.m_NetCode member) net_codes are >= 1 (net_code = 0 means not connected) Update the net buffer Must be called after editing pads (netname, or deleting) or after read a netlist set to 1 flag NET_CODE_OK of m_Pcb->m_Status_Pcb; m_Pcb->m_NbNodes and m_Pcb->m_NbNets are updated Be aware NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname ) when search a net by its net name does a binary search and expects to have a nets list sorted by an alphabetic case sensitive sort So do not change Build_Pads_Full_List() which build a sorted list of pads.

Definition at line 197 of file class_netinfolist.cpp.

References LSET::AllCuMask(), begin(), buildPadsFullList(), end(), D_PAD::GetLayerSet(), BOARD_CONNECTED_ITEM::GetNet(), BOARD_CONNECTED_ITEM::GetNetCode(), NETINFO_ITEM::m_PadInNetList, m_PadsFullList, m_Parent, BOARD::m_Status_Pcb, NET_CODES_OK, BOARD::SetAreasNetCodesFromNetNames(), BOARD::SetNodeCount(), BOARD::SynchronizeNetsAndNetClasses(), and UNCONNECTED.

Referenced by BOARD::BuildListOfNets().

198 {
199  D_PAD* pad;
200  int nodes_count = 0;
201 
202  // Build the PAD list, sorted by net
204 
205  // Restore the initial state of NETINFO_ITEMs
206  for( NETINFO_LIST::iterator net( begin() ), netEnd( end() ); net != netEnd; ++net )
207  net->Clear();
208 
209  // Assign pads to appropriate NETINFO_ITEMs
210  for( unsigned ii = 0; ii < m_PadsFullList.size(); ii++ )
211  {
212  pad = m_PadsFullList[ii];
213 
214  if( pad->GetNetCode() == NETINFO_LIST::UNCONNECTED ) // pad not connected
215  continue;
216 
217  if( !( pad->GetLayerSet() & LSET::AllCuMask() ).any() )
218  // pad not a copper layer (happens when building complex shapes)
219  continue;
220 
221  // Add pad to the appropriate list of pads
222  NETINFO_ITEM* net = pad->GetNet();
223 
224  // it should not be possible for BOARD_CONNECTED_ITEM to return NULL as a result of GetNet()
225  wxASSERT( net );
226 
227  if( net )
228  net->m_PadInNetList.push_back( pad );
229 
230  ++nodes_count;
231  }
232 
233  m_Parent->SetNodeCount( nodes_count );
234 
236 
238 
240 }
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu LAYER_IDs.
Definition: lset.cpp:638
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair
BOARD * m_Parent
void buildPadsFullList()
Function buildPadsFullList creates the pad list, and initializes: m_Pads (list of pads) set m_Status_...
D_PADS m_PadInNetList
List of pads connected to this net.
void SynchronizeNetsAndNetClasses()
Function SynchronizeNetsAndNetClasses copies NETCLASS info to each NET, based on NET membership in a ...
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:235
int SetAreasNetCodesFromNetNames(void)
Function SetAreasNetCodesFromNetNames Set the .m_NetCode member of all copper areas, according to the area Net Name The SetNetCodesFromNetNames is an equivalent to net name, for fast comparisons.
int GetNetCode() const
Function GetNetCode.
Class NETINFO_ITEM handles the data for a net.
iterator begin() const
iterator end() const
void SetNodeCount(unsigned aCount)
Function SetNodeCount set the number of nodes of the current net to aCount.
Definition: class_board.h:721
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
D_PADS m_PadsFullList
contains all pads, sorted by pad's netname.
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:240
void NETINFO_LIST::buildPadsFullList ( )
private

Function buildPadsFullList creates the pad list, and initializes: m_Pads (list of pads) set m_Status_Pcb = LISTE_PAD_OK; and clear for all pads in list the m_SubRatsnest member; clear m_Pcb->m_FullRatsnest.

Definition at line 258 of file class_netinfolist.cpp.

References LISTE_PAD_OK, BOARD::m_FullRatsnest, BOARD::m_Modules, m_PadsFullList, m_Parent, BOARD::m_Status_Pcb, MODULE::Next(), D_PAD::Next(), and padlistSortByNetnames().

Referenced by buildListOfNets().

259 {
260  /*
261  * initialize:
262  * m_Pads (list of pads)
263  * set m_Status_Pcb = LISTE_PAD_OK;
264  * also clear m_Pcb->m_FullRatsnest that could have bad data
265  * (m_Pcb->m_FullRatsnest uses pointer to pads)
266  * Be aware NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname )
267  * when search a net by its net name does a binary search
268  * and expects to have a nets list sorted by an alphabetic case sensitive sort
269  * So do not change the sort function used here
270  */
271 
273  return;
274 
275  // empty the old list
276  m_PadsFullList.clear();
277  m_Parent->m_FullRatsnest.clear();
278 
279  // Clear variables used in ratsnest computation
280  for( MODULE* module = m_Parent->m_Modules; module; module = module->Next() )
281  {
282  for( D_PAD* pad = module->Pads(); pad; pad = pad->Next() )
283  {
284  m_PadsFullList.push_back( pad );
285 
286  pad->SetSubRatsnest( 0 );
287  pad->SetParent( module );
288  }
289  }
290 
291  // Sort pad list per net
292  sort( m_PadsFullList.begin(), m_PadsFullList.end(), padlistSortByNetnames );
293 
295 }
static bool padlistSortByNetnames(const D_PAD *a, const D_PAD *b)
BOARD * m_Parent
MODULE * Next() const
Definition: class_module.h:99
std::vector< RATSNEST_ITEM > m_FullRatsnest
Ratsnest list for the BOARD.
Definition: class_board.h:248
D_PAD * Next() const
Definition: class_pad.h:106
DLIST< MODULE > m_Modules
Definition: class_board.h:243
D_PADS m_PadsFullList
contains all pads, sorted by pad's netname.
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:240
void NETINFO_LIST::clear ( )
private

Function clear deletes the list of nets (and free memory)

Definition at line 59 of file class_netinfolist.cpp.

References m_netCodes, m_netNames, m_newNetCode, and m_PadsFullList.

Referenced by ~NETINFO_LIST().

60 {
61  NETNAMES_MAP::iterator it, itEnd;
62  for( it = m_netNames.begin(), itEnd = m_netNames.end(); it != itEnd; ++it )
63  delete it->second;
64 
65  m_PadsFullList.clear();
66  m_netNames.clear();
67  m_netCodes.clear();
68  m_newNetCode = 0;
69 }
NETNAMES_MAP m_netNames
map of , is NETINFO_ITEM owner
int m_newNetCode
possible value for new net code assignment
D_PADS m_PadsFullList
contains all pads, sorted by pad's netname.
NETCODES_MAP m_netCodes
map of is NOT owner
bool NETINFO_LIST::DeletePad ( D_PAD aPad)

Definition at line 155 of file class_netinfolist.cpp.

References end(), and m_PadsFullList.

Referenced by BOARD::PadDelete().

156 {
157  std::vector<D_PAD*>::iterator it = m_PadsFullList.begin();
158  std::vector<D_PAD*>::iterator end = m_PadsFullList.end();
159 
160  for( ; it != end; ++it )
161  {
162  if( *it == aPad )
163  {
164  m_PadsFullList.erase( it );
165  return true;
166  }
167  }
168  return false;
169 }
iterator end() const
D_PADS m_PadsFullList
contains all pads, sorted by pad's netname.
iterator NETINFO_LIST::end ( ) const
inline

Definition at line 637 of file class_netinfo.h.

References m_netNames.

Referenced by buildListOfNets(), DeletePad(), BOARD::EndNets(), BOARD::SortedNetnamesList(), BOARD::SynchronizeNetsAndNetClasses(), and TestForExistingItem().

638  {
639  return iterator( m_netNames.end() );
640  }
NETNAMES_MAP m_netNames
map of , is NETINFO_ITEM owner
int NETINFO_LIST::getFreeNetCode ( )
private

Function getFreeNetCode returns the first available net code that is not used by any other net.

Definition at line 298 of file class_netinfolist.cpp.

References m_netCodes, and m_newNetCode.

Referenced by AppendNet().

299 {
300  do {
301  if( m_newNetCode < 0 )
302  m_newNetCode = 0;
303  } while( m_netCodes.count( ++m_newNetCode ) != 0 );
304 
305  return m_newNetCode;
306 }
int m_newNetCode
possible value for new net code assignment
NETCODES_MAP m_netCodes
map of is NOT owner
unsigned NETINFO_LIST::GetNetCount ( ) const
inline

Function GetNetCount.

Returns
the number of nets ( always >= 1 ) because the first net is the "not connected" net and always exists

Definition at line 525 of file class_netinfo.h.

References m_netNames.

Referenced by BOARD::FindNet(), BOARD::GetMsgPanelInfo(), BOARD::GetNetCount(), and BOARD::SortedNetnamesList().

525 { return m_netNames.size(); }
NETNAMES_MAP m_netNames
map of , is NETINFO_ITEM owner
NETINFO_ITEM * NETINFO_LIST::GetNetItem ( int  aNetCode) const

Function GetItem.

Parameters
aNetCode= netcode to identify a given NETINFO_ITEM
Returns
NETINFO_ITEM* - by aNetCode, or NULL if not found

Definition at line 72 of file class_netinfolist.cpp.

References m_netCodes.

Referenced by AppendNet(), DIALOG_GLOBAL_EDIT_TRACKS_AND_VIAS::buildNetsList(), DIALOG_SELECT_NET_FROM_LIST::buildNetsList(), BOARD::FindNet(), and BOARD::GetSortedPadListByXthenYCoord().

73 {
74  NETCODES_MAP::const_iterator result = m_netCodes.find( aNetCode );
75 
76  if( result != m_netCodes.end() )
77  return (*result).second;
78 
79  return NULL;
80 }
NETCODES_MAP m_netCodes
map of is NOT owner
NETINFO_ITEM * NETINFO_LIST::GetNetItem ( const wxString &  aNetName) const

Function GetItem.

Parameters
aNetName= net name to identify a given NETINFO_ITEM
Returns
NETINFO_ITEM* - by aNetName, or NULL if not found

Definition at line 83 of file class_netinfolist.cpp.

References m_netNames.

84 {
85  NETNAMES_MAP::const_iterator result = m_netNames.find( aNetName );
86 
87  if( result != m_netNames.end() )
88  return (*result).second;
89 
90  return NULL;
91 }
NETNAMES_MAP m_netNames
map of , is NETINFO_ITEM owner
D_PAD * NETINFO_LIST::GetPad ( unsigned  aIdx) const

Function GetPad.

Returns
D_PAD* - the pad from m_PadsFullList or nullptr if bad aIdx

Definition at line 146 of file class_netinfolist.cpp.

References m_PadsFullList.

Referenced by BOARD::GetPad(), and BOARD::GetPadFast().

147 {
148  if( aIdx < m_PadsFullList.size() )
149  return m_PadsFullList[aIdx];
150  else
151  return NULL;
152 }
D_PADS m_PadsFullList
contains all pads, sorted by pad's netname.
unsigned NETINFO_LIST::GetPadCount ( ) const
inline

Function GetPadCount.

Returns
the number of pads in board

Definition at line 543 of file class_netinfo.h.

References m_PadsFullList.

Referenced by BOARD::GetPadCount().

543 { return m_PadsFullList.size(); }
D_PADS m_PadsFullList
contains all pads, sorted by pad's netname.
const D_PADS& NETINFO_LIST::GetPads ( ) const
inline

Function GetPads returns a list of all the pads (so long as buildPadsFullList() has been recently called).

Returned list contains non-owning pointers.

Returns
D_PADS& - a full list of pads

Definition at line 551 of file class_netinfo.h.

References m_PadsFullList.

551 { return m_PadsFullList; }
D_PADS m_PadsFullList
contains all pads, sorted by pad's netname.
BOARD* NETINFO_LIST::GetParent ( ) const
inline

Definition at line 643 of file class_netinfo.h.

References m_Parent.

644  {
645  return m_Parent;
646  }
BOARD * m_Parent
const NETNAMES_MAP& NETINFO_LIST::NetsByName ( ) const
inline

Return the name map, at least for python.

Definition at line 554 of file class_netinfo.h.

References m_netNames.

554 { return m_netNames; }
NETNAMES_MAP m_netNames
map of , is NETINFO_ITEM owner
const NETCODES_MAP& NETINFO_LIST::NetsByNetcode ( ) const
inline

Return the netcode map, at least for python.

Definition at line 557 of file class_netinfo.h.

References m_netCodes.

557 { return m_netCodes; }
NETCODES_MAP m_netCodes
map of is NOT owner
void NETINFO_LIST::RemoveNet ( NETINFO_ITEM aNet)

Function RemoveNet Removes a new from the net list.

Definition at line 94 of file class_netinfolist.cpp.

References NETINFO_ITEM::m_NetCode, m_netCodes, m_netNames, m_newNetCode, and min.

Referenced by BOARD::Remove().

95 {
96  for( NETCODES_MAP::iterator i = m_netCodes.begin(); i != m_netCodes.end(); ++i )
97  {
98  if ( i->second == aNet )
99  {
100  m_netCodes.erase(i);
101  break;
102  }
103  }
104 
105  for( NETNAMES_MAP::iterator i = m_netNames.begin(); i != m_netNames.end(); ++i )
106  {
107  if ( i->second == aNet )
108  {
109  m_netNames.erase(i);
110  break;
111  }
112  }
113 
115 }
NETNAMES_MAP m_netNames
map of , is NETINFO_ITEM owner
int m_newNetCode
possible value for new net code assignment
int m_NetCode
A number equivalent to the net name.
#define min(a, b)
Definition: auxiliary.h:85
NETCODES_MAP m_netCodes
map of is NOT owner

Friends And Related Function Documentation

friend class BOARD
friend

Definition at line 500 of file class_netinfo.h.

Member Data Documentation

NETCODES_MAP NETINFO_LIST::m_netCodes
private

map of <int, NETINFO_ITEM*> is NOT owner

Definition at line 681 of file class_netinfo.h.

Referenced by AppendNet(), clear(), getFreeNetCode(), GetNetItem(), NetsByNetcode(), and RemoveNet().

NETNAMES_MAP NETINFO_LIST::m_netNames
private

map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner

Definition at line 680 of file class_netinfo.h.

Referenced by AppendNet(), begin(), clear(), end(), GetNetCount(), GetNetItem(), NetsByName(), and RemoveNet().

int NETINFO_LIST::m_newNetCode
private

possible value for new net code assignment

Definition at line 686 of file class_netinfo.h.

Referenced by clear(), getFreeNetCode(), NETINFO_LIST(), and RemoveNet().

D_PADS NETINFO_LIST::m_PadsFullList
private

contains all pads, sorted by pad's netname.

can be used in ratsnest calculations.

Definition at line 683 of file class_netinfo.h.

Referenced by buildListOfNets(), buildPadsFullList(), clear(), DeletePad(), GetPad(), GetPadCount(), GetPads(), BOARD::GetPads(), and BOARD::GetSortedPadListByXthenYCoord().

BOARD* NETINFO_LIST::m_Parent
private

Definition at line 678 of file class_netinfo.h.

Referenced by buildListOfNets(), buildPadsFullList(), and GetParent().

const int NETINFO_LIST::ORPHANED = -1
static

Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) when calling SetNetCode od board connected items

Definition at line 573 of file class_netinfo.h.

Referenced by RN_DATA::Add(), MODULE::ClearAllNets(), and RN_DATA::Remove().

NETINFO_ITEM NETINFO_LIST::ORPHANED_ITEM = NETINFO_ITEM( NULL, wxEmptyString, NETINFO_LIST::UNCONNECTED )
static

NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net list available.

Definition at line 577 of file class_netinfo.h.

Referenced by BOARD::FindNet(), and BOARD_CONNECTED_ITEM::SetNetCode().


The documentation for this class was generated from the following files: