我试图绘制具有一致腿长的VHV关系的继承树。我发现长度根据类盒内容的大小而变化。
这是(不是M)WE:
\documentclass[border={1cm 1cm 1cm 1cm}]{standalone}
\usepackage{tikz-uml}
\usetikzlibrary{calc, decorations.pathmorphing,decorations.pathreplacing,
fadings, shadings, shapes, arrows, positioning,patterns,automata}
\newcommand{\derivedown}[4]{
\umlclass[below=1cm of #1.south, anchor=north]{#2}{#3}{#4}
\umlinherit{#2}{#1}}
\newcommand{\derivedownt}[5]{
\umlclass[below=1cm of #1.south, anchor=north, template=#3]{#2}{#4}{#5}
\umlinherit{#2}{#1}}
\newcommand{\derivedownleft}[4]{
\umlclass[below left=1cm and 0.5cm of #1.south, anchor=north east]{#2}{#3}{#4}
\umlVHVinherit[arm2=-1.5cm]{#2}{#1}}
\newcommand{\siblingleft}[5]{
\umlclass[left=1cm of #1.north west, anchor=north east]{#3}{#4}{#5}
\umlVHVinherit[arm2=-1.5cm]{#3}{#2}}
\newcommand{\siblingright}[5]{
\umlclass[right=1cm of #1.north east, anchor=north west]{#3}{#4}{#5}
\umlVHVinherit[arm2=-1.5cm]{#3}{#2}}
\newcommand{\note}[2]{
\umlnote[below left=0.5cm and 0.5cm of #1.north east, anchor=south west]{#1}{#2}
}
\begin{document}
\begin{tikzpicture}
\umlclass{RefCount}{int refs;}{AddRef();Release();}
\note{RefCount}{deletes this on release to zero}
\derivedown{RefCount}{Event}{int id, prio}{}
\derivedown{Event}{EventAgent}{}{\umlvirt{deliver()=0;}\\ \umlvirt{getDeliveryTarget()=0;}}
\derivedown{EventAgent}{SyncEventAgent}{id=kAgentEventId}{send(IEventDispatcher dis) \{ \\ \hskip1em AddRef(); \\ \hskip1em dis.isThreadCurrent() \\ \hskip2em ? deliver() \\ \hskip2em : dis.sendEventSync(this); \\ \hskip1em Release(); \} }
\siblingleft{SyncEventAgent}{EventAgent}{SyncRetEventAgent}{}{}
\siblingright{SyncEventAgent}{EventAgent}{AsyncEventAgent}{}{send/remove(IEventDispatcher dis) \{ \\ \hskip1em dis.send/remove(this); \}}
\derivedownt{SyncRetEventAgent}{SyncRetEventAgentN}{T...}{}{}
\derivedownt{SyncEventAgent}{SyncEventAgentN}{T...}{}{}
\derivedownt{AsyncEventAgent}{AsyncEventAgentN}{T...}{}{}
\umlclass[right=10cm of RefCount]{IEventDispatcher}{}{\umlvirt{send/remove events} \\ \umlvirt{add/remove listener for id} \\ \umlvirt{isThreadCurrent()}}
\derivedown{IEventDispatcher}{EventDispatcher}{}{}
\derivedownleft{EventDispatcher}{EventThread}{}{}
\siblingright{EventThread}{EventDispatcher}{Selector}{}{}
\umlclass[right=2cm of EventDispatcher]{EventListenerNode}{}{}
\umluniaggreg[mult2=*]{EventDispatcher}{EventListenerNode}
\umlclass[right=10cm of IEventDispatcher]{IEventListener}{}{\umlvirt{void receiveEvent(Event*)}}
\end{tikzpicture}
\end{document}
在结果上,您将在EventAgent下方看到一个分叉,在EventDispatcher下方看到另一个分叉,但它们具有不同的分支长度。如果你取出所有3个[arm2 = -1.5cm]选项,你会发现左边的三向叉变得不平衡。这个-1.5cm的数字一开始很奇怪,但这就是我需要的大致正确的结果。
我认为开箱即用并没有理由让这些腿长取决于盒子的大小。它们应该从它们加入类盒边缘的位置进行测量。
我该如何解决这个问题?
PS:将第一个宏更改为:
\newcommand{\derivedown}[4]{
\umlclass[below=1cm of #1.south, anchor=north]{#2}{#3}{#4}
\umlinherit[name=under#1, anchor1=90, anchor2=90]{#2}{#1}
\umlpoint{under#1-1}}
我们看到继承箭头居中的位置,实际上它们似乎在类框的中点之间延伸。我尝试了arm1 / 2选项的每个组合,包括没有,没有用。