test_model.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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,
  41. arr2::to_arrange_bed(get_bed_shape(config)),
  42. arr2::ArrangeSettings{}.set_distance_from_objects(
  43. min_object_distance(config)));
  44. model_object->ensure_on_bed();
  45. print.auto_assign_extruders(model_object);
  46. THEN("Print works?") {
  47. print.set_status_silent();
  48. print.apply(model, config);
  49. print.process();
  50. boost::filesystem::path temp = boost::filesystem::unique_path();
  51. print.export_gcode(temp.string(), nullptr, nullptr);
  52. REQUIRE(boost::filesystem::exists(temp));
  53. REQUIRE(boost::filesystem::is_regular_file(temp));
  54. REQUIRE(boost::filesystem::file_size(temp) > 0);
  55. boost::nowide::remove(temp.string().c_str());
  56. }
  57. }
  58. }
  59. }