diff options
author | Sunil Shetye | 2024-09-13 01:25:32 +0530 |
---|---|---|
committer | Sunil Shetye | 2024-09-13 10:51:55 +0530 |
commit | a33b8d807f60c124c58cfa62b353303a6fbb1f24 (patch) | |
tree | f939bdc15818ead16ba206ae7d2a576d4aa46ee5 | |
parent | 973abf37ccae0362a4d624a933ebc962fe5c1032 (diff) | |
download | Common-Interface-Project-a33b8d807f60c124c58cfa62b353303a6fbb1f24.tar.gz Common-Interface-Project-a33b8d807f60c124c58cfa62b353303a6fbb1f24.tar.bz2 Common-Interface-Project-a33b8d807f60c124c58cfa62b353303a6fbb1f24.zip |
cleanup
-rwxr-xr-x | blocks/Xcos/MxGraphParser.py | 103 | ||||
-rwxr-xr-x | blocks/Xcos/XcosParser.py | 326 | ||||
-rw-r--r-- | blocks/Xcos/common/AAAAAA.py | 9 | ||||
-rw-r--r-- | blocks/authAPI/urls.py | 2 | ||||
-rw-r--r-- | blocks/create_gallery.py | 8 | ||||
-rw-r--r-- | blocks/open_editor.py | 6 | ||||
-rw-r--r-- | blocks/saveAPI/models.py | 1 |
7 files changed, 81 insertions, 374 deletions
diff --git a/blocks/Xcos/MxGraphParser.py b/blocks/Xcos/MxGraphParser.py index 4458d2e4..5a6aa398 100755 --- a/blocks/Xcos/MxGraphParser.py +++ b/blocks/Xcos/MxGraphParser.py @@ -40,39 +40,50 @@ outdiagram.append(comment) outmodel = ET.SubElement(outdiagram, 'mxGraphModel') outmodel.set('as', 'model') + def split_array_by_point(array, point): 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']: - return array[:i+1] + [point], [point] + 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']: - return array[:i+1] + [point], [point] + 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']: + return array[:i + 1] + [point], [point] + 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']: + return array[:i + 1] + [point], [point] + array[i + 1:] + return array, [] + def check_point_on_array(array, point): - # print('P1', type(array), type(point), type(array[i]), type(array[i + 1])) 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']: - 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']: - return True, array[:i+1], 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']: + 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']: + return True, array[:i + 1], array[i + 1:] + return False, 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) - if onarray == True: + print('testcheck', onarray, array4, array5) + if onarray: return array1, s1, t1, array4, array5 onarray, array4, array5 = check_point_on_array(array2, point) - if onarray == True: - return array2, s2, t2, array4, array5 + if onarray: + return array2, s2, t2, array4, array5 onarray, array4, array5 = check_point_on_array(array3, point) - if onarray == True: + if onarray: return array3, s3, t3, array4, array5 + for root in model: if root.tag != 'root': print('Not root') @@ -116,6 +127,7 @@ for root in model: cell_type = attrib['CellType'] if cell_type == 'Component': + style = attrib['style'] componentGeometry = {} componentGeometry['height'] = 40 @@ -147,9 +159,10 @@ for root in model: COM[attribid] = [] IDLIST[attribid] = cell_type blkgeometry[attribid] = componentGeometry - # print('BLK:', blkgeometry) globals()[style](outroot, attribid, componentOrdering, componentGeometry, parameters) + elif 'vertex' in attrib: + style = attrib['style'] geometry = {} geometry['height'] = 40 @@ -186,6 +199,7 @@ for root in model: globals()[style](outroot, attribid, ParentComponent, ordering, geometry) elif 'edge' in attrib: + mxGeometry = cell.find('mxGeometry') array = mxGeometry.find('Array') celid = cell.attrib.get('id') @@ -200,8 +214,6 @@ for root in model: if arrayChild.tag == 'mxPoint': arrayelem.append(arrayChild.attrib) - # print('ARRAYELEM:', arrayelem) - sourceVertex = attrib['sourceVertex'] targetVertex = attrib['targetVertex'] @@ -216,35 +228,44 @@ for root in model: sourceType = IDLIST[sourceVertex] targetType = IDLIST[targetVertex] - # print('ARRAYELEM:', arrayelem) # switch vertices if required - if sourceType in ['ExplicitInputPort', 'ImplicitInputPort', 'ControlPort'] and targetType in ['ExplicitOutputPort', 'ExplicitLink', 'ImplicitOutputPort', 'ImplicitLink', 'CommandPort', 'CommandControlLink']: + if sourceType in ['ExplicitInputPort', 'ImplicitInputPort', 'ControlPort'] and \ + targetType in ['ExplicitOutputPort', 'ExplicitLink', 'ImplicitOutputPort', 'ImplicitLink', 'CommandPort', 'CommandControlLink']: (sourceVertex, targetVertex) = (targetVertex, sourceVertex) (sourceType, targetType) = (targetType, sourceType) - elif sourceType in ['ExplicitInputPort', 'ExplicitLink', 'ImplicitInputPort', 'ImplicitLink', 'ControlPort', 'CommandControlLink'] and targetType in ['ExplicitOutputPort', 'ImplicitOutputPort', 'CommandPort']: + elif sourceType in ['ExplicitInputPort', 'ExplicitLink', 'ImplicitInputPort', 'ImplicitLink', 'ControlPort', 'CommandControlLink'] and \ + targetType in ['ExplicitOutputPort', 'ImplicitOutputPort', 'CommandPort']: (sourceVertex, targetVertex) = (targetVertex, sourceVertex) (sourceType, targetType) = (targetType, sourceType) style = None addSplit = False - if sourceType in ['ExplicitInputPort', 'ExplicitOutputPort', 'CommandPort', 'ControlPort'] and targetType == sourceType: + 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: + 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']: + elif sourceType in ['ExplicitOutputPort'] and \ + targetType in ['ExplicitInputPort']: style = 'ExplicitLink' - elif sourceType in ['ExplicitOutputPort', 'ExplicitLink'] and targetType in ['ExplicitInputPort', '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']: + 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' - elif sourceType in ['ImplicitOutputPort', 'ImplicitInputPort', 'ImplicitLink'] and targetType in ['ImplicitInputPort', 'ImplicitOutputPort', 'ImplicitLink']: - style= 'ImplicitLink' addSplit = True - elif sourceType in ['CommandPort'] and targetType in ['ControlPort']: + elif sourceType in ['CommandPort'] and \ + targetType in ['ControlPort']: style = 'CommandControlLink' - elif sourceType in ['CommandPort', 'CommandControlLink'] and targetType in ['ControlPort', 'CommandControlLink']: + elif sourceType in ['CommandPort', 'CommandControlLink'] and \ + targetType in ['ControlPort', 'CommandControlLink']: style = 'CommandControlLink' addSplit = True else: @@ -259,7 +280,6 @@ for root in model: if addSplit: try: - print("SOURCEV:", edgeDict[sourceVertex]) (style2, sourceVertex2, targetVertex2, sourceType2, targetType2, arrayelem2) = edgeDict[sourceVertex] except KeyError: pass @@ -321,7 +341,7 @@ for root in model: # pass except BaseException: traceback.print_exc() -print('EDGE:',edgeDict) +print('EDGE:', edgeDict) dict2 = {} dict1 = {} for (attribid, sourceVertex, targetVertex, sourceType, targetType, geometry, larger_array, array3, last_stored_point) in splitList: @@ -389,7 +409,7 @@ for (attribid, sourceVertex, targetVertex, sourceType, targetType, geometry, lar 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] @@ -399,7 +419,6 @@ for (attribid, sourceVertex, targetVertex, sourceType, targetType, geometry, lar port3 = nextattribid (inputCount, outputCount, nextattribid, nextAttribForSplit) = addExplicitOutputPortForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceType, targetType, edgeDict, inputCount, outputCount, nextattribid, nextAttribForSplit, array3) - elif targetType == 'ImplicitInputPort': geometry = {} geometry['width'] = 8 @@ -448,7 +467,7 @@ for (attribid, sourceVertex, targetVertex, sourceType, targetType, geometry, lar linkid = nextAttribForSplit nextAttribForSplit += 1 (style2, sourceVertex2, targetVertex2, sourceType2, targetType2) = edgeDict2[targetVertex] - #larger_array split code + # larger_array split code # 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] @@ -460,25 +479,25 @@ for (attribid, sourceVertex, targetVertex, sourceType, targetType, geometry, lar 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('DICTIONARY:', dict1) try: - print("Source",edgeDict[sourceVertex]) + print("Source", edgeDict[sourceVertex]) del edgeDict[sourceVertex] except KeyError: pass try: - print("target",edgeDict[targetVertex]) + print("target", edgeDict[targetVertex]) del edgeDict[targetVertex] except KeyError: pass - print('EDGE11:',edgeDict) + print('EDGE11:', edgeDict) for (attribid, (style, sourceVertex, targetVertex, sourceType, targetType, array1)) in edgeDict.items(): - print("testing",attribid,style, sourceVertex, targetVertex, sourceType, targetType, array1) + print("testing", attribid, style, sourceVertex, targetVertex, sourceType, targetType, array1) if int(attribid) >= 10000: attribid = nextattribid - nextattribid += 1 + nextattribid += 1 globals()[style](outroot, attribid, sourceVertex, targetVertex, array1) outnode = ET.SubElement(outdiagram, 'mxCell') diff --git a/blocks/Xcos/XcosParser.py b/blocks/Xcos/XcosParser.py deleted file mode 100755 index 0555d873..00000000 --- a/blocks/Xcos/XcosParser.py +++ /dev/null @@ -1,326 +0,0 @@ -#!/usr/bin/env python - -import os -import re -import sys -import traceback -import xml.etree.ElementTree as ET -import defusedxml.ElementTree as goodET - -from xcosblocks import * - -if len(sys.argv) != 2: - print("Usage: %s filename.xcos" % sys.argv[0]) - sys.exit(1) - -filename = sys.argv[1] -(basename, ext) = os.path.splitext(filename) - -if ext != '.xcos': - print("Usage: %s filename.xcos" % sys.argv[0]) - sys.exit(1) -base = r'(_[a-zA-Z]*_on_Cloud)?( *\([0-9]*\))?\.xcos$' -title = re.sub(r'^.*/', r'', filename) -title = re.sub(base, r'', title) - -tree = goodET.parse(filename) - -diagram = tree.getroot() -if diagram.tag != 'XcosDiagram': - print(diagram.tag, '!= XcosDiagram') - sys.exit(2) - -for model in diagram: - if model.tag == 'mxCell' and model.attrib['as'] == 'defaultParent': - continue - - if model.tag != 'mxGraphModel': - print(model.tag, '!= mxGraphModel') - sys.exit(2) - outmodel = ET.Element('mxGraphModel') - - for root in model: - if root.tag != 'root': - print('Not root') - sys.exit(2) - outroot = ET.SubElement(outmodel, 'root') - - EIV = {} - IIV = {} - CON = {} - EOV = {} - IOV = {} - COM = {} - IDLIST = {} - componentOrdering = 0 - nextattribid = 0 - nextAttribForSplit = 10000 - edgeDict = {} - edgeDict2 = {} - splitList = [] - splitBlockList = [] - for cell in list(root): - try: - tag = cell.tag - attrib = cell.attrib - attribid = attrib['id'] - - if attribid == '0' or attribid == '0:1:0': - parentattribid = attribid - outnode = ET.SubElement(outroot, 'mxCell') - outnode.set('id', attribid) - outnode.set('appname', 'Xcos') - outnode.set('description', '') - outnode.set('CellType', 'Unknown') - outnode.set('sourceVertex', str(0)) - outnode.set('targetVertex', str(0)) - outnode.set('tarx', str(0)) - outnode.set('tary', str(0)) - - node = ET.SubElement(outnode, 'Object') - node.set('as', 'parameter_values') - - node = ET.SubElement(outnode, 'Object') - node.set('as', 'displayProperties') - continue - - if attribid == '1' or attribid == '0:2:0': - childattribid = attribid - outnode = ET.SubElement(outroot, 'mxCell') - outnode.set('id', attribid) - outnode.set('CellType', 'Unknown') - outnode.set('sourceVertex', str(0)) - outnode.set('targetVertex', str(0)) - outnode.set('tarx', str(0)) - outnode.set('tary', str(0)) - - node = ET.SubElement(outnode, 'Object') - node.set('as', 'parameter_values') - - node = ET.SubElement(outnode, 'Object') - node.set('as', 'displayProperties') - continue - - if tag == 'SplitBlock': - print('SplitBlock', attribid) - splitBlockList.append(attribid) - continue - - try: - interfaceFunctionName = attrib['interfaceFunctionName'] - except KeyError as e: - interfaceFunctionName = None - - if interfaceFunctionName is not None: - outnode = ET.SubElement(outroot, 'mxCell') - outnode.set('style', interfaceFunctionName) - outnode.set('id', attribid) - outnode.set('vertex', str(1)) - outnode.set('connectable', str(0)) - outnode.set('CellType', 'Component') - outnode.set('blockprefix', 'XCOS') - outnode.set('sourceVertex', str(0)) - outnode.set('targetVertex', str(0)) - outnode.set('tarx', str(0)) - outnode.set('tary', str(0)) - - mxGeometry = cell.find('mxGeometry') - outMxGeometry = ET.SubElement(outnode, 'mxGeometry') - outMxGeometry.set('x', mxGeometry.attrib['x'] if mxGeometry is not None else str(0)) - outMxGeometry.set('y', mxGeometry.attrib['y'] if mxGeometry is not None else str(0)) - outMxGeometry.set('width', mxGeometry.attrib['width'] if mxGeometry is not None else str(40)) - outMxGeometry.set('height', mxGeometry.attrib['height'] if mxGeometry is not None else str(40)) - if mxGeometry is not None and mxGeometry.attrib.get('relative', '0') != '0': - outMxGeometry.set('relative', mxGeometry.attrib['relative']) - outMxGeometry.set('as', 'geometry') - - try: - (parameters, display_parameter) = globals()['get_from_' + interfaceFunctionName](cell) - except BaseException as e: - print(repr(e), 'in', tag, attrib) - (parameters, display_parameter) = ([], '') - - outObject = ET.SubElement(outnode, 'Object') - for i in range(0, 20): - outObject.set(f'p{i:03d}_value', parameters[i] if i < len(parameters) else '') - outObject.set('as', 'parameter_values') - - outObject = ET.SubElement(outnode, 'Object') - outObject.set('display_parameter', display_parameter) - outObject.set('as', 'displayProperties') - continue - elif tag.endswith('Port'): - ParentComponent = attrib['parent'] - IDLIST[attribid] = tag - - outnode = ET.SubElement(outroot, 'mxCell') - outnode.set('style', tag) - outnode.set('id', attribid) - outnode.set('vertex', str(1)) - outnode.set('CellType', 'Pin') - outnode.set('ParentComponent', ParentComponent) - outnode.set('sourceVertex', str(0)) - outnode.set('targetVertex', str(0)) - outnode.set('tarx', str(0)) - outnode.set('tary', str(0)) - - mxGeometry = cell.find('mxGeometry') - outMxGeometry = ET.SubElement(outnode, 'mxGeometry') - outMxGeometry.set('x', mxGeometry.attrib['x'] if mxGeometry is not None else str(0)) - outMxGeometry.set('y', mxGeometry.attrib['y'] if mxGeometry is not None else str(0)) - outMxGeometry.set('width', mxGeometry.attrib['width'] if mxGeometry is not None else str(40)) - outMxGeometry.set('height', mxGeometry.attrib['height'] if mxGeometry is not None else str(40)) - if mxGeometry is not None and mxGeometry.attrib.get('relative', '0') != '0': - outMxGeometry.set('relative', mxGeometry.attrib['relative']) - outMxGeometry.set('as', 'geometry') - - outObject = ET.SubElement(outnode, 'Object') - outObject.set('as', 'parameter_values') - - outObject = ET.SubElement(outnode, 'Object') - outObject.set('as', 'displayProperties') - continue - elif tag.endswith('Link'): - sourceVertex = attrib['source'] - targetVertex = attrib['target'] - sourceType = IDLIST[sourceVertex] - targetType = IDLIST[targetVertex] - print('sourceType=', sourceType, 'targetType=', targetType) - - sourcePorts = ['ExplicitOutputPort', 'ImplicitOutputPort', 'CommandPort'] - targetPorts = ['ExplicitInputPort', 'ImplicitInputPort', 'ControlPort'] - links = ['ExplicitLink', 'ImplicitLink', 'CommandControlLink'] - - # switch vertices if required - if sourceType in targetPorts and targetType in [*sourcePorts, *links]: - (sourceVertex, targetVertex) = (targetVertex, sourceVertex) - (sourceType, targetType) = (targetType, sourceType) - elif sourceType in [*targetPorts, *links] and targetType in sourcePorts: - (sourceVertex, targetVertex) = (targetVertex, sourceVertex) - (sourceType, targetType) = (targetType, sourceType) - - style = None - if sourceType in ['ExplicitInputPort', 'ExplicitOutputPort', 'ImplicitInputPort', 'ImplicitOutputPort', 'CommandPort', 'ControlPort'] and targetType == sourceType: - print('cannot connect two ports of', sourceType, 'and', targetType) - elif sourceType in ['ExplicitOutputPort'] and targetType in ['ExplicitInputPort']: - style = 'ExplicitLink' - elif sourceType in ['ImplicitOutputPort'] and targetType in ['ImplicitInputPort']: - style = 'ImplicitLink' - elif sourceType in ['CommandPort'] and targetType in ['ControlPort']: - style = 'CommandControlLink' - else: - print(attribid, 'Unknown combination of', sourceType, 'and', targetType) - continue - - if style is not None: - edgeDict[attribid] = (style, sourceVertex, targetVertex, sourceType, targetType) - edgeDict2[attribid] = (style, sourceVertex, targetVertex, sourceType, targetType) - IDLIST[attribid] = style - except KeyError as e: - print(repr(e), 'in', tag, attrib) - except BaseException: - traceback.print_exc() - - for (attribid, sourceVertex, targetVertex, sourceType, targetType, geometry) in splitList: - componentOrdering += 1 - SplitBlock(outroot, nextattribid, componentOrdering, geometry) - splitblockid = nextattribid - nextattribid += 1 - inputCount = 0 - outputCount = 0 - if sourceType == 'ExplicitOutputPort': - (inputCount, outputCount, nextattribid, nextAttribForSplit) = addExplicitInputPortForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceType, targetType, edgeDict, inputCount, outputCount, nextattribid, nextAttribForSplit) - (style2, sourceVertex2, targetVertex2, sourceType2, targetType2) = edgeDict2[targetVertex] - (inputCount, outputCount, nextattribid, nextAttribForSplit) = addExplicitInputPortForSplit(outroot, splitblockid, sourceVertex2, targetVertex2, sourceType2, targetType2, edgeDict, inputCount, outputCount, nextattribid, nextAttribForSplit) - (inputCount, outputCount, nextattribid, nextAttribForSplit) = addExplicitOutputPortForSplit(outroot, splitblockid, sourceVertex2, targetVertex2, sourceType2, targetType2, edgeDict, inputCount, outputCount, nextattribid, nextAttribForSplit) - elif sourceType == 'ImplicitOutputPort': - geometry = {} - geometry['width'] = 8 - geometry['height'] = 8 - geometry['x'] = -8 - geometry['y'] = -4 - inputCount += 1 - ImplicitInputPort(outroot, nextattribid, splitblockid, inputCount, geometry, forSplitBlock=True) - portid = nextattribid - nextattribid += 1 - linkid = nextAttribForSplit - nextAttribForSplit += 1 - (style2, sourceVertex2, targetVertex2, sourceType2, targetType2) = edgeDict2[sourceVertex] - elif sourceType == 'ControlPort': - geometry = {} - geometry['width'] = 8 - geometry['height'] = 8 - geometry['x'] = -4 - geometry['y'] = -8 - inputCount += 1 - CommandPort(outroot, nextattribid, splitblockid, inputCount, geometry, forSplitBlock=True) - portid = nextattribid - nextattribid += 1 - linkid = nextAttribForSplit - nextAttribForSplit += 1 - (style2, sourceVertex2, targetVertex2, sourceType2, targetType2) = edgeDict2[sourceVertex] - if targetType == 'ExplicitInputPort': - (style2, sourceVertex2, targetVertex2, sourceType2, targetType2) = edgeDict2[sourceVertex] - (inputCount, outputCount, nextattribid, nextAttribForSplit) = addExplicitInputPortForSplit(outroot, splitblockid, sourceVertex2, targetVertex2, sourceType2, targetType2, edgeDict, inputCount, outputCount, nextattribid, nextAttribForSplit) - (inputCount, outputCount, nextattribid, nextAttribForSplit) = addExplicitOutputPortForSplit(outroot, splitblockid, sourceVertex2, targetVertex2, sourceType2, targetType2, edgeDict, inputCount, outputCount, nextattribid, nextAttribForSplit) - (inputCount, outputCount, nextattribid, nextAttribForSplit) = addExplicitOutputPortForSplit(outroot, splitblockid, sourceVertex, targetVertex, sourceType, targetType, edgeDict, inputCount, outputCount, nextattribid, nextAttribForSplit) - elif targetType == 'ImplicitInputPort': - geometry = {} - geometry['width'] = 8 - geometry['height'] = 8 - geometry['x'] = 7 - geometry['y'] = -4 - outputCount += 1 - ImplicitOutputPort(outroot, nextattribid, splitblockid, outputCount, geometry, forSplitBlock=True) - portid = nextattribid - nextattribid += 1 - linkid = nextAttribForSplit - nextAttribForSplit += 1 - (style2, sourceVertex2, targetVertex2, sourceType2, targetType2) = edgeDict2[targetVertex] - geometry = {} - geometry['width'] = 8 - geometry['height'] = 8 - geometry['x'] = -8 - geometry['y'] = -4 - inputCount += 1 - ImplicitInputPort(outroot, nextattribid, splitblockid, inputCount, geometry, forSplitBlock=True) - portid = nextattribid - nextattribid += 1 - linkid = nextAttribForSplit - nextAttribForSplit += 1 - geometry = {} - geometry['width'] = 8 - geometry['height'] = 8 - geometry['x'] = 7 - geometry['y'] = -4 - outputCount += 1 - ImplicitOutputPort(outroot, nextattribid, splitblockid, outputCount, geometry, forSplitBlock=True) - portid = nextattribid - nextattribid += 1 - linkid = nextAttribForSplit - nextAttribForSplit += 1 - elif targetType == 'CommandPort': - geometry = {} - geometry['width'] = 8 - geometry['height'] = 8 - geometry['x'] = -4 - geometry['y'] = 7 - outputCount += 1 - ControlPort(outroot, nextattribid, splitblockid, outputCount, geometry, forSplitBlock=True) - portid = nextattribid - nextattribid += 1 - linkid = nextAttribForSplit - nextAttribForSplit += 1 - (style2, sourceVertex2, targetVertex2, sourceType2, targetType2) = edgeDict2[targetVertex] - - for (attribid, (style, sourceVertex, targetVertex, sourceType, targetType)) in edgeDict.items(): - if int(attribid) >= 10000: - attribid = nextattribid - nextattribid += 1 - globals()[style](outroot, attribid, sourceVertex, targetVertex) - -outtree = ET.ElementTree(outmodel) -ET.indent(outtree) -outfile = basename + '.xml' -outtree.write(outfile, encoding='UTF-8', xml_declaration=True) -sys.exit(0) diff --git a/blocks/Xcos/common/AAAAAA.py b/blocks/Xcos/common/AAAAAA.py index a3e392e8..16f917f8 100644 --- a/blocks/Xcos/common/AAAAAA.py +++ b/blocks/Xcos/common/AAAAAA.py @@ -181,7 +181,7 @@ def addData(node, column, line, value, isReal=False): data = ET.SubElement(node, 'data') data.set('line', str(line)) data.set('column', str(column)) - if type(value) == float or type(value) == int or isReal: + if isinstance(value, (float, int)) or isReal: data.set('realPart', str(value)) else: data.set('value', value) @@ -619,3 +619,10 @@ def format_real_number(parameter): else: formatted_number = "{:.1f}".format(float(parameter)) return formatted_number + + +def num2str(num): + """Converts a float to an integer first if it ends in .0.""" + if num % 1 == 0: + num = int(num) + return str(num) diff --git a/blocks/authAPI/urls.py b/blocks/authAPI/urls.py index 3e49e940..f3409c10 100644 --- a/blocks/authAPI/urls.py +++ b/blocks/authAPI/urls.py @@ -7,6 +7,6 @@ urlpatterns = [ re_path(r'^github-callback', authAPI_views.GitHubOAuth2, name='github-callback'), re_path(r'^google-callback', authAPI_views.GoogleOAuth2), re_path(r'^users/activate/(?P<uid>[\w-]+)/(?P<token>[\w-]+)/$', - authAPI_views.activate_user), + authAPI_views.activate_user), re_path(r'user/token/', authAPI_views.CustomTokenCreateView.as_view()) ] diff --git a/blocks/create_gallery.py b/blocks/create_gallery.py index 88079f70..e44d0e68 100644 --- a/blocks/create_gallery.py +++ b/blocks/create_gallery.py @@ -11,25 +11,27 @@ django.setup() from saveAPI.views import GalleryView + def escape_quotes(value): if value is None: return '' # Escape backslashes, single quotes, and double quotes return value.replace('\\', '\\\\').replace("'", "\\'") + def format_js_object(data): # This function will format each data item into the required JavaScript object structure - formatted = f""" - {{ + formatted = f"""{{ save_id: '{escape_quotes(data["save_id"])}', data_dump: '{escape_quotes(data["data_dump"])}', name: '{escape_quotes(data["name"])}', description: '{escape_quotes(data["description"])}', media: '{escape_quotes(data["media"])}', shared: {str(data["shared"]).lower()} - }}""" +}}""" return formatted + if __name__ == "__main__": # Create a request object factory = RequestFactory() diff --git a/blocks/open_editor.py b/blocks/open_editor.py index e9cf21e4..79e4d75c 100644 --- a/blocks/open_editor.py +++ b/blocks/open_editor.py @@ -19,6 +19,7 @@ service = ChromeService(ChromeDriverManager().install()) driver = webdriver.Chrome(service=service) wait = WebDriverWait(driver, 10) + def login_with_github(): driver.get('http://localhost/#/login') # Replace with your actual login page URL @@ -74,6 +75,7 @@ def login_with_github(): except Exception as e: print(f"An error occurred during GitHub login: {e}") + def wait_for_gallery_load(): try: # Wait until the `window.loadGalleryComplete` flag is set to true @@ -82,6 +84,7 @@ def wait_for_gallery_load(): except Exception as e: print(f"Error waiting for gallery load: {e}") + def main(): login_with_github() # After logging in, navigate to the gallery page @@ -113,7 +116,7 @@ def main(): print(snackbar_message.text) # Verify the share button is displayed - share_button = wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="root"]/div/header/div[1]/button[2]'))) + wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="root"]/div/header/div[1]/button[2]'))) print("Share button is displayed, diagram has been saved.") # Verify the "last saved" text is displayed @@ -132,5 +135,6 @@ def main(): input("Press Enter to close the browser...") driver.quit() + if __name__ == "__main__": main() diff --git a/blocks/saveAPI/models.py b/blocks/saveAPI/models.py index 3adbd0bc..5736451e 100644 --- a/blocks/saveAPI/models.py +++ b/blocks/saveAPI/models.py @@ -14,6 +14,7 @@ file_storage = FileSystemStorage( media = FileSystemStorage( location=settings.MEDIA_ROOT, base_url='.') + class StateSave(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=200, null=True) |