2014-05-06 08:07:18 +00:00
|
|
|
#ifndef slic3r_PlaceholderParser_hpp_
|
|
|
|
#define slic3r_PlaceholderParser_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2014-05-06 08:07:18 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2015-05-02 19:43:22 +00:00
|
|
|
#include <vector>
|
2014-06-13 13:32:11 +00:00
|
|
|
#include "PrintConfig.hpp"
|
2014-05-06 08:07:18 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
class PlaceholderParser
|
|
|
|
{
|
2017-11-17 10:15:46 +00:00
|
|
|
public:
|
2019-07-24 10:39:01 +00:00
|
|
|
PlaceholderParser(const DynamicConfig *external_config = nullptr);
|
2017-11-17 10:15:46 +00:00
|
|
|
|
2018-12-03 12:14:28 +00:00
|
|
|
// Return a list of keys, which should be changed in m_config from rhs.
|
|
|
|
// This contains keys, which are found in rhs, but not in m_config.
|
|
|
|
std::vector<std::string> config_diff(const DynamicPrintConfig &rhs);
|
2018-10-23 20:53:43 +00:00
|
|
|
// Return true if modified.
|
|
|
|
bool apply_config(const DynamicPrintConfig &config);
|
2019-07-25 12:39:19 +00:00
|
|
|
void apply_config(DynamicPrintConfig &&config);
|
2018-12-03 12:14:28 +00:00
|
|
|
// To be called on the values returned by PlaceholderParser::config_diff().
|
|
|
|
// The keys should already be valid.
|
|
|
|
void apply_only(const DynamicPrintConfig &config, const std::vector<std::string> &keys);
|
2015-07-01 15:56:38 +00:00
|
|
|
void apply_env_variables();
|
2017-11-17 10:15:46 +00:00
|
|
|
|
|
|
|
// Add new ConfigOption values to m_config.
|
|
|
|
void set(const std::string &key, const std::string &value) { this->set(key, new ConfigOptionString(value)); }
|
|
|
|
void set(const std::string &key, int value) { this->set(key, new ConfigOptionInt(value)); }
|
|
|
|
void set(const std::string &key, unsigned int value) { this->set(key, int(value)); }
|
2017-12-04 10:57:54 +00:00
|
|
|
void set(const std::string &key, bool value) { this->set(key, new ConfigOptionBool(value)); }
|
2017-11-17 10:15:46 +00:00
|
|
|
void set(const std::string &key, double value) { this->set(key, new ConfigOptionFloat(value)); }
|
|
|
|
void set(const std::string &key, const std::vector<std::string> &values) { this->set(key, new ConfigOptionStrings(values)); }
|
|
|
|
void set(const std::string &key, ConfigOption *opt) { m_config.set_key_value(key, opt); }
|
2019-02-03 09:41:14 +00:00
|
|
|
DynamicConfig& config_writable() { return m_config; }
|
|
|
|
const DynamicConfig& config() const { return m_config; }
|
2017-12-18 11:14:09 +00:00
|
|
|
const ConfigOption* option(const std::string &key) const { return m_config.option(key); }
|
2019-07-24 10:39:01 +00:00
|
|
|
// External config is not owned by PlaceholderParser. It has a lowest priority when looking up an option.
|
|
|
|
const DynamicConfig* external_config() const { return m_external_config; }
|
2017-11-17 10:15:46 +00:00
|
|
|
|
2017-12-18 11:14:09 +00:00
|
|
|
// Fill in the template using a macro processing language.
|
2020-12-03 10:03:03 +00:00
|
|
|
// Throws Slic3r::PlaceholderParserError on syntax or runtime error.
|
2020-01-21 11:10:02 +00:00
|
|
|
std::string process(const std::string &templ, unsigned int current_extruder_id = 0, const DynamicConfig *config_override = nullptr) const;
|
2015-07-01 17:35:22 +00:00
|
|
|
|
2017-12-18 11:14:09 +00:00
|
|
|
// Evaluate a boolean expression using the full expressive power of the PlaceholderParser boolean expression syntax.
|
2020-12-03 10:03:03 +00:00
|
|
|
// Throws Slic3r::PlaceholderParserError on syntax or runtime error.
|
2017-12-19 15:48:14 +00:00
|
|
|
static bool evaluate_boolean_expression(const std::string &templ, const DynamicConfig &config, const DynamicConfig *config_override = nullptr);
|
2017-12-18 11:14:09 +00:00
|
|
|
|
2018-09-11 12:04:47 +00:00
|
|
|
// Update timestamp, year, month, day, hour, minute, second variables at the provided config.
|
|
|
|
static void update_timestamp(DynamicConfig &config);
|
|
|
|
// Update timestamp, year, month, day, hour, minute, second variables at m_config.
|
|
|
|
void update_timestamp() { update_timestamp(m_config); }
|
|
|
|
|
2017-05-03 16:28:22 +00:00
|
|
|
private:
|
2019-07-24 10:39:01 +00:00
|
|
|
// config has a higher priority than external_config when looking up a symbol.
|
|
|
|
DynamicConfig m_config;
|
|
|
|
const DynamicConfig *m_external_config;
|
2014-05-06 08:07:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|