KiCad PCB EDA Suite
NETLIST_OBJECT_LIST Class Reference

NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected items in a full schematic hierarchy. More...

#include <netlist_object.h>

Inheritance diagram for NETLIST_OBJECT_LIST:

Public Member Functions

 NETLIST_OBJECT_LIST ()
 Constructor. More...
 
 ~NETLIST_OBJECT_LIST ()
 
bool BuildNetListInfo (SCH_SHEET_LIST &aSheets)
 Function BuildNetListInfo the master function of tgis class. More...
 
NETLIST_OBJECTGetItem (unsigned aIdx) const
 Acces to an item in list. More...
 
NETLIST_ITEM GetItemType (unsigned aIdx) const
 Acces to an item type. More...
 
int GetItemNet (unsigned aIdx) const
 Acces to an item net code. More...
 
NET_CONNECTION GetConnectionType (unsigned aIdx)
 
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 Pin not connected but have a NoConnect symbol on it (no error) PAD_CONNECT Normal connection (no error) More...
 
void Clear ()
 Delete all objects in list and clear list. More...
 
void ResetConnectionsType ()
 Reset the connection type of all items to UNCONNECTED type. More...
 
void SortListbyNetcode ()
 
void SortListbySheet ()
 
void TestforSimilarLabels ()
 Function TestforSimilarLabels detects labels which are different when using case sensitive comparisons but are equal when using case insensitive comparisons It can be due to a mistake from designer, so this kind of labels is reported by TestforSimilarLabels. More...
 

Private Member Functions

void propagateNetCode (int aOldNetCode, int aNewNetCode, bool aIsBus)
 
void labelConnect (NETLIST_OBJECT *aLabelRef)
 
void sheetLabelConnect (NETLIST_OBJECT *aSheetLabel)
 Propagate net codes from a parent sheet to an include sheet, from a pin sheet connection. More...
 
void pointToPointConnect (NETLIST_OBJECT *aRef, bool aIsBus, int start)
 
void segmentToPointConnect (NETLIST_OBJECT *aJonction, bool aIsBus, int aIdxStart)
 Search connections between a junction and segments Propagate the junction net code to objects connected by this junction. More...
 
void connectBusLabels ()
 Function connectBusLabels Propagate the net code (and create it, if not yet existing) between all bus label member objects connected by they name. More...
 
void setUnconnectedFlag ()
 Set the m_FlagOfConnection member of items in list depending on the connection type: UNCONNECTED, PAD_CONNECT or NOCONNECT_SYMBOL_PRESENT The list is expected sorted by order of net code, i.e. More...
 
void findBestNetNameForEachNet ()
 Function findBestNetNameForEachNet fill the .m_NetNameCandidate member of each item of aNetItemBuffer with a reference to the "best" NETLIST_OBJECT usable to give a name to the net If no suitable object found, .m_NetNameCandidate is filled with 0. More...
 

Static Private Member Functions

static bool sortItemsbyNetcode (const NETLIST_OBJECT *Objet1, const NETLIST_OBJECT *Objet2)
 
static bool sortItemsBySheet (const NETLIST_OBJECT *Objet1, const NETLIST_OBJECT *Objet2)
 

Private Attributes

int m_lastNetCode
 
int m_lastBusNetCode
 

Detailed Description

NETLIST_OBJECT_LIST is a container holding and owning NETLIST_OBJECTs, which are connected items in a full schematic hierarchy.

It is helpful for netlist and ERC calculations.

Definition at line 299 of file netlist_object.h.

Constructor & Destructor Documentation

◆ NETLIST_OBJECT_LIST()

NETLIST_OBJECT_LIST::NETLIST_OBJECT_LIST ( )
inline

Constructor.

NETLIST_OBJECT_LIST handle a list of connected items. these NETLIST_OBJECT items are freeed by the destructor

Definition at line 311 of file netlist_object.h.

312  {
313  // Do not leave some members uninitialized:
314  m_lastNetCode = 0;
315  m_lastBusNetCode = 0;
316  }

References m_lastBusNetCode, and m_lastNetCode.

◆ ~NETLIST_OBJECT_LIST()

NETLIST_OBJECT_LIST::~NETLIST_OBJECT_LIST ( )

Definition at line 40 of file netlist_object_list.cpp.

41 {
42  Clear();
43 }
void Clear()
Delete all objects in list and clear list.

References Clear().

Member Function Documentation

◆ BuildNetListInfo()

bool NETLIST_OBJECT_LIST::BuildNetListInfo ( SCH_SHEET_LIST aSheets)

Function BuildNetListInfo the master function of tgis class.

Build the list of connected objects (pins, labels ...) and all info to generate netlists or run ERC diags

Parameters
aSheets= the flattened sheet list
Returns
true if OK, false is not item found

Definition at line 72 of file netlist_object_list.cpp.

