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 ()
 Check the entire hierarchy for any modifications. More...
 
void ClearModifyStatus ()
 
SCH_ITEMGetItem (const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr)
 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 aForceIncludeOrphanComponents=false) const
 Add a SCH_REFERENCE object to aReferences for each component in the list of sheets. 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 (SCH_SCREEN *aScreen)
 Return a pointer to the first SCH_SHEET_PATH object (not necessarily the only one) 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)
 Sorts the list of sheets by page number. More...
 
bool NameExists (const wxString &aSheetName)
 
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
 
void ReplaceLegacySheetPaths (const std::vector< KIID_PATH > &aOldSheetPaths)
 Update all of the symbol sheet paths to the sheet paths defined in aOldSheetPaths. 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 component references are specific to a sheet path. When a sheet is entered, component references and sheet page number are updated.

Definition at line 350 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 426 of file sch_sheet_path.cpp.

427 {
428  if( aSheet != NULL )
429  {
430  BuildSheetList( aSheet, aCheckIntegrity );
432  }
433 }
#define NULL
void BuildSheetList(SCH_SHEET *aSheet, bool aCheckIntegrity)
Build the list of sheets and their sheet path from aSheet.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sorts the list of sheets by page number.

References BuildSheetList(), NULL, and SortByPageNumbers().

◆ ~SCH_SHEET_LIST()

SCH_SHEET_LIST::~SCH_SHEET_LIST ( )
inline

Definition at line 364 of file sch_sheet_path.h.

364 {}

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

866 {
867  for( const SCH_SHEET_PATH& instance : *this )
868  {
869  const SCH_SHEET* sheet = instance.Last();
870 
871  wxCHECK2( sheet, continue );
872 
873  if( !sheet->GetPageNumber( instance ).IsEmpty() )
874  return false;
875  }
876 
877  return true;
878 }
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:219
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
Definition: sch_sheet.cpp:1092

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

