I'd like do make a picture that consists of few blocks. One of these blocks I called \elementsymbol
(in MWE below) - it consists of an arrow surrounded by a circle.
- I have the problem with scaling of the picture - connection of the line to the circle center is lost while picture scale is not equal to 1.
- I don't know how to pass the label to my block in the form
angle:text
.
MWE:
\documentclass{standalone}
\usepackage{tikz}
% https://tex.stackexchange.com/questions/33703/extract-x-y-coordinate-of-an-arbitrary-point-in-tikz
\makeatletter
\newcommand{\gettikzxy}[3]{%
\tikz@scan@one@point\pgfutil@firstofone#1\relax
\edef#2{\the\pgf@x}%
\edef#3{\the\pgf@y}%
}
\makeatother
\pgfkeys{
/element settings/.is family,
/element settings,
default/.style={
name=nonameelement,
diameter=2ex,
x pos=0,
y pos=0,
label={}
},
name/.store in=\elementname,
diameter/.store in=\elementdiameter,
x pos/.store in=\elementxpos,
y pos/.store in=\elementypos,
label/.store in=\elementlabel
}
\tikzset{
pics/elementsym/.style args={origin #1:#2 d #3}{
foreground code={
\node (-housing) [draw,circle,minimum size=#3] at (#1,#2) {};
\draw [-stealth] (-housing.center) -- +(45:0.43*#3); % arrow part
\draw (-housing.center) -- +(225:0.4*#3); % arrow part
}
}
}
\newcommand\elementsymbol[1][]{
\pgfkeys{/element settings,default,#1}
\path pic (\elementname) {elementsym=origin {\elementxpos}:{\elementypos} d {\elementdiameter}};
% label attachment
\node [circle,inner sep=0,minimum size=\elementdiameter]
at (\elementxpos,\elementypos) [label={[label distance=-0.5ex]60:\elementlabel}] {};
}
\begin{document}
\begin{tikzpicture}[
scale=0.5
]
\draw (0,0) -- +(0:5mm) coordinate (con);
\gettikzxy{(con)}{\xpos}{\ypos}
\elementsymbol [x pos=\xpos,y pos=\ypos,name=device,label=x] % How to enable argument "label={60:text}"?
\end{tikzpicture}
\end{document}
Links listed below were helpful for me (not everything I understand), but I can't find solutions of the above problems by the use of information contained in these links.
- Using pgfkeys as an argument to a macro
- How to interpret the contents of a macro as key=value assignment for pgfkeys
- How to create a command with key values?
After reading pgfkeys documentation in pgf-tikz manual several times I can't understand it in many points.