KiCad PCB EDA Suite
NETINFO_MAPPING Class Reference

#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_MAPPING ()
 
void SetBoard (const BOARD *aBoard)
 Function SetBoard Sets a BOARD object that is used to prepare the net code map. More...
 
void Update ()
 Function Update Prepares a mapping for net codes so they can be saved as consecutive numbers. More...
 
int Translate (int aNetCode) const
 Function Translate Translates net number according to the map prepared by Update() function. More...
 
iterator begin () const
 Function begin() Returns iterator to the first entry in the mapping. More...
 
iterator end () const
 Function end() Returns iterator to the last entry in the mapping. More...
 
int GetSize () const
 Function GetSize. More...
 

Private Attributes

const BOARDm_board
 

Board for which mapping is prepared

More...
 
std::map< int, int > m_netMapping
 

Map that allows saving net codes with consecutive numbers (for compatibility reasons)

More...
 

Detailed Description

Definition at line 283 of file netinfo.h.

Constructor & Destructor Documentation

◆ NETINFO_MAPPING()

NETINFO_MAPPING::NETINFO_MAPPING ( )
inline

Definition at line 286 of file netinfo.h.

287  {
288  m_board = NULL;
289  }
const BOARD * m_board
Board for which mapping is prepared
Definition: netinfo.h:397
#define NULL

References m_board, and NULL.

Member Function Documentation

◆ begin()

iterator NETINFO_MAPPING::begin ( ) const
inline

Function begin() Returns iterator to the first entry in the mapping.

NOTE: The entry is a pointer to the original NETINFO_ITEM object, this it contains not mapped net code.

Definition at line 370 of file netinfo.h.

371  {
372  return iterator( m_netMapping.begin(), this );
373  }
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:400

References m_netMapping.

◆ end()

iterator NETINFO_MAPPING::end ( ) const
inline

Function end() Returns iterator to the last entry in the mapping.

NOTE: The entry is a pointer to the original NETINFO_ITEM object, this it contains not mapped net code.

Definition at line 381 of file netinfo.h.

382  {
383  return iterator( m_netMapping.end(), this );
384  }
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:400

References m_netMapping.

◆ GetSize()

int NETINFO_MAPPING::GetSize ( ) const
inline

Function GetSize.

Returns
Number of mapped nets (i.e. not empty nets for a given BOARD object).

Definition at line 390 of file netinfo.h.

391  {
392  return m_netMapping.size();
393  }
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:400

References m_netMapping.

Referenced by PCB_IO::formatGeneral().

◆ SetBoard()

void NETINFO_MAPPING::SetBoard ( const BOARD aBoard)
inline

Function SetBoard Sets a BOARD object that is used to prepare the net code map.

Definition at line 296 of file netinfo.h.

297  {
298  m_board = aBoard;
299  Update();
300  }
const BOARD * m_board
Board for which mapping is prepared
Definition: netinfo.h:397
void Update()
Function Update Prepares a mapping for net codes so they can be saved as consecutive numbers.

References m_board, and Update().

Referenced by CLIPBOARD_IO::Save(), PCB_IO::Save(), and CLIPBOARD_IO::SaveSelection().

◆ Translate()

int NETINFO_MAPPING::Translate ( int  aNetCode) const

Function Translate Translates net number according to the map prepared by Update() function.

It allows one to have items stored with consecutive net codes.

Parameters
aNetCodeis an old net code.
Returns
Net code that follows the mapping.

Definition at line 195 of file netinfo_list.cpp.

196 {
197  std::map<int, int>::const_iterator value = m_netMapping.find( aNetCode );
198 
199  if( value != m_netMapping.end() )
200  return value->second;
201 
202  // There was no entry for the given net code
203  return aNetCode;
204 }
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:400

References m_netMapping.

Referenced by PCB_IO::format(), and PCB_IO::formatNetInformation().

◆ Update()

void NETINFO_MAPPING::Update ( )

Function Update Prepares a mapping for net codes so they can be saved as consecutive numbers.

To retrieve a mapped net code, use translateNet() function after calling this.

Definition at line 207 of file netinfo_list.cpp.

208 {
209  // Collect all the used nets
210  std::set<int> nets;
211 
212  // Be sure that the unconnected gets 0 and is mapped as 0
213  nets.insert( 0 );
214 
215  // Zones
216  for( int i = 0; i < m_board->GetAreaCount(); ++i )
217  nets.insert( m_board->GetArea( i )->GetNetCode() );
218 
219  // Tracks
220  for( auto track : m_board->Tracks() )
221  nets.insert( track->GetNetCode() );
222 
223  // Modules/pads
224  for( auto module : m_board->Modules() )
225  {
226  for( auto pad : module->Pads() )
227  {
228  nets.insert( pad->GetNetCode() );
229  }
230  }
231 
232  // Prepare the new mapping
233  m_netMapping.clear();
234 
235  // Now the nets variable stores all the used net codes (not only for pads) and we are ready to
236  // assign new consecutive net numbers
237  int newNetCode = 0;
238  for( std::set<int>::const_iterator it = nets.begin(), itEnd = nets.end(); it != itEnd; ++it )
239  m_netMapping[*it] = newNetCode++;
240 }
int GetNetCode() const
Function GetNetCode.
const BOARD * m_board
Board for which mapping is prepared
Definition: netinfo.h:397
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:400
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:934
MODULES & Modules()
Definition: class_board.h:266
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:899
TRACKS & Tracks()
Definition: class_board.h:257

References BOARD::GetArea(), BOARD::GetAreaCount(), BOARD_CONNECTED_ITEM::GetNetCode(), m_board, m_netMapping, BOARD::Modules(), and BOARD::Tracks().

Referenced by SetBoard().

Member Data Documentation

◆ m_board

const BOARD* NETINFO_MAPPING::m_board
private

Board for which mapping is prepared

Definition at line 397 of file netinfo.h.

Referenced by NETINFO_MAPPING(), NETINFO_MAPPING::iterator::operator *(), SetBoard(), and Update().

◆ m_netMapping

std::map<int, int> NETINFO_MAPPING::m_netMapping
private

Map that allows saving net codes with consecutive numbers (for compatibility reasons)

Definition at line 400 of file netinfo.h.

Referenced by begin(), end(), GetSize(), Translate(), and Update().


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