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 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 324 of file eeschema/erc.cpp.

325 {
326  SCH_MARKER* marker = NULL;
327  SCH_SCREEN* screen;
328  ELECTRICAL_PINTYPE ii, jj;
329 
330  if( aDiag == OK || aMinConn < 1 )
331  return;
332 
333  /* Create new marker for ERC error. */
334  marker = new SCH_MARKER();
335  marker->SetTimeStamp( GetNewTimeStamp() );
336 
339  screen = aNetItemRef->m_SheetPath.LastScreen();
340  screen->Append( marker );
341 
342  wxString msg;
343 
344  ii = aNetItemRef->m_ElectricalPinType;
345 
346  wxString cmp_ref( "?" );
347 
348  if( aNetItemRef->m_Type == NETLIST_ITEM::PIN && aNetItemRef->m_Link )
349  cmp_ref = aNetItemRef->GetComponentParent()->GetRef( &aNetItemRef->m_SheetPath );
350 
351  if( aNetItemTst == NULL )
352  {
353  if( aMinConn == NOD ) /* Nothing driving the net. */
354  {
355  if( aNetItemRef->m_Type == NETLIST_ITEM::PIN && aNetItemRef->m_Link )
356  cmp_ref = aNetItemRef->GetComponentParent()->GetRef(
357  &aNetItemRef->m_SheetPath );
358 
359  msg.Printf( _( "Pin %s (%s) of component %s is not driven (Net %d)." ),
360  aNetItemRef->m_PinNum,
361  GetChars( GetText( ii ) ),
362  GetChars( cmp_ref ),
363  aNetItemRef->GetNet() );
364  marker->SetData( ERCE_PIN_NOT_DRIVEN, aNetItemRef->m_Start, msg, aNetItemRef->m_Start );
365  return;
366  }
367  }
368 
369  if( aNetItemTst ) /* Error between 2 pins */
370  {
371  jj = aNetItemTst->m_ElectricalPinType;
373 
374  if( aDiag == ERR )
375  {
378  }
379 
380  wxString alt_cmp( "?" );
381 
382  if( aNetItemTst->m_Type == NETLIST_ITEM::PIN && aNetItemTst->m_Link )
383  alt_cmp = aNetItemTst->GetComponentParent()->GetRef( &aNetItemTst->m_SheetPath );
384 
385  msg.Printf( _( "Pin %s (%s) of component %s is connected to " ),
386  aNetItemRef->m_PinNum,
387  GetChars( GetText( ii ) ),
388  GetChars( cmp_ref ) );
389  marker->SetData( errortype, aNetItemRef->m_Start, msg, aNetItemRef->m_Start );
390  msg.Printf( _( "pin %s (%s) of component %s (net %d)." ),
391  aNetItemTst->m_PinNum,
392  GetChars( GetText( jj ) ),
393  GetChars( alt_cmp ),
394  aNetItemRef->GetNet() );
395  marker->SetAuxiliaryData( msg, aNetItemTst->m_Start );
396  }
397 }
Definition: erc.h:42
timestamp_t GetNewTimeStamp()
Definition: common.cpp:215
Definition: erc.h:44
#define NULL
wxString GetText(GRAPHIC_PINSHAPE aShape)
Definition: pin_shape.cpp:58
void SetMarkerType(enum TYPEMARKER aMarkerType)
accessors to set/get marker type (DRC, ERC, or other)
Definition: marker_base.h:181
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.cpp:175
#define _(s)
Definition: 3d_actions.cpp:31
void SetErrorLevel(MARKER_SEVERITY aErrorLevel)
accessors to set/get error levels (warning, error, fatal error..)
Definition: marker_base.h:169
errortype
Definition: erc.h:40
void SetData(EDA_UNITS 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.
void SetAuxiliaryData(const wxString &aAuxiliaryText, const wxPoint &aAuxiliaryPos)
Function SetAuxiliaryData initialize data for the second (auxiliary) item.
Definition: marker_base.h:225
#define NOD
Definition: erc.h:81
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:212

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, NOD, NULL, OK, PIN, 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 208 of file eeschema/erc.cpp.

209 {
210  wxString msg;
211  wxPoint dummyPos( 0, 0 );
212  int err_count = 0;
213  SCH_SCREENS screens;
214  std::vector< std::shared_ptr<BUS_ALIAS> > aliases;
215 
216  for( auto screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
217  {
218  std::unordered_set< std::shared_ptr<BUS_ALIAS> > screen_aliases = screen->GetBusAliases();
219 
220  for( const std::shared_ptr<BUS_ALIAS>& alias : screen_aliases )
221  {
222  for( const std::shared_ptr<BUS_ALIAS>& test : aliases )
223  {
224  if( alias->GetName() == test->GetName() && alias->Members() != test->Members() )
225  {
226  if( aCreateMarker )
227  {
228  msg = wxString::Format( _( "Bus alias %s has conflicting definitions on"
229  " multiple sheets: %s and %s" ),
230  alias->GetName(),
231  alias->GetParent()->GetFileName(),
232  test->GetParent()->GetFileName() );
233 
234  SCH_MARKER* marker = new SCH_MARKER();
235  marker->SetData( ERCE_BUS_ALIAS_CONFLICT, dummyPos, msg, dummyPos );
236  marker->SetMarkerType( MARKER_BASE::MARKER_ERC );
237  marker->SetErrorLevel( MARKER_BASE::MARKER_SEVERITY_ERROR );
238 
239  test->GetParent()->Append( marker );
240  }
241 
242  ++err_count;
243  }
244  }
245  }
246 
247  aliases.insert( aliases.end(), screen_aliases.begin(), screen_aliases.end() );
248  }
249 
250  return err_count;
251 }
SCH_SCREEN * GetNext()
Definition: sch_screen.cpp:981
#define NULL
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
#define _(s)
Definition: 3d_actions.cpp:31
SCH_SCREEN * GetFirst()
Definition: sch_screen.cpp:970
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:498

References _, ERCE_BUS_ALIAS_CONFLICT, Format(), SCH_SCREENS::GetFirst(), SCH_SCREENS::GetNext(), MARKER_BASE::MARKER_ERC, MARKER_BASE::MARKER_SEVERITY_ERROR, and NULL.

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 157 of file eeschema/erc.cpp.

158 {
159  SCH_SCREEN* screen;
160  int err_count = 0;
161  SCH_SCREENS screenList; // Created the list of screen
162 
163  for( screen = screenList.GetFirst(); screen != NULL; screen = screenList.GetNext() )
164  {
165  std::vector<SCH_SHEET*> list;
166 
167  for( auto item : screen->Items().OfType( SCH_SHEET_T ) )
168  list.push_back( static_cast<SCH_SHEET*>( item ) );
169 
170  for( size_t i = 0; i < list.size(); i++ )
171  {
172  auto item = list[i];
173 
174  for( size_t j = i + 1; j < list.size(); j++ )
175  {
176  auto test_item = list[j];
177 
178  // We have found a second sheet: compare names
179  // we are using case insensitive comparison to avoid mistakes between
180  // similar names like Mysheet and mysheet
181  if( ( (SCH_SHEET*) item )->GetName().CmpNoCase(
182  ( ( SCH_SHEET* ) test_item )->GetName() ) == 0 )
183  {
184  if( aCreateMarker )
185  {
186  /* Create a new marker type ERC error*/
187  SCH_MARKER* marker = new SCH_MARKER();
188  marker->SetTimeStamp( GetNewTimeStamp() );
190  ( (SCH_SHEET*) test_item )->GetPosition(),
191  _( "Duplicate sheet name" ),
192  ( (SCH_SHEET*) test_item )->GetPosition() );
195  screen->Append( marker );
196  }
197 
198  err_count++;
199  }
200  }
201  }
202  }
203 
204  return err_count;
205 }
SCH_SCREEN * GetNext()
Definition: sch_screen.cpp:981
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
timestamp_t GetNewTimeStamp()
Definition: common.cpp:215
#define NULL
void SetMarkerType(enum TYPEMARKER aMarkerType)
accessors to set/get marker type (DRC, ERC, or other)
Definition: marker_base.h:181
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:206
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:175
#define _(s)
Definition: 3d_actions.cpp:31
void SetErrorLevel(MARKER_SEVERITY aErrorLevel)
accessors to set/get error levels (warning, error, fatal error..)
Definition: marker_base.h:169
EE_RTREE & Items()
Definition: sch_screen.h:127
SCH_SCREEN * GetFirst()
Definition: sch_screen.cpp:970
void SetData(EDA_UNITS 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.
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:498
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:212

◆ 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 254 of file eeschema/erc.cpp.

255 {
256  int errors = 0;
257  std::map<wxString, LIB_ID> footprints;
259  aSheetList.GetMultiUnitComponents( refMap, true );
260 
261  for( auto& component : refMap )
262  {
263  auto& refList = component.second;
264 
265  if( refList.GetCount() == 0 )
266  {
267  wxFAIL; // it should not happen
268  continue;
269  }
270 
271  // Reference footprint
272  wxString fp;
273  wxString unitName;
274 
275  for( unsigned i = 0; i < component.second.GetCount(); ++i )
276  {
277  SCH_COMPONENT* cmp = refList.GetItem( i ).GetComp();
278  SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
279  fp = cmp->GetField( FOOTPRINT )->GetText();
280 
281  if( !fp.IsEmpty() )
282  {
283  unitName = cmp->GetRef( &sheetPath )
284  + LIB_PART::SubReference( cmp->GetUnit(), false );
285  break;
286  }
287  }
288 
289  for( unsigned i = 0; i < component.second.GetCount(); ++i )
290  {
291  SCH_REFERENCE& ref = refList.GetItem( i );
292  SCH_COMPONENT* unit = ref.GetComp();
293  SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
294  const wxString curFp = unit->GetField( FOOTPRINT )->GetText();
295 
296  if( !curFp.IsEmpty() && fp != curFp )
297  {
298  wxString curUnitName = unit->GetRef( &sheetPath )
299  + LIB_PART::SubReference( unit->GetUnit(), false );
300  wxString msg = wxString::Format( _( "Unit %s has '%s' assigned, "
301  "whereas unit %s has '%s' assigned" ),
302  unitName,
303  fp,
304  curUnitName,
305  curFp );
306  wxPoint pos = unit->GetPosition();
307 
308  SCH_MARKER* marker = new SCH_MARKER();
309  marker->SetTimeStamp( GetNewTimeStamp() );
310  marker->SetData( ERCE_DIFFERENT_UNIT_FP, pos, msg, pos );
313  ref.GetSheetPath().LastScreen()->Append( marker );
314 
315  ++errors;
316  }
317  }
318  }
319 
320  return errors;
321 }
const SCH_SHEET_PATH & GetSheetPath() const
SCH_COMPONENT * GetComp() const
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:215
int GetUnit() const
SCH_SHEET_PATH.
void SetMarkerType(enum TYPEMARKER aMarkerType)
accessors to set/get marker type (DRC, ERC, or other)
Definition: marker_base.h:181
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 ...
SCH_SCREEN * LastScreen()
Function LastScreen.
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.cpp:175
#define _(s)
Definition: 3d_actions.cpp:31
void SetErrorLevel(MARKER_SEVERITY aErrorLevel)
accessors to set/get error levels (warning, error, fatal error..)
Definition: marker_base.h:169
static wxString SubReference(int aUnit, bool aAddSeparator=true)
SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:89
wxPoint GetPosition() const override
Function GetPosition.
void SetData(EDA_UNITS 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.
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:123
SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic.
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:212

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(), 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 400 of file eeschema/erc.cpp.

402 {
403  unsigned netItemTst = aNetStart;
405  int erc = OK;
406 
407  /* Analysis of the table of connections. */
408  ELECTRICAL_PINTYPE ref_elect_type = aList->GetItem( aNetItemRef )->m_ElectricalPinType;
409  int local_minconn = NOC;
410 
411  if( ref_elect_type == ELECTRICAL_PINTYPE::PT_NC )
412  local_minconn = NPI;
413 
414  /* Test pins connected to NetItemRef */
415  for( ; ; netItemTst++ )
416  {
417  if( aNetItemRef == netItemTst )
418  continue;
419 
420  // We examine only a given net. We stop the search if the net changes
421  if( ( netItemTst >= aList->size() ) // End of list
422  || ( aList->GetItemNet( aNetItemRef ) !=
423  aList->GetItemNet( netItemTst ) ) ) // End of net
424  {
425  /* End net code found: minimum connection test. */
426  if( ( *aMinConnexion < NET_NC ) && ( local_minconn < NET_NC ) )
427  {
428  /* Not connected or not driven pin. */
429  bool seterr = true;
430 
431  if( local_minconn == NOC && aList->GetItemType( aNetItemRef ) == NETLIST_ITEM::PIN )
432  {
433  /* This pin is not connected: for multiple part per
434  * package, and duplicated pin,
435  * search for another instance of this pin
436  * this will be flagged only if all instances of this pin
437  * are not connected
438  * TODO test also if instances connected are connected to
439  * the same net
440  */
441  for( unsigned duplicate = 0; duplicate < aList->size(); duplicate++ )
442  {
443  if( aList->GetItemType( duplicate ) != NETLIST_ITEM::PIN )
444  continue;
445 
446  if( duplicate == aNetItemRef )
447  continue;
448 
449  if( aList->GetItem( aNetItemRef )->m_PinNum !=
450  aList->GetItem( duplicate )->m_PinNum )
451  continue;
452 
453  if( ( (SCH_COMPONENT*) aList->GetItem( aNetItemRef )->
454  m_Link )->GetRef( &aList->GetItem( aNetItemRef )-> m_SheetPath ) !=
455  ( (SCH_COMPONENT*) aList->GetItem( duplicate )->m_Link )
456  ->GetRef( &aList->GetItem( duplicate )->m_SheetPath ) )
457  continue;
458 
459  // Same component and same pin. Do dot create error for this pin
460  // if the other pin is connected (i.e. if duplicate net has another
461  // item)
462  if( (duplicate > 0)
463  && ( aList->GetItemNet( duplicate ) ==
464  aList->GetItemNet( duplicate - 1 ) ) )
465  seterr = false;
466 
467  if( (duplicate < aList->size() - 1)
468  && ( aList->GetItemNet( duplicate ) ==
469  aList->GetItemNet( duplicate + 1 ) ) )
470  seterr = false;
471  }
472  }
473 
474  if( seterr )
475  Diagnose( aList->GetItem( aNetItemRef ), NULL, local_minconn, WAR );
476 
477  *aMinConnexion = DRV; // inhibiting other messages of this
478  // type for the net.
479  }
480  return;
481  }
482 
483  switch( aList->GetItemType( netItemTst ) )
484  {
487  case NETLIST_ITEM::BUS:
489  case NETLIST_ITEM::LABEL:
498  break;
499 
501  local_minconn = std::max( NET_NC, local_minconn );
502  break;
503 
504  case NETLIST_ITEM::PIN:
505  jj = aList->GetItem( netItemTst )->m_ElectricalPinType;
506  local_minconn = std::max(
507  MinimalReq[static_cast<int>( ref_elect_type )][static_cast<int>( jj )],
508  local_minconn );
509 
510  if( netItemTst <= aNetItemRef )
511  break;
512 
513  if( erc == OK )
514  {
515  erc = DiagErc[static_cast<int>( ref_elect_type )][static_cast<int>( jj )];
516 
517  if( erc != OK )
518  {
519  if( aList->GetConnectionType( netItemTst ) == NET_CONNECTION::UNCONNECTED )
520  {
521  Diagnose( aList->GetItem( aNetItemRef ), aList->GetItem( netItemTst ), 0,
522  erc );
523  aList->SetConnectionType(
525  }
526  }
527  }
528 
529  break;
530  }
531  }
532 }
Definition: erc.h:43
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...
SCH_SHEET_PATH m_SheetPath
ELECTRICAL_PINTYPE m_ElectricalPinType
int GetItemNet(unsigned aIdx) const
Acces to an item net code.
#define DRV
Definition: erc.h:79
Definition: erc.h:42
#define NULL
int DiagErc[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
NETLIST_ITEM GetItemType(unsigned aIdx) const
Acces to an item type.
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
#define NOC
Definition: erc.h:82
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
#define NPI
Definition: erc.h:78
SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:89
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...
NET_CONNECTION GetConnectionType(unsigned aIdx)
#define NET_NC
Definition: erc.h:80
not connected (must be left open)
SCH_ITEM * m_Link
static int MinimalReq[ELECTRICAL_PINTYPES_TOTAL][ELECTRICAL_PINTYPES_TOTAL]
Look up table which gives the minimal drive for a pair of connected pins on a net.

References BUS, BUSLABELMEMBER, DiagErc, Diagnose(), DRV, NETLIST_OBJECT_LIST::GetConnectionType(), NETLIST_OBJECT_LIST::GetItem(), NETLIST_OBJECT_LIST::GetItemNet(), NETLIST_OBJECT_LIST::GetItemType(), GLOBBUSLABELMEMBER, GLOBLABEL, HIERBUSLABELMEMBER, HIERLABEL, ITEM_UNSPECIFIED, JUNCTION, LABEL, NETLIST_OBJECT::m_ElectricalPinType, NETLIST_OBJECT::m_Link, NETLIST_OBJECT::m_PinNum, NETLIST_OBJECT::m_SheetPath, MinimalReq, NET_NC, NOC, NOCONNECT, NOCONNECT_SYMBOL_PRESENT, NPI, NULL, OK, PIN, PINLABEL, PT_NC, SEGMENT, NETLIST_OBJECT_LIST::SetConnectionType(), SHEETBUSLABELMEMBER, SHEETLABEL, UNCONNECTED, and WAR.

Referenced by DIALOG_ERC::TestErc().

◆ WriteDiagnosticERC()

bool WriteDiagnosticERC ( EDA_UNITS  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 553 of file eeschema/erc.cpp.

554 {
555  wxFFile file( aFullFileName, wxT( "wt" ) );
556 
557  if( !file.IsOpened() )
558  return false;
559 
560  wxString msg = wxString::Format( _( "ERC report (%s, Encoding UTF8)\n" ), DateAndTime() );
561  int err_count = 0;
562  int warn_count = 0;
563  int total_count = 0;
564  SCH_SHEET_LIST sheetList( g_RootSheet );
565 
566  for( unsigned i = 0; i < sheetList.size(); i++ )
567  {
568  msg << wxString::Format( _( "\n***** Sheet %s\n" ),
569  GetChars( sheetList[i].PathHumanReadable() ) );
570 
571  for( auto aItem : sheetList[i].LastScreen()->Items().OfType( SCH_MARKER_T ) )
572  {
573  auto marker = static_cast<const SCH_MARKER*>( aItem );
574 
575  if( marker->GetMarkerType() != MARKER_BASE::MARKER_ERC )
576  continue;
577 
578  total_count++;
579 
580  if( marker->GetErrorLevel() == MARKER_BASE::MARKER_SEVERITY_ERROR )
581  err_count++;
582 
583  if( marker->GetErrorLevel() == MARKER_BASE::MARKER_SEVERITY_WARNING )
584  warn_count++;
585 
586  msg << marker->GetReporter().ShowReport( aUnits );
587  }
588  }
589 
590  msg << wxString::Format( _( "\n ** ERC messages: %d Errors %d Warnings %d\n" ),
591  total_count, err_count, warn_count );
592 
593  // Currently: write report using UTF8 (as usual in Kicad).
594  // TODO: see if we can use the current encoding page (mainly for Windows users),
595  // Or other format (HTML?)
596  file.Write( msg );
597 
598  // wxFFile dtor will close the file.
599 
600  return true;
601 }
SCH_SHEET_LIST.
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
#define _(s)
Definition: 3d_actions.cpp:31
SCH_SHEET * g_RootSheet
wxString DateAndTime()
Definition: string.cpp:345

References _, DateAndTime(), Format(), g_RootSheet, GetChars(), MARKER_BASE::MARKER_ERC, MARKER_BASE::MARKER_SEVERITY_ERROR, MARKER_BASE::MARKER_SEVERITY_WARNING, and SCH_MARKER_T.

Referenced by DIALOG_ERC::TestErc().

Variable Documentation

◆ CommentERC_H

const wxString CommentERC_H[]

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

Referenced by DIALOG_ERC::ReBuildMatrixPanel().

◆ CommentERC_V

const wxString CommentERC_V[]

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

Referenced by DIALOG_ERC::ReBuildMatrixPanel().