1 #include <catch2/catch.hpp> 2 3 #include "libslic3r/libslic3r.h" 4 #include "libslic3r/Print.hpp" 5 #include "libslic3r/Layer.hpp" 6 7 #include "test_data.hpp" 8 9 using namespace Slic3r; 10 using namespace Slic3r::Test; 11 12 SCENARIO("PrintObject: Perimeter generation", "[PrintObject]") { 13 GIVEN("20mm cube and default config") { 14 WHEN("make_perimeters() is called") { 15 Slic3r::Print print; 16 Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, { { "fill_density", 0 } }); 17 const PrintObject &object = *print.objects().front(); 18 THEN("67 layers exist in the model") { 19 REQUIRE(object.layers().size() == 66); 20 } 21 THEN("Every layer in region 0 has 1 island of perimeters") { 22 for (const Layer *layer : object.layers()) 23 REQUIRE(layer->regions().front()->perimeters.entities.size() == 1); 24 } 25 THEN("Every layer in region 0 has 3 paths in its perimeters list.") { 26 for (const Layer *layer : object.layers()) 27 REQUIRE(layer->regions().front()->perimeters.items_count() == 3); 28 } 29 } 30 } 31 } 32 33 SCENARIO("Print: Skirt generation", "[Print]") { 34 GIVEN("20mm cube and default config") { 35 WHEN("Skirts is set to 2 loops") { 36 Slic3r::Print print; 37 Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, { 38 { "skirt_height", 1 }, 39 { "skirt_distance", 1 }, 40 { "skirts", 2 } 41 }); 42 THEN("Skirt Extrusion collection has 2 loops in it") { 43 REQUIRE(print.skirt().items_count() == 2); 44 REQUIRE(print.skirt().flatten().entities.size() == 2); 45 } 46 } 47 } 48 } 49 50 SCENARIO("Print: Changing number of solid surfaces does not cause all surfaces to become internal.", "[Print]") { 51 GIVEN("sliced 20mm cube and config with top_solid_surfaces = 2 and bottom_solid_surfaces = 1") { 52 Slic3r::DynamicPrintConfig config = Slic3r::DynamicPrintConfig::full_print_config(); 53 config.set_deserialize_strict({ 54 { "top_solid_layers", 2 }, 55 { "bottom_solid_layers", 1 }, 56 { "layer_height", 0.5 }, // get a known number of layers 57 { "first_layer_height", 0.5 } 58 }); 59 Slic3r::Print print; 60 Slic3r::Model model; 61 Slic3r::Test::init_print({TestMesh::cube_20x20x20}, print, model, config); 62 // Precondition: Ensure that the model has 2 solid top layers (39, 38) 63 // and one solid bottom layer (0). __anonbfa9aecb0102(size_t obj_id, size_t layer_id) 64 auto test_is_solid_infill = [&print](size_t obj_id, size_t layer_id) { 65 const Layer &layer = *(print.objects().at(obj_id)->get_layer((int)layer_id)); 66 // iterate over all of the regions in the layer 67 for (const LayerRegion *region : layer.regions()) { 68 // for each region, iterate over the fill surfaces 69 for (const Surface &surface : region->fill_surfaces.surfaces) 70 CHECK(surface.is_solid()); 71 } 72 }; 73 print.process(); 74 test_is_solid_infill(0, 0); // should be solid 75 test_is_solid_infill(0, 39); // should be solid 76 test_is_solid_infill(0, 38); // should be solid 77 WHEN("Model is re-sliced with top_solid_layers == 3") { 78 config.set("top_solid_layers", 3); 79 print.apply(model, config); 80 print.process(); 81 THEN("Print object does not have 0 solid bottom layers.") { 82 test_is_solid_infill(0, 0); 83 } 84 AND_THEN("Print object has 3 top solid layers") { 85 test_is_solid_infill(0, 39); 86 test_is_solid_infill(0, 38); 87 test_is_solid_infill(0, 37); 88 } 89 } 90 } 91 } 92 93 SCENARIO("Print: Brim generation", "[Print]") { 94 GIVEN("20mm cube and default config, 1mm first layer width") { 95 WHEN("Brim is set to 3mm") { 96 Slic3r::Print print; 97 Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, { 98 { "first_layer_extrusion_width", 1 }, 99 { "brim_width", 3 } 100 }); 101 THEN("Brim Extrusion collection has 3 loops in it") { 102 REQUIRE(print.brim().items_count() == 3); 103 } 104 } 105 WHEN("Brim is set to 6mm") { 106 Slic3r::Print print; 107 Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, { 108 { "first_layer_extrusion_width", 1 }, 109 { "brim_width", 6 } 110 }); 111 THEN("Brim Extrusion collection has 6 loops in it") { 112 REQUIRE(print.brim().items_count() == 6); 113 } 114 } 115 WHEN("Brim is set to 6mm, extrusion width 0.5mm") { 116 Slic3r::Print print; 117 Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, { 118 { "first_layer_extrusion_width", 1 }, 119 { "brim_width", 6 }, 120 { "first_layer_extrusion_width", 0.5 } 121 }); 122 print.process(); 123 THEN("Brim Extrusion collection has 12 loops in it") { 124 REQUIRE(print.brim().items_count() == 14); 125 } 126 } 127 } 128 } 129