mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-03 10:17:58 -05:00
print_start opens the dialog the Print button opens for the selected printer, for one plate or all of them, and is refused where the button would be disabled, such as for a plate not sliced. printer_send, and the Send G-code Speed Dial action with it, open the dialog that sends to a Bambu printer's storage where they used to refuse such a printer, and take the plate to send. printer_test_host checks that the printer's print host answers, as the Test button of its connection dialog does.
1117 lines
58 KiB
Python
1117 lines
58 KiB
Python
#!/usr/bin/env python3
|
|
"""The project's files, as the test_files entry of tools/mcp/test-entries/files.md designs them.
|
|
|
|
tools/mcp/orca_mcp.py launch
|
|
tools/mcp/test_files.py
|
|
|
|
A new project and the question New Project asks about unsaved changes; opening a project file and saving one under a
|
|
name; importing models (STL, a project's .3mf, ZIP archives, a STEP file, files that hold no model); exporting the
|
|
objects as STL and DRC, the Preview's toolpaths as OBJ, the model as a 3MF, the plate's G-code and the sliced file;
|
|
sending G-code with no print host; and the filament slots a merge and a mix leave in the project file. Every file
|
|
written is read back, by the test (a G-code's text, a sliced file's entries, a folder's file names and sizes) or by
|
|
the app (an exported mesh imported into an empty project, a saved project opened again). It runs on the harness's
|
|
default printer, the Bambu Lab X1 Carbon 0.4, writes into a folder of its own, kept when a check fails, and exits 0
|
|
when every check passes.
|
|
"""
|
|
|
|
import os
|
|
import re
|
|
import shutil
|
|
import sys
|
|
import tempfile
|
|
import threading
|
|
import time
|
|
import zipfile
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
import orca_mcp # noqa: E402
|
|
from checks import (Checks, answer_all, dialogs, gcode, layer_gcode, meshes, normal, obj_facts, plates, # noqa: E402
|
|
project, recent, reimport, run, sliced, sliced_flags, slots, undo_steps, unsaved, values, wait)
|
|
|
|
HERE = os.path.dirname(os.path.abspath(__file__))
|
|
REPO = os.path.dirname(os.path.dirname(HERE))
|
|
BOX_STL = os.path.join(REPO, "tests", "data", "test_stl", "ASCII", "20mmbox-LF.stl")
|
|
STEP = os.path.join(REPO, "tests", "data", "named_single_body.step")
|
|
BENCHY = os.path.join(REPO, "resources", "handy_models", "3DBenchy.drc")
|
|
HEIGHTMAP = os.path.join(HERE, "tests", "fixtures", "heightmap.png")
|
|
PLA_JSON = os.path.join(HERE, "tests", "fixtures", "mcp_import_pla.json")
|
|
|
|
PROCESS = "0.20mm Standard @BBL X1C"
|
|
NO_GEOMETRY = "The file does not contain any geometry data."
|
|
NEW_PROJECT_QUESTION = "Creating a new project: unsaved changes"
|
|
LOAD_PROJECT_QUESTION = "Load project: unsaved changes"
|
|
SAVE_QUESTION = "Orca Slicer - Save"
|
|
STEP_DIALOG = "STEP file import parameters"
|
|
NEW_PROJECT = "new_project"
|
|
SEND = "send_gcode"
|
|
SPIRAL = "Spiral mode only works"
|
|
# The undo steps a change of the current plate logs: Plater::select_plate() takes one, and PartPlateList::select_plate()
|
|
# another when the plate changes.
|
|
SELECTED = ["select partplate!", "select partplate!"]
|
|
ROW = re.compile(r'^"(.*)" (\d+)( \*)?$')
|
|
|
|
# A cube's corners and its twelve triangles, each turned outward.
|
|
CORNERS = [(0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 0, 1), (1, 0, 1), (1, 1, 1), (0, 1, 1)]
|
|
TRIANGLES = [(0, 2, 1), (0, 3, 2), (4, 5, 6), (4, 6, 7), (0, 1, 5), (0, 5, 4),
|
|
(1, 2, 6), (1, 6, 5), (2, 3, 7), (2, 7, 6), (3, 0, 4), (3, 4, 7)]
|
|
|
|
|
|
def cube_stl(size):
|
|
"""An ASCII STL of a cube of `size` mm."""
|
|
lines = ["solid cube"]
|
|
for triangle in TRIANGLES:
|
|
lines += [" facet normal 0 0 0", " outer loop"]
|
|
lines += [" vertex %g %g %g" % tuple(c * size for c in CORNERS[i]) for i in triangle]
|
|
lines += [" endloop", " endfacet"]
|
|
lines.append("endsolid cube")
|
|
return "\n".join(lines) + "\n"
|
|
|
|
|
|
def P(*rows):
|
|
"""Plates written as the entry writes them: '"" 1 *' is an unnamed plate with one object, current."""
|
|
out = []
|
|
for row in rows:
|
|
m = ROW.match(row)
|
|
assert m, row
|
|
out.append({"name": m.group(1), "current": bool(m.group(3)), "locked": False, "objects": int(m.group(2))})
|
|
return out
|
|
|
|
|
|
class FilesTest:
|
|
def __init__(self, client, session, folder):
|
|
self.c = client
|
|
self.session = session
|
|
self.t = Checks()
|
|
self.folder = folder
|
|
self.tag = os.path.basename(folder)
|
|
self.next_walls = 3
|
|
|
|
# ---- Calls ----
|
|
|
|
def run(self, tool, **args):
|
|
return run(self.c, tool, **args)
|
|
|
|
def w(self, *names):
|
|
return os.path.join(self.folder, *names)
|
|
|
|
def follow(self, reply, tool):
|
|
"""Follows the job of a call whose dialogs the test has answered to its end. A dialog still open raises, as
|
|
run() does, since nothing would answer it."""
|
|
deadline = time.monotonic() + 600
|
|
while isinstance(reply, dict) and "job" in reply and reply.get("status") in ("running", "blocked_by_dialog"):
|
|
shown = dialogs(self.c)
|
|
if shown:
|
|
raise orca_mcp.McpError(f"{tool} is held by the dialog {shown}", reply)
|
|
if time.monotonic() > deadline:
|
|
raise TimeoutError(f"{tool} still runs after 600 s")
|
|
reply = self.c.call("app_wait", **{"for": "job", "job": reply["job"], "timeout_s": 10})
|
|
return reply
|
|
|
|
def cube(self, name, size, x, y):
|
|
self.run("object_add_primitive", shape="cube", size=[size] * 3, name=name, position=[x, y, 0])
|
|
|
|
def cylinder(self, name):
|
|
self.run("object_add_primitive", shape="cylinder", size=[20, 10], name=name)
|
|
|
|
def new_project(self):
|
|
self.run("project_new", discard_changes=True, preset_changes="discard")
|
|
|
|
def start(self, name, tab="prepare"):
|
|
self.new_project()
|
|
self.run("view_set", tab=tab)
|
|
wait(self.c, "idle")
|
|
self.project_is(f"{name}: the start", "Untitled", None, "clean")
|
|
self.t.equal(f"{name}: the start: no objects", meshes(self.c), [])
|
|
self.t.equal(f"{name}: the start: the plates", plates(self.c), P('"" 0 *'))
|
|
self.t.equal(f"{name}: the start: no dialog", dialogs(self.c), [])
|
|
|
|
# ---- Reads ----
|
|
|
|
def project_is(self, label, name, file, state):
|
|
want = {"name": name, "file": normal(self.w(file)) if file else None, "dirty": state == "dirty"}
|
|
self.t.equal(f"{label}: the project", project(self.c), want)
|
|
|
|
def names_are(self, label, *names):
|
|
self.t.equal(f"{label}: the objects", [m["name"] for m in meshes(self.c)], list(names))
|
|
|
|
def placed(self, label, *places):
|
|
"""The objects, in order, each (name, x, y): its name and its offset x and y to 0.001 mm."""
|
|
got = meshes(self.c)
|
|
self.t.equal(f"{label}: the objects", [m["name"] for m in got], [p[0] for p in places])
|
|
for m, (name, x, y) in zip(got, places):
|
|
self.t.near(f"{label}: {name} at ({x}, {y})", m["offset"], [x, y], 0.001)
|
|
|
|
def meshes_are(self, label, *want, got=None):
|
|
"""The objects, in order, each (name, triangles, mesh_volume, size) of its one part: the name, triangles and
|
|
volume exactly, the size to 0.001 mm."""
|
|
got = meshes(self.c) if got is None else got
|
|
self.t.equal(f"{label}: the meshes", [(m["name"], [(p["triangles"], p["mesh_volume"]) for p in m["parts"]])
|
|
for m in got], [(n, [(t, v)]) for n, t, v, _ in want])
|
|
for m, (name, _, _, size) in zip(got, want):
|
|
self.t.near(f"{label}: {name}'s size", m["size"], size, 0.001)
|
|
|
|
def parts_are(self, label, *want):
|
|
"""Object 0's parts, each (type, triangles, mesh_volume); returns their ids."""
|
|
parts = meshes(self.c)[0]["parts"]
|
|
self.t.equal(f"{label}: object 0's parts", [(p["type"], p["triangles"], p["mesh_volume"]) for p in parts],
|
|
list(want))
|
|
return [p["id"] for p in parts]
|
|
|
|
def values_are(self, label, want, type="process"):
|
|
self.t.equal(f"{label}: the {type} values", values(self.c, list(want), type), want)
|
|
|
|
def unsaved_is(self, label, keys, type="process"):
|
|
self.t.equal(f"{label}: unsaved {type} keys", unsaved(self.c, type), keys)
|
|
|
|
def tab_is(self, label, tab):
|
|
self.t.equal(f"{label}: the tab", self.c.call("app_state")["tab"], tab)
|
|
|
|
def no_dialog(self, label):
|
|
self.t.equal(f"{label}: no dialog", dialogs(self.c), [])
|
|
|
|
def titles_are(self, label, titles):
|
|
self.t.equal(f"{label}: the dialogs open", [d["title"] for d in dialogs(self.c)], titles)
|
|
|
|
def steps_are(self, label, steps):
|
|
self.t.equal(f"{label}: the undo steps", undo_steps(self.c), steps)
|
|
|
|
def recent_has(self, label, file, held=True):
|
|
self.t.equal(f"{label}: recent projects {'hold' if held else 'lack'} {file}",
|
|
normal(self.w(file)) in recent(self.c), held)
|
|
|
|
def no_file(self, label, *names):
|
|
self.t.check(f"{label}: no file {'/'.join(names)}", not os.path.exists(self.w(*names)), self.w(*names))
|
|
|
|
def plates_are(self, label, *rows):
|
|
self.t.equal(f"{label}: the plates", plates(self.c), P(*rows))
|
|
|
|
def flags_are(self, label, flags):
|
|
self.t.equal(f"{label}: the plates sliced", sliced_flags(self.c), flags)
|
|
|
|
def sliced_ok(self, label, reply, layers):
|
|
self.t.equal(f"{label}: the slice", [(p.get("outcome"), p.get("layers")) for p in reply.get("plates", [])],
|
|
[("ok", layers)])
|
|
|
|
def saved(self, label, reply, file):
|
|
"""A save's or an export's reply: its path the file, and its bytes the file's size on disk."""
|
|
path = self.w(file)
|
|
self.t.equal(f"{label}: the reply's path", normal(reply.get("path", "")), normal(path))
|
|
self.t.equal(f"{label}: the reply's bytes", reply.get("bytes"), os.path.getsize(path) if os.path.exists(path)
|
|
else "no file")
|
|
|
|
def colours(self):
|
|
return self.c.call("project_get_settings", keys=["filament_colour"])["items"][0]["value"]
|
|
|
|
def rule_uses(self, match):
|
|
for rule in self.c.call("app_state").get("auto_answer_rules", []):
|
|
if rule.get("match") == match:
|
|
return rule.get("uses", 0)
|
|
return None
|
|
|
|
# ---- Scenarios ----
|
|
|
|
def new_project_scenario(self):
|
|
s = "a new project"
|
|
self.start(s, tab="home")
|
|
self.run("view_set", tab="home")
|
|
undo_steps(self.c)
|
|
reply = self.c.call("action_run", id=NEW_PROJECT)
|
|
self.t.check(f"{s} 1: the reply is not held by a dialog", reply.get("status") != "blocked_by_dialog", reply)
|
|
self.t.equal(f"{s} 1: the reply's ran", reply.get("ran"), "orca_command:new_project:orca")
|
|
self.follow(reply, "action_run")
|
|
self.project_is(f"{s} 1", "Untitled", None, "clean")
|
|
self.no_dialog(f"{s} 1")
|
|
self.tab_is(f"{s} 1", "prepare")
|
|
self.steps_are(f"{s} 1", ["Reset Project", "New Project"])
|
|
|
|
self.run("view_set", tab="home")
|
|
undo_steps(self.c)
|
|
reply = self.run("project_new", silent=True)
|
|
self.t.equal(f"{s} 2: the reply",
|
|
{k: reply.get(k) for k in ("objects", "names", "plates", "discarded", "modified")},
|
|
{"objects": 0, "names": [], "plates": 1, "discarded": None, "modified": None})
|
|
self.project_is(f"{s} 2", "Untitled", None, "clean")
|
|
self.tab_is(f"{s} 2", "home")
|
|
self.steps_are(f"{s} 2", ["Reset Project", "New Project"])
|
|
|
|
self.cube("box", 20, 128, 128)
|
|
self.run("view_set", tab="home")
|
|
self.t.refused(f"{s} 3: refused", lambda: self.c.call("project_new", silent=True), code="unsaved_changes")
|
|
self.project_is(f"{s} 3", "Untitled", None, "dirty")
|
|
self.placed(f"{s} 3", ("box", 128, 128))
|
|
self.tab_is(f"{s} 3", "home")
|
|
|
|
self.run("view_set", tab="home")
|
|
reply = self.run("project_new", discard_changes=True)
|
|
self.t.equal(f"{s} 4: the reply's objects", reply.get("objects"), 0)
|
|
self.project_is(f"{s} 4", "Untitled", None, "clean")
|
|
self.names_are(f"{s} 4")
|
|
self.tab_is(f"{s} 4", "home")
|
|
|
|
self.run("settings_set", values={"top_shell_layers": 7})
|
|
self.project_is(f"{s} 5", "Untitled", None, "dirty")
|
|
self.values_are(f"{s} 5", {"top_shell_layers": "7"})
|
|
self.unsaved_is(f"{s} 5", ["top_shell_layers"])
|
|
|
|
self.run("view_set", tab="home")
|
|
reply = self.c.call("action_run", id=NEW_PROJECT)
|
|
self.t.equal(f"{s} 6: the reply", reply.get("status"), "blocked_by_dialog")
|
|
self.titles_are(f"{s} 6: a project with no objects asks nothing about saving it", [NEW_PROJECT_QUESTION])
|
|
self.project_is(f"{s} 6", "Untitled", None, "dirty")
|
|
self.run("dialog_answer", dialog={"title": NEW_PROJECT_QUESTION}, button="Discard")
|
|
self.follow(reply, "action_run")
|
|
self.project_is(f"{s} 7", "Untitled", None, "clean")
|
|
self.values_are(f"{s} 7", {"top_shell_layers": "5"})
|
|
self.unsaved_is(f"{s} 7", [])
|
|
self.no_dialog(f"{s} 7")
|
|
self.tab_is(f"{s} 7", "prepare")
|
|
|
|
self.run("settings_set", values={"top_shell_layers": 7})
|
|
self.run("view_set", tab="home")
|
|
reply = self.c.call("action_run", id=NEW_PROJECT)
|
|
self.titles_are(f"{s} 8: the question of 6", [NEW_PROJECT_QUESTION])
|
|
self.run("dialog_answer", dialog={"title": NEW_PROJECT_QUESTION}, button="Transfer")
|
|
self.follow(reply, "action_run")
|
|
self.project_is(f"{s} 8", "Untitled", None, "clean")
|
|
self.values_are(f"{s} 8: the change is carried into the new project", {"top_shell_layers": "7"})
|
|
self.unsaved_is(f"{s} 8", ["top_shell_layers"])
|
|
self.tab_is(f"{s} 8", "prepare")
|
|
|
|
self.run("view_set", tab="home")
|
|
reply = self.run("project_new", discard_changes=True, preset_changes="discard")
|
|
self.t.equal(f"{s} 9: the reply's presets", (reply.get("discarded"), reply.get("modified")),
|
|
({"process": {"name": PROCESS, "keys": ["top_shell_layers"]}}, None))
|
|
self.project_is(f"{s} 9", "Untitled", None, "clean")
|
|
self.values_are(f"{s} 9", {"top_shell_layers": "5"})
|
|
self.unsaved_is(f"{s} 9", [])
|
|
self.tab_is(f"{s} 9", "home")
|
|
|
|
self.run("settings_set", values={"top_shell_layers": 7})
|
|
self.run("view_set", tab="home")
|
|
self.t.refused(f"{s} 10: refused", lambda: self.c.call("project_new", silent=True), code="unsaved_changes")
|
|
self.project_is(f"{s} 10", "Untitled", None, "dirty")
|
|
self.values_are(f"{s} 10", {"top_shell_layers": "7"})
|
|
self.tab_is(f"{s} 10", "home")
|
|
|
|
self.run("view_set", tab="home")
|
|
reply = self.run("project_new", discard_changes=True)
|
|
self.t.equal(f"{s} 11: the reply's presets", (reply.get("modified"), reply.get("discarded")),
|
|
({"process": {"name": PROCESS, "keys": ["top_shell_layers"]}}, None))
|
|
self.project_is(f"{s} 11", "Untitled", None, "clean")
|
|
self.values_are(f"{s} 11: the presets' changes carry over by default", {"top_shell_layers": "7"})
|
|
self.unsaved_is(f"{s} 11", ["top_shell_layers"])
|
|
|
|
def layer_gcode_scenario(self):
|
|
s = "the question keeps the layer G-code"
|
|
self.start(s)
|
|
self.cube("kept", 20, 100, 100)
|
|
reply = self.run("project_save", path=self.w("kept.3mf"))
|
|
self.project_is(f"{s} 1", "kept", "kept.3mf", "clean")
|
|
self.saved(f"{s} 1", reply, "kept.3mf")
|
|
|
|
self.sliced_ok(f"{s} 2", self.run("plate_slice"), 100)
|
|
self.flags_are(f"{s} 2", [True])
|
|
self.project_is(f"{s} 2", "kept", "kept.3mf", "clean")
|
|
|
|
reply = self.run("plate_set_custom_gcode", add=[{"layer": 26, "type": "pause"}])
|
|
self.t.equal(f"{s} 3: the reply's layer G-code",
|
|
[{"z": round(g.get("z", 0), 4), "layer": g.get("layer"), "type": g.get("type")}
|
|
for g in reply.get("layer_gcode", [])], [{"z": 5.2, "layer": 26, "type": "pause"}])
|
|
self.project_is(f"{s} 3", "kept", "kept.3mf", "dirty")
|
|
pause = [{"z": 5.2, "type": "pause"}]
|
|
rounded = lambda: [{"z": round(g["z"], 4), "type": g["type"]} for g in layer_gcode(self.c)]
|
|
self.t.equal(f"{s} 3: the layer G-code", rounded(), pause)
|
|
self.flags_are(f"{s} 3: a layer code invalidates the slice", [False])
|
|
|
|
self.run("object_transform", object=0, translate=[5, 0, 0])
|
|
self.project_is(f"{s} 4", "kept", "kept.3mf", "dirty")
|
|
self.placed(f"{s} 4", ("kept", 105, 100))
|
|
|
|
reply = self.c.call("action_run", id=NEW_PROJECT)
|
|
shown = dialogs(self.c)
|
|
self.t.equal(f"{s} 5: the question", [d["title"] for d in shown], [SAVE_QUESTION])
|
|
self.t.check(f"{s} 5: the question says the project has unsaved changes",
|
|
shown and "The current project has unsaved changes" in (shown[0]["message"] or ""), shown)
|
|
self.run("dialog_answer", dialog={"title": SAVE_QUESTION}, button="Cancel")
|
|
self.follow(reply, "action_run")
|
|
self.project_is(f"{s} 5", "kept", "kept.3mf", "dirty")
|
|
self.placed(f"{s} 5", ("kept", 105, 100))
|
|
self.t.equal(f"{s} 5: the layer G-code", rounded(), pause)
|
|
self.no_dialog(f"{s} 5")
|
|
|
|
reply = self.c.call("action_run", id=NEW_PROJECT)
|
|
self.titles_are(f"{s} 6: the question", [SAVE_QUESTION])
|
|
self.run("dialog_answer", dialog={"title": SAVE_QUESTION}, button="Yes")
|
|
self.follow(reply, "action_run")
|
|
self.project_is(f"{s} 6", "Untitled", None, "clean")
|
|
self.names_are(f"{s} 6")
|
|
self.t.equal(f"{s} 6: the layer G-code", rounded(), [])
|
|
self.plates_are(f"{s} 6", '"" 0 *')
|
|
self.tab_is(f"{s} 6", "prepare")
|
|
|
|
self.run("project_open", path=self.w("kept.3mf"))
|
|
self.project_is(f"{s} 7", "kept", "kept.3mf", "clean")
|
|
self.placed(f"{s} 7: the Save wrote the move", ("kept", 105, 100))
|
|
self.t.equal(f"{s} 7: the Save wrote the pause", rounded(), pause)
|
|
|
|
def opened(self, label, reply):
|
|
"""What every open of the source project leaves."""
|
|
self.t.equal(f"{label}: the reply", {k: reply.get(k) for k in ("opened", "objects", "names", "plates")},
|
|
{"opened": "project", "objects": 1, "names": ["source"], "plates": 1})
|
|
self.placed(label, ("source", 100, 100))
|
|
self.values_are(label, {"wall_loops": "5", "top_shell_layers": "5"})
|
|
self.unsaved_is(label, ["wall_loops"])
|
|
self.tab_is(label, "prepare")
|
|
self.no_dialog(label)
|
|
|
|
def open_case(self):
|
|
self.new_project()
|
|
self.run("view_set", tab="home")
|
|
|
|
def opening_scenario(self):
|
|
s = "opening a project"
|
|
self.start(s, tab="home")
|
|
self.cube("source", 20, 100, 100)
|
|
self.run("settings_set", values={"wall_loops": 5})
|
|
self.run("project_save", path=self.w("open_src.3mf"))
|
|
for copy in ("clean.3mf", "dirty.3mf", "presets.3mf"):
|
|
shutil.copyfile(self.w("open_src.3mf"), self.w(copy))
|
|
|
|
self.open_case()
|
|
self.project_is(f"{s} 1", "Untitled", None, "clean")
|
|
self.recent_has(f"{s} 1", "open_src.3mf")
|
|
for copy in ("clean.3mf", "dirty.3mf", "presets.3mf"):
|
|
self.recent_has(f"{s} 1", copy, held=False)
|
|
undo_steps(self.c)
|
|
reply = self.run("project_open", path=self.w("clean.3mf"))
|
|
self.project_is(f"{s} 2", "clean", "clean.3mf", "clean")
|
|
self.opened(f"{s} 2", reply)
|
|
self.recent_has(f"{s} 2", "clean.3mf")
|
|
self.steps_are(f"{s} 2", ["Reset Project", "Load Project"])
|
|
|
|
self.open_case()
|
|
self.cylinder("cyl")
|
|
self.run("view_set", tab="home")
|
|
self.t.refused(f"{s} 3: refused", lambda: self.c.call("project_open", path=self.w("dirty.3mf")),
|
|
code="unsaved_changes")
|
|
self.project_is(f"{s} 3", "Untitled", None, "dirty")
|
|
self.names_are(f"{s} 3", "cyl")
|
|
self.no_dialog(f"{s} 3")
|
|
self.tab_is(f"{s} 3", "home")
|
|
self.recent_has(f"{s} 3", "dirty.3mf", held=False)
|
|
reply = self.run("project_open", path=self.w("dirty.3mf"), discard_changes=True)
|
|
self.project_is(f"{s} 4", "dirty", "dirty.3mf", "clean")
|
|
self.opened(f"{s} 4", reply)
|
|
self.recent_has(f"{s} 4", "dirty.3mf")
|
|
|
|
self.open_case()
|
|
self.run("settings_set", values={"top_shell_layers": 7})
|
|
self.run("view_set", tab="home")
|
|
self.t.refused(f"{s} 5: refused", lambda: self.c.call("project_open", path=self.w("presets.3mf")),
|
|
code="unsaved_changes")
|
|
self.project_is(f"{s} 5", "Untitled", None, "dirty")
|
|
self.names_are(f"{s} 5")
|
|
self.values_are(f"{s} 5", {"top_shell_layers": "7"})
|
|
self.no_dialog(f"{s} 5")
|
|
reply = self.c.call("project_open", path=self.w("presets.3mf"), discard_changes=True)
|
|
self.t.equal(f"{s} 6: the reply", reply.get("status"), "blocked_by_dialog")
|
|
self.titles_are(f"{s} 6", [LOAD_PROJECT_QUESTION])
|
|
self.names_are(f"{s} 6")
|
|
self.values_are(f"{s} 6", {"top_shell_layers": "7"})
|
|
self.unsaved_is(f"{s} 6", ["top_shell_layers"])
|
|
self.project_is(f"{s} 6", "Untitled", None, "clean")
|
|
self.run("dialog_answer", dialog={"title": LOAD_PROJECT_QUESTION}, button="Discard")
|
|
reply = self.follow(reply, "project_open")
|
|
self.project_is(f"{s} 7", "presets", "presets.3mf", "clean")
|
|
self.opened(f"{s} 7: the file's top_shell_layers, the unsaved 7 gone", reply)
|
|
self.recent_has(f"{s} 7", "presets.3mf")
|
|
|
|
def saving_scenario(self):
|
|
s = "saving a project under a name"
|
|
self.start(s)
|
|
undo_steps(self.c)
|
|
reply = self.run("project_save", path=self.w("empty.3mf"))
|
|
self.project_is(f"{s} 1", "empty", "empty.3mf", "clean")
|
|
self.saved(f"{s} 1", reply, "empty.3mf")
|
|
self.recent_has(f"{s} 1: a project with no objects is saved", "empty.3mf")
|
|
self.steps_are(f"{s} 1", [])
|
|
|
|
self.new_project()
|
|
reply = self.c.call("project_open", path=self.w("empty.3mf"))
|
|
self.t.equal(f"{s} 2: the reply", reply.get("status"), "blocked_by_dialog")
|
|
answer_all(self.c, self.t, f"{s} 2", [("Warning", NO_GEOMETRY)])
|
|
reply = self.follow(reply, "project_open")
|
|
self.t.equal(f"{s} 2: the job's reply", {k: reply.get(k) for k in ("opened", "objects", "names", "plates")},
|
|
{"opened": "project", "objects": 0, "names": [], "plates": 1})
|
|
self.project_is(f"{s} 2", "", None, "clean")
|
|
self.plates_are(f"{s} 2", '"" 0 *')
|
|
|
|
self.new_project()
|
|
self.cube("box", 20, 100, 100)
|
|
undo_steps(self.c)
|
|
reply = self.run("project_save", path=self.w("saved.3mf"))
|
|
self.project_is(f"{s} 3", "saved", "saved.3mf", "clean")
|
|
self.saved(f"{s} 3", reply, "saved.3mf")
|
|
self.recent_has(f"{s} 3", "saved.3mf")
|
|
self.steps_are(f"{s} 3", [])
|
|
|
|
self.run("object_transform", object=0, translate=[5, 0, 0])
|
|
self.project_is(f"{s} 4", "saved", "saved.3mf", "dirty")
|
|
self.placed(f"{s} 4", ("box", 105, 100))
|
|
|
|
refusals = [(5, ["saved.gcode.3mf"], {"code": "sliced_file_name"}),
|
|
(6, ["missing", "saved.3mf"], {"words": "directory does not exist"}),
|
|
(7, ["saved.3mf"], {"words": "file exists (pass overwrite: true to replace it)"})]
|
|
for step, names, how in refusals:
|
|
undo_steps(self.c)
|
|
self.t.refused(f"{s} {step}: refused", lambda: self.c.call("project_save", path=self.w(*names)), **how)
|
|
self.project_is(f"{s} {step}", "saved", "saved.3mf", "dirty")
|
|
if step != 7:
|
|
self.no_file(f"{s} {step}", *names[:1])
|
|
self.placed(f"{s} {step}", ("box", 105, 100))
|
|
self.steps_are(f"{s} {step}", [])
|
|
|
|
self.run("project_open", path=self.w("saved.3mf"), discard_changes=True)
|
|
self.project_is(f"{s} 8", "saved", "saved.3mf", "clean")
|
|
self.placed(f"{s} 8: the refused saves wrote nothing", ("box", 100, 100))
|
|
|
|
self.run("object_transform", object=0, translate=[5, 0, 0])
|
|
undo_steps(self.c)
|
|
reply = self.run("project_save", path=self.w("saved.3mf"), overwrite=True)
|
|
self.project_is(f"{s} 9", "saved", "saved.3mf", "clean")
|
|
self.saved(f"{s} 9", reply, "saved.3mf")
|
|
self.placed(f"{s} 9", ("box", 105, 100))
|
|
self.steps_are(f"{s} 9", [])
|
|
|
|
self.new_project()
|
|
self.run("project_open", path=self.w("saved.3mf"))
|
|
self.project_is(f"{s} 10", "saved", "saved.3mf", "clean")
|
|
self.placed(f"{s} 10: the file was replaced", ("box", 105, 100))
|
|
|
|
def importing_scenario(self):
|
|
s = "importing models"
|
|
box = ("20mmbox-LF.stl", 12, 8000, [20, 20, 20])
|
|
self.start(s)
|
|
undo_steps(self.c)
|
|
reply = self.run("project_import", paths=[BOX_STL])
|
|
self.meshes_are(f"{s} 1", box)
|
|
self.t.equal(f"{s} 1: the reply",
|
|
{k: reply.get(k) for k in ("opened", "added", "objects", "names", "plates")},
|
|
{"opened": "models", "added": 1, "objects": 1, "names": ["20mmbox-LF.stl"], "plates": 1})
|
|
self.project_is(f"{s} 1: an untitled project takes the first file's name", "20mmbox-LF", None, "dirty")
|
|
self.steps_are(f"{s} 1", ["Import Objects: 20mmbox-LF.stl"])
|
|
self.unsaved_is(f"{s} 1", [])
|
|
self.t.check(f"{s} 1: recent projects lack the STL", normal(BOX_STL) not in recent(self.c))
|
|
self.run("undo", history="project")
|
|
self.names_are(f"{s} 2: the import is one undo step")
|
|
|
|
self.new_project()
|
|
self.cylinder("cyl")
|
|
self.run("settings_set", values={"top_shell_layers": 7})
|
|
reply = self.run("project_import", paths=[BOX_STL])
|
|
self.names_are(f"{s} 3", "cyl", "20mmbox-LF.stl")
|
|
self.meshes_are(f"{s} 3: the box", box, got=meshes(self.c)[1:])
|
|
self.t.equal(f"{s} 3: the reply's added", reply.get("added"), 1)
|
|
self.project_is(f"{s} 3", "20mmbox-LF", None, "dirty")
|
|
self.values_are(f"{s} 3", {"top_shell_layers": "7"})
|
|
self.unsaved_is(f"{s} 3", ["top_shell_layers"])
|
|
self.run("undo", history="project")
|
|
self.names_are(f"{s} 4", "cyl")
|
|
self.values_are(f"{s} 4", {"top_shell_layers": "7"})
|
|
self.unsaved_is(f"{s} 4", ["top_shell_layers"])
|
|
|
|
self.new_project()
|
|
self.cube("source", 20, 100, 100)
|
|
self.run("settings_set", values={"wall_loops": 5})
|
|
self.run("project_save", path=self.w("import_src.3mf"))
|
|
self.new_project()
|
|
self.cylinder("cyl")
|
|
self.run("settings_set", values={"top_shell_layers": 7})
|
|
self.names_are(f"{s} 5", "cyl")
|
|
self.values_are(f"{s} 5", {"wall_loops": "2", "top_shell_layers": "7"})
|
|
undo_steps(self.c)
|
|
reply = self.c.call("project_import", paths=[self.w("import_src.3mf")])
|
|
self.t.check(f"{s} 6: the reply is not held by a dialog", reply.get("status") != "blocked_by_dialog", reply)
|
|
reply = self.follow(reply, "project_import")
|
|
self.t.equal(f"{s} 6: the reply's added", reply.get("added"), 1)
|
|
self.names_are(f"{s} 6", "cyl", "source")
|
|
self.meshes_are(f"{s} 6: the source", ("source", 12, 8000, [20, 20, 20]), got=meshes(self.c)[1:])
|
|
self.no_dialog(f"{s} 6")
|
|
self.values_are(f"{s} 6: a project's .3mf adds none of its settings",
|
|
{"wall_loops": "2", "top_shell_layers": "7"})
|
|
self.unsaved_is(f"{s} 6", ["top_shell_layers"])
|
|
self.unsaved_is(f"{s} 6", [], "filament")
|
|
self.unsaved_is(f"{s} 6", [], "printer")
|
|
self.project_is(f"{s} 6", "import_src", None, "dirty")
|
|
self.steps_are(f"{s} 6", ["Import Objects: import_src.3mf"])
|
|
self.run("undo", history="project")
|
|
self.names_are(f"{s} 7", "cyl")
|
|
self.values_are(f"{s} 7", {"wall_loops": "2", "top_shell_layers": "7"})
|
|
self.unsaved_is(f"{s} 7", ["top_shell_layers"])
|
|
|
|
self.new_project()
|
|
self.cube("box", 20, 128, 128)
|
|
undo_steps(self.c)
|
|
self.t.refused(f"{s} 8: refused", lambda: self.c.call("project_import", paths=[self.w("missing.stl")]),
|
|
words="file not found")
|
|
self.names_are(f"{s} 8", "box")
|
|
self.steps_are(f"{s} 8", [])
|
|
|
|
for step, path in ((9, HEIGHTMAP), (10, PLA_JSON)):
|
|
undo_steps(self.c)
|
|
reply = self.c.call("project_import", paths=[path])
|
|
self.t.equal(f"{s} {step}: the reply", reply.get("status"), "blocked_by_dialog")
|
|
answer_all(self.c, self.t, f"{s} {step}",
|
|
[("Warning", NO_GEOMETRY), ("Orca Slicer error", "Unknown file format")])
|
|
self.t.refused(f"{s} {step}: the job ends refused", lambda: self.follow(reply, "project_import"),
|
|
code="nothing_loaded")
|
|
self.names_are(f"{s} {step}", "box")
|
|
self.steps_are(f"{s} {step}", [f"Import Objects: {os.path.basename(path)}"])
|
|
self.project_is(f"{s} {step}: an import that adds nothing names nothing", "Untitled", None, "dirty")
|
|
users = self.c.call("preset_list", type="filament", source="user", limit=500)["items"]
|
|
self.t.check(f"{s} 10: a preset file loads no preset", "MCP Import PLA" not in [p.get("name") for p in users],
|
|
[p.get("name") for p in users])
|
|
|
|
def zip_scenario(self):
|
|
s = "ZIP archives"
|
|
T = self.tag
|
|
large = (f"{T}_large.stl", 12, 8000, [20, 20, 20])
|
|
middle = (f"{T}_middle.stl", 12, 3375, [15, 15, 15])
|
|
small = (f"{T}_small.stl", 12, 1000, [10, 10, 10])
|
|
self.start(s)
|
|
with zipfile.ZipFile(self.w("cubes.zip"), "w") as archive:
|
|
for entry, size in ((f"parts/{T}_large.stl", 20), (f"parts/{T}_middle.stl", 15), (f"{T}_small.stl", 10)):
|
|
archive.writestr(entry, cube_stl(size))
|
|
archive.writestr("readme.txt", "not a model\n")
|
|
with open(self.w("not_a.zip"), "w") as f:
|
|
f.write("not an archive\n")
|
|
|
|
named = [f"{T}_small.stl", f"parts/{T}_large.stl"]
|
|
undo_steps(self.c)
|
|
reply = self.run("project_import", paths=[self.w("cubes.zip")], entries=named)
|
|
self.meshes_are(f"{s} 1: in the archive's order", large, small)
|
|
self.t.equal(f"{s} 1: the reply's added", reply.get("added"), 2)
|
|
self.t.equal(f"{s} 1: the reply's archives",
|
|
[{"path": normal(a.get("path", "")), "entries": a.get("entries")}
|
|
for a in reply.get("archives", [])],
|
|
[{"path": normal(self.w("cubes.zip")), "entries": named}])
|
|
self.steps_are(f"{s} 1", ["Import Objects: cubes.zip"])
|
|
self.no_dialog(f"{s} 1")
|
|
self.run("undo", history="project")
|
|
self.names_are(f"{s} 2: one undo step")
|
|
|
|
self.new_project()
|
|
reply = self.run("project_import", paths=[self.w("cubes.zip")])
|
|
self.meshes_are(f"{s} 3", large, middle, small)
|
|
self.t.equal(f"{s} 3: the reply's added", reply.get("added"), 3)
|
|
self.t.equal(f"{s} 3: every model file, and not the text file",
|
|
[a.get("entries") for a in reply.get("archives", [])],
|
|
[[f"parts/{T}_large.stl", f"parts/{T}_middle.stl", f"{T}_small.stl"]])
|
|
undo_steps(self.c)
|
|
self.t.refused(f"{s} 4: refused", lambda: self.c.call("project_import", paths=[self.w("not_a.zip")]),
|
|
code="unreadable_archive")
|
|
self.meshes_are(f"{s} 4", large, middle, small)
|
|
self.steps_are(f"{s} 4", [])
|
|
|
|
self.new_project()
|
|
self.cube("inside_zip", 10, 128, 128)
|
|
self.run("project_export", format="3mf", path=self.w("project.3mf"))
|
|
with zipfile.ZipFile(self.w("project.zip"), "w") as archive:
|
|
archive.write(self.w("project.3mf"), "project.3mf")
|
|
self.names_are(f"{s} 5", "inside_zip")
|
|
|
|
self.new_project()
|
|
self.cube("first", 20, 80, 128)
|
|
self.cube("second", 30, 176, 128)
|
|
undo_steps(self.c)
|
|
reply = self.run("project_import", paths=[self.w("project.zip")])
|
|
self.names_are(f"{s} 6", "first", "second", "inside_zip")
|
|
self.meshes_are(f"{s} 6: inside_zip", ("inside_zip", 12, 1000, [10, 10, 10]), got=meshes(self.c)[2:])
|
|
self.t.equal(f"{s} 6: the reply's added", reply.get("added"), 1)
|
|
self.t.equal(f"{s} 6: the reply's entries", [a.get("entries") for a in reply.get("archives", [])],
|
|
[["project.3mf"]])
|
|
self.no_dialog(f"{s} 6")
|
|
self.project_is(f"{s} 6: an archive names no project", "Untitled", None, "dirty")
|
|
self.steps_are(f"{s} 6", ["Import Objects: project.zip"])
|
|
|
|
def step_call(self, label, tool, **args):
|
|
"""A call that reads the STEP file: it replies blocked_by_dialog on the STEP options, which are answered OK,
|
|
and its job is followed to its end. Returns the job's reply."""
|
|
reply = self.c.call(tool, **args)
|
|
self.t.equal(f"{label}: the reply", (reply.get("status"), [d.get("title") for d in reply.get("dialogs", [])]),
|
|
("blocked_by_dialog", [STEP_DIALOG]))
|
|
self.run("dialog_answer", dialog={"title": STEP_DIALOG}, button="OK")
|
|
reply = self.follow(reply, tool)
|
|
self.no_dialog(label)
|
|
return reply
|
|
|
|
def step_scenario(self):
|
|
s = "a STEP file's mesh options"
|
|
tetra = ("part", 4, 166.667)
|
|
self.start(s)
|
|
reply = self.step_call(f"{s} 1", "project_import", paths=[STEP])
|
|
self.t.equal(f"{s} 1: the job's reply's added", reply.get("added"), 1)
|
|
ids1 = self.parts_are(f"{s} 1", tetra)
|
|
self.t.equal(f"{s} 1: one object", len(meshes(self.c)), 1)
|
|
self.project_is(f"{s} 1", "named_single_body", None, "dirty")
|
|
|
|
self.step_call(f"{s} 2", "part_add", object=0, type="part", path=STEP)
|
|
ids2 = self.parts_are(f"{s} 2", tetra, tetra)
|
|
self.t.equal(f"{s} 2: part 0 keeps its id", ids2[:1], ids1)
|
|
|
|
self.run("part_add", object=0, type="part", shape="cube", size=[5, 5, 5])
|
|
ids3 = self.parts_are(f"{s} 3", tetra, tetra, ("part", 12, 125))
|
|
self.t.equal(f"{s} 3: parts 0 and 1 keep their ids", ids3[:2], ids2)
|
|
self.no_dialog(f"{s} 3")
|
|
|
|
reply = self.step_call(f"{s} 4", "part_replace", object=0, part=2, path=STEP)
|
|
ids4 = self.parts_are(f"{s} 4", tetra, tetra, tetra)
|
|
self.t.equal(f"{s} 4: parts 0 and 1 keep their ids", ids4[:2], ids2)
|
|
self.t.equal(f"{s} 4: part 2 is the reply's part_id", ids4[2], (reply.get("parts") or [{}])[0].get("part_id"))
|
|
self.t.check(f"{s} 4: part 2 is not the cube", ids4[2] != ids3[2], (ids4, ids3))
|
|
self.t.equal(f"{s} 4: one object", len(meshes(self.c)), 1)
|
|
|
|
def exported(self, label, call):
|
|
"""An export of the meshes: no undo step, and the project untitled and dirty."""
|
|
undo_steps(self.c)
|
|
reply = call()
|
|
self.steps_are(label, [])
|
|
self.project_is(label, "Untitled", None, "dirty")
|
|
return reply
|
|
|
|
def folder_is(self, label, folder, sizes):
|
|
names = sorted(os.listdir(self.w(folder)))
|
|
self.t.equal(f"{label}: {folder} holds", names, sorted(sizes))
|
|
if sizes and all(isinstance(v, int) for v in sizes.values()):
|
|
self.t.equal(f"{label}: the sizes in {folder}", {n: os.path.getsize(self.w(folder, n)) for n in names},
|
|
sizes)
|
|
|
|
def meshes_scenario(self):
|
|
s = "exporting meshes"
|
|
self.start(s)
|
|
self.cube("small", 20, 100, 100)
|
|
self.cube("big", 30, 160, 100)
|
|
os.makedirs(self.w("each"))
|
|
os.makedirs(self.w("each_drc"))
|
|
both = [{"index": 0, "name": "small"}, {"index": 1, "name": "big"}]
|
|
objs = lambda reply: [{"index": o.get("index"), "name": o.get("name")} for o in reply.get("objects", [])]
|
|
files = lambda reply: [normal(f) for f in reply.get("files", [])]
|
|
|
|
reply = self.exported(f"{s} 1", lambda: self.run("project_export", format="stl", path=self.w("small.stl"),
|
|
objects=[0]))
|
|
self.t.equal(f"{s} 1: small.stl's size", os.path.getsize(self.w("small.stl")), 684)
|
|
self.t.equal(f"{s} 1: the reply", (objs(reply), reply.get("bytes")), ([{"index": 0, "name": "small"}], 684))
|
|
|
|
reply = self.exported(f"{s} 2", lambda: self.run("project_export", format="stl", path=self.w("both.stl")))
|
|
self.t.equal(f"{s} 2: both.stl's size", os.path.getsize(self.w("both.stl")), 1284)
|
|
self.t.equal(f"{s} 2: the reply", (objs(reply), reply.get("bytes")), (both, 1284))
|
|
|
|
reply = self.exported(f"{s} 3", lambda: self.run("project_export", format="stl", path=self.w("each"),
|
|
per_object=True))
|
|
self.folder_is(f"{s} 3", "each", {"big.stl": 684, "small.stl": 684})
|
|
self.t.equal(f"{s} 3: the reply", (objs(reply), files(reply), "bytes" in reply),
|
|
(both, [normal(self.w("each", "small.stl")), normal(self.w("each", "big.stl"))], False))
|
|
|
|
reply = self.exported(f"{s} 4", lambda: self.run("project_export", format="stl", path=self.w("each"),
|
|
per_object=True))
|
|
self.folder_is(f"{s} 4", "each", {"big(1).stl": 684, "big.stl": 684, "small(1).stl": 684, "small.stl": 684})
|
|
self.t.equal(f"{s} 4: a name the folder has gets a number", files(reply),
|
|
[normal(self.w("each", "small(1).stl")), normal(self.w("each", "big(1).stl"))])
|
|
|
|
reply = self.exported(f"{s} 5", lambda: self.run("project_export", format="drc", path=self.w("both.drc")))
|
|
self.t.equal(f"{s} 5: the reply", objs(reply), both)
|
|
self.saved(f"{s} 5", reply, "both.drc")
|
|
|
|
reply = self.exported(f"{s} 6", lambda: self.run("project_export", format="drc", path=self.w("each_drc"),
|
|
per_object=True))
|
|
self.folder_is(f"{s} 6", "each_drc", {"big.drc": None, "small.drc": None})
|
|
self.t.equal(f"{s} 6: the reply", (objs(reply), files(reply)),
|
|
(both, [normal(self.w("each_drc", "small.drc")), normal(self.w("each_drc", "big.drc"))]))
|
|
|
|
self.exported(f"{s} 7", lambda: self.t.refused(
|
|
f"{s} 7: refused", lambda: self.c.call("project_export", format="3mf", path=self.w("one.3mf"), objects=[0]),
|
|
code="objects_not_taken"))
|
|
self.no_file(f"{s} 7", "one.3mf")
|
|
self.exported(f"{s} 8", lambda: self.t.refused(
|
|
f"{s} 8: refused",
|
|
lambda: self.c.call("project_export", format="stl", path=self.w("five.stl"), objects=[5]),
|
|
code="no_such_object", words="Object 5 does not exist (the project has objects 0..1)"))
|
|
self.no_file(f"{s} 8", "five.stl")
|
|
|
|
self.sliced_ok(f"{s} 9", self.run("plate_slice", preview=True), 150)
|
|
self.flags_are(f"{s} 9", [True])
|
|
reply = self.exported(f"{s} 9", lambda: self.run("project_export", format="toolpaths_obj",
|
|
path=self.w("toolpaths.obj")))
|
|
self.saved(f"{s} 9", reply, "toolpaths.obj")
|
|
self.t.check(f"{s} 9: toolpaths.mtl is written", os.path.exists(self.w("toolpaths.mtl")))
|
|
facts = obj_facts(self.w("toolpaths.obj"))
|
|
self.t.equal(f"{s} 9: the OBJ's first line and material library", (facts["first"], facts["mtllib"]),
|
|
("# G-Code Toolpaths", "mtllib ./toolpaths.mtl"))
|
|
self.t.check(f"{s} 9: the OBJ has vertices and faces", facts["v"] > 0 and facts["f"] > 0, facts)
|
|
self.t.near(f"{s} 9: the OBJ's highest vertex, big's top layer plus half its height", facts["top"], 30.1, 0.01)
|
|
self.placed(f"{s} 10: the exports moved nothing", ("small", 100, 100), ("big", 160, 100))
|
|
|
|
r = lambda path: reimport(self.c, path)[1]
|
|
self.meshes_are(f"{s}: small.stl read back", ("small.stl", 12, 8000, [20, 20, 20]), got=r(self.w("small.stl")))
|
|
self.meshes_are(f"{s}: both.stl read back, both cubes as placed in one object",
|
|
("both.stl", 24, 35000, [85, 30, 30]), got=r(self.w("both.stl")))
|
|
reimport(self.c, self.w("each", "small.stl"))
|
|
self.run("project_import", paths=[self.w("each", "big.stl")])
|
|
self.meshes_are(f"{s}: each read back", ("small.stl", 12, 8000, [20, 20, 20]),
|
|
("big.stl", 12, 27000, [30, 30, 30]))
|
|
self.meshes_are(f"{s}: both.drc read back", ("both.drc", 24, 35000, [85, 30, 30]), got=r(self.w("both.drc")))
|
|
reimport(self.c, self.w("each_drc", "small.drc"))
|
|
self.run("project_import", paths=[self.w("each_drc", "big.drc")])
|
|
self.meshes_are(f"{s}: each_drc read back", ("small.drc", 12, 8000, [20, 20, 20]),
|
|
("big.drc", 12, 27000, [30, 30, 30]))
|
|
|
|
def model_3mf_scenario(self):
|
|
s = "exporting the model as a 3MF"
|
|
self.start(s)
|
|
self.cube("box", 20, 100, 100)
|
|
undo_steps(self.c)
|
|
reply = self.run("project_export", format="3mf", path=self.w("model.3mf"))
|
|
self.placed(f"{s} 1", ("box", 100, 100))
|
|
self.saved(f"{s} 1", reply, "model.3mf")
|
|
self.project_is(f"{s} 1: the export does not make the file the project's", "Untitled", None, "dirty")
|
|
self.recent_has(f"{s} 1", "model.3mf", held=False)
|
|
self.steps_are(f"{s} 1", [])
|
|
self.run("undo", history="project")
|
|
self.names_are(f"{s} 2: undo takes back the cube")
|
|
reply, got = reimport(self.c, self.w("model.3mf"))
|
|
self.meshes_are(f"{s} 3", ("box", 12, 8000, [20, 20, 20]), got=got)
|
|
self.t.equal(f"{s} 3: the reply's added", reply.get("added"), 1)
|
|
self.project_is(f"{s} 3", "model", None, "dirty")
|
|
|
|
def sliced_scenario(self):
|
|
s = "exporting the sliced file"
|
|
self.start(s)
|
|
plate_1 = "Metadata/plate_1.gcode"
|
|
|
|
def export(step, name, flags, steps=(), **args):
|
|
undo_steps(self.c)
|
|
self.run("project_export", format="sliced_3mf", path=self.w(name), **args)
|
|
self.project_is(f"{s} {step}", "Untitled", None, "dirty")
|
|
self.flags_are(f"{s} {step}", flags)
|
|
self.steps_are(f"{s} {step}", list(steps))
|
|
return sliced(self.w(name))
|
|
|
|
self.cube("a", 20, 128, 128)
|
|
wait(self.c, "idle")
|
|
got = export(1, "unsliced.gcode.3mf", [False])
|
|
self.plates_are(f"{s} 1", '"" 1 *')
|
|
self.t.equal(f"{s} 1: a plate not sliced is written without G-code", list(got), [])
|
|
|
|
self.sliced_ok(f"{s} 2", self.run("plate_slice"), 100)
|
|
got = export(2, "sliced.gcode.3mf", [True])
|
|
self.plates_are(f"{s} 2", '"" 1 *')
|
|
self.t.equal(f"{s} 2: the G-code entries", list(got), [plate_1])
|
|
self.t.equal(f"{s} 2: the G-code's layers and labels",
|
|
[(g["layers"], g["labels"]) for g in got.values()], [(100, 1)])
|
|
|
|
self.run("plate_add")
|
|
self.run("object_add_primitive", shape="cube", size=[20, 20, 20], name="b", plate=1)
|
|
self.sliced_ok(f"{s} 3", self.run("plate_slice", plates=0), 100)
|
|
self.run("plate_select", plate=0)
|
|
self.plates_are(f"{s} 3", '"" 1 *', '"" 1')
|
|
two = [True, False]
|
|
self.t.equal(f"{s} 4: the G-code entries", list(export(4, "half_current.gcode.3mf", two)), [plate_1])
|
|
self.plates_are(f"{s} 4", '"" 1 *', '"" 1')
|
|
self.t.equal(f"{s} 5: plate 1, not sliced, adds none",
|
|
list(export(5, "half_all.gcode.3mf", two, plates="all")), [plate_1])
|
|
self.plates_are(f"{s} 5", '"" 1 *', '"" 1')
|
|
self.t.equal(f"{s} 6: the G-code entries",
|
|
list(export(6, "half_1.gcode.3mf", two, SELECTED, plates=1)), [])
|
|
self.plates_are(f"{s} 6: the plate named is made current", '"" 1', '"" 1 *')
|
|
self.t.equal(f"{s} 7: the G-code entries", list(export(7, "from_1.gcode.3mf", two)), [])
|
|
self.plates_are(f"{s} 7", '"" 1', '"" 1 *')
|
|
self.t.equal(f"{s} 8: the G-code entries", list(export(8, "all_from_1.gcode.3mf", two, plates="all")),
|
|
[plate_1])
|
|
self.plates_are(f"{s} 8", '"" 1', '"" 1 *')
|
|
self.t.equal(f"{s} 9: the G-code entries",
|
|
list(export(9, "half_0.gcode.3mf", two, SELECTED, plates=0)), [plate_1])
|
|
self.plates_are(f"{s} 9", '"" 1 *', '"" 1')
|
|
|
|
undo_steps(self.c)
|
|
self.t.refused(f"{s} 10: refused", lambda: self.c.call("project_export", format="gcode",
|
|
path=self.w("plate_1.gcode"), plates=1),
|
|
code="plate_not_sliced")
|
|
self.no_file(f"{s} 10", "plate_1.gcode")
|
|
self.plates_are(f"{s} 10: a refused export leaves the current plate", '"" 1 *', '"" 1')
|
|
self.steps_are(f"{s} 10: and the undo history", [])
|
|
self.project_is(f"{s} 10", "Untitled", None, "dirty")
|
|
self.flags_are(f"{s} 10", two)
|
|
|
|
def gcode_refused_scenario(self):
|
|
s = "a G-code export refused"
|
|
self.start(s)
|
|
|
|
def refused(step, name, code, state="dirty", **args):
|
|
undo_steps(self.c)
|
|
self.t.refused(f"{s} {step}: refused", lambda: self.c.call("project_export", path=self.w(name), **args),
|
|
code=code)
|
|
self.no_file(f"{s} {step}", name)
|
|
self.project_is(f"{s} {step}", "Untitled", None, state)
|
|
self.steps_are(f"{s} {step}", [])
|
|
|
|
refused(1, "empty.gcode", "no_objects", state="clean", format="gcode")
|
|
self.plates_are(f"{s} 1", '"" 0 *')
|
|
self.cube("a", 20, 100, 128)
|
|
wait(self.c, "idle")
|
|
refused(2, "unsliced.gcode", "plate_not_sliced", format="gcode")
|
|
self.flags_are(f"{s} 2", [False])
|
|
self.plates_are(f"{s} 2", '"" 1 *')
|
|
refused(3, "three.gcode", "no_such_plate", format="gcode", plates=3)
|
|
self.plates_are(f"{s} 3", '"" 1 *')
|
|
|
|
self.cube("b", 20, 160, 128)
|
|
self.run("dialog_auto_answer", rules=[{"match": SPIRAL, "button": "yes"}])
|
|
self.run("plate_set_settings", plate=0, values={"spiral_mode": True})
|
|
reply = self.run("plate_slice")
|
|
self.t.equal(f"{s} 4: the spiral question was answered once", self.rule_uses(SPIRAL), 1)
|
|
self.t.equal(f"{s} 4: spiral vase mode prints one object",
|
|
[p.get("outcome") for p in reply.get("plates", [])], ["error"])
|
|
self.flags_are(f"{s} 4", [False])
|
|
self.plates_are(f"{s} 4", '"" 2 *')
|
|
refused(5, "error.gcode", "slice_has_errors", format="gcode")
|
|
self.plates_are(f"{s} 5", '"" 2 *')
|
|
refused(6, "error.gcode.3mf", "sliced_file_not_written", format="sliced_3mf")
|
|
self.plates_are(f"{s} 6", '"" 2 *')
|
|
self.run("dialog_auto_answer", rules=[])
|
|
|
|
def gcode_written_scenario(self):
|
|
s = "the G-code written"
|
|
self.start(s)
|
|
self.cube("box", 20, 128, 128)
|
|
self.run("settings_set", values={"layer_height": 0.25, "initial_layer_print_height": 0.25})
|
|
self.sliced_ok(f"{s} 1", self.run("plate_slice"), 80)
|
|
self.flags_are(f"{s} 1", [True])
|
|
self.names_are(f"{s} 1", "box")
|
|
|
|
for step, name in ((2, "box.gcode"), (3, "box_again.gcode")):
|
|
undo_steps(self.c)
|
|
reply = self.run("project_export", format="gcode", path=self.w(name))
|
|
there = os.path.exists(self.w(name))
|
|
self.t.equal(f"{s} {step}: the reply",
|
|
{"export": reply.get("export"), "path": normal(reply.get("path", ""))},
|
|
{"export": "ok", "path": normal(self.w(name))})
|
|
self.t.check(f"{s} {step}: the file is there when the reply comes", there)
|
|
facts = gcode(self.w(name)) if there else {"config": {}}
|
|
self.t.equal(f"{s} {step}: the G-code", (facts.get("layers"), facts.get("labels"),
|
|
facts["config"].get("layer_height"),
|
|
facts["config"].get("initial_layer_print_height")),
|
|
(80, 1, "0.25", "0.25"))
|
|
self.steps_are(f"{s} {step}", [])
|
|
self.project_is(f"{s} {step}", "Untitled", None, "dirty")
|
|
self.names_are(f"{s} {step}", "box")
|
|
self.flags_are(f"{s} 4: an export leaves the slice as it was", [True])
|
|
self.project_is(f"{s} 4", "Untitled", None, "dirty")
|
|
self.run("undo", history="project")
|
|
self.names_are(f"{s} 5: undo takes back the cube")
|
|
|
|
def slice_in_thread(self, action):
|
|
"""Starts `action` from a second client of the session in a thread; the box gets its result or error."""
|
|
box = {}
|
|
|
|
def go():
|
|
try:
|
|
other = orca_mcp.OrcaMcp(self.session["port"], self.session["token"])
|
|
box["result"] = other.await_job(other.call("action_run", id=action))
|
|
except Exception as e: # reported by the scenario
|
|
box["error"] = e
|
|
|
|
thread = threading.Thread(target=go)
|
|
thread.start()
|
|
return thread, box
|
|
|
|
def overlapping(self, label, action):
|
|
"""Attempts until an export overlaps the second client's slice: returns (walls, refusal, thread, box), or None
|
|
after three attempts in a row that do not overlap or a refusal with other words, failing the check."""
|
|
misses = []
|
|
while len(misses) < 3:
|
|
walls = self.next_walls
|
|
self.next_walls += 1
|
|
self.run("settings_set", values={"wall_loops": walls})
|
|
wait(self.c, "idle")
|
|
thread, box = self.slice_in_thread(action)
|
|
deadline, seen = time.monotonic() + 10, False
|
|
while time.monotonic() < deadline:
|
|
if self.c.call("app_state").get("slicing"):
|
|
seen = True
|
|
break
|
|
if not thread.is_alive():
|
|
break
|
|
time.sleep(0.005)
|
|
else:
|
|
thread.join()
|
|
self.t.check(f"{label}: the slice shows or its call ends within 10 s", False, walls)
|
|
return None
|
|
if seen:
|
|
try:
|
|
reply = self.c.call("project_export", format="gcode", path=self.w(f"during_{walls}.gcode"))
|
|
misses.append(f"{walls}: the export went through: {reply}")
|
|
except orca_mcp.McpError as e:
|
|
text = str(e)
|
|
if "Busy: job" in text:
|
|
self.t.check(f"{label}: an export during the slice is refused with Busy: job", True)
|
|
return walls, text, thread, box
|
|
thread.join()
|
|
self.t.check(f"{label}: an export during the slice is refused with Busy: job", False, text)
|
|
return None
|
|
else:
|
|
misses.append(f"{walls}: the slice ended before it was seen")
|
|
thread.join()
|
|
self.t.check(f"{label}: an export during the slice is refused with Busy: job", False, misses)
|
|
return None
|
|
|
|
def while_slicing_scenario(self):
|
|
s = "an export while a slice runs"
|
|
self.start(s)
|
|
reply = self.run("project_import", paths=[BENCHY])
|
|
wait(self.c, "idle")
|
|
self.names_are(f"{s} 1", "3DBenchy.drc")
|
|
self.t.equal(f"{s} 1: the reply's added", reply.get("added"), 1)
|
|
self.project_is(f"{s} 1", "3DBenchy", None, "dirty")
|
|
for steps, action, after in (("2-3", "orca_command:slice_and_preview:orca", "after_preview.gcode"),
|
|
("4", "orca_command:slice_all:orca", "after_all.gcode")):
|
|
label = f"{s} {steps}"
|
|
found = self.overlapping(label, action)
|
|
if found is None:
|
|
continue
|
|
walls, _, thread, box = found
|
|
self.no_file(label, f"during_{walls}.gcode")
|
|
self.project_is(label, "3DBenchy", None, "dirty")
|
|
thread.join(600)
|
|
result = box.get("result") or {}
|
|
self.t.check(f"{label}: the second client's call ends without an error", "error" not in box,
|
|
box.get("error"))
|
|
plates_ = result.get("plates", [])
|
|
self.t.equal(f"{label}: the slice's result", (result.get("status"), [p.get("outcome") for p in plates_]),
|
|
("done", ["ok"]))
|
|
layers = plates_[0].get("layers") if plates_ else None
|
|
wait(self.c, "idle")
|
|
undo_steps(self.c)
|
|
reply = self.run("project_export", format="gcode", path=self.w(after))
|
|
self.flags_are(label, [True])
|
|
self.t.equal(f"{label}: the export", reply.get("export"), "ok")
|
|
facts = gcode(self.w(after))
|
|
self.t.equal(f"{label}: the G-code's layers and walls",
|
|
(facts["layers"], facts["config"].get("wall_loops")), (layers, str(walls)))
|
|
self.tab_is(label, "preview")
|
|
self.project_is(label, "3DBenchy", None, "dirty")
|
|
self.steps_are(label, [])
|
|
self.names_are(label, "3DBenchy.drc")
|
|
|
|
def sending_scenario(self):
|
|
s = "sending G-code without a print host"
|
|
self.start(s)
|
|
host = ["bbl_use_printhost", "print_host"]
|
|
|
|
def after_send(step):
|
|
self.t.equal(f"{s} {step}: no upload", self.c.call("app_state").get("uploads"), [])
|
|
self.no_dialog(f"{s} {step}")
|
|
|
|
self.values_are(f"{s} 1", {"bbl_use_printhost": "0", "print_host": ""}, "printer")
|
|
self.t.equal(f"{s} 1: no upload", self.c.call("app_state").get("uploads"), [])
|
|
# On the X1 Carbon, which prints through the Bambu network, Send opens the dialog that sends to the printer's
|
|
# storage, which messages a printer: the scenario makes it a print host before its first send.
|
|
self.run("settings_set", type="printer", values={"bbl_use_printhost": True, "host_type": "octoprint",
|
|
"print_host": "", "use_3mf": False})
|
|
self.t.refused(f"{s} 2: refused, an empty address being no print host, with no objects",
|
|
lambda: self.c.call("action_run", id=SEND), code="no_print_host")
|
|
self.values_are(f"{s} 2", {"bbl_use_printhost": "1", "print_host": ""}, "printer")
|
|
after_send(2)
|
|
self.cube("box", 20, 128, 128)
|
|
self.sliced_ok(f"{s} 3", self.run("plate_slice"), 100)
|
|
self.flags_are(f"{s} 3", [True])
|
|
self.t.refused(f"{s} 3: refused", lambda: self.c.call("action_run", id=SEND), code="no_print_host")
|
|
self.values_are(f"{s} 3", {"bbl_use_printhost": "1", "print_host": ""}, "printer")
|
|
after_send(3)
|
|
self.new_project()
|
|
self.values_are(f"{s} 4", {"bbl_use_printhost": "0", "print_host": ""}, "printer")
|
|
self.unsaved_is(f"{s} 4", [], "printer")
|
|
|
|
def filaments_scenario(self):
|
|
s = "filament slots merged and mixed"
|
|
self.start(s)
|
|
for _ in range(32):
|
|
if "," not in slots(self.c):
|
|
break
|
|
self.run("filament_delete")
|
|
filaments = lambda: [(m["name"], m["filament"]) for m in meshes(self.c)]
|
|
self.t.equal(f"{s} 1", slots(self.c), "0")
|
|
for step, slot in ((2, 2), (3, 3)):
|
|
reply = self.run("filament_add")
|
|
self.t.equal(f"{s} {step}: the reply", (reply.get("filament_slot"), reply.get("filament_slots")),
|
|
(slot, slot))
|
|
self.t.equal(f"{s} {step}", slots(self.c), ",".join(["0"] * slot))
|
|
for i, colour in enumerate(("#FF0000", "#00FF00", "#0000FF")):
|
|
self.run("project_set_settings", values={"filament_colour": {"index": i, "value": colour}})
|
|
self.t.equal(f"{s} 4", slots(self.c), "0,0,0")
|
|
self.t.equal(f"{s} 4: the colours", self.colours(), "#FF0000;#00FF00;#0000FF")
|
|
self.cube("on_two", 20, 80, 128)
|
|
self.cube("on_three", 20, 176, 128)
|
|
self.run("settings_set", target="object", object=0, values={"extruder": 2})
|
|
self.run("settings_set", target="object", object=1, values={"extruder": 3})
|
|
self.t.equal(f"{s} 5", slots(self.c), "0,0,0")
|
|
self.t.equal(f"{s} 5: the objects' filaments", filaments(), [("on_two", 2), ("on_three", 3)])
|
|
|
|
reply = self.run("filament_delete", filament_slot=2, merge_into=1)
|
|
self.t.equal(f"{s} 6: the reply", {k: reply.get(k) for k in ("filament_slot", "merged_into", "filament_slots")},
|
|
{"filament_slot": 2, "merged_into": 1, "filament_slots": 2})
|
|
self.t.equal(f"{s} 6", slots(self.c), "0,0")
|
|
self.t.equal(f"{s} 6: the slot after the deleted one moved down, with its objects", filaments(),
|
|
[("on_two", 1), ("on_three", 2)])
|
|
self.t.equal(f"{s} 6: the colours", self.colours(), "#FF0000;#0000FF")
|
|
|
|
for step, added in ((7, True), (8, False)):
|
|
reply = self.run("filament_add_mixed", components=[1, 2], ratios=[50, 50])
|
|
self.t.equal(f"{s} {step}: the reply", (reply.get("filament_slot"), reply.get("added")), (3, added))
|
|
self.t.equal(f"{s} {step}", slots(self.c), "0,0,1")
|
|
self.t.equal(f"{s} {step}: the slots' presets",
|
|
len(self.c.call("app_state")["presets"]["filaments"]), 3)
|
|
self.t.equal(f"{s} {step}: the objects' filaments", filaments(), [("on_two", 1), ("on_three", 2)])
|
|
|
|
self.run("project_save", path=self.w("filaments.3mf"))
|
|
self.run("project_new", discard_changes=True)
|
|
self.run("project_open", path=self.w("filaments.3mf"))
|
|
self.t.equal(f"{s} 9: the project file keeps the mix", slots(self.c), "0,0,1")
|
|
self.t.equal(f"{s} 9: the project file keeps the merge", filaments(), [("on_two", 1), ("on_three", 2)])
|
|
self.t.check(f"{s} 9: the colours", self.colours().startswith("#FF0000;#0000FF;"), self.colours())
|
|
|
|
def run_all(self):
|
|
for name, scenario in [("a new project", self.new_project_scenario),
|
|
("the question keeps the layer G-code", self.layer_gcode_scenario),
|
|
("opening a project", self.opening_scenario),
|
|
("saving a project under a name", self.saving_scenario),
|
|
("importing models", self.importing_scenario),
|
|
("ZIP archives", self.zip_scenario),
|
|
("a STEP file's mesh options", self.step_scenario),
|
|
("exporting meshes", self.meshes_scenario),
|
|
("exporting the model as a 3MF", self.model_3mf_scenario),
|
|
("exporting the sliced file", self.sliced_scenario),
|
|
("a G-code export refused", self.gcode_refused_scenario),
|
|
("the G-code written", self.gcode_written_scenario),
|
|
("an export while a slice runs", self.while_slicing_scenario),
|
|
("sending G-code without a print host", self.sending_scenario),
|
|
("filament slots merged and mixed", self.filaments_scenario)]:
|
|
self.t.scenario(name, scenario)
|
|
self.c.call("dialog_auto_answer", rules=[])
|
|
self.new_project()
|
|
return self.t.exit_code()
|
|
|
|
|
|
def main():
|
|
client, session = orca_mcp.session_client()
|
|
folder = tempfile.mkdtemp(prefix="orca-files-")
|
|
code = FilesTest(client, session, folder).run_all()
|
|
if code == 0:
|
|
shutil.rmtree(folder, ignore_errors=True)
|
|
else:
|
|
print(f"the files written are kept in {folder}")
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|