73 {
74  SCH_SHEET_PATH* sheet;
75 
76  // Fill list with connected items from the flattened sheet list
77  for( unsigned i = 0; i < aSheets.size(); i++ )
78  {
79  sheet = &aSheets[i];
80 
81  for( auto item : sheet->LastScreen()->Items() )
82  item->GetNetListItem( *this, sheet );
83  }
84 
85  if( size() == 0 )
86  return false;
87 
88  // Sort objects by Sheet
90 
91  sheet = &(GetItem( 0 )->m_SheetPath);
93 
94  for( unsigned ii = 0, istart = 0; ii < size(); ii++ )
95  {
96  NETLIST_OBJECT* net_item = GetItem( ii );
97 
98  if( net_item->m_SheetPath != *sheet ) // Sheet change
99  {
100  sheet = &(net_item->m_SheetPath);
101  istart = ii;
102  }
103 
104  switch( net_item->m_Type )
105  {
107  wxMessageBox( wxT( "BuildNetListInfo() error" ) );
108  break;
109 
110  case NETLIST_ITEM::PIN:
114  if( net_item->GetNet() != 0 )
115  break;
116 
117  // Intentionally fall through if there is no net assigned
118 
120  // Test connections point to point type without bus.
121  if( net_item->GetNet() == 0 )
122  {
123  net_item->SetNet( m_lastNetCode );
124  m_lastNetCode++;
125  }
126 
127  pointToPointConnect( net_item, IS_WIRE, istart );
128  break;
129 
131  // Control of the junction outside BUS.
132  if( net_item->GetNet() == 0 )
133  {
134  net_item->SetNet( m_lastNetCode );
135  m_lastNetCode++;
136  }
137 
138  segmentToPointConnect( net_item, IS_WIRE, istart );
139 
140  // Control of the junction, on BUS.
141  if( net_item->m_BusNetCode == 0 )
142  {
143  net_item->m_BusNetCode = m_lastBusNetCode;
145  }
146 
147  segmentToPointConnect( net_item, IS_BUS, istart );
148  break;
149 
150  case NETLIST_ITEM::LABEL:
153  // Test connections type junction without bus.
154  if( net_item->GetNet() == 0 )
155  {
156  net_item->SetNet( m_lastNetCode );
157  m_lastNetCode++;
158  }
159 
160  segmentToPointConnect( net_item, IS_WIRE, istart );
161  break;
162 
164  if( net_item->m_BusNetCode != 0 )
165  break;
166 
167  // Intentionally fall through if there is no bus assigned
168 
169  case NETLIST_ITEM::BUS:
170  // Control type connections point to point mode bus
171  if( net_item->m_BusNetCode == 0 )
172  {
173  net_item->m_BusNetCode = m_lastBusNetCode;
175  }
176 
177  pointToPointConnect( net_item, IS_BUS, istart );
178  break;
179 
183  // Control connections similar has on BUS
184  if( net_item->GetNet() == 0 )
185  {
186  net_item->m_BusNetCode = m_lastBusNetCode;
188  }
189 
190  segmentToPointConnect( net_item, IS_BUS, istart );
191  break;
192  }
193  }
194 
195 #if defined(NETLIST_DEBUG) && defined(DEBUG)
196  std::cout << "\n\nafter sheet local\n\n";
197  DumpNetTable();
198 #endif
199 
200  // Updating the Bus Labels Netcode connected by Bus
202 
203  // Group objects by label.
204  for( unsigned ii = 0; ii < size(); ii++ )
205  {
206  switch( GetItem( ii )->m_Type )
207  {
208  case NETLIST_ITEM::PIN:
212  case NETLIST_ITEM::BUS:
214  break;
215 
216  case NETLIST_ITEM::LABEL:
221  labelConnect( GetItem( ii ) );
222  break;
223 
227  break;
228 
230  break;
231  }
232  }
233 
234 #if defined(NETLIST_DEBUG) && defined(DEBUG)
235  std::cout << "\n\nafter sheet global\n\n";
236  DumpNetTable();
237 #endif
238 
239  // Connection between hierarchy sheets
240  for( unsigned ii = 0; ii < size(); ii++ )
241  {
244  sheetLabelConnect( GetItem( ii ) );
245  }
246 
247  // Sort objects by NetCode
249 
250 #if defined(NETLIST_DEBUG) && defined(DEBUG)
251  std::cout << "\n\nafter qsort()\n";
252  DumpNetTable();
253 #endif
254 
255  // Compress numbers of Netcode having consecutive values.
256  int NetCode = 0;
257  m_lastNetCode = 0;
258 
259  for( unsigned ii = 0; ii < size(); ii++ )
260  {
261  if( GetItem( ii )->GetNet() != m_lastNetCode )
262  {
263  NetCode++;
264  m_lastNetCode = GetItem( ii )->GetNet();
265  }
266 
267  GetItem( ii )->SetNet( NetCode );
268  }
269 
270  // Set the minimal connection info:
272 
273  // find the best label object to give the best net name to each net
275 
276  return true;
277 }
void setUnconnectedFlag()
Set the m_FlagOfConnection member of items in list depending on the connection type: UNCONNECTED,...
void connectBusLabels()
Function connectBusLabels Propagate the net code (and create it, if not yet existing) between all bus...
int GetNet() const
#define IS_BUS
SCH_SHEET_PATH m_SheetPath
void findBestNetNameForEachNet()
Function findBestNetNameForEachNet fill the .m_NetNameCandidate member of each item of aNetItemBuffer...
void labelConnect(NETLIST_OBJECT *aLabelRef)
void sheetLabelConnect(NETLIST_OBJECT *aSheetLabel)
Propagate net codes from a parent sheet to an include sheet, from a pin sheet connection.
void segmentToPointConnect(NETLIST_OBJECT *aJonction, bool aIsBus, int aIdxStart)
Search connections between a junction and segments Propagate the junction net code to objects connect...
#define IS_WIRE
SCH_SHEET_PATH.
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
SCH_SCREEN * LastScreen()
Function LastScreen.
void SetNet(int aNetCode)
EE_RTREE & Items()
Definition: sch_screen.h:127
void pointToPointConnect(NETLIST_OBJECT *aRef, bool aIsBus, int start)
NETLIST_ITEM m_Type

References BUS, BUSLABELMEMBER, connectBusLabels(), findBestNetNameForEachNet(), GetItem(), NETLIST_OBJECT::GetNet(), GLOBBUSLABELMEMBER, GLOBLABEL, HIERBUSLABELMEMBER, HIERLABEL, IS_BUS, IS_WIRE, ITEM_UNSPECIFIED, SCH_SCREEN::Items(), JUNCTION, LABEL, labelConnect(), SCH_SHEET_PATH::LastScreen(), NETLIST_OBJECT::m_BusNetCode, m_lastBusNetCode, m_lastNetCode, NETLIST_OBJECT::m_SheetPath, NETLIST_OBJECT::m_Type, NOCONNECT, PIN, PINLABEL, pointToPointConnect(), SEGMENT, segmentToPointConnect(), NETLIST_OBJECT::SetNet(), setUnconnectedFlag(), SHEETBUSLABELMEMBER, SHEETLABEL, sheetLabelConnect(), SortListbyNetcode(), and SortListbySheet().

