KiCad PCB EDA Suite
ERC_TESTER Class Reference

#include <erc.h>

Public Member Functions

 ERC_TESTER (SCHEMATIC *aSchematic)
 
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)
 inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated). More...
 
void TestTextVars (KIGFX::WS_PROXY_VIEW_ITEM *aWorksheet)
 Checks for any unresolved text variable references. More...
 
int TestConflictingBusAliases ()
 Checks that there are not conflicting bus alias definitions in the schematic. More...
 
int TestMultiunitFootprints ()
 Test if all units of each multiunit component have the same footprint assigned. More...
 
int TestNoConnectPins ()
 In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type. More...
 

Private Member Functions

void diagnose (NETLIST_OBJECT *NetItemRef, NETLIST_OBJECT *NetItemTst, int MinConnexion, PIN_ERROR Diag)
 Performs ERC testing and creates an ERC marker to show the ERC problem for aNetItemRef or between aNetItemRef and aNetItemTst. More...
 

Private Attributes

SCHEMATICm_schematic
 

Detailed Description

Definition at line 51 of file erc.h.

Constructor & Destructor Documentation

◆ ERC_TESTER()

ERC_TESTER::ERC_TESTER ( SCHEMATIC aSchematic)
inline

Definition at line 55 of file erc.h.

55  :
56  m_schematic( aSchematic )
57  {
58  }
SCHEMATIC * m_schematic
Definition: erc.h:118

Member Function Documentation

◆ diagnose()

void ERC_TESTER::diagnose ( NETLIST_OBJECT NetItemRef,
NETLIST_OBJECT NetItemTst,
int  MinConnexion,
PIN_ERROR  Diag 
)
private

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

357 {
358  if( aDiag == PIN_ERROR::OK || aMinConn < 1 || aNetItemRef->m_Type != NETLIST_ITEM::PIN )
359  return;
360 
361  ERC_SETTINGS& settings = m_schematic->ErcSettings();
362 
363  SCH_PIN* pin = static_cast<SCH_PIN*>( aNetItemRef->m_Comp );
364 
365  if( aNetItemTst == NULL)
366  {
367  if( aMinConn == NOD ) /* Nothing driving the net. */
368  {
370  {
372  ercItem->SetItems( pin );
373 
374  SCH_MARKER* marker = new SCH_MARKER( ercItem, aNetItemRef->m_Start );
375  aNetItemRef->m_SheetPath.LastScreen()->Append( marker );
376  }
377  return;
378  }
379  }
380 
381  if( aNetItemTst && aNetItemTst->m_Type == NETLIST_ITEM::PIN ) /* Error between 2 pins */
382  {
384  {
385  ERC_ITEM* ercItem = ERC_ITEM::Create(
387  ercItem->SetItems( pin, static_cast<SCH_PIN*>( aNetItemTst->m_Comp ) );
388 
389  SCH_MARKER* marker = new SCH_MARKER( ercItem, aNetItemRef->m_Start );
390  aNetItemRef->m_SheetPath.LastScreen()->Append( marker );
391  }
392  }
393 }
#define NOD
Definition: erc_settings.h:78
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:115
int GetSeverity(int aErrorCode) const
#define NULL
Container for ERC settings.
Definition: erc_settings.h:87
static ERC_ITEM * Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:144
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:145
SCHEMATIC * m_schematic
Definition: erc.h:118

References SCH_SCREEN::Append(), ERC_ITEM::Create(), ERCE_PIN_NOT_DRIVEN, ERCE_PIN_TO_PIN_ERROR, ERCE_PIN_TO_PIN_WARNING, SCHEMATIC::ErcSettings(), ERC_SETTINGS::GetSeverity(), SCH_SHEET_PATH::LastScreen(), NETLIST_OBJECT::m_Comp, m_schematic, NETLIST_OBJECT::m_SheetPath, NETLIST_OBJECT::m_Start, NETLIST_OBJECT::m_Type, NOD, NULL, OK, PIN, PP_ERROR, RPT_SEVERITY_IGNORE, and RC_ITEM::SetItems().

Referenced by TestOthersItems().

◆ TestConflictingBusAliases()

int ERC_TESTER::TestConflictingBusAliases ( )

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)

Returns
the error count

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

249 {
250  wxString msg;
251  int err_count = 0;
252 
253  SCH_SCREENS screens( m_schematic->Root() );
254  std::vector< std::shared_ptr<BUS_ALIAS> > aliases;
255 
256  for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
257  {
258  std::unordered_set< std::shared_ptr<BUS_ALIAS> > screen_aliases = screen->GetBusAliases();
259 
260  for( const std::shared_ptr<BUS_ALIAS>& alias : screen_aliases )
261  {
262  for( const std::shared_ptr<BUS_ALIAS>& test : aliases )
263  {
264  if( alias->GetName() == test->GetName() && alias->Members() != test->Members() )
265  {
266  msg.Printf( _( "Bus alias %s has conflicting definitions on %s and %s" ),
267  alias->GetName(),
268  alias->GetParent()->GetFileName(),
269  test->GetParent()->GetFileName() );
270 
272  ercItem->SetErrorMessage( msg );
273 
274  SCH_MARKER* marker = new SCH_MARKER( ercItem, wxPoint() );
275  test->GetParent()->Append( marker );
276 
277  ++err_count;
278  }
279  }
280  }
281 
282  aliases.insert( aliases.end(), screen_aliases.begin(), screen_aliases.end() );
283  }
284 
285  return err_count;
286 }
#define NULL
static ERC_ITEM * Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:144
SCH_SHEET & Root() const
Definition: schematic.h:97
#define _(s)
Definition: 3d_actions.cpp:33
void SetErrorMessage(const wxString &aMessage)
Definition: rc_item.h:113
SCHEMATIC * m_schematic
Definition: erc.h:118
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:528

References _, ERC_ITEM::Create(), ERCE_BUS_ALIAS_CONFLICT, m_schematic, NULL, SCHEMATIC::Root(), and RC_ITEM::SetErrorMessage().

Referenced by DIALOG_ERC::TestErc().

◆ TestDuplicateSheetNames()

int ERC_TESTER::TestDuplicateSheetNames ( bool  aCreateMarker)

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

