test_model.cpp 2.6 KB

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