OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::PlaceholderParser Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/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)
void set_deferred (const std::string &key, const std::string &tag)
DynamicConfig & config_writable ()
const DynamicConfig & config () const
const ConfigOption * option (const std::string &key) const
const DynamicConfig * external_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 ()
void update_user_name ()

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)
static void update_user_name (DynamicConfig &config)

Static Public Attributes

static bool check_inactive_branches = false

Private Attributes

DynamicConfig m_config
const DynamicConfig * m_external_config
std::set< std::string > m_deferred_tags

Detailed Description


Class Documentation

◆ Slic3r::PlaceholderParser::ContextData

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

Constructor & Destructor Documentation

◆ PlaceholderParser()

Slic3r::PlaceholderParser::PlaceholderParser ( const DynamicConfig * external_config = nullptr)
113{
114 this->set("version", std::string(SoftFever_VERSION));
115 this->apply_env_variables();
116 this->update_timestamp();
117 this->update_user_name();
118}
const DynamicConfig * external_config() const
Definition PlaceholderParser.hpp:70
void set(const std::string &key, const std::string &value)
Definition PlaceholderParser.hpp:54
void update_user_name()
Definition PlaceholderParser.hpp:88
const DynamicConfig * m_external_config
Definition PlaceholderParser.hpp:93
void apply_env_variables()
Definition PlaceholderParser.cpp:197
void update_timestamp()
Definition PlaceholderParser.hpp:85

References apply_env_variables(), external_config(), m_external_config, set(), update_timestamp(), and update_user_name().

Here is the call graph for this function:

Member Function Documentation

◆ apply_config() [1/2]

bool Slic3r::PlaceholderParser::apply_config ( const DynamicPrintConfig & config)
175{
176 bool modified = false;
177 for (const t_config_option_key &opt_key : rhs.keys()) {
178 if (! opts_equal(m_config, rhs, opt_key)) {
179 this->set(opt_key, rhs.option(opt_key)->clone());
180 modified = true;
181 }
182 }
183 return modified;
184}
DynamicConfig m_config
Definition PlaceholderParser.hpp:92
static bool opts_equal(const DynamicConfig &config_old, const DynamicConfig &config_new, const std::string &opt_key)
Definition PlaceholderParser.cpp:151
std::string t_config_option_key
Definition Config.hpp:96

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

Here is the call graph for this function:

◆ apply_config() [2/2]

void Slic3r::PlaceholderParser::apply_config ( DynamicPrintConfig && config)
193{
194 m_config += std::move(rhs);
195}

References m_config.

◆ apply_env_variables()

void Slic3r::PlaceholderParser::apply_env_variables ( )
198{
199 for (char** env = environ; *env; ++ env) {
200 if (strncmp(*env, "SLIC3R_", 7) == 0) {
201 std::stringstream ss(*env);
202 std::string key, value;
203 std::getline(ss, key, '=');
204 ss >> value;
205 this->set(key, value);
206 }
207 }
208}
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 )
187{
188 for (const t_config_option_key &opt_key : keys)
189 this->set(opt_key, rhs.option(opt_key)->clone());
190}

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
41{ m_config.clear(); }

References m_config.

◆ config()

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

References m_config.

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

Here is the caller graph for this function:

◆ config_diff()

std::vector< std::string > Slic3r::PlaceholderParser::config_diff ( const DynamicPrintConfig & rhs)
160{
161 std::vector<std::string> diff_keys;
162 for (const t_config_option_key &opt_key : rhs.keys())
163 if (! opts_equal(m_config, rhs, opt_key))
164 diff_keys.emplace_back(opt_key);
165 return diff_keys;
166}

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

Here is the call graph for this function:

◆ config_writable()

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

References m_config.

◆ evaluate_boolean_expression()

bool Slic3r::PlaceholderParser::evaluate_boolean_expression ( const std::string & templ,
const DynamicConfig & config,
const DynamicConfig * config_override = nullptr )
static
2698{
2699 client::MyContext context;
2700 context.config = &config;
2701 context.config_override = config_override;
2702 // Let the macro processor parse just a boolean expression, not the full macro language.
2703 context.just_boolean_expression = true;
2704 return process_macro(templ, context) == "true";
2705}
const DynamicConfig & config() const
Definition PlaceholderParser.hpp:67
static std::string process_macro(const std::string &templ, client::MyContext &context)
Definition PlaceholderParser.cpp:2670

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
70{ return m_external_config; }

References m_external_config.

Referenced by PlaceholderParser(), and process().

Here is the caller graph for this function:

◆ option()

const ConfigOption * Slic3r::PlaceholderParser::option ( const std::string & key) const
inline
68{ return m_config.option(key); }

References m_config.

