KiCad PCB EDA Suite
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 NETLIST_OBJECT_H
32 #define NETLIST_OBJECT_H
33 
34 
35 #include <sch_sheet_path.h>
36 #include <lib_pin.h>
37 #include <sch_item.h>
38 
40 class SCH_COMPONENT;
41 
42 
43 /* Type of Net objects (wires, labels, pins...) */
44 enum class NETLIST_ITEM
45 {
46  ITEM_UNSPECIFIED, // only for not yet initialized instances
47  SEGMENT, // connection by wire
48  BUS, // connection by bus
49  JUNCTION, // connection by junction: can connect to
50  // or more crossing wires
51  LABEL, // this is a local label
52  GLOBLABEL, // this is a global label that connect all
53  // others global label in whole hierarchy
54  HIERLABEL, // element to indicate connection to a
55  // higher-level sheet
56  SHEETLABEL, // element to indicate connection to a
57  // lower-level sheet.
58  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  GLOBBUSLABELMEMBER, // see NET_BUSLABELMEMBER, used when a
66  // global bus label is found
67  HIERBUSLABELMEMBER, // see NET_BUSLABELMEMBER, used when a
68  // hierarchical bus label is found
69  SHEETBUSLABELMEMBER, // see NET_BUSLABELMEMBER, used when a
70  // pin sheet label using bus notation
71  // is found
72  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  PIN, // this is an usual pin
78  NOCONNECT // this is a no connect symbol
79 };
80 
81 
82 /* Values for .m_FlagOfConnection member */
83 enum class NET_CONNECTION
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 m_Type; /* Type of item (see NETLIST_ITEM_T enum) */
96  EDA_ITEM* m_Comp; /* Pointer to the 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 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 #endif
136 
137  NETLIST_OBJECT();
138  NETLIST_OBJECT( NETLIST_OBJECT& aSource ); // Copy constructor
139 
140  ~NETLIST_OBJECT();
141 
142  // Accessors:
143  void SetNet( int aNetCode ) { m_netCode = aNetCode; }
144  int GetNet() const { return m_netCode; }
145 
154  {
155  m_ConnectionType = aFlg;
156  }
157 
159  {
160  return m_ConnectionType;
161  }
162 
171  void SetNetNameCandidate( NETLIST_OBJECT* aCandidate );
172 
178 
183  const wxString& GetPinNumText() const
184  {
185  return m_PinNum;
186  }
187 
191  const wxString GetPinNameText() const;
192 
199  {
200  if( m_Link && m_Link->Type() == SCH_COMPONENT_T )
201  return (SCH_COMPONENT*) m_Link;
202 
203  return NULL;
204  }
205 
215  bool IsLabelConnected( NETLIST_OBJECT* aNetItem );
216 
223  bool IsLabelGlobal() const;
224 
235  bool IsLabelBusMemberType() const;
236 
241  bool IsLabelType() const;
242 
248  wxString GetNetName() const;
249 
255  wxString GetShortNetName() const;
256 
266  void ConvertBusToNetListItems( NETLIST_OBJECT_LIST& aNetListItems );
267 
268 private:
279  void fillBusVector( NETLIST_OBJECT_LIST& aNetListItems, wxString aName,
280  long aBegin, long aEnd, long aOffset );
281 
282 };
283 
284 
291 typedef std::vector<NETLIST_OBJECT*> NETLIST_OBJECTS;
292 
293 
300 {
301  int m_lastNetCode; // Used in intermediate calculation: last net code created
302  int m_lastBusNetCode; // Used in intermediate calculation:
303  // last net code created for bus members
304 
305 public:
312  {
313  // Do not leave some members uninitialized:
314  m_lastNetCode = 0;
315  m_lastBusNetCode = 0;
316  }
317 
319 
328  bool BuildNetListInfo( SCH_SHEET_LIST& aSheets );
329 
333  NETLIST_OBJECT* GetItem( unsigned aIdx ) const
334  {
335  return *( this->begin() + aIdx );
336  }
337 
341  NETLIST_ITEM GetItemType( unsigned aIdx ) const
342  {
343  return GetItem( aIdx )->m_Type;
344  }
345 
349  int GetItemNet( unsigned aIdx ) const
350  {
351  return GetItem( aIdx )->GetNet();
352  }
353 
355  {
356  return GetItem( aIdx )->GetConnectionType();
357  }
358 
367  {
368  GetItem( aIdx )->SetConnectionType( aFlg );
369  }
370 
372  void Clear();
373 
378  {
379  for( unsigned ii = 0; ii < size(); ii++ )
381  }
382 
383  /*
384  * Sorts the list of connected items by net code
385  */
386  void SortListbyNetcode();
387 
388  /*
389  * Sorts the list of connected items by sheet.
390  * This sorting is used when searching "physical" connection between items
391  * because obviously only items inside the same sheet can be connected
392  */
393  void SortListbySheet();
394 
402  void TestforSimilarLabels();
403 
404  #if defined(DEBUG)
405  void DumpNetTable()
406  {
407  for( unsigned idx = 0; idx < size(); ++idx )
408  {
409  GetItem( idx )->Show( std::cout, idx );
410  }
411  }
412 
413  #endif
414 
415 private:
416  /*
417  * Propagate aNewNetCode to items having an internal netcode aOldNetCode
418  * used to interconnect group of items already physically connected,
419  * when a new connection is found between aOldNetCode and aNewNetCode
420  */
421  void propagateNetCode( int aOldNetCode, int aNewNetCode, bool aIsBus );
422 
423  /*
424  * This function merges the net codes of groups of objects already connected
425  * to labels (wires, bus, pins ... ) when 2 labels are equivalents
426  * (i.e. group objects connected by labels)
427  */
428  void labelConnect( NETLIST_OBJECT* aLabelRef );
429 
430  /* Comparison function to sort by increasing Netcode the list of connected items
431  */
432  static bool sortItemsbyNetcode( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 )
433  {
434  return Objet1->GetNet() < Objet2->GetNet();
435  }
436 
437  /* Comparison routine to sort items by Sheet path
438  */
439  static bool sortItemsBySheet( const NETLIST_OBJECT* Objet1, const NETLIST_OBJECT* Objet2 )
440  {
441  return Objet1->m_SheetPath.Cmp( Objet2->m_SheetPath ) < 0;
442  }
443 
448  void sheetLabelConnect( NETLIST_OBJECT* aSheetLabel );
449 
450  void pointToPointConnect( NETLIST_OBJECT* aRef, bool aIsBus, int start );
451 
459  void segmentToPointConnect( NETLIST_OBJECT* aJonction, bool aIsBus, int aIdxStart );
460 
461 
468  void connectBusLabels();
469 
477  void setUnconnectedFlag();
478 
491 };
492 
493 
501 extern bool IsBusLabel( const wxString& aLabel );
502 
503 #endif // NETLIST_OBJECT_H
void fillBusVector(NETLIST_OBJECT_LIST &aNetListItems, wxString aName, long aBegin, long aEnd, long aOffset)
Given a bus vector, append the appropriate members into the list If given something like "DATA",...
SCH_SHEET_LIST.
void setUnconnectedFlag()
Set the m_FlagOfConnection member of items in list depending on the connection type: UNCONNECTED,...
SCH_COMPONENT * GetComponentParent() const
For Pins (NET_PINS):
void connectBusLabels()
Function connectBusLabels Propagate the net code (and create it, if not yet existing) between all bus...
SCH_SHEET_PATH m_SheetPathInclude
NETLIST_OBJECT * m_netNameCandidate
int GetNet() const
std::vector< NETLIST_OBJECT * > NETLIST_OBJECTS
Type NETLIST_OBJECTS is a container referring to (not owning) NETLIST_OBJECTs, which are connected it...
bool BuildNetListInfo(SCH_SHEET_LIST &aSheets)
Function BuildNetListInfo the master function of tgis class.
bool IsBusLabel(const wxString &aLabel)
Function IsBusLabel test if aLabel has a bus notation.
SCH_SHEET_PATH m_SheetPath
ELECTRICAL_PINTYPE m_ElectricalPinType
void findBestNetNameForEachNet()
Function findBestNetNameForEachNet fill the .m_NetNameCandidate member of each item of aNetItemBuffer...
bool IsLabelType() const
Function IsLabelType.
NET_CONNECTION
void labelConnect(NETLIST_OBJECT *aLabelRef)
int GetItemNet(unsigned aIdx) const
Acces to an item net code.
EDA_ITEM * m_Comp
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.
bool IsLabelBusMemberType() const
Function IsLabelBusMemberType.
bool IsLabelGlobal() const
Function IsLabelGlobal.
NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected items in a...
void segmentToPointConnect(NETLIST_OBJECT *aJonction, bool aIsBus, int aIdxStart)
Search connections between a junction and segments Propagate the junction net code to objects connect...
const wxString GetPinNameText() const
returns the pin name, for NET_PIN (usual pin) item.
static bool sortItemsBySheet(const NETLIST_OBJECT *Objet1, const NETLIST_OBJECT *Objet2)
void TestforSimilarLabels()
Function TestforSimilarLabels detects labels which are different when using case sensitive comparison...
#define NULL
static bool sortItemsbyNetcode(const NETLIST_OBJECT *Objet1, const NETLIST_OBJECT *Objet2)
void propagateNetCode(int aOldNetCode, int aNewNetCode, bool aIsBus)
NET_CONNECTION GetConnectionType() const
SCH_SHEET_PATH.
NETLIST_ITEM GetItemType(unsigned aIdx) const
Acces to an item type.
const wxString & GetPinNumText() const
returns a pin number in wxString form.
void SetConnectionType(NET_CONNECTION aFlg=NET_CONNECTION::UNCONNECTED)
Set the item connection type: UNCONNECTED Pin or Label not connected (error) NOCONNECT_SYMBOL_PRESENT...
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 ...
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
NETLIST_OBJECT_LIST()
Constructor.
wxString GetShortNetName() const
Function GetShortNetName.
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...
Schematic symbol object.
Definition: sch_component.h:88
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
void pointToPointConnect(NETLIST_OBJECT *aRef, bool aIsBus, int start)
void SetConnectionType(unsigned aIdx, NET_CONNECTION aFlg=NET_CONNECTION::UNCONNECTED)
Set the item connection type: UNCONNECTED Pin or Label not connected (error) NOCONNECT_SYMBOL_PRESENT...
NETLIST_ITEM
wxString GetNetName() const
Function GetNetName.
bool HasNetNameCandidate()
NET_CONNECTION GetConnectionType(unsigned aIdx)
NET_CONNECTION m_ConnectionType
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
NETLIST_ITEM m_Type
SCH_ITEM * m_Link
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Function Cmp Compare if this is the same sheet path as aSheetPathToTest.
void ConvertBusToNetListItems(NETLIST_OBJECT_LIST &aNetListItems)
Function ConvertBusToNetListItems breaks the text of a bus label type net list object into as many me...
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193