Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to draw a small chart showing a modular C++-program. I don't know where to start.

+-------------\  **    +------------\        + compiled src --+
| module.hpp  |\   **  | main.cpp   |\       |                |
+-------------+-+    **+------------+-+      | void func()    |
|               |      | #include "...|  ==> | int main() {   |
| void func();  |    **| int main() { |      |   ...          |
|               |  **  |   ...        |      |                |
+---------------+**    +--------------+      +----------------+

The module.hpp should visually "go into" the #include-line in main.cpp, so I thought about connecting lines that I draw as **-lines.

I will replace the text in the boxes with a bit better text, and probably add another box to the right for the applied compiler.

I can not think of what should be nodes here.

share|improve this question
1  
you should look into {tikz-uml} –  Sean Allred Jan 16 at 20:56
    
You can also play with \fbox, \parbox, \left. \right\rbrace and \rarrow and put the whole thing into an equation. But to do the triangle you need tikz. –  John Kormylo Jan 17 at 15:22
    
@towi have you found a solution or is this still open? –  Paul Gessler Mar 2 at 3:29
    
@PaulGessler I found a solution but did it a bit different. I think my current visualization is actually better then what I first planned. –  towi Mar 2 at 15:00
    
@towi great! You could either post your solution as a self-answer if you think it will be helpful for future visitors to the site, or close the question if you think the solution is too specific to your situation. It's up to you to decide. :) –  Paul Gessler Mar 2 at 15:02

1 Answer 1

For the record, I found a satisfactory solution. I modified a bit how I wanted to display the "inclusion" and I am quite satisfied with it. Just to let you know, if anyone wants to try the same.

modules

%%\usetikzlibrary{backgrounds,positioning}
%%\usetikzlibrary{decorations.pathreplacing}
%%\usetikzlibrary{shapes}
%%\usetikzlibrary{shapes.multipart}
%%\usetikzlibrary{arrows}

\pgfdeclarelayer{background}
\pgfdeclarelayer{back}
\pgfsetlayers{background,back,main}

\resizebox {\columnwidth} {!} {    % (2) scale to exact column width
\begin{tikzpicture}[
      background rectangle/.style={fill=black!10}, show background rectangle,
]

\tikzstyle{mybox} = [draw, fill=black!0, very thick,
    rectangle, inner sep=8pt, inner ysep=16pt]
\tikzstyle{fancytitle} =[fill=black!0, draw, very thick, text=black!100, rectangle, inner xsep=6pt,yshift=7.2pt,right=0pt]
\tikzstyle{modul} =[text=black!100, rectangle, inner sep=6pt]
\tikzstyle{cpp} =[fill=black!0, draw=black!30, thick]
\tikzstyle{hpp} =[fill=black!0, draw, thick]


  \node at (0,0) (main) [modul,cpp] {%
    \begin{minipage}{0.30\textwidth}
      \#include "teil1.hpp" \\ 
      \#include "teil2.hpp" \\ 
      \#include "const.hpp" \\ 
      int main() \{ ... \} 
    \end{minipage}%
  };
  \node[fancytitle,cpp] at (main.north west) {main.cpp};

  \node [below=of main.south east,xshift=-4ex] (teil1hpp) [modul,hpp] {%
    \begin{minipage}{0.30\textwidth}
      int func1(); \\
      static const int M=10;
    \end{minipage}%
  };
  \node[fancytitle,hpp] at (teil1hpp.north west) (a1) {teil1.hpp};

  \node [right=of teil1hpp.north east, anchor=north west] (teil1cpp) [modul,cpp] {%
    \begin{minipage}{0.30\textwidth}
      \#include "teil1.hpp" \\ 
      \#include "{}util.hpp" \\ 
      int func1() \{ ... \};
    \end{minipage}%
  };
  \node[fancytitle,cpp] at (teil1cpp.north west){teil1.cpp};


  \node [below=of teil1hpp,yshift=-12pt] (teil2hpp) [modul,hpp] {%
    \begin{minipage}{0.30\textwidth}
      \#include "{}util.hpp" \\ 
      \#include "const.hpp" \\ 
      int func2(); \\
          int data[Z];
    \end{minipage}%
  };
  \node[fancytitle,hpp] at (teil2hpp.north west) {teil2.hpp};

  \node [right=of teil2hpp.north east, anchor=north west] (teil2cpp) [modul,cpp] {%
    \begin{minipage}{0.30\textwidth}
      \#include "teil2.hpp" \\ 
      int func2() \{ ... \}; \\
          int data[Z] = \{\};
    \end{minipage}%
  };
  \node[fancytitle,cpp] at (teil2cpp.north west) {teil2.cpp};


  \node [below=of teil2hpp] (utilhpp) [modul,hpp] {%
    \begin{minipage}{0.30\textwidth}
      int calcLen();
    \end{minipage}%
  };
  \node[fancytitle,hpp] at (utilhpp.north west) (a2) {util.hpp};

  \node [right=of utilhpp.north east, anchor=north west] (utilcpp) [modul,cpp] {%
    \begin{minipage}{0.30\textwidth}
      \#include "{}util.hpp" \\ 
      \#include "const.hpp" \\ 
      int calcLen() \{ ... \};
    \end{minipage}%
  };
  \node[fancytitle,cpp] at (utilcpp.north west) {util.cpp};

  \node [right=of utilcpp.north east, anchor=north west] (consthpp) [modul,hpp] {%
    \begin{minipage}{0.30\textwidth}
      static const int X=1; \\
      static const int Y=2; \\
      static const int Z=3;
    \end{minipage}%
  };
  \node[fancytitle,hpp] at (consthpp.north west) {const.hpp};

\begin{pgfonlayer}{back}

 \path (main.south west) -- (a1.north west) node[midway] (aa) {};
 \path (main.south west)[xshift=-3ex] |- (aa) node[midway] (aaa) {};
   \draw[ultra thick,draw=black!20] (aaa) -- ([xshift=3ex]aaa -| consthpp.north east);

 \path (teil2hpp.south west) -- (a2.north west) node[midway] (bb) {};
   \draw[ultra thick,draw=black!20] (aaa |- bb) -- ([xshift=3ex]bb -| consthpp.north east);

\begin{scope}[->,thick,black!50]
 \draw[arrows={-triangle 45}]   (main.south west) |- (teil1hpp.west);
 \draw[arrows={-triangle 45}]   (main.south west) |- (teil2hpp)  ;
 \draw[arrows={-triangle 45}]   (main.east) -| ([xshift=1cm]consthpp.north);
 \draw[arrows={-triangle 45}]   (teil1cpp.south west)  -- (utilhpp.north east);
 \draw[arrows={-triangle 45}]   ([yshift=1.1cm]teil2cpp.west)  -- (teil1hpp);
 \draw[arrows={-triangle 45}]   (teil2hpp) edge [out=-20] (consthpp.north west); 
 \draw[arrows={-triangle 45}]   (utilcpp) -- (consthpp);
\end{scope}

\begin{scope}
 \draw[thick,dashed,black!50]   (teil1cpp.north west) -- (teil1hpp.north east);
 \draw[thick,dashed,black!50]   (teil2cpp.north west) -- (teil2hpp.north east);
 \draw[thick,dashed,black!50]   (utilcpp.north west) -- (utilhpp.north east);
\end{scope}
\end{pgfonlayer}



\end{tikzpicture}%
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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