test_complete_objects.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //#define CATCH_CONFIG_DISABLE
  2. #include <catch_main.hpp>
  3. #include <string>
  4. #include "test_data.hpp"
  5. #include <libslic3r/libslic3r.h>
  6. #include <libslic3r/ModelArrange.hpp>
  7. #include <libslic3r/SVG.hpp>
  8. using namespace Slic3r::Test;
  9. using namespace Slic3r;
  10. using namespace std::literals;
  11. std::unique_ptr<Print> init_print_with_dist(DynamicPrintConfig &config, float distance) {
  12. TestMesh m = TestMesh::cube_20x20x20;
  13. Model model{};
  14. std::unique_ptr<Print> print(new Print{});
  15. ModelObject* object{ model.add_object() };
  16. object->name += std::string(mesh_names.at(m)) + ".stl"s;
  17. object->add_volume(mesh(m));
  18. ModelInstance* inst1{ object->add_instance() };
  19. inst1->set_offset(Vec3d(-distance/2, 0, 0));
  20. inst1->set_rotation(Vec3d(0, 0, 0));
  21. inst1->set_scaling_factor(Vec3d(1, 1, 1));
  22. ModelInstance* inst2{ object->add_instance() };
  23. inst2->set_offset(Vec3d(distance/2, 0, 0));
  24. inst2->set_rotation(Vec3d(0, 0, 0));
  25. inst2->set_scaling_factor(Vec3d(1, 1, 1));
  26. for (auto* mo : model.objects) {
  27. print->auto_assign_extruders(mo);
  28. }
  29. if (distance <= 0) {
  30. print->apply(model, config);
  31. arrange_objects(model, InfiniteBed{}, ArrangeParams{ scale_t(10)/*min_object_distance(config)) }); PrintConfig::min_object_distance(&print->config(), 999999))/*/ });
  32. model.center_instances_around_point(Slic3r::Vec2d(100, 100));
  33. }
  34. std::cout << "inst1 pos = " << inst1->get_offset().x() << ":" << inst1->get_offset().y() << "\n";
  35. std::cout << "inst2 pos = " << inst2->get_offset().x() << ":" << inst2->get_offset().y() << "\n";
  36. print->apply(model, config);
  37. return print;
  38. }
  39. SCENARIO("Complete objects separatly") {
  40. GIVEN("20mm cubes and extruder_clearance_radius to 10") {
  41. ConfigSubstitutionContext subst(ForwardCompatibilitySubstitutionRule::Disable);
  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", subst);
  45. config.set_deserialize("layer_height", "0.3", subst);
  46. config.set_deserialize("extruder_clearance_height", "50", subst);
  47. config.set_deserialize("extruder_clearance_radius", "10", subst);
  48. config.set_deserialize("skirts", "0", subst);
  49. config.set_deserialize("skirt_height", "0", subst);
  50. config.set_deserialize("brim_width", "0", subst);
  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", subst);
  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", subst);
  94. config.set_deserialize("skirt_height", "1", subst);
  95. config.set_deserialize("skirt_distance", "10", subst);
  96. config.set_deserialize("complete_objects_one_skirt", "0", subst);
  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. ConfigSubstitutionContext subst(ForwardCompatibilitySubstitutionRule::Disable);
  112. DynamicPrintConfig& config = Slic3r::DynamicPrintConfig::full_print_config();
  113. config.set_key_value("fill_density", new ConfigOptionPercent(0));
  114. config.set_deserialize("nozzle_diameter", "0.4", subst);
  115. config.set_deserialize("layer_height", "0.3", subst);
  116. config.set_deserialize("extruder_clearance_height", "50", subst);
  117. config.set_deserialize("extruder_clearance_radius", "10", subst);
  118. config.set_deserialize("skirts", "0", subst);
  119. config.set_deserialize("skirt_height", "0", subst);
  120. config.set_deserialize("brim_width", "0", subst);
  121. std::pair<PrintBase::PrintValidationError, std::string> result;
  122. WHEN("no complete objects") {
  123. result = init_print_with_dist(config,-1)->validate();
  124. REQUIRE(result.second == "");
  125. }
  126. WHEN("complete objects") {
  127. config.set_key_value("complete_objects", new ConfigOptionBool(true));
  128. result = init_print_with_dist(config, -1)->validate();
  129. REQUIRE(result.second == "");
  130. }
  131. WHEN("complete objects whith brim") {
  132. config.set_key_value("complete_objects", new ConfigOptionBool(true));
  133. config.set_deserialize("brim_width", "10", subst);
  134. result = init_print_with_dist(config, -1)->validate();
  135. REQUIRE(result.second == "");
  136. }
  137. WHEN("complete objects whith skirt") {
  138. config.set_key_value("complete_objects", new ConfigOptionBool(true));
  139. config.set_deserialize("skirts", "1", subst);
  140. config.set_deserialize("skirt_height", "1", subst);
  141. config.set_deserialize("skirt_distance", "10", subst);
  142. config.set_deserialize("complete_objects_one_skirt", "0", subst);
  143. result = init_print_with_dist(config, -1)->validate();
  144. REQUIRE(result.second == "");
  145. }
  146. }
  147. }