KiCad PCB EDA Suite
SCH_SHEET_PATH Class Reference

Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened schematic hierarchy. More...

#include <sch_sheet_path.h>

Public Member Functions

 SCH_SHEET_PATH ()
 
 SCH_SHEET_PATH (const SCH_SHEET_PATH &aOther)
 
SCH_SHEET_PATHoperator= (const SCH_SHEET_PATH &aOther)
 
SCH_SHEET_PATH operator+ (const SCH_SHEET_PATH &aOther)
 
 ~SCH_SHEET_PATH ()=default
 
SCH_SHEETat (size_t aIndex) const
 Forwarded method from std::vector. More...
 
void clear ()
 Forwarded method from std::vector. More...
 
bool empty () const
 Forwarded method from std::vector. More...
 
void pop_back ()
 Forwarded method from std::vector. More...
 
void push_back (SCH_SHEET *aSheet)
 Forwarded method from std::vector. More...
 
size_t size () const
 Forwarded method from std::vector. More...
 
std::vector< SCH_SHEET * >::iterator erase (std::vector< SCH_SHEET * >::const_iterator aPosition)
 
void Rehash ()
 
size_t GetCurrentHash () const
 
void SetVirtualPageNumber (int aPageNumber)
 Set the sheet instance virtual page number. More...
 
int GetVirtualPageNumber () const
 
void SetPageNumber (const wxString &aPageNumber)
 Set the sheet instance user definable page number. More...
 
wxString GetPageNumber () const
 
const SCH_SHEETGetSheet (unsigned aIndex) const
 
bool IsFullPath () const
 
int Cmp (const SCH_SHEET_PATH &aSheetPathToTest) const
 Compare if this is the same sheet path as aSheetPathToTest. More...
 
int ComparePageNum (const SCH_SHEET_PATH &aSheetPathToTest) const
 Compare sheets by their page number. More...
 
bool IsContainedWithin (const SCH_SHEET_PATH &aSheetPathToTest) const
 Check if this path is contained inside aSheetPathToTest. More...
 
SCH_SHEETLast () const
 Return a pointer to the last SCH_SHEET of the list. More...
 
SCH_SCREENLastScreen ()
 
SCH_SCREENLastScreen () const
 
SCH_ITEMGetItem (const KIID &aID) const
 Fetch a SCH_ITEM by ID. More...
 
wxString PathAsString () const
 Return the path of time stamps which do not changes even when editing sheet parameters. More...
 
KIID_PATH Path () const
 Get the sheet path as an KIID_PATH. More...
 
wxString PathHumanReadable (bool aUseShortRootName=true, bool aStripTrailingSeparator=false) const
 Return the sheet path in a human readable form made from the sheet names. More...
 
void UpdateAllScreenReferences () const
 Update all the symbol references for this sheet path. More...
 
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. More...
 
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. More...
 
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-unit parts together. More...
 
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 sheet. More...
 
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 sheet stored in file aDestFileName will cause a sheet path recursion. More...
 
void MakeFilePathRelativeToParentSheet ()
 Make the sheet file name relative to its parent sheet. More...
 
void AddNewSymbolInstances (const SCH_SHEET_PATH &aPrefixSheetPath)
 Attempt to add new symbol instances for all symbols in this sheet path prefixed with aPrefixSheetPath. More...
 
void RemoveSymbolInstances (const SCH_SHEET_PATH &aPrefixSheetPath)
 
bool operator== (const SCH_SHEET_PATH &d1) const
 
bool operator!= (const SCH_SHEET_PATH &d1) const
 
bool operator< (const SCH_SHEET_PATH &d1) const
 

Protected Attributes

std::vector< SCH_SHEET * > m_sheets
 
size_t m_current_hash
 
int m_virtualPageNumber
 
std::map< std::pair< wxString, wxString >, bool > m_recursion_test_cache
 Page numbers are maintained by the sheet load order. More...
 

Private Member Functions

void initFromOther (const SCH_SHEET_PATH &aOther)
 

Detailed Description

Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened schematic hierarchy.

The SCH_SHEET objects are stored in a list from first (usually the root sheet) to a given sheet in last position. The last sheet is usually the sheet we want to select or reach (which is what the function Last() returns). Others sheets constitute the "path" from the first to the last sheet.

Definition at line 140 of file sch_sheet_path.h.

Constructor & Destructor Documentation

◆ SCH_SHEET_PATH() [1/2]

SCH_SHEET_PATH::SCH_SHEET_PATH ( )

Definition at line 107 of file sch_sheet_path.cpp.

108{
110 m_current_hash = 0;
111}

References m_current_hash, and m_virtualPageNumber.

◆ SCH_SHEET_PATH() [2/2]

SCH_SHEET_PATH::SCH_SHEET_PATH ( const SCH_SHEET_PATH aOther)

Definition at line 114 of file sch_sheet_path.cpp.

115{
116 initFromOther( aOther );
117}
void initFromOther(const SCH_SHEET_PATH &aOther)

