diff options
author | Suchita Lad | 2025-06-06 17:45:03 +0530 |
---|---|---|
committer | Suchita Lad | 2025-06-12 16:11:17 +0530 |
commit | e152b0e58cf0bdbb9f5f83383b45551ff5a284ba (patch) | |
tree | 4830ca65aa40804c2f59aade069528cd60c81c68 | |
parent | d2d27bb9e50b52eb588fe2f286cb83037307e6a9 (diff) | |
download | Common-Interface-Project-e152b0e58cf0bdbb9f5f83383b45551ff5a284ba.tar.gz Common-Interface-Project-e152b0e58cf0bdbb9f5f83383b45551ff5a284ba.tar.bz2 Common-Interface-Project-e152b0e58cf0bdbb9f5f83383b45551ff5a284ba.zip |
Code for xmldoc in superblock
-rw-r--r-- | blocks/eda-frontend/src/components/SchematicEditor/Helper/ComponentDrag.js | 1 | ||||
-rw-r--r-- | blocks/eda-frontend/src/pages/SchematicEditor.js | 91 |
2 files changed, 88 insertions, 4 deletions
diff --git a/blocks/eda-frontend/src/components/SchematicEditor/Helper/ComponentDrag.js b/blocks/eda-frontend/src/components/SchematicEditor/Helper/ComponentDrag.js index fd59ae5b..66371cee 100644 --- a/blocks/eda-frontend/src/components/SchematicEditor/Helper/ComponentDrag.js +++ b/blocks/eda-frontend/src/components/SchematicEditor/Helper/ComponentDrag.js @@ -160,6 +160,7 @@ export default function loadGrid (container, sidebar, outline, setMainDiagramBac const blockType = styleToObject(cell.style).default // Extract block type like 'SUPER_f' if (blockType === 'SUPER_f') { + console.log("CE:", cell.SuperBlockDiagram) // Save current diagram setMainDiagramBackup(getCurrentDiagramXML()) setActiveSuperBlockCell(cell) diff --git a/blocks/eda-frontend/src/pages/SchematicEditor.js b/blocks/eda-frontend/src/pages/SchematicEditor.js index f7db30b9..1acd4ba6 100644 --- a/blocks/eda-frontend/src/pages/SchematicEditor.js +++ b/blocks/eda-frontend/src/pages/SchematicEditor.js @@ -18,6 +18,20 @@ import { renderGalleryXML } from '../components/SchematicEditor/Helper/ToolbarTo import '../components/SchematicEditor/Helper/SchematicEditor.css' import { fetchDiagram, fetchSchematic } from '../redux/saveSchematicSlice' import { useDispatch, useSelector } from 'react-redux' +import { styleToObject } from '../utils/GalleryUtils' +import { changePorts } from '../components/SchematicEditor/ComponentProperties' +import { graph } from '../components/SchematicEditor/Helper/ComponentDrag' +import mxGraphFactory from 'mxgraph' +const { + mxPrintPreview, + mxConstants, + mxRectangle, + mxUtils, + mxUndoManager, + mxEvent, + mxCodec, + mxPoint +} = new mxGraphFactory() const useStyles = makeStyles((_theme) => ({ root: { @@ -50,16 +64,84 @@ export default function SchematicEditor (props) { if (!activeSuperBlockCell) return const updatedXML = getCurrentDiagramXML() - const updatedDOM = new DOMParser().parseFromString(updatedXML, 'text/xml') + 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 + + const xpath = ".//mxCell[@style]" + const xpathResult = document.evaluate( + xpath, + activeSuperBlockCell.SuperBlockDiagram, + null, + XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, + 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) + + 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] + // console.log('mapping:', mapping) + // if (mapping) { + // portCounts[mapping.field] += count * mapping.count + // } + // }) - activeSuperBlockCell.SuperBlockDiagram = updatedDOM.documentElement + // 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 blockElem = mainDOM.querySelector(`mxCell[id="${superBlockID}"]`) + + 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 existing = blockElem.querySelector('SuperBlockDiagram') + + const refreshDisplay = changePorts(activeSuperBlockCell, styleCounts['IN_f'], styleCounts[2], styleCounts[0], styleCounts[5], styleCounts[4], styleCounts[1], true) + console.log('blockElem:', blockElem, 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) @@ -70,6 +152,7 @@ export default function SchematicEditor (props) { const updatedMainXML = new XMLSerializer().serializeToString(mainDOM) setMainDiagramBackup(updatedMainXML) + console.log('updatedMainXML:', updatedMainXML) renderGalleryXML(updatedMainXML) // Hide the close button |