KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 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 <bitmaps.h>
21#include <pcb_edit_frame.h>
22#include <board.h>
24#include <confirm.h>
26#include <wx/filedlg.h>
27#include <kiplatform/ui.h>
28
30
31
32wxString DIALOG_IMPORT_SETTINGS::m_filePath; // remember for session
33
34
37 m_frame( aFrame )
38{
39 wxSize sizeNeeded;
40
42
43 // Make sure "Select All" button is big enough to hold "Deselect All"
44 m_selectAllButton->SetLabel( _( "Deselect All" ) ); // Change the text temporarily
45 sizeNeeded = m_selectAllButton->GetBestSize(); // Get control to tell us the width required
46 m_selectAllButton->SetLabel( _( "Select All" ) ); // Restore "Select All" as default text
47 sizeNeeded.y = m_selectAllButton->GetSize().y; // Keep the height unchanged
48 m_selectAllButton->SetMinSize( sizeNeeded ); // Set control to the required size
49
50 SetupStandardButtons( { { wxID_OK, _( "Import Settings" ) } } );
51
52 // Disable "Import Settings" button until user selects at least one import option
53 m_sdbSizer1OK->Enable( false );
54
55 m_buttonsSizer->Layout();
56
57 m_showSelectAllOnBtn = true; // Store state to toggle message/usage of "Select All" button
58}
59
60
61void DIALOG_IMPORT_SETTINGS::OnCheckboxClicked( wxCommandEvent& event )
62{
63 bool importButtonEnabled = UpdateImportSettingsButton();
64
65 // If clicking this checkbox clears the last of the import selection checkboxes,
66 // then make sure the "Select All" button is actually going to select all.
67
68 if( !importButtonEnabled )
69 {
72 }
73}
74
75
77{
78 // Enable "Import Settings" button if at least one import option is selected
79 bool buttonEnableState =
80 ( m_LayersOpt->IsChecked() || m_MaskAndPasteOpt->IsChecked() || m_ConstraintsOpt->IsChecked()
81 || m_NetclassesOpt->IsChecked() || m_SeveritiesOpt->IsChecked() || m_TextAndGraphicsOpt->IsChecked()
82 || m_FormattingOpt->IsChecked() || m_TracksAndViasOpt->IsChecked() || m_TuningPatternsOpt->IsChecked()
83 || m_CustomRulesOpt->IsChecked() || m_ComponentClassesOpt->IsChecked() || m_TuningProfilesOpt->IsChecked()
84 || m_TeardropsOpt->IsChecked() || m_ZonesOpt->IsChecked() || m_ZoneHatchingOffsetsOpt->IsChecked() );
85
86 m_sdbSizer1OK->Enable( buttonEnableState );
87
88 return buttonEnableState;
89}
90
91
93{
94 // Update message on button
96 m_selectAllButton->SetLabel( _( "Select All" ) );
97 else
98 m_selectAllButton->SetLabel( _( "Deselect All" ) );
99}
100
101
103{
104 m_filePathCtrl->SetValue( m_filePath );
105 return true;
106}
107
108
109void DIALOG_IMPORT_SETTINGS::OnBrowseClicked( wxCommandEvent& event )
110{
111 // Honor a path the user has already entered; fall back to the board's location
112 // when the field is empty or its directory no longer exists.
113 wxString currentPath = m_filePathCtrl->GetValue();
114 wxFileName fn( currentPath.IsEmpty() ? m_frame->GetBoard()->GetFileName() : currentPath );
115
116 if( !fn.DirExists() )
117 fn = m_frame->GetBoard()->GetFileName();
118
119 wxFileDialog dlg( this, _( "Import Settings From" ), fn.GetPath(), fn.GetFullName(),
121 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
122
124
125 if( dlg.ShowModal() == wxID_OK )
126 m_filePathCtrl->SetValue( dlg.GetPath() );
127}
128
129
131{
132 if( !wxFileExists( m_filePathCtrl->GetValue() ) )
133 {
134 DisplayError( this, wxString::Format( _( "File not found." ) ) );
135 m_filePathCtrl->SetFocus();
136 return false;
137 }
138
139 m_filePath = m_filePathCtrl->GetValue();
140 return true;
141}
142
143
144void DIALOG_IMPORT_SETTINGS::OnSelectAll( wxCommandEvent& event )
145{
146 // Select or deselect all options based on internal flag
153 m_ZonesOpt->SetValue( m_showSelectAllOnBtn );
162
163 // Ensure "Import Settings" button state is enabled as appropriate
165
166 // Toggle whether button selects or deselects all.
169}
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
DIALOG_IMPORT_SETTINGS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Import Settings"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
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={})
The main frame for Pcbnew.
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
#define _(s)
static wxString PcbFileWildcard()
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:448
Definition of file extensions used in Kicad.