KiCad PCB EDA Suite
CMP_TREE_MODEL_ADAPTER Class Reference

#include <cmp_tree_model_adapter.h>

Inheritance diagram for CMP_TREE_MODEL_ADAPTER:
CMP_TREE_MODEL_ADAPTER_BASE

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< CMP_TREE_MODEL_ADAPTER_BASEPTR
 Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE. More...
 

Public Member Functions

 ~CMP_TREE_MODEL_ADAPTER ()
 Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER. More...
 
void AddLibrary (wxString const &aLibNickname) override
 Add all the components and their aliases in this library. More...
 
void AddAliasList (wxString const &aNodeName, wxArrayString const &aAliasNameList) override
 Add the given list of components, by name. More...
 
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 AddLibrariesWithProgress (const std::vector< wxString > &aNicknames, wxWindow *aParent)
 Add all the libraries in a SYMBOL_LIB_TABLE to the model, displaying a progress dialog attached to the parent frame. More...
 
void AddAliasList (wxString const &aNodeName, wxString const &aDesc, std::vector< LIB_ALIAS * > const &aAliasList)
 Add the given list of components by alias. 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...
 
CMP_TREE_NODE::TYPE GetTypeFor (const wxDataViewItem &aSelection) const
 Return node type for the given item. More...
 
int GetComponentsCount () 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...
 
virtual 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 (SYMBOL_LIB_TABLE *aLibs)
 Factory function: create a model adapter in a reference-counting container. More...
 

Protected Member Functions

 CMP_TREE_MODEL_ADAPTER (SYMBOL_LIB_TABLE *aLibs)
 Constructor; takes a set of libraries to be included in the search. More...
 
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 (CMP_TREE_NODE const *aNode)
 Convert CMP_TREE_NODE -> wxDataViewItem. More...
 
static CMP_TREE_NODE const * ToNode (wxDataViewItem aItem)
 Convert wxDataViewItem -> CMP_TREE_NODE. More...
 
static unsigned int IntoArray (CMP_TREE_NODE const &aNode, wxDataViewItemArray &aChildren)
 Convert CMP_TREE_NODE's children to wxDataViewItemArray. More...
 

Protected Attributes

CMP_TREE_NODE_ROOT m_tree
 

Private Attributes

SYMBOL_LIB_TABLEm_libs
 

Detailed Description

Definition at line 29 of file cmp_tree_model_adapter.h.

Member Typedef Documentation

Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.

Definition at line 99 of file cmp_tree_model_adapter_base.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 cmp_tree_model_adapter_base.h.

Constructor & Destructor Documentation

CMP_TREE_MODEL_ADAPTER::~CMP_TREE_MODEL_ADAPTER ( )

Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER.

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

Definition at line 42 of file cmp_tree_model_adapter.cpp.

43 {}
CMP_TREE_MODEL_ADAPTER::CMP_TREE_MODEL_ADAPTER ( SYMBOL_LIB_TABLE aLibs)
protected

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

Definition at line 37 of file cmp_tree_model_adapter.cpp.

Referenced by Create().

38  : m_libs( aLibs )
39 {}

Member Function Documentation

void CMP_TREE_MODEL_ADAPTER::AddAliasList ( wxString const &  aNodeName,
wxArrayString const &  aAliasNameList 
)
overridevirtual

Add the given list of components, by name.

To be called in the setup phase.

Parameters
aNodeNamethe parent node the components will appear under
aAliasNameListlist of alias names

Implements CMP_TREE_MODEL_ADAPTER_BASE.

Definition at line 71 of file cmp_tree_model_adapter.cpp.

References Format(), LIB_TABLE::GetDescription(), SYMBOL_LIB_TABLE::LoadSymbol(), m_libs, name, and IO_ERROR::What().

Referenced by AddLibrary().

