mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-26 23:29:14 +00:00
Fix MCP menu paths, CAD-off replies, test-instance sign-in, Preview focus and clang-tidy on macOS
This commit is contained in:
parent
69cd4ff3cd
commit
72dc14c9d6
24 changed files with 260 additions and 49 deletions
10
.clang-tidy
10
.clang-tidy
|
|
@ -18,7 +18,8 @@ CheckOptions:
|
|||
# Headers that declare a symbol but are not the one to include: per-platform
|
||||
# implementations of wxWidgets and Boost.Thread (a Linux run would suggest the
|
||||
# GTK or pthread one), library internals and forward declarations (MSVC's STL
|
||||
# __msvc_* and the Windows UCRT's corecrt_* included), CPython's headers behind
|
||||
# __msvc_*, the Windows UCRT's corecrt_*, libc++'s __*/ directories and the
|
||||
# macOS SDK's _*.h behind its C headers included), CPython's headers behind
|
||||
# Python.h (python3.x/ on Linux and macOS, libpython/include/ on Windows),
|
||||
# curl's behind curl.h, oneTBB's behind tbb/, and
|
||||
# admesh's stl.h, which the include path also exposes without its directory.
|
||||
|
|
@ -31,7 +32,8 @@ CheckOptions:
|
|||
# The boost/process headers are only included through Utils/BoostProcessCompat.hpp.
|
||||
# FFmpeg's C headers are left alone because they are only included inside
|
||||
# extern "C", which an inserted include would miss. OS-specific headers (GLib,
|
||||
# GTK, D-Bus, POSIX, the Windows SDK) are only used inside platform #if blocks,
|
||||
# GTK, D-Bus, POSIX, the Windows SDK, the macOS SDK's frameworks and MacTypes.h)
|
||||
# are only used inside platform #if blocks,
|
||||
# and an include added at the top of the file would break the other platforms'
|
||||
# builds. A symbol these provide is not reported missing.
|
||||
# Write every / as [/\\] so the patterns also match Windows paths.
|
||||
|
|
@ -46,6 +48,8 @@ CheckOptions:
|
|||
bits[/\\].*;
|
||||
corecrt_.*\.h;
|
||||
__msvc_.*\.hpp;
|
||||
__[a-z0-9_]+[/\\].*;
|
||||
[/\\]_[A-Za-z0-9_]+\.h;
|
||||
boost[/\\]multiprecision[/\\]fwd\.hpp;
|
||||
imconfig\.h;
|
||||
expat_external\.h;
|
||||
|
|
@ -68,6 +72,8 @@ CheckOptions:
|
|||
termios\.h;
|
||||
[/\\](um|shared)[/\\].*;
|
||||
sal\.h;
|
||||
\.framework[/\\].*;
|
||||
MacTypes\.h;
|
||||
tchar\.h;
|
||||
clipper[/\\]clipper\.hpp;
|
||||
png(lib)?conf\.h;
|
||||
|
|
|
|||
|
|
@ -796,7 +796,12 @@ append_shortcut_item(export_menu, Shortcut::ExportSlicedFile, true, _L("Export p
|
|||
NULL" (`:3438-3445`). `wxEVT_CHILD_FOCUS` derives from `wxCommandEvent` and propagates, and its
|
||||
window is the *direct* child (`:3453-3491`).
|
||||
- `wxPanel::SetFocus` focuses the first child if "the control has at least one child";
|
||||
`SetFocusIgnoringChildren()` focuses the panel itself (`interface/wx/panel.h:125-142`).
|
||||
`SetFocusIgnoringChildren()` focuses the panel itself (`interface/wx/panel.h:125-142`). **[source]**
|
||||
Not while the focus is on the panel or inside it: `wxControlContainerBase::DoSetFocus()` returns at
|
||||
once when `FindFocus()` or one of its parents below the top-level window is the panel, so a panel that
|
||||
holds the focus itself keeps it (`src/common/containr.cpp:110-149`). Otherwise it focuses the child
|
||||
that had the focus last, if it is still shown, else the first child that `CanAcceptFocusFromKeyboard()`
|
||||
(`:605-700`).
|
||||
- `wxGetActiveWindow()` "always returns NULL in the other ports", i.e. on everything but MSW and GTK
|
||||
(`interface/wx/window.h:4545-4551`).
|
||||
|
||||
|
|
@ -811,6 +816,10 @@ append_shortcut_item(export_menu, Shortcut::ExportSlicedFile, true, _L("Export p
|
|||
`MSWEnableHWND`). Any `WM_SETFOCUS`, `WM_KILLFOCUS` or button-down in a window outside
|
||||
`wxCurrentPopupWindow` dismisses a transient popup that lacks `wxPU_CONTAINS_CONTROLS`
|
||||
(`src/msw/window.cpp:3018-3033` → `MSWDismissUnfocusedPopup`, `src/msw/popupwin.cpp:218-229`).
|
||||
- **macOS:** hiding a window that holds the focus moves it to the next view AppKit can focus, which can
|
||||
be a `wxPanel` just shown beside it rather than that panel's control; a `SetFocus()` on that panel then
|
||||
leaves the focus on the panel (see Contract). Seen in `Plater::priv::set_current_panel` on a switch from
|
||||
Prepare to Preview.
|
||||
- **Modeless windows:** focus requested right after `Show()` can be dropped while activation is still
|
||||
in flight (Orca comment in `SpeedDialWebDialog`'s ctor). Set it from `CallAfter` or on
|
||||
`wxEVT_ACTIVATE` (`SpeedDialWebDialog`'s activate handler, see `references/popups-menus.md`); the
|
||||
|
|
@ -846,6 +855,14 @@ append_shortcut_item(export_menu, Shortcut::ExportSlicedFile, true, _L("Export p
|
|||
e.Skip(); });
|
||||
```
|
||||
Cite: `GLCanvas3D::on_mouse`.
|
||||
- **Rule:** To give a view the keyboard, focus its control, not the panel that holds it.
|
||||
**Why:** a panel that holds the focus itself keeps it, and on macOS that is where hiding a focused
|
||||
sibling leaves it, so the view's keys wait until the pointer enters it.
|
||||
```cpp
|
||||
// Wrong: current_panel->SetFocusFromKbd();
|
||||
// Right: get_current_canvas3D()->force_set_focus(); // the shown view's canvas
|
||||
```
|
||||
Cite: `Plater::priv::set_current_panel`.
|
||||
- **Rule:** Defer focus changes out of `wxEVT_KILL_FOCUS`, and always `Skip()` focus events.
|
||||
```cpp
|
||||
// Wrong: ctrl->Bind(wxEVT_KILL_FOCUS, [=](wxFocusEvent&) { other->SetFocus(); });
|
||||
|
|
|
|||
|
|
@ -1242,6 +1242,10 @@ macOS. On MSW it breaks `wxTopLevelWindowMSW::OnActivate`'s focus restore in the
|
|||
- `append_shortcut_item` records the item in `m_shortcut_menu_items`, and `update_shortcut_labels()` rewrites the
|
||||
labels with `SetItemLabel` after the user rebinds a key. Menu text for a registry shortcut always goes through
|
||||
these helpers, never through a hard-coded `"\tCtrl+X"`.
|
||||
- `GetItemLabelText()` drops a key after `"\t"` but keeps one after `" - "`, so on macOS it returns the label with
|
||||
the key text. `MainFrame::menu_item_label()` gives a menu bar item's label without it, from the label the item was
|
||||
made with: the MCP server names menu items by it, so a menu path is the same on every platform. A menu bar item
|
||||
that writes a fixed key after `sep` itself, outside these helpers, records its plain label in `m_key_text_items`.
|
||||
|
||||
**`Plater::PopupMenu(menu, pos)`** (`Plater.cpp`).
|
||||
- It calls `wxGetApp().mainframe->PopupMenu(menu, pos)`. The invoking window is MainFrame, so **`pos` is in
|
||||
|
|
|
|||
|
|
@ -405,7 +405,8 @@ arguments instead of driving the widgets.
|
|||
An agent's call needs the MCP server on (`--mcp`, or Preferences), and every command, a person's tile
|
||||
included, needs the CAD feature on (Preferences > Features). The catalog holds them only when the feature
|
||||
is on at startup, as the main window makes the Design page only then, so turning it on takes a restart;
|
||||
with it off they are unknown commands, and `get_app_state` says in `cad_note` how a person turns it on.
|
||||
with it off they are unknown commands, whose error says how a person turns it on, as `get_app_state`'s
|
||||
`cad_note` does.
|
||||
Turned off while OrcaSlicer runs, the tab stays until the restart, but the Speed Dial has no tile of it. A
|
||||
call is refused (`-32002`) while the Design tab is busy: none runs while a rebuild owns the document,
|
||||
`change` and `sketch` commands do not run under an open feature card, the Text dialog, Constrain mode or a
|
||||
|
|
|
|||
|
|
@ -653,13 +653,15 @@ An agent calls into two catalogs by name: the commands (the typed tools, the Spe
|
|||
Design tab's and the operations plugins offer) and the Speed Dial's actions, which `run_action` runs.
|
||||
`search_tools {query}` finds a name in either, and a command runs by its key through `tools/call` and
|
||||
`call_tool`, with `search_tools` giving the schema of one `tools/list` does not show. A name that misses
|
||||
is answered with the closest names of the catalog asked and nothing else.
|
||||
`CommandCatalog::unknown_command()` builds the error for every lookup of a command that misses:
|
||||
`tools/call`, `call_tool`, `search_tools {tool}`, a replay step and a plugin's or script's call.
|
||||
is answered with the closest names of the catalog asked and nothing else, unless the catalog leaves that
|
||||
command out (`CommandCatalog::leave_out()`): then it says why. A catalog built with the CAD feature off
|
||||
leaves out the Design commands, and says that the feature was off when OrcaSlicer started and how a person
|
||||
turns it on. `CommandCatalog::unknown_command()` builds the error for every lookup of a command that
|
||||
misses: `tools/call`, `call_tool`, `search_tools {tool}`, a replay step and a plugin's or script's call.
|
||||
`run_action` gives the closest action ids, and says that `search_actions` finds an action and
|
||||
`search_tools` a command, since the name may be a command's that has no tile; a tile's key runs its
|
||||
command. For a Design tile that is not shown it says when the tile is there instead, and that `call_tool`
|
||||
runs its command from any tab.
|
||||
runs its command from any tab, or, when the catalog leaves its command out, why.
|
||||
|
||||
Each tool family lives in its own `McpTools*.cpp`. List tools take `limit` and `offset` and reply
|
||||
`{items, offset, total}` (`page()`; `list_objects`, a tree, has `plates` and `outside` in place of
|
||||
|
|
@ -1270,7 +1272,9 @@ never open the Design tab pay nothing for them in `tools/list`. Those that open
|
|||
whose tiles for them the Speed Dial has while the Design tab is shown (see Speed Dial catalog).
|
||||
`register_all_commands()` adds them through `register_cad_commands()` only when the catalog is built with
|
||||
the CAD feature on (`CatalogOptions::cad`, which startup takes from `enable_cad_feature` in the editor). With
|
||||
it off the catalog holds none: `call_tool {tool: "hole"}` is an unknown command, and `get_app_state` carries
|
||||
it off the catalog holds none, and records that it leaves them out (`leave_out_cad_commands()`):
|
||||
`call_tool {tool: "hole"}` is an unknown command whose error says the feature was off when OrcaSlicer
|
||||
started and how a person turns it on, and `get_app_state` carries
|
||||
`cad_note`, how a person turns the feature on (`cad_note()`, in the editor while the catalog holds no Design
|
||||
command or the preference is off). The catalog is sealed at startup and the main window makes the Design
|
||||
page only then, so turning the feature on or off takes effect after a restart, but for the Speed Dial's
|
||||
|
|
@ -1353,7 +1357,8 @@ finds them among the commands with their input schemas, and `search_tools {tool}
|
|||
`read_only`, description, input schema and examples. `call_tool {tool, args}` runs one, its arguments
|
||||
validated against its schema, and replies `{"result": ...}`, the tool's own reply; a replay step calls one
|
||||
by its name or through `call_tool`, and `orca_mcp.py`'s `call_command()` from Python. An unknown name is
|
||||
answered as any unknown command is, with the closest key.
|
||||
answered as any unknown command is: with the closest key, or, for a Design command's name in a run started
|
||||
with the CAD feature off, with how a person turns it on.
|
||||
|
||||
A call runs its function on the UI thread: a person's pick in place, an automated call in one UI closure
|
||||
under the mutate guard, then `settle()`. Before the silent form, `cad_gate()` refuses a call by its cause, in
|
||||
|
|
@ -1772,7 +1777,8 @@ close ids, scored by edit distance against both the full id and its key, a key t
|
|||
(`delete_all` in `obj_delete_all`) counting as closest, and says where to find an action or a command (see
|
||||
Tool catalog); the id or key of a Design tile that is not live says instead that the tile is there only while
|
||||
the Design tab is shown in its mode with the CAD feature on, and that `call_tool` runs its command from any
|
||||
tab (`unknown_action()`). A command's tile runs the command's own function:
|
||||
tab, or, in a run started with the feature off, that it was off then and how a person turns it on, as
|
||||
`call_tool` does (`unknown_action()`). A command's tile runs the command's own function:
|
||||
`args` are checked against its schema, and it runs through a `Mcp::TileContext`, which is `run_action`'s
|
||||
own context except that a command rewriting its journal entry does so inside `run_action`'s, as
|
||||
`{"id": ..., "args": ...}`, so a recorded session replays through `run_action`; the reply's `ran` is the
|
||||
|
|
@ -2182,8 +2188,12 @@ a menu that opens in a window where nothing is armed (a call that queues a menu
|
|||
is closed unseen too. The last three such menus, with the tool whose window took them, are in
|
||||
`get_app_state.closed_menus`.
|
||||
|
||||
A menu path is the item labels joined with `>`, as `GetItemLabelText()` gives them, matched without
|
||||
case; a trailing `...` may be left out. A label repeated among its siblings is numbered from its
|
||||
A menu path is the item labels joined with `>`, each without the key the menu shows after it
|
||||
(`MainFrame::menu_item_label()`), matched without case; a trailing `...` may be left out. That is the
|
||||
label `GetItemLabelText()` gives, which drops a key written after a tab, but for a key the macOS menu
|
||||
bar shows as plain text after ` - ` so that it does not take the key from text fields (`Edit>Undo`, not
|
||||
`Edit>Undo - ⌘+Z`), which `MainFrame` drops by the label it made the item with. So a path is the same
|
||||
on every platform. A label repeated among its siblings is numbered from its
|
||||
second time on (`Change Filament>Generic PLA #2`), so every listed path names one item, and the
|
||||
marker the Change Filament list appends to the slot in use (" (current)", translated) is left out of
|
||||
the numbering and the matching, so a path recorded with another slot in use still names the same
|
||||
|
|
@ -3920,7 +3930,8 @@ presets with a path, and reading a preference changed in the Preferences dialog,
|
|||
targets on negative parts and from below the bed, `tools/mcp/tests/slice_stats.json` the slice
|
||||
reply's statistics on one and two colours, `tools/mcp/tests/preview.json` `get_slice_stats`,
|
||||
`get_app_state.preview` and `set_view`'s preview arguments, `tools/mcp/tests/context_menus.json` context
|
||||
and button menus listed and run without one ever showing, `tools/mcp/tests/rows.json` object list
|
||||
and button menus listed and run without one ever showing, and the Edit menu's Undo and Redo picked by
|
||||
their paths, `tools/mcp/tests/rows.json` object list
|
||||
rows, checklist rows, the object settings table and the print button's popup,
|
||||
`tools/mcp/tests/recording.json` a recording with clicks, a dialog and a slice, stopped and encoded,
|
||||
and one a replay ends, `tools/mcp/tests/plate_icons.json` plate icons (lock, settings, arrange, the plate menu, move to
|
||||
|
|
|
|||
|
|
@ -257,6 +257,13 @@ echo "Comparing against $BASE"
|
|||
|
||||
# --- Run ----------------------------------------------------------------------
|
||||
|
||||
# Apple's compiler finds the macOS SDK through xcrun, so the compile database names
|
||||
# none; any other clang-tidy, such as the pinned one, finds it through SDKROOT.
|
||||
if [ "$OS" = Darwin ] && [ -z "${SDKROOT:-}" ]; then
|
||||
SDKROOT=$(xcrun --show-sdk-path)
|
||||
export SDKROOT
|
||||
fi
|
||||
|
||||
args=(-p "$BUILD_DIR" --base "$BASE" --clang-tidy "$CLANG_TIDY")
|
||||
[ -n "$JOBS" ] && args+=(-j "$JOBS")
|
||||
[ "$FIX" = 1 ] && args+=(-- --fix)
|
||||
|
|
|
|||
|
|
@ -33,6 +33,13 @@ void CommandCatalog::add_source(std::unique_ptr<CommandSource> source)
|
|||
m_sources.push_back(std::move(source));
|
||||
}
|
||||
|
||||
void CommandCatalog::leave_out(const std::string& key, std::string why)
|
||||
{
|
||||
if (m_sealed)
|
||||
throw std::logic_error("The command catalog is sealed; leaving out " + key + " comes too late");
|
||||
m_left_out[key] = std::move(why);
|
||||
}
|
||||
|
||||
void CommandCatalog::seal() { m_sealed = true; }
|
||||
|
||||
const NativeCommand* CommandCatalog::find(const std::string& key) const
|
||||
|
|
@ -75,9 +82,18 @@ std::vector<std::string> CommandCatalog::similar(const std::string& key, std::si
|
|||
return out;
|
||||
}
|
||||
|
||||
const std::string* CommandCatalog::left_out(const std::string& key) const
|
||||
{
|
||||
const auto it = m_left_out.find(key);
|
||||
return it == m_left_out.end() ? nullptr : &it->second;
|
||||
}
|
||||
|
||||
std::string CommandCatalog::unknown_command(const std::string& key, bool suggest) const
|
||||
{
|
||||
std::string message = "Unknown tool: " + key;
|
||||
// A key left out names the command the caller meant, so no other key is suggested.
|
||||
if (const std::string* why = left_out(key))
|
||||
return message + "; " + *why;
|
||||
if (suggest)
|
||||
if (const std::vector<std::string> close = similar(key); !close.empty())
|
||||
message += " (did you mean " + close.front() + "?)";
|
||||
|
|
|
|||
|
|
@ -117,6 +117,9 @@ public:
|
|||
// Before seal(); after it, throws std::logic_error. A source's commands are not checked against the
|
||||
// added ones: lookup() finds an added command first.
|
||||
void add_source(std::unique_ptr<CommandSource> source);
|
||||
// Before seal(); after it, throws std::logic_error. Records that this catalog leaves out `key`, a command
|
||||
// a run of the app with other options holds, and `why`, which unknown_command() gives after the key.
|
||||
void leave_out(const std::string& key, std::string why);
|
||||
void seal();
|
||||
bool sealed() const { return m_sealed; }
|
||||
|
||||
|
|
@ -130,17 +133,20 @@ public:
|
|||
const std::vector<NativeCommand>& commands() const { return m_commands; }
|
||||
// What the sources hold now, source by source.
|
||||
std::vector<std::shared_ptr<const NativeCommand>> source_commands() const;
|
||||
// Why this catalog leaves out `key` (leave_out()), or nullptr when it does not.
|
||||
const std::string* left_out(const std::string& key) const;
|
||||
// Up to `limit` keys of added commands closest to `key`, for "did you mean" errors: a key that
|
||||
// contains `key` first, then by edit distance, none further than max(3, half the length of `key`).
|
||||
std::vector<std::string> similar(const std::string& key, std::size_t limit = 3) const;
|
||||
|
||||
// The error for a key lookup() does not resolve: "Unknown tool: <key>", with `suggest` followed by the
|
||||
// closest key.
|
||||
// The error for a key lookup() does not resolve: "Unknown tool: <key>", followed by why the catalog leaves
|
||||
// it out (leave_out()), or else with `suggest` by the closest key.
|
||||
std::string unknown_command(const std::string& key, bool suggest = false) const;
|
||||
|
||||
private:
|
||||
std::vector<NativeCommand> m_commands;
|
||||
std::unordered_map<std::string, std::size_t> m_index; // key -> position in m_commands
|
||||
std::unordered_map<std::string, std::size_t> m_index; // key -> position in m_commands
|
||||
std::unordered_map<std::string, std::string> m_left_out; // key -> why the catalog leaves it out
|
||||
std::vector<std::unique_ptr<CommandSource>> m_sources;
|
||||
bool m_sealed = false;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2966,6 +2966,19 @@ void MainFrame::update_shortcut_labels()
|
|||
panel->shortcuts_changed();
|
||||
}
|
||||
|
||||
wxString MainFrame::menu_item_label(const wxMenuItem& item) const
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
for (const ShortcutMenuItem& entry : m_shortcut_menu_items)
|
||||
if (entry.item == &item)
|
||||
return wxMenuItem::GetLabelText(entry.label);
|
||||
for (const auto& [shown, label] : m_key_text_items)
|
||||
if (shown == &item)
|
||||
return wxMenuItem::GetLabelText(label);
|
||||
#endif
|
||||
return item.GetItemLabelText();
|
||||
}
|
||||
|
||||
CodeEditorWindow* MainFrame::focused_code_editor() const
|
||||
{
|
||||
const wxWindow* focus = wxWindow::FindFocus();
|
||||
|
|
@ -3560,7 +3573,7 @@ void MainFrame::init_menubar_as_editor()
|
|||
m_plater->select_all(); },
|
||||
"", nullptr, [this](){return focused_code_editor() != nullptr || can_select(); }, this);
|
||||
// BBS Deslect All
|
||||
append_menu_item(editMenu, wxID_ANY, _L("Deselect All") + sep + _L_CONTEXT("Esc", "Keyboard Shortcut"),
|
||||
wxMenuItem* deselect_all = append_menu_item(editMenu, wxID_ANY, _L("Deselect All") + sep + _L_CONTEXT("Esc", "Keyboard Shortcut"),
|
||||
_L("Deselects all objects"), [this, handle_key_event](wxCommandEvent&) {
|
||||
wxKeyEvent e;
|
||||
e.SetEventType(wxEVT_KEY_DOWN);
|
||||
|
|
@ -3570,6 +3583,7 @@ void MainFrame::init_menubar_as_editor()
|
|||
}
|
||||
m_plater->deselect_all(); },
|
||||
"", nullptr, [this](){return can_deselect(); }, this);
|
||||
m_key_text_items.emplace_back(deselect_all, _L("Deselect All"));
|
||||
//editMenu->AppendSeparator();
|
||||
//append_menu_check_item(editMenu, wxID_ANY, _L("Show Model Mesh(TODO)"),
|
||||
// _L("Display triangles of models."), [this](wxCommandEvent& evt) {
|
||||
|
|
|
|||
|
|
@ -276,6 +276,8 @@ class MainFrame : public DPIFrame
|
|||
bool accelerator; // false keeps the binding display-only on macOS, where the menu bar's accelerators are live
|
||||
};
|
||||
std::vector<ShortcutMenuItem> m_shortcut_menu_items;
|
||||
// Menu bar items whose label shows a fixed key as text after sep, and their label without it.
|
||||
std::vector<std::pair<const wxMenuItem*, wxString>> m_key_text_items;
|
||||
|
||||
wxString shortcut_label(const wxString& label, Shortcut shortcut, bool accelerator);
|
||||
template<typename... Args>
|
||||
|
|
@ -482,6 +484,10 @@ public:
|
|||
int get_calibration_curr_tab();
|
||||
void select_view(const std::string& direction);
|
||||
void update_shortcut_labels();
|
||||
// A menu item's label without the key shown after it, the name automation gives the item. GetItemLabelText()
|
||||
// drops a key that follows "\t"; on macOS a key the menu bar must not take follows sep instead (shortcut_label()),
|
||||
// which it keeps, so for MainFrame's own items that label is the one the item was made with.
|
||||
wxString menu_item_label(const wxMenuItem& item) const;
|
||||
// Propagate changed configuration from the Tab to the Plater and save changes to the AppConfig
|
||||
void on_config_changed(DynamicPrintConfig* cfg) const ;
|
||||
void set_print_button_to_default(PrintSelectType select_type);
|
||||
|
|
|
|||
|
|
@ -175,9 +175,10 @@ nlohmann::json rank_actions(const nlohmann::json& listed, const std::vector<std:
|
|||
std::string action_args_error(const AppAction& action, const nlohmann::json& args);
|
||||
|
||||
// What run_action answers for `id`, an action id or the name inside one, that no action of the app's state has:
|
||||
// for a Design tab tile's, when that tile is there and that call_tool runs its command from any tab; for any
|
||||
// other, where an action or a command is found.
|
||||
std::string unknown_action(const std::string& id);
|
||||
// for a Design tab tile's, when that tile is there and that call_tool runs its command from any tab, or, when
|
||||
// `catalog` leaves the tile's command out (CommandCatalog::leave_out()), why; for any other, where an action or a
|
||||
// command is found.
|
||||
std::string unknown_action(const std::string& id, const CommandCatalog& catalog);
|
||||
|
||||
// A setting value from JSON in the serialized form set_deserialize accepts: "3", "0.2", "1"/"0"
|
||||
// for booleans, "a,b" for arrays. A list of strings (`key` names a coStrings option, such as
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ const AppAction& find_action(ActionRegistry& actions, std::string& id)
|
|||
json similar = json::array();
|
||||
for (std::size_t i = 0; i < scored.size() && similar.size() < 3 && scored[i].first <= id.size() / 3 + 2; ++i)
|
||||
similar.push_back(scored[i].second);
|
||||
throw ToolFailure(unknown_action(id), {{"similar", similar}});
|
||||
throw ToolFailure(unknown_action(id, NativeCommands::instance()), {{"similar", similar}});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
@ -82,14 +82,17 @@ std::string action_args_error(const AppAction& action, const json& args)
|
|||
return "The action " + action.id() + " takes no arguments: run it without args";
|
||||
}
|
||||
|
||||
std::string unknown_action(const std::string& id)
|
||||
std::string unknown_action(const std::string& id, const CommandCatalog& catalog)
|
||||
{
|
||||
// A Design tile is no action while it is not live (ActionRegistry::materialize_design_actions()), but its
|
||||
// command is in the catalog.
|
||||
// A Design tile is no action while it is not live (ActionRegistry::materialize_design_actions()); its
|
||||
// command is in the catalog, unless the catalog was built with the CAD feature off.
|
||||
const std::string tile = id.find(':') != std::string::npos ? id : AppAction::compose_id(kCommandPrefix, id, kOrcaSourceKey);
|
||||
if (is_design_tile_id(tile))
|
||||
if (is_design_tile_id(tile)) {
|
||||
if (const std::string* why = catalog.left_out(short_id(tile)))
|
||||
return id + " is a Design tab tile, and " + *why;
|
||||
return id + " is a Design tab tile, there only while the Design tab is shown in its mode (a sketch's or the model's) "
|
||||
"with the CAD feature on; call_tool {\"tool\": \"" + short_id(tile) + "\"} runs its command from any tab";
|
||||
}
|
||||
// The name may be a command's that has no tile, which call_tool runs.
|
||||
return "Unknown action id " + id + "; find an action with search_actions, or a command with search_tools";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,6 +183,11 @@ const char* const kCadOffNote = "call_tool runs no Design command now: they need
|
|||
"Features, and on when OrcaSlicer started. A person turns it on there if it is off, and "
|
||||
"restarts OrcaSlicer.";
|
||||
|
||||
// Why a catalog built with the CAD feature off leaves out the Design commands, after "Unknown tool: <key>; "
|
||||
// or a tile's "<key> is a Design tab tile, and " (unknown_action()).
|
||||
const char* const kCadOffAtStartup = "the CAD feature was off when OrcaSlicer started: a person turns it on in "
|
||||
"Preferences > Features and restarts OrcaSlicer";
|
||||
|
||||
json describe_scene(DesignPanel* panel)
|
||||
{
|
||||
CadDocument& doc = panel->mcp_doc();
|
||||
|
|
@ -3762,6 +3767,13 @@ void register_cad_commands(CommandCatalog& catalog)
|
|||
catalog.add(design_command(t));
|
||||
}
|
||||
|
||||
void leave_out_cad_commands(CommandCatalog& catalog)
|
||||
{
|
||||
for (const DesignTool& t : kDesignTools)
|
||||
if (t.action != nullptr || t.doc != nullptr)
|
||||
catalog.leave_out(t.id, kCadOffAtStartup);
|
||||
}
|
||||
|
||||
json cad_note(const CommandCatalog& catalog)
|
||||
{
|
||||
if (!wxGetApp().is_editor())
|
||||
|
|
|
|||
|
|
@ -70,6 +70,11 @@ NativeCommand cad_command(std::string key, std::string title, nlohmann::json sch
|
|||
// and not among them.
|
||||
void register_cad_commands(CommandCatalog& catalog);
|
||||
|
||||
// Records in `catalog`, built with the CAD feature off, that it leaves out the keys register_cad_commands()
|
||||
// adds, because the feature was off when OrcaSlicer started and how a person turns it on
|
||||
// (CommandCatalog::leave_out()).
|
||||
void leave_out_cad_commands(CommandCatalog& catalog);
|
||||
|
||||
// The input schema of a tool block: an object whose properties are the block's params, a type written "a|b"
|
||||
// as the list of both, min, exclusive_min and max as minimum, exclusiveMinimum and maximum, enum and default
|
||||
// as written, and the unit joined to the description; a param with no default is required. `generation`, the
|
||||
|
|
|
|||
|
|
@ -506,6 +506,16 @@ std::vector<wxTopLevelWindow*> top_level_windows(McpService& service)
|
|||
return out;
|
||||
}
|
||||
|
||||
// A menu item's label as automation names it, without the key shown after it (MainFrame::menu_item_label()), so
|
||||
// a menu path is the same on every platform. Only a GUI_App has a main window: the unit tests run menus under a
|
||||
// plain wxApp.
|
||||
std::string menu_label(const wxMenuItem& item)
|
||||
{
|
||||
const auto* app = dynamic_cast<const GUI_App*>(wxTheApp);
|
||||
const MainFrame* frame = app != nullptr ? app->mainframe : nullptr;
|
||||
return into_u8(frame != nullptr ? frame->menu_item_label(item) : item.GetItemLabelText());
|
||||
}
|
||||
|
||||
// The menus of the main window: its menu bar on macOS, the title bar's File and dropdown menus
|
||||
// elsewhere.
|
||||
std::vector<std::pair<std::string, wxMenu*>> main_menus()
|
||||
|
|
@ -525,7 +535,7 @@ std::vector<std::pair<std::string, wxMenu*>> main_menus()
|
|||
if (wxMenu* top = topbar->GetTopMenu())
|
||||
for (wxMenuItem* item : top->GetMenuItems())
|
||||
if (item->IsSubMenu())
|
||||
out.emplace_back(into_u8(item->GetItemLabelText()), item->GetSubMenu());
|
||||
out.emplace_back(menu_label(*item), item->GetSubMenu());
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
@ -546,7 +556,7 @@ wxMenuItem* find_menu_item(int id, std::string* path)
|
|||
for (wxMenuItem* item : menu->GetMenuItems()) {
|
||||
if (item->IsSeparator())
|
||||
continue;
|
||||
const std::string here = prefix + ">" + into_u8(item->GetItemLabelText());
|
||||
const std::string here = prefix + ">" + menu_label(*item);
|
||||
if (item->GetId() == id && !item->IsSubMenu()) {
|
||||
if (path)
|
||||
*path = here;
|
||||
|
|
@ -570,7 +580,7 @@ wxMenuItem* find_menu_path(const std::string& wanted, int& id)
|
|||
for (wxMenuItem* item : menu->GetMenuItems()) {
|
||||
if (item->IsSeparator())
|
||||
continue;
|
||||
const std::string here = prefix + ">" + into_u8(item->GetItemLabelText());
|
||||
const std::string here = prefix + ">" + menu_label(*item);
|
||||
if (!item->IsSubMenu() && lower(here) == lower(wanted)) {
|
||||
id = item->GetId();
|
||||
return item;
|
||||
|
|
@ -599,7 +609,7 @@ std::vector<MenuEntry> menu_entries(wxMenu& menu)
|
|||
if (item->IsSeparator())
|
||||
continue;
|
||||
MenuEntry e;
|
||||
e.label = into_u8(item->GetItemLabelText());
|
||||
e.label = menu_label(*item);
|
||||
e.parent = parent;
|
||||
e.id = item->GetId();
|
||||
e.enabled = enabled && item->IsEnabled();
|
||||
|
|
@ -2093,7 +2103,7 @@ void UiInspector::add_menus(wxMenu* menu, const std::string& path, wxWindow* fra
|
|||
for (wxMenuItem* item : menu->GetMenuItems()) {
|
||||
if (item->IsSeparator())
|
||||
continue;
|
||||
const std::string label = into_u8(item->GetItemLabelText());
|
||||
const std::string label = menu_label(*item);
|
||||
const std::string here = path + ">" + label;
|
||||
UiNode node;
|
||||
node.kind = item->IsSubMenu() ? "menu" : "menu_item";
|
||||
|
|
|
|||
|
|
@ -1764,6 +1764,8 @@ void NativeCommands::register_all_commands(CommandCatalog& catalog, [[maybe_unus
|
|||
#ifdef SLIC3R_CAD
|
||||
if (options.cad)
|
||||
Mcp::register_cad_commands(catalog);
|
||||
else
|
||||
Mcp::leave_out_cad_commands(catalog);
|
||||
#endif
|
||||
Mcp::register_action_tools(catalog);
|
||||
Mcp::register_ui_tools(catalog);
|
||||
|
|
|
|||
|
|
@ -25,9 +25,11 @@ struct CatalogOptions
|
|||
// Adds the built-in commands to `catalog`: the Speed Dial's, each with in_palette, then the typed tools, each
|
||||
// listed, family by family (Mcp::register_app_tools() and the others), and with options.cad the Design tab's
|
||||
// (Mcp::register_cad_commands()), not listed, of which those with an action have a tile the Speed Dial shows
|
||||
// in the Design tab. new_project, save_project, start_recording and stop_recording are both: typed tools with
|
||||
// a tile (with_person_form()). undo and redo act on the Design tab's history or the project's, a person's pick
|
||||
// as the Edit menu's item does; with options.cad their examples show the Design tab's.
|
||||
// in the Design tab; without it, in a build with CAD, it records that it leaves them out and why
|
||||
// (Mcp::leave_out_cad_commands()). new_project, save_project, start_recording and stop_recording are both:
|
||||
// typed tools with a tile (with_person_form()). undo and redo act on the Design tab's history or the
|
||||
// project's, a person's pick as the Edit menu's item does; with options.cad their examples show the Design
|
||||
// tab's.
|
||||
void register_all_commands(CommandCatalog& catalog, const CatalogOptions& options);
|
||||
|
||||
// Builds and seals the process catalog. UI thread, once, at startup; a second call, or a call after
|
||||
|
|
|
|||
|
|
@ -13237,7 +13237,11 @@ void Plater::priv::set_current_panel(wxPanel* panel, bool no_slice)
|
|||
//view_toolbar.select_item("Assemble");
|
||||
}
|
||||
|
||||
current_panel->SetFocusFromKbd();
|
||||
// The shown view's canvas takes the keyboard. Focusing its panel instead hands the focus to the canvas, the
|
||||
// panel's one focusable child, except on macOS after a switch: hiding the panel whose canvas had the focus
|
||||
// moves it to the next view AppKit can focus, the panel just shown, and a panel that holds the focus itself
|
||||
// keeps it (wxControlContainer::DoSetFocus()), so the view's keys would wait for the pointer to enter it.
|
||||
get_current_canvas3D()->force_set_focus();
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": successfully, exit");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -438,6 +438,38 @@ TEST_CASE("a Speed Dial command is found by the one lookup", "[CommandCatalog]")
|
|||
CHECK_THAT(unknown, !ContainsSubstring("run_action"));
|
||||
}
|
||||
|
||||
TEST_CASE("a command the catalog leaves out is unknown with the reason", "[CommandCatalog]")
|
||||
{
|
||||
CommandCatalog catalog;
|
||||
catalog.add(command("hold"));
|
||||
catalog.leave_out("holes", "the feature was off");
|
||||
catalog.seal();
|
||||
REQUIRE(catalog.left_out("holes") != nullptr);
|
||||
CHECK(*catalog.left_out("holes") == "the feature was off");
|
||||
CHECK(catalog.left_out("hold") == nullptr);
|
||||
// The reason, and no close key: the key names the command the caller meant.
|
||||
CHECK(catalog.unknown_command("holes", /*suggest=*/true) == "Unknown tool: holes; the feature was off");
|
||||
CHECK(catalog.unknown_command("holx", /*suggest=*/true) == "Unknown tool: holx (did you mean hold?)");
|
||||
CHECK_THROWS_AS(catalog.leave_out("shell", "too late"), std::logic_error);
|
||||
|
||||
// A run with the CAD feature off at startup leaves out the Design commands, and says how a person turns it
|
||||
// on; a build without CAD has no Design commands to leave out.
|
||||
CommandCatalog no_cad;
|
||||
NativeCommands::register_all_commands(no_cad, {false});
|
||||
no_cad.seal();
|
||||
#ifdef SLIC3R_CAD
|
||||
for (const std::string key : {"extrude", "hole", "describe_scene"}) {
|
||||
INFO(key);
|
||||
CHECK(no_cad.unknown_command(key, /*suggest=*/true) ==
|
||||
"Unknown tool: " + key + "; the CAD feature was off when OrcaSlicer started: a person turns it on in "
|
||||
"Preferences > Features and restarts OrcaSlicer");
|
||||
}
|
||||
#else
|
||||
CHECK(no_cad.left_out("extrude") == nullptr);
|
||||
#endif
|
||||
CHECK(no_cad.left_out("obj_arrange") == nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("every expected-id argument of a schema is in id_args", "[CommandCatalog]")
|
||||
{
|
||||
for (const NativeCommand& c : NativeCommands::instance().commands()) {
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ using nlohmann::json;
|
|||
using Slic3r::GUI::CommandCatalog;
|
||||
using Slic3r::GUI::CommandSource;
|
||||
using Slic3r::GUI::NativeCommand;
|
||||
namespace NativeCommands = Slic3r::GUI::NativeCommands;
|
||||
|
||||
namespace {
|
||||
|
||||
|
|
@ -175,17 +176,28 @@ TEST_CASE("run_action refuses arguments for an action that takes none", "[Mcp][S
|
|||
|
||||
TEST_CASE("run_action says where an action it cannot find is", "[Mcp][SpeedDial]")
|
||||
{
|
||||
CHECK_THAT(unknown_action("obj_arange"), Catch::Matchers::ContainsSubstring("search_actions"));
|
||||
CHECK_THAT(unknown_action("obj_arange", NativeCommands::instance()), Catch::Matchers::ContainsSubstring("search_actions"));
|
||||
#ifdef SLIC3R_CAD
|
||||
// A Design tab tile, by its id or its key, while it is not shown.
|
||||
for (const char* id : {"orca_command:shell:orca", "shell"}) {
|
||||
INFO(id);
|
||||
const std::string why = unknown_action(id);
|
||||
CHECK_THAT(why, Catch::Matchers::ContainsSubstring("while the Design tab is shown"));
|
||||
CHECK_THAT(why, Catch::Matchers::ContainsSubstring("call_tool {\"tool\": \"shell\"}"));
|
||||
// A Design tab tile, by its id or its key, while it is not shown: in a run with the CAD feature on at startup
|
||||
// call_tool runs its command from any tab, and in one with it off there is no such command.
|
||||
for (const bool cad : {true, false}) {
|
||||
CommandCatalog catalog;
|
||||
NativeCommands::register_all_commands(catalog, {cad});
|
||||
catalog.seal();
|
||||
for (const std::string id : {"orca_command:shell:orca", "shell"}) {
|
||||
INFO(id << (cad ? ", the CAD feature on" : ", the CAD feature off"));
|
||||
const std::string why = unknown_action(id, catalog);
|
||||
if (cad) {
|
||||
CHECK_THAT(why, Catch::Matchers::ContainsSubstring("while the Design tab is shown"));
|
||||
CHECK_THAT(why, Catch::Matchers::ContainsSubstring("call_tool {\"tool\": \"shell\"}"));
|
||||
} else {
|
||||
CHECK(why == id + " is a Design tab tile, and the CAD feature was off when OrcaSlicer started: a person "
|
||||
"turns it on in Preferences > Features and restarts OrcaSlicer");
|
||||
}
|
||||
}
|
||||
// A Design command without a tile is any unknown action.
|
||||
CHECK_THAT(unknown_action("orca_command:describe_scene:orca", catalog), Catch::Matchers::ContainsSubstring("search_actions"));
|
||||
}
|
||||
// A Design command without a tile is any unknown action.
|
||||
CHECK_THAT(unknown_action("orca_command:describe_scene:orca"), Catch::Matchers::ContainsSubstring("search_actions"));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,10 @@ Python. It uses only the standard library. `docs/HLSD/mcp-server.md` covers the
|
|||
|
||||
`launch` creates a fresh temporary datadir unless you pass `--datadir`. It seeds the datadir with
|
||||
an `OrcaSlicer.conf` that has a finished setup wizard and one printer and filament (Bambu Lab X1
|
||||
Carbon 0.4 by default), with update checks and daily tips turned off. `--cad` turns the Design
|
||||
Carbon 0.4 by default), with update checks and daily tips turned off, and with the Orca Cloud login kept
|
||||
in a token file in the datadir (`use_encrypted_token_file`) instead of the system's secret store, so the
|
||||
instance starts signed out and never reads your login: on macOS that read would stop a newly built app at
|
||||
a keychain prompt. `--cad` turns the Design
|
||||
(CAD) tab on, and with it its commands: it sets `enable_cad_feature` in a fresh datadir's
|
||||
`OrcaSlicer.conf`, and in a reused one too, since the app creates the Design tab and its commands only at
|
||||
startup, when that setting is on.
|
||||
|
|
@ -427,7 +430,8 @@ once, and that a negative part, and a point seen through the bed from below, are
|
|||
`tests/context_menus.json` right-clicks a cube, the empty bed and two selected objects, and clicks a
|
||||
preset edit button that opens a menu: each menu is listed in the reply, or an item of it run with
|
||||
`popup_item` (a modifier, a primitive, Delete), and none is ever shown, so on macOS the run finishes
|
||||
with nobody pressing Escape.
|
||||
with nobody pressing Escape. It also picks the Edit menu's Undo and Redo by the paths `Edit>Undo` and
|
||||
`Edit>Redo`, which name them on every platform, though macOS shows their keys after them.
|
||||
|
||||
`tests/rows.json` drives rows and popups: object list rows (plates, an object and its parts, Ctrl
|
||||
to add a row, the Printable column, a double click), the object's and a part's menus run from their
|
||||
|
|
|
|||
|
|
@ -258,7 +258,11 @@ def write_conf(conf, data):
|
|||
def seed_datadir(datadir, printer, cad=False, unrestricted_scripts=False):
|
||||
"""Seed a fresh datadir's OrcaSlicer.conf. A datadir that has one keeps it, except for the settings
|
||||
cad and unrestricted_scripts turn on, which only the file can: the app creates the Design tab only at
|
||||
startup, when its setting is on, and no tool lets Python scripts run unrestricted."""
|
||||
startup, when its setting is on, and no tool lets Python scripts run unrestricted.
|
||||
|
||||
A fresh datadir keeps the Orca Cloud login in its own token file (use_encrypted_token_file), not in the
|
||||
system's secret store, so the instance starts signed out and never reads the person's login: on macOS
|
||||
that read stops a newly built app at a keychain prompt that only a person can answer."""
|
||||
vendor, model, nozzle, filament = printer
|
||||
os.makedirs(datadir, exist_ok=True)
|
||||
conf = os.path.join(datadir, "OrcaSlicer.conf")
|
||||
|
|
@ -280,7 +284,8 @@ def seed_datadir(datadir, printer, cad=False, unrestricted_scripts=False):
|
|||
"models": [{"model": model, "nozzle_diameter": nozzle, "vendor": vendor}],
|
||||
"filaments": [filament],
|
||||
"presets": {"machine": f"{model} {nozzle} nozzle"},
|
||||
"app": {"check_for_updates": False, "show_daily_tips": False, **switches}})
|
||||
"app": {"check_for_updates": False, "show_daily_tips": False, "use_encrypted_token_file": True,
|
||||
**switches}})
|
||||
|
||||
|
||||
# The headless compositors --headless tries, in order, by the binary each needs.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ mcp/server.json, or whose server.json is not JSON or names no port, naming the f
|
|||
--mcp advice; and one whose server.json names a port where nothing listens or where another server
|
||||
answers (HTTP 401, a reply that is not JSON), also chaining the cause. call_command(), against a
|
||||
stubbed call(), fails at once on a dialog, follows a running job, prefixes its errors with the
|
||||
command's name, chaining the original, and returns the command's whole reply. Exits 0 when every check passes.
|
||||
command's name, chaining the original, and returns the command's whole reply. seed_datadir() keeps a fresh
|
||||
datadir's login in its own token file and leaves a reused datadir's where it is. Exits 0 when every check passes.
|
||||
The folders the checks make are removed when they end.
|
||||
"""
|
||||
|
||||
|
|
@ -244,10 +245,33 @@ def check_call_command():
|
|||
ok("call_command() starts every error with the command's name, with the original as its cause")
|
||||
|
||||
|
||||
def read_conf(datadir):
|
||||
with open(os.path.join(datadir, "OrcaSlicer.conf"), encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
return json.loads(text[:text.rfind("}") + 1])
|
||||
|
||||
|
||||
def check_seed_datadir():
|
||||
fresh = scratch("orca-seed-")
|
||||
orca_mcp.seed_datadir(fresh, orca_mcp.DEFAULT_PRINTER)
|
||||
app = read_conf(fresh)["app"]
|
||||
assert app.get("use_encrypted_token_file") is True, app
|
||||
ok("seed_datadir() keeps a fresh datadir's login in its own token file, not the system's secret store")
|
||||
|
||||
reused = scratch("orca-seed-reused-")
|
||||
orca_mcp.write_conf(os.path.join(reused, "OrcaSlicer.conf"), {"app": {"use_encrypted_token_file": False}})
|
||||
orca_mcp.seed_datadir(reused, orca_mcp.DEFAULT_PRINTER, cad=True)
|
||||
app = read_conf(reused)["app"]
|
||||
assert app.get("enable_cad_feature") is True, app
|
||||
assert app.get("use_encrypted_token_file") is False, app
|
||||
ok("seed_datadir() leaves a reused datadir's login where its conf keeps it")
|
||||
|
||||
|
||||
def main():
|
||||
global _ROOT
|
||||
with tempfile.TemporaryDirectory(prefix="orca-attach-") as root:
|
||||
_ROOT = root
|
||||
check_seed_datadir()
|
||||
check_default_datadir()
|
||||
check_symlinked_binary()
|
||||
check_from_datadir()
|
||||
|
|
|
|||
|
|
@ -34,6 +34,13 @@
|
|||
{"tool": "run_action", "args": {"id": "orca_command:redo:orca"}},
|
||||
{"tool": "list_objects", "expect": {"/plates/0/objects/0/parts/1/type": {"eq": "modifier"}}},
|
||||
|
||||
// ---- The Edit menu's Undo and Redo, named by their labels alone on every platform, though macOS shows
|
||||
// their keys as text after them ----
|
||||
{"tool": "click", "args": {"target": {"menu": "Edit>Undo"}}, "expect": {"/clicked": {"eq": "Edit>Undo"}}},
|
||||
{"tool": "list_objects", "expect": {"/plates/0/objects/0/parts/1": {"exists": false}}},
|
||||
{"tool": "click", "args": {"target": {"menu": "Edit>Redo"}}, "expect": {"/clicked": {"eq": "Edit>Redo"}}},
|
||||
{"tool": "list_objects", "expect": {"/plates/0/objects/0/parts/1/type": {"eq": "modifier"}}},
|
||||
|
||||
// ---- Empty space with nothing selected: the default menu ----
|
||||
{"tool": "select_objects", "args": {"none": true}},
|
||||
{"tool": "mouse_gesture", "args": {"action": "click", "button": "right", "x": 1000, "y": 150},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue