KiCad PCB EDA Suite
Loading...
Searching...
No Matches
SYMBOL_IMPORT_MANAGER Class Reference

Manages the logic for selecting symbols to import from a library file. More...

#include <symbol_import_manager.h>

Public Types

using SYMBOL_EXISTS_FUNC = std::function<bool( const wxString& symbolName )>
 Callback type for checking if a symbol exists in the destination library.
 

Public Member Functions

 SYMBOL_IMPORT_MANAGER ()
 
 ~SYMBOL_IMPORT_MANAGER ()
 
void Clear ()
 Clear all loaded symbols and reset state.
 
void AddSymbol (const wxString &aName, const wxString &aParentName, bool aIsPower, LIB_SYMBOL *aSymbol=nullptr)
 Add a symbol to the import list.
 
void CheckExistingSymbols (SYMBOL_EXISTS_FUNC aExistsFunc)
 Mark symbols that exist in the destination library.
 
void BuildDependencyMaps ()
 Build the dependency maps from parent relationships.
 
std::vector< wxString > GetSymbolNames () const
 Get all symbol names.
 
SYMBOL_IMPORT_INFOGetSymbolInfo (const wxString &aName)
 Get symbol info by name.
 
const SYMBOL_IMPORT_INFOGetSymbolInfo (const wxString &aName) const
 
std::set< wxString > GetAncestors (const wxString &aSymbolName) const
 Get all ancestors of a symbol (full inheritance chain).
 
std::set< wxString > GetDescendants (const wxString &aSymbolName) const
 Get all descendants of a symbol (all derived symbols recursively).
 
wxString GetParent (const wxString &aSymbolName) const
 Get the direct parent of a symbol.
 
std::vector< wxString > GetDirectDerivatives (const wxString &aSymbolName) const
 Get direct children (derivatives) of a symbol.
 
bool IsDerived (const wxString &aSymbolName) const
 Check if a symbol is derived from another.
 
std::vector< wxString > SetSymbolSelected (const wxString &aSymbolName, bool aSelected)
 Set the selection state of a symbol.
 
std::vector< wxString > GetSelectedDescendants (const wxString &aSymbolName) const
 Get selected descendants that would be orphaned if a symbol is deselected.
 
void DeselectWithDescendants (const wxString &aSymbolName)
 Force deselection of a symbol and all its descendants.
 
void SelectAll (std::function< bool(const wxString &)> aFilter=nullptr)
 Select all symbols (optionally filtered).
 
void DeselectAll (std::function< bool(const wxString &)> aFilter=nullptr)
 Deselect all symbols (optionally filtered).
 
std::vector< wxString > GetSymbolsToImport () const
 Get list of all symbols that will be imported (checked + auto-selected).
 
int GetManualSelectionCount () const
 Get count of manually selected symbols.
 
int GetAutoSelectionCount () const
 Get count of auto-selected symbols (dependencies).
 
std::vector< wxString > GetConflicts () const
 Get list of symbols that will conflict (selected and exist in destination).
 
size_t GetSymbolCount () const
 Get total number of symbols.
 

Static Public Member Functions

static bool MatchesFilter (const wxString &aSymbolName, const wxString &aFilter)
 Check if a symbol name matches a filter string (case-insensitive contains).
 

Private Member Functions

void recalculateAutoSelections ()
 Recalculate auto-selection state for all symbols based on current manual selections.
 

Private Attributes

std::map< wxString, SYMBOL_IMPORT_INFOm_symbols
 All symbols available for import, keyed by name.
 
std::map< wxString, wxString > m_parentMap
 Map from symbol name to its parent name (for derived symbols)
 
std::map< wxString, std::vector< wxString > > m_derivativesMap
 Map from parent name to list of direct derivative names.
 

Detailed Description

Manages the logic for selecting symbols to import from a library file.

This class handles:

  • Loading and tracking symbol metadata from source libraries
  • Building dependency graphs for derived symbols
  • Auto-selecting parent symbols when derived symbols are selected
  • Tracking conflicts with existing symbols in destination library
  • Filtering symbols by search criteria

