KiCad PCB EDA Suite
erc.cpp File Reference

Electrical Rules Check implementation. More...

#include <fctsys.h>
#include <sch_draw_panel.h>
#include <kicad_string.h>
#include <sch_edit_frame.h>
#include <netlist.h>
#include <netlist_object.h>
#include <lib_pin.h>
#include <erc.h>
#include <sch_marker.h>
#include <sch_sheet.h>
#include <sch_reference_list.h>
#include <wx/ffile.h>

Go to the source code of this file.

Classes

struct  compare_labels
 
struct  compare_label_names
 
struct  compare_paths
 

Functions

int TestDuplicateSheetNames (bool aCreateMarker)
 Function TestDuplicateSheetNames( ) inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated). More...
 
int TestMultiunitFootprints (SCH_SHEET_LIST &aSheetList)
 Test if all units of each multiunit component have the same footprint assigned. More...
 
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 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...
 
bool WriteDiagnosticERC (EDA_UNITS_T aUnits, const wxString &aFullFileName)
 Function WriteDiagnosticERC save the ERC errors to aFullFileName. More...
 
static int countIndenticalLabels (std::vector< NETLIST_OBJECT * > &aList, NETLIST_OBJECT *aLabel)
 
static void SimilarLabelsDiagnose (NETLIST_OBJECT *aItemA, NETLIST_OBJECT *aItemB)
 

Variables

const wxString CommentERC_H []
 
const wxString CommentERC_V []
 
int DiagErc [PINTYPE_COUNT][PINTYPE_COUNT]
 
int DefaultDiagErc [PINTYPE_COUNT][PINTYPE_COUNT]
 Default Look up table which gives the ERC error level for a pair of connected pins Same as DiagErc, but cannot be modified. More...
 
static int MinimalReq [PINTYPE_COUNT][PINTYPE_COUNT]
 Look up table which gives the minimal drive for a pair of connected pins on a net. More...
 

Detailed Description

Electrical Rules Check implementation.

Definition in file erc.cpp.

Function Documentation

static int countIndenticalLabels ( std::vector< NETLIST_OBJECT * > &  aList,
NETLIST_OBJECT aLabel 
)
static

Definition at line 841 of file erc.cpp.

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

Referenced by compare_paths::operator()(), and NETLIST_OBJECT_LIST::TestforSimilarLabels().

842 {
843  int count = 0;
844 
845  if( aLabel->IsLabelGlobal() )
846  {
847  for( unsigned netItem = 0; netItem < aList.size(); ++netItem )
848  {
849  NETLIST_OBJECT* item = aList[netItem];
850 
851  if( item->IsLabelGlobal() && item->m_Label == aLabel->m_Label )
852  count++;
853  }
854  }
855  else
856  {
857  for( unsigned netItem = 0; netItem < aList.size(); ++netItem )
858  {
859  NETLIST_OBJECT* item = aList[netItem];
860 
861  if( item->m_Label == aLabel->m_Label &&
862  item->m_SheetPath.Path() == aLabel->m_SheetPath.Path() )
863  count++;
864  }
865  }
866 
867  return count;
868 }
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...
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 294 of file erc.cpp.

References SCH_SCREEN::Append(), ERCE_GLOBLABEL, ERCE_HIERACHICAL_LABEL, ERCE_NOCONNECT_CONNECTED, ERCE_PIN_NOT_CONNECTED, 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_Label, 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_GLOBLABEL, NET_HIERBUSLABELMEMBER, NET_HIERLABEL, NET_PIN, NOC, NOD, OK, MARKER_BASE::SetAuxiliaryData(), MARKER_BASE::SetData(), MARKER_BASE::SetErrorLevel(), MARKER_BASE::SetMarkerType(), EDA_ITEM::SetTimeStamp(), and UNC.

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

