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 (C) 2024 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 <eeschema_settings.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 <confirm.h>
37#include <ee_actions.h>
38#include <tool/tool_manager.h>
39
40static const wxString REPEATED_PLACEMENT = _( "Place repeated copies" );
41static const wxString PLACE_AS_SHEET = _( "Place as sheet" );
42static const wxString KEEP_ANNOTATIONS = _( "Keep annotations" );
43
45 std::vector<LIB_ID>& aHistoryList ) :
46 WX_PANEL( aParent ), m_frame( aParent )
47{
48 wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
49 m_chooserPanel = new PANEL_DESIGN_BLOCK_CHOOSER( aParent, this, aHistoryList,
50 [aParent]()
51 {
52 aParent->GetToolManager()->RunAction(
54 } );
55 sizer->Add( m_chooserPanel, 1, wxEXPAND, 5 );
56
57 if( aPreselect && aPreselect->IsValid() )
58 m_chooserPanel->SetPreselect( *aPreselect );
59
60 SetName( wxT( "Design Blocks" ) );
61
62 wxBoxSizer* cbSizer = new wxBoxSizer( wxVERTICAL );
63
64 m_repeatedPlacement = new wxCheckBox( this, wxID_ANY, REPEATED_PLACEMENT );
65 m_repeatedPlacement->SetToolTip( _( "Place copies of the design block on subsequent clicks." ) );
66
67 m_placeAsSheet = new wxCheckBox( this, wxID_ANY, PLACE_AS_SHEET );
68 m_placeAsSheet->SetToolTip( _( "Place the design block as a new sheet." ) );
69
70 m_keepAnnotations = new wxCheckBox( this, wxID_ANY, KEEP_ANNOTATIONS );
71 m_keepAnnotations->SetToolTip( _( "Preserve reference designators in the source schematic. "
72 "Otherwise, clear then reannotate according to settings." ) );
74
75 // Set all checkbox handlers to the same function
76 m_repeatedPlacement->Bind( wxEVT_CHECKBOX, &DESIGN_BLOCK_PANE::OnCheckBox, this );
77 m_placeAsSheet->Bind( wxEVT_CHECKBOX, &DESIGN_BLOCK_PANE::OnCheckBox, this );
78 m_keepAnnotations->Bind( wxEVT_CHECKBOX, &DESIGN_BLOCK_PANE::OnCheckBox, this );
79
80 cbSizer->Add( m_repeatedPlacement, 0, wxLEFT, 5 );
81 cbSizer->Add( m_placeAsSheet, 0, wxLEFT, 5 );
82 cbSizer->Add( m_keepAnnotations, 0, wxLEFT, 5 );
83
84 sizer->Add( cbSizer, 0, wxEXPAND | wxLEFT, 5 );
85 SetSizer( sizer );
86
88 Layout();
89
90 Bind( wxEVT_CHAR_HOOK, &PANEL_DESIGN_BLOCK_CHOOSER::OnChar, m_chooserPanel );
91}
92
93
94void DESIGN_BLOCK_PANE::OnCheckBox( wxCommandEvent& aEvent )
95{
96 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
97 {
98 cfg->m_DesignBlockChooserPanel.repeated_placement = m_repeatedPlacement->GetValue();
99 cfg->m_DesignBlockChooserPanel.place_as_sheet = m_placeAsSheet->GetValue();
100 cfg->m_DesignBlockChooserPanel.keep_annotations = m_keepAnnotations->GetValue();
101 }
102}
103
104
106{
107 if( EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( Kiface().KifaceSettings() ) )
108 {
109 m_repeatedPlacement->SetValue( cfg->m_DesignBlockChooserPanel.repeated_placement );
110 m_placeAsSheet->SetValue( cfg->m_DesignBlockChooserPanel.place_as_sheet );
111 m_keepAnnotations->SetValue( cfg->m_DesignBlockChooserPanel.keep_annotations );
112 }
113}
114
115
117{
118 return m_chooserPanel->GetSelectedLibId( aUnit );
119}
120
121
123{
124 m_chooserPanel->SelectLibId( aLibId );
125}
126
127
129{
131}
132
133
135{
136 wxASSERT( aSettings );
137 m_settings = aSettings;
138};
139
140
142{
146}
147
148
149void FILEDLG_IMPORT_SHEET_CONTENTS::AddCustomControls( wxFileDialogCustomize& customizer )
150{
151 m_cbRepeatedPlacement = customizer.AddCheckBox( REPEATED_PLACEMENT );
153 m_cbPlaceAsSheet = customizer.AddCheckBox( PLACE_AS_SHEET );
155 m_cbKeepAnnotations = customizer.AddCheckBox( KEEP_ANNOTATIONS );
157}
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
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
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
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.
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
This file is part of the common library.
static const wxString KEEP_ANNOTATIONS
static const wxString REPEATED_PLACEMENT
static const wxString PLACE_AS_SHEET
#define _(s)
Definition of file extensions used in Kicad.