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#include <pcb_painter.h>
22#include <footprint.h>
24#include <wx/sizer.h>
25#include <wx/stattext.h>
26#include <wx/slider.h>
27
28
30 FOOTPRINT_PREVIEW_WIDGET( aParent, aKiway ),
31 m_libraryItem( nullptr ),
32 m_slider( nullptr )
33{
34 wxBoxSizer* bottomSizer = new wxBoxSizer( wxHORIZONTAL );
35
36 wxStaticText* schLabel = new wxStaticText( this, wxID_ANY, _( "Board" ) );
37 wxStaticText* libLabel = new wxStaticText( this, wxID_ANY, _( "Library" ) );
38 m_slider = new wxSlider( this, wxID_ANY, 50, 0, 100 );
39
40 bottomSizer->Add( schLabel, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxALIGN_CENTRE_VERTICAL, 6 );
41 bottomSizer->Add( m_slider, 1, wxLEFT | wxRIGHT | wxALIGN_BOTTOM, 30 );
42 bottomSizer->Add( libLabel, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxALIGN_CENTRE_VERTICAL, 6 );
43
44 m_outerSizer->Add( bottomSizer, 0, wxTOP | wxLEFT | wxRIGHT | wxEXPAND, 10 );
45
46 Layout();
47
48 m_slider->Bind( wxEVT_SCROLL_TOP, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
49 m_slider->Bind( wxEVT_SCROLL_BOTTOM, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
50 m_slider->Bind( wxEVT_SCROLL_LINEUP, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
51 m_slider->Bind( wxEVT_SCROLL_LINEDOWN, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
52 m_slider->Bind( wxEVT_SCROLL_PAGEUP, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
53 m_slider->Bind( wxEVT_SCROLL_PAGEDOWN, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
54 m_slider->Bind( wxEVT_SCROLL_THUMBTRACK, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
55 m_slider->Bind( wxEVT_SCROLL_THUMBRELEASE, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
56 m_slider->Bind( wxEVT_SCROLL_CHANGED, &FOOTPRINT_DIFF_WIDGET::onSlider, this );
57}
58
59
61 std::shared_ptr<FOOTPRINT>& aLibFootprint )
62{
63 m_boardItemCopy.reset( static_cast<FOOTPRINT*>( aBoardFootprint->Clone() ) );
64 m_boardItemCopy->ClearSelected();
65 m_boardItemCopy->ClearBrightened();
66
67 m_boardItemCopy->RunOnDescendants(
68 [&]( BOARD_ITEM* item )
69 {
70 item->ClearSelected();
71 item->ClearBrightened();
72 } );
73
74 m_boardItemCopy->Move( -m_boardItemCopy->GetPosition() );
75
76 if( m_boardItemCopy->IsFlipped() )
77 m_boardItemCopy->Flip( {0,0}, false );
78
79 if( m_boardItemCopy->GetOrientation() != ANGLE_0 )
80 m_boardItemCopy->Rotate( {0,0}, -m_boardItemCopy->GetOrientation() );
81
82 m_libraryItem = aLibFootprint;
83
85
86 wxScrollEvent dummy;
87 onSlider( dummy );
88}
89
90
91void FOOTPRINT_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
92{
93 double pct = (double) m_slider->GetValue() / 100.0;
94
95 if( m_boardItemCopy )
96 {
97 double val;
98
99 if( pct < 0.5 )
100 val = 0.0;
101 else
102 val = ( pct - 0.5 ) * 2;
103
104 m_boardItemCopy->SetForcedTransparency( val );
105
106 m_boardItemCopy->RunOnDescendants(
107 [&]( BOARD_ITEM* item )
108 {
109 item->SetForcedTransparency( val );
110 } );
111 }
112
113 if( m_libraryItem )
114 {
115 double val;
116
117 if( pct > 0.5 )
118 val = 0.0;
119 else
120 val = 1.0 - ( pct * 2 );
121
122 m_libraryItem->SetForcedTransparency( val );
123
124 m_libraryItem->RunOnDescendants(
125 [&]( BOARD_ITEM* item )
126 {
127 item->SetForcedTransparency( val );
128 } );
129 }
130
131 RefreshAll();
132 aEvent.Skip();
133}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
void ClearSelected()
Definition: eda_item.h:121
void ClearBrightened()
Definition: eda_item.h:122
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...
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:1986
void SetForcedTransparency(double aForcedTransparency)
Definition: view_item.h:152
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:435
std::vector< FAB_LAYER_COLOR > dummy