mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-26 07:11:23 -05:00
Outside the Design tab an agent had 175 commands, 50 of them in the tool list. There are now 118, named by what they act on (`object_`, `plate_`, `preset_`, `filament_`, `plugin_` and so on), and 115 are listed. Each takes its target and values in the call, acts on the selection when it names no target and says what it acted on; an old name is refused. Printers and system filaments install and uninstall, preferences read and write, plugins enable, reload, uninstall and refresh, and objects reorder, with no dialog to drive. The Speed Dial keeps its 129 tiles under the same ids. Eight defects in the rows these commands share with the menus are fixed. For a person: an object row that cannot run says why instead of "Select an object first.", rows that failed no longer claim success, Duplicate Plate can be undone, and Refresh Plugins picked while a refresh runs now runs after it instead of beside it.
101 lines
4.6 KiB
Python
101 lines
4.6 KiB
Python
"""Checks that opening a project loads the settings it was saved with, whatever the load-behaviour preference says.
|
|
|
|
Launches OrcaSlicer on a fresh data folder whose Preferences say to load the geometry of a project only
|
|
(project_load_behaviour load_geometry_only, which a person picks under Load behavior), imports a cube, sets the
|
|
process's layer_height to 0.28, saves the project, starts a new one that drops the presets' changes, and opens the
|
|
saved file as a project: the process then has the project's layer_height again, and the preference is unchanged.
|
|
Run it as python tools/mcp/test_project_open_settings.py [--bin PATH] [--datadir PATH].
|
|
"""
|
|
import json
|
|
import os
|
|
import shutil
|
|
import socket
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
sys.path.insert(0, HERE)
|
|
from orca_mcp import DEFAULT_PRINTER, OrcaMcp, app_env, seed_datadir, write_conf # noqa: E402
|
|
|
|
CUBE = os.path.join(os.path.dirname(os.path.dirname(HERE)), "tests", "data", "20mm_cube.obj")
|
|
TOKEN = "project-open-settings-test-token"
|
|
LAYER_HEIGHT = 0.28
|
|
results = []
|
|
|
|
|
|
def check(name, ok, detail=""):
|
|
results.append((name, bool(ok)))
|
|
print(("PASS " if ok else "FAIL ") + name + ("" if ok else " " + str(detail)[:400]), flush=True)
|
|
|
|
|
|
def free_port():
|
|
"""A port nothing listens on now, so that this test runs beside the others of a sweep."""
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
s.bind(("127.0.0.1", 0))
|
|
return s.getsockname()[1]
|
|
|
|
|
|
def harness(env, *args):
|
|
return subprocess.run([sys.executable, os.path.join(HERE, "orca_mcp.py"), *args], env=env, capture_output=True, text=True,
|
|
timeout=300)
|
|
|
|
|
|
def layer_height(orca):
|
|
"""The process's layer_height being edited, as a number."""
|
|
items = orca.call("settings_get", type="process", keys=["layer_height"])["items"]
|
|
return float(items[0]["value"])
|
|
|
|
|
|
def main():
|
|
extra = sys.argv[1:]
|
|
binary = ["--bin", extra[extra.index("--bin") + 1]] if "--bin" in extra else []
|
|
datadir = os.path.abspath(extra[extra.index("--datadir") + 1]) if "--datadir" in extra else tempfile.mkdtemp(prefix="oos-")
|
|
port = free_port()
|
|
env = app_env(dict(os.environ, ORCA_MCP_SESSION=os.path.join(datadir, "session.json"), ORCA_MCP_TOKEN=TOKEN), datadir)
|
|
try:
|
|
# The preference a person sets under Preferences > Load behavior: a project's geometry only.
|
|
seed_datadir(datadir, DEFAULT_PRINTER)
|
|
conf = os.path.join(datadir, "OrcaSlicer.conf")
|
|
with open(conf, encoding="utf-8") as f:
|
|
seeded = json.load(f)
|
|
seeded["app"]["project_load_behaviour"] = "load_geometry_only"
|
|
write_conf(conf, seeded)
|
|
launched = harness(env, "launch", "--datadir", datadir, "--port", str(port), *binary)
|
|
if launched.returncode != 0:
|
|
print(launched.stdout, launched.stderr)
|
|
return 1
|
|
orca = OrcaMcp(port=port, token=TOKEN)
|
|
|
|
preference = orca.call("preferences_get", keys=["project_load_behaviour"])["items"]
|
|
check("the app loads a project's geometry only", len(preference) == 1 and preference[0]["key"] == "project_load_behaviour"
|
|
and preference[0]["value"] == "load_geometry_only", preference)
|
|
orca.call("project_import", paths=[CUBE])
|
|
orca.call("settings_set", values={"layer_height": LAYER_HEIGHT})
|
|
check("the process is set to the layer height the project keeps", layer_height(orca) == LAYER_HEIGHT, layer_height(orca))
|
|
project = os.path.join(datadir, "layer_height.3mf")
|
|
orca.call("project_save", path=project, overwrite=True)
|
|
orca.call("project_new", discard_changes=True, preset_changes="discard")
|
|
check("a new project prints with the preset's layer height", layer_height(orca) != LAYER_HEIGHT, layer_height(orca))
|
|
|
|
opened = orca.call("project_open", path=project, discard_changes=True)
|
|
check("the project opens with its object", len(opened.get("names", [])) == 1, opened)
|
|
check("the opened project prints with the layer height it was saved with", layer_height(orca) == LAYER_HEIGHT,
|
|
layer_height(orca))
|
|
preference = orca.call("preferences_get", keys=["project_load_behaviour"])["items"]
|
|
check("the preference is as it was", preference[0]["value"] == "load_geometry_only", preference)
|
|
finally:
|
|
harness(env, "stop")
|
|
time.sleep(2)
|
|
if "--datadir" not in extra:
|
|
shutil.rmtree(datadir, ignore_errors=True)
|
|
|
|
failed = [r for r in results if not r[1]]
|
|
print(f"\n{len(results) - len(failed)}/{len(results)} passed")
|
|
return 1 if failed else 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|