How to use the gaphor.diagram.connectors.IConnect.register function in gaphor

To help you get started, we’ve selected a few gaphor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gaphor / gaphor / gaphor / diagram / actions / flowconnect.py View on Github external
otc = self.get_connected(opposite)
        if opposite and isinstance(otc, (ForkNodeItem, DecisionNodeItem)):
            adapter = IConnect(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 = IConnect(otc, line)
            adapter.decombine_nodes()


IConnect.register(ActionItem, FlowItem)(FlowConnect)
IConnect.register(ActivityNodeItem, FlowItem)(FlowConnect)
IConnect.register(ObjectNodeItem, FlowItem)(FlowConnect)
IConnect.register(SendSignalActionItem, FlowItem)(FlowConnect)
IConnect.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]
github gaphor / gaphor / gaphor / diagram / general / connectors.py View on Github external
def disconnect(self, handle):
        c1 = self.get_connected(handle)
        opposite = self.line.opposite(handle)
        c2 = self.get_connected(opposite)
        if c1 and c2:
            if (
                isinstance(c1.subject, UML.Comment)
                and c2.subject in c1.subject.annotatedElement
            ):
                del c1.subject.annotatedElement[c2.subject]
            elif c2.subject and c1.subject in c2.subject.annotatedElement:
                del c2.subject.annotatedElement[c1.subject]
        super().disconnect(handle)


@IConnect.register(CommentLineItem, LinePresentation)
class InverseCommentLineLineConnect(CommentLineLineConnect):
    """
    In case a line is disconnected that contains a comment-line,
    the comment line unlinking should happen in a correct way.
    """

    def __init__(self, line, element):
        super().__init__(element, line)
github gaphor / gaphor / gaphor / diagram / usecases / usecaseconnect.py View on Github external
"""
Use cases related connection adapters.
"""

from gaphor import UML
from gaphor.diagram.usecases.usecase import UseCaseItem
from gaphor.diagram.usecases.extend import ExtendItem
from gaphor.diagram.usecases.include import IncludeItem
from gaphor.diagram.connectors import IConnect, RelationshipConnect


@IConnect.register(UseCaseItem, IncludeItem)
class IncludeConnect(RelationshipConnect):
    """Connect use cases with an include item relationship."""

    def allow(self, handle, port):
        line = self.line
        element = self.element

        if not (element.subject and isinstance(element.subject, UML.UseCase)):
            return None

        return super().allow(handle, port)

    def reconnect(self, handle, port):
        self.reconnect_relationship(
            handle, UML.Include.addition, UML.Include.includingCase
        )
github gaphor / gaphor / gaphor / diagram / states / vertexconnect.py View on Github external
subject = element.subject

        # Check if no other items are connected
        connections = self.canvas.get_connections(connected=element)
        connected_items = [
            c
            for c in connections
            if isinstance(c.item, TransitionItem) and c.item is not line
        ]
        if handle is line.head and not any(connected_items):
            return super().allow(handle, port)
        else:
            return None


@IConnect.register(HistoryPseudostateItem, TransitionItem)
class HistoryPseudostateTransitionConnect(VertexConnect):
    """Connect history pseudostate using transition item.

    It modifies InitialPseudostateItem._connected attribute to disallow
    connection of more than one transition.
    """

    def allow(self, handle, port):
        """
        """
        return super().allow(handle, port)
github gaphor / gaphor / gaphor / diagram / states / vertexconnect.py View on Github external
line = self.line
        subject = self.element.subject

        is_final = isinstance(subject, UML.FinalState)
        if (
            isinstance(subject, UML.State)
            and not is_final
            or handle is line.tail
            and is_final
        ):
            return super().allow(handle, port)
        else:
            return None


@IConnect.register(InitialPseudostateItem, TransitionItem)
class InitialPseudostateTransitionConnect(VertexConnect):
    """Connect initial pseudostate using transition item.

    It modifies InitialPseudostateItem._connected attribute to disallow
    connection of more than one transition.
    """

    def allow(self, handle, port):
        """
        Glue to initial pseudostate with transition's head and when there are
        no transitions connected.
        """
        assert self.canvas

        line = self.line
        element = self.element
github gaphor / gaphor / gaphor / diagram / actions / flowconnect.py View on Github external
adapter = IConnect(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 = IConnect(otc, line)
            adapter.decombine_nodes()


IConnect.register(ActionItem, FlowItem)(FlowConnect)
IConnect.register(ActivityNodeItem, FlowItem)(FlowConnect)
IConnect.register(ObjectNodeItem, FlowItem)(FlowConnect)
IConnect.register(SendSignalActionItem, FlowItem)(FlowConnect)
IConnect.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):
        # No cyclic connect is possible on a Flow/Decision node:
github gaphor / gaphor / gaphor / diagram / profiles / extensionconnect.py View on Github external
from gaphor import UML
from gaphor.diagram.presentation import Classified
from gaphor.diagram.profiles.extension import ExtensionItem
from gaphor.diagram.connectors import IConnect, RelationshipConnect


@IConnect.register(Classified, ExtensionItem)
class ExtensionConnect(RelationshipConnect):
    """Connect class and stereotype items using an extension item."""

    line: ExtensionItem

    def allow(self, handle, port):
        line = self.line
        subject = self.element.subject

        if handle is line.head:
            # Element at the head should be a class
            # (implies stereotype as well)
            allow = isinstance(subject, UML.Class)
        elif handle is line.tail:
            # Element at the tail should be a stereotype
            allow = isinstance(subject, UML.Stereotype)
github gaphor / gaphor / gaphor / diagram / classes / interfaceconnect.py View on Github external
Interface item related connections.

The connectors implemented in this module check if connection is possible
to folded interface, see `gaphor.diagram.classes.interface` documentation
for details.
"""


from gaphor.diagram.classes.classconnect import DependencyConnect, ImplementationConnect
from gaphor.diagram.classes.dependency import DependencyItem
from gaphor.diagram.classes.implementation import ImplementationItem
from gaphor.diagram.classes.interface import Folded, InterfaceItem
from gaphor.diagram.connectors import IConnect


@IConnect.register(InterfaceItem, ImplementationItem)
class ImplementationInterfaceConnect(ImplementationConnect):
    """Connect interface item and a behaviored classifier using an
    implementation.
    """

    def connect(self, handle, port):
        """
        Implementation item can be changed to draw in solid mode, when
        connected to folded interface.
        """
        super().connect(handle, port)
        if handle is self.line.head:
            self.line.request_update()

    def disconnect(self, handle):
        """
github gaphor / gaphor / gaphor / diagram / actions / flowconnect.py View on Github external
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 = IConnect(otc, line)
            adapter.decombine_nodes()


IConnect.register(ActionItem, FlowItem)(FlowConnect)
IConnect.register(ActivityNodeItem, FlowItem)(FlowConnect)
IConnect.register(ObjectNodeItem, FlowItem)(FlowConnect)
IConnect.register(SendSignalActionItem, FlowItem)(FlowConnect)
IConnect.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):
        # No cyclic connect is possible on a Flow/Decision node:
        head, tail = self.line.head, self.line.tail
        subject = self.element.subject