第8章 AI 网表生成与原理图自动绘制
8.1 网表 JSON 完整结构
interface AIGeneratedNetlist {
components: Array<{
lcsc: string;
designator: string;
deviceType: "resistor" | "capacitor" | "chip" | "diode"
| "triode" | "oscillator" | "inductive" | "otherDevice";
x?: number;
y?: number;
rotation?: number;
}>;
nets: Array<{
name: string;
connections: Array<{
designator: string;
pinNumber: string;
}>;
}>;
netFlags?: Array<{
type: "ground" | "power" | "analogGround" | "protectGround";
netName: string;
}>;
netPorts?: Array<{
type: "in" | "out" | "bi";
netName: string;
position: {
x: number; y: number };
}>;
}
8.2 三步绘制流程
Step 1: AI Agent 分析需求 → 生成网表 JSON
Step 2: EDA 扩展读取网表 → 创建 + 放置元件
Step 3: 自动布局 + 自动布线 → 人工微调
8.3 完整绘制代码
import {
eda, ESYS_ToastMessageType } from '@jlceda/pro-api-types';
async function placeComponents(netlist: AIGeneratedNetlist) {
for (const comp of netlist.components) {
const component = eda.sch_PrimitiveComponent.create();
component.setSupplierId(comp.lcsc);
component.setDesignator(comp.designator);
component.setX(comp.x || 0);
component.setY(comp.y || 0);
component.setRotation(comp.rotation || 0);
await component.done();
}
}
async function createNetFlags(netlist: AIGeneratedNetlist) {
if (!netlist.netFlags) return;
for (const flag of netlist.netFlags) {
const netFlag = eda.sch_PrimitiveComponent.createNetFlag();
switch (flag.type) {
case "ground":
eda.sch_PrimitiveComponent.setNetFlagComponentUuid_Ground();
break;
case "power":
eda.sch_PrimitiveComponent.setNetFlagComponentUuid_Power();
break;
case "analogGround":
eda.sch_PrimitiveComponent.setNetFlagComponentUuid_AnalogGround();
break;
case "protectGround":
eda.sch_PrimitiveComponent.setNetFlagComponentUuid_ProtectGround();
break;
}
await netFlag.done();
}
}
async function autoLayoutAndRoute(netlist: AIGeneratedNetlist) {
const allComponents = await eda.sch_PrimitiveComponent.getAll();
const uuids = allComponents.map(c => c.getPrimitiveId());
const typeMap = Object.fromEntries(
netlist.components.map(c => [c.designator, c.deviceType])
);
await eda.sch_Document.autoLayout({
uuids: uuids,
netlist: netlist,
designatorDeviceTypeMap: typeMap
}