2017-03-10 19:11:41 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-08-02 17:00:41 +00:00
|
|
|
* Copyright (C) 2017-2018 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>
|
|
|
|
#include <wx/stattext.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <kiway.h>
|
|
|
|
|
|
|
|
|
|
|
|
FOOTPRINT_PREVIEW_WIDGET::FOOTPRINT_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway ):
|
|
|
|
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
2018-08-05 13:22:29 +00:00
|
|
|
wxFULL_REPAINT_ON_RESIZE | wxTAB_TRAVERSAL ),
|
2017-03-10 19:11:41 +00:00
|
|
|
m_prev_panel( nullptr ),
|
2020-08-10 01:29:15 +00:00
|
|
|
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-08-10 01:29:15 +00:00
|
|
|
// Give the status panel the same color scheme as the canvas so it isn't jarring when switched to
|
|
|
|
m_statusPanel->SetBackgroundColour( m_prev_panel->GetBackgroundColor().ToColour() );
|
|
|
|
m_statusPanel->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 );
|
|
|
|
|
|
|
|
// Hide the status panel to start
|
|
|
|
m_statusPanel->Hide();
|
2017-03-10 19:11:41 +00:00
|
|
|
|
|
|
|
m_prev_panel->SetStatusHandler( [this]( FOOTPRINT_STATUS s ){ this->OnStatusChange( s ); } );
|
|
|
|
|
2020-08-10 01:29:15 +00:00
|
|
|
SetSizer( m_outerSizer );
|
|
|
|
Layout();
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_PREVIEW_WIDGET::CacheFootprint( const LIB_ID& aFPID )
|
|
|
|
{
|
|
|
|
if( m_prev_panel )
|
|
|
|
(void) m_prev_panel->CacheFootprint( aFPID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_PREVIEW_WIDGET::DisplayFootprint( const LIB_ID& aFPID )
|
|
|
|
{
|
|
|
|
if( m_prev_panel )
|
|
|
|
(void) m_prev_panel->DisplayFootprint( aFPID );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FOOTPRINT_PREVIEW_WIDGET::OnStatusChange( FOOTPRINT_STATUS aStatus )
|
|
|
|
{
|
|
|
|
switch( aStatus )
|
|
|
|
{
|
2020-11-07 21:40:56 +00:00
|
|
|
case FPS_NOT_FOUND: SetStatusText( _( "Footprint not found" ) ); break;
|
|
|
|
case FPS_LOADING: SetStatusText( _( "Loading..." ) ); break;
|
|
|
|
case FPS_READY: ClearStatus(); break;
|
2017-03-10 19:11:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2017-03-10 19:11:41 +00:00
|
|
|
KIFACE* kiface = aKiway.KiFACE( KIWAY::FACE_PCB );
|
|
|
|
|
2019-09-05 22:00:47 +00:00
|
|
|
auto window = kiface->CreateWindow( 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;
|
|
|
|
}
|