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
 
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 bus. 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 353 of file sch_connection.cpp.

354 {
355  if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
356  return;
357 
358  // These messages are not flagged as translatable, because they are only debug messages
359  wxString msg;
360 
361  AppendInfoToMsgPanel( aList );
362 
363  if( IsBus() )
364  {
365  msg.Printf( "%d", m_bus_code );
366  aList.push_back( MSG_PANEL_ITEM( "Bus Code", msg, BROWN ) );
367  }
368 
369  msg.Printf( "%d", m_subgraph_code );
370  aList.push_back( MSG_PANEL_ITEM( "Subgraph Code", msg, BROWN ) );
371 
372  if( auto driver = Driver() )
373  {
374  msg.Printf( "%s at %p", driver->GetSelectMenuText( MILLIMETRES ), driver );
375  aList.push_back( MSG_PANEL_ITEM( "Connection Source", msg, RED ) );
376  }
377 }
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.
Class 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 306 of file sch_connection.cpp.

307 {
308  if( !ADVANCED_CFG::GetCfg().m_realTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
309  return;
310 
311  wxString msg, group_name;
312  std::vector<wxString> group_members;
313 
314  aList.push_back( MSG_PANEL_ITEM( _( "Connection Name" ), Name(), BROWN ) );
315 
316  if( !IsBus() )
317  {
318  msg.Printf( "%d", m_net_code );
319  aList.push_back( MSG_PANEL_ITEM( _( "Net Code" ), msg, BROWN ) );
320  }
321 
322  if( auto alias = g_ConnectionGraph->GetBusAlias( m_name ) )
323  {
324  msg.Printf( _( "Bus Alias %s Members" ), m_name );
325 
326  wxString members;
327 
328  for( auto member : alias->Members() )
329  members << member << " ";
330 
331  aList.push_back( MSG_PANEL_ITEM( msg, members, RED ) );
332  }
333  else if( ParseBusGroup( m_name, &group_name, group_members ) )
334  {
335  for( auto group_member : group_members )
336  {
337  if( auto group_alias = g_ConnectionGraph->GetBusAlias( group_member ) )
338  {
339  msg.Printf( _( "Bus Alias %s Members" ), group_alias->GetName() );
340 
341  wxString members;
342 
343  for( auto member : group_alias->Members() )
344  members << member << " ";
345 
346  aList.push_back( MSG_PANEL_ITEM( msg, members, RED ) );
347  }
348  }
349  }
350 }
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 bus.
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.
#define _(s)
static bool m_allowRealTime
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
Class 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(), and RED.

Referenced by AppendDebugInfoToMsgPanel().

◆ BusCode()

int SCH_CONNECTION::BusCode ( ) const
inline

Definition at line 194 of file sch_connection.h.

195  {
196  return m_bus_code;
197  }

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 199 of file sch_connection.cpp.

200 {
201  m_type = aOther.Type();
202  m_driver = aOther.Driver();
203  m_sheet = aOther.Sheet();
204  m_name = aOther.m_name;
205  m_prefix = aOther.Prefix();
206  m_suffix = aOther.Suffix();
207  m_members = aOther.Members();
208  m_net_code = aOther.NetCode();
209  m_bus_code = aOther.BusCode();
210  m_vector_start = aOther.VectorStart();
211  m_vector_end = aOther.VectorEnd();
212  m_vector_index = aOther.VectorIndex();
213  m_vector_prefix = aOther.VectorPrefix();
214 
215  // Note: subgraph code isn't cloned, it should remain with the original object
216 }
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 bus.
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
long VectorIndex() 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_index
Index of bus vector member nets.
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_index, m_vector_prefix, m_vector_start, Members(), NetCode(), Prefix(), Sheet(), Suffix(), Type(), VectorEnd(), VectorIndex(), VectorPrefix(), and VectorStart().

Referenced by CONNECTION_GRAPH::buildConnectionGraph().

◆ 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  if( IsBusVectorLabel( aLabel ) )
117  {
118  m_name = aLabel;
120 
121  std::vector<wxString> members;
122 
123  ParseBusVector( aLabel, &m_vector_prefix, members );
124  long i = 0;
125 
126  for( const auto& vector_member : members )
127  {
128  auto member = std::make_shared< SCH_CONNECTION >( m_parent, m_sheet );
129  member->m_type = CONNECTION_NET;
130  member->m_prefix = m_prefix;
131  member->m_name = vector_member;
132  member->m_vector_index = i++;
133  m_members.push_back( member );
134  }
135  }
136  else if( IsBusGroupLabel( aLabel ) )
137  {
139  m_name = aLabel;
140 
141  std::vector<wxString> members;
142  wxString group_name;
143 
144  if( ParseBusGroup( aLabel, &group_name, members ) )
145  {
146  // Named bus groups generate a net prefix, unnamed ones don't
147  wxString prefix = group_name != wxT( "" ) ? ( group_name + wxT( "." ) ) : wxT( "" );
148 
149  for( const auto& group_member : members )
150  {
151  // Handle alias inside bus group member list
152  if( auto alias = g_ConnectionGraph->GetBusAlias( group_member ) )
153  {
154  for( const auto& alias_member : alias->Members() )
155  {
156  auto member = std::make_shared< SCH_CONNECTION >( m_parent, m_sheet );
157  member->SetPrefix( prefix );
158  member->ConfigureFromLabel( alias_member );
159  m_members.push_back( member );
160  }
161  }
162  else
163  {
164  auto member = std::make_shared< SCH_CONNECTION >( m_parent, m_sheet );
165  member->SetPrefix( prefix );
166  member->ConfigureFromLabel( group_member );
167  m_members.push_back( member );
168  }
169  }
170  }
171  }
172  else
173  {
174  m_name = aLabel;
176  }
177 }
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 bus.
CONNECTION_GRAPH * g_ConnectionGraph
This also wants to live in the eventual SCHEMATIC object.
CONNECTION_TYPE m_type
This item represents a net.
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.
bool ParseBusVector(wxString aBus, wxString *aName, std::vector< wxString > &aMemberList) const
Parses a bus vector (e.g.
size_t i
Definition: json11.cpp:597
static bool IsBusGroupLabel(const wxString &aLabel)
Test if aLabel has a bus group notation.
This item represents a bus group.
wxString m_vector_prefix
SCH_ITEM * m_parent
The SCH_ITEM this connection is owned by.
This item represents a bus vector.

References CONNECTION_BUS, CONNECTION_BUS_GROUP, CONNECTION_NET, g_ConnectionGraph, CONNECTION_GRAPH::GetBusAlias(), i, IsBusGroupLabel(), IsBusVectorLabel(), m_members, m_name, m_parent, m_prefix, m_sheet, m_type, m_vector_prefix, ParseBusGroup(), and ParseBusVector().

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 399 of file sch_connection.cpp.

400 {
401  try
402  {
403  return std::regex_match( std::string( aLabel.mb_str() ), bus_group_label_re );
404  }
405  catch( ... )
406  {
407  return false;
408  }
409 }
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 380 of file sch_connection.cpp.

381 {
382  return IsBusVectorLabel( aLabel ) || IsBusGroupLabel( aLabel );
383 }
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 386 of file sch_connection.cpp.

387 {
388  try
389  {
390  return std::regex_match( std::string( aLabel.mb_str() ), bus_label_re );
391  }
392  catch( ... )
393  {
394  return false;
395  }
396 }
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 219 of file sch_connection.cpp.

220 {
221  wxASSERT( Parent() );
222 
223  switch( Parent()->Type() )
224  {
225  case SCH_LABEL_T:
226  case SCH_GLOBAL_LABEL_T:
227  case SCH_HIER_LABEL_T:
228  case SCH_SHEET_PIN_T:
229  case SCH_SHEET_T:
230  case LIB_PIN_T:
231  return true;
232 
233  case SCH_PIN_T:
234  {
235  auto pin = static_cast<SCH_PIN*>( Parent() );
236 
237  // Only annotated components should drive nets
238  return pin->GetParentComponent()->IsAnnotated( &m_sheet );
239  }
240 
241  default:
242  return false;
243  }
244 }
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 540 of file sch_connection.cpp.

541 {
542  if( !aOther->IsBus() )
543  return false;
544 
545  auto me = Name( true );
546 
547  for( auto m : aOther->Members() )
548  if( m->Name( true ) == me )
549  return true;
550 
551  return false;
552 }
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_NET );
131  }
CONNECTION_TYPE m_type
This item represents a net.

References CONNECTION_NET, and m_type.

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 514 of file sch_connection.cpp.

515 {
516  if( aOther->IsNet() )
517  return IsNet() ? ( aOther->Name( true ) == Name( true ) ) : false;
518 
519  if( !IsBus() )
520  return false;
521 
522  std::vector<wxString> mine, theirs;
523 
524  for( auto m : Members() )
525  mine.push_back( m->Name( true ) );
526 
527  for( auto m : aOther->Members() )
528  theirs.push_back( m->Name( true ) );
529 
530  std::set<wxString> subset;
531 
532  std::set_intersection( mine.begin(), mine.end(),
533  theirs.begin(), theirs.end(),
534  std::inserter(subset, subset.begin() ) );
535 
536  return ( !subset.empty() );
537 }
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().

◆ Members() [1/2]

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

◆ Members() [2/2]

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

Definition at line 239 of file sch_connection.h.

240  {
241  return m_members;
242  }
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 247 of file sch_connection.cpp.

248 {
249  wxString ret = m_prefix + m_name + m_suffix;
250 
251  if( m_name.IsEmpty() )
252  ret = "<NO NET>";
253 
254  if( !Parent() || m_type == CONNECTION_NONE )
255  return ret;
256 
257  if( !aIgnoreSheet )
258  {
259  bool prepend_path = true;
260 
261  if( m_driver )
262  {
263  switch( m_driver->Type() )
264  {
265  case SCH_PIN_T:
266  // Pins are either power connections or belong to a uniquely-annotated
267  // component, so they don't need a path if they are driving the subgraph
268  prepend_path = false;
269  break;
270 
271  case SCH_GLOBAL_LABEL_T:
272  prepend_path = false;
273  break;
274 
275  default:
276  break;
277  }
278  }
279 
280  if( prepend_path )
281  ret = m_sheet.PathHumanReadable() + ret;
282  }
283 
284  return ret;
285 }
No connection to this item.
wxString m_name
Name of the bus.
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.
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:210

