KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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{
53 PROJECT_FILE& project = aParent->Prj().GetProjectFile();
54
55 for( const wxString& libName : m_libs->GetLogicalLibs() )
56 {
57 const FP_LIB_TABLE_ROW* library = nullptr;
58
59 try
60 {
61 library = m_libs->FindRow( libName, true );
62 }
63 catch( ... )
64 {
65 // Skip loading this library, if not exists/ not found
66 continue;
67 }
68 bool pinned = alg::contains( cfg->m_Session.pinned_fp_libs, libName )
69 || alg::contains( project.m_PinnedFootprintLibs, libName );
70
71 DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), pinned, true );
72 }
73
75}
76
77
78std::vector<LIB_TREE_ITEM*> FP_TREE_MODEL_ADAPTER::getFootprints( const wxString& aLibName )
79{
80 std::vector<LIB_TREE_ITEM*> libList;
81
82 auto fullListStart = GFootprintList.GetList().begin();
83 auto fullListEnd = GFootprintList.GetList().end();
84 std::unique_ptr<FOOTPRINT_INFO> dummy = std::make_unique<FOOTPRINT_INFO_IMPL>( aLibName, wxEmptyString );
85
86 // List is sorted, so use a binary search to find the range of footnotes for our library
87 auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy,
88 []( const std::unique_ptr<FOOTPRINT_INFO>& a,
89 const std::unique_ptr<FOOTPRINT_INFO>& b )
90 {
91 return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), false ) < 0;
92 } );
93
94 for( auto i = libBounds.first; i != libBounds.second; ++i )
95 libList.push_back( i->get() );
96
97 return libList;
98}
99
100
101wxString FP_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, int aUnit )
102{
103 return GenerateFootprintInfo( m_libs, aLibId );
104}
The base frame for deriving all KiCad main window classes.
const std::vector< std::unique_ptr< FOOTPRINT_INFO > > & 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 t...
Definition: fp_lib_table.h:42
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.
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition: pgm_base.cpp:679
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:72
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:200
Base window classes and related definitions.
Abstract pattern-matching tool and implementations.
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition: cvpcb.cpp:156
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:100
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1060
see class PGM_BASE
std::vector< FAB_LAYER_COLOR > dummy
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
std::vector< wxString > pinned_fp_libs