KiCad PCB EDA Suite
Loading...
Searching...
No Matches
conn_netchain_manager.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <functional>
23#include <map>
24#include <memory>
25#include <set>
26#include <vector>
27#include <unordered_map>
28#include <sch_netchain.h>
29#include <gal/color4d.h>
30
32class SCHEMATIC;
33class SCH_ITEM;
34class SCH_PIN;
35class SCH_SCREEN;
36class SCH_SHEET_PATH;
37class SCH_SYMBOL;
38class NET_SETTINGS;
39void boost_test_inject_committed_net_chain( CONNECTION_GRAPH&, std::unique_ptr<SCH_NETCHAIN> );
40
41namespace SCH_CONNECTIVITY
42{
43struct NETCHAIN_INPUT;
44
47{
48public:
49 explicit NETCHAIN_MANAGER( SCHEMATIC* aSchematic ) : m_schematic( aSchematic ) {}
50
51 void Rebuild( const NETCHAIN_INPUT& aConnectivity,
52 const std::function<void( NETCHAIN_MANAGER& )>& aBeforePublish = {} );
53 void ClearDerived();
55 void Merge( NETCHAIN_MANAGER& aOther );
56 void SetSchematic( SCHEMATIC* aSchematic ) { m_schematic = aSchematic; }
57
59 SCH_PIN* aPinB, const SCH_SHEET_PATH& aPathB );
60 static wxString NetKeyForItem( const SCH_ITEM& aItem, const SCH_SHEET_PATH& aPath );
61
66 std::map<SCH_SYMBOL*, SCH_SCREEN*> GetBridgeSymbols( const SCH_NETCHAIN& aChain,
67 const wxString& aNetKey ) const;
68
69 SCH_NETCHAIN* GetNetChainForNet( const wxString& aNet );
70 SCH_NETCHAIN* GetNetChainByName( const wxString& aName );
72 {
73 wxString chain;
74 int endpoint = 0;
77 };
78
79 bool ReplaceNetChainTerminalPin( const TERMINAL_CHANGE& aChange );
80
86 void SetNetChainNetClassOverrides( const std::map<wxString, wxString>& aOverrides )
87 {
88 m_netChainNetClassOverrides = aOverrides;
89 }
90
91 const std::map<wxString, wxString>& GetNetChainNetClassOverrides() const
92 {
94 }
95
97 {
98 wxString ref;
99 wxString pin;
100 };
101 using CHAIN_TERMINAL_REFS = std::pair<CHAIN_TERMINAL_REF, CHAIN_TERMINAL_REF>;
102
103 void SetNetChainTerminalRefOverrides( const std::map<wxString, CHAIN_TERMINAL_REFS>& aRefs )
104 {
106 }
107
108 const std::map<wxString, CHAIN_TERMINAL_REFS>& GetNetChainTerminalRefOverrides() const
109 {
111 }
112
113 void SetNetChainColorOverrides( const std::map<wxString, KIGFX::COLOR4D>& aOverrides )
114 {
115 m_netChainColorOverrides = aOverrides;
116 }
117
118 const std::map<wxString, KIGFX::COLOR4D>& GetNetChainColorOverrides() const
119 {
121 }
122
128 void SetNetChainMemberNetOverrides( const std::map<wxString, std::set<wxString>>& aOverrides )
129 {
130 m_netChainMemberNetOverrides = aOverrides;
131 }
132
133 const std::map<wxString, std::set<wxString>>& GetNetChainMemberNetOverrides() const
134 {
136 }
137
142 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& GetPotentialNetChains() const { return m_potentialNetChains; }
143
145 SCH_NETCHAIN* CreateNetChainFromPotential( SCH_NETCHAIN* aPotential, const wxString& aName );
146
163 SCH_NETCHAIN* CreateManualNetChain( const wxString& aName,
164 const std::set<class SCH_SYMBOL*>& aSymbols,
165 const std::set<wxString>& aNets,
166 const KIID& aTerminalPinA, const KIID& aTerminalPinB,
167 const wxString& aRefA, const wxString& aPinNumA,
168 const wxString& aRefB, const wxString& aPinNumB );
169
171 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& GetCommittedNetChains() const { return m_committedNetChains; }
172
182
184 bool NetChainsBuilt() const { return m_netChainsBuilt; }
185
195 bool DeleteCommittedNetChain( const wxString& aName );
196
203 bool RenameCommittedNetChain( const wxString& aOld, const wxString& aNew );
204
205private:
206 void rebuild( const NETCHAIN_INPUT& aConnectivity );
207 void setSymbolName( SCH_SYMBOL* aSymbol, const wxString& aName );
208 bool resolveTerminals( SCH_NETCHAIN& aChain, const CHAIN_TERMINAL_REFS* aSavedRefs = nullptr );
210 void storeTerminalRefs( const SCH_NETCHAIN& aChain );
211
213 wxString NetKeyForTerminal( const KIID& aPin, const KIID_PATH& aSheet ) const;
214
216 void storeMemberNets( const wxString& aName, const std::set<wxString>& aNets );
217
219 std::shared_ptr<NET_SETTINGS> liveNetSettings() const;
220
221 friend class ::CONNECTION_GRAPH;
222 friend void ::boost_test_inject_committed_net_chain( CONNECTION_GRAPH&,
223 std::unique_ptr<SCH_NETCHAIN> );
224
233 const CHAIN_TERMINAL_REFS& aTermRefs,
234 const std::map<std::pair<wxString, wxString>, wxString>& aRefPinToNet,
235 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& aPotentials,
236 const wxString& aChainName );
237
238 static SCH_NETCHAIN* findPotentialChain( const std::vector<std::unique_ptr<SCH_NETCHAIN>>& aPotentials,
239 const wxString& aNetA, const wxString& aNetB );
240
246 void rekeyOverrideMaps( const wxString& aOld, const wxString& aNew );
247
255 void refreshCommittedChainPayload( SCH_NETCHAIN* aTarget, const std::set<wxString>& aNets,
256 const std::set<class SCH_SYMBOL*>& aSymbols );
257
262 void refreshCommittedChainFromPotential( SCH_NETCHAIN* aTarget, const SCH_NETCHAIN& aSource );
263
264 // Bridge-graph helper types shared by RebuildNetChains() and FindNetChainPathsBetweenPins().
265 // A bridge edge represents a 2-pin passthrough symbol that ties two distinct subgraph nets
266 // together; the bridge graph is the adjacency built from the surviving (non-power-touching)
267 // edges after the leaf-prune pass.
268
269 struct SHEET_SYMBOLS;
270
272 {
273 wxString a;
274 wxString b;
277 };
278
280 {
281 wxString other;
283 };
284
286 {
287 std::map<wxString, std::vector<BRIDGE_NEIGHBOR>> adjacency;
288 std::vector<BRIDGE_EDGE> edges;
289 };
290
301 BRIDGE_GRAPH buildBridgeAdjacency( const std::vector<SHEET_SYMBOLS>& aSheets );
302
303 std::vector<std::unique_ptr<SCH_NETCHAIN>> m_committedNetChains;
304 std::vector<std::unique_ptr<SCH_NETCHAIN>> m_potentialNetChains;
305 std::vector<BRIDGE_EDGE> m_bridgeEdges;
306 bool m_netChainsBuilt = false;
307 std::map<wxString, wxString> m_netChainNetClassOverrides;
308 std::map<wxString, KIGFX::COLOR4D> m_netChainColorOverrides;
309 std::map<wxString, CHAIN_TERMINAL_REFS> m_netChainTerminalRefOverrides;
310 std::map<wxString, std::set<wxString>> m_netChainMemberNetOverrides;
311
312 std::unordered_map<SCH_SYMBOL*, wxString>* m_pendingSymbolNames = nullptr;
314};
315} // namespace SCH_CONNECTIVITY
Calculate the connectivity of a schematic and generate netlists.
Definition kiid.h:46
NET_SETTINGS stores various net-related settings in a project context.
Holds all the data relating to one schematic.
Definition schematic.h:148
Persistent chain configuration and the derived chains for one schematic.
void refreshCommittedChainPayload(SCH_NETCHAIN *aTarget, const std::set< wxString > &aNets, const std::set< class SCH_SYMBOL * > &aSymbols)
Replace the derived-view payload on aTarget with explicitly supplied member nets, and symbols.
std::map< wxString, wxString > m_netChainNetClassOverrides
void rekeyOverrideMaps(const wxString &aOld, const wxString &aNew)
Move every net-chain override map entry keyed by aOld to aNew.
std::vector< std::unique_ptr< SCH_NETCHAIN > > m_potentialNetChains
last built potential (uncommitted) net chains
void SetNetChainColorOverrides(const std::map< wxString, KIGFX::COLOR4D > &aOverrides)
SCH_NETCHAIN * GetNetChainForNet(const wxString &aNet)
bool refreshTerminalReferences(SCH_NETCHAIN &aChain)
std::map< wxString, std::set< wxString > > m_netChainMemberNetOverrides
void storeMemberNets(const wxString &aName, const std::set< wxString > &aNets)
Record the persistable subset of aNets as the restore fallback for aName.
void storeTerminalRefs(const SCH_NETCHAIN &aChain)
const std::vector< std::unique_ptr< SCH_NETCHAIN > > & GetCommittedNetChains() const
Return user-created (committed) net chains (legacy accessor retained under net-chain API).
SCH_NETCHAIN * GetNetChainByName(const wxString &aName)
static SCH_NETCHAIN * findPotentialChain(const std::vector< std::unique_ptr< SCH_NETCHAIN > > &aPotentials, const wxString &aNetA, const wxString &aNetB)
SCH_NETCHAIN * FindPotentialNetChainBetweenPins(SCH_PIN *aPinA, const SCH_SHEET_PATH &aPathA, SCH_PIN *aPinB, const SCH_SHEET_PATH &aPathB)
void SetNetChainNetClassOverrides(const std::map< wxString, wxString > &aOverrides)
Stash per-net-chain netclass overrides read from the schematic file.
const std::map< wxString, CHAIN_TERMINAL_REFS > & GetNetChainTerminalRefOverrides() const
void setSymbolName(SCH_SYMBOL *aSymbol, const wxString &aName)
void rebuild(const NETCHAIN_INPUT &aConnectivity)
BRIDGE_GRAPH buildBridgeAdjacency(const std::vector< SHEET_SYMBOLS > &aSheets)
Build the bridge graph used for net-chain discovery.
const std::map< wxString, std::set< wxString > > & GetNetChainMemberNetOverrides() const
bool ReplaceNetChainTerminalPin(const TERMINAL_CHANGE &aChange)
std::shared_ptr< NET_SETTINGS > liveNetSettings() const
Project net settings, or null for staged and temporary managers.
wxString NetKeyForTerminal(const KIID &aPin, const KIID_PATH &aSheet) const
Resolve a terminal pin UUID on a sheet instance to its chain member key.
std::map< wxString, CHAIN_TERMINAL_REFS > m_netChainTerminalRefOverrides
std::map< SCH_SYMBOL *, SCH_SCREEN * > GetBridgeSymbols(const SCH_NETCHAIN &aChain, const wxString &aNetKey) const
Symbols from the last rebuild whose passthrough joins aNetKey to another member of aChain,...
void Rebuild(const NETCHAIN_INPUT &aConnectivity, const std::function< void(NETCHAIN_MANAGER &)> &aBeforePublish={})
std::vector< std::unique_ptr< SCH_NETCHAIN > > m_committedNetChains
std::map< wxString, KIGFX::COLOR4D > m_netChainColorOverrides
void Merge(NETCHAIN_MANAGER &aOther)
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 ...
bool DeleteCommittedNetChain(const wxString &aName)
Delete a committed net chain by name.
bool resolveTerminals(SCH_NETCHAIN &aChain, const CHAIN_TERMINAL_REFS *aSavedRefs=nullptr)
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.
void refreshCommittedChainFromPotential(SCH_NETCHAIN *aTarget, const SCH_NETCHAIN &aSource)
Refresh aTarget from an inferred potential chain and resync its persisted member-net fallback.
const std::vector< std::unique_ptr< SCH_NETCHAIN > > & GetPotentialNetChains() const
Potential net chains are inferred groupings produced by RebuildNetChains() but not yet user-committed...
const std::map< wxString, wxString > & GetNetChainNetClassOverrides() const
void SetNetChainTerminalRefOverrides(const std::map< wxString, CHAIN_TERMINAL_REFS > &aRefs)
std::vector< BRIDGE_EDGE > m_bridgeEdges
raw bridge edges from the last rebuild
void SetSchematic(SCHEMATIC *aSchematic)
std::pair< CHAIN_TERMINAL_REF, CHAIN_TERMINAL_REF > CHAIN_TERMINAL_REFS
static wxString NetKeyForItem(const SCH_ITEM &aItem, const SCH_SHEET_PATH &aPath)
SCH_NETCHAIN * CreateNetChainFromPotential(SCH_NETCHAIN *aPotential, const wxString &aName)
Promote a potential net chain to an actual user net chain with the provided name.
bool NetChainsBuilt() const
Returns true once RebuildNetChains() has completed at least once on this graph.
void SetNetChainMemberNetOverrides(const std::map< wxString, std::set< wxString > > &aOverrides)
Stash per-chain member-net lists read from the schematic file.
void ApplyNetChainNetclasses()
Mirror each committed net chain's netclass override into the project NET_SETTINGS as a chain-derived ...
const std::map< wxString, KIGFX::COLOR4D > & GetNetChainColorOverrides() const
std::unordered_map< SCH_SYMBOL *, wxString > * m_pendingSymbolNames
bool RenameCommittedNetChain(const wxString &aOld, const wxString &aNew)
Rename a committed net chain.
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.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:75
void boost_test_inject_committed_net_chain(CONNECTION_GRAPH &, std::unique_ptr< SCH_NETCHAIN >)
KIID niluuid(0)
Immediate-use netchain input; shared-screen items are qualified by their instance.
std::map< wxString, std::vector< BRIDGE_NEIGHBOR > > adjacency