KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 KiCad Developers, see AUTHORS.txt for contributors.
5 * Copyright (C) 2017 Chris Pavlina <[email protected]>
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 <lib_id.h>
23#include <wx/stattext.h>
24#include <wx/sizer.h>
25#include <kiway.h>
26
27
29 wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
30 wxFULL_REPAINT_ON_RESIZE | wxTAB_TRAVERSAL ),
31 m_prev_panel( nullptr ),
32 m_status( nullptr ),
33 m_statusPanel( nullptr ),
34 m_statusSizer( nullptr ),
35 m_outerSizer( nullptr )
36{
38
39 m_statusPanel = new wxPanel( this );
40 m_status = new wxStaticText( m_statusPanel, wxID_ANY, wxEmptyString );
41 m_statusSizer = new wxBoxSizer( wxVERTICAL );
42 m_statusSizer->Add( 0, 0, 1 ); // add a spacer
43 m_statusSizer->Add( m_status, 0, wxALIGN_CENTER );
44 m_statusSizer->Add( 0, 0, 1 ); // add a spacer
45 m_statusPanel->SetSizer( m_statusSizer );
46
47 if( m_prev_panel )
48 {
49 // Give the status panel the same color scheme as the canvas so it isn't jarring when
50 // switched to
51 m_statusPanel->SetBackgroundColour( m_prev_panel->GetBackgroundColor().ToColour() );
52 m_statusPanel->SetForegroundColour( m_prev_panel->GetForegroundColor().ToColour() );
53 m_status->SetForegroundColour( m_prev_panel->GetForegroundColor().ToColour() );
54
55 // Set our background so wx doesn't render a normal control background momentarily when
56 // rapidly navigating with arrow keys
57 SetBackgroundColour( m_prev_panel->GetBackgroundColor().ToColour() );
58 SetForegroundColour( m_prev_panel->GetForegroundColor().ToColour() );
59 }
60
61 m_outerSizer = new wxBoxSizer( wxVERTICAL );
62
63 if( m_prev_panel )
64 m_outerSizer->Add( m_prev_panel->GetWindow(), 1, wxALL | wxEXPAND, 0 );
65
66 m_outerSizer->Add( m_statusPanel, 1, wxALL | wxEXPAND, 0 );
67
68 SetSizer( m_outerSizer );
69
70 SetStatusText( wxEmptyString );
71}
72
73
74void FOOTPRINT_PREVIEW_WIDGET::SetStatusText( wxString const& aText )
75{
76 m_status->SetLabel( aText );
77 m_statusPanel->Show();
78
79 if( m_prev_panel )
80 m_prev_panel->GetWindow()->Hide();
81
82 Layout();
83}
84
85
87{
88 m_status->SetLabel( wxEmptyString );
89 m_statusPanel->Hide();
90
91 if( m_prev_panel )
92 m_prev_panel->GetWindow()->Show();
93
94 Layout();
95}
96
97
99{
100 if( m_prev_panel )
101 m_prev_panel->SetUserUnits( aUnits );
102}
103
104
105void FOOTPRINT_PREVIEW_WIDGET::SetPinFunctions( const std::map<wxString, wxString>& aPinFunctions )
106{
107 if( m_prev_panel )
108 m_prev_panel->SetPinFunctions( aPinFunctions );
109}
110
111
113{
114 if( !m_prev_panel || m_libid == aFPID )
115 return;
116
117 wxBusyCursor busy;
118
119 if( m_prev_panel->DisplayFootprint( aFPID ) )
120 {
121 ClearStatus();
122 m_libid = aFPID;
123 }
124 else
125 {
126 SetStatusText( _( "Footprint not found." ) );
127 m_libid.clear();
128 }
129}
130
131
132void FOOTPRINT_PREVIEW_WIDGET::DisplayFootprints( std::shared_ptr<FOOTPRINT> aFootprintA,
133 std::shared_ptr<FOOTPRINT> aFootprintB )
134{
135 ClearStatus();
136
137 if( m_prev_panel )
138 m_prev_panel->DisplayFootprints( aFootprintA, aFootprintB );
139}
140
141
143{
144 if( m_prev_panel )
146}
147
148
150 KIWAY& aKiway )
151{
152 wxWindow* panel = nullptr;
153
154 try
155 {
156 if( KIFACE* kiface = aKiway.KiFACE( KIWAY::FACE_PCB ) )
157 panel = kiface->CreateKiWindow( aParent, FRAME_FOOTPRINT_PREVIEW, &aKiway );
158 }
159 catch( ... )
160 {
161 }
162
163 return dynamic_cast<FOOTPRINT_PREVIEW_PANEL_BASE*>( panel );
164}
Base class for the actual viewer panel.
virtual bool DisplayFootprint(LIB_ID const &aFPID)=0
Set the currently displayed footprint.
virtual void SetPinFunctions(const std::map< wxString, wxString > &aPinFunctions)=0
Set the pin functions from the symbol's netlist.
virtual wxWindow * GetWindow()=0
Get the underlying wxWindow.
virtual const KIGFX::COLOR4D & GetForegroundColor() const =0
virtual void RefreshAll()=0
Force the redrawing of all contents.
virtual void SetUserUnits(EDA_UNITS aUnits)=0
virtual const KIGFX::COLOR4D & GetBackgroundColor() const =0
Get the colors to use in a preview widget to match the preview panel.
virtual void DisplayFootprints(std::shared_ptr< FOOTPRINT > aFootprintA, std::shared_ptr< FOOTPRINT > aFootprintB)=0
Display a pair of footprints.
static FOOTPRINT_PREVIEW_PANEL_BASE * Create(wxWindow *aParent, KIWAY &aKiway)
Return a footprint preview panel instance via Kiface.
void SetPinFunctions(const std::map< wxString, wxString > &aPinFunctions)
Set the pin functions from the symbol's netlist.
FOOTPRINT_PREVIEW_PANEL_BASE * m_prev_panel
void RefreshAll()
Force the redrawing of all contents.
void DisplayFootprint(const LIB_ID &aFPID)
Set the currently displayed footprint.
FOOTPRINT_PREVIEW_WIDGET(wxWindow *aParent, KIWAY &aKiway)
Construct a footprint preview widget.
void DisplayFootprints(std::shared_ptr< FOOTPRINT > aFootprintA, std::shared_ptr< FOOTPRINT > aFootprintB)
Display a pair of footprints.
void SetUserUnits(EDA_UNITS aUnits)
Set the units for the preview.
void SetStatusText(const wxString &aText)
Set the contents of the status label and display it.
void ClearStatus()
Clear the contents of the status label and hide it.
wxColour ToColour() const
Definition: color4d.cpp:220
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:284
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition: kiway.cpp:202
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:292
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
void clear()
Clear the contents of the library nickname, library entry name.
Definition: lib_id.cpp:43
#define _(s)
EDA_UNITS
Definition: eda_units.h:46
@ FRAME_FOOTPRINT_PREVIEW
Definition: frame_type.h:48
wxWindow * CreateKiWindow(wxWindow *aParent, int aClassId, KIWAY *aKiway, int aCtlBits=0) override
Create a wxWindow for the current project.
Implement a participant in the KIWAY alchemy.
Definition: kiway.h:151
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)