296 {
297  SCH_MARKER* marker = NULL;
298  SCH_SCREEN* screen;
299  ELECTRICAL_PINTYPE ii, jj;
300 
301  if( aDiag == OK )
302  return;
303 
304  /* Create new marker for ERC error. */
305  marker = new SCH_MARKER();
306  marker->SetTimeStamp( GetNewTimeStamp() );
307 
310  screen = aNetItemRef->m_SheetPath.LastScreen();
311  screen->Append( marker );
312 
313  wxString msg;
314 
315  if( aMinConn < 0 )
316  {
317  if( aNetItemRef->m_Type == NET_HIERLABEL || aNetItemRef->m_Type == NET_HIERBUSLABELMEMBER )
318  {
319  msg.Printf( _( "Hierarchical label %s is not connected to a sheet label." ),
320  GetChars( aNetItemRef->m_Label ) );
322  aNetItemRef->m_Start,
323  msg,
324  aNetItemRef->m_Start );
325  }
326  else if( aNetItemRef->m_Type == NET_GLOBLABEL )
327  {
328  msg.Printf( _( "Global label %s is not connected to any other global label." ),
329  GetChars( aNetItemRef->m_Label ) );
330  marker->SetData( ERCE_GLOBLABEL,
331  aNetItemRef->m_Start,
332  msg,
333  aNetItemRef->m_Start );
334  }
335  else
336  {
337  msg.Printf( _( "Sheet label %s is not connected to a hierarchical label." ),
338  GetChars( aNetItemRef->m_Label ) );
340  aNetItemRef->m_Start,
341  msg,
342  aNetItemRef->m_Start );
343  }
344 
345  return;
346  }
347 
348  ii = aNetItemRef->m_ElectricalPinType;
349 
350  wxString cmp_ref( "?" );
351 
352  if( aNetItemRef->m_Type == NET_PIN && aNetItemRef->m_Link )
353  cmp_ref = aNetItemRef->GetComponentParent()->GetRef( &aNetItemRef->m_SheetPath );
354 
355  if( aNetItemTst == NULL )
356  {
357  if( aMinConn == NOC ) /* Only 1 element in the net. */
358  {
359  msg.Printf( _( "Pin %s (%s) of component %s is unconnected." ),
360  aNetItemRef->m_PinNum,
361  GetChars( GetText( ii ) ),
362  GetChars( cmp_ref ) );
364  aNetItemRef->m_Start,
365  msg,
366  aNetItemRef->m_Start );
367  return;
368  }
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,
382  aNetItemRef->m_Start,
383  msg,
384  aNetItemRef->m_Start );
385  return;
386  }
387 
388  if( aDiag == UNC )
389  {
390  msg.Printf( _( "More than 1 pin connected to an UnConnect symbol." ) );
392  aNetItemRef->m_Start,
393  msg,
394  aNetItemRef->m_Start );
395  return;
396  }
397  }
398 
399  if( aNetItemTst ) /* Error between 2 pins */
400  {
401  jj = aNetItemTst->m_ElectricalPinType;
403 
404  if( aDiag == ERR )
405  {
407  errortype = ERCE_PIN_TO_PIN_ERROR;
408  }
409 
410  wxString alt_cmp( "?" );
411 
412  if( aNetItemTst->m_Type == NET_PIN && aNetItemTst->m_Link )
413  alt_cmp = aNetItemTst->GetComponentParent()->GetRef( &aNetItemTst->m_SheetPath );
414 
415  msg.Printf( _( "Pin %s (%s) of component %s is connected to " ),
416  aNetItemRef->m_PinNum,
417  GetChars( GetText( ii ) ),
418  GetChars( cmp_ref ) );
419  marker->SetData( errortype, aNetItemRef->m_Start, msg, aNetItemRef->m_Start );
420  msg.Printf( _( "pin %s (%s) of component %s (net %d)." ),
421  aNetItemTst->m_PinNum,
422  GetChars( GetText( jj ) ),
423  GetChars( alt_cmp ),
424  aNetItemRef->GetNet() );
425  marker->SetAuxiliaryData( msg, aNetItemTst->m_Start );
426  }
427 }
#define ERCE_HIERACHICAL_LABEL
Definition: erc.h:58
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.
#define ERCE_PIN_NOT_DRIVEN
Definition: erc.h:55
#define ERCE_PIN_NOT_CONNECTED
Definition: erc.h:54
SCH_SHEET_PATH m_SheetPath
ELECTRICAL_PINTYPE m_ElectricalPinType
SCH_SCREEN * LastScreen() const
Function LastScreen.
NETLIST_ITEM_T m_Type
Definition: erc.h:42
timestamp_t GetNewTimeStamp()
Definition: common.cpp:212
Definition: erc.h:44
int GetNet() const
#define ERCE_GLOBLABEL
Definition: erc.h:60
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
Definition: erc.h:45
#define ERCE_PIN_TO_PIN_ERROR
Definition: erc.h:57
void SetMarkerType(enum TYPEMARKER aMarkerType)
accessors to set/get marker type (DRC, ERC, or other)
Definition: marker_base.h:159
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
SCH_COMPONENT * GetComponentParent() const
For Pins (NET_PINS):
#define NOC
Definition: erc.h:73
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:92
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:162
void SetErrorLevel(MARKER_SEVERITY aErrorLevel)
accessors to set/get error levels (warning, error, fatal error..)
Definition: marker_base.h:147
errortype
Definition: erc.h:40
#define ERCE_NOCONNECT_CONNECTED
Definition: erc.h:59
#define ERCE_PIN_TO_PIN_WARNING
Definition: erc.h:56
SCH_ITEM * m_Link
void SetAuxiliaryData(const wxString &aAuxiliaryText, const wxPoint &aAuxiliaryPos)
Function SetAuxiliaryData initialize data for the second (auxiliary) item.
Definition: marker_base.h:204
#define NOD
Definition: erc.h:72
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:206
static void SimilarLabelsDiagnose ( NETLIST_OBJECT aItemA,
NETLIST_OBJECT aItemB 
)
static

