KiCad PCB EDA Suite
CONNECTION_SUBGRAPH Class Reference

A subgraph is a set of items that are electrically connected on a single sheet. More...

#include <connection_graph.h>

Public Types

enum class  PRIORITY {
  INVALID = -1 , NONE = 0 , PIN , SHEET_PIN ,
  HIER_LABEL , LOCAL_LABEL , POWER_PIN , GLOBAL
}
 

Public Member Functions

 CONNECTION_SUBGRAPH (CONNECTION_GRAPH *aGraph)
 
 ~CONNECTION_SUBGRAPH ()=default
 
bool ResolveDrivers (bool aCheckMultipleDrivers=false)
 Determines which potential driver should drive the subgraph. More...
 
wxString GetNetName () const
 Returns the fully-qualified net name for this subgraph (if one exists) More...
 
std::vector< SCH_ITEM * > GetBusLabels () const
 Returns all the bus labels attached to this subgraph (if any) More...
 
const wxString & GetNameForDriver (SCH_ITEM *aItem) const
 Returns the candidate net name for a driver. More...
 
const wxString GetNetclassForDriver (SCH_ITEM *aItem) const
 
void Absorb (CONNECTION_SUBGRAPH *aOther)
 Combines another subgraph on the same sheet into this one. More...
 
void AddItem (SCH_ITEM *aItem)
 Adds a new item to the subgraph. More...
 
void UpdateItemConnections ()
 Updates all items to match the driver connection. More...
 
const std::vector< SCH_ITEM * > & GetItems () const
 Provides a read-only reference to the items in the subgraph. More...
 
PRIORITY GetDriverPriority ()
 
const SCH_ITEMGetDriver () const
 
const SCH_CONNECTIONGetDriverConnection () const
 
const SCH_ITEMGetNoConnect () const
 
const SCH_SHEET_PATHGetSheet () const
 

Static Public Member Functions

static PRIORITY GetDriverPriority (SCH_ITEM *aDriver)
 Return the priority (higher is more important) of a candidate driver. More...
 

Private Member Functions

wxString driverName (SCH_ITEM *aItem) const
 

Private Attributes

CONNECTION_GRAPHm_graph
 
bool m_dirty
 
bool m_absorbed
 True if this subgraph has been absorbed into another. No pointers here are safe if so! More...
 
CONNECTION_SUBGRAPHm_absorbed_by
 If this subgraph is absorbed, points to the absorbing (and valid) subgraph. More...
 
long m_code
 
bool m_multiple_drivers
 True if this subgraph contains more than one driver that should be shorted together in the netlist. More...
 
bool m_strong_driver
 True if the driver is "strong": a label or power object. More...
 
bool m_local_driver
 True if the driver is a local (i.e. non-global) type. More...
 
SCH_ITEMm_bus_entry
 Bus entry in graph, if any. More...
 
std::vector< SCH_ITEM * > m_drivers
 
std::unordered_map< std::shared_ptr< SCH_CONNECTION >, std::unordered_set< CONNECTION_SUBGRAPH * > > m_bus_neighbors
 If a subgraph is a bus, this map contains links between the bus members and any local sheet neighbors with the same connection name. More...
 
std::unordered_map< std::shared_ptr< SCH_CONNECTION >, std::unordered_set< CONNECTION_SUBGRAPH * > > m_bus_parents
 If this is a net, this vector contains links to any same-sheet buses that contain it. More...
 
std::vector< SCH_SHEET_PIN * > m_hier_pins
 
std::vector< SCH_HIERLABEL * > m_hier_ports
 
CONNECTION_SUBGRAPHm_hier_parent
 
std::unordered_map< SCH_ITEM *, wxString > m_driver_name_cache
 A cache of escaped netnames from schematic items. More...
 
SCH_ITEMm_driver
 Fully-resolved driver for the subgraph (might not exist in this subgraph) More...
 
SCH_ITEMm_first_driver
 Stores the primary driver for the multiple drivers ERC check. More...
 
SCH_ITEMm_second_driver
 Used for multiple drivers ERC message; stores the second possible driver (or nullptr) More...
 
std::vector< SCH_ITEM * > m_items
 Contents of the subgraph. More...
 
SCH_ITEMm_no_connect
 No-connect item in graph, if any. More...
 
SCH_SHEET_PATH m_sheet
 On which logical sheet is the subgraph contained. More...
 
SCH_CONNECTIONm_driver_connection
 Cache for driver connection. More...
 

Friends

class CONNECTION_GRAPH
 

Detailed Description

A subgraph is a set of items that are electrically connected on a single sheet.

For example, a label connected to a wire and so on. A net is composed of one or more subgraphs.

A set of items that appears to be physically connected may actually be more than one subgraph, because some items don't connect electrically.

For example, multiple bus wires can come together at a junction but have different labels on each branch. Each label+wire branch is its own subgraph.

Definition at line 60 of file connection_graph.h.

Member Enumeration Documentation

◆ PRIORITY

enum class CONNECTION_SUBGRAPH::PRIORITY
strong
Enumerator
INVALID 
NONE 
PIN 
SHEET_PIN 
HIER_LABEL 
LOCAL_LABEL 
POWER_PIN 
GLOBAL 

Definition at line 63 of file connection_graph.h.

64 {
65 INVALID = -1,
66 NONE = 0,
67 PIN,
68 SHEET_PIN,
69 HIER_LABEL,
70 LOCAL_LABEL,
71 POWER_PIN,
72 GLOBAL
73 };
@ NONE
Definition: kibis.h:53
@ INVALID
Definition: kiface_ids.h:32

Constructor & Destructor Documentation

◆ CONNECTION_SUBGRAPH()

CONNECTION_SUBGRAPH::CONNECTION_SUBGRAPH ( CONNECTION_GRAPH aGraph)
inlineexplicit

Definition at line 75 of file connection_graph.h.

75 :
76 m_graph( aGraph ),
77 m_dirty( false ),
78 m_absorbed( false ),
79 m_absorbed_by( nullptr ),
80 m_code( -1 ),
81 m_multiple_drivers( false ),
82 m_strong_driver( false ),
83 m_local_driver( false ),
84 m_bus_entry( nullptr ),
85 m_hier_parent( nullptr ),
86 m_driver( nullptr ),
87 m_first_driver( nullptr ),
88 m_second_driver( nullptr ),
89 m_no_connect( nullptr ),
90 m_driver_connection( nullptr )
91 {}
bool m_strong_driver
True if the driver is "strong": a label or power object.
SCH_ITEM * m_no_connect
No-connect item in graph, if any.
SCH_ITEM * m_bus_entry
Bus entry in graph, if any.
CONNECTION_GRAPH * m_graph
bool m_multiple_drivers
True if this subgraph contains more than one driver that should be shorted together in the netlist.
SCH_ITEM * m_first_driver
Stores the primary driver for the multiple drivers ERC check.
bool m_absorbed
True if this subgraph has been absorbed into another. No pointers here are safe if so!
SCH_CONNECTION * m_driver_connection
Cache for driver connection.
CONNECTION_SUBGRAPH * m_absorbed_by
If this subgraph is absorbed, points to the absorbing (and valid) subgraph.
SCH_ITEM * m_driver
Fully-resolved driver for the subgraph (might not exist in this subgraph)
CONNECTION_SUBGRAPH * m_hier_parent
SCH_ITEM * m_second_driver
Used for multiple drivers ERC message; stores the second possible driver (or nullptr)
bool m_local_driver
True if the driver is a local (i.e. non-global) type.

◆ ~CONNECTION_SUBGRAPH()

CONNECTION_SUBGRAPH::~CONNECTION_SUBGRAPH ( )
default

Member Function Documentation

◆ Absorb()

void CONNECTION_SUBGRAPH::Absorb ( CONNECTION_SUBGRAPH aOther)

Combines another subgraph on the same sheet into this one.

Definition at line 341 of file connection_graph.cpp.

342{
343 wxASSERT( m_sheet == aOther->m_sheet );
344
345 for( SCH_ITEM* item : aOther->m_items )
346 {
348 AddItem( item );
349 }
350
351 m_bus_neighbors.insert( aOther->m_bus_neighbors.begin(), aOther->m_bus_neighbors.end() );
352 m_bus_parents.insert( aOther->m_bus_parents.begin(), aOther->m_bus_parents.end() );
353
355
356 aOther->m_absorbed = true;
357 aOther->m_dirty = false;
358 aOther->m_driver = nullptr;
359 aOther->m_driver_connection = nullptr;
360 aOther->m_absorbed_by = this;
361}
std::vector< SCH_ITEM * > m_items
Contents of the subgraph.
SCH_SHEET_PATH m_sheet
On which logical sheet is the subgraph contained.
std::unordered_map< std::shared_ptr< SCH_CONNECTION >, std::unordered_set< CONNECTION_SUBGRAPH * > > m_bus_neighbors
If a subgraph is a bus, this map contains links between the bus members and any local sheet neighbors...
void AddItem(SCH_ITEM *aItem)
Adds a new item to the subgraph.
std::unordered_map< std::shared_ptr< SCH_CONNECTION >, std::unordered_set< CONNECTION_SUBGRAPH * > > m_bus_parents
If this is a net, this vector contains links to any same-sheet buses that contain it.
void SetSubgraphCode(int aCode)
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:146

References AddItem(), SCH_ITEM::Connection(), m_absorbed, m_absorbed_by, m_bus_neighbors, m_bus_parents, m_code, m_dirty, m_driver, m_driver_connection, m_items, m_multiple_drivers, m_sheet, and SCH_CONNECTION::SetSubgraphCode().

◆ AddItem()

void CONNECTION_SUBGRAPH::AddItem ( SCH_ITEM aItem)

Adds a new item to the subgraph.

Definition at line 364 of file connection_graph.cpp.

365{
366 m_items.push_back( aItem );
367
368 if( aItem->Connection( &m_sheet )->IsDriver() )
369 m_drivers.push_back( aItem );
370
371 if( aItem->Type() == SCH_SHEET_PIN_T )
372 m_hier_pins.push_back( static_cast<SCH_SHEET_PIN*>( aItem ) );
373 else if( aItem->Type() == SCH_HIER_LABEL_T )
374 m_hier_ports.push_back( static_cast<SCH_HIERLABEL*>( aItem ) );
375}
std::vector< SCH_ITEM * > m_drivers
std::vector< SCH_HIERLABEL * > m_hier_ports
std::vector< SCH_SHEET_PIN * > m_hier_pins
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
bool IsDriver() const
Checks if the SCH_ITEM this connection is attached to can drive connections Drivers can be labels,...
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:153
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:157

References SCH_ITEM::Connection(), SCH_CONNECTION::IsDriver(), m_drivers, m_hier_pins, m_hier_ports, m_items, m_sheet, SCH_HIER_LABEL_T, SCH_SHEET_PIN_T, and EDA_ITEM::Type().

Referenced by Absorb(), CONNECTION_GRAPH::buildItemSubGraphs(), and CONNECTION_GRAPH::generateGlobalPowerPinSubGraphs().

◆ driverName()

wxString CONNECTION_SUBGRAPH::driverName ( SCH_ITEM aItem) const
private

Definition at line 278 of file connection_graph.cpp.

279{
280 switch( aItem->Type() )
281 {
282 case SCH_PIN_T:
283 {
284 bool forceNoConnect = m_no_connect != nullptr;
285 SCH_PIN* pin = static_cast<SCH_PIN*>( aItem );
286 return pin->GetDefaultNetName( m_sheet, forceNoConnect );
287 break;
288 }
289
290 case SCH_LABEL_T:
292 case SCH_HIER_LABEL_T:
293 case SCH_SHEET_PIN_T:
294 {
295 return EscapeString( static_cast<SCH_TEXT*>( aItem )->GetShownText(), CTX_NETNAME );
296 break;
297 }
298
299 default:
300 wxFAIL_MSG( wxS( "Unhandled item type in GetNameForDriver" ) );
301 break;
302 }
303
304 return wxEmptyString;
305}
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_NETNAME
Definition: string_utils.h:54
@ SCH_LABEL_T
Definition: typeinfo.h:151
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:152
@ SCH_PIN_T
Definition: typeinfo.h:159

