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 (C) 2023 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, wxLEFT | wxRIGHT | wxBOTTOM | wxALIGN_CENTRE_VERTICAL, 6 );
46 bottomSizer->Add( m_slider, 1, wxLEFT | wxRIGHT | wxALIGN_BOTTOM, 30 );
47 bottomSizer->Add( libLabel, 0, wxLEFT | wxRIGHT | wxBOTTOM | 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 | wxRIGHT | wxALIGN_CENTRE_VERTICAL, 6 );
55
56 m_outerSizer->Add( bottomSizer, 0, wxTOP | wxLEFT | wxRIGHT | wxEXPAND, 10 );
57
58 Layout();
59
60 m_slider->Bind( wxEVT_SCROLL_TOP, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
61 m_slider->Bind( wxEVT_SCROLL_BOTTOM, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
62 m_slider->Bind( wxEVT_SCROLL_LINEUP, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
63 m_slider->Bind( wxEVT_SCROLL_LINEDOWN, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
64 m_slider->Bind( wxEVT_SCROLL_PAGEUP, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
65 m_slider->Bind( wxEVT_SCROLL_PAGEDOWN, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
66 m_slider->Bind( wxEVT_SCROLL_THUMBTRACK, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
67 m_slider->Bind( wxEVT_SCROLL_THUMBRELEASE, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
68 m_slider->Bind( wxEVT_SCROLL_CHANGED, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
69
70 // Bind keys
71 Bind( wxEVT_CHAR_HOOK, &FOOTPRINT_DIFF_WIDGET::onCharHook, this );
72
73 m_toggleButton->Bind( wxEVT_BUTTON,
74 [&]( wxCommandEvent& aEvent )
75 {
76 ToggleAB();
77 } );
78}
79
80
82 std::shared_ptr<FOOTPRINT>& aLibFootprint )
83{
84 m_boardItemCopy.reset( static_cast<FOOTPRINT*>( aBoardFootprint->Clone() ) );
85 m_boardItemCopy->ClearSelected();
86 m_boardItemCopy->ClearBrightened();
87
88 m_boardItemCopy->RunOnDescendants(
89 [&]( BOARD_ITEM* item )
90 {
91 item->ClearSelected();
92 item->ClearBrightened();
93 } );
94
95 m_boardItemCopy->Move( -m_boardItemCopy->GetPosition() );
96
97 if( m_boardItemCopy->IsFlipped() )
98 m_boardItemCopy->Flip( { 0, 0 }, FLIP_DIRECTION::TOP_BOTTOM );
99
100 if( m_boardItemCopy->GetOrientation() != ANGLE_0 )
101 m_boardItemCopy->Rotate( { 0, 0 }, -m_boardItemCopy->GetOrientation() );
102
103 m_libraryItem = aLibFootprint;
104
106
107 wxScrollEvent dummy;
108 onSlider( dummy );
109}
110
111
113{
114 const int val = m_slider->GetValue();
115
116 if( val == 0 )
117 m_slider->SetValue( 100 );
118 else
119 m_slider->SetValue( 0 );
120
121 wxScrollEvent dummy;
122 onSlider( dummy );
123}
124
125
126void FOOTPRINT_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
127{
128 double pct = (double) m_slider->GetValue() / 100.0;
129
130 if( m_boardItemCopy )
131 {
132 double val;
133
134 if( pct < 0.5 )
135 val = 0.0;
136 else
137 val = ( pct - 0.5 ) * 2;
138
139 m_boardItemCopy->SetForcedTransparency( val );
140
141 m_boardItemCopy->RunOnDescendants(
142 [&]( BOARD_ITEM* item )
143 {
144 item->SetForcedTransparency( val );
145 } );
146 }
147
148 if( m_libraryItem )
149 {
150 double val;
151
152 if( pct > 0.5 )
153 val = 0.0;
154 else
155 val = 1.0 - ( pct * 2 );
156
157 m_libraryItem->SetForcedTransparency( val );
158
159 m_libraryItem->RunOnDescendants(
160 [&]( BOARD_ITEM* item )
161 {
162 item->SetForcedTransparency( val );
163 } );
164 }
165
166 RefreshAll();
167 aEvent.Skip();
168}
169
170
171void FOOTPRINT_DIFF_WIDGET::onCharHook( wxKeyEvent& aEvent )
172{
173 if( aEvent.GetKeyCode() == '/' )
174 {
175 ToggleAB();
176 }
177 else
178 {
179 aEvent.Skip();
180 }
181}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
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:79
void ClearSelected()
Definition: eda_item.h:122
void ClearBrightened()
Definition: eda_item.h:123
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.
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.
Definition: footprint.cpp:2075
void SetForcedTransparency(double aForcedTransparency)
Definition: view_item.h:153
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:284
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:401
wxString AddHotkeyName(const wxString &aText, int aHotKey, HOTKEY_ACTION_TYPE aStyle)
std::vector< FAB_LAYER_COLOR > dummy