102 {
103  SCH_SCREEN* screen;
104  int err_count = 0;
105 
106  SCH_SCREENS screenList( m_schematic->Root() );
107 
108  for( screen = screenList.GetFirst(); screen != nullptr; screen = screenList.GetNext() )
109  {
110  std::vector<SCH_SHEET*> list;
111 
112  for( SCH_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
113  list.push_back( static_cast<SCH_SHEET*>( item ) );
114 
115  for( size_t i = 0; i < list.size(); i++ )
116  {
117  SCH_SHEET* sheet = list[i];
118 
119  for( size_t j = i + 1; j < list.size(); j++ )
120  {
121  SCH_SHEET* test_item = list[j];
122 
123  // We have found a second sheet: compare names
124  // we are using case insensitive comparison to avoid mistakes between
125  // similar names like Mysheet and mysheet
126  if( sheet->GetName().CmpNoCase( test_item->GetName() ) == 0 )
127  {
128  if( aCreateMarker )
129  {
131  ercItem->SetItems( sheet, test_item );
132 
133  SCH_MARKER* marker = new SCH_MARKER( ercItem, sheet->GetPosition() );
134  screen->Append( marker );
135  }
136 
137  err_count++;
138  }
139  }
140  }
141  }
142 
143  return err_count;
144 }
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:115
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
wxString GetName() const
Definition: sch_sheet.h:280
wxPoint GetPosition() const override
Definition: sch_sheet.h:570
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
static ERC_ITEM * Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:144
SCH_SHEET & Root() const
Definition: schematic.h:97
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:132
EE_RTREE & Items()
Definition: sch_screen.h:158
SCHEMATIC * m_schematic
Definition: erc.h:118
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:528

References SCH_SCREEN::Append(), ERC_ITEM::Create(), ERCE_DUPLICATE_SHEET_NAME, SCH_SHEET::GetName(), SCH_SHEET::GetPosition(), SCH_SCREEN::Items(), m_schematic, EE_RTREE::OfType(), SCHEMATIC::Root(), SCH_SHEET_T, and RC_ITEM::SetItems().

Referenced by SCH_EDIT_FRAME::ReadyToNetlist(), and DIALOG_ERC::TestErc().

◆ TestMultiunitFootprints()

int ERC_TESTER::TestMultiunitFootprints ( )

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

Returns
The error count.

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

290 {
292 
293  int errors = 0;
294  std::map<wxString, LIB_ID> footprints;
296  sheets.GetMultiUnitComponents( refMap, true );
297 
298  for( auto& component : refMap )
299  {
300  auto& refList = component.second;
301 
302  if( refList.GetCount() == 0 )
303  {
304  wxFAIL; // it should not happen
305  continue;
306  }
307 
308  // Reference footprint
309  SCH_COMPONENT* unit = nullptr;
310  wxString unitName;
311  wxString unitFP;
312 
313  for( unsigned i = 0; i < component.second.GetCount(); ++i )
314  {
315  SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
316  unitFP = refList.GetItem( i ).GetComp()->GetField( FOOTPRINT )->GetText();
317 
318  if( !unitFP.IsEmpty() )
319  {
320  unit = refList.GetItem( i ).GetComp();
321  unitName = unit->GetRef( &sheetPath, true );
322  break;
323  }
324  }
325 
326  for( unsigned i = 0; i < component.second.GetCount(); ++i )
327  {
328  SCH_REFERENCE& secondRef = refList.GetItem( i );
329  SCH_COMPONENT* secondUnit = secondRef.GetComp();
330  wxString secondName = secondUnit->GetRef( &secondRef.GetSheetPath(), true );
331  const wxString secondFp = secondUnit->GetField( FOOTPRINT )->GetText();
332  wxString msg;
333 
334  if( !secondFp.IsEmpty() && unitFP != secondFp )
335  {
336  msg.Printf( _( "Different footprints assigned to %s and %s" ),
337  unitName, secondName );
338 
340  ercItem->SetErrorMessage( msg );
341  ercItem->SetItems( unit, secondUnit );
342 
343  SCH_MARKER* marker = new SCH_MARKER( ercItem, secondUnit->GetPosition() );
344  secondRef.GetSheetPath().LastScreen()->Append( marker );
345 
346  ++errors;
347  }
348  }
349  }
350 
351  return errors;
352 }
SCH_SHEET_LIST.
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:92
const SCH_SHEET_PATH & GetSheetPath() const
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:115
SCH_COMPONENT * GetComp() const
Field Name Module PCB, i.e. "16DIP300".
void GetMultiUnitComponents(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true) const
Function GetMultiUnitComponents adds a SCH_REFERENCE_LIST object to aRefList for each same-reference ...
SCH_SHEET_PATH.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false)
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...
SCH_FIELD * GetField(int aFieldNdx)
Returns a field in this symbol.
static ERC_ITEM * Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:144
SCH_SCREEN * LastScreen()
Function LastScreen.
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:132
#define _(s)
Definition: 3d_actions.cpp:33
Schematic symbol object.
Definition: sch_component.h:88
wxPoint GetPosition() const override
void SetErrorMessage(const wxString &aMessage)
Definition: rc_item.h:113
SCHEMATIC * m_schematic
Definition: erc.h:118
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127
SCH_REFERENCE is used as a helper to define a component's reference designator in a schematic.

References _, SCH_SCREEN::Append(), ERC_ITEM::Create(), ERCE_DIFFERENT_UNIT_FP, FOOTPRINT, SCH_REFERENCE::GetComp(), SCH_COMPONENT::GetField(), SCH_SHEET_LIST::GetMultiUnitComponents(), SCH_COMPONENT::GetPosition(), SCH_COMPONENT::GetRef(), SCH_REFERENCE::GetSheetPath(), SCHEMATIC::GetSheets(), EDA_TEXT::GetText(), SCH_SHEET_PATH::LastScreen(), m_schematic, RC_ITEM::SetErrorMessage(), and RC_ITEM::SetItems().

Referenced by DIALOG_ERC::TestErc().

◆ TestNoConnectPins()

int ERC_TESTER::TestNoConnectPins ( )

In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.

In KiCad 6, this no longer results in those pins joining the net, so we need to warn about it

Returns
the error count

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

536 {
537  int err_count = 0;
538 
539  for( const SCH_SHEET_PATH& sheet : m_schematic->GetSheets() )
540  {
541  std::map<wxPoint, std::vector<SCH_PIN*>> pinMap;
542 
543  for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
544  {
545  SCH_COMPONENT* comp = static_cast<SCH_COMPONENT*>( item );
546 
547  for( SCH_PIN* pin : comp->GetSchPins( &sheet ) )
548  {
549  if( pin->GetLibPin()->GetType() == ELECTRICAL_PINTYPE::PT_NC )
550  pinMap[pin->GetPosition()].emplace_back( pin );
551  }
552  }
553 
554  for( auto& pair : pinMap )
555  {
556  if( pair.second.size() > 1 )
557  {
558  err_count++;
559 
561 
562  ercItem->SetItems( pair.second[0], pair.second[1],
563  pair.second.size() > 2 ? pair.second[2] : nullptr,
564  pair.second.size() > 3 ? pair.second[3] : nullptr );
565  ercItem->SetErrorMessage( _( "Pins with \"no connection\" type are connected" ) );
566 
567  SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
568  sheet.LastScreen()->Append( marker );
569  }
570  }
571  }
572 
573  return err_count;
574 }
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:92
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:115
SCH_SHEET_PATH.
static ERC_ITEM * Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:144
#define _(s)
Definition: 3d_actions.cpp:33
Schematic symbol object.
Definition: sch_component.h:88
void SetErrorMessage(const wxString &aMessage)
Definition: rc_item.h:113
SCHEMATIC * m_schematic
Definition: erc.h:118
not connected (must be left open)
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
SCH_PIN_PTRS GetSchPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieves a list of the SCH_PINs for the given sheet path.

References _, ERC_ITEM::Create(), ERCE_NOCONNECT_CONNECTED, SCH_COMPONENT::GetSchPins(), SCHEMATIC::GetSheets(), m_schematic, PT_NC, SCH_COMPONENT_T, RC_ITEM::SetErrorMessage(), and RC_ITEM::SetItems().

Referenced by DIALOG_ERC::TestErc().

◆ TestOthersItems()

void ERC_TESTER::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 396 of file eeschema/erc.cpp.

398 {
399  ERC_SETTINGS& settings = m_schematic->ErcSettings();
400 
401  unsigned netItemTst = aNetStart;
403  PIN_ERROR erc = PIN_ERROR::OK;
404 
405  /* Analysis of the table of connections. */
406  ELECTRICAL_PINTYPE ref_elect_type = aList->GetItem( aNetItemRef )->m_ElectricalPinType;
407  int local_minconn = NOC;
408 
409  if( ref_elect_type == ELECTRICAL_PINTYPE::PT_NC )
410  local_minconn = NPI;
411 
412  /* Test pins connected to NetItemRef */
413  for( ; ; netItemTst++ )
414  {
415  if( aNetItemRef == netItemTst )
416  continue;
417 
418  // We examine only a given net. We stop the search if the net changes
419  if( ( netItemTst >= aList->size() ) // End of list
420  || ( aList->GetItemNet( aNetItemRef ) !=
421  aList->GetItemNet( netItemTst ) ) ) // End of net
422  {
423  /* End net code found: minimum connection test. */
424  if( ( *aMinConnexion < NET_NC ) && ( local_minconn < NET_NC ) )
425  {
426  /* Not connected or not driven pin. */
427  bool seterr = true;
428 
429  if( local_minconn == NOC && aList->GetItemType( aNetItemRef ) == NETLIST_ITEM::PIN )
430  {
431  /* This pin is not connected: for multiple part per
432  * package, and duplicated pin,
433  * search for another instance of this pin
434  * this will be flagged only if all instances of this pin
435  * are not connected
436  * TODO test also if instances connected are connected to
437  * the same net
438  */
439  for( unsigned duplicate = 0; duplicate < aList->size(); duplicate++ )
440  {
441  if( aList->GetItemType( duplicate ) != NETLIST_ITEM::PIN )
442  continue;
443 
444  if( duplicate == aNetItemRef )
445  continue;
446 
447  if( aList->GetItem( aNetItemRef )->m_PinNum !=
448  aList->GetItem( duplicate )->m_PinNum )
449  continue;
450 
451  if( ( (SCH_COMPONENT*) aList->GetItem( aNetItemRef )->
452  m_Link )->GetRef( &aList->GetItem( aNetItemRef )-> m_SheetPath ) !=
453  ( (SCH_COMPONENT*) aList->GetItem( duplicate )->m_Link )
454  ->GetRef( &aList->GetItem( duplicate )->m_SheetPath ) )
455  continue;
456 
457  // Same component and same pin. Do dot create error for this pin
458  // if the other pin is connected (i.e. if duplicate net has another
459  // item)
460  if( (duplicate > 0)
461  && ( aList->GetItemNet( duplicate ) ==
462  aList->GetItemNet( duplicate - 1 ) ) )
463  seterr = false;
464 
465  if( (duplicate < aList->size() - 1)
466  && ( aList->GetItemNet( duplicate ) ==
467  aList->GetItemNet( duplicate + 1 ) ) )
468  seterr = false;
469  }
470  }
471 
472  if( seterr )
473  {
474  diagnose( aList->GetItem( aNetItemRef ), nullptr, local_minconn,
476  }
477 
478  *aMinConnexion = DRV; // inhibiting other messages of this
479  // type for the net.
480  }
481  return;
482  }
483 
484  switch( aList->GetItemType( netItemTst ) )
485  {
488  case NETLIST_ITEM::BUS:
490  case NETLIST_ITEM::LABEL:
499  break;
500 
502  local_minconn = std::max( NET_NC, local_minconn );
503  break;
504 
505  case NETLIST_ITEM::PIN:
506  jj = aList->GetItem( netItemTst )->m_ElectricalPinType;
507  local_minconn = std::max( settings.GetPinMinDrive( ref_elect_type, jj ),
508  local_minconn );
509 
510  if( netItemTst <= aNetItemRef )
511  break;
512 
513  if( erc == PIN_ERROR::OK )
514  {
515  erc = settings.GetPinMapValue( ref_elect_type, jj );
516 
517  if( erc != PIN_ERROR::OK )
518  {
519  if( aList->GetConnectionType( netItemTst ) == NET_CONNECTION::UNCONNECTED )
520  {
521  aList->SetConnectionType( netItemTst,
523  }
524 
525  diagnose( aList->GetItem( aNetItemRef ), aList->GetItem( netItemTst ), 1, erc );
526  }
527  }
528 
529  break;
530  }
531  }
532 }
int GetPinMinDrive(ELECTRICAL_PINTYPE aFirstType, ELECTRICAL_PINTYPE aSecondType) const
Definition: erc_settings.h:150
#define NOC
Definition: erc_settings.h:79
#define NET_NC
Definition: erc_settings.h:77
void diagnose(NETLIST_OBJECT *NetItemRef, NETLIST_OBJECT *NetItemTst, int MinConnexion, PIN_ERROR Diag)
Performs ERC testing and creates an ERC marker to show the ERC problem for aNetItemRef or between aNe...
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
Definition: erc_settings.h:66
SCH_SHEET_PATH m_SheetPath
ELECTRICAL_PINTYPE m_ElectricalPinType
int GetItemNet(unsigned aIdx) const
Acces to an item net code.
Container for ERC settings.
Definition: erc_settings.h:87
NETLIST_ITEM GetItemType(unsigned aIdx) const
Acces to an item type.
#define NPI
Types of drive on a net (used for legacy ERC)
Definition: erc_settings.h:75
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
ELECTRICAL_PINTYPE
The component library pin object electrical types used in ERC tests.
Definition: pin_type.h:37
Schematic symbol object.
Definition: sch_component.h:88
PIN_ERROR GetPinMapValue(int aFirstType, int aSecondType) const
Definition: erc_settings.h:125
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)
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:145
SCHEMATIC * m_schematic
Definition: erc.h:118
not connected (must be left open)
SCH_ITEM * m_Link
#define DRV
Definition: erc_settings.h:76

References BUS, BUSLABELMEMBER, diagnose(), DRV, SCHEMATIC::ErcSettings(), NETLIST_OBJECT_LIST::GetConnectionType(), NETLIST_OBJECT_LIST::GetItem(), NETLIST_OBJECT_LIST::GetItemNet(), NETLIST_OBJECT_LIST::GetItemType(), ERC_SETTINGS::GetPinMapValue(), ERC_SETTINGS::GetPinMinDrive(), GLOBBUSLABELMEMBER, GLOBLABEL, HIERBUSLABELMEMBER, HIERLABEL, ITEM_UNSPECIFIED, JUNCTION, LABEL, NETLIST_OBJECT::m_ElectricalPinType, NETLIST_OBJECT::m_Link, NETLIST_OBJECT::m_PinNum, m_schematic, NETLIST_OBJECT::m_SheetPath, NET_NC, NOC, NOCONNECT, NOCONNECT_SYMBOL_PRESENT, NPI, OK, PIN, PINLABEL, PT_NC, SEGMENT, NETLIST_OBJECT_LIST::SetConnectionType(), SHEETBUSLABELMEMBER, SHEETLABEL, UNCONNECTED, and WARNING.

Referenced by DIALOG_ERC::TestErc().

◆ TestTextVars()

void ERC_TESTER::TestTextVars ( KIGFX::WS_PROXY_VIEW_ITEM aWorksheet)

Checks for any unresolved text variable references.

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

148 {
149  WS_DRAW_ITEM_LIST wsItems;
150 
151  auto unresolved = [this]( wxString str )
152  {
153  str = ExpandEnvVarSubstitutions( str, &m_schematic->Prj() );
154  return str.Matches( wxT( "*${*}*" ) );
155  };
156 
157  if( aWorksheet )
158  {
159  wsItems.SetMilsToIUfactor( IU_PER_MILS );
160  wsItems.BuildWorkSheetGraphicList( aWorksheet->GetPageInfo(), aWorksheet->GetTitleBlock() );
161  }
162 
163  SCH_SCREENS screens( m_schematic->Root() );
164 
165  for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() )
166  {
167  for( SCH_ITEM* item : screen->Items().OfType( SCH_LOCATE_ANY_T ) )
168  {
169  if( item->Type() == SCH_COMPONENT_T )
170  {
171  SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
172 
173  for( SCH_FIELD& field : component->GetFields() )
174  {
175  if( unresolved( field.GetShownText() ) )
176  {
177  wxPoint pos = field.GetPosition() - component->GetPosition();
178  pos = component->GetTransform().TransformCoordinate( pos );
179  pos += component->GetPosition();
180 
182  ercItem->SetItems( &field );
183 
184  SCH_MARKER* marker = new SCH_MARKER( ercItem, pos );
185  screen->Append( marker );
186  }
187  }
188  }
189  else if( item->Type() == SCH_SHEET_T )
190  {
191  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
192 
193  for( SCH_FIELD& field : sheet->GetFields() )
194  {
195  if( unresolved( field.GetShownText() ) )
196  {
198  ercItem->SetItems( &field );
199 
200  SCH_MARKER* marker = new SCH_MARKER( ercItem, field.GetPosition() );
201  screen->Append( marker );
202  }
203  }
204 
205  for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
206  {
207  if( pin->GetShownText().Matches( wxT( "*${*}*" ) ) )
208  {
210  ercItem->SetItems( pin );
211 
212  SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() );
213  screen->Append( marker );
214  }
215  }
216  }
217  else if( SCH_TEXT* text = dynamic_cast<SCH_TEXT*>( item ) )
218  {
219  if( text->GetShownText().Matches( wxT( "*${*}*" ) ) )
220  {
222  ercItem->SetItems( text );
223 
224  SCH_MARKER* marker = new SCH_MARKER( ercItem, text->GetPosition() );
225  screen->Append( marker );
226  }
227  }
228  }
229 
230  for( WS_DRAW_ITEM_BASE* item = wsItems.GetFirst(); item; item = wsItems.GetNext() )
231  {
232  if( WS_DRAW_ITEM_TEXT* text = dynamic_cast<WS_DRAW_ITEM_TEXT*>( item ) )
233  {
234  if( text->GetShownText().Matches( wxT( "*${*}*" ) ) )
235  {
237  ercItem->SetErrorMessage( _( "Unresolved text variable in worksheet." ) );
238 
239  SCH_MARKER* marker = new SCH_MARKER( ercItem, text->GetPosition() );
240  screen->Append( marker );
241  }
242  }
243  }
244  }
245 }
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
void SetItems(EDA_ITEM *aItem, EDA_ITEM *bItem=nullptr, EDA_ITEM *cItem=nullptr, EDA_ITEM *dItem=nullptr)
Definition: rc_item.h:115
WS_DRAW_ITEM_BASE * GetNext()
Definition: ws_draw_item.h:480
WS_DRAW_ITEM_BASE * GetFirst()
Definition: ws_draw_item.h:470
const wxString ExpandEnvVarSubstitutions(const wxString &aString, PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:574
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:42
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populates a std::vector with SCH_FIELDs.
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:268
#define NULL
void BuildWorkSheetGraphicList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock)
Function BuildWorkSheetGraphicList is a core function for drawing or plotting the page layout with th...
TRANSFORM & GetTransform() const
void SetMilsToIUfactor(double aScale)
Function SetMilsToIUfactor Set the scalar to convert pages units (mils) to draw/plot units.
Definition: ws_draw_item.h:436
const TITLE_BLOCK & GetTitleBlock()
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:84
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
static ERC_ITEM * Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:144
SCH_SHEET & Root() const
Definition: schematic.h:97
#define _(s)
Definition: 3d_actions.cpp:33
Schematic symbol object.
Definition: sch_component.h:88
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:77
wxPoint GetPosition() const override
#define IU_PER_MILS
Definition: plotter.cpp:138
void SetErrorMessage(const wxString &aMessage)
Definition: rc_item.h:113
SCHEMATIC * m_schematic
Definition: erc.h:118
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:187
const PAGE_INFO & GetPageInfo()
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:528

References _, WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList(), ERC_ITEM::Create(), ERCE_UNRESOLVED_VARIABLE, ExpandEnvVarSubstitutions(), SCH_SHEET::GetFields(), SCH_COMPONENT::GetFields(), WS_DRAW_ITEM_LIST::GetFirst(), WS_DRAW_ITEM_LIST::GetNext(), KIGFX::WS_PROXY_VIEW_ITEM::GetPageInfo(), SCH_COMPONENT::GetPosition(), KIGFX::WS_PROXY_VIEW_ITEM::GetTitleBlock(), SCH_COMPONENT::GetTransform(), IU_PER_MILS, m_schematic, NULL, SCHEMATIC::Prj(), SCHEMATIC::Root(), SCH_COMPONENT_T, SCH_LOCATE_ANY_T, SCH_SHEET_T, RC_ITEM::SetErrorMessage(), RC_ITEM::SetItems(), WS_DRAW_ITEM_LIST::SetMilsToIUfactor(), and TRANSFORM::TransformCoordinate().

Referenced by DIALOG_ERC::TestErc().

Member Data Documentation

◆ m_schematic


The documentation for this class was generated from the following files: