KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_import_manager.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <functional>
23#include <map>
24#include <memory>
25#include <set>
26#include <vector>
27#include <wx/string.h>
28
29class LIB_SYMBOL;
30
31
36{
37 wxString m_name;
38 std::unique_ptr<LIB_SYMBOL> m_symbol;
39 wxString m_parentName;
40 bool m_isPower;
42 bool m_checked;
44
46 m_isPower( false ),
47 m_existsInDest( false ),
48 m_checked( false ),
49 m_autoSelected( false )
50 {
51 }
52};
53
54
63
64
78{
79public:
85 using SYMBOL_EXISTS_FUNC = std::function<bool( const wxString& symbolName )>;
86
89
93 void Clear();
94
103 void AddSymbol( const wxString& aName, const wxString& aParentName, bool aIsPower,
104 LIB_SYMBOL* aSymbol = nullptr );
105
111 void CheckExistingSymbols( SYMBOL_EXISTS_FUNC aExistsFunc );
112
117 void BuildDependencyMaps();
118
122 std::vector<wxString> GetSymbolNames() const;
123
128 SYMBOL_IMPORT_INFO* GetSymbolInfo( const wxString& aName );
129 const SYMBOL_IMPORT_INFO* GetSymbolInfo( const wxString& aName ) const;
130
137 std::set<wxString> GetAncestors( const wxString& aSymbolName ) const;
138
145 std::set<wxString> GetDescendants( const wxString& aSymbolName ) const;
146
153 wxString GetParent( const wxString& aSymbolName ) const;
154
161 std::vector<wxString> GetDirectDerivatives( const wxString& aSymbolName ) const;
162
166 bool IsDerived( const wxString& aSymbolName ) const;
167
176 std::vector<wxString> SetSymbolSelected( const wxString& aSymbolName, bool aSelected );
177
184 std::vector<wxString> GetSelectedDescendants( const wxString& aSymbolName ) const;
185
192 void DeselectWithDescendants( const wxString& aSymbolName );
193
199 void SelectAll( std::function<bool( const wxString& )> aFilter = nullptr );
200
206 void DeselectAll( std::function<bool( const wxString& )> aFilter = nullptr );
207
211 std::vector<wxString> GetSymbolsToImport() const;
212
216 int GetManualSelectionCount() const;
217
221 int GetAutoSelectionCount() const;
222
226 std::vector<wxString> GetConflicts() const;
227
231 static bool MatchesFilter( const wxString& aSymbolName, const wxString& aFilter );
232
236 size_t GetSymbolCount() const { return m_symbols.size(); }
237
238private:
243
245 std::map<wxString, SYMBOL_IMPORT_INFO> m_symbols;
246
248 std::map<wxString, wxString> m_parentMap;
249
251 std::map<wxString, std::vector<wxString>> m_derivativesMap;
252};
Define a library symbol object.
Definition lib_symbol.h:83
std::function< bool(const wxString &symbolName)> SYMBOL_EXISTS_FUNC
Callback type for checking if a symbol exists in the destination library.
void DeselectWithDescendants(const wxString &aSymbolName)
Force deselection of a symbol and all its descendants.
std::vector< wxString > GetConflicts() const
Get list of symbols that will conflict (selected and exist in destination).
void CheckExistingSymbols(SYMBOL_EXISTS_FUNC aExistsFunc)
Mark symbols that exist in the destination library.
std::map< wxString, wxString > m_parentMap
Map from symbol name to its parent name (for derived symbols)
void SelectAll(std::function< bool(const wxString &)> aFilter=nullptr)
Select all symbols (optionally filtered).
std::vector< wxString > GetDirectDerivatives(const wxString &aSymbolName) const
Get direct children (derivatives) of a symbol.
wxString GetParent(const wxString &aSymbolName) const
Get the direct parent of a symbol.
int GetManualSelectionCount() const
Get count of manually selected symbols.
std::map< wxString, SYMBOL_IMPORT_INFO > m_symbols
All symbols available for import, keyed by name.
void DeselectAll(std::function< bool(const wxString &)> aFilter=nullptr)
Deselect all symbols (optionally filtered).
size_t GetSymbolCount() const
Get total number of symbols.
void AddSymbol(const wxString &aName, const wxString &aParentName, bool aIsPower, LIB_SYMBOL *aSymbol=nullptr)
Add a symbol to the import list.
std::vector< wxString > GetSelectedDescendants(const wxString &aSymbolName) const
Get selected descendants that would be orphaned if a symbol is deselected.
std::vector< wxString > SetSymbolSelected(const wxString &aSymbolName, bool aSelected)
Set the selection state of a symbol.
std::vector< wxString > GetSymbolNames() const
Get all symbol names.
static bool MatchesFilter(const wxString &aSymbolName, const wxString &aFilter)
Check if a symbol name matches a filter string (case-insensitive contains).
int GetAutoSelectionCount() const
Get count of auto-selected symbols (dependencies).
void Clear()
Clear all loaded symbols and reset state.
void recalculateAutoSelections()
Recalculate auto-selection state for all symbols based on current manual selections.
SYMBOL_IMPORT_INFO * GetSymbolInfo(const wxString &aName)
Get symbol info by name.
std::map< wxString, std::vector< wxString > > m_derivativesMap
Map from parent name to list of direct derivative names.
bool IsDerived(const wxString &aSymbolName) const
Check if a symbol is derived from another.
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).
std::vector< wxString > GetSymbolsToImport() const
Get list of all symbols that will be imported (checked + auto-selected).
void BuildDependencyMaps()
Build the dependency maps from parent relationships.
Information about a symbol available for import.
bool m_existsInDest
True if symbol exists in destination library.
bool m_isPower
True if power symbol.
bool m_checked
User's manual selection state.
bool m_autoSelected
True if auto-selected as dependency.
wxString m_name
Symbol name.
std::unique_ptr< LIB_SYMBOL > m_symbol
Loaded symbol (may be null)
wxString m_parentName
Parent symbol name if derived.
CONFLICT_RESOLUTION
Result of conflict resolution for a single symbol.
@ OVERWRITE
Overwrite existing symbol.
@ SKIP
Don't import this symbol.