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 The 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, see <https://www.gnu.org/licenses/>.
20 */
21
22#include <algorithm>
23#include <map>
24#include <numeric>
25#include <set>
26
27#include "connection_graph.h"
28#include <kiface_services.h>
29#include <advanced_config.h>
31#include <common.h> // for ExpandEnvVarSubstitutions
32#include <erc/erc.h>
35#include <string_utils.h>
36#include <sch_pin.h>
38#include <sch_netchain.h>
39#include <project_sch.h>
42#include <sch_bus_entry.h>
43#include <sch_edit_frame.h>
44#include <sch_marker.h>
45#include <sch_reference_list.h>
46#include <sch_rule_area.h>
47#include <sch_sheet.h>
48#include <sch_sheet_pin.h>
49#include <sch_pin.h>
50#include <sch_textbox.h>
51#include <sch_line.h>
52#include <schematic.h>
53#include <lib_symbol.h>
54#include <sch_symbol.h>
55#include <pin_map.h>
58#include <vector>
59#include <optional>
60#include <wx/ffile.h>
61#include <sim/sim_lib_mgr.h>
62#include <progress_reporter.h>
63#include <kiway.h>
64#include <pgm_base.h>
66#include <trace_helpers.h>
68
69namespace
70{
71// Item paths participate in saved exclusion keys; preserve each check's serialized shape
72enum class ITEM_PATHS
73{
74 NONE,
75 MAIN,
76 BOTH
77};
78
79// Capture membership before the first marker; checks may insert markers while traversing the result
80class ERC_MARKER_PLACER
81{
82public:
83 explicit ERC_MARKER_PLACER( const SCHEMATIC& aSchematic ) :
84 m_schematic( aSchematic )
85 {
86 }
87
88 const SCH_SHEET_PATH* Find( const KIID_PATH& aSheet )
89 {
90 if( !m_paths )
91 {
92 m_hierarchy = m_schematic.Hierarchy();
93 m_paths.emplace();
94
95 for( const SCH_SHEET_PATH& path : m_hierarchy )
96 m_paths->emplace( path.PathRef(), &path );
97 }
98
99 if( const auto found = m_paths->find( aSheet ); found != m_paths->end() )
100 return found->second;
101
102 wxLogTrace( "KICAD_CONNECTIVITY", "ERC connectivity references unknown sheet instance %s", aSheet.AsString() );
103 return nullptr;
104 }
105
106 void Place( std::shared_ptr<ERC_ITEM> aItem, const KIID_PATH& aSheet, const VECTOR2I& aPosition,
107 ITEM_PATHS aItemPaths = ITEM_PATHS::NONE, bool aSheetSpecific = true )
108 {
109 const SCH_SHEET_PATH* sheet = Find( aSheet );
110
111 if( !sheet )
112 return;
113
114 if( aItemPaths == ITEM_PATHS::BOTH && aItem->GetAuxItemID() != niluuid )
115 aItem->SetItemsSheetPaths( *sheet, *sheet );
116 else if( aItemPaths != ITEM_PATHS::NONE )
117 aItem->SetItemsSheetPaths( *sheet );
118
119 append( std::move( aItem ), *sheet, aPosition, aSheetSpecific );
120 }
121
122 void Place( std::shared_ptr<ERC_ITEM> aItem, const KIID_PATH& aSheet, const VECTOR2I& aPosition,
123 const KIID_PATH& aMainItemSheet, const KIID_PATH& aAuxItemSheet )
124 {
125 const SCH_SHEET_PATH* sheet = Find( aSheet );
126 const SCH_SHEET_PATH* main = Find( aMainItemSheet );
127 const SCH_SHEET_PATH* aux = Find( aAuxItemSheet );
128
129 if( !sheet || !main || !aux )
130 return;
131
132 aItem->SetItemsSheetPaths( *main, *aux );
133 append( std::move( aItem ), *sheet, aPosition );
134 }
135
136 void Report( int aCode, const std::vector<KIID>& aItems, const KIID_PATH& aSheet, const VECTOR2I& aPosition,
137 ITEM_PATHS aItemPaths = ITEM_PATHS::NONE, const wxString& aMessage = wxEmptyString )
138 {
139 auto item = ERC_ITEM::Create( aCode );
140 item->SetItems( aItems );
141
142 if( !aMessage.empty() )
143 item->SetErrorMessage( aMessage );
144
145 Place( std::move( item ), aSheet, aPosition, aItemPaths );
146 }
147
148 int Count() const { return m_count; }
149
150private:
151 void append( std::shared_ptr<ERC_ITEM> aItem, const SCH_SHEET_PATH& aSheet, const VECTOR2I& aPosition,
152 bool aSheetSpecific = true )
153 {
154 if( aSheetSpecific )
155 aItem->SetSheetSpecificPath( aSheet );
156
157 aSheet.LastScreen()->Append( new SCH_MARKER( std::move( aItem ), aPosition ) );
158 ++m_count;
159 }
160
161 const SCHEMATIC& m_schematic;
162 SCH_SHEET_LIST m_hierarchy;
163 std::optional<std::map<KIID_PATH, const SCH_SHEET_PATH*>> m_paths;
164 int m_count = 0;
165};
166
167std::vector<SCH_CONNECTIVITY::FOOTPRINT_SOURCE> collectFootprints( SCHEMATIC& aSchematic )
168{
169 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
170 return aSchematic.Connectivity().Engine().FootprintSources();
171
172 std::vector<SCH_CONNECTIVITY::FOOTPRINT_SOURCE> result;
173
174 for( const SCH_SHEET_PATH& path : aSchematic.Hierarchy() )
175 {
176 for( SCH_ITEM* item : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
177 {
178 const auto& symbol = *static_cast<SCH_SYMBOL*>( item );
179 const auto& library = symbol.GetLibSymbolRef();
180 result.push_back( { path.PathRef(), symbol.m_Uuid, symbol.GetPosition(),
181 symbol.GetFootprintFieldText( &path, RESOLVED ),
182 library ? library->GetFPFilters() : wxArrayString() } );
183 }
184 }
185
186 return result;
187}
188
189template <typename LOCATION>
190int reportSourceErrors( SCHEMATIC& aSchematic, int aCode, const std::vector<LOCATION>& aSources )
191{
192 ERC_MARKER_PLACER markers( aSchematic );
193
194 for( const auto& source : aSources )
195 markers.Report( aCode, { source.item }, source.sheet, source.position, ITEM_PATHS::MAIN );
196
197 return markers.Count();
198}
199
200std::vector<SCH_CONNECTIVITY::NAMED_ITEM> collectNamedItems( SCHEMATIC& aSchematic, bool aSimilar )
201{
202 // The engine compares resolved net names for every power pin, including hidden and alternate pins
203 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
204 return aSchematic.Connectivity().Engine().NamedItems();
205
206 std::vector<SCH_CONNECTIVITY::NAMED_ITEM> result;
207
208 for( const auto& [key, subgraphs] : aSchematic.ConnectionGraph()->GetNetMap() )
209 {
210 for( const CONNECTION_SUBGRAPH* subgraph : subgraphs )
211 {
212 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
213
214 for( SCH_ITEM* item : subgraph->GetItems() )
215 {
216 if( item->Type() == SCH_LABEL_T || item->Type() == SCH_GLOBAL_LABEL_T
217 || item->Type() == SCH_HIER_LABEL_T )
218 {
219 auto* label = static_cast<SCH_LABEL_BASE*>( item );
220 result.push_back( { sheet.PathRef(), item->m_Uuid, item->GetPosition(),
221 label->GetShownText( &sheet, FOR_NETNAME ), item->Type(),
222 item->Type() == SCH_GLOBAL_LABEL_T } );
223 }
224 else if( item->Type() == SCH_PIN_T )
225 {
226 auto* pin = static_cast<SCH_PIN*>( item );
227 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( pin->GetParentSymbol() );
228
229 if( !pin->IsPower() || !symbol )
230 continue;
231
232 const wxString name = !aSimilar && pin->IsGlobalPower() && !symbol->IsGlobalPower()
233 ? pin->GetShownName() : symbol->GetValue( &sheet, FOR_NETNAME );
234 result.push_back( { sheet.PathRef(), item->m_Uuid, item->GetPosition(), name,
235 SCH_PIN_T, pin->IsGlobalPower() } );
236 }
237 }
238 }
239 }
240
241 return result;
242}
243
244void reportNameConflict( ERC_MARKER_PLACER& aMarkers, ERC_SETTINGS& aSettings, ERCE_T aCode,
246{
247 if( !aSettings.IsTestEnabled( aCode ) )
248 return;
249
250 auto item = ERC_ITEM::Create( aCode );
251 item->SetItems( aMain.item, aAux.item );
252 aMarkers.Place( std::move( item ), aMain.sheet, aMain.position, aMain.sheet, aAux.sheet );
253}
254
255}
256
257
258/* ERC tests :
259 * 1 - conflicts between connected pins ( example: 2 connected outputs )
260 * 2 - minimal connections requirements ( 1 input *must* be connected to an
261 * output, or a passive pin )
262 */
263
264/*
265 * Minimal ERC requirements:
266 * All pins *must* be connected (except ELECTRICAL_PINTYPE::PT_NC).
267 * When a pin is not connected in schematic, the user must place a "non
268 * connected" symbol to this pin.
269 * This ensures a forgotten connection will be detected.
270 */
271
272// Messages for matrix rows:
273const wxString CommentERC_H[] =
274{
275 _( "Input Pin" ),
276 _( "Output Pin" ),
277 _( "Bidirectional Pin" ),
278 _( "Tri-State Pin" ),
279 _( "Passive Pin" ),
280 _( "Free Pin" ),
281 _( "Unspecified Pin" ),
282 _( "Power Input Pin" ),
283 _( "Power Output Pin" ),
284 _( "Open Collector" ),
285 _( "Open Emitter" ),
286 _( "No Connection" )
287};
288
289// Messages for matrix columns
290const wxString CommentERC_V[] =
291{
292 _( "Input Pin" ),
293 _( "Output Pin" ),
294 _( "Bidirectional Pin" ),
295 _( "Tri-State Pin" ),
296 _( "Passive Pin" ),
297 _( "Free Pin" ),
298 _( "Unspecified Pin" ),
299 _( "Power Input Pin" ),
300 _( "Power Output Pin" ),
301 _( "Open Collector" ),
302 _( "Open Emitter" ),
303 _( "No Connection" )
304};
305
306
307// List of pin types that are considered drivers for usual input pins
308// i.e. pin type = ELECTRICAL_PINTYPE::PT_INPUT, but not PT_POWER_IN
309// that need only a PT_POWER_OUT pin type to be driven
318
319// List of pin types that are considered drivers for power pins
320// In fact only a ELECTRICAL_PINTYPE::PT_POWER_OUT pin type can drive
321// power input pins
322const std::set<ELECTRICAL_PINTYPE> DrivingPowerPinTypes =
323{
325};
326
327// List of pin types that require a driver elsewhere on the net
328const std::set<ELECTRICAL_PINTYPE> DrivenPinTypes =
329{
332};
333
334extern void CheckDuplicatePins( LIB_SYMBOL* aSymbol, std::vector<wxString>& aMessages,
335 UNITS_PROVIDER* aUnitsProvider );
336
337ERC_TESTER::ERC_TESTER( SCHEMATIC* aSchematic, bool aShowAllErrors ) :
338 m_schematic( aSchematic ),
339 m_settings( aSchematic->ErcSettings() ),
340 m_sheetList( aSchematic->BuildSheetListSortedByPageNumbers() ),
341 m_screens( aSchematic->Root() ),
342 m_nets( aSchematic->ConnectionGraph()->GetNetMap() ),
343 m_showAllErrors( aShowAllErrors )
344{
345 if( !ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
346 m_sheetList.GetMultiUnitSymbols( m_refMap, SYMBOL_FILTER_ALL );
347}
348
349
350int ERC_TESTER::TestDuplicateSheetNames( bool aCreateMarker )
351{
352 int err_count = 0;
353
354 // Preflight callers validate fresh edits before connectivity has been rebuilt
355 if( aCreateMarker && ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
356 {
357 const auto errors = m_schematic->Connectivity().Engine().DuplicateSheetNames();
358 ERC_MARKER_PLACER markers( *m_schematic );
359
360 for( const auto& error : errors )
361 {
362 markers.Report( ERCE_DUPLICATE_SHEET_NAME, { error.main, error.auxiliary }, error.sheet, error.position,
363 ITEM_PATHS::BOTH );
364 }
365
366 return markers.Count();
367 }
368
369 for( const SCH_SHEET_PATH& path : m_schematic->Hierarchy() )
370 {
371 SCH_SCREEN* screen = path.LastScreen();
372 std::vector<SCH_SHEET*> list;
373
374 for( SCH_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
375 list.push_back( static_cast<SCH_SHEET*>( item ) );
376
377 for( size_t i = 0; i < list.size(); i++ )
378 {
379 SCH_SHEET* sheet = list[i];
380
381 for( size_t j = i + 1; j < list.size(); j++ )
382 {
383 SCH_SHEET* test_item = list[j];
384
385 // We have found a second sheet: compare names
386 // we are using case insensitive comparison to avoid mistakes between
387 // similar names like Mysheet and mysheet
388 const wxString variant = m_schematic->GetCurrentVariant();
389 const wxString name =
390 sheet->GetField( FIELD_T::SHEET_NAME )->GetShownText( &path, RESOLVED, variant, 0 );
391 const wxString other =
392 test_item->GetField( FIELD_T::SHEET_NAME )->GetShownText( &path, RESOLVED, variant, 0 );
393
394 if( name.IsSameAs( other, false ) )
395 {
396 if( aCreateMarker )
397 {
399 ercItem->SetItems( sheet, test_item );
400 ercItem->SetSheetSpecificPath( path );
401 ercItem->SetItemsSheetPaths( path, path );
402
403 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), sheet->GetPosition() );
404 screen->Append( marker );
405 }
406
407 err_count++;
408 }
409 }
410 }
411 }
412
413 return err_count;
414}
415
416
417int ERC_TESTER::TestPinMap( KIFACE* aCvPcb, PROJECT* aProject )
418{
419 int errors = 0;
420 const bool checkStale = m_settings.IsTestEnabled( ERCE_PIN_MAP_STALE_PIN );
421 const bool checkDuplicate = m_settings.IsTestEnabled( ERCE_PIN_MAP_DUPLICATE_PAD );
422 const bool checkBadPad = m_settings.IsTestEnabled( ERCE_PIN_MAP_BAD_PAD );
423 wxString msg;
424
427
428 std::map<wxString, std::set<wxString>> padCache;
429
430 auto getPads =
431 [&]( const wxString& aFootprintId ) -> const std::set<wxString>&
432 {
433 auto it = padCache.find( aFootprintId );
434
435 if( it != padCache.end() )
436 return it->second;
437
438 std::set<wxString>& pads = padCache[aFootprintId];
439
440 if( padFetcher && !aFootprintId.IsEmpty() )
441 padFetcher( aFootprintId, aProject, pads );
442
443 return pads;
444 };
445
446 // Pin maps and the symbol's pin numbers are library-symbol properties, so iterate unique
447 // screens (not sheet paths) to avoid double-reporting on reused hierarchical sheets.
448 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
449 {
450 std::vector<SCH_CONNECTIVITY::PIN_MAP_FACT> sources;
451
452 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
453 {
454 sources = m_schematic->Connectivity().Engine().PinMapSymbols( screen->ConnectivityId() );
455 }
456 else
457 {
458 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
459 {
460 if( auto source = SCH_CONNECTIVITY::ExtractPinMapFacts( *static_cast<SCH_SYMBOL*>( item ) ) )
461 sources.push_back( std::move( *source ) );
462 }
463 }
464
465 for( const SCH_CONNECTIVITY::PIN_MAP_FACT& source : sources )
466 {
467 const PIN_MAP_SET& maps = source.maps;
468 const std::set<wxString>& pinNumbers = source.pinNumbers;
469 const JUMPER_GROUP_SET& jumperGroups = source.jumperGroups;
470
471 auto sharesJumperGroup =
472 [&]( const wxString& aPinA, const wxString& aPinB )
473 {
474 for( const JUMPER_GROUP& group : jumperGroups.GetAll() )
475 {
476 if( group.Contains( aPinA ) && group.Contains( aPinB ) )
477 return true;
478 }
479
480 return false;
481 };
482
483 for( const PIN_MAP& map : maps.GetAll() )
484 {
485 if( checkStale )
486 {
487 for( const PIN_MAP_ENTRY& entry : map.GetEntries() )
488 {
489 if( pinNumbers.count( entry.m_PinNumber ) )
490 continue;
491
492 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_PIN_MAP_STALE_PIN );
493
494 msg.Printf( _( "Pin map '%s' references unknown symbol pin '%s'" ),
495 map.GetName(),
496 entry.m_PinNumber );
497
498 ercItem->SetItems( source.id );
499 ercItem->SetErrorMessage( msg );
500 screen->Append( new SCH_MARKER( std::move( ercItem ), source.position ) );
501 errors++;
502 }
503 }
504
505 // A single pin stacked across several pads is allowed. Two pins on one pad is not.
506 if( checkDuplicate )
507 {
508 std::map<wxString, wxString> padToPin;
509
510 // Enter identity maps for those pins that aren't explicitly mapped
511 for( const wxString& pinNumber : pinNumbers )
512 {
513 if( !map.HasEntry( pinNumber ) )
514 padToPin[pinNumber] = pinNumber;
515 }
516
517 for( const PIN_MAP_ENTRY& entry : map.GetEntries() )
518 {
519 for( const wxString& pad : ExpandStackedPinNotation( entry.m_PadNumber ) )
520 {
521 auto it = padToPin.find( pad );
522
523 if( it == padToPin.end() )
524 {
525 padToPin[pad] = entry.m_PinNumber;
526 }
527 else if( it->second != entry.m_PinNumber
528 && !sharesJumperGroup( it->second, entry.m_PinNumber ) )
529 {
530 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_PIN_MAP_DUPLICATE_PAD );
531
532 msg.Printf( _( "Symbol pins '%s' and '%s' both map to pad '%s'" ),
533 it->second,
534 entry.m_PinNumber,
535 pad );
536
537 ercItem->SetItems( source.id );
538 ercItem->SetErrorMessage( msg );
539 screen->Append( new SCH_MARKER( std::move( ercItem ), source.position ) );
540 errors++;
541 }
542 }
543 }
544 }
545 }
546
547 if( checkBadPad && padFetcher )
548 {
549 for( const ASSOCIATED_FOOTPRINT& assoc : source.footprints )
550 {
551 const PIN_MAP* boundMap = maps.FindByName( assoc.m_MapName );
552
553 if( !boundMap )
554 continue;
555
556 const std::set<wxString>& pads = getPads( assoc.m_FootprintLibId.GetUniStringLibId() );
557
558 if( pads.empty() )
559 continue;
560
561 for( const PIN_MAP_ENTRY& entry : boundMap->GetEntries() )
562 {
563 for( const wxString& pad : ExpandStackedPinNotation( entry.m_PadNumber ) )
564 {
565 if( pads.count( pad ) )
566 continue;
567
568 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_PIN_MAP_BAD_PAD );
569
570 msg.Printf( _( "Pin map '%s' references pad '%s' not present on footprint '%s'" ),
571 boundMap->GetName(),
572 pad,
574
575 ercItem->SetItems( source.id );
576 ercItem->SetErrorMessage( msg );
577 screen->Append( new SCH_MARKER( std::move( ercItem ), source.position ) );
578 errors++;
579 }
580 }
581 }
582 }
583 }
584 }
585
586 if( m_settings.IsTestEnabled( ERCE_PIN_MAP_UNMAPPED_PIN ) && padFetcher )
587 {
588 auto report =
589 [&]( const SCH_SHEET_PATH& sheet, const KIID& pin, const VECTOR2I& position, const wxString& number,
590 const wxString& footprint )
591 {
592 std::shared_ptr<ERC_ITEM> error = ERC_ITEM::Create( ERCE_PIN_MAP_UNMAPPED_PIN );
593
594 msg.Printf( _( "Pin '%s' is connected but maps to no pad on footprint '%s'" ),
595 number,
596 footprint );
597
598 error->SetItems( pin );
599 error->SetSheetSpecificPath( sheet );
600 error->SetItemsSheetPaths( sheet );
601 error->SetErrorMessage( msg );
602 sheet.LastScreen()->Append( new SCH_MARKER( std::move( error ), position ) );
603 ++errors;
604 };
605
606 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
607 {
608 ERC_MARKER_PLACER sheets( *m_schematic );
609
610 for( const auto& pin : m_schematic->Connectivity().Engine().UnmappedPinCandidates() )
611 {
612 const SCH_SHEET_PATH* sheet = sheets.Find( pin.sheet );
613
614 if( !sheet )
615 continue;
616
617 LIB_ID footprint;
618 footprint.Parse( pin.footprint, true );
619 const std::set<wxString>& pads = getPads( footprint.GetUniStringLibId() );
620
621 if( !pads.empty() && !SCH_PIN::HasIdentityPad( pin.number, pads ) )
622 report( *sheet, pin.item, pin.position, pin.number, pin.footprint );
623 }
624
625 return errors;
626 }
627
628 const wxString variant = m_schematic ? m_schematic->GetCurrentVariant() : wxString();
629
630 for( SCH_SHEET_PATH& sheet : m_sheetList )
631 {
632 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
633 {
634 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
635 LIB_SYMBOL* lib = symbol->GetLibSymbolRef().get();
636
637 if( !lib || lib->GetEffectiveAssociatedFootprints().empty() )
638 continue;
639
640 wxString fpText = symbol->GetFootprintFieldText( &sheet, RESOLVED );
641 LIB_ID fpId;
642
643 if( fpText.IsEmpty() || fpId.Parse( fpText, true ) >= 0 )
644 continue;
645
646 const std::set<wxString>& pads = getPads( fpId.GetUniStringLibId() );
647
648 if( pads.empty() )
649 continue;
650
651 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
652 {
653 if( pin->IsDangling() )
654 continue;
655
656 SCH_PIN::PAD_RESOLUTION state = SCH_PIN::PAD_RESOLUTION::MAPPED;
657 pin->GetEffectivePadNumber( sheet, variant, fpId, &pads, &state );
658
659 if( state != SCH_PIN::PAD_RESOLUTION::UNMAPPED )
660 continue;
661
662 report( sheet, pin->m_Uuid, pin->GetPosition(), pin->GetNumber(), fpText );
663 }
664 }
665 }
666 }
667
668 return errors;
669}
670
671
673{
675
676 // The leading "(^|[^\\\\])" group requires the marker to start the string or follow a non-backslash,
677 // so `\${ERC_ERROR ...}` stays inert. (The group is just to make it easier for a human to parse.)
678 static wxRegEx varRefRegEx( wxT( "(^|[^\\\\])\\$\\{.*\\}.*" ) );
679
680 auto reportAssertions =
681 []( const KIID& item, const SCH_SHEET_PATH& sheet, SCH_SCREEN* screen,
682 const std::vector<SCH_CONNECTIVITY::TEXT_ASSERTION>& assertions, const VECTOR2I& pos )
683 {
684 for( const auto& assertion : assertions )
685 {
686 auto ercItem = ERC_ITEM::Create( assertion.warning ? ERCE_GENERIC_WARNING : ERCE_GENERIC_ERROR );
687 wxString message = assertion.message;
688
689 if( item != niluuid )
690 {
691 ercItem->SetItems( std::vector<KIID>{ item } );
692 ercItem->SetItemsSheetPaths( sheet );
693 }
694 else
695 {
696 message += _( " (in drawing sheet)" );
697 }
698
699 ercItem->SetSheetSpecificPath( sheet );
700 ercItem->SetErrorMessage( message );
701 screen->Append( new SCH_MARKER( std::move( ercItem ), pos ) );
702 }
703
704 return !assertions.empty();
705 };
706
707 if( aDrawingSheet && !ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
708 {
709 wsItems.SetPageNumber( wxS( "1" ) );
710 wsItems.SetSheetCount( 1 );
711 wsItems.SetFileName( wxS( "dummyFilename" ) );
712 wsItems.SetSheetName( wxS( "dummySheet" ) );
713 wsItems.SetSheetLayer( wxS( "dummyLayer" ) );
714 wsItems.SetProject( &m_schematic->Project() );
715 wsItems.BuildDrawItemsList( aDrawingSheet->GetPageInfo(), aDrawingSheet->GetTitleBlock() );
716 }
717
718 for( const SCH_SHEET_PATH& sheet : m_sheetList )
719 {
720 SCH_SCREEN* screen = sheet.LastScreen();
721
722 const auto sources = ADVANCED_CFG::GetCfg().m_ConnectivityEngine
723 ? m_schematic->Connectivity().TextChecks( sheet.PathRef() )
724 : SCH_CONNECTIVITY::ExtractTextChecks( *screen, sheet );
725
726 for( const auto& source : sources )
727 {
728 if( reportAssertions( source.assertionItem, sheet, screen, source.assertions, source.assertionPosition ) )
729 continue;
730
731 if( !varRefRegEx.Matches( source.shownText ) )
732 continue;
733
734 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
735 ercItem->SetItems( std::vector<KIID>{ source.item } );
736 ercItem->SetSheetSpecificPath( sheet );
737 ercItem->SetItemsSheetPaths( sheet );
738 screen->Append( new SCH_MARKER( std::move( ercItem ), source.position ) );
739 }
740
741 if( aDrawingSheet && ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
742 {
743 for( const auto& source : m_schematic->Connectivity().TextChecks( sheet.PathRef(), true ) )
744 {
745 if( reportAssertions( niluuid, sheet, screen, source.assertions, source.assertionPosition ) )
746 continue;
747
748 if( varRefRegEx.Matches( source.shownText ) )
749 {
750 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
751 ercItem->SetErrorMessage( _( "Unresolved text variable in drawing sheet" ) );
752 ercItem->SetSheetSpecificPath( sheet );
753 screen->Append( new SCH_MARKER( std::move( ercItem ), source.position ) );
754 }
755 }
756 }
757
758 for( DS_DRAW_ITEM_BASE* item = wsItems.GetFirst(); item; item = wsItems.GetNext() )
759 {
760 if( DS_DRAW_ITEM_TEXT* text = dynamic_cast<DS_DRAW_ITEM_TEXT*>( item ) )
761 {
762 if( reportAssertions( niluuid, sheet, screen,
764 text->GetPosition() ) )
765 {
766 // Skip unresolved-variable test.
767 // Yes, the assertion message could have an unresolved variable in it, but it's
768 // going to end up in the ERC window anyway, so there's not much sense in double-
769 // reporting it.
770 }
771 else if( varRefRegEx.Matches( text->GetShownText( FOR_ERC_DRC ) ) )
772 {
773 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNRESOLVED_VARIABLE );
774 ercItem->SetErrorMessage( _( "Unresolved text variable in drawing sheet" ) );
775 ercItem->SetSheetSpecificPath( sheet );
776
777 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), text->GetPosition() );
778 screen->Append( marker );
779 }
780 }
781 }
782 }
783}
784
785
787{
788 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
789 {
790 return reportSourceErrors( *m_schematic, ERCE_EMPTY_POWER_VALUE,
791 m_schematic->Connectivity().Engine().EmptyPowerValues() );
792 }
793
794 int errors = 0;
795
796 for( const SCH_SHEET_PATH& sheet : m_sheetList )
797 {
798 SCH_SCREEN* screen = sheet.LastScreen();
799
800 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
801 {
802 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
803
804 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
805 {
806 if( !pin->IsGlobalPower() && !pin->IsLocalPower() )
807 continue;
808
809 const SYMBOL* parent = pin->GetLibPin() ? pin->GetLibPin()->GetParentSymbol() : nullptr;
810
811 // A hidden power input on an ordinary symbol is named from the pin, not the value
812 if( !parent || ( !parent->IsGlobalPower() && !parent->IsLocalPower() ) )
813 continue;
814
815 wxString name = symbol->GetValue( &sheet, FOR_NETNAME );
816
817 if( name.Trim( false ).Trim( true ).IsEmpty() )
818 {
820 ercItem->SetItems( pin );
821 ercItem->SetItemsSheetPaths( sheet );
822 ercItem->SetSheetSpecificPath( sheet );
823
824 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
825 screen->Append( marker );
826 errors++;
827 }
828
829 break;
830 }
831 }
832 }
833
834 return errors;
835}
836
837
839{
840 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
841 {
842 return reportSourceErrors( *m_schematic, ERCE_EMPTY_LABEL_NAME,
843 m_schematic->Connectivity().Engine().EmptyLabels() );
844 }
845
846 int errors = 0;
847
848 // No directive labels, they carry no text (the netclass lives in a field)
850
851 for( const SCH_SHEET_PATH& sheet : m_sheetList )
852 {
853 SCH_SCREEN* screen = sheet.LastScreen();
854
855 for( KICAD_T labelType : labelTypes )
856 {
857 for( SCH_ITEM* item : screen->Items().OfType( labelType ) )
858 {
859 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
860
861 wxString text = label->GetText();
862 text.Trim( false ).Trim( true );
863
864 if( text.IsEmpty() )
865 {
866 auto ercItem = ERC_ITEM::Create( ERCE_EMPTY_LABEL_NAME );
867 ercItem->SetItems( label );
868 ercItem->SetItemsSheetPaths( sheet );
869 ercItem->SetSheetSpecificPath( sheet );
870
871 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), label->GetPosition() );
872 screen->Append( marker );
873 errors++;
874 }
875 }
876 }
877 }
878
879 return errors;
880}
881
882
884{
885 int warnings = 0;
886
887 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
888 {
889 const auto errors = m_schematic->Connectivity().Engine().InvalidFieldNames();
890 ERC_MARKER_PLACER markers( *m_schematic );
891
892 for( const auto& error : errors )
893 {
894 markers.Report( ERCE_FIELD_NAME_WHITESPACE, { error.field.owner, error.field.field }, error.sheet,
895 error.field.position, ITEM_PATHS::BOTH,
896 wxString::Format( _( "Field name has leading or trailing whitespace: '%s'" ),
897 error.field.name ) );
898 }
899
900 return markers.Count();
901 }
902
903 for( const SCH_SHEET_PATH& sheet : m_sheetList )
904 {
905 SCH_SCREEN* screen = sheet.LastScreen();
906
907 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
908 {
909 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
910
911 for( SCH_FIELD& field : symbol->GetFields() )
912 {
913 wxString trimmedFieldName = field.GetName();
914 trimmedFieldName.Trim();
915 trimmedFieldName.Trim( false );
916
917 if( field.GetName() != trimmedFieldName )
918 {
920 ercItem->SetItems( symbol, &field );
921 ercItem->SetItemsSheetPaths( sheet, sheet );
922 ercItem->SetSheetSpecificPath( sheet );
923 ercItem->SetErrorMessage(
924 wxString::Format(
925 _( "Field name has leading or trailing whitespace: '%s'" ),
926 field.GetName() ) );
927
928 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), field.GetPosition() );
929 screen->Append( marker );
930 warnings++;
931 }
932 }
933 }
934
935 for( SCH_ITEM* item : screen->Items().OfType( SCH_SHEET_T ) )
936 {
937 SCH_SHEET* subSheet = static_cast<SCH_SHEET*>( item );
938
939 for( SCH_FIELD& field : subSheet->GetFields() )
940 {
941 wxString trimmedFieldName = field.GetName();
942 trimmedFieldName.Trim();
943 trimmedFieldName.Trim( false );
944
945 if( field.GetName() != trimmedFieldName )
946 {
948 ercItem->SetItems( subSheet, &field );
949 ercItem->SetItemsSheetPaths( sheet, sheet );
950 ercItem->SetSheetSpecificPath( sheet );
951 ercItem->SetErrorMessage(
952 wxString::Format(
953 _( "Field name has leading or trailing whitespace: '%s'" ),
954 field.GetName() ) );
955
956 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), field.GetPosition() );
957 screen->Append( marker );
958 warnings++;
959 }
960 }
961 }
962 }
963
964 return warnings;
965}
966
967
968std::vector<SCH_CONNECTIVITY::MULTI_UNIT_GROUP> ERC_TESTER::multiUnitSources() const
969{
970 using namespace SCH_CONNECTIVITY;
971
972 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
973 return m_schematic->Connectivity().Engine().MultiUnitSymbols();
974
975 std::vector<MULTI_UNIT_GROUP> result;
976
977 for( const auto& [reference, refs] : m_refMap )
978 {
979 if( refs.GetCount() == 0 )
980 continue;
981
983 group.reference = reference;
984 group.units = ExtractUnitFacts( *refs.GetItem( 0 ).GetLibPart() );
985
986 for( size_t i = 0; i < refs.GetCount(); ++i )
987 {
988 const SCH_REFERENCE& ref = refs.GetItem( i );
989 const SCH_SYMBOL* symbol = ref.GetSymbol();
990 group.instances.push_back( { ref.GetSheetPath().PathRef(), symbol->m_Uuid,
991 symbol->GetPosition(), symbol->GetRef( &ref.GetSheetPath(), true ),
992 ref.GetFootprint(), ref.GetUnit() } );
993 }
994
995 result.push_back( std::move( group ) );
996 }
997
998 return result;
999}
1000
1001
1003{
1004 ERC_MARKER_PLACER markers( *m_schematic );
1005
1006 for( const auto& group : multiUnitSources() )
1007 {
1008 const SCH_CONNECTIVITY::MULTI_UNIT_INSTANCE* reference = nullptr;
1009
1010 for( const auto& unit : group.instances )
1011 {
1012 if( !unit.footprint.IsEmpty() )
1013 {
1014 reference = &unit;
1015 break;
1016 }
1017 }
1018
1019 if( !reference )
1020 continue;
1021
1022 // Equivalent reference witnesses must retain exclusions when pages are reordered
1023 for( const auto& unit : group.instances )
1024 {
1025 if( unit.item == reference->item && unit.footprint == reference->footprint
1026 && unit.name == reference->name && unit.sheet < reference->sheet )
1027 {
1028 reference = &unit;
1029 }
1030 }
1031
1032 for( const auto& unit : group.instances )
1033 {
1034 if( unit.footprint.IsEmpty() || unit.footprint == reference->footprint )
1035 continue;
1036
1038 error->SetErrorMessage( wxString::Format( _( "Different footprints assigned to %s and %s" ),
1039 reference->name, unit.name ) );
1040 error->SetItems( std::vector<KIID>{ reference->item, unit.item } );
1041 markers.Place( std::move( error ), unit.sheet, unit.position, reference->sheet, unit.sheet );
1042 }
1043 }
1044
1045 return markers.Count();
1046}
1047
1048
1050{
1051 SCH_REFERENCE_LIST references;
1052 m_schematic->Hierarchy().GetSymbols( references, SYMBOL_FILTER_NON_POWER, true );
1053
1054 ERC_MARKER_PLACER markers( *m_schematic );
1055
1056 references.CheckAnnotation(
1057 [&]( ERCE_T aType, const wxString& aMsg, SCH_REFERENCE* aItemA, SCH_REFERENCE* aItemB )
1058 {
1059 if( !m_settings.IsTestEnabled( aType ) )
1060 return;
1061
1062 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( aType );
1063 ercItem->SetErrorMessage( aMsg );
1064
1065 if( aItemB )
1066 ercItem->SetItems( aItemA->GetSymbol(), aItemB->GetSymbol() );
1067 else
1068 ercItem->SetItems( aItemA->GetSymbol() );
1069
1070 // Saved exclusions name these markers without a sheet path, as the dialog placed them
1071 markers.Place( std::move( ercItem ), aItemA->GetSheetPath().Path(),
1072 aItemA->GetSymbol()->GetPosition(), ITEM_PATHS::NONE, false );
1073 } );
1074
1075 return markers.Count();
1076}
1077
1078
1080{
1081 ERC_MARKER_PLACER markers( *m_schematic );
1082 const bool suffixMode = m_schematic->Settings().m_AnnotateReusedSheetSuffixes;
1083
1084 // Suffix mode shares one base across instances, so two bare instances also collide
1085 for( const auto& [path, first] : m_schematic->RefSuffixCollisions( suffixMode ) )
1086 {
1087 KIID_PATH parent = path.Path();
1088 KIID_PATH otherParent = first.Path();
1089 parent.pop_back();
1090 otherParent.pop_back();
1091
1092 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DUPLICATE_SHEET_SUFFIX );
1093 ercItem->SetItems( path.Last(), first.Last() );
1094 markers.Place( std::move( ercItem ), parent, path.Last()->GetPosition(), parent, otherParent );
1095 }
1096
1097 return markers.Count();
1098}
1099
1100
1102{
1103 ERC_MARKER_PLACER markers( *m_schematic );
1104 const bool suffixMode = m_schematic->Settings().m_AnnotateReusedSheetSuffixes;
1105
1106 std::map<const SCH_SCREEN*, const SCH_SHEET_PATH*> firstPath;
1107
1108 for( const SCH_SHEET_PATH& path : m_sheetList )
1109 {
1110 auto [first, isFirst] = firstPath.emplace( path.LastScreen(), &path );
1111
1112 for( SCH_ITEM* item : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1113 {
1114 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1115 SCH_SYMBOL_INSTANCE instance;
1116 wxString msg;
1117
1118 if( !symbol->GetInstance( instance, path.PathRef() ) )
1119 continue;
1120
1121 const SCH_SHEET_PATH& firstUse = *first->second;
1122
1123 if( suffixMode && instance.m_RefLacksSuffix )
1124 {
1125 msg = wxString::Format( _( "Reference %s was saved without the suffix %s" ), instance.m_Reference,
1126 m_schematic->GetRefSuffix( path ) );
1127 }
1128 else if( suffixMode && !isFirst && !m_schematic->CopiesSelectDifferentUnits( symbol )
1129 && !instance.m_Reference.StartsWith( wxS( "#" ) )
1130 && symbol->IsAnnotated( &path ) && symbol->IsAnnotated( &firstUse )
1131 && symbol->GetBaseRef( &path ) != symbol->GetBaseRef( &firstUse ) )
1132 {
1133 // Suffix mode numbers the first instance and every other instance shares its base
1134 msg = wxString::Format( _( "Reference %s does not share the base of %s" ), symbol->GetRef( &path ),
1135 symbol->GetRef( &firstUse ) );
1136 }
1137 else
1138 {
1139 continue;
1140 }
1141
1142 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_REF_SUFFIX_MISMATCH );
1143 ercItem->SetErrorMessage( msg );
1144 ercItem->SetItems( symbol );
1145 markers.Place( std::move( ercItem ), path.Path(), symbol->GetPosition(), ITEM_PATHS::MAIN );
1146 }
1147 }
1148
1149 return markers.Count();
1150}
1151
1152
1154{
1155 ERC_MARKER_PLACER markers( *m_schematic );
1156
1157 for( const auto& group : multiUnitSources() )
1158 {
1159 if( group.instances.empty() )
1160 continue;
1161
1162 const auto& base = group.instances.front();
1163 std::set<int> placed;
1164
1165 for( const auto& instance : group.instances )
1166 placed.insert( instance.unit );
1167
1168 std::set<int> missing;
1169 std::set<int> power;
1170 std::set<int> input;
1171 std::set<int> bidirectional;
1172
1173 for( size_t i = 0; i < group.units.size(); ++i )
1174 {
1175 const int unit = static_cast<int>( i ) + 1;
1176
1177 if( placed.contains( unit ) )
1178 continue;
1179
1180 missing.insert( unit );
1181
1182 if( group.units[i].powerInput )
1183 power.insert( unit );
1184
1185 if( group.units[i].input )
1186 input.insert( unit );
1187
1188 if( group.units[i].bidirectional )
1189 bidirectional.insert( unit );
1190 }
1191
1192 const auto report =
1193 [&]( const std::set<int>& units, const wxString& message, int code )
1194 {
1195 if( units.empty() || !m_settings.IsTestEnabled( code ) )
1196 return;
1197
1198 wxString names = wxS( "[ " );
1199 int count = 0;
1200
1201 for( int unit : units )
1202 {
1203 if( count == 3 )
1204 break;
1205
1206 if( count++ )
1207 names += wxS( ", " );
1208
1209 names += group.units[unit - 1].name;
1210 }
1211
1212 if( units.size() > 3 )
1213 names += wxS( ", ..." );
1214
1215 names += wxS( " ]" );
1216 markers.Report( code, { base.item }, base.sheet, base.position, ITEM_PATHS::MAIN,
1217 wxString::Format( message, group.reference, names ) );
1218 };
1219
1220 report( missing, _( "Symbol %s has unplaced units %s" ),
1222 report( power, _( "Symbol %s has input power pins in units %s that are not placed" ),
1224 report( input, _( "Symbol %s has input pins in units %s that are not placed" ),
1226 report( bidirectional, _( "Symbol %s has bidirectional pins in units %s that are not placed" ),
1228 }
1229
1230 return markers.Count();
1231}
1232
1233
1235{
1236 int err_count = 0;
1237 std::shared_ptr<NET_SETTINGS>& settings = m_schematic->Project().GetProjectFile().NetSettings();
1238 wxString defaultNetclass = settings->GetDefaultNetclass()->GetName();
1239
1240 auto logError =
1241 [&]( const SCH_SHEET_PATH& sheet, const KIID& item, const VECTOR2I& position, const wxString& netclass )
1242 {
1243 err_count++;
1244
1245 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNDEFINED_NETCLASS );
1246
1247 ercItem->SetItems( std::vector<KIID>{ item } );
1248 ercItem->SetSheetSpecificPath( sheet );
1249 ercItem->SetItemsSheetPaths( sheet );
1250 ercItem->SetErrorMessage( wxString::Format( _( "Netclass %s is not defined" ), netclass ) );
1251
1252 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), position );
1253 sheet.LastScreen()->Append( marker );
1254 };
1255
1256 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
1257 {
1258 ERC_MARKER_PLACER sheets( *m_schematic );
1259
1260 for( const auto& reference : m_schematic->Connectivity().Engine().NetclassReferences() )
1261 {
1262 if( reference.name == defaultNetclass || settings->HasNetclass( reference.name ) )
1263 continue;
1264
1265 if( const SCH_SHEET_PATH* sheet = sheets.Find( reference.sheet ) )
1266 logError( *sheet, reference.item, reference.position, reference.name );
1267 }
1268
1269 return err_count;
1270 }
1271
1272 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1273 {
1274 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
1275 {
1276 item->RunOnChildren(
1277 [&]( SCH_ITEM* aChild )
1278 {
1279 if( aChild->Type() == SCH_FIELD_T )
1280 {
1281 SCH_FIELD* field = static_cast<SCH_FIELD*>( aChild );
1282
1283 if( field->GetUntranslatedName() == wxT( "Netclass" ) )
1284 {
1285 wxString netclass = field->GetShownText( &sheet, FOR_NETNAME,
1286 m_schematic->GetCurrentVariant() );
1287
1288 if( !netclass.empty()
1289 && !netclass.IsSameAs( defaultNetclass )
1290 && !settings->HasNetclass( netclass ) )
1291 {
1292 logError( sheet, item->m_Uuid, item->GetPosition(), netclass );
1293 }
1294 }
1295 }
1296
1297 return true;
1298 },
1300 }
1301 }
1302
1303 return err_count;
1304}
1305
1306
1308{
1309 int err_count = 0;
1310
1311 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
1312 {
1313 ERC_MARKER_PLACER markers( *m_schematic );
1314
1315 for( const auto& conflict : m_schematic->Connectivity().Engine().LabelWireConflicts() )
1316 {
1317 std::vector<KIID> witnesses{ conflict.label };
1318 witnesses.insert( witnesses.end(), conflict.wires.begin(),
1319 conflict.wires.begin() + std::min<std::ptrdiff_t>( 3, std::ssize( conflict.wires ) ) );
1320 markers.Report( ERCE_LABEL_MULTIPLE_WIRES, witnesses, conflict.sheet, conflict.position, ITEM_PATHS::NONE,
1321 wxString::Format( _( "Label connects more than one wire at %d, %d" ),
1322 conflict.position.x, conflict.position.y ) );
1323 }
1324
1325 return markers.Count();
1326 }
1327
1328 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1329 {
1330 std::map<VECTOR2I, std::vector<SCH_ITEM*>> connMap;
1331
1332 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_LABEL_T ) )
1333 {
1334 SCH_LABEL* label = static_cast<SCH_LABEL*>( item );
1335
1336 for( const VECTOR2I& pt : label->GetConnectionPoints() )
1337 connMap[pt].emplace_back( label );
1338 }
1339
1340 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
1341 {
1342 std::vector<SCH_ITEM*> lines;
1343
1344 for( SCH_ITEM* item : sheet.LastScreen()->Items().Overlapping( SCH_LINE_T, pair.first ) )
1345 {
1346 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1347
1348 if( line->IsGraphicLine() )
1349 continue;
1350
1351 // If the line is connected at the endpoint, then there will be a junction
1352 if( !line->IsEndPoint( pair.first ) )
1353 lines.emplace_back( line );
1354 }
1355
1356 if( lines.size() > 1 )
1357 {
1358 err_count++;
1359 lines.resize( 3 ); // Only show the first 3 lines and if there are only two, adds a nullptr
1360
1361 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_LABEL_MULTIPLE_WIRES );
1362
1363 ercItem->SetItems( pair.second.front(), lines[0], lines[1], lines[2] );
1364 ercItem->SetErrorMessage( wxString::Format( _( "Label connects more than one wire at %d, %d" ),
1365 pair.first.x, pair.first.y ) );
1366 ercItem->SetSheetSpecificPath( sheet );
1367
1368 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pair.first );
1369 sheet.LastScreen()->Append( marker );
1370 }
1371 }
1372 }
1373
1374 return err_count;
1375}
1376
1377
1379{
1380 int err_count = 0;
1381
1382 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
1383 {
1384 ERC_MARKER_PLACER markers( *m_schematic );
1385
1386 for( const auto& junction : m_schematic->Connectivity().Engine().FourWayJunctions() )
1387 {
1388 markers.Report( ERCE_FOUR_WAY_JUNCTION, { junction.items.begin(), junction.items.begin() + 4 },
1389 junction.sheet, junction.position, ITEM_PATHS::NONE,
1390 wxString::Format( _( "Four items connected at %d, %d" ),
1391 junction.position.x, junction.position.y ) );
1392 }
1393
1394 return markers.Count();
1395 }
1396
1397 auto pinStackAlreadyRepresented =
1398 []( SCH_PIN* pin, std::vector<SCH_ITEM*>& collection ) -> bool
1399 {
1400 for( SCH_ITEM*& item : collection )
1401 {
1402 if( item->Type() == SCH_PIN_T && item->GetParentSymbol() == pin->GetParentSymbol() )
1403 {
1404 if( pin->IsVisible() && !static_cast<SCH_PIN*>( item )->IsVisible() )
1405 item = pin;
1406
1407 return true;
1408 }
1409 }
1410
1411 return false;
1412 };
1413
1414 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1415 {
1416 std::map<VECTOR2I, std::vector<SCH_ITEM*>> connMap;
1417 SCH_SCREEN* screen = sheet.LastScreen();
1418
1419 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
1420 {
1421 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1422
1423 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
1424 {
1425 std::vector<SCH_ITEM*>& entry = connMap[pin->GetPosition()];
1426
1427 // Only one pin per pin-stack.
1428 if( pinStackAlreadyRepresented( pin, entry ) )
1429 continue;
1430
1431 entry.emplace_back( pin );
1432 }
1433 }
1434
1435 for( SCH_ITEM* item : screen->Items().OfType( SCH_LINE_T ) )
1436 {
1437 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1438
1439 if( line->IsGraphicLine() )
1440 continue;
1441
1442 for( const VECTOR2I& pt : line->GetConnectionPoints() )
1443 connMap[pt].emplace_back( line );
1444 }
1445
1446 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : connMap )
1447 {
1448 if( pair.second.size() >= 4 )
1449 {
1450 err_count++;
1451
1452 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_FOUR_WAY_JUNCTION );
1453
1454 ercItem->SetItems( pair.second[0], pair.second[1], pair.second[2], pair.second[3] );
1455
1456 ercItem->SetErrorMessage( wxString::Format( _( "Four items connected at %d, %d" ),
1457 pair.first.x, pair.first.y ) );
1458
1459 ercItem->SetSheetSpecificPath( sheet );
1460
1461 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pair.first );
1462 sheet.LastScreen()->Append( marker );
1463 }
1464 }
1465 }
1466
1467 return err_count;
1468}
1469
1470
1472{
1473 int err_count = 0;
1474
1475 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
1476 {
1477 if( !m_settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED ) )
1478 return 0;
1479
1480 ERC_MARKER_PLACER markers( *m_schematic );
1481
1482 for( const auto& conflict : m_schematic->Connectivity().Engine().NoConnectPinConflicts() )
1483 {
1484 // Reserve a witness for the actual connection even when many NC pins coincide
1485 const auto witnessPins = std::min<std::ptrdiff_t>( 3, std::ssize( conflict.pins ) );
1486 std::vector<KIID> items( conflict.pins.begin(), conflict.pins.begin() + witnessPins );
1487 const auto witnessOthers = std::min<std::ptrdiff_t>( 4 - witnessPins, std::ssize( conflict.others ) );
1488 items.insert( items.end(), conflict.others.begin(), conflict.others.begin() + witnessOthers );
1489 markers.Report( ERCE_NOCONNECT_CONNECTED, items, conflict.sheet, conflict.position, ITEM_PATHS::NONE,
1490 _( "Pin with 'no connection' type is connected" ) );
1491 }
1492
1493 return markers.Count();
1494 }
1495
1496 for( const SCH_SHEET_PATH& sheet : m_sheetList )
1497 {
1498 std::map<VECTOR2I, std::vector<SCH_ITEM*>> pinMap;
1499
1500 auto addOther =
1501 [&]( const VECTOR2I& pt, SCH_ITEM* aOther )
1502 {
1503 if( pinMap.count( pt ) )
1504 pinMap[pt].emplace_back( aOther );
1505 };
1506
1507 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1508 {
1509 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1510
1511 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
1512 {
1513 if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC )
1514 pinMap[pin->GetPosition()].emplace_back( pin );
1515 }
1516 }
1517
1518 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
1519 {
1520 if( item->Type() == SCH_SYMBOL_T )
1521 {
1522 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1523
1524 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
1525 {
1526 if( pin->GetType() != ELECTRICAL_PINTYPE::PT_NC )
1527 addOther( pin->GetPosition(), pin );
1528 }
1529 }
1530 else if( item->IsConnectable() && item->Type() != SCH_NO_CONNECT_T )
1531 {
1532 for( const VECTOR2I& pt : item->GetConnectionPoints() )
1533 addOther( pt, item );
1534 }
1535 }
1536
1537 for( const std::pair<const VECTOR2I, std::vector<SCH_ITEM*>>& pair : pinMap )
1538 {
1539 if( pair.second.size() > 1 )
1540 {
1541 bool all_nc = true;
1542
1543 for( SCH_ITEM* item : pair.second )
1544 {
1545 if( item->Type() != SCH_PIN_T )
1546 {
1547 all_nc = false;
1548 break;
1549 }
1550
1551 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1552
1553 if( pin->GetType() != ELECTRICAL_PINTYPE::PT_NC )
1554 {
1555 all_nc = false;
1556 break;
1557 }
1558 }
1559
1560 if( all_nc )
1561 continue;
1562
1563 err_count++;
1564
1565 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_NOCONNECT_CONNECTED );
1566
1567 ercItem->SetItems( pair.second[0], pair.second[1],
1568 pair.second.size() > 2 ? pair.second[2] : nullptr,
1569 pair.second.size() > 3 ? pair.second[3] : nullptr );
1570 ercItem->SetErrorMessage( _( "Pin with 'no connection' type is connected" ) );
1571 ercItem->SetSheetSpecificPath( sheet );
1572
1573 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pair.first );
1574 sheet.LastScreen()->Append( marker );
1575 }
1576 }
1577 }
1578
1579 return err_count;
1580}
1581
1582
1583namespace
1584{
1585ERCE_T ercErrorCode( PIN_ERROR aPinError )
1586{
1587 return ( aPinError == PIN_ERROR::WARNING ) ? ERCE_PIN_TO_PIN_WARNING
1589}
1590
1591int testCapturedPinToPin( SCHEMATIC& aSchematic, ERC_SETTINGS& aSettings, bool aShowAllErrors )
1592{
1594
1595 std::vector<SCH_CONNECTIVITY::ERC_PIN_NET> nets = aSchematic.Connectivity().Engine().PinNets();
1596 const std::vector<std::unique_ptr<SCH_NETCHAIN>>& chains = aSchematic.NetChains().GetCommittedNetChains();
1597 std::map<wxString, const SCH_CONNECTIVITY::ERC_PIN_NET*> byName;
1598 std::set<wxString> powerDriven;
1599
1600 ERC_MARKER_PLACER markers( aSchematic );
1601
1602 const auto less =
1603 []( const PIN& a, const PIN& b )
1604 {
1605 int order = StrNumCmp( a.reference, b.reference );
1606
1607 if( order == 0 )
1608 order = StrNumCmp( a.pin.number, b.pin.number );
1609
1610 if( order != 0 )
1611 return order < 0;
1612
1613 // Tuple comparison would bypass KIID_PATH's length-first ordering
1614 if( a.sheet != b.sheet )
1615 return a.sheet < b.sheet;
1616
1617 return a.pin.id < b.pin.id;
1618 };
1619
1620 const auto mismatch =
1621 [&]( const PIN& a, const PIN& b )
1622 {
1623 const PIN_ERROR pinError = aSettings.GetPinMapValue( a.pin.type, b.pin.type );
1624
1625 return aSettings.IsTestEnabled( ercErrorCode( pinError ) ) ? pinError : PIN_ERROR::OK;
1626 };
1627
1628 const auto reportPair =
1629 [&]( const PIN& a, const PIN& b, PIN_ERROR pinError, const wxString& chain )
1630 {
1631 std::shared_ptr<ERC_ITEM> item = ERC_ITEM::Create( ercErrorCode( pinError ) );
1632
1633 item->SetItems( std::vector<KIID>{ a.pin.id, b.pin.id } );
1634
1635 if( chain.empty() )
1636 {
1637 item->SetErrorMessage( wxString::Format( _( "Pins of type %s and %s are connected" ),
1638 ElectricalPinTypeGetText( a.pin.type ),
1639 ElectricalPinTypeGetText( b.pin.type ) ) );
1640 }
1641 else
1642 {
1643 item->SetErrorMessage( wxString::Format( _( "Pins of type %s and %s are connected via "
1644 "net chain %s" ),
1645 ElectricalPinTypeGetText( a.pin.type ),
1646 ElectricalPinTypeGetText( b.pin.type ),
1647 chain ) );
1648 }
1649 markers.Place( std::move( item ), a.sheet, a.pin.position, a.sheet, b.sheet );
1650 };
1651
1652 const auto passiveOrNic =
1653 []( ELECTRICAL_PINTYPE type )
1654 {
1656 };
1657
1658 const bool heuristics = aSettings.GetERCSortingMetric() == ERC_PIN_SORTING_METRIC::SM_HEURISTICS;
1659
1660 struct MISMATCH
1661 {
1662 size_t first;
1663 size_t second;
1664 PIN_ERROR error;
1665 };
1666
1667 for( auto& net : nets )
1668 {
1669 std::sort( net.pins.begin(), net.pins.end(), less );
1670 byName.emplace( net.name, &net );
1671
1672 if( net.powerDriven )
1673 powerDriven.insert( net.name );
1674 }
1675
1676 for( const auto& net : nets )
1677 {
1678 const std::vector<PIN>& pins = net.pins;
1679 const bool powerNet = std::ranges::any_of( pins,
1680 []( const PIN& pin )
1681 {
1682 return pin.pin.type == ELECTRICAL_PINTYPE::PT_POWER_IN;
1683 } );
1684 const PIN* preferred = nullptr;
1685 std::vector<const PIN*> needsDriver;
1686 std::vector<const PIN*> nonPowerInputs;
1687 std::vector<const PIN*> powerInputs;
1688 std::vector<MISMATCH> mismatches;
1689 std::map<size_t, int> weights;
1690 bool hasDriver = net.powerDriven;
1691
1692 for( size_t i = 0; i < pins.size(); ++i )
1693 {
1694 const PIN& pin = pins[i];
1695 hasDriver |= powerNet ? DrivingPowerPinTypes.contains( pin.pin.type )
1696 : DrivingPinTypes.contains( pin.pin.type );
1697
1698 if( DrivenPinTypes.contains( pin.pin.type ) )
1699 {
1700 needsDriver.push_back( &pin );
1701
1702 if( !pin.pin.globalPower && !pin.pin.localPower )
1703 nonPowerInputs.push_back( &pin );
1704
1705 if( pin.pin.type == ELECTRICAL_PINTYPE::PT_POWER_IN )
1706 powerInputs.push_back( &pin );
1707
1708 if( !preferred
1709 || ( preferred->pin.invisible && !pin.pin.invisible )
1710 || ( powerNet != ( preferred->pin.type == ELECTRICAL_PINTYPE::PT_POWER_IN )
1711 && powerNet == ( pin.pin.type == ELECTRICAL_PINTYPE::PT_POWER_IN ) ) )
1712 {
1713 preferred = &pin;
1714 }
1715 }
1716
1717 for( size_t j = i + 1; j < pins.size(); ++j )
1718 {
1719 const PIN& other = pins[j];
1720 const bool stacked = pin.sheet == other.sheet
1721 && pin.owner == other.owner
1722 && pin.pin.position == other.pin.position
1723 && pin.pin.name == other.pin.name
1724 && ( pin.pin.type == other.pin.type
1725 || passiveOrNic( pin.pin.type )
1726 || passiveOrNic( other.pin.type ) );
1727
1728 if( stacked )
1729 continue;
1730
1731 const PIN_ERROR error = mismatch( pin, other );
1732
1733 if( error == PIN_ERROR::OK )
1734 continue;
1735
1736 mismatches.push_back( { i, j, error } );
1737
1738 if( heuristics )
1739 {
1740 weights[i] = aSettings.GetPinTypeWeight( pin.pin.type );
1741 weights[j] = aSettings.GetPinTypeWeight( other.pin.type );
1742 }
1743 else
1744 {
1745 ++weights[i];
1746 ++weights[j];
1747 }
1748 }
1749 }
1750
1751 // Each pin reports once against its nearest mismatch so one bad pin does not flood the net
1752 std::vector<std::pair<int, size_t>> worst;
1753
1754 for( const auto& [index, weight] : weights )
1755 worst.emplace_back( weight, index );
1756
1757 std::stable_sort( worst.begin(), worst.end(),
1758 []( const auto& a, const auto& b )
1759 {
1760 return a.first > b.first;
1761 } );
1762
1763 for( const auto& [weight, index] : worst )
1764 {
1765 const PIN& pin = pins[index];
1766 const PIN* nearest = nullptr;
1767 PIN_ERROR error = PIN_ERROR::OK;
1768 std::optional<double> nearestDistance;
1769
1770 std::erase_if( mismatches,
1771 [&]( const MISMATCH& candidate )
1772 {
1773 if( candidate.first != index && candidate.second != index )
1774 return false;
1775
1776 const PIN& other = pins[candidate.first == index ? candidate.second : candidate.first];
1777
1778 // Cross-sheet partners have no distance and stand in only until a same-sheet partner appears
1779 if( other.sheet != pin.sheet )
1780 {
1781 if( !nearestDistance )
1782 {
1783 nearest = &other;
1784 error = candidate.error;
1785 }
1786 }
1787 else if( const double distance = pin.pin.position.Distance( other.pin.position );
1788 !nearestDistance || distance < *nearestDistance )
1789 {
1790 nearestDistance = distance;
1791 nearest = &other;
1792 error = candidate.error;
1793 }
1794
1795 return true;
1796 } );
1797
1798 if( nearest )
1799 reportPair( pin, *nearest, error, wxString() );
1800 }
1801
1802 if( !preferred || hasDriver || net.noConnect )
1803 continue;
1804
1805 bool chainDriver = false;
1806
1807 if( powerNet )
1808 {
1809 for( const auto& chain : chains )
1810 {
1811 if( !chain || !chain->GetNets().contains( net.name ) )
1812 continue;
1813
1814 chainDriver = std::ranges::any_of( chain->GetNets(),
1815 [&]( const wxString& name )
1816 {
1817 return name != net.name && powerDriven.contains( name );
1818 } );
1819 break;
1820 }
1821 }
1822
1823 const ERCE_T code = powerNet ? ERCE_POWERPIN_NOT_DRIVEN : ERCE_PIN_NOT_DRIVEN;
1824
1825 if( chainDriver || !aSettings.IsTestEnabled( code ) )
1826 continue;
1827
1828 if( aShowAllErrors )
1829 {
1830 const auto& selected = powerNet && !powerInputs.empty() ? powerInputs
1831 : !nonPowerInputs.empty() ? nonPowerInputs
1832 : needsDriver;
1833
1834 for( const PIN* pin : selected )
1835 markers.Report( code, { pin->pin.id }, pin->sheet, pin->pin.position, ITEM_PATHS::MAIN );
1836 }
1837 else
1838 {
1839 const PIN& pin = powerNet && !powerInputs.empty() ? *powerInputs.front()
1840 : *preferred;
1841 markers.Report( code, { pin.pin.id }, pin.sheet, pin.pin.position, ITEM_PATHS::MAIN );
1842 }
1843 }
1844
1845 for( const std::unique_ptr<SCH_NETCHAIN>& chain : chains )
1846 {
1847 if( !chain )
1848 continue;
1849
1850 struct CHAIN_PIN
1851 {
1852 const PIN* pin;
1853 const wxString* net;
1854 };
1855 std::vector<CHAIN_PIN> pins;
1856
1857 for( const wxString& name : chain->GetNets() )
1858 {
1859 const auto net = byName.find( name );
1860
1861 if( net == byName.end() )
1862 continue;
1863
1864 for( const PIN& pin : net->second->pins )
1865 pins.push_back( { &pin, &net->first } );
1866 }
1867
1868 std::sort( pins.begin(), pins.end(),
1869 [&]( const CHAIN_PIN& a, const CHAIN_PIN& b )
1870 {
1871 return less( *a.pin, *b.pin );
1872 } );
1873
1874 for( size_t i = 0; i < pins.size(); ++i )
1875 {
1876 for( size_t j = i + 1; j < pins.size(); ++j )
1877 {
1878 if( *pins[i].net == *pins[j].net )
1879 continue;
1880
1881 if( const PIN_ERROR error = mismatch( *pins[i].pin, *pins[j].pin ); error != PIN_ERROR::OK )
1882 reportPair( *pins[i].pin, *pins[j].pin, error, chain->GetName() );
1883 }
1884 }
1885 }
1886
1887 return markers.Count();
1888}
1889}
1890
1891
1893{
1894 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
1895 return testCapturedPinToPin( *m_schematic, m_settings, m_showAllErrors );
1896
1897 int errors = 0;
1898 std::set<wxString> powerDrivenNets;
1899
1900 if( !m_schematic->ConnectionGraph()->GetCommittedNetChains().empty() )
1901 {
1902 for( const auto& [key, subgraphs] : m_nets )
1903 {
1904 for( const CONNECTION_SUBGRAPH* subgraph : subgraphs )
1905 {
1906 for( SCH_ITEM* item : subgraph->GetItems() )
1907 {
1908 if( item->Type() != SCH_PIN_T )
1909 continue;
1910
1911 const SCH_PIN* pin = static_cast<SCH_PIN*>( item );
1912
1913 if( DrivingPowerPinTypes.contains( pin->GetType() ) )
1914 powerDrivenNets.insert( key.Name );
1915 }
1916 }
1917 }
1918 }
1919
1920
1921 // Map each net name to the pins (with sheet context) found on that net so we can later
1922 // perform cross-net compatibility checks for grouped net chains.
1923 std::unordered_map<wxString, std::vector<ERC_SCH_PIN_CONTEXT>> netToPins;
1924
1925 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
1926 {
1927 using iterator_t = std::vector<ERC_SCH_PIN_CONTEXT>::iterator;
1928 std::vector<ERC_SCH_PIN_CONTEXT> pins;
1929 std::unordered_map<EDA_ITEM*, SCH_SCREEN*> pinToScreenMap;
1930 bool has_noconnect = false;
1931
1932 for( CONNECTION_SUBGRAPH* subgraph: net.second )
1933 {
1934 if( subgraph->GetNoConnect() )
1935 has_noconnect = true;
1936
1937 for( SCH_ITEM* item : subgraph->GetItems() )
1938 {
1939 if( item->Type() == SCH_PIN_T )
1940 {
1941 pins.emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
1942 netToPins[ net.first.Name ].emplace_back( static_cast<SCH_PIN*>( item ), subgraph->GetSheet() );
1943 pinToScreenMap[item] = subgraph->GetSheet().LastScreen();
1944 }
1945 }
1946 }
1947
1948 std::sort( pins.begin(), pins.end(),
1949 []( const ERC_SCH_PIN_CONTEXT& lhs, const ERC_SCH_PIN_CONTEXT& rhs )
1950 {
1951 int ret = StrNumCmp( lhs.Pin()->GetParentSymbol()->GetRef( &lhs.Sheet() ),
1952 rhs.Pin()->GetParentSymbol()->GetRef( &rhs.Sheet() ) );
1953
1954 if( ret == 0 )
1955 ret = StrNumCmp( lhs.Pin()->GetNumber(), rhs.Pin()->GetNumber() );
1956
1957 return ret != 0 ? ret < 0 : lhs < rhs;
1958 } );
1959
1960 ERC_SCH_PIN_CONTEXT needsDriver;
1962 bool hasDriver = false;
1963 std::vector<ERC_SCH_PIN_CONTEXT*> pinsNeedingDrivers;
1964 std::vector<ERC_SCH_PIN_CONTEXT*> nonPowerPinsNeedingDrivers;
1965 std::vector<ERC_SCH_PIN_CONTEXT*> powerInPinsNeedingDrivers;
1966
1967 // We need different drivers for power nets and normal nets.
1968 // A power net has at least one pin having the ELECTRICAL_PINTYPE::PT_POWER_IN
1969 // and power nets can be driven only by ELECTRICAL_PINTYPE::PT_POWER_OUT pins
1970 bool ispowerNet = false;
1971
1972 for( ERC_SCH_PIN_CONTEXT& refPin : pins )
1973 {
1974 if( refPin.Pin()->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
1975 {
1976 ispowerNet = true;
1977 break;
1978 }
1979 }
1980
1981 std::vector<std::tuple<iterator_t, iterator_t, PIN_ERROR>> pin_mismatches;
1982 std::map<iterator_t, int> pin_mismatch_counts;
1983
1984 for( auto refIt = pins.begin(); refIt != pins.end(); ++refIt )
1985 {
1986 ERC_SCH_PIN_CONTEXT& refPin = *refIt;
1987 ELECTRICAL_PINTYPE refType = refPin.Pin()->GetType();
1988
1989 if( DrivenPinTypes.contains( refType ) )
1990 {
1991 // needsDriver will be the pin shown in the error report eventually, so try to
1992 // upgrade to a "better" pin if possible: something visible and only a power symbol
1993 // if this net needs a power driver
1994 pinsNeedingDrivers.push_back( &refPin );
1995
1996 if( !refPin.Pin()->IsPower() )
1997 nonPowerPinsNeedingDrivers.push_back( &refPin );
1998
1999 if( refType == ELECTRICAL_PINTYPE::PT_POWER_IN )
2000 powerInPinsNeedingDrivers.push_back( &refPin );
2001
2002 if( !needsDriver.Pin()
2003 || ( !needsDriver.Pin()->IsVisible() && refPin.Pin()->IsVisible() )
2004 || ( ispowerNet != ( needsDriverType == ELECTRICAL_PINTYPE::PT_POWER_IN )
2005 && ispowerNet == ( refType == ELECTRICAL_PINTYPE::PT_POWER_IN ) ) )
2006 {
2007 needsDriver = refPin;
2008 needsDriverType = needsDriver.Pin()->GetType();
2009 }
2010 }
2011
2012 if( ispowerNet )
2013 hasDriver |= ( DrivingPowerPinTypes.count( refType ) != 0 );
2014 else
2015 hasDriver |= ( DrivingPinTypes.count( refType ) != 0 );
2016
2017 for( auto testIt = refIt + 1; testIt != pins.end(); ++testIt )
2018 {
2019 ERC_SCH_PIN_CONTEXT& testPin = *testIt;
2020
2021 // Multiple pins in the same symbol that share a type,
2022 // name and position are considered
2023 // "stacked" and shouldn't trigger ERC errors
2024 if( refPin.Pin()->IsStacked( testPin.Pin() ) && refPin.Sheet() == testPin.Sheet() )
2025 continue;
2026
2027 ELECTRICAL_PINTYPE testType = testPin.Pin()->GetType();
2028
2029 if( ispowerNet )
2030 hasDriver |= DrivingPowerPinTypes.contains( testType );
2031 else
2032 hasDriver |= DrivingPinTypes.contains( testType );
2033
2034 PIN_ERROR pinError = m_settings.GetPinMapValue( refType, testType );
2035
2036 if( pinError != PIN_ERROR::OK && m_settings.IsTestEnabled( ercErrorCode( pinError ) ) )
2037 {
2038 pin_mismatches.emplace_back( std::tuple<iterator_t, iterator_t,
2039 PIN_ERROR>{ refIt, testIt, pinError } );
2040
2041 if( m_settings.GetERCSortingMetric() == ERC_PIN_SORTING_METRIC::SM_HEURISTICS )
2042 {
2043 pin_mismatch_counts[refIt] = m_settings.GetPinTypeWeight( refIt->Pin()->GetType() );
2044 pin_mismatch_counts[testIt] = m_settings.GetPinTypeWeight( testIt->Pin()->GetType() );
2045 }
2046 else
2047 {
2048 if( !pin_mismatch_counts.contains( testIt ) )
2049 pin_mismatch_counts.emplace( testIt, 1 );
2050 else
2051 pin_mismatch_counts[testIt]++;
2052
2053 if( !pin_mismatch_counts.contains( refIt ) )
2054 pin_mismatch_counts.emplace( refIt, 1 );
2055 else
2056 pin_mismatch_counts[refIt]++;
2057 }
2058 }
2059 }
2060 }
2061
2062 std::multimap<size_t, iterator_t, std::greater<size_t>> pins_dsc;
2063
2064 std::transform( pin_mismatch_counts.begin(), pin_mismatch_counts.end(),
2065 std::inserter( pins_dsc, pins_dsc.begin() ),
2066 []( const auto& p )
2067 {
2068 return std::pair<size_t, iterator_t>( p.second, p.first );
2069 } );
2070
2071 for( const auto& [amount, pinItBind] : pins_dsc )
2072 {
2073 auto& pinIt = pinItBind;
2074
2075 if( pin_mismatches.empty() )
2076 break;
2077
2078 SCH_PIN* pin = pinIt->Pin();
2079 VECTOR2I position = pin->GetPosition();
2080
2081 iterator_t nearest_pin = pins.end();
2082 double smallest_distance = std::numeric_limits<double>::infinity();
2083 PIN_ERROR pinError;
2084
2085 std::erase_if(
2086 pin_mismatches,
2087 [&]( const auto& tuple )
2088 {
2089 iterator_t other;
2090
2091 if( pinIt == std::get<0>( tuple ) )
2092 other = std::get<1>( tuple );
2093 else if( pinIt == std::get<1>( tuple ) )
2094 other = std::get<0>( tuple );
2095 else
2096 return false;
2097
2098 if( ( *pinIt ).Sheet().Cmp( ( *other ).Sheet() ) != 0 )
2099 {
2100 if( std::isinf( smallest_distance ) )
2101 {
2102 nearest_pin = other;
2103 pinError = std::get<2>( tuple );
2104 }
2105 }
2106 else
2107 {
2108 double distance = position.Distance( ( *other ).Pin()->GetPosition() );
2109
2110 if( std::isinf( smallest_distance ) || distance < smallest_distance )
2111 {
2112 smallest_distance = distance;
2113 nearest_pin = other;
2114 pinError = std::get<2>( tuple );
2115 }
2116 }
2117
2118 return true;
2119 } );
2120
2121 if( nearest_pin != pins.end() )
2122 {
2123 SCH_PIN* other_pin = nearest_pin->Pin();
2124 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ercErrorCode( pinError ) );
2125
2126 ercItem->SetItems( pin, other_pin );
2127 ercItem->SetSheetSpecificPath( pinIt->Sheet() );
2128 ercItem->SetItemsSheetPaths( pinIt->Sheet(), nearest_pin->Sheet() );
2129
2130 ercItem->SetErrorMessage( wxString::Format( _( "Pins of type %s and %s are connected" ),
2131 ElectricalPinTypeGetText( pin->GetType() ),
2132 ElectricalPinTypeGetText( other_pin->GetType() ) ) );
2133
2134 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
2135 pinToScreenMap[pin]->Append( marker );
2136 errors++;
2137 }
2138 }
2139
2140 if( needsDriver.Pin() && !hasDriver && !has_noconnect )
2141 {
2142 int err_code = ispowerNet ? ERCE_POWERPIN_NOT_DRIVEN : ERCE_PIN_NOT_DRIVEN;
2143
2144 // NEW: For power nets, before reporting a not-driven error, look across the
2145 // net chain (multi-net chain formed via passives) to see if there is a
2146 // power driver pin on any other net in the same chain. If so, suppress the
2147 // error because the net chain as a whole is driven.
2148 bool suppressForNetChainDriver = false;
2149
2150 if( ispowerNet && m_schematic && m_schematic->ConnectionGraph() )
2151 {
2152 const wxString& thisNetName = net.first.Name;
2153 const auto& netChains = m_schematic->ConnectionGraph()->GetCommittedNetChains();
2154
2155 for( const auto& sig : netChains )
2156 {
2157 if( !sig )
2158 continue;
2159
2160 const auto& sigNets = sig->GetNets();
2161 bool containsThisNet = std::find( sigNets.begin(), sigNets.end(), thisNetName ) != sigNets.end();
2162
2163 if( !containsThisNet )
2164 continue;
2165
2166 // Look for a different net in this chain that has a power driver.
2167 for( const wxString& otherNet : sigNets )
2168 {
2169 if( otherNet == thisNetName )
2170 continue; // skip same net (we already know it lacks a driver)
2171
2172 if( powerDrivenNets.contains( otherNet ) )
2173 {
2174 suppressForNetChainDriver = true;
2175 break;
2176 }
2177 }
2178
2179 break; // examined the containing chain
2180 }
2181 }
2182
2183 if( !suppressForNetChainDriver && m_settings.IsTestEnabled( err_code ) )
2184 {
2185 std::vector<ERC_SCH_PIN_CONTEXT*> pinsToMark;
2186
2187 // The marker should land on a pin matching the error message: for an
2188 // ERCE_POWERPIN_NOT_DRIVEN error mark a PT_POWER_IN pin (which is what the
2189 // error refers to), for ERCE_PIN_NOT_DRIVEN prefer a pin that is not on a
2190 // power symbol so the marker is anchored to the consuming pin rather than
2191 // a power flag.
2192 if( m_showAllErrors )
2193 {
2194 if( ispowerNet && !powerInPinsNeedingDrivers.empty() )
2195 pinsToMark = powerInPinsNeedingDrivers;
2196 else if( !nonPowerPinsNeedingDrivers.empty() )
2197 pinsToMark = nonPowerPinsNeedingDrivers;
2198 else
2199 pinsToMark = pinsNeedingDrivers;
2200 }
2201 else
2202 {
2203 if( ispowerNet && !powerInPinsNeedingDrivers.empty() )
2204 pinsToMark.push_back( powerInPinsNeedingDrivers.front() );
2205 else
2206 pinsToMark.push_back( &needsDriver );
2207 }
2208
2209 for( ERC_SCH_PIN_CONTEXT* pinCtx : pinsToMark )
2210 {
2211 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( err_code );
2212
2213 ercItem->SetItems( pinCtx->Pin() );
2214 ercItem->SetSheetSpecificPath( pinCtx->Sheet() );
2215 ercItem->SetItemsSheetPaths( pinCtx->Sheet() );
2216
2217 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pinCtx->Pin()->GetPosition() );
2218 pinToScreenMap[pinCtx->Pin()]->Append( marker );
2219 errors++;
2220 }
2221 }
2222 }
2223 }
2224
2225 // --- Additional net-chain-level checking ---
2226 // If a pin participates in a grouped net chain (spanning multiple nets via passives), ensure
2227 // that all other pins reachable through that chain are electrically compatible even if
2228 // they reside on different nets.
2229 // We only consider pairs on DIFFERENT nets here to avoid duplicating existing net-level
2230 // mismatches already reported above.
2231 if( m_schematic && m_schematic->ConnectionGraph() )
2232 {
2233 auto& netChains = m_schematic->ConnectionGraph()->GetCommittedNetChains();
2234 wxLogTrace( traceSchNetChain, "ERC TestPinToPin: cross-chain phase start chains=%zu",
2235 netChains.size() );
2236
2237 for( const auto& sig : netChains )
2238 {
2239 if( !sig )
2240 continue;
2241
2242 const wxString chainName = sig->GetName();
2243 const auto& sigNets = sig->GetNets();
2244
2245 // Collect all pin contexts across the nets in this chain.
2246 struct CHAIN_PIN
2247 {
2248 ERC_SCH_PIN_CONTEXT context;
2249 const wxString* net;
2250 };
2251 std::vector<CHAIN_PIN> netChainPins;
2252 netChainPins.reserve( sigNets.size() * 4 );
2253
2254 for( const wxString& n : sigNets )
2255 {
2256 auto it = netToPins.find( n );
2257 if( it != netToPins.end() )
2258 {
2259 for( const ERC_SCH_PIN_CONTEXT& context : it->second )
2260 netChainPins.push_back( { context, &it->first } );
2261 }
2262 }
2263
2264 if( netChainPins.size() < 2 )
2265 continue; // nothing to compare
2266
2267 wxLogTrace( traceSchNetChain,
2268 "ERC TestPinToPin: chain '%s' nets=%zu collectedPins=%zu",
2269 TO_UTF8( chainName ), sigNets.size(), netChainPins.size() );
2270
2271 // For deterministic behavior, sort by reference/pin number similar to earlier pass.
2272 std::sort( netChainPins.begin(), netChainPins.end(),
2273 []( const CHAIN_PIN& left, const CHAIN_PIN& right )
2274 {
2275 const auto& lhs = left.context;
2276 const auto& rhs = right.context;
2277 int ret = StrNumCmp( lhs.Pin()->GetParentSymbol()->GetRef( &lhs.Sheet() ),
2278 rhs.Pin()->GetParentSymbol()->GetRef( &rhs.Sheet() ) );
2279 if( ret == 0 )
2280 ret = StrNumCmp( lhs.Pin()->GetNumber(), rhs.Pin()->GetNumber() );
2281 return ret != 0 ? ret < 0 : lhs < rhs;
2282 } );
2283
2284 for( size_t i = 0; i < netChainPins.size(); ++i )
2285 {
2286 const auto& aContext = netChainPins[i].context;
2287 SCH_PIN* aPin = aContext.Pin();
2288 ELECTRICAL_PINTYPE aType = aPin->GetType();
2289 const wxString& aNet = *netChainPins[i].net;
2290
2291 for( size_t j = i + 1; j < netChainPins.size(); ++j )
2292 {
2293 const auto& bContext = netChainPins[j].context;
2294 SCH_PIN* bPin = bContext.Pin();
2295 const wxString& bNet = *netChainPins[j].net;
2296
2297 if( aNet == bNet )
2298 continue; // already handled at net-level
2299
2300 ELECTRICAL_PINTYPE bType = bPin->GetType();
2301 PIN_ERROR pinError = m_settings.GetPinMapValue( aType, bType );
2302
2303 if( pinError != PIN_ERROR::OK && m_settings.IsTestEnabled( ercErrorCode( pinError ) ) )
2304 {
2305 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ercErrorCode( pinError ) );
2306
2307 ercItem->SetItems( aPin, bPin );
2308 ercItem->SetSheetSpecificPath( aContext.Sheet() );
2309 ercItem->SetItemsSheetPaths( aContext.Sheet(), bContext.Sheet() );
2310 ercItem->SetErrorMessage( wxString::Format( _( "Pins of type %s and %s are connected via "
2311 "net chain %s" ),
2312 ElectricalPinTypeGetText( aType ),
2313 ElectricalPinTypeGetText( bType ), chainName ) );
2314
2315 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), aPin->GetPosition() );
2316 aContext.Sheet().LastScreen()->Append( marker );
2317 errors++;
2318 }
2319 }
2320 }
2321 }
2322 }
2323
2324 return errors;
2325}
2326
2327
2329{
2330 int errors = 0;
2331
2332 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
2333 {
2334 ERC_MARKER_PLACER markers( *m_schematic );
2335
2336 for( const auto& conflict : m_schematic->Connectivity().Engine().MultiUnitPinConflicts() )
2337 {
2338 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_NET );
2339 ercItem->SetErrorMessage( wxString::Format( _( "Pin %s is connected to both %s and %s" ),
2340 conflict.number,
2341 conflict.otherNet,
2342 conflict.firstNet ) );
2343 ercItem->SetItems( std::vector<KIID>{ conflict.other.item, conflict.first.item } );
2344 markers.Place( std::move( ercItem ), conflict.other.sheet, conflict.other.position, conflict.other.sheet,
2345 conflict.first.sheet );
2346 }
2347
2348 return markers.Count();
2349 }
2350
2351 struct PIN_ON_NET
2352 {
2353 wxString m_netName;
2354 SCH_PIN* m_pin;
2355 SCH_SHEET_PATH m_sheet;
2356 };
2357
2358 std::unordered_map<wxString, std::vector<PIN_ON_NET>> pinToNetMap;
2359
2360 for( const std::pair<NET_NAME_CODE_CACHE_KEY, std::vector<CONNECTION_SUBGRAPH*>> net : m_nets )
2361 {
2362 const wxString& netName = net.first.Name;
2363
2364 for( CONNECTION_SUBGRAPH* subgraph : net.second )
2365 {
2366 for( SCH_ITEM* item : subgraph->GetItems() )
2367 {
2368 if( item->Type() == SCH_PIN_T )
2369 {
2370 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
2371 const SCH_SHEET_PATH& sheet = subgraph->GetSheet();
2372
2373 if( !pin->GetParentSymbol()->IsMultiUnit() )
2374 continue;
2375
2376 wxString name = pin->GetParentSymbol()->GetRef( &sheet ) + ":" + pin->GetShownNumber();
2377
2378 pinToNetMap[name].push_back( { netName, pin, sheet } );
2379 }
2380 }
2381 }
2382 }
2383
2384 // Pick the reference net/pin deterministically, so the same conflict yields the same marker on every ERC
2385 // run. While this won't necessarily match existing ERC exclusions, it will at least increase match fidelity
2386 // on future saves/reads.
2387 std::vector<wxString> conflicted;
2388
2389 for( const auto& [name, pins] : pinToNetMap )
2390 {
2391 for( const PIN_ON_NET& candidate : pins )
2392 {
2393 if( candidate.m_netName != pins.front().m_netName )
2394 {
2395 conflicted.push_back( name );
2396 break;
2397 }
2398 }
2399 }
2400
2401 std::sort( conflicted.begin(), conflicted.end() );
2402
2403 for( const wxString& name : conflicted )
2404 {
2405 std::vector<PIN_ON_NET> pins = pinToNetMap[name];
2406
2407 std::sort( pins.begin(), pins.end(),
2408 []( const PIN_ON_NET& a, const PIN_ON_NET& b )
2409 {
2410 if( a.m_netName != b.m_netName )
2411 return a.m_netName < b.m_netName;
2412
2413 return a.m_pin->m_Uuid < b.m_pin->m_Uuid;
2414 } );
2415
2416 const PIN_ON_NET& first = pins.front();
2417
2418 for( const PIN_ON_NET& other : pins )
2419 {
2420 if( other.m_netName == first.m_netName )
2421 continue;
2422
2423 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DIFFERENT_UNIT_NET );
2424
2425 ercItem->SetErrorMessage( wxString::Format( _( "Pin %s is connected to both %s and %s" ),
2426 other.m_pin->GetShownNumber(),
2427 other.m_netName,
2428 first.m_netName ) );
2429
2430 ercItem->SetItems( other.m_pin, first.m_pin );
2431 ercItem->SetSheetSpecificPath( other.m_sheet );
2432 ercItem->SetItemsSheetPaths( other.m_sheet, first.m_sheet );
2433
2434 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), other.m_pin->GetPosition() );
2435 other.m_sheet.LastScreen()->Append( marker );
2436 errors += 1;
2437 break;
2438 }
2439 }
2440
2441 return errors;
2442}
2443
2444
2446{
2447 const ERC_SETTINGS& settings = aSchematic.ErcSettings();
2448 const auto& connectivity = aSchematic.Connectivity().Engine();
2449 ERC_MARKER_PLACER markers( aSchematic );
2450
2452 {
2453 for( const SCH_CONNECTIVITY::SOURCE_LOCATION& pin : connectivity.WiredImplicitPowerPins() )
2454 {
2455 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_WIRED_IMPLICIT_POWER );
2456 ercItem->SetItems( pin.item );
2457 markers.Place( std::move( ercItem ), pin.sheet, pin.position, ITEM_PATHS::MAIN );
2458 }
2459 }
2460
2461 if( settings.IsTestEnabled( ERCE_DRIVER_CONFLICT ) )
2462 {
2463 for( const SCH_CONNECTIVITY::DRIVER_CONFLICT& conflict : connectivity.DriverConflicts() )
2464 {
2465 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DRIVER_CONFLICT );
2466 ercItem->SetItems( conflict.first, conflict.second );
2467 ercItem->SetErrorMessage( wxString::Format( _( "Both %s and %s are attached to the same items; "
2468 "%s will be used in the netlist" ),
2469 conflict.firstName,
2470 conflict.secondName,
2471 conflict.firstName ) );
2472 markers.Place( std::move( ercItem ), conflict.sheet, conflict.position, ITEM_PATHS::BOTH );
2473 }
2474 }
2475
2477 {
2478 for( const SCH_CONNECTIVITY::WIRE_ENDPOINT& endpoint : connectivity.DanglingWireEndpoints() )
2479 {
2480 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_UNCONNECTED_WIRE_ENDPOINT );
2481 ercItem->SetItems( endpoint.item );
2482 ercItem->SetErrorMessage( endpoint.busEntry ? _( "Unconnected wire to bus entry" )
2483 : _( "Unconnected wire endpoint" ) );
2484 markers.Place( std::move( ercItem ), endpoint.sheet, endpoint.position );
2485 }
2486 }
2487
2488 if( settings.IsTestEnabled( ERCE_BUS_TO_NET_CONFLICT ) )
2489 {
2490 for( const SCH_CONNECTIVITY::BUS_NET_CONFLICT& conflict : connectivity.BusNetConflicts() )
2491 {
2492 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_TO_NET_CONFLICT );
2493 ercItem->SetItems( conflict.net, conflict.bus );
2494 markers.Place( std::move( ercItem ), conflict.sheet, conflict.position );
2495 }
2496 }
2497
2498 if( settings.IsTestEnabled( ERCE_BUS_TO_BUS_CONFLICT ) )
2499 {
2500 for( const SCH_CONNECTIVITY::BUS_BUS_CONFLICT& conflict : connectivity.BusBusConflicts() )
2501 {
2502 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_TO_BUS_CONFLICT );
2503 ercItem->SetItems( conflict.canonical, conflict.other );
2504
2505 if( conflict.mixedShapes )
2506 ercItem->SetErrorMessage( _( "Bus vector and bus group are graphically connected" ) );
2507
2508 markers.Place( std::move( ercItem ), conflict.sheet, conflict.position );
2509 }
2510 }
2511
2512 if( settings.IsTestEnabled( ERCE_BUS_ENTRY_CONFLICT ) )
2513 {
2514 for( const SCH_CONNECTIVITY::BUS_ENTRY_CONFLICT& conflict : connectivity.BusEntryConflicts() )
2515 {
2516 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_BUS_ENTRY_CONFLICT );
2517 ercItem->SetItems( conflict.entry, conflict.bus );
2518 ercItem->SetErrorMessage( wxString::Format( _( "Net %s is graphically connected to bus %s but is not a"
2519 " member of that bus" ),
2520 UnescapeString( conflict.netName ),
2521 UnescapeString( conflict.busName ) ) );
2522 markers.Place( std::move( ercItem ), conflict.sheet, conflict.position );
2523 }
2524 }
2525
2527 {
2528 for( const SCH_CONNECTIVITY::NO_CONNECT_FLAG_ERROR& diagnostic : connectivity.NoConnectFlagErrors() )
2529 {
2530 const int code = diagnostic.connected ? ERCE_NOCONNECT_CONNECTED : ERCE_NOCONNECT_NOT_CONNECTED;
2531
2532 if( !settings.IsTestEnabled( code ) )
2533 continue;
2534
2535 markers.Report( code,
2536 diagnostic.pin == niluuid ? std::vector<KIID>{ diagnostic.flag }
2537 : std::vector<KIID>{ diagnostic.pin, diagnostic.flag },
2538 diagnostic.sheet, diagnostic.position, ITEM_PATHS::MAIN );
2539 }
2540 }
2541
2542 if( settings.IsTestEnabled( ERCE_PIN_NOT_CONNECTED ) )
2543 {
2544 for( const SCH_CONNECTIVITY::UNCONNECTED_PIN& pin : connectivity.UnconnectedPins() )
2545 markers.Report( ERCE_PIN_NOT_CONNECTED, { pin.item }, pin.sheet, pin.position, ITEM_PATHS::MAIN );
2546 }
2547
2549 {
2550 using ERROR_KIND = SCH_CONNECTIVITY::HIERARCHY_ERROR::KIND;
2551
2552 for( const SCH_CONNECTIVITY::HIERARCHY_ERROR& error : connectivity.HierarchyErrors() )
2553 {
2554 const bool mismatch = error.kind == ERROR_KIND::MISSING_LABEL || error.kind == ERROR_KIND::MISSING_PIN;
2555 const int code = mismatch ? ERCE_HIERACHICAL_LABEL : ERCE_PIN_NOT_CONNECTED;
2556
2557 if( !settings.IsTestEnabled( code ) )
2558 continue;
2559
2560 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( code );
2561 ercItem->SetItems( std::vector<KIID>{ error.item } );
2562 const wxString name = UnescapeString( error.name );
2563
2564 switch( error.kind )
2565 {
2566 case ERROR_KIND::ROOT_LABEL:
2567 ercItem->SetErrorMessage( wxString::Format( _( "Hierarchical label '%s' in root sheet cannot be "
2568 "connected to non-existent parent sheet" ),
2569 name ) );
2570 break;
2571
2572 case ERROR_KIND::MISSING_LABEL:
2573 ercItem->SetErrorMessage( wxString::Format( _( "Sheet pin %s has no matching hierarchical label "
2574 "inside the sheet" ),
2575 name ) );
2576 break;
2577
2578 case ERROR_KIND::MISSING_PIN:
2579 ercItem->SetErrorMessage( wxString::Format( _( "Hierarchical label %s has no matching sheet pin "
2580 "in the parent sheet" ),
2581 name ) );
2582 break;
2583
2584 case ERROR_KIND::DANGLING_PIN:
2585 break;
2586 }
2587
2588 // Root label markers are not sheet specific, and saved exclusions keep that shape
2589 const bool rootLabel = error.kind == ERROR_KIND::ROOT_LABEL;
2590 markers.Place( std::move( ercItem ), error.sheet, error.position,
2591 rootLabel ? ITEM_PATHS::NONE : ITEM_PATHS::MAIN, !rootLabel );
2592 }
2593 }
2594
2596 {
2597 for( const SCH_CONNECTIVITY::LABEL_CONNECTION_ERROR& label : connectivity.LabelConnectionErrors() )
2598 {
2599 const int code = label.singlePin ? ERCE_LABEL_SINGLE_PIN : ERCE_LABEL_NOT_CONNECTED;
2600
2601 if( settings.IsTestEnabled( code ) )
2602 markers.Report( code, { label.item }, label.sheet, label.position );
2603 }
2604 }
2605
2606 if( settings.IsTestEnabled( ERCE_LABEL_NOT_CONNECTED ) )
2607 {
2608 for( const SCH_CONNECTIVITY::LABEL_LOCATION& label : connectivity.DanglingDirectives() )
2609 markers.Report( ERCE_LABEL_NOT_CONNECTED, { label.item }, label.sheet, label.position );
2610 }
2611
2612 if( settings.IsTestEnabled( ERCE_SINGLE_GLOBAL_LABEL ) )
2613 {
2614 for( const SCH_CONNECTIVITY::LABEL_LOCATION& label : connectivity.SingleGlobalLabels() )
2615 {
2616 markers.Report( ERCE_SINGLE_GLOBAL_LABEL, { label.item }, label.sheet, label.position,
2617 ITEM_PATHS::MAIN );
2618 }
2619 }
2620
2621 if( settings.IsTestEnabled( ERCE_WIRE_DANGLING ) )
2622 {
2623 for( const SCH_CONNECTIVITY::FLOATING_WIRE& group : connectivity.FloatingWires() )
2624 markers.Report( ERCE_WIRE_DANGLING, group.items, group.sheet, group.position );
2625 }
2626
2627 return markers.Count();
2628}
2629
2630
2632{
2633 const bool engine = ADVANCED_CFG::GetCfg().m_ConnectivityEngine;
2634 int errors = 0;
2635
2636 for( const SCH_SHEET_PATH& sheet : m_sheetList )
2637 {
2638 SCH_SCREEN* screen = sheet.LastScreen();
2639
2640 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
2641 {
2642 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2643 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
2644
2645 if( !libSymbol )
2646 continue;
2647
2648 if( libSymbol->GetDuplicatePinNumbersAreJumpers() )
2649 continue;
2650
2651 std::vector<SCH_PIN*> pins = symbol->GetPins( &sheet );
2652
2653 std::map<wxString, std::vector<std::pair<SCH_PIN*, wxString>>> pinsByNumber;
2654
2655 for( SCH_PIN* pin : pins )
2656 {
2657 wxString netName;
2658
2659 if( engine )
2660 netName = pin->GetConnectionName( &sheet ).value_or( wxString() );
2661 else if( SCH_CONNECTION* conn = pin->Connection( &sheet ) )
2662 netName = conn->GetNetName();
2663
2664 pinsByNumber[pin->GetNumber()].emplace_back( pin, netName );
2665 }
2666
2667 for( const auto& [pinNumber, pinNetPairs] : pinsByNumber )
2668 {
2669 if( pinNetPairs.size() < 2 )
2670 continue;
2671
2672 wxString firstNet = pinNetPairs[0].second;
2673 bool hasDifferentNets = false;
2674 SCH_PIN* conflictPin = nullptr;
2675
2676 for( size_t i = 1; i < pinNetPairs.size(); i++ )
2677 {
2678 if( pinNetPairs[i].second != firstNet )
2679 {
2680 hasDifferentNets = true;
2681 conflictPin = pinNetPairs[i].first;
2682 break;
2683 }
2684 }
2685
2686 if( hasDifferentNets )
2687 {
2688 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_DUPLICATE_PIN_ERROR );
2689 wxString msg;
2690
2691 msg.Printf( _( "Pin %s on symbol '%s' is connected to different nets: %s and %s" ),
2692 pinNumber,
2693 symbol->GetRef( &sheet ),
2694 firstNet.IsEmpty() ? _( "<no net>" ) : firstNet,
2695 pinNetPairs[1].second.IsEmpty() ? _( "<no net>" ) : pinNetPairs[1].second );
2696
2697 ercItem->SetErrorMessage( msg );
2698 ercItem->SetItems( pinNetPairs[0].first, conflictPin );
2699 ercItem->SetSheetSpecificPath( sheet );
2700 ercItem->SetItemsSheetPaths( sheet, sheet );
2701
2702 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pinNetPairs[0].first->GetPosition() );
2703 screen->Append( marker );
2704 errors++;
2705 }
2706 }
2707 }
2708 }
2709
2710 return errors;
2711}
2712
2713
2715{
2716 int errors = 0;
2717
2718 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
2719 {
2720 ERC_MARKER_PLACER markers( *m_schematic );
2721
2722 for( const auto& mismatch : m_schematic->Connectivity().Engine().GroundPinErrors() )
2723 {
2724 markers.Report( ERCE_GROUND_PIN_NOT_GROUND, { mismatch.pin }, mismatch.sheet, mismatch.position,
2725 ITEM_PATHS::MAIN,
2726 wxString::Format( _( "Pin %s not connected to ground net" ), mismatch.name ) );
2727 }
2728
2729 return markers.Count();
2730 }
2731
2732 auto isGround =
2733 []( const wxString& txt )
2734 {
2735 wxString upper = txt.Upper();
2736
2737 return upper.Contains( wxT( "GND" ) )
2738 || upper == wxT( "EARTH" )
2739 || upper.StartsWith( wxT( "EARTH_" ) )
2740 || upper == wxT( "VSS" )
2741 || upper == wxT( "VSSA" );
2742 };
2743
2744 for( const SCH_SHEET_PATH& sheet : m_sheetList )
2745 {
2746 SCH_SCREEN* screen = sheet.LastScreen();
2747
2748 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
2749 {
2750 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2751 bool hasGroundNet = false;
2752 std::vector<SCH_PIN*> mismatched;
2753
2754 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
2755 {
2756 // We are only interested in power pins
2757 if( pin->GetType() != ELECTRICAL_PINTYPE::PT_POWER_OUT
2758 && pin->GetType() != ELECTRICAL_PINTYPE::PT_POWER_IN )
2759 {
2760 continue;
2761 }
2762
2763 const SCH_CONNECTION* conn = pin->Connection( &sheet );
2764 const wxString net = conn ? conn->Name( true ) : wxString();
2765 const bool netIsGround = isGround( net );
2766
2767 if( netIsGround )
2768 hasGroundNet = true;
2769
2770 if( isGround( pin->GetShownName() ) && !netIsGround )
2771 mismatched.push_back( pin );
2772 }
2773
2774 if( hasGroundNet )
2775 {
2776 for( SCH_PIN* pin : mismatched )
2777 {
2778 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_GROUND_PIN_NOT_GROUND );
2779
2780 ercItem->SetErrorMessage( wxString::Format( _( "Pin %s not connected to ground net" ),
2781 pin->GetShownName() ) );
2782 ercItem->SetItems( pin );
2783 ercItem->SetSheetSpecificPath( sheet );
2784 ercItem->SetItemsSheetPaths( sheet );
2785
2786 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
2787 screen->Append( marker );
2788 errors++;
2789 }
2790 }
2791 }
2792 }
2793
2794 return errors;
2795}
2796
2797
2799{
2800 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
2801 {
2802 return reportSourceErrors( *m_schematic, ERCE_STACKED_PIN_SYNTAX,
2803 m_schematic->Connectivity().Engine().InvalidPinNotation() );
2804 }
2805
2806 int warnings = 0;
2807
2808 for( const SCH_SHEET_PATH& sheet : m_sheetList )
2809 {
2810 SCH_SCREEN* screen = sheet.LastScreen();
2811
2812 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
2813 {
2814 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
2815
2816 for( SCH_PIN* pin : symbol->GetPins( &sheet ) )
2817 {
2818 bool valid;
2819 pin->GetStackedPinNumbers( &valid );
2820
2821 if( !valid )
2822 {
2823 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_STACKED_PIN_SYNTAX );
2824 ercItem->SetItems( pin );
2825 ercItem->SetSheetSpecificPath( sheet );
2826 ercItem->SetItemsSheetPaths( sheet );
2827
2828 SCH_MARKER* marker = new SCH_MARKER( std::move( ercItem ), pin->GetPosition() );
2829 screen->Append( marker );
2830 warnings++;
2831 }
2832 }
2833 }
2834 }
2835
2836 return warnings;
2837}
2838
2839
2841{
2843 std::map<wxString, NAMED_ITEM> globalLabels;
2844 std::map<wxString, NAMED_ITEM> localLabels;
2845
2846 for( const NAMED_ITEM& item : collectNamedItems( *m_schematic, false ) )
2847 {
2848 if( item.type == SCH_HIER_LABEL_T )
2849 continue;
2850
2851 auto& labels = item.global ? globalLabels : localLabels;
2852 auto found = labels.find( item.name );
2853
2854 // For one item, direct KIID_PATH comparison selects its shallowest instance
2855 if( found == labels.end()
2856 || item.item < found->second.item
2857 || ( item.item == found->second.item && item.sheet < found->second.sheet ) )
2858 {
2859 labels[item.name] = item;
2860 }
2861 }
2862
2863 ERC_MARKER_PLACER markers( *m_schematic );
2864
2865 for( const auto& [name, global] : globalLabels )
2866 {
2867 const auto local = localLabels.find( name );
2868
2869 if( local == localLabels.end() )
2870 continue;
2871
2872 const ERCE_T code = global.type == SCH_PIN_T && local->second.type == SCH_PIN_T ? ERCE_SAME_LOCAL_GLOBAL_POWER
2874 reportNameConflict( markers, m_settings, code, global, local->second );
2875 }
2876
2877 return markers.Count();
2878}
2879
2880
2882{
2884 std::map<wxString, std::vector<NAMED_ITEM>> generalMap;
2885
2886 auto normalizeLabel =
2887 []( const wxString& aLabel )
2888 {
2889 wxString stripped = aLabel.Strip( wxString::leading ).Strip( wxString::trailing );
2890 wxString prefix;
2891 wxString value;
2892 wxString units;
2893
2894 SplitString( stripped, &prefix, &value, &units );
2895
2896 if( prefix == wxT( "+" ) )
2897 prefix = wxEmptyString;
2898
2900 units.Replace( wxS( "µ" ), 'u' );
2901 units.Replace( wxS( "μ" ), 'u' );
2902
2903 return prefix.Lower() + value.Lower() + units.Lower();
2904 };
2905
2906 for( const NAMED_ITEM& item : collectNamedItems( *m_schematic, true ) )
2907 generalMap[normalizeLabel( item.name )].push_back( item );
2908
2909 ERC_MARKER_PLACER markers( *m_schematic );
2910
2911 for( auto& [name, entries] : generalMap )
2912 {
2913 std::sort( entries.begin(), entries.end(), []( const NAMED_ITEM& a, const NAMED_ITEM& b )
2914 {
2915 // Saved exclusions record which item is main, so order by path text rather than depth
2916 if( a.sheet != b.sheet )
2917 return a.sheet.AsString() < b.sheet.AsString();
2918
2919 return a.item < b.item;
2920 } );
2921
2922 // Report each unordered pair whose shown text differs only in case only once.
2923 for( size_t ii = 0; ii < entries.size(); ++ii )
2924 {
2925 for( size_t jj = ii + 1; jj < entries.size(); ++jj )
2926 {
2927 const NAMED_ITEM& a = entries[ii];
2928 const NAMED_ITEM& b = entries[jj];
2929
2930 if( a.name == b.name )
2931 continue;
2932
2933 // Similar local labels on different sheets are fine.
2934 if( a.type == SCH_LABEL_T && b.type == SCH_LABEL_T && a.sheet != b.sheet )
2935 continue;
2936
2938
2939 if( a.type == SCH_PIN_T && b.type == SCH_PIN_T )
2940 code = ERCE_SIMILAR_POWER;
2941 else if( a.type == SCH_PIN_T || b.type == SCH_PIN_T )
2943
2944 reportNameConflict( markers, m_settings, code, a, b );
2945 }
2946 }
2947 }
2948
2949 return markers.Count();
2950}
2951
2952
2954{
2955 wxCHECK( m_schematic, 0 );
2956
2957 LIBRARY_MANAGER& manager = Pgm().GetLibraryManager();
2959 int err_count = 0;
2960
2961 const bool captured = ADVANCED_CFG::GetCfg().m_ConnectivityEngine;
2962
2963 struct LIBRARY_ISSUE
2964 {
2965 int code;
2966 wxString message;
2967 };
2968
2969 const auto check =
2970 [&]( const SCH_CONNECTIVITY::LIBRARY_SYMBOL_FACT& aSource, const SCH_SYMBOL* aSymbol )
2971 {
2972 std::vector<LIBRARY_ISSUE> issues;
2973 const wxString libName = aSource.library.GetLibNickname();
2974 std::optional<const LIBRARY_TABLE_ROW*> optRow = manager.GetRow( LIBRARY_TABLE_TYPE::SYMBOL, libName );
2975
2976 if( !optRow || ( *optRow )->Disabled() )
2977 {
2978 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
2979 {
2980 issues.push_back( { ERCE_LIB_SYMBOL_ISSUES,
2981 wxString::Format( _( "The current configuration does not include the "
2982 "symbol library '%s'" ),
2983 UnescapeString( libName ) )
2984 } );
2985 }
2986
2987 return issues;
2988 }
2989
2990 if( !adapter->IsLibraryLoaded( libName ) )
2991 {
2992 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
2993 {
2994 std::optional<wxString> uri = manager.GetFullURI( LIBRARY_TABLE_TYPE::SYMBOL, libName, true );
2995 wxCHECK2( uri.has_value(), uri = wxEmptyString );
2996 issues.push_back( { ERCE_LIB_SYMBOL_ISSUES,
2997 wxString::Format( _( "The symbol library '%s' was not found at '%s'" ),
2998 UnescapeString( libName ), *uri )
2999 } );
3000 }
3001
3002 return issues;
3003 }
3004
3005 const wxString symbolName = aSource.library.GetLibItemName();
3006 LIB_SYMBOL* libSymbol = adapter->LoadSymbol( aSource.library );
3007
3008 if( !libSymbol )
3009 {
3010 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES ) )
3011 {
3012 issues.push_back( { ERCE_LIB_SYMBOL_ISSUES,
3013 wxString::Format( _( "Symbol '%s' not found in symbol library '%s'" ),
3014 UnescapeString( symbolName ),
3015 UnescapeString( libName ) )
3016 } );
3017 }
3018
3019 return issues;
3020 }
3021
3022 if( !m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_MISMATCH ) )
3023 return issues;
3024
3025 std::unique_ptr<LIB_SYMBOL> flattenedSymbol = libSymbol->Flatten();
3026 const int flags = m_schematic->Settings().SymbolCompareFlags();
3027 bool mismatch = false;
3028
3029 if( captured )
3030 {
3032 {
3033 mismatch = !SCH_CONNECTIVITY::ExtractLibrarySymbolFact( *flattenedSymbol )
3034 .Matches( aSource, flags );
3035 }
3036 }
3037 else
3038 {
3039 wxCHECK( aSymbol && aSymbol->GetLibSymbolRef(), issues );
3040
3041 LIB_SYMBOL* embedded = aSymbol->GetLibSymbolRef().get();
3042 std::vector<wxString> messages;
3043
3044 // Duplicate pins can be valid on the same net; TestDuplicatePinNets checks their nets
3045 if( !embedded->GetDuplicatePinNumbersAreJumpers() )
3046 {
3047 UNITS_PROVIDER unitsProvider( schIUScale, EDA_UNITS::MILS );
3048 CheckDuplicatePins( embedded, messages, &unitsProvider );
3049 }
3050
3051 mismatch = messages.empty() && flattenedSymbol->Compare( *embedded, flags ) != 0;
3052 }
3053
3054 if( mismatch )
3055 {
3056 issues.push_back( { ERCE_LIB_SYMBOL_MISMATCH,
3057 wxString::Format( _( "Symbol '%s' doesn't match copy in library '%s'" ),
3058 UnescapeString( symbolName ),
3059 UnescapeString( libName ) )
3060 } );
3061 }
3062
3063 return issues;
3064 };
3065
3066 // Library results depend only on the shared screen, so every instance reuses one lookup
3067 std::map<std::pair<const SCH_SCREEN*, KIID>, std::vector<LIBRARY_ISSUE>> results;
3068
3069 for( const SCH_SHEET_PATH& path : m_schematic->Hierarchy() )
3070 {
3071 SCH_SCREEN* screen = path.LastScreen();
3072 std::vector<SCH_CONNECTIVITY::LIBRARY_SYMBOL_FACT> sources;
3073
3074 // Legacy sources keep their symbol because duplicate UUIDs make screen lookup ambiguous
3075 std::vector<const SCH_SYMBOL*> symbols;
3076
3077 if( captured )
3078 {
3079 sources = m_schematic->Connectivity().Engine().LibrarySymbols( path.PathRef() );
3080 }
3081 else
3082 {
3083 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
3084 {
3085 const SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
3086 SCH_CONNECTIVITY::LIBRARY_SYMBOL_FACT& source = sources.emplace_back();
3087
3088 source.id = symbol->m_Uuid;
3089 source.position = symbol->GetPosition();
3090 source.library = symbol->GetLibId();
3091 source.hasEmbeddedSymbol = bool( symbol->GetLibSymbolRef() );
3092 symbols.push_back( symbol );
3093 }
3094 }
3095
3096 std::vector<SCH_MARKER*> markers;
3097
3098 for( size_t ii = 0; ii < sources.size(); ++ii )
3099 {
3100 const auto& source = sources[ii];
3101
3102 if( !source.hasEmbeddedSymbol )
3103 continue;
3104
3105 auto result = results.find( { screen, source.id } );
3106
3107 if( result == results.end() )
3108 {
3109 const SCH_SYMBOL* symbol = captured ? nullptr : symbols[ii];
3110 result = results.emplace( std::make_pair( screen, source.id ), check( source, symbol ) ).first;
3111 }
3112
3113 for( const LIBRARY_ISSUE& issue : result->second )
3114 {
3115 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( issue.code );
3116 ercItem->SetItems( std::vector<KIID>{ source.id } );
3117 ercItem->SetSheetSpecificPath( path );
3118 ercItem->SetItemsSheetPaths( path );
3119 ercItem->SetErrorMessage( issue.message );
3120 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), source.position ) );
3121 }
3122 }
3123
3124 for( SCH_MARKER* marker : markers )
3125 {
3126 screen->Append( marker );
3127 err_count += 1;
3128 }
3129 }
3130
3131 return err_count;
3132}
3133
3134
3136{
3137 wxCHECK( m_schematic, 0 );
3138
3139 if( std::optional<LIBRARY_MANAGER_ADAPTER*> adapter =
3140 Pgm().GetLibraryManager().Adapter( LIBRARY_TABLE_TYPE::FOOTPRINT ) )
3141 {
3142 ( *adapter )->BlockUntilLoaded();
3143 }
3144
3147 ERC_MARKER_PLACER markers( *m_schematic );
3148
3149 for( const auto& source : collectFootprints( *m_schematic ) )
3150 {
3151 if( source.footprint.IsEmpty() )
3152 continue;
3153
3154 wxString msg;
3155 LIB_ID fpID;
3156
3157 if( fpID.Parse( source.footprint, true ) >= 0 )
3158 {
3159 msg.Printf( _( "'%s' is not a valid footprint identifier" ), source.footprint );
3160 }
3161 else
3162 {
3163 const wxString libName = fpID.GetLibNickname();
3164 const wxString fpName = fpID.GetLibItemName();
3165 const int ret = linkTester( source.footprint, aProject );
3166
3168 {
3169 msg.Printf( _( "The current configuration does not include the footprint library '%s'" ),
3170 libName );
3171 }
3173 {
3174 msg.Printf( _( "The footprint library '%s' is not enabled in the current configuration" ),
3175 libName );
3176 }
3178 {
3179 msg.Printf( _( "Footprint '%s' not found in library '%s'" ), fpName, libName );
3180 }
3181 else
3182 {
3183 continue;
3184 }
3185 }
3186
3187 markers.Report( ERCE_FOOTPRINT_LINK_ISSUES, { source.item }, source.sheet, source.position, ITEM_PATHS::MAIN,
3188 msg );
3189 }
3190
3191 return markers.Count();
3192}
3193
3194
3196{
3197 wxCHECK( m_schematic, 0 );
3198 ERC_MARKER_PLACER markers( *m_schematic );
3199
3200 for( const auto& source : collectFootprints( *m_schematic ) )
3201 {
3202 if( source.filters.empty() )
3203 continue;
3204
3205 const wxString lowerId = source.footprint.Lower();
3206 LIB_ID footprint;
3207
3208 // An id rejected at its first character is still checked and reported
3209 if( footprint.Parse( lowerId ) > 0 )
3210 continue;
3211
3212 const wxString lowerItemName = footprint.GetUniStringLibItemName().Lower();
3213 const bool found = std::ranges::any_of( source.filters,
3214 [&]( const wxString& filter )
3215 {
3216 // If the filter contains a ':' character, include the library name in the pattern
3217 return filter.Contains( wxS( ":" ) ) ? lowerId.Matches( filter.Lower() )
3218 : lowerItemName.Matches( filter.Lower() );
3219 } );
3220
3221 if( found )
3222 continue;
3223
3224 markers.Report( ERCE_FOOTPRINT_FILTERS, { source.item }, source.sheet, source.position, ITEM_PATHS::MAIN,
3225 wxString::Format( _( "Assigned footprint (%s) doesn't match footprint filters (%s)" ),
3226 footprint.GetUniStringLibItemName(), wxJoin( source.filters, ' ' ) ) );
3227 }
3228
3229 return markers.Count();
3230}
3231
3232
3234{
3235 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
3236 {
3237 const int grid = m_schematic->Settings().m_ConnectionGridSize;
3238 return reportSourceErrors( *m_schematic, ERCE_ENDPOINT_OFF_GRID,
3239 m_schematic->Connectivity().Engine().OffGridEndpoints( grid ) );
3240 }
3241
3242 const int gridSize = m_schematic->Settings().m_ConnectionGridSize;
3243 int err_count = 0;
3244
3245 for( SCH_SCREEN* screen = m_screens.GetFirst(); screen; screen = m_screens.GetNext() )
3246 {
3247 std::vector<SCH_MARKER*> markers;
3248
3249 for( SCH_ITEM* item : screen->Items() )
3250 {
3251 if( item->Type() == SCH_LINE_T && item->IsConnectable() )
3252 {
3253 SCH_LINE* line = static_cast<SCH_LINE*>( item );
3254
3255 if( ( line->GetStartPoint().x % gridSize ) != 0
3256 || ( line->GetStartPoint().y % gridSize ) != 0 )
3257 {
3258 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
3259 ercItem->SetItems( line );
3260
3261 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), line->GetStartPoint() ) );
3262 }
3263 else if( ( line->GetEndPoint().x % gridSize ) != 0
3264 || ( line->GetEndPoint().y % gridSize ) != 0 )
3265 {
3266 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
3267 ercItem->SetItems( line );
3268
3269 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), line->GetEndPoint() ) );
3270 }
3271 }
3272 if( item->Type() == SCH_BUS_WIRE_ENTRY_T )
3273 {
3274 SCH_BUS_WIRE_ENTRY* entry = static_cast<SCH_BUS_WIRE_ENTRY*>( item );
3275
3276 for( const VECTOR2I& point : entry->GetConnectionPoints() )
3277 {
3278 if( ( point.x % gridSize ) != 0
3279 || ( point.y % gridSize ) != 0 )
3280 {
3281 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
3282 ercItem->SetItems( entry );
3283
3284 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), point ) );
3285 }
3286 }
3287 }
3288 else if( item->Type() == SCH_SYMBOL_T )
3289 {
3290 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
3291
3292 for( SCH_PIN* pin : symbol->GetPins( nullptr ) )
3293 {
3294 if( pin->GetType() == ELECTRICAL_PINTYPE::PT_NC )
3295 continue;
3296
3297 VECTOR2I pinPos = pin->GetPosition();
3298
3299 if( ( pinPos.x % gridSize ) != 0 || ( pinPos.y % gridSize ) != 0 )
3300 {
3301 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_ENDPOINT_OFF_GRID );
3302 ercItem->SetItems( pin );
3303
3304 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), pinPos ) );
3305 break;
3306 }
3307 }
3308 }
3309 }
3310
3311 for( SCH_MARKER* marker : markers )
3312 {
3313 screen->Append( marker );
3314 err_count += 1;
3315 }
3316 }
3317
3318 return err_count;
3319}
3320
3321
3323{
3325 int err_count = 0;
3326 SIM_LIB_MGR libMgr( &m_schematic->Project() );
3327 wxString variant = m_schematic->GetCurrentVariant();
3328
3329 for( SCH_SHEET_PATH& sheet : m_sheetList )
3330 {
3331 const auto sources = ADVANCED_CFG::GetCfg().m_ConnectivityEngine
3332 ? m_schematic->Connectivity().SimulationModels( sheet.PathRef() )
3334 std::vector<SCH_MARKER*> markers;
3335
3336 for( const auto& source : sources )
3337 {
3338 reporter.Clear();
3339 libMgr.CreateModel( source.input, true, reporter );
3340
3341 if( reporter.HasMessage() )
3342 {
3343 wxString msg = reporter.GetMessages();
3344 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( ERCE_SIMULATION_MODEL );
3345
3346 //Remove \n and \r at e.o.l if any:
3347 msg.Trim();
3348
3349 ercItem->SetErrorMessage( msg );
3350 ercItem->SetItems( source.id );
3351 ercItem->SetSheetSpecificPath( sheet );
3352 ercItem->SetItemsSheetPaths( sheet );
3353
3354 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), source.position ) );
3355 }
3356 }
3357
3358 for( SCH_MARKER* marker : markers )
3359 {
3360 sheet.LastScreen()->Append( marker );
3361 err_count += 1;
3362 }
3363 }
3364
3365 return err_count;
3366}
3367
3368
3370{
3371 wxCHECK( m_schematic, 0 );
3372
3374
3375 if( !adapter )
3376 return 0;
3377
3378 int err_count = 0;
3379
3380 // Flatten each alternate once per ERC run rather than once per referencing symbol.
3381 std::map<wxString, std::unique_ptr<LIB_SYMBOL>> flatAltCache;
3382
3383 for( SCH_SHEET_PATH& sheet : m_sheetList )
3384 {
3385 SCH_SCREEN* screen = sheet.LastScreen();
3386
3387 if( !screen )
3388 continue;
3389
3390 std::vector<SCH_MARKER*> markers;
3391 std::vector<SCH_CONNECTIVITY::VARIANT_SYMBOL_FACT> sources;
3392 std::vector<SCH_CONNECTIVITY::LIBRARY_SYMBOL_FACT> libraries;
3393
3394 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
3395 {
3396 sources = m_schematic->Connectivity().Engine().VariantSymbols( sheet.PathRef() );
3397
3398 if( sources.empty() )
3399 continue;
3400
3401 libraries = m_schematic->Connectivity().Engine().LibrarySymbols( sheet.PathRef() );
3402 }
3403 else
3404 {
3405 for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
3406 {
3407 const SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
3408 auto source = SCH_CONNECTIVITY::ExtractVariantSymbolFact( *symbol, sheet );
3409
3410 if( !source )
3411 continue;
3412
3413 auto& base = libraries.emplace_back();
3414
3415 if( symbol->GetLibSymbolRef() )
3417
3418 base.id = symbol->m_Uuid;
3419 base.position = symbol->GetPosition();
3420 base.library = symbol->GetLibId();
3421 sources.push_back( std::move( *source ) );
3422 }
3423
3424 std::sort( libraries.begin(), libraries.end(),
3425 []( const auto& a, const auto& b )
3426 {
3427 return a.id < b.id;
3428 } );
3429 }
3430
3431 for( const auto& source : sources )
3432 {
3433 const auto base = std::lower_bound( libraries.begin(), libraries.end(), source.id,
3434 []( const auto& a, const KIID& id )
3435 {
3436 return a.id < id;
3437 } );
3438
3439 if( base == libraries.end() || base->id != source.id )
3440 continue;
3441
3442 auto addMarker =
3443 [&]( int aErrorCode, const wxString& aMessage )
3444 {
3445 std::shared_ptr<ERC_ITEM> ercItem = ERC_ITEM::Create( aErrorCode );
3446
3447 ercItem->SetItems( std::vector<KIID>{ source.id } );
3448 ercItem->SetSheetSpecificPath( sheet );
3449 ercItem->SetItemsSheetPaths( sheet );
3450 ercItem->SetErrorMessage( aMessage );
3451
3452 markers.emplace_back( new SCH_MARKER( std::move( ercItem ), base->position ) );
3453 err_count++;
3454 };
3455
3456 for( const auto& [variantName, libId] : source.overrides )
3457 {
3458 wxString libIdStr = libId.Format();
3459
3460 // A self-referencing override is ignored by resolution, so skip it here too.
3461 if( libId == base->library )
3462 continue;
3463
3464 auto cacheIt = flatAltCache.find( libIdStr );
3465
3466 if( cacheIt == flatAltCache.end() )
3467 {
3468 std::unique_ptr<LIB_SYMBOL> flatAlt;
3469
3470 try
3471 {
3472 if( LIB_SYMBOL* altSymbol = adapter->LoadSymbol( libId ) )
3473 flatAlt = altSymbol->Flatten();
3474 }
3475 catch( const IO_ERROR& )
3476 {
3477 }
3478
3479 cacheIt = flatAltCache.emplace( libIdStr, std::move( flatAlt ) ).first;
3480 }
3481
3482 const LIB_SYMBOL* flatAlt = cacheIt->second.get();
3483
3484 if( !flatAlt )
3485 {
3486 if( m_settings.IsTestEnabled( ERCE_VARIANT_SYMBOL_INVALID ) )
3487 {
3488 addMarker( ERCE_VARIANT_SYMBOL_INVALID,
3489 wxString::Format( _( "Variant '%s': symbol '%s' not found in libraries" ),
3490 variantName, libIdStr ) );
3491 }
3492
3493 continue;
3494 }
3495
3496 if( !m_settings.IsTestEnabled( ERCE_VARIANT_SYMBOL_INCOMPATIBLE ) )
3497 continue;
3498
3499 if( !base->hasEmbeddedSymbol )
3500 continue;
3501
3502 std::vector<VARIANT_COMPAT_RESULT> issues =
3503 ValidateVariantSymbolCompatibility( *base, *flatAlt );
3504
3505 for( const VARIANT_COMPAT_RESULT& issue : issues )
3506 {
3508 wxString::Format( _( "Variant '%s', alternate '%s': %s" ),
3509 variantName, libIdStr, issue.detail ) );
3510 }
3511 }
3512 }
3513
3514 for( SCH_MARKER* marker : markers )
3515 screen->Append( marker );
3516 }
3517
3518 return err_count;
3519}
3520
3521
3523 KIFACE* aCvPcb, PROJECT* aProject, PROGRESS_REPORTER* aProgressReporter )
3524{
3525 if( !aEditFrame )
3526 {
3527 m_schematic->RecordERCExclusions();
3528 m_screens.DeleteAllMarkers( MARKER_BASE::MARKER_ERC, true );
3529 }
3530
3531 if( aEditFrame )
3532 {
3533 if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
3534 aEditFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
3535 else
3536 aEditFrame->RecalculateConnections( nullptr, NO_CLEANUP );
3537 }
3538 else if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
3539 {
3540 // Captured sources track revisions and text context, so an update refreshes job overrides
3541 m_schematic->Connectivity().Recalculate( *m_schematic );
3542 }
3543 else
3544 {
3545 m_schematic->RebuildConnectivity( nullptr, aProgressReporter );
3546 }
3547
3548 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine
3549 && m_settings.IsTestEnabled( ERCE_SIMULATION_MODEL ) )
3550 {
3551 m_schematic->Connectivity().PrepareSimulationModels( *m_schematic );
3552 }
3553
3554 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine
3555 && m_settings.IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) )
3556 {
3557 m_schematic->Connectivity().PrepareTextChecks( *m_schematic, aDrawingSheet != nullptr );
3558 }
3559
3560 // Test duplicate sheet names inside a given sheet. While one can have multiple references
3561 // to the same file, each must have a unique name.
3562 if( m_settings.IsTestEnabled( ERCE_DUPLICATE_SHEET_NAME ) )
3563 {
3564 if( aProgressReporter )
3565 aProgressReporter->AdvancePhase( _( "Checking sheet names..." ) );
3566
3568 }
3569
3570 // The schematic editor's dialog used to own this, so headless runs never checked annotation
3572
3573 if( m_settings.IsTestEnabled( ERCE_DUPLICATE_SHEET_SUFFIX ) )
3575
3576 if( m_settings.IsTestEnabled( ERCE_REF_SUFFIX_MISMATCH ) )
3578
3579 // Test pin-to-pad maps for stale pins, duplicate pad targets and bad pad references (issue #2282).
3580 if( m_settings.IsTestEnabled( ERCE_PIN_MAP_STALE_PIN ) || m_settings.IsTestEnabled( ERCE_PIN_MAP_DUPLICATE_PAD )
3581 || m_settings.IsTestEnabled( ERCE_PIN_MAP_BAD_PAD ) || m_settings.IsTestEnabled( ERCE_PIN_MAP_UNMAPPED_PIN ) )
3582 {
3583 if( aProgressReporter )
3584 aProgressReporter->AdvancePhase( _( "Checking pin maps..." ) );
3585
3586 TestPinMap( aCvPcb, aProject );
3587 }
3588
3589 if( aProgressReporter )
3590 aProgressReporter->AdvancePhase( _( "Checking conflicts..." ) );
3591
3592 if( ADVANCED_CFG::GetCfg().m_ConnectivityEngine )
3594 else
3595 m_schematic->ConnectionGraph()->RunERC();
3596
3597 if( aProgressReporter )
3598 aProgressReporter->AdvancePhase( _( "Checking units..." ) );
3599
3600 // Test is all units of each multiunit symbol have the same footprint assigned.
3601 if( m_settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_FP ) )
3602 {
3603 if( aProgressReporter )
3604 aProgressReporter->AdvancePhase( _( "Checking footprints..." ) );
3605
3607 }
3608
3609 if( m_settings.IsTestEnabled( ERCE_MISSING_UNIT )
3610 || m_settings.IsTestEnabled( ERCE_MISSING_INPUT_PIN )
3611 || m_settings.IsTestEnabled( ERCE_MISSING_POWER_INPUT_PIN )
3612 || m_settings.IsTestEnabled( ERCE_MISSING_BIDI_PIN ) )
3613 {
3615 }
3616
3617 if( aProgressReporter )
3618 aProgressReporter->AdvancePhase( _( "Checking pins..." ) );
3619
3620 if( m_settings.IsTestEnabled( ERCE_DIFFERENT_UNIT_NET ) )
3622
3623 if( m_settings.IsTestEnabled( ERCE_DUPLICATE_PIN_ERROR ) )
3625
3626 // Test pins on each net against the pin connection table
3627 if( m_settings.IsTestEnabled( ERCE_PIN_TO_PIN_ERROR )
3628 || m_settings.IsTestEnabled( ERCE_PIN_TO_PIN_WARNING )
3629 || m_settings.IsTestEnabled( ERCE_POWERPIN_NOT_DRIVEN )
3630 || m_settings.IsTestEnabled( ERCE_PIN_NOT_DRIVEN ) )
3631 {
3632 TestPinToPin();
3633 }
3634
3635 if( m_settings.IsTestEnabled( ERCE_GROUND_PIN_NOT_GROUND ) )
3637
3638 if( m_settings.IsTestEnabled( ERCE_STACKED_PIN_SYNTAX ) )
3640
3641 // Test similar labels (i;e. labels which are identical when
3642 // using case insensitive comparisons)
3643 if( m_settings.IsTestEnabled( ERCE_SIMILAR_LABELS )
3644 || m_settings.IsTestEnabled( ERCE_SIMILAR_POWER )
3645 || m_settings.IsTestEnabled( ERCE_SIMILAR_LABEL_AND_POWER ) )
3646 {
3647 if( aProgressReporter )
3648 aProgressReporter->AdvancePhase( _( "Checking similar labels..." ) );
3649
3651 }
3652
3653 if( m_settings.IsTestEnabled( ERCE_SAME_LOCAL_GLOBAL_LABEL )
3654 || m_settings.IsTestEnabled( ERCE_SAME_LOCAL_GLOBAL_POWER ) )
3655 {
3656 if( aProgressReporter )
3657 aProgressReporter->AdvancePhase( _( "Checking local and global labels..." ) );
3658
3660 }
3661
3662 if( m_settings.IsTestEnabled( ERCE_UNRESOLVED_VARIABLE ) )
3663 {
3664 if( aProgressReporter )
3665 aProgressReporter->AdvancePhase( _( "Checking for unresolved variables..." ) );
3666
3667 TestTextVars( aDrawingSheet );
3668 }
3669
3670 if( m_settings.IsTestEnabled( ERCE_FIELD_NAME_WHITESPACE ) )
3671 {
3672 if( aProgressReporter )
3673 aProgressReporter->AdvancePhase( _( "Checking field names..." ) );
3674
3676 }
3677
3678 if( m_settings.IsTestEnabled( ERCE_EMPTY_POWER_VALUE ) )
3679 {
3680 if( aProgressReporter )
3681 aProgressReporter->AdvancePhase( _( "Checking for empty power symbol values..." ) );
3682
3684 }
3685
3686 if( m_settings.IsTestEnabled( ERCE_EMPTY_LABEL_NAME ) )
3687 {
3688 if( aProgressReporter )
3689 aProgressReporter->AdvancePhase( _( "Checking for empty label names..." ) );
3690
3692 }
3693
3694 if( m_settings.IsTestEnabled( ERCE_SIMULATION_MODEL ) )
3695 {
3696 if( aProgressReporter )
3697 aProgressReporter->AdvancePhase( _( "Checking SPICE models..." ) );
3698
3700 }
3701
3702 if( m_settings.IsTestEnabled( ERCE_NOCONNECT_CONNECTED ) )
3703 {
3704 if( aProgressReporter )
3705 aProgressReporter->AdvancePhase( _( "Checking no connect pins for connections..." ) );
3706
3708 }
3709
3710 if( m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_ISSUES )
3711 || m_settings.IsTestEnabled( ERCE_LIB_SYMBOL_MISMATCH ) )
3712 {
3713 if( aProgressReporter )
3714 aProgressReporter->AdvancePhase( _( "Checking for library symbol issues..." ) );
3715
3717 }
3718
3719 if( m_settings.IsTestEnabled( ERCE_FOOTPRINT_LINK_ISSUES ) && aCvPcb )
3720 {
3721 if( aProgressReporter )
3722 aProgressReporter->AdvancePhase( _( "Checking for footprint link issues..." ) );
3723
3724 TestFootprintLinkIssues( aCvPcb, aProject );
3725 }
3726
3727 if( m_settings.IsTestEnabled( ERCE_FOOTPRINT_FILTERS ) )
3728 {
3729 if( aProgressReporter )
3730 aProgressReporter->AdvancePhase( _( "Checking footprint assignments against footprint filters..." ) );
3731
3733 }
3734
3735 if( m_settings.IsTestEnabled( ERCE_ENDPOINT_OFF_GRID ) )
3736 {
3737 if( aProgressReporter )
3738 aProgressReporter->AdvancePhase( _( "Checking for off grid pins and wires..." ) );
3739
3741 }
3742
3743 if( m_settings.IsTestEnabled( ERCE_FOUR_WAY_JUNCTION ) )
3744 {
3745 if( aProgressReporter )
3746 aProgressReporter->AdvancePhase( _( "Checking for four way junctions..." ) );
3747
3749 }
3750
3751 if( m_settings.IsTestEnabled( ERCE_LABEL_MULTIPLE_WIRES ) )
3752 {
3753 if( aProgressReporter )
3754 aProgressReporter->AdvancePhase( _( "Checking for labels on more than one wire..." ) );
3755
3757 }
3758
3759 if( m_settings.IsTestEnabled( ERCE_UNDEFINED_NETCLASS ) )
3760 {
3761 if( aProgressReporter )
3762 aProgressReporter->AdvancePhase( _( "Checking for undefined netclasses..." ) );
3763
3765 }
3766
3767 if( m_settings.IsTestEnabled( ERCE_VARIANT_SYMBOL_INVALID )
3768 || m_settings.IsTestEnabled( ERCE_VARIANT_SYMBOL_INCOMPATIBLE ) )
3769 {
3770 if( aProgressReporter )
3771 aProgressReporter->AdvancePhase( _( "Checking variant symbols..." ) );
3772
3774 }
3775
3776 m_schematic->ResolveERCExclusionsPostUpdate();
3777}
int index
const char * name
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
const NET_MAP & GetNetMap() const
A subgraph is a set of items that are electrically connected on a single sheet.
const std::set< SCH_ITEM * > & GetItems() const
Provide a read-only reference to the items in the subgraph.
const SCH_ITEM * GetNoConnect() const
const SCH_SHEET_PATH & GetSheet() const
Base class to handle basic graphic items.
Store the list of graphic items: rect, lines, polygons and texts to draw/plot the title block and fra...
DS_DRAW_ITEM_BASE * GetFirst()
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.
void SetSheetName(const wxString &aSheetName)
Set the sheet name to draw/plot.
void SetSheetLayer(const wxString &aSheetLayer)
Set the sheet layer to draw/plot.
void SetSheetCount(int aSheetCount)
Set the value of the count of sheets, for basic inscriptions.
void SetPageNumber(const wxString &aPageNumber)
Set the value of the sheet number.
DS_DRAW_ITEM_BASE * GetNext()
void SetProject(const PROJECT *aProject)
A graphic text.
const PAGE_INFO & GetPageInfo()
const TITLE_BLOCK & GetTitleBlock()
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
EE_TYPE Overlapping(const BOX2I &aRect) const
Definition sch_rtree.h:253
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:248
static std::shared_ptr< ERC_ITEM > Create(int aErrorCode)
Constructs an ERC_ITEM for the given error code.
Definition erc_item.cpp:321
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.
Container for ERC settings.
bool IsTestEnabled(int aErrorCode) const
ERC_PIN_SORTING_METRIC GetERCSortingMetric() const
Get the type of sorting metric the ERC checker should use to resolve multi-pin errors.
PIN_ERROR GetPinMapValue(int aFirstType, int aSecondType) const
int GetPinTypeWeight(ELECTRICAL_PINTYPE aPinType) const
Get the weight for an electrical pin type.
int TestLibSymbolIssues()
Test symbols for changed library symbols and broken symbol library links.
Definition erc.cpp:2953
const NET_MAP & m_nets
Definition erc.h:254
int TestStackedPinNotation()
Checks for pin numbers that resemble stacked pin notation but are invalid.
Definition erc.cpp:2798
int TestAnnotation()
Test the annotation of every symbol: unannotated, duplicate and mismatched units.
Definition erc.cpp:1049
ERC_TESTER(SCHEMATIC *aSchematic, bool aShowAllErrors=false)
Definition erc.cpp:337
void TestTextVars(DS_PROXY_VIEW_ITEM *aDrawingSheet)
Check for any unresolved text variable references.
Definition erc.cpp:672
int TestPinToPin()
Checks the full netlist against the pin-to-pin connectivity requirements.
Definition erc.cpp:1892
int TestSimilarLabels()
Checks for labels that differ only in capitalization.
Definition erc.cpp:2881
SCH_MULTI_UNIT_REFERENCE_MAP m_refMap
Definition erc.h:253
SCH_SCREENS m_screens
Definition erc.h:252
int TestEmptyLabelNames()
Check for labels with empty or whitespace-only names.
Definition erc.cpp:838
int TestDuplicateSheetSuffixes()
Test that the instances of each reused sheet compose distinct reference suffixes.
Definition erc.cpp:1079
int TestRefSuffixMismatch()
Report symbols whose saved reference lacked the reference suffix of their sheet instance.
Definition erc.cpp:1101
int TestFootprintLinkIssues(KIFACE *aCvPcb, PROJECT *aProject)
Test footprint links against the current footprint libraries.
Definition erc.cpp:3135
static int TestConnectivity(SCHEMATIC &aSchematic)
Definition erc.cpp:2445
int TestOffGridEndpoints()
Test pins and wire ends for being off grid.
Definition erc.cpp:3233
int TestDuplicateSheetNames(bool aCreateMarker)
Inside a given sheet, one cannot have sheets with duplicate names (file names can be duplicated).
Definition erc.cpp:350
int TestSameLocalGlobalLabel()
Checks for global and local labels with the same name.
Definition erc.cpp:2840
int TestMultUnitPinConflicts()
Checks if shared pins on multi-unit symbols have been connected to different nets.
Definition erc.cpp:2328
int TestEmptyPowerValues()
Check for power symbols whose value resolves to nothing, leaving their net unnamed.
Definition erc.cpp:786
int TestNoConnectPins()
In KiCad 5 and earlier, you could connect stuff up to pins with NC electrical type.
Definition erc.cpp:1471
int TestFootprintFilters()
Test symbols to ensure that assigned footprint passes any given footprint filters.
Definition erc.cpp:3195
int TestPinMap(KIFACE *aCvPcb, PROJECT *aProject)
Check pin-to-pad maps (issue #2282): stale pin references, duplicate pad targets, bad pads and unmapp...
Definition erc.cpp:417
int TestFieldNameWhitespace()
Check for field names with leading or trailing whitespace.
Definition erc.cpp:883
int TestDuplicatePinNets()
Checks if duplicate pin numbers within a symbol are connected to different nets.
Definition erc.cpp:2631
ERC_SETTINGS & m_settings
Definition erc.h:250
int TestFourWayJunction()
Test to see if there are potentially confusing 4-way junctions in the schematic.
Definition erc.cpp:1378
int TestMissingNetclasses()
Tests for netclasses that are referenced but not defined.
Definition erc.cpp:1234
int TestSimModelIssues()
Test SPICE models for various issues.
Definition erc.cpp:3322
SCH_SHEET_LIST m_sheetList
Definition erc.h:251
bool m_showAllErrors
Definition erc.h:255
int TestGroundPins()
Checks for ground-labeled pins not on a ground net while another pin is.
Definition erc.cpp:2714
SCHEMATIC * m_schematic
Definition erc.h:249
std::vector< SCH_CONNECTIVITY::MULTI_UNIT_GROUP > multiUnitSources() const
Definition erc.cpp:968
void RunTests(DS_PROXY_VIEW_ITEM *aDrawingSheet, SCH_EDIT_FRAME *aEditFrame, KIFACE *aCvPcb, PROJECT *aProject, PROGRESS_REPORTER *aProgressReporter)
Definition erc.cpp:3522
int TestMissingUnits()
Test for uninstantiated units of multi unit symbols.
Definition erc.cpp:1153
int TestLabelMultipleWires()
Test to see if there are labels that are connected to more than one wire.
Definition erc.cpp:1307
int TestVariantSymbols()
Test all variant symbol overrides for resolution and pin compatibility.
Definition erc.cpp:3369
int TestMultiunitFootprints()
Test if all units of each multiunit symbol have the same footprint assigned.
Definition erc.cpp:1002
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Represents an (ordered) list of JUMPER_GROUP objects.
const std::vector< JUMPER_GROUP > & GetAll() const
Represents a group of jumper pins or pads, keyed by name.
wxString AsString() const
Definition kiid.cpp:423
Definition kiid.h:46
bool IsLibraryLoaded(const wxString &aNickname)
std::optional< wxString > GetFullURI(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, bool aSubstituted=false)
Return the full location specifying URI for the LIB, either in original UI form or in environment var...
std::optional< LIBRARY_TABLE_ROW * > GetRow(LIBRARY_TABLE_TYPE aType, const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH)
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:65
wxString GetUniStringLibId() const
Definition lib_id.h:144
const wxString GetUniStringLibItemName() const
Get strings for display messages in dialogs.
Definition lib_id.h:108
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:83
Define a library symbol object.
Definition lib_symbol.h:114
const std::vector< ASSOCIATED_FOOTPRINT > & GetEffectiveAssociatedFootprints() const
Definition lib_symbol.h:302
std::unique_ptr< LIB_SYMBOL > Flatten() const
Return a flattened symbol inheritance to the caller.
bool GetDuplicatePinNumbersAreJumpers() const
Definition lib_symbol.h:886
virtual LIBRARY_MANAGER & GetLibraryManager() const
Definition pgm_base.h:126
A symbol-owned ordered set of named pin maps.
Definition pin_map.h:124
const std::vector< PIN_MAP > & GetAll() const
Definition pin_map.h:139
const PIN_MAP * FindByName(const wxString &aName) const
Definition pin_map.cpp:133
A named pin map.
Definition pin_map.h:65
const std::vector< PIN_MAP_ENTRY > & GetEntries() const
Definition pin_map.h:92
const wxString & GetName() const
Definition pin_map.h:70
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.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
Container for project specific data.
Definition project.h:63
Holds all the data relating to one schematic.
Definition schematic.h:155
SCH_CONNECTIVITY::NETCHAIN_MANAGER & NetChains() const
Definition schematic.h:412
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
SCH_CONNECTIVITY::FACADE & Connectivity() const
Definition schematic.h:411
CONNECTION_GRAPH * ConnectionGraph() const
Definition schematic.h:414
ERC_SETTINGS & ErcSettings() const
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Class for a wire to bus entry.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
wxString Name(bool aIgnoreSheet=false) const
std::vector< ERC_PIN_NET > PinNets() const
Active pins for each named net, in net name order.
std::vector< NAMED_ITEM > NamedItems() const
Every label and power pin with its resolved name, on every instance.
std::vector< FOOTPRINT_SOURCE > FootprintSources() const
Resolved footprint and filters of every symbol on every instance.
const ENGINE & Engine() const
const std::vector< std::unique_ptr< SCH_NETCHAIN > > & GetCommittedNetChains() const
Return user-created (committed) net chains (legacy accessor retained under net-chain API).
Schematic editor (Eeschema) main window.
bool RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags, PROGRESS_REPORTER *aProgressReporter=nullptr, bool aCleanupDone=false)
Generate the connection data for the entire schematic hierarchy.
wxString GetUntranslatedName() const
Get the untranslated field name for storage, variable look-up, etc.
wxString GetShownText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString, int aDepth=0) const
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:39
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition sch_line.cpp:811
VECTOR2I GetEndPoint() const
Definition sch_line.h:145
VECTOR2I GetStartPoint() const
Definition sch_line.h:136
bool IsEndPoint(const VECTOR2I &aPoint) const override
Test if aPt is an end point of this schematic object.
Definition sch_line.h:88
bool IsGraphicLine() const
Return if the line is a graphic (non electrical line)
bool IsVisible() const
Definition sch_pin.cpp:516
PAD_RESOLUTION
Outcome of pin-to-pad resolution (issue #2282).
Definition sch_pin.h:175
VECTOR2I GetPosition() const override
Definition sch_pin.cpp:381
bool IsStacked(const SCH_PIN *aPin) const
Definition sch_pin.cpp:608
static bool HasIdentityPad(const wxString &aPinNumber, const std::set< wxString > &aPads)
Definition sch_pin.cpp:822
bool IsPower() const
Check if the pin is either a global or local power pin.
Definition sch_pin.cpp:510
ELECTRICAL_PINTYPE GetType() const
Definition sch_pin.cpp:438
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
int CheckAnnotation(ANNOTATION_ERROR_HANDLER aErrorHandler)
Check for annotations errors.
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
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:122
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
const SCH_SHEET * GetSheet(unsigned aIndex) const
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SCREEN * LastScreen()
const KIID_PATH & PathRef() const
Borrow the cached path until this sheet path is modified or destroyed.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:50
std::vector< SCH_FIELD > & GetFields()
Return a reference to the vector holding the sheet's fields.
Definition sch_sheet.h:93
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this sheet.
VECTOR2I GetPosition() const override
Definition sch_sheet.h:548
Schematic symbol object.
Definition sch_symbol.h:76
bool IsAnnotated(const SCH_SHEET_PATH *aSheet) const
Check if the symbol has a valid annotation (reference) for the given sheet path.
const wxString GetFootprintFieldText(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString) const
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
wxString GetBaseRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
bool IsGlobalPower() const override
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
VECTOR2I GetPosition() const override
Definition sch_symbol.h:958
const LIB_ID & GetLibId() const override
Definition sch_symbol.h:166
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
const wxString GetValue(const SCH_SHEET_PATH *aPath, RESOLUTION_CONTEXT aContext, const wxString &aVariantName=wxEmptyString) const override
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition sch_symbol.h:185
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
VECTOR2I GetPosition() const override
Definition sch_text.h:143
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, std::span< const wxString > aPins, REPORTER &aReporter)
An interface to the global shared library manager that is schematic-specific and linked to one projec...
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
A base class for LIB_SYMBOL and SCH_SYMBOL.
Definition symbol.h:60
virtual bool IsGlobalPower() const =0
virtual bool IsLocalPower() const =0
double Distance(const VECTOR2< extended_type > &aVector) const
Compute the distance between two vectors.
Definition vector2d.h:574
A wrapper for reporting to a wxString object.
Definition reporter.h:242
@ FOR_ERC_DRC
Definition common.h:95
@ FOR_NETNAME
Definition common.h:94
@ RESOLVED
Definition common.h:97
#define _(s)
@ NONE
Definition eda_fill.h:42
@ NO_RECURSE
Definition eda_item.h:52
void CheckDuplicatePins(LIB_SYMBOL *aSymbol, std::vector< wxString > &aMessages, UNITS_PROVIDER *aUnitsProvider)
const wxString CommentERC_V[]
Definition erc.cpp:290
const wxString CommentERC_H[]
Definition erc.cpp:273
const std::set< ELECTRICAL_PINTYPE > DrivenPinTypes
Definition erc.cpp:328
const std::set< ELECTRICAL_PINTYPE > DrivingPinTypes
Definition erc.cpp:310
const std::set< ELECTRICAL_PINTYPE > DrivingPowerPinTypes
Definition erc.cpp:322
ERCE_T
ERC error codes.
@ ERCE_POWERPIN_NOT_DRIVEN
Power input pin connected to some others pins but no power out pin to drive it.
@ ERCE_DRIVER_CONFLICT
Conflicting drivers (labels, etc) on a subgraph.
@ ERCE_SIMILAR_POWER
2 power pins are equal for case insensitive comparisons.
@ ERCE_MISSING_POWER_INPUT_PIN
Symbol has power input pins that are not placed on the schematic.
@ ERCE_EMPTY_POWER_VALUE
Power symbol has no value, so it names no net.
@ ERCE_UNCONNECTED_WIRE_ENDPOINT
A label is connected to more than one wire.
@ ERCE_GROUND_PIN_NOT_GROUND
A ground-labeled pin is not on a ground net while another pin is.
@ ERCE_SIMILAR_LABELS
2 labels are equal for case insensitive comparisons.
@ ERCE_VARIANT_SYMBOL_INCOMPATIBLE
Variant symbol override fails pin compatibility.
@ ERCE_STACKED_PIN_SYNTAX
Pin name resembles stacked pin notation.
@ ERCE_LABEL_NOT_CONNECTED
Label not connected to any pins.
@ ERCE_ENDPOINT_OFF_GRID
Pin or wire-end off grid.
@ ERCE_REF_SUFFIX_MISMATCH
Saved reference lacks the suffix of its reused sheet.
@ ERCE_EMPTY_LABEL_NAME
Label has an empty or whitespace-only name.
@ ERCE_SAME_LOCAL_GLOBAL_LABEL
2 labels are equal for case insensitive comparisons.
@ ERCE_BUS_TO_BUS_CONFLICT
A connection between bus objects doesn't share at least one net.
@ ERCE_SIMILAR_LABEL_AND_POWER
label and pin are equal for case insensitive comparisons.
@ ERCE_SAME_LOCAL_GLOBAL_POWER
Local power port and global power port have the same name.
@ ERCE_PIN_MAP_BAD_PAD
Pin map references a pad absent from the footprint.
@ ERCE_LABEL_SINGLE_PIN
A label is connected only to a single pin.
@ ERCE_BUS_ENTRY_CONFLICT
A wire connected to a bus doesn't match the bus.
@ ERCE_FOOTPRINT_LINK_ISSUES
The footprint link is invalid, or points to a missing (or inactive) footprint or library.
@ ERCE_PIN_MAP_DUPLICATE_PAD
Two symbol pins map to one pad (not stacked/jumper).
@ ERCE_BUS_TO_NET_CONFLICT
A bus wire is graphically connected to a net port/pin (or vice versa).
@ ERCE_DUPLICATE_PIN_ERROR
@ ERCE_NOCONNECT_NOT_CONNECTED
A no connect symbol is not connected to anything.
@ ERCE_DIFFERENT_UNIT_NET
Shared pin in a multi-unit symbol is connected to more than one net.
@ ERCE_FOUR_WAY_JUNCTION
A four-way junction was found.
@ ERCE_PIN_NOT_CONNECTED
Pin not connected and not no connect symbol.
@ ERCE_UNDEFINED_NETCLASS
A netclass was referenced but not defined.
@ ERCE_UNRESOLVED_VARIABLE
A text variable could not be resolved.
@ ERCE_DUPLICATE_SHEET_SUFFIX
Two uses of one sheet file share a reference suffix.
@ ERCE_SIMULATION_MODEL
An error was found in the simulation model.
@ ERCE_LIB_SYMBOL_MISMATCH
Symbol doesn't match copy in library.
@ ERCE_GENERIC_ERROR
@ ERCE_DIFFERENT_UNIT_FP
Different units of the same symbol have different footprints assigned.
@ ERCE_NOCONNECT_CONNECTED
A no connect symbol is connected to more than 1 pin.
@ ERCE_PIN_TO_PIN_WARNING
@ ERCE_PIN_NOT_DRIVEN
Pin connected to some others pins but no pin to drive it.
@ ERCE_MISSING_INPUT_PIN
Symbol has input pins that are not placed.
@ ERCE_MISSING_UNIT
Symbol has units that are not placed on the schematic.
@ ERCE_FIELD_NAME_WHITESPACE
Field name has leading or trailing whitespace.
@ ERCE_DUPLICATE_SHEET_NAME
Duplicate sheet names within a given sheet.
@ ERCE_PIN_MAP_STALE_PIN
Pin map references a pin number not on the symbol.
@ ERCE_MISSING_BIDI_PIN
Symbol has bi-directional pins that are not placed.
@ ERCE_LIB_SYMBOL_ISSUES
Symbol not found in active libraries.
@ ERCE_FOOTPRINT_FILTERS
The assigned footprint doesn't match the footprint filters.
@ ERCE_HIERACHICAL_LABEL
Mismatch between hierarchical labels and pins sheets.
@ ERCE_WIRE_DANGLING
Some wires are not connected to anything else.
@ ERCE_GENERIC_WARNING
@ ERCE_VARIANT_SYMBOL_INVALID
Variant symbol override LIB_ID cannot be resolved.
@ ERCE_SINGLE_GLOBAL_LABEL
A label only exists once in the schematic.
@ ERCE_PIN_MAP_UNMAPPED_PIN
A connected pin resolves to no footprint pad.
@ ERCE_LABEL_MULTIPLE_WIRES
A label is connected to more than one wire.
@ ERCE_WIRED_IMPLICIT_POWER
Wired hidden power input also joins its global net by name.
@ ERCE_PIN_TO_PIN_ERROR
PIN_ERROR
The values a pin-to-pin entry in the pin matrix can take on.
bool m_ConnectivityEngine
Use the schematic connectivity engine instead of CONNECTION_GRAPH.
const wxChar *const traceSchNetChain
Flag to enable tracing of schematic net chain rebuild and ERC cross-chain checks.
std::string source
std::string message
@ KIFACE_TEST_FOOTPRINT_LINK_LIBRARY_NOT_ENABLED
Definition kiface_ids.h:89
@ KIFACE_TEST_FOOTPRINT_LINK_NO_LIBRARY
Definition kiface_ids.h:88
@ KIFACE_TEST_FOOTPRINT_LINK_NO_FOOTPRINT
Definition kiface_ids.h:90
Service::Type GetKifaceService(KIFACE *aKiface)
Look up a service exported by a KIFACE.
KIID niluuid(0)
@ MISMATCH
Entries name the host with another key of this type, and none with this one.
Value keys and the key session of the schematic connectivity engine.
SOURCE_LOCATION UNCONNECTED_PIN
std::optional< PIN_MAP_FACT > ExtractPinMapFacts(const SCH_SYMBOL &aSymbol)
std::vector< SIMULATION_MODEL_FACT > ExtractSimulationModelFacts(const SCH_SHEET_PATH &aPath, const wxString &aVariantName)
std::vector< TEXT_CHECK_FACT > ExtractTextChecks(const SCH_SCREEN &aScreen, const SCH_SHEET_PATH &aPath)
SOURCE_LOCATION LABEL_LOCATION
LIBRARY_SYMBOL_FACT ExtractLibrarySymbolFact(const LIB_SYMBOL &aSymbol)
std::vector< TEXT_ASSERTION > ExtractTextAssertions(const wxString &aText)
std::optional< VARIANT_SYMBOL_FACT > ExtractVariantSymbolFact(const SCH_SYMBOL &aSymbol, const SCH_SHEET_PATH &aPath)
std::vector< UNIT_FACT > ExtractUnitFacts(const LIB_SYMBOL &aSymbol)
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition pin_type.h:32
@ PT_INPUT
usual pin input: must be connected
Definition pin_type.h:33
@ PT_NC
not connected (must be left open)
Definition pin_type.h:46
@ PT_OUTPUT
usual output
Definition pin_type.h:34
@ PT_TRISTATE
tri state bus pin
Definition pin_type.h:36
@ PT_NIC
not internally connected (may be connected to anything)
Definition pin_type.h:40
@ PT_BIDI
input or output (like port for a microprocessor)
Definition pin_type.h:35
@ PT_POWER_OUT
output of a regulator: intended to be connected to power input pins
Definition pin_type.h:43
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:42
@ PT_UNSPECIFIED
unknown electrical properties: creates always a warning when connected
Definition pin_type.h:41
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
wxString ElectricalPinTypeGetText(ELECTRICAL_PINTYPE)
Definition pin_type.cpp:204
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
static const std::vector< KICAD_T > labelTypes
Definition sch_field.cpp:49
@ SYMBOL_FILTER_NON_POWER
@ SYMBOL_FILTER_ALL
@ NO_CLEANUP
Definition schematic.h:99
@ GLOBAL_CLEANUP
Definition schematic.h:101
int StrNumCmp(const wxString &aString1, const wxString &aString2, CMP_T aCaseSensitivity)
Compare two strings with alphanumerical content.
std::vector< wxString > ExpandStackedPinNotation(const wxString &aPinName, bool *aValid)
Expand stacked pin notation like [1,2,3], [1-4], [A1-A4], or [AA1-AA3,AB4,CD12-CD14] into individual ...
wxString UnescapeString(const wxString &aSource)
int SplitString(const wxString &strToSplit, wxString *strBeginning, wxString *strDigits, wxString *strEnd)
Break a string into three parts: he alphabetic preamble, the numeric part, and any alphabetic ending.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
A first-class footprint choice on a LIB_SYMBOL, tied to a named pin map.
Definition pin_map.h:159
LIB_ID m_FootprintLibId
Definition pin_map.h:160
Implement a participant in the KIWAY alchemy.
Definition kiway.h:153
One symbol-pin to footprint-pad mapping inside a PIN_MAP.
Definition pin_map.h:42
Two bus claims on one island that share no member, or a bus vector joined to a bus group.
Definition conn_engine.h:82
A bus wire entry whose net is not a member of the bus it touches.
Definition conn_engine.h:95
An island that mixes net and bus items.
Definition conn_engine.h:70
Two different strong names on one island.
Definition conn_engine.h:45
One active symbol pin on one sheet instance, with the reference of its symbol.
Up to four wires and bus entries of one island that has no driver.
A hierarchical label or sheet pin with no partner, or a dangling sheet pin.
A label that connects to nothing, or to only one pin.
bool Matches(const LIBRARY_SYMBOL_FACT &aOther, int aCompareFlags) const
All placed units that share one reference, with the unit table of the library symbol.
One placed unit of an annotated multi-unit symbol.
A label or a power pin with its resolved net name.
A no-connect flag on a net with more than one pin, or on a net with no pin and no label.
One item on one sheet instance, for a diagnostic that needs only a location.
One dangling end of a wire or a bus wire entry.
Definition conn_engine.h:58
A simple container for schematic symbol instance information.
bool m_RefLacksSuffix
Set at load when the saved reference lacked its sheet suffix, cleared when the reference changes.
std::string path
IbisParser parser & reporter
KIBIS_PIN * pin
static std::set< FOOTPRINT * > collectFootprints(const PCB_GROUP *aGroup)
const SHAPE_LINE_CHAIN chain
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ SCH_LINE_T
Definition typeinfo.h:159
@ SCH_NO_CONNECT_T
Definition typeinfo.h:156
@ SCH_SYMBOL_T
Definition typeinfo.h:168
@ SCH_FIELD_T
Definition typeinfo.h:146
@ SCH_LABEL_T
Definition typeinfo.h:163
@ SCH_SHEET_T
Definition typeinfo.h:171
@ SCH_HIER_LABEL_T
Definition typeinfo.h:165
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:157
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:164
@ SCH_PIN_T
Definition typeinfo.h:149
std::vector< VARIANT_COMPAT_RESULT > ValidateVariantSymbolCompatibility(const LIB_SYMBOL &aBase, const LIB_SYMBOL &aCandidate)
Check whether aCandidate can be used as a variant symbol override for aBase.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708