summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuchita Lad2024-09-19 15:25:04 +0530
committerSuchita Lad2024-09-19 15:25:14 +0530
commitdd578e8dad541b9154b96a36bc22f1595eaaa42c (patch)
tree40895d23ba098bf5ee2d8003687fd51d4de51c5d
parenta59c4dcb9ada6e0df4dcf9a907776a2d3c25f758 (diff)
downloadCommon-Interface-Project-dd578e8dad541b9154b96a36bc22f1595eaaa42c.tar.gz
Common-Interface-Project-dd578e8dad541b9154b96a36bc22f1595eaaa42c.tar.bz2
Common-Interface-Project-dd578e8dad541b9154b96a36bc22f1595eaaa42c.zip
Updated files
-rwxr-xr-xblocks/Xcos/MxGraphParser.py129
-rw-r--r--blocks/Xcos/links/ExplicitLink.py4
-rw-r--r--blocks/Xcos/ports/ExplicitInputPort.py6
-rw-r--r--blocks/Xcos/ports/ExplicitOutputPort.py6
4 files changed, 77 insertions, 68 deletions
diff --git a/blocks/Xcos/MxGraphParser.py b/blocks/Xcos/MxGraphParser.py
index 15d513e4..0839a2df 100755
--- a/blocks/Xcos/MxGraphParser.py
+++ b/blocks/Xcos/MxGraphParser.py
@@ -64,32 +64,45 @@ def split_array_by_point(array, point):
def check_point_on_array(array, point):
+ if array is None:
+ return False, array, []
for i in range(len(array) - 1):
# Check if the point lies on the line segment between array[i] and array[i + 1]
- if -40 <= array[i]['y'] - point['y'] <= 40 and \
- -40 <= array[i + 1]['y'] - point['y'] <= 40 and \
- array[i]['x'] <= point['x'] <= array[i + 1]['x']:
+ if -40 <= int(array[i]['y']) - int(point['y']) <= 40 and \
+ -40 <= int(array[i + 1]['y']) - int(point['y']) <= 40 and \
+ int(array[i]['x']) <= int(point['x']) <= int(array[i + 1]['x']):
return True, array[:i + 1], array[i + 1:]
- if -40 <= array[i]['x'] - point['x'] <= 40 and \
- -40 <= array[i + 1]['x'] - point['x'] <= 40 and \
- array[i]['y'] <= point['y'] <= array[i + 1]['y']:
+ if -40 <= int(array[i]['x']) - int(point['x']) <= 40 and \
+ -40 <= int(array[i + 1]['x']) - int(point['x']) <= 40 and \
+ int(array[i]['y']) <= int(point['y']) <= int(array[i + 1]['y']):
return True, array[:i + 1], array[i + 1:]
-
+ print("ERror:", point, "does not lie on", array)
return False, array, []
+def identify_segment(array, point):
+ for i, segment in enumerate(array):
+ print('COUNT:', len(segment))
+ result, left_array, right_array = check_point_on_array(segment[6], point)
+ if result:
+ return result, i, left_array, right_array
+ print("ERror11:", point, "does not lie on", array)
+ return False, -1, array, []
+
def splitlink_by_point(array1, s1, t1, array2, s2, t2, array3, s3, t3, point):
onarray, array4, array5 = check_point_on_array(array1, point)
- print('testcheck', onarray, array4, array5)
+ print('testcheck1', onarray, array4, array5)
if onarray:
return array1, s1, t1, array4, array5
onarray, array4, array5 = check_point_on_array(array2, point)
+ print('testcheck2', onarray, array4, array5)
if onarray:
return array2, s2, t2, array4, array5
onarray, array4, array5 = check_point_on_array(array3, point)
+ print('testcheck3', onarray, array4, array5)
if onarray:
return array3, s3, t3, array4, array5
-
+ print("ERror:", point, "does not lie on 3 array")
for root in model:
if root.tag != 'root':
@@ -270,9 +283,10 @@ for root in model:
waypoints.append(point)
IDLIST[attribid] = style
- link_data = (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit)
+ link_data = (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point)
edgeDict[attribid] = link_data
edgeList.append(link_data)
+ # print("EL:", edgeList)
except BaseException:
traceback.print_exc()
sys.exit(0)
@@ -282,9 +296,9 @@ for key, value in edgeDict.items():
print(f'{key}: {value}')
newEdgeDict = {}
-for (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit) in edgeList:
- link_data = (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit)
- print('test', attribid, sourceVertex, targetVertex, sourceType, targetType, style, addSplit)
+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)
+ print('test', attribid, sourceVertex, targetVertex, sourceType, targetType, style, addSplit, split_point)
if not addSplit:
newEdgeDict[attribid] = [link_data]
@@ -292,44 +306,43 @@ for (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoi
print(f'{key}: {value}')
continue
+
+ try:
+ print("SOURCEV:", newEdgeDict[sourceVertex])
+ linkSegments = newEdgeDict[sourceVertex]
+ except KeyError:
+ pass
+ try:
+ print("SOURCET:", newEdgeDict[targetVertex])
+ linkSegments = newEdgeDict[targetVertex]
+ except KeyError:
+ pass
+ print('CNT:', len(linkSegments))
+ result, i, left_array, right_array = identify_segment(linkSegments, split_point)
+ if not result:
+ sys.exit(0)
+ (attribid2, sourceVertex2, targetVertex2, sourceType2, targetType2, style2, waypoints2, addSplit2, split_point2) = linkSegments[i]
+ #remove code here
+ del newEdgeDict[attribid2][i]
+ print('A1:', left_array)
+ print('A2:', right_array)
+ array3 = waypoints
+
componentOrdering += 1
SplitBlock(outroot, nextattribid, componentOrdering, geometry)
splitblockid = nextattribid
nextattribid += 1
- if sourceVertex in dict1:
- new_array1, new_array2, new_array3, new_splitblockid, new_sourceVertex, new_targetVertex, new_splitblkgeometry, temp_new_port1, temp_new_port2, new_port1, new_point = dict1[sourceVertex][0]
- new_port3 = targetVertex
- print('DICTSV111', new_port1, new_port3, sourceVertex)
- if targetVertex in dict1:
- new_array1, new_array2, new_array3, new_splitblockid, new_sourceVertex, new_targetVertex, new_splitblkgeometry, temp_new_port1, temp_new_port2, new_port2, new_point = dict1[targetVertex][0]
- print('DICTSV1', new_port1, new_port2, new_port3, sourceVertex)
-
inputCount = 0
outputCount = 0
-
if sourceType == 'ExplicitLink':
- (style2, sourceVertex2, targetVertex2, sourceType2, targetType2, waypoints) = edgeDict2[sourceVertex]
- print('ED2', edgeDict2[sourceVertex], sourceVertex, sourceVertex2)
+ # (style2, sourceVertex2, targetVertex2, sourceType2, targetType2, waypoints) = newEdgeDict[sourceVertex]
port1 = nextattribid
- # print('D1:', dict1)
- if sourceVertex in dict1:
- # print('SP', array1, sourceVertex2, new_port1, array2, new_port3, targetVertex2, array3, new_port2, targetVertex2, point)
- splitpoints = splitlink_by_point(array1, sourceVertex2, new_port1, array2, new_port3, targetVertex2, array3, new_port2, targetVertex2, point)
- # print('SP1:', splitpoints)
- key_to_remove = None
- for key, value in edgeDict.items():
- if value[1] == str(splitpoints[1]) and value[2] == str(splitpoints[2]):
- key_to_remove = key
- break
-
- if key_to_remove is not None:
- del edgeDict[key_to_remove]
-
- (inputCount, outputCount, nextattribid, nextAttribForSplit) = addExplicitInputPortForSplit(outroot, splitblockid, sourceVertex2, targetVertex2, sourceType2, targetType2, edgeDict, inputCount, outputCount, nextattribid, nextAttribForSplit, array1)
+
+ (inputCount, outputCount, nextattribid, nextAttribForSplit) = addExplicitInputPortForSplit(outroot, splitblockid, sourceVertex2, targetVertex2, sourceType2, targetType2, edgeDict, inputCount, outputCount, nextattribid, nextAttribForSplit, left_array)
port2 = nextattribid
- (inputCount, outputCount, nextattribid, nextAttribForSplit) = addExplicitOutputPortForSplit(outroot, splitblockid, sourceVertex2, targetVertex2, sourceType2, targetType2, edgeDict, inputCount, outputCount, nextattribid, nextAttribForSplit, array2)
+ (inputCount, outputCount, nextattribid, nextAttribForSplit) = addExplicitOutputPortForSplit(outroot, splitblockid, sourceVertex2, targetVertex2, sourceType2, targetType2, edgeDict, inputCount, outputCount, nextattribid, nextAttribForSplit, right_array)
port3 = nextattribid
(inputCount, outputCount, nextattribid, nextAttribForSplit) = addExplicitOutputPortForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceType, targetType, edgeDict, inputCount, outputCount, nextattribid, nextAttribForSplit, array3)
@@ -345,7 +358,7 @@ for (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoi
nextattribid += 1
linkid = nextAttribForSplit
nextAttribForSplit += 1
- (style2, sourceVertex2, targetVertex2, sourceType2, targetType2) = edgeDict2.get(targetVertex, (None, None, None, None, None))
+ (style2, sourceVertex2, targetVertex2, sourceType2, targetType2) = newEdgeDict.get(targetVertex, (None, None, None, None, None))
geometry = {}
geometry['width'] = 8
geometry['height'] = 8
@@ -381,28 +394,24 @@ for (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoi
nextattribid += 1
linkid = nextAttribForSplit
nextAttribForSplit += 1
- (style2, sourceVertex2, targetVertex2, sourceType2, targetType2) = edgeDict2[targetVertex]
- # dict1[sourceVertex] = [array1, array2, array3, splitblockid, sourceVertex, targetVertex, geometry, port1, port2, port3, point]
- # # print('DICTSV2', dict1[sourceVertex], sourceVertex)
- # dict1[attribid] = [array1, array2, array3, splitblockid, sourceVertex, targetVertex, geometry, port1, port2, port3, point]
- dict1[sourceVertex] = []
- dict1[sourceVertex].append((array1, array2, array3, splitblockid, sourceVertex, targetVertex, geometry, port1, port2, port3, point))
- new_list = array1, array2, array3, splitblockid, int(sourceVertex2), port1, port2, int(targetVertex2), geometry, port1, port2, port3, point
-
- if sourceVertex in dict1:
- dict1[sourceVertex].append(new_list)
- dict1[attribid] = []
- dict1[attribid].append((array1, array2, array3, splitblockid, sourceVertex, targetVertex, geometry, port1, port2, port3, point))
- print('DICTIONARY:', dict1)
-
- print('EDGE11:', edgeDict)
-
-for (attribid, (style, sourceVertex, targetVertex, sourceType, targetType, array1)) in edgeDict.items():
- print("testing", attribid, style, sourceVertex, targetVertex, sourceType, targetType, array1)
+ (style2, sourceVertex2, targetVertex2, sourceType2, targetType2) = newEdgeDict[targetVertex]
+ # attribid2, sourceVertex2, targetVertex2, sourceType2, targetType2, style2, waypoints2, addSplit2, split_point2
+ newEdgeDict[attribid2].append((attribid2, sourceVertex2, port1, sourceType2, targetType, style2, left_array, addSplit2, split_point2))
+ newEdgeDict[attribid2].append((attribid2, port2, targetVertex2, sourceType, targetType2, style2, right_array, addSplit2, split_point2))
+
+ newEdgeDict[attribid] = [(attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point)]
+
+
+# print('ED:', edgeDict.items())
+# for (attribid, (style, sourceVertex, targetVertex, sourceType, targetType, array1)) in edgeDict.items():
+# print("testing", attribid, style, sourceVertex, targetVertex, sourceType, targetType, array1)
+for (attribid, (attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point)) in edgeDict.items():
+ print("testing", attribid, sourceVertex, targetVertex, sourceType, targetType, style, waypoints, addSplit, split_point)
+
if int(attribid) >= 10000:
attribid = nextattribid
nextattribid += 1
- globals()[style](outroot, attribid, sourceVertex, targetVertex, array1)
+ globals()[style](outroot, attribid, sourceVertex, targetVertex, waypoints)
outnode = ET.SubElement(outdiagram, 'mxCell')
outnode.set('id', str(1))
diff --git a/blocks/Xcos/links/ExplicitLink.py b/blocks/Xcos/links/ExplicitLink.py
index 0e1f8ce9..aec37268 100644
--- a/blocks/Xcos/links/ExplicitLink.py
+++ b/blocks/Xcos/links/ExplicitLink.py
@@ -1,6 +1,6 @@
from common.AAAAAA import *
-def ExplicitLink(outroot, attribid, sourceVertex, targetVertex, arrayelem):
+def ExplicitLink(outroot, attribid, sourceVertex, targetVertex, waypoints):
func_name = 'ExplicitLink'
outnode = addNode(outroot, func_name, **{'id': attribid},
@@ -12,7 +12,7 @@ def ExplicitLink(outroot, attribid, sourceVertex, targetVertex, arrayelem):
arrayNode = addNode(mxGeoNode, 'Array', **{'as': 'points'})
- for point in arrayelem:
+ for point in waypoints:
addNode(arrayNode, 'mxPoint', **{'x': point['x'], 'y': point['y']})
addNode(mxGeoNode, 'mxPoint', **{'as': 'targetPoint', 'x': "0.0", 'y': "0.0"})
diff --git a/blocks/Xcos/ports/ExplicitInputPort.py b/blocks/Xcos/ports/ExplicitInputPort.py
index ea68ce4a..705c2a9d 100644
--- a/blocks/Xcos/ports/ExplicitInputPort.py
+++ b/blocks/Xcos/ports/ExplicitInputPort.py
@@ -26,7 +26,7 @@ def ExplicitInputPort(outroot, attribid, parentattribid, ordering, geometry,
def addExplicitInputPortForSplit(outroot, splitBlock, sourceVertex, targetVertex,
sourceType, targetType, edgeDict, inputCount,
- outputCount, nextAttrib, nextAttribForSplit, arrayelem):
+ outputCount, nextAttrib, nextAttribForSplit, waypoints):
inputCount += 1
geometry = {}
geometry['width'] = 8
@@ -35,8 +35,8 @@ def addExplicitInputPortForSplit(outroot, splitBlock, sourceVertex, targetVertex
geometry['y'] = -4
ExplicitInputPort(outroot, nextAttrib, splitBlock, inputCount, geometry,
forSplitBlock=True)
- edgeDict[nextAttribForSplit] = ('ExplicitLink', str(sourceVertex), str(nextAttrib),
- sourceType, 'ExplicitInputPort', arrayelem)
+ edgeDict[nextAttribForSplit] = (nextAttribForSplit, str(sourceVertex), str(nextAttrib),
+ sourceType, 'ExplicitInputPort', 'ExplicitLink', waypoints, None, None)
nextAttrib += 1
nextAttribForSplit += 1
return (inputCount, outputCount, nextAttrib, nextAttribForSplit)
diff --git a/blocks/Xcos/ports/ExplicitOutputPort.py b/blocks/Xcos/ports/ExplicitOutputPort.py
index 4248d844..83a68451 100644
--- a/blocks/Xcos/ports/ExplicitOutputPort.py
+++ b/blocks/Xcos/ports/ExplicitOutputPort.py
@@ -26,7 +26,7 @@ def ExplicitOutputPort(outroot, attribid, parentattribid, ordering, geometry,
def addExplicitOutputPortForSplit(outroot, splitBlock, sourceVertex, targetVertex,
sourceType, targetType, edgeDict, inputCount,
- outputCount, nextAttrib, nextAttribForSplit, arrayelem):
+ outputCount, nextAttrib, nextAttribForSplit, waypoints):
outputCount += 1
geometry = {}
geometry['width'] = 8
@@ -35,8 +35,8 @@ def addExplicitOutputPortForSplit(outroot, splitBlock, sourceVertex, targetVerte
geometry['y'] = -4
ExplicitOutputPort(outroot, nextAttrib, splitBlock, outputCount, geometry,
forSplitBlock=True)
- edgeDict[nextAttribForSplit] = ('ExplicitLink', str(nextAttrib), str(targetVertex),
- 'ExplicitOutputPort', targetType, arrayelem)
+ # edgeDict[nextAttribForSplit] = (nextAttribForSplit, str(nextAttrib), str(targetVertex),
+ # 'ExplicitOutputPort', targetType, 'ExplicitLink', waypoints, None, None)
nextAttrib += 1
nextAttribForSplit += 1
return (inputCount, outputCount, nextAttrib, nextAttribForSplit)