From e46891fa8c0fffeb4c33097b4c477a05ca9bb8c0 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Thu, 23 Mar 2023 09:23:20 +0100 Subject: [PATCH] PlaceholderParser: Fixed compilation issues, added integration test with FDM slicing process. --- src/libslic3r/PlaceholderParser.cpp | 9 ++++----- tests/fff_print/test_custom_gcode.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/PlaceholderParser.cpp b/src/libslic3r/PlaceholderParser.cpp index 78ded40c4..55e7235eb 100644 --- a/src/libslic3r/PlaceholderParser.cpp +++ b/src/libslic3r/PlaceholderParser.cpp @@ -737,7 +737,7 @@ namespace client // Table to translate symbol tag to a human readable error message. static std::map tag_to_error_message; - static void evaluate_full_macro(const MyContext *ctx, bool &result) { result = ! ctx->just_boolean_expression; } + static bool evaluate_full_macro(const MyContext *ctx) { return ! ctx->just_boolean_expression; } const ConfigOption* optptr(const t_config_option_key &opt_key) const override { @@ -1570,13 +1570,12 @@ namespace client template struct InterpolateTableContext { - template struct Item { double x; boost::iterator_range it_range_x; double y; }; - std::vector> table; + std::vector table; static void init(const expr &x) { if (!x.numeric_type()) @@ -1785,8 +1784,8 @@ namespace client // Also the start symbol switches between the "full macro syntax" and a "boolean expression only", // depending on the context->just_boolean_expression flag. This way a single static expression parser // could serve both purposes. - start = eps[px::bind(&MyContext::evaluate_full_macro, _r1, _a)] > - ( (eps(_a==true) > text_block(_r1) [_val=_1]) + start = + ( (eps(px::bind(&MyContext::evaluate_full_macro, _r1)) > text_block(_r1) [_val=_1]) | conditional_expression(_r1) [ px::bind(&expr::evaluate_boolean_to_string, _1, _val) ] ) > eoi; start.name("start"); diff --git a/tests/fff_print/test_custom_gcode.cpp b/tests/fff_print/test_custom_gcode.cpp index 37103b316..0d109070b 100644 --- a/tests/fff_print/test_custom_gcode.cpp +++ b/tests/fff_print/test_custom_gcode.cpp @@ -258,4 +258,16 @@ SCENARIO("Custom G-code", "[CustomGCode]") REQUIRE(match_count == 2); } } + GIVEN("before_layer_gcode increments global variable") { + auto config = Slic3r::DynamicPrintConfig::new_with({ + { "start_gcode", "{global counter=0}" }, + { "before_layer_gcode", ";Counter{counter=counter+1;counter}\n" } + }); + std::string gcode = Slic3r::Test::slice({ Slic3r::Test::TestMesh::cube_20x20x20 }, config); + THEN("The counter is emitted multiple times before layer change.") { + REQUIRE(Slic3r::Test::contains(gcode, ";Counter1\n")); + REQUIRE(Slic3r::Test::contains(gcode, ";Counter2\n")); + REQUIRE(Slic3r::Test::contains(gcode, ";Counter3\n")); + } + } }