|
KiCad PCB EDA Suite
|
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_INFO * | GetSymbolInfo (const wxString &aName) |
| Get symbol info by name. | |
| const SYMBOL_IMPORT_INFO * | GetSymbolInfo (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_INFO > | m_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. | |
Manages the logic for selecting symbols to import from a library file.
This class handles:
The class is designed to be UI-independent for testability.
Definition at line 77 of file symbol_import_manager.h.
| 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.
| symbolName | The name of the symbol to check |
Definition at line 85 of file symbol_import_manager.h.
| SYMBOL_IMPORT_MANAGER::SYMBOL_IMPORT_MANAGER | ( | ) |
Definition at line 24 of file symbol_import_manager.cpp.
| SYMBOL_IMPORT_MANAGER::~SYMBOL_IMPORT_MANAGER | ( | ) |
Definition at line 29 of file symbol_import_manager.cpp.
| void SYMBOL_IMPORT_MANAGER::AddSymbol | ( | const wxString & | aName, |
| const wxString & | aParentName, | ||
| bool | aIsPower, | ||
| LIB_SYMBOL * | aSymbol = nullptr ) |
Add a symbol to the import list.
| aName | Symbol name |
| aParentName | Parent symbol name (empty if not derived) |
| aIsPower | True if this is a power symbol |
| aSymbol | Optional 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().
| 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().
| void SYMBOL_IMPORT_MANAGER::CheckExistingSymbols | ( | SYMBOL_EXISTS_FUNC | aExistsFunc | ) |
Mark symbols that exist in the destination library.
| aExistsFunc | Function 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().
| 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().
| void SYMBOL_IMPORT_MANAGER::DeselectAll | ( | std::function< bool(const wxString &)> | aFilter = nullptr | ) |
Deselect all symbols (optionally filtered).
| aFilter | Optional 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().
| void SYMBOL_IMPORT_MANAGER::DeselectWithDescendants | ( | const wxString & | aSymbolName | ) |
Force deselection of a symbol and all its descendants.
Used after user confirms cascade deselection.
| aSymbolName | Symbol 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().
| std::set< wxString > SYMBOL_IMPORT_MANAGER::GetAncestors | ( | const wxString & | aSymbolName | ) | const |
Get all ancestors of a symbol (full inheritance chain).
| aSymbolName | Name of the symbol |
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().
| 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().
| 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().
| std::set< wxString > SYMBOL_IMPORT_MANAGER::GetDescendants | ( | const wxString & | aSymbolName | ) | const |
Get all descendants of a symbol (all derived symbols recursively).
| aSymbolName | Name of the symbol |
Definition at line 134 of file symbol_import_manager.cpp.
References m_derivativesMap.
Referenced by BOOST_AUTO_TEST_CASE(), DeselectWithDescendants(), and GetSelectedDescendants().
| std::vector< wxString > SYMBOL_IMPORT_MANAGER::GetDirectDerivatives | ( | const wxString & | aSymbolName | ) | const |
Get direct children (derivatives) of a symbol.
| aSymbolName | Name of the symbol |
Definition at line 170 of file symbol_import_manager.cpp.
References m_derivativesMap.
Referenced by BOOST_AUTO_TEST_CASE().
| 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().
| wxString SYMBOL_IMPORT_MANAGER::GetParent | ( | const wxString & | aSymbolName | ) | const |
Get the direct parent of a symbol.
| aSymbolName | Name of the symbol |
Definition at line 163 of file symbol_import_manager.cpp.
References m_parentMap.
Referenced by BOOST_AUTO_TEST_CASE().
| std::vector< wxString > SYMBOL_IMPORT_MANAGER::GetSelectedDescendants | ( | const wxString & | aSymbolName | ) | const |
Get selected descendants that would be orphaned if a symbol is deselected.
| aSymbolName | Symbol to check |
Definition at line 235 of file symbol_import_manager.cpp.
References GetDescendants(), GetSymbolInfo(), and info.
Referenced by BOOST_AUTO_TEST_CASE().
|
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().
| SYMBOL_IMPORT_INFO * SYMBOL_IMPORT_MANAGER::GetSymbolInfo | ( | const wxString & | aName | ) |
Get symbol info by name.
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().
| 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.
| std::vector< wxString > SYMBOL_IMPORT_MANAGER::GetSymbolNames | ( | ) | const |
Get all symbol names.
Definition at line 83 of file symbol_import_manager.cpp.
| 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().
| 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().
|
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().
|
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().
| void SYMBOL_IMPORT_MANAGER::SelectAll | ( | std::function< bool(const wxString &)> | aFilter = nullptr | ) |
Select all symbols (optionally filtered).
| aFilter | Optional 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().
| 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.
| aSymbolName | Symbol to select/deselect |
| aSelected | New selection state |
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().
|
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().
|
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().
|
private |
All symbols available for import, keyed by name.
Definition at line 245 of file symbol_import_manager.h.
Referenced by AddSymbol(), BuildDependencyMaps(), CheckExistingSymbols(), Clear(), DeselectAll(), GetAncestors(), GetAutoSelectionCount(), GetConflicts(), GetManualSelectionCount(), GetSymbolCount(), GetSymbolInfo(), GetSymbolInfo(), GetSymbolNames(), GetSymbolsToImport(), recalculateAutoSelections(), SelectAll(), and SetSymbolSelected().