Add debugging support for KiCad2Step command line generation.

This commit is contained in:
Wayne Stambaugh 2022-09-12 14:01:48 -04:00
parent 9cda5e200c
commit 4f3db82c68
3 changed files with 111 additions and 95 deletions

View File

@ -53,6 +53,7 @@ const wxChar* const traceDisplayLocation = wxT( "KICAD_DISPLAY_LOCATION" );
const wxChar* const traceSchSheetPaths = wxT( "KICAD_SCH_SHEET_PATHS" );
const wxChar* const traceEnvVars = wxT( "KICAD_ENV_VARS" );
const wxChar* const traceGalProfile = wxT( "KICAD_GAL_PROFILE" );
const wxChar* const traceKiCad2Step = wxT( "KICAD2STEP" );
wxString dump( const wxArrayString& aArray )

View File

@ -205,6 +205,13 @@ extern const wxChar* const traceEnvVars;
*/
extern const wxChar* const traceGalProfile;
/**
* Flag to enable KiCad2Step debug tracing.
*
* Use "KICAD2STEP" to enable.
*/
extern const wxChar* const traceKiCad2Step;
///@}
/**

View File

@ -23,6 +23,7 @@
*/
#include <wx/choicdlg.h>
#include <wx/log.h>
#include <wx/stdpaths.h>
#include <wx/process.h>
#include <wx/string.h>
@ -39,14 +40,17 @@
#include <pcbnew_settings.h>
#include <project/project_file.h> // LAST_PATH_TYPE
#include <reporter.h>
#include <trace_helpers.h>
#include <widgets/text_ctrl_eval.h>
#include <wildcards_and_files_ext.h>
#include <filename_resolver.h>
#ifdef KICAD_STEP_EXPORT_LIB
#include <kicad2step.h>
#endif
class DIALOG_EXPORT_STEP : public DIALOG_EXPORT_STEP_BASE
{
public:
@ -59,15 +63,8 @@ public:
STEP_ORG_USER, // origin is entered by user
};
private:
PCB_EDIT_FRAME* m_parent;
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
DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& aBoardPath );
~DIALOG_EXPORT_STEP();
protected:
void onUpdateUnits( wxUpdateUIEvent& aEvent ) override;
@ -107,13 +104,21 @@ protected:
return m_cbOverwriteFile->GetValue();
}
public:
DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& aBoardPath );
~DIALOG_EXPORT_STEP();
private:
PCB_EDIT_FRAME* m_parent;
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
DIALOG_EXPORT_STEP::DIALOG_EXPORT_STEP( PCB_EDIT_FRAME* aParent, const wxString& aBoardPath ) :
DIALOG_EXPORT_STEP_BASE( aParent )
{
@ -333,6 +338,7 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
// Check if the board outline is continuous
// 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,
@ -367,7 +373,6 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
#ifndef KICAD_STEP_EXPORT_LIB
wxFileName appK2S( wxStandardPaths::Get().GetExecutablePath() );
#ifdef __WXMAC__
// 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 )
@ -424,8 +429,8 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
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:
{
@ -435,9 +440,9 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
LOCALE_IO dummy;
cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
quote, xOrg, yOrg, quote ) );
}
break;
}
}
{
LOCALE_IO dummy;
@ -445,12 +450,15 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
quote, tolerance, quote ) );
}
// Input file path.
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 );
#else
@ -492,8 +500,8 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
params.m_xOrigin = xOrg;
params.m_yOrigin = yOrg;
}
break;
}
case DIALOG_EXPORT_STEP::STEP_ORG_BOARD_CENTER:
{
@ -502,9 +510,9 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
yOrg = Iu2Millimeter( bbox.GetCenter().y );
params.m_xOrigin = xOrg;
params.m_yOrigin = yOrg;
}
break;
}
}
KICAD2STEP converter( params );
converter.Run();