KiCad PCB EDA Suite
eeschema/netlist.cpp File Reference
#include <fctsys.h>
#include <schframe.h>
#include <confirm.h>
#include <netlist_exporter_kicad.h>
#include <kiway.h>
#include <netlist.h>
#include <class_netlist_object.h>
#include <class_library.h>
#include <lib_pin.h>
#include <sch_junction.h>
#include <sch_component.h>
#include <sch_line.h>
#include <sch_no_connect.h>
#include <sch_text.h>
#include <sch_sheet.h>
#include <algorithm>
#include <invoke_sch_dialog.h>

Go to the source code of this file.

Macros

#define IS_WIRE   false
 
#define IS_BUS   true
 

Functions

int TestDuplicateSheetNames (bool aCreateMarker)
 Function TestDuplicateSheetNames( ) inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated). More...
 
static int getPriority (const NETLIST_OBJECT *Objet)
 
static bool evalLabelsPriority (const NETLIST_OBJECT *aLabel1, const NETLIST_OBJECT *aLabel2)
 

Macro Definition Documentation

#define IS_BUS   true

Function Documentation

static bool evalLabelsPriority ( const NETLIST_OBJECT aLabel1,
const NETLIST_OBJECT aLabel2 
)
static

Definition at line 414 of file eeschema/netlist.cpp.

References getPriority(), NETLIST_OBJECT::IsLabelGlobal(), NETLIST_OBJECT::m_Label, NETLIST_OBJECT::m_SheetPath, SCH_SHEET_PATH::Path(), and SCH_SHEET_PATH::PathHumanReadable().

Referenced by NETLIST_OBJECT_LIST::findBestNetNameForEachNet().

415 {
416  // Global labels have the highest prioriy.
417  // For local labels: names are prefixed by their sheetpath
418  // use name defined in the more top level hierarchical sheet
419  // (i.e. shorter timestamp path because paths are /<timestamp1>/<timestamp2>/...
420  // and timestamp = 8 letters.
421  // Note: the final net name uses human sheetpath name, not timestamp sheetpath name
422  // They are equivalent, but not for human readers.
423  if( ! aLabel1->IsLabelGlobal() && ! aLabel2->IsLabelGlobal() )
424  {
425  if( aLabel1->m_SheetPath.Path().Length() != aLabel2->m_SheetPath.Path().Length() )
426  return aLabel1->m_SheetPath.Path().Length() < aLabel2->m_SheetPath.Path().Length();
427  }
428 
429  int priority1 = getPriority( aLabel1 );
430  int priority2 = getPriority( aLabel2 );
431 
432  if( priority1 != priority2 )
433  return priority1 > priority2;
434 
435  // Objects have here the same priority, therefore they have the same type.
436  // for global labels, we select the best candidate by alphabetic order
437  // because they have no sheetpath as prefix name
438  // for other labels, we select them before by sheet deep order
439  // because the actual name is /sheetpath/label
440  // and for a given path length, by alphabetic order
441  if( aLabel1->IsLabelGlobal() )
442  return aLabel1->m_Label.Cmp( aLabel2->m_Label ) < 0;
443 
444  // Sheet paths have here the same length: use alphabetic label name order
445  // For labels on sheets having an equivalent deep in hierarchy, use
446  // alphabetic label name order:
447  if( aLabel1->m_Label.Cmp( aLabel2->m_Label ) != 0 )
448  return aLabel1->m_Label.Cmp( aLabel2->m_Label ) < 0;
449 
450  // For identical labels having the same priority: choose the
451  // alphabetic label full name order
452  return aLabel1->m_SheetPath.PathHumanReadable().Cmp(
453  aLabel2->m_SheetPath.PathHumanReadable() ) < 0;
454 }
bool IsLabelGlobal() const
Function IsLabelGlobal.
SCH_SHEET_PATH m_SheetPath
wxString Path() const
Function Path the path uses the time stamps which do not changes even when editing sheet parameters a...
wxString PathHumanReadable() const
Function PathHumanReadable returns the sheet path in a human readable form, i.e.
static int getPriority(const NETLIST_OBJECT *Objet)
static int getPriority ( const NETLIST_OBJECT Objet)
static

Definition at line 393 of file eeschema/netlist.cpp.

