Exemplo n.º 1
0
    def move(self, pos):
        """Move the item.

        x and y are in view coordinates.
        """
        super().move(pos)
        item = self.item
        view = self.view
        x, y = pos

        current_parent = view.canvas.get_parent(item)
        over_item = view.get_item_at_point((x, y), selected=False)

        if not over_item:
            view.dropzone_item = None
            return

        if current_parent and not over_item:
            # are we going to remove from parent?
            group = Group(current_parent, item)
            if group:
                view.dropzone_item = current_parent
                current_parent.request_update(matrix=False)

        if over_item:
            # are we going to add to parent?
            group = Group(over_item, item)
            if group and group.can_contain():
                view.dropzone_item = over_item
                over_item.request_update(matrix=False)
Exemplo n.º 2
0
    def on_motion_notify(self, event):
        """Change parent item to dropzone state if it can accept diagram item
        object to be created."""
        if self.grabbed_handle:
            return self.handle_tool.on_motion_notify(event)

        view = self.view

        try:
            parent = view.get_item_at_point((event.x, event.y))
        except KeyError:
            parent = None

        if parent:
            # create dummy adapter
            adapter = Group(parent, self._factory.item_class())
            if adapter and adapter.can_contain():
                view.dropzone_item = parent
                self._parent = parent
            else:
                view.dropzone_item = None
                self._parent = None
            parent.request_update(matrix=False)
        else:
            if view.dropzone_item:
                view.dropzone_item.request_update(matrix=False)
            view.dropzone_item = None
Exemplo n.º 3
0
    def move(self, pos):
        """
        Move the item. x and y are in view coordinates.
        """
        super(DropZoneInMotion, self).move(pos)
        item = self.item
        view = self.view
        x, y = pos

        current_parent = view.canvas.get_parent(item)
        over_item = view.get_item_at_point((x, y), selected=False)

        if not over_item:
            view.dropzone_item = None
            view.window.set_cursor(None)
            return

        if current_parent and not over_item:  # are we going to remove from parent?
            adapter = Group(current_parent, item)
            if adapter:
                view.window.set_cursor(OUT_CURSOR)
                view.dropzone_item = current_parent
                current_parent.request_update(matrix=False)

        if over_item:
            # are we going to add to parent?
            adapter = Group(over_item, item)
            if adapter and adapter.can_contain():
                view.dropzone_item = over_item
                view.window.set_cursor(IN_CURSOR)
                over_item.request_update(matrix=False)
Exemplo n.º 4
0
 def group(self, parent, item):
     """
     Group item within a parent.
     """
     self.diagram.canvas.reparent(item, parent)
     adapter = Group(parent, item)
     adapter.group()
Exemplo n.º 5
0
 def ungroup(self, parent, item):
     """
     Remove item from a parent.
     """
     adapter = Group(parent, item)
     adapter.ungroup()
     self.diagram.canvas.reparent(item, None)
Exemplo n.º 6
0
    def on_motion_notify(self, event):
        """
        Change parent item to dropzone state if it can accept diagram item
        object to be created.
        """
        view = self.view

        if view.focused_item:
            view.unselect_item(view.focused_item)
            view.focused_item = None

        try:
            parent = view.get_item_at_point((event.x, event.y))
        except KeyError:
            parent = None

        if parent:
            # create dummy adapter
            adapter = Group(parent, self._factory.item_class())
            if adapter and adapter.can_contain():
                view.dropzone_item = parent
                cursor = Gdk.Cursor.new_for_display(
                    view.get_window().get_display(), IN_CURSOR_TYPE)
                view.get_window().set_cursor(cursor)
                self._parent = parent
            else:
                view.dropzone_item = None
                view.get_window().set_cursor(None)
                self._parent = None
            parent.request_update(matrix=False)
        else:
            if view.dropzone_item:
                view.dropzone_item.request_update(matrix=False)
            view.dropzone_item = None
            view.get_window().set_cursor(None)
Exemplo n.º 7
0
    def stop_move(self, pos):
        """Motion stops: drop!"""
        super().stop_move(pos)
        item = self.item
        view = self.view
        old_parent = item.parent
        new_parent = view.selection.dropzone_item
        try:

            if new_parent is old_parent:
                if old_parent is not None:
                    old_parent.request_update(matrix=False)
                return

            if old_parent:
                item.parent = None

                adapter = Group(old_parent, item)
                if adapter:
                    adapter.ungroup()

                old_parent.request_update()

            if new_parent:
                item.parent = new_parent

                adapter = Group(new_parent, item)
                if adapter and adapter.can_contain():
                    adapter.group()

                new_parent.request_update()
        finally:
            view.selection.dropzone_item = None
