0

Unfortunately I am not able to connect node Client1 to port 13. My unsuccessful attempt is shown below. I know that unlike nodes, pics cannot be referenced later. Can someone help me convert port/.pic to a node that can be referenced later? The red circles in my example are for guidance only.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc, shadings, shadows, shapes.arrows}
\usetikzlibrary{positioning}

\tikzset{ port/.pic={% style, size, label \tikzset{port/.cd,#1} \coordinate[] (main) at (0cm,0cm); \coordinate[] (labelposition) at (.5cm,1.2cm); \draw[port/rect] (main) rectangle (\pgfkeysvalueof{/tikz/port/tr}); \draw[fill=black] (.1cm,0cm) rectangle (.9cm,.5cm); \draw[fill=black] (.2cm,.5cm) rectangle (.8cm,.7cm); \draw[fill=black] (.4cm,.7cm) rectangle (.6cm,.8cm); \node (labelnode) at (labelposition) {\pgfkeysvalueof{/tikz/port/label}};
}, port/.cd, rect/.style={thin, fill=gray!20}, tr/.initial={1cm,1.5cm}, label/.initial={}, name/.initial={}, /tikz/.cd, rack switch/.style={ name=#1, fill=white, draw, minimum width=20cm, minimum height=4cm, path picture={ \draw[top color=gray!5,bottom color=gray!40](path picture bounding box.south west) rectangle (path picture bounding box.north east); % \coordinate (A-west) at([xshift=1cm,yshift=.2]path picture bounding box.west); % \draw[rack switch/point] (A-west) circle ; % \coordinate (A-center) at ($(path picture bounding box.center)!0!(path picture bounding box.south)$); % \draw[rack switch/point] (A-center) circle; % \coordinate (A-east) at (path picture bounding box.east); % \draw[rack switch/point] (A-east) circle; % \foreach \x/\a in {0/1,1.2/2,2.4/3,3.6/4,4.8/5,6/7,7.2/8,8.4/9,9.6/10,10.8/11, 12/12, 13.2/13}{ \pic(\a) at ($(A-west)+(\x,0cm)$){port={label=\a}};
} \foreach \x/\b in {1/14,2.2/15,3.4/16, 4.6/17, 5.8/18, 7/19, 8.2/20, 9.4/21, 10.6/22, 11.8/23, 13/24, 14.2/25}{ \picrotate=180 at ($(A-west)+(\x,-.2cm)$){port={label=\b}}; }
} }, rack switch/.cd, point/.style={fill=red!50, radius=0.2cm}, /tikz/.cd }

\begin{document} \begin{tikzpicture} \node(Switch1) at (0,0) [rack switch=s]{}; \node(Client1) [above right=2of s] {\includegraphics{icons/fileserver}}; \draw [red, ->] (Client1) -- (13); \end{tikzpicture}
\end{document}

enter image description here

Z.J
  • 389
  • you can put a suitable node inside a pic with several parameters; one of them is name of node. So you can refer later the name of the node as if the name of the pic . See an example here https://tex.stackexchange.com/a/602058/140722 – Black Mild Aug 03 '21 at 06:04

1 Answers1

1

As Black Mild suggested, you need to include nodes inside the pic to reference them.

Following code shows another version for your switch. The complete switch is a pic and every port is a node with a path picture to draw the hole.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc, shadings, shadows, shapes.arrows, matrix}
\usetikzlibrary{positioning}

\tikzset{ port_up/.style={draw, top color=gray!5, bottom color=gray!40, minimum width=1cm, minimum height=1.5cm, path picture={\fill ([xshift=1mm]path picture bounding box.south west)|-++(1mm,5mm)|-++(2mm,2mm)|-++(2mm,1mm)|-++(2mm,-1mm)|-++(1mm,-2mm)|-cycle;}, label={[anchor=north, outer sep=1mm]north:#1}}, port_down/.style={draw, top color=gray!5, bottom color=gray!40, minimum width=1cm, minimum height=1.5cm, path picture={\fill ([xshift=1mm]path picture bounding box.north west)|-++(1mm,-5mm)|-++(2mm,-2mm)|-++(2mm,-1mm)|-++(2mm,1mm)|-++(1mm,2mm)|-cycle;}, label={[anchor=south, outer sep=1mm]south:#1}},
switch/.pic={ \node[minimum width=20cm, minimum height=4cm, draw, top color=gray!5,bottom color=gray!40] (-body) {}; \path[fill=red!50] ([shift={(1cm,.2cm)}]-body.west) coordinate (-A) circle (.2); \path[fill=red!50] (-body.center) circle (.2); \path[fill=red!50] (-body.east)++(90:.2) arc (90:270:.2)--cycle; \foreach \i [count=\topi from 1, count=\bottomi from 14] in {1,...,13}{ \node[port_up=\topi, anchor=south west] (-\topi) at ([xshift=(\i-1)*1.1cm]-A) {}; \node[port_down=\bottomi, anchor=north, below=2mm of -\topi] (-\bottomi){}; } }, }

\begin{document} \begin{tikzpicture}

\path pic (Switch1) {switch};

\node[above right=2cm of Switch1-body] (Client) {\includegraphics{fileserver}}; \draw[red] (Client) -- (Switch1-13); \draw[green, ultra thick] (Switch1-16.center) to[out=280, in=-100] (Switch1-22.center);

\end{tikzpicture} \end{document}

enter image description here

Ignasi
  • 136,588