Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::ConfigDef Class Reference

#include <src/libslic3r/Config.hpp>

+ Inheritance diagram for Slic3r::ConfigDef:
+ Collaboration diagram for Slic3r::ConfigDef:

Public Member Functions

bool has (const t_config_option_key &opt_key) const
 
const ConfigOptionDefget (const t_config_option_key &opt_key) const
 
std::vector< std::string > keys () const
 
std::ostream & print_cli_help (std::ostream &out, bool show_defaults, std::function< bool(const ConfigOptionDef &)> filter=[](const ConfigOptionDef &){ return true;}) const
 

Public Attributes

t_optiondef_map options
 
std::map< size_t, const ConfigOptionDef * > by_serialization_key_ordinal
 

Protected Member Functions

ConfigOptionDefadd (const t_config_option_key &opt_key, ConfigOptionType type)
 
ConfigOptionDefadd_nullable (const t_config_option_key &opt_key, ConfigOptionType type)
 
void finalize ()
 

Detailed Description

Member Function Documentation

◆ add()

ConfigOptionDef * Slic3r::ConfigDef::add ( const t_config_option_key opt_key,
ConfigOptionType  type 
)
protected
289{
290 static size_t serialization_key_ordinal_last = 0;
291 ConfigOptionDef *opt = &this->options[opt_key];
292 opt->opt_key = opt_key;
293 opt->type = type;
294 opt->serialization_key_ordinal = ++ serialization_key_ordinal_last;
295 this->by_serialization_key_ordinal[opt->serialization_key_ordinal] = opt;
296 return opt;
297}
std::map< size_t, const ConfigOptionDef * > by_serialization_key_ordinal
Definition Config.hpp:2066
t_optiondef_map options
Definition Config.hpp:2065

References by_serialization_key_ordinal, Slic3r::ConfigOptionDef::opt_key, options, Slic3r::ConfigOptionDef::serialization_key_ordinal, and Slic3r::ConfigOptionDef::type.

Referenced by Slic3r::AnycubicSLAFormatConfigDef::AnycubicSLAFormatConfigDef(), Slic3r::CLIActionsConfigDef::CLIActionsConfigDef(), Slic3r::CLIMiscConfigDef::CLIMiscConfigDef(), Slic3r::CLITransformConfigDef::CLITransformConfigDef(), add_nullable(), Slic3r::PrintConfigDef::init_common_params(), Slic3r::PrintConfigDef::init_fff_params(), Slic3r::PrintConfigDef::init_sla_params(), and Slic3r::PrintConfigDef::init_sla_support_params().

+ Here is the caller graph for this function:

◆ add_nullable()

ConfigOptionDef * Slic3r::ConfigDef::add_nullable ( const t_config_option_key opt_key,
ConfigOptionType  type 
)
protected
300{
301 ConfigOptionDef *def = this->add(opt_key, type);
302 def->nullable = true;
303 return def;
304}
ConfigOptionDef * add(const t_config_option_key &opt_key, ConfigOptionType type)
Definition Config.cpp:288

References add(), and Slic3r::ConfigOptionDef::nullable.

Referenced by Slic3r::PrintConfigDef::init_fff_params(), and Slic3r::PrintConfigDef::init_sla_params().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ finalize()

