KiCad PCB EDA Suite
FP_TREE_SYNCHRONIZING_ADAPTER Class Reference

#include <fp_tree_synchronizing_adapter.h>

Inheritance diagram for FP_TREE_SYNCHRONIZING_ADAPTER:
FP_TREE_MODEL_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 columns in the tree view. More...
 

Public Member Functions

bool IsContainer (const wxDataViewItem &aItem) const override
 
void Sync ()
 
int GetLibrariesCount () const override
 Return the number of libraries loaded in the tree. More...
 
TOOL_INTERACTIVEGetContextMenuTool () override
 
void AddLibraries (EDA_BASE_FRAME *aParent)
 
wxString GenerateInfo (LIB_ID const &aLibId, int aUnit) override
 
void SaveColWidths ()
 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 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...
 
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 ()
 

Static Public Member Functions

static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTERCreate (FOOTPRINT_EDIT_FRAME *aFrame, FP_LIB_TABLE *aLibs)
 
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_SYNCHRONIZING_ADAPTER (FOOTPRINT_EDIT_FRAME *aFrame, FP_LIB_TABLE *aLibs)
 
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
 
std::vector< LIB_TREE_ITEM * > getFootprints (const wxString &aLibName)
 
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...
 

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

FOOTPRINT_EDIT_FRAMEm_frame
 
std::set< wxString > m_libMap
 
FP_LIB_TABLEm_libs
 
LIB_TREE_NODE_ROOT m_tree
 

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

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
 
wxDataViewColumn * m_col_part
 
wxDataViewColumn * m_col_desc
 
wxDataViewCtrl * m_widget
 
int m_colWidths [NUM_COLS]
 

Detailed Description

Definition at line 33 of file fp_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 119 of file lib_tree_model_adapter.h.

120 {
123 };
@ SYM_FILTER_POWER
list symbols flagged PWR

◆ TREE_COLS

This enum defines the order of the 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 tree columns.

Definition at line 128 of file lib_tree_model_adapter.h.

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

Constructor & Destructor Documentation

◆ FP_TREE_SYNCHRONIZING_ADAPTER()

FP_TREE_SYNCHRONIZING_ADAPTER::FP_TREE_SYNCHRONIZING_ADAPTER ( FOOTPRINT_EDIT_FRAME aFrame,
FP_LIB_TABLE aLibs 
)
protected

Definition at line 48 of file fp_tree_synchronizing_adapter.cpp.

49 :
50 FP_TREE_MODEL_ADAPTER( aFrame, aLibs ),
51 m_frame( aFrame )
52{
53}
FP_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, LIB_TABLE *aLibs)
Constructor; takes a set of libraries to be included in the search.

Referenced by Create().

Member Function Documentation

◆ AddLibraries()

void FP_TREE_MODEL_ADAPTER::AddLibraries ( EDA_BASE_FRAME aParent)
inherited

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:145
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(), FP_TREE_MODEL_ADAPTER::getFootprints(), LIB_TABLE::GetLogicalLibs(), PROJECT::GetProjectFile(), library, FP_TREE_MODEL_ADAPTER::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 186 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 237 of file lib_tree_model_adapter.cpp.

238{
239 wxString itemHead = _( "Item" );
240 wxString descHead = _( "Description" );
241
242 // The extent of the text doesn't take into account the space on either side
243 // in the header, so artificially pad it
244 wxSize itemHeadMinWidth = KIUI::GetTextSize( itemHead + wxT( "MMM" ), aDataViewCtrl );
245 wxSize descHeadMinWidth = KIUI::GetTextSize( descHead + wxT( "MMM" ), aDataViewCtrl );
246
247 // Ensure the part column is wider than the smallest allowable width
248 if( m_colWidths[NAME_COL] < itemHeadMinWidth.x )
249 m_colWidths[NAME_COL] = itemHeadMinWidth.x;
250
251 m_widget = aDataViewCtrl;
252 aDataViewCtrl->SetIndent( kDataViewIndent );
253 aDataViewCtrl->AssociateModel( this );
254 aDataViewCtrl->ClearColumns();
255
256 m_col_part = aDataViewCtrl->AppendTextColumn( itemHead, NAME_COL, wxDATAVIEW_CELL_INERT,
258 m_col_desc = aDataViewCtrl->AppendTextColumn( descHead, DESC_COL, wxDATAVIEW_CELL_INERT,
260
261 m_col_part->SetMinWidth( itemHeadMinWidth.x );
262 m_col_desc->SetMinWidth( descHeadMinWidth.x );
263}
#define _(s)
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...
Definition: ui_common.cpp:70

References _, LIB_TREE_MODEL_ADAPTER::DESC_COL, KIUI::GetTextSize(), kDataViewIndent, LIB_TREE_MODEL_ADAPTER::m_col_desc, LIB_TREE_MODEL_ADAPTER::m_col_part, LIB_TREE_MODEL_ADAPTER::m_colWidths, LIB_TREE_MODEL_ADAPTER::m_widget, and LIB_TREE_MODEL_ADAPTER::NAME_COL.

◆ Create() [1/2]

wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > FP_TREE_MODEL_ADAPTER::Create ( EDA_BASE_FRAME aParent,
LIB_TABLE aLibs 
)
staticinherited

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}

References FP_TREE_MODEL_ADAPTER::FP_TREE_MODEL_ADAPTER().

Referenced by PCB_BASE_FRAME::SelectFootprintFromLibTree().

◆ Create() [2/2]

wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > FP_TREE_SYNCHRONIZING_ADAPTER::Create ( FOOTPRINT_EDIT_FRAME aFrame,
FP_LIB_TABLE aLibs 
)
static

Definition at line 41 of file fp_tree_synchronizing_adapter.cpp.

42{
43 auto* adapter = new FP_TREE_SYNCHRONIZING_ADAPTER( aFrame, aLibs );
44 return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
45}
FP_TREE_SYNCHRONIZING_ADAPTER(FOOTPRINT_EDIT_FRAME *aFrame, FP_LIB_TABLE *aLibs)

References FP_TREE_SYNCHRONIZING_ADAPTER().

Referenced by FOOTPRINT_EDIT_FRAME::initLibraryTree().

◆ deleteLibrary()

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

Definition at line 161 of file fp_tree_synchronizing_adapter.cpp.

162{
163 LIB_TREE_NODE* node = aLibNodeIt->get();
164 m_libMap.erase( node->m_Name );
165 auto it = m_tree.m_Children.erase( aLibNodeIt );
166 return it;
167}
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
PTR_VECTOR m_Children

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

Referenced by Sync().

◆ 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 134 of file lib_tree_model_adapter.cpp.

137{
138 LIB_TREE_NODE_LIB& lib_node = DoAddLibraryNode( aNodeName, aDesc, pinned );
139
140 for( LIB_TREE_ITEM* item: aItemList )
141 lib_node.AddItem( item );
142
143 lib_node.AssignIntrinsicRanks( presorted );
144}
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
Definition: lib_tree_item.h:39
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 Sync().

◆ DoAddLibraryNode()

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

Definition at line 123 of file lib_tree_model_adapter.cpp.

125{
126 LIB_TREE_NODE_LIB& lib_node = m_tree.AddLib( aNodeName, aDesc );
127
128 lib_node.m_Pinned = pinned;
129
130 return lib_node;
131}
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 482 of file lib_tree_model_adapter.cpp.

485{
486 for( std::unique_ptr<LIB_TREE_NODE>& node: aNode.m_Children )
487 {
488 if( aFunc( &*node ) )
489 {
490 if( !(*aHighScore) || node->m_Score > (*aHighScore)->m_Score )
491 (*aHighScore) = &*node;
492 }
493
494 Find( *node, aFunc, aHighScore );
495 }
496}
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 310 of file lib_tree_model_adapter.cpp.

311{
312 for( std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.m_Children )
313 {
314 if( lib->m_Name != aLibId.GetLibNickname() )
315 continue;
316
317 // if part name is not specified, return the library node
318 if( aLibId.GetLibItemName() == "" )
319 return ToItem( lib.get() );
320
321 for( std::unique_ptr<LIB_TREE_NODE>& alias: lib->m_Children )
322 {
323 if( alias->m_Name == aLibId.GetLibItemName() )
324 return ToItem( alias.get() );
325 }
326
327 break; // could not find the part in the requested library
328 }
329
330 return wxDataViewItem();
331}
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:90
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 353 of file lib_tree_model_adapter.cpp.

354{
355 m_col_part->SetWidth( m_colWidths[NAME_COL] );
356 m_col_desc->SetWidth( m_colWidths[DESC_COL] );
357}

References LIB_TREE_MODEL_ADAPTER::DESC_COL, LIB_TREE_MODEL_ADAPTER::m_col_desc, LIB_TREE_MODEL_ADAPTER::m_col_part, LIB_TREE_MODEL_ADAPTER::m_colWidths, and LIB_TREE_MODEL_ADAPTER::NAME_COL.

◆ Freeze()

void LIB_TREE_MODEL_ADAPTER::Freeze ( )
inlineinherited

◆ GenerateInfo()

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

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 FP_TREE_MODEL_ADAPTER::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 266 of file lib_tree_model_adapter.cpp.

267{
268 const LIB_TREE_NODE* node = ToNode( aSelection );
269
270 LIB_ID emptyId;
271
272 if( !node )
273 return emptyId;
274
275 return node->m_LibId;
276}
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:52
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 FP_TREE_SYNCHRONIZING_ADAPTER::GetAttr ( wxDataViewItem const &  aItem,
unsigned int  aCol,
wxDataViewItemAttr &  aAttr 
) const
overrideprotected

Definition at line 236 of file fp_tree_synchronizing_adapter.cpp.

238{
239 if( IsFrozen() )
240 return false;
241
242 // change attributes only for the name field
243 if( aCol != 0 )
244 return false;
245
246 // don't link to a board footprint, even if the FPIDs match
248 return false;
249
250 LIB_TREE_NODE* node = ToNode( aItem );
251 wxCHECK( node, false );
252
253 switch( node->m_Type )
254 {
256 if( node->m_Name == m_frame->GetLoadedFPID().GetLibNickname() )
257 {
258#ifdef __WXGTK__
259 // The native wxGTK+ impl ignores background colour, so set the text colour
260 // instead. Works reasonably well in dark themes, less well in light ones....
261 aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
262#else
263 aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
264 aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
265#endif
266
267 // mark modified libs with bold font
269 aAttr.SetBold( true );
270 }
271 break;
272
274 if( node->m_LibId == m_frame->GetLoadedFPID() )
275 {
276#ifdef __WXGTK__
277 // The native wxGTK+ impl ignores background colour, so set the text colour
278 // instead. Works reasonably well in dark themes, less well in light ones....
279 aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
280#else
281 aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
282 aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
283#endif
284
285 // mark modified part with bold font
287 aAttr.SetBold( true );
288 }
289 break;
290
291 default:
292 return false;
293 }
294
295 return true;
296}
bool IsContentModified() const
Definition: base_screen.h:60
LIB_ID GetLoadedFPID() const
Return the LIB_ID of the part being edited.
enum TYPE m_Type
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.

References LIB_ID::GetLibNickname(), FOOTPRINT_EDIT_FRAME::GetLoadedFPID(), PCB_BASE_FRAME::GetScreen(), BASE_SCREEN::IsContentModified(), FOOTPRINT_EDIT_FRAME::IsCurrentFPFromBoard(), LIB_TREE_MODEL_ADAPTER::IsFrozen(), LIB_TREE_NODE::LIB, LIB_TREE_NODE::LIBID, m_frame, LIB_TREE_NODE::m_LibId, LIB_TREE_NODE::m_Name, LIB_TREE_NODE::m_Type, and LIB_TREE_MODEL_ADAPTER::ToNode().

◆ 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 334 of file lib_tree_model_adapter.cpp.

336{
337 const LIB_TREE_NODE* node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
338
339 if( node->m_Type == LIB_TREE_NODE::TYPE::ROOT
340 || node->m_Type == LIB_TREE_NODE::LIB
341 || ( m_show_units && node->m_Type == LIB_TREE_NODE::TYPE::LIBID ) )
342 {
343 return IntoArray( *node, aChildren );
344 }
345 else
346 {
347 return 0;
348 }
349
350}
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 331 of file lib_tree_model_adapter.h.

331{ return NUM_COLS; }

References LIB_TREE_MODEL_ADAPTER::NUM_COLS.

◆ 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 336 of file lib_tree_model_adapter.h.

336{ return "string"; }

◆ GetContextMenuTool()

TOOL_INTERACTIVE * FP_TREE_SYNCHRONIZING_ADAPTER::GetContextMenuTool ( )
overridevirtual

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 56 of file fp_tree_synchronizing_adapter.cpp.

57{
59}
Module editor specific tools.
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

◆ getFootprints()

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

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
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:73
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 FP_TREE_MODEL_ADAPTER::AddLibraries(), Sync(), and updateLibrary().

◆ GetItemCount()

int LIB_TREE_MODEL_ADAPTER::GetItemCount ( ) const
inherited

Return the number of symbols loaded in the tree.

Definition at line 299 of file lib_tree_model_adapter.cpp.

300{
301 int n = 0;
302
303 for( const std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.m_Children )
304 n += lib->m_Children.size();
305
306 return n;
307}

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 FP_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount ( ) const
overridevirtual

Return the number of libraries loaded in the tree.

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 114 of file fp_tree_synchronizing_adapter.cpp.

115{
116 return GFootprintTable.GetCount();
117}
unsigned GetCount() const
Get the number of rows contained in the table.
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: cvpcb.cpp:134

References LIB_TABLE::GetCount(), and GFootprintTable.

◆ 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 410 of file lib_tree_model_adapter.cpp.

411{
412 if( m_freeze )
413 return ToItem( nullptr );
414
415 LIB_TREE_NODE* node = ToNode( aItem );
416 LIB_TREE_NODE* parent = node ? node->m_Parent : nullptr;
417
418 // wxDataViewModel has no root node, but rather top-level elements have
419 // an invalid (null) parent.
420 if( !node || !parent || parent->m_Type == LIB_TREE_NODE::TYPE::ROOT )
421 return ToItem( nullptr );
422 else
423 return ToItem( parent );
424}
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()

◆ GetTreeNodeFor()

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

Definition at line 293 of file lib_tree_model_adapter.cpp.

294{
295 return ToNode( aSelection );
296}

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 286 of file lib_tree_model_adapter.cpp.

287{
288 const LIB_TREE_NODE* node = ToNode( aSelection );
289 return node ? node->m_Type : LIB_TREE_NODE::INVALID;
290}

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 279 of file lib_tree_model_adapter.cpp.

280{
281 const LIB_TREE_NODE* node = ToNode( aSelection );
282 return node ? node->m_Unit : 0;
283}

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

◆ GetValue()

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

Definition at line 170 of file fp_tree_synchronizing_adapter.cpp.

172{
173 if( IsFrozen() )
174 {
175 aVariant = wxEmptyString;
176 return;
177 }
178
179 LIB_TREE_NODE* node = ToNode( aItem );
180
181 switch( aCol )
182 {
183 case NAME_COL:
185 {
186 // Do not use GetLoadedFPID(); it returns m_footprintNameWhenLoaded.
188
189 // mark modified part with an asterisk
191 aVariant = node->m_Name + wxT( " *" );
192 else
193 aVariant = node->m_Name;
194 }
195 else if( node->m_Pinned )
196 {
197 aVariant = GetPinningSymbol() + node->m_Name;
198 }
199 else
200 {
201 aVariant = node->m_Name;
202 }
203
204 break;
205
206 case DESC_COL:
208 {
210 }
211 else if( node->m_Type == LIB_TREE_NODE::LIB )
212 {
213 try
214 {
215 const FP_LIB_TABLE_ROW* lib =
217
218 if( lib )
219 node->m_Desc = lib->GetDescr();
220 }
221 catch( IO_ERROR& )
222 {
223 }
224 }
225
226 aVariant = node->m_Desc;
227 break;
228
229 default: // column == -1 is used for default Compare function
230 aVariant = node->m_Name;
231 break;
232 }
233}
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:372
const LIB_ID & GetFPID() const
Definition: footprint.h:208
const wxString & GetDescription() const
Definition: footprint.h:214
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
const wxString & GetDescr() const
Return the description of the library referenced by this row.
static const wxString GetPinningSymbol()
BOARD * GetBoard() const

References LIB_TREE_MODEL_ADAPTER::DESC_COL, FP_LIB_TABLE::FindRow(), PCB_BASE_FRAME::GetBoard(), LIB_TABLE_ROW::GetDescr(), FOOTPRINT::GetDescription(), BOARD::GetFirstFootprint(), FOOTPRINT::GetFPID(), LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), FOOTPRINT_EDIT_FRAME::GetLoadedFPID(), LIB_TREE_MODEL_ADAPTER::GetPinningSymbol(), PCB_BASE_FRAME::GetScreen(), GFootprintTable, BASE_SCREEN::IsContentModified(), FOOTPRINT_EDIT_FRAME::IsCurrentFPFromBoard(), LIB_TREE_MODEL_ADAPTER::IsFrozen(), LIB_TREE_NODE::LIB, LIB_TREE_NODE::m_Desc, m_frame, LIB_TREE_NODE::m_LibId, LIB_TREE_NODE::m_Name, LIB_TREE_NODE::m_Pinned, LIB_TREE_NODE::m_Type, LIB_TREE_MODEL_ADAPTER::NAME_COL, and LIB_TREE_MODEL_ADAPTER::ToNode().

◆ HasContainerColumns()

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

Check whether a container has columns too.

Definition at line 397 of file lib_tree_model_adapter.cpp.

398{
399 return IsContainer( aItem );
400}
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 52 of file lib_tree_model_adapter.cpp.

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

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

Referenced by LIB_TREE_MODEL_ADAPTER::GetChildren().

◆ IsContainer()

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

Definition at line 62 of file fp_tree_synchronizing_adapter.cpp.

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

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

◆ IsFrozen()

◆ OnSize()

void LIB_TREE_MODEL_ADAPTER::OnSize ( wxSizeEvent &  aEvent)
inherited

Definition at line 360 of file lib_tree_model_adapter.cpp.

361{
362 m_colWidths[NAME_COL] = m_col_part->GetWidth();
363 m_col_desc->SetWidth( m_colWidths[DESC_COL] );
364
365 // Mandatory in any wxSizeEvent handler:
366 aEvent.Skip();
367}

References LIB_TREE_MODEL_ADAPTER::DESC_COL, LIB_TREE_MODEL_ADAPTER::m_col_desc, LIB_TREE_MODEL_ADAPTER::m_col_part, LIB_TREE_MODEL_ADAPTER::m_colWidths, and LIB_TREE_MODEL_ADAPTER::NAME_COL.

