test_printobject.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. Slic3r::DynamicPrintConfig config = Slic3r::DynamicPrintConfig::full_print_config();
  10. TestMesh m = TestMesh::cube_20x20x20;
  11. Slic3r::Model model;
  12. config.set_deserialize("first_layer_height", "2");
  13. WHEN("generate_object_layers() is called for 2mm layer heights and nozzle diameter of 3mm") {
  14. config.opt_float("nozzle_diameter", 0) = 3;
  15. config.opt_float("layer_height") = 2.0;
  16. Slic3r::Print print;
  17. Slic3r::Test::init_print({m}, print, model, config);
  18. print.process();
  19. const std::vector<Slic3r::Layer*> &layers = print.objects().front()->layers();
  20. THEN("The output vector has 10 entries") {
  21. REQUIRE(layers.size() == 10);
  22. }
  23. AND_THEN("Each layer is approximately 2mm above the previous Z") {
  24. coordf_t last = 0.0;
  25. for (size_t i = 0; i < layers.size(); ++ i) {
  26. REQUIRE((layers[i]->print_z - last) == Approx(2.0));
  27. last = layers[i]->print_z;
  28. }
  29. }
  30. }
  31. WHEN("generate_object_layers() is called for 10mm layer heights and nozzle diameter of 11mm") {
  32. config.opt_float("nozzle_diameter", 0) = 11;
  33. config.opt_float("layer_height") = 10;
  34. Slic3r::Print print;
  35. Slic3r::Test::init_print({m}, print, model, config);
  36. print.process();
  37. const std::vector<Slic3r::Layer*> &layers = print.objects().front()->layers();
  38. THEN("The output vector has 3 entries") {
  39. REQUIRE(layers.size() == 3);
  40. }
  41. AND_THEN("Layer 0 is at 2mm") {
  42. REQUIRE(layers.front()->print_z == Approx(2.0));
  43. }
  44. AND_THEN("Layer 1 is at 12mm") {
  45. REQUIRE(layers[1]->print_z == Approx(12.0));
  46. }
  47. }
  48. WHEN("generate_object_layers() is called for 15mm layer heights and nozzle diameter of 16mm") {
  49. config.opt_float("nozzle_diameter", 0) = 16;
  50. config.opt_float("layer_height") = 15.0;
  51. Slic3r::Print print;
  52. Slic3r::Test::init_print({m}, print, model, config);
  53. print.process();
  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. config.opt_float("nozzle_diameter", 0) = 5;
  68. config.opt_float("layer_height") = 15.0;
  69. Slic3r::Print print;
  70. Slic3r::Test::init_print({m}, print, model, config);
  71. print.process();
  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. }