References initFromOther().

◆ ~SCH_SHEET_PATH()

SCH_SHEET_PATH::~SCH_SHEET_PATH ( )
default

Member Function Documentation

◆ AddNewSymbolInstances()

void SCH_SHEET_PATH::AddNewSymbolInstances ( const SCH_SHEET_PATH aPrefixSheetPath)

Attempt to add new symbol instances for all symbols in this sheet path prefixed with aPrefixSheetPath.

The new symbol instance data will be assigned by the following criteria:

  • If the instance data can be found for this sheet path, use the instance data.
  • If the instance data cannot be found for this sheet path and the instance data cache for the symbol is not empty, use the first instance data in the cache.
  • If the cache is empty and the library symbol link is valid, set the instance data from the library symbol.
  • If all else fails, set the reference to "U?", the unit to 1, and everything else to an empty string.

Definition at line 556 of file sch_sheet_path.cpp.

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}
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SCREEN * LastScreen()
Schematic symbol object.
Definition: sch_symbol.h:81
int GetUnit() const
Definition: sch_symbol.h:228
const std::vector< SCH_SYMBOL_INSTANCE > & GetInstanceReferences()
Definition: sch_symbol.h:140
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:843
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
Add a full hierarchical reference to this symbol.
Definition: sch_symbol.cpp:550
bool GetInstance(SCH_SYMBOL_INSTANCE &aInstance, const KIID_PATH &aSheetPath, bool aTestFromEnd=false) const
Definition: sch_symbol.cpp:497
A simple container for schematic symbol instance information.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
@ SCH_SYMBOL_T
Definition: typeinfo.h:156

References SCH_SYMBOL::AddHierarchicalReference(), SCH_SYMBOL::GetField(), SCH_SYMBOL::GetInstance(), SCH_SYMBOL::GetInstanceReferences(), EDA_TEXT::GetText(), SCH_SYMBOL::GetUnit(), LastScreen(), SCH_SYMBOL_INSTANCE::m_Path, SCH_SYMBOL_INSTANCE::m_Reference, SCH_SYMBOL_INSTANCE::m_Unit, Path(), REFERENCE_FIELD, and SCH_SYMBOL_T.

Referenced by SCH_SHEET_LIST::AddNewSymbolInstances().

◆ AppendMultiUnitSymbol()

void SCH_SHEET_PATH::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-unit parts together.

The map key for each element will be the reference designator.

Parameters
aRefListMap of reference designators to reference lists
aSymbolA symbol to add to aRefList
aIncludePowerSymbolsSet to false to only get normal symbols.

Definition at line 414 of file sch_sheet_path.cpp.

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}
Define a library symbol object.
Definition: lib_symbol.h:99
int GetUnitCount() const override
For items with units, return the number of units.
A helper to define a symbol's reference designator in a schematic.
wxString GetRef() const
void SetSheetNumber(int aSheetNumber)
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:652
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:192

References SCH_SYMBOL::GetLibSymbolRef(), SCH_REFERENCE::GetRef(), SCH_SYMBOL::GetRef(), LIB_SYMBOL::GetUnitCount(), m_virtualPageNumber, and SCH_REFERENCE::SetSheetNumber().

Referenced by SCH_EDIT_FRAME::AnnotateSymbols(), GetMultiUnitSymbols(), and TEST_SCH_REFERENCE_LIST_FIXTURE::loadTestCase().

◆ AppendSymbol()

void SCH_SHEET_PATH::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.

Parameters
aReferencesList of references to populate.
aSymbolA symbol to add to aReferences
aIncludePowerSymbolsset to false to only get normal symbols.
aForceIncludeOrphanSymbolsset to true to include symbols having no symbol found in lib. The normal option is false, and set to true only to build the full list of symbols.

Definition at line 382 of file sch_sheet_path.cpp.

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}
void AddItem(const SCH_REFERENCE &aItem)

References SCH_REFERENCE_LIST::AddItem(), SCH_SYMBOL::GetLibSymbolRef(), SCH_SYMBOL::GetRef(), m_virtualPageNumber, and SCH_REFERENCE::SetSheetNumber().

Referenced by SCH_EDIT_FRAME::AnnotateSymbols(), SCH_EDIT_FRAME::CheckAnnotate(), SCH_SEXPR_PLUGIN::Format(), GetSymbols(), and TEST_SCH_REFERENCE_LIST_FIXTURE::loadTestCase().

◆ at()

SCH_SHEET * SCH_SHEET_PATH::at ( size_t  aIndex) const
inline

Forwarded method from std::vector.

Definition at line 154 of file sch_sheet_path.h.

154{ return m_sheets.at( aIndex ); }
std::vector< SCH_SHEET * > m_sheets

References m_sheets.

Referenced by SCH_SHEET_LIST::AddNewSheetInstances(), Cmp(), GetSheet(), SCHEMATIC::GetUniqueFilenameForCurrentSheet(), IsContainedWithin(), SCH_SEXPR_PLUGIN::loadHierarchy(), operator+(), PathAsString(), PathHumanReadable(), and TestForRecursion().

