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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <design_block.h>
24#include <kiface_base.h>
25#include <sch_edit_frame.h>
26#include <core/kicad_algo.h>
27#include <template_fieldnames.h>
28#include <wx/button.h>
29#include <wx/checkbox.h>
30#include <wx/sizer.h>
31#include <sch_actions.h>
32#include <tool/tool_manager.h>
34
35
36// Do not make these static wxStrings; they need to respond to language changes
37#define REPEATED_PLACEMENT _( "Place repeated copies" )
38#define PLACE_AS_SHEET _( "Place as sheet" )
39#define PLACE_AS_GROUP _( "Place as group" )
40#define KEEP_ANNOTATIONS _( "Keep annotations" )
41
43 std::vector<LIB_ID>& aHistoryList ) :
44 DESIGN_BLOCK_PANE( aParent, aPreselect, aHistoryList )
45{
46 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
47
48 m_chooserPanel = new PANEL_DESIGN_BLOCK_CHOOSER( aParent, this, aHistoryList,
49 [aParent]()
50 {
51 aParent->GetToolManager()->RunAction(
53 },
54 aParent->GetToolManager()->GetTool<SCH_DESIGN_BLOCK_CONTROL>()
55 );
56 // Use the same draw engine type as the one used in parent frame m_frame
57 EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = m_frame->GetCanvas()->GetBackend();
58 m_chooserPanel->SetPreviewWidget(
59 new SCH_DESIGN_BLOCK_PREVIEW_WIDGET( m_chooserPanel->GetDetailsPanel(), canvasType, true ) );
60 sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
61
62 if( aPreselect && aPreselect->IsValid() )
63 m_chooserPanel->SetPreselect( *aPreselect );
64
65 SetName( wxT( "Design Blocks" ) );
66
67 wxBoxSizer* cbSizer = new wxBoxSizer( wxVERTICAL );
68
69 m_repeatedPlacement = new wxCheckBox( this, wxID_ANY, REPEATED_PLACEMENT );
70 m_placeAsGroup = new wxCheckBox( this, wxID_ANY, PLACE_AS_GROUP );
71 m_placeAsSheet = new wxCheckBox( this, wxID_ANY, PLACE_AS_SHEET );
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, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
78 m_placeAsGroup->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
79 m_placeAsSheet->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
80 m_keepAnnotations->Bind( wxEVT_CHECKBOX, &SCH_DESIGN_BLOCK_PANE::OnCheckBox, this );
81
82 cbSizer->Add( m_repeatedPlacement, 0, wxTOP | wxLEFT, 2 );
83 cbSizer->Add( m_placeAsGroup, 0, wxTOP | wxLEFT, 2 );
84 cbSizer->Add( m_placeAsSheet, 0, wxTOP | wxLEFT, 2 );
85 cbSizer->Add( m_keepAnnotations, 0, wxTOP | wxLEFT | wxBOTTOM, 2 );
86
87 sizer->Add( cbSizer, 0, wxEXPAND, 5 );
88 SetSizer( sizer );
89
90 m_chooserPanel->FinishSetup();
91 Layout();
92
93 Bind( wxEVT_CHAR_HOOK, &PANEL_DESIGN_BLOCK_CHOOSER::OnChar, m_chooserPanel );
94}
95
96
98{
100 {
102 m_repeatedPlacement->SetToolTip( _( "Place copies of the design block on subsequent "
103 "clicks." ) );
104 }
105
106 if( m_placeAsGroup )
107 {
108 m_placeAsGroup->SetLabel( PLACE_AS_GROUP );
109 m_placeAsGroup->SetToolTip( _( "Place the design block as a group." ) );
110 }
111
112 if( m_placeAsSheet )
113 {
114 m_placeAsSheet->SetLabel( PLACE_AS_SHEET );
115 m_placeAsSheet->SetToolTip( _( "Place the design block as a new sheet." ) );
116 }
117
119 {
121 m_keepAnnotations->SetToolTip( _( "Preserve reference designators in the source "
122 "schematic. Otherwise, clear then reannotate according "
123 "to settings." ) );
124 }
125}
126
127
128void SCH_DESIGN_BLOCK_PANE::OnCheckBox( wxCommandEvent& aEvent )
129{
130 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
131 {
132 cfg->m_DesignBlockChooserPanel.repeated_placement = m_repeatedPlacement->GetValue();
133 cfg->m_DesignBlockChooserPanel.place_as_group = m_placeAsGroup->GetValue();
134 cfg->m_DesignBlockChooserPanel.place_as_sheet = m_placeAsSheet->GetValue();
135 cfg->m_DesignBlockChooserPanel.keep_annotations = m_keepAnnotations->GetValue();
136 }
137}
138
139
141{
142 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
143 {
144 m_repeatedPlacement->SetValue( cfg->m_DesignBlockChooserPanel.repeated_placement );
145 m_placeAsGroup->SetValue( cfg->m_DesignBlockChooserPanel.place_as_group );
146 m_placeAsSheet->SetValue( cfg->m_DesignBlockChooserPanel.place_as_sheet );
147 m_keepAnnotations->SetValue( cfg->m_DesignBlockChooserPanel.keep_annotations );
148 }
149}
150
151
153{
154 // Project change will blow up the default project; re-create any active preview canvas
155 m_chooserPanel->GetPreviewWidget()->DisplayDesignBlock( GetSelectedDesignBlock( true, true ) );
156}
157
158
160 m_cbRepeatedPlacement( nullptr ), m_cbPlaceAsGroup( nullptr ), m_cbPlaceAsSheet( nullptr ),
161 m_cbKeepAnnotations( nullptr )
162{
163 wxASSERT( aSettings );
164 m_settings = aSettings;
165};
166
167
169{
170 m_settings->m_DesignBlockChooserPanel.repeated_placement = m_cbRepeatedPlacement->GetValue();
171 m_settings->m_DesignBlockChooserPanel.place_as_group = m_cbPlaceAsGroup->GetValue();
172 m_settings->m_DesignBlockChooserPanel.place_as_sheet = m_cbPlaceAsSheet->GetValue();
173 m_settings->m_DesignBlockChooserPanel.keep_annotations = m_cbKeepAnnotations->GetValue();
174}
175
176
177void FILEDLG_IMPORT_SHEET_CONTENTS::AddCustomControls( wxFileDialogCustomize& customizer )
178{
179#ifdef __WXMAC__
180 customizer.AddStaticText( wxT( "\n\n" ) ); // Increase height of static box
181#endif
182
183 m_cbRepeatedPlacement = customizer.AddCheckBox( REPEATED_PLACEMENT );
184 m_cbRepeatedPlacement->SetValue( m_settings->m_DesignBlockChooserPanel.repeated_placement );
185 m_cbPlaceAsGroup = customizer.AddCheckBox( PLACE_AS_GROUP );
186 m_cbPlaceAsGroup->SetValue( m_settings->m_DesignBlockChooserPanel.place_as_group );
187 m_cbPlaceAsSheet = customizer.AddCheckBox( PLACE_AS_SHEET );
188 m_cbPlaceAsSheet->SetValue( m_settings->m_DesignBlockChooserPanel.place_as_sheet );
189 m_cbKeepAnnotations = customizer.AddCheckBox( KEEP_ANNOTATIONS );
190 m_cbKeepAnnotations->SetValue( m_settings->m_DesignBlockChooserPanel.keep_annotations );
191}
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
EDA_DRAW_FRAME * m_frame
DESIGN_BLOCK * GetSelectedDesignBlock(bool aUseCacheLib, bool aShowErrorMsg)
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:45
bool IsValid() const
Check if this LID_ID is valid.
Definition lib_id.h:168
static TOOL_ACTION placeDesignBlock
Definition sch_actions.h:65
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.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
#define _(s)
#define KEEP_ANNOTATIONS
#define REPEATED_PLACEMENT
#define PLACE_AS_SHEET
#define PLACE_AS_GROUP