KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_netchain.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) 2023 KiCad Developers
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef SCH_NETCHAIN_H
21#define SCH_NETCHAIN_H
22
23#include <set>
24#include <utility>
25#include <vector>
26#include <wx/string.h>
27#include <gal/color4d.h>
28#include <kiid.h>
29
31
37{
38public:
41 static constexpr char SYNTHETIC_NET_PREFIX[] = "__SG_";
42
44
45 void SetName( const wxString& aName ) { m_name = aName; }
46 const wxString& GetName() const { return m_name; }
47
48 static bool IsValidName( const wxString& aName )
49 {
50 if( aName.IsEmpty() )
51 return false;
52
53 for( wxUniChar c : aName )
54 if( c == '"' || c == '\'' || c == '(' || c == ')' || c == ' ' )
55 return false;
56
57 return true;
58 }
59
60 void AddNet( const wxString& aNet )
61 {
62 m_nets.insert( aNet );
63 m_orderedNetsDirty = true;
64 }
65
66 void RemoveNet( const wxString& aNet )
67 {
68 m_nets.erase( aNet );
69 m_orderedNetsDirty = true;
70 }
71
72 void ReplaceNets( const std::set<wxString>& aNew )
73 {
74 m_nets = aNew;
75 m_orderedNetsDirty = true;
76 }
77
78 // Track a symbol that participates in this chain (2-pin passthrough component).
79 void AddSymbol( class SCH_SYMBOL* aSymbol )
80 {
81 m_symbols.insert( aSymbol );
82 m_orderedNetsDirty = true;
83 }
84
85 const std::set<class SCH_SYMBOL*>& GetSymbols() const { return m_symbols; }
86
87 void AbsorbSymbolsFrom( const SCH_NETCHAIN& aOther )
88 {
89 m_symbols.insert( aOther.m_symbols.begin(), aOther.m_symbols.end() );
90 m_orderedNetsDirty = true;
91 }
92
93 // The symbol set holds non-owning raw pointers to schematic items. Callers must invoke
94 // this before any pass that may free those items (e.g. CONNECTION_GRAPH::Reset()).
96 {
97 m_symbols.clear();
98 m_orderedNetsDirty = true;
99 }
100
101 const std::set<wxString>& GetNets() const { return m_nets; }
102
114 const std::vector<wxString>& GetOrderedNets( CONNECTION_GRAPH* aGraph ) const;
115
121 wxString GetTerminalNetName( int aIdx, CONNECTION_GRAPH* aGraph ) const;
122
123 void SetTerminalPins( const KIID& aPinA, const KIID& aPinB )
124 {
125 m_terminalPins[0] = aPinA;
126 m_terminalPins[1] = aPinB;
127 m_orderedNetsDirty = true;
128 }
129
130 const KIID& GetTerminalPinA() const { return m_terminalPins[0]; }
131 const KIID& GetTerminalPinB() const { return m_terminalPins[1]; }
132
133 void ReplaceTerminalPin( const KIID& aPrev, const KIID& aNew )
134 {
135 if( m_terminalPins[0] == aPrev )
136 m_terminalPins[0] = aNew;
137 else if( m_terminalPins[1] == aPrev )
138 m_terminalPins[1] = aNew;
139 else
140 return;
141
142 m_orderedNetsDirty = true;
143 }
144
150 void SetNetClass( const wxString& aNetClass ) { m_netClass = aNetClass; }
151 const wxString& GetNetClass() const { return m_netClass; }
152
159 void SetColor( const KIGFX::COLOR4D& aColor ) { m_color = aColor; }
160 const KIGFX::COLOR4D& GetColor() const { return m_color; }
161
162 void SetTerminalRefs( const wxString& aRefA, const wxString& aPinA, const wxString& aRefB, const wxString& aPinB )
163 {
164 m_terminalRef[0] = aRefA;
165 m_terminalPinNum[0] = aPinA;
166 m_terminalRef[1] = aRefB;
167 m_terminalPinNum[1] = aPinB;
168 }
169
170 const wxString& GetTerminalRef( int aIdx ) const
171 {
172 wxASSERT( aIdx >= 0 && aIdx < 2 );
173 return m_terminalRef[aIdx];
174 }
175
176 const wxString& GetTerminalPinNum( int aIdx ) const
177 {
178 wxASSERT( aIdx >= 0 && aIdx < 2 );
179 return m_terminalPinNum[aIdx];
180 }
181
182private:
183 wxString m_name;
184 std::set<wxString> m_nets;
185 std::set<class SCH_SYMBOL*> m_symbols;
187 wxString m_terminalRef[2];
188 wxString m_terminalPinNum[2];
189 wxString m_netClass;
191
192 // Cached topologically ordered net list. Populated lazily by GetOrderedNets()
193 // and invalidated by any topology-mutating accessor above.
194 mutable std::vector<wxString> m_orderedNets;
195 mutable bool m_orderedNetsDirty = true;
196};
197
198#endif
Calculate the connectivity of a schematic and generates netlists.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
Definition color4d.h:402
Definition kiid.h:48
const KIID & GetTerminalPinB() const
const std::set< wxString > & GetNets() const
void AddSymbol(class SCH_SYMBOL *aSymbol)
std::set< wxString > m_nets
const wxString & GetTerminalRef(int aIdx) const
const wxString & GetNetClass() const
std::vector< wxString > m_orderedNets
const KIGFX::COLOR4D & GetColor() const
const std::vector< wxString > & GetOrderedNets(CONNECTION_GRAPH *aGraph) const
Return the chain's member nets ordered from terminal pin A's net to terminal pin B's net along the sh...
const wxString & GetName() const
void ReplaceTerminalPin(const KIID &aPrev, const KIID &aNew)
static constexpr char SYNTHETIC_NET_PREFIX[]
Prefix used when synthesising net names for unnamed subgraphs.
static bool IsValidName(const wxString &aName)
KIID m_terminalPins[2]
wxString m_name
wxString m_terminalPinNum[2]
std::set< class SCH_SYMBOL * > m_symbols
KIGFX::COLOR4D m_color
void SetTerminalPins(const KIID &aPinA, const KIID &aPinB)
void ClearSymbols()
bool m_orderedNetsDirty
wxString GetTerminalNetName(int aIdx, CONNECTION_GRAPH *aGraph) const
Resolve terminal pin aIdx (0 or 1) to the net-chain key of its owning subgraph via aGraph.
void RemoveNet(const wxString &aNet)
wxString m_netClass
void ReplaceNets(const std::set< wxString > &aNew)
const std::set< class SCH_SYMBOL * > & GetSymbols() const
void SetNetClass(const wxString &aNetClass)
Net chains may override the netclass applied to every member net.
wxString m_terminalRef[2]
void AbsorbSymbolsFrom(const SCH_NETCHAIN &aOther)
const wxString & GetTerminalPinNum(int aIdx) const
void SetColor(const KIGFX::COLOR4D &aColor)
Optional display color for the chain.
const KIID & GetTerminalPinA() const
void AddNet(const wxString &aNet)
void SetName(const wxString &aName)
void SetTerminalRefs(const wxString &aRefA, const wxString &aPinA, const wxString &aRefB, const wxString &aPinB)
Schematic symbol object.
Definition sch_symbol.h:73