Skip to content

Commit

Permalink
Merge pull request #258 from suchitalad/xcosblocks
Browse files Browse the repository at this point in the history
Code of mxpoint
  • Loading branch information
sunilshetye authored Nov 6, 2024
2 parents 03de7e5 + 51cbc86 commit 68722b2
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 75 deletions.
145 changes: 81 additions & 64 deletions blocks/Xcos/MxGraphParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
def check_point_on_array(array, point, left_right_direction=True):
if array is None:
return False, array, []

pointX = float(point['x'])
pointY = float(point['y'])

Expand Down Expand Up @@ -167,11 +167,8 @@ def addPort3ForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceTy
elif sourceType == 'ImplicitLink' or targetType == 'ImplicitLink':
if targetType == 'ImplicitOutputPort' or sourceType == 'ImplicitOutputPort':
return addImplicitInputPortForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceType, targetType, inputCount, outputCount, nextattribid, nextAttribForSplit, array3)
elif targetType == 'ImplicitInputPort' or sourceType == 'ImplicitInputPort':
return addImplicitOutputPortForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceType, targetType, inputCount, outputCount, nextattribid, nextAttribForSplit, array3)
else:
print('Error: (sourceType, targetType, sourceType2, targetType2) =',
'(', sourceType, ',', targetType, ',', sourceType2, ',', targetType2, ')')
return addImplicitOutputPortForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceType, targetType, inputCount, outputCount, nextattribid, nextAttribForSplit, array3)
elif sourceType == 'CommandControlLink':
if targetType == 'ControlPort':
return addCommandPortForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceType, targetType, inputCount, outputCount, nextattribid, nextAttribForSplit, array3)
Expand Down Expand Up @@ -347,7 +344,7 @@ def addPort3ForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceTy
if sourceType in ['ExplicitInputPort', 'ExplicitOutputPort', 'CommandPort', 'ControlPort'] and \
targetType == sourceType:
print(attribid, 'cannot connect two ports of', sourceType, 'and', targetType)
elif sourceType in ['ExplicitLink', 'ImplicitLink', 'CommandControlLink'] and \
elif sourceType in ['ExplicitLink', 'CommandControlLink'] and \
targetType == sourceType:
print(attribid, 'cannot connect two links of', sourceType, 'and', targetType)
elif sourceType in ['ExplicitOutputPort'] and \
Expand Down Expand Up @@ -378,23 +375,35 @@ def addPort3ForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceTy
continue

split_point = None
split_point2 = None
print('attribid:', attribid)
print('targetVertex:', targetVertex, 'blkgeometry:', targetVertex in blkgeometry)
print('sourceVertex:', sourceVertex, 'blkgeometry:', sourceVertex in blkgeometry)
print('tarx' in attrib and 'tary' in attrib)

if sourceVertex in blkgeometry:
vertex = blkgeometry[sourceVertex]
point = {'x': vertex['x'], 'y': vertex['y']}
waypoints.insert(0, point)
elif 'tarx' in attrib and 'tary' in attrib:
if 'tarx' in attrib and 'tary' in attrib and (attrib['tarx'] != '0' or attrib['tary'] != '0'):
point = {'x': attrib['tarx'], 'y': attrib['tary']}
split_point = point
print('SPOINT:', split_point)
waypoints.insert(0, point)
elif sourceVertex in blkgeometry:
vertex = blkgeometry[sourceVertex]
point = {'x': vertex['x'], 'y': vertex['y']}
waypoints.insert(0, point)


if targetVertex in blkgeometry:
if 'tar2x' in attrib and 'tar2y' in attrib and (attrib['tar2x'] != '0' or attrib['tar2y'] != '0'):
point = {'x': attrib['tar2x'], 'y': attrib['tar2y']}
split_point2 = point
print('SPOINT2:', split_point2)
waypoints.append(point)
elif targetVertex in blkgeometry:
vertex = blkgeometry[targetVertex]
point = {'x': vertex['x'], 'y': vertex['y']}
waypoints.append(point)

IDLIST[attribid] = style
link_data = (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point)
link_data = (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point, split_point2)
edgeDict[attribid] = link_data
edgeList.append(link_data)
except BaseException:
Expand All @@ -412,61 +421,69 @@ def addPort3ForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceTy
print()

newEdgeDict = {}
for (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point) in edgeList:
link_data = (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point)

for (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point, split_point2) in edgeList:
link_data = (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point, split_point2)
print('NEWEDGE00:', attribid, waypoints, split_point, addSplit)
if not addSplit:
newEdgeDict[attribid] = [link_data]
print('NEWEDGE:', attribid, waypoints, split_point)
continue

