Merge branch 'main' into pr/tommasobbianchi/15238

This commit is contained in:
SoftFever
2026-09-08 21:54:22 +08:00
20 changed files with 819 additions and 1748 deletions
+70
View File
@@ -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; }));
}
@@ -554,6 +554,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.