Skip to content

Commit

Permalink
Merge pull request #255 from suchitalad/xcosblocks
Browse files Browse the repository at this point in the history
Added ordering attribute
  • Loading branch information
sunilshetye authored Oct 29, 2024
2 parents 81d543d + b47abc1 commit 37ce2a6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 21 deletions.
6 changes: 5 additions & 1 deletion blocks/Xcos/MxGraphParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ def addPort3ForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceTy
else:
orderingname = stylename
portCount[ParentComponent][orderingname] += 1
ordering = portCount[ParentComponent][orderingname]

try:
ordering = attrib['ordering']
except KeyError:
ordering = portCount[ParentComponent][orderingname]
geometry = dict(componentGeometry)
mxGeometry = cell.find('mxGeometry')
if mxGeometry is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ function parseXmlToGraph (xmlDoc, graph) {
let cells = xmlDoc.documentElement.children[0].children
let cellslength = cells.length
let remainingcells = []
let portCount
try {
console.log('cellslength=', cellslength)
while (cellslength > 0 && cellslength !== oldcellslength) {
Expand All @@ -410,9 +411,17 @@ function parseXmlToGraph (xmlDoc, graph) {
const cellAttrs = cell.attributes
const cellChildren = cell.children
if (cellAttrs.CellType?.value === 'Component') { // is component
portCount = {
ExplicitInputPort: 0,
ImplicitInputPort: 0,
ControlPort: 0,
ExplicitOutputPort: 0,
ImplicitOutputPort: 0,
CommandPort: 0
}
const style = cellAttrs.style.value
const styleObject = styleToObject(style)
// console.log(styleObject)
console.log(styleObject)
if (styleObject.rotation === undefined) {
blockrotation = 0
} else {
Expand Down Expand Up @@ -479,20 +488,23 @@ function parseXmlToGraph (xmlDoc, graph) {
portrotation = parseInt(styleObject.rotation)
}
let rotate = portrotation - blockrotation
if (stylename == 'ControlPort' || stylename == 'CommandPort') {
if (stylename === 'ControlPort' || stylename === 'CommandPort') {
rotate -= 90
}
if (rotate < 0) {
rotate += 360
}

const vertexId = cellAttrs.id.value
const geom = cellChildren[0].attributes

console.log('CELLATTR:', cellAttrs)
let xPos = (geom.x !== undefined) ? Number(geom.x.value) : 0
let yPos = (geom.y !== undefined) ? Number(geom.y.value) : 0
if (rotate != 0) {
console.log('Ports:', styleObject)
console.log('DIFF:', rotate)
console.log(geom, xPos, yPos, portSize)
}
// if (rotate != 0) {
console.log('Ports:', styleObject)
console.log('DIFF:', rotate)
console.log(geom, xPos, yPos, portSize)
// }
let pointX
let pointY

Expand Down Expand Up @@ -540,40 +552,59 @@ function parseXmlToGraph (xmlDoc, graph) {
pointY = -portSize / 2
break
}
const xPos_old = xPos
const xPosOld = xPos
switch (rotatename.portdirection) {
case L2T:
xPos = yPos
yPos = xPos_old
yPos = xPosOld
break
case L2R:
xPos = 1 - xPos_old
yPos = yPos
xPos = 1 - xPosOld
// yPos = yPos
break
case L2B:
xPos = yPos
yPos = 1 - xPos_old
yPos = 1 - xPosOld
break
case T2R:
xPos = 1 - yPos
yPos = xPos_old
yPos = xPosOld
break
case T2B:
xPos = xPos_old
xPos = xPosOld
yPos = 1 - yPos
break
case T2L:
xPos = yPos
yPos = xPos_old
yPos = xPosOld
break
}

const point = new mxPoint(pointX, pointY)
const vp = graph.insertVertex(v1, vertexId, null, xPos, yPos, portSize, portSize, style)

vp.geometry.relative = true
vp.geometry.offset = point
vp.CellType = 'Pin'
let orderingname
if (stylename === 'ImplicitInputPort') {
orderingname = 'ExplicitInputPort'
} else if (stylename === 'ImplicitOutputPort') {
orderingname = 'ExplicitOutputPort'
} else {
orderingname = stylename
}
portCount[orderingname] += 1
let ordering
if (cellAttrs.ordering) {
ordering = cellAttrs.ordering
} else {
ordering = portCount[orderingname]
}

vp.ordering = ordering
vp.ParentComponent = v1.id
// console.log('vp.ordering =:', cellAttrs.ordering)
} else if (cellAttrs.edge) { // is edge
const edgeId = cellAttrs.id.value

Expand Down
20 changes: 16 additions & 4 deletions blocks/xcos2xml/ports/port.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<xsl:attribute name="id">
<xsl:value-of select="@id" />
</xsl:attribute>
<xsl:attribute name="ordering">
<xsl:value-of select="@ordering" />
</xsl:attribute>
<xsl:attribute name="vertex">1</xsl:attribute>
<xsl:attribute name="CellType">Pin</xsl:attribute>
<xsl:attribute name="ParentComponent">
Expand All @@ -32,7 +35,7 @@
<xsl:attribute name="tarx">0</xsl:attribute>
<xsl:attribute name="tary">0</xsl:attribute>
<mxGeometry>
<xsl:variable name="numerator" select="2 * position() - 1" />
<xsl:variable name="numerator" select="2 * @ordering - 1" />
<xsl:attribute name="y">
<xsl:value-of select="$numerator div (2 * number($explicitInputPorts + $implicitInputPorts))"/>
</xsl:attribute>
Expand All @@ -54,6 +57,9 @@
<xsl:attribute name="id">
<xsl:value-of select="@id" />
</xsl:attribute>
<xsl:attribute name="ordering">
<xsl:value-of select="@ordering" />
</xsl:attribute>
<xsl:attribute name="vertex">1</xsl:attribute>
<xsl:attribute name="CellType">Pin</xsl:attribute>
<xsl:attribute name="ParentComponent">
Expand All @@ -64,7 +70,7 @@
<xsl:attribute name="tarx">0</xsl:attribute>
<xsl:attribute name="tary">0</xsl:attribute>
<mxGeometry>
<xsl:variable name="numerator" select="2 * position() - 1" />
<xsl:variable name="numerator" select="2 * @ordering - 1" />
<xsl:attribute name="x">1</xsl:attribute>
<xsl:attribute name="y">
<xsl:value-of select="$numerator div (2 * number($explicitOutputPorts + $implicitOutputPorts))"/>
Expand All @@ -87,6 +93,9 @@
<xsl:attribute name="id">
<xsl:value-of select="@id" />
</xsl:attribute>
<xsl:attribute name="ordering">
<xsl:value-of select="@ordering" />
</xsl:attribute>
<xsl:attribute name="vertex">1</xsl:attribute>
<xsl:attribute name="CellType">Pin</xsl:attribute>
<xsl:attribute name="ParentComponent">
Expand All @@ -97,7 +106,7 @@
<xsl:attribute name="tarx">0</xsl:attribute>
<xsl:attribute name="tary">0</xsl:attribute>
<mxGeometry>
<xsl:variable name="numerator" select="2 * position() - 1" />
<xsl:variable name="numerator" select="2 * @ordering - 1" />
<xsl:attribute name="x">
<xsl:value-of select="$numerator div (2 * number($commandPorts))"/>
</xsl:attribute>
Expand All @@ -120,6 +129,9 @@
<xsl:attribute name="id">
<xsl:value-of select="@id" />
</xsl:attribute>
<xsl:attribute name="ordering">
<xsl:value-of select="@ordering" />
</xsl:attribute>
<xsl:attribute name="vertex">1</xsl:attribute>
<xsl:attribute name="CellType">Pin</xsl:attribute>
<xsl:attribute name="ParentComponent">
Expand All @@ -130,7 +142,7 @@
<xsl:attribute name="tarx">0</xsl:attribute>
<xsl:attribute name="tary">0</xsl:attribute>
<mxGeometry>
<xsl:variable name="numerator" select="2 * position() - 1" />
<xsl:variable name="numerator" select="2 * @ordering - 1" />
<xsl:attribute name="x">
<xsl:value-of select="$numerator div (2 * number($controlPorts))"/>
</xsl:attribute>
Expand Down

0 comments on commit 37ce2a6

Please sign in to comment.