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