test_print.cpp 5.0 KB

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