2019-10-16 11:20:09 +00:00
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
|
|
|
|
#include "libslic3r/Model.hpp"
|
|
|
|
#include "libslic3r/Format/3mf.hpp"
|
2020-01-06 11:31:35 +00:00
|
|
|
#include "libslic3r/Format/STL.hpp"
|
2020-01-06 11:10:57 +00:00
|
|
|
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
2019-10-16 11:20:09 +00:00
|
|
|
|
|
|
|
using namespace Slic3r;
|
|
|
|
|
2019-10-18 11:05:22 +00:00
|
|
|
SCENARIO("Reading 3mf file", "[3mf]") {
|
2019-10-16 11:20:09 +00:00
|
|
|
GIVEN("umlauts in the path of the file") {
|
2020-01-06 11:10:57 +00:00
|
|
|
Model model;
|
2019-10-16 11:20:09 +00:00
|
|
|
WHEN("3mf model is read") {
|
|
|
|
std::string path = std::string(TEST_DATA_DIR) + "/test_3mf/Geräte/Büchse.3mf";
|
|
|
|
DynamicPrintConfig config;
|
Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.
When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.
Substitute enums and bools only. Allow booleans to be parsed as
true: "1", "enabled", "on" case insensitive
false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".
Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.
WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 14:04:23 +00:00
|
|
|
ConfigSubstitutionContext ctxt{ ForwardCompatibilitySubstitutionRule::Disable };
|
|
|
|
bool ret = load_3mf(path.c_str(), config, ctxt, &model, false);
|
2019-10-16 11:20:09 +00:00
|
|
|
THEN("load should succeed") {
|
|
|
|
REQUIRE(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-06 11:10:57 +00:00
|
|
|
|
|
|
|
SCENARIO("Export+Import geometry to/from 3mf file cycle", "[3mf]") {
|
|
|
|
GIVEN("world vertices coordinates before save") {
|
|
|
|
// load a model from stl file
|
|
|
|
Model src_model;
|
2020-01-20 10:20:18 +00:00
|
|
|
std::string src_file = std::string(TEST_DATA_DIR) + "/test_3mf/Prusa.stl";
|
2020-01-06 11:10:57 +00:00
|
|
|
load_stl(src_file.c_str(), &src_model);
|
|
|
|
src_model.add_default_instances();
|
|
|
|
|
2021-05-21 08:14:13 +00:00
|
|
|
ModelObject* src_object = src_model.objects.front();
|
2020-01-06 11:10:57 +00:00
|
|
|
|
|
|
|
// apply generic transformation to the 1st volume
|
|
|
|
Geometry::Transformation src_volume_transform;
|
2021-05-21 08:14:13 +00:00
|
|
|
src_volume_transform.set_offset({ 10.0, 20.0, 0.0 });
|
|
|
|
src_volume_transform.set_rotation({ Geometry::deg2rad(25.0), Geometry::deg2rad(35.0), Geometry::deg2rad(45.0) });
|
|
|
|
src_volume_transform.set_scaling_factor({ 1.1, 1.2, 1.3 });
|
|
|
|
src_volume_transform.set_mirror({ -1.0, 1.0, -1.0 });
|
|
|
|
src_object->volumes.front()->set_transformation(src_volume_transform);
|
2020-01-06 11:10:57 +00:00
|
|
|
|
|
|
|
// apply generic transformation to the 1st instance
|
|
|
|
Geometry::Transformation src_instance_transform;
|
2021-05-21 08:14:13 +00:00
|
|
|
src_instance_transform.set_offset({ 5.0, 10.0, 0.0 });
|
|
|
|
src_instance_transform.set_rotation({ Geometry::deg2rad(12.0), Geometry::deg2rad(13.0), Geometry::deg2rad(14.0) });
|
|
|
|
src_instance_transform.set_scaling_factor({ 0.9, 0.8, 0.7 });
|
|
|
|
src_instance_transform.set_mirror({ 1.0, -1.0, -1.0 });
|
|
|
|
src_object->instances.front()->set_transformation(src_instance_transform);
|
2020-01-06 11:10:57 +00:00
|
|
|
|
|
|
|
WHEN("model is saved+loaded to/from 3mf file") {
|
|
|
|
// save the model to 3mf file
|
|
|
|
std::string test_file = std::string(TEST_DATA_DIR) + "/test_3mf/prusa.3mf";
|
2020-01-08 10:11:38 +00:00
|
|
|
store_3mf(test_file.c_str(), &src_model, nullptr, false);
|
2020-01-06 11:10:57 +00:00
|
|
|
|
|
|
|
// load back the model from the 3mf file
|
|
|
|
Model dst_model;
|
|
|
|
DynamicPrintConfig dst_config;
|
Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.
When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.
Substitute enums and bools only. Allow booleans to be parsed as
true: "1", "enabled", "on" case insensitive
false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".
Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.
WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 14:04:23 +00:00
|
|
|
{
|
|
|
|
ConfigSubstitutionContext ctxt{ ForwardCompatibilitySubstitutionRule::Disable };
|
|
|
|
load_3mf(test_file.c_str(), dst_config, ctxt, &dst_model, false);
|
|
|
|
}
|
2020-01-06 11:10:57 +00:00
|
|
|
boost::filesystem::remove(test_file);
|
|
|
|
|
|
|
|
// compare meshes
|
|
|
|
TriangleMesh src_mesh = src_model.mesh();
|
|
|
|
src_mesh.repair();
|
|
|
|
|
|
|
|
TriangleMesh dst_mesh = dst_model.mesh();
|
|
|
|
dst_mesh.repair();
|
|
|
|
|
|
|
|
bool res = src_mesh.its.vertices.size() == dst_mesh.its.vertices.size();
|
2021-05-21 08:14:13 +00:00
|
|
|
if (res) {
|
|
|
|
for (size_t i = 0; i < dst_mesh.its.vertices.size(); ++i) {
|
2020-01-06 11:10:57 +00:00
|
|
|
res &= dst_mesh.its.vertices[i].isApprox(src_mesh.its.vertices[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
THEN("world vertices coordinates after load match") {
|
|
|
|
REQUIRE(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-20 10:53:47 +00:00
|
|
|
|
|
|
|
SCENARIO("2D convex hull of sinking object", "[3mf]") {
|
|
|
|
GIVEN("model") {
|
|
|
|
// load a model
|
|
|
|
Model model;
|
|
|
|
std::string src_file = std::string(TEST_DATA_DIR) + "/test_3mf/Prusa.stl";
|
|
|
|
load_stl(src_file.c_str(), &model);
|
|
|
|
model.add_default_instances();
|
|
|
|
|
|
|
|
WHEN("model is rotated, scaled and set as sinking") {
|
2021-05-21 08:14:13 +00:00
|
|
|
ModelObject* object = model.objects.front();
|
2021-05-20 10:53:47 +00:00
|
|
|
object->center_around_origin(false);
|
|
|
|
|
|
|
|
// set instance's attitude so that it is rotated, scaled and sinking
|
2021-05-21 08:14:13 +00:00
|
|
|
ModelInstance* instance = object->instances.front();
|
2021-05-24 06:54:08 +00:00
|
|
|
instance->set_rotation(X, -M_PI / 4.0);
|
2021-05-20 10:53:47 +00:00
|
|
|
instance->set_offset(Vec3d::Zero());
|
|
|
|
instance->set_scaling_factor({ 2.0, 2.0, 2.0 });
|
|
|
|
|
|
|
|
// calculate 2D convex hull
|
|
|
|
Polygon hull_2d = object->convex_hull_2d(instance->get_transformation().get_matrix());
|
|
|
|
|
|
|
|
// verify result
|
|
|
|
Points result = {
|
2021-05-24 06:54:08 +00:00
|
|
|
{ -91501496, -15914144 },
|
|
|
|
{ 91501496, -15914144 },
|
|
|
|
{ 91501496, 4243 },
|
|
|
|
{ 78229680, 4246883 },
|
|
|
|
{ 56898100, 4246883 },
|
|
|
|
{ -85501496, 4242641 },
|
|
|
|
{ -91501496, 4243 }
|
2021-05-20 10:53:47 +00:00
|
|
|
};
|
2021-05-21 09:56:10 +00:00
|
|
|
|
2021-05-24 06:54:08 +00:00
|
|
|
bool res = hull_2d.points == result;
|
|
|
|
|
2021-05-20 10:53:47 +00:00
|
|
|
THEN("2D convex hull should match with reference") {
|
|
|
|
REQUIRE(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|