KiCad PCB EDA Suite
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 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 <sch_screen.h>
27#include <sch_item.h>
28#include <sch_marker.h>
29#include <sch_label.h>
30#include <sch_reference_list.h>
31#include <symbol_library.h>
32#include <sch_sheet_path.h>
33#include <sch_symbol.h>
34#include <sch_sheet.h>
35#include <schematic.h>
36#include <template_fieldnames.h>
37#include <trace_helpers.h>
38
39#include <boost/functional/hash.hpp>
40#include <wx/filename.h>
41#include <wx/log.h>
42
43
49{
50public:
52 SCH_ITEM( nullptr, NOT_USED )
53 {}
54
55 wxString GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const override
56 {
57 return _( "(Deleted Item)" );
58 }
59
60 wxString GetClass() const override
61 {
62 return wxT( "DELETED_SHEET_ITEM" );
63 }
64
66 {
67 static DELETED_SHEET_ITEM* item = nullptr;
68
69 if( !item )
70 item = new DELETED_SHEET_ITEM();
71
72 return item;
73 }
74
75 // pure virtuals:
76 void SetPosition( const VECTOR2I& ) override {}
77 void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& aOffset ) 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 ) override {}
82
83#if defined(DEBUG)
84 void Show( int , std::ostream& ) const override {}
85#endif
86};
87
88
90 const SCH_SYMBOL_INSTANCE& aRhs )
91{
92 wxCHECK( !aLhs.m_Path.empty() && !aRhs.m_Path.empty(), false );
93
94 return aLhs.m_Path[0] < aRhs.m_Path[0];
95}
96
97
98namespace std
99{
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;
145
146 // Note: don't copy m_recursion_test_cache as it is slow and we want SCH_SHEET_PATHS to be
147 // very fast to construct for use in the connectivity algorithm.
148}
149
150
152{
153 // The root sheet path is empty. All other sheet paths must start with the root sheet path.
154 return ( m_sheets.size() == 0 ) || ( GetSheet( 0 )->IsRootSheet() );
155}
156
157
159{
160 m_current_hash = 0;
161
162 for( SCH_SHEET* sheet : m_sheets )
163 boost::hash_combine( m_current_hash, sheet->m_Uuid.Hash() );
164}
165
166
167int SCH_SHEET_PATH::Cmp( const SCH_SHEET_PATH& aSheetPathToTest ) const
168{
169 if( size() > aSheetPathToTest.size() )
170 return 1;
171
172 if( size() < aSheetPathToTest.size() )
173 return -1;
174
175 //otherwise, same number of sheets.
176 for( unsigned i = 0; i < size(); i++ )
177 {
178 if( at( i )->m_Uuid < aSheetPathToTest.at( i )->m_Uuid )
179 return -1;
180
181 if( at( i )->m_Uuid != aSheetPathToTest.at( i )->m_Uuid )
182 return 1;
183 }
184
185 return 0;
186}
187
188
189int SCH_SHEET_PATH::ComparePageNum( const SCH_SHEET_PATH& aSheetPathToTest ) const
190{
191 wxString pageA = this->GetPageNumber();
192 wxString pageB = aSheetPathToTest.GetPageNumber();
193
194 int pageNumComp = SCH_SHEET::ComparePageNum( pageA, pageB );
195
196 if( pageNumComp == 0 )
197 {
198 int virtualPageA = GetVirtualPageNumber();
199 int virtualPageB = aSheetPathToTest.GetVirtualPageNumber();
200
201 if( virtualPageA > virtualPageB )
202 pageNumComp = 1;
203 else if( virtualPageA < virtualPageB )
204 pageNumComp = -1;
205 }
206
207 return pageNumComp;
208}
209
210
211bool SCH_SHEET_PATH::IsContainedWithin( const SCH_SHEET_PATH& aSheetPathToTest ) const
212{
213 if( aSheetPathToTest.size() > size() )
214 return false;
215
216 for( size_t i = 0; i < aSheetPathToTest.size(); ++i )
217 {
218 if( at( i )->m_Uuid != aSheetPathToTest.at( i )->m_Uuid )
219 {
220 wxLogTrace( traceSchSheetPaths, "Sheet path '%s' is not within path '%s'.",
221 aSheetPathToTest.Path().AsString(), Path().AsString() );
222
223 return false;
224 }
225 }
226
227 wxLogTrace( traceSchSheetPaths, "Sheet path '%s' is within path '%s'.",
228 aSheetPathToTest.Path().AsString(), Path().AsString() );
229
230 return true;
231}
232
233
235{
236 if( !empty() )
237 return m_sheets.back();
238
239 return nullptr;
240}
241
242
244{
245 SCH_SHEET* lastSheet = Last();
246
247 if( lastSheet )
248 return lastSheet->GetScreen();
249
250 return nullptr;
251}
252
253
255{
256 SCH_SHEET* lastSheet = Last();
257
258 if( lastSheet )
259 return lastSheet->GetScreen();
260
261 return nullptr;
262}
263
264
266{
267 wxString s;
268
269 s = wxT( "/" ); // This is the root path
270
271 // Start at 1 to avoid the root sheet, which does not need to be added to the path.
272 // Its timestamp changes anyway.
273 for( unsigned i = 1; i < size(); i++ )
274 s += at( i )->m_Uuid.AsString() + "/";
275
276 return s;
277}
278
279
281{
283
284 for( const SCH_SHEET* sheet : m_sheets )
285 path.push_back( sheet->m_Uuid );
286
287 return path;
288}
289
290
291wxString SCH_SHEET_PATH::PathHumanReadable( bool aUseShortRootName,
292 bool aStripTrailingSeparator ) const
293{
294 wxString s;
295
296 if( aUseShortRootName )
297 {
298 s = wxS( "/" ); // Use only the short name in netlists
299 }
300 else
301 {
302 wxString fileName;
303
304 if( !empty() && at( 0 )->GetScreen() )
305 fileName = at( 0 )->GetScreen()->GetFileName();
306
307 wxFileName fn = fileName;
308
309 s = fn.GetName() + wxS( "/" );
310 }
311
312 // Start at 1 since we've already processed the root sheet.
313 for( unsigned i = 1; i < size(); i++ )
314 s << at( i )->GetFields()[SHEETNAME].GetShownText() << wxS( "/" );
315
316 if( aStripTrailingSeparator && s.EndsWith( "/" ) )
317 s = s.Left( s.length() - 1 );
318
319 return s;
320}
321
322
324{
325 std::vector<SCH_ITEM*> items;
326
327 std::copy_if( LastScreen()->Items().begin(), LastScreen()->Items().end(),
328 std::back_inserter( items ),
329 []( SCH_ITEM* aItem )
330 {
331 return ( aItem->Type() == SCH_SYMBOL_T || aItem->Type() == SCH_GLOBAL_LABEL_T );
332 } );
333
334 for( SCH_ITEM* item : items )
335 {
336 if( item->Type() == SCH_SYMBOL_T )
337 {
338 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
339
340 symbol->GetField( REFERENCE_FIELD )->SetText( symbol->GetRef( this ) );
341 symbol->UpdateUnit( symbol->GetUnitSelection( this ) );
342 LastScreen()->Update( item, false );
343 }
344 else if( item->Type() == SCH_GLOBAL_LABEL_T )
345 {
346 SCH_GLOBALLABEL* label = static_cast<SCH_GLOBALLABEL*>( item );
347
348 if( label->GetFields().size() > 0 ) // Possible when reading a legacy .sch schematic
349 {
350 SCH_FIELD& intersheetRefs = label->GetFields()[0];
351
352 // Fixup for legacy files which didn't store a position for the intersheet refs
353 // unless they were shown.
354 if( label->GetFields().size() == 1
355 && intersheetRefs.GetInternalName() == wxT( "Intersheet References" )
356 && intersheetRefs.GetPosition() == VECTOR2I( 0, 0 )
357 && !intersheetRefs.IsVisible() )
358 {
359 label->AutoplaceFields( LastScreen(), false );
360 }
361
362 intersheetRefs.SetVisible( label->Schematic()->Settings().m_IntersheetRefsShow );
363 LastScreen()->Update( &intersheetRefs );
364 }
365 }
366 }
367}
368
369
370
371void SCH_SHEET_PATH::GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols,
372 bool aForceIncludeOrphanSymbols ) const
373{
374 for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
375 {
376 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
377 AppendSymbol( aReferences, symbol, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
378 }
379}
380
381
383 bool aIncludePowerSymbols,
384 bool aForceIncludeOrphanSymbols ) const
385{
386 // Skip pseudo-symbols, which have a reference starting with #. This mainly
387 // affects power symbols.
388 if( aIncludePowerSymbols || aSymbol->GetRef( this )[0] != wxT( '#' ) )
389 {
390 LIB_SYMBOL* symbol = aSymbol->GetLibSymbolRef().get();
391
392 if( symbol || aForceIncludeOrphanSymbols )
393 {
394 SCH_REFERENCE schReference( aSymbol, symbol, *this );
395
396 schReference.SetSheetNumber( m_virtualPageNumber );
397 aReferences.AddItem( schReference );
398 }
399 }
400}
401
402
404 bool aIncludePowerSymbols ) const
405{
406 for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
407 {
408 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
409 AppendMultiUnitSymbol( aRefList, symbol, aIncludePowerSymbols );
410 }
411}
412
413
415 SCH_SYMBOL* aSymbol,
416 bool aIncludePowerSymbols ) const
417{
418 // Skip pseudo-symbols, which have a reference starting with #. This mainly
419 // affects power symbols.
420 if( !aIncludePowerSymbols && aSymbol->GetRef( this )[0] == wxT( '#' ) )
421 return;
422
423 LIB_SYMBOL* symbol = aSymbol->GetLibSymbolRef().get();
424
425 if( symbol && symbol->GetUnitCount() > 1 )
426 {
427 SCH_REFERENCE schReference = SCH_REFERENCE( aSymbol, symbol, *this );
428 schReference.SetSheetNumber( m_virtualPageNumber );
429 wxString reference_str = schReference.GetRef();
430
431 // Never lock unassigned references
432 if( reference_str[reference_str.Len() - 1] == '?' )
433 return;
434
435 aRefList[reference_str].AddItem( schReference );
436 }
437}
438
439
441{
442 return m_current_hash == d1.GetCurrentHash();
443}
444
445
446bool SCH_SHEET_PATH::TestForRecursion( const wxString& aSrcFileName, const wxString& aDestFileName )
447{
448 auto pair = std::make_pair( aSrcFileName, aDestFileName );
449
450 if( m_recursion_test_cache.count( pair ) )
451 return m_recursion_test_cache.at( pair );
452
453 SCHEMATIC* sch = LastScreen()->Schematic();
454
455 wxCHECK_MSG( sch, false, "No SCHEMATIC found in SCH_SHEET_PATH::TestForRecursion!" );
456
457 wxFileName rootFn = sch->GetFileName();
458 wxFileName srcFn = aSrcFileName;
459 wxFileName destFn = aDestFileName;
460
461 if( srcFn.IsRelative() )
462 srcFn.MakeAbsolute( rootFn.GetPath() );
463
464 if( destFn.IsRelative() )
465 destFn.MakeAbsolute( rootFn.GetPath() );
466
467
468 // The source and destination sheet file names cannot be the same.
469 if( srcFn == destFn )
470 {
471 m_recursion_test_cache[pair] = true;
472 return true;
473 }
474
478 unsigned i = 0;
479
480 while( i < size() )
481 {
482 wxFileName cmpFn = at( i )->GetFileName();
483
484 if( cmpFn.IsRelative() )
485 cmpFn.MakeAbsolute( rootFn.GetPath() );
486
487 // Test if the file name of the destination sheet is in anywhere in this sheet path.
488 if( cmpFn == destFn )
489 break;
490
491 i++;
492 }
493
494 // The destination sheet file name was not found in the sheet path or the destination
495 // sheet file name is the root sheet so no recursion is possible.
496 if( i >= size() || i == 0 )
497 {
498 m_recursion_test_cache[pair] = false;
499 return false;
500 }
501
502 // Walk back up to the root sheet to see if the source file name is already a parent in
503 // the sheet path. If so, recursion will occur.
504 do
505 {
506 i -= 1;
507
508 wxFileName cmpFn = at( i )->GetFileName();
509
510 if( cmpFn.IsRelative() )
511 cmpFn.MakeAbsolute( rootFn.GetPath() );
512
513 if( cmpFn == srcFn )
514 {
515 m_recursion_test_cache[pair] = true;
516 return true;
517 }
518
519 } while( i != 0 );
520
521 // The source sheet file name is not a parent of the destination sheet file name.
522 m_recursion_test_cache[pair] = false;
523 return false;
524}
525
526
528{
529 SCH_SHEET* sheet = Last();
530
531 wxCHECK( sheet, wxEmptyString );
532
533 SCH_SHEET_PATH tmpPath = *this;
534
535 tmpPath.pop_back();
536
537 return sheet->getPageNumber( tmpPath );
538}
539
540
541void SCH_SHEET_PATH::SetPageNumber( const wxString& aPageNumber )
542{
543 SCH_SHEET* sheet = Last();
544
545 wxCHECK( sheet, /* void */ );
546
547 SCH_SHEET_PATH tmpPath = *this;
548
549 tmpPath.pop_back();
550
551 sheet->addInstance( tmpPath );
552 sheet->setPageNumber( tmpPath, aPageNumber );
553}
554
555
557{
558 SCH_SHEET_PATH newSheetPath( aPrefixSheetPath );
559 SCH_SHEET_PATH currentSheetPath( *this );
560
561 // Prefix the new hierarchical path.
562 newSheetPath = newSheetPath + currentSheetPath;
563
564 for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
565 {
566 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
567
568 wxCHECK2( symbol, continue );
569
570 SCH_SYMBOL_INSTANCE newSymbolInstance;
571
572 if( symbol->GetInstance( newSymbolInstance, Path(), true ) )
573 {
574 // Use an existing symbol instance for this path if it exists.
575 newSymbolInstance.m_Path = newSheetPath.Path();
576 symbol->AddHierarchicalReference( newSymbolInstance );
577 }
578 else if( !symbol->GetInstanceReferences().empty() )
579 {
580 // Use the first symbol instance if any symbol instance data exists.
581 newSymbolInstance = symbol->GetInstanceReferences()[0];
582 newSymbolInstance.m_Path = newSheetPath.Path();
583 symbol->AddHierarchicalReference( newSymbolInstance );
584 }
585 else
586 {
587 // Fall back to the last saved symbol field and unit settings if there is no
588 // instance data.
589 newSymbolInstance.m_Path = newSheetPath.Path();
590 newSymbolInstance.m_Reference = symbol->GetField( REFERENCE_FIELD )->GetText();
591 newSymbolInstance.m_Unit = symbol->GetUnit();
592 symbol->AddHierarchicalReference( newSymbolInstance );
593 }
594 }
595}
596
597
599{
600 for( SCH_ITEM* item : LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
601 {
602 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
603
604 wxCHECK2( symbol, continue );
605
606 SCH_SHEET_PATH fullSheetPath( aPrefixSheetPath );
607 SCH_SHEET_PATH currentSheetPath( *this );
608
609 // Prefix the hierarchical path of the symbol instance to be removed.
610 fullSheetPath = fullSheetPath + currentSheetPath;
611 symbol->RemoveInstance( fullSheetPath );
612 }
613}
614
615
617{
618 wxCHECK( m_sheets.size() > 1, /* void */ );
619
620 wxFileName sheetFileName = Last()->GetFileName();
621
622 // If the sheet file name is absolute, then the user requested is so don't make it relative.
623 if( sheetFileName.IsAbsolute() )
624 return;
625
626 SCH_SCREEN* screen = LastScreen();
627 SCH_SCREEN* parentScreen = m_sheets[ m_sheets.size() - 2 ]->GetScreen();
628
629 wxCHECK( screen && parentScreen, /* void */ );
630
631 wxFileName fileName = screen->GetFileName();
632 wxFileName parentFileName = parentScreen->GetFileName();
633
634 // SCH_SCREEN file names must be absolute. If they are not, someone set them incorrectly
635 // on load or on creation.
636 wxCHECK( fileName.IsAbsolute() && parentFileName.IsAbsolute(), /* void */ );
637
638 if( fileName.GetPath() == parentFileName.GetPath() )
639 {
640 Last()->SetFileName( fileName.GetFullName() );
641 }
642 else if( fileName.MakeRelativeTo( parentFileName.GetPath() ) )
643 {
644 Last()->SetFileName( fileName.GetFullPath() );
645 }
646 else
647 {
648 Last()->SetFileName( screen->GetFileName() );
649 }
650
651 wxLogTrace( tracePathsAndFiles,
652 wxT( "\n File name: '%s'"
653 "\n parent file name '%s',"
654 "\n sheet '%s' file name '%s'." ),
655 screen->GetFileName(), parentScreen->GetFileName(), PathHumanReadable(),
656 Last()->GetFileName() );
657}
658
659
660SCH_SHEET_LIST::SCH_SHEET_LIST( SCH_SHEET* aSheet, bool aCheckIntegrity )
661{
662 if( aSheet != nullptr )
663 {
664 BuildSheetList( aSheet, aCheckIntegrity );
665
666 if( aSheet->IsRootSheet() )
668 }
669}
670
671
672void SCH_SHEET_LIST::BuildSheetList( SCH_SHEET* aSheet, bool aCheckIntegrity )
673{
674 wxCHECK_RET( aSheet != nullptr, wxT( "Cannot build sheet list from undefined sheet." ) );
675
676 std::vector<SCH_SHEET*> badSheets;
677
679 m_currentSheetPath.SetVirtualPageNumber( static_cast<int>( size() ) + 1 );
680 push_back( m_currentSheetPath );
681
683 {
684 wxString parentFileName = aSheet->GetFileName();
685 std::vector<SCH_ITEM*> childSheets;
686 m_currentSheetPath.LastScreen()->GetSheets( &childSheets );
687
688 for( SCH_ITEM* item : childSheets )
689 {
690 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
691
692 if( aCheckIntegrity )
693 {
694 if( !m_currentSheetPath.TestForRecursion( sheet->GetFileName(), parentFileName ) )
695 BuildSheetList( sheet, true );
696 else
697 badSheets.push_back( sheet );
698 }
699 else
700 {
701 BuildSheetList( sheet, false );
702 }
703 }
704 }
705
706 if( aCheckIntegrity )
707 {
708 for( SCH_SHEET* sheet : badSheets )
709 {
712 }
713 }
714
716}
717
718
719void SCH_SHEET_LIST::SortByPageNumbers( bool aUpdateVirtualPageNums )
720{
721 std::sort( begin(), end(),
722 []( SCH_SHEET_PATH a, SCH_SHEET_PATH b ) -> bool
723 {
724 int retval = a.ComparePageNum( b );
725
726 if( retval < 0 )
727 return true;
728 else if( retval > 0 )
729 return false;
730 else
731 return a.GetCurrentHash() < b.GetCurrentHash();
732 } );
733
734 if( aUpdateVirtualPageNums )
735 {
736 int virtualPageNum = 1;
737
738 for( SCH_SHEET_PATH& sheet : *this )
739 {
740 sheet.SetVirtualPageNumber( virtualPageNum++ );
741 }
742 }
743}
744
745
746bool SCH_SHEET_LIST::NameExists( const wxString& aSheetName ) const
747{
748 for( const SCH_SHEET_PATH& sheet : *this )
749 {
750 if( sheet.Last()->GetName() == aSheetName )
751 return true;
752 }
753
754 return false;
755}
756
757
758bool SCH_SHEET_LIST::PageNumberExists( const wxString& aPageNumber ) const
759{
760 for( const SCH_SHEET_PATH& sheet : *this )
761 {
762 if( sheet.GetPageNumber() == aPageNumber )
763 return true;
764 }
765
766 return false;
767}
768
769
771{
772 for( const SCH_SHEET_PATH& sheet : *this )
773 {
774 if( sheet.LastScreen() && sheet.LastScreen()->IsContentModified() )
775 return true;
776 }
777
778 return false;
779}
780
781
783{
784 for( const SCH_SHEET_PATH& sheet : *this )
785 {
786 if( sheet.LastScreen() )
787 sheet.LastScreen()->SetContentModified( false );
788 }
789}
790
791
793{
794 for( const SCH_SHEET_PATH& sheet : *this )
795 {
796 SCH_ITEM* item = sheet.GetItem( aID );
797
798 if( item )
799 {
800 if( aPathOut )
801 *aPathOut = sheet;
802
803 return item;
804 }
805 }
806
807 // Not found; weak reference has been deleted.
809}
810
811
813{
814 for( SCH_ITEM* aItem : LastScreen()->Items() )
815 {
816 if( aItem->m_Uuid == aID )
817 return aItem;
818
819 SCH_ITEM* childMatch = nullptr;
820
821 aItem->RunOnChildren(
822 [&]( SCH_ITEM* aChild )
823 {
824 if( aChild->m_Uuid == aID )
825 childMatch = aChild;
826 } );
827
828 if( childMatch )
829 return childMatch;
830 }
831
832 return nullptr;
833}
834
835
836void SCH_SHEET_LIST::FillItemMap( std::map<KIID, EDA_ITEM*>& aMap )
837{
838 for( const SCH_SHEET_PATH& sheet : *this )
839 {
840 SCH_SCREEN* screen = sheet.LastScreen();
841
842 for( SCH_ITEM* aItem : screen->Items() )
843 {
844 aMap[ aItem->m_Uuid ] = aItem;
845
846 aItem->RunOnChildren(
847 [&]( SCH_ITEM* aChild )
848 {
849 aMap[ aChild->m_Uuid ] = aChild;
850 } );
851 }
852 }
853}
854
855
857{
858 // List of reference for power symbols
859 SCH_REFERENCE_LIST references;
860 SCH_REFERENCE_LIST additionalreferences; // Todo: add as a parameter to this function
861
862 // Map of locked symbols (not used, but needed by Annotate()
863 SCH_MULTI_UNIT_REFERENCE_MAP lockedSymbols;
864
865 // Build the list of power symbols:
866 for( SCH_SHEET_PATH& sheet : *this )
867 {
868 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
869 {
870 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
871 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
872
873 if( libSymbol && libSymbol->IsPower() )
874 {
875 SCH_REFERENCE schReference( symbol, libSymbol, sheet );
876 references.AddItem( schReference );
877 }
878 }
879 }
880
881 // Find duplicate, and silently clear annotation of duplicate
882 std::map<wxString, int> ref_list; // stores the existing references
883
884 for( unsigned ii = 0; ii< references.GetCount(); ++ii )
885 {
886 wxString curr_ref = references[ii].GetRef();
887
888 if( ref_list.find( curr_ref ) == ref_list.end() )
889 {
890 ref_list[curr_ref] = ii;
891 continue;
892 }
893
894 // Possible duplicate, if the ref ends by a number:
895 if( curr_ref.Last() < '0' && curr_ref.Last() > '9' )
896 continue; // not annotated
897
898 // Duplicate: clear annotation by removing the number ending the ref
899 while( curr_ref.Last() >= '0' && curr_ref.Last() <= '9' )
900 curr_ref.RemoveLast();
901
902 references[ii].SetRef( curr_ref );
903 }
904
905 // Break full symbol reference into name (prefix) and number:
906 // example: IC1 become IC, and 1
907 references.SplitReferences();
908
909 // Ensure all power symbols have the reference starting by '#'
910 // (Not sure this is really useful)
911 for( unsigned ii = 0; ii< references.GetCount(); ++ii )
912 {
913 if( references[ii].GetRef()[0] != '#' )
914 {
915 wxString new_ref = "#" + references[ii].GetRef();
916 references[ii].SetRef( new_ref );
917 }
918 }
919
920 // Recalculate and update reference numbers in schematic
921 references.Annotate( false, 0, 100, lockedSymbols, additionalreferences );
922 references.UpdateAnnotation();
923}
924
925
926void SCH_SHEET_LIST::GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols,
927 bool aForceIncludeOrphanSymbols ) const
928{
929 for( const SCH_SHEET_PATH& sheet : *this )
930 sheet.GetSymbols( aReferences, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
931}
932
933
935 const SCH_SHEET_PATH& aSheetPath,
936 bool aIncludePowerSymbols,
937 bool aForceIncludeOrphanSymbols ) const
938{
939 for( const SCH_SHEET_PATH& sheet : *this )
940 {
941 if( sheet.IsContainedWithin( aSheetPath ) )
942 sheet.GetSymbols( aReferences, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
943 }
944}
945
946
948 const SCH_SHEET_PATH& aSheetPath ) const
949{
950 for( const SCH_SHEET_PATH& sheet : *this )
951 {
952 if( sheet.IsContainedWithin( aSheetPath ) )
953 aSheets.push_back( sheet );
954 }
955}
956
957
958std::optional<SCH_SHEET_PATH> SCH_SHEET_LIST::GetSheetPathByKIIDPath( const KIID_PATH& aPath,
959 bool aIncludeLastSheet ) const
960{
961 for( const SCH_SHEET_PATH& sheet : *this )
962 {
963 KIID_PATH testPath = sheet.Path();
964
965 if( !aIncludeLastSheet )
966 testPath.pop_back();
967
968 if( testPath == aPath )
969 return SCH_SHEET_PATH( sheet );
970 }
971
972 return std::nullopt;
973}
974
975
977 bool aIncludePowerSymbols ) const
978{
979 for( SCH_SHEET_PATHS::const_iterator it = begin(); it != end(); ++it )
980 {
982 ( *it ).GetMultiUnitSymbols( tempMap, aIncludePowerSymbols );
983
984 for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : tempMap )
985 {
986 // Merge this list into the main one
987 unsigned n_refs = pair.second.GetCount();
988
989 for( unsigned thisRef = 0; thisRef < n_refs; ++thisRef )
990 aRefList[pair.first].AddItem( pair.second[thisRef] );
991 }
992 }
993}
994
995
996bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
997 const wxString& aDestFileName )
998{
999 if( empty() )
1000 return false;
1001
1002 SCHEMATIC* sch = at( 0 ).LastScreen()->Schematic();
1003
1004 wxCHECK_MSG( sch, false, "No SCHEMATIC found in SCH_SHEET_LIST::TestForRecursion!" );
1005
1006 wxFileName rootFn = sch->GetFileName();
1007 wxFileName destFn = aDestFileName;
1008
1009 if( destFn.IsRelative() )
1010 destFn.MakeAbsolute( rootFn.GetPath() );
1011
1012 // Test each SCH_SHEET_PATH in this SCH_SHEET_LIST for potential recursion.
1013 for( unsigned i = 0; i < size(); i++ )
1014 {
1015 // Test each SCH_SHEET_PATH in the source sheet.
1016 for( unsigned j = 0; j < aSrcSheetHierarchy.size(); j++ )
1017 {
1018 const SCH_SHEET_PATH* sheetPath = &aSrcSheetHierarchy[j];
1019
1020 for( unsigned k = 0; k < sheetPath->size(); k++ )
1021 {
1022 if( at( i ).TestForRecursion( sheetPath->GetSheet( k )->GetFileName(),
1023 aDestFileName ) )
1024 {
1025 return true;
1026 }
1027 }
1028 }
1029 }
1030
1031 // The source sheet file can safely be added to the destination sheet file.
1032 return false;
1033}
1034
1035
1037{
1038 for( SCH_SHEET_PATH& path : *this )
1039 {
1040 if( path.Path() == aPath->Path() )
1041 return &path;
1042 }
1043
1044 return nullptr;
1045}
1046
1047
1049{
1050 for( SCH_SHEET_PATH& sheetpath : *this )
1051 {
1052 if( sheetpath.LastScreen() == aScreen )
1053 return &sheetpath;
1054 }
1055
1056 return nullptr;
1057}
1058
1059
1061{
1062 SCH_SHEET_LIST retval;
1063
1064 for( const SCH_SHEET_PATH& sheetpath : *this )
1065 {
1066 if( sheetpath.LastScreen() == aScreen )
1067 retval.push_back( sheetpath );
1068 }
1069
1070 return retval;
1071}
1072
1073
1075 const std::vector<SCH_SYMBOL_INSTANCE>& aSymbolInstances )
1076{
1077 for( SCH_SHEET_PATH& sheetPath : *this )
1078 {
1079 for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1080 {
1081 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1082
1083 wxCHECK2( symbol, continue );
1084
1085 KIID_PATH sheetPathWithSymbolUuid = sheetPath.Path();
1086 sheetPathWithSymbolUuid.push_back( symbol->m_Uuid );
1087
1088 auto it = std::find_if( aSymbolInstances.begin(), aSymbolInstances.end(),
1089 [ sheetPathWithSymbolUuid ]( const SCH_SYMBOL_INSTANCE& r ) -> bool
1090 {
1091 return sheetPathWithSymbolUuid == r.m_Path;
1092 } );
1093
1094 if( it == aSymbolInstances.end() )
1095 {
1096 wxLogTrace( traceSchSheetPaths, "No symbol instance found for symbol '%s'",
1097 sheetPathWithSymbolUuid.AsString() );
1098 continue;
1099 }
1100
1101 // Symbol instance paths are stored and looked up in memory with the root path so use
1102 // the full path here.
1103 symbol->AddHierarchicalReference( sheetPath.Path(), it->m_Reference, it->m_Unit );
1104 symbol->GetField( REFERENCE_FIELD )->SetText( it->m_Reference );
1105
1106 if( !it->m_Value.IsEmpty() )
1107 symbol->SetValueFieldText( it->m_Value );
1108
1109 if( !it->m_Footprint.IsEmpty() )
1110 symbol->SetFootprintFieldText( it->m_Footprint );
1111
1112 symbol->UpdatePrefix();
1113 }
1114 }
1115}
1116
1117
1118void SCH_SHEET_LIST::UpdateSheetInstanceData( const std::vector<SCH_SHEET_INSTANCE>& aSheetInstances )
1119{
1120
1121 for( SCH_SHEET_PATH& path : *this )
1122 {
1123 SCH_SHEET* sheet = path.Last();
1124
1125 wxCHECK2( sheet && path.Last(), continue );
1126
1127 auto it = std::find_if( aSheetInstances.begin(), aSheetInstances.end(),
1128 [ path ]( const SCH_SHEET_INSTANCE& r ) -> bool
1129 {
1130 return path.Path() == r.m_Path;
1131 } );
1132
1133 if( it == aSheetInstances.end() )
1134 {
1135 wxLogTrace( traceSchSheetPaths, "No sheet instance found for path '%s'",
1136 path.Path().AsString() );
1137 continue;
1138 }
1139
1140 wxLogTrace( traceSchSheetPaths, "Setting sheet '%s' instance '%s' page number '%s'",
1141 ( sheet->GetName().IsEmpty() ) ? wxString( wxT( "root" ) ) : sheet->GetName(),
1142 path.Path().AsString(), it->m_PageNumber );
1143 path.SetPageNumber( it->m_PageNumber );
1144 }
1145}
1146
1147
1148std::vector<KIID_PATH> SCH_SHEET_LIST::GetPaths() const
1149{
1150 std::vector<KIID_PATH> paths;
1151
1152 for( const SCH_SHEET_PATH& sheetPath : *this )
1153 paths.emplace_back( sheetPath.Path() );
1154
1155 return paths;
1156}
1157
1158
1159std::vector<SCH_SHEET_INSTANCE> SCH_SHEET_LIST::GetSheetInstances() const
1160{
1161 std::vector<SCH_SHEET_INSTANCE> retval;
1162
1163 for( const SCH_SHEET_PATH& path : *this )
1164 {
1165 const SCH_SHEET* sheet = path.Last();
1166
1167 wxCHECK2( sheet, continue );
1168
1169 SCH_SHEET_INSTANCE instance;
1170 SCH_SHEET_PATH tmpPath = path;
1171
1172 tmpPath.pop_back();
1173 instance.m_Path = tmpPath.Path();
1174 instance.m_PageNumber = path.GetPageNumber();
1175
1176 retval.push_back( instance );
1177 }
1178
1179 return retval;
1180}
1181
1182
1184{
1185 for( const SCH_SHEET_PATH& instance : *this )
1186 {
1187 if( !instance.GetPageNumber().IsEmpty() )
1188 return false;
1189 }
1190
1191 return true;
1192}
1193
1194
1196{
1197 // Don't accidentally renumber existing sheets.
1198 wxCHECK( AllSheetPageNumbersEmpty(), /* void */ );
1199
1200 wxString tmp;
1201 int pageNumber = 1;
1202
1203 for( SCH_SHEET_PATH& instance : *this )
1204 {
1205 tmp.Printf( "%d", pageNumber );
1206 instance.SetPageNumber( tmp );
1207 pageNumber += 1;
1208 }
1209}
1210
1211
1213{
1214 for( SCH_SHEET_PATH& sheetPath : *this )
1215 sheetPath.AddNewSymbolInstances( aPrefixSheetPath );
1216}
1217
1218
1220{
1221 for( SCH_SHEET_PATH& sheetPath : *this )
1222 sheetPath.RemoveSymbolInstances( aPrefixSheetPath );
1223}
1224
1225
1227 int aLastVirtualPageNumber )
1228{
1229 wxString pageNumber;
1230 int lastUsedPageNumber = 1;
1231 int nextVirtualPageNumber = aLastVirtualPageNumber;
1232
1233 // Fetch the list of page numbers already in use.
1234 std::vector< wxString > usedPageNumbers;
1235
1236 if( aPrefixSheetPath.size() )
1237 {
1238 SCH_SHEET_LIST prefixHierarchy( aPrefixSheetPath.at( 0 ) );
1239
1240 for( const SCH_SHEET_PATH& path : prefixHierarchy )
1241 {
1242 pageNumber = path.GetPageNumber();
1243
1244 if( !pageNumber.IsEmpty() )
1245 usedPageNumbers.emplace_back( pageNumber );
1246 }
1247 }
1248
1249 for( SCH_SHEET_PATH& sheetPath : *this )
1250 {
1251 SCH_SHEET_PATH tmp( sheetPath );
1252 SCH_SHEET_PATH newSheetPath( aPrefixSheetPath );
1253
1254 // Prefix the new hierarchical path.
1255 newSheetPath = newSheetPath + sheetPath;
1256
1257 // Sheets cannot have themselves in the path.
1258 tmp.pop_back();
1259
1260 SCH_SHEET* sheet = sheetPath.Last();
1261
1262 wxCHECK2( sheet, continue );
1263
1264 nextVirtualPageNumber += 1;
1265
1266 SCH_SHEET_INSTANCE instance;
1267
1268 if( sheet->getInstance( instance, tmp.Path(), true )
1269 && !instance.m_PageNumber.IsEmpty() )
1270 {
1271 newSheetPath.SetPageNumber( instance.m_PageNumber );
1272 usedPageNumbers.push_back( instance.m_PageNumber );
1273 }
1274 else
1275 {
1276 // Generate the next available page number.
1277 do
1278 {
1279 pageNumber.Printf( wxT( "%d" ), lastUsedPageNumber );
1280 lastUsedPageNumber += 1;
1281 } while( std::find( usedPageNumbers.begin(), usedPageNumbers.end(), pageNumber ) !=
1282 usedPageNumbers.end() );
1283
1284 newSheetPath.SetVirtualPageNumber( nextVirtualPageNumber );
1285 newSheetPath.SetPageNumber( pageNumber );
1286 usedPageNumbers.push_back( pageNumber );
1287 }
1288 }
1289}
1290
1291
1293{
1294 int lastVirtualPageNumber = 1;
1295
1296 for( const SCH_SHEET_PATH& sheetPath : *this )
1297 {
1298 if( sheetPath.GetVirtualPageNumber() > lastVirtualPageNumber )
1299 lastVirtualPageNumber = sheetPath.GetVirtualPageNumber();
1300 }
1301
1302 return lastVirtualPageNumber;
1303}
1304
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.
void Print(const RENDER_SETTINGS *aSettings, const VECTOR2I &aOffset) override
Print a schematic item.
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
wxString GetClass() const override
Return the class name.
void SetPosition(const VECTOR2I &) override
static DELETED_SHEET_ITEM * GetInstance()
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
void MirrorVertically(int aCenter) override
Mirror item vertically about aCenter.
void MirrorHorizontally(int aCenter) override
Mirror item horizontally about aCenter.
void Rotate(const VECTOR2I &aCenter) override
Rotate the item around aCenter 90 degrees in the clockwise direction.
const KIID m_Uuid
Definition: eda_item.h:492
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
virtual bool IsVisible() const
Definition: eda_text.h:136
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:219
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:165
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
wxString AsString() const
Definition: kiid.cpp:359
Definition: kiid.h:48
wxString AsString() const
Definition: kiid.cpp:257
Define a library symbol object.
Definition: lib_symbol.h:99
bool IsPower() const
Definition: lib_symbol.cpp:545
int GetUnitCount() const override
For items with units, return the number of units.
Holds all the data relating to one schematic.
Definition: schematic.h:61
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:199
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:205
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:1068
const wxString & GetInternalName()
Get the initial name of the field set at creation (or set by SetName()).
Definition: sch_field.h:123
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:112
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:444
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_label.cpp:376
std::vector< SCH_FIELD > & GetFields()
Definition: sch_label.h:90
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:109
const wxString & GetFileName() const
Definition: sch_screen.h:144
bool Remove(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:307
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:92
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:300
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 SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
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.
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
SCH_SHEET_LIST(SCH_SHEET *aSheet=nullptr, bool aCheckIntegrity=false)
Construct a flattened list of SCH_SHEET_PATH objects from aSheet.
int GetLastVirtualPageNumber() const
void UpdateSymbolInstanceData(const std::vector< SCH_SYMBOL_INSTANCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
SCH_SHEET_PATH * FindSheetForScreen(const SCH_SCREEN *aScreen)
Return a pointer to the first SCH_SHEET_PATH object (not necessarily the only one) using a particular...
bool PageNumberExists(const wxString &aPageNumber) const
void AddNewSheetInstances(const SCH_SHEET_PATH &aPrefixSheetPath, int aLastVirtualPageNumber)
std::vector< KIID_PATH > GetPaths() const
void AddNewSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath)
Attempt to add new symbol instances for all symbols in this list of sheet paths prefixed with aPrefix...
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.
void GetSheetsWithinPath(SCH_SHEET_PATHS &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...
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...
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
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 AddNewSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath)
Attempt to add new symbol instances for all symbols in this sheet path prefixed with aPrefixSheetPath...
void MakeFilePathRelativeToParentSheet()
Make the sheet file name relative to its parent sheet.
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 GetPageNumber() const
void RemoveSymbolInstances(const SCH_SHEET_PATH &aPrefixSheetPath)
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
std::vector< SCH_SHEET * > m_sheets
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.
wxString PathAsString() const
Return the path of time stamps which do not changes even when editing sheet parameters.
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
SCH_SHEET_PATH & operator=(const SCH_SHEET_PATH &aOther)
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:308
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:302
bool IsRootSheet() const
Definition: sch_sheet.cpp:194
bool getInstance(SCH_SHEET_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
Definition: sch_sheet.cpp:1247
void setPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1320
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:93
wxString GetName() const
Definition: sch_sheet.h:103
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:106
static int ComparePageNum(const wxString &aPageNumberA, const wxString &aPageNumberB)
Compares page numbers of schematic sheets.
Definition: sch_sheet.cpp:1338
wxString getPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1299
bool addInstance(const SCH_SHEET_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1221
Schematic symbol object.
Definition: sch_symbol.h:81
void UpdatePrefix()
Set the prefix based on the current reference designator.
Definition: sch_symbol.cpp:766
int GetUnit() const
Definition: sch_symbol.h:228
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstanceReferences()
Definition: sch_symbol.h:140
void UpdateUnit(int aUnit)
Change the unit number to aUnit without setting any internal flags.
Definition: sch_symbol.cpp:398
void RemoveInstance(const SCH_SHEET_PATH &aInstancePath)
Definition: sch_symbol.cpp:543
void SetValueFieldText(const wxString &aValue)
Definition: sch_symbol.cpp:844
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:674
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:865
void SetFootprintFieldText(const wxString &aFootprint)
Definition: sch_symbol.cpp:859
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
Definition: sch_symbol.cpp:572
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
Definition: sch_symbol.cpp:519
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
Definition: sch_symbol.cpp:793
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:192
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
const wxChar *const traceSchSheetPaths
Flag to enable debug output of schematic symbol sheet path manipulation code.
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.
static void hash_combine(std::size_t &seed)
This is a dummy function to take the final case of hash_combine below.
Definition: hash.h:34
_OUT_STRING AsString(const std::string &aString)
Definition: sexpr.h:131
Definition: bitmap.cpp:65
@ SHEETNAME
Definition: sch_sheet.h:45
bool SortSymbolInstancesByProjectUuid(const SCH_SYMBOL_INSTANCE &aLhs, const SCH_SYMBOL_INSTANCE &aRhs)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::vector< SCH_SHEET_PATH > SCH_SHEET_PATHS
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.
size_t operator()(const SCH_SHEET_PATH &path) const
Definition for symbol library class.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
wxLogTrace helper definitions.
@ SCH_SYMBOL_T
Definition: typeinfo.h:156
@ NOT_USED
the 3d code uses this value
Definition: typeinfo.h:79
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:152
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590