31#include <wx/tokenzr.h> 
   32#include <wx/wupdlock.h> 
   33#include <wx/settings.h> 
   51        return wxSize( GetOwner()->GetWidth(), GetTextExtent( 
m_text ).y + 2 );
 
 
   54    bool GetValue( wxVariant& aValue )
 const override 
 
   60    bool SetValue( 
const wxVariant& aValue )
 override 
   62        m_text = aValue.GetString();
 
 
   66    void SetAttr( 
const wxDataViewItemAttr& aAttr )
 override 
   71        wxDataViewItemAttr realAttr = aAttr;
 
   72        realAttr.SetStrikethrough( 
false );
 
   74        wxDataViewCustomRenderer::SetAttr( realAttr );
 
 
   77    bool Render( wxRect aRect, wxDC *dc, 
int aState )
 override 
   79        RenderBackground( dc, aRect );
 
   84            points[0] = aRect.GetTopLeft();
 
   85            points[1] = aRect.GetTopRight() + wxPoint( -4, 0 );
 
   86            points[2] = aRect.GetTopRight() + wxPoint( 0, aRect.GetHeight() / 2 );
 
   87            points[3] = aRect.GetBottomRight() + wxPoint( -4, 1 );
 
   88            points[4] = aRect.GetBottomLeft() + wxPoint( 0, 1 );
 
   89            points[5] = aRect.GetTopLeft();
 
   92            dc->DrawLines( 6, points );
 
  101        if( aState & wxDATAVIEW_CELL_SELECTED )
 
  102            dc->SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
 
  104        RenderText( 
m_text, 0, aRect, dc, 0 );
 
  106        RenderText( 
m_text, 0, aRect, dc, aState );
 
 
 
  119    return wxDataViewItem( 
const_cast<void*
>( 
static_cast<void const*
>( aNode ) ) );
 
 
  130                                                const wxString& aPinnedKey,
 
  135        m_cfg( aSettingsStruct ),
 
  148    for( 
const std::pair<const wxString, int>& pair : 
m_cfg.column_widths )
 
 
  167    std::vector<wxString> openLibs;
 
  168    wxDataViewItem        rootItem( 
nullptr );
 
  169    wxDataViewItemArray   children;
 
  173    for( 
const wxDataViewItem& child : children )
 
  176            openLibs.emplace_back( 
ToNode( child )->m_LibId.GetLibNickname().wx_str() );
 
 
  185    wxWindowUpdateLocker updateLock( 
m_widget );
 
  187    for( 
const wxString& lib : aLibs )
 
 
  202        m_cfg.column_widths.clear();
 
  204        for( 
const std::pair<const wxString, wxDataViewColumn*>& pair : 
m_colNameMap )
 
  207                m_cfg.column_widths[pair.first] = pair.second->GetWidth();
 
 
  229                                                                 const wxString& aDesc,
 
 
  241                                                             const wxString& aDesc,
 
  242                                                             const std::vector<LIB_TREE_ITEM*>& aItemList,
 
  243                                                             bool pinned, 
bool presorted )
 
 
  258    m_tree.RemoveGroup( aRecentGroup, aPlacedGroup );
 
 
  265        wxWindowUpdateLocker updateLock( 
m_widget );
 
  281        if( !aState && !aSearch.IsNull() && 
m_tree.m_Children.size() )
 
  283            for( std::unique_ptr<LIB_TREE_NODE>& child: 
m_tree.m_Children )
 
  284                m_widget->Collapse( wxDataViewItem( &*child ) );
 
  296        constexpr int MAX_TERMS = 100;
 
  298        wxStringTokenizer                                  tokenizer( aSearch, 
" \t\r\n", wxTOKEN_STRTOK );
 
  299        std::vector<std::unique_ptr<EDA_COMBINED_MATCHER>> termMatchers;
 
  301        while( tokenizer.HasMoreTokens() && termMatchers.size() < MAX_TERMS )
 
  303            wxString term = tokenizer.GetNextToken().Lower();
 
  304            termMatchers.emplace_back( std::make_unique<EDA_COMBINED_MATCHER>( term, 
CTX_LIBITEM ) );
 
  327        wxDataViewItem item = 
ToItem( firstMatch );
 
  338            wxDataViewItem parent = 
GetParent( item );
 
 
  353    aDataViewCtrl->AssociateModel( 
this );
 
 
  377            doAddColumn( colName, colName == wxT( 
"Description" ) );
 
 
  418    for( 
const std::unique_ptr<LIB_TREE_NODE>& lib: 
m_tree.m_Children )
 
  420        if( lib->m_IsRecentlyUsedGroup )
 
  421            lib->m_Name = wxT( 
"-- " ) + 
_( 
"Recently Used" ) + wxT( 
" --" );
 
  422        else if( lib->m_IsAlreadyPlacedGroup )
 
  423            lib->m_Name = wxT( 
"-- " ) + 
_( 
"Already Placed" ) + wxT( 
" --" );
 
 
  430    wxString translatedHeader = aTranslate ? wxGetTranslation( aHeader ) : aHeader;
 
  441    wxDataViewColumn* col = 
new wxDataViewColumn(
 
  443            wxDATAVIEW_CELL_INERT | 
static_cast<int>( wxDATAVIEW_COL_RESIZABLE ) );
 
  446    col->SetMinWidth( headerMinWidth.x );
 
 
  476    for( std::unique_ptr<LIB_TREE_NODE>& lib: 
m_tree.m_Children )
 
 
  491    return node ? node->
m_Unit : 0;
 
 
  498    return node ? node->
m_Type : LIB_TREE_NODE::TYPE::INVALID;
 
 
  504    return ToNode( aSelection );
 
 
  512    for( 
const std::unique_ptr<LIB_TREE_NODE>& lib: 
m_tree.m_Children )
 
  513        n += lib->m_Children.size();
 
 
  521    for( std::unique_ptr<LIB_TREE_NODE>& lib: 
m_tree.m_Children )
 
  528            return ToItem( lib.get() );
 
  530        for( std::unique_ptr<LIB_TREE_NODE>& alias: lib->m_Children )
 
  533                return ToItem( alias.get() );
 
  539    return wxDataViewItem();
 
 
  550                                                  wxDataViewItemArray&    aChildren )
 const 
  553    unsigned int         count = 0;
 
  555    if( node->
m_Type == LIB_TREE_NODE::TYPE::ROOT
 
  556            || node->
m_Type == LIB_TREE_NODE::TYPE::LIBRARY
 
  559        for( std::unique_ptr<LIB_TREE_NODE> 
const& child: node->
m_Children )
 
  561            if( child->m_Score > 0 )
 
  563                aChildren.Add( 
ToItem( &*child ) );
 
 
  575    wxDataViewColumn* col        = 
nullptr;
 
  580    for( ; idx < 
m_columns.size() - 1; idx++ )
 
  590        totalWidth += col->GetWidth();
 
  593    int remainingWidth = 
m_widget->GetSize().x - totalWidth;
 
 
  607    std::vector<int> widths;
 
  609    for( 
const wxDataViewColumn* col : 
m_columns )
 
  610        widths.emplace_back( col->GetWidth() );
 
  612    wxASSERT( widths.size() );
 
  626    colIt->second += walk;
 
  630        colIt->second -= walk;
 
 
  668    if( !node || !parent || parent->
m_Type == LIB_TREE_NODE::TYPE::ROOT )
 
 
  676                                       const wxDataViewItem&   aItem,
 
  677                                       unsigned int            aCol )
 const 
  681        aVariant = wxEmptyString;
 
  704            if( key == wxT( 
"Description" ) )
 
  706            else if( node->
m_Fields.count( key ) )
 
  709                valueStr = wxEmptyString;
 
  715    valueStr.Replace( wxS( 
"\n" ), wxS( 
" " ) ); 
 
 
  723                                      wxDataViewItemAttr&     aAttr )
 const 
  729    wxCHECK( node, 
false );
 
  731    if( node->
m_Type == LIB_TREE_NODE::TYPE::ITEM )
 
  736            aAttr.SetItalic( 
true );
 
 
  747    for( std::unique_ptr<LIB_TREE_NODE>& node: aNode.
m_Children )
 
  749        int r = f( node.get() );
 
 
  769                if( n->
m_Type == LIB_TREE_NODE::TYPE::ITEM && n->
m_Score > 1 )
 
  789                    if( n->
m_Name.StartsWith( 
"-- " ) )
 
  792                    if( n->
m_Type == LIB_TREE_NODE::TYPE::ITEM
 
  800                    else if( n->
m_Type == LIB_TREE_NODE::TYPE::UNIT
 
  818        for( 
const std::unique_ptr<LIB_TREE_NODE>& child : 
m_tree.m_Children )
 
  820            if( !child->m_Name.StartsWith( 
"-- " ) )
 
  830                    if( n->
m_Type == LIB_TREE_NODE::TYPE::ITEM )
 
 
The base frame for deriving all KiCad main window classes.
 
A logical library item identifier and consists of various portions much like a URI.
 
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).
 
LIB_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, const wxString &aPinnedKey, APP_SETTINGS_BASE::LIB_TREE &aSettingsStruct)
Create the adapter.
 
