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
|
2023-10-23 17:01:04 +00:00
|
|
|
* Copyright (C) 2016-2023 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
|
|
|
|
*/
|
|
|
|
|
2022-09-12 18:01:48 +00:00
|
|
|
#include <wx/log.h>
|
2016-09-19 07:40:36 +00:00
|
|
|
#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>
|
2023-10-23 17:01:04 +00:00
|
|
|
#include <wx/filedlg.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>
|
2023-10-23 17:01:04 +00:00
|
|
|
#include <bitmaps.h>
|
|
|
|
#include <widgets/std_bitmap_button.h>
|
2022-10-05 18:51:38 +00:00
|
|
|
#include "dialog_export_step_base.h"
|
|
|
|
#include "dialog_export_step_process.h"
|
2021-06-08 23:33:06 +00:00
|
|
|
#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>
|
2022-09-12 18:01:48 +00:00
|
|
|
#include <trace_helpers.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
|
|
|
|
2022-09-12 18:01:48 +00:00
|
|
|
|
|
|
|
class DIALOG_EXPORT_STEP : public DIALOG_EXPORT_STEP_BASE
|
2016-09-19 07:40:36 +00:00
|
|
|
{
|
2017-08-10 12:25:31 +00:00
|
|
|
public:
|
2022-11-09 16:31:29 +00:00
|
|
|
enum STEP_ORIGIN_OPTION
|
2017-08-10 12:25:31 +00:00
|
|
|
{
|
2022-11-09 16:31:29 +00:00
|
|
|
STEP_ORIGIN_0, // absolute coordinates
|
|
|
|
STEP_ORIGIN_PLOT_AXIS, // origin is plot/drill axis origin
|
|
|
|
STEP_ORIGIN_GRID_AXIS, // origin is grid origin
|
|
|
|
STEP_ORIGIN_BOARD_CENTER, // origin is board center
|
|
|
|
STEP_ORIGIN_USER, // origin is entered by user
|
2017-08-10 12:25:31 +00:00
|
|
|
};
|
|
|
|
|
2022-09-12 18:01:48 +00:00
|
|
|
DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& aBoardPath );
|
|
|
|
~DIALOG_EXPORT_STEP();
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2018-02-18 00:02:45 +00:00
|
|
|
protected:
|
2023-10-23 17:01:04 +00:00
|
|
|
void onBrowseClicked( wxCommandEvent& aEvent ) override;
|
2018-02-18 00:02:45 +00:00
|
|
|
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
|
|
|
{
|
2022-09-16 04:38:10 +00:00
|
|
|
return EDA_UNIT_UTILS::UI::DoubleValueFromString( m_STEP_Xorg->GetValue() );
|
2016-09-19 07:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double GetYOrg()
|
|
|
|
{
|
2022-09-16 04:38:10 +00:00
|
|
|
return EDA_UNIT_UTILS::UI::DoubleValueFromString( m_STEP_Yorg->GetValue() );
|
2016-09-19 07:40:36 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 16:31:29 +00:00
|
|
|
STEP_ORIGIN_OPTION GetOriginOption();
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2023-04-13 14:30:31 +00:00
|
|
|
bool GetNoUnspecifiedOption()
|
2016-09-19 07:40:36 +00:00
|
|
|
{
|
2023-04-13 14:30:31 +00:00
|
|
|
return m_cbRemoveUnspecified->GetValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetNoDNPOption()
|
|
|
|
{
|
|
|
|
return m_cbRemoveDNP->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();
|
|
|
|
}
|
|
|
|
|
2022-09-12 18:01:48 +00:00
|
|
|
private:
|
2022-11-09 16:31:29 +00:00
|
|
|
PCB_EDIT_FRAME* m_parent;
|
|
|
|
STEP_ORIGIN_OPTION m_origin; // The last preference for STEP origin option
|
|
|
|
double m_userOriginX; // remember last User Origin X value
|
|
|
|
double m_userOriginY; // remember last User Origin Y value
|
|
|
|
int m_originUnits; // remember last units for User Origin
|
2023-04-13 14:30:31 +00:00
|
|
|
bool m_noUnspecified; // remember last preference for No Unspecified Component
|
|
|
|
bool m_noDNP; // remember last preference for No DNP Component
|
2023-11-19 12:21:25 +00:00
|
|
|
static bool m_optimizeStep; // remember last preference for Optimize STEP file (stored only for the session)
|
|
|
|
static bool m_exportTracks; // remember last preference to export tracks (stored only for the session)
|
|
|
|
static bool m_exportZones; // remember last preference to export tracks (stored only for the session)
|
2022-11-09 16:31:29 +00:00
|
|
|
wxString m_boardPath; // path to the exported board file
|
|
|
|
static int m_toleranceLastChoice; // Store m_tolerance option during a session
|
2017-08-10 12:25:31 +00:00
|
|
|
};
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2022-09-12 18:01:48 +00:00
|
|
|
|
2023-03-02 18:38:19 +00:00
|
|
|
int DIALOG_EXPORT_STEP::m_toleranceLastChoice = -1; // Use default
|
2023-11-19 12:21:25 +00:00
|
|
|
bool DIALOG_EXPORT_STEP::m_optimizeStep = true;
|
2023-03-02 18:38:19 +00:00
|
|
|
bool DIALOG_EXPORT_STEP::m_exportTracks = false;
|
2023-08-21 02:10:43 +00:00
|
|
|
bool DIALOG_EXPORT_STEP::m_exportZones = false;
|
2022-09-12 18:01:48 +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
|
|
|
{
|
2023-10-23 17:01:04 +00:00
|
|
|
m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
|
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
m_parent = aParent;
|
|
|
|
m_boardPath = aBoardPath;
|
2023-10-23 17:01:04 +00:00
|
|
|
|
|
|
|
SetupStandardButtons( { { wxID_OK, _( "Export" ) },
|
|
|
|
{ wxID_CANCEL, _( "Close" ) } } );
|
2018-03-19 14:36:21 +00:00
|
|
|
|
|
|
|
// Build default output file name
|
2023-10-29 09:13:08 +00:00
|
|
|
// (last saved filename in project or built from board filename)
|
2019-08-03 03:03:03 +00:00
|
|
|
wxString path = m_parent->GetLastPath( LAST_PATH_STEP );
|
|
|
|
|
|
|
|
if( path.IsEmpty() )
|
|
|
|
{
|
2023-10-23 17:01:04 +00:00
|
|
|
wxFileName brdFile( m_parent->GetBoard()->GetFileName() );
|
2022-02-04 22:44:59 +00:00
|
|
|
brdFile.SetExt( wxT( "step" ) );
|
2019-08-03 03:03:03 +00:00
|
|
|
path = brdFile.GetFullPath();
|
|
|
|
}
|
|
|
|
|
2023-10-29 09:13:08 +00:00
|
|
|
m_outputFileName->SetValue( 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();
|
|
|
|
|
2022-04-13 22:45:51 +00:00
|
|
|
PCBNEW_SETTINGS* cfg = m_parent->GetPcbNewSettings();
|
2017-08-10 12:25:31 +00:00
|
|
|
|
2022-11-09 16:31:29 +00:00
|
|
|
m_origin = static_cast<STEP_ORIGIN_OPTION>( cfg->m_ExportStep.origin_mode );
|
2017-08-10 12:25:31 +00:00
|
|
|
|
2022-11-09 16:31:29 +00:00
|
|
|
switch( m_origin )
|
2016-09-19 08:07:39 +00:00
|
|
|
{
|
2022-11-09 16:20:24 +00:00
|
|
|
default:
|
2022-11-09 16:31:29 +00:00
|
|
|
case STEP_ORIGIN_PLOT_AXIS: m_rbDrillAndPlotOrigin->SetValue( true ); break;
|
|
|
|
case STEP_ORIGIN_GRID_AXIS: m_rbGridOrigin->SetValue( true ); break;
|
|
|
|
case STEP_ORIGIN_USER: m_rbUserDefinedOrigin->SetValue( true ); break;
|
|
|
|
case STEP_ORIGIN_BOARD_CENTER: m_rbBoardCenterOrigin->SetValue( true ); break;
|
2016-09-19 08:07:39 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 16:31:29 +00:00
|
|
|
m_originUnits = cfg->m_ExportStep.origin_units;
|
|
|
|
m_userOriginX = cfg->m_ExportStep.origin_x;
|
|
|
|
m_userOriginY = cfg->m_ExportStep.origin_y;
|
2023-04-13 14:30:31 +00:00
|
|
|
m_noUnspecified = cfg->m_ExportStep.no_unspecified;
|
|
|
|
m_noDNP = cfg->m_ExportStep.no_dnp;
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2023-11-19 12:21:25 +00:00
|
|
|
m_cbOptimizeStep->SetValue( m_optimizeStep );
|
2023-03-02 18:38:19 +00:00
|
|
|
m_cbExportTracks->SetValue( m_exportTracks );
|
2023-08-21 02:10:43 +00:00
|
|
|
m_cbExportZones->SetValue( m_exportZones );
|
2023-04-13 14:30:31 +00:00
|
|
|
m_cbRemoveUnspecified->SetValue( m_noUnspecified );
|
|
|
|
m_cbRemoveDNP->SetValue( m_noDNP );
|
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
|
|
|
|
2022-11-09 16:31:29 +00:00
|
|
|
m_STEP_OrgUnitChoice->SetSelection( m_originUnits );
|
2017-08-10 12:25:31 +00:00
|
|
|
wxString tmpStr;
|
2022-11-09 16:31:29 +00:00
|
|
|
tmpStr << m_userOriginX;
|
2017-08-10 12:25:31 +00:00
|
|
|
m_STEP_Xorg->SetValue( tmpStr );
|
2022-02-04 22:44:59 +00:00
|
|
|
tmpStr = wxEmptyString;
|
2022-11-09 16:31:29 +00:00
|
|
|
tmpStr << m_userOriginY;
|
2017-08-10 12:25:31 +00:00
|
|
|
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;
|
|
|
|
|
2022-04-13 22:45:51 +00:00
|
|
|
for( FOOTPRINT* fp : aParent->GetBoard()->Footprints() )
|
2021-06-08 23:33:06 +00:00
|
|
|
{
|
2022-04-13 22:45:51 +00:00
|
|
|
for( const FP_3DMODEL& model : fp->Models() )
|
2021-06-08 23:33:06 +00:00
|
|
|
{
|
2023-10-23 17:01:04 +00:00
|
|
|
if( model.m_Scale.x != 1.0 || model.m_Scale.y != 1.0 || model.m_Scale.z != 1.0 )
|
2021-06-08 23:33:06 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
wxString extendedMsg = _( "Non-unity scaled models:" ) + wxT( "\n" ) + bad_scales;
|
2021-06-08 23:33:06 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2022-04-13 22:45:51 +00:00
|
|
|
|
2022-07-01 07:44:10 +00:00
|
|
|
if( m_toleranceLastChoice >= 0 )
|
2023-03-02 18:38:19 +00:00
|
|
|
m_choiceTolerance->SetSelection( m_toleranceLastChoice );
|
2022-07-01 07:44:10 +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()
|
|
|
|
{
|
2022-11-09 16:31:29 +00:00
|
|
|
GetOriginOption(); // Update m_origin member.
|
2021-06-15 07:33:37 +00:00
|
|
|
|
2023-10-16 21:04:01 +00:00
|
|
|
PCBNEW_SETTINGS* cfg = nullptr;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
cfg = m_parent->GetPcbNewSettings();
|
|
|
|
}
|
|
|
|
catch( const std::runtime_error& e )
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( e.what() );
|
|
|
|
}
|
2021-06-15 07:33:37 +00:00
|
|
|
|
2023-10-16 21:04:01 +00:00
|
|
|
if( cfg )
|
|
|
|
{
|
|
|
|
cfg->m_ExportStep.origin_mode = static_cast<int>( m_origin );
|
|
|
|
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();
|
2021-06-15 07:33:37 +00:00
|
|
|
|
2023-10-16 21:04:01 +00:00
|
|
|
double val = 0.0;
|
2021-06-15 07:33:37 +00:00
|
|
|
|
2023-10-16 21:04:01 +00:00
|
|
|
m_STEP_Xorg->GetValue().ToDouble( &val );
|
|
|
|
cfg->m_ExportStep.origin_x = val;
|
2021-06-15 07:33:37 +00:00
|
|
|
|
2023-10-16 21:04:01 +00:00
|
|
|
m_STEP_Yorg->GetValue().ToDouble( &val );
|
|
|
|
cfg->m_ExportStep.origin_y = val;
|
2021-06-15 07:33:37 +00:00
|
|
|
|
2023-10-16 21:04:01 +00:00
|
|
|
cfg->m_ExportStep.no_unspecified = m_cbRemoveUnspecified->GetValue();
|
|
|
|
cfg->m_ExportStep.no_dnp = m_cbRemoveDNP->GetValue();
|
|
|
|
}
|
2022-07-01 07:44:10 +00:00
|
|
|
|
2023-03-02 18:38:19 +00:00
|
|
|
m_toleranceLastChoice = m_choiceTolerance->GetSelection();
|
2023-11-19 12:21:25 +00:00
|
|
|
m_optimizeStep = m_cbOptimizeStep->GetValue();
|
2023-03-02 18:38:19 +00:00
|
|
|
m_exportTracks = m_cbExportTracks->GetValue();
|
2023-08-21 07:36:25 +00:00
|
|
|
m_exportZones = m_cbExportZones->GetValue();
|
2021-06-15 07:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-09 16:31:29 +00:00
|
|
|
DIALOG_EXPORT_STEP::STEP_ORIGIN_OPTION DIALOG_EXPORT_STEP::GetOriginOption()
|
2017-08-10 12:25:31 +00:00
|
|
|
{
|
2022-11-09 16:31:29 +00:00
|
|
|
m_origin = STEP_ORIGIN_0;
|
2017-08-10 12:25:31 +00:00
|
|
|
|
2018-02-18 00:02:45 +00:00
|
|
|
if( m_rbDrillAndPlotOrigin->GetValue() )
|
2022-11-09 16:31:29 +00:00
|
|
|
m_origin = STEP_ORIGIN_PLOT_AXIS;
|
2018-02-18 00:02:45 +00:00
|
|
|
else if( m_rbGridOrigin->GetValue() )
|
2022-11-09 16:31:29 +00:00
|
|
|
m_origin = STEP_ORIGIN_GRID_AXIS;
|
2018-02-18 00:02:45 +00:00
|
|
|
else if( m_rbUserDefinedOrigin->GetValue() )
|
2022-11-09 16:31:29 +00:00
|
|
|
m_origin = STEP_ORIGIN_USER;
|
2018-02-18 00:02:45 +00:00
|
|
|
else if( m_rbBoardCenterOrigin->GetValue() )
|
2022-11-09 16:31:29 +00:00
|
|
|
m_origin = STEP_ORIGIN_BOARD_CENTER;
|
2017-08-10 12:25:31 +00:00
|
|
|
|
2022-11-09 16:31:29 +00:00
|
|
|
return m_origin;
|
2017-08-10 12:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-10-23 17:01:04 +00:00
|
|
|
void DIALOG_EXPORT_STEP::onBrowseClicked( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxString filter = _( "STEP files" )
|
2023-12-28 02:10:01 +00:00
|
|
|
+ AddFileExtListToFilter( { FILEEXT::StepFileExtension, FILEEXT::StepFileAbrvExtension } ) + "|"
|
2024-01-10 16:30:50 +00:00
|
|
|
+ _( "Binary glTF files" )
|
2023-12-28 02:10:01 +00:00
|
|
|
+ AddFileExtListToFilter( { FILEEXT::GltfBinaryFileExtension } );
|
2023-10-23 17:01:04 +00:00
|
|
|
|
|
|
|
// Build the absolute path of current output directory to preselect it in the file browser.
|
|
|
|
wxString path = ExpandEnvVarSubstitutions( m_outputFileName->GetValue(), &Prj() );
|
|
|
|
wxFileName fn( Prj().AbsolutePath( path ) );
|
|
|
|
|
|
|
|
wxFileDialog dlg( this, _( "STEP Output File" ), fn.GetPath(), fn.GetFullName(), filter,
|
2023-10-29 09:13:08 +00:00
|
|
|
wxFD_SAVE );
|
2023-10-23 17:01:04 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_outputFileName->SetValue( dlg.GetPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-19 14:36:21 +00:00
|
|
|
void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
|
|
|
|
{
|
2023-10-23 17:01:04 +00:00
|
|
|
wxString path = m_outputFileName->GetValue();
|
|
|
|
m_parent->SetLastPath( LAST_PATH_STEP, path );
|
|
|
|
|
2024-04-18 00:57:39 +00:00
|
|
|
// Build the absolute path of current output directory to preselect it in the file browser.
|
|
|
|
std::function<bool( wxString* )> textResolver =
|
|
|
|
[&]( wxString* token ) -> bool
|
|
|
|
{
|
|
|
|
return m_parent->GetBoard()->ResolveTextVar( token, 0 );
|
|
|
|
};
|
|
|
|
|
|
|
|
path = ExpandTextVars( path, &textResolver );
|
2023-10-23 17:01:04 +00:00
|
|
|
path = ExpandEnvVarSubstitutions( path, &Prj() );
|
2024-04-18 00:57:39 +00:00
|
|
|
path = Prj().AbsolutePath( path );
|
2019-08-03 03:03:03 +00:00
|
|
|
|
2023-10-29 09:13:08 +00:00
|
|
|
if( path.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( this, _( "No filename for output file" ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-13 22:45:51 +00:00
|
|
|
double tolerance; // default value in mm
|
2023-03-02 18:38:19 +00:00
|
|
|
m_toleranceLastChoice = m_choiceTolerance->GetSelection();
|
2023-11-19 12:21:25 +00:00
|
|
|
m_optimizeStep = m_cbOptimizeStep->GetValue();
|
2023-03-02 18:38:19 +00:00
|
|
|
m_exportTracks = m_cbExportTracks->GetValue();
|
2023-08-21 07:36:25 +00:00
|
|
|
m_exportZones = m_cbExportZones->GetValue();
|
2021-01-03 10:38:09 +00:00
|
|
|
|
2023-03-02 18:38:19 +00:00
|
|
|
switch( m_choiceTolerance->GetSelection() )
|
2021-01-03 10:38:09 +00:00
|
|
|
{
|
2022-04-13 22:45:51 +00:00
|
|
|
case 0: tolerance = 0.001; break;
|
2021-01-03 10:38:09 +00:00
|
|
|
default:
|
2022-04-13 22:45:51 +00:00
|
|
|
case 1: tolerance = 0.01; break;
|
|
|
|
case 2: tolerance = 0.1; break;
|
2021-01-03 10:38:09 +00:00
|
|
|
}
|
|
|
|
|
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:
|
2022-09-16 11:33:56 +00:00
|
|
|
int chainingEpsilon = pcbIUScale.mmToIU( tolerance );
|
2022-09-12 18:01:48 +00:00
|
|
|
|
2021-01-03 10:38:09 +00:00
|
|
|
// Arc to segment approx error (not critical here: we do not use the outline shape):
|
2022-09-16 11:33:56 +00:00
|
|
|
int maxError = pcbIUScale.mmToIU( 0.005 );
|
2021-01-03 10:38:09 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-10-23 17:01:04 +00:00
|
|
|
wxFileName fn( Prj().AbsolutePath( path ) );
|
2018-03-19 14:36:21 +00:00
|
|
|
|
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
|
|
|
|
2023-08-19 23:01:05 +00:00
|
|
|
if( wxMessageBox( msg, _( "STEP/GLTF Export" ), wxYES_NO | wxICON_QUESTION, this ) == wxNO )
|
2018-03-19 14:36:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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:
|
2022-09-12 18:01:48 +00:00
|
|
|
if( appK2S.GetPath().Find( "/Contents/Applications/pcbnew.app/Contents/MacOS" ) != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
appK2S.AppendDir( wxT( ".." ) );
|
|
|
|
appK2S.AppendDir( wxT( ".." ) );
|
|
|
|
appK2S.AppendDir( wxT( ".." ) );
|
|
|
|
appK2S.AppendDir( wxT( ".." ) );
|
|
|
|
appK2S.AppendDir( wxT( "MacOS" ) );
|
|
|
|
}
|
2022-10-05 00:06:50 +00:00
|
|
|
#else
|
|
|
|
if( wxGetEnv( wxT( "KICAD_RUN_FROM_BUILD_DIR" ), nullptr ) )
|
|
|
|
{
|
2022-10-05 03:53:56 +00:00
|
|
|
appK2S.RemoveLastDir();
|
|
|
|
appK2S.AppendDir( "kicad" );
|
2022-10-05 00:06:50 +00:00
|
|
|
}
|
2018-06-18 16:14:10 +00:00
|
|
|
#endif
|
|
|
|
|
2022-10-05 00:06:50 +00:00
|
|
|
appK2S.SetName( wxT( "kicad-cli" ) );
|
2022-12-01 23:49:08 +00:00
|
|
|
appK2S.Normalize( FN_NORMALIZE_FLAGS );
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
wxString cmdK2S = wxT( "\"" );
|
2016-09-21 23:03:00 +00:00
|
|
|
cmdK2S.Append( appK2S.GetFullPath() );
|
2022-02-04 22:44:59 +00:00
|
|
|
cmdK2S.Append( wxT( "\"" ) );
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2022-10-05 00:06:50 +00:00
|
|
|
cmdK2S.Append( wxT( " pcb" ) );
|
2022-10-04 01:53:37 +00:00
|
|
|
cmdK2S.Append( wxT( " export" ) );
|
2023-08-19 23:01:05 +00:00
|
|
|
|
2023-12-28 02:10:01 +00:00
|
|
|
if( fn.GetExt() == FILEEXT::GltfBinaryFileExtension )
|
2023-08-19 23:01:05 +00:00
|
|
|
cmdK2S.Append( wxT( " glb" ) );
|
2024-04-17 14:31:07 +00:00
|
|
|
else if( fn.GetExt() == FILEEXT::BrepFileExtension )
|
|
|
|
cmdK2S.Append( wxT( " brep" ) );
|
2023-08-19 23:01:05 +00:00
|
|
|
else
|
|
|
|
cmdK2S.Append( wxT( " step" ) );
|
2022-10-04 01:53:37 +00:00
|
|
|
|
2023-04-13 14:30:31 +00:00
|
|
|
if( GetNoUnspecifiedOption() )
|
|
|
|
cmdK2S.Append( wxT( " --no-unspecified" ) );
|
|
|
|
|
|
|
|
if( GetNoDNPOption() )
|
|
|
|
cmdK2S.Append( wxT( " --no-dnp" ) );
|
2016-09-19 08:07:39 +00:00
|
|
|
|
2021-06-08 22:46:37 +00:00
|
|
|
if( GetSubstOption() )
|
2022-02-04 22:44:59 +00:00
|
|
|
cmdK2S.Append( wxT( " --subst-models" ) );
|
2021-06-08 22:46:37 +00:00
|
|
|
|
2023-11-19 12:21:25 +00:00
|
|
|
if( !m_optimizeStep )
|
|
|
|
cmdK2S.Append( wxT( " --no-optimize-step" ) );
|
|
|
|
|
2023-03-02 18:38:19 +00:00
|
|
|
if( m_exportTracks )
|
2023-08-21 02:10:43 +00:00
|
|
|
cmdK2S.Append( wxT( " --include-tracks" ) );
|
|
|
|
|
|
|
|
if( m_exportZones )
|
|
|
|
cmdK2S.Append( wxT( " --include-zones" ) );
|
2023-03-02 18:38:19 +00:00
|
|
|
|
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
|
2022-11-13 16:49:20 +00:00
|
|
|
int quote = '\'';
|
2022-11-14 12:31:23 +00:00
|
|
|
int dblquote = '"';
|
2021-11-05 12:24:38 +00:00
|
|
|
|
2022-11-09 16:31:29 +00:00
|
|
|
switch( GetOriginOption() )
|
2017-08-10 12:25:31 +00:00
|
|
|
{
|
2022-11-09 16:31:29 +00:00
|
|
|
case STEP_ORIGIN_0:
|
2022-11-09 16:20:24 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unsupported origin option: how did we get here?" ) );
|
2022-09-12 18:01:48 +00:00
|
|
|
break;
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2022-11-09 16:31:29 +00:00
|
|
|
case STEP_ORIGIN_PLOT_AXIS:
|
2022-09-12 18:01:48 +00:00
|
|
|
cmdK2S.Append( wxT( " --drill-origin" ) );
|
|
|
|
break;
|
2017-08-10 12:25:31 +00:00
|
|
|
|
2022-11-09 16:31:29 +00:00
|
|
|
case STEP_ORIGIN_GRID_AXIS:
|
2022-09-12 18:01:48 +00:00
|
|
|
cmdK2S.Append( wxT( " --grid-origin" ) );
|
|
|
|
break;
|
2017-08-10 12:25:31 +00:00
|
|
|
|
2022-11-09 16:31:29 +00:00
|
|
|
case STEP_ORIGIN_USER:
|
2022-09-12 18:01:48 +00:00
|
|
|
{
|
2022-11-09 16:31:29 +00:00
|
|
|
double xOrg = GetXOrg();
|
|
|
|
double yOrg = GetYOrg();
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2022-09-12 18:01:48 +00:00
|
|
|
if( GetOrgUnitsChoice() == 1 )
|
2017-08-10 12:25:31 +00:00
|
|
|
{
|
2022-09-12 18:01:48 +00:00
|
|
|
// selected reference unit is in inches, and STEP units are mm
|
|
|
|
xOrg *= 25.4;
|
|
|
|
yOrg *= 25.4;
|
2017-08-10 12:25:31 +00:00
|
|
|
}
|
2022-09-12 18:01:48 +00:00
|
|
|
|
|
|
|
LOCALE_IO dummy;
|
|
|
|
cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
|
|
|
|
quote, xOrg, yOrg, quote ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-11-09 16:31:29 +00:00
|
|
|
case STEP_ORIGIN_BOARD_CENTER:
|
2022-09-12 18:01:48 +00:00
|
|
|
{
|
2022-11-09 16:31:29 +00:00
|
|
|
BOX2I bbox = m_parent->GetBoard()->ComputeBoundingBox( true );
|
|
|
|
double xOrg = pcbIUScale.IUTomm( bbox.GetCenter().x );
|
|
|
|
double yOrg = pcbIUScale.IUTomm( bbox.GetCenter().y );
|
2022-09-12 18:01:48 +00:00
|
|
|
LOCALE_IO dummy;
|
2022-11-09 16:31:29 +00:00
|
|
|
|
2022-09-12 18:01:48 +00:00
|
|
|
cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
|
|
|
|
quote, xOrg, yOrg, quote ) );
|
|
|
|
break;
|
|
|
|
}
|
2017-08-10 12:25:31 +00:00
|
|
|
}
|
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;
|
2022-07-01 07:44:10 +00:00
|
|
|
cmdK2S.Append( wxString::Format( wxT( " --min-distance=%c%.3fmm%c" ),
|
2022-02-04 22:44:59 +00:00
|
|
|
quote, tolerance, quote ) );
|
2019-01-29 06:15:38 +00:00
|
|
|
}
|
|
|
|
|
2023-10-23 17:01:04 +00:00
|
|
|
// Output file path.
|
2022-02-04 22:44:59 +00:00
|
|
|
cmdK2S.Append( wxString::Format( wxT( " -f -o %c%s%c" ),
|
2023-10-23 17:01:04 +00:00
|
|
|
dblquote, fn.GetFullPath(), dblquote ) );
|
2022-09-12 18:01:48 +00:00
|
|
|
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2023-10-23 17:01:04 +00:00
|
|
|
// Input file path.
|
2022-11-14 12:31:23 +00:00
|
|
|
cmdK2S.Append( wxString::Format( wxT( " %c%s%c" ), dblquote, m_boardPath, dblquote ) );
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2022-10-04 01:53:37 +00:00
|
|
|
wxLogTrace( traceKiCad2Step, wxT( "export step command: %s" ), cmdK2S );
|
2018-02-18 00:02:45 +00:00
|
|
|
|
2022-10-05 18:51:38 +00:00
|
|
|
DIALOG_EXPORT_STEP_LOG* log = new DIALOG_EXPORT_STEP_LOG( this, cmdK2S );
|
|
|
|
log->ShowModal();
|
|
|
|
Close();
|
2023-04-13 14:30:31 +00:00
|
|
|
}
|