KiCad PCB EDA Suite
dialog_import_settings.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) 2018-2022 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 <bitmaps.h>
25#include <pcb_edit_frame.h>
26#include <board.h>
28#include <confirm.h>
30#include <wx/filedlg.h>
31
33
34
35wxString DIALOG_IMPORT_SETTINGS::m_filePath; // remember for session
36
37
40 m_frame( aFrame )
41{
42 wxSize sizeNeeded;
43
45
46 // Make sure "Select All" button is big enough to hold "Deselect All"
47 m_selectAllButton->SetLabel( _( "Deselect All" ) ); // Change the text temporarily
48 sizeNeeded = m_selectAllButton->GetBestSize(); // Get control to tell us the width required
49 m_selectAllButton->SetLabel( _( "Select All" ) ); // Restore "Select All" as default text
50 sizeNeeded.y = m_selectAllButton->GetSize().y; // Keep the height unchanged
51 m_selectAllButton->SetMinSize( sizeNeeded ); // Set control to the required size
52
53 SetupStandardButtons( { { wxID_OK, _( "Import Settings" ) } } );
54
55 // Disable "Import Settings" button until user selects at least one import option
56 m_sdbSizer1OK->Enable( false );
57
58 m_buttonsSizer->Layout();
59
60 m_showSelectAllOnBtn = true; // Store state to toggle message/usage of "Select All" button
61}
62
63
64void DIALOG_IMPORT_SETTINGS::OnCheckboxClicked( wxCommandEvent& event )
65{
66 bool importButtonEnabled = UpdateImportSettingsButton();
67
68 // If clicking this checkbox clears the last of the import selection checkboxes,
69 // then make sure the "Select All" button is actually going to select all.
70
71 if( !importButtonEnabled )
72 {
75 }
76}
77
78
80{
81 // Enable "Import Settings" button if at least one import option is selected
82 bool buttonEnableState = ( m_LayersOpt->IsChecked() || m_MaskAndPasteOpt->IsChecked()
83 || m_ConstraintsOpt->IsChecked() || m_NetclassesOpt->IsChecked()
84 || m_SeveritiesOpt->IsChecked() || m_TextAndGraphicsOpt->IsChecked()
85 || m_FormattingOpt->IsChecked() || m_TracksAndViasOpt->IsChecked() );
86
87 m_sdbSizer1OK->Enable( buttonEnableState );
88
89 return buttonEnableState;
90}
91
92
94{
95 // Update message on button
97 m_selectAllButton->SetLabel( _( "Select All" ) );
98 else
99 m_selectAllButton->SetLabel( _( "Deselect All" ) );
100}
101
102
104{
105 m_filePathCtrl->SetValue( m_filePath );
106 return true;
107}
108
109
110void DIALOG_IMPORT_SETTINGS::OnBrowseClicked( wxCommandEvent& event )
111{
112 wxFileName fn = m_frame->GetBoard()->GetFileName();
113
114 wxFileDialog dlg( this, _( "Import Settings From" ), fn.GetPath(), fn.GetFullName(),
115 PcbFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
116
117 if( dlg.ShowModal() == wxID_OK )
118 m_filePathCtrl->SetValue( dlg.GetPath() );
119}
120
121
123{
124 if( !wxFileExists( m_filePathCtrl->GetValue() ) )
125 {
126 DisplayError( this, wxString::Format( _( "File not found." ) ) );
127 m_filePathCtrl->SetFocus();
128 return false;
129 }
130
131 m_filePath = m_filePathCtrl->GetValue();
132 return true;
133}
134
135
136void DIALOG_IMPORT_SETTINGS::OnSelectAll( wxCommandEvent& event )
137{
138 // Select or deselect all options based on internal flag
147
148 // Ensure "Import Settings" button state is enabled as appropriate
150
151 // Toggle whether button selects or deselects all.
154}
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
@ small_folder
const wxString & GetFileName() const
Definition: board.h:302
Class DIALOG_IMPORT_SETTINGS_BASE.
void OnSelectAll(wxCommandEvent &event) override
bool UpdateImportSettingsButton()
Enable or disable the "Import Settings" button.
DIALOG_IMPORT_SETTINGS(wxWindow *aParent, PCB_EDIT_FRAME *aFrame)
void OnCheckboxClicked(wxCommandEvent &event) override
void OnBrowseClicked(wxCommandEvent &event) override
void UpdateSelectAllButton()
Update "Select All" button label as appropriate.
bool m_showSelectAllOnBtn
Store state used to toggle button between "Select All" and "Deselect All".
void SetupStandardButtons(std::map< int, wxString > aLabels={})
BOARD * GetBoard() const
The main frame for Pcbnew.
void SetBitmap(const wxBitmap &aBmp)
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:300
This file is part of the common library.
#define _(s)
wxString PcbFileWildcard()
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Definition of file extensions used in Kicad.