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 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 )

View File

@ -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;
///@} ///@}
/** /**

View File

@ -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,14 +40,17 @@
#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:
@ -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 )
{ {
@ -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,7 +373,6 @@ 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 )
@ -424,8 +429,8 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
LOCALE_IO dummy; LOCALE_IO dummy;
cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ), cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
quote, xOrg, yOrg, quote ) ); quote, xOrg, yOrg, quote ) );
}
break; break;
}
case DIALOG_EXPORT_STEP::STEP_ORG_BOARD_CENTER: case DIALOG_EXPORT_STEP::STEP_ORG_BOARD_CENTER:
{ {
@ -435,9 +440,9 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
LOCALE_IO dummy; LOCALE_IO dummy;
cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ), cmdK2S.Append( wxString::Format( wxT( " --user-origin=%c%.6fx%.6fmm%c" ),
quote, xOrg, yOrg, quote ) ); quote, xOrg, yOrg, quote ) );
}
break; break;
} }
}
{ {
LOCALE_IO dummy; LOCALE_IO dummy;
@ -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
@ -492,8 +500,8 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
params.m_xOrigin = xOrg; params.m_xOrigin = xOrg;
params.m_yOrigin = yOrg; params.m_yOrigin = yOrg;
}
break; break;
}
case DIALOG_EXPORT_STEP::STEP_ORG_BOARD_CENTER: case DIALOG_EXPORT_STEP::STEP_ORG_BOARD_CENTER:
{ {
@ -502,9 +510,9 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent )
yOrg = Iu2Millimeter( bbox.GetCenter().y ); yOrg = Iu2Millimeter( bbox.GetCenter().y );
params.m_xOrigin = xOrg; params.m_xOrigin = xOrg;
params.m_yOrigin = yOrg; params.m_yOrigin = yOrg;
}
break; break;
} }
}
KICAD2STEP converter( params ); KICAD2STEP converter( params );
converter.Run(); converter.Run();