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 The 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
21
#include <
widgets/footprint_preview_widget.h
>
22
#include <
lib_id.h
>
23
#include <
class_draw_panel_gal.h
>
24
#include <wx/stattext.h>
25
#include <wx/sizer.h>
26
#include <
kiway.h
>
27
28
29
FOOTPRINT_PREVIEW_WIDGET::FOOTPRINT_PREVIEW_WIDGET
( wxWindow* aParent,
KIWAY
& aKiway ) :
30
wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
31
wxFULL_REPAINT_ON_RESIZE | wxTAB_TRAVERSAL ),
32
m_prev_panel
( nullptr ),
33
m_status
( nullptr ),
34
m_statusPanel
( nullptr ),
35
m_statusSizer
( nullptr ),
36
m_outerSizer
( nullptr )
37
{
38
m_prev_panel
=
FOOTPRINT_PREVIEW_PANEL_BASE::Create
(
this
, aKiway );
39
40
m_statusPanel
=
new
wxPanel(
this
);
41
m_status
=
new
wxStaticText(
m_statusPanel
, wxID_ANY, wxEmptyString );
42
m_statusSizer
=
new
wxBoxSizer( wxVERTICAL );
43
m_statusSizer
->Add( 0, 0, 1 );
// add a spacer
44
m_statusSizer
->Add(
m_status
, 0, wxALIGN_CENTER );
45
m_statusSizer
->Add( 0, 0, 1 );
// add a spacer
46
m_statusPanel
->SetSizer(
m_statusSizer
);
47
48
if
(
m_prev_panel
)
49
{
50
// Give the status panel the same color scheme as the canvas so it isn't jarring when
51
// switched to
52
m_statusPanel
->SetBackgroundColour(
m_prev_panel
->GetBackgroundColor().ToColour() );
53
m_statusPanel
->SetForegroundColour(
m_prev_panel
->GetForegroundColor().ToColour() );
54
m_status
->SetForegroundColour(
m_prev_panel
->GetForegroundColor().ToColour() );
55
}
56
57
m_outerSizer
=
new
wxBoxSizer( wxVERTICAL );
58
59
if
(
m_prev_panel
)
60
m_outerSizer
->Add(
m_prev_panel
->GetCanvas(), 1, wxALL | wxEXPAND, 0 );
61
62
m_outerSizer
->Add(
m_statusPanel
, 1, wxALL | wxEXPAND, 0 );
63
64
SetSizer(
m_outerSizer
);
65
Layout();
66
67
SetStatusText
( wxEmptyString );
68
}
69
70
71
void
FOOTPRINT_PREVIEW_WIDGET::SetStatusText
( wxString
const
& aText )
72
{
73
m_status
->SetLabel( aText );
74
m_statusPanel
->Show();
75
76
if
(
m_prev_panel
)
77
m_prev_panel
->GetCanvas()->Hide();
78
79
Layout();
80
}
81
82
83
void
FOOTPRINT_PREVIEW_WIDGET::ClearStatus
()
84
{
85
m_status
->SetLabel( wxEmptyString );
86
m_statusPanel
->Hide();
87
88
if
(
m_prev_panel
)
89
m_prev_panel
->GetCanvas()->Show();
90
91
Layout();
92
}
93
94
95
void
FOOTPRINT_PREVIEW_WIDGET::SetUserUnits
(
EDA_UNITS
aUnits )
96
{
97
if
(
m_prev_panel
)
98
m_prev_panel
->SetUserUnits( aUnits );
99
}
100
101
102
void
FOOTPRINT_PREVIEW_WIDGET::SetPinFunctions
(
const
std::map<wxString, wxString>& aPinFunctions )
103
{
104
if
(
m_prev_panel
)
105
m_prev_panel
->SetPinFunctions( aPinFunctions );
106
}
107
108
109
void
FOOTPRINT_PREVIEW_WIDGET::DisplayFootprint
(
const
LIB_ID
& aFPID )
110
{
111
if
( !
m_prev_panel
||
m_libid
== aFPID )
112
return
;
113
114
wxBusyCursor busy;
115
116
if
(
m_prev_panel
->DisplayFootprint( aFPID ) )
117
{
118
ClearStatus
();
119
m_libid
= aFPID;
120
}
121
else
122
{
123
SetStatusText
(
_
(
"Footprint not found."
) );
124
m_libid
.clear();
125
}
126
}
127
128
129
void
FOOTPRINT_PREVIEW_WIDGET::DisplayFootprints
( std::shared_ptr<FOOTPRINT> aFootprintA,
130
std::shared_ptr<FOOTPRINT> aFootprintB )
131
{
132
ClearStatus
();
133
134
if
(
m_prev_panel
)
135
m_prev_panel
->DisplayFootprints( aFootprintA, aFootprintB );
136
}
137
138
139
void
FOOTPRINT_PREVIEW_WIDGET::RefreshAll
()
140
{
141
if
(
m_prev_panel
)
142
m_prev_panel
->RefreshAll();
143
}
144
145
146
FOOTPRINT_PREVIEW_PANEL_BASE
*
FOOTPRINT_PREVIEW_PANEL_BASE::Create
( wxWindow* aParent,
147
KIWAY
& aKiway )
148
{
149
wxWindow* panel =
nullptr
;
150
151
try
152
{
153
if
(
KIFACE
*
kiface
= aKiway.
KiFACE
(
KIWAY::FACE_PCB
) )
154
panel =
kiface
->CreateKiWindow( aParent,
FRAME_FOOTPRINT_PREVIEW
, &aKiway );
155
}
156
catch
( ... )
157
{
158
}
159
160
return
dynamic_cast<
FOOTPRINT_PREVIEW_PANEL_BASE
*
>
( panel );
161
}
FOOTPRINT_PREVIEW_PANEL_BASE
Base class for the actual viewer panel.
Definition
footprint_preview_widget.h:116
FOOTPRINT_PREVIEW_PANEL_BASE::Create
static FOOTPRINT_PREVIEW_PANEL_BASE * Create(wxWindow *aParent, KIWAY &aKiway)
Return a footprint preview panel instance via Kiface.
Definition
footprint_preview_widget.cpp:146
FOOTPRINT_PREVIEW_WIDGET::SetPinFunctions
void SetPinFunctions(const std::map< wxString, wxString > &aPinFunctions)
Set the pin functions from the symbol's netlist.
Definition
footprint_preview_widget.cpp:102
FOOTPRINT_PREVIEW_WIDGET::m_prev_panel
FOOTPRINT_PREVIEW_PANEL_BASE * m_prev_panel
Definition
footprint_preview_widget.h:101
FOOTPRINT_PREVIEW_WIDGET::RefreshAll
void RefreshAll()
Force the redrawing of all contents.
Definition
footprint_preview_widget.cpp:139
FOOTPRINT_PREVIEW_WIDGET::DisplayFootprint
void DisplayFootprint(const LIB_ID &aFPID)
Set the currently displayed footprint.
Definition
footprint_preview_widget.cpp:109
FOOTPRINT_PREVIEW_WIDGET::m_statusSizer
wxSizer * m_statusSizer
Definition
footprint_preview_widget.h:105
FOOTPRINT_PREVIEW_WIDGET::m_statusPanel
wxPanel * m_statusPanel
Definition
footprint_preview_widget.h:104
FOOTPRINT_PREVIEW_WIDGET::m_outerSizer
wxSizer * m_outerSizer
Definition
footprint_preview_widget.h:106
FOOTPRINT_PREVIEW_WIDGET::FOOTPRINT_PREVIEW_WIDGET
FOOTPRINT_PREVIEW_WIDGET(wxWindow *aParent, KIWAY &aKiway)
Construct a footprint preview widget.
Definition
footprint_preview_widget.cpp:29
FOOTPRINT_PREVIEW_WIDGET::DisplayFootprints
void DisplayFootprints(std::shared_ptr< FOOTPRINT > aFootprintA, std::shared_ptr< FOOTPRINT > aFootprintB)
Display a pair of footprints.
Definition
footprint_preview_widget.cpp:129
FOOTPRINT_PREVIEW_WIDGET::SetUserUnits
void SetUserUnits(EDA_UNITS aUnits)
Set the units for the preview.
Definition
footprint_preview_widget.cpp:95
FOOTPRINT_PREVIEW_WIDGET::m_libid
LIB_ID m_libid
Definition
footprint_preview_widget.h:107
FOOTPRINT_PREVIEW_WIDGET::m_status
wxStaticText * m_status
Definition
footprint_preview_widget.h:103
FOOTPRINT_PREVIEW_WIDGET::SetStatusText
void SetStatusText(const wxString &aText)
Set the contents of the status label and display it.
Definition
footprint_preview_widget.cpp:71
FOOTPRINT_PREVIEW_WIDGET::ClearStatus
void ClearStatus()
Clear the contents of the status label and hide it.
Definition
footprint_preview_widget.cpp:83
KIWAY
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition
kiway.h:294
KIWAY::KiFACE
virtual KIFACE * KiFACE(FACE_T aFaceId, bool doLoad=true)
Return the KIFACE* given a FACE_T.
Definition
kiway.cpp:206
KIWAY::FACE_PCB
@ FACE_PCB
pcbnew DSO
Definition
kiway.h:302
LIB_ID
A logical library item identifier and consists of various portions much like a URI.
Definition
lib_id.h:49
class_draw_panel_gal.h
_
#define _(s)
Definition
eda_3d_actions.cpp:36
EDA_UNITS
EDA_UNITS
Definition
eda_units.h:48
footprint_preview_widget.h
FRAME_FOOTPRINT_PREVIEW
@ FRAME_FOOTPRINT_PREVIEW
Definition
frame_type.h:48
kiway.h
lib_id.h
KIFACE
Implement a participant in the KIWAY alchemy.
Definition
kiway.h:155
kiface
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)
src
common
widgets
footprint_preview_widget.cpp
Generated on Sun Feb 1 2026 00:08:22 for KiCad PCB EDA Suite by
1.13.2