KiCad PCB EDA Suite
SCH_CONNECTION Class Reference

Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net). More...

#include <sch_connection.h>

Public Member Functions

 SCH_CONNECTION (SCH_ITEM *aParent=nullptr, SCH_SHEET_PATH aPath=SCH_SHEET_PATH())
 
 ~SCH_CONNECTION ()
 
bool operator== (const SCH_CONNECTION &aOther) const
 Note: the equality operator for SCH_CONNECTION only tests the net properties, not the ownership / sheet location! More...
 
bool operator!= (const SCH_CONNECTION &aOther) const
 
void ConfigureFromLabel (wxString aLabel)
 Configures the connection given a label. More...
 
void Reset ()
 Clears connectivity information. More...
 
void Clone (SCH_CONNECTION &aOther)
 Copies connectivity information (but not parent) from another connection. More...
 
SCH_ITEMParent () const
 
SCH_ITEMDriver () const
 
SCH_SHEET_PATH Sheet () const
 
void SetDriver (SCH_ITEM *aItem)
 
void SetSheet (SCH_SHEET_PATH aSheet)
 
bool IsDriver () const
 Checks if the SCH_ITEM this connection is attached to can drive connections Drivers can be labels, sheet pins, or component pins. More...
 
bool IsBus () const
 
bool IsNet () const
 
bool IsDirty () const
 
void SetDirty ()
 
void ClearDirty ()
 
wxString Name (bool aIgnoreSheet=false) const
 
wxString RawName () const
 
wxString LocalName () const
 
void SetName (const wxString &aName)
 
wxString Prefix () const
 
wxString Suffix () const
 
void SetPrefix (const wxString &aPrefix)
 
void SetSuffix (const wxString &aSuffix)
 
CONNECTION_TYPE Type () const
 
void SetType (CONNECTION_TYPE aType)
 
int NetCode () const
 
void SetNetCode (int aCode)
 
int BusCode () const
 
void SetBusCode (int aCode)
 
int SubgraphCode () const
 
void SetSubgraphCode (int aCode)
 
long VectorStart () const
 
long VectorEnd () const
 
long VectorIndex () const
 
wxString VectorPrefix () const
 
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members ()
 
const std::vector< std::shared_ptr< SCH_CONNECTION > > & Members () const
 
bool IsSubsetOf (SCH_CONNECTION *aOther) const
 Returns true if aOther is a subset of this connection or vice versa. More...
 
bool IsMemberOfBus (SCH_CONNECTION *aOther) const
 Returns true if this connection is a member of bus connection aOther. More...
 
