KiCad PCB EDA Suite
erc.h File Reference

Go to the source code of this file.

Macros

#define NPI   4
 
#define DRV   3
 
#define NET_NC   2
 
#define NOD   1
 
#define NOC   0
 

Enumerations

enum  errortype { OK = 0, WAR, ERR, UNC }
 
enum  ERCE_T {
  ERCE_UNSPECIFIED = 0, ERCE_DUPLICATE_SHEET_NAME, ERCE_PIN_NOT_CONNECTED, ERCE_PIN_NOT_DRIVEN,
  ERCE_PIN_TO_PIN_WARNING, ERCE_PIN_TO_PIN_ERROR, ERCE_HIERACHICAL_LABEL, ERCE_NOCONNECT_CONNECTED,
  ERCE_NOCONNECT_NOT_CONNECTED, ERCE_LABEL_NOT_CONNECTED, ERCE_SIMILAR_LABELS, ERCE_SIMILAR_GLBL_LABELS,
  ERCE_DIFFERENT_UNIT_FP, ERCE_DIFFERENT_UNIT_NET, ERCE_BUS_ALIAS_CONFLICT, ERCE_DRIVER_CONFLICT,
  ERCE_BUS_ENTRY_CONFLICT, ERCE_BUS_LABEL_ERROR, ERCE_BUS_TO_BUS_CONFLICT, ERCE_BUS_TO_NET_CONFLICT,
  ERCE_GLOBLABEL
}
 DRC error codes: More...
 

Functions

bool WriteDiagnosticERC (EDA_UNITS_T aUnits, const wxString &aFullFileName)
 Function WriteDiagnosticERC save the ERC errors to aFullFileName. More...
 
void Diagnose (NETLIST_OBJECT *NetItemRef, NETLIST_OBJECT *NetItemTst, int MinConnexion, int Diag)
 Performs ERC testing and creates an ERC marker to show the ERC problem for aNetItemRef or between aNetItemRef and aNetItemTst. More...
 
void TestOthersItems (NETLIST_OBJECT_LIST *aList, unsigned aNetItemRef, unsigned aNetStart, int *aMinConnexion)
 Perform ERC testing for electrical conflicts between NetItemRef and other items (mainly pin) on the same net. More...
 
int TestDuplicateSheetNames (bool aCreateMarker)
 Function TestDuplicateSheetNames( ) inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated). More...
 
int TestConflictingBusAliases (bool aCreateMarker=true)
 Checks that there are not conflicting bus alias definitions in the schematic. More...
 
int TestMultiunitFootprints (SCH_SHEET_LIST &aSheetList)
 Test if all units of each multiunit component have the same footprint assigned. More...
 

Variables

const wxString CommentERC_H []
 
const wxString CommentERC_V []
 

Macro Definition Documentation

◆ DRV

#define DRV   3

Definition at line 79 of file erc.h.

◆ NET_NC

#define NET_NC   2

Definition at line 80 of file erc.h.

◆ NOC

#define NOC   0

Definition at line 82 of file erc.h.

◆ NOD

#define NOD   1

Definition at line 81 of file erc.h.

◆ NPI

#define NPI   4

Definition at line 78 of file erc.h.

Enumeration Type Documentation

◆ ERCE_T

enum ERCE_T

DRC error codes:

Enumerator
ERCE_UNSPECIFIED 
ERCE_DUPLICATE_SHEET_NAME 
ERCE_PIN_NOT_CONNECTED 
ERCE_PIN_NOT_DRIVEN 
ERCE_PIN_TO_PIN_WARNING 
ERCE_PIN_TO_PIN_ERROR 
ERCE_HIERACHICAL_LABEL 
ERCE_NOCONNECT_CONNECTED 
ERCE_NOCONNECT_NOT_CONNECTED 
ERCE_LABEL_NOT_CONNECTED 
ERCE_SIMILAR_LABELS 
ERCE_SIMILAR_GLBL_LABELS 
ERCE_DIFFERENT_UNIT_FP 
ERCE_DIFFERENT_UNIT_NET 
ERCE_BUS_ALIAS_CONFLICT 
ERCE_DRIVER_CONFLICT 
ERCE_BUS_ENTRY_CONFLICT 
ERCE_BUS_LABEL_ERROR 
ERCE_BUS_TO_BUS_CONFLICT 
ERCE_BUS_TO_NET_CONFLICT 
ERCE_GLOBLABEL 

Definition at line 52 of file erc.h.

53 {
54  ERCE_UNSPECIFIED = 0,
55  ERCE_DUPLICATE_SHEET_NAME, // duplicate sheet names within a given sheet
56  ERCE_PIN_NOT_CONNECTED, // pin not connected and not no connect symbol
57  ERCE_PIN_NOT_DRIVEN, // pin connected to some others pins but no pin to drive it
58  ERCE_PIN_TO_PIN_WARNING, // pin connected to an other pin: warning level
59  ERCE_PIN_TO_PIN_ERROR, // pin connected to an other pin: error level
60  ERCE_HIERACHICAL_LABEL, // mismatch between hierarchical labels and pins sheets
61  ERCE_NOCONNECT_CONNECTED, // a no connect symbol is connected to more than 1 pin
62  ERCE_NOCONNECT_NOT_CONNECTED, // a no connect symbol is not connected to anything
63  ERCE_LABEL_NOT_CONNECTED, // label not connected to anything
64  ERCE_SIMILAR_LABELS, // 2 labels are equal fir case insensitive comparisons
65  ERCE_SIMILAR_GLBL_LABELS, // 2 labels are equal fir case insensitive comparisons
66  ERCE_DIFFERENT_UNIT_FP, // different units of the same component have different footprints assigned
67  ERCE_DIFFERENT_UNIT_NET, // a shared pin in a multi-unit component is connected to more than one net
68  ERCE_BUS_ALIAS_CONFLICT, // conflicting bus alias definitions across sheets
69  ERCE_DRIVER_CONFLICT, // conflicting drivers (labels, etc) on a subgraph
70  ERCE_BUS_ENTRY_CONFLICT, // a wire connected to a bus doesn't match the bus
71  ERCE_BUS_LABEL_ERROR, // a label attached to a bus isn't in bus format
72  ERCE_BUS_TO_BUS_CONFLICT, // a connection between bus objects doesn't share at least one net
73  ERCE_BUS_TO_NET_CONFLICT, // a bus wire is graphically connected to a net port/pin (or vice versa)
74  ERCE_GLOBLABEL, // a global label is unique
75 };

◆ errortype

enum errortype
Enumerator
OK 
WAR 
ERR 
UNC 

Definition at line 40 of file erc.h.

41 {
42  OK = 0,
43  WAR, // Error: severity = warning
44  ERR, // Error: severity = error
45  UNC // Error: unconnected pin
46 };
Definition: erc.h:43
Definition: erc.h:42
Definition: erc.h:44
Definition: erc.h:45

Function Documentation

◆ Diagnose()

void Diagnose ( NETLIST_OBJECT NetItemRef,
NETLIST_OBJECT NetItemTst,
int  MinConnexion,
int  Diag 
)

Performs ERC testing and creates an ERC marker to show the ERC problem for aNetItemRef or between aNetItemRef and aNetItemTst.

if MinConn < 0: this is an error on labels

Definition at line 365 of file erc.cpp.

