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 (C) 1992-2024 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
29#include "connection_graph.h"
30#include "kiface_ids.h"
31#include <advanced_config.h>
32#include <common.h> // for ExpandEnvVarSubstitutions
33#include <erc/erc.h>
36#include <string_utils.h>
37#include <sch_pin.h>
38#include <project_sch.h>
41#include <sch_edit_frame.h>
42#include <sch_marker.h>
43#include <sch_reference_list.h>
44#include <sch_rule_area.h>
45#include <sch_sheet.h>
46#include <sch_sheet_pin.h>
47#include <sch_pin.h>
48#include <sch_textbox.h>
49#include <sch_line.h>
50#include <schematic.h>
51#include <symbol_lib_table.h>
54#include <vector>
55#include <wx/ffile.h>
56#include <sim/sim_lib_mgr.h>
57#include <progress_reporter.h>
58#include <kiway.h>
59
60
61/* ERC tests :
62 * 1 - conflicts between connected pins ( example: 2 connected outputs )
63 * 2 - minimal connections requirements ( 1 input *must* be connected to an
64 * output, or a passive pin )
65 */
66
67/*
68 * Minimal ERC requirements:
69 * All pins *must* be connected (except ELECTRICAL_PINTYPE::PT_NC).
70 * When a pin is not connected in schematic, the user must place a "non
71 * connected" symbol to this pin.
72 * This ensures a forgotten connection will be detected.
73 */
74
75// Messages for matrix rows:
76const wxString CommentERC_H[] =
77{
78 _( "Input Pin" ),
79 _( "Output Pin" ),
80 _( "Bidirectional Pin" ),
81 _( "Tri-State Pin" ),
82 _( "Passive Pin" ),
83 _( "Free Pin" ),
84 _( "Unspecified Pin" ),
85 _( "Power Input Pin" ),
86 _( "Power Output Pin" ),
87 _( "Open Collector" ),
88 _( "Open Emitter" ),
89 _( "No Connection" )
90};
91
92// Messages for matrix columns
93const wxString CommentERC_V[] =
94{
95 _( "Input Pin" ),
96 _( "Output Pin" ),
97 _( "Bidirectional Pin" ),
98 _( "Tri-State Pin" ),
99 _( "Passive Pin" ),
100 _( "Free Pin" ),
101 _( "Unspecified Pin" ),
102 _( "Power Input Pin" ),
103 _( "Power Output Pin" ),
104 _( "Open Collector" ),
105 _( "Open Emitter" ),
106 _( "No Connection" )
107};
108
109
110// List of pin types that are considered drivers for usual input pins
111// i.e. pin type = ELECTRICAL_PINTYPE::PT_INPUT, but not PT_POWER_IN
112// that need only a PT_POWER_OUT pin type to be driven
113const std::set<ELECTRICAL_PINTYPE> DrivingPinTypes =
114 {
120 };
121
122// List of pin types that are considered drivers for power pins
123// In fact only a ELECTRICAL_PINTYPE::PT_POWER_OUT pin type can drive
124// power input pins
125const std::set<ELECTRICAL_PINTYPE> DrivingPowerPinTypes =
126 {
128 };
129
130// List of pin types that require a driver elsewhere on the net
131const std::set<ELECTRICAL_PINTYPE> DrivenPinTypes =
132 {
135 };
136
137extern void CheckDuplicatePins( LIB_SYMBOL* aSymbol, std::vector<wxString>& aMessages,
138 UNITS_PROVIDER* aUnitsProvider );
139
140int ERC_TESTER::TestDuplicateSheetNames( bool aCreateMarker )
141{
142 int err_count = 0;
143
144 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
145 {
146 std::vector<SCH_SHEET*> list;
147
148 for( SCH_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
149 list.push_back( static_cast<SCH_SHEET*>( item ) );
150
151 for( size_t i = 0; i < list.size(); i++ )
152 {
153 SCH_SHEET* sheet = list[i];
154
155 for( size_t j = i + 1; j < list.size(); j++ )
156 {
157 SCH_SHEET* test_item = list[j];
158
159 // We have found a second sheet: compare names
160 // we are using case insensitive comparison to avoid mistakes between
161 // similar names like Mysheet and mysheet
162 if( sheet->GetShownName( false ).IsSameAs( test_item->GetShownName( false ), false ) )
163 {
164 if( aCreateMarker )
165 {
167 ercItem->SetItems( sheet, test_item );
168
169 SCH_MARKER* marker = new SCH_MARKER( ercItem, sheet->GetPosition() );
170 screen->Append( marker );
171 }
172
173 err_count++;
174 }
175 }
176 }
177 }
178
179 return err_count;
180}
181
182
184{
186
187 auto unresolved =
188 [this]( wxString str )
189 {
190 str = ExpandEnvVarSubstitutions( str, &m_schematic->Prj() );
191 return str.Matches( wxS( "*${*}*" ) );
192 };
193
194 auto testAssertion =
195 []( const SCH_ITEM* item, const SCH_SHEET_PATH& sheet, SCH_SCREEN* screen,
196 const wxString& text, const VECTOR2I& pos )
197 {
198 static wxRegEx warningExpr( wxS( "^\\$\\{ERC_WARNING\\s*([^}]*)\\}(.*)$" ) );
199 static wxRegEx errorExpr( wxS( "^\\$\\{ERC_ERROR\\s*([^}]*)\\}(.*)$" ) );
200
201 if( warningExpr.Matches( text ) )
202 {
203 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_GENERIC_WARNING );
204 wxString ercText = warningExpr.GetMatch( text, 1 );
205
206 if( item )
207 ercItem->SetItems( item );
208 else
209 ercText += _( " (in drawing sheet)" );
210
211 ercItem->SetSheetSpecificPath( sheet );
212 ercItem->SetErrorMessage( ercText );
213
214 SCH_MARKER* marker = new SCH_MARKER( ercItem, pos );
215 screen->Append( marker );
216
217 return true;
218 }
219
220 if( errorExpr.Matches( text ) )
221 {
222 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_GENERIC_ERROR );
223 wxString ercText = errorExpr.GetMatch( text, 1 );
224
225 if( item )
226 ercItem->SetItems( item );
227 else
228 ercText += _( " (in drawing sheet)" );
229
230 ercItem->SetSheetSpecificPath( sheet );
231 ercItem->SetErrorMessage( ercText );
232
233 SCH_MARKER* marker = new SCH_MARKER( ercItem, pos );
234 screen->Append( marker );
235
236 return true;
237 }
238
239 return false;
240 };
241
242 if( aDrawingSheet )
243 {
244 wsItems.SetPageNumber( wxS( "1" ) );
245 wsItems.SetSheetCount( 1 );
246 wsItems.SetFileName( wxS( "dummyFilename" ) );
247 wsItems.SetSheetName( wxS( "dummySheet" ) );
248 wsItems.SetSheetLayer( wxS( "dummyLayer" ) );
249 wsItems.SetProject( &m_schematic->Prj() );
250 wsItems.BuildDrawItemsList( aDrawingSheet->GetPageInfo(), aDrawingSheet->GetTitleBlock() );
251 }
252
253 for( const SCH_SHEET_PATH& sheet : m_sheetList )
254 {
255 SCH_SCREEN* screen = sheet.LastScreen();
256
257 for( SCH_ITEM* item : screen->Items().OfType( SCH_LOCATE_ANY_T ) )
258 {
259 if( item->Type() == SCH_SYMBOL_T )
260 {
261 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
262
263 for( SCH_FIELD& field : symbol->GetFields() )
264 {
265 if( unresolved( field.GetShownText( &sheet, true ) ) )
266 {
268 ercItem->SetItems( symbol );
269 ercItem->SetSheetSpecificPath( sheet );
270
271 SCH_MARKER* marker = new SCH_MARKER( ercItem, field.GetPosition() );
272 screen->Append( marker );
273 }
274
275 testAssertion( &field, sheet, screen, field.GetText(), field.GetPosition() );
276 }
277
278 symbol->GetLibSymbolRef()->RunOnChildren(
279 [&]( SCH_ITEM* child )
280 {
281 if( child->Type() == SCH_FIELD_T )
282 {
283 // test only SCH_SYMBOL fields, not LIB_SYMBOL fields
284 }
285 else if( child->Type() == SCH_TEXT_T )
286 {
287 SCH_TEXT* textItem = static_cast<SCH_TEXT*>( child );
288
289 if( unresolved( textItem->GetShownText( &sheet, true ) ) )
290 {
291 auto ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
292 ercItem->SetItems( symbol );
293 ercItem->SetSheetSpecificPath( sheet );
294
295 BOX2I bbox = textItem->GetBoundingBox();
296 bbox = symbol->GetTransform().TransformCoordinate( bbox );
297 VECTOR2I pos = bbox.Centre() + symbol->GetPosition();
298
299 SCH_MARKER* marker = new SCH_MARKER( ercItem, pos );
300 screen->Append( marker );
301 }
302
303 testAssertion( symbol, sheet, screen, textItem->GetText(),
304 textItem->GetPosition() );
305 }
306 else if( child->Type() == SCH_TEXTBOX_T )
307 {
308 SCH_TEXTBOX* textboxItem = static_cast<SCH_TEXTBOX*>( child );
309
310 if( unresolved( textboxItem->GetShownText( &sheet, true ) ) )
311 {
312 auto ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
313 ercItem->SetItems( symbol );
314 ercItem->SetSheetSpecificPath( sheet );
315
316 BOX2I bbox = textboxItem->GetBoundingBox();
317 bbox = symbol->GetTransform().TransformCoordinate( bbox );
318 VECTOR2I pos = bbox.Centre() + symbol->GetPosition();
319
320 SCH_MARKER* marker = new SCH_MARKER( ercItem, pos );
321 screen->Append( marker );
322 }
323
324 testAssertion( symbol, sheet, screen, textboxItem->GetText(),
325 textboxItem->GetPosition() );
326 }
327 } );
328 }
329 else if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( item ) )
330 {
331 for( SCH_FIELD& field : label->GetFields() )
332 {
333 if( unresolved( field.GetShownText( &sheet, true ) ) )
334 {
336 ercItem->SetItems( label );
337 ercItem->SetSheetSpecificPath( sheet );
338
339 SCH_MARKER* marker = new SCH_MARKER( ercItem, field.GetPosition() );
340 screen->Append( marker );
341 }
342
343 testAssertion( &field, sheet, screen, field.GetText(), field.GetPosition() );
344 }
345 }
346 else if( item->Type() == SCH_SHEET_T )
347 {
348 SCH_SHEET* subSheet = static_cast<SCH_SHEET*>( item );
349
350 for( SCH_FIELD& field : subSheet->GetFields() )
351 {
352 if( unresolved( field.GetShownText( &sheet, true ) ) )
353 {
355 ercItem->SetItems( subSheet );
356 ercItem->SetSheetSpecificPath( sheet );
357
358 SCH_MARKER* marker = new SCH_MARKER( ercItem, field.GetPosition() );
359 screen->Append( marker );
360 }
361
362 testAssertion( &field, sheet, screen, field.GetText(), field.GetPosition() );
363 }
364
365 SCH_SHEET_PATH subSheetPath = sheet;
366 subSheetPath.push_back( subSheet );
367
368 for( SCH_SHEET_PIN* pin : subSheet->GetPins() )
369 {
370 if( pin->GetShownText( &subSheetPath, true ).Matches( wxS( "*${*}*" ) ) )
371 {
373 ercItem->SetItems( pin );
374 ercItem->SetSheetSpecificPath( sheet );
375
376 SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() );
377 screen->Append( marker );
378 }
379 }
380 }
381 else if( SCH_TEXT* text = dynamic_cast<SCH_TEXT*>( item ) )
382 {
383 if( text->GetShownText( &sheet, true ).Matches( wxS( "*${*}*" ) ) )
384 {
386 ercItem->SetItems( text );
387 ercItem->SetSheetSpecificPath( sheet );
388
389 SCH_MARKER* marker = new SCH_MARKER( ercItem, text->GetPosition() );
390 screen->Append( marker );
391 }
392
393 testAssertion( text, sheet, screen, text->GetText(), text->GetPosition() );
394 }
395 else if( SCH_TEXTBOX* textBox = dynamic_cast<SCH_TEXTBOX*>( item ) )
396 {
397 if( textBox->GetShownText( &sheet, true ).Matches( wxS( "*${*}*" ) ) )
398 {
400 ercItem->SetItems( textBox );
401 ercItem->SetSheetSpecificPath( sheet );
402
403 SCH_MARKER* marker = new SCH_MARKER( ercItem, textBox->GetPosition() );
404 screen->Append( marker );
405 }
406
407 testAssertion( textBox, sheet, screen, textBox->GetText(), textBox->GetPosition() );
408 }
409 }
410
411 for( DS_DRAW_ITEM_BASE* item = wsItems.GetFirst(); item; item = wsItems.GetNext() )
412 {
413 if( DS_DRAW_ITEM_TEXT* text = dynamic_cast<DS_DRAW_ITEM_TEXT*>( item ) )
414 {
415 if( testAssertion( nullptr, sheet, screen, text->GetText(), text->GetPosition() ) )
416 {
417 // Don't run unresolved test
418 }
419 else if( text->GetShownText( true ).Matches( wxS( "*${*}*" ) ) )
420 {
421 std::shared_ptr<ERC_ITEM> erc = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
422 erc->SetErrorMessage( _( "Unresolved text variable in drawing sheet" ) );
423 erc->SetSheetSpecificPath( sheet );
424
425 SCH_MARKER* marker = new SCH_MARKER( erc, text->GetPosition() );
426 screen->Append( marker );
427 }
428 }
429 }
430 }
431}
432
433
435{
436 wxString msg;
437 int err_count = 0;
438 std::vector<std::shared_ptr<BUS_ALIAS>> aliases;
439
440 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
441 {
442 const auto& screen_aliases = screen->GetBusAliases();
443
444 for( const std::shared_ptr<BUS_ALIAS>& alias : screen_aliases )
445 {
446 std::vector<wxString> aliasMembers = alias->Members();
447 std::sort( aliasMembers.begin(), aliasMembers.end() );
448
449 for( const std::shared_ptr<BUS_ALIAS>& test : aliases )
450 {
451 std::vector<wxString> testMembers = test->Members();
452 std::sort( testMembers.begin(), testMembers.end() );
453
454 if( alias->GetName() == test->GetName() && aliasMembers != testMembers )
455 {
456 msg.Printf( _( "Bus alias %s has conflicting definitions on %s and %s" ),
457 alias->GetName(),
458 alias->GetParent()->GetFileName(),
459 test->GetParent()->GetFileName() );
460
461 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ALIAS_CONFLICT );
462 ercItem->SetErrorMessage( msg );
463
464 SCH_MARKER* marker = new SCH_MARKER( ercItem, VECTOR2I() );
465 test->GetParent()->Append( marker );
466
467 ++err_count;
468 }
469 }
470 }
471
472 aliases.insert( aliases.end(), screen_aliases.begin(), screen_aliases.end() );
473 }
474
475 return err_count;
476}
477
478
480{
481 int errors = 0;
482
483 for( std::pair<const wxString, SCH_REFERENCE_LIST>& symbol : m_refMap )
484 {
485 SCH_REFERENCE_LIST& refList = symbol.second;
486
487 if( refList.GetCount() == 0 )
488 {
489 wxFAIL; // it should not happen
490 continue;
491 }
492
493 // Reference footprint
494 SCH_SYMBOL* unit = nullptr;
495 wxString unitName;
496 wxString unitFP;
497
498 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
499 {
500 SCH_SHEET_PATH sheetPath = refList.GetItem( ii ).GetSheetPath();
501 unitFP = refList.GetItem( ii ).GetFootprint();
502
503 if( !unitFP.IsEmpty() )
504 {
505 unit = refList.GetItem( ii ).GetSymbol();
506 unitName = unit->GetRef( &sheetPath, true );
507 break;
508 }
509 }
510
511 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
512 {
513 SCH_REFERENCE& secondRef = refList.GetItem( ii );
514 SCH_SYMBOL* secondUnit = secondRef.GetSymbol();
515 wxString secondName = secondUnit->GetRef( &secondRef.GetSheetPath(), true );
516 const wxString secondFp = secondRef.GetFootprint();
517 wxString msg;
518
519 if( unit && !secondFp.IsEmpty() && unitFP != secondFp )
520 {
521 msg.Printf( _( "Different footprints assigned to %s and %s" ),
522 unitName, secondName );
523
524 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_FP );
525 ercItem->SetErrorMessage( msg );
526 ercItem->SetItems( unit, secondUnit );
527
528 SCH_MARKER* marker = new SCH_MARKER( ercItem, secondUnit->GetPosition() );
529 secondRef.GetSheetPath().LastScreen()->Append( marker );
530
531 ++errors;
532 }
533 }
534 }
535
536 return errors;
537}
538
539
541{
542 int errors = 0;
543
544 for( std::pair<const wxString, SCH_REFERENCE_LIST>& symbol : m_refMap )
545 {
546 SCH_REFERENCE_LIST& refList = symbol.second;
547
548 wxCHECK2( refList.GetCount(), continue );
549
550 // Reference unit
551 SCH_REFERENCE& base_ref = refList.GetItem( 0 );
552 SCH_SYMBOL* unit = base_ref.GetSymbol();
553 LIB_SYMBOL* libSymbol = base_ref.GetLibPart();
554
555 if( static_cast<ssize_t>( refList.GetCount() ) == libSymbol->GetUnitCount() )
556 continue;
557
558 std::set<int> lib_units;
559 std::set<int> instance_units;
560 std::set<int> missing_units;
561
562 auto report =
563 [&]( std::set<int>& aMissingUnits, const wxString& aErrorMsg, int aErrorCode )
564 {
565 wxString msg;
566 wxString missing_pin_units = wxS( "[ " );
567 int ii = 0;
568
569 for( int missing_unit : aMissingUnits )
570 {
571 if( ii++ == 3 )
572 {
573 missing_pin_units += wxS( "....." );
574 break;
575 }
576
577 missing_pin_units += libSymbol->GetUnitDisplayName( missing_unit ) + ", " ;
578 }
579
580 missing_pin_units.Truncate( missing_pin_units.length() - 2 );
581 missing_pin_units += wxS( " ]" );
582
583 msg.Printf( aErrorMsg, symbol.first, missing_pin_units );
584
585 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( aErrorCode );
586 ercItem->SetErrorMessage( msg );
587 ercItem->SetItems( unit );
588 ercItem->SetSheetSpecificPath( base_ref.GetSheetPath() );
589 ercItem->SetItemsSheetPaths( base_ref.GetSheetPath() );
590
591 SCH_MARKER* marker = new SCH_MARKER( ercItem, unit->GetPosition() );
592 base_ref.GetSheetPath().LastScreen()->Append( marker );
593
594 ++errors;
595 };
596
597 for( int ii = 1; ii <= libSymbol->GetUnitCount(); ++ii )
598 lib_units.insert( lib_units.end(), ii );
599
600 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
601 instance_units.insert( instance_units.end(), refList.GetItem( ii ).GetUnit() );
602
603 std::set_difference( lib_units.begin(), lib_units.end(),
604 instance_units.begin(), instance_units.end(),
605 std::inserter( missing_units, missing_units.begin() ) );
606
607 if( !missing_units.empty() && m_settings.IsTestEnabled( ERCE_MISSING_UNIT ) )
608 {
609 report( missing_units, _( "Symbol %s has unplaced units %s" ), ERCE_MISSING_UNIT );
610 }
611
612 std::set<int> missing_power;
613 std::set<int> missing_input;
614 std::set<int> missing_bidi;
615
616 for( int missing_unit : missing_units )
617 {
618 int bodyStyle = 0;
619
620 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
621 {
622 if( refList.GetItem( ii ).GetUnit() == missing_unit )
623 {
624 bodyStyle = refList.GetItem( ii ).GetSymbol()->GetBodyStyle();
625 break;
626 }
627 }
628
629 for( SCH_PIN* pin : libSymbol->GetPins( missing_unit, bodyStyle ) )
630 {
631 switch( pin->GetType() )
632 {
633 case ELECTRICAL_PINTYPE::PT_POWER_IN:
634 missing_power.insert( missing_unit );
635 break;
636
637 case ELECTRICAL_PINTYPE::PT_BIDI:
638 missing_bidi.insert( missing_unit );
639 break;
640
641 case ELECTRICAL_PINTYPE::PT_INPUT:
642 missing_input.insert( missing_unit );
643 break;
644
645 default:
646 break;
647 }
648 }
649 }
650
651 if( !missing_power.empty() && m_settings.IsTestEnabled( ERCE_MISSING_POWER_INPUT_PIN ) )
652 {
653 report( missing_power,
654 _( "Symbol %s has input power pins in units %s that are not placed." ),
656 }
657
658 if( !missing_input.empty() && m_settings.IsTestEnabled( ERCE_MISSING_INPUT_PIN ) )
659 {
660 report( missing_input,
661 _( "Symbol %s has input pins in units %s that are not placed." ),
663 }
664
665 if( !missing_bidi.empty() && m_settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
666 {
667 report( missing_bidi,
668 _( "Symbol %s has bidirectional pins in units %s that are not placed." ),
670 }
671 }
672
673 return errors;
674}
675
676
678{
679 int err_count = 0;
680 std::shared_ptr<NET_SETTINGS>& settings = m_schematic->Prj().GetProjectFile().NetSettings();
681 wxString defaultNetclass = settings->GetDefaultNetclass()->GetName();
682
683 auto logError =
684 [&]( const SCH_SHEET_PATH& sheet, SCH_ITEM* item, const wxString& netclass )
685 {
686 err_count++;
687
688 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNDEFINED_NETCLASS );
689
690 ercItem->SetItems( item );
691 ercItem->SetErrorMessage( wxString::Format( _( "Netclass %s is not defined" ),
692 netclass ) );
693
694 SCH_MARKER* marker = new SCH_MARKER( ercItem, item->GetPosition() );
695 sheet.LastScreen()->Append( marker );
696 };
697
698 for( const SCH_SHEET_PATH& sheet : m_sheetList )
699 {
700 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
701 {
702 item->RunOnChildren(
703 [&]( SCH_ITEM* aChild )
704 {
705 if( aChild->Type() == SCH_FIELD_T )
706 {
707 SCH_FIELD* field = static_cast<SCH_FIELD*>( aChild );
708
709 if( field->GetCanonicalName() == wxT( "Netclass" ) )
710 {
711 wxString netclass = field->GetShownText( &sheet, false );
712
713 if( !netclass.IsSameAs( defaultNetclass )
714 && !settings->HasNetclass( netclass ) )
715 {
716 logError( sheet, item, netclass );
717 }
718 }
719 }
720
721 return true;
722 } );
723 }
724 }
725
726 return err_count;
727}
728
729
731{
732 int err_count = 0;
733
734 for( const SCH_SHEET_PATH& sheet : m_sheetList )
735 {
736 std::map<VECTOR2I, std::vector<SCH_ITEM*>> connMap;
737
738 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_LABEL_T ) )
739 {
740 SCH_LABEL* label = static_cast<SCH_LABEL*>( item );
741
742 for( const VECTOR2I& pt : label->GetConnectionPoints() )
743 connMap[pt].emplace_back( label );
744 }
745
746 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
747 {
748 std::vector<SCH_ITEM*> lines;
749
750 for( SCH_ITEM* item : sheet.LastScreen()->Items().Overlapping( SCH_LINE_T, pair.first ) )
751 {
752 SCH_LINE* line = static_cast<SCH_LINE*>( item );
753
754 if( line->IsGraphicLine() )
755 continue;
756
757 // If the line is connected at the endpoint, then there will be a junction
758 if( !line->IsEndPoint( pair.first ) )
759 lines.emplace_back( line );
760 }
761
762 if( lines.size() > 1 )
763 {
764 err_count++;
765 lines.resize( 3 ); // Only show the first 3 lines and if there are only two, adds a nullptr
766
767 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LABEL_MULTIPLE_WIRES );
768 wxString msg = wxString::Format( _( "Label connects more than one wire at %d, %d" ),
769 pair.first.x, pair.first.y );
770
771 ercItem->SetItems( pair.second.front(), lines[0], lines[1], lines[2] );
772 ercItem->SetErrorMessage( msg );
773 ercItem->SetSheetSpecificPath( sheet );
774
775 SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
776 sheet.LastScreen()->Append( marker );
777 }
778 }
779 }
780
781 return err_count;
782}
783
784
786{
787 int err_count = 0;
788
789 for( const SCH_SHEET_PATH& sheet : m_sheetList )
790 {
791 std::map<VECTOR2I, std::vector<SCH_ITEM*>> connMap;
792 SCH_SCREEN* screen = sheet.LastScreen();
793
794 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
795 {
796 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
797
798 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
799 connMap[pin->GetPosition()].emplace_back( pin );
800 }
801
802 for( SCH_ITEM* item : screen->Items().OfType( SCH_LINE_T ) )
803 {
804 SCH_LINE* line = static_cast<SCH_LINE*>( item );
805
806 if( line->IsGraphicLine() )
807 continue;
808
809 for( const VECTOR2I& pt : line->GetConnectionPoints() )
810 connMap[pt].emplace_back( line );
811 }
812
813 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
814 {
815 if( pair.second.size() >= 4 )
816 {
817 err_count++;
818
819 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOUR_WAY_JUNCTION );
820
821 ercItem->SetItems( pair.second[0], pair.second[1], pair.second[2], pair.second[3] );
822
823 wxString msg = wxString::Format( _( "Four items connected at %d, %d" ),
824 pair.first.x, pair.first.y );
825 ercItem->SetErrorMessage( msg );
826
827 ercItem->SetSheetSpecificPath( sheet );
828
829 SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
830 sheet.LastScreen()->Append( marker );
831 }
832 }
833 }
834
835 return err_count;
836}
837
838
840{
841 int err_count = 0;
842
843 for( const SCH_SHEET_PATH& sheet : m_sheetList )
844 {
845 std::map<VECTOR2I, std::vector<SCH_ITEM*>> pinMap;
846
847 auto addOther =
848 [&]( const VECTOR2I& pt, SCH_ITEM* aOther )
849 {
850 if( pinMap.count( pt ) )
851 pinMap[pt].emplace_back( aOther );
852 };
853
854 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
855 {
856 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
857
858 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
859 {
860 if( pin->GetLibPin()->GetType() == ELECTRICAL_PINTYPE::PT_NC )
861 pinMap[pin->GetPosition()].emplace_back( pin );
862 }
863 }
864
865 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
866 {
867 if( item->Type() == SCH_SYMBOL_T )
868 {
869 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
870
871 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
872 {
873 if( pin->GetLibPin()->GetType() != ELECTRICAL_PINTYPE::PT_NC )
874 addOther( pin->GetPosition(), pin );
875 }
876 }
877 else if( item->IsConnectable() )
878 {
879 for( const VECTOR2I& pt : item->GetConnectionPoints() )
880 addOther( pt, item );
881 }
882 }
883
884 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : pinMap )
885 {
886 if( pair.second.size() > 1 )
887 {
888 err_count++;
889
890 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED );
891
892 ercItem->SetItems( pair.second[0], pair.second[1],
893 pair.second.size() > 2 ? pair.second[2] : nullptr,
894 pair.second.size() > 3 ? pair.second[3] : nullptr );
895 ercItem->SetErrorMessage( _( "Pin with 'no connection' type is connected" ) );
896 ercItem->SetSheetSpecificPath( sheet );
897
898 SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
899 sheet.LastScreen()->Append( marker );
900 }
901 }
902 }
903
904 return err_count;
905}
906
907
909{
910 int errors = 0;
911
912 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
913 {
914 using iterator_t = std::vector<ERC_SCH_PIN_CONTEXT>::iterator;
915 std::vector<ERC_SCH_PIN_CONTEXT> pins;
916 std::unordered_map<EDA_ITEM*, SCH_SCREEN*> pinToScreenMap;
917 bool has_noconnect = false;
918
919 for( CONNECTION_SUBGRAPH* subgraph: net.second )
920 {
921 if( subgraph->GetNoConnect() )
922 has_noconnect = true;
923
924 for( SCH_ITEM* item : subgraph->GetItems() )
925 {
926 if( item->Type() == SCH_PIN_T )
927 {
928 pins.emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
929 pinToScreenMap[item] = subgraph->GetSheet().LastScreen();
930 }
931 }
932 }
933
934 std::sort( pins.begin(), pins.end(),
935 []( const ERC_SCH_PIN_CONTEXT& lhs, const ERC_SCH_PIN_CONTEXT& rhs )
936 {
937 int ret = StrNumCmp( lhs.Pin()->GetParentSymbol()->GetRef( &lhs.Sheet() ),
938 rhs.Pin()->GetParentSymbol()->GetRef( &rhs.Sheet() ) );
939
940 if( ret == 0 )
941 ret = StrNumCmp( lhs.Pin()->GetNumber(), rhs.Pin()->GetNumber() );
942
943 if( ret == 0 )
944 ret = lhs < rhs; // Fallback to hash to guarantee deterministic sort
945
946 return ret < 0;
947 } );
948
949 ERC_SCH_PIN_CONTEXT needsDriver;
950 ELECTRICAL_PINTYPE needsDriverType = ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
951 bool hasDriver = false;
952
953 // We need different drivers for power nets and normal nets.
954 // A power net has at least one pin having the ELECTRICAL_PINTYPE::PT_POWER_IN
955 // and power nets can be driven only by ELECTRICAL_PINTYPE::PT_POWER_OUT pins
956 bool ispowerNet = false;
957
958 for( ERC_SCH_PIN_CONTEXT& refPin : pins )
959 {
960 if( refPin.Pin()->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
961 {
962 ispowerNet = true;
963 break;
964 }
965 }
966
967 std::vector<std::tuple<iterator_t, iterator_t, PIN_ERROR>> pin_mismatches;
968 std::map<iterator_t, int> pin_mismatch_counts;
969
970 for( auto refIt = pins.begin(); refIt != pins.end(); ++refIt )
971 {
972 ERC_SCH_PIN_CONTEXT& refPin = *refIt;
973 ELECTRICAL_PINTYPE refType = refPin.Pin()->GetType();
974
975 if( DrivenPinTypes.contains( refType ) )
976 {
977 // needsDriver will be the pin shown in the error report eventually, so try to
978 // upgrade to a "better" pin if possible: something visible and only a power symbol
979 // if this net needs a power driver
980 if( !needsDriver.Pin()
981 || ( !needsDriver.Pin()->IsVisible() && refPin.Pin()->IsVisible() )
982 || ( ispowerNet != ( needsDriverType == ELECTRICAL_PINTYPE::PT_POWER_IN )
983 && ispowerNet == ( refType == ELECTRICAL_PINTYPE::PT_POWER_IN ) ) )
984 {
985 needsDriver = refPin;
986 needsDriverType = needsDriver.Pin()->GetType();
987 }
988 }
989
990 if( ispowerNet )
991 hasDriver |= ( DrivingPowerPinTypes.count( refType ) != 0 );
992 else
993 hasDriver |= ( DrivingPinTypes.count( refType ) != 0 );
994
995 for( auto testIt = refIt + 1; testIt != pins.end(); ++testIt )
996 {
997 ERC_SCH_PIN_CONTEXT& testPin = *testIt;
998
999 // Multiple pins in the same symbol that share a type,
1000 // name and position are considered
1001 // "stacked" and shouldn't trigger ERC errors
1002 if( refPin.Pin()->IsStacked( testPin.Pin() ) && refPin.Sheet() == testPin.Sheet() )
1003 continue;
1004
1005 ELECTRICAL_PINTYPE testType = testPin.Pin()->GetType();
1006
1007 if( ispowerNet )
1008 hasDriver |= DrivingPowerPinTypes.contains( testType );
1009 else
1010 hasDriver |= DrivingPinTypes.contains( testType );
1011
1012 PIN_ERROR erc = m_settings.GetPinMapValue( refType, testType );
1013
1014 if( erc != PIN_ERROR::OK && m_settings.IsTestEnabled( ERCE_PIN_TO_PIN_WARNING ) )
1015 {
1016 pin_mismatches.emplace_back(
1017 std::tuple<iterator_t, iterator_t, PIN_ERROR>{ refIt, testIt, erc } );
1018
1019 if( m_settings.GetERCSortingMetric() == ERC_PIN_SORTING_METRIC::SM_HEURISTICS )
1020 {
1021 pin_mismatch_counts[refIt] =
1022 m_settings.GetPinTypeWeight( ( *refIt ).Pin()->GetType() );
1023
1024 pin_mismatch_counts[testIt] =
1025 m_settings.GetPinTypeWeight( ( *testIt ).Pin()->GetType() );
1026 }
1027 else
1028 {
1029 if( !pin_mismatch_counts.contains( testIt ) )
1030 pin_mismatch_counts.emplace( testIt, 1 );
1031 else
1032 pin_mismatch_counts[testIt]++;
1033
1034 if( !pin_mismatch_counts.contains( refIt ) )
1035 pin_mismatch_counts.emplace( refIt, 1 );
1036 else
1037 pin_mismatch_counts[refIt]++;
1038 }
1039 }
1040 }
1041 }
1042
1043 std::multimap<size_t, iterator_t, std::greater<size_t>> pins_dsc;
1044
1045 std::transform( pin_mismatch_counts.begin(), pin_mismatch_counts.end(),
1046 std::inserter( pins_dsc, pins_dsc.begin() ),
1047 []( const auto& p )
1048 {
1049 return std::pair<size_t, iterator_t>( p.second, p.first );
1050 } );
1051
1052 for( const auto& [amount, pinItBind] : pins_dsc )
1053 {
1054 auto& pinIt = pinItBind;
1055
1056 if( pin_mismatches.empty() )
1057 break;
1058
1059 SCH_PIN* pin = ( *pinIt ).Pin();
1060 VECTOR2I position = pin->GetPosition();
1061
1062 iterator_t nearest_pin = pins.end();
1063 double smallest_distance = std::numeric_limits<double>::infinity();
1064 PIN_ERROR erc;
1065
1066 std::erase_if(
1067 pin_mismatches,
1068 [&]( const auto& tuple )
1069 {
1070 iterator_t other;
1071
1072 if( pinIt == std::get<0>( tuple ) )
1073 other = std::get<1>( tuple );
1074 else if( pinIt == std::get<1>( tuple ) )
1075 other = std::get<0>( tuple );
1076 else
1077 return false;
1078
1079 if( ( *pinIt ).Sheet().Cmp( ( *other ).Sheet() ) != 0 )
1080 {
1081 if( std::isinf( smallest_distance ) )
1082 {
1083 nearest_pin = other;
1084 erc = std::get<2>( tuple );
1085 }
1086 }
1087 else
1088 {
1089 double distance = position.Distance( ( *other ).Pin()->GetPosition() );
1090
1091 if( std::isinf( smallest_distance ) || distance < smallest_distance )
1092 {
1093 smallest_distance = distance;
1094 nearest_pin = other;
1095 erc = std::get<2>( tuple );
1096 }
1097 }
1098
1099 return true;
1100 } );
1101
1102 if( nearest_pin != pins.end() )
1103 {
1104 SCH_PIN* other_pin = ( *nearest_pin ).Pin();
1105
1106 std::shared_ptr<ERC_ITEM> ercItem =
1107 ERC_ITEM::Create( erc == PIN_ERROR::WARNING ? ERCE_PIN_TO_PIN_WARNING
1109 ercItem->SetItems( pin, other_pin );
1110 ercItem->SetSheetSpecificPath( ( *pinIt ).Sheet() );
1111 ercItem->SetItemsSheetPaths( ( *pinIt ).Sheet(), ( *nearest_pin ).Sheet() );
1112
1113 ercItem->SetErrorMessage(
1114 wxString::Format( _( "Pins of type %s and %s are connected" ),
1115 ElectricalPinTypeGetText( pin->GetType() ),
1116 ElectricalPinTypeGetText( other_pin->GetType() ) ) );
1117
1118 SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() );
1119 pinToScreenMap[pin]->Append( marker );
1120 errors++;
1121 }
1122 }
1123
1124 if( needsDriver.Pin() && !hasDriver && !has_noconnect )
1125 {
1126 int err_code = ispowerNet ? ERCE_POWERPIN_NOT_DRIVEN : ERCE_PIN_NOT_DRIVEN;
1127
1128 if( m_settings.IsTestEnabled( err_code ) )
1129 {
1130 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( err_code );
1131
1132 ercItem->SetItems( needsDriver.Pin() );
1133 ercItem->SetSheetSpecificPath( needsDriver.Sheet() );
1134 ercItem->SetItemsSheetPaths( needsDriver.Sheet() );
1135
1136 SCH_MARKER* marker = new SCH_MARKER( ercItem, needsDriver.Pin()->GetPosition() );
1137 pinToScreenMap[needsDriver.Pin()]->Append( marker );
1138 errors++;
1139 }
1140 }
1141 }
1142
1143 return errors;
1144}
1145
1146
1148{
1149 int errors = 0;
1150
1151 std::unordered_map<wxString, std::pair<wxString, SCH_PIN*>> pinToNetMap;
1152
1153 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1154 {
1155 const wxString& netName = net.first.Name;
1156
1157 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1158 {
1159 for( SCH_ITEM* item : subgraph->GetItems() )
1160 {
1161 if( item->Type() == SCH_PIN_T )
1162 {
1163 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1164 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1165
1166 if( !pin->GetLibPin()->GetParentSymbol()->IsMulti() )
1167 continue;
1168
1169 wxString name = pin->GetParentSymbol()->GetRef( &sheet ) +
1170 + ":" + pin->GetShownNumber();
1171
1172 if( !pinToNetMap.count( name ) )
1173 {
1174 pinToNetMap[name] = std::make_pair( netName, pin );
1175 }
1176 else if( pinToNetMap[name].first != netName )
1177 {
1178 std::shared_ptr<ERC_ITEM> ercItem =
1180
1181 ercItem->SetErrorMessage( wxString::Format(
1182 _( "Pin %s is connected to both %s and %s" ),
1183 pin->GetShownNumber(),
1184 netName,
1185 pinToNetMap[name].first ) );
1186
1187 ercItem->SetItems( pin, pinToNetMap[name].second );
1188 ercItem->SetSheetSpecificPath( sheet );
1189 ercItem->SetItemsSheetPaths( sheet, sheet );
1190
1191 SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() );
1192 sheet.LastScreen()->Append( marker );
1193 errors += 1;
1194 }
1195 }
1196 }
1197 }
1198 }
1199
1200 return errors;
1201}
1202
1203
1205{
1206 int errCount = 0;
1207
1208 std::unordered_map<wxString, std::pair<SCH_ITEM*, SCH_SHEET_PATH>> globalLabels;
1209 std::unordered_map<wxString, std::pair<SCH_ITEM*, SCH_SHEET_PATH>> localLabels;
1210
1211 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1212 {
1213 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1214 {
1215 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1216
1217 for( SCH_ITEM* item : subgraph->GetItems() )
1218 {
1219 if( item->Type() == SCH_LABEL_T || item->Type() == SCH_GLOBAL_LABEL_T )
1220 {
1221 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
1222 wxString text = label->GetShownText( &sheet, false );
1223
1224 auto& map = item->Type() == SCH_LABEL_T ? localLabels : globalLabels;
1225
1226 if( !map.count( text ) )
1227 {
1228 map[text] = std::make_pair( label, sheet );
1229 }
1230 }
1231 }
1232 }
1233 }
1234
1235 for( auto& [globalText, globalItem] : globalLabels )
1236 {
1237 for( auto& [localText, localItem] : localLabels )
1238 {
1239 if( globalText == localText )
1240 {
1241 std::shared_ptr<ERC_ITEM> ercItem =
1243 ercItem->SetItems( globalItem.first, localItem.first );
1244 ercItem->SetSheetSpecificPath( globalItem.second );
1245 ercItem->SetItemsSheetPaths( globalItem.second, localItem.second );
1246
1247 SCH_MARKER* marker = new SCH_MARKER( ercItem, globalItem.first->GetPosition() );
1248 globalItem.second.LastScreen()->Append( marker );
1249
1250 errCount++;
1251 }
1252 }
1253 }
1254
1255 return errCount;
1256}
1257
1258
1260{
1261 int errors = 0;
1262 std::unordered_map<wxString, std::vector<std::tuple<wxString, SCH_ITEM*, SCH_SHEET_PATH>>> generalMap;
1263
1264 auto logError = [&]( const wxString& normalized, SCH_ITEM* item, const SCH_SHEET_PATH& sheet,
1265 const std::tuple<wxString, SCH_ITEM*, SCH_SHEET_PATH>& other )
1266 {
1267 auto& [otherText, otherItem, otherSheet] = other;
1268 ERCE_T typeOfWarning = ERCE_SIMILAR_LABELS;
1269
1270 if( item->Type() == SCH_PIN_T && otherItem->Type() == SCH_PIN_T )
1271 {
1272 //Two Pins
1273 typeOfWarning = ERCE_SIMILAR_POWER;
1274 }
1275 else if( item->Type() == SCH_PIN_T || otherItem->Type() == SCH_PIN_T )
1276 {
1277 //Pin and Label
1278 typeOfWarning = ERCE_SIMILAR_LABEL_AND_POWER;
1279 }
1280 else
1281 {
1282 //Two Labels
1283 typeOfWarning = ERCE_SIMILAR_LABELS;
1284 }
1285
1286 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( typeOfWarning );
1287 ercItem->SetItems( item, otherItem );
1288 ercItem->SetSheetSpecificPath( sheet );
1289 ercItem->SetItemsSheetPaths( sheet, otherSheet );
1290
1291 SCH_MARKER* marker = new SCH_MARKER( ercItem, item->GetPosition() );
1292 sheet.LastScreen()->Append( marker );
1293 };
1294
1295 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1296 {
1297 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1298 {
1299 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1300
1301 for( SCH_ITEM* item : subgraph->GetItems() )
1302 {
1303 switch( item->Type() )
1304 {
1305 case SCH_LABEL_T:
1306 case SCH_HIER_LABEL_T:
1307 case SCH_GLOBAL_LABEL_T:
1308 {
1309 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
1310 wxString unnormalized = label->GetShownText( &sheet, false );
1311 wxString normalized = unnormalized.Lower();
1312
1313 generalMap[normalized].emplace_back( std::make_tuple( unnormalized, label, sheet ) );
1314
1315 for( const auto& otherTuple : generalMap.at( normalized ) )
1316 {
1317 const auto& [otherText, otherItem, otherSheet] = otherTuple;
1318
1319 if( unnormalized != otherText )
1320 {
1321 logError( normalized, label, sheet, otherTuple );
1322 errors += 1;
1323 }
1324 }
1325
1326 break;
1327 }
1328 case SCH_PIN_T:
1329 {
1330 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1331
1332 if( !pin->IsGlobalPower() )
1333 {
1334 continue;
1335 }
1336
1337 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
1338 wxString unnormalized = symbol->GetValue( true, &sheet, false );
1339 wxString normalized = unnormalized.Lower();
1340
1341 generalMap[normalized].emplace_back( std::make_tuple( unnormalized, pin, sheet ) );
1342
1343 for( const auto& otherTuple : generalMap.at( normalized ) )
1344 {
1345 const auto& [otherText, otherItem, otherSheet] = otherTuple;
1346
1347 if( unnormalized != otherText )
1348 {
1349 logError( normalized, pin, sheet, otherTuple );
1350 errors += 1;
1351 }
1352 }
1353
1354 break;
1355 }
1356
1357 default:
1358 break;
1359 }
1360 }
1361 }
1362 }
1363 return errors;
1364}
1365
1366
1368{
1369 wxCHECK( m_schematic, 0 );
1370
1372 wxString msg;
1373 int err_count = 0;
1374
1375 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
1376 {
1377 std::vector<SCH_MARKER*> markers;
1378
1379 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1380 {
1381 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1382 LIB_SYMBOL* libSymbolInSchematic = symbol->GetLibSymbolRef().get();
1383
1384 wxCHECK2( libSymbolInSchematic, continue );
1385
1386 wxString libName = symbol->GetLibId().GetLibNickname();
1387 LIB_TABLE_ROW* libTableRow = libTable->FindRow( libName, true );
1388
1389 if( !libTableRow )
1390 {
1392 {
1393 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1394 ercItem->SetItems( symbol );
1395 msg.Printf( _( "The current configuration does not include the symbol library '%s'" ),
1396 UnescapeString( libName ) );
1397 ercItem->SetErrorMessage( msg );
1398
1399 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1400 }
1401
1402 continue;
1403 }
1404 else if( !libTable->HasLibrary( libName, true ) )
1405 {
1407 {
1408 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1409 ercItem->SetItems( symbol );
1410 msg.Printf( _( "The library '%s' is not enabled in the current configuration" ),
1411 UnescapeString( libName ) );
1412 ercItem->SetErrorMessage( msg );
1413
1414 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1415 }
1416
1417 continue;
1418 }
1419
1420 wxString symbolName = symbol->GetLibId().GetLibItemName();
1421 LIB_SYMBOL* libSymbol = SchGetLibSymbol( symbol->GetLibId(), libTable );
1422
1423 if( libSymbol == nullptr )
1424 {
1426 {
1427 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1428 ercItem->SetItems( symbol );
1429 msg.Printf( _( "Symbol '%s' not found in symbol library '%s'" ),
1430 UnescapeString( symbolName ),
1431 UnescapeString( libName ) );
1432 ercItem->SetErrorMessage( msg );
1433
1434 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1435 }
1436
1437 continue;
1438 }
1439
1440 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->Flatten();
1442
1444 {
1445 // We have to check for duplicate pins first as they will cause Compare() to fail.
1446 std::vector<wxString> messages;
1447 UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILS );
1448 CheckDuplicatePins( libSymbolInSchematic, messages, &unitsProvider );
1449
1450 if( !messages.empty() )
1451 {
1452 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DUPLICATE_PIN_ERROR );
1453 ercItem->SetItems( symbol );
1454 msg.Printf( _( "Symbol '%s' has multiple pins with the same pin number" ),
1455 UnescapeString( symbolName ) );
1456 ercItem->SetErrorMessage( msg );
1457
1458 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1459 }
1460 else if( flattenedSymbol->Compare( *libSymbolInSchematic, flags ) != 0 )
1461 {
1462 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_MISMATCH );
1463 ercItem->SetItems( symbol );
1464 msg.Printf( _( "Symbol '%s' doesn't match copy in library '%s'" ),
1465 UnescapeString( symbolName ),
1466 UnescapeString( libName ) );
1467 ercItem->SetErrorMessage( msg );
1468
1469 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1470 }
1471 }
1472 }
1473
1474 for( SCH_MARKER* marker : markers )
1475 {
1476 screen->Append( marker );
1477 err_count += 1;
1478 }
1479 }
1480
1481 return err_count;
1482}
1483
1484
1486{
1487 wxCHECK( m_schematic, 0 );
1488
1489 wxString msg;
1490 int err_count = 0;
1491
1492 typedef int (*TESTER_FN_PTR)( const wxString&, PROJECT* );
1493
1494 TESTER_FN_PTR linkTester = (TESTER_FN_PTR) aCvPcb->IfaceOrAddress( KIFACE_TEST_FOOTPRINT_LINK );
1495
1496 for( SCH_SHEET_PATH& sheet : m_sheetList )
1497 {
1498 std::vector<SCH_MARKER*> markers;
1499
1500 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1501 {
1502 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1503 wxString footprint = symbol->GetFootprintFieldText( true, &sheet, false );
1504
1505 if( footprint.IsEmpty() )
1506 continue;
1507
1508 LIB_ID fpID;
1509
1510 if( fpID.Parse( footprint, true ) >= 0 )
1511 {
1512 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1513 msg.Printf( _( "'%s' is not a valid footprint identifier." ), footprint );
1514 ercItem->SetErrorMessage( msg );
1515 ercItem->SetItems( symbol );
1516 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1517 continue;
1518 }
1519
1520 wxString libName = fpID.GetLibNickname();
1521 wxString fpName = fpID.GetLibItemName();
1522 int ret = (linkTester)( footprint, aProject );
1523
1525 {
1526 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1527 msg.Printf( _( "The current configuration does not include the footprint library '%s'." ),
1528 libName );
1529 ercItem->SetErrorMessage( msg );
1530 ercItem->SetItems( symbol );
1531 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1532 }
1534 {
1535 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1536 msg.Printf( _( "The footprint library '%s' is not enabled in the current configuration." ),
1537 libName );
1538 ercItem->SetErrorMessage( msg );
1539 ercItem->SetItems( symbol );
1540 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1541 }
1543 {
1544 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1545 msg.Printf( _( "Footprint '%s' not found in library '%s'." ),
1546 fpName,
1547 libName );
1548 ercItem->SetErrorMessage( msg );
1549 ercItem->SetItems( symbol );
1550 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1551 }
1552 }
1553
1554 for( SCH_MARKER* marker : markers )
1555 {
1556 sheet.LastScreen()->Append( marker );
1557 err_count += 1;
1558 }
1559 }
1560
1561 return err_count;
1562}
1563
1564
1566{
1567 wxCHECK( m_schematic, 0 );
1568
1569 wxString msg;
1570 int err_count = 0;
1571
1572 for( SCH_SHEET_PATH& sheet : m_sheetList )
1573 {
1574 std::vector<SCH_MARKER*> markers;
1575
1576 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1577 {
1578 SCH_SYMBOL* sch_symbol = static_cast<SCH_SYMBOL*>( item );
1579 std::unique_ptr<LIB_SYMBOL>& lib_symbol = sch_symbol->GetLibSymbolRef();
1580
1581 if( !lib_symbol )
1582 continue;
1583
1584 wxArrayString filters = lib_symbol->GetFPFilters();
1585
1586 if( filters.empty() )
1587 continue;
1588
1589 wxString lowerId = sch_symbol->GetFootprintFieldText( true, &sheet, false ).Lower();
1590 LIB_ID footprint;
1591
1592 if( footprint.Parse( lowerId ) > 0 )
1593 continue;
1594
1595 wxString lowerItemName = footprint.GetUniStringLibItemName().Lower();
1596 bool found = false;
1597
1598 for( wxString filter : filters )
1599 {
1600 filter.LowerCase();
1601
1602 // If the filter contains a ':' character, include the library name in the pattern
1603 if( filter.Contains( wxS( ":" ) ) )
1604 found |= lowerId.Matches( filter );
1605 else
1606 found |= lowerItemName.Matches( filter );
1607
1608 if( found )
1609 break;
1610 }
1611
1612 if( !found )
1613 {
1614 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1615 msg.Printf( _( "Assigned footprint (%s) doesn't match footprint filters (%s)." ),
1616 lowerItemName,
1617 wxJoin( filters, ' ' ) );
1618 ercItem->SetErrorMessage( msg );
1619 ercItem->SetItems( sch_symbol );
1620 markers.emplace_back( new SCH_MARKER( ercItem, sch_symbol->GetPosition() ) );
1621 }
1622 }
1623
1624 for( SCH_MARKER* marker : markers )
1625 {
1626 sheet.LastScreen()->Append( marker );
1627 err_count += 1;
1628 }
1629 }
1630
1631 return err_count;
1632}
1633
1634
1636{
1637 const int gridSize = m_schematic->Settings().m_ConnectionGridSize;
1638 int err_count = 0;
1639
1640 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
1641 {
1642 std::vector<SCH_MARKER*> markers;
1643
1644 for( SCH_ITEM* item : screen->Items() )
1645 {
1646 if( item->Type() == SCH_LINE_T && item->IsConnectable() )
1647 {
1648 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1649
1650 if( ( line->GetStartPoint().x % gridSize ) != 0
1651 || ( line->GetStartPoint().y % gridSize ) != 0 )
1652 {
1653 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1654 ercItem->SetItems( line );
1655
1656 markers.emplace_back( new SCH_MARKER( ercItem, line->GetStartPoint() ) );
1657 }
1658 else if( ( line->GetEndPoint().x % gridSize ) != 0
1659 || ( line->GetEndPoint().y % gridSize ) != 0 )
1660 {
1661 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1662 ercItem->SetItems( line );
1663
1664 markers.emplace_back( new SCH_MARKER( ercItem, line->GetEndPoint() ) );
1665 }
1666 }
1667 else if( item->Type() == SCH_SYMBOL_T )
1668 {
1669 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1670
1671 for( SCH_PIN* pin : symbol->GetPins( nullptr ) )
1672 {
1673 VECTOR2I pinPos = pin->GetPosition();
1674
1675 if( ( pinPos.x % gridSize ) != 0 || ( pinPos.y % gridSize ) != 0 )
1676 {
1677 auto ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1678 ercItem->SetItems( pin );
1679
1680 markers.emplace_back( new SCH_MARKER( ercItem, pinPos ) );
1681 break;
1682 }
1683 }
1684 }
1685 }
1686
1687 for( SCH_MARKER* marker : markers )
1688 {
1689 screen->Append( marker );
1690 err_count += 1;
1691 }
1692 }
1693
1694 return err_count;
1695}
1696
1697
1699{
1700 WX_STRING_REPORTER reporter;
1701 int err_count = 0;
1702 SIM_LIB_MGR libMgr( &m_schematic->Prj() );
1703
1704 for( SCH_SHEET_PATH& sheet : m_sheetList )
1705 {
1706 if( sheet.GetExcludedFromSim() )
1707 continue;
1708
1709 std::vector<SCH_MARKER*> markers;
1710
1711 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1712 {
1713 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1714
1715 // Power symbols and other symbols which have the reference starting with "#" are
1716 // not included in simulation
1717 if( symbol->GetRef( &sheet ).StartsWith( '#' ) || symbol->GetExcludedFromSim() )
1718 continue;
1719
1720 // Reset for each symbol
1721 reporter.Clear();
1722
1723 SIM_LIBRARY::MODEL model = libMgr.CreateModel( &sheet, *symbol, reporter );
1724
1725 if( reporter.HasMessage() )
1726 {
1727 wxString msg = reporter.GetMessages();
1728 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMULATION_MODEL );
1729
1730 //Remove \n and \r at e.o.l if any:
1731 msg.Trim();
1732
1733 ercItem->SetErrorMessage( msg );
1734 ercItem->SetItems( symbol );
1735
1736 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1737 }
1738 }
1739
1740 for( SCH_MARKER* marker : markers )
1741 {
1742 sheet.LastScreen()->Append( marker );
1743 err_count += 1;
1744 }
1745 }
1746
1747 return err_count;
1748}
1749
1750
1752 KIFACE* aCvPcb, PROJECT* aProject, PROGRESS_REPORTER* aProgressReporter )
1753{
1755
1756 // Test duplicate sheet names inside a given sheet. While one can have multiple references
1757 // to the same file, each must have a unique name.
1759 {
1760 if( aProgressReporter )
1761 aProgressReporter->AdvancePhase( _( "Checking sheet names..." ) );
1762
1764 }
1765
1767 {
1768 if( aProgressReporter )
1769 aProgressReporter->AdvancePhase( _( "Checking bus conflicts..." ) );
1770
1772 }
1773
1774 // The connection graph has a whole set of ERC checks it can run
1775 if( aProgressReporter )
1776 aProgressReporter->AdvancePhase( _( "Checking conflicts..." ) );
1777
1778 // If we are using the new connectivity, make sure that we do a full-rebuild
1779 if( aEditFrame )
1780 {
1781 if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
1782 aEditFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
1783 else
1784 aEditFrame->RecalculateConnections( nullptr, NO_CLEANUP );
1785 }
1786
1788
1789 if( aProgressReporter )
1790 aProgressReporter->AdvancePhase( _( "Checking units..." ) );
1791
1792 // Test is all units of each multiunit symbol have the same footprint assigned.
1794 {
1795 if( aProgressReporter )
1796 aProgressReporter->AdvancePhase( _( "Checking footprints..." ) );
1797
1799 }
1800
1805 {
1807 }
1808
1809 if( aProgressReporter )
1810 aProgressReporter->AdvancePhase( _( "Checking pins..." ) );
1811
1814
1815 // Test pins on each net against the pin connection table
1819 {
1820 TestPinToPin();
1821 }
1822
1823 // Test similar labels (i;e. labels which are identical when
1824 // using case insensitive comparisons)
1829 {
1830 if( aProgressReporter )
1831 aProgressReporter->AdvancePhase( _( "Checking labels..." ) );
1832
1835 }
1836
1838 {
1839 if( aProgressReporter )
1840 aProgressReporter->AdvancePhase( _( "Checking for unresolved variables..." ) );
1841
1842 TestTextVars( aDrawingSheet );
1843 }
1844
1846 {
1847 if( aProgressReporter )
1848 aProgressReporter->AdvancePhase( _( "Checking SPICE models..." ) );
1849
1851 }
1852
1854 {
1855 if( aProgressReporter )
1856 aProgressReporter->AdvancePhase( _( "Checking no connect pins for connections..." ) );
1857
1859 }
1860
1863 {
1864 if( aProgressReporter )
1865 aProgressReporter->AdvancePhase( _( "Checking for library symbol issues..." ) );
1866
1868 }
1869
1871 {
1872 if( aProgressReporter )
1873 aProgressReporter->AdvancePhase( _( "Checking for footprint link issues..." ) );
1874
1875 TestFootprintLinkIssues( aCvPcb, aProject );
1876 }
1877
1879 {
1880 if( aProgressReporter )
1881 aProgressReporter->AdvancePhase( _( "Checking footprint assignments against footprint filters..." ) );
1882
1884 }
1885
1887 {
1888 if( aProgressReporter )
1889 aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) );
1890
1892 }
1893
1895 {
1896 if( aProgressReporter )
1897 aProgressReporter->AdvancePhase( _( "Checking for four way junctions..." ) );
1898
1900 }
1901
1903 {
1904 if( aProgressReporter )
1905 aProgressReporter->AdvancePhase( _( "Checking for labels on more than one wire..." ) );
1906
1908 }
1909
1911 {
1912 if( aProgressReporter )
1913 aProgressReporter->AdvancePhase( _( "Checking for undefined netclasses..." ) );
1914
1916 }
1917
1919}
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
int RunERC()
Run electrical rule checks on the connectivity graph.
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.
Definition: ds_draw_item.h:59
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
Definition: ds_draw_item.h:401
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.
Definition: ds_draw_item.h:445
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ds_draw_item.h:450
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
Definition: ds_draw_item.h:460
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
Definition: ds_draw_item.h:499
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
Definition: ds_draw_item.h:489
void SetProject(const PROJECT *aProject)
Definition: ds_draw_item.h:425
A graphic text.
Definition: ds_draw_item.h:313
const PAGE_INFO & GetPageInfo()
const TITLE_BLOCK & GetTitleBlock()
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:243
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition: erc_item.cpp:299
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.
bool IsTestEnabled(int aErrorCode) const
Definition: erc_settings.h:151
ERC_PIN_SORTING_METRIC GetERCSortingMetric() const
Get the type of sorting metric the ERC checker should use to resolve multi-pin errors.
Definition: erc_settings.h:178
PIN_ERROR GetPinMapValue(int aFirstType, int aSecondType) const
Definition: erc_settings.h:180
int GetPinTypeWeight(ELECTRICAL_PINTYPE aPinType) const
Get the weight for an electrical pin type.
Definition: erc_settings.h:168
int TestLibSymbolIssues()
Test symbols for changed library symbols and broken symbol library links.
Definition: erc.cpp:1367
const NET_MAP & m_nets
Definition: erc.h:191
void TestTextVars(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Check for any unresolved text variable references.
Definition: erc.cpp:183
int TestPinToPin()
Checks the full netlist against the pin-to-pin connectivity requirements.
Definition: erc.cpp:908
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition: erc.cpp:1259
SCH_MULTI_UNIT_REFERENCE_MAP m_refMap
Definition: erc.h:190
SCH_SCREENS m_screens
Definition: erc.h:189
int TestFootprintLinkIssues(KIFACE *aCvPcb, PROJECT *aProject)
Test footprint links against the current footprint libraries.
Definition: erc.cpp:1485
int TestOffGridEndpoints()
Test pins and wire ends for being off grid.
Definition: erc.cpp:1635
int TestDuplicateSheetNames(bool aCreateMarker)
Inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated).
Definition: erc.cpp:140
int TestSameLocalGlobalLabel()
Checks for global and local labels with the same name.
Definition: erc.cpp:1204
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition: erc.cpp:1147
int TestConflictingBusAliases()
Check that there are no conflicting bus alias definitions in the schematic.
Definition: erc.cpp:434
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
Definition: erc.cpp:839
int TestFootprintFilters()
Test symbols to ensure that assigned footprint passes any given footprint filters.
Definition: erc.cpp:1565
ERC_SETTINGS & m_settings
Definition: erc.h:187
int TestFourWayJunction()
Test to see if there are potentially confusing 4-way junctions in the schematic.
Definition: erc.cpp:785
int TestMissingNetclasses()
Tests for netclasses that are referenced but not defined.
Definition: erc.cpp:677
int TestSimModelIssues()
Test SPICE models for various issues.
Definition: erc.cpp:1698
SCH_SHEET_LIST m_sheetList
Definition: erc.h:188
SCHEMATIC * m_schematic
Definition: erc.h:186
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition: erc.cpp:1751
int TestMissingUnits()
Test for uninstantiated units of multi unit symbols.
Definition: erc.cpp:540
int TestLabelMultipleWires()
Test to see if there are labels that are connected to more than one wire.
Definition: erc.cpp:730
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition: erc.cpp:479
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:51
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:78
std::vector< SCH_PIN * > GetPins(int aUnit=0, int aBodyStyle=0) const
Return a list of pin object pointers from the draw item list.
Definition: lib_symbol.cpp:822
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
Definition: lib_symbol.cpp:260
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:304
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
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.
std::shared_ptr< NET_SETTINGS > & NetSettings()
Definition: project_file.h:103
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
Container for project specific data.
Definition: project.h:64
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:200
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
Definition: schematic.cpp:843
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:314
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:162
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:92
Schematic editor (Eeschema) main window.
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
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:232
@ EQUALITY
Definition: sch_item.h:660
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const override
Definition: sch_label.cpp:816
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_label.cpp:896
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:706
VECTOR2I GetEndPoint() const
Definition: sch_line.h:141
VECTOR2I GetStartPoint() const
Definition: sch_line.h:136
bool IsEndPoint(const VECTOR2I &aPoint) const
Definition: sch_line.h:90
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:967
bool IsVisible() const
Definition: sch_pin.cpp:362
bool IsStacked(const SCH_PIN *aPin) const
Definition: sch_pin.cpp:421
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:304
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
SCH_REFERENCE & GetItem(size_t aIdx)
size_t GetCount() const
A helper to define a symbol's reference designator in a schematic.
const SCH_SHEET_PATH & GetSheetPath() const
const wxString GetFootprint() const
SCH_SYMBOL * GetSymbol() const
LIB_SYMBOL * GetLibPart() const
int GetUnit() const
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:153
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:108
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
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.
Definition: sch_sheet_pin.h:66
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:93
VECTOR2I GetPosition() const override
Definition: sch_sheet.h:400
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:181
wxString GetShownName(bool aAllowExtraText) const
Definition: sch_sheet.h:103
Schematic symbol object.
Definition: sch_symbol.h:104
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const override
Definition: sch_symbol.cpp:907
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve a list of the SCH_PINs for the given sheet path.
const wxString GetFootprintFieldText(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const
Definition: sch_symbol.cpp:923
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:807
const LIB_ID & GetLibId() const override
Definition: sch_symbol.h:193
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:987
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:212
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:737
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
bool GetExcludedFromSim() const override
Definition: symbol.h:136
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
Definition: vector2d.h:557
A wrapper for reporting to a wxString object.
Definition: reporter.h:171
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:97
const wxString & GetMessages() const
Definition: reporter.cpp:84
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:348
The common library.
#define FOR_ERC_DRC
Expand '${var-name}' templates in text.
Definition: common.h:91
#define _(s)
void CheckDuplicatePins(LIB_SYMBOL *aSymbol, std::vector< wxString > &aMessages, UNITS_PROVIDER *aUnitsProvider)
const wxString CommentERC_V[]
Definition: erc.cpp:93
const wxString CommentERC_H[]
Definition: erc.cpp:76
const std::set< ELECTRICAL_PINTYPE > DrivenPinTypes
Definition: erc.cpp:131
const std::set< ELECTRICAL_PINTYPE > DrivingPinTypes
Definition: erc.cpp:113
const std::set< ELECTRICAL_PINTYPE > DrivingPowerPinTypes
Definition: erc.cpp:125
ERCE_T
ERC error codes.
Definition: erc_settings.h:37
@ ERCE_POWERPIN_NOT_DRIVEN
Power input pin connected to some others pins but no power out pin to drive it.
Definition: erc_settings.h:45
@ ERCE_SIMILAR_POWER
2 power pins are equal for case insensitive comparisons.
Definition: erc_settings.h:52
@ ERCE_MISSING_POWER_INPUT_PIN
Symbol has power input pins that are not placed on the schematic.
Definition: erc_settings.h:58
@ ERCE_SIMILAR_LABELS
2 labels are equal for case insensitive comparisons.
Definition: erc_settings.h:51
@ ERCE_ENDPOINT_OFF_GRID
Pin or wire-end off grid.
Definition: erc_settings.h:41
@ ERCE_SAME_LOCAL_GLOBAL_LABEL
2 labels are equal for case insensitive comparisons.
Definition: erc_settings.h:55
@ ERCE_SIMILAR_LABEL_AND_POWER
label and pin are equal for case insensitive comparisons.
Definition: erc_settings.h:53
@ ERCE_FOOTPRINT_LINK_ISSUES
The footprint link is invalid, or points to a missing (or inactive) footprint or library.
Definition: erc_settings.h:79
@ ERCE_DUPLICATE_PIN_ERROR
Definition: erc_settings.h:96
@ ERCE_DIFFERENT_UNIT_NET
Shared pin in a multi-unit symbol is connected to more than one net.
Definition: erc_settings.h:63
@ ERCE_FOUR_WAY_JUNCTION
A four-way junction was found.
Definition: erc_settings.h:87
@ ERCE_UNDEFINED_NETCLASS
A netclass was referenced but not defined.
Definition: erc_settings.h:74
@ ERCE_UNRESOLVED_VARIABLE
A text variable could not be resolved.
Definition: erc_settings.h:73
@ ERCE_SIMULATION_MODEL
An error was found in the simulation model.
Definition: erc_settings.h:75
@ ERCE_LIB_SYMBOL_MISMATCH
Symbol doesn't match copy in library.
Definition: erc_settings.h:78
@ ERCE_GENERIC_ERROR
Definition: erc_settings.h:102
@ ERCE_DIFFERENT_UNIT_FP
Different units of the same symbol have different footprints assigned.
Definition: erc_settings.h:56
@ ERCE_NOCONNECT_CONNECTED
A no connect symbol is connected to more than 1 pin.
Definition: erc_settings.h:48
@ ERCE_PIN_TO_PIN_WARNING
Definition: erc_settings.h:97
@ ERCE_PIN_NOT_DRIVEN
Pin connected to some others pins but no pin to drive it.
Definition: erc_settings.h:43
@ ERCE_MISSING_INPUT_PIN
Symbol has input pins that are not placed.
Definition: erc_settings.h:60
@ ERCE_MISSING_UNIT
Symbol has units that are not placed on the schematic.
Definition: erc_settings.h:62
@ ERCE_DUPLICATE_SHEET_NAME
Duplicate sheet names within a given sheet.
Definition: erc_settings.h:40
@ ERCE_MISSING_BIDI_PIN
Symbol has bi-directional pins that are not placed.
Definition: erc_settings.h:61
@ ERCE_LIB_SYMBOL_ISSUES
Symbol not found in active libraries.
Definition: erc_settings.h:77
@ ERCE_FOOTPRINT_FILTERS
The assigned footprint doesn't match the footprint filters.
Definition: erc_settings.h:81
@ ERCE_BUS_ALIAS_CONFLICT
Conflicting bus alias definitions across sheets.
Definition: erc_settings.h:65
@ ERCE_GENERIC_WARNING
Definition: erc_settings.h:101
@ ERCE_LABEL_MULTIPLE_WIRES
A label is connected to more than one wire.
Definition: erc_settings.h:88
@ ERCE_PIN_TO_PIN_ERROR
Definition: erc_settings.h:98
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
Definition: erc_settings.h:107
@ KIFACE_TEST_FOOTPRINT_LINK_LIBRARY_NOT_ENABLED
Definition: kiface_ids.h:62
@ KIFACE_TEST_FOOTPRINT_LINK
Definition: kiface_ids.h:60
@ KIFACE_TEST_FOOTPRINT_LINK_NO_LIBRARY
Definition: kiface_ids.h:61
@ KIFACE_TEST_FOOTPRINT_LINK_NO_FOOTPRINT
Definition: kiface_ids.h:63
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:207
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
@ PT_OUTPUT
usual output
@ PT_TRISTATE
tris state bus pin
@ PT_BIDI
input or output (like port for a microprocessor)
@ PT_POWER_OUT
output of a regulator: intended to be connected to power input pins
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
LIB_SYMBOL * SchGetLibSymbol(const LIB_ID &aLibId, SYMBOL_LIB_TABLE *aLibTable, SYMBOL_LIB *aCacheLib, wxWindow *aParent, bool aShowErrorMsg)
Load symbol from symbol library table.
@ NO_CLEANUP
@ GLOBAL_CLEANUP
wxString UnescapeString(const wxString &aSource)
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151
virtual void * IfaceOrAddress(int aDataId)=0
Return pointer to the requested object.
@ SCH_LINE_T
Definition: typeinfo.h:163
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ SCH_FIELD_T
Definition: typeinfo.h:150
@ SCH_LABEL_T
Definition: typeinfo.h:167
@ SCH_LOCATE_ANY_T
Definition: typeinfo.h:198
@ SCH_SHEET_T
Definition: typeinfo.h:174
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:169
@ SCH_TEXT_T
Definition: typeinfo.h:151
@ SCH_TEXTBOX_T
Definition: typeinfo.h:152
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:168
@ SCH_PIN_T
Definition: typeinfo.h:153
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691