KiCad PCB EDA Suite
Loading...
Searching...
No Matches
erc.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <algorithm>
23#include <map>
24#include <numeric>
25#include <set>
26
27#include "connection_graph.h"
28#include "kiface_ids.h"
29#include <advanced_config.h>
30#include <common.h> // for ExpandEnvVarSubstitutions
31#include <erc/erc.h>
34#include <string_utils.h>
35#include <sch_pin.h>
36#include <project_sch.h>
39#include <sch_bus_entry.h>
40#include <sch_edit_frame.h>
41#include <sch_marker.h>
42#include <sch_reference_list.h>
43#include <sch_rule_area.h>
44#include <sch_sheet.h>
45#include <sch_sheet_pin.h>
46#include <sch_pin.h>
47#include <sch_textbox.h>
48#include <sch_line.h>
49#include <schematic.h>
50#include <lib_symbol.h>
51#include <sch_symbol.h>
52#include <pin_map.h>
55#include <vector>
56#include <wx/ffile.h>
57#include <sim/sim_lib_mgr.h>
58#include <progress_reporter.h>
59#include <kiway.h>
60#include <pgm_base.h>
62#include <trace_helpers.h>
64
65
66/* ERC tests :
67 * 1 - conflicts between connected pins ( example: 2 connected outputs )
68 * 2 - minimal connections requirements ( 1 input *must* be connected to an
69 * output, or a passive pin )
70 */
71
72/*
73 * Minimal ERC requirements:
74 * All pins *must* be connected (except ELECTRICAL_PINTYPE::PT_NC).
75 * When a pin is not connected in schematic, the user must place a "non
76 * connected" symbol to this pin.
77 * This ensures a forgotten connection will be detected.
78 */
79
80// Messages for matrix rows:
81const wxString CommentERC_H[] =
82{
83 _( "Input Pin" ),
84 _( "Output Pin" ),
85 _( "Bidirectional Pin" ),
86 _( "Tri-State Pin" ),
87 _( "Passive Pin" ),
88 _( "Free Pin" ),
89 _( "Unspecified Pin" ),
90 _( "Power Input Pin" ),
91 _( "Power Output Pin" ),
92 _( "Open Collector" ),
93 _( "Open Emitter" ),
94 _( "No Connection" )
95};
96
97// Messages for matrix columns
98const wxString CommentERC_V[] =
99{
100 _( "Input Pin" ),
101 _( "Output Pin" ),
102 _( "Bidirectional Pin" ),
103 _( "Tri-State Pin" ),
104 _( "Passive Pin" ),
105 _( "Free Pin" ),
106 _( "Unspecified Pin" ),
107 _( "Power Input Pin" ),
108 _( "Power Output Pin" ),
109 _( "Open Collector" ),
110 _( "Open Emitter" ),
111 _( "No Connection" )
112};
113
114
115// List of pin types that are considered drivers for usual input pins
116// i.e. pin type = ELECTRICAL_PINTYPE::PT_INPUT, but not PT_POWER_IN
117// that need only a PT_POWER_OUT pin type to be driven
126
127// List of pin types that are considered drivers for power pins
128// In fact only a ELECTRICAL_PINTYPE::PT_POWER_OUT pin type can drive
129// power input pins
130const std::set<ELECTRICAL_PINTYPE> DrivingPowerPinTypes =
131{
133};
134
135// List of pin types that require a driver elsewhere on the net
136const std::set<ELECTRICAL_PINTYPE> DrivenPinTypes =
137{
140};
141
142extern void CheckDuplicatePins( LIB_SYMBOL* aSymbol, std::vector<wxString>& aMessages,
143 UNITS_PROVIDER* aUnitsProvider );
144
145int ERC_TESTER::TestDuplicateSheetNames( bool aCreateMarker )
146{
147 int err_count = 0;
148
149 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
150 {
151 std::vector<SCH_SHEET*> list;
152
153 for( SCH_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
154 list.push_back( static_cast<SCH_SHEET*>( item ) );
155
156 for( size_t i = 0; i < list.size(); i++ )
157 {
158 SCH_SHEET* sheet = list[i];
159
160 for( size_t j = i + 1; j < list.size(); j++ )
161 {
162 SCH_SHEET* test_item = list[j];
163
164 // We have found a second sheet: compare names
165 // we are using case insensitive comparison to avoid mistakes between
166 // similar names like Mysheet and mysheet
167 if( sheet->GetShownName( false ).IsSameAs( test_item->GetShownName( false ), false ) )
168 {
169 if( aCreateMarker )
170 {
172 ercItem->SetItems( sheet, test_item );
173
174 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), sheet->GetPosition() );
175 screen->Append( marker );
176 }
177
178 err_count++;
179 }
180 }
181 }
182 }
183
184 return err_count;
185}
186
187
188int ERC_TESTER::TestPinMap( KIFACE* aCvPcb, PROJECT* aProject )
189{
190 int errors = 0;
191 const bool checkStale = m_settings.IsTestEnabled( ERCE_PIN_MAP_STALE_PIN );
192 const bool checkDuplicate = m_settings.IsTestEnabled( ERCE_PIN_MAP_DUPLICATE_PAD );
193 const bool checkBadPad = m_settings.IsTestEnabled( ERCE_PIN_MAP_BAD_PAD );
194
195 typedef void ( *PAD_NUMBERS_FN_PTR )( const wxString&, PROJECT*, std::set<wxString>& );
196
197 PAD_NUMBERS_FN_PTR padFetcher =
198 aCvPcb ? (PAD_NUMBERS_FN_PTR) aCvPcb->IfaceOrAddress( KIFACE_FOOTPRINT_PAD_NUMBERS ) : nullptr;
199
200 std::map<wxString, std::set<wxString>> padCache;
201
202 auto getPads = [&]( const wxString& aFootprintId ) -> const std::set<wxString>&
203 {
204 auto it = padCache.find( aFootprintId );
205
206 if( it != padCache.end() )
207 return it->second;
208
209 std::set<wxString>& pads = padCache[aFootprintId];
210
211 if( padFetcher && !aFootprintId.IsEmpty() )
212 padFetcher( aFootprintId, aProject, pads );
213
214 return pads;
215 };
216
217 // Pin maps and the symbol's pin numbers are library-symbol properties, so iterate unique
218 // screens (not sheet paths) to avoid double-reporting on reused hierarchical sheets.
219 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
220 {
221 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
222 {
223 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
224 LIB_SYMBOL* lib = symbol->GetLibSymbolRef().get();
225
226 if( !lib )
227 continue;
228
229 const PIN_MAP_SET& maps = lib->GetEffectivePinMaps();
230
231 if( maps.IsEmpty() )
232 continue;
233
234 std::set<wxString> pinNumbers;
235
236 for( const SCH_PIN* pin : lib->GetPins() )
237 pinNumbers.insert( pin->GetNumber() );
238
239 const std::vector<std::set<wxString>>& jumperGroups = lib->JumperPinGroups();
240
241 auto sharesJumperGroup = [&]( const wxString& aPinA, const wxString& aPinB )
242 {
243 for( const std::set<wxString>& group : jumperGroups )
244 {
245 if( group.count( aPinA ) && group.count( aPinB ) )
246 return true;
247 }
248
249 return false;
250 };
251
252 for( const PIN_MAP& map : maps.GetAll() )
253 {
254 if( checkStale )
255 {
256 for( const PIN_MAP_ENTRY& entry : map.GetEntries() )
257 {
258 if( pinNumbers.count( entry.m_PinNumber ) )
259 continue;
260
261 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_PIN_MAP_STALE_PIN );
262 ercItem->SetItems( symbol );
263 ercItem->SetErrorMessage(
264 wxString::Format( _( "Pin map '%s' references unknown symbol pin '%s'" ), map.GetName(),
265 entry.m_PinNumber ) );
266 screen->Append( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
267 errors++;
268 }
269 }
270
271 // A single pin stacked across several pads is allowed. Two pins on one pad is not.
272 if( checkDuplicate )
273 {
274 std::map<wxString, wxString> padToPin;
275
276 for( const PIN_MAP_ENTRY& entry : map.GetEntries() )
277 {
278 for( const wxString& pad : ExpandStackedPinNotation( entry.m_PadNumber ) )
279 {
280 auto it = padToPin.find( pad );
281
282 if( it == padToPin.end() )
283 {
284 padToPin[pad] = entry.m_PinNumber;
285 }
286 else if( it->second != entry.m_PinNumber
287 && !sharesJumperGroup( it->second, entry.m_PinNumber ) )
288 {
289 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_PIN_MAP_DUPLICATE_PAD );
290 ercItem->SetItems( symbol );
291 ercItem->SetErrorMessage(
292 wxString::Format( _( "Symbol pins '%s' and '%s' both map to pad '%s'" ),
293 it->second, entry.m_PinNumber, pad ) );
294 screen->Append( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
295 errors++;
296 }
297 }
298 }
299 }
300 }
301
302 if( checkBadPad && padFetcher )
303 {
304 for( const ASSOCIATED_FOOTPRINT& assoc : lib->GetEffectiveAssociatedFootprints() )
305 {
306 const PIN_MAP* boundMap = maps.FindByName( assoc.m_MapName );
307
308 if( !boundMap )
309 continue;
310
311 const std::set<wxString>& pads = getPads( assoc.m_FootprintLibId.GetUniStringLibId() );
312
313 if( pads.empty() )
314 continue;
315
316 for( const PIN_MAP_ENTRY& entry : boundMap->GetEntries() )
317 {
318 for( const wxString& pad : ExpandStackedPinNotation( entry.m_PadNumber ) )
319 {
320 if( pads.count( pad ) )
321 continue;
322
323 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_PIN_MAP_BAD_PAD );
324 ercItem->SetItems( symbol );
325 ercItem->SetErrorMessage( wxString::Format(
326 _( "Pin map '%s' references pad '%s' not present on footprint '%s'" ),
327 boundMap->GetName(), pad, assoc.m_FootprintLibId.GetUniStringLibId() ) );
328 screen->Append( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
329 errors++;
330 }
331 }
332 }
333 }
334 }
335 }
336
337 if( m_settings.IsTestEnabled( ERCE_PIN_MAP_UNMAPPED_PIN ) && padFetcher )
338 {
339 const wxString variant = m_schematic ? m_schematic->GetCurrentVariant() : wxString();
340
341 for( SCH_SHEET_PATH& sheet : m_sheetList )
342 {
343 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
344 {
345 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
346 LIB_SYMBOL* lib = symbol->GetLibSymbolRef().get();
347
348 if( !lib || lib->GetEffectiveAssociatedFootprints().empty() )
349 continue;
350
351 wxString fpText = symbol->GetFootprintFieldText( true, &sheet, false );
352 LIB_ID fpId;
353
354 if( fpText.IsEmpty() || fpId.Parse( fpText, true ) >= 0 )
355 continue;
356
357 const std::set<wxString>& pads = getPads( fpId.GetUniStringLibId() );
358
359 if( pads.empty() )
360 continue;
361
362 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
363 {
364 if( pin->IsDangling() )
365 continue;
366
367 SCH_PIN::PAD_RESOLUTION state = SCH_PIN::PAD_RESOLUTION::MAPPED;
368 pin->GetEffectivePadNumber( sheet, variant, fpId, &pads, &state );
369
370 if( state != SCH_PIN::PAD_RESOLUTION::UNMAPPED )
371 continue;
372
373 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_PIN_MAP_UNMAPPED_PIN );
374 ercItem->SetItems( pin );
375 ercItem->SetErrorMessage(
376 wxString::Format( _( "Pin '%s' is connected but maps to no pad on footprint '%s'" ),
377 pin->GetNumber(), fpText ) );
378 sheet.LastScreen()->Append( new SCH_MARKER( std::move( ercItem ), pin->GetPosition() ) );
379 errors++;
380 }
381 }
382 }
383 }
384
385 return errors;
386}
387
388
390{
392
393 auto unresolved =
394 [this]( wxString str )
395 {
396 str = ExpandEnvVarSubstitutions( str, &m_schematic->Project() );
397 return str.Matches( wxS( "*${*}*" ) );
398 };
399
400 auto testAssertion =
401 []( const SCH_ITEM* item, const SCH_SHEET_PATH& sheet, SCH_SCREEN* screen,
402 const wxString& text, const VECTOR2I& pos )
403 {
404 // Match anywhere in the text so users can embed ${ERC_ERROR ...}
405 // or ${ERC_WARNING ...} inside placeholder strings rather than
406 // only at the start of the field. The leading "(^|[^\\\\])"
407 // group requires the marker to start the string or follow a
408 // non-backslash, so `\${ERC_ERROR ...}` stays inert; the
409 // captured message is group 2.
410 static wxRegEx warningExpr( wxS( "(^|[^\\\\])\\$\\{ERC_WARNING\\s*([^}]*)\\}" ) );
411 static wxRegEx errorExpr( wxS( "(^|[^\\\\])\\$\\{ERC_ERROR\\s*([^}]*)\\}" ) );
412
413 auto reportEach =
414 [&]( wxRegEx& aExpr, int aErrorCode )
415 {
416 // Return true on any *match*, not only when a marker is appended,
417 // so the caller-side unresolved-variable suppression stays
418 // correct even if the limit-exceeded short-circuit lands here in
419 // the future.
420 bool found = false;
421 wxString remaining = text;
422
423 while( aExpr.Matches( remaining ) )
424 {
425 found = true;
426
427 wxString ercText = aExpr.GetMatch( remaining, 2 );
428
429 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( aErrorCode );
430
431 if( item )
432 ercItem->SetItems( item );
433 else
434 ercText += _( " (in drawing sheet)" );
435
436 ercItem->SetSheetSpecificPath( sheet );
437 ercItem->SetErrorMessage( ercText );
438
439 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pos );
440 screen->Append( marker );
441
442 size_t start = 0;
443 size_t len = 0;
444
445 if( !aExpr.GetMatch( &start, &len, 0 ) || len == 0 )
446 break;
447
448 remaining = remaining.Mid( start + len );
449 }
450
451 return found;
452 };
453
454 bool foundWarning = reportEach( warningExpr, ERCE_GENERIC_WARNING );
455 bool foundError = reportEach( errorExpr, ERCE_GENERIC_ERROR );
456
457 return foundWarning || foundError;
458 };
459
460 if( aDrawingSheet )
461 {
462 wsItems.SetPageNumber( wxS( "1" ) );
463 wsItems.SetSheetCount( 1 );
464 wsItems.SetFileName( wxS( "dummyFilename" ) );
465 wsItems.SetSheetName( wxS( "dummySheet" ) );
466 wsItems.SetSheetLayer( wxS( "dummyLayer" ) );
467 wsItems.SetProject( &m_schematic->Project() );
468 wsItems.BuildDrawItemsList( aDrawingSheet->GetPageInfo(), aDrawingSheet->GetTitleBlock() );
469 }
470
471 for( const SCH_SHEET_PATH& sheet : m_sheetList )
472 {
473 SCH_SCREEN* screen = sheet.LastScreen();
474
475 for( SCH_ITEM* item : screen->Items().OfType( SCH_LOCATE_ANY_T ) )
476 {
477 if( item->Type() == SCH_SYMBOL_T )
478 {
479 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
480
481 for( SCH_FIELD& field : symbol->GetFields() )
482 {
483 if( testAssertion( &field, sheet, screen, field.GetText(), field.GetPosition() ) )
484 {
485 // Don't run unresolved test
486 }
487 else if( unresolved( field.GetShownText( &sheet, true ) ) )
488 {
490 ercItem->SetItems( symbol );
491 ercItem->SetSheetSpecificPath( sheet );
492
493 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), field.GetPosition() );
494 screen->Append( marker );
495 }
496 }
497
498 if( symbol->GetLibSymbolRef() )
499 {
501 [&]( SCH_ITEM* child )
502 {
503 if( child->Type() == SCH_FIELD_T )
504 {
505 // test only SCH_SYMBOL fields, not LIB_SYMBOL fields
506 }
507 else if( child->Type() == SCH_TEXT_T )
508 {
509 SCH_TEXT* textItem = static_cast<SCH_TEXT*>( child );
510
511 if( testAssertion( symbol, sheet, screen, textItem->GetText(),
512 textItem->GetPosition() ) )
513 {
514 // Don't run unresolved test
515 }
516 else if( unresolved( textItem->GetShownText( &sheet, true ) ) )
517 {
519 ercItem->SetItems( symbol );
520 ercItem->SetSheetSpecificPath( sheet );
521
522 BOX2I bbox = textItem->GetBoundingBox();
523 bbox = symbol->GetTransform().TransformCoordinate( bbox );
524 VECTOR2I pos = bbox.Centre() + symbol->GetPosition();
525
526 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pos );
527 screen->Append( marker );
528 }
529 }
530 else if( child->Type() == SCH_TEXTBOX_T )
531 {
532 SCH_TEXTBOX* textboxItem = static_cast<SCH_TEXTBOX*>( child );
533
534 if( testAssertion( symbol, sheet, screen, textboxItem->GetText(),
535 textboxItem->GetPosition() ) )
536 {
537 // Don't run unresolved test
538 }
539 else if( unresolved( textboxItem->GetShownText( nullptr, &sheet,
540 true ) ) )
541 {
543 ercItem->SetItems( symbol );
544 ercItem->SetSheetSpecificPath( sheet );
545
546 BOX2I bbox = textboxItem->GetBoundingBox();
547 bbox = symbol->GetTransform().TransformCoordinate( bbox );
548 VECTOR2I pos = bbox.Centre() + symbol->GetPosition();
549
550 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pos );
551 screen->Append( marker );
552 }
553 }
554 },
556 }
557 }
558 else if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( item ) )
559 {
560 for( SCH_FIELD& field : label->GetFields() )
561 {
562 if( testAssertion( &field, sheet, screen, field.GetText(), field.GetPosition() ) )
563 {
564 // Don't run unresolved test
565 }
566 else if( unresolved( field.GetShownText( &sheet, true ) ) )
567 {
569 ercItem->SetItems( label );
570 ercItem->SetSheetSpecificPath( sheet );
571
572 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), field.GetPosition() );
573 screen->Append( marker );
574 }
575 }
576 }
577 else if( item->Type() == SCH_SHEET_T )
578 {
579 SCH_SHEET* subSheet = static_cast<SCH_SHEET*>( item );
580
581 for( SCH_FIELD& field : subSheet->GetFields() )
582 {
583 if( testAssertion( &field, sheet, screen, field.GetText(), field.GetPosition() ) )
584 {
585 // Don't run unresolved test
586 }
587 else if( unresolved( field.GetShownText( &sheet, true ) ) )
588 {
590 ercItem->SetItems( subSheet );
591 ercItem->SetSheetSpecificPath( sheet );
592
593 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), field.GetPosition() );
594 screen->Append( marker );
595 }
596 }
597
598 SCH_SHEET_PATH subSheetPath = sheet;
599 subSheetPath.push_back( subSheet );
600
601 for( SCH_SHEET_PIN* pin : subSheet->GetPins() )
602 {
603 if( pin->GetShownText( &subSheetPath, true ).Matches( wxS( "*${*}*" ) ) )
604 {
606 ercItem->SetItems( pin );
607 ercItem->SetSheetSpecificPath( sheet );
608
609 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
610 screen->Append( marker );
611 }
612 }
613 }
614 else if( SCH_TEXT* text = dynamic_cast<SCH_TEXT*>( item ) )
615 {
616 if( testAssertion( text, sheet, screen, text->GetText(), text->GetPosition() ) )
617 {
618 // Don't run unresolved test
619 }
620 else if( text->GetShownText( &sheet, true ).Matches( wxS( "*${*}*" ) ) )
621 {
623 ercItem->SetItems( text );
624 ercItem->SetSheetSpecificPath( sheet );
625
626 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), text->GetPosition() );
627 screen->Append( marker );
628 }
629 }
630 else if( SCH_TEXTBOX* textBox = dynamic_cast<SCH_TEXTBOX*>( item ) )
631 {
632 if( testAssertion( textBox, sheet, screen, textBox->GetText(),
633 textBox->GetPosition() ) )
634 {
635 // Don't run unresolved test
636 }
637 else if( textBox->GetShownText( nullptr, &sheet, true ).Matches( wxS( "*${*}*" ) ) )
638 {
640 ercItem->SetItems( textBox );
641 ercItem->SetSheetSpecificPath( sheet );
642
643 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), textBox->GetPosition() );
644 screen->Append( marker );
645 }
646 }
647 }
648
649 for( DS_DRAW_ITEM_BASE* item = wsItems.GetFirst(); item; item = wsItems.GetNext() )
650 {
651 if( DS_DRAW_ITEM_TEXT* text = dynamic_cast<DS_DRAW_ITEM_TEXT*>( item ) )
652 {
653 if( testAssertion( nullptr, sheet, screen, text->GetText(), text->GetPosition() ) )
654 {
655 // Don't run unresolved test
656 }
657 else if( text->GetShownText( true ).Matches( wxS( "*${*}*" ) ) )
658 {
659 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
660 ercItem->SetErrorMessage( _( "Unresolved text variable in drawing sheet" ) );
661 ercItem->SetSheetSpecificPath( sheet );
662
663 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), text->GetPosition() );
664 screen->Append( marker );
665 }
666 }
667 }
668 }
669}
670
671
673{
674 int errors = 0;
675
676 // No directive labels, they carry no text (the netclass lives in a field)
678
679 for( const SCH_SHEET_PATH& sheet : m_sheetList )
680 {
681 SCH_SCREEN* screen = sheet.LastScreen();
682
683 for( KICAD_T labelType : labelTypes )
684 {
685 for( SCH_ITEM* item : screen->Items().OfType( labelType ) )
686 {
687 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
688
689 wxString text = label->GetText();
690 text.Trim( false ).Trim( true );
691
692 if( text.IsEmpty() )
693 {
694 auto ercItem = ERC_ITEM::Create( ERCE_EMPTY_LABEL_NAME );
695 ercItem->SetItems( label );
696 ercItem->SetItemsSheetPaths( sheet );
697 ercItem->SetSheetSpecificPath( sheet );
698
699 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), label->GetPosition() );
700 screen->Append( marker );
701 errors++;
702 }
703 }
704 }
705 }
706
707 return errors;
708}
709
710
712{
713 int warnings = 0;
714
715 for( const SCH_SHEET_PATH& sheet : m_sheetList )
716 {
717 SCH_SCREEN* screen = sheet.LastScreen();
718
719 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
720 {
721 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
722
723 for( SCH_FIELD& field : symbol->GetFields() )
724 {
725 wxString trimmedFieldName = field.GetName();
726 trimmedFieldName.Trim();
727 trimmedFieldName.Trim( false );
728
729 if( field.GetName() != trimmedFieldName )
730 {
732 ercItem->SetItems( symbol, &field );
733 ercItem->SetItemsSheetPaths( sheet, sheet );
734 ercItem->SetSheetSpecificPath( sheet );
735 ercItem->SetErrorMessage(
736 wxString::Format(
737 _( "Field name has leading or trailing whitespace: '%s'" ),
738 field.GetName() ) );
739
740 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), field.GetPosition() );
741 screen->Append( marker );
742 warnings++;
743 }
744 }
745 }
746
747 for( SCH_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
748 {
749 SCH_SHEET* subSheet = static_cast<SCH_SHEET*>( item );
750
751 for( SCH_FIELD& field : subSheet->GetFields() )
752 {
753 wxString trimmedFieldName = field.GetName();
754 trimmedFieldName.Trim();
755 trimmedFieldName.Trim( false );
756
757 if( field.GetName() != trimmedFieldName )
758 {
760 ercItem->SetItems( subSheet, &field );
761 ercItem->SetItemsSheetPaths( sheet, sheet );
762 ercItem->SetSheetSpecificPath( sheet );
763 ercItem->SetErrorMessage(
764 wxString::Format(
765 _( "Field name has leading or trailing whitespace: '%s'" ),
766 field.GetName() ) );
767
768 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), field.GetPosition() );
769 screen->Append( marker );
770 warnings++;
771 }
772 }
773 }
774 }
775
776 return warnings;
777}
778
779
781{
782 int errors = 0;
783
784 for( std::pair<const wxString, SCH_REFERENCE_LIST>& symbol : m_refMap )
785 {
786 SCH_REFERENCE_LIST& refList = symbol.second;
787
788 if( refList.GetCount() == 0 )
789 {
790 wxFAIL; // it should not happen
791 continue;
792 }
793
794 // Reference footprint
795 SCH_SYMBOL* unit = nullptr;
796 wxString unitName;
797 wxString unitFP;
798
799 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
800 {
801 SCH_SHEET_PATH sheetPath = refList.GetItem( ii ).GetSheetPath();
802 unitFP = refList.GetItem( ii ).GetFootprint();
803
804 if( !unitFP.IsEmpty() )
805 {
806 unit = refList.GetItem( ii ).GetSymbol();
807 unitName = unit->GetRef( &sheetPath, true );
808 break;
809 }
810 }
811
812 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
813 {
814 SCH_REFERENCE& secondRef = refList.GetItem( ii );
815 SCH_SYMBOL* secondUnit = secondRef.GetSymbol();
816 wxString secondName = secondUnit->GetRef( &secondRef.GetSheetPath(), true );
817 const wxString secondFp = secondRef.GetFootprint();
818 wxString msg;
819
820 if( unit && !secondFp.IsEmpty() && unitFP != secondFp )
821 {
822 msg.Printf( _( "Different footprints assigned to %s and %s" ),
823 unitName, secondName );
824
825 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_FP );
826 ercItem->SetErrorMessage( msg );
827 ercItem->SetItems( unit, secondUnit );
828
829 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), secondUnit->GetPosition() );
830 secondRef.GetSheetPath().LastScreen()->Append( marker );
831
832 ++errors;
833 }
834 }
835 }
836
837 return errors;
838}
839
840
842{
843 int errors = 0;
844
845 for( std::pair<const wxString, SCH_REFERENCE_LIST>& symbol : m_refMap )
846 {
847 SCH_REFERENCE_LIST& refList = symbol.second;
848
849 wxCHECK2( refList.GetCount(), continue );
850
851 // Reference unit
852 SCH_REFERENCE& base_ref = refList.GetItem( 0 );
853 SCH_SYMBOL* unit = base_ref.GetSymbol();
854 LIB_SYMBOL* libSymbol = base_ref.GetLibPart();
855
856 if( static_cast<ssize_t>( refList.GetCount() ) == libSymbol->GetUnitCount() )
857 continue;
858
859 std::set<int> lib_units;
860 std::set<int> instance_units;
861 std::set<int> missing_units;
862
863 auto report =
864 [&]( std::set<int>& aMissingUnits, const wxString& aErrorMsg, int aErrorCode )
865 {
866 wxString msg;
867 wxString missing_pin_units = wxS( "[ " );
868 int ii = 0;
869
870 for( int missing_unit : aMissingUnits )
871 {
872 if( ii++ == 3 )
873 {
874 missing_pin_units += wxS( "..." );
875 break;
876 }
877
878 missing_pin_units += libSymbol->GetUnitDisplayName( missing_unit, false ) + ", " ;
879 }
880
881 missing_pin_units.Truncate( missing_pin_units.length() - 2 );
882 missing_pin_units += wxS( " ]" );
883
884 msg.Printf( aErrorMsg, symbol.first, missing_pin_units );
885
886 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( aErrorCode );
887 ercItem->SetErrorMessage( msg );
888 ercItem->SetItems( unit );
889 ercItem->SetSheetSpecificPath( base_ref.GetSheetPath() );
890 ercItem->SetItemsSheetPaths( base_ref.GetSheetPath() );
891
892 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), unit->GetPosition() );
893 base_ref.GetSheetPath().LastScreen()->Append( marker );
894
895 ++errors;
896 };
897
898 for( int ii = 1; ii <= libSymbol->GetUnitCount(); ++ii )
899 lib_units.insert( lib_units.end(), ii );
900
901 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
902 instance_units.insert( instance_units.end(), refList.GetItem( ii ).GetUnit() );
903
904 std::set_difference( lib_units.begin(), lib_units.end(),
905 instance_units.begin(), instance_units.end(),
906 std::inserter( missing_units, missing_units.begin() ) );
907
908 if( !missing_units.empty() && m_settings.IsTestEnabled( ERCE_MISSING_UNIT ) )
909 {
910 report( missing_units, _( "Symbol %s has unplaced units %s" ), ERCE_MISSING_UNIT );
911 }
912
913 std::set<int> missing_power;
914 std::set<int> missing_input;
915 std::set<int> missing_bidi;
916
917 for( int missing_unit : missing_units )
918 {
919 int bodyStyle = 0;
920
921 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
922 {
923 if( refList.GetItem( ii ).GetUnit() == missing_unit )
924 {
925 bodyStyle = refList.GetItem( ii ).GetSymbol()->GetBodyStyle();
926 break;
927 }
928 }
929
930 for( SCH_PIN* pin : libSymbol->GetGraphicalPins( missing_unit, bodyStyle ) )
931 {
932 switch( pin->GetType() )
933 {
935 missing_power.insert( missing_unit );
936 break;
937
939 missing_bidi.insert( missing_unit );
940 break;
941
943 missing_input.insert( missing_unit );
944 break;
945
946 default:
947 break;
948 }
949 }
950 }
951
952 if( !missing_power.empty() && m_settings.IsTestEnabled( ERCE_MISSING_POWER_INPUT_PIN ) )
953 {
954 report( missing_power, _( "Symbol %s has input power pins in units %s that are not placed" ),
956 }
957
958 if( !missing_input.empty() && m_settings.IsTestEnabled( ERCE_MISSING_INPUT_PIN ) )
959 {
960 report( missing_input, _( "Symbol %s has input pins in units %s that are not placed" ),
962 }
963
964 if( !missing_bidi.empty() && m_settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
965 {
966 report( missing_bidi, _( "Symbol %s has bidirectional pins in units %s that are not placed" ),
968 }
969 }
970
971 return errors;
972}
973
974
976{
977 int err_count = 0;
978 std::shared_ptr<NET_SETTINGS>& settings = m_schematic->Project().GetProjectFile().NetSettings();
979 wxString defaultNetclass = settings->GetDefaultNetclass()->GetName();
980
981 auto logError =
982 [&]( const SCH_SHEET_PATH& sheet, SCH_ITEM* item, const wxString& netclass )
983 {
984 err_count++;
985
986 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNDEFINED_NETCLASS );
987
988 ercItem->SetItems( item );
989 ercItem->SetErrorMessage( wxString::Format( _( "Netclass %s is not defined" ), netclass ) );
990
991 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), item->GetPosition() );
992 sheet.LastScreen()->Append( marker );
993 };
994
995 for( const SCH_SHEET_PATH& sheet : m_sheetList )
996 {
997 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
998 {
999 item->RunOnChildren(
1000 [&]( SCH_ITEM* aChild )
1001 {
1002 if( aChild->Type() == SCH_FIELD_T )
1003 {
1004 SCH_FIELD* field = static_cast<SCH_FIELD*>( aChild );
1005
1006 if( field->GetCanonicalName() == wxT( "Netclass" ) )
1007 {
1008 wxString netclass = field->GetShownText( &sheet, false );
1009
1010 if( !netclass.empty() && !netclass.IsSameAs( defaultNetclass )
1011 && !settings->HasNetclass( netclass ) )
1012 {
1013 logError( sheet, item, netclass );
1014 }
1015 }
1016 }
1017
1018 return true;
1019 },
1021 }
1022 }
1023
1024 return err_count;
1025}
1026
1027
1029{
1030 int err_count = 0;
1031
1032 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1033 {
1034 std::map<VECTOR2I, std::vector<SCH_ITEM*>> connMap;
1035
1036 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_LABEL_T ) )
1037 {
1038 SCH_LABEL* label = static_cast<SCH_LABEL*>( item );
1039
1040 for( const VECTOR2I& pt : label->GetConnectionPoints() )
1041 connMap[pt].emplace_back( label );
1042 }
1043
1044 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
1045 {
1046 std::vector<SCH_ITEM*> lines;
1047
1048 for( SCH_ITEM* item : sheet.LastScreen()->Items().Overlapping( SCH_LINE_T, pair.first ) )
1049 {
1050 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1051
1052 if( line->IsGraphicLine() )
1053 continue;
1054
1055 // If the line is connected at the endpoint, then there will be a junction
1056 if( !line->IsEndPoint( pair.first ) )
1057 lines.emplace_back( line );
1058 }
1059
1060 if( lines.size() > 1 )
1061 {
1062 err_count++;
1063 lines.resize( 3 ); // Only show the first 3 lines and if there are only two, adds a nullptr
1064
1065 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LABEL_MULTIPLE_WIRES );
1066 wxString msg = wxString::Format( _( "Label connects more than one wire at %d, %d" ),
1067 pair.first.x, pair.first.y );
1068
1069 ercItem->SetItems( pair.second.front(), lines[0], lines[1], lines[2] );
1070 ercItem->SetErrorMessage( msg );
1071 ercItem->SetSheetSpecificPath( sheet );
1072
1073 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pair.first );
1074 sheet.LastScreen()->Append( marker );
1075 }
1076 }
1077 }
1078
1079 return err_count;
1080}
1081
1082
1084{
1085 int err_count = 0;
1086
1087 auto pinStackAlreadyRepresented =
1088 []( SCH_PIN* pin, std::vector<SCH_ITEM*>& collection ) -> bool
1089 {
1090 for( SCH_ITEM*& item : collection )
1091 {
1092 if( item->Type() == SCH_PIN_T && item->GetParentSymbol() == pin->GetParentSymbol() )
1093 {
1094 if( pin->IsVisible() && !static_cast<SCH_PIN*>( item )->IsVisible() )
1095 item = pin;
1096
1097 return true;
1098 }
1099 }
1100
1101 return false;
1102 };
1103
1104 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1105 {
1106 std::map<VECTOR2I, std::vector<SCH_ITEM*>> connMap;
1107 SCH_SCREEN* screen = sheet.LastScreen();
1108
1109 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1110 {
1111 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1112
1113 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
1114 {
1115 std::vector<SCH_ITEM*>& entry = connMap[pin->GetPosition()];
1116
1117 // Only one pin per pin-stack.
1118 if( pinStackAlreadyRepresented( pin, entry ) )
1119 continue;
1120
1121 entry.emplace_back( pin );
1122 }
1123 }
1124
1125 for( SCH_ITEM* item : screen->Items().OfType( SCH_LINE_T ) )
1126 {
1127 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1128
1129 if( line->IsGraphicLine() )
1130 continue;
1131
1132 for( const VECTOR2I& pt : line->GetConnectionPoints() )
1133 connMap[pt].emplace_back( line );
1134 }
1135
1136 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
1137 {
1138 if( pair.second.size() >= 4 )
1139 {
1140 err_count++;
1141
1142 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOUR_WAY_JUNCTION );
1143
1144 ercItem->SetItems( pair.second[0], pair.second[1], pair.second[2], pair.second[3] );
1145
1146 wxString msg = wxString::Format( _( "Four items connected at %d, %d" ),
1147 pair.first.x, pair.first.y );
1148 ercItem->SetErrorMessage( msg );
1149
1150 ercItem->SetSheetSpecificPath( sheet );
1151
1152 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pair.first );
1153 sheet.LastScreen()->Append( marker );
1154 }
1155 }
1156 }
1157
1158 return err_count;
1159}
1160
1161
1163{
1164 int err_count = 0;
1165
1166 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1167 {
1168 std::map<VECTOR2I, std::vector<SCH_ITEM*>> pinMap;
1169
1170 auto addOther =
1171 [&]( const VECTOR2I& pt, SCH_ITEM* aOther )
1172 {
1173 if( pinMap.count( pt ) )
1174 pinMap[pt].emplace_back( aOther );
1175 };
1176
1177 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1178 {
1179 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1180
1181 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
1182 {
1183 if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC )
1184 pinMap[pin->GetPosition()].emplace_back( pin );
1185 }
1186 }
1187
1188 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
1189 {
1190 if( item->Type() == SCH_SYMBOL_T )
1191 {
1192 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1193
1194 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
1195 {
1196 if( pin->GetType() != ELECTRICAL_PINTYPE::PT_NC )
1197 addOther( pin->GetPosition(), pin );
1198 }
1199 }
1200 else if( item->IsConnectable() && item->Type() != SCH_NO_CONNECT_T )
1201 {
1202 for( const VECTOR2I& pt : item->GetConnectionPoints() )
1203 addOther( pt, item );
1204 }
1205 }
1206
1207 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : pinMap )
1208 {
1209 if( pair.second.size() > 1 )
1210 {
1211 bool all_nc = true;
1212
1213 for( SCH_ITEM* item : pair.second )
1214 {
1215 if( item->Type() != SCH_PIN_T )
1216 {
1217 all_nc = false;
1218 break;
1219 }
1220
1221 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1222
1223 if( pin->GetType() != ELECTRICAL_PINTYPE::PT_NC )
1224 {
1225 all_nc = false;
1226 break;
1227 }
1228 }
1229
1230 if( all_nc )
1231 continue;
1232
1233 err_count++;
1234
1235 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED );
1236
1237 ercItem->SetItems( pair.second[0], pair.second[1],
1238 pair.second.size() > 2 ? pair.second[2] : nullptr,
1239 pair.second.size() > 3 ? pair.second[3] : nullptr );
1240 ercItem->SetErrorMessage( _( "Pin with 'no connection' type is connected" ) );
1241 ercItem->SetSheetSpecificPath( sheet );
1242
1243 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pair.first );
1244 sheet.LastScreen()->Append( marker );
1245 }
1246 }
1247 }
1248
1249 return err_count;
1250}
1251
1252
1254{
1255 int errors = 0;
1256
1257 // Map each net name to the pins (with sheet context) found on that net so we can later
1258 // perform cross-net compatibility checks for grouped net chains.
1259 std::unordered_map<wxString, std::vector<ERC_SCH_PIN_CONTEXT>> netToPins;
1260
1261 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1262 {
1263 using iterator_t = std::vector<ERC_SCH_PIN_CONTEXT>::iterator;
1264 std::vector<ERC_SCH_PIN_CONTEXT> pins;
1265 std::unordered_map<EDA_ITEM*, SCH_SCREEN*> pinToScreenMap;
1266 bool has_noconnect = false;
1267
1268 for( CONNECTION_SUBGRAPH* subgraph: net.second )
1269 {
1270 if( subgraph->GetNoConnect() )
1271 has_noconnect = true;
1272
1273 for( SCH_ITEM* item : subgraph->GetItems() )
1274 {
1275 if( item->Type() == SCH_PIN_T )
1276 {
1277 pins.emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
1278 netToPins[ net.first.Name ].emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
1279 pinToScreenMap[item] = subgraph->GetSheet().LastScreen();
1280 }
1281 }
1282 }
1283
1284 std::sort( pins.begin(), pins.end(),
1285 []( const ERC_SCH_PIN_CONTEXT& lhs, const ERC_SCH_PIN_CONTEXT& rhs )
1286 {
1287 int ret = StrNumCmp( lhs.Pin()->GetParentSymbol()->GetRef( &lhs.Sheet() ),
1288 rhs.Pin()->GetParentSymbol()->GetRef( &rhs.Sheet() ) );
1289
1290 if( ret == 0 )
1291 ret = StrNumCmp( lhs.Pin()->GetNumber(), rhs.Pin()->GetNumber() );
1292
1293 if( ret == 0 )
1294 ret = lhs < rhs; // Fallback to hash to guarantee deterministic sort
1295
1296 return ret < 0;
1297 } );
1298
1299 ERC_SCH_PIN_CONTEXT needsDriver;
1301 bool hasDriver = false;
1302 std::vector<ERC_SCH_PIN_CONTEXT*> pinsNeedingDrivers;
1303 std::vector<ERC_SCH_PIN_CONTEXT*> nonPowerPinsNeedingDrivers;
1304 std::vector<ERC_SCH_PIN_CONTEXT*> powerInPinsNeedingDrivers;
1305
1306 // We need different drivers for power nets and normal nets.
1307 // A power net has at least one pin having the ELECTRICAL_PINTYPE::PT_POWER_IN
1308 // and power nets can be driven only by ELECTRICAL_PINTYPE::PT_POWER_OUT pins
1309 bool ispowerNet = false;
1310
1311 for( ERC_SCH_PIN_CONTEXT& refPin : pins )
1312 {
1313 if( refPin.Pin()->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
1314 {
1315 ispowerNet = true;
1316 break;
1317 }
1318 }
1319
1320 std::vector<std::tuple<iterator_t, iterator_t, PIN_ERROR>> pin_mismatches;
1321 std::map<iterator_t, int> pin_mismatch_counts;
1322
1323 for( auto refIt = pins.begin(); refIt != pins.end(); ++refIt )
1324 {
1325 ERC_SCH_PIN_CONTEXT& refPin = *refIt;
1326 ELECTRICAL_PINTYPE refType = refPin.Pin()->GetType();
1327
1328 if( DrivenPinTypes.contains( refType ) )
1329 {
1330 // needsDriver will be the pin shown in the error report eventually, so try to
1331 // upgrade to a "better" pin if possible: something visible and only a power symbol
1332 // if this net needs a power driver
1333 pinsNeedingDrivers.push_back( &refPin );
1334
1335 if( !refPin.Pin()->IsPower() )
1336 nonPowerPinsNeedingDrivers.push_back( &refPin );
1337
1338 if( refType == ELECTRICAL_PINTYPE::PT_POWER_IN )
1339 powerInPinsNeedingDrivers.push_back( &refPin );
1340
1341 if( !needsDriver.Pin()
1342 || ( !needsDriver.Pin()->IsVisible() && refPin.Pin()->IsVisible() )
1343 || ( ispowerNet != ( needsDriverType == ELECTRICAL_PINTYPE::PT_POWER_IN )
1344 && ispowerNet == ( refType == ELECTRICAL_PINTYPE::PT_POWER_IN ) ) )
1345 {
1346 needsDriver = refPin;
1347 needsDriverType = needsDriver.Pin()->GetType();
1348 }
1349 }
1350
1351 if( ispowerNet )
1352 hasDriver |= ( DrivingPowerPinTypes.count( refType ) != 0 );
1353 else
1354 hasDriver |= ( DrivingPinTypes.count( refType ) != 0 );
1355
1356 for( auto testIt = refIt + 1; testIt != pins.end(); ++testIt )
1357 {
1358 ERC_SCH_PIN_CONTEXT& testPin = *testIt;
1359
1360 // Multiple pins in the same symbol that share a type,
1361 // name and position are considered
1362 // "stacked" and shouldn't trigger ERC errors
1363 if( refPin.Pin()->IsStacked( testPin.Pin() ) && refPin.Sheet() == testPin.Sheet() )
1364 continue;
1365
1366 ELECTRICAL_PINTYPE testType = testPin.Pin()->GetType();
1367
1368 if( ispowerNet )
1369 hasDriver |= DrivingPowerPinTypes.contains( testType );
1370 else
1371 hasDriver |= DrivingPinTypes.contains( testType );
1372
1373 PIN_ERROR erc = m_settings.GetPinMapValue( refType, testType );
1374
1377
1378 if( erc != PIN_ERROR::OK && m_settings.IsTestEnabled( ercCode ) )
1379 {
1380 pin_mismatches.emplace_back( std::tuple<iterator_t, iterator_t, PIN_ERROR>{ refIt, testIt, erc } );
1381
1382 if( m_settings.GetERCSortingMetric() == ERC_PIN_SORTING_METRIC::SM_HEURISTICS )
1383 {
1384 pin_mismatch_counts[refIt] = m_settings.GetPinTypeWeight( ( *refIt ).Pin()->GetType() );
1385 pin_mismatch_counts[testIt] = m_settings.GetPinTypeWeight( ( *testIt ).Pin()->GetType() );
1386 }
1387 else
1388 {
1389 if( !pin_mismatch_counts.contains( testIt ) )
1390 pin_mismatch_counts.emplace( testIt, 1 );
1391 else
1392 pin_mismatch_counts[testIt]++;
1393
1394 if( !pin_mismatch_counts.contains( refIt ) )
1395 pin_mismatch_counts.emplace( refIt, 1 );
1396 else
1397 pin_mismatch_counts[refIt]++;
1398 }
1399 }
1400 }
1401 }
1402
1403 std::multimap<size_t, iterator_t, std::greater<size_t>> pins_dsc;
1404
1405 std::transform( pin_mismatch_counts.begin(), pin_mismatch_counts.end(),
1406 std::inserter( pins_dsc, pins_dsc.begin() ),
1407 []( const auto& p )
1408 {
1409 return std::pair<size_t, iterator_t>( p.second, p.first );
1410 } );
1411
1412 for( const auto& [amount, pinItBind] : pins_dsc )
1413 {
1414 auto& pinIt = pinItBind;
1415
1416 if( pin_mismatches.empty() )
1417 break;
1418
1419 SCH_PIN* pin = ( *pinIt ).Pin();
1420 VECTOR2I position = pin->GetPosition();
1421
1422 iterator_t nearest_pin = pins.end();
1423 double smallest_distance = std::numeric_limits<double>::infinity();
1424 PIN_ERROR erc;
1425
1426 std::erase_if(
1427 pin_mismatches,
1428 [&]( const auto& tuple )
1429 {
1430 iterator_t other;
1431
1432 if( pinIt == std::get<0>( tuple ) )
1433 other = std::get<1>( tuple );
1434 else if( pinIt == std::get<1>( tuple ) )
1435 other = std::get<0>( tuple );
1436 else
1437 return false;
1438
1439 if( ( *pinIt ).Sheet().Cmp( ( *other ).Sheet() ) != 0 )
1440 {
1441 if( std::isinf( smallest_distance ) )
1442 {
1443 nearest_pin = other;
1444 erc = std::get<2>( tuple );
1445 }
1446 }
1447 else
1448 {
1449 double distance = position.Distance( ( *other ).Pin()->GetPosition() );
1450
1451 if( std::isinf( smallest_distance ) || distance < smallest_distance )
1452 {
1453 smallest_distance = distance;
1454 nearest_pin = other;
1455 erc = std::get<2>( tuple );
1456 }
1457 }
1458
1459 return true;
1460 } );
1461
1462 if( nearest_pin != pins.end() )
1463 {
1464 SCH_PIN* other_pin = ( *nearest_pin ).Pin();
1465
1468 ercItem->SetItems( pin, other_pin );
1469 ercItem->SetSheetSpecificPath( ( *pinIt ).Sheet() );
1470 ercItem->SetItemsSheetPaths( ( *pinIt ).Sheet(), ( *nearest_pin ).Sheet() );
1471
1472 ercItem->SetErrorMessage( wxString::Format( _( "Pins of type %s and %s are connected" ),
1473 ElectricalPinTypeGetText( pin->GetType() ),
1474 ElectricalPinTypeGetText( other_pin->GetType() ) ) );
1475
1476 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
1477 pinToScreenMap[pin]->Append( marker );
1478 errors++;
1479 }
1480 }
1481
1482 if( needsDriver.Pin() && !hasDriver && !has_noconnect )
1483 {
1484 int err_code = ispowerNet ? ERCE_POWERPIN_NOT_DRIVEN : ERCE_PIN_NOT_DRIVEN;
1485
1486 // NEW: For power nets, before reporting a not-driven error, look across the
1487 // net chain (multi-net chain formed via passives) to see if there is a
1488 // power driver pin on any other net in the same chain. If so, suppress the
1489 // error because the net chain as a whole is driven.
1490 bool suppressForNetChainDriver = false;
1491
1492 if( ispowerNet && m_schematic && m_schematic->ConnectionGraph() )
1493 {
1494 const wxString& thisNetName = net.first.Name;
1495 const auto& netChains = m_schematic->ConnectionGraph()->GetCommittedNetChains();
1496
1497 auto netHasPowerDriver = [&]( const wxString& aNetName ) -> bool
1498 {
1499 // Scan m_nets for the named net and test its pins for a power driver type.
1500 for( const auto& n : m_nets )
1501 {
1502 if( n.first.Name != aNetName )
1503 continue;
1504
1505 for( CONNECTION_SUBGRAPH* sg : n.second )
1506 {
1507 for( SCH_ITEM* item : sg->GetItems() )
1508 {
1509 if( item->Type() == SCH_PIN_T )
1510 {
1511 SCH_PIN* p = static_cast<SCH_PIN*>( item );
1512 if( DrivingPowerPinTypes.contains( p->GetType() ) )
1513 return true;
1514 }
1515 }
1516 }
1517
1518 break; // found matching net (whether driver or not)
1519 }
1520
1521 return false;
1522 };
1523
1524 for( const auto& sig : netChains )
1525 {
1526 if( !sig )
1527 continue;
1528
1529 const auto& sigNets = sig->GetNets();
1530 bool containsThisNet = std::find( sigNets.begin(), sigNets.end(), thisNetName ) != sigNets.end();
1531
1532 if( !containsThisNet )
1533 continue;
1534
1535 // Look for a different net in this chain that has a power driver.
1536 for( const wxString& otherNet : sigNets )
1537 {
1538 if( otherNet == thisNetName )
1539 continue; // skip same net (we already know it lacks a driver)
1540
1541 if( netHasPowerDriver( otherNet ) )
1542 {
1543 suppressForNetChainDriver = true;
1544 break;
1545 }
1546 }
1547
1548 break; // examined the containing chain
1549 }
1550 }
1551
1552 if( !suppressForNetChainDriver && m_settings.IsTestEnabled( err_code ) )
1553 {
1554 std::vector<ERC_SCH_PIN_CONTEXT*> pinsToMark;
1555
1556 // The marker should land on a pin matching the error message: for an
1557 // ERCE_POWERPIN_NOT_DRIVEN error mark a PT_POWER_IN pin (which is what the
1558 // error refers to), for ERCE_PIN_NOT_DRIVEN prefer a pin that is not on a
1559 // power symbol so the marker is anchored to the consuming pin rather than
1560 // a power flag.
1561 if( m_showAllErrors )
1562 {
1563 if( ispowerNet && !powerInPinsNeedingDrivers.empty() )
1564 pinsToMark = powerInPinsNeedingDrivers;
1565 else if( !nonPowerPinsNeedingDrivers.empty() )
1566 pinsToMark = nonPowerPinsNeedingDrivers;
1567 else
1568 pinsToMark = pinsNeedingDrivers;
1569 }
1570 else
1571 {
1572 if( ispowerNet && !powerInPinsNeedingDrivers.empty() )
1573 pinsToMark.push_back( powerInPinsNeedingDrivers.front() );
1574 else
1575 pinsToMark.push_back( &needsDriver );
1576 }
1577
1578 for( ERC_SCH_PIN_CONTEXT* pinCtx : pinsToMark )
1579 {
1580 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( err_code );
1581
1582 ercItem->SetItems( pinCtx->Pin() );
1583 ercItem->SetSheetSpecificPath( pinCtx->Sheet() );
1584 ercItem->SetItemsSheetPaths( pinCtx->Sheet() );
1585
1586 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pinCtx->Pin()->GetPosition() );
1587 pinToScreenMap[pinCtx->Pin()]->Append( marker );
1588 errors++;
1589 }
1590 }
1591 }
1592 }
1593
1594 // --- Additional net-chain-level checking ---
1595 // If a pin participates in a grouped net chain (spanning multiple nets via passives), ensure
1596 // that all other pins reachable through that chain are electrically compatible even if
1597 // they reside on different nets.
1598 // We only consider pairs on DIFFERENT nets here to avoid duplicating existing net-level
1599 // mismatches already reported above.
1600 if( m_schematic && m_schematic->ConnectionGraph() )
1601 {
1602 auto& netChains = m_schematic->ConnectionGraph()->GetCommittedNetChains();
1603 wxLogTrace( traceSchNetChain, "ERC TestPinToPin: cross-chain phase start chains=%zu",
1604 netChains.size() );
1605
1606 for( const auto& sig : netChains )
1607 {
1608 if( !sig )
1609 continue;
1610
1611 const wxString chainName = sig->GetName();
1612 const auto& sigNets = sig->GetNets();
1613
1614 // Collect all pin contexts across the nets in this chain.
1615 std::vector<ERC_SCH_PIN_CONTEXT> netChainPins;
1616 netChainPins.reserve( sigNets.size() * 4 );
1617
1618 for( const wxString& n : sigNets )
1619 {
1620 auto it = netToPins.find( n );
1621 if( it != netToPins.end() )
1622 {
1623 const auto& vec = it->second;
1624 netChainPins.insert( netChainPins.end(), vec.begin(), vec.end() );
1625 }
1626 }
1627
1628 if( netChainPins.size() < 2 )
1629 continue; // nothing to compare
1630
1631 wxLogTrace( traceSchNetChain,
1632 "ERC TestPinToPin: chain '%s' nets=%zu collectedPins=%zu",
1633 TO_UTF8( chainName ), sigNets.size(), netChainPins.size() );
1634
1635 // For deterministic behavior, sort by reference/pin number similar to earlier pass.
1636 std::sort( netChainPins.begin(), netChainPins.end(),
1637 []( const ERC_SCH_PIN_CONTEXT& lhs, const ERC_SCH_PIN_CONTEXT& rhs )
1638 {
1639 int ret = StrNumCmp( lhs.Pin()->GetParentSymbol()->GetRef( &lhs.Sheet() ),
1640 rhs.Pin()->GetParentSymbol()->GetRef( &rhs.Sheet() ) );
1641 if( ret == 0 )
1642 ret = StrNumCmp( lhs.Pin()->GetNumber(), rhs.Pin()->GetNumber() );
1643 if( ret == 0 )
1644 ret = lhs < rhs;
1645 return ret < 0;
1646 } );
1647
1648 // Build a quick map from pin -> net name for skipping intra-net pairs.
1649 std::unordered_map<SCH_PIN*, wxString> pinNet;
1650 for( const auto& netEntry : netToPins )
1651 for( const auto& ctx : netEntry.second )
1652 pinNet[ ctx.Pin() ] = netEntry.first;
1653
1654 for( size_t i = 0; i < netChainPins.size(); ++i )
1655 {
1656 SCH_PIN* aPin = netChainPins[i].Pin();
1657 ELECTRICAL_PINTYPE aType = aPin->GetType();
1658 const wxString& aNet = pinNet[aPin];
1659
1660 for( size_t j = i + 1; j < netChainPins.size(); ++j )
1661 {
1662 SCH_PIN* bPin = netChainPins[j].Pin();
1663 const wxString& bNet = pinNet[bPin];
1664
1665 if( aNet == bNet )
1666 continue; // already handled at net-level
1667
1668 ELECTRICAL_PINTYPE bType = bPin->GetType();
1669 PIN_ERROR erc = m_settings.GetPinMapValue( aType, bType );
1670
1673
1674 if( erc != PIN_ERROR::OK && m_settings.IsTestEnabled( ercCode ) )
1675 {
1676 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ercCode );
1677
1678 ercItem->SetItems( aPin, bPin );
1679 ercItem->SetSheetSpecificPath( netChainPins[i].Sheet() );
1680 ercItem->SetItemsSheetPaths( netChainPins[i].Sheet(), netChainPins[j].Sheet() );
1681 ercItem->SetErrorMessage( wxString::Format(
1682 _( "Pins of type %s and %s are connected via net chain %s" ),
1683 ElectricalPinTypeGetText( aType ),
1684 ElectricalPinTypeGetText( bType ), chainName ) );
1685
1686 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), aPin->GetPosition() );
1687 netChainPins[i].Sheet().LastScreen()->Append( marker );
1688 errors++;
1689 }
1690 }
1691 }
1692 }
1693 }
1694
1695 return errors;
1696}
1697
1698
1700{
1701 int errors = 0;
1702
1703 std::unordered_map<wxString, std::pair<wxString, SCH_PIN*>> pinToNetMap;
1704
1705 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1706 {
1707 const wxString& netName = net.first.Name;
1708
1709 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1710 {
1711 for( SCH_ITEM* item : subgraph->GetItems() )
1712 {
1713 if( item->Type() == SCH_PIN_T )
1714 {
1715 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1716 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1717
1718 if( !pin->GetParentSymbol()->IsMultiUnit() )
1719 continue;
1720
1721 wxString name = pin->GetParentSymbol()->GetRef( &sheet ) + ":" + pin->GetShownNumber();
1722
1723 if( !pinToNetMap.count( name ) )
1724 {
1725 pinToNetMap[name] = std::make_pair( netName, pin );
1726 }
1727 else if( pinToNetMap[name].first != netName )
1728 {
1729 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_NET );
1730
1731 ercItem->SetErrorMessage( wxString::Format( _( "Pin %s is connected to both %s and %s" ),
1732 pin->GetShownNumber(),
1733 netName,
1734 pinToNetMap[name].first ) );
1735
1736 ercItem->SetItems( pin, pinToNetMap[name].second );
1737 ercItem->SetSheetSpecificPath( sheet );
1738 ercItem->SetItemsSheetPaths( sheet, sheet );
1739
1740 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
1741 sheet.LastScreen()->Append( marker );
1742 errors += 1;
1743 }
1744 }
1745 }
1746 }
1747 }
1748
1749 return errors;
1750}
1751
1752
1754{
1755 int errors = 0;
1756
1757 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1758 {
1759 SCH_SCREEN* screen = sheet.LastScreen();
1760
1761 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1762 {
1763 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1764 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
1765
1766 if( !libSymbol )
1767 continue;
1768
1769 if( libSymbol->GetDuplicatePinNumbersAreJumpers() )
1770 continue;
1771
1772 std::vector<SCH_PIN*> pins = symbol->GetPins( &sheet );
1773
1774 std::map<wxString, std::vector<std::pair<SCH_PIN*, wxString>>> pinsByNumber;
1775
1776 for( SCH_PIN* pin : pins )
1777 {
1778 SCH_CONNECTION* conn = pin->Connection( &sheet );
1779 wxString netName = conn ? conn->GetNetName() : wxString();
1780
1781 pinsByNumber[pin->GetNumber()].emplace_back( pin, netName );
1782 }
1783
1784 for( const auto& [pinNumber, pinNetPairs] : pinsByNumber )
1785 {
1786 if( pinNetPairs.size() < 2 )
1787 continue;
1788
1789 wxString firstNet = pinNetPairs[0].second;
1790 bool hasDifferentNets = false;
1791 SCH_PIN* conflictPin = nullptr;
1792
1793 for( size_t i = 1; i < pinNetPairs.size(); i++ )
1794 {
1795 if( pinNetPairs[i].second != firstNet )
1796 {
1797 hasDifferentNets = true;
1798 conflictPin = pinNetPairs[i].first;
1799 break;
1800 }
1801 }
1802
1803 if( hasDifferentNets )
1804 {
1805 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DUPLICATE_PIN_ERROR );
1806 wxString msg;
1807
1808 msg.Printf( _( "Pin %s on symbol '%s' is connected to different nets: %s and %s" ),
1809 pinNumber,
1810 symbol->GetRef( &sheet ),
1811 firstNet.IsEmpty() ? _( "<no net>" ) : firstNet,
1812 pinNetPairs[1].second.IsEmpty() ? _( "<no net>" ) : pinNetPairs[1].second );
1813
1814 ercItem->SetErrorMessage( msg );
1815 ercItem->SetItems( pinNetPairs[0].first, conflictPin );
1816 ercItem->SetSheetSpecificPath( sheet );
1817 ercItem->SetItemsSheetPaths( sheet, sheet );
1818
1819 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ),
1820 pinNetPairs[0].first->GetPosition() );
1821 screen->Append( marker );
1822 errors++;
1823 }
1824 }
1825 }
1826 }
1827
1828 return errors;
1829}
1830
1831
1833{
1834 int errors = 0;
1835
1836 auto isGround =
1837 []( const wxString& txt )
1838 {
1839 wxString upper = txt.Upper();
1840
1841 return upper.Contains( wxT( "GND" ) )
1842 || upper == wxT( "EARTH" ) || upper.StartsWith( wxT( "EARTH_" ) )
1843 || upper == wxT( "VSS" ) || upper == wxT( "VSSA" );
1844 };
1845
1846 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1847 {
1848 SCH_SCREEN* screen = sheet.LastScreen();
1849
1850 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1851 {
1852 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1853 bool hasGroundNet = false;
1854 std::vector<SCH_PIN*> mismatched;
1855
1856 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
1857 {
1858 SCH_CONNECTION* conn = pin->Connection( &sheet );
1859 wxString net = conn ? conn->GetNetName() : wxString();
1860 bool netIsGround = isGround( net );
1861
1862 // We are only interested in power pins
1863 if( pin->GetType() != ELECTRICAL_PINTYPE::PT_POWER_OUT
1864 && pin->GetType() != ELECTRICAL_PINTYPE::PT_POWER_IN )
1865 {
1866 continue;
1867 }
1868
1869 if( netIsGround )
1870 hasGroundNet = true;
1871
1872 if( isGround( pin->GetShownName() ) && !netIsGround )
1873 mismatched.push_back( pin );
1874 }
1875
1876 if( hasGroundNet )
1877 {
1878 for( SCH_PIN* pin : mismatched )
1879 {
1880 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_GROUND_PIN_NOT_GROUND );
1881
1882 ercItem->SetErrorMessage( wxString::Format( _( "Pin %s not connected to ground net" ),
1883 pin->GetShownName() ) );
1884 ercItem->SetItems( pin );
1885 ercItem->SetSheetSpecificPath( sheet );
1886 ercItem->SetItemsSheetPaths( sheet );
1887
1888 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
1889 screen->Append( marker );
1890 errors++;
1891 }
1892 }
1893 }
1894 }
1895
1896 return errors;
1897}
1898
1899
1901{
1902 int warnings = 0;
1903
1904 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1905 {
1906 SCH_SCREEN* screen = sheet.LastScreen();
1907
1908 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1909 {
1910 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1911
1912 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
1913 {
1914 bool valid;
1915 pin->GetStackedPinNumbers( &valid );
1916
1917 if( !valid )
1918 {
1919 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_STACKED_PIN_SYNTAX );
1920 ercItem->SetItems( pin );
1921 ercItem->SetSheetSpecificPath( sheet );
1922 ercItem->SetItemsSheetPaths( sheet );
1923
1924 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
1925 screen->Append( marker );
1926 warnings++;
1927 }
1928 }
1929 }
1930 }
1931
1932 return warnings;
1933}
1934
1935
1937{
1938 int errCount = 0;
1939
1940 std::unordered_map<wxString, std::pair<SCH_ITEM*, SCH_SHEET_PATH>> globalLabels;
1941 std::unordered_map<wxString, std::pair<SCH_ITEM*, SCH_SHEET_PATH>> localLabels;
1942
1943 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1944 {
1945 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1946 {
1947 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1948
1949 for( SCH_ITEM* item : subgraph->GetItems() )
1950 {
1951 if( item->Type() == SCH_LABEL_T || item->Type() == SCH_GLOBAL_LABEL_T )
1952 {
1953 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
1954 wxString text = label->GetShownText( &sheet, false );
1955
1956 auto& map = item->Type() == SCH_LABEL_T ? localLabels : globalLabels;
1957
1958 if( !map.count( text ) )
1959 {
1960 map[text] = std::make_pair( label, sheet );
1961 }
1962 }
1963 else if( item->Type() == SCH_PIN_T )
1964 {
1965 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1966
1967 if( !pin->IsPower() )
1968 continue;
1969
1970 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
1971
1972 if( !symbol )
1973 continue;
1974
1975 wxString text = ( pin->IsGlobalPower() && !symbol->IsGlobalPower() )
1976 ? pin->GetShownName()
1977 : symbol->GetValue( true, &sheet, false );
1978
1979 auto& map = pin->IsGlobalPower() ? globalLabels : localLabels;
1980
1981 if( !map.count( text ) )
1982 {
1983 map[text] = std::make_pair( pin, sheet );
1984 }
1985 }
1986 }
1987 }
1988 }
1989
1990 for( auto& [globalText, globalItem] : globalLabels )
1991 {
1992 for( auto& [localText, localItem] : localLabels )
1993 {
1994 if( globalText == localText )
1995 {
1996 ERCE_T errorCode = ( globalItem.first->Type() == SCH_PIN_T && localItem.first->Type() == SCH_PIN_T )
1999
2000 if( !m_settings.IsTestEnabled( errorCode ) )
2001 continue;
2002
2003 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( errorCode );
2004 ercItem->SetItems( globalItem.first, localItem.first );
2005 ercItem->SetSheetSpecificPath( globalItem.second );
2006 ercItem->SetItemsSheetPaths( globalItem.second, localItem.second );
2007
2008 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), globalItem.first->GetPosition() );
2009 globalItem.second.LastScreen()->Append( marker );
2010
2011 errCount++;
2012 }
2013 }
2014 }
2015
2016 return errCount;
2017}
2018
2019
2021{
2022 int errors = 0;
2023 std::unordered_map<wxString, std::vector<std::tuple<wxString, SCH_ITEM*, SCH_SHEET_PATH>>> generalMap;
2024
2025 auto logError =
2026 [&]( const wxString& normalized, SCH_ITEM* item, const SCH_SHEET_PATH& sheet,
2027 const std::tuple<wxString, SCH_ITEM*, SCH_SHEET_PATH>& other )
2028 {
2029 auto& [otherText, otherItem, otherSheet] = other;
2030 ERCE_T typeOfWarning = ERCE_SIMILAR_LABELS;
2031
2032 if( item->Type() == SCH_PIN_T && otherItem->Type() == SCH_PIN_T )
2033 {
2034 //Two Pins
2035 typeOfWarning = ERCE_SIMILAR_POWER;
2036 }
2037 else if( item->Type() == SCH_PIN_T || otherItem->Type() == SCH_PIN_T )
2038 {
2039 //Pin and Label
2040 typeOfWarning = ERCE_SIMILAR_LABEL_AND_POWER;
2041 }
2042 else
2043 {
2044 //Two Labels
2045 typeOfWarning = ERCE_SIMILAR_LABELS;
2046 }
2047
2048 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( typeOfWarning );
2049 ercItem->SetItems( item, otherItem );
2050 ercItem->SetSheetSpecificPath( sheet );
2051 ercItem->SetItemsSheetPaths( sheet, otherSheet );
2052
2053 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), item->GetPosition() );
2054 sheet.LastScreen()->Append( marker );
2055 };
2056
2057 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
2058 {
2059 for( CONNECTION_SUBGRAPH* subgraph : net.second )
2060 {
2061 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
2062
2063 for( SCH_ITEM* item : subgraph->GetItems() )
2064 {
2065 switch( item->Type() )
2066 {
2067 case SCH_LABEL_T:
2068 case SCH_HIER_LABEL_T:
2069 case SCH_GLOBAL_LABEL_T:
2070 {
2071 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
2072 wxString unnormalized = label->GetShownText( &sheet, false );
2073 wxString normalized = unnormalized.Lower();
2074
2075 generalMap[normalized].emplace_back( std::make_tuple( unnormalized, label, sheet ) );
2076
2077 for( const auto& otherTuple : generalMap.at( normalized ) )
2078 {
2079 const auto& [otherText, otherItem, otherSheet] = otherTuple;
2080
2081 if( unnormalized != otherText )
2082 {
2083 // Similar local labels on different sheets are fine
2084 if( item->Type() == SCH_LABEL_T && otherItem->Type() == SCH_LABEL_T
2085 && sheet != otherSheet )
2086 {
2087 continue;
2088 }
2089
2090 logError( normalized, label, sheet, otherTuple );
2091 errors += 1;
2092 }
2093 }
2094
2095 break;
2096 }
2097 case SCH_PIN_T:
2098 {
2099 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
2100
2101 if( !pin->IsPower() )
2102 continue;
2103
2104 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
2105 wxString unnormalized = symbol->GetValue( true, &sheet, false );
2106 wxString normalized = unnormalized.Lower();
2107
2108 generalMap[normalized].emplace_back( std::make_tuple( unnormalized, pin, sheet ) );
2109
2110 for( const auto& otherTuple : generalMap.at( normalized ) )
2111 {
2112 const auto& [otherText, otherItem, otherSheet] = otherTuple;
2113
2114 if( unnormalized != otherText )
2115 {
2116 logError( normalized, pin, sheet, otherTuple );
2117 errors += 1;
2118 }
2119 }
2120
2121 break;
2122 }
2123
2124 default:
2125 break;
2126 }
2127 }
2128 }
2129 }
2130
2131 return errors;
2132}
2133
2134
2136{
2137 wxCHECK( m_schematic, 0 );
2138
2139 LIBRARY_MANAGER& manager = Pgm().GetLibraryManager();
2141 wxString msg;
2142 int err_count = 0;
2143
2144 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
2145 {
2146 std::vector<SCH_MARKER*> markers;
2147
2148 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
2149 {
2150 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2151 LIB_SYMBOL* libSymbolInSchematic = symbol->GetLibSymbolRef().get();
2152
2153 if( !libSymbolInSchematic )
2154 continue;
2155
2156 wxString libName = symbol->GetLibId().GetLibNickname();
2157
2158 std::optional<const LIBRARY_TABLE_ROW*> optRow =
2159 manager.GetRow( LIBRARY_TABLE_TYPE::SYMBOL, libName );
2160
2161 if( !optRow || ( *optRow )->Disabled() )
2162 {
2163 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
2164 {
2165 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
2166 ercItem->SetItems( symbol );
2167 msg.Printf( _( "The current configuration does not include the symbol library '%s'" ),
2168 UnescapeString( libName ) );
2169 ercItem->SetErrorMessage( msg );
2170
2171 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2172 }
2173
2174 continue;
2175 }
2176 else if( !adapter->IsLibraryLoaded( libName ) )
2177 {
2178 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
2179 {
2180 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
2181 std::optional<wxString> uri =
2182 manager.GetFullURI( LIBRARY_TABLE_TYPE::SYMBOL, libName, true );
2183 wxCHECK2( uri.has_value(), uri = wxEmptyString );
2184 ercItem->SetItems( symbol );
2185 msg.Printf( _( "The symbol library '%s' was not found at '%s'" ),
2186 UnescapeString( libName ), *uri );
2187 ercItem->SetErrorMessage( msg );
2188
2189 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2190 }
2191
2192 continue;
2193 }
2194
2195 wxString symbolName = symbol->GetLibId().GetLibItemName();
2196 LIB_SYMBOL* libSymbol = adapter->LoadSymbol( symbol->GetLibId() );
2197
2198 if( libSymbol == nullptr )
2199 {
2200 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
2201 {
2202 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
2203 ercItem->SetItems( symbol );
2204 msg.Printf( _( "Symbol '%s' not found in symbol library '%s'" ),
2205 UnescapeString( symbolName ),
2206 UnescapeString( libName ) );
2207 ercItem->SetErrorMessage( msg );
2208
2209 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2210 }
2211
2212 continue;
2213 }
2214
2215 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->Flatten();
2217
2218 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_MISMATCH ) )
2219 {
2220 // We have to check for duplicate pins first as they will cause Compare() to fail.
2221 // Symbols with duplicate pins are valid if those pins share the same net, so we
2222 // only skip the comparison here. The actual error checking for duplicate pins on
2223 // different nets is done in TestDuplicatePinNets().
2224 std::vector<wxString> messages;
2225
2226 if( !libSymbolInSchematic->GetDuplicatePinNumbersAreJumpers() )
2227 {
2228 UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILS );
2229 CheckDuplicatePins( libSymbolInSchematic, messages, &unitsProvider );
2230 }
2231
2232 if( messages.empty() && flattenedSymbol->Compare( *libSymbolInSchematic, flags ) != 0 )
2233 {
2234 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_MISMATCH );
2235 ercItem->SetItems( symbol );
2236 msg.Printf( _( "Symbol '%s' doesn't match copy in library '%s'" ),
2237 UnescapeString( symbolName ),
2238 UnescapeString( libName ) );
2239 ercItem->SetErrorMessage( msg );
2240
2241 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2242 }
2243 }
2244 }
2245
2246 for( SCH_MARKER* marker : markers )
2247 {
2248 screen->Append( marker );
2249 err_count += 1;
2250 }
2251 }
2252
2253 return err_count;
2254}
2255
2256
2258{
2259 wxCHECK( m_schematic, 0 );
2260
2261 if( std::optional<LIBRARY_MANAGER_ADAPTER*> adapter =
2262 Pgm().GetLibraryManager().Adapter( LIBRARY_TABLE_TYPE::FOOTPRINT ) )
2263 {
2264 ( *adapter )->BlockUntilLoaded();
2265 }
2266
2267 wxString msg;
2268 int err_count = 0;
2269
2270 typedef int (*TESTER_FN_PTR)( const wxString&, PROJECT* );
2271
2272 TESTER_FN_PTR linkTester = (TESTER_FN_PTR) aCvPcb->IfaceOrAddress( KIFACE_TEST_FOOTPRINT_LINK );
2273
2274 for( SCH_SHEET_PATH& sheet : m_sheetList )
2275 {
2276 std::vector<SCH_MARKER*> markers;
2277
2278 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
2279 {
2280 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2281 wxString footprint = symbol->GetFootprintFieldText( true, &sheet, false );
2282
2283 if( footprint.IsEmpty() )
2284 continue;
2285
2286 LIB_ID fpID;
2287
2288 if( fpID.Parse( footprint, true ) >= 0 )
2289 {
2290 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2291 msg.Printf( _( "'%s' is not a valid footprint identifier" ), footprint );
2292 ercItem->SetErrorMessage( msg );
2293 ercItem->SetItems( symbol );
2294 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2295 continue;
2296 }
2297
2298 wxString libName = fpID.GetLibNickname();
2299 wxString fpName = fpID.GetLibItemName();
2300 int ret = (linkTester)( footprint, aProject );
2301
2303 {
2304 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2305 msg.Printf( _( "The current configuration does not include the footprint library '%s'" ),
2306 libName );
2307 ercItem->SetErrorMessage( msg );
2308 ercItem->SetItems( symbol );
2309 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2310 }
2312 {
2313 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2314 msg.Printf( _( "The footprint library '%s' is not enabled in the current configuration" ),
2315 libName );
2316 ercItem->SetErrorMessage( msg );
2317 ercItem->SetItems( symbol );
2318 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2319 }
2321 {
2322 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2323 msg.Printf( _( "Footprint '%s' not found in library '%s'" ),
2324 fpName,
2325 libName );
2326 ercItem->SetErrorMessage( msg );
2327 ercItem->SetItems( symbol );
2328 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2329 }
2330 }
2331
2332 for( SCH_MARKER* marker : markers )
2333 {
2334 sheet.LastScreen()->Append( marker );
2335 err_count += 1;
2336 }
2337 }
2338
2339 return err_count;
2340}
2341
2342
2344{
2345 wxCHECK( m_schematic, 0 );
2346
2347 wxString msg;
2348 int err_count = 0;
2349
2350 for( SCH_SHEET_PATH& sheet : m_sheetList )
2351 {
2352 std::vector<SCH_MARKER*> markers;
2353
2354 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
2355 {
2356 SCH_SYMBOL* sch_symbol = static_cast<SCH_SYMBOL*>( item );
2357 std::unique_ptr<LIB_SYMBOL>& lib_symbol = sch_symbol->GetLibSymbolRef();
2358
2359 if( !lib_symbol )
2360 continue;
2361
2362 wxArrayString filters = lib_symbol->GetFPFilters();
2363
2364 if( filters.empty() )
2365 continue;
2366
2367 wxString lowerId = sch_symbol->GetFootprintFieldText( true, &sheet, false ).Lower();
2368 LIB_ID footprint;
2369
2370 if( footprint.Parse( lowerId ) > 0 )
2371 continue;
2372
2373 wxString lowerItemName = footprint.GetUniStringLibItemName().Lower();
2374 bool found = false;
2375
2376 for( wxString filter : filters )
2377 {
2378 filter.LowerCase();
2379
2380 // If the filter contains a ':' character, include the library name in the pattern
2381 if( filter.Contains( wxS( ":" ) ) )
2382 found |= lowerId.Matches( filter );
2383 else
2384 found |= lowerItemName.Matches( filter );
2385
2386 if( found )
2387 break;
2388 }
2389
2390 if( !found )
2391 {
2392 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_FILTERS );
2393 msg.Printf( _( "Assigned footprint (%s) doesn't match footprint filters (%s)" ),
2394 footprint.GetUniStringLibItemName(),
2395 wxJoin( filters, ' ' ) );
2396 ercItem->SetErrorMessage( msg );
2397 ercItem->SetItems( sch_symbol );
2398 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), sch_symbol->GetPosition() ) );
2399 }
2400 }
2401
2402 for( SCH_MARKER* marker : markers )
2403 {
2404 sheet.LastScreen()->Append( marker );
2405 err_count += 1;
2406 }
2407 }
2408
2409 return err_count;
2410}
2411
2412
2414{
2415 const int gridSize = m_schematic->Settings().m_ConnectionGridSize;
2416 int err_count = 0;
2417
2418 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
2419 {
2420 std::vector<SCH_MARKER*> markers;
2421
2422 for( SCH_ITEM* item : screen->Items() )
2423 {
2424 if( item->Type() == SCH_LINE_T && item->IsConnectable() )
2425 {
2426 SCH_LINE* line = static_cast<SCH_LINE*>( item );
2427
2428 if( ( line->GetStartPoint().x % gridSize ) != 0
2429 || ( line->GetStartPoint().y % gridSize ) != 0 )
2430 {
2431 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
2432 ercItem->SetItems( line );
2433
2434 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), line->GetStartPoint() ) );
2435 }
2436 else if( ( line->GetEndPoint().x % gridSize ) != 0
2437 || ( line->GetEndPoint().y % gridSize ) != 0 )
2438 {
2439 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
2440 ercItem->SetItems( line );
2441
2442 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), line->GetEndPoint() ) );
2443 }
2444 }
2445 if( item->Type() == SCH_BUS_WIRE_ENTRY_T )
2446 {
2447 SCH_BUS_WIRE_ENTRY* entry = static_cast<SCH_BUS_WIRE_ENTRY*>( item );
2448
2449 for( const VECTOR2I& point : entry->GetConnectionPoints() )
2450 {
2451 if( ( point.x % gridSize ) != 0
2452 || ( point.y % gridSize ) != 0 )
2453 {
2454 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
2455 ercItem->SetItems( entry );
2456
2457 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), point ) );
2458 }
2459 }
2460 }
2461 else if( item->Type() == SCH_SYMBOL_T )
2462 {
2463 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2464
2465 for( SCH_PIN* pin : symbol->GetPins( nullptr ) )
2466 {
2467 if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC )
2468 continue;
2469
2470 VECTOR2I pinPos = pin->GetPosition();
2471
2472 if( ( pinPos.x % gridSize ) != 0 || ( pinPos.y % gridSize ) != 0 )
2473 {
2474 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
2475 ercItem->SetItems( pin );
2476
2477 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), pinPos ) );
2478 break;
2479 }
2480 }
2481 }
2482 }
2483
2484 for( SCH_MARKER* marker : markers )
2485 {
2486 screen->Append( marker );
2487 err_count += 1;
2488 }
2489 }
2490
2491 return err_count;
2492}
2493
2494
2496{
2498 int err_count = 0;
2499 SIM_LIB_MGR libMgr( &m_schematic->Project() );
2500 wxString variant = m_schematic->GetCurrentVariant();
2501
2502 for( SCH_SHEET_PATH& sheet : m_sheetList )
2503 {
2504 if( sheet.GetExcludedFromSim( variant ) )
2505 continue;
2506
2507 std::vector<SCH_MARKER*> markers;
2508
2509 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
2510 {
2511 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2512
2513 // Power symbols and other symbols which have the reference starting with "#" are
2514 // not included in simulation
2515 if( symbol->GetRef( &sheet ).StartsWith( '#' ) || symbol->ResolveExcludedFromSim() )
2516 continue;
2517
2518 // Reset for each symbol
2519 reporter.Clear();
2520
2521 SIM_LIBRARY::MODEL model = libMgr.CreateModel( &sheet, *symbol, true, 0, variant, reporter );
2522
2523 if( reporter.HasMessage() )
2524 {
2525 wxString msg = reporter.GetMessages();
2526 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMULATION_MODEL );
2527
2528 //Remove \n and \r at e.o.l if any:
2529 msg.Trim();
2530
2531 ercItem->SetErrorMessage( msg );
2532 ercItem->SetItems( symbol );
2533
2534 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2535 }
2536 }
2537
2538 for( SCH_MARKER* marker : markers )
2539 {
2540 sheet.LastScreen()->Append( marker );
2541 err_count += 1;
2542 }
2543 }
2544
2545 return err_count;
2546}
2547
2548
2550{
2551 wxCHECK( m_schematic, 0 );
2552
2554
2555 if( !adapter )
2556 return 0;
2557
2558 int err_count = 0;
2559
2560 // Flatten each alternate once per ERC run rather than once per referencing symbol.
2561 std::map<wxString, std::unique_ptr<LIB_SYMBOL>> flatAltCache;
2562
2563 for( SCH_SHEET_PATH& sheet : m_sheetList )
2564 {
2565 SCH_SCREEN* screen = sheet.LastScreen();
2566
2567 if( !screen )
2568 continue;
2569
2570 std::vector<SCH_MARKER*> markers;
2571
2572 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
2573 {
2574 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2575 SCH_SYMBOL_INSTANCE instance;
2576
2577 if( !symbol->GetInstance( instance, sheet.Path() ) )
2578 continue;
2579
2580 auto addMarker =
2581 [&]( int aErrorCode, const wxString& aMessage )
2582 {
2583 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( aErrorCode );
2584
2585 ercItem->SetItems( symbol );
2586 ercItem->SetSheetSpecificPath( sheet );
2587 ercItem->SetErrorMessage( aMessage );
2588
2589 markers.emplace_back(
2590 new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2591 err_count++;
2592 };
2593
2594 for( const auto& [variantName, variant] : instance.m_Variants )
2595 {
2596 if( !variant.m_SymbolOverride )
2597 continue;
2598
2599 const LIB_ID& libId = *variant.m_SymbolOverride;
2600 wxString libIdStr = libId.Format();
2601
2602 // A self-referencing override is ignored by resolution, so skip it here too.
2603 if( libId == symbol->GetLibId() )
2604 continue;
2605
2606 auto cacheIt = flatAltCache.find( libIdStr );
2607
2608 if( cacheIt == flatAltCache.end() )
2609 {
2610 std::unique_ptr<LIB_SYMBOL> flatAlt;
2611
2612 try
2613 {
2614 if( LIB_SYMBOL* altSymbol = adapter->LoadSymbol( libId ) )
2615 flatAlt = altSymbol->Flatten();
2616 }
2617 catch( const IO_ERROR& )
2618 {
2619 }
2620
2621 cacheIt = flatAltCache.emplace( libIdStr, std::move( flatAlt ) ).first;
2622 }
2623
2624 const LIB_SYMBOL* flatAlt = cacheIt->second.get();
2625
2626 if( !flatAlt )
2627 {
2628 if( m_settings.IsTestEnabled( ERCE_VARIANT_SYMBOL_INVALID ) )
2629 {
2630 addMarker( ERCE_VARIANT_SYMBOL_INVALID,
2631 wxString::Format( _( "Variant '%s': symbol '%s' not found in libraries" ),
2632 variantName, libIdStr ) );
2633 }
2634
2635 continue;
2636 }
2637
2638 if( !m_settings.IsTestEnabled( ERCE_VARIANT_SYMBOL_INCOMPATIBLE ) )
2639 continue;
2640
2641 // The schematic's library symbol is stored flattened, so compare it directly.
2642 LIB_SYMBOL* baseSymbol = symbol->GetLibSymbolRef().get();
2643
2644 if( !baseSymbol )
2645 continue;
2646
2647 std::vector<VARIANT_COMPAT_RESULT> issues =
2648 ValidateVariantSymbolCompatibility( *baseSymbol, *flatAlt );
2649
2650 for( const VARIANT_COMPAT_RESULT& issue : issues )
2651 {
2653 wxString::Format( _( "Variant '%s', alternate '%s': %s" ),
2654 variantName, libIdStr, issue.detail ) );
2655 }
2656 }
2657 }
2658
2659 for( SCH_MARKER* marker : markers )
2660 screen->Append( marker );
2661 }
2662
2663 return err_count;
2664}
2665
2666
2668 KIFACE* aCvPcb, PROJECT* aProject, PROGRESS_REPORTER* aProgressReporter )
2669{
2670 m_sheetList.AnnotatePowerSymbols();
2671
2672 // Test duplicate sheet names inside a given sheet. While one can have multiple references
2673 // to the same file, each must have a unique name.
2674 if( m_settings.IsTestEnabled( ERCE_DUPLICATE_SHEET_NAME ) )
2675 {
2676 if( aProgressReporter )
2677 aProgressReporter->AdvancePhase( _( "Checking sheet names..." ) );
2678
2680 }
2681
2682 // Test pin-to-pad maps for stale pins, duplicate pad targets and bad pad references (issue #2282).
2683 if( m_settings.IsTestEnabled( ERCE_PIN_MAP_STALE_PIN ) || m_settings.IsTestEnabled( ERCE_PIN_MAP_DUPLICATE_PAD )
2684 || m_settings.IsTestEnabled( ERCE_PIN_MAP_BAD_PAD ) || m_settings.IsTestEnabled( ERCE_PIN_MAP_UNMAPPED_PIN ) )
2685 {
2686 if( aProgressReporter )
2687 aProgressReporter->AdvancePhase( _( "Checking pin maps..." ) );
2688
2689 TestPinMap( aCvPcb, aProject );
2690 }
2691
2692 // The connection graph has a whole set of ERC checks it can run
2693 if( aProgressReporter )
2694 aProgressReporter->AdvancePhase( _( "Checking conflicts..." ) );
2695
2696 // If we are using the new connectivity, make sure that we do a full-rebuild
2697 if( aEditFrame )
2698 {
2699 if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
2700 aEditFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
2701 else
2702 aEditFrame->RecalculateConnections( nullptr, NO_CLEANUP );
2703 }
2704
2705 m_schematic->ConnectionGraph()->RunERC();
2706
2707 if( aProgressReporter )
2708 aProgressReporter->AdvancePhase( _( "Checking units..." ) );
2709
2710 // Test is all units of each multiunit symbol have the same footprint assigned.
2711 if( m_settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_FP ) )
2712 {
2713 if( aProgressReporter )
2714 aProgressReporter->AdvancePhase( _( "Checking footprints..." ) );
2715
2717 }
2718
2719 if( m_settings.IsTestEnabled( ERCE_MISSING_UNIT )
2720 || m_settings.IsTestEnabled( ERCE_MISSING_INPUT_PIN )
2721 || m_settings.IsTestEnabled( ERCE_MISSING_POWER_INPUT_PIN )
2722 || m_settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
2723 {
2725 }
2726
2727 if( aProgressReporter )
2728 aProgressReporter->AdvancePhase( _( "Checking pins..." ) );
2729
2730 if( m_settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_NET ) )
2732
2733 if( m_settings.IsTestEnabled( ERCE_DUPLICATE_PIN_ERROR ) )
2735
2736 // Test pins on each net against the pin connection table
2737 if( m_settings.IsTestEnabled( ERCE_PIN_TO_PIN_ERROR )
2738 || m_settings.IsTestEnabled( ERCE_PIN_TO_PIN_WARNING )
2739 || m_settings.IsTestEnabled( ERCE_POWERPIN_NOT_DRIVEN )
2740 || m_settings.IsTestEnabled( ERCE_PIN_NOT_DRIVEN ) )
2741 {
2742 TestPinToPin();
2743 }
2744
2745 if( m_settings.IsTestEnabled( ERCE_GROUND_PIN_NOT_GROUND ) )
2747
2748 if( m_settings.IsTestEnabled( ERCE_STACKED_PIN_SYNTAX ) )
2750
2751 // Test similar labels (i;e. labels which are identical when
2752 // using case insensitive comparisons)
2753 if( m_settings.IsTestEnabled( ERCE_SIMILAR_LABELS )
2754 || m_settings.IsTestEnabled( ERCE_SIMILAR_POWER )
2755 || m_settings.IsTestEnabled( ERCE_SIMILAR_LABEL_AND_POWER ) )
2756 {
2757 if( aProgressReporter )
2758 aProgressReporter->AdvancePhase( _( "Checking similar labels..." ) );
2759
2761 }
2762
2763 if( m_settings.IsTestEnabled( ERCE_SAME_LOCAL_GLOBAL_LABEL )
2764 || m_settings.IsTestEnabled( ERCE_SAME_LOCAL_GLOBAL_POWER ) )
2765 {
2766 if( aProgressReporter )
2767 aProgressReporter->AdvancePhase( _( "Checking local and global labels..." ) );
2768
2770 }
2771
2772 if( m_settings.IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) )
2773 {
2774 if( aProgressReporter )
2775 aProgressReporter->AdvancePhase( _( "Checking for unresolved variables..." ) );
2776
2777 TestTextVars( aDrawingSheet );
2778 }
2779
2780 if( m_settings.IsTestEnabled( ERCE_FIELD_NAME_WHITESPACE ) )
2781 {
2782 if( aProgressReporter )
2783 aProgressReporter->AdvancePhase( _( "Checking field names..." ) );
2784
2786 }
2787
2788 if( m_settings.IsTestEnabled( ERCE_EMPTY_LABEL_NAME ) )
2789 {
2790 if( aProgressReporter )
2791 aProgressReporter->AdvancePhase( _( "Checking for empty label names..." ) );
2792
2794 }
2795
2796 if( m_settings.IsTestEnabled( ERCE_SIMULATION_MODEL ) )
2797 {
2798 if( aProgressReporter )
2799 aProgressReporter->AdvancePhase( _( "Checking SPICE models..." ) );
2800
2802 }
2803
2804 if( m_settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED ) )
2805 {
2806 if( aProgressReporter )
2807 aProgressReporter->AdvancePhase( _( "Checking no connect pins for connections..." ) );
2808
2810 }
2811
2812 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES )
2813 || m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_MISMATCH ) )
2814 {
2815 if( aProgressReporter )
2816 aProgressReporter->AdvancePhase( _( "Checking for library symbol issues..." ) );
2817
2819 }
2820
2821 if( m_settings.IsTestEnabled( ERCE_FOOTPRINT_LINK_ISSUES ) && aCvPcb )
2822 {
2823 if( aProgressReporter )
2824 aProgressReporter->AdvancePhase( _( "Checking for footprint link issues..." ) );
2825
2826 TestFootprintLinkIssues( aCvPcb, aProject );
2827 }
2828
2829 if( m_settings.IsTestEnabled( ERCE_FOOTPRINT_FILTERS ) )
2830 {
2831 if( aProgressReporter )
2832 aProgressReporter->AdvancePhase( _( "Checking footprint assignments against footprint filters..." ) );
2833
2835 }
2836
2837 if( m_settings.IsTestEnabled( ERCE_ENDPOINT_OFF_GRID ) )
2838 {
2839 if( aProgressReporter )
2840 aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) );
2841
2843 }
2844
2845 if( m_settings.IsTestEnabled( ERCE_FOUR_WAY_JUNCTION ) )
2846 {
2847 if( aProgressReporter )
2848 aProgressReporter->AdvancePhase( _( "Checking for four way junctions..." ) );
2849
2851 }
2852
2853 if( m_settings.IsTestEnabled( ERCE_LABEL_MULTIPLE_WIRES ) )
2854 {
2855 if( aProgressReporter )
2856 aProgressReporter->AdvancePhase( _( "Checking for labels on more than one wire..." ) );
2857
2859 }
2860
2861 if( m_settings.IsTestEnabled( ERCE_UNDEFINED_NETCLASS ) )
2862 {
2863 if( aProgressReporter )
2864 aProgressReporter->AdvancePhase( _( "Checking for undefined netclasses..." ) );
2865
2867 }
2868
2869 if( m_settings.IsTestEnabled( ERCE_VARIANT_SYMBOL_INVALID )
2870 || m_settings.IsTestEnabled( ERCE_VARIANT_SYMBOL_INCOMPATIBLE ) )
2871 {
2872 if( aProgressReporter )
2873 aProgressReporter->AdvancePhase( _( "Checking variant symbols..." ) );
2874
2876 }
2877
2878 m_schematic->ResolveERCExclusionsPostUpdate();
2879}
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
constexpr Vec Centre() const
Definition box2.h:93
A subgraph is a set of items that are electrically connected on a single sheet.
const std::set< SCH_ITEM * > & GetItems() const
Provide a read-only reference to the items in the subgraph.
const SCH_ITEM * GetNoConnect() const
const SCH_SHEET_PATH & GetSheet() const
Base class to handle basic graphic items.
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
DS_DRAW_ITEM_BASE * GetFirst()
void BuildDrawItemsList(const PAGE_INFO &aPageInfo, const TITLE_BLOCK &aTitleBlock)
Drawing or plot the drawing sheet.
void SetFileName(const wxString &aFileName)
Set the filename to draw/plot.
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
DS_DRAW_ITEM_BASE * GetNext()
void SetProject(const PROJECT *aProject)
A graphic text.
const PAGE_INFO & GetPageInfo()
const TITLE_BLOCK & GetTitleBlock()
virtual VECTOR2I GetPosition() const
Definition eda_item.h:282
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:110
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:221
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition erc_item.cpp:305
A class used to associate a SCH_PIN with its owning SCH_SHEET_PATH, in order to handle ERC checks acr...
const SCH_SHEET_PATH & Sheet() const
Get the SCH_SHEET_PATH context for the paired SCH_PIN.
SCH_PIN * Pin() const
Get the SCH_PIN for this context.
int TestLibSymbolIssues()
Test symbols for changed library symbols and broken symbol library links.
Definition erc.cpp:2135
const NET_MAP & m_nets
Definition erc.h:228
int TestStackedPinNotation()
Checks for pin numbers that resemble stacked pin notation but are invalid.
Definition erc.cpp:1900
void TestTextVars(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Check for any unresolved text variable references.
Definition erc.cpp:389
int TestPinToPin()
Checks the full netlist against the pin-to-pin connectivity requirements.
Definition erc.cpp:1253
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition erc.cpp:2020
SCH_MULTI_UNIT_REFERENCE_MAP m_refMap
Definition erc.h:227
SCH_SCREENS m_screens
Definition erc.h:226
int TestEmptyLabelNames()
Check for labels with empty or whitespace-only names.
Definition erc.cpp:672
int TestFootprintLinkIssues(KIFACE *aCvPcb, PROJECT *aProject)
Test footprint links against the current footprint libraries.
Definition erc.cpp:2257
int TestOffGridEndpoints()
Test pins and wire ends for being off grid.
Definition erc.cpp:2413
int TestDuplicateSheetNames(bool aCreateMarker)
Inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated).
Definition erc.cpp:145
int TestSameLocalGlobalLabel()
Checks for global and local labels with the same name.
Definition erc.cpp:1936
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition erc.cpp:1699
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
Definition erc.cpp:1162
int TestFootprintFilters()
Test symbols to ensure that assigned footprint passes any given footprint filters.
Definition erc.cpp:2343
int TestPinMap(KIFACE *aCvPcb, PROJECT *aProject)
Check pin-to-pad maps (issue #2282): stale pin references, duplicate pad targets, bad pads and unmapp...
Definition erc.cpp:188
int TestFieldNameWhitespace()
Check for field names with leading or trailing whitespace.
Definition erc.cpp:711
int TestDuplicatePinNets()
Checks if duplicate pin numbers within a symbol are connected to different nets.
Definition erc.cpp:1753
ERC_SETTINGS & m_settings
Definition erc.h:224
int TestFourWayJunction()
Test to see if there are potentially confusing 4-way junctions in the schematic.
Definition erc.cpp:1083
int TestMissingNetclasses()
Tests for netclasses that are referenced but not defined.
Definition erc.cpp:975
int TestSimModelIssues()
Test SPICE models for various issues.
Definition erc.cpp:2495
SCH_SHEET_LIST m_sheetList
Definition erc.h:225
bool m_showAllErrors
Definition erc.h:229
int TestGroundPins()
Checks for ground-labeled pins not on a ground net while another pin is.
Definition erc.cpp:1832
SCHEMATIC * m_schematic
Definition erc.h:223
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition erc.cpp:2667
int TestMissingUnits()
Test for uninstantiated units of multi unit symbols.
Definition erc.cpp:841
int TestLabelMultipleWires()
Test to see if there are labels that are connected to more than one wire.
Definition erc.cpp:1028
int TestVariantSymbols()
Test all variant symbol overrides for resolution and pin compatibility.
Definition erc.cpp:2549
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition erc.cpp:780
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
bool IsLibraryLoaded(const wxString &aNickname)
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
std::optional< LIBRARY_TABLE_ROW * > GetRow(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH)
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:65
wxString GetUniStringLibId() const
Definition lib_id.h:144
UTF8 Format() const
Definition lib_id.cpp:132
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
Definition lib_id.h:108
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:83
Define a library symbol object.
Definition lib_symbol.h:114
std::vector< const SCH_PIN * > GetGraphicalPins(int aUnit=0, int aBodyStyle=0) const
Graphical pins: Return schematic pin objects as drawn (unexpanded), filtered by unit/body.
const std::vector< ASSOCIATED_FOOTPRINT > & GetEffectiveAssociatedFootprints() const
Definition lib_symbol.h:290
std::vector< SCH_PIN * > GetPins() const override
const PIN_MAP_SET & GetEffectivePinMaps() const
Definition lib_symbol.h:275
void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode) override
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
bool GetDuplicatePinNumbersAreJumpers() const
Definition lib_symbol.h:850
std::vector< std::set< wxString > > & JumperPinGroups()
Each jumper pin group is a set of pin numbers that should be treated as internally connected.
Definition lib_symbol.h:857
wxString GetUnitDisplayName(int aUnit, bool aLabel) const override
Return the user-defined display name for aUnit for symbols with units.
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:126
A symbol-owned ordered set of named pin maps.
Definition pin_map.h:123
bool IsEmpty() const
Definition pin_map.h:139
const std::vector< PIN_MAP > & GetAll() const
Definition pin_map.h:138
const PIN_MAP * FindByName(const wxString &aName) const
Definition pin_map.cpp:133
A named pin map.
Definition pin_map.h:64
const std::vector< PIN_MAP_ENTRY > & GetEntries() const
Definition pin_map.h:91
const wxString & GetName() const
Definition pin_map.h:69
A progress reporter interface for use in multi-threaded environments.
virtual void AdvancePhase()=0
Use the next available virtual zone of the dialog progress bar.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
Container for project specific data.
Definition project.h:63
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Class for a wire to bus entry.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString GetNetName() const
Schematic editor (Eeschema) main window.
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, PROGRESS_REPORTER *aProgressReporter=nullptr)
Generate the connection data for the entire schematic hierarchy.
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0, const wxString &aVariantName=wxEmptyString) const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
int GetBodyStyle() const
Definition sch_item.h:242
bool ResolveExcludedFromSim(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const
Definition sch_item.cpp:298
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const override
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:38
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition sch_line.cpp:755
VECTOR2I GetEndPoint() const
Definition sch_line.h:144
VECTOR2I GetStartPoint() const
Definition sch_line.h:135
bool IsEndPoint(const VECTOR2I &aPoint) const override
Test if aPt is an end point of this schematic object.
Definition sch_line.h:87
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
bool IsVisible() const
Definition sch_pin.cpp:485
PAD_RESOLUTION
Outcome of pin-to-pad resolution (issue #2282).
Definition sch_pin.h:161
VECTOR2I GetPosition() const override
Definition sch_pin.cpp:350
bool IsStacked(const SCH_PIN *aPin) const
Definition sch_pin.cpp:575
bool IsPower() const
Check if the pin is either a global or local power pin.
Definition sch_pin.cpp:479
ELECTRICAL_PINTYPE GetType() const
Definition sch_pin.cpp:407
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
SCH_REFERENCE & GetItem(size_t aIdx)
A helper to define a symbol's reference designator in a schematic.
const SCH_SHEET_PATH & GetSheetPath() const
const wxString GetFootprint() const
SCH_SYMBOL * GetSymbol() const
LIB_SYMBOL * GetLibPart() const
int GetUnit() const
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:115
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
VECTOR2I GetPosition() const override
Definition sch_shape.h:84
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the sheet's fields.
Definition sch_sheet.h:87
VECTOR2I GetPosition() const override
Definition sch_sheet.h:490
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition sch_sheet.h:227
wxString GetShownName(bool aAllowExtraText) const
Definition sch_sheet.h:132
Schematic symbol object.
Definition sch_symbol.h:69
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
bool IsGlobalPower() const override
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText, const wxString &aVariantName=wxEmptyString) const override
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
const wxString GetFootprintFieldText(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText, const wxString &aVariantName=wxEmptyString) const
VECTOR2I GetPosition() const override
Definition sch_symbol.h:914
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:158
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:177
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
virtual wxString GetShownText(const RENDER_SETTINGS *aSettings, const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
VECTOR2I GetPosition() const override
Definition sch_text.h:146
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_text.cpp:341
virtual wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const
Definition sch_text.cpp:362
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
An interface to the global shared library manager that is schematic-specific and linked to one projec...
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
const TRANSFORM & GetTransform() const
Definition symbol.h:243
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition transform.cpp:40
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
Definition vector2d.h:549
A wrapper for reporting to a wxString object.
Definition reporter.h:225
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition common.cpp:721
The common library.
#define FOR_ERC_DRC
Expand '${var-name}' templates in text.
Definition common.h:95
#define _(s)
@ NO_RECURSE
Definition eda_item.h:50
void CheckDuplicatePins(LIB_SYMBOL *aSymbol, std::vector< wxString > &aMessages, UNITS_PROVIDER *aUnitsProvider)
const wxString CommentERC_V[]
Definition erc.cpp:98
const wxString CommentERC_H[]
Definition erc.cpp:81
const std::set< ELECTRICAL_PINTYPE > DrivenPinTypes
Definition erc.cpp:136
const std::set< ELECTRICAL_PINTYPE > DrivingPinTypes
Definition erc.cpp:118
const std::set< ELECTRICAL_PINTYPE > DrivingPowerPinTypes
Definition erc.cpp:130
ERCE_T
ERC error codes.
@ ERCE_POWERPIN_NOT_DRIVEN
Power input pin connected to some others pins but no power out pin to drive it.
@ ERCE_SIMILAR_POWER
2 power pins are equal for case insensitive comparisons.
@ ERCE_MISSING_POWER_INPUT_PIN
Symbol has power input pins that are not placed on the schematic.
@ ERCE_GROUND_PIN_NOT_GROUND
A ground-labeled pin is not on a ground net while another pin is.
@ ERCE_SIMILAR_LABELS
2 labels are equal for case insensitive comparisons.
@ ERCE_VARIANT_SYMBOL_INCOMPATIBLE
Variant symbol override fails pin compatibility.
@ ERCE_STACKED_PIN_SYNTAX
Pin name resembles stacked pin notation.
@ ERCE_ENDPOINT_OFF_GRID
Pin or wire-end off grid.
@ ERCE_EMPTY_LABEL_NAME
Label has an empty or whitespace-only name.
@ ERCE_SAME_LOCAL_GLOBAL_LABEL
2 labels are equal for case insensitive comparisons.
@ ERCE_SIMILAR_LABEL_AND_POWER
label and pin are equal for case insensitive comparisons.
@ ERCE_SAME_LOCAL_GLOBAL_POWER
Local power port and global power port have the same name.
@ ERCE_PIN_MAP_BAD_PAD
Pin map references a pad absent from the footprint.
@ ERCE_FOOTPRINT_LINK_ISSUES
The footprint link is invalid, or points to a missing (or inactive) footprint or library.
@ ERCE_PIN_MAP_DUPLICATE_PAD
Two symbol pins map to one pad (not stacked/jumper).
@ ERCE_DUPLICATE_PIN_ERROR
@ ERCE_DIFFERENT_UNIT_NET
Shared pin in a multi-unit symbol is connected to more than one net.
@ ERCE_FOUR_WAY_JUNCTION
A four-way junction was found.
@ ERCE_UNDEFINED_NETCLASS
A netclass was referenced but not defined.
@ ERCE_UNRESOLVED_VARIABLE
A text variable could not be resolved.
@ ERCE_SIMULATION_MODEL
An error was found in the simulation model.
@ ERCE_LIB_SYMBOL_MISMATCH
Symbol doesn't match copy in library.
@ ERCE_GENERIC_ERROR
@ ERCE_DIFFERENT_UNIT_FP
Different units of the same symbol have different footprints assigned.
@ ERCE_NOCONNECT_CONNECTED
A no connect symbol is connected to more than 1 pin.
@ ERCE_PIN_TO_PIN_WARNING
@ ERCE_PIN_NOT_DRIVEN
Pin connected to some others pins but no pin to drive it.
@ ERCE_MISSING_INPUT_PIN
Symbol has input pins that are not placed.
@ ERCE_MISSING_UNIT
Symbol has units that are not placed on the schematic.
@ ERCE_FIELD_NAME_WHITESPACE
Field name has leading or trailing whitespace.
@ ERCE_DUPLICATE_SHEET_NAME
Duplicate sheet names within a given sheet.
@ ERCE_PIN_MAP_STALE_PIN
Pin map references a pin number not on the symbol.
@ ERCE_MISSING_BIDI_PIN
Symbol has bi-directional pins that are not placed.
@ ERCE_LIB_SYMBOL_ISSUES
Symbol not found in active libraries.
@ ERCE_FOOTPRINT_FILTERS
The assigned footprint doesn't match the footprint filters.
@ ERCE_GENERIC_WARNING
@ ERCE_VARIANT_SYMBOL_INVALID
Variant symbol override LIB_ID cannot be resolved.
@ ERCE_PIN_MAP_UNMAPPED_PIN
A connected pin resolves to no footprint pad.
@ ERCE_LABEL_MULTIPLE_WIRES
A label is connected to more than one wire.
@ ERCE_PIN_TO_PIN_ERROR
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
const wxChar *const traceSchNetChain
Flag to enable tracing of schematic net chain rebuild and ERC cross-chain checks.
@ KIFACE_TEST_FOOTPRINT_LINK_LIBRARY_NOT_ENABLED
Definition kiface_ids.h:56
@ KIFACE_TEST_FOOTPRINT_LINK
Definition kiface_ids.h:54
@ KIFACE_TEST_FOOTPRINT_LINK_NO_LIBRARY
Definition kiface_ids.h:55
@ KIFACE_TEST_FOOTPRINT_LINK_NO_FOOTPRINT
Definition kiface_ids.h:57
@ KIFACE_FOOTPRINT_PAD_NUMBERS
Function pointer type: void (*)( const wxString& aFootprint, PROJECT* aProject, std::set<wxString>& a...
Definition kiface_ids.h:62
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition pin_type.h:32
@ PT_INPUT
usual pin input: must be connected
Definition pin_type.h:33
@ PT_NC
not connected (must be left open)
Definition pin_type.h:46
@ PT_OUTPUT
usual output
Definition pin_type.h:34
@ PT_TRISTATE
tri state bus pin
Definition pin_type.h:36
@ PT_BIDI
input or output (like port for a microprocessor)
Definition pin_type.h:35
@ PT_POWER_OUT
output of a regulator: intended to be connected to power input pins
Definition pin_type.h:43
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:42
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
Definition pin_type.h:41
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE)
Definition pin_type.cpp:203
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
static const std::vector< KICAD_T > labelTypes
Definition sch_field.cpp:44
@ NO_CLEANUP
Definition schematic.h:77
@ GLOBAL_CLEANUP
Definition schematic.h:79
std::vector< wxString > ExpandStackedPinNotation(const wxString &aPinName, bool *aValid)
Expand stacked pin notation like [1,2,3], [1-4], [A1-A4], or [AA1-AA3,AB4,CD12-CD14] into individual ...
wxString UnescapeString(const wxString &aSource)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
A first-class footprint choice on a LIB_SYMBOL, tied to a named pin map.
Definition pin_map.h:158
Implement a participant in the KIWAY alchemy.
Definition kiway.h:152
virtual void * IfaceOrAddress(int aDataId)=0
Return pointer to the requested object.
One symbol-pin to footprint-pad mapping inside a PIN_MAP.
Definition pin_map.h:41
A simple container for schematic symbol instance information.
std::map< wxString, SCH_SYMBOL_VARIANT > m_Variants
A list of symbol variants.
IbisParser parser & reporter
KIBIS_MODEL * model
KIBIS_PIN * pin
wxLogTrace helper definitions.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71
@ SCH_LINE_T
Definition typeinfo.h:160
@ SCH_NO_CONNECT_T
Definition typeinfo.h:157
@ SCH_SYMBOL_T
Definition typeinfo.h:169
@ SCH_FIELD_T
Definition typeinfo.h:147
@ SCH_LABEL_T
Definition typeinfo.h:164
@ SCH_LOCATE_ANY_T
Definition typeinfo.h:196
@ SCH_SHEET_T
Definition typeinfo.h:172
@ SCH_HIER_LABEL_T
Definition typeinfo.h:166
@ SCH_TEXT_T
Definition typeinfo.h:148
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:158
@ SCH_TEXTBOX_T
Definition typeinfo.h:149
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:165
@ SCH_PIN_T
Definition typeinfo.h:150
std::vector< VARIANT_COMPAT_RESULT > ValidateVariantSymbolCompatibility(const LIB_SYMBOL &aBase, const LIB_SYMBOL &aCandidate)
Check whether aCandidate can be used as a variant symbol override for aBase.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683