Exemplo n.º 8
0
    def stop_move(self):
        """Motion stops: drop!"""
        super().stop_move()
        item = self.item
        view = self.view
        canvas = view.canvas
        old_parent = view.canvas.get_parent(item)
        new_parent = view.dropzone_item
        try:

            if new_parent is old_parent:
                if old_parent is not None:
                    old_parent.request_update(matrix=False)
                return

            if old_parent:
                canvas.reparent(item, None)

                adapter = Group(old_parent, item)
                if adapter:
                    adapter.ungroup()

                old_parent.request_update()

            if new_parent:
                canvas.reparent(item, new_parent)

                adapter = Group(new_parent, item)
                if adapter and adapter.can_contain():
                    adapter.group()

                new_parent.request_update()
        finally:
            view.dropzone_item = None
Exemplo n.º 9
0
        def item_factory(diagram, parent=None):
            if subject_class:
                element_factory = diagram.model
                subject = element_factory.create(subject_class)
            else:
                subject = None

            item = diagram.create(item_class, subject=subject)
            if config_func:
                config_func(item)

            adapter = Group(parent, item)
            if parent and adapter.can_contain():
                adapter.group()
                diagram.canvas.reparent(item, parent=parent)

            return item
Exemplo n.º 10
0
def owner_for_message(line, lifeline):
    maybe_interaction = lifeline.parent
    if line.subject.interaction:
        return
    elif isinstance(maybe_interaction, InteractionItem):
        Group(maybe_interaction, line).group()
    elif lifeline.subject and lifeline.subject.interaction:
        line.subject.interaction = lifeline.subject.interaction
Exemplo n.º 11
0
def test_group_message_item_without_subject(diagram, element_factory):
    interaction = diagram.create(InteractionItem,
                                 subject=element_factory.create(
                                     UML.Interaction))
    message = diagram.create(MessageItem)

    Group(interaction, message).group()

    assert message.subject is None
Exemplo n.º 12
0
def node_with_component(diagram, element_factory):
    node = element_factory.create(UML.Node)
    comp = element_factory.create(UML.Component)
    node_item = diagram.create(NodeItem, subject=node)
    comp_item = diagram.create(ComponentItem, subject=comp)

    Group(node_item, comp_item).group()
    diagram.canvas.reparent(comp_item, parent=node_item)

    assert diagram.canvas.get_parent(comp_item) is node_item

    return node_item, comp_item
Exemplo n.º 13
0
def node_with_component(diagram, element_factory):
    node = element_factory.create(UML.Node)
    comp = element_factory.create(UML.Component)
    node_item = diagram.create(NodeItem, subject=node)
    comp_item = diagram.create(ComponentItem, subject=comp)

    Group(node_item, comp_item).group()
    comp_item.parent = node_item

    assert comp_item.parent is node_item

    return node_item, comp_item
Exemplo n.º 14
0
def on_motion(controller, x, y, item_class):
    view: GtkView = controller.get_widget()
    model = view.model

    try:
        parent = item_at_point(view, (x, y))
    except KeyError:
        parent = None

    if parent:
        # create dummy adapter
        connections = Connections()
        adapter = Group(parent, item_class(connections))
        if adapter and adapter.can_contain():
            view.selection.dropzone_item = parent
        else:
            view.selection.dropzone_item = None
        model.request_update(parent, matrix=False)
    else:
        if view.selection.dropzone_item:
            model.request_update(view.selection.dropzone_item)
        view.selection.dropzone_item = None
Exemplo n.º 15
0
    def move(self, pos):
        """
        Move the item. x and y are in view coordinates.
        """
        super().move(pos)
        item = self.item
        view = self.view
        x, y = pos

        current_parent = view.canvas.get_parent(item)
        over_item = view.get_item_at_point((x, y), selected=False)

        if not over_item:
            view.dropzone_item = None
            view.get_window().set_cursor(None)
            return

        if current_parent and not over_item:
            # are we going to remove from parent?
            group = Group(current_parent, item)
            if group:
                cursor = Gdk.Cursor.new_for_display(
                    view.get_window().get_display(), OUT_CURSOR_TYPE
                )
                view.get_window().set_cursor(cursor)
                view.dropzone_item = current_parent
                current_parent.request_update(matrix=False)

        if over_item:
            # are we going to add to parent?
            group = Group(over_item, item)
            if group and group.can_contain():
                cursor = Gdk.Cursor.new_for_display(
                    view.get_window().get_display(), IN_CURSOR_TYPE
                )
                view.get_window().set_cursor(cursor)
                view.dropzone_item = over_item
                over_item.request_update(matrix=False)
