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
134extern void CheckDuplicatePins( LIB_SYMBOL* aSymbol, std::vector<wxString>& aMessages,
135 UNITS_PROVIDER* aUnitsProvider );
136
137int ERC_TESTER::TestDuplicateSheetNames( bool aCreateMarker )
138{
139 int err_count = 0;
140
141 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.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( const SCH_SHEET_PATH& sheet : m_sheetList )
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 std::vector<std::shared_ptr<BUS_ALIAS>> aliases;
308
309 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
310 {
311 const auto& screen_aliases = screen->GetBusAliases();
312
313 for( const std::shared_ptr<BUS_ALIAS>& alias : screen_aliases )
314 {
315 std::vector<wxString> aliasMembers = alias->Members();
316 std::sort( aliasMembers.begin(), aliasMembers.end() );
317
318 for( const std::shared_ptr<BUS_ALIAS>& test : aliases )
319 {
320 std::vector<wxString> testMembers = test->Members();
321 std::sort( testMembers.begin(), testMembers.end() );
322
323 if( alias->GetName() == test->GetName() && aliasMembers != testMembers )
324 {
325 msg.Printf( _( "Bus alias %s has conflicting definitions on %s and %s" ),
326 alias->GetName(),
327 alias->GetParent()->GetFileName(),
328 test->GetParent()->GetFileName() );
329
330 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ALIAS_CONFLICT );
331 ercItem->SetErrorMessage( msg );
332
333 SCH_MARKER* marker = new SCH_MARKER( ercItem, VECTOR2I() );
334 test->GetParent()->Append( marker );
335
336 ++err_count;
337 }
338 }
339 }
340
341 aliases.insert( aliases.end(), screen_aliases.begin(), screen_aliases.end() );
342 }
343
344 return err_count;
345}
346
347
349{
350 int errors = 0;
351
352 for( std::pair<const wxString, SCH_REFERENCE_LIST>& symbol : m_refMap )
353 {
354 SCH_REFERENCE_LIST& refList = symbol.second;
355
356 if( refList.GetCount() == 0 )
357 {
358 wxFAIL; // it should not happen
359 continue;
360 }
361
362 // Reference footprint
363 SCH_SYMBOL* unit = nullptr;
364 wxString unitName;
365 wxString unitFP;
366
367 for( unsigned i = 0; i < refList.GetCount(); ++i )
368 {
369 SCH_SHEET_PATH sheetPath = refList.GetItem( i ).GetSheetPath();
370 unitFP = refList.GetItem( i ).GetFootprint();
371
372 if( !unitFP.IsEmpty() )
373 {
374 unit = refList.GetItem( i ).GetSymbol();
375 unitName = unit->GetRef( &sheetPath, true );
376 break;
377 }
378 }
379
380 for( unsigned i = 0; i < refList.GetCount(); ++i )
381 {
382 SCH_REFERENCE& secondRef = refList.GetItem( i );
383 SCH_SYMBOL* secondUnit = secondRef.GetSymbol();
384 wxString secondName = secondUnit->GetRef( &secondRef.GetSheetPath(), true );
385 const wxString secondFp = secondRef.GetFootprint();
386 wxString msg;
387
388 if( unit && !secondFp.IsEmpty() && unitFP != secondFp )
389 {
390 msg.Printf( _( "Different footprints assigned to %s and %s" ),
391 unitName, secondName );
392
393 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_FP );
394 ercItem->SetErrorMessage( msg );
395 ercItem->SetItems( unit, secondUnit );
396
397 SCH_MARKER* marker = new SCH_MARKER( ercItem, secondUnit->GetPosition() );
398 secondRef.GetSheetPath().LastScreen()->Append( marker );
399
400 ++errors;
401 }
402 }
403 }
404
405 return errors;
406}
407
408
410{
411 int errors = 0;
412
413 for( std::pair<const wxString, SCH_REFERENCE_LIST>& symbol : m_refMap )
414 {
415 SCH_REFERENCE_LIST& refList = symbol.second;
416
417 wxCHECK2( refList.GetCount(), continue );
418
419 // Reference unit
420 SCH_REFERENCE& base_ref = refList.GetItem( 0 );
421 SCH_SYMBOL* unit = base_ref.GetSymbol();
422 LIB_SYMBOL& libSymbol = base_ref.GetSymbol()->GetLibSymbolRef();
423
424 if( static_cast<ssize_t>( refList.GetCount() ) == libSymbol.GetUnitCount() )
425 continue;
426
427 std::set<int> lib_units;
428 std::set<int> instance_units;
429 std::set<int> missing_units;
430
431 auto report_missing =
432 [&]( std::set<int>& aMissingUnits, wxString aErrorMsg, int aErrorCode )
433 {
434 wxString msg;
435 wxString missing_pin_units = wxS( "[ " );
436 int ii = 0;
437
438 for( int missing_unit : aMissingUnits )
439 {
440 if( ii++ == 3 )
441 {
442 missing_pin_units += wxS( "....." );
443 break;
444 }
445
446 missing_pin_units += libSymbol.GetUnitDisplayName( missing_unit ) + ", " ;
447 }
448
449 missing_pin_units.Truncate( missing_pin_units.length() - 2 );
450 missing_pin_units += wxS( " ]" );
451
452 msg.Printf( aErrorMsg, symbol.first, missing_pin_units );
453
454 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( aErrorCode );
455 ercItem->SetErrorMessage( msg );
456 ercItem->SetItems( unit );
457
458 SCH_MARKER* marker = new SCH_MARKER( ercItem, unit->GetPosition() );
459 base_ref.GetSheetPath().LastScreen()->Append( marker );
460
461 ++errors;
462 };
463
464 for( int ii = 1; ii <= libSymbol.GetUnitCount(); ++ii )
465 lib_units.insert( lib_units.end(), ii );
466
467 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
468 instance_units.insert( instance_units.end(), refList.GetItem( ii ).GetUnit() );
469
470 std::set_difference( lib_units.begin(), lib_units.end(),
471 instance_units.begin(), instance_units.end(),
472 std::inserter( missing_units, missing_units.begin() ) );
473
474 if( !missing_units.empty() && m_settings.IsTestEnabled( ERCE_MISSING_UNIT ) )
475 {
476 report_missing( missing_units, _( "Symbol %s has unplaced units %s" ),
478 }
479
480 std::set<int> missing_power;
481 std::set<int> missing_input;
482 std::set<int> missing_bidi;
483
484 for( int missing_unit : missing_units )
485 {
486 int bodyStyle = 0;
487
488 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
489 {
490 if( refList.GetItem( ii ).GetUnit() == missing_unit )
491 {
492 bodyStyle = refList.GetItem( ii ).GetSymbol()->GetBodyStyle();
493 break;
494 }
495 }
496
497 for( SCH_PIN* pin : libSymbol.GetPins( missing_unit, bodyStyle ) )
498 {
499 switch( pin->GetType() )
500 {
501 case ELECTRICAL_PINTYPE::PT_POWER_IN:
502 missing_power.insert( missing_unit );
503 break;
504
505 case ELECTRICAL_PINTYPE::PT_BIDI:
506 missing_bidi.insert( missing_unit );
507 break;
508
509 case ELECTRICAL_PINTYPE::PT_INPUT:
510 missing_input.insert( missing_unit );
511 break;
512
513 default:
514 break;
515 }
516 }
517 }
518
519 if( !missing_power.empty() && m_settings.IsTestEnabled( ERCE_MISSING_POWER_INPUT_PIN ) )
520 {
521 report_missing( missing_power,
522 _( "Symbol %s has input power pins in units %s that are not placed." ),
524 }
525
526 if( !missing_input.empty() && m_settings.IsTestEnabled( ERCE_MISSING_INPUT_PIN ) )
527 {
528 report_missing( missing_input,
529 _( "Symbol %s has input pins in units %s that are not placed." ),
531 }
532
533 if( !missing_bidi.empty() && m_settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
534 {
535 report_missing( missing_bidi,
536 _( "Symbol %s has bidirectional pins in units %s that are not "
537 "placed." ),
539 }
540 }
541
542 return errors;
543}
544
545
547{
548 int err_count = 0;
549 std::shared_ptr<NET_SETTINGS>& settings = m_schematic->Prj().GetProjectFile().NetSettings();
550 wxString defaultNetclass = settings->m_DefaultNetClass->GetName();
551
552 auto logError =
553 [&]( const SCH_SHEET_PATH& sheet, SCH_ITEM* item, const wxString& netclass )
554 {
555 err_count++;
556
557 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNDEFINED_NETCLASS );
558
559 ercItem->SetItems( item );
560 ercItem->SetErrorMessage( wxString::Format( _( "Netclass %s is not defined" ),
561 netclass ) );
562
563 SCH_MARKER* marker = new SCH_MARKER( ercItem, item->GetPosition() );
564 sheet.LastScreen()->Append( marker );
565 };
566
567 for( const SCH_SHEET_PATH& sheet : m_sheetList )
568 {
569 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
570 {
571 item->RunOnChildren(
572 [&]( SCH_ITEM* aChild )
573 {
574 if( aChild->Type() == SCH_FIELD_T )
575 {
576 SCH_FIELD* field = static_cast<SCH_FIELD*>( aChild );
577
578 if( field->GetCanonicalName() == wxT( "Netclass" ) )
579 {
580 wxString netclass = field->GetShownText( &sheet, false );
581
582 if( !netclass.IsSameAs( defaultNetclass )
583 && settings->m_NetClasses.count( netclass ) == 0 )
584 {
585 logError( sheet, item, netclass );
586 }
587 }
588 }
589
590 return true;
591 } );
592 }
593 }
594
595 return err_count;
596}
597
598
600{
601 int err_count = 0;
602
603 for( const SCH_SHEET_PATH& sheet : m_sheetList )
604 {
605 std::map<VECTOR2I, std::vector<SCH_ITEM*>> connMap;
606 SCH_SCREEN* screen = sheet.LastScreen();
607
608 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
609 {
610 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
611
612 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
613 connMap[pin->GetPosition()].emplace_back( pin );
614 }
615
616 for( SCH_ITEM* item : screen->Items().OfType( SCH_LINE_T ) )
617 {
618 SCH_LINE* line = static_cast<SCH_LINE*>( item );
619
620 if( line->IsGraphicLine() )
621 continue;
622
623 for( const VECTOR2I& pt : line->GetConnectionPoints() )
624 connMap[pt].emplace_back( line );
625 }
626
627 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
628 {
629 if( pair.second.size() >= 4 )
630 {
631 err_count++;
632
633 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOUR_WAY_JUNCTION );
634
635 ercItem->SetItems( pair.second[0], pair.second[1], pair.second[2], pair.second[3] );
636
637 wxString msg = wxString::Format( _( "Four items connected at %d, %d" ),
638 pair.first.x, pair.first.y );
639 ercItem->SetErrorMessage( msg );
640
641 ercItem->SetSheetSpecificPath( sheet );
642
643 SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
644 sheet.LastScreen()->Append( marker );
645 }
646 }
647 }
648
649 return err_count;
650}
651
652
654{
655 int err_count = 0;
656
657 for( const SCH_SHEET_PATH& sheet : m_sheetList )
658 {
659 std::map<VECTOR2I, std::vector<SCH_ITEM*>> pinMap;
660
661 auto addOther =
662 [&]( const VECTOR2I& pt, SCH_ITEM* aOther )
663 {
664 if( pinMap.count( pt ) )
665 pinMap[pt].emplace_back( aOther );
666 };
667
668 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
669 {
670 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
671
672 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
673 {
674 if( pin->GetLibPin()->GetType() == ELECTRICAL_PINTYPE::PT_NC )
675 pinMap[pin->GetPosition()].emplace_back( pin );
676 }
677 }
678
679 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
680 {
681 if( item->Type() == SCH_SYMBOL_T )
682 {
683 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
684
685 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
686 {
687 if( pin->GetLibPin()->GetType() != ELECTRICAL_PINTYPE::PT_NC )
688 addOther( pin->GetPosition(), pin );
689 }
690 }
691 else if( item->IsConnectable() )
692 {
693 for( const VECTOR2I& pt : item->GetConnectionPoints() )
694 addOther( pt, item );
695 }
696 }
697
698 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : pinMap )
699 {
700 if( pair.second.size() > 1 )
701 {
702 err_count++;
703
704 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED );
705
706 ercItem->SetItems( pair.second[0], pair.second[1],
707 pair.second.size() > 2 ? pair.second[2] : nullptr,
708 pair.second.size() > 3 ? pair.second[3] : nullptr );
709 ercItem->SetErrorMessage( _( "Pin with 'no connection' type is connected" ) );
710 ercItem->SetSheetSpecificPath( sheet );
711
712 SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
713 sheet.LastScreen()->Append( marker );
714 }
715 }
716 }
717
718 return err_count;
719}
720
721
723{
724 int errors = 0;
725
726 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
727 {
728 std::vector<ERC_SCH_PIN_CONTEXT> pins;
729 std::unordered_map<EDA_ITEM*, SCH_SCREEN*> pinToScreenMap;
730 bool has_noconnect = false;
731
732 for( CONNECTION_SUBGRAPH* subgraph: net.second )
733 {
734 if( subgraph->GetNoConnect() )
735 has_noconnect = true;
736
737 for( SCH_ITEM* item : subgraph->GetItems() )
738 {
739 if( item->Type() == SCH_PIN_T )
740 {
741 pins.emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
742 pinToScreenMap[item] = subgraph->GetSheet().LastScreen();
743 }
744 }
745 }
746
747 std::sort( pins.begin(), pins.end(),
748 []( const ERC_SCH_PIN_CONTEXT& lhs, const ERC_SCH_PIN_CONTEXT& rhs )
749 {
750 int ret = StrNumCmp( lhs.Pin()->GetParentSymbol()->GetRef( &lhs.Sheet() ),
751 rhs.Pin()->GetParentSymbol()->GetRef( &rhs.Sheet() ) );
752
753 if( ret == 0 )
754 ret = StrNumCmp( lhs.Pin()->GetNumber(), rhs.Pin()->GetNumber() );
755
756 if( ret == 0 )
757 ret = lhs < rhs; // Fallback to hash to guarantee deterministic sort
758
759 return ret < 0;
760 } );
761
762 ERC_SCH_PIN_CONTEXT needsDriver;
763 bool hasDriver = false;
764
765 // We need different drivers for power nets and normal nets.
766 // A power net has at least one pin having the ELECTRICAL_PINTYPE::PT_POWER_IN
767 // and power nets can be driven only by ELECTRICAL_PINTYPE::PT_POWER_OUT pins
768 bool ispowerNet = false;
769
770 for( ERC_SCH_PIN_CONTEXT& refPin : pins )
771 {
772 if( refPin.Pin()->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
773 {
774 ispowerNet = true;
775 break;
776 }
777 }
778
779 for( auto refIt = pins.begin(); refIt != pins.end(); ++refIt )
780 {
781 ERC_SCH_PIN_CONTEXT& refPin = *refIt;
782 ELECTRICAL_PINTYPE refType = refPin.Pin()->GetType();
783
784 if( DrivenPinTypes.contains( refType ) )
785 {
786 // needsDriver will be the pin shown in the error report eventually, so try to
787 // upgrade to a "better" pin if possible: something visible and only a power symbol
788 // if this net needs a power driver
789 if( !needsDriver.Pin()
790 || ( !needsDriver.Pin()->IsVisible() && refPin.Pin()->IsVisible() )
791 || ( ispowerNet
792 != ( needsDriver.Pin()->GetType()
793 == ELECTRICAL_PINTYPE::PT_POWER_IN )
794 && ispowerNet == ( refType == ELECTRICAL_PINTYPE::PT_POWER_IN ) ) )
795 {
796 needsDriver = refPin;
797 }
798 }
799
800 if( ispowerNet )
801 hasDriver |= ( DrivingPowerPinTypes.count( refType ) != 0 );
802 else
803 hasDriver |= ( DrivingPinTypes.count( refType ) != 0 );
804
805 for( auto testIt = refIt + 1; testIt != pins.end(); ++testIt )
806 {
807 ERC_SCH_PIN_CONTEXT& testPin = *testIt;
808
809 // Multiple pins in the same symbol that share a type,
810 // name and position are considered
811 // "stacked" and shouldn't trigger ERC errors
812 if( refPin.Pin()->IsStacked( testPin.Pin() ) && refPin.Sheet() == testPin.Sheet() )
813 continue;
814
815 ELECTRICAL_PINTYPE testType = testPin.Pin()->GetType();
816
817 if( ispowerNet )
818 hasDriver |= DrivingPowerPinTypes.contains( testType );
819 else
820 hasDriver |= DrivingPinTypes.contains( testType );
821
822 PIN_ERROR erc = m_settings.GetPinMapValue( refType, testType );
823
824 if( erc != PIN_ERROR::OK && m_settings.IsTestEnabled( ERCE_PIN_TO_PIN_WARNING ) )
825 {
826 std::shared_ptr<ERC_ITEM> ercItem =
827 ERC_ITEM::Create( erc == PIN_ERROR::WARNING ? ERCE_PIN_TO_PIN_WARNING :
829 ercItem->SetItems( refPin.Pin(), testPin.Pin() );
830 ercItem->SetSheetSpecificPath( refPin.Sheet() );
831 ercItem->SetItemsSheetPaths( refPin.Sheet(), testPin.Sheet() );
832
833 ercItem->SetErrorMessage(
834 wxString::Format( _( "Pins of type %s and %s are connected" ),
835 ElectricalPinTypeGetText( refType ),
836 ElectricalPinTypeGetText( testType ) ) );
837
838 SCH_MARKER* marker = new SCH_MARKER( ercItem, refPin.Pin()->GetPosition() );
839 pinToScreenMap[refPin.Pin()]->Append( marker );
840 errors++;
841 }
842 }
843 }
844
845 if( needsDriver.Pin() && !hasDriver && !has_noconnect )
846 {
847 int err_code = ispowerNet ? ERCE_POWERPIN_NOT_DRIVEN : ERCE_PIN_NOT_DRIVEN;
848
849 if( m_settings.IsTestEnabled( err_code ) )
850 {
851 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( err_code );
852
853 ercItem->SetItems( needsDriver.Pin() );
854 ercItem->SetSheetSpecificPath( needsDriver.Sheet() );
855 ercItem->SetItemsSheetPaths( needsDriver.Sheet() );
856
857 SCH_MARKER* marker = new SCH_MARKER( ercItem, needsDriver.Pin()->GetPosition() );
858 pinToScreenMap[needsDriver.Pin()]->Append( marker );
859 errors++;
860 }
861 }
862 }
863
864 return errors;
865}
866
867
869{
870 int errors = 0;
871
872 std::unordered_map<wxString, std::pair<wxString, SCH_PIN*>> pinToNetMap;
873
874 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
875 {
876 const wxString& netName = net.first.Name;
877
878 for( CONNECTION_SUBGRAPH* subgraph : net.second )
879 {
880 for( SCH_ITEM* item : subgraph->GetItems() )
881 {
882 if( item->Type() == SCH_PIN_T )
883 {
884 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
885 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
886
887 if( !pin->GetLibPin()->GetParentSymbol()->IsMulti() )
888 continue;
889
890 wxString name = pin->GetParentSymbol()->GetRef( &sheet ) +
891 + ":" + pin->GetShownNumber();
892
893 if( !pinToNetMap.count( name ) )
894 {
895 pinToNetMap[name] = std::make_pair( netName, pin );
896 }
897 else if( pinToNetMap[name].first != netName )
898 {
899 std::shared_ptr<ERC_ITEM> ercItem =
901
902 ercItem->SetErrorMessage( wxString::Format(
903 _( "Pin %s is connected to both %s and %s" ),
904 pin->GetShownNumber(),
905 netName,
906 pinToNetMap[name].first ) );
907
908 ercItem->SetItems( pin, pinToNetMap[name].second );
909 ercItem->SetSheetSpecificPath( sheet );
910 ercItem->SetItemsSheetPaths( sheet, sheet );
911
912 SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() );
913 sheet.LastScreen()->Append( marker );
914 errors += 1;
915 }
916 }
917 }
918 }
919 }
920
921 return errors;
922}
923
924
926{
927 int errors = 0;
928
929 std::unordered_map<wxString, std::pair<SCH_LABEL_BASE*, SCH_SHEET_PATH>> labelMap;
930
931 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
932 {
933 for( CONNECTION_SUBGRAPH* subgraph : net.second )
934 {
935 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
936
937 for( SCH_ITEM* item : subgraph->GetItems() )
938 {
939 switch( item->Type() )
940 {
941 case SCH_LABEL_T:
942 case SCH_HIER_LABEL_T:
944 {
945 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
946
947 wxString normalized = label->GetShownText( &sheet, false ).Lower();
948
949 if( !labelMap.count( normalized ) )
950 {
951 labelMap[normalized] = std::make_pair( label, sheet );
952 break;
953 }
954
955 auto& [ otherLabel, otherSheet ] = labelMap.at( normalized );
956
957 if( otherLabel->GetShownText( &otherSheet, false )
958 != label->GetShownText( &sheet, false ) )
959 {
960 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMILAR_LABELS );
961 ercItem->SetItems( label, labelMap.at( normalized ).first );
962 ercItem->SetSheetSpecificPath( sheet );
963 ercItem->SetItemsSheetPaths( sheet, labelMap.at( normalized ).second );
964
965 SCH_MARKER* marker = new SCH_MARKER( ercItem, label->GetPosition() );
966 sheet.LastScreen()->Append( marker );
967 errors += 1;
968 }
969
970 break;
971 }
972
973 default:
974 break;
975 }
976 }
977 }
978 }
979
980 return errors;
981}
982
983
985{
986 wxCHECK( m_schematic, 0 );
987
989 wxString msg;
990 int err_count = 0;
991
992 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
993 {
994 std::vector<SCH_MARKER*> markers;
995
996 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
997 {
998 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
999 LIB_SYMBOL& libSymbolInSchematic = symbol->GetLibSymbolRef();
1000
1001 wxString libName = symbol->GetLibId().GetLibNickname();
1002 LIB_TABLE_ROW* libTableRow = libTable->FindRow( libName, true );
1003
1004 if( !libTableRow )
1005 {
1007 {
1008 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1009 ercItem->SetItems( symbol );
1010 msg.Printf( _( "The current configuration does not include the symbol library '%s'" ),
1011 UnescapeString( libName ) );
1012 ercItem->SetErrorMessage( msg );
1013
1014 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1015 }
1016
1017 continue;
1018 }
1019 else if( !libTable->HasLibrary( libName, true ) )
1020 {
1022 {
1023 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1024 ercItem->SetItems( symbol );
1025 msg.Printf( _( "The library '%s' is not enabled in the current configuration" ),
1026 UnescapeString( libName ) );
1027 ercItem->SetErrorMessage( msg );
1028
1029 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1030 }
1031
1032 continue;
1033 }
1034
1035 wxString symbolName = symbol->GetLibId().GetLibItemName();
1036 LIB_SYMBOL* libSymbol = SchGetLibSymbol( symbol->GetLibId(), libTable );
1037
1038 if( libSymbol == nullptr )
1039 {
1041 {
1042 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1043 ercItem->SetItems( symbol );
1044 msg.Printf( _( "Symbol '%s' not found in symbol library '%s'" ),
1045 UnescapeString( symbolName ),
1046 UnescapeString( libName ) );
1047 ercItem->SetErrorMessage( msg );
1048
1049 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1050 }
1051
1052 continue;
1053 }
1054
1055 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->Flatten();
1057
1059 {
1060 // We have to check for duplicate pins first as they will cause Compare() to fail.
1061 std::vector<wxString> messages;
1062 UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILS );
1063 CheckDuplicatePins( &libSymbolInSchematic, messages, &unitsProvider );
1064
1065 if( !messages.empty() )
1066 {
1067 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DUPLICATE_PIN_ERROR );
1068 ercItem->SetItems( symbol );
1069 msg.Printf( _( "Symbol '%s' has multiple pins with the same pin number" ),
1070 UnescapeString( symbolName ) );
1071 ercItem->SetErrorMessage( msg );
1072
1073 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1074 }
1075 else if( flattenedSymbol->Compare( libSymbolInSchematic, flags ) != 0 )
1076 {
1077 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_MISMATCH );
1078 ercItem->SetItems( symbol );
1079 msg.Printf( _( "Symbol '%s' doesn't match copy in library '%s'" ),
1080 UnescapeString( symbolName ),
1081 UnescapeString( libName ) );
1082 ercItem->SetErrorMessage( msg );
1083
1084 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1085 }
1086 }
1087 }
1088
1089 for( SCH_MARKER* marker : markers )
1090 {
1091 screen->Append( marker );
1092 err_count += 1;
1093 }
1094 }
1095
1096 return err_count;
1097}
1098
1099
1101{
1102 wxCHECK( m_schematic, 0 );
1103
1104 wxString msg;
1105 int err_count = 0;
1106
1107 typedef int (*TESTER_FN_PTR)( const wxString&, PROJECT* );
1108
1109 TESTER_FN_PTR linkTester = (TESTER_FN_PTR) aCvPcb->IfaceOrAddress( KIFACE_TEST_FOOTPRINT_LINK );
1110
1111 for( SCH_SHEET_PATH& sheet : m_sheetList )
1112 {
1113 std::vector<SCH_MARKER*> markers;
1114
1115 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1116 {
1117 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1118 wxString footprint = symbol->GetFootprintFieldText( true, &sheet, false );
1119
1120 if( footprint.IsEmpty() )
1121 continue;
1122
1123 LIB_ID fpID;
1124
1125 if( fpID.Parse( footprint, true ) >= 0 )
1126 {
1127 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1128 msg.Printf( _( "'%s' is not a valid footprint identifier." ), footprint );
1129 ercItem->SetErrorMessage( msg );
1130 ercItem->SetItems( symbol );
1131 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1132 continue;
1133 }
1134
1135 wxString libName = fpID.GetLibNickname();
1136 wxString fpName = fpID.GetLibItemName();
1137 int ret = (linkTester)( footprint, aProject );
1138
1140 {
1141 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1142 msg.Printf( _( "The current configuration does not include the footprint library '%s'." ),
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( _( "The footprint library '%s' is not enabled in the current configuration." ),
1152 libName );
1153 ercItem->SetErrorMessage( msg );
1154 ercItem->SetItems( symbol );
1155 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1156 }
1158 {
1159 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1160 msg.Printf( _( "Footprint '%s' not found in library '%s'." ),
1161 fpName,
1162 libName );
1163 ercItem->SetErrorMessage( msg );
1164 ercItem->SetItems( symbol );
1165 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1166 }
1167 }
1168
1169 for( SCH_MARKER* marker : markers )
1170 {
1171 sheet.LastScreen()->Append( marker );
1172 err_count += 1;
1173 }
1174 }
1175
1176 return err_count;
1177}
1178
1179
1181{
1182 const int gridSize = m_schematic->Settings().m_ConnectionGridSize;
1183 int err_count = 0;
1184
1185 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
1186 {
1187 std::vector<SCH_MARKER*> markers;
1188
1189 for( SCH_ITEM* item : screen->Items() )
1190 {
1191 if( item->Type() == SCH_LINE_T && item->IsConnectable() )
1192 {
1193 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1194
1195 if( ( line->GetStartPoint().x % gridSize ) != 0
1196 || ( line->GetStartPoint().y % gridSize ) != 0 )
1197 {
1198 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1199 ercItem->SetItems( line );
1200
1201 markers.emplace_back( new SCH_MARKER( ercItem, line->GetStartPoint() ) );
1202 }
1203 else if( ( line->GetEndPoint().x % gridSize ) != 0
1204 || ( line->GetEndPoint().y % gridSize ) != 0 )
1205 {
1206 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1207 ercItem->SetItems( line );
1208
1209 markers.emplace_back( new SCH_MARKER( ercItem, line->GetEndPoint() ) );
1210 }
1211 }
1212 else if( item->Type() == SCH_SYMBOL_T )
1213 {
1214 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1215
1216 for( SCH_PIN* pin : symbol->GetPins( nullptr ) )
1217 {
1218 VECTOR2I pinPos = pin->GetPosition();
1219
1220 if( ( pinPos.x % gridSize ) != 0 || ( pinPos.y % gridSize ) != 0 )
1221 {
1222 auto ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1223 ercItem->SetItems( pin );
1224
1225 markers.emplace_back( new SCH_MARKER( ercItem, pinPos ) );
1226 break;
1227 }
1228 }
1229 }
1230 }
1231
1232 for( SCH_MARKER* marker : markers )
1233 {
1234 screen->Append( marker );
1235 err_count += 1;
1236 }
1237 }
1238
1239 return err_count;
1240}
1241
1242
1244{
1245 wxString msg;
1246 WX_STRING_REPORTER reporter( &msg );
1247 int err_count = 0;
1248 SIM_LIB_MGR libMgr( &m_schematic->Prj() );
1249
1250 for( SCH_SHEET_PATH& sheet : m_sheetList )
1251 {
1252 if( sheet.GetExcludedFromSim() )
1253 continue;
1254
1255 std::vector<SCH_MARKER*> markers;
1256
1257 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1258 {
1259 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1260
1261 // Power symbols and other symbols which have the reference starting with "#" are
1262 // not included in simulation
1263 if( symbol->GetRef( &sheet ).StartsWith( '#' ) || symbol->GetExcludedFromSim() )
1264 continue;
1265
1266 // Reset for each symbol
1267 msg.Clear();
1268
1269 SIM_LIBRARY::MODEL model = libMgr.CreateModel( &sheet, *symbol, reporter );
1270
1271 if( !msg.IsEmpty() )
1272 {
1273 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMULATION_MODEL );
1274
1275 //Remove \n and \r at e.o.l if any:
1276 msg.Trim();
1277
1278 ercItem->SetErrorMessage( msg );
1279 ercItem->SetItems( symbol );
1280
1281 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1282 }
1283 }
1284
1285 for( SCH_MARKER* marker : markers )
1286 {
1287 sheet.LastScreen()->Append( marker );
1288 err_count += 1;
1289 }
1290 }
1291
1292 return err_count;
1293}
1294
1295
1297{
1298 int numErrors = 0;
1299
1301 return 0;
1302
1303 std::map<SCH_SCREEN*, std::vector<SCH_RULE_AREA*>> allScreenRuleAreas;
1304
1305 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
1306 {
1307 for( SCH_ITEM* item : screen->Items().OfType( SCH_RULE_AREA_T ) )
1308 {
1309 allScreenRuleAreas[screen].push_back( static_cast<SCH_RULE_AREA*>( item ) );
1310 }
1311 }
1312
1314 numErrors += TestRuleAreaOverlappingRuleAreasERC( allScreenRuleAreas );
1315
1316 return numErrors;
1317}
1318
1319
1321 std::map<SCH_SCREEN*, std::vector<SCH_RULE_AREA*>>& allScreenRuleAreas )
1322{
1323 int numErrors = 0;
1324
1325 for( auto screenRuleAreas : allScreenRuleAreas )
1326 {
1327 std::vector<SCH_RULE_AREA*>& ruleAreas = screenRuleAreas.second;
1328
1329 for( std::size_t i = 0; i < ruleAreas.size(); ++i )
1330 {
1331 SHAPE_POLY_SET& polyFirst = ruleAreas[i]->GetPolyShape();
1332
1333 for( std::size_t j = i + 1; j < ruleAreas.size(); ++j )
1334 {
1335 SHAPE_POLY_SET polySecond = ruleAreas[j]->GetPolyShape();
1336
1337 if( polyFirst.Collide( &polySecond ) )
1338 {
1339 numErrors++;
1340
1341 SCH_SCREEN* screen = screenRuleAreas.first;
1342 SCH_SHEET_PATH firstSheet = screen->GetClientSheetPaths()[0];
1343
1344 std::shared_ptr<ERC_ITEM> ercItem =
1346 ercItem->SetItems( ruleAreas[i], ruleAreas[j] );
1347 ercItem->SetSheetSpecificPath( firstSheet );
1348 ercItem->SetItemsSheetPaths( firstSheet, firstSheet );
1349
1350 SCH_MARKER* marker = new SCH_MARKER( ercItem, ruleAreas[i]->GetPosition() );
1351 screen->Append( marker );
1352 }
1353 }
1354 }
1355 }
1356
1357 return numErrors;
1358}
1359
1360
1362 KIFACE* aCvPcb, PROJECT* aProject, PROGRESS_REPORTER* aProgressReporter )
1363{
1365
1366 // Test duplicate sheet names inside a given sheet. While one can have multiple references
1367 // to the same file, each must have a unique name.
1369 {
1370 if( aProgressReporter )
1371 aProgressReporter->AdvancePhase( _( "Checking sheet names..." ) );
1372
1374 }
1375
1377 {
1378 if( aProgressReporter )
1379 aProgressReporter->AdvancePhase( _( "Checking bus conflicts..." ) );
1380
1382 }
1383
1384 // The connection graph has a whole set of ERC checks it can run
1385 if( aProgressReporter )
1386 aProgressReporter->AdvancePhase( _( "Checking conflicts..." ) );
1387
1388 // If we are using the new connectivity, make sure that we do a full-rebuild
1389 if( aEditFrame )
1390 {
1391 if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
1392 aEditFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
1393 else
1394 aEditFrame->RecalculateConnections( nullptr, NO_CLEANUP );
1395 }
1396
1398
1399 if( aProgressReporter )
1400 aProgressReporter->AdvancePhase( _( "Checking rule areas..." ) );
1401
1403 {
1405 }
1406
1407 if( aProgressReporter )
1408 aProgressReporter->AdvancePhase( _( "Checking units..." ) );
1409
1410 // Test is all units of each multiunit symbol have the same footprint assigned.
1412 {
1413 if( aProgressReporter )
1414 aProgressReporter->AdvancePhase( _( "Checking footprints..." ) );
1415
1417 }
1418
1423 {
1425 }
1426
1427 if( aProgressReporter )
1428 aProgressReporter->AdvancePhase( _( "Checking pins..." ) );
1429
1432
1433 // Test pins on each net against the pin connection table
1437 {
1438 TestPinToPin();
1439 }
1440
1441 // Test similar labels (i;e. labels which are identical when
1442 // using case insensitive comparisons)
1444 {
1445 if( aProgressReporter )
1446 aProgressReporter->AdvancePhase( _( "Checking labels..." ) );
1447
1449 }
1450
1452 {
1453 if( aProgressReporter )
1454 aProgressReporter->AdvancePhase( _( "Checking for unresolved variables..." ) );
1455
1456 TestTextVars( aDrawingSheet );
1457 }
1458
1460 {
1461 if( aProgressReporter )
1462 aProgressReporter->AdvancePhase( _( "Checking SPICE models..." ) );
1463
1465 }
1466
1468 {
1469 if( aProgressReporter )
1470 aProgressReporter->AdvancePhase( _( "Checking no connect pins for connections..." ) );
1471
1473 }
1474
1477 {
1478 if( aProgressReporter )
1479 aProgressReporter->AdvancePhase( _( "Checking for library symbol issues..." ) );
1480
1482 }
1483
1485 {
1486 if( aProgressReporter )
1487 aProgressReporter->AdvancePhase( _( "Checking for footprint link issues..." ) );
1488
1489 TestFootprintLinkIssues( aCvPcb, aProject );
1490 }
1491
1493 {
1494 if( aProgressReporter )
1495 aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) );
1496
1498 }
1499
1501 {
1502 if( aProgressReporter )
1503 aProgressReporter->AdvancePhase( _( "Checking for four way junctions..." ) );
1504
1506 }
1507
1509 {
1510 if( aProgressReporter )
1511 aProgressReporter->AdvancePhase( _( "Checking for undefined netclasses..." ) );
1512
1514 }
1515
1517}
const char * name
Definition: DXF_plotter.cpp:57
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
int RunERC()
Run electrical rule checks on the connectivity graph.
A subgraph is a set of items that are electrically connected on a single sheet.
const std::set< SCH_ITEM * > & GetItems() const
Provide a read-only reference to the items in the subgraph.
const SCH_ITEM * GetNoConnect() const
const SCH_SHEET_PATH & GetSheet() const
Base class to handle basic graphic items.
Definition: ds_draw_item.h:59
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
Definition: ds_draw_item.h:401
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:262
A class used to associate a SCH_PIN with its owning SCH_SHEET_PATH, in order to handle ERC checks acr...
const SCH_SHEET_PATH & Sheet() const
Get the SCH_SHEET_PATH context for the paired SCH_PIN.
SCH_PIN * Pin() const
Get the SCH_PIN for this context.
bool IsTestEnabled(int aErrorCode) const
Definition: erc_settings.h:138
PIN_ERROR GetPinMapValue(int aFirstType, int aSecondType) const
Definition: erc_settings.h:149
int TestLibSymbolIssues()
Test symbols for changed library symbols and broken symbol library links.
Definition: erc.cpp:984
const NET_MAP & m_nets
Definition: erc.h:180
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:722
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition: erc.cpp:925
SCH_MULTI_UNIT_REFERENCE_MAP m_refMap
Definition: erc.h:179
SCH_SCREENS m_screens
Definition: erc.h:178
int RunRuleAreaERC()
Tests for rule area ERC issues.
Definition: erc.cpp:1296
int TestFootprintLinkIssues(KIFACE *aCvPcb, PROJECT *aProject)
Test footprint links against the current footprint libraries.
Definition: erc.cpp:1100
int TestOffGridEndpoints()
Test pins and wire ends for being off grid.
Definition: erc.cpp:1180
int TestDuplicateSheetNames(bool aCreateMarker)
Inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated).
Definition: erc.cpp:137
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition: erc.cpp:868
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:653
int TestRuleAreaOverlappingRuleAreasERC(std::map< SCH_SCREEN *, std::vector< SCH_RULE_AREA * > > &allScreenRuleAreas)
Runs ERC to check for overlapping rule areas.
Definition: erc.cpp:1320
ERC_SETTINGS & m_settings
Definition: erc.h:176
int TestFourWayJunction()
Test to see if there are potentially confusing 4-way junctions in the schematic.
Definition: erc.cpp:599
int TestMissingNetclasses()
Tests for netclasses that are referenced but not defined.
Definition: erc.cpp:546
int TestSimModelIssues()
Test SPICE models for various issues.
Definition: erc.cpp:1243
SCH_SHEET_LIST m_sheetList
Definition: erc.h:177
SCHEMATIC * m_schematic
Definition: erc.h:175
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition: erc.cpp:1361
int TestMissingUnits()
Test for uninstantiated units of multi unit symbols.
Definition: erc.cpp:409
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition: erc.cpp:348
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:845
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
Definition: lib_symbol.cpp:296
int GetUnitCount() const override
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
Definition: lib_symbol.cpp:340
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:829
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:289
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:153
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:90
Schematic editor (Eeschema) main window.
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
int GetBodyStyle() const
Definition: sch_item.h:232
@ EQUALITY
Definition: sch_item.h:660
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0) const override
Definition: sch_label.cpp:892
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:709
VECTOR2I GetEndPoint() const
Definition: sch_line.h:141
VECTOR2I GetStartPoint() const
Definition: sch_line.h:136
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
int GetUnit() const
SCH_SCREEN * GetNext()
SCH_SCREEN * GetFirst()
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:152
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
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
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:400
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:181
wxString GetShownName(bool aAllowExtraText) const
Definition: sch_sheet.h:103
Schematic symbol object.
Definition: sch_symbol.h: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:834
LIB_SYMBOL & GetLibSymbolRef()
Definition: sch_symbol.h:198
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:779
const LIB_ID & GetLibId() const override
Definition: sch_symbol.h:179
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:898
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:651
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.
#define _(s)
void CheckDuplicatePins(LIB_SYMBOL *aSymbol, std::vector< wxString > &aMessages, UNITS_PROVIDER *aUnitsProvider)
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_DUPLICATE_PIN_ERROR
Definition: erc_settings.h:92
@ 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:93
@ 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:94
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
Definition: erc_settings.h:101
@ 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
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< int32_t > VECTOR2I
Definition: vector2d.h:638