30 #include <wx/tokenzr.h> 31 #include <wx/wupdlock.h> 35 #define PINNED_ITEMS_KEY wxT( "PinnedItems" ) 42 return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
48 return static_cast<LIB_TREE_NODE*>( aItem.GetID() );
53 wxDataViewItemArray& aChildren )
57 for( std::unique_ptr<LIB_TREE_NODE>
const& child: aNode.
m_Children )
59 if( child->m_Score > 0 )
61 aChildren.Add(
ToItem( &*child ) );
71 const wxString& aPinnedKey ) :
73 m_filter( SYM_FILTER_NONE ),
75 m_preselect_unit( 0 ),
77 m_col_part( nullptr ),
78 m_col_desc( nullptr ),
81 m_pinnedKey( aPinnedKey )
93 std::vector<wxString>& entries = (
m_pinnedKey == wxT(
"pinned_symbol_libs" ) ) ?
97 for(
const wxString& entry : entries )
120 std::vector<wxString>& entries = (
m_pinnedKey == wxT(
"pinned_symbol_libs" ) ) ?
129 if( child->m_Pinned )
131 m_pinnedLibs.push_back( child->m_LibId.GetLibNickname() );
132 entries.push_back( child->m_LibId.GetLibNickname() );
160 const wxString& aDesc )
171 const std::vector<LIB_TREE_ITEM*>& aItemList,
186 wxWindowUpdateLocker updateLock(
m_widget );
205 m_widget->Collapse( wxDataViewItem( &*child ) );
219 if( child->m_Pinned )
223 wxStringTokenizer tokenizer( aSearch );
225 while( tokenizer.HasMoreTokens() )
228 wxString term = tokenizer.GetNextToken().Lower();
230 if( term.Contains(
":" ) )
232 lib = term.BeforeFirst(
':' );
233 term = term.AfterFirst(
':' );
256 wxDataViewItem item = wxDataViewItem( bestMatch );
268 wxDataViewItem parent =
GetParent( item );
281 wxString partHead =
_(
"Item" );
282 wxString descHead =
_(
"Description" );
286 wxSize partHeadMinWidth =
KIUI::GetTextSize( partHead + wxT(
"MMM" ), aDataViewCtrl );
294 aDataViewCtrl->AssociateModel(
this );
295 aDataViewCtrl->ClearColumns();
297 m_col_part = aDataViewCtrl->AppendTextColumn( partHead,
PART_COL, wxDATAVIEW_CELL_INERT,
299 m_col_desc = aDataViewCtrl->AppendTextColumn( descHead,
DESC_COL, wxDATAVIEW_CELL_INERT,
302 m_col_part->SetMinWidth( partHeadMinWidth.x );
322 return node ? node->
m_Unit : 0;
335 return ToNode( aSelection );
344 n += lib->m_Children.size();
359 return ToItem( lib.get() );
361 for( std::unique_ptr<LIB_TREE_NODE>& alias: lib->m_Children )
364 return ToItem( alias.get() );
370 return wxDataViewItem();
375 wxDataViewItemArray& aChildren )
const 379 if( node->
m_Type == LIB_TREE_NODE::TYPE::ROOT
450 if( !node || !parent || parent->
m_Type == LIB_TREE_NODE::TYPE::ROOT )
458 const wxDataViewItem& aItem,
459 unsigned int aCol )
const 463 aVariant = wxEmptyString;
485 wxDataViewItemAttr& aAttr )
const 502 aAttr.SetItalic(
true );
516 for( std::unique_ptr<LIB_TREE_NODE>& node: aNode.
m_Children )
518 if( aFunc( &*node ) )
520 wxDataViewItem item = wxDataViewItem( &*node );
523 if( !(*aHighScore) || node->m_Score > (*aHighScore)->m_Score )
524 (*aHighScore) = &*node;
540 return n->
m_Type == LIB_TREE_NODE::TYPE::LIBID && n->
m_Score > 1;
580 return n->
m_Type == LIB_TREE_NODE::TYPE::LIBID &&
~LIB_TREE_MODEL_ADAPTER()
Destructor.
bool HasContainerColumns(const wxDataViewItem &aItem) const override
Check whether a container has columns too.
const UTF8 & GetLibItemName() const
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
bool IsContainer(const wxDataViewItem &aItem) const override
Check whether an item can have children.
void SetFilter(SYM_FILTER_TYPE aFilter)
Set the symbol filter type.
LIB_TREE_NODE_LIB & DoAddLibraryNode(const wxString &aNodeName, const wxString &aDesc)
void UpdateSearchString(const wxString &aSearch, bool aState)
Set the search string provided by the user.
unsigned int GetChildren(const wxDataViewItem &aItem, wxDataViewItemArray &aChildren) const override
Populate a list of all the children of an item.
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
wxDataViewColumn * m_col_desc
void FindAndExpand(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 ...
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
int GetUnitFor(const wxDataViewItem &aSelection) const
Return the unit for the given item.
virtual PROJECT_FILE & GetProjectFile() const
void SetPreselectNode(const LIB_ID &aLibId, int aUnit)
Set the symbol name to be selected if there are no search results.
EDA_BASE_FRAME * m_parent
LIB_TREE_NODE * ShowResults()
Find and expand successful search results.
bool GetAttr(const wxDataViewItem &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
Get any formatting for an item.
LIB_TREE_NODE::TYPE GetTypeFor(const wxDataViewItem &aSelection) const
Return node type for the given item.
LIB_TREE_NODE * ShowPreselect()
Find and expand preselected node.
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
LIB_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, const wxString &aPinnedKey)
Create the adapter.
The backing store for a PROJECT, in JSON format.
SYM_FILTER_TYPE
This enum allows a selective filtering of symbols to list.
static wxDataViewItem ToItem(const LIB_TREE_NODE *aNode)
Convert #SYM_TREE_NODE -> wxDataViewItem.
Abstract pattern-matching tool and implementations.
LIB_TREE_NODE * GetTreeNodeFor(const wxDataViewItem &aSelection) const
static const int kDataViewIndent
int GetItemCount() const
Return the number of symbols loaded in the tree.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
LIB_TREE_NODE_LIB_ID & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
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...
wxDataViewItem GetParent(const wxDataViewItem &aItem) const override
Get the parent of an item.
void FinishTreeInitialization()
A final-stage initialization to be called after the window hierarchy has been realized and the window...
Base window classes and related definitions.
Functions to provide common constants and other functions to assist in making a consistent UI.
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> #SYM_TREE_NODE.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
static unsigned int IntoArray(const LIB_TREE_NODE &aNode, wxDataViewItemArray &aChildren)
Convert SYM_TREE_NODE's children to wxDataViewItemArray.
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
void GetValue(wxVariant &aVariant, const wxDataViewItem &aItem, unsigned int aCol) const override
Get the value of an item.
wxString UnescapeString(const wxString &aSource)
LIB_TREE_NODE_LIB & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.
int m_colWidths[NUM_COLS]
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher, const wxString &aLib) override
Update the score for this part.
LIB_ID GetAliasFor(const wxDataViewItem &aSelection) const
Return the alias for the given item.
void DoAddLibrary(const wxString &aNodeName, const wxString &aDesc, const std::vector< LIB_TREE_ITEM * > &aItemList, bool presorted)
Add the given list of symbols by alias.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
wxDataViewCtrl * m_widget
The base frame for deriving all KiCad main window classes.
LIB_ID m_preselect_lib_id
wxArrayString m_pinnedLibs
APP_SETTINGS_BASE * KifaceSettings() const
wxDataViewItem FindItem(const LIB_ID &aLibId)
Returns tree item corresponding to part.
wxDataViewColumn * m_col_part
LIB_TREE_NODE_ROOT m_tree
LIB_TREE_NODE * ShowSingleLibrary()
Find and expand a library if there is only one.
void SaveColWidths()
Save the column widths to the config file.
void AttachTo(wxDataViewCtrl *aDataViewCtrl)
Attach to a wxDataViewCtrl and initialize it.
void ShowUnits(bool aShow)
Whether or not to show units.