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  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...
 
typedef wxObjectDataPtr< LIB_TREE_MODEL_ADAPTERPTR
 Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE. 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 (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)
 Set the search string provided by the user. More...
 
void AttachTo (wxDataViewCtrl *aDataViewCtrl)
 Attach to a wxDataViewCtrl and initialize it. 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 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 PTR Create (FOOTPRINT_EDIT_FRAME *aFrame, FP_LIB_TABLE *aLibs)
 
static PTR Create (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 (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

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 Typedef Documentation

◆ PTR

typedef wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> LIB_TREE_MODEL_ADAPTER::PTR
inherited

Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.

Definition at line 105 of file lib_tree_model_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 116 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 125 of file lib_tree_model_adapter.h.

126  {
127  PART_COL = 0,
128  DESC_COL,
129  NUM_COLS
130  };

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

44  :
45  FP_TREE_MODEL_ADAPTER( aFrame, aLibs ),
46  m_frame( aFrame )
47 {
48 }
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 42 of file fp_tree_model_adapter.cpp.

43 {
44  for( const auto& libName : m_libs->GetLogicalLibs() )
45  {
46  const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName );
47 
48  DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true );
49  }
50 
52 }
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.
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const wxString & GetDescr() const
Return the description of the library referenced by this row.
std::vector< LIB_TREE_ITEM * > getFootprints(const wxString &aLibName)
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
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(), LIB_TABLE_ROW::GetDescr(), FP_TREE_MODEL_ADAPTER::getFootprints(), LIB_TABLE::GetLogicalLibs(), FP_TREE_MODEL_ADAPTER::m_libs, and LIB_TREE_MODEL_ADAPTER::m_tree.

◆ AssignIntrinsicRanks()

void LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks ( )
inlineinherited

Sort the tree and assign ranks after adding libraries.

Definition at line 183 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 273 of file lib_tree_model_adapter.cpp.

274 {
275  wxString partHead = _( "Item" );
276  wxString descHead = _( "Description" );
277 
278  // The extent of the text doesn't take into account the space on either side
279  // in the header, so artificially pad it by M
280  wxSize partHeadMinWidth = GetTextSize( partHead + "M", aDataViewCtrl );
281 
282  if( aDataViewCtrl->GetColumnCount() > 0 )
283  {
284  int partWidth = aDataViewCtrl->GetColumn( PART_COL )->GetWidth();
285  int descWidth = aDataViewCtrl->GetColumn( DESC_COL )->GetWidth();
286 
287  // Only use the widths read back if they are non-zero.
288  // GTK returns the displayed width of the column, which is not calculated immediately
289  // this leads to cases of 0 column width if the user types too fast in the filter
290  if( descWidth > 0 )
291  {
292  m_colWidths[PART_COL] = partWidth;
293  m_colWidths[DESC_COL] = descWidth;
294  }
295  }
296 
297  m_widget = aDataViewCtrl;
298  aDataViewCtrl->SetIndent( kDataViewIndent );
299  aDataViewCtrl->AssociateModel( this );
300  aDataViewCtrl->ClearColumns();
301 
302  m_col_part = aDataViewCtrl->AppendTextColumn( partHead, PART_COL, wxDATAVIEW_CELL_INERT,
304  m_col_desc = aDataViewCtrl->AppendTextColumn( descHead, DESC_COL, wxDATAVIEW_CELL_INERT,
306 
307  // Ensure the part column is wider than the smallest allowable width
308  if( m_colWidths[PART_COL] < partHeadMinWidth.x )
309  {
310  m_colWidths[PART_COL] = partHeadMinWidth.x;
311  m_col_part->SetWidth( partHeadMinWidth.x );
312  }
313 
314  m_col_part->SetMinWidth( partHeadMinWidth.x );
315 }
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: common.cpp:268
static const int kDataViewIndent
#define _(s)
Definition: 3d_actions.cpp:33

References _, LIB_TREE_MODEL_ADAPTER::DESC_COL, 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.

Referenced by LIB_TREE_MODEL_ADAPTER::UpdateSearchString().

◆ Create() [1/2]

LIB_TREE_MODEL_ADAPTER::PTR FP_TREE_SYNCHRONIZING_ADAPTER::Create ( FOOTPRINT_EDIT_FRAME aFrame,
FP_LIB_TABLE aLibs 
)
static

Definition at line 36 of file fp_tree_synchronizing_adapter.cpp.

38 {
39  return PTR( new FP_TREE_SYNCHRONIZING_ADAPTER( aFrame, aLibs ) );
40 }
FP_TREE_SYNCHRONIZING_ADAPTER(FOOTPRINT_EDIT_FRAME *aFrame, FP_LIB_TABLE *aLibs)
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > PTR
Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.

References FP_TREE_SYNCHRONIZING_ADAPTER().

Referenced by FOOTPRINT_EDIT_FRAME::initLibraryTree().

◆ Create() [2/2]

FP_TREE_MODEL_ADAPTER::PTR 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 29 of file fp_tree_model_adapter.cpp.

31 {
32  return PTR( new FP_TREE_MODEL_ADAPTER( aParent, aLibs ) );
33 }
FP_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, LIB_TABLE *aLibs)
Constructor; takes a set of libraries to be included in the search.
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > PTR
Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.

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

150 {
151  LIB_TREE_NODE* node = aLibNodeIt->get();
152  m_libMap.erase( node->m_Name );
153  auto it = m_tree.m_Children.erase( aLibNodeIt );
154  return it;
155 }
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
wxString m_Name
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 ( 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 180 of file lib_tree_model_adapter.cpp.

183 {
184  LIB_TREE_NODE_LIB& lib_node = DoAddLibraryNode( aNodeName, aDesc );
185 
186  for( LIB_TREE_ITEM* item: aItemList )
187  lib_node.AddItem( item );
188 
189  lib_node.AssignIntrinsicRanks( presorted );
190 }
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::AddLibrary(), and Sync().

◆ DoAddLibraryNode()

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

Definition at line 169 of file lib_tree_model_adapter.cpp.

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

363 {
364  for( auto& lib: m_tree.m_Children )
365  {
366  if( lib->m_Name != aLibId.GetLibNickname() )
367  continue;
368 
369  // if part name is not specified, return the library node
370  if( aLibId.GetLibItemName() == "" )
371  return ToItem( lib.get() );
372 
373  for( auto& alias: lib->m_Children )
374  {
375  if( alias->m_Name == aLibId.GetLibItemName() )
376  return ToItem( alias.get() );
377  }
378 
379  break; // could not find the part in the requested library
380  }
381 
382  return wxDataViewItem();
383 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
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:97
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().

◆ 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 77 of file fp_tree_model_adapter.cpp.

78 {
79  return GenerateFootprintInfo( m_libs, aLibId );
80 }
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 318 of file lib_tree_model_adapter.cpp.

319 {
320  const LIB_TREE_NODE* node = ToNode( aSelection );
321 
322  LIB_ID emptyId;
323 
324  if( !node )
325  return emptyId;
326 
327  return node->m_LibId;
328 }
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 FP_TREE_SYNCHRONIZING_ADAPTER::GetAttr ( wxDataViewItem const &  aItem,
unsigned int  aCol,
wxDataViewItemAttr &  aAttr 
) const
overrideprotected

Definition at line 202 of file fp_tree_synchronizing_adapter.cpp.

204 {
205  if( IsFrozen() )
206  return false;
207 
208  // change attributes only for the name field
209  if( aCol != 0 )
210  return false;
211 
212  // don't link to a board footprint, even if the FPIDs match
214  return false;
215 
216  auto node = ToNode( aItem );
217  wxCHECK( node, false );
218 
219  switch( node->m_Type )
220  {
221  case LIB_TREE_NODE::LIB:
222  if( node->m_Name == m_frame->GetLoadedFPID().GetLibNickname() )
223  {
224 #ifdef __WXGTK__
225  // The native wxGTK+ impl ignores background colour, so set the text colour
226  // instead. Works reasonably well in dark themes, less well in light ones....
227  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
228 #else
229  aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
230  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
231 #endif
232 
233  // mark modified libs with bold font
235  aAttr.SetBold( true );
236  }
237  break;
238 
240  if( node->m_LibId == m_frame->GetLoadedFPID() )
241  {
242 #ifdef __WXGTK__
243  // The native wxGTK+ impl ignores background colour, so set the text colour
244  // instead. Works reasonably well in dark themes, less well in light ones....
245  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
246 #else
247  aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
248  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
249 #endif
250 
251  // mark modified part with bold font
253  aAttr.SetBold( true );
254  }
255  break;
256 
257  default:
258  return false;
259  }
260 
261  return true;
262 }
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:97
bool IsModify() const
Definition: base_screen.h:187
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(), FOOTPRINT_EDIT_FRAME::IsCurrentFPFromBoard(), LIB_TREE_MODEL_ADAPTER::IsFrozen(), BASE_SCREEN::IsModify(), LIB_TREE_NODE::LIB, LIB_TREE_NODE::LIBID, m_frame, 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 386 of file lib_tree_model_adapter.cpp.

388 {
389  auto node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
390 
391  if( node->m_Type != LIB_TREE_NODE::TYPE::LIBID
392  || ( m_show_units && node->m_Type == LIB_TREE_NODE::TYPE::LIBID ) )
393  return IntoArray( *node, aChildren );
394  else
395  return 0;
396 }
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.

References LIB_TREE_MODEL_ADAPTER::IntoArray(), LIB_TREE_MODEL_ADAPTER::m_show_units, LIB_TREE_MODEL_ADAPTER::m_tree, and LIB_TREE_MODEL_ADAPTER::ToNode().

◆ GetColumnCount()

unsigned int LIB_TREE_MODEL_ADAPTER::GetColumnCount ( ) const
inlineoverrideprotectedinherited

Definition at line 309 of file lib_tree_model_adapter.h.

309 { 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 314 of file lib_tree_model_adapter.h.

314 { return "string"; }

◆ GetContextMenuTool()

TOOL_INTERACTIVE * FP_TREE_SYNCHRONIZING_ADAPTER::GetContextMenuTool ( )
overridevirtual

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 51 of file fp_tree_synchronizing_adapter.cpp.

52 {
54 }
FOOTPRINT_EDITOR_TOOLS.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:74

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

149 { return m_filter; }

References LIB_TREE_MODEL_ADAPTER::m_filter.

Referenced by SYMBOL_TREE_MODEL_ADAPTER::AddLibrary().

◆ getFootprints()

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

Definition at line 55 of file fp_tree_model_adapter.cpp.

56 {
57  std::vector<LIB_TREE_ITEM*> libList;
58 
59  auto fullListStart = GFootprintList.GetList().begin();
60  auto fullListEnd = GFootprintList.GetList().end();
61  std::unique_ptr<FOOTPRINT_INFO> dummy( new FOOTPRINT_INFO_IMPL( aLibName, wxEmptyString ) );
62 
63  // List is sorted, so use a binary search to find the range of footnotes for our library
64  auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy,
65  []( const std::unique_ptr<FOOTPRINT_INFO>& a, const std::unique_ptr<FOOTPRINT_INFO>& b )
66  {
67  return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), false ) < 0;
68  } );
69 
70  for( auto i = libBounds.first; i != libBounds.second; ++i )
71  libList.push_back( i->get() );
72 
73  return libList;
74 }
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
Definition: string.cpp:388
const FPILIST & GetList() const
Was forced to add this by modview_frame.cpp.
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.

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 components loaded in the tree.

Definition at line 351 of file lib_tree_model_adapter.cpp.

352 {
353  int n = 0;
354 
355  for( const std::unique_ptr<LIB_TREE_NODE>& lib: m_tree.m_Children )
356  n += lib->m_Children.size();
357 
358  return n;
359 }
PTR_VECTOR m_Children

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

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

103 {
104  return GFootprintTable.GetCount();
105 }
FP_LIB_TABLE GFootprintTable
!!!!!!!!!!!!!! This code is obsolete because of the merge into pcbnew, don't bother with it.
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 ( 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 425 of file lib_tree_model_adapter.cpp.

426 {
427  if( m_freeze )
428  return ToItem( nullptr );
429 
430  auto node = ToNode( aItem );
431  auto parent = node ? node->m_Parent : nullptr;
432 
433  // wxDataViewModel has no root node, but rather top-level elements have
434  // an invalid (null) parent.
435  if( !node || !parent || parent->m_Type == LIB_TREE_NODE::TYPE::ROOT )
436  return ToItem( nullptr );
437  else
438  return ToItem( parent );
439 }
static wxDataViewItem ToItem(LIB_TREE_NODE const *aNode)
Convert CMP_TREE_NODE -> wxDataViewItem.
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.

References LIB_TREE_MODEL_ADAPTER::m_freeze, 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 352 of file lib_tree_model_adapter.h.

353  {
354  return wxString::FromUTF8( "☆ " );
355  }

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

346 {
347  return ToNode( aSelection );
348 }
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 338 of file lib_tree_model_adapter.cpp.

339 {
340  const LIB_TREE_NODE* node = ToNode( aSelection );
341  return node ? node->m_Type : LIB_TREE_NODE::INVALID;
342 }
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 331 of file lib_tree_model_adapter.cpp.

332 {
333  const LIB_TREE_NODE* node = ToNode( aSelection );
334  return node ? node->m_Unit : 0;
335 }
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 FP_TREE_SYNCHRONIZING_ADAPTER::GetValue ( wxVariant &  aVariant,
wxDataViewItem const &  aItem,
unsigned int  aCol 
) const
overrideprotected

Definition at line 158 of file fp_tree_synchronizing_adapter.cpp.

160 {
161  if( IsFrozen() )
162  {
163  aVariant = wxEmptyString;
164  return;
165  }
166 
167  auto node = ToNode( aItem );
168 
169  switch( aCol )
170  {
171  case 0:
172  if( node->m_LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() )
173  {
174  node->m_Name = m_frame->GetLoadedFPID().GetLibItemName();
175 
176  // mark modified part with an asterisk
177  if( m_frame->GetScreen()->IsModify() )
178  aVariant = node->m_Name + " *";
179  else
180  aVariant = node->m_Name;
181  }
182  else if( node->m_Pinned )
183  aVariant = GetPinningSymbol() + node->m_Name;
184  else
185  aVariant = node->m_Name;
186  break;
187 
188  case 1:
189  if( node->m_LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() )
190  node->m_Desc = m_frame->GetBoard()->GetFirstModule()->GetDescription();
191 
192  aVariant = node->m_Desc;
193  break;
194 
195  default: // column == -1 is used for default Compare function
196  aVariant = node->m_Name;
197  break;
198  }
199 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
MODULE * GetFirstModule() const
Gets the first module in the list (used in footprint viewer/editor) or NULL if none.
Definition: class_board.h:330
static LIB_TREE_NODE * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
bool IsModify() const
Definition: base_screen.h:187
const wxString & GetDescription() const
Definition: class_module.h:218
const wxString GetPinningSymbol() const
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

References PCB_BASE_FRAME::GetBoard(), MODULE::GetDescription(), BOARD::GetFirstModule(), LIB_ID::GetLibItemName(), FOOTPRINT_EDIT_FRAME::GetLoadedFPID(), LIB_TREE_MODEL_ADAPTER::GetPinningSymbol(), PCB_BASE_FRAME::GetScreen(), FOOTPRINT_EDIT_FRAME::IsCurrentFPFromBoard(), LIB_TREE_MODEL_ADAPTER::IsFrozen(), BASE_SCREEN::IsModify(), m_frame, 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 412 of file lib_tree_model_adapter.cpp.

413 {
414  return IsContainer( aItem );
415 }
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 59 of file lib_tree_model_adapter.cpp.

61 {
62  unsigned int n = 0;
63 
64  for( auto const& child: aNode.m_Children )
65  {
66  if( child->m_Score > 0 )
67  {
68  aChildren.Add( ToItem( &*child ) );
69  ++n;
70  }
71  }
72 
73  return n;
74 }
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 FP_TREE_SYNCHRONIZING_ADAPTER::IsContainer ( const wxDataViewItem &  aItem) const
override

Definition at line 57 of file fp_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 399 of file lib_tree_model_adapter.cpp.

400 {
401  // Yes, this is an enormous hack. But it works on all platforms, it doesn't suffer
402  // the On^2 sorting issues that ItemChanged() does on OSX, and it doesn't lose the
403  // user's scroll position (which re-attaching or deleting/re-inserting columns does).
404  static int walk = 1;
405 
406  m_col_part->SetWidth( m_col_part->GetWidth() + walk );
407  m_col_desc->SetWidth( m_col_desc->GetWidth() - walk );
408  walk = -walk;
409 }

References LIB_TREE_MODEL_ADAPTER::m_col_desc, and LIB_TREE_MODEL_ADAPTER::m_col_part.

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

113 {
114  if( m_widget )
115  {
116  auto cfg = Kiface().KifaceSettings();
117  cfg->m_LibTree.column_width = m_widget->GetColumn( PART_COL )->GetWidth();
118  }
119  else
120  {
121  wxLogDebug( "Error saving column size, tree view doesn't exist" );
122  }
123 }
APP_SETTINGS_BASE * KifaceSettings() const
Definition: kiface_i.h:103
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 126 of file lib_tree_model_adapter.cpp.

127 {
128  PROJECT_FILE& project = m_parent->Kiway().Prj().GetProjectFile();
129 
130  std::vector<wxString>& entries = ( m_pinnedKey == "pinned_symbol_libs" ) ?
131  project.m_PinnedSymbolLibs :
132  project.m_PinnedFootprintLibs;
133 
134  entries.clear();
135  m_pinnedLibs.clear();
136 
137  for( auto& child: m_tree.m_Children )
138  {
139  if( child->m_Pinned )
140  {
141  m_pinnedLibs.push_back( child->m_LibId.GetLibNickname() );
142  entries.push_back( child->m_LibId.GetLibNickname() );
143  }
144  }
145 
146 
147 }
std::vector< wxString > m_PinnedSymbolLibs
Below are project-level settings that have not been moved to a dedicated file.
Definition: project_file.h:122
std::vector< wxString > m_PinnedFootprintLibs
The list of pinned footprint libraries.
Definition: project_file.h:125
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
VTBL_ENTRY PROJECT & Prj() const
Function Prj returns the PROJECT associated with this KIWAY.
Definition: kiway.cpp:172
PROJECT_FILE is the backing store for a PROJECT, in JSON format.
Definition: project_file.h:61
VTBL_ENTRY PROJECT_FILE & GetProjectFile() const
Definition: project.h:129
PTR_VECTOR m_Children

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

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

151 {
152  m_filter = aFilter;
153 }

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

163 {
164  m_preselect_lib_id = aLibId;
165  m_preselect_unit = aUnit;
166 }

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

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

333  { 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 156 of file lib_tree_model_adapter.cpp.

157 {
158  m_show_units = aShow;
159 }

References LIB_TREE_MODEL_ADAPTER::m_show_units.

◆ Sync()

void FP_TREE_SYNCHRONIZING_ADAPTER::Sync ( )

Definition at line 66 of file fp_tree_synchronizing_adapter.cpp.

67 {
68  // Process already stored libraries
69  for( auto it = m_tree.m_Children.begin(); it != m_tree.m_Children.end(); )
70  {
71  const wxString& name = it->get()->m_Name;
72 
73  if( !m_libs->HasLibrary( name, true ) )
74  {
75  it = deleteLibrary( it );
76  continue;
77  }
78 
79  updateLibrary( *(LIB_TREE_NODE_LIB*) it->get() );
80  ++it;
81  }
82 
83  // Look for new libraries
84  size_t count = m_libMap.size();
85 
86  for( const auto& libName : m_libs->GetLogicalLibs() )
87  {
88  if( m_libMap.count( libName ) == 0 )
89  {
90  const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName );
91 
92  DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true );
93  m_libMap.insert( libName );
94  }
95  }
96 
97  if( m_libMap.size() > count )
99 }
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.
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
const wxString & GetDescr() const
Return the description of the library referenced by this row.
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)
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
const char * name
Definition: DXF_plotter.cpp:60
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(), LIB_TABLE_ROW::GetDescr(), FP_TREE_MODEL_ADAPTER::getFootprints(), LIB_TABLE::GetLogicalLibs(), LIB_TABLE::HasLibrary(), 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 ( LIB_TREE_NODE const *  aNode)
staticprotectedinherited

Convert CMP_TREE_NODE -> wxDataViewItem.

Definition at line 41 of file lib_tree_model_adapter.cpp.

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

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

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

References LIB_TREE_NODE_LIB::AddItem(), LIB_TREE_NODE::AssignIntrinsicRanks(), dummy(), FP_TREE_MODEL_ADAPTER::getFootprints(), LIB_PART::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 ( wxString const &  aSearch)
inherited

Set the search string provided by the user.

Parameters
aSearchfull, unprocessed search text

Definition at line 193 of file lib_tree_model_adapter.cpp.

194 {
195  m_tree.ResetScore();
196 
197  for( auto& child: m_tree.m_Children )
198  {
199  if( child->m_Pinned )
200  child->m_Score *= 2;
201  }
202 
203  wxStringTokenizer tokenizer( aSearch );
204 
205  while( tokenizer.HasMoreTokens() )
206  {
207  const wxString term = tokenizer.GetNextToken().Lower();
208  EDA_COMBINED_MATCHER matcher( term );
209 
210  m_tree.UpdateScore( matcher );
211  }
212 
213  m_tree.SortNodes();
214 
215  {
216  wxWindowUpdateLocker updateLock( m_widget );
217 
218  Freeze();
219  // Even with the updateLock, wxWidgets sometimes ties its knickers in
220  // a knot when trying to run a wxdataview_selection_changed_callback()
221  // on a row that has been deleted.
222  // https://bugs.launchpad.net/kicad/+bug/1756255
223  m_widget->UnselectAll();
224 
225  Cleared();
226  Thaw();
227 
228  // This was fixed in wxWidgets 3.0.5 and 3.1.3.
229 #if defined( __WXGTK__ ) && ( (wxVERSION_NUMBER < 030005 ) || \
230  ( ( wxVERSION_NUMBER >= 030100 ) && ( wxVERSION_NUMBER < 030103 ) ) )
231  // The fastest method to update wxDataViewCtrl is to rebuild from
232  // scratch by calling Cleared(). Linux requires to reassociate model to
233  // display data, but Windows will create multiple associations.
234  // On MacOS, this crashes kicad. See https://gitlab.com/kicad/code/kicad/issues/3666
235  // and https://gitlab.com/kicad/code/kicad/issues/3653
236  AttachTo( m_widget );
237 #endif
238  }
239 
240  LIB_TREE_NODE* bestMatch = ShowResults();
241 
242  if( !bestMatch )
243  bestMatch = ShowPreselect();
244 
245  if( !bestMatch )
246  bestMatch = ShowSingleLibrary();
247 
248  if( bestMatch )
249  {
250  auto item = wxDataViewItem( bestMatch );
251  m_widget->Select( item );
252 
253  // Make sure the *parent* item is visible. The selected item is the
254  // first (shown) child of the parent. So it's always right below the parent,
255  // and this way the user can also see what library the selected part belongs to,
256  // without having a case where the selection is off the screen (unless the
257  // window is a single row high, which is unlikely)
258  //
259  // This also happens to circumvent https://bugs.launchpad.net/kicad/+bug/1804400
260  // which appears to be a GTK+3 bug.
261  {
262  wxDataViewItem parent = GetParent( item );
263 
264  if( parent.IsOk() )
265  item = parent;
266  }
267 
268  m_widget->EnsureVisible( item );
269  }
270 }
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
void AttachTo(wxDataViewCtrl *aDataViewCtrl)
Attach to a wxDataViewCtrl and initialize it.

References LIB_TREE_MODEL_ADAPTER::AttachTo(), 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 59 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 60 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: