Пример #1
0
 def _set_object_value(self, row, col, value):
     attr = row[-1]
     if col == 0:
         parse(attr, value)
         row[0] = format(attr)
     elif col == 1:
         attr.isStatic = not attr.isStatic
         row[1] = attr.isStatic
     elif col == 2:
         # Value in attribute object changed:
         row[0] = format(attr)
         row[1] = attr.isStatic
Пример #2
0
def format_operation(
    el,
    pattern=None,
    visibility=False,
    type=False,
    multiplicity=False,
    default=False,
    tags=False,
    direction=False,
):
    """Create a OCL representation of the operation, Returns the operation as a
    string."""
    name = el.name
    if not name:
        return ""
    if no_render_pat.match(name):
        return name

    # Render all fields if they all are set to False
    if not (visibility or type or multiplicity or default or tags
            or direction):
        visibility = type = multiplicity = default = tags = direction = True

    s = []
    if visibility:
        s.append(f"{vis_map[el.visibility]} ")

    s.append(name)
    s.append("(")

    for p in el.formalParameter:
        s.append(
            format(
                p,
                direction=direction,
                type=type,
                multiplicity=multiplicity,
                default=default,
            ))
        if p is not el.formalParameter[-1]:
            s.append(", ")

    s.append(")")

    rr = el.returnResult and el.returnResult[0]
    if rr:
        s.append(
            format(rr, type=type, multiplicity=multiplicity, default=default))
    return "".join(s)
Пример #3
0
 def _set_object_value(self, row, col, value):
     operation = row[-1]
     if col == 0:
         parse(operation, value)
         row[0] = format(operation)
     elif col == 1:
         operation.isAbstract = not operation.isAbstract
         row[1] = operation.isAbstract
     elif col == 2:
         operation.isStatic = not operation.isStatic
         row[2] = operation.isStatic
     elif col == 3:
         row[0] = format(operation)
         row[1] = operation.isAbstract
         row[2] = operation.isStatic
Пример #4
0
 def _get_rows(self):
     for operation in self._item.subject.ownedOperation:
         yield [
             format(operation),
             operation.isAbstract,
             operation.isStatic,
             operation,
         ]
Пример #5
0
        def sort_func(model, iter_a, iter_b, userdata):
            va = model.get_value(iter_a, 0)
            vb = model.get_value(iter_b, 0)

            # Put Relationships pseudo-node at top
            if va is RELATIONSHIPS:
                return -1
            if vb is RELATIONSHIPS:
                return 1

            a = (format(va) or "").lower()
            b = (format(vb) or "").lower()
            if a == b:
                return 0
            if a > b:
                return 1
            return -1
Пример #6
0
 def handler(event):
     operation = event.element
     for row in self.model:
         if row[-1] is operation:
             row[:] = [
                 format(operation),
                 operation.isAbstract,
                 operation.isStatic,
                 operation,
             ]
Пример #7
0
def format_property(
    el,
    visibility=False,
    is_derived=False,
    type=False,
    multiplicity=False,
    default=False,
    tags=False,
):
    """Create a OCL representation of the attribute, Returns the attribute as a
    string. If one or more of the parameters (visibility, is_derived, type,
    multiplicity, default and/or tags) is set, only that field is rendered.
    Note that the name of the attribute is always rendered, so a parseable
    string is returned.

    Note that, when some of those parameters are set, parsing the string
    will not give you the same result.
    """
    name = el.name

    if name and no_render_pat.match(name):
        return name

    # Render all fields if they all are set to False
    if not (visibility or is_derived or type or multiplicity or default):
        visibility = is_derived = type = multiplicity = default = True

    s = []

    if name and visibility:
        s.append(vis_map[el.visibility])
        s.append(" ")

    if name and is_derived and el.isDerived:
        s.append("/")

    if name:
        s.append(name)

    if type and el.typeValue:
        s.append(f": {el.typeValue}")
    elif type and el.type and el.type.name:
        s.append(f": {el.type.name}")

    if multiplicity:
        s.append(format_multiplicity(el))

    if default and el.defaultValue:
        s.append(f" = {el.defaultValue}")

    if tags:
        slots = [format(slot) for slot in el.appliedStereotype[:].slot if slot]
        if slots:
            s.append(" { %s }" % ", ".join(slots))
    return "".join(s)
Пример #8
0
def test_interface_with_attributes_and_operation(diagram, element_factory):
    iface = element_factory.create(UML.Interface)

    attr = element_factory.create(UML.Property)
    parse(attr, "- attr: str")
    iface.ownedAttribute = attr

    oper = element_factory.create(UML.Operation)
    parse(oper, "- oper(inout param: str): str")
    iface.ownedOperation = oper

    iface_item = diagram.create(InterfaceItem, subject=iface)

    new_items = copy_clear_and_paste({iface_item}, diagram, element_factory)
    new_iface_item = new_items.pop()

    assert isinstance(new_iface_item, InterfaceItem)
    assert format(new_iface_item.subject.ownedAttribute[0]) == "- attr: str"
    assert (format(new_iface_item.subject.ownedOperation[0]) ==
            "- oper(inout param: str): str")
Пример #9
0
def association_item_inline_editor(item, view, pos=None) -> bool:
    """Text edit support for Named items."""
    @transactional
    def update_text(text):
        item.subject.name = text
        return True

    @transactional
    def update_end_text(text):
        assert end_item
        parse(end_item.subject, text)
        return True

    subject = item.subject
    if not subject:
        return False

    end_item = None
    if pos and distance_point_point_fast(item.handles()[0].pos, pos) < 50:
        end_item = item.head_end
    elif pos and distance_point_point_fast(item.handles()[-1].pos, pos) < 50:
        end_item = item.tail_end

    if end_item:
        text = (format(
            end_item.subject,
            visibility=True,
            is_derived=True,
            type=True,
            multiplicity=True,
            default=True,
        ) or "")

        def escape():
            assert end_item
            parse(end_item.subject, text)

        entry = popup_entry(text, update_end_text)
        bb = end_item.name_bounds
        x, y = view.get_matrix_i2v(item).transform_point(bb.x, bb.y)
        box = Rectangle(x, y, 10, 10)
    else:
        text = item.subject.name or ""

        def escape():
            item.subject.name = text

        entry = popup_entry(text, update_text)
        box = editable_text_box(view, view.hovered_item)

    show_popover(entry, view, box, escape)
    return True
Пример #10
0
 def update_end_name(self, builder, end_name, subject):
     name = builder.get_object(f"{end_name}-name")
     new_name = (format(
         subject,
         visibility=True,
         is_derived=True,
         multiplicity=True,
     ) or "")
     if not (name.is_focus() or self.semaphore):
         self.semaphore += 1
         name.set_text(new_name)
         self.semaphore -= 1
     return name
Пример #11
0
def test_class_with_attributes(diagram, element_factory):
    cls = element_factory.create(UML.Class)
    attr = element_factory.create(UML.Property)
    parse(attr, "- attr: str")
    cls.ownedAttribute = attr

    cls_item = diagram.create(ClassItem, subject=cls)

    new_items = copy_clear_and_paste({cls_item}, diagram, element_factory)
    new_cls_item = new_items.pop()

    assert isinstance(new_cls_item, ClassItem)
    assert format(new_cls_item.subject.ownedAttribute[0]) == "- attr: str"
Пример #12
0
def test_class_with_operation(diagram, element_factory):
    cls = element_factory.create(UML.Class)
    oper = element_factory.create(UML.Operation)
    parse(oper, "- oper(inout param: str): str")
    cls.ownedOperation = oper

    cls_item = diagram.create(ClassItem, subject=cls)

    new_items = copy_clear_and_paste({cls_item}, diagram, element_factory)
    new_cls_item = new_items.pop()

    assert isinstance(new_cls_item, ClassItem)
    assert (format(new_cls_item.subject.ownedOperation[0]) ==
            "- oper(inout param: str): str")
Пример #13
0
def format_association_end(el) -> Tuple[str, str]:
    """Format association end."""
    name = ""
    n = []
    if el.name:
        n.append(vis_map[el.visibility])
        n.append(" ")
        if el.isDerived:
            n.append("/")
        n.append(el.name)

        name = "".join(n)

    m = [format_multiplicity(el, bare=True)]
    slots = [format(slot) for slot in el.appliedStereotype[:].slot if slot]
    if slots:
        m.append(" { %s }" % ",\n".join(slots))
    mult = "".join(m)

    return name, mult
Пример #14
0
        def search_func(model, column, key, rowiter):
            # Note that this function returns `False` for a match!
            assert column == 0
            row = model[rowiter]
            matched = False

            # Search in child rows.  If any element in the underlying
            # tree matches, it will expand.
            for inner in row.iterchildren():
                if not search_func(model, column, key, inner.iter):
                    view.expand_to_path(row.path)
                    matched = True

            element = list(row)[column]
            s = format(element)
            if s and key.lower() in s.lower():
                matched = True
            elif not matched:
                view.collapse_row(row.path)

            return not matched  # False means match found!
Пример #15
0
    def _set_text(self, column, cell, model, iter, data):
        """Set font and of model elements in tree view."""
        element = model.get_value(iter, 0)

        cell.set_property(
            "weight",
            Pango.Weight.BOLD
            if isinstance(element, Diagram) else Pango.Weight.NORMAL,
        )

        cell.set_property(
            "style",
            Pango.Style.ITALIC
            if isinstance(element, (UML.Classifier, UML.BehavioralFeature))
            and element.isAbstract else Pango.Style.NORMAL,
        )

        if element is RELATIONSHIPS:
            text = gettext("<Relationships>")
        else:
            text = format(element) or "<None>"
        cell.set_property("text", text)
Пример #16
0
 def lazy_format(slot):
     return lambda: format(slot)
Пример #17
0
 def lazy_format(attribute):
     return lambda: format(attribute)
Пример #18
0
 def lazy_format(operation):
     return lambda: format(operation,
                           visibility=True,
                           type=True,
                           multiplicity=True,
                           default=True)
Пример #19
0
 def _get_rows(self):
     for attr in self._item.subject.ownedAttribute:
         if not attr.association:
             yield [format(attr), attr.isStatic, attr]
Пример #20
0
 def handler(event):
     attribute = event.element
     for row in self.model:
         if row[-1] is attribute:
             row[:] = [format(attribute), attribute.isStatic, attribute]