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.

156 lines
4.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 CERN
  5. * @author Maciej Suminski <maciej.suminski@cern.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include "dialog_gencad_export_options.h"
  25. #include <wxPcbStruct.h>
  26. #include <class_board.h>
  27. #include <project.h>
  28. #include <confirm.h>
  29. #include <wx/statline.h>
  30. #include <wx/button.h>
  31. DIALOG_GENCAD_EXPORT_OPTIONS::DIALOG_GENCAD_EXPORT_OPTIONS( PCB_EDIT_FRAME* aParent )
  32. : DIALOG_SHIM( aParent, wxID_ANY, _( "Export to GenCAD settings" ) )
  33. {
  34. // Obtain a potential filename for the exported file
  35. wxFileName fn = aParent->GetBoard()->GetFileName();
  36. fn.SetExt( "cad" );
  37. // Create widgets
  38. SetSizeHints( wxSize( 500, 200 ), wxDefaultSize );
  39. wxBoxSizer* m_mainSizer= new wxBoxSizer( wxVERTICAL );
  40. wxBoxSizer* m_fileSizer = new wxBoxSizer( wxHORIZONTAL );
  41. m_filePath = new wxTextCtrl( this, wxID_ANY, fn.GetFullPath() );
  42. m_fileSizer->Add( m_filePath, 1, wxALL, 5 );
  43. wxButton* m_browseBtn = new wxButton( this, wxID_ANY, _( "Browse" ) );
  44. m_browseBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
  45. wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowse ), NULL, this );
  46. m_fileSizer->Add( m_browseBtn, 0, wxALL, 5 );
  47. m_mainSizer->Add( m_fileSizer, 0, wxEXPAND, 5 );
  48. m_optsSizer = new wxGridSizer( 0, 1, 0, 0 );
  49. createOptCheckboxes();
  50. m_mainSizer->Add( m_optsSizer, 1, wxEXPAND, 5 );
  51. wxSizer* stdButtons = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
  52. m_mainSizer->Add( stdButtons, 0, wxEXPAND, 5 );
  53. SetSizer( m_mainSizer );
  54. Layout();
  55. m_mainSizer->Fit( this );
  56. Centre( wxBOTH );
  57. }
  58. DIALOG_GENCAD_EXPORT_OPTIONS::~DIALOG_GENCAD_EXPORT_OPTIONS()
  59. {
  60. }
  61. bool DIALOG_GENCAD_EXPORT_OPTIONS::GetOption( GENCAD_EXPORT_OPT aOption ) const
  62. {
  63. auto it = m_options.find( aOption );
  64. if( it == m_options.end() )
  65. {
  66. wxASSERT_MSG( false, "Missing checkbox for an option" );
  67. return false;
  68. }
  69. return it->second->IsChecked();
  70. }
  71. std::map<GENCAD_EXPORT_OPT, bool> DIALOG_GENCAD_EXPORT_OPTIONS::GetAllOptions() const
  72. {
  73. std::map<GENCAD_EXPORT_OPT, bool> retVal;
  74. for( const auto& option : m_options )
  75. retVal[option.first] = option.second->IsChecked();
  76. return retVal;
  77. }
  78. wxString DIALOG_GENCAD_EXPORT_OPTIONS::GetFileName() const
  79. {
  80. return m_filePath->GetValue();
  81. }
  82. bool DIALOG_GENCAD_EXPORT_OPTIONS::TransferDataFromWindow()
  83. {
  84. if( !wxDialog::TransferDataFromWindow() )
  85. return false;
  86. wxString fn = GetFileName();
  87. if( wxFile::Exists( fn ) )
  88. return IsOK( this, wxString::Format( _( "File %s already exists. Overwrite?" ), fn ) );
  89. return true;
  90. }
  91. void DIALOG_GENCAD_EXPORT_OPTIONS::createOptCheckboxes()
  92. {
  93. std::map<GENCAD_EXPORT_OPT, wxString> opts =
  94. {
  95. { FLIP_BOTTOM_PADS, _( "Flip bottom components padstacks" ) },
  96. { UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) },
  97. { INDIVIDUAL_SHAPES, _( "Generate a new shape for each component (do not reuse shapes)" ) }
  98. };
  99. for( const auto& option : opts )
  100. {
  101. wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
  102. m_options[option.first] = chkbox;
  103. m_optsSizer->Add( chkbox, 0, wxALL, 5 );
  104. }
  105. }
  106. void DIALOG_GENCAD_EXPORT_OPTIONS::onBrowse( wxCommandEvent& aEvent )
  107. {
  108. wxFileDialog dlg( this, _( "Save GenCAD Board File" ),
  109. wxPathOnly( Prj().GetProjectFullName() ),
  110. m_filePath->GetValue(),
  111. _( "GenCAD 1.4 board files (.cad)|*.cad" ),
  112. wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
  113. if( dlg.ShowModal() == wxID_CANCEL )
  114. return;
  115. m_filePath->SetValue( dlg.GetPath() );
  116. }