def addModule(self, module, name=None, pos=(0, 0)): if name is None: name = 'new_module' n = 1 if self.graphView.hasNode(name): while self.graphView.hasNode('{}{}'.format(name, n)): n += 1 name = '{}{}'.format(name, n) g = self.graphView node = Node(g, name) if module.path.startswith('hardware'): node.setColor(palette.c2) elif module.path.startswith('logic'): node.setColor(palette.c1) elif module.path.startswith('gui'): node.setColor(palette.c4) else: node.setColor(palette.c3) for conn in module.conn_in: node.addPort(InputPort(node, g, conn[0], palette.c3, conn[1])) for conn in module.conn_out: node.addPort(OutputPort(node, g, conn[0], palette.c3, conn[1])) node.setGraphPos(QtCore.QPointF(pos[0], pos[1])) self.mods[name] = { 'node': node, 'module': module, } g.addNode(node)
def generateNodes(count, offset, depth): for i in range(count): node1 = Node(graph, 'node' + str(depth) + str(i)) node1.addPort( InputPort(node1, graph, 'InPort', QtGui.QColor(128, 170, 170, 255), 'MyDataX')) node1.addPort( OutputPort(node1, graph, 'OutPort', QtGui.QColor(32, 255, 32, 255), 'MyDataX')) node1.setGraphPos(QtCore.QPointF(offset, i * 80)) graph.addNode(node1) global totalCount totalCount += 1 if depth < 6: generateNodes(count * 2, offset + 160, depth + 1) for i in range(count): graph.connectPorts('node' + str(depth) + str(i), 'OutPort', 'node' + str(depth + 1) + str(i * 2), 'InPort') graph.connectPorts('node' + str(depth) + str(i), 'OutPort', 'node' + str(depth + 1) + str(i * 2 + 1), 'InPort') elif depth < 12: generateNodes(int(count / 2), offset + 160, depth + 1) for i in range(count / 2): graph.connectPorts('node' + str(depth) + str(i), 'OutPort', 'node' + str(depth + 1) + str(int(i)), 'InPort')
def addModule(self, module, name=None, pos=(0, 0)): """ Add a module to the GraphView """ # sort out the module name if name is None: name = 'new_module' n = 1 if self.graphView.hasNode(name): while self.graphView.hasNode('{}{}'.format(name, n)): n += 1 name = '{}{}'.format(name, n) # chart view g = self.graphView # new node in chart node = Node(g, name) # coloring node.setColor(self.colors[module.base]) # check where the module belongs and what it can connect to for conn in module.connections: port_type = QudiPortType('in', module.base, [conn[1]]) node.addPort(InputPort(node, g, conn[0], palette.c3, port_type)) if module.base != 'gui': port_type = QudiPortType('out', module.base, module.interfaces) node.addPort(OutputPort(node, g, 'out', palette.c3, port_type)) # set position in view node.setGraphPos(QtCore.QPointF(pos[0], pos[1])) # save the module instance and node relatonship self.mods[name] = { 'node': node, 'module': module, } # add node to view g.addNode(node)
def addModule(self, module, name=None, pos=(0,0)): """ Add a module to the GraphView """ # sort out the module name if name is None: name = 'new_module' n = 1 if self.graphView.hasNode(name): while self.graphView.hasNode('{}{}'.format(name, n)): n += 1 name = '{}{}'.format(name, n) # chart view g = self.graphView # new node in chart node = Node(g, name) # coloring node.setColor(self.colors[module.base]) # check where the module belongs and what it can connect to for conn in module.connections: port_type = QudiPortType('in', module.base, [conn[1]]) node.addPort(InputPort(node, g, conn[0], palette.c3, port_type)) if module.base != 'gui': port_type = QudiPortType('out', module.base, module.interfaces) node.addPort(OutputPort(node, g, 'out', palette.c3, port_type)) # set position in view node.setGraphPos(QtCore.QPointF(pos[0], pos[1])) # save the module instance and node relatonship self.mods[name] = { 'node': node, 'module': module, } # add node to view g.addNode(node)
def generateNodes(count, offset, depth): for i in range(count): node1 = Node(graph, 'node' + str(depth) + str(i)) node1.addPort(InputPort(node1, graph, 'InPort', QtGui.QColor(128, 170, 170, 255), 'MyDataX')) node1.addPort(OutputPort(node1, graph, 'OutPort', QtGui.QColor(32, 255, 32, 255), 'MyDataX')) node1.setGraphPos(QtCore.QPointF(offset, i * 80 )) graph.addNode(node1) global totalCount totalCount += 1 if depth < 6: generateNodes( count * 2, offset+160, depth+1) for i in range(count): graph.connectPorts('node' + str(depth) + str(i), 'OutPort', 'node' + str(depth+1) + str(i*2), 'InPort') graph.connectPorts('node' + str(depth) + str(i), 'OutPort', 'node' + str(depth+1) + str(i*2+1), 'InPort') elif depth < 12: generateNodes( int(count / 2), offset+160, depth+1) for i in range(count/2): graph.connectPorts('node' + str(depth) + str(i), 'OutPort', 'node' + str(depth+1) + str(int(i)), 'InPort')
def addNode(self): # NODE COLORS # text = 'Green = MESHES' node = Node(graph, "NODE COLOR ASSOCIATION") node.addPort( InputPort(node, graph, "GREEN = Meshes ", QtGui.QColor(243, 207, 139), 'MyDataX')) node.addPort( InputPort(node, graph, "PINK = Materials", QtGui.QColor(243, 207, 139), 'MyDataY')) node.addPort( InputPort(node, graph, "YELLOW = Cameras", QtGui.QColor(243, 207, 139), 'MyDataY')) node.addPort( InputPort(node, graph, "BLUE = SpotLights", QtGui.QColor(243, 207, 139), 'MyDataY')) node.setGraphPos(QtCore.QPointF(-250, 0)) node.setColor(QtGui.QColor(200, 200, 200, 255)) graph.addNode(node) text = fileContent.splitlines() lineList = [line.split() for line in text] myCamerasList = [] myMaterialsList = [] myMeshesList = [] mySpotLightsList = [] for line in lineList: # print line # GETS MESH NODES if line[0] == "createNode" and line[1] == "mesh": # print "My MESH Line" lineLength = len(line) - 1 meshNodeName = line[lineLength] meshNodeNameBroken = meshNodeName.split("\"") meshNodeNameClean = meshNodeNameBroken[1] myMeshesList.append(meshNodeNameClean) # GETS MATERIAL NODES elif line[0] == "createNode" and line[1] == "lambert": # print "My MAT Line" lineLength = len(line) - 1 matNodeName = line[lineLength] matNodeNameBroken = matNodeName.split("\"") matNodeNameClean = matNodeNameBroken[1] myMaterialsList.append(matNodeNameClean) # GETS CAMERA NODES elif line[0] == "createNode" and line[1] == "camera": # print "My MAT Line" lineLength = len(line) - 1 matNodeName = line[lineLength] matNodeNameBroken = matNodeName.split("\"") cameraNodeNameClean = matNodeNameBroken[1] myCamerasList.append(cameraNodeNameClean) # GETS SPOTLIGHT NODES elif line[0] == "createNode" and line[1] == "spotLight": # print "My MAT Line" lineLength = len(line) - 1 matNodeName = line[lineLength] matNodeNameBroken = matNodeName.split("\"") spotLightNodeNameClean = matNodeNameBroken[1] mySpotLightsList.append(spotLightNodeNameClean) # print myMeshesList x1 = len(myMeshesList) x2 = len(myMaterialsList) x3 = len(myCamerasList) x4 = len(mySpotLightsList) # print x # ADDIND NODE TYPES for meshNodeSpawn in range(x1): node = Node(graph, myMeshesList[meshNodeSpawn]) node.addPort( InputPort(node, graph, 'In ', QtGui.QColor(243, 207, 139), 'MyDataX')) node.addPort( OutputPort(node, graph, ' Out', QtGui.QColor(243, 207, 139), 'MyDataY')) node.setGraphPos(QtCore.QPointF(0, meshNodeSpawn * 80)) node.setColor(QtGui.QColor(92, 204, 146, 255)) graph.addNode(node) for materialNodeSpawn in range(x2): node = Node(graph, myMaterialsList[materialNodeSpawn]) node.addPort( InputPort(node, graph, 'In ', QtGui.QColor(243, 207, 139), 'MyDataX')) node.addPort( OutputPort(node, graph, ' Out', QtGui.QColor(243, 207, 139), 'MyDataY')) node.setGraphPos(QtCore.QPointF(150, materialNodeSpawn * 80)) node.setColor(QtGui.QColor(215, 140, 255, 255)) graph.addNode(node) for cameraNodeSpawn in range(x3): node = Node(graph, myCamerasList[cameraNodeSpawn]) node.addPort( InputPort(node, graph, 'In ', QtGui.QColor(243, 207, 139), 'MyDataX')) node.addPort( OutputPort(node, graph, ' Out', QtGui.QColor(243, 207, 139), 'MyDataY')) node.setGraphPos(QtCore.QPointF(300, cameraNodeSpawn * 80)) node.setColor(QtGui.QColor(243, 207, 139)) graph.addNode(node) for spotLightNodeSpawn in range(x4): node = Node(graph, mySpotLightsList[spotLightNodeSpawn]) node.addPort( InputPort(node, graph, 'In ', QtGui.QColor(243, 207, 139), 'MyDataX')) node.addPort( OutputPort(node, graph, ' Out', QtGui.QColor(243, 207, 139), 'MyDataY')) node.setGraphPos(QtCore.QPointF(450, spotLightNodeSpawn * 80)) node.setColor(QtGui.QColor(79, 170, 204, 255)) graph.addNode(node)
app = QtCore.QCoreApplication.instance() if not app: app = QtWidgets.QApplication(sys.argv) widget = GraphViewWidget() graph = GraphView(parent=widget) node1 = Node(graph, 'Short') node1.addPort(InputPort(node1, graph, 'InPort1', QtGui.QColor(128, 170, 170, 255), 'MyDataX')) node1.addPort(InputPort(node1, graph, 'InPort2', QtGui.QColor(128, 170, 170, 255), 'MyDataX')) node1.addPort(OutputPort(node1, graph, 'OutPort', QtGui.QColor(32, 255, 32, 255), 'MyDataY')) node1.addPort(IOPort(node1, graph, 'IOPort1', QtGui.QColor(32, 255, 32, 255), 'MyDataY')) node1.addPort(IOPort(node1, graph, 'IOPort2', QtGui.QColor(32, 255, 32, 255), 'MyDataY')) node1.setGraphPos(QtCore.QPointF( -100, 0 )) graph.addNode(node1) node2 = Node(graph, 'ReallyLongLabel') node2.addPort(InputPort(node2, graph, 'InPort1', QtGui.QColor(128, 170, 170, 255), 'MyDataY')) node2.addPort(InputPort(node2, graph, 'InPort2', QtGui.QColor(128, 170, 170, 255), 'MyDataX')) node2.addPort(OutputPort(node2, graph, 'OutPort', QtGui.QColor(32, 255, 32, 255), 'MyDataY')) node2.addPort(IOPort(node2, graph, 'IOPort1', QtGui.QColor(32, 255, 32, 255), 'MyDataY')) node2.addPort(IOPort(node2, graph, 'IOPort2', QtGui.QColor(32, 255, 32, 255), 'MyDataY')) node2.setGraphPos(QtCore.QPointF( 100, 0 )) graph.addNode(node2) graph.connectPorts(node1, 'OutPort', node2, 'InPort1') widget.setGraphView(graph)
node1 = Node(graph, 'Short') node1.addPort( InputPort(node1, graph, 'InPort1', QtGui.QColor(128, 170, 170, 255), 'MyDataX')) node1.addPort( InputPort(node1, graph, 'InPort2', QtGui.QColor(128, 170, 170, 255), 'MyDataX')) node1.addPort( OutputPort(node1, graph, 'OutPort', QtGui.QColor(32, 255, 32, 255), 'MyDataY')) node1.addPort( IOPort(node1, graph, 'IOPort1', QtGui.QColor(32, 255, 32, 255), 'MyDataY')) node1.addPort( IOPort(node1, graph, 'IOPort2', QtGui.QColor(32, 255, 32, 255), 'MyDataY')) node1.setGraphPos(QtCore.QPointF(-100, 0)) graph.addNode(node1) node2 = Node(graph, 'ReallyLongLabel') node2.addPort( InputPort(node2, graph, 'InPort1', QtGui.QColor(128, 170, 170, 255), 'MyDataY')) node2.addPort( InputPort(node2, graph, 'InPort2', QtGui.QColor(128, 170, 170, 255), 'MyDataX')) node2.addPort( OutputPort(node2, graph, 'OutPort', QtGui.QColor(32, 255, 32, 255), 'MyDataY')) node2.addPort( IOPort(node2, graph, 'IOPort1', QtGui.QColor(32, 255, 32, 255), 'MyDataY'))