From 74fd23f573d428beac44c6e79d149e87396b1152 Mon Sep 17 00:00:00 2001 From: Marek Roszko Date: Sat, 11 Sep 2021 12:40:20 -0400 Subject: [PATCH] Add (off by default) build option to link kicad2step directly into pcbnew Because debugging it separately is annoying. --- CMakeLists.txt | 3 + pcbnew/CMakeLists.txt | 11 ++ pcbnew/dialogs/dialog_export_step.cpp | 64 ++++++- utils/kicad2step/CMakeLists.txt | 29 +-- utils/kicad2step/kicad2step.cpp | 264 ++++---------------------- utils/kicad2step/kicad2step.h | 69 +++++++ utils/kicad2step/kicad2step_app.cpp | 237 +++++++++++++++++++++++ utils/kicad2step/panel_kicad2step.h | 24 +-- utils/kicad2step/pcb/base.h | 6 +- 9 files changed, 448 insertions(+), 259 deletions(-) create mode 100644 utils/kicad2step/kicad2step.h create mode 100644 utils/kicad2step/kicad2step_app.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 22847969c5..44a6648e9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,6 +156,9 @@ cmake_dependent_option( KICAD_WIN32_INSTALL_PDBS OFF "WIN32" OFF ) +option( KICAD_STEP_EXPORT_LIB + "Build and use kicad2step as a library, meant for debugging" + OFF ) # Global setting: exports are explicit set( CMAKE_CXX_VISIBILITY_PRESET "hidden" ) diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index bc1dc2984d..87f2bca386 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -655,6 +655,17 @@ add_dependencies( pcbnew_kiface_objects dxflib_qcad ) add_dependencies( pcbnew_kiface_objects tinyspline_lib ) add_dependencies( pcbnew_kiface_objects nanosvg ) +if( KICAD_STEP_EXPORT_LIB ) + target_include_directories( pcbnew_kiface_objects PRIVATE + $ + ) + add_dependencies( pcbnew_kiface_objects kicad2step_lib ) + + list( APPEND PCBNEW_EXTRA_LIBS kicad2step_lib ) + + add_definitions( -DKICAD_STEP_EXPORT_LIB ) +endif() + add_library( pcbnew_kiface MODULE $ ) set_target_properties( pcbnew_kiface PROPERTIES diff --git a/pcbnew/dialogs/dialog_export_step.cpp b/pcbnew/dialogs/dialog_export_step.cpp index 3173f737b1..a01c4df4e1 100644 --- a/pcbnew/dialogs/dialog_export_step.cpp +++ b/pcbnew/dialogs/dialog_export_step.cpp @@ -43,6 +43,10 @@ #include #include +#ifdef KICAD_STEP_EXPORT_LIB +#include +#endif + class DIALOG_EXPORT_STEP: public DIALOG_EXPORT_STEP_BASE { public: @@ -358,6 +362,7 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent ) double xOrg = 0.0; double yOrg = 0.0; +#ifndef KICAD_STEP_EXPORT_LIB wxFileName appK2S( wxStandardPaths::Get().GetExecutablePath() ); #ifdef __WXMAC__ @@ -438,5 +443,62 @@ void DIALOG_EXPORT_STEP::onExportButton( wxCommandEvent& aEvent ) wxExecute( cmdK2S, wxEXEC_ASYNC | wxEXEC_SHOW_CONSOLE ); - aEvent.Skip(); // Close the dialog + #else + + KICAD2MCAD_PRMS params; + params.m_filename = m_boardPath; + params.m_outputFile = m_filePickerSTEP->GetPath(); + + params.m_includeVirtual = !GetNoVirtOption(); + + params.m_substModels = GetSubstOption(); + params.m_minDistance = tolerance; + params.m_overwrite = true; + + switch( orgOpt ) + { + case DIALOG_EXPORT_STEP::STEP_ORG_0: + break; + + case DIALOG_EXPORT_STEP::STEP_ORG_PLOT_AXIS: + params.m_useDrillOrigin = true; + break; + + case DIALOG_EXPORT_STEP::STEP_ORG_GRID_AXIS: + params.m_useGridOrigin = true; + break; + + case DIALOG_EXPORT_STEP::STEP_ORG_USER: + { + xOrg = GetXOrg(); + yOrg = GetYOrg(); + + 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: + { + EDA_RECT bbox = m_parent->GetBoard()->ComputeBoundingBox( true ); + xOrg = Iu2Millimeter( bbox.GetCenter().x ); + yOrg = Iu2Millimeter( bbox.GetCenter().y ); + params.m_xOrigin = xOrg; + params.m_yOrigin = yOrg; + } + break; + } + + KICAD2STEP converter( params ); + converter.Run(); + #endif + + aEvent.Skip(); // Close the dialog } diff --git a/utils/kicad2step/CMakeLists.txt b/utils/kicad2step/CMakeLists.txt index fda9ad5a1f..f816ae4939 100644 --- a/utils/kicad2step/CMakeLists.txt +++ b/utils/kicad2step/CMakeLists.txt @@ -16,6 +16,10 @@ set( KS2_LIB_FILES pcb/oce_utils.cpp ) +if( MINGW ) + list( APPEND KS2_LIB_FILES ${CMAKE_SOURCE_DIR}/common/streamwrapper.cpp ) +endif( MINGW ) + # Break the library out for re-use by both kicad2step and any qa that needs it # In future, this could move for re-use by other programs needing s-expr support (?) add_library( kicad2step_lib STATIC @@ -30,40 +34,43 @@ target_include_directories( kicad2step_lib PUBLIC target_link_libraries( kicad2step_lib sexpr + ${wxWidgets_LIBRARIES} + ${OCC_LIBRARIES} + ${ZLIB_LIBRARIES} ) set( K2S_FILES - kicad2step.cpp + kicad2step_app.cpp ) if( MINGW ) list( APPEND K2S_FILES ${CMAKE_SOURCE_DIR}/common/streamwrapper.cpp ) endif( MINGW ) -add_executable( kicad2step WIN32 ${K2S_FILES} ) +add_executable( kicad2step_bin WIN32 ${K2S_FILES} ) -target_link_libraries( kicad2step - kicad2step_lib - ${wxWidgets_LIBRARIES} - ${OCC_LIBRARIES} - ${ZLIB_LIBRARIES} ) +target_link_libraries( kicad2step_bin + kicad2step_lib ) target_include_directories( kicad2step_lib PRIVATE $ ) +set_target_properties( kicad2step_bin + PROPERTIES OUTPUT_NAME kicad2step) + if( APPLE ) # puts binaries into the *.app bundle while linking - set_target_properties( kicad2step PROPERTIES + set_target_properties( kicad2step_bin PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_BIN_DIR} ) else() - install( TARGETS kicad2step - DESTINATION ${KICAD_BIN} + install( TARGETS kicad2step_bin kicad2step_lib + RUNTIME DESTINATION ${KICAD_BIN} COMPONENT binary ) endif() if( KICAD_WIN32_INSTALL_PDBS ) # Get the PDBs to copy over for MSVC - install(FILES $ DESTINATION ${KICAD_BIN}) + install(FILES $ DESTINATION ${KICAD_BIN}) endif() \ No newline at end of file diff --git a/utils/kicad2step/kicad2step.cpp b/utils/kicad2step/kicad2step.cpp index b667dd4077..ca83c31c88 100644 --- a/utils/kicad2step/kicad2step.cpp +++ b/utils/kicad2step/kicad2step.cpp @@ -32,44 +32,26 @@ #include #include +#include "kicad2step.h" #include "pcb/kicadpcb.h" #include "kicad2step_frame_base.h" #include "panel_kicad2step.h" #include // In open cascade -class KICAD2STEP_FRAME; - -class KICAD2MCAD_APP : public wxApp -{ -public: - KICAD2MCAD_APP() : - wxApp(), - m_Panel( nullptr ), - m_frame( nullptr ) - {} - - virtual bool OnInit() override; - virtual int OnRun() override; - virtual void OnInitCmdLine(wxCmdLineParser& parser) override; - virtual bool OnCmdLineParsed(wxCmdLineParser& parser) override; - - PANEL_KICAD2STEP* m_Panel; - -private: - KICAD2STEP_FRAME* m_frame; - KICAD2MCAD_PRMS m_params; -}; - - -wxIMPLEMENT_APP( KICAD2MCAD_APP ); - - class KICAD2STEP_FRAME : public KICAD2STEP_FRAME_BASE { public: KICAD2STEP_FRAME( const wxString& title ); }; +// Horrible hack until we decouple things more +static PANEL_KICAD2STEP* openPanel = nullptr; +void ReportMessage( const wxString& aMessage ) +{ + if( openPanel != nullptr ) + openPanel->AppendMessage( aMessage ); +} + KICAD2MCAD_PRMS::KICAD2MCAD_PRMS() { @@ -88,90 +70,11 @@ KICAD2MCAD_PRMS::KICAD2MCAD_PRMS() } -void ReportMessage( const wxString& aMessage ) -{ - KICAD2MCAD_APP& app = wxGetApp(); - app.m_Panel->AppendMessage( aMessage ); -} - - -static const wxCmdLineEntryDesc cmdLineDesc[] = { - { wxCMD_LINE_PARAM, NULL, NULL, _( "pcb_filename" ).mb_str(), wxCMD_LINE_VAL_STRING, - wxCMD_LINE_OPTION_MANDATORY }, - { wxCMD_LINE_OPTION, "o", "output-filename", _( "output filename" ).mb_str(), - wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, - -#ifdef SUPPORTS_IGES - { wxCMD_LINE_SWITCH, "fmt-iges", NULL, _( "IGES output (default STEP)" ).mb_str(), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, -#endif - - { wxCMD_LINE_SWITCH, "f", "force", _( "overwrite output file" ).mb_str(), wxCMD_LINE_VAL_NONE, - wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_SWITCH, NULL, "drill-origin", _( "Use Drill Origin for output origin" ).mb_str(), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_SWITCH, NULL, "grid-origin", _( "Use Grid Origin for output origin" ).mb_str(), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_OPTION, NULL, "user-origin", - _( "User-specified output origin ex. 1x1in, 1x1inch, 25.4x25.4mm (default mm)" ).mb_str(), - wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_SWITCH, NULL, "no-virtual", - _( "Exclude 3D models for components with 'virtual' attribute" ).mb_str(), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_SWITCH, NULL, "subst-models", - _( "Substitute STEP or IGS models with the same name in place of VRML models" ).mb_str(), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_OPTION, NULL, "min-distance", - _( "Minimum distance between points to treat them as separate ones (default 0.01 mm)" ) - .mb_str(), - wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_SWITCH, "h", NULL, _( "display this message" ).mb_str(), wxCMD_LINE_VAL_NONE, - wxCMD_LINE_OPTION_HELP }, - { wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 } -}; - - -bool KICAD2MCAD_APP::OnInit() -{ - if( !wxApp::OnInit() ) - return false; - - // create the main application window - m_frame = new KICAD2STEP_FRAME( "Kicad2step" ); - - m_Panel = m_frame->m_panelKicad2Step; - m_Panel->m_params = m_params; - - // and show it (a wxFrame is not shown when created initially) - m_frame->Show( true ); - m_frame->Iconize( false ); - - return true; -} - - -int KICAD2MCAD_APP::OnRun() -{ - int diag = m_Panel->RunConverter(); - wxApp::OnRun(); // Start the main loop event, to manage the main frame - - return diag; -} - - KICAD2STEP_FRAME::KICAD2STEP_FRAME( const wxString& title ) : KICAD2STEP_FRAME_BASE( NULL, wxID_ANY, title ) { } - -void KICAD2MCAD_APP::OnInitCmdLine( wxCmdLineParser& parser ) -{ - parser.SetDesc( cmdLineDesc ); - parser.SetSwitchChars( "-" ); -} - - PANEL_KICAD2STEP::PANEL_KICAD2STEP( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style ) @@ -195,122 +98,6 @@ void PANEL_KICAD2STEP::AppendMessage( const wxString& aMessage ) } -bool KICAD2MCAD_APP::OnCmdLineParsed( wxCmdLineParser& parser ) -{ -#ifdef SUPPORTS_IGES - if( parser.Found( "fmt-iges" ) ) - m_fmtIGES = true; -#endif - - if( parser.Found( "f" ) ) - m_params.m_overwrite = true; - - if( parser.Found( "grid-origin" ) ) - m_params.m_useGridOrigin = true; - - if( parser.Found( "drill-origin" ) ) - m_params. m_useDrillOrigin = true; - - if( parser.Found( "no-virtual" ) ) - m_params.m_includeVirtual = false; - - if( parser.Found( "subst-models" ) ) - m_params.m_substModels = true; - - wxString tstr; - - if( parser.Found( "user-origin", &tstr ) ) - { - std::istringstream istr; - istr.str( std::string( tstr.ToUTF8() ) ); - istr >> m_params.m_xOrigin; - - if( istr.fail() ) - { - parser.Usage(); - return false; - } - - char tmpc; - istr >> tmpc; - - if( istr.fail() || ( tmpc != 'x' && tmpc != 'X' ) ) - { - parser.Usage(); - return false; - } - - istr >> m_params.m_yOrigin; - - if( istr.fail() ) - { - parser.Usage(); - return false; - } - - if( !istr.eof() ) - { - std::string tunit; - istr >> tunit; - - if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) ) - { - m_params.m_xOrigin *= 25.4; - m_params.m_yOrigin *= 25.4; - } - else if( tunit.compare( "mm" ) ) - { - parser.Usage(); - return false; - } - } - } - - if( parser.Found( "min-distance", &tstr ) ) - { - std::istringstream istr; - istr.str( std::string( tstr.ToUTF8() ) ); - istr >> m_params.m_minDistance; - - if( istr.fail() ) - { - parser.Usage(); - return false; - } - - if( !istr.eof() ) - { - std::string tunit; - istr >> tunit; - - if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) ) - { - m_params.m_minDistance *= 25.4; - } - else if( tunit.compare( "mm" ) ) - { - parser.Usage(); - return false; - } - } - } - - if( parser.Found( "o", &tstr ) ) - m_params.m_outputFile = tstr; - - - if( parser.GetParamCount() < 1 ) - { - parser.Usage(); - return false; - } - - m_params.m_filename = parser.GetParam( 0 ); - - return true; -} - - // Smart class that will swap streambufs and replace them when object goes out of scope. // ( ensure the initial stream buffer is restored ) // see: @@ -477,3 +264,36 @@ wxString KICAD2MCAD_PRMS::getOutputExt() const #endif return wxString( "step" ); } + + +KICAD2STEP::KICAD2STEP( KICAD2MCAD_PRMS aParams ) : m_params( aParams ), m_panel( nullptr ) +{ +} + + +int KICAD2STEP::Run() +{ + // create the main application window + KICAD2STEP_FRAME* frame = new KICAD2STEP_FRAME( "Kicad2step" ); + + m_panel = frame->m_panelKicad2Step; + m_panel->m_params = m_params; + + // and show it (a wxFrame is not shown when created initially) + frame->Show( true ); + frame->Iconize( false ); + + openPanel = m_panel; + + int diag = m_panel->RunConverter(); + + openPanel = nullptr; + + return diag; +} + + +void KICAD2STEP::ReportMessage( const wxString& aMessage ) +{ + m_panel->AppendMessage( aMessage ); +} \ No newline at end of file diff --git a/utils/kicad2step/kicad2step.h b/utils/kicad2step/kicad2step.h new file mode 100644 index 0000000000..e8286cebda --- /dev/null +++ b/utils/kicad2step/kicad2step.h @@ -0,0 +1,69 @@ +/* + * This program source code file is part of kicad2mcad + * + * Copyright (C) 2016 Cirilo Bernardo + * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 + */ + +#ifndef KICAD2STEP_H +#define KICAD2STEP_H + +#include +#include + +class PANEL_KICAD2STEP; + +class APIEXPORT KICAD2MCAD_PRMS // A small class to handle parameters of conversion +{ +public: + KICAD2MCAD_PRMS(); + + ///< Return file extension for the selected output format + wxString getOutputExt() const; + +#ifdef SUPPORTS_IGES + bool m_fmtIGES; +#endif + bool m_overwrite; + bool m_useGridOrigin; + bool m_useDrillOrigin; + bool m_includeVirtual; + bool m_substModels; + wxString m_filename; + wxString m_outputFile; + double m_xOrigin; + double m_yOrigin; + double m_minDistance; +}; + +class APIEXPORT KICAD2STEP +{ +public: + KICAD2STEP( KICAD2MCAD_PRMS aParams ); + + int Run(); + void ReportMessage( const wxString& aMessage ); + +private: + KICAD2MCAD_PRMS m_params; + PANEL_KICAD2STEP* m_panel; +}; + +#endif \ No newline at end of file diff --git a/utils/kicad2step/kicad2step_app.cpp b/utils/kicad2step/kicad2step_app.cpp new file mode 100644 index 0000000000..ca1bda4829 --- /dev/null +++ b/utils/kicad2step/kicad2step_app.cpp @@ -0,0 +1,237 @@ +/* + * This program source code file is part of kicad2mcad + * + * Copyright (C) 2016 Cirilo Bernardo + * Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kicad2step.h" +#include "pcb/kicadpcb.h" +#include "kicad2step_frame_base.h" +#include // In open cascade + + +class KICAD2MCAD_APP : public wxApp +{ +public: + KICAD2MCAD_APP() : wxApp(), m_converter( nullptr ) {} + + virtual bool OnInit() override; + virtual int OnRun() override; + virtual void OnInitCmdLine( wxCmdLineParser& parser ) override; + virtual bool OnCmdLineParsed( wxCmdLineParser& parser ) override; + +private: + KICAD2STEP* m_converter; + KICAD2MCAD_PRMS m_params; +}; + + +wxIMPLEMENT_APP( KICAD2MCAD_APP ); + + +static const wxCmdLineEntryDesc cmdLineDesc[] = { + { wxCMD_LINE_PARAM, NULL, NULL, _( "pcb_filename" ).mb_str(), wxCMD_LINE_VAL_STRING, + wxCMD_LINE_OPTION_MANDATORY }, + { wxCMD_LINE_OPTION, "o", "output-filename", _( "output filename" ).mb_str(), + wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, + +#ifdef SUPPORTS_IGES + { wxCMD_LINE_SWITCH, "fmt-iges", NULL, _( "IGES output (default STEP)" ).mb_str(), + wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, +#endif + + { wxCMD_LINE_SWITCH, "f", "force", _( "overwrite output file" ).mb_str(), wxCMD_LINE_VAL_NONE, + wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_SWITCH, NULL, "drill-origin", _( "Use Drill Origin for output origin" ).mb_str(), + wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_SWITCH, NULL, "grid-origin", _( "Use Grid Origin for output origin" ).mb_str(), + wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_OPTION, NULL, "user-origin", + _( "User-specified output origin ex. 1x1in, 1x1inch, 25.4x25.4mm (default mm)" ).mb_str(), + wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_SWITCH, NULL, "no-virtual", + _( "Exclude 3D models for components with 'virtual' attribute" ).mb_str(), + wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_SWITCH, NULL, "subst-models", + _( "Substitute STEP or IGS models with the same name in place of VRML models" ).mb_str(), + wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_OPTION, NULL, "min-distance", + _( "Minimum distance between points to treat them as separate ones (default 0.01 mm)" ) + .mb_str(), + wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_SWITCH, "h", NULL, _( "display this message" ).mb_str(), wxCMD_LINE_VAL_NONE, + wxCMD_LINE_OPTION_HELP }, + { wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 } +}; + + +void KICAD2MCAD_APP::OnInitCmdLine( wxCmdLineParser& parser ) +{ + parser.SetDesc( cmdLineDesc ); + parser.SetSwitchChars( "-" ); +} + + +bool KICAD2MCAD_APP::OnInit() +{ + if( !wxApp::OnInit() ) + return false; + + // create the main application window + m_converter = new KICAD2STEP( m_params ); + + return true; +} + + +int KICAD2MCAD_APP::OnRun() +{ + int diag = m_converter->Run(); + wxApp::OnRun(); // Start the main loop event, to manage the main frame + + return diag; +} + + +bool KICAD2MCAD_APP::OnCmdLineParsed( wxCmdLineParser& parser ) +{ +#ifdef SUPPORTS_IGES + if( parser.Found( "fmt-iges" ) ) + m_fmtIGES = true; +#endif + + if( parser.Found( "f" ) ) + m_params.m_overwrite = true; + + if( parser.Found( "grid-origin" ) ) + m_params.m_useGridOrigin = true; + + if( parser.Found( "drill-origin" ) ) + m_params.m_useDrillOrigin = true; + + if( parser.Found( "no-virtual" ) ) + m_params.m_includeVirtual = false; + + if( parser.Found( "subst-models" ) ) + m_params.m_substModels = true; + + wxString tstr; + + if( parser.Found( "user-origin", &tstr ) ) + { + std::istringstream istr; + istr.str( std::string( tstr.ToUTF8() ) ); + istr >> m_params.m_xOrigin; + + if( istr.fail() ) + { + parser.Usage(); + return false; + } + + char tmpc; + istr >> tmpc; + + if( istr.fail() || ( tmpc != 'x' && tmpc != 'X' ) ) + { + parser.Usage(); + return false; + } + + istr >> m_params.m_yOrigin; + + if( istr.fail() ) + { + parser.Usage(); + return false; + } + + if( !istr.eof() ) + { + std::string tunit; + istr >> tunit; + + if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) ) + { + m_params.m_xOrigin *= 25.4; + m_params.m_yOrigin *= 25.4; + } + else if( tunit.compare( "mm" ) ) + { + parser.Usage(); + return false; + } + } + } + + if( parser.Found( "min-distance", &tstr ) ) + { + std::istringstream istr; + istr.str( std::string( tstr.ToUTF8() ) ); + istr >> m_params.m_minDistance; + + if( istr.fail() ) + { + parser.Usage(); + return false; + } + + if( !istr.eof() ) + { + std::string tunit; + istr >> tunit; + + if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) ) + { + m_params.m_minDistance *= 25.4; + } + else if( tunit.compare( "mm" ) ) + { + parser.Usage(); + return false; + } + } + } + + if( parser.Found( "o", &tstr ) ) + m_params.m_outputFile = tstr; + + + if( parser.GetParamCount() < 1 ) + { + parser.Usage(); + return false; + } + + m_params.m_filename = parser.GetParam( 0 ); + + return true; +} diff --git a/utils/kicad2step/panel_kicad2step.h b/utils/kicad2step/panel_kicad2step.h index aa34242e10..eaad55ee39 100644 --- a/utils/kicad2step/panel_kicad2step.h +++ b/utils/kicad2step/panel_kicad2step.h @@ -34,29 +34,7 @@ #include #include -class KICAD2MCAD_PRMS // A small class to handle parameters of conversion -{ -public: - KICAD2MCAD_PRMS(); - - ///< Return file extension for the selected output format - wxString getOutputExt() const; - -#ifdef SUPPORTS_IGES - bool m_fmtIGES; -#endif - bool m_overwrite; - bool m_useGridOrigin; - bool m_useDrillOrigin; - bool m_includeVirtual; - bool m_substModels; - wxString m_filename; - wxString m_outputFile; - double m_xOrigin; - double m_yOrigin; - double m_minDistance; - -}; +#include "kicad2step.h" class PANEL_KICAD2STEP: public wxPanel { diff --git a/utils/kicad2step/pcb/base.h b/utils/kicad2step/pcb/base.h index 997a4c5190..b01c0ebad0 100644 --- a/utils/kicad2step/pcb/base.h +++ b/utils/kicad2step/pcb/base.h @@ -34,6 +34,8 @@ #include +#include + ///< Default minimum distance between points to treat them as separate ones (mm) static constexpr double MIN_DISTANCE = 0.01; @@ -94,7 +96,7 @@ struct TRIPLET std::ostream& operator<<( std::ostream& aStream, const TRIPLET& aTriplet ); -bool Get2DPositionAndRotation( const SEXPR::SEXPR* data, DOUBLET& aPosition, double& aRotation ); +APIEXPORT bool Get2DPositionAndRotation( const SEXPR::SEXPR* data, DOUBLET& aPosition, double& aRotation ); bool Get2DCoordinate( const SEXPR::SEXPR* data, DOUBLET& aCoordinate ); bool Get3DCoordinate( const SEXPR::SEXPR* data, TRIPLET& aCoordinate ); bool GetXYZRotation( const SEXPR::SEXPR* data, TRIPLET& aRotation ); @@ -107,6 +109,6 @@ bool GetXYZRotation( const SEXPR::SEXPR* data, TRIPLET& aRotation ); * @param aLayerElem the s-expr element to get the name from. * @return the layer name if valid, else empty. */ -OPT GetLayerName( const SEXPR::SEXPR& aLayerElem ); +APIEXPORT OPT GetLayerName( const SEXPR::SEXPR& aLayerElem ); #endif // KICADBASE_H