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"
59 auto names = magic_enum::enum_names<T>();
61 for(
size_t i = 0; i < names.size(); i++ )
63 std::string
name = { names[i].begin(), names[i].end() };
71 return std::tolower( c );
84 std::vector<std::string> out;
86 for(
auto& strView : magic_enum::enum_names<T>() )
88 std::string
name = { strView.begin(), strView.end() };
93 return std::tolower( c );
96 out.emplace_back(
name );
106 return magic_enum::enum_cast<T>( aInput, magic_enum::case_insensitive );
111static bool getToEnum(
const std::string& aInput, T& aOutput )
117 if(
auto opt = magic_enum::enum_cast<T>( aInput, magic_enum::case_insensitive ) )
136 if( wxStr[0] ==
'\'' )
137 wxStr = wxStr.AfterFirst(
'\'' );
139 if( wxStr[wxStr.length() - 1] ==
'\'' )
140 wxStr = wxStr.BeforeLast(
'\'' );
142 wxArrayString arr = wxSplit( wxStr,
',', 0 );
144 if( arr.size() != 3 )
149 success &= arr[0].Trim().ToCDouble( &vec.
x );
150 success &= arr[1].Trim().ToCDouble( &vec.
y );
151 success &= arr[2].Trim().ToCDouble( &vec.
z );
167 UTF8STDSTR(
_(
"Renders the PCB in 3D view to PNG or JPEG image" ) ) );
170 .default_value( 1600 )
176 .default_value( 900 )
182 .default_value( std::string(
"top" ) )
183 .add_choices( enumChoices<JOB_PCB_RENDER::SIDE>() )
185 .help(
UTF8STDSTR( wxString::Format(
_(
"Render from side. Options: %s" ),
186 enumString<JOB_PCB_RENDER::SIDE>() ) ) );
189 .default_value( std::string(
"" ) )
190 .
help(
UTF8STDSTR(
_(
"Image background. Options: transparent, opaque. Default: "
191 "transparent for PNG, opaque for JPEG" ) ) )
195 .default_value( std::string(
"basic" ) )
196 .add_choices( enumChoices<JOB_PCB_RENDER::QUALITY>() )
197 .metavar(
"QUALITY" )
198 .help(
UTF8STDSTR( wxString::Format(
_(
"Render quality. Options: %s" ),
199 enumString<JOB_PCB_RENDER::QUALITY>() ) ) );
204 .help(
UTF8STDSTR( wxString::Format(
_(
"Color preset. Options: %s, %s, %s, ..." ),
210 .help(
UTF8STDSTR(
_(
"Enables floor, shadows and post-processing, even if disabled in "
211 "quality preset" ) ) );
215 .help(
UTF8STDSTR(
_(
"Use perspective projection instead of orthogonal" ) ) );
218 .default_value( 1.0 )
224 .default_value( std::string(
"" ) )
226 .help(
UTF8STDSTR(
_(
"Pan camera, format 'X,Y,Z' e.g.: '3,0,0'" ) ) );
229 .default_value( std::string(
"" ) )
231 .help(
UTF8STDSTR(
_(
"Set pivot point relative to the board center in centimeters, format 'X,Y,Z' "
232 "e.g.: '-10,2,0'" ) ) );
235 .default_value( std::string(
"" ) )
238 _(
"Rotate board, format 'X,Y,Z' e.g.: '-45,0,45' for isometric view" ) ) );
244 std::unique_ptr<JOB_PCB_RENDER> renderJob(
new JOB_PCB_RENDER() );
246 renderJob->m_outputFile = m_argOutput;
247 renderJob->m_filename = m_argInput;
248 renderJob->SetVarOverrides( m_argDefineVars );
250 renderJob->m_colorPreset = m_argParser.get<std::string>(
ARG_PRESET );
251 renderJob->m_width = m_argParser.get<
int>(
ARG_WIDTH );
252 renderJob->m_height = m_argParser.get<
int>(
ARG_HEIGHT );
253 renderJob->m_zoom = m_argParser.get<
double>(
ARG_ZOOM );
255 renderJob->m_floor = m_argParser.get<
bool>(
ARG_FLOOR );
262 wxFprintf( stderr,
_(
"Invalid background\n" ) );
268 wxFprintf( stderr,
_(
"Invalid rotation format\n" ) );
274 wxFprintf( stderr,
_(
"Invalid pan format\n" ) );
280 wxFprintf( stderr,
_(
"Invalid pivot format\n" ) );
284 if( m_argOutput.Lower().EndsWith( wxS(
".png" ) ) )
288 else if( m_argOutput.Lower().EndsWith( wxS(
".jpg" ) )
289 || m_argOutput.Lower().EndsWith( wxS(
".jpeg" ) ) )
295 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 getToEnum(const std::string &aInput, T &aOutput)
static std::vector< std::string > enumChoices()
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)