Definition at line 871 of file erc.cpp.

References SCH_SCREEN::Append(), ERCE_SIMILAR_GLBL_LABELS, ERCE_SIMILAR_LABELS, GetChars(), GetNewTimeStamp(), NETLIST_OBJECT::IsLabelGlobal(), SCH_SHEET_PATH::LastScreen(), NETLIST_OBJECT::m_Label, NETLIST_OBJECT::m_SheetPath, NETLIST_OBJECT::m_Start, MARKER_BASE::MARKER_ERC, MARKER_BASE::MARKER_SEVERITY_WARNING, SCH_SHEET_PATH::PathHumanReadable(), MARKER_BASE::SetAuxiliaryData(), MARKER_BASE::SetData(), MARKER_BASE::SetErrorLevel(), MARKER_BASE::SetMarkerType(), and EDA_ITEM::SetTimeStamp().

Referenced by compare_paths::operator()(), and NETLIST_OBJECT_LIST::TestforSimilarLabels().

872 {
873  // Create new marker for ERC.
874  SCH_MARKER* marker = new SCH_MARKER();
875 
876  marker->SetTimeStamp( GetNewTimeStamp() );
879  SCH_SCREEN* screen = aItemA->m_SheetPath.LastScreen();
880  screen->Append( marker );
881 
882  wxString fmt = aItemA->IsLabelGlobal() ?
883  _( "Global label \"%s\" (sheet \"%s\") looks like:" ) :
884  _( "Local label \"%s\" (sheet \"%s\") looks like:" );
885  wxString msg;
886 
887  msg.Printf( fmt, GetChars( aItemA->m_Label ), GetChars( aItemA->m_SheetPath.PathHumanReadable() ) );
888  marker->SetData( aItemA->IsLabelGlobal() && aItemB->IsLabelGlobal() ?
890  aItemA->m_Start, msg, aItemA->m_Start );
891 
892  fmt = aItemB->IsLabelGlobal() ? _( "Global label \"%s\" (sheet \"%s\")" ) :
893  _( "Local label \"%s\" (sheet \"%s\")" );
894  msg.Printf( fmt, GetChars( aItemB->m_Label ), GetChars( aItemB->m_SheetPath.PathHumanReadable() ) );
895  marker->SetAuxiliaryData( msg, aItemB->m_Start );
896 }
bool IsLabelGlobal() const
Function IsLabelGlobal.
#define ERCE_SIMILAR_LABELS
Definition: erc.h:61
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.
SCH_SHEET_PATH m_SheetPath
SCH_SCREEN * LastScreen() const
Function LastScreen.
timestamp_t GetNewTimeStamp()
Definition: common.cpp:212
#define ERCE_SIMILAR_GLBL_LABELS
Definition: erc.h:62
wxString PathHumanReadable() const
Function PathHumanReadable returns the sheet path in a human readable form, i.e.
void SetMarkerType(enum TYPEMARKER aMarkerType)
accessors to set/get marker type (DRC, ERC, or other)
Definition: marker_base.h:159
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:92
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:162
void SetErrorLevel(MARKER_SEVERITY aErrorLevel)
accessors to set/get error levels (warning, error, fatal error..)
Definition: marker_base.h:147
void SetAuxiliaryData(const wxString &aAuxiliaryText, const wxPoint &aAuxiliaryPos)
Function SetAuxiliaryData initialize data for the second (auxiliary) item.
Definition: marker_base.h:204
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:206
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(), DIALOG_ERC::TestErc(), and SCH_EDIT_FRAME::WriteNetListFile().

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:201
SCH_SCREEN * GetNext()
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.
SCH_ITEM * Next() const
timestamp_t GetNewTimeStamp()
Definition: common.cpp:212
#define ERCE_DUPLICATE_SHEET_NAME
Definition: erc.h:53
void SetMarkerType(enum TYPEMARKER aMarkerType)
accessors to set/get marker type (DRC, ERC, or other)
Definition: marker_base.h:159
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:160
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:162
void SetErrorLevel(MARKER_SEVERITY aErrorLevel)
accessors to set/get error levels (warning, error, fatal error..)
Definition: marker_base.h:147
SCH_SCREEN * GetFirst()
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:523
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:206
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 228 of file erc.cpp.

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, and LIB_PART::SubReference().

