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 { PART_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 ()
 
wxString GenerateInfo (LIB_ID const &aLibId, int aUnit) override
 
void SaveColWidths ()
 Save the column widths to the config file. More...
 
void SavePinnedItems ()
 
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 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...
 
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...
 

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 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...
 
const wxString GetPinningSymbol () const
 

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
 

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

◆ TREE_COLS

This enum defines the order of the columns in the tree view.

Enumerator
PART_COL 

Part name column.

DESC_COL 

Part description column.

NUM_COLS 

The number of tree columns.

Definition at line 118 of file lib_tree_model_adapter.h.

119  {
120  PART_COL = 0,
121  DESC_COL,
122  NUM_COLS
123  };

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 46 of file fp_tree_synchronizing_adapter.cpp.

47  :
48  FP_TREE_MODEL_ADAPTER( aFrame, aLibs ),
49  m_frame( aFrame )
50 {
51 }
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 ( )
inherited

Definition at line 45 of file fp_tree_model_adapter.cpp.

46 {
47  for( const wxString& libName : m_libs->GetLogicalLibs() )
48  {
49  const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName, true );
50 
51  DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true );
52  }
53 
55 }
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
Definition: fp_lib_table.h:40
std::vector< LIB_TREE_ITEM * > getFootprints(const wxString &aLibName)
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.
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< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.

References LIB_TREE_NODE::AssignIntrinsicRanks(), LIB_TREE_MODEL_ADAPTER::DoAddLibrary(), FP_LIB_TABLE::FindRow(), FP_TREE_MODEL_ADAPTER::getFootprints(), LIB_TABLE::GetLogicalLibs(), library, FP_TREE_MODEL_ADAPTER::m_libs, and LIB_TREE_MODEL_ADAPTER::m_tree.

Referenced by PCB_BASE_FRAME::SelectFootprintFromLibTree().

◆ AssignIntrinsicRanks()

void LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks ( )
inlineinherited

Sort the tree and assign ranks after adding libraries.

Definition at line 176 of file lib_tree_model_adapter.h.

void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.

References LIB_TREE_NODE::AssignIntrinsicRanks(), and LIB_TREE_MODEL_ADAPTER::m_tree.

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

272 {
273  wxString partHead = _( "Item" );
274  wxString descHead = _( "Description" );
275 
276  // The extent of the text doesn't take into account the space on either side
277  // in the header, so artificially pad it
278  wxSize partHeadMinWidth = KIUI::GetTextSize( partHead + "MMM", aDataViewCtrl );
279 
280  // Ensure the part column is wider than the smallest allowable width
281  if( m_colWidths[PART_COL] < partHeadMinWidth.x )
282  m_colWidths[PART_COL] = partHeadMinWidth.x;
283 
284  m_widget = aDataViewCtrl;
285  aDataViewCtrl->SetIndent( kDataViewIndent );
286  aDataViewCtrl->AssociateModel( this );
287  aDataViewCtrl->ClearColumns();
288 
289  m_col_part = aDataViewCtrl->AppendTextColumn( partHead, PART_COL, wxDATAVIEW_CELL_INERT,
291  m_col_desc = aDataViewCtrl->AppendTextColumn( descHead, DESC_COL, wxDATAVIEW_CELL_INERT,
293 
294  m_col_part->SetMinWidth( partHeadMinWidth.x );
295 }
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:66
#define _(s)

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

◆ Create() [1/2]

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

Definition at line 39 of file fp_tree_synchronizing_adapter.cpp.

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

References FP_TREE_SYNCHRONIZING_ADAPTER().

Referenced by FOOTPRINT_EDIT_FRAME::initLibraryTree().

◆ Create() [2/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 32 of file fp_tree_model_adapter.cpp.

33 {
34  auto* adapter = new FP_TREE_MODEL_ADAPTER( aParent, aLibs );
35  return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
36 }
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::FP_TREE_MODEL_ADAPTER().

Referenced by PCB_BASE_FRAME::SelectFootprintFromLibTree().

◆ deleteLibrary()

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

Definition at line 154 of file fp_tree_synchronizing_adapter.cpp.

156 {
157  LIB_TREE_NODE* node = aLibNodeIt->get();
158  m_libMap.erase( node->m_Name );
159  auto it = m_tree.m_Children.erase( aLibNodeIt );
160  return it;
161 }
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  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 170 of file lib_tree_model_adapter.cpp.

173 {
174  LIB_TREE_NODE_LIB& lib_node = DoAddLibraryNode( aNodeName, aDesc );
175 
176  for( LIB_TREE_ITEM* item: aItemList )
177  lib_node.AddItem( item );
178 
179  lib_node.AssignIntrinsicRanks( presorted );
180 }
LIB_TREE_NODE_LIB & DoAddLibraryNode(const wxString &aNodeName, const wxString &aDesc)
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
Definition: lib_tree_item.h:38
LIB_TREE_NODE_LIB_ID & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
Node type: library.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.

References LIB_TREE_NODE_LIB::AddItem(), LIB_TREE_NODE::AssignIntrinsicRanks(), and LIB_TREE_MODEL_ADAPTER::DoAddLibraryNode().

Referenced by FP_TREE_MODEL_ADAPTER::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), and Sync().

◆ DoAddLibraryNode()

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

Definition at line 159 of file lib_tree_model_adapter.cpp.

161 {
162  LIB_TREE_NODE_LIB& lib_node = m_tree.AddLib( aNodeName, aDesc );
163 
164  lib_node.m_Pinned = m_pinnedLibs.Index( lib_node.m_LibId.GetLibNickname() ) != wxNOT_FOUND;
165 
166  return lib_node;
167 }
Node type: library.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:90
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_ID::GetLibNickname(), LIB_TREE_NODE::m_LibId, LIB_TREE_NODE::m_Pinned, LIB_TREE_MODEL_ADAPTER::m_pinnedLibs, and LIB_TREE_MODEL_ADAPTER::m_tree.

Referenced by LIB_TREE_MODEL_ADAPTER::DoAddLibrary(), and SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync().

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

343 {
344  for( std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.m_Children )
345  {
346  if( lib->m_Name != aLibId.GetLibNickname() )
347  continue;
348 
349  // if part name is not specified, return the library node
350  if( aLibId.GetLibItemName() == "" )
351  return ToItem( lib.get() );
352 
353  for( std::unique_ptr<LIB_TREE_NODE>& alias: lib->m_Children )
354  {
355  if( alias->m_Name == aLibId.GetLibItemName() )
356  return ToItem( alias.get() );
357  }
358 
359  break; // could not find the part in the requested library
360  }
361 
362  return wxDataViewItem();
363 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
static wxDataViewItem ToItem(const LIB_TREE_NODE *aNode)
Convert #SYM_TREE_NODE -> wxDataViewItem.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:90
PTR_VECTOR m_Children

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

380 {
381  m_col_part->SetWidth( m_colWidths[PART_COL] );
382  m_col_desc->SetWidth( m_colWidths[DESC_COL] );
383 }

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::PART_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 81 of file fp_tree_model_adapter.cpp.

82 {
83  return GenerateFootprintInfo( m_libs, aLibId );
84 }
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 298 of file lib_tree_model_adapter.cpp.

299 {
300  const LIB_TREE_NODE* node = ToNode( aSelection );
301 
302  LIB_ID emptyId;
303 
304  if( !node )
305  return emptyId;
306 
307  return node->m_LibId;
308 }
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
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 FP_TREE_SYNCHRONIZING_ADAPTER::GetAttr ( wxDataViewItem const &  aItem,
unsigned int  aCol,
wxDataViewItemAttr &  aAttr 
) const
overrideprotected

Definition at line 224 of file fp_tree_synchronizing_adapter.cpp.

226 {
227  if( IsFrozen() )
228  return false;
229 
230  // change attributes only for the name field
231  if( aCol != 0 )
232  return false;
233 
234  // don't link to a board footprint, even if the FPIDs match
236  return false;
237 
238  auto node = ToNode( aItem );
239  wxCHECK( node, false );
240 
241  switch( node->m_Type )
242  {
243  case LIB_TREE_NODE::LIB:
244  if( node->m_Name == m_frame->GetLoadedFPID().GetLibNickname() )
245  {
246 #ifdef __WXGTK__
247  // The native wxGTK+ impl ignores background colour, so set the text colour
248  // instead. Works reasonably well in dark themes, less well in light ones....
249  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
250 #else
251  aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
252  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
253 #endif
254 
255  // mark modified libs with bold font
257  aAttr.SetBold( true );
258  }
259  break;
260 
262  if( node->m_LibId == m_frame->GetLoadedFPID() )
263  {
264 #ifdef __WXGTK__
265  // The native wxGTK+ impl ignores background colour, so set the text colour
266  // instead. Works reasonably well in dark themes, less well in light ones....
267  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
268 #else
269  aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
270  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
271 #endif
272 
273  // mark modified part with bold font
275  aAttr.SetBold( true );
276  }
277  break;
278 
279  default:
280  return false;
281  }
282 
283  return true;
284 }
bool IsContentModified() const
Definition: base_screen.h:60
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.
Definition: lib_id.h:90
LIB_ID GetLoadedFPID() const
Return the LIB_ID of the part being edited.
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, 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 366 of file lib_tree_model_adapter.cpp.

368 {
369  const LIB_TREE_NODE* node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
370 
371  if( node->m_Type != LIB_TREE_NODE::TYPE::LIBID
372  || ( m_show_units && node->m_Type == LIB_TREE_NODE::TYPE::LIBID ) )
373  return IntoArray( *node, aChildren );
374  else
375  return 0;
376 }
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> #SYM_TREE_NODE.
static unsigned int IntoArray(const LIB_TREE_NODE &aNode, wxDataViewItemArray &aChildren)
Convert SYM_TREE_NODE's children to wxDataViewItemArray.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
enum TYPE m_Type

References LIB_TREE_MODEL_ADAPTER::IntoArray(), 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 319 of file lib_tree_model_adapter.h.

319 { 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 324 of file lib_tree_model_adapter.h.

324 { return "string"; }

◆ GetContextMenuTool()

TOOL_INTERACTIVE * FP_TREE_SYNCHRONIZING_ADAPTER::GetContextMenuTool ( )
overridevirtual

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 54 of file fp_tree_synchronizing_adapter.cpp.

55 {
57 }
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

Return the active filter.

Definition at line 142 of file lib_tree_model_adapter.h.

142 { return m_filter; }

References LIB_TREE_MODEL_ADAPTER::m_filter.

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibraries(), and SYMBOL_TREE_MODEL_ADAPTER::AddLibrary().

◆ getFootprints()

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

Definition at line 58 of file fp_tree_model_adapter.cpp.

59 {
60  std::vector<LIB_TREE_ITEM*> libList;
61 
62  auto fullListStart = GFootprintList.GetList().begin();
63  auto fullListEnd = GFootprintList.GetList().end();
64  std::unique_ptr<FOOTPRINT_INFO> dummy = std::make_unique<FOOTPRINT_INFO_IMPL>( aLibName, wxEmptyString );
65 
66  // List is sorted, so use a binary search to find the range of footnotes for our library
67  auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy,
68  []( const std::unique_ptr<FOOTPRINT_INFO>& a,
69  const std::unique_ptr<FOOTPRINT_INFO>& b )
70  {
71  return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), false ) < 0;
72  } );
73 
74  for( auto i = libBounds.first; i != libBounds.second; ++i )
75  libList.push_back( i->get() );
76 
77  return libList;
78 }
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:71
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 331 of file lib_tree_model_adapter.cpp.

332 {
333  int n = 0;
334 
335  for( const std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.m_Children )
336  n += lib->m_Children.size();
337 
338  return n;
339 }
PTR_VECTOR m_Children

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

Referenced by 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 108 of file fp_tree_synchronizing_adapter.cpp.

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

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

427 {
428  if( m_freeze )
429  return ToItem( nullptr );
430 
431  LIB_TREE_NODE* node = ToNode( aItem );
432  LIB_TREE_NODE* parent = node ? node->m_Parent : nullptr;
433 
434  // wxDataViewModel has no root node, but rather top-level elements have
435  // an invalid (null) parent.
436  if( !node || !parent || parent->m_Type == LIB_TREE_NODE::TYPE::ROOT )
437  return ToItem( nullptr );
438  else
439  return ToItem( parent );
440 }
static wxDataViewItem ToItem(const LIB_TREE_NODE *aNode)
Convert #SYM_TREE_NODE -> wxDataViewItem.
LIB_TREE_NODE * m_Parent
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> #SYM_TREE_NODE.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
enum TYPE m_Type

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

const wxString LIB_TREE_MODEL_ADAPTER::GetPinningSymbol ( ) const
inlineprotectedinherited
Returns
a unicode string to mark a node name like a pinned library name This is not an ASCII7 char, but a unicode char

Definition at line 362 of file lib_tree_model_adapter.h.

363  {
364  return wxString::FromUTF8( "☆ " );
365  }

Referenced by GetValue(), and SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue().

◆ GetTreeNodeFor()

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

Definition at line 325 of file lib_tree_model_adapter.cpp.

326 {
327  return ToNode( aSelection );
328 }
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> #SYM_TREE_NODE.

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

319 {
320  const LIB_TREE_NODE* node = ToNode( aSelection );
321  return node ? node->m_Type : LIB_TREE_NODE::INVALID;
322 }
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> #SYM_TREE_NODE.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
enum TYPE m_Type

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

312 {
313  const LIB_TREE_NODE* node = ToNode( aSelection );
314  return node ? node->m_Unit : 0;
315 }
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_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 164 of file fp_tree_synchronizing_adapter.cpp.

166 {
167  if( IsFrozen() )
168  {
169  aVariant = wxEmptyString;
170  return;
171  }
172 
173  auto node = ToNode( aItem );
174 
175  switch( aCol )
176  {
177  case 0:
178  if( node->m_LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() )
179  {
180  node->m_Name = m_frame->GetLoadedFPID().GetLibItemName();
181 
182  // mark modified part with an asterisk
184  aVariant = node->m_Name + " *";
185  else
186  aVariant = node->m_Name;
187  }
188  else if( node->m_Pinned )
189  aVariant = GetPinningSymbol() + node->m_Name;
190  else
191  aVariant = node->m_Name;
192  break;
193 
194  case 1:
195  if( node->m_LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() )
196  {
197  node->m_Desc = m_frame->GetBoard()->GetFirstFootprint()->GetDescription();
198  }
199  else if( node->m_Type == LIB_TREE_NODE::LIB )
200  {
201  try
202  {
203  const FP_LIB_TABLE_ROW* lib =
204  GFootprintTable.FindRow( node->m_LibId.GetLibNickname() );
205 
206  if( lib )
207  node->m_Desc = lib->GetDescr();
208  }
209  catch( IO_ERROR& )
210  {
211  }
212  }
213 
214  aVariant = node->m_Desc;
215  break;
216 
217  default: // column == -1 is used for default Compare function
218  aVariant = node->m_Name;
219  break;
220  }
221 }
const wxString & GetDescription() const
Definition: footprint.h:197
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
bool IsContentModified() const
Definition: base_screen.h:60
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: cvpcb.cpp:134
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
Definition: fp_lib_table.h:40
const wxString & GetDescr() const
Return the description of the library referenced by this row.
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:317
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> #SYM_TREE_NODE.
const wxString GetPinningSymbol() const
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...
LIB_ID GetLoadedFPID() const
Return the LIB_ID of the part being edited.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
BOARD * GetBoard() const
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75

References FP_LIB_TABLE::FindRow(), PCB_BASE_FRAME::GetBoard(), LIB_TABLE_ROW::GetDescr(), FOOTPRINT::GetDescription(), BOARD::GetFirstFootprint(), LIB_ID::GetLibItemName(), 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, m_frame, 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 413 of file lib_tree_model_adapter.cpp.

414 {
415  return IsContainer( aItem );
416 }
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 }
static wxDataViewItem ToItem(const LIB_TREE_NODE *aNode)
Convert #SYM_TREE_NODE -> wxDataViewItem.
PTR_VECTOR m_Children

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 60 of file fp_tree_synchronizing_adapter.cpp.

