KiCad PCB EDA Suite
FP_TREE_MODEL_ADAPTER Class Reference

#include <fp_tree_model_adapter.h>

Inheritance diagram for FP_TREE_MODEL_ADAPTER:
LIB_TREE_MODEL_ADAPTER FP_TREE_SYNCHRONIZING_ADAPTER

Public Types

enum  CMP_FILTER_TYPE { CMP_FILTER_NONE, CMP_FILTER_POWER }
 This enum allows a selective filtering of components to list. More...
 
typedef wxObjectDataPtr< LIB_TREE_MODEL_ADAPTERPTR
 Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE. More...
 

Public Member Functions

 ~FP_TREE_MODEL_ADAPTER ()
 Destructor. More...
 
void AddLibraries ()
 
wxString GenerateInfo (LIB_ID const &aLibId, int aUnit) override
 
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...
 
int GetItemCount () const
 Return the number of components loaded in the tree. More...
 
virtual int GetLibrariesCount () const
 Return the number of libraries 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
 

Static Public Member Functions

static PTR Create (LIB_TABLE *aLibs)
 Factory function: create a model adapter in a reference-counting container. More...
 

Protected Member Functions

 FP_TREE_MODEL_ADAPTER (LIB_TABLE *aLibs)
 Constructor; takes a set of libraries to be included in the search. More...
 
std::vector< LIB_TREE_ITEM * > getFootprints (const wxString &aLibName)
 
virtual bool HasContainerColumns (wxDataViewItem const &aItem) const override
 Check whether a container has columns too. More...
 
virtual bool IsContainer (wxDataViewItem const &aItem) const override
 Check whether an item can have children. More...
 
virtual wxDataViewItem GetParent (wxDataViewItem const &aItem) const override
 Get the parent of an item. More...
 
virtual unsigned int GetColumnCount () const override
 Return the number of columns in the model. More...
 
virtual wxString GetColumnType (unsigned int aCol) const override
 Return the type of data stored in the column. More...
 
virtual void GetValue (wxVariant &aVariant, wxDataViewItem const &aItem, unsigned int aCol) const override
 Get the value of an item. More...
 
virtual bool SetValue (wxVariant const &aVariant, wxDataViewItem const &aItem, unsigned int aCol) override
 Set the value of an item. More...
 
virtual bool GetAttr (wxDataViewItem const &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
 Get any formatting for an item. More...
 

Static Protected Member Functions

static wxDataViewItem ToItem (LIB_TREE_NODE const *aNode)
 Convert CMP_TREE_NODE -> wxDataViewItem. More...
 
static LIB_TREE_NODE const * ToNode (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

FP_LIB_TABLEm_libs
 
LIB_TREE_NODE_ROOT m_tree
 

Detailed Description

Definition at line 31 of file fp_tree_model_adapter.h.

Member Typedef Documentation

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

Member Enumeration Documentation

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

Constructor & Destructor Documentation

FP_TREE_MODEL_ADAPTER::~FP_TREE_MODEL_ADAPTER ( )

Destructor.

Do NOT delete this class manually; it is reference-counted by wxObject.

Definition at line 42 of file fp_tree_model_adapter.cpp.

43 {}
FP_TREE_MODEL_ADAPTER::FP_TREE_MODEL_ADAPTER ( LIB_TABLE aLibs)
protected

Constructor; takes a set of libraries to be included in the search.

Definition at line 37 of file fp_tree_model_adapter.cpp.

Referenced by Create().

38  : m_libs( (FP_LIB_TABLE*) aLibs )
39 {}

Member Function Documentation

void FP_TREE_MODEL_ADAPTER::AddLibraries ( )

Definition at line 46 of file fp_tree_model_adapter.cpp.

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

Referenced by FOOTPRINT_EDIT_FRAME::initLibraryTree().

47 {
48  for( const auto& libName : m_libs->GetLogicalLibs() )
49  {
50  const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName );
51 
52  DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true );
53  }
54 
56 }
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.
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
std::vector< LIB_TREE_ITEM * > getFootprints(const wxString &aLibName)
const wxString & GetDescr() const
Return the description of the library referenced by this row.
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...
void LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks ( )
inlineinherited
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 173 of file lib_tree_model_adapter.cpp.