References NETLIST_OBJECT::m_Type, NET_GLOBBUSLABELMEMBER, NET_GLOBLABEL, NET_HIERLABEL, NET_LABEL, NET_PIN, and NET_PINLABEL.

Referenced by evalLabelsPriority().

394 {
395  switch( Objet->m_Type )
396  {
397  case NET_PIN: return 1;
398  case NET_LABEL: return 2;
399  case NET_HIERLABEL: return 3;
400  case NET_PINLABEL: return 4;
401  case NET_GLOBBUSLABELMEMBER: return 5;
402  case NET_GLOBLABEL: return 6;
403  default: break;
404  }
405 
406  return 0;
407 }
NETLIST_ITEM_T m_Type
int TestDuplicateSheetNames ( bool  aCreateMarker)

Function TestDuplicateSheetNames( ) inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated).

Returns
the error count
Parameters
aCreateMarkertrue = create error markers in schematic, false = calculate error count only

Definition at line 177 of file erc.cpp.

References SCH_SCREEN::Append(), ERCE_DUPLICATE_SHEET_NAME, SCH_SCREEN::GetDrawItems(), SCH_SCREENS::GetFirst(), GetNewTimeStamp(), SCH_SCREENS::GetNext(), MARKER_BASE::MARKER_ERC, MARKER_BASE::MARKER_SEVERITY_ERROR, SCH_ITEM::Next(), SCH_SHEET_T, MARKER_BASE::SetData(), MARKER_BASE::SetErrorLevel(), MARKER_BASE::SetMarkerType(), EDA_ITEM::SetTimeStamp(), and EDA_ITEM::Type().

Referenced by SCH_EDIT_FRAME::HighlightConnectionAtPosition(), SCH_EDIT_FRAME::prepareForNetlist(), SCH_EDIT_FRAME::SetCurrentSheetHighlightFlags(), and DIALOG_ERC::TestErc().

178 {
179  SCH_SCREEN* screen;
180  SCH_ITEM* item;
181  SCH_ITEM* test_item;
182  int err_count = 0;
183  SCH_SCREENS screenList; // Created the list of screen
184 
185  for( screen = screenList.GetFirst(); screen != NULL; screen = screenList.GetNext() )
186  {
187  for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
188  {
189  // search for a sheet;
190  if( item->Type() != SCH_SHEET_T )
191  continue;
192 
193  for( test_item = item->Next(); test_item != NULL; test_item = test_item->Next() )
194  {
195  if( test_item->Type() != SCH_SHEET_T )
196  continue;
197 
198  // We have found a second sheet: compare names
199  // we are using case insensitive comparison to avoid mistakes between
200  // similar names like Mysheet and mysheet
201  if( ( (SCH_SHEET*) item )->GetName().CmpNoCase(
202  ( ( SCH_SHEET* ) test_item )->GetName() ) == 0 )
203  {
204  if( aCreateMarker )
205  {
206  /* Create a new marker type ERC error*/
207  SCH_MARKER* marker = new SCH_MARKER();
208  marker->SetTimeStamp( GetNewTimeStamp() );
210  ( (SCH_SHEET*) test_item )->GetPosition(),
211  _( "Duplicate sheet name" ),
212  ( (SCH_SHEET*) test_item )->GetPosition() );
215  screen->Append( marker );
216  }
217 
218  err_count++;
219  }
220  }
221  }
222  }
223 
224  return err_count;
225 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
SCH_SCREEN * GetNext()
time_t GetNewTimeStamp()
Definition: common.cpp:266
SCH_ITEM * Next() const
void SetData(int aErrorCode, const wxPoint &aMarkerPos, const wxString &aText, const wxPoint &aPos, const wxString &bText, const wxPoint &bPos)
Function SetData fills in all the reportable data associated with a MARKER.
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
#define ERCE_DUPLICATE_SHEET_NAME
Definition: erc.h:53
void SetMarkerType(enum TYPEMARKER aMarkerType)
accessors to set/get marker type (DRC, ERC, or other)
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
SCH_ITEM * GetDrawItems() const
Function GetDrawItems().
void Append(SCH_ITEM *aItem)
void SetErrorLevel(MARKER_SEVERITY aErrorLevel)
accessors to set/get error levels (warning, error, fatal error..)
SCH_SCREEN * GetFirst()
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Class SCH_SCREENS is a container class that holds multiple SCH_SCREENs in a hierarchy.