KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_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 <kiface_base.h>
29#include <sch_edit_frame.h>
30#include <core/kicad_algo.h>
31#include <template_fieldnames.h>
32#include <wx/button.h>
33#include <wx/checkbox.h>
34#include <wx/sizer.h>
35#include <sch_actions.h>
36#include <tool/tool_manager.h>
38
39
40// Do not make these static wxStrings; they need to respond to language changes
41#define REPEATED_PLACEMENT _( "Place repeated copies" )
42#define PLACE_AS_SHEET _( "Place as sheet" )
43#define PLACE_AS_GROUP _( "Place as group" )
44#define KEEP_ANNOTATIONS _( "Keep annotations" )
45
47 std::vector<LIB_ID>& aHistoryList ) :
48 DESIGN_BLOCK_PANE( aParent, aPreselect, aHistoryList )
49{
50 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
51
52 m_chooserPanel = new PANEL_DESIGN_BLOCK_CHOOSER( aParent, this, aHistoryList,
53 [aParent]()
54 {
55 aParent->GetToolManager()->RunAction(
57 },
58 aParent->GetToolManager()->GetTool<SCH_DESIGN_BLOCK_CONTROL>()
59 );
60 // Use the same draw engine type as the one used in parent frame m_frame
64 sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
65
66 if( aPreselect && aPreselect->IsValid() )
67 m_chooserPanel->SetPreselect( *aPreselect );
68
69 SetName( wxT( "Design Blocks" ) );
70
71 wxBoxSizer* cbSizer = new wxBoxSizer( wxVERTICAL );
72
73 m_repeatedPlacement = new wxCheckBox( this, wxID_ANY, REPEATED_PLACEMENT );
74 m_placeAsGroup = new wxCheckBox( this, wxID_ANY, PLACE_AS_GROUP );
75 m_placeAsSheet = new wxCheckBox( this, wxID_ANY, PLACE_AS_SHEET );
76 m_keepAnnotations = new wxCheckBox( this, wxID_ANY, KEEP_ANNOTATIONS );
79
80 // Set all checkbox handlers to the same function
81 m_repeatedPlacement->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
82 m_placeAsGroup->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
83 m_placeAsSheet->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
84 m_keepAnnotations->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
85
86 cbSizer->Add( m_repeatedPlacement, 0, wxTOP | wxLEFT, 2 );
87 cbSizer->Add( m_placeAsGroup, 0, wxTOP | wxLEFT, 2 );
88 cbSizer->Add( m_placeAsSheet, 0, wxTOP | wxLEFT, 2 );
89 cbSizer->Add( m_keepAnnotations, 0, wxTOP | wxLEFT | wxBOTTOM, 2 );
90
91 sizer->Add( cbSizer, 0, wxEXPAND, 5 );
92 SetSizer( sizer );
93
95 Layout();
96
97 Bind( wxEVT_CHAR_HOOK, &PANEL_DESIGN_BLOCK_CHOOSER::OnChar, m_chooserPanel );
98}
99
100
102{
104 {
106 m_repeatedPlacement->SetToolTip( _( "Place copies of the design block on subsequent "
107 "clicks." ) );
108 }
109
110 if( m_placeAsGroup )
111 {
112 m_placeAsGroup->SetLabel( PLACE_AS_GROUP );
113 m_placeAsGroup->SetToolTip( _( "Place the design block as a group." ) );
114 }
115
116 if( m_placeAsSheet )
117 {
118 m_placeAsSheet->SetLabel( PLACE_AS_SHEET );
119 m_placeAsSheet->SetToolTip( _( "Place the design block as a new sheet." ) );
120 }
121
123 {
125 m_keepAnnotations->SetToolTip( _( "Preserve reference designators in the source "
126 "schematic. Otherwise, clear then reannotate according "
127 "to settings." ) );
128 }
129}
130
131
132void SCH_DESIGN_BLOCK_PANE::OnCheckBox( wxCommandEvent& aEvent )
133{
134 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
135 {
136 cfg->m_DesignBlockChooserPanel.repeated_placement = m_repeatedPlacement->GetValue();
137 cfg->m_DesignBlockChooserPanel.place_as_group = m_placeAsGroup->GetValue();
138 cfg->m_DesignBlockChooserPanel.place_as_sheet = m_placeAsSheet->GetValue();
139 cfg->m_DesignBlockChooserPanel.keep_annotations = m_keepAnnotations->GetValue();
140 }
141}
142
143
145{
146 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
147 {
148 m_repeatedPlacement->SetValue( cfg->m_DesignBlockChooserPanel.repeated_placement );
149 m_placeAsGroup->SetValue( cfg->m_DesignBlockChooserPanel.place_as_group );
150 m_placeAsSheet->SetValue( cfg->m_DesignBlockChooserPanel.place_as_sheet );
151 m_keepAnnotations->SetValue( cfg->m_DesignBlockChooserPanel.keep_annotations );
152 }
153}
154
155
157 m_cbRepeatedPlacement( nullptr ), m_cbPlaceAsGroup( nullptr ), m_cbPlaceAsSheet( nullptr ),
158 m_cbKeepAnnotations( nullptr )
159{
160 wxASSERT( aSettings );
161 m_settings = aSettings;
162};
163
164
166{
171}
172
173
174void FILEDLG_IMPORT_SHEET_CONTENTS::AddCustomControls( wxFileDialogCustomize& customizer )
175{
176 m_cbRepeatedPlacement = customizer.AddCheckBox( REPEATED_PLACEMENT );
178 m_cbPlaceAsGroup = customizer.AddCheckBox( PLACE_AS_GROUP );
180 m_cbPlaceAsSheet = customizer.AddCheckBox( PLACE_AS_SHEET );
182 m_cbKeepAnnotations = customizer.AddCheckBox( KEEP_ANNOTATIONS );
184}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
PANEL_DESIGN_BLOCK_CHOOSER m_DesignBlockChooserPanel
Definition: app_settings.h:216
PANEL_DESIGN_BLOCK_CHOOSER * m_chooserPanel
EDA_DRAW_FRAME * m_frame
virtual EDA_DRAW_PANEL_GAL * GetCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
wxFileDialogCheckBox * m_cbRepeatedPlacement
wxFileDialogCheckBox * m_cbPlaceAsSheet
wxFileDialogCheckBox * m_cbKeepAnnotations
void AddCustomControls(wxFileDialogCustomize &customizer) override
FILEDLG_IMPORT_SHEET_CONTENTS(EESCHEMA_SETTINGS *aSettings)
wxFileDialogCheckBox * m_cbPlaceAsGroup
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: sch_actions.h:69
void setLabelsAndTooltips() override
void OnCheckBox(wxCommandEvent &aEvent)
SCH_DESIGN_BLOCK_PANE(SCH_EDIT_FRAME *aParent, const LIB_ID *aPreselect, std::vector< LIB_ID > &aHistoryList)
Schematic editor (Eeschema) main window.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
#define _(s)
#define KEEP_ANNOTATIONS
#define REPEATED_PLACEMENT
#define PLACE_AS_SHEET
#define PLACE_AS_GROUP