74 {
75  std::vector<LIB_ALIAS*> alias_list;
76 
77  for( const wxString& name: aAliasNameList )
78  {
79  LIB_ALIAS* a = nullptr;
80 
81  try
82  {
83  a = m_libs->LoadSymbol( aNodeName, name );
84  }
85  catch( const IO_ERROR& ioe )
86  {
87  wxLogError( wxString::Format( _( "Error occurred loading symbol %s from library %s."
88  "\n\n%s" ), name, aNodeName, ioe.What() ) );
89  continue;
90  }
91 
92  if( a )
93  alias_list.push_back( a );
94  }
95 
96  if( alias_list.size() > 0 )
97  AddAliasList( aNodeName, m_libs->GetDescription( aNodeName ), alias_list );
98 }
LIB_ALIAS * LoadSymbol(const wxString &aNickname, const wxString &aAliasName)
Load a LIB_ALIAS having aAliasName from the library given by aNickname.
Part library alias object definition.
const wxString GetDescription(const wxString &aNickname)
void AddAliasList(wxString const &aNodeName, wxArrayString const &aAliasNameList) override
Add the given list of components, by name.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
const char * name
Definition: DXF_plotter.cpp:61
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
void CMP_TREE_MODEL_ADAPTER_BASE::AddAliasList ( wxString const &  aNodeName,
wxString const &  aDesc,
std::vector< LIB_ALIAS * > const &  aAliasList 
)
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
aAliasListlist of aliases

Definition at line 147 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_NODE_LIB::AddAlias(), CMP_TREE_NODE_ROOT::AddLib(), CMP_TREE_NODE::AssignIntrinsicRanks(), and CMP_TREE_MODEL_ADAPTER_BASE::m_tree.

149 {
150  auto& lib_node = m_tree.AddLib( aNodeName, aDesc );
151 
152  for( auto a: aAliasList )
153  {
154  lib_node.AddAlias( a );
155  }
156 
157  lib_node.AssignIntrinsicRanks();
159 }
CMP_TREE_NODE_LIB & AddLib(wxString const &aName, wxString const &aDesc)
Construct an empty library node, add it to the root, and return it.
CMP_TREE_NODE_LIB_ID & AddAlias(LIB_ALIAS *aAlias)
Construct a new alias node, add it to this library, and return it.
void AssignIntrinsicRanks()
Store intrinsic ranks on all children of this node.
void CMP_TREE_MODEL_ADAPTER_BASE::AddLibrariesWithProgress ( const std::vector< wxString > &  aNicknames,
wxWindow *  aParent 
)
inherited

Add all the libraries in a SYMBOL_LIB_TABLE to the model, displaying a progress dialog attached to the parent frame.

Parameters
aNicknamesis the list of library nicknames
aParentis the parent window to display the progress dialog

Definition at line 113 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::AddLibrary(), Format(), CMP_TREE_MODEL_ADAPTER_BASE::m_show_progress, and PROGRESS_INTERVAL_MILLIS.

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetFilter().

115 {
116  wxProgressDialog* prg = nullptr;
117  wxLongLong nextUpdate = wxGetUTCTimeMillis() + (PROGRESS_INTERVAL_MILLIS / 2);
118 
119  if( m_show_progress )
120  prg = new wxProgressDialog( _( "Loading Symbol Libraries" ),
121  wxEmptyString,
122  aNicknames.size(),
123  aParent );
124 
125  unsigned int ii = 0;
126 
127  for( const auto& nickname : aNicknames )
128  {
129  if( prg && wxGetUTCTimeMillis() > nextUpdate )
130  {
131  prg->Update( ii, wxString::Format( _( "Loading library \"%s\"" ), nickname ) );
132  nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS;
133  }
134 
135  AddLibrary( nickname );
136  ii++;
137  }
138 
139  if( prg )
140  {
141  prg->Destroy();
142  m_show_progress = false;
143  }
144 }
static bool m_show_progress
Flag to only show the symbol library table load progress dialog the first time.
virtual void AddLibrary(wxString const &aLibNickname)=0
Add all the components and their aliases in this library.
#define PROGRESS_INTERVAL_MILLIS
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void CMP_TREE_MODEL_ADAPTER::AddLibrary ( wxString const &  aLibNickname)
overridevirtual

Add all the components and their aliases in this library.

To be called in the setup phase.

Parameters
aLibNicknamereference to a symbol library nickname

Implements CMP_TREE_MODEL_ADAPTER_BASE.

Definition at line 46 of file cmp_tree_model_adapter.cpp.

References AddAliasList(), CMP_TREE_NODE::AssignIntrinsicRanks(), CMP_TREE_MODEL_ADAPTER_BASE::CMP_FILTER_POWER, Format(), LIB_TABLE::GetDescription(), CMP_TREE_MODEL_ADAPTER_BASE::GetFilter(), SYMBOL_LIB_TABLE::LoadSymbolLib(), m_libs, CMP_TREE_MODEL_ADAPTER_BASE::m_tree, and IO_ERROR::What().

47 {
48  bool onlyPowerSymbols = ( GetFilter() == CMP_FILTER_POWER );
49 
50  std::vector<LIB_ALIAS*> alias_list;
51 
52  try
53  {
54  m_libs->LoadSymbolLib( alias_list, aLibNickname, onlyPowerSymbols );
55  }
56  catch( const IO_ERROR& ioe )
57  {
58  wxLogError( wxString::Format( _( "Error occurred loading symbol library %s."
59  "\n\n%s" ), aLibNickname, ioe.What() ) );
60  return;
61  }
62 
63  if( alias_list.size() > 0 )
64  {
65  AddAliasList( aLibNickname, m_libs->GetDescription( aLibNickname ), alias_list );
67  }
68 }
void LoadSymbolLib(std::vector< LIB_ALIAS * > &aAliasList, const wxString &aNickname, bool aPowerSymbolsOnly=false)
void AssignIntrinsicRanks()
Store intrinsic ranks on all children of this node.
const wxString GetDescription(const wxString &aNickname)
void AddAliasList(wxString const &aNodeName, wxArrayString const &aAliasNameList) override
Add the given list of components, by name.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
CMP_FILTER_TYPE GetFilter() const
Return the active filter.
void CMP_TREE_MODEL_ADAPTER_BASE::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 213 of file cmp_tree_model_adapter_base.cpp.

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

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetFilter(), and CMP_TREE_MODEL_ADAPTER_BASE::UpdateSearchString().

