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 The 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 bool& aCancelled ) :
47 DIALOG_SHIM( aParent, wxID_ANY, _( "Choose Symbol" ), wxDefaultPosition, wxDefaultSize,
48 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
49{
50 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
51 m_chooserPanel = new PANEL_SYMBOL_CHOOSER( aParent, this, aFilter, aHistoryList, aAlreadyPlaced,
52 aAllowFieldEdits, aShowFootprints, aCancelled,
53 // Accept handler
54 [this]()
55 {
56 EndModal( wxID_OK );
57 },
58 // Escape handler
59 [this]()
60 {
61 EndModal( wxID_CANCEL );
62 } );
63
64 sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
65
66 if( aPreselect && aPreselect->IsValid() )
67 m_chooserPanel->SetPreselect( *aPreselect );
68
69 if( aFilter && aFilter->GetFilterPowerSymbols() )
70 SetTitle( _( "Choose Power Symbol" ) );
71
72 SetTitle( GetTitle() + wxString::Format( _( " (%d items loaded)" ),
74
75 wxBoxSizer* buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
76
77 m_keepSymbol = new wxCheckBox( this, wxID_ANY, _( "Place repeated copies" ) );
78 m_keepSymbol->SetToolTip( _( "Keep the symbol selected for subsequent clicks." ) );
79
80 m_useUnits = new wxCheckBox( this, wxID_ANY, _( "Place all units" ) );
81 m_useUnits->SetToolTip( _( "Sequentially place all units of the symbol." ) );
82
83 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
84 {
85 m_keepSymbol->SetValue( cfg->m_SymChooserPanel.keep_symbol );
86 m_useUnits->SetValue( cfg->m_SymChooserPanel.place_all_units );
87 }
88
89 buttonsSizer->Add( m_keepSymbol, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
90 buttonsSizer->Add( m_useUnits, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 30 );
91
92 wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
93 wxButton* okButton = new wxButton( this, wxID_OK );
94 wxButton* cancelButton = new wxButton( this, wxID_CANCEL );
95
96 sdbSizer->AddButton( okButton );
97 sdbSizer->AddButton( cancelButton );
98 sdbSizer->Realize();
99
100 buttonsSizer->Add( sdbSizer, 1, wxALL, 5 );
101
102 sizer->Add( buttonsSizer, 0, wxEXPAND | wxLEFT, 5 );
103 SetSizer( sizer );
104
107
109 Layout();
110
111 Bind( wxEVT_CHAR_HOOK, &PANEL_SYMBOL_CHOOSER::OnChar, m_chooserPanel );
112}
113
114
116{
117 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
118 {
119 cfg->m_SymChooserPanel.keep_symbol = m_keepSymbol->GetValue();
120 cfg->m_SymChooserPanel.place_all_units = m_useUnits->GetValue();
121 }
122
123 Unbind( wxEVT_CHAR_HOOK, &PANEL_SYMBOL_CHOOSER::OnChar, m_chooserPanel );
124}
125
126
128{
129 return m_chooserPanel->GetSelectedLibId( aUnit );
130}
131
132
133std::vector<std::pair<FIELD_T, wxString>> DIALOG_SYMBOL_CHOOSER::GetFields() const
134{
135 return m_chooserPanel->GetFields();
136}
137
138
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:52
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:66
void SetupStandardButtons(std::map< int, wxString > aLabels={})
std::vector< std::pair< FIELD_T, wxString > > GetFields() const
Get a list of fields edited by the user.
PANEL_SYMBOL_CHOOSER * m_chooserPanel
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, bool &aCancelled)
Create dialog to choose symbol.
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
To be called after this dialog returns from ShowModal().
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
wxWindow * GetFocusTarget() const
std::vector< std::pair< FIELD_T, wxString > > GetFields() const
Get a list of fields edited by the user.
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.