mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-13 20:17:49 +00:00
Merge main and resolved conflicts
This commit is contained in:
@@ -8,6 +8,7 @@ add_executable(${_TEST_NAME}_tests
|
||||
test_arachne_walls.cpp
|
||||
test_arrange.cpp
|
||||
test_bambu_networking.cpp
|
||||
test_buildvolume.cpp
|
||||
test_calib.cpp
|
||||
test_clipper_offset.cpp
|
||||
test_clipper_utils.cpp
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#include "libslic3r/Arachne/utils/ExtrusionLine.hpp"
|
||||
#include "libslic3r/Arachne/BeadingStrategy/BeadingStrategyFactory.hpp"
|
||||
#include "libslic3r/Arachne/BeadingStrategy/BeadingStrategy.hpp"
|
||||
#include "libslic3r/Feature/FuzzySkin/FuzzySkin.hpp"
|
||||
#include "libslic3r/Flow.hpp"
|
||||
#include "libslic3r/Polygon.hpp"
|
||||
#include "libslic3r/ExPolygon.hpp"
|
||||
#include "libslic3r/ClipperUtils.hpp"
|
||||
@@ -309,3 +311,71 @@ TEST_CASE("Beading interpolation tolerates a thicker side with fewer insets", "[
|
||||
CHECK(result.bead_widths[i] == expected.bead_widths[i]);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Closed 20 mm square loop at a uniform width.
|
||||
Arachne::ExtrusionJunctions square_loop(coord_t width)
|
||||
{
|
||||
const coord_t s = scaled<coord_t>(20.);
|
||||
return {{Point(0, 0), width, 0}, {Point(s, 0), width, 0}, {Point(s, s), width, 0}, {Point(0, s), width, 0}, {Point(0, 0), width, 0}};
|
||||
}
|
||||
|
||||
FuzzySkinConfig thick_fuzzy_config(FuzzySkinMode mode, NoiseType noise_type, double thickness_mm)
|
||||
{
|
||||
FuzzySkinConfig cfg{};
|
||||
cfg.type = FuzzySkinType::All;
|
||||
cfg.thickness = scaled<coord_t>(thickness_mm);
|
||||
cfg.point_distance = scaled<coord_t>(0.3);
|
||||
cfg.fuzzy_first_layer = true;
|
||||
cfg.noise_type = noise_type;
|
||||
cfg.noise_scale = 1.0;
|
||||
cfg.noise_octaves = 4;
|
||||
cfg.noise_persistence = 0.5;
|
||||
cfg.mode = mode;
|
||||
cfg.layer_id = 5;
|
||||
return cfg;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Extrusion and Combined mode add noise to each junction's width. A junction narrower than
|
||||
// height * (1 - PI/4) makes Flow::rounded_rectangle_extrusion_spacing() throw and fails the slice.
|
||||
// The fuzz thickness is 3x the line width so the clamp is hit on every run regardless of RNG seed.
|
||||
// Ridged multifractal is covered because its output is not bounded to [-1, 1], so it scales past
|
||||
// the configured thickness; the floor has to hold for any noise value, not just an in-range one.
|
||||
TEST_CASE("Fuzzy skin extrusion width is floored at the minimum the flow accepts", "[Arachne][FuzzySkin]") {
|
||||
using namespace Slic3r::Feature::FuzzySkin;
|
||||
|
||||
const double layer_height = GENERATE(0.08, 0.2, 0.28);
|
||||
const auto mode = GENERATE(FuzzySkinMode::Extrusion, FuzzySkinMode::Combined);
|
||||
const auto noise_type = GENERATE(NoiseType::Classic, NoiseType::Perlin, NoiseType::Billow, NoiseType::RidgedMulti, NoiseType::Voronoi);
|
||||
CAPTURE(layer_height, int(mode), int(noise_type));
|
||||
|
||||
const double line_width_mm = 0.42;
|
||||
auto loop = square_loop(scaled<coord_t>(line_width_mm));
|
||||
fuzzy_extrusion_line(loop, /*slice_z*/ 1.0, layer_height, thick_fuzzy_config(mode, noise_type, 3 * line_width_mm));
|
||||
|
||||
REQUIRE(loop.size() > 100);
|
||||
|
||||
const auto narrowest = std::min_element(loop.begin(), loop.end(), [](const auto& a, const auto& b) { return a.w < b.w; });
|
||||
const double narrowest_mm = unscaled<double>(narrowest->w);
|
||||
const double floor_mm = layer_height * (1. - 0.25 * PI);
|
||||
CAPTURE(narrowest_mm, floor_mm);
|
||||
|
||||
CHECK(narrowest_mm < line_width_mm); // the clamp was exercised
|
||||
CHECK(narrowest_mm > floor_mm);
|
||||
CHECK_NOTHROW(Flow::rounded_rectangle_extrusion_spacing(float(narrowest_mm), float(layer_height)));
|
||||
}
|
||||
|
||||
// Displacement mode only moves points; widths must pass through unchanged.
|
||||
TEST_CASE("Fuzzy skin displacement mode leaves widths untouched", "[Arachne][FuzzySkin]") {
|
||||
using namespace Slic3r::Feature::FuzzySkin;
|
||||
|
||||
const coord_t width = scaled<coord_t>(0.42);
|
||||
auto loop = square_loop(width);
|
||||
fuzzy_extrusion_line(loop, /*slice_z*/ 1.0, /*layer_height*/ 0.2, thick_fuzzy_config(FuzzySkinMode::Displacement, NoiseType::Classic, 1.26));
|
||||
|
||||
REQUIRE(loop.size() > 100);
|
||||
CHECK(std::all_of(loop.begin(), loop.end(), [width](const auto& j) { return j.w == width; }));
|
||||
}
|
||||
|
||||
40
tests/libslic3r/test_buildvolume.cpp
Normal file
40
tests/libslic3r/test_buildvolume.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#include "libslic3r/BuildVolume.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
static std::vector<Vec2d> rect_area(double w, double d)
|
||||
{
|
||||
return { { 0., 0. }, { w, 0. }, { w, d }, { 0., d } };
|
||||
}
|
||||
|
||||
// extruder_printable_height and extruder_printable_area are independent config options, so a
|
||||
// profile can leave the heights short. BuildVolume must not index past the end of the heights.
|
||||
TEST_CASE("BuildVolume falls back to the bed height when extruder_printable_height is short", "[BuildVolume]")
|
||||
{
|
||||
const std::vector<Vec2d> bed = rect_area(200., 200.);
|
||||
const std::vector<std::vector<Vec2d>> areas = { rect_area(200., 200.), rect_area(100., 200.) };
|
||||
const std::vector<double> heights = { 180. };
|
||||
|
||||
const BuildVolume build_volume(bed, 250., areas, heights);
|
||||
|
||||
REQUIRE(build_volume.get_extruder_area_count() == 2);
|
||||
// The extruder with a height of its own keeps it, and differs from the bed, so it gets its own volume.
|
||||
CHECK_THAT(build_volume.get_extruder_area_volume(0).bboxf.max.z(), Catch::Matchers::WithinAbs(180., 1e-6));
|
||||
// The extruder without one falls back to the bed's printable_height instead of reading out of range.
|
||||
CHECK_THAT(build_volume.get_extruder_area_volume(1).bboxf.max.z(), Catch::Matchers::WithinAbs(250., 1e-6));
|
||||
}
|
||||
|
||||
TEST_CASE("BuildVolume keeps per-extruder heights when both vectors match", "[BuildVolume]")
|
||||
{
|
||||
const std::vector<Vec2d> bed = rect_area(200., 200.);
|
||||
const std::vector<std::vector<Vec2d>> areas = { rect_area(120., 200.), rect_area(100., 200.) };
|
||||
const std::vector<double> heights = { 180., 200.5 };
|
||||
|
||||
const BuildVolume build_volume(bed, 250., areas, heights);
|
||||
|
||||
REQUIRE(build_volume.get_extruder_area_count() == 2);
|
||||
CHECK_THAT(build_volume.get_extruder_area_volume(0).bboxf.max.z(), Catch::Matchers::WithinAbs(180., 1e-6));
|
||||
CHECK_THAT(build_volume.get_extruder_area_volume(1).bboxf.max.z(), Catch::Matchers::WithinAbs(200.5, 1e-6));
|
||||
}
|
||||
@@ -856,19 +856,19 @@ TEST_CASE("read_cli rejects an invalid boolean value", "[Config]") {
|
||||
|
||||
TEST_CASE("read_cli accepts the common spellings of a boolean value", "[Config]") {
|
||||
const auto [text, expected] = GENERATE(table<const char*, bool>({
|
||||
{"--reduce-crossing-wall=1", true },
|
||||
{"--reduce-crossing-wall=true", true },
|
||||
{"--reduce-crossing-wall=Yes", true },
|
||||
{"--reduce-crossing-wall=on", true },
|
||||
{"--reduce-crossing-wall=enabled", true },
|
||||
{"--reduce-crossing-wall=TRUE", true },
|
||||
{"--reduce-crossing-wall=oN", true },
|
||||
{"--reduce-crossing-wall=0", false},
|
||||
{"--reduce-crossing-wall=false", false},
|
||||
{"--reduce-crossing-wall=No", false},
|
||||
{"--reduce-crossing-wall=off", false},
|
||||
{"--reduce-crossing-wall=1", true},
|
||||
{"--reduce-crossing-wall=true", true},
|
||||
{"--reduce-crossing-wall=Yes", true},
|
||||
{"--reduce-crossing-wall=on", true},
|
||||
{"--reduce-crossing-wall=enabled", true},
|
||||
{"--reduce-crossing-wall=TRUE", true},
|
||||
{"--reduce-crossing-wall=oN", true},
|
||||
{"--reduce-crossing-wall=0", false},
|
||||
{"--reduce-crossing-wall=false", false},
|
||||
{"--reduce-crossing-wall=No", false},
|
||||
{"--reduce-crossing-wall=off", false},
|
||||
{"--reduce-crossing-wall=disabled", false},
|
||||
{"--reduce-crossing-wall=FALSE", false},
|
||||
{"--reduce-crossing-wall=FALSE", false},
|
||||
{"--reduce-crossing-wall=DiSaBlEd", false},
|
||||
}));
|
||||
|
||||
@@ -1051,3 +1051,43 @@ TEST_CASE("read_cli accepts nil entries for a nullable vector option", "[Config]
|
||||
REQUIRE_FALSE(opt->is_nil(1));
|
||||
REQUIRE_THAT(opt->values[1], Catch::Matchers::WithinAbs(2.5, 1e-9));
|
||||
}
|
||||
|
||||
// get_at() returns values.front() for an out-of-range index, so calling it on an empty vector
|
||||
// option is UB. filament_id and filament_is_support are unpopulated on a CLI from-scratch slice.
|
||||
TEST_CASE("get_filament_type treats empty vector options as absent", "[Config][Filament]")
|
||||
{
|
||||
DynamicPrintConfig config;
|
||||
std::string displayed;
|
||||
|
||||
SECTION("an empty filament_type yields no type at all")
|
||||
{
|
||||
config.set_key_value("filament_type", new ConfigOptionStrings());
|
||||
REQUIRE(config.get_filament_type(displayed, 0) == "");
|
||||
}
|
||||
|
||||
SECTION("an empty filament_is_support falls back to the plain filament type")
|
||||
{
|
||||
config.set_key_value("filament_type", new ConfigOptionStrings({"PETG"}));
|
||||
config.set_key_value("filament_is_support", new ConfigOptionBools());
|
||||
REQUIRE(config.get_filament_type(displayed, 0) == "PETG");
|
||||
REQUIRE(displayed == "PETG");
|
||||
}
|
||||
|
||||
SECTION("a support filament with an empty filament_id resolves from the type alone")
|
||||
{
|
||||
config.set_key_value("filament_type", new ConfigOptionStrings({"PLA"}));
|
||||
config.set_key_value("filament_is_support", new ConfigOptionBools({true}));
|
||||
config.set_key_value("filament_id", new ConfigOptionStrings());
|
||||
REQUIRE(config.get_filament_type(displayed, 0) == "PLA-S");
|
||||
REQUIRE(displayed == "Sup.PLA");
|
||||
}
|
||||
|
||||
SECTION("a populated filament_id still selects the support type by id")
|
||||
{
|
||||
config.set_key_value("filament_type", new ConfigOptionStrings({"PETG"}));
|
||||
config.set_key_value("filament_is_support", new ConfigOptionBools({true}));
|
||||
config.set_key_value("filament_id", new ConfigOptionStrings({"GFS00"}));
|
||||
REQUIRE(config.get_filament_type(displayed, 0) == "PLA-S");
|
||||
REQUIRE(displayed == "Sup.PLA");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,12 @@ TEST_CASE("get_config_index_base resolves (volume type, extruder type, id) to a
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("support interface pattern registry includes spiral inset", "[Config]")
|
||||
{
|
||||
const auto &values = ConfigOptionEnum<SupportMaterialInterfacePattern>::get_enum_values();
|
||||
REQUIRE(values.at("spiralinset") == SupportMaterialInterfacePattern::smipSpiralInset);
|
||||
}
|
||||
|
||||
TEST_CASE("get_extruder_nozzle_volume_count reads the per-extruder volume-type layout", "[Config]")
|
||||
{
|
||||
std::vector<std::vector<NozzleVolumeType>> nozzle_volume_types;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <fstream>
|
||||
|
||||
@@ -589,6 +590,401 @@ struct LibraryFilamentTestCollection : public PresetCollection
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Missing app config is accepted as default CLI state", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
AppConfig app_config;
|
||||
app_config.set_loading_path((dir.path() / "missing.conf").string());
|
||||
CHECK(app_config.load_if_exists().empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Read-only user preset loading does not create or delete files", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
PresetBundle bundle;
|
||||
PresetsConfigSubstitutions substitutions;
|
||||
|
||||
const fs::path missing_root = dir.path() / "missing-user";
|
||||
bundle.prints.load_presets(missing_root.string(), PRESET_PRINT_NAME, substitutions,
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, nullptr,
|
||||
PresetOrigin(), true);
|
||||
CHECK_FALSE(fs::exists(missing_root / PRESET_PRINT_NAME));
|
||||
|
||||
const fs::path malformed = dir.path() / "existing-user" / PRESET_PRINT_NAME / "malformed.json";
|
||||
fs::create_directories(malformed.parent_path());
|
||||
std::ofstream(malformed.string()) << "{not-json";
|
||||
bundle.prints.load_presets((dir.path() / "existing-user").string(), PRESET_PRINT_NAME, substitutions,
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, nullptr,
|
||||
PresetOrigin(), true);
|
||||
CHECK(fs::exists(malformed));
|
||||
}
|
||||
|
||||
TEST_CASE("Typeless preset resolution probes loaded FFF collections", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path source_file = dir.path() / "typeless-process.json";
|
||||
std::ofstream(source_file.string()) << R"({"name":"Typeless Process","from":"User"})";
|
||||
|
||||
PresetBundle bundle;
|
||||
Preset &process = add_inmemory_preset(bundle.prints, "Typeless Process");
|
||||
process.file = source_file.string();
|
||||
process.config.option<ConfigOptionFloats>("travel_speed", true)->values = {321.0};
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
Preset::Type resolved_type = Preset::TYPE_INVALID;
|
||||
std::string error;
|
||||
REQUIRE(bundle.resolve_preset_config_type(raw, resolved_type, source_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error, false));
|
||||
CHECK(error.empty());
|
||||
CHECK(resolved_type == Preset::TYPE_PRINT);
|
||||
REQUIRE(raw.option<ConfigOptionFloats>("travel_speed")->values.size() == 1);
|
||||
CHECK_THAT(raw.option<ConfigOptionFloats>("travel_speed")->values.front(), Catch::Matchers::WithinAbs(321.0, 1e-6));
|
||||
}
|
||||
|
||||
TEST_CASE("Typeless preset resolution preserves duplicate identity ambiguity", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path source_file = dir.path() / "duplicate-process.json";
|
||||
std::ofstream(source_file.string()) << "{}";
|
||||
|
||||
PresetBundle bundle;
|
||||
add_inmemory_preset(bundle.prints, "First Process Identity").file = source_file.string();
|
||||
add_inmemory_preset(bundle.prints, "Second Process Identity").file = source_file.string();
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
Preset::Type resolved_type = Preset::TYPE_INVALID;
|
||||
std::string error;
|
||||
CHECK_FALSE(bundle.resolve_preset_config_type(raw, resolved_type, source_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error, false));
|
||||
CHECK(error == "Preset identity is ambiguous");
|
||||
CHECK(resolved_type == Preset::TYPE_INVALID);
|
||||
}
|
||||
|
||||
TEST_CASE("Typeless preset resolution rejects cross-type ambiguity", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path source_file = dir.path() / "ambiguous.json";
|
||||
std::ofstream(source_file.string()) << "{}";
|
||||
|
||||
PresetBundle bundle;
|
||||
add_inmemory_preset(bundle.prints, "Process Identity").file = source_file.string();
|
||||
add_inmemory_preset(bundle.filaments, "Filament Identity").file = source_file.string();
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
Preset::Type resolved_type = Preset::TYPE_INVALID;
|
||||
std::string error;
|
||||
CHECK_FALSE(bundle.resolve_preset_config_type(raw, resolved_type, source_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error, false));
|
||||
CHECK(error == "Preset type is ambiguous");
|
||||
CHECK(resolved_type == Preset::TYPE_INVALID);
|
||||
}
|
||||
|
||||
TEST_CASE("Typeless preset resolution rejects a missing type candidate", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path source_file = dir.path() / "unknown.json";
|
||||
std::ofstream(source_file.string()) << "{}";
|
||||
|
||||
PresetBundle bundle;
|
||||
DynamicPrintConfig raw;
|
||||
Preset::Type resolved_type = Preset::TYPE_INVALID;
|
||||
std::string error;
|
||||
CHECK_FALSE(bundle.resolve_preset_config_type(raw, resolved_type, source_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error, false));
|
||||
CHECK(error == "Preset type could not be resolved");
|
||||
CHECK(resolved_type == Preset::TYPE_INVALID);
|
||||
}
|
||||
|
||||
TEST_CASE("Exact file resolution rejects multiple preset identities", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path source_file = dir.path() / "duplicate.json";
|
||||
std::ofstream(source_file.string()) << "{}";
|
||||
|
||||
PresetBundle bundle;
|
||||
Preset &first = add_inmemory_preset(bundle.prints, "First Identity");
|
||||
first.file = source_file.string();
|
||||
Preset &second = add_inmemory_preset(bundle.prints, "Second Identity");
|
||||
second.file = source_file.string();
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "Parent";
|
||||
|
||||
std::string error;
|
||||
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, source_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error, false));
|
||||
CHECK(error == "Preset identity is ambiguous");
|
||||
}
|
||||
|
||||
TEST_CASE("System preset resolution returns the canonical vendor configuration", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir source_dir;
|
||||
PresetBundle bundle;
|
||||
|
||||
VendorProfile vendor("VendorB");
|
||||
vendor.name = "Vendor B";
|
||||
auto [vendor_it, inserted] = bundle.vendors.emplace(vendor.id, std::move(vendor));
|
||||
REQUIRE(inserted);
|
||||
|
||||
Preset &resolved = add_inmemory_preset(bundle.prints, "Vendor B Process", "fdm_process_common");
|
||||
resolved.is_system = true;
|
||||
resolved.vendor = &vendor_it->second;
|
||||
resolved.file = (source_dir.path() / "vendor-b-process.json").string();
|
||||
std::ofstream(resolved.file) << "{}";
|
||||
resolved.config.option<ConfigOptionFloats>("travel_speed", true)->values = {321.0};
|
||||
resolved.config.option<ConfigOptionInt>("wall_loops", true)->value = 2;
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "fdm_process_common";
|
||||
raw.option<ConfigOptionInt>("wall_loops", true)->value = 5;
|
||||
|
||||
std::string error;
|
||||
REQUIRE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, resolved.file,
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
|
||||
CHECK(error.empty());
|
||||
REQUIRE(raw.option<ConfigOptionFloats>("travel_speed")->values.size() == 1);
|
||||
CHECK_THAT(raw.option<ConfigOptionFloats>("travel_speed")->values.front(), Catch::Matchers::WithinAbs(321.0, 1e-6));
|
||||
CHECK(raw.option<ConfigOptionInt>("wall_loops")->value == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("Manifest-backed preset resolution loads the source vendor tree", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path vendor_dir = dir.path() / "Acme";
|
||||
const fs::path child_file = vendor_dir / "process" / "nested" / "child.json";
|
||||
|
||||
std::ofstream((dir.path() / "Acme.json").string())
|
||||
<< R"({"version":"1.0.0","name":"Acme","process_list":[)"
|
||||
<< R"({"name":"fdm_process_common","sub_path":"process/base.json"},)"
|
||||
<< R"({"name":"Acme Process","sub_path":"process/nested/child.json"}]})";
|
||||
fs::create_directories(child_file.parent_path());
|
||||
std::ofstream((vendor_dir / "process" / "base.json").string())
|
||||
<< R"({"type":"process","name":"fdm_process_common","from":"system",)"
|
||||
<< R"("instantiation":"false","travel_speed":["321"]})";
|
||||
std::ofstream(child_file.string())
|
||||
<< R"({"type":"process","name":"Acme Process","from":"system",)"
|
||||
<< R"("instantiation":"true","inherits":"fdm_process_common","wall_loops":"5"})";
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "fdm_process_common";
|
||||
raw.option<ConfigOptionInt>("wall_loops", true)->value = 5;
|
||||
|
||||
PresetBundle bundle;
|
||||
std::string error;
|
||||
REQUIRE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, child_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
|
||||
CHECK(error.empty());
|
||||
REQUIRE(raw.option<ConfigOptionFloats>("travel_speed")->values.size() == 1);
|
||||
CHECK_THAT(raw.option<ConfigOptionFloats>("travel_speed")->values.front(), Catch::Matchers::WithinAbs(321.0, 1e-6));
|
||||
CHECK(raw.option<ConfigOptionInt>("wall_loops")->value == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("Manifest-backed resolution is scoped to the explicit source root", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
auto write_vendor = [&](const std::string &root_name, double travel_speed) {
|
||||
const fs::path root = dir.path() / root_name;
|
||||
const fs::path child_file = root / "Acme" / "process" / "child.json";
|
||||
fs::create_directories(child_file.parent_path());
|
||||
std::ofstream((root / "Acme.json").string())
|
||||
<< R"({"version":"1.0.0","name":"Acme","process_list":[)"
|
||||
<< R"({"name":"fdm_process_common","sub_path":"process/base.json"},)"
|
||||
<< R"({"name":"Acme Process","sub_path":"process/child.json"}]})";
|
||||
std::ofstream((root / "Acme" / "process" / "base.json").string())
|
||||
<< R"({"type":"process","name":"fdm_process_common","from":"system",)"
|
||||
<< R"("instantiation":"false","travel_speed":[")" << travel_speed << R"("]})";
|
||||
std::ofstream(child_file.string())
|
||||
<< R"({"type":"process","name":"Acme Process","from":"system",)"
|
||||
<< R"("instantiation":"true","inherits":"fdm_process_common"})";
|
||||
return child_file;
|
||||
};
|
||||
|
||||
const fs::path source_a = write_vendor("root-a", 111.0);
|
||||
const fs::path source_b = write_vendor("root-b", 222.0);
|
||||
REQUIRE(fs::exists(source_a));
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "synthetic-parent-marker";
|
||||
|
||||
PresetBundle bundle;
|
||||
std::string error;
|
||||
REQUIRE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, source_b.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
|
||||
REQUIRE(raw.option<ConfigOptionFloats>("travel_speed")->values.size() == 1);
|
||||
CHECK_THAT(raw.option<ConfigOptionFloats>("travel_speed")->values.front(), Catch::Matchers::WithinAbs(222.0, 1e-6));
|
||||
}
|
||||
|
||||
TEST_CASE("Exact-only resolution rejects an unconfigured manifest-backed file", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path source_file = dir.path() / "Acme" / "process" / "child.json";
|
||||
fs::create_directories(source_file.parent_path());
|
||||
std::ofstream((dir.path() / "Acme.json").string())
|
||||
<< R"({"version":"1.0.0","name":"Acme","process_list":[)"
|
||||
<< R"({"name":"Acme Process","sub_path":"process/child.json"}]})";
|
||||
std::ofstream(source_file.string())
|
||||
<< R"({"type":"process","name":"Acme Process","from":"system",)"
|
||||
<< R"("instantiation":"true","layer_height":"0.2"})";
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "Some Parent";
|
||||
|
||||
PresetBundle bundle;
|
||||
std::string error;
|
||||
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, source_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error, false));
|
||||
CHECK(error == "Preset was not found in the loaded bundle");
|
||||
}
|
||||
|
||||
TEST_CASE("Vendor filament resolution uses the shared Orca library base", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path library_dir = dir.path() / PresetBundle::ORCA_FILAMENT_LIBRARY;
|
||||
const fs::path vendor_dir = dir.path() / "Acme";
|
||||
const fs::path child_file = vendor_dir / "filament" / "nested" / "petg.json";
|
||||
|
||||
std::ofstream((dir.path() / (std::string(PresetBundle::ORCA_FILAMENT_LIBRARY) + ".json")).string())
|
||||
<< R"({"version":"1.0.0","name":"OrcaFilamentLibrary","filament_list":[)"
|
||||
<< R"({"name":"fdm_filament_pet","sub_path":"filament/pet.json","filament_id":"GFL99"}]})";
|
||||
fs::create_directories(library_dir / "filament");
|
||||
std::ofstream((library_dir / "filament" / "pet.json").string())
|
||||
<< R"({"type":"filament","name":"fdm_filament_pet","from":"system",)"
|
||||
<< R"("filament_id":"GFL99","instantiation":"false",)"
|
||||
<< R"("filament_type":["PETG"],"filament_density":["1.27"]})";
|
||||
|
||||
std::ofstream((dir.path() / "Acme.json").string())
|
||||
<< R"({"version":"1.0.0","name":"Acme","filament_list":[)"
|
||||
<< R"({"name":"Acme PETG","sub_path":"filament/nested/petg.json","filament_id":"GFA00"}]})";
|
||||
fs::create_directories(child_file.parent_path());
|
||||
std::ofstream(child_file.string())
|
||||
<< R"({"type":"filament","name":"Acme PETG","from":"system",)"
|
||||
<< R"("filament_id":"GFA00","instantiation":"true","inherits":"fdm_filament_pet"})";
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "fdm_filament_pet";
|
||||
|
||||
PresetBundle bundle;
|
||||
std::string error;
|
||||
REQUIRE(bundle.resolve_preset_config(raw, Preset::TYPE_FILAMENT, child_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
|
||||
CHECK(error.empty());
|
||||
CHECK(raw.opt_string("filament_type", 0u) == "PETG");
|
||||
REQUIRE(raw.option<ConfigOptionFloats>("filament_density")->values.size() == 1);
|
||||
CHECK_THAT(raw.option<ConfigOptionFloats>("filament_density")->values.front(), Catch::Matchers::WithinAbs(1.27, 1e-6));
|
||||
}
|
||||
|
||||
TEST_CASE("Manifest-backed resolution rejects a missing parent", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path child_file = dir.path() / "Acme" / "process" / "child.json";
|
||||
|
||||
std::ofstream((dir.path() / "Acme.json").string())
|
||||
<< R"({"version":"1.0.0","name":"Acme","process_list":[)"
|
||||
<< R"({"name":"Acme Process","sub_path":"process/child.json"}]})";
|
||||
fs::create_directories(child_file.parent_path());
|
||||
std::ofstream(child_file.string())
|
||||
<< R"({"type":"process","name":"Acme Process","from":"system",)"
|
||||
<< R"("instantiation":"true","inherits":"Missing Parent","layer_height":"0.2"})";
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "Missing Parent";
|
||||
|
||||
PresetBundle bundle;
|
||||
std::string error;
|
||||
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, child_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
|
||||
CHECK_FALSE(error.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Manifest-backed resolution rejects a vendor load with malformed entries", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path child_file = dir.path() / "Acme" / "process" / "child.json";
|
||||
|
||||
std::ofstream((dir.path() / "Acme.json").string())
|
||||
<< R"({"version":"1.0.0","name":"Acme","process_list":[123,)"
|
||||
<< R"({"name":"Acme Process","sub_path":"process/child.json"}]})";
|
||||
fs::create_directories(child_file.parent_path());
|
||||
std::ofstream(child_file.string())
|
||||
<< R"({"type":"process","name":"Acme Process","from":"system",)"
|
||||
<< R"("instantiation":"true","layer_height":"0.2"})";
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "fdm_process_common";
|
||||
|
||||
PresetBundle bundle;
|
||||
std::string error;
|
||||
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, child_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
|
||||
CHECK_FALSE(error.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Manifest-backed resolution rejects files absent from the vendor manifest", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path listed_file = dir.path() / "Acme" / "process" / "listed.json";
|
||||
const fs::path unlisted_file = dir.path() / "Acme" / "process" / "unlisted.json";
|
||||
|
||||
std::ofstream((dir.path() / "Acme.json").string())
|
||||
<< R"({"version":"1.0.0","name":"Acme","process_list":[)"
|
||||
<< R"({"name":"Listed Process","sub_path":"process/listed.json"}]})";
|
||||
fs::create_directories(listed_file.parent_path());
|
||||
std::ofstream(listed_file.string())
|
||||
<< R"({"type":"process","name":"Listed Process","from":"system",)"
|
||||
<< R"("instantiation":"true","layer_height":"0.2"})";
|
||||
std::ofstream(unlisted_file.string())
|
||||
<< R"({"type":"process","name":"Unlisted Process","from":"system",)"
|
||||
<< R"("instantiation":"true","inherits":"fdm_process_common"})";
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "fdm_process_common";
|
||||
|
||||
PresetBundle bundle;
|
||||
std::string error;
|
||||
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, unlisted_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
|
||||
CHECK(error == "Source file is not an instantiated preset in its vendor manifest");
|
||||
}
|
||||
|
||||
TEST_CASE("Manifest-backed resolution rejects a mismatched preset type", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path process_file = dir.path() / "Acme" / "process" / "child.json";
|
||||
|
||||
std::ofstream((dir.path() / "Acme.json").string())
|
||||
<< R"({"version":"1.0.0","name":"Acme","process_list":[)"
|
||||
<< R"({"name":"Acme Process","sub_path":"process/child.json"}]})";
|
||||
fs::create_directories(process_file.parent_path());
|
||||
std::ofstream(process_file.string())
|
||||
<< R"({"type":"process","name":"Acme Process","from":"system",)"
|
||||
<< R"("instantiation":"true","layer_height":"0.2"})";
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "fdm_filament_common";
|
||||
|
||||
PresetBundle bundle;
|
||||
std::string error;
|
||||
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_FILAMENT, process_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
|
||||
CHECK(error == "Source file is not an instantiated preset in its vendor manifest");
|
||||
}
|
||||
|
||||
TEST_CASE("Resolution terminates when no vendor manifest exists", "[Preset][Bundle][Regression]")
|
||||
{
|
||||
ScopedTemporaryDir dir;
|
||||
const fs::path detached_file = dir.path() / "detached.json";
|
||||
std::ofstream(detached_file.string()) << "{}";
|
||||
|
||||
DynamicPrintConfig raw;
|
||||
raw.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = "Missing Parent";
|
||||
|
||||
PresetBundle bundle;
|
||||
std::string error;
|
||||
CHECK_FALSE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, detached_file.string(),
|
||||
ForwardCompatibilitySubstitutionRule::EnableSilent, error));
|
||||
CHECK(error == "Preset was not found in the loaded bundle");
|
||||
}
|
||||
|
||||
// Orca: a filament in the Orca Filament Library that names its compatible printers has to hide the generic
|
||||
// library filament sharing its alias, the same way a vendor owned filament does. Otherwise both are compatible
|
||||
// with that printer and the plater combo box lists the shared alias twice.
|
||||
@@ -640,6 +1036,88 @@ TEST_CASE("A printer specific filament supersedes the generic library filament w
|
||||
CHECK(is_compatible_with_printer(generic_lib, PresetWithVendorProfile(*printer_c, nullptr)));
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// One system printer plus the filament presets a machine facing dialog has to choose between:
|
||||
// an Orca Filament Library generic with no compatible_printers, a same alias vendor filament
|
||||
// that names the printer, a library filament with no vendor twin, and a vendor filament that
|
||||
// belongs to a different printer.
|
||||
struct MachineFilaments
|
||||
{
|
||||
PresetBundle bundle;
|
||||
VendorProfile library{PresetBundle::ORCA_FILAMENT_LIBRARY};
|
||||
VendorProfile vendor{"Vendor"};
|
||||
|
||||
MachineFilaments()
|
||||
{
|
||||
// VendorProfile's constructor takes an id; the library rule keys off the name.
|
||||
library.name = PresetBundle::ORCA_FILAMENT_LIBRARY;
|
||||
vendor.name = "Vendor";
|
||||
|
||||
Preset &printer = add_inmemory_preset(bundle.printers, "Printer A 0.4 nozzle");
|
||||
printer.is_system = true;
|
||||
printer.vendor = &vendor;
|
||||
printer.config.option<ConfigOptionString>("printer_model", true)->value = "Printer A";
|
||||
|
||||
add_filament(library, "Generic ABS @System", "Generic ABS", {});
|
||||
add_filament(vendor, "Generic ABS @Printer A", "Generic ABS", { "Printer A 0.4 nozzle" });
|
||||
add_filament(library, "FilAr ABS @System", "FilAr ABS", {});
|
||||
add_filament(vendor, "Vendor PLA @Printer B", "Vendor PLA", { "Printer B 0.4 nozzle" });
|
||||
|
||||
// update_library_profile_excluded_from() is protected and has its own test above; record
|
||||
// the exclusion it derives from the same alias vendor filament.
|
||||
Preset *shadowed = bundle.filaments.find_preset("Generic ABS @System");
|
||||
REQUIRE(shadowed != nullptr);
|
||||
shadowed->m_excluded_from.insert("Printer A 0.4 nozzle");
|
||||
}
|
||||
|
||||
void add_filament(const VendorProfile &owner, const std::string &name, const std::string &alias,
|
||||
std::vector<std::string> compatible_printers)
|
||||
{
|
||||
Preset &preset = add_inmemory_preset(bundle.filaments, name);
|
||||
preset.is_system = true;
|
||||
preset.alias = alias;
|
||||
preset.vendor = &owner;
|
||||
compatible_list(bundle.filaments, name, "compatible_printers") = std::move(compatible_printers);
|
||||
}
|
||||
|
||||
bool offers(const std::string &preset_name, bool include_user_presets = false)
|
||||
{
|
||||
const std::vector<Preset *> offered =
|
||||
bundle.get_filament_presets_for_machine("Printer A", "0.4", include_user_presets);
|
||||
return std::any_of(offered.begin(), offered.end(),
|
||||
[&preset_name](const Preset *p) { return p->name == preset_name; });
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Filaments offered for a machine follow the app's compatibility rule", "[Preset][Bundle]")
|
||||
{
|
||||
MachineFilaments f;
|
||||
|
||||
SECTION("a library filament with no compatible_printers is offered") {
|
||||
CHECK(f.offers("FilAr ABS @System"));
|
||||
}
|
||||
|
||||
SECTION("a same alias vendor filament shadows the library generic") {
|
||||
CHECK(f.offers("Generic ABS @Printer A"));
|
||||
CHECK_FALSE(f.offers("Generic ABS @System"));
|
||||
}
|
||||
|
||||
SECTION("a filament naming a different printer is not offered") {
|
||||
CHECK_FALSE(f.offers("Vendor PLA @Printer B"));
|
||||
}
|
||||
|
||||
SECTION("a user filament is offered only when the printer supports user presets") {
|
||||
add_inmemory_preset(f.bundle.filaments, "My PLA");
|
||||
|
||||
CHECK_FALSE(f.offers("My PLA", /*include_user_presets=*/false));
|
||||
CHECK(f.offers("My PLA", /*include_user_presets=*/true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
const char *kMixedKeys[] = {
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
using namespace Slic3r;
|
||||
|
||||
// Golden vectors from the Python reference generate_preset_setting_id (defined in
|
||||
// scripts/assign_vendor_setting_ids.py). The C++ generate_preset_setting_id() MUST stay
|
||||
// byte-identical to it, otherwise app-side on-the-fly ids would diverge from the
|
||||
// scripts/orca_id_tool.py). The C++ generate_preset_setting_id() MUST stay byte-identical
|
||||
// to it, otherwise app-side on-the-fly ids would diverge from the
|
||||
// script-assigned ones in the profiles. Regenerate a vector with:
|
||||
// python3 -c "from assign_vendor_setting_ids import generate_preset_setting_id as g; print(g('Afinia','filament','Afinia ABS @Afinia H400'))"
|
||||
// python3 -c "import sys; sys.path.insert(0, 'scripts'); from orca_id_tool import generate_preset_setting_id as g; print(g('Afinia','filament','Afinia ABS @Afinia H400'))"
|
||||
TEST_CASE("preset setting_id matches the Python reference", "[Preset][setting_id]") {
|
||||
struct Vec { const char* vendor; const char* type; const char* name; const char* expected; };
|
||||
const Vec vectors[] = {
|
||||
|
||||
Reference in New Issue
Block a user