Exemplo n.º 16
0
def test_message_is_owned_by_interaction_item_connecting_to_one_end(
        diagram, element_factory, end_name):
    """Test messages' lifetimes connection."""
    interaction = diagram.create(InteractionItem,
                                 subject=element_factory.create(
                                     UML.Interaction))
    ll = diagram.create(LifelineItem,
                        subject=element_factory.create(UML.Lifeline))
    Group(interaction, ll).group()

    msg = diagram.create(MessageItem)
    connect(msg, getattr(msg, end_name), ll)

    assert msg.subject is not None
    assert msg.subject.interaction is interaction.subject
    assert msg.parent is interaction
Exemplo n.º 17
0
    def stop_move(self):
        """
        Motion stops: drop!
        """
        super(DropZoneInMotion, self).stop_move()
        item = self.item
        view = self.view
        canvas = view.canvas
        old_parent = view.canvas.get_parent(item)
        new_parent = view.dropzone_item
        try:

            if new_parent is old_parent:
                if old_parent is not None:
                    old_parent.request_update(matrix=False)
                return

            if old_parent:
                adapter = Group(old_parent, item)
                if adapter:
                    adapter.ungroup()

                canvas.reparent(item, None)
                m = canvas.get_matrix_i2c(old_parent)
                item.matrix *= m
                old_parent.request_update()

            if new_parent:
                adapter = Group(new_parent, item)
                if adapter and adapter.can_contain():
                    adapter.group()

                canvas.reparent(item, new_parent)
                m = canvas.get_matrix_c2i(new_parent)
                item.matrix *= m
                new_parent.request_update()
        finally:
            view.dropzone_item = None
            view.get_window().set_cursor(None)
Exemplo n.º 18
0
    def _create_item(self, pos):
        """
        Create diagram item and place it within parent's boundaries.
        """
        parent = self._parent
        view = self.view
        try:
            adapter = Group(parent, self._factory.item_class())
            if parent and adapter and adapter.can_contain():
                item = super()._create_item(pos, parent=parent)
            else:
                item = super()._create_item(pos)

            adapter = Group(parent, item)
            if parent and item and adapter:
                adapter.group()

                parent.request_update(matrix=False)
        finally:
            self._parent = None
            view.dropzone_item = None
            view.get_window().set_cursor(None)
        return item
Exemplo n.º 19
0
    def _create_item(self, pos, **kw):
        """
        Create diagram item and place it within parent's boundaries.
        """
        parent = self._parent
        view = self.view
        try:
            adapter = Group(parent, self._factory.item_class())
            if parent and adapter and adapter.can_contain():
                kw["parent"] = parent

            item = super(GroupPlacementTool, self)._create_item(pos, **kw)

            adapter = Group(parent, item)
            if parent and item and adapter:
                adapter.group()

                canvas = view.canvas
                parent.request_update(matrix=False)
        finally:
            self._parent = None
            view.dropzone_item = None
            view.window.set_cursor(None)
        return item
Exemplo n.º 20
0
 def can_group(self, parent, item):
     """
     Check if an item can be grouped by parent.
     """
     adapter = Group(parent, item)
     return adapter.can_contain()
Exemplo n.º 21
0
 def ungroup(self, parent, item):
     """Remove item from a parent."""
     adapter = Group(parent, item)
     adapter.ungroup()
     item.parent = None
Exemplo n.º 22
0
 def group(self, parent, item):
     """Group item within a parent."""
     item.parent = parent
     adapter = Group(parent, item)
     adapter.group()
Exemplo n.º 23
0
        ]
        for n in nodes:
            canvas.reparent(n, None)

        sp.unlink()


class ActivityNodePartitionGroup(AbstractGroup):
    """
    Group activity nodes within activity partition.
    """
    def can_contain(self):
        return self.parent.subject and len(
            self.parent.subject.subpartition) == 0

    def group(self):
        partition = self.parent.subject
        node = self.item.subject
        partition.node = node

    def ungroup(self):
        partition = self.parent.subject
        node = self.item.subject
        partition.node.remove(node)


Group.register(PartitionItem, ActivityNodeItem)(ActivityNodePartitionGroup)
Group.register(PartitionItem, ActionItem)(ActivityNodePartitionGroup)
Group.register(PartitionItem, ObjectNodeItem)(ActivityNodePartitionGroup)
Group.register(PartitionItem, ForkNodeItem)(ActivityNodePartitionGroup)