◆ RefreshTree()

void LIB_TREE_MODEL_ADAPTER::RefreshTree ( )
inherited

Definition at line 370 of file lib_tree_model_adapter.cpp.

371{
372 // Yes, this is an enormous hack. But it works on all platforms, it doesn't suffer
373 // the On^2 sorting issues that ItemChanged() does on OSX, and it doesn't lose the
374 // user's scroll position (which re-attaching or deleting/re-inserting columns does).
375 static int walk = 1;
376
377 int partWidth = m_col_part->GetWidth();
378 int descWidth = m_col_desc->GetWidth();
379
380 // Only use the widths read back if they are non-zero.
381 // GTK returns the displayed width of the column, which is not calculated immediately
382 if( descWidth > 0 )
383 {
384 m_colWidths[NAME_COL] = partWidth;
385 m_colWidths[DESC_COL] = descWidth;
386 }
387
388 m_colWidths[NAME_COL] += walk;
389 m_colWidths[DESC_COL] -= walk;
390
391 m_col_part->SetWidth( m_colWidths[NAME_COL] );
392 m_col_desc->SetWidth( m_colWidths[DESC_COL] );
393 walk = -walk;
394}

References LIB_TREE_MODEL_ADAPTER::DESC_COL, LIB_TREE_MODEL_ADAPTER::m_col_desc, LIB_TREE_MODEL_ADAPTER::m_col_part, LIB_TREE_MODEL_ADAPTER::m_colWidths, and LIB_TREE_MODEL_ADAPTER::NAME_COL.