bool ParseBusVector (wxString aBus, wxString *aName, std::vector< wxString > &aMemberList) const
 Parses a bus vector (e.g. More...
 
bool ParseBusGroup (wxString aGroup, wxString *name, std::vector< wxString > &aMemberList) const
 Parses a bus group label into the name and a list of components. More...
 
void AppendInfoToMsgPanel (MSG_PANEL_ITEMS &aList) const
 Adds information about the connection object to aList. More...
 
void AppendDebugInfoToMsgPanel (MSG_PANEL_ITEMS &aList) const
 Adds extended debug information about the connection object to aList. More...
 

Static Public Member Functions

static bool IsBusLabel (const wxString &aLabel)
 Test if aLabel has a bus notation. More...
 
static bool IsBusVectorLabel (const wxString &aLabel)
 Test if aLabel has a bus vector notation (simple bus, e.g. More...
 
static bool IsBusGroupLabel (const wxString &aLabel)
 Test if aLabel has a bus group notation. More...
 

Private Attributes

bool m_dirty
 
SCH_SHEET_PATH m_sheet
 The hierarchical sheet this connection is on. More...
 
SCH_ITEMm_parent
 The SCH_ITEM this connection is owned by. More...
 
SCH_ITEMm_driver
 The SCH_ITEM that drives this connection's net. More...
 
CONNECTION_TYPE m_type
 
wxString m_name
 Name of the connection. More...
 
wxString m_local_name
 For bus members, we want to keep track of the "local" name of a member, that is, the name it takes on from its parent bus name. More...
 
wxString m_prefix
 
wxString m_suffix
 Name suffix (used only for disambiguation) More...
 
int m_net_code
 
int m_bus_code
 
int m_subgraph_code
 Groups directly-connected items. More...
 
long m_vector_index
 Index of bus vector member nets. More...
 
long m_vector_start
 Highest member of a vector bus. More...
 
long m_vector_end
 Lowest member of a vector bus. More...
 
wxString m_vector_prefix
 
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members
 For bus connections, store a list of member connections. More...
 

Detailed Description

Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).

These are generated when netlisting, or when editing operations that can change the netlist are performed.

In hierarchical schematics, a single SCH_ITEM object can refer to multiple distinct parts of a design (in the case of a sub-sheet that is instanced more than once in a higher level sheet). Because of this, a single item may contain more than one SCH_CONNECTION – each is specific to a sheet.

Components contain connections for each of their pins (and for each sheet they exist on) but don't use their own connection object.

Definition at line 60 of file sch_connection.h.

Constructor & Destructor Documentation

◆ SCH_CONNECTION()

SCH_CONNECTION::SCH_CONNECTION ( SCH_ITEM aParent = nullptr,
SCH_SHEET_PATH  aPath = SCH_SHEET_PATH() 
)

Definition at line 65 of file sch_connection.cpp.

65  :
66  m_sheet( aPath ),
67  m_parent( aParent )
68 {
69  Reset();
70 }
void Reset()
Clears connectivity information.
SCH_SHEET_PATH m_sheet
The hierarchical sheet this connection is on.
SCH_ITEM * m_parent
The SCH_ITEM this connection is owned by.

References Reset().

◆ ~SCH_CONNECTION()

SCH_CONNECTION::~SCH_CONNECTION ( )
inline

Definition at line 65 of file sch_connection.h.

66  {}

Member Function Documentation

◆ AppendDebugInfoToMsgPanel()

void SCH_CONNECTION::AppendDebugInfoToMsgPanel ( MSG_PANEL_ITEMS aList) const

Adds extended debug information about the connection object to aList.

Definition at line 364 of file sch_connection.cpp.

365 {
366  if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
367  return;
368 
369  // These messages are not flagged as translatable, because they are only debug messages
370  wxString msg;
371 
372  AppendInfoToMsgPanel( aList );
373 
374  if( IsBus() )
375  {
376  msg.Printf( "%d", m_bus_code );
377  aList.push_back( MSG_PANEL_ITEM( "Bus Code", msg, BROWN ) );
378  }
379 
380  msg.Printf( "%d", m_subgraph_code );
381  aList.push_back( MSG_PANEL_ITEM( "Subgraph Code", msg, BROWN ) );
382 
383  if( auto driver = Driver() )
384  {
385  msg.Printf( "%s at %p", driver->GetSelectMenuText( EDA_UNITS::MILLIMETRES ), driver );
386  aList.push_back( MSG_PANEL_ITEM( "Connection Source", msg, RED ) );
387  }
388 }
int m_subgraph_code
Groups directly-connected items.
SCH_ITEM * Driver() const
Definition: colors.h:60
static bool m_allowRealTime
void AppendInfoToMsgPanel(MSG_PANEL_ITEMS &aList) const
Adds information about the connection object to aList.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
bool IsBus() const
Definition: colors.h:62

References AppendInfoToMsgPanel(), BROWN, Driver(), ADVANCED_CFG::GetCfg(), IsBus(), CONNECTION_GRAPH::m_allowRealTime, m_bus_code, m_subgraph_code, MILLIMETRES, and RED.

Referenced by LIB_PIN::GetMsgPanelInfo().

◆ AppendInfoToMsgPanel()

void SCH_CONNECTION::AppendInfoToMsgPanel ( MSG_PANEL_ITEMS aList) const

Adds information about the connection object to aList.

Definition at line 312 of file sch_connection.cpp.

313 {
314  if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
315  return;
316 
317  wxString msg, group_name;
318  std::vector<wxString> group_members;
319 
320  aList.push_back( MSG_PANEL_ITEM( _( "Connection Name" ), UnescapeString( Name() ), BROWN ) );
321 
322  // NOTE(JE) Disabling this for now, because net codes are generated in the netlist exporter
323  // in order to avoid sort costs. It may make sense to just tear out net codes from the
324  // CONNECTION_GRAPH entirely in the future, as they are mostly only useful for netlist exports.
325 #if 0
326  if( !IsBus() )
327  {
328  msg.Printf( "%d", m_net_code );
329  aList.push_back( MSG_PANEL_ITEM( _( "Net Code" ), msg, BROWN ) );
330  }
331 #endif
332 
333  if( auto alias = g_ConnectionGraph->GetBusAlias( m_name ) )
334  {
335  msg.Printf( _( "Bus Alias %s Members" ), m_name );
336 
337  wxString members;
338 
339  for( const auto& member : alias->Members() )
340  members << member << " ";
341 
342  aList.push_back( MSG_PANEL_ITEM( msg, members, RED ) );
343  }
344  else if( ParseBusGroup( m_name, &group_name, group_members ) )
345  {
346  for( const auto& group_member : group_members )
347  {
348  if( auto group_alias = g_ConnectionGraph->GetBusAlias( group_member ) )
349  {
350  msg.Printf( _( "Bus Alias %s Members" ), group_alias->GetName() );
351 
352  wxString members;
353 
354  for( const auto& member : group_alias->Members() )
355  members << member << " ";
356 
357  aList.push_back( MSG_PANEL_ITEM( msg, members, RED ) );
358  }
359  }
360  }
361 }
std::shared_ptr< BUS_ALIAS > GetBusAlias(const wxString &aName)
Returns a bus alias pointer for the given name if it exists (from cache)
wxString m_name
Name of the connection.
CONNECTION_GRAPH * g_ConnectionGraph
This also wants to live in the eventual SCHEMATIC object.
wxString Name(bool aIgnoreSheet=false) const
Definition: colors.h:60
bool ParseBusGroup(wxString aGroup, wxString *name, std::vector< wxString > &aMemberList) const
Parses a bus group label into the name and a list of components.
static bool m_allowRealTime
#define _(s)
Definition: 3d_actions.cpp:31
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
bool IsBus() const
Definition: colors.h:62

References _, BROWN, g_ConnectionGraph, CONNECTION_GRAPH::GetBusAlias(), ADVANCED_CFG::GetCfg(), IsBus(), CONNECTION_GRAPH::m_allowRealTime, m_name, m_net_code, Name(), ParseBusGroup(), RED, and UnescapeString().

Referenced by AppendDebugInfoToMsgPanel().

◆ BusCode()

int SCH_CONNECTION::BusCode ( ) const
inline

Definition at line 196 of file sch_connection.h.

197  {
198  return m_bus_code;
199  }

References m_bus_code.

Referenced by Clone().

◆ ClearDirty()

void SCH_CONNECTION::ClearDirty ( )
inline

Definition at line 143 of file sch_connection.h.

144  {
145  m_dirty = false;
146  }

References m_dirty.

Referenced by CONNECTION_GRAPH::buildConnectionGraph().

◆ Clone()

void SCH_CONNECTION::Clone ( SCH_CONNECTION aOther)

Copies connectivity information (but not parent) from another connection.

Parameters
aOtheris the connection to clone

Definition at line 203 of file sch_connection.cpp.

204 {
205  m_type = aOther.Type();
206  m_driver = aOther.Driver();
207  m_sheet = aOther.Sheet();
208  m_name = aOther.m_name;
209  // Note: m_local_name is not cloned
210  m_prefix = aOther.Prefix();
211  m_suffix = aOther.Suffix();
212  m_members = aOther.Members();
213  m_net_code = aOther.NetCode();
214  m_bus_code = aOther.BusCode();
215  m_vector_start = aOther.VectorStart();
216  m_vector_end = aOther.VectorEnd();
217  // Note: m_vector_index is not cloned
218  m_vector_prefix = aOther.VectorPrefix();
219 
220  // Note: subgraph code isn't cloned, it should remain with the original object
221 }
wxString Prefix() const
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members
For bus connections, store a list of member connections.
wxString m_name
Name of the connection.
SCH_ITEM * m_driver
The SCH_ITEM that drives this connection's net.
int BusCode() const
CONNECTION_TYPE m_type
int NetCode() const
wxString Suffix() const
long VectorEnd() const
SCH_ITEM * Driver() const
SCH_SHEET_PATH m_sheet
The hierarchical sheet this connection is on.
wxString m_suffix
Name suffix (used only for disambiguation)
SCH_SHEET_PATH Sheet() const
long m_vector_start
Highest member of a vector bus.
wxString VectorPrefix() const
long VectorStart() const
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members()
long m_vector_end
Lowest member of a vector bus.
wxString m_vector_prefix
CONNECTION_TYPE Type() const

References BusCode(), Driver(), m_bus_code, m_driver, m_members, m_name, m_net_code, m_prefix, m_sheet, m_suffix, m_type, m_vector_end, m_vector_prefix, m_vector_start, Members(), NetCode(), Prefix(), Sheet(), Suffix(), Type(), VectorEnd(), VectorPrefix(), and VectorStart().

Referenced by CONNECTION_GRAPH::buildConnectionGraph(), and CONNECTION_GRAPH::propagateToNeighbors().

◆ ConfigureFromLabel()

void SCH_CONNECTION::ConfigureFromLabel ( wxString  aLabel)

Configures the connection given a label.

For CONNECTION_NET, this just sets the name. For CONNECTION_BUS, this will deduce the correct BUS_TYPE and also generate a correct list of members.

Definition at line 112 of file sch_connection.cpp.

113 {
114  m_members.clear();
115 
116  m_name = aLabel;
117  m_local_name = aLabel;
118 
119  wxString unescaped = UnescapeString( aLabel );
120 
121  if( IsBusVectorLabel( unescaped ) )
122  {
124 
125  std::vector<wxString> members;
126 
127  ParseBusVector( unescaped, &m_vector_prefix, members );
128  long i = 0;
129 
130  for( const auto& vector_member : members )
131  {
132  auto member = std::make_shared<SCH_CONNECTION>( m_parent, m_sheet );
133  member->m_type = CONNECTION_TYPE::NET;
134  member->m_prefix = m_prefix;
135  member->m_name = vector_member;
136  member->m_local_name = vector_member;
137  member->m_vector_index = i++;
138  m_members.push_back( member );
139  }
140  }
141  else if( IsBusGroupLabel( unescaped ) )
142  {
144 
145  std::vector<wxString> members;
146  wxString group_name;
147 
148  if( ParseBusGroup( unescaped, &group_name, members ) )
149  {
150  // Named bus groups generate a net prefix, unnamed ones don't
151  wxString prefix = group_name != wxT( "" ) ? ( group_name + wxT( "." ) ) : wxT( "" );
152 
153  for( const auto& group_member : members )
154  {
155  // Handle alias inside bus group member list
156  if( auto alias = g_ConnectionGraph->GetBusAlias( group_member ) )
157  {
158  for( const auto& alias_member : alias->Members() )
159  {
160  auto member = std::make_shared< SCH_CONNECTION >( m_parent, m_sheet );
161  member->SetPrefix( prefix );
162  member->ConfigureFromLabel( alias_member );
163  m_members.push_back( member );
164  }
165  }
166  else
167  {
168  auto member = std::make_shared< SCH_CONNECTION >( m_parent, m_sheet );
169  member->SetPrefix( prefix );
170  member->ConfigureFromLabel( group_member );
171  m_members.push_back( member );
172  }
173  }
174  }
175  }
176  else
177  {
179  }
180 }
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members
For bus connections, store a list of member connections.
std::shared_ptr< BUS_ALIAS > GetBusAlias(const wxString &aName)
Returns a bus alias pointer for the given name if it exists (from cache)
wxString m_name
Name of the connection.
This item represents a bus group.
CONNECTION_GRAPH * g_ConnectionGraph
This also wants to live in the eventual SCHEMATIC object.
CONNECTION_TYPE m_type
static bool IsBusVectorLabel(const wxString &aLabel)
Test if aLabel has a bus vector notation (simple bus, e.g.
bool ParseBusGroup(wxString aGroup, wxString *name, std::vector< wxString > &aMemberList) const
Parses a bus group label into the name and a list of components.
SCH_SHEET_PATH m_sheet
The hierarchical sheet this connection is on.
This item represents a net.
wxString m_local_name
For bus members, we want to keep track of the "local" name of a member, that is, the name it takes on...
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
bool ParseBusVector(wxString aBus, wxString *aName, std::vector< wxString > &aMemberList) const
Parses a bus vector (e.g.
static bool IsBusGroupLabel(const wxString &aLabel)
Test if aLabel has a bus group notation.
wxString m_vector_prefix
SCH_ITEM * m_parent
The SCH_ITEM this connection is owned by.
This item represents a bus vector.

References BUS, BUS_GROUP, g_ConnectionGraph, CONNECTION_GRAPH::GetBusAlias(), IsBusGroupLabel(), IsBusVectorLabel(), m_local_name, m_members, m_name, m_parent, m_prefix, m_sheet, m_type, m_vector_prefix, NET, ParseBusGroup(), ParseBusVector(), and UnescapeString().

Referenced by CONNECTION_GRAPH::buildConnectionGraph(), CONNECTION_GRAPH::ercCheckBusToNetConflicts(), and DIALOG_MIGRATE_BUSES::getProposedLabels().

◆ Driver()

SCH_ITEM* SCH_CONNECTION::Driver ( ) const
inline

Definition at line 101 of file sch_connection.h.

102  {
103  return m_driver;
104  }
SCH_ITEM * m_driver
The SCH_ITEM that drives this connection's net.

References m_driver.

Referenced by AppendDebugInfoToMsgPanel(), and Clone().

◆ IsBus()

◆ IsBusGroupLabel()

bool SCH_CONNECTION::IsBusGroupLabel ( const wxString &  aLabel)
static

Test if aLabel has a bus group notation.

Parameters
aLabelA wxString object containing the label to test.
Returns
true if text is a bus group notation format

Definition at line 410 of file sch_connection.cpp.

411 {
412  try
413  {
414  return std::regex_match( std::string( aLabel.mb_str() ), bus_group_label_re );
415  }
416  catch( ... )
417  {
418  return false;
419  }
420 }
static std::regex bus_group_label_re("^([^[:space:]]+)?\\{((?:[^[:space:]]+(?:\\[[\\d]+\\.+[\\d]+\\])? ?)+)\\}$")

References bus_group_label_re().

Referenced by ConfigureFromLabel(), NETLIST_OBJECT::ConvertBusToNetListItems(), IsBusLabel(), and SCH_NETNAME_VALIDATOR::IsValid().

◆ IsBusLabel()

bool SCH_CONNECTION::IsBusLabel ( const wxString &  aLabel)
static

Test if aLabel has a bus notation.

Parameters
aLabelA wxString object containing the label to test.
Returns
true if text is a bus notation format otherwise false is returned.

Definition at line 391 of file sch_connection.cpp.

392 {
393  return IsBusVectorLabel( aLabel ) || IsBusGroupLabel( aLabel );
394 }
static bool IsBusVectorLabel(const wxString &aLabel)
Test if aLabel has a bus vector notation (simple bus, e.g.
static bool IsBusGroupLabel(const wxString &aLabel)
Test if aLabel has a bus group notation.

References IsBusGroupLabel(), and IsBusVectorLabel().

Referenced by SCH_BUS_WIRE_ENTRY::ConnectionPropagatesTo(), NETLIST_OBJECT::ConvertBusToNetListItems(), SCH_TEXT::GetNetListItem(), SCH_SHEET::GetNetListItem(), and SCH_SCREEN::IsTerminalPoint().

◆ IsBusVectorLabel()

bool SCH_CONNECTION::IsBusVectorLabel ( const wxString &  aLabel)
static

Test if aLabel has a bus vector notation (simple bus, e.g.

A[7..0])

Parameters
aLabelA wxString object containing the label to test.
Returns
true if text is a bus notation format otherwise false is returned.

Definition at line 397 of file sch_connection.cpp.

398 {
399  try
400  {
401  return std::regex_match( std::string( aLabel.mb_str() ), bus_label_re );
402  }
403  catch( ... )
404  {
405  return false;
406  }
407 }
static std::regex bus_label_re("^([^[:space:]]+)(\\[[\\d]+\\.+[\\d]+\\])(~?)$")
Buses can be defined in multiple ways.

References bus_label_re().

Referenced by ConfigureFromLabel(), NETLIST_OBJECT::ConvertBusToNetListItems(), IsBusLabel(), SCH_NETNAME_VALIDATOR::IsValid(), and SCH_EAGLE_PLUGIN::translateEagleBusName().

◆ IsDirty()

bool SCH_CONNECTION::IsDirty ( ) const
inline

Definition at line 133 of file sch_connection.h.

134  {
135  return m_dirty;
136  }

References m_dirty.

◆ IsDriver()

bool SCH_CONNECTION::IsDriver ( ) const

Checks if the SCH_ITEM this connection is attached to can drive connections Drivers can be labels, sheet pins, or component pins.

Returns
true if the attached items is a driver

Definition at line 224 of file sch_connection.cpp.

225 {
226  wxASSERT( Parent() );
227 
228  switch( Parent()->Type() )
229  {
230  case SCH_LABEL_T:
231  case SCH_GLOBAL_LABEL_T:
232  case SCH_HIER_LABEL_T:
233  case SCH_SHEET_PIN_T:
234  case SCH_SHEET_T:
235  case LIB_PIN_T:
236  return true;
237 
238  case SCH_PIN_T:
239  {
240  auto pin = static_cast<SCH_PIN*>( Parent() );
241 
242  // Only annotated components should drive nets
243  return ( pin->IsPowerConnection()
244  || pin->GetParentComponent()->IsAnnotated( &m_sheet ) );
245  }
246 
247  default:
248  return false;
249  }
250 }
SCH_SHEET_PATH m_sheet
The hierarchical sheet this connection is on.
SCH_ITEM * Parent() const
CONNECTION_TYPE Type() const

References LIB_PIN_T, m_sheet, Parent(), SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_LABEL_T, SCH_PIN_T, SCH_SHEET_PIN_T, SCH_SHEET_T, and Type().

Referenced by CONNECTION_SUBGRAPH::AddItem().

◆ IsMemberOfBus()

bool SCH_CONNECTION::IsMemberOfBus ( SCH_CONNECTION aOther) const

Returns true if this connection is a member of bus connection aOther.

Will always return false if aOther is not a bus connection

Definition at line 551 of file sch_connection.cpp.

552 {
553  if( !aOther->IsBus() )
554  return false;
555 
556  auto me = Name( true );
557 
558  for( const auto& m : aOther->Members() )
559  if( m->Name( true ) == me )
560  return true;
561 
562  return false;
563 }
wxString Name(bool aIgnoreSheet=false) const
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members()
bool IsBus() const

References IsBus(), Members(), and Name().

◆ IsNet()

bool SCH_CONNECTION::IsNet ( ) const
inline

Definition at line 128 of file sch_connection.h.

129  {
130  return ( m_type == CONNECTION_TYPE::NET );
131  }
CONNECTION_TYPE m_type
This item represents a net.

References m_type, and NET.

Referenced by CONNECTION_GRAPH::buildConnectionGraph(), IsSubsetOf(), and CONNECTION_SUBGRAPH::UpdateItemConnections().

◆ IsSubsetOf()

bool SCH_CONNECTION::IsSubsetOf ( SCH_CONNECTION aOther) const

Returns true if aOther is a subset of this connection or vice versa.

For plain nets, this just tests whether or not the connectio names are the same. For buses, this tests whether the two have any shared members.

Will always return false if one connection is a bus and the other a net.

Definition at line 525 of file sch_connection.cpp.

526 {
527  if( aOther->IsNet() )
528  return IsNet() ? ( aOther->Name( true ) == Name( true ) ) : false;
529 
530  if( !IsBus() )
531  return false;
532 
533  std::vector<wxString> mine, theirs;
534 
535  for( const auto& m : Members() )
536  mine.push_back( m->Name( true ) );
537 
538  for( const auto& m : aOther->Members() )
539  theirs.push_back( m->Name( true ) );
540 
541  std::set<wxString> subset;
542 
543  std::set_intersection( mine.begin(), mine.end(),
544  theirs.begin(), theirs.end(),
545  std::inserter(subset, subset.begin() ) );
546 
547  return ( !subset.empty() );
548 }
wxString Name(bool aIgnoreSheet=false) const
bool IsNet() const
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members()
bool IsBus() const

References IsBus(), IsNet(), Members(), and Name().

◆ LocalName()

wxString SCH_CONNECTION::LocalName ( ) const
inline

Definition at line 155 of file sch_connection.h.

155 { return m_local_name; }
wxString m_local_name
For bus members, we want to keep track of the "local" name of a member, that is, the name it takes on...

References m_local_name.

Referenced by CONNECTION_GRAPH::propagateToNeighbors().

◆ Members() [1/2]

std::vector< std::shared_ptr< SCH_CONNECTION > >& SCH_CONNECTION::Members ( )
inline

Definition at line 236 of file sch_connection.h.

237  {
238  return m_members;
239  }
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members
For bus connections, store a list of member connections.

References m_members.

Referenced by CONNECTION_GRAPH::assignNetCodesToBus(), Clone(), CONNECTION_GRAPH::ercCheckBusToBusConflicts(), CONNECTION_GRAPH::ercCheckBusToBusEntryConflicts(), IsMemberOfBus(), IsSubsetOf(), CONNECTION_GRAPH::matchBusMember(), SetPrefix(), SetSuffix(), and BUS_UNFOLD_MENU::update().

◆ Members() [2/2]

const std::vector< std::shared_ptr< SCH_CONNECTION > >& SCH_CONNECTION::Members ( ) const
inline

Definition at line 241 of file sch_connection.h.

242  {
243  return m_members;
244  }
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members
For bus connections, store a list of member connections.

References m_members.

◆ Name()

wxString SCH_CONNECTION::Name ( bool  aIgnoreSheet = false) const

Definition at line 253 of file sch_connection.cpp.

254 {
255  wxString ret = m_prefix + m_name + m_suffix;
256 
257  if( m_name.IsEmpty() )
258  ret = "<NO NET>";
259 
260  if( !Parent() || m_type == CONNECTION_TYPE::NONE )
261  return ret;
262 
263  if( !aIgnoreSheet )
264  {
265  bool prepend_path = true;
266 
267  if( m_driver )
268  {
269  switch( m_driver->Type() )
270  {
271  case SCH_PIN_T:
272  // Pins are either power connections or belong to a uniquely-annotated
273  // component, so they don't need a path if they are driving the subgraph
274  prepend_path = false;
275  break;
276 
277  case SCH_GLOBAL_LABEL_T:
278  prepend_path = false;
279  break;
280 
281  default:
282  break;
283  }
284  }
285 
286  if( prepend_path )
287  ret = m_sheet.PathHumanReadable() + ret;
288  }
289 
290  return ret;
291 }
wxString m_name
Name of the connection.
SCH_ITEM * m_driver
The SCH_ITEM that drives this connection's net.
CONNECTION_TYPE m_type
No connection to this item.
SCH_SHEET_PATH m_sheet
The hierarchical sheet this connection is on.
wxString m_suffix
Name suffix (used only for disambiguation)
SCH_ITEM * Parent() const
wxString PathHumanReadable() const
Function PathHumanReadable returns the sheet path in a human readable form, i.e.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References m_driver, m_name, m_prefix, m_sheet, m_suffix, m_type, NONE, Parent(), SCH_SHEET_PATH::PathHumanReadable(), SCH_GLOBAL_LABEL_T, SCH_PIN_T, and EDA_ITEM::Type().

Referenced by AppendInfoToMsgPanel(), CONNECTION_GRAPH::assignNewNetCode(), CONNECTION_GRAPH::buildConnectionGraph(), CONNECTION_GRAPH::ercCheckBusToBusEntryConflicts(), CONNECTION_GRAPH::ercCheckNoConnects(), CONNECTION_SUBGRAPH::GetNetName(), highlightNet(), IsMemberOfBus(), IsSubsetOf(), CONNECTION_GRAPH::propagateToNeighbors(), CONNECTION_GRAPH::recacheSubgraphName(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::TransferDataToWindow(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), and DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem().

◆ NetCode()

int SCH_CONNECTION::NetCode ( ) const
inline

Definition at line 186 of file sch_connection.h.

187  {
188  return m_net_code;
189  }

References m_net_code.

Referenced by Clone().

◆ operator!=()

bool SCH_CONNECTION::operator!= ( const SCH_CONNECTION aOther) const

Definition at line 106 of file sch_connection.cpp.

107 {
108  return !( aOther == *this );
109 }

◆ operator==()

bool SCH_CONNECTION::operator== ( const SCH_CONNECTION aOther) const

Note: the equality operator for SCH_CONNECTION only tests the net properties, not the ownership / sheet location!

Definition at line 73 of file sch_connection.cpp.

74 {
75  // NOTE: Not comparing m_dirty or net/bus/subgraph codes
76  if( ( aOther.m_driver == m_driver ) &&
77  ( aOther.m_type == m_type ) &&
78  ( aOther.m_name == m_name ) &&
79  ( aOther.m_sheet == m_sheet ) )
80  {
81  return true;
82  }
83 
84  return false;
85 }
wxString m_name
Name of the connection.
SCH_ITEM * m_driver
The SCH_ITEM that drives this connection's net.
CONNECTION_TYPE m_type
SCH_SHEET_PATH m_sheet
The hierarchical sheet this connection is on.

References m_driver, m_name, m_sheet, and m_type.

◆ Parent()

SCH_ITEM* SCH_CONNECTION::Parent ( ) const
inline

Definition at line 96 of file sch_connection.h.

97  {
98  return m_parent;
99  }
SCH_ITEM * m_parent
The SCH_ITEM this connection is owned by.

References m_parent.

Referenced by IsDriver(), and Name().

◆ ParseBusGroup()

bool SCH_CONNECTION::ParseBusGroup ( wxString  aGroup,
wxString *  name,
std::vector< wxString > &  aMemberList 
) const

Parses a bus group label into the name and a list of components.

Parameters
aGroupis the input label, e.g. "USB{DP DM}"
nameis the output group name, e.g. "USB"
aMemberListis a list of member strings, e.g. "DP", "DM"
Returns
true if aGroup was successfully parsed

Definition at line 495 of file sch_connection.cpp.

497 {
498  auto ss_group = std::string( aGroup.mb_str() );
499  std::smatch matches;
500 
501  try
502  {
503  if( !std::regex_match( ss_group, matches, bus_group_label_re ) )
504  {
505  return false;
506  }
507  }
508  catch( ... )
509  {
510  return false;
511  }
512 
513  *aName = wxString( matches[1] );
514 
515  wxStringTokenizer tokenizer( wxString( matches[2] ), " " );
516  while( tokenizer.HasMoreTokens() )
517  {
518  aMemberList.push_back( tokenizer.GetNextToken() );
519  }
520 
521  return true;
522 }
static std::regex bus_group_label_re("^([^[:space:]]+)?\\{((?:[^[:space:]]+(?:\\[[\\d]+\\.+[\\d]+\\])? ?)+)\\}$")

References bus_group_label_re().

Referenced by AppendInfoToMsgPanel(), ConfigureFromLabel(), and NETLIST_OBJECT::ConvertBusToNetListItems().

◆ ParseBusVector()

bool SCH_CONNECTION::ParseBusVector ( wxString  aBus,
wxString *  aName,
std::vector< wxString > &  aMemberList 
) const

Parses a bus vector (e.g.

A[7..0]) into name, begin, and end. Ensures that begin and end are positive and that end > begin.

Parameters
aBusis a bus vector label string
aNameout is the bus name, e.g. "A"
aMemberListis a list of member strings, e.g. "A7", "A6", and so on
Returns
true if aBus was successfully parsed

Definition at line 423 of file sch_connection.cpp.

425 {
426  auto ss_vector = std::string( aBus.mb_str() );
427  std::smatch matches;
428 
429  try
430  {
431  if( !std::regex_match( ss_vector, matches, bus_label_re ) )
432  return false;
433  }
434  catch( ... )
435  {
436  return false;
437  }
438 
439  long begin = 0, end = 0;
440  *aName = wxString( matches[1] );
441  wxString numberString( matches[2] );
442 
443  // If we have three match groups, it means there was a tilde at the end of the vector
444  bool append_tilde = wxString( matches[3] ).IsSameAs( wxT( "~" ) );
445 
446  // numberString will include the brackets, e.g. [5..0] so skip the first one
447  size_t i = 1, len = numberString.Len();
448  wxString tmp;
449 
450  while( i < len && numberString[i] != '.' )
451  {
452  tmp.Append( numberString[i] );
453  i++;
454  }
455 
456  tmp.ToLong( &begin );
457 
458  while( i < len && numberString[i] == '.' )
459  i++;
460 
461  tmp.Empty();
462 
463  while( i < len && numberString[i] != ']' )
464  {
465  tmp.Append( numberString[i] );
466  i++;
467  }
468 
469  tmp.ToLong( &end );
470 
471  if( begin < 0 )
472  begin = 0;
473 
474  if( end < 0 )
475  end = 0;
476 
477  if( begin > end )
478  std::swap( begin, end );
479 
480  for( long idx = begin; idx <= end; ++idx )
481  {
482  wxString str = *aName;
483  str << idx;
484 
485  if( append_tilde )
486  str << '~';
487 
488  aMemberList.emplace_back( str );
489  }
490 
491  return true;
492 }
static std::regex bus_label_re("^([^[:space:]]+)(\\[[\\d]+\\.+[\\d]+\\])(~?)$")
Buses can be defined in multiple ways.

References bus_label_re().

Referenced by ConfigureFromLabel(), and NETLIST_OBJECT::ConvertBusToNetListItems().

◆ Prefix()

wxString SCH_CONNECTION::Prefix ( ) const
inline

Definition at line 162 of file sch_connection.h.

163  {
164  return m_prefix;
165  }

References m_prefix.

Referenced by Clone().

◆ RawName()

wxString SCH_CONNECTION::RawName ( ) const
inline

Definition at line 150 of file sch_connection.h.

151  {
152  return m_name;
153  }
wxString m_name
Name of the connection.

References m_name.

Referenced by CONNECTION_GRAPH::matchBusMember().

◆ Reset()

void SCH_CONNECTION::Reset ( )

Clears connectivity information.

Definition at line 183 of file sch_connection.cpp.

184 {
186  m_name.Empty();
187  m_local_name.Empty();
188  m_prefix.Empty();
189  m_suffix .Empty();
190  m_driver = nullptr;
191  m_members.clear();
192  m_dirty = true;
193  m_net_code = 0;
194  m_bus_code = 0;
195  m_subgraph_code = 0;
196  m_vector_start = 0;
197  m_vector_end = 0;
198  m_vector_index = 0;
199  m_vector_prefix.Empty();
200 }
int m_subgraph_code
Groups directly-connected items.
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members
For bus connections, store a list of member connections.
wxString m_name
Name of the connection.
SCH_ITEM * m_driver
The SCH_ITEM that drives this connection's net.
CONNECTION_TYPE m_type
No connection to this item.
wxString m_suffix
Name suffix (used only for disambiguation)
wxString m_local_name
For bus members, we want to keep track of the "local" name of a member, that is, the name it takes on...
long m_vector_start
Highest member of a vector bus.
long m_vector_index
Index of bus vector member nets.
long m_vector_end
Lowest member of a vector bus.
wxString m_vector_prefix

References m_bus_code, m_dirty, m_driver, m_local_name, m_members, m_name, m_net_code, m_prefix, m_subgraph_code, m_suffix, m_type, m_vector_end, m_vector_index, m_vector_prefix, m_vector_start, and NONE.

Referenced by SCH_ITEM::InitializeConnection(), and SCH_CONNECTION().

◆ SetBusCode()

void SCH_CONNECTION::SetBusCode ( int  aCode)
inline

Definition at line 201 of file sch_connection.h.

202  {
203  m_bus_code = aCode;
204  }

References m_bus_code.

Referenced by CONNECTION_GRAPH::buildConnectionGraph().

◆ SetDirty()

void SCH_CONNECTION::SetDirty ( )
inline

Definition at line 138 of file sch_connection.h.

139  {
140  m_dirty = true;
141  }

References m_dirty.

◆ SetDriver()

void SCH_CONNECTION::SetDriver ( SCH_ITEM aItem)

Definition at line 88 of file sch_connection.cpp.

89 {
90  m_driver = aItem;
91 
92  for( const auto& member : m_members )
93  member->SetDriver( aItem );
94 }
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members
For bus connections, store a list of member connections.
SCH_ITEM * m_driver
The SCH_ITEM that drives this connection's net.

References m_driver, and m_members.

Referenced by CONNECTION_GRAPH::buildConnectionGraph().

◆ SetName()

void SCH_CONNECTION::SetName ( const wxString &  aName)
inline

Definition at line 157 of file sch_connection.h.

158  {
159  m_name = aName;
160  }
wxString m_name
Name of the connection.

References m_name.

Referenced by CONNECTION_GRAPH::buildConnectionGraph().

◆ SetNetCode()

void SCH_CONNECTION::SetNetCode ( int  aCode)
inline

Definition at line 191 of file sch_connection.h.

192  {
193  m_net_code = aCode;
194  }

References m_net_code.

Referenced by CONNECTION_GRAPH::assignNewNetCode(), and CONNECTION_GRAPH::buildConnectionGraph().

◆ SetPrefix()

void SCH_CONNECTION::SetPrefix ( const wxString &  aPrefix)

Definition at line 294 of file sch_connection.cpp.

295 {
296  m_prefix = aPrefix;
297 
298  for( const auto& m : Members() )
299  m->SetPrefix( aPrefix );
300 }
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members()

References m_prefix, and Members().

◆ SetSheet()

void SCH_CONNECTION::SetSheet ( SCH_SHEET_PATH  aSheet)

Definition at line 97 of file sch_connection.cpp.

98 {
99  m_sheet = aSheet;
100 
101  for( const auto& member : m_members )
102  member->SetSheet( aSheet );
103 }
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members
For bus connections, store a list of member connections.
SCH_SHEET_PATH m_sheet
The hierarchical sheet this connection is on.

References m_members, and m_sheet.

Referenced by SCH_ITEM::InitializeConnection().

◆ SetSubgraphCode()

void SCH_CONNECTION::SetSubgraphCode ( int  aCode)
inline

Definition at line 211 of file sch_connection.h.

212  {
213  m_subgraph_code = aCode;
214  }
int m_subgraph_code
Groups directly-connected items.

References m_subgraph_code.

Referenced by CONNECTION_SUBGRAPH::Absorb(), and CONNECTION_GRAPH::buildConnectionGraph().

◆ SetSuffix()

void SCH_CONNECTION::SetSuffix ( const wxString &  aSuffix)

Definition at line 303 of file sch_connection.cpp.

304 {
305  m_suffix = aSuffix;
306 
307  for( const auto& m : Members() )
308  m->SetSuffix( aSuffix );
309 }
wxString m_suffix
Name suffix (used only for disambiguation)
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members()

References m_suffix, and Members().

Referenced by CONNECTION_GRAPH::buildConnectionGraph().

◆ SetType()

void SCH_CONNECTION::SetType ( CONNECTION_TYPE  aType)
inline

Definition at line 181 of file sch_connection.h.

182  {
183  m_type = aType;
184  }
CONNECTION_TYPE m_type

References m_type.

◆ Sheet()

SCH_SHEET_PATH SCH_CONNECTION::Sheet ( ) const
inline

Definition at line 106 of file sch_connection.h.

107  {
108  return m_sheet;
109  }
SCH_SHEET_PATH m_sheet
The hierarchical sheet this connection is on.

References m_sheet.

Referenced by Clone().

◆ SubgraphCode()

int SCH_CONNECTION::SubgraphCode ( ) const
inline

Definition at line 206 of file sch_connection.h.

207  {
208  return m_subgraph_code;
209  }
int m_subgraph_code
Groups directly-connected items.

References m_subgraph_code.

Referenced by CONNECTION_GRAPH::buildConnectionGraph().

◆ Suffix()

wxString SCH_CONNECTION::Suffix ( ) const
inline

Definition at line 167 of file sch_connection.h.

168  {
169  return m_suffix;
170  }
wxString m_suffix
Name suffix (used only for disambiguation)

References m_suffix.

Referenced by Clone().

◆ Type()

CONNECTION_TYPE SCH_CONNECTION::Type ( ) const
inline

Definition at line 176 of file sch_connection.h.

177  {
178  return m_type;
179  }
CONNECTION_TYPE m_type

References m_type.

Referenced by Clone(), IsDriver(), and CONNECTION_GRAPH::matchBusMember().

◆ VectorEnd()

long SCH_CONNECTION::VectorEnd ( ) const
inline

Definition at line 221 of file sch_connection.h.

222  {
223  return m_vector_end;
224  }
long m_vector_end
Lowest member of a vector bus.

References m_vector_end.

Referenced by Clone(), NETLIST_OBJECT::ConvertBusToNetListItems(), and DIALOG_MIGRATE_BUSES::getProposedLabels().

◆ VectorIndex()

long SCH_CONNECTION::VectorIndex ( ) const
inline

Definition at line 226 of file sch_connection.h.

227  {
228  return m_vector_index;
229  }
long m_vector_index
Index of bus vector member nets.

References m_vector_index.

Referenced by CONNECTION_GRAPH::matchBusMember().

◆ VectorPrefix()

wxString SCH_CONNECTION::VectorPrefix ( ) const
inline

Definition at line 231 of file sch_connection.h.

232  {
233  return m_vector_prefix;
234  }
wxString m_vector_prefix

References m_vector_prefix.

Referenced by Clone(), and DIALOG_MIGRATE_BUSES::getProposedLabels().

◆ VectorStart()

long SCH_CONNECTION::VectorStart ( ) const
inline

Definition at line 216 of file sch_connection.h.

217  {
218  return m_vector_start;
219  }
long m_vector_start
Highest member of a vector bus.

References m_vector_start.

Referenced by Clone(), NETLIST_OBJECT::ConvertBusToNetListItems(), and DIALOG_MIGRATE_BUSES::getProposedLabels().

Member Data Documentation

◆ m_bus_code

int SCH_CONNECTION::m_bus_code
private

Definition at line 350 of file sch_connection.h.

Referenced by AppendDebugInfoToMsgPanel(), BusCode(), Clone(), Reset(), and SetBusCode().

◆ m_dirty

bool SCH_CONNECTION::m_dirty
private

Definition at line 322 of file sch_connection.h.

Referenced by ClearDirty(), IsDirty(), Reset(), and SetDirty().

◆ m_driver

SCH_ITEM* SCH_CONNECTION::m_driver
private

The SCH_ITEM that drives this connection's net.

Definition at line 328 of file sch_connection.h.

Referenced by Clone(), Driver(), Name(), operator==(), Reset(), and SetDriver().

◆ m_local_name

wxString SCH_CONNECTION::m_local_name
private

For bus members, we want to keep track of the "local" name of a member, that is, the name it takes on from its parent bus name.

This is because we always want to use the local name for bus unfolding, matching within buses, etc. The actual resolved name of this bus member might change, for example if it's connected elsewhere to some other item with higher priority.Prefix if connection is member of a labeled bus group (or "" if not)

Definition at line 341 of file sch_connection.h.

Referenced by ConfigureFromLabel(), LocalName(), and Reset().

◆ m_members

std::vector< std::shared_ptr< SCH_CONNECTION > > SCH_CONNECTION::m_members
private

For bus connections, store a list of member connections.

NOTE: All connections that Clone() others share the list of member pointers. This seems fine at the moment.

Definition at line 369 of file sch_connection.h.

Referenced by Clone(), ConfigureFromLabel(), Members(), Reset(), SetDriver(), and SetSheet().

◆ m_name

wxString SCH_CONNECTION::m_name
private

Name of the connection.

Definition at line 332 of file sch_connection.h.

Referenced by AppendInfoToMsgPanel(), Clone(), ConfigureFromLabel(), Name(), operator==(), RawName(), Reset(), and SetName().

◆ m_net_code

int SCH_CONNECTION::m_net_code
private

Definition at line 348 of file sch_connection.h.

Referenced by AppendInfoToMsgPanel(), Clone(), NetCode(), Reset(), and SetNetCode().

◆ m_parent

SCH_ITEM* SCH_CONNECTION::m_parent
private

The SCH_ITEM this connection is owned by.

Definition at line 326 of file sch_connection.h.

Referenced by ConfigureFromLabel(), and Parent().

◆ m_prefix

wxString SCH_CONNECTION::m_prefix
private

Definition at line 344 of file sch_connection.h.

Referenced by Clone(), ConfigureFromLabel(), Name(), Prefix(), Reset(), and SetPrefix().

◆ m_sheet

SCH_SHEET_PATH SCH_CONNECTION::m_sheet
private

The hierarchical sheet this connection is on.

Definition at line 324 of file sch_connection.h.

Referenced by Clone(), ConfigureFromLabel(), IsDriver(), Name(), operator==(), SetSheet(), and Sheet().

◆ m_subgraph_code

int SCH_CONNECTION::m_subgraph_code
private

Groups directly-connected items.

Definition at line 352 of file sch_connection.h.

Referenced by AppendDebugInfoToMsgPanel(), Reset(), SetSubgraphCode(), and SubgraphCode().

◆ m_suffix

wxString SCH_CONNECTION::m_suffix
private

Name suffix (used only for disambiguation)

Definition at line 346 of file sch_connection.h.

Referenced by Clone(), Name(), Reset(), SetSuffix(), and Suffix().

◆ m_type

CONNECTION_TYPE SCH_CONNECTION::m_type
private
See also
enum CONNECTION_TYPE

Definition at line 330 of file sch_connection.h.

Referenced by Clone(), ConfigureFromLabel(), IsBus(), IsNet(), Name(), operator==(), Reset(), SetType(), and Type().

◆ m_vector_end

long SCH_CONNECTION::m_vector_end
private

Lowest member of a vector bus.

Prefix name of the vector, if m_type == CONNECTION_BUS (or "" if not)

Definition at line 358 of file sch_connection.h.

Referenced by Clone(), Reset(), and VectorEnd().

◆ m_vector_index

long SCH_CONNECTION::m_vector_index
private

Index of bus vector member nets.

Definition at line 354 of file sch_connection.h.

Referenced by Reset(), and VectorIndex().

◆ m_vector_prefix

wxString SCH_CONNECTION::m_vector_prefix
private

Definition at line 361 of file sch_connection.h.

Referenced by Clone(), ConfigureFromLabel(), Reset(), and VectorPrefix().

◆ m_vector_start

long SCH_CONNECTION::m_vector_start
private

Highest member of a vector bus.

Definition at line 356 of file sch_connection.h.

Referenced by Clone(), Reset(), and VectorStart().


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