test_complete_objects.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #define CATCH_CONFIG_DISABLE
  2. #include <catch2/catch.hpp>
  3. //#include <catch_main.hpp>
  4. #include <string>
  5. #include "test_data.hpp"
  6. #include <libslic3r/libslic3r.h>
  7. #include <libslic3r/ModelArrange.hpp>
  8. #include <libslic3r/SVG.hpp>
  9. using namespace Slic3r::Test;
  10. using namespace Slic3r;
  11. using namespace std::literals;
  12. std::unique_ptr<Print> init_print_with_dist(DynamicPrintConfig &config, float distance) {
  13. TestMesh m = TestMesh::cube_20x20x20;
  14. Model model{};
  15. std::unique_ptr<Print> print(new Print{});
  16. ModelObject* object{ model.add_object() };
  17. object->name += std::string(mesh_names.at(m)) + ".stl"s;
  18. object->add_volume(mesh(m));
  19. ModelInstance* inst1{ object->add_instance() };
  20. inst1->set_offset(Vec3d(-distance/2, 0, 0));
  21. inst1->set_rotation(Vec3d(0, 0, 0));
  22. inst1->set_scaling_factor(Vec3d(1, 1, 1));
  23. ModelInstance* inst2{ object->add_instance() };
  24. inst2->set_offset(Vec3d(distance/2, 0, 0));
  25. inst2->set_rotation(Vec3d(0, 0, 0));
  26. inst2->set_scaling_factor(Vec3d(1, 1, 1));
  27. for (auto* mo : model.objects) {
  28. print->auto_assign_extruders(mo);
  29. }
  30. if (distance <= 0) {
  31. print->apply(model, config);
  32. arrange_objects(model, InfiniteBed{}, ArrangeParams{ scaled(/*min_object_distance(config)) });/*/ PrintConfig::min_object_distance(&print->config(), 999999)) });
  33. model.center_instances_around_point(Slic3r::Vec2d(100, 100));
  34. }
  35. std::cout << "inst1 pos = " << inst1->get_offset().x() << ":" << inst1->get_offset().y() << "\n";
  36. std::cout << "inst2 pos = " << inst2->get_offset().x() << ":" << inst2->get_offset().y() << "\n";
  37. print->apply(model, config);
  38. return print;
  39. }
  40. SCENARIO("Complete objects separatly") {
  41. GIVEN("20mm cubes and extruder_clearance_radius to 10") {
  42. DynamicPrintConfig& config = Slic3r::DynamicPrintConfig::full_print_config();
  43. config.set_key_value("fill_density", new ConfigOptionPercent(0));
  44. config.set_deserialize("nozzle_diameter", "0.4");
  45. config.set_deserialize("layer_height", "0.3");
  46. config.set_deserialize("extruder_clearance_height", "50");
  47. config.set_deserialize("extruder_clearance_radius", "10");
  48. config.set_deserialize("skirts", "0");
  49. config.set_deserialize("skirt_height", "0");
  50. config.set_deserialize("brim_width", "0");
  51. std::pair<PrintBase::PrintValidationError, std::string> result;
  52. WHEN("2 mm appart") {
  53. //model.arrange_objects(print.config().min_object_distance());
  54. //model.center_instances_around_point(Slic3r::Vec2d(100, 100));
  55. THEN("no complete objects") {
  56. result = init_print_with_dist(config, 22)->validate();
  57. REQUIRE(result.second == "");
  58. }
  59. //now with complete_objects
  60. THEN("complete objects") {
  61. config.set_key_value("complete_objects", new ConfigOptionBool(true));
  62. result = init_print_with_dist(config, 22)->validate();
  63. REQUIRE(result.first == PrintBase::PrintValidationError::pveWrongPosition);
  64. }
  65. }
  66. WHEN("at the limit (~30 mm)") {
  67. config.set_key_value("complete_objects", new ConfigOptionBool(true));
  68. THEN("(too near)") {
  69. result = init_print_with_dist(config, 29.9)->validate();
  70. REQUIRE(result.first == PrintBase::PrintValidationError::pveWrongPosition);
  71. }
  72. THEN("(ok far)") {
  73. result = init_print_with_dist(config, 30.1)->validate();
  74. REQUIRE(result.second == "");
  75. REQUIRE(result.first == PrintBase::PrintValidationError::pveNone);
  76. }
  77. }
  78. WHEN("with a 10 mm brim, so the dist should be 40mm ") {
  79. config.set_key_value("complete_objects", new ConfigOptionBool(true));
  80. config.set_deserialize("brim_width", "10");
  81. THEN("(too near)") {
  82. result = init_print_with_dist(config, 39.9)->validate();
  83. REQUIRE(result.first == PrintBase::PrintValidationError::pveWrongPosition);
  84. }
  85. THEN("(ok far)") {
  86. result = init_print_with_dist(config, 40.1)->validate();
  87. REQUIRE(result.second == "");
  88. REQUIRE(result.first == PrintBase::PrintValidationError::pveNone);
  89. }
  90. }
  91. WHEN("with a 10 mm dist short skirt, so the dist should be 40mm +extrusionwidth") {
  92. config.set_key_value("complete_objects", new ConfigOptionBool(true));
  93. config.set_deserialize("skirts", "1");
  94. config.set_deserialize("skirt_height", "1");
  95. config.set_deserialize("skirt_distance", "10");
  96. config.set_deserialize("complete_objects_one_skirt", "0");
  97. THEN("(too near)") {
  98. result = init_print_with_dist(config, 40)->validate();
  99. REQUIRE(result.first == PrintBase::PrintValidationError::pveWrongPosition);
  100. }
  101. THEN("(ok far)") {
  102. result = init_print_with_dist(config, 40.8)->validate();
  103. REQUIRE(result.second == "");
  104. REQUIRE(result.first == PrintBase::PrintValidationError::pveNone);
  105. }
  106. }
  107. }
  108. }
  109. SCENARIO("Arrange is good enough") {
  110. GIVEN("20mm cubes and extruder_clearance_radius to 10") {
  111. DynamicPrintConfig& config = Slic3r::DynamicPrintConfig::full_print_config();
  112. config.set_key_value("fill_density", new ConfigOptionPercent(0));
  113. config.set_deserialize("nozzle_diameter", "0.4");
  114. config.set_deserialize("layer_height", "0.3");
  115. config.set_deserialize("extruder_clearance_height", "50");
  116. config.set_deserialize("extruder_clearance_radius", "10");
  117. config.set_deserialize("skirts", "0");
  118. config.set_deserialize("skirt_height", "0");
  119. config.set_deserialize("brim_width", "0");
  120. std::pair<PrintBase::PrintValidationError, std::string> result;
  121. WHEN("no complete objects") {
  122. result = init_print_with_dist(config,-1)->validate();
  123. REQUIRE(result.second == "");
  124. }
  125. WHEN("complete objects") {
  126. config.set_key_value("complete_objects", new ConfigOptionBool(true));
  127. result = init_print_with_dist(config, -1)->validate();
  128. REQUIRE(result.second == "");
  129. }
  130. WHEN("complete objects whith brim") {
  131. config.set_key_value("complete_objects", new ConfigOptionBool(true));
  132. config.set_deserialize("brim_width", "10");
  133. result = init_print_with_dist(config, -1)->validate();
  134. REQUIRE(result.second == "");
  135. }
  136. WHEN("complete objects whith skirt") {
  137. config.set_key_value("complete_objects", new ConfigOptionBool(true));
  138. config.set_deserialize("skirts", "1");
  139. config.set_deserialize("skirt_height", "1");
  140. config.set_deserialize("skirt_distance", "10");
  141. config.set_deserialize("complete_objects_one_skirt", "0");
  142. result = init_print_with_dist(config, -1)->validate();
  143. REQUIRE(result.second == "");
  144. }
  145. }
  146. }