def deserialize(self, data, hashmap={}, restore_id=True): self.clear() hashmap = {} if restore_id: self.id = data['id'] # create nodes for node_data in data['nodes']: Node(self).deserialize(node_data, hashmap, restore_id) # create edges for edge_data in data['edges']: Edge(self).deserialize(edge_data, hashmap, restore_id) return True
def deserializeFromClipboard(self, data): hashmap = {} # calculate mouse pointer - scene position view = self.scene.grScene.views()[0] mouse_scene_pos = view.last_scene_mouse_position # calculate selected objects bbox and center minx, maxx, miny, maxy = 0, 0, 0, 0 for node_data in data['nodes']: x, y = node_data['pos_x'], node_data['pos_y'] if x < minx: minx = x if x > maxx: maxx = x if y < miny: miny = y if y > maxy: maxy = y bbox_center_x = (minx + maxx) / 2 bbox_center_y = (miny + maxy) / 2 #center = view.mapToScene(view.rect().center()) # calculate the offset of the newly creating nodes offset_x = mouse_scene_pos.x() - bbox_center_x offset_y = mouse_scene_pos.y() - bbox_center_y # create each node for node_data in data['nodes']: new_node = Node(self.scene) new_node.deserialize(node_data, hashmap, restore_id=False) # readjust the new node's position pos = new_node.pos new_node.setPos(pos.x() + offset_x, pos.y() + offset_y) # create each edge if 'edges' in data: for edge_data in data['edges']: new_edge = Edge(self.scene) new_edge.deserialize(edge_data, hashmap, restore_id=False) # store history self.scene.history.storeHistory("Pasted elements in scene")
def addNodes(self): node1 = Node(self.scene, "My Awesome Node 1", inputs=[0, 2, 3], outputs=[1]) node2 = Node(self.scene, "My Awesome Node 2", inputs=[1, 4, 5], outputs=[1]) node3 = Node(self.scene, "My Awesome Node 3", inputs=[4, 0, 2], outputs=[1]) node1.setPos(-350, -250) node2.setPos(-75, 0) node3.setPos(200, -150) edge1 = Edge(self.scene, node1.outputs[0], node2.inputs[0], edge_type=EDGE_TYPE_BEZIER) edge2 = Edge(self.scene, node2.outputs[0], node3.inputs[1], edge_type=EDGE_TYPE_BEZIER)
def addNodes(self): node1 = Node(self.scene, "My Awesome Node 1", inputs=[0, 0, 0], outputs=[1]) node2 = Node(self.scene, "My Awesome Node 2", inputs=[3, 3, 3], outputs=[1]) node3 = Node(self.scene, "My Awesome Node 3", inputs=[2, 2, 2], outputs=[1]) node1.setPos(-350, -250) node2.setPos(-75, 0) node3.setPos(200, -150) edge1 = Edge(self.scene, node1.outputs[0], node2.inputs[0], edge_type=EDGE_TYPE_BEZIER) edge2 = Edge(self.scene, node2.outputs[0], node3.inputs[0], edge_type=EDGE_TYPE_BEZIER) self.scene.history.storeInitialHistoryStamp()
def addNodes(self): """Testing method to create 3 `Nodes` with 3 `Edges` connecting them""" node1 = Node(self.scene, "My Awesome Node 1", inputs=[0, 0, 0], outputs=[1, 5]) node2 = Node(self.scene, "My Awesome Node 2", inputs=[3, 3, 3], outputs=[1]) node3 = Node(self.scene, "My Awesome Node 3", inputs=[2, 2, 2], outputs=[1]) node1.setPos(-350, -250) node2.setPos(-75, 0) node3.setPos(200, -200) edge1 = Edge(self.scene, node1.outputs[0], node2.inputs[0], edge_type=EDGE_TYPE_BEZIER) edge2 = Edge(self.scene, node2.outputs[0], node3.inputs[0], edge_type=EDGE_TYPE_BEZIER) edge3 = Edge(self.scene, node1.outputs[0], node3.inputs[2], edge_type=EDGE_TYPE_BEZIER) self.scene.history.storeInitialHistoryStamp()