KiCad PCB EDA Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
pcb_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>
28#include <pcbnew_settings.h>
29#include <kiface_base.h>
30#include <pcb_edit_frame.h>
31#include <core/kicad_algo.h>
32#include <template_fieldnames.h>
33#include <wx/button.h>
34#include <wx/checkbox.h>
35#include <wx/sizer.h>
36#include <confirm.h>
38#include <tool/tool_manager.h>
39#include <tools/pcb_actions.h>
41
42// Do not make these static wxStrings; they need to respond to language changes
43#define REPEATED_PLACEMENT _( "Place repeated copies" )
44#define PLACE_AS_GROUP _( "Place as group" )
45#define KEEP_ANNOTATIONS _( "Keep annotations" )
46
48 std::vector<LIB_ID>& aHistoryList ) :
49 DESIGN_BLOCK_PANE( aParent, aPreselect, aHistoryList )
50{
51 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
52 m_chooserPanel = new PANEL_DESIGN_BLOCK_CHOOSER( aParent, this, aHistoryList,
53 [aParent]()
54 {
55 aParent->GetToolManager()->RunAction(
57 },
58 aParent->GetToolManager()->GetTool<PCB_DESIGN_BLOCK_CONTROL>()
59 );
61 sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
62
63 if( aPreselect && aPreselect->IsValid() )
64 m_chooserPanel->SetPreselect( *aPreselect );
65
66 SetName( wxT( "Design Blocks" ) );
67
68 wxBoxSizer* cbSizer = new wxBoxSizer( wxVERTICAL );
69
70 m_repeatedPlacement = new wxCheckBox( this, wxID_ANY, REPEATED_PLACEMENT );
71 m_placeAsGroup = new wxCheckBox( this, wxID_ANY, PLACE_AS_GROUP );
72 m_keepAnnotations = new wxCheckBox( this, wxID_ANY, KEEP_ANNOTATIONS );
75
76 // Set all checkbox handlers to the same function
77 m_repeatedPlacement->Bind( wxEVT_CHECKBOX, &PCB_DESIGN_BLOCK_PANE::OnCheckBox, this );
78 m_placeAsGroup->Bind( wxEVT_CHECKBOX, &PCB_DESIGN_BLOCK_PANE::OnCheckBox, this );
79 m_keepAnnotations->Bind( wxEVT_CHECKBOX, &PCB_DESIGN_BLOCK_PANE::OnCheckBox, this );
80
81 cbSizer->Add( m_repeatedPlacement, 0, wxTOP | wxLEFT, 2 );
82 cbSizer->Add( m_placeAsGroup, 0, wxTOP | wxLEFT, 2 );
83 cbSizer->Add( m_keepAnnotations, 0, wxTOP | wxLEFT | wxBOTTOM, 2 );
84
85 sizer->Add( cbSizer, 0, wxEXPAND, 5 );
86 SetSizer( sizer );
87
89 Layout();
90
91 Bind( wxEVT_CHAR_HOOK, &PANEL_DESIGN_BLOCK_CHOOSER::OnChar, m_chooserPanel );
92}
93
94
96{
98 {
100 m_repeatedPlacement->SetToolTip( _( "Place copies of the design block on subsequent "
101 "clicks." ) );
102 }
103
104 if( m_placeAsGroup )
105 {
106 m_placeAsGroup->SetLabel( PLACE_AS_GROUP );
107 m_placeAsGroup->SetToolTip( _( "Place the design block as a group." ) );
108 }
109
111 {
113 m_keepAnnotations->SetToolTip( _( "Preserve reference designators in the source "
114 "layout. Otherwise, clear them." ) );
115 }
116}
117
118void PCB_DESIGN_BLOCK_PANE::OnCheckBox( wxCommandEvent& aEvent )
119{
120 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
121 {
122 cfg->m_DesignBlockChooserPanel.repeated_placement = m_repeatedPlacement->GetValue();
123 cfg->m_DesignBlockChooserPanel.place_as_sheet = m_placeAsGroup->GetValue();
124 cfg->m_DesignBlockChooserPanel.keep_annotations = m_keepAnnotations->GetValue();
125 }
126}
127
128
130{
131 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
132 {
133 m_repeatedPlacement->SetValue( cfg->m_DesignBlockChooserPanel.repeated_placement );
134 m_placeAsGroup->SetValue( cfg->m_DesignBlockChooserPanel.place_as_sheet );
135 m_keepAnnotations->SetValue( cfg->m_DesignBlockChooserPanel.keep_annotations );
136 }
137}
138
139
141 m_cbRepeatedPlacement( nullptr ), m_cbPlaceAsSheet( nullptr ), m_cbKeepAnnotations( nullptr )
142{
143 wxASSERT( aSettings );
144 m_settings = aSettings;
145};
146
147
149{
153}
154
155
156void FILEDLG_IMPORT_SHEET_CONTENTS::AddCustomControls( wxFileDialogCustomize& customizer )
157{
158 m_cbRepeatedPlacement = customizer.AddCheckBox( REPEATED_PLACEMENT );
160 m_cbPlaceAsSheet = customizer.AddCheckBox( PLACE_AS_GROUP );
162 m_cbKeepAnnotations = customizer.AddCheckBox( KEEP_ANNOTATIONS );
164}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
PANEL_DESIGN_BLOCK_CHOOSER m_DesignBlockChooserPanel
Definition: app_settings.h:197
PANEL_DESIGN_BLOCK_CHOOSER * m_chooserPanel
wxFileDialogCheckBox * m_cbKeepAnnotations
void AddCustomControls(wxFileDialogCustomize &customizer) override
FILEDLG_IMPORT_SHEET_CONTENTS(EESCHEMA_SETTINGS *aSettings)
wxFileDialogCheckBox * m_cbRepeatedPlacement
wxFileDialogCheckBox * m_cbPlaceAsSheet
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)
void SetPreviewWidget(DESIGN_BLOCK_PREVIEW_WIDGET *aPreview)
static TOOL_ACTION placeDesignBlock
Definition: pcb_actions.h:464
void OnCheckBox(wxCommandEvent &aEvent)
PCB_DESIGN_BLOCK_PANE(PCB_EDIT_FRAME *aParent, const LIB_ID *aPreselect, std::vector< LIB_ID > &aHistoryList)
void setLabelsAndTooltips() override
The main frame for Pcbnew.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
This file is part of the common library.
#define _(s)
#define PLACE_AS_GROUP
#define KEEP_ANNOTATIONS
#define REPEATED_PLACEMENT
Definition of file extensions used in Kicad.