Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::ConfigBase Class Referenceabstract

#include <src/libslic3r/Config.hpp>

+ Inheritance diagram for Slic3r::ConfigBase:
+ Collaboration diagram for Slic3r::ConfigBase:

Classes

struct  SetDeserializeItem
 

Public Member Functions

 ConfigBase ()=default
 
 ~ConfigBase () override=default
 
virtual const ConfigDefdef () const =0
 
virtual ConfigOptionoptptr (const t_config_option_key &opt_key, bool create=false)=0
 
virtual t_config_option_keys keys () const =0
 
ConfigOptionoption (const t_config_option_key &opt_key, bool create=false)
 
template<typename TYPE >
TYPE * option (const t_config_option_key &opt_key, bool create=false)
 
ConfigOptionoption_throw (const t_config_option_key &opt_key, bool create=false)
 
template<typename TYPE >
TYPE * option_throw (const t_config_option_key &opt_key, bool create=false)
 
template<class T >
T * opt (const t_config_option_key &opt_key, bool create=false)
 
template<class T >
const T * opt (const t_config_option_key &opt_key) const
 
const ConfigOptionDefoption_def (const t_config_option_key &opt_key) const
 
void apply (const ConfigBase &other, bool ignore_nonexistent=false)
 
void apply_only (const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent=false)
 
bool equals (const ConfigBase &other) const
 
t_config_option_keys diff (const ConfigBase &other) const
 
t_config_option_keys equal (const ConfigBase &other) const
 
std::string opt_serialize (const t_config_option_key &opt_key) const
 
void set (const std::string &opt_key, bool value, bool create=false)
 
void set (const std::string &opt_key, int value, bool create=false)
 
void set (const std::string &opt_key, double value, bool create=false)
 
void set (const std::string &opt_key, const char *value, bool create=false)
 
void set (const std::string &opt_key, const std::string &value, bool create=false)
 
bool set_deserialize_nothrow (const t_config_option_key &opt_key_src, const std::string &value_src, ConfigSubstitutionContext &substitutions, bool append=false)
 
void set_deserialize (const t_config_option_key &opt_key, const std::string &str, ConfigSubstitutionContext &config_substitutions, bool append=false)
 
void set_deserialize_strict (const t_config_option_key &opt_key, const std::string &str, bool append=false)
 
void set_deserialize (std::initializer_list< SetDeserializeItem > items, ConfigSubstitutionContext &substitutions)
 
void set_deserialize_strict (std::initializer_list< SetDeserializeItem > items)
 
double get_abs_value (const t_config_option_key &opt_key) const
 
double get_abs_value (const t_config_option_key &opt_key, double ratio_over) const
 
std::string & opt_string (const t_config_option_key &opt_key, bool create=false)
 
const std::string & opt_string (const t_config_option_key &opt_key) const
 
std::string & opt_string (const t_config_option_key &opt_key, unsigned int idx)
 
const std::string & opt_string (const t_config_option_key &opt_key, unsigned int idx) const
 
double & opt_float (const t_config_option_key &opt_key)
 
const double & opt_float (const t_config_option_key &opt_key) const
 
double & opt_float (const t_config_option_key &opt_key, unsigned int idx)
 
const double & opt_float (const t_config_option_key &opt_key, unsigned int idx) const
 
int & opt_int (const t_config_option_key &opt_key)
 
int opt_int (const t_config_option_key &opt_key) const
 
int & opt_int (const t_config_option_key &opt_key, unsigned int idx)
 
int opt_int (const t_config_option_key &opt_key, unsigned int idx) const
 
template<typename ENUM >
ENUM opt_enum (const t_config_option_key &opt_key) const
 
bool opt_bool (const t_config_option_key &opt_key) const
 
bool opt_bool (const t_config_option_key &opt_key, unsigned int idx) const
 
void setenv_ () const
 
ConfigSubstitutions load (const std::string &file, ForwardCompatibilitySubstitutionRule compatibility_rule)
 
ConfigSubstitutions load_from_ini (const std::string &file, ForwardCompatibilitySubstitutionRule compatibility_rule)
 
ConfigSubstitutions load_from_ini_string (const std::string &data, ForwardCompatibilitySubstitutionRule compatibility_rule)
 
ConfigSubstitutions load_from_ini_string_commented (std::string &&data, ForwardCompatibilitySubstitutionRule compatibility_rule)
 
ConfigSubstitutions load_from_gcode_file (const std::string &file, ForwardCompatibilitySubstitutionRule compatibility_rule)
 
ConfigSubstitutions load (const boost::property_tree::ptree &tree, ForwardCompatibilitySubstitutionRule compatibility_rule)
 
void save (const std::string &file) const
 
void null_nullables ()
 
virtual const ConfigOptionoptptr (const t_config_option_key &opt_key) const=0
 
const ConfigOptionoption (const t_config_option_key &opt_key) const
 
template<typename TYPE >
const TYPE * option (const t_config_option_key &opt_key) const
 
const ConfigOptionoption_throw (const t_config_option_key &opt_key) const
 
template<typename TYPE >
const TYPE * option_throw (const t_config_option_key &opt_key) const
 
bool has (const t_config_option_key &opt_key) const
 

Static Public Member Functions

static size_t load_from_gcode_string_legacy (ConfigBase &config, const char *str, ConfigSubstitutionContext &substitutions)
 

Protected Member Functions

virtual void handle_legacy (t_config_option_key &, std::string &) const
 

Private Member Functions

bool set_deserialize_raw (const t_config_option_key &opt_key_src, const std::string &value, ConfigSubstitutionContext &substitutions, bool append)
 

Detailed Description

Constructor & Destructor Documentation

◆ ConfigBase()

Slic3r::ConfigBase::ConfigBase ( )
default

◆ ~ConfigBase()

Slic3r::ConfigBase::~ConfigBase ( )
overridedefault

Member Function Documentation

◆ apply()

void Slic3r::ConfigBase::apply ( const ConfigBase other,
bool  ignore_nonexistent = false 
)
inline
2209{ this->apply_only(other, other.keys(), ignore_nonexistent); }
void apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent=false)
Definition Config.cpp:466

References apply_only(), and keys().

Referenced by Slic3r::PresetCollection::PresetCollection(), Slic3r::GCodeProcessor::apply_config_superslicer(), Slic3r::GUI::SLAImportJob::finalize(), Slic3r::PresetBundle::full_fff_config(), Slic3r::PresetBundle::full_sla_config(), Slic3r::PresetBundle::load_config_file(), Slic3r::PresetBundle::load_configbundle(), Slic3r::GUI::Plater::priv::load_files(), Slic3r::PresetCollection::load_presets(), Slic3r::GCodeProcessor::process_file(), Slic3r::CLI::run(), and Slic3r::GUI::ObjectSettings::update_config_values().

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

◆ apply_only()

void Slic3r::ConfigBase::apply_only ( const ConfigBase other,
const t_config_option_keys keys,
bool  ignore_nonexistent = false 
)
467{
468 // loop through options and apply them
469 for (const t_config_option_key &opt_key : keys) {
470 // Create a new option with default value for the key.
471 // If the key is not in the parameter definition, or this ConfigBase is a static type and it does not support the parameter,
472 // an exception is thrown if not ignore_nonexistent.
473 ConfigOption *my_opt = this->option(opt_key, true);
474 if (my_opt == nullptr) {
475 // opt_key does not exist in this ConfigBase and it cannot be created, because it is not defined by this->def().
476 // This is only possible if other is of DynamicConfig type.
477 if (ignore_nonexistent)
478 continue;
479 throw UnknownOptionException(opt_key);
480 }
481 const ConfigOption *other_opt = other.option(opt_key);
482 if (other_opt == nullptr) {
483 // The key was not found in the source config, therefore it will not be initialized!
484// printf("Not found, therefore not initialized: %s\n", opt_key.c_str());
485 } else
486 my_opt->set(other_opt);
487 }
488}
virtual t_config_option_keys keys() const =0
Definition getopt.h:102
std::string t_config_option_key
Definition Config.hpp:76