References CTX_NETNAME, EscapeString(), m_no_connect, m_sheet, pin, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_LABEL_T, SCH_PIN_T, SCH_SHEET_PIN_T, and EDA_ITEM::Type().

Referenced by GetNameForDriver().

◆ GetBusLabels()

std::vector< SCH_ITEM * > CONNECTION_SUBGRAPH::GetBusLabels ( ) const

Returns all the bus labels attached to this subgraph (if any)

Definition at line 249 of file connection_graph.cpp.

250{
251 std::vector<SCH_ITEM*> labels;
252
253 for( SCH_ITEM* item : m_drivers )
254 {
255 switch( item->Type() )
256 {
257 case SCH_LABEL_T:
259 {
260 SCH_CONNECTION* label_conn = item->Connection( &m_sheet );
261
262 // Only consider bus vectors
263 if( label_conn->Type() == CONNECTION_TYPE::BUS )
264 labels.push_back( item );
265
266 break;
267 }
268
269 default:
270 break;
271 }
272 }
273
274 return labels;
275}
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
CONNECTION_TYPE Type() const
@ BUS
This item represents a bus vector.

References BUS, m_drivers, m_sheet, SCH_GLOBAL_LABEL_T, SCH_LABEL_T, and SCH_CONNECTION::Type().

◆ GetDriver()

const SCH_ITEM * CONNECTION_SUBGRAPH::GetDriver ( ) const
inline
Returns
pointer to the SCH_ITEM whose name sets the subgraph netname. N.B. This item may not be in the subgraph

Definition at line 164 of file connection_graph.h.

165 {
166 return m_driver;
167 }

References m_driver.

Referenced by DIALOG_MIGRATE_BUSES::onItemSelected().

◆ GetDriverConnection()

const SCH_CONNECTION * CONNECTION_SUBGRAPH::GetDriverConnection ( ) const
inline
Returns
SCH_CONNECTION object for m_driver on m_sheet

Definition at line 172 of file connection_graph.h.

173 {
174 return m_driver_connection;
175 }

References m_driver_connection.

Referenced by SCHEMATIC::GetNetClassAssignmentCandidates().

◆ GetDriverPriority() [1/2]

◆ GetDriverPriority() [2/2]

CONNECTION_SUBGRAPH::PRIORITY CONNECTION_SUBGRAPH::GetDriverPriority ( SCH_ITEM aDriver)
static

Return the priority (higher is more important) of a candidate driver.

0: Invalid driver 1: Symbol pin 2: Hierarchical sheet pin 3: Hierarchical label 4: Local label 5: Power pin 6: Global label

Parameters
aDriveris the item to inspect
Returns
a PRIORITY

Definition at line 405 of file connection_graph.cpp.

406{
407 if( !aDriver )
408 return PRIORITY::NONE;
409
410 switch( aDriver->Type() )
411 {
416 case SCH_PIN_T:
417 {
418 SCH_PIN* sch_pin = static_cast<SCH_PIN*>( aDriver );
419
420 if( sch_pin->IsGlobalPower() )
421 return PRIORITY::POWER_PIN;
422 else
423 return PRIORITY::PIN;
424 }
425
426 default: return PRIORITY::NONE;
427 }
428}
bool IsGlobalPower() const
Definition: sch_pin.h:158

References GLOBAL, HIER_LABEL, SCH_PIN::IsGlobalPower(), LOCAL_LABEL, NONE, PIN, POWER_PIN, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_LABEL_T, SCH_PIN_T, SCH_SHEET_PIN_T, SHEET_PIN, and EDA_ITEM::Type().

Referenced by CONNECTION_GRAPH::ercCheckNoConnects(), and SCHEMATIC::GetNetClassAssignmentCandidates().

◆ GetItems()

const std::vector< SCH_ITEM * > & CONNECTION_SUBGRAPH::GetItems ( ) const
inline

