29#include <magic_enum.hpp>
32#include <wx/tokenzr.h>
33#include "../../3d-viewer/3d_viewer/eda_3d_viewer_settings.h"
36#define ARG_BACKGROUND "--background"
37#define ARG_QUALITY "--quality"
39#define ARG_WIDTH "--width"
40#define ARG_WIDTH_SHORT "-w"
42#define ARG_HEIGHT "--height"
43#define ARG_HEIGHT_SHORT "-h"
45#define ARG_SIDE "--side"
46#define ARG_PRESET "--preset"
47#define ARG_PAN "--pan"
48#define ARG_PIVOT "--pivot"
49#define ARG_ROTATE "--rotate"
50#define ARG_ZOOM "--zoom"
51#define ARG_PERSPECTIVE "--perspective"
52#define ARG_FLOOR "--floor"
54#define ARG_LIGHT_TOP "--light-top"
55#define ARG_LIGHT_BOTTOM "--light-bottom"
56#define ARG_LIGHT_SIDE "--light-side"
57#define ARG_LIGHT_CAMERA "--light-camera"
59#define ARG_LIGHT_SIDE_ELEVATION "--light-side-elevation"
66 auto names = magic_enum::enum_names<T>();
68 for(
size_t i = 0; i < names.size(); i++ )
70 std::string
name = { names[i].begin(), names[i].end() };
78 return std::tolower( c );
91 std::vector<std::string> out;
93 for(
auto& strView : magic_enum::enum_names<T>() )
95 std::string
name = { strView.begin(), strView.end() };
100 return std::tolower( c );
103 out.emplace_back(
name );
113 return magic_enum::enum_cast<T>( aInput, magic_enum::case_insensitive );
118static bool getToEnum(
const std::string& aInput, T& aOutput )
124 if(
auto opt = magic_enum::enum_cast<T>( aInput, magic_enum::case_insensitive ) )
143 if( wxStr[0] ==
'\'' )
144 wxStr = wxStr.AfterFirst(
'\'' );
146 if( wxStr[wxStr.length() - 1] ==
'\'' )
147 wxStr = wxStr.BeforeLast(
'\'' );
149 wxArrayString arr = wxSplit( wxStr,
',', 0 );
151 if( arr.size() != 3 )
156 success &= arr[0].Trim().ToCDouble( &vec.
x );
157 success &= arr[1].Trim().ToCDouble( &vec.
y );
158 success &= arr[2].Trim().ToCDouble( &vec.
z );
177 if( wxStr[0] ==
'\'' )
178 wxStr = wxStr.AfterFirst(
'\'' );
180 if( wxStr[wxStr.length() - 1] ==
'\'' )
181 wxStr = wxStr.BeforeLast(
'\'' );
183 wxArrayString arr = wxSplit( wxStr,
',', 0 );
185 if( arr.size() == 3 )
189 success &= arr[0].Trim().ToCDouble( &vec.
x );
190 success &= arr[1].Trim().ToCDouble( &vec.
y );
191 success &= arr[2].Trim().ToCDouble( &vec.
z );
199 else if( arr.size() == 1 )
202 if( arr[0].Trim().ToCDouble( &val ) )
204 aOutput =
VECTOR3D( val, val, val );
219 UTF8STDSTR(
_(
"Renders the PCB in 3D view to PNG or JPEG image" ) ) );
222 .default_value( 1600 )
228 .default_value( 900 )
234 .default_value( std::string(
"top" ) )
235 .add_choices( enumChoices<JOB_PCB_RENDER::SIDE>() )
237 .help(
UTF8STDSTR( wxString::Format(
_(
"Render from side. Options: %s" ),
238 enumString<JOB_PCB_RENDER::SIDE>() ) ) );
241 .default_value( std::string(
"" ) )
242 .
help(
UTF8STDSTR( wxString::Format(
_(
"Image background. Options: %s. Default: "
243 "transparent for PNG, opaque for JPEG" ),
244 enumString<JOB_PCB_RENDER::BG_STYLE>() ) ) )
248 .default_value( std::string(
"basic" ) )
249 .add_choices( enumChoices<JOB_PCB_RENDER::QUALITY>() )
250 .metavar(
"QUALITY" )
251 .help(
UTF8STDSTR( wxString::Format(
_(
"Render quality. Options: %s" ),
252 enumString<JOB_PCB_RENDER::QUALITY>() ) ) );
257 .help(
UTF8STDSTR( wxString::Format(
_(
"Color preset. Options: %s, %s, %s, ..." ),
263 .help(
UTF8STDSTR(
_(
"Enables floor, shadows and post-processing, even if disabled in "
264 "quality preset" ) ) );
268 .help(
UTF8STDSTR(
_(
"Use perspective projection instead of orthogonal" ) ) );
271 .default_value( 1.0 )
277 .default_value( std::string(
"" ) )
279 .help(
UTF8STDSTR(
_(
"Pan camera, format 'X,Y,Z' e.g.: '3,0,0'" ) ) );
282 .default_value( std::string(
"" ) )
284 .help(
UTF8STDSTR(
_(
"Set pivot point relative to the board center in centimeters, format 'X,Y,Z' "
285 "e.g.: '-10,2,0'" ) ) );
288 .default_value( std::string(
"" ) )
291 _(
"Rotate board, format 'X,Y,Z' e.g.: '-45,0,45' for isometric view" ) ) );
294 .default_value( std::string(
"" ) )
296 .help(
UTF8STDSTR(
_(
"Top light intensity, format 'R,G,B' or a single number, range: 0-1" ) ) );
299 .default_value( std::string(
"" ) )
301 .help(
UTF8STDSTR(
_(
"Bottom light intensity, format 'R,G,B' or a single number, range: 0-1" ) ) );
304 .default_value( std::string(
"" ) )
306 .help(
UTF8STDSTR(
_(
"Side lights intensity, format 'R,G,B' or a single number, range: 0-1" ) ) );
309 .default_value( std::string(
"" ) )
311 .help(
UTF8STDSTR(
_(
"Camera light intensity, format 'R,G,B' or a single number, range: 0-1" ) ) );
317 .help(
UTF8STDSTR(
_(
"Side lights elevation angle in degrees, range: 0-90" ) ) );
323 std::unique_ptr<JOB_PCB_RENDER> renderJob(
new JOB_PCB_RENDER() );
325 renderJob->SetConfiguredOutputPath( m_argOutput );
326 renderJob->m_filename = m_argInput;
327 renderJob->SetVarOverrides( m_argDefineVars );
329 renderJob->m_colorPreset = m_argParser.get<std::string>(
ARG_PRESET );
330 renderJob->m_width = m_argParser.get<
int>(
ARG_WIDTH );
331 renderJob->m_height = m_argParser.get<
int>(
ARG_HEIGHT );
332 renderJob->m_zoom = m_argParser.get<
double>(
ARG_ZOOM );
334 renderJob->m_floor = m_argParser.get<
bool>(
ARG_FLOOR );
342 wxFprintf( stderr,
_(
"Invalid background\n" ) );
348 wxFprintf( stderr,
_(
"Invalid rotation format\n" ) );
354 wxFprintf( stderr,
_(
"Invalid pan format\n" ) );
360 wxFprintf( stderr,
_(
"Invalid pivot format\n" ) );
365 renderJob->m_lightTopIntensity ) )
367 wxFprintf( stderr,
_(
"Invalid light top intensity format\n" ) );
372 renderJob->m_lightBottomIntensity ) )
374 wxFprintf( stderr,
_(
"Invalid light bottom intensity format\n" ) );
379 renderJob->m_lightSideIntensity ) )
381 wxFprintf( stderr,
_(
"Invalid light side intensity format\n" ) );
386 renderJob->m_lightCameraIntensity ) )
388 wxFprintf( stderr,
_(
"Invalid light camera intensity format\n" ) );
392 if( m_argOutput.Lower().EndsWith( wxS(
".png" ) ) )
396 else if( m_argOutput.Lower().EndsWith( wxS(
".jpg" ) )
397 || m_argOutput.Lower().EndsWith( wxS(
".jpeg" ) ) )
403 wxFprintf( stderr,
_(
"Invalid image format\n" ) );
argparse::ArgumentParser m_argParser
void addDefineArg()
Set up the drawing sheet arg used by many of the export commands.
void addCommonArgs(bool aInput, bool aOutput, bool aInputIsDir, bool aOutputIsDir)
Set up the most common of args used across cli.
int doPerform(KIWAY &aKiway) override
The internal handler that should be overloaded to implement command specific processing and work.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
int ProcessJob(KIWAY::FACE_T aFace, JOB *aJob, REPORTER *aReporter=nullptr)
static bool getToVector3(const std::string &aInput, VECTOR3D &aOutput)
static bool getColorOrIntensity(const std::string &aInput, VECTOR3D &aOutput)
static bool getToEnum(const std::string &aInput, T &aOutput)
static std::vector< std::string > enumChoices()
#define ARG_LIGHT_SIDE_ELEVATION
static wxString enumString()
static std::optional< T > strToEnum(std::string &aInput)
#define FOLLOW_PLOT_SETTINGS
#define LEGACY_PRESET_FLAG
This file contains miscellaneous commonly used macros and functions.
static const int ERR_ARGS
wxString From_UTF8(const char *cstring)
VECTOR3< double > VECTOR3D