KiCad PCB EDA Suite
SCH_SHEET_LIST Class Reference

SCH_SHEET_LIST. More...

#include <sch_sheet_path.h>

Inheritance diagram for SCH_SHEET_LIST:

Public Member Functions

 SCH_SHEET_LIST (SCH_SHEET *aSheet=NULL)
 Constructor build a flattened list of SCH_SHEET_PATH objects from aSheet. More...
 
 ~SCH_SHEET_LIST ()
 
bool IsModified ()
 Function IsModified checks 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 ()
 Function AnnotatePowerSymbols Silently annotates the not yet annotated power symbols of the entire hierarchy of the sheet path list. More...
 
void GetComponents (SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false) const
 Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the list of sheets. More...
 
void GetMultiUnitComponents (SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true) const
 Function GetMultiUnitComponents adds 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)
 Function TestForRecursion. More...
 
SCH_SHEET_PATHFindSheetForScreen (SCH_SCREEN *aScreen)
 Function FindSheetForScreen. More...
 
void BuildSheetList (SCH_SHEET *aSheet)
 Function BuildSheetList builds the list of sheets and their sheet path from aSheet. More...
 
bool NameExists (const wxString &aSheetName)
 
void UpdateSymbolInstances (const std::vector< COMPONENT_INSTANCE_REFERENCE > &aSymbolInstances)
 Update all of the symbol instance information using aSymbolInstances. 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...
 

Private Attributes

SCH_SHEET_PATH m_currentSheetPath
 

Detailed Description

SCH_SHEET_LIST.

handles a list of 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 333 of file sch_sheet_path.h.

Constructor & Destructor Documentation

◆ SCH_SHEET_LIST()

SCH_SHEET_LIST::SCH_SHEET_LIST ( SCH_SHEET aSheet = NULL)

Constructor build 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 401 of file sch_sheet_path.cpp.

402 {
403  if( aSheet != NULL )
404  BuildSheetList( aSheet );
405 }
#define NULL
void BuildSheetList(SCH_SHEET *aSheet)
Function BuildSheetList builds the list of sheets and their sheet path from aSheet.

References BuildSheetList(), and NULL.

◆ ~SCH_SHEET_LIST()

SCH_SHEET_LIST::~SCH_SHEET_LIST ( )
inline

Definition at line 348 of file sch_sheet_path.h.

348 {}

Member Function Documentation

◆ AnnotatePowerSymbols()

void SCH_SHEET_LIST::AnnotatePowerSymbols ( )

Function AnnotatePowerSymbols Silently annotates 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 594 of file sch_sheet_path.cpp.

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

◆ BuildSheetList()

void SCH_SHEET_LIST::BuildSheetList ( SCH_SHEET aSheet)

Function BuildSheetList builds 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.

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.
Todo:
: Schematic page number is currently a left over relic and is generated as SCH_SHEET_PATH object is pushed to the list. This only has meaning when entire hierarchy is created from the root sheet down.

Definition at line 408 of file sch_sheet_path.cpp.

409 {
410  wxCHECK_RET( aSheet != NULL, wxT( "Cannot build sheet list from undefined sheet." ) );
411 
412  std::vector<SCH_SHEET*> badSheets;
413 
414  m_currentSheetPath.push_back( aSheet );
415 
421  m_currentSheetPath.SetPageNumber( size() + 1 );
422  push_back( m_currentSheetPath );
423 
425  {
426  std::vector<SCH_ITEM*> childSheets;
427  m_currentSheetPath.LastScreen()->GetSheets( &childSheets );
428 
429  for( SCH_ITEM* item : childSheets )
430  {
431  auto sheet = static_cast<SCH_SHEET*>( item );
432 
434  sheet->GetFileName(), aSheet->GetFileName() ) )
435  BuildSheetList( sheet );
436  else
437  badSheets.push_back( sheet );
438  }
439  }
440 
441  for( auto sheet : badSheets )
442  {
445  }
446 
448 }
bool Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:243
void SetPageNumber(int aPageNumber)
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
void GetSheets(std::vector< SCH_ITEM * > *aItems)
Similar to GetItems().OfType( SCH_SHEET_T ), but return the sheets in a deterministic order (L-R,...
Definition: sch_screen.cpp:962
void pop_back()
Forwarded method from std::vector.
#define NULL
SCH_SHEET_PATH m_currentSheetPath
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:496
void BuildSheetList(SCH_SHEET *aSheet)
Function BuildSheetList builds the list of sheets and their sheet path from aSheet.
SCH_SCREEN * LastScreen()
Function LastScreen.
void SetModify()
Definition: base_screen.h:100
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)
Function TestForRecursion.

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::SetPageNumber(), 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(), SCH_EDITOR_CONTROL::FindComponentAndItem(), and SCH_SHEET_LIST().

