PlaceholderParser on G-code export:

1) added "num_extruders" placeholder
2) changed "is_extruder_used" vector to be always minimum 256 elements long
   with the non-existent extruder values set to zero.
   This is wasteful, but necessary until we change the PlaceholderParser
   handling of vector values to not substitute missing elements
   with the zero'th value.
This commit is contained in:
Vojtech Bubnik 2023-06-13 10:20:45 +02:00
parent f8eb152a5e
commit 8806442f55
2 changed files with 9 additions and 2 deletions

View File

@ -1296,8 +1296,12 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
this->placeholder_parser().set("first_layer_print_min", new ConfigOptionFloats({ bbox.min.x(), bbox.min.y() })); this->placeholder_parser().set("first_layer_print_min", new ConfigOptionFloats({ bbox.min.x(), bbox.min.y() }));
this->placeholder_parser().set("first_layer_print_max", new ConfigOptionFloats({ bbox.max.x(), bbox.max.y() })); this->placeholder_parser().set("first_layer_print_max", new ConfigOptionFloats({ bbox.max.x(), bbox.max.y() }));
this->placeholder_parser().set("first_layer_print_size", new ConfigOptionFloats({ bbox.size().x(), bbox.size().y() })); this->placeholder_parser().set("first_layer_print_size", new ConfigOptionFloats({ bbox.size().x(), bbox.size().y() }));
this->placeholder_parser().set("num_extruders", int(print.config().nozzle_diameter.values.size()));
std::vector<unsigned char> is_extruder_used(print.config().nozzle_diameter.size(), 0); // PlaceholderParser currently substitues non-existent vector values with the zero'th value, which is harmful in the case of "is_extruder_used[]"
// as Slicer may lie about availability of such non-existent extruder.
// We rather sacrifice 256B of memory before we change the behavior of the PlaceholderParser, which should really only fill in the non-existent
// vector elements for filament parameters.
std::vector<unsigned char> is_extruder_used(std::max(size_t(255), print.config().nozzle_diameter.size()), 0);
for (unsigned int extruder_id : tool_ordering.all_extruders()) for (unsigned int extruder_id : tool_ordering.all_extruders())
is_extruder_used[extruder_id] = true; is_extruder_used[extruder_id] = true;
this->placeholder_parser().set("is_extruder_used", new ConfigOptionBools(is_extruder_used)); this->placeholder_parser().set("is_extruder_used", new ConfigOptionBools(is_extruder_used));

View File

@ -1090,6 +1090,7 @@ namespace client
static void scalar_variable_assign_scalar(const MyContext *ctx, OptWithPos &lhs, const expr &rhs) static void scalar_variable_assign_scalar(const MyContext *ctx, OptWithPos &lhs, const expr &rhs)
{ {
assert(! ctx->skipping());
assert(lhs.opt->is_scalar()); assert(lhs.opt->is_scalar());
check_writable(ctx, lhs); check_writable(ctx, lhs);
ConfigOption *wropt = const_cast<ConfigOption*>(lhs.opt); ConfigOption *wropt = const_cast<ConfigOption*>(lhs.opt);
@ -1121,6 +1122,7 @@ namespace client
static void vector_variable_element_assign_scalar(const MyContext *ctx, OptWithPos &lhs, const expr &rhs) static void vector_variable_element_assign_scalar(const MyContext *ctx, OptWithPos &lhs, const expr &rhs)
{ {
assert(! ctx->skipping());
assert(lhs.opt->is_vector()); assert(lhs.opt->is_vector());
check_writable(ctx, lhs); check_writable(ctx, lhs);
if (! lhs.has_index()) if (! lhs.has_index())
@ -1158,6 +1160,7 @@ namespace client
static void vector_variable_assign_expr_with_count(const MyContext *ctx, OptWithPos &lhs, const expr &rhs_count, const expr &rhs_value) static void vector_variable_assign_expr_with_count(const MyContext *ctx, OptWithPos &lhs, const expr &rhs_count, const expr &rhs_value)
{ {
assert(! ctx->skipping());
size_t count = evaluate_count(rhs_count); size_t count = evaluate_count(rhs_count);
auto *opt = const_cast<ConfigOption*>(lhs.opt); auto *opt = const_cast<ConfigOption*>(lhs.opt);
switch (lhs.opt->type()) { switch (lhs.opt->type()) {