References LIB_TREE_MODEL_ADAPTER::ColWidth(), kDataViewIndent, LIB_TREE_MODEL_ADAPTER::m_col_desc, LIB_TREE_MODEL_ADAPTER::m_col_part, LIB_TREE_MODEL_ADAPTER::m_tree, and LIB_TREE_MODEL_ADAPTER::m_widget.

Referenced by LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks(), and LIB_TREE_MODEL_ADAPTER::UpdateSearchString().

174 {
175  m_widget = aDataViewCtrl;
176  aDataViewCtrl->SetIndent( kDataViewIndent );
177  aDataViewCtrl->AssociateModel( this );
178  aDataViewCtrl->ClearColumns();
179 
180  wxString part_head = _( "Item" );
181  wxString desc_head = _( "Description" );
182 
183  m_col_part = aDataViewCtrl->AppendTextColumn( part_head, 0, wxDATAVIEW_CELL_INERT,
184  ColWidth( m_tree, 0, part_head ) );
185  m_col_desc = aDataViewCtrl->AppendTextColumn( desc_head, 1, wxDATAVIEW_CELL_INERT,
186  ColWidth( m_tree, 1, desc_head ) );
187 }
int ColWidth(LIB_TREE_NODE &aTree, int aCol, wxString const &aHeading)
Compute the width required for the given column of a node and its children.
static const int kDataViewIndent
FP_TREE_MODEL_ADAPTER::PTR FP_TREE_MODEL_ADAPTER::Create ( LIB_TABLE aLibs)
static

Factory function: create a model adapter in a reference-counting container.

Parameters
aLibslibrary set from which parts will be loaded

Definition at line 31 of file fp_tree_model_adapter.cpp.

References FP_TREE_MODEL_ADAPTER().

Referenced by PCB_BASE_FRAME::SelectFootprintFromLibTree().

32 {
33  return PTR( new FP_TREE_MODEL_ADAPTER( aLibs ) );
34 }
FP_TREE_MODEL_ADAPTER(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.
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 109 of file lib_tree_model_adapter.cpp.

References LIB_TREE_NODE_LIB::AddItem(), LIB_TREE_NODE_ROOT::AddLib(), LIB_TREE_NODE::AssignIntrinsicRanks(), and LIB_TREE_MODEL_ADAPTER::m_tree.

Referenced by AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), LIB_TREE_MODEL_ADAPTER::GetFilter(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), and FP_TREE_SYNCHRONIZING_ADAPTER::Sync().

112 {
113  auto& lib_node = m_tree.AddLib( aNodeName, aDesc );
114 
115  for( auto item: aItemList )
116  lib_node.AddItem( item );
117 
118  lib_node.AssignIntrinsicRanks( presorted );
119 }
LIB_TREE_NODE_LIB_ID & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
LIB_TREE_NODE_LIB & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
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 228 of file lib_tree_model_adapter.cpp.

References LIB_TREE_NODE::Children, LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), LIB_TREE_MODEL_ADAPTER::m_tree, and LIB_TREE_MODEL_ADAPTER::ToItem().

Referenced by LIB_TREE_MODEL_ADAPTER::GetLibrariesCount().

