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-2022 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 <pgm_base.h>
21#include <eda_base_frame.h>
22#include <core/kicad_algo.h>
25#include <wx/tokenzr.h>
26#include <string_utils.h>
27#include <eda_pattern_match.h>
28#include <fp_lib_table.h>
29#include <footprint_info.h>
30#include <footprint_info_impl.h>
32#include <wx/settings.h>
33
35
36wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
38{
39 auto* adapter = new FP_TREE_MODEL_ADAPTER( aParent, aLibs );
40 return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
41}
42
43
45 LIB_TREE_MODEL_ADAPTER( aParent, wxT( "pinned_footprint_libs" ) ),
46 m_libs( (FP_LIB_TABLE*) aLibs )
47{}
48
49
51{
52 COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
53 PROJECT_FILE& project = aParent->Prj().GetProjectFile();
54
55 for( const wxString& libName : m_libs->GetLogicalLibs() )
56 {
57 const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName, true );
58 bool pinned = alg::contains( cfg->m_Session.pinned_fp_libs, libName )
59 || alg::contains( project.m_PinnedFootprintLibs, libName );
60
61 DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), pinned, true );
62 }
63
65}
66
67
68std::vector<LIB_TREE_ITEM*> FP_TREE_MODEL_ADAPTER::getFootprints( const wxString& aLibName )
69{
70 std::vector<LIB_TREE_ITEM*> libList;
71
72 auto fullListStart = GFootprintList.GetList().begin();
73 auto fullListEnd = GFootprintList.GetList().end();
74 std::unique_ptr<FOOTPRINT_INFO> dummy = std::make_unique<FOOTPRINT_INFO_IMPL>( aLibName, wxEmptyString );
75
76 // List is sorted, so use a binary search to find the range of footnotes for our library
77 auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy,
78 []( const std::unique_ptr<FOOTPRINT_INFO>& a,
79 const std::unique_ptr<FOOTPRINT_INFO>& b )
80 {
81 return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), false ) < 0;
82 } );
83
84 for( auto i = libBounds.first; i != libBounds.second; ++i )
85 libList.push_back( i->get() );
86
87 return libList;
88}
89
90
91wxString FP_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, int aUnit )
92{
93 return GenerateFootprintInfo( m_libs, aLibId );
94}
The base frame for deriving all KiCad main window classes.
const FPILIST & GetList() const
Was forced to add this by modview_frame.cpp.
Hold a record identifying a library accessed by the appropriate footprint library PLUGIN object in th...
Definition: fp_lib_table.h:41
const FP_LIB_TABLE_ROW * FindRow(const wxString &aNickName, bool aCheckIfEnabled=false)
Return an FP_LIB_TABLE_ROW if aNickName is found in this table or in any chained fall back table frag...
FP_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, LIB_TABLE *aLibs)
Constructor; takes a set of libraries to be included in the search.
wxString GenerateInfo(LIB_ID const &aLibId, int aUnit) override
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.
void AddLibraries(EDA_BASE_FRAME *aParent)
std::vector< LIB_TREE_ITEM * > getFootprints(const wxString &aLibName)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
Manage LIB_TABLE_ROW records (rows), and can be searched based on library nickname.
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 DoAddLibrary(const wxString &aNodeName, const wxString &aDesc, const std::vector< LIB_TREE_ITEM * > &aItemList, bool pinned, bool presorted)
Add the given list of symbols by alias.
void AssignIntrinsicRanks(bool presorted=false)
Store intrinsic ranks on all children of this node.
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:65
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:148
Base window classes and related definitions.
Abstract pattern-matching tool and implementations.
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: cvpcb.cpp:140
wxString GenerateFootprintInfo(FP_LIB_TABLE *aFpLibTable, LIB_ID const &aLibId)
Return an HTML page describing a LIB_ID in a FP_LIB_TABLE.
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:99
see class PGM_BASE
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
std::vector< wxString > pinned_fp_libs