367 {
368  SCH_MARKER* marker = NULL;
369  SCH_SCREEN* screen;
370  ELECTRICAL_PINTYPE ii, jj;
371 
372  if( aDiag == OK || aMinConn < 1 )
373  return;
374 
375  /* Create new marker for ERC error. */
376  marker = new SCH_MARKER();
377  marker->SetTimeStamp( GetNewTimeStamp() );
378 
381  screen = aNetItemRef->m_SheetPath.LastScreen();
382  screen->Append( marker );
383 
384  wxString msg;
385 
386  ii = aNetItemRef->m_ElectricalPinType;
387 
388  wxString cmp_ref( "?" );
389 
390  if( aNetItemRef->m_Type == NET_PIN && aNetItemRef->m_Link )
391  cmp_ref = aNetItemRef->GetComponentParent()->GetRef( &aNetItemRef->m_SheetPath );
392 
393  if( aNetItemTst == NULL )
394  {
395  if( aMinConn == NOD ) /* Nothing driving the net. */
396  {
397  if( aNetItemRef->m_Type == NET_PIN && aNetItemRef->m_Link )
398  cmp_ref = aNetItemRef->GetComponentParent()->GetRef(
399  &aNetItemRef->m_SheetPath );
400 
401  msg.Printf( _( "Pin %s (%s) of component %s is not driven (Net %d)." ),
402  aNetItemRef->m_PinNum,
403  GetChars( GetText( ii ) ),
404  GetChars( cmp_ref ),
405  aNetItemRef->GetNet() );
406  marker->SetData( ERCE_PIN_NOT_DRIVEN,
407  aNetItemRef->m_Start,
408  msg,
409  aNetItemRef->m_Start );
410  return;
411  }
412  }
413 
414  if( aNetItemTst ) /* Error between 2 pins */
415  {
416  jj = aNetItemTst->m_ElectricalPinType;
418 
419  if( aDiag == ERR )
420  {
423  }
424 
425  wxString alt_cmp( "?" );
426 
427  if( aNetItemTst->m_Type == NET_PIN && aNetItemTst->m_Link )
428  alt_cmp = aNetItemTst->GetComponentParent()->GetRef( &aNetItemTst->m_SheetPath );
429 
430  msg.Printf( _( "Pin %s (%s) of component %s is connected to " ),
431  aNetItemRef->m_PinNum,
432  GetChars( GetText( ii ) ),
433  GetChars( cmp_ref ) );
434  marker->SetData( errortype, aNetItemRef->m_Start, msg, aNetItemRef->m_Start );
435  msg.Printf( _( "pin %s (%s) of component %s (net %d)." ),
436  aNetItemTst->m_PinNum,
437  GetChars( GetText( jj ) ),
438  GetChars( alt_cmp ),
439  aNetItemRef->GetNet() );
440  marker->SetAuxiliaryData( msg, aNetItemTst->m_Start );
441  }
442 }
void SetData(EDA_UNITS_T aUnits, int aErrorCode, const wxPoint &aMarkerPos, EDA_ITEM *aItem, const wxPoint &aPos, EDA_ITEM *bItem=nullptr, const wxPoint &bPos=wxPoint())
Function SetData fills in all the reportable data associated with a MARKER.
Definition: erc.h:42
timestamp_t GetNewTimeStamp()
Definition: common.cpp:217
Definition: erc.h:44
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
void SetMarkerType(enum TYPEMARKER aMarkerType)
accessors to set/get marker type (DRC, ERC, or other)
Definition: marker_base.h:182
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:100
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:155
void SetErrorLevel(MARKER_SEVERITY aErrorLevel)
accessors to set/get error levels (warning, error, fatal error..)
Definition: marker_base.h:170
errortype
Definition: erc.h:40
void SetAuxiliaryData(const wxString &aAuxiliaryText, const wxPoint &aAuxiliaryPos)
Function SetAuxiliaryData initialize data for the second (auxiliary) item.
Definition: marker_base.h:227
#define NOD
Definition: erc.h:81
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:209

References SCH_SCREEN::Append(), ERCE_PIN_NOT_DRIVEN, ERCE_PIN_TO_PIN_ERROR, ERCE_PIN_TO_PIN_WARNING, ERR, GetChars(), NETLIST_OBJECT::GetComponentParent(), NETLIST_OBJECT::GetNet(), GetNewTimeStamp(), SCH_COMPONENT::GetRef(), GetText(), SCH_SHEET_PATH::LastScreen(), NETLIST_OBJECT::m_ElectricalPinType, NETLIST_OBJECT::m_Link, NETLIST_OBJECT::m_PinNum, NETLIST_OBJECT::m_SheetPath, NETLIST_OBJECT::m_Start, NETLIST_OBJECT::m_Type, MARKER_BASE::MARKER_ERC, MARKER_BASE::MARKER_SEVERITY_ERROR, MARKER_BASE::MARKER_SEVERITY_WARNING, NET_PIN, NOD, OK, MARKER_BASE::SetAuxiliaryData(), MARKER_BASE::SetData(), MARKER_BASE::SetErrorLevel(), MARKER_BASE::SetMarkerType(), and EDA_ITEM::SetTimeStamp().