229 {
230  for( auto& lib: m_tree.Children )
231  {
232  if( lib->Name != aLibId.GetLibNickname() )
233  continue;
234 
235  // if part name is not specified, return the library node
236  if( aLibId.GetLibItemName() == "" )
237  return ToItem( lib.get() );
238 
239  for( auto& alias: lib->Children )
240  {
241  if( alias->Name == aLibId.GetLibItemName() )
242  return ToItem( alias.get() );
243  }
244 
245  break; // could not find the part in the requested library
246  }
247 
248  return wxDataViewItem();
249 }
PTR_VECTOR Children
List of child nodes.
static wxDataViewItem ToItem(LIB_TREE_NODE const *aNode)
Convert CMP_TREE_NODE -> wxDataViewItem.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
void LIB_TREE_MODEL_ADAPTER::Freeze ( )
inlineinherited
wxString FP_TREE_MODEL_ADAPTER::GenerateInfo ( LIB_ID const &  aLibId,
int  aUnit 
)
overridevirtual

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 81 of file fp_tree_model_adapter.cpp.

References GenerateFootprintInfo(), and m_libs.

82 {
83  return GenerateFootprintInfo( m_libs, aLibId );
84 }
wxString GenerateFootprintInfo(FP_LIB_TABLE *aFpLibTable, LIB_ID const &aLibId)
Return an HTML page describing a LIB_ID in a FP_LIB_TABLE.
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 190 of file lib_tree_model_adapter.cpp.

References LIB_TREE_MODEL_ADAPTER::ToNode().

Referenced by LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks().

191 {
192  auto node = ToNode( aSelection );
193 
194  LIB_ID emptyId;
195 
196  if( !node )
197  return emptyId;
198 
199  return node->LibId;
200 }
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
static LIB_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
bool LIB_TREE_MODEL_ADAPTER::GetAttr ( wxDataViewItem const &  aItem,
unsigned int  aCol,
wxDataViewItemAttr &  aAttr 
) const
overrideprotectedvirtualinherited

Get any formatting for an item.

Parameters
aItemitem to get formatting for
aColcolumn number of interest
aAttrreceiver for attributes
Returns
true iff the item has non-default attributes

Reimplemented in SYMBOL_TREE_SYNCHRONIZING_ADAPTER, and FP_TREE_SYNCHRONIZING_ADAPTER.

Definition at line 318 of file lib_tree_model_adapter.cpp.

References LIB_TREE_MODEL_ADAPTER::IsFrozen(), LIB_TREE_NODE::LIBID, and LIB_TREE_MODEL_ADAPTER::ToNode().

Referenced by LIB_TREE_MODEL_ADAPTER::SetValue().

321 {
322  if( IsFrozen() )
323  return false;
324 
325  auto node = ToNode( aItem );
326  wxASSERT( node );
327 
328  if( node->Type != LIB_TREE_NODE::LIBID )
329  {
330  // Currently only aliases are formatted at all
331  return false;
332  }
333 
334  if( !node->IsRoot && aCol == 0 )
335  {
336  // Names of non-root aliases are italicized
337  aAttr.SetItalic( true );
338  return true;
339  }
340  else
341  {
342  return false;
343  }
344 }
static LIB_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
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 252 of file lib_tree_model_adapter.cpp.

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

Referenced by LIB_TREE_MODEL_ADAPTER::GetLibrariesCount().

254 {
255  auto node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
256 
257  if( node->Type != LIB_TREE_NODE::TYPE::LIBID
258  || ( m_show_units && node->Type == LIB_TREE_NODE::TYPE::LIBID ) )
259  return IntoArray( *node, aChildren );
260  else
261  return 0;
262 }
static unsigned int IntoArray(LIB_TREE_NODE const &aNode, wxDataViewItemArray &aChildren)
Convert CMP_TREE_NODE&#39;s children to wxDataViewItemArray.
static LIB_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
virtual unsigned int LIB_TREE_MODEL_ADAPTER::GetColumnCount ( ) const
inlineoverrideprotectedvirtualinherited

Return the number of columns in the model.

Definition at line 279 of file lib_tree_model_adapter.h.

279 { return 2; }
virtual wxString LIB_TREE_MODEL_ADAPTER::GetColumnType ( unsigned int  aCol) const
inlineoverrideprotectedvirtualinherited

Return the type of data stored in the column.

Returns
type of data as indicated by wxVariant::GetType()

Definition at line 286 of file lib_tree_model_adapter.h.

References LIB_TREE_MODEL_ADAPTER::GetValue().

286 { return "string"; }
CMP_FILTER_TYPE LIB_TREE_MODEL_ADAPTER::GetFilter ( ) const
inlineinherited
std::vector< LIB_TREE_ITEM * > FP_TREE_MODEL_ADAPTER::getFootprints ( const wxString &  aLibName)
protected

Definition at line 59 of file fp_tree_model_adapter.cpp.

References dummy(), FOOTPRINT_LIST::GetList(), GFootprintList, i, and StrNumCmp().

Referenced by AddLibraries(), FP_TREE_SYNCHRONIZING_ADAPTER::Sync(), and FP_TREE_SYNCHRONIZING_ADAPTER::updateLibrary().

60 {
61  std::vector<LIB_TREE_ITEM*> libList;
62 
63  auto fullListStart = GFootprintList.GetList().begin();
64  auto fullListEnd = GFootprintList.GetList().end();
65  std::unique_ptr<FOOTPRINT_INFO> dummy( new FOOTPRINT_INFO_IMPL( aLibName, wxEmptyString ) );
66 
67  // List is sorted, so use a binary search to find the range of footnotes for our library
68  auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy,
69  []( const std::unique_ptr<FOOTPRINT_INFO>& a, const std::unique_ptr<FOOTPRINT_INFO>& b )
70  {
71  return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), INT_MAX, true ) < 0;
72  } );
73 
74  for( auto i = libBounds.first; i != libBounds.second; ++i )
75  libList.push_back( i->get() );
76 
77  return libList;
78 }
const FPILIST & GetList() const
Was forced to add this by modview_frame.cpp.
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: pcbnew.cpp:338
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
size_t i
Definition: json11.cpp:597
int StrNumCmp(const wxString &aString1, const wxString &aString2, int aLength, bool aIgnoreCase)
Function StrNumCmp is a routine compatible with qsort() to sort by alphabetical order.
Definition: string.cpp:315
int LIB_TREE_MODEL_ADAPTER::GetItemCount ( ) const
inherited

Return the number of components loaded in the tree.

Definition at line 217 of file lib_tree_model_adapter.cpp.

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

Referenced by LIB_TREE_MODEL_ADAPTER::GenerateInfo().

218 {
219  int n = 0;
220 
221  for( auto& lib: m_tree.Children )
222  n += lib->Children.size();
223 
224  return n;
225 }
PTR_VECTOR Children
List of child nodes.
virtual int LIB_TREE_MODEL_ADAPTER::GetLibrariesCount ( ) const
inlinevirtualinherited

Return the number of libraries loaded in the tree.

Reimplemented in SYMBOL_TREE_SYNCHRONIZING_ADAPTER, and FP_TREE_SYNCHRONIZING_ADAPTER.

Definition at line 218 of file lib_tree_model_adapter.h.

References LIB_TREE_NODE::Children, LIB_TREE_MODEL_ADAPTER::FindItem(), LIB_TREE_MODEL_ADAPTER::GetChildren(), and LIB_TREE_MODEL_ADAPTER::m_tree.

Referenced by SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount().

219  {
220  return m_tree.Children.size();
221  }
PTR_VECTOR Children
List of child nodes.
wxDataViewItem LIB_TREE_MODEL_ADAPTER::GetParent ( wxDataViewItem const &  aItem) const
overrideprotectedvirtualinherited

Get the parent of an item.

Parameters
aItemitem to get the parent of
Returns
parent of aItem, or an invalid wxDataViewItem if parent is root

Definition at line 278 of file lib_tree_model_adapter.cpp.

References LIB_TREE_MODEL_ADAPTER::ToItem(), and LIB_TREE_MODEL_ADAPTER::ToNode().

