KiCad PCB EDA Suite
CLI::EXPORT_PCB_STEP_COMMAND Struct Reference

#include <command_export_pcb_step.h>

Inheritance diagram for CLI::EXPORT_PCB_STEP_COMMAND:
CLI::COMMAND

Public Member Functions

 EXPORT_PCB_STEP_COMMAND ()
 
int Perform (KIWAY &aKiway)
 Entry point to processing commands from args and doing work. More...
 
argparse::ArgumentParser & GetArgParser ()
 
const std::string & GetName () const
 
void PrintHelp ()
 

Protected Member Functions

int doPerform (KIWAY &aKiway) override
 The internal handler that should be overloaded to implement command specific processing and work. More...
 

Protected Attributes

std::string m_name
 
argparse::ArgumentParser m_argParser
 

Detailed Description

Definition at line 28 of file command_export_pcb_step.h.

Constructor & Destructor Documentation

◆ EXPORT_PCB_STEP_COMMAND()

CLI::EXPORT_PCB_STEP_COMMAND::EXPORT_PCB_STEP_COMMAND ( )

Definition at line 46 of file command_export_pcb_step.cpp.

46 : COMMAND( "step" )
47{
48 m_argParser.add_argument( ARG_DRILL_ORIGIN )
49 .help( UTF8STDSTR( _( "Use Drill Origin for output origin" ) ) )
50 .implicit_value( true )
51 .default_value( false );
52
53 m_argParser.add_argument( ARG_GRID_ORIGIN )
54 .help( UTF8STDSTR( _( "Use Grid Origin for output origin" ) ) )
55 .implicit_value( true )
56 .default_value( false );
57
58 m_argParser.add_argument( ARG_NO_VIRTUAL )
59 .help( UTF8STDSTR( _( "Exclude 3D models for components with 'virtual' attribute" ) ) )
60 .implicit_value( true )
61 .default_value( false );
62
63 m_argParser.add_argument( "--subst-models" )
64 .help( UTF8STDSTR( _( "Substitute STEP or IGS models with the same name in place of VRML models" ) ) )
65 .implicit_value( true )
66 .default_value( false );
67
68 m_argParser.add_argument( ARG_FORCE, "-f" )
69 .help( UTF8STDSTR( _( "Overwrite output file" ) ) )
70 .implicit_value( true )
71 .default_value( false );
72
73 m_argParser.add_argument( ARG_BOARD_ONLY )
74 .help( UTF8STDSTR( _( "Only generate a board with no components" ) ) )
75 .implicit_value( true )
76 .default_value( false );
77
78 m_argParser.add_argument( ARG_EXPORT_TRACKS )
79 .help( UTF8STDSTR( _( "Export tracks (extremely time consuming)" ) ) )
80 .implicit_value( true )
81 .default_value( false );
82
83 m_argParser.add_argument( ARG_MIN_DISTANCE )
84 .default_value( std::string( "0.01mm" ) )
85 .help( UTF8STDSTR( _( "Minimum distance between points to treat them as separate ones" ) ) );
86
87 m_argParser.add_argument( ARG_USER_ORIGIN )
88 .default_value( std::string() )
89 .help( UTF8STDSTR( _( "User-specified output origin ex. 1x1in, 1x1inch, 25.4x25.4mm (default unit mm)" ) ) );
90
91 m_argParser.add_argument( "-o", ARG_OUTPUT )
92 .default_value( std::string() )
93 .help( UTF8STDSTR( _( "Output file name" ) ) );
94
95 m_argParser.add_argument( ARG_INPUT ).help( UTF8STDSTR( _( "Input file" ) ) );
96}
argparse::ArgumentParser m_argParser
Definition: command.h:68
COMMAND(const std::string &aName)
Define a new COMMAND instance.
Definition: command.cpp:29
#define UTF8STDSTR(s)
Definition: command.h:27
#define ARG_OUTPUT
#define ARG_INPUT
#define ARG_MIN_DISTANCE
#define ARG_FORCE
#define ARG_NO_VIRTUAL
#define ARG_EXPORT_TRACKS
#define ARG_BOARD_ONLY
#define ARG_GRID_ORIGIN
#define ARG_USER_ORIGIN
#define ARG_DRILL_ORIGIN
#define _(s)

References _, ARG_BOARD_ONLY, ARG_DRILL_ORIGIN, ARG_EXPORT_TRACKS, ARG_FORCE, ARG_GRID_ORIGIN, ARG_INPUT, ARG_MIN_DISTANCE, ARG_NO_VIRTUAL, ARG_OUTPUT, ARG_USER_ORIGIN, CLI::COMMAND::m_argParser, and UTF8STDSTR.

Member Function Documentation

◆ doPerform()

int CLI::EXPORT_PCB_STEP_COMMAND::doPerform ( KIWAY aKiway)
overrideprotectedvirtual

The internal handler that should be overloaded to implement command specific processing and work.

If not overloaded, the command will simply emit the help options by default

Reimplemented from CLI::COMMAND.

Definition at line 98 of file command_export_pcb_step.cpp.

