Add debugging support for KiCad2Step command line generation.
This commit is contained in:
parent
9cda5e200c
commit
4f3db82c68
|
@ -53,6 +53,7 @@ const wxChar* const traceDisplayLocation = wxT( "KICAD_DISPLAY_LOCATION" );
|
||||||
const wxChar* const traceSchSheetPaths = wxT( "KICAD_SCH_SHEET_PATHS" );
|
const wxChar* const traceSchSheetPaths = wxT( "KICAD_SCH_SHEET_PATHS" );
|
||||||
const wxChar* const traceEnvVars = wxT( "KICAD_ENV_VARS" );
|
const wxChar* const traceEnvVars = wxT( "KICAD_ENV_VARS" );
|
||||||
const wxChar* const traceGalProfile = wxT( "KICAD_GAL_PROFILE" );
|
const wxChar* const traceGalProfile = wxT( "KICAD_GAL_PROFILE" );
|
||||||
|
const wxChar* const traceKiCad2Step = wxT( "KICAD2STEP" );
|
||||||
|
|
||||||
|
|
||||||
wxString dump( const wxArrayString& aArray )
|
wxString dump( const wxArrayString& aArray )
|
||||||
|
|
|
@ -205,6 +205,13 @@ extern const wxChar* const traceEnvVars;
|
||||||
*/
|
*/
|
||||||
extern const wxChar* const traceGalProfile;
|
extern const wxChar* const traceGalProfile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag to enable KiCad2Step debug tracing.
|
||||||
|
*
|
||||||
|
* Use "KICAD2STEP" to enable.
|
||||||
|
*/
|
||||||
|
extern const wxChar* const traceKiCad2Step;
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <wx/choicdlg.h>
|
#include <wx/choicdlg.h>
|
||||||
|
#include <wx/log.h>
|
||||||
#include <wx/stdpaths.h>
|
#include <wx/stdpaths.h>
|
||||||
#include <wx/process.h>
|
#include <wx/process.h>
|
||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
@ -39,15 +40,18 @@
|
||||||
#include <pcbnew_settings.h>
|
#include <pcbnew_settings.h>
|
||||||
#include <project/project_file.h> // LAST_PATH_TYPE
|
#include <project/project_file.h> // LAST_PATH_TYPE
|
||||||
#include <reporter.h>
|
#include <reporter.h>
|
||||||
|
#include <trace_helpers.h>
|
||||||
#include <widgets/text_ctrl_eval.h>
|
#include <widgets/text_ctrl_eval.h>
|
||||||
#include <wildcards_and_files_ext.h>
|
#include <wildcards_and_files_ext.h>
|
||||||
#include <filename_resolver.h>
|
#include <filename_resolver.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef KICAD_STEP_EXPORT_LIB
|
#ifdef KICAD_STEP_EXPORT_LIB
|
||||||
#include <kicad2step.h>
|
#include <kicad2step.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class DIALOG_EXPORT_STEP: public DIALOG_EXPORT_STEP_BASE
|
|
||||||
|
class DIALOG_EXPORT_STEP : public DIALOG_EXPORT_STEP_BASE
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum STEP_ORG_OPT
|
enum STEP_ORG_OPT
|
||||||
|
@ -59,15 +63,8 @@ public:
|
||||||
STEP_ORG_USER, // origin is entered by user
|
STEP_ORG_USER, // origin is entered by user
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& aBoardPath );
|
||||||
PCB_EDIT_FRAME* m_parent;
|
~DIALOG_EXPORT_STEP();
|
||||||
STEP_ORG_OPT m_STEP_org_opt; // The last preference for STEP Origin:
|
|
||||||
bool m_noVirtual; // remember last preference for No Virtual Component
|
|
||||||
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
|
|
||||||
wxString m_boardPath; // path to the exported board file
|
|
||||||
static int m_toleranceLastChoice; // Store m_tolerance option during a session
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onUpdateUnits( wxUpdateUIEvent& aEvent ) override;
|
void onUpdateUnits( wxUpdateUIEvent& aEvent ) override;
|
||||||
|
@ -107,13 +104,21 @@ protected:
|
||||||
return m_cbOverwriteFile->GetValue();
|
return m_cbOverwriteFile->GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
private:
|
||||||
DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& aBoardPath );
|
PCB_EDIT_FRAME* m_parent;
|
||||||
~DIALOG_EXPORT_STEP();
|
STEP_ORG_OPT m_STEP_org_opt; // The last preference for STEP Origin:
|
||||||
|
bool m_noVirtual; // remember last preference for No Virtual Component
|
||||||
|
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
|
||||||
|
wxString m_boardPath; // path to the exported board file
|
||||||
|
static int m_toleranceLastChoice; // Store m_tolerance option during a session
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int DIALOG_EXPORT_STEP::m_toleranceLastChoice = -1; // Use default
|
int DIALOG_EXPORT_STEP::m_toleranceLastChoice = -1; // Use default
|
||||||
|
|
||||||
|
|
||||||
DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& aBoardPath ) :
|
DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& aBoardPath ) :
|
||||||
DIALOG_EXPORT_STEP_BASE( aParent )
|
DIALOG_EXPORT_STEP_BASE( aParent )
|
||||||
{
|
{
|
||||||
|
@ -144,7 +149,7 @@ DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString&
|
||||||
_( "STEP files" ) + AddFileExtListToFilter( { "STEP", "STP" } ),
|
_( "STEP files" ) + AddFileExtListToFilter( { "STEP", "STP" } ),
|
||||||
wxDefaultPosition,
|
wxDefaultPosition,
|
||||||
wxSize( -1, -1 ), wxFLP_SAVE | wxFLP_USE_TEXTCTRL );
|
wxSize( -1, -1 ), wxFLP_SAVE | wxFLP_USE_TEXTCTRL );
|
||||||
bSizerTop->Add( m_filePickerSTEP, 1, wxTOP|wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
|
bSizerTop->Add( m_filePickerSTEP, 1, wxTOP | wxRIGHT | wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
|
||||||
|
|
||||||
m_filePickerSTEP->SetPath( path );
|
m_filePickerSTEP->SetPath( path );
|
||||||
|
|
||||||
|
@ -159,11 +164,11 @@ DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString&
|
||||||
|
|
||||||
switch( m_STEP_org_opt )
|
switch( m_STEP_org_opt )
|
||||||
{
|
{
|
||||||
default: break;
|
default: break;
|
||||||
case STEP_ORG_PLOT_AXIS: m_rbDrillAndPlotOrigin->SetValue( true ); break;
|
case STEP_ORG_PLOT_AXIS: m_rbDrillAndPlotOrigin->SetValue( true ); break;
|
||||||
case STEP_ORG_GRID_AXIS: m_rbGridOrigin->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_USER: m_rbUserDefinedOrigin->SetValue( true ); break;
|
||||||
case STEP_ORG_BOARD_CENTER: m_rbBoardCenterOrigin->SetValue( true ); break;
|
case STEP_ORG_BOARD_CENTER: m_rbBoardCenterOrigin->SetValue( true ); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_OrgUnits = cfg->m_ExportStep.origin_units;
|
m_OrgUnits = cfg->m_ExportStep.origin_units;
|
||||||
|
@ -333,6 +338,7 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
|
||||||
// Check if the board outline is continuous
|
// Check if the board outline is continuous
|
||||||
// max dist from one endPt to next startPt to build a closed shape:
|
// max dist from one endPt to next startPt to build a closed shape:
|
||||||
int chainingEpsilon = Millimeter2iu( tolerance );
|
int chainingEpsilon = Millimeter2iu( tolerance );
|
||||||
|
|
||||||
// Arc to segment approx error (not critical here: we do not use the outline shape):
|
// Arc to segment approx error (not critical here: we do not use the outline shape):
|
||||||
int maxError = Millimeter2iu( 0.005 );
|
int maxError = Millimeter2iu( 0.005 );
|
||||||
bool success = BuildBoardPolygonOutlines( m_parent->GetBoard(), outline, maxError,
|
bool success = BuildBoardPolygonOutlines( m_parent->GetBoard(), outline, maxError,
|
||||||
|
@ -367,17 +373,16 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
|
||||||
|
|
||||||
#ifndef KICAD_STEP_EXPORT_LIB
|
#ifndef KICAD_STEP_EXPORT_LIB
|
||||||
wxFileName appK2S( wxStandardPaths::Get().GetExecutablePath() );
|
wxFileName appK2S( wxStandardPaths::Get().GetExecutablePath() );
|
||||||
|
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
// On macOS, we have standalone applications inside the main bundle, so we handle that here:
|
// On macOS, we have standalone applications inside the main bundle, so we handle that here:
|
||||||
if( appK2S.GetPath().Find( "/Contents/Applications/pcbnew.app/Contents/MacOS" ) != wxNOT_FOUND )
|
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( ".." ) );
|
appK2S.AppendDir( wxT( ".." ) );
|
||||||
appK2S.AppendDir( wxT( ".." ) );
|
appK2S.AppendDir( wxT( ".." ) );
|
||||||
appK2S.AppendDir( wxT( "MacOS" ) );
|
appK2S.AppendDir( wxT( "MacOS" ) );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
appK2S.SetName( wxT( "kicad2step" ) );
|
appK2S.SetName( wxT( "kicad2step" ) );
|
||||||
|
@ -398,45 +403,45 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
|
||||||
|
|
||||||
switch( orgOpt )
|
switch( orgOpt )
|
||||||
{
|
{
|
||||||
case DIALOG_EXPORT_STEP::STEP_ORG_0:
|
case DIALOG_EXPORT_STEP::STEP_ORG_0:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DIALOG_EXPORT_STEP::STEP_ORG_PLOT_AXIS:
|
case DIALOG_EXPORT_STEP::STEP_ORG_PLOT_AXIS:
|
||||||
cmdK2S.Append( wxT( " --drill-origin" ) );
|
cmdK2S.Append( wxT( " --drill-origin" ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DIALOG_EXPORT_STEP::STEP_ORG_GRID_AXIS:
|
case DIALOG_EXPORT_STEP::STEP_ORG_GRID_AXIS:
|
||||||
cmdK2S.Append( wxT( " --grid-origin" ) );
|
cmdK2S.Append( wxT( " --grid-origin" ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DIALOG_EXPORT_STEP::STEP_ORG_USER:
|
case DIALOG_EXPORT_STEP::STEP_ORG_USER:
|
||||||
|
{
|
||||||
|
xOrg = GetXOrg();
|
||||||
|
yOrg = GetYOrg();
|
||||||
|
|
||||||
|
if( GetOrgUnitsChoice() == 1 )
|
||||||
{
|
{
|
||||||
xOrg = GetXOrg();
|
// selected reference unit is in inches, and STEP units are mm
|
||||||
yOrg = GetYOrg();
|
xOrg *= 25.4;
|
||||||
|
yOrg *= 25.4;
|
||||||
if( 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( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
|
|
||||||
quote, xOrg, yOrg, quote ) );
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case DIALOG_EXPORT_STEP::STEP_ORG_BOARD_CENTER:
|
LOCALE_IO dummy;
|
||||||
{
|
cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
|
||||||
BOX2I bbox = m_parent->GetBoard()->ComputeBoundingBox( true );
|
quote, xOrg, yOrg, quote ) );
|
||||||
xOrg = Iu2Millimeter( bbox.GetCenter().x );
|
break;
|
||||||
yOrg = Iu2Millimeter( bbox.GetCenter().y );
|
}
|
||||||
LOCALE_IO dummy;
|
|
||||||
cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
|
case DIALOG_EXPORT_STEP::STEP_ORG_BOARD_CENTER:
|
||||||
quote, xOrg, yOrg, quote ) );
|
{
|
||||||
}
|
BOX2I bbox = m_parent->GetBoard()->ComputeBoundingBox( true );
|
||||||
break;
|
xOrg = Iu2Millimeter( bbox.GetCenter().x );
|
||||||
|
yOrg = Iu2Millimeter( bbox.GetCenter().y );
|
||||||
|
LOCALE_IO dummy;
|
||||||
|
cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
|
||||||
|
quote, xOrg, yOrg, quote ) );
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -445,12 +450,15 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
|
||||||
quote, tolerance, quote ) );
|
quote, tolerance, quote ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Input file path.
|
||||||
cmdK2S.Append( wxString::Format( wxT( " -f -o %c%s%c" ),
|
cmdK2S.Append( wxString::Format( wxT( " -f -o %c%s%c" ),
|
||||||
quote, m_filePickerSTEP->GetPath(), quote ) ); // input file path
|
quote, m_filePickerSTEP->GetPath(), quote ) );
|
||||||
|
|
||||||
cmdK2S.Append( wxString::Format( wxT( " %c%s%c" ),
|
|
||||||
quote, m_boardPath, quote ) ); // output file path
|
|
||||||
|
|
||||||
|
// Output file path.
|
||||||
|
cmdK2S.Append( wxString::Format( wxT( " %c%s%c" ), quote, m_boardPath, quote ) );
|
||||||
|
|
||||||
|
wxLogTrace( traceKiCad2Step, wxT( "KiCad2Step command: %s" ), cmdK2S );
|
||||||
wxExecute( cmdK2S, wxEXEC_ASYNC | wxEXEC_SHOW_CONSOLE );
|
wxExecute( cmdK2S, wxEXEC_ASYNC | wxEXEC_SHOW_CONSOLE );
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -467,43 +475,43 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
|
||||||
|
|
||||||
switch( orgOpt )
|
switch( orgOpt )
|
||||||
{
|
{
|
||||||
case DIALOG_EXPORT_STEP::STEP_ORG_0:
|
case DIALOG_EXPORT_STEP::STEP_ORG_0:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DIALOG_EXPORT_STEP::STEP_ORG_PLOT_AXIS:
|
case DIALOG_EXPORT_STEP::STEP_ORG_PLOT_AXIS:
|
||||||
params.m_useDrillOrigin = true;
|
params.m_useDrillOrigin = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DIALOG_EXPORT_STEP::STEP_ORG_GRID_AXIS:
|
case DIALOG_EXPORT_STEP::STEP_ORG_GRID_AXIS:
|
||||||
params.m_useGridOrigin = true;
|
params.m_useGridOrigin = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DIALOG_EXPORT_STEP::STEP_ORG_USER:
|
case DIALOG_EXPORT_STEP::STEP_ORG_USER:
|
||||||
|
{
|
||||||
|
xOrg = GetXOrg();
|
||||||
|
yOrg = GetYOrg();
|
||||||
|
|
||||||
|
if( GetOrgUnitsChoice() == 1 )
|
||||||
{
|
{
|
||||||
xOrg = GetXOrg();
|
// selected reference unit is in inches, and STEP units are mm
|
||||||
yOrg = GetYOrg();
|
xOrg *= 25.4;
|
||||||
|
yOrg *= 25.4;
|
||||||
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:
|
params.m_xOrigin = xOrg;
|
||||||
{
|
params.m_yOrigin = yOrg;
|
||||||
BOX2I bbox = m_parent->GetBoard()->ComputeBoundingBox( true );
|
break;
|
||||||
xOrg = Iu2Millimeter( bbox.GetCenter().x );
|
}
|
||||||
yOrg = Iu2Millimeter( bbox.GetCenter().y );
|
|
||||||
params.m_xOrigin = xOrg;
|
case DIALOG_EXPORT_STEP::STEP_ORG_BOARD_CENTER:
|
||||||
params.m_yOrigin = yOrg;
|
{
|
||||||
}
|
BOX2I bbox = m_parent->GetBoard()->ComputeBoundingBox( true );
|
||||||
break;
|
xOrg = Iu2Millimeter( bbox.GetCenter().x );
|
||||||
|
yOrg = Iu2Millimeter( bbox.GetCenter().y );
|
||||||
|
params.m_xOrigin = xOrg;
|
||||||
|
params.m_yOrigin = yOrg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KICAD2STEP converter( params );
|
KICAD2STEP converter( params );
|
||||||
|
|
Loading…
Reference in New Issue