2017-03-10 19:11:41 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-08-03 16:53:30 +00:00
|
|
|
* Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-03-10 19:11:41 +00:00
|
|
|
* Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <widgets/footprint_preview_widget.h>
|
2021-02-25 20:13:42 +00:00
|
|
|
#include <lib_id.h>
|
2017-03-10 19:11:41 +00:00
|
|
|
#include <wx/stattext.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <kiway.h>
|
|
|
|
|
|
|
|
|
2020-12-21 22:02:13 +00:00
|
|
|
FOOTPRINT_PREVIEW_WIDGET::FOOTPRINT_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway ) :
|
|
|
|
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxFULL_REPAINT_ON_RESIZE | wxTAB_TRAVERSAL ),
|
|
|
|
m_prev_panel( nullptr ),
|
|
|
|
m_status( nullptr ),
|
|
|
|
m_statusPanel( nullptr ),
|
|
|
|
m_statusSizer( nullptr ),
|
|
|
|
m_outerSizer( nullptr )
|
2017-03-10 19:11:41 +00:00
|
|
|
{
|
|
|
|
m_prev_panel = FOOTPRINT_PREVIEW_PANEL_BASE::Create( this, aKiway );
|
|
|
|
|
|
|
|
if( !m_prev_panel )
|
|
|
|
return;
|
|
|
|
|
2020-08-10 01:29:15 +00:00
|
|
|
m_statusPanel = new wxPanel( this );
|
|
|
|
m_status = new wxStaticText( m_statusPanel, wxID_ANY, wxEmptyString );
|
|
|
|
m_statusSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
m_statusSizer->Add( 0, 0, 1 ); // add a spacer
|
|
|
|
m_statusSizer->Add( m_status, 0, wxALIGN_CENTER );
|
|
|
|
m_statusSizer->Add( 0, 0, 1 ); // add a spacer
|
|
|
|
m_statusPanel->SetSizer( m_statusSizer );
|
2017-03-10 19:11:41 +00:00
|
|
|
|
2020-12-21 22:02:13 +00:00
|
|
|
// Give the status panel the same color scheme as the canvas so it isn't jarring when
|
|
|
|
// switched to
|
2020-08-10 01:29:15 +00:00
|
|
|
m_statusPanel->SetBackgroundColour( m_prev_panel->GetBackgroundColor().ToColour() );
|
|
|
|
m_statusPanel->SetForegroundColour( m_prev_panel->GetForegroundColor().ToColour() );
|
2020-12-21 22:02:13 +00:00
|
|
|
m_status->SetForegroundColour( m_prev_panel->GetForegroundColor().ToColour() );
|
2020-12-14 14:48:26 +00:00
|
|
|
|
2020-12-21 22:02:13 +00:00
|
|
|
// Set our background so wx doesn't render a normal control background momentarily when
|
|
|
|
// rapidly navigating with arrow keys
|
2020-12-14 14:48:26 +00:00
|
|
|
SetBackgroundColour( m_prev_panel->GetBackgroundColor().ToColour() );
|
|
|
|
SetForegroundColour( m_prev_panel->GetForegroundColor().ToColour() );
|
2017-03-10 19:11:41 +00:00
|
|
|
|
2020-08-10 01:29:15 +00:00
|
|
|
m_outerSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
m_outerSizer->Add( m_prev_panel->GetWindow(), 1, wxALL | wxEXPAND, 0 );
|
|
|
|
m_outerSizer->Add( m_statusPanel, 1, wxALL | wxEXPAND, 0 );
|
|
|
|
|
|
|
|
SetSizer( m_outerSizer );
|
2020-12-21 22:02:13 +00:00
|
|
|
|
|
|
|
SetStatusText( wxEmptyString );
|
2017-03-10 19:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_PREVIEW_WIDGET::SetStatusText( wxString const& aText )
|
|
|
|
{
|
2020-08-10 01:29:15 +00:00
|
|
|
m_status->SetLabel( aText );
|
|
|
|
m_statusPanel->Show();
|
2017-03-10 19:11:41 +00:00
|
|
|
m_prev_panel->GetWindow()->Hide();
|
|
|
|
Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_PREVIEW_WIDGET::ClearStatus()
|
|
|
|
{
|
2020-08-10 01:29:15 +00:00
|
|
|
m_status->SetLabel( wxEmptyString );
|
|
|
|
m_statusPanel->Hide();
|
2017-03-10 19:11:41 +00:00
|
|
|
m_prev_panel->GetWindow()->Show();
|
|
|
|
Layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-02 22:11:44 +00:00
|
|
|
void FOOTPRINT_PREVIEW_WIDGET::SetUserUnits( EDA_UNITS aUnits )
|
|
|
|
{
|
|
|
|
m_prev_panel->SetUserUnits( aUnits );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-10 19:11:41 +00:00
|
|
|
void FOOTPRINT_PREVIEW_WIDGET::DisplayFootprint( const LIB_ID& aFPID )
|
|
|
|
{
|
2021-02-25 20:13:42 +00:00
|
|
|
if( !m_prev_panel || m_libid == aFPID )
|
2020-12-21 22:02:13 +00:00
|
|
|
return;
|
2017-03-10 19:11:41 +00:00
|
|
|
|
2020-12-21 22:02:13 +00:00
|
|
|
wxBusyCursor busy;
|
2017-03-10 19:11:41 +00:00
|
|
|
|
2020-12-21 22:02:13 +00:00
|
|
|
if( m_prev_panel->DisplayFootprint( aFPID ) )
|
2021-02-25 20:13:42 +00:00
|
|
|
{
|
2020-12-21 22:02:13 +00:00
|
|
|
ClearStatus();
|
2021-02-25 20:13:42 +00:00
|
|
|
m_libid = aFPID;
|
|
|
|
}
|
2020-12-21 22:02:13 +00:00
|
|
|
else
|
2021-02-25 20:13:42 +00:00
|
|
|
{
|
2020-12-21 22:02:13 +00:00
|
|
|
SetStatusText( _( "Footprint not found." ) );
|
2021-02-25 20:13:42 +00:00
|
|
|
m_libid.clear();
|
|
|
|
}
|
2017-03-10 19:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-06 18:37:43 +00:00
|
|
|
FOOTPRINT_PREVIEW_PANEL_BASE* FOOTPRINT_PREVIEW_PANEL_BASE::Create( wxWindow* aParent,
|
|
|
|
KIWAY& aKiway )
|
2017-03-10 19:11:41 +00:00
|
|
|
{
|
|
|
|
FOOTPRINT_PREVIEW_PANEL_BASE* panel = nullptr;
|
|
|
|
|
2020-08-06 18:37:43 +00:00
|
|
|
try
|
|
|
|
{
|
2021-08-03 16:53:30 +00:00
|
|
|
KIFACE* kiface = aKiway.KiFACE( KIWAY::FACE_PCB );
|
2022-11-08 09:14:40 +00:00
|
|
|
wxWindow* window = kiface->CreateKiWindow( aParent, FRAME_FOOTPRINT_PREVIEW, &aKiway );
|
2017-03-10 19:11:41 +00:00
|
|
|
|
|
|
|
panel = dynamic_cast<FOOTPRINT_PREVIEW_PANEL_BASE*>( window );
|
|
|
|
|
|
|
|
if( window && !panel )
|
|
|
|
delete window;
|
2020-08-06 18:37:43 +00:00
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
}
|
2017-03-10 19:11:41 +00:00
|
|
|
|
|
|
|
return panel;
|
|
|
|
}
|