Corrected syntax in kicad2step's help message regarding user-specified origin.

(cherry picked from commit 8456d6cea9)
This commit is contained in:
Adam Wahab 2022-06-28 23:24:13 +00:00 committed by Seth Hillbrand
parent 90ef84b958
commit 29d58ae063
1 changed files with 21 additions and 36 deletions

View File

@ -30,12 +30,15 @@
#include <wx/filename.h> #include <wx/filename.h>
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
#include <sstream> #include <regex>
#include "kicad2step.h" #include "kicad2step.h"
#include "kicad2step_frame_base.h" #include "kicad2step_frame_base.h"
#include <Standard_Failure.hxx> // In open cascade #include <Standard_Failure.hxx> // In open cascade
#define REGEX_QUANTITY "([\\s]*[+-]?[\\d]*[.]?[\\d]*)"
#define REGEX_DELIMITER "(?:[\\s]*x)"
#define REGEX_UNIT "([m]{2}|(?:in))"
class KICAD2MCAD_APP : public wxApp class KICAD2MCAD_APP : public wxApp
{ {
@ -146,38 +149,21 @@ bool KICAD2MCAD_APP::OnCmdLineParsed( wxCmdLineParser& parser )
if( parser.Found( wxT( "user-origin" ), &tstr ) ) if( parser.Found( wxT( "user-origin" ), &tstr ) )
{ {
std::istringstream istr; std::regex re_pattern( REGEX_QUANTITY REGEX_DELIMITER REGEX_QUANTITY REGEX_UNIT,
istr.str( std::string( tstr.ToUTF8() ) ); std::regex_constants::icase );
istr >> m_params.m_xOrigin; std::smatch sm;
std::string str( tstr.ToUTF8() );
std::regex_search( str, sm, re_pattern );
m_params.m_xOrigin = atof( sm.str( 1 ).c_str() );
m_params.m_yOrigin = atof( sm.str( 2 ).c_str() );
std::string tunit( sm[3] );
if( istr.fail() ) if( ( !sm.str( 1 ).compare( " " ) || !sm.str( 2 ).compare( " " ) ) || ( sm.size() != 4 ) )
{ {
parser.Usage(); parser.Usage();
return false; 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" ) ) if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) )
{ {
m_params.m_xOrigin *= 25.4; m_params.m_xOrigin *= 25.4;
@ -189,7 +175,6 @@ bool KICAD2MCAD_APP::OnCmdLineParsed( wxCmdLineParser& parser )
return false; return false;
} }
} }
}
if( parser.Found( wxT( "min-distance" ), &tstr ) ) if( parser.Found( wxT( "min-distance" ), &tstr ) )
{ {