def duplicationNode(self): """ Duplicates the current node(s). """ buttleData = ButtleDataSingleton().get() if buttleData.getCurrentSelectedNodeWrappers() != []: for node in buttleData.getCurrentSelectedNodeWrappers(): # Create a node giving the current selected node's type, x and y nodeType = node.getNode().getType() coord = node.getNode().getCoord() buttleData.getGraph().createNode(nodeType, coord[0], coord[1]) newNode = buttleData.getGraph().getNodes()[-1] # Get the current selected node's properties nameUser = node.getNameUser() + "_duplicate" oldCoord = node.getNode().getOldCoord() color = node.getNode().getColor() # Use the current selected node's properties to set the duplicated node's properties newNode.setNameUser(nameUser) newNode.setOldCoord(oldCoord[0], oldCoord[1]) newNode.setColor(color) newNode.getTuttleNode().getParamSet().copyParamsValues( node.getNode().getTuttleNode().getParamSet()) # update undo/redo display self.undoRedoChanged()
def duplicationNode(self): """ Duplicates the current node(s). """ buttleData = ButtleDataSingleton().get() if buttleData.getCurrentSelectedNodeWrappers() != []: for node in buttleData.getCurrentSelectedNodeWrappers(): # Create a node giving the current selected node's type, x and y nodeType = node.getNode().getType() coord = node.getNode().getCoord() buttleData.getGraph().createNode(nodeType, coord[0], coord[1]) newNode = buttleData.getGraph().getNodes()[-1] # Get the current selected node's properties nameUser = node.getNameUser() + "_duplicate" oldCoord = node.getNode().getOldCoord() color = node.getNode().getColor() # Use the current selected node's properties to set the duplicated node's properties newNode.setNameUser(nameUser) newNode.setOldCoord(oldCoord[0], oldCoord[1]) newNode.setColor(color) newNode.getTuttleNode().getParamSet().copyParamsValues(node.getNode().getTuttleNode().getParamSet()) # update undo/redo display self.undoRedoChanged()
def nodeMoved(self, nodeName, newX, newY): """ This function pushes a cmdMoved in the CommandManager. """ from buttleofx.data import ButtleDataSingleton buttleData = ButtleDataSingleton().get() node = buttleData.getGraph().getNode(nodeName) # What is the value of the movement (compared to the old position) ? oldX, oldY = node.getOldCoord() xMovement = newX - oldX yMovement = newY - oldY # if the node did'nt really move, nothing is done if (xMovement, xMovement) == (0, 0): return commands = [] # we create a GroupUndoableCommands of CmdSetCoord for each selected node for selectedNodeWrapper in buttleData.getCurrentSelectedNodeWrappers(): # we get the needed informations for this node selectedNode = selectedNodeWrapper.getNode() selectedNodeName = selectedNode.getName() oldX, oldY = selectedNode.getOldCoord() # we set the new coordinates of the node (each selected node is doing the same movement) cmdMoved = CmdSetCoord(self, selectedNodeName, (oldX + xMovement, oldY + yMovement)) commands.append(cmdMoved) # then we push the group of commands CommandManager().push(GroupUndoableCommands(commands))
def copyNode(self): """ Copies the current node(s). """ buttleData = ButtleDataSingleton().get() # Clear the info saved in currentCopiedNodesInfo buttleData.clearCurrentCopiedNodesInfo() # Save new data in currentCopiedNodesInfo for each selected node if buttleData.getCurrentSelectedNodeWrappers() != []: for node in buttleData.getCurrentSelectedNodeWrappers(): copyNode = {} copyNode.update({"nodeType": node.getNode().getType()}) copyNode.update({"nameUser": node.getNode().getNameUser()}) copyNode.update({"color": node.getNode().getColor()}) copyNode.update({"params": node.getNode().getTuttleNode().getParamSet()}) copyNode.update({"mode": "_copy"}) buttleData.getCurrentCopiedNodesInfo()[node.getName()] = copyNode # Emit the change for the toolbar buttleData.pastePossibilityChanged.emit()
def cutNode(self): """ Cuts the current node(s). """ # Call the copyNode function to save the data of the selected nodes self.copyNode() buttleData = ButtleDataSingleton().get() # If we are sure that at least one node is selected if buttleData.getCurrentSelectedNodeWrappers() != []: for node in buttleData.getCurrentSelectedNodeWrappers(): # We precise that we want to cut the node and not only copy it buttleData.getCurrentCopiedNodesInfo()[node.getName()].update({"mode": ""}) # And we delete it self.destructionNodes() # And update the view if necessary if buttleData.getCurrentViewerNodeName() in buttleData.getCurrentSelectedNodeNames(): buttleData.setCurrentViewerNodeName(None) if buttleData.getCurrentParamNodeName() in buttleData.getCurrentSelectedNodeNames(): buttleData.setCurrentParamNodeName(None) # Emit the change for the toolbar buttleData.pastePossibilityChanged.emit()
def copyNode(self): """ Copies the current node(s). """ buttleData = ButtleDataSingleton().get() # Clear the info saved in currentCopiedNodesInfo buttleData.clearCurrentCopiedNodesInfo() # Save new data in currentCopiedNodesInfo for each selected node if buttleData.getCurrentSelectedNodeWrappers() != []: for node in buttleData.getCurrentSelectedNodeWrappers(): copyNode = {} copyNode.update({"nodeType": node.getNode().getType()}) copyNode.update({"nameUser": node.getNode().getNameUser()}) copyNode.update({"color": node.getNode().getColor()}) copyNode.update( {"params": node.getNode().getTuttleNode().getParamSet()}) copyNode.update({"mode": "_copy"}) buttleData.getCurrentCopiedNodesInfo()[ node.getName()] = copyNode # Emit the change for the toolbar buttleData.pastePossibilityChanged.emit()
def cutNode(self): """ Cuts the current node(s). """ # Call the copyNode function to save the data of the selected nodes self.copyNode() buttleData = ButtleDataSingleton().get() # If we are sure that at least one node is selected if buttleData.getCurrentSelectedNodeWrappers() != []: for node in buttleData.getCurrentSelectedNodeWrappers(): # We precise that we want to cut the node and not only copy it buttleData.getCurrentCopiedNodesInfo()[node.getName()].update( {"mode": ""}) # And we delete it self.destructionNodes() # And update the view if necessary if buttleData.getCurrentViewerNodeName( ) in buttleData.getCurrentSelectedNodeNames(): buttleData.setCurrentViewerNodeName(None) if buttleData.getCurrentParamNodeName( ) in buttleData.getCurrentSelectedNodeNames(): buttleData.setCurrentParamNodeName(None) # Emit the change for the toolbar buttleData.pastePossibilityChanged.emit()
def nodeIsMoving(self, nodeName, newX, newY): """ This function updates the position of the selected nodes and the connections, when one or several nodes are moving. """ buttleData = ButtleDataSingleton().get() node = buttleData.getGraph().getNode(nodeName) # What is the value of the movement (compared to the old position) ? oldX, oldY = node.getCoord() xMovement = newX - oldX yMovement = newY - oldY # for each selected node, we update the position considering the value of the movement for selectedNodeWrapper in buttleData.getCurrentSelectedNodeWrappers(): selectedNode = selectedNodeWrapper.getNode() currentX, currentY = selectedNode.getCoord() selectedNode.setCoord(currentX + xMovement, currentY + yMovement) # we update also the position of all the connections buttleData.getGraph().connectionsCoordChanged(selectedNode)
def destructionNodes(self): """ Deletes the current node(s). """ buttleData = ButtleDataSingleton().get() # if the params of the current node deleted are display if buttleData.getCurrentParamNodeName( ) in buttleData.getCurrentSelectedNodeNames(): buttleData.setCurrentParamNodeName(None) # if the viewer of the current node deleted is display if buttleData.getCurrentViewerNodeName( ) in buttleData.getCurrentSelectedNodeNames(): buttleData.setCurrentViewerNodeName(None) # if the viewer display a node affected by the destruction # need something from Tuttle # if at least one node in the graph if len(buttleData.getGraphWrapper().getNodeWrappers()) > 0 and len( buttleData.getGraph().getNodes()) > 0: # if a node is selected if buttleData.getCurrentSelectedNodeNames() != []: buttleData.getGraph().deleteNodes([ nodeWrapper.getNode() for nodeWrapper in buttleData.getCurrentSelectedNodeWrappers() ]) buttleData.clearCurrentSelectedNodeNames() # emit signals buttleData.currentParamNodeChanged.emit() buttleData.currentViewerNodeChanged.emit() buttleData.currentSelectedNodesChanged.emit() # update undo/redo display self.undoRedoChanged()
def destructionNodes(self): """ Deletes the current node(s). """ buttleData = ButtleDataSingleton().get() # if the params of the current node deleted are display if buttleData.getCurrentParamNodeName() in buttleData.getCurrentSelectedNodeNames(): buttleData.setCurrentParamNodeName(None) # if the viewer of the current node deleted is display if buttleData.getCurrentViewerNodeName() in buttleData.getCurrentSelectedNodeNames(): buttleData.setCurrentViewerNodeName(None) # if the viewer display a node affected by the destruction # need something from Tuttle # if at least one node in the graph if len(buttleData.getGraphWrapper().getNodeWrappers()) > 0 and len(buttleData.getGraph().getNodes()) > 0: # if a node is selected if buttleData.getCurrentSelectedNodeNames() != []: buttleData.getGraph().deleteNodes([nodeWrapper.getNode() for nodeWrapper in buttleData.getCurrentSelectedNodeWrappers()]) buttleData.clearCurrentSelectedNodeNames() # emit signals buttleData.currentParamNodeChanged.emit() buttleData.currentViewerNodeChanged.emit() buttleData.currentSelectedNodesChanged.emit() # update undo/redo display self.undoRedoChanged()