◆ 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
2683{
2684 client::MyContext context;
2685 context.external_config = this->external_config();
2686 context.config = &this->config();
2687 context.config_override = config_override;
2688 context.config_outputs = config_outputs;
2689 context.deferred_tags = &m_deferred_tags;
2690 context.current_extruder_id = current_extruder_id;
2691 context.context_data = context_data;
2692 return process_macro(templ, context);
2693}
std::set< std::string > m_deferred_tags
Definition PlaceholderParser.hpp:94

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::deferred_tags, Slic3r::client::MyContext::external_config, external_config(), m_deferred_tags, 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
76 { 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:2682

References process().

Here is the call graph for this function:

◆ set() [1/9]

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

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
62{ m_config.set_key_value(key, opt); }

References m_config.

◆ set() [3/9]

void Slic3r::PlaceholderParser::set ( const std::string & key,
const char * value )
inline
56{ this->set(key, new ConfigOptionString(value)); }
zaa_minimize_perimeter_height ConfigOptionString
Definition PrintConfig.hpp:1702

References Slic3r::ConfigOptionString, and 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
54{ this->set(key, new ConfigOptionString(value)); }

References Slic3r::ConfigOptionString, and set().

Referenced by PlaceholderParser(), Slic3r::GCode::_do_export(), Slic3r::WipeTowerIntegration::append_tcr(), apply_config(), apply_env_variables(), apply_only(), set(), set_deferred(), Slic3r::GCode::set_extruder(), and Slic3r::GCode::update_placeholder_parser_with_variant_params().

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
61{ 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
60{ this->set(key, new ConfigOptionFloat(value)); }
zaa_minimize_perimeter_height ConfigOptionFloat
Definition PrintConfig.hpp:1954

References Slic3r::ConfigOptionFloat, and 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
57{ 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
55{ this->set(key, new ConfigOptionString(std::string(value))); }

References Slic3r::ConfigOptionString, and 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
58{ 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:

◆ set_deferred()

void Slic3r::PlaceholderParser::set_deferred ( const std::string & key,
const std::string & tag )
inline
65{ this->set(key, tag); m_deferred_tags.insert(tag); }

References m_deferred_tags, and set().

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

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
121{
122 time_t rawtime;
123 time(&rawtime);
124 struct tm* timeinfo = localtime(&rawtime);
125
126 {
127 std::ostringstream ss;
128 ss << (1900 + timeinfo->tm_year);
129 ss << std::setw(2) << std::setfill('0') << (1 + timeinfo->tm_mon);
130 ss << std::setw(2) << std::setfill('0') << timeinfo->tm_mday;
131 ss << "-";
132 ss << std::setw(2) << std::setfill('0') << timeinfo->tm_hour;
133 ss << std::setw(2) << std::setfill('0') << timeinfo->tm_min;
134 ss << std::setw(2) << std::setfill('0') << timeinfo->tm_sec;
135 config.set_key_value("timestamp", new ConfigOptionString(ss.str()));
136 }
137 config.set_key_value("year", new ConfigOptionInt(1900 + timeinfo->tm_year));
138 config.set_key_value("month", new ConfigOptionInt(1 + timeinfo->tm_mon));
139 config.set_key_value("day", new ConfigOptionInt(timeinfo->tm_mday));
140 config.set_key_value("hour", new ConfigOptionInt(timeinfo->tm_hour));
141 config.set_key_value("minute", new ConfigOptionInt(timeinfo->tm_min));
142 config.set_key_value("second", new ConfigOptionInt(timeinfo->tm_sec));
143}

References config(), and Slic3r::ConfigOptionString.

Here is the call graph for this function:

◆ update_user_name() [1/2]

void Slic3r::PlaceholderParser::update_user_name ( )
inline

References m_config, and update_user_name().

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

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

◆ update_user_name() [2/2]

void Slic3r::PlaceholderParser::update_user_name ( DynamicConfig & config)
static
146{
147 const char* user = boost::nowide::getenv("USER") ? boost::nowide::getenv("USER") : boost::nowide::getenv("USERNAME") ? boost::nowide::getenv("USERNAME") : "unknown";
148 config.set_key_value("user", new ConfigOptionString(user));
149}

References config(), and Slic3r::ConfigOptionString.

Here is the call graph for this function:

Member Data Documentation

◆ check_inactive_branches

bool Slic3r::PlaceholderParser::check_inactive_branches = false
inlinestatic

◆ m_config

◆ m_deferred_tags

std::set<std::string> Slic3r::PlaceholderParser::m_deferred_tags
private

Referenced by process(), and set_deferred().

◆ m_external_config

const DynamicConfig* Slic3r::PlaceholderParser::m_external_config
private

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