устранение ошибки типа данных при экспорте и импорте
This commit is contained in:
parent
948cbfe361
commit
79f67accb0
75
src/App.jsx
75
src/App.jsx
@ -364,7 +364,7 @@ function App() {
|
|||||||
})
|
})
|
||||||
}, [nodes])
|
}, [nodes])
|
||||||
|
|
||||||
const handleExportXml = useCallback(() => {
|
const handleExportXml = useCallback(async () => {
|
||||||
if (nodes.length === 0) {
|
if (nodes.length === 0) {
|
||||||
alert('На холсте нет блоков для экспорта')
|
alert('На холсте нет блоков для экспорта')
|
||||||
return
|
return
|
||||||
@ -451,21 +451,36 @@ function App() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
xml += ` <interface>\n`
|
xml += ` <interface>\n`
|
||||||
xml += ` <localVars>\n`
|
|
||||||
|
|
||||||
const values = new Map()
|
const valuesIn = new Map()
|
||||||
|
const valuesOut = new Map()
|
||||||
nodes.forEach(node => {
|
nodes.forEach(node => {
|
||||||
if ((node.data.type === 'input' || node.data.type === 'output') && node.data.value)
|
if (node.data.type === 'input' && node.data.value)
|
||||||
values.set(node.data.value, node.data.metaFromType || 'ANY')
|
valuesIn.set(node.data.value, node.data.metaFromType || 'ANY')
|
||||||
|
else if (node.data.type === 'output' && node.data.value)
|
||||||
|
valuesOut.set(node.data.value, node.data.metaFromType || 'ANY')
|
||||||
})
|
})
|
||||||
|
|
||||||
values.forEach((type, value) => {
|
if (valuesIn) {
|
||||||
xml += ` <variable name="${value}">\n`
|
xml += ` <inputVars>\n`
|
||||||
xml += ` <type><${getPortType(type)}/></type>\n`
|
valuesIn.forEach((type, value) => {
|
||||||
xml += ` </variable>\n`
|
xml += ` <variable name="${value}">\n`
|
||||||
})
|
xml += ` <type><${getPortType(type)}/></type>\n`
|
||||||
|
xml += ` </variable>\n`
|
||||||
|
})
|
||||||
|
xml += ` </inputVars>\n`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valuesOut) {
|
||||||
|
xml += ` <outputVars>\n`
|
||||||
|
valuesOut.forEach((type, value) => {
|
||||||
|
xml += ` <variable name="${value}">\n`
|
||||||
|
xml += ` <type><${getPortType(type)}/></type>\n`
|
||||||
|
xml += ` </variable>\n`
|
||||||
|
})
|
||||||
|
xml += ` </outputVars>\n`
|
||||||
|
}
|
||||||
|
|
||||||
xml += ` </localVars>\n`
|
|
||||||
xml += ` </interface>\n`
|
xml += ` </interface>\n`
|
||||||
|
|
||||||
xml += ` <body>\n`
|
xml += ` <body>\n`
|
||||||
@ -567,14 +582,32 @@ function App() {
|
|||||||
xml += ` </instances>\n`
|
xml += ` </instances>\n`
|
||||||
xml += `</project>`
|
xml += `</project>`
|
||||||
|
|
||||||
console.log(xml)
|
|
||||||
|
|
||||||
const file = new Blob([xml], {type: 'application/xml'})
|
const file = new Blob([xml], {type: 'application/xml'})
|
||||||
const link = document.createElement('a')
|
if ('showSaveFilePicker' in window) {
|
||||||
link.download = 'fbd-program.xml'
|
try {
|
||||||
link.href = URL.createObjectURL(file)
|
const handle = await window.showSaveFilePicker({
|
||||||
link.click()
|
suggestedName: 'fbd-scheme.xml',
|
||||||
URL.revokeObjectURL(link.href)
|
types: [{
|
||||||
|
description: 'FBD диаграмма в XML',
|
||||||
|
accept: {'application/xml': ['.xml']}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
|
||||||
|
const writable = await handle.createWritable()
|
||||||
|
await writable.write(file)
|
||||||
|
await writable.close()
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log('Сохранение XML отменено или произошла ошибка:', err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.download = 'fbd-program.xml'
|
||||||
|
link.href = URL.createObjectURL(file)
|
||||||
|
link.click()
|
||||||
|
URL.revokeObjectURL(link.href)
|
||||||
|
}
|
||||||
}, [nodes, edges])
|
}, [nodes, edges])
|
||||||
|
|
||||||
const handleImportXml = useCallback((event) => {
|
const handleImportXml = useCallback((event) => {
|
||||||
@ -677,6 +710,7 @@ function App() {
|
|||||||
data: {
|
data: {
|
||||||
type: finalType, label,
|
type: finalType, label,
|
||||||
value: finalValue,
|
value: finalValue,
|
||||||
|
metaFromType: outputPortType,
|
||||||
width, height,
|
width, height,
|
||||||
inputs: [],
|
inputs: [],
|
||||||
outputs: [restoreType(outputPortType)],
|
outputs: [restoreType(outputPortType)],
|
||||||
@ -711,6 +745,7 @@ function App() {
|
|||||||
type: 'output',
|
type: 'output',
|
||||||
label: `${value} (${dataType})`,
|
label: `${value} (${dataType})`,
|
||||||
value,
|
value,
|
||||||
|
metaFromType: dataType,
|
||||||
width, height,
|
width, height,
|
||||||
inputs: [restoreType(dataType)],
|
inputs: [restoreType(dataType)],
|
||||||
outputs: [],
|
outputs: [],
|
||||||
@ -784,7 +819,7 @@ function App() {
|
|||||||
|
|
||||||
const isSwitchType = xmlType.includes('_TO_')
|
const isSwitchType = xmlType.includes('_TO_')
|
||||||
const finalType = isSwitchType ? 'switch_type' : xmlType.toLowerCase()
|
const finalType = isSwitchType ? 'switch_type' : xmlType.toLowerCase()
|
||||||
const width = parseFloat(block.getAttribute('width') || (isSwitchType ? '80' : 50 + (Math.max(input.length, output.length, 2) - 1) * 34))
|
const width = parseFloat(block.getAttribute('width') || (isSwitchType ? '80' : 50 + (Math.max(inputs.length, outputs.length, 2) - 1) * 34))
|
||||||
const height = parseFloat(block.getAttribute('height') || (isSwitchType ? '40' : '60'))
|
const height = parseFloat(block.getAttribute('height') || (isSwitchType ? '40' : '60'))
|
||||||
const newNode = {
|
const newNode = {
|
||||||
id: xmlId,
|
id: xmlId,
|
||||||
@ -878,8 +913,6 @@ function App() {
|
|||||||
const { currentNodes, currentEdges } = updateGraphTypes(finalEdges, finalNodes)
|
const { currentNodes, currentEdges } = updateGraphTypes(finalEdges, finalNodes)
|
||||||
setNodes(currentNodes)
|
setNodes(currentNodes)
|
||||||
setEdges(currentEdges)
|
setEdges(currentEdges)
|
||||||
console.log(currentNodes)
|
|
||||||
console.log(currentEdges)
|
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
alert('Произошла ошибка при обработке соединений')
|
alert('Произошла ошибка при обработке соединений')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user