From c4f09a0a3e9084cc8d456200856ddb8a5fc84854 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sun, 6 Oct 2024 22:27:49 +0200 Subject: [PATCH] added _ret for return sequences --- src/diagram.typ | 29 ++++++++++++++++++++++++++++- src/lib.typ | 2 +- src/sequence.typ | 7 +++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/diagram.typ b/src/diagram.typ index ba03faa..7644d49 100644 --- a/src/diagram.typ +++ b/src/diagram.typ @@ -1,6 +1,7 @@ #import "utils.typ": get-group-span, fit-canvas #import "renderer.typ": render #import "participant.typ" as participant: _par, PAR-SPECIALS +#import "sequence.typ": _seq #let _gap(size: 20) = { return (( @@ -38,7 +39,9 @@ let elmts = elements let i = 0 - // Flatten groups + let activation-history = () + + // Flatten groups + convert returns while i < elmts.len() { let elmt = elmts.at(i) if elmt.type == "grp" { @@ -62,6 +65,30 @@ ),) + elmts.slice(i+1) ) + } else if elmt.type == "seq" { + if elmt.enable-dst { + activation-history.push(elmt) + } + } else if elmt.type == "evt" { + if elmt.event == "enable" { + for elmt2 in elmts.slice(0, i).rev() { + if elmt2.type == "seq" { + activation-history.push(elmt2) + break + } + } + } + } else if elmt.type == "ret" { + if activation-history.len() == 0 { + panic("Cannot return if no lifeline is activated") + } + let seq = activation-history.pop() + elmts.at(i) = _seq( + seq.p2, seq.p1, + comment: elmt.comment, + disable-src: true, + dashed: true + ).first() } i += 1 } diff --git a/src/lib.typ b/src/lib.typ index 2d96474..79c8ab6 100644 --- a/src/lib.typ +++ b/src/lib.typ @@ -1,7 +1,7 @@ #let version = version(0, 1, 1) #import "diagram.typ": diagram, from-plantuml, _gap, _evt, _col -#import "sequence.typ": _seq +#import "sequence.typ": _seq, _ret #import "group.typ": _grp, _loop, _alt, _opt, _break #import "participant.typ": _par #import "separator.typ": _sep diff --git a/src/sequence.typ b/src/sequence.typ index c9300b4..73096ae 100644 --- a/src/sequence.typ +++ b/src/sequence.typ @@ -88,6 +88,13 @@ ),) } +#let _ret(comment: none) = { + return (( + type: "ret", + comment: comment + ),) +} + #let render(pars-i, x-pos, participants, elmt, y, lifelines) = { let shapes = ()