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 SetComponentFootprint (const wxString &aReference, const wxString &aFootPrint, bool aSetVisible)
 Function SetFootprintField searches all the sheets for a component with aReference and set the footprint field to aFootPrint if found. 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 379 of file sch_sheet_path.cpp.

380 {
381  if( aSheet != NULL )
382  BuildSheetList( aSheet );
383 }
#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 575 of file sch_sheet_path.cpp.

576 {
577  // List of reference for power symbols
578  SCH_REFERENCE_LIST references;
579 
580  // Map of locked components (not used, but needed by Annotate()
581  SCH_MULTI_UNIT_REFERENCE_MAP lockedComponents;
582 
583  // Build the list of power components:
584  for( SCH_SHEET_PATH& sheet : *this )
585  {
586  for( auto item : sheet.LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
587  {
588  auto component = static_cast<SCH_COMPONENT*>( item );
589  LIB_PART* part = component->GetPartRef().get();
590 
591  if( !part || !part->IsPower() )
592  continue;
593 
594  if( part )
595  {
596  SCH_REFERENCE schReference( component, part, sheet );
597  references.AddItem( schReference );
598  }
599  }
600  }
601 
602  // Find duplicate, and silently clear annotation of duplicate
603  std::map<wxString, int> ref_list; // stores the existing references
604 
605  for( unsigned ii = 0; ii< references.GetCount(); ++ii )
606  {
607  wxString curr_ref = references[ii].GetRef();
608 
609  if( ref_list.find( curr_ref ) == ref_list.end() )
610  {
611  ref_list[curr_ref] = ii;
612  continue;
613  }
614 
615  // Possible duplicate, if the ref ends by a number:
616  if( curr_ref.Last() < '0' && curr_ref.Last() > '9' )
617  continue; // not annotated
618 
619  // Duplicate: clear annotation by removing the number ending the ref
620  while( curr_ref.Last() >= '0' && curr_ref.Last() <= '9' )
621  curr_ref.RemoveLast();
622 
623  references[ii].SetRef( curr_ref );
624  }
625 
626 
627  // Break full components reference in name (prefix) and number:
628  // example: IC1 become IC, and 1
629  references.SplitReferences();
630 
631  // Ensure all power symbols have the reference starting by '#'
632  // (No sure this is really useful)
633  for( unsigned ii = 0; ii< references.GetCount(); ++ii )
634  {
635  if( references[ii].GetRef()[0] != '#' )
636  {
637  wxString new_ref = "#" + references[ii].GetRef();
638  references[ii].SetRef( new_ref );
639  }
640  }
641 
642  // Recalculate and update reference numbers in schematic
643  references.Annotate( false, 0, 100, lockedComponents );
644  references.UpdateAnnotation();
645 }
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:162
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 386 of file sch_sheet_path.cpp.

387 {
388  wxCHECK_RET( aSheet != NULL, wxT( "Cannot build sheet list from undefined sheet." ) );
389 
390  std::vector<SCH_SHEET*> badSheets;
391 
392  m_currentSheetPath.push_back( aSheet );
393 
399  m_currentSheetPath.SetPageNumber( size() + 1 );
400  push_back( m_currentSheetPath );
401 
403  {
404  std::vector<SCH_ITEM*> childSheets;
405  m_currentSheetPath.LastScreen()->GetSheets( &childSheets );
406 
407  for( SCH_ITEM* item : childSheets )
408  {
409  auto sheet = static_cast<SCH_SHEET*>( item );
410 
412  sheet->GetFileName(), aSheet->GetFileName() ) )
413  BuildSheetList( sheet );
414  else
415  badSheets.push_back( sheet );
416  }
417  }
418 
419  for( auto sheet : badSheets )
420  {
423  }
424 
426 }
bool Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:245
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:952
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:183
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:186
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 453 of file sch_sheet_path.cpp.

