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 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 <wx/progdlg.h>
22 
23 #include <eda_pattern_match.h>
24 #include <fp_lib_table.h>
25 #include <footprint_info.h>
26 #include <footprint_info_impl.h>
28 
29 #include "fp_tree_model_adapter.h"
30 
32 {
33  return PTR( new FP_TREE_MODEL_ADAPTER( aLibs ) );
34 }
35 
36 
38  : m_libs( (FP_LIB_TABLE*) aLibs )
39 {}
40 
41 
43 {}
44 
45 
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 }
57 
58 
59 std::vector<LIB_TREE_ITEM*> FP_TREE_MODEL_ADAPTER::getFootprints( const wxString& aLibName )
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 }
79 
80 
81 wxString FP_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, int aUnit )
82 {
83  return GenerateFootprintInfo( m_libs, aLibId );
84 }
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.
const FPILIST & GetList() const
Was forced to add this by modview_frame.cpp.
Class FP_LIB_TABLE_ROW.
Definition: fp_lib_table.h:42
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.
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: pcbnew.cpp:338
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.
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 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
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > PTR
Reference-counting container for a pointer to CMP_TREE_MODEL_ADAPTER_BASE.
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
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.