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.h>
34#include <erc_sch_pin_context.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_textbox.h>
48#include <sch_line.h>
49#include <schematic.h>
52#include <wx/ffile.h>
53#include <sim/sim_lib_mgr.h>
54#include <progress_reporter.h>
55#include <kiway.h>
56
57
58/* ERC tests :
59 * 1 - conflicts between connected pins ( example: 2 connected outputs )
60 * 2 - minimal connections requirements ( 1 input *must* be connected to an
61 * output, or a passive pin )
62 */
63
64/*
65 * Minimal ERC requirements:
66 * All pins *must* be connected (except ELECTRICAL_PINTYPE::PT_NC).
67 * When a pin is not connected in schematic, the user must place a "non
68 * connected" symbol to this pin.
69 * This ensures a forgotten connection will be detected.
70 */
71
72// Messages for matrix rows:
73const wxString CommentERC_H[] =
74{
75 _( "Input Pin" ),
76 _( "Output Pin" ),
77 _( "Bidirectional Pin" ),
78 _( "Tri-State Pin" ),
79 _( "Passive Pin" ),
80 _( "Free Pin" ),
81 _( "Unspecified Pin" ),
82 _( "Power Input Pin" ),
83 _( "Power Output Pin" ),
84 _( "Open Collector" ),
85 _( "Open Emitter" ),
86 _( "No Connection" )
87};
88
89// Messages for matrix columns
90const wxString CommentERC_V[] =
91{
92 _( "Input Pin" ),
93 _( "Output Pin" ),
94 _( "Bidirectional Pin" ),
95 _( "Tri-State Pin" ),
96 _( "Passive Pin" ),
97 _( "Free Pin" ),
98 _( "Unspecified Pin" ),
99 _( "Power Input Pin" ),
100 _( "Power Output Pin" ),
101 _( "Open Collector" ),
102 _( "Open Emitter" ),
103 _( "No Connection" )
104};
105
106
107// List of pin types that are considered drivers for usual input pins
108// i.e. pin type = ELECTRICAL_PINTYPE::PT_INPUT, but not PT_POWER_IN
109// that need only a PT_POWER_OUT pin type to be driven
110const std::set<ELECTRICAL_PINTYPE> DrivingPinTypes =
111 {
117 };
118
119// List of pin types that are considered drivers for power pins
120// In fact only a ELECTRICAL_PINTYPE::PT_POWER_OUT pin type can drive
121// power input pins
122const std::set<ELECTRICAL_PINTYPE> DrivingPowerPinTypes =
123 {
125 };
126
127// List of pin types that require a driver elsewhere on the net
128const std::set<ELECTRICAL_PINTYPE> DrivenPinTypes =
129 {
132 };
133
134int ERC_TESTER::TestDuplicateSheetNames( bool aCreateMarker )
135{
136 SCH_SCREEN* screen;
137 int err_count = 0;
138
139 SCH_SCREENS screenList( m_schematic->Root() );
140
141 for( screen = screenList.GetFirst(); screen != nullptr; screen = screenList.GetNext() )
142 {
143 std::vector<SCH_SHEET*> list;
144
145 for( SCH_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
146 list.push_back( static_cast<SCH_SHEET*>( item ) );
147
148 for( size_t i = 0; i < list.size(); i++ )
149 {
150 SCH_SHEET* sheet = list[i];
151
152 for( size_t j = i + 1; j < list.size(); j++ )
153 {
154 SCH_SHEET* test_item = list[j];
155
156 // We have found a second sheet: compare names
157 // we are using case insensitive comparison to avoid mistakes between
158 // similar names like Mysheet and mysheet
159 if( sheet->GetShownName( false ).CmpNoCase( test_item->GetShownName( false ) ) == 0 )
160 {
161 if( aCreateMarker )
162 {
163 std::shared_ptr<ERC_ITEM> ercItem =
165 ercItem->SetItems( sheet, test_item );
166
167 SCH_MARKER* marker = new SCH_MARKER( ercItem, sheet->GetPosition() );
168 screen->Append( marker );
169 }
170
171 err_count++;
172 }
173 }
174 }
175 }
176
177 return err_count;
178}
179
180
182{
183 DS_DRAW_ITEM_LIST wsItems( schIUScale );
184
185 auto unresolved = [this]( wxString str )
186 {
187 str = ExpandEnvVarSubstitutions( str, &m_schematic->Prj() );
188 return str.Matches( wxS( "*${*}*" ) );
189 };
190
191 if( aDrawingSheet )
192 {
193 wsItems.SetPageNumber( wxS( "1" ) );
194 wsItems.SetSheetCount( 1 );
195 wsItems.SetFileName( wxS( "dummyFilename" ) );
196 wsItems.SetSheetName( wxS( "dummySheet" ) );
197 wsItems.SetSheetLayer( wxS( "dummyLayer" ) );
198 wsItems.SetProject( &m_schematic->Prj() );
199 wsItems.BuildDrawItemsList( aDrawingSheet->GetPageInfo(), aDrawingSheet->GetTitleBlock() );
200 }
201
202 for( SCH_SHEET_PATH& sheet : m_schematic->GetSheets() )
203 {
204 SCH_SCREEN* screen = sheet.LastScreen();
205
206 for( SCH_ITEM* item : screen->Items().OfType( SCH_LOCATE_ANY_T ) )
207 {
208 if( item->Type() == SCH_SYMBOL_T )
209 {
210 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
211
212 for( SCH_FIELD& field : symbol->GetFields() )
213 {
214 if( unresolved( field.GetShownText( &sheet, true ) ) )
215 {
217 ercItem->SetItems( &field );
218 ercItem->SetSheetSpecificPath( sheet );
219
220 SCH_MARKER* marker = new SCH_MARKER( ercItem, field.GetPosition() );
221 screen->Append( marker );
222 }
223 }
224 }
225 else if( item->Type() == SCH_SHEET_T )
226 {
227 SCH_SHEET* subSheet = static_cast<SCH_SHEET*>( item );
228
229 for( SCH_FIELD& field : subSheet->GetFields() )
230 {
231 if( unresolved( field.GetShownText( &sheet, true ) ) )
232 {
234 ercItem->SetItems( &field );
235 ercItem->SetSheetSpecificPath( sheet );
236
237 SCH_MARKER* marker = new SCH_MARKER( ercItem, field.GetPosition() );
238 screen->Append( marker );
239 }
240 }
241
242 SCH_SHEET_PATH subSheetPath = sheet;
243 subSheetPath.push_back( subSheet );
244
245 for( SCH_SHEET_PIN* pin : subSheet->GetPins() )
246 {
247 if( pin->GetShownText( &subSheetPath, true ).Matches( wxS( "*${*}*" ) ) )
248 {
250 ercItem->SetItems( pin );
251 ercItem->SetSheetSpecificPath( sheet );
252
253 SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() );
254 screen->Append( marker );
255 }
256 }
257 }
258 else if( SCH_TEXT* text = dynamic_cast<SCH_TEXT*>( item ) )
259 {
260 if( text->GetShownText( &sheet, true ).Matches( wxS( "*${*}*" ) ) )
261 {
263 ercItem->SetItems( text );
264 ercItem->SetSheetSpecificPath( sheet );
265
266 SCH_MARKER* marker = new SCH_MARKER( ercItem, text->GetPosition() );
267 screen->Append( marker );
268 }
269 }
270 else if( SCH_TEXTBOX* textBox = dynamic_cast<SCH_TEXTBOX*>( item ) )
271 {
272 if( textBox->GetShownText( &sheet, true ).Matches( wxS( "*${*}*" ) ) )
273 {
275 ercItem->SetItems( textBox );
276 ercItem->SetSheetSpecificPath( sheet );
277
278 SCH_MARKER* marker = new SCH_MARKER( ercItem, textBox->GetPosition() );
279 screen->Append( marker );
280 }
281 }
282 }
283
284 for( DS_DRAW_ITEM_BASE* item = wsItems.GetFirst(); item; item = wsItems.GetNext() )
285 {
286 if( DS_DRAW_ITEM_TEXT* text = dynamic_cast<DS_DRAW_ITEM_TEXT*>( item ) )
287 {
288 if( text->GetShownText( true ).Matches( wxS( "*${*}*" ) ) )
289 {
290 std::shared_ptr<ERC_ITEM> erc = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
291 erc->SetErrorMessage( _( "Unresolved text variable in drawing sheet" ) );
292 erc->SetSheetSpecificPath( sheet );
293
294 SCH_MARKER* marker = new SCH_MARKER( erc, text->GetPosition() );
295 screen->Append( marker );
296 }
297 }
298 }
299 }
300}
301
302
304{
305 wxString msg;
306 int err_count = 0;
307
308 SCH_SCREENS screens( m_schematic->Root() );
309 std::vector< std::shared_ptr<BUS_ALIAS> > aliases;
310
311 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
312 {
313 const auto& screen_aliases = screen->GetBusAliases();
314
315 for( const std::shared_ptr<BUS_ALIAS>& alias : screen_aliases )
316 {
317 std::vector<wxString> aliasMembers = alias->Members();
318 std::sort( aliasMembers.begin(), aliasMembers.end() );
319
320 for( const std::shared_ptr<BUS_ALIAS>& test : aliases )
321 {
322 std::vector<wxString> testMembers = test->Members();
323 std::sort( testMembers.begin(), testMembers.end() );
324
325 if( alias->GetName() == test->GetName() && aliasMembers != testMembers )
326 {
327 msg.Printf( _( "Bus alias %s has conflicting definitions on %s and %s" ),
328 alias->GetName(),
329 alias->GetParent()->GetFileName(),
330 test->GetParent()->GetFileName() );
331
332 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ALIAS_CONFLICT );
333 ercItem->SetErrorMessage( msg );
334
335 SCH_MARKER* marker = new SCH_MARKER( ercItem, VECTOR2I() );
336 test->GetParent()->Append( marker );
337
338 ++err_count;
339 }
340 }
341 }
342
343 aliases.insert( aliases.end(), screen_aliases.begin(), screen_aliases.end() );
344 }
345
346 return err_count;
347}
348
349
351{
353
354 int errors = 0;
356 sheets.GetMultiUnitSymbols( refMap, true );
357
358 for( std::pair<const wxString, SCH_REFERENCE_LIST>& symbol : refMap )
359 {
360 SCH_REFERENCE_LIST& refList = symbol.second;
361
362 if( refList.GetCount() == 0 )
363 {
364 wxFAIL; // it should not happen
365 continue;
366 }
367
368 // Reference footprint
369 SCH_SYMBOL* unit = nullptr;
370 wxString unitName;
371 wxString unitFP;
372
373 for( unsigned i = 0; i < refList.GetCount(); ++i )
374 {
375 SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
376 unitFP = refList.GetItem( i ).GetFootprint();
377
378 if( !unitFP.IsEmpty() )
379 {
380 unit = refList.GetItem( i ).GetSymbol();
381 unitName = unit->GetRef( &sheetPath, true );
382 break;
383 }
384 }
385
386 for( unsigned i = 0; i < refList.GetCount(); ++i )
387 {
388 SCH_REFERENCE& secondRef = refList.GetItem( i );
389 SCH_SYMBOL* secondUnit = secondRef.GetSymbol();
390 wxString secondName = secondUnit->GetRef( &secondRef.GetSheetPath(), true );
391 const wxString secondFp = secondRef.GetFootprint();
392 wxString msg;
393
394 if( unit && !secondFp.IsEmpty() && unitFP != secondFp )
395 {
396 msg.Printf( _( "Different footprints assigned to %s and %s" ),
397 unitName, secondName );
398
399 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_FP );
400 ercItem->SetErrorMessage( msg );
401 ercItem->SetItems( unit, secondUnit );
402
403 SCH_MARKER* marker = new SCH_MARKER( ercItem, secondUnit->GetPosition() );
404 secondRef.GetSheetPath().LastScreen()->Append( marker );
405
406 ++errors;
407 }
408 }
409 }
410
411 return errors;
412}
413
414
416{
417 ERC_SETTINGS& settings = m_schematic->ErcSettings();
419
420 int errors = 0;
422 sheets.GetMultiUnitSymbols( refMap, true );
423
424 for( std::pair<const wxString, SCH_REFERENCE_LIST>& symbol : refMap )
425 {
426 SCH_REFERENCE_LIST& refList = symbol.second;
427
428 wxCHECK2( refList.GetCount(), continue );
429
430 // Reference unit
431 SCH_REFERENCE& base_ref = refList.GetItem( 0 );
432 SCH_SYMBOL* unit = base_ref.GetSymbol();
433 LIB_SYMBOL* libSymbol = base_ref.GetLibPart();
434
435 if( static_cast<ssize_t>( refList.GetCount() ) == libSymbol->GetUnitCount() )
436 continue;
437
438 std::set<int> lib_units;
439 std::set<int> instance_units;
440 std::set<int> missing_units;
441
442 auto report_missing = [&]( std::set<int>& aMissingUnits, wxString aErrorMsg,
443 int aErrorCode )
444 {
445 wxString msg;
446 wxString missing_pin_units = wxS( "[ " );
447 int ii = 0;
448
449 for( int missing_unit : aMissingUnits )
450 {
451 if( ii++ == 3 )
452 {
453 missing_pin_units += wxS( "....." );
454 break;
455 }
456
457 missing_pin_units += libSymbol->GetUnitDisplayName( missing_unit ) + ", " ;
458 }
459
460 missing_pin_units.Truncate( missing_pin_units.length() - 2 );
461 missing_pin_units += wxS( " ]" );
462
463 msg.Printf( aErrorMsg, symbol.first, missing_pin_units );
464
465 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( aErrorCode );
466 ercItem->SetErrorMessage( msg );
467 ercItem->SetItems( unit );
468
469 SCH_MARKER* marker = new SCH_MARKER( ercItem, unit->GetPosition() );
470 base_ref.GetSheetPath().LastScreen()->Append( marker );
471
472 ++errors;
473 };
474
475 for( int ii = 1; ii <= libSymbol->GetUnitCount(); ++ii )
476 lib_units.insert( lib_units.end(), ii );
477
478 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
479 instance_units.insert( instance_units.end(), refList.GetItem( ii ).GetUnit() );
480
481 std::set_difference( lib_units.begin(), lib_units.end(),
482 instance_units.begin(), instance_units.end(),
483 std::inserter( missing_units, missing_units.begin() ) );
484
485 if( !missing_units.empty() && settings.IsTestEnabled( ERCE_MISSING_UNIT ) )
486 {
487 report_missing( missing_units, _( "Symbol %s has unplaced units %s" ),
489 }
490
491 std::set<int> missing_power;
492 std::set<int> missing_input;
493 std::set<int> missing_bidi;
494
495 for( int missing_unit : missing_units )
496 {
497 int bodyStyle = 0;
498
499 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
500 {
501 if( refList.GetItem( ii ).GetUnit() == missing_unit )
502 {
503 bodyStyle = refList.GetItem( ii ).GetSymbol()->GetBodyStyle();
504 break;
505 }
506 }
507
508 for( SCH_PIN* pin : libSymbol->GetPins( missing_unit, bodyStyle ) )
509 {
510 switch( pin->GetType() )
511 {
512 case ELECTRICAL_PINTYPE::PT_POWER_IN:
513 missing_power.insert( missing_unit );
514 break;
515
516 case ELECTRICAL_PINTYPE::PT_BIDI:
517 missing_bidi.insert( missing_unit );
518 break;
519
520 case ELECTRICAL_PINTYPE::PT_INPUT:
521 missing_input.insert( missing_unit );
522 break;
523
524 default:
525 break;
526 }
527 }
528 }
529
530 if( !missing_power.empty() && settings.IsTestEnabled( ERCE_MISSING_POWER_INPUT_PIN ) )
531 {
532 report_missing( missing_power,
533 _( "Symbol %s has input power pins in units %s that are not placed." ),
535 }
536
537 if( !missing_input.empty() && settings.IsTestEnabled( ERCE_MISSING_INPUT_PIN ) )
538 {
539 report_missing( missing_input,
540 _( "Symbol %s has input pins in units %s that are not placed." ),
542 }
543
544 if( !missing_bidi.empty() && settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
545 {
546 report_missing( missing_bidi,
547 _( "Symbol %s has bidirectional pins in units %s that are not "
548 "placed." ),
550 }
551 }
552
553 return errors;
554}
555
556
558{
559 int err_count = 0;
560 std::shared_ptr<NET_SETTINGS>& settings = m_schematic->Prj().GetProjectFile().NetSettings();
561 wxString defaultNetclass = settings->m_DefaultNetClass->GetName();
562
563 auto logError =
564 [&]( const SCH_SHEET_PATH& sheet, SCH_ITEM* item, const wxString& netclass )
565 {
566 err_count++;
567
568 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNDEFINED_NETCLASS );
569
570 ercItem->SetItems( item );
571 ercItem->SetErrorMessage( wxString::Format( _( "Netclass %s is not defined" ),
572 netclass ) );
573
574 SCH_MARKER* marker = new SCH_MARKER( ercItem, item->GetPosition() );
575 sheet.LastScreen()->Append( marker );
576 };
577
578 for( const SCH_SHEET_PATH& sheet : m_schematic->GetSheets() )
579 {
580 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
581 {
582 item->RunOnChildren(
583 [&]( SCH_ITEM* aChild )
584 {
585 if( aChild->Type() == SCH_FIELD_T )
586 {
587 SCH_FIELD* field = static_cast<SCH_FIELD*>( aChild );
588
589 if( field->GetCanonicalName() == wxT( "Netclass" ) )
590 {
591 wxString netclass = field->GetText();
592
593 if( !netclass.IsSameAs( defaultNetclass )
594 && settings->m_NetClasses.count( netclass ) == 0 )
595 {
596 logError( sheet, item, netclass );
597 }
598 }
599 }
600
601 return true;
602 } );
603 }
604 }
605
606 return err_count;
607}
608
609
611{
612 int err_count = 0;
613
614 for( const SCH_SHEET_PATH& sheet : m_schematic->GetSheets() )
615 {
616 std::map<VECTOR2I, std::vector<SCH_ITEM*>> pinMap;
617
618 auto addOther =
619 [&]( const VECTOR2I& pt, SCH_ITEM* aOther )
620 {
621 if( pinMap.count( pt ) )
622 pinMap[pt].emplace_back( aOther );
623 };
624
625 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
626 {
627 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
628
629 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
630 {
631 if( pin->GetLibPin()->GetType() == ELECTRICAL_PINTYPE::PT_NC )
632 pinMap[pin->GetPosition()].emplace_back( pin );
633 }
634 }
635
636 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
637 {
638 if( item->Type() == SCH_SYMBOL_T )
639 {
640 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
641
642 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
643 {
644 if( pin->GetLibPin()->GetType() != ELECTRICAL_PINTYPE::PT_NC )
645 addOther( pin->GetPosition(), pin );
646 }
647 }
648 else if( item->IsConnectable() )
649 {
650 for( const VECTOR2I& pt : item->GetConnectionPoints() )
651 addOther( pt, item );
652 }
653 }
654
655 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : pinMap )
656 {
657 if( pair.second.size() > 1 )
658 {
659 err_count++;
660
661 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED );
662
663 ercItem->SetItems( pair.second[0], pair.second[1],
664 pair.second.size() > 2 ? pair.second[2] : nullptr,
665 pair.second.size() > 3 ? pair.second[3] : nullptr );
666 ercItem->SetErrorMessage( _( "Pin with 'no connection' type is connected" ) );
667 ercItem->SetSheetSpecificPath( sheet );
668
669 SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
670 sheet.LastScreen()->Append( marker );
671 }
672 }
673 }
674
675 return err_count;
676}
677
678
680{
681 ERC_SETTINGS& settings = m_schematic->ErcSettings();
682 const NET_MAP& nets = m_schematic->ConnectionGraph()->GetNetMap();
683
684 int errors = 0;
685
686 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : nets )
687 {
688 std::vector<ERC_SCH_PIN_CONTEXT> pins;
689 std::unordered_map<EDA_ITEM*, SCH_SCREEN*> pinToScreenMap;
690 bool has_noconnect = false;
691
692 for( CONNECTION_SUBGRAPH* subgraph: net.second )
693 {
694 if( subgraph->GetNoConnect() )
695 has_noconnect = true;
696
697 for( SCH_ITEM* item : subgraph->GetItems() )
698 {
699 if( item->Type() == SCH_PIN_T )
700 {
701 pins.emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
702 pinToScreenMap[item] = subgraph->GetSheet().LastScreen();
703 }
704 }
705 }
706
707 ERC_SCH_PIN_CONTEXT needsDriver;
708 bool hasDriver = false;
709
710 // We need different drivers for power nets and normal nets.
711 // A power net has at least one pin having the ELECTRICAL_PINTYPE::PT_POWER_IN
712 // and power nets can be driven only by ELECTRICAL_PINTYPE::PT_POWER_OUT pins
713 bool ispowerNet = false;
714
715 for( ERC_SCH_PIN_CONTEXT& refPin : pins )
716 {
717 if( refPin.Pin()->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
718 {
719 ispowerNet = true;
720 break;
721 }
722 }
723
724 for( auto refIt = pins.begin(); refIt != pins.end(); ++refIt )
725 {
726 ERC_SCH_PIN_CONTEXT& refPin = *refIt;
727 ELECTRICAL_PINTYPE refType = refPin.Pin()->GetType();
728
729 if( DrivenPinTypes.contains( refType ) )
730 {
731 // needsDriver will be the pin shown in the error report eventually, so try to
732 // upgrade to a "better" pin if possible: something visible and only a power symbol
733 // if this net needs a power driver
734 if( !needsDriver.Pin()
735 || ( !needsDriver.Pin()->IsVisible() && refPin.Pin()->IsVisible() )
736 || ( ispowerNet
737 != ( needsDriver.Pin()->GetType()
738 == ELECTRICAL_PINTYPE::PT_POWER_IN )
739 && ispowerNet == ( refType == ELECTRICAL_PINTYPE::PT_POWER_IN ) ) )
740 {
741 needsDriver = refPin;
742 }
743 }
744
745 if( ispowerNet )
746 hasDriver |= ( DrivingPowerPinTypes.count( refType ) != 0 );
747 else
748 hasDriver |= ( DrivingPinTypes.count( refType ) != 0 );
749
750 for( auto testIt = refIt + 1; testIt != pins.end(); ++testIt )
751 {
752 ERC_SCH_PIN_CONTEXT& testPin = *testIt;
753
754 // Multiple pins in the same symbol that share a type,
755 // name and position are considered
756 // "stacked" and shouldn't trigger ERC errors
757 if( refPin.Pin()->IsStacked( testPin.Pin() ) && refPin.Sheet() == testPin.Sheet() )
758 continue;
759
760 ELECTRICAL_PINTYPE testType = testPin.Pin()->GetType();
761
762 if( ispowerNet )
763 hasDriver |= DrivingPowerPinTypes.contains( testType );
764 else
765 hasDriver |= DrivingPinTypes.contains( testType );
766
767 PIN_ERROR erc = settings.GetPinMapValue( refType, testType );
768
769 if( erc != PIN_ERROR::OK && settings.IsTestEnabled( ERCE_PIN_TO_PIN_WARNING ) )
770 {
771 std::shared_ptr<ERC_ITEM> ercItem =
772 ERC_ITEM::Create( erc == PIN_ERROR::WARNING ? ERCE_PIN_TO_PIN_WARNING :
774 ercItem->SetItems( refPin.Pin(), testPin.Pin() );
775 ercItem->SetSheetSpecificPath( refPin.Sheet() );
776 ercItem->SetItemsSheetPaths( refPin.Sheet(), testPin.Sheet() );
777
778 ercItem->SetErrorMessage(
779 wxString::Format( _( "Pins of type %s and %s are connected" ),
780 ElectricalPinTypeGetText( refType ),
781 ElectricalPinTypeGetText( testType ) ) );
782
783 SCH_MARKER* marker = new SCH_MARKER( ercItem, refPin.Pin()->GetPosition() );
784 pinToScreenMap[refPin.Pin()]->Append( marker );
785 errors++;
786 }
787 }
788 }
789
790 if( needsDriver.Pin() && !hasDriver && !has_noconnect )
791 {
792 int err_code = ispowerNet ? ERCE_POWERPIN_NOT_DRIVEN : ERCE_PIN_NOT_DRIVEN;
793
794 if( settings.IsTestEnabled( err_code ) )
795 {
796 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( err_code );
797
798 ercItem->SetItems( needsDriver.Pin() );
799 ercItem->SetSheetSpecificPath( needsDriver.Sheet() );
800 ercItem->SetItemsSheetPaths( needsDriver.Sheet() );
801
802 SCH_MARKER* marker = new SCH_MARKER( ercItem, needsDriver.Pin()->GetPosition() );
803 pinToScreenMap[needsDriver.Pin()]->Append( marker );
804 errors++;
805 }
806 }
807 }
808
809 return errors;
810}
811
812
814{
815 const NET_MAP& nets = m_schematic->ConnectionGraph()->GetNetMap();
816
817 int errors = 0;
818
819 std::unordered_map<wxString, std::pair<wxString, SCH_PIN*>> pinToNetMap;
820
821 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : nets )
822 {
823 const wxString& netName = net.first.Name;
824
825 for( CONNECTION_SUBGRAPH* subgraph : net.second )
826 {
827 for( SCH_ITEM* item : subgraph->GetItems() )
828 {
829 if( item->Type() == SCH_PIN_T )
830 {
831 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
832 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
833
834 if( !pin->GetLibPin()->GetParentSymbol()->IsMulti() )
835 continue;
836
837 wxString name = pin->GetParentSymbol()->GetRef( &sheet ) +
838 + ":" + pin->GetShownNumber();
839
840 if( !pinToNetMap.count( name ) )
841 {
842 pinToNetMap[name] = std::make_pair( netName, pin );
843 }
844 else if( pinToNetMap[name].first != netName )
845 {
846 std::shared_ptr<ERC_ITEM> ercItem =
848
849 ercItem->SetErrorMessage( wxString::Format(
850 _( "Pin %s is connected to both %s and %s" ),
851 pin->GetShownNumber(),
852 netName,
853 pinToNetMap[name].first ) );
854
855 ercItem->SetItems( pin, pinToNetMap[name].second );
856 ercItem->SetSheetSpecificPath( sheet );
857 ercItem->SetItemsSheetPaths( sheet, sheet );
858
859 SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() );
860 sheet.LastScreen()->Append( marker );
861 errors += 1;
862 }
863 }
864 }
865 }
866 }
867
868 return errors;
869}
870
871
873{
874 const NET_MAP& nets = m_schematic->ConnectionGraph()->GetNetMap();
875
876 int errors = 0;
877
878 std::unordered_map<wxString, std::pair<SCH_LABEL_BASE*, SCH_SHEET_PATH>> labelMap;
879
880 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : nets )
881 {
882 for( CONNECTION_SUBGRAPH* subgraph : net.second )
883 {
884 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
885
886 for( SCH_ITEM* item : subgraph->GetItems() )
887 {
888 switch( item->Type() )
889 {
890 case SCH_LABEL_T:
891 case SCH_HIER_LABEL_T:
893 {
894 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
895
896 wxString normalized = label->GetShownText( &sheet, false ).Lower();
897
898 if( !labelMap.count( normalized ) )
899 {
900 labelMap[normalized] = std::make_pair( label, sheet );
901 break;
902 }
903
904 auto& [ otherLabel, otherSheet ] = labelMap.at( normalized );
905
906 if( otherLabel->GetShownText( &otherSheet, false )
907 != label->GetShownText( &sheet, false ) )
908 {
909 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMILAR_LABELS );
910 ercItem->SetItems( label, labelMap.at( normalized ).first );
911 ercItem->SetSheetSpecificPath( sheet );
912 ercItem->SetItemsSheetPaths( sheet, labelMap.at( normalized ).second );
913
914 SCH_MARKER* marker = new SCH_MARKER( ercItem, label->GetPosition() );
915 sheet.LastScreen()->Append( marker );
916 errors += 1;
917 }
918
919 break;
920 }
921
922 default:
923 break;
924 }
925 }
926 }
927 }
928
929 return errors;
930}
931
932
934{
935 wxCHECK( m_schematic, 0 );
936
937 ERC_SETTINGS& settings = m_schematic->ErcSettings();
939 wxString msg;
940 int err_count = 0;
941
942 SCH_SCREENS screens( m_schematic->Root() );
943
944 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
945 {
946 std::vector<SCH_MARKER*> markers;
947
948 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
949 {
950 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
951 LIB_SYMBOL* libSymbolInSchematic = symbol->GetLibSymbolRef().get();
952
953 wxCHECK2( libSymbolInSchematic, continue );
954
955 wxString libName = symbol->GetLibId().GetLibNickname();
956 LIB_TABLE_ROW* libTableRow = libTable->FindRow( libName, true );
957
958 if( !libTableRow )
959 {
960 if( settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
961 {
962 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
963 ercItem->SetItems( symbol );
964 msg.Printf( _( "The current configuration does not include the symbol library '%s'" ),
965 UnescapeString( libName ) );
966 ercItem->SetErrorMessage( msg );
967
968 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
969 }
970
971 continue;
972 }
973 else if( !libTable->HasLibrary( libName, true ) )
974 {
975 if( settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
976 {
977 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
978 ercItem->SetItems( symbol );
979 msg.Printf( _( "The library '%s' is not enabled in the current configuration" ),
980 UnescapeString( libName ) );
981 ercItem->SetErrorMessage( msg );
982
983 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
984 }
985
986 continue;
987 }
988
989 wxString symbolName = symbol->GetLibId().GetLibItemName();
990 LIB_SYMBOL* libSymbol = SchGetLibSymbol( symbol->GetLibId(), libTable );
991
992 if( libSymbol == nullptr )
993 {
994 if( settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
995 {
996 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
997 ercItem->SetItems( symbol );
998 msg.Printf( _( "Symbol '%s' not found in symbol library '%s'" ),
999 UnescapeString( symbolName ),
1000 UnescapeString( libName ) );
1001 ercItem->SetErrorMessage( msg );
1002
1003 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1004 }
1005
1006 continue;
1007 }
1008
1009 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->Flatten();
1011
1013 && flattenedSymbol->Compare( *libSymbolInSchematic, flags ) != 0 )
1014 {
1015 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_MISMATCH );
1016 ercItem->SetItems( symbol );
1017 msg.Printf( _( "Symbol '%s' doesn't match copy in library '%s'" ),
1018 UnescapeString( symbolName ),
1019 UnescapeString( libName ) );
1020 ercItem->SetErrorMessage( msg );
1021
1022 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1023 }
1024 }
1025
1026 for( SCH_MARKER* marker : markers )
1027 {
1028 screen->Append( marker );
1029 err_count += 1;
1030 }
1031 }
1032
1033 return err_count;
1034}
1035
1036
1038{
1039 wxCHECK( m_schematic, 0 );
1040
1041 wxString msg;
1042 int err_count = 0;
1043
1044 typedef int (*TESTER_FN_PTR)( const wxString&, PROJECT* );
1045
1046 TESTER_FN_PTR linkTester = (TESTER_FN_PTR) aCvPcb->IfaceOrAddress( KIFACE_TEST_FOOTPRINT_LINK );
1047
1048 for( SCH_SHEET_PATH& sheet : m_schematic->GetSheets() )
1049 {
1050 std::vector<SCH_MARKER*> markers;
1051
1052 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1053 {
1054 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1055 wxString footprint = symbol->GetFootprintFieldText( true, &sheet, false );
1056
1057 if( footprint.IsEmpty() )
1058 continue;
1059
1060 LIB_ID fpID;
1061
1062 if( fpID.Parse( footprint, true ) >= 0 )
1063 {
1064 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1065 msg.Printf( _( "'%s' is not a valid footprint identifier." ), footprint );
1066 ercItem->SetErrorMessage( msg );
1067 ercItem->SetItems( symbol );
1068 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1069 continue;
1070 }
1071
1072 wxString libName = fpID.GetLibNickname();
1073 wxString fpName = fpID.GetLibItemName();
1074 int ret = (linkTester)( footprint, aProject );
1075
1077 {
1078 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1079 msg.Printf( _( "The current configuration does not include the footprint library '%s'." ),
1080 libName );
1081 ercItem->SetErrorMessage( msg );
1082 ercItem->SetItems( symbol );
1083 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1084 }
1086 {
1087 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1088 msg.Printf( _( "The footprint library '%s' is not enabled in the current configuration." ),
1089 libName );
1090 ercItem->SetErrorMessage( msg );
1091 ercItem->SetItems( symbol );
1092 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1093 }
1095 {
1096 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1097 msg.Printf( _( "Footprint '%s' not found in library '%s'." ),
1098 fpName,
1099 libName );
1100 ercItem->SetErrorMessage( msg );
1101 ercItem->SetItems( symbol );
1102 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1103 }
1104 }
1105
1106 for( SCH_MARKER* marker : markers )
1107 {
1108 sheet.LastScreen()->Append( marker );
1109 err_count += 1;
1110 }
1111 }
1112
1113 return err_count;
1114}
1115
1116
1118{
1119 const int gridSize = m_schematic->Settings().m_ConnectionGridSize;
1120
1121 SCH_SCREENS screens( m_schematic->Root() );
1122 int err_count = 0;
1123
1124 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
1125 {
1126 std::vector<SCH_MARKER*> markers;
1127
1128 for( SCH_ITEM* item : screen->Items() )
1129 {
1130 if( item->Type() == SCH_LINE_T && item->IsConnectable() )
1131 {
1132 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1133
1134 if( ( line->GetStartPoint().x % gridSize ) != 0
1135 || ( line->GetStartPoint().y % gridSize ) != 0 )
1136 {
1137 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1138 ercItem->SetItems( line );
1139
1140 markers.emplace_back( new SCH_MARKER( ercItem, line->GetStartPoint() ) );
1141 }
1142 else if( ( line->GetEndPoint().x % gridSize ) != 0
1143 || ( line->GetEndPoint().y % gridSize ) != 0 )
1144 {
1145 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1146 ercItem->SetItems( line );
1147
1148 markers.emplace_back( new SCH_MARKER( ercItem, line->GetEndPoint() ) );
1149 }
1150 }
1151 else if( item->Type() == SCH_SYMBOL_T )
1152 {
1153 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1154
1155 for( SCH_PIN* pin : symbol->GetPins( nullptr ) )
1156 {
1157 VECTOR2I pinPos = pin->GetPosition();
1158
1159 if( ( pinPos.x % gridSize ) != 0 || ( pinPos.y % gridSize ) != 0 )
1160 {
1161 auto ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1162 ercItem->SetItems( pin );
1163
1164 markers.emplace_back( new SCH_MARKER( ercItem, pinPos ) );
1165 break;
1166 }
1167 }
1168 }
1169 }
1170
1171 for( SCH_MARKER* marker : markers )
1172 {
1173 screen->Append( marker );
1174 err_count += 1;
1175 }
1176 }
1177
1178 return err_count;
1179}
1180
1181
1183{
1184 wxString msg;
1185 WX_STRING_REPORTER reporter( &msg );
1187 int err_count = 0;
1188 SIM_LIB_MGR libMgr( &m_schematic->Prj() );
1189
1190 for( SCH_SHEET_PATH& sheet : sheets )
1191 {
1192 std::vector<SCH_MARKER*> markers;
1193
1194 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1195 {
1196 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1197
1198 // Power symbols and other symbols which have the reference starting with "#" are
1199 // not included in simulation
1200 if( symbol->GetRef( &sheet ).StartsWith( '#' ) || symbol->GetExcludedFromSim() )
1201 continue;
1202
1203 // Reset for each symbol
1204 msg.Clear();
1205
1206 SIM_LIBRARY::MODEL model = libMgr.CreateModel( &sheet, *symbol, reporter );
1207
1208 if( !msg.IsEmpty() )
1209 {
1210 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMULATION_MODEL );
1211
1212 //Remove \n and \r at e.o.l if any:
1213 msg.Trim();
1214
1215 ercItem->SetErrorMessage( msg );
1216 ercItem->SetItems( symbol );
1217
1218 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1219 }
1220 }
1221
1222 for( SCH_MARKER* marker : markers )
1223 {
1224 sheet.LastScreen()->Append( marker );
1225 err_count += 1;
1226 }
1227 }
1228
1229 return err_count;
1230}
1231
1232
1234{
1235 int numErrors = 0;
1236 ERC_SETTINGS& settings = m_schematic->ErcSettings();
1237
1239 return 0;
1240
1241 std::map<SCH_SCREEN*, std::vector<SCH_RULE_AREA*>> allScreenRuleAreas;
1242
1243 SCH_SCREENS screens( m_schematic->Root() );
1244
1245 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
1246 {
1247 for( SCH_ITEM* item : screen->Items().OfType( SCH_RULE_AREA_T ) )
1248 {
1249 allScreenRuleAreas[screen].push_back( static_cast<SCH_RULE_AREA*>( item ) );
1250 }
1251 }
1252
1254 numErrors += TestRuleAreaOverlappingRuleAreasERC( allScreenRuleAreas );
1255
1256 return numErrors;
1257}
1258
1259
1261 std::map<SCH_SCREEN*, std::vector<SCH_RULE_AREA*>>& allScreenRuleAreas )
1262{
1263 int numErrors = 0;
1264
1265 for( auto screenRuleAreas : allScreenRuleAreas )
1266 {
1267 std::vector<SCH_RULE_AREA*>& ruleAreas = screenRuleAreas.second;
1268
1269 for( std::size_t i = 0; i < ruleAreas.size(); ++i )
1270 {
1271 SHAPE_POLY_SET& polyFirst = ruleAreas[i]->GetPolyShape();
1272
1273 for( std::size_t j = i + 1; j < ruleAreas.size(); ++j )
1274 {
1275 SHAPE_POLY_SET polySecond = ruleAreas[j]->GetPolyShape();
1276 if( polyFirst.Collide( &polySecond ) )
1277 {
1278 numErrors++;
1279
1280 SCH_SCREEN* screen = screenRuleAreas.first;
1281 SCH_SHEET_PATH firstSheet = screen->GetClientSheetPaths()[0];
1282
1283 std::shared_ptr<ERC_ITEM> ercItem =
1285 ercItem->SetItems( ruleAreas[i], ruleAreas[j] );
1286 ercItem->SetSheetSpecificPath( firstSheet );
1287 ercItem->SetItemsSheetPaths( firstSheet, firstSheet );
1288
1289 SCH_MARKER* marker = new SCH_MARKER( ercItem, ruleAreas[i]->GetPosition() );
1290 screen->Append( marker );
1291 }
1292 }
1293 }
1294 }
1295
1296 return numErrors;
1297}
1298
1299
1301 KIFACE* aCvPcb, PROJECT* aProject, PROGRESS_REPORTER* aProgressReporter )
1302{
1303 ERC_SETTINGS& settings = m_schematic->ErcSettings();
1304
1305 // Test duplicate sheet names inside a given sheet. While one can have multiple references
1306 // to the same file, each must have a unique name.
1308 {
1309 if( aProgressReporter )
1310 aProgressReporter->AdvancePhase( _( "Checking sheet names..." ) );
1311
1313 }
1314
1315 if( settings.IsTestEnabled( ERCE_BUS_ALIAS_CONFLICT ) )
1316 {
1317 if( aProgressReporter )
1318 aProgressReporter->AdvancePhase( _( "Checking bus conflicts..." ) );
1319
1321 }
1322
1323 // The connection graph has a whole set of ERC checks it can run
1324 if( aProgressReporter )
1325 aProgressReporter->AdvancePhase( _( "Checking conflicts..." ) );
1326
1327 // If we are using the new connectivity, make sure that we do a full-rebuild
1328 if( aEditFrame )
1329 {
1330 if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
1331 aEditFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
1332 else
1333 aEditFrame->RecalculateConnections( nullptr, NO_CLEANUP );
1334 }
1335
1337
1338 if( aProgressReporter )
1339 aProgressReporter->AdvancePhase( _( "Checking rule areas..." ) );
1340
1342 {
1344 }
1345
1346 if( aProgressReporter )
1347 aProgressReporter->AdvancePhase( _( "Checking units..." ) );
1348
1349 // Test is all units of each multiunit symbol have the same footprint assigned.
1350 if( settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_FP ) )
1351 {
1352 if( aProgressReporter )
1353 aProgressReporter->AdvancePhase( _( "Checking footprints..." ) );
1354
1356 }
1357
1358 if( settings.IsTestEnabled( ERCE_MISSING_UNIT )
1361 || settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
1362 {
1364 }
1365
1366 if( aProgressReporter )
1367 aProgressReporter->AdvancePhase( _( "Checking pins..." ) );
1368
1369 if( settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_NET ) )
1371
1372 // Test pins on each net against the pin connection table
1373 if( settings.IsTestEnabled( ERCE_PIN_TO_PIN_ERROR )
1375 || settings.IsTestEnabled( ERCE_PIN_NOT_DRIVEN ) )
1376 {
1377 TestPinToPin();
1378 }
1379
1380 // Test similar labels (i;e. labels which are identical when
1381 // using case insensitive comparisons)
1382 if( settings.IsTestEnabled( ERCE_SIMILAR_LABELS ) )
1383 {
1384 if( aProgressReporter )
1385 aProgressReporter->AdvancePhase( _( "Checking labels..." ) );
1386
1388 }
1389
1390 if( settings.IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) )
1391 {
1392 if( aProgressReporter )
1393 aProgressReporter->AdvancePhase( _( "Checking for unresolved variables..." ) );
1394
1395 TestTextVars( aDrawingSheet );
1396 }
1397
1398 if( settings.IsTestEnabled( ERCE_SIMULATION_MODEL ) )
1399 {
1400 if( aProgressReporter )
1401 aProgressReporter->AdvancePhase( _( "Checking SPICE models..." ) );
1402
1404 }
1405
1406 if( settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED ) )
1407 {
1408 if( aProgressReporter )
1409 aProgressReporter->AdvancePhase( _( "Checking no connect pins for connections..." ) );
1410
1412 }
1413
1416 {
1417 if( aProgressReporter )
1418 aProgressReporter->AdvancePhase( _( "Checking for library symbol issues..." ) );
1419
1421 }
1422
1423 if( settings.IsTestEnabled( ERCE_FOOTPRINT_LINK_ISSUES ) && aCvPcb )
1424 {
1425 if( aProgressReporter )
1426 aProgressReporter->AdvancePhase( _( "Checking for footprint link issues..." ) );
1427
1428 TestFootprintLinkIssues( aCvPcb, aProject );
1429 }
1430
1431 if( settings.IsTestEnabled( ERCE_ENDPOINT_OFF_GRID ) )
1432 {
1433 if( aProgressReporter )
1434 aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) );
1435
1437 }
1438
1439 if( settings.IsTestEnabled( ERCE_UNDEFINED_NETCLASS ) )
1440 {
1441 if( aProgressReporter )
1442 aProgressReporter->AdvancePhase( _( "Checking for undefined netclasses..." ) );
1443
1445 }
1446
1448}
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.
const NET_MAP & GetNetMap() const
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
DS_DRAW_ITEM_BASE * GetFirst()
Definition: ds_draw_item.h:511
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:444
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
Definition: ds_draw_item.h:449
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
Definition: ds_draw_item.h:459
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
Definition: ds_draw_item.h:498
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
Definition: ds_draw_item.h:488
DS_DRAW_ITEM_BASE * GetNext()
Definition: ds_draw_item.h:521
void SetProject(const PROJECT *aProject)
Definition: ds_draw_item.h:424
A graphic text.
Definition: ds_draw_item.h:313
const PAGE_INFO & GetPageInfo()
const TITLE_BLOCK & GetTitleBlock()
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
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:252
A class used to associate a SCH_PIN with its owning SCH_SHEET_PATH, in order to handle ERC checks acr...
SCH_PIN * Pin()
Get the SCH_PIN for this context.
SCH_SHEET_PATH & Sheet()
Get the SCH_SHEET_PATH context for the paired SCH_PIN.
Container for ERC settings.
Definition: erc_settings.h:120
bool IsTestEnabled(int aErrorCode) const
Definition: erc_settings.h:136
PIN_ERROR GetPinMapValue(int aFirstType, int aSecondType) const
Definition: erc_settings.h:147
int TestLibSymbolIssues()
Test symbols for changed library symbols and broken symbol library links.
Definition: erc.cpp:933
void TestTextVars(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Check for any unresolved text variable references.
Definition: erc.cpp:181
int TestPinToPin()
Checks the full netlist against the pin-to-pin connectivity requirements.
Definition: erc.cpp:679
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition: erc.cpp:872
int RunRuleAreaERC()
Tests for rule area ERC issues.
Definition: erc.cpp:1233
int TestFootprintLinkIssues(KIFACE *aCvPcb, PROJECT *aProject)
Test footprint links against the current footprint libraries.
Definition: erc.cpp:1037
int TestOffGridEndpoints()
Test pins and wire ends for being off grid.
Definition: erc.cpp:1117
int TestDuplicateSheetNames(bool aCreateMarker)
Inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated).
Definition: erc.cpp:134
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition: erc.cpp:813
int TestConflictingBusAliases()
Check that there are no conflicting bus alias definitions in the schematic.
Definition: erc.cpp:303
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
Definition: erc.cpp:610
int TestRuleAreaOverlappingRuleAreasERC(std::map< SCH_SCREEN *, std::vector< SCH_RULE_AREA * > > &allScreenRuleAreas)
Runs ERC to check for overlapping rule areas.
Definition: erc.cpp:1260
int TestMissingNetclasses()
Tests for netclasses that are referenced but not defined.
Definition: erc.cpp:557
int TestSimModelIssues()
Test SPICE models for various issues.
Definition: erc.cpp:1182
SCHEMATIC * m_schematic
Definition: erc.h:164
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition: erc.cpp:1300
int TestMissingUnits()
Test for uninstantiated units of multi unit symbols.
Definition: erc.cpp:415
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition: erc.cpp:350
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 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:77
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:982
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
Definition: lib_symbol.cpp:535
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:579
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:101
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
Container for project specific data.
Definition: project.h:62
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:166
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
Definition: schematic.cpp:823
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:287
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:146
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:100
SCH_SHEET & Root() const
Definition: schematic.h:105
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:90
ERC_SETTINGS & ErcSettings() const
Definition: schematic.cpp:294
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:174
int GetBodyStyle() const
Definition: sch_item.h:240
@ EQUALITY
Definition: sch_item.h:668
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const override
Definition: sch_label.cpp:892
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
VECTOR2I GetEndPoint() const
Definition: sch_line.h:140
VECTOR2I GetStartPoint() const
Definition: sch_line.h:135
bool IsVisible() const
Definition: sch_pin.cpp:338
VECTOR2I GetPosition() const override
Definition: sch_pin.cpp:235
bool IsStacked(const SCH_PIN *aPin) const
Definition: sch_pin.cpp:372
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:289
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
size_t GetCount() const
SCH_REFERENCE & GetItem(int aIdx)
A helper to define a symbol's reference designator in a schematic.
const SCH_SHEET_PATH & GetSheetPath() const
const wxString GetFootprint() const
SCH_SYMBOL * GetSymbol() const
LIB_SYMBOL * GetLibPart() const
int GetUnit() const
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:704
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:150
std::vector< SCH_SHEET_PATH > & GetClientSheetPaths()
Return the number of times this screen is used.
Definition: sch_screen.h:178
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:109
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void GetMultiUnitSymbols(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true) const
Add a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the li...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.
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:376
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:108
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:894
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:782
const LIB_ID & GetLibId() const override
Definition: sch_symbol.h:197
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:958
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:216
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:711
VECTOR2I GetPosition() const override
Definition: sch_text.h:141
Represent a set of closed polygons.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
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
A wrapper for reporting to a wxString object.
Definition: reporter.h:164
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:334
The common library.
std::unordered_map< NET_NAME_CODE_CACHE_KEY, std::vector< CONNECTION_SUBGRAPH * > > NET_MAP
Associate a #NET_CODE_NAME with all the subgraphs in that net.
#define _(s)
const wxString CommentERC_V[]
Definition: erc.cpp:90
const wxString CommentERC_H[]
Definition: erc.cpp:73
const std::set< ELECTRICAL_PINTYPE > DrivenPinTypes
Definition: erc.cpp:128
const std::set< ELECTRICAL_PINTYPE > DrivingPinTypes
Definition: erc.cpp:110
const std::set< ELECTRICAL_PINTYPE > DrivingPowerPinTypes
Definition: erc.cpp:122
@ 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_OVERLAPPING_RULE_AREAS
Rule areas are overlapping.
Definition: erc_settings.h:70
@ ERCE_MISSING_POWER_INPUT_PIN
Symbol has power input pins that are not placed on the schematic.
Definition: erc_settings.h:55
@ 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_FOOTPRINT_LINK_ISSUES
The footprint link is invalid, or points to a missing (or inactive) footprint or library.
Definition: erc_settings.h:78
@ ERCE_DIFFERENT_UNIT_NET
Shared pin in a multi-unit symbol is connected to more than one net.
Definition: erc_settings.h:60
@ ERCE_UNDEFINED_NETCLASS
A netclass was referenced but not defined.
Definition: erc_settings.h:73
@ ERCE_UNRESOLVED_VARIABLE
A text variable could not be resolved.
Definition: erc_settings.h:72
@ ERCE_SIMULATION_MODEL
An error was found in the simulation model.
Definition: erc_settings.h:74
@ ERCE_LIB_SYMBOL_MISMATCH
Symbol doesn't match copy in library.
Definition: erc_settings.h:77
@ ERCE_DIFFERENT_UNIT_FP
Different units of the same symbol have different footprints assigned.
Definition: erc_settings.h:53
@ 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:91
@ 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:57
@ ERCE_MISSING_UNIT
Symbol has units that are not placed on the schematic.
Definition: erc_settings.h:59
@ 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:58
@ ERCE_LIB_SYMBOL_ISSUES
Symbol not found in active libraries.
Definition: erc_settings.h:76
@ ERCE_BUS_ALIAS_CONFLICT
Conflicting bus alias definitions across sheets.
Definition: erc_settings.h:62
@ ERCE_PIN_TO_PIN_ERROR
Definition: erc_settings.h:92
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
Definition: erc_settings.h:99
@ 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
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
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.
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_RULE_AREA_T
Definition: typeinfo.h:170
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:169
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:168
@ SCH_PIN_T
Definition: typeinfo.h:153
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588