From 880e9a52c34943ba4ee22a3d6c2162d314af4e66 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 2 Sep 2018 11:49:49 -0500 Subject: [PATCH] Prime layer_z and layer_num for end gcode in C++ PrintGcode. --- src/test/libslic3r/test_printgcode.cpp | 17 +++++++++++++++++ xs/src/libslic3r/PrintGCode.cpp | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/test/libslic3r/test_printgcode.cpp b/src/test/libslic3r/test_printgcode.cpp index 34c529ed6..67577875b 100644 --- a/src/test/libslic3r/test_printgcode.cpp +++ b/src/test/libslic3r/test_printgcode.cpp @@ -208,6 +208,23 @@ SCENARIO( "PrintGCode basic functionality") { } } + + WHEN("end_gcode exists with layer_num and layer_z") { + config->set("end_gcode", "; Layer_num [layer_num]\n; Layer_z [layer_z]"); + config->set("layer_height", 0.1); + config->set("first_layer_height", 0.1); + + Slic3r::Model model; + auto print {Slic3r::Test::init_print({TestMesh::cube_20x20x20}, model, config)}; + Slic3r::Test::gcode(gcode, print); + + auto exported {gcode.str()}; + THEN("layer_num and layer_z are processed in the end gcode") {\ + REQUIRE(exported.find("; Layer_num 199") != std::string::npos); + REQUIRE(exported.find("; Layer_z 20") != std::string::npos); + } + } + gcode.clear(); } } diff --git a/xs/src/libslic3r/PrintGCode.cpp b/xs/src/libslic3r/PrintGCode.cpp index 179943679..0af21863c 100644 --- a/xs/src/libslic3r/PrintGCode.cpp +++ b/xs/src/libslic3r/PrintGCode.cpp @@ -269,6 +269,8 @@ PrintGCode::output() this->process_layer(idx, layer, layer->object()->_shifted_copies); } } + gcodegen.placeholder_parser->set("layer_z", unscale(print_z)); + gcodegen.placeholder_parser->set("layer_num", gcodegen.layer_index); } this->flush_filters();