How to make properly macro with the use of pic?

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.

  1. 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.
  2. I don't know how to pass the label to my block in the form angle:text.

MWE:

\documentclass{standalone} \usepackage{tikz}  % http://tex.stackexchange.com/questions/33703/extract-x-y-coordinate-of-an-arbitrary-point-in-tikz \makeatletter \newcommand{\gettikzxy}[3]{%   \[email protected]@[email protected]\[email protected]#1\relax   \edef#2{\the\[email protected]}%   \edef#3{\the\[email protected]}% } \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} 

How to make properly macro with the use of pic?

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.

  1. Using pgfkeys as an argument to a macro
  2. How to interpret the contents of a macro as key=value assignment for pgfkeys
  3. 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.

Replay

Following code shows how to define a new shape for your symbol adapting the original code from forbidden sign shape.

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning, arrows.meta}

\makeatletter
\pgfdeclareshape{newsign}
{
  \inheritsavedanchors[from=circle] % this is nearly a circle
  \inheritanchorborder[from=circle]
  \inheritanchor[from=circle]{north}
  \inheritanchor[from=circle]{north west}
  \inheritanchor[from=circle]{north east}
  \inheritanchor[from=circle]{center}
  \inheritanchor[from=circle]{west}
  \inheritanchor[from=circle]{east}
  \inheritanchor[from=circle]{mid}
  \inheritanchor[from=circle]{mid west}
  \inheritanchor[from=circle]{mid east}
  \inheritanchor[from=circle]{base}
  \inheritanchor[from=circle]{base west}
  \inheritanchor[from=circle]{base east}
  \inheritanchor[from=circle]{south}
  \inheritanchor[from=circle]{south west}
  \inheritanchor[from=circle]{south east}
  \inheritbackgroundpath[from=circle]
  \foregroundpath{
    \centerpoint%
    \[email protected]=\[email protected]%
    \[email protected]=\[email protected]%
    \[email protected]=\radius%
    \pgfmathsetlength{\[email protected]}{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength{\[email protected]}{\pgfkeysvalueof{/pgf/outer ysep}}%
    \ifdim\[email protected]<\[email protected]%
      \advance\[email protected] by-\[email protected]%
    \else%
      \advance\[email protected] by-\[email protected]%
    \fi%
    \pgfpathmoveto{\pgfpointadd{\pgfqpoint{\[email protected]}{\[email protected]}}{\pgfqpoint{-0.6\[email protected]}{-0.6\[email protected]}}}
    \pgfpathlineto{\pgfpointadd{\pgfqpoint{\[email protected]}{\[email protected]}}{\pgfqpoint{0.6\[email protected]}{0.6\[email protected]}}}
    \pgfsetarrowsstart{}
    \pgfsetarrowsend{Latex}
  }
\makeatother

}

\begin{document}
\begin{tikzpicture}
\node[draw, newsign] (A) {A};

\node[draw, newsign, minimum size=1cm, red, fill=green!30, ultra thick, label=x] at (2,0) (B) {};

\draw (A) -- (B);

\node[draw, newsign] at (0,1) {Text};
\end{tikzpicture}
\end{document}

How to make properly macro with the use of pic?

Category: tikz pgf Time: 2016-07-28 Views: 3

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.123 (s). 12 q(s)