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
1036 // We need different drivers for power nets and normal nets.
1037 // A power net has at least one pin having the ELECTRICAL_PINTYPE::PT_POWER_IN
1038 // and power nets can be driven only by ELECTRICAL_PINTYPE::PT_POWER_OUT pins
1039 bool ispowerNet = false;
1040
1041 for( ERC_SCH_PIN_CONTEXT& refPin : pins )
1042 {
1043 if( refPin.Pin()->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
1044 {
1045 ispowerNet = true;
1046 break;
1047 }
1048 }
1049
1050 std::vector<std::tuple<iterator_t, iterator_t, PIN_ERROR>> pin_mismatches;
1051 std::map<iterator_t, int> pin_mismatch_counts;
1052
1053 for( auto refIt = pins.begin(); refIt != pins.end(); ++refIt )
1054 {
1055 ERC_SCH_PIN_CONTEXT& refPin = *refIt;
1056 ELECTRICAL_PINTYPE refType = refPin.Pin()->GetType();
1057
1058 if( DrivenPinTypes.contains( refType ) )
1059 {
1060 // needsDriver will be the pin shown in the error report eventually, so try to
1061 // upgrade to a "better" pin if possible: something visible and only a power symbol
1062 // if this net needs a power driver
1063 pinsNeedingDrivers.push_back( &refPin );
1064
1065 if( !refPin.Pin()->IsPower() )
1066 nonPowerPinsNeedingDrivers.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 if( m_showAllErrors )
1284 {
1285 if( !nonPowerPinsNeedingDrivers.empty() )
1286 pinsToMark = nonPowerPinsNeedingDrivers;
1287 else
1288 pinsToMark = pinsNeedingDrivers;
1289 }
1290 else
1291 {
1292 if( !nonPowerPinsNeedingDrivers.empty() )
1293 pinsToMark.push_back( nonPowerPinsNeedingDrivers.front() );
1294 else
1295 pinsToMark.push_back( &needsDriver );
1296 }
1297
1298 for( ERC_SCH_PIN_CONTEXT* pinCtx : pinsToMark )
1299 {
1300 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( err_code );
1301
1302 ercItem->SetItems( pinCtx->Pin() );
1303 ercItem->SetSheetSpecificPath( pinCtx->Sheet() );
1304 ercItem->SetItemsSheetPaths( pinCtx->Sheet() );
1305
1306 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pinCtx->Pin()->GetPosition() );
1307 pinToScreenMap[pinCtx->Pin()]->Append( marker );
1308 errors++;
1309 }
1310 }
1311 }
1312 }
1313
1314 // --- Additional net-chain-level checking ---
1315 // If a pin participates in a grouped net chain (spanning multiple nets via passives), ensure
1316 // that all other pins reachable through that chain are electrically compatible even if
1317 // they reside on different nets.
1318 // We only consider pairs on DIFFERENT nets here to avoid duplicating existing net-level
1319 // mismatches already reported above.
1320 if( m_schematic && m_schematic->ConnectionGraph() )
1321 {
1322 auto& netChains = m_schematic->ConnectionGraph()->GetCommittedNetChains();
1323 wxLogTrace( traceSchNetChain, "ERC TestPinToPin: cross-chain phase start chains=%zu",
1324 netChains.size() );
1325
1326 for( const auto& sig : netChains )
1327 {
1328 if( !sig )
1329 continue;
1330
1331 const wxString chainName = sig->GetName();
1332 const auto& sigNets = sig->GetNets();
1333
1334 // Collect all pin contexts across the nets in this chain.
1335 std::vector<ERC_SCH_PIN_CONTEXT> netChainPins;
1336 netChainPins.reserve( sigNets.size() * 4 );
1337
1338 for( const wxString& n : sigNets )
1339 {
1340 auto it = netToPins.find( n );
1341 if( it != netToPins.end() )
1342 {
1343 const auto& vec = it->second;
1344 netChainPins.insert( netChainPins.end(), vec.begin(), vec.end() );
1345 }
1346 }
1347
1348 if( netChainPins.size() < 2 )
1349 continue; // nothing to compare
1350
1351 wxLogTrace( traceSchNetChain,
1352 "ERC TestPinToPin: chain '%s' nets=%zu collectedPins=%zu",
1353 TO_UTF8( chainName ), sigNets.size(), netChainPins.size() );
1354
1355 // For deterministic behavior, sort by reference/pin number similar to earlier pass.
1356 std::sort( netChainPins.begin(), netChainPins.end(),
1357 []( const ERC_SCH_PIN_CONTEXT& lhs, const ERC_SCH_PIN_CONTEXT& rhs )
1358 {
1359 int ret = StrNumCmp( lhs.Pin()->GetParentSymbol()->GetRef( &lhs.Sheet() ),
1360 rhs.Pin()->GetParentSymbol()->GetRef( &rhs.Sheet() ) );
1361 if( ret == 0 )
1362 ret = StrNumCmp( lhs.Pin()->GetNumber(), rhs.Pin()->GetNumber() );
1363 if( ret == 0 )
1364 ret = lhs < rhs;
1365 return ret < 0;
1366 } );
1367
1368 // Build a quick map from pin -> net name for skipping intra-net pairs.
1369 std::unordered_map<SCH_PIN*, wxString> pinNet;
1370 for( const auto& netEntry : netToPins )
1371 for( const auto& ctx : netEntry.second )
1372 pinNet[ ctx.Pin() ] = netEntry.first;
1373
1374 for( size_t i = 0; i < netChainPins.size(); ++i )
1375 {
1376 SCH_PIN* aPin = netChainPins[i].Pin();
1377 ELECTRICAL_PINTYPE aType = aPin->GetType();
1378 const wxString& aNet = pinNet[aPin];
1379
1380 for( size_t j = i + 1; j < netChainPins.size(); ++j )
1381 {
1382 SCH_PIN* bPin = netChainPins[j].Pin();
1383 const wxString& bNet = pinNet[bPin];
1384
1385 if( aNet == bNet )
1386 continue; // already handled at net-level
1387
1388 ELECTRICAL_PINTYPE bType = bPin->GetType();
1389 PIN_ERROR erc = m_settings.GetPinMapValue( aType, bType );
1390
1393
1394 if( erc != PIN_ERROR::OK && m_settings.IsTestEnabled( ercCode ) )
1395 {
1396 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ercCode );
1397
1398 ercItem->SetItems( aPin, bPin );
1399 ercItem->SetSheetSpecificPath( netChainPins[i].Sheet() );
1400 ercItem->SetItemsSheetPaths( netChainPins[i].Sheet(), netChainPins[j].Sheet() );
1401 ercItem->SetErrorMessage( wxString::Format(
1402 _( "Pins of type %s and %s are connected via net chain %s" ),
1403 ElectricalPinTypeGetText( aType ),
1404 ElectricalPinTypeGetText( bType ), chainName ) );
1405
1406 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), aPin->GetPosition() );
1407 netChainPins[i].Sheet().LastScreen()->Append( marker );
1408 errors++;
1409 }
1410 }
1411 }
1412 }
1413 }
1414
1415 return errors;
1416}
1417
1418
1420{
1421 int errors = 0;
1422
1423 std::unordered_map<wxString, std::pair<wxString, SCH_PIN*>> pinToNetMap;
1424
1425 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1426 {
1427 const wxString& netName = net.first.Name;
1428
1429 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1430 {
1431 for( SCH_ITEM* item : subgraph->GetItems() )
1432 {
1433 if( item->Type() == SCH_PIN_T )
1434 {
1435 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1436 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1437
1438 if( !pin->GetParentSymbol()->IsMultiUnit() )
1439 continue;
1440
1441 wxString name = pin->GetParentSymbol()->GetRef( &sheet ) + ":" + pin->GetShownNumber();
1442
1443 if( !pinToNetMap.count( name ) )
1444 {
1445 pinToNetMap[name] = std::make_pair( netName, pin );
1446 }
1447 else if( pinToNetMap[name].first != netName )
1448 {
1449 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_NET );
1450
1451 ercItem->SetErrorMessage( wxString::Format( _( "Pin %s is connected to both %s and %s" ),
1452 pin->GetShownNumber(),
1453 netName,
1454 pinToNetMap[name].first ) );
1455
1456 ercItem->SetItems( pin, pinToNetMap[name].second );
1457 ercItem->SetSheetSpecificPath( sheet );
1458 ercItem->SetItemsSheetPaths( sheet, sheet );
1459
1460 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
1461 sheet.LastScreen()->Append( marker );
1462 errors += 1;
1463 }
1464 }
1465 }
1466 }
1467 }
1468
1469 return errors;
1470}
1471
1472
1474{
1475 int errors = 0;
1476
1477 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1478 {
1479 SCH_SCREEN* screen = sheet.LastScreen();
1480
1481 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1482 {
1483 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1484 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
1485
1486 if( !libSymbol )
1487 continue;
1488
1489 if( libSymbol->GetDuplicatePinNumbersAreJumpers() )
1490 continue;
1491
1492 std::vector<SCH_PIN*> pins = symbol->GetPins( &sheet );
1493
1494 std::map<wxString, std::vector<std::pair<SCH_PIN*, wxString>>> pinsByNumber;
1495
1496 for( SCH_PIN* pin : pins )
1497 {
1498 SCH_CONNECTION* conn = pin->Connection( &sheet );
1499 wxString netName = conn ? conn->GetNetName() : wxString();
1500
1501 pinsByNumber[pin->GetNumber()].emplace_back( pin, netName );
1502 }
1503
1504 for( const auto& [pinNumber, pinNetPairs] : pinsByNumber )
1505 {
1506 if( pinNetPairs.size() < 2 )
1507 continue;
1508
1509 wxString firstNet = pinNetPairs[0].second;
1510 bool hasDifferentNets = false;
1511 SCH_PIN* conflictPin = nullptr;
1512
1513 for( size_t i = 1; i < pinNetPairs.size(); i++ )
1514 {
1515 if( pinNetPairs[i].second != firstNet )
1516 {
1517 hasDifferentNets = true;
1518 conflictPin = pinNetPairs[i].first;
1519 break;
1520 }
1521 }
1522
1523 if( hasDifferentNets )
1524 {
1525 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DUPLICATE_PIN_ERROR );
1526 wxString msg;
1527
1528 msg.Printf( _( "Pin %s on symbol '%s' is connected to different nets: %s and %s" ),
1529 pinNumber,
1530 symbol->GetRef( &sheet ),
1531 firstNet.IsEmpty() ? _( "<no net>" ) : firstNet,
1532 pinNetPairs[1].second.IsEmpty() ? _( "<no net>" ) : pinNetPairs[1].second );
1533
1534 ercItem->SetErrorMessage( msg );
1535 ercItem->SetItems( pinNetPairs[0].first, conflictPin );
1536 ercItem->SetSheetSpecificPath( sheet );
1537 ercItem->SetItemsSheetPaths( sheet, sheet );
1538
1539 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ),
1540 pinNetPairs[0].first->GetPosition() );
1541 screen->Append( marker );
1542 errors++;
1543 }
1544 }
1545 }
1546 }
1547
1548 return errors;
1549}
1550
1551
1553{
1554 int errors = 0;
1555
1556 auto isGround =
1557 []( const wxString& txt )
1558 {
1559 wxString upper = txt.Upper();
1560 return upper.Contains( wxT( "GND" ) );
1561 };
1562
1563 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1564 {
1565 SCH_SCREEN* screen = sheet.LastScreen();
1566
1567 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1568 {
1569 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1570 bool hasGroundNet = false;
1571 std::vector<SCH_PIN*> mismatched;
1572
1573 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
1574 {
1575 SCH_CONNECTION* conn = pin->Connection( &sheet );
1576 wxString net = conn ? conn->GetNetName() : wxString();
1577 bool netIsGround = isGround( net );
1578
1579 // We are only interested in power pins
1580 if( pin->GetType() != ELECTRICAL_PINTYPE::PT_POWER_OUT
1581 && pin->GetType() != ELECTRICAL_PINTYPE::PT_POWER_IN )
1582 {
1583 continue;
1584 }
1585
1586 if( netIsGround )
1587 hasGroundNet = true;
1588
1589 if( isGround( pin->GetShownName() ) && !netIsGround )
1590 mismatched.push_back( pin );
1591 }
1592
1593 if( hasGroundNet )
1594 {
1595 for( SCH_PIN* pin : mismatched )
1596 {
1597 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_GROUND_PIN_NOT_GROUND );
1598
1599 ercItem->SetErrorMessage( wxString::Format( _( "Pin %s not connected to ground net" ),
1600 pin->GetShownName() ) );
1601 ercItem->SetItems( pin );
1602 ercItem->SetSheetSpecificPath( sheet );
1603 ercItem->SetItemsSheetPaths( sheet );
1604
1605 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
1606 screen->Append( marker );
1607 errors++;
1608 }
1609 }
1610 }
1611 }
1612
1613 return errors;
1614}
1615
1616
1618{
1619 int warnings = 0;
1620
1621 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1622 {
1623 SCH_SCREEN* screen = sheet.LastScreen();
1624
1625 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1626 {
1627 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1628
1629 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
1630 {
1631 bool valid;
1632 pin->GetStackedPinNumbers( &valid );
1633
1634 if( !valid )
1635 {
1636 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_STACKED_PIN_SYNTAX );
1637 ercItem->SetItems( pin );
1638 ercItem->SetSheetSpecificPath( sheet );
1639 ercItem->SetItemsSheetPaths( sheet );
1640
1641 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
1642 screen->Append( marker );
1643 warnings++;
1644 }
1645 }
1646 }
1647 }
1648
1649 return warnings;
1650}
1651
1652
1654{
1655 int errCount = 0;
1656
1657 std::unordered_map<wxString, std::pair<SCH_ITEM*, SCH_SHEET_PATH>> globalLabels;
1658 std::unordered_map<wxString, std::pair<SCH_ITEM*, SCH_SHEET_PATH>> localLabels;
1659
1660 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1661 {
1662 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1663 {
1664 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1665
1666 for( SCH_ITEM* item : subgraph->GetItems() )
1667 {
1668 if( item->Type() == SCH_LABEL_T || item->Type() == SCH_GLOBAL_LABEL_T )
1669 {
1670 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
1671 wxString text = label->GetShownText( &sheet, false );
1672
1673 auto& map = item->Type() == SCH_LABEL_T ? localLabels : globalLabels;
1674
1675 if( !map.count( text ) )
1676 {
1677 map[text] = std::make_pair( label, sheet );
1678 }
1679 }
1680 else if( item->Type() == SCH_PIN_T )
1681 {
1682 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1683
1684 if( !pin->IsPower() )
1685 continue;
1686
1687 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
1688
1689 if( !symbol )
1690 continue;
1691
1692 wxString text = ( pin->IsGlobalPower() && !symbol->IsGlobalPower() )
1693 ? pin->GetShownName()
1694 : symbol->GetValue( true, &sheet, false );
1695
1696 auto& map = pin->IsGlobalPower() ? globalLabels : localLabels;
1697
1698 if( !map.count( text ) )
1699 {
1700 map[text] = std::make_pair( pin, sheet );
1701 }
1702 }
1703 }
1704 }
1705 }
1706
1707 for( auto& [globalText, globalItem] : globalLabels )
1708 {
1709 for( auto& [localText, localItem] : localLabels )
1710 {
1711 if( globalText == localText )
1712 {
1713 ERCE_T errorCode = ( globalItem.first->Type() == SCH_PIN_T && localItem.first->Type() == SCH_PIN_T )
1716
1717 if( !m_settings.IsTestEnabled( errorCode ) )
1718 continue;
1719
1720 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( errorCode );
1721 ercItem->SetItems( globalItem.first, localItem.first );
1722 ercItem->SetSheetSpecificPath( globalItem.second );
1723 ercItem->SetItemsSheetPaths( globalItem.second, localItem.second );
1724
1725 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), globalItem.first->GetPosition() );
1726 globalItem.second.LastScreen()->Append( marker );
1727
1728 errCount++;
1729 }
1730 }
1731 }
1732
1733 return errCount;
1734}
1735
1736
1738{
1739 int errors = 0;
1740 std::unordered_map<wxString, std::vector<std::tuple<wxString, SCH_ITEM*, SCH_SHEET_PATH>>> generalMap;
1741
1742 auto logError =
1743 [&]( const wxString& normalized, SCH_ITEM* item, const SCH_SHEET_PATH& sheet,
1744 const std::tuple<wxString, SCH_ITEM*, SCH_SHEET_PATH>& other )
1745 {
1746 auto& [otherText, otherItem, otherSheet] = other;
1747 ERCE_T typeOfWarning = ERCE_SIMILAR_LABELS;
1748
1749 if( item->Type() == SCH_PIN_T && otherItem->Type() == SCH_PIN_T )
1750 {
1751 //Two Pins
1752 typeOfWarning = ERCE_SIMILAR_POWER;
1753 }
1754 else if( item->Type() == SCH_PIN_T || otherItem->Type() == SCH_PIN_T )
1755 {
1756 //Pin and Label
1757 typeOfWarning = ERCE_SIMILAR_LABEL_AND_POWER;
1758 }
1759 else
1760 {
1761 //Two Labels
1762 typeOfWarning = ERCE_SIMILAR_LABELS;
1763 }
1764
1765 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( typeOfWarning );
1766 ercItem->SetItems( item, otherItem );
1767 ercItem->SetSheetSpecificPath( sheet );
1768 ercItem->SetItemsSheetPaths( sheet, otherSheet );
1769
1770 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), item->GetPosition() );
1771 sheet.LastScreen()->Append( marker );
1772 };
1773
1774 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1775 {
1776 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1777 {
1778 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1779
1780 for( SCH_ITEM* item : subgraph->GetItems() )
1781 {
1782 switch( item->Type() )
1783 {
1784 case SCH_LABEL_T:
1785 case SCH_HIER_LABEL_T:
1786 case SCH_GLOBAL_LABEL_T:
1787 {
1788 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
1789 wxString unnormalized = label->GetShownText( &sheet, false );
1790 wxString normalized = unnormalized.Lower();
1791
1792 generalMap[normalized].emplace_back( std::make_tuple( unnormalized, label, sheet ) );
1793
1794 for( const auto& otherTuple : generalMap.at( normalized ) )
1795 {
1796 const auto& [otherText, otherItem, otherSheet] = otherTuple;
1797
1798 if( unnormalized != otherText )
1799 {
1800 // Similar local labels on different sheets are fine
1801 if( item->Type() == SCH_LABEL_T && otherItem->Type() == SCH_LABEL_T
1802 && sheet != otherSheet )
1803 {
1804 continue;
1805 }
1806
1807 logError( normalized, label, sheet, otherTuple );
1808 errors += 1;
1809 }
1810 }
1811
1812 break;
1813 }
1814 case SCH_PIN_T:
1815 {
1816 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1817
1818 if( !pin->IsPower() )
1819 continue;
1820
1821 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
1822 wxString unnormalized = symbol->GetValue( true, &sheet, false );
1823 wxString normalized = unnormalized.Lower();
1824
1825 generalMap[normalized].emplace_back( std::make_tuple( unnormalized, pin, sheet ) );
1826
1827 for( const auto& otherTuple : generalMap.at( normalized ) )
1828 {
1829 const auto& [otherText, otherItem, otherSheet] = otherTuple;
1830
1831 if( unnormalized != otherText )
1832 {
1833 logError( normalized, pin, sheet, otherTuple );
1834 errors += 1;
1835 }
1836 }
1837
1838 break;
1839 }
1840
1841 default:
1842 break;
1843 }
1844 }
1845 }
1846 }
1847
1848 return errors;
1849}
1850
1851
1853{
1854 wxCHECK( m_schematic, 0 );
1855
1856 LIBRARY_MANAGER& manager = Pgm().GetLibraryManager();
1858 wxString msg;
1859 int err_count = 0;
1860
1861 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
1862 {
1863 std::vector<SCH_MARKER*> markers;
1864
1865 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1866 {
1867 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1868 LIB_SYMBOL* libSymbolInSchematic = symbol->GetLibSymbolRef().get();
1869
1870 if( !libSymbolInSchematic )
1871 continue;
1872
1873 wxString libName = symbol->GetLibId().GetLibNickname();
1874
1875 std::optional<const LIBRARY_TABLE_ROW*> optRow =
1876 manager.GetRow( LIBRARY_TABLE_TYPE::SYMBOL, libName );
1877
1878 if( !optRow || ( *optRow )->Disabled() )
1879 {
1880 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
1881 {
1882 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1883 ercItem->SetItems( symbol );
1884 msg.Printf( _( "The current configuration does not include the symbol library '%s'" ),
1885 UnescapeString( libName ) );
1886 ercItem->SetErrorMessage( msg );
1887
1888 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
1889 }
1890
1891 continue;
1892 }
1893 else if( !adapter->IsLibraryLoaded( libName ) )
1894 {
1895 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
1896 {
1897 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1898 std::optional<wxString> uri =
1899 manager.GetFullURI( LIBRARY_TABLE_TYPE::SYMBOL, libName, true );
1900 wxCHECK2( uri.has_value(), uri = wxEmptyString );
1901 ercItem->SetItems( symbol );
1902 msg.Printf( _( "The symbol library '%s' was not found at '%s'" ),
1903 UnescapeString( libName ), *uri );
1904 ercItem->SetErrorMessage( msg );
1905
1906 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
1907 }
1908
1909 continue;
1910 }
1911
1912 wxString symbolName = symbol->GetLibId().GetLibItemName();
1913 LIB_SYMBOL* libSymbol = adapter->LoadSymbol( symbol->GetLibId() );
1914
1915 if( libSymbol == nullptr )
1916 {
1917 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
1918 {
1919 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1920 ercItem->SetItems( symbol );
1921 msg.Printf( _( "Symbol '%s' not found in symbol library '%s'" ),
1922 UnescapeString( symbolName ),
1923 UnescapeString( libName ) );
1924 ercItem->SetErrorMessage( msg );
1925
1926 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
1927 }
1928
1929 continue;
1930 }
1931
1932 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->Flatten();
1934
1935 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_MISMATCH ) )
1936 {
1937 // We have to check for duplicate pins first as they will cause Compare() to fail.
1938 // Symbols with duplicate pins are valid if those pins share the same net, so we
1939 // only skip the comparison here. The actual error checking for duplicate pins on
1940 // different nets is done in TestDuplicatePinNets().
1941 std::vector<wxString> messages;
1942
1943 if( !libSymbolInSchematic->GetDuplicatePinNumbersAreJumpers() )
1944 {
1945 UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILS );
1946 CheckDuplicatePins( libSymbolInSchematic, messages, &unitsProvider );
1947 }
1948
1949 if( messages.empty() && flattenedSymbol->Compare( *libSymbolInSchematic, flags ) != 0 )
1950 {
1951 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_MISMATCH );
1952 ercItem->SetItems( symbol );
1953 msg.Printf( _( "Symbol '%s' doesn't match copy in library '%s'" ),
1954 UnescapeString( symbolName ),
1955 UnescapeString( libName ) );
1956 ercItem->SetErrorMessage( msg );
1957
1958 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
1959 }
1960 }
1961 }
1962
1963 for( SCH_MARKER* marker : markers )
1964 {
1965 screen->Append( marker );
1966 err_count += 1;
1967 }
1968 }
1969
1970 return err_count;
1971}
1972
1973
1975{
1976 wxCHECK( m_schematic, 0 );
1977
1978 wxString msg;
1979 int err_count = 0;
1980
1981 typedef int (*TESTER_FN_PTR)( const wxString&, PROJECT* );
1982
1983 TESTER_FN_PTR linkTester = (TESTER_FN_PTR) aCvPcb->IfaceOrAddress( KIFACE_TEST_FOOTPRINT_LINK );
1984
1985 for( SCH_SHEET_PATH& sheet : m_sheetList )
1986 {
1987 std::vector<SCH_MARKER*> markers;
1988
1989 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1990 {
1991 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1992 wxString footprint = symbol->GetFootprintFieldText( true, &sheet, false );
1993
1994 if( footprint.IsEmpty() )
1995 continue;
1996
1997 LIB_ID fpID;
1998
1999 if( fpID.Parse( footprint, true ) >= 0 )
2000 {
2001 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2002 msg.Printf( _( "'%s' is not a valid footprint identifier" ), footprint );
2003 ercItem->SetErrorMessage( msg );
2004 ercItem->SetItems( symbol );
2005 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2006 continue;
2007 }
2008
2009 wxString libName = fpID.GetLibNickname();
2010 wxString fpName = fpID.GetLibItemName();
2011 int ret = (linkTester)( footprint, aProject );
2012
2014 {
2015 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2016 msg.Printf( _( "The current configuration does not include the footprint library '%s'" ),
2017 libName );
2018 ercItem->SetErrorMessage( msg );
2019 ercItem->SetItems( symbol );
2020 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2021 }
2023 {
2024 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2025 msg.Printf( _( "The footprint library '%s' is not enabled in the current configuration" ),
2026 libName );
2027 ercItem->SetErrorMessage( msg );
2028 ercItem->SetItems( symbol );
2029 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2030 }
2032 {
2033 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2034 msg.Printf( _( "Footprint '%s' not found in library '%s'" ),
2035 fpName,
2036 libName );
2037 ercItem->SetErrorMessage( msg );
2038 ercItem->SetItems( symbol );
2039 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2040 }
2041 }
2042
2043 for( SCH_MARKER* marker : markers )
2044 {
2045 sheet.LastScreen()->Append( marker );
2046 err_count += 1;
2047 }
2048 }
2049
2050 return err_count;
2051}
2052
2053
2055{
2056 wxCHECK( m_schematic, 0 );
2057
2058 wxString msg;
2059 int err_count = 0;
2060
2061 for( SCH_SHEET_PATH& sheet : m_sheetList )
2062 {
2063 std::vector<SCH_MARKER*> markers;
2064
2065 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
2066 {
2067 SCH_SYMBOL* sch_symbol = static_cast<SCH_SYMBOL*>( item );
2068 std::unique_ptr<LIB_SYMBOL>& lib_symbol = sch_symbol->GetLibSymbolRef();
2069
2070 if( !lib_symbol )
2071 continue;
2072
2073 wxArrayString filters = lib_symbol->GetFPFilters();
2074
2075 if( filters.empty() )
2076 continue;
2077
2078 wxString lowerId = sch_symbol->GetFootprintFieldText( true, &sheet, false ).Lower();
2079 LIB_ID footprint;
2080
2081 if( footprint.Parse( lowerId ) > 0 )
2082 continue;
2083
2084 wxString lowerItemName = footprint.GetUniStringLibItemName().Lower();
2085 bool found = false;
2086
2087 for( wxString filter : filters )
2088 {
2089 filter.LowerCase();
2090
2091 // If the filter contains a ':' character, include the library name in the pattern
2092 if( filter.Contains( wxS( ":" ) ) )
2093 found |= lowerId.Matches( filter );
2094 else
2095 found |= lowerItemName.Matches( filter );
2096
2097 if( found )
2098 break;
2099 }
2100
2101 if( !found )
2102 {
2103 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
2104 msg.Printf( _( "Assigned footprint (%s) doesn't match footprint filters (%s)" ),
2105 footprint.GetUniStringLibItemName(),
2106 wxJoin( filters, ' ' ) );
2107 ercItem->SetErrorMessage( msg );
2108 ercItem->SetItems( sch_symbol );
2109 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), sch_symbol->GetPosition() ) );
2110 }
2111 }
2112
2113 for( SCH_MARKER* marker : markers )
2114 {
2115 sheet.LastScreen()->Append( marker );
2116 err_count += 1;
2117 }
2118 }
2119
2120 return err_count;
2121}
2122
2123
2125{
2126 const int gridSize = m_schematic->Settings().m_ConnectionGridSize;
2127 int err_count = 0;
2128
2129 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
2130 {
2131 std::vector<SCH_MARKER*> markers;
2132
2133 for( SCH_ITEM* item : screen->Items() )
2134 {
2135 if( item->Type() == SCH_LINE_T && item->IsConnectable() )
2136 {
2137 SCH_LINE* line = static_cast<SCH_LINE*>( item );
2138
2139 if( ( line->GetStartPoint().x % gridSize ) != 0
2140 || ( line->GetStartPoint().y % gridSize ) != 0 )
2141 {
2142 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
2143 ercItem->SetItems( line );
2144
2145 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), line->GetStartPoint() ) );
2146 }
2147 else if( ( line->GetEndPoint().x % gridSize ) != 0
2148 || ( line->GetEndPoint().y % gridSize ) != 0 )
2149 {
2150 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
2151 ercItem->SetItems( line );
2152
2153 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), line->GetEndPoint() ) );
2154 }
2155 }
2156 if( item->Type() == SCH_BUS_WIRE_ENTRY_T )
2157 {
2158 SCH_BUS_WIRE_ENTRY* entry = static_cast<SCH_BUS_WIRE_ENTRY*>( item );
2159
2160 for( const VECTOR2I& point : entry->GetConnectionPoints() )
2161 {
2162 if( ( point.x % gridSize ) != 0
2163 || ( point.y % gridSize ) != 0 )
2164 {
2165 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
2166 ercItem->SetItems( entry );
2167
2168 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), point ) );
2169 }
2170 }
2171 }
2172 else if( item->Type() == SCH_SYMBOL_T )
2173 {
2174 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2175
2176 for( SCH_PIN* pin : symbol->GetPins( nullptr ) )
2177 {
2178 if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC )
2179 continue;
2180
2181 VECTOR2I pinPos = pin->GetPosition();
2182
2183 if( ( pinPos.x % gridSize ) != 0 || ( pinPos.y % gridSize ) != 0 )
2184 {
2185 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
2186 ercItem->SetItems( pin );
2187
2188 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), pinPos ) );
2189 break;
2190 }
2191 }
2192 }
2193 }
2194
2195 for( SCH_MARKER* marker : markers )
2196 {
2197 screen->Append( marker );
2198 err_count += 1;
2199 }
2200 }
2201
2202 return err_count;
2203}
2204
2205
2207{
2208 WX_STRING_REPORTER reporter;
2209 int err_count = 0;
2210 SIM_LIB_MGR libMgr( &m_schematic->Project() );
2211 wxString variant = m_schematic->GetCurrentVariant();
2212
2213 for( SCH_SHEET_PATH& sheet : m_sheetList )
2214 {
2215 if( sheet.GetExcludedFromSim( variant ) )
2216 continue;
2217
2218 std::vector<SCH_MARKER*> markers;
2219
2220 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
2221 {
2222 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2223
2224 // Power symbols and other symbols which have the reference starting with "#" are
2225 // not included in simulation
2226 if( symbol->GetRef( &sheet ).StartsWith( '#' ) || symbol->ResolveExcludedFromSim() )
2227 continue;
2228
2229 // Reset for each symbol
2230 reporter.Clear();
2231
2232 SIM_LIBRARY::MODEL model = libMgr.CreateModel( &sheet, *symbol, true, 0, variant, reporter );
2233
2234 if( reporter.HasMessage() )
2235 {
2236 wxString msg = reporter.GetMessages();
2237 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMULATION_MODEL );
2238
2239 //Remove \n and \r at e.o.l if any:
2240 msg.Trim();
2241
2242 ercItem->SetErrorMessage( msg );
2243 ercItem->SetItems( symbol );
2244
2245 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), symbol->GetPosition() ) );
2246 }
2247 }
2248
2249 for( SCH_MARKER* marker : markers )
2250 {
2251 sheet.LastScreen()->Append( marker );
2252 err_count += 1;
2253 }
2254 }
2255
2256 return err_count;
2257}
2258
2259
2261 KIFACE* aCvPcb, PROJECT* aProject, PROGRESS_REPORTER* aProgressReporter )
2262{
2263 m_sheetList.AnnotatePowerSymbols();
2264
2265 // Test duplicate sheet names inside a given sheet. While one can have multiple references
2266 // to the same file, each must have a unique name.
2267 if( m_settings.IsTestEnabled( ERCE_DUPLICATE_SHEET_NAME ) )
2268 {
2269 if( aProgressReporter )
2270 aProgressReporter->AdvancePhase( _( "Checking sheet names..." ) );
2271
2273 }
2274
2275 // The connection graph has a whole set of ERC checks it can run
2276 if( aProgressReporter )
2277 aProgressReporter->AdvancePhase( _( "Checking conflicts..." ) );
2278
2279 // If we are using the new connectivity, make sure that we do a full-rebuild
2280 if( aEditFrame )
2281 {
2282 if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
2283 aEditFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
2284 else
2285 aEditFrame->RecalculateConnections( nullptr, NO_CLEANUP );
2286 }
2287
2288 m_schematic->ConnectionGraph()->RunERC();
2289
2290 if( aProgressReporter )
2291 aProgressReporter->AdvancePhase( _( "Checking units..." ) );
2292
2293 // Test is all units of each multiunit symbol have the same footprint assigned.
2294 if( m_settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_FP ) )
2295 {
2296 if( aProgressReporter )
2297 aProgressReporter->AdvancePhase( _( "Checking footprints..." ) );
2298
2300 }
2301
2302 if( m_settings.IsTestEnabled( ERCE_MISSING_UNIT )
2303 || m_settings.IsTestEnabled( ERCE_MISSING_INPUT_PIN )
2304 || m_settings.IsTestEnabled( ERCE_MISSING_POWER_INPUT_PIN )
2305 || m_settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
2306 {
2308 }
2309
2310 if( aProgressReporter )
2311 aProgressReporter->AdvancePhase( _( "Checking pins..." ) );
2312
2313 if( m_settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_NET ) )
2315
2316 if( m_settings.IsTestEnabled( ERCE_DUPLICATE_PIN_ERROR ) )
2318
2319 // Test pins on each net against the pin connection table
2320 if( m_settings.IsTestEnabled( ERCE_PIN_TO_PIN_ERROR )
2321 || m_settings.IsTestEnabled( ERCE_PIN_TO_PIN_WARNING )
2322 || m_settings.IsTestEnabled( ERCE_POWERPIN_NOT_DRIVEN )
2323 || m_settings.IsTestEnabled( ERCE_PIN_NOT_DRIVEN ) )
2324 {
2325 TestPinToPin();
2326 }
2327
2328 if( m_settings.IsTestEnabled( ERCE_GROUND_PIN_NOT_GROUND ) )
2330
2331 if( m_settings.IsTestEnabled( ERCE_STACKED_PIN_SYNTAX ) )
2333
2334 // Test similar labels (i;e. labels which are identical when
2335 // using case insensitive comparisons)
2336 if( m_settings.IsTestEnabled( ERCE_SIMILAR_LABELS )
2337 || m_settings.IsTestEnabled( ERCE_SIMILAR_POWER )
2338 || m_settings.IsTestEnabled( ERCE_SIMILAR_LABEL_AND_POWER ) )
2339 {
2340 if( aProgressReporter )
2341 aProgressReporter->AdvancePhase( _( "Checking similar labels..." ) );
2342
2344 }
2345
2346 if( m_settings.IsTestEnabled( ERCE_SAME_LOCAL_GLOBAL_LABEL )
2347 || m_settings.IsTestEnabled( ERCE_SAME_LOCAL_GLOBAL_POWER ) )
2348 {
2349 if( aProgressReporter )
2350 aProgressReporter->AdvancePhase( _( "Checking local and global labels..." ) );
2351
2353 }
2354
2355 if( m_settings.IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) )
2356 {
2357 if( aProgressReporter )
2358 aProgressReporter->AdvancePhase( _( "Checking for unresolved variables..." ) );
2359
2360 TestTextVars( aDrawingSheet );
2361 }
2362
2363 if( m_settings.IsTestEnabled( ERCE_FIELD_NAME_WHITESPACE ) )
2364 {
2365 if( aProgressReporter )
2366 aProgressReporter->AdvancePhase( _( "Checking field names..." ) );
2367
2369 }
2370
2371 if( m_settings.IsTestEnabled( ERCE_SIMULATION_MODEL ) )
2372 {
2373 if( aProgressReporter )
2374 aProgressReporter->AdvancePhase( _( "Checking SPICE models..." ) );
2375
2377 }
2378
2379 if( m_settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED ) )
2380 {
2381 if( aProgressReporter )
2382 aProgressReporter->AdvancePhase( _( "Checking no connect pins for connections..." ) );
2383
2385 }
2386
2387 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES )
2388 || m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_MISMATCH ) )
2389 {
2390 if( aProgressReporter )
2391 aProgressReporter->AdvancePhase( _( "Checking for library symbol issues..." ) );
2392
2394 }
2395
2396 if( m_settings.IsTestEnabled( ERCE_FOOTPRINT_LINK_ISSUES ) && aCvPcb )
2397 {
2398 if( aProgressReporter )
2399 aProgressReporter->AdvancePhase( _( "Checking for footprint link issues..." ) );
2400
2401 TestFootprintLinkIssues( aCvPcb, aProject );
2402 }
2403
2404 if( m_settings.IsTestEnabled( ERCE_FOOTPRINT_FILTERS ) )
2405 {
2406 if( aProgressReporter )
2407 aProgressReporter->AdvancePhase( _( "Checking footprint assignments against footprint filters..." ) );
2408
2410 }
2411
2412 if( m_settings.IsTestEnabled( ERCE_ENDPOINT_OFF_GRID ) )
2413 {
2414 if( aProgressReporter )
2415 aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) );
2416
2418 }
2419
2420 if( m_settings.IsTestEnabled( ERCE_FOUR_WAY_JUNCTION ) )
2421 {
2422 if( aProgressReporter )
2423 aProgressReporter->AdvancePhase( _( "Checking for four way junctions..." ) );
2424
2426 }
2427
2428 if( m_settings.IsTestEnabled( ERCE_LABEL_MULTIPLE_WIRES ) )
2429 {
2430 if( aProgressReporter )
2431 aProgressReporter->AdvancePhase( _( "Checking for labels on more than one wire..." ) );
2432
2434 }
2435
2436 if( m_settings.IsTestEnabled( ERCE_UNDEFINED_NETCLASS ) )
2437 {
2438 if( aProgressReporter )
2439 aProgressReporter->AdvancePhase( _( "Checking for undefined netclasses..." ) );
2440
2442 }
2443
2444 m_schematic->ResolveERCExclusionsPostUpdate();
2445}
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:279
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:317
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:1852
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:1617
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:1737
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:1974
int TestOffGridEndpoints()
Test pins and wire ends for being off grid.
Definition erc.cpp:2124
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:1653
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition erc.cpp:1419
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:2054
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:1473
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:2206
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:1552
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:2260
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
virtual bool HasMessage() const
Returns true if any messages were reported.
Definition reporter.h:136
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:168
int GetBodyStyle() const
Definition sch_item.h:248
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:76
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:892
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:165
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:184
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
void Clear() override
Definition reporter.cpp:111
const wxString & GetMessages() const
Definition reporter.cpp:105
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.
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