KiCad PCB EDA Suite
FP_TREE_MODEL_ADAPTER Class Reference

#include <fp_tree_model_adapter.h>

Inheritance diagram for FP_TREE_MODEL_ADAPTER:
LIB_TREE_MODEL_ADAPTER FP_TREE_SYNCHRONIZING_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

void AddLibraries (EDA_BASE_FRAME *aParent)
 
wxString GenerateInfo (LIB_ID const &aLibId, int aUnit) 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
 
int GetItemCount () const
 Return the number of symbols loaded in the tree. More...
 
virtual int GetLibrariesCount () const
 Return the number of libraries 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 ()
 
virtual TOOL_INTERACTIVEGetContextMenuTool ()
 
void PinLibrary (LIB_TREE_NODE *aTreeNode)
 
void UnpinLibrary (LIB_TREE_NODE *aTreeNode)
 

Static Public Member Functions

static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTERCreate (EDA_BASE_FRAME *aParent, LIB_TABLE *aLibs)
 Factory function: create a model adapter in a reference-counting container. More...
 
static const wxString GetPinningSymbol ()
 

Protected Member Functions

 FP_TREE_MODEL_ADAPTER (EDA_BASE_FRAME *aParent, LIB_TABLE *aLibs)
 Constructor; takes a set of libraries to be included in the search. More...
 
std::vector< LIB_TREE_ITEM * > getFootprints (const wxString &aLibName)
 
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...
 
bool IsContainer (const wxDataViewItem &aItem) const override
 Check whether an item can have children. 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...
 
void GetValue (wxVariant &aVariant, const wxDataViewItem &aItem, unsigned int aCol) const override
 Get the value of an item. More...
 
bool SetValue (const wxVariant &aVariant, const wxDataViewItem &aItem, unsigned int aCol) override
 Set the value of an item. More...
 
bool GetAttr (const wxDataViewItem &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
 Get any formatting for 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

FP_LIB_TABLEm_libs
 
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 31 of file fp_tree_model_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

◆ FP_TREE_MODEL_ADAPTER()

FP_TREE_MODEL_ADAPTER::FP_TREE_MODEL_ADAPTER ( EDA_BASE_FRAME aParent,
LIB_TABLE aLibs 
)
protected

Constructor; takes a set of libraries to be included in the search.

Definition at line 44 of file fp_tree_model_adapter.cpp.

44 :
45 LIB_TREE_MODEL_ADAPTER( aParent, wxT( "pinned_footprint_libs" ) ),
46 m_libs( (FP_LIB_TABLE*) aLibs )
47{}
LIB_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, const wxString &aPinnedKey)
Create the adapter.

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().

◆ AddLibraries()

void FP_TREE_MODEL_ADAPTER::AddLibraries ( EDA_BASE_FRAME aParent)

Definition at line 50 of file fp_tree_model_adapter.cpp.

51{
52 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
53 PROJECT_FILE& project = aParent->Prj().GetProjectFile();
54
55 for( const wxString& libName : m_libs->GetLogicalLibs() )
56 {
57 const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName, true );
58 bool pinned = alg::contains( cfg->m_Session.pinned_fp_libs, libName )
59 || alg::contains( project.m_PinnedFootprintLibs, libName );
60
61 DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), pinned, true );
62 }
63
65}
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
Definition: fp_lib_table.h:41
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an FP_LIB_TABLE_ROW if aNickName is found in this table or in any chained fall back table frag...
std::vector< LIB_TREE_ITEM * > getFootprints(const wxString &aLibName)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
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.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:65
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:149
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_fp_libs

References LIB_TREE_NODE::AssignIntrinsicRanks(), alg::contains(), LIB_TREE_MODEL_ADAPTER::DoAddLibrary(), FP_LIB_TABLE::FindRow(), getFootprints(), LIB_TABLE::GetLogicalLibs(), PROJECT::GetProjectFile(), library, m_libs, COMMON_SETTINGS::m_Session, LIB_TREE_MODEL_ADAPTER::m_tree, Pgm(), COMMON_SETTINGS::SESSION::pinned_fp_libs, KIWAY_HOLDER::Prj(), and project.

Referenced by FOOTPRINT_EDIT_FRAME::initLibraryTree(), and PCB_BASE_FRAME::SelectFootprintFromLibTree().

◆ 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.

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 > FP_TREE_MODEL_ADAPTER::Create ( EDA_BASE_FRAME aParent,
LIB_TABLE aLibs 
)
static

Factory function: create a model adapter in a reference-counting container.

Parameters
aLibslibrary set from which parts will be loaded

Definition at line 37 of file fp_tree_model_adapter.cpp.

38{
39 auto* adapter = new FP_TREE_MODEL_ADAPTER( aParent, aLibs );
40 return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
41}
FP_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, LIB_TABLE *aLibs)
Constructor; takes a set of libraries to be included in the search.

References FP_TREE_MODEL_ADAPTER().

Referenced by PCB_BASE_FRAME::SelectFootprintFromLibTree().

◆ 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(), 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 SYMBOL_TREE_SYNCHRONIZING_ADAPTER::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 ...
PTR_VECTOR m_Children

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()

wxString FP_TREE_MODEL_ADAPTER::GenerateInfo ( LIB_ID const &  aLibId,
int  aUnit 
)
overridevirtual

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 91 of file fp_tree_model_adapter.cpp.

92{
93 return GenerateFootprintInfo( m_libs, aLibId );
94}
wxString GenerateFootprintInfo(FP_LIB_TABLE *aFpLibTable, LIB_ID const &aLibId)
Return an HTML page describing a LIB_ID in a FP_LIB_TABLE.

References GenerateFootprintInfo(), and m_libs.

◆ 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.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.

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

◆ GetAttr()

bool LIB_TREE_MODEL_ADAPTER::GetAttr ( const wxDataViewItem &  aItem,
unsigned int  aCol,
wxDataViewItemAttr &  aAttr 
) const
overrideprotectedinherited

Get any formatting for an item.

Parameters
aItemitem to get formatting for
aColcolumn number of interest
aAttrreceiver for attributes
Returns
true if the item has non-default attributes

Definition at line 593 of file lib_tree_model_adapter.cpp.

596{
597 if( IsFrozen() )
598 return false;
599
600 LIB_TREE_NODE* node = ToNode( aItem );
601 wxASSERT( node );
602
603 if( node->m_Type != LIB_TREE_NODE::LIBID )
604 {
605 // Currently only aliases are formatted at all
606 return false;
607 }
608
609 if( !node->m_IsRoot && aCol == 0 )
610 {
611 // Names of non-root aliases are italicized
612 aAttr.SetItalic( true );
613 return true;
614 }
615 else
616 {
617 return false;
618 }
619}
enum TYPE m_Type

References LIB_TREE_MODEL_ADAPTER::IsFrozen(), LIB_TREE_NODE::LIBID, LIB_TREE_NODE::m_IsRoot, LIB_TREE_NODE::m_Type, 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()

virtual TOOL_INTERACTIVE * LIB_TREE_MODEL_ADAPTER::GetContextMenuTool ( )
inlinevirtualinherited

Reimplemented in SYMBOL_TREE_SYNCHRONIZING_ADAPTER, and FP_TREE_SYNCHRONIZING_ADAPTER.

Definition at line 301 of file lib_tree_model_adapter.h.

301{ return nullptr; }

◆ GetFilter()

SYM_FILTER_TYPE LIB_TREE_MODEL_ADAPTER::GetFilter ( ) const
inlineinherited

◆ getFootprints()

std::vector< LIB_TREE_ITEM * > FP_TREE_MODEL_ADAPTER::getFootprints ( const wxString &  aLibName)
protected

Definition at line 68 of file fp_tree_model_adapter.cpp.

69{
70 std::vector<LIB_TREE_ITEM*> libList;
71
72 auto fullListStart = GFootprintList.GetList().begin();
73 auto fullListEnd = GFootprintList.GetList().end();
74 std::unique_ptr<FOOTPRINT_INFO> dummy = std::make_unique<FOOTPRINT_INFO_IMPL>( aLibName, wxEmptyString );
75
76 // List is sorted, so use a binary search to find the range of footnotes for our library
77 auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy,
78 []( const std::unique_ptr<FOOTPRINT_INFO>& a,
79 const std::unique_ptr<FOOTPRINT_INFO>& b )
80 {
81 return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), false ) < 0;
82 } );
83
84 for( auto i = libBounds.first; i != libBounds.second; ++i )
85 libList.push_back( i->get() );
86
87 return libList;
88}
const FPILIST & GetList() const
Was forced to add this by modview_frame.cpp.
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: cvpcb.cpp:140
std::vector< FAB_LAYER_COLOR > dummy
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.

References dummy, FOOTPRINT_LIST::GetList(), GFootprintList, and StrNumCmp().

Referenced by AddLibraries(), FP_TREE_SYNCHRONIZING_ADAPTER::Sync(), and FP_TREE_SYNCHRONIZING_ADAPTER::updateLibrary().

◆ 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()

virtual int LIB_TREE_MODEL_ADAPTER::GetLibrariesCount ( ) const
inlinevirtualinherited

Return the number of libraries loaded in the tree.

Reimplemented in SYMBOL_TREE_SYNCHRONIZING_ADAPTER, and FP_TREE_SYNCHRONIZING_ADAPTER.

Definition at line 270 of file lib_tree_model_adapter.h.

271 {
272 return m_tree.m_Children.size();
273 }

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

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount().

◆ 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}
LIB_TREE_NODE * m_Parent

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 LIB_TREE_MODEL_ADAPTER::GetValue ( wxVariant &  aVariant,
const wxDataViewItem &  aItem,
unsigned int  aCol 
) const
overrideprotectedinherited

Get the value of an item.

Parameters
aVariantwxVariant to receive the data
aItemitem whose data will be placed into aVariant
aColcolumn number of the data

Definition at line 552 of file lib_tree_model_adapter.cpp.

555{
556 if( IsFrozen() )
557 {
558 aVariant = wxEmptyString;
559 return;
560 }
561
562 LIB_TREE_NODE* node = ToNode( aItem );
563 wxASSERT( node );
564
565 switch( aCol )
566 {
567 case NAME_COL:
568 if( node->m_Pinned )
569 aVariant = GetPinningSymbol() + UnescapeString( node->m_Name );
570 else
571 aVariant = UnescapeString( node->m_Name );
572
573 break;
574
575 default:
576 if( m_colIdxMap.count( aCol ) )
577 {
578 const wxString& key = m_colIdxMap.at( aCol );
579
580 if( node->m_Fields.count( key ) )
581 aVariant = node->m_Fields.at( key );
582 else if( key == wxT( "Description" ) )
583 aVariant = node->m_Desc;
584 else
585 aVariant = wxEmptyString;
586 }
587
588 break;
589 }
590}
static const wxString GetPinningSymbol()
std::map< wxString, wxString > m_Fields
wxString UnescapeString(const wxString &aSource)

References LIB_TREE_MODEL_ADAPTER::GetPinningSymbol(), LIB_TREE_MODEL_ADAPTER::IsFrozen(), LIB_TREE_MODEL_ADAPTER::m_colIdxMap, LIB_TREE_NODE::m_Desc, LIB_TREE_NODE::m_Fields, LIB_TREE_NODE::m_Name, LIB_TREE_NODE::m_Pinned, 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 LIB_TREE_MODEL_ADAPTER::IsContainer ( const wxDataViewItem &  aItem) const
overrideprotectedinherited

Check whether an item can have children.

Definition at line 528 of file lib_tree_model_adapter.cpp.

529{
530 LIB_TREE_NODE* node = ToNode( aItem );
531 return node ? node->m_Children.size() : true;
532}

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

Referenced by LIB_TREE_MODEL_ADAPTER::HasContainerColumns().

◆ IsFrozen()

◆ isSymbolModel()

bool FP_TREE_MODEL_ADAPTER::isSymbolModel ( )
inlineoverrideprotectedvirtual

Implements LIB_TREE_MODEL_ADAPTER.

Definition at line 54 of file fp_tree_model_adapter.h.

54{ return false; }

◆ 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

◆ 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:110
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:139
std::map< wxString, int > column_widths
Column widths, keyed by header name.
Definition: app_settings.h:140

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.

◆ 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().

◆ 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_freeze

int LIB_TREE_MODEL_ADAPTER::m_freeze
privateinherited

◆ m_libs

FP_LIB_TABLE* FP_TREE_MODEL_ADAPTER::m_libs
protected

◆ 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: