是否有可能以某种方式破解序列图以延长接收消息的线程Some Server
,以便它可以延伸到下一条消息notify
?
代码如下:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgf-umlsd}
\begin{document}
\begin{sequencediagram}%
\newthread{client}{Some Client}
\newinst{server}{Some Server}
\newinst{third}{Some Third Service}
\begin{call}{client}{do}{server}{}
\end{call}
\begin{messcall}{server}{notify}{third}
\end{messcall}
\end{sequencediagram}%
\end{document}
编辑:(关于 Ignasi 的评论)我希望得到类似以下内容:
答案1
实现类似效果的最简单方法是seqlevel
稍微操纵计数器。这个计数器是决定这些矩形长度的一部分。如果你这样做
\begin{sequencediagram}%
\newthread{client}{Some Client}
\newinst{server}{Some Server}
\newinst{third}{Some Third Service}
\begin{call}{client}{do}{server}{}
\addtocounter{seqlevel}{2}
\end{call}
\addtocounter{seqlevel}{-2}
\begin{messcall}{server}{notify}{third}
\end{messcall}
\end{sequencediagram}
你最终会得到
这不完全是你想要的,但差不多。
虽然我不能说我的方法很优雅,但可以得到你想要的结果。我定义了一个新环境customcall
,它的功能与你的情况基本相同call
,但有两个小修改来扩展相关矩形,如以下代码中的注释所示。
将call
环境替换为customcall
,其定义如下:
\documentclass{article}
\usepackage{pgf-umlsd}
\newenvironment*{customcall}[5][1]{
\stepcounter{seqlevel}
\stepcounter{callevel} % push
\path
(#2)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (cf\thecallevel) {}
(#4.\threadbias)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (ct\thecallevel) {};
\draw[->,>=triangle 60] ({cf\thecallevel}) -- (ct\thecallevel)
node[midway, above] {#3};
\def\l\thecallevel{#1}
\def\f\thecallevel{#2}
\def\t\thecallevel{#4}
\def\returnvalue{#5}
\tikzstyle{threadstyle}+=[instcolor#2]
}
{
\addtocounter{seqlevel}{\l\thecallevel}
\path
(\f\thecallevel)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (rf\thecallevel) {}
(\t\thecallevel.\threadbias)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (rt\thecallevel){}
++(0,-2.5cm) node (tmp) {} % this line is new
;
\draw[dashed,->,>=angle 60] ({rt\thecallevel}) -- (rf\thecallevel)
node[midway, above]{\returnvalue};
\drawthread{ct\thecallevel}{tmp} % second argument changed to "tmp" from "rt\thecallevel"
\addtocounter{callevel}{-1} % pop
}
\begin{document}
%Counter manipulation:
\begin{sequencediagram}%
\newthread{client}{Some Client}
\newinst{server}{Some Server}
\newinst{third}{Some Third Service}
\begin{call}{client}{do}{server}{}
\addtocounter{seqlevel}{2}
\end{call}
\addtocounter{seqlevel}{-2}
\begin{messcall}{server}{notify}{third}
\end{messcall}
\end{sequencediagram}%
%Environment hacking:
\begin{sequencediagram}%
\newthread{client}{Some Client}
\newinst{server}{Some Server}
\newinst{third}{Some Third Service}
\begin{customcall}{client}{do}{server}{}
\end{customcall}
\begin{messcall}{server}{notify}{third}
\end{messcall}
\end{sequencediagram}%
\end{document}