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
565 SCH_MARKER* marker = new SCH_MARKER( ercItem, unit->GetPosition() );
566 base_ref.GetSheetPath().LastScreen()->Append( marker );
567
568 ++errors;
569 };
570
571 for( int ii = 1; ii <= libSymbol->GetUnitCount(); ++ii )
572 lib_units.insert( lib_units.end(), ii );
573
574 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
575 instance_units.insert( instance_units.end(), refList.GetItem( ii ).GetUnit() );
576
577 std::set_difference( lib_units.begin(), lib_units.end(),
578 instance_units.begin(), instance_units.end(),
579 std::inserter( missing_units, missing_units.begin() ) );
580
581 if( !missing_units.empty() && m_settings.IsTestEnabled( ERCE_MISSING_UNIT ) )
582 {
583 report( missing_units, _( "Symbol %s has unplaced units %s" ), ERCE_MISSING_UNIT );
584 }
585
586 std::set<int> missing_power;
587 std::set<int> missing_input;
588 std::set<int> missing_bidi;
589
590 for( int missing_unit : missing_units )
591 {
592 int bodyStyle = 0;
593
594 for( size_t ii = 0; ii < refList.GetCount(); ++ii )
595 {
596 if( refList.GetItem( ii ).GetUnit() == missing_unit )
597 {
598 bodyStyle = refList.GetItem( ii ).GetSymbol()->GetBodyStyle();
599 break;
600 }
601 }
602
603 for( SCH_PIN* pin : libSymbol->GetPins( missing_unit, bodyStyle ) )
604 {
605 switch( pin->GetType() )
606 {
607 case ELECTRICAL_PINTYPE::PT_POWER_IN:
608 missing_power.insert( missing_unit );
609 break;
610
611 case ELECTRICAL_PINTYPE::PT_BIDI:
612 missing_bidi.insert( missing_unit );
613 break;
614
615 case ELECTRICAL_PINTYPE::PT_INPUT:
616 missing_input.insert( missing_unit );
617 break;
618
619 default:
620 break;
621 }
622 }
623 }
624
625 if( !missing_power.empty() && m_settings.IsTestEnabled( ERCE_MISSING_POWER_INPUT_PIN ) )
626 {
627 report( missing_power,
628 _( "Symbol %s has input power pins in units %s that are not placed." ),
630 }
631
632 if( !missing_input.empty() && m_settings.IsTestEnabled( ERCE_MISSING_INPUT_PIN ) )
633 {
634 report( missing_input,
635 _( "Symbol %s has input pins in units %s that are not placed." ),
637 }
638
639 if( !missing_bidi.empty() && m_settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
640 {
641 report( missing_bidi,
642 _( "Symbol %s has bidirectional pins in units %s that are not placed." ),
644 }
645 }
646
647 return errors;
648}
649
650
652{
653 int err_count = 0;
654 std::shared_ptr<NET_SETTINGS>& settings = m_schematic->Prj().GetProjectFile().NetSettings();
655 wxString defaultNetclass = settings->m_DefaultNetClass->GetName();
656
657 auto logError =
658 [&]( const SCH_SHEET_PATH& sheet, SCH_ITEM* item, const wxString& netclass )
659 {
660 err_count++;
661
662 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNDEFINED_NETCLASS );
663
664 ercItem->SetItems( item );
665 ercItem->SetErrorMessage( wxString::Format( _( "Netclass %s is not defined" ),
666 netclass ) );
667
668 SCH_MARKER* marker = new SCH_MARKER( ercItem, item->GetPosition() );
669 sheet.LastScreen()->Append( marker );
670 };
671
672 for( const SCH_SHEET_PATH& sheet : m_sheetList )
673 {
674 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
675 {
676 item->RunOnChildren(
677 [&]( SCH_ITEM* aChild )
678 {
679 if( aChild->Type() == SCH_FIELD_T )
680 {
681 SCH_FIELD* field = static_cast<SCH_FIELD*>( aChild );
682
683 if( field->GetCanonicalName() == wxT( "Netclass" ) )
684 {
685 wxString netclass = field->GetShownText( &sheet, false );
686
687 if( !netclass.IsSameAs( defaultNetclass )
688 && settings->m_NetClasses.count( netclass ) == 0 )
689 {
690 logError( sheet, item, netclass );
691 }
692 }
693 }
694
695 return true;
696 } );
697 }
698 }
699
700 return err_count;
701}
702
703
705{
706 int err_count = 0;
707
708 for( const SCH_SHEET_PATH& sheet : m_sheetList )
709 {
710 std::map<VECTOR2I, std::vector<SCH_ITEM*>> connMap;
711
712 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_LABEL_T ) )
713 {
714 SCH_LABEL* label = static_cast<SCH_LABEL*>( item );
715
716 for( const VECTOR2I& pt : label->GetConnectionPoints() )
717 connMap[pt].emplace_back( label );
718 }
719
720 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
721 {
722 std::vector<SCH_ITEM*> lines;
723
724 for( SCH_ITEM* item : sheet.LastScreen()->Items().Overlapping( SCH_LINE_T, pair.first ) )
725 {
726 SCH_LINE* line = static_cast<SCH_LINE*>( item );
727
728 if( line->IsGraphicLine() )
729 continue;
730
731 // If the line is connected at the endpoint, then there will be a junction
732 if( !line->IsEndPoint( pair.first ) )
733 lines.emplace_back( line );
734 }
735
736 if( lines.size() > 1 )
737 {
738 err_count++;
739 lines.resize( 3 ); // Only show the first 3 lines and if there are only two, adds a nullptr
740
741 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LABEL_MULTIPLE_WIRES );
742 wxString msg = wxString::Format( _( "Label connects more than one wire at %d, %d" ),
743 pair.first.x, pair.first.y );
744
745 ercItem->SetItems( pair.second.front(), lines[0], lines[1], lines[2] );
746 ercItem->SetErrorMessage( msg );
747 ercItem->SetSheetSpecificPath( sheet );
748
749 SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
750 sheet.LastScreen()->Append( marker );
751 }
752 }
753 }
754
755 return err_count;
756}
757
758
760{
761 int err_count = 0;
762
763 for( const SCH_SHEET_PATH& sheet : m_sheetList )
764 {
765 std::map<VECTOR2I, std::vector<SCH_ITEM*>> connMap;
766 SCH_SCREEN* screen = sheet.LastScreen();
767
768 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
769 {
770 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
771
772 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
773 connMap[pin->GetPosition()].emplace_back( pin );
774 }
775
776 for( SCH_ITEM* item : screen->Items().OfType( SCH_LINE_T ) )
777 {
778 SCH_LINE* line = static_cast<SCH_LINE*>( item );
779
780 if( line->IsGraphicLine() )
781 continue;
782
783 for( const VECTOR2I& pt : line->GetConnectionPoints() )
784 connMap[pt].emplace_back( line );
785 }
786
787 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
788 {
789 if( pair.second.size() >= 4 )
790 {
791 err_count++;
792
793 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOUR_WAY_JUNCTION );
794
795 ercItem->SetItems( pair.second[0], pair.second[1], pair.second[2], pair.second[3] );
796
797 wxString msg = wxString::Format( _( "Four items connected at %d, %d" ),
798 pair.first.x, pair.first.y );
799 ercItem->SetErrorMessage( msg );
800
801 ercItem->SetSheetSpecificPath( sheet );
802
803 SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
804 sheet.LastScreen()->Append( marker );
805 }
806 }
807 }
808
809 return err_count;
810}
811
812
814{
815 int err_count = 0;
816
817 for( const SCH_SHEET_PATH& sheet : m_sheetList )
818 {
819 std::map<VECTOR2I, std::vector<SCH_ITEM*>> pinMap;
820
821 auto addOther =
822 [&]( const VECTOR2I& pt, SCH_ITEM* aOther )
823 {
824 if( pinMap.count( pt ) )
825 pinMap[pt].emplace_back( aOther );
826 };
827
828 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
829 {
830 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
831
832 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
833 {
834 if( pin->GetLibPin()->GetType() == ELECTRICAL_PINTYPE::PT_NC )
835 pinMap[pin->GetPosition()].emplace_back( pin );
836 }
837 }
838
839 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
840 {
841 if( item->Type() == SCH_SYMBOL_T )
842 {
843 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
844
845 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
846 {
847 if( pin->GetLibPin()->GetType() != ELECTRICAL_PINTYPE::PT_NC )
848 addOther( pin->GetPosition(), pin );
849 }
850 }
851 else if( item->IsConnectable() )
852 {
853 for( const VECTOR2I& pt : item->GetConnectionPoints() )
854 addOther( pt, item );
855 }
856 }
857
858 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : pinMap )
859 {
860 if( pair.second.size() > 1 )
861 {
862 err_count++;
863
864 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED );
865
866 ercItem->SetItems( pair.second[0], pair.second[1],
867 pair.second.size() > 2 ? pair.second[2] : nullptr,
868 pair.second.size() > 3 ? pair.second[3] : nullptr );
869 ercItem->SetErrorMessage( _( "Pin with 'no connection' type is connected" ) );
870 ercItem->SetSheetSpecificPath( sheet );
871
872 SCH_MARKER* marker = new SCH_MARKER( ercItem, pair.first );
873 sheet.LastScreen()->Append( marker );
874 }
875 }
876 }
877
878 return err_count;
879}
880
881
883{
884 int errors = 0;
885
886 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
887 {
888 std::vector<ERC_SCH_PIN_CONTEXT> pins;
889 std::unordered_map<EDA_ITEM*, SCH_SCREEN*> pinToScreenMap;
890 bool has_noconnect = false;
891
892 for( CONNECTION_SUBGRAPH* subgraph: net.second )
893 {
894 if( subgraph->GetNoConnect() )
895 has_noconnect = true;
896
897 for( SCH_ITEM* item : subgraph->GetItems() )
898 {
899 if( item->Type() == SCH_PIN_T )
900 {
901 pins.emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
902 pinToScreenMap[item] = subgraph->GetSheet().LastScreen();
903 }
904 }
905 }
906
907 std::sort( pins.begin(), pins.end(),
908 []( const ERC_SCH_PIN_CONTEXT& lhs, const ERC_SCH_PIN_CONTEXT& rhs )
909 {
910 int ret = StrNumCmp( lhs.Pin()->GetParentSymbol()->GetRef( &lhs.Sheet() ),
911 rhs.Pin()->GetParentSymbol()->GetRef( &rhs.Sheet() ) );
912
913 if( ret == 0 )
914 ret = StrNumCmp( lhs.Pin()->GetNumber(), rhs.Pin()->GetNumber() );
915
916 if( ret == 0 )
917 ret = lhs < rhs; // Fallback to hash to guarantee deterministic sort
918
919 return ret < 0;
920 } );
921
922 ERC_SCH_PIN_CONTEXT needsDriver;
923 ELECTRICAL_PINTYPE needsDriverType = ELECTRICAL_PINTYPE::PT_UNSPECIFIED;
924 bool hasDriver = false;
925
926 // We need different drivers for power nets and normal nets.
927 // A power net has at least one pin having the ELECTRICAL_PINTYPE::PT_POWER_IN
928 // and power nets can be driven only by ELECTRICAL_PINTYPE::PT_POWER_OUT pins
929 bool ispowerNet = false;
930
931 for( ERC_SCH_PIN_CONTEXT& refPin : pins )
932 {
933 if( refPin.Pin()->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
934 {
935 ispowerNet = true;
936 break;
937 }
938 }
939
940 for( auto refIt = pins.begin(); refIt != pins.end(); ++refIt )
941 {
942 ERC_SCH_PIN_CONTEXT& refPin = *refIt;
943 ELECTRICAL_PINTYPE refType = refPin.Pin()->GetType();
944
945 if( DrivenPinTypes.contains( refType ) )
946 {
947 // needsDriver will be the pin shown in the error report eventually, so try to
948 // upgrade to a "better" pin if possible: something visible and only a power symbol
949 // if this net needs a power driver
950 if( !needsDriver.Pin()
951 || ( !needsDriver.Pin()->IsVisible() && refPin.Pin()->IsVisible() )
952 || ( ispowerNet != ( needsDriverType == ELECTRICAL_PINTYPE::PT_POWER_IN )
953 && ispowerNet == ( refType == ELECTRICAL_PINTYPE::PT_POWER_IN ) ) )
954 {
955 needsDriver = refPin;
956 needsDriverType = needsDriver.Pin()->GetType();
957 }
958 }
959
960 if( ispowerNet )
961 hasDriver |= ( DrivingPowerPinTypes.count( refType ) != 0 );
962 else
963 hasDriver |= ( DrivingPinTypes.count( refType ) != 0 );
964
965 for( auto testIt = refIt + 1; testIt != pins.end(); ++testIt )
966 {
967 ERC_SCH_PIN_CONTEXT& testPin = *testIt;
968
969 // Multiple pins in the same symbol that share a type,
970 // name and position are considered
971 // "stacked" and shouldn't trigger ERC errors
972 if( refPin.Pin()->IsStacked( testPin.Pin() ) && refPin.Sheet() == testPin.Sheet() )
973 continue;
974
975 ELECTRICAL_PINTYPE testType = testPin.Pin()->GetType();
976
977 if( ispowerNet )
978 hasDriver |= DrivingPowerPinTypes.contains( testType );
979 else
980 hasDriver |= DrivingPinTypes.contains( testType );
981
982 PIN_ERROR erc = m_settings.GetPinMapValue( refType, testType );
983
984 if( erc != PIN_ERROR::OK && m_settings.IsTestEnabled( ERCE_PIN_TO_PIN_WARNING ) )
985 {
986 std::shared_ptr<ERC_ITEM> ercItem =
987 ERC_ITEM::Create( erc == PIN_ERROR::WARNING ? ERCE_PIN_TO_PIN_WARNING :
989 ercItem->SetItems( refPin.Pin(), testPin.Pin() );
990 ercItem->SetSheetSpecificPath( refPin.Sheet() );
991 ercItem->SetItemsSheetPaths( refPin.Sheet(), testPin.Sheet() );
992
993 ercItem->SetErrorMessage(
994 wxString::Format( _( "Pins of type %s and %s are connected" ),
995 ElectricalPinTypeGetText( refType ),
996 ElectricalPinTypeGetText( testType ) ) );
997
998 SCH_MARKER* marker = new SCH_MARKER( ercItem, refPin.Pin()->GetPosition() );
999 pinToScreenMap[refPin.Pin()]->Append( marker );
1000 errors++;
1001 }
1002 }
1003 }
1004
1005 if( needsDriver.Pin() && !hasDriver && !has_noconnect )
1006 {
1007 int err_code = ispowerNet ? ERCE_POWERPIN_NOT_DRIVEN : ERCE_PIN_NOT_DRIVEN;
1008
1009 if( m_settings.IsTestEnabled( err_code ) )
1010 {
1011 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( err_code );
1012
1013 ercItem->SetItems( needsDriver.Pin() );
1014 ercItem->SetSheetSpecificPath( needsDriver.Sheet() );
1015 ercItem->SetItemsSheetPaths( needsDriver.Sheet() );
1016
1017 SCH_MARKER* marker = new SCH_MARKER( ercItem, needsDriver.Pin()->GetPosition() );
1018 pinToScreenMap[needsDriver.Pin()]->Append( marker );
1019 errors++;
1020 }
1021 }
1022 }
1023
1024 return errors;
1025}
1026
1027
1029{
1030 int errors = 0;
1031
1032 std::unordered_map<wxString, std::pair<wxString, SCH_PIN*>> pinToNetMap;
1033
1034 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1035 {
1036 const wxString& netName = net.first.Name;
1037
1038 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1039 {
1040 for( SCH_ITEM* item : subgraph->GetItems() )
1041 {
1042 if( item->Type() == SCH_PIN_T )
1043 {
1044 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1045 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1046
1047 if( !pin->GetLibPin()->GetParentSymbol()->IsMulti() )
1048 continue;
1049
1050 wxString name = pin->GetParentSymbol()->GetRef( &sheet ) +
1051 + ":" + pin->GetShownNumber();
1052
1053 if( !pinToNetMap.count( name ) )
1054 {
1055 pinToNetMap[name] = std::make_pair( netName, pin );
1056 }
1057 else if( pinToNetMap[name].first != netName )
1058 {
1059 std::shared_ptr<ERC_ITEM> ercItem =
1061
1062 ercItem->SetErrorMessage( wxString::Format(
1063 _( "Pin %s is connected to both %s and %s" ),
1064 pin->GetShownNumber(),
1065 netName,
1066 pinToNetMap[name].first ) );
1067
1068 ercItem->SetItems( pin, pinToNetMap[name].second );
1069 ercItem->SetSheetSpecificPath( sheet );
1070 ercItem->SetItemsSheetPaths( sheet, sheet );
1071
1072 SCH_MARKER* marker = new SCH_MARKER( ercItem, pin->GetPosition() );
1073 sheet.LastScreen()->Append( marker );
1074 errors += 1;
1075 }
1076 }
1077 }
1078 }
1079 }
1080
1081 return errors;
1082}
1083
1084
1086{
1087 int errors = 0;
1088 std::unordered_map<wxString, std::tuple<wxString, SCH_ITEM*, SCH_SHEET_PATH>> generalMap;
1089
1090 auto logError = [&]( const wxString& normalized, SCH_ITEM* item, const SCH_SHEET_PATH& sheet )
1091 {
1092 auto& [otherText, otherItem, otherSheet] = generalMap.at( normalized );
1093 ERCE_T typeOfWarning = ERCE_SIMILAR_LABELS;
1094
1095 if( item->Type() == SCH_PIN_T && otherItem->Type() == SCH_PIN_T )
1096 {
1097 //Two Pins
1098 typeOfWarning = ERCE_SIMILAR_POWER;
1099 }
1100 else if( item->Type() == SCH_PIN_T || otherItem->Type() == SCH_PIN_T )
1101 {
1102 //Pin and Label
1103 typeOfWarning = ERCE_SIMILAR_LABEL_AND_POWER;
1104 }
1105 else
1106 {
1107 //Two Labels
1108 typeOfWarning = ERCE_SIMILAR_LABELS;
1109 }
1110
1111 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( typeOfWarning );
1112 ercItem->SetItems( item, otherItem );
1113 ercItem->SetSheetSpecificPath( sheet );
1114 ercItem->SetItemsSheetPaths( sheet, otherSheet );
1115
1116 SCH_MARKER* marker = new SCH_MARKER( ercItem, item->GetPosition() );
1117 sheet.LastScreen()->Append( marker );
1118 };
1119
1120 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1121 {
1122 for( CONNECTION_SUBGRAPH* subgraph : net.second )
1123 {
1124 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
1125
1126 for( SCH_ITEM* item : subgraph->GetItems() )
1127 {
1128 switch( item->Type() )
1129 {
1130 case SCH_LABEL_T:
1131 case SCH_HIER_LABEL_T:
1132 case SCH_GLOBAL_LABEL_T:
1133 {
1134 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
1135 wxString unnormalized = label->GetShownText( &sheet, false );
1136 wxString normalized = unnormalized.Lower();
1137
1138 if( !generalMap.count( normalized ) )
1139 {
1140 generalMap[normalized] = std::make_tuple( unnormalized, label, sheet );
1141 }
1142
1143 auto& [otherText, otherItem, otherSheet] = generalMap.at( normalized );
1144
1145 if( unnormalized != otherText )
1146 {
1147 logError( normalized, label, sheet );
1148 errors += 1;
1149 }
1150
1151 break;
1152 }
1153 case SCH_PIN_T:
1154 {
1155 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1156
1157 if( !pin->IsGlobalPower() )
1158 {
1159 continue;
1160 }
1161
1162 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
1163 wxString unnormalized = symbol->GetValue( true, &sheet, false );
1164 wxString normalized = unnormalized.Lower();
1165
1166 if( !generalMap.count( normalized ) )
1167 {
1168 generalMap[normalized] = std::make_tuple( unnormalized, pin, sheet );
1169 }
1170
1171 auto& [otherText, otherItem, otherSheet] = generalMap.at( normalized );
1172
1173 if( unnormalized != otherText )
1174 {
1175 logError( normalized, pin, sheet );
1176 errors += 1;
1177 }
1178
1179 break;
1180 }
1181
1182 default:
1183 break;
1184 }
1185 }
1186 }
1187 }
1188 return errors;
1189}
1190
1191
1193{
1194 wxCHECK( m_schematic, 0 );
1195
1197 wxString msg;
1198 int err_count = 0;
1199
1200 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
1201 {
1202 std::vector<SCH_MARKER*> markers;
1203
1204 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1205 {
1206 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1207 LIB_SYMBOL* libSymbolInSchematic = symbol->GetLibSymbolRef().get();
1208
1209 wxCHECK2( libSymbolInSchematic, continue );
1210
1211 wxString libName = symbol->GetLibId().GetLibNickname();
1212 LIB_TABLE_ROW* libTableRow = libTable->FindRow( libName, true );
1213
1214 if( !libTableRow )
1215 {
1217 {
1218 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1219 ercItem->SetItems( symbol );
1220 msg.Printf( _( "The current configuration does not include the symbol library '%s'" ),
1221 UnescapeString( libName ) );
1222 ercItem->SetErrorMessage( msg );
1223
1224 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1225 }
1226
1227 continue;
1228 }
1229 else if( !libTable->HasLibrary( libName, true ) )
1230 {
1232 {
1233 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1234 ercItem->SetItems( symbol );
1235 msg.Printf( _( "The library '%s' is not enabled in the current configuration" ),
1236 UnescapeString( libName ) );
1237 ercItem->SetErrorMessage( msg );
1238
1239 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1240 }
1241
1242 continue;
1243 }
1244
1245 wxString symbolName = symbol->GetLibId().GetLibItemName();
1246 LIB_SYMBOL* libSymbol = SchGetLibSymbol( symbol->GetLibId(), libTable );
1247
1248 if( libSymbol == nullptr )
1249 {
1251 {
1252 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_ISSUES );
1253 ercItem->SetItems( symbol );
1254 msg.Printf( _( "Symbol '%s' not found in symbol library '%s'" ),
1255 UnescapeString( symbolName ),
1256 UnescapeString( libName ) );
1257 ercItem->SetErrorMessage( msg );
1258
1259 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1260 }
1261
1262 continue;
1263 }
1264
1265 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->Flatten();
1267
1269 {
1270 // We have to check for duplicate pins first as they will cause Compare() to fail.
1271 std::vector<wxString> messages;
1272 UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILS );
1273 CheckDuplicatePins( libSymbolInSchematic, messages, &unitsProvider );
1274
1275 if( !messages.empty() )
1276 {
1277 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DUPLICATE_PIN_ERROR );
1278 ercItem->SetItems( symbol );
1279 msg.Printf( _( "Symbol '%s' has multiple pins with the same pin number" ),
1280 UnescapeString( symbolName ) );
1281 ercItem->SetErrorMessage( msg );
1282
1283 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1284 }
1285 else if( flattenedSymbol->Compare( *libSymbolInSchematic, flags ) != 0 )
1286 {
1287 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LIB_SYMBOL_MISMATCH );
1288 ercItem->SetItems( symbol );
1289 msg.Printf( _( "Symbol '%s' doesn't match copy in library '%s'" ),
1290 UnescapeString( symbolName ),
1291 UnescapeString( libName ) );
1292 ercItem->SetErrorMessage( msg );
1293
1294 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1295 }
1296 }
1297 }
1298
1299 for( SCH_MARKER* marker : markers )
1300 {
1301 screen->Append( marker );
1302 err_count += 1;
1303 }
1304 }
1305
1306 return err_count;
1307}
1308
1309
1311{
1312 wxCHECK( m_schematic, 0 );
1313
1314 wxString msg;
1315 int err_count = 0;
1316
1317 typedef int (*TESTER_FN_PTR)( const wxString&, PROJECT* );
1318
1319 TESTER_FN_PTR linkTester = (TESTER_FN_PTR) aCvPcb->IfaceOrAddress( KIFACE_TEST_FOOTPRINT_LINK );
1320
1321 for( SCH_SHEET_PATH& sheet : m_sheetList )
1322 {
1323 std::vector<SCH_MARKER*> markers;
1324
1325 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1326 {
1327 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1328 wxString footprint = symbol->GetFootprintFieldText( true, &sheet, false );
1329
1330 if( footprint.IsEmpty() )
1331 continue;
1332
1333 LIB_ID fpID;
1334
1335 if( fpID.Parse( footprint, true ) >= 0 )
1336 {
1337 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1338 msg.Printf( _( "'%s' is not a valid footprint identifier." ), footprint );
1339 ercItem->SetErrorMessage( msg );
1340 ercItem->SetItems( symbol );
1341 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1342 continue;
1343 }
1344
1345 wxString libName = fpID.GetLibNickname();
1346 wxString fpName = fpID.GetLibItemName();
1347 int ret = (linkTester)( footprint, aProject );
1348
1350 {
1351 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1352 msg.Printf( _( "The current configuration does not include the footprint library '%s'." ),
1353 libName );
1354 ercItem->SetErrorMessage( msg );
1355 ercItem->SetItems( symbol );
1356 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1357 }
1359 {
1360 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1361 msg.Printf( _( "The footprint library '%s' is not enabled in the current configuration." ),
1362 libName );
1363 ercItem->SetErrorMessage( msg );
1364 ercItem->SetItems( symbol );
1365 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1366 }
1368 {
1369 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOOTPRINT_LINK_ISSUES );
1370 msg.Printf( _( "Footprint '%s' not found in library '%s'." ),
1371 fpName,
1372 libName );
1373 ercItem->SetErrorMessage( msg );
1374 ercItem->SetItems( symbol );
1375 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1376 }
1377 }
1378
1379 for( SCH_MARKER* marker : markers )
1380 {
1381 sheet.LastScreen()->Append( marker );
1382 err_count += 1;
1383 }
1384 }
1385
1386 return err_count;
1387}
1388
1389
1391{
1392 const int gridSize = m_schematic->Settings().m_ConnectionGridSize;
1393 int err_count = 0;
1394
1395 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
1396 {
1397 std::vector<SCH_MARKER*> markers;
1398
1399 for( SCH_ITEM* item : screen->Items() )
1400 {
1401 if( item->Type() == SCH_LINE_T && item->IsConnectable() )
1402 {
1403 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1404
1405 if( ( line->GetStartPoint().x % gridSize ) != 0
1406 || ( line->GetStartPoint().y % gridSize ) != 0 )
1407 {
1408 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1409 ercItem->SetItems( line );
1410
1411 markers.emplace_back( new SCH_MARKER( ercItem, line->GetStartPoint() ) );
1412 }
1413 else if( ( line->GetEndPoint().x % gridSize ) != 0
1414 || ( line->GetEndPoint().y % gridSize ) != 0 )
1415 {
1416 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1417 ercItem->SetItems( line );
1418
1419 markers.emplace_back( new SCH_MARKER( ercItem, line->GetEndPoint() ) );
1420 }
1421 }
1422 else if( item->Type() == SCH_SYMBOL_T )
1423 {
1424 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1425
1426 for( SCH_PIN* pin : symbol->GetPins( nullptr ) )
1427 {
1428 VECTOR2I pinPos = pin->GetPosition();
1429
1430 if( ( pinPos.x % gridSize ) != 0 || ( pinPos.y % gridSize ) != 0 )
1431 {
1432 auto ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
1433 ercItem->SetItems( pin );
1434
1435 markers.emplace_back( new SCH_MARKER( ercItem, pinPos ) );
1436 break;
1437 }
1438 }
1439 }
1440 }
1441
1442 for( SCH_MARKER* marker : markers )
1443 {
1444 screen->Append( marker );
1445 err_count += 1;
1446 }
1447 }
1448
1449 return err_count;
1450}
1451
1452
1454{
1455 wxString msg;
1456 WX_STRING_REPORTER reporter( &msg );
1457 int err_count = 0;
1458 SIM_LIB_MGR libMgr( &m_schematic->Prj() );
1459
1460 for( SCH_SHEET_PATH& sheet : m_sheetList )
1461 {
1462 if( sheet.GetExcludedFromSim() )
1463 continue;
1464
1465 std::vector<SCH_MARKER*> markers;
1466
1467 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1468 {
1469 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1470
1471 // Power symbols and other symbols which have the reference starting with "#" are
1472 // not included in simulation
1473 if( symbol->GetRef( &sheet ).StartsWith( '#' ) || symbol->GetExcludedFromSim() )
1474 continue;
1475
1476 // Reset for each symbol
1477 msg.Clear();
1478
1479 SIM_LIBRARY::MODEL model = libMgr.CreateModel( &sheet, *symbol, reporter );
1480
1481 if( !msg.IsEmpty() )
1482 {
1483 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMULATION_MODEL );
1484
1485 //Remove \n and \r at e.o.l if any:
1486 msg.Trim();
1487
1488 ercItem->SetErrorMessage( msg );
1489 ercItem->SetItems( symbol );
1490
1491 markers.emplace_back( new SCH_MARKER( ercItem, symbol->GetPosition() ) );
1492 }
1493 }
1494
1495 for( SCH_MARKER* marker : markers )
1496 {
1497 sheet.LastScreen()->Append( marker );
1498 err_count += 1;
1499 }
1500 }
1501
1502 return err_count;
1503}
1504
1505
1507{
1508 int numErrors = 0;
1509
1511 return 0;
1512
1513 std::map<SCH_SCREEN*, std::vector<SCH_RULE_AREA*>> allScreenRuleAreas;
1514
1515 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
1516 {
1517 for( SCH_ITEM* item : screen->Items().OfType( SCH_RULE_AREA_T ) )
1518 {
1519 allScreenRuleAreas[screen].push_back( static_cast<SCH_RULE_AREA*>( item ) );
1520 }
1521 }
1522
1524 numErrors += TestRuleAreaOverlappingRuleAreasERC( allScreenRuleAreas );
1525
1526 return numErrors;
1527}
1528
1529
1531 std::map<SCH_SCREEN*, std::vector<SCH_RULE_AREA*>>& allScreenRuleAreas )
1532{
1533 int numErrors = 0;
1534
1535 for( auto screenRuleAreas : allScreenRuleAreas )
1536 {
1537 std::vector<SCH_RULE_AREA*>& ruleAreas = screenRuleAreas.second;
1538
1539 for( std::size_t i = 0; i < ruleAreas.size(); ++i )
1540 {
1541 SHAPE_POLY_SET& polyFirst = ruleAreas[i]->GetPolyShape();
1542
1543 for( std::size_t j = i + 1; j < ruleAreas.size(); ++j )
1544 {
1545 SHAPE_POLY_SET polySecond = ruleAreas[j]->GetPolyShape();
1546
1547 if( polyFirst.Collide( &polySecond ) )
1548 {
1549 numErrors++;
1550
1551 SCH_SCREEN* screen = screenRuleAreas.first;
1552 SCH_SHEET_PATH firstSheet = screen->GetClientSheetPaths()[0];
1553
1554 std::shared_ptr<ERC_ITEM> ercItem =
1556 ercItem->SetItems( ruleAreas[i], ruleAreas[j] );
1557 ercItem->SetSheetSpecificPath( firstSheet );
1558 ercItem->SetItemsSheetPaths( firstSheet, firstSheet );
1559
1560 SCH_MARKER* marker = new SCH_MARKER( ercItem, ruleAreas[i]->GetPosition() );
1561 screen->Append( marker );
1562 }
1563 }
1564 }
1565 }
1566
1567 return numErrors;
1568}
1569
1570
1572 KIFACE* aCvPcb, PROJECT* aProject, PROGRESS_REPORTER* aProgressReporter )
1573{
1575
1576 // Test duplicate sheet names inside a given sheet. While one can have multiple references
1577 // to the same file, each must have a unique name.
1579 {
1580 if( aProgressReporter )
1581 aProgressReporter->AdvancePhase( _( "Checking sheet names..." ) );
1582
1584 }
1585
1587 {
1588 if( aProgressReporter )
1589 aProgressReporter->AdvancePhase( _( "Checking bus conflicts..." ) );
1590
1592 }
1593
1594 // The connection graph has a whole set of ERC checks it can run
1595 if( aProgressReporter )
1596 aProgressReporter->AdvancePhase( _( "Checking conflicts..." ) );
1597
1598 // If we are using the new connectivity, make sure that we do a full-rebuild
1599 if( aEditFrame )
1600 {
1601 if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
1602 aEditFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
1603 else
1604 aEditFrame->RecalculateConnections( nullptr, NO_CLEANUP );
1605 }
1606
1608
1609 if( aProgressReporter )
1610 aProgressReporter->AdvancePhase( _( "Checking rule areas..." ) );
1611
1613 {
1615 }
1616
1617 if( aProgressReporter )
1618 aProgressReporter->AdvancePhase( _( "Checking units..." ) );
1619
1620 // Test is all units of each multiunit symbol have the same footprint assigned.
1622 {
1623 if( aProgressReporter )
1624 aProgressReporter->AdvancePhase( _( "Checking footprints..." ) );
1625
1627 }
1628
1633 {
1635 }
1636
1637 if( aProgressReporter )
1638 aProgressReporter->AdvancePhase( _( "Checking pins..." ) );
1639
1642
1643 // Test pins on each net against the pin connection table
1647 {
1648 TestPinToPin();
1649 }
1650
1651 // Test similar labels (i;e. labels which are identical when
1652 // using case insensitive comparisons)
1656 {
1657 if( aProgressReporter )
1658 aProgressReporter->AdvancePhase( _( "Checking labels..." ) );
1659
1661 }
1662
1664 {
1665 if( aProgressReporter )
1666 aProgressReporter->AdvancePhase( _( "Checking for unresolved variables..." ) );
1667
1668 TestTextVars( aDrawingSheet );
1669 }
1670
1672 {
1673 if( aProgressReporter )
1674 aProgressReporter->AdvancePhase( _( "Checking SPICE models..." ) );
1675
1677 }
1678
1680 {
1681 if( aProgressReporter )
1682 aProgressReporter->AdvancePhase( _( "Checking no connect pins for connections..." ) );
1683
1685 }
1686
1689 {
1690 if( aProgressReporter )
1691 aProgressReporter->AdvancePhase( _( "Checking for library symbol issues..." ) );
1692
1694 }
1695
1697 {
1698 if( aProgressReporter )
1699 aProgressReporter->AdvancePhase( _( "Checking for footprint link issues..." ) );
1700
1701 TestFootprintLinkIssues( aCvPcb, aProject );
1702 }
1703
1705 {
1706 if( aProgressReporter )
1707 aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) );
1708
1710 }
1711
1713 {
1714 if( aProgressReporter )
1715 aProgressReporter->AdvancePhase( _( "Checking for four way junctions..." ) );
1716
1718 }
1719
1721 {
1722 if( aProgressReporter )
1723 aProgressReporter->AdvancePhase( _( "Checking for labels on more than one wire..." ) );
1724
1726 }
1727
1729 {
1730 if( aProgressReporter )
1731 aProgressReporter->AdvancePhase( _( "Checking for undefined netclasses..." ) );
1732
1734 }
1735
1737}
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:294
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:143
PIN_ERROR GetPinMapValue(int aFirstType, int aSecondType) const
Definition: erc_settings.h:154
int TestLibSymbolIssues()
Test symbols for changed library symbols and broken symbol library links.
Definition: erc.cpp:1192
const NET_MAP & m_nets
Definition: erc.h:185
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:882
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition: erc.cpp:1085
SCH_MULTI_UNIT_REFERENCE_MAP m_refMap
Definition: erc.h:184
SCH_SCREENS m_screens
Definition: erc.h:183
int RunRuleAreaERC()
Tests for rule area ERC issues.
Definition: erc.cpp:1506
int TestFootprintLinkIssues(KIFACE *aCvPcb, PROJECT *aProject)
Test footprint links against the current footprint libraries.
Definition: erc.cpp:1310
int TestOffGridEndpoints()
Test pins and wire ends for being off grid.
Definition: erc.cpp:1390
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 TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition: erc.cpp:1028
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:813
int TestRuleAreaOverlappingRuleAreasERC(std::map< SCH_SCREEN *, std::vector< SCH_RULE_AREA * > > &allScreenRuleAreas)
Runs ERC to check for overlapping rule areas.
Definition: erc.cpp:1530
ERC_SETTINGS & m_settings
Definition: erc.h:181
int TestFourWayJunction()
Test to see if there are potentially confusing 4-way junctions in the schematic.
Definition: erc.cpp:759
int TestMissingNetclasses()
Tests for netclasses that are referenced but not defined.
Definition: erc.cpp:651
int TestSimModelIssues()
Test SPICE models for various issues.
Definition: erc.cpp:1453
SCH_SHEET_LIST m_sheetList
Definition: erc.h:182
SCHEMATIC * m_schematic
Definition: erc.h:180
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition: erc.cpp:1571
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:704
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 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:809
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:101
static SYMBOL_LIB_TABLE * SchSymbolLibTable(PROJECT *aProject)
Accessor for project symbol library table.
Container for project specific data.
Definition: project.h:62
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:166
void ResolveERCExclusionsPostUpdate()
Update markers to match recorded exclusions.
Definition: schematic.cpp: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:709
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:970
bool IsVisible() const
Definition: sch_pin.cpp:340
VECTOR2I GetPosition() const override
Definition: sch_pin.cpp:237
bool IsStacked(const SCH_PIN *aPin) const
Definition: sch_pin.cpp:374
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:291
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
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
std::vector< SCH_SHEET_PATH > & GetClientSheetPaths()
Return the number of times this screen is used.
Definition: sch_screen.h:177
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:108
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:93
VECTOR2I GetPosition() const override
Definition: sch_sheet.h:400
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:181
wxString GetShownName(bool aAllowExtraText) const
Definition: sch_sheet.h:103
Schematic symbol object.
Definition: sch_symbol.h:105
const wxString GetValue(bool aResolve, const SCH_SHEET_PATH *aPath, bool aAllowExtraText) const override
Definition: sch_symbol.cpp:887
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:903
VECTOR2I GetPosition() const override
Definition: sch_symbol.h:802
const LIB_ID & GetLibId() const override
Definition: sch_symbol.h:194
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:967
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:213
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:720
Represent a set of closed polygons.
bool Collide(const SHAPE *aShape, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the shape aShape than aClearance,...
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
SYMBOL_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an SYMBOL_LIB_TABLE_ROW if aNickName is found in this table or in any chained fallBack table f...
bool GetExcludedFromSim() const override
Definition: symbol.h:136
A wrapper for reporting to a wxString object.
Definition: reporter.h:164
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp: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_OVERLAPPING_RULE_AREAS
Rule areas are overlapping.
Definition: erc_settings.h:72
@ 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:57
@ 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_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:80
@ ERCE_DUPLICATE_PIN_ERROR
Definition: erc_settings.h:95
@ ERCE_DIFFERENT_UNIT_NET
Shared pin in a multi-unit symbol is connected to more than one net.
Definition: erc_settings.h:62
@ 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:75
@ ERCE_UNRESOLVED_VARIABLE
A text variable could not be resolved.
Definition: erc_settings.h:74
@ ERCE_SIMULATION_MODEL
An error was found in the simulation model.
Definition: erc_settings.h:76
@ ERCE_LIB_SYMBOL_MISMATCH
Symbol doesn't match copy in library.
Definition: erc_settings.h:79
@ ERCE_GENERIC_ERROR
Definition: erc_settings.h:101
@ ERCE_DIFFERENT_UNIT_FP
Different units of the same symbol have different footprints assigned.
Definition: erc_settings.h:55
@ 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:96
@ 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:59
@ ERCE_MISSING_UNIT
Symbol has units that are not placed on the schematic.
Definition: erc_settings.h:61
@ 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:60
@ ERCE_LIB_SYMBOL_ISSUES
Symbol not found in active libraries.
Definition: erc_settings.h:78
@ ERCE_BUS_ALIAS_CONFLICT
Conflicting bus alias definitions across sheets.
Definition: erc_settings.h:64
@ ERCE_GENERIC_WARNING
Definition: erc_settings.h:100
@ 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:97
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
Definition: erc_settings.h:106
@ KIFACE_TEST_FOOTPRINT_LINK_LIBRARY_NOT_ENABLED
Definition: kiface_ids.h:62
@ KIFACE_TEST_FOOTPRINT_LINK
Definition: kiface_ids.h:60
@ KIFACE_TEST_FOOTPRINT_LINK_NO_LIBRARY
Definition: kiface_ids.h:61
@ KIFACE_TEST_FOOTPRINT_LINK_NO_FOOTPRINT
Definition: kiface_ids.h:63
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE aType)
Definition: pin_type.cpp:207
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:36
@ PT_INPUT
usual pin input: must be connected
@ PT_OUTPUT
usual output
@ PT_TRISTATE
tris state bus pin
@ PT_BIDI
input or output (like port for a microprocessor)
@ PT_POWER_OUT
output of a regulator: intended to be connected to power input pins
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin
LIB_SYMBOL * SchGetLibSymbol(const LIB_ID &aLibId, SYMBOL_LIB_TABLE *aLibTable, SYMBOL_LIB *aCacheLib, wxWindow *aParent, bool aShowErrorMsg)
Load symbol from symbol library table.
@ NO_CLEANUP
@ GLOBAL_CLEANUP
wxString UnescapeString(const wxString &aSource)
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151
virtual void * IfaceOrAddress(int aDataId)=0
Return pointer to the requested object.
@ SCH_LINE_T
Definition: typeinfo.h:163
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ SCH_FIELD_T
Definition: typeinfo.h:150
@ SCH_LABEL_T
Definition: typeinfo.h:167
@ SCH_LOCATE_ANY_T
Definition: typeinfo.h:198
@ SCH_SHEET_T
Definition: typeinfo.h:174
@ SCH_RULE_AREA_T
Definition: typeinfo.h:170
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:169
@ SCH_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:673