Skip to content

Commit

Permalink
Have one different callselflevel counter per inst. Fix xuyuan#29.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebousse committed Feb 11, 2017
1 parent 8383f51 commit 5cb6700
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions dev/pgf-umlsd.sty
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,27 @@ Sequence Diagrams.]
\newcounter{threadnum}
\newcounter{seqlevel} % level
\newcounter{callevel}
\newcounter{callselflevel}
\newcounter{blocklevel}

% From https://tex.stackexchange.com/questions/155776/check-if-counter-exists
% Tests if a counter has already been defined.
% Usage:
% \ifcounter{counter name}{action if exists}{action else}
\newcommand*\ifcounter[1]{%
\ifcsname c@#1\endcsname
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}

% new an instance
% Example:
% \newinst[edge distance]{var}{name:class}
\newcommand{\newinst}[3][0.2]{
\ifcounter{callselflevel#2}
{\setcounter{callselflevel#2}{0}}
{\newcounter{callselflevel#2}}
\stepcounter{instnum}
\path (inst\thepreinst.east)+(#1,0) node[inststyle] (inst\theinstnum)
{\ifpgfumlsdunderline
Expand Down Expand Up @@ -171,30 +185,30 @@ Sequence Diagrams.]
\newenvironment*{callself}[4][1]{
\stepcounter{seqlevel}
\stepcounter{callevel} % push
\stepcounter{callselflevel}
\def\l\thecallevel{#1}
\def\f\thecallevel{#2}
\def\t\thecallevel{#2}
\stepcounter{callselflevel\f\thecallevel}

\path
(#2)+(\thecallselflevel*0.1-0.1,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (sc\thecallevel) {}
(#2)+(\arabic{callselflevel\f\thecallevel}*0.1-0.1,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (sc\thecallevel) {}
({sc\thecallevel}.east)+(0,-0.33*\unitfactor) node (scb\thecallevel) {};

\draw[->,>=triangle 60] ({sc\thecallevel}.east) -- ++(0.8,0)
node[near start, above right] {#3} -- ++(0,-0.33*\unitfactor)
-- (scb\thecallevel);
\def\l\thecallevel{#1}
\def\f\thecallevel{#2}
\def\t\thecallevel{#2}
\def\returnvalue{#4}
\tikzstyle{threadstyle}+=[instcolor#2]
}{
\addtocounter{seqlevel}{\l\thecallevel}
\path (\f\thecallevel)+(\thecallselflevel*0.1-0.1,-\theseqlevel*\unitfactor-0.33*\unitfactor) node
\path (\f\thecallevel)+(\arabic{callselflevel\f\thecallevel}*0.1-0.1,-\theseqlevel*\unitfactor-0.33*\unitfactor) node
(sct\thecallevel) {};

\draw[dashed,->,>=angle 60] ({sct\thecallevel}.east) node
(sce\thecallevel) {} -- ++(0.8,0) -- node[midway, right]{\returnvalue} ++(0,-0.33*\unitfactor) -- ++(-0.8,0);
\drawthread{scb\thecallevel}{sce\thecallevel}
\addtocounter{callevel}{-1} % pop
\addtocounter{callselflevel}{-1}
\addtocounter{callselflevel\f\thecallevel}{-1}
}

% message between threads
Expand Down Expand Up @@ -224,11 +238,11 @@ Sequence Diagrams.]
\newcommand*{\messself}[3][1]{
\stepcounter{seqlevel}
\stepcounter{callevel} % push
\stepcounter{callselflevel}
\def\l\thecallevel{#1}
\def\f\thecallevel{#2}
\stepcounter{callselflevel\f\thecallevel}
\path
(\f\thecallevel)+(\thecallselflevel*0.1-0.1,-\theseqlevel*\unitfactor-0.33*\unitfactor)
(\f\thecallevel)+(\arabic{callselflevel\f\thecallevel}*0.1-0.1,-\theseqlevel*\unitfactor-0.33*\unitfactor)
node
(sct\thecallevel) {};
\addtocounter{seqlevel}{\l\thecallevel}
Expand All @@ -237,7 +251,7 @@ node
++(0,-\l\thecallevel*\unitfactor) -- ++(-0.8,0);

\addtocounter{callevel}{-1} % pop
\addtocounter{callselflevel}{-1}
\addtocounter{callselflevel\f\thecallevel}{-1}
}

% message between threads
Expand Down Expand Up @@ -357,7 +371,6 @@ node
\setcounter{threadnum}{0}
\setcounter{seqlevel}{0}
\setcounter{callevel}{0}
\setcounter{callselflevel}{0}
\setcounter{blocklevel}{0}

% origin
Expand Down

0 comments on commit 5cb6700

Please sign in to comment.