KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_diff_frame.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * https://www.gnu.org/licenses/gpl-3.0.html
19 * or you may write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22#include <symbol_diff_frame.h>
23#include <sch_base_frame.h>
24
25#include <wx/event.h>
26
27BEGIN_EVENT_TABLE( SYMBOL_DIFF_FRAME, SCH_BASE_FRAME )
28 // Window events
30 EVT_ACTIVATE( SYMBOL_DIFF_FRAME::OnActivate )
31
32 // Toolbar events
33 // EVT_TOOL( ID_LIBVIEW_SELECT_PART, SYMBOL_DIFF_FRAME::OnSelectSymbol )
34 // EVT_TOOL( ID_LIBVIEW_NEXT, SYMBOL_DIFF_FRAME::onSelectNextSymbol )
35 // EVT_TOOL( ID_LIBVIEW_PREVIOUS, SYMBOL_DIFF_FRAME::onSelectPreviousSymbol )
36 // EVT_CHOICE( ID_LIBVIEW_SELECT_UNIT_NUMBER, SYMBOL_DIFF_FRAME::onSelectSymbolUnit )
37
38 // listbox events
39 // EVT_TEXT( ID_LIBVIEW_LIB_FILTER, SYMBOL_DIFF_FRAME::OnLibFilter )
40 // EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, SYMBOL_DIFF_FRAME::ClickOnLibList )
41 // EVT_TEXT( ID_LIBVIEW_SYM_FILTER, SYMBOL_DIFF_FRAME::OnSymFilter )
42 // EVT_LISTBOX( ID_LIBVIEW_SYM_LIST, SYMBOL_DIFF_FRAME::ClickOnSymbolList )
43 // EVT_LISTBOX_DCLICK( ID_LIBVIEW_SYM_LIST, SYMBOL_DIFF_FRAME::DClickOnSymbolList )
44
45 // Menu (and/or hotkey) events
46 EVT_MENU( wxID_CLOSE, SYMBOL_DIFF_FRAME::CloseLibraryViewer )
47
48 EVT_UPDATE_UI( ID_LIBVIEW_SELECT_UNIT_NUMBER, SYMBOL_DIFF_FRAME::onUpdateUnitChoice )
49
50END_EVENT_TABLE()
51
52#define LIB_VIEW_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE )
53#define LIB_VIEW_STYLE_MODAL ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT )
54
55SYMBOL_DIFF_FRAME::SYMBOL_DIFF_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType,
56 const wxString& aLibraryName ) :
57 SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Symbol Library Browser" ),
58 wxDefaultPosition, wxDefaultSize, wxS( "SymbolDiff" ) )
59{
60 SetModal( true );
61
62 m_aboutTitle = _HKI( "KiCad Symbol Difference Viewer" );
63
64 // Give an icon
65 wxIcon icon;
66 icon.CopyFromBitmap( KiBitmap( BITMAPS::library_browser ) );
67 SetIcon( icon );
68
69
70 SetScreen( new SCH_SCREEN );
71 GetScreen()->m_Center = true; // Axis origin centered on screen.
73
74 // Ensure axis are always drawn (initial default display was not drawn)
76 gal_opts.m_axesEnabled = true;
77 gal_opts.m_gridMinSpacing = 10.0;
78 gal_opts.NotifyChanged();
79
82
84
85 setupTools();
87
91
92 wxPanel* libPanel = new wxPanel( this );
93 wxSizer* libSizer = new wxBoxSizer( wxVERTICAL );
94
95
96 wxPanel* symbolPanel = new wxPanel( this );
97 wxSizer* symbolSizer = new wxBoxSizer( wxVERTICAL );
98
99 m_symbolFilter = new wxSearchCtrl( symbolPanel, ID_LIBVIEW_SYM_FILTER, wxEmptyString,
100 wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
101 m_symbolFilter->SetDescriptiveText( _( "Filter" ) );
102 m_symbolFilter->SetToolTip(
103 _( "Filter on symbol name, keywords, description and pin count.\n"
104 "Search terms are separated by spaces. All search terms must match.\n"
105 "A term which is a number will also match against the pin count." ) );
106 symbolSizer->Add( m_symbolFilter, 0, wxEXPAND, 5 );
107
108#ifdef __WXGTK__
109 // wxSearchCtrl vertical height is not calculated correctly on some GTK setups
110 // See https://gitlab.com/kicad/code/kicad/-/issues/9019
111 m_libFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT( "qb" ) ).y + 10 ) );
112 m_symbolFilter->SetMinSize( wxSize( -1, GetTextExtent( wxT( "qb" ) ).y + 10 ) );
113#endif
114
115 m_symbolList = new WX_LISTBOX( symbolPanel, ID_LIBVIEW_SYM_LIST, wxDefaultPosition, wxDefaultSize,
116 0, nullptr, wxLB_HSCROLL | wxNO_BORDER );
117 symbolSizer->Add( m_symbolList, 1, wxEXPAND, 5 );
118
119 symbolPanel->SetSizer( symbolSizer );
120 symbolPanel->Fit();
121
122 // Preload libraries
123 loadAllLibraries();
124
125 if( aLibraryName.empty() )
126 {
127 ReCreateLibList();
128 }
129 else
130 {
131 m_currentSymbol.SetLibNickname( aLibraryName );
132 m_currentSymbol.SetLibItemName( "" );
133 m_unit = 1;
134 m_convert = 1;
135 }
136
137 m_selection_changed = false;
138
139 DisplayLibInfos();
140
141 m_auimgr.SetManagedWindow( this );
142
144
145 // Manage main toolbar
146 m_auimgr.AddPane( m_mainToolBar, EDA_PANE().HToolbar().Name( "MainToolbar" ).Top().Layer(6) );
147 m_auimgr.AddPane( m_messagePanel, EDA_PANE().Messages().Name( "MsgPanel" ) .Bottom().Layer(6) );
148
149 m_auimgr.AddPane( libPanel, EDA_PANE().Palette().Name( "Libraries" ).Left().Layer(2)
150 .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 200, -1 ) );
151 m_auimgr.AddPane( symbolPanel, EDA_PANE().Palette().Name( "Symbols" ).Left().Layer(1)
152 .CaptionVisible( false ).MinSize( 100, -1 ).BestSize( 300, -1 ) );
153
154 m_auimgr.AddPane( GetCanvas(), EDA_PANE().Canvas().Name( "DrawFrame" ).Center() );
155
156 m_auimgr.GetPane( libPanel ).Show( aLibraryName.empty() );
157
158 m_auimgr.Update();
159
160 if( m_libListWidth > 0 )
161 SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "Libraries" ), m_libListWidth, -1 );
162
163 if( m_symbolListWidth > 0 )
164 SetAuiPaneSize( m_auimgr, m_auimgr.GetPane( "Symbols" ), m_symbolListWidth, -1 );
165
167
168 if( !IsModal() ) // For modal mode, calling ShowModal() will show this frame
169 {
170 Raise();
171 Show( true );
172 }
173
174 SyncView();
175 GetCanvas()->SetCanFocus( false );
176
177 setupUnits( config() );
178
179 // Set the working/draw area size to display a symbol to a reasonable value:
180 // A 450mm x 450mm with a origin at the area center looks like a large working area
181 double max_size_x = schIUScale.mmToIU( 450 );
182 double max_size_y = schIUScale.mmToIU( 450 );
183 BOX2D bbox;
184 bbox.SetOrigin( -max_size_x / 2, -max_size_y / 2 );
185 bbox.SetSize( max_size_x, max_size_y );
186 GetCanvas()->GetView()->SetBoundary( bbox );
188
189 // If a symbol was previously selected in m_symbolList from a previous run, show it
190 wxString symbName = m_symbolList->GetStringSelection();
191
192 if( !symbName.IsEmpty() )
193 {
194 SetSelectedSymbol( symbName );
195 updatePreviewSymbol();
196 }
197}
198
199
201{
202 // Shutdown all running tools
203 if( m_toolManager )
205
206 if( m_previewItem )
207 {
208 GetCanvas()->GetView()->Remove( m_previewItem.get() );
209 m_previewItem = nullptr;
210 }
211}
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
static TOOL_ACTION zoomFitScreen
Definition: actions.h:124
bool m_Center
Center on screen.
Definition: base_screen.h:96
void SetOrigin(const Vec &pos)
Definition: box2.h:227
void SetSize(const SizeVec &size)
Definition: box2.h:238
COLOR4D GetColor(int aLayer) const
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void FinishAUIInitialization()
wxAuiManager m_auimgr
wxString m_aboutTitle
void ReCreateMenuBar()
Recreates the menu bar.
COLOR_SETTINGS * m_colorSettings
void setupUnits(APP_SETTINGS_BASE *aCfg)
GAL_DISPLAY_OPTIONS_IMPL & GetGalDisplayOptions()
Return a reference to the gal rendering options used by GAL for rendering.
EDA_MSG_PANEL * m_messagePanel
virtual void SetScreen(BASE_SCREEN *aScreen)
ACTION_TOOLBAR * m_mainToolBar
KIGFX::GAL * GetGAL() const
Return a pointer to the GAL instance used in the panel.
Specialization of the wxAuiPaneInfo class for KiCad panels.
double m_gridMinSpacing
Whether or not to draw the coordinate system axes.
bool m_axesEnabled
Fullscreen crosshair or small cross.
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
void SetDefaultPenWidth(int aWidth)
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:354
void SetBoundary(const BOX2D &aBoundary)
Set limits for view area.
Definition: view.h:281
void SetModal(bool aIsModal)
Definition: kiway_player.h:155
bool IsModal() const override
Return true if the frame is shown in our modal mode and false if the frame is shown as an usual frame...
Definition: kiway_player.h:154
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
SCH_RENDER_SETTINGS * GetRenderSettings()
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SyncView()
Mark all items for refresh.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void LoadColors(const COLOR_SETTINGS *aSettings) override
Symbol library viewer main window.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
SYMBOL_DIFF_FRAME(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aLibraryName=wxEmptyString)
void ReCreateVToolbar() override
void OnActivate(wxActivateEvent &event)
Called when the frame is activated to reload the libraries and symbol lists that can be changed by th...
void ReCreateHToolbar() override
void OnSize(wxSizeEvent &event) override
Recalculate the size of toolbars and display panel when the frame size changes.
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:167
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
void ShutdownAllTools()
Shutdown all tools with a currently registered event loop in this tool manager by waking them up with...
#define DEFAULT_LINE_WIDTH_MILS
The default wire width in mils. (can be changed in preference menu)
#define _HKI(x)
#define _(s)
@ ID_LIBVIEW_SELECT_UNIT_NUMBER
Definition: eeschema_id.h:65
@ ID_LIBVIEW_SYM_LIST
Definition: eeschema_id.h:69
@ ID_LIBVIEW_SYM_FILTER
Definition: eeschema_id.h:68
EVT_UPDATE_UI(ID_LOAD_FOOTPRINT_FROM_BOARD, FOOTPRINT_EDIT_FRAME::OnUpdateLoadFootprintFromBoard) EVT_UPDATE_UI(ID_ADD_FOOTPRINT_TO_BOARD
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
@ LAYER_SCHEMATIC_GRID_AXES
Definition: layer_ids.h:389
const double IU_PER_MILS
Definition: base_units.h:77
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
void SetAuiPaneSize(wxAuiManager &aManager, wxAuiPaneInfo &aPane, int aWidth, int aHeight)
Sets the size of an AUI pane, working around http://trac.wxwidgets.org/ticket/13180.