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

#include <src/libslic3r/PlaceholderParser.hpp>

+ Collaboration diagram for Slic3r::PlaceholderParser:

Classes

struct  ContextData
 

Public Member Functions

 PlaceholderParser (const DynamicConfig *external_config=nullptr)
 
void clear_config ()
 
std::vector< std::string > config_diff (const DynamicPrintConfig &rhs)
 
bool apply_config (const DynamicPrintConfig &config)
 
void apply_config (DynamicPrintConfig &&config)
 
void apply_only (const DynamicPrintConfig &config, const std::vector< std::string > &keys)
 
void apply_env_variables ()
 
void set (const std::string &key, const std::string &value)
 
void set (const std::string &key, std::string_view value)
 
void set (const std::string &key, const char *value)
 
void set (const std::string &key, int value)
 
void set (const std::string &key, unsigned int value)
 
void set (const std::string &key, bool value)
 
void set (const std::string &key, double value)
 
void set (const std::string &key, const std::vector< std::string > &values)
 
void set (const std::string &key, ConfigOption *opt)
 
DynamicConfigconfig_writable ()
 
const DynamicConfigconfig () const
 
const ConfigOptionoption (const std::string &key) const
 
const DynamicConfigexternal_config () const
 
std::string process (const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override, DynamicConfig *config_outputs, ContextData *context) const
 
std::string process (const std::string &templ, unsigned int current_extruder_id=0, const DynamicConfig *config_override=nullptr, ContextData *context=nullptr) const
 
void update_timestamp ()
 

Static Public Member Functions

static bool evaluate_boolean_expression (const std::string &templ, const DynamicConfig &config, const DynamicConfig *config_override=nullptr)
 
static void update_timestamp (DynamicConfig &config)
 

Private Attributes

DynamicConfig m_config
 
const DynamicConfigm_external_config
 

Detailed Description


Class Documentation

◆ Slic3r::PlaceholderParser::ContextData

struct Slic3r::PlaceholderParser::ContextData
+ Collaboration diagram for Slic3r::PlaceholderParser::ContextData:
Class Members
unique_ptr< DynamicConfig > global_config
mt19937 rng

Constructor & Destructor Documentation

◆ PlaceholderParser()

Slic3r::PlaceholderParser::PlaceholderParser ( const DynamicConfig external_config = nullptr)
70{
71 this->set("version", std::string(SLIC3R_VERSION));
72 this->apply_env_variables();
73 this->update_timestamp();
74}
const DynamicConfig * external_config() const
Definition PlaceholderParser.hpp:57
void set(const std::string &key, const std::string &value)
Definition PlaceholderParser.hpp:44
const DynamicConfig * m_external_config
Definition PlaceholderParser.hpp:77
void apply_env_variables()
Definition PlaceholderParser.cpp:147
void update_timestamp()
Definition PlaceholderParser.hpp:72

References apply_env_variables(), set(), and update_timestamp().

+ Here is the call graph for this function:

Member Function Documentation

◆ apply_config() [1/2]

bool Slic3r::PlaceholderParser::apply_config ( const DynamicPrintConfig config)
125{
126 bool modified = false;
127 for (const t_config_option_key &opt_key : rhs.keys()) {
128 if (! opts_equal(m_config, rhs, opt_key)) {
129 this->set(opt_key, rhs.option(opt_key)->clone());
130 modified = true;
131 }
132 }
133 return modified;
134}
DynamicConfig m_config
Definition PlaceholderParser.hpp:76
static bool opts_equal(const DynamicConfig &config_old, const DynamicConfig &config_new, const std::string &opt_key)
Definition PlaceholderParser.cpp:101
std::string t_config_option_key
Definition Config.hpp:76

References Slic3r::ConfigOption::clone(), Slic3r::DynamicConfig::keys(), m_config, Slic3r::ConfigBase::option(), Slic3r::opts_equal(), and set().

Referenced by Slic3r::SLAPrint::apply().

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

◆ apply_config() [2/2]

void Slic3r::PlaceholderParser::apply_config ( DynamicPrintConfig &&  config)
143{
144 m_config += std::move(rhs);
145}

References m_config.

◆ apply_env_variables()

void Slic3r::PlaceholderParser::apply_env_variables ( )
148{
149 for (char** env = environ; *env; ++ env) {
150 if (strncmp(*env, "SLIC3R_", 7) == 0) {
151 std::stringstream ss(*env);
152 std::string key, value;
153 std::getline(ss, key, '=');
154 ss >> value;
155 this->set(key, value);
156 }
157 }
158}
char ** environ

References environ, and set().

Referenced by PlaceholderParser().

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

◆ apply_only()

void Slic3r::PlaceholderParser::apply_only ( const DynamicPrintConfig config,
const std::vector< std::string > &  keys 
)
137{
138 for (const t_config_option_key &opt_key : keys)
139 this->set(opt_key, rhs.option(opt_key)->clone());
140}
Definition getopt.h:102
VoxelGridPtr clone(const VoxelGrid &grid)
Definition OpenVDBUtils.cpp:285

References Slic3r::ConfigOption::clone(), Slic3r::ConfigBase::option(), and set().

+ Here is the call graph for this function:

◆ clear_config()

void Slic3r::PlaceholderParser::clear_config ( )
inline
31{ m_config.clear(); }
void clear()
Definition Config.hpp:2400

References Slic3r::DynamicConfig::clear(), and m_config.

+ Here is the call graph for this function:

◆ config()

const DynamicConfig & Slic3r::PlaceholderParser::config ( ) const
inline
54{ return m_config; }

References m_config.

Referenced by evaluate_boolean_expression(), process(), and update_timestamp().

+ Here is the caller graph for this function:

◆ config_diff()

std::vector< std::string > Slic3r::PlaceholderParser::config_diff ( const DynamicPrintConfig rhs)
110{
111 std::vector<std::string> diff_keys;
112 for (const t_config_option_key &opt_key : rhs.keys())
113 if (! opts_equal(m_config, rhs, opt_key))
114 diff_keys.emplace_back(opt_key);
115 return diff_keys;
116}
if(!(yy_init))
Definition lexer.c:1190

References Slic3r::DynamicConfig::keys(), m_config, and Slic3r::opts_equal().

Referenced by Slic3r::SLAPrint::apply().

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

◆ config_writable()

DynamicConfig & Slic3r::PlaceholderParser::config_writable ( )
inline
53{ return m_config; }

References m_config.

Referenced by Slic3r::GCode::_do_export().

+ Here is the caller graph for this function:

◆ evaluate_boolean_expression()

bool Slic3r::PlaceholderParser::evaluate_boolean_expression ( const std::string &  templ,
const DynamicConfig config,
const DynamicConfig config_override = nullptr 
)
static
2359{
2360 client::MyContext context;
2361 context.config = &config;
2362 context.config_override = config_override;
2363 // Let the macro processor parse just a boolean expression, not the full macro language.
2364 context.just_boolean_expression = true;
2365 return process_macro(templ, context) == "true";
2366}
const DynamicConfig & config() const
Definition PlaceholderParser.hpp:54
static std::string process_macro(const std::string &templ, client::MyContext &context)
Definition PlaceholderParser.cpp:2332

References Slic3r::client::MyContext::config, config(), Slic3r::client::MyContext::config_override, Slic3r::client::MyContext::just_boolean_expression, and Slic3r::process_macro().

Referenced by Slic3r::is_compatible_with_print(), and Slic3r::is_compatible_with_printer().

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

◆ external_config()

const DynamicConfig * Slic3r::PlaceholderParser::external_config ( ) const
inline
57{ return m_external_config; }

References m_external_config.

Referenced by process().

+ Here is the caller graph for this function:

◆ option()

const ConfigOption * Slic3r::PlaceholderParser::option ( const std::string &  key) const
inline
55{ return m_config.option(key); }
ConfigOption * option(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2169

References m_config, and Slic3r::ConfigBase::option().

+ Here is the call graph for this function:

◆ process() [1/2]

std::string Slic3r::PlaceholderParser::process ( const std::string &  templ,
unsigned int  current_extruder_id,
const DynamicConfig config_override,
DynamicConfig config_outputs,
ContextData context 
) const
2345{
2346 client::MyContext context;
2347 context.external_config = this->external_config();
2348 context.config = &this->config();
2349 context.config_override = config_override;
2350 context.config_outputs = config_outputs;
2351 context.current_extruder_id = current_extruder_id;
2352 context.context_data = context_data;
2353 return process_macro(templ, context);
2354}

References Slic3r::client::MyContext::config, config(), Slic3r::client::MyContext::config_outputs, Slic3r::client::MyContext::config_override, Slic3r::client::MyContext::context_data, Slic3r::client::MyContext::current_extruder_id, Slic3r::client::MyContext::external_config, external_config(), and Slic3r::process_macro().

Referenced by Slic3r::PrintStatistics::finalize_output_path(), Slic3r::SLAPrintStatistics::finalize_output_path(), Slic3r::PrintBase::output_filename(), Slic3r::GCode::placeholder_parser_process(), and process().

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

◆ process() [2/2]

std::string Slic3r::PlaceholderParser::process ( const std::string &  templ,
unsigned int  current_extruder_id = 0,
const DynamicConfig config_override = nullptr,
ContextData context = nullptr 
) const
inline
63 { return this->process(templ, current_extruder_id, config_override, nullptr /* config_outputs */, context); }
std::string process(const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override, DynamicConfig *config_outputs, ContextData *context) const
Definition PlaceholderParser.cpp:2344

References process().

+ Here is the call graph for this function:

◆ set() [1/9]

void Slic3r::PlaceholderParser::set ( const std::string &  key,
bool  value 
)
inline
49{ this->set(key, new ConfigOptionBool(value)); }
ConfigOptionBool
Definition PrintConfig.hpp:665

References set().

Referenced by set().

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

◆ set() [2/9]

void Slic3r::PlaceholderParser::set ( const std::string &  key,
ConfigOption opt 
)
inline
52{ m_config.set_key_value(key, opt); }
bool set_key_value(const std::string &opt_key, ConfigOption *opt)
Definition Config.hpp:2431

References m_config, and Slic3r::DynamicConfig::set_key_value().

+ Here is the call graph for this function:

◆ set() [3/9]

void Slic3r::PlaceholderParser::set ( const std::string &  key,
const char *  value 
)
inline
46{ this->set(key, new ConfigOptionString(value)); }

References set().

Referenced by set().

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

◆ set() [4/9]

void Slic3r::PlaceholderParser::set ( const std::string &  key,
const std::string &  value 
)
inline
44{ this->set(key, new ConfigOptionString(value)); }

References set().

Referenced by PlaceholderParser(), Slic3r::GCode::_do_export(), Slic3r::SLAPrint::apply(), apply_config(), apply_env_variables(), apply_only(), set(), and Slic3r::GCode::set_extruder().

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

◆ set() [5/9]

void Slic3r::PlaceholderParser::set ( const std::string &  key,
const std::vector< std::string > &  values 
)
inline
51{ this->set(key, new ConfigOptionStrings(values)); }

References set().

Referenced by set().

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

◆ set() [6/9]

void Slic3r::PlaceholderParser::set ( const std::string &  key,
double  value 
)
inline
50{ this->set(key, new ConfigOptionFloat(value)); }
ConfigOptionFloat
Definition PrintConfig.hpp:570

References set().

Referenced by set().

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

◆ set() [7/9]

void Slic3r::PlaceholderParser::set ( const std::string &  key,
int  value 
)
inline
47{ this->set(key, new ConfigOptionInt(value)); }

References set().

Referenced by set().

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

◆ set() [8/9]

void Slic3r::PlaceholderParser::set ( const std::string &  key,
std::string_view  value 
)
inline
45{ this->set(key, new ConfigOptionString(std::string(value))); }

References set().

Referenced by set().

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

◆ set() [9/9]

void Slic3r::PlaceholderParser::set ( const std::string &  key,
unsigned int  value 
)
inline
48{ this->set(key, int(value)); }

References set().

Referenced by set().

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

◆ update_timestamp() [1/2]

void Slic3r::PlaceholderParser::update_timestamp ( )
inline

References m_config, and update_timestamp().

Referenced by PlaceholderParser(), Slic3r::PrintBase::output_filename(), and update_timestamp().

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

◆ update_timestamp() [2/2]

void Slic3r::PlaceholderParser::update_timestamp ( DynamicConfig config)
static
77{
78 time_t rawtime;
79 time(&rawtime);
80 struct tm* timeinfo = localtime(&rawtime);
81
82 {
83 std::ostringstream ss;
84 ss << (1900 + timeinfo->tm_year);
85 ss << std::setw(2) << std::setfill('0') << (1 + timeinfo->tm_mon);
86 ss << std::setw(2) << std::setfill('0') << timeinfo->tm_mday;
87 ss << "-";
88 ss << std::setw(2) << std::setfill('0') << timeinfo->tm_hour;
89 ss << std::setw(2) << std::setfill('0') << timeinfo->tm_min;
90 ss << std::setw(2) << std::setfill('0') << timeinfo->tm_sec;
91 config.set_key_value("timestamp", new ConfigOptionString(ss.str()));
92 }
93 config.set_key_value("year", new ConfigOptionInt(1900 + timeinfo->tm_year));
94 config.set_key_value("month", new ConfigOptionInt(1 + timeinfo->tm_mon));
95 config.set_key_value("day", new ConfigOptionInt(timeinfo->tm_mday));
96 config.set_key_value("hour", new ConfigOptionInt(timeinfo->tm_hour));
97 config.set_key_value("minute", new ConfigOptionInt(timeinfo->tm_min));
98 config.set_key_value("second", new ConfigOptionInt(timeinfo->tm_sec));
99}

References config(), and Slic3r::DynamicConfig::set_key_value().

Referenced by Slic3r::GCode::_do_export().

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

Member Data Documentation

◆ m_config

◆ m_external_config

const DynamicConfig* Slic3r::PlaceholderParser::m_external_config
private

Referenced by external_config().


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