◆ GetNameForDriver()

const wxString & CONNECTION_SUBGRAPH::GetNameForDriver ( SCH_ITEM aItem) const

Returns the candidate net name for a driver.

Definition at line 308 of file connection_graph.cpp.

309{
310 auto [it, success] = m_driver_name_cache.try_emplace( aItem, driverName( aItem ) );
311
312 return it->second;
313}
wxString driverName(SCH_ITEM *aItem) const
std::unordered_map< SCH_ITEM *, wxString > m_driver_name_cache
A cache of escaped netnames from schematic items.

References driverName(), and m_driver_name_cache.

Referenced by CONNECTION_GRAPH::ercCheckBusToBusEntryConflicts(), CONNECTION_GRAPH::ercCheckMultipleDrivers(), CONNECTION_GRAPH::getDefaultConnection(), CONNECTION_GRAPH::propagateToNeighbors(), and ResolveDrivers().

◆ GetNetclassForDriver()

const wxString CONNECTION_SUBGRAPH::GetNetclassForDriver ( SCH_ITEM aItem) const

Definition at line 316 of file connection_graph.cpp.

317{
318 wxString netclass;
319
320 aItem->RunOnChildren(
321 [&]( SCH_ITEM* aChild )
322 {
323 if( aChild->Type() == SCH_FIELD_T )
324 {
325 SCH_FIELD* field = static_cast<SCH_FIELD*>( aChild );
326
327 if( field->GetCanonicalName() == wxT( "Netclass" ) )
328 {
329 netclass = field->GetText();
330 return false;
331 }
332 }
333
334 return true;
335 } );
336
337 return netclass;
338}
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:444
@ SCH_FIELD_T
Definition: typeinfo.h:155

References SCH_ITEM::RunOnChildren(), SCH_FIELD_T, and EDA_ITEM::Type().

Referenced by CONNECTION_GRAPH::buildConnectionGraph().

◆ GetNetName()

wxString CONNECTION_SUBGRAPH::GetNetName ( ) const

Returns the fully-qualified net name for this subgraph (if one exists)

Definition at line 231 of file connection_graph.cpp.

232{
233 if( !m_driver || m_dirty )
234 return "";
235
236 if( !m_driver->Connection( &m_sheet ) )
237 {
238#ifdef CONNECTIVITY_DEBUG
239 wxASSERT_MSG( false, wxS( "Tried to get the net name of an item with no connection" ) );
240#endif
241
242 return "";
243 }
244
245 return m_driver->Connection( &m_sheet )->Name();
246}
wxString Name(bool aIgnoreSheet=false) const

References SCH_ITEM::Connection(), m_dirty, m_driver, m_sheet, and SCH_CONNECTION::Name().

Referenced by CONNECTION_GRAPH::buildConnectionGraph(), CONNECTION_GRAPH::generateGlobalPowerPinSubGraphs(), and CONNECTION_GRAPH::GetResolvedSubgraphName().

◆ GetNoConnect()

const SCH_ITEM * CONNECTION_SUBGRAPH::GetNoConnect ( ) const
inline
Returns
pointer to the item causing a no-connect or nullptr if none

Definition at line 180 of file connection_graph.h.

181 {
182 return m_no_connect;
183 }

References m_no_connect.

Referenced by NETLIST_EXPORTER_BASE::CreatePinList(), NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol(), and ERC_TESTER::TestPinToPin().

◆ GetSheet()

const SCH_SHEET_PATH & CONNECTION_SUBGRAPH::GetSheet ( ) const
inline

◆ ResolveDrivers()

bool CONNECTION_SUBGRAPH::ResolveDrivers ( bool  aCheckMultipleDrivers = false)

Determines which potential driver should drive the subgraph.

If multiple possible drivers exist, picks one according to the priority. If multiple "winners" exist, returns false and sets m_driver to nullptr.

Parameters
aCheckMultipleDriverscontrols whether the second driver should be captured for ERC
Returns
true if m_driver was set, or false if a conflict occurred

Definition at line 67 of file connection_graph.cpp.

