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