References keys(), option(), and Slic3r::ConfigOption::set().

Referenced by Slic3r::PresetBundle::PresetBundle(), apply(), Slic3r::ModelConfig::apply(), Slic3r::ModelConfig::apply_only(), Slic3r::PresetBundle::load_config_file_config(), Slic3r::PresetCollection::load_external_preset(), Slic3r::PresetCollection::load_preset(), Slic3r::GUI::Tab::may_discard_current_dirty_preset(), Slic3r::PresetBundle::save_changes_for_preset(), Slic3r::PresetBundle::transfer_and_save(), Slic3r::PhysicalPrinter::update_from_config(), and Slic3r::PhysicalPrinter::update_from_preset().

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

◆ def()

virtual const ConfigDef * Slic3r::ConfigBase::def ( ) const
pure virtual

◆ diff()

t_config_option_keys Slic3r::ConfigBase::diff ( const ConfigBase other) const
504{
506 for (const t_config_option_key &opt_key : this->keys()) {
507 const ConfigOption *this_opt = this->option(opt_key);
508 const ConfigOption *other_opt = other.option(opt_key);
509 if (this_opt != nullptr && other_opt != nullptr && *this_opt != *other_opt)
510 diff.emplace_back(opt_key);
511 }
512 return diff;
513}
t_config_option_keys diff(const ConfigBase &other) const
Definition Config.cpp:503
std::vector< std::string > t_config_option_keys
Definition Config.hpp:77

References diff(), keys(), and option().

Referenced by diff(), and Slic3r::DynamicConfig::diff().

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

◆ equal()

t_config_option_keys Slic3r::ConfigBase::equal ( const ConfigBase other) const
517{
519 for (const t_config_option_key &opt_key : this->keys()) {
520 const ConfigOption *this_opt = this->option(opt_key);
521 const ConfigOption *other_opt = other.option(opt_key);
522 if (this_opt != nullptr && other_opt != nullptr && *this_opt == *other_opt)
523 equal.emplace_back(opt_key);
524 }
525 return equal;
526}
t_config_option_keys equal(const ConfigBase &other) const
Definition Config.cpp:516

References equal(), keys(), and option().

Referenced by equal(), and Slic3r::DynamicConfig::equal().

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

◆ equals()

bool Slic3r::ConfigBase::equals ( const ConfigBase other) const
492{
493 for (const t_config_option_key &opt_key : this->keys()) {
494 const ConfigOption *this_opt = this->option(opt_key);
495 const ConfigOption *other_opt = other.option(opt_key);
496 if (this_opt != nullptr && other_opt != nullptr && *this_opt != *other_opt)
497 return false;
498 }
499 return true;
500}

References keys(), and option().

+ Here is the call graph for this function:

◆ get_abs_value() [1/2]

double Slic3r::ConfigBase::get_abs_value ( const t_config_option_key opt_key) const
670{
671 // Get stored option value.
672 const ConfigOption *raw_opt = this->option(opt_key);
673 assert(raw_opt != nullptr);
674 if (raw_opt->type() == coFloat)
675 return static_cast<const ConfigOptionFloat*>(raw_opt)->value;
676 if (raw_opt->type() == coFloatOrPercent) {
677 // Get option definition.
678 const ConfigDef *def = this->def();
679 if (def == nullptr)
680 throw NoDefinitionException(opt_key);
681 const ConfigOptionDef *opt_def = def->get(opt_key);
682 assert(opt_def != nullptr);
683 // Compute absolute value over the absolute value of the base option.
684 //FIXME there are some ratio_over chains, which end with empty ratio_with.
685 // For example, XXX_extrusion_width parameters are not handled by get_abs_value correctly.
686 return opt_def->ratio_over.empty() ? 0. :
687 static_cast<const ConfigOptionFloatOrPercent*>(raw_opt)->get_abs_value(this->get_abs_value(opt_def->ratio_over));
688 }
689 throw ConfigurationError("ConfigBase::get_abs_value(): Not a valid option type for get_abs_value()");
690}
virtual const ConfigDef * def() const =0
double get_abs_value(const t_config_option_key &opt_key) const
Definition Config.cpp:669
const ConfigOptionDef * get(const t_config_option_key &opt_key) const
Definition Config.hpp:2069
ConfigOptionFloat
Definition PrintConfig.hpp:570
@ coFloat
Definition Config.hpp:164
@ coFloatOrPercent
Definition Config.hpp:180

References Slic3r::coFloat, Slic3r::coFloatOrPercent, def(), Slic3r::ConfigDef::get(), get_abs_value(), Slic3r::ConfigOptionDef::ratio_over, and Slic3r::ConfigOption::type().

Referenced by get_abs_value(), get_abs_value(), Slic3r::PresetHints::maximum_volumetric_flow_description(), and Slic3r::CLI::run().

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

◆ get_abs_value() [2/2]

double Slic3r::ConfigBase::get_abs_value ( const t_config_option_key opt_key,
double  ratio_over 
) const
695{
696 // Get stored option value.
697 const ConfigOption *raw_opt = this->option(opt_key);
698 assert(raw_opt != nullptr);
699 if (raw_opt->type() != coFloatOrPercent)
700 throw ConfigurationError("ConfigBase::get_abs_value(): opt_key is not of coFloatOrPercent");
701 // Compute absolute value.
702 return static_cast<const ConfigOptionFloatOrPercent*>(raw_opt)->get_abs_value(ratio_over);
703}

References Slic3r::coFloatOrPercent, get_abs_value(), and Slic3r::ConfigOption::type().

+ Here is the call graph for this function:

◆ handle_legacy()

virtual void Slic3r::ConfigBase::handle_legacy ( t_config_option_key ,
std::string &   
) const
inlineprotectedvirtual

Reimplemented in Slic3r::DynamicPrintConfig, Slic3r::StaticPrintConfig, and Slic3r::DynamicPrintAndCLIConfig.

2162{}

Referenced by set_deserialize_nothrow().

+ Here is the caller graph for this function:

◆ has()

◆ keys()

virtual t_config_option_keys Slic3r::ConfigBase::keys ( ) const
pure virtual

◆ load() [1/2]

ConfigSubstitutions Slic3r::ConfigBase::load ( const boost::property_tree::ptree &  tree,
ForwardCompatibilitySubstitutionRule  compatibility_rule 
)
790{
791 ConfigSubstitutionContext substitutions_ctxt(compatibility_rule);
792 for (const boost::property_tree::ptree::value_type &v : tree) {
793 try {
794 t_config_option_key opt_key = v.first;
795 this->set_deserialize(opt_key, v.second.get_value<std::string>(), substitutions_ctxt);
796 } catch (UnknownOptionException & /* e */) {
797 // ignore
798 }
799 }
800 return std::move(substitutions_ctxt.substitutions);
801}
void set_deserialize(const t_config_option_key &opt_key, const std::string &str, ConfigSubstitutionContext &config_substitutions, bool append=false)
Definition Config.cpp:571

References set_deserialize(), and Slic3r::ConfigSubstitutionContext::substitutions.

+ Here is the call graph for this function:

◆ load() [2/2]

ConfigSubstitutions Slic3r::ConfigBase::load ( const std::string &  file,
ForwardCompatibilitySubstitutionRule  compatibility_rule 
)
724{
725 return is_gcode_file(file) ?
726 this->load_from_gcode_file(file, compatibility_rule) :
727 this->load_from_ini(file, compatibility_rule);
728}
ConfigSubstitutions load_from_ini(const std::string &file, ForwardCompatibilitySubstitutionRule compatibility_rule)
Definition Config.cpp:730
ConfigSubstitutions load_from_gcode_file(const std::string &file, ForwardCompatibilitySubstitutionRule compatibility_rule)
Definition Config.cpp:928
bool is_gcode_file(const std::string &path)
Definition utils.cpp:783

References Slic3r::is_gcode_file(), load_from_gcode_file(), and load_from_ini().

Referenced by Slic3r::extract_profile(), Slic3r::PresetBundle::load_config_file(), load_from_ini(), load_from_ini_string(), Slic3r::SL1Reader::read(), Slic3r::SL1_SVGReader::read(), and Slic3r::CLI::run().

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

◆ load_from_gcode_file()

ConfigSubstitutions Slic3r::ConfigBase::load_from_gcode_file ( const std::string &  file,
ForwardCompatibilitySubstitutionRule  compatibility_rule 
)
929{
930 // Read a 64k block from the end of the G-code.
931 boost::nowide::ifstream ifs(file, std::ifstream::binary);
932 // Look for Slic3r or PrusaSlicer header.
933 // Look for the header across the whole file as the G-code may have been extended at the start by a post-processing script or the user.
934 bool has_delimiters = false;
935 {
936 static constexpr const char slic3r_gcode_header[] = "; generated by Slic3r ";
937 static constexpr const char prusaslicer_gcode_header[] = "; generated by PrusaSlicer ";
938 std::string header;
939 bool header_found = false;
940 while (std::getline(ifs, header)) {
941 if (strncmp(slic3r_gcode_header, header.c_str(), strlen(slic3r_gcode_header)) == 0) {
942 header_found = true;
943 break;
944 } else if (strncmp(prusaslicer_gcode_header, header.c_str(), strlen(prusaslicer_gcode_header)) == 0) {
945 // Parse PrusaSlicer version.
946 size_t i = strlen(prusaslicer_gcode_header);
947 for (; i < header.size() && header[i] == ' '; ++ i) ;
948 size_t j = i;
949 for (; j < header.size() && header[j] != ' '; ++ j) ;
950 try {
951 Semver semver(header.substr(i, j - i));
952 has_delimiters = semver >= Semver(2, 4, 0, nullptr, "alpha0");
953 } catch (const RuntimeError &) {
954 }
955 header_found = true;
956 break;
957 }
958 }
959 if (! header_found)
960 throw Slic3r::RuntimeError("Not a PrusaSlicer / Slic3r PE generated g-code.");
961 }
962
963 auto header_end_pos = ifs.tellg();
964 ConfigSubstitutionContext substitutions_ctxt(compatibility_rule);
965 size_t key_value_pairs = 0;
966
967 if (has_delimiters)
968 {
969 // PrusaSlicer starting with 2.4.0-alpha0 delimits the config section stored into G-code with
970 // ; prusaslicer_config = begin
971 // ...
972 // ; prusaslicer_config = end
973 // The begin / end tags look like any other key / value pairs on purpose to be compatible with older G-code viewer.
974 // Read the file in reverse line by line.
975 ReverseLineReader reader(ifs, header_end_pos);
976 // Read the G-code file by 64k blocks back to front.
977 bool begin_found = false;
978 bool end_found = false;
979 std::string line;
980 while (reader.getline(line))
981 if (line == "; prusaslicer_config = end") {
982 end_found = true;
983 break;
984 }
985 if (! end_found)
986 throw Slic3r::RuntimeError(format("Configuration block closing tag \"; prusaslicer_config = end\" not found when reading %1%", file));
987 std::string key, value;
988 while (reader.getline(line)) {
989 if (line == "; prusaslicer_config = begin") {
990 begin_found = true;
991 break;
992 }
993 // line should be a valid key = value pair.
994 auto pos = line.find('=');
995 if (pos != std::string::npos && pos > 1 && line.front() == ';') {
996 key = line.substr(1, pos - 1);
997 value = line.substr(pos + 1);
998 boost::trim(key);
999 boost::trim(value);
1000 try {
1001 this->set_deserialize(key, value, substitutions_ctxt);
1002 ++ key_value_pairs;
1003 } catch (UnknownOptionException & /* e */) {
1004 // ignore
1005 }
1006 }
1007 }
1008 if (! begin_found)
1009 throw Slic3r::RuntimeError(format("Configuration block opening tag \"; prusaslicer_config = begin\" not found when reading %1%", file));
1010 }
1011 else
1012 {
1013 // Slic3r or PrusaSlicer older than 2.4.0-alpha0 do not emit any delimiter.
1014 // Try a heuristics reading the G-code from back.
1015 ifs.seekg(0, ifs.end);
1016 auto file_length = ifs.tellg();
1017 auto data_length = std::min<std::fstream::pos_type>(65535, file_length - header_end_pos);
1018 ifs.seekg(file_length - data_length, ifs.beg);
1019 std::vector<char> data(size_t(data_length) + 1, 0);
1020 ifs.read(data.data(), data_length);
1021 ifs.close();
1022 key_value_pairs = load_from_gcode_string_legacy(*this, data.data(), substitutions_ctxt);
1023 }
1024
1025 if (key_value_pairs < 80)
1026 throw Slic3r::RuntimeError(format("Suspiciously low number of configuration values extracted from %1%: %2%", file, key_value_pairs));
1027 return std::move(substitutions_ctxt.substitutions);
1028}
static size_t load_from_gcode_string_legacy(ConfigBase &config, const char *str, ConfigSubstitutionContext &substitutions)
Definition Config.cpp:804
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:14
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:44
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195

References Slic3r::format(), Slic3r::ReverseLineReader::getline(), load_from_gcode_string_legacy(), set_deserialize(), and Slic3r::ConfigSubstitutionContext::substitutions.

Referenced by load(), Slic3r::PresetBundle::load_config_file(), and Slic3r::GCodeProcessor::process_file().

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

◆ load_from_gcode_string_legacy()

