diff --git a/src/App.vue b/src/App.vue index f1e28b3..e4d64dc 100644 --- a/src/App.vue +++ b/src/App.vue @@ -11,6 +11,9 @@ const palette: PaletteItem[] = [...elements] const viewportRef = ref(null) const worldRef = ref(null) +// 右侧 AI 面板显示开关 +const showAI = ref(true) + const state = reactive({ scale: 1, minScale: 0.2, @@ -277,6 +280,39 @@ function isNearest(instId: string, cpIndex: number) { return !!n && n.instId === instId && n.cpIndex === cpIndex } +// 悬停端点与其连通集高亮 +const hoveredEndpoint = ref(null) +const connectedEndpointSet = computed>(() => { + const set = new Set() + const start = hoveredEndpoint.value + if (!start) return set + // 构建无向邻接表(仅基于导线) + const key = (ep: EndpointRef) => `${ep.instId}:${ep.cpIndex}` + const adj = new Map() + const add = (a: EndpointRef, b: EndpointRef) => { + const ka = key(a), kb = key(b) + if (!adj.has(ka)) adj.set(ka, []) + if (!adj.has(kb)) adj.set(kb, []) + adj.get(ka)!.push(kb) + adj.get(kb)!.push(ka) + } + for (const w of wires) add(w.a, w.b) + // BFS/DFS 查找连通端点 + const startKey = key(start) + const stack = [startKey] + set.add(startKey) + while (stack.length) { + const cur = stack.pop()! + for (const nxt of adj.get(cur) || []) { + if (!set.has(nxt)) { set.add(nxt); stack.push(nxt) } + } + } + return set +}) +function isConnectedEndpoint(instId: string, cpIndex: number) { + return connectedEndpointSet.value.has(`${instId}:${cpIndex}`) +} + // 7.5) 直流电路求解(MNA) // - 支持:电压源(battery)、电阻(resistor/light_bulb/meter)、开关(ON=0V源,OFF=断开)、电感(DC=0V源)、电容(DC=断开) // - 结果:每个实例的端口电压差与电流(方向:从连接点0 -> 连接点1 为正) @@ -861,7 +897,7 @@ function deleteSelected() { -