KiCad PCB EDA Suite
NETLIST_OBJECT Class Reference

#include <netlist_object.h>

Public Member Functions

 NETLIST_OBJECT ()
 
 NETLIST_OBJECT (NETLIST_OBJECT &aSource)
 
 ~NETLIST_OBJECT ()
 
void SetNet (int aNetCode)
 
int GetNet () const
 
void SetConnectionType (NET_CONNECTION aFlg=NET_CONNECTION::UNCONNECTED)
 Set the item connection type: UNCONNECTED Pin or Label not connected (error) NOCONNECT_SYMBOL_PRESENT Pin not connected but have a NoConnect symbol on it (no error) PAD_CONNECT Normal connection (no error) More...
 
NET_CONNECTION GetConnectionType () const
 
void SetNetNameCandidate (NETLIST_OBJECT *aCandidate)
 Set m_netNameCandidate to a connected item which will be used to calcule the net name of the item Obviously the candidate can be only a label when there is no label on the net a pad which will used to build a net name (something like Cmp<REF>_Pad<PAD_NAME> More...
 
bool HasNetNameCandidate ()
 
const wxString & GetPinNumText () const
 returns a pin number in wxString form. More...
 
const wxString GetPinNameText () const
 returns the pin name, for NET_PIN (usual pin) item. More...
 
SCH_COMPONENTGetComponentParent () const
 For Pins (NET_PINS): More...
 
bool IsLabelConnected (NETLIST_OBJECT *aNetItem)
 Function IsLabelConnected tests if the net list object is a hierarchical label or sheet label and is connected to an associated hierarchical label or sheet label of aNetItem. More...
 
bool IsLabelGlobal () const
 Function IsLabelGlobal. More...
 
bool IsLabelBusMemberType () const
 Function IsLabelBusMemberType. More...
 
bool IsLabelType () const
 Function IsLabelType. More...
 
wxString GetNetName () const
 Function GetNetName. More...
 
wxString GetShortNetName () const
 Function GetShortNetName. More...
 
void ConvertBusToNetListItems (NETLIST_OBJECT_LIST &aNetListItems)
 Function ConvertBusToNetListItems breaks the text of a bus label type net list object into as many members as it contains and creates a NETLIST_OBJECT for each label and adds it to aNetListItems. More...
 

Public Attributes

NETLIST_ITEM m_Type
 
EDA_ITEMm_Comp
 
SCH_ITEMm_Link
 
int m_Flag
 
SCH_SHEET_PATH m_SheetPath
 
SCH_SHEET_PATH m_SheetPathInclude
 
ELECTRICAL_PINTYPE m_ElectricalPinType
 
int m_BusNetCode
 
int m_Member
 
NET_CONNECTION m_ConnectionType
 
wxString m_PinNum
 
wxString m_Label
 
wxPoint m_Start
 
wxPoint m_End
 

Private Member Functions

void fillBusVector (NETLIST_OBJECT_LIST &aNetListItems, wxString aName, long aBegin, long aEnd, long aOffset)
 Given a bus vector, append the appropriate members into the list If given something like "DATA", 7, 0, will append "DATA7", "DATA6", etc. More...
 

Private Attributes

int m_netCode
 
NETLIST_OBJECTm_netNameCandidate
 

Detailed Description

Definition at line 92 of file netlist_object.h.

Constructor & Destructor Documentation

◆ NETLIST_OBJECT() [1/2]

NETLIST_OBJECT::NETLIST_OBJECT ( )

Definition at line 148 of file netlist_object.cpp.

149 {
150  m_Type = NETLIST_ITEM::ITEM_UNSPECIFIED; /* Type of this item (see NETLIST_ITEM_T enum) */
151  m_Comp = NULL; /* Pointer on the library item that created this net object
152  * (the parent)*/
153  m_Link = NULL; /* For SCH_SHEET_PIN:
154  * Pointer to the hierarchy sheet that contains this
155  * SCH_SHEET_PIN For Pins: pointer to the component that
156  * contains this pin
157  */
158  m_Flag = 0; /* flag used in calculations */
159  m_netCode = 0; /* net code for all items except BUS labels because a BUS
160  * label has as many net codes as bus members
161  */
162  m_BusNetCode = 0; /* Used for BUS connections */
163  m_Member = 0; /* for labels type NETLIST_ITEM::BUSLABELMEMBER ( bus member created
164  * from the BUS label ) member number
165  */
168  ELECTRICAL_PINTYPE::PT_INPUT; /* Has meaning only for Pins: electrical type of the pin
169  * used to detect conflicts between pins in ERC
170  */
171  m_netNameCandidate = NULL; /* a pointer to a NETLIST_OBJECT type label connected to this
172  * object used to give a name to the net
173  */
174 }
NETLIST_OBJECT * m_netNameCandidate
ELECTRICAL_PINTYPE m_ElectricalPinType
EDA_ITEM * m_Comp
#define NULL
usual pin input: must be connected
NET_CONNECTION m_ConnectionType
NETLIST_ITEM m_Type
SCH_ITEM * m_Link

References ITEM_UNSPECIFIED, m_BusNetCode, m_Comp, m_ConnectionType, m_ElectricalPinType, m_Flag, m_Link, m_Member, m_netCode, m_netNameCandidate, m_Type, NULL, PT_INPUT, and UNCONNECTED.

Referenced by ConvertBusToNetListItems(), and fillBusVector().

◆ NETLIST_OBJECT() [2/2]

NETLIST_OBJECT::NETLIST_OBJECT ( NETLIST_OBJECT aSource)

Definition at line 178 of file netlist_object.cpp.

179 {
180  *this = aSource;
181 }

◆ ~NETLIST_OBJECT()

NETLIST_OBJECT::~NETLIST_OBJECT ( )

Definition at line 184 of file netlist_object.cpp.

185 {
186 }

Member Function Documentation

◆ ConvertBusToNetListItems()

void NETLIST_OBJECT::ConvertBusToNetListItems ( NETLIST_OBJECT_LIST aNetListItems)

Function ConvertBusToNetListItems breaks the text of a bus label type net list object into as many members as it contains and creates a NETLIST_OBJECT for each label and adds it to aNetListItems.

Parameters
aNetListItemsA reference to vector of NETLIST_OBJECT pointers to add the bus label NETLIST_OBJECTs.

Definition at line 224 of file netlist_object.cpp.

225 {
226  SCH_CONNECTION conn;
227  wxCHECK_RET( conn.IsBusLabel( m_Label ),
228  wxT( "<" ) + m_Label + wxT( "> is not a valid bus label." ) );
229 
232  else if( m_Type == NETLIST_ITEM::GLOBLABEL )
234  else if( m_Type == NETLIST_ITEM::SHEETLABEL )
236  else if( m_Type == NETLIST_ITEM::LABEL )
238  else
239  wxCHECK_RET( false, wxT( "Net list object type is not valid." ) );
240 
241  // NOTE: all netlist objects generated from a single bus definition need to have different
242  // member codes set. For bus vectors, the member code matches the vector index, but for
243  // bus groups (including with nested vectors) the code is something arbitrary.
244  long member_offset = 0;
245 
246  auto alias = static_cast<SCH_ITEM*>( m_Comp )->Schematic()->GetBusAlias( m_Label );
247  wxString group_name;
248  bool self_set = false;
249  std::vector<wxString> bus_contents_vec;
250 
251  if( alias || SCH_CONNECTION::ParseBusGroup( m_Label, &group_name, &bus_contents_vec ) )
252  {
253  if( alias )
254  {
255  for( const wxString& member : alias->Members() )
256  bus_contents_vec.emplace_back( member );
257  }
258 
259  // For named bus groups, like "USB{DP DM}"
260  wxString group_prefix = ( group_name != "" ) ? ( group_name + "." ) : "";
261 
262  std::list<wxString> bus_contents( bus_contents_vec.begin(), bus_contents_vec.end() );
263 
264  for( const auto& bus_member : bus_contents )
265  {
266  wxString prefix;
267  std::vector<wxString> members;
268 
269  // Nested bus vector inside a bus group
270  if( SCH_CONNECTION::ParseBusVector( bus_member, &prefix, &members ) )
271  {
272  long begin, end;
273 
274  prefix = group_prefix + prefix;
275  begin = conn.VectorStart();
276  end = conn.VectorEnd();
277 
278  if( !self_set )
279  {
280  m_Label = members[0];
281  m_Member = ( begin++ ) + ( member_offset++ );
282 
283  self_set = true;
284  begin++;
285  }
286 
287  fillBusVector( aNetListItems, prefix, begin, end, member_offset );
288  member_offset += std::abs( end - begin );
289  }
290  else if( auto nested_alias = static_cast<SCH_ITEM*>( m_Comp )->Schematic()->GetBusAlias(
291  bus_member ) )
292  {
293  // Nested alias inside a group
294  for( const auto& alias_member : nested_alias->Members() )
295  {
296  bus_contents.push_back( alias_member );
297  }
298  }
299  else
300  {
301  if( !self_set )
302  {
303  m_Label = group_prefix + bus_member;
304  m_Member = member_offset++;
305  self_set = true;
306  }
307  else
308  {
309  auto item = new NETLIST_OBJECT( *this );
310  item->m_Label = group_prefix + bus_member;
311  item->m_Member = member_offset++;
312  aNetListItems.push_back( item );
313  }
314  }
315  }
316  }
317  else if( SCH_CONNECTION::ParseBusVector( m_Label, &group_name, &bus_contents_vec ) )
318  {
319  long begin = conn.VectorStart();
320  long end = conn.VectorEnd();
321 
322  m_Label = bus_contents_vec[0];
323  m_Member = begin;
324 
325  fillBusVector( aNetListItems, group_name, begin + 1, end, 0 );
326  }
327 }
void fillBusVector(NETLIST_OBJECT_LIST &aNetListItems, wxString aName, long aBegin, long aEnd, long aOffset)
Given a bus vector, append the appropriate members into the list If given something like "DATA",...
static bool IsBusLabel(const wxString &aLabel)
Test if aLabel has a bus notation.
EDA_ITEM * m_Comp
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parses a bus vector (e.g.
static bool ParseBusGroup(wxString aGroup, wxString *name, std::vector< wxString > *aMemberList)
Parses a bus group label into the name and a list of components.
long VectorEnd() const
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
long VectorStart() const
NETLIST_ITEM m_Type

References BUSLABELMEMBER, fillBusVector(), GLOBBUSLABELMEMBER, GLOBLABEL, HIERBUSLABELMEMBER, HIERLABEL, SCH_CONNECTION::IsBusLabel(), LABEL, m_Comp, m_Label, m_Member, m_Type, NETLIST_OBJECT(), SCH_CONNECTION::ParseBusGroup(), SCH_CONNECTION::ParseBusVector(), SHEETBUSLABELMEMBER, SHEETLABEL, SCH_CONNECTION::VectorEnd(), and SCH_CONNECTION::VectorStart().

Referenced by SCH_TEXT::GetNetListItem(), and SCH_SHEET::GetNetListItem().

◆ fillBusVector()

void NETLIST_OBJECT::fillBusVector ( NETLIST_OBJECT_LIST aNetListItems,
wxString  aName,
long  aBegin,
long  aEnd,
long  aOffset 
)
private

Given a bus vector, append the appropriate members into the list If given something like "DATA", 7, 0, will append "DATA7", "DATA6", etc.

Parameters
aNetListItemsis the list to append to
aNameis the prefix for the vector, like "DATA"
aBeginis the first entry in the vector
aEndis the last entry in the vector
aOffsetis an offset to add to the member code for each member

Definition at line 329 of file netlist_object.cpp.

331 {
332  for( long member = aBegin; member <= aEnd; member++ )
333  {
334  auto item = new NETLIST_OBJECT( *this );
335 
336  item->m_Label = aName;
337  item->m_Label << member;
338  item->m_Member = member;
339 
340  aNetListItems.push_back( item );
341  }
342 }

References NETLIST_OBJECT().

Referenced by ConvertBusToNetListItems().

◆ GetComponentParent()

SCH_COMPONENT* NETLIST_OBJECT::GetComponentParent ( ) const
inline

For Pins (NET_PINS):

Returns
the schematic component which contains this pin (Note: this is the schematic component, not the library component for others items: return NULL

Definition at line 198 of file netlist_object.h.

199  {
200  if( m_Link && m_Link->Type() == SCH_COMPONENT_T )
201  return (SCH_COMPONENT*) m_Link;
202 
203  return NULL;
204  }
#define NULL
Schematic symbol object.
Definition: sch_component.h:88
SCH_ITEM * m_Link
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References m_Link, NULL, SCH_COMPONENT_T, and EDA_ITEM::Type().

Referenced by NETLIST_OBJECT_LIST::findBestNetNameForEachNet(), and GetShortNetName().

◆ GetConnectionType()

NET_CONNECTION NETLIST_OBJECT::GetConnectionType ( ) const
inline

Definition at line 158 of file netlist_object.h.

159  {
160  return m_ConnectionType;
161  }
NET_CONNECTION m_ConnectionType

References m_ConnectionType.

Referenced by NETLIST_OBJECT_LIST::GetConnectionType().

◆ GetNet()

◆ GetNetName()

wxString NETLIST_OBJECT::GetNetName ( ) const

Function GetNetName.

Returns
the full net name of the item, i.e. the net name from the "best" label, prefixed by the sheet path

Definition at line 372 of file netlist_object.cpp.

373 {
374  if( m_netNameCandidate == NULL )
375  return wxEmptyString;
376 
377  wxString netName;
378 
380  return GetShortNetName();
381 
383  {
384  // usual net name, prefix it by the sheet path
386  }
387 
388  netName += m_netNameCandidate->m_Label;
389 
390  return netName;
391 }
NETLIST_OBJECT * m_netNameCandidate
SCH_SHEET_PATH m_SheetPath
bool IsLabelGlobal() const
Function IsLabelGlobal.
#define NULL
wxString GetShortNetName() const
Function GetShortNetName.
wxString PathHumanReadable() const
Function PathHumanReadable returns the sheet path in a human readable form, i.e.
NETLIST_ITEM m_Type

References GetShortNetName(), IsLabelGlobal(), m_Label, m_netNameCandidate, m_SheetPath, m_Type, NULL, SCH_SHEET_PATH::PathHumanReadable(), and PIN.

◆ GetPinNameText()

const wxString NETLIST_OBJECT::GetPinNameText ( ) const

returns the pin name, for NET_PIN (usual pin) item.

Definition at line 449 of file netlist_object.cpp.

450 {
451  wxString name;
452  // returns the pin name, for NETLIST_ITEM::PIN (usual pin) item.
453  if( m_Type == NETLIST_ITEM::PIN )
454  {
455  name = static_cast<LIB_PIN*>( m_Comp )->GetName();
456 
457  if( name == "~" ) //empty name
458  name = wxEmptyString;
459  }
460 
461  return name;
462 }
EDA_ITEM * m_Comp
const char * name
Definition: DXF_plotter.cpp:60
NETLIST_ITEM m_Type

References m_Comp, m_Type, name, and PIN.

◆ GetPinNumText()

const wxString& NETLIST_OBJECT::GetPinNumText ( ) const
inline

returns a pin number in wxString form.

Pin numbers are not always numbers. "A23" would be a valid pin number.

Definition at line 183 of file netlist_object.h.

184  {
185  return m_PinNum;
186  }

References m_PinNum.

◆ GetShortNetName()

wxString NETLIST_OBJECT::GetShortNetName ( ) const

Function GetShortNetName.

return the short net name of the item i.e.

Returns
the short net name of the item i.e. the net name from the "best" label without any prefix. 2 different nets can have the same short name

the net name from the "best" label without any prefix. 2 different nets can have the same short name

Definition at line 398 of file netlist_object.cpp.

399 {
400  if( m_netNameCandidate == NULL )
401  return wxEmptyString;
402 
403  wxString netName;
404 
406  {
408  if( link ) // Should be always true
409  {
410  netName = wxT("Net-(");
411  netName << link->GetRef( &m_netNameCandidate->m_SheetPath );
412  netName << wxT("-Pad") << m_netNameCandidate->m_PinNum << wxT(")");
413  }
414  }
415  else
416  netName = m_netNameCandidate->m_Label;
417 
418  return netName;
419 }
SCH_COMPONENT * GetComponentParent() const
For Pins (NET_PINS):
NETLIST_OBJECT * m_netNameCandidate
SCH_SHEET_PATH m_SheetPath
#define NULL
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false)
Return the reference for the given sheet path.
Schematic symbol object.
Definition: sch_component.h:88
NETLIST_ITEM m_Type

References GetComponentParent(), SCH_COMPONENT::GetRef(), m_Label, m_netNameCandidate, m_PinNum, m_SheetPath, m_Type, NULL, and PIN.

Referenced by NETLIST_OBJECT_LIST::findBestNetNameForEachNet(), and GetNetName().

◆ HasNetNameCandidate()

bool NETLIST_OBJECT::HasNetNameCandidate ( )
inline
Returns
true if an item has already a net name candidate and false if not ( m_netNameCandidate == NULL )

Definition at line 177 of file netlist_object.h.

177 { return m_netNameCandidate != NULL; }
NETLIST_OBJECT * m_netNameCandidate
#define NULL

References m_netNameCandidate, and NULL.

Referenced by NETLIST_OBJECT_LIST::findBestNetNameForEachNet().

◆ IsLabelBusMemberType()

bool NETLIST_OBJECT::IsLabelBusMemberType ( ) const

Function IsLabelBusMemberType.

Returns
true if the object is a bus label member build from a schematic bus label (like label[xx..yy], xx and yy are the first and last bus member id) bus label members have specific properties: they do not live in schematic they have specific properties in connections: 2 bus label members can be connected connected only if they have the same member value.

Definition at line 355 of file netlist_object.cpp.

356 {
357  // return true if the object is a bus label member build from a
358  // schematic bus label (like label[xx..yy)
359  // They are labels with very specific properties, especially for connection
360  // between them: 2 bus label members can be connected only
361  // if they have the same member value.
366 }
NETLIST_ITEM m_Type

References BUSLABELMEMBER, GLOBBUSLABELMEMBER, HIERBUSLABELMEMBER, m_Type, and SHEETBUSLABELMEMBER.

Referenced by NETLIST_OBJECT_LIST::connectBusLabels().

◆ IsLabelConnected()

bool NETLIST_OBJECT::IsLabelConnected ( NETLIST_OBJECT aNetItem)

Function IsLabelConnected tests if the net list object is a hierarchical label or sheet label and is connected to an associated hierarchical label or sheet label of aNetItem.

Parameters
aNetItemA pointer to a NETLIST_OBJECT to test against.
Returns
A bool value of true if there is a connection with aNetItem or false if no connection to aNetItem.

Definition at line 198 of file netlist_object.cpp.

199 {
200  if( aNetItem == this ) // Don't compare the same net list object.
201  return false;
202 
203  NETLIST_ITEM at = m_Type;
204  NETLIST_ITEM bt = aNetItem->m_Type;
205 
208  {
209  if( m_SheetPath == aNetItem->m_SheetPathInclude )
210  {
211  return true; //connected!
212  }
213  }
214  else if( ( at == NETLIST_ITEM::GLOBLABEL ) && ( bt == NETLIST_ITEM::GLOBLABEL ) )
215  {
216  if( m_Label == aNetItem->m_Label )
217  return true; //connected!
218  }
219 
220  return false; //these two are unconnected
221 }
SCH_SHEET_PATH m_SheetPathInclude
SCH_SHEET_PATH m_SheetPath
NETLIST_ITEM
NETLIST_ITEM m_Type

References GLOBLABEL, HIERBUSLABELMEMBER, HIERLABEL, m_Label, m_SheetPath, m_SheetPathInclude, m_Type, SHEETBUSLABELMEMBER, and SHEETLABEL.

◆ IsLabelGlobal()

bool NETLIST_OBJECT::IsLabelGlobal ( ) const

Function IsLabelGlobal.

Returns
true if the object is a global label (i.e. an real global label or a pin label coming from a power pin invisible

Definition at line 345 of file netlist_object.cpp.

346 {
347  // return true if the object is a global label
348  // * a actual global label
349  // * a pin label coming from a invisible power pin
352 }
NETLIST_ITEM m_Type

References GLOBBUSLABELMEMBER, GLOBLABEL, m_Type, and PINLABEL.

Referenced by countIndenticalLabels(), evalLabelsPriority(), GetNetName(), and NETLIST_OBJECT_LIST::TestforSimilarLabels().

◆ IsLabelType()

◆ SetConnectionType()

void NETLIST_OBJECT::SetConnectionType ( NET_CONNECTION  aFlg = NET_CONNECTION::UNCONNECTED)
inline

Set the item connection type: UNCONNECTED Pin or Label not connected (error) NOCONNECT_SYMBOL_PRESENT Pin not connected but have a NoConnect symbol on it (no error) PAD_CONNECT Normal connection (no error)

Definition at line 153 of file netlist_object.h.

154  {
155  m_ConnectionType = aFlg;
156  }
NET_CONNECTION m_ConnectionType

References m_ConnectionType.

Referenced by NETLIST_OBJECT_LIST::ResetConnectionsType(), and NETLIST_OBJECT_LIST::SetConnectionType().

◆ SetNet()

◆ SetNetNameCandidate()

void NETLIST_OBJECT::SetNetNameCandidate ( NETLIST_OBJECT aCandidate)

Set m_netNameCandidate to a connected item which will be used to calcule the net name of the item Obviously the candidate can be only a label when there is no label on the net a pad which will used to build a net name (something like Cmp<REF>_Pad<PAD_NAME>

Set m_netNameCandidate to a connected item which will be used to calcule the net name of the item Obviously the candidate can be only a label If there is no label on the net, a pad name will be used to build a net name (something like Cmp<REF>_Pad<PAD_NAME>

Parameters
aCandidate= the connected item candidate

Definition at line 429 of file netlist_object.cpp.

430 {
431  switch( aCandidate->m_Type )
432  {
434  case NETLIST_ITEM::LABEL:
439  case NETLIST_ITEM::PIN:
440  m_netNameCandidate = aCandidate;
441  break;
442 
443  default:
444  break;
445  }
446 }
NETLIST_OBJECT * m_netNameCandidate
NETLIST_ITEM m_Type

References GLOBBUSLABELMEMBER, GLOBLABEL, HIERLABEL, LABEL, m_netNameCandidate, m_Type, PIN, PINLABEL, and SHEETBUSLABELMEMBER.

Referenced by NETLIST_OBJECT_LIST::findBestNetNameForEachNet().

Member Data Documentation

◆ m_BusNetCode

◆ m_Comp

◆ m_ConnectionType

NET_CONNECTION NETLIST_OBJECT::m_ConnectionType

◆ m_ElectricalPinType

ELECTRICAL_PINTYPE NETLIST_OBJECT::m_ElectricalPinType

◆ m_End

◆ m_Flag

int NETLIST_OBJECT::m_Flag

Definition at line 105 of file netlist_object.h.

Referenced by NETLIST_OBJECT().

◆ m_Label

◆ m_Link

◆ m_Member

int NETLIST_OBJECT::m_Member

◆ m_netCode

int NETLIST_OBJECT::m_netCode
private

Definition at line 120 of file netlist_object.h.

Referenced by GetNet(), NETLIST_OBJECT(), and SetNet().

◆ m_netNameCandidate

NETLIST_OBJECT* NETLIST_OBJECT::m_netNameCandidate
private

◆ m_PinNum

wxString NETLIST_OBJECT::m_PinNum

◆ m_SheetPath

◆ m_SheetPathInclude

◆ m_Start

◆ m_Type


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