Verify axis rename and byte-for-byte undo on the live WPF sample

This commit is contained in:
wanglei 2026-12-05 22:14:01 +08:00
parent cfb25928cb
commit c2e88950a6
2 changed files with 29 additions and 7 deletions

View File

@ -57,6 +57,8 @@
调用 `preview_vision_function_rename(id, newName)` 可重命名配方中的视觉功能。预览包括同一配方内 `GetVisionFunction` 的常量名称参数,以及直接查询 `VisionsModel.VisionFunctions` 时的名称相等比较。请核对 `ManualReferences` 中的动态或不确定引用。确认后一起保存 `configuration/vision.json` 和受影响的脚本。
调用 `preview_axis_rename(id, newName)` 可按硬件 ID 重命名工程运动轴。预览扫描所有配方的脚本,识别直接查询轴集合时的轴名相等比较,并将动态或不确定的匹配列入 `ManualReferences`。点位的 X、Y、Z、U 轴名及插补组的 X、Y 轴名列在 `PointReferences`。确认后一起保存硬件配置、点位配置和受影响的脚本。
核对后将草案 ID 交给 `apply_changes`,在 WPF 弹窗确认后一起保存名称和受影响的脚本。要撤销,把**已保存的重命名草案 ID** 传给 `preview_undo`,再对返回的**撤销草案 ID** 调用 `apply_changes` 并确认。变量 ID 始终保留。撤销记录保存在处理本次请求的编辑器或离线 MCP 服务会话中,沿用最近 256 个草案的缓存;关闭会话后记录失效。名称所在的 JSON 文件或该配方的脚本发生冲突时会停止写入。
## 界面展示

View File

@ -64,7 +64,17 @@ def prepare_vision(sample, directory):
caller.write_bytes(source.encode("utf-8"))
def verify(exe, directory, workflow=False, point=False, vision=False):
def prepare_axis(sample, directory):
shutil.copytree(sample, directory)
caller, = (p for p in directory.rglob("*.cs") if 'GetVisionFunction("检查")' in p.read_text(encoding="utf-8"))
source = caller.read_text(encoding="utf-8")
source = source.replace('model.GetVisionFunction("检查")', 'model.ControllersModel.Axes.FirstOrDefault(a => a.Name == "X")')
source = source.replace('model.GetVisionFunction(flow.Step.ToString())',
'model.ControllersModel.Axes.FirstOrDefault(a => a.Name == flow.Step.ToString())')
caller.write_bytes(source.encode("utf-8"))
def verify(exe, directory, workflow=False, point=False, vision=False, axis=False):
before = {p: p.read_bytes() for p in directory.rglob("*") if p.is_file()}
client = Client(exe, directory, "--allow-write")
try:
@ -79,7 +89,9 @@ def verify(exe, directory, workflow=False, point=False, vision=False):
if vision:
kind, old, new = "VisionFunctions", "检查", "装配检查"
tool, lookup = "preview_vision_function_rename", "GetVisionFunction"
items = client.call("list_objects", kind=kind, recipeId=recipe)["items"]
if axis:
kind, old, new, tool = "Axes", "X", "横移轴", "preview_axis_rename"
items = client.call("list_objects", kind=kind, **({} if axis else {"recipeId": recipe}))["items"]
target, = (item for item in items if item["name"] == old)
draft = client.call(tool, id=target["id"], newName=new, **({"kind": kind} if point else {}))
plan = draft["Rename"]
@ -88,6 +100,10 @@ def verify(exe, directory, workflow=False, point=False, vision=False):
assert draft["Status"] == "pending" and script["Review"]["Compiled"]
assert manual["confidence"] == "dynamic" and manual["line"] == 6
replacement = f'p.Name == "{new}"' if point else f'{lookup}("{new}")'
if axis:
replacement = f'a.Name == "{new}"'
assert {(ref["Table"], ref["Field"]) for ref in plan["PointReferences"]} == {
("AxisPoints", "AxisXName"), ("InterpolationGroups", "AxisXName")}
if point:
link, = plan["MatrixReferences"]
assert link["Table"] == "Matrices" and link["Field"] == "StartName"
@ -101,8 +117,12 @@ def verify(exe, directory, workflow=False, point=False, vision=False):
if point:
assert client.call("get_object", kind="Matrices", id=link["Id"])["StartName"] == new
metadata = draft["Path"]
assert {p for p, old in before.items() if p.read_bytes() != old} == {
directory / metadata, directory / script["Path"]}
changed = {directory / metadata, directory / script["Path"]}
if axis:
changed.add(directory / "configuration/points.json")
for ref in plan["PointReferences"]:
assert client.call("get_object", kind=ref["Table"], id=ref["Id"])[ref["Field"]] == new
assert {p for p, old in before.items() if p.read_bytes() != old} == changed
undo = client.call("preview_undo", draftId=draft["DraftId"])
assert undo["Rename"]["Compiled"] and undo["Rename"]["UndoOf"] == draft["DraftId"]
assert client.call("apply_changes", draftId=undo["DraftId"])["Status"] == "saved"
@ -117,13 +137,13 @@ def verify(exe, directory, workflow=False, point=False, vision=False):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("mode", choices=["prepare", "verify", "prepare-workflow", "verify-workflow", "prepare-point", "verify-point", "prepare-vision", "verify-vision"])
parser.add_argument("mode", choices=["prepare", "verify", "prepare-workflow", "verify-workflow", "prepare-point", "verify-point", "prepare-vision", "verify-vision", "prepare-axis", "verify-axis"])
parser.add_argument("source", type=Path, help="Sample directory for prepare, MCP executable for verify")
parser.add_argument("project", type=Path)
args = parser.parse_args()
if args.mode.startswith("prepare"):
{"prepare": prepare, "prepare-workflow": prepare_workflow, "prepare-point": prepare_point, "prepare-vision": prepare_vision}[args.mode](args.source, args.project)
{"prepare": prepare, "prepare-workflow": prepare_workflow, "prepare-point": prepare_point, "prepare-vision": prepare_vision, "prepare-axis": prepare_axis}[args.mode](args.source, args.project)
else:
verify(args.source, args.project, workflow=args.mode == "verify-workflow", point=args.mode == "verify-point",
vision=args.mode == "verify-vision")
vision=args.mode == "verify-vision", axis=args.mode == "verify-axis")