summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuchita Lad2024-10-21 17:12:01 +0530
committerSuchita Lad2024-10-21 17:12:01 +0530
commit53be7d0ad833f577b110d0503088f5bf16221574 (patch)
tree85f1db9966e482f31277105d7280657f18052339
parentcdc40723190d605822bd569a66ada24a9d3b6d7c (diff)
downloadCommon-Interface-Project-53be7d0ad833f577b110d0503088f5bf16221574.tar.gz
Common-Interface-Project-53be7d0ad833f577b110d0503088f5bf16221574.tar.bz2
Common-Interface-Project-53be7d0ad833f577b110d0503088f5bf16221574.zip
Added ImplicitInputOutputPort, CommandPort, ControlPort function for split
-rwxr-xr-xblocks/Xcos/MxGraphParser.py354
-rw-r--r--blocks/Xcos/common/AAAAAA.py28
-rw-r--r--blocks/Xcos/ports/CommandPort.py15
-rw-r--r--blocks/Xcos/ports/ControlPort.py15
-rw-r--r--blocks/Xcos/ports/ImplicitInputPort.py15
-rw-r--r--blocks/Xcos/ports/ImplicitOutputPort.py15
-rw-r--r--blocks/simulationAPI/views.py2
7 files changed, 275 insertions, 169 deletions
diff --git a/blocks/Xcos/MxGraphParser.py b/blocks/Xcos/MxGraphParser.py
index f7af3cb1..04ebd868 100755
--- a/blocks/Xcos/MxGraphParser.py
+++ b/blocks/Xcos/MxGraphParser.py
@@ -114,176 +114,194 @@ for root in model:
mxPointList = {}
blkgeometry = {}
points1 = []
- for cell in list(root):
- try:
- attrib = cell.attrib
- attribid = attrib['id']
- attribint = get_int(attribid)
- if nextattribid <= attribint:
- nextattribid = attribint + 1
-
- if attribid == '0':
- outnode = ET.SubElement(outroot, 'mxCell')
- outnode.set('id', attribid)
- continue
-
- if attribid == '1':
- outnode = ET.SubElement(outroot, 'mxCell')
- outnode.set('id', attribid)
- outnode.set('parent', '0')
- continue
-
- cell_type = attrib['CellType']
-
- if cell_type == 'Component':
-
- style = attrib['style']
- componentOrdering += 1
- portCount[attribid] = {
- 'ExplicitInputPort': 0,
- 'ImplicitInputPort': 0,
- 'ControlPort': 0,
- 'ExplicitOutputPort': 0,
- 'ImplicitOutputPort': 0,
- 'CommandPort': 0
- }
- componentGeometry = {}
- componentGeometry['height'] = 40
- componentGeometry['width'] = 40
- componentGeometry['x'] = 0
- componentGeometry['y'] = 0
- mxGeometry = cell.find('mxGeometry')
- if mxGeometry is not None:
- componentGeometry['height'] = mxGeometry.attrib['height']
- componentGeometry['width'] = mxGeometry.attrib['width']
- componentGeometry['x'] = mxGeometry.attrib.get('x', '0')
- componentGeometry['y'] = mxGeometry.attrib.get('y', '0')
- parameter_values = cell.find('./Object[@as="parameter_values"]')
- parameters = []
- if parameter_values is not None:
- parameter_values = parameter_values.attrib
- for i in range(100):
- parameter = 'p%03d_value' % i
- if parameter in parameter_values:
- parameters.append(parameter_values[parameter])
- else:
- break
- globals()[style](outroot, attribid, componentOrdering, componentGeometry, parameters)
-
- IDLIST[attribid] = cell_type
- blkgeometry[attribid] = componentGeometry
-
- elif 'vertex' in attrib:
-
- style = attrib['style']
- ParentComponent = attrib['ParentComponent']
- portCount[ParentComponent][style] += 1
- ordering = portCount[ParentComponent][style]
- geometry = dict(componentGeometry)
- mxGeometry = cell.find('mxGeometry')
- if mxGeometry is not None:
- geometry['height'] = mxGeometry.attrib['height']
- geometry['width'] = mxGeometry.attrib['width']
- geometryX = mxGeometry.attrib.get('x', 0)
- geometryY = mxGeometry.attrib.get('y', 0)
- if mxGeometry.attrib.get('relative', '0') == '1':
- geometryX = num2str(float(componentGeometry['x']) +
- float(componentGeometry['width']) * float(geometryX))
- geometryY = num2str(float(componentGeometry['y']) +
- float(componentGeometry['height']) * float(geometryY))
- geometry['x'] = geometryX
- geometry['y'] = geometryY
- globals()[style](outroot, attribid, ParentComponent, ordering, geometry)
-
- IDLIST[attribid] = style
- blkgeometry[attribid] = geometry
-
- elif 'edge' in attrib:
-
- mxGeometry = cell.find('mxGeometry')
- waypoints = []
- arrayElement = mxGeometry.find('Array')
- if arrayElement is not None:
- for arrayChild in arrayElement:
- if arrayChild.tag == 'mxPoint':
- waypoints.append(arrayChild.attrib)
-
- sourceVertex = attrib['sourceVertex']
- targetVertex = attrib['targetVertex']
-
- sourceType = IDLIST[sourceVertex]
- targetType = IDLIST[targetVertex]
-
- # switch vertices if required
- if sourceType in ['ExplicitInputPort', 'ImplicitInputPort', 'ControlPort'] and \
- targetType in ['ExplicitOutputPort', 'ExplicitLink', 'ImplicitOutputPort', 'ImplicitLink', 'CommandPort', 'CommandControlLink']:
- (sourceVertex, targetVertex) = (targetVertex, sourceVertex)
- (sourceType, targetType) = (targetType, sourceType)
- waypoints.reverse()
- elif sourceType in ['ExplicitInputPort', 'ExplicitLink', 'ImplicitInputPort', 'ImplicitLink', 'ControlPort', 'CommandControlLink'] and \
- targetType in ['ExplicitOutputPort', 'ImplicitOutputPort', 'CommandPort']:
- (sourceVertex, targetVertex) = (targetVertex, sourceVertex)
- (sourceType, targetType) = (targetType, sourceType)
- waypoints.reverse()
-
- style = None
- addSplit = False
- 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 \
- targetType == sourceType:
- print(attribid, 'cannot connect two links of', sourceType, 'and', targetType)
- elif sourceType in ['ExplicitOutputPort'] and \
- targetType in ['ExplicitInputPort']:
- style = 'ExplicitLink'
- elif sourceType in ['ExplicitOutputPort', 'ExplicitLink'] and \
- targetType in ['ExplicitInputPort', 'ExplicitLink']:
- style = 'ExplicitLink'
- addSplit = True
- elif sourceType in ['ImplicitOutputPort', 'ImplicitInputPort'] and \
- targetType in ['ImplicitInputPort', 'ImplicitOutputPort']:
- style = 'ImplicitLink'
- elif sourceType in ['ImplicitOutputPort', 'ImplicitInputPort', 'ImplicitLink'] and \
- targetType in ['ImplicitInputPort', 'ImplicitOutputPort', 'ImplicitLink']:
- style = 'ImplicitLink'
- addSplit = True
- elif sourceType in ['CommandPort'] and \
- targetType in ['ControlPort']:
- style = 'CommandControlLink'
- elif sourceType in ['CommandPort', 'CommandControlLink'] and \
- targetType in ['ControlPort', 'CommandControlLink']:
- style = 'CommandControlLink'
- addSplit = True
- else:
- print(attribid, 'Unknown combination of', sourceType, 'and', targetType)
-
- if style is None:
+ cells = list(root)
+ remainingcells = []
+ cellslength = len(cells)
+ oldcellslength = 0
+ while cellslength > 0 and cellslength != oldcellslength :
+ for cell in cells:
+ try:
+ attrib = cell.attrib
+ attribid = attrib['id']
+ attribint = get_int(attribid)
+ if nextattribid <= attribint:
+ nextattribid = attribint + 1
+
+ if attribid == '0':
+ outnode = ET.SubElement(outroot, 'mxCell')
+ outnode.set('id', attribid)
continue
- split_point = None
-
- 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:
- point = {'x': attrib['tarx'], 'y': attrib['tary']}
- split_point = point
- waypoints.insert(0, point)
-
- if 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)
- edgeDict[attribid] = link_data
- edgeList.append(link_data)
- except BaseException:
- traceback.print_exc()
- sys.exit(0)
+ if attribid == '1':
+ outnode = ET.SubElement(outroot, 'mxCell')
+ outnode.set('id', attribid)
+ outnode.set('parent', '0')
+ continue
+
+ cell_type = attrib['CellType']
+
+ if cell_type == 'Component':
+
+ style = attrib['style']
+ componentOrdering += 1
+ portCount[attribid] = {
+ 'ExplicitInputPort': 0,
+ 'ImplicitInputPort': 0,
+ 'ControlPort': 0,
+ 'ExplicitOutputPort': 0,
+ 'ImplicitOutputPort': 0,
+ 'CommandPort': 0
+ }
+ componentGeometry = {}
+ componentGeometry['height'] = 40
+ componentGeometry['width'] = 40
+ componentGeometry['x'] = 0
+ componentGeometry['y'] = 0
+ mxGeometry = cell.find('mxGeometry')
+ if mxGeometry is not None:
+ componentGeometry['height'] = mxGeometry.attrib['height']
+ componentGeometry['width'] = mxGeometry.attrib['width']
+ componentGeometry['x'] = mxGeometry.attrib.get('x', '0')
+ componentGeometry['y'] = mxGeometry.attrib.get('y', '0')
+ parameter_values = cell.find('./Object[@as="parameter_values"]')
+ parameters = []
+ if parameter_values is not None:
+ parameter_values = parameter_values.attrib
+ for i in range(100):
+ parameter = 'p%03d_value' % i
+ if parameter in parameter_values:
+ parameters.append(parameter_values[parameter])
+ else:
+ break
+
+ style = style_to_object(style)['default']
+ globals()[style](outroot, attribid, componentOrdering, componentGeometry, parameters)
+
+ IDLIST[attribid] = cell_type
+ blkgeometry[attribid] = componentGeometry
+
+ elif 'vertex' in attrib:
+
+ style = attrib['style']
+ ParentComponent = attrib['ParentComponent']
+ portCount[ParentComponent][style] += 1
+ ordering = portCount[ParentComponent][style]
+ geometry = dict(componentGeometry)
+ mxGeometry = cell.find('mxGeometry')
+ if mxGeometry is not None:
+ geometry['height'] = mxGeometry.attrib['height']
+ geometry['width'] = mxGeometry.attrib['width']
+ geometryX = mxGeometry.attrib.get('x', 0)
+ geometryY = mxGeometry.attrib.get('y', 0)
+ if mxGeometry.attrib.get('relative', '0') == '1':
+ geometryX = num2str(float(componentGeometry['x']) +
+ float(componentGeometry['width']) * float(geometryX))
+ geometryY = num2str(float(componentGeometry['y']) +
+ float(componentGeometry['height']) * float(geometryY))
+ geometry['x'] = geometryX
+ geometry['y'] = geometryY
+ globals()[style](outroot, attribid, ParentComponent, ordering, geometry)
+
+ IDLIST[attribid] = style
+ blkgeometry[attribid] = geometry
+
+ elif 'edge' in attrib:
+
+ mxGeometry = cell.find('mxGeometry')
+ waypoints = []
+ arrayElement = mxGeometry.find('Array')
+ if arrayElement is not None:
+ for arrayChild in arrayElement:
+ if arrayChild.tag == 'mxPoint':
+ waypoints.append(arrayChild.attrib)
+
+ sourceVertex = attrib['sourceVertex']
+ targetVertex = attrib['targetVertex']
+
+ try:
+ sourceType = IDLIST[sourceVertex]
+ targetType = IDLIST[targetVertex]
+ except KeyError:
+ remainingcells.append(cell)
+ continue
+
+
+ # switch vertices if required
+ if sourceType in ['ExplicitInputPort', 'ImplicitInputPort', 'ControlPort'] and \
+ targetType in ['ExplicitOutputPort', 'ExplicitLink', 'ImplicitOutputPort', 'ImplicitLink', 'CommandPort', 'CommandControlLink']:
+ (sourceVertex, targetVertex) = (targetVertex, sourceVertex)
+ (sourceType, targetType) = (targetType, sourceType)
+ waypoints.reverse()
+ elif sourceType in ['ExplicitInputPort', 'ExplicitLink', 'ImplicitInputPort', 'ImplicitLink', 'ControlPort', 'CommandControlLink'] and \
+ targetType in ['ExplicitOutputPort', 'ImplicitOutputPort', 'CommandPort']:
+ (sourceVertex, targetVertex) = (targetVertex, sourceVertex)
+ (sourceType, targetType) = (targetType, sourceType)
+ waypoints.reverse()
+
+ style = None
+ addSplit = False
+ 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 \
+ targetType == sourceType:
+ print(attribid, 'cannot connect two links of', sourceType, 'and', targetType)
+ elif sourceType in ['ExplicitOutputPort'] and \
+ targetType in ['ExplicitInputPort']:
+ style = 'ExplicitLink'
+ elif sourceType in ['ExplicitOutputPort', 'ExplicitLink'] and \
+ targetType in ['ExplicitInputPort', 'ExplicitLink']:
+ style = 'ExplicitLink'
+ addSplit = True
+ elif sourceType in ['ImplicitOutputPort', 'ImplicitInputPort'] and \
+ targetType in ['ImplicitInputPort', 'ImplicitOutputPort']:
+ style = 'ImplicitLink'
+ elif sourceType in ['ImplicitOutputPort', 'ImplicitInputPort', 'ImplicitLink'] and \
+ targetType in ['ImplicitInputPort', 'ImplicitOutputPort', 'ImplicitLink']:
+ style = 'ImplicitLink'
+ addSplit = True
+ elif sourceType in ['CommandPort'] and \
+ targetType in ['ControlPort']:
+ style = 'CommandControlLink'
+ elif sourceType in ['CommandPort', 'CommandControlLink'] and \
+ targetType in ['ControlPort', 'CommandControlLink']:
+ style = 'CommandControlLink'
+ addSplit = True
+ else:
+ print(attribid, 'Unknown combination of', sourceType, 'and', targetType)
+
+ if style is None:
+ continue
+
+ split_point = None
+
+ 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:
+ point = {'x': attrib['tarx'], 'y': attrib['tary']}
+ split_point = point
+ waypoints.insert(0, point)
+
+ if 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)
+ edgeDict[attribid] = link_data
+ edgeList.append(link_data)
+ except BaseException:
+ traceback.print_exc()
+ sys.exit(0)
+ oldcellslength = cellslength
+ cells = remainingcells
+ cellslength = len(remainingcells)
+ remainingcells = []
+ print('cellslength=', cellslength, ', oldcellslength=', oldcellslength)
+
print('EDGES:')
for key, value in edgeDict.items():
diff --git a/blocks/Xcos/common/AAAAAA.py b/blocks/Xcos/common/AAAAAA.py
index bfe03af4..10ac6d9f 100644
--- a/blocks/Xcos/common/AAAAAA.py
+++ b/blocks/Xcos/common/AAAAAA.py
@@ -628,4 +628,30 @@ def generate_id(block_count, port_count, link_count):
port_ids = all_ids[block_count:block_count + port_count]
link_ids = all_ids[block_count + port_count:block_count + port_count + link_count]
- return block_ids, port_ids, link_ids \ No newline at end of file
+ return block_ids, port_ids, link_ids
+
+
+def style_to_object(style):
+ if not style.endswith(';'):
+ style += ';'
+
+ style_object = {}
+ remaining_style = style
+
+ while remaining_style:
+ index_of_key_value = remaining_style.find(';')
+
+ index_of_key = remaining_style.find('=')
+ if 0 < index_of_key < index_of_key_value:
+ key = remaining_style[:index_of_key]
+ value = remaining_style[index_of_key + 1:index_of_key_value]
+ style_object[key] = value
+ else:
+ key = 'default'
+ value = remaining_style[:index_of_key_value]
+ if value and key not in style_object:
+ style_object[key] = value
+
+ remaining_style = remaining_style[index_of_key_value + 1:]
+
+ return style_object
diff --git a/blocks/Xcos/ports/CommandPort.py b/blocks/Xcos/ports/CommandPort.py
index 7658785b..5f937939 100644
--- a/blocks/Xcos/ports/CommandPort.py
+++ b/blocks/Xcos/ports/CommandPort.py
@@ -16,3 +16,18 @@ def CommandPort(outroot, attribid, parentattribid, ordering, geometry,
style=func_name, value=value)
return outnode
+
+def addCommandPortForSplit(outroot, splitBlock, sourceVertex, targetVertex,
+ sourceType, targetType, inputCount,
+ outputCount, nextAttrib, nextAttribForSplit, waypoints):
+ outputCount += 1
+ geometry = {}
+ geometry['width'] = 8
+ geometry['height'] = 8
+ geometry['x'] = 7
+ geometry['y'] = -4
+ CommandPort(outroot, nextAttrib, splitBlock, outputCount, geometry,
+ forSplitBlock=True)
+ nextAttrib += 1
+ nextAttribForSplit += 1
+ return (inputCount, outputCount, nextAttrib, nextAttribForSplit)
diff --git a/blocks/Xcos/ports/ControlPort.py b/blocks/Xcos/ports/ControlPort.py
index d2fa0ff5..b7691324 100644
--- a/blocks/Xcos/ports/ControlPort.py
+++ b/blocks/Xcos/ports/ControlPort.py
@@ -16,3 +16,18 @@ def ControlPort(outroot, attribid, parentattribid, ordering, geometry,
style=func_name, value=value)
return outnode
+
+def addControlPortForSplit(outroot, splitBlock, sourceVertex, targetVertex,
+ sourceType, targetType, inputCount,
+ outputCount, nextAttrib, nextAttribForSplit, waypoints):
+ inputCount += 1
+ geometry = {}
+ geometry['width'] = 8
+ geometry['height'] = 8
+ geometry['x'] = -8
+ geometry['y'] = -4
+ ControlPort(outroot, nextAttrib, splitBlock, inputCount, geometry,
+ forSplitBlock=True)
+ nextAttrib += 1
+ nextAttribForSplit += 1
+ return (inputCount, outputCount, nextAttrib, nextAttribForSplit)
diff --git a/blocks/Xcos/ports/ImplicitInputPort.py b/blocks/Xcos/ports/ImplicitInputPort.py
index bd273801..680fcc16 100644
--- a/blocks/Xcos/ports/ImplicitInputPort.py
+++ b/blocks/Xcos/ports/ImplicitInputPort.py
@@ -22,3 +22,18 @@ def ImplicitInputPort(outroot, attribid, parentattribid, ordering, geometry,
style=func_name, value=value)
return outnode
+
+def addImplicitInputPortForSplit(outroot, splitBlock, sourceVertex, targetVertex,
+ sourceType, targetType, inputCount,
+ outputCount, nextAttrib, nextAttribForSplit, waypoints):
+ inputCount += 1
+ geometry = {}
+ geometry['width'] = 8
+ geometry['height'] = 8
+ geometry['x'] = -8
+ geometry['y'] = -4
+ ImplicitInputPort(outroot, nextAttrib, splitBlock, inputCount, geometry,
+ forSplitBlock=True)
+ nextAttrib += 1
+ nextAttribForSplit += 1
+ return (inputCount, outputCount, nextAttrib, nextAttribForSplit)
diff --git a/blocks/Xcos/ports/ImplicitOutputPort.py b/blocks/Xcos/ports/ImplicitOutputPort.py
index c67a25b3..de7a81bd 100644
--- a/blocks/Xcos/ports/ImplicitOutputPort.py
+++ b/blocks/Xcos/ports/ImplicitOutputPort.py
@@ -22,3 +22,18 @@ def ImplicitOutputPort(outroot, attribid, parentattribid, ordering, geometry,
style=func_name, value=value)
return outnode
+
+def addImplicitOutputPortForSplit(outroot, splitBlock, sourceVertex, targetVertex,
+ sourceType, targetType, inputCount,
+ outputCount, nextAttrib, nextAttribForSplit, waypoints):
+ outputCount += 1
+ geometry = {}
+ geometry['width'] = 8
+ geometry['height'] = 8
+ geometry['x'] = 7
+ geometry['y'] = -4
+ ImplicitOutputPort(outroot, nextAttrib, splitBlock, outputCount, geometry,
+ forSplitBlock=True)
+ nextAttrib += 1
+ nextAttribForSplit += 1
+ return (inputCount, outputCount, nextAttrib, nextAttribForSplit)
diff --git a/blocks/simulationAPI/views.py b/blocks/simulationAPI/views.py
index ee9c6c2a..be241666 100644
--- a/blocks/simulationAPI/views.py
+++ b/blocks/simulationAPI/views.py
@@ -223,6 +223,7 @@ class StreamView(APIView):
time.sleep(LOOK_DELAY)
continue
logger.warning('log file is empty')
+
return None
return log_name
@@ -235,6 +236,7 @@ class StreamView(APIView):
self.duplicatelineno = 0
def event_stream(self, task_id):
+ print('ABC',task_id)
if not isinstance(task_id, uuid.UUID):
raise ValidationError('Invalid uuid format')