KiCad PCB EDA Suite
Loading...
Searching...
No Matches
connection_graph.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2018 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Jon Evans <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef _CONNECTION_GRAPH_H
23#define _CONNECTION_GRAPH_H
24
25#include <functional>
26#include <memory>
27#include <mutex>
28#include <utility>
29#include <vector>
30#include <map>
31
32#include <erc/erc_settings.h>
33#include <gal/color4d.h>
34#include <sch_connection.h>
35#include <sch_item.h>
36#include <sch_netchain.h>
37#include <wx/treectrl.h>
38#include <wx/string.h>
39#include <advanced_config.h>
40#include <progress_reporter.h>
41
42
43#ifdef DEBUG
44// Uncomment this line to enable connectivity debugging features
45// #define CONNECTIVITY_DEBUG
46#endif
47
48
50class SCHEMATIC;
51class SCH_EDIT_FRAME;
52class SCH_HIERLABEL;
53class SCH_PIN;
54class SCH_SHEET_PIN;
55class SCH_NETCHAIN;
56
57
71{
72public:
85
87 m_graph( aGraph ),
88 m_dirty( false ),
89 m_absorbed( false ),
90 m_is_bus_member( false ),
91 m_absorbed_by( nullptr ),
92 m_code( -1 ),
93 m_multiple_drivers( false ),
94 m_strong_driver( false ),
95 m_local_driver( false ),
96 m_bus_entry( nullptr ),
97 m_hier_parent( nullptr ),
98 m_driver( nullptr ),
99 m_no_connect( nullptr ),
100 m_driver_connection( nullptr )
101 {}
102
103
104 friend class CONNECTION_GRAPH;
105
115 bool ResolveDrivers( bool aCheckMultipleDrivers = false );
116
120 wxString GetNetName() const;
121
123 std::vector<SCH_ITEM*> GetVectorBusLabels() const;
124
126 std::vector<SCH_ITEM*> GetAllBusLabels() const;
127
129 const wxString& GetNameForDriver( SCH_ITEM* aItem ) const;
130
133 const std::vector<std::pair<wxString, SCH_ITEM*>>
134 GetNetclassesForDriver( SCH_ITEM* aItem ) const;
135
137 void Absorb( CONNECTION_SUBGRAPH* aOther );
138
140 void AddItem( SCH_ITEM* aItem );
141
144
146 const std::set<SCH_ITEM*>& GetItems() const
147 {
148 return m_items;
149 }
150
152 void getAllConnectedItems( std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>>& aItems,
153 std::set<CONNECTION_SUBGRAPH*>& aSubgraphs );
154
169 static PRIORITY GetDriverPriority( SCH_ITEM* aDriver );
170
172 {
173 if( m_driver )
174 return GetDriverPriority( m_driver );
175 else
176 return PRIORITY::NONE;
177 }
178
183 const SCH_ITEM* GetDriver() const
184 {
185 return m_driver;
186 }
187
192 {
193 return m_driver_connection;
194 }
195
199 const SCH_ITEM* GetNoConnect() const
200 {
201 return m_no_connect;
202 }
203
205 {
206 return m_sheet;
207 }
208
209 const std::unordered_map< std::shared_ptr<SCH_CONNECTION>,
210 std::unordered_set<CONNECTION_SUBGRAPH*> >& GetBusParents() const
211 {
212 return m_bus_parents;
213 }
214
215 void RemoveItem( SCH_ITEM* aItem );
216
220 void ExchangeItem( SCH_ITEM* aOldItem, SCH_ITEM* aNewItem );
221
222 // Use this to keep a connection pointer that is not owned by any item
223 // This will be destroyed with the subgraph
224 SCH_CONNECTION* StoreImplicitConnection( std::unique_ptr<SCH_CONNECTION> aConnection )
225 {
226 SCH_CONNECTION* raw = aConnection.get();
227
228 m_bus_element_connections.insert( std::move( aConnection ) );
229
230 return raw;
231 }
232
233private:
234 wxString driverName( SCH_ITEM* aItem ) const;
235
237
239
242
248
251
253 std::set<CONNECTION_SUBGRAPH*> m_absorbed_subgraphs;
254
255 long m_code;
256
263
266
269
272
273 std::set<SCH_ITEM*> m_drivers;
274
283 std::unordered_map< std::shared_ptr<SCH_CONNECTION>,
284 std::unordered_set<CONNECTION_SUBGRAPH*> > m_bus_neighbors;
285
291 std::unordered_map< std::shared_ptr<SCH_CONNECTION>,
292 std::unordered_set<CONNECTION_SUBGRAPH*> > m_bus_parents;
293
295 std::set<SCH_SHEET_PIN*> m_hier_pins;
296
298 std::set<SCH_HIERLABEL*> m_hier_ports;
299
302
305 std::unordered_set<CONNECTION_SUBGRAPH*> m_hier_children;
306
308 mutable std::mutex m_driver_name_cache_mutex;
309 mutable std::unordered_map<SCH_ITEM*, wxString> m_driver_name_cache;
310
313
315 std::set<SCH_ITEM*> m_items;
316
319
322
325
326 // A comparator for unique_ptr<SCH_CONNECTION> to allow storage in a set
328 {
329 bool operator()( const std::unique_ptr<SCH_CONNECTION>& aLeft,
330 const std::unique_ptr<SCH_CONNECTION>& aRight ) const
331 {
332 return aLeft.get() < aRight.get();
333 }
334 };
335
338 std::set<std::unique_ptr<SCH_CONNECTION>, CompareConnectionPtr> m_bus_element_connections;
339
340 std::mutex m_driver_mutex;
341};
342
344{
345 wxString Name;
347
348 bool operator==(const NET_NAME_CODE_CACHE_KEY& other) const
349 {
350 return Name == other.Name && Netcode == other.Netcode;
351 }
352};
353
354namespace std
355{
356 template <>
358 {
359 std::size_t operator()( const NET_NAME_CODE_CACHE_KEY& k ) const
360 {
361 const std::size_t prime = 19937;
362
363 return hash<wxString>()( k.Name ) ^ ( hash<int>()( k.Netcode ) * prime );
364 }
365 };
366}
367
369typedef std::unordered_map<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> NET_MAP;
370
375{
376public:
377 CONNECTION_GRAPH( SCHEMATIC* aSchematic = nullptr ) :
378 m_last_net_code( 1 ),
379 m_last_bus_code( 1 ),
381 m_schematic( aSchematic )
382 {}
383
385
386 // We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that
387 // will only land us in trouble.
390
391 // Define QA friend functions to allow testing of private methods
395 std::unique_ptr<SCH_NETCHAIN> aChain );
397 const std::pair<std::pair<wxString, wxString>,
398 std::pair<wxString, wxString>>& aTerms,
399 const std::map<std::pair<wxString, wxString>, wxString>& aRefPinToNet,
400 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& aPotentials,
401 const wxString& aChainName );
402
403 void Reset();
404
405 void SetSchematic( SCHEMATIC* aSchematic )
406 {
407 m_schematic = aSchematic;
408 }
409
410 SCHEMATIC* GetSchematic() const { return m_schematic; }
411
412 void SetLastCodes( const CONNECTION_GRAPH* aOther )
413 {
417 }
418
426 void Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnconditional = false,
427 std::function<void( SCH_ITEM* )>* aChangedItemHandler = nullptr,
428 PROGRESS_REPORTER* aProgressReporter = nullptr );
429
436 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aName );
437
444
445 std::vector<const CONNECTION_SUBGRAPH*> GetBusesNeedingMigration();
446
454 int RunERC();
455
457
458 // (Deprecated accessor moved to potential net chains section; retained later.)
459
460 SCH_NETCHAIN* GetNetChainForNet( const wxString& aNet );
461 SCH_NETCHAIN* GetNetChainByName( const wxString& aName );
462 void ReplaceNetChainTerminalPin( const wxString& aNetChain, const KIID& aPrev, const KIID& aNew );
463 void SetNetChainTerminalOverrides( const std::map<wxString, std::pair<KIID, KIID>>& aOverrides );
464
470 void SetNetChainNetClassOverrides( const std::map<wxString, wxString>& aOverrides )
471 {
472 m_netChainNetClassOverrides = aOverrides;
473 }
474
475 const std::map<wxString, wxString>& GetNetChainNetClassOverrides() const
476 {
478 }
479
481 {
482 wxString ref;
483 wxString pin;
484 };
485 using CHAIN_TERMINAL_REFS = std::pair<CHAIN_TERMINAL_REF, CHAIN_TERMINAL_REF>;
486
487 void SetNetChainTerminalRefOverrides( const std::map<wxString, CHAIN_TERMINAL_REFS>& aRefs )
488 {
490 }
491
492 const std::map<wxString, CHAIN_TERMINAL_REFS>& GetNetChainTerminalRefOverrides() const
493 {
495 }
496
497 const std::map<wxString, std::pair<KIID, KIID>>& GetNetChainTerminalOverrides() const
498 {
500 }
501
502 void SetNetChainColorOverrides( const std::map<wxString, COLOR4D>& aOverrides )
503 {
504 m_netChainColorOverrides = aOverrides;
505 }
506
507 const std::map<wxString, COLOR4D>& GetNetChainColorOverrides() const
508 {
510 }
511
517 void SetNetChainMemberNetOverrides( const std::map<wxString, std::set<wxString>>& aOverrides )
518 {
519 m_netChainMemberNetOverrides = aOverrides;
520 }
521
522 const std::map<wxString, std::set<wxString>>& GetNetChainMemberNetOverrides() const
523 {
525 }
526
534 CONNECTION_SUBGRAPH* FindSubgraphByName( const wxString& aNetName,
535 const SCH_SHEET_PATH& aPath );
536
545 CONNECTION_SUBGRAPH* FindFirstSubgraphByName( const wxString& aNetName );
546
548
549 const std::vector<CONNECTION_SUBGRAPH*>& GetAllSubgraphs( const wxString& aNetName ) const;
550
557 wxString GetResolvedSubgraphName( const CONNECTION_SUBGRAPH* aSubGraph ) const;
558
566 static wxString MakeNetChainKey( const wxString& aRawNetName, long aSubgraphCode );
567
571 static wxString MakeNetChainKey( const CONNECTION_SUBGRAPH* aSubGraph );
572
580 std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> ExtractAffectedItems(
581 const std::set<SCH_ITEM*> &aItems );
582
590 void Merge( CONNECTION_GRAPH& aGraph );
591
592 void RemoveItem( SCH_ITEM* aItem );
593
597 void ExchangeItem( SCH_ITEM* aOldItem, SCH_ITEM* aNewItem );
598
606 bool IsMinor() const
607 {
608 return static_cast<ssize_t>( m_items.size() )
610 }
611
612private:
613
619 void updateSymbolConnectivity( const SCH_SHEET_PATH& aSheet,
620 SCH_SYMBOL* aSymbol,
621 std::map<VECTOR2I, std::vector<SCH_ITEM*>>& aConnectionMap );
622
628 void updatePinConnectivity( const SCH_SHEET_PATH& aSheet,
629 SCH_PIN* aPin,
630 SCH_CONNECTION* aConnection );
631
638 SCH_ITEM* aItem,
639 std::map<VECTOR2I, std::vector<SCH_ITEM*>>& aConnectionMap );
640
668 void updateItemConnectivity( const SCH_SHEET_PATH& aSheet,
669 const std::vector<SCH_ITEM*>& aItemList );
670
688 void buildConnectionGraph( std::function<void( SCH_ITEM* )>* aChangedItemHandler,
689 bool aUnconditional );
690
694 void buildItemSubGraphs();
695
699 void resolveAllDrivers();
700
705
710
715
719 void processSubGraphs();
720
726 int assignNewNetCode( SCH_CONNECTION& aConnection );
727
733 int getOrCreateNetCode( const wxString& aNetName );
734
740 void assignNetCodesToBus( SCH_CONNECTION* aConnection );
741
751 void propagateToNeighbors( CONNECTION_SUBGRAPH* aSubgraph, bool aForce );
752
758 void removeSubgraphs( std::set<CONNECTION_SUBGRAPH*>& aSubgraphs );
759
770 static SCH_CONNECTION* matchBusMember( SCH_CONNECTION* aBusConnection,
771 SCH_CONNECTION* aSearch );
772
782 std::shared_ptr<SCH_CONNECTION> getDefaultConnection( SCH_ITEM* aItem,
783 CONNECTION_SUBGRAPH* aSubgraph );
784
785 void recacheSubgraphName( CONNECTION_SUBGRAPH* aSubgraph, const wxString& aOldName );
786
795 bool ercCheckMultipleDrivers( const CONNECTION_SUBGRAPH* aSubgraph );
796
805 bool ercCheckBusToNetConflicts( const CONNECTION_SUBGRAPH* aSubgraph );
806
817 bool ercCheckBusToBusConflicts( const CONNECTION_SUBGRAPH* aSubgraph );
818
832
842 bool ercCheckNoConnects( const CONNECTION_SUBGRAPH* aSubgraph );
843
852 bool ercCheckFloatingWires( const CONNECTION_SUBGRAPH* aSubgraph );
853
862 bool ercCheckDanglingWireEndpoints( const CONNECTION_SUBGRAPH* aSubgraph );
863
867 void collectBusMemberSiblings( const CONNECTION_SUBGRAPH* aBusParent, const wxString& aMemberName,
868 std::unordered_set<const CONNECTION_SUBGRAPH*>& aOut ) const;
869
879 bool ercCheckLabels( const CONNECTION_SUBGRAPH* aSubgraph );
880
887
895 int ercCheckHierSheets();
896
901
908 size_t hasPins( const CONNECTION_SUBGRAPH* aLocSubgraph );
909
910 void RebuildNetChains();
911
912 // Potential net chain (inferred) API -------------------------------
913public:
918 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& GetPotentialNetChains() const { return m_potentialNetChains; }
919
922
924 SCH_NETCHAIN* CreateNetChainFromPotential( SCH_NETCHAIN* aPotential, const wxString& aName );
925
942 SCH_NETCHAIN* CreateManualNetChain( const wxString& aName,
943 const std::set<class SCH_SYMBOL*>& aSymbols,
944 const std::set<wxString>& aNets,
945 const KIID& aTerminalPinA, const KIID& aTerminalPinB,
946 const wxString& aRefA, const wxString& aPinNumA,
947 const wxString& aRefB, const wxString& aPinNumB );
948
950 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& GetCommittedNetChains() const { return m_committedNetChains; }
951
961
963 bool NetChainsBuilt() const { return m_netChainsBuilt; }
964
972 static std::function<void( CONNECTION_GRAPH& )>& RebuildNetChainsTestHook();
973
982 bool DeleteCommittedNetChain( const wxString& aName );
983
990 bool RenameCommittedNetChain( const wxString& aOld, const wxString& aNew );
991
992private:
1001 const CHAIN_TERMINAL_REFS& aTermRefs,
1002 const std::map<std::pair<wxString, wxString>, wxString>& aRefPinToNet,
1003 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& aPotentials,
1004 const wxString& aChainName );
1005
1011 void rekeyOverrideMaps( const wxString& aOld, const wxString& aNew );
1012
1020 void refreshCommittedChainPayload( SCH_NETCHAIN* aTarget, const std::set<wxString>& aNets,
1021 const std::set<class SCH_SYMBOL*>& aSymbols,
1022 const KIID& aTerminalPinA, const KIID& aTerminalPinB,
1023 const wxString& aRefA, const wxString& aPinNumA,
1024 const wxString& aRefB, const wxString& aPinNumB );
1025
1030 void refreshCommittedChainFromPotential( SCH_NETCHAIN* aTarget, const SCH_NETCHAIN& aSource );
1031
1032 // Bridge-graph helper types shared by RebuildNetChains() and FindNetChainPathsBetweenPins().
1033 // A bridge edge represents a 2-pin passthrough symbol that ties two distinct subgraph nets
1034 // together; the bridge graph is the adjacency built from the surviving (non-power-touching)
1035 // edges after the leaf-prune pass.
1036
1038 {
1039 wxString a;
1040 wxString b;
1042 };
1043
1045 {
1046 wxString other;
1048 };
1049
1051 {
1052 std::map<wxString, std::vector<BRIDGE_NEIGHBOR>> adjacency;
1053 std::vector<BRIDGE_EDGE> edges;
1054 };
1055
1067
1070
1072 std::vector<SCH_ITEM*> m_items;
1073
1075 std::vector<CONNECTION_SUBGRAPH*> m_subgraphs;
1076
1078 std::vector<CONNECTION_SUBGRAPH*> m_driver_subgraphs;
1079
1081 std::unordered_map<SCH_SHEET_PATH, std::vector<CONNECTION_SUBGRAPH*>> m_sheet_to_subgraphs_map;
1082
1083 std::vector<std::pair<SCH_SHEET_PATH, SCH_PIN*>> m_global_power_pins;
1084
1085 std::unordered_map<wxString, std::shared_ptr<BUS_ALIAS>> m_bus_alias_cache;
1086
1087 std::unordered_map<wxString, int> m_net_name_to_code_map;
1088
1089 std::unordered_map<wxString, int> m_bus_name_to_code_map;
1090
1091 std::unordered_map<wxString, std::vector<const CONNECTION_SUBGRAPH*>> m_global_label_cache;
1092
1093 std::map< std::pair<SCH_SHEET_PATH, wxString>,
1094 std::vector<const CONNECTION_SUBGRAPH*> > m_local_label_cache;
1095
1096 std::unordered_map<wxString, std::vector<CONNECTION_SUBGRAPH*>> m_net_name_to_subgraphs_map;
1097
1098 std::unordered_map<SCH_ITEM*, CONNECTION_SUBGRAPH*> m_item_to_subgraph_map;
1099
1101
1102 std::vector<std::unique_ptr<SCH_NETCHAIN>> m_committedNetChains;
1103 std::vector<std::unique_ptr<SCH_NETCHAIN>> m_potentialNetChains;
1104 bool m_netChainsBuilt = false;
1105 std::map<wxString, std::pair<KIID, KIID>> m_netChainTerminalOverrides;
1106 std::map<wxString, wxString> m_netChainNetClassOverrides;
1107 std::map<wxString, COLOR4D> m_netChainColorOverrides;
1108 std::map<wxString, CHAIN_TERMINAL_REFS> m_netChainTerminalRefOverrides;
1109 std::map<wxString, std::set<wxString>> m_netChainMemberNetOverrides;
1110
1112
1114
1116
1118};
1119
1120#endif
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Calculate the connectivity of a schematic and generates netlists.
static SCH_NETCHAIN * resolvePotentialChainByTerminals(const CHAIN_TERMINAL_REFS &aTermRefs, const std::map< std::pair< wxString, wxString >, wxString > &aRefPinToNet, const std::vector< std::unique_ptr< SCH_NETCHAIN > > &aPotentials, const wxString &aChainName)
Disambiguate the saved (refA.pinA, refB.pinB) terminal pair against the current set of potential net ...
int RunERC()
Run electrical rule checks on the connectivity graph.
void SetSchematic(SCHEMATIC *aSchematic)
bool ercCheckBusToBusConflicts(const CONNECTION_SUBGRAPH *aSubgraph)
Check one subgraph for conflicting connections between two bus items.
void processSubGraphs()
Process all subgraphs to assign netcodes and merge subgraphs based on labels.
void refreshCommittedChainFromPotential(SCH_NETCHAIN *aTarget, const SCH_NETCHAIN &aSource)
Thin forwarder over refreshCommittedChainPayload that pulls payload fields from an inferred potential...
std::map< wxString, wxString > m_netChainNetClassOverrides
std::pair< CHAIN_TERMINAL_REF, CHAIN_TERMINAL_REF > CHAIN_TERMINAL_REFS
void SetNetChainColorOverrides(const std::map< wxString, COLOR4D > &aOverrides)
SCH_NETCHAIN * GetNetChainByName(const wxString &aName)
friend void boost_test_inject_committed_net_chain(CONNECTION_GRAPH &aGraph, std::unique_ptr< SCH_NETCHAIN > aChain)
const std::map< wxString, COLOR4D > & GetNetChainColorOverrides() const
bool ercCheckLabels(const CONNECTION_SUBGRAPH *aSubgraph)
Check one subgraph for proper connection of labels.
void RemoveItem(SCH_ITEM *aItem)
std::map< wxString, COLOR4D > m_netChainColorOverrides
void collectAllDriverValues()
Map the driver values for each subgraph.
friend void boost_test_update_generic_connectivity()
CONNECTION_SUBGRAPH * FindSubgraphByName(const wxString &aNetName, const SCH_SHEET_PATH &aPath)
Return the subgraph for a given net name on a given sheet.
int ercCheckDirectiveLabels()
Check directive labels should be connected to something.
void recacheSubgraphName(CONNECTION_SUBGRAPH *aSubgraph, const wxString &aOldName)
void SetNetChainMemberNetOverrides(const std::map< wxString, std::set< wxString > > &aOverrides)
Stash per-chain member-net lists read from the schematic file.
const std::map< wxString, std::set< wxString > > & GetNetChainMemberNetOverrides() const
const NET_MAP & GetNetMap() const
static SCH_CONNECTION * matchBusMember(SCH_CONNECTION *aBusConnection, SCH_CONNECTION *aSearch)
Search for a matching bus member inside a bus connection.
CONNECTION_GRAPH & operator=(const CONNECTION_GRAPH &)=delete
std::unordered_map< wxString, std::shared_ptr< BUS_ALIAS > > m_bus_alias_cache
SCHEMATIC * m_schematic
The schematic this graph represents.
void updateGenericItemConnectivity(const SCH_SHEET_PATH &aSheet, SCH_ITEM *aItem, std::map< VECTOR2I, std::vector< SCH_ITEM * > > &aConnectionMap)
Update the connectivity of items that are not pins or symbols.
friend void boost_test_update_symbol_connectivity()
std::vector< std::unique_ptr< SCH_NETCHAIN > > m_committedNetChains
std::unordered_map< SCH_SHEET_PATH, std::vector< CONNECTION_SUBGRAPH * > > m_sheet_to_subgraphs_map
Cache to lookup subgraphs in m_driver_subgraphs by sheet path.
void updateSymbolConnectivity(const SCH_SHEET_PATH &aSheet, SCH_SYMBOL *aSymbol, std::map< VECTOR2I, std::vector< SCH_ITEM * > > &aConnectionMap)
Update the connectivity of a symbol and its pins.
CONNECTION_SUBGRAPH * FindFirstSubgraphByName(const wxString &aNetName)
Retrieve a subgraph for the given net name, if one exists.
void propagateToNeighbors(CONNECTION_SUBGRAPH *aSubgraph, bool aForce)
Update all neighbors of a subgraph with this one's connectivity info.
void buildItemSubGraphs()
Generate individual item subgraphs on a per-sheet basis.
SCH_NETCHAIN * GetNetChainForNet(const wxString &aNet)
const std::vector< CONNECTION_SUBGRAPH * > & GetAllSubgraphs(const wxString &aNetName) const
bool ercCheckMultipleDrivers(const CONNECTION_SUBGRAPH *aSubgraph)
If the subgraph has multiple drivers of equal priority that are graphically connected,...
void SetNetChainNetClassOverrides(const std::map< wxString, wxString > &aOverrides)
Stash per-net-chain netclass overrides read from the schematic file.
SCH_SHEET_LIST m_sheetList
All the sheets in the schematic (as long as we don't have partial updates).
void generateGlobalPowerPinSubGraphs()
Iterate through the global power pins to collect the global labels as drivers.
std::map< wxString, CHAIN_TERMINAL_REFS > m_netChainTerminalRefOverrides
BRIDGE_GRAPH buildBridgeAdjacency()
Build the bridge graph used for net-chain discovery.
void SetNetChainTerminalRefOverrides(const std::map< wxString, CHAIN_TERMINAL_REFS > &aRefs)
SCH_NETCHAIN * CreateNetChainFromPotential(SCH_NETCHAIN *aPotential, const wxString &aName)
Promote a potential net chain to an actual user net chain with the provided name.
std::unordered_map< wxString, int > m_net_name_to_code_map
int ercCheckSingleGlobalLabel()
Check that a global label is instantiated more that once across the schematic hierarchy.
int ercCheckHierSheets()
Check that a hierarchical sheet has at least one matching label inside the sheet for each port on the...
bool ercCheckBusToNetConflicts(const CONNECTION_SUBGRAPH *aSubgraph)
Check one subgraph for conflicting connections between net and bus labels.
std::shared_ptr< SCH_CONNECTION > getDefaultConnection(SCH_ITEM *aItem, CONNECTION_SUBGRAPH *aSubgraph)
Build a new default connection for the given item based on its properties.
static std::function< void(CONNECTION_GRAPH &)> & RebuildNetChainsTestHook()
Test-only hook fired inside RebuildNetChains() after the restore passes have finished but before the ...
bool RenameCommittedNetChain(const wxString &aOld, const wxString &aNew)
Rename a committed net chain.
std::vector< const CONNECTION_SUBGRAPH * > GetBusesNeedingMigration()
Determine which subgraphs have more than one conflicting bus label.
void Recalculate(const SCH_SHEET_LIST &aSheetList, bool aUnconditional=false, std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Update the connection graph for the given list of sheets.
int assignNewNetCode(SCH_CONNECTION &aConnection)
Helper to assign a new net code to a connection.
std::map< std::pair< SCH_SHEET_PATH, wxString >, std::vector< const CONNECTION_SUBGRAPH * > > m_local_label_cache
int getOrCreateNetCode(const wxString &aNetName)
void collectBusMemberSiblings(const CONNECTION_SUBGRAPH *aBusParent, const wxString &aMemberName, std::unordered_set< const CONNECTION_SUBGRAPH * > &aOut) const
Find bus members on other sheets that share aBusParent's bus and member name.
bool ercCheckDanglingWireEndpoints(const CONNECTION_SUBGRAPH *aSubgraph)
Check one subgraph for dangling wire endpoints.
void refreshCommittedChainPayload(SCH_NETCHAIN *aTarget, const std::set< wxString > &aNets, const std::set< class SCH_SYMBOL * > &aSymbols, const KIID &aTerminalPinA, const KIID &aTerminalPinB, const wxString &aRefA, const wxString &aPinNumA, const wxString &aRefB, const wxString &aPinNumB)
Replace the derived-view payload on aTarget with explicitly supplied member nets, symbols,...
void assignNetCodesToBus(SCH_CONNECTION *aConnection)
Ensure all members of the bus connection have a valid net code assigned.
std::unordered_map< wxString, int > m_bus_name_to_code_map
const std::vector< std::unique_ptr< SCH_NETCHAIN > > & GetPotentialNetChains() const
Potential net chains are inferred groupings produced by RebuildNetChains() but not yet user-committed...
bool IsMinor() const
We modify how we handle the connectivity graph for small graphs vs large graphs.
std::unordered_map< wxString, std::vector< const CONNECTION_SUBGRAPH * > > m_global_label_cache
std::vector< CONNECTION_SUBGRAPH * > m_subgraphs
The owner of all CONNECTION_SUBGRAPH objects.
std::vector< std::pair< SCH_SHEET_PATH, SCH_PIN * > > m_global_power_pins
bool NetChainsBuilt() const
Returns true once RebuildNetChains() has completed at least once on this graph.
SCH_NETCHAIN * CreateManualNetChain(const wxString &aName, const std::set< class SCH_SYMBOL * > &aSymbols, const std::set< wxString > &aNets, const KIID &aTerminalPinA, const KIID &aTerminalPinB, const wxString &aRefA, const wxString &aPinNumA, const wxString &aRefB, const wxString &aPinNumB)
Commit a manually-defined net chain that the inferred-potential pass did not produce.
CONNECTION_GRAPH(SCHEMATIC *aSchematic=nullptr)
bool ercCheckNoConnects(const CONNECTION_SUBGRAPH *aSubgraph)
Check one subgraph for proper presence or absence of no-connect symbols.
size_t hasPins(const CONNECTION_SUBGRAPH *aLocSubgraph)
Get the number of pins in a given subgraph.
std::vector< SCH_ITEM * > m_items
All connectable items in the schematic.
void SetNetChainTerminalOverrides(const std::map< wxString, std::pair< KIID, KIID > > &aOverrides)
const std::map< wxString, wxString > & GetNetChainNetClassOverrides() const
std::vector< std::unique_ptr< SCH_NETCHAIN > > m_potentialNetChains
last built potential (uncommitted) net chains
std::unordered_map< wxString, std::vector< CONNECTION_SUBGRAPH * > > m_net_name_to_subgraphs_map
std::shared_ptr< BUS_ALIAS > GetBusAlias(const wxString &aName)
Return a bus alias pointer for the given name if it exists (from cache)
void removeSubgraphs(std::set< CONNECTION_SUBGRAPH * > &aSubgraphs)
Remove references to the given subgraphs from all structures in the connection graph.
SCH_NETCHAIN * FindPotentialNetChainBetweenPins(SCH_PIN *aPinA, SCH_PIN *aPinB)
Locate a potential net chain that contains both pins (by subgraph net membership).
std::unordered_map< SCH_ITEM *, CONNECTION_SUBGRAPH * > m_item_to_subgraph_map
friend SCH_NETCHAIN * boost_test_resolve_potential_chain_by_terminals(const std::pair< std::pair< wxString, wxString >, std::pair< wxString, wxString > > &aTerms, const std::map< std::pair< wxString, wxString >, wxString > &aRefPinToNet, const std::vector< std::unique_ptr< SCH_NETCHAIN > > &aPotentials, const wxString &aChainName)
std::set< std::pair< SCH_SHEET_PATH, SCH_ITEM * > > ExtractAffectedItems(const std::set< SCH_ITEM * > &aItems)
For a set of items, this will remove the connected items and their associated data including subgraph...
wxString GetResolvedSubgraphName(const CONNECTION_SUBGRAPH *aSubGraph) const
Return the fully-resolved netname for a given subgraph.
bool ercCheckBusToBusEntryConflicts(const CONNECTION_SUBGRAPH *aSubgraph)
Check one subgraph for conflicting bus entry to bus connections.
void ReplaceNetChainTerminalPin(const wxString &aNetChain, const KIID &aPrev, const KIID &aNew)
std::vector< CONNECTION_SUBGRAPH * > m_driver_subgraphs
Cache of a subset of m_subgraphs.
CONNECTION_GRAPH(const CONNECTION_GRAPH &)=delete
void ExchangeItem(SCH_ITEM *aOldItem, SCH_ITEM *aNewItem)
Replace all references to #aOldItem with #aNewItem in the graph.
const std::vector< std::unique_ptr< SCH_NETCHAIN > > & GetCommittedNetChains() const
Return user-created (committed) net chains (legacy accessor retained under net-chain API).
NET_MAP m_net_code_to_subgraphs_map
bool ercCheckFloatingWires(const CONNECTION_SUBGRAPH *aSubgraph)
Check one subgraph for floating wires.
const std::map< wxString, std::pair< KIID, KIID > > & GetNetChainTerminalOverrides() const
static wxString MakeNetChainKey(const wxString &aRawNetName, long aSubgraphCode)
Map a subgraph's raw net name and code to the stable key used as a SCH_NETCHAIN member.
void ApplyNetChainNetclasses()
Mirror each committed net chain's netclass override into the project NET_SETTINGS as a chain-derived ...
void rekeyOverrideMaps(const wxString &aOld, const wxString &aNew)
Move every net-chain override map entry keyed by aOld to aNew.
void SetLastCodes(const CONNECTION_GRAPH *aOther)
void buildConnectionGraph(std::function< void(SCH_ITEM *)> *aChangedItemHandler, bool aUnconditional)
Generate the connection graph (after all item connectivity has been updated).
void Merge(CONNECTION_GRAPH &aGraph)
Combine the input graph contents into the current graph.
SCHEMATIC * GetSchematic() const
void updatePinConnectivity(const SCH_SHEET_PATH &aSheet, SCH_PIN *aPin, SCH_CONNECTION *aConnection)
Update the connectivity of a pin and its connections.
void resolveAllDrivers()
Find all subgraphs in the connection graph and calls ResolveDrivers() in parallel.
void updateItemConnectivity(const SCH_SHEET_PATH &aSheet, const std::vector< SCH_ITEM * > &aItemList)
Update the graphical connectivity between items (i.e.
CONNECTION_SUBGRAPH * GetSubgraphForItem(SCH_ITEM *aItem) const
void generateBusAliasMembers()
Iterate through labels to create placeholders for bus elements.
bool DeleteCommittedNetChain(const wxString &aName)
Delete a committed net chain by name.
const std::map< wxString, CHAIN_TERMINAL_REFS > & GetNetChainTerminalRefOverrides() const
std::map< wxString, std::set< wxString > > m_netChainMemberNetOverrides
std::map< wxString, std::pair< KIID, KIID > > m_netChainTerminalOverrides
A subgraph is a set of items that are electrically connected on a single sheet.
wxString driverName(SCH_ITEM *aItem) const
const std::set< SCH_ITEM * > & GetItems() const
Provide a read-only reference to the items in the subgraph.
const SCH_ITEM * GetNoConnect() const
bool m_strong_driver
True if the driver is "strong": a label or power object.
friend class CONNECTION_GRAPH
SCH_ITEM * m_no_connect
No-connect item in graph, if any.
std::set< CONNECTION_SUBGRAPH * > m_absorbed_subgraphs
Set of subgraphs that have been absorbed by this subgraph.
const SCH_ITEM * GetDriver() const
SCH_ITEM * m_bus_entry
Bus entry in graph, if any.
std::mutex m_driver_name_cache_mutex
A cache of escaped netnames from schematic items.
SCH_SHEET_PATH m_sheet
On which logical sheet is the subgraph contained.
void UpdateItemConnections()
Update all items to match the driver connection.
SCH_CONNECTION * StoreImplicitConnection(std::unique_ptr< SCH_CONNECTION > aConnection)
std::set< SCH_SHEET_PIN * > m_hier_pins
Cache for lookup of any hierarchical (sheet) pins on this subgraph (for referring down).
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...
CONNECTION_GRAPH * m_graph
std::vector< SCH_ITEM * > GetAllBusLabels() const
Return all the all bus labels attached to this subgraph (if any).
std::unordered_map< SCH_ITEM *, wxString > m_driver_name_cache
const wxString & GetNameForDriver(SCH_ITEM *aItem) const
Return the candidate net name for a driver.
wxString GetNetName() const
Return the fully-qualified net name for this subgraph (if one exists)
std::vector< SCH_ITEM * > GetVectorBusLabels() const
Return all the vector-based bus labels attached to this subgraph (if any).
const std::unordered_map< std::shared_ptr< SCH_CONNECTION >, std::unordered_set< CONNECTION_SUBGRAPH * > > & GetBusParents() const
const SCH_SHEET_PATH & GetSheet() const
bool m_multiple_drivers
True if this subgraph contains more than one driver that should be shorted together in the netlist.
bool ResolveDrivers(bool aCheckMultipleDrivers=false)
Determine which potential driver should drive the subgraph.
std::set< SCH_ITEM * > m_drivers
const SCH_CONNECTION * GetDriverConnection() const
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.
std::set< std::unique_ptr< SCH_CONNECTION >, CompareConnectionPtr > m_bus_element_connections
A cache of connections that are part of this subgraph but that don't have an owning element (i....
std::unordered_set< CONNECTION_SUBGRAPH * > m_hier_children
If not null, this indicates the subgraph(s) on a lower level sheet that are linked to this one.
void AddItem(SCH_ITEM *aItem)
Add a new item to the subgraph.
const std::vector< std::pair< wxString, SCH_ITEM * > > GetNetclassesForDriver(SCH_ITEM *aItem) const
Return the resolved netclasses for the item, and the source item providing the netclass.
void Absorb(CONNECTION_SUBGRAPH *aOther)
Combine another subgraph on the same sheet into this one.
std::set< SCH_ITEM * > m_items
Contents of 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.
SCH_ITEM * m_driver
Fully-resolved driver for the subgraph (might not exist in this subgraph).
CONNECTION_SUBGRAPH(CONNECTION_GRAPH *aGraph)
bool m_is_bus_member
True if the subgraph is not actually part of a net.
void ExchangeItem(SCH_ITEM *aOldItem, SCH_ITEM *aNewItem)
Replaces all references to #aOldItem with #aNewItem in the subgraph.
CONNECTION_SUBGRAPH * m_hier_parent
If not null, this indicates the subgraph on a higher level sheet that is linked to this one.
void RemoveItem(SCH_ITEM *aItem)
bool m_local_driver
True if the driver is a local (i.e. non-global) type.
std::set< SCH_HIERLABEL * > m_hier_ports
Cache for lookup of any hierarchical ports on this subgraph (for referring up).
void getAllConnectedItems(std::set< std::pair< SCH_SHEET_PATH, SCH_ITEM * > > &aItems, std::set< CONNECTION_SUBGRAPH * > &aSubgraphs)
Find all items in the subgraph as well as child subgraphs recursively.
Definition kiid.h:48
A progress reporter interface for use in multi-threaded environments.
Holds all the data relating to one schematic.
Definition schematic.h:89
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:166
A net chain is a collection of nets that are connected together through passive components.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Schematic symbol object.
Definition sch_symbol.h:73
std::unordered_map< NET_NAME_CODE_CACHE_KEY, std::vector< CONNECTION_SUBGRAPH * > > NET_MAP
Associate a #NET_CODE_NAME with all the subgraphs in that net.
int m_MinorSchematicGraphSize
Set the number of items in a schematic graph for it to be considered "minor".
STL namespace.
std::vector< BRIDGE_EDGE > edges
std::map< wxString, std::vector< BRIDGE_NEIGHBOR > > adjacency
bool operator()(const std::unique_ptr< SCH_CONNECTION > &aLeft, const std::unique_ptr< SCH_CONNECTION > &aRight) const
bool operator==(const NET_NAME_CODE_CACHE_KEY &other) const
std::size_t operator()(const NET_NAME_CODE_CACHE_KEY &k) const
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687