diff --git a/capellambse/aird/_edge_factories.py b/capellambse/aird/_edge_factories.py index fc5b90fa..36f5dc81 100644 --- a/capellambse/aird/_edge_factories.py +++ b/capellambse/aird/_edge_factories.py @@ -62,13 +62,14 @@ def generic_factory(seb: C.SemanticElementBuilder) -> diagram.Edge: edge.styleoverrides = _styling.apply_style_overrides( seb.target_diagram.styleclass, f"Edge.{seb.styleclass}", ostyle ) # type: ignore[assignment] - edge.labels.extend(_construct_labels(edge, seb)) if isinstance(targetport, diagram.Box): snaptarget(edge, -1, -2, targetport, not edge.hidden, routingstyle) if isinstance(sourceport, diagram.Box): snaptarget(edge, 0, 1, sourceport, not edge.hidden, routingstyle) + edge.labels.extend(_construct_labels(edge, seb)) + sourceport.add_context(seb.data_element.attrib["element"]) if targetport is not None: targetport.add_context(seb.data_element.attrib["element"]) @@ -310,9 +311,18 @@ def snap_oblique( target: diagram.DiagramElement, ) -> None: """Snap ``points``' end to ``target`` in a straight line.""" - points[i] = target.vector_snap( - points[i], source=points[next_i], style=diagram.RoutingStyle.OBLIQUE + source = points[next_i] + new_point = target.vector_snap( + points[i], style=diagram.RoutingStyle.OBLIQUE, source=source ) + delta = (points[i] - source).angleto(new_point - source) + if abs(delta) >= 1: + new_point = target.vector_snap( + source, + style=diagram.RoutingStyle.OBLIQUE, + source=points[next_i - i + next_i], + ) + points[i] = new_point def snap_manhattan( diff --git a/capellambse/diagram/_diagram.py b/capellambse/diagram/_diagram.py index c0f38307..8f516068 100644 --- a/capellambse/diagram/_diagram.py +++ b/capellambse/diagram/_diagram.py @@ -272,7 +272,7 @@ def vector_snap( source = diagram.Vector2D(*source) if style is RoutingStyle.OBLIQUE: - return self.__vector_snap_oblique(source) + return self.__vector_snap_oblique(point) if style is RoutingStyle.MANHATTAN: return self.__vector_snap_manhattan(point, point - source) if style is RoutingStyle.TREE: @@ -282,6 +282,9 @@ def vector_snap( def __vector_snap_oblique( self, source: diagram.Vector2D ) -> diagram.Vector2D: + if source == self.center: + return source + angle = self.size.angleto(source - self.center) alpha = 2 * self.size.angleto((1, 0)) assert alpha >= 0 diff --git a/capellambse/svg/drawing.py b/capellambse/svg/drawing.py index 47d58d3c..c2cc499e 100644 --- a/capellambse/svg/drawing.py +++ b/capellambse/svg/drawing.py @@ -287,6 +287,8 @@ def _draw_feature_text( def _draw_label(self, builder: LabelBuilder) -> LinesData | None: """Draw label text on given object and return the label's group.""" + if not builder.labels: + return None builder.icon &= diagram.has_icon(builder.class_ or "") text = self._make_text(builder) lines = None