diff --git a/blocks/eda-frontend/src/components/SchematicEditor/Helper/SvgParser.js b/blocks/eda-frontend/src/components/SchematicEditor/Helper/SvgParser.js index 1932a278..f15036be 100644 --- a/blocks/eda-frontend/src/components/SchematicEditor/Helper/SvgParser.js +++ b/blocks/eda-frontend/src/components/SchematicEditor/Helper/SvgParser.js @@ -3,7 +3,7 @@ import 'mxgraph/javascript/src/css/common.css' import mxGraphFactory from 'mxgraph' -import { getRotationParameters, PORTDIRECTIONS } from './ToolbarTools' +import { getRotationParameters, getPins, getPointXY, getXYPos } from './ToolbarTools' const { mxPoint @@ -78,85 +78,16 @@ export function getSvgMetadata (graph, parent, evt, target, x, y, component) { const portRotation = blockport.port_rotation const rotationParameters = getRotationParameters(portOrientation, portRotation) - let pointX - let pointY - let pins - switch (rotationParameters.rotatename) { - case 'ExplicitInputPort': - pointX = -portSize - pointY = -portSize / 2 - break - case 'ControlPort': - pointX = -portSize / 2 - pointY = -portSize - break - case 'ExplicitOutputPort': - pointX = 0 - pointY = -portSize / 2 - break - case 'CommandPort': - pointX = -portSize / 2 - pointY = 0 - break - default: - pointX = -portSize / 2 - pointY = -portSize / 2 - break - } - switch (portOrientation) { - case 'ExplicitInputPort': - v1.explicitInputPorts += 1 - pins = v1.pins.explicitInputPorts - break - case 'ImplicitInputPort': - v1.implicitInputPorts += 1 - pins = v1.pins.implicitInputPorts - break - case 'ControlPort': - v1.controlPorts += 1 - pins = v1.pins.controlPorts - break - case 'ExplicitOutputPort': - v1.explicitOutputPorts += 1 - pins = v1.pins.explicitOutputPorts - break - case 'ImplicitOutputPort': - v1.implicitOutputPorts += 1 - pins = v1.pins.implicitOutputPorts - break - case 'CommandPort': - v1.commandPorts += 1 - pins = v1.pins.commandPorts - break - default: - pins = null - break - } + const pins = getPins(portOrientation, v1) + + const pointXY = getPointXY(rotationParameters) + const pointX = pointXY.pointX + const pointY = pointXY.pointY + + const xyPos = getXYPos(rotationParameters, xPos, yPos) + xPos = xyPos.xPos + yPos = xyPos.yPos - const xPosOld = xPos - switch (rotationParameters.portdirection) { - case PORTDIRECTIONS.L2T: - case PORTDIRECTIONS.T2L: - xPos = yPos - yPos = xPosOld - break - case PORTDIRECTIONS.L2R: - xPos = 1 - xPosOld - /* same yPos */ - break - case PORTDIRECTIONS.L2B: - xPos = yPos - yPos = 1 - xPosOld - break - case PORTDIRECTIONS.T2R: - xPos = 1 - yPos - yPos = xPosOld - break - case PORTDIRECTIONS.T2B: - /* same xPos */ - yPos = 1 - yPos - break - } const point = new mxPoint(pointX, pointY) const vp = graph.insertVertex(v1, null, null, xPos, yPos, portSize, portSize, portOrientation) diff --git a/blocks/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js b/blocks/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js index 0eaf3bd8..f0808acd 100644 --- a/blocks/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js +++ b/blocks/eda-frontend/src/components/SchematicEditor/Helper/ToolbarTools.js @@ -352,7 +352,7 @@ export function renderXML () { parseXmlToGraph(xmlDoc, graph) } -export const PORTDIRECTIONS = { +const PORTDIRECTIONS = { UNK: 0, LOR: 4, L2T: 5, @@ -398,6 +398,96 @@ export function getRotationParameters (stylename, rotation) { return { rotatename, portdirection } } +export function getPins (portOrientation, v1) { + let pins + switch (portOrientation) { + case 'ExplicitInputPort': + v1.explicitInputPorts += 1 + pins = v1.pins?.explicitInputPorts + break + case 'ImplicitInputPort': + v1.implicitInputPorts += 1 + pins = v1.pins?.implicitInputPorts + break + case 'ControlPort': + v1.controlPorts += 1 + pins = v1.pins?.controlPorts + break + case 'ExplicitOutputPort': + v1.explicitOutputPorts += 1 + pins = v1.pins?.explicitOutputPorts + break + case 'ImplicitOutputPort': + v1.implicitOutputPorts += 1 + pins = v1.pins?.implicitOutputPorts + break + case 'CommandPort': + v1.commandPorts += 1 + pins = v1.pins?.commandPorts + break + default: + pins = null + break + } + return pins +} + +export function getPointXY (rotationParameters) { + let pointX + let pointY + switch (rotationParameters.rotatename) { + case 'ExplicitInputPort': + pointX = -portSize + pointY = -portSize / 2 + break + case 'ControlPort': + pointX = -portSize / 2 + pointY = -portSize + break + case 'ExplicitOutputPort': + pointX = 0 + pointY = -portSize / 2 + break + case 'CommandPort': + pointX = -portSize / 2 + pointY = 0 + break + default: + pointX = -portSize / 2 + pointY = -portSize / 2 + break + } + return { pointX, pointY } +} + +export function getXYPos (rotationParameters, xPos, yPos) { + const xPosOld = xPos + switch (rotationParameters.portdirection) { + case PORTDIRECTIONS.L2T: + case PORTDIRECTIONS.T2L: + xPos = yPos + yPos = xPosOld + break + case PORTDIRECTIONS.L2R: + xPos = 1 - xPosOld + /* same yPos */ + break + case PORTDIRECTIONS.L2B: + xPos = yPos + yPos = 1 - xPosOld + break + case PORTDIRECTIONS.T2R: + xPos = 1 - yPos + yPos = xPosOld + break + case PORTDIRECTIONS.T2B: + /* same xPos */ + yPos = 1 - yPos + break + } + return { xPos, yPos } +} + function parseXmlToGraph (xmlDoc, graph) { const parent = graph.getDefaultParent() let v1 @@ -515,76 +605,15 @@ function parseXmlToGraph (xmlDoc, graph) { console.log('rotationParameters:', rotationParameters) } - switch (stylename) { - case 'ExplicitInputPort': - v1.explicitInputPorts += 1 - break - case 'ImplicitInputPort': - v1.implicitInputPorts += 1 - break - case 'ControlPort': - v1.controlPorts += 1 - break - case 'ExplicitOutputPort': - v1.explicitOutputPorts += 1 - break - case 'ImplicitOutputPort': - v1.implicitOutputPorts += 1 - break - case 'CommandPort': - v1.commandPorts += 1 - break - } + getPins(stylename, v1) - let pointX - let pointY - switch (rotationParameters.rotatename) { - case 'ExplicitInputPort': - pointX = -portSize - pointY = -portSize / 2 - break - case 'ControlPort': - pointX = -portSize / 2 - pointY = -portSize - break - case 'ExplicitOutputPort': - pointX = 0 - pointY = -portSize / 2 - break - case 'CommandPort': - pointX = -portSize / 2 - pointY = 0 - break - default: - pointX = -portSize / 2 - pointY = -portSize / 2 - break - } + const pointXY = getPointXY(rotationParameters) + const pointX = pointXY.pointX + const pointY = pointXY.pointY - const xPosOld = xPos - switch (rotationParameters.portdirection) { - case PORTDIRECTIONS.L2T: - case PORTDIRECTIONS.T2L: - xPos = yPos - yPos = xPosOld - break - case PORTDIRECTIONS.L2R: - xPos = 1 - xPosOld - /* same yPos */ - break - case PORTDIRECTIONS.L2B: - xPos = yPos - yPos = 1 - xPosOld - break - case PORTDIRECTIONS.T2R: - xPos = 1 - yPos - yPos = xPosOld - break - case PORTDIRECTIONS.T2B: - /* same xPos */ - yPos = 1 - yPos - break - } + const xyPos = getXYPos(rotationParameters, xPos, yPos) + xPos = xyPos.xPos + yPos = xyPos.yPos const point = new mxPoint(pointX, pointY) const vp = graph.insertVertex(v1, vertexId, null, xPos, yPos, portSize, portSize, style)