Referenced by NETLIST_OBJECT_LIST::TestforNonOrphanLabel(), and TestOthersItems().

◆ TestConflictingBusAliases()

int TestConflictingBusAliases ( bool  aCreateMarker = true)

Checks that there are not conflicting bus alias definitions in the schematic.

(for example, two hierarchical sub-sheets contain different definitions for the same bus alias)

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

Definition at line 228 of file erc.cpp.

229 {
230  using std::pair;
231  using std::shared_ptr;
232  using std::vector;
233 
234  int err_count = 0;
235  SCH_SCREENS screens;
236  vector< shared_ptr<BUS_ALIAS> > aliases;
237  vector< pair< shared_ptr<BUS_ALIAS>, shared_ptr<BUS_ALIAS> > > conflicts;
238 
239  for( auto screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
240  {
241  auto screen_aliases = screen->GetBusAliases();
242 
243  for( auto alias : screen_aliases )
244  {
245  for( auto test : aliases )
246  {
247  if( alias->GetName() == test->GetName() &&
248  alias->Members() != test->Members() )
249  {
250  conflicts.push_back( std::make_pair( alias, test ) );
251  }
252  }
253  }
254 
255  aliases.insert( aliases.end(),
256  screen_aliases.begin(), screen_aliases.end() );
257  }
258 
259  if( !conflicts.empty() )
260  {
261  if( aCreateMarker )
262  {
263  wxString msg;
264 
265  for( auto conflict : conflicts )
266  {
267  auto marker = new SCH_MARKER();
268  auto a1 = conflict.first;
269  auto a2 = conflict.second;
270 
271  msg.Printf( _( "Bus alias %s has conflicting definitions on multiple sheets: " ),
272  GetChars( a1->GetName() ) );
273 
274  wxFileName f1 = a1->GetParent()->GetFileName();
275  wxFileName f2 = a2->GetParent()->GetFileName();
276 
277  msg << f1.GetFullName() << " and " << f2.GetFullName();
278 
279  marker->SetData( ERCE_BUS_ALIAS_CONFLICT, wxPoint( 0, 0 ),
280  msg, wxPoint( 0, 0 ) );
281  marker->SetMarkerType( MARKER_BASE::MARKER_ERC );
282  marker->SetErrorLevel( MARKER_BASE::MARKER_SEVERITY_ERROR );
283 
284  a2->GetParent()->Append( marker );
285 
286  ++err_count;
287  }
288  }
289  }
290 
291  return err_count;
292 }
SCH_SCREEN * GetNext()
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:100
SCH_SCREEN * GetFirst()
Definition: sch_screen.cpp:996
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:493

References ERCE_BUS_ALIAS_CONFLICT, GetChars(), SCH_SCREENS::GetFirst(), SCH_SCREENS::GetNext(), MARKER_BASE::MARKER_ERC, and MARKER_BASE::MARKER_SEVERITY_ERROR.

Referenced by DIALOG_ERC::TestErc().

◆ TestDuplicateSheetNames()

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.

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 }
SCH_SCREEN * GetNext()
SCH_ITEM * Next() const
Definition: sch_item.h:153
void SetData(EDA_UNITS_T aUnits, int aErrorCode, const wxPoint &aMarkerPos, EDA_ITEM *aItem, const wxPoint &aPos, EDA_ITEM *bItem=nullptr, const wxPoint &bPos=wxPoint())
Function SetData fills in all the reportable data associated with a MARKER.
timestamp_t GetNewTimeStamp()
Definition: common.cpp:217
void SetMarkerType(enum TYPEMARKER aMarkerType)
accessors to set/get marker type (DRC, ERC, or other)
Definition: marker_base.h:182
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:201
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:155
void SetErrorLevel(MARKER_SEVERITY aErrorLevel)
accessors to set/get error levels (warning, error, fatal error..)
Definition: marker_base.h:170
SCH_SCREEN * GetFirst()
Definition: sch_screen.cpp:996
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:493
KICAD_T Type() const
Function Type()
Definition: base_struct.h:204
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:209
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:153

◆ TestMultiunitFootprints()

int TestMultiunitFootprints ( SCH_SHEET_LIST aSheetList)

Test if all units of each multiunit component have the same footprint assigned.

Parameters
aSheetListcontains components to be validated.
Returns
The error count.

Definition at line 295 of file erc.cpp.

296 {
297  int errors = 0;
298  std::map<wxString, LIB_ID> footprints;
300  aSheetList.GetMultiUnitComponents( refMap, true );
301 
302  for( auto& component : refMap )
303  {
304  auto& refList = component.second;
305 
306  if( refList.GetCount() == 0 )
307  {
308  wxFAIL; // it should not happen
309  continue;
310  }
311 
312  // Reference footprint
313  wxString fp;
314  wxString unitName;
315 
316  for( unsigned i = 0; i < component.second.GetCount(); ++i )
317  {
318  SCH_COMPONENT* cmp = refList.GetItem( i ).GetComp();
319  SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
320  fp = cmp->GetField( FOOTPRINT )->GetText();
321 
322  if( !fp.IsEmpty() )
323  {
324  unitName = cmp->GetRef( &sheetPath )
325  + LIB_PART::SubReference( cmp->GetUnit(), false );
326  break;
327  }
328  }
329 
330  for( unsigned i = 0; i < component.second.GetCount(); ++i )
331  {
332  SCH_REFERENCE& ref = refList.GetItem( i );
333  SCH_COMPONENT* unit = ref.GetComp();
334  SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
335  const wxString curFp = unit->GetField( FOOTPRINT )->GetText();
336 
337  if( !curFp.IsEmpty() && fp != curFp )
338  {
339  wxString curUnitName = unit->GetRef( &sheetPath )
340  + LIB_PART::SubReference( unit->GetUnit(), false );
341  wxString msg = wxString::Format( _( "Unit %s has '%s' assigned, "
342  "whereas unit %s has '%s' assigned" ),
343  unitName,
344  fp,
345  curUnitName,
346  curFp );
347  wxPoint pos = unit->GetPosition();
348 
349  SCH_MARKER* marker = new SCH_MARKER();
350  marker->SetTimeStamp( GetNewTimeStamp() );
351  marker->SetData( ERCE_DIFFERENT_UNIT_FP, pos, msg, pos );
354  ref.GetSheetPath().LastScreen()->Append( marker );
355 
356  ++errors;
357  }
358  }
359  }
360 
361  return errors;
362 }
const SCH_SHEET_PATH & GetSheetPath() const
const wxString GetText() const override
Function GetText returns the string associated with the text object.
Definition: sch_field.cpp:105
SCH_COMPONENT * GetComp() const
void SetData(EDA_UNITS_T aUnits, int aErrorCode, const wxPoint &aMarkerPos, EDA_ITEM *aItem, const wxPoint &aPos, EDA_ITEM *bItem=nullptr, const wxPoint &bPos=wxPoint())
Function SetData fills in all the reportable data associated with a MARKER.
Field Name Module PCB, i.e. "16DIP300".
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
timestamp_t GetNewTimeStamp()
Definition: common.cpp:217
int GetUnit() const
Class SCH_SHEET_PATH.
void SetMarkerType(enum TYPEMARKER aMarkerType)
accessors to set/get marker type (DRC, ERC, or other)
Definition: marker_base.h:182
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Type SCH_MULTI_UNIT_REFERENCE_MAP is used to create a map of reference designators for multi-unit par...
void GetMultiUnitComponents(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true)
Function GetMultiUnitComponents adds a SCH_REFERENCE_LIST object to aRefList for each same-reference ...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:155
void SetErrorLevel(MARKER_SEVERITY aErrorLevel)
accessors to set/get error levels (warning, error, fatal error..)
Definition: marker_base.h:170
size_t i
Definition: json11.cpp:597
static wxString SubReference(int aUnit, bool aAddSeparator=true)
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
wxPoint GetPosition() const override
Function GetPosition.
Class SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic.
SCH_SCREEN * LastScreen() const
Function LastScreen.
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:209

References SCH_SCREEN::Append(), ERCE_DIFFERENT_UNIT_FP, FOOTPRINT, Format(), SCH_REFERENCE::GetComp(), SCH_COMPONENT::GetField(), SCH_SHEET_LIST::GetMultiUnitComponents(), GetNewTimeStamp(), SCH_COMPONENT::GetPosition(), SCH_COMPONENT::GetRef(), SCH_REFERENCE::GetSheetPath(), SCH_FIELD::GetText(), SCH_COMPONENT::GetUnit(), i, SCH_SHEET_PATH::LastScreen(), MARKER_BASE::MARKER_ERC, MARKER_BASE::MARKER_SEVERITY_WARNING, MARKER_BASE::SetData(), MARKER_BASE::SetErrorLevel(), MARKER_BASE::SetMarkerType(), EDA_ITEM::SetTimeStamp(), and LIB_PART::SubReference().

Referenced by DIALOG_ERC::TestErc().

◆ TestOthersItems()

void TestOthersItems ( NETLIST_OBJECT_LIST aList,
unsigned  aNetItemRef,
unsigned  aNetStart,
int *  aMinConnexion 
)

Perform ERC testing for electrical conflicts between NetItemRef and other items (mainly pin) on the same net.

Parameters
aList= a reference to the list of connected objects
aNetItemRef= index in list of the current object
aNetStart= index in list of net objects of the first item
aMinConnexion= a pointer to a variable to store the minimal connection found( NOD, DRV, NPI, NET_NC)

Definition at line 445 of file erc.cpp.