68{
69 PRIORITY highest_priority = PRIORITY::INVALID;
70 std::vector<SCH_ITEM*> candidates;
71 std::vector<SCH_ITEM*> strong_drivers;
72
73 m_driver = nullptr;
74
75 // Hierarchical labels are lower priority than local labels here,
76 // because on the first pass we want local labels to drive subgraphs
77 // so that we can identify same-sheet neighbors and link them together.
78 // Hierarchical labels will end up overriding the final net name if
79 // a higher-level sheet has a different name during the hierarchical
80 // pass.
81
82 for( SCH_ITEM* item : m_drivers )
83 {
84 PRIORITY item_priority = GetDriverPriority( item );
85
86 if( item_priority == PRIORITY::PIN
87 && !static_cast<SCH_PIN*>( item )->GetParentSymbol()->IsInNetlist() )
88 continue;
89
90 if( item_priority >= PRIORITY::HIER_LABEL )
91 strong_drivers.push_back( item );
92
93 if( item_priority > highest_priority )
94 {
95 candidates.clear();
96 candidates.push_back( item );
97 highest_priority = item_priority;
98 }
99 else if( !candidates.empty() && ( item_priority == highest_priority ) )
100 {
101 candidates.push_back( item );
102 }
103 }
104
105 if( highest_priority >= PRIORITY::HIER_LABEL )
106 m_strong_driver = true;
107
108 // Power pins are 5, global labels are 6
109 m_local_driver = ( highest_priority < PRIORITY::POWER_PIN );
110
111 if( !candidates.empty() )
112 {
113 if( candidates.size() > 1 )
114 {
115 if( highest_priority == PRIORITY::SHEET_PIN )
116 {
117 // We have multiple options, and they are all hierarchical
118 // sheet pins. Let's prefer outputs over inputs.
119
120 for( SCH_ITEM* c : candidates )
121 {
122 SCH_SHEET_PIN* p = static_cast<SCH_SHEET_PIN*>( c );
123
125 {
126 m_driver = c;
127 break;
128 }
129 }
130 }
131 else
132 {
133 // For all other driver types, sort by quality of name
134 std::sort( candidates.begin(), candidates.end(),
135 [&]( SCH_ITEM* a, SCH_ITEM* b ) -> bool
136 {
137 // meet irreflexive requirements of std::sort
138 if( a == b )
139 return false;
140
141 SCH_CONNECTION* ac = a->Connection( &m_sheet );
142 SCH_CONNECTION* bc = b->Connection( &m_sheet );
143
144 // Ensure we don't pick the subset over the superset
145 if( ac->IsBus() && bc->IsBus() )
146 return bc->IsSubsetOf( ac );
147
148 // Ensure we don't pick a hidden power pin on a regular symbol over
149 // one on a power symbol
150 if( a->Type() == SCH_PIN_T && b->Type() == SCH_PIN_T )
151 {
152 SCH_PIN* pa = static_cast<SCH_PIN*>( a );
153 SCH_PIN* pb = static_cast<SCH_PIN*>( b );
154
155 bool aPower = pa->GetLibPin()->GetParent()->IsPower();
156 bool bPower = pb->GetLibPin()->GetParent()->IsPower();
157
158 if( aPower && !bPower )
159 return true;
160 else if( bPower && !aPower )
161 return false;
162 }
163
164 const wxString& a_name = GetNameForDriver( a );
165 const wxString& b_name = GetNameForDriver( b );
166 bool a_lowQualityName = a_name.Contains( "-Pad" );
167 bool b_lowQualityName = b_name.Contains( "-Pad" );
168
169 if( a_lowQualityName && !b_lowQualityName )
170 return false;
171 else if( b_lowQualityName && !a_lowQualityName )
172 return true;
173 else
174 return a_name < b_name;
175 } );
176 }
177 }
178
179 if( !m_driver )
180 m_driver = candidates[0];
181 }
182
183 if( strong_drivers.size() > 1 )
184 m_multiple_drivers = true;
185
186 // Drop weak drivers
187 if( m_strong_driver )
188 m_drivers = strong_drivers;
189
190 // Cache driver connection
191 if( m_driver )
192 {
197 }
198 else
199 {
200 m_driver_connection = nullptr;
201 }
202
203 if( aCheckMultipleDrivers && m_multiple_drivers )
204 {
205 // First check if all the candidates are actually the same
206 bool same = true;
207 const wxString& first = GetNameForDriver( candidates[0] );
208 SCH_ITEM* second_item = nullptr;
209
210 for( unsigned i = 1; i < candidates.size(); i++ )
211 {
212 if( GetNameForDriver( candidates[i] ) != first )
213 {
214 second_item = candidates[i];
215 same = false;
216 break;
217 }
218 }
219
220 if( !same )
221 {
223 m_second_driver = second_item;
224 }
225 }
226
227 return ( m_driver != nullptr );
228}
const wxString & GetNameForDriver(SCH_ITEM *aItem) const
Returns the candidate net name for a driver.
void ConfigureFromLabel(const wxString &aLabel)
Configures the connection given a label.
void SetDriver(SCH_ITEM *aItem)
LABEL_FLAG_SHAPE GetShape() const override
Definition: sch_label.h:73
@ L_OUTPUT
Definition: sch_text.h:98

References GetDriverPriority(), GetNameForDriver(), SCH_LABEL_BASE::GetShape(), HIER_LABEL, INVALID, L_OUTPUT, m_driver, m_drivers, m_local_driver, m_strong_driver, PIN, POWER_PIN, and SHEET_PIN.

Referenced by CONNECTION_GRAPH::generateGlobalPowerPinSubGraphs().

◆ UpdateItemConnections()

void CONNECTION_SUBGRAPH::UpdateItemConnections ( )

Updates all items to match the driver connection.

Definition at line 378 of file connection_graph.cpp.

379{
381 return;
382
383 for( SCH_ITEM* item : m_items )
384 {
385 SCH_CONNECTION* item_conn = item->GetOrInitConnection( m_sheet, m_graph );
386
387 if( !item_conn )
388 continue;
389
390 if( ( m_driver_connection->IsBus() && item_conn->IsNet() ) ||
391 ( m_driver_connection->IsNet() && item_conn->IsBus() ) )
392 {
393 continue;
394 }
395
396 if( item != m_driver )
397 {
398 item_conn->Clone( *m_driver_connection );
399 item_conn->ClearDirty();
400 }
401 }
402}
bool IsNet() const
bool IsBus() const
void Clone(const SCH_CONNECTION &aOther)
Copies connectivity information (but not parent) from another connection.

References SCH_CONNECTION::ClearDirty(), SCH_CONNECTION::Clone(), SCH_CONNECTION::IsBus(), SCH_CONNECTION::IsNet(), m_driver, m_driver_connection, m_graph, m_items, and m_sheet.

Friends And Related Function Documentation

◆ CONNECTION_GRAPH

friend class CONNECTION_GRAPH
friend

Definition at line 95 of file connection_graph.h.

Member Data Documentation

◆ m_absorbed

bool CONNECTION_SUBGRAPH::m_absorbed
private

True if this subgraph has been absorbed into another. No pointers here are safe if so!

Definition at line 198 of file connection_graph.h.

Referenced by Absorb(), CONNECTION_GRAPH::buildConnectionGraph(), CONNECTION_GRAPH::FindSubgraphByName(), CONNECTION_GRAPH::GetSubgraphForItem(), CONNECTION_GRAPH::processSubGraphs(), and CONNECTION_GRAPH::propagateToNeighbors().

◆ m_absorbed_by

CONNECTION_SUBGRAPH* CONNECTION_SUBGRAPH::m_absorbed_by
private

If this subgraph is absorbed, points to the absorbing (and valid) subgraph.

Definition at line 201 of file connection_graph.h.

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

◆ m_bus_entry

SCH_ITEM* CONNECTION_SUBGRAPH::m_bus_entry
private

Bus entry in graph, if any.

Definition at line 219 of file connection_graph.h.

◆ m_bus_neighbors

