KiCad PCB EDA Suite
footprint_preview_widget.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
5  * Copyright (C) 2017 Chris Pavlina <pavlina.chris@gmail.com>
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
22 #include <wx/stattext.h>
23 #include <wx/sizer.h>
24 #include <kiway.h>
25 
26 
28  wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
29  wxFULL_REPAINT_ON_RESIZE | wxSUNKEN_BORDER | wxTAB_TRAVERSAL ),
30  m_prev_panel( nullptr ),
31  m_status_label( nullptr ),
32  m_sizer( nullptr )
33 {
35 
36  if( !m_prev_panel )
37  return;
38 
39  SetBackgroundColour( *wxBLACK );
40  SetForegroundColour( *wxWHITE );
41 
42  m_status_label = new wxStaticText( this, -1, wxEmptyString );
43  m_sizer = new wxBoxSizer( wxVERTICAL );
44  m_sizer->Add( 0, 0, 1 );
45  m_sizer->Add( m_status_label, 0, wxALL | wxALIGN_CENTER, 0 );
46  m_sizer->Add( 0, 0, 1 );
47 
48  auto outer_sizer = new wxBoxSizer( wxVERTICAL );
49  outer_sizer->Add( m_prev_panel->GetWindow(), 1, wxALL | wxEXPAND, 0 );
50  outer_sizer->Add( m_sizer, 1, wxALL | wxALIGN_CENTER, 0 );
51 
52  m_sizer->ShowItems( false );
53  m_prev_panel->SetStatusHandler( [this]( FOOTPRINT_STATUS s ){ this->OnStatusChange( s ); } );
54 
55  SetSizer( outer_sizer );
56 }
57 
58 
59 void FOOTPRINT_PREVIEW_WIDGET::SetStatusText( wxString const& aText )
60 {
61  m_status_label->SetLabel( aText );
62  m_sizer->ShowItems( true );
63  m_prev_panel->GetWindow()->Hide();
64  Layout();
65 }
66 
67 
69 {
70  m_status_label->SetLabel( wxEmptyString );
71  m_prev_panel->GetWindow()->Show();
72  m_sizer->ShowItems( false );
73  Layout();
74 }
75 
76 
78 {
79  if( m_prev_panel )
80  (void) m_prev_panel->CacheFootprint( aFPID );
81 }
82 
83 
85 {
86  if( m_prev_panel )
87  (void) m_prev_panel->DisplayFootprint( aFPID );
88 }
89 
90 
92 {
93  switch( aStatus )
94  {
95  case FPS_NOT_FOUND:
96  SetStatusText( _( "Footprint not found" ) );
97  break;
98 
99  case FPS_LOADING:
100  SetStatusText( _( "Loading..." ) );
101  break;
102 
103  case FPS_READY:
104  ClearStatus();
105  }
106 
107  Refresh();
108 }
109 
110 
112  wxWindow* aParent, KIWAY& aKiway )
113 {
114  FOOTPRINT_PREVIEW_PANEL_BASE* panel = nullptr;
115 
116  try {
117  KIFACE* kiface = aKiway.KiFACE( KIWAY::FACE_PCB );
118 
119  auto window = kiface->CreateWindow( aParent, FRAME_PCB_FOOTPRINT_PREVIEW, &aKiway );
120 
121  panel = dynamic_cast<FOOTPRINT_PREVIEW_PANEL_BASE*>( window );
122 
123  if( window && !panel )
124  delete window;
125  } catch( ... )
126  {}
127 
128  return panel;
129 }
void OnStatusChange(FOOTPRINT_STATUS aStatus)
Callback from the FOOTPRINT_PREVIEW_PANEL.
Class LIB_ID.
Definition: lib_id.h:56
FOOTPRINT_PREVIEW_PANEL_BASE * m_prev_panel
virtual void CacheFootprint(LIB_ID const &aFPID)=0
Preload a footprint into the cache.
virtual void DisplayFootprint(LIB_ID const &aFPID)=0
Set the currently displayed footprint.
VTBL_ENTRY wxWindow * CreateWindow(wxWindow *aParent, int aClassId, KIWAY *aKIWAY, int aCtlBits=0)=0
Function CreateWindow creates a wxWindow for the current project.
void Refresh()
void ClearStatus()
Clear the contents of the status label and hide it.
virtual wxWindow * GetWindow()=0
Get the underlying wxWindow.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
pcbnew DSO
Definition: kiway.h:266
void SetStatusText(wxString const &aText)
Set the contents of the status label and display it.
VTBL_ENTRY KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Function KiFACE returns the KIFACE* given a FACE_T.
Definition: kiway.cpp:150
Base class for the actual viewer panel.
static FOOTPRINT_PREVIEW_PANEL_BASE * Create(wxWindow *aParent, KIWAY &aKiway)
Return a footprint preview panel instance via Kiface.
void CacheFootprint(const LIB_ID &aFPID)
Preload a footprint into the cache.
void DisplayFootprint(const LIB_ID &aFPID)
Set the currently displayed footprint.
Class KIFACE is used by a participant in the KIWAY alchemy.
Definition: kiway.h:150
FOOTPRINT_PREVIEW_WIDGET(wxWindow *aParent, KIWAY &aKiway)
Construct a footprint preview widget.
return & kiface
Definition: pcbnew.cpp:207
virtual void SetStatusHandler(FOOTPRINT_STATUS_HANDLER aHandler)=0
Set the callback to receive status updates.