KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_symbol_chooser.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 2
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 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <symbol_library.h>
27#include <eeschema_settings.h>
28#include <kiface_base.h>
29#include <sch_base_frame.h>
30#include <core/kicad_algo.h>
31#include <template_fieldnames.h>
35#include <wx/button.h>
36#include <wx/checkbox.h>
37#include <wx/sizer.h>
38
40
42 const SYMBOL_LIBRARY_FILTER* aFilter,
43 std::vector<PICKED_SYMBOL>& aHistoryList,
44 std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
45 bool aAllowFieldEdits, bool aShowFootprints ) :
46 DIALOG_SHIM( aParent, wxID_ANY, _( "Choose Symbol" ), wxDefaultPosition, wxDefaultSize,
47 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
48{
49 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
50 m_chooserPanel = new PANEL_SYMBOL_CHOOSER( aParent, this, aFilter, aHistoryList, aAlreadyPlaced,
51 aAllowFieldEdits, aShowFootprints,
52 [this]()
53 {
54 EndModal( wxID_OK );
55 },
56 [this]()
57 {
58 EndModal( wxID_CANCEL );
59 } );
60
61 sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
62
63 if( aPreselect && aPreselect->IsValid() )
64 m_chooserPanel->SetPreselect( *aPreselect );
65
66 if( aFilter && aFilter->GetFilterPowerSymbols() )
67 SetTitle( _( "Choose Power Symbol" ) );
68
69 SetTitle( GetTitle() + wxString::Format( _( " (%d items loaded)" ),
71
72 wxBoxSizer* buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
73
74 m_keepSymbol = new wxCheckBox( this, wxID_ANY, _( "Place repeated copies" ) );
75 m_keepSymbol->SetToolTip( _( "Keep the symbol selected for subsequent clicks." ) );
76
77 m_useUnits = new wxCheckBox( this, wxID_ANY, _( "Place all units" ) );
78 m_useUnits->SetToolTip( _( "Sequentially place all units of the symbol." ) );
79
80 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
81 {
82 m_keepSymbol->SetValue( cfg->m_SymChooserPanel.keep_symbol );
83 m_useUnits->SetValue( cfg->m_SymChooserPanel.place_all_units );
84 }
85
86 buttonsSizer->Add( m_keepSymbol, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
87 buttonsSizer->Add( m_useUnits, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 30 );
88
89 wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
90 wxButton* okButton = new wxButton( this, wxID_OK );
91 wxButton* cancelButton = new wxButton( this, wxID_CANCEL );
92
93 sdbSizer->AddButton( okButton );
94 sdbSizer->AddButton( cancelButton );
95 sdbSizer->Realize();
96
97 buttonsSizer->Add( sdbSizer, 1, wxALL, 5 );
98
99 sizer->Add( buttonsSizer, 0, wxEXPAND | wxLEFT, 5 );
100 SetSizer( sizer );
101
104
106 Layout();
107
108 Bind( wxEVT_CHAR_HOOK, &PANEL_SYMBOL_CHOOSER::OnChar, m_chooserPanel );
109}
110
111
113{
114 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
115 {
116 cfg->m_SymChooserPanel.keep_symbol = m_keepSymbol->GetValue();
117 cfg->m_SymChooserPanel.place_all_units = m_useUnits->GetValue();
118 }
119}
120
121
123{
124 return m_chooserPanel->GetSelectedLibId( aUnit );
125}
126
127
128std::vector<std::pair<int, wxString>> DIALOG_SYMBOL_CHOOSER::GetFields() const
129{
130 return m_chooserPanel->GetFields();
131}
132
133
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition: dialog_shim.h:84
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:98
void SetupStandardButtons(std::map< int, wxString > aLabels={})
std::vector< std::pair< int, wxString > > GetFields() const
Get a list of fields edited by the user.
PANEL_SYMBOL_CHOOSER * m_chooserPanel
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
To be called after this dialog returns from ShowModal().
DIALOG_SYMBOL_CHOOSER(SCH_BASE_FRAME *aParent, const LIB_ID *aPreselect, const SYMBOL_LIBRARY_FILTER *aFilter, std::vector< PICKED_SYMBOL > &aHistoryList, std::vector< PICKED_SYMBOL > &aAlreadyPlaced, bool aAllowFieldEdits, bool aShowFootprints)
Create dialog to choose symbol.
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:49
bool IsValid() const
Check if this LID_ID is valid.
Definition: lib_id.h:172
std::vector< std::pair< int, wxString > > GetFields() const
Get a list of fields edited by the user.
wxWindow * GetFocusTarget() const
void OnChar(wxKeyEvent &aEvent)
void SetPreselect(const LIB_ID &aPreselect)
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
To be called after this dialog returns from ShowModal().
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
Helper object to filter a list of libraries.
#define _(s)
Definition for symbol library class.