61 {
62  const LIB_TREE_NODE* node = ToNode( aItem );
63  return node ? node->m_Type == LIB_TREE_NODE::LIB : true;
64 }
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> #SYM_TREE_NODE.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
enum TYPE m_Type

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

◆ IsFrozen()

◆ RefreshTree()

void LIB_TREE_MODEL_ADAPTER::RefreshTree ( )
inherited

Definition at line 386 of file lib_tree_model_adapter.cpp.

387 {
388  // Yes, this is an enormous hack. But it works on all platforms, it doesn't suffer
389  // the On^2 sorting issues that ItemChanged() does on OSX, and it doesn't lose the
390  // user's scroll position (which re-attaching or deleting/re-inserting columns does).
391  static int walk = 1;
392 
393  int partWidth = m_col_part->GetWidth();
394  int descWidth = m_col_desc->GetWidth();
395 
396  // Only use the widths read back if they are non-zero.
397  // GTK returns the displayed width of the column, which is not calculated immediately
398  if( descWidth > 0 )
399  {
400  m_colWidths[PART_COL] = partWidth;
401  m_colWidths[DESC_COL] = descWidth;
402  }
403 
404  m_colWidths[PART_COL] += walk;
405  m_colWidths[DESC_COL] -= walk;
406 
407  m_col_part->SetWidth( m_colWidths[PART_COL] );
408  m_col_desc->SetWidth( m_colWidths[DESC_COL] );
409  walk = -walk;
410 }

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::PART_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 106 of file lib_tree_model_adapter.cpp.

107 {
108  if( m_widget )
109  {
111  cfg->m_LibTree.column_width = m_widget->GetColumn( PART_COL )->GetWidth();
112  }
113 }
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_i.h:92
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.

References APP_SETTINGS_BASE::LIB_TREE::column_width, Kiface(), KIFACE_I::KifaceSettings(), APP_SETTINGS_BASE::m_LibTree, LIB_TREE_MODEL_ADAPTER::m_widget, and LIB_TREE_MODEL_ADAPTER::PART_COL.

◆ SavePinnedItems()

void LIB_TREE_MODEL_ADAPTER::SavePinnedItems ( )
inherited

Definition at line 116 of file lib_tree_model_adapter.cpp.

117 {
119 
120  std::vector<wxString>& entries = ( m_pinnedKey == "pinned_symbol_libs" ) ?
121  project.m_PinnedSymbolLibs :
122  project.m_PinnedFootprintLibs;
123 
124  entries.clear();
125  m_pinnedLibs.clear();
126 
127  for( std::unique_ptr<LIB_TREE_NODE>& child: m_tree.m_Children )
128  {
129  if( child->m_Pinned )
130  {
131  m_pinnedLibs.push_back( child->m_LibId.GetLibNickname() );
132  entries.push_back( child->m_LibId.GetLibNickname() );
133  }
134  }
135 
136 
137 }
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition: kiway.cpp:189
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:145
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:64
PTR_VECTOR m_Children

