2019-10-16 11:20:09 +00:00
|
|
|
#include <catch2/catch.hpp>
|
|
|
|
|
|
|
|
#include "libslic3r/libslic3r.h"
|
|
|
|
#include "libslic3r/Print.hpp"
|
2020-05-26 12:34:07 +00:00
|
|
|
#include "libslic3r/Layer.hpp"
|
2019-10-16 11:20:09 +00:00
|
|
|
|
|
|
|
#include "test_data.hpp"
|
|
|
|
|
|
|
|
using namespace Slic3r;
|
|
|
|
using namespace Slic3r::Test;
|
|
|
|
|
|
|
|
SCENARIO("PrintObject: Perimeter generation", "[PrintObject]") {
|
|
|
|
GIVEN("20mm cube and default config") {
|
|
|
|
WHEN("make_perimeters() is called") {
|
2019-10-17 15:09:15 +00:00
|
|
|
Slic3r::Print print;
|
2019-10-17 17:09:24 +00:00
|
|
|
Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, { { "fill_density", 0 } });
|
2019-10-17 15:09:15 +00:00
|
|
|
const PrintObject &object = *print.objects().front();
|
2019-10-16 11:20:09 +00:00
|
|
|
THEN("67 layers exist in the model") {
|
|
|
|
REQUIRE(object.layers().size() == 66);
|
|
|
|
}
|
|
|
|
THEN("Every layer in region 0 has 1 island of perimeters") {
|
2019-10-17 15:09:15 +00:00
|
|
|
for (const Layer *layer : object.layers())
|
2022-10-26 16:41:39 +00:00
|
|
|
REQUIRE(layer->regions().front()->perimeters().size() == 1);
|
2019-10-16 11:20:09 +00:00
|
|
|
}
|
|
|
|
THEN("Every layer in region 0 has 3 paths in its perimeters list.") {
|
2019-10-17 15:09:15 +00:00
|
|
|
for (const Layer *layer : object.layers())
|
2022-10-26 16:41:39 +00:00
|
|
|
REQUIRE(layer->regions().front()->perimeters().items_count() == 3);
|
2019-10-16 11:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SCENARIO("Print: Skirt generation", "[Print]") {
|
|
|
|
GIVEN("20mm cube and default config") {
|
|
|
|
WHEN("Skirts is set to 2 loops") {
|
2019-10-17 15:09:15 +00:00
|
|
|
Slic3r::Print print;
|
|
|
|
Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, {
|
2019-10-17 17:09:24 +00:00
|
|
|
{ "skirt_height", 1 },
|
|
|
|
{ "skirt_distance", 1 },
|
|
|
|
{ "skirts", 2 }
|
2019-10-17 15:09:15 +00:00
|
|
|
});
|
2019-10-16 11:20:09 +00:00
|
|
|
THEN("Skirt Extrusion collection has 2 loops in it") {
|
2019-10-17 15:09:15 +00:00
|
|
|
REQUIRE(print.skirt().items_count() == 2);
|
|
|
|
REQUIRE(print.skirt().flatten().entities.size() == 2);
|
2019-10-16 11:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SCENARIO("Print: Changing number of solid surfaces does not cause all surfaces to become internal.", "[Print]") {
|
|
|
|
GIVEN("sliced 20mm cube and config with top_solid_surfaces = 2 and bottom_solid_surfaces = 1") {
|
|
|
|
Slic3r::DynamicPrintConfig config = Slic3r::DynamicPrintConfig::full_print_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
|
|
|
config.set_deserialize_strict({
|
2019-10-17 17:09:24 +00:00
|
|
|
{ "top_solid_layers", 2 },
|
|
|
|
{ "bottom_solid_layers", 1 },
|
2021-03-09 12:54:42 +00:00
|
|
|
{ "layer_height", 0.25 }, // get a known number of layers
|
|
|
|
{ "first_layer_height", 0.25 }
|
2019-10-17 15:09:15 +00:00
|
|
|
});
|
|
|
|
Slic3r::Print print;
|
2019-10-16 11:20:09 +00:00
|
|
|
Slic3r::Model model;
|
2019-10-17 15:09:15 +00:00
|
|
|
Slic3r::Test::init_print({TestMesh::cube_20x20x20}, print, model, config);
|
2019-10-16 11:20:09 +00:00
|
|
|
// Precondition: Ensure that the model has 2 solid top layers (39, 38)
|
|
|
|
// and one solid bottom layer (0).
|
2019-10-17 15:09:15 +00:00
|
|
|
auto test_is_solid_infill = [&print](size_t obj_id, size_t layer_id) {
|
2022-10-19 14:26:59 +00:00
|
|
|
const Layer &layer = *print.objects()[obj_id]->get_layer((int)layer_id);
|
2019-10-17 15:09:15 +00:00
|
|
|
// iterate over all of the regions in the layer
|
|
|
|
for (const LayerRegion *region : layer.regions()) {
|
|
|
|
// for each region, iterate over the fill surfaces
|
2022-10-26 16:41:39 +00:00
|
|
|
for (const Surface &surface : region->fill_surfaces())
|
2019-10-17 15:09:15 +00:00
|
|
|
CHECK(surface.is_solid());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
print.process();
|
|
|
|
test_is_solid_infill(0, 0); // should be solid
|
2021-03-09 12:54:42 +00:00
|
|
|
test_is_solid_infill(0, 79); // should be solid
|
|
|
|
test_is_solid_infill(0, 78); // should be solid
|
2019-10-16 11:20:09 +00:00
|
|
|
WHEN("Model is re-sliced with top_solid_layers == 3") {
|
2019-10-18 10:05:37 +00:00
|
|
|
config.set("top_solid_layers", 3);
|
2019-10-17 15:09:15 +00:00
|
|
|
print.apply(model, config);
|
|
|
|
print.process();
|
2019-10-16 11:20:09 +00:00
|
|
|
THEN("Print object does not have 0 solid bottom layers.") {
|
2019-10-17 15:09:15 +00:00
|
|
|
test_is_solid_infill(0, 0);
|
2019-10-16 11:20:09 +00:00
|
|
|
}
|
|
|
|
AND_THEN("Print object has 3 top solid layers") {
|
2021-03-09 12:54:42 +00:00
|
|
|
test_is_solid_infill(0, 79);
|
|
|
|
test_is_solid_infill(0, 78);
|
|
|
|
test_is_solid_infill(0, 77);
|
2019-10-16 11:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SCENARIO("Print: Brim generation", "[Print]") {
|
|
|
|
GIVEN("20mm cube and default config, 1mm first layer width") {
|
|
|
|
WHEN("Brim is set to 3mm") {
|
2019-10-17 15:09:15 +00:00
|
|
|
Slic3r::Print print;
|
|
|
|
Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, {
|
2019-10-17 17:09:24 +00:00
|
|
|
{ "first_layer_extrusion_width", 1 },
|
|
|
|
{ "brim_width", 3 }
|
2019-10-17 15:09:15 +00:00
|
|
|
});
|
2019-10-16 11:20:09 +00:00
|
|
|
THEN("Brim Extrusion collection has 3 loops in it") {
|
2019-10-17 15:09:15 +00:00
|
|
|
REQUIRE(print.brim().items_count() == 3);
|
2019-10-16 11:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("Brim is set to 6mm") {
|
2019-10-17 15:09:15 +00:00
|
|
|
Slic3r::Print print;
|
|
|
|
Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, {
|
2019-10-17 17:09:24 +00:00
|
|
|
{ "first_layer_extrusion_width", 1 },
|
|
|
|
{ "brim_width", 6 }
|
2019-10-17 15:09:15 +00:00
|
|
|
});
|
2019-10-16 11:20:09 +00:00
|
|
|
THEN("Brim Extrusion collection has 6 loops in it") {
|
2019-10-17 15:09:15 +00:00
|
|
|
REQUIRE(print.brim().items_count() == 6);
|
2019-10-16 11:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
WHEN("Brim is set to 6mm, extrusion width 0.5mm") {
|
2019-10-17 15:09:15 +00:00
|
|
|
Slic3r::Print print;
|
|
|
|
Slic3r::Test::init_and_process_print({TestMesh::cube_20x20x20}, print, {
|
2019-10-17 17:09:24 +00:00
|
|
|
{ "first_layer_extrusion_width", 1 },
|
|
|
|
{ "brim_width", 6 },
|
|
|
|
{ "first_layer_extrusion_width", 0.5 }
|
2019-10-17 15:09:15 +00:00
|
|
|
});
|
|
|
|
print.process();
|
2019-10-16 11:20:09 +00:00
|
|
|
THEN("Brim Extrusion collection has 12 loops in it") {
|
2019-10-17 15:09:15 +00:00
|
|
|
REQUIRE(print.brim().items_count() == 14);
|
2019-10-16 11:20:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-06 16:30:10 +00:00
|
|
|
|
|
|
|
SCENARIO("Ported from Perl", "[Print]") {
|
|
|
|
GIVEN("20mm cube") {
|
|
|
|
WHEN("Print center is set to 100x100 (test framework default)") {
|
|
|
|
auto config = Slic3r::DynamicPrintConfig::full_print_config();
|
|
|
|
std::string gcode = Slic3r::Test::slice({ TestMesh::cube_20x20x20 }, config);
|
|
|
|
GCodeReader parser;
|
|
|
|
Points extrusion_points;
|
|
|
|
parser.parse_buffer(gcode, [&extrusion_points](Slic3r::GCodeReader &self, const Slic3r::GCodeReader::GCodeLine &line)
|
|
|
|
{
|
|
|
|
if (line.cmd_is("G1") && line.extruding(self) && line.dist_XY(self) > 0)
|
|
|
|
extrusion_points.emplace_back(line.new_XY_scaled(self));
|
|
|
|
});
|
|
|
|
Vec2d center = unscaled<double>(BoundingBox(extrusion_points).center());
|
|
|
|
THEN("print is centered around print_center") {
|
|
|
|
REQUIRE(is_approx(center.x(), 100.));
|
|
|
|
REQUIRE(is_approx(center.y(), 100.));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GIVEN("Model with multiple objects") {
|
|
|
|
auto config = Slic3r::DynamicPrintConfig::full_print_config_with({
|
|
|
|
{ "nozzle_diameter", { 0.4, 0.4, 0.4, 0.4 } }
|
|
|
|
});
|
|
|
|
Print print;
|
|
|
|
Model model;
|
|
|
|
Slic3r::Test::init_print({ TestMesh::cube_20x20x20 }, print, model, config);
|
|
|
|
|
|
|
|
// User sets a per-region option, also testing a deep copy of Model.
|
|
|
|
Model model2(model);
|
|
|
|
model2.objects.front()->config.set_deserialize_strict("fill_density", "100%");
|
|
|
|
WHEN("fill_density overridden") {
|
|
|
|
print.apply(model2, config);
|
|
|
|
THEN("region config inherits model object config") {
|
|
|
|
REQUIRE(print.get_print_region(0).config().fill_density == 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
model2.objects.front()->config.erase("fill_density");
|
|
|
|
WHEN("fill_density resetted") {
|
|
|
|
print.apply(model2, config);
|
|
|
|
THEN("region config is resetted") {
|
|
|
|
REQUIRE(print.get_print_region(0).config().fill_density == 20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WHEN("extruder is assigned") {
|
|
|
|
model2.objects.front()->config.set("extruder", 3);
|
|
|
|
model2.objects.front()->config.set("perimeter_extruder", 2);
|
|
|
|
print.apply(model2, config);
|
|
|
|
THEN("extruder setting is correctly expanded") {
|
|
|
|
REQUIRE(print.get_print_region(0).config().infill_extruder == 3);
|
|
|
|
}
|
|
|
|
THEN("extruder setting does not override explicitely specified extruders") {
|
|
|
|
REQUIRE(print.get_print_region(0).config().perimeter_extruder == 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|