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 341 of file erc.cpp.

342 {
343  SCH_MARKER* marker = NULL;
344  SCH_SCREEN* screen;
345  ELECTRICAL_PINTYPE ii, jj;
346 
347  if( aDiag == OK || aMinConn < 1 )
348  return;
349 
350  /* Create new marker for ERC error. */
351  marker = new SCH_MARKER();
352  marker->SetTimeStamp( GetNewTimeStamp() );
353 
356  screen = aNetItemRef->m_SheetPath.LastScreen();
357  screen->Append( marker );
358 
359  wxString msg;
360 
361  ii = aNetItemRef->m_ElectricalPinType;
362 
363  wxString cmp_ref( "?" );
364 
365  if( aNetItemRef->m_Type == NET_PIN && aNetItemRef->m_Link )
366  cmp_ref = aNetItemRef->GetComponentParent()->GetRef( &aNetItemRef->m_SheetPath );
367 
368  if( aNetItemTst == NULL )
369  {
370  if( aMinConn == NOD ) /* Nothing driving the net. */
371  {
372  if( aNetItemRef->m_Type == NET_PIN && aNetItemRef->m_Link )
373  cmp_ref = aNetItemRef->GetComponentParent()->GetRef(
374  &aNetItemRef->m_SheetPath );
375 
376  msg.Printf( _( "Pin %s (%s) of component %s is not driven (Net %d)." ),
377  aNetItemRef->m_PinNum,
378  GetChars( GetText( ii ) ),
379  GetChars( cmp_ref ),
380  aNetItemRef->GetNet() );
381  marker->SetData( ERCE_PIN_NOT_DRIVEN, aNetItemRef->m_Start, msg, aNetItemRef->m_Start );
382  return;
383  }
384  }
385 
386  if( aNetItemTst ) /* Error between 2 pins */
387  {
388  jj = aNetItemTst->m_ElectricalPinType;
390 
391  if( aDiag == ERR )
392  {
395  }
396 
397  wxString alt_cmp( "?" );
398 
399  if( aNetItemTst->m_Type == NET_PIN && aNetItemTst->m_Link )
400  alt_cmp = aNetItemTst->GetComponentParent()->GetRef( &aNetItemTst->m_SheetPath );
401 
402  msg.Printf( _( "Pin %s (%s) of component %s is connected to " ),
403  aNetItemRef->m_PinNum,
404  GetChars( GetText( ii ) ),
405  GetChars( cmp_ref ) );
406  marker->SetData( errortype, aNetItemRef->m_Start, msg, aNetItemRef->m_Start );
407  msg.Printf( _( "pin %s (%s) of component %s (net %d)." ),
408  aNetItemTst->m_PinNum,
409  GetChars( GetText( jj ) ),
410  GetChars( alt_cmp ),
411  aNetItemRef->GetNet() );
412  marker->SetAuxiliaryData( msg, aNetItemTst->m_Start );
413  }
414 }
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
#define _(s)
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:101
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:154
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:215

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 225 of file erc.cpp.

