From 74c4a7e450a745380108b55a1dc72233a2742f6d Mon Sep 17 00:00:00 2001 From: SoftFever Date: Mon, 3 Aug 2026 22:25:50 +0800 Subject: [PATCH 1/2] Support printer specific filament profiles in the OrcaFilamentLibrary (#15101) * Support printer specific filament profiles in the Orca Filament Library --- scripts/orca_extra_profile_check.py | 10 ++- src/libslic3r/Preset.cpp | 6 +- .../libslic3r/test_preset_bundle_loading.cpp | 66 +++++++++++++++++++ 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/scripts/orca_extra_profile_check.py b/scripts/orca_extra_profile_check.py index cdfc8544a4..07ce3d69d3 100644 --- a/scripts/orca_extra_profile_check.py +++ b/scripts/orca_extra_profile_check.py @@ -46,12 +46,16 @@ def no_duplicates_object_pairs_hook(pairs): return seen # NOTE: currently Orca expects compatible_printers to be a defined in every instantiation profile, inheritation is not supported in Profile page -def check_filament_compatible_printers(vendor_folder): +def check_filament_compatible_printers(vendor, vendor_folder): """ Checks JSON files in the vendor folder for missing or empty 'compatible_printers' when 'instantiation' is flagged as true. + In the OrcaFilamentLibrary 'compatible_printers' is optional: a profile without it is generic and + offered on every printer, while a profile that lists printers supersedes the generic one there. + Parameters: + vendor (str): The vendor name the folder belongs to. vendor_folder (str or Path): The directory to search for JSON profile files. Returns: @@ -115,7 +119,7 @@ def check_filament_compatible_printers(vendor_folder): for profile in profiles.values(): instantiation = str(profile['content'].get("instantiation", "")).lower() == "true" - if instantiation: + if instantiation and vendor != 'OrcaFilamentLibrary': try: compatible_printers = get_property(profile, "compatible_printers") if not compatible_printers or (isinstance(compatible_printers, list) and not compatible_printers): @@ -571,7 +575,7 @@ def main(): vendor_path = profiles_dir / vendor_name if args.check_filaments or not (args.check_materials and not args.check_filaments): - errors_found += check_filament_compatible_printers(vendor_path / "filament") + errors_found += check_filament_compatible_printers(vendor_name, vendor_path / "filament") if args.check_materials: new_errors, new_warnings = check_machine_default_materials(profiles_dir, vendor_name) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 2821bef0af..d5bf251d37 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -3784,12 +3784,14 @@ void PresetCollection::update_library_profile_excluded_from() } // Check all presets that has the same alias as the filament presets with empty compatible_printers in Orca Filament Library. + // A printer specific profile supersedes the generic one, no matter whether it lives in a vendor bundle or in the + // library itself. for (const Preset& preset : m_presets) { - if (preset.vendor == nullptr || preset.vendor->name == PresetBundle::ORCA_FILAMENT_LIBRARY) + if (preset.vendor == nullptr) continue; const auto* compatible_printers = dynamic_cast(preset.config.option("compatible_printers")); - // All profiles in concrete vendor profile shouldn't have empty compatible_printers, but here we check it for safety. + // Profiles with empty compatible_printers are the generic ones, they never supersede anything. if (compatible_printers == nullptr || compatible_printers->values.empty()) continue; auto itr = excluded_froms.find(preset.alias); diff --git a/tests/libslic3r/test_preset_bundle_loading.cpp b/tests/libslic3r/test_preset_bundle_loading.cpp index 351535dd9d..c697c4461c 100644 --- a/tests/libslic3r/test_preset_bundle_loading.cpp +++ b/tests/libslic3r/test_preset_bundle_loading.cpp @@ -488,3 +488,69 @@ TEST_CASE("Plugin capability override keys are scoped per preset type", "[Preset } } +namespace { + +// A standalone filament collection that exposes the protected library masking builder, so the Orca +// Filament Library scenario can be set up without the full system-profile load pipeline. +struct LibraryFilamentTestCollection : public PresetCollection +{ + LibraryFilamentTestCollection() + : PresetCollection(Preset::TYPE_FILAMENT, Preset::filament_options(), + static_cast(FullPrintConfig::defaults())) + {} + using PresetCollection::update_library_profile_excluded_from; +}; + +} // namespace + +// 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. +TEST_CASE("A printer specific filament supersedes the generic library filament with the same alias", "[Preset][Bundle]") +{ + LibraryFilamentTestCollection filaments; + PresetCollection printers(Preset::TYPE_PRINTER, Preset::printer_options(), + static_cast(FullPrintConfig::defaults())); + // The masking keys off the vendor name, which VendorProfile's constructor does not derive from the id. + VendorProfile library(PresetBundle::ORCA_FILAMENT_LIBRARY); + VendorProfile vendor("Vendor"); + library.name = PresetBundle::ORCA_FILAMENT_LIBRARY; + vendor.name = "Vendor"; + + auto add_filament = [&filaments](const VendorProfile &owner, const std::string &name, std::vector compatible_printers) { + Preset &preset = add_inmemory_preset(filaments, name); + preset.alias = "Generic ABS"; + preset.vendor = &owner; + preset.config.option("compatible_printers", true)->values = std::move(compatible_printers); + }; + + add_filament(library, "Generic ABS @System", {}); + add_filament(library, "Generic ABS @Printer A", { "Printer A" }); + add_filament(vendor, "Generic ABS @Printer B", { "Printer B" }); + + filaments.update_library_profile_excluded_from(); + + const Preset *generic = filaments.find_preset("Generic ABS @System"); + REQUIRE(generic != nullptr); + CHECK(generic->m_excluded_from.count("Printer A") == 1); + CHECK(generic->m_excluded_from.count("Printer B") == 1); + CHECK(generic->m_excluded_from.size() == 2); + + // A printer specific profile names printers, so it is never the one being hidden - not even by itself. + const Preset *specific = filaments.find_preset("Generic ABS @Printer A"); + REQUIRE(specific != nullptr); + CHECK(specific->m_excluded_from.empty()); + + // ...and the generic profile really drops out of the compatible set on the printer it is hidden from. + add_inmemory_preset(printers, "Printer A"); + add_inmemory_preset(printers, "Printer C"); + const Preset *printer_a = printers.find_preset("Printer A"); + const Preset *printer_c = printers.find_preset("Printer C"); + REQUIRE(printer_a != nullptr); + REQUIRE(printer_c != nullptr); + + const PresetWithVendorProfile generic_lib(*generic, &library); + CHECK_FALSE(is_compatible_with_printer(generic_lib, PresetWithVendorProfile(*printer_a, nullptr))); + CHECK(is_compatible_with_printer(generic_lib, PresetWithVendorProfile(*printer_c, nullptr))); +} + From 06ef58bad8cbe7b6f9ee930372001e20dc24c156 Mon Sep 17 00:00:00 2001 From: Kris Austin Date: Mon, 3 Aug 2026 09:29:00 -0500 Subject: [PATCH 2/2] test: replace the disabled convex_hull_2d test (#14892) test(libslic3r): replace the disabled convex_hull_2d test, closing #11269 The last "failing libslic3r test" from #11269 was the disabled SCENARIO("2D convex hull of sinking object", "[3mf][.]") in test_3mf.cpp. It checked ModelObject::convex_hull_2d for a sinking object against PrusaSlicer's reference hull, but Orca's convex_hull_2d does not clip geometry below the bed the way PrusaSlicer's its_convex_hull_2d_above does, so the reference never matched. The test also wrote a debug mesh to a hardcoded /tmp path and its comparison loop was inverted. Remove it and add tests/libslic3r/test_model.cpp characterizing convex_hull_2d on non-sinking transforms (identity and scale+offset), where the projected footprint is unambiguous. Homed in a Model test file since it exercises ModelObject, not 3MF. --- tests/libslic3r/CMakeLists.txt | 1 + tests/libslic3r/test_3mf.cpp | 61 ---------------------------------- tests/libslic3r/test_model.cpp | 40 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 61 deletions(-) create mode 100644 tests/libslic3r/test_model.cpp diff --git a/tests/libslic3r/CMakeLists.txt b/tests/libslic3r/CMakeLists.txt index dbc6c99f15..1ad299473c 100644 --- a/tests/libslic3r/CMakeLists.txt +++ b/tests/libslic3r/CMakeLists.txt @@ -29,6 +29,7 @@ add_executable(${_TEST_NAME}_tests test_stl.cpp test_meshboolean.cpp test_marchingsquares.cpp + test_model.cpp test_utils.cpp test_timeutils.cpp test_voronoi.cpp diff --git a/tests/libslic3r/test_3mf.cpp b/tests/libslic3r/test_3mf.cpp index 1a082cd8e0..a6fe3ed460 100644 --- a/tests/libslic3r/test_3mf.cpp +++ b/tests/libslic3r/test_3mf.cpp @@ -509,64 +509,3 @@ SCENARIO("Nozzle-group metadata .3mf round-trip", "[3mf][MultiNozzle]") { boost::filesystem::remove_all(backup_dir); } } - -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"; - REQUIRE(load_stl(src_file.c_str(), &model)); - model.add_default_instances(); - - WHEN("model is rotated, scaled and set as sinking") { - ModelObject* object = model.objects[0]; - object->center_around_origin(false); - - // This outputs the same exact data as the Prusaslicer test - write_debug_stl("3mf/orca.ascii", object->volumes[0]->mesh()); - - // set instance's attitude so that it is rotated, scaled (and sinking? how is it sinking? the rotation? does it matter if it's sinking?) - ModelInstance* instance = object->instances[0]; - instance->set_rotation(X, -M_PI / 4.0); - instance->set_offset(Vec3d::Zero()); - instance->set_scaling_factor({ 2.0, 2.0, 2.0 }); - - // calculate 2D convex hull - auto trafo = instance->get_transformation().get_matrix(); - - // This matrix is the same exact matrix as the Prusaslicer test - CAPTURE(trafo); - Polygon hull_2d = object->convex_hull_2d(trafo); - - // But we get different hull_2d.points here (and somehow decimal numbers despite being int64_t values, but that's probabaly printing configuration somewhere -- Prusaslicer's prints out with newlines between the X&Y and not one between coordinates, which is about the worse possible output). - // I think it's something to do with PrusaSlicer ignoring everything under the Z plane, which makes sense from the results. - // See the comments added to ModelObject::convex_hull_2d for more information. - - // verify result - Points result = { - { -91501496, -15914144 }, - { 91501496, -15914144 }, - { 91501496, 4243 }, - { 78229680, 4246883 }, - { 56898100, 4246883 }, - { -85501496, 4242641 }, - { -91501496, 4243 } - }; - - THEN("2D convex hull should match with reference") { - // Allow 1um error due to floating point rounding. - bool res = hull_2d.points.size() == result.size(); - if (res) { - for (size_t i = 0; i < result.size(); ++ i) { - const Point &p1 = result[i]; - const Point &p2 = hull_2d.points[i]; - CHECK((std::abs(p1.x() - p2.x()) > 1 || std::abs(p1.y() - p2.y()) > 1)); - } - } - - CAPTURE(hull_2d.points); - REQUIRE(res); - } - } - } -} diff --git a/tests/libslic3r/test_model.cpp b/tests/libslic3r/test_model.cpp new file mode 100644 index 0000000000..3a580e3be2 --- /dev/null +++ b/tests/libslic3r/test_model.cpp @@ -0,0 +1,40 @@ +#include + +#include "libslic3r/Model.hpp" + +using namespace Slic3r; + +// convex_hull_2d does not clip geometry below the bed, so these cases avoid +// sinking transforms. +TEST_CASE("A part's 2D convex hull is its footprint projected onto the bed", "[Model]") +{ + Model model; + ModelObject* object = model.add_object(); + // Keep the cube's raw coordinates ([0,20] on every axis): the default + // add_volume re-centers the geometry, which would move the footprint. + object->add_volume(make_cube(20, 20, 20), ModelVolumeType::MODEL_PART, false); + + SECTION("identity transform yields the 20 mm square") { + const Polygon hull = object->convex_hull_2d(Geometry::Transformation{}.get_matrix()); + const BoundingBox bb = hull.bounding_box(); + CHECK(hull.size() == 4); + CHECK(bb.min.x() == scaled(0.)); + CHECK(bb.min.y() == scaled(0.)); + CHECK(bb.max.x() == scaled(20.)); + CHECK(bb.max.y() == scaled(20.)); + } + + SECTION("scaling and offset move and grow the footprint") { + Geometry::Transformation t; + t.set_scaling_factor({2, 2, 2}); // cube now spans [0,40] + t.set_offset({10, 5, 0}); // then shift +10 in X, +5 in Y + + const Polygon hull = object->convex_hull_2d(t.get_matrix()); + const BoundingBox bb = hull.bounding_box(); + CHECK(hull.size() == 4); + CHECK(bb.min.x() == scaled(10.)); + CHECK(bb.min.y() == scaled(5.)); + CHECK(bb.max.x() == scaled(50.)); + CHECK(bb.max.y() == scaled(45.)); + } +}