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 <wx/string.h>
26#include <gal/color4d.h>
27#include <kiid.h>
28
34{
35public:
38 static constexpr char SYNTHETIC_NET_PREFIX[] = "__SG_";
39
41
42 void SetName( const wxString& aName ) { m_name = aName; }
43 const wxString& GetName() const { return m_name; }
44
45 static bool IsValidName( const wxString& aName )
46 {
47 if( aName.IsEmpty() )
48 return false;
49
50 for( wxUniChar c : aName )
51 if( c == '"' || c == '\'' || c == '(' || c == ')' || c == ' ' )
52 return false;
53
54 return true;
55 }
56
57 void AddNet( const wxString& aNet ) { m_nets.insert( aNet ); }
58 void RemoveNet( const wxString& aNet ) { m_nets.erase( aNet ); }
59 void ReplaceNets( const std::set<wxString>& aNew ) { m_nets = aNew; }
60
61 // Track a symbol that participates in this chain (2-pin passthrough component).
62 void AddSymbol( class SCH_SYMBOL* aSymbol ) { m_symbols.insert( aSymbol ); }
63 const std::set<class SCH_SYMBOL*>& GetSymbols() const { return m_symbols; }
64 void AbsorbSymbolsFrom( const SCH_NETCHAIN& aOther )
65 {
66 m_symbols.insert( aOther.m_symbols.begin(), aOther.m_symbols.end() );
67 }
68
69 // The symbol set holds non-owning raw pointers to schematic items. Callers must invoke
70 // this before any pass that may free those items (e.g. CONNECTION_GRAPH::Reset()).
71 void ClearSymbols() { m_symbols.clear(); }
72
73 const std::set<wxString>& GetNets() const { return m_nets; }
74
75 void SetTerminalPins( const KIID& aPinA, const KIID& aPinB )
76 {
77 m_terminalPins[0] = aPinA;
78 m_terminalPins[1] = aPinB;
79 }
80
81 const KIID& GetTerminalPinA() const { return m_terminalPins[0]; }
82 const KIID& GetTerminalPinB() const { return m_terminalPins[1]; }
83
84 void ReplaceTerminalPin( const KIID& aPrev, const KIID& aNew )
85 {
86 if( m_terminalPins[0] == aPrev )
87 m_terminalPins[0] = aNew;
88 else if( m_terminalPins[1] == aPrev )
89 m_terminalPins[1] = aNew;
90 }
91
97 void SetNetClass( const wxString& aNetClass ) { m_netClass = aNetClass; }
98 const wxString& GetNetClass() const { return m_netClass; }
99
106 void SetColor( const KIGFX::COLOR4D& aColor ) { m_color = aColor; }
107 const KIGFX::COLOR4D& GetColor() const { return m_color; }
108
109 void SetTerminalRefs( const wxString& aRefA, const wxString& aPinA, const wxString& aRefB, const wxString& aPinB )
110 {
111 m_terminalRef[0] = aRefA;
112 m_terminalPinNum[0] = aPinA;
113 m_terminalRef[1] = aRefB;
114 m_terminalPinNum[1] = aPinB;
115 }
116
117 const wxString& GetTerminalRef( int aIdx ) const
118 {
119 wxASSERT( aIdx >= 0 && aIdx < 2 );
120 return m_terminalRef[aIdx];
121 }
122
123 const wxString& GetTerminalPinNum( int aIdx ) const
124 {
125 wxASSERT( aIdx >= 0 && aIdx < 2 );
126 return m_terminalPinNum[aIdx];
127 }
128
129private:
130 wxString m_name;
131 std::set<wxString> m_nets;
132 std::set<class SCH_SYMBOL*> m_symbols;
134 wxString m_terminalRef[2];
135 wxString m_terminalPinNum[2];
136 wxString m_netClass;
138};
139
140#endif
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
const KIGFX::COLOR4D & GetColor() const
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()
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:76