KiCad PCB EDA Suite
SYMBOL_TREE_SYNCHRONIZING_ADAPTER Class Reference

#include <symbol_tree_synchronizing_adapter.h>

Inheritance diagram for SYMBOL_TREE_SYNCHRONIZING_ADAPTER:
LIB_TREE_MODEL_ADAPTER

Public Types

enum  CMP_FILTER_TYPE { CMP_FILTER_NONE, CMP_FILTER_POWER }
 This enum allows a selective filtering of components 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 (const wxString &aForceRefresh, std::function< void(int, int, const wxString &)> aProgressCallback)
 
int GetLibrariesCount () const override
 Return the number of libraries loaded in the tree. More...
 
TOOL_INTERACTIVEGetContextMenuTool () override
 
void SaveColWidths ()
 Save the column widths to the config file. More...
 
void SavePinnedItems ()
 
void SetFilter (CMP_FILTER_TYPE aFilter)
 Set the component filter type. More...
 
CMP_FILTER_TYPE GetFilter () const
 Return the active filter. More...
 
void ShowUnits (bool aShow)
 Whether or not to show units. More...
 
void SetPreselectNode (LIB_ID const &aLibId, int aUnit)
 Set the component name to be selected if there are no search results. More...
 
void DoAddLibrary (wxString const &aNodeName, wxString const &aDesc, std::vector< LIB_TREE_ITEM * > const &aItemList, bool presorted)
 Add the given list of components by alias. More...
 
void AssignIntrinsicRanks ()
 Sort the tree and assign ranks after adding libraries. More...
 
