2017-10-04 09:57:59 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 CERN
|
2019-08-03 03:03:03 +00:00
|
|
|
* Copyright (C) 2018-2019 KiCad Developers, see change_log.txt for contributors.
|
2018-06-27 18:27:38 +00:00
|
|
|
*
|
2017-10-04 09:57:59 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dialog_gencad_export_options.h"
|
|
|
|
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2017-10-04 09:57:59 +00:00
|
|
|
#include <class_board.h>
|
|
|
|
#include <project.h>
|
|
|
|
#include <confirm.h>
|
2017-11-12 00:31:38 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2019-08-03 03:03:03 +00:00
|
|
|
#include <wx/filepicker.h>
|
2017-10-04 09:57:59 +00:00
|
|
|
#include <wx/statline.h>
|
|
|
|
|
2019-08-03 03:03:03 +00:00
|
|
|
|
|
|
|
DIALOG_GENCAD_EXPORT_OPTIONS::DIALOG_GENCAD_EXPORT_OPTIONS( PCB_EDIT_FRAME* aParent,
|
|
|
|
const wxString& aPath )
|
2018-06-27 18:27:38 +00:00
|
|
|
: DIALOG_SHIM( aParent, wxID_ANY, _( "Export to GenCAD settings" ), wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
|
2017-10-04 09:57:59 +00:00
|
|
|
{
|
|
|
|
wxBoxSizer* m_mainSizer= new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
2019-10-10 16:44:33 +00:00
|
|
|
// Ctreate the file picker. The path will be set later, when the widget size
|
|
|
|
// is set to.
|
|
|
|
m_filePicker = new wxFilePickerCtrl( this, wxID_ANY, "",
|
2019-08-03 03:03:03 +00:00
|
|
|
_("Select a GenCAD export filename"),
|
|
|
|
GencadFileWildcard(),
|
|
|
|
wxDefaultPosition, wxSize( -1,-1 ),
|
|
|
|
wxFLP_SAVE|wxFLP_USE_TEXTCTRL );
|
|
|
|
m_mainSizer->Add( m_filePicker, 0, wxEXPAND | wxRIGHT, 5 );
|
2017-10-04 09:57:59 +00:00
|
|
|
|
2018-06-27 18:27:38 +00:00
|
|
|
m_optsSizer = new wxGridSizer( 0, 1, 3, 3 );
|
2017-10-04 09:57:59 +00:00
|
|
|
createOptCheckboxes();
|
2018-06-27 18:27:38 +00:00
|
|
|
m_mainSizer->Add( m_optsSizer, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
|
2017-10-04 09:57:59 +00:00
|
|
|
|
|
|
|
wxSizer* stdButtons = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
|
2018-06-27 18:27:38 +00:00
|
|
|
m_mainSizer->Add( stdButtons, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5 );
|
2017-10-04 09:57:59 +00:00
|
|
|
|
|
|
|
SetSizer( m_mainSizer );
|
2019-10-10 16:44:33 +00:00
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
FinishDialogSettings();
|
|
|
|
|
|
|
|
// Set the path in m_filePicker, now the size is set
|
|
|
|
// (otherwize the text is truncated)
|
|
|
|
m_filePicker->SetPath( aPath );
|
2017-10-04 09:57:59 +00:00
|
|
|
|
|
|
|
Centre( wxBOTH );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_GENCAD_EXPORT_OPTIONS::~DIALOG_GENCAD_EXPORT_OPTIONS()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_GENCAD_EXPORT_OPTIONS::GetOption( GENCAD_EXPORT_OPT aOption ) const
|
|
|
|
{
|
|
|
|
auto it = m_options.find( aOption );
|
|
|
|
|
|
|
|
if( it == m_options.end() )
|
|
|
|
{
|
|
|
|
wxASSERT_MSG( false, "Missing checkbox for an option" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return it->second->IsChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::map<GENCAD_EXPORT_OPT, bool> DIALOG_GENCAD_EXPORT_OPTIONS::GetAllOptions() const
|
|
|
|
{
|
|
|
|
std::map<GENCAD_EXPORT_OPT, bool> retVal;
|
|
|
|
|
|
|
|
for( const auto& option : m_options )
|
|
|
|
retVal[option.first] = option.second->IsChecked();
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString DIALOG_GENCAD_EXPORT_OPTIONS::GetFileName() const
|
|
|
|
{
|
2019-08-03 03:03:03 +00:00
|
|
|
return m_filePicker->GetPath();
|
2017-10-04 09:57:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_GENCAD_EXPORT_OPTIONS::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxString fn = GetFileName();
|
|
|
|
|
|
|
|
if( wxFile::Exists( fn ) )
|
2018-07-10 14:33:04 +00:00
|
|
|
{
|
|
|
|
wxString msg = wxString::Format( _( "File %s already exists." ), fn );
|
|
|
|
KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
|
|
|
|
dlg.SetOKLabel( _( "Overwrite" ) );
|
2018-08-29 22:37:20 +00:00
|
|
|
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
2018-07-10 14:33:04 +00:00
|
|
|
|
|
|
|
return ( dlg.ShowModal() == wxID_OK );
|
|
|
|
}
|
2017-10-04 09:57:59 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_GENCAD_EXPORT_OPTIONS::createOptCheckboxes()
|
|
|
|
{
|
|
|
|
std::map<GENCAD_EXPORT_OPT, wxString> opts =
|
|
|
|
{
|
2019-08-03 03:03:03 +00:00
|
|
|
{ FLIP_BOTTOM_PADS, _( "Flip bottom footprint padstacks" ) },
|
|
|
|
{ UNIQUE_PIN_NAMES, _( "Generate unique pin names" ) },
|
|
|
|
{ INDIVIDUAL_SHAPES, _( "Generate a new shape for each footprint instance (do not reuse shapes)" ) },
|
|
|
|
{ USE_AUX_ORIGIN, _( "Use auxiliary axis as origin" ) },
|
|
|
|
{ STORE_ORIGIN_COORDS, _( "Save the origin coordinates in the file" ) }
|
2017-10-04 09:57:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for( const auto& option : opts )
|
|
|
|
{
|
|
|
|
wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
|
|
|
|
m_options[option.first] = chkbox;
|
2018-06-27 18:27:38 +00:00
|
|
|
m_optsSizer->Add( chkbox );
|
2017-10-04 09:57:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|