The following example generates a rack switch with a single port.
The front oft the rack switch is defined by a path picture.
I add the port to path picture by using \node and i am placing the node via coodinates. Unfortunately the coordinates of the port are ignored. Instead of this the port is placed at the center oft the path picture.
Is there a general approach to place a fully defined picture like, the port, absolutely at any point inside a path picture via coordinates?
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc, shadings, shadows, shapes.arrows}
\usetikzlibrary{positioning}
\tikzset{
port/.code={% style, size, label
\draw[port/rect] (0,0) 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);
},
port/.cd,
rect/.style={thin, fill=gray!20},
tr/.initial={1cm,1.5cm},
label/.initial={},
/tikz/.cd,
rack switch/.style={
name=#1,
fill=white, draw,
minimum width=20cm,
minimum height=4cm,
path picture={
anchor=center;
\node(port1)[port] at (-2,2){};
}
}
}
\begin{document}
\begin{tikzpicture}
\node(Switch1) at (0,0) [rack switch=switch1]{};
\end{tikzpicture}
\end{document}
pic. – Ignasi Aug 03 '21 at 12:09