2014-01-02 09:26:03 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2015-01-12 19:25:20 +00:00
|
|
|
* Copyright (C) 2013-2015 Cirilo Bernardo
|
2019-08-03 03:03:03 +00:00
|
|
|
* Copyright (C) 2013-2019 KiCad Developers, see change_log.txt for contributors.
|
2014-01-02 09:26:03 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2018-01-29 20:58:58 +00:00
|
|
|
#include <pcb_edit_frame.h>
|
2020-11-12 20:19:22 +00:00
|
|
|
#include <board.h>
|
2017-11-23 13:05:26 +00:00
|
|
|
#include <widgets/text_ctrl_eval.h>
|
2014-01-02 09:26:03 +00:00
|
|
|
#include <dialog_export_idf_base.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <pcbnew_settings.h>
|
2020-05-31 21:42:04 +00:00
|
|
|
#include <project/project_file.h> // LAST_PATH_TYPE
|
2018-07-10 14:33:04 +00:00
|
|
|
#include <confirm.h>
|
2014-01-02 09:26:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DIALOG_EXPORT_IDF3: public DIALOG_EXPORT_IDF3_BASE
|
|
|
|
{
|
|
|
|
private:
|
2015-08-13 13:13:34 +00:00
|
|
|
bool m_idfThouOpt; // remember last preference for units in THOU
|
2015-08-18 23:48:42 +00:00
|
|
|
bool m_AutoAdjust; // remember last Reference Point AutoAdjust setting
|
2015-08-13 13:13:34 +00:00
|
|
|
int m_RefUnits; // remember last units for Reference Point
|
|
|
|
double m_XRef; // remember last X Reference Point
|
|
|
|
double m_YRef; // remember last Y Reference Point
|
2014-01-02 09:26:03 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
PCB_EDIT_FRAME* m_parent;
|
|
|
|
|
2014-01-02 09:26:03 +00:00
|
|
|
public:
|
|
|
|
DIALOG_EXPORT_IDF3( PCB_EDIT_FRAME* parent ) :
|
2020-01-13 01:44:19 +00:00
|
|
|
DIALOG_EXPORT_IDF3_BASE( parent ), m_parent( parent )
|
2014-01-02 09:26:03 +00:00
|
|
|
{
|
|
|
|
SetFocus();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-05-06 01:43:37 +00:00
|
|
|
auto cfg = m_parent->GetPcbNewSettings();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
m_idfThouOpt = cfg->m_ExportIdf.units_mils;
|
2014-01-25 12:23:29 +00:00
|
|
|
m_rbUnitSelection->SetSelection( m_idfThouOpt ? 1 : 0 );
|
2020-01-13 01:44:19 +00:00
|
|
|
m_AutoAdjust = cfg->m_ExportIdf.auto_adjust;
|
|
|
|
m_RefUnits = cfg->m_ExportIdf.ref_units;
|
|
|
|
m_XRef = cfg->m_ExportIdf.ref_x;
|
|
|
|
m_YRef = cfg->m_ExportIdf.ref_y;
|
2015-08-13 13:13:34 +00:00
|
|
|
|
2015-08-18 23:48:42 +00:00
|
|
|
m_cbAutoAdjustOffset->SetValue( m_AutoAdjust );
|
|
|
|
m_cbAutoAdjustOffset->Bind( wxEVT_CHECKBOX, &DIALOG_EXPORT_IDF3::OnAutoAdjustOffset, this );
|
|
|
|
|
2015-08-13 13:13:34 +00:00
|
|
|
m_IDF_RefUnitChoice->SetSelection( m_RefUnits );
|
|
|
|
wxString tmpStr;
|
|
|
|
tmpStr << m_XRef;
|
|
|
|
m_IDF_Xref->SetValue( tmpStr );
|
|
|
|
tmpStr = wxT( "" );
|
|
|
|
tmpStr << m_YRef;
|
|
|
|
m_IDF_Yref->SetValue( tmpStr );
|
2014-01-02 09:26:03 +00:00
|
|
|
|
2015-08-18 23:48:42 +00:00
|
|
|
if( m_AutoAdjust )
|
|
|
|
{
|
|
|
|
m_IDF_RefUnitChoice->Enable( false );
|
|
|
|
m_IDF_Xref->Enable( false );
|
|
|
|
m_IDF_Yref->Enable( false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_IDF_RefUnitChoice->Enable( true );
|
|
|
|
m_IDF_Xref->Enable( true );
|
|
|
|
m_IDF_Yref->Enable( true );
|
|
|
|
}
|
|
|
|
|
2016-07-18 15:54:41 +00:00
|
|
|
m_sdbSizerOK->SetDefault();
|
2015-01-12 19:25:20 +00:00
|
|
|
|
2016-07-18 15:54:41 +00:00
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2014-01-02 09:26:03 +00:00
|
|
|
}
|
2014-01-25 12:23:29 +00:00
|
|
|
|
2014-01-02 09:26:03 +00:00
|
|
|
~DIALOG_EXPORT_IDF3()
|
|
|
|
{
|
2014-01-25 12:23:29 +00:00
|
|
|
m_idfThouOpt = m_rbUnitSelection->GetSelection() == 1;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-05-06 01:43:37 +00:00
|
|
|
auto cfg = m_parent->GetPcbNewSettings();
|
2020-01-13 01:44:19 +00:00
|
|
|
|
|
|
|
cfg->m_ExportIdf.units_mils = m_idfThouOpt;
|
|
|
|
cfg->m_ExportIdf.auto_adjust = m_AutoAdjust;
|
|
|
|
cfg->m_ExportIdf.ref_units = m_RefUnits;
|
|
|
|
cfg->m_ExportIdf.ref_x = m_XRef;
|
|
|
|
cfg->m_ExportIdf.ref_y = m_YRef;
|
2014-01-02 09:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GetThouOption()
|
|
|
|
{
|
2014-01-25 12:23:29 +00:00
|
|
|
return m_rbUnitSelection->GetSelection() == 1;
|
2014-01-02 09:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxFilePickerCtrl* FilePicker()
|
|
|
|
{
|
|
|
|
return m_filePickerIDF;
|
|
|
|
}
|
2015-08-13 13:13:34 +00:00
|
|
|
|
|
|
|
int GetRefUnitsChoice()
|
|
|
|
{
|
|
|
|
return m_IDF_RefUnitChoice->GetSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
double GetXRef()
|
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
return DoubleValueFromString( EDA_UNITS::UNSCALED, m_IDF_Xref->GetValue() );
|
2015-08-13 13:13:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double GetYRef()
|
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
return DoubleValueFromString( EDA_UNITS::UNSCALED, m_IDF_Yref->GetValue() );
|
2015-08-13 13:13:34 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 23:48:42 +00:00
|
|
|
bool GetAutoAdjustOffset()
|
|
|
|
{
|
|
|
|
return m_cbAutoAdjustOffset->GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnAutoAdjustOffset( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( GetAutoAdjustOffset() )
|
|
|
|
{
|
|
|
|
m_IDF_RefUnitChoice->Enable( false );
|
|
|
|
m_IDF_Xref->Enable( false );
|
|
|
|
m_IDF_Yref->Enable( false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_IDF_RefUnitChoice->Enable( true );
|
|
|
|
m_IDF_Xref->Enable( true );
|
|
|
|
m_IDF_Yref->Enable( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2017-08-02 17:30:57 +00:00
|
|
|
bool TransferDataFromWindow() override;
|
2014-01-02 09:26:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-08-02 17:30:57 +00:00
|
|
|
bool DIALOG_EXPORT_IDF3::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
wxFileName fn = m_filePickerIDF->GetPath();
|
|
|
|
|
|
|
|
if( fn.FileExists() )
|
|
|
|
{
|
2018-07-10 14:33:04 +00:00
|
|
|
wxString msg = wxString::Format( _( "File %s already exists." ), fn.GetPath() );
|
|
|
|
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-08-02 17:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-19 17:35:25 +00:00
|
|
|
void PCB_EDIT_FRAME::OnExportIDF3( wxCommandEvent& event )
|
2014-01-02 09:26:03 +00:00
|
|
|
{
|
2019-08-03 03:03:03 +00:00
|
|
|
// Build default output file name
|
|
|
|
wxString path = GetLastPath( LAST_PATH_IDF );
|
2014-01-02 09:26:03 +00:00
|
|
|
|
2019-08-03 03:03:03 +00:00
|
|
|
if( path.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName brdFile = GetBoard()->GetFileName();
|
|
|
|
brdFile.SetExt( "emn" );
|
|
|
|
path = brdFile.GetFullPath();
|
|
|
|
}
|
2014-01-02 09:26:03 +00:00
|
|
|
|
|
|
|
DIALOG_EXPORT_IDF3 dlg( this );
|
2019-08-03 03:03:03 +00:00
|
|
|
dlg.FilePicker()->SetPath( path );
|
2014-01-02 09:26:03 +00:00
|
|
|
|
|
|
|
if ( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool thou = dlg.GetThouOption();
|
2015-08-18 23:48:42 +00:00
|
|
|
double aXRef;
|
|
|
|
double aYRef;
|
|
|
|
|
|
|
|
if( dlg.GetAutoAdjustOffset() )
|
|
|
|
{
|
2017-02-23 04:31:26 +00:00
|
|
|
EDA_RECT bbox = GetBoard()->GetBoardEdgesBoundingBox();
|
2015-08-13 13:13:34 +00:00
|
|
|
|
2015-08-18 23:48:42 +00:00
|
|
|
aXRef = bbox.Centre().x * MM_PER_IU;
|
|
|
|
aYRef = bbox.Centre().y * MM_PER_IU;
|
|
|
|
}
|
|
|
|
else
|
2015-08-13 13:13:34 +00:00
|
|
|
{
|
2015-08-18 23:48:42 +00:00
|
|
|
aXRef = dlg.GetXRef();
|
|
|
|
aYRef = dlg.GetYRef();
|
|
|
|
|
|
|
|
if( dlg.GetRefUnitsChoice() == 1 )
|
|
|
|
{
|
|
|
|
// selected reference unit is in inches
|
|
|
|
aXRef *= 25.4;
|
|
|
|
aYRef *= 25.4;
|
|
|
|
}
|
|
|
|
|
2015-08-13 13:13:34 +00:00
|
|
|
}
|
2014-01-02 09:26:03 +00:00
|
|
|
|
|
|
|
wxBusyCursor dummy;
|
|
|
|
|
|
|
|
wxString fullFilename = dlg.FilePicker()->GetPath();
|
2019-08-03 03:03:03 +00:00
|
|
|
SetLastPath( LAST_PATH_IDF, fullFilename );
|
2014-01-02 09:26:03 +00:00
|
|
|
|
2015-08-13 13:13:34 +00:00
|
|
|
if( !Export_IDF3( GetBoard(), fullFilename, thou, aXRef, aYRef ) )
|
2014-01-02 09:26:03 +00:00
|
|
|
{
|
2021-07-05 12:40:38 +00:00
|
|
|
wxString msg = wxString::Format( _( "Failed to create file '%s'." ), fullFilename );
|
2014-01-02 09:26:03 +00:00
|
|
|
wxMessageBox( msg );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-04-08 00:09:07 +00:00
|
|
|
|