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