void createMissingColumns()
 
std::vector< wxString > GetOpenLibs() const
 
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.
 
APP_SETTINGS_BASE::LIB_TREE & m_cfg
 
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)
 
virtual PROJECT::LIB_TYPE_T getLibType()=0
 
virtual wxDataViewItem GetCurrentDataViewItem()
 
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 SetShownColumns(const std::vector< wxString > &aColumnNames)
Sets which columns are shown in the widget.
 
std::function< void()> m_lazyLoadHandler
 
static wxDataViewItem ToItem(const LIB_TREE_NODE *aNode)
Convert #SYM_TREE_NODE -> wxDataViewItem.
 
bool IsContainer(const wxDataViewItem &aItem) const override
Check whether an item can have children.
 
static const wxString GetPinningSymbol()
 
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)
 
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.
 
void ShowChangedLanguage()
 
const LIB_TREE_NODE * ShowResults()
Find and expand successful search results.
 
std::vector< wxString > m_shownColumns
 
void RemoveGroup(bool aRecentlyUsedGroup, bool aAlreadyPlacedGroup)
Remove one of the system groups from the library.
 
void GetValue(wxVariant &aVariant, const wxDataViewItem &aItem, unsigned int aCol) const override
Get the value of an item.
 
void UnpinLibrary(LIB_TREE_NODE *aTreeNode)
 
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.
 
LIB_TREE_NODE_LIBRARY & DoAddLibraryNode(const wxString &aNodeName, const wxString &aDesc, bool pinned)
 
std::vector< wxString > m_availableColumns
 
EDA_BASE_FRAME * m_parent
 
LIB_TREE_NODE_LIBRARY & 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.
 
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.
 
std::function< bool(LIB_TREE_NODE &aNode)> * m_filter
 
void OpenLibs(const std::vector< wxString > &aLibs)
 
LIB_TREE_NODE_ITEM & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
 
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
 
std::map< wxString, wxString > m_Fields
List of weighted search terms.
 
void AssignIntrinsicRanks(const std::vector< wxString > &aShownColumns, bool presorted=false)
Store intrinsic ranks on all children of this node.
 
void SetAttr(const wxDataViewItemAttr &aAttr) override
 
bool SetValue(const wxVariant &aValue) override
 
wxSize GetSize() const override
 
bool GetValue(wxVariant &aValue) const override
 
bool Render(wxRect aRect, wxDC *dc, int aState) override
 
static void recursiveDescent(wxSizer *aSizer, std::map< int, wxString > &aLabels)
 
Base window classes and related definitions.
 
Abstract pattern-matching tool and implementations.
 
void recursiveDescent(LIB_TREE_NODE &aNode, const std::function< int(const LIB_TREE_NODE *)> &f)
 
static const int kDataViewIndent
 
KICOMMON_API 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)
 
Functions to provide common constants and other functions to assist in making a consistent UI.