KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_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 <sch_painter.h>
22#include <eeschema_settings.h>
24#include <sch_view.h>
25#include <wx/sizer.h>
26#include <wx/stattext.h>
27#include <wx/slider.h>
28
29
31 EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType ) :
32 SYMBOL_PREVIEW_WIDGET( aParent, nullptr, false, aCanvasType ),
33 m_libraryItem( nullptr ),
34 m_slider( nullptr )
35{
36 wxBoxSizer* bottomSizer = new wxBoxSizer( wxHORIZONTAL );
37
38 wxStaticText* schLabel = new wxStaticText( this, wxID_ANY, _( "Schematic" ) );
39 wxStaticText* libLabel = new wxStaticText( this, wxID_ANY, _( "Library" ) );
40 m_slider = new wxSlider( this, wxID_ANY, 50, 0, 100 );
41
42 bottomSizer->Add( schLabel, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxALIGN_CENTRE_VERTICAL, 6 );
43 bottomSizer->Add( m_slider, 1, wxLEFT | wxRIGHT | wxALIGN_BOTTOM, 30 );
44 bottomSizer->Add( libLabel, 0, wxLEFT | wxRIGHT | wxBOTTOM | wxALIGN_CENTRE_VERTICAL, 6 );
45
46 m_outerSizer->Add( bottomSizer, 0, wxTOP | wxLEFT | wxRIGHT | wxEXPAND, 10 );
47
48 Layout();
49
50 m_slider->Bind( wxEVT_SCROLL_TOP, &SYMBOL_DIFF_WIDGET::onSlider, this );
51 m_slider->Bind( wxEVT_SCROLL_BOTTOM, &SYMBOL_DIFF_WIDGET::onSlider, this );
52 m_slider->Bind( wxEVT_SCROLL_LINEUP, &SYMBOL_DIFF_WIDGET::onSlider, this );
53 m_slider->Bind( wxEVT_SCROLL_LINEDOWN, &SYMBOL_DIFF_WIDGET::onSlider, this );
54 m_slider->Bind( wxEVT_SCROLL_PAGEUP, &SYMBOL_DIFF_WIDGET::onSlider, this );
55 m_slider->Bind( wxEVT_SCROLL_PAGEDOWN, &SYMBOL_DIFF_WIDGET::onSlider, this );
56 m_slider->Bind( wxEVT_SCROLL_THUMBTRACK, &SYMBOL_DIFF_WIDGET::onSlider, this );
57 m_slider->Bind( wxEVT_SCROLL_THUMBRELEASE, &SYMBOL_DIFF_WIDGET::onSlider, this );
58 m_slider->Bind( wxEVT_SCROLL_CHANGED, &SYMBOL_DIFF_WIDGET::onSlider, this );
59}
60
61
63{
64 delete m_libraryItem;
65}
66
67
68void SYMBOL_DIFF_WIDGET::DisplayDiff( LIB_SYMBOL* aSchSymbol, LIB_SYMBOL* aLibSymbol, int aUnit,
69 int aConvert )
70{
71 KIGFX::VIEW* view = m_preview->GetView();
72
73 if( m_previewItem )
74 {
75 view->Remove( m_previewItem );
76 delete m_previewItem;
77 m_previewItem = nullptr;
78
79 wxASSERT( m_libraryItem );
80
81 view->Remove( m_libraryItem );
82 delete m_libraryItem;
83 m_libraryItem = nullptr;
84 }
85
86 if( aSchSymbol )
87 {
88 m_previewItem = aSchSymbol;
89
90 // For symbols having a De Morgan body style, use the first style
91 auto settings =
92 static_cast<KIGFX::SCH_RENDER_SETTINGS*>( view->GetPainter()->GetSettings() );
93
94 settings->m_ShowUnit = ( m_previewItem->IsMulti() && !aUnit ) ? 1 : aUnit;
95 settings->m_ShowConvert = ( m_previewItem->HasConversion() && !aConvert ) ? 1 : aConvert;
96
97 view->Add( m_previewItem );
98
99 // Get the symbol size, in internal units
100 m_itemBBox = m_previewItem->GetUnitBoundingBox( settings->m_ShowUnit,
101 settings->m_ShowConvert );
102
103 // Calculate the draw scale to fit the drawing area
105
106 wxASSERT( aLibSymbol );
107
108 m_libraryItem = aLibSymbol;
109 view->Add( m_libraryItem );
110 }
111
112 wxScrollEvent dummy;
113 onSlider( dummy );
114
115 m_preview->Show();
116 Layout();
117}
118
119
120void SYMBOL_DIFF_WIDGET::onSlider( wxScrollEvent& aEvent )
121{
122 KIGFX::VIEW* view = m_preview->GetView();
123 double pct = (double) m_slider->GetValue() / 100.0;
124
125 if( m_previewItem )
126 {
127 double val;
128
129 if( pct < 0.5 )
130 val = 0.0;
131 else
132 val = ( pct - 0.5 ) * 2;
133
135 view->Update( m_previewItem );
136
137 for( LIB_ITEM& child : m_previewItem->GetDrawItems() )
138 {
139 child.SetForcedTransparency( val );
140 view->Update( &child );
141 }
142 }
143
144 if( m_libraryItem )
145 {
146 double val;
147
148 if( pct > 0.5 )
149 val = 0.0;
150 else
151 val = 1.0 - ( pct * 2 );
152
154 view->Update( m_libraryItem );
155
156 for( LIB_ITEM& child : m_libraryItem->GetDrawItems() )
157 {
158 child.SetForcedTransparency( val );
159 view->Update( &child );
160 }
161 }
162
164
165 aEvent.Skip();
166}
virtual KIGFX::VIEW * GetView() const
Return a pointer to the #VIEW instance used in the panel.
void ForceRefresh()
Force a redraw.
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Store schematic specific render settings.
Definition: sch_painter.h:71
void SetForcedTransparency(double aForcedTransparency)
Definition: view_item.h:150
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:313
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:350
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1607
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:212
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:68
Define a library symbol object.
Definition: lib_symbol.h:99
bool IsMulti() const
Definition: lib_symbol.h:601
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:546
const BOX2I GetUnitBoundingBox(int aUnit, int aConvert, bool aIgnoreHiddenFields=true) const
Get the bounding box for the symbol.
bool HasConversion() const
Test if symbol has more than one body conversion type (DeMorgan).
void DisplayDiff(LIB_SYMBOL *aSchSymbol, LIB_SYMBOL *aLibSymbol, int aUnit, int aConvert)
Set the currently displayed symbol.
LIB_SYMBOL * m_libraryItem
SYMBOL_DIFF_WIDGET(wxWindow *aParent, EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType)
Construct a symbol diff widget, consisting on a canvas for displaying a schematic and a library symbo...
void onSlider(wxScrollEvent &aEvent)
LIB_SYMBOL * m_previewItem
A local copy of the LIB_SYMBOL to display on the canvas.
EDA_DRAW_PANEL_GAL * m_preview
BOX2I m_itemBBox
The bounding box of the current item.
#define _(s)
std::vector< FAB_LAYER_COLOR > dummy