References CONNECTION_NONE, m_driver, m_name, m_prefix, m_sheet, m_suffix, m_type, 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(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), and DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::visitItem().

◆ NetCode()

int SCH_CONNECTION::NetCode ( ) const
inline

Definition at line 184 of file sch_connection.h.

185  {
186  return m_net_code;
187  }

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 bus.
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 484 of file sch_connection.cpp.

486 {
487  auto ss_group = std::string( aGroup.mb_str() );
488  std::smatch matches;
489 
490  try
491  {
492  if( !std::regex_match( ss_group, matches, bus_group_label_re ) )
493  {
494  return false;
495  }
496  }
497  catch( ... )
498  {
499  return false;
500  }
501 
502  *aName = wxString( matches[1] );
503 
504  wxStringTokenizer tokenizer( wxString( matches[2] ), " " );
505  while( tokenizer.HasMoreTokens() )
506  {
507  aMemberList.push_back( tokenizer.GetNextToken() );
508  }
509 
510  return true;
511 }
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 412 of file sch_connection.cpp.

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

References bus_label_re(), i, and str.

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

◆ Prefix()

wxString SCH_CONNECTION::Prefix ( ) const
inline

Definition at line 160 of file sch_connection.h.

161  {
162  return m_prefix;
163  }

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 bus.

References m_name.

