123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- //#define CATCH_CONFIG_DISABLE
- #include <catch_main.hpp>
- #include "test_data.hpp"
- #include <libslic3r/GCodeReader.hpp>
- using namespace Slic3r::Test;
- using namespace Slic3r;
- constexpr char* SKIRT_TAG = "Skirt";
- constexpr char* BRIM_TAG = "Brim";
- SCENARIO("skirt test by merill", "") {
- GIVEN("2 objects, don't complete individual object") {
- DynamicPrintConfig &config = Slic3r::DynamicPrintConfig::full_print_config();
- // remove noise
- config.set_deserialize("top_solid_layers", "0");
- config.set_deserialize("bottom_solid_layers", "0");
- config.set_deserialize("fill_density", "0");
- config.set_deserialize("perimeters", "1");
- config.set_deserialize("complete_objects", "0");
- config.set_key_value("gcode_comments", new ConfigOptionBool(true));
- WHEN("skirt with 3 layers is requested") {
- config.set_deserialize("skirts", "1");
- config.set_deserialize("skirt_height", "3");
- config.set_deserialize("brim_width", "0");
- Model model{};
- Print print{};
- Slic3r::Test::init_print(print, { TestMesh::cube_20x20x20, TestMesh::cube_20x20x20 }, model, &config);
- std::map<double, bool> layers_with_skirt;
- std::map<double, bool> layers_with_brim;
- std::string gcode_filepath{ "" };
- Slic3r::Test::gcode(gcode_filepath, print);
- auto parser{ Slic3r::GCodeReader() };
- parser.parse_file(gcode_filepath, [&layers_with_skirt, &layers_with_brim, &config](Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
- {
- if (line.extruding(self) && line.comment().find(SKIRT_TAG) != std::string::npos) {
- layers_with_skirt[self.z()] = 1;
- }
- if (line.extruding(self) && line.comment().find(BRIM_TAG) != std::string::npos) {
- layers_with_brim[self.z()] = 1;
- }
- });
- clean_file(gcode_filepath, "gcode");
- THEN("one skrit generated") {
- REQUIRE(print.skirt().entities().size() == 1);
- for (auto obj : print.objects()) {
- REQUIRE(obj->skirt().entities().size() == 0);
- }
- }
- THEN("brim is not generated") {
- REQUIRE(print.brim().entities().size() == 0);
- for (auto obj : print.objects()) {
- REQUIRE(obj->brim().entities().size() == 0);
- }
- REQUIRE(layers_with_brim.size() == 0);
- }
- THEN("skirt_height is honored") {
- REQUIRE(layers_with_skirt.size() == (size_t)config.opt_int("skirt_height"));
- }
- }
- WHEN("brim and skirt with 3 layers is requested") {
- config.set_deserialize("skirts", "1");
- config.set_deserialize("skirt_height", "3");
- config.set_deserialize("brim_width", "4");
- Model model{};
- Print print{};
- Slic3r::Test::init_print(print, { TestMesh::cube_20x20x20, TestMesh::cube_20x20x20 }, model, &config);
- std::map<double, bool> layers_with_skirt;
- std::map<double, bool> layers_with_brim;
- std::string gcode_filepath{ "" };
- Slic3r::Test::gcode(gcode_filepath, print);
- auto parser{ Slic3r::GCodeReader() };
- parser.parse_file(gcode_filepath, [&layers_with_skirt, &layers_with_brim, &config](Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
- {
- if (line.extruding(self) && line.comment().find(SKIRT_TAG) != std::string::npos) {
- layers_with_skirt[self.z()] = 1;
- }
- if (line.extruding(self) && line.comment().find(BRIM_TAG) != std::string::npos) {
- layers_with_brim[self.z()] = 1;
- }
- });
- clean_file(gcode_filepath, "gcode");
- THEN("one skirt generated") {
- REQUIRE(print.skirt().entities().size() == 1);
- for (auto obj : print.objects()) {
- REQUIRE(obj->skirt().entities().size() == 0);
- }
- }
- THEN("brim generated") {
- REQUIRE(print.brim().entities().size() > 0);
- for (auto obj : print.objects()) {
- REQUIRE(obj->brim().entities().size() == 0);
- }
- REQUIRE(layers_with_brim.size() == 1);
- }
- THEN("skirt_height is honored") {
- REQUIRE(layers_with_skirt.size() == (size_t)config.opt_int("skirt_height"));
- }
- }
- WHEN("brim is requested") {
- config.set_deserialize("skirts", "0");
- config.set_deserialize("skirt_height", "3");
- config.set_deserialize("brim_width", "4");
- Model model{};
- Print print{};
- Slic3r::Test::init_print(print, { TestMesh::cube_20x20x20, TestMesh::cube_20x20x20 }, model, &config);
- std::map<double, bool> layers_with_skirt;
- std::map<double, bool> layers_with_brim;
- std::string gcode_filepath{ "" };
- Slic3r::Test::gcode(gcode_filepath, print);
- auto parser{ Slic3r::GCodeReader() };
- parser.parse_file(gcode_filepath, [&layers_with_skirt, &layers_with_brim, &config](Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
- {
- if (line.extruding(self) && line.comment().find(SKIRT_TAG) != std::string::npos) {
- layers_with_skirt[self.z()] = 1;
- }
- if (line.extruding(self) && line.comment().find(BRIM_TAG) != std::string::npos) {
- layers_with_brim[self.z()] = 1;
- }
- });
- clean_file(gcode_filepath, "gcode");
- THEN("no skirt generated") {
- REQUIRE(print.skirt().entities().size() == 0);
- for (auto obj : print.objects()) {
- REQUIRE(obj->skirt().entities().size() == 0);
- }
- }
- THEN("brim generated") {
- REQUIRE(print.brim().entities().size() > 0);
- for (auto obj : print.objects()) {
- REQUIRE(obj->brim().entities().size() == 0);
- }
- REQUIRE(layers_with_brim.size() == 1);
- }
- THEN("skirt_height is honored") {
- REQUIRE(layers_with_skirt.size() == 0);
- }
- }
- }
- GIVEN("3 objects, complete individual object") {
- DynamicPrintConfig &config = Slic3r::DynamicPrintConfig::full_print_config();
- // remove noise
- config.set_deserialize("top_solid_layers", "0");
- config.set_deserialize("bottom_solid_layers", "0");
- config.set_deserialize("fill_density", "0");
- config.set_deserialize("perimeters", "1");
- config.set_deserialize("complete_objects", "1");
- config.set_deserialize("brim_per_object", "1");
- config.set_deserialize("gcode_comments", "1");
- WHEN("skirt with 3 layers is requested") {
- config.set_deserialize("skirts", "1");
- config.set_deserialize("skirt_height", "3");
- config.set_deserialize("brim_width", "0");
- Model model{};
- Print print{};
- Slic3r::Test::init_print(print, { TestMesh::cube_20x20x20, TestMesh::cube_20x20x20, TestMesh::pyramid }, model, &config);
- std::map<double, bool> layers_with_skirt;
- std::map<double, bool> layers_with_brim;
- std::string gcode_filepath{ "" };
- Slic3r::Test::gcode(gcode_filepath, print);
- auto parser{ Slic3r::GCodeReader() };
- parser.parse_file(gcode_filepath, [&layers_with_skirt, &layers_with_brim, &config](Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
- {
- if (line.extruding(self) && line.comment().find(SKIRT_TAG) != std::string::npos) {
- layers_with_skirt[self.z()] = 1;
- }
- if (line.extruding(self) && line.comment().find(BRIM_TAG) != std::string::npos) {
- layers_with_brim[self.z()] = 1;
- }
- });
- THEN("one skirt per object") {
- REQUIRE(print.skirt().entities().size() == 0);
- for (auto obj : print.objects()) {
- REQUIRE(obj->skirt().entities().size() == 1);
- }
- }
- THEN("brim is not generated") {
- REQUIRE(print.brim().entities().size() == 0);
- for (auto obj : print.objects()) {
- REQUIRE(obj->brim().entities().size() == 0);
- }
- REQUIRE(layers_with_brim.size() == 0);
- }
- THEN("skirt_height is honored") {
- REQUIRE(layers_with_skirt.size() == (size_t)config.opt_int("skirt_height"));
- }
- }
- WHEN("brim and skirt with 3 layers is requested") {
- config.set_deserialize("skirts", "1");
- config.set_deserialize("skirt_height", "3");
- config.set_deserialize("brim_width", "4");
- Model model{};
- Print print{};
- Slic3r::Test::init_print(print, { TestMesh::cube_20x20x20, TestMesh::cube_20x20x20 }, model, &config);
- std::map<double, bool> layers_with_skirt;
- std::map<double, bool> layers_with_brim;
- std::string gcode_filepath{ "" };
- Slic3r::Test::gcode(gcode_filepath, print);
- auto parser{ Slic3r::GCodeReader() };
- parser.parse_file(gcode_filepath, [&layers_with_skirt, &layers_with_brim, &config](Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
- {
- if (line.extruding(self) && line.comment().find(SKIRT_TAG) != std::string::npos) {
- layers_with_skirt[self.z()] = 1;
- }
- if (line.extruding(self) && line.comment().find(BRIM_TAG) != std::string::npos) {
- layers_with_brim[self.z()] = 1;
- }
- });
- clean_file(gcode_filepath, "gcode");
- THEN("one skirt per object") {
- REQUIRE(print.skirt().entities().size() == 0);
- for (auto obj : print.objects()) {
- REQUIRE(obj->skirt().entities().size() == 1);
- }
- }
- THEN("brim generated") {
- REQUIRE(print.brim().entities().size() == 0);
- for (auto obj : print.objects()) {
- REQUIRE(obj->brim().entities().size() > 0);
- }
- REQUIRE(layers_with_brim.size() == 1);
- }
- THEN("skirt_height is honored") {
- REQUIRE(layers_with_skirt.size() == (size_t)config.opt_int("skirt_height"));
- }
- }
- WHEN("brim is requested") {
- config.set_deserialize("skirts", "0");
- config.set_deserialize("skirt_height", "3");
- config.set_deserialize("brim_width", "4");
- Model model{};
- Print print{};
- Slic3r::Test::init_print(print, { TestMesh::cube_20x20x20, TestMesh::cube_20x20x20 }, model, &config);
- std::map<double, bool> layers_with_skirt;
- std::map<double, bool> layers_with_brim;
- std::string gcode_filepath{ "" };
- Slic3r::Test::gcode(gcode_filepath, print);
- auto parser{ Slic3r::GCodeReader() };
- parser.parse_file(gcode_filepath, [&layers_with_skirt, &layers_with_brim, &config](Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
- {
- if (line.extruding(self) && line.comment().find(SKIRT_TAG) != std::string::npos) {
- layers_with_skirt[self.z()] = 1;
- }
- if (line.extruding(self) && line.comment().find(BRIM_TAG) != std::string::npos) {
- layers_with_brim[self.z()] = 1;
- }
- });
- clean_file(gcode_filepath, "gcode");
- THEN("no skrit") {
- REQUIRE(print.skirt().entities().size() == 0);
- for (auto obj : print.objects()) {
- REQUIRE(obj->skirt().entities().size() == 0);
- }
- }
- THEN("brim generated") {
- REQUIRE(print.brim().entities().size() == 0);
- for (auto obj : print.objects()) {
- REQUIRE(obj->brim().entities().size() > 0);
- }
- REQUIRE(layers_with_brim.size() == 1);
- }
- THEN("skirt_height is honored") {
- REQUIRE(layers_with_skirt.size() == 0);
- }
- }
- }
- }
- SCENARIO("Original Slic3r Skirt/Brim tests", "[!mayfail]") {
- GIVEN("Configuration with a skirt height of 2") {
- DynamicPrintConfig &config = Slic3r::DynamicPrintConfig::full_print_config();
- config.set_deserialize("skirts", "1");
- config.set_deserialize("skirt_height", "2");
- config.set_deserialize("perimeters", "1");
- config.set_deserialize("support_material_speed", "99");
- config.set_deserialize("gcode_comments", "1");
- // avoid altering speeds unexpectedly
- config.set_deserialize("cooling", "0");
- config.set_deserialize("first_layer_speed", "100%");
- WHEN("multiple objects are printed") {
- auto gcode {std::stringstream("")};
- Model model{};
- Print print{};
- Slic3r::Test::init_print(print, { TestMesh::cube_20x20x20, TestMesh::cube_20x20x20 }, model, &config, false);
- std::map<double, bool> layers_with_skirt;
- std::string gcode_filepath{ "" };
- Slic3r::Test::gcode(gcode_filepath, print);
- auto parser {Slic3r::GCodeReader()};
- parser.parse_file(gcode_filepath, [&layers_with_skirt, &config] (Slic3r::GCodeReader& self, const Slic3r::GCodeReader::GCodeLine& line)
- {
- if (line.extruding(self) && line.comment().find(SKIRT_TAG) != std::string::npos) {
- layers_with_skirt[self.z()] = 1;
- }
- //if (self.z() > 0) {
- // if (line.extruding(self) && (line.new_F(self) == config.opt_float("support_material_speed") * 60.0) ) {
- // layers_with_skirt[self.z()] = 1;
- // }
- //}
- });
- clean_file(gcode_filepath, "gcode");
- THEN("skirt_height is honored") {
- REQUIRE(layers_with_skirt.size() == (size_t)config.opt_int("skirt_height"));
- }
- }
- }
- GIVEN("A default configuration") {
- DynamicPrintConfig &config = Slic3r::DynamicPrintConfig::full_print_config();
- config.set_deserialize("support_material_speed", "99");
- // avoid altering speeds unexpectedly
- config.set_deserialize("cooling", "0");
- config.set_deserialize("first_layer_speed", "100%");
- // remove noise from top/solid layers
- config.set_deserialize("top_solid_layers", "0");
- config.set_deserialize("bottom_solid_layers", "0");
- WHEN("Brim width is set to 5") {
- config.set_deserialize("perimeters", "0");
- config.set_deserialize("skirts", "0");
- config.set_deserialize("brim_width", "5");
- THEN("Brim is generated") {
- Model model{};
- Print print{};
- Slic3r::Test::init_print(print, { TestMesh::cube_20x20x20 }, model, &config, false);
- print.process();
- REQUIRE(print.brim().entities().size()>0);
- }
- }
- WHEN("Skirt area is smaller than the brim") {
- config.set_deserialize("skirts", "1");
- config.set_deserialize("brim_width", "10");
- THEN("GCode generates successfully.") {
- Model model{};
- Print print{};
- Slic3r::Test::init_print(print, { TestMesh::cube_20x20x20 }, model, &config, false);
- std::string gcode_filepath{ "" };
- Slic3r::Test::gcode(gcode_filepath, print);
- std::string gcode_from_file = read_to_string(gcode_filepath);
- REQUIRE(gcode_from_file.size() > 0);
- clean_file(gcode_filepath, "gcode");
- }
- }
- WHEN("Skirt height is 0 and skirts > 0") {
- config.set_deserialize("skirts", "2");
- config.set_deserialize("skirt_height", "0");
- THEN("GCode generates successfully.") {
- Model model{};
- Print print{};
- Slic3r::Test::init_print(print, { TestMesh::cube_20x20x20 }, model, &config, false);
- std::string gcode_filepath{ "" };
- Slic3r::Test::gcode(gcode_filepath, print);
- std::string gcode_from_file = read_to_string(gcode_filepath);
- REQUIRE(gcode_from_file.size() > 0);
- clean_file(gcode_filepath, "gcode");
- }
- }
- WHEN("Perimeter extruder = 2 and support extruders = 3") {
- THEN("Brim is printed with the extruder used for the perimeters of first object") {
- REQUIRE(true); //TODO
- }
- }
- WHEN("Perimeter extruder = 2, support extruders = 3, raft is enabled") {
- THEN("brim is printed with same extruder as skirt") {
- REQUIRE(true); //TODO
- }
- }
- //TODO review this test that fail because "there are no layer" and it test nothing anyway
- //WHEN("Object is plated with overhang support and a brim") {
- // config.set_deserialize("layer_height", "0.4");
- // config.set_deserialize("first_layer_height", "0.4");
- // config.set_deserialize("skirts", "1");
- // config.set_deserialize("skirt_distance", "0");
- // config.set_deserialize("support_material_speed", "99");
- // config.set_deserialize("perimeter_extruder", "1");
- // config.set_deserialize("support_material_extruder", "2");
- // config.set_deserialize("cooling", "0"); // to prevent speeds to be altered
- // config.set_deserialize("first_layer_speed", "100%"); // to prevent speeds to be altered
- // Slic3r::Model model;
- // Print print{};
- // Slic3r::Test::init_print(print, { TestMesh::overhang }, model, &config, false);
- // print.process();
- //
- // config.set_deserialize("support_material", "true"); // to prevent speeds to be altered
- // THEN("skirt length is large enough to contain object with support") {
- // REQUIRE(true); //TODO
- // }
- //}
- WHEN("Large minimum skirt length is used.") {
- config.set_deserialize("min_skirt_length", "20");
- auto gcode {std::stringstream("")};
- Slic3r::Model model;
- Print print{};
- Slic3r::Test::init_print(print, { TestMesh::cube_20x20x20 }, model, &config, false);
- THEN("Gcode generation doesn't crash") {
- std::string gcode_filepath{ "" };
- Slic3r::Test::gcode(gcode_filepath, print);
- std::string gcode_from_file = read_to_string(gcode_filepath);
- REQUIRE(gcode_from_file.size() > 0);
- clean_file(gcode_filepath, "gcode");
- }
- }
- }
- }
|