test_model.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <catch2/catch.hpp>
  2. #include "libslic3r/libslic3r.h"
  3. #include "libslic3r/Model.hpp"
  4. #include "libslic3r/ModelArrange.hpp"
  5. #include <boost/nowide/cstdio.hpp>
  6. #include <boost/filesystem.hpp>
  7. #include "test_data.hpp"
  8. using namespace Slic3r;
  9. using namespace Slic3r::Test;
  10. SCENARIO("Model construction", "[Model]") {
  11. GIVEN("A Slic3r Model") {
  12. Slic3r::Model model;
  13. Slic3r::TriangleMesh sample_mesh = Slic3r::make_cube(20,20,20);
  14. Slic3r::DynamicPrintConfig config = Slic3r::DynamicPrintConfig::full_print_config();
  15. Slic3r::Print print;
  16. WHEN("Model object is added") {
  17. Slic3r::ModelObject *model_object = model.add_object();
  18. THEN("Model object list == 1") {
  19. REQUIRE(model.objects.size() == 1);
  20. }
  21. model_object->add_volume(sample_mesh);
  22. THEN("Model volume list == 1") {
  23. REQUIRE(model_object->volumes.size() == 1);
  24. }
  25. THEN("Model volume is a part") {
  26. REQUIRE(model_object->volumes.front()->is_model_part());
  27. }
  28. THEN("Mesh is equivalent to input mesh.") {
  29. REQUIRE(! sample_mesh.its.vertices.empty());
  30. const std::vector<Vec3f>& mesh_vertices = model_object->volumes.front()->mesh().its.vertices;
  31. Vec3f mesh_offset = model_object->volumes.front()->source.mesh_offset.cast<float>();
  32. for (size_t i = 0; i < sample_mesh.its.vertices.size(); ++ i) {
  33. const Vec3f &p1 = sample_mesh.its.vertices[i];
  34. const Vec3f p2 = mesh_vertices[i] + mesh_offset;
  35. REQUIRE((p2 - p1).norm() < EPSILON);
  36. }
  37. }
  38. model_object->add_instance();
  39. print.apply(model, config); // apply config for arrange_objects
  40. arrange_objects(model, InfiniteBed{ scaled(Vec2d(100, 100)) }, ArrangeParams{ scaled(print.config().min_object_distance()) });
  41. model_object->ensure_on_bed();
  42. print.auto_assign_extruders(model_object);
  43. THEN("Print works?") {
  44. print.set_status_silent();
  45. print.apply(model, config);
  46. print.process();
  47. boost::filesystem::path temp = boost::filesystem::unique_path();
  48. print.export_gcode(temp.string(), nullptr, nullptr);
  49. REQUIRE(boost::filesystem::exists(temp));
  50. REQUIRE(boost::filesystem::is_regular_file(temp));
  51. REQUIRE(boost::filesystem::file_size(temp) > 0);
  52. boost::nowide::remove(temp.string().c_str());
  53. }
  54. }
  55. }
  56. }