Ejemplo n.º 1
0
    def removePort(self, port: 'pt.Port') -> bool:
        """
		Removes a port from this action - no need to specify input or output.

		Removing the port from the action does not destroy the port. The caller should take
		special care to remove any wires if desired.

		:raises: PortException if the port is not found.

		:param port: The port instance to be removed.
		:type port: Port
		:return: True if the port was successfully removed, False otherwise.
		:rtype: bool
		"""

        if port not in Action.allPorts:
            raise pt.PortException("Port not found in any actions.")

        found = False
        if port in self._inputs:
            found = True
            self._inputs.remove(port)
        elif port in self._outputs:
            found = True
            self._outputs.remove(port)
        else:
            raise pt.PortException("Port not found in this action.")

        if found:
            Action.allPorts.remove(port)
            port.setAction(None)

        self.synchronizeWrappers()
        self.triggerUpdate()
        return found
    def removePort(self, port: 'Port') -> bool:
        """
		Removes a port from this action pipeline or a sub-action - no need to specify input or
		output.

		Removing the port from the action does not destroy the port.
		Removing a port removes all wires connected to the port.

		:raises: PortException if the port is not found.
		:raises: PortException if the port does not belong the ActionPipeline or a child action.
		:raises: PortException if the port does not have an action.

		:param port: The port instance to be removed.
		:type port: Port
		:return: True if the port was successfully removed, False otherwise.
		:rtype: bool
		"""

        if port.getAction() is not None:
            if port.getAction() in self._actions or port.getAction() is self:
                removed = Action.removePort(port.getAction(), port)
                self._wireSet.deleteWiresConnectedToPort(port)
                return removed
            else:
                raise pt.PortException(
                    "The port does not belong to this action pipeline or any children"
                )
        else:
            raise pt.PortException("The port does not have an action.")

        self.updated.emit()
    def disconnect(self, portA: 'Port', portB: 'Port') -> None:
        """
		Remove the wire spanning from portA to portB.
		
		:raises: PortException if either portA or portB do not belong to either this
		ActionPipeline or any of its inner actions.
		:raises: WireException if A wire does not exist from portA to portB.
		
		:param portA: The source port of the wire to disconnect.
		:type portA: Port
		:param portB: The destination port of the wire to disconnect.
		:type portA: Port
		:return: None
		:rtype: NoneType
		"""

        # Check for errors
        allowableActions = [self] + self._actions

        if portA.getAction() not in allowableActions:
            raise pt.PortException("The source port is invalid")

        if portB.getAction() not in allowableActions:
            raise pt.PortException("The destination port is invalid")

        wireFound = False
        if portB.getInputWire() is not None:
            if portB.getInputWire().getSourcePort() == portA:
                wireFound = True

        if not wireFound:
            raise WireException("There is no wire between the specified ports")

        # now we can delete the wire
        self._wireSet.deleteWire(portA, portB)
        self.updated.emit()
    def connect(self, portA: 'pt.Port', portB: 'pt.Port') -> 'Wire':
        """
		Insert a wire to carry data from port A to port B. Returns a reference to the newly created Wire.
		
		:raises: PortException if either portA or portB do not belong to either this
		ActionPipeline or any of its inner actions.
		:raises: PortException if portB already has an input.
		:raises: WireException if the connection is invalid.
		
		:param portA: The port that will be the source of the wire.
		:type portA: Port
		:param portB: The port that will be the destination of the wire.
		:type portB: Port
		:return: The newly created Wire object connecting the given ports.
		:rtype: Wire
		"""

        allowableActions = [self] + self._actions

        if portA.getAction() not in allowableActions:
            raise pt.PortException("The source port is invalid")

        if portB.getAction() not in allowableActions:
            raise pt.PortException("The destination port is invalid")

        if portB.getInputWire() is not None:
            raise pt.PortException(
                "The destination port already has an input wire.")

        if not self.connectionIsValid(portA, portB):
            raise WireException("The connection is not a valid configuration.")

        newWire = self._wireSet.addWire(portA, portB)
        self.updated.emit()

        return newWire
Ejemplo n.º 5
0
    def addWire(self, sourcePort: 'pt.Port',
                destPort: 'pt.Port') -> 'Wire or None':
        """
        Creates a new wire and adds it to the set of wires (WireSet).

        .. note:: Adding a wire that already exists will not add a new wire, but it will not 
            raise an exception either.

        :raises: PortException if the the destination port already has an input wire, 
                 but the wire is not a duplication.

        :param sourcePort: The Port to be connected to the input of the wire.
        :type sourcePort: Port
        :param destPort: The Port to be connected to the output of the wire.
        :type destPort: Port
        :return: A reference to the wire newly created wire. Return None if there is already a wire existing between
        the two given ports.
        :rtype: Wire or NoneType
        """
        # Check to see if the new wire is redundant with a wire that already exists in the WireSet.
        newWireAlreadyInSet = False
        for wire in self._wires:
            if (sourcePort, destPort) == wire.asTuple():
                newWireAlreadyInSet = True
                break

        if not newWireAlreadyInSet:
            if destPort.getInputWire() is not None:
                raise pt.PortException(
                    "The destination port already has an input!")

        # Only add wires that are unique (not redundant).
        if not newWireAlreadyInSet:
            newWire = Wire(sourcePort, destPort)  # Create the Wire.
            sourcePort.addOutputWire(
                newWire)  # Connect the wire to its source Port.
            destPort.setInputWire(
                newWire)  # Connect the wire to its destination Port.
            self._wires.append(newWire)  # Add the Wire to the WireSet.
            return newWire
        else:
            return None
Ejemplo n.º 6
0
    def addInputPort(self, port: 'pt.Port') -> None:
        """
		Adds a port to the list of inputs for this action.
		
		The port may have wires connected to it when added, but it is not recommended.
		The port instance cannot be used anywhere else.
		
		:raises: PortException if the port is used elsewhere.
		
		:param port: The new port to be added.
		:type port: Port
		:return: None
		:rtype: NoneType
		"""
        if port in Action.allPorts:
            raise pt.PortException(
                "Port is already used. Can't add port to action.")

        port.setAction(self)

        Action.allPorts.add(port)
        self._inputs.append(port)
        self.synchronizeWrappers()
        self.triggerUpdate()