◆ SaveColWidths()

void LIB_TREE_MODEL_ADAPTER::SaveColWidths ( )
inherited

Save the column widths to the config file.

This requires the tree view to still be valid.

Definition at line 94 of file lib_tree_model_adapter.cpp.

95{
96 if( m_widget )
97 {
99 cfg->m_LibTree.column_width = m_widget->GetColumn( NAME_COL )->GetWidth();
100 }
101}
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

References APP_SETTINGS_BASE::LIB_TREE::column_width, Kiface(), KIFACE_BASE::KifaceSettings(), APP_SETTINGS_BASE::m_LibTree, LIB_TREE_MODEL_ADAPTER::m_widget, and LIB_TREE_MODEL_ADAPTER::NAME_COL.

◆ 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 104 of file lib_tree_model_adapter.cpp.

105{
106 m_filter = aFilter;
107}

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

◆ 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 353 of file lib_tree_model_adapter.h.

355 { 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 521 of file lib_tree_model_adapter.cpp.

522{
523 LIB_TREE_NODE* highScore = nullptr;
524
526 return highScore;
527
528 Find( m_tree,
529 [&]( LIB_TREE_NODE const* n )
530 {
531 if( n->m_Type == LIB_TREE_NODE::LIBID && ( n->m_Children.empty() ||
533 return m_preselect_lib_id == n->m_LibId;
535 return m_preselect_lib_id == n->m_Parent->m_LibId &&
537 else
538 return false;
539 },
540 &highScore );
541
542 if( highScore)
543 {
544 wxDataViewItem item = wxDataViewItem( highScore );
545 m_widget->ExpandAncestors( item );
546 }
547
548 return highScore;
549}
bool IsValid() const
Check if this LID_ID is valid.
Definition: lib_id.h:159

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 499 of file lib_tree_model_adapter.cpp.

500{
501 LIB_TREE_NODE* highScore = nullptr;
502
503 Find( m_tree,
504 []( LIB_TREE_NODE const* n )
505 {
506 // return leaf nodes with some level of matching
507 return n->m_Type == LIB_TREE_NODE::TYPE::LIBID && n->m_Score > 1;
508 },
509 &highScore );
510
511 if( highScore)
512 {
513 wxDataViewItem item = wxDataViewItem( highScore );
514 m_widget->ExpandAncestors( item );
515 }
516
517 return highScore;
518}

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 552 of file lib_tree_model_adapter.cpp.

553{
554 LIB_TREE_NODE* highScore = nullptr;
555
556 Find( m_tree,
557 []( LIB_TREE_NODE const* n )
558 {
559 return n->m_Type == LIB_TREE_NODE::TYPE::LIBID &&
560 n->m_Parent->m_Parent->m_Children.size() == 1;
561 },
562 &highScore );
563
564 if( highScore)
565 {
566 wxDataViewItem item = wxDataViewItem( highScore );
567 m_widget->ExpandAncestors( item );
568 }
569
570 return highScore;
571}

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 110 of file lib_tree_model_adapter.cpp.

111{
112 m_show_units = aShow;
113}

References LIB_TREE_MODEL_ADAPTER::m_show_units.

◆ Sync()

void FP_TREE_SYNCHRONIZING_ADAPTER::Sync ( )

Definition at line 71 of file fp_tree_synchronizing_adapter.cpp.

72{
73 // Process already stored libraries
74 for( auto it = m_tree.m_Children.begin(); it != m_tree.m_Children.end(); )
75 {
76 const wxString& name = it->get()->m_Name;
77
78 // Remove the library if it no longer exists or it exists in both the global and the
79 // project library but the project library entry is disabled.
80 if( !m_libs->HasLibrary( name, true )
81 || m_libs->FindRow( name, true ) != m_libs->FindRow( name, false ) )
82 {
83 it = deleteLibrary( it );
84 continue;
85 }
86
87 updateLibrary( *(LIB_TREE_NODE_LIB*) it->get() );
88 ++it;
89 }
90
91 // Look for new libraries
92 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
94 size_t count = m_libMap.size();
95
96 for( const wxString& libName : m_libs->GetLogicalLibs() )
97 {
98 if( m_libMap.count( libName ) == 0 )
99 {
100 const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName, true );
101 bool pinned = alg::contains( cfg->m_Session.pinned_fp_libs, libName )
102 || alg::contains( project.m_PinnedFootprintLibs, libName );
103
104 DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), pinned, true );
105 m_libMap.insert( libName );
106 }
107 }
108
109 if( m_libMap.size() > count )
111}
const char * name
Definition: DXF_plotter.cpp:56
void updateLibrary(LIB_TREE_NODE_LIB &aLibNode)
LIB_TREE_NODE::PTR_VECTOR::iterator deleteLibrary(LIB_TREE_NODE::PTR_VECTOR::iterator &aLibNodeIt)
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.