◆ ClearModifyStatus()

void SCH_SHEET_LIST::ClearModifyStatus ( )

Definition at line 475 of file sch_sheet_path.cpp.

476 {
477  for( const SCH_SHEET_PATH& sheet : *this )
478  {
479  if( sheet.LastScreen() )
480  sheet.LastScreen()->ClrModify();
481  }
482 }
SCH_SHEET_PATH.
SCH_SCREEN * LastScreen()
Function LastScreen.
void ClrModify()
Definition: base_screen.h:101

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

560 {
561  for( const SCH_SHEET_PATH& sheet : *this )
562  {
563  SCH_SCREEN* screen = sheet.LastScreen();
564 
565  for( SCH_ITEM* aItem : screen->Items() )
566  {
567  aMap[ aItem->m_Uuid ] = aItem;
568 
569  if( aItem->Type() == SCH_COMPONENT_T )
570  {
571  SCH_COMPONENT* comp = static_cast<SCH_COMPONENT*>( aItem );
572 
573  for( SCH_FIELD& field : comp->GetFields() )
574  aMap[ field.m_Uuid ] = &field;
575 
576  for( SCH_PIN* pin : comp->GetPins() )
577  aMap[ pin->m_Uuid ] = pin;
578  }
579  else if( aItem->Type() == SCH_SHEET_T )
580  {
581  SCH_SHEET* sch_sheet = static_cast<SCH_SHEET*>( aItem );
582 
583  for( SCH_FIELD& field : sch_sheet->GetFields() )
584  aMap[ field.m_Uuid ] = &field;
585 
586  for( SCH_SHEET_PIN* pin : sch_sheet->GetPins() )
587  aMap[ pin->m_Uuid ] = pin;
588  }
589  }
590  }
591 }
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populates a std::vector with SCH_FIELDs.
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:268
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:84
SCH_SHEET_PATH.
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieves a list of the SCH_PINs for the given sheet path.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:362
SCH_SCREEN * LastScreen()
Function LastScreen.
EE_RTREE & Items()
Definition: sch_screen.h:158
Schematic symbol object.
Definition: sch_component.h:80
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194

References SCH_SHEET::GetFields(), SCH_COMPONENT::GetFields(), SCH_SHEET::GetPins(), SCH_COMPONENT::GetPins(), SCH_SCREEN::Items(), SCH_SHEET_PATH::LastScreen(), SCH_COMPONENT_T, and SCH_SHEET_T.

Referenced by DIALOG_ERC::writeReport().

◆ FindSheetForScreen()

SCH_SHEET_PATH * SCH_SHEET_LIST::FindSheetForScreen ( SCH_SCREEN aScreen)

Function FindSheetForScreen.

returns the first sheetPath (not necessarily the only one) using a particular screen

Definition at line 735 of file sch_sheet_path.cpp.

736 {
737  for( SCH_SHEET_PATH& sheetpath : *this )
738  {
739  if( sheetpath.LastScreen() == aScreen )
740  return &sheetpath;
741  }
742 
743  return nullptr;
744 }
SCH_SHEET_PATH.
SCH_SCREEN * LastScreen()
Function LastScreen.

