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  * @author Jon Evans <jon@craftyjon.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef _SCH_CONNECTION_H
22 #define _SCH_CONNECTION_H
23 
24 #include <memory>
25 #include <unordered_set>
26 
27 #include <boost/optional.hpp>
28 #include <wx/regex.h>
29 
30 #include <bus_alias.h>
31 #include <msgpanel.h>
32 #include <sch_sheet_path.h>
33 
34 
35 class CONNECTION_GRAPH;
36 class SCH_ITEM;
37 class SCH_SHEET_PATH;
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( SCH_CONNECTION& aOther );
103 
104  SCH_ITEM* Parent() const
105  {
106  return m_parent;
107  }
108 
109  SCH_ITEM* Driver() const
110  {
111  return m_driver;
112  }
113 
115  {
116  return m_sheet;
117  }
118 
119  void SetDriver( SCH_ITEM* aItem );
120 
121  void SetSheet( SCH_SHEET_PATH aSheet );
122 
129  bool IsDriver() const;
130 
131  bool IsBus() const
132  {
134  }
135 
136  bool IsNet() const
137  {
138  return ( m_type == CONNECTION_TYPE::NET );
139  }
140 
141  bool IsDirty() const
142  {
143  return m_dirty;
144  }
145 
146  void SetDirty()
147  {
148  m_dirty = true;
149  }
150 
151  void ClearDirty()
152  {
153  m_dirty = false;
154  }
155 
156  const wxString& Name( bool aIgnoreSheet = false ) const;
157 
158  const wxString& RawName() const
159  {
160  return m_name;
161  }
162 
163  wxString LocalName() const { return m_local_name; }
164 
165  wxString FullLocalName() const
166  {
167  return m_prefix + m_local_name + m_suffix;
168  }
169 
170  void SetName( const wxString& aName )
171  {
172  m_name = aName;
173  recacheName();
174  }
175 
176  wxString Prefix() const
177  {
178  return m_prefix;
179  }
180 
181  wxString BusPrefix() const
182  {
183  return m_bus_prefix;
184  }
185 
186  wxString Suffix() const
187  {
188  return m_suffix;
189  }
190 
191  void SetPrefix( const wxString& aPrefix );
192 
193  void SetSuffix( const wxString& aSuffix );
194 
196  {
197  return m_type;
198  }
199 
200  void SetType( CONNECTION_TYPE aType )
201  {
202  m_type = aType;
203  recacheName();
204  }
205 
206  int NetCode() const
207  {
208  return m_net_code;
209  }
210 
211  void SetNetCode( int aCode )
212  {
213  m_net_code = aCode;
214  }
215 
216  int BusCode() const
217  {
218  return m_bus_code;
219  }
220 
221  void SetBusCode( int aCode )
222  {
223  m_bus_code = aCode;
224  }
225 
226  int SubgraphCode() const
227  {
228  return m_subgraph_code;
229  }
230 
231  void SetSubgraphCode( int aCode )
232  {
233  m_subgraph_code = aCode;
234  }
235 
236  long VectorStart() const
237  {
238  return m_vector_start;
239  }
240 
241  long VectorEnd() const
242  {
243  return m_vector_end;
244  }
245 
246  long VectorIndex() const
247  {
248  return m_vector_index;
249  }
250 
251  wxString VectorPrefix() const
252  {
253  return m_vector_prefix;
254  }
255 
256  std::vector< std::shared_ptr< SCH_CONNECTION > >& Members()
257  {
258  return m_members;
259  }
260 
261  const std::vector< std::shared_ptr< SCH_CONNECTION > >& Members() const
262  {
263  return m_members;
264  }
265 
266  const std::vector< std::shared_ptr< SCH_CONNECTION > > AllMembers() const;
267 
268  static wxString PrintBusForUI( const wxString& aString );
269 
274  bool IsSubsetOf( SCH_CONNECTION* aOther ) const;
275 
281  bool IsMemberOfBus( SCH_CONNECTION* aOther ) const;
282 
286  void AppendInfoToMsgPanel( MSG_PANEL_ITEMS& aList ) const;
287 
294  static bool IsBusLabel( const wxString& aLabel );
295 
303  static bool MightBeBusLabel( const wxString& aLabel );
304 
305 private:
306  void recacheName();
307 
308  bool m_dirty;
309 
311 
313 
315 
317 
318  wxString m_name;
319 
320  wxString m_cached_name;
321 
323 
331  wxString m_local_name;
332 
334  wxString m_prefix;
335 
337  wxString m_bus_prefix;
338 
339  wxString m_suffix;
340 
341  int m_net_code; // TODO(JE) remove if unused
342 
343  int m_bus_code; // TODO(JE) remove if unused
344 
346 
348 
350 
352 
354  wxString m_vector_prefix;
355 
362  std::vector< std::shared_ptr< SCH_CONNECTION > > m_members;
363 
369 
370 };
371 
372 #endif
373 
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.
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
int BusCode() const
CONNECTION_TYPE m_type
No connection to this item.
const wxString & RawName() const
int NetCode() const
wxString Suffix() const
const std::vector< std::shared_ptr< SCH_CONNECTION > > & Members() const
const std::vector< std::shared_ptr< SCH_CONNECTION > > AllMembers() const
void SetSubgraphCode(int aCode)
long VectorEnd() const
void Reset()
Clears connectivity information.
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.
const wxString & Name(bool aIgnoreSheet=false) const
bool IsDirty() const
SCH_SHEET_PATH.
wxString FullLocalName() const
long VectorIndex() const
void Clone(SCH_CONNECTION &aOther)
Copies connectivity information (but not parent) from another connection.
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:102
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
CONNECTION_TYPE Type() const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
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.