void UpdateSearchString (wxString const &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
 
virtual wxString GenerateInfo (LIB_ID const &aLibId, int aUnit)
 
int GetItemCount () const
 Return the number of components loaded in the tree. More...
 
wxDataViewItem FindItem (const LIB_ID &aLibId)
 Returns tree item corresponding to part. More...
 
unsigned int GetChildren (wxDataViewItem const &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 (SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibs)
 

Protected Member Functions

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
 
 SYMBOL_TREE_SYNCHRONIZING_ADAPTER (SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibMgr)
 
LIB_TREE_NODE_LIBDoAddLibraryNode (wxString const &aNodeName, wxString const &aDesc)
 
bool HasContainerColumns (wxDataViewItem const &aItem) const override
 Check whether a container has columns too. More...
 
wxDataViewItem GetParent (wxDataViewItem const &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 (wxVariant const &aVariant, wxDataViewItem const &aItem, unsigned int aCol) override
 Set the value of an item. More...
 
const wxString GetPinningSymbol () const
 

Static Protected Member Functions

static wxDataViewItem ToItem (LIB_TREE_NODE const *aNode)
 Convert CMP_TREE_NODE -> wxDataViewItem. More...
 
static LIB_TREE_NODEToNode (wxDataViewItem aItem)
 Convert wxDataViewItem -> CMP_TREE_NODE. More...
 
static unsigned int IntoArray (LIB_TREE_NODE const &aNode, wxDataViewItemArray &aChildren)
 Convert CMP_TREE_NODE's children to wxDataViewItemArray. More...
 

Protected Attributes

SYMBOL_EDIT_FRAMEm_frame
 
SYMBOL_LIBRARY_MANAGERm_libMgr
 Hashes to decide whether a library needs an update. More...
 
std::map< wxString, int > m_libHashes
 SYMBOL_LIBRARY_MANAGER hash value returned in the last synchronization. More...
 
int m_lastSyncHash
 
LIB_TREE_NODE_ROOT m_tree
 

Detailed Description

Definition at line 36 of file symbol_tree_synchronizing_adapter.h.

Member Enumeration Documentation

◆ CMP_FILTER_TYPE

This enum allows a selective filtering of components to list.

Enumerator
CMP_FILTER_NONE 

no filtering

CMP_FILTER_POWER 

list components 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

◆ SYMBOL_TREE_SYNCHRONIZING_ADAPTER()

SYMBOL_TREE_SYNCHRONIZING_ADAPTER::SYMBOL_TREE_SYNCHRONIZING_ADAPTER ( SYMBOL_EDIT_FRAME aParent,
SYMBOL_LIBRARY_MANAGER aLibMgr 
)
protected

Definition at line 41 of file symbol_tree_synchronizing_adapter.cpp.

42  :
43  LIB_TREE_MODEL_ADAPTER( aParent, "pinned_symbol_libs" ),
44  m_frame( aParent ),
45  m_libMgr( aLibMgr ),
46  m_lastSyncHash( -1 )
47 {
48 }
SYMBOL_LIBRARY_MANAGER * m_libMgr
Hashes to decide whether a library needs an update.
LIB_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, wxString aPinnedKey)
Creates the adapter.

Referenced by Create().

Member Function Documentation

◆ 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 component in the dialog

Definition at line 278 of file lib_tree_model_adapter.cpp.

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

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

wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Create ( SYMBOL_EDIT_FRAME aParent,
SYMBOL_LIBRARY_MANAGER aLibs 
)
static

Definition at line 33 of file symbol_tree_synchronizing_adapter.cpp.

35 {
36  auto* adapter = new SYMBOL_TREE_SYNCHRONIZING_ADAPTER( aParent, aLibMgr );
37  return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
38 }
SYMBOL_TREE_SYNCHRONIZING_ADAPTER(SYMBOL_EDIT_FRAME *aParent, SYMBOL_LIBRARY_MANAGER *aLibMgr)

References SYMBOL_TREE_SYNCHRONIZING_ADAPTER().

Referenced by SYMBOL_LIBRARY_MANAGER::SYMBOL_LIBRARY_MANAGER().

◆ deleteLibrary()

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

Definition at line 191 of file symbol_tree_synchronizing_adapter.cpp.

193 {
194  LIB_TREE_NODE* node = aLibNodeIt->get();
195  m_libHashes.erase( node->m_Name );
196  auto it = m_tree.m_Children.erase( aLibNodeIt );
197  return it;
198 }
std::map< wxString, int > m_libHashes
SYMBOL_LIBRARY_MANAGER hash value returned in the last synchronization.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
PTR_VECTOR m_Children

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

Referenced by Sync().

◆ DoAddLibrary()

void LIB_TREE_MODEL_ADAPTER::DoAddLibrary ( wxString const &  aNodeName,
wxString const &  aDesc,
std::vector< LIB_TREE_ITEM * > const &  aItemList,
bool  presorted 
)
inherited

Add the given list of components by alias.

To be called in the setup phase.

Parameters
aNodeNamethe parent node the components will appear under
aDescthe description field of the parent node
aItemListlist of components

Definition at line 177 of file lib_tree_model_adapter.cpp.

180 {
181  LIB_TREE_NODE_LIB& lib_node = DoAddLibraryNode( aNodeName, aDesc );
182 
183  for( LIB_TREE_ITEM* item: aItemList )
184  lib_node.AddItem( item );
185 
186  lib_node.AssignIntrinsicRanks( presorted );
187 }
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_ID & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
Node type: library.
LIB_TREE_NODE_LIB & DoAddLibraryNode(wxString const &aNodeName, wxString const &aDesc)
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 FP_TREE_SYNCHRONIZING_ADAPTER::Sync().

◆ DoAddLibraryNode()

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

Definition at line 166 of file lib_tree_model_adapter.cpp.

168 {
169  LIB_TREE_NODE_LIB& lib_node = m_tree.AddLib( aNodeName, aDesc );
170 
171  lib_node.m_Pinned = m_pinnedLibs.Index( lib_node.m_LibId.GetLibNickname() ) != wxNOT_FOUND;
172 
173  return lib_node;
174 }
Node type: library.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:92
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 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 349 of file lib_tree_model_adapter.cpp.

350 {
351  for( std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.m_Children )
352  {
353  if( lib->m_Name != aLibId.GetLibNickname() )
354  continue;
355 
356  // if part name is not specified, return the library node
357  if( aLibId.GetLibItemName() == "" )
358  return ToItem( lib.get() );
359 
360  for( std::unique_ptr<LIB_TREE_NODE>& alias: lib->m_Children )
361  {
362  if( alias->m_Name == aLibId.GetLibItemName() )
363  return ToItem( alias.get() );
364  }
365 
366  break; // could not find the part in the requested library
367  }
368 
369  return wxDataViewItem();
370 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:106
static wxDataViewItem ToItem(LIB_TREE_NODE const *aNode)
Convert CMP_TREE_NODE -> wxDataViewItem.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:92
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 386 of file lib_tree_model_adapter.cpp.

387 {
388  m_col_part->SetWidth( m_colWidths[PART_COL] );
389  m_col_desc->SetWidth( m_colWidths[DESC_COL] );
390 }

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

virtual wxString LIB_TREE_MODEL_ADAPTER::GenerateInfo ( LIB_ID const &  aLibId,
int  aUnit 
)
inlinevirtualinherited

Reimplemented in SYMBOL_TREE_MODEL_ADAPTER, and FP_TREE_MODEL_ADAPTER.

Definition at line 233 of file lib_tree_model_adapter.h.

233 { return wxEmptyString; };

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

306 {
307  const LIB_TREE_NODE* node = ToNode( aSelection );
308 
309  LIB_ID emptyId;
310 
311  if( !node )
312  return emptyId;
313 
314  return node->m_LibId;
315 }
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 -> CMP_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 SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr ( wxDataViewItem const &  aItem,
unsigned int  aCol,
wxDataViewItemAttr &  aAttr 
) const
overrideprotected

Definition at line 270 of file symbol_tree_synchronizing_adapter.cpp.

272 {
273  if( IsFrozen() )
274  return false;
275 
276  LIB_TREE_NODE* node = ToNode( aItem );
277  wxCHECK( node, false );
278 
279  // Mark both columns of unloaded libraries using grey text color (to look disabled)
280  if( node->m_Type == LIB_TREE_NODE::LIB && !m_libMgr->IsLibraryLoaded( node->m_Name ) )
281  {
282  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
283  return true;
284  }
285 
286  // The remaining attributes are only for the name column
287  if( aCol != 0 )
288  return false;
289 
290  LIB_PART* curPart = m_frame->GetCurPart();
291 
292  switch( node->m_Type )
293  {
294  case LIB_TREE_NODE::LIB:
295  // mark modified libs with bold font
296  aAttr.SetBold( m_libMgr->IsLibraryModified( node->m_Name ) );
297 
298  // mark the current library with background color
299  if( curPart && curPart->GetLibId().GetLibNickname() == node->m_LibId.GetLibNickname() )
300  {
301 #ifdef __WXGTK__
302  // The native wxGTK+ impl ignores background colour, so set the text colour instead.
303  // This works reasonably well in dark themes, and quite poorly in light ones....
304  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
305 #else
306  aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
307  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
308 #endif
309  }
310  break;
311 
313  // mark modified part with bold font
314  aAttr.SetBold( m_libMgr->IsPartModified( node->m_Name, node->m_Parent->m_Name ) );
315 
316  // mark aliases with italic font
317  aAttr.SetItalic( !node->m_IsRoot );
318 
319  // mark the current part with background color
320  if( curPart && curPart->GetLibId() == node->m_LibId )
321  {
322 #ifdef __WXGTK__
323  // The native wxGTK+ impl ignores background colour, so set the text colour instead.
324  // This works reasonably well in dark themes, and quite poorly in light ones....
325  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
326 #else
327  aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
328  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
329 #endif
330  }
331  break;
332 
333  default:
334  return false;
335  }
336 
337  return true;
338 }
LIB_ID GetLibId() const override
Definition: lib_symbol.h:131
LIB_TREE_NODE * m_Parent
Define a library symbol object.
Definition: lib_symbol.h:93
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:92
SYMBOL_LIBRARY_MANAGER * m_libMgr
Hashes to decide whether a library needs an update.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
LIB_PART * GetCurPart()
Return the current part being edited or NULL if none selected.
bool IsLibraryModified(const wxString &aLibrary) const
Return true if library has unsaved modifications.
enum TYPE m_Type
bool IsLibraryLoaded(const wxString &aLibrary) const
Return true if the library was successfully loaded.
bool IsPartModified(const wxString &aAlias, const wxString &aLibrary) const
Return true if part has unsaved modifications.

References SYMBOL_EDIT_FRAME::GetCurPart(), LIB_PART::GetLibId(), LIB_ID::GetLibNickname(), LIB_TREE_MODEL_ADAPTER::IsFrozen(), SYMBOL_LIBRARY_MANAGER::IsLibraryLoaded(), SYMBOL_LIBRARY_MANAGER::IsLibraryModified(), SYMBOL_LIBRARY_MANAGER::IsPartModified(), LIB_TREE_NODE::LIB, LIB_TREE_NODE::LIBID, m_frame, LIB_TREE_NODE::m_IsRoot, LIB_TREE_NODE::m_LibId, m_libMgr, LIB_TREE_NODE::m_Name, LIB_TREE_NODE::m_Parent, LIB_TREE_NODE::m_Type, and LIB_TREE_MODEL_ADAPTER::ToNode().

◆ GetChildren()

unsigned int LIB_TREE_MODEL_ADAPTER::GetChildren ( wxDataViewItem const &  aItem,
wxDataViewItemArray &  aChildren 
) const
overrideinherited

Populate a list of all the children of an item.

Returns
number of children

Definition at line 373 of file lib_tree_model_adapter.cpp.

375 {
376  const LIB_TREE_NODE* node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
377 
378  if( node->m_Type != LIB_TREE_NODE::TYPE::LIBID
379  || ( m_show_units && node->m_Type == LIB_TREE_NODE::TYPE::LIBID ) )
380  return IntoArray( *node, aChildren );
381  else
382  return 0;
383 }
static unsigned int IntoArray(LIB_TREE_NODE const &aNode, wxDataViewItemArray &aChildren)
Convert CMP_TREE_NODE's children to wxDataViewItemArray.
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
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 307 of file lib_tree_model_adapter.h.

307 { 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 312 of file lib_tree_model_adapter.h.

312 { return "string"; }

◆ GetContextMenuTool()

TOOL_INTERACTIVE * SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetContextMenuTool ( )
overridevirtual

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 51 of file symbol_tree_synchronizing_adapter.cpp.

52 {
54 }
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
Handle actions for the various symbol editor and viewers.

References TOOL_MANAGER::GetTool(), TOOLS_HOLDER::GetToolManager(), and m_frame.

◆ GetFilter()

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

◆ GetItemCount()

int LIB_TREE_MODEL_ADAPTER::GetItemCount ( ) const
inherited

Return the number of components loaded in the tree.

Definition at line 338 of file lib_tree_model_adapter.cpp.

339 {
340  int n = 0;
341 
342  for( const std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.m_Children )
343  n += lib->m_Children.size();
344 
345  return n;
346 }
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 SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount ( ) const
overridevirtual

Return the number of libraries loaded in the tree.

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 128 of file symbol_tree_synchronizing_adapter.cpp.

129 {
131 
132  for( const wxString& libName : m_libMgr->GetLibraryNames() )
133  {
134  if( m_libHashes.count( libName ) == 0 )
135  ++count;
136  }
137 
138  return count;
139 }
virtual int GetLibrariesCount() const
Return the number of libraries loaded in the tree.
std::map< wxString, int > m_libHashes
SYMBOL_LIBRARY_MANAGER hash value returned in the last synchronization.
SYMBOL_LIBRARY_MANAGER * m_libMgr
Hashes to decide whether a library needs an update.
wxArrayString GetLibraryNames() const
Return the array of library names.

References LIB_TREE_MODEL_ADAPTER::GetLibrariesCount(), SYMBOL_LIBRARY_MANAGER::GetLibraryNames(), m_libHashes, and m_libMgr.

Referenced by Sync().

◆ GetParent()

wxDataViewItem LIB_TREE_MODEL_ADAPTER::GetParent ( wxDataViewItem const &  aItem) const
overrideprotectedinherited

Get the parent of an item.

Returns
parent of aItem, or an invalid wxDataViewItem if parent is root

Definition at line 433 of file lib_tree_model_adapter.cpp.

434 {
435  if( m_freeze )
436  return ToItem( nullptr );
437 
438  LIB_TREE_NODE* node = ToNode( aItem );
439  LIB_TREE_NODE* parent = node ? node->m_Parent : nullptr;
440 
441  // wxDataViewModel has no root node, but rather top-level elements have
442  // an invalid (null) parent.
443  if( !node || !parent || parent->m_Type == LIB_TREE_NODE::TYPE::ROOT )
444  return ToItem( nullptr );
445  else
446  return ToItem( parent );
447 }
static wxDataViewItem ToItem(LIB_TREE_NODE const *aNode)
Convert CMP_TREE_NODE -> wxDataViewItem.
LIB_TREE_NODE * m_Parent
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_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 350 of file lib_tree_model_adapter.h.

351  {
352  return wxString::FromUTF8( "☆ " );
353  }

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

◆ GetTreeNodeFor()

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

Definition at line 332 of file lib_tree_model_adapter.cpp.

333 {
334  return ToNode( aSelection );
335 }
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_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 325 of file lib_tree_model_adapter.cpp.

326 {
327  const LIB_TREE_NODE* node = ToNode( aSelection );
328  return node ? node->m_Type : LIB_TREE_NODE::INVALID;
329 }
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_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 318 of file lib_tree_model_adapter.cpp.

319 {
320  const LIB_TREE_NODE* node = ToNode( aSelection );
321  return node ? node->m_Unit : 0;
322 }
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_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 SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetValue ( wxVariant &  aVariant,
wxDataViewItem const &  aItem,
unsigned int  aCol 
) const
overrideprotected

Definition at line 201 of file symbol_tree_synchronizing_adapter.cpp.

203 {
204  if( IsFrozen() )
205  {
206  aVariant = wxEmptyString;
207  return;
208  }
209 
210  LIB_TREE_NODE* node = ToNode( aItem );
211  wxASSERT( node );
212 
213  switch( aCol )
214  {
215  case 0:
216  if( m_frame->GetCurPart() && m_frame->GetCurPart()->GetLibId() == node->m_LibId )
218 
219  if( node->m_Pinned )
220  aVariant = GetPinningSymbol() + node->m_Name;
221  else
222  aVariant = node->m_Name;
223 
224  // mark modified items with an asterisk
225  if( node->m_Type == LIB_TREE_NODE::LIB )
226  {
227  if( m_libMgr->IsLibraryModified( node->m_Name ) )
228  aVariant = aVariant.GetString() + " *";
229  }
230  else if( node->m_Type == LIB_TREE_NODE::LIBID )
231  {
232  if( m_libMgr->IsPartModified( node->m_Name, node->m_Parent->m_Name ) )
233  aVariant = aVariant.GetString() + " *";
234  }
235 
236  break;
237 
238  case 1:
239  if( m_frame->GetCurPart() && m_frame->GetCurPart()->GetLibId() == node->m_LibId )
240  {
241  node->m_Desc = m_frame->GetCurPart()->GetDescription();
242  }
243  else if( node->m_Type == LIB_TREE_NODE::LIB )
244  {
246  SYMBOL_LIB_TABLE_ROW* lib = libMgr.GetLibrary( node->m_LibId.GetLibNickname() );
247 
248  if( lib )
249  node->m_Desc = lib->GetDescr();
250  }
251 
252  aVariant = node->m_Desc;
253 
254  // Annotate that the library failed to load in the description column
255  if( node->m_Type == LIB_TREE_NODE::LIB )
256  {
257  if( !m_libMgr->IsLibraryLoaded( node->m_Name ) )
258  aVariant = _( "(failed to load)" ) + wxS( " " ) + aVariant.GetString();
259  }
260 
261  break;
262 
263  default: // column == -1 is used for default Compare function
264  aVariant = node->m_Name;
265  break;
266  }
267 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:106
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
LIB_ID GetLibId() const override
Definition: lib_symbol.h:131
const wxString & GetDescr() const
Return the description of the library referenced by this row.
SYMBOL_LIB_TABLE_ROW * GetLibrary(const wxString &aLibrary) const
Find a single library within the (aggregate) library table.
Class to handle modifications to the symbol libraries.
LIB_TREE_NODE * m_Parent
SYMBOL_LIBRARY_MANAGER & GetLibManager()
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:92
wxString GetDescription() override
Definition: lib_symbol.h:138
SYMBOL_LIBRARY_MANAGER * m_libMgr
Hashes to decide whether a library needs an update.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
LIB_PART * GetCurPart()
Return the current part being edited or NULL if none selected.
const wxString GetPinningSymbol() const
bool IsLibraryModified(const wxString &aLibrary) const
Return true if library has unsaved modifications.
#define _(s)
Definition: 3d_actions.cpp:33
enum TYPE m_Type
bool IsLibraryLoaded(const wxString &aLibrary) const
Return true if the library was successfully loaded.
bool IsPartModified(const wxString &aAlias, const wxString &aLibrary) const
Return true if part has unsaved modifications.

References _, SYMBOL_EDIT_FRAME::GetCurPart(), LIB_TABLE_ROW::GetDescr(), LIB_PART::GetDescription(), LIB_PART::GetLibId(), LIB_ID::GetLibItemName(), SYMBOL_EDIT_FRAME::GetLibManager(), LIB_ID::GetLibNickname(), SYMBOL_LIBRARY_MANAGER::GetLibrary(), LIB_TREE_MODEL_ADAPTER::GetPinningSymbol(), LIB_TREE_MODEL_ADAPTER::IsFrozen(), SYMBOL_LIBRARY_MANAGER::IsLibraryLoaded(), SYMBOL_LIBRARY_MANAGER::IsLibraryModified(), SYMBOL_LIBRARY_MANAGER::IsPartModified(), LIB_TREE_NODE::LIB, LIB_TREE_NODE::LIBID, LIB_TREE_NODE::m_Desc, m_frame, LIB_TREE_NODE::m_LibId, m_libMgr, LIB_TREE_NODE::m_Name, LIB_TREE_NODE::m_Parent, LIB_TREE_NODE::m_Pinned, LIB_TREE_NODE::m_Type, and LIB_TREE_MODEL_ADAPTER::ToNode().

◆ HasContainerColumns()

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

Check whether a container has columns too.

Definition at line 420 of file lib_tree_model_adapter.cpp.

421 {
422  return IsContainer( aItem );
423 }
bool IsContainer(wxDataViewItem const &aItem) const override
Check whether an item can have children.

References LIB_TREE_MODEL_ADAPTER::IsContainer().

◆ IntoArray()

unsigned int LIB_TREE_MODEL_ADAPTER::IntoArray ( LIB_TREE_NODE const &  aNode,
wxDataViewItemArray &  aChildren 
)
staticprotectedinherited

Convert CMP_TREE_NODE's children to wxDataViewItemArray.

Definition at line 60 of file lib_tree_model_adapter.cpp.

62 {
63  unsigned int n = 0;
64 
65  for( std::unique_ptr<LIB_TREE_NODE> const& child: aNode.m_Children )
66  {
67  if( child->m_Score > 0 )
68  {
69  aChildren.Add( ToItem( &*child ) );
70  ++n;
71  }
72  }
73 
74  return n;
75 }
static wxDataViewItem ToItem(LIB_TREE_NODE const *aNode)
Convert CMP_TREE_NODE -> wxDataViewItem.

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

Referenced by LIB_TREE_MODEL_ADAPTER::GetChildren().

◆ IsContainer()

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

Definition at line 57 of file symbol_tree_synchronizing_adapter.cpp.

58 {
59  const LIB_TREE_NODE* node = ToNode( aItem );
60  return node ? node->m_Type == LIB_TREE_NODE::LIB : true;
61 }
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_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 393 of file lib_tree_model_adapter.cpp.

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

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

114 {
115  if( m_widget )
116  {
118  cfg->m_LibTree.column_width = m_widget->GetColumn( PART_COL )->GetWidth();
119  }
120 }
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 123 of file lib_tree_model_adapter.cpp.

124 {
126 
127  std::vector<wxString>& entries = ( m_pinnedKey == "pinned_symbol_libs" ) ?
128  project.m_PinnedSymbolLibs :
129  project.m_PinnedFootprintLibs;
130 
131  entries.clear();
132  m_pinnedLibs.clear();
133 
134  for( std::unique_ptr<LIB_TREE_NODE>& child: m_tree.m_Children )
135  {
136  if( child->m_Pinned )
137  {
138  m_pinnedLibs.push_back( child->m_LibId.GetLibNickname() );
139  entries.push_back( child->m_LibId.GetLibNickname() );
140  }
141  }
142 
143 
144 }
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:56
virtual PROJECT & Prj() const
Return the PROJECT associated with this KIWAY.
Definition: kiway.cpp:173
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 ( CMP_FILTER_TYPE  aFilter)
inherited

Set the component filter type.

Must be set before adding libraries

Parameters
aFilterif CMP_FILTER_POWER, only power parts are loaded

Definition at line 147 of file lib_tree_model_adapter.cpp.

148 {
149  m_filter = aFilter;
150 }

References LIB_TREE_MODEL_ADAPTER::m_filter.

◆ SetPreselectNode()

void LIB_TREE_MODEL_ADAPTER::SetPreselectNode ( LIB_ID const &  aLibId,
int  aUnit 
)
inherited

Set the component 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 159 of file lib_tree_model_adapter.cpp.

160 {
161  m_preselect_lib_id = aLibId;
162  m_preselect_unit = aUnit;
163 }

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 ( wxVariant const &  aVariant,
wxDataViewItem const &  aItem,
unsigned int  aCol 
)
inlineoverrideprotectedinherited

Set the value of an item.

Does nothing - this model doesn't support editing.

Definition at line 329 of file lib_tree_model_adapter.h.

331  { 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 153 of file lib_tree_model_adapter.cpp.

154 {
155  m_show_units = aShow;
156 }

References LIB_TREE_MODEL_ADAPTER::m_show_units.

◆ Sync()

void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::Sync ( const wxString &  aForceRefresh,
std::function< void(int, int, const wxString &)>  aProgressCallback 
)

Definition at line 66 of file symbol_tree_synchronizing_adapter.cpp.

68 {
69  wxLongLong nextUpdate = wxGetUTCTimeMillis() + (PROGRESS_INTERVAL_MILLIS / 2);
70 
72  int i = 0, max = GetLibrariesCount();
73 
74  // Process already stored libraries
75  for( auto it = m_tree.m_Children.begin(); it != m_tree.m_Children.end(); /* iteration inside */ )
76  {
77  const wxString& name = it->get()->m_Name;
78 
79  if( wxGetUTCTimeMillis() > nextUpdate )
80  {
81  aProgressCallback( i, max, name );
82  nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS;
83  }
84 
85  // There is a bug in SYMBOL_LIBRARY_MANAGER::LibraryExists() that uses the buffered
86  // modified libraries before the symbol library table which prevents the library from
87  // being removed from the tree control.
88  if( !m_libMgr->LibraryExists( name, true )
89  || !m_frame->Prj().SchSymbolLibTable()->HasLibrary( name, true )
90  || m_frame->Prj().SchSymbolLibTable()->FindRow( name, true ) !=
91  m_frame->Prj().SchSymbolLibTable()->FindRow( name, false )
92  || name == aForceRefresh )
93  {
94  it = deleteLibrary( it );
95  continue;
96  }
97  else
98  {
99  updateLibrary( *(LIB_TREE_NODE_LIB*) it->get() );
100  }
101 
102  ++it;
103  ++i;
104  }
105 
106  // Look for new libraries
107  for( const wxString& libName : m_libMgr->GetLibraryNames() )
108  {
109  if( m_libHashes.count( libName ) == 0 )
110  {
111  if( wxGetUTCTimeMillis() > nextUpdate )
112  {
113  aProgressCallback( i++, max, libName );
114  nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS;
115  }
116 
118  LIB_TREE_NODE_LIB& lib_node = DoAddLibraryNode( libName, library->GetDescr() );
119 
120  updateLibrary( lib_node );
121  }
122  }
123 
125 }
Hold a record identifying a symbol library accessed by the appropriate symbol library SCH_PLUGIN obje...
std::map< wxString, int > m_libHashes
SYMBOL_LIBRARY_MANAGER hash value returned in the last synchronization.
int GetLibrariesCount() const override
Return the number of libraries loaded in the tree.
#define PROGRESS_INTERVAL_MILLIS
SYMBOL_LIB_TABLE_ROW * GetLibrary(const wxString &aLibrary) const
Find a single library within the (aggregate) library table.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Node type: library.
SYMBOL_LIBRARY_MANAGER * m_libMgr
Hashes to decide whether a library needs an update.
LIB_TREE_NODE_LIB & DoAddLibraryNode(wxString const &aNodeName, wxString const &aDesc)
wxArrayString GetLibraryNames() const
Return the array of library names.
LIB_TREE_NODE::PTR_VECTOR::iterator deleteLibrary(LIB_TREE_NODE::PTR_VECTOR::iterator &aLibNodeIt)
bool LibraryExists(const wxString &aLibrary, bool aCheckEnabled=false) const
Return true if library exists.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
const char * name
Definition: DXF_plotter.cpp:59
PTR_VECTOR m_Children

References LIB_TREE_NODE::AssignIntrinsicRanks(), deleteLibrary(), LIB_TREE_MODEL_ADAPTER::DoAddLibraryNode(), SYMBOL_LIBRARY_MANAGER::GetHash(), GetLibrariesCount(), SYMBOL_LIBRARY_MANAGER::GetLibrary(), SYMBOL_LIBRARY_MANAGER::GetLibraryNames(), library, SYMBOL_LIBRARY_MANAGER::LibraryExists(), LIB_TREE_NODE::m_Children, m_frame, m_lastSyncHash, m_libHashes, m_libMgr, LIB_TREE_MODEL_ADAPTER::m_tree, name, KIWAY_HOLDER::Prj(), PROGRESS_INTERVAL_MILLIS, and updateLibrary().

Referenced by SYMBOL_LIBRARY_MANAGER::Sync().

◆ Thaw()

void LIB_TREE_MODEL_ADAPTER::Thaw ( )
inlineinherited

◆ ToItem()

wxDataViewItem LIB_TREE_MODEL_ADAPTER::ToItem ( LIB_TREE_NODE const *  aNode)
staticprotectedinherited

Convert CMP_TREE_NODE -> wxDataViewItem.

Definition at line 42 of file lib_tree_model_adapter.cpp.

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

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

◆ ToNode()

◆ updateLibrary()

void SYMBOL_TREE_SYNCHRONIZING_ADAPTER::updateLibrary ( LIB_TREE_NODE_LIB aLibNode)
protected

Definition at line 142 of file symbol_tree_synchronizing_adapter.cpp.

143 {
144  auto hashIt = m_libHashes.find( aLibNode.m_Name );
145 
146  if( hashIt == m_libHashes.end() )
147  {
148  // add a new library
149  for( LIB_PART* alias : m_libMgr->GetAliases( aLibNode.m_Name ) )
150  aLibNode.AddItem( alias );
151  }
152  else if( hashIt->second != m_libMgr->GetLibraryHash( aLibNode.m_Name ) )
153  {
154  // update an existing library
155  std::list<LIB_PART*> aliases = m_libMgr->GetAliases( aLibNode.m_Name );
156 
157  // remove the common part from the aliases list
158  for( auto nodeIt = aLibNode.m_Children.begin(); nodeIt != aLibNode.m_Children.end(); )
159  {
160  auto aliasIt = std::find_if( aliases.begin(), aliases.end(),
161  [&] ( const LIB_PART* a )
162  {
163  return a->GetName() == (*nodeIt)->m_Name;
164  } );
165 
166  if( aliasIt != aliases.end() )
167  {
168  // alias exists both in the component tree and the library manager,
169  // update only the node data
170  static_cast<LIB_TREE_NODE_LIB_ID*>( nodeIt->get() )->Update( *aliasIt );
171  aliases.erase( aliasIt );
172  ++nodeIt;
173  }
174  else
175  {
176  // node does not exist in the library manager, remove the corresponding node
177  nodeIt = aLibNode.m_Children.erase( nodeIt );
178  }
179  }
180 
181  // now the aliases list contains only new aliases that need to be added to the tree
182  for( LIB_PART* alias : aliases )
183  aLibNode.AddItem( alias );
184  }
185 
186  aLibNode.AssignIntrinsicRanks();
187  m_libHashes[aLibNode.m_Name] = m_libMgr->GetLibraryHash( aLibNode.m_Name );
188 }
std::map< wxString, int > m_libHashes
SYMBOL_LIBRARY_MANAGER hash value returned in the last synchronization.
LIB_TREE_NODE_LIB_ID & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
int GetLibraryHash(const wxString &aLibrary) const
Return a library hash value to determine if it has changed.
Define a library symbol object.
Definition: lib_symbol.h:93
SYMBOL_LIBRARY_MANAGER * m_libMgr
Hashes to decide whether a library needs an update.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
std::list< LIB_PART * > GetAliases(const wxString &aLibrary) const
PTR_VECTOR m_Children

References LIB_TREE_NODE_LIB::AddItem(), LIB_TREE_NODE::AssignIntrinsicRanks(), SYMBOL_LIBRARY_MANAGER::GetAliases(), SYMBOL_LIBRARY_MANAGER::GetLibraryHash(), LIB_TREE_NODE::m_Children, m_libHashes, m_libMgr, and LIB_TREE_NODE::m_Name.

Referenced by Sync().

◆ UpdateSearchString()

void LIB_TREE_MODEL_ADAPTER::UpdateSearchString ( wxString const &  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 190 of file lib_tree_model_adapter.cpp.

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

SYMBOL_EDIT_FRAME* SYMBOL_TREE_SYNCHRONIZING_ADAPTER::m_frame
protected

Definition at line 65 of file symbol_tree_synchronizing_adapter.h.

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

◆ m_lastSyncHash

int SYMBOL_TREE_SYNCHRONIZING_ADAPTER::m_lastSyncHash
protected

Definition at line 72 of file symbol_tree_synchronizing_adapter.h.

Referenced by Sync().

◆ m_libHashes

std::map<wxString, int> SYMBOL_TREE_SYNCHRONIZING_ADAPTER::m_libHashes
protected

SYMBOL_LIBRARY_MANAGER hash value returned in the last synchronization.

Definition at line 69 of file symbol_tree_synchronizing_adapter.h.

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

◆ m_libMgr

SYMBOL_LIBRARY_MANAGER* SYMBOL_TREE_SYNCHRONIZING_ADAPTER::m_libMgr
protected

Hashes to decide whether a library needs an update.

Definition at line 66 of file symbol_tree_synchronizing_adapter.h.

Referenced by GetAttr(), GetLibrariesCount(), GetValue(), Sync(), and updateLibrary().

◆ m_tree


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