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 <jon@craftyjon.com>
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 
31 #include <bus_alias.h>
32 #include <widgets/msgpanel.h>
33 #include <sch_sheet_path.h>
34 
35 
36 class CONNECTION_GRAPH;
37 class SCH_ITEM;
38 class SCH_SHEET_PATH;
39 
40 
41 enum class CONNECTION_TYPE
42 {
43  NONE,
44  NET,
45  BUS,
46  BUS_GROUP,
47 };
48 
63 {
64 public:
65  SCH_CONNECTION( SCH_ITEM* aParent = nullptr, SCH_SHEET_PATH aPath = SCH_SHEET_PATH() );
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 
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 
166  void SetType( CONNECTION_TYPE aType )
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( MSG_PANEL_ITEMS& aList ) const;
219 
226  static bool IsBusLabel( const wxString& aLabel );
227 
235  static bool MightBeBusLabel( const wxString& aLabel );
236 
237 private:
238  void recacheName();
239 
240  bool m_dirty;
241 
243 
245 
246  void* m_lastDriver;
247 
250 
252 
253  wxString m_name;
254 
255  wxString m_cached_name;
256 
258 
266  wxString m_local_name;
267 
269  wxString m_prefix;
270 
272  wxString m_local_prefix;
273 
275  wxString m_bus_prefix;
276 
277  wxString m_suffix;
278 
279  int m_net_code; // TODO(JE) remove if unused
280 
281  int m_bus_code; // TODO(JE) remove if unused
282 
284 
286 
288 
290 
292  wxString m_vector_prefix;
293 
300  std::vector< std::shared_ptr< SCH_CONNECTION > > m_members;
301 
307 
308 };
309 
310 #endif
311 
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
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 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
void AppendInfoToMsgPanel(MSG_PANEL_ITEMS &aList) const
Adds information about the connection object to aList.
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
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:97
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)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
bool IsBus() const
Message panel definition file.
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:193
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.