References PROJECT::GetProjectFile(), KIWAY_HOLDER::Kiway(), LIB_TREE_NODE::m_Children, LIB_TREE_MODEL_ADAPTER::m_parent, LIB_TREE_MODEL_ADAPTER::m_pinnedKey, LIB_TREE_MODEL_ADAPTER::m_pinnedLibs, LIB_TREE_MODEL_ADAPTER::m_tree, KIWAY::Prj(), and project.

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

141 {
142  m_filter = aFilter;
143 }

References LIB_TREE_MODEL_ADAPTER::m_filter.

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

153 {
154  m_preselect_lib_id = aLibId;
155  m_preselect_unit = aUnit;
156 }

References LIB_TREE_MODEL_ADAPTER::m_preselect_lib_id, and LIB_TREE_MODEL_ADAPTER::m_preselect_unit.

Referenced by 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 341 of file lib_tree_model_adapter.h.

343  { return false; }

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

147 {
148  m_show_units = aShow;
149 }

References LIB_TREE_MODEL_ADAPTER::m_show_units.

◆ Sync()

void FP_TREE_SYNCHRONIZING_ADAPTER::Sync ( )

Definition at line 69 of file fp_tree_synchronizing_adapter.cpp.

70 {
71  // Process already stored libraries
72  for( auto it = m_tree.m_Children.begin(); it != m_tree.m_Children.end(); )
73  {
74  const wxString& name = it->get()->m_Name;
75 
76  // Remove the library if it no longer exists or it exists in both the global and the
77  // project library but the project library entry is disabled.
78  if( !m_libs->HasLibrary( name, true )
79  || ( m_libs->FindRow( name, true ) != m_libs->FindRow( name, false ) ) )
80  {
81  it = deleteLibrary( it );
82  continue;
83  }
84 
85  updateLibrary( *(LIB_TREE_NODE_LIB*) it->get() );
86  ++it;
87  }
88 
89  // Look for new libraries
90  size_t count = m_libMap.size();
91 
92  for( const auto& libName : m_libs->GetLogicalLibs() )
93  {
94  if( m_libMap.count( libName ) == 0 )
95  {
96  const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName, true );
97 
98  DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true );
99  m_libMap.insert( libName );
100  }
101  }
102 
103  if( m_libMap.size() > count )
105 }
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
Definition: fp_lib_table.h:40
std::vector< LIB_TREE_ITEM * > getFootprints(const wxString &aLibName)
LIB_TREE_NODE::PTR_VECTOR::iterator deleteLibrary(LIB_TREE_NODE::PTR_VECTOR::iterator &aLibNodeIt)
Node type: library.
void updateLibrary(LIB_TREE_NODE_LIB &aLibNode)
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.
const char * name
Definition: DXF_plotter.cpp:59
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...
PTR_VECTOR m_Children
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.

References LIB_TREE_NODE::AssignIntrinsicRanks(), deleteLibrary(), LIB_TREE_MODEL_ADAPTER::DoAddLibrary(), FP_LIB_TABLE::FindRow(), FP_TREE_MODEL_ADAPTER::getFootprints(), LIB_TABLE::GetLogicalLibs(), LIB_TABLE::HasLibrary(), library, LIB_TREE_NODE::m_Children, m_libMap, FP_TREE_MODEL_ADAPTER::m_libs, LIB_TREE_MODEL_ADAPTER::m_tree, name, 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 114 of file fp_tree_synchronizing_adapter.cpp.

115 {
116  std::vector<LIB_TREE_ITEM*> footprints = getFootprints( aLibNode.m_Name );
117 
118  // remove the common part from the footprints list
119  for( auto nodeIt = aLibNode.m_Children.begin(); nodeIt != aLibNode.m_Children.end(); )
120  {
121  // Since the list is sorted we can use a binary search to speed up searches within
122  // libraries with lots of footprints.
123  FOOTPRINT_INFO_IMPL dummy( wxEmptyString, (*nodeIt)->m_Name );
124  auto footprintIt = std::lower_bound( footprints.begin(), footprints.end(), &dummy,
125  []( LIB_TREE_ITEM* a, LIB_TREE_ITEM* b )
126  {
127  return StrNumCmp( a->GetName(), b->GetName(), false ) < 0;
128  } );
129 
130  if( footprintIt != footprints.end() && dummy.GetName() == (*footprintIt)->GetName() )
131  {
132  // footprint exists both in the lib tree and the footprint info list; just
133  // update the node data
134  static_cast<LIB_TREE_NODE_LIB_ID*>( nodeIt->get() )->Update( *footprintIt );
135  footprints.erase( footprintIt );
136  ++nodeIt;
137  }
138  else
139  {
140  // node does not exist in the library manager, remove the corresponding node
141  nodeIt = aLibNode.m_Children.erase( nodeIt );
142  }
143  }
144 
145  // now the footprint list contains only new aliases that need to be added to the tree
146  for( auto footprint : footprints )
147  aLibNode.AddItem( footprint );
148 
149  aLibNode.AssignIntrinsicRanks();
150  m_libMap.insert( aLibNode.m_Name );
151 }
wxString GetName() const override
Definition: lib_symbol.h:133
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints).
Definition: lib_tree_item.h:38
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:71
std::vector< LIB_TREE_ITEM * > getFootprints(const wxString &aLibName)
LIB_TREE_NODE_LIB_ID & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
PTR_VECTOR m_Children

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, LIB_TREE_NODE::m_Name, and StrNumCmp().

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

184 {
185  {
186  wxWindowUpdateLocker updateLock( m_widget );
187 
188  // Even with the updateLock, wxWidgets sometimes ties its knickers in a knot trying to
189  // run a wxdataview_selection_changed_callback() on a row that has been deleted.
190  // https://bugs.launchpad.net/kicad/+bug/1756255
191  m_widget->UnselectAll();
192 
193  // This collapse is required before the call to "Freeze()" below. Once Freeze()
194  // is called, GetParent() will return nullptr. While this works for some calls, it
195  // segfaults when we have any expanded elements b/c the sub units in the tree don't
196  // have explicit references that are maintained over a search
197  // The tree will be expanded again below when we get our matches
198  //
199  // Also note that this cannot happen when we have deleted a symbol as GTK will also
200  // iterate over the tree in this case and find a symbol that has an invalid link
201  // and crash https://gitlab.com/kicad/code/kicad/-/issues/6910
202  if( !aState && !aSearch.IsNull() && m_tree.m_Children.size() )
203  {
204  for( std::unique_ptr<LIB_TREE_NODE>& child: m_tree.m_Children )
205  m_widget->Collapse( wxDataViewItem( &*child ) );
206  }
207 
208  // DO NOT REMOVE THE FREEZE/THAW. This freeze/thaw is a flag for this model adapter
209  // that tells it when it shouldn't trust any of the data in the model. When set, it will
210  // not return invalid data to the UI, since this invalid data can cause crashes.
211  // This is different than the update locker, which locks the UI aspects only.
212  Freeze();
213  BeforeReset();
214 
215  m_tree.ResetScore();
216 
217  for( std::unique_ptr<LIB_TREE_NODE>& child: m_tree.m_Children )
218  {
219  if( child->m_Pinned )
220  child->m_Score *= 2;
221  }
222 
223  wxStringTokenizer tokenizer( aSearch );
224 
225  while( tokenizer.HasMoreTokens() )
226  {
227  const wxString term = tokenizer.GetNextToken().Lower();
228  EDA_COMBINED_MATCHER matcher( term );
229 
230  m_tree.UpdateScore( matcher );
231  }
232 
233  m_tree.SortNodes();
234  AfterReset();
235  Thaw();
236  }
237 
238  LIB_TREE_NODE* bestMatch = ShowResults();
239 
240  if( !bestMatch )
241  bestMatch = ShowPreselect();
242 
243  if( !bestMatch )
244  bestMatch = ShowSingleLibrary();
245 
246  if( bestMatch )
247  {
248  wxDataViewItem item = wxDataViewItem( bestMatch );
249  m_widget->Select( item );
250 
251  // Make sure the *parent* item is visible. The selected item is the
252  // first (shown) child of the parent. So it's always right below the parent,
253  // and this way the user can also see what library the selected part belongs to,
254  // without having a case where the selection is off the screen (unless the
255  // window is a single row high, which is unlikely)
256  //
257  // This also happens to circumvent https://bugs.launchpad.net/kicad/+bug/1804400
258  // which appears to be a GTK+3 bug.
259  {
260  wxDataViewItem parent = GetParent( item );
261 
262  if( parent.IsOk() )
263  item = parent;
264  }
265 
266  m_widget->EnsureVisible( item );
267  }
268 }
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
LIB_TREE_NODE * ShowResults()
Find and expand successful search results.
LIB_TREE_NODE * ShowPreselect()
Find and expand preselected node.
wxDataViewItem GetParent(const wxDataViewItem &aItem) const override
Get the parent of an item.
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Update the score for this part.
LIB_TREE_NODE * ShowSingleLibrary()
Find and expand a library if there is only one.
PTR_VECTOR m_Children

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_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(), and GetValue().

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


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