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 <numeric>
24#include <set>
25
26#include "connection_graph.h"
27#include "kiface_ids.h"
28#include <advanced_config.h>
29#include <common.h> // for ExpandEnvVarSubstitutions
30#include <erc/erc.h>
33#include <string_utils.h>
34#include <sch_pin.h>
35#include <project_sch.h>
38#include <sch_bus_entry.h>
39#include <sch_edit_frame.h>
40#include <sch_marker.h>
41#include <sch_reference_list.h>
42#include <sch_rule_area.h>
43#include <sch_sheet.h>
44#include <sch_sheet_pin.h>
45#include <sch_pin.h>
46#include <sch_textbox.h>
47#include <sch_line.h>
48#include <schematic.h>
51#include <vector>
52#include <wx/ffile.h>
53#include <sim/sim_lib_mgr.h>
54#include <progress_reporter.h>
55#include <kiway.h>
56#include <pgm_base.h>
58#include <trace_helpers.h>
59
60
61/* ERC tests :
62 * 1 - conflicts between connected pins ( example: 2 connected outputs )
63 * 2 - minimal connections requirements ( 1 input *must* be connected to an
64 * output, or a passive pin )
65 */
66
67/*
68 * Minimal ERC requirements:
69 * All pins *must* be connected (except ELECTRICAL_PINTYPE::PT_NC).
70 * When a pin is not connected in schematic, the user must place a "non
71 * connected" symbol to this pin.
72 * This ensures a forgotten connection will be detected.
73 */
74
75// Messages for matrix rows:
76const wxString CommentERC_H[] =
77{
78 _( "Input Pin" ),
79 _( "Output Pin" ),
80 _( "Bidirectional Pin" ),
81 _( "Tri-State Pin" ),
82 _( "Passive Pin" ),
83 _( "Free Pin" ),
84 _( "Unspecified Pin" ),
85 _( "Power Input Pin" ),
86 _( "Power Output Pin" ),
87 _( "Open Collector" ),
88 _( "Open Emitter" ),
89 _( "No Connection" )
90};
91
92// Messages for matrix columns
93const wxString CommentERC_V[] =
94{
95 _( "Input Pin" ),
96 _( "Output Pin" ),
97 _( "Bidirectional Pin" ),
98 _( "Tri-State Pin" ),
99 _( "Passive Pin" ),
100 _( "Free Pin" ),
101 _( "Unspecified Pin" ),
102 _( "Power Input Pin" ),
103 _( "Power Output Pin" ),
104 _( "Open Collector" ),
105 _( "Open Emitter" ),
106 _( "No Connection" )
107};
108
109
110// List of pin types that are considered drivers for usual input pins
111// i.e. pin type = ELECTRICAL_PINTYPE::PT_INPUT, but not PT_POWER_IN
112// that need only a PT_POWER_OUT pin type to be driven
121
122// List of pin types that are considered drivers for power pins
123// In fact only a ELECTRICAL_PINTYPE::PT_POWER_OUT pin type can drive
124// power input pins
125const std::set<ELECTRICAL_PINTYPE> DrivingPowerPinTypes =
126{
128};
129
130// List of pin types that require a driver elsewhere on the net
131const std::set<ELECTRICAL_PINTYPE> DrivenPinTypes =
132{
135};
136
137extern void CheckDuplicatePins( LIB_SYMBOL* aSymbol, std::vector<wxString>& aMessages,
138 UNITS_PROVIDER* aUnitsProvider );
139
140int ERC_TESTER::TestDuplicateSheetNames( bool aCreateMarker )
141{
142 int err_count = 0;
143
144 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
145 {
146 std::vector<SCH_SHEET*> list;
147
148 for( SCH_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
149 list.push_back( static_cast<SCH_SHEET*>( item ) );
150
151 for( size_t i = 0; i < list.size(); i++ )
152 {
153 SCH_SHEET* sheet = list[i];
154
155 for( size_t j = i + 1; j < list.size(); j++ )
156 {
157 SCH_SHEET* test_item = list[j];
158
159 // We have found a second sheet: compare names
160 // we are using case insensitive comparison to avoid mistakes between
161 // similar names like Mysheet and mysheet
162 if( sheet->GetShownName( false ).IsSameAs( test_item->GetShownName( false ), false ) )
163 {
164 if( aCreateMarker )
165 {
167 ercItem->SetItems( sheet, test_item );
168
169 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), sheet->GetPosition() );
170 screen->Append( marker );
171 }
172
173 err_count++;
174 }
175 }
176 }
177 }
178
179 return err_count;
180}
181
182
184{
186
187 auto unresolved =
188 [this]( wxString str )
189 {
190 str = ExpandEnvVarSubstitutions( str, &m_schematic->Project() );
191 return str.Matches( wxS( "*${*}*" ) );
192 };
193
194 auto testAssertion =
195 []( const SCH_ITEM* item, const SCH_SHEET_PATH& sheet, SCH_SCREEN* screen,
196 const wxString& text, const VECTOR2I& pos )
197 {
198 static wxRegEx warningExpr( wxS( "^\\$\\{ERC_WARNING\\s*([^}]*)\\}(.*)$" ) );
199 static wxRegEx errorExpr( wxS( "^\\$\\{ERC_ERROR\\s*([^}]*)\\}(.*)$" ) );
200
201 if( warningExpr.Matches( text ) )
202 {
203 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_GENERIC_WARNING );
204 wxString ercText = warningExpr.GetMatch( text, 1 );
205
206 if( item )
207 ercItem->SetItems( item );
208 else
209 ercText += _( " (in drawing sheet)" );
210
211 ercItem->SetSheetSpecificPath( sheet );
212 ercItem->SetErrorMessage( ercText );
213
214 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pos );
215 screen->Append( marker );
216
217 return true;
218 }
219
220 if( errorExpr.Matches( text ) )
221 {
222 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_GENERIC_ERROR );
223 wxString ercText = errorExpr.GetMatch( text, 1 );
224
225 if( item )
226 ercItem->SetItems( item );
227 else
228 ercText += _( " (in drawing sheet)" );
229
230 ercItem->SetSheetSpecificPath( sheet );
231 ercItem->SetErrorMessage( ercText );
232
233 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pos );
234 screen->Append( marker );
235
236 return true;
237 }
238
239 return false;
240 };
241
242 if( aDrawingSheet )
243 {
244 wsItems.SetPageNumber( wxS( "1" ) );
245 wsItems.SetSheetCount( 1 );
246 wsItems.SetFileName( wxS( "dummyFilename" ) );
247 wsItems.SetSheetName( wxS( "dummySheet" ) );
248 wsItems.SetSheetLayer( wxS( "dummyLayer" ) );
249 wsItems.SetProject( &m_schematic->Project() );
250 wsItems.BuildDrawItemsList( aDrawingSheet->GetPageInfo(), aDrawingSheet->GetTitleBlock() );
251 }
252
253 for( const SCH_SHEET_PATH& sheet : m_sheetList )
254 {
255 SCH_SCREEN* screen = sheet.LastScreen();
256
257 for( SCH_ITEM* item : screen->Items().OfType( SCH_LOCATE_ANY_T ) )
258 {
259 if( item->Type() == SCH_SYMBOL_T )
260 {
261 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
262
263 for( SCH_FIELD& field : symbol->GetFields() )
264 {
265 if( unresolved( field.GetShownText( &sheet, true ) ) )
266 {
268 ercItem->SetItems( symbol );
269 ercItem->SetSheetSpecificPath( sheet );
270
271 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), field.GetPosition() );
272 screen->Append( marker );
273 }
274
275 testAssertion( &field, sheet, screen, field.GetText(), field.GetPosition() );
276 }
277
278 if( symbol->GetLibSymbolRef() )
279 {
281 [&]( SCH_ITEM* child )
282 {
283 if( child->Type() == SCH_FIELD_T )
284 {
285 // test only SCH_SYMBOL fields, not LIB_SYMBOL fields
286 }
287 else if( child->Type() == SCH_TEXT_T )
288 {
289 SCH_TEXT* textItem = static_cast<SCH_TEXT*>( child );
290
291 if( unresolved( textItem->GetShownText( &sheet, true ) ) )
292 {
294 ercItem->SetItems( symbol );
295 ercItem->SetSheetSpecificPath( sheet );
296
297 BOX2I bbox = textItem->GetBoundingBox();
298 bbox = symbol->GetTransform().TransformCoordinate( bbox );
299 VECTOR2I pos = bbox.Centre() + symbol->GetPosition();
300
301 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pos );
302 screen->Append( marker );
303 }
304
305 testAssertion( symbol, sheet, screen, textItem->GetText(),
306 textItem->GetPosition() );
307 }
308 else if( child->Type() == SCH_TEXTBOX_T )
309 {
310 SCH_TEXTBOX* textboxItem = static_cast<SCH_TEXTBOX*>( child );
311
312 if( unresolved( textboxItem->GetShownText( nullptr, &sheet, true ) ) )
313 {
315 ercItem->SetItems( symbol );
316 ercItem->SetSheetSpecificPath( sheet );
317
318 BOX2I bbox = textboxItem->GetBoundingBox();
319 bbox = symbol->GetTransform().TransformCoordinate( bbox );
320 VECTOR2I pos = bbox.Centre() + symbol->GetPosition();
321
322 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pos );
323 screen->Append( marker );
324 }
325
326 testAssertion( symbol, sheet, screen, textboxItem->GetText(),
327 textboxItem->GetPosition() );
328 }
329 },
331 }
332 }
333 else if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( item ) )
334 {
335 for( SCH_FIELD& field : label->GetFields() )
336 {
337 if( unresolved( field.GetShownText( &sheet, true ) ) )
338 {
340 ercItem->SetItems( label );
341 ercItem->SetSheetSpecificPath( sheet );
342
343 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), field.GetPosition() );
344 screen->Append( marker );
345 }
346
347 testAssertion( &field, sheet, screen, field.GetText(), field.GetPosition() );
348 }
349 }
350 else if( item->Type() == SCH_SHEET_T )
351 {
352 SCH_SHEET* subSheet = static_cast<SCH_SHEET*>( item );
353
354 for( SCH_FIELD& field : subSheet->GetFields() )
355 {
356 if( unresolved( field.GetShownText( &sheet, true ) ) )
357 {
359 ercItem->SetItems( subSheet );
360 ercItem->SetSheetSpecificPath( sheet );
361
362 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), field.GetPosition() );
363 screen->Append( marker );
364 }
365
366 testAssertion( &field, sheet, screen, field.GetText(), field.GetPosition() );
367 }
368
369 SCH_SHEET_PATH subSheetPath = sheet;
370 subSheetPath.push_back( subSheet );
371
372 for( SCH_SHEET_PIN* pin : subSheet->GetPins() )
373 {
374 if( pin->GetShownText( &subSheetPath, true ).Matches( wxS( "*${*}*" ) ) )
375 {
377 ercItem->SetItems( pin );
378 ercItem->SetSheetSpecificPath( sheet );
379
380 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
381 screen->Append( marker );
382 }
383 }
384 }
385 else if( SCH_TEXT* text = dynamic_cast<SCH_TEXT*>( item ) )
386 {
387 if( text->GetShownText( &sheet, true ).Matches( wxS( "*${*}*" ) ) )
388 {
390 ercItem->SetItems( text );
391 ercItem->SetSheetSpecificPath( sheet );
392
393 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), text->GetPosition() );
394 screen->Append( marker );
395 }
396
397 testAssertion( text, sheet, screen, text->GetText(), text->GetPosition() );
398 }
399 else if( SCH_TEXTBOX* textBox = dynamic_cast<SCH_TEXTBOX*>( item ) )
400 {
401 if( textBox->GetShownText( nullptr, &sheet, true ).Matches( wxS( "*${*}*" ) ) )
402 {
404 ercItem->SetItems( textBox );
405 ercItem->SetSheetSpecificPath( sheet );
406
407 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), textBox->GetPosition() );
408 screen->Append( marker );
409 }
410
411 testAssertion( textBox, sheet, screen, textBox->GetText(), textBox->GetPosition() );
412 }
413 }
414
415 for( DS_DRAW_ITEM_BASE* item = wsItems.GetFirst(); item; item = wsItems.GetNext() )
416 {
417 if( DS_DRAW_ITEM_TEXT* text = dynamic_cast<DS_DRAW_ITEM_TEXT*>( item ) )
418 {
419 if( testAssertion( nullptr, sheet, screen, text->GetText(), text->GetPosition() ) )
420 {
421 // Don't run unresolved test
422 }
423 else if( text->GetShownText( true ).Matches( wxS( "*${*}*" ) ) )
424 {
425 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
426 ercItem->SetErrorMessage( _( "Unresolved text variable in drawing sheet" ) );
427 ercItem->SetSheetSpecificPath( sheet );
428
429 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), text->GetPosition() );
430 screen->Append( marker );
431 }
432 }
433 }
434 }
435}
436
437
439{
440 int warnings = 0;
441
442 for( const SCH_SHEET_PATH& sheet : m_sheetList )
443 {
444 SCH_SCREEN* screen = sheet.LastScreen();
445
446 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
447 {
448 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
449
450 for( SCH_FIELD& field : symbol->GetFields() )
451 {
452 wxString trimmedFieldName = field.GetName();
453 trimmedFieldName.Trim();
454 trimmedFieldName.Trim( false );
455
456 if( field.GetName() != trimmedFieldName )
457 {
459 ercItem->SetItems( symbol, &field );
460 ercItem->SetItemsSheetPaths( sheet, sheet );
461 ercItem->SetSheetSpecificPath( sheet );
462 ercItem->SetErrorMessage(
463 wxString::Format(
464 _( "Field name has leading or trailing whitespace: '%s'" ),
465 field.GetName() ) );
466
467 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), field.GetPosition() );
468 screen->Append( marker );
469 warnings++;
470 }
471 }
472 }
473
474 for( SCH_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
475 {
476 SCH_SHEET* subSheet = static_cast<SCH_SHEET*>( item );
477
478 for( SCH_FIELD& field : subSheet->GetFields() )
479 {
480 wxString trimmedFieldName = field.GetName();
481 trimmedFieldName.Trim();
482 trimmedFieldName.Trim( false );
483
484 if( field.GetName() != trimmedFieldName )
485 {
487 ercItem->SetItems( subSheet, &field );
488 ercItem->SetItemsSheetPaths( sheet, sheet );
489 ercItem->SetSheetSpecificPath( sheet );
490 ercItem->SetErrorMessage(
491 wxString::Format(
492 _( "Field name has leading or trailing whitespace: '%s'" ),
493 field.GetName() ) );
494
495 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), field.GetPosition() );
496 screen->Append( marker );
497 warnings++;
498 }
499 }
500 }
501 }
502
503 return warnings;
504}
505
506
508{
509 int errors = 0;
510
511 for( std::pair<const wxString, SCH_REFERENCE_LIST>& symbol : m_refMap )
512 {
513 SCH_REFERENCE_LIST& refList = symbol.second;
514
515 if( refList.GetCount() == 0 )
516 {
517 wxFAIL; // it should not happen
518 continue;
519 }
520
521 // Reference footprint
522 SCH_SYMBOL* unit = nullptr;
523 wxString unitName;
524 wxString unitFP;
525
526 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
527 {
528 SCH_SHEET_PATH sheetPath = refList.GetItem( ii ).GetSheetPath();
529 unitFP = refList.GetItem( ii ).GetFootprint();
530
531 if( !unitFP.IsEmpty() )
532 {
533 unit = refList.GetItem( ii ).GetSymbol();
534 unitName = unit->GetRef( &sheetPath, true );
535 break;
536 }
537 }
538
539 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
540 {
541 SCH_REFERENCE& secondRef = refList.GetItem( ii );
542 SCH_SYMBOL* secondUnit = secondRef.GetSymbol();
543 wxString secondName = secondUnit->GetRef( &secondRef.GetSheetPath(), true );
544 const wxString secondFp = secondRef.GetFootprint();
545 wxString msg;
546
547 if( unit && !secondFp.IsEmpty() && unitFP != secondFp )
548 {
549 msg.Printf( _( "Different footprints assigned to %s and %s" ),
550 unitName, secondName );
551
552 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_FP );
553 ercItem->SetErrorMessage( msg );
554 ercItem->SetItems( unit, secondUnit );
555
556 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), secondUnit->GetPosition() );
557 secondRef.GetSheetPath().LastScreen()->Append( marker );
558
559 ++errors;
560 }
561 }
562 }
563
564 return errors;
565}
566
567
569{
570 int errors = 0;
571
572 for( std::pair<const wxString, SCH_REFERENCE_LIST>& symbol : m_refMap )
573 {
574 SCH_REFERENCE_LIST& refList = symbol.second;
575
576 wxCHECK2( refList.GetCount(), continue );
577
578 // Reference unit
579 SCH_REFERENCE& base_ref = refList.GetItem( 0 );
580 SCH_SYMBOL* unit = base_ref.GetSymbol();
581 LIB_SYMBOL* libSymbol = base_ref.GetLibPart();
582
583 if( static_cast<ssize_t>( refList.GetCount() ) == libSymbol->GetUnitCount() )
584 continue;
585
586 std::set<int> lib_units;
587 std::set<int> instance_units;
588 std::set<int> missing_units;
589
590 auto report =
591 [&]( std::set<int>& aMissingUnits, const wxString& aErrorMsg, int aErrorCode )
592 {
593 wxString msg;
594 wxString missing_pin_units = wxS( "[ " );
595 int ii = 0;
596
597 for( int missing_unit : aMissingUnits )
598 {
599 if( ii++ == 3 )
600 {
601 missing_pin_units += wxS( "..." );
602 break;
603 }
604
605 missing_pin_units += libSymbol->GetUnitDisplayName( missing_unit, false ) + ", " ;
606 }
607
608 missing_pin_units.Truncate( missing_pin_units.length() - 2 );
609 missing_pin_units += wxS( " ]" );
610
611 msg.Printf( aErrorMsg, symbol.first, missing_pin_units );
612
613 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( aErrorCode );
614 ercItem->SetErrorMessage( msg );
615 ercItem->SetItems( unit );
616 ercItem->SetSheetSpecificPath( base_ref.GetSheetPath() );
617 ercItem->SetItemsSheetPaths( base_ref.GetSheetPath() );
618
619 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), unit->GetPosition() );
620 base_ref.GetSheetPath().LastScreen()->Append( marker );
621
622 ++errors;
623 };
624
625 for( int ii = 1; ii <= libSymbol->GetUnitCount(); ++ii )
626 lib_units.insert( lib_units.end(), ii );
627
628 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
629 instance_units.insert( instance_units.end(), refList.GetItem( ii ).GetUnit() );
630
631 std::set_difference( lib_units.begin(), lib_units.end(),
632 instance_units.begin(), instance_units.end(),
633 std::inserter( missing_units, missing_units.begin() ) );
634
635 if( !missing_units.empty() && m_settings.IsTestEnabled( ERCE_MISSING_UNIT ) )
636 {
637 report( missing_units, _( "Symbol %s has unplaced units %s" ), ERCE_MISSING_UNIT );
638 }
639
640 std::set<int> missing_power;
641 std::set<int> missing_input;
642 std::set<int> missing_bidi;
643
644 for( int missing_unit : missing_units )
645 {
646 int bodyStyle = 0;
647
648 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
649 {
650 if( refList.GetItem( ii ).GetUnit() == missing_unit )
651 {
652 bodyStyle = refList.GetItem( ii ).GetSymbol()->GetBodyStyle();
653 break;
654 }
655 }
656
657 for( SCH_PIN* pin : libSymbol->GetGraphicalPins( missing_unit, bodyStyle ) )
658 {
659 switch( pin->GetType() )
660 {
662 missing_power.insert( missing_unit );
663 break;
664
666 missing_bidi.insert( missing_unit );
667 break;
668
670 missing_input.insert( missing_unit );
671 break;
672
673 default:
674 break;
675 }
676 }
677 }
678
679 if( !missing_power.empty() && m_settings.IsTestEnabled( ERCE_MISSING_POWER_INPUT_PIN ) )
680 {
681 report( missing_power, _( "Symbol %s has input power pins in units %s that are not placed" ),
683 }
684
685 if( !missing_input.empty() && m_settings.IsTestEnabled( ERCE_MISSING_INPUT_PIN ) )
686 {
687 report( missing_input, _( "Symbol %s has input pins in units %s that are not placed" ),
689 }
690
691 if( !missing_bidi.empty() && m_settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
692 {
693 report( missing_bidi, _( "Symbol %s has bidirectional pins in units %s that are not placed" ),
695 }
696 }
697
698 return errors;
699}
700
701
703{
704 int err_count = 0;
705 std::shared_ptr<NET_SETTINGS>& settings = m_schematic->Project().GetProjectFile().NetSettings();
706 wxString defaultNetclass = settings->GetDefaultNetclass()->GetName();
707
708 auto logError =
709 [&]( const SCH_SHEET_PATH& sheet, SCH_ITEM* item, const wxString& netclass )
710 {
711 err_count++;
712
713 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNDEFINED_NETCLASS );
714
715 ercItem->SetItems( item );
716 ercItem->SetErrorMessage( wxString::Format( _( "Netclass %s is not defined" ), netclass ) );
717
718 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), item->GetPosition() );
719 sheet.LastScreen()->Append( marker );
720 };
721
722 for( const SCH_SHEET_PATH& sheet : m_sheetList )
723 {
724 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
725 {
726 item->RunOnChildren(
727 [&]( SCH_ITEM* aChild )
728 {
729 if( aChild->Type() == SCH_FIELD_T )
730 {
731 SCH_FIELD* field = static_cast<SCH_FIELD*>( aChild );
732
733 if( field->GetCanonicalName() == wxT( "Netclass" ) )
734 {
735 wxString netclass = field->GetShownText( &sheet, false );
736
737 if( !netclass.empty() && !netclass.IsSameAs( defaultNetclass )
738 && !settings->HasNetclass( netclass ) )
739 {
740 logError( sheet, item, netclass );
741 }
742 }
743 }
744
745 return true;
746 },
748 }
749 }
750
751 return err_count;
752}
753
754
756{
757 int err_count = 0;
758
759 for( const SCH_SHEET_PATH& sheet : m_sheetList )
760 {
761 std::map<VECTOR2I, std::vector<SCH_ITEM*>> connMap;
762
763 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_LABEL_T ) )
764 {
765 SCH_LABEL* label = static_cast<SCH_LABEL*>( item );
766
767 for( const VECTOR2I& pt : label->GetConnectionPoints() )
768 connMap[pt].emplace_back( label );
769 }
770
771 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
772 {
773 std::vector<SCH_ITEM*> lines;
774
775 for( SCH_ITEM* item : sheet.LastScreen()->Items().Overlapping( SCH_LINE_T, pair.first ) )
776 {
777 SCH_LINE* line = static_cast<SCH_LINE*>( item );
778
779 if( line->IsGraphicLine() )
780 continue;
781
782 // If the line is connected at the endpoint, then there will be a junction
783 if( !line->IsEndPoint( pair.first ) )
784 lines.emplace_back( line );
785 }
786
787 if( lines.size() > 1 )
788 {
789 err_count++;
790 lines.resize( 3 ); // Only show the first 3 lines and if there are only two, adds a nullptr
791
792 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LABEL_MULTIPLE_WIRES );
793 wxString msg = wxString::Format( _( "Label connects more than one wire at %d, %d" ),
794 pair.first.x, pair.first.y );
795
796 ercItem->SetItems( pair.second.front(), lines[0], lines[1], lines[2] );
797 ercItem->SetErrorMessage( msg );
798 ercItem->SetSheetSpecificPath( sheet );
799
800 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pair.first );
801 sheet.LastScreen()->Append( marker );
802 }
803 }
804 }
805
806 return err_count;
807}
808
809
811{
812 int err_count = 0;
813
814 auto pinStackAlreadyRepresented =
815 []( SCH_PIN* pin, std::vector<SCH_ITEM*>& collection ) -> bool
816 {
817 for( SCH_ITEM*& item : collection )
818 {
819 if( item->Type() == SCH_PIN_T && item->GetParentSymbol() == pin->GetParentSymbol() )
820 {
821 if( pin->IsVisible() && !static_cast<SCH_PIN*>( item )->IsVisible() )
822 item = pin;
823
824 return true;
825 }
826 }
827
828 return false;
829 };
830
831 for( const SCH_SHEET_PATH& sheet : m_sheetList )
832 {
833 std::map<VECTOR2I, std::vector<SCH_ITEM*>> connMap;
834 SCH_SCREEN* screen = sheet.LastScreen();
835
836 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
837 {
838 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
839
840 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
841 {
842 std::vector<SCH_ITEM*>& entry = connMap[pin->GetPosition()];
843
844 // Only one pin per pin-stack.
845 if( pinStackAlreadyRepresented( pin, entry ) )
846 continue;
847
848 entry.emplace_back( pin );
849 }
850 }
851
852 for( SCH_ITEM* item : screen->Items().OfType( SCH_LINE_T ) )
853 {
854 SCH_LINE* line = static_cast<SCH_LINE*>( item );
855
856 if( line->IsGraphicLine() )
857 continue;
858
859 for( const VECTOR2I& pt : line->GetConnectionPoints() )
860 connMap[pt].emplace_back( line );
861 }
862
863 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
864 {
865 if( pair.second.size() >= 4 )
866 {
867 err_count++;
868
869 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOUR_WAY_JUNCTION );
870
871 ercItem->SetItems( pair.second[0], pair.second[1], pair.second[2], pair.second[3] );
872
873 wxString msg = wxString::Format( _( "Four items connected at %d, %d" ),
874 pair.first.x, pair.first.y );
875 ercItem->SetErrorMessage( msg );
876
877 ercItem->SetSheetSpecificPath( sheet );
878
879 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pair.first );
880 sheet.LastScreen()->Append( marker );
881 }
882 }
883 }
884
885 return err_count;
886}
887
888
890{
891 int err_count = 0;
892
893 for( const SCH_SHEET_PATH& sheet : m_sheetList )
894 {
895 std::map<VECTOR2I, std::vector<SCH_ITEM*>> pinMap;
896
897 auto addOther =
898 [&]( const VECTOR2I& pt, SCH_ITEM* aOther )
899 {
900 if( pinMap.count( pt ) )
901 pinMap[pt].emplace_back( aOther );
902 };
903
904 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
905 {
906 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
907
908 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
909 {
910 if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC )
911 pinMap[pin->GetPosition()].emplace_back( pin );
912 }
913 }
914
915 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
916 {
917 if( item->Type() == SCH_SYMBOL_T )
918 {
919 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
920
921 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
922 {
923 if( pin->GetType() != ELECTRICAL_PINTYPE::PT_NC )
924 addOther( pin->GetPosition(), pin );
925 }
926 }
927 else if( item->IsConnectable() && item->Type() != SCH_NO_CONNECT_T )
928 {
929 for( const VECTOR2I& pt : item->GetConnectionPoints() )
930 addOther( pt, item );
931 }
932 }
933
934 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : pinMap )
935 {
936 if( pair.second.size() > 1 )
937 {
938 bool all_nc = true;
939
940 for( SCH_ITEM* item : pair.second )
941 {
942 if( item->Type() != SCH_PIN_T )
943 {
944 all_nc = false;
945 break;
946 }
947
948 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
949
950 if( pin->GetType() != ELECTRICAL_PINTYPE::PT_NC )
951 {
952 all_nc = false;
953 break;
954 }
955 }
956
957 if( all_nc )
958 continue;
959
960 err_count++;
961
962 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED );
963
964 ercItem->SetItems( pair.second[0], pair.second[1],
965 pair.second.size() > 2 ? pair.second[2] : nullptr,
966 pair.second.size() > 3 ? pair.second[3] : nullptr );
967 ercItem->SetErrorMessage( _( "Pin with 'no connection' type is connected" ) );
968 ercItem->SetSheetSpecificPath( sheet );
969
970 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pair.first );
971 sheet.LastScreen()->Append( marker );
972 }
973 }
974 }
975
976 return err_count;
977}
978
979
981{
982 int errors = 0;
983
984 // Map each net name to the pins (with sheet context) found on that net so we can later
985 // perform cross-net compatibility checks for grouped net chains.
986 std::unordered_map<wxString, std::vector<ERC_SCH_PIN_CONTEXT>> netToPins;
987
988 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
989 {
990 using iterator_t = std::vector<ERC_SCH_PIN_CONTEXT>::iterator;
991 std::vector<ERC_SCH_PIN_CONTEXT> pins;
992 std::unordered_map<EDA_ITEM*, SCH_SCREEN*> pinToScreenMap;
993 bool has_noconnect = false;
994
995 for( CONNECTION_SUBGRAPH* subgraph: net.second )
996 {
997 if( subgraph->GetNoConnect() )
998 has_noconnect = true;
999
1000 for( SCH_ITEM* item : subgraph->GetItems() )
1001 {
1002 if( item->Type() == SCH_PIN_T )
1003 {
1004 pins.emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
1005 netToPins[ net.first.Name ].emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
1006 pinToScreenMap[item] = subgraph->GetSheet().LastScreen();
1007 }
1008 }
1009 }
1010
1011 std::sort( pins.begin(), pins.end(),
1012 []( const ERC_SCH_PIN_CONTEXT& lhs, const ERC_SCH_PIN_CONTEXT& rhs )
1013 {
1014 int ret = StrNumCmp( lhs.Pin()->GetParentSymbol()->GetRef( &lhs.Sheet() ),
1015 rhs.Pin()->GetParentSymbol()->GetRef( &rhs.Sheet() ) );
1016
1017 if( ret == 0 )
1018 ret = StrNumCmp( lhs.Pin()->GetNumber(), rhs.Pin()->GetNumber() );
1019
1020 if( ret == 0 )
1021 ret = lhs < rhs; // Fallback to hash to guarantee deterministic sort
1022
1023 return ret < 0;
1024 } );
1025
1026 ERC_SCH_PIN_CONTEXT needsDriver;
1028 bool hasDriver = false;
1029 std::vector<ERC_SCH_PIN_CONTEXT*> pinsNeedingDrivers;
1030 std::vector<ERC_SCH_PIN_CONTEXT*> nonPowerPinsNeedingDrivers;
1031 std::vector<ERC_SCH_PIN_CONTEXT*> powerInPinsNeedingDrivers;
1032
1033 // We need different drivers for power nets and normal nets.
1034 // A power net has at least one pin having the ELECTRICAL_PINTYPE::PT_POWER_IN
1035 // and power nets can be driven only by ELECTRICAL_PINTYPE::PT_POWER_OUT pins
1036 bool ispowerNet = false;
1037
1038 for( ERC_SCH_PIN_CONTEXT& refPin : pins )
1039 {
1040 if( refPin.Pin()->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
1041 {
1042 ispowerNet = true;
1043 break;
1044 }
1045 }
1046
1047 std::vector<std::tuple<iterator_t, iterator_t, PIN_ERROR>> pin_mismatches;
1048 std::map<iterator_t, int> pin_mismatch_counts;
1049
1050 for( auto refIt = pins.begin(); refIt != pins.end(); ++refIt )
1051 {
1052 ERC_SCH_PIN_CONTEXT& refPin = *refIt;
1053 ELECTRICAL_PINTYPE refType = refPin.Pin()->GetType();
1054
1055 if( DrivenPinTypes.contains( refType ) )
1056 {
1057 // needsDriver will be the pin shown in the error report eventually, so try to
1058 // upgrade to a "better" pin if possible: something visible and only a power symbol
1059 // if this net needs a power driver
1060 pinsNeedingDrivers.push_back( &refPin );
1061
1062 if( !refPin.Pin()->IsPower() )
1063 nonPowerPinsNeedingDrivers.push_back( &refPin );
1064
1065 if( refType == ELECTRICAL_PINTYPE::PT_POWER_IN )
1066 powerInPinsNeedingDrivers.push_back( &refPin );
1067
1068 if( !needsDriver.Pin()
1069 || ( !needsDriver.Pin()->IsVisible() && refPin.Pin()->IsVisible() )
1070 || ( ispowerNet != ( needsDriverType == ELECTRICAL_PINTYPE::PT_POWER_IN )
1071 && ispowerNet == ( refType == ELECTRICAL_PINTYPE::PT_POWER_IN ) ) )
1072 {
1073 needsDriver = refPin;
1074 needsDriverType = needsDriver.Pin()->GetType();
1075 }
1076 }
1077
1078 if( ispowerNet )
1079 hasDriver |= ( DrivingPowerPinTypes.count( refType ) != 0 );
1080 else
1081 hasDriver |= ( DrivingPinTypes.count( refType ) != 0 );
1082
1083 for( auto testIt = refIt + 1; testIt != pins.end(); ++testIt )
1084 {
1085 ERC_SCH_PIN_CONTEXT& testPin = *testIt;
1086
1087 // Multiple pins in the same symbol that share a type,
1088 // name and position are considered
1089 // "stacked" and shouldn't trigger ERC errors
1090 if( refPin.Pin()->IsStacked( testPin.Pin() ) && refPin.Sheet() == testPin.Sheet() )
1091 continue;
1092
1093 ELECTRICAL_PINTYPE testType = testPin.Pin()->GetType();
1094
1095 if( ispowerNet )
1096 hasDriver |= DrivingPowerPinTypes.contains( testType );
1097 else
1098 hasDriver |= DrivingPinTypes.contains( testType );
1099
1100 PIN_ERROR erc = m_settings.GetPinMapValue( refType, testType );
1101
1104
1105 if( erc != PIN_ERROR::OK && m_settings.IsTestEnabled( ercCode ) )
1106 {
1107 pin_mismatches.emplace_back( std::tuple<iterator_t, iterator_t, PIN_ERROR>{ refIt, testIt, erc } );
1108
1109 if( m_settings.GetERCSortingMetric() == ERC_PIN_SORTING_METRIC::SM_HEURISTICS )
1110 {
1111 pin_mismatch_counts[refIt] = m_settings.GetPinTypeWeight( ( *refIt ).Pin()->GetType() );
1112 pin_mismatch_counts[testIt] = m_settings.GetPinTypeWeight( ( *testIt ).Pin()->GetType() );
1113 }
1114 else
1115 {
1116 if( !pin_mismatch_counts.contains( testIt ) )
1117 pin_mismatch_counts.emplace( testIt, 1 );
1118 else
1119 pin_mismatch_counts[testIt]++;
1120
1121 if( !pin_mismatch_counts.contains( refIt ) )
1122 pin_mismatch_counts.emplace( refIt, 1 );
1123 else
1124 pin_mismatch_counts[refIt]++;
1125 }
1126 }
1127 }
1128 }
1129
1130 std::multimap<size_t, iterator_t, std::greater<size_t>> pins_dsc;
1131
1132 std::transform( pin_mismatch_counts.begin(), pin_mismatch_counts.end(),
1133 std::inserter( pins_dsc, pins_dsc.begin() ),
1134 []( const auto& p )
1135 {
1136 return std::pair<size_t, iterator_t>( p.second, p.first );
1137 } );
1138
1139 for( const auto& [amount, pinItBind] : pins_dsc )
1140 {
1141 auto& pinIt = pinItBind;
1142
1143 if( pin_mismatches.empty() )
1144 break;
1145
1146 SCH_PIN* pin = ( *pinIt ).Pin();
1147 VECTOR2I position = pin->GetPosition();
1148
1149 iterator_t nearest_pin = pins.end();
1150 double smallest_distance = std::numeric_limits<double>::infinity();
1151 PIN_ERROR erc;
1152
1153 std::erase_if(
1154 pin_mismatches,
1155 [&]( const auto& tuple )
1156 {
1157 iterator_t other;
1158
1159 if( pinIt == std::get<0>( tuple ) )
1160 other = std::get<1>( tuple );
1161 else if( pinIt == std::get<1>( tuple ) )
1162 other = std::get<0>( tuple );
1163 else
1164 return false;
1165
1166 if( ( *pinIt ).Sheet().Cmp( ( *other ).Sheet() ) != 0 )
1167 {
1168 if( std::isinf( smallest_distance ) )
1169 {
1170 nearest_pin = other;
1171 erc = std::get<2>( tuple );
1172 }
1173 }
1174 else
1175 {
1176 double distance = position.Distance( ( *other ).Pin()->GetPosition() );
1177
1178 if( std::isinf( smallest_distance ) || distance < smallest_distance )
1179 {
1180 smallest_distance = distance;
1181 nearest_pin = other;
1182 erc = std::get<2>( tuple );
1183 }
1184 }
1185
1186 return true;
1187 } );
1188
1189 if( nearest_pin != pins.end() )
1190 {
1191 SCH_PIN* other_pin = ( *nearest_pin ).Pin();
1192
1195 ercItem->SetItems( pin, other_pin );
1196 ercItem->SetSheetSpecificPath( ( *pinIt ).Sheet() );
1197 ercItem->SetItemsSheetPaths( ( *pinIt ).Sheet(), ( *nearest_pin ).Sheet() );
1198
1199 ercItem->SetErrorMessage( wxString::Format( _( "Pins of type %s and %s are connected" ),
1200 ElectricalPinTypeGetText( pin->GetType() ),
1201 ElectricalPinTypeGetText( other_pin->GetType() ) ) );
1202
1203 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
1204 pinToScreenMap[pin]->Append( marker );
1205 errors++;
1206 }
1207 }
1208
1209 if( needsDriver.Pin() && !hasDriver && !has_noconnect )
1210 {
1211 int err_code = ispowerNet ? ERCE_POWERPIN_NOT_DRIVEN : ERCE_PIN_NOT_DRIVEN;
1212
1213 // NEW: For power nets, before reporting a not-driven error, look across the
1214 // net chain (multi-net chain formed via passives) to see if there is a
1215 // power driver pin on any other net in the same chain. If so, suppress the
1216 // error because the net chain as a whole is driven.
1217 bool suppressForNetChainDriver = false;
1218
1219 if( ispowerNet && m_schematic && m_schematic->ConnectionGraph() )
1220 {
1221 const wxString& thisNetName = net.first.Name;
1222 const auto& netChains = m_schematic->ConnectionGraph()->GetCommittedNetChains();
1223
1224 auto netHasPowerDriver = [&]( const wxString& aNetName ) -> bool
1225 {
1226 // Scan m_nets for the named net and test its pins for a power driver type.
1227 for( const auto& n : m_nets )
1228 {
1229 if( n.first.Name != aNetName )
1230 continue;
1231
1232 for( CONNECTION_SUBGRAPH* sg : n.second )
1233 {
1234 for( SCH_ITEM* item : sg->GetItems() )
1235 {
1236 if( item->Type() == SCH_PIN_T )
1237 {
1238 SCH_PIN* p = static_cast<SCH_PIN*>( item );
1239 if( DrivingPowerPinTypes.contains( p->GetType() ) )
1240 return true;
1241 }
1242 }
1243 }
1244
1245 break; // found matching net (whether driver or not)
1246 }
1247
1248 return false;
1249 };
1250
1251 for( const auto& sig : netChains )
1252 {
1253 if( !sig )
1254 continue;
1255
1256 const auto& sigNets = sig->GetNets();
1257 bool containsThisNet = std::find( sigNets.begin(), sigNets.end(), thisNetName ) != sigNets.end();
1258
1259 if( !containsThisNet )
1260 continue;
1261
1262 // Look for a different net in this chain that has a power driver.
1263 for( const wxString& otherNet : sigNets )
1264 {
1265 if( otherNet == thisNetName )
1266 continue; // skip same net (we already know it lacks a driver)
1267
1268 if( netHasPowerDriver( otherNet ) )
1269 {
1270 suppressForNetChainDriver = true;
1271 break;
1272 }
1273 }
1274
1275 break; // examined the containing chain
1276 }
1277 }
1278
1279 if( !suppressForNetChainDriver && m_settings.IsTestEnabled( err_code ) )
1280 {
1281 std::vector<ERC_SCH_PIN_CONTEXT*> pinsToMark;
1282
1283 // The marker should land on a pin matching the error message: for an
1284 // ERCE_POWERPIN_NOT_DRIVEN error mark a PT_POWER_IN pin (which is what the
1285 // error refers to), for ERCE_PIN_NOT_DRIVEN prefer a pin that is not on a
1286 // power symbol so the marker is anchored to the consuming pin rather than
1287 // a power flag.
1288 if( m_showAllErrors )
1289 {
1290 if( ispowerNet && !powerInPinsNeedingDrivers.empty() )
1291 pinsToMark = powerInPinsNeedingDrivers;
1292 else if( !nonPowerPinsNeedingDrivers.empty() )
1293 pinsToMark = nonPowerPinsNeedingDrivers;
1294 else
1295 pinsToMark = pinsNeedingDrivers;
1296 }
1297 else
1298 {
1299 if( ispowerNet && !powerInPinsNeedingDrivers.empty() )
1300 pinsToMark.push_back( powerInPinsNeedingDrivers.front() );
1301 else
1302 pinsToMark.push_back( &needsDriver );
1303 }
1304
1305 for( ERC_SCH_PIN_CONTEXT* pinCtx : pinsToMark )
1306 {
1307 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( err_code );
1308
1309 ercItem->SetItems( pinCtx->Pin() );
1310 ercItem->SetSheetSpecificPath( pinCtx->Sheet() );
1311 ercItem->SetItemsSheetPaths( pinCtx->Sheet() );
1312
1313 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pinCtx->Pin()->GetPosition() );
1314 pinToScreenMap[pinCtx->Pin()]->Append( marker );
1315 errors++;
1316 }
1317 }
1318 }
1319 }
1320
1321 // --- Additional net-chain-level checking ---
1322 // If a pin participates in a grouped net chain (spanning multiple nets via passives), ensure
1323 // that all other pins reachable through that chain are electrically compatible even if
1324 // they reside on different nets.
1325 // We only consider pairs on DIFFERENT nets here to avoid duplicating existing net-level
1326 // mismatches already reported above.
1327 if( m_schematic && m_schematic->ConnectionGraph() )
1328 {
1329 auto& netChains = m_schematic->ConnectionGraph()->GetCommittedNetChains();
1330 wxLogTrace( traceSchNetChain, "ERC TestPinToPin: cross-chain phase start chains=%zu",
1331 netChains.size() );
1332
1333 for( const auto& sig : netChains )
1334 {
1335 if( !sig )
1336 continue;
1337
1338 const wxString chainName = sig->GetName();
1339 const auto& sigNets = sig->GetNets();
1340
1341 // Collect all pin contexts across the nets in this chain.
1342 std::vector<ERC_SCH_PIN_CONTEXT> netChainPins;
1343 netChainPins.reserve( sigNets.size() * 4 );
1344
1345 for( const wxString& n : sigNets )
1346 {
1347 auto it = netToPins.find( n );
1348 if( it != netToPins.end() )
1349 {
1350 const auto& vec = it->second;
1351 netChainPins.insert( netChainPins.end(), vec.begin(), vec.end() );
1352 }
1353 }
1354
1355 if( netChainPins.size() < 2 )
1356 continue; // nothing to compare
1357
1358 wxLogTrace( traceSchNetChain,
1359 "ERC TestPinToPin: chain '%s' nets=%zu collectedPins=%zu",
1360 TO_UTF8( chainName ), sigNets.size(), netChainPins.size() );
1361
1362 // For deterministic behavior, sort by reference/pin number similar to earlier pass.
1363 std::sort( netChainPins.begin(), netChainPins.end(),
1364 []( const ERC_SCH_PIN_CONTEXT& lhs, const ERC_SCH_PIN_CONTEXT& rhs )
1365 {
1366 int ret = StrNumCmp( lhs.Pin()->GetParentSymbol()->GetRef( &lhs.Sheet() ),
1367 rhs.Pin()->GetParentSymbol()->GetRef( &rhs.Sheet() ) );
1368 if( ret == 0 )
1369 ret = StrNumCmp( lhs.Pin()->GetNumber(), rhs.Pin()->GetNumber() );
1370 if( ret == 0 )
1371 ret = lhs < rhs;
1372 return ret < 0;
1373 } );
1374
1375 // Build a quick map from pin -> net name for skipping intra-net pairs.
1376 std::unordered_map<SCH_PIN*, wxString> pinNet;
1377 for( const auto& netEntry : netToPins )
1378 for( const auto& ctx : netEntry.second )
1379 pinNet[ ctx.Pin() ] = netEntry.first;
1380
1381 for( size_t i = 0; i < netChainPins.size(); ++i )
1382 {
1383 SCH_PIN* aPin = netChainPins[i].Pin();
1384 ELECTRICAL_PINTYPE aType = aPin->GetType();
1385 const wxString& aNet = pinNet[aPin];
1386
1387 for( size_t j = i + 1; j < netChainPins.size(); ++j )
1388 {
1389 SCH_PIN* bPin = netChainPins[j].Pin();
1390 const wxString& bNet = pinNet[bPin];
1391
1392 if( aNet == bNet )
1393 continue; // already handled at net-level
1394
1395 ELECTRICAL_PINTYPE bType = bPin->GetType();
1396 PIN_ERROR erc = m_settings.GetPinMapValue( aType, bType );
1397
1400
1401 if( erc != PIN_ERROR::OK && m_settings.IsTestEnabled( ercCode ) )
1402 {
1403 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ercCode );
1404
1405 ercItem->SetItems( aPin, bPin );
1406 ercItem->SetSheetSpecificPath( netChainPins[i].Sheet() );
1407 ercItem->SetItemsSheetPaths( netChainPins[i].Sheet(), netChainPins[j].Sheet() );
1408 ercItem->SetErrorMessage( wxString::Format(
1409 _( "Pins of type %s and %s are connected via net chain %s" ),
1410 ElectricalPinTypeGetText( aType ),
1411 ElectricalPinTypeGetText( bType ), chainName ) );
1412
1413 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), aPin->GetPosition() );
1414 netChainPins[i].Sheet().LastScreen()->Append( marker );
1415 errors++;
1416 }
1417 }
1418 }
1419 }
1420 }
1421
1422 return errors;
1423}
1424
1425
1427{
1428 int errors = 0;
1429
1430 std::unordered_map<wxString, std::pair<wxString, SCH_PIN*>> pinToNetMap;
1431
1432 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1433 {
1434 const wxString& netName = net.first.Name;
1435
1436 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1437 {
1438 for( SCH_ITEM* item : subgraph->GetItems() )
1439 {
1440 if( item->Type() == SCH_PIN_T )
1441 {
1442 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1443 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1444
1445 if( !pin->GetParentSymbol()->IsMultiUnit() )
1446 continue;
1447
1448 wxString name = pin->GetParentSymbol()->GetRef( &sheet ) + ":" + pin->GetShownNumber();
1449
1450 if( !pinToNetMap.count( name ) )
1451 {
1452 pinToNetMap[name] = std::make_pair( netName, pin );
1453 }
1454 else if( pinToNetMap[name].first != netName )
1455 {
1456 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_NET );
1457
1458 ercItem->SetErrorMessage( wxString::Format( _( "Pin %s is connected to both %s and %s" ),
1459 pin->GetShownNumber(),
1460 netName,
1461 pinToNetMap[name].first ) );
1462
1463 ercItem->SetItems( pin, pinToNetMap[name].second );
1464 ercItem->SetSheetSpecificPath( sheet );
1465 ercItem->SetItemsSheetPaths( sheet, sheet );
1466
1467 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
1468 sheet.LastScreen()->Append( marker );
1469 errors += 1;
1470 }
1471 }
1472 }
1473 }
1474 }
1475
1476 return errors;
1477}
1478
1479
1481{
1482 int errors = 0;
1483
1484 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1485 {
1486 SCH_SCREEN* screen = sheet.LastScreen();
1487
1488 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1489 {
1490 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1491 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
1492
1493 if( !libSymbol )
1494 continue;
1495
1496 if( libSymbol->GetDuplicatePinNumbersAreJumpers() )
1497 continue;
1498
1499 std::vector<SCH_PIN*> pins = symbol->GetPins( &sheet );
1500
1501 std::map<wxString, std::vector<std::pair<SCH_PIN*, wxString>>> pinsByNumber;
1502
1503 for( SCH_PIN* pin : pins )
1504 {
1505 SCH_CONNECTION* conn = pin->Connection( &sheet );
1506 wxString netName = conn ? conn->GetNetName() : wxString();
1507
1508 pinsByNumber[pin->GetNumber()].emplace_back( pin, netName );
1509 }
1510
1511 for( const auto& [pinNumber, pinNetPairs] : pinsByNumber )
1512 {
1513 if( pinNetPairs.size() < 2 )
1514 continue;
1515
1516 wxString firstNet = pinNetPairs[0].second;
1517 bool hasDifferentNets = false;
1518 SCH_PIN* conflictPin = nullptr;
1519
1520 for( size_t i = 1; i < pinNetPairs.size(); i++ )
1521 {
1522 if( pinNetPairs[i].second != firstNet )
1523 {
1524 hasDifferentNets = true;
1525 conflictPin = pinNetPairs[i].first;
1526 break;
1527 }
1528 }
1529
1530 if( hasDifferentNets )
1531 {
1532 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DUPLICATE_PIN_ERROR );
1533 wxString msg;
1534
1535 msg.Printf( _( "Pin %s on symbol '%s' is connected to different nets: %s and %s" ),
1536 pinNumber,
1537 symbol->GetRef( &sheet ),
1538 firstNet.IsEmpty() ? _( "<no net>" ) : firstNet,
1539 pinNetPairs[1].second.IsEmpty() ? _( "<no net>" ) : pinNetPairs[1].second );
1540
1541 ercItem->SetErrorMessage( msg );
1542 ercItem->SetItems( pinNetPairs[0].first, conflictPin );
1543 ercItem->SetSheetSpecificPath( sheet );
1544 ercItem->SetItemsSheetPaths( sheet, sheet );
1545
1546 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ),
1547 pinNetPairs[0].first->GetPosition() );
1548 screen->Append( marker );
1549 errors++;
1550 }
1551 }
1552 }
1553 }
1554
1555 return errors;
1556}
1557
1558
1560{
1561 int errors = 0;
1562
1563 auto isGround =
1564 []( const wxString& txt )
1565 {
1566 wxString upper = txt.Upper();
1567
1568 return upper.Contains( wxT( "GND" ) )
1569 || upper == wxT( "EARTH" ) || upper.StartsWith( wxT( "EARTH_" ) )
1570 || upper == wxT( "VSS" ) || upper == wxT( "VSSA" );
1571 };
1572
1573 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1574 {
1575 SCH_SCREEN* screen = sheet.LastScreen();
1576
1577 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1578 {
1579 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1580 bool hasGroundNet = false;
1581 std::vector<SCH_PIN*> mismatched;
1582
1583 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
1584 {
1585 SCH_CONNECTION* conn = pin->Connection( &sheet );
1586 wxString net = conn ? conn->GetNetName() : wxString();
1587 bool netIsGround = isGround( net );
1588
1589 // We are only interested in power pins
1590 if( pin->GetType() != ELECTRICAL_PINTYPE::PT_POWER_OUT
1591 && pin->GetType() != ELECTRICAL_PINTYPE::PT_POWER_IN )
1592 {
1593 continue;
1594 }
1595
1596 if( netIsGround )
1597 hasGroundNet = true;
1598
1599 if( isGround( pin->GetShownName() ) && !netIsGround )
1600 mismatched.push_back( pin );
1601 }
1602
1603 if( hasGroundNet )
1604 {
1605 for( SCH_PIN* pin : mismatched )
1606 {
1607 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_GROUND_PIN_NOT_GROUND );
1608
1609 ercItem->SetErrorMessage( wxString::Format( _( "Pin %s not connected to ground net" ),
1610 pin->GetShownName() ) );
1611 ercItem->SetItems( pin );
1612 ercItem->SetSheetSpecificPath( sheet );
1613 ercItem->SetItemsSheetPaths( sheet );
1614
1615 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
1616 screen->Append( marker );
1617 errors++;
1618 }
1619 }
1620 }
1621 }
1622
1623 return errors;
1624}
1625
1626
1628{
1629 int warnings = 0;
1630
1631 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1632 {
1633 SCH_SCREEN* screen = sheet.LastScreen();
1634
1635 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1636 {
1637 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1638
1639 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
1640 {
1641 bool valid;
1642 pin->GetStackedPinNumbers( &valid );
1643
1644 if( !valid )
1645 {
1646 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_STACKED_PIN_SYNTAX );
1647 ercItem->SetItems( pin );
1648 ercItem->SetSheetSpecificPath( sheet );
1649 ercItem->SetItemsSheetPaths( sheet );
1650
1651 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
1652 screen->Append( marker );
1653 warnings++;
1654 }
1655 }
1656 }
1657 }
1658
1659 return warnings;
1660}
1661
1662
1664{
1665 int errCount = 0;
1666
1667 std::unordered_map<wxString, std::pair<SCH_ITEM*, SCH_SHEET_PATH>> globalLabels;
1668 std::unordered_map<wxString, std::pair<SCH_ITEM*, SCH_SHEET_PATH>> localLabels;
1669
1670 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1671 {
1672 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1673 {
1674 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1675
1676 for( SCH_ITEM* item : subgraph->GetItems() )
1677 {
1678 if( item->Type() == SCH_LABEL_T || item->Type() == SCH_GLOBAL_LABEL_T )
1679 {
1680 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
1681 wxString text = label->GetShownText( &sheet, false );
1682
1683 auto& map = item->Type() == SCH_LABEL_T ? localLabels : globalLabels;
1684
1685 if( !map.count( text ) )
1686 {
1687 map[text] = std::make_pair( label, sheet );
1688 }
1689 }
1690 else if( item->Type() == SCH_PIN_T )
1691 {
1692 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1693
1694 if( !pin->IsPower() )
1695 continue;
1696
1697 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
1698
1699 if( !symbol )
1700 continue;
1701
1702 wxString text = ( pin->IsGlobalPower() && !symbol->IsGlobalPower() )
1703 ? pin->GetShownName()
1704 : symbol->GetValue( true, &sheet, false );
1705
1706 auto& map = pin->IsGlobalPower() ? globalLabels : localLabels;
1707
1708 if( !map.count( text ) )
1709 {
1710 map[text] = std::make_pair( pin, sheet );
1711 }
1712 }
1713 }
1714 }
1715 }
1716
1717 for( auto& [globalText, globalItem] : globalLabels )
1718 {
1719 for( auto& [localText, localItem] : localLabels )
1720 {
1721 if( globalText == localText )
1722 {
1723 ERCE_T errorCode = ( globalItem.first->Type() == SCH_PIN_T && localItem.first->Type() == SCH_PIN_T )
1726
1727 if( !m_settings.IsTestEnabled( errorCode ) )
1728 continue;
1729
1730 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( errorCode );
1731 ercItem->SetItems( globalItem.first, localItem.first );
1732 ercItem->SetSheetSpecificPath( globalItem.second );
1733 ercItem->SetItemsSheetPaths( globalItem.second, localItem.second );
1734
1735 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), globalItem.first->GetPosition() );
1736 globalItem.second.LastScreen()->Append( marker );
1737
1738 errCount++;
1739 }
1740 }
1741 }
1742
1743 return errCount;
1744}
1745
1746
1748{
1749 int errors = 0;
1750 std::unordered_map<wxString, std::vector<std::tuple<wxString, SCH_ITEM*, SCH_SHEET_PATH>>> generalMap;
1751
1752 auto logError =
1753 [&]( const wxString& normalized, SCH_ITEM* item, const SCH_SHEET_PATH& sheet,
1754 const std::tuple<wxString, SCH_ITEM*, SCH_SHEET_PATH>& other )
1755 {
1756 auto& [otherText, otherItem, otherSheet] = other;
1757 ERCE_T typeOfWarning = ERCE_SIMILAR_LABELS;
1758
1759 if( item->Type() == SCH_PIN_T && otherItem->Type() == SCH_PIN_T )
1760 {
1761 //Two Pins
1762 typeOfWarning = ERCE_SIMILAR_POWER;
1763 }
1764 else if( item->Type() == SCH_PIN_T || otherItem->Type() == SCH_PIN_T )
1765 {
1766 //Pin and Label
1767 typeOfWarning = ERCE_SIMILAR_LABEL_AND_POWER;
1768 }
1769 else
1770 {
1771 //Two Labels
1772 typeOfWarning = ERCE_SIMILAR_LABELS;
1773 }
1774
1775 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( typeOfWarning );
1776 ercItem->SetItems( item, otherItem );
1777 ercItem->SetSheetSpecificPath( sheet );
1778 ercItem->SetItemsSheetPaths( sheet, otherSheet );
1779
1780 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), item->GetPosition() );
1781 sheet.LastScreen()->Append( marker );
1782 };
1783
1784 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1785 {
1786 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1787 {
1788 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1789
1790 for( SCH_ITEM* item : subgraph->GetItems() )
1791 {
1792 switch( item->Type() )
1793 {
1794 case SCH_LABEL_T:
1795 case SCH_HIER_LABEL_T:
1796 case SCH_GLOBAL_LABEL_T:
1797 {
1798 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
1799 wxString unnormalized = label->GetShownText( &sheet, false );
1800 wxString normalized = unnormalized.Lower();
1801
1802 generalMap[normalized].emplace_back( std::make_tuple( unnormalized, label, sheet ) );
1803
1804 for( const auto& otherTuple : generalMap.at( normalized ) )
1805 {
1806 const auto& [otherText, otherItem, otherSheet] = otherTuple;
1807
1808 if( unnormalized != otherText )
1809 {
1810 // Similar local labels on different sheets are fine
1811 if( item->Type() == SCH_LABEL_T && otherItem->Type() == SCH_LABEL_T
1812 && sheet != otherSheet )
1813 {
1814 continue;
1815 }
1816
1817 logError( normalized, label, sheet, otherTuple );
1818 errors += 1;
1819 }
1820 }
1821
1822 break;
1823 }
1824 case SCH_PIN_T:
1825 {
1826 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1827
1828 if( !pin->IsPower() )
1829 continue;
1830
1831 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
1832 wxString unnormalized = symbol->GetValue( true, &sheet, false );
1833 wxString normalized = unnormalized.Lower();
1834
1835 generalMap[normalized].emplace_back( std::make_tuple( unnormalized, pin, sheet ) );
1836
1837 for( const auto& otherTuple : generalMap.at( normalized ) )
1838 {
1839 const auto& [otherText, otherItem, otherSheet] = otherTuple;
1840
1841 if( unnormalized != otherText )
1842 {
1843 logError( normalized, pin, sheet, otherTuple );
1844 errors += 1;
1845 }
1846 }
1847
1848 break;
1849 }
1850
1851 default:
1852 break;
1853 }
1854 }
1855 }
1856 }
1857
1858 return errors;
1859}
1860
1861
1863{
1864 wxCHECK( m_schematic, 0 );
1865
1866 LIBRARY_MANAGER& manager = Pgm().GetLibraryManager();
1868 wxString msg;
1869 int err_count = 0;
1870
1871 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
1872 {
1873 std::vector<SCH_MARKER*> markers;
1874
1875 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1876 {
1877 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1878 LIB_SYMBOL* libSymbolInSchematic = symbol->GetLibSymbolRef().get();
1879
1880 if( !libSymbolInSchematic )
1881 continue;
1882
1883 wxString libName = symbol->GetLibId().GetLibNickname();
1884
1885 std::optional<const LIBRARY_TABLE_ROW*> optRow =
1886 manager.GetRow( LIBRARY_TABLE_TYPE::SYMBOL, libName );
1887
1888 if( !optRow || ( *optRow )->Disabled() )
1889 {
1890 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
1891 {
1892 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1893 ercItem->SetItems( symbol );
1894 msg.Printf( _( "The current configuration does not include the symbol library '%s'" ),
1895 UnescapeString( libName ) );
1896 ercItem->SetErrorMessage( msg );
1897
1898 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
1899 }
1900
1901 continue;
1902 }
1903 else if( !adapter->IsLibraryLoaded( libName ) )
1904 {
1905 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
1906 {
1907 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1908 std::optional<wxString> uri =
1909 manager.GetFullURI( LIBRARY_TABLE_TYPE::SYMBOL, libName, true );
1910 wxCHECK2( uri.has_value(), uri = wxEmptyString );
1911 ercItem->SetItems( symbol );
1912 msg.Printf( _( "The symbol library '%s' was not found at '%s'" ),
1913 UnescapeString( libName ), *uri );
1914 ercItem->SetErrorMessage( msg );
1915
1916 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
1917 }
1918
1919 continue;
1920 }
1921
1922 wxString symbolName = symbol->GetLibId().GetLibItemName();
1923 LIB_SYMBOL* libSymbol = adapter->LoadSymbol( symbol->GetLibId() );
1924
1925 if( libSymbol == nullptr )
1926 {
1927 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
1928 {
1929 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1930 ercItem->SetItems( symbol );
1931 msg.Printf( _( "Symbol '%s' not found in symbol library '%s'" ),
1932 UnescapeString( symbolName ),
1933 UnescapeString( libName ) );
1934 ercItem->SetErrorMessage( msg );
1935
1936 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
1937 }
1938
1939 continue;
1940 }
1941
1942 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->Flatten();
1944
1945 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_MISMATCH ) )
1946 {
1947 // We have to check for duplicate pins first as they will cause Compare() to fail.
1948 // Symbols with duplicate pins are valid if those pins share the same net, so we
1949 // only skip the comparison here. The actual error checking for duplicate pins on
1950 // different nets is done in TestDuplicatePinNets().
1951 std::vector<wxString> messages;
1952
1953 if( !libSymbolInSchematic->GetDuplicatePinNumbersAreJumpers() )
1954 {
1955 UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILS );
1956 CheckDuplicatePins( libSymbolInSchematic, messages, &unitsProvider );
1957 }
1958
1959 if( messages.empty() && flattenedSymbol->Compare( *libSymbolInSchematic, flags ) != 0 )
1960 {
1961 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_MISMATCH );
1962 ercItem->SetItems( symbol );
1963 msg.Printf( _( "Symbol '%s' doesn't match copy in library '%s'" ),
1964 UnescapeString( symbolName ),
1965 UnescapeString( libName ) );
1966 ercItem->SetErrorMessage( msg );
1967
1968 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
1969 }
1970 }
1971 }
1972
1973 for( SCH_MARKER* marker : markers )
1974 {
1975 screen->Append( marker );
1976 err_count += 1;
1977 }
1978 }
1979
1980 return err_count;
1981}
1982
1983
1985{
1986 wxCHECK( m_schematic, 0 );
1987
1988 if( std::optional<LIBRARY_MANAGER_ADAPTER*> adapter =
1989 Pgm().GetLibraryManager().Adapter( LIBRARY_TABLE_TYPE::FOOTPRINT ) )
1990 {
1991 ( *adapter )->BlockUntilLoaded();
1992 }
1993
1994 wxString msg;
1995 int err_count = 0;
1996
1997 typedef int (*TESTER_FN_PTR)( const wxString&, PROJECT* );
1998
1999 TESTER_FN_PTR linkTester = (TESTER_FN_PTR) aCvPcb->IfaceOrAddress( KIFACE_TEST_FOOTPRINT_LINK );
2000
2001 for( SCH_SHEET_PATH& sheet : m_sheetList )
2002 {
2003 std::vector<SCH_MARKER*> markers;
2004
2005 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
2006 {
2007 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2008 wxString footprint = symbol->GetFootprintFieldText( true, &sheet, false );
2009
2010 if( footprint.IsEmpty() )
2011 continue;
2012
2013 LIB_ID fpID;
2014
2015 if( fpID.Parse( footprint, true ) >= 0 )
2016 {
2017 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2018 msg.Printf( _( "'%s' is not a valid footprint identifier" ), footprint );
2019 ercItem->SetErrorMessage( msg );
2020 ercItem->SetItems( symbol );
2021 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2022 continue;
2023 }
2024
2025 wxString libName = fpID.GetLibNickname();
2026 wxString fpName = fpID.GetLibItemName();
2027 int ret = (linkTester)( footprint, aProject );
2028
2030 {
2031 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2032 msg.Printf( _( "The current configuration does not include the footprint library '%s'" ),
2033 libName );
2034 ercItem->SetErrorMessage( msg );
2035 ercItem->SetItems( symbol );
2036 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2037 }
2039 {
2040 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2041 msg.Printf( _( "The footprint library '%s' is not enabled in the current configuration" ),
2042 libName );
2043 ercItem->SetErrorMessage( msg );
2044 ercItem->SetItems( symbol );
2045 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2046 }
2048 {
2049 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2050 msg.Printf( _( "Footprint '%s' not found in library '%s'" ),
2051 fpName,
2052 libName );
2053 ercItem->SetErrorMessage( msg );
2054 ercItem->SetItems( symbol );
2055 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2056 }
2057 }
2058
2059 for( SCH_MARKER* marker : markers )
2060 {
2061 sheet.LastScreen()->Append( marker );
2062 err_count += 1;
2063 }
2064 }
2065
2066 return err_count;
2067}
2068
2069
2071{
2072 wxCHECK( m_schematic, 0 );
2073
2074 wxString msg;
2075 int err_count = 0;
2076
2077 for( SCH_SHEET_PATH& sheet : m_sheetList )
2078 {
2079 std::vector<SCH_MARKER*> markers;
2080
2081 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
2082 {
2083 SCH_SYMBOL* sch_symbol = static_cast<SCH_SYMBOL*>( item );
2084 std::unique_ptr<LIB_SYMBOL>& lib_symbol = sch_symbol->GetLibSymbolRef();
2085
2086 if( !lib_symbol )
2087 continue;
2088
2089 wxArrayString filters = lib_symbol->GetFPFilters();
2090
2091 if( filters.empty() )
2092 continue;
2093
2094 wxString lowerId = sch_symbol->GetFootprintFieldText( true, &sheet, false ).Lower();
2095 LIB_ID footprint;
2096
2097 if( footprint.Parse( lowerId ) > 0 )
2098 continue;
2099
2100 wxString lowerItemName = footprint.GetUniStringLibItemName().Lower();
2101 bool found = false;
2102
2103 for( wxString filter : filters )
2104 {
2105 filter.LowerCase();
2106
2107 // If the filter contains a ':' character, include the library name in the pattern
2108 if( filter.Contains( wxS( ":" ) ) )
2109 found |= lowerId.Matches( filter );
2110 else
2111 found |= lowerItemName.Matches( filter );
2112
2113 if( found )
2114 break;
2115 }
2116
2117 if( !found )
2118 {
2119 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2120 msg.Printf( _( "Assigned footprint (%s) doesn't match footprint filters (%s)" ),
2121 footprint.GetUniStringLibItemName(),
2122 wxJoin( filters, ' ' ) );
2123 ercItem->SetErrorMessage( msg );
2124 ercItem->SetItems( sch_symbol );
2125 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), sch_symbol->GetPosition() ) );
2126 }
2127 }
2128
2129 for( SCH_MARKER* marker : markers )
2130 {
2131 sheet.LastScreen()->Append( marker );
2132 err_count += 1;
2133 }
2134 }
2135
2136 return err_count;
2137}
2138
2139
2141{
2142 const int gridSize = m_schematic->Settings().m_ConnectionGridSize;
2143 int err_count = 0;
2144
2145 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
2146 {
2147 std::vector<SCH_MARKER*> markers;
2148
2149 for( SCH_ITEM* item : screen->Items() )
2150 {
2151 if( item->Type() == SCH_LINE_T && item->IsConnectable() )
2152 {
2153 SCH_LINE* line = static_cast<SCH_LINE*>( item );
2154
2155 if( ( line->GetStartPoint().x % gridSize ) != 0
2156 || ( line->GetStartPoint().y % gridSize ) != 0 )
2157 {
2158 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
2159 ercItem->SetItems( line );
2160
2161 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), line->GetStartPoint() ) );
2162 }
2163 else if( ( line->GetEndPoint().x % gridSize ) != 0
2164 || ( line->GetEndPoint().y % gridSize ) != 0 )
2165 {
2166 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
2167 ercItem->SetItems( line );
2168
2169 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), line->GetEndPoint() ) );
2170 }
2171 }
2172 if( item->Type() == SCH_BUS_WIRE_ENTRY_T )
2173 {
2174 SCH_BUS_WIRE_ENTRY* entry = static_cast<SCH_BUS_WIRE_ENTRY*>( item );
2175
2176 for( const VECTOR2I& point : entry->GetConnectionPoints() )
2177 {
2178 if( ( point.x % gridSize ) != 0
2179 || ( point.y % gridSize ) != 0 )
2180 {
2181 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
2182 ercItem->SetItems( entry );
2183
2184 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), point ) );
2185 }
2186 }
2187 }
2188 else if( item->Type() == SCH_SYMBOL_T )
2189 {
2190 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2191
2192 for( SCH_PIN* pin : symbol->GetPins( nullptr ) )
2193 {
2194 if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC )
2195 continue;
2196
2197 VECTOR2I pinPos = pin->GetPosition();
2198
2199 if( ( pinPos.x % gridSize ) != 0 || ( pinPos.y % gridSize ) != 0 )
2200 {
2201 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
2202 ercItem->SetItems( pin );
2203
2204 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), pinPos ) );
2205 break;
2206 }
2207 }
2208 }
2209 }
2210
2211 for( SCH_MARKER* marker : markers )
2212 {
2213 screen->Append( marker );
2214 err_count += 1;
2215 }
2216 }
2217
2218 return err_count;
2219}
2220
2221
2223{
2225 int err_count = 0;
2226 SIM_LIB_MGR libMgr( &m_schematic->Project() );
2227 wxString variant = m_schematic->GetCurrentVariant();
2228
2229 for( SCH_SHEET_PATH& sheet : m_sheetList )
2230 {
2231 if( sheet.GetExcludedFromSim( variant ) )
2232 continue;
2233
2234 std::vector<SCH_MARKER*> markers;
2235
2236 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
2237 {
2238 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2239
2240 // Power symbols and other symbols which have the reference starting with "#" are
2241 // not included in simulation
2242 if( symbol->GetRef( &sheet ).StartsWith( '#' ) || symbol->ResolveExcludedFromSim() )
2243 continue;
2244
2245 // Reset for each symbol
2246 reporter.Clear();
2247
2248 SIM_LIBRARY::MODEL model = libMgr.CreateModel( &sheet, *symbol, true, 0, variant, reporter );
2249
2250 if( reporter.HasMessage() )
2251 {
2252 wxString msg = reporter.GetMessages();
2253 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMULATION_MODEL );
2254
2255 //Remove \n and \r at e.o.l if any:
2256 msg.Trim();
2257
2258 ercItem->SetErrorMessage( msg );
2259 ercItem->SetItems( symbol );
2260
2261 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2262 }
2263 }
2264
2265 for( SCH_MARKER* marker : markers )
2266 {
2267 sheet.LastScreen()->Append( marker );
2268 err_count += 1;
2269 }
2270 }
2271
2272 return err_count;
2273}
2274
2275
2277 KIFACE* aCvPcb, PROJECT* aProject, PROGRESS_REPORTER* aProgressReporter )
2278{
2279 m_sheetList.AnnotatePowerSymbols();
2280
2281 // Test duplicate sheet names inside a given sheet. While one can have multiple references
2282 // to the same file, each must have a unique name.
2283 if( m_settings.IsTestEnabled( ERCE_DUPLICATE_SHEET_NAME ) )
2284 {
2285 if( aProgressReporter )
2286 aProgressReporter->AdvancePhase( _( "Checking sheet names..." ) );
2287
2289 }
2290
2291 // The connection graph has a whole set of ERC checks it can run
2292 if( aProgressReporter )
2293 aProgressReporter->AdvancePhase( _( "Checking conflicts..." ) );
2294
2295 // If we are using the new connectivity, make sure that we do a full-rebuild
2296 if( aEditFrame )
2297 {
2298 if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
2299 aEditFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
2300 else
2301 aEditFrame->RecalculateConnections( nullptr, NO_CLEANUP );
2302 }
2303
2304 m_schematic->ConnectionGraph()->RunERC();
2305
2306 if( aProgressReporter )
2307 aProgressReporter->AdvancePhase( _( "Checking units..." ) );
2308
2309 // Test is all units of each multiunit symbol have the same footprint assigned.
2310 if( m_settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_FP ) )
2311 {
2312 if( aProgressReporter )
2313 aProgressReporter->AdvancePhase( _( "Checking footprints..." ) );
2314
2316 }
2317
2318 if( m_settings.IsTestEnabled( ERCE_MISSING_UNIT )
2319 || m_settings.IsTestEnabled( ERCE_MISSING_INPUT_PIN )
2320 || m_settings.IsTestEnabled( ERCE_MISSING_POWER_INPUT_PIN )
2321 || m_settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
2322 {
2324 }
2325
2326 if( aProgressReporter )
2327 aProgressReporter->AdvancePhase( _( "Checking pins..." ) );
2328
2329 if( m_settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_NET ) )
2331
2332 if( m_settings.IsTestEnabled( ERCE_DUPLICATE_PIN_ERROR ) )
2334
2335 // Test pins on each net against the pin connection table
2336 if( m_settings.IsTestEnabled( ERCE_PIN_TO_PIN_ERROR )
2337 || m_settings.IsTestEnabled( ERCE_PIN_TO_PIN_WARNING )
2338 || m_settings.IsTestEnabled( ERCE_POWERPIN_NOT_DRIVEN )
2339 || m_settings.IsTestEnabled( ERCE_PIN_NOT_DRIVEN ) )
2340 {
2341 TestPinToPin();
2342 }
2343
2344 if( m_settings.IsTestEnabled( ERCE_GROUND_PIN_NOT_GROUND ) )
2346
2347 if( m_settings.IsTestEnabled( ERCE_STACKED_PIN_SYNTAX ) )
2349
2350 // Test similar labels (i;e. labels which are identical when
2351 // using case insensitive comparisons)
2352 if( m_settings.IsTestEnabled( ERCE_SIMILAR_LABELS )
2353 || m_settings.IsTestEnabled( ERCE_SIMILAR_POWER )
2354 || m_settings.IsTestEnabled( ERCE_SIMILAR_LABEL_AND_POWER ) )
2355 {
2356 if( aProgressReporter )
2357 aProgressReporter->AdvancePhase( _( "Checking similar labels..." ) );
2358
2360 }
2361
2362 if( m_settings.IsTestEnabled( ERCE_SAME_LOCAL_GLOBAL_LABEL )
2363 || m_settings.IsTestEnabled( ERCE_SAME_LOCAL_GLOBAL_POWER ) )
2364 {
2365 if( aProgressReporter )
2366 aProgressReporter->AdvancePhase( _( "Checking local and global labels..." ) );
2367
2369 }
2370
2371 if( m_settings.IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) )
2372 {
2373 if( aProgressReporter )
2374 aProgressReporter->AdvancePhase( _( "Checking for unresolved variables..." ) );
2375
2376 TestTextVars( aDrawingSheet );
2377 }
2378
2379 if( m_settings.IsTestEnabled( ERCE_FIELD_NAME_WHITESPACE ) )
2380 {
2381 if( aProgressReporter )
2382 aProgressReporter->AdvancePhase( _( "Checking field names..." ) );
2383
2385 }
2386
2387 if( m_settings.IsTestEnabled( ERCE_SIMULATION_MODEL ) )
2388 {
2389 if( aProgressReporter )
2390 aProgressReporter->AdvancePhase( _( "Checking SPICE models..." ) );
2391
2393 }
2394
2395 if( m_settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED ) )
2396 {
2397 if( aProgressReporter )
2398 aProgressReporter->AdvancePhase( _( "Checking no connect pins for connections..." ) );
2399
2401 }
2402
2403 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES )
2404 || m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_MISMATCH ) )
2405 {
2406 if( aProgressReporter )
2407 aProgressReporter->AdvancePhase( _( "Checking for library symbol issues..." ) );
2408
2410 }
2411
2412 if( m_settings.IsTestEnabled( ERCE_FOOTPRINT_LINK_ISSUES ) && aCvPcb )
2413 {
2414 if( aProgressReporter )
2415 aProgressReporter->AdvancePhase( _( "Checking for footprint link issues..." ) );
2416
2417 TestFootprintLinkIssues( aCvPcb, aProject );
2418 }
2419
2420 if( m_settings.IsTestEnabled( ERCE_FOOTPRINT_FILTERS ) )
2421 {
2422 if( aProgressReporter )
2423 aProgressReporter->AdvancePhase( _( "Checking footprint assignments against footprint filters..." ) );
2424
2426 }
2427
2428 if( m_settings.IsTestEnabled( ERCE_ENDPOINT_OFF_GRID ) )
2429 {
2430 if( aProgressReporter )
2431 aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) );
2432
2434 }
2435
2436 if( m_settings.IsTestEnabled( ERCE_FOUR_WAY_JUNCTION ) )
2437 {
2438 if( aProgressReporter )
2439 aProgressReporter->AdvancePhase( _( "Checking for four way junctions..." ) );
2440
2442 }
2443
2444 if( m_settings.IsTestEnabled( ERCE_LABEL_MULTIPLE_WIRES ) )
2445 {
2446 if( aProgressReporter )
2447 aProgressReporter->AdvancePhase( _( "Checking for labels on more than one wire..." ) );
2448
2450 }
2451
2452 if( m_settings.IsTestEnabled( ERCE_UNDEFINED_NETCLASS ) )
2453 {
2454 if( aProgressReporter )
2455 aProgressReporter->AdvancePhase( _( "Checking for undefined netclasses..." ) );
2456
2458 }
2459
2460 m_schematic->ResolveERCExclusionsPostUpdate();
2461}
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:315
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:1862
const NET_MAP & m_nets
Definition erc.h:204
int TestStackedPinNotation()
Checks for pin numbers that resemble stacked pin notation but are invalid.
Definition erc.cpp:1627
void TestTextVars(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Check for any unresolved text variable references.
Definition erc.cpp:183
int TestPinToPin()
Checks the full netlist against the pin-to-pin connectivity requirements.
Definition erc.cpp:980
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition erc.cpp:1747
SCH_MULTI_UNIT_REFERENCE_MAP m_refMap
Definition erc.h:203
SCH_SCREENS m_screens
Definition erc.h:202
int TestFootprintLinkIssues(KIFACE *aCvPcb, PROJECT *aProject)
Test footprint links against the current footprint libraries.
Definition erc.cpp:1984
int TestOffGridEndpoints()
Test pins and wire ends for being off grid.
Definition erc.cpp:2140
int TestDuplicateSheetNames(bool aCreateMarker)
Inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated).
Definition erc.cpp:140
int TestSameLocalGlobalLabel()
Checks for global and local labels with the same name.
Definition erc.cpp:1663
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition erc.cpp:1426
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
Definition erc.cpp:889
int TestFootprintFilters()
Test symbols to ensure that assigned footprint passes any given footprint filters.
Definition erc.cpp:2070
int TestFieldNameWhitespace()
Check for field names with leading or trailing whitespace.
Definition erc.cpp:438
int TestDuplicatePinNets()
Checks if duplicate pin numbers within a symbol are connected to different nets.
Definition erc.cpp:1480
ERC_SETTINGS & m_settings
Definition erc.h:200
int TestFourWayJunction()
Test to see if there are potentially confusing 4-way junctions in the schematic.
Definition erc.cpp:810
int TestMissingNetclasses()
Tests for netclasses that are referenced but not defined.
Definition erc.cpp:702
int TestSimModelIssues()
Test SPICE models for various issues.
Definition erc.cpp:2222
SCH_SHEET_LIST m_sheetList
Definition erc.h:201
bool m_showAllErrors
Definition erc.h:205
int TestGroundPins()
Checks for ground-labeled pins not on a ground net while another pin is.
Definition erc.cpp:1559
SCHEMATIC * m_schematic
Definition erc.h:199
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition erc.cpp:2276
int TestMissingUnits()
Test for uninstantiated units of multi unit symbols.
Definition erc.cpp:568
int TestLabelMultipleWires()
Test to see if there are labels that are connected to more than one wire.
Definition erc.cpp:755
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition erc.cpp:507
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:48
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:79
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.
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:750
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 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:62
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:480
VECTOR2I GetPosition() const override
Definition sch_pin.cpp:345
bool IsStacked(const SCH_PIN *aPin) const
Definition sch_pin.cpp:570
bool IsPower() const
Check if the pin is either a global or local power pin.
Definition sch_pin.cpp:474
ELECTRICAL_PINTYPE GetType() const
Definition sch_pin.cpp:402
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:885
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:158
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:189
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition common.cpp:704
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:93
const wxString CommentERC_H[]
Definition erc.cpp:76
const std::set< ELECTRICAL_PINTYPE > DrivenPinTypes
Definition erc.cpp:131
const std::set< ELECTRICAL_PINTYPE > DrivingPinTypes
Definition erc.cpp:113
const std::set< ELECTRICAL_PINTYPE > DrivingPowerPinTypes
Definition erc.cpp:125
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_STACKED_PIN_SYNTAX
Pin name resembles stacked pin notation.
@ ERCE_ENDPOINT_OFF_GRID
Pin or wire-end off grid.
@ 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_FOOTPRINT_LINK_ISSUES
The footprint link is invalid, or points to a missing (or inactive) footprint or library.
@ 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_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_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
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)
@ NO_CLEANUP
Definition schematic.h:77
@ GLOBAL_CLEANUP
Definition schematic.h:79
wxString UnescapeString(const wxString &aSource)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Implement a participant in the KIWAY alchemy.
Definition kiway.h:152
virtual void * IfaceOrAddress(int aDataId)=0
Return pointer to the requested object.
IbisParser parser & reporter
KIBIS_MODEL * model
KIBIS_PIN * pin
wxLogTrace helper definitions.
@ 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
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683