Referenced by DIALOG_ERC::TestErc().

229 {
230  int errors = 0;
231  std::map<wxString, LIB_ID> footprints;
233  aSheetList.GetMultiUnitComponents( refMap, true );
234 
235  for( auto& component : refMap )
236  {
237  auto& refList = component.second;
238 
239  if( refList.GetCount() == 0 )
240  {
241  wxFAIL; // it should not happen
242  continue;
243  }
244 
245  // Reference footprint
246  wxString fp;
247  wxString unitName;
248 
249  for( unsigned i = 0; i < component.second.GetCount(); ++i )
250  {
251  SCH_COMPONENT* cmp = refList.GetItem( i ).GetComp();
252  SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
253  fp = cmp->GetField( FOOTPRINT )->GetText();
254 
255  if( !fp.IsEmpty() )
256  {
257  unitName = cmp->GetRef( &sheetPath )
258  + LIB_PART::SubReference( cmp->GetUnit(), false );
259  break;
260  }
261  }
262 
263  for( unsigned i = 0; i < component.second.GetCount(); ++i )
264  {
265  SCH_REFERENCE& ref = refList.GetItem( i );
266  SCH_COMPONENT* unit = ref.GetComp();
267  SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
268  const wxString& curFp = unit->GetField( FOOTPRINT )->GetText();
269 
270  if( !curFp.IsEmpty() && fp != curFp )
271  {
272  wxString curUnitName = unit->GetRef( &sheetPath )
273  + LIB_PART::SubReference( unit->GetUnit(), false );
274 
275  SCH_MARKER* marker = new SCH_MARKER();
276  marker->SetTimeStamp( GetNewTimeStamp() );
277  marker->SetData( ERCE_DIFFERENT_UNIT_FP, unit->GetPosition(),
278  wxString::Format( _( "Unit %s has '%s' assigned, "
279  "whereas unit %s has '%s' assigned" ), unitName, fp, curUnitName, curFp ),
280  unit->GetPosition() );
281  marker->SetMarkerType( MARKER_BASE::MARKER_ERC );
282  marker->SetErrorLevel( MARKER_BASE::MARKER_SEVERITY_WARNING );
283  ref.GetSheetPath().LastScreen()->Append( marker );
284 
285  ++errors;
286  }
287  }
288  }
289 
290  return errors;
291 }
SCH_SCREEN * LastScreen() const
Function LastScreen.
Field Name Module PCB, i.e. "16DIP300".
timestamp_t GetNewTimeStamp()
Definition: common.cpp:212
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
#define ERCE_DIFFERENT_UNIT_FP
Definition: erc.h:63
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:143
int GetUnit() const
Class SCH_SHEET_PATH.
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:162
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:69
wxPoint GetPosition() const override
Function GetPosition.
SCH_COMPONENT * GetComp() const
Class SCH_REFERENCE is used as a helper to define a component&#39;s reference designator in a schematic...
const SCH_SHEET_PATH & GetSheetPath() const
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 430 of file erc.cpp.

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().

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

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().

584 {
585  wxString msg;
586 
587  wxFFile file( aFullFileName, wxT( "wt" ) );
588 
589  if( !file.IsOpened() )
590  return false;
591 
592  msg = _( "ERC report" );
593  msg << wxT(" (") << DateAndTime() << wxT( ", " )
594  << _( "Encoding UTF8" ) << wxT( " )\n" );
595 
596  int err_count = 0;
597  int warn_count = 0;
598  int total_count = 0;
599  SCH_SHEET_LIST sheetList( g_RootSheet );
600 
601  for( unsigned i = 0; i < sheetList.size(); i++ )
602  {
603  msg << wxString::Format( _( "\n***** Sheet %s\n" ),
604  GetChars( sheetList[i].PathHumanReadable() ) );
605 
606  for( SCH_ITEM* item = sheetList[i].LastDrawList(); item != NULL; item = item->Next() )
607  {
608  if( item->Type() != SCH_MARKER_T )
609  continue;
610 
611  SCH_MARKER* marker = (SCH_MARKER*) item;
612 
613  if( marker->GetMarkerType() != MARKER_BASE::MARKER_ERC )
614  continue;
615 
616  total_count++;
617 
619  err_count++;
620 
622  warn_count++;
623 
624  msg << marker->GetReporter().ShowReport( aUnits );
625  }
626  }
627 
628  msg << wxString::Format( _( "\n ** ERC messages: %d Errors %d Warnings %d\n" ),
629  total_count, err_count, warn_count );
630 
631  // Currently: write report using UTF8 (as usual in Kicad).
632  // TODO: see if we can use the current encoding page (mainly for Windows users),
633  // Or other format (HTML?)
634  file.Write( msg );
635 
636  // wxFFile dtor will close the file.
637 
638  return true;
639 }
Class SCH_SHEET_LIST.
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:201
SCH_ITEM * Next() const
enum TYPEMARKER GetMarkerType() const
Definition: marker_base.h:164
MARKER_SEVERITY GetErrorLevel() const
Definition: marker_base.h:152
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:56
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:220
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:92
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
size_t i
Definition: json11.cpp:597
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
wxString DateAndTime()
Function DateAndTime.
Definition: string.cpp:306

Variable Documentation

const wxString CommentERC_H[]
Initial value:
=
{
_( "Input Pin" ),
_( "Output Pin" ),
_( "Bidirectional Pin" ),
_( "Tri-State Pin" ),
_( "Passive Pin" ),
_( "Unspecified Pin" ),
_( "Power Input Pin" ),
_( "Power Output Pin" ),
_( "Open Collector" ),
_( "Open Emitter" ),
_( "No Connection" )
}

