29#include <wx/tokenzr.h>
30#include <wx/wupdlock.h>
39 return wxDataViewItem(
const_cast<void*
>(
static_cast<void const*
>( aNode ) ) );
50 wxDataViewItemArray& aChildren )
54 for( std::unique_ptr<LIB_TREE_NODE>
const& child: aNode.
m_Children )
56 if( child->m_Score > 0 )
58 aChildren.Add(
ToItem( &*child ) );
68 const wxString& aPinnedKey ) :
70 m_filter( SYM_FILTER_NONE ),
72 m_preselect_unit( 0 ),
110 for(
const std::pair<const wxString, wxDataViewColumn*>& pair :
m_colNameMap )
136 const wxString& aDesc,
bool pinned )
147 const std::vector<LIB_TREE_ITEM*>& aItemList,
148 bool pinned,
bool presorted )
162 wxWindowUpdateLocker updateLock(
m_widget );
181 m_widget->Collapse( wxDataViewItem( &*child ) );
193 wxStringTokenizer tokenizer( aSearch );
195 while( tokenizer.HasMoreTokens() )
198 wxString term = tokenizer.GetNextToken().Lower();
200 if( term.Contains(
":" ) )
202 lib = term.BeforeFirst(
':' );
203 term = term.AfterFirst(
':' );
226 wxDataViewItem item = wxDataViewItem( bestMatch );
238 wxDataViewItem parent =
GetParent( item );
253 aDataViewCtrl->AssociateModel(
this );
311 wxString translatedHeader = aTranslate ? wxGetTranslation( aHeader ) : aHeader;
322 wxDataViewColumn* ret =
m_widget->AppendTextColumn( translatedHeader, index,
323 wxDATAVIEW_CELL_INERT,
325 ret->SetMinWidth( headerMinWidth.x );
373 return node ? node->
m_Unit : 0;
386 return ToNode( aSelection );
395 n += lib->m_Children.size();
410 return ToItem( lib.get() );
412 for( std::unique_ptr<LIB_TREE_NODE>& alias: lib->m_Children )
415 return ToItem( alias.get() );
421 return wxDataViewItem();
426 wxDataViewItemArray& aChildren )
const
430 if( node->
m_Type == LIB_TREE_NODE::TYPE::ROOT
446 wxDataViewColumn* col =
nullptr;
451 for( ; idx <
m_columns.size() - 1; idx++ )
461 totalWidth += col->GetWidth();
464 int remainingWidth =
m_widget->GetSize().x - totalWidth;
484 std::vector<int> widths;
486 for(
const wxDataViewColumn* col :
m_columns )
487 widths.emplace_back( col->GetWidth() );
489 wxASSERT( widths.size() );
503 colIt->second += walk;
507 colIt->second -= walk;
545 if( !node || !parent || parent->
m_Type == LIB_TREE_NODE::TYPE::ROOT )
553 const wxDataViewItem& aItem,
554 unsigned int aCol )
const
558 aVariant = wxEmptyString;
581 aVariant = node->
m_Fields.at( key );
582 else if( key == wxT(
"Description" ) )
585 aVariant = wxEmptyString;
595 wxDataViewItemAttr& aAttr )
const
612 aAttr.SetItalic(
true );
626 for( std::unique_ptr<LIB_TREE_NODE>& node: aNode.
m_Children )
628 if( aFunc( &*node ) )
630 if( !(*aHighScore) || node->m_Score > (*aHighScore)->m_Score )
631 (*aHighScore) = &*node;
634 Find( *node, aFunc, aHighScore );
647 return n->
m_Type == LIB_TREE_NODE::TYPE::LIBID && n->
m_Score > 1;
653 wxDataViewItem item = wxDataViewItem( highScore );
684 wxDataViewItem item = wxDataViewItem( highScore );
699 return n->
m_Type == LIB_TREE_NODE::TYPE::LIBID &&
706 wxDataViewItem item = wxDataViewItem( highScore );
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
The base frame for deriving all KiCad main window classes.
APP_SETTINGS_BASE * KifaceSettings() const
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A logical library item identifier and consists of various portions much like a URI.
bool IsValid() const
Check if this LID_ID is valid.
const UTF8 & GetLibItemName() const
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
int GetUnitFor(const wxDataViewItem &aSelection) const
Return the unit for the given item.
LIB_ID m_preselect_lib_id
LIB_TREE_NODE::TYPE GetTypeFor(const wxDataViewItem &aSelection) const
Return node type for the given item.
bool GetAttr(const wxDataViewItem &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
Get any formatting for an item.
LIB_TREE_NODE_ROOT m_tree
std::map< wxString, int > m_colWidths
void FinishTreeInitialization()
A final-stage initialization to be called after the window hierarchy has been realized and the window...
void addColumnIfNecessary(const wxString &aHeader)
void PinLibrary(LIB_TREE_NODE *aTreeNode)
void OnSize(wxSizeEvent &aEvent)
LIB_TREE_NODE_LIB & DoAddLibraryNode(const wxString &aNodeName, const wxString &aDesc, bool pinned)
void SetPreselectNode(const LIB_ID &aLibId, int aUnit)
Set the symbol name to be selected if there are no search results.
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> #SYM_TREE_NODE.
LIB_ID GetAliasFor(const wxDataViewItem &aSelection) const
Return the alias for the given item.
~LIB_TREE_MODEL_ADAPTER()
Destructor.
void AttachTo(wxDataViewCtrl *aDataViewCtrl)
Attach to a wxDataViewCtrl and initialize it.
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 SetShownColumns(const std::vector< wxString > &aColumnNames)
Sets which columns are shown in the widget.
static wxDataViewItem ToItem(const LIB_TREE_NODE *aNode)
Convert #SYM_TREE_NODE -> wxDataViewItem.
void SetFilter(SYM_FILTER_TYPE aFilter)
Set the symbol filter type.
virtual bool isSymbolModel()=0
bool IsContainer(const wxDataViewItem &aItem) const override
Check whether an item can have children.
static const wxString GetPinningSymbol()
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 ...
void ShowUnits(bool aShow)
Whether or not to show units.
LIB_TREE_NODE * GetTreeNodeFor(const wxDataViewItem &aSelection) const
unsigned int GetChildren(const wxDataViewItem &aItem, wxDataViewItemArray &aChildren) const override
Populate a list of all the children of an item.
void SaveSettings()
Save the column widths to the config file.
@ NAME_COL
Library or library item name column.
std::map< unsigned, wxString > m_colIdxMap
wxDataViewColumn * doAddColumn(const wxString &aHeader, bool aTranslate=true)
LIB_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, const wxString &aPinnedKey)
Create the adapter.
LIB_TREE_NODE * ShowPreselect()
Find and expand preselected node.
std::vector< wxDataViewColumn * > m_columns
std::vector< wxString > GetShownColumns() const
wxDataViewCtrl * m_widget
int GetItemCount() const
Return the number of symbols loaded in the tree.
std::vector< wxString > m_shownColumns
void GetValue(wxVariant &aVariant, const wxDataViewItem &aItem, unsigned int aCol) const override
Get the value of an item.
void UnpinLibrary(LIB_TREE_NODE *aTreeNode)
LIB_TREE_NODE * ShowSingleLibrary()
Find and expand a library if there is only one.
std::map< wxString, wxDataViewColumn * > m_colNameMap
bool HasContainerColumns(const wxDataViewItem &aItem) const override
Check whether a container has columns too.
wxDataViewItem GetParent(const wxDataViewItem &aItem) const override
Get the parent of an item.
std::vector< wxString > m_availableColumns
EDA_BASE_FRAME * m_parent
static unsigned int IntoArray(const LIB_TREE_NODE &aNode, wxDataViewItemArray &aChildren)
Convert SYM_TREE_NODE's children to wxDataViewItemArray.
LIB_TREE_NODE * ShowResults()
Find and expand successful search results.
wxDataViewItem FindItem(const LIB_ID &aLibId)
Returns tree item corresponding to part.
void UpdateSearchString(const wxString &aSearch, bool aState)
Set the search string provided by the user.
SYM_FILTER_TYPE
This enum allows a selective filtering of symbols to list.
LIB_TREE_NODE_LIB_ID & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher, const wxString &aLib) override
Update the score for this part.
LIB_TREE_NODE_LIB & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
std::map< wxString, wxString > m_Fields
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
void UnpinLibrary(const wxString &aLibrary, bool isSymbolLibrary)
void PinLibrary(const wxString &aLibrary, bool isSymbolLibrary)
Base window classes and related definitions.
Abstract pattern-matching tool and implementations.
static const int kDataViewIndent
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...
wxString UnescapeString(const wxString &aSource)
std::vector< wxString > columns
Ordered list of visible columns in the tree.
std::map< wxString, int > column_widths
Column widths, keyed by header name.
Functions to provide common constants and other functions to assist in making a consistent UI.