2017-03-23 00:59:25 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-01-19 01:17:40 +00:00
|
|
|
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-03-23 00:59:25 +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/>.
|
|
|
|
*/
|
|
|
|
|
2020-08-09 10:55:00 +00:00
|
|
|
#include <eda_draw_frame.h>
|
2017-03-23 00:59:25 +00:00
|
|
|
#include <kiway.h>
|
|
|
|
#include <kiway_player.h>
|
|
|
|
#include <project.h>
|
|
|
|
#include <widgets/footprint_choice.h>
|
|
|
|
#include <widgets/footprint_select_widget.h>
|
|
|
|
|
|
|
|
#include <wx/wupdlock.h>
|
2018-04-16 22:18:02 +00:00
|
|
|
#include <widgets/progress_reporter.h>
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
wxDEFINE_EVENT( EVT_FOOTPRINT_SELECTED, wxCommandEvent );
|
|
|
|
|
|
|
|
|
2020-08-09 10:55:00 +00:00
|
|
|
FOOTPRINT_SELECT_WIDGET::FOOTPRINT_SELECT_WIDGET( EDA_DRAW_FRAME* aFrame, wxWindow* aParent,
|
2020-12-21 22:02:13 +00:00
|
|
|
FOOTPRINT_LIST* aFpList, bool aUpdate,
|
|
|
|
int aMaxItems ) :
|
2020-08-09 10:55:00 +00:00
|
|
|
wxPanel( aParent ),
|
|
|
|
m_kiway( nullptr ),
|
|
|
|
m_update( aUpdate ),
|
|
|
|
m_max_items( aMaxItems ),
|
2021-01-04 12:18:00 +00:00
|
|
|
m_fp_list( aFpList )
|
2017-03-23 00:59:25 +00:00
|
|
|
{
|
2017-11-09 17:51:06 +00:00
|
|
|
m_zero_filter = true;
|
2017-03-23 00:59:25 +00:00
|
|
|
m_sizer = new wxBoxSizer( wxVERTICAL );
|
2018-06-08 23:50:06 +00:00
|
|
|
m_fp_sel_ctrl = new FOOTPRINT_CHOICE( this, wxID_ANY );
|
2018-07-25 23:16:34 +00:00
|
|
|
m_sizer->Add( m_fp_sel_ctrl, 1, wxEXPAND, 5 );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
SetSizer( m_sizer );
|
|
|
|
Layout();
|
|
|
|
m_sizer->Fit( this );
|
|
|
|
|
|
|
|
m_fp_sel_ctrl->Bind( wxEVT_COMBOBOX, &FOOTPRINT_SELECT_WIDGET::OnComboBox, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_SELECT_WIDGET::Load( KIWAY& aKiway, PROJECT& aProject )
|
|
|
|
{
|
|
|
|
m_kiway = &aKiway;
|
|
|
|
|
2017-06-30 20:59:56 +00:00
|
|
|
try
|
2017-03-23 00:59:25 +00:00
|
|
|
{
|
2018-04-04 00:19:20 +00:00
|
|
|
m_fp_list = FOOTPRINT_LIST::GetInstance( aKiway );
|
2020-12-21 22:02:13 +00:00
|
|
|
m_fp_filter.SetList( *m_fp_list );
|
2017-06-30 20:59:56 +00:00
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
// no footprint libraries available
|
|
|
|
}
|
2018-04-04 00:19:20 +00:00
|
|
|
|
|
|
|
if( m_update )
|
|
|
|
UpdateList();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-23 00:59:25 +00:00
|
|
|
void FOOTPRINT_SELECT_WIDGET::OnComboBox( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxCommandEvent evt( EVT_FOOTPRINT_SELECTED );
|
|
|
|
int sel = m_fp_sel_ctrl->GetSelection();
|
|
|
|
|
2021-01-19 01:17:40 +00:00
|
|
|
if( sel == wxNOT_FOUND )
|
|
|
|
return;
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2021-01-19 01:17:40 +00:00
|
|
|
wxStringClientData* clientdata =
|
|
|
|
static_cast<wxStringClientData*>( m_fp_sel_ctrl->GetClientObject( sel ) );
|
|
|
|
wxASSERT( clientdata );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
2021-01-19 01:17:40 +00:00
|
|
|
evt.SetString( clientdata->GetData() );
|
2017-03-23 00:59:25 +00:00
|
|
|
wxPostEvent( this, evt );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_SELECT_WIDGET::ClearFilters()
|
|
|
|
{
|
|
|
|
m_fp_filter.ClearFilters();
|
|
|
|
m_default_footprint.Clear();
|
|
|
|
m_zero_filter = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_SELECT_WIDGET::FilterByPinCount( int aPinCount )
|
|
|
|
{
|
|
|
|
m_fp_filter.FilterByPinCount( aPinCount );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-05 22:00:47 +00:00
|
|
|
void FOOTPRINT_SELECT_WIDGET::FilterByFootprintFilters( wxArrayString const& aFilters,
|
|
|
|
bool aZeroFilters )
|
2017-03-23 00:59:25 +00:00
|
|
|
{
|
2019-09-05 22:00:47 +00:00
|
|
|
m_zero_filter = ( aZeroFilters && aFilters.size() == 0 );
|
2017-03-23 00:59:25 +00:00
|
|
|
m_fp_filter.FilterByFootprintFilters( aFilters );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_SELECT_WIDGET::SetDefaultFootprint( wxString const& aFp )
|
|
|
|
{
|
|
|
|
m_default_footprint = aFp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FOOTPRINT_SELECT_WIDGET::UpdateList()
|
|
|
|
{
|
|
|
|
int n_items = 0;
|
|
|
|
|
2020-12-21 22:02:13 +00:00
|
|
|
if( !m_fp_list )
|
2017-03-23 00:59:25 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
wxWindowUpdateLocker lock( m_fp_sel_ctrl );
|
|
|
|
m_fp_sel_ctrl->Clear();
|
|
|
|
|
|
|
|
// Be careful adding items! "Default" must occupy POS_DEFAULT,
|
|
|
|
// "Other" must occupy POS_OTHER, and the separator must occupy POS_SEPARATOR.
|
|
|
|
|
|
|
|
m_fp_sel_ctrl->Append( m_default_footprint.IsEmpty() ?
|
|
|
|
_( "No default footprint" ) :
|
|
|
|
"[" + _( "Default" ) + "] " + m_default_footprint,
|
2021-01-19 01:17:40 +00:00
|
|
|
new wxStringClientData( m_default_footprint ) );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
if( !m_zero_filter )
|
|
|
|
{
|
|
|
|
for( auto& fpinfo : m_fp_filter )
|
|
|
|
{
|
2018-07-30 13:18:37 +00:00
|
|
|
wxString display_name( fpinfo.GetLibNickname() + ":" + fpinfo.GetFootprintName() );
|
2017-03-23 00:59:25 +00:00
|
|
|
|
|
|
|
m_fp_sel_ctrl->Append( display_name, new wxStringClientData( display_name ) );
|
|
|
|
++n_items;
|
|
|
|
|
|
|
|
if( n_items >= m_max_items )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectDefault();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_SELECT_WIDGET::SelectDefault()
|
|
|
|
{
|
2021-01-19 01:17:40 +00:00
|
|
|
m_fp_sel_ctrl->SetSelection( 0 );
|
2017-03-23 00:59:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool FOOTPRINT_SELECT_WIDGET::Enable( bool aEnable )
|
|
|
|
{
|
|
|
|
return m_fp_sel_ctrl->Enable( aEnable );
|
|
|
|
}
|