Exemple #1
0
def test_connect(diagram, comment, commentline):
    sink = ConnectionSink(comment, comment.ports()[0])
    aspect = ConnectorAspect(commentline, commentline.handles()[0])
    aspect.connect(sink)
    canvas = diagram.canvas
    cinfo = canvas.get_connection(commentline.handles()[0])
    assert cinfo, cinfo
Exemple #2
0
def test_allow(commentline, comment):
    aspect = ConnectorAspect(commentline, commentline.handles()[0])
    assert aspect.item is commentline
    assert aspect.handle is commentline.handles()[0]

    sink = ConnectionSink(comment, comment.ports()[0])
    assert aspect.allow(sink)
Exemple #3
0
def postload_connect(item: gaphas.Item, handle: gaphas.Handle,
                     target: gaphas.Item):
    """
    Helper function: when loading a model, handles should be connected as
    part of the `postload` step. This function finds a suitable spot on the
    `target` item to connect the handle to.
    """
    connector = ConnectorAspect(item, handle)
    sink = _get_sink(item, handle, target)
    connector.connect(sink)
Exemple #4
0
    def connect(self, line, handle, item, port=None):
        """Connect line's handle to an item.

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

        sink = ConnectionSink(item, port)
        connector = ConnectorAspect(line, handle)

        connector.connect(sink)

        cinfo = canvas.get_connection(handle)
        assert cinfo.connected is item
        assert cinfo.port is port
Exemple #5
0
def test_iconnect(session, event_manager, element_factory):
    """
    Test basic glue functionality using CommentItem and CommentLine
    items.
    """
    diagram = element_factory.create(UML.Diagram)
    event_manager.handle(DiagramOpened(diagram))
    comment = diagram.create(CommentItem,
                             subject=element_factory.create(UML.Comment))

    actor = diagram.create(ActorItem,
                           subject=element_factory.create(UML.Actor))
    actor.matrix.translate(200, 200)
    diagram.canvas.update_matrix(actor)

    line = diagram.create(CommentLineItem)

    view = current_diagram_view(session)
    assert view, "View should be available here"
    comment_bb = view.get_item_bounding_box(comment)

    # select handle:
    handle = line.handles()[-1]
    tool = ConnectHandleTool(view=view)

    tool.grab_handle(line, handle)
    handle.pos = (comment_bb.x, comment_bb.y)
    item = tool.glue(line, handle, handle.pos)
    assert item is not None

    tool.connect(line, handle, handle.pos)
    cinfo = diagram.canvas.get_connection(handle)
    assert cinfo.constraint is not None
    assert cinfo.connected is actor, cinfo.connected

    ConnectorAspect(line, handle).disconnect()

    cinfo = diagram.canvas.get_connection(handle)

    assert cinfo is None
Exemple #6
0
def test_aspect_type(commentline):
    aspect = ConnectorAspect(commentline, commentline.handles()[0])
    assert isinstance(aspect, DiagramItemConnector)