2018-07-29 00:11:39 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-07-22 08:26:49 +00:00
|
|
|
* Copyright (C) 2018-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-07-29 00:11:39 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-07-22 08:26:49 +00:00
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <eda_base_frame.h>
|
|
|
|
#include <core/kicad_algo.h>
|
|
|
|
#include <settings/common_settings.h>
|
|
|
|
#include <project/project_file.h>
|
2018-07-29 00:11:39 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#include <string_utils.h>
|
2018-07-29 00:11:39 +00:00
|
|
|
#include <eda_pattern_match.h>
|
|
|
|
#include <fp_lib_table.h>
|
|
|
|
#include <footprint_info.h>
|
2018-07-29 15:33:58 +00:00
|
|
|
#include <footprint_info_impl.h>
|
2018-07-29 00:11:39 +00:00
|
|
|
#include <generate_footprint_info.h>
|
2021-05-01 18:04:11 +00:00
|
|
|
#include <wx/settings.h>
|
2018-07-29 00:11:39 +00:00
|
|
|
|
|
|
|
#include "fp_tree_model_adapter.h"
|
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>
|
|
|
|
FP_TREE_MODEL_ADAPTER::Create( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs )
|
2018-07-29 00:11:39 +00:00
|
|
|
{
|
2020-11-07 14:31:50 +00:00
|
|
|
auto* adapter = new FP_TREE_MODEL_ADAPTER( aParent, aLibs );
|
|
|
|
return wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER>( adapter );
|
2018-07-29 00:11:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-14 14:22:21 +00:00
|
|
|
FP_TREE_MODEL_ADAPTER::FP_TREE_MODEL_ADAPTER( EDA_BASE_FRAME* aParent, LIB_TABLE* aLibs ) :
|
2022-02-04 22:44:59 +00:00
|
|
|
LIB_TREE_MODEL_ADAPTER( aParent, wxT( "pinned_footprint_libs" ) ),
|
2020-02-14 14:22:21 +00:00
|
|
|
m_libs( (FP_LIB_TABLE*) aLibs )
|
2018-07-29 00:11:39 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2022-07-22 08:26:49 +00:00
|
|
|
void FP_TREE_MODEL_ADAPTER::AddLibraries( EDA_BASE_FRAME* aParent )
|
2018-07-29 00:11:39 +00:00
|
|
|
{
|
2022-07-22 08:26:49 +00:00
|
|
|
COMMON_SETTINGS* cfg = Pgm().GetCommonSettings();
|
|
|
|
PROJECT_FILE& project = aParent->Prj().GetProjectFile();
|
|
|
|
|
2020-11-07 14:31:50 +00:00
|
|
|
for( const wxString& libName : m_libs->GetLogicalLibs() )
|
2018-07-29 15:33:58 +00:00
|
|
|
{
|
2021-01-10 22:55:30 +00:00
|
|
|
const FP_LIB_TABLE_ROW* library = m_libs->FindRow( libName, true );
|
2022-07-22 08:26:49 +00:00
|
|
|
bool pinned = alg::contains( cfg->m_Session.pinned_fp_libs, libName )
|
|
|
|
|| alg::contains( project.m_PinnedFootprintLibs, libName );
|
2018-07-29 15:33:58 +00:00
|
|
|
|
2022-07-22 08:26:49 +00:00
|
|
|
DoAddLibrary( libName, library->GetDescr(), getFootprints( libName ), pinned, true );
|
2018-07-29 15:33:58 +00:00
|
|
|
}
|
2018-08-05 11:56:02 +00:00
|
|
|
|
|
|
|
m_tree.AssignIntrinsicRanks();
|
2018-07-29 15:33:58 +00:00
|
|
|
}
|
|
|
|
|
2018-07-29 00:11:39 +00:00
|
|
|
|
2018-07-29 15:33:58 +00:00
|
|
|
std::vector<LIB_TREE_ITEM*> FP_TREE_MODEL_ADAPTER::getFootprints( const wxString& aLibName )
|
|
|
|
{
|
2018-08-03 21:09:48 +00:00
|
|
|
std::vector<LIB_TREE_ITEM*> libList;
|
2018-07-29 00:11:39 +00:00
|
|
|
|
2018-08-03 21:09:48 +00:00
|
|
|
auto fullListStart = GFootprintList.GetList().begin();
|
|
|
|
auto fullListEnd = GFootprintList.GetList().end();
|
2020-10-26 23:49:11 +00:00
|
|
|
std::unique_ptr<FOOTPRINT_INFO> dummy = std::make_unique<FOOTPRINT_INFO_IMPL>( aLibName, wxEmptyString );
|
2018-08-03 21:09:48 +00:00
|
|
|
|
|
|
|
// List is sorted, so use a binary search to find the range of footnotes for our library
|
|
|
|
auto libBounds = std::equal_range( fullListStart, fullListEnd, dummy,
|
2020-11-07 14:31:50 +00:00
|
|
|
[]( const std::unique_ptr<FOOTPRINT_INFO>& a,
|
|
|
|
const std::unique_ptr<FOOTPRINT_INFO>& b )
|
|
|
|
{
|
|
|
|
return StrNumCmp( a->GetLibNickname(), b->GetLibNickname(), false ) < 0;
|
|
|
|
} );
|
2018-08-03 21:09:48 +00:00
|
|
|
|
|
|
|
for( auto i = libBounds.first; i != libBounds.second; ++i )
|
|
|
|
libList.push_back( i->get() );
|
2018-07-29 00:11:39 +00:00
|
|
|
|
2018-08-03 21:09:48 +00:00
|
|
|
return libList;
|
2018-07-29 00:11:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString FP_TREE_MODEL_ADAPTER::GenerateInfo( LIB_ID const& aLibId, int aUnit )
|
|
|
|
{
|
|
|
|
return GenerateFootprintInfo( m_libs, aLibId );
|
|
|
|
}
|
2022-07-10 02:06:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
void FP_TREE_MODEL_ADAPTER::GetValue( wxVariant& aVariant, wxDataViewItem const& aItem,
|
|
|
|
unsigned int aCol ) const
|
|
|
|
{
|
|
|
|
if( IsFrozen() )
|
|
|
|
{
|
|
|
|
aVariant = wxEmptyString;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIB_TREE_NODE* node = ToNode( aItem );
|
|
|
|
wxASSERT( node );
|
|
|
|
|
|
|
|
if( aCol == 0 && node->m_Pinned )
|
|
|
|
aVariant = GetPinningSymbol() + node->m_Name;
|
|
|
|
else
|
|
|
|
aVariant = node->m_Name;
|
2022-07-28 13:51:13 +00:00
|
|
|
|
|
|
|
switch( aCol )
|
|
|
|
{
|
|
|
|
case NAME_COL:
|
|
|
|
if( node->m_Pinned )
|
|
|
|
aVariant = GetPinningSymbol() + UnescapeString( node->m_Name );
|
|
|
|
else
|
|
|
|
aVariant = UnescapeString( node->m_Name );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DESC_COL:
|
|
|
|
aVariant = node->m_Desc;
|
|
|
|
break;
|
|
|
|
}
|
2022-07-10 02:06:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|