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

Constructor & Destructor Documentation

◆ NETINFO_MAPPING()

NETINFO_MAPPING::NETINFO_MAPPING ( )
inline

Definition at line 273 of file netinfo.h.

274  {
275  m_board = NULL;
276  }
const BOARD * m_board
Board for which mapping is prepared
Definition: netinfo.h:384

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

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

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

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

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

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

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

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

187 {
188  std::map<int, int>::const_iterator value = m_netMapping.find( aNetCode );
189 
190  if( value != m_netMapping.end() )
191  return value->second;
192 
193  // There was no entry for the given net code
194  return aNetCode;
195 }
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:387

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

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

References BOARD::GetArea(), BOARD::GetAreaCount(), BOARD_CONNECTED_ITEM::GetNetCode(), i, 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 384 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 387 of file netinfo.h.

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


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