mercredi 3 décembre 2014

TikZ: use-provide UML-style


I would like to draw some components driagrams with use and provide ports with TikZ. But the way I want them to look is quite different from what tikz-uml since my needs are differents. I do not focus on describing a real application, but more on the structure between components.


There are mainly two cases: those that I know how verbose I want the code to be, and those I'm not sure about the way to express them.


Here are the simple cases.



  • When the components are close enough the U and the circle should touch.


Close components.


And the code should be as simple as this.



\begin{tikzpicture}
\node[component] (A) {A};
\node[component,right of=A] (B) {B};
\draw[useprovide] (A) -- (B);
\end{tikzpicture}



  • But when the components are too far away, the port stay within 1cm of the border of the component and the ports are connected with a line.


Far components.


And the code should remain exactly the same.



  • Also, two components may be connected by more than one pair of ports and they should be placed nicely.


Multiple use-provide between two components.


And the code should remain as simple as possible. For instance:



\begin{tikzpicture}
\node[component] (A) {A};
\node[component,above of=A] (B) {B};
\draw[useprovide] (A) -- (B);
\draw[useprovide] (A) -- (B);
\end{tikzpicture}


Optionally it would be nice if it would allow me to put some text on the lines and around the use and provide ports.


I tried with a decorated path but had trouble placing the nodes where I wanted. I tried with a to path operation but things get complicated as soon as I want to handle the second case (in addition to drawing the half circle backward when the connections are in diagonal). I can provide the code of my failed attempts if needed.


And here are the cases I also need to draw but I don't know how I want to write them.



  • One "use" port for several "provide" ports.


Multiple use.


Notice the small separation between the lines on the "use" side while they still touch the half circle.



  • One "provide" port for multiple "use" ports.


Multiple provide.


Again, there is a small gap between the lines.



  • And last but not least, when the components are far away in a complex setting, I may want to decide of the path of the line connecting them, but let the code put the use and provide shapes at the right place.


Complex connection path.


Notice How the long connection between A and D is made of 3 parts. I may also want the 90° turn on the side of D to happen before the use port. (But I'll probably try to avoid that.)


I can provide the code I used for the schema here if that helps.





Aucun commentaire:

Enregistrer un commentaire