226 {
227  wxString msg;
228  wxPoint dummyPos( 0, 0 );
229  int err_count = 0;
230  SCH_SCREENS screens;
231  std::vector< std::shared_ptr<BUS_ALIAS> > aliases;
232 
233  for( auto screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
234  {
235  std::unordered_set< std::shared_ptr<BUS_ALIAS> > screen_aliases = screen->GetBusAliases();
236 
237  for( const std::shared_ptr<BUS_ALIAS>& alias : screen_aliases )
238  {
239  for( const std::shared_ptr<BUS_ALIAS>& test : aliases )
240  {
241  if( alias->GetName() == test->GetName() && alias->Members() != test->Members() )
242  {
243  if( aCreateMarker )
244  {
245  msg = wxString::Format( _( "Bus alias %s has conflicting definitions on"
246  " multiple sheets: %s and %s" ),
247  alias->GetName(),
248  alias->GetParent()->GetFileName(),
249  test->GetParent()->GetFileName() );
250 
251  SCH_MARKER* marker = new SCH_MARKER();
252  marker->SetData( ERCE_BUS_ALIAS_CONFLICT, dummyPos, msg, dummyPos );
253  marker->SetMarkerType( MARKER_BASE::MARKER_ERC );
254  marker->SetErrorLevel( MARKER_BASE::MARKER_SEVERITY_ERROR );
255 
256  test->GetParent()->Append( marker );
257  }
258 
259  ++err_count;
260  }
261  }
262  }
263 
264  aliases.insert( aliases.end(), screen_aliases.begin(), screen_aliases.end() );
265  }
266 
267  return err_count;
268 }
SCH_SCREEN * GetNext()
Definition: sch_screen.cpp:994
#define _(s)
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
SCH_SCREEN * GetFirst()
Definition: sch_screen.cpp:983
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:491

References _, ERCE_BUS_ALIAS_CONFLICT, Format(), 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 174 of file erc.cpp.

175 {
176  SCH_SCREEN* screen;
177  SCH_ITEM* item;
178  SCH_ITEM* test_item;
179  int err_count = 0;
180  SCH_SCREENS screenList; // Created the list of screen
181 
182  for( screen = screenList.GetFirst(); screen != NULL; screen = screenList.GetNext() )
183  {
184  for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
185  {
186  // search for a sheet;
187  if( item->Type() != SCH_SHEET_T )
188  continue;
189 
190  for( test_item = item->Next(); test_item != NULL; test_item = test_item->Next() )
191  {
192  if( test_item->Type() != SCH_SHEET_T )
193  continue;
194 
195  // We have found a second sheet: compare names
196  // we are using case insensitive comparison to avoid mistakes between
197  // similar names like Mysheet and mysheet
198  if( ( (SCH_SHEET*) item )->GetName().CmpNoCase(
199  ( ( SCH_SHEET* ) test_item )->GetName() ) == 0 )
200  {
201  if( aCreateMarker )
202  {
203  /* Create a new marker type ERC error*/
204  SCH_MARKER* marker = new SCH_MARKER();
205  marker->SetTimeStamp( GetNewTimeStamp() );
207  ( (SCH_SHEET*) test_item )->GetPosition(),
208  _( "Duplicate sheet name" ),
209  ( (SCH_SHEET*) test_item )->GetPosition() );
212  screen->Append( marker );
213  }
214 
215  err_count++;
216  }
217  }
218  }
219  }
220 
221  return err_count;
222 }
SCH_SCREEN * GetNext()
Definition: sch_screen.cpp:994
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
#define _(s)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:154
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:983
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:491
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:152

◆ 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 271 of file erc.cpp.

272 {
273  int errors = 0;
274  std::map<wxString, LIB_ID> footprints;
276  aSheetList.GetMultiUnitComponents( refMap, true );
277 
278  for( auto& component : refMap )
279  {
280  auto& refList = component.second;
281 
282  if( refList.GetCount() == 0 )
283  {
284  wxFAIL; // it should not happen
285  continue;
286  }
287 
288  // Reference footprint
289  wxString fp;
290  wxString unitName;
291 
292  for( unsigned i = 0; i < component.second.GetCount(); ++i )
293  {
294  SCH_COMPONENT* cmp = refList.GetItem( i ).GetComp();
295  SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
296  fp = cmp->GetField( FOOTPRINT )->GetText();
297 
298  if( !fp.IsEmpty() )
299  {
300  unitName = cmp->GetRef( &sheetPath )
301  + LIB_PART::SubReference( cmp->GetUnit(), false );
302  break;
303  }
304  }
305 
306  for( unsigned i = 0; i < component.second.GetCount(); ++i )
307  {
308  SCH_REFERENCE& ref = refList.GetItem( i );
309  SCH_COMPONENT* unit = ref.GetComp();
310  SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
311  const wxString curFp = unit->GetField( FOOTPRINT )->GetText();
312 
313  if( !curFp.IsEmpty() && fp != curFp )
314  {
315  wxString curUnitName = unit->GetRef( &sheetPath )
316  + LIB_PART::SubReference( unit->GetUnit(), false );
317  wxString msg = wxString::Format( _( "Unit %s has '%s' assigned, "
318  "whereas unit %s has '%s' assigned" ),
319  unitName,
320  fp,
321  curUnitName,
322  curFp );
323  wxPoint pos = unit->GetPosition();
324 
325  SCH_MARKER* marker = new SCH_MARKER();
326  marker->SetTimeStamp( GetNewTimeStamp() );
327  marker->SetData( ERCE_DIFFERENT_UNIT_FP, pos, msg, pos );
330  ref.GetSheetPath().LastScreen()->Append( marker );
331 
332  ++errors;
333  }
334  }
335  }
336 
337  return errors;
338 }
const SCH_SHEET_PATH & GetSheetPath() const
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.
#define _(s)
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:154
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:649
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.
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
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:215

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(), EDA_TEXT::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 417 of file erc.cpp.

419 {
420  unsigned netItemTst = aNetStart;
422  int erc = OK;
423 
424  /* Analysis of the table of connections. */
425  ELECTRICAL_PINTYPE ref_elect_type = aList->GetItem( aNetItemRef )->m_ElectricalPinType;
426  int local_minconn = NOC;
427 
428  if( ref_elect_type == PIN_NC )
429  local_minconn = NPI;
430 
431  /* Test pins connected to NetItemRef */
432  for( ; ; netItemTst++ )
433  {
434  if( aNetItemRef == netItemTst )
435  continue;
436 
437  // We examine only a given net. We stop the search if the net changes
438  if( ( netItemTst >= aList->size() ) // End of list
439  || ( aList->GetItemNet( aNetItemRef ) !=
440  aList->GetItemNet( netItemTst ) ) ) // End of net
441  {
442  /* End net code found: minimum connection test. */
443  if( ( *aMinConnexion < NET_NC ) && ( local_minconn < NET_NC ) )
444  {
445  /* Not connected or not driven pin. */
446  bool seterr = true;
447 
448  if( local_minconn == NOC &&
449  aList->GetItemType( aNetItemRef ) == NET_PIN )
450  {
451  /* This pin is not connected: for multiple part per
452  * package, and duplicated pin,
453  * search for another instance of this pin
454  * this will be flagged only if all instances of this pin
455  * are not connected
456  * TODO test also if instances connected are connected to
457  * the same net
458  */
459  for( unsigned duplicate = 0; duplicate < aList->size(); duplicate++ )
460  {
461  if( aList->GetItemType( duplicate ) != NET_PIN )
462  continue;
463 
464  if( duplicate == aNetItemRef )
465  continue;
466 
467  if( aList->GetItem( aNetItemRef )->m_PinNum !=
468  aList->GetItem( duplicate )->m_PinNum )
469  continue;
470 
471  if( ( (SCH_COMPONENT*) aList->GetItem( aNetItemRef )->
472  m_Link )->GetRef( &aList->GetItem( aNetItemRef )-> m_SheetPath ) !=
473  ( (SCH_COMPONENT*) aList->GetItem( duplicate )->m_Link )
474  ->GetRef( &aList->GetItem( duplicate )->m_SheetPath ) )
475  continue;
476 
477  // Same component and same pin. Do dot create error for this pin
478  // if the other pin is connected (i.e. if duplicate net has another
479  // item)
480  if( (duplicate > 0)
481  && ( aList->GetItemNet( duplicate ) ==
482  aList->GetItemNet( duplicate - 1 ) ) )
483  seterr = false;
484 
485  if( (duplicate < aList->size() - 1)
486  && ( aList->GetItemNet( duplicate ) ==
487  aList->GetItemNet( duplicate + 1 ) ) )
488  seterr = false;
489  }
490  }
491 
492  if( seterr )
493  Diagnose( aList->GetItem( aNetItemRef ), NULL, local_minconn, WAR );
494 
495  *aMinConnexion = DRV; // inhibiting other messages of this
496  // type for the net.
497  }
498  return;
499  }
500 
501  switch( aList->GetItemType( netItemTst ) )
502  {
504  case NET_SEGMENT:
505  case NET_BUS:
506  case NET_JUNCTION:
507  case NET_LABEL:
508  case NET_HIERLABEL:
509  case NET_BUSLABELMEMBER:
512  case NET_SHEETLABEL:
513  case NET_GLOBLABEL:
515  case NET_PINLABEL:
516  break;
517 
518  case NET_NOCONNECT:
519  local_minconn = std::max( NET_NC, local_minconn );
520  break;
521 
522  case NET_PIN:
523  jj = aList->GetItem( netItemTst )->m_ElectricalPinType;
524  local_minconn = std::max( MinimalReq[ref_elect_type][jj], local_minconn );
525 
526  if( netItemTst <= aNetItemRef )
527  break;
528 
529  if( erc == OK )
530  {
531  erc = DiagErc[ref_elect_type][jj];
532 
533  if( erc != OK )
534  {
535  if( aList->GetConnectionType( netItemTst ) == UNCONNECTED )
536  {
537  Diagnose( aList->GetItem( aNetItemRef ),
538  aList->GetItem( netItemTst ),
539  0, erc );
540  aList->SetConnectionType( netItemTst, NOCONNECT_SYMBOL_PRESENT );
541  }
542  }
543  }
544 
545  break;
546  }
547  }
548 }
Definition: erc.h:43
int DiagErc[PINTYPE_COUNT][PINTYPE_COUNT]
Definition: erc.cpp:121
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:341
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:157
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 569 of file erc.cpp.

570 {
571  wxFFile file( aFullFileName, wxT( "wt" ) );
572 
573  if( !file.IsOpened() )
574  return false;
575 
576  wxString msg = wxString::Format( _( "ERC report (%s, Encoding UTF8)\n" ), DateAndTime() );
577  int err_count = 0;
578  int warn_count = 0;
579  int total_count = 0;
580  SCH_SHEET_LIST sheetList( g_RootSheet );
581 
582  for( unsigned i = 0; i < sheetList.size(); i++ )
583  {
584  msg << wxString::Format( _( "\n***** Sheet %s\n" ),
585  GetChars( sheetList[i].PathHumanReadable() ) );
586 
587  for( SCH_ITEM* item = sheetList[i].LastDrawList(); item != NULL; item = item->Next() )
588  {
589  if( item->Type() != SCH_MARKER_T )
590  continue;
591 
592  SCH_MARKER* marker = (SCH_MARKER*) item;
593 
594  if( marker->GetMarkerType() != MARKER_BASE::MARKER_ERC )
595  continue;
596 
597  total_count++;
598 
600  err_count++;
601 
603  warn_count++;
604 
605  msg << marker->GetReporter().ShowReport( aUnits );
606  }
607  }
608 
609  msg << wxString::Format( _( "\n ** ERC messages: %d Errors %d Warnings %d\n" ),
610  total_count, err_count, warn_count );
611 
612  // Currently: write report using UTF8 (as usual in Kicad).
613  // TODO: see if we can use the current encoding page (mainly for Windows users),
614  // Or other format (HTML?)
615  file.Write( msg );
616 
617  // wxFFile dtor will close the file.
618 
619  return true;
620 }
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:47
#define _(s)
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:101
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:649
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:229
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:345

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 84 of file erc.cpp.

Referenced by DIALOG_ERC::ReBuildMatrixPanel().

◆ CommentERC_V

const wxString CommentERC_V[]

Definition at line 100 of file erc.cpp.

Referenced by DIALOG_ERC::ReBuildMatrixPanel().