KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <design_block.h>
24#include <pcbnew_settings.h>
25#include <kiface_base.h>
26#include <pcb_edit_frame.h>
27#include <core/kicad_algo.h>
28#include <template_fieldnames.h>
29#include <wx/button.h>
30#include <wx/checkbox.h>
31#include <wx/sizer.h>
32#include <confirm.h>
34#include <tool/tool_manager.h>
35#include <tools/pcb_actions.h>
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_GROUP _( "Place as group" )
41#define KEEP_ANNOTATIONS _( "Keep annotations" )
42
44 std::vector<LIB_ID>& aHistoryList ) :
45 DESIGN_BLOCK_PANE( aParent, aPreselect, aHistoryList )
46{
47 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
48 m_chooserPanel = new PANEL_DESIGN_BLOCK_CHOOSER( aParent, this, aHistoryList,
49 [aParent]()
50 {
51 aParent->GetToolManager()->RunAction(
53 },
54 aParent->GetToolManager()->GetTool<PCB_DESIGN_BLOCK_CONTROL>()
55 );
56 m_chooserPanel->SetPreviewWidget(new PCB_DESIGN_BLOCK_PREVIEW_WIDGET( m_chooserPanel->GetDetailsPanel(), aParent ) );
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_placeAsGroup = new wxCheckBox( this, wxID_ANY, PLACE_AS_GROUP );
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, &PCB_DESIGN_BLOCK_PANE::OnCheckBox, this );
74 m_placeAsGroup->Bind( wxEVT_CHECKBOX, &PCB_DESIGN_BLOCK_PANE::OnCheckBox, this );
75 m_keepAnnotations->Bind( wxEVT_CHECKBOX, &PCB_DESIGN_BLOCK_PANE::OnCheckBox, this );
76
77 cbSizer->Add( m_repeatedPlacement, 0, wxTOP | wxLEFT, 2 );
78 cbSizer->Add( m_placeAsGroup, 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
84 m_chooserPanel->FinishSetup();
85 Layout();
86
87 Bind( wxEVT_CHAR_HOOK, &PANEL_DESIGN_BLOCK_CHOOSER::OnChar, m_chooserPanel );
88}
89
90
92{
94 {
96 m_repeatedPlacement->SetToolTip( _( "Place copies of the design block on subsequent "
97 "clicks." ) );
98 }
99
100 if( m_placeAsGroup )
101 {
102 m_placeAsGroup->SetLabel( PLACE_AS_GROUP );
103 m_placeAsGroup->SetToolTip( _( "Place the design block as a group." ) );
104 }
105
107 {
109 m_keepAnnotations->SetToolTip( _( "Preserve reference designators in the source "
110 "layout. Otherwise, clear them." ) );
111 }
112}
113
114void PCB_DESIGN_BLOCK_PANE::OnCheckBox( wxCommandEvent& aEvent )
115{
116 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
117 {
118 cfg->m_DesignBlockChooserPanel.repeated_placement = m_repeatedPlacement->GetValue();
119 cfg->m_DesignBlockChooserPanel.place_as_group = m_placeAsGroup->GetValue();
120 cfg->m_DesignBlockChooserPanel.keep_annotations = m_keepAnnotations->GetValue();
121 }
122}
123
124
126{
127 if( PCBNEW_SETTINGS* cfg = dynamic_cast<PCBNEW_SETTINGS*>( Kiface().KifaceSettings() ) )
128 {
129 m_repeatedPlacement->SetValue( cfg->m_DesignBlockChooserPanel.repeated_placement );
130 m_placeAsGroup->SetValue( cfg->m_DesignBlockChooserPanel.place_as_group );
131 m_keepAnnotations->SetValue( cfg->m_DesignBlockChooserPanel.keep_annotations );
132 }
133}
134
135
137 m_cbRepeatedPlacement( nullptr ), m_cbPlaceAsGroup( nullptr ), m_cbKeepAnnotations( nullptr )
138{
139 wxASSERT( aSettings );
140 m_settings = aSettings;
141};
142
143
145{
146 m_settings->m_DesignBlockChooserPanel.repeated_placement = m_cbRepeatedPlacement->GetValue();
147 m_settings->m_DesignBlockChooserPanel.place_as_group = m_cbPlaceAsGroup->GetValue();
148 m_settings->m_DesignBlockChooserPanel.keep_annotations = m_cbKeepAnnotations->GetValue();
149}
150
151
152void FILEDLG_IMPORT_BOARD_CONTENTS::AddCustomControls( wxFileDialogCustomize& customizer )
153{
154 m_cbRepeatedPlacement = customizer.AddCheckBox( REPEATED_PLACEMENT );
155 m_cbRepeatedPlacement->SetValue( m_settings->m_DesignBlockChooserPanel.repeated_placement );
156 m_cbPlaceAsGroup = customizer.AddCheckBox( PLACE_AS_GROUP );
157 m_cbPlaceAsGroup->SetValue( m_settings->m_DesignBlockChooserPanel.place_as_group );
158 m_cbKeepAnnotations = customizer.AddCheckBox( KEEP_ANNOTATIONS );
159 m_cbKeepAnnotations->SetValue( m_settings->m_DesignBlockChooserPanel.keep_annotations );
160}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
DESIGN_BLOCK_PANE(EDA_DRAW_FRAME *aParent, const LIB_ID *aPreselect, std::vector< LIB_ID > &aHistoryList)
PANEL_DESIGN_BLOCK_CHOOSER * m_chooserPanel
FILEDLG_IMPORT_BOARD_CONTENTS(PCBNEW_SETTINGS *aSettings)
wxFileDialogCheckBox * m_cbRepeatedPlacement
wxFileDialogCheckBox * m_cbPlaceAsGroup
void AddCustomControls(wxFileDialogCustomize &customizer) override
wxFileDialogCheckBox * m_cbKeepAnnotations
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
static TOOL_ACTION placeDesignBlock
void OnCheckBox(wxCommandEvent &aEvent)
PCB_DESIGN_BLOCK_PANE(PCB_EDIT_FRAME *aParent, const LIB_ID *aPreselect, std::vector< LIB_ID > &aHistoryList)
The main frame for Pcbnew.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
This file is part of the common library.
#define _(s)
#define KEEP_ANNOTATIONS
#define REPEATED_PLACEMENT
#define PLACE_AS_GROUP
Definition of file extensions used in Kicad.