From 34fef23bd4cb29bf8814ccd4ea086ec1f24ca5d9 Mon Sep 17 00:00:00 2001 From: Cirilo Bernardo Date: Sun, 18 Sep 2016 12:24:04 +1000 Subject: [PATCH] Reworked cmdline options and added output filename option --- utils/kicad2step/kicad2step.cpp | 107 +++++++++++++++++++++------ utils/kicad2step/pcb/kicadmodule.cpp | 3 - 2 files changed, 85 insertions(+), 25 deletions(-) diff --git a/utils/kicad2step/kicad2step.cpp b/utils/kicad2step/kicad2step.cpp index e9e735852d..e91f40cb88 100644 --- a/utils/kicad2step/kicad2step.cpp +++ b/utils/kicad2step/kicad2step.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "kicadpcb.h" @@ -49,28 +50,31 @@ private: bool m_useDrillOrigin; bool m_includeVirtual; wxString m_filename; + wxString m_outputFile; double m_xOrigin; double m_yOrigin; + bool m_inch; }; static const wxCmdLineEntryDesc cmdLineDesc[] = { - { wxCMD_LINE_PARAM, NULL, NULL, _( "pcb_file" ), + { wxCMD_LINE_PARAM, NULL, NULL, _( "pcb_filename" ), wxCMD_LINE_VAL_STRING, wxCMD_LINE_OPTION_MANDATORY }, + { wxCMD_LINE_OPTION, "o", "output-filename", _( "output filename" ), + wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, #ifdef SUPPORTS_IGES - { wxCMD_LINE_SWITCH, "i", NULL, "IGES output (default STEP)", + { wxCMD_LINE_SWITCH, "fmt-iges", NULL, "IGES output (default STEP)", wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, #endif - { wxCMD_LINE_SWITCH, "w", NULL, _( "overwrite output file" ), + { wxCMD_LINE_SWITCH, "f", "force", _( "overwrite output file" ), wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_SWITCH, "d", NULL, _( "Use Drill Origin for output origin" ), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_SWITCH, "o", NULL, _( "Use Grid Origin for output origin" ), - wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_OPTION, "x", NULL, _( "X origin of board" ), - wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL }, - { wxCMD_LINE_OPTION, "y", NULL, _( "Y origin of board (pcbnew coordinate system)" ), - wxCMD_LINE_VAL_DOUBLE, wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_SWITCH, NULL, "drill-origin", _( "Use Drill Origin for output origin" ), + wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, + { wxCMD_LINE_SWITCH, NULL, "grid-origin", _( "Use Grid Origin for output origin" ), + 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)" ), + wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, { wxCMD_LINE_SWITCH, NULL, "no-virtual", _( "exclude 3D models for components with 'virtual' attribute" ), wxCMD_LINE_VAL_NONE, wxCMD_LINE_PARAM_OPTIONAL }, @@ -92,6 +96,7 @@ bool KICAD2MCAD::OnInit() m_useGridOrigin = false; m_useDrillOrigin = false; m_includeVirtual = true; + m_inch = false; m_xOrigin = 0.0; m_yOrigin = 0.0; @@ -113,26 +118,73 @@ void KICAD2MCAD::OnInitCmdLine( wxCmdLineParser& parser ) bool KICAD2MCAD::OnCmdLineParsed( wxCmdLineParser& parser ) { #ifdef SUPPORTS_IGES - if( parser.Found( "i" ) ) + if( parser.Found( "fmt-iges" ) ) m_fmtIGES = true; #endif - if( parser.Found( "w" ) ) + if( parser.Found( "f" ) ) m_overwrite = true; - if( parser.Found( "o" ) ) + if( parser.Found( "grid-origin" ) ) m_useGridOrigin = true; - if( parser.Found( "d" ) ) + if( parser.Found( "drill-origin" ) ) m_useDrillOrigin = true; if( parser.Found( "no-virtual" ) ) m_includeVirtual = false; - parser.Found( "x", &m_xOrigin ); - parser.Found( "y", &m_yOrigin ); + wxString tstr; + + if( parser.Found( "user-origin", &tstr ) ) + { + std::istringstream istr; + istr.str( std::string( tstr.ToUTF8() ) ); + istr >> 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_yOrigin; + + if( istr.fail() ) + { + parser.Usage(); + return false; + } + + if( !istr.eof() ) + { + std::string tunit; + istr >> tunit; + + if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) ) + { + m_inch = true; + } + else if( tunit.compare( "mm" ) ) + { + parser.Usage(); + return false; + } + } + } + + if( parser.Found( "o", &tstr ) ) + m_outputFile = tstr; - wxString fname; if( parser.GetParamCount() < 1 ) { @@ -160,17 +212,28 @@ int KICAD2MCAD::OnRun() return -1; } + wxFileName tfname; + + if( m_outputFile.empty() ) + tfname.Assign( fname.GetFullPath() ); + else + tfname.Assign( m_outputFile ); + #ifdef SUPPORTS_IGES if( m_fmtIGES ) - fname.SetExt( "igs" ); + tfname.SetExt( "igs" ); else #endif - fname.SetExt( "stp" ); + tfname.SetExt( "stp" ); - wxString outfile = fname.GetFullPath(); + wxString outfile = tfname.GetFullPath(); KICADPCB pcb; - pcb.SetOrigin( m_xOrigin, m_yOrigin ); + + if( m_inch ) + pcb.SetOrigin( m_xOrigin * 25.4, m_yOrigin * 25.4 ); + else + pcb.SetOrigin( m_xOrigin, m_yOrigin ); if( pcb.ReadFile( m_filename ) ) { diff --git a/utils/kicad2step/pcb/kicadmodule.cpp b/utils/kicad2step/pcb/kicadmodule.cpp index 5d87b59149..6f3fac7a90 100644 --- a/utils/kicad2step/pcb/kicadmodule.cpp +++ b/utils/kicad2step/pcb/kicadmodule.cpp @@ -351,9 +351,6 @@ bool KICADMODULE::ComposePCB( class PCBMODEL* aPCB, S3D_RESOLVER* resolver, } - if( m_virtual ) - std::cerr << "This is a virtual component, aComposeVirtual == " << (aComposeVirtual ? "true" : "false" ) << "\n"; - if( m_virtual && !aComposeVirtual ) return hasdata;