diff --git a/src/hook/render/layout.js b/src/hook/render/layout.js index 5d1e814..f395646 100644 --- a/src/hook/render/layout.js +++ b/src/hook/render/layout.js @@ -3,6 +3,7 @@ */ import { globalLookup } from "../global"; +import { pinkLog } from "../utils"; import { Cell, dotConnect, ModuleView } from "./yosys"; // 线段的宽度 @@ -199,9 +200,12 @@ export class Module { */ makeConnectionElkNodes() { const nodes = []; + + // 完成去重 + const id2EdgeCount = new Map(); const edges = []; - const tree = this.view + const tree = this.view; for (const cellName of tree.nameToCell.keys()) { const cell = tree.nameToCell.get(cellName); @@ -281,25 +285,40 @@ export class Module { // 器件当前的口为 input,那么所连接的 port 就必须是 input,即便这个 port 是 output if (connection.direction === 'input') { - const edge = { - // id 遵循 sourcePort-targetPort - id: makeEdgeId(port.id, connection.id), - source: port.id, - sourcePort: dotConnect(port.id, '0'), - target: cell.id, - targetPort: connection.id - }; - - edges.push(edge); + const edgeId = makeEdgeId(port.id, connection.id); + if (!id2EdgeCount.has(edgeId)) { + id2EdgeCount.set(edgeId, 0); + + const edge = { + // id 遵循 sourcePort-targetPort + id: edgeId, + source: port.id, + sourcePort: dotConnect(port.id, '0'), + target: cell.id, + targetPort: connection.id + }; + edges.push(edge); + } + const counter = id2EdgeCount.get(edgeId); + id2EdgeCount.set(edgeId, counter + 1); + } else { - const edge = { - id: makeEdgeId(connection.id, port.id), - source: cell.id, - sourcePort: connection.id, - target: port.id, - targetPort: dotConnect(port.id, '0') - }; - edges.push(edge); + const edgeId = makeEdgeId(connection.id, port.id); + if (!id2EdgeCount.has(edgeId)) { + id2EdgeCount.set(edgeId, 0); + const edge = { + id: edgeId, + source: cell.id, + sourcePort: connection.id, + target: port.id, + targetPort: dotConnect(port.id, '0') + }; + edges.push(edge); + } + + const counter = id2EdgeCount.get(edgeId); + id2EdgeCount.set(edgeId, counter + 1); + } } else if (tree.wireIdToConnection.has(wireId)) { @@ -312,25 +331,39 @@ export class Module { } if (conn.direction === 'input') { - const edge = { - // id 遵循 sourcePort-targetPort - id: makeEdgeId(conn.id, connection.id), - source: cell.id, - sourcePort: connection.id, - target: conn.cell.id, - targetPort: conn.id - }; - - edges.push(edge); + const edgeId = makeEdgeId(conn.id, connection.id); + if (!id2EdgeCount.has(edgeId)) { + id2EdgeCount.set(edgeId, 0); + const edge = { + // id 遵循 sourcePort-targetPort + id: edgeId, + source: cell.id, + sourcePort: connection.id, + target: conn.cell.id, + targetPort: conn.id + }; + edges.push(edge); + } + + const counter = id2EdgeCount.get(edgeId); + id2EdgeCount.set(edgeId, counter + 1); + } else { - const edge = { - id: makeEdgeId(connection.id, conn.id), - source: conn.cell.id, - sourcePort: conn.id, - target: cell.id, - targetPort: connection.id - }; - edges.push(edge); + const edgeId = makeEdgeId(connection.id, conn.id); + if (!id2EdgeCount.has(edgeId)) { + id2EdgeCount.set(edgeId, 0); + const edge = { + id: edgeId, + source: conn.cell.id, + sourcePort: conn.id, + target: cell.id, + targetPort: connection.id + }; + edges.push(edge); + } + + const counter = id2EdgeCount.get(edgeId); + id2EdgeCount.set(edgeId, counter + 1); } } } @@ -339,6 +372,9 @@ export class Module { } } + pinkLog('#edge: ' + edges.length); + this.id2EdgeCount = id2EdgeCount; + return [nodes, edges]; }