25#include <wx/settings.h>
43wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
47 return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
54 aParent->GetViewerSettingsBase()->m_LibTree ),
71 return node ? node->
m_Type == LIB_TREE_NODE::TYPE::LIBRARY :
true;
76 std::function<
void(
int,
int,
const wxString& )> aProgressCallback )
78 THROTTLE progressThrottle( std::chrono::milliseconds( 120 ) );
80 wxLogTrace( wxT(
"KICAD_TABS_DBG" ), wxT(
"SymbolSyncAdapter::Sync enter (forceRefresh='%s')" ),
95 wxLogTrace( wxT(
"KICAD_TABS_DBG" ), wxT(
"SymbolSyncAdapter::Sync freeing/updating nodes" ) );
98 for(
auto it =
m_tree.m_Children.begin(); it !=
m_tree.m_Children.end(); )
100 const wxString&
name = it->get()->m_Name;
102 if( progressThrottle.
Ready() )
103 aProgressCallback( i, max,
name );
113 std::optional<LIBRARY_TABLE_ROW*> optRow = adapter->
GetRow(
name );
116 bool loadFailed = libStatus.has_value()
119 if( !optRow.has_value()
120 || ( *optRow )->Disabled()
121 || ( *optRow )->Hidden()
123 ||
name == aForceRefresh )
149 if( progressThrottle.
Ready() )
150 aProgressCallback( i++, max, libName );
152 std::optional<LIBRARY_TABLE_ROW*> optRow = adapter->
GetRow( libName );
153 wxCHECK2( optRow.has_value(),
continue );
155 if( optRow.value()->Hidden() )
161 wxString description = optRow.value()->Description();
171 wxLogTrace( wxT(
"KICAD_TABS_DBG" ), wxT(
"SymbolSyncAdapter::Sync exit" ) );
179 for(
const wxString& libName :
m_libMgr->GetLibraryNames() )
199 else if( hashIt->second !=
m_libMgr->GetLibraryHash( aLibNode.
m_Name ) )
202 std::list<LIB_SYMBOL*> symbols =
m_libMgr->EnumerateSymbols( aLibNode.
m_Name );
207 auto symbolIt = std::find_if( symbols.begin(), symbols.end(),
210 return a->GetName() == (*nodeIt)->m_LibId.GetLibItemName().wx_str();
213 if( symbolIt != symbols.end() )
218 symbols.erase( symbolIt );
243std::vector<std::unique_ptr<LIB_TREE_NODE>>::iterator
248 return m_tree.m_Children.erase( aLibNodeIt );
257 return wxDataViewItem();
262 unsigned int aCol )
const
266 aVariant = wxEmptyString;
277 node->
m_Name =
m_frame->GetCurSymbol()->GetLibId().GetUniStringLibItemName();
285 if( node->
m_Type == LIB_TREE_NODE::TYPE::LIBRARY )
288 aVariant = aVariant.GetString() +
" *";
290 else if( node->
m_Type == LIB_TREE_NODE::TYPE::ITEM )
293 aVariant = aVariant.GetString() +
" *";
301 if( node->
m_Type == LIB_TREE_NODE::TYPE::LIBRARY )
307 node->
m_Desc = ( *optRow )->Description();
310 aVariant =
_(
"(failed to load)" ) + wxS(
" " ) + aVariant.GetString();
312 aVariant =
_(
"(read-only)" ) + wxS(
" " ) + aVariant.GetString();
322 if( key == wxT(
"Description" ) )
324 else if( node->
m_Fields.count( key ) )
325 valueStr = node->
m_Fields.at( key );
327 valueStr = wxEmptyString;
329 valueStr.Replace( wxS(
"\n" ), wxS(
" " ) );
331 if( !aVariant.GetString().IsEmpty() )
333 if( !valueStr.IsEmpty() )
334 aVariant = valueStr + wxS(
" - " ) + aVariant.GetString();
347 wxDataViewItemAttr& aAttr )
const
353 wxCHECK( node,
false );
356 if( node->
m_Type == LIB_TREE_NODE::TYPE::LIBRARY && !
m_libMgr->IsLibraryLoaded( node->
m_Name ) )
358 aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
370 case LIB_TREE_NODE::TYPE::LIBRARY:
379 aAttr.SetStrikethrough(
true );
386 case LIB_TREE_NODE::TYPE::ITEM:
396 aAttr.SetStrikethrough(
true );
413 wxCHECK( node,
false );
423 const wxDataViewItem& aItem )
433 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
434 aParent->SetSizer( mainSizer );
440 wxBoxSizer* panelSizer =
new wxBoxSizer( wxVERTICAL );
441 panel->SetSizer( panelSizer );
446 preview->SetLayoutDirection( wxLayout_LeftToRight );
448 panelSizer->Add( preview, 1, wxEXPAND | wxALL, 1 );
449 mainSizer->Add( panel, 1, wxEXPAND, 0 );
459 wxWindow* previewWindow = wxWindow::FindWindowByName(
c_previewName, aParent );
463 preview->GetCanvas()->SetEvtHandlerEnabled(
false );
464 preview->GetCanvas()->StopDrawing();
static const COLOR4D BLACK
std::optional< LIB_STATUS > GetLibraryStatus(const wxString &aNickname) const
Returns the status of a loaded library, or nullopt if the library hasn't been loaded (yet)
std::optional< LIBRARY_TABLE_ROW * > GetRow(const wxString &aNickname, LIBRARY_TABLE_SCOPE aScope=LIBRARY_TABLE_SCOPE::BOTH) const
Like LIBRARY_MANAGER::GetRow but filtered to the LIBRARY_TABLE_TYPE of this adapter.
std::vector< std::pair< wxString, LIB_STATUS > > GetLibraryStatuses() const
Returns a list of all library nicknames and their status (even if they failed to load)
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Define a library symbol object.
const LIB_ID & GetLibId() const override
RAII guard that detaches the GtkTreeView from the model across a tree rebuild so a deferred frame-clo...
LIB_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, const wxString &aPinnedKey, APP_SETTINGS_BASE::LIB_TREE &aSettingsStruct)
Create the adapter.
LIB_TREE_NODE_ROOT m_tree
void addColumnIfNecessary(const wxString &aHeader)
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> LIB_TREE_NODE.
static wxDataViewItem ToItem(const LIB_TREE_NODE *aNode)
Convert LIB_TREE_NODE -> wxDataViewItem.
static const wxString GetPinningSymbol()
@ NAME_COL
Library or library item name column.
std::map< unsigned, wxString > m_colIdxMap
virtual int GetLibrariesCount() const
Return the number of libraries loaded in the tree.
wxDataViewCtrl * m_widget
std::vector< wxString > m_shownColumns
LIB_TREE_NODE_LIBRARY & DoAddLibraryNode(const wxString &aNodeName, const wxString &aDesc, bool pinned)
wxDataViewItem FindItem(const LIB_ID &aLibId)
Returns tree item corresponding to part.
void Update(LIB_TREE_ITEM *aItem)
Update the node using data from a LIB_ALIAS object.
LIB_TREE_NODE_ITEM & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
std::map< wxString, wxString > m_Fields
List of weighted search terms.
std::vector< std::unique_ptr< LIB_TREE_NODE > > m_Children
void AssignIntrinsicRanks(const std::vector< wxString > &aShownColumns, bool presorted=false)
Store intrinsic ranks on all children of this node.
virtual COMMON_SETTINGS * GetCommonSettings() const
The backing store for a PROJECT, in JSON format.
static SYMBOL_LIBRARY_ADAPTER * SymbolLibAdapter(PROJECT *aProject)
Accessor for project symbol library manager adapter.
Handle actions for the various symbol editor and viewers.
The symbol library editor main window.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
std::vector< wxString > GetAvailableExtraFields(const wxString &aNickname)
Returns a list of additional (non-mandatory) symbol fields present in the given library.
Class to handle modifications to the symbol libraries.
SYMBOL_LIBRARY_MANAGER * m_libMgr
void GetValue(wxVariant &aVariant, wxDataViewItem const &aItem, unsigned int aCol) const override
SYMBOL_EDIT_FRAME * m_frame
bool GetAttr(wxDataViewItem const &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
void ShutdownPreview(wxWindow *aParent) override
void updateLibrary(LIB_TREE_NODE_LIBRARY &aLibNode)
wxDataViewItem GetCurrentDataViewItem() override
static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > Create(SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibs)
void ShowPreview(wxWindow *aParent, const wxDataViewItem &aItem) override
std::vector< std::unique_ptr< LIB_TREE_NODE > >::iterator deleteLibrary(std::vector< std::unique_ptr< LIB_TREE_NODE > >::iterator &aLibNodeIt)
int GetLibrariesCount() const override
Return the number of libraries loaded in the tree.
int m_lastSyncHash
SYMBOL_LIBRARY_MANAGER hash value returned in the last synchronization.
void Sync(const wxString &aForceRefresh, std::function< void(int, int, const wxString &)> aProgressCallback)
TOOL_INTERACTIVE * GetContextMenuTool() override
bool IsContainer(const wxDataViewItem &aItem) const override
bool HasPreview(const wxDataViewItem &aItem) override
std::map< wxString, int > m_libHashes
Hashes to decide whether a library needs an update.
SYMBOL_TREE_SYNCHRONIZING_ADAPTER(SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibMgr)
Rate-limiter that fires at most once per interval.
void SetBorders(bool aLeft, bool aRight, bool aTop, bool aBottom)
void SetBorderColor(const KIGFX::COLOR4D &aColor)
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
PGM_BASE & Pgm()
The global program "get" accessor.
wxString UnescapeString(const wxString &aSource)
std::vector< wxString > pinned_symbol_libs
static const wxString c_previewName