2019-10-16 13:40:09 +00:00
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
|
|
|
|
#include "libslic3r/libslic3r.h"
|
|
|
|
#include "libslic3r/GCodeReader.hpp"
|
|
|
|
|
|
|
|
#include "test_data.hpp"
|
|
|
|
|
|
|
|
#include <algorithm>
|
2019-10-18 14:50:03 +00:00
|
|
|
#include <boost/regex.hpp>
|
2019-10-16 13:40:09 +00:00
|
|
|
|
|
|
|
using namespace Slic3r;
|
|
|
|
using namespace Slic3r::Test;
|
|
|
|
|
2019-10-18 14:50:03 +00:00
|
|
|
boost::regex perimeters_regex("G1 X[-0-9.]* Y[-0-9.]* E[-0-9.]* ; perimeter");
|
|
|
|
boost::regex infill_regex("G1 X[-0-9.]* Y[-0-9.]* E[-0-9.]* ; infill");
|
|
|
|
boost::regex skirt_regex("G1 X[-0-9.]* Y[-0-9.]* E[-0-9.]* ; skirt");
|
2019-10-16 13:40:09 +00:00
|
|
|
|
|
|
|
SCENARIO( "PrintGCode basic functionality", "[PrintGCode]") {
|
|
|
|
GIVEN("A default configuration and a print test object") {
|
|
|
|
WHEN("the output is executed with no support material") {
|
2019-10-17 15:09:15 +00:00
|
|
|
Slic3r::Print print;
|
2019-10-16 13:40:09 +00:00
|
|
|
Slic3r::Model model;
|
2019-10-17 15:09:15 +00:00
|
|
|
Slic3r::Test::init_print({TestMesh::cube_20x20x20}, print, model, {
|
2019-10-17 17:09:24 +00:00
|
|
|
{ "layer_height", 0.2 },
|
|
|
|
{ "first_layer_height", 0.2 },
|
|
|
|
{ "first_layer_extrusion_width", 0 },
|
|
|
|
{ "gcode_comments", true },
|
2019-10-17 15:09:15 +00:00
|
|
|
{ "start_gcode", "" }
|
|
|
|
});
|
2019-10-16 13:40:09 +00:00
|
|
|
std::string gcode = Slic3r::Test::gcode(print);
|
|
|
|
THEN("Some text output is generated.") {
|
|
|
|
REQUIRE(gcode.size() > 0);
|
|
|
|
}
|
|
|
|
THEN("Exported text contains slic3r version") {
|
|
|
|
REQUIRE(gcode.find(SLIC3R_VERSION) != std::string::npos);
|
|
|
|
}
|
|
|
|
//THEN("Exported text contains git commit id") {
|
|
|
|
// REQUIRE(gcode.find("; Git Commit") != std::string::npos);
|
|
|
|
// REQUIRE(gcode.find(SLIC3R_BUILD_ID) != std::string::npos);
|
|
|
|
//}
|
|
|
|
THEN("Exported text contains extrusion statistics.") {
|
|
|
|
REQUIRE(gcode.find("; external perimeters extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; perimeters extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; infill extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; solid infill extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; top infill extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; support material extrusion width") == std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; first layer extrusion width") == std::string::npos);
|
|
|
|
}
|
|
|
|
THEN("Exported text does not contain cooling markers (they were consumed)") {
|
|
|
|
REQUIRE(gcode.find(";_EXTRUDE_SET_SPEED") == std::string::npos);
|
|
|
|
}
|
|
|
|
|
|
|
|
THEN("GCode preamble is emitted.") {
|
|
|
|
REQUIRE(gcode.find("G21 ; set units to millimeters") != std::string::npos);
|
|
|
|
}
|
|
|
|
|
|
|
|
THEN("Config options emitted for print config, default region config, default object config") {
|
|
|
|
REQUIRE(gcode.find("; first_layer_temperature") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; layer_height") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; fill_density") != std::string::npos);
|
|
|
|
}
|
|
|
|
THEN("Infill is emitted.") {
|
2019-10-18 14:50:03 +00:00
|
|
|
boost::smatch has_match;
|
|
|
|
REQUIRE(boost::regex_search(gcode, has_match, infill_regex));
|
2019-10-16 13:40:09 +00:00
|
|
|
}
|
|
|
|
THEN("Perimeters are emitted.") {
|
2019-10-18 14:50:03 +00:00
|
|
|
boost::smatch has_match;
|
|
|
|
REQUIRE(boost::regex_search(gcode, has_match, perimeters_regex));
|
2019-10-16 13:40:09 +00:00
|
|
|
}
|
|
|
|
THEN("Skirt is emitted.") {
|
2019-10-18 14:50:03 +00:00
|
|
|
boost::smatch has_match;
|
|
|
|
REQUIRE(boost::regex_search(gcode, has_match, skirt_regex));
|
2019-10-16 13:40:09 +00:00
|
|
|
}
|
|
|
|
THEN("final Z height is 20mm") {
|
2019-10-16 15:55:41 +00:00
|
|
|
double final_z = 0.0;
|
|
|
|
GCodeReader reader;
|
2019-10-17 15:09:15 +00:00
|
|
|
reader.apply_config(print.config());
|
2019-10-16 15:55:41 +00:00
|
|
|
reader.parse_buffer(gcode, [&final_z] (GCodeReader& self, const GCodeReader::GCodeLine& line) {
|
2019-10-16 13:40:09 +00:00
|
|
|
final_z = std::max<double>(final_z, static_cast<double>(self.z())); // record the highest Z point we reach
|
|
|
|
});
|
|
|
|
REQUIRE(final_z == Approx(20.));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("output is executed with complete objects and two differently-sized meshes") {
|
2019-10-17 15:09:15 +00:00
|
|
|
Slic3r::Print print;
|
2019-10-16 13:40:09 +00:00
|
|
|
Slic3r::Model model;
|
2019-10-17 15:09:15 +00:00
|
|
|
Slic3r::Test::init_print({TestMesh::cube_20x20x20,TestMesh::cube_20x20x20}, print, model, {
|
2019-10-17 17:09:24 +00:00
|
|
|
{ "first_layer_extrusion_width", 0 },
|
|
|
|
{ "first_layer_height", 0.3 },
|
|
|
|
{ "layer_height", 0.2 },
|
|
|
|
{ "support_material", false },
|
|
|
|
{ "raft_layers", 0 },
|
|
|
|
{ "complete_objects", true },
|
|
|
|
{ "gcode_comments", true },
|
2019-10-17 15:09:15 +00:00
|
|
|
{ "between_objects_gcode", "; between-object-gcode" }
|
|
|
|
});
|
2019-10-16 13:40:09 +00:00
|
|
|
std::string gcode = Slic3r::Test::gcode(print);
|
|
|
|
THEN("Some text output is generated.") {
|
|
|
|
REQUIRE(gcode.size() > 0);
|
|
|
|
}
|
|
|
|
THEN("Infill is emitted.") {
|
2019-10-18 14:50:03 +00:00
|
|
|
boost::smatch has_match;
|
|
|
|
REQUIRE(boost::regex_search(gcode, has_match, infill_regex));
|
2019-10-16 13:40:09 +00:00
|
|
|
}
|
|
|
|
THEN("Perimeters are emitted.") {
|
2019-10-18 14:50:03 +00:00
|
|
|
boost::smatch has_match;
|
|
|
|
REQUIRE(boost::regex_search(gcode, has_match, perimeters_regex));
|
2019-10-16 13:40:09 +00:00
|
|
|
}
|
|
|
|
THEN("Skirt is emitted.") {
|
2019-10-18 14:50:03 +00:00
|
|
|
boost::smatch has_match;
|
|
|
|
REQUIRE(boost::regex_search(gcode, has_match, skirt_regex));
|
2019-10-16 13:40:09 +00:00
|
|
|
}
|
|
|
|
THEN("Between-object-gcode is emitted.") {
|
|
|
|
REQUIRE(gcode.find("; between-object-gcode") != std::string::npos);
|
|
|
|
}
|
|
|
|
THEN("final Z height is 20.1mm") {
|
2019-10-16 15:55:41 +00:00
|
|
|
double final_z = 0.0;
|
|
|
|
GCodeReader reader;
|
2019-10-17 15:09:15 +00:00
|
|
|
reader.apply_config(print.config());
|
2019-10-16 15:55:41 +00:00
|
|
|
reader.parse_buffer(gcode, [&final_z] (GCodeReader& self, const GCodeReader::GCodeLine& line) {
|
2019-10-16 13:40:09 +00:00
|
|
|
final_z = std::max(final_z, static_cast<double>(self.z())); // record the highest Z point we reach
|
|
|
|
});
|
|
|
|
REQUIRE(final_z == Approx(20.1));
|
|
|
|
}
|
|
|
|
THEN("Z height resets on object change") {
|
2019-10-16 15:55:41 +00:00
|
|
|
double final_z = 0.0;
|
|
|
|
bool reset = false;
|
|
|
|
GCodeReader reader;
|
2019-10-17 15:09:15 +00:00
|
|
|
reader.apply_config(print.config());
|
2019-10-16 15:55:41 +00:00
|
|
|
reader.parse_buffer(gcode, [&final_z, &reset] (GCodeReader& self, const GCodeReader::GCodeLine& line) {
|
2019-10-16 13:40:09 +00:00
|
|
|
if (final_z > 0 && std::abs(self.z() - 0.3) < 0.01 ) { // saw higher Z before this, now it's lower
|
|
|
|
reset = true;
|
|
|
|
} else {
|
|
|
|
final_z = std::max(final_z, static_cast<double>(self.z())); // record the highest Z point we reach
|
|
|
|
}
|
|
|
|
});
|
|
|
|
REQUIRE(reset == true);
|
|
|
|
}
|
|
|
|
THEN("Shorter object is printed before taller object.") {
|
2019-10-16 15:55:41 +00:00
|
|
|
double final_z = 0.0;
|
|
|
|
bool reset = false;
|
|
|
|
GCodeReader reader;
|
2019-10-17 15:09:15 +00:00
|
|
|
reader.apply_config(print.config());
|
2019-10-16 15:55:41 +00:00
|
|
|
reader.parse_buffer(gcode, [&final_z, &reset] (GCodeReader& self, const GCodeReader::GCodeLine& line) {
|
2019-10-16 13:40:09 +00:00
|
|
|
if (final_z > 0 && std::abs(self.z() - 0.3) < 0.01 ) {
|
|
|
|
reset = (final_z > 20.0);
|
|
|
|
} else {
|
|
|
|
final_z = std::max(final_z, static_cast<double>(self.z())); // record the highest Z point we reach
|
|
|
|
}
|
|
|
|
});
|
|
|
|
REQUIRE(reset == true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("the output is executed with support material") {
|
2019-10-17 15:09:15 +00:00
|
|
|
std::string gcode = ::Test::slice({TestMesh::cube_20x20x20}, {
|
2019-10-17 17:09:24 +00:00
|
|
|
{ "first_layer_extrusion_width", 0 },
|
|
|
|
{ "support_material", true },
|
|
|
|
{ "raft_layers", 3 },
|
|
|
|
{ "gcode_comments", true }
|
2019-10-17 15:09:15 +00:00
|
|
|
});
|
2019-10-16 13:40:09 +00:00
|
|
|
THEN("Some text output is generated.") {
|
|
|
|
REQUIRE(gcode.size() > 0);
|
|
|
|
}
|
|
|
|
THEN("Exported text contains extrusion statistics.") {
|
|
|
|
REQUIRE(gcode.find("; external perimeters extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; perimeters extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; infill extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; solid infill extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; top infill extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; support material extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; first layer extrusion width") == std::string::npos);
|
|
|
|
}
|
|
|
|
THEN("Raft is emitted.") {
|
|
|
|
REQUIRE(gcode.find("; raft") != std::string::npos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("the output is executed with a separate first layer extrusion width") {
|
2019-10-17 15:09:15 +00:00
|
|
|
std::string gcode = ::Test::slice({ TestMesh::cube_20x20x20 }, {
|
|
|
|
{ "first_layer_extrusion_width", "0.5" }
|
|
|
|
});
|
2019-10-16 13:40:09 +00:00
|
|
|
THEN("Some text output is generated.") {
|
|
|
|
REQUIRE(gcode.size() > 0);
|
|
|
|
}
|
|
|
|
THEN("Exported text contains extrusion statistics.") {
|
|
|
|
REQUIRE(gcode.find("; external perimeters extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; perimeters extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; infill extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; solid infill extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; top infill extrusion width") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; support material extrusion width") == std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; first layer extrusion width") != std::string::npos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("Cooling is enabled and the fan is disabled.") {
|
2019-10-17 15:09:15 +00:00
|
|
|
std::string gcode = ::Test::slice({ TestMesh::cube_20x20x20 }, {
|
2019-10-17 17:09:24 +00:00
|
|
|
{ "cooling", true },
|
|
|
|
{ "disable_fan_first_layers", 5 }
|
2019-10-17 15:09:15 +00:00
|
|
|
});
|
2019-10-16 13:40:09 +00:00
|
|
|
THEN("GCode to disable fan is emitted."){
|
|
|
|
REQUIRE(gcode.find("M107") != std::string::npos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("end_gcode exists with layer_num and layer_z") {
|
2019-10-17 15:09:15 +00:00
|
|
|
std::string gcode = ::Test::slice({ TestMesh::cube_20x20x20 }, {
|
|
|
|
{ "end_gcode", "; Layer_num [layer_num]\n; Layer_z [layer_z]" },
|
2019-10-17 17:09:24 +00:00
|
|
|
{ "layer_height", 0.1 },
|
|
|
|
{ "first_layer_height", 0.1 }
|
2019-10-17 15:09:15 +00:00
|
|
|
});
|
2019-10-16 13:40:09 +00:00
|
|
|
THEN("layer_num and layer_z are processed in the end gcode") {
|
|
|
|
REQUIRE(gcode.find("; Layer_num 199") != std::string::npos);
|
|
|
|
REQUIRE(gcode.find("; Layer_z 20") != std::string::npos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("current_extruder exists in start_gcode") {
|
|
|
|
{
|
2019-10-17 15:09:15 +00:00
|
|
|
std::string gcode = ::Test::slice({ TestMesh::cube_20x20x20 }, {
|
|
|
|
{ "start_gcode", "; Extruder [current_extruder]" }
|
|
|
|
});
|
2019-10-16 13:40:09 +00:00
|
|
|
THEN("current_extruder is processed in the start gcode and set for first extruder") {
|
|
|
|
REQUIRE(gcode.find("; Extruder 0") != std::string::npos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
2019-10-17 15:09:15 +00:00
|
|
|
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
|
|
|
config.set_num_extruders(4);
|
Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.
When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.
Substitute enums and bools only. Allow booleans to be parsed as
true: "1", "enabled", "on" case insensitive
false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".
Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.
WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 14:04:23 +00:00
|
|
|
config.set_deserialize_strict({
|
2019-10-17 15:09:15 +00:00
|
|
|
{ "start_gcode", "; Extruder [current_extruder]" },
|
2019-10-17 17:09:24 +00:00
|
|
|
{ "infill_extruder", 2 },
|
|
|
|
{ "solid_infill_extruder", 2 },
|
|
|
|
{ "perimeter_extruder", 2 },
|
|
|
|
{ "support_material_extruder", 2 },
|
|
|
|
{ "support_material_interface_extruder", 2 }
|
2019-10-17 15:09:15 +00:00
|
|
|
});
|
|
|
|
std::string gcode = Slic3r::Test::slice({TestMesh::cube_20x20x20}, config);
|
2019-10-16 13:40:09 +00:00
|
|
|
THEN("current_extruder is processed in the start gcode and set for second extruder") {
|
|
|
|
REQUIRE(gcode.find("; Extruder 1") != std::string::npos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("layer_num represents the layer's index from z=0") {
|
2019-10-17 15:09:15 +00:00
|
|
|
std::string gcode = ::Test::slice({ TestMesh::cube_20x20x20, TestMesh::cube_20x20x20 }, {
|
2019-10-17 17:09:24 +00:00
|
|
|
{ "complete_objects", true },
|
|
|
|
{ "gcode_comments", true },
|
2019-10-17 15:09:15 +00:00
|
|
|
{ "layer_gcode", ";Layer:[layer_num] ([layer_z] mm)" },
|
2021-03-09 12:54:42 +00:00
|
|
|
{ "layer_height", 0.1 },
|
|
|
|
{ "first_layer_height", 0.1 }
|
2019-10-17 15:09:15 +00:00
|
|
|
});
|
2019-10-16 13:40:09 +00:00
|
|
|
// End of the 1st object.
|
2021-03-09 12:54:42 +00:00
|
|
|
std::string token = ";Layer:199 ";
|
|
|
|
size_t pos = gcode.find(token);
|
2019-10-16 13:40:09 +00:00
|
|
|
THEN("First and second object last layer is emitted") {
|
|
|
|
// First object
|
|
|
|
REQUIRE(pos != std::string::npos);
|
2021-03-09 12:54:42 +00:00
|
|
|
pos += token.size();
|
2019-10-16 13:40:09 +00:00
|
|
|
REQUIRE(pos < gcode.size());
|
|
|
|
double z = 0;
|
|
|
|
REQUIRE((sscanf(gcode.data() + pos, "(%lf mm)", &z) == 1));
|
|
|
|
REQUIRE(z == Approx(20.));
|
|
|
|
// Second object
|
2021-03-09 12:54:42 +00:00
|
|
|
pos = gcode.find(";Layer:399 ", pos);
|
2019-10-16 13:40:09 +00:00
|
|
|
REQUIRE(pos != std::string::npos);
|
2021-03-09 12:54:42 +00:00
|
|
|
pos += token.size();
|
2019-10-16 13:40:09 +00:00
|
|
|
REQUIRE(pos < gcode.size());
|
|
|
|
REQUIRE((sscanf(gcode.data() + pos, "(%lf mm)", &z) == 1));
|
|
|
|
REQUIRE(z == Approx(20.));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|