KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_sheet_path.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) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2011 Wayne Stambaugh <[email protected]>
6 * Copyright (C) 1992-2023, 2024 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26#include <refdes_utils.h>
27#include <sch_screen.h>
28#include <sch_item.h>
29#include <sch_marker.h>
30#include <sch_label.h>
31#include <sch_reference_list.h>
32#include <symbol_library.h>
33#include <sch_sheet_path.h>
34#include <sch_symbol.h>
35#include <sch_sheet.h>
36#include <schematic.h>
37#include <template_fieldnames.h>
38#include <trace_helpers.h>
39
40#include <boost/functional/hash.hpp>
41#include <wx/filename.h>
42#include <wx/log.h>
43
44
50{
51public:
53 SCH_ITEM( nullptr, NOT_USED )
54 {}
55
56 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const override
57 {
58 return _( "(Deleted Item)" );
59 }
60
61 wxString GetClass() const override
62 {
63 return wxT( "DELETED_SHEET_ITEM" );
64 }
65
67 {
68 static DELETED_SHEET_ITEM* item = nullptr;
69
70 if( !item )
71 item = new DELETED_SHEET_ITEM();
72
73 return item;
74 }
75
76 // pure virtuals:
77 void SetPosition( const VECTOR2I& ) override {}
78 void Move( const VECTOR2I& aMoveVector ) override {}
79 void MirrorHorizontally( int aCenter ) override {}
80 void MirrorVertically( int aCenter ) override {}
81 void Rotate( const VECTOR2I& aCenter, bool aRotateCCW ) override {}
82
83 double Similarity( const SCH_ITEM& aOther ) const override
84 {
85 return 0.0;
86 }
87
88 bool operator==( const SCH_ITEM& aOther ) const override
89 {
90 return false;
91 }
92
93#if defined(DEBUG)
94 void Show( int , std::ostream& ) const override {}
95#endif
96};
97
98namespace std
99{
100 size_t hash<SCH_SHEET_PATH>::operator()( const SCH_SHEET_PATH& path ) const
101 {
102 return path.GetCurrentHash();
103 }
104}
105
106
108{
110 m_current_hash = 0;
111}
112
113
115{
116 initFromOther( aOther );
117}
118
119
121{
122 initFromOther( aOther );
123 return *this;
124}
125
126
128{
129 SCH_SHEET_PATH retv = *this;
130
131 size_t size = aOther.size();
132
133 for( size_t i = 0; i < size; i++ )
134 retv.push_back( aOther.at( i ) );
135
136 return retv;
137}
138
139
141{
142 m_sheets = aOther.m_sheets;
146
147 // Note: don't copy m_recursion_test_cache as it is slow and we want std::vector<SCH_SHEET_PATH> to be
148 // very fast to construct for use in the connectivity algorithm.
149}
150
151
153{
154 // The root sheet path is empty. All other sheet paths must start with the root sheet path.
155 return ( m_sheets.size() == 0 ) || ( GetSheet( 0 )->IsRootSheet() );
156}
157
158
160{
161 m_current_hash = 0;
162
163 for( SCH_SHEET* sheet : m_sheets )
164 boost::hash_combine( m_current_hash, sheet->m_Uuid.Hash() );
165}
166
167
168int SCH_SHEET_PATH::Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const
169{
170 if( size() > aSheetPathToTest.size() )
171 return 1;
172
173 if( size() < aSheetPathToTest.size() )
174 return -1;
175
176 //otherwise, same number of sheets.
177 for( unsigned i = 0; i < size(); i++ )
178 {
179 if( at( i )->m_Uuid < aSheetPathToTest.at( i )->m_Uuid )
180 return -1;
181
182 if( at( i )->m_Uuid != aSheetPathToTest.at( i )->m_Uuid )
183 return 1;
184 }
185
186 return 0;
187}
188
189
190int SCH_SHEET_PATH::ComparePageNum( const SCH_SHEET_PATH& aSheetPathToTest ) const
191{
192 wxString pageA = this->GetPageNumber();
193 wxString pageB = aSheetPathToTest.GetPageNumber();
194
195 int pageNumComp = SCH_SHEET::ComparePageNum( pageA, pageB );
196
197 if( pageNumComp == 0 )
198 {
199 int virtualPageA = GetVirtualPageNumber();
200 int virtualPageB = aSheetPathToTest.GetVirtualPageNumber();
201
202 if( virtualPageA > virtualPageB )
203 pageNumComp = 1;
204 else if( virtualPageA < virtualPageB )
205 pageNumComp = -1;
206 }
207
208 return pageNumComp;
209}
210
211
212bool SCH_SHEET_PATH::IsContainedWithin( const SCH_SHEET_PATH& aSheetPathToTest ) const
213{
214 if( aSheetPathToTest.size() > size() )
215 return false;
216
217 for( size_t i = 0; i < aSheetPathToTest.size(); ++i )
218 {
219 if( at( i )->m_Uuid != aSheetPathToTest.at( i )->m_Uuid )
220 {
221 wxLogTrace( traceSchSheetPaths, "Sheet path '%s' is not within path '%s'.",
222 aSheetPathToTest.Path().AsString(), Path().AsString() );
223
224 return false;
225 }
226 }
227
228 wxLogTrace( traceSchSheetPaths, "Sheet path '%s' is within path '%s'.",
229 aSheetPathToTest.Path().AsString(), Path().AsString() );
230
231 return true;
232}
233
234
236{
237 if( !empty() )
238 return m_sheets.back();
239
240 return nullptr;
241}
242
243
245{
246 SCH_SHEET* lastSheet = Last();
247
248 if( lastSheet )
249 return lastSheet->GetScreen();
250
251 return nullptr;
252}
253
254
256{
257 SCH_SHEET* lastSheet = Last();
258
259 if( lastSheet )
260 return lastSheet->GetScreen();
261
262 return nullptr;
263}
264
265
267{
268 for( SCH_SHEET* sheet : m_sheets )
269 {
270 if( sheet->GetExcludedFromSim() )
271 return true;
272 }
273
274 return false;
275}
276
277
279{
280 for( SCH_SHEET* sheet : m_sheets )
281 {
282 if( sheet->GetExcludedFromBOM() )
283 return true;
284 }
285
286 return false;
287}
288
289
291{
292 for( SCH_SHEET* sheet : m_sheets )
293 {
294 if( sheet->GetExcludedFromBoard() )
295 return true;
296 }
297
298 return false;
299}
300
301
303{
304 for( SCH_SHEET* sheet : m_sheets )
305 {
306 if( sheet->GetDNP() )
307 return true;
308 }
309
310 return false;
311}
312
313
315{
316 wxString s;
317
318 s = wxT( "/" ); // This is the root path
319
320 // Start at 1 to avoid the root sheet, which does not need to be added to the path.
321 // Its timestamp changes anyway.
322 for( unsigned i = 1; i < size(); i++ )
323 s += at( i )->m_Uuid.AsString() + "/";
324
325 return s;
326}
327
328
330{
332 path.reserve( m_sheets.size() );
333
334 for( const SCH_SHEET* sheet : m_sheets )
335 path.push_back( sheet->m_Uuid );
336
337 return path;
338}
339
340
341wxString SCH_SHEET_PATH::PathHumanReadable( bool aUseShortRootName,
342 bool aStripTrailingSeparator ) const
343{
344 wxString s;
345
346 if( aUseShortRootName )
347 {
348 s = wxS( "/" ); // Use only the short name in netlists
349 }
350 else
351 {
352 wxString fileName;
353
354 if( !empty() && at( 0 )->GetScreen() )
355 fileName = at( 0 )->GetScreen()->GetFileName();
356
357 wxFileName fn = fileName;
358
359 s = fn.GetName() + wxS( "/" );
360 }
361
362 // Start at 1 since we've already processed the root sheet.
363 for( unsigned i = 1; i < size(); i++ )
364 s << at( i )->GetFields()[SHEETNAME].GetShownText( false ) << wxS( "/" );
365
366 if( aStripTrailingSeparator && s.EndsWith( "/" ) )
367 s = s.Left( s.length() - 1 );
368
369 return s;
370}
371
372
374{
375 std::vector<SCH_ITEM*> items;
376
377 std::copy_if( LastScreen()->Items().begin(), LastScreen()->Items().end(),
378 std::back_inserter( items ),
379 []( SCH_ITEM* aItem )
380 {
381 return ( aItem->Type() == SCH_SYMBOL_T || aItem->Type() == SCH_GLOBAL_LABEL_T );
382 } );
383
384 for( SCH_ITEM* item : items )
385 {
386 if( item->Type() == SCH_SYMBOL_T )
387 {
388 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
389
390 symbol->GetField( REFERENCE_FIELD )->SetText( symbol->GetRef( this ) );
391 symbol->SetUnit( symbol->GetUnitSelection( this ) );
392 LastScreen()->Update( item, false );
393 }
394 else if( item->Type() == SCH_GLOBAL_LABEL_T )
395 {
396 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( item );
397
398 if( label->GetFields().size() > 0 ) // Possible when reading a legacy .sch schematic
399 {
400 SCH_FIELD& intersheetRefs = label->GetFields()[0];
401
402 // Fixup for legacy files which didn't store a position for the intersheet refs
403 // unless they were shown.
404 if( label->GetFields().size() == 1
405 && intersheetRefs.GetInternalName() == wxT( "Intersheet References" )
406 && intersheetRefs.GetPosition() == VECTOR2I( 0, 0 )
407 && !intersheetRefs.IsVisible() )
408 {
409 label->AutoplaceFields( LastScreen(), false );
410 }
411
412 intersheetRefs.SetVisible( label->Schematic()->Settings().m_IntersheetRefsShow );
413 LastScreen()->Update( &intersheetRefs );
414 }
415 }
416 }
417}
418
419
420
421void SCH_SHEET_PATH::GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols,
422 bool aForceIncludeOrphanSymbols ) const
423{
424 for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
425 {
426 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
427 AppendSymbol( aReferences, symbol, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
428 }
429}
430
431
433 bool aIncludePowerSymbols,
434 bool aForceIncludeOrphanSymbols ) const
435{
436 // Skip pseudo-symbols, which have a reference starting with #. This mainly
437 // affects power symbols.
438 if( aIncludePowerSymbols || aSymbol->GetRef( this )[0] != wxT( '#' ) )
439 {
440 if( aSymbol->GetLibSymbolRef() || aForceIncludeOrphanSymbols )
441 {
442 SCH_REFERENCE schReference( aSymbol, *this );
443
444 schReference.SetSheetNumber( m_virtualPageNumber );
445 aReferences.AddItem( schReference );
446 }
447 }
448}
449
450
452 bool aIncludePowerSymbols ) const
453{
454 for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
455 {
456 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
457 AppendMultiUnitSymbol( aRefList, symbol, aIncludePowerSymbols );
458 }
459}
460
461
463 SCH_SYMBOL* aSymbol,
464 bool aIncludePowerSymbols ) const
465{
466 // Skip pseudo-symbols, which have a reference starting with #. This mainly
467 // affects power symbols.
468 if( !aIncludePowerSymbols && aSymbol->GetRef( this )[0] == wxT( '#' ) )
469 return;
470
471 LIB_SYMBOL* symbol = aSymbol->GetLibSymbolRef().get();
472
473 if( symbol && symbol->GetUnitCount() > 1 )
474 {
475 SCH_REFERENCE schReference = SCH_REFERENCE( aSymbol, *this );
476 schReference.SetSheetNumber( m_virtualPageNumber );
477 wxString reference_str = schReference.GetRef();
478
479 // Never lock unassigned references
480 if( reference_str[reference_str.Len() - 1] == '?' )
481 return;
482
483 aRefList[reference_str].AddItem( schReference );
484 }
485}
486
487
489{
490 return m_current_hash == d1.GetCurrentHash();
491}
492
493
494bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName )
495{
496 auto pair = std::make_pair( aSrcFileName, aDestFileName );
497
498 if( m_recursion_test_cache.count( pair ) )
499 return m_recursion_test_cache.at( pair );
500
501 SCHEMATIC* sch = LastScreen()->Schematic();
502
503 wxCHECK_MSG( sch, false, "No SCHEMATIC found in SCH_SHEET_PATH::TestForRecursion!" );
504
505 wxFileName rootFn = sch->GetFileName();
506 wxFileName srcFn = aSrcFileName;
507 wxFileName destFn = aDestFileName;
508
509 if( srcFn.IsRelative() )
510 srcFn.MakeAbsolute( rootFn.GetPath() );
511
512 if( destFn.IsRelative() )
513 destFn.MakeAbsolute( rootFn.GetPath() );
514
515 // The source and destination sheet file names cannot be the same.
516 if( srcFn == destFn )
517 {
518 m_recursion_test_cache[pair] = true;
519 return true;
520 }
521
525 unsigned i = 0;
526
527 while( i < size() )
528 {
529 wxFileName cmpFn = at( i )->GetFileName();
530
531 if( cmpFn.IsRelative() )
532 cmpFn.MakeAbsolute( rootFn.GetPath() );
533
534 // Test if the file name of the destination sheet is in anywhere in this sheet path.
535 if( cmpFn == destFn )
536 break;
537
538 i++;
539 }
540
541 // The destination sheet file name was not found in the sheet path or the destination
542 // sheet file name is the root sheet so no recursion is possible.
543 if( i >= size() || i == 0 )
544 {
545 m_recursion_test_cache[pair] = false;
546 return false;
547 }
548
549 // Walk back up to the root sheet to see if the source file name is already a parent in
550 // the sheet path. If so, recursion will occur.
551 do
552 {
553 i -= 1;
554
555 wxFileName cmpFn = at( i )->GetFileName();
556
557 if( cmpFn.IsRelative() )
558 cmpFn.MakeAbsolute( rootFn.GetPath() );
559
560 if( cmpFn == srcFn )
561 {
562 m_recursion_test_cache[pair] = true;
563 return true;
564 }
565
566 } while( i != 0 );
567
568 // The source sheet file name is not a parent of the destination sheet file name.
569 m_recursion_test_cache[pair] = false;
570 return false;
571}
572
573
575{
576 SCH_SHEET* sheet = Last();
577
578 wxCHECK( sheet, wxEmptyString );
579
580 KIID_PATH tmpPath = Path();
581 tmpPath.pop_back();
582
583 return sheet->getPageNumber( tmpPath );
584}
585
586
587void SCH_SHEET_PATH::SetPageNumber( const wxString& aPageNumber )
588{
589 SCH_SHEET* sheet = Last();
590
591 wxCHECK( sheet, /* void */ );
592
593 KIID_PATH tmpPath = Path();
594
595 tmpPath.pop_back();
596
597 sheet->addInstance( tmpPath );
598 sheet->setPageNumber( tmpPath, aPageNumber );
599}
600
601
603 const wxString& aProjectName )
604{
605 wxCHECK( !aProjectName.IsEmpty(), /* void */ );
606
607 SCH_SHEET_PATH newSheetPath( aPrefixSheetPath );
608 SCH_SHEET_PATH currentSheetPath( *this );
609
610 // Prefix the new hierarchical path.
611 newSheetPath = newSheetPath + currentSheetPath;
612
613 for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
614 {
615 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
616
617 wxCHECK2( symbol, continue );
618
619 SCH_SYMBOL_INSTANCE newSymbolInstance;
620
621 if( symbol->GetInstance( newSymbolInstance, Path(), true ) )
622 {
623 newSymbolInstance.m_ProjectName = aProjectName;
624 // Use an existing symbol instance for this path if it exists.
625
626 newSymbolInstance.m_Path = newSheetPath.Path();
627 symbol->AddHierarchicalReference( newSymbolInstance );
628 }
629 else if( !symbol->GetInstances().empty() )
630 {
631 newSymbolInstance.m_ProjectName = aProjectName;
632
633 // Use the first symbol instance if any symbol instance data exists.
634 newSymbolInstance = symbol->GetInstances()[0];
635 newSymbolInstance.m_Path = newSheetPath.Path();
636 symbol->AddHierarchicalReference( newSymbolInstance );
637 }
638 else
639 {
640 newSymbolInstance.m_ProjectName = aProjectName;
641
642 // Fall back to the last saved symbol field and unit settings if there is no
643 // instance data.
644 newSymbolInstance.m_Path = newSheetPath.Path();
645 newSymbolInstance.m_Reference = symbol->GetField( REFERENCE_FIELD )->GetText();
646 newSymbolInstance.m_Unit = symbol->GetUnit();
647 symbol->AddHierarchicalReference( newSymbolInstance );
648 }
649 }
650}
651
652
654{
655 for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
656 {
657 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
658
659 wxCHECK2( symbol, continue );
660
661 SCH_SHEET_PATH fullSheetPath( aPrefixSheetPath );
662 SCH_SHEET_PATH currentSheetPath( *this );
663
664 // Prefix the hierarchical path of the symbol instance to be removed.
665 fullSheetPath = fullSheetPath + currentSheetPath;
666 symbol->RemoveInstance( fullSheetPath );
667 }
668}
669
670
671void SCH_SHEET_PATH::CheckForMissingSymbolInstances( const wxString& aProjectName )
672{
673 wxCHECK( !aProjectName.IsEmpty() && LastScreen(), /* void */ );
674
675 for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
676 {
677 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
678
679 wxCHECK2( symbol, continue );
680
681 SCH_SYMBOL_INSTANCE symbolInstance;
682
683 if( !symbol->GetInstance( symbolInstance, Path() ) )
684 {
685 wxLogTrace( traceSchSheetPaths, "Adding missing symbol \"%s\" instance data for "
686 "sheet path '%s'.",
687 symbol->m_Uuid.AsString(), PathHumanReadable( false ) );
688
689 symbolInstance.m_Reference = UTIL::GetRefDesUnannotated( symbol->GetPrefix() );
690 symbolInstance.m_ProjectName = aProjectName;
691 symbolInstance.m_Path = Path();
692 symbol->AddHierarchicalReference( symbolInstance );
693 }
694 }
695}
696
697
699{
700 wxCHECK( m_sheets.size() > 1, /* void */ );
701
702 wxFileName sheetFileName = Last()->GetFileName();
703
704 // If the sheet file name is absolute, then the user requested is so don't make it relative.
705 if( sheetFileName.IsAbsolute() )
706 return;
707
708 SCH_SCREEN* screen = LastScreen();
709 SCH_SCREEN* parentScreen = m_sheets[ m_sheets.size() - 2 ]->GetScreen();
710
711 wxCHECK( screen && parentScreen, /* void */ );
712
713 wxFileName fileName = screen->GetFileName();
714 wxFileName parentFileName = parentScreen->GetFileName();
715
716 // SCH_SCREEN file names must be absolute. If they are not, someone set them incorrectly
717 // on load or on creation.
718 wxCHECK( fileName.IsAbsolute() && parentFileName.IsAbsolute(), /* void */ );
719
720 if( fileName.GetPath() == parentFileName.GetPath() )
721 {
722 Last()->SetFileName( fileName.GetFullName() );
723 }
724 else if( fileName.MakeRelativeTo( parentFileName.GetPath() ) )
725 {
726 Last()->SetFileName( fileName.GetFullPath() );
727 }
728 else
729 {
730 Last()->SetFileName( screen->GetFileName() );
731 }
732
733 wxLogTrace( tracePathsAndFiles,
734 wxT( "\n File name: '%s'"
735 "\n parent file name '%s',"
736 "\n sheet '%s' file name '%s'." ),
737 screen->GetFileName(), parentScreen->GetFileName(), PathHumanReadable(),
738 Last()->GetFileName() );
739}
740
741
743{
744 if( aSheet != nullptr )
745 BuildSheetList( aSheet, false );
746}
747
748
749void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity )
750{
751 wxCHECK_RET( aSheet != nullptr, wxT( "Cannot build sheet list from undefined sheet." ) );
752
753 std::vector<SCH_SHEET*> badSheets;
754
756 m_currentSheetPath.SetVirtualPageNumber( static_cast<int>( size() ) + 1 );
757 push_back( m_currentSheetPath );
758
760 {
761 wxString parentFileName = aSheet->GetFileName();
762 std::vector<SCH_ITEM*> childSheets;
763 m_currentSheetPath.LastScreen()->GetSheets( &childSheets );
764
765 for( SCH_ITEM* item : childSheets )
766 {
767 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
768
769 if( aCheckIntegrity )
770 {
771 if( !m_currentSheetPath.TestForRecursion( sheet->GetFileName(), parentFileName ) )
772 BuildSheetList( sheet, true );
773 else
774 badSheets.push_back( sheet );
775 }
776 else
777 {
778 // If we are not performing a full recursion test, at least check if we are in
779 // a simple recursion scenario to prevent stack overflow crashes
780 wxCHECK2_MSG( sheet->GetFileName() != aSheet->GetFileName(), continue,
781 wxT( "Recursion prevented in SCH_SHEET_LIST::BuildSheetList" ) );
782
783 BuildSheetList( sheet, false );
784 }
785 }
786 }
787
788 if( aCheckIntegrity )
789 {
790 for( SCH_SHEET* sheet : badSheets )
791 {
794 }
795 }
796
798}
799
800
801void SCH_SHEET_LIST::SortByPageNumbers( bool aUpdateVirtualPageNums )
802{
803 for( const SCH_SHEET_PATH& path : *this )
804 path.CachePageNumber();
805
806 std::sort( begin(), end(),
807 []( const SCH_SHEET_PATH& a, const SCH_SHEET_PATH& b ) -> bool
808 {
811
812 if( retval < 0 )
813 return true;
814 else if( retval > 0 )
815 return false;
816
818 return true;
819 else if( a.GetVirtualPageNumber() > b.GetVirtualPageNumber() )
820 return false;
821
823 return a.GetCurrentHash() < b.GetCurrentHash();
824 } );
825
826 if( aUpdateVirtualPageNums )
827 {
828 int virtualPageNum = 1;
829
830 for( SCH_SHEET_PATH& sheet : *this )
831 sheet.SetVirtualPageNumber( virtualPageNum++ );
832 }
833}
834
835
836bool SCH_SHEET_LIST::NameExists( const wxString& aSheetName ) const
837{
838 for( const SCH_SHEET_PATH& sheet : *this )
839 {
840 if( sheet.Last()->GetName() == aSheetName )
841 return true;
842 }
843
844 return false;
845}
846
847
848bool SCH_SHEET_LIST::PageNumberExists( const wxString& aPageNumber ) const
849{
850 for( const SCH_SHEET_PATH& sheet : *this )
851 {
852 if( sheet.GetPageNumber() == aPageNumber )
853 return true;
854 }
855
856 return false;
857}
858
859
860void SCH_SHEET_LIST::TrimToPageNumbers( const std::vector<wxString>& aPageInclusions )
861{
862 auto it = std::remove_if( begin(), end(),
863 [&]( SCH_SHEET_PATH sheet )
864 {
865 return std::find( aPageInclusions.begin(), aPageInclusions.end(),
866 sheet.GetPageNumber() )
867 == aPageInclusions.end();
868 } );
869
870 erase( it, end() );
871}
872
873
875{
876 for( const SCH_SHEET_PATH& sheet : *this )
877 {
878 if( sheet.LastScreen() && sheet.LastScreen()->IsContentModified() )
879 return true;
880 }
881
882 return false;
883}
884
885
887{
888 for( const SCH_SHEET_PATH& sheet : *this )
889 {
890 if( sheet.LastScreen() )
891 sheet.LastScreen()->SetContentModified( false );
892 }
893}
894
895
897{
898 for( const SCH_SHEET_PATH& sheet : *this )
899 {
900 SCH_ITEM* item = sheet.GetItem( aID );
901
902 if( item )
903 {
904 if( aPathOut )
905 *aPathOut = sheet;
906
907 return item;
908 }
909 }
910
911 // Not found; weak reference has been deleted.
913}
914
915
917{
918 for( SCH_ITEM* aItem : LastScreen()->Items() )
919 {
920 if( aItem->m_Uuid == aID )
921 return aItem;
922
923 SCH_ITEM* childMatch = nullptr;
924
925 aItem->RunOnChildren(
926 [&]( SCH_ITEM* aChild )
927 {
928 if( aChild->m_Uuid == aID )
929 childMatch = aChild;
930 } );
931
932 if( childMatch )
933 return childMatch;
934 }
935
936 return nullptr;
937}
938
939
940void SCH_SHEET_LIST::FillItemMap( std::map<KIID, EDA_ITEM*>& aMap )
941{
942 for( const SCH_SHEET_PATH& sheet : *this )
943 {
944 SCH_SCREEN* screen = sheet.LastScreen();
945
946 for( SCH_ITEM* aItem : screen->Items() )
947 {
948 aMap[ aItem->m_Uuid ] = aItem;
949
950 aItem->RunOnChildren(
951 [&]( SCH_ITEM* aChild )
952 {
953 aMap[ aChild->m_Uuid ] = aChild;
954 } );
955 }
956 }
957}
958
959
961{
962 // List of reference for power symbols
963 SCH_REFERENCE_LIST references;
964 SCH_REFERENCE_LIST additionalreferences; // Todo: add as a parameter to this function
965
966 // Map of locked symbols (not used, but needed by Annotate()
967 SCH_MULTI_UNIT_REFERENCE_MAP lockedSymbols;
968
969 // Build the list of power symbols:
970 for( SCH_SHEET_PATH& sheet : *this )
971 {
972 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
973 {
974 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
975 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
976
977 if( libSymbol && libSymbol->IsPower() )
978 {
979 SCH_REFERENCE schReference( symbol, sheet );
980 references.AddItem( schReference );
981 }
982 }
983 }
984
985 // Find duplicate, and silently clear annotation of duplicate
986 std::map<wxString, int> ref_list; // stores the existing references
987
988 for( unsigned ii = 0; ii< references.GetCount(); ++ii )
989 {
990 wxString curr_ref = references[ii].GetRef();
991
992 if( ref_list.find( curr_ref ) == ref_list.end() )
993 {
994 ref_list[curr_ref] = ii;
995 continue;
996 }
997
998 // Possible duplicate, if the ref ends by a number:
999 if( curr_ref.Last() < '0' && curr_ref.Last() > '9' )
1000 continue; // not annotated
1001
1002 // Duplicate: clear annotation by removing the number ending the ref
1003 while( curr_ref.Last() >= '0' && curr_ref.Last() <= '9' )
1004 curr_ref.RemoveLast();
1005
1006 references[ii].SetRef( curr_ref );
1007 }
1008
1009 // Break full symbol reference into name (prefix) and number:
1010 // example: IC1 become IC, and 1
1011 references.SplitReferences();
1012
1013 // Ensure all power symbols have the reference starting by '#'
1014 // (Not sure this is really useful)
1015 for( unsigned ii = 0; ii< references.GetCount(); ++ii )
1016 {
1017 if( references[ii].GetRef()[0] != '#' )
1018 {
1019 wxString new_ref = "#" + references[ii].GetRef();
1020 references[ii].SetRef( new_ref );
1021 }
1022 }
1023
1024 // Recalculate and update reference numbers in schematic
1025 references.Annotate( false, 0, 100, lockedSymbols, additionalreferences );
1026 references.UpdateAnnotation();
1027}
1028
1029
1030void SCH_SHEET_LIST::GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols,
1031 bool aForceIncludeOrphanSymbols ) const
1032{
1033 for( const SCH_SHEET_PATH& sheet : *this )
1034 sheet.GetSymbols( aReferences, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
1035}
1036
1037
1039 const SCH_SHEET_PATH& aSheetPath,
1040 bool aIncludePowerSymbols,
1041 bool aForceIncludeOrphanSymbols ) const
1042{
1043 for( const SCH_SHEET_PATH& sheet : *this )
1044 {
1045 if( sheet.IsContainedWithin( aSheetPath ) )
1046 sheet.GetSymbols( aReferences, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
1047 }
1048}
1049
1050
1051void SCH_SHEET_LIST::GetSheetsWithinPath( std::vector<SCH_SHEET_PATH>& aSheets,
1052 const SCH_SHEET_PATH& aSheetPath ) const
1053{
1054 for( const SCH_SHEET_PATH& sheet : *this )
1055 {
1056 if( sheet.IsContainedWithin( aSheetPath ) )
1057 aSheets.push_back( sheet );
1058 }
1059}
1060
1061
1062std::optional<SCH_SHEET_PATH> SCH_SHEET_LIST::GetSheetPathByKIIDPath( const KIID_PATH& aPath,
1063 bool aIncludeLastSheet ) const
1064{
1065 for( const SCH_SHEET_PATH& sheet : *this )
1066 {
1067 KIID_PATH testPath = sheet.Path();
1068
1069 if( !aIncludeLastSheet )
1070 testPath.pop_back();
1071
1072 if( testPath == aPath )
1073 return SCH_SHEET_PATH( sheet );
1074 }
1075
1076 return std::nullopt;
1077}
1078
1079
1081 bool aIncludePowerSymbols ) const
1082{
1083 for( auto it = begin(); it != end(); ++it )
1084 {
1086 ( *it ).GetMultiUnitSymbols( tempMap, aIncludePowerSymbols );
1087
1088 for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : tempMap )
1089 {
1090 // Merge this list into the main one
1091 unsigned n_refs = pair.second.GetCount();
1092
1093 for( unsigned thisRef = 0; thisRef < n_refs; ++thisRef )
1094 aRefList[pair.first].AddItem( pair.second[thisRef] );
1095 }
1096 }
1097}
1098
1099
1100bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
1101 const wxString& aDestFileName )
1102{
1103 if( empty() )
1104 return false;
1105
1106 SCHEMATIC* sch = at( 0 ).LastScreen()->Schematic();
1107
1108 wxCHECK_MSG( sch, false, "No SCHEMATIC found in SCH_SHEET_LIST::TestForRecursion!" );
1109
1110 wxFileName rootFn = sch->GetFileName();
1111 wxFileName destFn = aDestFileName;
1112
1113 if( destFn.IsRelative() )
1114 destFn.MakeAbsolute( rootFn.GetPath() );
1115
1116 // Test each SCH_SHEET_PATH in this SCH_SHEET_LIST for potential recursion.
1117 for( unsigned i = 0; i < size(); i++ )
1118 {
1119 // Test each SCH_SHEET_PATH in the source sheet.
1120 for( unsigned j = 0; j < aSrcSheetHierarchy.size(); j++ )
1121 {
1122 const SCH_SHEET_PATH* sheetPath = &aSrcSheetHierarchy[j];
1123
1124 for( unsigned k = 0; k < sheetPath->size(); k++ )
1125 {
1126 if( at( i ).TestForRecursion( sheetPath->GetSheet( k )->GetFileName(),
1127 aDestFileName ) )
1128 {
1129 return true;
1130 }
1131 }
1132 }
1133 }
1134
1135 // The source sheet file can safely be added to the destination sheet file.
1136 return false;
1137}
1138
1139
1141{
1142 for( SCH_SHEET_PATH& path : *this )
1143 {
1144 if( path.Path() == aPath->Path() )
1145 return &path;
1146 }
1147
1148 return nullptr;
1149}
1150
1151
1153{
1154 for( SCH_SHEET_PATH& sheetpath : *this )
1155 {
1156 if( sheetpath.LastScreen() == aScreen )
1157 return sheetpath;
1158 }
1159
1160 return SCH_SHEET_PATH();
1161}
1162
1163
1165{
1166 SCH_SHEET_LIST retval;
1167
1168 for( const SCH_SHEET_PATH& sheetpath : *this )
1169 {
1170 if( sheetpath.LastScreen() == aScreen )
1171 retval.push_back( sheetpath );
1172 }
1173
1174 return retval;
1175}
1176
1177
1179 const std::vector<SCH_SYMBOL_INSTANCE>& aSymbolInstances )
1180{
1181 for( SCH_SHEET_PATH& sheetPath : *this )
1182 {
1183 for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1184 {
1185 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1186
1187 wxCHECK2( symbol, continue );
1188
1189 KIID_PATH sheetPathWithSymbolUuid = sheetPath.Path();
1190 sheetPathWithSymbolUuid.push_back( symbol->m_Uuid );
1191
1192 auto it = std::find_if( aSymbolInstances.begin(), aSymbolInstances.end(),
1193 [ sheetPathWithSymbolUuid ]( const SCH_SYMBOL_INSTANCE& r ) -> bool
1194 {
1195 return sheetPathWithSymbolUuid == r.m_Path;
1196 } );
1197
1198 if( it == aSymbolInstances.end() )
1199 {
1200 wxLogTrace( traceSchSheetPaths, "No symbol instance found for symbol '%s'",
1201 sheetPathWithSymbolUuid.AsString() );
1202 continue;
1203 }
1204
1205 // Symbol instance paths are stored and looked up in memory with the root path so use
1206 // the full path here.
1207 symbol->AddHierarchicalReference( sheetPath.Path(), it->m_Reference, it->m_Unit );
1208 symbol->GetField( REFERENCE_FIELD )->SetText( it->m_Reference );
1209
1210 if( !it->m_Value.IsEmpty() )
1211 symbol->SetValueFieldText( it->m_Value );
1212
1213 if( !it->m_Footprint.IsEmpty() )
1214 symbol->SetFootprintFieldText( it->m_Footprint );
1215
1216 symbol->UpdatePrefix();
1217 }
1218 }
1219}
1220
1221
1222void SCH_SHEET_LIST::UpdateSheetInstanceData( const std::vector<SCH_SHEET_INSTANCE>& aSheetInstances )
1223{
1224
1225 for( SCH_SHEET_PATH& path : *this )
1226 {
1227 SCH_SHEET* sheet = path.Last();
1228
1229 wxCHECK2( sheet && path.Last(), continue );
1230
1231 auto it = std::find_if( aSheetInstances.begin(), aSheetInstances.end(),
1232 [ path ]( const SCH_SHEET_INSTANCE& r ) -> bool
1233 {
1234 return path.Path() == r.m_Path;
1235 } );
1236
1237 if( it == aSheetInstances.end() )
1238 {
1239 wxLogTrace( traceSchSheetPaths, "No sheet instance found for path '%s'",
1240 path.Path().AsString() );
1241 continue;
1242 }
1243
1244 wxLogTrace( traceSchSheetPaths, "Setting sheet '%s' instance '%s' page number '%s'",
1245 ( sheet->GetName().IsEmpty() ) ? wxString( wxT( "root" ) ) : sheet->GetName(),
1246 path.Path().AsString(), it->m_PageNumber );
1247 path.SetPageNumber( it->m_PageNumber );
1248 }
1249}
1250
1251
1252std::vector<KIID_PATH> SCH_SHEET_LIST::GetPaths() const
1253{
1254 std::vector<KIID_PATH> paths;
1255
1256 for( const SCH_SHEET_PATH& sheetPath : *this )
1257 paths.emplace_back( sheetPath.Path() );
1258
1259 return paths;
1260}
1261
1262
1263std::vector<SCH_SHEET_INSTANCE> SCH_SHEET_LIST::GetSheetInstances() const
1264{
1265 std::vector<SCH_SHEET_INSTANCE> retval;
1266
1267 for( const SCH_SHEET_PATH& path : *this )
1268 {
1269 const SCH_SHEET* sheet = path.Last();
1270
1271 wxCHECK2( sheet, continue );
1272
1273 SCH_SHEET_INSTANCE instance;
1274 SCH_SHEET_PATH tmpPath = path;
1275
1276 tmpPath.pop_back();
1277 instance.m_Path = tmpPath.Path();
1278 instance.m_PageNumber = path.GetPageNumber();
1279
1280 retval.push_back( instance );
1281 }
1282
1283 return retval;
1284}
1285
1286
1288{
1289 for( const SCH_SHEET_PATH& instance : *this )
1290 {
1291 if( !instance.GetPageNumber().IsEmpty() )
1292 return false;
1293 }
1294
1295 return true;
1296}
1297
1298
1300{
1301 // Don't accidentally renumber existing sheets.
1302 wxCHECK( AllSheetPageNumbersEmpty(), /* void */ );
1303
1304 wxString tmp;
1305 int pageNumber = 1;
1306
1307 for( SCH_SHEET_PATH& instance : *this )
1308 {
1309 tmp.Printf( "%d", pageNumber );
1310 instance.SetPageNumber( tmp );
1311 pageNumber += 1;
1312 }
1313}
1314
1315
1317 const wxString& aProjectName )
1318{
1319 for( SCH_SHEET_PATH& sheetPath : *this )
1320 sheetPath.AddNewSymbolInstances( aPrefixSheetPath, aProjectName );
1321}
1322
1323
1325{
1326 for( SCH_SHEET_PATH& sheetPath : *this )
1327 sheetPath.RemoveSymbolInstances( aPrefixSheetPath );
1328}
1329
1330
1332 int aLastVirtualPageNumber )
1333{
1334 wxString pageNumber;
1335 int lastUsedPageNumber = 1;
1336 int nextVirtualPageNumber = aLastVirtualPageNumber;
1337
1338 // Fetch the list of page numbers already in use.
1339 std::vector< wxString > usedPageNumbers;
1340
1341 if( aPrefixSheetPath.size() )
1342 {
1343 SCH_SHEET_LIST prefixHierarchy( aPrefixSheetPath.at( 0 ) );
1344
1345 for( const SCH_SHEET_PATH& path : prefixHierarchy )
1346 {
1347 pageNumber = path.GetPageNumber();
1348
1349 if( !pageNumber.IsEmpty() )
1350 usedPageNumbers.emplace_back( pageNumber );
1351 }
1352 }
1353
1354 for( SCH_SHEET_PATH& sheetPath : *this )
1355 {
1356 KIID_PATH tmp = sheetPath.Path();
1357 SCH_SHEET_PATH newSheetPath( aPrefixSheetPath );
1358
1359 // Prefix the new hierarchical path.
1360 newSheetPath = newSheetPath + sheetPath;
1361
1362 // Sheets cannot have themselves in the path.
1363 tmp.pop_back();
1364
1365 SCH_SHEET* sheet = sheetPath.Last();
1366
1367 wxCHECK2( sheet, continue );
1368
1369 nextVirtualPageNumber += 1;
1370
1371 SCH_SHEET_INSTANCE instance;
1372
1373 // Add the instance if it doesn't already exist
1374 if( !sheet->getInstance( instance, tmp, true ) )
1375 {
1376 sheet->addInstance( tmp );
1377 sheet->getInstance( instance, tmp, true );
1378 }
1379
1380 // Get a new page number if we don't have one
1381 if( instance.m_PageNumber.IsEmpty() )
1382 {
1383 // Generate the next available page number.
1384 do
1385 {
1386 pageNumber.Printf( wxT( "%d" ), lastUsedPageNumber );
1387 lastUsedPageNumber += 1;
1388 } while( std::find( usedPageNumbers.begin(), usedPageNumbers.end(), pageNumber ) !=
1389 usedPageNumbers.end() );
1390
1391 instance.m_PageNumber = pageNumber;
1392 newSheetPath.SetVirtualPageNumber( nextVirtualPageNumber );
1393 }
1394
1395 newSheetPath.SetPageNumber( instance.m_PageNumber );
1396 usedPageNumbers.push_back( instance.m_PageNumber );
1397 }
1398}
1399
1400
1401void SCH_SHEET_LIST::CheckForMissingSymbolInstances( const wxString& aProjectName )
1402{
1403 for( SCH_SHEET_PATH& sheetPath : *this )
1404 sheetPath.CheckForMissingSymbolInstances( aProjectName );
1405}
1406
1407
1409{
1410 int lastVirtualPageNumber = 1;
1411
1412 for( const SCH_SHEET_PATH& sheetPath : *this )
1413 {
1414 if( sheetPath.GetVirtualPageNumber() > lastVirtualPageNumber )
1415 lastVirtualPageNumber = sheetPath.GetVirtualPageNumber();
1416 }
1417
1418 return lastVirtualPageNumber;
1419}
1420
1421
1422bool SCH_SHEET_LIST::HasPath( const KIID_PATH& aPath ) const
1423{
1424 for( const SCH_SHEET_PATH& path : *this )
1425 {
1426 if( path.Path() == aPath )
1427 return true;
1428 }
1429
1430 return false;
1431}
1432
1433
1434bool SCH_SHEET_LIST::ContainsSheet( const SCH_SHEET* aSheet ) const
1435{
1436 for( const SCH_SHEET_PATH& path : *this )
1437 {
1438 for( size_t i = 0; i < path.size(); i++ )
1439 {
1440 if( path.at( i ) == aSheet )
1441 return true;
1442 }
1443 }
1444
1445 return false;
1446}
bool IsContentModified() const
Definition: base_screen.h:60
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
A singleton item of this class is returned for a weak reference that no longer exists.
wxString GetClass() const override
Return the class name.
void SetPosition(const VECTOR2I &) override
static DELETED_SHEET_ITEM * GetInstance()
double Similarity(const SCH_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
void Rotate(const VECTOR2I &aCenter, bool aRotateCCW) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
bool operator==(const SCH_ITEM &aOther) const override
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
const KIID m_Uuid
Definition: eda_item.h:489
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:94
virtual bool IsVisible() const
Definition: eda_text.h:170
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:275
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
wxString AsString() const
Definition: kiid.cpp:357
Definition: kiid.h:49
wxString AsString() const
Definition: kiid.cpp:247
Define a library symbol object.
Definition: lib_symbol.h:78
bool IsPower() const override
Definition: lib_symbol.cpp:389
int GetUnitCount() const override
Holds all the data relating to one schematic.
Definition: schematic.h:76
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:291
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:297
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1478
void SetText(const wxString &aText) override
Definition: sch_field.cpp:1205
const wxString & GetInternalName()
Get the initial name of the field set at creation (or set by SetName()).
Definition: sch_field.h:131
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:150
int GetUnit() const
Definition: sch_item.h:229
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:568
virtual void SetUnit(int aUnit)
Definition: sch_item.h:228
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_label.cpp:614
std::vector< SCH_FIELD > & GetFields()
Definition: sch_label.h:201
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void Annotate(bool aUseSheetNum, int aSheetIntervalId, int aStartNumber, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap, const SCH_REFERENCE_LIST &aAdditionalRefs, bool aStartAtCurrent=false)
Set the reference designators in the list that have not been annotated.
size_t GetCount() const
void SplitReferences()
Attempt to split all reference designators into a name (U) and number (1).
void AddItem(const SCH_REFERENCE &aItem)
void UpdateAnnotation()
Update the symbol references for the schematic project (or the current sheet).
A helper to define a symbol's reference designator in a schematic.
wxString GetRef() const
void SetSheetNumber(int aSheetNumber)
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:108
const wxString & GetFileName() const
Definition: sch_screen.h:143
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:322
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:99
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:315
void GetSheets(std::vector< SCH_ITEM * > *aItems) const
Similar to Items().OfType( SCH_SHEET_T ), but return the sheets in a deterministic order (L-R,...
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
std::optional< SCH_SHEET_PATH > GetSheetPathByKIIDPath(const KIID_PATH &aPath, bool aIncludeLastSheet=true) const
Finds a SCH_SHEET_PATH that matches the provided KIID_PATH.
SCH_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
Fetch a SCH_ITEM by ID.
void GetMultiUnitSymbols(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true) const
Add a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the li...
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
Fill an item cache for temporary use when many items need to be fetched.
SCH_SHEET_PATH m_currentSheetPath
void TrimToPageNumbers(const std::vector< wxString > &aPageInclusions)
Truncates the list by removing sheet's with page numbers not in the given list.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
void AddNewSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath, const wxString &aProjectName)
Attempt to add new symbol instances for all symbols in this list of sheet paths prefixed with aPrefix...
bool NameExists(const wxString &aSheetName) const
std::vector< SCH_SHEET_INSTANCE > GetSheetInstances() const
Fetch the instance information for all of the sheets in the hiearchy.
void UpdateSheetInstanceData(const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
Update all of the sheet instance information using aSheetInstances.
void SetInitialPageNumbers()
Set initial sheet page numbers.
void RemoveSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath)
SCH_SHEET_LIST FindAllSheetsForScreen(const SCH_SCREEN *aScreen) const
Return a SCH_SHEET_LIST with a copy of all the SCH_SHEET_PATH using a particular screen.
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
bool IsModified() const
Check the entire hierarchy for any modifications.
SCH_SHEET_LIST(SCH_SHEET *aSheet=nullptr)
Construct a flattened list of SCH_SHEET_PATH objects from aSheet.
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
int GetLastVirtualPageNumber() const
void UpdateSymbolInstanceData(const std::vector< SCH_SYMBOL_INSTANCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
void GetSheetsWithinPath(std::vector< SCH_SHEET_PATH > &aSheets, const SCH_SHEET_PATH &aSheetPath) const
Add a SCH_SHEET_PATH object to aSheets for each sheet in the list that are contained within aSheetPat...
bool PageNumberExists(const wxString &aPageNumber) const
void AddNewSheetInstances(const SCH_SHEET_PATH &aPrefixSheetPath, int aLastVirtualPageNumber)
bool ContainsSheet(const SCH_SHEET *aSheet) const
std::vector< KIID_PATH > GetPaths() const
void GetSymbolsWithinPath(SCH_REFERENCE_LIST &aReferences, const SCH_SHEET_PATH &aSheetPath, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets that are contained wi...
void BuildSheetList(SCH_SHEET *aSheet, bool aCheckIntegrity)
Build the list of sheets and their sheet path from aSheet.
SCH_SHEET_PATH FindSheetForScreen(const SCH_SCREEN *aScreen)
Return the first SCH_SHEET_PATH object (not necessarily the only one) using a particular screen.
void CheckForMissingSymbolInstances(const wxString &aProjectName)
bool HasPath(const KIID_PATH &aPath) const
SCH_SHEET_PATH * FindSheetForPath(const SCH_SHEET_PATH *aPath)
Return a pointer to the first SCH_SHEET_PATH object (not necessarily the only one) matching the provi...
bool TestForRecursion(const SCH_SHEET_LIST &aSrcSheetHierarchy, const wxString &aDestFileName)
Test every SCH_SHEET_PATH in this SCH_SHEET_LIST to verify if adding the sheets stored in aSrcSheetHi...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool GetExcludedFromBOM() const
SCH_ITEM * GetItem(const KIID &aID) const
Fetch a SCH_ITEM by ID.
void AppendMultiUnitSymbol(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, SCH_SYMBOL *aSymbol, bool aIncludePowerSymbols=true) const
Append a SCH_REFERENCE_LIST object to aRefList based on aSymbol, storing same-reference set of multi-...
const SCH_SHEET * GetSheet(unsigned aIndex) const
bool empty() const
Forwarded method from std::vector.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Adds SCH_REFERENCE object to aReferences for each symbol in the sheet.
int ComparePageNum(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare sheets by their page number.
size_t GetCurrentHash() const
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false) const
Return the sheet path in a human readable form made from the sheet names.
bool operator==(const SCH_SHEET_PATH &d1) const
void AddNewSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath, const wxString &aProjectName)
Attempt to add new symbol instances for all symbols in this sheet path prefixed with aPrefixSheetPath...
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
bool TestForRecursion(const wxString &aSrcFileName, const wxString &aDestFileName)
Test the SCH_SHEET_PATH file names to check adding the sheet stored in the file aSrcFileName to the s...
void UpdateAllScreenReferences() const
Update all the symbol references for this sheet path.
bool IsFullPath() const
void MakeFilePathRelativeToParentSheet()
Make the sheet file name relative to its parent sheet.
wxString GetCachedPageNumber() const
std::vector< SCH_SHEET * > m_sheets
SCH_SCREEN * LastScreen()
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare if this is the same sheet path as aSheetPathToTest.
void GetMultiUnitSymbols(SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true) const
Add a SCH_REFERENCE_LIST object to aRefList for each same-reference set of multi-unit parts in the sh...
void initFromOther(const SCH_SHEET_PATH &aOther)
wxString m_cached_page_number
wxString GetPageNumber() const
void RemoveSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath)
void CheckForMissingSymbolInstances(const wxString &aProjectName)
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.
void SetVirtualPageNumber(int aPageNumber)
Set the sheet instance virtual page number.
void AppendSymbol(SCH_REFERENCE_LIST &aReferences, SCH_SYMBOL *aSymbol, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Append a SCH_REFERENCE object to aReferences based on aSymbol.
std::map< std::pair< wxString, wxString >, bool > m_recursion_test_cache
Page numbers are maintained by the sheet load order.
bool GetExcludedFromSim() const
wxString PathAsString() const
Return the path of time stamps which do not changes even when editing sheet parameters.
bool GetExcludedFromBoard() const
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
SCH_SHEET_PATH & operator=(const SCH_SHEET_PATH &aOther)
bool GetDNP() const
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
SCH_SHEET_PATH operator+(const SCH_SHEET_PATH &aOther)
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
size_t size() const
Forwarded method from std::vector.
int GetVirtualPageNumber() const
void pop_back()
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
void SetFileName(const wxString &aFilename)
Definition: sch_sheet.h:312
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:306
bool IsRootSheet() const
Definition: sch_sheet.cpp:204
bool getInstance(SCH_SHEET_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
Definition: sch_sheet.cpp:1453
bool addInstance(const KIID_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1430
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:93
wxString GetName() const
Definition: sch_sheet.h:107
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:110
static int ComparePageNum(const wxString &aPageNumberA, const wxString &aPageNumberB)
Compares page numbers of schematic sheets.
Definition: sch_sheet.cpp:1535
void setPageNumber(const KIID_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1522
wxString getPageNumber(const KIID_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1505
Schematic symbol object.
Definition: sch_symbol.h:106
void UpdatePrefix()
Set the prefix based on the current reference designator.
Definition: sch_symbol.cpp:824
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstances() const
Definition: sch_symbol.h:165
void RemoveInstance(const SCH_SHEET_PATH &aInstancePath)
Definition: sch_symbol.cpp:607
void SetValueFieldText(const wxString &aValue)
Definition: sch_symbol.cpp:912
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:934
void SetFootprintFieldText(const wxString &aFootprint)
Definition: sch_symbol.cpp:928
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
Definition: sch_symbol.cpp:635
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
Definition: sch_symbol.cpp:583
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
Definition: sch_symbol.cpp:860
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:214
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
Definition: sch_symbol.cpp:735
wxString GetPrefix() const
Definition: sch_symbol.h:280
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
const wxChar *const traceSchSheetPaths
Flag to enable debug output of schematic symbol sheet path manipulation code.
wxString GetRefDesUnannotated(const wxString &aSource)
Return an unannotated refdes from either a prefix or an existing refdes.
STL namespace.
Collection of utility functions for component reference designators (refdes)
@ SHEETNAME
Definition: sch_sheet.h:45
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.
A simple container for sheet instance information.
A simple container for schematic symbol instance information.
Definition for symbol library class.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
wxLogTrace helper definitions.
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ NOT_USED
the 3d code uses this value
Definition: typeinfo.h:79
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:168
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:676