summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Shetye2024-10-04 20:00:12 +0530
committerSunil Shetye2024-10-07 11:27:05 +0530
commit1aa0bffec32a82435c2163e956fa2d38bdacd9f6 (patch)
tree8b19919aa561e46462b652bfa0b2b5220017b6e3
parent5acf9b4b3f67a0904d2cf16fb4008da98e1c3d0d (diff)
downloadCommon-Interface-Project-1aa0bffec32a82435c2163e956fa2d38bdacd9f6.tar.gz
Common-Interface-Project-1aa0bffec32a82435c2163e956fa2d38bdacd9f6.tar.bz2
Common-Interface-Project-1aa0bffec32a82435c2163e956fa2d38bdacd9f6.zip
merge the two processors into one function
-rw-r--r--blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js7
-rw-r--r--blocks/eda-frontend/src/redux/actions/saveSchematicActions.js7
-rw-r--r--blocks/eda-frontend/src/utils/GalleryUtils.js26
-rw-r--r--blocks/xcos2xml/links/ExplicitLink.xsl118
-rwxr-xr-xblocks/xcos2xml/replacesplitblocks.sh2
5 files changed, 69 insertions, 91 deletions
diff --git a/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js b/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js
index 751e7d71..d7b371cc 100644
--- a/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js
+++ b/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js
@@ -32,7 +32,7 @@ import { editorZoomIn, editorZoomOut, editorZoomAct, deleteComp, PrintPreview, R
import { useSelector, useDispatch } from 'react-redux'
import { toggleSimulate, closeCompProperties, setSchXmlData, saveSchematic, openLocalSch } from '../../redux/actions/index'
import api from '../../utils/Api'
-import { getXsltProcessor } from '../../utils/GalleryUtils'
+import { transformXcos } from '../../utils/GalleryUtils'
const {
mxUtils
@@ -403,11 +403,10 @@ export default function SchematicToolbar ({ mobileClose, gridRef }) {
reader.onload = function (event) {
const title = filename.replace(re, '')
let dataDump = event.target.result
- let xmlDoc = mxUtils.parseXml(dataDump)
+ const xmlDoc = mxUtils.parseXml(dataDump)
const rexcos = /\.xcos$/i
if (rexcos.test(filename)) {
- getXsltProcessor().then(processor => {
- xmlDoc = processor.transformToDocument(xmlDoc)
+ transformXcos(xmlDoc).then(xmlDoc => {
dataDump = new XMLSerializer().serializeToString(xmlDoc)
readXmlFile(xmlDoc, dataDump, title)
})
diff --git a/blocks/eda-frontend/src/redux/actions/saveSchematicActions.js b/blocks/eda-frontend/src/redux/actions/saveSchematicActions.js
index 18b6a932..818bef29 100644
--- a/blocks/eda-frontend/src/redux/actions/saveSchematicActions.js
+++ b/blocks/eda-frontend/src/redux/actions/saveSchematicActions.js
@@ -4,7 +4,7 @@ import api from '../../utils/Api'
import GallerySchSample from '../../utils/GallerySchSample'
import { renderGalleryXML } from '../../components/SchematicEditor/Helper/ToolbarTools'
import { setTitle } from './index'
-import { getXsltProcessor } from '../../utils/GalleryUtils'
+import { transformXcos } from '../../utils/GalleryUtils'
export const setSchTitle = (title) => (dispatch) => {
dispatch({
@@ -166,7 +166,7 @@ export const loadGallery = (saveId) => (dispatch, getState) => {
// Check if the data is xcos or xml
const parser = new DOMParser()
- let xmlDoc = parser.parseFromString(data.data_dump, 'application/xml')
+ const xmlDoc = parser.parseFromString(data.data_dump, 'application/xml')
const isXcos = xmlDoc.getElementsByTagName('XcosDiagram').length > 0
const handleGalleryLoad = (dispatch, data, dataDump) => {
@@ -182,8 +182,7 @@ export const loadGallery = (saveId) => (dispatch, getState) => {
}
if (isXcos) {
- getXsltProcessor().then(processor => {
- xmlDoc = processor.transformToDocument(xmlDoc)
+ transformXcos(xmlDoc).then(xmlDoc => {
const dataDump = new XMLSerializer().serializeToString(xmlDoc)
handleGalleryLoad(dispatch, data, dataDump)
}).catch(error => {
diff --git a/blocks/eda-frontend/src/utils/GalleryUtils.js b/blocks/eda-frontend/src/utils/GalleryUtils.js
index b1035a00..54fd408e 100644
--- a/blocks/eda-frontend/src/utils/GalleryUtils.js
+++ b/blocks/eda-frontend/src/utils/GalleryUtils.js
@@ -1,4 +1,4 @@
-export const getXsltProcessor = async () => {
+const getXsltProcessor = async () => {
const xcos2xml = '/xcos2xml.xsl'
const response = await fetch(xcos2xml)
const text = await response.text()
@@ -9,7 +9,7 @@ export const getXsltProcessor = async () => {
return processor
}
-export const getSplitXsltProcessor = async () => {
+const getSplitXsltProcessor = async () => {
const xcos2xml = '/splitblock.xsl'
const response = await fetch(xcos2xml)
const text = await response.text()
@@ -19,3 +19,25 @@ export const getSplitXsltProcessor = async () => {
processor.importStylesheet(xsl)
return processor
}
+
+export const transformXcos = async (xmlDoc) => {
+ const splitBlock = /<SplitBlock /g
+ const splitProcessor = await getSplitXsltProcessor()
+ let dataDump = new XMLSerializer().serializeToString(xmlDoc)
+ let count = dataDump.match(splitBlock).length
+ console.log('count=', count)
+ while (count > 0) {
+ xmlDoc = splitProcessor.transformToDocument(xmlDoc)
+ dataDump = new XMLSerializer().serializeToString(xmlDoc)
+ const matches = dataDump.match(splitBlock)
+ const newCount = matches ? matches.length : 0
+ if (newCount !== count - 1) {
+ console.error('newCount=', newCount, ', count=', count)
+ }
+ count = newCount
+ console.log('count=', count)
+ }
+ const processor = await getXsltProcessor()
+ xmlDoc = processor.transformToDocument(xmlDoc)
+ return xmlDoc
+}
diff --git a/blocks/xcos2xml/links/ExplicitLink.xsl b/blocks/xcos2xml/links/ExplicitLink.xsl
index baa13ea4..4800ec1e 100644
--- a/blocks/xcos2xml/links/ExplicitLink.xsl
+++ b/blocks/xcos2xml/links/ExplicitLink.xsl
@@ -1,4 +1,4 @@
-<xsl:template match="ExplicitLink | CommandControlLink | ImplicitLink">
+ <xsl:template match="ExplicitLink | CommandControlLink | ImplicitLink">
<xsl:variable name="sourceId" select="@source"/>
<xsl:variable name="sourceElement" select="//*[@id = $sourceId]"/>
<xsl:variable name="sourceElemId" select="$sourceElement/@parent"/>
@@ -8,83 +8,41 @@
<xsl:variable name="targetElemId" select="$targetElement/@parent"/>
<xsl:variable name="parentTargetElement" select="//*[@id = $targetElemId]"/>
<mxCell>
- <!-- <xsl:choose> -->
- <!-- <xsl:when test="name($parentElement) != 'SplitBlock' and name($parentTargetElement) != 'SplitBlock'" > -->
- <!-- <xsl:copy> -->
-
- <!-- <xsl:copy-of select="@*"/> -->
- <xsl:attribute name="id">
- <xsl:value-of select="@id" />
- </xsl:attribute>
- <xsl:attribute name="edge">1</xsl:attribute>
- <xsl:attribute name="sourceVertex">
- <xsl:value-of select="$sourceId" />
- </xsl:attribute>
- <xsl:attribute name="targetVertex">
- <xsl:value-of select="$targetId" />
- </xsl:attribute>
- <xsl:attribute name="tarx">
- <xsl:choose>
- <xsl:when test="mxGeometry/mxPoint[@as='targetPoint']">
- <xsl:value-of select="mxGeometry/mxPoint[@as='targetPoint']/@x" />
- </xsl:when>
- <xsl:when test="mxGeometry/mxPoint[@as='sourcePoint']">
- <xsl:value-of select="mxGeometry/mxPoint[@as='sourcePoint']/@x" />
- </xsl:when>
- <xsl:otherwise>0</xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
- <xsl:attribute name="tary">
- <xsl:choose>
- <xsl:when test="mxGeometry/mxPoint[@as='targetPoint']">
- <xsl:value-of select="mxGeometry/mxPoint[@as='targetPoint']/@y" />
- </xsl:when>
- <xsl:when test="mxGeometry/mxPoint[@as='sourcePoint']">
- <xsl:value-of select="mxGeometry/mxPoint[@as='sourcePoint']/@y" />
- </xsl:when>
- <xsl:otherwise>0</xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
- <xsl:attribute name="CellType">Unknown</xsl:attribute>
-
- <xsl:copy-of select="node()"/>
- <Object as="parameter_values"/>
- <Object as="displayProperties"/>
- <!-- </xsl:copy> -->
- <!-- </xsl:when> -->
-
- <!-- </xsl:choose> -->
+ <xsl:attribute name="id">
+ <xsl:value-of select="@id" />
+ </xsl:attribute>
+ <xsl:attribute name="edge">1</xsl:attribute>
+ <xsl:attribute name="sourceVertex">
+ <xsl:value-of select="$sourceId" />
+ </xsl:attribute>
+ <xsl:attribute name="targetVertex">
+ <xsl:value-of select="$targetId" />
+ </xsl:attribute>
+ <xsl:attribute name="tarx">
+ <xsl:choose>
+ <xsl:when test="mxGeometry/mxPoint[@as='targetPoint']">
+ <xsl:value-of select="mxGeometry/mxPoint[@as='targetPoint']/@x" />
+ </xsl:when>
+ <xsl:when test="mxGeometry/mxPoint[@as='sourcePoint']">
+ <xsl:value-of select="mxGeometry/mxPoint[@as='sourcePoint']/@x" />
+ </xsl:when>
+ <xsl:otherwise>0</xsl:otherwise>
+ </xsl:choose>
+ </xsl:attribute>
+ <xsl:attribute name="tary">
+ <xsl:choose>
+ <xsl:when test="mxGeometry/mxPoint[@as='targetPoint']">
+ <xsl:value-of select="mxGeometry/mxPoint[@as='targetPoint']/@y" />
+ </xsl:when>
+ <xsl:when test="mxGeometry/mxPoint[@as='sourcePoint']">
+ <xsl:value-of select="mxGeometry/mxPoint[@as='sourcePoint']/@y" />
+ </xsl:when>
+ <xsl:otherwise>0</xsl:otherwise>
+ </xsl:choose>
+ </xsl:attribute>
+ <xsl:attribute name="CellType">Unknown</xsl:attribute>
+ <xsl:copy-of select="node()"/>
+ <Object as="parameter_values"/>
+ <Object as="displayProperties"/>
</mxCell>
- </xsl:template>
-<!-- <xsl:template match="ExplicitLink | CommandControlLink | ImplicitLink">
- <xsl:variable name="sourceId" select="@source" />
- <xsl:variable name="sourceParentId" select="//*[@id = $sourceId]/@parent" />
- <xsl:variable name="sourceParentName" select="name(//*[@id = $sourceParentId])" />
- <xsl:variable name="targetId" select="@target" />
- <xsl:variable name="targetParentId" select="//*[@id = $targetId]/@parent" />
- <xsl:variable name="targetParentName" select="name(//*[@id = $targetParentId])" />
- <xsl:if test="$sourceParentName != 'SplitBlock' and $targetParentName != 'SplitBlock'">
- <xsl:element name="mxCell">
- <xsl:attribute name="id">
- <xsl:value-of select="@id" />
- </xsl:attribute>
- <xsl:attribute name="id">
- <xsl:value-of select="@id" />
- </xsl:attribute>
- <xsl:attribute name="edge">1</xsl:attribute>
- <xsl:attribute name="sourceVertex">
- <xsl:value-of select="@source" />
- </xsl:attribute>
- <xsl:attribute name="targetVertex">
- <xsl:value-of select="@target" />
- </xsl:attribute>
- <xsl:attribute name="node">.null</xsl:attribute>
- <xsl:attribute name="CellType">Unknown</xsl:attribute>
- <xsl:attribute name="tarx">0</xsl:attribute>
- <xsl:attribute name="tary">0</xsl:attribute>
- <mxGeometry relative="1" as="geometry" />
- <Object as="parameter_values"/>
- <Object as="displayProperties"/>
- </xsl:element>
- </xsl:if>
- </xsl:template> --> \ No newline at end of file
+ </xsl:template>
diff --git a/blocks/xcos2xml/replacesplitblocks.sh b/blocks/xcos2xml/replacesplitblocks.sh
index 2c98d00e..d223c5cd 100755
--- a/blocks/xcos2xml/replacesplitblocks.sh
+++ b/blocks/xcos2xml/replacesplitblocks.sh
@@ -58,7 +58,7 @@ trap "cat $TMPFILE2; rm -f $TMPFILE1 $TMPFILE2" 0 1 2 15
if test -n "$INPUTXML"; then
xmllint --format "$INPUTXML" > "$TMPFILE2"
- if ! diff -q "$TMPFILE2" "$INPUTXML"; then
+ if ! diff -q "$TMPFILE2" "$INPUTXML" >&2; then
cp -f "$TMPFILE2" "$INPUTXML"
echo "$INPUTXML updated" >&2
fi