2

Is it possible, when defining a node, to give external (hierarchical) access to the subnode? Consider the following MWE, where I would like to give a stable access to the internal node, like something stable like (A.innerC.180)...

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\makeatletter
\pgfdeclareshape{myshape}{
    \savedanchor{\northeast}{%
        \pgfpoint{1cm}{1cm}
    }
    \anchor{north}{\northeast\pgf@x=0cm\relax}
    \anchor{east}{\northeast\pgf@y=0cm\relax}
    \anchor{south}{\northeast\pgf@y=-\pgf@y \pgf@x=0cm\relax}
    \anchor{west}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x}
    \anchor{center}{
        \pgfpointorigin
    }
    \behindbackgroundpath{
        \pgfnode{circle}{center}{}{innerC}{\pgfusepath{fill,stroke}}
        \pgfpathmoveto{\pgfpointanchor{innerC}{-45}}
        \pgfpathlineto{\pgfpoint{1cm}{-1cm}}
        \pgfusepath{draw}
    }
}
\makeatother

\begin{document}
\begin{tikzpicture}
    \draw (0,0) node[myshape](A){};
    % I have access to innerC node here:
    \draw (innerC.90) -- ++(0,1);
    % Now I lose access to the "innerC" of A:
    \draw (2,0) node[myshape](B){};
    \draw (innerC.90) -- ++(0,1);
    % what I would like to do
    % \draw (A.innerC.90) -- (B.innerC.90);
\end{tikzpicture}
\end{document}

"sub

Rmano
  • 40,848
  • 3
  • 64
  • 125

1 Answers1

4

The name of the current shape is stored in \tikz@fig@name.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\makeatletter
\pgfdeclareshape{myshape}{
    \savedanchor{\northeast}{%
        \pgfpoint{1cm}{1cm}
    }
    \anchor{north}{\northeast\pgf@x=0cm\relax}
    \anchor{east}{\northeast\pgf@y=0cm\relax}
    \anchor{south}{\northeast\pgf@y=-\pgf@y \pgf@x=0cm\relax}
    \anchor{west}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x}
    \anchor{center}{
        \pgfpointorigin
    }
    \behindbackgroundpath{
        \pgfnode{circle}{center}{}{\tikz@fig@name-innerC}{\pgfusepath{fill,stroke}}
        \pgfpathmoveto{\pgfpointanchor{\tikz@fig@name-innerC}{-45}}
        \pgfpathlineto{\pgfpoint{1cm}{-1cm}}
        \pgfusepath{draw}
    }
}
\makeatother

\begin{document}
\begin{tikzpicture}
    \draw (0,0) node[myshape](A){};
    % I have access to innerC node here:
    \draw (A-innerC.90) -- ++(0,1);
    % Now I lose access to the "innerC" of A:
    \draw (2,0) node[myshape](B){};
    \draw (B-innerC.90) -- ++(0,1);
    % what I would like to do
    \draw (A-innerC.90) -- (B-innerC.90);
\end{tikzpicture}
\end{document}

enter image description here

Rmano
  • 40,848
  • 3
  • 64
  • 125