Home > SCH_PrimitiveBus > modify
SCH_PrimitiveBus.modify() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
修改总线
签名
typescript
function modify(
primitiveId: string | ISCH_PrimitiveBus,
property: {
busName?: undefined | string;
line?: undefined | number[] | number[][];
color?: undefined | null | string;
lineWidth?: undefined | null | number;
lineType?:
| undefined
| null
| ESCH_PrimitiveLineType.SOLID
| ESCH_PrimitiveLineType.DASHED
| ESCH_PrimitiveLineType.DOTTED
| ESCH_PrimitiveLineType.DOT_DASHED;
},
): Promise<ISCH_PrimitiveBus | undefined>;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
参数名
参数 | 类型 | 描述 |
|---|---|---|
primitiveId | string | ISCH_PrimitiveBus | 总线的图元 ID 或总线图元对象 |
property | { busName?: undefined | string; line?: undefined | number[] | number[][]; color?: undefined | null | string; lineWidth?: undefined | null | number; lineType?: undefined | null | ESCH_PrimitiveLineType.SOLID | ESCH_PrimitiveLineType.DASHED | ESCH_PrimitiveLineType.DOTTED | ESCH_PrimitiveLineType.DOT_DASHED } | 修改参数 |
返回值
Promise<ISCH_PrimitiveBus | undefined>
总线图元对象
示例
javascript
// 1. 创建待修改的测试总线(随机坐标避免与画布已有总线重合)
const x = 2000 + Math.floor(Math.random() * 8000);
const y = 2000 + Math.floor(Math.random() * 8000);
const bus = await eda.sch_PrimitiveBus.create('DATA[0..7]', [x, y, x + 400, y], '#FF0000', 6, 1);
const busId = bus.getState_PrimitiveId();
// 2. 读取修改前的名称、线宽与颜色
const beforeName = bus.getState_BusName();
const beforeWidth = bus.getState_LineWidth();
const beforeColor = bus.getState_Color();
// 3. 批量修改:名称 DATA[0..7] → ADDR[0..15]、线宽 6 → 10、颜色改为绿色
await eda.sch_PrimitiveBus.modify(busId, { busName: 'ADDR[0..15]', lineWidth: 10, color: '#00AA00' });
// 4. modify 返回后需要重新 get() 才能读到画布上的最新值
const refreshed = await eda.sch_PrimitiveBus.get(busId);
// 5. 修改类保留现场,供观察修改结果
console.log('primitiveId:', busId);
console.log('busName:', beforeName, '→', refreshed.getState_BusName());
console.log('lineWidth:', beforeWidth, '→', refreshed.getState_LineWidth());
console.log('color:', beforeColor, '→', refreshed.getState_Color());1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22