The class is designed to be UI-independent for testability.

Definition at line 77 of file symbol_import_manager.h.

Member Typedef Documentation

◆ SYMBOL_EXISTS_FUNC

using SYMBOL_IMPORT_MANAGER::SYMBOL_EXISTS_FUNC = std::function<bool( const wxString& symbolName )>

Callback type for checking if a symbol exists in the destination library.

Parameters
symbolNameThe name of the symbol to check
Returns
true if the symbol already exists

Definition at line 85 of file symbol_import_manager.h.

Constructor & Destructor Documentation

◆ SYMBOL_IMPORT_MANAGER()

SYMBOL_IMPORT_MANAGER::SYMBOL_IMPORT_MANAGER ( )

Definition at line 24 of file symbol_import_manager.cpp.

◆ ~SYMBOL_IMPORT_MANAGER()

SYMBOL_IMPORT_MANAGER::~SYMBOL_IMPORT_MANAGER ( )

Definition at line 29 of file symbol_import_manager.cpp.

Member Function Documentation

◆ AddSymbol()

void SYMBOL_IMPORT_MANAGER::AddSymbol ( const wxString & aName,
const wxString & aParentName,
bool aIsPower,
LIB_SYMBOL * aSymbol = nullptr )

Add a symbol to the import list.

Parameters
aNameSymbol name
aParentNameParent symbol name (empty if not derived)
aIsPowerTrue if this is a power symbol
aSymbolOptional loaded symbol (takes ownership)

Definition at line 42 of file symbol_import_manager.cpp.

References info, and m_symbols.

Referenced by TEST_SYMBOL_IMPORT_MANAGER_FIXTURE::LoadKiCadLibraryHelper(), and TEST_SYMBOL_IMPORT_MANAGER_FIXTURE::LoadLegacyLibraryHelper().

◆ BuildDependencyMaps()

void SYMBOL_IMPORT_MANAGER::BuildDependencyMaps ( )

Build the dependency maps from parent relationships.

Call this after all symbols have been added.

Definition at line 67 of file symbol_import_manager.cpp.

References info, m_derivativesMap, m_parentMap, m_symbols, and name.

Referenced by TEST_SYMBOL_IMPORT_MANAGER_FIXTURE::LoadKiCadLibraryHelper(), and TEST_SYMBOL_IMPORT_MANAGER_FIXTURE::LoadLegacyLibraryHelper().

◆ CheckExistingSymbols()

void SYMBOL_IMPORT_MANAGER::CheckExistingSymbols ( SYMBOL_EXISTS_FUNC aExistsFunc)

Mark symbols that exist in the destination library.

Parameters
aExistsFuncFunction to check if a symbol exists in destination

Definition at line 58 of file symbol_import_manager.cpp.

References info, m_symbols, and name.

Referenced by BOOST_AUTO_TEST_CASE().

◆ Clear()

void SYMBOL_IMPORT_MANAGER::Clear ( )

Clear all loaded symbols and reset state.

Definition at line 34 of file symbol_import_manager.cpp.

References m_derivativesMap, m_parentMap, and m_symbols.

Referenced by BOOST_AUTO_TEST_CASE().

◆ DeselectAll()

void SYMBOL_IMPORT_MANAGER::DeselectAll ( std::function< bool(const wxString &)> aFilter = nullptr)

Deselect all symbols (optionally filtered).

Parameters
aFilterOptional filter function - only deselect symbols where filter returns true

Definition at line 294 of file symbol_import_manager.cpp.

References info, m_symbols, name, and recalculateAutoSelections().

Referenced by BOOST_AUTO_TEST_CASE().

◆ DeselectWithDescendants()

void SYMBOL_IMPORT_MANAGER::DeselectWithDescendants ( const wxString & aSymbolName)

Force deselection of a symbol and all its descendants.

Used after user confirms cascade deselection.

Parameters
aSymbolNameSymbol to deselect along with descendants

