Example #1
0
File: cr.py Project: wrobell/piuml
    def v_element(self, node):
        """
        Calculate minimal size of an element.

        :Parameters:
         node
            Node, which size shall be calculated.
        """
        if node.cls == "actor":
            node.style.size = Size(40, 60)
            return

        cr = self.cr
        style = node.style
        pad = style.padding
        sizes = []

        # calculate name size, but include icon size if necessary
        name = _name(node)
        nw, nh = text_size(cr, name)

        # include icon size
        ics = style.icon_size
        if ics != (0, 0):
            nw += ics.width + pad.right
            nh = max(nh, ics.height)
        style.compartment[0] = nh
        sizes.append(Size(nw, nh))

        compartments = []
        attrs = _features(node, "attributes")
        opers = _features(node, "operations")
        if attrs:
            w, h = text_size(cr, attrs)
            sizes.append(Size(w, h))
            style.compartment.append(h)
        if opers:
            w, h = text_size(cr, opers)
            sizes.append(Size(w, h))
            style.compartment.append(h)

        for f in node.data["stattrs"]:
            title = "<small>%s</small>\n" % st_fmt([f.name])
            attrs = title + "\n".join(a.name for a in f)
            w, h = text_size(cr, attrs)
            sizes.append(Size(w, h))
            style.compartment.append(h)

        k = len(style.compartment)
        if _is_packaging(node):
            k += 1

        width = max(w for w, h in sizes) + pad.left + pad.right
        height = sum(h for w, h in sizes) + (pad.top + pad.bottom) * k

        style.min_size.width = max(width, style.min_size.width)
        style.min_size.height = max(height, style.min_size.height)
Example #2
0
File: cr.py Project: wrobell/piuml
    def _set_edge_len(self, edge, length=0):
        """
        Calculate and set minimal length of an edge.

        :Parameters:
         edge
            Edge, which length shall be calculated.
         length
            Additional length to be added to calculated length.
        """
        cr = self.cr
        pad = edge.style.padding.left
        lens = [text_size(cr, edge.name)[0], length]
        if edge.stereotypes:
            lens.append(text_size(cr, st_fmt(edge.stereotypes))[0])
        edge.style.min_length = max(75, sum(lens) + len(lens) * pad)
Example #3
0
File: cr.py Project: wrobell/piuml
def _name(node, bold=True, underline=False, fmt="{}", skip_keyword=False):
    texts = []
    if node.stereotypes:
        k = 0
        if skip_keyword and node.stereotypes[0] in KEYWORDS:
            k = 1
        if k == 0 or len(node.stereotypes) > 2:
            texts.append('<span size="small">{}</span>'.format(st_fmt(node.stereotypes[k:])))
    name = node.name.replace("\\n", "\n")
    if name:
        name = fmt.format(name)
        if bold:
            name = "<b>{}</b>".format(name)
        if underline:
            name = "<u>{}</u>".format(name)
        texts.append(name)
    return "\n".join(texts)
Example #4
0
File: cr.py Project: wrobell/piuml
    def v_element(self, node):
        if node.parent.cls == "align":
            return
        style = node.style
        pos = x, y = style.pos
        width, height = size = style.size
        pad = style.padding
        iw, ih = style.icon_size

        align = (0, 0)
        outside = False
        underline = False
        lalign = pango.Alignment.CENTER
        bold = True
        xskip = 0
        yskip = 0

        cr = self.cr
        cr.save()

        if _is_packaging(node):
            align = (0, -1)

        if node.cls in ("node", "device"):
            draw_box3d(cr, pos, size)
        elif node.cls in ("package", "profile"):
            draw_tabbed_box(cr, pos, size)
            yskip = 20
        elif node.cls == "usecase":
            align = (0, 0)

            r1 = size.width / 2.0
            r2 = size.height / 2.0
            x0 = pos.x + r1
            y0 = pos.y + r2
            draw_ellipse(cr, (x0, y0), r1, r2)
        elif node.cls == "actor":
            align = (0, 1)
            outside = True
            draw_human(cr, pos, size)
        elif node.cls == "comment":
            draw_note(cr, pos, size)
            lalign = pango.Alignment.LEFT
            bold = False
        elif node.cls in ("instance", "artifact"):
            underline = True
            cr.rectangle(x, y, width, height)
            cr.stroke()
        else:
            cr.rectangle(x, y, width, height)
            cr.stroke()

        # draw icons
        if node.cls in ("artifact", "component"):
            x0 = x + width - iw - pad.top
            y0 = y + pad.top
            if node.cls == "artifact":
                draw_artifact(cr, (x0, y0), (iw, ih))
            else:
                draw_component(cr, (x0, y0), (iw, ih))
            xskip = -(iw + pad.top) / 2.0

        name = _name(node, bold, underline)

        # calculate height of name from compartment data
        tskip = _head_size(style)
        log.debug("element {} allocated head height {}".format(name, tskip))

        draw_text(cr, (width, tskip), style, name, lalign=lalign, pos=(xskip, yskip), align=align, outside=outside)

        nc = 1
        attrs = _features(node, "attributes")
        if attrs:
            self._compartment(node, attrs, tskip)
            tskip += style.compartment[nc] + pad.top + pad.bottom
            nc += 1

        opers = _features(node, "operations")
        if opers:
            self._compartment(node, opers, tskip)
            tskip += style.compartment[nc] + pad.top + pad.bottom
            nc += 1

        for f in node.data["stattrs"]:
            title = st_fmt([f.name]) + "\n"
            attrs = "\n".join(a.name for a in f)
            self._compartment(node, attrs, tskip, title)
            tskip += style.compartment[nc] + pad.top + pad.bottom
            nc += 1

        cr.restore()
Example #5
0
 def test_keywords(self):
     """
     Test stereotypes rendering with keywords
     """
     self.assertEquals("\xabinterface\xbb \xabt1, t2, t3\xbb", st_fmt(["t1", "interface", "t2", "t3"]))
Example #6
0
 def test_multiple(self):
     """
     Test multiple stereotype rendering
     """
     self.assertEquals("\xabt1, t2, t3\xbb", st_fmt(["t1", "t2", "t3"]))
Example #7
0
 def test_single(self):
     """
     Test single stereotype rendering
     """
     self.assertEquals("\xabt1\xbb", st_fmt(["t1"]))