References SCH_SHEET_PATH::LastScreen().

Referenced by SCH_EDITOR_CONTROL::FindNext(), and SCH_EDITOR_CONTROL::ReplaceAll().

◆ GetComponents()

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

Function GetComponents adds 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 667 of file sch_sheet_path.cpp.

669 {
670  for( const SCH_SHEET_PATH& sheet : *this )
671  sheet.GetComponents( aReferences, aIncludePowerSymbols, aForceIncludeOrphanComponents );
672 }
void GetComponents(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanComponents=false) const
Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the sheet.
SCH_SHEET_PATH.

References SCH_SHEET_PATH::GetComponents().

Referenced by SCH_EDIT_FRAME::AnnotateComponents(), SCH_EDITOR_CONTROL::BackAnnotateFootprints(), 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().

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

486 {
487  for( const SCH_SHEET_PATH& sheet : *this )
488  {
489  SCH_SCREEN* screen = sheet.LastScreen();
490 
491  for( SCH_ITEM* aItem : screen->Items() )
492  {
493  if( aItem->m_Uuid == aID )
494  {
495  if( aPathOut )
496  *aPathOut = sheet;
497 
498  return aItem;
499  }
500  else if( aItem->Type() == SCH_COMPONENT_T )
501  {
502  SCH_COMPONENT* comp = static_cast<SCH_COMPONENT*>( aItem );
503 
504  for( SCH_FIELD& field : comp->GetFields() )
505  {
506  if( field.m_Uuid == aID )
507  {
508  if( aPathOut )
509  *aPathOut = sheet;
510 
511  return &field;
512  }
513  }
514 
515  for( SCH_PIN* pin : comp->GetPins() )
516  {
517  if( pin->m_Uuid == aID )
518  {
519  if( aPathOut )
520  *aPathOut = sheet;
521 
522  return pin;
523  }
524  }
525  }
526  else if( aItem->Type() == SCH_SHEET_T )
527  {
528  SCH_SHEET* sch_sheet = static_cast<SCH_SHEET*>( aItem );
529 
530  for( SCH_FIELD& field : sch_sheet->GetFields() )
531  {
532  if( field.m_Uuid == aID )
533  {
534  if( aPathOut )
535  *aPathOut = sheet;
536  return &field;
537  }
538  }
539 
540  for( SCH_SHEET_PIN* pin : sch_sheet->GetPins() )
541  {
542  if( pin->m_Uuid == aID )
543  {
544  if( aPathOut )
545  *aPathOut = sheet;
546 
547  return pin;
548  }
549  }
550  }
551  }
552  }
553 
554  // Not found; weak reference has been deleted.
556 }
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populates a std::vector with SCH_FIELDs.
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:268
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:84
SCH_SHEET_PATH.
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieves a list of the SCH_PINs for the given sheet path.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:216
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:362
SCH_SCREEN * LastScreen()
Function LastScreen.
static DELETED_SHEET_ITEM * GetInstance()
EE_RTREE & Items()
Definition: sch_screen.h:158
Schematic symbol object.
Definition: sch_component.h:80
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194

References SCH_SHEET::GetFields(), SCH_COMPONENT::GetFields(), DELETED_SHEET_ITEM::GetInstance(), SCH_SHEET::GetPins(), SCH_COMPONENT::GetPins(), SCH_SCREEN::Items(), SCH_SHEET_PATH::LastScreen(), SCH_COMPONENT_T, and SCH_SHEET_T.

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

◆ GetMultiUnitComponents()

void SCH_SHEET_LIST::GetMultiUnitComponents ( SCH_MULTI_UNIT_REFERENCE_MAP aRefList,
bool  aIncludePowerSymbols = true 
) const

Function GetMultiUnitComponents adds 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 675 of file sch_sheet_path.cpp.

677 {
678  for( SCH_SHEET_PATHS::const_iterator it = begin(); it != end(); ++it )
679  {
681  (*it).GetMultiUnitComponents( tempMap );
682 
683  for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : tempMap )
684  {
685  // Merge this list into the main one
686  unsigned n_refs = pair.second.GetCount();
687 
688  for( unsigned thisRef = 0; thisRef < n_refs; ++thisRef )
689  {
690  aRefList[pair.first].AddItem( pair.second[thisRef] );
691  }
692  }
693  }
694 }
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Type SCH_MULTI_UNIT_REFERENCE_MAP is used to create a map of reference designators for multi-unit par...

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

800 {
801  std::vector<KIID_PATH> paths;
802 
803  for( const SCH_SHEET_PATH& sheetPath : *this )
804  paths.emplace_back( sheetPath.Path() );
805 
806  return paths;
807 }
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SHEET_PATH.

References SCH_SHEET_PATH::Path().

Referenced by SCH_EDIT_FRAME::ConvertTimeStampUuids().

◆ IsModified()

bool SCH_SHEET_LIST::IsModified ( )

Function IsModified checks the entire hierarchy for any modifications.

Returns
True if the hierarchy is modified otherwise false.

Definition at line 463 of file sch_sheet_path.cpp.

464 {
465  for( const SCH_SHEET_PATH& sheet : *this )
466  {
467  if( sheet.LastScreen() && sheet.LastScreen()->IsModify() )
468  return true;
469  }
470 
471  return false;
472 }
bool IsModify() const
Definition: base_screen.h:104
SCH_SHEET_PATH.
SCH_SCREEN * LastScreen()
Function 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 451 of file sch_sheet_path.cpp.

452 {
453  for( const SCH_SHEET_PATH& sheet : *this )
454  {
455  if( sheet.Last()->GetName() == aSheetName )
456  return true;
457  }
458 
459  return false;
460 }
SCH_SHEET * Last() const
Function Last returns a pointer to the last sheet of the list One can see the others sheet as the "pa...
wxString GetName() const
Definition: sch_sheet.h:280
SCH_SHEET_PATH.

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

811 {
812  wxCHECK( size() == aOldSheetPaths.size(), /* void */ );
813 
814  for( size_t i = 0; i < size(); i++ )
815  {
816  const KIID_PATH oldSheetPath = aOldSheetPaths.at( i );
817  const KIID_PATH newSheetPath = at( i ).Path();
818  SCH_SCREEN* screen = at(i).LastScreen();
819 
820  wxCHECK( screen, /* void */ );
821 
822  for( SCH_ITEM* symbol : screen->Items().OfType( SCH_COMPONENT_T ) )
823  {
824  static_cast<SCH_COMPONENT*>( symbol )->ReplaceInstanceSheetPath( oldSheetPath,
825  newSheetPath );
826  }
827  }
828 }
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
EE_RTREE & Items()
Definition: sch_screen.h:158
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.

Referenced by SCH_EDIT_FRAME::ConvertTimeStampUuids().

◆ TestForRecursion()

bool SCH_SHEET_LIST::TestForRecursion ( const SCH_SHEET_LIST aSrcSheetHierarchy,
const wxString &  aDestFileName 
)

Function TestForRecursion.

test every SCH_SHEET_PATH in the 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 697 of file sch_sheet_path.cpp.

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

◆ UpdateSymbolInstances()

void SCH_SHEET_LIST::UpdateSymbolInstances ( const std::vector< COMPONENT_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 747 of file sch_sheet_path.cpp.

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

References SCH_COMPONENT::AddHierarchicalReference(), GetComponents(), SCH_REFERENCE_LIST::GetCount(), SCH_COMPONENT::GetField(), REFERENCE, EDA_TEXT::SetText(), and traceSchSheetPaths.

Referenced by TEST_NETLISTS_FIXTURE::loadSchematic(), and SCH_EDIT_FRAME::OpenProjectFiles().

Member Data Documentation

◆ m_currentSheetPath

SCH_SHEET_PATH SCH_SHEET_LIST::m_currentSheetPath
private

Definition at line 336 of file sch_sheet_path.h.

Referenced by BuildSheetList().


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