601 {
602  // List of reference for power symbols
603  SCH_REFERENCE_LIST references;
604 
605  // Map of locked components (not used, but needed by Annotate()
606  SCH_MULTI_UNIT_REFERENCE_MAP lockedComponents;
607 
608  // Build the list of power components:
609  for( SCH_SHEET_PATH& sheet : *this )
610  {
611  for( auto item : sheet.LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
612  {
613  auto component = static_cast<SCH_COMPONENT*>( item );
614  LIB_PART* part = component->GetPartRef().get();
615 
616  if( !part || !part->IsPower() )
617  continue;
618 
619  if( part )
620  {
621  SCH_REFERENCE schReference( component, part, sheet );
622  references.AddItem( schReference );
623  }
624  }
625  }
626 
627  // Find duplicate, and silently clear annotation of duplicate
628  std::map<wxString, int> ref_list; // stores the existing references
629 
630  for( unsigned ii = 0; ii< references.GetCount(); ++ii )
631  {
632  wxString curr_ref = references[ii].GetRef();
633 
634  if( ref_list.find( curr_ref ) == ref_list.end() )
635  {
636  ref_list[curr_ref] = ii;
637  continue;
638  }
639 
640  // Possible duplicate, if the ref ends by a number:
641  if( curr_ref.Last() < '0' && curr_ref.Last() > '9' )
642  continue; // not annotated
643 
644  // Duplicate: clear annotation by removing the number ending the ref
645  while( curr_ref.Last() >= '0' && curr_ref.Last() <= '9' )
646  curr_ref.RemoveLast();
647 
648  references[ii].SetRef( curr_ref );
649  }
650 
651 
652  // Break full components reference in name (prefix) and number:
653  // example: IC1 become IC, and 1
654  references.SplitReferences();
655 
656  // Ensure all power symbols have the reference starting by '#'
657  // (No sure this is really useful)
658  for( unsigned ii = 0; ii< references.GetCount(); ++ii )
659  {
660  if( references[ii].GetRef()[0] != '#' )
661  {
662  wxString new_ref = "#" + references[ii].GetRef();
663  references[ii].SetRef( new_ref );
664  }
665  }
666 
667  // Recalculate and update reference numbers in schematic
668  references.Annotate( false, 0, 100, lockedComponents );
669  references.UpdateAnnotation();
670 }
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:219
void AddItem(SCH_REFERENCE &aItem)
SCH_REFERENCE_LIST is used to create a flattened list of symbols because in a complex hierarchy,...
void UpdateAnnotation()
function UpdateAnnotation Updates the symbol references for the schematic project (or the current she...
Define a library symbol object.
void Annotate(bool aUseSheetNum, int aSheetIntervalId, int aStartNumber, SCH_MULTI_UNIT_REFERENCE_MAP aLockedUnitMap)
Function Annotate set the reference designators in the list that have not been annotated.
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.
unsigned GetCount() const
bool IsPower() const
SCH_SCREEN * LastScreen()
void SplitReferences()
Function SplitReferences attempts to split all reference designators into a name (U) and number (1).
EE_RTREE & Items()
Definition: sch_screen.h:159
SCH_REFERENCE is used as 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(), LIB_PART::IsPower(), SCH_SCREEN::Items(), SCH_SHEET_PATH::LastScreen(), EE_RTREE::OfType(), SCH_COMPONENT_T, SCH_REFERENCE_LIST::SplitReferences(), and SCH_REFERENCE_LIST::UpdateAnnotation().

Referenced by SCH_EDIT_FRAME::KiwayMailIn(), 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 436 of file sch_sheet_path.cpp.

437 {
438  wxCHECK_RET( aSheet != NULL, wxT( "Cannot build sheet list from undefined sheet." ) );
439 
440  std::vector<SCH_SHEET*> badSheets;
441 
442  m_currentSheetPath.push_back( aSheet );
443  m_currentSheetPath.SetVirtualPageNumber( static_cast<int>( size() ) + 1 );
444  push_back( m_currentSheetPath );
445 
447  {
448  wxString parentFileName = aSheet->GetFileName();
449  std::vector<SCH_ITEM*> childSheets;
450  m_currentSheetPath.LastScreen()->GetSheets( &childSheets );
451 
452  for( SCH_ITEM* item : childSheets )
453  {
454  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
455 
456  if( aCheckIntegrity )
457  {
458  if( !m_currentSheetPath.TestForRecursion( sheet->GetFileName(), parentFileName ) )
459  BuildSheetList( sheet, true );
460  else
461  badSheets.push_back( sheet );
462  }
463  else
464  {
465  BuildSheetList( sheet, false );
466  }
467  }
468  }
469 
470  if( aCheckIntegrity )
471  {
472  for( SCH_SHEET* sheet : badSheets )
473  {
476  }
477  }
478 
480 }
bool Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:241
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
void GetSheets(std::vector< SCH_ITEM * > *aItems)
Similar to Items().OfType( SCH_SHEET_T ), but return the sheets in a deterministic order (L-R,...
Definition: sch_screen.cpp:969
void pop_back()
Forwarded method from std::vector.
#define NULL
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:499
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
SCH_SCREEN * LastScreen()
void SetModify()
Definition: base_screen.h:59
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
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, NULL, SCH_SHEET_PATH::pop_back(), SCH_SHEET_PATH::push_back(), SCH_SCREEN::Remove(), BASE_SCREEN::SetModify(), SCH_SHEET_PATH::SetVirtualPageNumber(), and SCH_SHEET_PATH::TestForRecursion().

Referenced by DIALOG_PLOT_SCHEMATIC::CreateDXFFile(), DIALOG_PLOT_SCHEMATIC::createHPGLFile(), DIALOG_PLOT_SCHEMATIC::createPDFFile(), DIALOG_PLOT_SCHEMATIC::createPSFile(), DIALOG_PLOT_SCHEMATIC::createSVGFile(), SCHEMATIC::GetFullHierarchy(), and SCH_SHEET_LIST().

◆ ClearModifyStatus()

void SCH_SHEET_LIST::ClearModifyStatus ( )

Definition at line 530 of file sch_sheet_path.cpp.

531 {
532  for( const SCH_SHEET_PATH& sheet : *this )
533  {
534  if( sheet.LastScreen() )
535  sheet.LastScreen()->ClrModify();
536  }
537 }
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
void ClrModify()
Definition: base_screen.h:60

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

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

581 {
582  for( const SCH_SHEET_PATH& sheet : *this )
583  {
584  SCH_SCREEN* screen = sheet.LastScreen();
585 
586  for( SCH_ITEM* aItem : screen->Items() )
587  {
588  aMap[ aItem->m_Uuid ] = aItem;
589 
590  aItem->RunOnChildren(
591  [&]( SCH_ITEM* aChild )
592  {
593  aMap[ aChild->m_Uuid ] = aChild;
594  } );
595  }
596  }
597 }
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:523
SCH_SCREEN * LastScreen()
EE_RTREE & Items()
Definition: sch_screen.h:159
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194

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

Referenced by DIALOG_ERC::writeReport().

◆ FindSheetForScreen()

SCH_SHEET_PATH * SCH_SHEET_LIST::FindSheetForScreen ( 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 741 of file sch_sheet_path.cpp.

742 {
743  for( SCH_SHEET_PATH& sheetpath : *this )
744  {
745  if( sheetpath.LastScreen() == aScreen )
746  return &sheetpath;
747  }
748 
749  return nullptr;
750 }
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_EDITOR_CONTROL::FindNext(), and SCH_EDITOR_CONTROL::ReplaceAll().

◆ GetItem()

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

Fetch a SCH_ITEM by ID.

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

Definition at line 540 of file sch_sheet_path.cpp.

541 {
542  for( const SCH_SHEET_PATH& sheet : *this )
543  {
544  SCH_SCREEN* screen = sheet.LastScreen();
545 
546  for( SCH_ITEM* aItem : screen->Items() )
547  {
548  if( aItem->m_Uuid == aID )
549  {
550  if( aPathOut )
551  *aPathOut = sheet;
552 
553  return aItem;
554  }
555 
556  SCH_ITEM* childMatch = nullptr;
557 
558  aItem->RunOnChildren(
559  [&]( SCH_ITEM* aChild )
560  {
561  if( aChild->m_Uuid == aID )
562  childMatch = aChild;
563  } );
564 
565  if( childMatch )
566  {
567  if( aPathOut )
568  *aPathOut = sheet;
569 
570  return childMatch;
571  }
572  }
573  }
574 
575  // Not found; weak reference has been deleted.
577 }
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
Definition: sch_item.h:475
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:523
SCH_SCREEN * LastScreen()
static DELETED_SHEET_ITEM * GetInstance()
EE_RTREE & Items()
Definition: sch_screen.h:159
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194

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(), and SCH_EDIT_FRAME::ResolveERCExclusions().

◆ 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 components.

Definition at line 681 of file sch_sheet_path.cpp.

683 {
684  for( SCH_SHEET_PATHS::const_iterator it = begin(); it != end(); ++it )
685  {
687  (*it).GetMultiUnitComponents( tempMap );
688 
689  for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : tempMap )
690  {
691  // Merge this list into the main one
692  unsigned n_refs = pair.second.GetCount();
693 
694  for( unsigned thisRef = 0; thisRef < n_refs; ++thisRef )
695  {
696  aRefList[pair.first].AddItem( pair.second[thisRef] );
697  }
698  }
699  }
700 }
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::AnnotateComponents(), BACK_ANNOTATE::BackAnnotateSymbols(), and ERC_TESTER::TestMultiunitFootprints().

◆ GetPaths()

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

Definition at line 833 of file sch_sheet_path.cpp.

834 {
835  std::vector<KIID_PATH> paths;
836 
837  for( const SCH_SHEET_PATH& sheetPath : *this )
838  paths.emplace_back( sheetPath.Path() );
839 
840  return paths;
841 }
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().

◆ GetSymbols()

void SCH_SHEET_LIST::GetSymbols ( SCH_REFERENCE_LIST aReferences,
bool  aIncludePowerSymbols = true,
bool  aForceIncludeOrphanComponents = false 
) const

Add a SCH_REFERENCE object to aReferences for each component in the list of sheets.

Parameters
aReferencesList of references to populate.
aIncludePowerSymbolsSet to false to only get normal components.
aForceIncludeOrphanComponents: true to include components having no symbol found in lib. ( orphan components) The normal option is false, and set to true only to build the full list of components.

Definition at line 673 of file sch_sheet_path.cpp.

675 {
676  for( const SCH_SHEET_PATH& sheet : *this )
677  sheet.GetSymbols( aReferences, aIncludePowerSymbols, aForceIncludeOrphanComponents );
678 }
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 aForceIncludeOrphanComponents=false) const
Adds SCH_REFERENCE object to aReferences for each component in the sheet.

References SCH_SHEET_PATH::GetSymbols().

Referenced by SCH_EDIT_FRAME::AnnotateComponents(), SCH_EDITOR_CONTROL::AssignFootprints(), BACK_ANNOTATE::BackAnnotateSymbols(), SCH_EDIT_FRAME::CheckAnnotate(), SCHEMATIC::ConvertRefsToKIIDs(), DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL(), SCH_EDITOR_CONTROL::doCopy(), DIALOG_EDIT_COMPONENTS_LIBID::initDlg(), SCH_EDIT_FRAME::mapExistingAnnotation(), DIALOG_LABEL_EDITOR::onScintillaCharAdded(), DIALOG_SCH_EDIT_ONE_FIELD::onScintillaCharAdded(), SCH_EDITOR_CONTROL::processCmpToFootprintLinkFile(), and UpdateSymbolInstances().

◆ IsModified()

bool SCH_SHEET_LIST::IsModified ( )

Check the entire hierarchy for any modifications.

Returns
True if the hierarchy is modified otherwise false.

Definition at line 518 of file sch_sheet_path.cpp.

519 {
520  for( const SCH_SHEET_PATH& sheet : *this )
521  {
522  if( sheet.LastScreen() && sheet.LastScreen()->IsModify() )
523  return true;
524  }
525 
526  return false;
527 }
bool IsModify() const
Definition: base_screen.h:63
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::IsModify(), 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)

Definition at line 506 of file sch_sheet_path.cpp.

507 {
508  for( const SCH_SHEET_PATH& sheet : *this )
509  {
510  if( sheet.Last()->GetName() == aSheetName )
511  return true;
512  }
513 
514  return false;
515 }
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
wxString GetName() const
Definition: sch_sheet.h:283
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().

Referenced by SCH_EDIT_TOOL::Duplicate(), and SCH_EDITOR_CONTROL::Paste().

◆ ReplaceLegacySheetPaths()

void SCH_SHEET_LIST::ReplaceLegacySheetPaths ( const std::vector< KIID_PATH > &  aOldSheetPaths)

Update all of the symbol sheet paths to the sheet paths defined in aOldSheetPaths.

Note
The list of old sheet paths must be the exact same size and order as the existing sheet paths. This should not be an issue if no new sheets where added between the creation of this sheet list and aOldSheetPaths. This should only be called when updating legacy schematics to the new schematic file format. Once this happens, the schematic cannot be save to the legacy file format because the time stamp part of UUIDs are no longer guaranteed to be unique.
Parameters
aOldSheetPathsis the #SHEET_PATH_LIST to update from.

Definition at line 844 of file sch_sheet_path.cpp.

845 {
846  wxCHECK( size() == aOldSheetPaths.size(), /* void */ );
847 
848  for( size_t i = 0; i < size(); i++ )
849  {
850  const KIID_PATH oldSheetPath = aOldSheetPaths.at( i );
851  const KIID_PATH newSheetPath = at( i ).Path();
852  SCH_SCREEN* screen = at(i).LastScreen();
853 
854  wxCHECK( screen, /* void */ );
855 
856  for( SCH_ITEM* symbol : screen->Items().OfType( SCH_COMPONENT_T ) )
857  {
858  static_cast<SCH_COMPONENT*>( symbol )->ReplaceInstanceSheetPath( oldSheetPath,
859  newSheetPath );
860  }
861  }
862 }
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:219
EE_RTREE & Items()
Definition: sch_screen.h:159
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194

References SCH_SCREEN::Items(), EE_RTREE::OfType(), and SCH_COMPONENT_T.

◆ SetInitialPageNumbers()

void SCH_SHEET_LIST::SetInitialPageNumbers ( )

Set initial sheet page numbers.

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

Definition at line 881 of file sch_sheet_path.cpp.

882 {
883  // Don't accidently renumber existing sheets.
884  wxCHECK( AllSheetPageNumbersEmpty(), /* void */ );
885 
886  wxString tmp;
887  int pageNumber = 1;
888 
889  for( const SCH_SHEET_PATH& instance : *this )
890  {
891  SCH_SHEET* sheet = instance.Last();
892 
893  wxCHECK2( sheet, continue );
894 
895  sheet->AddInstance( instance.Path() );
896  tmp.Printf( "%d", pageNumber );
897  sheet->SetPageNumber( instance, tmp );
898  pageNumber += 1;
899  }
900 }
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1110
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:219
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
bool AddInstance(const KIID_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1068

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

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

◆ SortByPageNumbers()

void SCH_SHEET_LIST::SortByPageNumbers ( bool  aUpdateVirtualPageNums = true)

Sorts the list of sheets by page number.

This should be called after BuildSheetList

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

Definition at line 483 of file sch_sheet_path.cpp.

484 {
485  std::sort( begin(), end(),
486  []( SCH_SHEET_PATH a, SCH_SHEET_PATH b ) -> bool
487  {
488  wxString pageA = a.GetPageNumber();
489  wxString pageB = b.GetPageNumber();
490 
491  return SCH_SHEET::ComparePageNum( pageA, pageB ) < 0;
492  } );
493 
494  if( aUpdateVirtualPageNums )
495  {
496  int virtualPageNum = 1;
497 
498  for( SCH_SHEET_PATH& sheet : *this )
499  {
500  sheet.SetVirtualPageNumber( virtualPageNum++ );
501  }
502  }
503 }
static int ComparePageNum(const wxString &aPageNumberA, const wxString aPageNumberB)
Compares page numbers of schematic sheets.
Definition: sch_sheet.cpp:1125
void SetVirtualPageNumber(int aPageNumber)
Set the sheet instance virtual page number.
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::ComparePageNum(), SCH_SHEET_PATH::GetPageNumber(), and SCH_SHEET_PATH::SetVirtualPageNumber().

Referenced by DIALOG_PLOT_SCHEMATIC::CreateDXFFile(), DIALOG_PLOT_SCHEMATIC::createHPGLFile(), DIALOG_PLOT_SCHEMATIC::createPDFFile(), DIALOG_PLOT_SCHEMATIC::createPSFile(), DIALOG_PLOT_SCHEMATIC::createSVGFile(), SCHEMATIC::GetFullHierarchy(), 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 703 of file sch_sheet_path.cpp.

705 {
706  if( empty() )
707  return false;
708 
709  SCHEMATIC* sch = at( 0 ).LastScreen()->Schematic();
710 
711  wxCHECK_MSG( sch, false, "No SCHEMATIC found in SCH_SHEET_LIST::TestForRecursion!" );
712 
713  wxFileName rootFn = sch->GetFileName();
714  wxFileName destFn = aDestFileName;
715 
716  if( destFn.IsRelative() )
717  destFn.MakeAbsolute( rootFn.GetPath() );
718 
719  // Test each SCH_SHEET_PATH in this SCH_SHEET_LIST for potential recursion.
720  for( unsigned i = 0; i < size(); i++ )
721  {
722  // Test each SCH_SHEET_PATH in the source sheet.
723  for( unsigned j = 0; j < aSrcSheetHierarchy.size(); j++ )
724  {
725  const SCH_SHEET_PATH* sheetPath = &aSrcSheetHierarchy[j];
726 
727  for( unsigned k = 0; k < sheetPath->size(); k++ )
728  {
729  if( at( i ).TestForRecursion( sheetPath->GetSheet( k )->GetFileName(),
730  aDestFileName ) )
731  return true;
732  }
733  }
734  }
735 
736  // The source sheet file can safely be added to the destination sheet file.
737  return false;
738 }
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
Definition: schematic.h:44
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:119
size_t size() const
Forwarded method from std::vector.
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:499
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(), and SCH_EDITOR_CONTROL::Paste().

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

806 {
807 
808  for( const SCH_SHEET_PATH& instance : *this )
809  {
810  auto it = std::find_if( aSheetInstances.begin(), aSheetInstances.end(),
811  [ instance ]( const SCH_SHEET_INSTANCE& r ) -> bool
812  {
813  return instance.PathWithoutRootUuid() == r.m_Path;
814  } );
815 
816  if( it == aSheetInstances.end() )
817  {
818  wxLogTrace( traceSchSheetPaths, "No sheet instance found for path \"%s\"",
819  instance.PathWithoutRootUuid().AsString() );
820  continue;
821  }
822 
823  SCH_SHEET* sheet = instance.Last();
824 
825  wxCHECK2( sheet, continue );
826 
827  sheet->AddInstance( instance.Path() );
828  sheet->SetPageNumber( instance, it->m_PageNumber );
829  }
830 }
const wxChar *const traceSchSheetPaths
Flag to enable debug output of schematic symbol sheet path manipulation code.
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1110
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
KIID_PATH PathWithoutRootUuid() const
Get the sheet path as an KIID_PATH without the root sheet UUID prefix.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:219
A simple container for sheet instance infromation.
wxString AsString() const
Definition: kiid.cpp:245
bool AddInstance(const KIID_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1068

References SCH_SHEET::AddInstance(), KIID_PATH::AsString(), SCH_SHEET_PATH::Last(), SCH_SHEET_PATH::Path(), SCH_SHEET_PATH::PathWithoutRootUuid(), SCH_SHEET::SetPageNumber(), and traceSchSheetPaths.

Referenced by 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 753 of file sch_sheet_path.cpp.

755 {
756  SCH_REFERENCE_LIST symbolInstances;
757 
758  GetSymbols( symbolInstances, true, true );
759 
760  std::map<KIID_PATH, wxString> pathNameCache;
761 
762  // Calculating the name of a path is somewhat expensive; on large designs with many components
763  // this can blow up to a serious amount of time when loading the schematic
764  auto getName = [&pathNameCache]( const KIID_PATH& aPath ) -> const wxString&
765  {
766  if( pathNameCache.count( aPath ) )
767  return pathNameCache.at( aPath );
768 
769  pathNameCache[aPath] = aPath.AsString();
770  return pathNameCache[aPath];
771  };
772 
773  for( size_t i = 0; i < symbolInstances.GetCount(); i++ )
774  {
775  // The instance paths are stored in the file sans root path so the comparison
776  // should not include the root path.
777  wxString path = symbolInstances[i].GetPath();
778 
779  auto it = std::find_if( aSymbolInstances.begin(), aSymbolInstances.end(),
780  [ path, &getName ]( const SYMBOL_INSTANCE_REFERENCE& r ) -> bool
781  {
782  return path == getName( r.m_Path );
783  } );
784 
785  if( it == aSymbolInstances.end() )
786  {
787  wxLogTrace( traceSchSheetPaths, "No symbol instance found for path \"%s\"", path );
788  continue;
789  }
790 
791  SCH_COMPONENT* symbol = symbolInstances[ i ].GetSymbol();
792 
793  wxCHECK2( symbol, continue );
794 
795  // Symbol instance paths are stored and looked up in memory with the root path so use
796  // the full path here.
797  symbol->AddHierarchicalReference( symbolInstances[i].GetSheetPath().Path(),
798  it->m_Reference, it->m_Unit, it->m_Value,
799  it->m_Footprint );
800  symbol->GetField( REFERENCE_FIELD )->SetText( it->m_Reference );
801  }
802 }
const wxChar *const traceSchSheetPaths
Flag to enable debug output of schematic symbol sheet path manipulation code.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false) const
Add a SCH_REFERENCE object to aReferences for each component in the list of sheets.
SCH_REFERENCE_LIST is used to create a flattened list of symbols because in a complex hierarchy,...
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:121
A simple container for schematic symbol instance infromation.
unsigned GetCount() const
SCH_FIELD * GetField(int aFieldNdx)
Returns a field in this symbol.
Schematic symbol object.
Definition: sch_component.h:79
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.
Field Reference of part, i.e. "IC21".

References SCH_COMPONENT::AddHierarchicalReference(), SCH_REFERENCE_LIST::GetCount(), SCH_COMPONENT::GetField(), GetSymbols(), 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 353 of file sch_sheet_path.h.

Referenced by BuildSheetList().


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