Exemplo n.º 1
0
    def connect_subject(self, handle):
        line = self.line
        assert line

        # TODO: connect opposite side again (in case it's a join/fork or
        #       decision/merge node)
        c1 = self.get_connected(line.head)
        c2 = self.get_connected(line.tail)
        assert c1 and c2
        assert isinstance(c1.subject, UML.ActivityNode)

        if isinstance(c1.subject, UML.ObjectNode) or isinstance(
                c2.subject, UML.ObjectNode):
            relation: UML.ActivityEdge = self.relationship_or_new(
                UML.ObjectFlow, UML.ObjectFlow.source, UML.ObjectFlow.target)
        else:
            relation = self.relationship_or_new(UML.ControlFlow,
                                                UML.ControlFlow.source,
                                                UML.ControlFlow.target)
        line.subject = relation
        relation.activity = c1.subject.activity
        opposite = line.opposite(handle)
        otc = self.get_connected(opposite)
        if opposite and isinstance(otc, (ForkNodeItem, DecisionNodeItem)):
            adapter = Connector(otc, line)
            adapter.combine_nodes()
Exemplo n.º 2
0
 def unlink(self):
     c1 = self._connections.get_connection(self.head)
     c2 = self._connections.get_connection(self.tail)
     if c1 and c2:
         adapter = Connector(c1.connected, self)
         adapter.disconnect(self.head)
     super().unlink()
Exemplo n.º 3
0
def connectable(line, handle, element):
    connector = Connector(element, line)
    for port in element.ports():
        allow = connector.allow(handle, port)
        if allow:
            return True
    return False
Exemplo n.º 4
0
 def disconnect_subject(self, handle):
     super().disconnect_subject(handle)
     line = self.line
     opposite = line.opposite(handle)
     otc = self.get_connected(opposite)
     if opposite and isinstance(otc, (ForkNodeItem, DecisionNodeItem)):
         adapter = Connector(otc, line)
         adapter.decombine_nodes()
Exemplo n.º 5
0
def connected_proxy_port_item(diagram, element_factory):
    proxy_port_item = diagram.create(ProxyPortItem)
    block_item = diagram.create(BlockItem,
                                subject=element_factory.create(sysml.Block))

    connector = Connector(block_item, proxy_port_item)
    connector.connect(proxy_port_item.handles()[0], block_item.ports()[0])

    return proxy_port_item
Exemplo n.º 6
0
    def unlink(self):
        assert self.canvas

        canvas = self.canvas
        c1 = canvas.get_connection(self.head)
        c2 = canvas.get_connection(self.tail)
        if c1 and c2:
            adapter = Connector(c1.connected, self)
            adapter.disconnect(self.head)
        super().unlink()
Exemplo n.º 7
0
    def allow(self, line, handle, item, port=None):
        """Glue line's handle to an item.

        If port is not provided, then first port is used.
        """
        if port is None and len(item.ports()) > 0:
            port = item.ports()[0]

        adapter = Connector(item, line)
        return adapter.allow(handle, port)
Exemplo n.º 8
0
def test_connect_proxy_port_to_block(diagram, block_item, proxy_port_item):
    connector = Connector(block_item, proxy_port_item)

    connected = connector.connect(proxy_port_item.handles()[0],
                                  block_item.ports()[0])

    assert connected
    assert proxy_port_item.subject
    assert proxy_port_item.subject.encapsulatedClassifier is block_item.subject
    assert proxy_port_item.subject in block_item.subject.ownedPort
Exemplo n.º 9
0
    def __call__(self):
        handle = self.handle
        item = self.item
        connections = self.connections
        cinfo = connections.get_connection(handle)

        if self.disable:
            log.debug(f"Not disconnecting {item}.{handle} (disabled)")
        else:
            log.debug(f"Disconnecting {item}.{handle}")
            if cinfo:
                adapter = Connector(cinfo.connected, item)
                adapter.disconnect(handle)
Exemplo n.º 10
0
    def __call__(self):
        handle = self.handle
        item = self.item
        connections = self.connections
        cinfo = connections.get_connection(handle)

        if self.disable:
            log.debug(f"Disconnect callback disabled for {item}.{handle} (disabled)")
        else:
            log.debug(f"Disconnect callback {item}.{handle}")
            if cinfo:
                adapter = Connector(cinfo.connected, item)
                adapter.disconnect(handle)
        self.item.handle(
            ItemDisconnected(self.item, self.handle, cinfo.connected, cinfo.port)
        )