◆ Clear()

void NETLIST_OBJECT_LIST::Clear ( )

Delete all objects in list and clear list.

Definition at line 46 of file netlist_object_list.cpp.

47 {
48  NETLIST_OBJECTS::iterator iter;
49 
50  for( iter = begin(); iter != end(); iter++ )
51  {
52  NETLIST_OBJECT* item = *iter;
53  delete item;
54  }
55 
56  clear();
57 }

Referenced by ~NETLIST_OBJECT_LIST().

◆ connectBusLabels()

void NETLIST_OBJECT_LIST::connectBusLabels ( )
private

Function connectBusLabels Propagate the net code (and create it, if not yet existing) between all bus label member objects connected by they name.

Search is done in the entire list

Definition at line 528 of file netlist_object_list.cpp.

529 {
530  // Propagate the net code between all bus label member objects connected by they name.
531  // If the net code is not yet existing, a new one is created
532  // Search is done in the entire list
533  for( unsigned ii = 0; ii < size(); ii++ )
534  {
535  NETLIST_OBJECT* Label = GetItem( ii );
536 
537  if( Label->IsLabelBusMemberType() )
538  {
539  if( Label->GetNet() == 0 )
540  {
541  // Not yet existiing net code: create a new one.
542  Label->SetNet( m_lastNetCode );
543  m_lastNetCode++;
544  }
545 
546  for( unsigned jj = ii + 1; jj < size(); jj++ )
547  {
548  NETLIST_OBJECT* LabelInTst = GetItem( jj );
549 
550  if( LabelInTst->IsLabelBusMemberType() )
551  {
552  if( LabelInTst->m_BusNetCode != Label->m_BusNetCode )
553  continue;
554 
555  if( LabelInTst->m_Member != Label->m_Member )
556  continue;
557 
558  if( LabelInTst->GetNet() == 0 )
559  // Append this object to the current net
560  LabelInTst->SetNet( Label->GetNet() );
561  else
562  // Merge the 2 net codes, they are connected.
563  propagateNetCode( LabelInTst->GetNet(), Label->GetNet(), IS_WIRE );
564  }
565  }
566  }
567  }
568 }
int GetNet() const
bool IsLabelBusMemberType() const
Function IsLabelBusMemberType.
void propagateNetCode(int aOldNetCode, int aNewNetCode, bool aIsBus)
#define IS_WIRE
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
void SetNet(int aNetCode)

References GetItem(), NETLIST_OBJECT::GetNet(), IS_WIRE, NETLIST_OBJECT::IsLabelBusMemberType(), NETLIST_OBJECT::m_BusNetCode, m_lastNetCode, NETLIST_OBJECT::m_Member, propagateNetCode(), and NETLIST_OBJECT::SetNet().

Referenced by BuildNetListInfo().

◆ findBestNetNameForEachNet()

void NETLIST_OBJECT_LIST::findBestNetNameForEachNet ( )
private

Function findBestNetNameForEachNet fill the .m_NetNameCandidate member of each item of aNetItemBuffer with a reference to the "best" NETLIST_OBJECT usable to give a name to the net If no suitable object found, .m_NetNameCandidate is filled with 0.

The "best" NETLIST_OBJECT is a NETLIST_OBJECT that have the type label and by priority order: the label is global or local the label is in the first sheet in a hierarchy (the root sheet has the most priority) alphabetic order.

Definition at line 351 of file netlist_object_list.cpp.

352 {
353  // Important note: NETLIST_ITEM::SHEETLABEL items of sheet items should *NOT* be considered,
354  // because they live in a sheet but their names are actually used in the subsheet.
355  // Moreover, in the parent sheet, the name of NETLIST_ITEM::SHEETLABEL can be not unique,
356  // ( for instance when 2 different sheets share the same schematic in complex hierarchies
357  // and 2 identical NETLIST_ITEM::SHEETLABEL labels can be connected to 2 different nets
358 
359  int netcode = 0; // current netcode for tested items
360  unsigned idxstart = 0; // index of the first item of this net
361  NETLIST_OBJECT* item;
362  NETLIST_OBJECT* candidate;
363 
364  // Pass 1: find the best name for labelled nets:
365  candidate = NULL;
366  for( unsigned ii = 0; ii <= size(); ii++ )
367  {
368  if( ii == size() ) // last item already tested
369  item = NULL;
370  else
371  item = GetItem( ii );
372 
373  if( !item || netcode != item->GetNet() ) // End of net found
374  {
375  if( candidate ) // One or more labels exists, find the best
376  {
377  for (unsigned jj = idxstart; jj < ii; jj++ )
378  GetItem( jj )->SetNetNameCandidate( candidate );
379  }
380 
381  if( item == NULL ) // End of list
382  break;
383 
384  // Prepare next net analysis:
385  netcode = item->GetNet();
386  candidate = NULL;
387  idxstart = ii;
388  }
389 
390  switch( item->m_Type )
391  {
393  case NETLIST_ITEM::LABEL:
397  // A candidate is found: select the better between the previous and this one
398  if( candidate == NULL )
399  candidate = item;
400  else
401  {
402  if( evalLabelsPriority( item, candidate ) )
403  // item has a higher priority than candidate so update the best candidate
404  candidate = item;
405  }
406  break;
407 
408  default:
409  break;
410  }
411  }
412 
413  // Pass 2: find the best name for not labelled nets:
414  // The "default" net name is Net-<<Ref cmp>_Pad<num pad>>
415  // (see NETLIST_OBJECT::GetShortNetName())
416  // therefore the "best" is the short net name alphabetically classed first
417  // (to avoid net names changes when the net is not modified,
418  // even if components are moved or deleted and undelete or replaced, as long
419  // the reference is kept)
420 
421  // Build a list of items with no net names
422  NETLIST_OBJECTS list; // no ownership of elements being pointed at
423 
424  for( unsigned ii = 0; ii < size(); ii++ )
425  {
426  item = GetItem( ii );
427 
428  if( !item->HasNetNameCandidate() )
429  list.push_back( item );
430  }
431 
432  if( list.size() == 0 )
433  return;
434 
435  idxstart = 0;
436  candidate = NULL;
437  netcode = list[0]->GetNet();
438 
439  for( unsigned ii = 0; ii <= list.size(); ii++ )
440  {
441  if( ii < list.size() )
442  item = list[ii];
443  else
444  item = NULL;
445 
446  if( !item || netcode != item->GetNet() ) // End of net found
447  {
448  if( candidate )
449  {
450  for (unsigned jj = idxstart; jj < ii; jj++ )
451  {
452  NETLIST_OBJECT* obj = list[jj];
453  obj->SetNetNameCandidate( candidate );
454  }
455  }
456 
457  if( !item )
458  break;
459 
460  netcode = item->GetNet();
461  candidate = NULL;
462  idxstart = ii;
463  }
464 
465  // Examine all pins of the net to find the best candidate,
466  // i.e. the first net name candidate, by alphabetic order
467  // the net names are built by GetShortNetName
468  // (Net-<{reference}-Pad{pad number}> like Net-<U3-Pad5>
469  // Not named nets do not have usually a lot of members.
470  // Many have only 2 members(a pad and a non connection symbol)
471  if( item->m_Type == NETLIST_ITEM::PIN )
472  {
473  // A candidate is found, however components which are not in
474  // netlist are not candidate because some have their reference
475  // changed each time the netlist is built (power components)
476  // and anyway obviously they are not a good candidate
477  SCH_COMPONENT* link = item->GetComponentParent();
478 
479  if( link && link->IsInNetlist() )
480  {
481  // select the better between the previous and this one
482  item->SetNetNameCandidate( item ); // Needed to calculate GetShortNetName
483 
484  if( candidate == NULL )
485  candidate = item;
486  else
487  {
488  if( item->GetShortNetName().Cmp( candidate->GetShortNetName() ) < 0 )
489  candidate = item;
490  }
491  }
492  }
493  }
494 }
SCH_COMPONENT * GetComponentParent() const
For Pins (NET_PINS):
static bool evalLabelsPriority(const NETLIST_OBJECT *aLabel1, const NETLIST_OBJECT *aLabel2)
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 IsInNetlist() const
#define NULL
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
wxString GetShortNetName() const
Function GetShortNetName.
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...
SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:99
bool HasNetNameCandidate()
NETLIST_ITEM m_Type

References evalLabelsPriority(), NETLIST_OBJECT::GetComponentParent(), GetItem(), NETLIST_OBJECT::GetNet(), NETLIST_OBJECT::GetShortNetName(), GLOBBUSLABELMEMBER, GLOBLABEL, NETLIST_OBJECT::HasNetNameCandidate(), HIERLABEL, SCH_COMPONENT::IsInNetlist(), LABEL, NETLIST_OBJECT::m_Type, NULL, PIN, PINLABEL, and NETLIST_OBJECT::SetNetNameCandidate().

Referenced by BuildNetListInfo().

◆ GetConnectionType()

NET_CONNECTION NETLIST_OBJECT_LIST::GetConnectionType ( unsigned  aIdx)
inline

Definition at line 354 of file netlist_object.h.

355  {
356  return GetItem( aIdx )->GetConnectionType();
357  }
NET_CONNECTION GetConnectionType() const
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.

References NETLIST_OBJECT::GetConnectionType(), and GetItem().

Referenced by TestOthersItems().

◆ GetItem()

◆ GetItemNet()

int NETLIST_OBJECT_LIST::GetItemNet ( unsigned  aIdx) const
inline

Acces to an item net code.

Definition at line 349 of file netlist_object.h.

350  {
351  return GetItem( aIdx )->GetNet();
352  }
int GetNet() const
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.

References GetItem(), and NETLIST_OBJECT::GetNet().

Referenced by TestOthersItems().

◆ GetItemType()

NETLIST_ITEM NETLIST_OBJECT_LIST::GetItemType ( unsigned  aIdx) const
inline

Acces to an item type.

Definition at line 341 of file netlist_object.h.

342  {
343  return GetItem( aIdx )->m_Type;
344  }
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
NETLIST_ITEM m_Type

References GetItem(), and NETLIST_OBJECT::m_Type.

Referenced by TestforSimilarLabels(), and TestOthersItems().

◆ labelConnect()

void NETLIST_OBJECT_LIST::labelConnect ( NETLIST_OBJECT aLabelRef)
private

Definition at line 738 of file netlist_object_list.cpp.

