KiCad PCB EDA Suite
sch_connection.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 (C) 2021 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 along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef _SCH_CONNECTION_H
23#define _SCH_CONNECTION_H
24
25#include <memory>
26#include <unordered_set>
27
28#include <wx/regex.h>
29#include <bus_alias.h>
30#include <sch_sheet_path.h>
31
32
34class SCH_ITEM;
35class SCH_SHEET_PATH;
36class MSG_PANEL_ITEM;
37
38
40{
41 NONE,
42 NET,
43 BUS,
44 BUS_GROUP,
45};
46
61{
62public:
63 SCH_CONNECTION( SCH_ITEM* aParent = nullptr, SCH_SHEET_PATH aPath = SCH_SHEET_PATH() );
64
66
68 {}
69
74 bool operator==( const SCH_CONNECTION& aOther ) const;
75
76 bool operator!=( const SCH_CONNECTION& aOther ) const;
77
78 void SetGraph( CONNECTION_GRAPH* aGraph )
79 {
80 m_graph = aGraph;
81 }
82
89 void ConfigureFromLabel( const wxString& aLabel );
90
94 void Reset();
95
101 void Clone( const SCH_CONNECTION& aOther );
102
103 SCH_ITEM* Parent() const { return m_parent; }
104
105 SCH_ITEM* Driver() const { return m_driver; }
106 void SetDriver( SCH_ITEM* aItem );
107
108 SCH_SHEET_PATH Sheet() const { return m_sheet; }
109 void SetSheet( SCH_SHEET_PATH aSheet );
110
112
119 bool IsDriver() const;
120
121 bool IsBus() const
122 {
124 }
125
126 bool IsNet() const
127 {
128 return ( m_type == CONNECTION_TYPE::NET );
129 }
130
131 bool IsUnconnected() const { return ( m_type == CONNECTION_TYPE::NONE ); }
132
133 bool IsDirty() const { return m_dirty; }
134 void SetDirty() { m_dirty = true; }
135 void ClearDirty() { m_dirty = false; }
136
137 bool HasDriverChanged() const;
138 void ClearDriverChanged();
139 void* GetLastDriver() const { return m_lastDriver; }
140
141 wxString Name( bool aIgnoreSheet = false ) const;
142
143 wxString LocalName() const { return m_local_name; }
144
145 wxString FullLocalName() const
146 {
148 }
149
150 void SetName( const wxString& aName )
151 {
152 m_name = aName;
153 recacheName();
154 }
155
156 wxString Prefix() const { return m_prefix; }
157 void SetPrefix( const wxString& aPrefix );
158
159 wxString BusPrefix() const { return m_bus_prefix; }
160
161 wxString Suffix() const { return m_suffix; }
162 void SetSuffix( const wxString& aSuffix );
163
164 CONNECTION_TYPE Type() const { return m_type; }
165
167 {
168 m_type = aType;
169 recacheName();
170 }
171
172 int NetCode() const { return m_net_code; }
173 void SetNetCode( int aCode ) { m_net_code = aCode; }
174
175 int BusCode() const { return m_bus_code; }
176 void SetBusCode( int aCode ) { m_bus_code = aCode; }
177
178 int SubgraphCode() const { return m_subgraph_code; }
179 void SetSubgraphCode( int aCode ) { m_subgraph_code = aCode; }
180
181 long VectorStart() const { return m_vector_start; }
182 long VectorEnd() const { return m_vector_end; }
183
184 long VectorIndex() const { return m_vector_index; }
185
186 wxString VectorPrefix() const { return m_vector_prefix; }
187
188 std::vector< std::shared_ptr< SCH_CONNECTION > >& Members()
189 {
190 return m_members;
191 }
192
193 const std::vector< std::shared_ptr< SCH_CONNECTION > >& Members() const
194 {
195 return m_members;
196 }
197
198 const std::vector< std::shared_ptr< SCH_CONNECTION > > AllMembers() const;
199
200 static wxString PrintBusForUI( const wxString& aString );
201
206 bool IsSubsetOf( SCH_CONNECTION* aOther ) const;
207
213 bool IsMemberOfBus( SCH_CONNECTION* aOther ) const;
214
218 void AppendInfoToMsgPanel( std::vector<MSG_PANEL_ITEM>& aList ) const;
219
226 static bool IsBusLabel( const wxString& aLabel );
227
235 static bool MightBeBusLabel( const wxString& aLabel );
236
237private:
238 void recacheName();
239
241
243
251
253
256
258
260
261 wxString m_name;
262
263 wxString m_cached_name;
264
266
274 wxString m_local_name;
275
277 wxString m_prefix;
278
281
283 wxString m_bus_prefix;
284
285 wxString m_suffix;
286
287 int m_net_code; // TODO(JE) remove if unused
288
289 int m_bus_code; // TODO(JE) remove if unused
290
292
294
296
298
301
308 std::vector< std::shared_ptr< SCH_CONNECTION > > m_members;
309
315
316};
317
318#endif
319
Calculates the connectivity of a schematic and generates netlists.
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:54
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
long VectorEnd() const
wxString FullLocalName() const
long m_vector_start
Highest member of a vector bus.
bool IsMemberOfBus(SCH_CONNECTION *aOther) const
Returns true if this connection is a member of bus connection aOther.
wxString BusPrefix() const
void ConfigureFromLabel(const wxString &aLabel)
Configures the connection given a label.
SCH_ITEM * m_parent
The SCH_ITEM this connection is owned by.
SCH_SHEET_PATH LocalSheet() const
SCH_SHEET_PATH m_sheet
The hierarchical sheet this connection is on.
bool IsNet() const
bool operator!=(const SCH_CONNECTION &aOther) const
void SetSubgraphCode(int aCode)
void SetSuffix(const wxString &aSuffix)
void SetBusCode(int aCode)
void SetName(const wxString &aName)
long VectorStart() const
wxString m_name
Name of the connection.
SCH_ITEM * Parent() const
long m_vector_end
Lowest member of a vector bus.
SCH_SHEET_PATH Sheet() const
CONNECTION_TYPE Type() const
int SubgraphCode() const
bool HasDriverChanged() const
bool IsDirty() const
const std::vector< std::shared_ptr< SCH_CONNECTION > > AllMembers() const
void Reset()
Clears connectivity information.
int BusCode() const
bool operator==(const SCH_CONNECTION &aOther) const
Note: the equality operator for SCH_CONNECTION only tests the net properties, not the ownership / she...
SCH_CONNECTION(SCH_ITEM *aParent=nullptr, SCH_SHEET_PATH aPath=SCH_SHEET_PATH())
Buses can be defined in multiple ways.
void SetNetCode(int aCode)
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members
For bus connections, store a list of member connections.
wxString m_local_prefix
Local prefix for group bus members (used with m_local_name)
CONNECTION_TYPE m_type
SCH_ITEM * m_driver
The SCH_ITEM that drives this connection's net.
bool IsDriver() const
Checks if the SCH_ITEM this connection is attached to can drive connections Drivers can be labels,...
void SetType(CONNECTION_TYPE aType)
void SetPrefix(const wxString &aPrefix)
wxString LocalName() const
wxString Name(bool aIgnoreSheet=false) const
bool IsSubsetOf(SCH_CONNECTION *aOther) const
Returns true if this connection is contained within aOther (but not the same as aOther)
wxString Suffix() const
void SetDriver(SCH_ITEM *aItem)
SCH_SHEET_PATH m_local_sheet
When a connection is overridden by one on a different hierarchical sheet, it will be cloned and m_she...
bool IsBus() const
void * GetLastDriver() const
wxString m_prefix
Prefix if connection is member of a labeled bus group (or "" if not)
void Clone(const SCH_CONNECTION &aOther)
Copies connectivity information (but not parent) from another connection.
void * m_lastDriver
WEAK POINTER (there is no guarantee it is still allocated) Equality comparisons are OK,...
wxString m_cached_name_with_path
Full name including sheet path (if not global)
long m_vector_index
Index of bus vector member nets.
wxString VectorPrefix() const
void SetGraph(CONNECTION_GRAPH *aGraph)
SCH_ITEM * Driver() const
void AppendInfoToMsgPanel(std::vector< MSG_PANEL_ITEM > &aList) const
Adds information about the connection object to aList.
static bool IsBusLabel(const wxString &aLabel)
Test if aLabel has a bus notation.
wxString m_suffix
Name suffix (used only for disambiguation)
wxString m_bus_prefix
Optional prefix of a bux group (always empty for nets and vector buses)
const std::vector< std::shared_ptr< SCH_CONNECTION > > & Members() const
void SetSheet(SCH_SHEET_PATH aSheet)
wxString m_cached_name
Full name, including prefix and suffix.
bool IsUnconnected() const
wxString Prefix() const
long VectorIndex() const
CONNECTION_GRAPH * m_graph
Pointer to the connection graph for the schematic this connection exists on.
static wxString PrintBusForUI(const wxString &aString)
wxString m_local_name
For bus members, we want to keep track of the "local" name of a member, that is, the name it takes on...
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members()
int m_subgraph_code
Groups directly-connected items.
wxString m_vector_prefix
static bool MightBeBusLabel(const wxString &aLabel)
Test if aLabel looks like a bus notation.
int NetCode() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
CONNECTION_TYPE
@ BUS
This item represents a bus vector.
@ NET
This item represents a net.
@ NONE
No connection to this item.
@ BUS_GROUP
This item represents a bus group.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.