KiCad PCB EDA Suite
FOOTPRINT_PREVIEW_WIDGET Class Reference

#include <footprint_preview_widget.h>

Inheritance diagram for FOOTPRINT_PREVIEW_WIDGET:

Public Member Functions

 FOOTPRINT_PREVIEW_WIDGET (wxWindow *aParent, KIWAY &aKiway)
 Construct a footprint preview widget. More...
 
bool IsInitialized () const
 Return whether the widget initialized properly. More...
 
void SetStatusText (wxString const &aText)
 Set the contents of the status label and display it. More...
 
void ClearStatus ()
 Clear the contents of the status label and hide it. More...
 
void CacheFootprint (const LIB_ID &aFPID)
 Preload a footprint into the cache. More...
 
void DisplayFootprint (const LIB_ID &aFPID)
 Set the currently displayed footprint. More...
 

Private Member Functions

void OnStatusChange (FOOTPRINT_STATUS aStatus)
 Callback from the FOOTPRINT_PREVIEW_PANEL. More...
 

Private Attributes

FOOTPRINT_PREVIEW_PANEL_BASEm_prev_panel
 
wxStaticText * m_status
 
wxPanel * m_statusPanel
 
wxSizer * m_statusSizer
 
wxSizer * m_outerSizer
 

Detailed Description

Definition at line 45 of file footprint_preview_widget.h.

Constructor & Destructor Documentation

◆ FOOTPRINT_PREVIEW_WIDGET()

FOOTPRINT_PREVIEW_WIDGET::FOOTPRINT_PREVIEW_WIDGET ( wxWindow *  aParent,
KIWAY aKiway 
)

Construct a footprint preview widget.

Parameters
aParent- parent window
aKiway- an active Kiway instance

Definition at line 27 of file footprint_preview_widget.cpp.

27  :
28  wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
29  wxFULL_REPAINT_ON_RESIZE | wxTAB_TRAVERSAL ),
30  m_prev_panel( nullptr ),
31  m_status( nullptr ),
32  m_statusPanel( nullptr ),
33  m_statusSizer( nullptr ),
34  m_outerSizer( nullptr )
35 {
37 
38  if( !m_prev_panel )
39  return;
40 
41  m_statusPanel = new wxPanel( this );
42  m_status = new wxStaticText( m_statusPanel, wxID_ANY, wxEmptyString );
43  m_statusSizer = new wxBoxSizer( wxVERTICAL );
44  m_statusSizer->Add( 0, 0, 1 ); // add a spacer
45  m_statusSizer->Add( m_status, 0, wxALIGN_CENTER );
46  m_statusSizer->Add( 0, 0, 1 ); // add a spacer
47  m_statusPanel->SetSizer( m_statusSizer );
48 
49  // Give the status panel the same color scheme as the canvas so it isn't jarring when switched to
50  m_statusPanel->SetBackgroundColour( m_prev_panel->GetBackgroundColor().ToColour() );
51  m_statusPanel->SetForegroundColour( m_prev_panel->GetForegroundColor().ToColour() );
52 
53  m_outerSizer = new wxBoxSizer( wxVERTICAL );
54  m_outerSizer->Add( m_prev_panel->GetWindow(), 1, wxALL | wxEXPAND, 0 );
55  m_outerSizer->Add( m_statusPanel, 1, wxALL | wxEXPAND, 0 );
56 
57  // Hide the status panel to start
58  m_statusPanel->Hide();
59 
60  m_prev_panel->SetStatusHandler( [this]( FOOTPRINT_STATUS s ){ this->OnStatusChange( s ); } );
61 
62  SetSizer( m_outerSizer );
63  Layout();
64 }
void OnStatusChange(FOOTPRINT_STATUS aStatus)
Callback from the FOOTPRINT_PREVIEW_PANEL.
virtual const KIGFX::COLOR4D & GetForegroundColor()=0
FOOTPRINT_PREVIEW_PANEL_BASE * m_prev_panel
virtual wxWindow * GetWindow()=0
Get the underlying wxWindow.
virtual const KIGFX::COLOR4D & GetBackgroundColor()=0
Get the colors to use in a preview widget to match the preview panel.
static FOOTPRINT_PREVIEW_PANEL_BASE * Create(wxWindow *aParent, KIWAY &aKiway)
Return a footprint preview panel instance via Kiface.
virtual void SetStatusHandler(FOOTPRINT_STATUS_HANDLER aHandler)=0
Set the callback to receive status updates.

References FOOTPRINT_PREVIEW_PANEL_BASE::Create(), FOOTPRINT_PREVIEW_PANEL_BASE::GetBackgroundColor(), FOOTPRINT_PREVIEW_PANEL_BASE::GetForegroundColor(), FOOTPRINT_PREVIEW_PANEL_BASE::GetWindow(), m_outerSizer, m_prev_panel, m_status, m_statusPanel, m_statusSizer, OnStatusChange(), and FOOTPRINT_PREVIEW_PANEL_BASE::SetStatusHandler().

Member Function Documentation

◆ CacheFootprint()

void FOOTPRINT_PREVIEW_WIDGET::CacheFootprint ( const LIB_ID aFPID)

Preload a footprint into the cache.

This must be called prior to DisplayFootprint, and may be called early.

Definition at line 85 of file footprint_preview_widget.cpp.

86 {
87  if( m_prev_panel )
88  (void) m_prev_panel->CacheFootprint( aFPID );
89 }
FOOTPRINT_PREVIEW_PANEL_BASE * m_prev_panel
virtual void CacheFootprint(LIB_ID const &aFPID)=0
Preload a footprint into the cache.

References FOOTPRINT_PREVIEW_PANEL_BASE::CacheFootprint(), and m_prev_panel.

Referenced by DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected(), and DIALOG_CHOOSE_COMPONENT::ShowFootprint().

◆ ClearStatus()

void FOOTPRINT_PREVIEW_WIDGET::ClearStatus ( )

Clear the contents of the status label and hide it.

Definition at line 76 of file footprint_preview_widget.cpp.

77 {
78  m_status->SetLabel( wxEmptyString );
79  m_statusPanel->Hide();
80  m_prev_panel->GetWindow()->Show();
81  Layout();
82 }
FOOTPRINT_PREVIEW_PANEL_BASE * m_prev_panel
virtual wxWindow * GetWindow()=0
Get the underlying wxWindow.

References FOOTPRINT_PREVIEW_PANEL_BASE::GetWindow(), m_prev_panel, m_status, and m_statusPanel.

Referenced by DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected(), OnStatusChange(), and DIALOG_CHOOSE_COMPONENT::ShowFootprint().

◆ DisplayFootprint()

void FOOTPRINT_PREVIEW_WIDGET::DisplayFootprint ( const LIB_ID aFPID)

Set the currently displayed footprint.

Any footprint passed in here must have been passed to CacheFootprint before.

Definition at line 92 of file footprint_preview_widget.cpp.

93 {
94  if( m_prev_panel )
95  (void) m_prev_panel->DisplayFootprint( aFPID );
96 }
FOOTPRINT_PREVIEW_PANEL_BASE * m_prev_panel
virtual void DisplayFootprint(LIB_ID const &aFPID)=0
Set the currently displayed footprint.

References FOOTPRINT_PREVIEW_PANEL_BASE::DisplayFootprint(), and m_prev_panel.

Referenced by DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected(), and DIALOG_CHOOSE_COMPONENT::ShowFootprint().

◆ IsInitialized()

bool FOOTPRINT_PREVIEW_WIDGET::IsInitialized ( ) const
inline

Return whether the widget initialized properly.

This could return false if Kiway is not available. If this returns false, no other methods should be called.

Definition at line 62 of file footprint_preview_widget.h.

62 { return !! m_prev_panel; }
FOOTPRINT_PREVIEW_PANEL_BASE * m_prev_panel

References m_prev_panel.

Referenced by DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected(), DIALOG_CHOOSE_COMPONENT::OnComponentPreselected(), DIALOG_CHOOSE_COMPONENT::OnInitDialog(), DIALOG_CHOOSE_COMPONENT::ShowFootprint(), and DIALOG_CHOOSE_COMPONENT::ShowFootprintFor().

◆ OnStatusChange()

void FOOTPRINT_PREVIEW_WIDGET::OnStatusChange ( FOOTPRINT_STATUS  aStatus)
private

Callback from the FOOTPRINT_PREVIEW_PANEL.

Definition at line 99 of file footprint_preview_widget.cpp.

100 {
101  switch( aStatus )
102  {
103  case FPS_NOT_FOUND:
104  SetStatusText( _( "Footprint not found" ) );
105  break;
106 
107  case FPS_LOADING:
108  SetStatusText( _( "Loading..." ) );
109  break;
110 
111  case FPS_READY:
112  ClearStatus();
113  }
114 
115  Refresh();
116 }
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
void ClearStatus()
Clear the contents of the status label and hide it.
void SetStatusText(wxString const &aText)
Set the contents of the status label and display it.
#define _(s)
Definition: 3d_actions.cpp:33

References _, ClearStatus(), FPS_LOADING, FPS_NOT_FOUND, FPS_READY, Refresh(), and SetStatusText().

Referenced by FOOTPRINT_PREVIEW_WIDGET().

◆ SetStatusText()

void FOOTPRINT_PREVIEW_WIDGET::SetStatusText ( wxString const &  aText)

Set the contents of the status label and display it.

Definition at line 67 of file footprint_preview_widget.cpp.

68 {
69  m_status->SetLabel( aText );
70  m_statusPanel->Show();
71  m_prev_panel->GetWindow()->Hide();
72  Layout();
73 }
FOOTPRINT_PREVIEW_PANEL_BASE * m_prev_panel
virtual wxWindow * GetWindow()=0
Get the underlying wxWindow.

References FOOTPRINT_PREVIEW_PANEL_BASE::GetWindow(), m_prev_panel, m_status, and m_statusPanel.

Referenced by DIALOG_CHOOSE_FOOTPRINT::OnComponentPreselected(), DIALOG_CHOOSE_COMPONENT::OnComponentPreselected(), DIALOG_CHOOSE_COMPONENT::OnInitDialog(), OnStatusChange(), and DIALOG_CHOOSE_COMPONENT::ShowFootprint().

Member Data Documentation

◆ m_outerSizer

wxSizer* FOOTPRINT_PREVIEW_WIDGET::m_outerSizer
private

Definition at line 98 of file footprint_preview_widget.h.

Referenced by FOOTPRINT_PREVIEW_WIDGET().

◆ m_prev_panel

FOOTPRINT_PREVIEW_PANEL_BASE* FOOTPRINT_PREVIEW_WIDGET::m_prev_panel
private

◆ m_status

wxStaticText* FOOTPRINT_PREVIEW_WIDGET::m_status
private

Definition at line 95 of file footprint_preview_widget.h.

Referenced by ClearStatus(), FOOTPRINT_PREVIEW_WIDGET(), and SetStatusText().

◆ m_statusPanel

wxPanel* FOOTPRINT_PREVIEW_WIDGET::m_statusPanel
private

Definition at line 96 of file footprint_preview_widget.h.

Referenced by ClearStatus(), FOOTPRINT_PREVIEW_WIDGET(), and SetStatusText().

◆ m_statusSizer

wxSizer* FOOTPRINT_PREVIEW_WIDGET::m_statusSizer
private

Definition at line 97 of file footprint_preview_widget.h.

Referenced by FOOTPRINT_PREVIEW_WIDGET().


The documentation for this class was generated from the following files: