kicad-source/pcbnew/dialogs/dialog_gencad_export_options.cpp

237 lines
7.9 KiB
C++
Raw Normal View History

2017-10-04 11:57:59 +02:00
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2017 CERN
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
2017-10-04 11:57:59 +02: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"
2025-02-25 22:44:16 -05:00
#include <jobs/job_export_pcb_gencad.h>
2018-01-29 21:58:58 +01:00
#include <pcb_edit_frame.h>
2024-04-27 22:57:24 +03:00
#include <kidialog.h>
#include <wildcards_and_files_ext.h>
2025-05-19 15:27:43 -04:00
#include <wx/anybutton.h>
#include <wx/filedlg.h>
2021-06-03 07:49:49 -04:00
#include <wx/checkbox.h>
#include <wx/filepicker.h>
2024-04-27 22:57:24 +03:00
#include <wx/sizer.h>
2025-02-25 22:44:16 -05:00
#include <wx/stattext.h>
#include <wx/textctrl.h>
#include "widgets/std_bitmap_button.h"
#include <board.h>
2017-10-04 11:57:59 +02:00
DIALOG_GENCAD_EXPORT_OPTIONS::DIALOG_GENCAD_EXPORT_OPTIONS( PCB_EDIT_FRAME* aParent,
2025-02-25 22:44:16 -05:00
const wxString& aPath ) :
DIALOG_SHIM( aParent, wxID_ANY, _( "Export to GenCAD settings" ), wxDefaultPosition,
wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
m_frame( aParent ),
m_job( nullptr )
2017-10-04 11:57:59 +02:00
{
2025-02-25 22:44:16 -05:00
wxBoxSizer* m_mainSizer = new wxBoxSizer( wxVERTICAL );
m_fileSizer = new wxBoxSizer( wxHORIZONTAL );
m_textFile = new wxStaticText( this, wxID_ANY, _( "Output File:" ), wxDefaultPosition, wxDefaultSize, 0 );
m_textFile->Wrap( -1 );
m_fileSizer->Add( m_textFile, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5 );
m_outputFileName =
new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
m_outputFileName->SetToolTip( _( "Enter a filename if you do not want to use default file names" ) );
m_outputFileName->SetMinSize( wxSize( 350, -1 ) );
m_fileSizer->Add( m_outputFileName, 1, wxALL | wxEXPAND, 5 );
m_browseButton = new STD_BITMAP_BUTTON( this, wxID_ANY, wxNullBitmap, wxDefaultPosition,
wxSize( -1, -1 ), wxBU_AUTODRAW | 0 );
m_fileSizer->Add( m_browseButton, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5 );
m_mainSizer->Add( m_fileSizer, 0, wxEXPAND | wxALL, 5 );
2017-10-04 11:57:59 +02:00
m_optsSizer = new wxGridSizer( 0, 1, 3, 3 );
2017-10-04 11:57:59 +02:00
createOptCheckboxes();
2025-02-25 22:44:16 -05:00
m_mainSizer->Add( m_optsSizer, 1, wxEXPAND | wxALL, 5 );
2017-10-04 11:57:59 +02:00
wxSizer* stdButtons = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
2025-02-25 22:44:16 -05:00
m_mainSizer->Add( stdButtons, 0, wxALL | wxEXPAND, 5 );
2017-10-04 11:57:59 +02:00
SetSizer( m_mainSizer );
// Now all widgets have the size fixed, call FinishDialogSettings
2020-11-16 11:16:44 +00:00
finishDialogSettings();
// Set the path in m_filePicker, now the size is set
// (otherwise the text is truncated)
2025-02-25 22:44:16 -05:00
m_outputFileName->SetValue( aPath );
Layout();
Fit();
2017-10-04 11:57:59 +02:00
2025-02-25 22:44:16 -05:00
m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
m_browseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked ),
NULL, this );
}
DIALOG_GENCAD_EXPORT_OPTIONS::DIALOG_GENCAD_EXPORT_OPTIONS( PCB_EDIT_FRAME* aParent,
JOB_EXPORT_PCB_GENCAD* aJob ) :
DIALOG_GENCAD_EXPORT_OPTIONS( aParent, aJob->GetConfiguredOutputPath() )
{
m_job = aJob;
m_browseButton->Hide();
// Set the title
SetTitle( aJob->GetSettingsDialogTitle() );
2017-10-04 11:57:59 +02:00
}
DIALOG_GENCAD_EXPORT_OPTIONS::~DIALOG_GENCAD_EXPORT_OPTIONS()
{
2025-02-25 22:44:16 -05:00
m_browseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler( DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked ),
NULL, this );
}
void DIALOG_GENCAD_EXPORT_OPTIONS::onBrowseClicked( wxCommandEvent& aEvent )
{
wxFileName brdFile( m_frame->GetBoard()->GetFileName() );
wxString fileDialogName( wxString::Format( wxS( "%s-gencad" ), brdFile.GetName() ) );
wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
wxFileName fn( Prj().AbsolutePath( path ) );
wxFileDialog dlg( this, _( "Export GenCAD File" ), fn.GetPath(), fileDialogName,
FILEEXT::GencadFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
if( dlg.ShowModal() == wxID_OK )
m_outputFileName->SetValue( dlg.GetPath() );
2017-10-04 11:57:59 +02:00
}
bool DIALOG_GENCAD_EXPORT_OPTIONS::GetOption( GENCAD_EXPORT_OPT aOption ) const
{
auto it = m_options.find( aOption );
if( it == m_options.end() )
{
2022-02-04 22:44:59 +00:00
wxASSERT_MSG( false, wxT( "Missing checkbox for an option" ) );
2017-10-04 11:57:59 +02:00
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
{
2025-02-25 22:44:16 -05:00
return m_outputFileName->GetValue();
}
bool DIALOG_GENCAD_EXPORT_OPTIONS::TransferDataToWindow()
{
if( !wxDialog::TransferDataToWindow() )
return false;
if( m_job )
{
m_options[FLIP_BOTTOM_PADS]->SetValue( m_job->m_flipBottomPads );
m_options[UNIQUE_PIN_NAMES]->SetValue( m_job->m_useUniquePins );
m_options[INDIVIDUAL_SHAPES]->SetValue( m_job->m_useIndividualShapes );
m_options[USE_AUX_ORIGIN]->SetValue( m_job->m_useDrillOrigin );
m_options[STORE_ORIGIN_COORDS]->SetValue( m_job->m_storeOriginCoords );
}
return true;
2017-10-04 11:57:59 +02:00
}
bool DIALOG_GENCAD_EXPORT_OPTIONS::TransferDataFromWindow()
{
if( !wxDialog::TransferDataFromWindow() )
return false;
2025-02-25 22:44:16 -05:00
if( m_job )
{
m_job->SetConfiguredOutputPath( GetFileName() );
m_job->m_flipBottomPads = GetOption( FLIP_BOTTOM_PADS );
m_job->m_useUniquePins = GetOption( UNIQUE_PIN_NAMES );
m_job->m_useIndividualShapes = GetOption( INDIVIDUAL_SHAPES );
m_job->m_useDrillOrigin = GetOption( USE_AUX_ORIGIN );
m_job->m_storeOriginCoords = GetOption( STORE_ORIGIN_COORDS );
}
else
{
2025-02-25 22:44:16 -05:00
wxString fn = GetFileName();
if( wxFile::Exists( fn ) )
{
wxString msg = wxString::Format( _( "File %s already exists." ), fn );
KIDIALOG dlg( this, msg, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
dlg.SetOKLabel( _( "Overwrite" ) );
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
2025-02-25 22:44:16 -05:00
return ( dlg.ShowModal() == wxID_OK );
}
}
2017-10-04 11:57:59 +02:00
return true;
}
void DIALOG_GENCAD_EXPORT_OPTIONS::createOptCheckboxes()
{
std::map<GENCAD_EXPORT_OPT, wxString> opts =
{
{ 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 drill/place file origin as origin" ) },
{ STORE_ORIGIN_COORDS, _( "Save the origin coordinates in the file" ) }
2017-10-04 11:57:59 +02:00
};
for( const auto& option : opts )
{
wxCheckBox* chkbox = new wxCheckBox( this, wxID_ANY, option.second );
m_options[option.first] = chkbox;
m_optsSizer->Add( chkbox );
2017-10-04 11:57:59 +02:00
}
}