KiCad PCB EDA Suite
fp_tree_model_adapter.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2018-2019 KiCad Developers, see AUTHORS.txt for contributors.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <wx/tokenzr.h>
21 #include <kicad_string.h>
22 #include <eda_pattern_match.h>
23 #include <fp_lib_table.h>
24 #include <footprint_info.h>
25 #include <footprint_info_impl.h>
27 
28 #include "fp_tree_model_adapter.h"
29 
30 wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
32 {
33  auto* adapter = new FP_TREE_MODEL_ADAPTER( aParent, aLibs );
34  return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
35 }
36 
37 
39  LIB_TREE_MODEL_ADAPTER( aParent, "pinned_footprint_libs" ),
40  m_libs( (FP_LIB_TABLE*) aLibs )
41 {}
42 
43 
45 {
46  for( const wxString& libName : m_libs->GetLogicalLibs() )
47  {
48  const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName );
49 
50  DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true );
51  }
52 
54 }
55 
56 
57 std::vector<LIB_TREE_ITEM*> FP_TREE_MODEL_ADAPTER::getFootprints( const wxString& aLibName )
58 {
59  std::vector<LIB_TREE_ITEM*> libList;
60 
61  auto fullListStart = GFootprintList.GetList().begin();
62  auto fullListEnd = GFootprintList.GetList().end();
63  std::unique_ptr<FOOTPRINT_INFO> dummy = std::make_unique<FOOTPRINT_INFO_IMPL>( aLibName, wxEmptyString );
64 
65  // List is sorted, so use a binary search to find the range of footnotes for our library
66  auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy,
67  []( const std::unique_ptr<FOOTPRINT_INFO>& a,
68  const std::unique_ptr<FOOTPRINT_INFO>& b )
69  {
70  return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), false ) < 0;
71  } );
72 
73  for( auto i = libBounds.first; i != libBounds.second; ++i )
74  libList.push_back( i->get() );
75 
76  return libList;
77 }
78 
79 
80 wxString FP_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, int aUnit )
81 {
82  return GenerateFootprintInfo( m_libs, aLibId );
83 }
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.
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
Definition: string.cpp:415
FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
FP_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, LIB_TABLE *aLibs)
Constructor; takes a set of libraries to be included in the search.
const FPILIST & GetList() const
Was forced to add this by modview_frame.cpp.
wxString GenerateInfo(LIB_ID const &aLibId, int aUnit) override
wxString GenerateFootprintInfo(FP_LIB_TABLE *aFpLibTable, LIB_ID const &aLibId)
Return an HTML page describing a LIB_ID in a FP_LIB_TABLE.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
Abstract pattern-matching tool and implementations.
const wxString & GetDescr() const
Return the description of the library referenced by this row.
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
std::vector< LIB_TREE_ITEM * > getFootprints(const wxString &aLibName)
static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > Create(EDA_BASE_FRAME *aParent, LIB_TABLE *aLibs)
Factory function: create a model adapter in a reference-counting container.
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.
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
The base frame for deriving all KiCad main window classes.
std::vector< wxString > GetLogicalLibs()
Return the logical library names, all of them that are pertinent to a look up done on this LIB_TABLE.
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.