Exercise vision function rename and byte-for-byte undo on the portable sample
This commit is contained in:
parent
2b66063b4d
commit
f3590d2ee7
@ -55,6 +55,8 @@
|
||||
|
||||
调用 `preview_point_rename(kind, id, newName)` 可重命名轴点位(`AxisPoints`)或机器人点位(`RobotPoints`)。预览会列出同一配方的脚本差异,以及矩阵的起点、X 端点、Y 端点引用(`MatrixReferences`)。轴点位支持直接查询 `ControllersModel.AxisPoints` 时的名称相等比较。机器人点位按所属机器人匹配,支持通过常量名称直接选择唯一机器人后的 `RunPoint`、`Jog` 和 `Points` 查询。运行时名称和无法判定所属机器人的调用会列入 `ManualReferences`,供人工核对。
|
||||
|
||||
调用 `preview_vision_function_rename(id, newName)` 可重命名配方中的视觉功能。预览包括同一配方内 `GetVisionFunction` 的常量名称参数,以及直接查询 `VisionsModel.VisionFunctions` 时的名称相等比较。请核对 `ManualReferences` 中的动态或不确定引用。确认后一起保存 `configuration/vision.json` 和受影响的脚本。
|
||||
|
||||
核对后将草案 ID 交给 `apply_changes`,在 WPF 弹窗确认后一起保存名称和受影响的脚本。要撤销,把**已保存的重命名草案 ID** 传给 `preview_undo`,再对返回的**撤销草案 ID** 调用 `apply_changes` 并确认。变量 ID 始终保留。撤销记录保存在处理本次请求的编辑器或离线 MCP 服务会话中,沿用最近 256 个草案的缓存;关闭会话后记录失效。名称所在的 JSON 文件或该配方的脚本发生冲突时会停止写入。
|
||||
|
||||
## 界面展示
|
||||
|
||||
@ -53,7 +53,18 @@ def prepare_point(sample, directory):
|
||||
caller.write_bytes(source.encode("utf-8"))
|
||||
|
||||
|
||||
def verify(exe, directory, workflow=False, point=False):
|
||||
def prepare_vision(sample, directory):
|
||||
shutil.copytree(sample, directory)
|
||||
caller, = (p for p in directory.rglob("*.cs") if 'p.Name == "定位"' in p.read_text(encoding="utf-8"))
|
||||
source = caller.read_text(encoding="utf-8")
|
||||
source = source.replace('model.ControllersModel.AxisPoints.FirstOrDefault(p => p.Name == "定位")',
|
||||
'model.GetVisionFunction("检查")')
|
||||
source = source.replace('model.ControllersModel.AxisPoints.FirstOrDefault(p => p.Name == flow.Step.ToString())',
|
||||
'model.GetVisionFunction(flow.Step.ToString())')
|
||||
caller.write_bytes(source.encode("utf-8"))
|
||||
|
||||
|
||||
def verify(exe, directory, workflow=False, point=False, vision=False):
|
||||
before = {p: p.read_bytes() for p in directory.rglob("*") if p.is_file()}
|
||||
client = Client(exe, directory, "--allow-write")
|
||||
try:
|
||||
@ -65,6 +76,9 @@ def verify(exe, directory, workflow=False, point=False):
|
||||
("Variables", "计数", "完成计数", "preview_variable_rename", "GetVariable"))
|
||||
if point:
|
||||
kind, old, new, tool = "AxisPoints", "定位", "装配定位", "preview_point_rename"
|
||||
if vision:
|
||||
kind, old, new = "VisionFunctions", "检查", "装配检查"
|
||||
tool, lookup = "preview_vision_function_rename", "GetVisionFunction"
|
||||
items = client.call("list_objects", kind=kind, 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 {}))
|
||||
@ -96,19 +110,20 @@ def verify(exe, directory, workflow=False, point=False):
|
||||
assert client.call("get_object", kind=kind, id=target["id"])["Name"] == old
|
||||
assert client.call("get_object", kind="Workflows", id=script["Id"])["Code"] == script["Before"]
|
||||
assert before == {p: p.read_bytes() for p in directory.rglob("*") if p.is_file()}
|
||||
print("PASS: live editor rename, confirmation, undo and byte-for-byte restore.")
|
||||
print(f"PASS: live editor rename, confirmation, undo and byte-for-byte restore of {len(before)} files.")
|
||||
finally:
|
||||
client.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("mode", choices=["prepare", "verify", "prepare-workflow", "verify-workflow", "prepare-point", "verify-point"])
|
||||
parser.add_argument("mode", choices=["prepare", "verify", "prepare-workflow", "verify-workflow", "prepare-point", "verify-point", "prepare-vision", "verify-vision"])
|
||||
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}[args.mode](args.source, args.project)
|
||||
{"prepare": prepare, "prepare-workflow": prepare_workflow, "prepare-point": prepare_point, "prepare-vision": prepare_vision}[args.mode](args.source, args.project)
|
||||
else:
|
||||
verify(args.source, args.project, workflow=args.mode == "verify-workflow", point=args.mode == "verify-point")
|
||||
verify(args.source, args.project, workflow=args.mode == "verify-workflow", point=args.mode == "verify-point",
|
||||
vision=args.mode == "verify-vision")
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user