You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
5.3 KiB

  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. #include <bitmaps.h>
  24. #include <pcb_edit_frame.h>
  25. #include <board.h>
  26. #include <wildcards_and_files_ext.h>
  27. #include <confirm.h>
  28. #include <wx/filedlg.h>
  29. #include <dialog_import_settings.h>
  30. wxString DIALOG_IMPORT_SETTINGS::m_filePath; // remember for session
  31. DIALOG_IMPORT_SETTINGS::DIALOG_IMPORT_SETTINGS( wxWindow* aParent, PCB_EDIT_FRAME* aFrame ) :
  32. DIALOG_IMPORT_SETTINGS_BASE( aParent ),
  33. m_frame( aFrame )
  34. {
  35. wxSize sizeNeeded;
  36. m_browseButton->SetBitmap( KiBitmap( BITMAPS::small_folder ) );
  37. // Make sure "Select All" button is big enough to hold "Deselect All"
  38. m_selectAllButton->SetLabel( _( "Deselect All" ) ); // Change the text temporarily
  39. sizeNeeded = m_selectAllButton->GetBestSize(); // Get control to tell us the width required
  40. m_selectAllButton->SetLabel( _( "Select All" ) ); // Restore "Select All" as default text
  41. sizeNeeded.y = m_selectAllButton->GetSize().y; // Keep the height unchanged
  42. m_selectAllButton->SetMinSize( sizeNeeded ); // Set control to the required size
  43. SetupStandardButtons( { { wxID_OK, _( "Import Settings" ) } } );
  44. // Disable "Import Settings" button until user selects at least one import option
  45. m_sdbSizer1OK->Enable( false );
  46. m_buttonsSizer->Layout();
  47. m_showSelectAllOnBtn = true; // Store state to toggle message/usage of "Select All" button
  48. }
  49. void DIALOG_IMPORT_SETTINGS::OnCheckboxClicked( wxCommandEvent& event )
  50. {
  51. bool importButtonEnabled = UpdateImportSettingsButton();
  52. // If clicking this checkbox clears the last of the import selection checkboxes,
  53. // then make sure the "Select All" button is actually going to select all.
  54. if( !importButtonEnabled )
  55. {
  56. m_showSelectAllOnBtn = true;
  57. UpdateSelectAllButton();
  58. }
  59. }
  60. bool DIALOG_IMPORT_SETTINGS::UpdateImportSettingsButton()
  61. {
  62. // Enable "Import Settings" button if at least one import option is selected
  63. bool buttonEnableState = ( m_LayersOpt->IsChecked() || m_MaskAndPasteOpt->IsChecked()
  64. || m_ConstraintsOpt->IsChecked() || m_NetclassesOpt->IsChecked()
  65. || m_SeveritiesOpt->IsChecked() || m_TextAndGraphicsOpt->IsChecked()
  66. || m_FormattingOpt->IsChecked() || m_TracksAndViasOpt->IsChecked() );
  67. m_sdbSizer1OK->Enable( buttonEnableState );
  68. return buttonEnableState;
  69. }
  70. void DIALOG_IMPORT_SETTINGS::UpdateSelectAllButton()
  71. {
  72. // Update message on button
  73. if( m_showSelectAllOnBtn )
  74. m_selectAllButton->SetLabel( _( "Select All" ) );
  75. else
  76. m_selectAllButton->SetLabel( _( "Deselect All" ) );
  77. }
  78. bool DIALOG_IMPORT_SETTINGS::TransferDataToWindow()
  79. {
  80. m_filePathCtrl->SetValue( m_filePath );
  81. return true;
  82. }
  83. void DIALOG_IMPORT_SETTINGS::OnBrowseClicked( wxCommandEvent& event )
  84. {
  85. wxFileName fn = m_frame->GetBoard()->GetFileName();
  86. wxFileDialog dlg( this, _( "Import Settings From" ), fn.GetPath(), fn.GetFullName(),
  87. PcbFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
  88. if( dlg.ShowModal() == wxID_OK )
  89. m_filePathCtrl->SetValue( dlg.GetPath() );
  90. }
  91. bool DIALOG_IMPORT_SETTINGS::TransferDataFromWindow()
  92. {
  93. if( !wxFileExists( m_filePathCtrl->GetValue() ) )
  94. {
  95. DisplayError( this, wxString::Format( _( "File not found." ) ) );
  96. m_filePathCtrl->SetFocus();
  97. return false;
  98. }
  99. m_filePath = m_filePathCtrl->GetValue();
  100. return true;
  101. }
  102. void DIALOG_IMPORT_SETTINGS::OnSelectAll( wxCommandEvent& event )
  103. {
  104. // Select or deselect all options based on internal flag
  105. m_LayersOpt->SetValue( m_showSelectAllOnBtn );
  106. m_TextAndGraphicsOpt->SetValue( m_showSelectAllOnBtn );
  107. m_FormattingOpt->SetValue( m_showSelectAllOnBtn );
  108. m_ConstraintsOpt->SetValue( m_showSelectAllOnBtn );
  109. m_NetclassesOpt->SetValue( m_showSelectAllOnBtn );
  110. m_TracksAndViasOpt->SetValue( m_showSelectAllOnBtn );
  111. m_MaskAndPasteOpt->SetValue( m_showSelectAllOnBtn );
  112. m_SeveritiesOpt->SetValue( m_showSelectAllOnBtn );
  113. // Ensure "Import Settings" button state is enabled as appropriate
  114. UpdateImportSettingsButton();
  115. // Toggle whether button selects or deselects all.
  116. m_showSelectAllOnBtn = !m_showSelectAllOnBtn;
  117. UpdateSelectAllButton();
  118. }