Referenced by CONNECTION_GRAPH::matchBusMember().

◆ Reset()

void SCH_CONNECTION::Reset ( )

Clears connectivity information.

Definition at line 180 of file sch_connection.cpp.

181 {
183  m_name.Empty();
184  m_prefix.Empty();
185  m_suffix .Empty();
186  m_driver = nullptr;
187  m_members.clear();
188  m_dirty = true;
189  m_net_code = 0;
190  m_bus_code = 0;
191  m_subgraph_code = 0;
192  m_vector_start = 0;
193  m_vector_end = 0;
194  m_vector_index = 0;
195  m_vector_prefix.Empty();
196 }
int m_subgraph_code
Groups directly-connected items.
No connection to this item.
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members
For bus connections, store a list of member connections.
wxString m_name
Name of the bus.
SCH_ITEM * m_driver
The SCH_ITEM that drives this connection's net.
CONNECTION_TYPE m_type
wxString m_suffix
Name suffix (used only for disambiguation)
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 CONNECTION_NONE, m_bus_code, m_dirty, m_driver, 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, and m_vector_start.

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

◆ SetBusCode()

void SCH_CONNECTION::SetBusCode ( int  aCode)
inline

Definition at line 199 of file sch_connection.h.

200  {
201  m_bus_code = aCode;
202  }

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( 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 155 of file sch_connection.h.

156  {
157  m_name = aName;
158  }
wxString m_name
Name of the bus.

References m_name.

Referenced by CONNECTION_GRAPH::buildConnectionGraph().

◆ SetNetCode()

void SCH_CONNECTION::SetNetCode ( int  aCode)
inline

Definition at line 189 of file sch_connection.h.

190  {
191  m_net_code = aCode;
192  }

References m_net_code.

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

◆ SetPrefix()

void SCH_CONNECTION::SetPrefix ( const wxString &  aPrefix)

Definition at line 288 of file sch_connection.cpp.

289 {
290  m_prefix = aPrefix;
291 
292  for( auto m : Members() )
293  m->SetPrefix( aPrefix );
294 }
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( 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 209 of file sch_connection.h.

210  {
211  m_subgraph_code = aCode;
212  }
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 297 of file sch_connection.cpp.

298 {
299  m_suffix = aSuffix;
300 
301  for( auto m : Members() )
302  m->SetSuffix( aSuffix );
303 }
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 179 of file sch_connection.h.

180  {
181  m_type = aType;
182  }
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 204 of file sch_connection.h.

205  {
206  return m_subgraph_code;
207  }
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 165 of file sch_connection.h.

166  {
167  return m_suffix;
168  }
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 174 of file sch_connection.h.

175  {
176  return m_type;
177  }
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 219 of file sch_connection.h.

220  {
221  return m_vector_end;
222  }
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 224 of file sch_connection.h.

225  {
226  return m_vector_index;
227  }
long m_vector_index
Index of bus vector member nets.

References m_vector_index.

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

◆ VectorPrefix()

wxString SCH_CONNECTION::VectorPrefix ( ) const
inline

Definition at line 229 of file sch_connection.h.

230  {
231  return m_vector_prefix;
232  }
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 214 of file sch_connection.h.

215  {
216  return m_vector_start;
217  }
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 339 of file sch_connection.h.

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

◆ m_dirty

bool SCH_CONNECTION::m_dirty
private

Definition at line 320 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 326 of file sch_connection.h.

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

◆ 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 358 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 bus.

Prefix if connection is member of a labeled bus group (or "" if not)

Definition at line 330 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 337 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 324 of file sch_connection.h.

Referenced by ConfigureFromLabel(), and Parent().

◆ m_prefix

wxString SCH_CONNECTION::m_prefix
private

Definition at line 333 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 322 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 341 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 335 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 328 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 347 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 343 of file sch_connection.h.

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

◆ m_vector_prefix

wxString SCH_CONNECTION::m_vector_prefix
private

Definition at line 350 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 345 of file sch_connection.h.

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


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