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.

150 lines
4.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 CERN
  5. * Copyright (C) 2018-2019 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * @author Maciej Suminski <maciej.suminski@cern.ch>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, you may find one here:
  21. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  22. * or you may search the http://www.gnu.org website for the version 2 license,
  23. * or you may write to the Free Software Foundation, Inc.,
  24. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  25. */
  26. #include "dialog_gencad_export_options.h"
  27. #include <pcb_edit_frame.h>
  28. #include <board.h>
  29. #include <project.h>
  30. #include <confirm.h>
  31. #include <wildcards_and_files_ext.h>
  32. #include <wx/checkbox.h>
  33. #include <wx/filepicker.h>
  34. #include <wx/statline.h>
  35. DIALOG_GENCAD_EXPORT_OPTIONS::DIALOG_GENCAD_EXPORT_OPTIONS( PCB_EDIT_FRAME* aParent,
  36. const wxString& aPath )
  37. : DIALOG_SHIM( aParent, wxID_ANY, _( "Export to GenCAD settings" ), wxDefaultPosition,
  38. wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
  39. {
  40. wxBoxSizer* m_mainSizer= new wxBoxSizer( wxVERTICAL );
  41. // Ctreate the file picker. The path will be set later, when the widget size
  42. // is set to.
  43. m_filePicker = new wxFilePickerCtrl( this, wxID_ANY, "",
  44. _("Select a GenCAD export filename"),
  45. GencadFileWildcard(),
  46. wxDefaultPosition, wxSize( -1,-1 ),
  47. wxFLP_SAVE|wxFLP_USE_TEXTCTRL );
  48. m_mainSizer->Add( m_filePicker, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 5 );
  49. m_optsSizer = new wxGridSizer( 0, 1, 3, 3 );
  50. createOptCheckboxes();
  51. m_mainSizer->Add( m_optsSizer, 1, wxEXPAND | wxALL, 10 );
  52. wxSizer* stdButtons = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
  53. m_mainSizer->Add( stdButtons, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
  54. SetSizer( m_mainSizer );
  55. // Now all widgets have the size fixed, call FinishDialogSettings
  56. finishDialogSettings();
  57. // Set the path in m_filePicker, now the size is set
  58. // (otherwize the text is truncated)
  59. m_filePicker->SetPath( aPath );
  60. Centre( wxBOTH );
  61. }
  62. DIALOG_GENCAD_EXPORT_OPTIONS::~DIALOG_GENCAD_EXPORT_OPTIONS()
  63. {
  64. }
  65. bool DIALOG_GENCAD_EXPORT_OPTIONS::GetOption( GENCAD_EXPORT_OPT aOption ) const
  66. {
  67. auto it = m_options.find( aOption );
  68. if( it == m_options.end() )
  69. {
  70. wxASSERT_MSG( false, "Missing checkbox for an option" );
  71. return false;
  72. }
  73. return it->second->IsChecked();
  74. }
  75. std::map<GENCAD_EXPORT_OPT, bool> DIALOG_GENCAD_EXPORT_OPTIONS::GetAllOptions() const
  76. {
  77. std::map<GENCAD_EXPORT_OPT, bool> retVal;
  78. for( const auto& option : m_options )
  79. retVal[option.first] = option.second->IsChecked();
  80. return retVal;
  81. }
  82. wxString DIALOG_GENCAD_EXPORT_OPTIONS::GetFileName() const
  83. {
  84. return m_filePicker->GetPath();
  85. }
  86. bool DIALOG_GENCAD_EXPORT_OPTIONS::TransferDataFromWindow()
  87. {
  88. if( !wxDialog::TransferDataFromWindow() )
  89. return false;
  90. wxString fn = GetFileName();
  91. if( wxFile::Exists( fn ) )
  92. {
  93. wxString msg = wxString::Format( _( "File %s already exists." ), fn );
  94. KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
  95. dlg.SetOKLabel( _( "Overwrite" ) );
  96. dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
  97. return ( dlg.ShowModal() == wxID_OK );
  98. }
  99. return true;
  100. }
  101. void DIALOG_GENCAD_EXPORT_OPTIONS::createOptCheckboxes()
  102. {
  103. std::map<GENCAD_EXPORT_OPT, wxString> opts =
  104. {
  105. { FLIP_BOTTOM_PADS, _( "Flip bottom footprint padstacks" ) },
  106. { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) },
  107. { INDIVIDUAL_SHAPES, _( "Generate a new shape for each footprint instance (do not reuse shapes)" ) },
  108. { USE_AUX_ORIGIN, _( "Use drill/place file origin as origin" ) },
  109. { STORE_ORIGIN_COORDS, _( "Save the origin coordinates in the file" ) }
  110. };
  111. for( const auto& option : opts )
  112. {
  113. wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
  114. m_options[option.first] = chkbox;
  115. m_optsSizer->Add( chkbox );
  116. }
  117. }