Exemplo n.º 11
0
    def connect(self, handle, port):
        lifeline = self.element.subject
        exec_spec: UML.ExecutionSpecification = self.line.subject
        model = self.element.model
        if not exec_spec:
            exec_spec = model.create(UML.BehaviorExecutionSpecification)
            self.line.subject = exec_spec

            start_occurence: UML.ExecutionOccurrenceSpecification = model.create(
                UML.ExecutionOccurrenceSpecification
            )
            start_occurence.covered = lifeline
            start_occurence.execution = exec_spec

            finish_occurence: UML.ExecutionOccurrenceSpecification = model.create(
                UML.ExecutionOccurrenceSpecification
            )
            finish_occurence.covered = lifeline
            finish_occurence.execution = exec_spec

        canvas = self.canvas
        if canvas.get_parent(self.line) is not self.element:
            reparent(canvas, self.line, self.element)

        for cinfo in canvas.get_connections(connected=self.line):
            Connector(self.line, cinfo.item).connect(cinfo.handle, cinfo.port)
        return True
Exemplo n.º 12
0
    def connect(self, handle, port):
        lifeline = self.element.subject
        exec_spec = self.line.subject
        model = self.element.model
        if not exec_spec:
            exec_spec = model.create(UML.BehaviorExecutionSpecification)
            self.line.subject = exec_spec

            start_occurence: UML.ExecutionOccurrenceSpecification = model.create(
                UML.ExecutionOccurrenceSpecification)
            start_occurence.covered = lifeline
            start_occurence.execution = exec_spec

            finish_occurence: UML.ExecutionOccurrenceSpecification = model.create(
                UML.ExecutionOccurrenceSpecification)
            finish_occurence.covered = lifeline
            finish_occurence.execution = exec_spec

        if lifeline.interaction:
            exec_spec.enclosingInteraction = lifeline.interaction

        diagram = self.diagram
        if self.line.parent is not self.element:
            self.line.parent = self.element

        for cinfo in diagram.connections.get_connections(connected=self.line):
            Connector(self.line, cinfo.item).connect(cinfo.handle, cinfo.port)
        return True
Exemplo n.º 13
0
    def disconnect(self, handle):
        exec_spec: Optional[UML.ExecutionSpecification] = self.line.subject
        del self.line.subject
        if exec_spec and not exec_spec.presentation:
            exec_spec.unlink()

        for cinfo in self.canvas.get_connections(connected=self.line):
            Connector(self.line, cinfo.item).disconnect(cinfo.handle)
Exemplo n.º 14
0
def test_disconnect_proxy_port_to_block(diagram, block_item, proxy_port_item):
    connector = Connector(block_item, proxy_port_item)
    connector.connect(proxy_port_item.handles()[0], block_item.ports()[0])

    connector.disconnect(proxy_port_item.handles()[0])

    assert proxy_port_item.subject is None
    assert proxy_port_item.diagram
Exemplo n.º 15
0
    def disconnect(self, handle):
        exec_spec: Optional[UML.ExecutionSpecification] = self.line.subject
        del self.line.subject
        if exec_spec:
            exec_spec.unlink()

        canvas = self.canvas

        if canvas.get_parent(self.line) is self.element:
            new_parent = canvas.get_parent(self.element)
            reparent(canvas, self.line, new_parent)

        for cinfo in canvas.get_connections(connected=self.line):
            Connector(self.line, cinfo.item).disconnect(cinfo.handle)
Exemplo n.º 16
0
    def disconnect(self, handle):
        exec_spec: Optional[UML.ExecutionSpecification] = self.line.subject
        del self.line.subject
        if exec_spec:
            exec_spec.unlink()

        diagram = self.diagram

        if self.line.parent is self.element:
            new_parent = self.element.parent
            self.line.parent = new_parent  # type: ignore[assignment]

        for cinfo in diagram.connections.get_connections(connected=self.line):
            Connector(self.line, cinfo.item).disconnect(cinfo.handle)
Exemplo n.º 17
0
    def connect(self, handle, _port):
        parent_exec_spec = self.element.subject

        if not parent_exec_spec:
            # Can connect child exec spec if parent is not connected
            return True

        connected_item: Optional[UML.Presentation[UML.Element]]
        connected_item = self.get_connected(self.element.handles()[0])
        assert connected_item
        Connector(connected_item, self.line).connect(handle, None)

        reparent(self.canvas, self.line, self.element)

        return True
