KiCad PCB EDA Suite
NETINFO_MAPPING Class Reference

#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_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 359 of file class_netinfo.h.

Constructor & Destructor Documentation

NETINFO_MAPPING::NETINFO_MAPPING ( )
inline

Definition at line 362 of file class_netinfo.h.

References m_board.

363  {
364  m_board = NULL;
365  }
const BOARD * m_board
Board for which mapping is prepared

Member Function Documentation

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 446 of file class_netinfo.h.

References m_netMapping.

447  {
448  return iterator( m_netMapping.begin(), this );
449  }
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons) ...
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 457 of file class_netinfo.h.

References m_netMapping.

458  {
459  return iterator( m_netMapping.end(), this );
460  }
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons) ...
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 466 of file class_netinfo.h.

References m_netMapping.

467  {
468  return m_netMapping.size();
469  }
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons) ...
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 372 of file class_netinfo.h.

References m_board, and Update().

Referenced by PCB_IO::Save().

373  {
374  m_board = aBoard;
375  Update();
376  }
const BOARD * m_board
Board for which mapping is prepared
void Update()
Function Update Prepares a mapping for net codes so they can be saved as consecutive numbers...
int NETINFO_MAPPING::Translate ( int  aNetCode) const

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

It allows to have items stored with consecutive net codes.

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

Definition at line 309 of file class_netinfolist.cpp.

References m_netMapping.

310 {
311  std::map<int, int>::const_iterator value = m_netMapping.find( aNetCode );
312 
313  if( value != m_netMapping.end() )
314  return value->second;
315 
316  // There was no entry for the given net code
317  return aNetCode;
318 }
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons) ...
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 321 of file class_netinfolist.cpp.

References BOARD::GetArea(), BOARD::GetAreaCount(), BOARD_CONNECTED_ITEM::GetNetCode(), m_board, BOARD::m_Modules, m_netMapping, BOARD::m_Track, BOARD::m_Zone, TRACK::Next(), MODULE::Next(), D_PAD::Next(), and SEGZONE::Next().

Referenced by SetBoard().

322 {
323  // Collect all the used nets
324  std::set<int> nets;
325 
326  // Be sure that the unconnected gets 0 and is mapped as 0
327  nets.insert( 0 );
328 
329  // Zones
330  for( int i = 0; i < m_board->GetAreaCount(); ++i )
331  nets.insert( m_board->GetArea( i )->GetNetCode() );
332 
333  // Tracks
334  for( TRACK* track = m_board->m_Track; track; track = track->Next() )
335  nets.insert( track->GetNetCode() );
336 
337  // Modules/pads
338  for( MODULE* module = m_board->m_Modules; module; module = module->Next() )
339  {
340  for( D_PAD* pad = module->Pads().GetFirst(); pad; pad = pad->Next() )
341  {
342  nets.insert( pad->GetNetCode() );
343  }
344  }
345 
346  // Segzones
347  for( SEGZONE* zone = m_board->m_Zone; zone; zone = zone->Next() )
348  nets.insert( zone->GetNetCode() );
349 
350  // Prepare the new mapping
351  m_netMapping.clear();
352 
353  // Now the nets variable stores all the used net codes (not only for pads) and we are ready to
354  // assign new consecutive net numbers
355  int newNetCode = 0;
356  for( std::set<int>::const_iterator it = nets.begin(), itEnd = nets.end(); it != itEnd; ++it )
357  m_netMapping[*it] = newNetCode++;
358 }
const BOARD * m_board
Board for which mapping is prepared
MODULE * Next() const
Definition: class_module.h:99
DLIST< SEGZONE > m_Zone
Definition: class_board.h:245
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons) ...
SEGZONE * Next() const
Definition: class_track.h:362
D_PAD * Next() const
Definition: class_pad.h:106
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1051
int GetNetCode() const
Function GetNetCode.
TRACK * Next() const
Definition: class_track.h:97
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:1022
DLIST< MODULE > m_Modules
Definition: class_board.h:243
DLIST< TRACK > m_Track
Definition: class_board.h:244

Member Data Documentation

const BOARD* NETINFO_MAPPING::m_board
private

Board for which mapping is prepared

Definition at line 473 of file class_netinfo.h.

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

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

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

Definition at line 476 of file class_netinfo.h.

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


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