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#include <widgets/msgpanel.h>
32
33
35class SCH_ITEM;
36class SCH_SHEET_PATH;
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
70 {}
71
76 bool operator==( const SCH_CONNECTION& aOther ) const;
77
78 bool operator!=( const SCH_CONNECTION& aOther ) const;
79
80 void SetGraph( CONNECTION_GRAPH* aGraph )
81 {
82 m_graph = aGraph;
83 }
84
91 void ConfigureFromLabel( const wxString& aLabel );
92
96 void Reset();
97
103 void Clone( const SCH_CONNECTION& aOther );
104
105 SCH_ITEM* Parent() const { return m_parent; }
106
107 SCH_ITEM* Driver() const { return m_driver; }
108 void SetDriver( SCH_ITEM* aItem );
109
110 SCH_SHEET_PATH Sheet() const { return m_sheet; }
111 void SetSheet( SCH_SHEET_PATH aSheet );
112
114
121 bool IsDriver() const;
122
123 bool IsBus() const
124 {
125 return ( m_type == CONNECTION_TYPE::BUS || m_type == CONNECTION_TYPE::BUS_GROUP );
126 }
127
128 bool IsNet() const
129 {
130 return ( m_type == CONNECTION_TYPE::NET );
131 }
132
133 bool IsUnconnected() const { return ( m_type == CONNECTION_TYPE::NONE ); }
134
135 bool IsDirty() const { return m_dirty; }
136 void SetDirty() { m_dirty = true; }
137 void ClearDirty() { m_dirty = false; }
138
139 bool HasDriverChanged() const;
140 void ClearDriverChanged();
141 void* GetLastDriver() const { return m_lastDriver; }
142
143 wxString Name( bool aIgnoreSheet = false ) const;
144
145 wxString LocalName() const { return m_local_name; }
146
147 wxString FullLocalName() const
148 {
150 }
151
152 void SetName( const wxString& aName )
153 {
154 m_name = aName;
155 recacheName();
156 }
157
158 wxString GetNetName() const;
159
160 wxString Prefix() const { return m_prefix; }
161 void SetPrefix( const wxString& aPrefix );
162
163 wxString BusPrefix() const { return m_bus_prefix; }
164
165 wxString Suffix() const { return m_suffix; }
166 void SetSuffix( const wxString& aSuffix );
167
168 CONNECTION_TYPE Type() const { return m_type; }
169
171 {
172 m_type = aType;
173 recacheName();
174 }
175
176 int NetCode() const { return m_net_code; }
177 void SetNetCode( int aCode ) { m_net_code = aCode; }
178
179 int BusCode() const { return m_bus_code; }
180 void SetBusCode( int aCode ) { m_bus_code = aCode; }
181
182 int SubgraphCode() const { return m_subgraph_code; }
183 void SetSubgraphCode( int aCode ) { m_subgraph_code = aCode; }
184
185 long VectorStart() const { return m_vector_start; }
186 long VectorEnd() const { return m_vector_end; }
187
188 long VectorIndex() const { return m_vector_index; }
189
190 wxString VectorPrefix() const { return m_vector_prefix; }
191
192 const std::vector< std::shared_ptr< SCH_CONNECTION > >& Members() const
193 {
194 return m_members;
195 }
196
197 const std::vector< std::shared_ptr< SCH_CONNECTION > > AllMembers() const;
198
199 static wxString PrintBusForUI( const wxString& aString );
200
205 bool IsSubsetOf( SCH_CONNECTION* aOther ) const;
206
212 bool IsMemberOfBus( SCH_CONNECTION* aOther ) const;
213
217 void AppendInfoToMsgPanel( std::vector<MSG_PANEL_ITEM>& aList ) const;
218
225 static bool IsBusLabel( const wxString& aLabel );
226
234 static bool MightBeBusLabel( const wxString& aLabel );
235
236private:
237 void recacheName();
238
240
242
250
252
255
257
259
260 wxString m_name;
261
262 wxString m_cached_name;
263
265
273 wxString m_local_name;
274
276 wxString m_prefix;
277
280
282 wxString m_bus_prefix;
283
284 wxString m_suffix;
285
286 int m_net_code; // TODO(JE) remove if unused
287
288 int m_bus_code; // TODO(JE) remove if unused
289
291
293
295
297
300
307 std::vector< std::shared_ptr< SCH_CONNECTION > > m_members;
308
314
315};
316
317#endif
318
Calculate the connectivity of a schematic and generates netlists.
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:166
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Message panel definition file.
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.