◆ clear()

void SCH_SHEET_PATH::clear ( )
inline

Forwarded method from std::vector.

Definition at line 157 of file sch_sheet_path.h.

158 {
159 m_sheets.clear();
160 Rehash();
161 }

References m_sheets, and Rehash().

Referenced by SCH_EDIT_FRAME::doCloseWindow(), SCHEMATIC::Reset(), SCHEMATIC::SetRoot(), and HIERARCHY_PANE::UpdateHierarchyTree().

◆ Cmp()

int SCH_SHEET_PATH::Cmp ( const SCH_SHEET_PATH aSheetPathToTest) const

Compare if this is the same sheet path as aSheetPathToTest.

Parameters
aSheetPathToTestis the sheet path to compare.
Returns
1 if this sheet path has more sheets than aSheetPathToTest, -1 if this sheet path has fewer sheets than aSheetPathToTest, or 0 if same

Definition at line 167 of file sch_sheet_path.cpp.

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}
const KIID m_Uuid
Definition: eda_item.h:492
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.
size_t size() const
Forwarded method from std::vector.

References at(), EDA_ITEM::m_Uuid, and size().

Referenced by SCH_REFERENCE_LIST::sortByTimeStamp().

◆ ComparePageNum()

int SCH_SHEET_PATH::ComparePageNum ( const SCH_SHEET_PATH aSheetPathToTest) const

Compare sheets by their page number.

If the actual page number is equal, use virtual page numbers to compare.

Returns
-1 if aSheetPathToTest is greater than this (should appear later in the sort order) 0 if aSheetPathToTest is equal to this 1 if aSheetPathToTest is less than this (should appear earlier in the sort order)

Definition at line 189 of file sch_sheet_path.cpp.

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}
wxString GetPageNumber() const
int GetVirtualPageNumber() const
static int ComparePageNum(const wxString &aPageNumberA, const wxString &aPageNumberB)
Compares page numbers of schematic sheets.
Definition: sch_sheet.cpp:1338

References SCH_SHEET::ComparePageNum(), GetPageNumber(), and GetVirtualPageNumber().

Referenced by HIERARCHY_TREE::OnCompareItems(), and SCH_SHEET_LIST::SortByPageNumbers().

◆ empty()

bool SCH_SHEET_PATH::empty ( ) const
inline

Forwarded method from std::vector.

Definition at line 164 of file sch_sheet_path.h.

164{ return m_sheets.empty(); }

References m_sheets.

Referenced by SCH_SHEET::findSelf(), Last(), SCH_SEXPR_PLUGIN::loadHierarchy(), DIALOG_ERC::OnERCItemSelected(), and PathHumanReadable().

◆ erase()

std::vector< SCH_SHEET * >::iterator SCH_SHEET_PATH::erase ( std::vector< SCH_SHEET * >::const_iterator  aPosition)
inline

Definition at line 183 of file sch_sheet_path.h.

184 {
185 return m_sheets.erase( aPosition );
186 }

References m_sheets.

◆ GetCurrentHash()

size_t SCH_SHEET_PATH::GetCurrentHash ( ) const
inline

◆ GetItem()

SCH_ITEM * SCH_SHEET_PATH::GetItem ( const KIID aID) const

Fetch a SCH_ITEM by ID.

Definition at line 812 of file sch_sheet_path.cpp.

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}
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:444

References LastScreen(), EDA_ITEM::m_Uuid, and SCH_ITEM::RunOnChildren().

Referenced by SIM_PLOT_FRAME::applyTuners(), SCH_SHEET_LIST::GetItem(), and SIM_PLOT_FRAME::UpdateTunerValue().

◆ GetMultiUnitSymbols()

void SCH_SHEET_PATH::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 sheet.

The map key for each element will be the reference designator.

Parameters
aRefListMap of reference designators to reference lists
aIncludePowerSymbolsSet to false to only get normal symbols.

Definition at line 403 of file sch_sheet_path.cpp.

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}
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-...

References AppendMultiUnitSymbol(), LastScreen(), and SCH_SYMBOL_T.

Referenced by SCH_EDIT_FRAME::AnnotateSymbols().

◆ GetPageNumber()

wxString SCH_SHEET_PATH::GetPageNumber ( ) const

Definition at line 527 of file sch_sheet_path.cpp.

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}
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
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
wxString getPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1299

References SCH_SHEET::getPageNumber(), Last(), and pop_back().

Referenced by SCH_SHEET_LIST::AllSheetPageNumbersEmpty(), HIERARCHY_PANE::buildHierarchyTree(), ComparePageNum(), SCH_EDIT_TOOL::EditPageNumber(), HIERARCHY_PANE::getRootString(), HIERARCHY_PANE::onRightClick(), SCH_SHEET_LIST::PageNumberExists(), SCH_PLOTTER::plotOneSheetDXF(), SCH_PLOTTER::plotOneSheetHpgl(), SCH_PLOTTER::plotOneSheetPS(), SCH_PLOTTER::plotOneSheetSVG(), SCHEMATIC::ResolveTextVar(), and DIALOG_SHEET_PROPERTIES::TransferDataToWindow().