214 {
215  m_widget = aDataViewCtrl;
216  aDataViewCtrl->SetIndent( kDataViewIndent );
217  aDataViewCtrl->AssociateModel( this );
218  aDataViewCtrl->ClearColumns();
219 
220  wxString part_head = _( "Symbol" );
221  wxString desc_head = _( "Desc" );
222 
223  m_col_part = aDataViewCtrl->AppendTextColumn( part_head, 0, wxDATAVIEW_CELL_INERT,
224  ColWidth( m_tree, 0, part_head ) );
225  m_col_desc = aDataViewCtrl->AppendTextColumn( desc_head, 1, wxDATAVIEW_CELL_INERT,
226  ColWidth( m_tree, 1, desc_head ) );
227 }
static const int kDataViewIndent
int ColWidth(CMP_TREE_NODE &aTree, int aCol, wxString const &aHeading)
Compute the width required for the given column of a node and its children.
CMP_TREE_MODEL_ADAPTER_BASE::PTR CMP_TREE_MODEL_ADAPTER::Create ( SYMBOL_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 29 of file cmp_tree_model_adapter.cpp.

References CMP_TREE_MODEL_ADAPTER().

Referenced by LIB_VIEW_FRAME::OnSelectSymbol(), and SCH_BASE_FRAME::SelectComponentFromLibrary().

30 {
31  auto adapter = new CMP_TREE_MODEL_ADAPTER( aLibs );
32  auto container = CMP_TREE_MODEL_ADAPTER::PTR( adapter );
33  return container;
34 }
wxObjectDataPtr< CMP_TREE_MODEL_ADAPTER_BASE > PTR
Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.
CMP_TREE_MODEL_ADAPTER(SYMBOL_LIB_TABLE *aLibs)
Constructor; takes a set of libraries to be included in the search.
wxDataViewItem CMP_TREE_MODEL_ADAPTER_BASE::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 274 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_NODE::Children, LIB_ID::GetLibItemName(), LIB_ID::GetLibNickname(), CMP_TREE_MODEL_ADAPTER_BASE::m_tree, and CMP_TREE_MODEL_ADAPTER_BASE::ToItem().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetLibrariesCount().

275 {
276  for( auto& lib: m_tree.Children )
277  {
278  if( lib->Name != aLibId.GetLibNickname() )
279  continue;
280 
281  // if part name is not specified, return the library node
282  if( aLibId.GetLibItemName() == "" )
283  return ToItem( lib.get() );
284 
285  for( auto& alias: lib->Children )
286  {
287  if( alias->Name == aLibId.GetLibItemName() )
288  return ToItem( alias.get() );
289  }
290 
291  break; // could not find the part in the requested library
292  }
293 
294  return wxDataViewItem();
295 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
PTR_VECTOR Children
List of child nodes.
static wxDataViewItem ToItem(CMP_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:101
void CMP_TREE_MODEL_ADAPTER_BASE::Freeze ( )
inlineinherited
LIB_ID CMP_TREE_MODEL_ADAPTER_BASE::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 230 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetFilter().

231 {
232  auto node = ToNode( aSelection );
233 
234  LIB_ID emptyId;
235 
236  if( !node )
237  return emptyId;
238 
239  return node->LibId;
240 }
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
static CMP_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
bool CMP_TREE_MODEL_ADAPTER_BASE::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 LIB_MANAGER_ADAPTER.

Definition at line 370 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::IsFrozen(), CMP_TREE_NODE::LIBID, and CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::SetValue().

374 {
375  if( IsFrozen() )
376  return false;
377 
378  auto node = ToNode( aItem );
379  wxASSERT( node );
380 
381  if( node->Type != CMP_TREE_NODE::LIBID )
382  {
383  // Currently only aliases are formatted at all
384  return false;
385  }
386 
387  if( !node->IsRoot && aCol == 0 )
388  {
389  // Names of non-root aliases are italicized
390  aAttr.SetItalic( true );
391  return true;
392  }
393  else
394  {
395  return false;
396  }
397 }
static CMP_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
unsigned int CMP_TREE_MODEL_ADAPTER_BASE::GetChildren ( wxDataViewItem const &  aItem,
wxDataViewItemArray &  aChildren 
) const
overridevirtualinherited

Populate a list of all the children of an item.

Returns
number of children

Definition at line 298 of file cmp_tree_model_adapter_base.cpp.

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

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetLibrariesCount().

301 {
302  auto node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
303 
304  if( node->Type != CMP_TREE_NODE::TYPE::LIBID
305  || ( m_show_units && node->Type == CMP_TREE_NODE::TYPE::LIBID ) )
306  return IntoArray( *node, aChildren );
307  else
308  return 0;
309 }
static unsigned int IntoArray(CMP_TREE_NODE const &aNode, wxDataViewItemArray &aChildren)
Convert CMP_TREE_NODE&#39;s children to wxDataViewItemArray.
static CMP_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
virtual unsigned int CMP_TREE_MODEL_ADAPTER_BASE::GetColumnCount ( ) const
inlineoverrideprotectedvirtualinherited

Return the number of columns in the model.

Definition at line 303 of file cmp_tree_model_adapter_base.h.

303 { return 2; }
virtual wxString CMP_TREE_MODEL_ADAPTER_BASE::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 310 of file cmp_tree_model_adapter_base.h.

References CMP_TREE_MODEL_ADAPTER_BASE::GetValue().

310 { return "string"; }
int CMP_TREE_MODEL_ADAPTER_BASE::GetComponentsCount ( ) const
inherited

Return the number of components loaded in the tree.

Definition at line 257 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_NODE::Children, and CMP_TREE_MODEL_ADAPTER_BASE::m_tree.

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetFilter().

258 {
259  int n = 0;
260 
261  for( auto& lib: m_tree.Children )
262  {
263  for( auto& alias: lib->Children )
264  {
265  (void) alias;
266  ++n;
267  }
268  }
269 
270  return n;
271 }
PTR_VECTOR Children
List of child nodes.
virtual int CMP_TREE_MODEL_ADAPTER_BASE::GetLibrariesCount ( ) const
inlinevirtualinherited

Return the number of libraries loaded in the tree.

Reimplemented in LIB_MANAGER_ADAPTER.

Definition at line 241 of file cmp_tree_model_adapter_base.h.

References CMP_TREE_NODE::Children, CMP_TREE_MODEL_ADAPTER_BASE::FindItem(), CMP_TREE_MODEL_ADAPTER_BASE::GetChildren(), and CMP_TREE_MODEL_ADAPTER_BASE::m_tree.

Referenced by LIB_MANAGER_ADAPTER::GetLibrariesCount().

242  {
243  return m_tree.Children.size();
244  }
PTR_VECTOR Children
List of child nodes.
wxDataViewItem CMP_TREE_MODEL_ADAPTER_BASE::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 325 of file cmp_tree_model_adapter_base.cpp.

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

326 {
327  auto node = ToNode( aItem );
328  auto parent = node ? node->Parent : nullptr;
329 
330  // wxDataViewModel has no root node, but rather top-level elements have
331  // an invalid (null) parent.
332  if( !node || !parent || parent->Type == CMP_TREE_NODE::TYPE::ROOT )
333  {
334  return ToItem( nullptr );
335  }
336  else
337  {
338  return ToItem( parent );
339  }
340 }
static CMP_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
static wxDataViewItem ToItem(CMP_TREE_NODE const *aNode)
Convert CMP_TREE_NODE -> wxDataViewItem.
CMP_TREE_NODE::TYPE CMP_TREE_MODEL_ADAPTER_BASE::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 250 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_NODE::INVALID, and CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetFilter().

251 {
252  auto node = ToNode( aSelection );
253  return node ? node->Type : CMP_TREE_NODE::INVALID;
254 }
static CMP_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
int CMP_TREE_MODEL_ADAPTER_BASE::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 243 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetFilter().

244 {
245  auto node = ToNode( aSelection );
246  return node ? node->Unit : 0;
247 }
static CMP_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
void CMP_TREE_MODEL_ADAPTER_BASE::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 LIB_MANAGER_ADAPTER.

Definition at line 343 of file cmp_tree_model_adapter_base.cpp.

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

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetColumnType().

347 {
348  if( IsFrozen() )
349  {
350  aVariant = wxEmptyString;
351  return;
352  }
353 
354  auto node = ToNode( aItem );
355  wxASSERT( node );
356 
357  switch( aCol )
358  {
359  default: // column == -1 is used for default Compare function
360  case 0:
361  aVariant = node->Name;
362  break;
363  case 1:
364  aVariant = node->Desc;
365  break;
366  }
367 }
static CMP_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
bool CMP_TREE_MODEL_ADAPTER_BASE::HasContainerColumns ( wxDataViewItem const &  aItem) const
overrideprotectedvirtualinherited

Check whether a container has columns too.

Definition at line 312 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::IsContainer().

313 {
314  return IsContainer( aItem );
315 }
virtual bool IsContainer(wxDataViewItem const &aItem) const override
Check whether an item can have children.
unsigned int CMP_TREE_MODEL_ADAPTER_BASE::IntoArray ( CMP_TREE_NODE const &  aNode,
wxDataViewItemArray &  aChildren 
)
staticprotectedinherited

Convert CMP_TREE_NODE's children to wxDataViewItemArray.

Definition at line 61 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_NODE::Children, and CMP_TREE_MODEL_ADAPTER_BASE::ToItem().

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

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

Check whether an item can have children.

Reimplemented in LIB_MANAGER_ADAPTER.

Definition at line 318 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::HasContainerColumns().

319 {
320  auto node = ToNode( aItem );
321  return node ? node->Children.size() : true;
322 }
static CMP_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
void CMP_TREE_MODEL_ADAPTER_BASE::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 94 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::m_filter.

95 {
96  m_filter = aFilter;
97 }
void CMP_TREE_MODEL_ADAPTER_BASE::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 106 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::m_preselect_lib_id, and CMP_TREE_MODEL_ADAPTER_BASE::m_preselect_unit.

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetFilter().

virtual bool CMP_TREE_MODEL_ADAPTER_BASE::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 328 of file cmp_tree_model_adapter_base.h.

References CMP_TREE_MODEL_ADAPTER_BASE::GetAttr().

331  { return false; }
void CMP_TREE_MODEL_ADAPTER_BASE::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 100 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::m_show_units.

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetFilter().

101 {
102  m_show_units = aShow;
103 }
void CMP_TREE_MODEL_ADAPTER_BASE::Thaw ( )
inlineinherited
wxDataViewItem CMP_TREE_MODEL_ADAPTER_BASE::ToItem ( CMP_TREE_NODE const *  aNode)
staticprotectedinherited

Convert CMP_TREE_NODE -> wxDataViewItem.

Definition at line 43 of file cmp_tree_model_adapter_base.cpp.

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

44 {
45  return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
46 }
void CMP_TREE_MODEL_ADAPTER_BASE::UpdateSearchString ( wxString const &  aSearch)
inherited

Set the search string provided by the user.

Parameters
aSearchfull, unprocessed search text

Definition at line 162 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::AttachTo(), CMP_TREE_MODEL_ADAPTER_BASE::m_tree, CMP_TREE_MODEL_ADAPTER_BASE::m_widget, CMP_TREE_NODE::ResetScore(), CMP_TREE_MODEL_ADAPTER_BASE::ShowPreselect(), CMP_TREE_MODEL_ADAPTER_BASE::ShowResults(), CMP_TREE_MODEL_ADAPTER_BASE::ShowSingleLibrary(), CMP_TREE_NODE::SortNodes(), and CMP_TREE_NODE_ROOT::UpdateScore().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetFilter().

163 {
164  m_tree.ResetScore();
165 
166  wxStringTokenizer tokenizer( aSearch );
167 
168  while( tokenizer.HasMoreTokens() )
169  {
170  const wxString term = tokenizer.GetNextToken().Lower();
171  EDA_COMBINED_MATCHER matcher( term );
172 
173  m_tree.UpdateScore( matcher );
174  }
175 
176  m_tree.SortNodes();
177 
178  {
179  wxWindowUpdateLocker updateLock( m_widget );
180 
181  // Even with the updateLock, wxWidgets sometimes ties its knickers in
182  // a knot when trying to run a wxdataview_selection_changed_callback()
183  // on a row that has been deleted.
184  // https://bugs.launchpad.net/kicad/+bug/1756255
185  m_widget->UnselectAll();
186 
187  Cleared();
188 #ifndef __WINDOWS__
189  // The fastest method to update wxDataViewCtrl is to rebuild from
190  // scratch by calling Cleared(). Linux requires to reassociate model to
191  // display data, but Windows will create multiple associations.
192  AttachTo( m_widget );
193 #endif
194  }
195 
196  CMP_TREE_NODE* bestMatch = ShowResults();
197 
198  if( !bestMatch )
199  bestMatch = ShowPreselect();
200 
201  if( !bestMatch )
202  bestMatch = ShowSingleLibrary();
203 
204  if( bestMatch )
205  {
206  auto item = wxDataViewItem( bestMatch );
207  m_widget->Select( item );
208  m_widget->EnsureVisible( item );
209  }
210 }
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Update the score for this part.
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
void SortNodes()
Sort child nodes quickly and recursively (IntrinsicRanks must have been set).
CMP_TREE_NODE * ShowResults()
Find and expand successful search results.
CMP_TREE_NODE * ShowPreselect()
Find and expand preselected node.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
CMP_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

SYMBOL_LIB_TABLE* CMP_TREE_MODEL_ADAPTER::m_libs
private

Definition at line 80 of file cmp_tree_model_adapter.h.

Referenced by AddAliasList(), and AddLibrary().


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