Exemplo n.º 18
0
    def connect(self, sink):
        """Create connection at handle level and at model level."""
        handle = self.handle
        item = self.item
        cinfo = self.connections.get_connection(handle)

        if cinfo and cinfo.connected is sink.item:
            # reconnect only constraint - leave model intact
            log.debug("performing reconnect constraint")
            self.glue(sink)
            constraint = sink.constraint(item, handle)
            self.connections.reconnect_item(
                item, handle, sink.port, constraint=constraint
            )
            return

        adapter = Connector(sink.item, item)
        if cinfo:
            # first disconnect but disable disconnection handle as
            # reconnection is going to happen
            try:
                connect = adapter.reconnect
            except AttributeError:
                connect = adapter.connect
            else:
                cinfo.callback.disable = True
            self.disconnect()
        else:
            # new connection
            connect = adapter.connect

        self.glue(sink)
        if not sink.port:
            print("No port found", item, sink.item)
            return

        self.connect_handle(sink)

        # adapter requires both ends to be connected.
        connect(handle, sink.port)
        item.handle(ItemConnected(item, handle, sink.item, sink.port))
Exemplo n.º 19
0
    def connect(self, sink):
        """
        Create connection at handle level and at model level.
        """
        handle = self.handle
        item = self.item
        cinfo = item.canvas.get_connection(handle)

        try:
            callback = DisconnectHandle(self.item, self.handle)
            if cinfo and cinfo.connected is sink.item:
                # reconnect only constraint - leave model intact
                log.debug("performing reconnect constraint")
                constraint = sink.port.constraint(item.canvas, item, handle,
                                                  sink.item)
                item.canvas.reconnect_item(item,
                                           handle,
                                           sink.port,
                                           constraint=constraint)
            elif cinfo:
                # first disconnect but disable disconnection handle as
                # reconnection is going to happen
                adapter = Connector(sink.item, item)
                try:
                    connect = adapter.reconnect
                except AttributeError:
                    connect = adapter.connect
                else:
                    cinfo.callback.disable = True
                self.disconnect()

                # new connection
                self.connect_handle(sink, callback=callback)

                # adapter requires both ends to be connected.
                connect(handle, sink.port)
            else:
                # new connection
                adapter = Connector(sink.item, item)
                self.connect_handle(sink, callback=callback)
                adapter.connect(handle, sink.port)
        except Exception:
            log.error("Error during connect", exc_info=True)
Exemplo n.º 20
0
def test_query(comment, commentline):
    assert Connector(comment, commentline)
Exemplo n.º 21
0
 def allow(self, sink):
     adapter = Connector(sink.item, self.item)
     return adapter and adapter.allow(self.handle, sink.port)
Exemplo n.º 22
0
def test_connection_is_allowed(diagram, block_item, proxy_port_item):
    connector = Connector(block_item, proxy_port_item)

    assert isinstance(connector, BlockProperyProxyPortConnector)
    assert connector.allow(proxy_port_item.handles()[0], block_item.ports()[0])
Exemplo n.º 23
0
        otc = self.get_connected(opposite)
        if opposite and isinstance(otc, (ForkNodeItem, DecisionNodeItem)):
            adapter = Connector(otc, line)
            adapter.combine_nodes()

    def disconnect_subject(self, handle):
        super().disconnect_subject(handle)
        line = self.line
        opposite = line.opposite(handle)
        otc = self.get_connected(opposite)
        if opposite and isinstance(otc, (ForkNodeItem, DecisionNodeItem)):
            adapter = Connector(otc, line)
            adapter.decombine_nodes()


Connector.register(ActionItem, FlowItem)(FlowConnect)
Connector.register(ActivityNodeItem, FlowItem)(FlowConnect)
Connector.register(ObjectNodeItem, FlowItem)(FlowConnect)
Connector.register(SendSignalActionItem, FlowItem)(FlowConnect)
Connector.register(AcceptEventActionItem, FlowItem)(FlowConnect)


class FlowForkDecisionNodeConnect(FlowConnect):
    """Abstract class with common behaviour for Fork/Join node and
    Decision/Merge node."""

    element: Union[ForkNodeItem, DecisionNodeItem]
    fork_node_cls: Type[UML.ControlNode]
    join_node_cls: Type[UML.ControlNode]

    def allow(self, handle, port):
Exemplo n.º 24
0
def allow(line, handle, item, port=None) -> bool:
    if port is None and len(item.ports()) > 0:
        port = item.ports()[0]

    adapter = Connector(item, line)
    return adapter.allow(handle, port)