◆ GetSheet()

const SCH_SHEET * SCH_SHEET_PATH::GetSheet ( unsigned  aIndex) const
inline

Definition at line 214 of file sch_sheet_path.h.

215 {
216 SCH_SHEET* retv = nullptr;
217
218 if( aIndex < size() )
219 retv = at( aIndex );
220
221 return retv;
222 }

References at(), and size().

Referenced by IsFullPath(), and SCH_SHEET_LIST::TestForRecursion().

◆ GetSymbols()

void SCH_SHEET_PATH::GetSymbols ( SCH_REFERENCE_LIST aReferences,
bool  aIncludePowerSymbols = true,
bool  aForceIncludeOrphanSymbols = false 
) const

Adds SCH_REFERENCE object to aReferences for each symbol in the sheet.

Parameters
aReferencesList of references to populate.
aIncludePowerSymbolsset to false to only get normal symbols.
aForceIncludeOrphanSymbolsset to true to include symbols having no symbol found in lib. The normal option is false, and set to true only to build the full list of symbols.

Definition at line 371 of file sch_sheet_path.cpp.

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}
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.

References AppendSymbol(), LastScreen(), and SCH_SYMBOL_T.

Referenced by SCH_EDIT_FRAME::AnnotateSymbols(), SCH_EDIT_FRAME::CheckAnnotate(), CollectOtherUnits(), findSymbolsAndPins(), SCH_SHEET_LIST::GetSymbols(), SCH_SHEET_LIST::GetSymbolsWithinPath(), SCH_EDITOR_CONTROL::Paste(), sheetContainsOnlyWantedItems(), and SCH_EDITOR_CONTROL::updatePastedSheet().

◆ GetVirtualPageNumber()

◆ initFromOther()

void SCH_SHEET_PATH::initFromOther ( const SCH_SHEET_PATH aOther)
private

Definition at line 140 of file sch_sheet_path.cpp.

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}

References m_current_hash, m_sheets, and m_virtualPageNumber.

Referenced by operator=(), and SCH_SHEET_PATH().

◆ IsContainedWithin()

bool SCH_SHEET_PATH::IsContainedWithin ( const SCH_SHEET_PATH aSheetPathToTest) const

Check if this path is contained inside aSheetPathToTest.

Parameters
aSheetPathToTestis the sheet path to compare against.
Returns
true if this path is contained inside or equal to aSheetPathToTest.

Definition at line 211 of file sch_sheet_path.cpp.

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}
wxString AsString() const
Definition: kiid.cpp:359
const wxChar *const traceSchSheetPaths
Flag to enable debug output of schematic symbol sheet path manipulation code.
_OUT_STRING AsString(const std::string &aString)
Definition: sexpr.h:131

References KIID_PATH::AsString(), SEXPR::AsString(), at(), EDA_ITEM::m_Uuid, Path(), size(), and traceSchSheetPaths.

Referenced by findSymbolsAndPins(), SCH_SHEET_LIST::GetSheetsWithinPath(), SCH_SHEET_LIST::GetSymbolsWithinPath(), and sheetContainsOnlyWantedItems().

◆ IsFullPath()

bool SCH_SHEET_PATH::IsFullPath ( ) const

Definition at line 151 of file sch_sheet_path.cpp.

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}
const SCH_SHEET * GetSheet(unsigned aIndex) const
bool IsRootSheet() const
Definition: sch_sheet.cpp:194

References GetSheet(), SCH_SHEET::IsRootSheet(), and m_sheets.

Referenced by SCH_SHEET::addInstance(), SCH_SHEET::getPageNumber(), and SCH_SHEET::setPageNumber().

◆ Last()

SCH_SHEET * SCH_SHEET_PATH::Last ( ) const

Return a pointer to the last SCH_SHEET of the list.

One can see the others sheet as the "path" to reach this last sheet.

Definition at line 234 of file sch_sheet_path.cpp.

235{
236 if( !empty() )
237 return m_sheets.back();
238
239 return nullptr;
240}
bool empty() const
Forwarded method from std::vector.

References empty(), and m_sheets.

