Exemplo n.º 1
0
    def canConnectTmpNodes(self, dataTmpClip, clip, clipIndex):
        """
            Returns True if the connection between the nodes is possible, else False.
            This function is called by Clip.qml on the event onDragEnter, to display in real time if the nodes can be connected (during a creation of a connection).
            It simulates a connection and calls the function self.canConnect(clip1, clip2).
        """
        buttleData = ButtleDataSingleton().get()

        # we split the data of the tmpClip (from mimeData) to find needed informations about this clip.
        infosTmpClip = dataTmpClip.split("/")

        if infosTmpClip[0] != "clip" or len(infosTmpClip) != 4:
            return False
        else:
            tmpClipNodeName, tmpClipName, tmpClipIndex = infosTmpClip[1], infosTmpClip[2], int(infosTmpClip[3])

        # we find the position of this tmpClip to be able to create a IdClip object.
        positionTmpClip = buttleData.getGraphWrapper().getPositionClip(tmpClipNodeName, tmpClipName, tmpClipIndex)
        tmpClip = IdClip(tmpClipNodeName, tmpClipName, clipIndex, positionTmpClip)

        if tmpClip:
            # idem, for the "dropped" clip = newClip
            positionNewClip = buttleData.getGraphWrapper().getPositionClip(clip.getNodeName(), clip.getClipName(), clipIndex)
            newClip = IdClip(clip.getNodeName(), clip.getClipName(), clipIndex, positionNewClip)

            # finally we return if the clips can be connected
            return self.canConnect(tmpClip, newClip)

        else:
            return False
Exemplo n.º 2
0
    def canConnectTmpNodes(self, dataTmpClip, clip, clipIndex):
        """
            Returns True if the connection between the nodes is possible, else False.
            This function is called by Clip.qml on the event onDragEnter, to display in real time if the nodes can be connected (during a creation of a connection).
            It simulates a connection and calls the function self.canConnect(clip1, clip2).
        """
        buttleData = ButtleDataSingleton().get()

        # we split the data of the tmpClip (from mimeData) to find needed informations about this clip.
        infosTmpClip = dataTmpClip.split("/")

        if infosTmpClip[0] != "clip" or len(infosTmpClip) != 4:
            return False
        else:
            tmpClipNodeName, tmpClipName, tmpClipIndex = infosTmpClip[
                1], infosTmpClip[2], int(infosTmpClip[3])

        # we find the position of this tmpClip to be able to create a IdClip object.
        positionTmpClip = buttleData.getGraphWrapper().getPositionClip(
            tmpClipNodeName, tmpClipName, tmpClipIndex)
        tmpClip = IdClip(tmpClipNodeName, tmpClipName, clipIndex,
                         positionTmpClip)

        if tmpClip:
            # idem, for the "dropped" clip = newClip
            positionNewClip = buttleData.getGraphWrapper().getPositionClip(
                clip.getNodeName(), clip.getClipName(), clipIndex)
            newClip = IdClip(clip.getNodeName(), clip.getClipName(), clipIndex,
                             positionNewClip)

            # finally we return if the clips can be connected
            return self.canConnect(tmpClip, newClip)

        else:
            return False
