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> // LIB_PIN::PinStringNum( m_PinNum )
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  long m_PinNum; // pin number ( 1 long = 4 bytes -> 4 ascii codes)
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  wxString GetPinNumText()
186  {
187  // hide the ugliness in here, but do it inline.
188  return LIB_PIN::PinStringNum( m_PinNum );
189  }
190 
197  {
198  if( m_Link && m_Link->Type() == SCH_COMPONENT_T )
199  return (SCH_COMPONENT*) m_Link;
200 
201  return NULL;
202  }
203 
213  bool IsLabelConnected( NETLIST_OBJECT* aNetItem );
214 
221  bool IsLabelGlobal() const;
222 
233  bool IsLabelBusMemberType() const;
234 
239  bool IsLabelType() const;
240 
247  wxString GetNetName( bool adoptTimestamp = false ) const;
248 
256  wxString GetShortNetName( bool adoptTimestamp = false ) const;
257 
267  void ConvertBusToNetListItems( NETLIST_OBJECT_LIST& aNetListItems );
268 };
269 
270 
277 typedef std::vector<NETLIST_OBJECT*> NETLIST_OBJECTS;
278 
279 
286 {
287  int m_lastNetCode; // Used in intermediate calculation: last net code created
288  int m_lastBusNetCode; // Used in intermediate calculation:
289  // last net code created for bus members
290 
291 public:
301  {
302  // Do not leave some members uninitialized:
303  m_lastNetCode = 0;
304  m_lastBusNetCode = 0;
305  }
306 
308 
317  bool BuildNetListInfo( SCH_SHEET_LIST& aSheets );
318 
322  NETLIST_OBJECT* GetItem( unsigned aIdx ) const
323  {
324  return *( this->begin() + aIdx );
325  }
326 
330  NETLIST_ITEM_T GetItemType( unsigned aIdx ) const
331  {
332  return GetItem( aIdx )->m_Type;
333  }
334 
338  int GetItemNet( unsigned aIdx ) const
339  {
340  return GetItem( aIdx )->GetNet();
341  }
342 
344  {
345  return GetItem( aIdx )->GetConnectionType();
346  }
347 
355  void SetConnectionType( unsigned aIdx, NET_CONNECTION_T aFlg = UNCONNECTED )
356  {
357  GetItem( aIdx )->SetConnectionType( aFlg );
358  }
359 
361  void Clear();
362 
367  {
368  for( unsigned ii = 0; ii < size(); ii++ )
370  }
371 
372  /*
373  * Sorts the list of connected items by net code
374  */
375  void SortListbyNetcode();
376 
377  /*
378  * Sorts the list of connected items by sheet.
379  * This sorting is used when searching "physical" connection between items
380  * because obviously only items inside the same sheet can be connected
381  */
382  void SortListbySheet();
383 
390  int CountPinsInNet( unsigned aNetStart );
391 
399  void TestforNonOrphanLabel( unsigned aNetItemRef, unsigned aStartNet );
400 
408  void TestforSimilarLabels();
409 
410 
411  #if defined(DEBUG)
412  void DumpNetTable()
413  {
414  for( unsigned idx = 0; idx < size(); ++idx )
415  {
416  GetItem( idx )->Show( std::cout, idx );
417  }
418  }
419 
420  #endif
421 
422 private:
423  /*
424  * Propagate aNewNetCode to items having an internal netcode aOldNetCode
425  * used to interconnect group of items already physically connected,
426  * when a new connection is found between aOldNetCode and aNewNetCode
427  */
428  void propagateNetCode( int aOldNetCode, int aNewNetCode, bool aIsBus );
429 
430  /*
431  * This function merges the net codes of groups of objects already connected
432  * to labels (wires, bus, pins ... ) when 2 labels are equivalents
433  * (i.e. group objects connected by labels)
434  */
435  void labelConnect( NETLIST_OBJECT* aLabelRef );
436 
437  /* Comparison function to sort by increasing Netcode the list of connected items
438  */
439  static bool sortItemsbyNetcode( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 )
440  {
441  return Objet1->GetNet() < Objet2->GetNet();
442  }
443 
444  /* Comparison routine to sort items by Sheet path
445  */
446  static bool sortItemsBySheet( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 )
447  {
448  return Objet1->m_SheetPath.Cmp( Objet2->m_SheetPath ) < 0;
449  }
450 
455  void sheetLabelConnect( NETLIST_OBJECT* aSheetLabel );
456 
457  void pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus, int start );
458 
466  void segmentToPointConnect( NETLIST_OBJECT* aJonction, bool aIsBus, int aIdxStart );
467 
468 
475  void connectBusLabels();
476 
484  void setUnconnectedFlag();
485 
498 };
499 
500 
508 extern bool IsBusLabel( const wxString& aLabel );
509 
510 #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:198
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...
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...
wxString GetPinNumText()
Function GetPinNum returns a pin number in wxString form.
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
void PinStringNum(wxString &aStringBuffer) const
Fill a string buffer with pin number.
Definition: lib_pin.cpp:1886
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:151
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...