Referenced by SCH_SHEET::addInstance(), SCH_NAVIGATE_TOOL::CanGoUp(), KIGFX::SCH_VIEW::DisplaySheet(), SCH_DRAWING_TOOLS::DrawSheet(), SCH_EDIT_TOOL::EditPageNumber(), SCH_SHEET::findSelf(), SCH_SHEET::GetContextualTextVars(), SCH_EAGLE_PLUGIN::getCurrentScreen(), SCH_ALTIUM_PLUGIN::getCurrentSheet(), SCH_EAGLE_PLUGIN::getCurrentSheet(), GetPageNumber(), SCH_SHEET::getPageNumber(), NETLIST_EXPORTER_SPICE::GetSheets(), SCH_TEXT::GetShownText(), SCH_TEXTBOX::GetShownText(), EE_SELECTION_TOOL::Init(), SCH_DRAWING_TOOLS::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), LastScreen(), CADSTAR_SCH_ARCHIVE_LOADER::loadSheetAndChildSheets(), MakeFilePathRelativeToParentSheet(), NETLIST_EXPORTER_XML::makeSymbols(), SCH_SHEET_LIST::NameExists(), HIERARCHY_PANE::onRightClick(), DIALOG_SCH_FIELD_PROPERTIES::onScintillaCharAdded(), DIALOG_TEXT_PROPERTIES::onScintillaCharAdded(), SCH_ALTIUM_PLUGIN::ParseComponent(), SCH_EDITOR_CONTROL::Paste(), SCH_PLOTTER::plotOneSheetDXF(), SCH_PLOTTER::plotOneSheetHpgl(), SCH_PLOTTER::plotOneSheetPDF(), SCH_PLOTTER::plotOneSheetPS(), SCH_PLOTTER::plotOneSheetSVG(), SCH_LABEL_BASE::ResolveTextVar(), SCHEMATIC::ResolveTextVar(), SCH_SHEET::ResolveTextVar(), SCH_SYMBOL::ResolveTextVar(), SCH_EDITOR_CONTROL::Revert(), SCH_EDITOR_CONTROL::SaveCurrSheetCopyAs(), SCH_SHEET::setPageNumber(), SetPageNumber(), and HIERARCHY_PANE::UpdateHierarchySelection().

◆ LastScreen() [1/2]

SCH_SCREEN * SCH_SHEET_PATH::LastScreen ( )
Returns
the SCH_SCREEN relative to the last sheet in list.
the SCH_SCREEN relative to the last sheet in list.

Definition at line 243 of file sch_sheet_path.cpp.

244{
245 SCH_SHEET* lastSheet = Last();
246
247 if( lastSheet )
248 return lastSheet->GetScreen();
249
250 return nullptr;
251}
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:106

References SCH_SHEET::GetScreen(), and Last().

Referenced by AddNewSymbolInstances(), SCH_SHEET_LIST::AnnotatePowerSymbols(), SCH_EDIT_FRAME::AnnotateSymbols(), BACK_ANNOTATE::applyChangelist(), SCH_EDITOR_CONTROL::AssignNetclass(), HIERARCHY_PANE::buildHierarchyTree(), SCH_SHEET_LIST::BuildSheetList(), SCH_EDIT_FRAME::CheckAnnotate(), SCH_EDIT_FRAME::CheckSheetForRecursion(), SCH_SHEET_LIST::ClearModifyStatus(), SCH_EDIT_FRAME::CommonSettingsChanged(), SCH_PLOTTER::createDXFFiles(), SCH_PLOTTER::createHPGLFiles(), SCH_PLOTTER::createPDFFile(), SCH_PLOTTER::createPSFiles(), SCH_PLOTTER::createSVGFiles(), SCH_EDIT_FRAME::DeleteAnnotation(), SCH_EDIT_FRAME::DisplayCurrentSheet(), SCH_EDIT_TOOL::EditPageNumber(), CONNECTION_GRAPH::ercCheckBusToBusConflicts(), CONNECTION_GRAPH::ercCheckBusToBusEntryConflicts(), CONNECTION_GRAPH::ercCheckBusToNetConflicts(), CONNECTION_GRAPH::ercCheckFloatingWires(), CONNECTION_GRAPH::ercCheckLabels(), CONNECTION_GRAPH::ercCheckMultipleDrivers(), CONNECTION_GRAPH::ercCheckNoConnects(), SCH_SHEET_LIST::FillItemMap(), SCH_SHEET_LIST::FindAllSheetsForScreen(), findItemsFromSyncSelection(), NETLIST_EXPORTER_BASE::findNextSymbol(), SCH_SHEET_LIST::FindSheetForScreen(), SCHEMATIC::GetContextualTextVars(), SCH_ALTIUM_PLUGIN::getCurrentScreen(), GetItem(), GetMultiUnitSymbols(), SCH_EDIT_FRAME::GetScreen(), GetSymbols(), SCH_EDIT_FRAME::HardRedraw(), DIALOG_EDIT_SYMBOLS_LIBID::initDlg(), SCH_SHEET_LIST::IsModified(), SCH_SEXPR_PLUGIN::loadHierarchy(), MakeFilePathRelativeToParentSheet(), NETLIST_EXPORTER_XML::makeSymbols(), SCH_PRINTOUT::OnPrintPage(), HIERARCHY_PANE::onRightClick(), DIALOG_ERC::OnRunERCClick(), DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged(), SCH_EDITOR_CONTROL::Paste(), SCH_DRAWING_TOOLS::PlaceSymbol(), DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS::processItem(), BACK_ANNOTATE::processNetNameChange(), SCHEMATIC::RecomputeIntersheetRefs(), RemoveSymbolInstances(), SCH_EDITOR_CONTROL::RepairSchematic(), SCH_FIND_REPLACE_TOOL::ReplaceAndFindNext(), RESCUER::RESCUER(), SCH_EDIT_FRAME::ResolveERCExclusions(), SCH_EDIT_FRAME::SetCurrentSheet(), SCHEMATIC::SetSheetNumberAndCount(), TestForRecursion(), ERC_TESTER::TestMissingUnits(), ERC_TESTER::TestMultiunitFootprints(), ERC_TESTER::TestMultUnitPinConflicts(), ERC_TESTER::TestPinToPin(), ERC_TESTER::TestSimilarLabels(), DIALOG_SHEET_PROPERTIES::TransferDataFromWindow(), SCH_LINE_WIRE_BUS_TOOL::TrimOverLappingWires(), UpdateAllScreenReferences(), CONNECTION_GRAPH::updateItemConnectivity(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), SCH_SHEET_LIST::UpdateSymbolInstanceData(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

◆ LastScreen() [2/2]

SCH_SCREEN * SCH_SHEET_PATH::LastScreen ( ) const

Definition at line 254 of file sch_sheet_path.cpp.

255{
256 SCH_SHEET* lastSheet = Last();
257
258 if( lastSheet )
259 return lastSheet->GetScreen();
260
261 return nullptr;
262}

References SCH_SHEET::GetScreen(), and Last().

◆ MakeFilePathRelativeToParentSheet()

void SCH_SHEET_PATH::MakeFilePathRelativeToParentSheet ( )

Make the sheet file name relative to its parent sheet.

This should only be called when changing the parent sheet path such performing a save as or a new schematic without a project in stand alone mode. The sheet file name is only made relative if the current file name is relative. Absolute sheet file name paths are a user choice so do not change them.

Sheet file name paths are set according to the following criteria:

  • If the sheet file name path is in the same as the parent sheet file name path, set the sheet file name to just the file name and extension with no path.
  • If the sheet file name path can be made relative to the parent sheet file name path, set the sheet file name using the relative path.
  • If the sheet file name path cannot be converted to a relative path, then fall back to the absolute file name path.

Definition at line 616 of file sch_sheet_path.cpp.

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}
const wxString & GetFileName() const
Definition: sch_screen.h:144
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false) const
Return the sheet path in a human readable form made from the sheet names.
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
const wxChar *const tracePathsAndFiles
Flag to enable path and file name debug output.

