KiCad PCB EDA Suite
FP_TREE_SYNCHRONIZING_ADAPTER Class Reference

#include <fp_tree_synchronizing_adapter.h>

Inheritance diagram for FP_TREE_SYNCHRONIZING_ADAPTER:
FP_TREE_MODEL_ADAPTER LIB_TREE_MODEL_ADAPTER

Public Types

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

Public Member Functions

bool IsContainer (const wxDataViewItem &aItem) const override
 Check whether an item can have children. More...
 
void Sync ()
 
int GetLibrariesCount () const override
 Return the number of libraries loaded in the tree. 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...
 
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 (FOOTPRINT_EDIT_FRAME *aFrame, FP_LIB_TABLE *aLibs)
 
static PTR Create (LIB_TABLE *aLibs)
 Factory function: create a model adapter in a reference-counting container. More...
 

Protected Member Functions

 FP_TREE_SYNCHRONIZING_ADAPTER (FOOTPRINT_EDIT_FRAME *aFrame, FP_LIB_TABLE *aLibs)
 
void updateLibrary (LIB_TREE_NODE_LIB &aLibNode)
 
LIB_TREE_NODE::PTR_VECTOR::iterator deleteLibrary (LIB_TREE_NODE::PTR_VECTOR::iterator &aLibNodeIt)
 
void GetValue (wxVariant &aVariant, wxDataViewItem const &aItem, unsigned int aCol) const override
 Get the value of an item. More...
 
bool GetAttr (wxDataViewItem const &aItem, unsigned int aCol, wxDataViewItemAttr &aAttr) const override
 Get any formatting for an item. 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 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 bool SetValue (wxVariant const &aVariant, wxDataViewItem const &aItem, unsigned int aCol) override
 Set the value of 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

FOOTPRINT_EDIT_FRAMEm_frame
 
std::set< wxString > m_libMap
 
FP_LIB_TABLEm_libs
 
LIB_TREE_NODE_ROOT m_tree
 

Detailed Description

Definition at line 33 of file fp_tree_synchronizing_adapter.h.

Member Typedef Documentation

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_SYNCHRONIZING_ADAPTER::FP_TREE_SYNCHRONIZING_ADAPTER ( FOOTPRINT_EDIT_FRAME aFrame,
FP_LIB_TABLE aLibs 
)
protected

Definition at line 40 of file fp_tree_synchronizing_adapter.cpp.

Referenced by Create().

41  :
42  FP_TREE_MODEL_ADAPTER( aLibs ),
43  m_frame( aFrame )
44 {
45 }
FP_TREE_MODEL_ADAPTER(LIB_TABLE *aLibs)
Constructor; takes a set of libraries to be included in the search.

Member Function Documentation

void FP_TREE_MODEL_ADAPTER::AddLibraries ( )
inherited

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(), FP_TREE_MODEL_ADAPTER::getFootprints(), LIB_TABLE::GetLogicalLibs(), FP_TREE_MODEL_ADAPTER::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
LIB_TREE_MODEL_ADAPTER::PTR FP_TREE_SYNCHRONIZING_ADAPTER::Create ( FOOTPRINT_EDIT_FRAME aFrame,
FP_LIB_TABLE aLibs 
)
static

Definition at line 33 of file fp_tree_synchronizing_adapter.cpp.

References FP_TREE_SYNCHRONIZING_ADAPTER().

Referenced by FOOTPRINT_EDIT_FRAME::initLibraryTree().

35 {
36  return PTR( new FP_TREE_SYNCHRONIZING_ADAPTER( aFrame, aLibs ) );
37 }
FP_TREE_SYNCHRONIZING_ADAPTER(FOOTPRINT_EDIT_FRAME *aFrame, FP_LIB_TABLE *aLibs)
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > PTR
Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.
FP_TREE_MODEL_ADAPTER::PTR FP_TREE_MODEL_ADAPTER::Create ( LIB_TABLE aLibs)
staticinherited

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

Parameters
aLibslibrary set from which parts will be loaded

Definition at line 31 of file fp_tree_model_adapter.cpp.

References FP_TREE_MODEL_ADAPTER::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.
LIB_TREE_NODE::PTR_VECTOR::iterator FP_TREE_SYNCHRONIZING_ADAPTER::deleteLibrary ( LIB_TREE_NODE::PTR_VECTOR::iterator &  aLibNodeIt)
protected

