diff options
author | Suchita Lad | 2025-06-09 16:41:11 +0530 |
---|---|---|
committer | Suchita Lad | 2025-06-12 16:11:17 +0530 |
commit | f2d07ebf439da229527528dad68fb0b3d303ba65 (patch) | |
tree | 49f9aac670f4107bb3a64d10ee2cee2508f82eb8 | |
parent | e152b0e58cf0bdbb9f5f83383b45551ff5a284ba (diff) | |
download | Common-Interface-Project-f2d07ebf439da229527528dad68fb0b3d303ba65.tar.gz Common-Interface-Project-f2d07ebf439da229527528dad68fb0b3d303ba65.tar.bz2 Common-Interface-Project-f2d07ebf439da229527528dad68fb0b3d303ba65.zip |
code to add port count
-rw-r--r-- | blocks/eda-frontend/src/pages/SchematicEditor.js | 111 |
1 files changed, 57 insertions, 54 deletions
diff --git a/blocks/eda-frontend/src/pages/SchematicEditor.js b/blocks/eda-frontend/src/pages/SchematicEditor.js index 1acd4ba6..ba187844 100644 --- a/blocks/eda-frontend/src/pages/SchematicEditor.js +++ b/blocks/eda-frontend/src/pages/SchematicEditor.js @@ -64,17 +64,23 @@ export default function SchematicEditor (props) { if (!activeSuperBlockCell) return const updatedXML = getCurrentDiagramXML() - console.log('updatedXML::', updatedXML) - const updatedDOM = mxUtils.parseXml(updatedXML) - // const updatedDOM = new DOMParser().parseFromString(updatedXML, 'text/xml') - - activeSuperBlockCell.SuperBlockDiagram = updatedDOM - console.log('activeSuperBlockCell.SuperBlockDiagram:', activeSuperBlockCell.SuperBlockDiagram) - - const prefixes = ['CLKOUTV_f', 'CLKINV_f', 'INIMPL_f', 'OUTIMPL_f', 'IN_f', 'OUT_f'] - // eiv, iiv, con, eov, iov, com + // console.log('updatedXML::', updatedXML) + const xml = '<SuperBlockDiagram as="child" background="-1" title="">' + updatedXML + '</SuperBlockDiagram>' + const updatedDOM = mxUtils.parseXml(xml) + const updatedDOM1 = updatedDOM.getElementsByTagName('SuperBlockDiagram')[0] + activeSuperBlockCell.SuperBlockDiagram = updatedDOM1 + + // Mapping block styles to port count fields + const portMapping = { + 'IN_f': 'explicitInputPorts', + 'INIMPL_f': 'implicitInputPorts', + 'CLKINV_f': 'commandPorts', + 'OUT_f': 'explicitOutputPorts', + 'OUTIMPL_f': 'implicitOutputPorts', + 'CLKOUTV_f': 'controlPorts' + } - const xpath = ".//mxCell[@style]" + const xpath = "/SuperBlockDiagram/mxGraphModel/root/mxCell[@style]" const xpathResult = document.evaluate( xpath, activeSuperBlockCell.SuperBlockDiagram, @@ -83,73 +89,70 @@ export default function SchematicEditor (props) { null ) - // Convert XPathResult to an array const allCells = [] for (let i = 0; i < xpathResult.snapshotLength; i++) { allCells.push(xpathResult.snapshotItem(i)) } + const styleCounts = {} - // Now filter the cells + allCells.forEach(cell => { - console.log("CELL", cell) - const defaultStyle = styleToObject(cell.style).default - // For more precise matching, get only the prefix before the first semicolon - console.log("CELL", defaultStyle) + console.log("CELL1", cell) + const cellAttrs = cell.attributes + console.log('cellAttrs:', cellAttrs) + const style = cellAttrs.style.value + const defaultStyle = styleToObject(style).default + console.log("CELL2", defaultStyle) styleCounts[defaultStyle] = (styleCounts[defaultStyle] || 0) + 1 }) - console.log('Style counts:', styleCounts) - - // Apply counts from matching styles // Object.entries(styleCounts).forEach(([blockStyle, count]) => { - // const blockType = styleToObject(blockStyle).default // get clean style prefix - // console.log('blockType:', blockType) - // const mapping = styleCounts[blockType] + // const mapping = portMapping[blockStyle] // console.log('mapping:', mapping) // if (mapping) { - // portCounts[mapping.field] += count * mapping.count + // activeSuperBlockCell[mapping] = count // } - // }) - - - // const superBlockID = activeSuperBlockCell.id - // const mainDOM = new DOMParser().parseFromString(mainDiagramBackup, 'text/xml') - // const blockElem = mainDOM.querySelector(`mxCell[id="${superBlockID}"]`) - const superBlockID = activeSuperBlockCell.id - const mainDOM = new DOMParser().parseFromString(mainDiagramBackup, 'text/xml') - const cells = mainDOM.getElementsByTagName('mxCell') - let blockElem = null - - for (let i = 0; i < cells.length; i++) { - if (cells[i].getAttribute('id') === superBlockID) { - blockElem = cells[i] - break - } - } - - if (blockElem) { - - const refreshDisplay = changePorts(activeSuperBlockCell, styleCounts['IN_f'], styleCounts[2], styleCounts[0], styleCounts[5], styleCounts[4], styleCounts[1], true) - console.log('blockElem:', blockElem, refreshDisplay) + // }) + console.log('activeSuperBlockCell1:', activeSuperBlockCell) + + if (activeSuperBlockCell) { + const refreshDisplay = changePorts( + activeSuperBlockCell, + styleCounts['OUT_f'] || 0, + styleCounts['OUTIMPL_f'] || 0, + styleCounts['CLKOUTV_f'] || 0, + styleCounts['IN_f'] || 0, + styleCounts['INIMPL_f'] || 0, + styleCounts['CLKINV_f'] || 0, + false + ) + + console.log('blockElem:', activeSuperBlockCell, refreshDisplay) if (refreshDisplay) { graph.refresh() } - // const existing = blockElem.querySelector('SuperBlockDiagram') - // if (existing) existing.remove() - const existing = Array.from(blockElem.childNodes).find(node => node.nodeName === 'SuperBlockDiagram') - if (existing) existing.remove() - - const newElem = mainDOM.importNode(updatedDOM.documentElement, true) - const wrapper = mainDOM.createElement('SuperBlockDiagram') - wrapper.appendChild(newElem) - blockElem.appendChild(wrapper) + + // Remove existing <SuperBlockDiagram> child if present + const existing = activeSuperBlockCell.getElementsByTagName?.('SuperBlockDiagram')?.[0] + if (existing && existing.parentNode) { + existing.parentNode.removeChild(existing) + } + if (existing) { + activeSuperBlockCell.removeChild(existing) + } + + // Create and append the new SuperBlockDiagram element + const newDiagramElement = updatedDOM.documentElement // this is <SuperBlockDiagram> + const importedElement = mainDOM.importNode(newDiagramElement, true) + activeSuperBlockCell.appendChild(importedElement) } + // Update the XML string and reflect it const updatedMainXML = new XMLSerializer().serializeToString(mainDOM) setMainDiagramBackup(updatedMainXML) console.log('updatedMainXML:', updatedMainXML) |