test_printobject.cpp 3.5 KB

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