KiCad PCB EDA Suite
SYMBOL_TREE_SYNCHRONIZING_ADAPTER Class Reference

#include <symbol_tree_synchronizing_adapter.h>

Inheritance diagram for SYMBOL_TREE_SYNCHRONIZING_ADAPTER:
LIB_TREE_MODEL_ADAPTER

Public Types

enum  SYM_FILTER_TYPE { SYM_FILTER_NONE , SYM_FILTER_POWER }
 This enum allows a selective filtering of symbols to list. More...
 
enum  TREE_COLS { NAME_COL = 0 , DESC_COL , NUM_COLS }
 This enum defines the order of the default columns in the tree view. More...
 

Public Member Functions

bool IsContainer (const wxDataViewItem &aItem) const override
 
void Sync (const wxString &aForceRefresh, std::function< void(int, int, const wxString &)> aProgressCallback)
 
int GetLibrariesCount () const override
 Return the number of libraries loaded in the tree. More...
 
TOOL_INTERACTIVEGetContextMenuTool () override
 
void SaveSettings ()
 Save the column widths to the config file. More...
 
void SetFilter (SYM_FILTER_TYPE aFilter)
 Set the symbol filter type. More...
 
SYM_FILTER_TYPE GetFilter () const
 Return the active filter. More...
 
void ShowUnits (bool aShow)
 Whether or not to show units. More...
 
void SetPreselectNode (const LIB_ID &aLibId, int aUnit)
 Set the symbol name to be selected if there are no search results. More...
 
void DoAddLibrary (const wxString &aNodeName, const wxString &aDesc, const std::vector< LIB_TREE_ITEM * > &aItemList, bool pinned, bool presorted)
 Add the given list of symbols by alias. More...
 
void AddColumn (const wxString &aHeader)
 
std::vector< wxString > GetAvailableColumns () const
 
std::vector< wxString > GetShownColumns () const
 
void SetShownColumns (const std::vector< wxString > &aColumnNames)
 Sets which columns are shown in the widget. More...
 
void AssignIntrinsicRanks ()
 Sort the tree and assign ranks after adding libraries. More...
 
void UpdateSearchString (const wxString &aSearch, bool aState)
 Set the search string provided by the user. More...
 
void AttachTo (wxDataViewCtrl *aDataViewCtrl)
 Attach to a wxDataViewCtrl and initialize it. More...
 
void FinishTreeInitialization ()
 A final-stage initialization to be called after the window hierarchy has been realized and the window sizes set. More...
 
void OnSize (wxSizeEvent &aEvent)
 
LIB_ID GetAliasFor (const wxDataViewItem &aSelection) const
 Return the alias for the given item. More...
 
int GetUnitFor (const wxDataViewItem &aSelection) const
 Return the unit for the given item. More...
 
LIB_TREE_NODE::TYPE GetTypeFor (const wxDataViewItem &aSelection) const
 Return node type for the given item. More...
 
LIB_TREE_NODEGetTreeNodeFor (const wxDataViewItem &aSelection) const
 
virtual wxString GenerateInfo (const LIB_ID &aLibId, int aUnit)
 
int GetItemCount () const
 Return the number of symbols loaded in the tree. More...
 
wxDataViewItem FindItem (const LIB_ID &aLibId)
 Returns tree item corresponding to part. More...
 
unsigned int GetChildren (const wxDataViewItem &aItem, wxDataViewItemArray &aChildren) const override
 Populate a list of all the children of an item. More...
 
void Freeze ()
 
void Thaw ()
 
bool IsFrozen () const
 
void RefreshTree ()
 
void PinLibrary (LIB_TREE_NODE *aTreeNode)
 
void UnpinLibrary (LIB_TREE_NODE *aTreeNode)
 

Static Public Member Functions

static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTERCreate (SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibs)
 
static const wxString GetPinningSymbol ()
 

Protected Member Functions

void updateLibrary (LIB_TREE_NODE_LIB &aLibNode)
 
LIB_TREE_NODE::PTR_VECTOR::iterator deleteLibrary (LIB_TREE_NODE::PTR_VECTOR::iterator &aLibNodeIt)
 
void GetValue (wxVariant &aVariant, wxDataViewItem const &aItem, unsigned int aCol) const override
 
bool GetAttr (wxDataViewItem const &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
 
 SYMBOL_TREE_SYNCHRONIZING_ADAPTER (SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibMgr)
 
bool isSymbolModel () override
 
LIB_TREE_NODE_LIBDoAddLibraryNode (const wxString &aNodeName, const wxString &aDesc, bool pinned)
 
bool HasContainerColumns (const wxDataViewItem &aItem) const override
 Check whether a container has columns too. More...
 
wxDataViewItem GetParent (const wxDataViewItem &aItem) const override
 Get the parent of an item. More...
 
unsigned int GetColumnCount () const override
 
wxString GetColumnType (unsigned int aCol) const override
 Return the type of data stored in the column as indicated by wxVariant::GetType() More...
 
bool SetValue (const wxVariant &aVariant, const wxDataViewItem &aItem, unsigned int aCol) override
 Set the value of an item. More...
 
void resortTree ()
 
void addColumnIfNecessary (const wxString &aHeader)
 
void recreateColumns ()
 

Static Protected Member Functions

static wxDataViewItem ToItem (const LIB_TREE_NODE *aNode)
 Convert #SYM_TREE_NODE -> wxDataViewItem. More...
 
static LIB_TREE_NODEToNode (wxDataViewItem aItem)
 Convert wxDataViewItem -> #SYM_TREE_NODE. More...
 
static unsigned int IntoArray (const LIB_TREE_NODE &aNode, wxDataViewItemArray &aChildren)
 Convert SYM_TREE_NODE's children to wxDataViewItemArray. More...
 

Protected Attributes

SYMBOL_EDIT_FRAMEm_frame
 
SYMBOL_LIBRARY_MANAGERm_libMgr
 Hashes to decide whether a library needs an update. More...
 
std::map< wxString, int > m_libHashes
 SYMBOL_LIBRARY_MANAGER hash value returned in the last synchronization. More...
 
int m_lastSyncHash
 
LIB_TREE_NODE_ROOT m_tree
 
std::map< unsigned, wxString > m_colIdxMap
 

Private Member Functions

void Find (LIB_TREE_NODE &aNode, std::function< bool(const LIB_TREE_NODE *)> aFunc, LIB_TREE_NODE **aHighScore)
 Find any results worth highlighting and expand them, according to given criteria The highest-scoring node is written to aHighScore. More...
 
LIB_TREE_NODEShowResults ()
 Find and expand successful search results. More...
 
LIB_TREE_NODEShowPreselect ()
 Find and expand preselected node. More...
 
LIB_TREE_NODEShowSingleLibrary ()
 Find and expand a library if there is only one. More...
 
wxDataViewColumn * doAddColumn (const wxString &aHeader, bool aTranslate=true)
 

Private Attributes

EDA_BASE_FRAMEm_parent
 
SYM_FILTER_TYPE m_filter
 
bool m_show_units
 
LIB_ID m_preselect_lib_id
 
int m_preselect_unit
 
int m_freeze
 
wxDataViewCtrl * m_widget
 
std::vector< wxDataViewColumn * > m_columns
 
std::map< wxString, wxDataViewColumn * > m_colNameMap
 
std::map< wxString, int > m_colWidths
 
std::vector< wxString > m_availableColumns
 
std::vector< wxString > m_shownColumns
 

Detailed Description

Definition at line 36 of file symbol_tree_synchronizing_adapter.h.

Member Enumeration Documentation

◆ SYM_FILTER_TYPE

This enum allows a selective filtering of symbols to list.

Enumerator
SYM_FILTER_NONE 

no filtering

SYM_FILTER_POWER 

list symbols flagged PWR

Definition at line 120 of file lib_tree_model_adapter.h.

121 {
124 };
@ SYM_FILTER_POWER
list symbols flagged PWR

◆ TREE_COLS

This enum defines the order of the default columns in the tree view.

Enumerator
NAME_COL 

Library or library item name column.

DESC_COL 

Library or library description column.

NUM_COLS 

The number of default tree columns.

Definition at line 129 of file lib_tree_model_adapter.h.

130 {
131 NAME_COL = 0,
132 DESC_COL,
133 NUM_COLS
134 };
@ NUM_COLS
The number of default tree columns.
@ NAME_COL
Library or library item name column.
@ DESC_COL
Library or library description column.

Constructor & Destructor Documentation

◆ SYMBOL_TREE_SYNCHRONIZING_ADAPTER()

SYMBOL_TREE_SYNCHRONIZING_ADAPTER::SYMBOL_TREE_SYNCHRONIZING_ADAPTER ( SYMBOL_EDIT_FRAME aParent,
SYMBOL_LIBRARY_MANAGER aLibMgr 
)
protected

Definition at line 44 of file symbol_tree_synchronizing_adapter.cpp.

45 :
46 LIB_TREE_MODEL_ADAPTER( aParent, "pinned_symbol_libs" ),
47 m_frame( aParent ),
48 m_libMgr( aLibMgr ),
49 m_lastSyncHash( -1 )
50{
51}
LIB_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, const wxString &aPinnedKey)
Create the adapter.
SYMBOL_LIBRARY_MANAGER * m_libMgr
Hashes to decide whether a library needs an update.

Referenced by Create().

Member Function Documentation

◆ AddColumn()

void LIB_TREE_MODEL_ADAPTER::AddColumn ( const wxString &  aHeader)
inlineinherited

Definition at line 184 of file lib_tree_model_adapter.h.

185 {
186 doAddColumn( aHeader, false );
187 }
wxDataViewColumn * doAddColumn(const wxString &aHeader, bool aTranslate=true)

References LIB_TREE_MODEL_ADAPTER::doAddColumn().

◆ addColumnIfNecessary()

void LIB_TREE_MODEL_ADAPTER::addColumnIfNecessary ( const wxString &  aHeader)
protectedinherited

Definition at line 335 of file lib_tree_model_adapter.cpp.

336{
337 if( m_colNameMap.count( aHeader ) )
338 return;
339
340 // Columns will be created later
341 m_colNameMap[aHeader] = nullptr;
342 m_availableColumns.emplace_back( aHeader );
343}
std::map< wxString, wxDataViewColumn * > m_colNameMap
std::vector< wxString > m_availableColumns

References LIB_TREE_MODEL_ADAPTER::m_availableColumns, and LIB_TREE_MODEL_ADAPTER::m_colNameMap.

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries().

◆ AssignIntrinsicRanks()

void LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks ( )
inlineinherited

Sort the tree and assign ranks after adding libraries.

Definition at line 202 of file lib_tree_model_adapter.h.

void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.

References LIB_TREE_NODE::AssignIntrinsicRanks(), and LIB_TREE_MODEL_ADAPTER::m_tree.

Referenced by SCH_BASE_FRAME::PickSymbolFromLibTree().

◆ AttachTo()

void LIB_TREE_MODEL_ADAPTER::AttachTo ( wxDataViewCtrl *  aDataViewCtrl)
inherited

Attach to a wxDataViewCtrl and initialize it.

This will set up columns and associate the model via the adapter.

Parameters
aDataViewCtrlthe view symbol in the dialog

Definition at line 249 of file lib_tree_model_adapter.cpp.

250{
251 m_widget = aDataViewCtrl;
252 aDataViewCtrl->SetIndent( kDataViewIndent );
253 aDataViewCtrl->AssociateModel( this );
255}
static const int kDataViewIndent

References kDataViewIndent, LIB_TREE_MODEL_ADAPTER::m_widget, and LIB_TREE_MODEL_ADAPTER::recreateColumns().

◆ Create()

wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Create ( SYMBOL_EDIT_FRAME aParent,
SYMBOL_LIBRARY_MANAGER aLibs 
)
static

Definition at line 36 of file symbol_tree_synchronizing_adapter.cpp.

38{
39 auto* adapter = new SYMBOL_TREE_SYNCHRONIZING_ADAPTER( aParent, aLibMgr );
40 return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
41}
SYMBOL_TREE_SYNCHRONIZING_ADAPTER(SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibMgr)

References SYMBOL_TREE_SYNCHRONIZING_ADAPTER().

Referenced by LIB_SYMBOL_LIBRARY_MANAGER::LIB_SYMBOL_LIBRARY_MANAGER().

◆ deleteLibrary()

LIB_TREE_NODE::PTR_VECTOR::iterator SYMBOL_TREE_SYNCHRONIZING_ADAPTER::deleteLibrary ( LIB_TREE_NODE::PTR_VECTOR::iterator &  aLibNodeIt)
protected

Definition at line 202 of file symbol_tree_synchronizing_adapter.cpp.

203{
204 LIB_TREE_NODE* node = aLibNodeIt->get();
205 m_libHashes.erase( node->m_Name );
206 auto it = m_tree.m_Children.erase( aLibNodeIt );
207 return it;
208}
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
PTR_VECTOR m_Children
std::map< wxString, int > m_libHashes
SYMBOL_LIBRARY_MANAGER hash value returned in the last synchronization.

References LIB_TREE_NODE::m_Children, m_libHashes, LIB_TREE_NODE::m_Name, and LIB_TREE_MODEL_ADAPTER::m_tree.

Referenced by Sync().

◆ doAddColumn()

wxDataViewColumn * LIB_TREE_MODEL_ADAPTER::doAddColumn ( const wxString &  aHeader,
bool  aTranslate = true 
)
privateinherited

Definition at line 309 of file lib_tree_model_adapter.cpp.

310{
311 wxString translatedHeader = aTranslate ? wxGetTranslation( aHeader ) : aHeader;
312
313 // The extent of the text doesn't take into account the space on either side
314 // in the header, so artificially pad it
315 wxSize headerMinWidth = KIUI::GetTextSize( translatedHeader + wxT( "MMM" ), m_widget );
316
317 if( !m_colWidths.count( aHeader ) || m_colWidths[aHeader] < headerMinWidth.x )
318 m_colWidths[aHeader] = headerMinWidth.x;
319
320 int index = m_columns.size();
321
322 wxDataViewColumn* ret = m_widget->AppendTextColumn( translatedHeader, index,
323 wxDATAVIEW_CELL_INERT,
324 m_colWidths[aHeader] );
325 ret->SetMinWidth( headerMinWidth.x );
326
327 m_columns.emplace_back( ret );
328 m_colNameMap[aHeader] = ret;
329 m_colIdxMap[m_columns.size() - 1] = aHeader;
330
331 return ret;
332}
std::map< wxString, int > m_colWidths
std::map< unsigned, wxString > m_colIdxMap
std::vector< wxDataViewColumn * > m_columns
wxSize GetTextSize(const wxString &aSingleLine, wxWindow *aWindow)
Return the size of aSingleLine of text when it is rendered in aWindow using whatever font is currentl...
Definition: ui_common.cpp:70

References KIUI::GetTextSize(), LIB_TREE_MODEL_ADAPTER::m_colIdxMap, LIB_TREE_MODEL_ADAPTER::m_colNameMap, LIB_TREE_MODEL_ADAPTER::m_columns, LIB_TREE_MODEL_ADAPTER::m_colWidths, and LIB_TREE_MODEL_ADAPTER::m_widget.

Referenced by LIB_TREE_MODEL_ADAPTER::AddColumn(), and LIB_TREE_MODEL_ADAPTER::recreateColumns().

◆ DoAddLibrary()

void LIB_TREE_MODEL_ADAPTER::DoAddLibrary ( const wxString &  aNodeName,
const wxString &  aDesc,
const std::vector< LIB_TREE_ITEM * > &  aItemList,
bool  pinned,
bool  presorted 
)
inherited

Add the given list of symbols by alias.

To be called in the setup phase.

Parameters
aNodeNamethe parent node the symbols will appear under
aDescthe description field of the parent node
aItemListlist of symbols

Definition at line 146 of file lib_tree_model_adapter.cpp.

149{
150 LIB_TREE_NODE_LIB& lib_node = DoAddLibraryNode( aNodeName, aDesc, pinned );
151
152 for( LIB_TREE_ITEM* item: aItemList )
153 lib_node.AddItem( item );
154
155 lib_node.AssignIntrinsicRanks( presorted );
156}
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
Definition: lib_tree_item.h:40
LIB_TREE_NODE_LIB & DoAddLibraryNode(const wxString &aNodeName, const wxString &aDesc, bool pinned)
Node type: library.
LIB_TREE_NODE_LIB_ID & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.

References LIB_TREE_NODE_LIB::AddItem(), LIB_TREE_NODE::AssignIntrinsicRanks(), and LIB_TREE_MODEL_ADAPTER::DoAddLibraryNode().

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), FP_TREE_MODEL_ADAPTER::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), SCH_BASE_FRAME::PickSymbolFromLibTree(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), and FP_TREE_SYNCHRONIZING_ADAPTER::Sync().

◆ DoAddLibraryNode()

LIB_TREE_NODE_LIB & LIB_TREE_MODEL_ADAPTER::DoAddLibraryNode ( const wxString &  aNodeName,
const wxString &  aDesc,
bool  pinned 
)
protectedinherited

Definition at line 135 of file lib_tree_model_adapter.cpp.

137{
138 LIB_TREE_NODE_LIB& lib_node = m_tree.AddLib( aNodeName, aDesc );
139
140 lib_node.m_Pinned = pinned;
141
142 return lib_node;
143}
LIB_TREE_NODE_LIB & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.