std::unordered_map< std::shared_ptr<SCH_CONNECTION>, std::unordered_set<CONNECTION_SUBGRAPH*> > CONNECTION_SUBGRAPH::m_bus_neighbors
private

If a subgraph is a bus, this map contains links between the bus members and any local sheet neighbors with the same connection name.

For example, if this subgraph is a bus D[7..0], and on the same sheet there is a net with label D7, this map will contain an entry for the D7 bus member, and the vector will contain a pointer to the D7 net subgraph.

Definition at line 232 of file connection_graph.h.

Referenced by Absorb().

◆ m_bus_parents

std::unordered_map< std::shared_ptr<SCH_CONNECTION>, std::unordered_set<CONNECTION_SUBGRAPH*> > CONNECTION_SUBGRAPH::m_bus_parents
private

If this is a net, this vector contains links to any same-sheet buses that contain it.

The string key is the name of the connection that forms the link (which isn't necessarily the same as the name of the connection driving this subgraph)

Definition at line 240 of file connection_graph.h.

Referenced by Absorb(), and CONNECTION_GRAPH::processSubGraphs().

◆ m_code

◆ m_dirty

◆ m_driver

◆ m_driver_connection

◆ m_driver_name_cache

std::unordered_map<SCH_ITEM*, wxString> CONNECTION_SUBGRAPH::m_driver_name_cache
mutableprivate

A cache of escaped netnames from schematic items.

Definition at line 252 of file connection_graph.h.

Referenced by GetNameForDriver().

◆ m_drivers

◆ m_first_driver

SCH_ITEM* CONNECTION_SUBGRAPH::m_first_driver
private

Stores the primary driver for the multiple drivers ERC check.

This is the chosen driver before subgraphs are absorbed (so m_driver may be different)

Definition at line 261 of file connection_graph.h.

Referenced by CONNECTION_GRAPH::ercCheckMultipleDrivers().

◆ m_graph

CONNECTION_GRAPH* CONNECTION_SUBGRAPH::m_graph
private

Definition at line 193 of file connection_graph.h.

Referenced by UpdateItemConnections().

◆ m_hier_parent

CONNECTION_SUBGRAPH* CONNECTION_SUBGRAPH::m_hier_parent
private

Definition at line 249 of file connection_graph.h.

Referenced by CONNECTION_GRAPH::propagateToNeighbors().

◆ m_hier_pins

std::vector<SCH_SHEET_PIN*> CONNECTION_SUBGRAPH::m_hier_pins
private

Definition at line 243 of file connection_graph.h.

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

◆ m_hier_ports

std::vector<SCH_HIERLABEL*> CONNECTION_SUBGRAPH::m_hier_ports
private

Definition at line 246 of file connection_graph.h.

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

◆ m_items

◆ m_local_driver

bool CONNECTION_SUBGRAPH::m_local_driver
private

True if the driver is a local (i.e. non-global) type.

Definition at line 216 of file connection_graph.h.

Referenced by ResolveDrivers().

◆ m_multiple_drivers

bool CONNECTION_SUBGRAPH::m_multiple_drivers
private

True if this subgraph contains more than one driver that should be shorted together in the netlist.

For example, two labels or two power ports.

Definition at line 210 of file connection_graph.h.

Referenced by Absorb(), CONNECTION_GRAPH::ercCheckMultipleDrivers(), CONNECTION_GRAPH::processSubGraphs(), and CONNECTION_GRAPH::propagateToNeighbors().

◆ m_no_connect

SCH_ITEM* CONNECTION_SUBGRAPH::m_no_connect
private

◆ m_second_driver

SCH_ITEM* CONNECTION_SUBGRAPH::m_second_driver
private

Used for multiple drivers ERC message; stores the second possible driver (or nullptr)

Definition at line 264 of file connection_graph.h.

Referenced by CONNECTION_GRAPH::ercCheckMultipleDrivers().

◆ m_sheet

◆ m_strong_driver

bool CONNECTION_SUBGRAPH::m_strong_driver
private

True if the driver is "strong": a label or power object.

Definition at line 213 of file connection_graph.h.

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


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