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 <boost/optional.hpp>
29 #include <wx/regex.h>
30 #include <bus_alias.h>
31 #include <sch_sheet_path.h>
32 
33 
34 class CONNECTION_GRAPH;
35 class SCH_ITEM;
36 class SCH_SHEET_PATH;
37 class MSG_PANEL_ITEM;
38 
39 
40 enum class CONNECTION_TYPE
41 {
42  NONE,
43  NET,
44  BUS,
45  BUS_GROUP,
46 };
47 
62 {
63 public:
64  SCH_CONNECTION( SCH_ITEM* aParent = nullptr, SCH_SHEET_PATH aPath = SCH_SHEET_PATH() );
65 
67 
69  {}
70 
75  bool operator==( const SCH_CONNECTION& aOther ) const;
76 
77  bool operator!=( const SCH_CONNECTION& aOther ) const;
78 
79  void SetGraph( CONNECTION_GRAPH* aGraph )
80  {
81  m_graph = aGraph;
82  }
83 
90  void ConfigureFromLabel( const wxString& aLabel );
91 
95  void Reset();
96 
102  void Clone( const SCH_CONNECTION& aOther );
103 
104  SCH_ITEM* Parent() const { return m_parent; }
105 
106  SCH_ITEM* Driver() const { return m_driver; }
107  void SetDriver( SCH_ITEM* aItem );
108 
109  SCH_SHEET_PATH Sheet() const { return m_sheet; }
110  void SetSheet( SCH_SHEET_PATH aSheet );
111 
113 
120  bool IsDriver() const;
121 
122  bool IsBus() const
123  {
125  }
126 
127  bool IsNet() const
128  {
129  return ( m_type == CONNECTION_TYPE::NET );
130  }
131 
132  bool IsUnconnected() const { return ( m_type == CONNECTION_TYPE::NONE ); }
133 
134  bool IsDirty() const { return m_dirty; }
135  void SetDirty() { m_dirty = true; }
136  void ClearDirty() { m_dirty = false; }
137 
138  bool HasDriverChanged() const;
139  void ClearDriverChanged();
140  void* GetLastDriver() const { return m_lastDriver; }
141 
142  wxString Name( bool aIgnoreSheet = false ) const;
143 
144  wxString LocalName() const { return m_local_name; }
145 
146  wxString FullLocalName() const
147  {
149  }
150 
151  void SetName( const wxString& aName )
152  {
153  m_name = aName;
154  recacheName();
155  }
156 
157  wxString Prefix() const { return m_prefix; }
158  void SetPrefix( const wxString& aPrefix );
159 
160  wxString BusPrefix() const { return m_bus_prefix; }
161 
162  wxString Suffix() const { return m_suffix; }
163  void SetSuffix( const wxString& aSuffix );
164 
165  CONNECTION_TYPE Type() const { return m_type; }
166 
167  void SetType( CONNECTION_TYPE aType )
168  {
169  m_type = aType;
170  recacheName();
171  }
172 
173  int NetCode() const { return m_net_code; }
174  void SetNetCode( int aCode ) { m_net_code = aCode; }
175 
176  int BusCode() const { return m_bus_code; }
177  void SetBusCode( int aCode ) { m_bus_code = aCode; }
178 
179  int SubgraphCode() const { return m_subgraph_code; }
180  void SetSubgraphCode( int aCode ) { m_subgraph_code = aCode; }
181 
182  long VectorStart() const { return m_vector_start; }
183  long VectorEnd() const { return m_vector_end; }
184 
185  long VectorIndex() const { return m_vector_index; }
186 
187  wxString VectorPrefix() const { return m_vector_prefix; }
188 
189  std::vector< std::shared_ptr< SCH_CONNECTION > >& Members()
190  {
191  return m_members;
192  }
193 
194  const std::vector< std::shared_ptr< SCH_CONNECTION > >& Members() const
195  {
196  return m_members;
197  }
198 
199  const std::vector< std::shared_ptr< SCH_CONNECTION > > AllMembers() const;
200 
201  static wxString PrintBusForUI( const wxString& aString );
202 
207  bool IsSubsetOf( SCH_CONNECTION* aOther ) const;
208 
214  bool IsMemberOfBus( SCH_CONNECTION* aOther ) const;
215 
219  void AppendInfoToMsgPanel( std::vector<MSG_PANEL_ITEM>& aList ) const;
220 
227  static bool IsBusLabel( const wxString& aLabel );
228 
236  static bool MightBeBusLabel( const wxString& aLabel );
237 
238 private:
239  void recacheName();
240 
241  bool m_dirty;
242 
244 
252 
254 
255  void* m_lastDriver;
256 
259 
261 
262  wxString m_name;
263 
264  wxString m_cached_name;
265 
267 
275  wxString m_local_name;
276 
278  wxString m_prefix;
279 
281  wxString m_local_prefix;
282 
284  wxString m_bus_prefix;
285 
286  wxString m_suffix;
287 
288  int m_net_code; // TODO(JE) remove if unused
289 
290  int m_bus_code; // TODO(JE) remove if unused
291 
293 
295 
297 
299 
301  wxString m_vector_prefix;
302 
309  std::vector< std::shared_ptr< SCH_CONNECTION > > m_members;
310 
316 
317 };
318 
319 #endif
320 
static wxString PrintBusForUI(const wxString &aString)
int m_subgraph_code
Groups directly-connected items.
void SetBusCode(int aCode)
wxString Prefix() const
static bool MightBeBusLabel(const wxString &aLabel)
Test if aLabel looks like a bus notation.
void Clone(const SCH_CONNECTION &aOther)
Copies connectivity information (but not parent) from another connection.
bool IsUnconnected() const
wxString m_cached_name
Full name, including prefix and suffix.
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members
For bus connections, store a list of member connections.
Calculates the connectivity of a schematic and generates netlists.
wxString m_name
Name of the connection.
SCH_ITEM * m_driver
The SCH_ITEM that drives this connection's net.
static bool IsBusLabel(const wxString &aLabel)
Test if aLabel has a bus notation.
This item represents a bus group.
wxString m_bus_prefix
Optional prefix of a bux group (always empty for nets and vector buses)
SCH_CONNECTION(SCH_ITEM *aParent=nullptr, SCH_SHEET_PATH aPath=SCH_SHEET_PATH())
Buses can be defined in multiple ways.
bool IsMemberOfBus(SCH_CONNECTION *aOther) const
Returns true if this connection is a member of bus connection aOther.
void ConfigureFromLabel(const wxString &aLabel)
Configures the connection given a label.
void SetDriver(SCH_ITEM *aItem)
void SetName(const wxString &aName)
void SetSheet(SCH_SHEET_PATH aSheet)
wxString m_cached_name_with_path
Full name including sheet path (if not global)
CONNECTION_TYPE
wxString LocalName() const
bool HasDriverChanged() const
SCH_SHEET_PATH LocalSheet() const
int BusCode() const
CONNECTION_TYPE m_type
No connection to this item.
int NetCode() const
wxString Suffix() const
const std::vector< std::shared_ptr< SCH_CONNECTION > > & Members() const
wxString Name(bool aIgnoreSheet=false) const
const std::vector< std::shared_ptr< SCH_CONNECTION > > AllMembers() const
void AppendInfoToMsgPanel(std::vector< MSG_PANEL_ITEM > &aList) const
Adds information about the connection object to aList.
void SetSubgraphCode(int aCode)
long VectorEnd() const
void Reset()
Clears connectivity information.
wxString m_local_prefix
Local prefix for group bus members (used with m_local_name)
void SetGraph(CONNECTION_GRAPH *aGraph)
SCH_ITEM * Driver() const
int SubgraphCode() const
wxString m_prefix
Prefix if connection is member of a labeled bus group (or "" if not)
CONNECTION_GRAPH * m_graph
Pointer to the connection graph for the schematic this connection exists on.
bool IsDirty() const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString FullLocalName() const
long VectorIndex() const
bool IsDriver() const
Checks if the SCH_ITEM this connection is attached to can drive connections Drivers can be labels,...
SCH_SHEET_PATH m_sheet
The hierarchical sheet this connection is on.
This item represents a net.
wxString m_suffix
Name suffix (used only for disambiguation)
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...
SCH_SHEET_PATH Sheet() const
bool IsNet() const
long m_vector_start
Highest member of a vector bus.
wxString VectorPrefix() const
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
void SetSuffix(const wxString &aSuffix)
void SetPrefix(const wxString &aPrefix)
bool operator!=(const SCH_CONNECTION &aOther) const
wxString BusPrefix() const
SCH_ITEM * Parent() const
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...
long VectorStart() const
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members()
long m_vector_index
Index of bus vector member nets.
long m_vector_end
Lowest member of a vector bus.
void SetType(CONNECTION_TYPE aType)
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
bool IsBus() const
bool IsSubsetOf(SCH_CONNECTION *aOther) const
Returns true if this connection is contained within aOther (but not the same as aOther)
wxString m_vector_prefix
void * m_lastDriver
WEAK POINTER (there is no guarantee it is still allocated) Equality comparisons are OK,...
void * GetLastDriver() const
CONNECTION_TYPE Type() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
SCH_ITEM * m_parent
The SCH_ITEM this connection is owned by.
void SetNetCode(int aCode)
bool operator==(const SCH_CONNECTION &aOther) const
Note: the equality operator for SCH_CONNECTION only tests the net properties, not the ownership / she...
This item represents a bus vector.