References LIB_TREE_NODE_ROOT::AddLib(), LIB_TREE_NODE::m_Pinned, and LIB_TREE_MODEL_ADAPTER::m_tree.

Referenced by LIB_TREE_MODEL_ADAPTER::DoAddLibrary(), and Sync().

◆ Find()

void LIB_TREE_MODEL_ADAPTER::Find ( LIB_TREE_NODE aNode,
std::function< bool(const LIB_TREE_NODE *)>  aFunc,
LIB_TREE_NODE **  aHighScore 
)
privateinherited

Find any results worth highlighting and expand them, according to given criteria The highest-scoring node is written to aHighScore.

Definition at line 622 of file lib_tree_model_adapter.cpp.

625{
626 for( std::unique_ptr<LIB_TREE_NODE>& node: aNode.m_Children )
627 {
628 if( aFunc( &*node ) )
629 {
630 if( !(*aHighScore) || node->m_Score > (*aHighScore)->m_Score )
631 (*aHighScore) = &*node;
632 }
633
634 Find( *node, aFunc, aHighScore );
635 }
636}
void Find(LIB_TREE_NODE &aNode, std::function< bool(const LIB_TREE_NODE *)> aFunc, LIB_TREE_NODE **aHighScore)
Find any results worth highlighting and expand them, according to given criteria The highest-scoring ...

References LIB_TREE_MODEL_ADAPTER::Find(), and LIB_TREE_NODE::m_Children.

Referenced by LIB_TREE_MODEL_ADAPTER::Find(), LIB_TREE_MODEL_ADAPTER::ShowPreselect(), LIB_TREE_MODEL_ADAPTER::ShowResults(), and LIB_TREE_MODEL_ADAPTER::ShowSingleLibrary().

◆ FindItem()

wxDataViewItem LIB_TREE_MODEL_ADAPTER::FindItem ( const LIB_ID aLibId)
inherited

Returns tree item corresponding to part.

Parameters
aLibIdspecifies the part and library name to be searched for.
Returns
Tree data item representing the part. Might be invalid if nothings was found.

Definition at line 401 of file lib_tree_model_adapter.cpp.

402{
403 for( std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.m_Children )
404 {
405 if( lib->m_Name != aLibId.GetLibNickname() )
406 continue;
407
408 // if part name is not specified, return the library node
409 if( aLibId.GetLibItemName() == "" )
410 return ToItem( lib.get() );
411
412 for( std::unique_ptr<LIB_TREE_NODE>& alias: lib->m_Children )
413 {
414 if( alias->m_Name == aLibId.GetLibItemName() )
415 return ToItem( alias.get() );
416 }
417
418 break; // could not find the part in the requested library
419 }
420
421 return wxDataViewItem();
422}
const UTF8 & GetLibItemName() const
Definition: lib_id.h:101
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:87
static wxDataViewItem ToItem(const LIB_TREE_NODE *aNode)
Convert #SYM_TREE_NODE -> wxDataViewItem.

References LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), LIB_TREE_NODE::m_Children, LIB_TREE_MODEL_ADAPTER::m_tree, and LIB_TREE_MODEL_ADAPTER::ToItem().

◆ FinishTreeInitialization()

void LIB_TREE_MODEL_ADAPTER::FinishTreeInitialization ( )
inherited

A final-stage initialization to be called after the window hierarchy has been realized and the window sizes set.

Definition at line 444 of file lib_tree_model_adapter.cpp.

445{
446 wxDataViewColumn* col = nullptr;
447 size_t idx = 0;
448 int totalWidth = 0;
449 wxString header;
450
451 for( ; idx < m_columns.size() - 1; idx++ )
452 {
453 wxASSERT( m_colIdxMap.count( idx ) );
454
455 col = m_columns[idx];
456 header = m_colIdxMap[idx];
457
458 wxASSERT( m_colWidths.count( header ) );
459
460 col->SetWidth( m_colWidths[header] );
461 totalWidth += col->GetWidth();
462 }
463
464 int remainingWidth = m_widget->GetSize().x - totalWidth;
465 header = m_columns[idx]->GetTitle();
466
467 m_columns[idx]->SetWidth( std::max( m_colWidths[header], remainingWidth ) );
468}

References LIB_TREE_MODEL_ADAPTER::m_colIdxMap, LIB_TREE_MODEL_ADAPTER::m_columns, LIB_TREE_MODEL_ADAPTER::m_colWidths, and LIB_TREE_MODEL_ADAPTER::m_widget.

◆ Freeze()

void LIB_TREE_MODEL_ADAPTER::Freeze ( )
inlineinherited

◆ GenerateInfo()

virtual wxString LIB_TREE_MODEL_ADAPTER::GenerateInfo ( const LIB_ID aLibId,
int  aUnit 
)
inlinevirtualinherited

Reimplemented in SYMBOL_TREE_MODEL_ADAPTER, and FP_TREE_MODEL_ADAPTER.

Definition at line 260 of file lib_tree_model_adapter.h.

260{ return wxEmptyString; };

◆ GetAliasFor()

LIB_ID LIB_TREE_MODEL_ADAPTER::GetAliasFor ( const wxDataViewItem &  aSelection) const
inherited

Return the alias for the given item.

Parameters
aSelectionitem from the wxDataViewCtrl (see wxDataViewCtrl::GetSelection())
Returns
alias, or nullptr if none is selected

Definition at line 357 of file lib_tree_model_adapter.cpp.

358{
359 const LIB_TREE_NODE* node = ToNode( aSelection );
360
361 LIB_ID emptyId;
362
363 if( !node )
364 return emptyId;
365
366 return node->m_LibId;
367}
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> #SYM_TREE_NODE.

References LIB_TREE_NODE::m_LibId, and LIB_TREE_MODEL_ADAPTER::ToNode().

◆ GetAttr()

bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr ( wxDataViewItem const &  aItem,
unsigned int  aCol,
wxDataViewItemAttr &  aAttr 
) const
overrideprotected

Definition at line 280 of file symbol_tree_synchronizing_adapter.cpp.

282{
283 if( IsFrozen() )
284 return false;
285
286 LIB_TREE_NODE* node = ToNode( aItem );
287 wxCHECK( node, false );
288
289 // Mark both columns of unloaded libraries using grey text color (to look disabled)
290 if( node->m_Type == LIB_TREE_NODE::LIB && !m_libMgr->IsLibraryLoaded( node->m_Name ) )
291 {
292 aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
293 return true;
294 }
295
296 // The remaining attributes are only for the name column
297 if( aCol != NAME_COL )
298 return false;
299
300 LIB_SYMBOL* curSymbol = m_frame->GetCurSymbol();
301
302 switch( node->m_Type )
303 {
305 // mark modified libs with bold font
306 aAttr.SetBold( m_libMgr->IsLibraryModified( node->m_Name ) );
307
308 // mark the current library with background color
309 if( curSymbol && curSymbol->GetLibId().GetLibNickname() == node->m_LibId.GetLibNickname() )
310 {
311#ifdef __WXGTK__
312 // The native wxGTK+ impl ignores background colour, so set the text colour instead.
313 // This works reasonably well in dark themes, and quite poorly in light ones....
314 aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
315#else
316 aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
317 aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
318#endif
319 }
320 break;
321
323 // mark modified part with bold font
324 aAttr.SetBold( m_libMgr->IsSymbolModified( node->m_Name, node->m_Parent->m_Name ) );
325
326 // mark aliases with italic font
327 aAttr.SetItalic( !node->m_IsRoot );
328
329 // mark the current part with background color
330 if( curSymbol && curSymbol->GetLibId() == node->m_LibId )
331 {
332#ifdef __WXGTK__
333 // The native wxGTK+ impl ignores background colour, so set the text colour instead.
334 // This works reasonably well in dark themes, and quite poorly in light ones....
335 aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
336#else
337 aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
338 aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
339#endif
340 }
341 break;
342
343 default:
344 return false;
345 }
346
347 return true;
348}
Define a library symbol object.
Definition: lib_symbol.h:98
LIB_ID GetLibId() const override
Definition: lib_symbol.h:139
enum TYPE m_Type
LIB_TREE_NODE * m_Parent
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
bool IsLibraryModified(const wxString &aLibrary) const
Return true if library has unsaved modifications.
bool IsSymbolModified(const wxString &aAlias, const wxString &aLibrary) const
Return true if symbol has unsaved modifications.
bool IsLibraryLoaded(const wxString &aLibrary) const
Return true if the library was successfully loaded.

References SYMBOL_EDIT_FRAME::GetCurSymbol(), LIB_SYMBOL::GetLibId(), LIB_ID::GetLibNickname(), LIB_TREE_MODEL_ADAPTER::IsFrozen(), SYMBOL_LIBRARY_MANAGER::IsLibraryLoaded(), SYMBOL_LIBRARY_MANAGER::IsLibraryModified(), SYMBOL_LIBRARY_MANAGER::IsSymbolModified(), LIB_TREE_NODE::LIB, LIB_TREE_NODE::LIBID, m_frame, LIB_TREE_NODE::m_IsRoot, LIB_TREE_NODE::m_LibId, m_libMgr, LIB_TREE_NODE::m_Name, LIB_TREE_NODE::m_Parent, LIB_TREE_NODE::m_Type, LIB_TREE_MODEL_ADAPTER::NAME_COL, and LIB_TREE_MODEL_ADAPTER::ToNode().

◆ GetAvailableColumns()

std::vector< wxString > LIB_TREE_MODEL_ADAPTER::GetAvailableColumns ( ) const
inlineinherited

Definition at line 189 of file lib_tree_model_adapter.h.

189{ return m_availableColumns; }

References LIB_TREE_MODEL_ADAPTER::m_availableColumns.

◆ GetChildren()

unsigned int LIB_TREE_MODEL_ADAPTER::GetChildren ( const wxDataViewItem &  aItem,
wxDataViewItemArray &  aChildren 
) const
overrideinherited

Populate a list of all the children of an item.

Returns
number of children

Definition at line 425 of file lib_tree_model_adapter.cpp.

427{
428 const LIB_TREE_NODE* node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
429
430 if( node->m_Type == LIB_TREE_NODE::TYPE::ROOT
431 || node->m_Type == LIB_TREE_NODE::LIB
432 || ( m_show_units && node->m_Type == LIB_TREE_NODE::TYPE::LIBID ) )
433 {
434 return IntoArray( *node, aChildren );
435 }
436 else
437 {
438 return 0;
439 }
440
441}
static unsigned int IntoArray(const LIB_TREE_NODE &aNode, wxDataViewItemArray &aChildren)
Convert SYM_TREE_NODE's children to wxDataViewItemArray.

References LIB_TREE_MODEL_ADAPTER::IntoArray(), LIB_TREE_NODE::LIB, LIB_TREE_MODEL_ADAPTER::m_show_units, LIB_TREE_MODEL_ADAPTER::m_tree, LIB_TREE_NODE::m_Type, and LIB_TREE_MODEL_ADAPTER::ToNode().

◆ GetColumnCount()

unsigned int LIB_TREE_MODEL_ADAPTER::GetColumnCount ( ) const
inlineoverrideprotectedinherited

Definition at line 350 of file lib_tree_model_adapter.h.

350{ return m_columns.size(); }

References LIB_TREE_MODEL_ADAPTER::m_columns.

◆ GetColumnType()

wxString LIB_TREE_MODEL_ADAPTER::GetColumnType ( unsigned int  aCol) const
inlineoverrideprotectedinherited

Return the type of data stored in the column as indicated by wxVariant::GetType()

Definition at line 355 of file lib_tree_model_adapter.h.

355{ return "string"; }

◆ GetContextMenuTool()

TOOL_INTERACTIVE * SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetContextMenuTool ( )
overridevirtual

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 54 of file symbol_tree_synchronizing_adapter.cpp.

55{
57}
Handle actions for the various symbol editor and viewers.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:54

References TOOL_MANAGER::GetTool(), TOOLS_HOLDER::GetToolManager(), and m_frame.

◆ GetFilter()

SYM_FILTER_TYPE LIB_TREE_MODEL_ADAPTER::GetFilter ( ) const
inlineinherited

◆ GetItemCount()

int LIB_TREE_MODEL_ADAPTER::GetItemCount ( ) const
inherited

Return the number of symbols loaded in the tree.

Definition at line 390 of file lib_tree_model_adapter.cpp.

391{
392 int n = 0;
393
394 for( const std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.m_Children )
395 n += lib->m_Children.size();
396
397 return n;
398}

References LIB_TREE_NODE::m_Children, and LIB_TREE_MODEL_ADAPTER::m_tree.

Referenced by SYMBOL_VIEWER_FRAME::OnSelectSymbol(), and PCB_BASE_FRAME::SelectFootprintFromLibTree().

◆ GetLibrariesCount()

int SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount ( ) const
overridevirtual

Return the number of libraries loaded in the tree.

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 138 of file symbol_tree_synchronizing_adapter.cpp.

139{
141
142 for( const wxString& libName : m_libMgr->GetLibraryNames() )
143 {
144 if( m_libHashes.count( libName ) == 0 )
145 ++count;
146 }
147
148 return count;
149}
virtual int GetLibrariesCount() const
Return the number of libraries loaded in the tree.
wxArrayString GetLibraryNames() const
Return the array of library names.

References LIB_TREE_MODEL_ADAPTER::GetLibrariesCount(), SYMBOL_LIBRARY_MANAGER::GetLibraryNames(), m_libHashes, and m_libMgr.

Referenced by Sync().

◆ GetParent()

wxDataViewItem LIB_TREE_MODEL_ADAPTER::GetParent ( const wxDataViewItem &  aItem) const
overrideprotectedinherited

Get the parent of an item.

Returns
parent of aItem, or an invalid wxDataViewItem if parent is root

Definition at line 535 of file lib_tree_model_adapter.cpp.

536{
537 if( m_freeze )
538 return ToItem( nullptr );
539
540 LIB_TREE_NODE* node = ToNode( aItem );
541 LIB_TREE_NODE* parent = node ? node->m_Parent : nullptr;
542
543 // wxDataViewModel has no root node, but rather top-level elements have
544 // an invalid (null) parent.
545 if( !node || !parent || parent->m_Type == LIB_TREE_NODE::TYPE::ROOT )
546 return ToItem( nullptr );
547 else
548 return ToItem( parent );
549}

References LIB_TREE_MODEL_ADAPTER::m_freeze, LIB_TREE_NODE::m_Parent, LIB_TREE_NODE::m_Type, LIB_TREE_MODEL_ADAPTER::ToItem(), and LIB_TREE_MODEL_ADAPTER::ToNode().

Referenced by LIB_TREE_MODEL_ADAPTER::UpdateSearchString().

◆ GetPinningSymbol()

◆ GetShownColumns()

std::vector< wxString > LIB_TREE_MODEL_ADAPTER::GetShownColumns ( ) const
inlineinherited

Definition at line 191 of file lib_tree_model_adapter.h.

191{ return m_shownColumns; }
std::vector< wxString > m_shownColumns

References LIB_TREE_MODEL_ADAPTER::m_shownColumns.

Referenced by LIB_TREE_MODEL_ADAPTER::SaveSettings().

◆ GetTreeNodeFor()

LIB_TREE_NODE * LIB_TREE_MODEL_ADAPTER::GetTreeNodeFor ( const wxDataViewItem &  aSelection) const
inherited

Definition at line 384 of file lib_tree_model_adapter.cpp.

385{
386 return ToNode( aSelection );
387}

References LIB_TREE_MODEL_ADAPTER::ToNode().

◆ GetTypeFor()

LIB_TREE_NODE::TYPE LIB_TREE_MODEL_ADAPTER::GetTypeFor ( const wxDataViewItem &  aSelection) const
inherited

Return node type for the given item.

Parameters
aSelectionitem from the wxDataViewCtrl (see wxDataViewCtrl::GetSelection())
Returns
Type of the selected node, might be INVALID.

Definition at line 377 of file lib_tree_model_adapter.cpp.

378{
379 const LIB_TREE_NODE* node = ToNode( aSelection );
380 return node ? node->m_Type : LIB_TREE_NODE::INVALID;
381}

References LIB_TREE_NODE::INVALID, LIB_TREE_NODE::m_Type, and LIB_TREE_MODEL_ADAPTER::ToNode().

◆ GetUnitFor()

int LIB_TREE_MODEL_ADAPTER::GetUnitFor ( const wxDataViewItem &  aSelection) const
inherited

Return the unit for the given item.

Parameters
aSelectionitem from the wxDataViewCtrl (see wxDataViewCtrl::GetSelection())
Returns
Unit, or zero if the alias itself is selected. Return valid is invalid if GetAliasFor() returns nullptr.

Definition at line 370 of file lib_tree_model_adapter.cpp.

371{
372 const LIB_TREE_NODE* node = ToNode( aSelection );
373 return node ? node->m_Unit : 0;
374}

References LIB_TREE_NODE::m_Unit, and LIB_TREE_MODEL_ADAPTER::ToNode().

◆ GetValue()

void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue ( wxVariant &  aVariant,
wxDataViewItem const &  aItem,
unsigned int  aCol 
) const
overrideprotected

Definition at line 211 of file symbol_tree_synchronizing_adapter.cpp.

213{
214 if( IsFrozen() )
215 {
216 aVariant = wxEmptyString;
217 return;
218 }
219
220 LIB_TREE_NODE* node = ToNode( aItem );
221 wxASSERT( node );
222
223 switch( aCol )
224 {
225 case NAME_COL:
226 if( m_frame->GetCurSymbol() && m_frame->GetCurSymbol()->GetLibId() == node->m_LibId )
228
229 if( node->m_Pinned )
230 aVariant = GetPinningSymbol() + UnescapeString( node->m_Name );
231 else
232 aVariant = UnescapeString( node->m_Name );
233
234 // mark modified items with an asterisk
235 if( node->m_Type == LIB_TREE_NODE::LIB )
236 {
237 if( m_libMgr->IsLibraryModified( node->m_Name ) )
238 aVariant = aVariant.GetString() + " *";
239 }
240 else if( node->m_Type == LIB_TREE_NODE::LIBID )
241 {
242 if( m_libMgr->IsSymbolModified( node->m_Name, node->m_Parent->m_Name ) )
243 aVariant = aVariant.GetString() + " *";
244 }
245
246 break;
247
248 case DESC_COL:
249 if( m_frame->GetCurSymbol() && m_frame->GetCurSymbol()->GetLibId() == node->m_LibId )
250 {
252 }
253 else if( node->m_Type == LIB_TREE_NODE::LIB )
254 {
256 SYMBOL_LIB_TABLE_ROW* lib = libMgr.GetLibrary( node->m_LibId.GetLibNickname() );
257
258 if( lib )
259 node->m_Desc = lib->GetDescr();
260 }
261
262 aVariant = node->m_Desc;
263
264 // Annotate that the library failed to load in the description column
265 if( node->m_Type == LIB_TREE_NODE::LIB )
266 {
267 if( !m_libMgr->IsLibraryLoaded( node->m_Name ) )
268 aVariant = _( "(failed to load)" ) + wxS( " " ) + aVariant.GetString();
269 }
270
271 break;
272
273 default: // column == -1 is used for default Compare function
274 aVariant = node->m_Name;
275 break;
276 }
277}
Symbol library management helper that is specific to the symbol library editor frame.
wxString GetDescription() override
Definition: lib_symbol.h:146
const wxString & GetDescr() const
Return the description of the library referenced by this row.
static const wxString GetPinningSymbol()
LIB_SYMBOL_LIBRARY_MANAGER & GetLibManager()
SYMBOL_LIB_TABLE_ROW * GetLibrary(const wxString &aLibrary) const
Find a single library within the (aggregate) library table.
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
#define _(s)
wxString UnescapeString(const wxString &aSource)

References _, LIB_TREE_MODEL_ADAPTER::DESC_COL, SYMBOL_EDIT_FRAME::GetCurSymbol(), LIB_TABLE_ROW::GetDescr(), LIB_SYMBOL::GetDescription(), LIB_SYMBOL::GetLibId(), LIB_ID::GetLibItemName(), SYMBOL_EDIT_FRAME::GetLibManager(), LIB_ID::GetLibNickname(), SYMBOL_LIBRARY_MANAGER::GetLibrary(), LIB_TREE_MODEL_ADAPTER::GetPinningSymbol(), LIB_TREE_MODEL_ADAPTER::IsFrozen(), SYMBOL_LIBRARY_MANAGER::IsLibraryLoaded(), SYMBOL_LIBRARY_MANAGER::IsLibraryModified(), SYMBOL_LIBRARY_MANAGER::IsSymbolModified(), LIB_TREE_NODE::LIB, LIB_TREE_NODE::LIBID, LIB_TREE_NODE::m_Desc, m_frame, LIB_TREE_NODE::m_LibId, m_libMgr, LIB_TREE_NODE::m_Name, LIB_TREE_NODE::m_Parent, LIB_TREE_NODE::m_Pinned, LIB_TREE_NODE::m_Type, LIB_TREE_MODEL_ADAPTER::NAME_COL, LIB_TREE_MODEL_ADAPTER::ToNode(), and UnescapeString().

◆ HasContainerColumns()

bool LIB_TREE_MODEL_ADAPTER::HasContainerColumns ( const wxDataViewItem &  aItem) const
overrideprotectedinherited

Check whether a container has columns too.

Definition at line 522 of file lib_tree_model_adapter.cpp.

523{
524 return IsContainer( aItem );
525}
bool IsContainer(const wxDataViewItem &aItem) const override
Check whether an item can have children.

References LIB_TREE_MODEL_ADAPTER::IsContainer().

◆ IntoArray()

unsigned int LIB_TREE_MODEL_ADAPTER::IntoArray ( const LIB_TREE_NODE aNode,
wxDataViewItemArray &  aChildren 
)
staticprotectedinherited

Convert SYM_TREE_NODE's children to wxDataViewItemArray.

Definition at line 49 of file lib_tree_model_adapter.cpp.

51{
52 unsigned int n = 0;
53
54 for( std::unique_ptr<LIB_TREE_NODE> const& child: aNode.m_Children )
55 {
56 if( child->m_Score > 0 )
57 {
58 aChildren.Add( ToItem( &*child ) );
59 ++n;
60 }
61 }
62
63 return n;
64}

References LIB_TREE_NODE::m_Children, and LIB_TREE_MODEL_ADAPTER::ToItem().

Referenced by LIB_TREE_MODEL_ADAPTER::GetChildren().

◆ IsContainer()

bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::IsContainer ( const wxDataViewItem &  aItem) const
override

Definition at line 60 of file symbol_tree_synchronizing_adapter.cpp.

61{
62 const LIB_TREE_NODE* node = ToNode( aItem );
63 return node ? node->m_Type == LIB_TREE_NODE::LIB : true;
64}

References LIB_TREE_NODE::LIB, LIB_TREE_NODE::m_Type, and LIB_TREE_MODEL_ADAPTER::ToNode().

◆ IsFrozen()

◆ isSymbolModel()

bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::isSymbolModel ( )
inlineoverrideprotectedvirtual

Implements LIB_TREE_MODEL_ADAPTER.

Definition at line 64 of file symbol_tree_synchronizing_adapter.h.

64{ return true; }

◆ OnSize()

void LIB_TREE_MODEL_ADAPTER::OnSize ( wxSizeEvent &  aEvent)
inherited

Definition at line 471 of file lib_tree_model_adapter.cpp.

472{
473 aEvent.Skip();
474}

◆ PinLibrary()

void LIB_TREE_MODEL_ADAPTER::PinLibrary ( LIB_TREE_NODE aTreeNode)
inherited

Definition at line 289 of file lib_tree_model_adapter.cpp.

290{
292 aTreeNode->m_Pinned = true;
293
294 resortTree();
295 m_widget->EnsureVisible( ToItem( aTreeNode ) );
296}
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
virtual bool isSymbolModel()=0
void PinLibrary(const wxString &aLibrary, bool isSymbolLibrary)
Definition: project.cpp:156

References LIB_ID::GetLibNickname(), LIB_TREE_MODEL_ADAPTER::isSymbolModel(), LIB_TREE_NODE::m_LibId, LIB_TREE_MODEL_ADAPTER::m_parent, LIB_TREE_NODE::m_Pinned, LIB_TREE_MODEL_ADAPTER::m_widget, PROJECT::PinLibrary(), KIWAY_HOLDER::Prj(), LIB_TREE_MODEL_ADAPTER::resortTree(), and LIB_TREE_MODEL_ADAPTER::ToItem().

◆ recreateColumns()

void LIB_TREE_MODEL_ADAPTER::recreateColumns ( )
protectedinherited

Definition at line 258 of file lib_tree_model_adapter.cpp.

259{
260 m_widget->ClearColumns();
261
262 m_columns.clear();
263 m_colIdxMap.clear();
264 m_colNameMap.clear();
265
266 // The Item column is always shown
267 doAddColumn( wxT( "Item" ) );
268
269 for( const wxString& colName : m_shownColumns )
270 {
271 if( !m_colNameMap.count( colName ) )
272 doAddColumn( colName, false );
273 }
274}

References LIB_TREE_MODEL_ADAPTER::doAddColumn(), LIB_TREE_MODEL_ADAPTER::m_colIdxMap, LIB_TREE_MODEL_ADAPTER::m_colNameMap, LIB_TREE_MODEL_ADAPTER::m_columns, LIB_TREE_MODEL_ADAPTER::m_shownColumns, and LIB_TREE_MODEL_ADAPTER::m_widget.

Referenced by LIB_TREE_MODEL_ADAPTER::AttachTo(), and LIB_TREE_MODEL_ADAPTER::SetShownColumns().

◆ RefreshTree()

void LIB_TREE_MODEL_ADAPTER::RefreshTree ( )
inherited

Definition at line 477 of file lib_tree_model_adapter.cpp.

478{
479 // Yes, this is an enormous hack. But it works on all platforms, it doesn't suffer
480 // the On^2 sorting issues that ItemChanged() does on OSX, and it doesn't lose the
481 // user's scroll position (which re-attaching or deleting/re-inserting columns does).
482 static int walk = 1;
483
484 std::vector<int> widths;
485
486 for( const wxDataViewColumn* col : m_columns )
487 widths.emplace_back( col->GetWidth() );
488
489 wxASSERT( widths.size() );
490
491 // Only use the widths read back if they are non-zero.
492 // GTK returns the displayed width of the column, which is not calculated immediately
493 if( widths[0] > 0 )
494 {
495 size_t i = 0;
496
497 for( const auto& [ colName, colPtr ] : m_colNameMap )
498 m_colWidths[ colName ] = widths[i++];
499 }
500
501 auto colIt = m_colWidths.begin();
502
503 colIt->second += walk;
504 colIt++;
505
506 if( colIt != m_colWidths.end() )
507 colIt->second -= walk;
508
509 for( const auto& [ colName, colPtr ] : m_colNameMap )
510 {
511 if( colPtr == m_columns[0] )
512 continue;
513
514 wxASSERT( m_colWidths.count( colName ) );
515 colPtr->SetWidth( m_colWidths[ colName ] );
516 }
517
518 walk = -walk;
519}

References LIB_TREE_MODEL_ADAPTER::m_colNameMap, LIB_TREE_MODEL_ADAPTER::m_columns, and LIB_TREE_MODEL_ADAPTER::m_colWidths.

◆ resortTree()

void LIB_TREE_MODEL_ADAPTER::resortTree ( )
protectedinherited

Definition at line 277 of file lib_tree_model_adapter.cpp.

278{
279 Freeze();
280 BeforeReset();
281
283
284 AfterReset();
285 Thaw();
286}
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).

References LIB_TREE_MODEL_ADAPTER::Freeze(), LIB_TREE_MODEL_ADAPTER::m_tree, LIB_TREE_NODE::SortNodes(), and LIB_TREE_MODEL_ADAPTER::Thaw().

Referenced by LIB_TREE_MODEL_ADAPTER::PinLibrary(), and LIB_TREE_MODEL_ADAPTER::UnpinLibrary().

◆ SaveSettings()

void LIB_TREE_MODEL_ADAPTER::SaveSettings ( )
inherited

Save the column widths to the config file.

This requires the tree view to still be valid.

Definition at line 101 of file lib_tree_model_adapter.cpp.

102{
103 if( m_widget )
104 {
106
108 cfg->m_LibTree.column_widths.clear();
109
110 for( const std::pair<const wxString, wxDataViewColumn*>& pair : m_colNameMap )
111 cfg->m_LibTree.column_widths[pair.first] = pair.second->GetWidth();
112 }
113}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:101
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_base.h:93
std::vector< wxString > GetShownColumns() const
std::vector< wxString > columns
Ordered list of visible columns in the tree.
Definition: app_settings.h:130
std::map< wxString, int > column_widths
Column widths, keyed by header name.
Definition: app_settings.h:131

References APP_SETTINGS_BASE::LIB_TREE::column_widths, APP_SETTINGS_BASE::LIB_TREE::columns, LIB_TREE_MODEL_ADAPTER::GetShownColumns(), Kiface(), KIFACE_BASE::KifaceSettings(), LIB_TREE_MODEL_ADAPTER::m_colNameMap, APP_SETTINGS_BASE::m_LibTree, and LIB_TREE_MODEL_ADAPTER::m_widget.

Referenced by SYMBOL_VIEWER_FRAME::OnSelectSymbol(), SCH_BASE_FRAME::PickSymbolFromLibTree(), and PCB_BASE_FRAME::SelectFootprintFromLibTree().

◆ SetFilter()

void LIB_TREE_MODEL_ADAPTER::SetFilter ( SYM_FILTER_TYPE  aFilter)
inherited

Set the symbol filter type.

Must be set before adding libraries

Parameters
aFilterif SYM_FILTER_POWER, only power parts are loaded

Definition at line 116 of file lib_tree_model_adapter.cpp.

117{
118 m_filter = aFilter;
119}

References LIB_TREE_MODEL_ADAPTER::m_filter.

Referenced by SCH_BASE_FRAME::PickSymbolFromLibTree().

◆ SetPreselectNode()

void LIB_TREE_MODEL_ADAPTER::SetPreselectNode ( const LIB_ID aLibId,
int  aUnit 
)
inherited

Set the symbol name to be selected if there are no search results.

May be set at any time; updates at the next UpdateSearchString().

Parameters
aLibIdsymbol LIB_ID to be selected
aUnitunit to be selected, if > 0 (0 selects the alias itself)

Definition at line 128 of file lib_tree_model_adapter.cpp.

References LIB_TREE_MODEL_ADAPTER::m_preselect_lib_id, and LIB_TREE_MODEL_ADAPTER::m_preselect_unit.

Referenced by SYMBOL_VIEWER_FRAME::OnSelectSymbol(), SCH_BASE_FRAME::PickSymbolFromLibTree(), and PCB_BASE_FRAME::SelectFootprintFromLibTree().

◆ SetShownColumns()

void LIB_TREE_MODEL_ADAPTER::SetShownColumns ( const std::vector< wxString > &  aColumnNames)
inherited

Sets which columns are shown in the widget.

Invalid column names are discarded.

Parameters
aColumnNamesis an ordered list of column names to show

Definition at line 346 of file lib_tree_model_adapter.cpp.

347{
348 bool recreate = m_shownColumns != aColumnNames;
349
350 m_shownColumns = aColumnNames;
351
352 if( recreate && m_widget )
354}

References LIB_TREE_MODEL_ADAPTER::m_shownColumns, LIB_TREE_MODEL_ADAPTER::m_widget, and LIB_TREE_MODEL_ADAPTER::recreateColumns().

◆ SetValue()

bool LIB_TREE_MODEL_ADAPTER::SetValue ( const wxVariant &  aVariant,
const wxDataViewItem &  aItem,
unsigned int  aCol 
)
inlineoverrideprotectedinherited

Set the value of an item.

Does nothing - this model doesn't support editing.

Definition at line 372 of file lib_tree_model_adapter.h.

374 { return false; }

◆ ShowPreselect()

LIB_TREE_NODE * LIB_TREE_MODEL_ADAPTER::ShowPreselect ( )
privateinherited

Find and expand preselected node.

Return the best match (if any).

Definition at line 661 of file lib_tree_model_adapter.cpp.

