KiCad PCB EDA Suite
SCH_SHEET_LIST Class Reference

A container for handling SCH_SHEET_PATH objects in a flattened hierarchy. More...

#include <sch_sheet_path.h>

Inheritance diagram for SCH_SHEET_LIST:

Public Member Functions

 SCH_SHEET_LIST (SCH_SHEET *aSheet=nullptr, bool aCheckIntegrity=false)
 Construct a flattened list of SCH_SHEET_PATH objects from aSheet. More...
 
 ~SCH_SHEET_LIST ()
 
bool IsModified () const
 Check the entire hierarchy for any modifications. More...
 
void ClearModifyStatus ()
 
SCH_ITEMGetItem (const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr) const
 Fetch a SCH_ITEM by ID. More...
 
void FillItemMap (std::map< KIID, EDA_ITEM * > &aMap)
 Fill an item cache for temporary use when many items need to be fetched. More...
 
void AnnotatePowerSymbols ()
 Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list. More...
 
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. More...
 
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 within aSheetPath as well as recursively downwards inside aSheetPath. More...
 
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 aSheetPath as well as recursively downwards inside aSheetPath. 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 list of sheets. More...
 
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 aSrcSheetHierarchy to the sheet stored in aDestFileName will cause recursion. More...
 
SCH_SHEET_PATHFindSheetForScreen (const SCH_SCREEN *aScreen)
 Return a pointer to the first SCH_SHEET_PATH object (not necessarily the only one) using a particular screen. More...
 
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. More...
 
void BuildSheetList (SCH_SHEET *aSheet, bool aCheckIntegrity)
 Build the list of sheets and their sheet path from aSheet. More...
 
void SortByPageNumbers (bool aUpdateVirtualPageNums=true)
 Sort the list of sheets by page number. More...
 
bool NameExists (const wxString &aSheetName) const
 
bool PageNumberExists (const wxString &aPageNumber) const
 
void UpdateSymbolInstances (const std::vector< SYMBOL_INSTANCE_REFERENCE > &aSymbolInstances)
 Update all of the symbol instance information using aSymbolInstances. More...
 
void UpdateSheetInstances (const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
 Update all of the sheet instance information using aSheetInstances. More...
 
std::vector< KIID_PATHGetPaths () const
 
std::vector< SCH_SHEET_INSTANCEGetSheetInstances () const
 Fetch the instance information for all of the sheets in the hiearchy. More...
 
bool AllSheetPageNumbersEmpty () const
 Check all of the sheet instance for empty page numbers. More...
 
void SetInitialPageNumbers ()
 Set initial sheet page numbers. More...
 

Private Attributes

SCH_SHEET_PATH m_currentSheetPath
 

Detailed Description

A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.

SCH_SHEET objects are not unique, there can be many sheets with the same filename and that share the same SCH_SCREEN reference. Each The schematic file (SCH_SCREEN) may be shared between these sheets and symbol references are specific to a sheet path. When a sheet is entered, symbol references and sheet page number are updated.

Definition at line 409 of file sch_sheet_path.h.

Constructor & Destructor Documentation

◆ SCH_SHEET_LIST()

SCH_SHEET_LIST::SCH_SHEET_LIST ( SCH_SHEET aSheet = nullptr,
bool  aCheckIntegrity = false 
)

Construct a flattened list of SCH_SHEET_PATH objects from aSheet.

If aSheet == NULL, then this is an empty hierarchy which the user can populate.

Definition at line 527 of file sch_sheet_path.cpp.

528 {
529  if( aSheet != nullptr )
530  {
531  BuildSheetList( aSheet, aCheckIntegrity );
532 
533  if( aSheet->IsRootSheet() )
535  }
536 }
bool IsRootSheet() const
Definition: sch_sheet.cpp:204
void BuildSheetList(SCH_SHEET *aSheet, bool aCheckIntegrity)
Build the list of sheets and their sheet path from aSheet.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.

References BuildSheetList(), SCH_SHEET::IsRootSheet(), and SortByPageNumbers().

◆ ~SCH_SHEET_LIST()

SCH_SHEET_LIST::~SCH_SHEET_LIST ( )
inline

Definition at line 419 of file sch_sheet_path.h.

419 {}

Member Function Documentation

◆ AllSheetPageNumbersEmpty()

bool SCH_SHEET_LIST::AllSheetPageNumbersEmpty ( ) const

Check all of the sheet instance for empty page numbers.

Note
This should only return true when loading a legacy schematic or an s-expression schematic before version 20201005.
Returns
true if all sheet instance page numbers are not defined. Otherwise false.

Definition at line 1015 of file sch_sheet_path.cpp.

1016 {
1017  for( const SCH_SHEET_PATH& instance : *this )
1018  {
1019  const SCH_SHEET* sheet = instance.Last();
1020 
1021  wxCHECK2( sheet, continue );
1022 
1023  if( !sheet->GetPageNumber( instance ).IsEmpty() )
1024  return false;
1025  }
1026 
1027  return true;
1028 }
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1163

References SCH_SHEET::GetPageNumber(), and SCH_SHEET_PATH::Last().

Referenced by BOOST_AUTO_TEST_CASE(), SCH_EDIT_FRAME::OpenProjectFiles(), and SetInitialPageNumbers().

◆ AnnotatePowerSymbols()

void SCH_SHEET_LIST::AnnotatePowerSymbols ( )

Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.

It is called before creating a netlist, to annotate power symbols, without prompting the user about not annotated or duplicate for these symbols, if only these symbols need annotation ( a very frequent case ).

Definition at line 712 of file sch_sheet_path.cpp.

713 {
714  // List of reference for power symbols
715  SCH_REFERENCE_LIST references;
716  SCH_REFERENCE_LIST additionalreferences; // Todo: add as a parameter to this function
717 
718  // Map of locked symbols (not used, but needed by Annotate()
719  SCH_MULTI_UNIT_REFERENCE_MAP lockedSymbols;
720 
721  // Build the list of power symbols:
722  for( SCH_SHEET_PATH& sheet : *this )
723  {
724  for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
725  {
726  SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
727  LIB_SYMBOL* libSymbol = symbol->GetLibSymbolRef().get();
728 
729  if( libSymbol && libSymbol->IsPower() )
730  {
731  SCH_REFERENCE schReference( symbol, libSymbol, sheet );
732  references.AddItem( schReference );
733  }
734  }
735  }
736 
737  // Find duplicate, and silently clear annotation of duplicate
738  std::map<wxString, int> ref_list; // stores the existing references
739 
740  for( unsigned ii = 0; ii< references.GetCount(); ++ii )
741  {
742  wxString curr_ref = references[ii].GetRef();
743 
744  if( ref_list.find( curr_ref ) == ref_list.end() )
745  {
746  ref_list[curr_ref] = ii;
747  continue;
748  }
749 
750  // Possible duplicate, if the ref ends by a number:
751  if( curr_ref.Last() < '0' && curr_ref.Last() > '9' )
752  continue; // not annotated
753 
754  // Duplicate: clear annotation by removing the number ending the ref
755  while( curr_ref.Last() >= '0' && curr_ref.Last() <= '9' )
756  curr_ref.RemoveLast();
757 
758  references[ii].SetRef( curr_ref );
759  }
760 
761  // Break full symbol reference into name (prefix) and number:
762  // example: IC1 become IC, and 1
763  references.SplitReferences();
764 
765  // Ensure all power symbols have the reference starting by '#'
766  // (Not sure this is really useful)
767  for( unsigned ii = 0; ii< references.GetCount(); ++ii )
768  {
769  if( references[ii].GetRef()[0] != '#' )
770  {
771  wxString new_ref = "#" + references[ii].GetRef();
772  references[ii].SetRef( new_ref );
773  }
774  }
775 
776  // Recalculate and update reference numbers in schematic
777  references.Annotate( false, 0, 100, lockedSymbols, additionalreferences );
778  references.UpdateAnnotation();
779 }
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:230
bool IsPower() const
Definition: lib_symbol.cpp:444
void AddItem(const SCH_REFERENCE &aItem)
Define a library symbol object.
Definition: lib_symbol.h:96
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:164
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void UpdateAnnotation()
Update the symbol references for the schematic project (or the current sheet).
size_t GetCount() const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.
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.
Schematic symbol object.
Definition: sch_symbol.h:78
SCH_SCREEN * LastScreen()
void SplitReferences()
Attempt to split all reference designators into a name (U) and number (1).
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:110
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
A helper to define a symbol's reference designator in a schematic.

References SCH_REFERENCE_LIST::AddItem(), SCH_REFERENCE_LIST::Annotate(), SCH_REFERENCE_LIST::GetCount(), SCH_SYMBOL::GetLibSymbolRef(), LIB_SYMBOL::IsPower(), SCH_SCREEN::Items(), SCH_SHEET_PATH::LastScreen(), EE_RTREE::OfType(), SCH_SYMBOL_T, SCH_REFERENCE_LIST::SplitReferences(), and SCH_REFERENCE_LIST::UpdateAnnotation().

Referenced by TEST_SCH_SHEET_LIST_FIXTURE::loadSchematic(), TEST_NETLISTS_FIXTURE::loadSchematic(), DIALOG_ERC::OnRunERCClick(), SCH::readSchematicFromFile(), ReadSchematicFromFile(), SCH_EDIT_FRAME::ReadyToNetlist(), DIALOG_ERC::testErc(), and SCH_EDIT_FRAME::WriteNetListFile().

◆ BuildSheetList()

void SCH_SHEET_LIST::BuildSheetList ( SCH_SHEET aSheet,
bool  aCheckIntegrity 
)

Build the list of sheets and their sheet path from aSheet.

If aSheet is the root sheet, the full sheet path and sheet list are built.

The list will be ordered as per SCH_SCREEN::GetSheets which results in sheets being ordered in the legacy way of using the X and Y positions of the sheets.

See also
SortByPageNumbers to sort by page numbers
Parameters
aSheetis the starting sheet from which the list is built, or NULL indicating that g_RootSheet should be used.
Exceptions
std::bad_allocif the memory for the sheet path list could not be allocated.

Definition at line 539 of file sch_sheet_path.cpp.

540 {
541  wxCHECK_RET( aSheet != nullptr, wxT( "Cannot build sheet list from undefined sheet." ) );
542 
543  std::vector<SCH_SHEET*> badSheets;
544 
545  m_currentSheetPath.push_back( aSheet );
546  m_currentSheetPath.SetVirtualPageNumber( static_cast<int>( size() ) + 1 );
547  push_back( m_currentSheetPath );
548 
550  {
551  wxString parentFileName = aSheet->GetFileName();
552  std::vector<SCH_ITEM*> childSheets;
553  m_currentSheetPath.LastScreen()->GetSheets( &childSheets );
554 
555  for( SCH_ITEM* item : childSheets )
556  {
557  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
558 
559  if( aCheckIntegrity )
560  {
561  if( !m_currentSheetPath.TestForRecursion( sheet->GetFileName(), parentFileName ) )
562  BuildSheetList( sheet, true );
563  else
564  badSheets.push_back( sheet );
565  }
566  else
567  {
568  BuildSheetList( sheet, false );
569  }
570  }
571  }
572 
573  if( aCheckIntegrity )
574  {
575  for( SCH_SHEET* sheet : badSheets )
576  {
579  }
580  }
581 
583 }
bool Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:273
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,...
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
void pop_back()
Forwarded method from std::vector.
SCH_SHEET_PATH m_currentSheetPath
void SetVirtualPageNumber(int aPageNumber)
Set the sheet instance virtual page number.
void BuildSheetList(SCH_SHEET *aSheet, bool aCheckIntegrity)
Build the list of sheets and their sheet path from aSheet.
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:317
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
SCH_SCREEN * LastScreen()
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182
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...

References SCH_SHEET::GetFileName(), SCH_SCREEN::GetSheets(), SCH_SHEET_PATH::LastScreen(), m_currentSheetPath, SCH_SHEET_PATH::pop_back(), SCH_SHEET_PATH::push_back(), SCH_SCREEN::Remove(), BASE_SCREEN::SetContentModified(), SCH_SHEET_PATH::SetVirtualPageNumber(), and SCH_SHEET_PATH::TestForRecursion().

Referenced by DIALOG_PLOT_SCHEMATIC::createDXFFiles(), DIALOG_PLOT_SCHEMATIC::createHPGLFiles(), DIALOG_PLOT_SCHEMATIC::createPDFFile(), DIALOG_PLOT_SCHEMATIC::createPSFiles(), DIALOG_PLOT_SCHEMATIC::createSVGFiles(), SCHEMATIC::GetFullHierarchy(), and SCH_SHEET_LIST().

◆ ClearModifyStatus()

void SCH_SHEET_LIST::ClearModifyStatus ( )

Definition at line 642 of file sch_sheet_path.cpp.

643 {
644  for( const SCH_SHEET_PATH& sheet : *this )
645  {
646  if( sheet.LastScreen() )
647  sheet.LastScreen()->SetContentModified( false );
648  }
649 }
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void SetContentModified(bool aModified=true)
Definition: base_screen.h:59
SCH_SCREEN * LastScreen()

References SCH_SHEET_PATH::LastScreen(), and BASE_SCREEN::SetContentModified().

Referenced by SCH_EDIT_FRAME::doCloseWindow().

◆ FillItemMap()

void SCH_SHEET_LIST::FillItemMap ( std::map< KIID, EDA_ITEM * > &  aMap)

Fill an item cache for temporary use when many items need to be fetched.

Definition at line 692 of file sch_sheet_path.cpp.

693 {
694  for( const SCH_SHEET_PATH& sheet : *this )
695  {
696  SCH_SCREEN* screen = sheet.LastScreen();
697 
698  for( SCH_ITEM* aItem : screen->Items() )
699  {
700  aMap[ aItem->m_Uuid ] = aItem;
701 
702  aItem->RunOnChildren(
703  [&]( SCH_ITEM* aChild )
704  {
705  aMap[ aChild->m_Uuid ] = aChild;
706  } );
707  }
708  }
709 }
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
const KIID m_Uuid
Definition: eda_item.h:474
SCH_SCREEN * LastScreen()
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:110
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182

References SCH_SCREEN::Items(), SCH_SHEET_PATH::LastScreen(), and EDA_ITEM::m_Uuid.

Referenced by DIALOG_ERC::writeReport().

◆ FindAllSheetsForScreen()

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

Definition at line 886 of file sch_sheet_path.cpp.

887 {
888  SCH_SHEET_LIST retval;
889 
890  for( const SCH_SHEET_PATH& sheetpath : *this )
891  {
892  if( sheetpath.LastScreen() == aScreen )
893  retval.push_back( sheetpath );
894  }
895 
896  return retval;
897 }
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()

References SCH_SHEET_PATH::LastScreen().

Referenced by SCH_DRAWING_TOOLS::DrawSheet(), SCH_EDITOR_CONTROL::Paste(), and SCH_EDITOR_CONTROL::ReplaceAll().

◆ FindSheetForScreen()

SCH_SHEET_PATH * SCH_SHEET_LIST::FindSheetForScreen ( const SCH_SCREEN aScreen)

Return a pointer to the first SCH_SHEET_PATH object (not necessarily the only one) using a particular screen.

Definition at line 874 of file sch_sheet_path.cpp.

875 {
876  for( SCH_SHEET_PATH& sheetpath : *this )
877  {
878  if( sheetpath.LastScreen() == aScreen )
879  return &sheetpath;
880  }
881 
882  return nullptr;
883 }
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()

References SCH_SHEET_PATH::LastScreen().

Referenced by SCH_EDIT_FRAME::PutDataInPreviousState().

◆ GetItem()

SCH_ITEM * SCH_SHEET_LIST::GetItem ( const KIID aID,
SCH_SHEET_PATH aPathOut = nullptr 
) const

Fetch a SCH_ITEM by ID.

Also returns the sheet the item was found on in aPathOut.

Definition at line 652 of file sch_sheet_path.cpp.

653 {
654  for( const SCH_SHEET_PATH& sheet : *this )
655  {
656  SCH_SCREEN* screen = sheet.LastScreen();
657 
658  for( SCH_ITEM* aItem : screen->Items() )
659  {
660  if( aItem->m_Uuid == aID )
661  {
662  if( aPathOut )
663  *aPathOut = sheet;
664 
665  return aItem;
666  }
667 
668  SCH_ITEM* childMatch = nullptr;
669 
670  aItem->RunOnChildren(
671  [&]( SCH_ITEM* aChild )
672  {
673  if( aChild->m_Uuid == aID )
674  childMatch = aChild;
675  } );
676 
677  if( childMatch )
678  {
679  if( aPathOut )
680  *aPathOut = sheet;
681 
682  return childMatch;
683  }
684  }
685  }
686 
687  // Not found; weak reference has been deleted.
689 }
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:444
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
const KIID m_Uuid
Definition: eda_item.h:474
SCH_SCREEN * LastScreen()
static DELETED_SHEET_ITEM * GetInstance()
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:110
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:182

References DELETED_SHEET_ITEM::GetInstance(), SCH_SCREEN::Items(), SCH_SHEET_PATH::LastScreen(), EDA_ITEM::m_Uuid, and SCH_ITEM::RunOnChildren().

Referenced by SCHEMATIC::ConvertKIIDsToRefs(), SCH_EDIT_FRAME::FocusOnItem(), SCH_EDIT_FRAME::GetItem(), DIALOG_ERC::OnERCItemSelected(), SCHEMATIC::ResolveCrossReference(), SCH_EDIT_FRAME::ResolveERCExclusions(), and SCH_EDIT_FRAME::SaveSymbolToSchematic().

◆ GetMultiUnitSymbols()

void SCH_SHEET_LIST::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 list of sheets.

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 814 of file sch_sheet_path.cpp.

816 {
817  for( SCH_SHEET_PATHS::const_iterator it = begin(); it != end(); ++it )
818  {
820  ( *it ).GetMultiUnitSymbols( tempMap );
821 
822  for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : tempMap )
823  {
824  // Merge this list into the main one
825  unsigned n_refs = pair.second.GetCount();
826 
827  for( unsigned thisRef = 0; thisRef < n_refs; ++thisRef )
828  aRefList[pair.first].AddItem( pair.second[thisRef] );
829  }
830  }
831 }
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.

Referenced by SCH_EDIT_FRAME::AnnotateSymbols(), BACK_ANNOTATE::BackAnnotateSymbols(), and ERC_TESTER::TestMultiunitFootprints().

◆ GetPaths()

std::vector< KIID_PATH > SCH_SHEET_LIST::GetPaths ( ) const

Definition at line 983 of file sch_sheet_path.cpp.

984 {
985  std::vector<KIID_PATH> paths;
986 
987  for( const SCH_SHEET_PATH& sheetPath : *this )
988  paths.emplace_back( sheetPath.Path() );
989 
990  return paths;
991 }
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...

References SCH_SHEET_PATH::Path().

◆ GetSheetInstances()

std::vector< SCH_SHEET_INSTANCE > SCH_SHEET_LIST::GetSheetInstances ( ) const

Fetch the instance information for all of the sheets in the hiearchy.

Returns
all of the sheet instance data for the hierarchy.

Definition at line 994 of file sch_sheet_path.cpp.

995 {
996  std::vector<SCH_SHEET_INSTANCE> retval;
997 
998  for( const SCH_SHEET_PATH& path : *this )
999  {
1000  const SCH_SHEET* sheet = path.Last();
1001 
1002  wxCHECK2( sheet, continue );
1003 
1004  SCH_SHEET_INSTANCE instance;
1005  instance.m_Path = path.PathWithoutRootUuid();
1006  instance.m_PageNumber = sheet->GetPageNumber( path );
1007 
1008  retval.push_back( instance );
1009  }
1010 
1011  return retval;
1012 }
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
A simple container for sheet instance information.
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1163

References SCH_SHEET::GetPageNumber(), SCH_SHEET_INSTANCE::m_PageNumber, SCH_SHEET_INSTANCE::m_Path, and path.

Referenced by SCH_SEXPR_PLUGIN::Format(), and DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged().

◆ GetSheetsWithinPath()

void SCH_SHEET_LIST::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 aSheetPath as well as recursively downwards inside aSheetPath.

Parameters
aReferencesList of sheets to populate.
aSheetPathPath to return sheets from

Definition at line 803 of file sch_sheet_path.cpp.

805 {
806  for( const SCH_SHEET_PATH& sheet : *this )
807  {
808  if( sheet.IsContainedWithin( aSheetPath ) )
809  aSheets.push_back( sheet );
810  }
811 }
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...

References SCH_SHEET_PATH::IsContainedWithin().

Referenced by SCH_SEXPR_PLUGIN::Format().

◆ GetSymbols()

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

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 782 of file sch_sheet_path.cpp.

784 {
785  for( const SCH_SHEET_PATH& sheet : *this )
786  sheet.GetSymbols( aReferences, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
787 }
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
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.

References SCH_SHEET_PATH::GetSymbols().

Referenced by SCH_EDIT_FRAME::AnnotateSymbols(), SCH_EDITOR_CONTROL::AssignFootprints(), BACK_ANNOTATE::BackAnnotateSymbols(), SCH_EDIT_FRAME::CheckAnnotate(), SCHEMATIC::ConvertRefsToKIIDs(), DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE(), DIALOG_EDIT_SYMBOLS_LIBID::initDlg(), SCH_EDIT_FRAME::mapExistingAnnotation(), DIALOG_TEXT_AND_LABEL_PROPERTIES::onScintillaCharAdded(), DIALOG_SCH_FIELD_PROPERTIES::onScintillaCharAdded(), SCH_EDITOR_CONTROL::processCmpToFootprintLinkFile(), and UpdateSymbolInstances().

◆ GetSymbolsWithinPath()

void SCH_SHEET_LIST::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 within aSheetPath as well as recursively downwards inside aSheetPath.

Parameters
aReferencesList of references to populate.
aSheetPathPath to return symbols from
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 790 of file sch_sheet_path.cpp.

794 {
795  for( const SCH_SHEET_PATH& sheet : *this )
796  {
797  if( sheet.IsContainedWithin( aSheetPath ) )
798  sheet.GetSymbols( aReferences, aIncludePowerSymbols, aForceIncludeOrphanSymbols );
799  }
800 }
bool IsContainedWithin(const SCH_SHEET_PATH &aSheetPathToTest) const
Check if this path is contained inside aSheetPathToTest.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
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.

References SCH_SHEET_PATH::GetSymbols(), and SCH_SHEET_PATH::IsContainedWithin().

Referenced by SCH_SEXPR_PLUGIN::Format().

◆ IsModified()

bool SCH_SHEET_LIST::IsModified ( ) const

Check the entire hierarchy for any modifications.

Returns
True if the hierarchy is modified otherwise false.

Definition at line 630 of file sch_sheet_path.cpp.

631 {
632  for( const SCH_SHEET_PATH& sheet : *this )
633  {
634  if( sheet.LastScreen() && sheet.LastScreen()->IsContentModified() )
635  return true;
636  }
637 
638  return false;
639 }
bool IsContentModified() const
Definition: base_screen.h:60
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()

References BASE_SCREEN::IsContentModified(), and SCH_SHEET_PATH::LastScreen().

Referenced by SCH_EDIT_FRAME::canCloseWindow(), SCH_EDIT_FRAME::IsContentModified(), and SCH_EDIT_FRAME::OpenProjectFiles().

◆ NameExists()

bool SCH_SHEET_LIST::NameExists ( const wxString &  aSheetName) const

Definition at line 606 of file sch_sheet_path.cpp.

607 {
608  for( const SCH_SHEET_PATH& sheet : *this )
609  {
610  if( sheet.Last()->GetName() == aSheetName )
611  return true;
612  }
613 
614  return false;
615 }
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
wxString GetName() const
Definition: sch_sheet.h:103
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...

References SCH_SHEET::GetName(), and SCH_SHEET_PATH::Last().

◆ PageNumberExists()

bool SCH_SHEET_LIST::PageNumberExists ( const wxString &  aPageNumber) const

Definition at line 618 of file sch_sheet_path.cpp.

619 {
620  for( const SCH_SHEET_PATH& sheet : *this )
621  {
622  if( sheet.GetPageNumber() == aPageNumber )
623  return true;
624  }
625 
626  return false;
627 }
wxString GetPageNumber() const
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...

References SCH_SHEET_PATH::GetPageNumber().

◆ SetInitialPageNumbers()

void SCH_SHEET_LIST::SetInitialPageNumbers ( )

Set initial sheet page numbers.

The number scheme is base on the old pseudo sheet numbering algorithm prior to the implementation of user definable sheet page numbers.

Definition at line 1031 of file sch_sheet_path.cpp.

1032 {
1033  // Don't accidentally renumber existing sheets.
1034  wxCHECK( AllSheetPageNumbersEmpty(), /* void */ );
1035 
1036  wxString tmp;
1037  int pageNumber = 1;
1038 
1039  for( const SCH_SHEET_PATH& instance : *this )
1040  {
1041  SCH_SHEET* sheet = instance.Last();
1042 
1043  wxCHECK2( sheet, continue );
1044 
1045  sheet->AddInstance( instance );
1046  tmp.Printf( "%d", pageNumber );
1047  sheet->SetPageNumber( instance, tmp );
1048  pageNumber += 1;
1049  }
1050 }
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1183
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
bool AddInstance(const SCH_SHEET_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1138

References SCH_SHEET::AddInstance(), AllSheetPageNumbersEmpty(), SCH_SHEET_PATH::Last(), and SCH_SHEET::SetPageNumber().

Referenced by BOOST_AUTO_TEST_CASE(), and SCH_EDIT_FRAME::OpenProjectFiles().

◆ SortByPageNumbers()

void SCH_SHEET_LIST::SortByPageNumbers ( bool  aUpdateVirtualPageNums = true)

Sort the list of sheets by page number.

This should be called after BuildSheetList

If page numbers happen to be equal, then it compares the sheet names to ensure deterministic ordering.

Parameters
aUpdateVirtualPageNumsIf true, updates the virtual page numbers to match the new ordering

Definition at line 586 of file sch_sheet_path.cpp.

587 {
588  std::sort( begin(), end(),
589  []( SCH_SHEET_PATH a, SCH_SHEET_PATH b ) -> bool
590  {
591  return a.ComparePageNum( b ) < 0;
592  } );
593 
594  if( aUpdateVirtualPageNums )
595  {
596  int virtualPageNum = 1;
597 
598  for( SCH_SHEET_PATH& sheet : *this )
599  {
600  sheet.SetVirtualPageNumber( virtualPageNum++ );
601  }
602  }
603 }
int ComparePageNum(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare sheets by their page number.
void SetVirtualPageNumber(int aPageNumber)
Set the sheet instance virtual page number.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...

References SCH_SHEET_PATH::ComparePageNum(), and SCH_SHEET_PATH::SetVirtualPageNumber().

Referenced by DIALOG_PLOT_SCHEMATIC::createDXFFiles(), DIALOG_PLOT_SCHEMATIC::createHPGLFiles(), DIALOG_PLOT_SCHEMATIC::createPDFFile(), DIALOG_PLOT_SCHEMATIC::createPSFiles(), DIALOG_PLOT_SCHEMATIC::createSVGFiles(), SCH_DRAWING_TOOLS::DrawSheet(), SCH_SEXPR_PLUGIN::Format(), SCH_EDITOR_CONTROL::Paste(), and SCH_SHEET_LIST().

◆ TestForRecursion()

bool SCH_SHEET_LIST::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 aSrcSheetHierarchy to the sheet stored in aDestFileName will cause recursion.

Parameters
aSrcSheetHierarchyis the SCH_SHEET_LIST of the source 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.

Definition at line 834 of file sch_sheet_path.cpp.

836 {
837  if( empty() )
838  return false;
839 
840  SCHEMATIC* sch = at( 0 ).LastScreen()->Schematic();
841 
842  wxCHECK_MSG( sch, false, "No SCHEMATIC found in SCH_SHEET_LIST::TestForRecursion!" );
843 
844  wxFileName rootFn = sch->GetFileName();
845  wxFileName destFn = aDestFileName;
846 
847  if( destFn.IsRelative() )
848  destFn.MakeAbsolute( rootFn.GetPath() );
849 
850  // Test each SCH_SHEET_PATH in this SCH_SHEET_LIST for potential recursion.
851  for( unsigned i = 0; i < size(); i++ )
852  {
853  // Test each SCH_SHEET_PATH in the source sheet.
854  for( unsigned j = 0; j < aSrcSheetHierarchy.size(); j++ )
855  {
856  const SCH_SHEET_PATH* sheetPath = &aSrcSheetHierarchy[j];
857 
858  for( unsigned k = 0; k < sheetPath->size(); k++ )
859  {
860  if( at( i ).TestForRecursion( sheetPath->GetSheet( k )->GetFileName(),
861  aDestFileName ) )
862  {
863  return true;
864  }
865  }
866  }
867  }
868 
869  // The source sheet file can safely be added to the destination sheet file.
870  return false;
871 }
Holds all the data relating to one schematic.
Definition: schematic.h:59
size_t size() const
Forwarded method from std::vector.
wxString GetFileName() const override
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:161
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:317
const SCH_SHEET * GetSheet(unsigned aIndex) const
static bool empty(const wxTextEntryBase *aCtrl)

References empty(), SCHEMATIC::GetFileName(), SCH_SHEET::GetFileName(), SCH_SHEET_PATH::GetSheet(), and SCH_SHEET_PATH::size().

Referenced by SCH_EDIT_FRAME::CheckSheetForRecursion().

◆ UpdateSheetInstances()

void SCH_SHEET_LIST::UpdateSheetInstances ( const std::vector< SCH_SHEET_INSTANCE > &  aSheetInstances)

Update all of the sheet instance information using aSheetInstances.

Warning
Do not call this on anything other than the full hierarchy.
Parameters
aSymbolInstancesis the symbol path information loaded from the root schematic.

Definition at line 952 of file sch_sheet_path.cpp.

953 {
954 
955  for( const SCH_SHEET_PATH& path : *this )
956  {
957  SCH_SHEET* sheet = path.Last();
958 
959  wxCHECK2( sheet, continue );
960 
961  auto it = std::find_if( aSheetInstances.begin(), aSheetInstances.end(),
962  [ path ]( const SCH_SHEET_INSTANCE& r ) -> bool
963  {
964  return path.PathWithoutRootUuid() == r.m_Path;
965  } );
966 
967  if( it == aSheetInstances.end() )
968  {
969  wxLogTrace( traceSchSheetPaths, "No sheet instance found for path '%s'",
970  path.PathWithoutRootUuid().AsString() );
971  continue;
972  }
973 
974  wxLogTrace( traceSchSheetPaths, "Setting sheet '%s' instance '%s' page number '%s'",
975  ( sheet->GetName().IsEmpty() ) ? wxT( "root" ) : sheet->GetName(),
976  path.PathWithoutRootUuid().AsString(), it->m_PageNumber );
977  sheet->AddInstance( path );
978  sheet->SetPageNumber( path, it->m_PageNumber );
979  }
980 }
const wxChar *const traceSchSheetPaths
Flag to enable debug output of schematic symbol sheet path manipulation code.
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1183
wxString GetName() const
Definition: sch_sheet.h:103
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
_OUT_STRING AsString(const std::string &aString)
Definition: sexpr.h:131
E_SERIE r
Definition: eserie.cpp:41
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
A simple container for sheet instance information.
bool AddInstance(const SCH_SHEET_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1138

References SCH_SHEET::AddInstance(), SCH_SHEET::GetName(), path, r, SCH_SHEET::SetPageNumber(), and traceSchSheetPaths.

Referenced by TEST_SCH_SHEET_LIST_FIXTURE::loadSchematic(), DIALOG_SHEET_PROPERTIES::onSheetFilenameChanged(), and SCH_EDIT_FRAME::OpenProjectFiles().

◆ UpdateSymbolInstances()

void SCH_SHEET_LIST::UpdateSymbolInstances ( const std::vector< SYMBOL_INSTANCE_REFERENCE > &  aSymbolInstances)

Update all of the symbol instance information using aSymbolInstances.

WARNING: Do not call this on anything other than the full hierarchy.

Parameters
aSymbolInstancesis the symbol path information loaded from the root schematic.

Definition at line 900 of file sch_sheet_path.cpp.

902 {
903  SCH_REFERENCE_LIST symbolInstances;
904 
905  GetSymbols( symbolInstances, true, true );
906 
907  std::map<KIID_PATH, wxString> pathNameCache;
908 
909  // Calculating the name of a path is somewhat expensive; on large designs with many symbols
910  // this can blow up to a serious amount of time when loading the schematic
911  auto getName = [&pathNameCache]( const KIID_PATH& aPath ) -> const wxString&
912  {
913  if( pathNameCache.count( aPath ) )
914  return pathNameCache.at( aPath );
915 
916  pathNameCache[aPath] = aPath.AsString();
917  return pathNameCache[aPath];
918  };
919 
920  for( size_t i = 0; i < symbolInstances.GetCount(); i++ )
921  {
922  // The instance paths are stored in the file sans root path so the comparison
923  // should not include the root path.
924  wxString path = symbolInstances[i].GetPath();
925 
926  auto it = std::find_if( aSymbolInstances.begin(), aSymbolInstances.end(),
927  [ path, &getName ]( const SYMBOL_INSTANCE_REFERENCE& r ) -> bool
928  {
929  return path == getName( r.m_Path );
930  } );
931 
932  if( it == aSymbolInstances.end() )
933  {
934  wxLogTrace( traceSchSheetPaths, "No symbol instance found for path '%s'", path );
935  continue;
936  }
937 
938  SCH_SYMBOL* symbol = symbolInstances[ i ].GetSymbol();
939 
940  wxCHECK2( symbol, continue );
941 
942  // Symbol instance paths are stored and looked up in memory with the root path so use
943  // the full path here.
944  symbol->AddHierarchicalReference( symbolInstances[i].GetSheetPath().Path(),
945  it->m_Reference, it->m_Unit, it->m_Value,
946  it->m_Footprint );
947  symbol->GetField( REFERENCE_FIELD )->SetText( it->m_Reference );
948  }
949 }
Field Reference of part, i.e. "IC21".
const wxChar *const traceSchSheetPaths
Flag to enable debug output of schematic symbol sheet path manipulation code.
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:677
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.
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:124
A simple container for schematic symbol instance information.
size_t GetCount() const
E_SERIE r
Definition: eserie.cpp:41
Schematic symbol object.
Definition: sch_symbol.h:78
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit, const wxString &aValue=wxEmptyString, const wxString &aFootprint=wxEmptyString)
Add a full hierarchical reference to this symbol.
Definition: sch_symbol.cpp:402

References SCH_SYMBOL::AddHierarchicalReference(), SCH_REFERENCE_LIST::GetCount(), SCH_SYMBOL::GetField(), GetSymbols(), path, r, REFERENCE_FIELD, EDA_TEXT::SetText(), and traceSchSheetPaths.

Referenced by TEST_SCH_SHEET_LIST_FIXTURE::loadSchematic(), TEST_NETLISTS_FIXTURE::loadSchematic(), SCH_EDIT_FRAME::OpenProjectFiles(), SCH::readSchematicFromFile(), and ReadSchematicFromFile().

Member Data Documentation

◆ m_currentSheetPath

SCH_SHEET_PATH SCH_SHEET_LIST::m_currentSheetPath
private

Definition at line 594 of file sch_sheet_path.h.

Referenced by BuildSheetList().


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