Definition at line 252 of file symbol_import_manager.cpp.

References GetDescendants(), GetSymbolInfo(), info, SYMBOL_IMPORT_INFO::m_autoSelected, SYMBOL_IMPORT_INFO::m_checked, and recalculateAutoSelections().

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetAncestors()

std::set< wxString > SYMBOL_IMPORT_MANAGER::GetAncestors ( const wxString & aSymbolName) const

Get all ancestors of a symbol (full inheritance chain).

Parameters
aSymbolNameName of the symbol
Returns
Set of ancestor symbol names (may be empty)

Definition at line 109 of file symbol_import_manager.cpp.

References m_parentMap, and m_symbols.

Referenced by BOOST_AUTO_TEST_CASE(), recalculateAutoSelections(), and SetSymbolSelected().

◆ GetAutoSelectionCount()

int SYMBOL_IMPORT_MANAGER::GetAutoSelectionCount ( ) const

Get count of auto-selected symbols (dependencies).

Definition at line 337 of file symbol_import_manager.cpp.

References info, m_symbols, and name.

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ GetConflicts()

std::vector< wxString > SYMBOL_IMPORT_MANAGER::GetConflicts ( ) const

Get list of symbols that will conflict (selected and exist in destination).

Definition at line 351 of file symbol_import_manager.cpp.

References info, m_symbols, and name.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetDescendants()

std::set< wxString > SYMBOL_IMPORT_MANAGER::GetDescendants ( const wxString & aSymbolName) const

Get all descendants of a symbol (all derived symbols recursively).

Parameters
aSymbolNameName of the symbol
Returns
Set of descendant symbol names (may be empty)

Definition at line 134 of file symbol_import_manager.cpp.

References m_derivativesMap.

Referenced by BOOST_AUTO_TEST_CASE(), DeselectWithDescendants(), and GetSelectedDescendants().

◆ GetDirectDerivatives()

std::vector< wxString > SYMBOL_IMPORT_MANAGER::GetDirectDerivatives ( const wxString & aSymbolName) const

Get direct children (derivatives) of a symbol.

Parameters
aSymbolNameName of the symbol
Returns
Vector of direct derivative names

Definition at line 170 of file symbol_import_manager.cpp.

References m_derivativesMap.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetManualSelectionCount()

int SYMBOL_IMPORT_MANAGER::GetManualSelectionCount ( ) const

Get count of manually selected symbols.

Definition at line 323 of file symbol_import_manager.cpp.

References info, m_symbols, and name.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ GetParent()

wxString SYMBOL_IMPORT_MANAGER::GetParent ( const wxString & aSymbolName) const

Get the direct parent of a symbol.

Parameters
aSymbolNameName of the symbol
Returns
Parent name or empty string if none

Definition at line 163 of file symbol_import_manager.cpp.

References m_parentMap.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetSelectedDescendants()

std::vector< wxString > SYMBOL_IMPORT_MANAGER::GetSelectedDescendants ( const wxString & aSymbolName) const

Get selected descendants that would be orphaned if a symbol is deselected.

Parameters
aSymbolNameSymbol to check
Returns
Vector of selected descendant names that depend on this symbol

Definition at line 235 of file symbol_import_manager.cpp.

References GetDescendants(), GetSymbolInfo(), and info.

Referenced by BOOST_AUTO_TEST_CASE().

◆ GetSymbolCount()

size_t SYMBOL_IMPORT_MANAGER::GetSymbolCount ( ) const
inline

Get total number of symbols.

Definition at line 236 of file symbol_import_manager.h.

References m_symbols.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ GetSymbolInfo() [1/2]

SYMBOL_IMPORT_INFO * SYMBOL_IMPORT_MANAGER::GetSymbolInfo ( const wxString & aName)

Get symbol info by name.

Returns
Pointer to info or nullptr if not found

Definition at line 95 of file symbol_import_manager.cpp.

References m_symbols.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), DeselectWithDescendants(), GetSelectedDescendants(), recalculateAutoSelections(), and SetSymbolSelected().

◆ GetSymbolInfo() [2/2]

const SYMBOL_IMPORT_INFO * SYMBOL_IMPORT_MANAGER::GetSymbolInfo ( const wxString & aName) const

Definition at line 102 of file symbol_import_manager.cpp.

References m_symbols.

◆ GetSymbolNames()

std::vector< wxString > SYMBOL_IMPORT_MANAGER::GetSymbolNames ( ) const

Get all symbol names.

Definition at line 83 of file symbol_import_manager.cpp.

References info, m_symbols, and name.

◆ GetSymbolsToImport()

std::vector< wxString > SYMBOL_IMPORT_MANAGER::GetSymbolsToImport ( ) const

Get list of all symbols that will be imported (checked + auto-selected).

Definition at line 309 of file symbol_import_manager.cpp.

References info, m_symbols, name, and result.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ IsDerived()

bool SYMBOL_IMPORT_MANAGER::IsDerived ( const wxString & aSymbolName) const

Check if a symbol is derived from another.

Definition at line 181 of file symbol_import_manager.cpp.

References m_parentMap.

Referenced by BOOST_AUTO_TEST_CASE().

◆ MatchesFilter()

bool SYMBOL_IMPORT_MANAGER::MatchesFilter ( const wxString & aSymbolName,
const wxString & aFilter )
static

Check if a symbol name matches a filter string (case-insensitive contains).

Definition at line 365 of file symbol_import_manager.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), and DIALOG_IMPORT_SYMBOL_SELECT::matchesFilter().

◆ recalculateAutoSelections()

void SYMBOL_IMPORT_MANAGER::recalculateAutoSelections ( )
private

Recalculate auto-selection state for all symbols based on current manual selections.

Definition at line 374 of file symbol_import_manager.cpp.

References GetAncestors(), GetSymbolInfo(), info, SYMBOL_IMPORT_INFO::m_autoSelected, SYMBOL_IMPORT_INFO::m_checked, m_symbols, and name.

Referenced by DeselectAll(), DeselectWithDescendants(), SelectAll(), and SetSymbolSelected().

◆ SelectAll()

void SYMBOL_IMPORT_MANAGER::SelectAll ( std::function< bool(const wxString &)> aFilter = nullptr)

Select all symbols (optionally filtered).

Parameters
aFilterOptional filter function - only select symbols where filter returns true

Definition at line 279 of file symbol_import_manager.cpp.

References info, m_symbols, name, and recalculateAutoSelections().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ SetSymbolSelected()

std::vector< wxString > SYMBOL_IMPORT_MANAGER::SetSymbolSelected ( const wxString & aSymbolName,
bool aSelected )

Set the selection state of a symbol.

This handles auto-selection of ancestors.

Parameters
aSymbolNameSymbol to select/deselect
aSelectedNew selection state
Returns
Vector of symbol names whose auto-selection state changed

Definition at line 188 of file symbol_import_manager.cpp.

References GetAncestors(), GetSymbolInfo(), info, SYMBOL_IMPORT_INFO::m_autoSelected, SYMBOL_IMPORT_INFO::m_checked, m_symbols, name, and recalculateAutoSelections().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

Member Data Documentation

◆ m_derivativesMap

std::map<wxString, std::vector<wxString> > SYMBOL_IMPORT_MANAGER::m_derivativesMap
private

Map from parent name to list of direct derivative names.

Definition at line 251 of file symbol_import_manager.h.

Referenced by BuildDependencyMaps(), Clear(), GetDescendants(), and GetDirectDerivatives().

◆ m_parentMap

std::map<wxString, wxString> SYMBOL_IMPORT_MANAGER::m_parentMap
private

Map from symbol name to its parent name (for derived symbols)

Definition at line 248 of file symbol_import_manager.h.

Referenced by BuildDependencyMaps(), Clear(), GetAncestors(), GetParent(), and IsDerived().

◆ m_symbols


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