1
\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}

output: outputOfCode

Now I want to use TikZ variables like this:

\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}

But the variables are undefined. How do I include the variables? If I use \pgfcircdeclarebipole the variables exist. But I need anchors so \pgfcircdeclarebipole is not a solution for me.

  • Do you mean setting up the keys that set those macros? – percusse Sep 21 '14 at 19:52
  • Now I see that \pgf@circ@res@left, \pgf@circ@res@right, \pgf@circ@res@up, \pgf@circ@res@down are defined in \pgfcircdeclarebiple. – Michael Banucu Sep 21 '14 at 20:25
  • You can define anchors (you can do anything there as it gets passed to \pgfdeclareshape directly) in the first parameter of \pgfcircdeclarebipole. – Qrrbrbirlbel May 10 '15 at 20:49
  • Typically one defines \pgf@circ@res@right etc. from saved anchors \northeast and \southwest, which in turn use pgfkeys like \pgfkeysvalueof{/tikz/circuitikz/bipoles/oscillator/height} (for example). – John Kormylo Dec 10 '15 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.