2016-09-19 07:40:36 +00:00
|
|
|
/**
|
|
|
|
* @file dialog_export_step.cpp
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Cirilo Bernardo
|
2017-08-09 17:17:26 +00:00
|
|
|
* Copyright (C) 2016-2017 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-01-29 20:58:58 +00:00
|
|
|
#include "pcb_edit_frame.h"
|
2016-09-19 07:40:36 +00:00
|
|
|
#include "kiface_i.h"
|
2017-08-09 17:17:26 +00:00
|
|
|
#include "confirm.h"
|
|
|
|
|
2016-09-19 07:40:36 +00:00
|
|
|
#include "pcbnew.h"
|
|
|
|
#include "class_board.h"
|
|
|
|
#include "dialog_export_step_base.h"
|
2017-11-23 13:05:26 +00:00
|
|
|
#include <widgets/text_ctrl_eval.h>
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
#define OPTKEY_STEP_ORIGIN_OPT "STEP_Origin_Opt"
|
2016-09-21 23:03:00 +00:00
|
|
|
#define OPTKEY_STEP_UORG_UNITS "STEP_UserOriginUnits"
|
|
|
|
#define OPTKEY_STEP_UORG_X "STEP_UserOriginX"
|
|
|
|
#define OPTKEY_STEP_UORG_Y "STEP_UserOriginY"
|
|
|
|
#define OPTKEY_STEP_NOVIRT "STEP_NoVirtual"
|
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;
|
|
|
|
wxConfigBase* m_config;
|
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
|
|
|
|
|
|
|
|
public:
|
2017-08-10 12:25:31 +00:00
|
|
|
DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* parent );
|
2016-09-19 07:40:36 +00:00
|
|
|
|
|
|
|
~DIALOG_EXPORT_STEP()
|
|
|
|
{
|
2017-08-10 12:25:31 +00:00
|
|
|
GetOriginOption(); // Update m_STEP_org_opt member.
|
|
|
|
m_config->Write( OPTKEY_STEP_ORIGIN_OPT, (int)m_STEP_org_opt );
|
|
|
|
|
2016-09-19 08:07:39 +00:00
|
|
|
m_config->Write( OPTKEY_STEP_NOVIRT, m_cbRemoveVirtual->GetValue() );
|
2016-09-19 07:40:36 +00:00
|
|
|
|
|
|
|
m_config->Write( OPTKEY_STEP_UORG_UNITS, m_STEP_OrgUnitChoice->GetSelection() );
|
|
|
|
m_config->Write( OPTKEY_STEP_UORG_X, m_STEP_Xorg->GetValue() );
|
|
|
|
m_config->Write( OPTKEY_STEP_UORG_Y, m_STEP_Yorg->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFilePickerCtrl* FilePicker()
|
|
|
|
{
|
|
|
|
return m_filePickerSTEP;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetOrgUnitsChoice()
|
|
|
|
{
|
|
|
|
return m_STEP_OrgUnitChoice->GetSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
double GetXOrg()
|
|
|
|
{
|
|
|
|
return DoubleValueFromString( UNSCALED_UNITS, m_STEP_Xorg->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
double GetYOrg()
|
|
|
|
{
|
|
|
|
return DoubleValueFromString( UNSCALED_UNITS, m_STEP_Yorg->GetValue() );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
bool TransferDataFromWindow() override;
|
|
|
|
void onSelectOrigin( wxCommandEvent& event ) override;
|
|
|
|
};
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* parent ) :
|
|
|
|
DIALOG_EXPORT_STEP_BASE( parent )
|
|
|
|
{
|
|
|
|
m_parent = parent;
|
|
|
|
m_config = Kiface().KifaceSettings();
|
|
|
|
SetFocus();
|
|
|
|
|
|
|
|
m_STEP_org_opt = STEP_ORG_0;;
|
|
|
|
int tmp = STEP_ORG_0;
|
|
|
|
|
|
|
|
if( m_config->Read( OPTKEY_STEP_ORIGIN_OPT, &tmp ) )
|
|
|
|
m_STEP_org_opt = (STEP_ORG_OPT) tmp;
|
|
|
|
|
|
|
|
switch( m_STEP_org_opt )
|
2016-09-19 08:07:39 +00:00
|
|
|
{
|
2017-08-10 12:25:31 +00:00
|
|
|
default: break;
|
|
|
|
case STEP_ORG_PLOT_AXIS: m_cbPlotOrigin->SetValue( true ); break;
|
|
|
|
case STEP_ORG_GRID_AXIS: m_cbGridOrigin->SetValue( true ); break;
|
|
|
|
case STEP_ORG_USER: m_cbUserOrigin->SetValue( true ); break;
|
|
|
|
case STEP_ORG_BOARD_CENTER: m_cbBoardCenter->SetValue( true ); break;
|
2016-09-19 08:07:39 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
m_config->Read( OPTKEY_STEP_UORG_UNITS, &m_OrgUnits, 0 );
|
|
|
|
m_config->Read( OPTKEY_STEP_UORG_X, &m_XOrg, 0.0 );
|
|
|
|
m_config->Read( OPTKEY_STEP_UORG_Y, &m_YOrg, 0.0 );
|
|
|
|
m_config->Read( OPTKEY_STEP_NOVIRT, &m_noVirtual );
|
|
|
|
m_cbRemoveVirtual->SetValue( m_noVirtual );
|
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
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
m_STEP_OrgUnitChoice->Enable( m_cbUserOrigin->IsChecked() );
|
|
|
|
m_STEP_Xorg->Enable( m_cbUserOrigin->IsChecked() );
|
|
|
|
m_STEP_Yorg->Enable( m_cbUserOrigin->IsChecked() );
|
|
|
|
|
|
|
|
m_sdbSizerOK->SetDefault();
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
FinishDialogSettings();
|
|
|
|
}
|
2016-09-19 07:40:36 +00:00
|
|
|
|
|
|
|
|
2017-08-09 17:17:26 +00:00
|
|
|
bool DIALOG_EXPORT_STEP::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxFileName fn = m_filePickerSTEP->GetFileName();
|
|
|
|
|
|
|
|
if( fn.FileExists() )
|
|
|
|
{
|
2017-08-10 07:48:17 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "File: %s\n"
|
|
|
|
"already exists. Do you want overwrite this file?" ),
|
|
|
|
fn.GetFullPath().GetData() );
|
2017-08-09 17:17:26 +00:00
|
|
|
|
|
|
|
if( wxMessageBox( msg, _( "STEP Export" ), wxYES_NO | wxICON_QUESTION, this ) == wxNO )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
void DIALOG_EXPORT_STEP::onSelectOrigin( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
// If a new checkbox was checked: ensure other options are disabled
|
|
|
|
wxCheckBox* cbList[]
|
|
|
|
{
|
|
|
|
m_cbPlotOrigin, m_cbGridOrigin, m_cbUserOrigin, m_cbBoardCenter, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
if( event.IsChecked() )
|
|
|
|
{
|
|
|
|
for( int ii = 0; cbList[ii]; ii++ )
|
|
|
|
{
|
|
|
|
if( cbList[ii] != event.GetEventObject() )
|
|
|
|
cbList[ii]->SetValue( false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable/disable the user origin widgets:
|
|
|
|
m_STEP_OrgUnitChoice->Enable( m_cbUserOrigin->IsChecked() );
|
|
|
|
m_STEP_Xorg->Enable( m_cbUserOrigin->IsChecked() );
|
|
|
|
m_STEP_Yorg->Enable( m_cbUserOrigin->IsChecked() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DIALOG_EXPORT_STEP::STEP_ORG_OPT DIALOG_EXPORT_STEP::GetOriginOption()
|
|
|
|
{
|
|
|
|
m_STEP_org_opt = STEP_ORG_0;
|
|
|
|
|
|
|
|
if( m_cbPlotOrigin->IsChecked() )
|
|
|
|
m_STEP_org_opt = STEP_ORG_PLOT_AXIS;
|
|
|
|
else if( m_cbGridOrigin->IsChecked() )
|
|
|
|
m_STEP_org_opt = STEP_ORG_GRID_AXIS;
|
|
|
|
else if( m_cbUserOrigin->IsChecked() )
|
|
|
|
m_STEP_org_opt = STEP_ORG_USER;
|
|
|
|
else if( m_cbBoardCenter->IsChecked() )
|
|
|
|
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();
|
2016-09-21 23:03:00 +00:00
|
|
|
wxString brdName;
|
2016-09-19 07:40:36 +00:00
|
|
|
|
|
|
|
if( GetScreen()->IsModify() || brdFile.GetFullPath().empty() )
|
|
|
|
{
|
2016-09-20 22:55:35 +00:00
|
|
|
if( !doAutoSave() )
|
2016-09-19 07:40:36 +00:00
|
|
|
{
|
2017-08-09 17:17:26 +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
|
|
|
}
|
|
|
|
|
2016-09-20 22:55:35 +00:00
|
|
|
brdFile = GetBoard()->GetFileName();
|
|
|
|
brdName = GetAutoSaveFilePrefix();
|
|
|
|
brdName.append( brdFile.GetName() );
|
|
|
|
brdFile.SetName( brdName );
|
2016-09-19 07:40:36 +00:00
|
|
|
}
|
|
|
|
|
2016-09-21 23:03:00 +00:00
|
|
|
brdName = "\"";
|
|
|
|
brdName.Append( brdFile.GetFullPath() );
|
|
|
|
brdName.Append( "\"" );
|
|
|
|
|
2016-09-19 07:40:36 +00:00
|
|
|
// Build default output file name
|
|
|
|
brdFile = GetBoard()->GetFileName();
|
|
|
|
wxString brdExt = brdFile.GetExt();
|
2016-09-21 23:03:00 +00:00
|
|
|
brdFile.SetExt( "stp" );
|
2016-09-19 07:40:36 +00:00
|
|
|
|
|
|
|
DIALOG_EXPORT_STEP dlg( this );
|
|
|
|
dlg.FilePicker()->SetPath( brdFile.GetFullPath() );
|
|
|
|
|
2017-08-09 17:17:26 +00:00
|
|
|
if ( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2017-08-09 17:17:26 +00:00
|
|
|
wxString outputFile = dlg.FilePicker()->GetPath();
|
|
|
|
brdFile.SetExt( brdExt );
|
2016-09-21 23:03:00 +00:00
|
|
|
outputFile.Prepend( "\"" );
|
|
|
|
outputFile.Append( "\"" );
|
2016-09-19 07:40:36 +00:00
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
DIALOG_EXPORT_STEP::STEP_ORG_OPT orgOpt = dlg.GetOriginOption();
|
|
|
|
double xOrg = 0.0;
|
|
|
|
double yOrg = 0.0;
|
2016-09-19 07:40:36 +00:00
|
|
|
|
|
|
|
wxFileName appK2S( wxStandardPaths::Get().GetExecutablePath() );
|
|
|
|
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
|
|
|
|
2017-08-10 12:25:31 +00:00
|
|
|
if( dlg.GetNoVirtOption() )
|
2016-09-19 08:07:39 +00:00
|
|
|
cmdK2S.Append( " --no-virtual" );
|
|
|
|
|
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:
|
|
|
|
{
|
|
|
|
xOrg = dlg.GetXOrg();
|
|
|
|
yOrg = dlg.GetYOrg();
|
|
|
|
|
|
|
|
if( dlg.GetOrgUnitsChoice() == 1 )
|
|
|
|
{
|
|
|
|
// selected reference unit is in inches, and STEP units are mm
|
|
|
|
xOrg *= 25.4;
|
|
|
|
yOrg *= 25.4;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOCALE_IO dummy;
|
|
|
|
cmdK2S.Append( wxString::Format( " --user-origin %.6fx%.6f", xOrg, yOrg ) );
|
|
|
|
}
|
|
|
|
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:
|
|
|
|
{
|
|
|
|
EDA_RECT bbox = GetBoard()->ComputeBoundingBox( true );
|
|
|
|
xOrg = Iu2Millimeter( bbox.GetCenter().x );
|
|
|
|
yOrg = Iu2Millimeter( bbox.GetCenter().y );
|
|
|
|
LOCALE_IO dummy;
|
|
|
|
cmdK2S.Append( wxString::Format( " --user-origin %.6fx%.6f", xOrg, yOrg ) );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-09-19 07:40:36 +00:00
|
|
|
|
|
|
|
cmdK2S.Append( " -f -o " );
|
|
|
|
cmdK2S.Append( outputFile );
|
|
|
|
|
|
|
|
cmdK2S.Append( " " );
|
|
|
|
cmdK2S.Append( brdName );
|
|
|
|
|
2016-09-21 23:03:00 +00:00
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
wxBusyCursor dummy;
|
|
|
|
result = wxExecute( cmdK2S, wxEXEC_SYNC | wxEXEC_HIDE_CONSOLE );
|
|
|
|
} while( 0 );
|
|
|
|
|
|
|
|
if( result )
|
2016-09-19 07:40:36 +00:00
|
|
|
{
|
2017-08-09 17:17:26 +00:00
|
|
|
DisplayErrorMessage( this, _( "Unable to create STEP file. Check that the board has a "
|
|
|
|
"valid outline and models." ), cmdK2S );
|
2016-09-19 07:40:36 +00:00
|
|
|
}
|
|
|
|
}
|