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, 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...
 
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...
 

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 69 of file cmp_tree_model_adapter.cpp.

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

Referenced by AddLibrary().

72 {
73  std::vector<LIB_ALIAS*> alias_list;
74 
75  for( const wxString& name: aAliasNameList )
76  {
77  LIB_ALIAS* a = nullptr;
78 
79  try
80  {
81  a = m_libs->LoadSymbol( aNodeName, name );
82  }
83  catch( const IO_ERROR& ioe )
84  {
85  wxLogError( wxString::Format( _( "Error occurred loading symbol %s from library %s."
86  "\n\n%s" ), name, aNodeName, ioe.What() ) );
87  continue;
88  }
89 
90  if( a )
91  alias_list.push_back( a );
92  }
93 
94  AddAliasList( aNodeName, alias_list );
95 }
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.
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
const char * name
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
void CMP_TREE_MODEL_ADAPTER_BASE::AddAliasList ( wxString const &  aNodeName,
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
aAliasListlist of aliases

Definition at line 129 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.

132 {
133  auto& lib_node = m_tree.AddLib( aNodeName );
134 
135  for( auto a: aAliasList )
136  {
137  lib_node.AddAlias( a );
138  }
139 
140  lib_node.AssignIntrinsicRanks();
142 }
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.
CMP_TREE_NODE_LIB & AddLib(wxString const &aName)
Construct an empty library node, add it to the root, and return it.
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 108 of file cmp_tree_model_adapter_base.cpp.

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

110 {
111  auto* prg = new wxProgressDialog(
112  _( "Loading symbol libraries" ),
113  wxEmptyString,
114  aNicknames.size(),
115  aParent );
116 
117  unsigned int ii = 0;
118 
119  for( auto nickname : aNicknames )
120  {
121  prg->Update( ii++, wxString::Format( _( "Loading library '%s'" ), nickname ) );
122  AddLibrary( nickname );
123  }
124 
125  prg->Destroy();
126 }
virtual void AddLibrary(wxString const &aLibNickname)=0
Add all the components and their aliases in this library.
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, SYMBOL_LIB_TABLE::EnumerateSymbolLib(), Format(), CMP_TREE_MODEL_ADAPTER_BASE::GetFilter(), m_libs, CMP_TREE_MODEL_ADAPTER_BASE::m_tree, and IO_ERROR::What().

47 {
48  bool onlyPowerSymbols = ( GetFilter() == CMP_FILTER_POWER );
49 
50  wxArrayString aliases;
51 
52  try
53  {
54  m_libs->EnumerateSymbolLib( aLibNickname, aliases, 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  AddAliasList( aLibNickname, aliases );
64 
66 }
void EnumerateSymbolLib(const wxString &aNickname, wxArrayString &aAliasNames, bool aPowerSymbolsOnly=false)
Return a list of symbol alias names contained within the library given by aNickname.
void AssignIntrinsicRanks()
Store intrinsic ranks on all children of this node.
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:47
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 166 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.

167 {
168  m_widget = aDataViewCtrl;
169  aDataViewCtrl->Freeze();
170  aDataViewCtrl->SetIndent( kDataViewIndent );
171  aDataViewCtrl->AssociateModel( this );
172  aDataViewCtrl->ClearColumns();
173 
174  wxString part_head = _( "Part" );
175  wxString desc_head = _( "Desc" );
176 
177  m_col_part = aDataViewCtrl->AppendTextColumn( part_head, 0, wxDATAVIEW_CELL_INERT,
178  ColWidth( m_tree, 0, part_head ) );
179  m_col_desc = aDataViewCtrl->AppendTextColumn( desc_head, 1, wxDATAVIEW_CELL_INERT,
180  ColWidth( m_tree, 1, desc_head ) );
181  m_col_part->SetSortOrder( 0 );
182  aDataViewCtrl->Thaw();
183 }
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 230 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().

231 {
232  for( auto& lib: m_tree.Children )
233  {
234  if( lib->Name != aLibId.GetLibNickname() )
235  continue;
236 
237  // if part name is not specified, return the library node
238  if( aLibId.GetLibItemName() == "" )
239  return ToItem( lib.get() );
240 
241  for( auto& alias: lib->Children )
242  {
243  if( alias->Name == aLibId.GetLibItemName() )
244  return ToItem( alias.get() );
245  }
246 
247  break; // could not find the part in the requested library
248  }
249 
250  return wxDataViewItem();
251 }
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
PTR_VECTOR Children
List of child nodes.
static wxDataViewItem ToItem(CMP_TREE_NODE const *aNode)
Convert CMP_TREE_NODE -> wxDataViewItem.
const UTF8 & GetLibNickname() const
Function GetLibNickname.
Definition: lib_id.h:108
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 186 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

187 {
188  auto node = ToNode( aSelection );
189 
190  LIB_ID emptyId;
191 
192  if( !node )
193  return emptyId;
194 
195  return node->LibId;
196 }
Class LIB_ID.
Definition: lib_id.h:56
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 320 of file cmp_tree_model_adapter_base.cpp.

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

324 {
325  auto node = ToNode( aItem );
326  wxASSERT( node );
327 
328  if( node->Type != CMP_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 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 254 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().

257 {
258  auto node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
259 
260  if( node->Type != CMP_TREE_NODE::TYPE::LIBID
261  || ( m_show_units && node->Type == CMP_TREE_NODE::TYPE::LIBID ) )
262  return IntoArray( *node, aChildren );
263  else
264  return 0;
265 }
static unsigned int IntoArray(CMP_TREE_NODE const &aNode, wxDataViewItemArray &aChildren)
Convert CMP_TREE_NODE'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 286 of file cmp_tree_model_adapter_base.h.

286 { 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 293 of file cmp_tree_model_adapter_base.h.

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

Return the number of components loaded in the tree.

Definition at line 213 of file cmp_tree_model_adapter_base.cpp.

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

214 {
215  int n = 0;
216 
217  for( auto& lib: m_tree.Children )
218  {
219  for( auto& alias: lib->Children )
220  {
221  (void) alias;
222  ++n;
223  }
224  }
225 
226  return n;
227 }
PTR_VECTOR Children
List of child nodes.
CMP_FILTER_TYPE CMP_TREE_MODEL_ADAPTER_BASE::GetFilter ( ) const
inlineinherited

Return the active filter.

Definition at line 126 of file cmp_tree_model_adapter_base.h.

References CMP_TREE_MODEL_ADAPTER_BASE::m_filter.

Referenced by AddLibrary().

126 { return m_filter; }
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 281 of file cmp_tree_model_adapter_base.cpp.

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

282 {
283  auto node = ToNode( aItem );
284  auto parent = node ? node->Parent : nullptr;
285 
286  // wxDataViewModel has no root node, but rather top-level elements have
287  // an invalid (null) parent.
288  if( !node || !parent || parent->Type == CMP_TREE_NODE::TYPE::ROOT )
289  {
290  return ToItem( nullptr );
291  }
292  else
293  {
294  return ToItem( parent );
295  }
296 }
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 206 of file cmp_tree_model_adapter_base.cpp.

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

207 {
208  auto node = ToNode( aSelection );
209  return node ? node->Type : CMP_TREE_NODE::INVALID;
210 }
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 199 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

200 {
201  auto node = ToNode( aSelection );
202  return node ? node->Unit : 0;
203 }
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

Definition at line 299 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

303 {
304  auto node = ToNode( aItem );
305  wxASSERT( node );
306 
307  switch( aCol )
308  {
309  default: // column == -1 is used for default Compare function
310  case 0:
311  aVariant = node->Name;
312  break;
313  case 1:
314  aVariant = node->Desc;
315  break;
316  }
317 }
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 268 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::IsContainer().

269 {
270  return IsContainer( aItem );
271 }
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 57 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().

59 {
60  unsigned int n = 0;
61 
62  for( auto const& child: aNode.Children )
63  {
64  if( child->Score > 0 && child->InTree )
65  {
66  aChildren.Add( ToItem( &*child ) );
67  ++n;
68  }
69  }
70 
71  return n;
72 }
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 274 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::HasContainerColumns().

275 {
276  auto node = ToNode( aItem );
277  return node ? node->Children.size() : true;
278 }
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 89 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::m_filter.

90 {
91  m_filter = aFilter;
92 }
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 101 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.

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 311 of file cmp_tree_model_adapter_base.h.

314  { 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 95 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::m_show_units.

96 {
97  m_show_units = aShow;
98 }
wxDataViewItem CMP_TREE_MODEL_ADAPTER_BASE::ToItem ( CMP_TREE_NODE const *  aNode)
staticprotectedinherited
CMP_TREE_NODE const * CMP_TREE_MODEL_ADAPTER_BASE::ToNode ( wxDataViewItem  aItem)
staticprotectedinherited
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 145 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::filterContents(), 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(), and CMP_TREE_NODE_ROOT::UpdateScore().

146 {
147  m_widget->Freeze();
148  m_tree.ResetScore();
149 
150  wxStringTokenizer tokenizer( aSearch );
151 
152  while( tokenizer.HasMoreTokens() )
153  {
154  const wxString term = tokenizer.GetNextToken().Lower();
155  EDA_COMBINED_MATCHER matcher( term );
156 
157  m_tree.UpdateScore( matcher );
158  }
159 
160  filterContents();
162  m_widget->Thaw();
163 }
virtual void UpdateScore(EDA_COMBINED_MATCHER &aMatcher) override
Update the score for this part.
void ResetScore()
Initialize score to kLowestDefaultScore, recursively.
bool ShowSingleLibrary()
Find and expand a library if there is only one.
bool ShowResults()
Find and expand successful search results.
bool ShowPreselect()
Find and expand preselected node.
void filterContents()
Filters the items shown in the view according to the score.

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: