KiCad PCB EDA Suite
NETINFO_MAPPING Class Reference

#include <netinfo.h>

Classes

class  iterator
 

Public Member Functions

 NETINFO_MAPPING ()
 
void SetBoard (const BOARD *aBoard)
 Set a BOARD object that is used to prepare the net code map. More...
 
void Update ()
 Prepare a mapping for net codes so they can be saved as consecutive numbers. More...
 
int Translate (int aNetCode) const
 Translate net number according to the map prepared by Update() function. More...
 
iterator begin () const
 Return iterator to the first entry in the mapping. More...
 
iterator end () const
 Return iterator to the last entry in the mapping. More...
 
int GetSize () const
 

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

Constructor & Destructor Documentation

◆ NETINFO_MAPPING()

NETINFO_MAPPING::NETINFO_MAPPING ( )
inline

Definition at line 191 of file netinfo.h.

192  {
193  m_board = nullptr;
194  }
const BOARD * m_board
Board for which mapping is prepared.
Definition: netinfo.h:300

References m_board.

Member Function Documentation

◆ begin()

iterator NETINFO_MAPPING::begin ( ) const
inline

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

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

References m_netMapping.

◆ end()

iterator NETINFO_MAPPING::end ( ) const
inline

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

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

References m_netMapping.

◆ GetSize()

int NETINFO_MAPPING::GetSize ( ) const
inline
Returns
Number of mapped nets (i.e. not empty nets for a given BOARD object).

Definition at line 294 of file netinfo.h.

295  {
296  return m_netMapping.size();
297  }
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:301

References m_netMapping.

◆ SetBoard()

void NETINFO_MAPPING::SetBoard ( const BOARD aBoard)
inline

Set a BOARD object that is used to prepare the net code map.

Definition at line 200 of file netinfo.h.

201  {
202  m_board = aBoard;
203  Update();
204  }
const BOARD * m_board
Board for which mapping is prepared.
Definition: netinfo.h:300
void Update()
Prepare a mapping for net codes so they can be saved as consecutive numbers.

References m_board, and Update().

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

◆ Translate()

int NETINFO_MAPPING::Translate ( int  aNetCode) const

Translate 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.Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString, NETINFO_ITEM*>

Definition at line 201 of file netinfo_list.cpp.

202 {
203  std::map<int, int>::const_iterator value = m_netMapping.find( aNetCode );
204 
205  if( value != m_netMapping.end() )
206  return value->second;
207 
208  // There was no entry for the given net code
209  return aNetCode;
210 }
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:301

References m_netMapping.

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

◆ Update()

void NETINFO_MAPPING::Update ( )

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

214 {
215  // Collect all the used nets
216  std::set<int> nets;
217 
218  // Be sure that the unconnected gets 0 and is mapped as 0
219  nets.insert( 0 );
220 
221  // Zones
222  for( ZONE* zone : m_board->Zones() )
223  nets.insert( zone->GetNetCode() );
224 
225  // Tracks
226  for( PCB_TRACK* track : m_board->Tracks() )
227  nets.insert( track->GetNetCode() );
228 
229  // footprints/pads
230  for( FOOTPRINT* footprint : m_board->Footprints() )
231  {
232  for( PAD* pad : footprint->Pads() )
233  nets.insert( pad->GetNetCode() );
234  }
235 
236  // Prepare the new mapping
237  m_netMapping.clear();
238 
239  // Now the nets variable stores all the used net codes (not only for pads) and we are ready to
240  // assign new consecutive net numbers
241  int newNetCode = 0;
242 
243  for( auto net : nets )
244  m_netMapping[net] = newNetCode++;
245 }
ZONES & Zones()
Definition: board.h:240
const BOARD * m_board
Board for which mapping is prepared.
Definition: netinfo.h:300
std::map< int, int > m_netMapping
Map that allows saving net codes with consecutive numbers (for compatibility reasons)
Definition: netinfo.h:301
FOOTPRINTS & Footprints()
Definition: board.h:234
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
Definition: pad.h:57
TRACKS & Tracks()
Definition: board.h:231

References BOARD::Footprints(), m_board, m_netMapping, pad, BOARD::Tracks(), and BOARD::Zones().

Referenced by SetBoard().

Member Data Documentation

◆ m_board

const BOARD* NETINFO_MAPPING::m_board
private

Board for which mapping is prepared.

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

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


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