예제 #1
0
    def __init__(self, connections, id=None, model=None):
        super().__init__(id=id, model=model)
        self._matrix = Matrix()
        self._matrix_i2c = Matrix()
        self._connections = connections

        h1, h2 = Handle(), Handle()
        self._handles = [h1, h2]
        self._ports = [LinePort(h1.pos, h2.pos)]

        self._combined = None

        self.shape = IconBox(
            Box(style={"min-width": 0, "min-height": 45}, draw=self.draw_fork_node),
            Text(
                text=lambda: stereotypes_str(self.subject),
            ),
            EditableText(text=lambda: self.subject and self.subject.name or ""),
            Text(
                text=lambda: isinstance(self.subject, UML.JoinNode)
                and self.subject.joinSpec not in (None, DEFAULT_JOIN_SPEC)
                and f"{{ joinSpec = {self.subject.joinSpec} }}"
                or "",
            ),
        )

        self.watch("subject[NamedElement].name")
        self.watch("subject.appliedStereotype.classifier.name")
        self.watch("subject[JoinNode].joinSpec")

        connections.add_constraint(self, constraint(vertical=(h1.pos, h2.pos)))
        connections.add_constraint(self, constraint(above=(h1.pos, h2.pos), delta=30))
예제 #2
0
    def __init__(self, diagram, id=None):
        super().__init__(diagram, id=id)

        h1, h2 = Handle(), Handle()
        self._handles = [h1, h2]
        self._ports = [LinePort(h1.pos, h2.pos)]
        self.watch_handle(h1)
        self.watch_handle(h2)

        self.shape = IconBox(
            Box(draw=self.draw_fork_node),
            Text(
                text=lambda: stereotypes_str(self.subject),
            ),
            EditableText(text=lambda: self.subject and self.subject.name or ""),
            Text(
                text=lambda: isinstance(self.subject, UML.JoinNode)
                and self.subject.joinSpec not in (None, DEFAULT_JOIN_SPEC)
                and f"{{ joinSpec = {self.subject.joinSpec} }}"
                or "",
            ),
        )

        self.watch("subject[NamedElement].name")
        self.watch("subject.appliedStereotype.classifier.name")
        self.watch("subject[JoinNode].joinSpec")

        diagram.connections.add_constraint(self, constraint(vertical=(h1.pos, h2.pos)))
        diagram.connections.add_constraint(
            self, constraint(above=(h1.pos, h2.pos), delta=30)
        )
예제 #3
0
def test_above_constraint(pos1, pos2):
    """Test "less than" constraint (vertical) creation."""
    c = constraint(above=(pos1, pos2))

    assert isinstance(c, LessThanConstraint)
    assert 2 == c.smaller
    assert 4 == c.bigger
예제 #4
0
def test_left_of_constraint(pos1, pos2):
    """Test "less than" constraint (horizontal) creation."""
    c = constraint(left_of=(pos1, pos2))

    assert isinstance(c, LessThanConstraint)
    assert 1 == c.smaller
    assert 3 == c.bigger
예제 #5
0
def test_horizontal_constraint(pos1, pos2):
    """Test horizontal constraint creation."""
    c = constraint(horizontal=(pos1, pos2))

    assert isinstance(c, EqualsConstraint)
    # Expect constraint on y-axis
    assert 2 == c.a
    assert 4 == c.b
예제 #6
0
def test_line_constraint(pos1):
    """Test line creation constraint."""
    line = (Position(3, 4), Position(5, 6))
    c = constraint(line=(pos1, line))

    assert isinstance(c, LineConstraint)
    assert Position(1, 2) == c._point
    assert (Position(3, 4), Position(5, 6)) == c._line
예제 #7
0
def test_vertical_constraint(pos1, pos2):
    """Test vertical constraint creation."""
    c = constraint(vertical=(pos1, pos2))

    assert isinstance(c, EqualsConstraint)
    # Expect constraint on x-axis
    assert 1 == c.a
    assert 3 == c.b
예제 #8
0
    def __init__(self, diagram, id=None):
        super().__init__(diagram, id=id)
        self._connections = diagram.connections

        self.bar_width = 12

        ht, hb = Handle(), Handle()
        ht.connectable = True

        self._handles = [ht, hb]
        self.watch_handle(ht)
        self.watch_handle(hb)

        self._connections.add_constraint(self, constraint(vertical=(ht.pos, hb.pos)))

        r = self.bar_width / 2
        nw = Position(-r, 0, strength=WEAK)
        ne = Position(r, 0, strength=WEAK)
        se = Position(r, 0, strength=WEAK)
        sw = Position(-r, 0, strength=WEAK)

        for c in (
            constraint(horizontal=(nw, ht.pos)),
            constraint(horizontal=(ne, ht.pos)),
            constraint(horizontal=(sw, hb.pos)),
            constraint(horizontal=(se, hb.pos)),
            constraint(vertical=(nw, ht.pos), delta=-r),
            constraint(vertical=(ne, ht.pos), delta=r),
            constraint(vertical=(sw, hb.pos), delta=-r),
            constraint(vertical=(se, hb.pos), delta=r),
        ):
            self._connections.add_constraint(self, c)

        self._ports = [LinePort(nw, sw), LinePort(ne, se)]

        self.shape = Box(
            style={"background-color": (1.0, 1.0, 1.0, 1.0)}, draw=draw_border
        )
예제 #9
0
    def __init__(self,
                 connections: Connections,
                 width: float = 10,
                 height: float = 10,
                 **kwargs: object) -> None:
        super().__init__(**kwargs)
        self._handles = [h(strength=VERY_STRONG) for h in [Handle] * 4]

        handles = self._handles
        h_nw = handles[NW]
        h_ne = handles[NE]
        h_sw = handles[SW]
        h_se = handles[SE]

        # edge of element define default element ports
        self._ports = [
            LinePort(h_nw.pos, h_ne.pos),
            LinePort(h_ne.pos, h_se.pos),
            LinePort(h_se.pos, h_sw.pos),
            LinePort(h_sw.pos, h_nw.pos),
        ]

        # initialize min_x variables
        self.min_width, self.min_height = 10, 10

        add = connections.add_constraint
        add(self, constraint(horizontal=(h_nw.pos, h_ne.pos)))
        add(self, constraint(horizontal=(h_sw.pos, h_se.pos)))
        add(self, constraint(vertical=(h_nw.pos, h_sw.pos)))
        add(self, constraint(vertical=(h_ne.pos, h_se.pos)))

        # create minimal size constraints
        add(self, constraint(left_of=(h_nw.pos, h_se.pos),
                             delta=self.min_width))
        add(self, constraint(above=(h_nw.pos, h_se.pos),
                             delta=self.min_height))

        self.width = width
        self.height = height

        # Trigger solver to honour width/height by SE handle pos
        self._handles[SE].pos.x.dirty()
        self._handles[SE].pos.y.dirty()