size_t Slic3r::ConfigBase::load_from_gcode_string_legacy ( ConfigBase config,
const char *  str,
ConfigSubstitutionContext substitutions 
)
static
805{
806 if (str == nullptr)
807 return 0;
808
809 // Walk line by line in reverse until a non-configuration key appears.
810 const char *data_start = str;
811 // boost::nowide::ifstream seems to cook the text data somehow, so less then the 64k of characters may be retrieved.
812 const char *end = data_start + strlen(str);
813 size_t num_key_value_pairs = 0;
814 for (;;) {
815 // Extract next line.
816 for (--end; end > data_start && (*end == '\r' || *end == '\n'); --end);
817 if (end == data_start)
818 break;
819 const char *start = end ++;
820 for (; start > data_start && *start != '\r' && *start != '\n'; --start);
821 if (start == data_start)
822 break;
823 // Extracted a line from start to end. Extract the key = value pair.
824 if (end - (++ start) < 10 || start[0] != ';' || start[1] != ' ')
825 break;
826 const char *key = start + 2;
827 if (!((*key >= 'a' && *key <= 'z') || (*key >= 'A' && *key <= 'Z')))
828 // A key must start with a letter.
829 break;
830 const char *sep = key;
831 for (; sep != end && *sep != '='; ++ sep) ;
832 if (sep == end || sep[-1] != ' ' || sep[1] != ' ')
833 break;
834 const char *value = sep + 2;
835 if (value > end)
836 break;
837 const char *key_end = sep - 1;
838 if (key_end - key < 3)
839 break;
840 // The key may contain letters, digits and underscores.
841 for (const char *c = key; c != key_end; ++ c)
842 if (!((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '_')) {
843 key = nullptr;
844 break;
845 }
846 if (key == nullptr)
847 break;
848 try {
849 config.set_deserialize(std::string(key, key_end), std::string(value, end), substitutions);
850 ++num_key_value_pairs;
851 }
852 catch (UnknownOptionException & /* e */) {
853 // ignore
854 }
855 end = start;
856 }
857
858 return num_key_value_pairs;
859}
S::iterator end(S &sh, const PathTag &)
Definition geometry_traits.hpp:620

References set_deserialize().

Referenced by Slic3r::AMFParserContext::endElement(), load_from_gcode_file(), and Slic3r::load_from_superslicer_gcode_file().

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

◆ load_from_ini()

ConfigSubstitutions Slic3r::ConfigBase::load_from_ini ( const std::string &  file,
ForwardCompatibilitySubstitutionRule  compatibility_rule 
)
731{
732 try {
733 boost::property_tree::ptree tree;
734 boost::nowide::ifstream ifs(file);
735 boost::property_tree::read_ini(ifs, tree);
736 return this->load(tree, compatibility_rule);
737 } catch (const ConfigurationError &e) {
738 throw ConfigurationError(format("Failed loading configuration file \"%1%\": %2%", file, e.what()));
739 }
740}
ConfigSubstitutions load(const std::string &file, ForwardCompatibilitySubstitutionRule compatibility_rule)
Definition Config.cpp:723

References Slic3r::format(), and load().

Referenced by load(), Slic3r::PresetCollection::load_presets(), and Slic3r::PhysicalPrinterCollection::load_printers().

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

◆ load_from_ini_string()

ConfigSubstitutions Slic3r::ConfigBase::load_from_ini_string ( const std::string &  data,
ForwardCompatibilitySubstitutionRule  compatibility_rule 
)
743{
744 boost::property_tree::ptree tree;
745 std::istringstream iss(data);
746 boost::property_tree::read_ini(iss, tree);
747 return this->load(tree, compatibility_rule);
748}

References load().

Referenced by Slic3r::anonymous_namespace{AnycubicSLA.cpp}::fill_header(), and load_from_ini_string_commented().

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

◆ load_from_ini_string_commented()

ConfigSubstitutions Slic3r::ConfigBase::load_from_ini_string_commented ( std::string &&  data,
ForwardCompatibilitySubstitutionRule  compatibility_rule 
)
753{
754 // Convert the "data" string into INI format by removing the semi-colons at the start of a line.
755 // Also the "; generated by PrusaSlicer ..." comment line will be removed.
756 size_t j = 0;
757 for (size_t i = 0; i < data.size();)
758 if (i == 0 || data[i] == '\n') {
759 // Start of a line.
760 if (data[i] == '\n') {
761 // Consume LF, don't keep empty lines.
762 if (j > 0 && data[j - 1] != '\n')
763 data[j ++] = data[i];
764 ++ i;
765 }
766 // Skip all leading spaces;
767 for (; i < data.size() && (data[i] == ' ' || data[i] == '\t'); ++ i) ;
768 // Skip the semicolon (comment indicator).
769 if (i < data.size() && data[i] == ';')
770 ++ i;
771 // Skip all leading spaces after semicolon.
772 for (; i < data.size() && (data[i] == ' ' || data[i] == '\t'); ++ i) ;
773 if (strncmp(data.data() + i, "generated by ", 13) == 0) {
774 // Skip the "; generated by ..." line.
775 for (; i < data.size() && data[i] != '\n'; ++ i);
776 }
777 } else if (data[i] == '\r' && i + 1 < data.size() && data[i + 1] == '\n') {
778 // Skip CR.
779 ++ i;
780 } else {
781 // Consume the rest of the data.
782 data[j ++] = data[i ++];
783 }
784 data.erase(data.begin() + j, data.end());
785
786 return this->load_from_ini_string(data, compatibility_rule);
787}
ConfigSubstitutions load_from_ini_string(const std::string &data, ForwardCompatibilitySubstitutionRule compatibility_rule)
Definition Config.cpp:742

References load_from_ini_string().

+ Here is the call graph for this function:

◆ null_nullables()

void Slic3r::ConfigBase::null_nullables ( )
1042{
1043 for (const std::string &opt_key : this->keys()) {
1044 ConfigOption *opt = this->optptr(opt_key, false);
1045 assert(opt != nullptr);
1046 if (opt->nullable())
1047 opt->deserialize("nil", ForwardCompatibilitySubstitutionRule::Disable);
1048 }
1049}
virtual ConfigOption * optptr(const t_config_option_key &opt_key, bool create=false)=0
T * opt(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2196
@ Disable
Definition Config.hpp:219

References Slic3r::ConfigOption::deserialize(), Slic3r::Disable, keys(), Slic3r::ConfigOption::nullable(), opt(), and optptr().

Referenced by Slic3r::PresetBundle::PresetBundle().

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

◆ opt() [1/2]

template<class T >
const T * Slic3r::ConfigBase::opt ( const t_config_option_key opt_key) const
inline
2199 { return dynamic_cast<const T*>(this->optptr(opt_key)); }

References optptr().

+ Here is the call graph for this function:

◆ opt() [2/2]

template<class T >
T * Slic3r::ConfigBase::opt ( const t_config_option_key opt_key,
bool  create = false 
)
inline
2197 { return dynamic_cast<T*>(this->optptr(opt_key, create)); }

References optptr().

Referenced by Slic3r::apply_to_print_region_config(), Slic3r::GUI::GLCanvas3D::WipeTowerInfo::apply_wipe_tower(), Slic3r::PrinterPresetCollection::default_preset_for(), Slic3r::get_bed_shape(), Slic3r::GUI::Materials::get_filament_type(), Slic3r::GUI::Materials::get_filament_vendor(), Slic3r::GUI::Materials::get_material_type(), Slic3r::GUI::Materials::get_material_vendor(), Slic3r::GUI::get_string_value(), Slic3r::handle_legacy_sla(), Slic3r::is_XL_printer(), Slic3r::DynamicConfig::keys(), Slic3r::GUI::Plater::priv::load_files(), Slic3r::GUI::Plater::priv::load_model_objects(), Slic3r::DynamicPrintConfig::normalize_fdm(), null_nullables(), Slic3r::GUI::Plater::priv::on_wipetower_moved(), Slic3r::GUI::Plater::priv::on_wipetower_rotated(), opt_serialize(), option(), option_throw(), Slic3r::DynamicConfig::optptr(), Slic3r::PresetHints::recommended_thin_wall_thickness(), Slic3r::CLI::run(), Slic3r::run_post_process_scripts(), set(), set(), Slic3r::StaticConfig::set_defaults(), set_deserialize_raw(), Slic3r::DynamicPrintConfig::set_num_extruders(), Slic3r::CLI::setup(), Slic3r::PresetUtils::system_printer_model(), Slic3r::GUI::anonymous_namespace{HintNotification.cpp}::tag_check_material(), Slic3r::GUI::DiffPresetDialog::update_tree(), Slic3r::GUI::UnsavedChangesDialog::update_tree(), and Slic3r::DynamicPrintConfig::validate().

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

◆ opt_bool() [1/2]

◆ opt_bool() [2/2]

bool Slic3r::ConfigBase::opt_bool ( const t_config_option_key opt_key,
unsigned int  idx 
) const
inline
2297{ return this->option<ConfigOptionBools>(opt_key)->get_at(idx) != 0; }

◆ opt_enum()

template<typename ENUM >
ENUM Slic3r::ConfigBase::opt_enum ( const t_config_option_key opt_key) const
inline
2294{ return static_cast<ENUM>(this->option(opt_key)->getInt()); }

Referenced by Slic3r::BackgroundSlicingProcess::apply(), Slic3r::GUI::Plater::on_config_change(), Slic3r::GUI::ConfigManipulation::toggle_print_fff_options(), Slic3r::GUI::ConfigManipulation::toggle_print_sla_options(), and Slic3r::GUI::ConfigManipulation::update_print_fff_config().

+ Here is the caller graph for this function:

◆ opt_float() [1/4]

◆ opt_float() [2/4]

const double & Slic3r::ConfigBase::opt_float ( const t_config_option_key opt_key) const
inline
2282{ return dynamic_cast<const ConfigOptionFloat*>(this->option(opt_key))->value; }

◆ opt_float() [3/4]

double & Slic3r::ConfigBase::opt_float ( const t_config_option_key opt_key,
unsigned int  idx 
)
inline
2283{ return this->option<ConfigOptionFloats>(opt_key)->get_at(idx); }

◆ opt_float() [4/4]

const double & Slic3r::ConfigBase::opt_float ( const t_config_option_key opt_key,
unsigned int  idx 
) const
inline
2284{ return dynamic_cast<const ConfigOptionFloats*>(this->option(opt_key))->get_at(idx); }
ConfigOptionFloatsTempl< false > ConfigOptionFloats
Definition Config.hpp:716

◆ opt_int() [1/4]

◆ opt_int() [2/4]

int Slic3r::ConfigBase::opt_int ( const t_config_option_key opt_key) const
inline
2287{ return dynamic_cast<const ConfigOptionInt*>(this->option(opt_key))->value; }

◆ opt_int() [3/4]

int & Slic3r::ConfigBase::opt_int ( const t_config_option_key opt_key,
unsigned int  idx 
)
inline
2288{ return this->option<ConfigOptionInts>(opt_key)->get_at(idx); }

◆ opt_int() [4/4]

int Slic3r::ConfigBase::opt_int ( const t_config_option_key opt_key,
unsigned int  idx 
) const
inline
2289{ return dynamic_cast<const ConfigOptionInts*>(this->option(opt_key))->get_at(idx); }
ConfigOptionIntsTempl< false > ConfigOptionInts
Definition Config.hpp:844

◆ opt_serialize()

std::string Slic3r::ConfigBase::opt_serialize ( const t_config_option_key opt_key) const
529{
530 const ConfigOption* opt = this->option(opt_key);
531 assert(opt != nullptr);
532 return opt->serialize();
533}

References opt(), and Slic3r::ConfigOption::serialize().

Referenced by Slic3r::_3MF_Exporter::_add_print_config_file_to_archive(), Slic3r::GCode::append_full_config(), Slic3r::anonymous_namespace{SL1.cpp}::fill_slicerconf(), Slic3r::ModelConfig::opt_serialize(), save(), and Slic3r::store_amf().

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

◆ opt_string() [1/4]

const std::string & Slic3r::ConfigBase::opt_string ( const t_config_option_key opt_key) const
inline
2277{ return const_cast<ConfigBase*>(this)->opt_string(opt_key); }
ConfigBase()=default
std::string & opt_string(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2276

References opt_string().

Referenced by opt_string().

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

◆ opt_string() [2/4]

std::string & Slic3r::ConfigBase::opt_string ( const t_config_option_key opt_key,
bool  create = false 
)
inline
2276{ return this->option<ConfigOptionString>(opt_key, create)->value; }

Referenced by Slic3r::PresetBundle::PresetBundle(), Slic3r::_3MF_Exporter::_add_custom_gcode_per_print_z_file_to_archive(), Slic3r::GUI::ConfigOptionsGroup::back_to_config_value(), Slic3r::GUI::PhysicalPrinterDialog::build_printhost_settings(), Slic3r::PhysicalPrinterCollection::find_printer_with_same_config(), Slic3r::PrinterPresetCollection::find_system_preset_by_model_and_variant(), Slic3r::GUI::ConfigOptionsGroup::get_config_value(), Slic3r::GUI::get_string_value(), Slic3r::PhysicalPrinter::has_empty_config(), Slic3r::PhysicalPrinter::has_print_host_information(), Slic3r::PresetBundle::load_config_file_config(), Slic3r::PresetBundle::load_configbundle(), Slic3r::PhysicalPrinterCollection::load_printers_from_presets(), Slic3r::GUI::PresetComboBox::open_physical_printer_url(), Slic3r::PrintBase::output_filename(), Slic3r::CLI::output_filepath(), Slic3r::CLI::run(), Slic3r::GUI::Tab::save_preset(), Slic3r::Preset::set_visible_from_appconfig(), Slic3r::CLI::setup(), Slic3r::GUI::PlaterPresetComboBox::show_edit_menu(), Slic3r::store_amf(), Slic3r::GUI::TabSLAMaterial::toggle_options(), Slic3r::GUI::PlaterPresetComboBox::update(), Slic3r::GLVolumeCollection::update_colors_by_extruder(), Slic3r::PresetBundle::update_compatible(), Slic3r::GUI::Plater::update_filament_colors_in_full_config(), Slic3r::PresetBundle::update_filaments_compatible(), Slic3r::GUI::PhysicalPrinterDialog::update_host_type(), Slic3r::GUI::Tab::update_preset_description_line(), and Slic3r::GUI::PhysicalPrinterDialog::update_printhost_buttons().

+ Here is the caller graph for this function:

◆ opt_string() [3/4]

std::string & Slic3r::ConfigBase::opt_string ( const t_config_option_key opt_key,
unsigned int  idx 
)
inline
2278{ return this->option<ConfigOptionStrings>(opt_key)->get_at(idx); }

◆ opt_string() [4/4]

const std::string & Slic3r::ConfigBase::opt_string ( const t_config_option_key opt_key,
unsigned int  idx 
) const
inline
2279{ return const_cast<ConfigBase*>(this)->opt_string(opt_key, idx); }

References opt_string().

Referenced by opt_string().

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

◆ option() [1/4]

const ConfigOption * Slic3r::ConfigOptionResolver::option ( const t_config_option_key opt_key) const
inline
2107{ return this->optptr(opt_key); }

◆ option() [2/4]

template<typename TYPE >
const TYPE * Slic3r::ConfigOptionResolver::option ( const t_config_option_key opt_key) const
inline
2111 {
2112 const ConfigOption* opt = this->optptr(opt_key);
2113 return (opt == nullptr || opt->type() != TYPE::static_type()) ? nullptr : static_cast<const TYPE*>(opt);
2114 }

◆ option() [3/4]

ConfigOption * Slic3r::ConfigBase::option ( const t_config_option_key opt_key,
bool  create = false 
)
inline
2170 { return this->optptr(opt_key, create); }

References optptr().

Referenced by Slic3r::DynamicConfig::DynamicConfig(), Slic3r::PresetBundle::PresetBundle(), Slic3r::GCode::_do_export(), Slic3r::GUI::GLCanvas3D::_render_arrange_menu(), Slic3r::GUI::ObjectList::add_category_to_settings_from_frequent(), Slic3r::GUI::ObjectList::add_category_to_settings_from_selection(), Slic3r::add_correct_opts_to_diff(), Slic3r::GUI::add_correct_opts_to_options_list(), Slic3r::GUI::ObjectSettings::add_missed_options(), Slic3r::GCode::append_full_config(), Slic3r::Search::OptionsSearcher::append_options(), Slic3r::Print::apply(), Slic3r::SLAPrint::apply(), Slic3r::GUI::ConfigManipulation::apply(), Slic3r::GCodeProcessor::apply_config(), Slic3r::PlaceholderParser::apply_config(), apply_only(), Slic3r::PlaceholderParser::apply_only(), Slic3r::GUI::ConfigOptionsGroup::back_to_config_value(), Slic3r::GUI::TabSLAMaterial::build(), Slic3r::GUI::TabPrinter::build_extruder_pages(), Slic3r::GUI::TabPrinter::build_fff(), Slic3r::GUI::TabPrinter::cache_extruder_cnt(), Slic3r::GUI::PlaterPresetComboBox::change_extruder_color(), Slic3r::Search::change_opt_key(), Slic3r::GUI::change_opt_value(), Slic3r::Preset::compatible_printers_condition(), Slic3r::Preset::compatible_prints_condition(), Slic3r::copy_bed_model_and_texture_if_needed(), Slic3r::deep_diff(), Slic3r::GUI::Bed3D::detect_type(), diff(), equal(), equals(), Slic3r::GUI::GUI_App::extruders_cnt(), Slic3r::GUI::GUI_App::extruders_edited_cnt(), Slic3r::anonymous_namespace{AnycubicSLA.cpp}::fill_header(), Slic3r::GUI::Plater::force_filament_colors_update(), Slic3r::PresetBundle::full_fff_config(), Slic3r::full_print_config_diffs(), Slic3r::PresetBundle::full_sla_config(), Slic3r::anonymous_namespace{SL1.cpp}::get_cfg_value(), Slic3r::anonymous_namespace{AnycubicSLA.cpp}::get_cfg_value_f(), Slic3r::anonymous_namespace{AnycubicSLA.cpp}::get_cfg_value_i(), Slic3r::GUI::GLGizmoHollow::get_config_options(), Slic3r::GUI::GLGizmoSlaSupports::get_config_options(), Slic3r::GUI::ConfigOptionsGroup::get_config_value(), Slic3r::GUI::Plater::get_extruder_colors_from_plater_config(), Slic3r::GUI::get_full_label(), Slic3r::PrintHost::get_print_host(), get_printer_technology(), Slic3r::get_raster_params(), Slic3r::get_sla_suptree_prefix(), Slic3r::get_slice_params(), Slic3r::GUI::get_string_value(), Slic3r::handle_legacy_project_loaded(), Slic3r::Preset::inherits(), Slic3r::is_compatible_with_print(), Slic3r::is_compatible_with_printer(), Slic3r::is_compatible_with_printer(), Slic3r::GUI::MainFrame::load_config(), Slic3r::GUI::Tab::load_config(), Slic3r::GUI::Tab::load_current_preset(), Slic3r::PresetHints::maximum_volumetric_flow_description(), Slic3r::min_object_distance(), Slic3r::Preset::normalize(), Slic3r::GUI::Plater::on_config_change(), Slic3r::GUI::GLGizmoSlaSupports::on_set_state(), Slic3r::PlaceholderParser::option(), Slic3r::ModelConfig::option(), Slic3r::client::MyContext::optptr(), Slic3r::opts_equal(), Slic3r::GUI::ObjectList::paste_settings_into_list(), Slic3r::BackgroundSlicingProcess::prepare_upload(), Slic3r::print_config_diffs(), Slic3r::Preset::printer_technology(), Slic3r::PhysicalPrinter::printer_technology(), Slic3r::Preset::printer_technology_ref(), Slic3r::BackgroundSlicingProcess::process_sla(), Slic3r::GUI::GLCanvas3D::reload_scene(), Slic3r::CLI::run(), Slic3r::CLI::setup(), Slic3r::GUI::Plater::priv::show_action_buttons(), Slic3r::GUI::ConfigManipulation::toggle_print_fff_options(), Slic3r::GUI::PhysicalPrinterDialog::update(), Slic3r::GLVolumeCollection::update_colors_by_extruder(), Slic3r::PresetCollection::update_compatible_internal(), Slic3r::ExtruderFilaments::update_compatible_internal(), Slic3r::CustomGCode::update_custom_gcode_per_print_z_from_config(), Slic3r::PresetBundle::update_filaments_compatible(), Slic3r::PhysicalPrinter::update_from_config(), Slic3r::GUI::PhysicalPrinterDialog::update_host_type(), Slic3r::GUI::Tab::update_preset_description_line(), Slic3r::PhysicalPrinter::update_preset_names_in_config(), Slic3r::GUI::Sidebar::update_presets(), Slic3r::GUI::ConfigManipulation::update_print_fff_config(), and Slic3r::GUI::Sidebar::update_sliced_info_sizer().

+ Here is the call graph for this function:

◆ option() [4/4]

template<typename TYPE >
TYPE * Slic3r::ConfigBase::option ( const t_config_option_key opt_key,
bool  create = false 
)
inline
2174 {
2175 ConfigOption *opt = this->optptr(opt_key, create);
2176 return (opt == nullptr || opt->type() != TYPE::static_type()) ? nullptr : static_cast<TYPE*>(opt);
2177 }

References opt(), optptr(), and Slic3r::ConfigOption::type().

+ Here is the call graph for this function:

◆ option_def()

const ConfigOptionDef * Slic3r::ConfigBase::option_def ( const t_config_option_key opt_key) const
inline
2204 { return this->def()->get(opt_key); }

References def(), and Slic3r::ConfigDef::get().

Referenced by Slic3r::Search::OptionsSearcher::append_options(), Slic3r::GUI::GLGizmoHollow::get_config_options(), Slic3r::GUI::get_string_value(), Slic3r::DynamicConfig::read_cli(), and Slic3r::GUI::ConfigManipulation::update_print_fff_config().

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

◆ option_throw() [1/4]

const ConfigOption * Slic3r::ConfigOptionResolver::option_throw ( const t_config_option_key opt_key) const
inline
2117 {
2118 const ConfigOption* opt = this->optptr(opt_key);
2119 if (opt == nullptr)
2120 throw UnknownOptionException(opt_key);
2121 return opt;
2122 }

◆ option_throw() [2/4]

template<typename TYPE >
const TYPE * Slic3r::ConfigOptionResolver::option_throw ( const t_config_option_key opt_key) const
inline
2126 {
2127 const ConfigOption* opt = this->option_throw(opt_key);
2128 if (opt->type() != TYPE::static_type())
2129 throw BadOptionTypeException("Conversion to a wrong type");
2130 return static_cast<TYPE*>(opt);
2131 }
ConfigOption * option_throw(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2179

◆ option_throw() [3/4]

ConfigOption * Slic3r::ConfigBase::option_throw ( const t_config_option_key opt_key,
bool  create = false 
)
inline
2180 {
2181 ConfigOption *opt = this->optptr(opt_key, create);
2182 if (opt == nullptr)
2183 throw UnknownOptionException(opt_key);
2184 return opt;
2185 }

References opt(), and optptr().

Referenced by option_throw(), set(), and set().

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

◆ option_throw() [4/4]

template<typename TYPE >
TYPE * Slic3r::ConfigBase::option_throw ( const t_config_option_key opt_key,
bool  create = false 
)
inline
2189 {
2190 ConfigOption *opt = this->option_throw(opt_key, create);
2191 if (opt->type() != TYPE::static_type())
2192 throw BadOptionTypeException("Conversion to a wrong type");
2193 return static_cast<TYPE*>(opt);
2194 }

References opt(), option_throw(), and Slic3r::ConfigOption::type().

+ Here is the call graph for this function:

◆ optptr() [1/2]

virtual const ConfigOption * Slic3r::ConfigOptionResolver::optptr ( const t_config_option_key opt_key) const
virtual

Implements Slic3r::ConfigOptionResolver.

Reimplemented in Slic3r::DynamicConfig.

◆ optptr() [2/2]

virtual ConfigOption * Slic3r::ConfigBase::optptr ( const t_config_option_key opt_key,
bool  create = false 
)
pure virtual

Implemented in Slic3r::DynamicConfig.

Referenced by null_nullables(), opt(), opt(), option(), and option_throw().

+ Here is the caller graph for this function:

◆ save()

void Slic3r::ConfigBase::save ( const std::string &  file) const
1031{
1032 boost::nowide::ofstream c;
1033 c.open(file, std::ios::out | std::ios::trunc);
1034 c << "# " << Slic3r::header_slic3r_generated() << std::endl;
1035 for (const std::string &opt_key : this->keys())
1036 c << opt_key << " = " << this->opt_serialize(opt_key) << std::endl;
1037 c.close();
1038}
std::string opt_serialize(const t_config_option_key &opt_key) const
Definition Config.cpp:528
std::string header_slic3r_generated()
Definition utils.cpp:914
STL namespace.

References Slic3r::header_slic3r_generated(), keys(), and opt_serialize().

Referenced by Slic3r::CLI::run(), Slic3r::Preset::save(), Slic3r::PhysicalPrinter::save(), and Slic3r::PhysicalPrinter::save().

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

◆ set() [1/5]

void Slic3r::ConfigBase::set ( const std::string &  opt_key,
bool  value,
bool  create = false 
)
inline
2227 { this->option_throw<ConfigOptionBool>(opt_key, create)->value = value; }

Referenced by Slic3r::extract_profile(), and Slic3r::ModelConfig::set().

+ Here is the caller graph for this function:

◆ set() [2/5]

void Slic3r::ConfigBase::set ( const std::string &  opt_key,
const char *  value,
bool  create = false 
)
inline
2231 { this->option_throw<ConfigOptionString>(opt_key, create)->value = value; }

◆ set() [3/5]

void Slic3r::ConfigBase::set ( const std::string &  opt_key,
const std::string &  value,
bool  create = false 
)
inline
2233 { this->option_throw<ConfigOptionString>(opt_key, create)->value = value; }

◆ set() [4/5]

void Slic3r::ConfigBase::set ( const std::string &  opt_key,
double  value,
bool  create = false 
)
548{
549 ConfigOption *opt = this->option_throw(opt_key, create);
550 switch (opt->type()) {
551 case coFloat: static_cast<ConfigOptionFloat*>(opt)->value = value; break;
552 case coFloatOrPercent: static_cast<ConfigOptionFloatOrPercent*>(opt)->value = value; static_cast<ConfigOptionFloatOrPercent*>(opt)->percent = false; break;
553 case coString: static_cast<ConfigOptionString*>(opt)->value = float_to_string_decimal_point(value); break;
554 default: throw BadOptionTypeException("Configbase::set() - conversion from float not possible");
555 }
556}
std::string float_to_string_decimal_point(double value, int precision)
Definition LocalesUtils.cpp:74
@ coString
Definition Config.hpp:172

References Slic3r::coFloat, Slic3r::coFloatOrPercent, Slic3r::coString, Slic3r::float_to_string_decimal_point(), opt(), option_throw(), and Slic3r::ConfigOption::type().

+ Here is the call graph for this function:

◆ set() [5/5]

void Slic3r::ConfigBase::set ( const std::string &  opt_key,
int  value,
bool  create = false 
)
536{
537 ConfigOption *opt = this->option_throw(opt_key, create);
538 switch (opt->type()) {
539 case coInt: static_cast<ConfigOptionInt*>(opt)->value = value; break;
540 case coFloat: static_cast<ConfigOptionFloat*>(opt)->value = value; break;
541 case coFloatOrPercent: static_cast<ConfigOptionFloatOrPercent*>(opt)->value = value; static_cast<ConfigOptionFloatOrPercent*>(opt)->percent = false; break;
542 case coString: static_cast<ConfigOptionString*>(opt)->value = std::to_string(value); break;
543 default: throw BadOptionTypeException("Configbase::set() - conversion from int not possible");
544 }
545}
@ coInt
Definition Config.hpp:168

References Slic3r::coFloat, Slic3r::coFloatOrPercent, Slic3r::coInt, Slic3r::coString, opt(), option_throw(), and Slic3r::ConfigOption::type().

+ Here is the call graph for this function:

◆ set_deserialize() [1/2]

void Slic3r::ConfigBase::set_deserialize ( const t_config_option_key opt_key,
const std::string &  str,
ConfigSubstitutionContext config_substitutions,
bool  append = false 
)
572{
573 if (! this->set_deserialize_nothrow(opt_key_src, value_src, substitutions_ctxt, append))
574 throw BadOptionValueException(format("Invalid value provided for parameter %1%: %2%", opt_key_src, value_src));
575}
bool set_deserialize_nothrow(const t_config_option_key &opt_key_src, const std::string &value_src, ConfigSubstitutionContext &substitutions, bool append=false)
Definition Config.cpp:558
void append(std::vector< T, Alloc > &dest, const std::vector< T, Alloc2 > &src)
Definition libslic3r.h:110

References Slic3r::append(), Slic3r::format(), and set_deserialize_nothrow().

Referenced by load(), Slic3r::PresetBundle::load_configbundle(), load_from_gcode_file(), load_from_gcode_string_legacy(), Slic3r::ModelConfig::set_deserialize(), set_deserialize(), set_deserialize_strict(), and set_deserialize_strict().

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

◆ set_deserialize() [2/2]

void Slic3r::ConfigBase::set_deserialize ( std::initializer_list< SetDeserializeItem items,
ConfigSubstitutionContext substitutions 
)
578{
579 for (const SetDeserializeItem &item : items)
580 this->set_deserialize(item.opt_key, item.opt_value, substitutions_ctxt, item.append);
581}

References set_deserialize().

+ Here is the call graph for this function:

◆ set_deserialize_nothrow()

bool Slic3r::ConfigBase::set_deserialize_nothrow ( const t_config_option_key opt_key_src,
const std::string &  value_src,
ConfigSubstitutionContext substitutions,
bool  append = false 
)
559{
560 t_config_option_key opt_key = opt_key_src;
561 std::string value = value_src;
562 // Both opt_key and value may be modified by handle_legacy().
563 // If the opt_key is no more valid in this version of Slic3r, opt_key is cleared by handle_legacy().
564 this->handle_legacy(opt_key, value);
565 if (opt_key.empty())
566 // Ignore the option.
567 return true;
568 return this->set_deserialize_raw(opt_key, value, substitutions_ctxt, append);
569}
virtual void handle_legacy(t_config_option_key &, std::string &) const
Definition Config.hpp:2162
bool set_deserialize_raw(const t_config_option_key &opt_key_src, const std::string &value, ConfigSubstitutionContext &substitutions, bool append)
Definition Config.cpp:583

References Slic3r::append(), handle_legacy(), and set_deserialize_raw().

Referenced by Slic3r::DynamicConfig::read_cli(), and set_deserialize().

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

◆ set_deserialize_raw()

bool Slic3r::ConfigBase::set_deserialize_raw ( const t_config_option_key opt_key_src,
const std::string &  value,
ConfigSubstitutionContext substitutions,
bool  append 
)
private
584{
585 t_config_option_key opt_key = opt_key_src;
586 // Try to deserialize the option by its name.
587 const ConfigDef *def = this->def();
588 if (def == nullptr)
589 throw NoDefinitionException(opt_key);
590 const ConfigOptionDef *optdef = def->get(opt_key);
591 if (optdef == nullptr) {
592 // If we didn't find an option, look for any other option having this as an alias.
593 for (const auto &opt : def->options) {
594 for (const t_config_option_key &opt_key2 : opt.second.aliases) {
595 if (opt_key2 == opt_key) {
596 opt_key = opt.first;
597 optdef = &opt.second;
598 break;
599 }
600 }
601 if (optdef != nullptr)
602 break;
603 }
604 if (optdef == nullptr)
605 throw UnknownOptionException(opt_key);
606 }
607
608 if (! optdef->shortcut.empty()) {
609 // Aliasing for example "solid_layers" to "top_solid_layers" and "bottom_solid_layers".
610 for (const t_config_option_key &shortcut : optdef->shortcut)
611 // Recursive call.
612 if (! this->set_deserialize_raw(shortcut, value, substitutions_ctxt, append))
613 return false;
614 return true;
615 }
616
617 ConfigOption *opt = this->option(opt_key, true);
618 assert(opt != nullptr);
619 bool success = false;
620 bool substituted = false;
621 if (optdef->type == coBools && substitutions_ctxt.rule != ForwardCompatibilitySubstitutionRule::Disable) {
622 //FIXME Special handling of vectors of bools, quick and not so dirty solution before PrusaSlicer 2.3.2 release.
623 bool nullable = opt->nullable();
625 if (optdef->default_value) {
626 // Default value for vectors of booleans used in a "per extruder" context, thus the default contains just a single value.
627 assert(dynamic_cast<const ConfigOptionVector<unsigned char>*>(optdef->default_value.get()));
628 auto &values = static_cast<const ConfigOptionVector<unsigned char>*>(optdef->default_value.get())->values;
629 if (values.size() == 1 && values.front() == 1)
631 }
632 auto result = nullable ?
633 static_cast<ConfigOptionBoolsNullable*>(opt)->deserialize_with_substitutions(value, append, default_value) :
634 static_cast<ConfigOptionBools*>(opt)->deserialize_with_substitutions(value, append, default_value);
637 } else {
638 success = opt->deserialize(value, append);
639 if (! success && substitutions_ctxt.rule != ForwardCompatibilitySubstitutionRule::Disable &&
640 // Only allow substitutions of an enum value by another enum value or a boolean value with an enum value.
641 // That means, we expect enum values being added in the future and possibly booleans being converted to enums.
642 (optdef->type == coEnum || optdef->type == coBool) && ConfigHelpers::looks_like_enum_value(value)) {
643 // Deserialize failed, try to substitute with a default value.
644 assert(substitutions_ctxt.rule == ForwardCompatibilitySubstitutionRule::Enable || substitutions_ctxt.rule == ForwardCompatibilitySubstitutionRule::EnableSilent);
645 if (optdef->type == coBool)
646 static_cast<ConfigOptionBool*>(opt)->value = ConfigHelpers::enum_looks_like_true_value(value);
647 else
648 // Just use the default of the option.
649 opt->set(optdef->default_value.get());
650 success = true;
651 substituted = true;
652 }
653 }
654
655 if (substituted && (substitutions_ctxt.rule == ForwardCompatibilitySubstitutionRule::Enable ||
657 // Log the substitution.
658 ConfigSubstitution config_substitution;
659 config_substitution.opt_def = optdef;
660 config_substitution.old_value = value;
661 config_substitution.new_value = ConfigOptionUniquePtr(opt->clone());
662 substitutions_ctxt.substitutions.emplace_back(std::move(config_substitution));
663 }
664 return success;
665}
if(!(yy_init))
Definition lexer.c:1190
bool looks_like_enum_value(std::string value)
Definition Config.hpp:87
DeserializationSubstitution
Definition Config.hpp:103
bool enum_looks_like_true_value(std::string value)
Definition Config.hpp:98
@ EnableSystemSilent
Definition Config.hpp:225
@ EnableSilent
Definition Config.hpp:223
@ Enable
Definition Config.hpp:221
ConfigOptionBool
Definition PrintConfig.hpp:665
ConfigOptionBoolsTempl< true > ConfigOptionBoolsNullable
Definition Config.hpp:1492
ConfigOptionBoolsTempl< false > ConfigOptionBools
Definition Config.hpp:1491
std::unique_ptr< ConfigOption, ConfigOptionDeleter > ConfigOptionUniquePtr
Definition Config.hpp:235
@ coBools
Definition Config.hpp:192
@ coEnum
Definition Config.hpp:194
@ coBool
Definition Config.hpp:190

References Slic3r::append(), Slic3r::ConfigOption::clone(), Slic3r::coBool, Slic3r::coBools, Slic3r::coEnum, def(), Slic3r::ConfigOptionDef::default_value, Slic3r::ConfigHelpers::DefaultsToFalse, Slic3r::ConfigHelpers::DefaultsToTrue, Slic3r::ConfigOption::deserialize(), Slic3r::Disable, Slic3r::Enable, Slic3r::EnableSilent, Slic3r::EnableSystemSilent, Slic3r::ConfigHelpers::enum_looks_like_true_value(), Slic3r::ConfigHelpers::Failed, Slic3r::ConfigDef::get(), Slic3r::ConfigHelpers::looks_like_enum_value(), Slic3r::ConfigSubstitution::new_value, Slic3r::ConfigOption::nullable(), Slic3r::ConfigSubstitution::old_value, opt(), Slic3r::ConfigSubstitution::opt_def, Slic3r::ConfigDef::options, Slic3r::ConfigSubstitutionContext::rule, Slic3r::ConfigOption::set(), set_deserialize_raw(), Slic3r::ConfigOptionDef::shortcut, Slic3r::ConfigHelpers::Substituted, Slic3r::ConfigSubstitutionContext::substitutions, and Slic3r::ConfigOptionDef::type.

Referenced by set_deserialize_nothrow(), and set_deserialize_raw().

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

◆ set_deserialize_strict() [1/2]

void Slic3r::ConfigBase::set_deserialize_strict ( const t_config_option_key opt_key,
const std::string &  str,
bool  append = false 
)
inline
2241 { ConfigSubstitutionContext ctxt{ ForwardCompatibilitySubstitutionRule::Disable }; this->set_deserialize(opt_key, str, ctxt, append); }

References Slic3r::append(), Slic3r::Disable, and set_deserialize().

Referenced by Slic3r::DynamicPrintConfig::new_with(), Slic3r::DynamicPrintConfig::new_with(), and Slic3r::ModelConfig::set_deserialize_strict().

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

◆ set_deserialize_strict() [2/2]

void Slic3r::ConfigBase::set_deserialize_strict ( std::initializer_list< SetDeserializeItem items)
inline
2271 { ConfigSubstitutionContext ctxt{ ForwardCompatibilitySubstitutionRule::Disable }; this->set_deserialize(items, ctxt); }

References Slic3r::Disable, and set_deserialize().

+ Here is the call graph for this function:

◆ setenv_()

void Slic3r::ConfigBase::setenv_ ( ) const
706{
707 t_config_option_keys opt_keys = this->keys();
708 for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it) {
709 // prepend the SLIC3R_ prefix
710 std::ostringstream ss;
711 ss << "SLIC3R_";
712 ss << *it;
713 std::string envname = ss.str();
714
715 // capitalize environment variable name
716 for (size_t i = 0; i < envname.size(); ++i)
717 envname[i] = (envname[i] <= 'z' && envname[i] >= 'a') ? envname[i]-('a'-'A') : envname[i];
718
719 boost::nowide::setenv(envname.c_str(), this->opt_serialize(*it).c_str(), 1);
720 }
721}

References keys().

Referenced by Slic3r::run_post_process_scripts().

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

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