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, see <https://www.gnu.org/licenses/>.
18 */
19
22#include <eeschema_settings.h>
23#include <kiface_base.h>
24#include <sch_base_frame.h>
25#include <core/kicad_algo.h>
26#include <template_fieldnames.h>
30
31#include <wx/button.h>
32#include <wx/checkbox.h>
33#include <wx/sizer.h>
34
36
38 const SYMBOL_LIBRARY_FILTER* aFilter,
39 std::vector<PICKED_SYMBOL>& aHistoryList,
40 std::vector<PICKED_SYMBOL>& aAlreadyPlaced,
41 bool aAllowFieldEdits, bool aShowFootprints,
42 bool& aCancelled ) :
43 DIALOG_SHIM( aParent, wxID_ANY, _( "Choose Symbol" ), wxDefaultPosition, wxDefaultSize,
44 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
45{
46 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
47 m_chooserPanel = new PANEL_SYMBOL_CHOOSER( aParent, this, aFilter, aHistoryList, aAlreadyPlaced,
48 aAllowFieldEdits, aShowFootprints, aCancelled,
49 // Accept handler
50 [this]()
51 {
52 EndModal( wxID_OK );
53 },
54 // Escape handler
55 [this]()
56 {
57 EndModal( wxID_CANCEL );
58 } );
59
60 sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
61
62 if( aPreselect && aPreselect->IsValid() )
63 m_chooserPanel->SetPreselect( *aPreselect );
64
65 if( aFilter && aFilter->GetFilterPowerSymbols() )
66 SetTitle( _( "Choose Power Symbol" ) );
67
68 m_originalTitle = GetTitle();
70 m_chooserPanel->Adapter()->RegisterLazyLoadHandler(
71 std::bind( &DIALOG_SYMBOL_CHOOSER::onLazyLoadUpdate, this ) );
72
73 wxBoxSizer* buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
74
75 m_keepSymbol = new wxCheckBox( this, wxID_ANY, _( "Place repeated copies" ) );
76 m_keepSymbol->SetToolTip( _( "Keep the symbol selected for subsequent clicks." ) );
77
78 m_useUnits = new wxCheckBox( this, wxID_ANY, _( "Place all units" ) );
79 m_useUnits->SetValue( true );
80 m_useUnits->SetToolTip( _( "Sequentially place all units of the symbol." ) );
81
82 buttonsSizer->Add( m_keepSymbol, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
83 buttonsSizer->Add( m_useUnits, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 30 );
84
85 wxStdDialogButtonSizer* sdbSizer = new wxStdDialogButtonSizer();
86 wxButton* okButton = new wxButton( this, wxID_OK );
87 wxButton* cancelButton = new wxButton( this, wxID_CANCEL );
88
89 sdbSizer->AddButton( okButton );
90 sdbSizer->AddButton( cancelButton );
91 sdbSizer->Realize();
92
93 buttonsSizer->Add( sdbSizer, 1, wxALL, 5 );
94
95 sizer->Add( buttonsSizer, 0, wxEXPAND | wxLEFT, 5 );
96 SetSizer( sizer );
97
98 SetInitialFocus( m_chooserPanel->GetFocusTarget() );
100
101 m_chooserPanel->FinishSetup();
102 Layout();
103
104 Bind( wxEVT_CHAR_HOOK, &PANEL_SYMBOL_CHOOSER::OnChar, m_chooserPanel );
105}
106
107
112
113
115{
116 return m_chooserPanel->GetSelectedLibId( aUnit );
117}
118
119
120std::vector<std::pair<FIELD_T, wxString>> DIALOG_SYMBOL_CHOOSER::GetFields() const
121{
122 return m_chooserPanel->GetFields();
123}
124
125
126
128{
129 SetTitle( m_originalTitle + wxString::Format( _( " (%d items loaded)" ),
130 m_chooserPanel->GetItemCount() ) );
131 m_chooserPanel->Regenerate();
132}
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition dialog_shim.h:79
void SetupStandardButtons(std::map< int, wxString > aLabels={})
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER, const wxString &name=wxDialogNameStr)
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:45
bool IsValid() const
Check if this LID_ID is valid.
Definition lib_id.h:168
void OnChar(wxKeyEvent &aEvent)
A shim class between EDA_DRAW_FRAME and several derived classes: SYMBOL_EDIT_FRAME,...
Helper object to filter a list of libraries.
#define _(s)