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 <eda_pattern_match.h>
22 #include <fp_lib_table.h>
23 #include <footprint_info.h>
24 #include <footprint_info_impl.h>
26 
27 #include "fp_tree_model_adapter.h"
28 
30 {
31  return PTR( new FP_TREE_MODEL_ADAPTER( aLibs ) );
32 }
33 
34 
36  : m_libs( (FP_LIB_TABLE*) aLibs )
37 {}
38 
39 
41 {
42  for( const auto& libName : m_libs->GetLogicalLibs() )
43  {
44  const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName );
45 
46  DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), true );
47  }
48 
50 }
51 
52 
53 std::vector<LIB_TREE_ITEM*> FP_TREE_MODEL_ADAPTER::getFootprints( const wxString& aLibName )
54 {
55  std::vector<LIB_TREE_ITEM*> libList;
56 
57  auto fullListStart = GFootprintList.GetList().begin();
58  auto fullListEnd = GFootprintList.GetList().end();
59  std::unique_ptr<FOOTPRINT_INFO> dummy( new FOOTPRINT_INFO_IMPL( aLibName, wxEmptyString ) );
60 
61  // List is sorted, so use a binary search to find the range of footnotes for our library
62  auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy,
63  []( const std::unique_ptr<FOOTPRINT_INFO>& a, const std::unique_ptr<FOOTPRINT_INFO>& b )
64  {
65  return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), false ) < 0;
66  } );
67 
68  for( auto i = libBounds.first; i != libBounds.second; ++i )
69  libList.push_back( i->get() );
70 
71  return libList;
72 }
73 
74 
75 wxString FP_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, int aUnit )
76 {
77  return GenerateFootprintInfo( m_libs, aLibId );
78 }
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.
FP_TREE_MODEL_ADAPTER(LIB_TABLE *aLibs)
Constructor; takes a set of libraries to be included in the search.
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
Definition: string.cpp:354
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
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.
Definition: pcbnew.cpp:316
std::vector< LIB_TREE_ITEM * > getFootprints(const wxString &aLibName)
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName)
Function FindRow.
static PTR Create(LIB_TABLE *aLibs)
Factory function: create a model adapter in a reference-counting container.
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.
size_t i
Definition: json11.cpp:649
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > PTR
Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.
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.