mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-21 04:13:50 +00:00
add user name placeholder (#10109)
* Add user name placeholder * non-ASCII character support * fix: Explicitly include <boost/nowide/cstdlib.hpp>
This commit is contained in:
@@ -2041,6 +2041,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
|
|||||||
// Prepare the helper object for replacing placeholders in custom G-code and output filename.
|
// Prepare the helper object for replacing placeholders in custom G-code and output filename.
|
||||||
m_placeholder_parser_integration.parser = print.placeholder_parser();
|
m_placeholder_parser_integration.parser = print.placeholder_parser();
|
||||||
m_placeholder_parser_integration.parser.update_timestamp();
|
m_placeholder_parser_integration.parser.update_timestamp();
|
||||||
|
m_placeholder_parser_integration.parser.update_user_name();
|
||||||
m_placeholder_parser_integration.context.rng = std::mt19937(std::chrono::high_resolution_clock::now().time_since_epoch().count());
|
m_placeholder_parser_integration.context.rng = std::mt19937(std::chrono::high_resolution_clock::now().time_since_epoch().count());
|
||||||
// Enable passing global variables between PlaceholderParser invocations.
|
// Enable passing global variables between PlaceholderParser invocations.
|
||||||
m_placeholder_parser_integration.context.global_config = std::make_unique<DynamicConfig>();
|
m_placeholder_parser_integration.context.global_config = std::make_unique<DynamicConfig>();
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <boost/nowide/convert.hpp>
|
#include <boost/nowide/convert.hpp>
|
||||||
|
#include <boost/nowide/cstdlib.hpp>
|
||||||
|
|
||||||
// Spirit v2.5 allows you to suppress automatic generation
|
// Spirit v2.5 allows you to suppress automatic generation
|
||||||
// of predefined terminals to speed up complation. With
|
// of predefined terminals to speed up complation. With
|
||||||
@@ -71,6 +72,7 @@ PlaceholderParser::PlaceholderParser(const DynamicConfig *external_config) : m_e
|
|||||||
this->set("version", std::string(SoftFever_VERSION));
|
this->set("version", std::string(SoftFever_VERSION));
|
||||||
this->apply_env_variables();
|
this->apply_env_variables();
|
||||||
this->update_timestamp();
|
this->update_timestamp();
|
||||||
|
this->update_user_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlaceholderParser::update_timestamp(DynamicConfig &config)
|
void PlaceholderParser::update_timestamp(DynamicConfig &config)
|
||||||
@@ -98,6 +100,12 @@ void PlaceholderParser::update_timestamp(DynamicConfig &config)
|
|||||||
config.set_key_value("second", new ConfigOptionInt(timeinfo->tm_sec));
|
config.set_key_value("second", new ConfigOptionInt(timeinfo->tm_sec));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlaceholderParser::update_user_name(DynamicConfig &config)
|
||||||
|
{
|
||||||
|
const char* user = boost::nowide::getenv("USER") ? boost::nowide::getenv("USER") : boost::nowide::getenv("USERNAME") ? boost::nowide::getenv("USERNAME") : "unknown";
|
||||||
|
config.set_key_value("user", new ConfigOptionString(user));
|
||||||
|
}
|
||||||
|
|
||||||
static inline bool opts_equal(const DynamicConfig &config_old, const DynamicConfig &config_new, const std::string &opt_key)
|
static inline bool opts_equal(const DynamicConfig &config_old, const DynamicConfig &config_new, const std::string &opt_key)
|
||||||
{
|
{
|
||||||
const ConfigOption *opt_old = config_old.option(opt_key);
|
const ConfigOption *opt_old = config_old.option(opt_key);
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ public:
|
|||||||
// Update timestamp, year, month, day, hour, minute, second variables at m_config.
|
// Update timestamp, year, month, day, hour, minute, second variables at m_config.
|
||||||
void update_timestamp() { update_timestamp(m_config); }
|
void update_timestamp() { update_timestamp(m_config); }
|
||||||
|
|
||||||
|
static void update_user_name(DynamicConfig &config);
|
||||||
|
void update_user_name() { update_user_name(m_config); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// config has a higher priority than external_config when looking up a symbol.
|
// config has a higher priority than external_config when looking up a symbol.
|
||||||
DynamicConfig m_config;
|
DynamicConfig m_config;
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ std::string PrintBase::output_filename(const std::string &format, const std::str
|
|||||||
cfg = *config_override;
|
cfg = *config_override;
|
||||||
cfg.set_key_value("version", new ConfigOptionString(std::string(SoftFever_VERSION)));
|
cfg.set_key_value("version", new ConfigOptionString(std::string(SoftFever_VERSION)));
|
||||||
PlaceholderParser::update_timestamp(cfg);
|
PlaceholderParser::update_timestamp(cfg);
|
||||||
|
PlaceholderParser::update_user_name(cfg);
|
||||||
this->update_object_placeholders(cfg, default_ext);
|
this->update_object_placeholders(cfg, default_ext);
|
||||||
if (! filename_base.empty()) {
|
if (! filename_base.empty()) {
|
||||||
cfg.set_key_value("input_filename", new ConfigOptionString(filename_base + default_ext));
|
cfg.set_key_value("input_filename", new ConfigOptionString(filename_base + default_ext));
|
||||||
|
|||||||
Reference in New Issue
Block a user