448 {
449  unsigned netItemTst = aNetStart;
451  int erc = OK;
452 
453  /* Analysis of the table of connections. */
454  ELECTRICAL_PINTYPE ref_elect_type = aList->GetItem( aNetItemRef )->m_ElectricalPinType;
455  int local_minconn = NOC;
456 
457  if( ref_elect_type == PIN_NC )
458  local_minconn = NPI;
459 
460  /* Test pins connected to NetItemRef */
461  for( ; ; netItemTst++ )
462  {
463  if( aNetItemRef == netItemTst )
464  continue;
465 
466  // We examine only a given net. We stop the search if the net changes
467  if( ( netItemTst >= aList->size() ) // End of list
468  || ( aList->GetItemNet( aNetItemRef ) !=
469  aList->GetItemNet( netItemTst ) ) ) // End of net
470  {
471  /* End net code found: minimum connection test. */
472  if( ( *aMinConnexion < NET_NC ) && ( local_minconn < NET_NC ) )
473  {
474  /* Not connected or not driven pin. */
475  bool seterr = true;
476 
477  if( local_minconn == NOC &&
478  aList->GetItemType( aNetItemRef ) == NET_PIN )
479  {
480  /* This pin is not connected: for multiple part per
481  * package, and duplicated pin,
482  * search for another instance of this pin
483  * this will be flagged only if all instances of this pin
484  * are not connected
485  * TODO test also if instances connected are connected to
486  * the same net
487  */
488  for( unsigned duplicate = 0; duplicate < aList->size(); duplicate++ )
489  {
490  if( aList->GetItemType( duplicate ) != NET_PIN )
491  continue;
492 
493  if( duplicate == aNetItemRef )
494  continue;
495 
496  if( aList->GetItem( aNetItemRef )->m_PinNum !=
497  aList->GetItem( duplicate )->m_PinNum )
498  continue;
499 
500  if( ( (SCH_COMPONENT*) aList->GetItem( aNetItemRef )->
501  m_Link )->GetRef( &aList->GetItem( aNetItemRef )-> m_SheetPath ) !=
502  ( (SCH_COMPONENT*) aList->GetItem( duplicate )->m_Link )
503  ->GetRef( &aList->GetItem( duplicate )->m_SheetPath ) )
504  continue;
505 
506  // Same component and same pin. Do dot create error for this pin
507  // if the other pin is connected (i.e. if duplicate net has another
508  // item)
509  if( (duplicate > 0)
510  && ( aList->GetItemNet( duplicate ) ==
511  aList->GetItemNet( duplicate - 1 ) ) )
512  seterr = false;
513 
514  if( (duplicate < aList->size() - 1)
515  && ( aList->GetItemNet( duplicate ) ==
516  aList->GetItemNet( duplicate + 1 ) ) )
517  seterr = false;
518  }
519  }
520 
521  if( seterr )
522  Diagnose( aList->GetItem( aNetItemRef ), NULL, local_minconn, WAR );
523 
524  *aMinConnexion = DRV; // inhibiting other messages of this
525  // type for the net.
526  }
527  return;
528  }
529 
530  switch( aList->GetItemType( netItemTst ) )
531  {
533  case NET_SEGMENT:
534  case NET_BUS:
535  case NET_JUNCTION:
536  case NET_LABEL:
537  case NET_HIERLABEL:
538  case NET_BUSLABELMEMBER:
541  case NET_SHEETLABEL:
542  case NET_GLOBLABEL:
544  case NET_PINLABEL:
545  break;
546 
547  case NET_NOCONNECT:
548  local_minconn = std::max( NET_NC, local_minconn );
549  break;
550 
551  case NET_PIN:
552  jj = aList->GetItem( netItemTst )->m_ElectricalPinType;
553  local_minconn = std::max( MinimalReq[ref_elect_type][jj], local_minconn );
554 
555  if( netItemTst <= aNetItemRef )
556  break;
557 
558  if( erc == OK )
559  {
560  erc = DiagErc[ref_elect_type][jj];
561 
562  if( erc != OK )
563  {
564  if( aList->GetConnectionType( netItemTst ) == UNCONNECTED )
565  {
566  Diagnose( aList->GetItem( aNetItemRef ),
567  aList->GetItem( netItemTst ),
568  0, erc );
569  aList->SetConnectionType( netItemTst, NOCONNECT_SYMBOL_PRESENT );
570  }
571  }
572  }
573 
574  break;
575  }
576  }
577 }
Definition: erc.h:43
int DiagErc[PINTYPE_COUNT][PINTYPE_COUNT]
Definition: erc.cpp:124
void Diagnose(NETLIST_OBJECT *aNetItemRef, NETLIST_OBJECT *aNetItemTst, int aMinConn, int aDiag)
Performs ERC testing and creates an ERC marker to show the ERC problem for aNetItemRef or between aNe...
Definition: erc.cpp:365
SCH_SHEET_PATH m_SheetPath
ELECTRICAL_PINTYPE m_ElectricalPinType
int GetItemNet(unsigned aIdx) const
Acces to an item net code.
void SetConnectionType(unsigned aIdx, NET_CONNECTION_T aFlg=UNCONNECTED)
Set the item connection type: UNCONNECTED Pin or Label not connected (error) NOCONNECT_SYMBOL_PRESENT...
#define DRV
Definition: erc.h:79
Definition: erc.h:42
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
#define NOC
Definition: erc.h:82
NET_CONNECTION_T GetConnectionType(unsigned aIdx)
static int MinimalReq[PINTYPE_COUNT][PINTYPE_COUNT]
Look up table which gives the minimal drive for a pair of connected pins on a net.
Definition: erc.cpp:160
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
#define max(a, b)
Definition: auxiliary.h:86
#define NPI
Definition: erc.h:78
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
#define NET_NC
Definition: erc.h:80
SCH_ITEM * m_Link
NETLIST_ITEM_T GetItemType(unsigned aIdx) const
Acces to an item type.

References DiagErc, Diagnose(), DRV, NETLIST_OBJECT_LIST::GetConnectionType(), NETLIST_OBJECT_LIST::GetItem(), NETLIST_OBJECT_LIST::GetItemNet(), NETLIST_OBJECT_LIST::GetItemType(), NETLIST_OBJECT::m_ElectricalPinType, NETLIST_OBJECT::m_Link, NETLIST_OBJECT::m_PinNum, NETLIST_OBJECT::m_SheetPath, max, MinimalReq, NET_BUS, NET_BUSLABELMEMBER, NET_GLOBBUSLABELMEMBER, NET_GLOBLABEL, NET_HIERBUSLABELMEMBER, NET_HIERLABEL, NET_ITEM_UNSPECIFIED, NET_JUNCTION, NET_LABEL, NET_NC, NET_NOCONNECT, NET_PIN, NET_PINLABEL, NET_SEGMENT, NET_SHEETBUSLABELMEMBER, NET_SHEETLABEL, NOC, NOCONNECT_SYMBOL_PRESENT, NPI, OK, PIN_NC, NETLIST_OBJECT_LIST::SetConnectionType(), UNCONNECTED, and WAR.

Referenced by DIALOG_ERC::TestErc().

◆ WriteDiagnosticERC()

bool WriteDiagnosticERC ( EDA_UNITS_T  aUnits,
const wxString &  aFullFileName 
)

Function WriteDiagnosticERC save the ERC errors to aFullFileName.

Parameters
aFullFileNameA wxString object containing the file name and path.

Definition at line 598 of file erc.cpp.

599 {
600  wxString msg;
601 
602  wxFFile file( aFullFileName, wxT( "wt" ) );
603 
604  if( !file.IsOpened() )
605  return false;
606 
607  msg = _( "ERC report" );
608  msg << wxT(" (") << DateAndTime() << wxT( ", " )
609  << _( "Encoding UTF8" ) << wxT( " )\n" );
610 
611  int err_count = 0;
612  int warn_count = 0;
613  int total_count = 0;
614  SCH_SHEET_LIST sheetList( g_RootSheet );
615 
616  for( unsigned i = 0; i < sheetList.size(); i++ )
617  {
618  msg << wxString::Format( _( "\n***** Sheet %s\n" ),
619  GetChars( sheetList[i].PathHumanReadable() ) );
620 
621  for( SCH_ITEM* item = sheetList[i].LastDrawList(); item != NULL; item = item->Next() )
622  {
623  if( item->Type() != SCH_MARKER_T )
624  continue;
625 
626  SCH_MARKER* marker = (SCH_MARKER*) item;
627 
628  if( marker->GetMarkerType() != MARKER_BASE::MARKER_ERC )
629  continue;
630 
631  total_count++;
632 
634  err_count++;
635 
637  warn_count++;
638 
639  msg << marker->GetReporter().ShowReport( aUnits );
640  }
641  }
642 
643  msg << wxString::Format( _( "\n ** ERC messages: %d Errors %d Warnings %d\n" ),
644  total_count, err_count, warn_count );
645 
646  // Currently: write report using UTF8 (as usual in Kicad).
647  // TODO: see if we can use the current encoding page (mainly for Windows users),
648  // Or other format (HTML?)
649  file.Write( msg );
650 
651  // wxFFile dtor will close the file.
652 
653  return true;
654 }
Class SCH_SHEET_LIST.
const DRC_ITEM & GetReporter() const
Function GetReporter returns the DRC_ITEM held within this MARKER so that its interface may be used.
Definition: marker_base.h:243
SCH_ITEM * Next() const
Definition: sch_item.h:153
MARKER_SEVERITY GetErrorLevel() const
Definition: marker_base.h:175
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:56
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:100
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
enum TYPEMARKER GetMarkerType() const
Definition: marker_base.h:187
size_t i
Definition: json11.cpp:597
wxString ShowReport(EDA_UNITS_T aUnits) const
Function ShowReport translates this object into a text string suitable for saving to disk in a report...
Definition: drc_item.cpp:227
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
wxString DateAndTime()
Definition: string.cpp:333

References DateAndTime(), Format(), g_RootSheet, GetChars(), MARKER_BASE::GetErrorLevel(), MARKER_BASE::GetMarkerType(), MARKER_BASE::GetReporter(), i, MARKER_BASE::MARKER_ERC, MARKER_BASE::MARKER_SEVERITY_ERROR, MARKER_BASE::MARKER_SEVERITY_WARNING, SCH_MARKER_T, and DRC_ITEM::ShowReport().

Referenced by DIALOG_ERC::TestErc().

Variable Documentation

◆ CommentERC_H

const wxString CommentERC_H[]

Definition at line 87 of file erc.cpp.

Referenced by DIALOG_ERC::ReBuildMatrixPanel().

◆ CommentERC_V

const wxString CommentERC_V[]

Definition at line 103 of file erc.cpp.

Referenced by DIALOG_ERC::ReBuildMatrixPanel().