From f2d07ebf439da229527528dad68fb0b3d303ba65 Mon Sep 17 00:00:00 2001
From: Suchita Lad
Date: Mon, 9 Jun 2025 16:41:11 +0530
Subject: code to add port count
---
blocks/eda-frontend/src/pages/SchematicEditor.js | 111 ++++++++++++-----------
1 file 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 = '' + updatedXML + ''
+ 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 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
+ 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)
--
cgit