Exemplo n.º 3
0
    def connectionDropEvent(self, dataTmpClip, clip, clipIndex):
        """
            Creates or deletes a connection between 2 clips ('tmpClip', the "dragged" clip, and 'newClip', the "dropped" clip)
            Arguments :
            - dataTmpClip : the string from mimeData, identifying the tmpClip (the "dragged" clip).
            - clip : the ClipWrapper of the "dropped" clip.
            - clipIndex : the index of the "dropped" clip.
        """
        buttleData = ButtleDataSingleton().get()

        # we split the data of the tmpClip (from mimeData) to find needed informations about this clip.
        infosTmpClip = dataTmpClip.split("/")

        if infosTmpClip[0] != "clip" or len(infosTmpClip) != 4:
            return  # use exception !
        else:
            tmpClipNodeName, tmpClipName, tmpClipIndex = infosTmpClip[
                1], infosTmpClip[2], int(infosTmpClip[3])

        # we find the position of this tmpClip to be able to create a IdClip object.
        positionTmpClip = buttleData.getGraphWrapper().getPositionClip(
            tmpClipNodeName, tmpClipName, tmpClipIndex)
        tmpClip = IdClip(tmpClipNodeName, tmpClipName, clipIndex,
                         positionTmpClip)

        if tmpClip:
            # idem, for the "dropped" clip = newClip
            positionNewClip = buttleData.getGraphWrapper().getPositionClip(
                clip.getNodeName(), clip.getClipName(), clipIndex)
            newClip = IdClip(clip.getNodeName(), clip.getClipName(), clipIndex,
                             positionNewClip)

            # a connection must be created from the ouput clip to the input clip (the order of the arguments is important !)
            if tmpClip.getClipName() == "Output":
                clipOut, clipIn = tmpClip, newClip
            else:
                clipOut, clipIn = newClip, tmpClip

            # if the clips can be connected, we connect them
            if self.canConnect(clipOut, clipIn):
                self.connect(clipOut, clipIn)
                return

            # else if they can't be connected, we check if they are already connected, and disconnect them if it is the case.
            else:
                connection = buttleData.getGraph().getConnectionByClips(
                    clipOut, clipIn)
                if connection:
                    self.disconnect(
                        buttleData.getGraphWrapper().getConnectionWrapper(
                            connection.getId()))
                    return

        # update undo/redo display
        self.undoRedoChanged()
Exemplo n.º 4
0
    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()
Exemplo n.º 5
0
    def connectionDropEvent(self, dataTmpClip, clip, clipIndex):
        """
            Creates or deletes a connection between 2 clips ('tmpClip', the "dragged" clip, and 'newClip', the "dropped" clip)
            Arguments :
            - dataTmpClip : the string from mimeData, identifying the tmpClip (the "dragged" clip).
            - clip : the ClipWrapper of the "dropped" clip.
            - clipIndex : the index of the "dropped" clip.
        """
        buttleData = ButtleDataSingleton().get()

        # we split the data of the tmpClip (from mimeData) to find needed informations about this clip.
        infosTmpClip = dataTmpClip.split("/")

        if infosTmpClip[0] != "clip" or len(infosTmpClip) != 4:
            return  # use exception !
        else:
            tmpClipNodeName, tmpClipName, tmpClipIndex = infosTmpClip[1], infosTmpClip[2], int(infosTmpClip[3])

        # we find the position of this tmpClip to be able to create a IdClip object.
        positionTmpClip = buttleData.getGraphWrapper().getPositionClip(tmpClipNodeName, tmpClipName, tmpClipIndex)
        tmpClip = IdClip(tmpClipNodeName, tmpClipName, clipIndex, positionTmpClip)

        if tmpClip:
            # idem, for the "dropped" clip = newClip
            positionNewClip = buttleData.getGraphWrapper().getPositionClip(clip.getNodeName(), clip.getClipName(), clipIndex)
            newClip = IdClip(clip.getNodeName(), clip.getClipName(), clipIndex, positionNewClip)

            # a connection must be created from the ouput clip to the input clip (the order of the arguments is important !)
            if tmpClip.getClipName() == "Output":
                clipOut, clipIn = tmpClip, newClip
            else:
                clipOut, clipIn = newClip, tmpClip

            # if the clips can be connected, we connect them
            if self.canConnect(clipOut, clipIn):
                self.connect(clipOut, clipIn)
                return

            # else if they can't be connected, we check if they are already connected, and disconnect them if it is the case.
            else:
                connection = buttleData.getGraph().getConnectionByClips(clipOut, clipIn)
                if connection:
                    self.disconnect(buttleData.getGraphWrapper().getConnectionWrapper(connection.getId()))
                    return

        # update undo/redo display
        self.undoRedoChanged()
Exemplo n.º 6
0
    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()