Make setting orthogonal property not error

Use latest gaphas.
This commit is contained in:
Arjan Molenaar 2023-03-28 21:49:35 +02:00
parent 50d18c6612
commit d4e051f0c7
No known key found for this signature in database
GPG Key ID: BF977B918996CB13
4 changed files with 16 additions and 33 deletions

View File

@ -4,7 +4,6 @@ import pytest
from gaphor import UML
from gaphor.diagram.tests.fixtures import connect, get_connected
from gaphor.tests.raises import raises_exception_group
from gaphor.UML.classes.association import (
AssociationItem,
draw_default_head,
@ -91,24 +90,6 @@ def test_association_end_updates(create, diagram):
assert a.head_end._name == "+ blah", a.head_end.get_name()
def test_association_orthogonal(items, create):
c1 = create(ClassItem, UML.Class)
c2 = create(ClassItem, UML.Class)
a = create(AssociationItem)
connect(a, a.head, c1)
c = get_connected(a, a.head)
assert c is c1
a.matrix.translate(100, 100)
connect(a, a.tail, c2)
c = get_connected(a, a.tail)
assert c is c2
with raises_exception_group(ValueError):
a.orthogonal = True
def test_association_end_owner_handles(items):
assert items.assoc.head_end.owner_handle is items.assoc.head
assert items.assoc.tail_end.owner_handle is items.assoc.tail

View File

@ -12,7 +12,7 @@ from gaphas.geometry import Rectangle, distance_rectangle_point
from gaphas.solver.constraint import BaseConstraint
from gaphor.core.modeling.diagram import Diagram
from gaphor.core.modeling.event import RevertibleEvent
from gaphor.core.modeling.event import RevertibleEvent, AttributeUpdated
from gaphor.core.modeling.presentation import Presentation, S, literal_eval
from gaphor.core.modeling.properties import attribute
from gaphor.core.styling import Style, merge_styles
@ -214,9 +214,7 @@ class LinePresentation(gaphas.Line, HandlePositionUpdate, Presentation[S]):
self._shape_head_rect = None
self._shape_middle_rect = None
self._shape_tail_rect = None
self.watch("orthogonal", self._on_orthogonal).watch(
"horizontal", self._on_horizontal
)
self.watch_handle(self.head)
self.watch_handle(self.tail)
@ -249,10 +247,12 @@ class LinePresentation(gaphas.Line, HandlePositionUpdate, Presentation[S]):
def insert_handle(self, index: int, handle: Handle) -> None:
super().insert_handle(index, handle)
self.watch_handle(handle)
self.update_orthogonal_constraints()
def remove_handle(self, handle: Handle) -> None:
self.remove_watch_handle(handle)
super().remove_handle(handle)
self.update_orthogonal_constraints()
def update_shape_bounds(self, context):
def shape_bounds(shape, align):
@ -338,9 +338,6 @@ class LinePresentation(gaphas.Line, HandlePositionUpdate, Presentation[S]):
def postload(self):
super().postload()
if self.orthogonal:
self._on_orthogonal(None)
if hasattr(self, "_load_head_connection"):
postload_connect(self, self.head, self._load_head_connection)
assert self._connections.get_connection(self.head)
@ -351,13 +348,15 @@ class LinePresentation(gaphas.Line, HandlePositionUpdate, Presentation[S]):
assert self._connections.get_connection(self.tail)
del self._load_tail_connection
def _on_orthogonal(self, _event):
if self.orthogonal and len(self.handles()) < 3:
raise ValueError("Can't set orthogonal line with less than 3 handles")
self.update_orthogonal_constraints(self.orthogonal)
self.update_orthogonal_constraints()
def _on_horizontal(self, _event):
self.update_orthogonal_constraints(self.orthogonal)
def handle(self, event):
if isinstance(event, AttributeUpdated) and event.property in (
LinePresentation.horizontal,
LinePresentation.orthogonal,
):
self.update_orthogonal_constraints()
super().handle(event)
def draw_line_end(context, end_handle, second_handle, draw):

View File

@ -94,7 +94,7 @@ def test_line_saving(element_factory, diagram):
p.save(save_func)
assert properties["matrix"] == (1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
assert "orthogonal" not in properties
assert properties["orthogonal"] is False
assert properties["horizontal"] is False
assert properties["points"] == [(0.0, 0.0), (10.0, 10.0)]
assert properties["subject"] is subject

View File

@ -32,6 +32,9 @@
<horizontal>
<val>0</val>
</horizontal>
<orthogonal>
<val>0</val>
</orthogonal>
<matrix>
<val>(1.0, 0.0, 0.0, 1.0, 336.0, 113.0)</val>
</matrix>