<commit_before>"""
Sequence and communication diagram messages.

Messages are implemented according to UML 2.1.1 specification.

Implementation Issues
=====================

Reply Messages
--------------
Different sources show that reply message has filled arrow, including
UML 2.0. UML 2.1.1 specification says that reply message should be drawn
with an open arrow.

We draw reply message with a filled arrow.

Asynchronous Message
--------------------
It is not clear how to draw asynchronous messages. 
"""

from gaphas.util import path_ellipse

from gaphor import UML
from gaphor.diagram.diagramline import NamedLine


class MessageItem(NamedLine):
    def _draw_circle(self, cr):
        """
        Draw circle for lost/found messages.
        """
        r = 8
        # method is called by draw_head or by draw_tail methods,
        # so draw in (0, 0))
        path_ellipse(cr, 0, 0, r, r)
        cr.fill_preserve()


    def draw_head(self, context):
        super(MessageItem, self).draw_head(context)
        cr = context.cairo

        subject = self.subject
        if subject and subject.messageKind == 'found':
            self._draw_circle(cr)


    def draw_tail(self, context):
        super(MessageItem, self).draw_tail(context)

        cr = context.cairo

        subject = self.subject
        if subject and subject.messageKind == 'lost':
            self._draw_circle(cr)

        # we need always some kind of arrow...
        cr.move_to(15, -6)
        cr.line_to(0, 0)
        cr.line_to(15, 6)

        # ... which should be filled arrow in some cases
        # no subject - draw like synchronous call
        if not subject or subject.messageSort in ('synchCall', 'reply'):
            cr.close_path()
            cr.fill_preserve()

        cr.stroke()

<commit_msg>- draw reply messages with open arrows (see UML 2.0 and 2.1.1 examples)<commit_after>"""
Sequence and communication diagram messages.

Messages are implemented according to UML 2.1.1 specification.

Implementation Issues
=====================

Reply Messages
--------------
Different sources show that reply message has filled arrow, including
UML 2.0.

UML 2.1.1 specification says that reply message should be drawn with an
open arrow. This is visible on examples in UML 2.0 and UML 2.1.1
specifications.

Asynchronous Message
--------------------
It is not clear how to draw asynchronous messages. 
"""

from gaphas.util import path_ellipse

from gaphor import UML
from gaphor.diagram.diagramline import NamedLine


class MessageItem(NamedLine):
    def _draw_circle(self, cr):
        """
        Draw circle for lost/found messages.
        """
        r = 8
        # method is called by draw_head or by draw_tail methods,
        # so draw in (0, 0))
        path_ellipse(cr, 0, 0, r, r)
        cr.fill_preserve()


    def draw_head(self, context):
        super(MessageItem, self).draw_head(context)
        cr = context.cairo

        subject = self.subject
        if subject and subject.messageKind == 'found':
            self._draw_circle(cr)


    def draw_tail(self, context):
        super(MessageItem, self).draw_tail(context)

        cr = context.cairo

        subject = self.subject
        if subject and subject.messageKind == 'lost':
            self._draw_circle(cr)

        # we need always some kind of arrow...
        cr.move_to(15, -6)
        cr.line_to(0, 0)
        cr.line_to(15, 6)

        # ... which should be filled arrow in some cases
        # no subject - draw like synchronous call
        if not subject or subject.messageSort in ('synchCall'):
            cr.close_path()
            cr.fill_preserve()

        cr.stroke()


{'fraction_non_alphanumeric': 0.10950694633614819, 'fraction_numerical': 0.014165077635521656, 'mean_word_length': 2.305130513051305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '740550', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1013, 'n_words': 365}