% Copyright 2008 by Till Tantau and others Wibrow
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/generic/pgf/licenses/LICENSE for more details.


%
% Resistor shape based on a zig-zag-line
%

\pgfdeclareshape{var resistor IEC}
{
  \inheritsavedanchors[from=rectangle ee]
  \inheritanchor[from=rectangle ee]{center}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}
  \inheritanchorborder[from=rectangle ee]

  \backgroundpath{
    \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    % Middle line
    \pgf@yc=.5\pgf@ya
    \advance\pgf@yc by.5\pgf@yb
    % Height
    \pgf@xc=-.5\pgf@ya
    \advance\pgf@xc by.5\pgf@yb
    % Start point
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yc}}
    % Lines
    \advance\pgf@xb by.1pt%
    \pgfutil@loop%
      \advance\pgf@xa by4\pgf@xc\relax%
    \ifdim\pgf@xa<\pgf@xb%
      \advance\pgf@xa by-3\pgf@xc%
      \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}%
      \advance\pgf@xa by2\pgf@xc%
      \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@ya}}%
      \advance\pgf@xa by\pgf@xc%
      \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yc}}%
    \pgfutil@repeat%
    \advance\pgf@xb by-.1pt%
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yc}}%  
  }
}



%
% Inductor shape based on a bumpy line
%

\pgfdeclareshape{inductor IEC}
{
  \savedanchor\northeast{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgf@x=\pgf@xa%
    \advance\pgf@x by .5\pgf@xb%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}%
    \pgf@y=\pgf@ya%
    \advance\pgf@y by\pgf@yb%
  }
  \savedanchor\southwest{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgf@x=-\pgf@xa%
    \advance\pgf@x by -.5\pgf@xb%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgf@y=-\pgf@ya%
  }

  \anchor{center}{\pgfpointorigin}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}

  \anchorborder{%
    \ifdim\pgf@y<0pt%
      % tricky... simpilfy to the origin...
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@y%
      \pgf@process{\southwest}%
      \advance\pgf@y by-0.5pt%
      \pgf@xa=\pgf@x%
      \pgf@ya=\pgf@y%
      \pgf@process{\pgfpointborderrectangle{\pgfqpoint{\pgf@xc}{\the\pgf@yc}}{\pgfqpoint{-\pgf@xa}{-\pgf@ya}}}%
    \else%
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@y%
      \pgf@process{\pgfpointborderrectangle{\pgfqpoint{\pgf@xc}{\the\pgf@yc}}{\northeast}}%
    \fi%
  }
  
  \backgroundpath{
    \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xa=-\pgf@x \pgf@ya=0pt
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    % Height
    \pgf@xc=\pgf@yb%
    % Start point
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{0pt}}
    % Lines
    \advance\pgf@xb by.1pt%
    \pgfutil@loop%
      \advance\pgf@xa by2\pgf@xc\relax%
    \ifdim\pgf@xa<\pgf@xb%
      \pgfpatharc{180}{0}{\pgf@xc}%  
    \pgfutil@repeat%
    \advance\pgf@xb by-.1pt%
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{0pt}}%  
  }
}




%
% Simple capacitor, consisting of two parallel lines
%

\pgfdeclareshape{capacitor IEC}
{
  \inheritsavedanchors[from=rectangle ee]
  \inheritanchor[from=rectangle ee]{center}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}
  \inheritanchorborder[from=rectangle ee]

  \backgroundpath{
    \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
  }
}




%
% Simple ground, consisting of three lines, getting smaller
%

\pgfdeclareshape{ground IEC}
{
  \inheritsavedanchors[from=rectangle ee]
  \inheritanchor[from=rectangle ee]{center}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}
  \inheritanchorborder[from=rectangle ee]

  \backgroundpath{
    \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    % First line, simple
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    % Advance to middle
    \pgfmathsetlength\pgf@xa{.5\pgf@xa+.5\pgf@xb}
    % Make smaller
    \pgfmathsetlength\pgf@yc{.16666\pgf@yb-.16666\pgf@ya}
    \advance\pgf@ya by\pgf@yc
    \advance\pgf@yb by-\pgf@yc
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    % Make even smaller
    \advance\pgf@ya by\pgf@yc
    \advance\pgf@yb by-\pgf@yc
    \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
  }
}



%
% Battery, consisting of two parallel lines, one smaller than
% the other
%

\pgfdeclareshape{battery IEC}
{
  \inheritsavedanchors[from=rectangle ee]
  \inheritanchor[from=rectangle ee]{center}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}
  \inheritanchorborder[from=rectangle ee]

  \backgroundpath{
    \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    % First line, simple
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    % Make smaller
    \pgfmathsetlength\pgf@yc{.25\pgf@yb-.25\pgf@ya}
    \advance\pgf@ya by\pgf@yc
    \advance\pgf@yb by-\pgf@yc
    \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
  }
}


%
% Special diodes
%


\pgfdeclareshape{breakdown diode IEC}
{
  \inheritsavedanchors[from=rectangle ee]
  \inheritanchor[from=rectangle ee]{center}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}
  \inheritanchorborder[from=rectangle ee]

  \backgroundpath{
    \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgf@xc=.5\pgf@xa \advance\pgf@xc by.5\pgf@xb
    \pgf@yc=.5\pgf@ya
    \advance\pgf@yc by .5\pgf@yb
    % Triangles:
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xc}{\pgf@yc}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathclose
    \pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xc}{\pgf@yc}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathclose
  }

  
  \beforebackgroundpath{
    {
      \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
      \pgf@xa=\pgf@x \pgf@ya=\pgf@y
      \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
      \pgf@xb=\pgf@x \pgf@yb=\pgf@y
      \pgf@yc=.5\pgf@ya
      \advance\pgf@yc by.5\pgf@yb
      \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yc}}
      \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yc}}
      \pgfusepathqstroke
      \pgf@xc=.5\pgf@xa
      \advance\pgf@xc by.5\pgf@xb
      \pgftransformshift{\pgfqpoint{\pgf@xc}{\pgf@yc}}  
      \pgf@yc=.5\pgf@yb
      \advance\pgf@yc by-.5\pgf@ya
      \pgftransformscale{\pgf@sys@tonumber{\pgf@yc}}
      \pgfpathmoveto{\pgfqpoint{-.5pt}{-1pt}}
      \pgfpathlineto{\pgfqpoint{0pt}{-1pt}}
      \pgfpathlineto{\pgfqpoint{0pt}{1pt}}
      \pgfpathlineto{\pgfqpoint{.5pt}{1pt}}
      \pgfusepathqstroke
    }
  }
}






% Generic shapes
%
% When these shapes are used, you can set a key derived form the
% shapes name to some code that will be executed as the before
% background path. This means that the basic shape is fixed, but
% things like a special line inside the shape or at the border can be
% added without having to define a whole new shape.


\pgfdeclareshape{generic circle IEC}
{
  % This shape is a generic circle, to which you can add something to
  % the before background path using the key
  % /pgf/generic circle IEC/before background
  % When this key is invoked, the transformation matrix will have been
  % setup such that the circle's center is at the origin and that the
  % position \pgfpoint{1pt}{0pt} lies exactly on the top of the circle
  % (and, there, on the middle of the line).
  
  \inheritsavedanchors[from=circle ee]
  \inheritanchorborder[from=circle ee]
  \inheritanchor[from=circle ee]{north}
  \inheritanchor[from=circle ee]{north west}
  \inheritanchor[from=circle ee]{north east}
  \inheritanchor[from=circle ee]{center}
  \inheritanchor[from=circle ee]{west}
  \inheritanchor[from=circle ee]{east}
  \inheritanchor[from=circle ee]{south}
  \inheritanchor[from=circle ee]{south west}
  \inheritanchor[from=circle ee]{south east}
  \inheritanchor[from=circle ee]{input}
  \inheritanchor[from=circle ee]{output}
  \inheritbackgroundpath[from=circle ee]
  
  \beforebackgroundpath{
    {
      \centerpoint%
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@y%
      \pgftransformshift{}  
      \pgfutil@tempdima=\radius%
      \pgfmathsetlength{\pgf@xb}{\pgfkeysvalueof{/pgf/outer xsep}}%  
      \pgfmathsetlength{\pgf@yb}{\pgfkeysvalueof{/pgf/outer ysep}}%  
      \ifdim\pgf@xb<\pgf@yb%
        \advance\pgfutil@tempdima by-\pgf@yb%
      \else%
        \advance\pgfutil@tempdima by-\pgf@xb%
      \fi%
      \pgftransformscale{\pgf@sys@tonumber{\pgfutil@tempdima}}
      \pgfkeysvalueof{/pgf/generic circle IEC/before background}
    }
  }
}



