test_model.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //#define CATCH_CONFIG_DISABLE
  2. #include <catch_main.hpp>
  3. #include <libslic3r/Config.hpp>
  4. #include <libslic3r/Print.hpp>
  5. #include <libslic3r/Model.hpp>
  6. #include <libslic3r/ModelArrange.hpp>
  7. #include <libslic3r/Arrange.hpp>
  8. #include <libslic3r/sla/IndexedMesh.hpp>
  9. #include "test_data.hpp" // get access to init_print, etc
  10. using namespace Slic3r;
  11. using namespace Slic3r::Test;
  12. SCENARIO("Model construction") {
  13. GIVEN("A Slic3r Model") {
  14. Model model{};
  15. TriangleMesh sample_mesh = make_cube(20,20,20);
  16. Slic3r::sla::IndexedMesh indexed_mesh(sample_mesh); // for ease of use
  17. //sample_mesh.repair();
  18. DynamicPrintConfig &config = Slic3r::DynamicPrintConfig::full_print_config();
  19. Slic3r::Print print{};
  20. print.apply(model, config);
  21. //Slic3r::Test::init_print(print, { sample_mesh }, model, config);
  22. print.set_status_callback([](const PrintBase::SlicingStatus &) {});
  23. WHEN("Model object is added") {
  24. ModelObject* mo = model.add_object();
  25. mo->name = "cube20";
  26. THEN("Model object list == 1") {
  27. REQUIRE(model.objects.size() == 1);
  28. }
  29. mo->add_volume(sample_mesh, false);
  30. THEN("Model volume list == 1") {
  31. REQUIRE(mo->volumes.size() == 1);
  32. }
  33. THEN("Model volume modifier is false") {
  34. REQUIRE(mo->volumes.front()->is_modifier() == false);
  35. }
  36. THEN("Mesh is equivalent to input mesh.") {
  37. Slic3r::sla::IndexedMesh trimesh(mo->volumes.front()->mesh());
  38. REQUIRE(indexed_mesh.vertices() == trimesh.vertices());
  39. }
  40. ModelInstance* inst = mo->add_instance();
  41. inst->set_rotation(Vec3d(0,0,0));
  42. inst->set_scaling_factor(Vec3d(1, 1, 1));
  43. ArrangeParams params;
  44. params.min_obj_distance = Slic3r::min_object_distance(print.config());
  45. Slic3r::arrange_objects(model, InfiniteBed{Point(scale_t(100),scale_t(100))}, params);
  46. model.center_instances_around_point(Slic3r::Vec2d(100,100));
  47. print.auto_assign_extruders(mo);
  48. //print.add_model_object(mo);
  49. print.apply(model, config);
  50. print.validate();
  51. THEN("Print works?") {
  52. std::string gcode_filepath{ "" };
  53. Slic3r::Test::gcode(gcode_filepath, print);
  54. std::cout << "gcode generation done\n";
  55. std::string gcode_from_file = read_to_string(gcode_filepath);
  56. REQUIRE(gcode_from_file.size() > 0);
  57. clean_file(gcode_filepath, "gcode");
  58. }
  59. }
  60. }
  61. }
  62. SCENARIO("xy compensations"){
  63. GIVEN(("A Square with a complex hole inside")){
  64. Slic3r::Polygon square/*new_scale*/{ std::vector<Point>{
  65. Point{ 100, 100 },
  66. Point{ 200, 100 },
  67. Point{ 200, 200 },
  68. Point{ 100, 200 }} };
  69. THEN("elephant and xy can compensate each other"){
  70. //TODO
  71. }
  72. THEN("hole and xy can compensate each othere"){
  73. }
  74. }
  75. }