try:
linkSegments = newEdgeDict[sourceVertex]
attribid2 = sourceVertex
except KeyError:
pass
try:
linkSegments = newEdgeDict[targetVertex]
attribid2 = targetVertex
except KeyError:
pass

result, i, left_array, right_array = identify_segment(linkSegments, split_point)
if not result:
sys.exit(0)
(linkid, sourceVertex2, targetVertex2, sourceType2, targetType2, style2, waypoints2, addSplit2, split_point2) = linkSegments[i]
array3 = waypoints

componentOrdering += 1
geometry = {}
geometry['height'] = 7
geometry['width'] = 7
geometry['x'] = split_point['x']
geometry['y'] = split_point['y']
if sourceType2 == 'ControlPort' or sourceType2 == 'CommandPort' or sourceType2 == 'CommandControlLink':
split_style = 'CLKSPLIT_f'
func_name = 'CLKSPLIT_f'
else:
split_style = 'SPLIT_f;flip=false;mirror=false'
func_name = 'SPLIT_f'
SplitBlock(outroot, nextattribid, componentOrdering, geometry, parent=parentattribid, style=split_style, func_name=func_name)
splitblockid = nextattribid
nextattribid += 1

inputCount = 0
outputCount = 0
port1 = nextattribid
(inputCount, outputCount, nextattribid, nextAttribForSplit) = addPort1ForSplit(outroot, splitblockid, sourceVertex2, targetVertex2, sourceType, targetType, sourceType2, targetType2, inputCount, outputCount, nextattribid, nextAttribForSplit, left_array)
port2 = nextattribid
(inputCount, outputCount, nextattribid, nextAttribForSplit) = addPort2ForSplit(outroot, splitblockid, sourceVertex2, targetVertex2, sourceType, targetType, sourceType2, targetType2, inputCount, outputCount, nextattribid, nextAttribForSplit, right_array)
port3 = nextattribid
(inputCount, outputCount, nextattribid, nextAttribForSplit) = addPort3ForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceType, targetType, sourceType2, targetType2, inputCount, outputCount, nextattribid, nextAttribForSplit, array3)

newEdgeDict[attribid2][i] = ((nextAttribForSplit, sourceVertex2, port1, sourceType2, targetType, style2, left_array, addSplit2, split_point2))
nextAttribForSplit += 1
newEdgeDict[attribid2].insert(i + 1, (nextAttribForSplit, port2, targetVertex2, sourceType, targetType2, style2, right_array, addSplit2, split_point2))
nextAttribForSplit += 1
newEdgeDict[attribid] = [(nextAttribForSplit, port3, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point)]
nextAttribForSplit += 1
for attribid2 in sourceVertex, targetVertex:
try:
linkSegments = newEdgeDict[attribid2]
print('linkSegments:',linkSegments)
except KeyError:
continue

print('split_point:', split_point, linkSegments)
result, i, left_array, right_array = identify_segment(linkSegments, split_point)
print('LR:', left_array, right_array)
print('waypoints:',waypoints)
if not result:
sys.exit(0)
(linkid, sourceVertex2, targetVertex2, sourceType2, targetType2, style2, waypoints2, addSplit2, split_point, split_point2) = linkSegments[i]
print('SP2:',split_point2)
array3 = waypoints
print('ARRAY3:',array3)

componentOrdering += 1
geometry = {}
geometry['height'] = 7
geometry['width'] = 7
geometry['x'] = split_point['x']
geometry['y'] = split_point['y']
if sourceType2 == 'ControlPort' or sourceType2 == 'CommandPort' or sourceType2 == 'CommandControlLink':
split_style = 'CLKSPLIT_f'
func_name = 'CLKSPLIT_f'
else:
split_style = 'SPLIT_f;flip=false;mirror=false'
func_name = 'SPLIT_f'
SplitBlock(outroot, nextattribid, componentOrdering, geometry, parent=parentattribid, style=split_style, func_name=func_name)
splitblockid = nextattribid
nextattribid += 1