%
% Generic diode, based on a rectangle
%

\pgfdeclareshape{generic diode IEC}
{
  % This shape is a generic diode, to which you can add something to
  % the before background path using the key
  % /pgf/generic diode IEC/before background
  % When this key is invoked, the transformation matrix will have been
  % setup such that the center is at the tip of the diode. The 
  % position \pgfpoint{1pt}{0pt} lies exactly on the top of the
  % (suggested) line before the diode. 
  
  \inheritsavedanchors[from=rectangle ee]
  \inheritanchor[from=rectangle ee]{center}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}
  \inheritanchorborder[from=rectangle ee]

  \backgroundpath{
    \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
    \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    % Move tip back a little bit
    \advance\pgf@xb by-.5\pgflinewidth
    % Triangle triangle:
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
    \pgf@yc=.5\pgf@ya
    \advance\pgf@yc by .5\pgf@yb
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yc}}
    \pgfpathclose
  }

  
  \beforebackgroundpath{
    {
      \pgf@process{\pgfpointadd{\southwest}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}
      \pgf@xa=\pgf@x \pgf@ya=\pgf@y
      \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
      \pgf@xb=\pgf@x \pgf@yb=\pgf@y
      \pgf@yc=.5\pgf@ya
      \advance\pgf@yc by.5\pgf@yb
      \pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@yc}}
      \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yc}}
      \pgfusepathqstroke
      \pgftransformshift{\pgfqpoint{\pgf@xb}{\pgf@yc}}  
      \pgf@yc=.5\pgf@yb
      \advance\pgf@yc by-.5\pgf@ya
      \pgftransformscale{\pgf@sys@tonumber{\pgf@yc}}
      \pgfkeysvalueof{/pgf/generic diode IEC/before background}
    }
  }
}


\pgfkeys{
  /pgf/generic circle IEC/before background/.initial=,
  /pgf/generic diode IEC/before background/.initial=,
}





%
% Concacts
%

\pgfdeclareshape{make contact IEC}
{
  \savedanchor\northeast{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgf@x=\pgf@xa%
    \advance\pgf@x by .5\pgf@xb%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}%
    \pgf@y=\pgf@ya%
    \advance\pgf@y by\pgf@yb%
  }
  \savedanchor\southwest{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgf@x=-.5\pgf@xa%
    \advance\pgf@x by -.5\pgf@xb%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgf@y=-\pgf@ya%
  }

  \anchor{center}{\pgfpointorigin}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}

  \anchorborder{%
    \ifdim\pgf@y<0pt%
      % tricky... simpilfy to the origin...
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@y%
      \pgf@process{\southwest}%
      \advance\pgf@y by-0.5pt%
      \pgf@xa=\pgf@x%
      \pgf@ya=\pgf@y%
      \pgf@process{\pgfpointborderrectangle{\pgfqpoint{\pgf@xc}{\the\pgf@yc}}{\pgfqpoint{-\pgf@xa}{-\pgf@ya}}}%
    \else%
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@y%
      \pgf@process{\pgfpointborderrectangle{\pgfqpoint{\pgf@xc}{\the\pgf@yc}}{\northeast}}%
    \fi%
  }
  
  \backgroundpath{
    \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xa=-\pgf@x \pgf@ya=0pt
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    % Start point
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{0pt}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
  }
}



%
% Concacts
%

