如何将 tikz/pgf 中的变量纳入 pgfdeclareshape

如何将 tikz/pgf 中的变量纳入 pgfdeclareshape
\documentclass[tikz]{standalone}
\usepackage{circuitikz}
\pgfdeclareshape{oscillator}
{
    \anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
    \anchor{text} % this is used to center the text in the node
    {
        \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}
    }
    \savedanchor\opinright{\pgfpoint{0.4cm}{0cm}} % pin 1
    \anchor{p1}{\opinright}
    \savedanchor\opinup{\pgfpoint{0cm}{0.4cm}} % pin 2
    \anchor{p2}{\opinup}
    \savedanchor\opinleft{\pgfpoint{-0.4cm}{0cm}} % pin 3
    \anchor{p3}{\opinleft}
    \savedanchor\opindown{\pgfpoint{0cm}{-0.4cm}} % pin 4
    \anchor{p4}{\opindown}
    \foregroundpath
    { % draw
        \pgfsetlinewidth{0.03cm}

        \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{0.4cm}}{\pgfpoint{0.4cm}{0}}
        \pgfpathmoveto{\pgfpoint{-0.4cm+0.1cm}{-0.4cm+0.3cm}}
        \pgfpathlineto{\pgfpoint{-0.4cm+0.4cm}{-0.4cm+0.6cm}}
        \pgfpathlineto{\pgfpoint{-0.4cm+0.4cm}{-0.4cm+0.3cm}}
        \pgfpathlineto{\pgfpoint{-0.4cm+0.7cm}{-0.4cm+0.6cm}}
        \pgfpathlineto{\pgfpoint{-0.4cm+0.7cm}{-0.4cm+0.3cm}}

        \pgfusepath{draw}
    }
}
\begin{document}
    \begin{circuitikz}[european, scale=1]
        \draw
            (0,0) node[oscillator](osci){}
        ;
    \end{circuitikz}
\end{document}

输出: 输出代码

现在我想使用如下 TikZ 变量:

\pgfdeclareshape{osci}
{
    \anchor{center}{\pgfpointorigin} % within the node, (0,0) is the center
    \anchor{text} % this is used to center the text in the node
    {
        \pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}
    }
    \savedanchor\oscipina{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}} % pin 1
    \anchor{p1}{\oscipina}
    \savedanchor\oscipinb{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}} % pin 2
    \anchor{p2}{\oscipinb}
    \savedanchor\oscipinc{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}} % pin 3
    \anchor{p3}{\oscipinc}
    \savedanchor\oscipind{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}} % pin 4
    \anchor{p4}{\oscipind}
    \foregroundpath
    { % draw
        \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

        \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left+0.1cm}{\pgf@circ@res@down+0.3cm}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+0.4cm}{\pgf@circ@res@down+0.6cm}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+0.4cm}{\pgf@circ@res@down+0.3cm}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+0.7cm}{\pgf@circ@res@down+0.6cm}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+0.7cm}{\pgf@circ@res@down+0.3cm}}

        \pgfusepath{draw}
    }
}
\begin{document}
    \begin{circuitikz}[european, scale=1]
        \draw
            (0,0) node[osci](osci){}
        ;
    \end{circuitikz}
\end{document}

但变量未定义。我该如何包含变量?如果我使用\pgfcircdeclarebipole存在的变量。但我需要锚点,所以\pgfcircdeclarebipole对我来说这不是一个解决方案。

相关内容