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.h>
31
33
34wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
36{
37 auto* adapter = new FP_TREE_MODEL_ADAPTER( aParent, aLibs );
38 return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
39}
40
41
43 LIB_TREE_MODEL_ADAPTER( aParent, wxT( "pinned_footprint_libs" ),
44 aParent->GetViewerSettingsBase()->m_LibTree ),
45 m_libs( aLibs )
46{}
47
48
50{
52 PROJECT_FILE& project = aParent->Prj().GetProjectFile();
53 std::vector<wxString> libNames = m_libs->GetLibraryNames();
54
55 for( const wxString& libName : libNames )
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 std::vector<FOOTPRINT*> footprints = m_libs->GetFootprints( libName, true );
64 std::vector<LIB_TREE_ITEM*> treeItems;
65 treeItems.reserve( footprints.size() );
66
67 for( FOOTPRINT* fp : footprints )
68 treeItems.push_back( fp );
69
70 DoAddLibrary( libName, *m_libs->GetLibraryDescription( libName ), treeItems, pinned, true );
71 }
72
73 m_tree.AssignIntrinsicRanks( m_shownColumns );
74}
75
76
77wxString FP_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, int aUnit )
78{
79 return GenerateFootprintInfo( m_libs, aLibId );
80}
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)
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:535
The backing store for a PROJECT, in JSON format.
virtual PROJECT_FILE & GetProjectFile() const
Definition project.h:203
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.
see class PGM_BASE
std::vector< wxString > pinned_fp_libs