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

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:47
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 146 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.

148 {
149  auto& lib_node = m_tree.AddLib( aNodeName, aDesc );
150 
151  for( auto a: aAliasList )
152  {
153  lib_node.AddAlias( a );
154  }
155 
156  lib_node.AssignIntrinsicRanks();
158 }
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 112 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().

114 {
115  wxProgressDialog* prg = nullptr;
116  wxLongLong nextUpdate = wxGetUTCTimeMillis() + (PROGRESS_INTERVAL_MILLIS / 2);
117 
118  if( m_show_progress )
119  prg = new wxProgressDialog( _( "Loading Symbol Libraries" ),
120  wxEmptyString,
121  aNicknames.size(),
122  aParent );
123 
124  unsigned int ii = 0;
125 
126  for( const auto& nickname : aNicknames )
127  {
128  if( prg && wxGetUTCTimeMillis() > nextUpdate )
129  {
130  prg->Update( ii, wxString::Format( _( "Loading library \"%s\"" ), nickname ) );
131  nextUpdate = wxGetUTCTimeMillis() + PROGRESS_INTERVAL_MILLIS;
132  }
133 
134  AddLibrary( nickname );
135  ii++;
136  }
137 
138  if( prg )
139  {
140  prg->Destroy();
141  m_show_progress = false;
142  }
143 }
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: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 193 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().

194 {
195  m_widget = aDataViewCtrl;
196  aDataViewCtrl->SetIndent( kDataViewIndent );
197  aDataViewCtrl->AssociateModel( this );
198  aDataViewCtrl->ClearColumns();
199 
200  wxString part_head = _( "Symbol" );
201  wxString desc_head = _( "Desc" );
202 
203  m_col_part = aDataViewCtrl->AppendTextColumn( part_head, 0, wxDATAVIEW_CELL_INERT,
204  ColWidth( m_tree, 0, part_head ) );
205  m_col_desc = aDataViewCtrl->AppendTextColumn( desc_head, 1, wxDATAVIEW_CELL_INERT,
206  ColWidth( m_tree, 1, desc_head ) );
207 }
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 254 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().

255 {
256  for( auto& lib: m_tree.Children )
257  {
258  if( lib->Name != aLibId.GetLibNickname() )
259  continue;
260 
261  // if part name is not specified, return the library node
262  if( aLibId.GetLibItemName() == "" )
263  return ToItem( lib.get() );
264 
265  for( auto& alias: lib->Children )
266  {
267  if( alias->Name == aLibId.GetLibItemName() )
268  return ToItem( alias.get() );
269  }
270 
271  break; // could not find the part in the requested library
272  }
273 
274  return wxDataViewItem();
275 }
const UTF8 & GetLibItemName() const
Definition: lib_id.h:115
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:98
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 210 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetFilter().

211 {
212  auto node = ToNode( aSelection );
213 
214  LIB_ID emptyId;
215 
216  if( !node )
217  return emptyId;
218 
219  return node->LibId;
220 }
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 344 of file cmp_tree_model_adapter_base.cpp.

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

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::SetValue().

348 {
349  auto node = ToNode( aItem );
350  wxASSERT( node );
351 
352  if( node->Type != CMP_TREE_NODE::LIBID )
353  {
354  // Currently only aliases are formatted at all
355  return false;
356  }
357 
358  if( !node->IsRoot && aCol == 0 )
359  {
360  // Names of non-root aliases are italicized
361  aAttr.SetItalic( true );
362  return true;
363  }
364  else
365  {
366  return false;
367  }
368 }
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 278 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().

281 {
282  auto node = ( aItem.IsOk() ? ToNode( aItem ) : &m_tree );
283 
284  if( node->Type != CMP_TREE_NODE::TYPE::LIBID
285  || ( m_show_units && node->Type == CMP_TREE_NODE::TYPE::LIBID ) )
286  return IntoArray( *node, aChildren );
287  else
288  return 0;
289 }
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 296 of file cmp_tree_model_adapter_base.h.

