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