Definition at line 87 of file erc.cpp.

Referenced by DIALOG_ERC::ReBuildMatrixPanel().

const wxString CommentERC_V[]
Initial value:
=
{
_( "Input Pin" ),
_( "Output Pin" ),
_( "Bidirectional Pin" ),
_( "Tri-State Pin" ),
_( "Passive Pin" ),
_( "Unspecified Pin" ),
_( "Power Input Pin" ),
_( "Power Output Pin" ),
_( "Open Collector" ),
_( "Open Emitter" ),
_( "No Connection" )
}

Definition at line 103 of file erc.cpp.

Referenced by DIALOG_ERC::ReBuildMatrixPanel().

int DefaultDiagErc[PINTYPE_COUNT][PINTYPE_COUNT]
Initial value:
=
{
{ OK, OK, OK, OK, OK, WAR, OK, OK, OK, OK, ERR },
{ OK, ERR, OK, WAR, OK, WAR, OK, ERR, ERR, ERR, ERR },
{ OK, OK, OK, OK, OK, WAR, OK, WAR, OK, WAR, ERR },
{ OK, WAR, OK, OK, OK, WAR, WAR, ERR, WAR, WAR, ERR },
{ OK, OK, OK, OK, OK, WAR, OK, OK, OK, OK, ERR },
{ WAR, WAR, WAR, WAR, WAR, WAR, WAR, WAR, WAR, WAR, ERR },
{ OK, OK, OK, WAR, OK, WAR, OK, OK, OK, OK, ERR },
{ OK, ERR, WAR, ERR, OK, WAR, OK, ERR, ERR, ERR, ERR },
{ OK, ERR, OK, WAR, OK, WAR, OK, ERR, OK, OK, ERR },
{ OK, ERR, WAR, WAR, OK, WAR, OK, ERR, OK, OK, ERR },
{ ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR, ERR }
}
Definition: erc.h:43
Definition: erc.h:42
Definition: erc.h:44

Default Look up table which gives the ERC error level for a pair of connected pins Same as DiagErc, but cannot be modified.

Used to init or reset DiagErc note also, to avoid inconsistancy: DefaultDiagErc[i][j] = DefaultDiagErc[j][i]

Definition at line 133 of file erc.cpp.

Referenced by DIALOG_ERC::ReBuildMatrixPanel(), and DIALOG_ERC::ResetDefaultERCDiag().

int MinimalReq[PINTYPE_COUNT][PINTYPE_COUNT]
static
Initial value:
=
{
{ NOD, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
{ DRV, DRV, DRV, DRV, DRV, DRV, DRV, DRV, DRV, DRV, NPI },
{ DRV, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
{ DRV, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
{ DRV, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
{ DRV, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
{ NOD, DRV, NOD, NOD, NOD, NOD, NOD, DRV, NOD, NOD, NPI },
{ DRV, DRV, DRV, DRV, DRV, DRV, DRV, DRV, DRV, DRV, NPI },
{ DRV, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
{ DRV, DRV, DRV, DRV, DRV, DRV, NOD, DRV, DRV, DRV, NPI },
{ NPI, NPI, NPI, NPI, NPI, NPI, NPI, NPI, NPI, NPI, NPI }
}
#define DRV
Definition: erc.h:70
#define NPI
Definition: erc.h:69
#define NOD
Definition: erc.h:72

Look up table which gives the minimal drive for a pair of connected pins on a net.

The initial state of a net is NOC (Net with No Connection). It can be updated to NPI (Pin Isolated), NET_NC (Net with a no connect symbol), NOD (Not Driven) or DRV (DRIven). It can be updated to NET_NC with no error only if there is only one pin in net. Nets are OK when their final state is NET_NC or DRV. Nets with the state NOD have no valid source signal.

Definition at line 160 of file erc.cpp.

Referenced by TestOthersItems().