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
19 * along with this program. If not, see <https://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>
38#include <wx/string.h>
39#include <progress_reporter.h>
40
41
42#ifdef DEBUG
43// Uncomment this line to enable connectivity debugging features
44// #define CONNECTIVITY_DEBUG
45#endif
46
47
49class SCHEMATIC;
50class SCH_EDIT_FRAME;
51class SCH_HIERLABEL;
52class SCH_PIN;
53class SCH_SHEET_PIN;
54class SCH_NETCHAIN;
55
56
70{
71public:
84
86 m_graph( aGraph ),
87 m_dirty( false ),
88 m_absorbed( false ),
89 m_is_bus_member( false ),
90 m_absorbed_by( nullptr ),
91 m_code( -1 ),
92 m_multiple_drivers( false ),
93 m_strong_driver( false ),
94 m_local_driver( false ),
95 m_bus_entry( nullptr ),
96 m_hier_parent( nullptr ),
97 m_driver( nullptr ),
98 m_no_connect( nullptr ),
99 m_driver_connection( nullptr )
100 {}
101
102
103 friend class CONNECTION_GRAPH;
104
114 bool ResolveDrivers( bool aCheckMultipleDrivers = false );
115
119 wxString GetNetName() const;
120
122 std::vector<SCH_ITEM*> GetVectorBusLabels() const;
123
125 std::vector<SCH_ITEM*> GetAllBusLabels() const;
126
128 const wxString& GetNameForDriver( SCH_ITEM* aItem ) const;
129
132 const std::vector<std::pair<wxString, SCH_ITEM*>>
133 GetNetclassesForDriver( SCH_ITEM* aItem ) const;
134
136 void Absorb( CONNECTION_SUBGRAPH* aOther );
137
139 void AddItem( SCH_ITEM* aItem );
140
143
145 const std::set<SCH_ITEM*>& GetItems() const
146 {
147 return m_items;
148 }
149
151 void getAllConnectedItems( std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>>& aItems,
152 std::set<CONNECTION_SUBGRAPH*>& aSubgraphs );
153
168 static PRIORITY GetDriverPriority( SCH_ITEM* aDriver );
169
171 {
172 if( m_driver )
173 return GetDriverPriority( m_driver );
174 else
175 return PRIORITY::NONE;
176 }
177
182 const SCH_ITEM* GetDriver() const
183 {
184 return m_driver;
185 }
186
191 {
192 return m_driver_connection;
193 }
194
198 const SCH_ITEM* GetNoConnect() const
199 {
200 return m_no_connect;
201 }
202
204 {
205 return m_sheet;
206 }
207
208 const std::unordered_map< std::shared_ptr<SCH_CONNECTION>,
209 std::unordered_set<CONNECTION_SUBGRAPH*> >& GetBusParents() const
210 {
211 return m_bus_parents;
212 }
213
214 void RemoveItem( SCH_ITEM* aItem );
215
219 void ExchangeItem( SCH_ITEM* aOldItem, SCH_ITEM* aNewItem );
220
221 // Use this to keep a connection pointer that is not owned by any item
222 // This will be destroyed with the subgraph
223 SCH_CONNECTION* StoreImplicitConnection( std::unique_ptr<SCH_CONNECTION> aConnection )
224 {
225 SCH_CONNECTION* raw = aConnection.get();
226
227 m_bus_element_connections.insert( std::move( aConnection ) );
228
229 return raw;
230 }
231
232private:
233 wxString driverName( SCH_ITEM* aItem ) const;
234
236
238
241
247
250
252 std::set<CONNECTION_SUBGRAPH*> m_absorbed_subgraphs;
253
254 long m_code;
255
262
265
268
271
272 std::set<SCH_ITEM*> m_drivers;
273
282 std::unordered_map< std::shared_ptr<SCH_CONNECTION>,
283 std::unordered_set<CONNECTION_SUBGRAPH*> > m_bus_neighbors;
284
290 std::unordered_map< std::shared_ptr<SCH_CONNECTION>,
291 std::unordered_set<CONNECTION_SUBGRAPH*> > m_bus_parents;
292
294 std::set<SCH_SHEET_PIN*> m_hier_pins;
295
297 std::set<SCH_HIERLABEL*> m_hier_ports;
298
301
304 std::unordered_set<CONNECTION_SUBGRAPH*> m_hier_children;
305
307 mutable std::mutex m_driver_name_cache_mutex;
308 mutable std::unordered_map<SCH_ITEM*, wxString> m_driver_name_cache;
309
312
314 std::set<SCH_ITEM*> m_items;
315
318
321
324
325 // A comparator for unique_ptr<SCH_CONNECTION> to allow storage in a set
327 {
328 bool operator()( const std::unique_ptr<SCH_CONNECTION>& aLeft,
329 const std::unique_ptr<SCH_CONNECTION>& aRight ) const
330 {
331 return aLeft.get() < aRight.get();
332 }
333 };
334
337 std::set<std::unique_ptr<SCH_CONNECTION>, CompareConnectionPtr> m_bus_element_connections;
338
339 std::mutex m_driver_mutex;
340};
341
343{
344 wxString Name;
346
347 bool operator==(const NET_NAME_CODE_CACHE_KEY& other) const
348 {
349 return Name == other.Name && Netcode == other.Netcode;
350 }
351};
352
353namespace std
354{
355 template <>
357 {
358 std::size_t operator()( const NET_NAME_CODE_CACHE_KEY& k ) const
359 {
360 const std::size_t prime = 19937;
361
362 return hash<wxString>()( k.Name ) ^ ( hash<int>()( k.Netcode ) * prime );
363 }
364 };
365}
366
368typedef std::unordered_map<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> NET_MAP;
369
375
376
381{
382public:
383 CONNECTION_GRAPH( SCHEMATIC* aSchematic = nullptr,
384 SCH_CONNECTIVITY::NETCHAIN_MANAGER* aNetChains = nullptr ) :
385 m_ownedNetChains( aNetChains ? nullptr
386 : std::make_unique<SCH_CONNECTIVITY::NETCHAIN_MANAGER>( aSchematic ) ),
387 m_netChains( aNetChains ? aNetChains : m_ownedNetChains.get() ),
388 m_last_net_code( 1 ),
389 m_last_bus_code( 1 ),
391 m_schematic( aSchematic )
392 {}
393
395
396 // We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that
397 // will only land us in trouble.
400
401 // Define QA friend functions to allow testing of private methods
405 std::unique_ptr<SCH_NETCHAIN> aChain );
407 const std::pair<std::pair<wxString, wxString>,
408 std::pair<wxString, wxString>>& aTerms,
409 const std::map<std::pair<wxString, wxString>, wxString>& aRefPinToNet,
410 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& aPotentials,
411 const wxString& aChainName );
412
413 void Reset();
414
415 void SetSchematic( SCHEMATIC* aSchematic )
416 {
417 m_schematic = aSchematic;
418 m_netChains->SetSchematic( aSchematic );
419 }
420
421 SCHEMATIC* GetSchematic() const { return m_schematic; }
422
423 void SetLastCodes( const CONNECTION_GRAPH* aOther )
424 {
428 }
429
438 void Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnconditional = false,
439 std::function<void( SCH_ITEM* )>* aChangedItemHandler = nullptr,
440 PROGRESS_REPORTER* aProgressReporter = nullptr );
441
448 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aName );
449
456
457 std::vector<const CONNECTION_SUBGRAPH*> GetBusesNeedingMigration();
458
466 int RunERC();
467
469
470 // (Deprecated accessor moved to potential net chains section; retained later.)
471
472 SCH_NETCHAIN* GetNetChainForNet( const wxString& aNet );
473 SCH_NETCHAIN* GetNetChainByName( const wxString& aName );
474
480 void SetNetChainNetClassOverrides( const std::map<wxString, wxString>& aOverrides )
481 {
482 m_netChains->SetNetChainNetClassOverrides( aOverrides );
483 }
484
485 const std::map<wxString, wxString>& GetNetChainNetClassOverrides() const
486 {
487 return m_netChains->GetNetChainNetClassOverrides();
488 }
489
492
493 void SetNetChainTerminalRefOverrides( const std::map<wxString, CHAIN_TERMINAL_REFS>& aRefs )
494 {
495 m_netChains->SetNetChainTerminalRefOverrides( aRefs );
496 }
497
498 const std::map<wxString, CHAIN_TERMINAL_REFS>& GetNetChainTerminalRefOverrides() const
499 {
500 return m_netChains->GetNetChainTerminalRefOverrides();
501 }
502
503 void SetNetChainColorOverrides( const std::map<wxString, COLOR4D>& aOverrides )
504 {
505 m_netChains->SetNetChainColorOverrides( aOverrides );
506 }
507
508 const std::map<wxString, COLOR4D>& GetNetChainColorOverrides() const
509 {
510 return m_netChains->GetNetChainColorOverrides();
511 }
512
518 void SetNetChainMemberNetOverrides( const std::map<wxString, std::set<wxString>>& aOverrides )
519 {
520 m_netChains->SetNetChainMemberNetOverrides( aOverrides );
521 }
522
523 const std::map<wxString, std::set<wxString>>& GetNetChainMemberNetOverrides() const
524 {
525 return m_netChains->GetNetChainMemberNetOverrides();
526 }
527
536 CONNECTION_SUBGRAPH* FindFirstSubgraphByName( const wxString& aNetName );
537
539
545 CONNECTION_SUBGRAPH* GetSubgraphForItemOnSheet( SCH_ITEM* aItem, const SCH_SHEET_PATH& aSheetPath ) const;
546
547 const std::vector<CONNECTION_SUBGRAPH*>& GetAllSubgraphs( const wxString& aNetName ) const;
548
558 std::vector<wxString> GetEquivalentBusNames( const wxString& aBusName ) const;
559
566 wxString GetResolvedSubgraphName( const CONNECTION_SUBGRAPH* aSubGraph ) const;
567
575 std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> ExtractAffectedItems(
576 const std::set<SCH_ITEM*> &aItems );
577
585 void Merge( CONNECTION_GRAPH& aGraph );
586
587 void RemoveItem( SCH_ITEM* aItem );
588
592 void ExchangeItem( SCH_ITEM* aOldItem, SCH_ITEM* aNewItem );
593
601 bool IsMinor() const;
602
603private:
604
610 void updateSymbolConnectivity( const SCH_SHEET_PATH& aSheet,
611 SCH_SYMBOL* aSymbol,
612 std::map<VECTOR2I, std::vector<SCH_ITEM*>>& aConnectionMap );
613
619 void updatePinConnectivity( const SCH_SHEET_PATH& aSheet,
620 SCH_PIN* aPin,
621 SCH_CONNECTION* aConnection );
622
629 SCH_ITEM* aItem,
630 std::map<VECTOR2I, std::vector<SCH_ITEM*>>& aConnectionMap );
631
659 void updateItemConnectivity( const SCH_SHEET_PATH& aSheet,
660 const std::vector<SCH_ITEM*>& aItemList );
661
679 void buildConnectionGraph( std::function<void( SCH_ITEM* )>* aChangedItemHandler,
680 bool aUnconditional );
681
685 void buildItemSubGraphs();
686
690 void resolveAllDrivers();
691
696
701
706
710 void processSubGraphs();
711
717 int assignNewNetCode( SCH_CONNECTION& aConnection );
718
724 int getOrCreateNetCode( const wxString& aNetName );
725
731 void assignNetCodesToBus( SCH_CONNECTION* aConnection );
732
742 void propagateToNeighbors( CONNECTION_SUBGRAPH* aSubgraph, bool aForce );
743
749 void removeSubgraphs( std::set<CONNECTION_SUBGRAPH*>& aSubgraphs );
750
761 static SCH_CONNECTION* matchBusMember( SCH_CONNECTION* aBusConnection,
762 SCH_CONNECTION* aSearch );
763
773 std::shared_ptr<SCH_CONNECTION> getDefaultConnection( SCH_ITEM* aItem,
774 CONNECTION_SUBGRAPH* aSubgraph );
775
776 void recacheSubgraphName( CONNECTION_SUBGRAPH* aSubgraph, const wxString& aOldName );
777
786 bool ercCheckMultipleDrivers( const CONNECTION_SUBGRAPH* aSubgraph );
787
796 bool ercCheckBusToNetConflicts( const CONNECTION_SUBGRAPH* aSubgraph );
797
808 bool ercCheckBusToBusConflicts( const CONNECTION_SUBGRAPH* aSubgraph );
809
823
833 bool ercCheckNoConnects( const CONNECTION_SUBGRAPH* aSubgraph );
834
843 bool ercCheckFloatingWires( const CONNECTION_SUBGRAPH* aSubgraph );
844
853 bool ercCheckDanglingWireEndpoints( const CONNECTION_SUBGRAPH* aSubgraph );
854
858 void collectBusMemberSiblings( const CONNECTION_SUBGRAPH* aBusParent, const wxString& aMemberName,
859 std::unordered_set<const CONNECTION_SUBGRAPH*>& aOut ) const;
860
869 bool ercCheckLabels( const CONNECTION_SUBGRAPH* aSubgraph );
870
877
884 int ercCheckHierSheets();
885
890
897 size_t hasPins( const CONNECTION_SUBGRAPH* aLocSubgraph );
898
899 void RebuildNetChains();
900
901 // Potential net chain (inferred) API -------------------------------
902public:
907 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& GetPotentialNetChains() const
908 {
909 return m_netChains->GetPotentialNetChains();
910 }
911
913 SCH_NETCHAIN* CreateNetChainFromPotential( SCH_NETCHAIN* aPotential, const wxString& aName );
914
931 SCH_NETCHAIN* CreateManualNetChain( const wxString& aName,
932 const std::set<class SCH_SYMBOL*>& aSymbols,
933 const std::set<wxString>& aNets,
934 const KIID& aTerminalPinA, const KIID& aTerminalPinB,
935 const wxString& aRefA, const wxString& aPinNumA,
936 const wxString& aRefB, const wxString& aPinNumB );
937
939 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& GetCommittedNetChains() const
940 {
941 return m_netChains->GetCommittedNetChains();
942 }
943
953
955 bool NetChainsBuilt() const { return m_netChains->NetChainsBuilt(); }
956
958 static std::function<void( SCH_CONNECTIVITY::NETCHAIN_MANAGER& )>& RebuildNetChainsTestHook();
959
968 bool DeleteCommittedNetChain( const wxString& aName );
969
976 bool RenameCommittedNetChain( const wxString& aOld, const wxString& aNew );
977
978private:
979 friend class SCHEMATIC;
980
982 std::unique_ptr<SCH_CONNECTIVITY::NETCHAIN_MANAGER> ReleaseNetChains() noexcept
983 {
984 return std::move( m_ownedNetChains );
985 }
986
988 {
989 m_netChains = &aManager;
990 m_ownedNetChains.reset();
991 }
992
1000 static SCH_NETCHAIN*
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
1008
1010 std::vector<SCH_ITEM*> m_items;
1011
1013 std::vector<CONNECTION_SUBGRAPH*> m_subgraphs;
1014
1016 std::vector<CONNECTION_SUBGRAPH*> m_driver_subgraphs;
1017
1019 std::unordered_map<SCH_SHEET_PATH, std::vector<CONNECTION_SUBGRAPH*>> m_sheet_to_subgraphs_map;
1020
1021 std::vector<std::pair<SCH_SHEET_PATH, SCH_PIN*>> m_global_power_pins;
1022
1023 std::unordered_map<wxString, std::shared_ptr<BUS_ALIAS>> m_bus_alias_cache;
1024
1025 std::unordered_map<wxString, int> m_net_name_to_code_map;
1026
1027 std::unordered_map<wxString, int> m_bus_name_to_code_map;
1028
1029 std::unordered_map<wxString, std::vector<const CONNECTION_SUBGRAPH*>> m_global_label_cache;
1030
1031 std::map< std::pair<SCH_SHEET_PATH, wxString>,
1032 std::vector<const CONNECTION_SUBGRAPH*> > m_local_label_cache;
1033
1034 std::unordered_map<wxString, std::vector<CONNECTION_SUBGRAPH*>> m_net_name_to_subgraphs_map;
1035
1038 std::unordered_map<SCH_ITEM*, std::vector<CONNECTION_SUBGRAPH*>> m_item_to_subgraph_map;
1039
1041
1042 std::unique_ptr<SCH_CONNECTIVITY::NETCHAIN_MANAGER> m_ownedNetChains;
1044
1046
1048
1050
1052
1054 std::shared_ptr<CONNECTION_GRAPH_LIFETIME> m_lifetime =
1055 std::make_shared<CONNECTION_GRAPH_LIFETIME>( CONNECTION_GRAPH_LIFETIME{ this } );
1056};
1057
1058#endif
Calculate the connectivity of a schematic and generate 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 ...
void BorrowNetChains(SCH_CONNECTIVITY::NETCHAIN_MANAGER &aManager) noexcept
int RunERC()
Run electrical rule checks on the connectivity graph.
void SetSchematic(SCHEMATIC *aSchematic)
std::shared_ptr< CONNECTION_GRAPH_LIFETIME > m_lifetime
Retired before graph teardown so late item destruction cannot enter this graph.
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 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.
std::unordered_map< SCH_ITEM *, std::vector< CONNECTION_SUBGRAPH * > > m_item_to_subgraph_map
Every subgraph referencing the item, one per instantiating sheet path for items on shared screens.
void RemoveItem(SCH_ITEM *aItem)
void collectAllDriverValues()
Map the driver values for each subgraph.
friend void boost_test_update_generic_connectivity()
int ercCheckDirectiveLabels()
Check directive labels should be connected to something.
void recacheSubgraphName(CONNECTION_SUBGRAPH *aSubgraph, const wxString &aOldName)
CONNECTION_GRAPH(SCHEMATIC *aSchematic=nullptr, SCH_CONNECTIVITY::NETCHAIN_MANAGER *aNetChains=nullptr)
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
static std::function< void(SCH_CONNECTIVITY::NETCHAIN_MANAGER &)> & RebuildNetChainsTestHook()
QA hook receives candidate state before publication and may throw to test rollback.
friend class SCHEMATIC
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::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.
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.
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 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.
bool ercCheckNoConnects(const CONNECTION_SUBGRAPH *aSubgraph)
Check one subgraph for proper presence or absence of no-connect symbols.
SCH_CONNECTIVITY::NETCHAIN_MANAGER::CHAIN_TERMINAL_REFS CHAIN_TERMINAL_REFS
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.
const std::map< wxString, wxString > & GetNetChainNetClassOverrides() const
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)
std::unique_ptr< SCH_CONNECTIVITY::NETCHAIN_MANAGER > ReleaseNetChains() noexcept
The graph keeps using the released manager.
void removeSubgraphs(std::set< CONNECTION_SUBGRAPH * > &aSubgraphs)
Remove references to the given subgraphs from all structures in the connection graph.
SCH_CONNECTIVITY::NETCHAIN_MANAGER * m_netChains
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.
std::vector< CONNECTION_SUBGRAPH * > m_driver_subgraphs
Cache of a subset of m_subgraphs.
CONNECTION_GRAPH(const CONNECTION_GRAPH &)=delete
std::unique_ptr< SCH_CONNECTIVITY::NETCHAIN_MANAGER > m_ownedNetChains
std::vector< wxString > GetEquivalentBusNames(const wxString &aBusName) const
Map a bus group name between its alias and expanded forms ({MIXED_BUS} <-> {FOO BAR HAM EGGS}...
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.
void ApplyNetChainNetclasses()
Mirror each committed net chain's netclass override into the project NET_SETTINGS as a chain-derived ...
CONNECTION_SUBGRAPH * GetSubgraphForItemOnSheet(SCH_ITEM *aItem, const SCH_SHEET_PATH &aSheetPath) const
Return the subgraph containing an item on a specific sheet path.
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
SCH_CONNECTIVITY::NETCHAIN_MANAGER::CHAIN_TERMINAL_REF CHAIN_TERMINAL_REF
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
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)
Replace 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:46
A progress reporter interface for use in multi-threaded environments.
Holds all the data relating to one schematic.
Definition schematic.h:149
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
Persistent chain configuration and the derived chains for one schematic.
std::pair< CHAIN_TERMINAL_REF, CHAIN_TERMINAL_REF > CHAIN_TERMINAL_REFS
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
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_NAME_CODE_CACHE_KEY with all the subgraphs in that net.
Value keys and the key session of the schematic connectivity engine.
STL namespace.
Lets indexed items detect graph destruction without traversing their schematic parents.
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:708