454 {
455  for( const SCH_SHEET_PATH& sheet : *this )
456  {
457  if( sheet.LastScreen() )
458  sheet.LastScreen()->ClrModify();
459  }
460 }
SCH_SHEET_PATH.
SCH_SCREEN * LastScreen()
Function LastScreen.
void ClrModify()
Definition: base_screen.h:184

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

Referenced by SCH_EDIT_FRAME::OnCloseWindow().

◆ 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 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  aMap[ aItem->m_Uuid ] = aItem;
549 
550  if( aItem->Type() == SCH_COMPONENT_T )
551  {
552  SCH_COMPONENT* comp = static_cast<SCH_COMPONENT*>( aItem );
553 
554  for( SCH_FIELD& field : comp->GetFields() )
555  aMap[ field.m_Uuid ] = &field;
556 
557  for( SCH_PIN* pin : comp->GetSchPins() )
558  aMap[ pin->m_Uuid ] = pin;
559  }
560  else if( aItem->Type() == SCH_SHEET_T )
561  {
562  SCH_SHEET* sch_sheet = static_cast<SCH_SHEET*>( aItem );
563 
564  for( SCH_FIELD& field : sch_sheet->GetFields() )
565  aMap[ field.m_Uuid ] = &field;
566 
567  for( SCH_SHEET_PIN* pin : sch_sheet->GetPins() )
568  aMap[ pin->m_Uuid ] = pin;
569  }
570  }
571  }
572 }
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.
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:162
Schematic symbol object.
Definition: sch_component.h:88
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:186
SCH_PIN_PTRS GetSchPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieves a list of the SCH_PINs for the given sheet path.

References SCH_SHEET::GetFields(), SCH_COMPONENT::GetFields(), SCH_SHEET::GetPins(), SCH_COMPONENT::GetSchPins(), 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 728 of file sch_sheet_path.cpp.

729 {
730  for( SCH_SHEET_PATH& sheetpath : *this )
731  {
732  if( sheetpath.LastScreen() == aScreen )
733  return &sheetpath;
734  }
735 
736  return nullptr;
737 }
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 648 of file sch_sheet_path.cpp.

650 {
651  for( const SCH_SHEET_PATH& sheet : *this )
652  sheet.GetComponents( aReferences, aIncludePowerSymbols, aForceIncludeOrphanComponents );
653 }
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(), DIALOG_LABEL_EDITOR::convertReferencesToKIIDs(), DIALOG_FIELDS_EDITOR_GLOBAL::DIALOG_FIELDS_EDITOR_GLOBAL(), 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 463 of file sch_sheet_path.cpp.

464 {
465  for( const SCH_SHEET_PATH& sheet : *this )
466  {
467  SCH_SCREEN* screen = sheet.LastScreen();
468 
469  for( SCH_ITEM* aItem : screen->Items() )
470  {
471  if( aItem->m_Uuid == aID )
472  {
473  if( aPathOut )
474  *aPathOut = sheet;
475 
476  return aItem;
477  }
478  else if( aItem->Type() == SCH_COMPONENT_T )
479  {
480  SCH_COMPONENT* comp = static_cast<SCH_COMPONENT*>( aItem );
481 
482  for( SCH_FIELD& field : comp->GetFields() )
483  {
484  if( field.m_Uuid == aID )
485  {
486  if( aPathOut )
487  *aPathOut = sheet;
488 
489  return &field;
490  }
491  }
492 
493  for( SCH_PIN* pin : comp->GetSchPins() )
494  {
495  if( pin->m_Uuid == aID )
496  {
497  if( aPathOut )
498  *aPathOut = sheet;
499 
500  return pin;
501  }
502  }
503  }
504  else if( aItem->Type() == SCH_SHEET_T )
505  {
506  SCH_SHEET* sch_sheet = static_cast<SCH_SHEET*>( aItem );
507 
508  for( SCH_FIELD& field : sch_sheet->GetFields() )
509  {
510  if( field.m_Uuid == aID )
511  {
512  if( aPathOut )
513  *aPathOut = sheet;
514  return &field;
515  }
516  }
517 
518  for( SCH_SHEET_PIN* pin : sch_sheet->GetPins() )
519  {
520  if( pin->m_Uuid == aID )
521  {
522  if( aPathOut )
523  *aPathOut = sheet;
524 
525  return pin;
526  }
527  }
528  }
529  }
530  }
531 
532  // Not found; weak reference has been deleted.
533  if( !g_DeletedItem )
535 
536  return g_DeletedItem;
537 }
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
DELETED_SHEET_ITEM * g_DeletedItem
A singleton item of this class is returned for a weak reference that no longer exists.
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.
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:162
Schematic symbol object.
Definition: sch_component.h:88
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:186
SCH_PIN_PTRS GetSchPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieves a list of the SCH_PINs for the given sheet path.

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

Referenced by DIALOG_LABEL_EDITOR::convertKIIDsToReferences(), SCH_EDIT_FRAME::FocusOnItem(), SCH_EDIT_FRAME::GetItem(), SCH_TEXT::GetShownText(), and DIALOG_ERC::OnERCItemSelected().

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

658 {
659  for( SCH_SHEET_PATHS::const_iterator it = begin(); it != end(); ++it )
660  {
662  (*it).GetMultiUnitComponents( tempMap );
663 
664  for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : tempMap )
665  {
666  // Merge this list into the main one
667  unsigned n_refs = pair.second.GetCount();
668 
669  for( unsigned thisRef = 0; thisRef < n_refs; ++thisRef )
670  {
671  aRefList[pair.first].AddItem( pair.second[thisRef] );
672  }
673  }
674  }
675 }
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 779 of file sch_sheet_path.cpp.

780 {
781  std::vector<KIID_PATH> paths;
782 
783  for( auto sheetPath : *this )
784  paths.emplace_back( sheetPath.Path() );
785 
786  return paths;
787 }

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

442 {
443  for( const SCH_SHEET_PATH& sheet : *this )
444  {
445  if( sheet.LastScreen() && sheet.LastScreen()->IsModify() )
446  return true;
447  }
448 
449  return false;
450 }
bool IsModify() const
Definition: base_screen.h:187
SCH_SHEET_PATH.
SCH_SCREEN * LastScreen()
Function LastScreen.

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

Referenced by SCH_EDIT_FRAME::IsContentModified(), SCH_EDIT_FRAME::OnCloseWindow(), SCH_EDIT_FRAME::OpenProjectFiles(), and SCH_EDIT_FRAME::ReCreateMenuBar().

◆ NameExists()

bool SCH_SHEET_LIST::NameExists ( const wxString &  aSheetName)

Definition at line 429 of file sch_sheet_path.cpp.

430 {
431  for( const SCH_SHEET_PATH& sheet : *this )
432  {
433  if( sheet.Last()->GetName() == aSheetName )
434  return true;
435  }
436 
437  return false;
438 }
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 790 of file sch_sheet_path.cpp.

791 {
792  wxCHECK( size() == aOldSheetPaths.size(), /* void */ );
793 
794  for( size_t i = 0; i < size(); i++ )
795  {
796  const KIID_PATH oldSheetPath = aOldSheetPaths.at( i );
797  const KIID_PATH newSheetPath = at( i ).Path();
798  SCH_SCREEN* screen = at(i).LastScreen();
799 
800  wxCHECK( screen, /* void */ );
801 
802  for( auto symbol : screen->Items().OfType( SCH_COMPONENT_T ) )
803  {
804  static_cast<SCH_COMPONENT*>( symbol )->ReplaceInstanceSheetPath( oldSheetPath,
805  newSheetPath );
806  }
807  }
808 }
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
EE_RTREE & Items()
Definition: sch_screen.h:162

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

Referenced by SCH_EDIT_FRAME::ConvertTimeStampUuids().

◆ SetComponentFootprint()

bool SCH_SHEET_LIST::SetComponentFootprint ( const wxString &  aReference,
const wxString &  aFootPrint,
bool  aSetVisible 
)

Function SetFootprintField searches all the sheets for a component with aReference and set the footprint field to aFootPrint if found.

Parameters
aReferenceThe reference designator of the component.
aFootPrintThe value to set the footprint field.
aSetVisibleThe value to set the field visibility flag.
Returns
True if aReference was found otherwise false.

Definition at line 678 of file sch_sheet_path.cpp.

680 {
681  bool found = false;
682 
683  for( SCH_SHEET_PATH& sheet : *this )
684  found = sheet.SetComponentFootprint( aReference, aFootPrint, aSetVisible );
685 
686  return found;
687 }
bool SetComponentFootprint(const wxString &aReference, const wxString &aFootPrint, bool aSetVisible)
Function SetFootprintField searches last sheet in the path for a component with aReference and set th...
SCH_SHEET_PATH.

References SCH_SHEET_PATH::SetComponentFootprint().

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

692 {
693  if( empty() )
694  return false;
695 
696  SCHEMATIC* sch = at( 0 ).LastScreen()->Schematic();
697 
698  wxCHECK_MSG( sch, false, "No SCHEMATIC found in SCH_SHEET_LIST::TestForRecursion!" );
699 
700  wxFileName rootFn = sch->GetFileName();
701  wxFileName destFn = aDestFileName;
702 
703  if( destFn.IsRelative() )
704  destFn.MakeAbsolute( rootFn.GetPath() );
705 
706  // Test each SCH_SHEET_PATH in this SCH_SHEET_LIST for potential recursion.
707  for( unsigned i = 0; i < size(); i++ )
708  {
709  // Test each SCH_SHEET_PATH in the source sheet.
710  for( unsigned j = 0; j < aSrcSheetHierarchy.size(); j++ )
711  {
712  const SCH_SHEET_PATH* sheetPath = &aSrcSheetHierarchy[j];
713 
714  for( unsigned k = 0; k < sheetPath->size(); k++ )
715  {
716  if( at( i ).TestForRecursion( sheetPath->GetSheet( k )->GetFileName(),
717  aDestFileName ) )
718  return true;
719  }
720  }
721  }
722 
723  // The source sheet file can safely be added to the destination sheet file.
724  return false;
725 }
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:128
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 740 of file sch_sheet_path.cpp.

742 {
743  SCH_REFERENCE_LIST symbolInstances;
744 
745  GetComponents( symbolInstances, true, true );
746 
747  for( size_t i = 0; i < symbolInstances.GetCount(); i++ )
748  {
749  // The instance paths are stored in the file sans root path so the comparison
750  // should not include the root path.
751  wxString path = symbolInstances[i].GetPath();
752 
753  auto it = std::find_if( aSymbolInstances.begin(), aSymbolInstances.end(),
754  [ path ]( const COMPONENT_INSTANCE_REFERENCE& r ) -> bool
755  {
756  return path == r.m_Path.AsString();
757  }
758  );
759 
760  if( it == aSymbolInstances.end() )
761  {
762  wxLogTrace( traceSchSheetPaths, "No symbol instance found for path \"%s\"", path );
763  continue;
764  }
765 
766  SCH_COMPONENT* symbol = symbolInstances[i].GetComp();
767 
768  wxCHECK2( symbol, continue );
769 
770  // Symbol instance paths are stored and looked up in memory with the root path so use
771  // the full path here.
772  symbol->AddHierarchicalReference( symbolInstances[i].GetSheetPath().Path(),
773  it->m_Reference, it->m_Unit );
774  symbol->GetField( REFERENCE )->SetText( it->m_Reference );
775  }
776 }
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:116
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:88
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit)
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: