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

Constructor & Destructor Documentation

◆ NETINFO_MAPPING()

NETINFO_MAPPING::NETINFO_MAPPING ( )
inline

Definition at line 275 of file netinfo.h.

276  {
277  m_board = NULL;
278  }
const BOARD * m_board
Board for which mapping is prepared
Definition: netinfo.h:386

References m_board.

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

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

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

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

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

380  {
381  return m_netMapping.size();
382  }
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:389

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

286  {
287  m_board = aBoard;
288  Update();
289  }
const BOARD * m_board
Board for which mapping is prepared
Definition: netinfo.h:386
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 194 of file netinfo_list.cpp.

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

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

207 {
208  // Collect all the used nets
209  std::set<int> nets;
210 
211  // Be sure that the unconnected gets 0 and is mapped as 0
212  nets.insert( 0 );
213 
214  // Zones
215  for( int i = 0; i < m_board->GetAreaCount(); ++i )
216  nets.insert( m_board->GetArea( i )->GetNetCode() );
217 
218  // Tracks
219  for( TRACK* track = m_board->m_Track; track; track = track->Next() )
220  nets.insert( track->GetNetCode() );
221 
222  // Modules/pads
223  for( MODULE* module = m_board->m_Modules; module; module = module->Next() )
224  {
225  for( D_PAD* pad = module->PadsList().GetFirst(); pad; pad = pad->Next() )
226  {
227  nets.insert( pad->GetNetCode() );
228  }
229  }
230 
231  // Prepare the new mapping
232  m_netMapping.clear();
233 
234  // Now the nets variable stores all the used net codes (not only for pads) and we are ready to
235  // assign new consecutive net numbers
236  int newNetCode = 0;
237  for( std::set<int>::const_iterator it = nets.begin(), itEnd = nets.end(); it != itEnd; ++it )
238  m_netMapping[*it] = newNetCode++;
239 }
D_PAD * Next() const
Definition: class_pad.h:162
int GetNetCode() const
Function GetNetCode.
const BOARD * m_board
Board for which mapping is prepared
Definition: netinfo.h:386
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:389
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:981
DLIST< MODULE > m_Modules
Definition: class_board.h:248
size_t i
Definition: json11.cpp:597
DLIST< TRACK > m_Track
Definition: class_board.h:249
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:952

References BOARD::GetArea(), BOARD::GetAreaCount(), BOARD_CONNECTED_ITEM::GetNetCode(), i, m_board, BOARD::m_Modules, m_netMapping, BOARD::m_Track, and D_PAD::Next().

Referenced by SetBoard().

Member Data Documentation

◆ m_board

const BOARD* NETINFO_MAPPING::m_board
private

Board for which mapping is prepared

Definition at line 386 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 389 of file netinfo.h.

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


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