99{
100 std::unique_ptr<JOB_EXPORT_PCB_STEP> step( new JOB_EXPORT_PCB_STEP( true ) );
101
102 step->m_useDrillOrigin = m_argParser.get<bool>( ARG_DRILL_ORIGIN );
103 step->m_useGridOrigin = m_argParser.get<bool>( ARG_GRID_ORIGIN );
104 step->m_includeExcludedBom = !m_argParser.get<bool>( ARG_NO_VIRTUAL );
105 step->m_substModels = m_argParser.get<bool>( ARG_SUBST_MODELS );
106 step->m_overwrite = m_argParser.get<bool>( ARG_FORCE );
107 step->m_filename = FROM_UTF8( m_argParser.get<std::string>( ARG_INPUT ).c_str() );
108 step->m_outputFile = FROM_UTF8( m_argParser.get<std::string>( ARG_OUTPUT ).c_str() );
109 step->m_boardOnly = m_argParser.get<bool>( ARG_BOARD_ONLY );
110 step->m_exportTracks = m_argParser.get<bool>( ARG_EXPORT_TRACKS );
111
112 wxString userOrigin = FROM_UTF8( m_argParser.get<std::string>( ARG_USER_ORIGIN ).c_str() );
113
114 LOCALE_IO dummy; // Switch to "C" locale
115
116 if( !userOrigin.IsEmpty() )
117 {
119 std::regex_constants::icase );
120 std::smatch sm;
121 std::string str( userOrigin.ToUTF8() );
122 std::regex_search( str, sm, re_pattern );
123 step->m_xOrigin = atof( sm.str( 1 ).c_str() );
124 step->m_yOrigin = atof( sm.str( 2 ).c_str() );
125
126 std::string tunit( sm[3] );
127
128 if( tunit.size() > 0 ) // No unit accepted ( default = mm )
129 {
130 if( ( !sm.str( 1 ).compare( " " ) || !sm.str( 2 ).compare( " " ) )
131 || ( sm.size() != 4 ) )
132 {
133 std::cout << m_argParser;
135 }
136
137 // only in, inch and mm are valid:
138 if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) )
139 {
140 step->m_xOrigin *= 25.4;
141 step->m_yOrigin *= 25.4;
142 }
143 else if( tunit.compare( "mm" ) )
144 {
145 std::cout << m_argParser;
147 }
148 }
149 }
150
151 wxString minDistance = FROM_UTF8( m_argParser.get<std::string>( ARG_MIN_DISTANCE ).c_str() );
152
153 if( !minDistance.IsEmpty() )
154 {
155 std::regex re_pattern( REGEX_QUANTITY REGEX_UNIT,
156 std::regex_constants::icase );
157 std::smatch sm;
158 std::string str( minDistance.ToUTF8() );
159 std::regex_search( str, sm, re_pattern );
160 step->m_BoardOutlinesChainingEpsilon = atof( sm.str( 1 ).c_str() );
161
162 std::string tunit( sm[2] );
163
164 if( tunit.size() > 0 ) // No unit accepted ( default = mm )
165 {
166 if( !tunit.compare( "in" ) || !tunit.compare( "inch" ) )
167 {
168 step->m_BoardOutlinesChainingEpsilon *= 25.4;
169 }
170 else if( tunit.compare( "mm" ) )
171 {
172 std::cout << m_argParser;
174 }
175 }
176 }
177
178 int exitCode = aKiway.ProcessJob( KIWAY::FACE_PCB, step.get() );
179
180 return exitCode;
181}
int ProcessJob(KIWAY::FACE_T aFace, JOB *job)
Definition: kiway.cpp:660
@ FACE_PCB
pcbnew DSO
Definition: kiway.h:287
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
#define REGEX_QUANTITY
#define REGEX_UNIT
#define REGEX_DELIMITER
#define ARG_SUBST_MODELS
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110
static const int ERR_ARGS
Definition: exit_codes.h:31
std::vector< FAB_LAYER_COLOR > dummy

References ARG_BOARD_ONLY, ARG_DRILL_ORIGIN, ARG_EXPORT_TRACKS, ARG_FORCE, ARG_GRID_ORIGIN, ARG_INPUT, ARG_MIN_DISTANCE, ARG_NO_VIRTUAL, ARG_OUTPUT, ARG_SUBST_MODELS, ARG_USER_ORIGIN, dummy, CLI::EXIT_CODES::ERR_ARGS, KIWAY::FACE_PCB, FROM_UTF8(), KIWAY::ProcessJob(), REGEX_DELIMITER, REGEX_QUANTITY, and REGEX_UNIT.

◆ GetArgParser()

argparse::ArgumentParser & CLI::COMMAND::GetArgParser ( )
inlineinherited

Definition at line 54 of file command.h.

54{ return m_argParser; }

References CLI::COMMAND::m_argParser.

Referenced by recurseArgParserBuild(), and recurseArgParserSubCommandUsed().

◆ GetName()

const std::string & CLI::COMMAND::GetName ( void  ) const
inlineinherited

Definition at line 55 of file command.h.

55{ return m_name; }
std::string m_name
Definition: command.h:67

References CLI::COMMAND::m_name.

Referenced by recurseArgParserSubCommandUsed().

◆ Perform()

int CLI::COMMAND::Perform ( KIWAY aKiway)
inherited

Entry point to processing commands from args and doing work.

Definition at line 49 of file command.cpp.

50{
51 if( m_argParser[ARG_HELP] == true )
52 {
53 PrintHelp();
54
55 return 0;
56 }
57
58 return doPerform( aKiway );
59}
virtual int doPerform(KIWAY &aKiway)
The internal handler that should be overloaded to implement command specific processing and work.
Definition: command.cpp:62
void PrintHelp()
Definition: command.cpp:41
#define ARG_HELP
Definition: command.h:30

References ARG_HELP.

◆ PrintHelp()

void CLI::COMMAND::PrintHelp ( )
inherited

Definition at line 41 of file command.cpp.

42{
43 std::stringstream ss;
44 ss << m_argParser;
45 wxPrintf( FROM_UTF8( ss.str().c_str() ) );
46}

References FROM_UTF8().

Member Data Documentation

◆ m_argParser

◆ m_name

std::string CLI::COMMAND::m_name
protectedinherited

Definition at line 67 of file command.h.

Referenced by CLI::COMMAND::GetName().


The documentation for this struct was generated from the following files: