test_print.cpp 5.5 KB

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