\pgfdeclareshape{var make contact IEC}
{
  \savedanchor\northeast{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgf@x=\pgf@xa%
    \advance\pgf@x by .5\pgf@xb%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}%
    \pgf@y=\pgf@ya%
    \advance\pgf@y by\pgf@yb%
  }
  \savedanchor\southwest{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgf@x=-.5\pgf@xa%
    \advance\pgf@x by -.5\pgf@xb%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgf@y=-\pgf@ya%
    \pgf@xc=0.083333\pgf@x%
    \advance\pgf@y by\pgf@xc%
  }

  \anchor{center}{\pgfpointorigin}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}

  \anchorborder{%
    \ifdim\pgf@y<0pt%
      % tricky... simpilfy to the origin...
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@y%
      \pgf@process{\southwest}%
      \pgf@xa=\pgf@x%
      \pgf@ya=\pgf@y%
      \pgf@process{\pgfpointborderrectangle{\pgfqpoint{\pgf@xc}{\the\pgf@yc}}{\pgfqpoint{-\pgf@xa}{-\pgf@ya}}}%
    \else%
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@y%
      \pgf@process{\pgfpointborderrectangle{\pgfqpoint{\pgf@xc}{\the\pgf@yc}}{\northeast}}%
    \fi%
  }
  
  \backgroundpath{
    \pgf@process{\pgfpointadd{\northeast}{
        \pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xa=-\pgf@x \pgf@ya=0pt
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgf@xc=\pgf@xa
    \pgfutil@tempdima=2\pgf@xb%
    \pgfutil@tempdima=0.083333\pgfutil@tempdima%
    \advance\pgf@xa by \pgfutil@tempdima
    % Circle
    {\pgfpathcircle{\pgfqpoint{\pgf@xa}{0pt}}{\pgfutil@tempdima}}
    % Height
    % Start point
    \pgf@process{\pgfpointnormalised{\pgfpointdiff{\pgfqpoint{\pgf@xa}{0pt}}{\pgfqpoint{\pgf@xb}{\pgf@yb}}}}
    \pgf@xc=\pgf@x
    \pgf@yc=\pgf@y
    \pgfpathmoveto{\pgfpointadd{\pgfqpoint{\pgf@xa}{0pt}}{%
        \pgfpointscale{\pgfutil@tempdima}{\pgfqpoint{\pgf@xc}{\pgf@yc}}}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
  }
}



\pgfdeclareshape{break contact IEC}
{
  \savedanchor\northeast{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgf@x=\pgf@xa%
    \advance\pgf@x by .5\pgf@xb%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}%
    \pgf@y=\pgf@ya%
    \advance\pgf@y by\pgf@yb%
  }
  \savedanchor\southwest{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgf@x=-.5\pgf@xa%
    \advance\pgf@x by -.5\pgf@xb%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgf@y=-\pgf@ya%
  }

  \anchor{center}{\pgfpointorigin}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}

  \anchorborder{%
    \ifdim\pgf@y<0pt%
      % tricky... simpilfy to the origin...
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@y%
      \pgf@process{\southwest}%
      \advance\pgf@y by-0.5pt%
      \pgf@xa=\pgf@x%
      \pgf@ya=\pgf@y%
      \pgf@process{\pgfpointborderrectangle{\pgfqpoint{\pgf@xc}{\the\pgf@yc}}{\pgfqpoint{-\pgf@xa}{-\pgf@ya}}}%
    \else%
      \pgf@xc=\pgf@x%
      \pgf@yc=\pgf@y%
      \pgf@process{\pgfpointborderrectangle{\pgfqpoint{\pgf@xc}{\the\pgf@yc}}{\northeast}}%
    \fi%
  }
  
  \backgroundpath{
    \pgf@process{\pgfpointadd{\northeast}{\pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xa=-\pgf@x \pgf@ya=0pt
    \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    % Start point
    \pgfpathmoveto{\pgfqpoint{\pgf@xa}{0pt}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
    % Break point
    \pgf@xc=.2\pgf@xb
    \advance\pgf@xc by-.2\pgf@xa
    \pgfpathmoveto{\pgfqpoint{\pgf@xb}{0pt}}
    \advance\pgf@xb by-\pgf@xc
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{0pt}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
  }
}





\endinput

