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 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{
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;
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( false ) << 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
770void SCH_SHEET_LIST::TrimToPageNumbers( const std::vector<wxString>& aPageInclusions )
771{
772 auto it = std::remove_if( begin(), end(),
773 [&]( SCH_SHEET_PATH sheet )
774 {
775 return std::find( aPageInclusions.begin(), aPageInclusions.end(),
776 sheet.GetPageNumber() )
777 == aPageInclusions.end();
778 } );
779
780 erase( it, end() );
781}
782
783
785{
786 for( const SCH_SHEET_PATH& sheet : *this )
787 {
788 if( sheet.LastScreen() && sheet.LastScreen()->IsContentModified() )
789 return true;
790 }
791
792 return false;
793}
794
795
797{
798 for( const SCH_SHEET_PATH& sheet : *this )
799 {
800 if( sheet.LastScreen() )
801 sheet.LastScreen()->SetContentModified( false );
802 }
803}
804
805
807{
808 for( const SCH_SHEET_PATH& sheet : *this )
809 {
810 SCH_ITEM* item = sheet.GetItem( aID );
811
812 if( item )
813 {
814 if( aPathOut )
815 *aPathOut = sheet;
816
817 return item;
818 }
819 }
820
821 // Not found; weak reference has been deleted.
823}
824
825
827{
828 for( SCH_ITEM* aItem : LastScreen()->Items() )
829 {
830 if( aItem->m_Uuid == aID )
831 return aItem;
832
833 SCH_ITEM* childMatch = nullptr;
834
835 aItem->RunOnChildren(
836 [&]( SCH_ITEM* aChild )
837 {
838 if( aChild->m_Uuid == aID )
839 childMatch = aChild;
840 } );
841
842 if( childMatch )
843 return childMatch;
844 }
845
846 return nullptr;
847}
848
849
850void SCH_SHEET_LIST::FillItemMap( std::map<KIID, EDA_ITEM*>& aMap )
851{
852 for( const SCH_SHEET_PATH& sheet : *this )
853 {
854 SCH_SCREEN* screen = sheet.LastScreen();
855
856 for( SCH_ITEM* aItem : screen->Items() )
857 {
858 aMap[ aItem->m_Uuid ] = aItem;
859
860 aItem->RunOnChildren(
861 [&]( SCH_ITEM* aChild )
862 {
863 aMap[ aChild->m_Uuid ] = aChild;
864 } );
865 }
866 }
867}
868
869
871{
872 // List of reference for power symbols
873 SCH_REFERENCE_LIST references;
874 SCH_REFERENCE_LIST additionalreferences; // Todo: add as a parameter to this function
875
876 // Map of locked symbols (not used, but needed by Annotate()
877 SCH_MULTI_UNIT_REFERENCE_MAP lockedSymbols;
878
879 // Build the list of power symbols:
880 for( SCH_SHEET_PATH& sheet : *this )
881 {
882 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
883 {
884 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
885 LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
886
887 if( libSymbol && libSymbol->IsPower() )
888 {
889 SCH_REFERENCE schReference( symbol, libSymbol, sheet );
890 references.AddItem( schReference );
891 }
892 }
893 }
894
895 // Find duplicate, and silently clear annotation of duplicate
896 std::map<wxString, int> ref_list; // stores the existing references
897
898 for( unsigned ii = 0; ii< references.GetCount(); ++ii )
899 {
900 wxString curr_ref = references[ii].GetRef();
901
902 if( ref_list.find( curr_ref ) == ref_list.end() )
903 {
904 ref_list[curr_ref] = ii;
905 continue;
906 }
907
908 // Possible duplicate, if the ref ends by a number:
909 if( curr_ref.Last() < '0' && curr_ref.Last() > '9' )
910 continue; // not annotated
911
912 // Duplicate: clear annotation by removing the number ending the ref
913 while( curr_ref.Last() >= '0' && curr_ref.Last() <= '9' )
914 curr_ref.RemoveLast();
915
916 references[ii].SetRef( curr_ref );
917 }
918
919 // Break full symbol reference into name (prefix) and number:
920 // example: IC1 become IC, and 1
921 references.SplitReferences();
922
923 // Ensure all power symbols have the reference starting by '#'
924 // (Not sure this is really useful)
925 for( unsigned ii = 0; ii< references.GetCount(); ++ii )
926 {
927 if( references[ii].GetRef()[0] != '#' )
928 {
929 wxString new_ref = "#" + references[ii].GetRef();
930 references[ii].SetRef( new_ref );
931 }
932 }
933
934 // Recalculate and update reference numbers in schematic
935 references.Annotate( false, 0, 100, lockedSymbols, additionalreferences );
936 references.UpdateAnnotation();
937}
938
939
940void SCH_SHEET_LIST::GetSymbols( SCH_REFERENCE_LIST& aReferences, bool aIncludePowerSymbols,
941 bool aForceIncludeOrphanSymbols ) const
942{
943 for( const SCH_SHEET_PATH& sheet : *this )
944 sheet.GetSymbols( aReferences, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
945}
946
947
949 const SCH_SHEET_PATH& aSheetPath,
950 bool aIncludePowerSymbols,
951 bool aForceIncludeOrphanSymbols ) const
952{
953 for( const SCH_SHEET_PATH& sheet : *this )
954 {
955 if( sheet.IsContainedWithin( aSheetPath ) )
956 sheet.GetSymbols( aReferences, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
957 }
958}
959
960
962 const SCH_SHEET_PATH& aSheetPath ) const
963{
964 for( const SCH_SHEET_PATH& sheet : *this )
965 {
966 if( sheet.IsContainedWithin( aSheetPath ) )
967 aSheets.push_back( sheet );
968 }
969}
970
971
972std::optional<SCH_SHEET_PATH> SCH_SHEET_LIST::GetSheetPathByKIIDPath( const KIID_PATH& aPath,
973 bool aIncludeLastSheet ) const
974{
975 for( const SCH_SHEET_PATH& sheet : *this )
976 {
977 KIID_PATH testPath = sheet.Path();
978
979 if( !aIncludeLastSheet )
980 testPath.pop_back();
981
982 if( testPath == aPath )
983 return SCH_SHEET_PATH( sheet );
984 }
985
986 return std::nullopt;
987}
988
989
991 bool aIncludePowerSymbols ) const
992{
993 for( SCH_SHEET_PATHS::const_iterator it = begin(); it != end(); ++it )
994 {
996 ( *it ).GetMultiUnitSymbols( tempMap, aIncludePowerSymbols );
997
998 for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : tempMap )
999 {
1000 // Merge this list into the main one
1001 unsigned n_refs = pair.second.GetCount();
1002
1003 for( unsigned thisRef = 0; thisRef < n_refs; ++thisRef )
1004 aRefList[pair.first].AddItem( pair.second[thisRef] );
1005 }
1006 }
1007}
1008
1009
1010bool SCH_SHEET_LIST::TestForRecursion( const SCH_SHEET_LIST& aSrcSheetHierarchy,
1011 const wxString& aDestFileName )
1012{
1013 if( empty() )
1014 return false;
1015
1016 SCHEMATIC* sch = at( 0 ).LastScreen()->Schematic();
1017
1018 wxCHECK_MSG( sch, false, "No SCHEMATIC found in SCH_SHEET_LIST::TestForRecursion!" );
1019
1020 wxFileName rootFn = sch->GetFileName();
1021 wxFileName destFn = aDestFileName;
1022
1023 if( destFn.IsRelative() )
1024 destFn.MakeAbsolute( rootFn.GetPath() );
1025
1026 // Test each SCH_SHEET_PATH in this SCH_SHEET_LIST for potential recursion.
1027 for( unsigned i = 0; i < size(); i++ )
1028 {
1029 // Test each SCH_SHEET_PATH in the source sheet.
1030 for( unsigned j = 0; j < aSrcSheetHierarchy.size(); j++ )
1031 {
1032 const SCH_SHEET_PATH* sheetPath = &aSrcSheetHierarchy[j];
1033
1034 for( unsigned k = 0; k < sheetPath->size(); k++ )
1035 {
1036 if( at( i ).TestForRecursion( sheetPath->GetSheet( k )->GetFileName(),
1037 aDestFileName ) )
1038 {
1039 return true;
1040 }
1041 }
1042 }
1043 }
1044
1045 // The source sheet file can safely be added to the destination sheet file.
1046 return false;
1047}
1048
1049
1051{
1052 for( SCH_SHEET_PATH& path : *this )
1053 {
1054 if( path.Path() == aPath->Path() )
1055 return &path;
1056 }
1057
1058 return nullptr;
1059}
1060
1061
1063{
1064 for( SCH_SHEET_PATH& sheetpath : *this )
1065 {
1066 if( sheetpath.LastScreen() == aScreen )
1067 return sheetpath;
1068 }
1069
1070 return SCH_SHEET_PATH();
1071}
1072
1073
1075{
1076 SCH_SHEET_LIST retval;
1077
1078 for( const SCH_SHEET_PATH& sheetpath : *this )
1079 {
1080 if( sheetpath.LastScreen() == aScreen )
1081 retval.push_back( sheetpath );
1082 }
1083
1084 return retval;
1085}
1086
1087
1089 const std::vector<SCH_SYMBOL_INSTANCE>& aSymbolInstances )
1090{
1091 for( SCH_SHEET_PATH& sheetPath : *this )
1092 {
1093 for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
1094 {
1095 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1096
1097 wxCHECK2( symbol, continue );
1098
1099 KIID_PATH sheetPathWithSymbolUuid = sheetPath.Path();
1100 sheetPathWithSymbolUuid.push_back( symbol->m_Uuid );
1101
1102 auto it = std::find_if( aSymbolInstances.begin(), aSymbolInstances.end(),
1103 [ sheetPathWithSymbolUuid ]( const SCH_SYMBOL_INSTANCE& r ) -> bool
1104 {
1105 return sheetPathWithSymbolUuid == r.m_Path;
1106 } );
1107
1108 if( it == aSymbolInstances.end() )
1109 {
1110 wxLogTrace( traceSchSheetPaths, "No symbol instance found for symbol '%s'",
1111 sheetPathWithSymbolUuid.AsString() );
1112 continue;
1113 }
1114
1115 // Symbol instance paths are stored and looked up in memory with the root path so use
1116 // the full path here.
1117 symbol->AddHierarchicalReference( sheetPath.Path(), it->m_Reference, it->m_Unit );
1118 symbol->GetField( REFERENCE_FIELD )->SetText( it->m_Reference );
1119
1120 if( !it->m_Value.IsEmpty() )
1121 symbol->SetValueFieldText( it->m_Value );
1122
1123 if( !it->m_Footprint.IsEmpty() )
1124 symbol->SetFootprintFieldText( it->m_Footprint );
1125
1126 symbol->UpdatePrefix();
1127 }
1128 }
1129}
1130
1131
1132void SCH_SHEET_LIST::UpdateSheetInstanceData( const std::vector<SCH_SHEET_INSTANCE>& aSheetInstances )
1133{
1134
1135 for( SCH_SHEET_PATH& path : *this )
1136 {
1137 SCH_SHEET* sheet = path.Last();
1138
1139 wxCHECK2( sheet && path.Last(), continue );
1140
1141 auto it = std::find_if( aSheetInstances.begin(), aSheetInstances.end(),
1142 [ path ]( const SCH_SHEET_INSTANCE& r ) -> bool
1143 {
1144 return path.Path() == r.m_Path;
1145 } );
1146
1147 if( it == aSheetInstances.end() )
1148 {
1149 wxLogTrace( traceSchSheetPaths, "No sheet instance found for path '%s'",
1150 path.Path().AsString() );
1151 continue;
1152 }
1153
1154 wxLogTrace( traceSchSheetPaths, "Setting sheet '%s' instance '%s' page number '%s'",
1155 ( sheet->GetName().IsEmpty() ) ? wxString( wxT( "root" ) ) : sheet->GetName(),
1156 path.Path().AsString(), it->m_PageNumber );
1157 path.SetPageNumber( it->m_PageNumber );
1158 }
1159}
1160
1161
1162std::vector<KIID_PATH> SCH_SHEET_LIST::GetPaths() const
1163{
1164 std::vector<KIID_PATH> paths;
1165
1166 for( const SCH_SHEET_PATH& sheetPath : *this )
1167 paths.emplace_back( sheetPath.Path() );
1168
1169 return paths;
1170}
1171
1172
1173std::vector<SCH_SHEET_INSTANCE> SCH_SHEET_LIST::GetSheetInstances() const
1174{
1175 std::vector<SCH_SHEET_INSTANCE> retval;
1176
1177 for( const SCH_SHEET_PATH& path : *this )
1178 {
1179 const SCH_SHEET* sheet = path.Last();
1180
1181 wxCHECK2( sheet, continue );
1182
1183 SCH_SHEET_INSTANCE instance;
1184 SCH_SHEET_PATH tmpPath = path;
1185
1186 tmpPath.pop_back();
1187 instance.m_Path = tmpPath.Path();
1188 instance.m_PageNumber = path.GetPageNumber();
1189
1190 retval.push_back( instance );
1191 }
1192
1193 return retval;
1194}
1195
1196
1198{
1199 for( const SCH_SHEET_PATH& instance : *this )
1200 {
1201 if( !instance.GetPageNumber().IsEmpty() )
1202 return false;
1203 }
1204
1205 return true;
1206}
1207
1208
1210{
1211 // Don't accidentally renumber existing sheets.
1212 wxCHECK( AllSheetPageNumbersEmpty(), /* void */ );
1213
1214 wxString tmp;
1215 int pageNumber = 1;
1216
1217 for( SCH_SHEET_PATH& instance : *this )
1218 {
1219 tmp.Printf( "%d", pageNumber );
1220 instance.SetPageNumber( tmp );
1221 pageNumber += 1;
1222 }
1223}
1224
1225
1227{
1228 for( SCH_SHEET_PATH& sheetPath : *this )
1229 sheetPath.AddNewSymbolInstances( aPrefixSheetPath );
1230}
1231
1232
1234{
1235 for( SCH_SHEET_PATH& sheetPath : *this )
1236 sheetPath.RemoveSymbolInstances( aPrefixSheetPath );
1237}
1238
1239
1241 int aLastVirtualPageNumber )
1242{
1243 wxString pageNumber;
1244 int lastUsedPageNumber = 1;
1245 int nextVirtualPageNumber = aLastVirtualPageNumber;
1246
1247 // Fetch the list of page numbers already in use.
1248 std::vector< wxString > usedPageNumbers;
1249
1250 if( aPrefixSheetPath.size() )
1251 {
1252 SCH_SHEET_LIST prefixHierarchy( aPrefixSheetPath.at( 0 ) );
1253
1254 for( const SCH_SHEET_PATH& path : prefixHierarchy )
1255 {
1256 pageNumber = path.GetPageNumber();
1257
1258 if( !pageNumber.IsEmpty() )
1259 usedPageNumbers.emplace_back( pageNumber );
1260 }
1261 }
1262
1263 for( SCH_SHEET_PATH& sheetPath : *this )
1264 {
1265 SCH_SHEET_PATH tmp( sheetPath );
1266 SCH_SHEET_PATH newSheetPath( aPrefixSheetPath );
1267
1268 // Prefix the new hierarchical path.
1269 newSheetPath = newSheetPath + sheetPath;
1270
1271 // Sheets cannot have themselves in the path.
1272 tmp.pop_back();
1273
1274 SCH_SHEET* sheet = sheetPath.Last();
1275
1276 wxCHECK2( sheet, continue );
1277
1278 nextVirtualPageNumber += 1;
1279
1280 SCH_SHEET_INSTANCE instance;
1281
1282 // Add the instance if it doesn't already exist
1283 if( !sheet->getInstance( instance, tmp.Path(), true ) )
1284 {
1285 sheet->addInstance( tmp );
1286 sheet->getInstance( instance, tmp.Path(), true );
1287 }
1288
1289 // Get a new page number if we don't have one
1290 if( instance.m_PageNumber.IsEmpty() )
1291 {
1292 // Generate the next available page number.
1293 do
1294 {
1295 pageNumber.Printf( wxT( "%d" ), lastUsedPageNumber );
1296 lastUsedPageNumber += 1;
1297 } while( std::find( usedPageNumbers.begin(), usedPageNumbers.end(), pageNumber ) !=
1298 usedPageNumbers.end() );
1299
1300 instance.m_PageNumber = pageNumber;
1301 newSheetPath.SetVirtualPageNumber( nextVirtualPageNumber );
1302 }
1303
1304 newSheetPath.SetPageNumber( instance.m_PageNumber );
1305 usedPageNumbers.push_back( instance.m_PageNumber );
1306 }
1307}
1308
1309
1311{
1312 int lastVirtualPageNumber = 1;
1313
1314 for( const SCH_SHEET_PATH& sheetPath : *this )
1315 {
1316 if( sheetPath.GetVirtualPageNumber() > lastVirtualPageNumber )
1317 lastVirtualPageNumber = sheetPath.GetVirtualPageNumber();
1318 }
1319
1320 return lastVirtualPageNumber;
1321}
1322
1323
1324bool SCH_SHEET_LIST::HasPath( const KIID_PATH& aPath ) const
1325{
1326 for( const SCH_SHEET_PATH& path : *this )
1327 {
1328 if( path.Path() == aPath )
1329 return true;
1330 }
1331
1332 return false;
1333}
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:482
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:95
virtual bool IsVisible() const
Definition: eda_text.h:147
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:226
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:49
wxString AsString() const
Definition: kiid.cpp:257
Define a library symbol object.
Definition: lib_symbol.h:99
bool IsPower() const
Definition: lib_symbol.cpp:714
int GetUnitCount() const override
For items with units, return the number of units.
Holds all the data relating to one schematic.
Definition: schematic.h:75
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:203
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:209
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:52
VECTOR2I GetPosition() const override
Definition: sch_field.cpp:1256
void SetText(const wxString &aText) override
Definition: sch_field.cpp:985
const wxString & GetInternalName()
Get the initial name of the field set at creation (or set by SetName()).
Definition: sch_field.h:126
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:150
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:113
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:463
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_label.cpp:582
std::vector< SCH_FIELD > & GetFields()
Definition: sch_label.h:167
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:321
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:98
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:314
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.
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.
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.
SCH_SHEET_PATH FindSheetForScreen(const SCH_SCREEN *aScreen)
Return the first SCH_SHEET_PATH object (not necessarily the only one) using a particular screen.
bool HasPath(const KIID_PATH &aPath) const
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:318
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:312
bool IsRootSheet() const
Definition: sch_sheet.cpp:193
bool getInstance(SCH_SHEET_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
Definition: sch_sheet.cpp:1263
void setPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1336
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:1354
wxString getPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1315
bool addInstance(const SCH_SHEET_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1237
Schematic symbol object.
Definition: sch_symbol.h:81
void UpdatePrefix()
Set the prefix based on the current reference designator.
Definition: sch_symbol.cpp:757
int GetUnit() const
Definition: sch_symbol.h:226
void UpdateUnit(int aUnit)
Change the unit number to aUnit without setting any internal flags.
Definition: sch_symbol.cpp:393
void RemoveInstance(const SCH_SHEET_PATH &aInstancePath)
Definition: sch_symbol.cpp:534
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstanceReferences() const
Definition: sch_symbol.h:140
void SetValueFieldText(const wxString &aValue)
Definition: sch_symbol.cpp:836
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:665
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:858
void SetFootprintFieldText(const wxString &aFootprint)
Definition: sch_symbol.cpp:852
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
Definition: sch_symbol.cpp:563
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
Definition: sch_symbol.cpp:510
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
Definition: sch_symbol.cpp:784
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:190
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.
STL namespace.
@ 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.
Definition for symbol library class.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
wxLogTrace helper definitions.
@ SCH_SYMBOL_T
Definition: typeinfo.h:155
@ NOT_USED
the 3d code uses this value
Definition: typeinfo.h:79
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:151
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588