From b3d7a732c585d400d5314472a3ddaba332689100 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Wed, 3 Jun 2026 19:55:46 +0800 Subject: [PATCH] feat(automation): add open_files to backend interface + kErrLoadFailed (1007) --- src/slic3r/GUI/Automation/IUiBackend.hpp | 6 ++++++ src/slic3r/GUI/Automation/JsonRpcDispatcher.hpp | 1 + tests/automation/MockUiBackend.hpp | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/slic3r/GUI/Automation/IUiBackend.hpp b/src/slic3r/GUI/Automation/IUiBackend.hpp index 27ff9501eb..85db9abaef 100644 --- a/src/slic3r/GUI/Automation/IUiBackend.hpp +++ b/src/slic3r/GUI/Automation/IUiBackend.hpp @@ -95,6 +95,12 @@ public: // Screenshot. target == nullptr => main frame. Captured from the on-screen // composited framebuffer, so it includes the GL viewport and ImGui overlays. virtual PngImage screenshot_window(const UiNode* target) = 0; + + // Load one or more files (absolute paths) into the running instance on the GUI + // thread. Returns the number of objects added to the scene (load_files(...).size()). + // Throws AutomationError(kErrLoadFailed) when nothing loads. Header stays wx-free: + // the concrete LoadStrategy is chosen inside WxUiBackend, not exposed here. + virtual int open_files(const std::vector& paths) = 0; }; }}} // namespace Slic3r::GUI::Automation diff --git a/src/slic3r/GUI/Automation/JsonRpcDispatcher.hpp b/src/slic3r/GUI/Automation/JsonRpcDispatcher.hpp index d95b5c6b6a..401df06d72 100644 --- a/src/slic3r/GUI/Automation/JsonRpcDispatcher.hpp +++ b/src/slic3r/GUI/Automation/JsonRpcDispatcher.hpp @@ -17,6 +17,7 @@ constexpr int kErrWaitTimeout = 1003; constexpr int kErrGuiBusy = 1004; // GUI thread timeout constexpr int kErrScreenshotFail = 1005; constexpr int kErrDisabled = 1006; +constexpr int kErrLoadFailed = 1007; // file.open: load_files returned empty / threw constexpr const char* kProtocolVersion = "2.0"; constexpr const char* kAutomationVersion = "1.0.0"; diff --git a/tests/automation/MockUiBackend.hpp b/tests/automation/MockUiBackend.hpp index edf9408011..8485281e15 100644 --- a/tests/automation/MockUiBackend.hpp +++ b/tests/automation/MockUiBackend.hpp @@ -1,5 +1,6 @@ #pragma once #include "slic3r/GUI/Automation/IUiBackend.hpp" +#include "slic3r/GUI/Automation/JsonRpcDispatcher.hpp" // kErrLoadFailed #include #include @@ -18,12 +19,15 @@ public: std::vector typed_text; std::vector> sent_keys; int screenshot_window_count = 0; + std::vector> opened_paths; // paths of each open_files() // Canned outputs (set by tests). UiNode tree; // default tree for dump_tree AppState state; PngImage canned_png{ {0x89,0x50,0x4E,0x47}, 4, 4 }; // fake "PNG" bytes bool click_result = true; + int open_return_count = 0; // value open_files() returns + bool open_should_fail = false; // when true, open_files() throws kErrLoadFailed // Optional: per-call tree provider (overrides `tree` when set). std::function tree_provider; @@ -49,6 +53,12 @@ public: PngImage screenshot_window(const UiNode*) override { ++screenshot_window_count; return canned_png; } + int open_files(const std::vector& paths) override { + opened_paths.push_back(paths); + if (open_should_fail) + throw AutomationError(kErrLoadFailed, "mock load failed"); + return open_return_count; + } }; }}} // namespace