2016-09-19 07:40:36 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Cirilo Bernardo
|
2021-01-03 10:01:03 +00:00
|
|
|
* Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-09-19 07:40:36 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wx/choicdlg.h>
|
|
|
|
#include <wx/stdpaths.h>
|
2018-10-02 06:34:07 +00:00
|
|
|
#include <wx/process.h>
|
2021-08-20 21:07:00 +00:00
|
|
|
#include <wx/string.h>
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2021-07-27 14:13:26 +00:00
|
|
|
#include <pgm_base.h>
|
2021-06-08 23:33:06 +00:00
|
|
|
#include <board.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <dialog_export_step_base.h>
|
|
|
|
#include <footprint.h>
|
2021-09-14 22:45:14 +00:00
|
|
|
#include <kiface_base.h>
|
2020-10-24 01:38:50 +00:00
|
|
|
#include <locale_io.h>
|
2021-06-08 23:33:06 +00:00
|
|
|
#include <math/vector3.h>
|
|
|
|
#include <pcb_edit_frame.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
|
2021-06-08 23:33:06 +00:00
|
|
|
#include <reporter.h>
|
2017-11-23 13:05:26 +00:00
|
|
|
#include <widgets/text_ctrl_eval.h>
|
2021-08-20 21:07:00 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2021-06-14 15:53:54 +00:00
|
|
|
#include <filename_resolver.h>
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2021-09-11 16:40:20 +00:00
|
|
|
#ifdef KICAD_STEP_EXPORT_LIB
|
|
|
|
#include <kicad2step.h>
|
|
|
|
#endif
|
|
|
|
|
2016-09-19 07:40:36 +00:00
|
|
|
class DIALOG_EXPORT_STEP: public DIALOG_EXPORT_STEP_BASE
|
|
|
|
{
|
2017-08-10 12:25:31 +00:00
|
|
|
public:
|
|
|
|
enum STEP_ORG_OPT
|
|
|
|
{
|
|
|
|
STEP_ORG_0, // absolute coordinates
|
|
|
|
STEP_ORG_PLOT_AXIS, // origin is plot/drill axis origin
|
|
|
|
STEP_ORG_GRID_AXIS, // origin is grid origin
|
|
|
|
STEP_ORG_BOARD_CENTER, // origin is board center
|
|
|
|
STEP_ORG_USER, // origin is entered by user
|
|
|
|
};
|
|
|
|
|
2016-09-19 07:40:36 +00:00
|
|
|
private:
|
|
|
|
PCB_EDIT_FRAME* m_parent;
|
2017-08-10 12:25:31 +00:00
|
|
|
// The last preference for STEP Origin:
|
|
|
|
STEP_ORG_OPT m_STEP_org_opt;
|
2016-09-19 08:07:39 +00:00
|
|
|
bool m_noVirtual; // remember last preference for No Virtual Component
|
2016-09-19 07:40:36 +00:00
|
|
|
int m_OrgUnits; // remember last units for User Origin
|
|
|
|
double m_XOrg; // remember last User Origin X value
|
|
|
|
double m_YOrg; // remember last User Origin Y value
|
2018-03-19 14:36:21 +00:00
|
|
|
wxString m_boardPath; // path to the exported board file
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2018-02-18 00:02:45 +00:00
|
|
|
protected:
|
|
|
|
void onUpdateUnits( wxUpdateUIEvent& aEvent ) override;
|
|
|
|
void onUpdateXPos( wxUpdateUIEvent& aEvent ) override;
|
|
|
|
void onUpdateYPos( wxUpdateUIEvent& aEvent ) override;
|
2018-03-19 14:36:21 +00:00
|
|
|
void onExportButton( wxCommandEvent& aEvent ) override;
|
2018-02-18 00:02:45 +00:00
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
int GetOrgUnitsChoice() const
|
2016-09-19 07:40:36 +00:00
|
|
|
{
|
|
|
|
return m_STEP_OrgUnitChoice->GetSelection();
|
|
|
|
}
|
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
double GetXOrg() const
|
2016-09-19 07:40:36 +00:00
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
return DoubleValueFromString( EDA_UNITS::UNSCALED, m_STEP_Xorg->GetValue() );
|
2016-09-19 07:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double GetYOrg()
|
|
|
|
{
|
2019-12-20 14:11:39 +00:00
|
|
|
return DoubleValueFromString( EDA_UNITS::UNSCALED, m_STEP_Yorg->GetValue() );
|
2016-09-19 07:40:36 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
STEP_ORG_OPT GetOriginOption();
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
bool GetNoVirtOption()
|
2016-09-19 07:40:36 +00:00
|
|
|
{
|
2017-08-10 12:25:31 +00:00
|
|
|
return m_cbRemoveVirtual->GetValue();
|
2016-09-19 07:40:36 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 22:46:37 +00:00
|
|
|
bool GetSubstOption()
|
|
|
|
{
|
|
|
|
return m_cbSubstModels->GetValue();
|
|
|
|
}
|
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
bool GetOverwriteFile()
|
|
|
|
{
|
|
|
|
return m_cbOverwriteFile->GetValue();
|
|
|
|
}
|
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
public:
|
|
|
|
DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& aBoardPath );
|
2021-06-15 07:33:37 +00:00
|
|
|
~DIALOG_EXPORT_STEP();
|
2017-08-10 12:25:31 +00:00
|
|
|
};
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2018-02-18 00:02:45 +00:00
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& aBoardPath ) :
|
|
|
|
DIALOG_EXPORT_STEP_BASE( aParent )
|
2017-08-10 12:25:31 +00:00
|
|
|
{
|
2018-03-19 14:36:21 +00:00
|
|
|
m_parent = aParent;
|
|
|
|
m_boardPath = aBoardPath;
|
2018-05-09 11:24:42 +00:00
|
|
|
m_sdbSizerCancel->SetLabel( _( "Close" ) );
|
2018-09-24 18:57:02 +00:00
|
|
|
m_sdbSizerOK->SetLabel( _( "Export" ) );
|
2018-05-09 11:24:42 +00:00
|
|
|
m_sdbSizer->Layout();
|
2018-03-19 14:36:21 +00:00
|
|
|
|
|
|
|
// Build default output file name
|
2019-08-03 03:03:03 +00:00
|
|
|
wxString path = m_parent->GetLastPath( LAST_PATH_STEP );
|
|
|
|
|
|
|
|
if( path.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName brdFile = m_parent->GetBoard()->GetFileName();
|
|
|
|
brdFile.SetExt( "step" );
|
|
|
|
path = brdFile.GetFullPath();
|
|
|
|
}
|
|
|
|
|
2021-08-20 21:07:00 +00:00
|
|
|
// Reset this picker bc wxFormBuilder doesn't allow untranslated strings
|
|
|
|
wxSizerItem* sizer_item = bSizerTop->GetItem( 1UL );
|
|
|
|
wxWindow* widget = sizer_item->GetWindow();
|
|
|
|
bSizerTop->Hide( widget );
|
|
|
|
widget->Destroy();
|
|
|
|
|
|
|
|
m_filePickerSTEP = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString,
|
2021-09-03 14:22:32 +00:00
|
|
|
_( "Select a STEP export filename" ),
|
|
|
|
_( "STEP files" ) + AddFileExtListToFilter( { "STEP", "STP" } ),
|
|
|
|
wxDefaultPosition,
|
2021-08-20 21:07:00 +00:00
|
|
|
wxSize( -1, -1 ), wxFLP_SAVE | wxFLP_USE_TEXTCTRL );
|
|
|
|
bSizerTop->Add( m_filePickerSTEP, 1, wxTOP|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
|
|
|
|
|
2021-09-03 14:22:32 +00:00
|
|
|
m_filePickerSTEP->SetPath( path );
|
|
|
|
|
2021-08-20 21:07:00 +00:00
|
|
|
Layout();
|
|
|
|
bSizerSTEPFile->Fit( this );
|
2018-03-19 14:36:21 +00:00
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
SetFocus();
|
|
|
|
|
2020-05-06 01:43:37 +00:00
|
|
|
auto cfg = m_parent->GetPcbNewSettings();
|
2017-08-10 12:25:31 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
m_STEP_org_opt = static_cast<STEP_ORG_OPT>( cfg->m_ExportStep.origin_mode );
|
2017-08-10 12:25:31 +00:00
|
|
|
|
|
|
|
switch( m_STEP_org_opt )
|
2016-09-19 08:07:39 +00:00
|
|
|
{
|
2017-08-10 12:25:31 +00:00
|
|
|
default: break;
|
2018-02-18 00:02:45 +00:00
|
|
|
case STEP_ORG_PLOT_AXIS: m_rbDrillAndPlotOrigin->SetValue( true ); break;
|
|
|
|
case STEP_ORG_GRID_AXIS: m_rbGridOrigin->SetValue( true ); break;
|
|
|
|
case STEP_ORG_USER: m_rbUserDefinedOrigin->SetValue( true ); break;
|
|
|
|
case STEP_ORG_BOARD_CENTER: m_rbBoardCenterOrigin->SetValue( true ); break;
|
2016-09-19 08:07:39 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
m_OrgUnits = cfg->m_ExportStep.origin_units;
|
|
|
|
m_XOrg = cfg->m_ExportStep.origin_x;
|
|
|
|
m_YOrg = cfg->m_ExportStep.origin_y;
|
|
|
|
m_noVirtual = cfg->m_ExportStep.no_virtual;
|
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
m_cbRemoveVirtual->SetValue( m_noVirtual );
|
2021-06-15 07:33:37 +00:00
|
|
|
m_cbSubstModels->SetValue( cfg->m_ExportStep.replace_models );
|
|
|
|
m_cbOverwriteFile->SetValue( cfg->m_ExportStep.overwrite_file );
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
m_STEP_OrgUnitChoice->SetSelection( m_OrgUnits );
|
|
|
|
wxString tmpStr;
|
|
|
|
tmpStr << m_XOrg;
|
|
|
|
m_STEP_Xorg->SetValue( tmpStr );
|
|
|
|
tmpStr = "";
|
|
|
|
tmpStr << m_YOrg;
|
|
|
|
m_STEP_Yorg->SetValue( tmpStr );
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2021-06-08 23:33:06 +00:00
|
|
|
wxString bad_scales;
|
|
|
|
size_t bad_count = 0;
|
|
|
|
|
|
|
|
for( auto& fp : aParent->GetBoard()->Footprints() )
|
|
|
|
{
|
|
|
|
for( auto& model : fp->Models() )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( model.m_Scale.x != 1.0 ||
|
|
|
|
model.m_Scale.y != 1.0 ||
|
|
|
|
model.m_Scale.z != 1.0 )
|
|
|
|
{
|
|
|
|
bad_scales.Append( wxS("\n") );
|
|
|
|
bad_scales.Append( model.m_Filename );
|
|
|
|
bad_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bad_count >= 5 )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-27 14:13:26 +00:00
|
|
|
if( !bad_scales.empty()
|
|
|
|
&& !Pgm().GetCommonSettings()->m_DoNotShowAgain.scaled_3d_models_warning )
|
2021-06-08 23:33:06 +00:00
|
|
|
{
|
|
|
|
wxString extendedMsg = _( "Non-unity scaled models:" ) + "\n" + bad_scales;
|
|
|
|
|
|
|
|
KIDIALOG msgDlg( m_parent, _( "Scaled models detected. "
|
2021-07-27 14:13:26 +00:00
|
|
|
"Model scaling is not reliable for mechanical export." ),
|
2021-06-08 23:33:06 +00:00
|
|
|
_( "Model Scale Warning" ), wxOK | wxICON_WARNING );
|
|
|
|
msgDlg.SetExtendedMessage( extendedMsg );
|
|
|
|
msgDlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
|
|
|
|
|
|
|
msgDlg.ShowModal();
|
2021-07-27 14:13:26 +00:00
|
|
|
|
|
|
|
if( msgDlg.DoNotShowAgain() )
|
|
|
|
Pgm().GetCommonSettings()->m_DoNotShowAgain.scaled_3d_models_warning = true;
|
2021-06-08 23:33:06 +00:00
|
|
|
}
|
2017-08-10 12:25:31 +00:00
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2017-08-10 12:25:31 +00:00
|
|
|
}
|
2016-09-19 07:40:36 +00:00
|
|
|
|
|
|
|
|
2021-06-15 07:33:37 +00:00
|
|
|
DIALOG_EXPORT_STEP::~DIALOG_EXPORT_STEP()
|
|
|
|
{
|
|
|
|
GetOriginOption(); // Update m_STEP_org_opt member.
|
|
|
|
|
|
|
|
auto cfg = m_parent->GetPcbNewSettings();
|
|
|
|
|
|
|
|
cfg->m_ExportStep.origin_mode = static_cast<int>( m_STEP_org_opt );
|
|
|
|
cfg->m_ExportStep.origin_units = m_STEP_OrgUnitChoice->GetSelection();
|
|
|
|
cfg->m_ExportStep.replace_models = m_cbSubstModels->GetValue();
|
|
|
|
cfg->m_ExportStep.overwrite_file = m_cbOverwriteFile->GetValue();
|
|
|
|
|
|
|
|
double val = 0.0;
|
|
|
|
|
|
|
|
m_STEP_Xorg->GetValue().ToDouble( &val );
|
|
|
|
cfg->m_ExportStep.origin_x = val;
|
|
|
|
|
|
|
|
m_STEP_Yorg->GetValue().ToDouble( &val );
|
|
|
|
cfg->m_ExportStep.origin_y = val;
|
|
|
|
|
|
|
|
cfg->m_ExportStep.no_virtual = m_cbRemoveVirtual->GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
DIALOG_EXPORT_STEP::STEP_ORG_OPT DIALOG_EXPORT_STEP::GetOriginOption()
|
|
|
|
{
|
|
|
|
m_STEP_org_opt = STEP_ORG_0;
|
|
|
|
|
2018-02-18 00:02:45 +00:00
|
|
|
if( m_rbDrillAndPlotOrigin->GetValue() )
|
2017-08-10 12:25:31 +00:00
|
|
|
m_STEP_org_opt = STEP_ORG_PLOT_AXIS;
|
2018-02-18 00:02:45 +00:00
|
|
|
else if( m_rbGridOrigin->GetValue() )
|
2017-08-10 12:25:31 +00:00
|
|
|
m_STEP_org_opt = STEP_ORG_GRID_AXIS;
|
2018-02-18 00:02:45 +00:00
|
|
|
else if( m_rbUserDefinedOrigin->GetValue() )
|
2017-08-10 12:25:31 +00:00
|
|
|
m_STEP_org_opt = STEP_ORG_USER;
|
2018-02-18 00:02:45 +00:00
|
|
|
else if( m_rbBoardCenterOrigin->GetValue() )
|
2017-08-10 12:25:31 +00:00
|
|
|
m_STEP_org_opt = STEP_ORG_BOARD_CENTER;
|
|
|
|
|
|
|
|
return m_STEP_org_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-19 07:40:36 +00:00
|
|
|
void PCB_EDIT_FRAME::OnExportSTEP( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxFileName brdFile = GetBoard()->GetFileName();
|
|
|
|
|
2021-05-28 19:07:04 +00:00
|
|
|
if( GetScreen()->IsContentModified() || brdFile.GetFullPath().empty() )
|
2016-09-19 07:40:36 +00:00
|
|
|
{
|
2016-09-20 22:55:35 +00:00
|
|
|
if( !doAutoSave() )
|
2016-09-19 07:40:36 +00:00
|
|
|
{
|
2020-11-20 13:55:10 +00:00
|
|
|
DisplayErrorMessage( this, _( "STEP export failed! "
|
|
|
|
"Please save the PCB and try again" ) );
|
2016-09-20 22:55:35 +00:00
|
|
|
return;
|
2016-09-19 07:40:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
// Use auto-saved board for export
|
|
|
|
brdFile.SetName( GetAutoSaveFilePrefix() + brdFile.GetName() );
|
2016-09-19 07:40:36 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
DIALOG_EXPORT_STEP dlg( this, brdFile.GetFullPath() );
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
2016-09-21 23:03:00 +00:00
|
|
|
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
void DIALOG_EXPORT_STEP::onUpdateUnits( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
aEvent.Enable( m_rbUserDefinedOrigin->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_EXPORT_STEP::onUpdateXPos( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
aEvent.Enable( m_rbUserDefinedOrigin->GetValue() );
|
|
|
|
}
|
2016-09-19 07:40:36 +00:00
|
|
|
|
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
void DIALOG_EXPORT_STEP::onUpdateYPos( wxUpdateUIEvent& aEvent )
|
|
|
|
{
|
|
|
|
aEvent.Enable( m_rbUserDefinedOrigin->GetValue() );
|
|
|
|
}
|
|
|
|
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
2019-08-03 03:03:03 +00:00
|
|
|
m_parent->SetLastPath( LAST_PATH_STEP, m_filePickerSTEP->GetPath() );
|
|
|
|
|
2021-01-03 10:38:09 +00:00
|
|
|
double tolerance = 0.01; // default value in mm
|
|
|
|
|
|
|
|
switch( m_tolerance->GetSelection() )
|
|
|
|
{
|
|
|
|
case 0: // small
|
|
|
|
tolerance = 0.001;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case 1: break; // Normal
|
|
|
|
|
|
|
|
case 2: // large
|
|
|
|
tolerance = 0.1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-03-19 16:34:11 +00:00
|
|
|
SHAPE_POLY_SET outline;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
// Check if the board outline is continuous
|
2021-01-03 10:38:09 +00:00
|
|
|
// max dist from one endPt to next startPt to build a closed shape:
|
|
|
|
int chainingEpsilon = Millimeter2iu( tolerance );
|
|
|
|
// Arc to segment approx error (not critical here: we do not use the outline shape):
|
|
|
|
int maxError = Millimeter2iu( 0.005 );
|
|
|
|
bool success = BuildBoardPolygonOutlines( m_parent->GetBoard(), outline, maxError,
|
|
|
|
chainingEpsilon, nullptr );
|
|
|
|
if( !success )
|
2018-03-19 16:34:11 +00:00
|
|
|
{
|
2021-01-03 10:38:09 +00:00
|
|
|
DisplayErrorMessage( this, wxString::Format(
|
|
|
|
_( "Board outline is missing or not closed using %.3f mm tolerance.\n"
|
|
|
|
"Run DRC for a full analysis." ), tolerance ) );
|
2018-03-19 16:34:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
wxFileName fn = m_filePickerSTEP->GetFileName();
|
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
if( fn.FileExists() && !GetOverwriteFile() )
|
2018-03-19 14:36:21 +00:00
|
|
|
{
|
|
|
|
msg.Printf( _( "File '%s' already exists. Do you want overwrite this file?" ),
|
2021-01-03 10:01:03 +00:00
|
|
|
fn.GetFullPath() );
|
2018-03-19 14:36:21 +00:00
|
|
|
|
|
|
|
if( wxMessageBox( msg, _( "STEP Export" ), wxYES_NO | wxICON_QUESTION, this ) == wxNO )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-14 15:53:54 +00:00
|
|
|
FILENAME_RESOLVER* fnResolver = m_parent->Prj().Get3DFilenameResolver();
|
|
|
|
|
|
|
|
fnResolver->WritePathList( wxStandardPaths::Get().GetTempDir(), "ExportPaths.cfg", true );
|
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
DIALOG_EXPORT_STEP::STEP_ORG_OPT orgOpt = GetOriginOption();
|
2017-08-10 12:25:31 +00:00
|
|
|
double xOrg = 0.0;
|
|
|
|
double yOrg = 0.0;
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2021-09-11 16:40:20 +00:00
|
|
|
#ifndef KICAD_STEP_EXPORT_LIB
|
2016-09-19 07:40:36 +00:00
|
|
|
wxFileName appK2S( wxStandardPaths::Get().GetExecutablePath() );
|
2018-06-18 16:14:10 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
2018-06-13 02:35:42 +00:00
|
|
|
// On macOS, we have standalone applications inside the main bundle, so we handle that here:
|
2020-08-31 15:54:51 +00:00
|
|
|
if( appK2S.GetPath().Find( "/Contents/Applications/pcbnew.app/Contents/MacOS" ) != wxNOT_FOUND )
|
2018-06-13 02:35:42 +00:00
|
|
|
{
|
2018-06-18 16:14:10 +00:00
|
|
|
appK2S.AppendDir( ".." );
|
|
|
|
appK2S.AppendDir( ".." );
|
|
|
|
appK2S.AppendDir( ".." );
|
|
|
|
appK2S.AppendDir( ".." );
|
2018-06-18 18:57:01 +00:00
|
|
|
appK2S.AppendDir( "MacOS" );
|
2018-06-13 02:35:42 +00:00
|
|
|
}
|
2018-06-18 16:14:10 +00:00
|
|
|
#endif
|
|
|
|
|
2016-09-19 07:40:36 +00:00
|
|
|
appK2S.SetName( "kicad2step" );
|
|
|
|
|
2016-09-21 23:03:00 +00:00
|
|
|
wxString cmdK2S = "\"";
|
|
|
|
cmdK2S.Append( appK2S.GetFullPath() );
|
|
|
|
cmdK2S.Append( "\"" );
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
if( GetNoVirtOption() )
|
2016-09-19 08:07:39 +00:00
|
|
|
cmdK2S.Append( " --no-virtual" );
|
|
|
|
|
2021-06-08 22:46:37 +00:00
|
|
|
if( GetSubstOption() )
|
|
|
|
cmdK2S.Append( " --subst-models" );
|
|
|
|
|
2021-11-05 12:24:38 +00:00
|
|
|
// Note: for some reason, using \" to insert a quote in a format string, under MacOS
|
|
|
|
// wxString::Format does not work. So use a %c format in string
|
|
|
|
int quote = '"';
|
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
switch( orgOpt )
|
|
|
|
{
|
|
|
|
case DIALOG_EXPORT_STEP::STEP_ORG_0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIALOG_EXPORT_STEP::STEP_ORG_PLOT_AXIS:
|
|
|
|
cmdK2S.Append( " --drill-origin" );
|
|
|
|
break;
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
case DIALOG_EXPORT_STEP::STEP_ORG_GRID_AXIS:
|
|
|
|
cmdK2S.Append( " --grid-origin" );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIALOG_EXPORT_STEP::STEP_ORG_USER:
|
|
|
|
{
|
2018-03-19 14:36:21 +00:00
|
|
|
xOrg = GetXOrg();
|
|
|
|
yOrg = GetYOrg();
|
2017-08-10 12:25:31 +00:00
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
if( GetOrgUnitsChoice() == 1 )
|
2017-08-10 12:25:31 +00:00
|
|
|
{
|
|
|
|
// selected reference unit is in inches, and STEP units are mm
|
|
|
|
xOrg *= 25.4;
|
|
|
|
yOrg *= 25.4;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOCALE_IO dummy;
|
2021-11-05 12:24:38 +00:00
|
|
|
cmdK2S.Append( wxString::Format( " --user-origin=%c%.6f x %.6f%c", quote, xOrg, yOrg, quote ) );
|
2017-08-10 12:25:31 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
case DIALOG_EXPORT_STEP::STEP_ORG_BOARD_CENTER:
|
|
|
|
{
|
2018-03-19 14:36:21 +00:00
|
|
|
EDA_RECT bbox = m_parent->GetBoard()->ComputeBoundingBox( true );
|
2017-08-10 12:25:31 +00:00
|
|
|
xOrg = Iu2Millimeter( bbox.GetCenter().x );
|
|
|
|
yOrg = Iu2Millimeter( bbox.GetCenter().y );
|
|
|
|
LOCALE_IO dummy;
|
2021-11-05 12:24:38 +00:00
|
|
|
cmdK2S.Append( wxString::Format( " --user-origin=%c%.6f x %.6f%c", quote, xOrg, yOrg, quote ) );
|
2017-08-10 12:25:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2019-01-29 06:15:38 +00:00
|
|
|
{
|
2019-02-04 17:05:49 +00:00
|
|
|
LOCALE_IO dummy;
|
2021-11-05 12:24:38 +00:00
|
|
|
cmdK2S.Append( wxString::Format( " --min-distance=%c%.3f mm%c", quote, tolerance, quote ) );
|
2019-01-29 06:15:38 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 12:24:38 +00:00
|
|
|
cmdK2S.Append( wxString::Format( " -f -o %c%s%c", quote,
|
|
|
|
m_filePickerSTEP->GetPath(), quote ) ); // input file path
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2021-11-05 12:24:38 +00:00
|
|
|
cmdK2S.Append( wxString::Format( " %c%s%c",quote, m_boardPath, quote ) ); // output file path
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2018-10-02 06:34:07 +00:00
|
|
|
wxExecute( cmdK2S, wxEXEC_ASYNC | wxEXEC_SHOW_CONSOLE );
|
2018-02-18 00:02:45 +00:00
|
|
|
|
2021-09-11 16:40:20 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
KICAD2MCAD_PRMS params;
|
|
|
|
params.m_filename = m_boardPath;
|
|
|
|
params.m_outputFile = m_filePickerSTEP->GetPath();
|
|
|
|
|
|
|
|
params.m_includeVirtual = !GetNoVirtOption();
|
|
|
|
|
|
|
|
params.m_substModels = GetSubstOption();
|
|
|
|
params.m_minDistance = tolerance;
|
|
|
|
params.m_overwrite = true;
|
|
|
|
|
|
|
|
switch( orgOpt )
|
|
|
|
{
|
|
|
|
case DIALOG_EXPORT_STEP::STEP_ORG_0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIALOG_EXPORT_STEP::STEP_ORG_PLOT_AXIS:
|
|
|
|
params.m_useDrillOrigin = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIALOG_EXPORT_STEP::STEP_ORG_GRID_AXIS:
|
|
|
|
params.m_useGridOrigin = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIALOG_EXPORT_STEP::STEP_ORG_USER:
|
|
|
|
{
|
|
|
|
xOrg = GetXOrg();
|
|
|
|
yOrg = GetYOrg();
|
|
|
|
|
|
|
|
if( GetOrgUnitsChoice() == 1 )
|
|
|
|
{
|
|
|
|
// selected reference unit is in inches, and STEP units are mm
|
|
|
|
xOrg *= 25.4;
|
|
|
|
yOrg *= 25.4;
|
|
|
|
}
|
|
|
|
|
|
|
|
params.m_xOrigin = xOrg;
|
|
|
|
params.m_yOrigin = yOrg;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIALOG_EXPORT_STEP::STEP_ORG_BOARD_CENTER:
|
|
|
|
{
|
|
|
|
EDA_RECT bbox = m_parent->GetBoard()->ComputeBoundingBox( true );
|
|
|
|
xOrg = Iu2Millimeter( bbox.GetCenter().x );
|
|
|
|
yOrg = Iu2Millimeter( bbox.GetCenter().y );
|
|
|
|
params.m_xOrigin = xOrg;
|
|
|
|
params.m_yOrigin = yOrg;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
KICAD2STEP converter( params );
|
|
|
|
converter.Run();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
aEvent.Skip(); // Close the dialog
|
2018-02-18 00:02:45 +00:00
|
|
|
}
|