void Slic3r::ConfigDef::finalize ( )
protected
307{
308 // Validate & finalize open & closed enums.
309 for (std::pair<const t_config_option_key, ConfigOptionDef> &kvp : options) {
310 ConfigOptionDef& def = kvp.second;
311 if (def.type == coEnum) {
312 assert(def.enum_def);
313 assert(def.enum_def->is_valid_closed_enum());
314 assert(def.gui_type != ConfigOptionDef::GUIType::i_enum_open &&
315 def.gui_type != ConfigOptionDef::GUIType::f_enum_open &&
317 def.enum_def->finalize_closed_enum();
318 } else if (def.gui_type == ConfigOptionDef::GUIType::i_enum_open || def.gui_type == ConfigOptionDef::GUIType::f_enum_open ||
320 assert(def.enum_def);
321 assert(def.enum_def->is_valid_open_enum());
322 assert(def.gui_type != ConfigOptionDef::GUIType::i_enum_open || def.type == coInt || def.type == coInts);
323 assert(def.gui_type != ConfigOptionDef::GUIType::f_enum_open || def.type == coFloat || def.type == coPercent || def.type == coFloatOrPercent);
324 assert(def.gui_type != ConfigOptionDef::GUIType::select_open || def.type == coString || def.type == coStrings);
325 } else {
326 assert(! def.enum_def);
327 }
328 }
329}
@ coString
Definition Config.hpp:172
@ coEnum
Definition Config.hpp:194
@ coInts
Definition Config.hpp:170
@ coInt
Definition Config.hpp:168
@ coFloat
Definition Config.hpp:164
@ coFloatOrPercent
Definition Config.hpp:180
@ coStrings
Definition Config.hpp:174
@ coPercent
Definition Config.hpp:176

References Slic3r::coEnum, Slic3r::coFloat, Slic3r::coFloatOrPercent, Slic3r::coInt, Slic3r::coInts, Slic3r::coPercent, Slic3r::coString, Slic3r::coStrings, Slic3r::ConfigOptionDef::enum_def, Slic3r::ConfigOptionDef::f_enum_open, Slic3r::ConfigOptionDef::gui_type, Slic3r::ConfigOptionDef::i_enum_open, options, Slic3r::ConfigOptionDef::select_open, and Slic3r::ConfigOptionDef::type.

Referenced by Slic3r::PrintConfigDef::PrintConfigDef().

+ Here is the caller graph for this function:

◆ get()

◆ has()

bool Slic3r::ConfigDef::has ( const t_config_option_key opt_key) const
inline
2068{ return this->options.count(opt_key) > 0; }

Referenced by Slic3r::PrintConfigDef::handle_legacy(), and Slic3r::CLI::setup().

+ Here is the caller graph for this function:

◆ keys()

std::vector< std::string > Slic3r::ConfigDef::keys ( ) const
inline
2073 {
2074 std::vector<std::string> out;
2075 out.reserve(options.size());
2076 for(auto const& kvp : options)
2077 out.push_back(kvp.first);
2078 return out;
2079 }

References options.

◆ print_cli_help()

std::ostream & Slic3r::ConfigDef::print_cli_help ( std::ostream &  out,
bool  show_defaults,
std::function< bool(const ConfigOptionDef &)>  filter = [](const ConfigOptionDef &){ return true; } 
) const
332{
333 // prepare a function for wrapping text
334 auto wrap = [](const std::string& text, size_t line_length) -> std::string {
335 std::istringstream words(text);
336 std::ostringstream wrapped;
337 std::string word;
338
339 if (words >> word) {
340 wrapped << word;
341 size_t space_left = line_length - word.length();
342 while (words >> word) {
343 if (space_left < word.length() + 1) {
344 wrapped << '\n' << word;
345 space_left = line_length - word.length();
346 } else {
347 wrapped << ' ' << word;
348 space_left -= word.length() + 1;
349 }
350 }
351 }
352 return wrapped.str();
353 };
354
355 // get the unique categories
356 std::set<std::string> categories;
357 for (const auto& opt : this->options) {
358 const ConfigOptionDef& def = opt.second;
359 if (filter(def))
360 categories.insert(def.category);
361 }
362
363 for (const std::string& category : categories) {
364 if (category != "") {
365 out << category << ":" << std::endl;
366 } else if (categories.size() > 1) {
367 out << "Misc options:" << std::endl;
368 }
369
370 for (const auto& opt : this->options) {
371 const ConfigOptionDef& def = opt.second;
372 if (def.category != category || def.cli == ConfigOptionDef::nocli || !filter(def))
373 continue;
374
375 // get all possible variations: --foo, --foobar, -f...
376 std::vector<std::string> cli_args = def.cli_args(opt.first);
377 if (cli_args.empty())
378 continue;
379
380 for (auto& arg : cli_args) {
381 arg.insert(0, (arg.size() == 1) ? "-" : "--");
382 if (def.type == coFloat || def.type == coInt || def.type == coFloatOrPercent
383 || def.type == coFloats || def.type == coInts) {
384 arg += " N";
385 } else if (def.type == coPoint) {
386 arg += " X,Y";
387 } else if (def.type == coPoint3) {
388 arg += " X,Y,Z";
389 } else if (def.type == coString || def.type == coStrings) {
390 arg += " ABCD";
391 }
392 }
393
394 // left: command line options
395 const std::string cli = boost::algorithm::join(cli_args, ", ");
396 out << " " << std::left << std::setw(20) << cli;
397
398 // right: option description
399 std::string descr = def.tooltip;
400 bool show_defaults_this = show_defaults || def.opt_key == "config_compatibility";
401 if (show_defaults_this && def.default_value && def.type != coBool
402 && (def.type != coString || !def.default_value->serialize().empty())) {
403 descr += " (";
404 if (!def.sidetext.empty()) {
405 descr += def.sidetext + ", ";
406 } else if (def.enum_def->has_values()) {
407 descr += boost::algorithm::join(def.enum_def->values(), ", ") + "; ";
408 }
409 descr += "default: " + def.default_value->serialize() + ")";
410 }
411
412 // wrap lines of description
413 descr = wrap(descr, 80);
414 std::vector<std::string> lines;
415 boost::split(lines, descr, boost::is_any_of("\n"));
416
417 // if command line options are too long, print description in new line
418 for (size_t i = 0; i < lines.size(); ++i) {
419 if (i == 0 && cli.size() > 19)
420 out << std::endl;
421 if (i > 0 || cli.size() > 19)
422 out << std::string(21, ' ');
423 out << lines[i] << std::endl;
424 }
425 }
426 }
427 return out;
428}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Definition ArrayCwiseUnaryOps.h:57
static const constexpr char * nocli
Definition Config.hpp:2035
@ coPoint
Definition Config.hpp:184
@ coPoint3
Definition Config.hpp:187
@ coBool
Definition Config.hpp:190
@ coFloats
Definition Config.hpp:166

References arg(), Slic3r::ConfigOptionDef::category, Slic3r::ConfigOptionDef::cli, Slic3r::ConfigOptionDef::cli_args(), Slic3r::coBool, Slic3r::coFloat, Slic3r::coFloatOrPercent, Slic3r::coFloats, Slic3r::coInt, Slic3r::coInts, Slic3r::coPoint, Slic3r::coPoint3, Slic3r::coString, Slic3r::coStrings, Slic3r::ConfigOptionDef::default_value, Slic3r::ConfigOptionDef::enum_def, Slic3r::ConfigOptionDef::nocli, Slic3r::ConfigOptionDef::opt_key, options, Slic3r::ConfigOptionDef::sidetext, Slic3r::ConfigOptionDef::tooltip, and Slic3r::ConfigOptionDef::type.

Referenced by Slic3r::CLI::print_help().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ by_serialization_key_ordinal

std::map<size_t, const ConfigOptionDef*> Slic3r::ConfigDef::by_serialization_key_ordinal

◆ options


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