FIX: backend get the extruder id based on filament_map

Change-Id: Ib7679c0fc67336e462467dab9f5b4d4684d6eb19
(cherry picked from commit dcd9fd501354da33baea2adc0f645fabe8880cf1)
This commit is contained in:
zhimin.zeng
2024-07-02 19:26:52 +08:00
committed by Noisyfox
parent f5d2a1bc0c
commit 8db3e3cd54
20 changed files with 193 additions and 131 deletions

View File

@@ -80,7 +80,7 @@ void PlaceholderParser::update_timestamp(DynamicConfig &config)
time_t rawtime;
time(&rawtime);
struct tm* timeinfo = localtime(&rawtime);
{
std::ostringstream ss;
ss << (1900 + timeinfo->tm_year);
@@ -214,7 +214,7 @@ namespace client
explicit expr(const char *s) : m_type(TYPE_STRING) { m_data.s = new std::string(s); }
explicit expr(const std::string &s) : m_type(TYPE_STRING) { m_data.s = new std::string(s); }
explicit expr(std::string &&s) : m_type(TYPE_STRING) { m_data.s = new std::string(std::move(s)); }
explicit expr(const std::string &s, const Iterator &it_begin, const Iterator &it_end) :
explicit expr(const std::string &s, const Iterator &it_begin, const Iterator &it_end) :
m_type(TYPE_STRING), it_range(it_begin, it_end) { m_data.s = new std::string(s); }
explicit expr(expr &&rhs, const Iterator &it_begin, const Iterator &it_end) : m_type(rhs.type()), it_range{ it_begin, it_end }
{
@@ -233,8 +233,8 @@ namespace client
return *this;
}
expr &operator=(expr &&rhs)
{
expr &operator=(expr &&rhs)
{
if (this != &rhs) {
this->reset();
m_type = rhs.type();
@@ -245,7 +245,7 @@ namespace client
return *this;
}
void reset()
void reset()
{
if (this->type() == TYPE_STRING)
delete m_data.s;
@@ -298,8 +298,8 @@ namespace client
else
this->set_s_take_ownership(new std::string(s));
}
std::string to_string() const
std::string to_string() const
{
std::string out;
switch (this->type()) {
@@ -308,7 +308,7 @@ namespace client
break;
case TYPE_BOOL: out = this->b() ? "true" : "false"; break;
case TYPE_INT: out = std::to_string(this->i()); break;
case TYPE_DOUBLE:
case TYPE_DOUBLE:
#if 0
// The default converter produces trailing zeros after the decimal point.
out = std::to_string(data.d);
@@ -333,7 +333,7 @@ namespace client
IteratorRange it_range;
expr unary_minus(const Iterator start_pos) const
{
{
switch (this->type()) {
case TYPE_EMPTY:
// Inside an if / else block to be skipped.
@@ -351,7 +351,7 @@ namespace client
}
expr unary_integer(const Iterator start_pos) const
{
{
switch (this->type()) {
case TYPE_EMPTY:
// Inside an if / else block to be skipped.
@@ -369,7 +369,7 @@ namespace client
}
expr round(const Iterator start_pos) const
{
{
switch (this->type()) {
case TYPE_EMPTY:
// Inside an if / else block to be skipped.
@@ -387,7 +387,7 @@ namespace client
}
expr unary_not(const Iterator start_pos) const
{
{
switch (this->type()) {
case TYPE_EMPTY:
// Inside an if / else block to be skipped.
@@ -403,7 +403,7 @@ namespace client
}
expr &operator+=(const expr &rhs)
{
{
if (this->type() == TYPE_EMPTY) {
// Inside an if / else block to be skipped.
} else if (this->type() == TYPE_STRING) {
@@ -426,7 +426,7 @@ namespace client
}
expr &operator-=(const expr &rhs)
{
{
if (this->type() == TYPE_EMPTY) {
// Inside an if / else block to be skipped.
this->reset();
@@ -444,7 +444,7 @@ namespace client
}
expr &operator*=(const expr &rhs)
{
{
if (this->type() == TYPE_EMPTY) {
// Inside an if / else block to be skipped.
this->reset();
@@ -535,16 +535,16 @@ namespace client
// Both types are numeric.
switch (op) {
case '=':
value = (lhs.type() == TYPE_DOUBLE || rhs.type() == TYPE_DOUBLE) ?
value = (lhs.type() == TYPE_DOUBLE || rhs.type() == TYPE_DOUBLE) ?
(std::abs(lhs.as_d() - rhs.as_d()) < 1e-8) : (lhs.i() == rhs.i());
break;
case '<':
value = (lhs.type() == TYPE_DOUBLE || rhs.type() == TYPE_DOUBLE) ?
value = (lhs.type() == TYPE_DOUBLE || rhs.type() == TYPE_DOUBLE) ?
(lhs.as_d() < rhs.as_d()) : (lhs.i() < rhs.i());
break;
case '>':
default:
value = (lhs.type() == TYPE_DOUBLE || rhs.type() == TYPE_DOUBLE) ?
value = (lhs.type() == TYPE_DOUBLE || rhs.type() == TYPE_DOUBLE) ?
(lhs.as_d() > rhs.as_d()) : (lhs.i() > rhs.i());
break;
}
@@ -556,7 +556,7 @@ namespace client
value = lhs.b() == rhs.b();
} else if (lhs.type() == TYPE_STRING || rhs.type() == TYPE_STRING) {
// One type is string, the other could be converted to string.
value = (op == '=') ? (lhs.to_string() == rhs.to_string()) :
value = (op == '=') ? (lhs.to_string() == rhs.to_string()) :
(op == '<') ? (lhs.to_string() < rhs.to_string()) : (lhs.to_string() > rhs.to_string());
} else {
boost::throw_exception(qi::expectation_failure<Iterator>(
@@ -576,7 +576,7 @@ namespace client
static void throw_if_not_numeric(const expr &param)
{
const char *err_msg = "Not a numeric type.";
param.throw_if_not_numeric(err_msg);
param.throw_if_not_numeric(err_msg);
}
enum Function2ParamsType {
@@ -585,7 +585,7 @@ namespace client
};
// Store the result into param1.
static void function_2params(expr &param1, expr &param2, Function2ParamsType fun)
{
{
if (param1.type() == TYPE_EMPTY)
// Inside an if / else block to be skipped
return;
@@ -615,7 +615,7 @@ namespace client
// Store the result into param1.
static void random(expr &param1, expr &param2, std::mt19937 &rng)
{
{
if (param1.type() == TYPE_EMPTY)
// Inside an if / else block to be skipped
return;
@@ -631,7 +631,7 @@ namespace client
// param3 is optional
template<bool leading_zeros>
static void digits(expr &param1, expr &param2, expr &param3)
{
{
if (param1.type() == TYPE_EMPTY)
// Inside an if / else block to be skipped
return;
@@ -738,13 +738,13 @@ namespace client
static void logical_or (expr &lhs, expr &rhs) { logical_op(lhs, rhs, '|'); }
static void logical_and(expr &lhs, expr &rhs) { logical_op(lhs, rhs, '&'); }
void throw_exception(const char *message) const
void throw_exception(const char *message) const
{
boost::throw_exception(qi::expectation_failure<Iterator>(
this->it_range.begin(), this->it_range.end(), spirit::info(std::string("*") + message)));
}
void throw_if_not_numeric(const char *message) const
void throw_if_not_numeric(const char *message) const
{
if (! this->numeric_type())
this->throw_exception(message);
@@ -794,7 +794,7 @@ namespace client
mutable DynamicConfig *config_outputs = nullptr;
// Local variables, read / write
mutable DynamicConfig config_local;
size_t current_extruder_id = 0;
size_t current_extruder_id = 0; // This is filament_id actually
// Random number generator and optionally global variables.
PlaceholderParser::ContextData *context_data = nullptr;
// If false, the macro_processor will evaluate a full macro.
@@ -805,7 +805,14 @@ namespace client
// Table to translate symbol tag to a human readable error message.
static std::map<std::string, std::string> tag_to_error_message;
// Should the parser consider the parsed string to be a macro or a boolean expression?
size_t get_extruder_id() const {
const ConfigOptionInts * filament_map_opt = external_config->option<ConfigOptionInts>("filament_map");
if (filament_map_opt && current_extruder_id < filament_map_opt->values.size()) {
return filament_map_opt->values[current_extruder_id];
}
return 0;
}
static bool evaluate_full_macro(const MyContext *ctx) { return ! ctx->just_boolean_expression; }
// Entering a conditional block.
@@ -908,7 +915,7 @@ namespace client
}
static void legacy_variable_expansion2(
const MyContext *ctx,
const MyContext *ctx,
IteratorRange &opt_key,
IteratorRange &opt_vector_index,
std::string &output)
@@ -1546,7 +1553,7 @@ namespace client
static void evaluate_index(expr &expr_index, int &output)
{
if (expr_index.type() != expr::TYPE_EMPTY) {
if (expr_index.type() != expr::TYPE_INT)
if (expr_index.type() != expr::TYPE_INT)
expr_index.throw_exception("Non-integer index is not allowed to address a vector variable.");
output = expr_index.i();
}
@@ -1738,11 +1745,11 @@ namespace client
// This parser is to be used inside a raw[] directive to accept a single valid UTF-8 character.
// If an invalid UTF-8 sequence is encountered, a qi::expectation_failure is thrown.
struct utf8_char_parser : qi::primitive_parser<utf8_char_parser>
{
// Define the attribute type exposed by this parser component
{
// Define the attribute type exposed by this parser component
template <typename Context, typename Iterator>
struct attribute
{
{
typedef wchar_t type;
};
@@ -1750,7 +1757,7 @@ namespace client
// Also it throws if it encounters valid or invalid UTF-8 sequence.
template <typename Iterator, typename Context , typename Skipper, typename Attribute>
bool parse(Iterator &first, Iterator const &last, Context &context, Skipper const &skipper, Attribute& attr) const
{
{
// The skipper shall always be empty, any white space will be accepted.
// skip_over(first, last, skipper);
if (first == last)
@@ -1794,7 +1801,7 @@ namespace client
// This function is called during error handling to create a human readable string for the error context.
template <typename Context>
spirit::info what(Context&) const
{
{
return spirit::info("unicode_char");
}
};
@@ -2039,7 +2046,7 @@ namespace client
legacy_variable_expansion =
(identifier >> &lit(']'))
[ px::bind(&MyContext::legacy_variable_expansion, _r1, _1, _val) ]
| (identifier > lit('[') > identifier > ']')
| (identifier > lit('[') > identifier > ']')
[ px::bind(&MyContext::legacy_variable_expansion2, _r1, _1, _2, _val) ]
;
legacy_variable_expansion.name("legacy_variable_expansion");
@@ -2057,12 +2064,12 @@ namespace client
eps[px::bind(&MyContext::block_enter, _r1, ! _a)] > conditional_expression(_r1)[px::bind(&MyContext::block_exit_ternary, _r1, ! _a, _1, _val)]);
conditional_expression.name("conditional_expression");
logical_or_expression =
logical_or_expression =
logical_and_expression(_r1) [_val = _1]
>> *( ((kw["or"] | "||") > logical_and_expression(_r1) ) [px::bind(&expr::logical_or, _val, _1)] );
logical_or_expression.name("logical_or_expression");
logical_and_expression =
logical_and_expression =
equality_expression(_r1) [_val = _1]
>> *( ((kw["and"] | "&&") > equality_expression(_r1) ) [px::bind(&expr::logical_and, _val, _1)] );
logical_and_expression.name("logical_and_expression");
@@ -2082,7 +2089,7 @@ namespace client
bool_expr_eval = conditional_expression(_r1) [ px::bind(&expr::evaluate_boolean, _1, _val) ];
bool_expr_eval.name("bool_expr_eval");
relational_expression =
relational_expression =
additive_expression(_r1) [_val = _1]
>> *( ("<=" > additive_expression(_r1) ) [px::bind(&expr::leq, _val, _1)]
| (">=" > additive_expression(_r1) ) [px::bind(&expr::geq, _val, _1)]
@@ -2150,11 +2157,11 @@ namespace client
| (lit('-') > unary_expression(_r1) ) [ px::bind(&FactorActions::minus_, _1, _val) ]
| (lit('+') > unary_expression(_r1) > iter_pos) [ px::bind(&FactorActions::expr_, _1, _2, _val) ]
| ((kw["not"] | '!') > unary_expression(_r1) > iter_pos) [ px::bind(&FactorActions::not_, _1, _val) ]
| (kw["min"] > '(' > conditional_expression(_r1) [_val = _1] > ',' > conditional_expression(_r1) > ')')
| (kw["min"] > '(' > conditional_expression(_r1) [_val = _1] > ',' > conditional_expression(_r1) > ')')
[ px::bind(&expr::min, _val, _2) ]
| (kw["max"] > '(' > conditional_expression(_r1) [_val = _1] > ',' > conditional_expression(_r1) > ')')
| (kw["max"] > '(' > conditional_expression(_r1) [_val = _1] > ',' > conditional_expression(_r1) > ')')
[ px::bind(&expr::max, _val, _2) ]
| (kw["random"] > '(' > conditional_expression(_r1) [_val = _1] > ',' > conditional_expression(_r1) > ')')
| (kw["random"] > '(' > conditional_expression(_r1) [_val = _1] > ',' > conditional_expression(_r1) > ')')
[ px::bind(&MyContext::random, _r1, _val, _2) ]
| (kw["digits"] > '(' > conditional_expression(_r1) [_val = _1] > ',' > conditional_expression(_r1) > optional_parameter(_r1))
[ px::bind(&expr::digits<false>, _val, _2, _3) ]