mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-07 15:51:08 +00:00
* Add Missing Includes Across src/libslic3r Every libslic3r source and header now directly includes the headers declaring what it uses, rather than relying on the precompiled header or transitive includes. Generated with clang-tidy misc-include-cleaner, with libslic3r headers spelled libslic3r/... so they resolve outside the library's private include paths. MultiMaterialSegmentation.hpp, Support/SupportParameters.hpp and Format/STEP.hpp are made self-contained by hand. * Make the libslic3r Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Left out: I18N.hpp, which errors on purpose when included from GUI code, and VoxelizeCSGMesh.hpp and SLA/bicubic.h, which nothing includes and which no longer compile at all. * Add the Includes Missing From the Hand-Fixed libslic3r Headers clang-tidy would not edit these headers while they failed to compile on their own, so the first pass skipped them. With the headers now self-contained, a second pass adds the rest. * Keep Windows Setup Ahead of the Added libslic3r Includes Print.cpp and Thread.cpp open with a _WIN32 block that has to come first; without the precompiled header, Print.cpp otherwise reaches windows.h through OCCT with NONLS defined and boost/regex fails. OpenVDBUtils.cpp and SLA/SupportTreeBuilder.cpp had includes inside #ifndef NOMINMAX, which libslic3r defines on Windows, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory. * Re-Add libslic3r Includes After the Clipper2 2.0.1 Migration Rebasing onto main took main's version of the files the Clipper2 migration rewrote, so their added includes are restored here, along with includes for main's new code. Clipper2's individual headers are now ignored by clang-tidy: they only build the Z variant through clipper2_z.hpp, which defines USINGZ first, so including clipper.core.h and the like directly broke ClipperZUtils.cpp.
96 lines
5.2 KiB
C++
96 lines
5.2 KiB
C++
#ifndef slic3r_PlaceholderParser_hpp_
|
|
#define slic3r_PlaceholderParser_hpp_
|
|
|
|
#include "Config.hpp"
|
|
#include "libslic3r.h"
|
|
#include <map>
|
|
#include <memory>
|
|
#include <random>
|
|
#include <set>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
#include "PrintConfig.hpp"
|
|
|
|
namespace Slic3r {
|
|
|
|
class PlaceholderParser
|
|
{
|
|
public:
|
|
// Context to be shared during multiple executions of the PlaceholderParser.
|
|
// The context is kept external to the PlaceholderParser, so that the same PlaceholderParser
|
|
// may be called safely from multiple threads.
|
|
// In the future, the context may hold variables created and modified by the PlaceholderParser
|
|
// and shared between the PlaceholderParser::process() invocations.
|
|
struct ContextData {
|
|
std::mt19937 rng;
|
|
// If defined, then this dictionary is used by the scripts to define user variables and persist them
|
|
// between PlaceholderParser evaluations.
|
|
std::unique_ptr<DynamicConfig> global_config;
|
|
// Global variables declared in {if} branches that were not taken, see check_inactive_branches.
|
|
std::set<std::string> inactive_global_variables;
|
|
};
|
|
|
|
// Orca: when set, variable names inside {if} branches that are not taken must resolve too, so a single
|
|
// expansion checks every branch of a template. Only the profile validator's slice sweep sets it.
|
|
// It does not apply to evaluate_boolean_expression(), where an error reads as "compatible".
|
|
static inline bool check_inactive_branches = false;
|
|
|
|
PlaceholderParser(const DynamicConfig *external_config = nullptr);
|
|
|
|
void clear_config() { m_config.clear(); }
|
|
// 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);
|
|
// Return true if modified.
|
|
bool apply_config(const DynamicPrintConfig &config);
|
|
void apply_config(DynamicPrintConfig &&config);
|
|
// 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);
|
|
void apply_env_variables();
|
|
|
|
// 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, std::string_view value) { this->set(key, new ConfigOptionString(std::string(value))); }
|
|
void set(const std::string &key, const char *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)); }
|
|
void set(const std::string &key, bool value) { this->set(key, new ConfigOptionBool(value)); }
|
|
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); }
|
|
DynamicConfig& config_writable() { return m_config; }
|
|
const DynamicConfig& config() const { return m_config; }
|
|
const ConfigOption* option(const std::string &key) const { return m_config.option(key); }
|
|
// 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; }
|
|
|
|
// Fill in the template using a macro processing language.
|
|
// Throws Slic3r::PlaceholderParserError on syntax or runtime error.
|
|
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
|
|
{ return this->process(templ, current_extruder_id, config_override, nullptr /* config_outputs */, context); }
|
|
|
|
// Evaluate a boolean expression using the full expressive power of the PlaceholderParser boolean expression syntax.
|
|
// Throws Slic3r::PlaceholderParserError on syntax or runtime error.
|
|
static bool evaluate_boolean_expression(const std::string &templ, const DynamicConfig &config, const DynamicConfig *config_override = nullptr);
|
|
|
|
// 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); }
|
|
|
|
static void update_user_name(DynamicConfig &config);
|
|
void update_user_name() { update_user_name(m_config); }
|
|
|
|
private:
|
|
// config has a higher priority than external_config when looking up a symbol.
|
|
DynamicConfig m_config;
|
|
const DynamicConfig *m_external_config;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|