KiCad PCB EDA Suite
Loading...
Searching...
No Matches
erc.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <algorithm>
27#include <numeric>
28
29#include "connection_graph.h"
30#include "kiface_ids.h"
31#include <advanced_config.h>
32#include <common.h> // for ExpandEnvVarSubstitutions
33#include <erc/erc.h>
36#include <string_utils.h>
37#include <sch_pin.h>
38#include <project_sch.h>
41#include <sch_edit_frame.h>
42#include <sch_marker.h>
43#include <sch_reference_list.h>
44#include <sch_rule_area.h>
45#include <sch_sheet.h>
46#include <sch_sheet_pin.h>
47#include <sch_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*>> connMap;
617 SCH_SCREEN* screen = sheet.LastScreen();
618
619 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
620 {
621 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
622
623 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
624 connMap[pin->GetPosition()].emplace_back( pin );
625 }
626
627 for( SCH_ITEM* item : screen->Items().OfType( SCH_LINE_T ) )
628 {
629 SCH_LINE* line = static_cast<SCH_LINE*>( item );
630
631 if( line->IsGraphicLine() )
632 continue;
633
634 for( const VECTOR2I& pt : line->GetConnectionPoints() )
635 connMap[pt].emplace_back( line );
636 }
637
638 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
639 {
640 if( pair.second.size() >= 4 )
641 {
642 err_count++;
643
644 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOUR_WAY_JUNCTION );
645
646 ercItem->SetItems( pair.second[0], pair.second[1], pair.second[2], pair.second[3] );
647
648 wxString msg = wxString::Format( _( "Four items connected at %d, %d" ),
649 pair.first.x, pair.first.y );
650 ercItem->SetErrorMessage( msg );
651
652 ercItem->SetSheetSpecificPath( sheet );
653
654 SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
655 sheet.LastScreen()->Append( marker );
656 }
657 }
658 }
659
660 return err_count;
661}
662
663
665{
666 int err_count = 0;
667
668 for( const SCH_SHEET_PATH& sheet : m_schematic->GetSheets() )
669 {
670 std::map<VECTOR2I, std::vector<SCH_ITEM*>> pinMap;
671
672 auto addOther =
673 [&]( const VECTOR2I& pt, SCH_ITEM* aOther )
674 {
675 if( pinMap.count( pt ) )
676 pinMap[pt].emplace_back( aOther );
677 };
678
679 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
680 {
681 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
682
683 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
684 {
685 if( pin->GetLibPin()->GetType() == ELECTRICAL_PINTYPE::PT_NC )
686 pinMap[pin->GetPosition()].emplace_back( pin );
687 }
688 }
689
690 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
691 {
692 if( item->Type() == SCH_SYMBOL_T )
693 {
694 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
695
696 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
697 {
698 if( pin->GetLibPin()->GetType() != ELECTRICAL_PINTYPE::PT_NC )
699 addOther( pin->GetPosition(), pin );
700 }
701 }
702 else if( item->IsConnectable() )
703 {
704 for( const VECTOR2I& pt : item->GetConnectionPoints() )
705 addOther( pt, item );
706 }
707 }
708
709 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : pinMap )
710 {
711 if( pair.second.size() > 1 )
712 {
713 err_count++;
714
715 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED );
716
717 ercItem->SetItems( pair.second[0], pair.second[1],
718 pair.second.size() > 2 ? pair.second[2] : nullptr,
719 pair.second.size() > 3 ? pair.second[3] : nullptr );
720 ercItem->SetErrorMessage( _( "Pin with 'no connection' type is connected" ) );
721 ercItem->SetSheetSpecificPath( sheet );
722
723 SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
724 sheet.LastScreen()->Append( marker );
725 }
726 }
727 }
728
729 return err_count;
730}
731
732
734{
735 ERC_SETTINGS& settings = m_schematic->ErcSettings();
736 const NET_MAP& nets = m_schematic->ConnectionGraph()->GetNetMap();
737
738 int errors = 0;
739
740 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : nets )
741 {
742 std::vector<ERC_SCH_PIN_CONTEXT> pins;
743 std::unordered_map<EDA_ITEM*, SCH_SCREEN*> pinToScreenMap;
744 bool has_noconnect = false;
745
746 for( CONNECTION_SUBGRAPH* subgraph: net.second )
747 {
748 if( subgraph->GetNoConnect() )
749 has_noconnect = true;
750
751 for( SCH_ITEM* item : subgraph->GetItems() )
752 {
753 if( item->Type() == SCH_PIN_T )
754 {
755 pins.emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
756 pinToScreenMap[item] = subgraph->GetSheet().LastScreen();
757 }
758 }
759 }
760
761 ERC_SCH_PIN_CONTEXT needsDriver;
762 bool hasDriver = false;
763
764 // We need different drivers for power nets and normal nets.
765 // A power net has at least one pin having the ELECTRICAL_PINTYPE::PT_POWER_IN
766 // and power nets can be driven only by ELECTRICAL_PINTYPE::PT_POWER_OUT pins
767 bool ispowerNet = false;
768
769 for( ERC_SCH_PIN_CONTEXT& refPin : pins )
770 {
771 if( refPin.Pin()->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
772 {
773 ispowerNet = true;
774 break;
775 }
776 }
777
778 for( auto refIt = pins.begin(); refIt != pins.end(); ++refIt )
779 {
780 ERC_SCH_PIN_CONTEXT& refPin = *refIt;
781 ELECTRICAL_PINTYPE refType = refPin.Pin()->GetType();
782
783 if( DrivenPinTypes.contains( refType ) )
784 {
785 // needsDriver will be the pin shown in the error report eventually, so try to
786 // upgrade to a "better" pin if possible: something visible and only a power symbol
787 // if this net needs a power driver
788 if( !needsDriver.Pin()
789 || ( !needsDriver.Pin()->IsVisible() && refPin.Pin()->IsVisible() )
790 || ( ispowerNet
791 != ( needsDriver.Pin()->GetType()
792 == ELECTRICAL_PINTYPE::PT_POWER_IN )
793 && ispowerNet == ( refType == ELECTRICAL_PINTYPE::PT_POWER_IN ) ) )
794 {
795 needsDriver = refPin;
796 }
797 }
798
799 if( ispowerNet )
800 hasDriver |= ( DrivingPowerPinTypes.count( refType ) != 0 );
801 else
802 hasDriver |= ( DrivingPinTypes.count( refType ) != 0 );
803
804 for( auto testIt = refIt + 1; testIt != pins.end(); ++testIt )
805 {
806 ERC_SCH_PIN_CONTEXT& testPin = *testIt;
807
808 // Multiple pins in the same symbol that share a type,
809 // name and position are considered
810 // "stacked" and shouldn't trigger ERC errors
811 if( refPin.Pin()->IsStacked( testPin.Pin() ) && refPin.Sheet() == testPin.Sheet() )
812 continue;
813
814 ELECTRICAL_PINTYPE testType = testPin.Pin()->GetType();
815
816 if( ispowerNet )
817 hasDriver |= DrivingPowerPinTypes.contains( testType );
818 else
819 hasDriver |= DrivingPinTypes.contains( testType );
820
821 PIN_ERROR erc = settings.GetPinMapValue( refType, testType );
822
823 if( erc != PIN_ERROR::OK && settings.IsTestEnabled( ERCE_PIN_TO_PIN_WARNING ) )
824 {
825 std::shared_ptr<ERC_ITEM> ercItem =
826 ERC_ITEM::Create( erc == PIN_ERROR::WARNING ? ERCE_PIN_TO_PIN_WARNING :
828 ercItem->SetItems( refPin.Pin(), testPin.Pin() );
829 ercItem->SetSheetSpecificPath( refPin.Sheet() );
830 ercItem->SetItemsSheetPaths( refPin.Sheet(), testPin.Sheet() );
831
832 ercItem->SetErrorMessage(
833 wxString::Format( _( "Pins of type %s and %s are connected" ),
834 ElectricalPinTypeGetText( refType ),
835 ElectricalPinTypeGetText( testType ) ) );
836
837 SCH_MARKER* marker = new SCH_MARKER( ercItem, refPin.Pin()->GetPosition() );
838 pinToScreenMap[refPin.Pin()]->Append( marker );
839 errors++;
840 }
841 }
842 }
843
844 if( needsDriver.Pin() && !hasDriver && !has_noconnect )
845 {
846 int err_code = ispowerNet ? ERCE_POWERPIN_NOT_DRIVEN : ERCE_PIN_NOT_DRIVEN;
847
848 if( settings.IsTestEnabled( err_code ) )
849 {
850 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( err_code );
851
852 ercItem->SetItems( needsDriver.Pin() );
853 ercItem->SetSheetSpecificPath( needsDriver.Sheet() );
854 ercItem->SetItemsSheetPaths( needsDriver.Sheet() );
855
856 SCH_MARKER* marker = new SCH_MARKER( ercItem, needsDriver.Pin()->GetPosition() );
857 pinToScreenMap[needsDriver.Pin()]->Append( marker );
858 errors++;
859 }
860 }
861 }
862
863 return errors;
864}
865
866
868{
869 const NET_MAP& nets = m_schematic->ConnectionGraph()->GetNetMap();
870
871 int errors = 0;
872
873 std::unordered_map<wxString, std::pair<wxString, SCH_PIN*>> pinToNetMap;
874
875 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : nets )
876 {
877 const wxString& netName = net.first.Name;
878
879 for( CONNECTION_SUBGRAPH* subgraph : net.second )
880 {
881 for( SCH_ITEM* item : subgraph->GetItems() )
882 {
883 if( item->Type() == SCH_PIN_T )
884 {
885 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
886 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
887
888 if( !pin->GetLibPin()->GetParentSymbol()->IsMulti() )
889 continue;
890
891 wxString name = pin->GetParentSymbol()->GetRef( &sheet ) +
892 + ":" + pin->GetShownNumber();
893
894 if( !pinToNetMap.count( name ) )
895 {
896 pinToNetMap[name] = std::make_pair( netName, pin );
897 }
898 else if( pinToNetMap[name].first != netName )
899 {
900 std::shared_ptr<ERC_ITEM> ercItem =
902
903 ercItem->SetErrorMessage( wxString::Format(
904 _( "Pin %s is connected to both %s and %s" ),
905 pin->GetShownNumber(),
906 netName,
907 pinToNetMap[name].first ) );
908
909 ercItem->SetItems( pin, pinToNetMap[name].second );
910 ercItem->SetSheetSpecificPath( sheet );
911 ercItem->SetItemsSheetPaths( sheet, sheet );
912
913 SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() );
914 sheet.LastScreen()->Append( marker );
915 errors += 1;
916 }
917 }
918 }
919 }
920 }
921
922 return errors;
923}
924
925
927{
928 const NET_MAP& nets = m_schematic->ConnectionGraph()->GetNetMap();
929
930 int errors = 0;
931
932 std::unordered_map<wxString, std::pair<SCH_LABEL_BASE*, SCH_SHEET_PATH>> labelMap;
933
934 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : nets )
935 {
936 for( CONNECTION_SUBGRAPH* subgraph : net.second )
937 {
938 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
939
940 for( SCH_ITEM* item : subgraph->GetItems() )
941 {
942 switch( item->Type() )
943 {
944 case SCH_LABEL_T:
945 case SCH_HIER_LABEL_T:
947 {
948 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
949
950 wxString normalized = label->GetShownText( &sheet, false ).Lower();
951
952 if( !labelMap.count( normalized ) )
953 {
954 labelMap[normalized] = std::make_pair( label, sheet );
955 break;
956 }
957
958 auto& [ otherLabel, otherSheet ] = labelMap.at( normalized );
959
960 if( otherLabel->GetShownText( &otherSheet, false )
961 != label->GetShownText( &sheet, false ) )
962 {
963 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMILAR_LABELS );
964 ercItem->SetItems( label, labelMap.at( normalized ).first );
965 ercItem->SetSheetSpecificPath( sheet );
966 ercItem->SetItemsSheetPaths( sheet, labelMap.at( normalized ).second );
967
968 SCH_MARKER* marker = new SCH_MARKER( ercItem, label->GetPosition() );
969 sheet.LastScreen()->Append( marker );
970 errors += 1;
971 }
972
973 break;
974 }
975
976 default:
977 break;
978 }
979 }
980 }
981 }
982
983 return errors;
984}
985
986
988{
989 wxCHECK( m_schematic, 0 );
990
991 ERC_SETTINGS& settings = m_schematic->ErcSettings();
993 wxString msg;
994 int err_count = 0;
995
996 SCH_SCREENS screens( m_schematic->Root() );
997
998 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
999 {
1000 std::vector<SCH_MARKER*> markers;
1001
1002 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1003 {
1004 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1005 LIB_SYMBOL* libSymbolInSchematic = symbol->GetLibSymbolRef().get();
1006
1007 wxCHECK2( libSymbolInSchematic, continue );
1008
1009 wxString libName = symbol->GetLibId().GetLibNickname();
1010 LIB_TABLE_ROW* libTableRow = libTable->FindRow( libName, true );
1011
1012 if( !libTableRow )
1013 {
1014 if( settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
1015 {
1016 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1017 ercItem->SetItems( symbol );
1018 msg.Printf( _( "The current configuration does not include the symbol library '%s'" ),
1019 UnescapeString( libName ) );
1020 ercItem->SetErrorMessage( msg );
1021
1022 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1023 }
1024
1025 continue;
1026 }
1027 else if( !libTable->HasLibrary( libName, true ) )
1028 {
1029 if( settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
1030 {
1031 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1032 ercItem->SetItems( symbol );
1033 msg.Printf( _( "The library '%s' is not enabled in the current configuration" ),
1034 UnescapeString( libName ) );
1035 ercItem->SetErrorMessage( msg );
1036
1037 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1038 }
1039
1040 continue;
1041 }
1042
1043 wxString symbolName = symbol->GetLibId().GetLibItemName();
1044 LIB_SYMBOL* libSymbol = SchGetLibSymbol( symbol->GetLibId(), libTable );
1045
1046 if( libSymbol == nullptr )
1047 {
1048 if( settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
1049 {
1050 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1051 ercItem->SetItems( symbol );
1052 msg.Printf( _( "Symbol '%s' not found in symbol library '%s'" ),
1053 UnescapeString( symbolName ),
1054 UnescapeString( libName ) );
1055 ercItem->SetErrorMessage( msg );
1056
1057 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1058 }
1059
1060 continue;
1061 }
1062
1063 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->Flatten();
1065
1067 && flattenedSymbol->Compare( *libSymbolInSchematic, flags ) != 0 )
1068 {
1069 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_MISMATCH );
1070 ercItem->SetItems( symbol );
1071 msg.Printf( _( "Symbol '%s' doesn't match copy in library '%s'" ),
1072 UnescapeString( symbolName ),
1073 UnescapeString( libName ) );
1074 ercItem->SetErrorMessage( msg );
1075
1076 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1077 }
1078 }
1079
1080 for( SCH_MARKER* marker : markers )
1081 {
1082 screen->Append( marker );
1083 err_count += 1;
1084 }
1085 }
1086
1087 return err_count;
1088}
1089
1090
1092{
1093 wxCHECK( m_schematic, 0 );
1094
1095 wxString msg;
1096 int err_count = 0;
1097
1098 typedef int (*TESTER_FN_PTR)( const wxString&, PROJECT* );
1099
1100 TESTER_FN_PTR linkTester = (TESTER_FN_PTR) aCvPcb->IfaceOrAddress( KIFACE_TEST_FOOTPRINT_LINK );
1101
1102 for( SCH_SHEET_PATH& sheet : m_schematic->GetSheets() )
1103 {
1104 std::vector<SCH_MARKER*> markers;
1105
1106 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1107 {
1108 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1109 wxString footprint = symbol->GetFootprintFieldText( true, &sheet, false );
1110
1111 if( footprint.IsEmpty() )
1112 continue;
1113
1114 LIB_ID fpID;
1115
1116 if( fpID.Parse( footprint, true ) >= 0 )
1117 {
1118 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1119 msg.Printf( _( "'%s' is not a valid footprint identifier." ), footprint );
1120 ercItem->SetErrorMessage( msg );
1121 ercItem->SetItems( symbol );
1122 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1123 continue;
1124 }
1125
1126 wxString libName = fpID.GetLibNickname();
1127 wxString fpName = fpID.GetLibItemName();
1128 int ret = (linkTester)( footprint, aProject );
1129
1131 {
1132 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1133 msg.Printf( _( "The current configuration does not include the footprint library '%s'." ),
1134 libName );
1135 ercItem->SetErrorMessage( msg );
1136 ercItem->SetItems( symbol );
1137 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1138 }
1140 {
1141 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1142 msg.Printf( _( "The footprint library '%s' is not enabled in the current configuration." ),
1143 libName );
1144 ercItem->SetErrorMessage( msg );
1145 ercItem->SetItems( symbol );
1146 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1147 }
1149 {
1150 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1151 msg.Printf( _( "Footprint '%s' not found in library '%s'." ),
1152 fpName,
1153 libName );
1154 ercItem->SetErrorMessage( msg );
1155 ercItem->SetItems( symbol );
1156 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1157 }
1158 }
1159
1160 for( SCH_MARKER* marker : markers )
1161 {
1162 sheet.LastScreen()->Append( marker );
1163 err_count += 1;
1164 }
1165 }
1166
1167 return err_count;
1168}
1169
1170
1172{
1173 const int gridSize = m_schematic->Settings().m_ConnectionGridSize;
1174
1175 SCH_SCREENS screens( m_schematic->Root() );
1176 int err_count = 0;
1177
1178 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
1179 {
1180 std::vector<SCH_MARKER*> markers;
1181
1182 for( SCH_ITEM* item : screen->Items() )
1183 {
1184 if( item->Type() == SCH_LINE_T && item->IsConnectable() )
1185 {
1186 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1187
1188 if( ( line->GetStartPoint().x % gridSize ) != 0
1189 || ( line->GetStartPoint().y % gridSize ) != 0 )
1190 {
1191 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1192 ercItem->SetItems( line );
1193
1194 markers.emplace_back( new SCH_MARKER( ercItem, line->GetStartPoint() ) );
1195 }
1196 else if( ( line->GetEndPoint().x % gridSize ) != 0
1197 || ( line->GetEndPoint().y % gridSize ) != 0 )
1198 {
1199 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1200 ercItem->SetItems( line );
1201
1202 markers.emplace_back( new SCH_MARKER( ercItem, line->GetEndPoint() ) );
1203 }
1204 }
1205 else if( item->Type() == SCH_SYMBOL_T )
1206 {
1207 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1208
1209 for( SCH_PIN* pin : symbol->GetPins( nullptr ) )
1210 {
1211 VECTOR2I pinPos = pin->GetPosition();
1212
1213 if( ( pinPos.x % gridSize ) != 0 || ( pinPos.y % gridSize ) != 0 )
1214 {
1215 auto ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1216 ercItem->SetItems( pin );
1217
1218 markers.emplace_back( new SCH_MARKER( ercItem, pinPos ) );
1219 break;
1220 }
1221 }
1222 }
1223 }
1224
1225 for( SCH_MARKER* marker : markers )
1226 {
1227 screen->Append( marker );
1228 err_count += 1;
1229 }
1230 }
1231
1232 return err_count;
1233}
1234
1235
1237{
1238 wxString msg;
1239 WX_STRING_REPORTER reporter( &msg );
1241 int err_count = 0;
1242 SIM_LIB_MGR libMgr( &m_schematic->Prj() );
1243
1244 for( SCH_SHEET_PATH& sheet : sheets )
1245 {
1246 std::vector<SCH_MARKER*> markers;
1247
1248 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1249 {
1250 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1251
1252 // Power symbols and other symbols which have the reference starting with "#" are
1253 // not included in simulation
1254 if( symbol->GetRef( &sheet ).StartsWith( '#' ) || symbol->GetExcludedFromSim() )
1255 continue;
1256
1257 // Reset for each symbol
1258 msg.Clear();
1259
1260 SIM_LIBRARY::MODEL model = libMgr.CreateModel( &sheet, *symbol, reporter );
1261
1262 if( !msg.IsEmpty() )
1263 {
1264 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMULATION_MODEL );
1265
1266 //Remove \n and \r at e.o.l if any:
1267 msg.Trim();
1268
1269 ercItem->SetErrorMessage( msg );
1270 ercItem->SetItems( symbol );
1271
1272 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1273 }
1274 }
1275
1276 for( SCH_MARKER* marker : markers )
1277 {
1278 sheet.LastScreen()->Append( marker );
1279 err_count += 1;
1280 }
1281 }
1282
1283 return err_count;
1284}
1285
1286
1288{
1289 int numErrors = 0;
1290 ERC_SETTINGS& settings = m_schematic->ErcSettings();
1291
1293 return 0;
1294
1295 std::map<SCH_SCREEN*, std::vector<SCH_RULE_AREA*>> allScreenRuleAreas;
1296
1297 SCH_SCREENS screens( m_schematic->Root() );
1298
1299 for( SCH_SCREEN* screen = screens.GetFirst(); screen != nullptr; screen = screens.GetNext() )
1300 {
1301 for( SCH_ITEM* item : screen->Items().OfType( SCH_RULE_AREA_T ) )
1302 {
1303 allScreenRuleAreas[screen].push_back( static_cast<SCH_RULE_AREA*>( item ) );
1304 }
1305 }
1306
1308 numErrors += TestRuleAreaOverlappingRuleAreasERC( allScreenRuleAreas );
1309
1310 return numErrors;
1311}
1312
1313
1315 std::map<SCH_SCREEN*, std::vector<SCH_RULE_AREA*>>& allScreenRuleAreas )
1316{
1317 int numErrors = 0;
1318
1319 for( auto screenRuleAreas : allScreenRuleAreas )
1320 {
1321 std::vector<SCH_RULE_AREA*>& ruleAreas = screenRuleAreas.second;
1322
1323 for( std::size_t i = 0; i < ruleAreas.size(); ++i )
1324 {
1325 SHAPE_POLY_SET& polyFirst = ruleAreas[i]->GetPolyShape();
1326
1327 for( std::size_t j = i + 1; j < ruleAreas.size(); ++j )
1328 {
1329 SHAPE_POLY_SET polySecond = ruleAreas[j]->GetPolyShape();
1330 if( polyFirst.Collide( &polySecond ) )
1331 {
1332 numErrors++;
1333
1334 SCH_SCREEN* screen = screenRuleAreas.first;
1335 SCH_SHEET_PATH firstSheet = screen->GetClientSheetPaths()[0];
1336
1337 std::shared_ptr<ERC_ITEM> ercItem =
1339 ercItem->SetItems( ruleAreas[i], ruleAreas[j] );
1340 ercItem->SetSheetSpecificPath( firstSheet );
1341 ercItem->SetItemsSheetPaths( firstSheet, firstSheet );
1342
1343 SCH_MARKER* marker = new SCH_MARKER( ercItem, ruleAreas[i]->GetPosition() );
1344 screen->Append( marker );
1345 }
1346 }
1347 }
1348 }
1349
1350 return numErrors;
1351}
1352
1353
1355 KIFACE* aCvPcb, PROJECT* aProject, PROGRESS_REPORTER* aProgressReporter )
1356{
1357 ERC_SETTINGS& settings = m_schematic->ErcSettings();
1358
1359 // Test duplicate sheet names inside a given sheet. While one can have multiple references
1360 // to the same file, each must have a unique name.
1362 {
1363 if( aProgressReporter )
1364 aProgressReporter->AdvancePhase( _( "Checking sheet names..." ) );
1365
1367 }
1368
1369 if( settings.IsTestEnabled( ERCE_BUS_ALIAS_CONFLICT ) )
1370 {
1371 if( aProgressReporter )
1372 aProgressReporter->AdvancePhase( _( "Checking bus conflicts..." ) );
1373
1375 }
1376
1377 // The connection graph has a whole set of ERC checks it can run
1378 if( aProgressReporter )
1379 aProgressReporter->AdvancePhase( _( "Checking conflicts..." ) );
1380
1381 // If we are using the new connectivity, make sure that we do a full-rebuild
1382 if( aEditFrame )
1383 {
1384 if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
1385 aEditFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
1386 else
1387 aEditFrame->RecalculateConnections( nullptr, NO_CLEANUP );
1388 }
1389
1391
1392 if( aProgressReporter )
1393 aProgressReporter->AdvancePhase( _( "Checking rule areas..." ) );
1394
1396 {
1398 }
1399
1400 if( aProgressReporter )
1401 aProgressReporter->AdvancePhase( _( "Checking units..." ) );
1402
1403 // Test is all units of each multiunit symbol have the same footprint assigned.
1404 if( settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_FP ) )
1405 {
1406 if( aProgressReporter )
1407 aProgressReporter->AdvancePhase( _( "Checking footprints..." ) );
1408
1410 }
1411
1412 if( settings.IsTestEnabled( ERCE_MISSING_UNIT )
1415 || settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
1416 {
1418 }
1419
1420 if( aProgressReporter )
1421 aProgressReporter->AdvancePhase( _( "Checking pins..." ) );
1422
1423 if( settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_NET ) )
1425
1426 // Test pins on each net against the pin connection table
1427 if( settings.IsTestEnabled( ERCE_PIN_TO_PIN_ERROR )
1429 || settings.IsTestEnabled( ERCE_PIN_NOT_DRIVEN ) )
1430 {
1431 TestPinToPin();
1432 }
1433
1434 // Test similar labels (i;e. labels which are identical when
1435 // using case insensitive comparisons)
1436 if( settings.IsTestEnabled( ERCE_SIMILAR_LABELS ) )
1437 {
1438 if( aProgressReporter )
1439 aProgressReporter->AdvancePhase( _( "Checking labels..." ) );
1440
1442 }
1443
1444 if( settings.IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) )
1445 {
1446 if( aProgressReporter )
1447 aProgressReporter->AdvancePhase( _( "Checking for unresolved variables..." ) );
1448
1449 TestTextVars( aDrawingSheet );
1450 }
1451
1452 if( settings.IsTestEnabled( ERCE_SIMULATION_MODEL ) )
1453 {
1454 if( aProgressReporter )
1455 aProgressReporter->AdvancePhase( _( "Checking SPICE models..." ) );
1456
1458 }
1459
1460 if( settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED ) )
1461 {
1462 if( aProgressReporter )
1463 aProgressReporter->AdvancePhase( _( "Checking no connect pins for connections..." ) );
1464
1466 }
1467
1470 {
1471 if( aProgressReporter )
1472 aProgressReporter->AdvancePhase( _( "Checking for library symbol issues..." ) );
1473
1475 }
1476
1477 if( settings.IsTestEnabled( ERCE_FOOTPRINT_LINK_ISSUES ) && aCvPcb )
1478 {
1479 if( aProgressReporter )
1480 aProgressReporter->AdvancePhase( _( "Checking for footprint link issues..." ) );
1481
1482 TestFootprintLinkIssues( aCvPcb, aProject );
1483 }
1484
1485 if( settings.IsTestEnabled( ERCE_ENDPOINT_OFF_GRID ) )
1486 {
1487 if( aProgressReporter )
1488 aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) );
1489
1491 }
1492
1493 if( settings.IsTestEnabled( ERCE_FOUR_WAY_JUNCTION ) )
1494 {
1495 if( aProgressReporter )
1496 aProgressReporter->AdvancePhase( _( "Checking for four way junctions..." ) );
1497
1499 }
1500
1501 if( settings.IsTestEnabled( ERCE_UNDEFINED_NETCLASS ) )
1502 {
1503 if( aProgressReporter )
1504 aProgressReporter->AdvancePhase( _( "Checking for undefined netclasses..." ) );
1505
1507 }
1508
1510}
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:257
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:121
bool IsTestEnabled(int aErrorCode) const
Definition: erc_settings.h:137
PIN_ERROR GetPinMapValue(int aFirstType, int aSecondType) const
Definition: erc_settings.h:148
int TestLibSymbolIssues()
Test symbols for changed library symbols and broken symbol library links.
Definition: erc.cpp:987
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:733
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition: erc.cpp:926
int RunRuleAreaERC()
Tests for rule area ERC issues.
Definition: erc.cpp:1287
int TestFootprintLinkIssues(KIFACE *aCvPcb, PROJECT *aProject)
Test footprint links against the current footprint libraries.
Definition: erc.cpp:1091
int TestOffGridEndpoints()
Test pins and wire ends for being off grid.
Definition: erc.cpp:1171
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:867
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:664
int TestRuleAreaOverlappingRuleAreasERC(std::map< SCH_SCREEN *, std::vector< SCH_RULE_AREA * > > &allScreenRuleAreas)
Runs ERC to check for overlapping rule areas.
Definition: erc.cpp:1314
int TestFourWayJunction()
Test to see if there are potentially confusing 4-way junctions in the schematic.
Definition: erc.cpp:610
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:1236
SCHEMATIC * m_schematic
Definition: erc.h:169
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition: erc.cpp:1354
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:825
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:289
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:296
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
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:709
VECTOR2I GetEndPoint() const
Definition: sch_line.h:140
VECTOR2I GetStartPoint() const
Definition: sch_line.h:135
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
Definition: sch_line.cpp:970
bool IsVisible() const
Definition: sch_pin.cpp:340
VECTOR2I GetPosition() const override
Definition: sch_pin.cpp:237
bool IsStacked(const SCH_PIN *aPin) const
Definition: sch_pin.cpp:374
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:291
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:703
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:151
std::vector< SCH_SHEET_PATH > & GetClientSheetPaths()
Return the number of times this screen is used.
Definition: sch_screen.h:177
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:108
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:105
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:895
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:779
const LIB_ID & GetLibId() const override
Definition: sch_symbol.h:194
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:959
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:213
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:712
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_FOUR_WAY_JUNCTION
A four-way junction was found.
Definition: erc_settings.h:85
@ 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:92
@ 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:93
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
Definition: erc_settings.h:100
@ 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:602