Add Contains search to SCHEMATIC

This commit is contained in:
Seth Hillbrand 2025-07-25 16:12:22 -07:00
parent fd7abdfdd5
commit 9fff1d955e
2 changed files with 28 additions and 0 deletions

View File

@ -216,6 +216,25 @@ void SCHEMATIC::CacheExistingAnnotation()
}
bool SCHEMATIC::Contains( const SCH_REFERENCE& aRef ) const
{
SCH_SHEET_LIST sheets = Hierarchy();
SCH_REFERENCE_LIST references;
/// TODO(snh): This is horribly inefficient, we should be using refdesTracker for this.
/// REFDES_TRACKER will need to be extended to track if a reference is currently present in the schematic
/// as well as the units. For now, this is relatively fast for reasonably sized schematics
/// Famous last words...
sheets.GetSymbols( references );
return std::any_of( references.begin(), references.end(),
[&]( const SCH_REFERENCE& ref )
{
return ref.GetFullRef( true ) == aRef.GetFullRef( true );
} );
}
void SCHEMATIC::SetRoot( SCH_SHEET* aRootSheet )
{
wxCHECK_RET( aRootSheet, wxS( "Call to SetRoot with null SCH_SHEET!" ) );

View File

@ -39,6 +39,7 @@ class SCH_SCREEN;
class SCH_SHEET;
class SCH_SHEET_LIST;
class SCH_GLOBALLABEL;
class SCH_REFERENCE;
class PROGRESS_REPORTER;
class TOOL_MANAGER;
class PICKED_ITEMS_LIST;
@ -432,6 +433,14 @@ public:
*/
void CacheExistingAnnotation();
/**
* Check if the schematic contains the specified reference.
*
* @param aRef is the reference to check for.
* @return true if the schematic contains the reference, false otherwise.
*/
bool Contains( const SCH_REFERENCE& aRef ) const;
/**
* True if a SCHEMATIC exists, false if not
*/