279 {
280  auto node = ToNode( aItem );
281  auto parent = node ? node->Parent : nullptr;
282 
283  // wxDataViewModel has no root node, but rather top-level elements have
284  // an invalid (null) parent.
285  if( !node || !parent || parent->Type == LIB_TREE_NODE::TYPE::ROOT )
286  return ToItem( nullptr );
287  else
288  return ToItem( parent );
289 }
static wxDataViewItem ToItem(LIB_TREE_NODE const *aNode)
Convert CMP_TREE_NODE -> wxDataViewItem.
static LIB_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
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 210 of file lib_tree_model_adapter.cpp.

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

Referenced by LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks().

211 {
212  auto node = ToNode( aSelection );
213  return node ? node->Type : LIB_TREE_NODE::INVALID;
214 }
static LIB_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
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 203 of file lib_tree_model_adapter.cpp.

References LIB_TREE_MODEL_ADAPTER::ToNode().

Referenced by LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks().

204 {
205  auto node = ToNode( aSelection );
206  return node ? node->Unit : 0;
207 }
static LIB_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
void LIB_TREE_MODEL_ADAPTER::GetValue ( wxVariant &  aVariant,
wxDataViewItem const &  aItem,
unsigned int  aCol 
) const
overrideprotectedvirtualinherited

Get the value of an item.

Parameters
aVariantwxVariant to receive the data
aItemitem whose data will be placed into aVariant
aColcolumn number of the data

Reimplemented in SYMBOL_TREE_SYNCHRONIZING_ADAPTER, and FP_TREE_SYNCHRONIZING_ADAPTER.

Definition at line 292 of file lib_tree_model_adapter.cpp.

References LIB_TREE_MODEL_ADAPTER::IsFrozen(), and LIB_TREE_MODEL_ADAPTER::ToNode().

Referenced by LIB_TREE_MODEL_ADAPTER::GetColumnType().

295 {
296  if( IsFrozen() )
297  {
298  aVariant = wxEmptyString;
299  return;
300  }
301 
302  auto node = ToNode( aItem );
303  wxASSERT( node );
304 
305  switch( aCol )
306  {
307  default: // column == -1 is used for default Compare function
308  case 0:
309  aVariant = node->Name;
310  break;
311  case 1:
312  aVariant = node->Desc;
313  break;
314  }
315 }
static LIB_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
bool LIB_TREE_MODEL_ADAPTER::HasContainerColumns ( wxDataViewItem const &  aItem) const
overrideprotectedvirtualinherited

Check whether a container has columns too.

Definition at line 265 of file lib_tree_model_adapter.cpp.

References LIB_TREE_MODEL_ADAPTER::IsContainer().

266 {
267  return IsContainer( aItem );
268 }
virtual bool IsContainer(wxDataViewItem const &aItem) const override
Check whether an item can have children.
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 57 of file lib_tree_model_adapter.cpp.

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

Referenced by LIB_TREE_MODEL_ADAPTER::GetChildren(), and LIB_TREE_MODEL_ADAPTER::IsFrozen().

59 {
60  unsigned int n = 0;
61 
62  for( auto const& child: aNode.Children )
63  {
64  if( child->Score > 0 )
65  {
66  aChildren.Add( ToItem( &*child ) );
67  ++n;
68  }
69  }
70 
71  return n;
72 }
static wxDataViewItem ToItem(LIB_TREE_NODE const *aNode)
Convert CMP_TREE_NODE -> wxDataViewItem.
bool LIB_TREE_MODEL_ADAPTER::IsContainer ( wxDataViewItem const &  aItem) const
overrideprotectedvirtualinherited

Check whether an item can have children.

Reimplemented in FP_TREE_SYNCHRONIZING_ADAPTER, and SYMBOL_TREE_SYNCHRONIZING_ADAPTER.

Definition at line 271 of file lib_tree_model_adapter.cpp.

References LIB_TREE_MODEL_ADAPTER::ToNode().