References SCH_SCREEN::GetFileName(), SCH_SHEET::GetFileName(), Last(), LastScreen(), m_sheets, PathHumanReadable(), SCH_SHEET::SetFileName(), and tracePathsAndFiles.

◆ operator!=()

bool SCH_SHEET_PATH::operator!= ( const SCH_SHEET_PATH d1) const
inline

Definition at line 405 of file sch_sheet_path.h.

405{ return !( *this == d1 ) ; }

◆ operator+()

SCH_SHEET_PATH SCH_SHEET_PATH::operator+ ( const SCH_SHEET_PATH aOther)

Definition at line 127 of file sch_sheet_path.cpp.

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}
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.

References at(), push_back(), and size().

◆ operator<()

bool SCH_SHEET_PATH::operator< ( const SCH_SHEET_PATH d1) const
inline

Definition at line 407 of file sch_sheet_path.h.

407{ return m_sheets < d1.m_sheets; }

References m_sheets.

◆ operator=()

SCH_SHEET_PATH & SCH_SHEET_PATH::operator= ( const SCH_SHEET_PATH aOther)

Definition at line 120 of file sch_sheet_path.cpp.

121{
122 initFromOther( aOther );
123 return *this;
124}

References initFromOther().

◆ operator==()

bool SCH_SHEET_PATH::operator== ( const SCH_SHEET_PATH d1) const

Definition at line 440 of file sch_sheet_path.cpp.

441{
442 return m_current_hash == d1.GetCurrentHash();
443}
size_t GetCurrentHash() const

References GetCurrentHash(), and m_current_hash.

◆ Path()

◆ PathAsString()

wxString SCH_SHEET_PATH::PathAsString ( ) const

Return the path of time stamps which do not changes even when editing sheet parameters.

A path is something like / (root) or /34005677 or /34005677/00AE4523.

Definition at line 265 of file sch_sheet_path.cpp.

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}
wxString AsString() const
Definition: kiid.cpp:257

References KIID::AsString(), at(), EDA_ITEM::m_Uuid, and size().

Referenced by SCH_REFERENCE::GetFullPath(), SCH_REFERENCE::GetPath(), NETLIST_EXPORTER_XML::makeSymbols(), SCH_EDIT_FRAME::SendSelectItemsToPcb(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

◆ PathHumanReadable()

wxString SCH_SHEET_PATH::PathHumanReadable ( bool  aUseShortRootName = true,
bool  aStripTrailingSeparator = false 
) const

Return the sheet path in a human readable form made from the sheet names.

The "normal" path instead uses the KIID objects in the path that do not change even when editing sheet parameters.

Definition at line 291 of file sch_sheet_path.cpp.

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}
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:93
@ SHEETNAME
Definition: sch_sheet.h:45

References at(), empty(), SCH_SHEET::GetFields(), SCH_SCREEN::GetFileName(), SCH_SHEET::GetScreen(), SHEETNAME, and size().

Referenced by KIGFX::SCH_VIEW::DisplaySheet(), SCH_EDIT_TOOL::EditPageNumber(), CONNECTION_GRAPH::ercCheckBusToBusEntryConflicts(), SCH_EDIT_FRAME::GetScreenDesc(), MakeFilePathRelativeToParentSheet(), NETLIST_EXPORTER_XML::makeSymbols(), HIERARCHY_PANE::onRightClick(), DIALOG_SHEET_PROPERTIES::OnUpdateUI(), SCH_PLOTTER::plotOneSheetDXF(), SCH_PLOTTER::plotOneSheetHpgl(), SCH_PLOTTER::plotOneSheetPDF(), SCH_PLOTTER::plotOneSheetPS(), SCH_PLOTTER::plotOneSheetSVG(), SCH_CONNECTION::recacheName(), SCHEMATIC::ResolveTextVar(), SCH_SHEET::ResolveTextVar(), and SCH_EDIT_FRAME::updateTitle().

◆ pop_back()

◆ push_back()

◆ Rehash()

void SCH_SHEET_PATH::Rehash ( )

Definition at line 158 of file sch_sheet_path.cpp.

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}
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

References hash_combine(), m_current_hash, and m_sheets.

Referenced by clear(), pop_back(), and push_back().

◆ RemoveSymbolInstances()

void SCH_SHEET_PATH::RemoveSymbolInstances ( const SCH_SHEET_PATH aPrefixSheetPath)

Definition at line 598 of file sch_sheet_path.cpp.

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}
void RemoveInstance(const SCH_SHEET_PATH &aInstancePath)
Definition: sch_symbol.cpp:521

References LastScreen(), SCH_SYMBOL::RemoveInstance(), and SCH_SYMBOL_T.

Referenced by SCH_SHEET_LIST::RemoveSymbolInstances().

◆ SetPageNumber()

void SCH_SHEET_PATH::SetPageNumber ( const wxString &  aPageNumber)

Set the sheet instance user definable page number.

Note
User definable page numbers can be any string devoid of white space characters.

Definition at line 541 of file sch_sheet_path.cpp.

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}
void setPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1320
bool addInstance(const SCH_SHEET_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1221

References SCH_SHEET::addInstance(), Last(), pop_back(), and SCH_SHEET::setPageNumber().

Referenced by SCH_SHEET_LIST::AddNewSheetInstances(), SCH_EDIT_FRAME::CreateScreens(), SCH_EDIT_TOOL::EditPageNumber(), SCH_ALTIUM_PLUGIN::Load(), SCH_EAGLE_PLUGIN::loadSchematic(), CADSTAR_SCH_ARCHIVE_LOADER::loadSheetAndChildSheets(), CADSTAR_SCH_ARCHIVE_LOADER::loadSheets(), HIERARCHY_PANE::onRightClick(), SCH_ALTIUM_PLUGIN::ParseHarnessConnector(), SCH_ALTIUM_PLUGIN::ParseParameter(), SCH_SEXPR_PARSER::parseSchSheetInstances(), SCH_ALTIUM_PLUGIN::ParseSheetSymbol(), SCH_SHEET_LIST::SetInitialPageNumbers(), DIALOG_SHEET_PROPERTIES::TransferDataFromWindow(), and DIALOG_SHEET_PROPERTIES::TransferDataToWindow().

◆ SetVirtualPageNumber()

void SCH_SHEET_PATH::SetVirtualPageNumber ( int  aPageNumber)
inline

Set the sheet instance virtual page number.

Virtual page numbers are incremental integers set automatically when the sheet path hierarchy is created (

See also
SCH_SHEET_LIST::BuildSheetList). The virtual page numbering is ordered by the X and Y position of the sheet in a schematic which mimics the page numbering code prior to the addition of actual user definable page numbers. Virtual page numbers should only be use when annotating schematics.

Definition at line 201 of file sch_sheet_path.h.

201{ m_virtualPageNumber = aPageNumber; }

References m_virtualPageNumber.

Referenced by SCH_SHEET_LIST::AddNewSheetInstances(), SCH_SHEET_LIST::BuildSheetList(), SCHEMATIC::SetSheetNumberAndCount(), and SCH_SHEET_LIST::SortByPageNumbers().

◆ size()

◆ TestForRecursion()

bool SCH_SHEET_PATH::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 sheet stored in file aDestFileName will cause a sheet path recursion.

Parameters
aSrcFileNameis the source file name of the sheet add to aDestFileName.
aDestFileNameis the file name of the destination sheet for aSrcFileName.
Returns
true if aFileName will cause recursion in the sheet path. Otherwise false.
Todo:
Store sheet file names with full path, either relative to project path or absolute path. The current design always assumes subsheet files are located in the project folder which may or may not be desirable.

Definition at line 446 of file sch_sheet_path.cpp.

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}
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:197
SCHEMATIC * Schematic() const
Definition: sch_screen.cpp:92
std::map< std::pair< wxString, wxString >, bool > m_recursion_test_cache
Page numbers are maintained by the sheet load order.

References at(), SCH_SHEET::GetFileName(), SCHEMATIC::GetFileName(), LastScreen(), m_recursion_test_cache, SCH_SCREEN::Schematic(), and size().

Referenced by SCH_SHEET_LIST::BuildSheetList().

◆ UpdateAllScreenReferences()

void SCH_SHEET_PATH::UpdateAllScreenReferences ( ) const

Update all the symbol references for this sheet path.

Mandatory in complex hierarchies because sheets may use the same screen (basic schematic) more than once but with different references and units according to the displayed sheet.

Definition at line 323 of file sch_sheet_path.cpp.

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}
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
virtual bool IsVisible() const
Definition: eda_text.h:136
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:217
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:163
SCHEMATIC_SETTINGS & Settings() const
Definition: schematic.cpp:203
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:1061
const wxString & GetInternalName()
Get the initial name of the field set at creation (or set by SetName()).
Definition: sch_field.h:123
SCHEMATIC * Schematic() const
Searches the item hierarchy to find a SCHEMATIC.
Definition: sch_item.cpp:112
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual) override
Definition: sch_label.cpp:376
std::vector< SCH_FIELD > & GetFields()
Definition: sch_label.h:90
void Update(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Update aItem's bounding box in the tree.
Definition: sch_screen.cpp:300
void UpdateUnit(int aUnit)
Change the unit number to aUnit without setting any internal flags.
Definition: sch_symbol.cpp:394
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
Return the instance-specific unit selection for the given sheet path.
Definition: sch_symbol.cpp:771
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:152
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References SCH_LABEL_BASE::AutoplaceFields(), SCH_SYMBOL::GetField(), SCH_LABEL_BASE::GetFields(), SCH_FIELD::GetInternalName(), SCH_FIELD::GetPosition(), SCH_SYMBOL::GetRef(), SCH_SYMBOL::GetUnitSelection(), EDA_TEXT::IsVisible(), LastScreen(), SCHEMATIC_SETTINGS::m_IntersheetRefsShow, REFERENCE_FIELD, SCH_GLOBAL_LABEL_T, SCH_SYMBOL_T, SCH_ITEM::Schematic(), EDA_TEXT::SetText(), SCHEMATIC::Settings(), EDA_TEXT::SetVisible(), EDA_ITEM::Type(), SCH_SCREEN::Update(), and SCH_SYMBOL::UpdateUnit().

Referenced by SCH_EDIT_FRAME::AnnotateSymbols(), SCH_PLOTTER::createDXFFiles(), SCH_PLOTTER::createHPGLFiles(), SCH_PLOTTER::createPDFFile(), SCH_PLOTTER::createPSFiles(), SCH_PLOTTER::createSVGFiles(), SCH_EDIT_FRAME::DeleteAnnotation(), SCH_EDIT_FRAME::DisplayCurrentSheet(), ERC_TREE_MODEL::GetValue(), DIALOG_MIGRATE_BUSES::onItemSelected(), SCH_PRINTOUT::OnPrintPage(), DIALOG_UPDATE_FROM_PCB::OnUpdateClick(), SCH_EDIT_FRAME::OpenProjectFiles(), SCH_EDITOR_CONTROL::Paste(), SCH_DRAWING_TOOLS::PlaceSymbol(), DIALOG_CHANGE_SYMBOLS::processMatchingSymbols(), SCH_FIND_REPLACE_TOOL::ReplaceAll(), SCH_FIND_REPLACE_TOOL::ReplaceAndFindNext(), and SCH_PLOTTER::restoreEnvironment().

Member Data Documentation

◆ m_current_hash

size_t SCH_SHEET_PATH::m_current_hash
protected

Definition at line 415 of file sch_sheet_path.h.

Referenced by GetCurrentHash(), initFromOther(), operator==(), Rehash(), and SCH_SHEET_PATH().

◆ m_recursion_test_cache

std::map<std::pair<wxString, wxString>, bool> SCH_SHEET_PATH::m_recursion_test_cache
protected

Page numbers are maintained by the sheet load order.

Definition at line 419 of file sch_sheet_path.h.

Referenced by TestForRecursion().

◆ m_sheets

std::vector< SCH_SHEET* > SCH_SHEET_PATH::m_sheets
protected

◆ m_virtualPageNumber

int SCH_SHEET_PATH::m_virtualPageNumber
protected

The documentation for this class was generated from the following files: