KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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, const 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 {
123 return ( m_type == CONNECTION_TYPE::BUS || m_type == CONNECTION_TYPE::BUS_GROUP );
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 GetNetName() const;
157
158 wxString Prefix() const { return m_prefix; }
159 void SetPrefix( const wxString& aPrefix );
160
161 wxString BusPrefix() const { return m_bus_prefix; }
162
163 wxString Suffix() const { return m_suffix; }
164 void SetSuffix( const wxString& aSuffix );
165
166 CONNECTION_TYPE Type() const { return m_type; }
167
169 {
170 m_type = aType;
171 recacheName();
172 }
173
174 int NetCode() const { return m_net_code; }
175 void SetNetCode( int aCode ) { m_net_code = aCode; }
176
177 int BusCode() const { return m_bus_code; }
178 void SetBusCode( int aCode ) { m_bus_code = aCode; }
179
180 int SubgraphCode() const { return m_subgraph_code; }
181 void SetSubgraphCode( int aCode ) { m_subgraph_code = aCode; }
182
183 long VectorStart() const { return m_vector_start; }
184 long VectorEnd() const { return m_vector_end; }
185
186 long VectorIndex() const { return m_vector_index; }
187
188 wxString VectorPrefix() const { return m_vector_prefix; }
189
190 const std::vector< std::shared_ptr< SCH_CONNECTION > >& Members() const
191 {
192 return m_members;
193 }
194
195 const std::vector< std::shared_ptr< SCH_CONNECTION > > AllMembers() const;
196
197 static wxString PrintBusForUI( const wxString& aString );
198
203 bool IsSubsetOf( SCH_CONNECTION* aOther ) const;
204
210 bool IsMemberOfBus( SCH_CONNECTION* aOther ) const;
211
215 void AppendInfoToMsgPanel( std::vector<MSG_PANEL_ITEM>& aList ) const;
216
223 static bool IsBusLabel( const wxString& aLabel );
224
232 static bool MightBeBusLabel( const wxString& aLabel );
233
234private:
235 void recacheName();
236
238
240
248
250
253
255
257
258 wxString m_name;
259
260 wxString m_cached_name;
261
263
271 wxString m_local_name;
272
274 wxString m_prefix;
275
278
280 wxString m_bus_prefix;
281
282 wxString m_suffix;
283
284 int m_net_code; // TODO(JE) remove if unused
285
286 int m_bus_code; // TODO(JE) remove if unused
287
289
291
293
295
298
305 std::vector< std::shared_ptr< SCH_CONNECTION > > m_members;
306
312
313};
314
315#endif
316
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
wxString GetNetName() 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...
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...
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.