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 SCH_ITEM;
36 class SCH_SHEET_PATH;
37 
38 
40 {
45 };
46 
61 {
62 public:
63  SCH_CONNECTION( SCH_ITEM* aParent = nullptr, SCH_SHEET_PATH aPath = SCH_SHEET_PATH() );
64 
66  {}
67 
72  bool operator==( const SCH_CONNECTION& aOther ) const;
73 
74  bool operator!=( const SCH_CONNECTION& aOther ) const;
75 
82  void ConfigureFromLabel( wxString aLabel );
83 
87  void Reset();
88 
94  void Clone( SCH_CONNECTION& aOther );
95 
96  SCH_ITEM* Parent() const
97  {
98  return m_parent;
99  }
100 
101  SCH_ITEM* Driver() const
102  {
103  return m_driver;
104  }
105 
107  {
108  return m_sheet;
109  }
110 
111  void SetDriver( SCH_ITEM* aItem );
112 
113  void SetSheet( SCH_SHEET_PATH aSheet );
114 
121  bool IsDriver() const;
122 
123  bool IsBus() const
124  {
125  return ( m_type == CONNECTION_BUS || m_type == CONNECTION_BUS_GROUP );
126  }
127 
128  bool IsNet() const
129  {
130  return ( m_type == CONNECTION_NET );
131  }
132 
133  bool IsDirty() const
134  {
135  return m_dirty;
136  }
137 
138  void SetDirty()
139  {
140  m_dirty = true;
141  }
142 
143  void ClearDirty()
144  {
145  m_dirty = false;
146  }
147 
148  wxString Name( bool aIgnoreSheet = false ) const;
149 
150  wxString RawName() const
151  {
152  return m_name;
153  }
154 
155  void SetName( const wxString& aName )
156  {
157  m_name = aName;
158  }
159 
160  wxString Prefix() const
161  {
162  return m_prefix;
163  }
164 
165  wxString Suffix() const
166  {
167  return m_suffix;
168  }
169 
170  void SetPrefix( const wxString& aPrefix );
171 
172  void SetSuffix( const wxString& aSuffix );
173 
175  {
176  return m_type;
177  }
178 
179  void SetType( CONNECTION_TYPE aType )
180  {
181  m_type = aType;
182  }
183 
184  int NetCode() const
185  {
186  return m_net_code;
187  }
188 
189  void SetNetCode( int aCode )
190  {
191  m_net_code = aCode;
192  }
193 
194  int BusCode() const
195  {
196  return m_bus_code;
197  }
198 
199  void SetBusCode( int aCode )
200  {
201  m_bus_code = aCode;
202  }
203 
204  int SubgraphCode() const
205  {
206  return m_subgraph_code;
207  }
208 
209  void SetSubgraphCode( int aCode )
210  {
211  m_subgraph_code = aCode;
212  }
213 
214  long VectorStart() const
215  {
216  return m_vector_start;
217  }
218 
219  long VectorEnd() const
220  {
221  return m_vector_end;
222  }
223 
224  long VectorIndex() const
225  {
226  return m_vector_index;
227  }
228 
229  wxString VectorPrefix() const
230  {
231  return m_vector_prefix;
232  }
233 
234  std::vector< std::shared_ptr< SCH_CONNECTION > >& Members()
235  {
236  return m_members;
237  }
238 
239  const std::vector< std::shared_ptr< SCH_CONNECTION > >& Members() const
240  {
241  return m_members;
242  }
243 
252  bool IsSubsetOf( SCH_CONNECTION* aOther ) const;
253 
259  bool IsMemberOfBus( SCH_CONNECTION* aOther ) const;
260 
270  bool ParseBusVector( wxString aBus, wxString* aName,
271  std::vector<wxString>& aMemberList ) const;
272 
281  bool ParseBusGroup( wxString aGroup, wxString* name,
282  std::vector<wxString>& aMemberList ) const;
283 
287  void AppendInfoToMsgPanel( MSG_PANEL_ITEMS& aList ) const;
288 
292  void AppendDebugInfoToMsgPanel( MSG_PANEL_ITEMS& aList ) const;
293 
300  static bool IsBusLabel( const wxString& aLabel );
301 
308  static bool IsBusVectorLabel( const wxString& aLabel );
309 
316  static bool IsBusGroupLabel( const wxString& aLabel );
317 
318 private:
319 
320  bool m_dirty;
321 
323 
325 
327 
329 
330  wxString m_name;
331 
333  wxString m_prefix;
334 
335  wxString m_suffix;
336 
337  int m_net_code; // TODO(JE) remove if unused
338 
339  int m_bus_code; // TODO(JE) remove if unused
340 
342 
344 
346 
348 
350  wxString m_vector_prefix;
351 
358  std::vector< std::shared_ptr< SCH_CONNECTION > > m_members;
359 
360 };
361 
362 #endif
363 
int m_subgraph_code
Groups directly-connected items.
void SetBusCode(int aCode)
wxString Prefix() const
No connection to this item.
std::vector< std::shared_ptr< SCH_CONNECTION > > m_members
For bus connections, store a list of member connections.
wxString m_name
Name of the bus.
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.
SCH_CONNECTION(SCH_ITEM *aParent=nullptr, SCH_SHEET_PATH aPath=SCH_SHEET_PATH())
bool IsMemberOfBus(SCH_CONNECTION *aOther) const
Returns true if this connection is a member of bus connection aOther.
void SetDriver(SCH_ITEM *aItem)
void SetName(const wxString &aName)
void SetSheet(SCH_SHEET_PATH aSheet)
CONNECTION_TYPE
wxString RawName() const
int BusCode() const
CONNECTION_TYPE m_type
int NetCode() const
wxString Suffix() const
const std::vector< std::shared_ptr< SCH_CONNECTION > > & Members() const
wxString Name(bool aIgnoreSheet=false) const
void SetSubgraphCode(int aCode)
long VectorEnd() const
void Reset()
Clears connectivity information.
This item represents a net.
SCH_ITEM * Driver() const
int SubgraphCode() const
void ConfigureFromLabel(wxString aLabel)
Configures the connection given a label.
static bool IsBusVectorLabel(const wxString &aLabel)
Test if aLabel has a bus vector notation (simple bus, e.g.
bool IsDirty() const
Class SCH_SHEET_PATH.
bool ParseBusGroup(wxString aGroup, wxString *name, std::vector< wxString > &aMemberList) const
Parses a bus group label into the name and a list of components.
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.
void AppendDebugInfoToMsgPanel(MSG_PANEL_ITEMS &aList) const
Adds extended debug information about the connection object to aList.
wxString m_suffix
Name suffix (used only for disambiguation)
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.
const char * name
Definition: DXF_plotter.cpp:61
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 ParseBusVector(wxString aBus, wxString *aName, std::vector< wxString > &aMemberList) const
Parses a bus vector (e.g.
bool operator!=(const SCH_CONNECTION &aOther) 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.
static bool IsBusGroupLabel(const wxString &aLabel)
Test if aLabel has a bus group notation.
void SetType(CONNECTION_TYPE aType)
This item represents a bus group.
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 aOther is a subset of this connection or vice versa.
wxString m_vector_prefix
CONNECTION_TYPE Type() const
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
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.