Referenced by LIB_TREE_MODEL_ADAPTER::HasContainerColumns().

272 {
273  auto node = ToNode( aItem );
274  return node ? node->Children.size() : true;
275 }
static LIB_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
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 90 of file lib_tree_model_adapter.cpp.

References LIB_TREE_MODEL_ADAPTER::m_filter.

91 {
92  m_filter = aFilter;
93 }
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 102 of file lib_tree_model_adapter.cpp.

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

Referenced by LIB_TREE_MODEL_ADAPTER::GetFilter().

103 {
104  m_preselect_lib_id = aLibId;
105  m_preselect_unit = aUnit;
106 }
virtual bool LIB_TREE_MODEL_ADAPTER::SetValue ( wxVariant const &  aVariant,
wxDataViewItem const &  aItem,
unsigned int  aCol 
)
inlineoverrideprotectedvirtualinherited

Set the value of an item.

Does nothing - this model doesn't support editing.

Definition at line 303 of file lib_tree_model_adapter.h.

References LIB_TREE_MODEL_ADAPTER::GetAttr().

305  { return false; }
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 96 of file lib_tree_model_adapter.cpp.

References LIB_TREE_MODEL_ADAPTER::m_show_units.

Referenced by LIB_TREE_MODEL_ADAPTER::GetFilter().

97 {
98  m_show_units = aShow;
99 }
void LIB_TREE_MODEL_ADAPTER::Thaw ( )
inlineinherited
wxDataViewItem LIB_TREE_MODEL_ADAPTER::ToItem ( LIB_TREE_NODE const *  aNode)
staticprotectedinherited

Convert CMP_TREE_NODE -> wxDataViewItem.

Definition at line 39 of file lib_tree_model_adapter.cpp.

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

40 {
41  return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
42 }
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 122 of file lib_tree_model_adapter.cpp.

References LIB_TREE_MODEL_ADAPTER::AttachTo(), 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(), and LIB_TREE_NODE_ROOT::UpdateScore().

Referenced by LIB_TREE_MODEL_ADAPTER::AssignIntrinsicRanks().

123 {
124  m_tree.ResetScore();
125 
126  wxStringTokenizer tokenizer( aSearch );
127 
128  while( tokenizer.HasMoreTokens() )
129  {
130  const wxString term = tokenizer.GetNextToken().Lower();
131  EDA_COMBINED_MATCHER matcher( term );
132 
133  m_tree.UpdateScore( matcher );
134  }
135 
136  m_tree.SortNodes();
137 
138  {
139  wxWindowUpdateLocker updateLock( m_widget );
140 
141  // Even with the updateLock, wxWidgets sometimes ties its knickers in
142  // a knot when trying to run a wxdataview_selection_changed_callback()
143  // on a row that has been deleted.
144  // https://bugs.launchpad.net/kicad/+bug/1756255
145  m_widget->UnselectAll();
146 
147  Cleared();
148 #ifndef __WINDOWS__
149  // The fastest method to update wxDataViewCtrl is to rebuild from
150  // scratch by calling Cleared(). Linux requires to reassociate model to
151  // display data, but Windows will create multiple associations.
152  AttachTo( m_widget );
153 #endif
154  }
155 
156  LIB_TREE_NODE* bestMatch = ShowResults();
157 
158  if( !bestMatch )
159  bestMatch = ShowPreselect();
160 
161  if( !bestMatch )
162  bestMatch = ShowSingleLibrary();
163 
164  if( bestMatch )
165  {
166  auto item = wxDataViewItem( bestMatch );
167  m_widget->Select( item );
168  m_widget->EnsureVisible( item );
169  }
170 }
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.
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.
void AttachTo(wxDataViewCtrl *aDataViewCtrl)
Attach to a wxDataViewCtrl and initialize it.

Member Data Documentation

FP_LIB_TABLE* FP_TREE_MODEL_ADAPTER::m_libs
protected

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