KiCad PCB EDA Suite
NETINFO_LIST Class Reference

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

#include <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...
 
void RemoveUnusedNets ()
 
const NETNAMES_MAP & NetsByName () const
 Function GetPadCount. More...
 
const NETCODES_MAP & NetsByNetcode () const
 Return the netcode map, at least for python. More...
 
iterator begin () const
 
iterator end () const
 
BOARDGetParent () const
 

Static Public Member Functions

static NETINFO_ITEMOrphanedItem ()
 

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

More...
 

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...
 

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...
 
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...
 
int m_newNetCode
 possible value for new net code assignment More...
 

Friends

class BOARD
 

Detailed Description

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 422 of file netinfo.h.

Constructor & Destructor Documentation

◆ NETINFO_LIST()

NETINFO_LIST::NETINFO_LIST ( BOARD aParent)

Definition at line 33 of file netinfo_list.cpp.

33  : m_Parent( aParent )
34 {
35  // Make sure that the unconnected net has number 0
36  AppendNet( new NETINFO_ITEM( aParent, wxEmptyString, 0 ) );
37 
38  m_newNetCode = 0;
39 }
BOARD * m_Parent
Definition: netinfo.h:585
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
Definition: netinfo.h:590
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65

References AppendNet(), and m_newNetCode.

◆ ~NETINFO_LIST()

NETINFO_LIST::~NETINFO_LIST ( )

Definition at line 42 of file netinfo_list.cpp.

43 {
44  clear();
45 }
void clear()
Function clear deletes the list of nets (and free memory)

References clear().

Member Function Documentation

◆ AppendNet()

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 124 of file netinfo_list.cpp.

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

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

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

◆ begin()

iterator NETINFO_LIST::begin ( ) const
inline

Definition at line 549 of file netinfo.h.

550  {
551  return iterator( m_netNames.begin() );
552  }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:587

References m_netNames.

Referenced by BOARD::BeginNets(), and TestForExistingItem().

◆ buildListOfNets()

void NETINFO_LIST::buildListOfNets ( )
private

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

Definition at line 152 of file netinfo_list.cpp.

153 {
154  // Restore the initial state of NETINFO_ITEMs
155  for( NETINFO_ITEM* net : *this )
156  net->Clear();
157 
160 }
BOARD * m_Parent
Definition: netinfo.h:585
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1379
int SetAreasNetCodesFromNetNames()
Set the .m_NetCode member of all copper areas, according to the area Net Name The SetNetCodesFromNetN...
Definition: board.cpp:1412
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
void Clear()
Function Clear sets all fields to their defaults values.
Definition: netinfo.h:271

References NETINFO_ITEM::Clear(), m_Parent, BOARD::SetAreasNetCodesFromNetNames(), and BOARD::SynchronizeNetsAndNetClasses().

Referenced by BOARD::BuildListOfNets().

◆ clear()

void NETINFO_LIST::clear ( )
private

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

Definition at line 48 of file netinfo_list.cpp.

49 {
50  NETNAMES_MAP::iterator it, itEnd;
51  for( it = m_netNames.begin(), itEnd = m_netNames.end(); it != itEnd; ++it )
52  delete it->second;
53 
54  m_netNames.clear();
55  m_netCodes.clear();
56  m_newNetCode = 0;
57 }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:587
int m_newNetCode
possible value for new net code assignment
Definition: netinfo.h:590
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:588

References m_netCodes, m_netNames, and m_newNetCode.

Referenced by ~NETINFO_LIST().

◆ end()

iterator NETINFO_LIST::end ( ) const
inline

Definition at line 554 of file netinfo.h.

555  {
556  return iterator( m_netNames.end() );
557  }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:587

References m_netNames.

Referenced by BOARD::EndNets(), and TestForExistingItem().

◆ getFreeNetCode()

int NETINFO_LIST::getFreeNetCode ( )
private

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

Definition at line 180 of file netinfo_list.cpp.

181 {
182  do
183  {
184  if( m_newNetCode < 0 )
185  m_newNetCode = 0;
186  } while( m_netCodes.count( ++m_newNetCode ) != 0 );
187 
188  return m_newNetCode;
189 }
int m_newNetCode
possible value for new net code assignment
Definition: netinfo.h:590
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:588

References m_netCodes, and m_newNetCode.

Referenced by AppendNet().

◆ GetNetCount()

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 449 of file netinfo.h.

449 { return m_netNames.size(); }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:587

References m_netNames.

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

◆ GetNetItem() [1/2]

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 60 of file netinfo_list.cpp.

61 {
62  NETCODES_MAP::const_iterator result = m_netCodes.find( aNetCode );
63 
64  if( result != m_netCodes.end() )
65  return (*result).second;
66 
67  return NULL;
68 }
#define NULL
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:588

References m_netCodes, and NULL.

Referenced by NET_SELECTOR_COMBOPOPUP::Accept(), AppendNet(), BOARD::FindNet(), NET_SELECTOR_COMBOPOPUP::GetSelectedNetname(), NET_SELECTOR_COMBOPOPUP::GetStringValue(), PCB_EDIT_FRAME::LoadProjectSettings(), APPEARANCE_CONTROLS::onNetclassContextMenu(), test::DRC_TEST_PROVIDER_DIFF_PAIR_COUPLING::Run(), DRC_TEST_PROVIDER_MATCHED_LENGTH::runInternal(), PCB_EDIT_FRAME::SaveProjectSettings(), NET_SELECTOR_COMBOPOPUP::SetSelectedNet(), and APPEARANCE_CONTROLS::showNetclass().

◆ GetNetItem() [2/2]

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 71 of file netinfo_list.cpp.

72 {
73  NETNAMES_MAP::const_iterator result = m_netNames.find( aNetName );
74 
75  if( result != m_netNames.end() )
76  return (*result).second;
77 
78  return NULL;
79 }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:587
#define NULL

References m_netNames, and NULL.

◆ GetParent()

BOARD* NETINFO_LIST::GetParent ( void  ) const
inline

Definition at line 560 of file netinfo.h.

561  {
562  return m_Parent;
563  }
BOARD * m_Parent
Definition: netinfo.h:585

References m_Parent.

Referenced by NET_SELECTOR_COMBOPOPUP::Accept().

◆ NetsByName()

const NETNAMES_MAP& NETINFO_LIST::NetsByName ( ) const
inline

Function GetPadCount.

Returns
the number of pads in boardReturn the name map, at least for python.

Definition at line 471 of file netinfo.h.

471 { return m_netNames; }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:587

Referenced by NET_GRID_TABLE::Rebuild().

◆ NetsByNetcode()

const NETCODES_MAP& NETINFO_LIST::NetsByNetcode ( ) const
inline

Return the netcode map, at least for python.

Definition at line 474 of file netinfo.h.

474 { return m_netCodes; }
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:588

References m_netCodes.

Referenced by DIALOG_NET_INSPECTOR::buildNetsList().

◆ OrphanedItem()

static NETINFO_ITEM* NETINFO_LIST::OrphanedItem ( )
inlinestatic

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

Definition at line 486 of file netinfo.h.

487  {
488  static NETINFO_ITEM* g_orphanedItem;
489 
490  if( !g_orphanedItem )
491  g_orphanedItem = new NETINFO_ITEM( nullptr, wxEmptyString, NETINFO_LIST::UNCONNECTED );
492 
493  return g_orphanedItem;
494  }
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:478

References UNCONNECTED.

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

◆ RemoveNet()

void NETINFO_LIST::RemoveNet ( NETINFO_ITEM aNet)

Function RemoveNet Removes a new from the net list.

Definition at line 82 of file netinfo_list.cpp.

83 {
84  for( NETCODES_MAP::iterator i = m_netCodes.begin(); i != m_netCodes.end(); ++i )
85  {
86  if ( i->second == aNet )
87  {
88  m_netCodes.erase(i);
89  break;
90  }
91  }
92 
93  for( NETNAMES_MAP::iterator i = m_netNames.begin(); i != m_netNames.end(); ++i )
94  {
95  if ( i->second == aNet )
96  {
97  m_netNames.erase(i);
98  break;
99  }
100  }
101 
102  m_newNetCode = std::min( m_newNetCode, aNet->m_NetCode - 1 );
103 }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:587
int m_newNetCode
possible value for new net code assignment
Definition: netinfo.h:590
int m_NetCode
A number equivalent to the net name.
Definition: netinfo.h:70
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:588

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

Referenced by NET_SELECTOR_COMBOPOPUP::Accept(), and BOARD::Remove().

◆ RemoveUnusedNets()

void NETINFO_LIST::RemoveUnusedNets ( )

Definition at line 106 of file netinfo_list.cpp.

107 {
108  NETCODES_MAP existingNets = m_netCodes;
109 
110  m_netCodes.clear();
111  m_netNames.clear();
112 
113  for( std::pair<const int, NETINFO_ITEM*> item : existingNets )
114  {
115  if( item.second->IsCurrent() )
116  {
117  m_netNames.insert( std::make_pair( item.second->GetNetname(), item.second ) );
118  m_netCodes.insert( std::make_pair( item.first, item.second ) );
119  }
120  }
121 }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:587
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:588

References m_netCodes, and m_netNames.

Referenced by BOARD_NETLIST_UPDATER::UpdateNetlist().

Friends And Related Function Documentation

◆ BOARD

friend class BOARD
friend

Definition at line 424 of file netinfo.h.

Member Data Documentation

◆ m_netCodes

NETCODES_MAP NETINFO_LIST::m_netCodes
private

map of <int, NETINFO_ITEM*> is NOT owner

Definition at line 588 of file netinfo.h.

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

◆ m_netNames

NETNAMES_MAP NETINFO_LIST::m_netNames
private

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

Definition at line 587 of file netinfo.h.

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

◆ m_newNetCode

int NETINFO_LIST::m_newNetCode
private

possible value for new net code assignment

Definition at line 590 of file netinfo.h.

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

◆ m_Parent

BOARD* NETINFO_LIST::m_Parent
private

Definition at line 585 of file netinfo.h.

Referenced by buildListOfNets(), and GetParent().

◆ ORPHANED

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 482 of file netinfo.h.

Referenced by FOOTPRINT::ClearAllNets(), PCB_PARSER::parsePAD(), and BOARD::SanitizeNetcodes().

◆ UNCONNECTED


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