4

I have several TikZ-UML sequence diagrams and mostly I always set the options dt=5 and padding=3 for all umlcall. Is it possible to set these two variables for these values as default?

\documentclass{report}
\usepackage{tikz}
\usepackage{tikz-uml}
\begin{document}

\begin{tikzpicture}
      \begin{umlseqdiag}
        \umlbasicobject{B}
        \umlbasicobject[x=6]{C}

        \begin{umlcall}[op=msg1, return={r0, r1}, dt=4, padding=3]{C}{B}
        \end{umlcall}

        \begin{umlcall}[op=callback, return={ok}, dt=5, padding=3]{B}{C}
        \end{umlcall}

        \begin{umlcall}[op=msg2, return=r2, dt=5, padding=3]{C}{B}
        \end{umlcall}

      \end{umlseqdiag}
\end{tikzpicture}

\end{document}
3

The umlcall environment does

\pgfkeys{/tikzuml/call/.cd,%
   dt/.initial={tikzumlEmpty},%
   padding/.initial=2,%
   [...]

so there's no way to pass different initial values except correcting the environment's definition. Here's a way with xpatch.

\documentclass{report}
\usepackage{tikz}
\usepackage{tikz-uml}

\usepackage{xpatch}
\xpatchcmd{\umlcall}
  {dt/.initial={tikzumlEmpty}}
  {dt/.initial=5}
  {}{}
\xpatchcmd{\umlcall}
  {padding/.initial=2}
  {padding/.initial=3}
  {}{}

\begin{document}

\begin{tikzpicture}
      \begin{umlseqdiag}
        \umlbasicobject{B}
        \umlbasicobject[x=6]{C}

        \begin{umlcall}[op=msg1, return={r0, r1}, dt=4, padding=3]{C}{B}
        \end{umlcall}

        \begin{umlcall}[op=callback, return={ok}, dt=5, padding=3]{B}{C}
        \end{umlcall}

        \begin{umlcall}[op=msg2, return=r2, dt=5, padding=3]{C}{B}
        \end{umlcall}

      \end{umlseqdiag}
\end{tikzpicture}

\begin{tikzpicture}
      \begin{umlseqdiag}
        \umlbasicobject{B}
        \umlbasicobject[x=6]{C}

        \begin{umlcall}[op=msg1, return={r0, r1}, dt=4]{C}{B}
        \end{umlcall}

        \begin{umlcall}[op=callback, return={ok}]{B}{C}
        \end{umlcall}

        \begin{umlcall}[op=msg2, return=r2]{C}{B}
        \end{umlcall}

      \end{umlseqdiag}
\end{tikzpicture}

\end{document}

I typeset the original call and the new one where the values are not specified in order to see they're identical.

enter image description here

  • Is \ddt a non-existent command to cause an error on purpose when xpatch fails? (I couldn't find a specific definition on the documentation.) Why is not used when patching dt? – user3371321 Apr 1 '14 at 13:28
  • @user3371321 Yes, I use it to get warned if the patch fails, it's supposed to be undefined. Usually I remove it after testing, but this time I forgot doing it. – egreg Apr 1 '14 at 13:31
2

Here, I created a new environment, Umlcall which has your desired defaults. I changed up your MWE parameters a bit to show that one can override the defaults, and that the method works without any optional argument, as well. The defaults are defined in the macro \umldefaults.

\documentclass{report}
\usepackage{tikz}
\usepackage{tikz-uml}
\newcommand\umldefaults{dt=5, padding=3, }
\newenvironment{Umlcall}[3][]{\expandafter\umlcall\expandafter[\umldefaults #1]{#2}{#3}}%
  {\endumlcall}
\begin{document}

\begin{tikzpicture}
      \begin{umlseqdiag}
        \umlbasicobject{B}
        \umlbasicobject[x=6]{C}

        \begin{Umlcall}[op=msg1, return={r0, r1}, dt=7, padding=5]{C}{B}
        \end{Umlcall}

        \begin{Umlcall}[op=callback, return={ok}]{B}{C}
        \end{Umlcall}

        \begin{Umlcall}[op=msg2, return=r2]{C}{B}
        \end{Umlcall}

        \begin{Umlcall}{C}{B}
        \end{Umlcall}

      \end{umlseqdiag}
\end{tikzpicture}

\end{document}

enter image description here

0

You're right. tikz-uml offers a way to define global default value thanks to the command \tikzumlset but I only activated it for drawing purpose, namely draw, fill and text options of each available UML element. I added the possibility to define global default value for quite every option of every element. This will be available soon in the new release of tikz-uml.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.