From 4373bc36978d1ea58829360d7fc85fb89418482a Mon Sep 17 00:00:00 2001 From: Hanif Koh Date: Mon, 14 Sep 2026 13:38:51 +0800 Subject: [PATCH 01/13] Add a Nightly Parity Workflow Runs orca-test-repo's full override-sweep effect stage (two shards) and the GUI-vs-CLI parity harness every night against the latest successful build_all Linux AppImage, with sources checked out at that build's commit. Kept out of the per-build regression step, whose time budget it would exceed, and never gates a build. --- .github/workflows/parity_nightly.yml | 219 +++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 .github/workflows/parity_nightly.yml diff --git a/.github/workflows/parity_nightly.yml b/.github/workflows/parity_nightly.yml new file mode 100644 index 0000000000..79f5c9b514 --- /dev/null +++ b/.github/workflows/parity_nightly.yml @@ -0,0 +1,219 @@ +# Nightly parity checks from OrcaSlicer/orca-test-repo, kept out of the +# per-build "Run external slicer regression tests" step because they take far +# longer than that step's budget: +# effect - the CLI override sweep's full effect stage: every landed option +# re-sliced on its own to see whether it changes the G-code +# harness - the GUI-vs-CLI parity harness (metrics only, never fails) +# Both test the latest successful build_all.yml Linux AppImage from main, with +# sources checked out at the commit that build was made from. Nothing here +# gates a build or a PR. +name: Parity Nightly + +on: + schedule: + # build_all.yml starts at 17:00 UTC and has finished by ~20:00 + - cron: "0 21 * * *" + workflow_dispatch: + inputs: + test_repo_ref: + description: "orca-test-repo ref to run" + required: false + default: "main" + build_branch: + description: "branch whose latest successful build_all artifact to test" + required: false + default: "main" + fixtures: + description: "harness fixture ids, space-separated (empty = all)" + required: false + default: "" + cli_presets: + description: "harness lane C presets: flat = flatten inherits first, raw = leaf profile as-is" + required: false + default: "flat" + +permissions: + contents: read + actions: read + +jobs: + build: + name: Find the build to test + # Don't run scheduled checks on forks + if: github.event_name != 'schedule' || github.repository == 'OrcaSlicer/OrcaSlicer' + runs-on: ubuntu-24.04 + outputs: + run_id: ${{ steps.find.outputs.run_id }} + head_sha: ${{ steps.find.outputs.head_sha }} + steps: + - id: find + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: | + set -euo pipefail + gh run list --workflow build_all.yml \ + --branch "${{ inputs.build_branch || 'main' }}" \ + --status success --limit 1 --json databaseId,headSha \ + --jq '"run_id=\(.[0].databaseId)\nhead_sha=\(.[0].headSha)"' \ + >> "$GITHUB_OUTPUT" + cat "$GITHUB_OUTPUT" + + effect: + name: Override sweep effect stage (shard ${{ matrix.shard }}) + needs: build + runs-on: ubuntu-24.04 + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + # orca-test-repo's parity/effect_routing.json holds a 2-way split, + # ~12.5 min a shard on this runner + shard: [0, 1] + steps: + - &checkout-suite + name: Check out the test suite + uses: actions/checkout@v7 + with: + repository: OrcaSlicer/orca-test-repo + ref: ${{ inputs.test_repo_ref || 'main' }} + path: orca-test-repo + + # The AppImage ships only packed preset caches, so profiles and the CLI + # option surface come from the sources the build was made from + - &checkout-slicer + name: Check out OrcaSlicer at the build's commit + uses: actions/checkout@v7 + with: + ref: ${{ needs.build.outputs.head_sha }} + path: slicer + lfs: 'false' + + - &extract-appimage + name: Download and extract the Linux AppImage + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: | + set -euo pipefail + gh run download "${{ needs.build.outputs.run_id }}" --dir appimage \ + --pattern "OrcaSlicer_Linux_ubuntu_2404*" + appimage=$(find appimage -name "*.AppImage" ! -name "*aarch64*" | head -1) + [ -n "$appimage" ] || { echo "no x86_64 AppImage in run ${{ needs.build.outputs.run_id }}"; exit 1; } + chmod +x "$appimage" + "$appimage" --appimage-extract > /dev/null + # The bare binary cannot find the AppImage's bundled libraries; AppRun + # sets them up and execs it, so exit codes and signals pass through + [ -x squashfs-root/AppRun ] || { echo "no AppRun in the AppImage"; exit 1; } + echo "ORCA_BIN=$PWD/squashfs-root/AppRun" >> "$GITHUB_ENV" + echo "ORCA_SOURCE=$PWD/slicer" >> "$GITHUB_ENV" + + - name: Install the AppImage's host runtime dependencies + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + libopengl0 libglu1-mesa libgl1 libegl1 libwebkit2gtk-4.1-0 + + - uses: actions/setup-python@v6 + with: + python-version: "3.12" + + - name: Install suite dependencies + run: pip install -r orca-test-repo/requirements.txt + + - name: Run the override sweep with the full effect stage + id: run + continue-on-error: true + working-directory: orca-test-repo + run: | + set -o pipefail + # -rA keeps the per-stage summaries, which pytest otherwise swallows + # for passing tests + python -m pytest test_cli_overrides.py -c pytest.ini -v -rA \ + --effect-full --effect-shard ${{ matrix.shard }}/2 \ + --orca-bin "$ORCA_BIN" --orca-source "$ORCA_SOURCE" \ + 2>&1 | tee ../sweep.log + + - name: Publish job summary + if: always() + run: | + { + echo "## Override sweep effect stage, shard ${{ matrix.shard }}/2" + echo "Build ${{ needs.build.outputs.head_sha }} (run ${{ needs.build.outputs.run_id }})" + echo '```' + grep -E "\[override sweep" sweep.log || echo "no stage summaries, see the log" + grep -E "^=+ .*(passed|failed)" sweep.log | tail -1 || true + echo '```' + } >> "$GITHUB_STEP_SUMMARY" + + - name: Upload the override report + if: always() + uses: actions/upload-artifact@v7 + with: + name: override-report-shard${{ matrix.shard }} + path: | + orca-test-repo/.pytest_cache/override_report.json + sweep.log + if-no-files-found: warn + retention-days: 30 + + # The sweep step continues on error so the summary and report still get + # published; this puts the failure back on the job + - name: Fail the job if the sweep failed + if: steps.run.outcome == 'failure' + run: | + echo "the override sweep failed, see the job summary and the uploaded report" >&2 + exit 1 + + harness: + name: GUI-vs-CLI parity harness + needs: build + runs-on: ubuntu-24.04 + timeout-minutes: 180 + steps: + - *checkout-suite + - *checkout-slicer + - *extract-appimage + + - name: Install display tooling and the AppImage's host runtime + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + xvfb xdotool imagemagick openbox mesa-utils \ + libopengl0 libglu1-mesa libgl1 libegl1 libwebkit2gtk-4.1-0 + + - name: Run the parity harness + run: | + set -euo pipefail + fixtures=() + for f in ${{ inputs.fixtures || '' }}; do + fixtures+=(--fixture "$f") + done + # 2 GUI displays: ~1.5 cores peak / ~1.9 GB on this 4-vCPU runner, + # and each fixture is fully isolated, so results match a serial run + python3 orca-test-repo/parity/run_parity.py \ + --slicer-root "$ORCA_SOURCE" --bin "$ORCA_BIN" \ + --cli-presets "${{ inputs.cli_presets || 'flat' }}" \ + --gui-workers 2 --out "$PWD/parity-out" "${fixtures[@]}" + + - name: Publish job summary + if: always() + run: | + if [ -f parity-out/report.md ]; then + cat parity-out/report.md >> "$GITHUB_STEP_SUMMARY" + else + echo "the harness produced no report, see the log" >> "$GITHUB_STEP_SUMMARY" + fi + + - name: Drop per-lane datadirs before upload + if: always() + run: rm -rf parity-out/*/seed parity-out/*/datadir-* || true + + - name: Upload the scorecard and evidence + if: always() + uses: actions/upload-artifact@v7 + with: + name: parity-scorecard + path: parity-out/ + if-no-files-found: warn + retention-days: 30 From ffb4f192c1bcab178e1eb25f74afbb630f0a9c61 Mon Sep 17 00:00:00 2001 From: Lam Wei Lun Date: Mon, 14 Sep 2026 14:19:25 +0800 Subject: [PATCH 02/13] Fix macOS UI issue in publish dialog. Remove item_size helper in TabCtrl and its relevant setter --- src/slic3r/GUI/PublishSettingsDialog.cpp | 3 --- src/slic3r/GUI/Widgets/Button.cpp | 9 ++++++--- src/slic3r/GUI/Widgets/TabCtrl.cpp | 23 +++++++---------------- src/slic3r/GUI/Widgets/TabCtrl.hpp | 5 ----- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/slic3r/GUI/PublishSettingsDialog.cpp b/src/slic3r/GUI/PublishSettingsDialog.cpp index 16b0b6201c..e63cec7615 100644 --- a/src/slic3r/GUI/PublishSettingsDialog.cpp +++ b/src/slic3r/GUI/PublishSettingsDialog.cpp @@ -1037,9 +1037,6 @@ size_t PublishSettingsDialog::section_group_for(Section kind) section.mixed_tabs = new TabCtrl(section.page, wxID_ANY, wxDefaultPosition, wxDefaultSize, s_tab_style); section.mixed_tabs->SetFont(Label::Body_14); section.mixed_tabs->SetBackgroundColour(GetBackgroundColour()); - // The mixed tabs carry full swatch compositions: give them a touch more room than the - // filament tabs so neighbouring compositions stay distinguishable (must precede AppendItem). - section.mixed_tabs->SetItemSpace(FromDIP(3)); page_sizer->Add(section.mixed_tabs, 0, wxEXPAND | wxTOP, FromDIP(2)); section.mixed_tabs->Hide(); } diff --git a/src/slic3r/GUI/Widgets/Button.cpp b/src/slic3r/GUI/Widgets/Button.cpp index 22b1c34cab..5f03636f18 100644 --- a/src/slic3r/GUI/Widgets/Button.cpp +++ b/src/slic3r/GUI/Widgets/Button.cpp @@ -311,8 +311,11 @@ void Button::render(wxDC& dc) } } auto szContent = textSize; + // Whether the measured content reserved the text/icon gap. macOS measures an empty label + // as 0-high, so the gap is skipped there; the dot must not advance past it in that case. + const bool gap_reserved = szContent.y > 0; if (icon.bmp().IsOk()) { - if (szContent.y > 0) { + if (gap_reserved) { //BBS norrow size between text and icon if (vertical) szContent.y += spacing; @@ -357,10 +360,10 @@ void Button::render(wxDC& dc) dc.DrawBitmap(icon.bmp(), pt); //BBS norrow size between text and icon if (vertical) { - pt.y += szIcon.y + spacing; + pt.y += szIcon.y + (gap_reserved ? spacing : 0); pt.x = rcContent.x; } else { - pt.x += szIcon.x + spacing; + pt.x += szIcon.x + (gap_reserved ? spacing : 0); pt.y = rcContent.y; } } diff --git a/src/slic3r/GUI/Widgets/TabCtrl.cpp b/src/slic3r/GUI/Widgets/TabCtrl.cpp index 34de109b8f..ef23e2c5e4 100644 --- a/src/slic3r/GUI/Widgets/TabCtrl.cpp +++ b/src/slic3r/GUI/Widgets/TabCtrl.cpp @@ -99,7 +99,7 @@ int TabCtrl::AppendItem(const wxString& item, int image, int selImage, void* cli btns.push_back(btn); if (btns.size() > 1) sizer->GetItem(sizer->GetItemCount() - 1)->SetMinSize({0, 0}); - sizer->Add(btn, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, item_space); + sizer->Add(btn, 0, wxALIGN_CENTER_VERTICAL); sizer->AddStretchSpacer(1); relayout(); return btns.size() - 1; @@ -256,12 +256,12 @@ void TabCtrl::relayout() int item = sel + 1; int first = 0; for (int i = 0; i < item; ++i) - offset += btns[i]->GetMinSize().x + item_space * 2; + offset += btns[i]->GetMinSize().x; if (item < btns.size()) - offset += btns[item]->GetMinSize().x + item_space * 2; + offset += btns[item]->GetMinSize().x; int width = GetSize().x; for (int i = 0; i < btns.size(); ++i) { - auto size = btns[i]->GetMinSize().x + item_space * 2; + auto size = btns[i]->GetMinSize().x; if (i < sel && offset > width) { sizer->Show(i * 2 + 1, false); sizer->Show(i * 2 + 2, false); @@ -284,26 +284,17 @@ void TabCtrl::relayout() if (item >= btns.size()) --item; // Keep spacing 2 ~ 10 TAB_BUTTON_SPACE - int b = GetSize().x - offset - 10 - (item + 1 - first) * item_space * 8; + int b = GetSize().x - offset - 10 - (item + 1 - first) * 16; sizer->GetItem(item * 2 + 2)->SetMinSize({b > 0 ? b : 0, 0}); Layout(); } -void TabCtrl::SetItemSpace(int space) -{ - if (space < 0 || space == item_space) - return; - item_space = space; - relayout(); - Refresh(); -} - int TabCtrl::GetFullSize() const { - // Mirrors relayout(): a 10px leading spacer plus every button's min width and spacing. + // Mirrors relayout(): a 10px leading spacer plus every button's min width. int width = 10; for (const Button* btn : btns) - width += btn->GetMinSize().x + item_space * 2; + width += btn->GetMinSize().x; return width; } diff --git a/src/slic3r/GUI/Widgets/TabCtrl.hpp b/src/slic3r/GUI/Widgets/TabCtrl.hpp index 493c4edee5..d89da145af 100644 --- a/src/slic3r/GUI/Widgets/TabCtrl.hpp +++ b/src/slic3r/GUI/Widgets/TabCtrl.hpp @@ -14,7 +14,6 @@ class TabCtrl : public StaticBox int sel = -1; wxFont bold; - int item_space = 2; // space around each button, both sides (SetItemSpace) public: TabCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0); @@ -64,10 +63,6 @@ public: int GetNextVisible(int item) const; bool IsVisible(unsigned int item) const; - // Extra space around each tab button (in px on both sides). Defaults to the control-wide - // standard; call before appending items so every button picks it up. - void SetItemSpace(int space); - int GetFullSize() const; private: From 31f6eb2718491ba34272786c826ba577a4410777 Mon Sep 17 00:00:00 2001 From: HanifKoh <76276251+HanifKoh@users.noreply.github.com> Date: Mon, 14 Sep 2026 14:26:32 +0800 Subject: [PATCH 03/13] Keep the First Value When a Per-Filament Variant Option Is Too Short (#15639) update_values_to_printer_extruders_for_multiple_filaments picks each filament's value from the flattened (filament x variant) columns of every per-filament variant option. When a column index fell past the end of the option's values, it skipped that filament and left the zero the output vector was created with. The GUI always hands this function full columns, but the CLI does not: - a CLI override of a single value, such as --nozzle-temperature=211 on a four-filament project, came out as 211,0,0,0, so three filaments would print at 0 C; - loading fewer filament presets than the project has filaments left the remaining filaments' columns missing, so filament_cooling_before_tower came out as 10,10,0,0 and filament_ramming_volumetric_speed as -1,-1,0,0. An out-of-range column now keeps the option's first value, the fallback get_at() and the sibling gather step already use. The seven per-type copies of the loop are replaced by that same gather_option_values helper, moved above the function; it now takes its caller's name for its log lines. An empty option, which has no first value, is given one registered default per filament first; it used to be replaced with zeros. On a partial load a filament whose preset was not loaded takes the first filament's value rather than its own preset's, which the CLI does not load; for the options seen in practice those agree. --- src/libslic3r/PrintConfig.cpp | 215 ++++-------------- .../test_config_variant_expansion.cpp | 28 +++ 2 files changed, 67 insertions(+), 176 deletions(-) diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 4c27995ba0..e8ac749bd3 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -10936,6 +10936,28 @@ std::vector DynamicPrintConfig::update_values_to_printer_extruders(DynamicP return variant_index; } +// Regathers a vector option's values through per-slot source indices (one input index per +// output slot). Out-of-range indices keep the first value, matching get_at's fallback. +template +static void gather_option_values(const char *caller, const std::string &key, OptType *opt, const std::vector &slot_param_indices) +{ + if (!opt || opt->values.empty()) { + BOOST_LOG_TRIVIAL(warning) << caller << boost::format(", Line %1%: option %2% not found or empty, skipping")%__LINE__%key; + return; + } + std::vector new_values; + new_values.reserve(slot_param_indices.size()); + for (int idx : slot_param_indices) { + if (idx < 0 || static_cast(idx) >= opt->values.size()) { + BOOST_LOG_TRIVIAL(warning) << caller << boost::format(", Line %1%: option %2% slot index %3% out of range, keeping first value")%__LINE__%key%idx; + new_values.emplace_back(opt->values.front()); + } + else + new_values.emplace_back(opt->values[idx]); + } + opt->values = std::move(new_values); +} + void DynamicPrintConfig::update_values_to_printer_extruders_for_multiple_filaments(DynamicPrintConfig& printer_config, int extruder_count, int extruder_nozzle_volume_count, std::set& key_set, std::string id_name, std::string variant_name) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: extruder_count %2%, extruder_nozzle_volume_count %3%")%__LINE__ %extruder_count %extruder_nozzle_volume_count; @@ -11013,155 +11035,18 @@ void DynamicPrintConfig::update_values_to_printer_extruders_for_multiple_filamen BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: can not find opt define for %2%")%__LINE__%key; continue; } + // An empty option has no first value to fall back on; give it one registered default per filament. + if (auto *vec = dynamic_cast(this->option(key)); vec && vec->empty() && optdef->default_value) + vec->resize(filament_count, optdef->default_value.get()); switch (optdef->type) { - case coStrings: - { - ConfigOptionStrings * opt = this->option(key); - if (!opt) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% not found, skipping")%__LINE__%key; - break; - } - std::vector new_values; - - new_values.resize(filament_count); - for (int f_index = 0; f_index < filament_count; f_index++) - { - if (variant_index[f_index] < 0 || static_cast(variant_index[f_index]) >= opt->size()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% variant index %3% out of range, skipping")%__LINE__%key%variant_index[f_index]; - continue; - } - new_values[f_index] = opt->get_at(variant_index[f_index]); - } - opt->values = new_values; - break; - } - case coInts: - { - ConfigOptionInts * opt = this->option(key); - if (!opt) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% not found, skipping")%__LINE__%key; - break; - } - std::vector new_values; - - new_values.resize(filament_count); - for (int f_index = 0; f_index < filament_count; f_index++) - { - if (variant_index[f_index] < 0 || static_cast(variant_index[f_index]) >= opt->size()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% variant index %3% out of range, skipping")%__LINE__%key%variant_index[f_index]; - continue; - } - new_values[f_index] = opt->get_at(variant_index[f_index]); - } - opt->values = new_values; - break; - } - case coFloats: - { - ConfigOptionFloats * opt = this->option(key); - if (!opt) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% not found, skipping")%__LINE__%key; - break; - } - std::vector new_values; - - new_values.resize(filament_count); - for (int f_index = 0; f_index < filament_count; f_index++) - { - if (variant_index[f_index] < 0 || static_cast(variant_index[f_index]) >= opt->size()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% variant index %3% out of range, skipping")%__LINE__%key%variant_index[f_index]; - continue; - } - new_values[f_index] = opt->get_at(variant_index[f_index]); - } - opt->values = new_values; - break; - } - case coPercents: - { - ConfigOptionPercents * opt = this->option(key); - if (!opt) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% not found, skipping")%__LINE__%key; - break; - } - std::vector new_values; - - new_values.resize(filament_count); - for (int f_index = 0; f_index < filament_count; f_index++) - { - if (variant_index[f_index] < 0 || static_cast(variant_index[f_index]) >= opt->size()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% variant index %3% out of range, skipping")%__LINE__%key%variant_index[f_index]; - continue; - } - new_values[f_index] = opt->get_at(variant_index[f_index]); - } - opt->values = new_values; - break; - } - case coFloatsOrPercents: - { - ConfigOptionFloatsOrPercents * opt = this->option(key); - if (!opt) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% not found, skipping")%__LINE__%key; - break; - } - std::vector new_values; - - new_values.resize(filament_count); - for (int f_index = 0; f_index < filament_count; f_index++) - { - if (variant_index[f_index] < 0 || static_cast(variant_index[f_index]) >= opt->size()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% variant index %3% out of range, skipping")%__LINE__%key%variant_index[f_index]; - continue; - } - new_values[f_index] = opt->get_at(variant_index[f_index]); - } - opt->values = new_values; - break; - } - case coBools: - { - ConfigOptionBools * opt = this->option(key); - if (!opt) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% not found, skipping")%__LINE__%key; - break; - } - std::vector new_values; - - new_values.resize(filament_count); - for (int f_index = 0; f_index < filament_count; f_index++) - { - if (variant_index[f_index] < 0 || static_cast(variant_index[f_index]) >= opt->size()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% variant index %3% out of range, skipping")%__LINE__%key%variant_index[f_index]; - continue; - } - new_values[f_index] = opt->get_at(variant_index[f_index]); - } - opt->values = new_values; - break; - } - case coEnums: - { - ConfigOptionEnumsGeneric * opt = this->option(key); - if (!opt) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% not found, skipping")%__LINE__%key; - break; - } - std::vector new_values; - - new_values.resize(filament_count); - for (int f_index = 0; f_index < filament_count; f_index++) - { - if (variant_index[f_index] < 0 || static_cast(variant_index[f_index]) >= opt->size()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% variant index %3% out of range, skipping")%__LINE__%key%variant_index[f_index]; - continue; - } - new_values[f_index] = opt->get_at(variant_index[f_index]); - } - opt->values = new_values; - break; - } + case coStrings: gather_option_values(__FUNCTION__, key, this->option(key), variant_index); break; + case coInts: gather_option_values(__FUNCTION__, key, this->option(key), variant_index); break; + case coFloats: gather_option_values(__FUNCTION__, key, this->option(key), variant_index); break; + case coPercents: gather_option_values(__FUNCTION__, key, this->option(key), variant_index); break; + case coFloatsOrPercents: gather_option_values(__FUNCTION__, key, this->option(key), variant_index); break; + case coBools: gather_option_values(__FUNCTION__, key, this->option(key), variant_index); break; + case coEnums: gather_option_values(__FUNCTION__, key, this->option(key), variant_index); break; default: BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: unsupported option type for %2%")%__LINE__%key; break; @@ -11180,28 +11065,6 @@ void DynamicPrintConfig::update_values_to_printer_extruders_for_multiple_filamen } } -// Regathers a vector option's values through per-slot source indices (one input index per -// output slot). Out-of-range indices keep the first value, matching get_at's fallback. -template -static void gather_option_values(const std::string &key, OptType *opt, const std::vector &slot_param_indices) -{ - if (!opt || opt->values.empty()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% not found or empty, skipping")%__LINE__%key; - return; - } - std::vector new_values; - new_values.reserve(slot_param_indices.size()); - for (int idx : slot_param_indices) { - if (idx < 0 || static_cast(idx) >= opt->values.size()) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: option %2% slot index %3% out of range, keeping first value")%__LINE__%key%idx; - new_values.emplace_back(opt->values.front()); - } - else - new_values.emplace_back(opt->values[idx]); - } - opt->values = std::move(new_values); -} - void DynamicPrintConfig::update_filament_config_values_for_multiple_extruders(DynamicPrintConfig& printer_config, const std::unordered_map>& filament_variant_uses, int extruder_count, int extruder_nozzle_volume_count, @@ -11296,13 +11159,13 @@ void DynamicPrintConfig::update_filament_config_values_for_multiple_extruders(Dy continue; } switch (optdef->type) { - case coStrings: gather_option_values(key, this->option(key), slot_param_indices); break; - case coInts: gather_option_values(key, this->option(key), slot_param_indices); break; - case coFloats: gather_option_values(key, this->option(key), slot_param_indices); break; - case coPercents: gather_option_values(key, this->option(key), slot_param_indices); break; - case coFloatsOrPercents: gather_option_values(key, this->option(key), slot_param_indices); break; - case coBools: gather_option_values(key, this->option(key), slot_param_indices); break; - case coEnums: gather_option_values(key, this->option(key), slot_param_indices); break; + case coStrings: gather_option_values(__FUNCTION__, key, this->option(key), slot_param_indices); break; + case coInts: gather_option_values(__FUNCTION__, key, this->option(key), slot_param_indices); break; + case coFloats: gather_option_values(__FUNCTION__, key, this->option(key), slot_param_indices); break; + case coPercents: gather_option_values(__FUNCTION__, key, this->option(key), slot_param_indices); break; + case coFloatsOrPercents: gather_option_values(__FUNCTION__, key, this->option(key), slot_param_indices); break; + case coBools: gather_option_values(__FUNCTION__, key, this->option(key), slot_param_indices); break; + case coEnums: gather_option_values(__FUNCTION__, key, this->option(key), slot_param_indices); break; default: BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: unsupported option type for %2%")%__LINE__%key; break; diff --git a/tests/libslic3r/test_config_variant_expansion.cpp b/tests/libslic3r/test_config_variant_expansion.cpp index 2469789d5b..d8e09539bb 100644 --- a/tests/libslic3r/test_config_variant_expansion.cpp +++ b/tests/libslic3r/test_config_variant_expansion.cpp @@ -484,6 +484,34 @@ TEST_CASE("update_values_to_printer_extruders_for_multiple_filaments resolves pe REQUIRE(config.option("filament_max_volumetric_speed")->values == std::vector({12., 21.})); REQUIRE(config.option("filament_self_index")->values == std::vector({1, 2})); } + + SECTION("a variant option shorter than the filament slots keeps its first value instead of zero") { + DynamicPrintConfig config; + config.option("extruder_type", true)->values = {etDirectDrive, etDirectDrive}; + config.option("nozzle_volume_type", true)->values = {nvtStandard, nvtHighFlow}; + config.option("extruder_variant_list", true)->values = {"Direct Drive Standard,Direct Drive High Flow", + "Direct Drive Standard,Direct Drive High Flow"}; + make_filament_arrays(config); + config.option("filament_map", true)->values = {1, 2}; + // no loaded preset carries the key, so only its single registered default is present + config.option("filament_cooling_before_tower", true)->values = {10.}; + // only the first filament's two variant columns were loaded + config.option("filament_ramming_volumetric_speed", true)->values = {-1., -2.}; + + std::vector> nozzle_volume_types; + int extruder_count = 2; + int count = config.get_extruder_nozzle_volume_count(extruder_count, nozzle_volume_types); + + config.update_values_to_printer_extruders_for_multiple_filaments(config, extruder_count, count, filament_keys, + "filament_self_index", "filament_extruder_variant"); + + // filament 2 resolves to column 3 (its extruder's High Flow column), past the end of both vectors + REQUIRE_THAT(config.option("filament_cooling_before_tower")->values, + Catch::Matchers::Approx(std::vector({10., 10.}))); + REQUIRE_THAT(config.option("filament_ramming_volumetric_speed")->values, + Catch::Matchers::Approx(std::vector({-1., -1.}))); + REQUIRE(config.option("filament_max_volumetric_speed")->values == std::vector({12., 21.})); + } } // update_values_from_multi_to_multi_2 walks the DESTINATION PRINTER's variant list while writing From 00429da73928550a88c5dc73c683a1d8078d61f5 Mon Sep 17 00:00:00 2001 From: HanifKoh <76276251+HanifKoh@users.noreply.github.com> Date: Mon, 14 Sep 2026 14:28:08 +0800 Subject: [PATCH 04/13] Apply the GUI's Mixed Filament Rules on the CLI (#15636) A valid mixed filament already slices the same on the CLI as in the GUI; these are the places where the CLI still skipped a rule the GUI applies. - Keep the prime tower when a mixed filament is used, even if every --load-filaments preset is the same. A mixed filament swaps between its components every layer, so turning the tower off left the swaps with nothing to purge on. - Leave a mixed slot's row and column of the flush matrix at zero when --filament-colour triggers a recompute, as the GUI does; a mixed slot never reaches a nozzle. - Refuse a mixed slot that has no filament of its own. Feature filament ids aimed at it were past the filament count, got reset to filament 1 and the model silently printed in one colour. - Refuse a plate that uses a mixed filament whose components are different filament types, the type half of the GUI's Sidebar::has_broken_mixed_filament. Missing or out-of-range components are already rejected for the whole project by validate(). get_extruders_under_cli gains an expand_mixed_slots flag so the gate can see mixed slots rather than their components; existing callers keep the expanded list. Both refusals exit with the new CLI_MIXED_FILAMENT_INVALID (-69). --- src/OrcaSlicer.cpp | 68 +++++++++++++++++++++++++++++++++++- src/libslic3r/Utils.hpp | 1 + src/slic3r/GUI/PartPlate.cpp | 4 +-- src/slic3r/GUI/PartPlate.hpp | 3 +- 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index 499e73d073..b75c653eda 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -53,6 +53,7 @@ using namespace nlohmann; #include "libslic3r/libslic3r.h" #include "libslic3r/Config.hpp" +#include "libslic3r/FilamentMixer.hpp" #include "libslic3r/Preset.hpp" #include "libslic3r/Geometry.hpp" #include "libslic3r/GCode.hpp" @@ -162,6 +163,7 @@ std::map cli_errors = { {CLI_FILAMENT_CAN_NOT_MAP, "Some filaments cannot be mapped to correct extruders for multi-extruder Printer."}, {CLI_ONLY_ONE_TPU_SUPPORTED, "Not support printing 2 or more TPU filaments."}, {CLI_FILAMENTS_NOT_SUPPORTED_BY_EXTRUDER, "Some filaments cannot be printed on the extruder mapped to."}, + {CLI_MIXED_FILAMENT_INVALID, "A mixed filament is invalid: its components are different filament types, or it has no filament of its own."}, {CLI_SLICING_ERROR, "Failed slicing the model. Please verify the slicing of all plates on Orca Slicer before uploading."}, {CLI_GCODE_PATH_CONFLICTS, " G-code conflicts detected after slicing. Please make sure the 3mf file can be successfully sliced in the latest Orca Slicer. If the file slices normally in Orca Slicer, try moving the wipe tower further from other models, as we use more conservative parameters for it during upload."}, {CLI_GCODE_PATH_IN_UNPRINTABLE_AREA, "Found G-code in unprintable area of multi-extruder printers after slicing. Please make sure the 3mf file can be successfully sliced in the latest Orca Slicer."} @@ -3700,6 +3702,15 @@ int CLI::run(int argc, char **argv) } } + // A mixed slot never reaches a nozzle, so its row and column stay empty, as in the GUI. + // Command line options are not merged into m_print_config yet, so they win here. + const ConfigOptionBools *is_mixed_opt = m_extra_config.option("filament_is_mixed"); + if (!is_mixed_opt) + is_mixed_opt = m_print_config.option("filament_is_mixed"); + auto is_mixed_slot = [is_mixed_opt](int idx) { + return is_mixed_opt && idx < static_cast(is_mixed_opt->values.size()) && is_mixed_opt->values[idx]; + }; + for (size_t nozzle_id = 0; nozzle_id < new_extruder_count; ++nozzle_id) { std::vector flush_vol_mtx = get_flush_volumes_matrix(flush_vol_matrix, nozzle_id, new_extruder_count); for (int from_idx = 0; from_idx < project_filament_count; from_idx++) { @@ -3709,7 +3720,7 @@ int CLI::run(int argc, char **argv) bool is_from_support = filament_is_support->get_at(from_idx); for (int to_idx = 0; to_idx < project_filament_count; to_idx++) { bool is_to_support = filament_is_support->get_at(to_idx); - if (from_idx == to_idx) { + if (from_idx == to_idx || is_mixed_slot(from_idx) || is_mixed_slot(to_idx)) { flush_vol_mtx[project_filament_count * from_idx + to_idx] = 0.f; } else { int flushing_volume = 0; @@ -3937,6 +3948,22 @@ int CLI::run(int argc, char **argv) // Normalizing after importing the 3MFs / AMFs m_print_config.normalize_fdm(); + // A mixed slot is virtual but still needs a filament entry of its own. Without one, feature + // filament ids aimed at it fall outside the filament count, are reset to the first filament + // and the model silently prints in a single colour. + if (const auto *is_mixed_opt = m_print_config.option("filament_is_mixed")) { + const auto &is_mixed = is_mixed_opt->values; + for (size_t slot = static_cast(std::max(filament_count, 0)); slot < is_mixed.size(); ++slot) { + if (!is_mixed[slot]) + continue; + BOOST_LOG_TRIVIAL(error) << boost::format("mixed filament slot %1% has no filament of its own, only %2% filaments are loaded; " + "load one filament per slot, including each mixed one") + % (slot + 1) % filament_count; + record_exit_reson(outfile_dir, CLI_MIXED_FILAMENT_INVALID, 0, cli_errors[CLI_MIXED_FILAMENT_INVALID], sliced_info); + flush_and_exit(CLI_MIXED_FILAMENT_INVALID); + } + } + m_print_config.option>("printer_technology", true)->value = printer_technology; bool has_wipe_tower_position = m_print_config.option("wipe_tower_x") && m_print_config.option("wipe_tower_y"); @@ -3991,6 +4018,15 @@ int CLI::run(int argc, char **argv) bool is_smooth_timelapse = false; if (enable_timelapse && timelapse_type_opt && (timelapse_type_opt->getInt() == TimelapseType::tlSmooth)) is_smooth_timelapse = true; + // A mixed filament swaps between its components every layer, so it needs the tower even when + // every loaded preset is the same. + if (disable_wipe_tower_after_mapping) { + if (const auto *is_mixed_opt = m_print_config.option("filament_is_mixed"); + is_mixed_opt && has_any_mixed_filament(is_mixed_opt->values)) { + disable_wipe_tower_after_mapping = false; + BOOST_LOG_TRIVIAL(info) << boost::format("%1%, set disable_wipe_tower_after_mapping back to false due to a mixed filament")%__LINE__; + } + } if (disable_wipe_tower_after_mapping) { if (is_smooth_timelapse) { @@ -6197,6 +6233,36 @@ int CLI::run(int argc, char **argv) flush_and_exit(CLI_ONLY_ONE_TPU_SUPPORTED); } + // Same type gate as the GUI's Sidebar::has_broken_mixed_filament: refuse a plate that uses a + // mixed slot whose components are different filament types. Missing or out-of-range + // components never get here, validate() already rejects them for the whole project. + const auto *is_mixed_opt = m_print_config.option("filament_is_mixed"); + const auto *components_opt = m_print_config.option("filament_mixed_components"); + if (is_mixed_opt && components_opt && has_any_mixed_filament(is_mixed_opt->values)) { + const auto &is_mixed = is_mixed_opt->values; + const auto &components = components_opt->values; + const size_t num_physical = static_cast(filament_count) - static_cast(std::count(is_mixed.begin(), is_mixed.end(), true)); + std::vector physical_types(num_physical); + for (size_t f_index = 0; f_index < num_physical; ++f_index) { + std::string displayed_type; + physical_types[f_index] = m_print_config.get_filament_type(displayed_type, static_cast(f_index)); + if (physical_types[f_index].empty()) + physical_types[f_index] = "PLA"; + } + const std::vector mismatched_slots = check_mixed_filament_type_consistency(is_mixed, components, physical_types); + // plate_filaments has mixed slots expanded to their components; the gate needs the slots. + const std::vector plate_slots = mismatched_slots.empty() ? std::vector() : + part_plate->get_extruders_under_cli(true, m_print_config, false); + for (size_t slot : mismatched_slots) { + if (std::find(plate_slots.begin(), plate_slots.end(), static_cast(slot) + 1) == plate_slots.end()) + continue; + BOOST_LOG_TRIVIAL(error) << boost::format("plate %1%: mixed filament %2% mixes components of different filament types") + % (index + 1) % (slot + 1); + record_exit_reson(outfile_dir, CLI_MIXED_FILAMENT_INVALID, index + 1, cli_errors[CLI_MIXED_FILAMENT_INVALID], sliced_info); + flush_and_exit(CLI_MIXED_FILAMENT_INVALID); + } + } + if (new_extruder_count > 1) { std::vector> unprintable_filament_vec; for (const std::set& filamnt_ids : unprintable_filament_ids) { diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp index 797894442a..c364860531 100644 --- a/src/libslic3r/Utils.hpp +++ b/src/libslic3r/Utils.hpp @@ -70,6 +70,7 @@ #define CLI_FILAMENT_CAN_NOT_MAP -66 #define CLI_ONLY_ONE_TPU_SUPPORTED -67 #define CLI_FILAMENTS_NOT_SUPPORTED_BY_EXTRUDER -68 +#define CLI_MIXED_FILAMENT_INVALID -69 #define CLI_SLICING_ERROR -100 #define CLI_GCODE_PATH_CONFLICTS -101 diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index c9370cc282..893260f934 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -1717,7 +1717,7 @@ std::vector PartPlate::get_extruders(bool conside_custom_gcode, const Dynam return plate_extruders; } -std::vector PartPlate::get_extruders_under_cli(bool conside_custom_gcode, DynamicPrintConfig& full_config) const +std::vector PartPlate::get_extruders_under_cli(bool conside_custom_gcode, DynamicPrintConfig& full_config, bool expand_mixed_slots) const { std::vector plate_extruders; @@ -1878,7 +1878,7 @@ std::vector PartPlate::get_extruders_under_cli(bool conside_custom_gcode, D // Expand mixed filament slots to their physical components. A mixed slot is virtual and // is never loaded into a tray, so callers (AMS mapping, filament checks) must see the // physical filaments it resolves to instead. - { + if (expand_mixed_slots) { auto* is_mixed_opt = full_config.option("filament_is_mixed"); auto* comp_strs_opt = full_config.option("filament_mixed_components"); if (is_mixed_opt && comp_strs_opt && has_any_mixed_filament(is_mixed_opt->values)) { diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index 6d7eb18beb..e913ebaabf 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -350,7 +350,8 @@ public: // get used filaments from config, 1 based idx std::vector get_extruders(bool conside_custom_gcode = false) const; std::vector get_extruders(bool conside_custom_gcode, const DynamicPrintConfig& glb_config, const DynamicPrintConfig& project_config) const; - std::vector get_extruders_under_cli(bool conside_custom_gcode, DynamicPrintConfig& full_config) const; + // expand_mixed_slots = false keeps mixed filament slots as slots instead of their components. + std::vector get_extruders_under_cli(bool conside_custom_gcode, DynamicPrintConfig& full_config, bool expand_mixed_slots = true) const; std::vector get_extruders_without_support(bool conside_custom_gcode = false) const; // get used filaments from gcode result, 1 based idx std::vector get_used_filaments(); From 5f01f21661d5bd4002a6b261464ec4cd13cb3c7d Mon Sep 17 00:00:00 2001 From: Hanif Koh Date: Mon, 14 Sep 2026 17:44:17 +0800 Subject: [PATCH 05/13] Load Each Vendor Tree Once When the CLI Resolves System Presets Resolving a system preset through its vendor manifest loaded the whole vendor tree and the filament library from JSON, and the CLI did that separately for every --load-settings and --load-filaments file. A run with machine, process and filament presets parsed BBL's 2,879 profile files and the library's 512 three times over, about a second each. Keep the library and vendor bundles loaded by the manifest path on the PresetBundle that resolved them, keyed by source root, vendor and substitution rule, and have the CLI resolve every system preset through one bundle for the whole run. A failed load is not kept, so errors are reported as before. On a cube slice with X1C machine, process and PLA presets: 2.42 s -> 0.93 s, BBL.json opened once instead of three times, identical G-code. --- src/OrcaSlicer.cpp | 10 ++-- src/libslic3r/PresetBundle.cpp | 58 ++++++++++++------- src/libslic3r/PresetBundle.hpp | 14 +++++ .../libslic3r/test_preset_bundle_loading.cpp | 44 ++++++++++++++ 4 files changed, 100 insertions(+), 26 deletions(-) diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index b75c653eda..f2ce73e1f4 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -2010,19 +2010,21 @@ int CLI::run(int argc, char **argv) } }; - auto resolve_preset = [&ensure_cli_preset_bundle](const std::string &file, DynamicPrintConfig &config, + // One resolver for the whole run, so presets from the same vendor tree share its load. + std::unique_ptr system_preset_resolver; + auto resolve_preset = [&ensure_cli_preset_bundle, &system_preset_resolver](const std::string &file, DynamicPrintConfig &config, std::string &config_type, const std::string &config_from, bool probe_type, std::string &error) { const auto *inherits = config.option(BBL_JSON_KEY_INHERITS); if (!probe_type && (inherits == nullptr || inherits->value.empty())) return true; - std::unique_ptr source_bundle; PresetBundle *bundle = nullptr; bool allow_source_manifest = false; if (config_from == "system") { - source_bundle = std::make_unique(); - bundle = source_bundle.get(); + if (!system_preset_resolver) + system_preset_resolver = std::make_unique(); + bundle = system_preset_resolver.get(); allow_source_manifest = true; } else { bundle = ensure_cli_preset_bundle(error); diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 4b8fb03a02..9cef965490 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -549,30 +549,11 @@ bool PresetBundle::resolve_preset_config(DynamicPrintConfig &config, Preset::Typ continue; try { - PresetBundle library_bundle; - const PresetBundle *base_bundle = nullptr; - if (vendor_id != ORCA_FILAMENT_LIBRARY && - boost::filesystem::is_regular_file(root_dir / (std::string(ORCA_FILAMENT_LIBRARY) + ".json"))) { - library_bundle.m_preserve_vendor_source_paths = true; - library_bundle.load_vendor_configs_from_json(root_dir.string(), ORCA_FILAMENT_LIBRARY, LoadSystem, - compatibility_rule, nullptr, false); - if (library_bundle.error_count() != 0) { - error = "OrcaFilamentLibrary contains invalid presets"; - return false; - } - base_bundle = &library_bundle; - } - - PresetBundle source_bundle; - source_bundle.m_preserve_vendor_source_paths = true; - source_bundle.load_vendor_configs_from_json(root_dir.string(), vendor_id, LoadSystem, - compatibility_rule, base_bundle, false); - if (source_bundle.error_count() != 0) { - error = "Vendor bundle contains invalid presets"; + const SourceManifestBundles *loaded = load_source_manifest(root_dir, vendor_id, compatibility_rule, error); + if (loaded == nullptr) return false; - } - const Preset *resolved = find_loaded(source_bundle); + const Preset *resolved = find_loaded(*loaded->vendor); if (resolved == nullptr) { if (error.empty()) error = "Source file is not an instantiated preset in its vendor manifest"; @@ -591,6 +572,39 @@ bool PresetBundle::resolve_preset_config(DynamicPrintConfig &config, Preset::Typ return false; } +const PresetBundle::SourceManifestBundles *PresetBundle::load_source_manifest(const boost::filesystem::path &root_dir, + const std::string &vendor_id, + ForwardCompatibilitySubstitutionRule compatibility_rule, + std::string &error) +{ + auto key = std::make_tuple(root_dir.string(), vendor_id, static_cast(compatibility_rule)); + if (auto it = m_source_manifest_bundles.find(key); it != m_source_manifest_bundles.end()) + return &it->second; + + SourceManifestBundles loaded; + if (vendor_id != ORCA_FILAMENT_LIBRARY && + boost::filesystem::is_regular_file(root_dir / (std::string(ORCA_FILAMENT_LIBRARY) + ".json"))) { + loaded.library = std::make_unique(); + loaded.library->m_preserve_vendor_source_paths = true; + loaded.library->load_vendor_configs_from_json(root_dir.string(), ORCA_FILAMENT_LIBRARY, LoadSystem, + compatibility_rule, nullptr, false); + if (loaded.library->error_count() != 0) { + error = "OrcaFilamentLibrary contains invalid presets"; + return nullptr; + } + } + + loaded.vendor = std::make_unique(); + loaded.vendor->m_preserve_vendor_source_paths = true; + loaded.vendor->load_vendor_configs_from_json(root_dir.string(), vendor_id, LoadSystem, + compatibility_rule, loaded.library.get(), false); + if (loaded.vendor->error_count() != 0) { + error = "Vendor bundle contains invalid presets"; + return nullptr; + } + return &m_source_manifest_bundles.emplace(std::move(key), std::move(loaded)).first->second; +} + bool PresetBundle::resolve_preset_config_type(DynamicPrintConfig &config, Preset::Type &type, const std::string &source_file, ForwardCompatibilitySubstitutionRule compatibility_rule, diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 353b6dc07d..a0fceb332b 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -652,6 +653,19 @@ private: bool m_generate_vendor_caches { false }; bool m_preserve_vendor_source_paths { false }; + // Vendor trees loaded by resolve_preset_config's manifest path, so every preset + // resolved through this bundle shares one load per source root and vendor. + struct SourceManifestBundles { + std::unique_ptr library; + std::unique_ptr vendor; + }; + std::map, SourceManifestBundles> m_source_manifest_bundles; + + const SourceManifestBundles *load_source_manifest(const boost::filesystem::path &root_dir, + const std::string &vendor_id, + ForwardCompatibilitySubstitutionRule compatibility_rule, + std::string &error); + // Orca: validation only - flag any printer with two or more compatible // filament presets sharing one filament_id (ambiguous AMS subtype match). bool check_duplicate_filament_subtypes() const; diff --git a/tests/libslic3r/test_preset_bundle_loading.cpp b/tests/libslic3r/test_preset_bundle_loading.cpp index ecdede7053..5341e6c621 100644 --- a/tests/libslic3r/test_preset_bundle_loading.cpp +++ b/tests/libslic3r/test_preset_bundle_loading.cpp @@ -987,6 +987,50 @@ TEST_CASE("Resolution terminates when no vendor manifest exists", "[Preset][Bund CHECK(error == "Preset was not found in the loaded bundle"); } +TEST_CASE("Manifest-backed resolution reuses the vendor tree it already loaded", "[Preset][Bundle][Regression]") +{ + ScopedTemporaryDir dir; + const fs::path process_dir = dir.path() / "Acme" / "process"; + fs::create_directories(process_dir); + 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 First","sub_path":"process/first.json"},)" + << R"({"name":"Acme Second","sub_path":"process/second.json"}]})"; + auto write_base = [&](double travel_speed) { + std::ofstream((process_dir / "base.json").string()) + << R"({"type":"process","name":"fdm_process_common","from":"system",)" + << R"("instantiation":"false","travel_speed":[")" << travel_speed << R"("]})"; + }; + auto write_child = [&](const std::string &file, const std::string &name) { + std::ofstream((process_dir / file).string()) + << R"({"type":"process","name":")" << name << R"(","from":"system",)" + << R"("instantiation":"true","inherits":"fdm_process_common"})"; + }; + write_base(111.0); + write_child("first.json", "Acme First"); + write_child("second.json", "Acme Second"); + + auto travel_speed = [&](PresetBundle &bundle, const std::string &file) { + DynamicPrintConfig raw; + raw.option(BBL_JSON_KEY_INHERITS, true)->value = "fdm_process_common"; + std::string error; + REQUIRE(bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, (process_dir / file).string(), + ForwardCompatibilitySubstitutionRule::EnableSilent, error)); + return raw.option("travel_speed")->values.front(); + }; + + PresetBundle bundle; + CHECK_THAT(travel_speed(bundle, "first.json"), Catch::Matchers::WithinAbs(111.0, 1e-6)); + + // Only a reload would see this change. + write_base(222.0); + CHECK_THAT(travel_speed(bundle, "second.json"), Catch::Matchers::WithinAbs(111.0, 1e-6)); + + PresetBundle fresh; + CHECK_THAT(travel_speed(fresh, "second.json"), Catch::Matchers::WithinAbs(222.0, 1e-6)); +} + // 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. From d4840901fc2476e6d141ab46da51a8e361705516 Mon Sep 17 00:00:00 2001 From: Hanif Koh Date: Mon, 14 Sep 2026 18:51:48 +0800 Subject: [PATCH 06/13] Test That Failed Vendor Loads Are Not Kept and the Library Base Is Reused Cover the two cache paths the first test left open: a vendor tree that fails to load is retried on the next resolution instead of being served from the cache, and a type-probed filament resolved through resolve_preset_config_type reuses the OrcaFilamentLibrary base already loaded for a sibling. --- .../libslic3r/test_preset_bundle_loading.cpp | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/tests/libslic3r/test_preset_bundle_loading.cpp b/tests/libslic3r/test_preset_bundle_loading.cpp index 5341e6c621..29c38395ac 100644 --- a/tests/libslic3r/test_preset_bundle_loading.cpp +++ b/tests/libslic3r/test_preset_bundle_loading.cpp @@ -1031,6 +1031,93 @@ TEST_CASE("Manifest-backed resolution reuses the vendor tree it already loaded", CHECK_THAT(travel_speed(fresh, "second.json"), Catch::Matchers::WithinAbs(222.0, 1e-6)); } +TEST_CASE("Manifest-backed resolution does not keep a vendor tree that failed to load", "[Preset][Bundle][Regression]") +{ + ScopedTemporaryDir dir; + const fs::path child_file = dir.path() / "Acme" / "process" / "child.json"; + auto write_manifest = [&](const std::string &leading_entry) { + std::ofstream((dir.path() / "Acme.json").string()) + << R"({"version":"1.0.0","name":"Acme","process_list":[)" << leading_entry + << R"({"name":"Acme Process","sub_path":"process/child.json"}]})"; + }; + write_manifest("123,"); + 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"})"; + + PresetBundle bundle; + auto resolve = [&](std::string &error) { + DynamicPrintConfig raw; + raw.option(BBL_JSON_KEY_INHERITS, true)->value = "fdm_process_common"; + return bundle.resolve_preset_config(raw, Preset::TYPE_PRINT, child_file.string(), + ForwardCompatibilitySubstitutionRule::EnableSilent, error); + }; + + std::string error; + CHECK_FALSE(resolve(error)); + CHECK_FALSE(error.empty()); + + write_manifest(""); + error.clear(); + CHECK(resolve(error)); + CHECK(error.empty()); +} + +TEST_CASE("Manifest-backed resolution reuses the library base for type-probed files", "[Preset][Bundle][Regression]") +{ + ScopedTemporaryDir dir; + const fs::path library_pet = dir.path() / PresetBundle::ORCA_FILAMENT_LIBRARY / "filament" / "pet.json"; + const fs::path filament_dir = dir.path() / "Acme" / "filament"; + + 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_pet.parent_path()); + auto write_library_pet = [&](double density) { + std::ofstream(library_pet.string()) + << R"({"type":"filament","name":"fdm_filament_pet","from":"system",)" + << R"("filament_id":"GFL99","instantiation":"false",)" + << R"("filament_type":["PETG"],"filament_density":[")" << density << R"("]})"; + }; + write_library_pet(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/petg.json","filament_id":"GFA00"},)" + << R"({"name":"Acme PETG Matte","sub_path":"filament/petg_matte.json","filament_id":"GFA01"}]})"; + fs::create_directories(filament_dir); + auto write_child = [&](const std::string &file, const std::string &name, const std::string &filament_id) { + std::ofstream((filament_dir / file).string()) + << R"({"type":"filament","name":")" << name << R"(","from":"system",)" + << R"("filament_id":")" << filament_id << R"(","instantiation":"true","inherits":"fdm_filament_pet"})"; + }; + write_child("petg.json", "Acme PETG", "GFA00"); + write_child("petg_matte.json", "Acme PETG Matte", "GFA01"); + + auto density = [](const DynamicPrintConfig &config) { + return config.option("filament_density")->values.front(); + }; + + PresetBundle bundle; + DynamicPrintConfig first; + first.option(BBL_JSON_KEY_INHERITS, true)->value = "fdm_filament_pet"; + std::string error; + REQUIRE(bundle.resolve_preset_config(first, Preset::TYPE_FILAMENT, (filament_dir / "petg.json").string(), + ForwardCompatibilitySubstitutionRule::EnableSilent, error)); + CHECK_THAT(density(first), Catch::Matchers::WithinAbs(1.27, 1e-6)); + + // Only a reload would see this change. + write_library_pet(1.5); + + DynamicPrintConfig second; + Preset::Type type = Preset::TYPE_INVALID; + REQUIRE(bundle.resolve_preset_config_type(second, type, (filament_dir / "petg_matte.json").string(), + ForwardCompatibilitySubstitutionRule::EnableSilent, error)); + CHECK(type == Preset::TYPE_FILAMENT); + CHECK_THAT(density(second), Catch::Matchers::WithinAbs(1.27, 1e-6)); +} + // 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. From 70247ad298a1087c5d507b27a9f0e95f6c236b09 Mon Sep 17 00:00:00 2001 From: Daniel Williams <35799546+danielwoz@users.noreply.github.com> Date: Mon, 14 Sep 2026 20:37:04 +0800 Subject: [PATCH 07/13] Extract Layer::choose_ironing_extruder for unit-testable ironing routing (#13467) * Extract Layer::choose_ironing_extruder for unit-testable ironing routing The ironing extruder selection in make_ironing() was a 5-line nested conditional inlined at the top of the loop, with no isolated test coverage. Pull the gating into a static helper so the routing decision is unit-testable without spinning up the slicing pipeline. Pure refactor: the helper preserves the original logic bit-for-bit (NoIroning -> -1; AllSolid always enabled; TopSurfaces and TopmostOnly require some top shells or, in spiral mode, more than one bottom shell; TopmostOnly additionally requires being on the topmost layer; enabled ironing routes to solid_infill_filament). Add tests/fff_print/test_choose_ironing_extruder.cpp covering: - AllSolid regardless of layer position - TopSurfaces with top_shell_layers > 0 - TopSurfaces with top_shell_layers=0 + spiral mode + bottom_shell_layers>1 - TopmostOnly + topmost layer - NoIroning short-circuit - TopSurfaces with top_shell_layers=0 (and not spiral) -> disabled - TopSurfaces, spiral, but bottom_shell_layers=1 -> disabled - TopmostOnly on a non-topmost layer -> disabled * Move ironing routing test into the Fill subsystem file Rename the test to tests/libslic3r/test_fill.cpp and tag it [Fill] to match the subsystem it covers, use flat behavioral test cases with GENERATE for the parameterized ones, and drop the history narration from the code comments. * tests: move ironing routing tests into fff_print/test_fill.cpp Keeps the Fill tests in one file, alongside the existing ironing rotation-template test. --- src/libslic3r/Fill/Fill.cpp | 36 ++++++++++++------- src/libslic3r/Layer.hpp | 6 ++++ tests/fff_print/test_fill.cpp | 68 +++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/Fill/Fill.cpp b/src/libslic3r/Fill/Fill.cpp index f5386b085c..28fabed8af 100644 --- a/src/libslic3r/Fill/Fill.cpp +++ b/src/libslic3r/Fill/Fill.cpp @@ -1595,6 +1595,25 @@ Polylines Layer::generate_sparse_infill_polylines_for_anchoring(FillAdaptive::Oc return sparse_infill_polylines; } +// Returns the filament id (1-based) the region is ironed with, or -1 when the +// region is not ironed. AllSolid always irons. TopSurfaces and TopmostOnly need +// either some top shells or, in spiral mode, more than one bottom shell, and +// TopmostOnly additionally needs the layer to be the topmost one. +int Layer::choose_ironing_extruder(const PrintRegionConfig &cfg, + bool spiral_mode, + bool is_topmost_layer) +{ + if (cfg.ironing_type == IroningType::NoIroning) + return -1; + const bool gate = (cfg.ironing_type == IroningType::AllSolid) + || ((cfg.top_shell_layers > 0 || (spiral_mode && cfg.bottom_shell_layers > 1)) + && (cfg.ironing_type == IroningType::TopSurfaces + || (cfg.ironing_type == IroningType::TopmostOnly && is_topmost_layer))); + if (!gate) + return -1; + return cfg.top_surface_filament_id; +} + // Create ironing extrusions over top surfaces. void Layer::make_ironing() { @@ -1664,19 +1683,10 @@ void Layer::make_ironing() if (! layerm->slices.empty()) { IroningParams ironing_params; const PrintRegionConfig &config = layerm->region().config(); - if (config.ironing_type != IroningType::NoIroning && - (config.ironing_type == IroningType::AllSolid || - ((config.top_shell_layers > 0 || (this->object()->print()->config().spiral_mode && config.bottom_shell_layers > 1)) && - (config.ironing_type == IroningType::TopSurfaces || - (config.ironing_type == IroningType::TopmostOnly && layerm->layer()->upper_layer == nullptr))))) { - if (config.outer_wall_filament_id == config.top_surface_filament_id || config.wall_loops == 0) { - // Iron the whole face. - ironing_params.extruder = config.top_surface_filament_id; - } else { - // Iron just the infill. - ironing_params.extruder = config.top_surface_filament_id; - } - } + ironing_params.extruder = Layer::choose_ironing_extruder( + config, + /*spiral_mode=*/this->object()->print()->config().spiral_mode, + /*is_topmost_layer=*/layerm->layer()->upper_layer == nullptr); if (ironing_params.extruder != -1) { //TODO just_infill is currently not used. ironing_params.just_infill = false; diff --git a/src/libslic3r/Layer.hpp b/src/libslic3r/Layer.hpp index 8a5aa78036..9be6b86139 100644 --- a/src/libslic3r/Layer.hpp +++ b/src/libslic3r/Layer.hpp @@ -16,6 +16,7 @@ using LayerPtrs = std::vector; class LayerRegion; using LayerRegionPtrs = std::vector; class PrintRegion; +class PrintRegionConfig; class PrintObject; class Print; @@ -200,6 +201,11 @@ public: FillAdaptive::Octree *support_fill_octree, FillLightning::Generator* lightning_generator) const; void make_ironing(); + // Returns the filament id (1-based) the region is ironed with, or -1 when the + // region is not ironed. + static int choose_ironing_extruder(const PrintRegionConfig &cfg, + bool spiral_mode, + bool is_topmost_layer); void make_contour_z(const sla::IndexedMesh &mesh); void export_region_slices_to_svg(const char *path) const; diff --git a/tests/fff_print/test_fill.cpp b/tests/fff_print/test_fill.cpp index aa81570e56..a3696c47ad 100644 --- a/tests/fff_print/test_fill.cpp +++ b/tests/fff_print/test_fill.cpp @@ -15,6 +15,7 @@ #include "libslic3r/Geometry.hpp" #include "libslic3r/Layer.hpp" #include "libslic3r/Print.hpp" +#include "libslic3r/PrintConfig.hpp" #include "libslic3r/SVG.hpp" #include "libslic3r/libslic3r.h" @@ -676,6 +677,73 @@ TEST_CASE("Ironing follows the solid infill rotation template", "[Fill]") REQUIRE(compared > int(ironing.size()) / 2); } + +namespace { + +PrintRegionConfig ironing_config(IroningType type, + int top_surface_filament_id = 1, + int top_shell_layers = 3, + int bottom_shell_layers = 1) +{ + PrintRegionConfig cfg; + cfg.ironing_type.value = type; + cfg.top_surface_filament_id.value = top_surface_filament_id; + cfg.top_shell_layers.value = top_shell_layers; + cfg.bottom_shell_layers.value = bottom_shell_layers; + cfg.outer_wall_filament_id.value = 1; + cfg.wall_loops.value = 2; + return cfg; +} + +} // namespace + +TEST_CASE("Ironing an all-solid region uses the top surface filament on every layer", "[Fill]") +{ + const PrintRegionConfig cfg = ironing_config(IroningType::AllSolid, /*top_surface_filament_id=*/2); + const bool is_topmost_layer = GENERATE(false, true); + CAPTURE(is_topmost_layer); + REQUIRE(Layer::choose_ironing_extruder(cfg, /*spiral_mode=*/false, is_topmost_layer) == 2); +} + +TEST_CASE("Ironing top surfaces uses the top surface filament when the region has top shells", "[Fill]") +{ + const PrintRegionConfig cfg = ironing_config(IroningType::TopSurfaces, + /*top_surface_filament_id=*/3, + /*top_shell_layers=*/2); + REQUIRE(Layer::choose_ironing_extruder(cfg, /*spiral_mode=*/false, /*is_topmost_layer=*/false) == 3); +} + +TEST_CASE("Ironing top surfaces without top shells needs spiral mode and more than one bottom shell", "[Fill]") +{ + const PrintRegionConfig one_bottom_shell = ironing_config(IroningType::TopSurfaces, + /*top_surface_filament_id=*/1, + /*top_shell_layers=*/0, + /*bottom_shell_layers=*/1); + const PrintRegionConfig two_bottom_shells = ironing_config(IroningType::TopSurfaces, + /*top_surface_filament_id=*/1, + /*top_shell_layers=*/0, + /*bottom_shell_layers=*/2); + + REQUIRE(Layer::choose_ironing_extruder(two_bottom_shells, /*spiral_mode=*/true, /*is_topmost_layer=*/false) == 1); + REQUIRE(Layer::choose_ironing_extruder(one_bottom_shell, /*spiral_mode=*/true, /*is_topmost_layer=*/false) == -1); + REQUIRE(Layer::choose_ironing_extruder(two_bottom_shells, /*spiral_mode=*/false, /*is_topmost_layer=*/false) == -1); +} + +TEST_CASE("Ironing the topmost surface only applies to the topmost layer", "[Fill]") +{ + const PrintRegionConfig cfg = ironing_config(IroningType::TopmostOnly, /*top_surface_filament_id=*/4); + REQUIRE(Layer::choose_ironing_extruder(cfg, /*spiral_mode=*/false, /*is_topmost_layer=*/true) == 4); + REQUIRE(Layer::choose_ironing_extruder(cfg, /*spiral_mode=*/false, /*is_topmost_layer=*/false) == -1); +} + +TEST_CASE("A region with ironing turned off is never ironed", "[Fill]") +{ + const PrintRegionConfig cfg = ironing_config(IroningType::NoIroning); + const bool spiral_mode = GENERATE(false, true); + CAPTURE(spiral_mode); + REQUIRE(Layer::choose_ironing_extruder(cfg, spiral_mode, /*is_topmost_layer=*/true) == -1); +} + TEST_CASE("Solid infill direction offsets every layer when no template is set", "[Fill]") { auto angles_for = [](int direction) { From 31eb8a2bd1f402da52b4b81af82ef436b2a83705 Mon Sep 17 00:00:00 2001 From: packerlschupfer <83344883+packerlschupfer@users.noreply.github.com> Date: Mon, 14 Sep 2026 19:35:29 +0200 Subject: [PATCH 08/13] CLI: let --export-settings - write the merged config to stdout --export-settings already writes the merged config as JSON at the right point in the CLI flow. Passing - writes the same document to stdout. - ConfigBase::save_to_json gains a stream overload. The file overload serializes through it before opening the file, so the format is unchanged and a config that cannot be serialized leaves an existing file untouched instead of truncating it. - On stdout, invalid UTF-8 in string values is written as U+FFFD instead of ending the process with an uncaught type_error; files keep the strict behaviour. - - is rejected up front when combined with an action or transform that can write to stdout or does real work, so stdout carries only the JSON. - The unconditional "skip locked instance" stdout write during arrange now goes to the log. - Tests in tests/libslic3r/test_config.cpp. --- src/OrcaSlicer.cpp | 27 ++++++++++++++-- src/libslic3r/Config.cpp | 21 +++++++++---- src/libslic3r/Config.hpp | 3 ++ src/libslic3r/PrintConfig.cpp | 2 +- tests/libslic3r/test_config.cpp | 55 +++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 9 deletions(-) diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index b75c653eda..07009ef46a 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -1387,6 +1387,25 @@ int CLI::run(int argc, char **argv) if (downward_check_option) downward_check = downward_check_option->value; + // --export-settings - writes its JSON to stdout, so reject every action or transform that may write there + // too (--info, --help, --orient, slicing and exporting). The allowed ones do nothing when nothing is + // sliced or exported. + if (std::find(m_actions.begin(), m_actions.end(), "export_settings") != m_actions.end() && m_config.opt_string("export_settings") == "-") { + static const std::set stdout_compatible = { "export_settings", "uptodate", "load_defaultfila", "min_save", + "mtcpp", "mstpp", "no_check", "normative_check", "pipe" }; + for (const std::vector *opt_keys : { &m_actions, &m_transforms }) { + for (const std::string &opt_key : *opt_keys) { + if (stdout_compatible.count(opt_key) == 0) { + std::string flag = opt_key; + std::replace(flag.begin(), flag.end(), '_', '-'); + boost::nowide::cerr << "--export-settings - cannot be combined with --" << flag << std::endl; + record_exit_reson(outfile_dir, CLI_INVALID_PARAMS, 0, cli_errors[CLI_INVALID_PARAMS], sliced_info); + flush_and_exit(CLI_INVALID_PARAMS); + } + } + } + } + bool start_gui = m_actions.empty() && !downward_check; if (start_gui) { BOOST_LOG_TRIVIAL(info) << "no action, start gui directly" << std::endl; @@ -5348,7 +5367,7 @@ int CLI::run(int argc, char **argv) //skip this object due to be locked in plate ap.itemid = locked_aps.size(); locked_aps.emplace_back(ap); - boost::nowide::cout <<__FUNCTION__ << boost::format(": skip locked instance, obj_id %1%, instance_id %2%") % oidx % inst_idx; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": skip locked instance, obj_id %1%, instance_id %2%") % oidx % inst_idx; } } } @@ -5937,7 +5956,11 @@ int CLI::run(int argc, char **argv) //FIXME check for mixing the FFF / SLA parameters. // or better save fff_print_config vs. sla_print_config //m_print_config.save(m_config.opt_string("save")); - m_print_config.save_to_json(m_config.opt_string(opt_key), std::string("project_settings"), std::string("project"), std::string(SoftFever_VERSION)); + const std::string &settings_file = m_config.opt_string(opt_key); + if (settings_file == "-") + m_print_config.save_to_json(boost::nowide::cout, "project_settings", "project", SoftFever_VERSION, /*replace_invalid_utf8=*/true); + else + m_print_config.save_to_json(settings_file, std::string("project_settings"), std::string("project"), std::string(SoftFever_VERSION)); } else if (opt_key == "info") { // --info works on unrepaired model for (Model &model : m_models) { diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index 394cfb5b74..52a46dcacf 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -1515,6 +1516,19 @@ std::optional parse_capability_ref(const std::string& value //BBS: add json support void ConfigBase::save_to_json(const std::string &file, const std::string &name, const std::string &from, const std::string &version) const +{ + // Serialize first: if that throws (invalid UTF-8), the existing file stays untouched. + std::ostringstream ss; + this->save_to_json(ss, name, from, version); + boost::nowide::ofstream c; + c.open(file, std::ios::out | std::ios::trunc); + c << ss.str(); + c.close(); + + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" <<__LINE__ << boost::format(", saved config to %1%\n")%file; +} + +void ConfigBase::save_to_json(std::ostream &os, const std::string &name, const std::string &from, const std::string &version, bool replace_invalid_utf8) const { json j; //record the headers @@ -1561,12 +1575,7 @@ void ConfigBase::save_to_json(const std::string &file, const std::string &name, j["plugins"] = unique_refs; } - boost::nowide::ofstream c; - c.open(file, std::ios::out | std::ios::trunc); - c << j.dump(1, '\t') << std::endl; - c.close(); - - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" <<__LINE__ << boost::format(", saved config to %1%\n")%file; + os << j.dump(1, '\t', false, replace_invalid_utf8 ? json::error_handler_t::replace : json::error_handler_t::strict) << std::endl; } void ConfigBase::save(const std::string &file) const diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index ea85cda1e7..6d23ec3770 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -2825,6 +2825,9 @@ public: //BBS: add json support void save_to_json(const std::string &file, const std::string &name, const std::string &from, const std::string &version) const; + // Same document, written to a stream. Invalid UTF-8 in a string value throws nlohmann's type_error unless + // replace_invalid_utf8 is set, which writes U+FFFD instead (for callers such as stdout with no handler). + void save_to_json(std::ostream &os, const std::string &name, const std::string &from, const std::string &version, bool replace_invalid_utf8 = false) const; // Rebuild the in-memory "plugins" manifest (the "name;uuid;capability" references the plugin // dispatchers consume) from the plugin-backed options via the registered resolver. save_to_json() diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index e8ac749bd3..0b0fe71dc0 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -11916,7 +11916,7 @@ CLIActionsConfigDef::CLIActionsConfigDef() def = this->add("export_settings", coString); def->label = L("Export Settings"); - def->tooltip = L("This exports settings to a file."); + def->tooltip = L("This exports settings to a file. Use - to write them to stdout."); def->cli_params = "settings.json"; def->set_default_value(new ConfigOptionString("output.json")); diff --git a/tests/libslic3r/test_config.cpp b/tests/libslic3r/test_config.cpp index 3813e2df3f..208bbc6cf0 100644 --- a/tests/libslic3r/test_config.cpp +++ b/tests/libslic3r/test_config.cpp @@ -15,6 +15,8 @@ #include #include +#include + using namespace Slic3r; SCENARIO("Generic config validation performs as expected.", "[Config]") { @@ -488,6 +490,59 @@ TEST_CASE("save_to_json round-trips plugin capability references as strings", "[ CHECK(reloaded.option("slicing_pipeline_plugin")->values == refs); } +TEST_CASE("save_to_json writes the same document to a stream as to a file", "[Config]") { + DynamicPrintConfig config; + config.set_key_value("layer_height", new ConfigOptionFloat(0.2)); + config.set_key_value("wall_loops", new ConfigOptionInt(3)); + config.set_key_value("filament_type", new ConfigOptionStrings({ "PLA", "PETG" })); + config.set_key_value("machine_start_gcode", new ConfigOptionString("G28\nG1 Z5")); + + ScopedTemporaryFile tmp(".json"); + config.save_to_json(tmp.string(), "test_preset", "User", "1.0.0.0"); + std::string file_contents; + { + boost::nowide::ifstream ifs(tmp.string()); + file_contents.assign(std::istreambuf_iterator(ifs), std::istreambuf_iterator()); + } + // The file format: one tab per nesting level and a trailing newline. + REQUIRE_FALSE(file_contents.empty()); + CHECK(file_contents.rfind("{\n\t\"", 0) == 0); + CHECK(file_contents.back() == '\n'); + + std::ostringstream strict, replaced; + config.save_to_json(strict, "test_preset", "User", "1.0.0.0"); + config.save_to_json(replaced, "test_preset", "User", "1.0.0.0", true); + CHECK(strict.str() == file_contents); + CHECK(replaced.str() == file_contents); + CHECK(nlohmann::json::parse(strict.str())["machine_start_gcode"] == "G28\nG1 Z5"); +} + +TEST_CASE("save_to_json replaces invalid UTF-8 in a stream only when asked", "[Config]") { + DynamicPrintConfig config; + config.set_key_value("machine_start_gcode", new ConfigOptionString("G28 ; \xff")); + + std::ostringstream strict, replaced; + CHECK_THROWS_AS(config.save_to_json(strict, "test_preset", "User", "1.0.0.0"), nlohmann::json::type_error); + REQUIRE_NOTHROW(config.save_to_json(replaced, "test_preset", "User", "1.0.0.0", true)); + CHECK(nlohmann::json::parse(replaced.str())["machine_start_gcode"] == "G28 ; \xEF\xBF\xBD"); +} + +TEST_CASE("save_to_json leaves an existing file untouched when the config cannot be serialized", "[Config]") { + DynamicPrintConfig config; + config.set_key_value("machine_start_gcode", new ConfigOptionString("G28 ; \xff")); + + ScopedTemporaryFile tmp(".json"); + { + boost::nowide::ofstream ofs(tmp.string()); + ofs << "previous"; + } + CHECK_THROWS_AS(config.save_to_json(tmp.string(), "test_preset", "User", "1.0.0.0"), nlohmann::json::type_error); + + boost::nowide::ifstream ifs(tmp.string()); + const std::string contents((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); + CHECK(contents == "previous"); +} + TEST_CASE("plugin capability references survive string-map serialization", "[Config][plugins]") { const std::vector refs = { "master_plugin;;header-stamp", From 54968834932950f67596e70f64845c1a72ed252c Mon Sep 17 00:00:00 2001 From: Nopraz <12595433+Nopraz@users.noreply.github.com> Date: Mon, 14 Sep 2026 19:44:15 +0200 Subject: [PATCH 09/13] =?UTF-8?q?fix(profiles):=20Snapmaker=20U1=20?= =?UTF-8?q?=E2=80=94=20cap=20ABS/ASA/PPS=20bed=20temps=20at=20100=20=C2=B0?= =?UTF-8?q?C=20(#15483)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The U1's heated bed tops out at 100 °C, but these profiles requested 105-110 °C, which leads to print errors unless the user modifies the printer's firmware configuration. Affected profiles: - Snapmaker ABS @U1 base (110/105 → 100) - Snapmaker ASA @U1 base (110 → 100) - Fiberon ASA-CF08 @Snapmaker U1 base (105 → 100) - Fiberon PPS-GF20 @Snapmaker U1 base (105 → 100) Bumps Snapmaker.json to 02.04.00.10. Co-authored-by: yw4z --- resources/profiles/Snapmaker.json | 2 +- .../Fiberon ASA-CF08 @Snapmaker U1 base.json | 10 +++++----- .../Fiberon PPS-GF20 @Snapmaker U1 base.json | 16 ++++++++-------- .../filament/Snapmaker ABS @U1 base.json | 4 ++-- .../filament/Snapmaker ASA @U1 base.json | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/resources/profiles/Snapmaker.json b/resources/profiles/Snapmaker.json index 0407dca2ec..393271d0e5 100644 --- a/resources/profiles/Snapmaker.json +++ b/resources/profiles/Snapmaker.json @@ -1,6 +1,6 @@ { "name": "Snapmaker", - "version": "02.04.00.12", + "version": "02.04.00.13", "force_update": "0", "description": "Snapmaker configurations", "machine_model_list": [ diff --git a/resources/profiles/Snapmaker/filament/Polymaker/Fiberon ASA-CF08 @Snapmaker U1 base.json b/resources/profiles/Snapmaker/filament/Polymaker/Fiberon ASA-CF08 @Snapmaker U1 base.json index 693553bdcb..86648d6096 100644 --- a/resources/profiles/Snapmaker/filament/Polymaker/Fiberon ASA-CF08 @Snapmaker U1 base.json +++ b/resources/profiles/Snapmaker/filament/Polymaker/Fiberon ASA-CF08 @Snapmaker U1 base.json @@ -15,13 +15,13 @@ "1" ], "cool_plate_temp": [ - "105" + "100" ], "cool_plate_temp_initial_layer": [ - "105" + "100" ], "eng_plate_temp": [ - "105" + "100" ], "eng_plate_temp_initial_layer": [ "100" @@ -48,7 +48,7 @@ "Polymaker" ], "hot_plate_temp": [ - "105" + "100" ], "hot_plate_temp_initial_layer": [ "100" @@ -72,7 +72,7 @@ "110.8" ], "textured_plate_temp": [ - "105" + "100" ], "textured_plate_temp_initial_layer": [ "100" diff --git a/resources/profiles/Snapmaker/filament/Polymaker/Fiberon PPS-GF20 @Snapmaker U1 base.json b/resources/profiles/Snapmaker/filament/Polymaker/Fiberon PPS-GF20 @Snapmaker U1 base.json index 5e1cfa7c61..ee28c2b059 100644 --- a/resources/profiles/Snapmaker/filament/Polymaker/Fiberon PPS-GF20 @Snapmaker U1 base.json +++ b/resources/profiles/Snapmaker/filament/Polymaker/Fiberon PPS-GF20 @Snapmaker U1 base.json @@ -15,16 +15,16 @@ "1" ], "cool_plate_temp": [ - "105" + "100" ], "cool_plate_temp_initial_layer": [ - "105" + "100" ], "eng_plate_temp": [ - "105" + "100" ], "eng_plate_temp_initial_layer": [ - "105" + "100" ], "fan_cooling_layer_time": [ "12" @@ -51,10 +51,10 @@ "Polymaker" ], "hot_plate_temp": [ - "105" + "100" ], "hot_plate_temp_initial_layer": [ - "105" + "100" ], "nozzle_temperature": [ "300" @@ -81,10 +81,10 @@ "110" ], "textured_plate_temp": [ - "105" + "100" ], "textured_plate_temp_initial_layer": [ - "105" + "100" ], "filament_type": [ "ABS" diff --git a/resources/profiles/Snapmaker/filament/Snapmaker ABS @U1 base.json b/resources/profiles/Snapmaker/filament/Snapmaker ABS @U1 base.json index 67754ade09..48740f94bc 100644 --- a/resources/profiles/Snapmaker/filament/Snapmaker ABS @U1 base.json +++ b/resources/profiles/Snapmaker/filament/Snapmaker ABS @U1 base.json @@ -9,10 +9,10 @@ "" ], "hot_plate_temp": [ - "110" + "100" ], "hot_plate_temp_initial_layer": [ - "105" + "100" ], "overhang_fan_speed": [ "20" diff --git a/resources/profiles/Snapmaker/filament/Snapmaker ASA @U1 base.json b/resources/profiles/Snapmaker/filament/Snapmaker ASA @U1 base.json index 413c14cebb..b75f8d84d3 100644 --- a/resources/profiles/Snapmaker/filament/Snapmaker ASA @U1 base.json +++ b/resources/profiles/Snapmaker/filament/Snapmaker ASA @U1 base.json @@ -9,7 +9,7 @@ "" ], "hot_plate_temp": [ - "110" + "100" ], "hot_plate_temp_initial_layer": [ "100" From 5c635d5e504c5f88d45ff7f0d66b63a83382d0bc Mon Sep 17 00:00:00 2001 From: Kris Austin Date: Mon, 14 Sep 2026 15:04:03 -0500 Subject: [PATCH 10/13] build: scope -Werror to the Clang family so GCC builds again (#15701) --- CMakeLists.txt | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2880a7d4b..6e713d8c88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -587,10 +587,15 @@ if ((NOT MSVC OR IS_CLANG_CL) AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR add_compile_options(-Wno-${w}) endforeach () - # Turn everything else into an error. Dependency headers are exempt because the SYSTEM - # include flag (-imsvc on clang-cl, -isystem elsewhere) keeps their diagnostics out, - # apart from GCC's maybe-uninitialized, demoted below. - add_compile_options(-Werror) + # GCC is not built in CI, so don't throw errors CI won't catch. + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_compile_options(-Werror=return-type) + else () + # Turn everything else into an error. Dependency headers are exempt because the + # SYSTEM include flag (-imsvc on clang-cl, -isystem elsewhere) keeps their + # diagnostics out. + add_compile_options(-Werror) + endif () # Demoted. Remove a name once its category is cleared on every compiler. set(warnings_demoted) @@ -612,20 +617,6 @@ if ((NOT MSVC OR IS_CLANG_CL) AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR cast-function-type-mismatch ) endif () - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - list(APPEND warnings_demoted - # maybe-uninitialized runs after inlining and reports inside boost/variant, - # boost/tuple and the bundled clipper header even with -isystem. - maybe-uninitialized - - # array-bounds is reported once, where ConfigOptionVector::set_at inlines - # into OrcaSlicer.cpp on a branch the preceding type test rules out. - array-bounds - - # template-id-cdtor is a GCC 14+ warning in the bundled Clipper2 headers. - template-id-cdtor - ) - endif () if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") list(APPEND warnings_demoted # enum-constexpr-conversion is a Clang warning that defaults to an error, From 292cf0095e698a6e0f96041bd142fd41afd6ccfb Mon Sep 17 00:00:00 2001 From: Kris Austin Date: Mon, 14 Sep 2026 16:31:23 -0500 Subject: [PATCH 11/13] drop the per-frame mouse raycast that only a drag start reads (#15664) --- src/slic3r/GUI/GLCanvas3D.cpp | 11 +++-------- src/slic3r/GUI/GLCanvas3D.hpp | 1 - 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index e63501eec1..76192491bf 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2098,12 +2098,6 @@ void GLCanvas3D::render(bool only_init) _render_selection_center(); #endif // ENABLE_RENDER_SELECTION_CENTER - // we need to set the mouse's scene position here because the depth buffer - // could be invalidated by the following gizmo render methods - // this position is used later into on_mouse() to drag the objects - if (m_picking_enabled) - m_mouse.scene_position = _mouse_to_3d(m_mouse.position.cast()); - // sidebar hints need to be rendered before the gizmos because the depth buffer // could be invalidated by the following gizmo render methods _render_selection_sidebar_hints(); @@ -4491,12 +4485,13 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) BoundingBoxf3 volume_bbox = m_volumes.volumes[volume_idx]->transformed_bounding_box(); volume_bbox.offset(1.0); const bool is_cut_connector_selected = m_selection.is_any_connector(); - if ((!any_gizmo_active || !evt.CmdDown()) && volume_bbox.contains(m_mouse.scene_position) && !is_cut_connector_selected) { + const Vec3d scene_position = _mouse_to_3d(pos); + if ((!any_gizmo_active || !evt.CmdDown()) && volume_bbox.contains(scene_position) && !is_cut_connector_selected) { m_volumes.volumes[volume_idx]->hover = GLVolume::HS_None; // The dragging operation is initiated. m_mouse.drag.move_volume_idx = volume_idx; m_selection.setup_cache(); - m_mouse.drag.start_position_3D = m_mouse.scene_position; + m_mouse.drag.start_position_3D = scene_position; m_sequential_print_clearance_first_displacement = true; m_moving = true; diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index b1dd674d96..c2962c3858 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -337,7 +337,6 @@ class GLCanvas3D bool dragging{ false }; Vec2d position{ DBL_MAX, DBL_MAX }; - Vec3d scene_position{ DBL_MAX, DBL_MAX, DBL_MAX }; bool ignore_left_up{ false }; Drag drag; bool ignore_right_up; From efc9f253ee2d3e16cfb95331ea5234d2b237dca1 Mon Sep 17 00:00:00 2001 From: Kris Austin Date: Mon, 14 Sep 2026 23:47:01 -0500 Subject: [PATCH 12/13] fix: resolve relative input paths given on the command line (#14803) Opening a model with a relative path, for example `orca-slicer ./some.3mf`, failed with "Loading of a model file failed." and "The file does not contain any geometry data.", while the same file opened by an absolute path or by drag and drop worked. GUI_App::init_app_config() changes the working directory to /log, and it runs from the GUI_App constructor because the app config is needed early for instance checking. The input files are opened much later, in post_init(), so a path still relative at that point resolved against the log directory instead of the directory OrcaSlicer was started from, and the 3MF reader failed to open it. Resolve the input paths in CLI::setup(), which runs before GUI_App is constructed and therefore before the working directory moves. Absolute paths are returned unchanged, so the forms that open today are unaffected, and custom open protocol URLs are passed through since post_init() hands those to the downloader rather than the file loader. The working directory change is left alone. It was added in #3248 so the TUTK logs land in the data directory instead of the working directory (#3209). --- src/OrcaSlicer.cpp | 7 ++++ src/libslic3r/Utils.hpp | 3 ++ src/libslic3r/utils.cpp | 13 +++++++ tests/libslic3r/test_utils.cpp | 64 ++++++++++++++++++++++++++++++++++ tests/test_utils.hpp | 18 ++++++++++ 5 files changed, 105 insertions(+) diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index b75c653eda..24f218caa5 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -7715,6 +7715,13 @@ bool CLI::setup(int argc, char **argv) this->print_help(); return false; } + + // Orca: resolve here, while the process is still in the directory the user invoked it from. + // GUI_App's constructor moves the working directory to /log, long before the GUI + // opens these files in post_init(), and a relative path would then resolve against that. + for (std::string &input_file : m_input_files) + input_file = resolve_cli_input_path(input_file); + // Parse actions and transform options. for (auto const &opt_key : opt_order) { if (cli_actions_config_def.has(opt_key)) diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp index c364860531..b21da72fc8 100644 --- a/src/libslic3r/Utils.hpp +++ b/src/libslic3r/Utils.hpp @@ -314,6 +314,9 @@ extern unsigned get_current_pid(); std::string per_user_temp_id(); // Per-user temp root under `base`; an empty `user_id` returns `base` unchanged. std::string per_user_temp_dir(const std::string &base, const std::string &user_id); +// Completes a relative command line input path against the current working directory. Absolute +// paths and custom open protocol URLs are returned unchanged. +std::string resolve_cli_input_path(const std::string &path); // BBS: backup & restore std::string get_process_name(int pid); diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp index 58323b29ce..9def5dad17 100644 --- a/src/libslic3r/utils.cpp +++ b/src/libslic3r/utils.cpp @@ -1339,6 +1339,19 @@ std::string per_user_temp_dir(const std::string &base, const std::string &user_i return base + "/orcaslicer_" + user_id; } +std::string resolve_cli_input_path(const std::string &path) +{ + const boost::filesystem::path input(path); + if (path.empty() || is_supported_open_protocol(path) || input.is_absolute()) + return path; + + boost::system::error_code ec; + const boost::filesystem::path resolved = boost::filesystem::system_complete(input, ec); + if (ec) + return path; + return resolved.lexically_normal().make_preferred().string(); +} + // BBS: backup & restore std::string get_process_name(int pid) { diff --git a/tests/libslic3r/test_utils.cpp b/tests/libslic3r/test_utils.cpp index 484438127c..7880b783f1 100644 --- a/tests/libslic3r/test_utils.cpp +++ b/tests/libslic3r/test_utils.cpp @@ -4,6 +4,8 @@ #include "test_utils.hpp" +#include + #include #include #include @@ -88,3 +90,65 @@ TEST_CASE("copy_file reports the OS error when the destination cannot be written REQUIRE(std::all_of(code.begin(), code.end(), [](unsigned char c) { return std::isdigit(c) != 0; })); #endif // _WIN32 } + +TEST_CASE("A resolved input path still names the same file after the working directory changes", "[utils]") { + ScopedTemporaryFile model(".3mf"); + { std::ofstream out(model.string()); out << "3mf"; } + const std::string name = model.path().filename().string(); + + // Resolve the bare name from the directory holding the file, then move away from it. The guard + // restores the directory the test started in, wherever this leaves it. + ScopedWorkingDirectory cwd(model.path().parent_path()); + const std::string resolved = resolve_cli_input_path(name); + boost::filesystem::current_path(boost::filesystem::path(TEST_DATA_DIR)); + + REQUIRE(boost::filesystem::exists(resolved)); + REQUIRE(boost::filesystem::equivalent(resolved, model.path())); + // Control: the bare name finds nothing from here, so resolving it this late would have failed. + REQUIRE_FALSE(boost::filesystem::exists(name)); +} + +TEST_CASE("resolve_cli_input_path completes a relative path against the working directory", "[utils]") { + ScopedWorkingDirectory cwd(boost::filesystem::temp_directory_path()); + // Read back rather than reusing temp_directory_path(): changing to it resolves any symlink. + const boost::filesystem::path here = boost::filesystem::current_path(); + + SECTION("a bare name") { + REQUIRE(resolve_cli_input_path("model.3mf") == (here / "model.3mf").make_preferred().string()); + } + SECTION("a ./ prefix is dropped") { + REQUIRE(resolve_cli_input_path("./model.3mf") == (here / "model.3mf").make_preferred().string()); + } + SECTION("a ../ traversal is collapsed") { + REQUIRE(resolve_cli_input_path("../model.3mf") == (here.parent_path() / "model.3mf").make_preferred().string()); + } +} + +TEST_CASE("resolve_cli_input_path leaves inputs that must not be completed unchanged", "[utils]") { + SECTION("an absolute path") { + const boost::filesystem::path absolute = (boost::filesystem::temp_directory_path() / "model.3mf").make_preferred(); + REQUIRE(resolve_cli_input_path(absolute.string()) == absolute.string()); + } +#ifdef _WIN32 + // Every absolute form Windows accepts opens today, so each must come back byte for byte: + // normalizing them would rewrite the forward slashes and rebuild the \\?\ and UNC prefixes. + SECTION("an absolute Windows path of any form") { + for (const std::string absolute : {R"(C:\models\model.3mf)", + R"(C:/models/model.3mf)", + R"(\\server\share\model.3mf)", + R"(\\?\C:\models\model.3mf)"}) + REQUIRE(resolve_cli_input_path(absolute) == absolute); + } +#endif + // These are downloaded rather than opened, and completing one would produce a path, not a URL. + SECTION("a custom open protocol URL") { + for (const std::string url : {"orcaslicer://open/?file=https://example.com/model.3mf", + "prusaslicer://open/?file=https://example.com/model.3mf", + "bambustudio://open/?file=https://example.com/model.3mf", + "cura://open/?file=https://example.com/model.3mf"}) + REQUIRE(resolve_cli_input_path(url) == url); + } + SECTION("an empty argument") { + REQUIRE(resolve_cli_input_path("").empty()); + } +} diff --git a/tests/test_utils.hpp b/tests/test_utils.hpp index e3fbbe8fab..0b04e6ad11 100644 --- a/tests/test_utils.hpp +++ b/tests/test_utils.hpp @@ -176,4 +176,22 @@ inline void write_debug_stream([[maybe_unused]] const std::string &name, [[maybe #endif } +// Changes the working directory and restores the previous one on scope exit, including when an +// assertion throws. It is process wide state shared with every other test. +class ScopedWorkingDirectory +{ +public: + explicit ScopedWorkingDirectory(const boost::filesystem::path &dir) + : m_previous(boost::filesystem::current_path()) + { + boost::filesystem::current_path(dir); + } + ~ScopedWorkingDirectory() { boost::system::error_code ec; boost::filesystem::current_path(m_previous, ec); } + ScopedWorkingDirectory(const ScopedWorkingDirectory &) = delete; + ScopedWorkingDirectory &operator=(const ScopedWorkingDirectory &) = delete; + +private: + boost::filesystem::path m_previous; +}; + #endif // SLIC3R_TEST_UTILS From d5cf1502c442b0b4860dedfa0b6d791d243f4299 Mon Sep 17 00:00:00 2001 From: Hanif Koh Date: Tue, 15 Sep 2026 13:31:30 +0800 Subject: [PATCH 13/13] Share One Library Load Between Vendors in the CLI Preset Resolver The manifest resolver loaded OrcaFilamentLibrary once per vendor it resolved through, so a run that mixes vendors parsed the library tree again for each of them. The library is now cached like any other vendor tree, keyed on its root and substitution rule, and doubles as the base every vendor under that root loads against. A vendor bundle only reads from its base while loading, so sharing the instance is safe. The cache key carries the substitution rule as its enum, and the lookup lambdas take a const bundle since they only read. --- src/libslic3r/PresetBundle.cpp | 48 ++++++++-------- src/libslic3r/PresetBundle.hpp | 18 +++--- .../libslic3r/test_preset_bundle_loading.cpp | 56 +++++++++++++++++++ 3 files changed, 87 insertions(+), 35 deletions(-) diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 9cef965490..54e5db27e4 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -484,7 +484,7 @@ bool PresetBundle::resolve_preset_config(DynamicPrintConfig &config, Preset::Typ else if (compatibility_rule == ForwardCompatibilitySubstitutionRule::EnableSilentDisableSystem) compatibility_rule = ForwardCompatibilitySubstitutionRule::Disable; - auto collection_for_type = [](PresetBundle &bundle, Preset::Type preset_type) -> PresetCollection * { + auto collection_for_type = [](const PresetBundle &bundle, Preset::Type preset_type) -> const PresetCollection * { switch (preset_type) { case Preset::TYPE_PRINT: return &bundle.prints; case Preset::TYPE_FILAMENT: return &bundle.filaments; @@ -493,15 +493,15 @@ bool PresetBundle::resolve_preset_config(DynamicPrintConfig &config, Preset::Typ } }; - PresetCollection *collection = collection_for_type(*this, type); + const PresetCollection *collection = collection_for_type(*this, type); if (collection == nullptr) { error = "Unsupported preset type"; return false; } const boost::filesystem::path source_path = boost::filesystem::absolute(source_file).lexically_normal(); - auto find_loaded = [&](PresetBundle &bundle) -> const Preset * { - PresetCollection *loaded_collection = collection_for_type(bundle, type); + auto find_loaded = [&](const PresetBundle &bundle) -> const Preset * { + const PresetCollection *loaded_collection = collection_for_type(bundle, type); const Preset *resolved = nullptr; for (const Preset &preset : loaded_collection->get_presets()) { if (preset.file.empty()) @@ -549,11 +549,11 @@ bool PresetBundle::resolve_preset_config(DynamicPrintConfig &config, Preset::Typ continue; try { - const SourceManifestBundles *loaded = load_source_manifest(root_dir, vendor_id, compatibility_rule, error); + const PresetBundle *loaded = load_source_vendor(root_dir, vendor_id, compatibility_rule, error); if (loaded == nullptr) return false; - const Preset *resolved = find_loaded(*loaded->vendor); + const Preset *resolved = find_loaded(*loaded); if (resolved == nullptr) { if (error.empty()) error = "Source file is not an instantiated preset in its vendor manifest"; @@ -572,37 +572,35 @@ bool PresetBundle::resolve_preset_config(DynamicPrintConfig &config, Preset::Typ return false; } -const PresetBundle::SourceManifestBundles *PresetBundle::load_source_manifest(const boost::filesystem::path &root_dir, - const std::string &vendor_id, - ForwardCompatibilitySubstitutionRule compatibility_rule, - std::string &error) +const PresetBundle *PresetBundle::load_source_vendor(const boost::filesystem::path &root_dir, + const std::string &vendor_id, + ForwardCompatibilitySubstitutionRule compatibility_rule, + std::string &error) { - auto key = std::make_tuple(root_dir.string(), vendor_id, static_cast(compatibility_rule)); - if (auto it = m_source_manifest_bundles.find(key); it != m_source_manifest_bundles.end()) - return &it->second; + auto key = std::make_tuple(root_dir.string(), vendor_id, compatibility_rule); + if (auto it = m_source_vendor_bundles.find(key); it != m_source_vendor_bundles.end()) + return it->second.get(); - SourceManifestBundles loaded; + // The library loads with no base of its own, so the tree a vendor inherits from + // is the same one that resolves the library's own presets. + const PresetBundle *library = nullptr; if (vendor_id != ORCA_FILAMENT_LIBRARY && boost::filesystem::is_regular_file(root_dir / (std::string(ORCA_FILAMENT_LIBRARY) + ".json"))) { - loaded.library = std::make_unique(); - loaded.library->m_preserve_vendor_source_paths = true; - loaded.library->load_vendor_configs_from_json(root_dir.string(), ORCA_FILAMENT_LIBRARY, LoadSystem, - compatibility_rule, nullptr, false); - if (loaded.library->error_count() != 0) { + library = load_source_vendor(root_dir, ORCA_FILAMENT_LIBRARY, compatibility_rule, error); + if (library == nullptr) { error = "OrcaFilamentLibrary contains invalid presets"; return nullptr; } } - loaded.vendor = std::make_unique(); - loaded.vendor->m_preserve_vendor_source_paths = true; - loaded.vendor->load_vendor_configs_from_json(root_dir.string(), vendor_id, LoadSystem, - compatibility_rule, loaded.library.get(), false); - if (loaded.vendor->error_count() != 0) { + auto bundle = std::make_unique(); + bundle->m_preserve_vendor_source_paths = true; + bundle->load_vendor_configs_from_json(root_dir.string(), vendor_id, LoadSystem, compatibility_rule, library, false); + if (bundle->error_count() != 0) { error = "Vendor bundle contains invalid presets"; return nullptr; } - return &m_source_manifest_bundles.emplace(std::move(key), std::move(loaded)).first->second; + return m_source_vendor_bundles.emplace(std::move(key), std::move(bundle)).first->second.get(); } bool PresetBundle::resolve_preset_config_type(DynamicPrintConfig &config, Preset::Type &type, diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index a0fceb332b..88455fabf3 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -654,17 +654,15 @@ private: bool m_preserve_vendor_source_paths { false }; // Vendor trees loaded by resolve_preset_config's manifest path, so every preset - // resolved through this bundle shares one load per source root and vendor. - struct SourceManifestBundles { - std::unique_ptr library; - std::unique_ptr vendor; - }; - std::map, SourceManifestBundles> m_source_manifest_bundles; + // resolved through this bundle shares one load per source root and vendor. The + // filament library is one such tree, shared by every vendor under its root. + std::map, std::unique_ptr> + m_source_vendor_bundles; - const SourceManifestBundles *load_source_manifest(const boost::filesystem::path &root_dir, - const std::string &vendor_id, - ForwardCompatibilitySubstitutionRule compatibility_rule, - std::string &error); + const PresetBundle *load_source_vendor(const boost::filesystem::path &root_dir, + const std::string &vendor_id, + ForwardCompatibilitySubstitutionRule compatibility_rule, + std::string &error); // Orca: validation only - flag any printer with two or more compatible // filament presets sharing one filament_id (ambiguous AMS subtype match). diff --git a/tests/libslic3r/test_preset_bundle_loading.cpp b/tests/libslic3r/test_preset_bundle_loading.cpp index 29c38395ac..73d244cf42 100644 --- a/tests/libslic3r/test_preset_bundle_loading.cpp +++ b/tests/libslic3r/test_preset_bundle_loading.cpp @@ -1118,6 +1118,62 @@ TEST_CASE("Manifest-backed resolution reuses the library base for type-probed fi CHECK_THAT(density(second), Catch::Matchers::WithinAbs(1.27, 1e-6)); } +TEST_CASE("Manifest-backed resolution shares the library between vendors under one root", "[Preset][Bundle][Regression]") +{ + ScopedTemporaryDir dir; + const fs::path library_dir = dir.path() / PresetBundle::ORCA_FILAMENT_LIBRARY / "filament"; + + 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"},)" + << R"({"name":"Generic PETG","sub_path":"filament/generic_petg.json","filament_id":"GFL98"}]})"; + fs::create_directories(library_dir); + auto write_library_pet = [&](double density) { + std::ofstream((library_dir / "pet.json").string()) + << R"({"type":"filament","name":"fdm_filament_pet","from":"system",)" + << R"("filament_id":"GFL99","instantiation":"false",)" + << R"("filament_type":["PETG"],"filament_density":[")" << density << R"("]})"; + }; + write_library_pet(1.27); + std::ofstream((library_dir / "generic_petg.json").string()) + << R"({"type":"filament","name":"Generic PETG","from":"system",)" + << R"("filament_id":"GFL98","instantiation":"true","inherits":"fdm_filament_pet"})"; + + auto write_vendor = [&](const std::string &vendor, const std::string &filament_id) { + const fs::path filament_dir = dir.path() / vendor / "filament"; + fs::create_directories(filament_dir); + std::ofstream((dir.path() / (vendor + ".json")).string()) + << R"({"version":"1.0.0","name":")" << vendor << R"(","filament_list":[)" + << R"({"name":")" << vendor << R"( PETG","sub_path":"filament/petg.json","filament_id":")" << filament_id << R"("}]})"; + std::ofstream((filament_dir / "petg.json").string()) + << R"({"type":"filament","name":")" << vendor << R"( PETG","from":"system",)" + << R"("filament_id":")" << filament_id << R"(","instantiation":"true","inherits":"fdm_filament_pet"})"; + return filament_dir / "petg.json"; + }; + const fs::path acme_petg = write_vendor("Acme", "GFA00"); + const fs::path beta_petg = write_vendor("Beta", "GFB00"); + + auto density = [&](PresetBundle &bundle, const fs::path &file) { + DynamicPrintConfig raw; + raw.option(BBL_JSON_KEY_INHERITS, true)->value = "fdm_filament_pet"; + std::string error; + REQUIRE(bundle.resolve_preset_config(raw, Preset::TYPE_FILAMENT, file.string(), + ForwardCompatibilitySubstitutionRule::EnableSilent, error)); + return raw.option("filament_density")->values.front(); + }; + + PresetBundle bundle; + CHECK_THAT(density(bundle, acme_petg), Catch::Matchers::WithinAbs(1.27, 1e-6)); + + // Only a reload would see this change. + write_library_pet(1.5); + CHECK_THAT(density(bundle, beta_petg), Catch::Matchers::WithinAbs(1.27, 1e-6)); + CHECK_THAT(density(bundle, library_dir / "generic_petg.json"), Catch::Matchers::WithinAbs(1.27, 1e-6)); + + PresetBundle fresh; + CHECK_THAT(density(fresh, beta_petg), Catch::Matchers::WithinAbs(1.5, 1e-6)); +} + // 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.