[Tex/LaTex] Statecharts using TikZ

nestingnodestikz-pgf

I haven't found any example of using TikZ for drawing Harel's statecharts notation. There are numerous examples of finite-state automata, but that cannot be applied for statecharts for two reasons: no hierarchy and no orthogonality. Can anyone suggest me please what is the best way to draw something as simple as this:

(A) –> (B(D) | C(E)),

where there are two top-level states: A and B|C (state with two orthogonal regions B and C, divided by a dashed line in the middle of state); B has a nested state D, whereas C has a nested state E; interlevel connections should be possible, i.e. a directed connection between A and C.

Edited: here's the picture

enter image description here

Best Answer

Code

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{fit,arrows,calc}

\begin{document}

\begin{tikzpicture}
[   round/.style={rounded corners=1.5mm,minimum width=1cm,inner sep=2mm,above right,draw,align=left,text width=7mm}
]
    \node[round] (D) at (0,0) {D};
    \node[round] (E) at (2,0) {E};
    \node[above right,inner sep=2mm] (B) at (0,1) {B};
    \node[above right,inner sep=2mm] (C) at (2,1) {C};
    \node[round,fit=(B)(C)(D)(E)] (BC) {};
        \draw[densely dashed] (BC.north) -- (BC.south);
    \node[round] (A) at (2.5,2.5) {A};
    \draw[-latex] (A) to[out=180, in=90] (D);
    \draw[-latex] ($(BC.north east)+(-0.3,-0.3)$) coordinate (temp) to[out=180,in=90] (E);
        \fill (temp) circle (0.05);
\end{tikzpicture}

\end{document}

Output

enter image description here

Related Question