662{
663 LIB_TREE_NODE* highScore = nullptr;
664
666 return highScore;
667
668 Find( m_tree,
669 [&]( LIB_TREE_NODE const* n )
670 {
671 if( n->m_Type == LIB_TREE_NODE::LIBID && ( n->m_Children.empty() ||
673 return m_preselect_lib_id == n->m_LibId;
675 return m_preselect_lib_id == n->m_Parent->m_LibId &&
677 else
678 return false;
679 },
680 &highScore );
681
682 if( highScore)
683 {
684 wxDataViewItem item = wxDataViewItem( highScore );
685 m_widget->ExpandAncestors( item );
686 }
687
688 return highScore;
689}
bool IsValid() const
Check if this LID_ID is valid.
Definition: lib_id.h:165

References LIB_TREE_MODEL_ADAPTER::Find(), LIB_ID::IsValid(), LIB_TREE_NODE::LIBID, LIB_TREE_NODE::m_Children, LIB_TREE_NODE::m_LibId, LIB_TREE_NODE::m_Parent, LIB_TREE_MODEL_ADAPTER::m_preselect_lib_id, LIB_TREE_MODEL_ADAPTER::m_preselect_unit, LIB_TREE_MODEL_ADAPTER::m_tree, LIB_TREE_NODE::m_Type, LIB_TREE_NODE::m_Unit, LIB_TREE_MODEL_ADAPTER::m_widget, and LIB_TREE_NODE::UNIT.

Referenced by LIB_TREE_MODEL_ADAPTER::UpdateSearchString().

◆ ShowResults()

LIB_TREE_NODE * LIB_TREE_MODEL_ADAPTER::ShowResults ( )
privateinherited

Find and expand successful search results.

Return the best match (if any).

Definition at line 639 of file lib_tree_model_adapter.cpp.

640{
641 LIB_TREE_NODE* highScore = nullptr;
642
643 Find( m_tree,
644 []( LIB_TREE_NODE const* n )
645 {
646 // return leaf nodes with some level of matching
647 return n->m_Type == LIB_TREE_NODE::TYPE::LIBID && n->m_Score > 1;
648 },
649 &highScore );
650
651 if( highScore)
652 {
653 wxDataViewItem item = wxDataViewItem( highScore );
654 m_widget->ExpandAncestors( item );
655 }
656
657 return highScore;
658}

References LIB_TREE_MODEL_ADAPTER::Find(), LIB_TREE_NODE::m_Score, LIB_TREE_MODEL_ADAPTER::m_tree, LIB_TREE_NODE::m_Type, and LIB_TREE_MODEL_ADAPTER::m_widget.

Referenced by LIB_TREE_MODEL_ADAPTER::UpdateSearchString().

◆ ShowSingleLibrary()

LIB_TREE_NODE * LIB_TREE_MODEL_ADAPTER::ShowSingleLibrary ( )
privateinherited

Find and expand a library if there is only one.

Return the best match (if any).

Definition at line 692 of file lib_tree_model_adapter.cpp.

693{
694 LIB_TREE_NODE* highScore = nullptr;
695
696 Find( m_tree,
697 []( LIB_TREE_NODE const* n )
698 {
699 return n->m_Type == LIB_TREE_NODE::TYPE::LIBID &&
700 n->m_Parent->m_Parent->m_Children.size() == 1;
701 },
702 &highScore );
703
704 if( highScore)
705 {
706 wxDataViewItem item = wxDataViewItem( highScore );
707 m_widget->ExpandAncestors( item );
708 }
709
710 return highScore;
711}

References LIB_TREE_MODEL_ADAPTER::Find(), LIB_TREE_NODE::m_Children, LIB_TREE_NODE::m_Parent, LIB_TREE_MODEL_ADAPTER::m_tree, LIB_TREE_NODE::m_Type, and LIB_TREE_MODEL_ADAPTER::m_widget.

Referenced by LIB_TREE_MODEL_ADAPTER::UpdateSearchString().

◆ ShowUnits()

void LIB_TREE_MODEL_ADAPTER::ShowUnits ( bool  aShow)
inherited

Whether or not to show units.

May be set at any time; updates at the next UpdateSearchString()

Parameters
aShowif true, units are displayed

Definition at line 122 of file lib_tree_model_adapter.cpp.

123{
124 m_show_units = aShow;
125}

References LIB_TREE_MODEL_ADAPTER::m_show_units.

◆ Sync()

void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync ( const wxString &  aForceRefresh,
std::function< void(int, int, const wxString &)>  aProgressCallback 
)

Definition at line 69 of file symbol_tree_synchronizing_adapter.cpp.

71{
72 wxLongLong nextUpdate = wxGetUTCTimeMillis() + (PROGRESS_INTERVAL_MILLIS / 2);
73
75 int i = 0, max = GetLibrariesCount();
76
77 // Process already stored libraries
78 for( auto it = m_tree.m_Children.begin(); it != m_tree.m_Children.end(); /* iteration inside */ )
79 {
80 const wxString& name = it->get()->m_Name;
81
82 if( wxGetUTCTimeMillis() > nextUpdate )
83 {
84 aProgressCallback( i, max, name );
85 nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS;
86 }
87
88 // There is a bug in SYMBOL_LIBRARY_MANAGER::LibraryExists() that uses the buffered
89 // modified libraries before the symbol library table which prevents the library from
90 // being removed from the tree control.
91 if( !m_libMgr->LibraryExists( name, true )
92 || !m_frame->Prj().SchSymbolLibTable()->HasLibrary( name, true )
93 || m_frame->Prj().SchSymbolLibTable()->FindRow( name, true ) !=
94 m_frame->Prj().SchSymbolLibTable()->FindRow( name, false )
95 || name == aForceRefresh )
96 {
97 it = deleteLibrary( it );
98 continue;
99 }
100 else
101 {
102 updateLibrary( *(LIB_TREE_NODE_LIB*) it->get() );
103 }
104
105 ++it;
106 ++i;
107 }
108
109 // Look for new libraries
110 //
111 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
113
114 for( const wxString& libName : m_libMgr->GetLibraryNames() )
115 {
116 if( m_libHashes.count( libName ) == 0 )
117 {
118 if( wxGetUTCTimeMillis() > nextUpdate )
119 {
120 aProgressCallback( i++, max, libName );
121 nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS;
122 }
123
125 bool pinned = alg::contains( cfg->m_Session.pinned_symbol_libs, libName )
126 || alg::contains( project.m_PinnedSymbolLibs, libName );
127
128 LIB_TREE_NODE_LIB& lib_node = DoAddLibraryNode( libName, library->GetDescr(), pinned );
129
130 updateLibrary( lib_node );
131 }
132 }
133
135}
const char * name
Definition: DXF_plotter.cpp:56
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:65
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:148
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Return true if library exists.
LIB_TREE_NODE::PTR_VECTOR::iterator deleteLibrary(LIB_TREE_NODE::PTR_VECTOR::iterator &aLibNodeIt)
int GetLibrariesCount() const override
Return the number of libraries loaded in the tree.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:99
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
std::vector< wxString > pinned_symbol_libs
#define PROGRESS_INTERVAL_MILLIS

References LIB_TREE_NODE::AssignIntrinsicRanks(), alg::contains(), deleteLibrary(), LIB_TREE_MODEL_ADAPTER::DoAddLibraryNode(), SYMBOL_LIBRARY_MANAGER::GetHash(), GetLibrariesCount(), SYMBOL_LIBRARY_MANAGER::GetLibrary(), SYMBOL_LIBRARY_MANAGER::GetLibraryNames(), PROJECT::GetProjectFile(), library, SYMBOL_LIBRARY_MANAGER::LibraryExists(), LIB_TREE_NODE::m_Children, m_frame, m_lastSyncHash, m_libHashes, m_libMgr, COMMON_SETTINGS::m_Session, LIB_TREE_MODEL_ADAPTER::m_tree, name, Pgm(), COMMON_SETTINGS::SESSION::pinned_symbol_libs, KIWAY_HOLDER::Prj(), PROGRESS_INTERVAL_MILLIS, project, and updateLibrary().

Referenced by LIB_SYMBOL_LIBRARY_MANAGER::Sync().

◆ Thaw()

void LIB_TREE_MODEL_ADAPTER::Thaw ( )
inlineinherited

◆ ToItem()

wxDataViewItem LIB_TREE_MODEL_ADAPTER::ToItem ( const LIB_TREE_NODE aNode)
staticprotectedinherited

Convert #SYM_TREE_NODE -> wxDataViewItem.

Definition at line 37 of file lib_tree_model_adapter.cpp.

38{
39 return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
40}

Referenced by LIB_TREE_MODEL_ADAPTER::FindItem(), LIB_TREE_MODEL_ADAPTER::GetParent(), LIB_TREE_MODEL_ADAPTER::IntoArray(), and LIB_TREE_MODEL_ADAPTER::PinLibrary().

◆ ToNode()

◆ UnpinLibrary()

void LIB_TREE_MODEL_ADAPTER::UnpinLibrary ( LIB_TREE_NODE aTreeNode)
inherited

Definition at line 299 of file lib_tree_model_adapter.cpp.

300{
302 aTreeNode->m_Pinned = false;
303
304 resortTree();
305 // Keep focus at top when unpinning
306}
void UnpinLibrary(const wxString &aLibrary, bool isSymbolLibrary)
Definition: project.cpp:177

References LIB_ID::GetLibNickname(), LIB_TREE_MODEL_ADAPTER::isSymbolModel(), LIB_TREE_NODE::m_LibId, LIB_TREE_MODEL_ADAPTER::m_parent, LIB_TREE_NODE::m_Pinned, KIWAY_HOLDER::Prj(), LIB_TREE_MODEL_ADAPTER::resortTree(), and PROJECT::UnpinLibrary().

◆ updateLibrary()

void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary ( LIB_TREE_NODE_LIB aLibNode)
protected

Definition at line 152 of file symbol_tree_synchronizing_adapter.cpp.

153{
154 auto hashIt = m_libHashes.find( aLibNode.m_Name );
155
156 if( hashIt == m_libHashes.end() )
157 {
158 // add a new library
159 for( LIB_SYMBOL* alias : m_libMgr->GetAliases( aLibNode.m_Name ) )
160 aLibNode.AddItem( alias );
161 }
162 else if( hashIt->second != m_libMgr->GetLibraryHash( aLibNode.m_Name ) )
163 {
164 // update an existing library
165 std::list<LIB_SYMBOL*> aliases = m_libMgr->GetAliases( aLibNode.m_Name );
166
167 // remove the common part from the aliases list
168 for( auto nodeIt = aLibNode.m_Children.begin(); nodeIt != aLibNode.m_Children.end(); )
169 {
170 auto aliasIt = std::find_if( aliases.begin(), aliases.end(),
171 [&] ( const LIB_SYMBOL* a )
172 {
173 return a->GetName() == (*nodeIt)->m_LibId.GetLibItemName();
174 } );
175
176 if( aliasIt != aliases.end() )
177 {
178 // alias exists both in the symbol tree and the library manager,
179 // update only the node data.
180 static_cast<LIB_TREE_NODE_LIB_ID*>( nodeIt->get() )->Update( *aliasIt );
181 aliases.erase( aliasIt );
182 ++nodeIt;
183 }
184 else
185 {
186 // node does not exist in the library manager, remove the corresponding node
187 nodeIt = aLibNode.m_Children.erase( nodeIt );
188 }
189 }
190
191 // now the aliases list contains only new aliases that need to be added to the tree
192 for( LIB_SYMBOL* alias : aliases )
193 aLibNode.AddItem( alias );
194 }
195
196 aLibNode.AssignIntrinsicRanks();
197 m_libHashes[aLibNode.m_Name] = m_libMgr->GetLibraryHash( aLibNode.m_Name );
198}
Node type: LIB_ID.
int GetLibraryHash(const wxString &aLibrary) const
Return a library hash value to determine if it has changed.
std::list< LIB_SYMBOL * > GetAliases(const wxString &aLibrary) const

References LIB_TREE_NODE_LIB::AddItem(), LIB_TREE_NODE::AssignIntrinsicRanks(), SYMBOL_LIBRARY_MANAGER::GetAliases(), SYMBOL_LIBRARY_MANAGER::GetLibraryHash(), LIB_TREE_NODE::m_Children, m_libHashes, m_libMgr, and LIB_TREE_NODE::m_Name.

Referenced by Sync().

◆ UpdateSearchString()

void LIB_TREE_MODEL_ADAPTER::UpdateSearchString ( const wxString &  aSearch,
bool  aState 
)
inherited

Set the search string provided by the user.

Parameters
aSearchfull, unprocessed search text
aStateif true, we are keeping the state and so we shouldn't collapse the tree

Definition at line 159 of file lib_tree_model_adapter.cpp.

160{
161 {
162 wxWindowUpdateLocker updateLock( m_widget );
163
164 // Even with the updateLock, wxWidgets sometimes ties its knickers in a knot trying to
165 // run a wxdataview_selection_changed_callback() on a row that has been deleted.
166 // https://bugs.launchpad.net/kicad/+bug/1756255
167 m_widget->UnselectAll();
168
169 // This collapse is required before the call to "Freeze()" below. Once Freeze()
170 // is called, GetParent() will return nullptr. While this works for some calls, it
171 // segfaults when we have any expanded elements b/c the sub units in the tree don't
172 // have explicit references that are maintained over a search
173 // The tree will be expanded again below when we get our matches
174 //
175 // Also note that this cannot happen when we have deleted a symbol as GTK will also
176 // iterate over the tree in this case and find a symbol that has an invalid link
177 // and crash https://gitlab.com/kicad/code/kicad/-/issues/6910
178 if( !aState && !aSearch.IsNull() && m_tree.m_Children.size() )
179 {
180 for( std::unique_ptr<LIB_TREE_NODE>& child: m_tree.m_Children )
181 m_widget->Collapse( wxDataViewItem( &*child ) );
182 }
183
184 // DO NOT REMOVE THE FREEZE/THAW. This freeze/thaw is a flag for this model adapter
185 // that tells it when it shouldn't trust any of the data in the model. When set, it will
186 // not return invalid data to the UI, since this invalid data can cause crashes.
187 // This is different than the update locker, which locks the UI aspects only.
188 Freeze();
189 BeforeReset();
190
192
193 wxStringTokenizer tokenizer( aSearch );
194
195 while( tokenizer.HasMoreTokens() )
196 {
197 wxString lib;
198 wxString term = tokenizer.GetNextToken().Lower();
199
200 if( term.Contains( ":" ) )
201 {
202 lib = term.BeforeFirst( ':' );
203 term = term.AfterFirst( ':' );
204 }
205
206 EDA_COMBINED_MATCHER matcher( term, CTX_LIBITEM );
207
208 m_tree.UpdateScore( matcher, lib );
209 }
210
212 AfterReset();
213 Thaw();
214 }
215
216 LIB_TREE_NODE* bestMatch = ShowResults();
217
218 if( !bestMatch )
219 bestMatch = ShowPreselect();
220
221 if( !bestMatch )
222 bestMatch = ShowSingleLibrary();
223
224 if( bestMatch )
225 {
226 wxDataViewItem item = wxDataViewItem( bestMatch );
227 m_widget->Select( item );
228
229 // Make sure the *parent* item is visible. The selected item is the
230 // first (shown) child of the parent. So it's always right below the parent,
231 // and this way the user can also see what library the selected part belongs to,
232 // without having a case where the selection is off the screen (unless the
233 // window is a single row high, which is unlikely)
234 //
235 // This also happens to circumvent https://bugs.launchpad.net/kicad/+bug/1804400
236 // which appears to be a GTK+3 bug.
237 {
238 wxDataViewItem parent = GetParent( item );
239
240 if( parent.IsOk() )
241 m_widget->EnsureVisible( parent );
242 }
243
244 m_widget->EnsureVisible( item );
245 }
246}
LIB_TREE_NODE * ShowPreselect()
Find and expand preselected node.
LIB_TREE_NODE * ShowSingleLibrary()
Find and expand a library if there is only one.
wxDataViewItem GetParent(const wxDataViewItem &aItem) const override
Get the parent of an item.
LIB_TREE_NODE * ShowResults()
Find and expand successful search results.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher, const wxString &aLib) override
Update the score for this part.
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
@ CTX_LIBITEM

References CTX_LIBITEM, LIB_TREE_MODEL_ADAPTER::Freeze(), LIB_TREE_MODEL_ADAPTER::GetParent(), LIB_TREE_NODE::m_Children, LIB_TREE_MODEL_ADAPTER::m_tree, LIB_TREE_MODEL_ADAPTER::m_widget, LIB_TREE_NODE::ResetScore(), LIB_TREE_MODEL_ADAPTER::ShowPreselect(), LIB_TREE_MODEL_ADAPTER::ShowResults(), LIB_TREE_MODEL_ADAPTER::ShowSingleLibrary(), LIB_TREE_NODE::SortNodes(), LIB_TREE_MODEL_ADAPTER::Thaw(), and LIB_TREE_NODE_ROOT::UpdateScore().

Member Data Documentation

◆ m_availableColumns

std::vector<wxString> LIB_TREE_MODEL_ADAPTER::m_availableColumns
privateinherited

◆ m_colIdxMap

std::map<unsigned, wxString> LIB_TREE_MODEL_ADAPTER::m_colIdxMap
protectedinherited

◆ m_colNameMap

std::map<wxString, wxDataViewColumn*> LIB_TREE_MODEL_ADAPTER::m_colNameMap
privateinherited

◆ m_columns

◆ m_colWidths

std::map<wxString, int> LIB_TREE_MODEL_ADAPTER::m_colWidths
privateinherited

◆ m_filter

SYM_FILTER_TYPE LIB_TREE_MODEL_ADAPTER::m_filter
privateinherited

◆ m_frame

SYMBOL_EDIT_FRAME* SYMBOL_TREE_SYNCHRONIZING_ADAPTER::m_frame
protected

Definition at line 67 of file symbol_tree_synchronizing_adapter.h.

Referenced by GetAttr(), GetContextMenuTool(), GetValue(), and Sync().

◆ m_freeze

int LIB_TREE_MODEL_ADAPTER::m_freeze
privateinherited

◆ m_lastSyncHash

int SYMBOL_TREE_SYNCHRONIZING_ADAPTER::m_lastSyncHash
protected

Definition at line 74 of file symbol_tree_synchronizing_adapter.h.

Referenced by Sync().

◆ m_libHashes

std::map<wxString, int> SYMBOL_TREE_SYNCHRONIZING_ADAPTER::m_libHashes
protected

SYMBOL_LIBRARY_MANAGER hash value returned in the last synchronization.

Definition at line 71 of file symbol_tree_synchronizing_adapter.h.

Referenced by deleteLibrary(), GetLibrariesCount(), Sync(), and updateLibrary().

◆ m_libMgr

SYMBOL_LIBRARY_MANAGER* SYMBOL_TREE_SYNCHRONIZING_ADAPTER::m_libMgr
protected

Hashes to decide whether a library needs an update.

Definition at line 68 of file symbol_tree_synchronizing_adapter.h.

Referenced by GetAttr(), GetLibrariesCount(), GetValue(), Sync(), and updateLibrary().

◆ m_parent

EDA_BASE_FRAME* LIB_TREE_MODEL_ADAPTER::m_parent
privateinherited

◆ m_preselect_lib_id

LIB_ID LIB_TREE_MODEL_ADAPTER::m_preselect_lib_id
privateinherited

◆ m_preselect_unit

int LIB_TREE_MODEL_ADAPTER::m_preselect_unit
privateinherited

◆ m_show_units

bool LIB_TREE_MODEL_ADAPTER::m_show_units
privateinherited

◆ m_shownColumns

std::vector<wxString> LIB_TREE_MODEL_ADAPTER::m_shownColumns
privateinherited

◆ m_tree

◆ m_widget


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