Definition at line 139 of file fp_tree_synchronizing_adapter.cpp.

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

Referenced by Sync().

141 {
142  LIB_TREE_NODE* node = aLibNodeIt->get();
143  m_libMap.erase( node->Name );
144  auto it = m_tree.Children.erase( aLibNodeIt );
145  return it;
146 }
PTR_VECTOR Children
List of child nodes.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
wxString Name
Actual name of the part.
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 FP_TREE_MODEL_ADAPTER::AddLibraries(), SYMBOL_TREE_MODEL_ADAPTER::AddLibrary(), LIB_TREE_MODEL_ADAPTER::GetFilter(), PCB_BASE_FRAME::SelectFootprintFromLibTree(), and 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 
)
overridevirtualinherited

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 81 of file fp_tree_model_adapter.cpp.

References GenerateFootprintInfo(), and FP_TREE_MODEL_ADAPTER::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 FP_TREE_SYNCHRONIZING_ADAPTER::GetAttr ( wxDataViewItem const &  aItem,
unsigned int  aCol,
wxDataViewItemAttr &  aAttr 
) const
overrideprotectedvirtual

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

Definition at line 188 of file fp_tree_synchronizing_adapter.cpp.

References LIB_ID::GetLibNickname(), FOOTPRINT_EDIT_FRAME::GetLoadedFPID(), PCB_BASE_FRAME::GetScreen(), FOOTPRINT_EDIT_FRAME::IsCurrentFPFromBoard(), LIB_TREE_MODEL_ADAPTER::IsFrozen(), BASE_SCREEN::IsModify(), LIB_TREE_NODE::LIB, LIB_TREE_NODE::LIBID, m_frame, and LIB_TREE_MODEL_ADAPTER::ToNode().

190 {
191  if( IsFrozen() )
192  return false;
193 
194  // change attributes only for the name field
195  if( aCol != 0 )
196  return false;
197 
198  // don't link to a board footprint, even if the FPIDs match
200  return false;
201 
202  auto node = ToNode( aItem );
203  wxCHECK( node, false );
204 
205  switch( node->Type )
206  {
207  case LIB_TREE_NODE::LIB:
208  if( node->Name == m_frame->GetLoadedFPID().GetLibNickname() )
209  {
210 #ifdef __WXGTK__
211  // The native wxGTK+ impl ignores background colour, so set the text colour
212  // instead. Works reasonably well in dark themes, less well in light ones....
213  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
214 #else
215  aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
216 #endif
217 
218  // mark modified libs with bold font
220  aAttr.SetBold( true );
221  }
222  break;
223 
225  if( node->LibId == m_frame->GetLoadedFPID() )
226  {
227 #ifdef __WXGTK__
228  // The native wxGTK+ impl ignores background colour, so set the text colour
229  // instead. Works reasonably well in dark themes, less well in light ones....
230  aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
231 #else
232  aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
233 #endif
234 
235  // mark modified part with bold font
237  aAttr.SetBold( true );
238  }
239  break;
240 
241  default:
242  return false;
243  }
244 
245  return true;
246 }
bool IsModify() const
Definition: base_screen.h:328
LIB_ID GetLoadedFPID() const
Return the LIB_ID of the part being edited.
static LIB_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
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)
protectedinherited

Definition at line 59 of file fp_tree_model_adapter.cpp.

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

Referenced by FP_TREE_MODEL_ADAPTER::AddLibraries(), Sync(), and 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.
int FP_TREE_SYNCHRONIZING_ADAPTER::GetLibrariesCount ( ) const
overridevirtual

Return the number of libraries loaded in the tree.

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 93 of file fp_tree_synchronizing_adapter.cpp.

References LIB_TABLE::GetCount(), and GFootprintTable.

94 {
95  return GFootprintTable.GetCount();
96 }
int GetCount()
FP_LIB_TABLE GFootprintTable
The global footprint library table.
Definition: pcbnew.cpp:333
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 FP_TREE_SYNCHRONIZING_ADAPTER::GetValue ( wxVariant &  aVariant,
wxDataViewItem const &  aItem,
unsigned int  aCol 
) const
overrideprotectedvirtual

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

Definition at line 149 of file fp_tree_synchronizing_adapter.cpp.

References PCB_BASE_FRAME::GetBoard(), MODULE::GetFPID(), LIB_ID::GetLibItemName(), FOOTPRINT_EDIT_FRAME::GetLoadedFPID(), PCB_BASE_FRAME::GetScreen(), FOOTPRINT_EDIT_FRAME::IsCurrentFPFromBoard(), LIB_TREE_MODEL_ADAPTER::IsFrozen(), BASE_SCREEN::IsModify(), m_frame, BOARD::m_Modules, and LIB_TREE_MODEL_ADAPTER::ToNode().

151 {
152  if( IsFrozen() )
153  {
154  aVariant = wxEmptyString;
155  return;
156  }
157 
158  auto node = ToNode( aItem );
159 
160  switch( aCol )
161  {
162  case 0:
163  if( node->LibId == m_frame->GetLoadedFPID() && !m_frame->IsCurrentFPFromBoard() )
164  {
165  wxString currentFPName = m_frame->GetBoard()->m_Modules->GetFPID().GetLibItemName();
166 
167  // mark modified part with an asterix
168  if( m_frame->GetScreen()->IsModify() )
169  aVariant = currentFPName + " *";
170  else
171  aVariant = currentFPName;
172  }
173  else
174  aVariant = node->Name;
175  break;
176 
177  case 1:
178  aVariant = node->Desc;
179  break;
180 
181  default: // column == -1 is used for default Compare function
182  aVariant = node->Name;
183  break;
184  }
185 }
BOARD * GetBoard() const
bool IsModify() const
Definition: base_screen.h:328
const LIB_ID & GetFPID() const
Definition: class_module.h:193
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
LIB_ID GetLoadedFPID() const
Return the LIB_ID of the part being edited.
static LIB_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
DLIST< MODULE > m_Modules
Definition: class_board.h:248
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
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 FP_TREE_SYNCHRONIZING_ADAPTER::IsContainer ( const wxDataViewItem &  aItem) const
overridevirtual

Check whether an item can have children.

Reimplemented from LIB_TREE_MODEL_ADAPTER.

Definition at line 48 of file fp_tree_synchronizing_adapter.cpp.

References LIB_TREE_NODE::LIB, LIB_TREE_MODEL_ADAPTER::ToNode(), and LIB_TREE_NODE::Type.

49 {
50  const LIB_TREE_NODE* node = ToNode( aItem );
51  return node ? node->Type == LIB_TREE_NODE::LIB : true;
52 }
enum TYPE Type
Node type.
static LIB_TREE_NODE const * ToNode(wxDataViewItem aItem)
Convert wxDataViewItem -> CMP_TREE_NODE.
Model class in the component selector Model-View-Adapter (mediated MVC) architecture.
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 FP_TREE_SYNCHRONIZING_ADAPTER::Sync ( )

Definition at line 57 of file fp_tree_synchronizing_adapter.cpp.

References LIB_TREE_NODE::AssignIntrinsicRanks(), LIB_TREE_NODE::Children, deleteLibrary(), LIB_TREE_MODEL_ADAPTER::DoAddLibrary(), FP_LIB_TABLE::FindRow(), LIB_TABLE_ROW::GetDescr(), FP_TREE_MODEL_ADAPTER::getFootprints(), LIB_TABLE::GetLogicalLibs(), LIB_TABLE::HasLibrary(), m_libMap, FP_TREE_MODEL_ADAPTER::m_libs, LIB_TREE_MODEL_ADAPTER::m_tree, name, and updateLibrary().

