diff options
author | Suchita Lad | 2024-10-29 17:05:16 +0530 |
---|---|---|
committer | Suchita Lad | 2024-10-29 17:05:16 +0530 |
commit | 9804aa56f5ea1f90467ee10493e54172b2c0debc (patch) | |
tree | 46e8b91baade60ba299a6354907b78a396be90ca | |
parent | 1e0f9abc765e69d9edff0e032f8838c810a34d54 (diff) | |
download | Common-Interface-Project-9804aa56f5ea1f90467ee10493e54172b2c0debc.tar.gz Common-Interface-Project-9804aa56f5ea1f90467ee10493e54172b2c0debc.tar.bz2 Common-Interface-Project-9804aa56f5ea1f90467ee10493e54172b2c0debc.zip |
Added one port_rotation column in newblockport
4 files changed, 58 insertions, 17 deletions
diff --git a/blocks/blocks/xcosblocks/models.py b/blocks/blocks/xcosblocks/models.py index 616e9ed7..3641b2a7 100644 --- a/blocks/blocks/xcosblocks/models.py +++ b/blocks/blocks/xcosblocks/models.py @@ -109,6 +109,7 @@ class NewBlockPort(models.Model): port_part = models.IntegerField(default=1) port_dmg = models.IntegerField(default=1) port_type = models.CharField(max_length=100) + port_rotation = models.IntegerField(default=0) def __str__(self): """String for representing the Model object.""" diff --git a/blocks/blocks/xcosblocks/serializers.py b/blocks/blocks/xcosblocks/serializers.py index 5e802ce1..a97dbf2e 100644 --- a/blocks/blocks/xcosblocks/serializers.py +++ b/blocks/blocks/xcosblocks/serializers.py @@ -100,6 +100,7 @@ class NewBlockPortSerializer(serializers.ModelSerializer): 'port_part', 'port_dmg', 'port_type', + 'port_rotation', ] diff --git a/blocks/eda-frontend/src/components/SchematicEditor/Helper/SvgParser.js b/blocks/eda-frontend/src/components/SchematicEditor/Helper/SvgParser.js index 354c6031..1932a278 100644 --- a/blocks/eda-frontend/src/components/SchematicEditor/Helper/SvgParser.js +++ b/blocks/eda-frontend/src/components/SchematicEditor/Helper/SvgParser.js @@ -3,6 +3,8 @@ import 'mxgraph/javascript/src/css/common.css' import mxGraphFactory from 'mxgraph' +import { getRotationParameters, PORTDIRECTIONS } from './ToolbarTools' + const { mxPoint } = new mxGraphFactory() @@ -64,60 +66,97 @@ export function getSvgMetadata (graph, parent, evt, target, x, y, component) { } for (let i = 0; i < ports; i++) { const blockport = blockports[i] + if (!allowedPart.includes(blockport.port_part)) { continue } if (!allowedDmg.includes(blockport.port_dmg)) { continue } if (blockport.port_name === 'NC') { continue } - const xPos = 1 / 2 + blockport.port_x / defaultScale / width - const yPos = 1 / 2 + blockport.port_y / defaultScale / height + let xPos = 1 / 2 + blockport.port_x / defaultScale / width + let yPos = 1 / 2 + blockport.port_y / defaultScale / height const portOrientation = blockport.port_orientation + const portRotation = blockport.port_rotation + const rotationParameters = getRotationParameters(portOrientation, portRotation) + let pointX let pointY let pins - switch (portOrientation) { + 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': - pointX = -portSize - pointY = -portSize / 2 v1.implicitInputPorts += 1 pins = v1.pins.implicitInputPorts break case 'ControlPort': - pointX = -portSize / 2 - pointY = -portSize v1.controlPorts += 1 pins = v1.pins.controlPorts break case 'ExplicitOutputPort': - pointX = 0 - pointY = -portSize / 2 v1.explicitOutputPorts += 1 pins = v1.pins.explicitOutputPorts break case 'ImplicitOutputPort': - pointX = 0 - pointY = -portSize / 2 v1.implicitOutputPorts += 1 pins = v1.pins.implicitOutputPorts break case 'CommandPort': - pointX = -portSize / 2 - pointY = 0 v1.commandPorts += 1 pins = v1.pins.commandPorts break default: - pointX = -portSize / 2 - pointY = -portSize / 2 pins = null break } + + 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 9b11e5a8..0eaf3bd8 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) } -const PORTDIRECTIONS = { +export const PORTDIRECTIONS = { UNK: 0, LOR: 4, L2T: 5, @@ -364,7 +364,7 @@ const PORTDIRECTIONS = { T2L: 15 } -function getRotationParameters (stylename, rotation) { +export function getRotationParameters (stylename, rotation) { const RotateNames = ['ExplicitInputPort', 'ControlPort', 'ExplicitOutputPort', 'CommandPort', 'ExplicitInputPort', 'ControlPort', 'ExplicitOutputPort', 'CommandPort'] |