References LIB_TREE_NODE::AssignIntrinsicRanks(), alg::contains(), deleteLibrary(), LIB_TREE_MODEL_ADAPTER::DoAddLibrary(), FP_LIB_TABLE::FindRow(), FP_TREE_MODEL_ADAPTER::getFootprints(), LIB_TABLE::GetLogicalLibs(), PROJECT::GetProjectFile(), LIB_TABLE::HasLibrary(), library, LIB_TREE_NODE::m_Children, m_frame, m_libMap, FP_TREE_MODEL_ADAPTER::m_libs, COMMON_SETTINGS::m_Session, LIB_TREE_MODEL_ADAPTER::m_tree, name, Pgm(), COMMON_SETTINGS::SESSION::pinned_fp_libs, KIWAY_HOLDER::Prj(), project, and updateLibrary().

◆ 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 40 of file lib_tree_model_adapter.cpp.

41{
42 return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
43}

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

◆ ToNode()

◆ updateLibrary()

void FP_TREE_SYNCHRONIZING_ADAPTER::updateLibrary ( LIB_TREE_NODE_LIB aLibNode)
protected

Definition at line 120 of file fp_tree_synchronizing_adapter.cpp.

121{
122 std::vector<LIB_TREE_ITEM*> footprints = getFootprints( aLibNode.m_Name );
123
124 // remove the common part from the footprints list
125 for( auto nodeIt = aLibNode.m_Children.begin(); nodeIt != aLibNode.m_Children.end(); )
126 {
127 // Since the list is sorted we can use a binary search to speed up searches within
128 // libraries with lots of footprints.
129 FOOTPRINT_INFO_IMPL dummy( wxEmptyString, (*nodeIt)->m_Name );
130 auto footprintIt = std::lower_bound( footprints.begin(), footprints.end(), &dummy,
131 []( LIB_TREE_ITEM* a, LIB_TREE_ITEM* b )
132 {
133 return StrNumCmp( a->GetName(), b->GetName(), false ) < 0;
134 } );
135
136 if( footprintIt != footprints.end() && dummy.GetName() == (*footprintIt)->GetName() )
137 {
138 // footprint exists both in the lib tree and the footprint info list; just
139 // update the node data
140 static_cast<LIB_TREE_NODE_LIB_ID*>( nodeIt->get() )->Update( *footprintIt );
141 footprints.erase( footprintIt );
142 ++nodeIt;
143 }
144 else
145 {
146 // node does not exist in the library manager, remove the corresponding node
147 nodeIt = aLibNode.m_Children.erase( nodeIt );
148 }
149 }
150
151 // now the footprint list contains only new aliases that need to be added to the tree
152 for( LIB_TREE_ITEM* footprint : footprints )
153 aLibNode.AddItem( footprint );
154
155 aLibNode.AssignIntrinsicRanks();
156 m_libMap.insert( aLibNode.m_Name );
157}
wxString GetName() const override
Definition: lib_symbol.h:137
Node type: LIB_ID.

References LIB_TREE_NODE_LIB::AddItem(), LIB_TREE_NODE::AssignIntrinsicRanks(), dummy(), FP_TREE_MODEL_ADAPTER::getFootprints(), LIB_SYMBOL::GetName(), LIB_TREE_NODE::m_Children, m_libMap, 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 147 of file lib_tree_model_adapter.cpp.

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

References 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_col_desc

wxDataViewColumn* LIB_TREE_MODEL_ADAPTER::m_col_desc
privateinherited

◆ m_col_part

wxDataViewColumn* LIB_TREE_MODEL_ADAPTER::m_col_part
privateinherited

◆ m_colWidths

◆ m_filter

SYM_FILTER_TYPE LIB_TREE_MODEL_ADAPTER::m_filter
privateinherited

◆ m_frame

FOOTPRINT_EDIT_FRAME* FP_TREE_SYNCHRONIZING_ADAPTER::m_frame
protected

Definition at line 60 of file fp_tree_synchronizing_adapter.h.

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

◆ m_freeze

int LIB_TREE_MODEL_ADAPTER::m_freeze
privateinherited

◆ m_libMap

std::set<wxString> FP_TREE_SYNCHRONIZING_ADAPTER::m_libMap
protected

Definition at line 61 of file fp_tree_synchronizing_adapter.h.

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

◆ m_libs

FP_LIB_TABLE* FP_TREE_MODEL_ADAPTER::m_libs
protectedinherited

◆ m_parent

EDA_BASE_FRAME* LIB_TREE_MODEL_ADAPTER::m_parent
privateinherited

Definition at line 396 of file lib_tree_model_adapter.h.

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

◆ m_widget


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