739 {
740  if( aLabelRef->GetNet() == 0 )
741  return;
742 
743  for( unsigned i = 0; i < size(); i++ )
744  {
745  NETLIST_OBJECT* item = GetItem( i );
746 
747  if( item->GetNet() == aLabelRef->GetNet() )
748  continue;
749 
750  if( item->m_SheetPath != aLabelRef->m_SheetPath )
751  {
754  continue;
755 
756  if( ( item->m_Type == NETLIST_ITEM::GLOBLABEL
758  && item->m_Type != aLabelRef->m_Type )
759  //global labels only connect other global labels.
760  continue;
761  }
762 
763  // NETLIST_ITEM::HIERLABEL are used to connect sheets.
764  // NETLIST_ITEM::LABEL are local to a sheet
765  // NETLIST_ITEM::GLOBLABEL are global.
766  // NETLIST_ITEM::PINLABEL is a kind of global label (generated by a power pin invisible)
767  if( item->IsLabelType() )
768  {
769  if( item->m_Label != aLabelRef->m_Label )
770  continue;
771 
772  if( item->GetNet() )
773  propagateNetCode( item->GetNet(), aLabelRef->GetNet(), IS_WIRE );
774  else
775  item->SetNet( aLabelRef->GetNet() );
776  }
777  }
778 }
int GetNet() const
SCH_SHEET_PATH m_SheetPath
bool IsLabelType() const
Function IsLabelType.
void propagateNetCode(int aOldNetCode, int aNewNetCode, bool aIsBus)
#define IS_WIRE
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
void SetNet(int aNetCode)
NETLIST_ITEM m_Type

References GetItem(), NETLIST_OBJECT::GetNet(), GLOBBUSLABELMEMBER, GLOBLABEL, IS_WIRE, NETLIST_OBJECT::IsLabelType(), NETLIST_OBJECT::m_Label, NETLIST_OBJECT::m_SheetPath, NETLIST_OBJECT::m_Type, PINLABEL, propagateNetCode(), and NETLIST_OBJECT::SetNet().

Referenced by BuildNetListInfo().

◆ pointToPointConnect()

void NETLIST_OBJECT_LIST::pointToPointConnect ( NETLIST_OBJECT aRef,
bool  aIsBus,
int  start 
)
private

Definition at line 599 of file netlist_object_list.cpp.

600 {
601  int netCode;
602 
603  if( aIsBus == false ) // Objects other than BUS and BUSLABELS
604  {
605  netCode = aRef->GetNet();
606 
607  for( unsigned i = start; i < size(); i++ )
608  {
609  NETLIST_OBJECT* item = GetItem( i );
610 
611  if( item->m_SheetPath != aRef->m_SheetPath ) //used to be > (why?)
612  continue;
613 
614  switch( item->m_Type )
615  {
617  case NETLIST_ITEM::PIN:
618  case NETLIST_ITEM::LABEL:
625  if( aRef->m_Start == item->m_Start
626  || aRef->m_Start == item->m_End
627  || aRef->m_End == item->m_Start
628  || aRef->m_End == item->m_End )
629  {
630  if( item->GetNet() == 0 )
631  item->SetNet( netCode );
632  else
633  propagateNetCode( item->GetNet(), netCode, IS_WIRE );
634  }
635  break;
636 
637  case NETLIST_ITEM::BUS:
643  break;
644  }
645  }
646  }
647  else // Object type BUS, BUSLABELS, and junctions.
648  {
649  netCode = aRef->m_BusNetCode;
650 
651  for( unsigned i = start; i < size(); i++ )
652  {
653  NETLIST_OBJECT* item = GetItem( i );
654 
655  if( item->m_SheetPath != aRef->m_SheetPath )
656  continue;
657 
658  switch( item->m_Type )
659  {
662  case NETLIST_ITEM::PIN:
663  case NETLIST_ITEM::LABEL:
669  break;
670 
671  case NETLIST_ITEM::BUS:
677  if( aRef->m_Start == item->m_Start
678  || aRef->m_Start == item->m_End
679  || aRef->m_End == item->m_Start
680  || aRef->m_End == item->m_End )
681  {
682  if( item->m_BusNetCode == 0 )
683  item->m_BusNetCode = netCode;
684  else
685  propagateNetCode( item->m_BusNetCode, netCode, IS_BUS );
686  }
687  break;
688  }
689  }
690  }
691 }
int GetNet() const
#define IS_BUS
SCH_SHEET_PATH m_SheetPath
void propagateNetCode(int aOldNetCode, int aNewNetCode, bool aIsBus)
#define IS_WIRE
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
void SetNet(int aNetCode)
NETLIST_ITEM m_Type

References BUS, BUSLABELMEMBER, GetItem(), NETLIST_OBJECT::GetNet(), GLOBBUSLABELMEMBER, GLOBLABEL, HIERBUSLABELMEMBER, HIERLABEL, IS_BUS, IS_WIRE, ITEM_UNSPECIFIED, JUNCTION, LABEL, NETLIST_OBJECT::m_BusNetCode, NETLIST_OBJECT::m_End, NETLIST_OBJECT::m_SheetPath, NETLIST_OBJECT::m_Start, NETLIST_OBJECT::m_Type, NOCONNECT, PIN, PINLABEL, propagateNetCode(), SEGMENT, NETLIST_OBJECT::SetNet(), SHEETBUSLABELMEMBER, and SHEETLABEL.

Referenced by BuildNetListInfo().

◆ propagateNetCode()

void NETLIST_OBJECT_LIST::propagateNetCode ( int  aOldNetCode,
int  aNewNetCode,
bool  aIsBus 
)
private

Definition at line 571 of file netlist_object_list.cpp.

572 {
573  if( aOldNetCode == aNewNetCode )
574  return;
575 
576  if( aIsBus == false ) // Propagate NetCode
577  {
578  for( unsigned jj = 0; jj < size(); jj++ )
579  {
580  NETLIST_OBJECT* object = GetItem( jj );
581 
582  if( object->GetNet() == aOldNetCode )
583  object->SetNet( aNewNetCode );
584  }
585  }
586  else // Propagate BusNetCode
587  {
588  for( unsigned jj = 0; jj < size(); jj++ )
589  {
590  NETLIST_OBJECT* object = GetItem( jj );
591 
592  if( object->m_BusNetCode == aOldNetCode )
593  object->m_BusNetCode = aNewNetCode;
594  }
595  }
596 }
int GetNet() const
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
void SetNet(int aNetCode)

References GetItem(), NETLIST_OBJECT::GetNet(), NETLIST_OBJECT::m_BusNetCode, and NETLIST_OBJECT::SetNet().

Referenced by connectBusLabels(), labelConnect(), pointToPointConnect(), segmentToPointConnect(), and sheetLabelConnect().

◆ ResetConnectionsType()

void NETLIST_OBJECT_LIST::ResetConnectionsType ( )
inline

Reset the connection type of all items to UNCONNECTED type.

Definition at line 377 of file netlist_object.h.

378  {
379  for( unsigned ii = 0; ii < size(); ii++ )
381  }
void SetConnectionType(NET_CONNECTION aFlg=NET_CONNECTION::UNCONNECTED)
Set the item connection type: UNCONNECTED Pin or Label not connected (error) NOCONNECT_SYMBOL_PRESENT...
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.

References GetItem(), NETLIST_OBJECT::SetConnectionType(), and UNCONNECTED.

◆ segmentToPointConnect()

void NETLIST_OBJECT_LIST::segmentToPointConnect ( NETLIST_OBJECT aJonction,
bool  aIsBus,
int  aIdxStart 
)
private

Search connections between a junction and segments Propagate the junction net code to objects connected by this junction.

The junction must have a valid net code The list of objects is expected sorted by sheets. Search is done from index aIdxStart to the last element of list

Definition at line 694 of file netlist_object_list.cpp.

696 {
697  for( unsigned i = aIdxStart; i < size(); i++ )
698  {
699  NETLIST_OBJECT* segment = GetItem( i );
700 
701  // if different sheets, obviously no physical connection between elements.
702  if( segment->m_SheetPath != aJonction->m_SheetPath )
703  continue;
704 
705  if( aIsBus == IS_WIRE )
706  {
707  if( segment->m_Type != NETLIST_ITEM::SEGMENT )
708  continue;
709  }
710  else
711  {
712  if( segment->m_Type != NETLIST_ITEM::BUS )
713  continue;
714  }
715 
716  if( IsPointOnSegment( segment->m_Start, segment->m_End, aJonction->m_Start ) )
717  {
718  // Propagation Netcode has all the objects of the same Netcode.
719  if( aIsBus == IS_WIRE )
720  {
721  if( segment->GetNet() )
722  propagateNetCode( segment->GetNet(), aJonction->GetNet(), aIsBus );
723  else
724  segment->SetNet( aJonction->GetNet() );
725  }
726  else
727  {
728  if( segment->m_BusNetCode )
729  propagateNetCode( segment->m_BusNetCode, aJonction->m_BusNetCode, aIsBus );
730  else
731  segment->m_BusNetCode = aJonction->m_BusNetCode;
732  }
733  }
734  }
735 }
int GetNet() const
bool IsPointOnSegment(const wxPoint &aSegStart, const wxPoint &aSegEnd, const wxPoint &aTestPoint)
Test if aTestPoint is on line defined by aSegStart and aSegEnd.
Definition: trigo.cpp:42
SCH_SHEET_PATH m_SheetPath
void propagateNetCode(int aOldNetCode, int aNewNetCode, bool aIsBus)
#define IS_WIRE
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
void SetNet(int aNetCode)
NETLIST_ITEM m_Type

References BUS, GetItem(), NETLIST_OBJECT::GetNet(), IS_WIRE, IsPointOnSegment(), NETLIST_OBJECT::m_BusNetCode, NETLIST_OBJECT::m_End, NETLIST_OBJECT::m_SheetPath, NETLIST_OBJECT::m_Start, NETLIST_OBJECT::m_Type, propagateNetCode(), SEGMENT, and NETLIST_OBJECT::SetNet().

Referenced by BuildNetListInfo().

◆ SetConnectionType()

void NETLIST_OBJECT_LIST::SetConnectionType ( unsigned  aIdx,
NET_CONNECTION  aFlg = NET_CONNECTION::UNCONNECTED 
)
inline

Set the item connection type: UNCONNECTED Pin or Label not connected (error) NOCONNECT_SYMBOL_PRESENT Pin not connected but have a NoConnect symbol on it (no error) PAD_CONNECT Normal connection (no error)

Definition at line 366 of file netlist_object.h.

367  {
368  GetItem( aIdx )->SetConnectionType( aFlg );
369  }
void SetConnectionType(NET_CONNECTION aFlg=NET_CONNECTION::UNCONNECTED)
Set the item connection type: UNCONNECTED Pin or Label not connected (error) NOCONNECT_SYMBOL_PRESENT...
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.

References GetItem(), and NETLIST_OBJECT::SetConnectionType().

Referenced by TestOthersItems().

◆ setUnconnectedFlag()

void NETLIST_OBJECT_LIST::setUnconnectedFlag ( )
private

Set the m_FlagOfConnection member of items in list depending on the connection type: UNCONNECTED, PAD_CONNECT or NOCONNECT_SYMBOL_PRESENT The list is expected sorted by order of net code, i.e.

items having the same net code are grouped

Definition at line 781 of file netlist_object_list.cpp.

782 {
783  NETLIST_OBJECT* NetItemRef;
784  unsigned NetStart, NetEnd;
785  NET_CONNECTION StateFlag;
786 
787  NetStart = NetEnd = 0;
788  StateFlag = NET_CONNECTION::UNCONNECTED;
789  for( unsigned ii = 0; ii < size(); ii++ )
790  {
791  NetItemRef = GetItem( ii );
792  if( NetItemRef->m_Type == NETLIST_ITEM::NOCONNECT
793  && StateFlag != NET_CONNECTION::PAD_CONNECT )
795 
796  // Analysis of current net.
797  unsigned idxtoTest = ii + 1;
798 
799  if( ( idxtoTest >= size() )
800  || ( NetItemRef->GetNet() != GetItem( idxtoTest )->GetNet() ) )
801  {
802  // Net analysis to update m_ConnectionType
803  NetEnd = idxtoTest;
804 
805  /* set m_ConnectionType member to StateFlag for all items of
806  * this net: */
807  for( unsigned kk = NetStart; kk < NetEnd; kk++ )
808  GetItem( kk )->m_ConnectionType = StateFlag;
809 
810  if( idxtoTest >= size() )
811  return;
812 
813  // Start Analysis next Net
814  StateFlag = NET_CONNECTION::UNCONNECTED;
815  NetStart = idxtoTest;
816  continue;
817  }
818 
819  /* test the current item: if this is a pin and if the reference item
820  * is also a pin, then 2 pins are connected, so set StateFlag to
821  * PAD_CONNECT (can be already done) Of course, if the current
822  * item is a no connect symbol, set StateFlag to
823  * NOCONNECT_SYMBOL_PRESENT to inhibit error diags. However if
824  * StateFlag is already set to PAD_CONNECT this state is kept (the
825  * no connect symbol was surely an error and an ERC will report this)
826  */
827  for( ; ; idxtoTest++ )
828  {
829  if( ( idxtoTest >= size() )
830  || ( NetItemRef->GetNet() != GetItem( idxtoTest )->GetNet() ) )
831  break;
832 
833  switch( GetItem( idxtoTest )->m_Type )
834  {
836  wxMessageBox( wxT( "BuildNetListBase() error" ) );
837  break;
838 
840  case NETLIST_ITEM::LABEL:
845  case NETLIST_ITEM::BUS:
851  break;
852 
853  case NETLIST_ITEM::PIN:
854  if( NetItemRef->m_Type == NETLIST_ITEM::PIN )
855  StateFlag = NET_CONNECTION::PAD_CONNECT;
856 
857  break;
858 
860  if( StateFlag != NET_CONNECTION::PAD_CONNECT )
862 
863  break;
864  }
865  }
866  }
867 }
int GetNet() const
NET_CONNECTION
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
NET_CONNECTION m_ConnectionType
NETLIST_ITEM m_Type

References BUS, BUSLABELMEMBER, GetItem(), NETLIST_OBJECT::GetNet(), GLOBBUSLABELMEMBER, GLOBLABEL, HIERBUSLABELMEMBER, HIERLABEL, ITEM_UNSPECIFIED, JUNCTION, LABEL, NETLIST_OBJECT::m_ConnectionType, NETLIST_OBJECT::m_Type, NOCONNECT, NOCONNECT_SYMBOL_PRESENT, PAD_CONNECT, PIN, PINLABEL, SEGMENT, SHEETBUSLABELMEMBER, SHEETLABEL, and UNCONNECTED.

Referenced by BuildNetListInfo().

◆ sheetLabelConnect()

void NETLIST_OBJECT_LIST::sheetLabelConnect ( NETLIST_OBJECT aSheetLabel)
private

Propagate net codes from a parent sheet to an include sheet, from a pin sheet connection.

Definition at line 497 of file netlist_object_list.cpp.

498 {
499  if( SheetLabel->GetNet() == 0 )
500  return;
501 
502  for( unsigned ii = 0; ii < size(); ii++ )
503  {
504  NETLIST_OBJECT* ObjetNet = GetItem( ii );
505 
506  if( ObjetNet->m_SheetPath != SheetLabel->m_SheetPathInclude )
507  continue; //use SheetInclude, not the sheet!!
508 
509  if( ( ObjetNet->m_Type != NETLIST_ITEM::HIERLABEL )
510  && ( ObjetNet->m_Type != NETLIST_ITEM::HIERBUSLABELMEMBER ) )
511  continue;
512 
513  if( ObjetNet->GetNet() == SheetLabel->GetNet() )
514  continue; //already connected.
515 
516  if( ObjetNet->m_Label != SheetLabel->m_Label )
517  continue; //different names.
518 
519  // Propagate Netcode having all the objects of the same Netcode.
520  if( ObjetNet->GetNet() )
521  propagateNetCode( ObjetNet->GetNet(), SheetLabel->GetNet(), IS_WIRE );
522  else
523  ObjetNet->SetNet( SheetLabel->GetNet() );
524  }
525 }
int GetNet() const
SCH_SHEET_PATH m_SheetPath
void propagateNetCode(int aOldNetCode, int aNewNetCode, bool aIsBus)
#define IS_WIRE
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
void SetNet(int aNetCode)
NETLIST_ITEM m_Type

References GetItem(), NETLIST_OBJECT::GetNet(), HIERBUSLABELMEMBER, HIERLABEL, IS_WIRE, NETLIST_OBJECT::m_Label, NETLIST_OBJECT::m_SheetPath, NETLIST_OBJECT::m_SheetPathInclude, NETLIST_OBJECT::m_Type, propagateNetCode(), and NETLIST_OBJECT::SetNet().

Referenced by BuildNetListInfo().

◆ sortItemsbyNetcode()

static bool NETLIST_OBJECT_LIST::sortItemsbyNetcode ( const NETLIST_OBJECT Objet1,
const NETLIST_OBJECT Objet2 
)
inlinestaticprivate

Definition at line 432 of file netlist_object.h.

433  {
434  return Objet1->GetNet() < Objet2->GetNet();
435  }
int GetNet() const

References NETLIST_OBJECT::GetNet().

Referenced by SortListbyNetcode().

◆ sortItemsBySheet()

static bool NETLIST_OBJECT_LIST::sortItemsBySheet ( const NETLIST_OBJECT Objet1,
const NETLIST_OBJECT Objet2 
)
inlinestaticprivate

Definition at line 439 of file netlist_object.h.

440  {
441  return Objet1->m_SheetPath.Cmp( Objet2->m_SheetPath ) < 0;
442  }
SCH_SHEET_PATH m_SheetPath
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Function Cmp Compare if this is the same sheet path as aSheetPathToTest.

References SCH_SHEET_PATH::Cmp(), and NETLIST_OBJECT::m_SheetPath.

Referenced by SortListbySheet().

◆ SortListbyNetcode()

void NETLIST_OBJECT_LIST::SortListbyNetcode ( )

Definition at line 60 of file netlist_object_list.cpp.

61 {
62  sort( this->begin(), this->end(), NETLIST_OBJECT_LIST::sortItemsbyNetcode );
63 }
static bool sortItemsbyNetcode(const NETLIST_OBJECT *Objet1, const NETLIST_OBJECT *Objet2)

References sortItemsbyNetcode().

Referenced by BuildNetListInfo().

◆ SortListbySheet()

void NETLIST_OBJECT_LIST::SortListbySheet ( )

Definition at line 66 of file netlist_object_list.cpp.

67 {
68  sort( this->begin(), this->end(), NETLIST_OBJECT_LIST::sortItemsBySheet );
69 }
static bool sortItemsBySheet(const NETLIST_OBJECT *Objet1, const NETLIST_OBJECT *Objet2)

References sortItemsBySheet().

Referenced by BuildNetListInfo().

◆ TestforSimilarLabels()

void NETLIST_OBJECT_LIST::TestforSimilarLabels ( )

Function TestforSimilarLabels detects labels which are different when using case sensitive comparisons but are equal when using case insensitive comparisons It can be due to a mistake from designer, so this kind of labels is reported by TestforSimilarLabels.

Definition at line 510 of file eeschema/erc.cpp.

511 {
512  // Similar labels which are different when using case sensitive comparisons
513  // but are equal when using case insensitive comparisons
514 
515  // list of all labels (used the better item to build diag messages)
516  std::vector<NETLIST_OBJECT*> fullLabelList;
517  // list of all labels , each label appears only once (used to to detect similar labels)
518  std::set<NETLIST_OBJECT*, compare_labels> uniqueLabelList;
519  wxString msg;
520 
521  // Build a list of differents labels. If inside a given sheet there are
522  // more than one given label, only one label is stored.
523  // not also the sheet labels are not taken in account for 2 reasons:
524  // * they are in the root sheet but they are seen only from the child sheet
525  // * any mismatch between child sheet hierarchical labels and the sheet label
526  // already detected by ERC
527  for( unsigned netItem = 0; netItem < size(); ++netItem )
528  {
529  switch( GetItemType( netItem ) )
530  {
531  case NETLIST_ITEM::LABEL:
538  // add this label in lists
539  uniqueLabelList.insert( GetItem( netItem ) );
540  fullLabelList.push_back( GetItem( netItem ) );
541  break;
542 
545  default:
546  break;
547  }
548  }
549 
550  // build global labels and compare
551  std::set<NETLIST_OBJECT*, compare_label_names> loc_labelList;
552 
553  for( auto it = uniqueLabelList.begin(); it != uniqueLabelList.end(); ++it )
554  {
555  if( (*it)->IsLabelGlobal() )
556  loc_labelList.insert( *it );
557  }
558 
559  // compare global labels (same label names appears only once in list)
560  for( auto it = loc_labelList.begin(); it != loc_labelList.end(); ++it )
561  {
562  auto it_aux = it;
563 
564  for( ++it_aux; it_aux != loc_labelList.end(); ++it_aux )
565  {
566  if( (*it)->m_Label.CmpNoCase( (*it_aux)->m_Label ) == 0 )
567  {
568  // Create new marker for ERC.
569  int cntA = countIndenticalLabels( fullLabelList, *it );
570  int cntB = countIndenticalLabels( fullLabelList, *it_aux );
571 
572  if( cntA <= cntB )
573  SimilarLabelsDiagnose( (*it), (*it_aux) );
574  else
575  SimilarLabelsDiagnose( (*it_aux), (*it) );
576  }
577  }
578  }
579 
580  // Build paths list
581  std::set<NETLIST_OBJECT*, compare_paths> pathsList;
582 
583  for( NETLIST_OBJECT* label : uniqueLabelList )
584  pathsList.insert( label );
585 
586  // Examine each label inside a sheet path:
587  for( NETLIST_OBJECT* candidate : pathsList )
588  {
589  loc_labelList.clear();
590 
591  for( NETLIST_OBJECT* uniqueLabel : uniqueLabelList)
592  {
593  if( candidate->m_SheetPath.Path() == uniqueLabel->m_SheetPath.Path() )
594  loc_labelList.insert( uniqueLabel );
595  }
596 
597  // at this point, loc_labelList contains labels of the current sheet path.
598  // Detect similar labels (same label names appears only once in list)
599 
600  for( auto ref_it = loc_labelList.begin(); ref_it != loc_labelList.end(); ++ref_it )
601  {
602  NETLIST_OBJECT* ref_item = *ref_it;
603  auto it_aux = ref_it;
604 
605  for( ++it_aux; it_aux != loc_labelList.end(); ++it_aux )
606  {
607  // global label versus global label was already examined.
608  // here, at least one label must be local
609  if( ref_item->IsLabelGlobal() && ( *it_aux )->IsLabelGlobal() )
610  continue;
611 
612  if( ref_item->m_Label.CmpNoCase( ( *it_aux )->m_Label ) == 0 )
613  {
614  // Create new marker for ERC.
615  int cntA = countIndenticalLabels( fullLabelList, ref_item );
616  int cntB = countIndenticalLabels( fullLabelList, *it_aux );
617 
618  if( cntA <= cntB )
619  SimilarLabelsDiagnose( ref_item, ( *it_aux ) );
620  else
621  SimilarLabelsDiagnose( ( *it_aux ), ref_item );
622  }
623  }
624  }
625  }
626 }
static int countIndenticalLabels(std::vector< NETLIST_OBJECT * > &aList, NETLIST_OBJECT *aRef)
bool IsLabelGlobal() const
Function IsLabelGlobal.
NETLIST_ITEM GetItemType(unsigned aIdx) const
Acces to an item type.
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
static void SimilarLabelsDiagnose(NETLIST_OBJECT *aItemA, NETLIST_OBJECT *aItemB)

References BUSLABELMEMBER, countIndenticalLabels(), GetItem(), GetItemType(), GLOBBUSLABELMEMBER, GLOBLABEL, HIERBUSLABELMEMBER, HIERLABEL, NETLIST_OBJECT::IsLabelGlobal(), LABEL, NETLIST_OBJECT::m_Label, PINLABEL, SHEETBUSLABELMEMBER, SHEETLABEL, and SimilarLabelsDiagnose().

Member Data Documentation

◆ m_lastBusNetCode

int NETLIST_OBJECT_LIST::m_lastBusNetCode
private

Definition at line 302 of file netlist_object.h.

Referenced by BuildNetListInfo(), and NETLIST_OBJECT_LIST().

◆ m_lastNetCode

int NETLIST_OBJECT_LIST::m_lastNetCode
private

Definition at line 301 of file netlist_object.h.

Referenced by BuildNetListInfo(), connectBusLabels(), and NETLIST_OBJECT_LIST().


The documentation for this class was generated from the following files: