KiCad PCB EDA Suite
Loading...
Searching...
No Matches
design_block_pane.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 <design_block.h>
27#include <kiface_base.h>
28#include <sch_edit_frame.h>
29#include <core/kicad_algo.h>
30#include <template_fieldnames.h>
31#include <wx/button.h>
32#include <wx/checkbox.h>
33#include <wx/sizer.h>
34#include <ee_actions.h>
35#include <tool/tool_manager.h>
36
37
38// Do not make these static wxStrings; they need to respond to language changes
39#define REPEATED_PLACEMENT _( "Place repeated copies" )
40#define PLACE_AS_SHEET _( "Place as sheet" )
41#define KEEP_ANNOTATIONS _( "Keep annotations" )
42
44 std::vector<LIB_ID>& aHistoryList ) :
45 WX_PANEL( aParent ),
46 m_frame( aParent )
47{
48 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
49
50 m_chooserPanel = new PANEL_DESIGN_BLOCK_CHOOSER( aParent, this, aHistoryList,
51 // Accept handler
52 [this]()
53 {
55 } );
56
57 sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
58
59 if( aPreselect && aPreselect->IsValid() )
60 m_chooserPanel->SetPreselect( *aPreselect );
61
62 SetName( wxT( "Design Blocks" ) );
63
64 wxBoxSizer* cbSizer = new wxBoxSizer( wxVERTICAL );
65
66 m_repeatedPlacement = new wxCheckBox( this, wxID_ANY, REPEATED_PLACEMENT );
67 m_placeAsSheet = new wxCheckBox( this, wxID_ANY, PLACE_AS_SHEET );
68 m_keepAnnotations = new wxCheckBox( this, wxID_ANY, KEEP_ANNOTATIONS );
71
72 // Set all checkbox handlers to the same function
73 m_repeatedPlacement->Bind( wxEVT_CHECKBOX, &DESIGN_BLOCK_PANE::OnCheckBox, this );
74 m_placeAsSheet->Bind( wxEVT_CHECKBOX, &DESIGN_BLOCK_PANE::OnCheckBox, this );
75 m_keepAnnotations->Bind( wxEVT_CHECKBOX, &DESIGN_BLOCK_PANE::OnCheckBox, this );
76
77 cbSizer->Add( m_repeatedPlacement, 0, wxTOP|wxLEFT, 2 );
78 cbSizer->Add( m_placeAsSheet, 0, wxTOP|wxLEFT, 2 );
79 cbSizer->Add( m_keepAnnotations, 0, wxTOP|wxLEFT|wxBOTTOM, 2 );
80
81 sizer->Add( cbSizer, 0, wxEXPAND, 5 );
82 SetSizer( sizer );
83
85 Layout();
86
87 Bind( wxEVT_CHAR_HOOK, &PANEL_DESIGN_BLOCK_CHOOSER::OnChar, m_chooserPanel );
88 Bind( wxEVT_SIZE, &DESIGN_BLOCK_PANE::OnSize, this );
89 m_frame->Bind( EDA_LANG_CHANGED, &DESIGN_BLOCK_PANE::OnLanguageChanged, this );
90}
91
92
94{
95 m_frame->Unbind( EDA_LANG_CHANGED, &DESIGN_BLOCK_PANE::OnLanguageChanged, this );
96}
97
98
99void DESIGN_BLOCK_PANE::OnSize( wxSizeEvent &aEvent )
100{
101 if( APP_SETTINGS_BASE* cfg = m_frame->config() )
102 {
103 if( IsShownOnScreen() ) // Ensure the panel is shown when trying to save its size
104 m_frame->SaveSettings( cfg );
105 }
106
107 aEvent.Skip();
108}
109
110
112{
114 {
116 m_repeatedPlacement->SetToolTip( _( "Place copies of the design block on subsequent "
117 "clicks." ) );
118 }
119
120 if( m_placeAsSheet )
121 {
122 m_placeAsSheet->SetLabel( PLACE_AS_SHEET );
123 m_placeAsSheet->SetToolTip( _( "Place the design block as a new sheet." ) );
124 }
125
127 {
129 m_keepAnnotations->SetToolTip( _( "Preserve reference designators in the source "
130 "schematic. Otherwise, clear then reannotate according "
131 "to settings." ) );
132 }
133}
134
135
136void DESIGN_BLOCK_PANE::OnLanguageChanged( wxCommandEvent& aEvent )
137{
138 if( m_chooserPanel )
140
142
143 aEvent.Skip();
144}
145
146
147void DESIGN_BLOCK_PANE::OnCheckBox( wxCommandEvent& aEvent )
148{
149 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
150 {
151 cfg->m_DesignBlockChooserPanel.repeated_placement = m_repeatedPlacement->GetValue();
152 cfg->m_DesignBlockChooserPanel.place_as_sheet = m_placeAsSheet->GetValue();
153 cfg->m_DesignBlockChooserPanel.keep_annotations = m_keepAnnotations->GetValue();
154 }
155}
156
157
159{
160 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
161 {
162 m_repeatedPlacement->SetValue( cfg->m_DesignBlockChooserPanel.repeated_placement );
163 m_placeAsSheet->SetValue( cfg->m_DesignBlockChooserPanel.place_as_sheet );
164 m_keepAnnotations->SetValue( cfg->m_DesignBlockChooserPanel.keep_annotations );
165 }
166}
167
168
170{
172}
173
174
176{
177 return m_chooserPanel->GetSelectedLibId( aUnit );
178}
179
180
182{
183 m_chooserPanel->SelectLibId( aLibId );
184}
185
186
188{
190}
191
192
194 m_cbRepeatedPlacement( nullptr ),
195 m_cbPlaceAsSheet( nullptr ),
196 m_cbKeepAnnotations( nullptr )
197{
198 wxASSERT( aSettings );
199 m_settings = aSettings;
200};
201
202
204{
208}
209
210
211void FILEDLG_IMPORT_SHEET_CONTENTS::AddCustomControls( wxFileDialogCustomize& customizer )
212{
213 m_cbRepeatedPlacement = customizer.AddCheckBox( REPEATED_PLACEMENT );
215 m_cbPlaceAsSheet = customizer.AddCheckBox( PLACE_AS_SHEET );
217 m_cbKeepAnnotations = customizer.AddCheckBox( KEEP_ANNOTATIONS );
219}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
void OnSize(wxSizeEvent &aEvent)
~DESIGN_BLOCK_PANE() override
void SelectLibId(const LIB_ID &aLibId)
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
To be called after this dialog returns from ShowModal().
void OnCheckBox(wxCommandEvent &aEvent)
PANEL_DESIGN_BLOCK_CHOOSER * m_chooserPanel
wxCheckBox * m_repeatedPlacement
virtual void OnLanguageChanged(wxCommandEvent &aEvent)
SCH_EDIT_FRAME * m_frame
DESIGN_BLOCK_PANE(SCH_EDIT_FRAME *aParent, const LIB_ID *aPreselect, std::vector< LIB_ID > &aHistoryList)
Create dialog to choose design_block.
wxCheckBox * m_placeAsSheet
wxCheckBox * m_keepAnnotations
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
PANEL_DESIGN_BLOCK_CHOOSER m_DesignBlockChooserPanel
static TOOL_ACTION placeDesignBlock
Definition: ee_actions.h:82
wxFileDialogCheckBox * m_cbRepeatedPlacement
wxFileDialogCheckBox * m_cbPlaceAsSheet
virtual void TransferDataFromCustomControls() override
wxFileDialogCheckBox * m_cbKeepAnnotations
virtual void AddCustomControls(wxFileDialogCustomize &customizer) override
FILEDLG_IMPORT_SHEET_CONTENTS(EESCHEMA_SETTINGS *aSettings)
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
void SetPreselect(const LIB_ID &aPreselect)
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
To be called after this dialog returns from ShowModal().
void RefreshLibs(bool aProgress=false)
void SelectLibId(const LIB_ID &aLibId)
Schematic editor (Eeschema) main window.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
#define KEEP_ANNOTATIONS
#define REPEATED_PLACEMENT
#define PLACE_AS_SHEET
#define _(s)