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