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 The 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 <pcb_base_frame.h>
22#include <core/kicad_algo.h>
24#include <pcbnew_settings.h>
26#include <wx/tokenzr.h>
27#include <string_utils.h>
29#include <footprint_info.h>
30#include <footprint_info_impl.h>
32
34
35wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
37{
38 auto* adapter = new FP_TREE_MODEL_ADAPTER( aParent, aLibs );
39 return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
40}
41
42
44 LIB_TREE_MODEL_ADAPTER( aParent, wxT( "pinned_footprint_libs" ),
45 aParent->GetViewerSettingsBase()->m_LibTree ),
46 m_libs( aLibs )
47{}
48
49
51{
53 PROJECT_FILE& project = aParent->Prj().GetProjectFile();
54
55 for( const wxString& libName : m_libs->GetLibraryNames() )
56 {
57 if( !m_libs->HasLibrary( libName, true ) )
58 continue;
59
60 bool pinned = alg::contains( cfg->m_Session.pinned_fp_libs, libName )
61 || alg::contains( project.m_PinnedFootprintLibs, libName );
62
63 DoAddLibrary( libName, *m_libs->GetLibraryDescription( libName ), getFootprints( libName ), pinned, true );
64 }
65
66 m_tree.AssignIntrinsicRanks( m_shownColumns );
67}
68
69
70std::vector<LIB_TREE_ITEM*> FP_TREE_MODEL_ADAPTER::getFootprints( const wxString& aLibName )
71{
72 std::vector<LIB_TREE_ITEM*> libList;
73
74 auto fullListStart = GFootprintList.GetList().begin();
75 auto fullListEnd = GFootprintList.GetList().end();
76 std::unique_ptr<FOOTPRINT_INFO> dummy = std::make_unique<FOOTPRINT_INFO_IMPL>( aLibName, wxEmptyString );
77
78 // List is sorted, so use a binary search to find the range of footnotes for our library
79 auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy,
80 []( const std::unique_ptr<FOOTPRINT_INFO>& a,
81 const std::unique_ptr<FOOTPRINT_INFO>& b )
82 {
83 return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), false ) < 0;
84 } );
85
86 for( auto i = libBounds.first; i != libBounds.second; ++i )
87 libList.push_back( i->get() );
88
89 return libList;
90}
91
92
93wxString FP_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, int aUnit )
94{
95 return GenerateFootprintInfo( m_libs, aLibId );
96}
The base frame for deriving all KiCad main window classes.
An interface to the global shared library manager that is schematic-specific and linked to one projec...
wxString GenerateInfo(LIB_ID const &aLibId, int aUnit) override
FOOTPRINT_LIBRARY_ADAPTER * m_libs
FP_TREE_MODEL_ADAPTER(PCB_BASE_FRAME *aParent, FOOTPRINT_LIBRARY_ADAPTER *aLibs)
Constructor; takes a set of libraries to be included in the search.
void AddLibraries(EDA_BASE_FRAME *aParent)
std::vector< LIB_TREE_ITEM * > getFootprints(const wxString &aLibName)
static wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > Create(PCB_BASE_FRAME *aParent, FOOTPRINT_LIBRARY_ADAPTER *aLibs)
Factory function: create a model adapter in a reference-counting container.
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
LIB_TREE_MODEL_ADAPTER(EDA_BASE_FRAME *aParent, const wxString &aPinnedKey, APP_SETTINGS_BASE::LIB_TREE &aSettingsStruct)
Create the adapter.
std::vector< wxString > m_shownColumns
LIB_TREE_NODE_LIBRARY & 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.
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:537
The backing store for a PROJECT, in JSON format.
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:204
FOOTPRINT_LIST_IMPL GFootprintList
The global footprint info table.
Definition cvpcb.cpp:138
wxString GenerateFootprintInfo(FOOTPRINT_LIBRARY_ADAPTER *aAdapter, LIB_ID const &aLibId)
Return an HTML page describing a LIB_ID in a footprint library.
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:946
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