inputCount = 0
outputCount = 0
port1 = nextattribid
(inputCount, outputCount, nextattribid, nextAttribForSplit) = addPort1ForSplit(outroot, splitblockid, sourceVertex2, targetVertex2, sourceType, targetType, sourceType2, targetType2, inputCount, outputCount, nextattribid, nextAttribForSplit, left_array)
print('nextAttribForSplit1:',nextAttribForSplit)
port2 = nextattribid
(inputCount, outputCount, nextattribid, nextAttribForSplit) = addPort2ForSplit(outroot, splitblockid, sourceVertex2, targetVertex2, sourceType, targetType, sourceType2, targetType2, inputCount, outputCount, nextattribid, nextAttribForSplit, right_array)
print('nextAttribForSplit2:',nextAttribForSplit)
port3 = nextattribid
(inputCount, outputCount, nextattribid, nextAttribForSplit) = addPort3ForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceType, targetType, sourceType2, targetType2, inputCount, outputCount, nextattribid, nextAttribForSplit, array3)
print('nextAttribForSplit3:',nextAttribForSplit)
newEdgeDict[attribid2][i] = ((nextAttribForSplit, sourceVertex2, port1, sourceType2, targetType, style2, left_array, addSplit2, split_point2))
nextAttribForSplit += 1
newEdgeDict[attribid2].insert(i + 1, (nextAttribForSplit, port2, targetVertex2, sourceType, targetType2, style2, right_array, addSplit2, split_point2))
nextAttribForSplit += 1
for (__, __, __, __, __, __, tmp_array, __, tmp_split_point) in newEdgeDict[attribid2]:
print('NEWEDGE2:', attribid2, tmp_array, tmp_split_point )
newEdgeDict[attribid] = [(nextAttribForSplit, port3, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point)]
nextAttribForSplit += 1
for (__, __, __, __, __, __, tmp_array, __, tmp_split_point) in newEdgeDict[attribid]:
print('NEWEDGE3:', attribid, tmp_array, tmp_split_point )

print()
for key, newEdges in newEdgeDict.items():
Expand Down
107 changes: 102 additions & 5 deletions blocks/eda-frontend/public/splitblock.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<xsl:param name="sourcetwotgtsecondlink" />
<xsl:param name="sourcethreesrcsecondlink" />
<xsl:param name="sourcethreetgtsecondlink" />
<xsl:param name="targetonewaypoints" />
<xsl:param name="sourceonewaypoints" />
<xsl:param name="sourcetwowaypoints" />
<xsl:param name="x" />
<xsl:param name="y" />
<xsl:param name="parent" />
Expand Down Expand Up @@ -84,12 +87,23 @@
<xsl:attribute name="value"></xsl:attribute>
<mxGeometry relative="1" as="geometry">
<Array as="points">
<xsl:for-each select="$targetonelink/mxGeometry/Array/mxPoint">
<xsl:element name="waypoint">
<xsl:attribute name="waypoint1">
<xsl:value-of select="$targetonewaypoints" />
</xsl:attribute>
<xsl:attribute name="waypoint2">
<xsl:value-of select="$sourceonewaypoints" />
</xsl:attribute>
<xsl:attribute name="waypoint3">
<xsl:value-of select="$sourcetwowaypoints" /> <!-- removed by suchita $targetonelink/@source-->
</xsl:attribute>
</xsl:element>
<!-- <xsl:for-each select="$targetonewaypoints">
<xsl:copy-of select="." />
</xsl:for-each>
<xsl:for-each select="$sourceonelink/mxGeometry/Array/mxPoint">
<xsl:for-each select="$sourceonewaypoints">
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:for-each> -->
</Array>
<xsl:for-each select="$targetonelink/mxGeometry/mxPoint">
<xsl:copy>
Expand Down Expand Up @@ -171,9 +185,9 @@
<xsl:attribute name="as">sourcePoint</xsl:attribute>
</mxPoint>
<Array as="points">
<xsl:for-each select="$sourcetwolink/mxGeometry/Array/mxPoint">
<!-- <xsl:for-each select="$sourcetwowaypoints">
<xsl:copy-of select="." />
</xsl:for-each>
</xsl:for-each> -->
</Array>
</mxGeometry>
</xsl:element>
Expand Down Expand Up @@ -270,6 +284,9 @@
<xsl:variable name="sourcethreesrcsecondlink" select="key('k-srclink', $sourcethreelink/@id)" />
<xsl:variable name="sourcethreetgtsecondlink" select="key('k-tgtlink', $sourcethreelink/@id)" />

<xsl:variable name="targetonewaypoints" select="$targetonelink/mxGeometry/Array/mxPoint" />
<xsl:variable name="sourceonewaypoints" select="$sourceonelink/mxGeometry/Array/mxPoint" />
<xsl:variable name="sourcetwowaypoints" select="$sourcetwolink/mxGeometry/Array/mxPoint" />
<xsl:call-template name="links">
<xsl:with-param name="linktype" select="$linktype"/>
<xsl:with-param name="targetonelink" select="$targetonelink"/>
Expand Down Expand Up @@ -313,6 +330,9 @@
<xsl:variable name="sourcethreesrcsecondlink" select="key('k-commandsrclink', $sourcecommandthreelink/@id)" />
<xsl:variable name="sourcethreetgtsecondlink" select="key('k-commandtgtlink', $sourcecommandthreelink/@id)" />

<xsl:variable name="targetonewaypoints" select="$targetcommandonelink/mxGeometry/Array/mxPoint" />
<xsl:variable name="sourceonewaypoints" select="$sourcecommandonelink/mxGeometry/Array/mxPoint" />
<xsl:variable name="sourcetwowaypoints" select="$sourcecommandtwolink/mxGeometry/Array/mxPoint" />
<xsl:call-template name="links">
<xsl:with-param name="linktype" select="$linktype"/>
<xsl:with-param name="targetonelink" select="$targetcommandonelink"/>
Expand All @@ -331,6 +351,10 @@
<xsl:with-param name="sourcetwotgtsecondlink" select="$sourcetwotgtsecondlink"/>
<xsl:with-param name="sourcethreesrcsecondlink" select="$sourcethreesrcsecondlink"/>
<xsl:with-param name="sourcethreetgtsecondlink" select="$sourcethreetgtsecondlink"/>

<xsl:with-param name="targetonewaypoints" select="$targetonewaypoints"/>
<xsl:with-param name="sourceonewaypoints" select="$sourceonewaypoints"/>
<xsl:with-param name="sourcetwowaypoints" select="$sourcetwowaypoints"/>
<xsl:with-param name="x" select="$x"/>
<xsl:with-param name="y" select="$y"/>
<xsl:with-param name="parent" select="$parent"/>
Expand Down Expand Up @@ -410,7 +434,76 @@
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="targetonewaypoints" >
<xsl:choose>
<xsl:when test="$targetimplicitoneid = $targetimplicitonelink/@source">
<array>
<xsl:for-each select="$targetimplicitonelink/mxGeometry/Array/mxPoint">
<xsl:sort select="position()" order="descending"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</array>
</xsl:when>
<xsl:when test="$targetimplicitoneid = $targetimplicitonelink/@target">
<xsl:value-of select="$targetimplicitonelink/mxGeometry/Array/mxPoint"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>No match found</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="sourceonewaypoints" >
<xsl:choose>
<xsl:when test="$sourceimplicitoneid = $sourceimplicitonelink/@target">
<array>
<xsl:for-each select="$sourceimplicitonelink/mxGeometry/Array/mxPoint">
<xsl:sort select="position()" order="descending"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</array>
</xsl:when>
<xsl:when test="$sourceimplicitoneid = $sourceimplicitonelink/@source">
<xsl:value-of select="$sourceimplicitonelink/mxGeometry/Array/mxPoint"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>No match found</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="sourcetwowaypoints" >
<xsl:choose>
<xsl:when test="$sourceimplicittwoid = $sourceimplicittwolink/@target">
<array>
<xsl:for-each select="$sourceimplicittwolink/mxGeometry/Array/mxPoint">
<xsl:sort select="position()" order="descending"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</array>
</xsl:when>
<xsl:when test="$sourceimplicittwoid = $sourceimplicittwolink/@source">
<xsl:value-of select="$sourceimplicittwolink/mxGeometry/Array/mxPoint"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>No match found</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:element name="waypoint">
<xsl:attribute name="waypoint1">
<xsl:value-of select="count($targetonewaypoints)" />
</xsl:attribute>
<xsl:attribute name="waypoint2">
<xsl:value-of select="count($sourceonewaypoints)" />
</xsl:attribute>
<xsl:attribute name="waypoint3">
<xsl:value-of select="count($sourcetwowaypoints)" /> <!-- removed by suchita $targetonelink/@source-->
</xsl:attribute>
</xsl:element>

<xsl:call-template name="links">
<xsl:with-param name="linktype" select="$linktype"/>
<xsl:with-param name="targetonelink" select="$targetimplicitonelink"/>
Expand All @@ -429,6 +522,10 @@
<xsl:with-param name="sourcetwotgtsecondlink" select="$sourcetwotgtsecondlink"/>
<xsl:with-param name="sourcethreesrcsecondlink" select="$sourcethreesrcsecondlink"/>
<xsl:with-param name="sourcethreetgtsecondlink" select="$sourcethreetgtsecondlink"/>

<xsl:with-param name="targetonewaypoints" select="$targetonewaypoints"/>
<xsl:with-param name="sourceonewaypoints" select="$sourceonewaypoints"/>
<xsl:with-param name="sourcetwowaypoints" select="$sourcetwowaypoints"/>
<xsl:with-param name="x" select="$x"/>
<xsl:with-param name="y" select="$y"/>
<xsl:with-param name="parent" select="$parent"/>
Expand Down
Loading

0 comments on commit 68722b2

Please sign in to comment.