KiCad PCB EDA Suite
SCH_SHEET_LIST Class Reference

Class 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 ()
 
SCH_SHEET_PATHGetSheetByPath (const wxString aPath, bool aHumanReadable=true)
 Function GetSheetByPath returns a sheet matching the path name in aPath. More...
 
bool IsModified ()
 Function IsModified checks the entire hierarchy for any modifications. More...
 
bool IsAutoSaveRequired ()
 Function IsAutoSaveRequired checks the entire hierarchy for any modifications that require auto save. More...
 
void ClearModifyStatus ()
 
void AnnotatePowerSymbols (PART_LIBS *aLib)
 Function AnnotatePowerSymbols clear and annotates the entire hierarchy of the sheet path list. More...
 
void GetComponents (PART_LIBS *aLibs, SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true)
 Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the list of sheets. More...
 
void GetMultiUnitComponents (PART_LIBS *aLibs, SCH_MULTI_UNIT_REFERENCE_MAP &aRefList, bool aIncludePowerSymbols=true)
 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...
 
SCH_ITEMFindNextItem (KICAD_T aType, SCH_SHEET_PATH **aSheetFound=NULL, SCH_ITEM *aLastItem=NULL, bool aWrap=true)
 Function FindNextItem searches the entire schematic for the next schematic object. More...
 
SCH_ITEMFindPreviousItem (KICAD_T aType, SCH_SHEET_PATH **aSheetFound=NULL, SCH_ITEM *aLastItem=NULL, bool aWrap=true)
 Function FindPreviousItem searches the entire schematic for the previous schematic item. 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 IsComplexHierarchy () const
 Function IsComplexHierarchy searches all of the sheets for duplicate files names which indicates a complex hierarchy. More...
 
bool TestForRecursion (const SCH_SHEET_LIST &aSrcSheetHierarchy, const wxString &aDestFileName) const
 Function TestForRecursion. More...
 
SCH_SHEETFindSheetByName (const wxString &aSheetName)
 Function FindSheetByName. More...
 
void BuildSheetList (SCH_SHEET *aSheet)
 Function BuildSheetList builds the list of sheets and their sheet path from aSheet. More...
 

Private Attributes

bool m_isRootSheet
 
SCH_SHEET_PATH m_currentSheetPath
 

Detailed Description

Class 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 334 of file sch_sheet_path.h.

Constructor & Destructor Documentation

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

References BuildSheetList(), and m_isRootSheet.

468 {
469  m_isRootSheet = false;
470 
471  if( aSheet != NULL )
472  BuildSheetList( aSheet );
473 }
void BuildSheetList(SCH_SHEET *aSheet)
Function BuildSheetList builds the list of sheets and their sheet path from aSheet.
SCH_SHEET_LIST::~SCH_SHEET_LIST ( )
inline

Definition at line 350 of file sch_sheet_path.h.

350 {}

Member Function Documentation

void SCH_SHEET_LIST::AnnotatePowerSymbols ( PART_LIBS aLib)

Function AnnotatePowerSymbols clear and annotates the entire hierarchy of the sheet path list.

Parameters
aLibthe library list to use

Definition at line 563 of file sch_sheet_path.cpp.

Referenced by SCH_EDIT_FRAME::prepareForNetlist(), and DIALOG_ERC::TestErc().

564 {
565  int ref = 1;
566 
567  for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
568  (*it).AnnotatePowerSymbols( aLibs, &ref );
569 }
SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER
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 492 of file sch_sheet_path.cpp.

References g_RootSheet, SCH_SHEET::GetScreen(), SCH_SHEET_PATH::LastDrawList(), m_currentSheetPath, m_isRootSheet, EDA_ITEM::Next(), SCH_SHEET_T, SCH_SHEET_PATH::SetPageNumber(), and EDA_ITEM::Type().

Referenced by DIALOG_PLOT_SCHEMATIC::CreateDXFFile(), DIALOG_PLOT_SCHEMATIC::createHPGLFile(), DIALOG_PLOT_SCHEMATIC::createPDFFile(), DIALOG_PLOT_SCHEMATIC::createPSFile(), DIALOG_PLOT_SCHEMATIC::createSVGFile(), SCH_EDIT_FRAME::FindComponentAndItem(), and SCH_SHEET_LIST().

493 {
494  wxCHECK_RET( aSheet != NULL, wxT( "Cannot build sheet list from undefined sheet." ) );
495 
496  if( aSheet == g_RootSheet )
497  m_isRootSheet = true;
498 
499  m_currentSheetPath.push_back( aSheet );
500 
506  m_currentSheetPath.SetPageNumber( size() + 1 );
507  push_back( m_currentSheetPath );
508 
509  if( aSheet->GetScreen() )
510  {
512 
513  while( item )
514  {
515  if( item->Type() == SCH_SHEET_T )
516  {
517  SCH_SHEET* sheet = (SCH_SHEET*) item;
518  BuildSheetList( sheet );
519  }
520 
521  item = item->Next();
522  }
523  }
524 
525  m_currentSheetPath.pop_back();
526 }
SCH_ITEM * LastDrawList() const
Function LastDrawList.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
void SetPageNumber(int aPageNumber)
EDA_ITEM * Next() const
Definition: base_struct.h:206
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:286
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
SCH_SHEET_PATH m_currentSheetPath
void BuildSheetList(SCH_SHEET *aSheet)
Function BuildSheetList builds the list of sheets and their sheet path from aSheet.
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
void SCH_SHEET_LIST::ClearModifyStatus ( )

Definition at line 553 of file sch_sheet_path.cpp.

Referenced by SCH_EDIT_FRAME::OnCloseWindow().

554 {
555  for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
556  {
557  if( (*it).LastScreen() )
558  (*it).LastScreen()->ClrModify();
559  }
560 }
SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER
SCH_ITEM * SCH_SHEET_LIST::FindNextItem ( KICAD_T  aType,
SCH_SHEET_PATH **  aSheetFound = NULL,
SCH_ITEM aLastItem = NULL,
bool  aWrap = true 
)

Function FindNextItem searches the entire schematic for the next schematic object.

Parameters
aType- The type of schematic item to find.
aSheetFound- The sheet the item was found in. NULL if the next item is not found.
aLastItem- Find next item after aLastItem if not NULL.
aWrap- Wrap past around the end of the list of sheets.
Returns
If found, Returns the next schematic item. Otherwise, returns NULL.

Definition at line 602 of file sch_sheet_path.cpp.

References SCH_ITEM::Next(), and EDA_ITEM::Type().

Referenced by SCH_EDIT_FRAME::OnFindDrcMarker().

604 {
605  bool hasWrapped = false;
606  bool firstItemFound = false;
607 
608  SCH_ITEM* drawItem = NULL;
609  SCH_SHEET_PATHS_ITER it = begin();
610 
611  while( it != end() )
612  {
613  drawItem = (*it).LastDrawList();
614 
615  while( drawItem )
616  {
617  if( drawItem->Type() == aType )
618  {
619  if( aLastItem == NULL || firstItemFound )
620  {
621  if( aSheetFoundIn )
622  *aSheetFoundIn = &(*it);
623 
624  return drawItem;
625  }
626  else if( !firstItemFound && drawItem == aLastItem )
627  {
628  firstItemFound = true;
629  }
630  }
631 
632  drawItem = drawItem->Next();
633  }
634 
635  ++it;
636 
637  if( it == end() && aLastItem && aWrap && !hasWrapped )
638  {
639  hasWrapped = true;
640  it = begin();
641  }
642  }
643 
644  return NULL;
645 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER
SCH_ITEM * Next() const
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
SCH_ITEM * SCH_SHEET_LIST::FindPreviousItem ( KICAD_T  aType,
SCH_SHEET_PATH **  aSheetFound = NULL,
SCH_ITEM aLastItem = NULL,
bool  aWrap = true 
)

Function FindPreviousItem searches the entire schematic for the previous schematic item.

Parameters
aType- The type of schematic item to find.
aSheetFound- The sheet the item was found in. NULL if the previous item is not found.
aLastItem- Find the previous item before aLastItem if not NULL.
aWrap- Wrap past around the beginning of the list of sheets.
Returns
If found, the previous schematic item. Otherwise, NULL.

Definition at line 648 of file sch_sheet_path.cpp.

References SCH_ITEM::Back(), and EDA_ITEM::Type().

650 {
651  bool hasWrapped = false;
652  bool firstItemFound = false;
653  SCH_ITEM* drawItem = NULL;
654  SCH_SHEET_PATHS_RITER it = rbegin();
655 
656  while( it != rend() )
657  {
658  drawItem = (*it).FirstDrawList();
659 
660  while( drawItem )
661  {
662  if( drawItem->Type() == aType )
663  {
664  if( aLastItem == NULL || firstItemFound )
665  {
666  if( aSheetFoundIn )
667  *aSheetFoundIn = &(*it);
668 
669  return drawItem;
670  }
671  else if( !firstItemFound && drawItem == aLastItem )
672  {
673  firstItemFound = true;
674  }
675  }
676 
677  drawItem = drawItem->Back();
678  }
679 
680  ++it;
681 
682  if( it == rend() && aLastItem && aWrap && !hasWrapped )
683  {
684  hasWrapped = true;
685  it = rbegin();
686  }
687  }
688 
689  return NULL;
690 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
SCH_ITEM * Back() const
SCH_SHEET_PATHS::reverse_iterator SCH_SHEET_PATHS_RITER
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
SCH_SHEET * SCH_SHEET_LIST::FindSheetByName ( const wxString &  aSheetName)

Function FindSheetByName.

searches the entire SCH_SHEET_LIST for a sheet named aSheetName.

Parameters
aSheetNameis the name of the sheet to find.
Returns
a pointer to the sheet named aSheetName if found or NULL if not found.

Definition at line 758 of file sch_sheet_path.cpp.

Referenced by SCH_EDIT_FRAME::EditSheet().

759 {
760  for( unsigned i = 0; i < size(); i++ )
761  {
762  SCH_SHEET* sheet = at( i ).FindSheetByName( aSheetName );
763 
764  if( sheet )
765  return sheet;
766  }
767 
768  return NULL;
769 }
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
void SCH_SHEET_LIST::GetComponents ( PART_LIBS aLibs,
SCH_REFERENCE_LIST aReferences,
bool  aIncludePowerSymbols = true 
)

Function GetComponents adds a SCH_REFERENCE() object to aReferences for each component in the list of sheets.

Parameters
aLibsthe library list to use
aReferencesList of references to populate.
aIncludePowerSymbolsSet to false to only get normal components.

Definition at line 572 of file sch_sheet_path.cpp.

Referenced by SCH_EDIT_FRAME::AnnotateComponents(), SCH_EDIT_FRAME::backAnnotateFootprints(), SCH_EDIT_FRAME::CheckAnnotate(), and SCH_EDIT_FRAME::ProcessCmpToFootprintLinkFile().

574 {
575  for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
576  (*it).GetComponents( aLibs, aReferences, aIncludePowerSymbols );
577 }
SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER
void SCH_SHEET_LIST::GetMultiUnitComponents ( PART_LIBS aLibs,
SCH_MULTI_UNIT_REFERENCE_MAP aRefList,
bool  aIncludePowerSymbols = true 
)

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
aLibsthe library list to use
aRefListMap of reference designators to reference lists
aIncludePowerSymbolsSet to false to only get normal components.

Definition at line 579 of file sch_sheet_path.cpp.

Referenced by SCH_EDIT_FRAME::AnnotateComponents().

582 {
583  for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
584  {
586  (*it).GetMultiUnitComponents( aLibs, tempMap );
587 
588  for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : tempMap )
589  {
590  // Merge this list into the main one
591  unsigned n_refs = pair.second.GetCount();
592 
593  for( unsigned thisRef = 0; thisRef < n_refs; ++thisRef )
594  {
595  aRefList[pair.first].AddItem( pair.second[thisRef] );
596  }
597  }
598  }
599 }
SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER
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...
SCH_SHEET_PATH * SCH_SHEET_LIST::GetSheetByPath ( const wxString  aPath,
bool  aHumanReadable = true 
)

Function GetSheetByPath returns a sheet matching the path name in aPath.

Parameters
aPathA wxString object containing path of the sheet to get.
aHumanReadableTrue uses the human readable path for comparison. False uses the timestamp generated path.
Returns
The sheet that matches aPath or NULL if no sheet matching aPath is found.

Definition at line 476 of file sch_sheet_path.cpp.

References SCH_SHEET_PATH::PathHumanReadable().

Referenced by SCH_EDIT_FRAME::OnFindReplace(), and SCH_EDIT_FRAME::updateFindReplaceView().

477 {
478  wxString sheetPath;
479 
480  for( unsigned i = 0; i < size(); i++ )
481  {
482  sheetPath = ( aHumanReadable ) ? at( i ).PathHumanReadable() : at( i ).Path();
483 
484  if( sheetPath == aPath )
485  return &at( i );
486  }
487 
488  return NULL;
489 }
bool SCH_SHEET_LIST::IsAutoSaveRequired ( )

Function IsAutoSaveRequired checks the entire hierarchy for any modifications that require auto save.

Returns
True if the hierarchy is modified otherwise false.

Definition at line 541 of file sch_sheet_path.cpp.

Referenced by SCH_EDIT_FRAME::isAutoSaveRequired().

542 {
543  for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
544  {
545  if( (*it).LastScreen() && (*it).LastScreen()->IsSave() )
546  return true;
547  }
548 
549  return false;
550 }
SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER
bool SCH_SHEET_LIST::IsComplexHierarchy ( ) const

Function IsComplexHierarchy searches all of the sheets for duplicate files names which indicates a complex hierarchy.

Returns
true if the SCH_SHEET_LIST is a complex hierarchy.

Definition at line 705 of file sch_sheet_path.cpp.

706 {
707  wxString fileName;
708 
709  for( unsigned i = 0; i < size(); i++ )
710  {
711  fileName = at( i ).Last()->GetFileName();
712 
713  for( unsigned j = 0; j < size(); j++ )
714  {
715  if( i == j )
716  continue;
717 
718  if( fileName == at( j ).Last()->GetFileName() )
719  return true;
720  }
721  }
722 
723  return false;
724 }
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 529 of file sch_sheet_path.cpp.

Referenced by SCH_EDIT_FRAME::OnCloseWindow(), and SCH_EDIT_FRAME::OnUpdateSave().

530 {
531  for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
532  {
533  if( (*it).LastScreen() && (*it).LastScreen()->IsModify() )
534  return true;
535  }
536 
537  return false;
538 }
SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER
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 693 of file sch_sheet_path.cpp.

695 {
696  bool found = false;
697 
698  for( SCH_SHEET_PATHS_ITER it = begin(); it != end(); ++it )
699  found = (*it).SetComponentFootprint( aReference, aFootPrint, aSetVisible );
700 
701  return found;
702 }
SCH_SHEET_PATHS::iterator SCH_SHEET_PATHS_ITER
bool SCH_SHEET_LIST::TestForRecursion ( const SCH_SHEET_LIST aSrcSheetHierarchy,
const wxString &  aDestFileName 
) const

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

References g_RootSheet, SCH_SHEET::GetFileName(), and SCH_SHEET_PATH::GetSheet().

Referenced by SCH_EDIT_FRAME::EditSheet(), and SCH_EDIT_FRAME::PasteListOfItems().

729 {
730  wxFileName rootFn = g_RootSheet->GetFileName();
731  wxFileName destFn = aDestFileName;
732 
733  if( destFn.IsRelative() )
734  destFn.MakeAbsolute( rootFn.GetPath() );
735 
736  // Test each SCH_SHEET_PATH in this SCH_SHEET_LIST for potential recursion.
737  for( unsigned i = 0; i < size(); i++ )
738  {
739  // Test each SCH_SHEET_PATH in the source sheet.
740  for( unsigned j = 0; j < aSrcSheetHierarchy.size(); j++ )
741  {
742  const SCH_SHEET_PATH* sheetPath = &aSrcSheetHierarchy[j];
743 
744  for( unsigned k = 0; k < sheetPath->size(); k++ )
745  {
746  if( at( i ).TestForRecursion( sheetPath->GetSheet( k )->GetFileName(),
747  aDestFileName ) )
748  return true;
749  }
750  }
751  }
752 
753  // The source sheet file can safely be added to the destination sheet file.
754  return false;
755 }
const SCH_SHEET * GetSheet(unsigned aIndex) const
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
Class SCH_SHEET_PATH.
wxString GetFileName(void) const
Function GetFileName return the filename corresponding to this sheet.
Definition: sch_sheet.cpp:849

Member Data Documentation

SCH_SHEET_PATH SCH_SHEET_LIST::m_currentSheetPath
private

Definition at line 338 of file sch_sheet_path.h.

Referenced by BuildSheetList().

bool SCH_SHEET_LIST::m_isRootSheet
private

Definition at line 337 of file sch_sheet_path.h.

Referenced by BuildSheetList(), and SCH_SHEET_LIST().


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