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/treectrl.h>
39#include <wx/string.h>
40#include <advanced_config.h>
41#include <progress_reporter.h>
42
43
44#ifdef DEBUG
45// Uncomment this line to enable connectivity debugging features
46// #define CONNECTIVITY_DEBUG
47#endif
48
49
51class SCHEMATIC;
52class SCH_EDIT_FRAME;
53class SCH_HIERLABEL;
54class SCH_PIN;
55class SCH_SHEET_PIN;
56class SCH_NETCHAIN;
57
58
72{
73public:
86
88 m_graph( aGraph ),
89 m_dirty( false ),
90 m_absorbed( false ),
91 m_is_bus_member( false ),
92 m_absorbed_by( nullptr ),
93 m_code( -1 ),
94 m_multiple_drivers( false ),
95 m_strong_driver( false ),
96 m_local_driver( false ),
97 m_bus_entry( nullptr ),
98 m_hier_parent( nullptr ),
99 m_driver( nullptr ),
100 m_no_connect( nullptr ),
101 m_driver_connection( nullptr )
102 {}
103
104
105 friend class CONNECTION_GRAPH;
106
116 bool ResolveDrivers( bool aCheckMultipleDrivers = false );
117
121 wxString GetNetName() const;
122
124 std::vector<SCH_ITEM*> GetVectorBusLabels() const;
125
127 std::vector<SCH_ITEM*> GetAllBusLabels() const;
128
130 const wxString& GetNameForDriver( SCH_ITEM* aItem ) const;
131
134 const std::vector<std::pair<wxString, SCH_ITEM*>>
135 GetNetclassesForDriver( SCH_ITEM* aItem ) const;
136
138 void Absorb( CONNECTION_SUBGRAPH* aOther );
139
141 void AddItem( SCH_ITEM* aItem );
142
145
147 const std::set<SCH_ITEM*>& GetItems() const
148 {
149 return m_items;
150 }
151
153 void getAllConnectedItems( std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>>& aItems,
154 std::set<CONNECTION_SUBGRAPH*>& aSubgraphs );
155
170 static PRIORITY GetDriverPriority( SCH_ITEM* aDriver );
171
173 {
174 if( m_driver )
175 return GetDriverPriority( m_driver );
176 else
177 return PRIORITY::NONE;
178 }
179
184 const SCH_ITEM* GetDriver() const
185 {
186 return m_driver;
187 }
188
193 {
194 return m_driver_connection;
195 }
196
200 const SCH_ITEM* GetNoConnect() const
201 {
202 return m_no_connect;
203 }
204
206 {
207 return m_sheet;
208 }
209
210 const std::unordered_map< std::shared_ptr<SCH_CONNECTION>,
211 std::unordered_set<CONNECTION_SUBGRAPH*> >& GetBusParents() const
212 {
213 return m_bus_parents;
214 }
215
216 void RemoveItem( SCH_ITEM* aItem );
217
221 void ExchangeItem( SCH_ITEM* aOldItem, SCH_ITEM* aNewItem );
222
223 // Use this to keep a connection pointer that is not owned by any item
224 // This will be destroyed with the subgraph
225 SCH_CONNECTION* StoreImplicitConnection( std::unique_ptr<SCH_CONNECTION> aConnection )
226 {
227 SCH_CONNECTION* raw = aConnection.get();
228
229 m_bus_element_connections.insert( std::move( aConnection ) );
230
231 return raw;
232 }
233
234private:
235 wxString driverName( SCH_ITEM* aItem ) const;
236
238
240
243
249
252
254 std::set<CONNECTION_SUBGRAPH*> m_absorbed_subgraphs;
255
256 long m_code;
257
264
267
270
273
274 std::set<SCH_ITEM*> m_drivers;
275
284 std::unordered_map< std::shared_ptr<SCH_CONNECTION>,
285 std::unordered_set<CONNECTION_SUBGRAPH*> > m_bus_neighbors;
286
292 std::unordered_map< std::shared_ptr<SCH_CONNECTION>,
293 std::unordered_set<CONNECTION_SUBGRAPH*> > m_bus_parents;
294
296 std::set<SCH_SHEET_PIN*> m_hier_pins;
297
299 std::set<SCH_HIERLABEL*> m_hier_ports;
300
303
306 std::unordered_set<CONNECTION_SUBGRAPH*> m_hier_children;
307
309 mutable std::mutex m_driver_name_cache_mutex;
310 mutable std::unordered_map<SCH_ITEM*, wxString> m_driver_name_cache;
311
314
316 std::set<SCH_ITEM*> m_items;
317
320
323
326
327 // A comparator for unique_ptr<SCH_CONNECTION> to allow storage in a set
329 {
330 bool operator()( const std::unique_ptr<SCH_CONNECTION>& aLeft,
331 const std::unique_ptr<SCH_CONNECTION>& aRight ) const
332 {
333 return aLeft.get() < aRight.get();
334 }
335 };
336
339 std::set<std::unique_ptr<SCH_CONNECTION>, CompareConnectionPtr> m_bus_element_connections;
340
341 std::mutex m_driver_mutex;
342};
343
345{
346 wxString Name;
348
349 bool operator==(const NET_NAME_CODE_CACHE_KEY& other) const
350 {
351 return Name == other.Name && Netcode == other.Netcode;
352 }
353};
354
355namespace std
356{
357 template <>
359 {
360 std::size_t operator()( const NET_NAME_CODE_CACHE_KEY& k ) const
361 {
362 const std::size_t prime = 19937;
363
364 return hash<wxString>()( k.Name ) ^ ( hash<int>()( k.Netcode ) * prime );
365 }
366 };
367}
368
370typedef std::unordered_map<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> NET_MAP;
371
377
378
383{
384public:
385 CONNECTION_GRAPH( SCHEMATIC* aSchematic = nullptr,
386 SCH_CONNECTIVITY::NETCHAIN_MANAGER* aNetChains = nullptr ) :
387 m_ownedNetChains( aNetChains ? nullptr
388 : std::make_unique<SCH_CONNECTIVITY::NETCHAIN_MANAGER>( aSchematic ) ),
389 m_netChains( aNetChains ? aNetChains : m_ownedNetChains.get() ),
390 m_last_net_code( 1 ),
391 m_last_bus_code( 1 ),
393 m_schematic( aSchematic )
394 {}
395
397
398 // We own at least one list of raw pointers. Don't let the compiler fill in copy c'tors that
399 // will only land us in trouble.
402
403 // Define QA friend functions to allow testing of private methods
407 std::unique_ptr<SCH_NETCHAIN> aChain );
409 const std::pair<std::pair<wxString, wxString>,
410 std::pair<wxString, wxString>>& aTerms,
411 const std::map<std::pair<wxString, wxString>, wxString>& aRefPinToNet,
412 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& aPotentials,
413 const wxString& aChainName );
414
415 void Reset();
416
417 void SetSchematic( SCHEMATIC* aSchematic )
418 {
419 m_schematic = aSchematic;
420 m_netChains->SetSchematic( aSchematic );
421 }
422
423 SCHEMATIC* GetSchematic() const { return m_schematic; }
424
425 void SetLastCodes( const CONNECTION_GRAPH* aOther )
426 {
430 }
431
439 void Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnconditional = false,
440 std::function<void( SCH_ITEM* )>* aChangedItemHandler = nullptr,
441 PROGRESS_REPORTER* aProgressReporter = nullptr );
442
449 std::shared_ptr<BUS_ALIAS> GetBusAlias( const wxString& aName );
450
457
458 std::vector<const CONNECTION_SUBGRAPH*> GetBusesNeedingMigration();
459
467 int RunERC();
468
470
471 // (Deprecated accessor moved to potential net chains section; retained later.)
472
473 SCH_NETCHAIN* GetNetChainForNet( const wxString& aNet );
474 SCH_NETCHAIN* GetNetChainByName( const wxString& aName );
475
481 void SetNetChainNetClassOverrides( const std::map<wxString, wxString>& aOverrides )
482 {
483 m_netChains->SetNetChainNetClassOverrides( aOverrides );
484 }
485
486 const std::map<wxString, wxString>& GetNetChainNetClassOverrides() const
487 {
488 return m_netChains->GetNetChainNetClassOverrides();
489 }
490
493
494 void SetNetChainTerminalRefOverrides( const std::map<wxString, CHAIN_TERMINAL_REFS>& aRefs )
495 {
496 m_netChains->SetNetChainTerminalRefOverrides( aRefs );
497 }
498
499 const std::map<wxString, CHAIN_TERMINAL_REFS>& GetNetChainTerminalRefOverrides() const
500 {
501 return m_netChains->GetNetChainTerminalRefOverrides();
502 }
503
504 void SetNetChainColorOverrides( const std::map<wxString, COLOR4D>& aOverrides )
505 {
506 m_netChains->SetNetChainColorOverrides( aOverrides );
507 }
508
509 const std::map<wxString, COLOR4D>& GetNetChainColorOverrides() const
510 {
511 return m_netChains->GetNetChainColorOverrides();
512 }
513
519 void SetNetChainMemberNetOverrides( const std::map<wxString, std::set<wxString>>& aOverrides )
520 {
521 m_netChains->SetNetChainMemberNetOverrides( aOverrides );
522 }
523
524 const std::map<wxString, std::set<wxString>>& GetNetChainMemberNetOverrides() const
525 {
526 return m_netChains->GetNetChainMemberNetOverrides();
527 }
528
537 CONNECTION_SUBGRAPH* FindFirstSubgraphByName( const wxString& aNetName );
538
540
541 const std::vector<CONNECTION_SUBGRAPH*>& GetAllSubgraphs( const wxString& aNetName ) const;
542
552 std::vector<wxString> GetEquivalentBusNames( const wxString& aBusName ) const;
553
560 wxString GetResolvedSubgraphName( const CONNECTION_SUBGRAPH* aSubGraph ) const;
561
569 std::set<std::pair<SCH_SHEET_PATH, SCH_ITEM*>> ExtractAffectedItems(
570 const std::set<SCH_ITEM*> &aItems );
571
579 void Merge( CONNECTION_GRAPH& aGraph );
580
581 void RemoveItem( SCH_ITEM* aItem );
582
586 void ExchangeItem( SCH_ITEM* aOldItem, SCH_ITEM* aNewItem );
587
595 bool IsMinor() const
596 {
597 return static_cast<ssize_t>( m_items.size() )
599 }
600
601private:
602
608 void updateSymbolConnectivity( const SCH_SHEET_PATH& aSheet,
609 SCH_SYMBOL* aSymbol,
610 std::map<VECTOR2I, std::vector<SCH_ITEM*>>& aConnectionMap );
611
617 void updatePinConnectivity( const SCH_SHEET_PATH& aSheet,
618 SCH_PIN* aPin,
619 SCH_CONNECTION* aConnection );
620
627 SCH_ITEM* aItem,
628 std::map<VECTOR2I, std::vector<SCH_ITEM*>>& aConnectionMap );
629
657 void updateItemConnectivity( const SCH_SHEET_PATH& aSheet,
658 const std::vector<SCH_ITEM*>& aItemList );
659
677 void buildConnectionGraph( std::function<void( SCH_ITEM* )>* aChangedItemHandler,
678 bool aUnconditional );
679
683 void buildItemSubGraphs();
684
688 void resolveAllDrivers();
689
694
699
704
708 void processSubGraphs();
709
715 int assignNewNetCode( SCH_CONNECTION& aConnection );
716
722 int getOrCreateNetCode( const wxString& aNetName );
723
729 void assignNetCodesToBus( SCH_CONNECTION* aConnection );
730
740 void propagateToNeighbors( CONNECTION_SUBGRAPH* aSubgraph, bool aForce );
741
747 void removeSubgraphs( std::set<CONNECTION_SUBGRAPH*>& aSubgraphs );
748
759 static SCH_CONNECTION* matchBusMember( SCH_CONNECTION* aBusConnection,
760 SCH_CONNECTION* aSearch );
761
771 std::shared_ptr<SCH_CONNECTION> getDefaultConnection( SCH_ITEM* aItem,
772 CONNECTION_SUBGRAPH* aSubgraph );
773
774 void recacheSubgraphName( CONNECTION_SUBGRAPH* aSubgraph, const wxString& aOldName );
775
784 bool ercCheckMultipleDrivers( const CONNECTION_SUBGRAPH* aSubgraph );
785
794 bool ercCheckBusToNetConflicts( const CONNECTION_SUBGRAPH* aSubgraph );
795
806 bool ercCheckBusToBusConflicts( const CONNECTION_SUBGRAPH* aSubgraph );
807
821
831 bool ercCheckNoConnects( const CONNECTION_SUBGRAPH* aSubgraph );
832
841 bool ercCheckFloatingWires( const CONNECTION_SUBGRAPH* aSubgraph );
842
851 bool ercCheckDanglingWireEndpoints( const CONNECTION_SUBGRAPH* aSubgraph );
852
856 void collectBusMemberSiblings( const CONNECTION_SUBGRAPH* aBusParent, const wxString& aMemberName,
857 std::unordered_set<const CONNECTION_SUBGRAPH*>& aOut ) const;
858
868 bool ercCheckLabels( const CONNECTION_SUBGRAPH* aSubgraph );
869
876
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 { return m_netChains->GetPotentialNetChains(); }
908
910 SCH_NETCHAIN* CreateNetChainFromPotential( SCH_NETCHAIN* aPotential, const wxString& aName );
911
928 SCH_NETCHAIN* CreateManualNetChain( const wxString& aName,
929 const std::set<class SCH_SYMBOL*>& aSymbols,
930 const std::set<wxString>& aNets,
931 const KIID& aTerminalPinA, const KIID& aTerminalPinB,
932 const wxString& aRefA, const wxString& aPinNumA,
933 const wxString& aRefB, const wxString& aPinNumB );
934
936 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& GetCommittedNetChains() const { return m_netChains->GetCommittedNetChains(); }
937
947
949 bool NetChainsBuilt() const { return m_netChains->NetChainsBuilt(); }
950
952 static std::function<void( SCH_CONNECTIVITY::NETCHAIN_MANAGER& )>& RebuildNetChainsTestHook();
953
962 bool DeleteCommittedNetChain( const wxString& aName );
963
970 bool RenameCommittedNetChain( const wxString& aOld, const wxString& aNew );
971
972private:
973 friend class SCHEMATIC;
974
976 std::unique_ptr<SCH_CONNECTIVITY::NETCHAIN_MANAGER> ReleaseNetChains() noexcept
977 {
978 return std::move( m_ownedNetChains );
979 }
980
982 {
983 m_netChains = &aManager;
984 m_ownedNetChains.reset();
985 }
986
995 const CHAIN_TERMINAL_REFS& aTermRefs,
996 const std::map<std::pair<wxString, wxString>, wxString>& aRefPinToNet,
997 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& aPotentials,
998 const wxString& aChainName );
999
1002
1004 std::vector<SCH_ITEM*> m_items;
1005
1007 std::vector<CONNECTION_SUBGRAPH*> m_subgraphs;
1008
1010 std::vector<CONNECTION_SUBGRAPH*> m_driver_subgraphs;
1011
1013 std::unordered_map<SCH_SHEET_PATH, std::vector<CONNECTION_SUBGRAPH*>> m_sheet_to_subgraphs_map;
1014
1015 std::vector<std::pair<SCH_SHEET_PATH, SCH_PIN*>> m_global_power_pins;
1016
1017 std::unordered_map<wxString, std::shared_ptr<BUS_ALIAS>> m_bus_alias_cache;
1018
1019 std::unordered_map<wxString, int> m_net_name_to_code_map;
1020
1021 std::unordered_map<wxString, int> m_bus_name_to_code_map;
1022
1023 std::unordered_map<wxString, std::vector<const CONNECTION_SUBGRAPH*>> m_global_label_cache;
1024
1025 std::map< std::pair<SCH_SHEET_PATH, wxString>,
1026 std::vector<const CONNECTION_SUBGRAPH*> > m_local_label_cache;
1027
1028 std::unordered_map<wxString, std::vector<CONNECTION_SUBGRAPH*>> m_net_name_to_subgraphs_map;
1029
1032 std::unordered_map<SCH_ITEM*, std::vector<CONNECTION_SUBGRAPH*>> m_item_to_subgraph_map;
1033
1035
1036 std::unique_ptr<SCH_CONNECTIVITY::NETCHAIN_MANAGER> m_ownedNetChains;
1038
1040
1042
1044
1046
1048 std::shared_ptr<CONNECTION_GRAPH_LIFETIME> m_lifetime =
1049 std::make_shared<CONNECTION_GRAPH_LIFETIME>( CONNECTION_GRAPH_LIFETIME{ this } );
1050};
1051
1052#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 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 ...
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)
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:46
A progress reporter interface for use in multi-threaded environments.
Holds all the data relating to one schematic.
Definition schematic.h:148
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:165
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:75
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.
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:683