296 { 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 303 of file cmp_tree_model_adapter_base.h.

References CMP_TREE_MODEL_ADAPTER_BASE::GetValue().

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

Return the number of components loaded in the tree.

Definition at line 237 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().

238 {
239  int n = 0;
240 
241  for( auto& lib: m_tree.Children )
242  {
243  for( auto& alias: lib->Children )
244  {
245  (void) alias;
246  ++n;
247  }
248  }
249 
250  return n;
251 }
PTR_VECTOR Children
List of child nodes.
virtual int CMP_TREE_MODEL_ADAPTER_BASE::GetLibrariesCount ( ) const
inlinevirtualinherited
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 305 of file cmp_tree_model_adapter_base.cpp.

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

306 {
307  auto node = ToNode( aItem );
308  auto parent = node ? node->Parent : nullptr;
309 
310  // wxDataViewModel has no root node, but rather top-level elements have
311  // an invalid (null) parent.
312  if( !node || !parent || parent->Type == CMP_TREE_NODE::TYPE::ROOT )
313  {
314  return ToItem( nullptr );
315  }
316  else
317  {
318  return ToItem( parent );
319  }
320 }
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 230 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().

231 {
232  auto node = ToNode( aSelection );
233  return node ? node->Type : CMP_TREE_NODE::INVALID;
234 }
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 223 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetFilter().

224 {
225  auto node = ToNode( aSelection );
226  return node ? node->Unit : 0;
227 }
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 323 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::GetColumnType().

327 {
328  auto node = ToNode( aItem );
329  wxASSERT( node );
330 
331  switch( aCol )
332  {
333  default: // column == -1 is used for default Compare function
334  case 0:
335  aVariant = node->Name;
336  break;
337  case 1:
338  aVariant = node->Desc;
339  break;
340  }
341 }
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 292 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::IsContainer().

293 {
294  return IsContainer( aItem );
295 }
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::GetLibrariesCount().

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 298 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::ToNode().

Referenced by CMP_TREE_MODEL_ADAPTER_BASE::HasContainerColumns().

299 {
300  auto node = ToNode( aItem );
301  return node ? node->Children.size() : true;
302 }
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 93 of file cmp_tree_model_adapter_base.cpp.

References CMP_TREE_MODEL_ADAPTER_BASE::m_filter.

94 {
95  m_filter = aFilter;
96 }
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 105 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 321 of file cmp_tree_model_adapter_base.h.

References CMP_TREE_MODEL_ADAPTER_BASE::GetAttr().

324  { 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 99 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().

100 {
101  m_show_units = aShow;
102 }
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::GetLibrariesCount(), CMP_TREE_MODEL_ADAPTER_BASE::GetParent(), and CMP_TREE_MODEL_ADAPTER_BASE::IntoArray().

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

162 {
163  m_tree.ResetScore();
164 
165  wxStringTokenizer tokenizer( aSearch );
166 
167  while( tokenizer.HasMoreTokens() )
168  {
169  const wxString term = tokenizer.GetNextToken().Lower();
170  EDA_COMBINED_MATCHER matcher( term );
171 
172  m_tree.UpdateScore( matcher );
173  }
174 
175  m_tree.SortNodes();
176 
177  {
178  wxWindowUpdateLocker updateLock( m_widget );
179 
180  Cleared();
181 #ifndef __WINDOWS__
182  // The fastest method to update wxDataViewCtrl is to rebuild from
183  // scratch by calling Cleared(). Linux requires to reassociate model to
184  // display data, but Windows will create multiple associations.
185  AttachTo( m_widget );
186 #endif
187  }
188 
190 }
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).
bool ShowSingleLibrary()
Find and expand a library if there is only one.
void AttachTo(wxDataViewCtrl *aDataViewCtrl)
Attach to a wxDataViewCtrl and initialize it.
bool ShowResults()
Find and expand successful search results.
bool ShowPreselect()
Find and expand preselected node.

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: