def deserializeFromClipboard(self, data: dict): """ Deserializes data from Clipboard. :param data: ``dict`` data for deserialization to the :class:`nodeeditor.node_scene.Scene`. :type data: ``dict`` """ hashmap = {} # calculate mouse pointer - scene position view = self.scene.getView() 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 tehe 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 = self.scene.getNodeClassFromData(node_data)(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", setModified=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 deserializeFromClipboard(self, data:dict, *args, **kwargs): """ Deserializes data from Clipboard. :param data: ``dict`` data for deserialization to the :class:`nodeeditor.node_scene.Scene`. :type data: ``dict`` """ hashmap = {} # calculate mouse pointer - scene position view = self.scene.getView() mouse_scene_pos = view.last_scene_mouse_position # calculate selected objects bbox and center minx, maxx, miny, maxy = 10000000,-10000000, 10000000,-10000000 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 # add width and height of a node maxx -= 180 maxy += 100 relbboxcenterx = (minx + maxx) / 2 - minx relbboxcentery = (miny + maxy) / 2 - miny if DEBUG_PASTING: print (" *** PASTA:") print("Copied boudaries:\n\tX:", minx, maxx, " Y:", miny, maxy) print("\tbbox_center:", relbboxcenterx, relbboxcentery) # calculate the offset of the newly creating nodes mousex, mousey = mouse_scene_pos.x(), mouse_scene_pos.y() # create each node created_nodes = [] self.scene.setSilentSelectionEvents() self.scene.doDeselectItems() for node_data in data['nodes']: new_node = self.scene.getNodeClassFromData(node_data)(self.scene) new_node.deserialize(node_data, hashmap, restore_id=False, *args, **kwargs) created_nodes.append(new_node) # readjust the new nodeeditor's position # new node's current position posx, posy = new_node.pos.x(), new_node.pos.y() newx, newy = mousex + posx - minx, mousey + posy - miny new_node.setPos(newx, newy) new_node.doSelect() if DEBUG_PASTING: print("** PASTA SUM:") print("\tMouse pos:", mousex, mousey) print("\tnew node pos:", posx, posy) print("\tFINAL:", newx, newy) # 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, *args, **kwargs) self.scene.setSilentSelectionEvents(False) # store history self.scene.history.storeHistory("Pasted elements in scene", setModified=True) return created_nodes