KiCad PCB EDA Suite
class_netlist_object.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) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
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
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #ifndef _CLASS_NETLIST_OBJECT_H_
32 #define _CLASS_NETLIST_OBJECT_H_
33 
34 
35 #include <sch_sheet_path.h>
36 #include <lib_pin.h>
37 #include <sch_item_struct.h>
38 
40 class SCH_COMPONENT;
41 
42 
43 /* Type of Net objects (wires, labels, pins...) */
45 {
46  NET_ITEM_UNSPECIFIED, // only for not yet initialized instances
47  NET_SEGMENT, // connection by wire
48  NET_BUS, // connection by bus
49  NET_JUNCTION, // connection by junction: can connect to
50  // or more crossing wires
51  NET_LABEL, // this is a local label
52  NET_GLOBLABEL, // this is a global label that connect all
53  // others global label in whole hierarchy
54  NET_HIERLABEL, // element to indicate connection to a
55  // higher-level sheet
56  NET_SHEETLABEL, // element to indicate connection to a
57  // lower-level sheet.
58  NET_BUSLABELMEMBER, /* created when a bus label is found:
59  * the bus label (like DATA[0..7] is
60  * converted to n single labels like
61  * DATA0, DATA1 ...
62  * These objects are living only in the current
63  * NETLIST_OBJECT_LIST, not in shematic.
64  */
65  NET_GLOBBUSLABELMEMBER, // see NET_BUSLABELMEMBER, used when a
66  // global bus label is found
67  NET_HIERBUSLABELMEMBER, // see NET_BUSLABELMEMBER, used when a
68  // hierarchical bus label is found
69  NET_SHEETBUSLABELMEMBER, // see NET_BUSLABELMEMBER, used when a
70  // pin sheet label using bus notation
71  // is found
72  NET_PINLABEL, /* created when a pin is POWER (IN or
73  * OUT) with invisible attribute is found:
74  * these pins are equivalent to a global
75  * label and are automatically connected
76  */
77  NET_PIN, // this is an usual pin
78  NET_NOCONNECT // this is a no connect symbol
79 };
80 
81 
82 /* Values for .m_FlagOfConnection member */
84 {
85  UNCONNECTED = 0, /* Pin or Label not connected (error) */
86  NOCONNECT_SYMBOL_PRESENT, /* Pin not connected but have a NoConnect
87  * symbol on it (no error) */
88  PAD_CONNECT /* Normal connection (no error) */
89 };
90 
91 
93 {
94 public:
95  NETLIST_ITEM_T m_Type; /* Type of item (see NETLIST_ITEM_T enum) */
96  EDA_ITEM* m_Comp; /* Pointer to the library item that
97  * created this net object (the parent)
98  */
99  SCH_ITEM* m_Link; /* For SCH_SHEET_PIN:
100  * Pointer to the hierarchy sheet that
101  * contains this SCH_SHEET_PIN
102  * For Pins: pointer to the schematic component
103  * that contains this pin
104  */
105  int m_Flag; /* flag used in calculations */
106  SCH_SHEET_PATH m_SheetPath; // the sheet path which contains this item
107  SCH_SHEET_PATH m_SheetPathInclude; // sheet path which contains the hierarchical label
108  ELECTRICAL_PINTYPE m_ElectricalPinType; // Has meaning only for Pins: electrical type of the pin
109  int m_BusNetCode; /* Used for BUS connections */
110  int m_Member; /* for labels type NET_BUSLABELMEMBER ( bus member
111  * created from the BUS label ) member number.
112  */
113  NET_CONNECTION_T m_ConnectionType; // Used to store the connection type
114  wxString m_PinNum; // pin number
115  wxString m_Label; // Label text (for labels) or Pin name (for pins)
116  wxPoint m_Start; // Position of object or for segments: starting point
117  wxPoint m_End; // For segments (wire and buses): ending point
118 
119 private:
120  int m_netCode; /* net code for all items except BUS
121  * labels because a BUS label has
122  * as many net codes as bus members
123  */
124  NETLIST_OBJECT* m_netNameCandidate; /* a pointer to a label connected to the net,
125  * that can be used to give a name to the net
126  * or a pin if there is no label in net
127  * When no label, the pin is used to build
128  * default net name.
129  */
130 
131 public:
132 
133 #if defined(DEBUG)
134  void Show( std::ostream& out, int ndx ) const;
135 
136 #endif
137 
138  NETLIST_OBJECT();
139  NETLIST_OBJECT( NETLIST_OBJECT& aSource ); // Copy constructor
140 
141  ~NETLIST_OBJECT();
142 
143  // Accessors:
144  void SetNet( int aNetCode ) { m_netCode = aNetCode; }
145  int GetNet() const { return m_netCode; }
146 
155  {
156  m_ConnectionType = aFlg;
157  }
158 
160  {
161  return m_ConnectionType;
162  }
163 
172  void SetNetNameCandidate( NETLIST_OBJECT* aCandidate );
173 
178  bool HasNetNameCandidate() { return m_netNameCandidate != NULL; }
179 
185  const wxString& GetPinNumText() const
186  {
187  return m_PinNum;
188  }
189 
196  {
197  if( m_Link && m_Link->Type() == SCH_COMPONENT_T )
198  return (SCH_COMPONENT*) m_Link;
199 
200  return NULL;
201  }
202 
212  bool IsLabelConnected( NETLIST_OBJECT* aNetItem );
213 
220  bool IsLabelGlobal() const;
221 
232  bool IsLabelBusMemberType() const;
233 
238  bool IsLabelType() const;
239 
246  wxString GetNetName( bool adoptTimestamp = false ) const;
247 
255  wxString GetShortNetName( bool adoptTimestamp = false ) const;
256 
266  void ConvertBusToNetListItems( NETLIST_OBJECT_LIST& aNetListItems );
267 };
268 
269 
276 typedef std::vector<NETLIST_OBJECT*> NETLIST_OBJECTS;
277 
278 
285 {
286  int m_lastNetCode; // Used in intermediate calculation: last net code created
287  int m_lastBusNetCode; // Used in intermediate calculation:
288  // last net code created for bus members
289 
290 public:
297  {
298  // Do not leave some members uninitialized:
299  m_lastNetCode = 0;
300  m_lastBusNetCode = 0;
301  }
302 
304 
313  bool BuildNetListInfo( SCH_SHEET_LIST& aSheets );
314 
318  NETLIST_OBJECT* GetItem( unsigned aIdx ) const
319  {
320  return *( this->begin() + aIdx );
321  }
322 
326  NETLIST_ITEM_T GetItemType( unsigned aIdx ) const
327  {
328  return GetItem( aIdx )->m_Type;
329  }
330 
334  int GetItemNet( unsigned aIdx ) const
335  {
336  return GetItem( aIdx )->GetNet();
337  }
338 
340  {
341  return GetItem( aIdx )->GetConnectionType();
342  }
343 
351  void SetConnectionType( unsigned aIdx, NET_CONNECTION_T aFlg = UNCONNECTED )
352  {
353  GetItem( aIdx )->SetConnectionType( aFlg );
354  }
355 
357  void Clear();
358 
363  {
364  for( unsigned ii = 0; ii < size(); ii++ )
366  }
367 
368  /*
369  * Sorts the list of connected items by net code
370  */
371  void SortListbyNetcode();
372 
373  /*
374  * Sorts the list of connected items by sheet.
375  * This sorting is used when searching "physical" connection between items
376  * because obviously only items inside the same sheet can be connected
377  */
378  void SortListbySheet();
379 
386  int CountPinsInNet( unsigned aNetStart );
387 
395  void TestforNonOrphanLabel( unsigned aNetItemRef, unsigned aStartNet );
396 
404  void TestforSimilarLabels();
405 
406 
407  #if defined(DEBUG)
408  void DumpNetTable()
409  {
410  for( unsigned idx = 0; idx < size(); ++idx )
411  {
412  GetItem( idx )->Show( std::cout, idx );
413  }
414  }
415 
416  #endif
417 
418 private:
419  /*
420  * Propagate aNewNetCode to items having an internal netcode aOldNetCode
421  * used to interconnect group of items already physically connected,
422  * when a new connection is found between aOldNetCode and aNewNetCode
423  */
424  void propagateNetCode( int aOldNetCode, int aNewNetCode, bool aIsBus );
425 
426  /*
427  * This function merges the net codes of groups of objects already connected
428  * to labels (wires, bus, pins ... ) when 2 labels are equivalents
429  * (i.e. group objects connected by labels)
430  */
431  void labelConnect( NETLIST_OBJECT* aLabelRef );
432 
433  /* Comparison function to sort by increasing Netcode the list of connected items
434  */
435  static bool sortItemsbyNetcode( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 )
436  {
437  return Objet1->GetNet() < Objet2->GetNet();
438  }
439 
440  /* Comparison routine to sort items by Sheet path
441  */
442  static bool sortItemsBySheet( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 )
443  {
444  return Objet1->m_SheetPath.Cmp( Objet2->m_SheetPath ) < 0;
445  }
446 
451  void sheetLabelConnect( NETLIST_OBJECT* aSheetLabel );
452 
453  void pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus, int start );
454 
462  void segmentToPointConnect( NETLIST_OBJECT* aJonction, bool aIsBus, int aIdxStart );
463 
464 
471  void connectBusLabels();
472 
480  void setUnconnectedFlag();
481 
494 };
495 
496 
504 extern bool IsBusLabel( const wxString& aLabel );
505 
506 #endif // _CLASS_NETLIST_OBJECT_H_
Class SCH_SHEET_LIST.
void setUnconnectedFlag()
Set the m_FlagOfConnection member of items in list depending on the connection type: UNCONNECTED...
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
NET_CONNECTION_T GetConnectionType() const
bool IsLabelGlobal() const
Function IsLabelGlobal.
NETLIST_ITEM_T
wxString GetNetName(bool adoptTimestamp=false) const
Function GetNetName.
void connectBusLabels()
Function connectBusLabels Propagate the net code (and create it, if not yet existing) between all bus...
const wxString & GetPinNumText() const
Function GetPinNum returns a pin number in wxString form.
NETLIST_ITEM_T GetItemType(unsigned aIdx) const
Acces to an item type.
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
Base schematic object class definition.
SCH_SHEET_PATH m_SheetPathInclude
NETLIST_OBJECT * m_netNameCandidate
bool BuildNetListInfo(SCH_SHEET_LIST &aSheets)
Function BuildNetListInfo the master function of tgis class.
int CountPinsInNet(unsigned aNetStart)
Counts number of pins connected on the same net.
Definition: erc.cpp:506
NET_CONNECTION_T m_ConnectionType
SCH_SHEET_PATH m_SheetPath
ELECTRICAL_PINTYPE m_ElectricalPinType
void findBestNetNameForEachNet()
Function findBestNetNameForEachNet fill the .m_NetNameCandidate member of each item of aNetItemBuffer...
NETLIST_ITEM_T m_Type
void labelConnect(NETLIST_OBJECT *aLabelRef)
void SetConnectionType(unsigned aIdx, NET_CONNECTION_T aFlg=UNCONNECTED)
Set the item connection type: UNCONNECTED Pin or Label not connected (error) NOCONNECT_SYMBOL_PRESENT...
void Clear()
Delete all objects in list and clear list.
void sheetLabelConnect(NETLIST_OBJECT *aSheetLabel)
Propagate net codes from a parent sheet to an include sheet, from a pin sheet connection.
NET_CONNECTION_T
Class NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected item...
void segmentToPointConnect(NETLIST_OBJECT *aJonction, bool aIsBus, int aIdxStart)
Search connections between a junction and segments Propagate the junction net code to objects connect...
bool IsLabelType() const
Function IsLabelType.
static bool sortItemsBySheet(const NETLIST_OBJECT *Objet1, const NETLIST_OBJECT *Objet2)
std::vector< NETLIST_OBJECT * > NETLIST_OBJECTS
Type NETLIST_OBJECTS is a container referring to (not owning) NETLIST_OBJECTs, which are connected it...
void TestforSimilarLabels()
Function TestforSimilarLabels detects labels which are different when using case sensitive comparison...
Definition: erc.cpp:658
bool IsLabelBusMemberType() const
Function IsLabelBusMemberType.
bool IsBusLabel(const wxString &aLabel)
Function IsBusLabel test if aLabel has a bus notation.
static bool sortItemsbyNetcode(const NETLIST_OBJECT *Objet1, const NETLIST_OBJECT *Objet2)
void propagateNetCode(int aOldNetCode, int aNewNetCode, bool aIsBus)
void TestforNonOrphanLabel(unsigned aNetItemRef, unsigned aStartNet)
Function TestforNonOrphanLabel Sheet labels are expected to be connected to a hierarchical label...
Definition: erc.cpp:584
Class SCH_SHEET_PATH.
SCH_COMPONENT * GetComponentParent() const
For Pins (NET_PINS):
void ResetConnectionsType()
Reset the connection type of all items to UNCONNECTED type.
bool IsLabelConnected(NETLIST_OBJECT *aNetItem)
Function IsLabelConnected tests if the net list object is a hierarchical label or sheet label and is ...
NET_CONNECTION_T GetConnectionType(unsigned aIdx)
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
NETLIST_OBJECT_LIST()
Constructor.
void SetNet(int aNetCode)
void SetNetNameCandidate(NETLIST_OBJECT *aCandidate)
Set m_netNameCandidate to a connected item which will be used to calcule the net name of the item Obv...
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
wxString GetShortNetName(bool adoptTimestamp=false) const
Function GetShortNetName.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
void pointToPointConnect(NETLIST_OBJECT *aRef, bool aIsBus, int start)
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Function Cmp Compare if this is the same sheet path as aSheetPathToTest.
int GetItemNet(unsigned aIdx) const
Acces to an item net code.
void SetConnectionType(NET_CONNECTION_T aFlg=UNCONNECTED)
Set the item connection type: UNCONNECTED Pin or Label not connected (error) NOCONNECT_SYMBOL_PRESENT...
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
void ConvertBusToNetListItems(NETLIST_OBJECT_LIST &aNetListItems)
Function ConvertBusToNetListItems breaks the text of a bus label type net list object into as many me...