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 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 <class_board.h>
28 #include <confirm.h>
29 
30 #include <dialog_import_settings.h>
31 
32 
33 wxString DIALOG_IMPORT_SETTINGS::m_filePath; // remember for session
34 
35 
37  DIALOG_IMPORT_SETTINGS_BASE( aParent ),
38  m_frame( aFrame )
39 {
40  wxSize sizeNeeded;
41 
42  m_browseButton->SetBitmap( KiBitmap( folder_xpm ) );
43 
44  // Button created in wxFormBuilder is an "OK" button. Change label here
45  m_sdbSizer1OK->SetLabel( _( "Import Settings" ) );
46 
47  // Disable "Import Settings" button until user selects at least one import option
48  m_sdbSizer1OK->Enable( false );
49 
50  // Make sure "Select All" button is big enough to hold "Deselect All"
51  m_selectAllButton->SetLabel( _( "Deselect All" ) ); // Change the text temporarily
52  sizeNeeded = m_selectAllButton->GetBestSize(); // Get control to tell us the width required
53  m_selectAllButton->SetLabel( _( "Select All" ) ); // Restore "Select All" as default text
54  sizeNeeded.y = m_selectAllButton->GetSize().y; // Keep the height unchanged
55  m_selectAllButton->SetMinSize( sizeNeeded ); // Set control to the required size
56 
57  m_buttonsSizer->Layout();
58 
59  m_sdbSizer1OK->SetDefault();
60 
61  m_showSelectAllOnBtn = true; // Store state to toggle message/usage of "Select All" button
62 }
63 
64 
65 void DIALOG_IMPORT_SETTINGS::OnCheckboxClicked( wxCommandEvent& event )
66 {
67  bool importButtonEnabled = UpdateImportSettingsButton();
68 
69  // If clicking this checkbox clears the last of the import selection checkboxes,
70  // then make sure the "Select All" button is actually going to select all.
71 
72  if( !importButtonEnabled )
73  {
74  m_showSelectAllOnBtn = true;
76  }
77 }
78 
79 
81 {
82  // Enable "Import Settings" button if at least one import option is selected
83  bool buttonEnableState = ( m_LayersOpt->IsChecked() || m_MaskAndPasteOpt->IsChecked()
84  || m_ConstraintsOpt->IsChecked() || m_NetclassesOpt->IsChecked()
85  || m_SeveritiesOpt->IsChecked() || m_TextAndGraphicsOpt->IsChecked()
86  || m_TracksAndViasOpt->IsChecked() );
87 
88  m_sdbSizer1OK->Enable( buttonEnableState );
89 
90  return buttonEnableState;
91 }
92 
93 
95 {
96  // Update message on button
98  m_selectAllButton->SetLabel( _( "Select All" ) );
99  else
100  m_selectAllButton->SetLabel( _( "Deselect All" ) );
101 }
102 
103 
105 {
106  m_filePathCtrl->SetValue( m_filePath );
107  return true;
108 }
109 
110 
111 void DIALOG_IMPORT_SETTINGS::OnBrowseClicked( wxCommandEvent& event )
112 {
113  wxFileName fn = m_frame->GetBoard()->GetFileName();
114  fn.SetExt( ProjectFileExtension );
115 
116  wxFileDialog dlg( this, _( "Import Settings From" ), fn.GetPath(), fn.GetFullName(),
117  PcbFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
118 
119  if( dlg.ShowModal() == wxID_OK )
120  m_filePathCtrl->SetValue( dlg.GetPath() );
121 }
122 
123 
125 {
126  if( !wxFileExists( m_filePathCtrl->GetValue() ) )
127  {
128  DisplayError( this, wxString::Format( _( "File not found." ) ) );
129  m_filePathCtrl->SetFocus();
130  return false;
131  }
132 
133  m_filePath = m_filePathCtrl->GetValue();
134  return true;
135 }
136 
137 
138 void DIALOG_IMPORT_SETTINGS::OnSelectAll( wxCommandEvent& event )
139 {
140  // Select or deselect all options based on internal flag
141  m_LayersOpt->SetValue( m_showSelectAllOnBtn );
148 
149  // Ensure "Import Settings" button state is enabled as appropriate
151 
152  // Toggle whether button selects or deselects all.
155 }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
const BITMAP_OPAQUE folder_xpm[1]
Definition: folder.cpp:20
bool UpdateImportSettingsButton()
Enables/Disables "Import Settings" button.
This file is part of the common library.
const std::string ProjectFileExtension
void OnCheckboxClicked(wxCommandEvent &event) override
const wxString & GetFileName() const
Definition: class_board.h:255
void OnSelectAll(wxCommandEvent &event) override
wxBitmap KiBitmap(BITMAP_DEF aBitmap)
Construct a wxBitmap from a memory record, held in a BITMAP_DEF.
Definition: bitmap.cpp:80
DIALOG_IMPORT_SETTINGS(wxWindow *aParent, PCB_EDIT_FRAME *aFrame)
Definition of file extensions used in Kicad.
Class DIALOG_IMPORT_SETTINGS_BASE.
void UpdateSelectAllButton()
Update "Select All" button label as appropriate.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
#define _(s)
Definition: 3d_actions.cpp:33
PCB_EDIT_FRAME is the main frame for Pcbnew.
void OnBrowseClicked(wxCommandEvent &event) override
wxString PcbFileWildcard()
BOARD * GetBoard() const
bool m_showSelectAllOnBtn
Stores state used to toggle button between "Select All" and "Deselect All".