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

Constructor & Destructor Documentation

NETINFO_MAPPING::NETINFO_MAPPING ( )
inline

Definition at line 282 of file class_netinfo.h.

References m_board.

283  {
284  m_board = NULL;
285  }
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 366 of file class_netinfo.h.

References m_netMapping.

Referenced by PCB_IO::format().

367  {
368  return iterator( m_netMapping.begin(), this );
369  }
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 377 of file class_netinfo.h.

References m_netMapping.

Referenced by PCB_IO::format().

378  {
379  return iterator( m_netMapping.end(), this );
380  }
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 386 of file class_netinfo.h.

References m_netMapping.

Referenced by PCB_IO::format().

387  {
388  return m_netMapping.size();
389  }
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 292 of file class_netinfo.h.

References m_board, and Update().

Referenced by PCB_IO::Save().

293  {
294  m_board = aBoard;
295  Update();
296  }
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 193 of file class_netinfolist.cpp.

References m_netMapping.

Referenced by PCB_IO::format().

194 {
195  std::map<int, int>::const_iterator value = m_netMapping.find( aNetCode );
196 
197  if( value != m_netMapping.end() )
198  return value->second;
199 
200  // There was no entry for the given net code
201  return aNetCode;
202 }
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 205 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().

206 {
207  // Collect all the used nets
208  std::set<int> nets;
209 
210  // Be sure that the unconnected gets 0 and is mapped as 0
211  nets.insert( 0 );
212 
213  // Zones
214  for( int i = 0; i < m_board->GetAreaCount(); ++i )
215  nets.insert( m_board->GetArea( i )->GetNetCode() );
216 
217  // Tracks
218  for( TRACK* track = m_board->m_Track; track; track = track->Next() )
219  nets.insert( track->GetNetCode() );
220 
221  // Modules/pads
222  for( MODULE* module = m_board->m_Modules; module; module = module->Next() )
223  {
224  for( D_PAD* pad = module->PadsList().GetFirst(); pad; pad = pad->Next() )
225  {
226  nets.insert( pad->GetNetCode() );
227  }
228  }
229 
230  // Segzones
231  for( SEGZONE* zone = m_board->m_Zone; zone; zone = zone->Next() )
232  nets.insert( zone->GetNetCode() );
233 
234  // Prepare the new mapping
235  m_netMapping.clear();
236 
237  // Now the nets variable stores all the used net codes (not only for pads) and we are ready to
238  // assign new consecutive net numbers
239  int newNetCode = 0;
240  for( std::set<int>::const_iterator it = nets.begin(), itEnd = nets.end(); it != itEnd; ++it )
241  m_netMapping[*it] = newNetCode++;
242 }
const BOARD * m_board
Board for which mapping is prepared
MODULE * Next() const
Definition: class_module.h:100
DLIST< SEGZONE > m_Zone
Definition: class_board.h:247
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:358
D_PAD * Next() const
Definition: class_pad.h:106
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1025
int GetNetCode() const
Function GetNetCode.
TRACK * Next() const
Definition: class_track.h:98
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:996
DLIST< MODULE > m_Modules
Definition: class_board.h:245
DLIST< TRACK > m_Track
Definition: class_board.h:246

Member Data Documentation

const BOARD* NETINFO_MAPPING::m_board
private

Board for which mapping is prepared

Definition at line 393 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 396 of file class_netinfo.h.

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


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