58 {
59  // Process already stored libraries
60  for( auto it = m_tree.Children.begin(); it != m_tree.Children.end(); )
61  {
62  const wxString& name = it->get()->Name;
63 
64  if( !m_libs->HasLibrary( name, true ) )
65  {
66  it = deleteLibrary( it );
67  continue;
68  }
69 
70  updateLibrary( *(LIB_TREE_NODE_LIB*) it->get() );
71  ++it;
72  }
73 
74  // Look for new libraries
75  size_t count = m_libMap.size();
76 
77  for( const auto& libName : m_libs->GetLogicalLibs() )
78  {
79  if( m_libMap.count( libName ) == 0 )
80  {
81  const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName );
82 
83  DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true );
84  m_libMap.insert( libName );
85  }
86  }
87 
88  if( m_libMap.size() > count )
90 }
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.
PTR_VECTOR Children
List of child nodes.
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
std::vector< LIB_TREE_ITEM * > getFootprints(const wxString &aLibName)
LIB_TREE_NODE::PTR_VECTOR::iterator deleteLibrary(LIB_TREE_NODE::PTR_VECTOR::iterator &aLibNodeIt)
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
Node type: library.
const wxString & GetDescr() const
Return the description of the library referenced by this row.
void updateLibrary(LIB_TREE_NODE_LIB &aLibNode)
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
const char * name
Definition: DXF_plotter.cpp:61
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::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 FP_TREE_SYNCHRONIZING_ADAPTER::updateLibrary ( LIB_TREE_NODE_LIB aLibNode)
protected

Definition at line 99 of file fp_tree_synchronizing_adapter.cpp.

References LIB_TREE_NODE_LIB::AddItem(), LIB_TREE_NODE::AssignIntrinsicRanks(), LIB_TREE_NODE::Children, dummy(), FP_TREE_MODEL_ADAPTER::getFootprints(), FOOTPRINT_INFO::GetName(), m_libMap, LIB_TREE_NODE::Name, and StrNumCmp().

Referenced by Sync().

100 {
101  std::vector<LIB_TREE_ITEM*> footprints = getFootprints( aLibNode.Name );
102 
103  // remove the common part from the footprints list
104  for( auto nodeIt = aLibNode.Children.begin(); nodeIt != aLibNode.Children.end(); )
105  {
106  // Since the list is sorted we can use a binary search to speed up searches within
107  // libraries with lots of footprints.
108  FOOTPRINT_INFO_IMPL dummy( wxEmptyString, (*nodeIt)->Name );
109  auto footprintIt = std::lower_bound( footprints.begin(), footprints.end(), &dummy,
110  []( LIB_TREE_ITEM* a, LIB_TREE_ITEM* b )
111  {
112  return StrNumCmp( a->GetName(), b->GetName(), INT_MAX, true ) < 0;
113  } );
114 
115  if( footprintIt != footprints.end() && dummy.GetName() == (*footprintIt)->GetName() )
116  {
117  // footprint exists both in the lib tree and the footprint info list; just
118  // update the node data
119  static_cast<LIB_TREE_NODE_LIB_ID*>( nodeIt->get() )->Update( *footprintIt );
120  footprints.erase( footprintIt );
121  ++nodeIt;
122  }
123  else
124  {
125  // node does not exist in the library manager, remove the corresponding node
126  nodeIt = aLibNode.Children.erase( nodeIt );
127  }
128  }
129 
130  // now the footprint list contains only new aliases that need to be added to the tree
131  for( auto footprint : footprints )
132  aLibNode.AddItem( footprint );
133 
134  aLibNode.AssignIntrinsicRanks();
135  m_libMap.insert( aLibNode.Name );
136 }
PTR_VECTOR Children
List of child nodes.
A mix-in to provide polymorphism between items stored in libraries (symbols, aliases and footprints)...
Definition: lib_tree_item.h:39
Node type: LIB_ID.
std::vector< LIB_TREE_ITEM * > getFootprints(const wxString &aLibName)
LIB_TREE_NODE_LIB_ID & AddItem(LIB_TREE_ITEM *aItem)
Construct a new alias node, add it to this library, and return it.
wxString Name
Actual name of the part.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
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...
const wxString & GetName() const
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
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

FOOTPRINT_EDIT_FRAME* FP_TREE_SYNCHRONIZING_ADAPTER::m_frame
protected

Definition at line 56 of file fp_tree_synchronizing_adapter.h.

Referenced by GetAttr(), and GetValue().

std::set<wxString> FP_TREE_SYNCHRONIZING_ADAPTER::m_libMap
protected

Definition at line 57 of file fp_tree_synchronizing_adapter.h.

Referenced by deleteLibrary(), Sync(), and updateLibrary().

FP_LIB_TABLE* FP_TREE_MODEL_ADAPTER::m_libs
protectedinherited

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