fix(layout_optimizer): apply code review follow-ups

This commit is contained in:
yexiaozhou
2026-04-03 01:42:22 +08:00
parent 00bdf9b822
commit a7a6d77d7a
12 changed files with 336 additions and 68 deletions

View File

@@ -9,6 +9,7 @@ footprints.json 由 extract_footprints.py 生成,包含碰撞包围盒、开
from __future__ import annotations
from collections import Counter
import json
import logging
from pathlib import Path
@@ -262,11 +263,17 @@ def create_devices_from_list(
"""
footprints = load_footprints()
devices = []
catalog_counts = Counter(spec["id"] for spec in device_specs)
catalog_seen: Counter[str] = Counter()
for spec in device_specs:
catalog_id = spec["id"]
# Use uuid as internal ID when available to ensure uniqueness
# (multiple instances of the same catalog device get different IDs)
dev_id = spec.get("uuid") or catalog_id
catalog_seen[catalog_id] += 1
instance_idx = catalog_seen[catalog_id]
if catalog_counts[catalog_id] > 1 and instance_idx > 1:
dev_id = f"{catalog_id}#{instance_idx}"
else:
dev_id = catalog_id
size = spec.get("size")
if size:
bbox = (float(size[0]), float(size[1]))
@@ -289,6 +296,7 @@ def create_devices_from_list(
bbox=bbox,
device_type=spec.get("device_type", "static"),
openings=openings,
uuid=spec.get("uuid", ""),
)
)
return devices