test_printobject.cpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include <catch2/catch.hpp>
  2. #include "libslic3r/libslic3r.h"
  3. #include "libslic3r/Print.hpp"
  4. #include "test_data.hpp"
  5. using namespace Slic3r;
  6. using namespace Slic3r::Test;
  7. SCENARIO("PrintObject: object layer heights", "[PrintObject]") {
  8. GIVEN("20mm cube and default initial config, initial layer height of 2mm") {
  9. WHEN("generate_object_layers() is called for 2mm layer heights and nozzle diameter of 3mm") {
  10. Slic3r::Print print;
  11. Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, {
  12. { "first_layer_height", 2 },
  13. { "layer_height", 2 },
  14. { "nozzle_diameter", 3 }
  15. });
  16. const std::vector<Slic3r::Layer*> &layers = print.objects().front()->layers();
  17. THEN("The output vector has 10 entries") {
  18. REQUIRE(layers.size() == 10);
  19. }
  20. AND_THEN("Each layer is approximately 2mm above the previous Z") {
  21. coordf_t last = 0.0;
  22. for (size_t i = 0; i < layers.size(); ++ i) {
  23. REQUIRE((layers[i]->print_z - last) == Approx(2.0));
  24. last = layers[i]->print_z;
  25. }
  26. }
  27. }
  28. WHEN("generate_object_layers() is called for 10mm layer heights and nozzle diameter of 11mm") {
  29. Slic3r::Print print;
  30. Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, {
  31. { "first_layer_height", 2 },
  32. { "layer_height", 10 },
  33. { "nozzle_diameter", 11 }
  34. });
  35. const std::vector<Slic3r::Layer*> &layers = print.objects().front()->layers();
  36. THEN("The output vector has 3 entries") {
  37. REQUIRE(layers.size() == 3);
  38. }
  39. AND_THEN("Layer 0 is at 2mm") {
  40. REQUIRE(layers.front()->print_z == Approx(2.0));
  41. }
  42. AND_THEN("Layer 1 is at 12mm") {
  43. REQUIRE(layers[1]->print_z == Approx(12.0));
  44. }
  45. }
  46. WHEN("generate_object_layers() is called for 15mm layer heights and nozzle diameter of 16mm") {
  47. Slic3r::Print print;
  48. Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, {
  49. { "first_layer_height", 2 },
  50. { "layer_height", 15 },
  51. { "nozzle_diameter", 16 }
  52. });
  53. const std::vector<Slic3r::Layer*> &layers = print.objects().front()->layers();
  54. THEN("The output vector has 2 entries") {
  55. REQUIRE(layers.size() == 2);
  56. }
  57. AND_THEN("Layer 0 is at 2mm") {
  58. REQUIRE(layers[0]->print_z == Approx(2.0));
  59. }
  60. AND_THEN("Layer 1 is at 17mm") {
  61. REQUIRE(layers[1]->print_z == Approx(17.0));
  62. }
  63. }
  64. #if 0
  65. WHEN("generate_object_layers() is called for 15mm layer heights and nozzle diameter of 5mm") {
  66. Slic3r::Print print;
  67. Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, {
  68. { "first_layer_height", 2 },
  69. { "layer_height", 15 },
  70. { "nozzle_diameter", 5 }
  71. });
  72. const std::vector<Slic3r::Layer*> &layers = print.objects().front()->layers();
  73. THEN("The layer height is limited to 5mm.") {
  74. CHECK(layers.size() == 5);
  75. coordf_t last = 2.0;
  76. for (size_t i = 1; i < layers.size(); i++) {
  77. REQUIRE((layers[i]->print_z - last) == Approx(5.0));
  78. last = layers[i]->print_z;
  79. }
  80. }
  81. }
  82. #endif
  83. }
  84. }