KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_diff_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 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
22#include <wx/sizer.h>
23#include <wx/stattext.h>
24#include <wx/slider.h>
25#include <wx/bmpbuttn.h>
26
27#include <bitmaps.h>
28#include <footprint.h>
29#include <hotkeys_basic.h>
30#include <pcb_painter.h>
32
33
35 FOOTPRINT_PREVIEW_WIDGET( aParent, aKiway ),
36 m_libraryItem( nullptr ),
37 m_slider( nullptr )
38{
39 wxBoxSizer* bottomSizer = new wxBoxSizer( wxHORIZONTAL );
40
41 wxStaticText* schLabel = new wxStaticText( this, wxID_ANY, _( "Board" ) );
42 wxStaticText* libLabel = new wxStaticText( this, wxID_ANY, _( "Library" ) );
43 m_slider = new wxSlider( this, wxID_ANY, 50, 0, 100 );
44
45 bottomSizer->Add( schLabel, 0, wxALIGN_CENTRE_VERTICAL, 6 );
46 bottomSizer->Add( m_slider, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 6 );
47 bottomSizer->Add( libLabel, 0, wxLEFT | wxALIGN_CENTRE_VERTICAL, 6 );
48
49 m_toggleButton = new wxBitmapButton( this, wxID_ANY, KiBitmapBundle( BITMAPS::swap ) );
50 wxString toggleTooltip = _( "Toggle between A and B display" );
51 toggleTooltip = AddHotkeyName( toggleTooltip, '/', HOTKEY_ACTION_TYPE::IS_COMMENT );
52 m_toggleButton->SetToolTip( toggleTooltip );
53
54 bottomSizer->Add( m_toggleButton, 0, wxLEFT | wxALIGN_CENTRE_VERTICAL, 6 );
55
56 m_outerSizer->Add( bottomSizer, 0, wxTOP | wxEXPAND, 6 );
57
58 Layout();
59
60 if( aParent->GetSizer() )
61 aParent->GetSizer()->Fit( aParent );
62
63 m_slider->Bind( wxEVT_SCROLL_TOP, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
64 m_slider->Bind( wxEVT_SCROLL_BOTTOM, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
65 m_slider->Bind( wxEVT_SCROLL_LINEUP, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
66 m_slider->Bind( wxEVT_SCROLL_LINEDOWN, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
67 m_slider->Bind( wxEVT_SCROLL_PAGEUP, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
68 m_slider->Bind( wxEVT_SCROLL_PAGEDOWN, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
69 m_slider->Bind( wxEVT_SCROLL_THUMBTRACK, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
70 m_slider->Bind( wxEVT_SCROLL_THUMBRELEASE, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
71 m_slider->Bind( wxEVT_SCROLL_CHANGED, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
72
73 // Bind keys
74 Bind( wxEVT_CHAR_HOOK, &FOOTPRINT_DIFF_WIDGET::onCharHook, this );
75
76 m_toggleButton->Bind( wxEVT_BUTTON,
77 [&]( wxCommandEvent& aEvent )
78 {
79 ToggleAB();
80 } );
81}
82
83
85 std::shared_ptr<FOOTPRINT>& aLibFootprint )
86{
87 m_boardItemCopy.reset( static_cast<FOOTPRINT*>( aBoardFootprint->Clone() ) );
88 m_boardItemCopy->ClearSelected();
89 m_boardItemCopy->ClearBrightened();
90
91 m_boardItemCopy->RunOnChildren(
92 [&]( BOARD_ITEM* item )
93 {
94 item->ClearSelected();
95 item->ClearBrightened();
96 },
98
99 m_boardItemCopy->Move( -m_boardItemCopy->GetPosition() );
100
101 if( m_boardItemCopy->IsFlipped() )
103
104 if( m_boardItemCopy->GetOrientation() != ANGLE_0 )
105 m_boardItemCopy->Rotate( { 0, 0 }, -m_boardItemCopy->GetOrientation() );
106
107 m_libraryItem = aLibFootprint;
108
110
111 wxScrollEvent dummy;
112 onSlider( dummy );
113}
114
115
117{
118 const int val = m_slider->GetValue();
119
120 if( val == 0 )
121 m_slider->SetValue( 100 );
122 else
123 m_slider->SetValue( 0 );
124
125 wxScrollEvent dummy;
126 onSlider( dummy );
127}
128
129
130void FOOTPRINT_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
131{
132 double pct = (double) m_slider->GetValue() / 100.0;
133
134 if( m_boardItemCopy )
135 {
136 double val;
137
138 if( pct < 0.5 )
139 val = 0.0;
140 else
141 val = ( pct - 0.5 ) * 2;
142
143 m_boardItemCopy->SetForcedTransparency( val );
144
145 m_boardItemCopy->RunOnChildren(
146 [&]( BOARD_ITEM* item )
147 {
148 item->SetForcedTransparency( val );
149 },
151 }
152
153 if( m_libraryItem )
154 {
155 double val;
156
157 if( pct > 0.5 )
158 val = 0.0;
159 else
160 val = 1.0 - ( pct * 2 );
161
162 m_libraryItem->SetForcedTransparency( val );
163
164 m_libraryItem->RunOnChildren(
165 [&]( BOARD_ITEM* item )
166 {
167 item->SetForcedTransparency( val );
168 },
170 }
171
172 RefreshAll();
173 aEvent.Skip();
174}
175
176
177void FOOTPRINT_DIFF_WIDGET::onCharHook( wxKeyEvent& aEvent )
178{
179 if( aEvent.GetKeyCode() == '/' )
180 {
181 ToggleAB();
182 }
183 else
184 {
185 aEvent.Skip();
186 }
187}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:110
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:83
void ClearSelected()
Definition eda_item.h:142
void ClearBrightened()
Definition eda_item.h:143
void ToggleAB()
Toggle between full-A and full-B display.
void DisplayDiff(FOOTPRINT *aBoardFootprint, std::shared_ptr< FOOTPRINT > &aLibFootprint)
Set the currently displayed symbol.
std::shared_ptr< FOOTPRINT > m_libraryItem
FOOTPRINT_DIFF_WIDGET(wxWindow *aParent, KIWAY &aKiway)
Construct a footprint diff widget, consisting on a canvas for displaying a board and a library footpr...
void onCharHook(wxKeyEvent &aEvent)
wxBitmapButton * m_toggleButton
std::shared_ptr< FOOTPRINT > m_boardItemCopy
void onSlider(wxScrollEvent &aEvent)
void RefreshAll()
Force the redrawing of all contents.
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.
EDA_ITEM * Clone() const override
Invoke a function on all children.
void SetForcedTransparency(double aForcedTransparency)
Definition view_item.h:166
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:294
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
@ RECURSE
Definition eda_item.h:51
wxString AddHotkeyName(const wxString &aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle)
@ IS_COMMENT
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
Definition mirror.h:29
std::vector< FAB_LAYER_COLOR > dummy