KiCad PCB EDA Suite
NETINFO_LIST Class Reference

Container for NETINFO_ITEM elements, which are the nets. More...

#include <netinfo.h>

Classes

class  iterator
 

Public Member Functions

 NETINFO_LIST (BOARD *aParent)
 
 ~NETINFO_LIST ()
 
NETINFO_ITEMGetNetItem (int aNetCode) const
 
NETINFO_ITEMGetNetItem (const wxString &aNetName) const
 
unsigned GetNetCount () const
 
void AppendNet (NETINFO_ITEM *aNewElement)
 Add aNewElement to the end of the net list. More...
 
void RemoveNet (NETINFO_ITEM *aNet)
 Remove a net from the net list. More...
 
void RemoveUnusedNets ()
 
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...
 
iterator begin () const
 
iterator end () const
 
BOARDGetParent () const
 

Static Public Member Functions

static NETINFO_ITEMOrphanedItem ()
 Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString, NETINFO_ITEM*> More...
 

Static Public Attributes

static const int UNCONNECTED = 0
 Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) when calling SetNetCode on board connected items. More...
 
static const int ORPHANED = -1
 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 ()
 Delete the list of nets (and free memory). More...
 
void buildListOfNets ()
 Rebuild the list of NETINFO_ITEMs. More...
 
int getFreeNetCode ()
 Return 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

Container for NETINFO_ITEM elements, which are the nets.

Definition at line 322 of file netinfo.h.

Constructor & Destructor Documentation

◆ NETINFO_LIST()

NETINFO_LIST::NETINFO_LIST ( BOARD aParent)

Definition at line 35 of file netinfo_list.cpp.

35  :
36  m_parent( aParent )
37 {
38  // Make sure that the unconnected net has number 0
39  AppendNet( new NETINFO_ITEM( aParent, wxEmptyString, 0 ) );
40 
41  m_newNetCode = 0;
42 }
BOARD * m_parent
Definition: netinfo.h:477
void AppendNet(NETINFO_ITEM *aNewElement)
Add aNewElement to the end of the net list.
int m_newNetCode
possible value for new net code assignment
Definition: netinfo.h:482
Handle the data for a net.
Definition: netinfo.h:66

References AppendNet(), and m_newNetCode.

◆ ~NETINFO_LIST()

NETINFO_LIST::~NETINFO_LIST ( )

Definition at line 45 of file netinfo_list.cpp.

46 {
47  clear();
48 }
void clear()
Delete the list of nets (and free memory).

References clear().

Member Function Documentation

◆ AppendNet()

void NETINFO_LIST::AppendNet ( NETINFO_ITEM aNewElement)

Add aNewElement to the end of the net list.

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

Definition at line 133 of file netinfo_list.cpp.

134 {
135  // if there is a net with such name then just assign the correct number
136  NETINFO_ITEM* sameName = GetNetItem( aNewElement->GetNetname() );
137 
138  if( sameName != nullptr )
139  {
140  aNewElement->m_netCode = sameName->GetNetCode();
141 
142  return;
143  }
144  else if( aNewElement->m_netCode != (int) m_netCodes.size() || aNewElement->m_netCode < 0 )
145  {
146  // be sure that net codes are consecutive
147  // negative net code means that it has to be auto assigned
148  aNewElement->m_netCode = getFreeNetCode();
149  }
150 
151  // net names & codes are supposed to be unique
152  assert( GetNetItem( aNewElement->GetNetname() ) == nullptr );
153  assert( GetNetItem( aNewElement->GetNetCode() ) == nullptr );
154 
155  // add an entry for fast look up by a net name using a map
156  m_netNames.insert( std::make_pair( aNewElement->GetNetname(), aNewElement ) );
157  m_netCodes.insert( std::make_pair( aNewElement->GetNetCode(), aNewElement ) );
158 }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:479
int getFreeNetCode()
Return the first available net code that is not used by any other net.
int m_netCode
A number equivalent to the net name.
Definition: netinfo.h:174
const wxString & GetNetname() const
Definition: netinfo.h:126
Handle the data for a net.
Definition: netinfo.h:66
NETINFO_ITEM * GetNetItem(int aNetCode) const
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:480
int GetNetCode() const
Definition: netinfo.h:120

References getFreeNetCode(), NETINFO_ITEM::GetNetCode(), GetNetItem(), NETINFO_ITEM::GetNetname(), NETINFO_ITEM::m_netCode, m_netCodes, and m_netNames.

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

◆ begin()

iterator NETINFO_LIST::begin ( ) const
inline

Definition at line 443 of file netinfo.h.

444  {
445  return iterator( m_netNames.begin() );
446  }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:479

References m_netNames.

Referenced by BOARD::BeginNets(), DSN::SPECCTRA_DB::FromBOARD(), and TestForExistingItem().

◆ buildListOfNets()

void NETINFO_LIST::buildListOfNets ( )
private

Rebuild the list of NETINFO_ITEMs.

The list is sorted by names.

Definition at line 161 of file netinfo_list.cpp.

162 {
163  // Restore the initial state of NETINFO_ITEMs
164  for( NETINFO_ITEM* net : *this )
165  net->Clear();
166 
169 }
BOARD * m_parent
Definition: netinfo.h:477
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1394
int SetAreasNetCodesFromNetNames()
Set the .m_NetCode member of all copper areas, according to the area Net Name The SetNetCodesFromNetN...
Definition: board.cpp:1427
Handle the data for a net.
Definition: netinfo.h:66
void Clear()
Set all fields to their default values.
Definition: netinfo.h:161

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

Referenced by BOARD::BuildListOfNets().

◆ clear()

void NETINFO_LIST::clear ( )
private

Delete the list of nets (and free memory).

Definition at line 51 of file netinfo_list.cpp.

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

References m_netCodes, m_netNames, and m_newNetCode.

Referenced by ~NETINFO_LIST().

◆ end()

iterator NETINFO_LIST::end ( ) const
inline

Definition at line 448 of file netinfo.h.

449  {
450  return iterator( m_netNames.end() );
451  }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:479

References m_netNames.

Referenced by BOARD::EndNets(), DSN::SPECCTRA_DB::FromBOARD(), and TestForExistingItem().

◆ getFreeNetCode()

int NETINFO_LIST::getFreeNetCode ( )
private

Return the first available net code that is not used by any other net.

Definition at line 189 of file netinfo_list.cpp.

190 {
191  do
192  {
193  if( m_newNetCode < 0 )
194  m_newNetCode = 0;
195  } while( m_netCodes.count( ++m_newNetCode ) != 0 );
196 
197  return m_newNetCode;
198 }
int m_newNetCode
possible value for new net code assignment
Definition: netinfo.h:482
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:480

References m_netCodes, and m_newNetCode.

Referenced by AppendNet().

◆ GetNetCount()

unsigned NETINFO_LIST::GetNetCount ( ) const
inline
Returns
the number of nets ( always >= 1 ) because the first net is the "not connected" net and always exists

Definition at line 346 of file netinfo.h.

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

References m_netNames.

Referenced by DIALOG_COPPER_ZONE::buildListOfNets(), BOARD::FindNet(), BOARD::GetNetCount(), FABMASTER::loadZones(), and DIALOG_COPPER_ZONE::readNetInformation().

◆ GetNetItem() [1/2]

NETINFO_ITEM * NETINFO_LIST::GetNetItem ( int  aNetCode) const
Parameters
aNetCodenetcode to identify a given NETINFO_ITEM.
Returns
net item by aNetCode, or NULL if not found.

Definition at line 63 of file netinfo_list.cpp.

64 {
65  NETCODES_MAP::const_iterator result = m_netCodes.find( aNetCode );
66 
67  if( result != m_netCodes.end() )
68  return (*result).second;
69 
70  return nullptr;
71 }
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:480

References m_netCodes.

Referenced by NET_SELECTOR_COMBOPOPUP::Accept(), AppendNet(), BOARD::FindNet(), NET_SELECTOR_COMBOPOPUP::GetSelectedNetname(), NET_SELECTOR_COMBOPOPUP::GetStringValue(), PCB_EDIT_FRAME::LoadProjectSettings(), APPEARANCE_CONTROLS::onNetclassContextMenu(), NET_SELECTOR_COMBOPOPUP::rebuildList(), BOARD::Remove(), 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
Parameters
aNetNamenet name to identify a given NETINFO_ITEM.
Returns
net item by aNetName, or NULL if not found.

Definition at line 74 of file netinfo_list.cpp.

75 {
76  NETNAMES_MAP::const_iterator result = m_netNames.find( aNetName );
77 
78  if( result != m_netNames.end() )
79  return (*result).second;
80 
81  return nullptr;
82 }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:479

References m_netNames.

◆ GetParent()

BOARD* NETINFO_LIST::GetParent ( void  ) const
inline

Definition at line 454 of file netinfo.h.

455  {
456  return m_parent;
457  }
BOARD * m_parent
Definition: netinfo.h:477

References m_parent.

Referenced by NET_SELECTOR_COMBOPOPUP::Accept().

◆ NetsByName()

const NETNAMES_MAP& NETINFO_LIST::NetsByName ( ) const
inline

Return the name map, at least for python.

Returns
the number of pads in board.

Definition at line 365 of file netinfo.h.

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

Referenced by FABMASTER::loadEtch(), FABMASTER::loadFootprints(), FABMASTER::loadVias(), FABMASTER::loadZone(), and NET_GRID_TABLE::Rebuild().

◆ NetsByNetcode()

const NETCODES_MAP& NETINFO_LIST::NetsByNetcode ( ) const
inline

Return the netcode map, at least for python.

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

Definition at line 368 of file netinfo.h.

References m_netCodes.

Referenced by DIALOG_NET_INSPECTOR::buildNetsList().

◆ OrphanedItem()

static NETINFO_ITEM* NETINFO_LIST::OrphanedItem ( )
inlinestatic

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

Definition at line 380 of file netinfo.h.

References UNCONNECTED.

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

◆ RemoveNet()

void NETINFO_LIST::RemoveNet ( NETINFO_ITEM aNet)

Remove a net from the net list.

Definition at line 85 of file netinfo_list.cpp.

86 {
87  bool removed = false;
88 
89  for( NETCODES_MAP::iterator i = m_netCodes.begin(); i != m_netCodes.end(); ++i )
90  {
91  if ( i->second == aNet )
92  {
93  removed = true;
94  m_netCodes.erase(i);
95  break;
96  }
97  }
98 
99  for( NETNAMES_MAP::iterator i = m_netNames.begin(); i != m_netNames.end(); ++i )
100  {
101  if ( i->second == aNet )
102  {
103  wxASSERT_MSG( removed, wxT( "NETINFO_LIST::RemoveNet: target net found in m_netNames "
104  "but not m_netCodes!" ) );
105  m_netNames.erase(i);
106  break;
107  }
108  }
109 
110  if( removed )
111  m_newNetCode = std::min( m_newNetCode, aNet->m_netCode - 1 );
112 }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:479
int m_netCode
A number equivalent to the net name.
Definition: netinfo.h:174
int m_newNetCode
possible value for new net code assignment
Definition: netinfo.h:482
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:480

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

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

◆ RemoveUnusedNets()

void NETINFO_LIST::RemoveUnusedNets ( )

Definition at line 115 of file netinfo_list.cpp.

116 {
117  NETCODES_MAP existingNets = m_netCodes;
118 
119  m_netCodes.clear();
120  m_netNames.clear();
121 
122  for( std::pair<const int, NETINFO_ITEM*> item : existingNets )
123  {
124  if( item.second->IsCurrent() )
125  {
126  m_netNames.insert( std::make_pair( item.second->GetNetname(), item.second ) );
127  m_netCodes.insert( std::make_pair( item.first, item.second ) );
128  }
129  }
130 }
NETNAMES_MAP m_netNames
map of <wxString, NETINFO_ITEM*>, is NETINFO_ITEM owner
Definition: netinfo.h:479
NETCODES_MAP m_netCodes
map of <int, NETINFO_ITEM*> is NOT owner
Definition: netinfo.h:480

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

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

◆ m_parent

BOARD* NETINFO_LIST::m_parent
private

Definition at line 477 of file netinfo.h.

Referenced by buildListOfNets(), and GetParent().

◆ ORPHANED

const int NETINFO_LIST::ORPHANED = -1
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 376 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: