38 #include <boost/functional/hash.hpp> 39 #include <wx/filename.h> 56 return _(
"(Deleted Item)" );
61 return wxT(
"DELETED_SHEET_ITEM" );
77 void Move(
const wxPoint& aMoveVector )
override {}
78 void MirrorY(
int aYaxis_position )
override {}
79 void MirrorX(
int aXaxis_position )
override {}
80 void Rotate( wxPoint aPosition )
override {}
83 void Show(
int , std::ostream& )
const override {}
139 if(
size() > aSheetPathToTest.
size() )
142 if(
size() < aSheetPathToTest.
size() )
146 for(
unsigned i = 0; i <
size(); i++ )
198 for(
unsigned i = 1; i <
size(); i++ )
210 path.push_back( sheet->m_Uuid );
220 for(
size_t i = 1; i <
size(); i++ )
221 path.push_back(
at( i )->m_Uuid );
232 if( !
empty() &&
at( 0 )->GetScreen() )
235 wxFileName fn = fileName;
237 if( aUseShortRootName )
240 s = fn.GetName() + wxT(
"/" );
243 for(
unsigned i = 1; i <
size(); i++ )
254 SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
265 bool aForceIncludeOrphanComponents )
const 269 SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
273 if( aIncludePowerSymbols || component->
GetRef(
this )[0] != wxT(
'#' ) )
277 if( part || aForceIncludeOrphanComponents )
282 aReferences.
AddItem( schReference );
290 bool aIncludePowerSymbols )
const 294 auto component = static_cast<SCH_COMPONENT*>( item );
298 if( !aIncludePowerSymbols && component->GetRef(
this )[0] == wxT(
'#' ) )
301 LIB_PART* part = component->GetPartRef().get();
307 wxString reference_str = schReference.
GetRef();
310 if( reference_str[reference_str.Len() - 1] ==
'?' )
313 aRefList[reference_str].AddItem( schReference );
327 auto pair = std::make_pair( aSrcFileName, aDestFileName );
334 wxCHECK_MSG( sch,
false,
"No SCHEMATIC found in SCH_SHEET_PATH::TestForRecursion!" );
337 wxFileName srcFn = aSrcFileName;
338 wxFileName destFn = aDestFileName;
340 if( srcFn.IsRelative() )
341 srcFn.MakeAbsolute( rootFn.GetPath() );
343 if( destFn.IsRelative() )
344 destFn.MakeAbsolute( rootFn.GetPath() );
348 if( srcFn == destFn )
363 if( cmpFn.IsRelative() )
364 cmpFn.MakeAbsolute( rootFn.GetPath() );
367 if( cmpFn == destFn )
375 if( i >=
size() || i == 0 )
389 if( cmpFn.IsRelative() )
390 cmpFn.MakeAbsolute( rootFn.GetPath() );
410 wxCHECK( sheet, wxEmptyString );
438 wxCHECK_RET( aSheet !=
NULL, wxT(
"Cannot build sheet list from undefined sheet." ) );
440 std::vector<SCH_SHEET*> badSheets;
449 std::vector<SCH_ITEM*> childSheets;
454 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
456 if( aCheckIntegrity )
461 badSheets.push_back( sheet );
470 if( aCheckIntegrity )
485 std::sort( begin(), end(),
494 if( aUpdateVirtualPageNums )
496 int virtualPageNum = 1;
548 if( aItem->m_Uuid == aID )
561 if( aChild->
m_Uuid == aID )
588 aMap[ aItem->m_Uuid ] = aItem;
590 aItem->RunOnChildren(
593 aMap[ aChild->
m_Uuid ] = aChild;
613 auto component = static_cast<SCH_COMPONENT*>( item );
614 LIB_PART* part = component->GetPartRef().get();
616 if( !part || !part->
IsPower() )
622 references.
AddItem( schReference );
628 std::map<wxString, int> ref_list;
630 for(
unsigned ii = 0; ii< references.
GetCount(); ++ii )
632 wxString curr_ref = references[ii].GetRef();
634 if( ref_list.find( curr_ref ) == ref_list.end() )
636 ref_list[curr_ref] = ii;
641 if( curr_ref.Last() <
'0' && curr_ref.Last() >
'9' )
645 while( curr_ref.Last() >=
'0' && curr_ref.Last() <=
'9' )
646 curr_ref.RemoveLast();
648 references[ii].SetRef( curr_ref );
658 for(
unsigned ii = 0; ii< references.
GetCount(); ++ii )
660 if( references[ii].GetRef()[0] !=
'#' )
662 wxString new_ref =
"#" + references[ii].GetRef();
663 references[ii].SetRef( new_ref );
668 references.
Annotate(
false, 0, 100, lockedComponents );
674 bool aForceIncludeOrphanComponents )
const 677 sheet.
GetSymbols( aReferences, aIncludePowerSymbols, aForceIncludeOrphanComponents );
682 bool aIncludePowerSymbols )
const 684 for( SCH_SHEET_PATHS::const_iterator it = begin(); it != end(); ++it )
687 (*it).GetMultiUnitComponents( tempMap );
689 for( SCH_MULTI_UNIT_REFERENCE_MAP::value_type& pair : tempMap )
692 unsigned n_refs = pair.second.GetCount();
694 for(
unsigned thisRef = 0; thisRef < n_refs; ++thisRef )
696 aRefList[pair.first].AddItem( pair.second[thisRef] );
704 const wxString& aDestFileName )
709 SCHEMATIC* sch = at( 0 ).LastScreen()->Schematic();
711 wxCHECK_MSG( sch,
false,
"No SCHEMATIC found in SCH_SHEET_LIST::TestForRecursion!" );
714 wxFileName destFn = aDestFileName;
716 if( destFn.IsRelative() )
717 destFn.MakeAbsolute( rootFn.GetPath() );
720 for(
unsigned i = 0; i < size(); i++ )
723 for(
unsigned j = 0; j < aSrcSheetHierarchy.size(); j++ )
727 for(
unsigned k = 0; k < sheetPath->
size(); k++ )
754 const std::vector<SYMBOL_INSTANCE_REFERENCE>& aSymbolInstances )
760 std::map<KIID_PATH, wxString> pathNameCache;
764 auto getName = [&pathNameCache](
const KIID_PATH& aPath ) ->
const wxString&
766 if( pathNameCache.count( aPath ) )
767 return pathNameCache.at( aPath );
769 pathNameCache[aPath] = aPath.AsString();
770 return pathNameCache[aPath];
773 for(
size_t i = 0; i < symbolInstances.
GetCount(); i++ )
777 wxString path = symbolInstances[i].GetPath();
779 auto it = std::find_if( aSymbolInstances.begin(), aSymbolInstances.end(),
782 return path == getName( r.m_Path );
785 if( it == aSymbolInstances.end() )
793 wxCHECK2( symbol,
continue );
798 it->m_Reference, it->m_Unit, it->m_Value,
810 auto it = std::find_if( aSheetInstances.begin(), aSheetInstances.end(),
816 if( it == aSheetInstances.end() )
825 wxCHECK2( sheet,
continue );
835 std::vector<KIID_PATH> paths;
838 paths.emplace_back( sheetPath.
Path() );
846 wxCHECK( size() == aOldSheetPaths.size(), );
848 for(
size_t i = 0; i < size(); i++ )
850 const KIID_PATH oldSheetPath = aOldSheetPaths.at( i );
851 const KIID_PATH newSheetPath = at( i ).Path();
858 static_cast<SCH_COMPONENT*>( symbol )->ReplaceInstanceSheetPath( oldSheetPath,
871 wxCHECK2( sheet,
continue );
893 wxCHECK2( sheet,
continue );
896 tmp.Printf(
"%d", pageNumber );
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
void SetSheetNumber(int aSheetNumber)
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
EE_TYPE OfType(KICAD_T aType) const
const wxChar *const traceSchSheetPaths
Flag to enable debug output of schematic symbol sheet path manipulation code.
bool IsModified()
Check the entire hierarchy for any modifications.
const wxString & GetFileName() const
void initFromOther(const SCH_SHEET_PATH &aOther)
bool Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
void SetPageNumber(const wxString &aPageNumber)
Set the sheet instance user definable page number.
void UpdateUnit(int aUnit)
Change the unit number to aUnit without setting any internal flags.
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_ITEM * GetItem(const KIID &aID, SCH_SHEET_PATH *aPathOut=nullptr)
Fetch a SCH_ITEM by ID.
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
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 li...
Holds all the data relating to one schematic A schematic may consist of one or more sheets (and one r...
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
bool operator==(const SCH_SHEET_PATH &d1) const
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
wxString PathHumanReadable(bool aUseShortRootName=true) const
Return the sheet path in a human readable form made from thesheet names.
the 3d code uses this value
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void AddItem(SCH_REFERENCE &aItem)
void GetSheets(std::vector< SCH_ITEM * > *aItems)
Similar to Items().OfType( SCH_SHEET_T ), but return the sheets in a deterministic order (L-R,...
wxString AsString() const
Template specialization to enable wxStrings for certain containers (e.g. unordered_map)
std::map< std::pair< wxString, wxString >, bool > m_recursion_test_cache
Page numbers are maintained by the sheet load order.
wxString PathAsString() const
Return the path of time stamps which do not changes even when editing sheet parameters.
A singleton item of this class is returned for a weak reference that no longer exists.
static int ComparePageNum(const wxString &aPageNumberA, const wxString aPageNumberB)
Compares page numbers of schematic sheets.
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
void UpdateAllScreenReferences()
Update all the symbol references for this sheet path.
SCH_SCREEN * GetScreen() const
wxString GetClass() const override
Return the class name.
SCH_SHEET_PATH * FindSheetForScreen(SCH_SCREEN *aScreen)
Return a pointer to the first SCH_SHEET_PATH object (not necessarily the only one) using a particular...
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
void UpdateSheetInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
Update all of the sheet instance information using aSheetInstances.
static void hash_combine(std::size_t &seed)
This is a dummy function to take the final case of hash_combine below.
void GetMultiUnitComponents(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 sh...
SCH_REFERENCE_LIST is used to create a flattened list of symbols because in a complex hierarchy,...
void Print(const RENDER_SETTINGS *aSettings, const wxPoint &aOffset) override
Print a schematic item.
Field Value of part, i.e. "3.3K".
void pop_back()
Forwarded method from std::vector.
const wxString GetFootprint(const SCH_SHEET_PATH *sheet, bool aResolve) const
std::vector< SCH_FIELD > & GetFields()
void FillItemMap(std::map< KIID, EDA_ITEM * > &aMap)
Fill an item cache for temporary use when many items need to be fetched.
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction)
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 aSrcSheetHi...
void UpdateAnnotation()
function UpdateAnnotation Updates the symbol references for the schematic project (or the current she...
SCH_SHEET_PATH & operator=(const SCH_SHEET_PATH &aOther)
virtual void SetText(const wxString &aText)
const wxString GetValue(const SCH_SHEET_PATH *sheet, bool aResolve) const
int GetUnitCount() const override
For items with units, return the number of units.
size_t size() const
Forwarded method from std::vector.
SCH_SHEET_PATH m_currentSheetPath
void SetVirtualPageNumber(int aPageNumber)
Set the sheet instance virtual page number.
std::vector< SCH_SHEET * > m_sheets
wxString GetPageNumber() const
size_t operator()(const SCH_SHEET_PATH &path) const
void Rotate(wxPoint aPosition) override
Rotate the item around aPosition 90 degrees in the clockwise direction.
void BuildSheetList(SCH_SHEET *aSheet, bool aCheckIntegrity)
Build the list of sheets and their sheet path from aSheet.
Define a library symbol object.
A simple container for schematic symbol instance infromation.
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.
wxLogTrace helper definitions.
void SetPosition(const wxPoint &) override
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
std::unique_ptr< LIB_PART > & GetPartRef()
wxString GetFileName() const
Return the filename corresponding to this sheet.
void UpdateSymbolInstances(const std::vector< SYMBOL_INSTANCE_REFERENCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
void MirrorX(int aXaxis_position) override
Mirror item relative to the X axis about aXaxis_position.
std::map< wxString, SCH_REFERENCE_LIST > SCH_MULTI_UNIT_REFERENCE_MAP
Container to map reference designators for multi-unit parts.
KIID_PATH PathWithoutRootUuid() const
Get the sheet path as an KIID_PATH without the root sheet UUID prefix.
bool NameExists(const wxString &aSheetName)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Field Name Module PCB, i.e. "16DIP300".
void MirrorY(int aYaxis_position) override
Mirror item relative to the Y axis about aYaxis_position.
unsigned GetCount() const
SCH_FIELD * GetField(int aFieldNdx)
Returns a field in this symbol.
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
A simple container for sheet instance infromation.
const SCH_SHEET * GetSheet(unsigned aIndex) const
SCH_SCREEN * LastScreen()
static DELETED_SHEET_ITEM * GetInstance()
void SplitReferences()
Function SplitReferences attempts to split all reference designators into a name (U) and number (1).
SCHEMATIC * Schematic() const
SCH_SHEET_LIST(SCH_SHEET *aSheet=nullptr, bool aCheckIntegrity=false)
Construct a flattened list of SCH_SHEET_PATH objects from aSheet.
wxString AsString() const
size_t GetCurrentHash() const
SCH_SHEET * at(size_t aIndex) const
Forwarded method from std::vector.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sorts the list of sheets by page number.
std::vector< KIID_PATH > GetPaths() const
void ReplaceLegacySheetPaths(const std::vector< KIID_PATH > &aOldSheetPaths)
Update all of the symbol sheet paths to the sheet paths defined in aOldSheetPaths.
static bool empty(const wxTextEntryBase *aCtrl)
bool empty() const
Forwarded method from std::vector.
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Return the text to display to be used in the selection clarification context menu when multiple items...
void AddHierarchicalReference(const KIID_PATH &aPath, const wxString &aRef, int aUnit, const wxString &aValue=wxEmptyString, const wxString &aFootprint=wxEmptyString)
Add a full hierarchical reference to this symbol.
Definition for part library class.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Field Reference of part, i.e. "IC21".
Base class for any item which can be embedded within the SCHEMATIC container class,...
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...
int Cmp(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare if this is the same sheet path as aSheetPathToTest.
void SetInitialPageNumbers()
Set initial sheet page numbers.
int GetUnitSelection(const SCH_SHEET_PATH *aSheet) const
wxString GetPageNumber(const SCH_SHEET_PATH &aInstance) const
Return the sheet page number for aInstance.
SCH_REFERENCE is used as a helper to define a symbol's reference designator in a schematic.
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.
bool AddInstance(const KIID_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.