% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.
%
% This module file is normally overriden by the provided m-circuitikz.tex
% in the newer ConTeXt distributions.
%
\startmodule[circuitikzgit]
\usemodule[tikz]

\def\pgfcircversion{1.6.10-unreleased-7d02c73}
\def\pgfcircversiondate{2024/07/26}
\writestatus{loading}{\pgfcircversiondate{} The CircuiTikz circuit drawing package version \pgfcircversion}


\usetikzlibrary[calc]
\usetikzlibrary[arrows.meta, bending]
\usetikzlibrary[fpu] % may be needed for use fpu reciprocal (v1.0.1)

\unprotect

\edef\tikzatcode{\the\catcode`\@}
\edef\tikzbarcode{\the\catcode`\|}
\edef\tikzexclaimcode{\the\catcode`\!}
\catcode`\@=11
\catcode`\|=12
\catcode`\!=12

%%%%%%%%%%% Springe nach tex/pgfcirc.defines
%%%---------- open: tex/pgfcirc.defines.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.
%
% This file has folding marks for vim (See last line).
%

%
% This file is loaded *before* the options for the package are executed, mainly
% for the following three ifs
%
% these three ifs are fundamental for the package loading options;
% do not move away
\newif\ifpgf@circ@siunitx
\newif\ifpgf@circ@siunitx@res
\newif\ifpgf@circuit@compat

%% Key managements%<<<1

\long\def\pgf@circ@comment#1{}

\def\circuitikzbasekey{/tikz/circuitikz}

\pgfkeys{\circuitikzbasekey/.is family}

\def\circuitikzset{\expandafter\pgfqkeys\expandafter{\circuitikzbasekey}}
\let\ctikzset\circuitikzset
\def\ctikzvalof#1{\pgfkeysvalueof{\circuitikzbasekey/#1}}
\def\ctikzsetvalof#1#2{\pgfkeyssetvalue{\circuitikzbasekey/#1}{#2}}

\pgfkeys{\circuitikzbasekey/.search also={/tikz}}
%%>>>

%% Temporary Counters and dimensions%<<<1
%% Temporary Counters
\newcount\pgf@circ@count@a
\newcount\pgf@circ@count@b
\newcount\pgf@circ@count@c
%%%%%%%%%%%%
%% Dimensions
% coordinate
\newdimen\pgf@circ@res@up
\newdimen\pgf@circ@res@down
\newdimen\pgf@circ@res@zero
\newdimen\pgf@circ@res@left
\newdimen\pgf@circ@res@right
\newdimen\pgf@circ@res@other
\newdimen\pgf@circ@res@step
\newdimen\pgf@circ@res@temp
% Base len for all circuitikz
\newdimen\pgf@circ@Rlen
% scaled length for internal use in scalable shapes
\newdimen\pgf@circ@scaled@Rlen
\ctikzset{bipoles/length/.code={\pgf@circ@Rlen = #1\pgf@circ@scaled@Rlen=\pgf@circ@Rlen}}
\pgf@circ@Rlen = 1.4cm
% by default scale is 1.0
\pgf@circ@scaled@Rlen=\pgf@circ@Rlen
% inital thickness
\newdimen \pgfstartlinewidth
%%>>>

%% Colors%<<<

% The following code is by @muzimuzhi --- see comment in
% https://github.com/circuitikz/circuitikz/issues/605#issuecomment-1030745366
\newif\ifpgf@circ@setcolor

% similar to how `/tikz/draw` and `/tikz/fill` are defined
%
% - `color=none`, \pgfusecolor is not executed at the beginning of node path(s)
% - `color` or `color=` (no or empty value), ignored
% - `color=<color name>`, \pgfusecolor{<color name>} will be executed
\ctikzset{
  color/.code={%
    \edef\pgf@circ@temp{#1}%
    \ifx\pgf@circ@temp\pgf@nonetext
      \pgf@circ@setcolorfalse
    \else
      \ifx\pgf@circ@temp\pgfutil@empty
      \else
        \pgf@circ@setcolortrue
        \pgfkeyssetvalue{\circuitikzbasekey/color}{#1}%
        \edef\ctikz@strokecolor{\ctikzvalof{color}}%
      \fi
    \fi
  },
  % init
  color=none
}

\let\ctikz@strokecolor\pgfutil@empty
\let\ctikz@fillcolor\pgfutil@empty
% do our tracking of color
\pgfkeys{/tikz/color/.add code={}{%
    \edef\ctikz@strokecolor{#1}\ctikzset{color={#1}}}}
% do our tracking of fill
\pgfkeys{/tikz/fill/.add code={}{%
    \edef\ctikz@fillcolor{#1}}}
%
% This is to try to track the "implicit" color specification of Tikz,
% like \draw[red,...] ...; which are not exactly the same than saying
% \draw[color=red,...] ...;
% This is too dangerous to issue by default (it was in 1.5.0 and it
% was an error), so we will just define a command and tell it in the
% manual.
% It needs \usepackage{regexpatch} (which is not compatible with
% xpatch, unfortunately)
% I do not know how to do the xpatchcmd in ConTeXt...
%
\def\ctikzPatchImplicitColor{%
\ifpgfutil@format@is@latex
    \pgfkeysgetvalue{/tikz/.unknown/.@cmd}{\my@temp}
    \xpatchcmd*\my@temp % use starred-form to replace all (two places actually)
      {\expandafter\tikz@addoption\expandafter}
        {\edef\ctikz@strokecolor{\tikz@key}%
        \expandafter\tikz@addoption\expandafter}
      {}{%
      \pgfutil@packagewarning{circuitikz}{%
        Color patch failed, use only explicit color=... (see manual)}}
    \pgfkeyslet{/tikz/.unknown/.@cmd}{\my@temp}
\else
    \pgfutil@packagewarning{circuitikz}{%
        Not on LaTeX: patch failed, ^^J%
        use only explicit color=...(see manual).}
\fi
}
%
\def\pgf@circ@setcolor{%
  \ifpgf@circ@setcolor
    \pgfsetcolor{\ctikzvalof{color}}%
  \fi
}%
%
% Try our best to set the fill color the same as the draw
% color. This needs the patch above
%
\def\pgf@circ@setfillcolorasdraw{%
    \ifx\tikz@strokecolor\pgfutil@empty
        % we do not have the stroke color. Resort to the
        % last explicit color command; this will fail if
        % the color is changed mid-draw.
        % "Doctor, it hurts if I touch here..."
        \ifx\ctikz@strokecolor\pgfutil@empty
            % no info here. Try to use the current color.
            \pgfsetfillcolor{.}%
        \else
            % Try with the last seen change-color command
            \pgfsetfillcolor{\ctikz@strokecolor}
        \fi
    \else
        % we have strokecolor, yay!
        \pgfsetfillcolor{\tikz@strokecolor}
    \fi
}
% we call this when we want to fill of the "draw"
% color. So if we have no explicit color, use ".".
\def\pgf@circ@fill@strokecolor{%
    \pgf@circ@setfillcolorasdraw
}
% this is to select the \pgftext color; set it as
% the stroke color (\pgftext uses the fill color)
\def\pgf@circ@text@strokecolor{%
    \pgf@circ@setfillcolorasdraw
}
% debug text
\def\pgf@circ@debug@colors{%
    \pgfscope
        \pgfsetcolor{black}%
        \pgftext[y=10pt]{\tiny S:\tikz@strokecolor~T:\tikz@textcolor~F:\tikz@fillcolor}%
        \pgftext[y=16pt]{\tiny CS:\ctikz@strokecolor~CF:\ctikz@fillcolor}%
    \endpgfscope
}
%>>>


%% Macros for basic drawing%<<<
%
\long\gdef\pgf@circ@draw@component#1{%
    \behindbackgroundpath{%
        \pgf@circ@start@draw@hooks
        #1%
        \pgf@circ@end@draw@hooks
    }%
}%
%
% auxiliary macros to reset some thing in paths, for background images.
% use with care and ALWAYS inside a \pgfscope, see here:
% https://matrix.to/#/!NuxCISwYQJuyWwNsEI:matrix.org/$vQO6luq1F66LJ79dERmaqKI46qMBcjStqYCPi725uZE?via=matrix.org&via=2krueger.de&via=im.f3l.de
% Thanks to @muzimuzhi
%
\def\pgf@circ@reset@arrows{%
    \pgfsetshortenstart{+0pt}\pgfsetshortenend{+0pt}\pgfsetarrows{-}%
}
\def\pgf@circ@reset@rounded{%
    \pgfsetcornersarced{\pgfpointorigin}%
}
\def\pgf@circ@reset@arrows@rounded{%
    \pgf@circ@reset@arrows\pgf@circ@reset@rounded
}
\def\pgf@circ@adjustfill{%
    \ifx\ctikz@fillcolor\pgfutil@empty
    % do  nothing
    \else
        \ifx\ctikz@fillcolor\pgf@nonetext
        % do nothing
        \else
            \pgfsetfillcolor{\ctikz@fillcolor}%
        \fi
    \fi
}
%% Hook macros for the start and end of component drawing. The idea is that
%% specific macros overrides class macro that overrides generic macro
%% the generic macro is the one that resets arrows and curved path parameters
%% but let the path inherits the rest (dashed, etc.)

\def\pgf@circ@start@draw@hooks{%
    % \typeout{SHAPE: \pgf@sm@shape@name}
    \ifcsname ctikz@hook@start@draw@component@\pgf@sm@shape@name\endcsname
        \csname ctikz@hook@start@draw@component@\pgf@sm@shape@name\endcsname
    \else
        \ifcsname ctikzclass\endcsname
            \ifcsname ctikz@hook@start@draw@class@\ctikzclass\endcsname
                \csname ctikz@hook@start@draw@class@\ctikzclass\endcsname
            % class defined, but no hook, run generic hook
            \else
                \csname ctikz@hook@start@draw@default\endcsname
            \fi
        % we have no class, we did not run specific hook:run generic hook
        \else
            \csname ctikz@hook@start@draw@default\endcsname
        \fi
    \fi
}
\def\pgf@circ@end@draw@hooks{%
    % \typeout{SHAPE: \pgf@sm@shape@name}
    \ifcsname ctikz@hook@end@draw@component@\pgf@sm@shape@name\endcsname
        \csname ctikz@hook@end@draw@component@\pgf@sm@shape@name\endcsname
    \else
        \ifcsname ctikzclass\endcsname
            \ifcsname ctikz@hook@end@draw@class@\ctikzclass\endcsname
                \csname ctikz@hook@end@draw@class@\ctikzclass\endcsname
            % class defined, but no hook, run generic hook
            \else
                \csname ctikz@hook@end@draw@default\endcsname
            \fi
        % we have no class, we did not run specific hook:run generic hook
        \else
            \csname ctikz@hook@end@draw@default\endcsname
        \fi
    \fi
}
%
%% default hook is to stop the propagation of arrows parameters and
%% arced corners.
%
\def\ctikz@hook@start@draw@default{\pgf@circ@reset@arrows@rounded}
%
%
%>>>

%% check loaded TikZ/pgf version %<<<`
%
% parse the release date, thanks to Skillmon
% https://github.com/pgf-tikz/pgf/issues/1348#issuecomment-2231681032
% date can be yyyy-mm-dd or (older TikZ) yyyy/mm/dd
\begingroup
    \pgfutil@protected\def\parsedate#1%
      {%
        \afterassignment\parsedate@month
        \pgf@circ@count@a=#1\relax
      }
    \pgfutil@protected\def\parsedate@month#1%
      {%
        \afterassignment\parsedate@day
        \pgf@circ@count@b=%
      }
    \pgfutil@protected\def\parsedate@day#1%
      {%
        \afterassignment\parsedate@cleanup
        \pgf@circ@count@c=%
      }
    \def\parsedate@cleanup#1\relax{}%
    \parsedate{\pgfrevisiondate}%
    \xdef\ctikz@@pgfyear{\the\pgf@circ@count@a}%
    \xdef\ctikz@@pgfmonth{\the\pgf@circ@count@b}%
    \xdef\ctikz@@pgfday{\the\pgf@circ@count@c}%
\endgroup
% The following code thanks to Skillmon:
% https://tex.stackexchange.com/a/722570/38080
% modified by romano to check the date
\def\ctikz@@ifpgfafter@auxi#1#2%
  {%
    \ifnum#1
      \ctikz@@ifpgfafter@auxii{#2}%
    \fi
  }
\def\ctikz@@ifpgfafter@auxii#1\fi#2\ctikz@@ifpgfafter#3{\fi#1}
\def\ctikz@@ifpgfafter#1-#2-#3#%
  {%
    \ctikz@@ifpgfafter@auxi{\ctikz@@pgfyear>#1}\pgfutil@firstoftwo
    \ctikz@@ifpgfafter@auxi{\ctikz@@pgfyear<#1}\pgfutil@secondoftwo
    \ctikz@@ifpgfafter@auxi{\ctikz@@pgfmonth>#2}\pgfutil@firstoftwo
    \ctikz@@ifpgfafter@auxi{\ctikz@@pgfmonth<#2}\pgfutil@secondoftwo
    \ctikz@@ifpgfafter@auxi{\ctikz@@pgfday<#3}\pgfutil@secondoftwo
    \pgfutil@gobble\ctikz@@ifpgfafter\pgfutil@firstoftwo
  }
%
% usage \ctikz@@ifpgfafter 2023-01-16{true}{false}
%                                 ^^^ no spaces here, braces needed.
%
%>>>

%% arrow tips macros and utilities %<<<1

% the default arrow is latexslim, which has been ported over old arrows library (deprecated)
% see https://tex.stackexchange.com/questions/234084/latex-arrow-tip-with-arrows-meta-library
% this was the original definition of latex' tips, renamed to avoid clashes
%
\pgfarrowsdeclare{latexslim}{latexslim}
{
  \pgfutil@tempdima=0.28pt%
  \advance\pgfutil@tempdima by.3\pgflinewidth%
  \pgfarrowsleftextend{+-4\pgfutil@tempdima}
  \pgfarrowsrightextend{+6\pgfutil@tempdima}
}
{
  \pgfutil@tempdima=0.28pt%
  \advance\pgfutil@tempdima by.3\pgflinewidth%
  \pgfpathmoveto{\pgfqpoint{6\pgfutil@tempdima}{0\pgfutil@tempdima}}
  \pgfpathcurveto
  {\pgfqpoint{3.5\pgfutil@tempdima}{.5\pgfutil@tempdima}}
  {\pgfqpoint{-1\pgfutil@tempdima}{1.5\pgfutil@tempdima}}
  {\pgfqpoint{-4\pgfutil@tempdima}{3.75\pgfutil@tempdima}}
  \pgfpathcurveto
  {\pgfqpoint{-1.5\pgfutil@tempdima}{1\pgfutil@tempdima}}
  {\pgfqpoint{-1.5\pgfutil@tempdima}{-1\pgfutil@tempdima}}
  {\pgfqpoint{-4\pgfutil@tempdima}{-3.75\pgfutil@tempdima}}
  \pgfpathcurveto
  {\pgfqpoint{-1\pgfutil@tempdima}{-1.5\pgfutil@tempdima}}
  {\pgfqpoint{3.5\pgfutil@tempdima}{-.5\pgfutil@tempdima}}
  {\pgfqpoint{6\pgfutil@tempdima}{0\pgfutil@tempdima}}
  \pgfpathclose
  \pgfusepathqfill
}
\pgfarrowsdeclarereversed{latexslim reversed}{latexslim reversed}{latexslim}{latexslim}
%% Jack Tap, see
%% https://github.com/circuitikz/circuitikz/issues/806
\pgfdeclarearrow{name=Jack Tap,
    parameters = {%
    \the\pgfarrowlength,%
    \the\pgfarrowwidth,%
    \ifpgfarrowswap s\fi%
    \ifpgfarrowopen o\fi%
    \ifpgfarrowroundjoin j\fi
    \ifpgfarrowroundcap c\fi%
    },
    setup code = {
        \pgfarrowssettipend{.5\pgfarrowlength}
        \pgfarrowssetlineend{-.6\pgfarrowlength}
        \pgfarrowssetvisualbackend{-.6\pgfarrowlength}
        \pgfarrowssetbackend{-.6\pgfarrowlength}
        % hull
        \pgfarrowshullpoint{.5\pgfarrowlength}{0pt}
        \pgfarrowshullpoint{0pt}{\pgfarrowwidth}
        \pgfarrowshullpoint{-.6\pgfarrowlength}{0pt}
        % Saves: Only the length:
        \pgfarrowssavethe\pgfarrowlength
        \pgfarrowssavethe\pgfarrowwidth
    },
    drawing code = {
        \pgfsetdash{}{+0pt}
        \pgfarrowlinewidth=\pgflinewidth
        \ifpgfarrowroundjoin\pgfsetroundjoin\else\pgfsetmiterjoin\fi
        \ifpgfarrowroundcap\pgfsetroundcap\else\pgfsetbuttcap\fi
        \pgfpathmoveto{\pgfqpoint{-.6\pgfarrowlength}{0pt}}
        \pgfpathlineto{\pgfqpoint{-.5\pgfarrowlength}{0pt}}
        \pgfpathlineto{\pgfqpoint{0pt}{\pgfarrowwidth}}
        \pgfpathlineto{\pgfqpoint{.5\pgfarrowlength}{0pt}}
        \ifpgfarrowopen
            \pgfusepathqstroke
        \else
            \pgfpathclose
            \ifdim\pgfarrowlinewidth>0pt\pgfusepathqfillstroke\else\pgfusepathqfill\fi
        \fi
    },
    defaults = {length = 0.3cm, width=0.15cm, open},
    % cache=false, % breaks everything
}
% the new "fill without arg" will be in TikZ 3.1.11. Apply it here if we have an
% older version
\ctikz@@ifpgfafter 2023-01-16{\relax}{%
    % thanks @muzimuzhi https://github.com/pgf-tikz/pgf/issues/1348#issuecomment-2229075269
    % undo the fill/.value required key
    \expandafter\let\csname pgfk@/pgf/arrow keys/fill/.@def\endcsname\@undefined
    \pgfkeys{/pgf/arrow keys/fill/.code={%
        \def\pgf@temp{#1}%
        \ifx\pgf@temp\pgf@nonetext%
          \pgfarrowsaddtooptions{\pgfarrowopentrue}%
        \else\ifx\pgf@temp\pgfkeysnovalue@text%
          \pgfarrowsaddtooptions{\pgfarrowopenfalse}%
        \else
          \pgfarrowsaddtooptions{\pgfarrowopenfalse\def\pgf@arrows@fill@color{#1}}%
        \fi\fi
    }}%
}
\tikzset{v/.tip={Jack Tap[swap]}, ^/.tip={Jack Tap},
    vf/.tip={Jack Tap[swap,fill]}, ^f/.tip={Jack Tap[fill]}}
%
% select the arrows using available defaults.
\def\pgfcirc@arrow@default{default}
% choose the arrows to use. Use #2 and #3 if the key is equal to "default"
% arguments: type, default start, default end
\def\pgfcirc@set@arrows#1#2#3{%
        \pgfkeysifdefined{\circuitikzbasekey/#1 start arrow}%
            {\edef\@@start{\ctikzvalof{#1 start arrow}}}%
            {\edef\@@start{\pgfcirc@arrow@default}}
        \pgfkeysifdefined{\circuitikzbasekey/#1 end arrow}%
            {\edef\@@end{\ctikzvalof{#1 end arrow}}}%
            {\edef\@@end{\pgfcirc@arrow@default}}
        \ifx\@@start\pgfcirc@arrow@default
            \pgfsetarrowsstart{#2}%
        \else
            \pgfsetarrowsstart{\@@start}%
        \fi
        \ifx\@@end\pgfcirc@arrow@default
            \pgfsetarrowsend{#3}%
        \else
            \pgfsetarrowsend{\@@end}%
        \fi
}

\def\pgf@circ@declare@family@arrows#1{%
    \ctikzset{#1 start arrow/.initial={default}}
    \ctikzset{#1 end arrow/.initial={default}}
    \tikzset{#1 start arrow/.style={\circuitikzbasekey/#1 start arrow={##1}}}
    \tikzset{#1 end arrow/.style={\circuitikzbasekey/#1 end arrow={##1}}}
}
%%>>>

%% Macros to do things depending on the class%<<<1

\def\pgf@circ@setifdefinedfill#1#2{%
    % if \ctikzclass is defined and \ctikzclass/fill is defined and is not none:
    % set the fill color and execute \pgfusepath{#1}, else execute \pgfusepath{#2}
    % \typeout{SETIFDEF:#1\space#2:}
    \ifdefined\ctikzclass
        \pgfkeysifdefined{\circuitikzbasekey/\ctikzclass/fill}%
        {% yes, it's defined
            \edef\@@tmp{\ctikzvalof{\ctikzclass/fill}}\edef\@@none{none}%
            \ifx\@@tmp\@@none % but it's none
                \pgfusepath{#2}%
            \else
                \pgfsetfillcolor{\@@tmp}%
                \pgfusepath{#1}%
            \fi
        }{% the class is defined but the fill key not; use  #2
            \pgfusepath{#2}%
        }
    \else
    \pgfusepath{#2}%
    \fi
}

%% Macro to fill or draw

\def\pgf@circ@draworfill{%
    \ifx\tikz@fillcolor\pgfutil@empty
        \ifx\ctikz@fillcolor\pgfutil@empty
            \pgf@circ@setifdefinedfill{draw,fill}{draw}
        \else
            \ifx\ctikz@fillcolor\pgf@nonetext
                 \pgf@circ@setifdefinedfill{draw,fill}{draw}
            \else
                \pgfsetfillcolor{\ctikz@fillcolor}
                \pgfusepath{draw, fill}
            \fi
        \fi
    \else
        \pgfsetfillcolor{\tikz@fillcolor}
        \pgfusepath{draw, fill}
    \fi
}

\def\pgf@circ@draworfillandclip{%
    \ifx\tikz@fillcolor\pgfutil@empty
        \ifx\ctikz@fillcolor\pgfutil@empty
            \pgf@circ@setifdefinedfill{draw, clip, fill}{draw, clip}
            \pgfusepath{draw, clip}
        \else
            \ifx\ctikz@fillcolor\pgf@nonetext
                \pgf@circ@setifdefinedfill{draw, clip, fill}{draw, clip}
                \pgfusepath{draw, clip}
            \else
                \pgfsetfillcolor{\ctikz@fillcolor}
                \pgfusepath{draw, clip, fill}
            \fi
        \fi
    \else
        \pgfsetfillcolor{\tikz@fillcolor}
        \pgfusepath{draw, clip, fill}
    \fi
}

\def\pgf@circ@maybefill{%
    % \typeout{MAYBEFILL\tikz@fillcolor}%
    \ifx\tikz@fillcolor\pgfutil@empty
        \ifx\ctikz@fillcolor\pgfutil@empty
            \pgf@circ@setifdefinedfill{fill}{discard}
        \else
            \ifx\ctikz@fillcolor\pgf@nonetext
                \pgf@circ@setifdefinedfill{fill}{discard}
            \else
                \pgfsetfillcolor{\ctikz@fillcolor}
                \pgfusepath{fill}
            \fi
        \fi
    \else
        \pgfsetfillcolor{\tikz@fillcolor}
        \pgfusepath{fill}
    \fi
}

%% Macros for setting linewidth
% #1 is the legacy class (bipoles, tripoles) etc
% #2 is the reference linewidth
\def\pgf@circ@setlinewidth#1#2{%
    \ifdefined\ctikzclass
        \pgfkeysifdefined{\circuitikzbasekey/\ctikzclass/thickness}%
        {% yes, it's defined
        \edef\@@tmp{\ctikzvalof{\ctikzclass/thickness}}\edef\@@none{none}%
        \ifx\@@tmp\@@none % but it's none
            \pgfsetlinewidth{\ctikzvalof{#1/thickness}#2}% passthrough legacy class
        \else
            \pgfsetlinewidth{\@@tmp #2}%
        \fi
        }{ % key not defined, do the legacy thing
            \pgfsetlinewidth{\ctikzvalof{#1/thickness}#2}%
        }% Ok, do nothing
    \else % no class
        \pgfsetlinewidth{\ctikzvalof{#1/thickness}#2}%
    \fi
}
% use \pgf@circ@setlinewidth{none}{\pgflinewidth} if there is no legacy case
\ctikzset{none/thickness/.initial=1.0} % do not touch

% set thickness relative to current thickness if exists class and key
\def\pgf@circ@set@relative@thickness#1{%
    \ifdefined\ctikzclass
        \pgfkeysifdefined{\circuitikzbasekey/\ctikzclass/#1}
        {% yes, it's defined
            \pgfsetlinewidth{\ctikzvalof{\ctikzclass/#1}\pgflinewidth}%
        }{}
    \fi
}

% set the color and dash pattern for a subset of the shape, following keys #1/color
% and #1/dash. The keys must exist, and check for none or default for both
\def\pgf@circ@subset@color@dash#1{%
    % You *must* be sure that this is called inside a \pgfscope!
    \edef\@@none{none}\edef\@@default{default}
    \edef\@@tmp{\ctikzvalof{#1/color}}
    \ifx\@@tmp\@@default\else
        \pgfsetcolor{\@@tmp}
    \fi
    \edef\@@tmp{\ctikzvalof{#1/dash}}
    \ifx\@@tmp\@@default\else
        \ifx\@@tmp\@@none
            \pgfsetdash{}{0pt}% solid line, override dash
        \else
            \expandafter\pgfsetdash\expandafter{\@@tmp}{0cm}
        \fi
    \fi
}
% similar o the above, use the fill parameter to set fill or draw
% for a subset of the shape
\def\pgf@circ@subset@fill@or@draw#1{%
    % You *must* be sure that this is called inside a \pgfscope!
    \edef\@@none{none}\edef\@@default{default}
    \edef\@@tmp{\ctikzvalof{#1/fill}}
    \ifx\@@tmp\@@none
        \pgfusepath{draw}
    \else
        \ifx\@@tmp\@@default\else
            \pgfsetfillcolor{\@@tmp}
        \fi
        \pgfusepath{draw, fill}
    \fi
}
% ...and for the  thickness
\def\pgf@circ@subset@thickness#1{%
    % You *must* be sure that this is called inside a \pgfscope!
    \edef\@@default{default}
    \edef\@@tmp{\ctikzvalof{#1/thickness}}
    \ifx\@@tmp\@@default\else
        \pgfsetlinewidth{\@@tmp\pgflinewidth}%
    \fi
}
% set the text color (via \color) if the color is not default or none
% needed in some strange case (like bodydiode' dots)
\def\pgf@circ@maybe@color#1{%
    \edef\@@none{none}\edef\@@default{default}%
     \edef\@@tmp{\ctikzvalof{#1}}%
     \ifx\@@tmp\@@default\else
        \ifx\@@tmp\@@none\else
            \color{\@@tmp}%
        \fi
     \fi
}

%%>>>

%% font changes compatible with plain/LaTeX/ConTeXt%<<<1
%% thanks to Henri Menke https://github.com/circuitikz/circuitikz/issues/285#issuecomment-537224605

\ifpgfutil@format@is@latex
    \long\def\pgf@circ@font@tiny{\tiny}
    \long\def\pgf@circ@font@small{\small}
    \long\def\pgf@circ@font@bold{\textbf}
    \long\def\pgf@circ@font@boldmath{\boldmath}
    \long\def\pgf@circ@font@sixbm{\fontsize{6}{7}\selectfont\boldmath}
    \long\def\pgf@circ@font@tenbm{\fontsize{10}{12}\selectfont\boldmath}
    \long\def\pgf@circ@font@twelve{\fontsize{12}{14}\selectfont}
\else\ifpgfutil@format@is@plain
    \long\def\pgf@circ@font@tiny{\fiverm}
    \long\def\pgf@circ@font@small{\sevenrm}
    \long\def\pgf@circ@font@bold#1{{\bf#1}}
    \long\def\pgf@circ@font@boldmath{\bf}       % to be tested
    \long\def\pgf@circ@font@sixbm{\sevenrm\bf}  %
    \long\def\pgf@circ@font@tenbm{\tenrm\bf}    %
    \long\def\pgf@circ@font@twelve{\twelverm}   %
\else\ifpgfutil@format@is@context
    \long\def\pgf@circ@font@tiny{\tfxx}
    \long\def\pgf@circ@font@small{\tfx}
    \long\def\pgf@circ@font@bold{\bold}
    \long\def\pgf@circ@font@boldmath{\bold}    % to be tested
    \long\def\pgf@circ@font@sixbm{\tfx\bold}   %
    \long\def\pgf@circ@font@tenbm{\normal\bold}%
    \long\def\pgf@circ@font@twelve{\tfa}       %
\fi\fi\fi
% noop
\def\pgfcirc@nop#1{#1}% no operation, just strip {}
%
%
% Thanks to Phelype Oleinik https://tex.stackexchange.com/a/520806/38080
%
% this is needed to avoid problems with \ConTeXt
\ifcsname normalunexpanded\endcsname
  \let\pgfcircutil@unexpanded\normalunexpanded
\else
  \let\pgfcircutil@unexpanded\unexpanded
\fi
% minimally expand a pgfkey to check if it's {}/undefined or filled.
\def\unexpandedvalueof#1{%
  \pgfcircutil@unexpanded\expandafter\expandafter
    \expandafter\pgf@circ@valueof@chk\pgfkeysvalueof{#1}}
\def\pgf@circ@valueof@chk#1{%
  \ifx\relax#1%
    \expandafter\pgfutil@firstoftwo
  \else
    \expandafter\pgfutil@secondoftwo
  \fi
    {{}}% #1 is \relax, so consider empty
    {\expandafter{#1}}% otherwise, leave the key after one more expansion
}%
%>>>

%% Generic macro for defining a bipole shape%<<<
% #1 - additional anchors
% #2 - lower y-size of the bipole (from the center).
% #3 - #shape is the name of the shape
% #4 - upper y-size of the bipole (from the center)
% #5 - width of the bipole
% #6 - macros drawing the bipole
%
\long\def\pgfcircdeclarebipole{%
    \pgfcircdeclarebipolescaled{default}}

%% Generic macro for defining a bipole shape
% #1 - scale factor
% #2 - additional anchors
% #3 - lower y-size of the bipole (from the center).
% #4 - #shape is the name of the shape
% #5 - upper y-size of the bipole (from the center)
% #6 - width of the bipole
% #7 - macros drawing the bipole
%
\long\def\pgfcircdeclarebipolescaled#1#2#3#4#5#6#7{
    \pgfdeclareshape{#4shape}{
        \savedmacro{\ctikzclass}{\edef\ctikzclass{#1}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \savedanchor{\northeast}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@y=#5\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@x=#6\pgf@circ@scaled@Rlen
            \pgf@x=.5\pgf@x
        }
        \savedanchor{\northeastborder}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@y=#5\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@y=\ctikzvalof{bipoles/border margin}\pgf@y
            \pgf@x=#6\pgf@circ@scaled@Rlen
            \pgf@x=.5\pgf@x
            \pgf@x=\ctikzvalof{bipoles/border margin}\pgf@x
        }
        \savedanchor{\southwestborder}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@y=-#3\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@y=\ctikzvalof{bipoles/border margin}\pgf@y
            \pgf@x=-#6\pgf@circ@scaled@Rlen
            \pgf@x=.5\pgf@x
            \pgf@x=\ctikzvalof{bipoles/border margin}\pgf@x
        }
        \savedanchor{\southwest}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@y=-#3\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@x=-#6\pgf@circ@scaled@Rlen
            \pgf@x=.5\pgf@x
        }
        \savedanchor{\centerpoint}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@circ@res@down=-#3\pgf@circ@scaled@Rlen
            \pgf@circ@res@up=#5\pgf@circ@scaled@Rlen
            \pgfpointorigin
            \pgf@y=\pgf@circ@res@up
            \advance\pgf@y by\pgf@circ@res@down
            \pgf@y=.5\pgf@y
        }
        \anchor{center}{\pgfpointorigin}
        \anchor{n}{
            \northeast
            \pgf@x=0cm
        }
        \anchor{north east}{
            \northeast
        }
        \anchor{north west}{
            \northeast
            \pgf@x=-\pgf@x
        }
        \anchor{ne}{
            \northeast
        }
        \anchor{nw}{
            \northeast
            \pgf@x=-\pgf@x
        }
        \anchor{e}{
            \northeast
            \pgf@y=0cm
        }
        \anchor{s}{
            \southwest
            \pgf@x=0cm
        }
        \anchor{south east}{
            \southwest
            \pgf@x=-\pgf@x
        }
        \anchor{south west}{
            \southwest
        }
        \anchor{se}{
            \southwest
            \pgf@x=-\pgf@x
        }
        \anchor{sw}{
            \southwest
        }
        \anchor{w}{
            \southwest
            \pgf@y=0cm
        }
        \anchor{north}{
            \northeast
            \pgf@x=0cm
        }
        \anchor{east}{
            \northeast
            \pgf@y=0cm
        }
        \anchor{south}{
            \southwest
            \pgf@x=0cm
        }
        \anchor{west}{
            \southwest
            \pgf@y=0cm
        }
        \anchor{right}{
            \northeast
            \pgf@y=0cm
        }
        \anchor{above}{
            \northeast
            \pgf@x=0cm
        }
        \anchor{left}{
            \southwest
            \pgf@y=0cm
        }
        \anchor{below}{
            \southwest
            \pgf@x=0cm
        }
        \anchor{a}{
            \northeast
            \pgf@y=0cm
        }
        \anchor{b}{
            \southwest
            \pgf@y=0cm
        }
        \savedanchor{\textanchor}{%
            \pgf@y=\ht\pgfnodeparttextbox
            \pgf@x=-.5\wd\pgfnodeparttextbox
        }
        \anchor{text}{
            \textanchor
        }
        \anchorborder{%
            \ifpgf@circuit@bipole@inverted
                \pgf@circ@res@left=-\pgf@x
                \pgf@circ@res@up=-\pgf@y
            \else
                \pgf@circ@res@left=\pgf@x
                \pgf@circ@res@up=\pgf@y
            \fi
            \ifdim\pgf@circ@res@up>0cm
                \pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\northeastborder}
            \else
                \southwestborder
                \pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{-\pgf@x}{-\pgf@y}}
            \fi
        }
        #2%
        \pgf@circ@draw@component{
            \pgf@circ@setcolor

            \northeast
            \pgf@circ@res@up = \pgf@y
            \pgf@circ@res@zero = 0cm
            \pgf@circ@res@left = -\pgf@x
            \pgf@circ@res@right = \pgf@x
            \southwest
            \pgf@circ@res@down = \pgf@y
            \pgf@circ@scaled@Rlen=\scaledRlen
            \pgfstartlinewidth=\pgflinewidth
            % we used to reset arced corners here --- now it's in the hooks. I hope.
            #7%
            \pgfsetlinewidth{\pgfstartlinewidth}
        }
    }
}% %>>>

%% anchor adjustment macros%<<<

% Extend the border anchor position by the specified factors on the right-top (north east corner)
% and the left-down (southwest border). Argument must be number (possibly decimal) without sign

\def\pgfcirc@border@extend@full#1#2#3#4{% right, top, left, down
    \anchorborder{%
        \ifpgf@circuit@bipole@inverted
            \pgf@circ@res@left=-\pgf@x
            \pgf@circ@res@up=-\pgf@y
        \else
            \pgf@circ@res@left=\pgf@x
            \pgf@circ@res@up=\pgf@y
        \fi
        \ifdim\pgf@circ@res@up>0cm
            \northeastborder
            \pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{#1\pgf@x}{#2\pgf@y}}
        \else
            \southwestborder
            \pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{-#3\pgf@x}{-#4\pgf@y}}
        \fi
    }
}

% Just up and down (very common)
\def\pgfcirc@border@extend@updown#1#2{\pgfcirc@border@extend@full{1}{#1}{1}{#2}}%


% set of symmetrical, geographical anchors when a \northwest saved anchor is available
\long\def\pgfcirc@northwest@symmetric@geoanchors{%
    \anchor{right}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{east}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{e}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{left}{\northwest\pgf@y=0pt}
    \anchor{west}{\northwest\pgf@y=0pt}
    \anchor{w}{\northwest\pgf@y=0pt}
    \anchor{south}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{s}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{north}{\northwest\pgf@x=0pt}
    \anchor{n}{\northwest\pgf@x=0pt}
    \anchor{south west}{\northwest\pgf@y=-\pgf@y}
    \anchor{sw}{\northwest\pgf@y=-\pgf@y}
    \anchor{north east}{\northwest\pgf@x=-\pgf@x}
    \anchor{ne}{\northwest\pgf@x=-\pgf@x}
    \anchor{north west}{\northwest}
    \anchor{nw}{\northwest}
    \anchor{south east}{\northwest\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
    \anchor{se}{\northwest\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
}
% the same, when we have \northeast (I know...)
\long\def\pgfcirc@northeast@symmetric@geoanchors{%
    \anchor{north}{\northeast\pgf@x=0cm\relax}
    \anchor{n}{\northeast\pgf@x=0cm\relax}
    \anchor{east}{\northeast\pgf@y=0cm\relax}
    \anchor{e}{\northeast\pgf@y=0cm\relax}
    \anchor{right}{\northeast\pgf@y=0cm\relax}
    \anchor{south}{\northeast\pgf@y=-\pgf@y \pgf@x=0cm\relax}
    \anchor{s}{\northeast\pgf@y=-\pgf@y \pgf@x=0cm\relax}
    \anchor{west}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x}
    \anchor{w}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x}
    \anchor{left}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x}
    \anchor{north east}{\northeast}
    \anchor{ne}{\northeast}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \anchor{nw}{\northeast\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast\pgf@y=-\pgf@y}
    \anchor{se}{\northeast\pgf@y=-\pgf@y}
    \anchor{south west}{\northeast\pgf@y=-\pgf@y\pgf@x=-\pgf@x}
    \anchor{sw}{\northeast\pgf@y=-\pgf@y\pgf@x=-\pgf@x}
}
%>>>

%% text position in some component.%<<<1
% (added with ieeestd logic ports. Maybe to be extended to other components,
% like amplifiers)
%
\newif\ifpgf@circ@center@text\pgf@circ@center@texttrue
\tikzset{component text/.is choice}%
\tikzset{component text/center/.code={\pgf@circ@center@texttrue}}%
\tikzset{component text/left/.code={\pgf@circ@center@textfalse}}%
\ctikzset{component text/.is choice}%
\ctikzset{component text/center/.code={\pgf@circ@center@texttrue}}%
\ctikzset{component text/left/.code={\pgf@circ@center@textfalse}}%
\ctikzset{left text distance/.initial=0.3em}%
%>>>

%% voltage direction options%<<<1

\newif\ifpgf@circ@oldvoltagedirection % default false
\newif\ifpgf@circ@explicitvdir
\newif\ifpgf@circ@fixbatteries

\ctikzset{voltage dir/.is choice}
\ctikzset{voltage dir/old/.code={\pgf@circ@oldvoltagedirectiontrue\pgf@circ@fixbatteriesfalse}}
\ctikzset{voltage dir/noold/.code={\pgf@circ@oldvoltagedirectionfalse\pgf@circ@fixbatteriesfalse}}
\ctikzset{voltage dir/RP/.code={\pgf@circ@oldvoltagedirectiontrue\pgf@circ@fixbatteriestrue}}
\ctikzset{voltage dir/EF/.code={\pgf@circ@oldvoltagedirectionfalse\pgf@circ@fixbatteriestrue}}
\tikzset{voltage dir/.style={circuitikz/voltage dir=#1}}%
%>>>

%% bipole definitions for path component and text decorations%%<<<1
%
% Option "t=*" for nodes
\pgfkeys{/tikz/t/.add code={}{\ctikzset{text=#1}}}
\pgfkeys{/tikz/t1/.add code={}{\ctikzset{text in=#1}}}
\pgfkeys{/tikz/t2/.add code={}{\ctikzset{text out=#1}}}
%
\ctikzset{bipole/.is family}
\ctikzset{bipole/kind/.initial=}
\ctikzset{bipole/name/.initial=}
\newif\ifpgf@circuit@bipole@isvoltage
\ctikzset{bipole/is voltage/.is if=pgf@circuit@bipole@isvoltage}
\newif\ifpgf@circuit@bipole@override@source@vif
\ctikzset{bipole/override source vif/.is if=pgf@circuit@bipole@override@source@vif}
\newif\ifpgf@circuit@bipole@voltageoutsideofsymbol
\ctikzset{bipole/is voltageoutsideofsymbol/.is if=pgf@circuit@bipole@voltageoutsideofsymbol}
\newif\ifpgf@circuit@bipole@strokedsymbol
\ctikzset{bipole/is strokedsymbol/.is if=pgf@circuit@bipole@strokedsymbol}
\newif\ifpgf@circuit@bipole@iscurrent
\ctikzset{bipole/is current/.is if=pgf@circuit@bipole@iscurrent}

\ctikzset{bipole/voltage/.is family}
\newif\ifpgf@circuit@bipole@voltage@backward
\ctikzset{bipole/voltage/direction/.is choice}
\ctikzset{bipole/voltage/direction/forward/.code={\pgf@circuit@bipole@voltage@backwardfalse}}
\ctikzset{bipole/voltage/direction/backward/.code={\pgf@circuit@bipole@voltage@backwardtrue}}
\newif\ifpgf@circuit@bipole@voltage@below
\ctikzset{bipole/voltage/position/.is choice}
\ctikzset{bipole/voltage/position/above/.code={\pgf@circuit@bipole@voltage@belowfalse}}
\ctikzset{bipole/voltage/position/below/.code={\pgf@circuit@bipole@voltage@belowtrue}}

\ctikzset{bipole/voltage/label/unit/.initial=}
\ctikzset{bipole/voltage/label/name/.initial=}

\ctikzset{bipole/current/.is family}
\newif\ifpgf@circuit@bipole@current@backward
\ctikzset{bipole/current/direction/.is choice}
\ctikzset{bipole/current/direction/forward/.code={\pgf@circuit@bipole@current@backwardfalse}}
\ctikzset{bipole/current/direction/backward/.code={\pgf@circuit@bipole@current@backwardtrue}}
\newif\ifpgf@circuit@bipole@current@before
\ctikzset{bipole/current/x position/.is choice}
\ctikzset{bipole/current/x position/after/.code={\pgf@circuit@bipole@current@beforefalse}}
\ctikzset{bipole/current/x position/before/.code={\pgf@circuit@bipole@current@beforetrue}}
\newif\ifpgf@circuit@bipole@current@below
\ctikzset{bipole/current/y position/.is choice}
\ctikzset{bipole/current/y position/above/.code={\pgf@circuit@bipole@current@belowfalse}}
\ctikzset{bipole/current/y position/below/.code={\pgf@circuit@bipole@current@belowtrue}}
\ctikzset{bipole/current/label/unit/.initial=}
\ctikzset{bipole/current/label/name/.initial=}

\ctikzset{bipole/flow/.is family}
\newif\ifpgf@circuit@bipole@flow@backward
\ctikzset{bipole/flow/direction/.is choice}
\ctikzset{bipole/flow/direction/forward/.code={\pgf@circuit@bipole@flow@backwardfalse}}
\ctikzset{bipole/flow/direction/backward/.code={\pgf@circuit@bipole@flow@backwardtrue}}
\newif\ifpgf@circuit@bipole@flow@before
\ctikzset{bipole/flow/x position/.is choice}
\ctikzset{bipole/flow/x position/after/.code={\pgf@circuit@bipole@flow@beforefalse}}
\ctikzset{bipole/flow/x position/before/.code={\pgf@circuit@bipole@flow@beforetrue}}
\newif\ifpgf@circuit@bipole@flow@below
\ctikzset{bipole/flow/y position/.is choice}
\ctikzset{bipole/flow/y position/above/.code={\pgf@circuit@bipole@flow@belowfalse}}
\ctikzset{bipole/flow/y position/below/.code={\pgf@circuit@bipole@flow@belowtrue}}
\ctikzset{bipole/flow/label/unit/.initial=}
\ctikzset{bipole/flow/label/name/.initial=}
\ctikzset{flow/distance/.initial = .5}
\ctikzset{flow/offset/.initial = .2}%distance between flow-arrow and conductor

\ctikzset{bipole/label/.is family}
\ctikzset{bipole/label/position/.initial=90}
\ctikzset{bipole/label/unit/.initial=}
\ctikzset{bipole/label/name/.initial=}
\ctikzset{bipole/annotation/.is family}
\ctikzset{bipole/annotation/position/.initial=-90}
\ctikzset{bipole/annotation/unit/.initial=}
\ctikzset{bipole/annotation/name/.initial=}


\ctikzset{label/align/.is choice}
\ctikzset{label/align/straight/.code={\ctikzsetvalof{label/align}{straight}}}
\ctikzset{label/align/rotate/.code={\ctikzsetvalof{label/align}{rotate}}}
\ctikzset{label/align/smart/.code={\ctikzsetvalof{label/align}{smart}}}
%%>>>

%% traditional styles %<<<1
%
\ctikzset{thickness/.initial=2}
\ctikzset{bipoles/border margin/.initial=1.1}
\ctikzset{bipoles/thickness/.initial=2}
\ctikzset{tripoles/thickness/.initial=2}
\ctikzset{quadpoles/thickness/.initial=2}
\ctikzset{nodes width/.initial=.04}
%%>>>

%% Styles definitions and macros%<<<1

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% main style definitions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% load a style file: search ctikzstyle-NAME.tex in path
\def\ctikzloadstyle#1{%
    \pgfutil@InputIfFileExists{ctikzstyle-#1}{}{%
        \tikzerror{I did not find the circuitikz style #1}}%
}

% load and enact a style
\def\ctikzsetstyle#1{%
    \ctikzloadstyle{#1}%
    \tikzset{#1 circuit style}%
}

% global style parameters
\ctikzset{default/scale/.initial=1.0}   % do not touch
\ctikzset{default/fill/.initial=none}   % do not touch
\ctikzset{default/thickness/.initial=none}   % do not touch
% default is use as the generic default style for bipoles

% mostly bipoles:

\ctikzset{resistors/scale/.initial=1.0}
\ctikzset{resistors/fill/.initial=none}
\ctikzset{resistors/thickness/.initial=none}
\ctikzset{resistors/modifier thickness/.initial=1}% relative to main thickness

\ctikzset{capacitors/scale/.initial=1.0}
\ctikzset{capacitors/fill/.initial=none}
\ctikzset{capacitors/thickness/.initial=none}
\ctikzset{capacitors/modifier thickness/.initial=1}

\ctikzset{inductors/scale/.initial=1.0}
\ctikzset{inductors/fill/.initial=none}
\ctikzset{inductors/thickness/.initial=none}
\ctikzset{inductors/modifier thickness/.initial=1}

\ctikzset{diodes/scale/.initial=1.0}
\ctikzset{diodes/fill/.initial=none}
\ctikzset{diodes/thickness/.initial=none}
% we define opto arrows style here because they are used also
% in transistors
\ctikzset{opto arrows/.is family}
\ctikzset{opto arrows/relative thickness/.initial=1}
\ctikzset{opto arrows/color/.initial=default}
\ctikzset{opto arrows/dash/.initial=default}
\def\pgf@circ@set@optoarrow@style{%
    % You *must* be sure that this is called inside a \pgfscope!
    \pgfsetlinewidth{\ctikzvalof{opto arrows/relative thickness}\pgflinewidth}
        \pgf@circ@subset@color@dash{opto arrows}
        \pgfcirc@set@arrows{opto}{}{latexslim}
    }

\ctikzset{batteries/scale/.initial=1.0}
\ctikzset{batteries/fill/.initial=none}
\ctikzset{batteries/thickness/.initial=none}

\ctikzset{sources/scale/.initial=1.0}
\ctikzset{sources/fill/.initial=none}
\ctikzset{sources/thickness/.initial=none}

\ctikzset{csources/scale/.initial=1.0}
\ctikzset{csources/fill/.initial=none}
\ctikzset{csources/thickness/.initial=none}

\ctikzset{instruments/scale/.initial=1.0}
\ctikzset{instruments/fill/.initial=none}
\ctikzset{instruments/thickness/.initial=none}

\ctikzset{mechanicals/scale/.initial=1.0}
\ctikzset{mechanicals/fill/.initial=none}
\ctikzset{mechanicals/thickness/.initial=none}

\ctikzset{misc/scale/.initial=1.0}
\ctikzset{misc/fill/.initial=none}
\ctikzset{misc/thickness/.initial=none}

\ctikzset{blocks/scale/.initial=1.0}
\ctikzset{blocks/fill/.initial=none}
\ctikzset{blocks/thickness/.initial=none}

% mostly nodes

\ctikzset{grounds/scale/.initial=1.0}
\ctikzset{grounds/fill/.initial=none}
\ctikzset{grounds/thickness/.initial=none}

\ctikzset{power supplies/scale/.initial=1.0}
\ctikzset{power supplies/fill/.initial=none}
\ctikzset{power supplies/thickness/.initial=none}

\ctikzset{transistors/scale/.initial=1.0}
\ctikzset{transistors/fill/.initial=none}
\ctikzset{transistors/thickness/.initial=none}
\ctikzset{transistors/modifier thickness/.initial=1}% relative to main thickness

\ctikzset{tubes/scale/.initial=1.0}
\ctikzset{tubes/fill/.initial=none}
\ctikzset{tubes/thickness/.initial=none}

\ctikzset{RF/scale/.initial=1.0}
\ctikzset{RF/fill/.initial=none}
\ctikzset{RF/thickness/.initial=none}

\ctikzset{electromechanicals/scale/.initial=1.0}
\ctikzset{electromechanicals/fill/.initial=none}
\ctikzset{electromechanicals/thickness/.initial=none}

% transformers go with inductors
\ctikzset{amplifiers/scale/.initial=1.0}
\ctikzset{amplifiers/fill/.initial=none}
\ctikzset{amplifiers/thickness/.initial=none}

\ctikzset{switches/scale/.initial=1.0}
\ctikzset{switches/fill/.initial=none}
\ctikzset{switches/thickness/.initial=none}

\ctikzset{logic ports/scale/.initial=1.0}
\ctikzset{logic ports/fill/.initial=none}
\ctikzset{logic ports/thickness/.initial=none}

\ctikzset{flipflops/scale/.initial=1.0}
\ctikzset{flipflops/fill/.initial=none}
\ctikzset{flipflops/thickness/.initial=none}

\ctikzset{muxdemuxes/scale/.initial=1.0}
\ctikzset{muxdemuxes/fill/.initial=none}
\ctikzset{muxdemuxes/thickness/.initial=none}

\ctikzset{chips/scale/.initial=1.0}
\ctikzset{chips/fill/.initial=none}
\ctikzset{chips/thickness/.initial=none}

\ctikzset{displays/scale/.initial=1.0}
\ctikzset{displays/fill/.initial=none}
\ctikzset{displays/thickness/.initial=none}
%
% general styles
%
\tikzset{european/.style = {european currents, european voltages, european resistors, european inductors, european ports, european gas filled surge arrester set}}
\tikzset{american/.style = {american currents, american voltages, american resistors, american inductors, american ports, american gas filled surge arrester set}}
\tikzset{cute/.style = {european currents, european voltages, american resistors, cute inductors, american ports}}
%%>>>

%% voltage and current options%<<<1
%
\ctikzset{current arrow scale/.initial=16}
\ctikzset{current/distance/.initial = .5}

\newif\ifpgf@circuit@europeancurrent
\newif\ifpgf@circuit@europeanvoltage
\newif\ifpgf@circuit@bipole@voltage@straight
\newif\ifpgf@circuit@bipole@voltage@raised

\ctikzset{voltage/.is choice}
%
% straight is expected to be a subset of european, so disable it in american style
%
\ctikzset{voltage/american/.code = {%
    \pgf@circuit@europeanvoltagefalse
    \pgf@circuit@bipole@voltage@straightfalse
    \pgf@circuit@bipole@voltage@raisedfalse
}}
\ctikzset{voltage/raised/.code = {%
    \pgf@circuit@europeanvoltagefalse
    \pgf@circuit@bipole@voltage@straightfalse
    \pgf@circuit@bipole@voltage@raisedtrue
}}
\ctikzset{voltage/european/.code = {%
    \pgf@circuit@europeanvoltagetrue
    \pgf@circuit@bipole@voltage@straightfalse
    \pgf@circuit@bipole@voltage@raisedfalse
}}
\ctikzset{voltage/straight/.code = {%
    \pgf@circuit@europeanvoltagetrue
    \pgf@circuit@bipole@voltage@straighttrue
    \pgf@circuit@bipole@voltage@raisedfalse
}}
\ctikzset{voltage/curved/.code = {%
    \pgf@circuit@europeanvoltagetrue
    \pgf@circuit@bipole@voltage@straightfalse
    \pgf@circuit@bipole@voltage@raisedfalse
}}
% are these used?
\ctikzset{current/.is choice}
\ctikzset{current/american/.code = \pgf@circuit@europeancurrentfalse}
\ctikzset{current/european/.code = \pgf@circuit@europeancurrenttrue}

% this is left for backward compatibility...
\ctikzset{straight/.is choice}
\ctikzset{straight/true/.code = {\pgf@circuit@bipole@voltage@straighttrue}}
\ctikzset{straight/false/.code = {\pgf@circuit@bipole@voltage@straightfalse}}
\ctikzset{bipole/straight/.is if=pgf@circuit@bipole@voltage@straight}
%
% voltage is used also to set parameters, apart for the /.is choice
% above. I hope it is ok --- would be a mess otherwise
%
\ctikzset{voltage/shift/.initial=0.0} % shift form the cable of voltage symbols
\ctikzset{voltage shift/.style={\circuitikzbasekey/voltage/shift=#1}}
\tikzset{voltage shift/.style={\circuitikzbasekey/voltage/shift=#1}}
%
% keys for exporting voltage, current, flow anchors
%
\newif\ifpgfcirc@has@v\pgfcirc@has@vfalse
\newif\ifpgfcirc@has@f\pgfcirc@has@ffalse
\newif\ifpgfcirc@has@i\pgfcirc@has@ifalse
\def\ctikzgetanchor#1#2{\csname pgfcirc@#1-#2-anchor\endcsname}
\def\ctikzgetdirection#1{\csname pgfcirc@#1-direction\endcsname}
%
% shaping the +/- sign, see pgfcircvoltage.tex
\ctikzset{voltage/american font/.initial={}}
\ctikzset{voltage/american plus/.initial={$+$}}
% In the mayority of fonts, the size of - is smaller than +, so we have
% unaligned signs when positioned independently.
% See https://github.com/circuitikz/circuitikz/issues/721
\ctikzset{voltage/american minus/.initial={$\vphantom{+}-$}}
% here we start the voltage adjustments for special components.
% default values:
%
% this is the distance of the "point" marking the voltage along the line
% 0.0 is on the external nodes of the to path
% 1.0 is cramped on the object
% this can be overriden component by component
\ctikzset{voltage/distance from node/.initial=.5}% pos, 0->1
%
% this is the distance from the line (perpendicular to) where the voltage is drawn.
% It is global, and not adjustable by component (use the "label distance" or locally
% if you need it)
\ctikzset{voltage/distance from line/.initial=.08}% in \pgf@circ@scaled@Rlen units
%
% bend paramenters for european arc. You can override them component-based
\ctikzset{voltage/bump b/.initial=1.5}
%
% generator voltages symbols or arrows (always straight) are put along the
% 60 ... 120 angles of the symbol (don't ask why). The distance here is on the
% center..angle line. It's called bump a because I don't know...
%
\ctikzset{voltage/bump a/.initial=1.2}
%
% these are the label distances FROM the drawings.
% You can override them component by component.
\ctikzset{voltage/european label distance/.initial=1.4}
\ctikzset{voltage/straight label distance/.initial=1.4}
\ctikzset{voltage/american label distance/.initial=1.4}
% american open voltage adjusting
%
\newif\ifpgf@adjust@open@voltage\pgf@adjust@open@voltagetrue
\ctikzset{open voltage position/.is choice}
\ctikzset{open voltage position/center/.code={\pgf@adjust@open@voltagetrue}}
\ctikzset{open voltage position/legacy/.code={\pgf@adjust@open@voltagefalse}}
% bad names, kept for compatibility, don't use
\ctikzset{american open voltage/.is choice}
\ctikzset{american open voltage/center/.code={\pgf@adjust@open@voltagetrue}}
\ctikzset{american open voltage/legacy/.code={\pgf@adjust@open@voltagefalse}}
%
% voltage and current styles
%
\tikzset{american currents/.style = {\circuitikzbasekey/current = american}}
\tikzset{european currents/.style = {\circuitikzbasekey/current = european}}
\tikzset{american voltages/.style = {\circuitikzbasekey/voltage = american}}
\tikzset{european voltages/.style = {\circuitikzbasekey/voltage = european}}
\tikzset{straight voltages/.style = {\circuitikzbasekey/voltage = straight}}
\tikzset{raised voltages/.style = {\circuitikzbasekey/voltage = raised}}
%%>>>

% vim: set fdm=marker fmr=%<<<,%>>>:
%%%---------- close: tex/pgfcirc.defines
%%%%%%%%%%% Springe nach tex/pgfcircutils
%%%---------- open: tex/pgfcircutils.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.

\def\pgf@circ@handleSI#1{
    \noexpandarg
    \def\pgf@temp{}
    \StrBetween{#1}{<}{>}[\pgf@circ@handleSI@unit]
    \StrLen{\pgf@circ@handleSI@unit}[\pgf@circ@handleSI@unit@len]

    \ifnum\pgf@circ@handleSI@unit@len=0
    \pgf@circ@siunitx@resfalse
    \else
    \IfEndWith{#1}{>}{
        \pgf@circ@siunitx@restrue
        \noexpandarg
        \StrBefore{#1}{<}[\pgf@circ@handleSI@val]
        %\typeout{si |#1|}
        }{
        \pgf@circ@siunitx@resfalse
        %\typeout{no si |#1|}
    }
\fi
}

\def\pgf@circ@ifkeyempty#1{
    \pgfextra{
        \ctikzset{#1/.get=\pgf@circ@temp}
        \edef\pgf@temp{}
    }
    \ifx\pgf@circ@temp\pgf@temp
    }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%    Math routines

\def\pgf@circ@stripdecimals#1.#2\pgf@nil{#1}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% useful commands

\ifpgfutil@format@is@latex
    %% flipping text
    \def\ctikzflipx#1{\scalebox{-1}[1]{#1}}
    \def\ctikzflipy#1{\scalebox{1}[-1]{#1}}
    \def\ctikzflipxy#1{\scalebox{-1}[-1]{#1}}
    % text mode overbar
    % Thanks to @egreg https://tex.stackexchange.com/a/24133/38080
    \def\ctikztextnot#1{$\overline{\hbox{#1}}\m@th$}
\else\ifpgfutil@format@is@plain
    % text mode overbar
    % but really circuitikz will not work in plain...
    % Thanks to @egreg https://tex.stackexchange.com/a/24133/38080
    \def\ctikztextnot#1{$\overline{\hbox{#1}}$}
\else\ifpgfutil@format@is@context
    %% flipping text
    \def\ctikzflipx#1{\mirror{#1}}
    \def\ctikzflipy#1{\mirror{\rotate[rotation=180]{#1}}}
    \def\ctikzflipxy#1{\rotate[rotation=180]{#1}}
    % text mode overbar
    % Thanks to @egreg https://tex.stackexchange.com/a/24133/38080
    \def\ctikztextnot#1{$\overline{\hbox{#1}}$}
\fi\fi\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% switch to use fpu in reciprocal scale transformations
%%
%% this code has been contributed by Schrödinger's cat
%% https://tex.stackexchange.com/a/529159/38080
%%
%% Use the official key to use the fpu if installed, see
%% https://github.com/pgf-tikz/pgf/issues/861
%%
%% Thanks to "muzimuzhi Z" https://tex.stackexchange.com/a/547085/38080
%% Thanks to Henri Menke for a faster approach https://github.com/circuitikz/circuitikz/commit/00966c45c42b464fab5429f89f2b7fb414e9b3f7#commitcomment-54592494
%%
\pgfkeysifdefined{/pgf/fpu/install only/.@cmd}{%
    \pgfqkeys{/pgf}{use fpu reciprocal/.code={\pgfkeys{/pgf/fpu/install only={reciprocal}}}}%
    }{%
    \pgfkeysifdefined{/pgf/use fpu reciprocal/.@cmd}{% use stock one
        }{
        \pgfqkeys{/pgf}{use fpu reciprocal/.code={%
                \def\pgfmathreciprocal@##1{%
                    \begingroup
                    \pgfmathfloatparsenumber{##1}%
                    \pgfmathfloatreciprocal@{\pgfmathresult}%
                    \pgfmathfloattofixed@{\pgfmathresult}%
                    \pgfmath@smuggleone\pgfmathresult
                    \endgroup
    }}}}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% subcircuits (experimental)
%%
%% introduced by Romano Giannetti around April 2021
%% changes suggested by Jonathan P. Spratte
%%
\newbox\ctikz@scratchbox
\pgfutil@protected\def\ctikzsubcircuitdef#1#2#3{%
    \expandafter\gdef\csname #1@Anchor\endcsname{}%
    \expandafter\gdef\csname #1@setanchors\endcsname{%
        \setbox\ctikz@scratchbox=\hbox{%
        \tikzpicture
        \draw (0,0) \csname#1\endcsname{T-#1}{};
        \foreach [count=\i] \anchor in {#2}
        % reference anchor is -center
        \draw (0,{2-\i/2}) let \p1 = ($(T-#1-subckt@reference)-(T-#1-\anchor)$) in
            node[right]{\anchor: \x1,\y1 \expandafter\xdef\csname #1@Anchor\anchor\endcsname{++(\x1,\y1)}};
        \endtikzpicture
        }%
    }%
    \expandafter\gdef\csname#1\endcsname##1##2{%
        \csname #1@Anchor##2\endcsname coordinate(##1-subckt@reference)#3%
    }%
}
\long\def\ctikzsubcircuitactivate#1{\csname #1@setanchors\endcsname}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Basic utility macros
%%
%% Functions provided here are:
%%  \pgf@circ@ifempty{<argument>}{<true>}{<false>}
%%    Tests whether <argument> is completely empty.
%%  \pgf@circ@ifblank{<argument>}{<true>}{<false>}
%%    Tests whether <argument> is either empty or only contains spaces.
%%  \pgf@circ@trimspaces@do{<argument>}{<next>}
%%    Trims at most one space from either end of <argument> and forwards the
%%    result to <next> as <next>{<trimmed argument>}

% these two are pretty standard code
\long\def\pgf@circ@ifempty#1%
  {%
    \if\relax\detokenize{#1}\relax
      \expandafter\pgfutil@firstoftwo
    \else
      \expandafter\pgfutil@secondoftwo
    \fi
  }
\long\def\pgf@circ@ifblank#1%
  {%
    \if\relax\detokenize\expandafter{\pgfutil@gobble#1.}\relax
      \expandafter\pgfutil@firstoftwo
    \else
      \expandafter\pgfutil@secondoftwo
    \fi
  }

% \pgfutil@trimspaces needs two expansions. The first expansion we'll do during
% the definition.
\def\pgf@circ@trimspaces@do#1%
  {%
    \def\pgf@circ@trimspaces@do##1%
      {\expandafter\pgf@circ@trimspaces@do@\expandafter{#1}}%
  }
\expandafter\pgf@circ@trimspaces@do\expandafter{\pgfutil@trimspaces{#1}}
\def\pgf@circ@trimspaces@do@#1#2{#2{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% list handling
%%
%% Contribution by Jonathan P. Spratte (blame him!)
%%
%% The list implementation here has a few limitations. Those are:
%%  1. not long, so no \par in the lists (but many used functions in pgfutil
%%     aren't long as well)
%%  2. list elements can't contain a Q with category code 3 (but the used
%%     function \pgfutil@trimspaces doesn't support them as well, and this
%%     should be a very rare token anyway)
%%  3. list elements can't contain the token \pgf@circ@set@list as that is used
%%     as the end marker
%%  4. currently these lists are meant for numeric data (hence only
%%     \pgf@circ@if@num@in@list is provided as a test), as a result there is
%%     another limitation for the data here. If the list element contains no
%%     hyphen '-', the element will be stored without further processing
%%     'as-is' (well, after trimming spaces). If there is a hyphen we assume
%%     well-behaved input data and will interpret this as a num-range without
%%     further tests.
%%
%% Functions provided here are:
%%  \pgf@circ@set@list<macro>{<csv-list>}
%%    Parses the <csv-list> and stores the result inside <macro> (local
%%    assignment). If a num-range given as <start - stop> (with or without
%%    spaces) is found it will be expanded to <start>,<start+1>,...,<stop>.
%%  \pgf@circ@if@num@in@list<macro>{<value>}{<true>}{<false>}
%%    Checks whether <value> (numeric value, evaluated once with \numexpr) is
%%    found inside the list stored in <macro>. There are two special cases: If
%%    <macro> is undefined <false> is executed. If the list contains only one
%%    element and that is `all' <true> is executed.

% set the catcode of our marker
\chardef\pgf@circ@temp=\the\catcode`\Q
\catcode`\Q=3

% lists will have the structure
% <marker><element 1><marker>...<element n><marker>
% As marker we use a Q with category 3. Under the assumption that no list
% element does ever contain that token we can set the elements without braces,
% allowing us to use \pgfutil@in@ to search for elements (see above). The other
% token that isn't allowed to show up in the list is \pgf@circ@set@list, that we
% use as another marker during parsing.
% The other big restriction in this implementation is that lists can't contain a
% \par (but \pgfutil@in@ doesn't support that anyway so there is not much
% sense in supporting it here)
\pgfutil@protected\def\pgf@circ@set@list#1#2%
  {%
    % clear the error flag
    \let\pgf@circ@error@marker\pgf@circ@undefined
    % set the list
    \edef#1%
      {Q\pgf@circ@set@list@sanitize#2,\pgf@circ@set@list,\pgf@circ@set@list}%
    % there was an error, throw the error message, recovery was already done by
    % ignoring the offending elements.
    \ifx\pgf@circ@error@marker\relax
      \begingroup
        \newlinechar`\^^J
        \pgfutil@packageerror{circuitikz}
          {%
            Unallowed marker found in list^^J%
            \pgfutil@unexpanded{#2}.^^J%
            Offending elements were ignored.%
          }
          {Lists can't contain a Q with category code 3}%
      \endgroup
    \fi
  }
% just a utility for the <marker> test
\def\pgf@circ@set@list@gobbletomarker#1Q{}
% quick way to check whether list parsing is done by gobbling up to a marker, in
% this case the marker is \pgf@circ@set@list
\def\pgf@circ@set@list@sanitize@checkend#1\pgf@circ@set@list{}
% will only be called after the last element is handled, will gobble the
% remainder of the current sanitizing step
\def\pgf@circ@set@list@sanitize@end\pgf@circ@set@list#1\pgf@circ@set@list{}
% grabs the next list element, checks whether we're done, and if not sanitizes
% it (meaning stripping spaces from either end and placing the <marker>).
\def\pgf@circ@set@list@sanitize#1,%
  {%
    \pgf@circ@set@list@sanitize@checkend
      #1\pgf@circ@set@list@sanitize@end\pgf@circ@set@list
    \pgf@circ@set@list@sanitize@a{#1}%
  }
% testing whether a list element contains the used <marker> expandably, if it
% does set the flag, else continue sanitizing.
\def\pgf@circ@set@list@sanitize@a#1%
  {%
    \expandafter\pgf@circ@ifempty\expandafter
      % if this is empty no marker was found
      {\pgf@circ@set@list@gobbletomarker#1Q}
      {%
        \pgf@circ@ifblank{#1}
          {}% ignore blank entries
          {\pgf@circ@trimspaces@do{#1}\pgf@circ@set@list@sanitize@b}%
      }
      {%
        % panic, there was a marker found in a list element. We'll recover by
        % ignoring the current element after setting a flag. When we do
        % \csname ...\endcsname on an undefined macro name TeX will let that
        % macro to relax and we exploit this to expandable set a flag and
        % gobbling the result.
        \expandafter\pgfutil@gobble\csname pgf@circ@error@marker\endcsname
      }%
    % get the next element
    \pgf@circ@set@list@sanitize
  }
% we'll protect any element from further expanding using \unexpanded and place
% the marker after the element, and ignore empty/blank elements
\def\pgf@circ@set@list@sanitize@b#1%
  {%
    \expandafter\pgf@circ@ifempty\expandafter
      % if this is empty no hyphen is found
      {\pgf@circ@gobbletohyphen#1-}
      {\pgfutil@unexpanded{#1}Q}
      {\pgf@circ@set@list@parse@range{#1}}%
  }
\def\pgf@circ@gobbletohyphen#1-{}
\def\pgf@circ@set@list@parse@range#1{\pgf@circ@set@list@parse@range@a#1Q}
\def\pgf@circ@set@list@parse@range@a#1-#2Q%
  {%
    \expandafter\pgf@circ@set@list@parse@range@b
      \the\numexpr#1\expandafter Q\the\numexpr#2Q%
  }
\def\pgf@circ@set@list@parse@range@b#1Q#2Q%
  {%
    \ifnum#1<#2
      % expand to the range from #1 to #2 (inclusive)
      \pgf@circ@set@list@range{#1}{#2}%
    \else
      \ifnum#2<#1
        % if #2 is smaller than #1 just swap the order
        \pgf@circ@set@list@range{#2}{#1}%
      \else
        % last case, they are equal, so just put the result here
        #1Q%
      \fi
    \fi
  }
\def\pgf@circ@set@list@parse@range@norange#1Q#2{\pgfutil@unexpanded{#2}Q}
\def\pgf@circ@set@list@range#1#2%
  {%
    #1Q%
    \ifnum#1<#2
      \expandafter\pgfutil@secondoftwo
    \fi
    \pgfutil@gobble
    {\expandafter\pgf@circ@set@list@range\expandafter{\the\numexpr#1+1}{#2}}%
  }

% flag for special value
\def\pgf@circ@all@flag{QallQ}
\pgfutil@protected\def\pgf@circ@if@num@in@list#1#2%
  {%
    % test whether the list macro is defined, if it isn't result is false
    \pgfutil@ifx\pgf@circ@undefined#1%
      {\pgfutil@secondoftwo}
      {%
        % test whether the list macro is just the special value 'all', if so
        % true, else search (and start that by evaluating a numexpr)
        \pgfutil@ifx\pgf@circ@all@flag#1%
          {\pgfutil@firstoftwo}
          {%
            \expandafter\pgf@circ@if@num@in@list@a\expandafter
              {\the\numexpr#2}%
              #1%
          }%
      }%
  }
% next step is expanding the list macro
\pgfutil@protected\def\pgf@circ@if@num@in@list@a#1#2%
  {\expandafter\pgf@circ@if@num@in@list@b\expandafter{#2}{#1}}
% now use \pgfutil@in@ to check whether there is the searched list element
\pgfutil@protected\def\pgf@circ@if@num@in@list@b#1#2%
  {%
    \begingroup
      % put the <marker> around the number to make sure only full matches are
      % found. \pgfutil@in@ will set \ifpgfutil@in@ to true if it finds a match
      \pgfutil@in@{Q#2Q}{#1}%
      \expandafter
    \endgroup
    \ifpgfutil@in@
      \expandafter\pgfutil@firstoftwo
    \else
      \expandafter\pgfutil@secondoftwo
    \fi
  }

% reset the catcode of Q
\catcode`\Q=\pgf@circ@temp

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% temporary fix for old TikZ versions (remove me)
%%
%% All blame to Romano Giannetti for this code!
%%
%% This tries to be smart and provide \pgfutil@unexpanded and \pgfutil@ifx if
%% PGF doesn't provide them.

\ifx\pgfutil@unexpanded\pgf@circ@undefined
  \ifpgfutil@format@is@context
    \let\pgfutil@unexpanded\normalunexpanded
  \else
    \let\pgfutil@unexpanded\unexpanded
  \fi
\fi

\ifx\pgfutil@ifx\pgf@circ@undefined
  \long\def\pgfutil@ifx#1#2{%
    \ifx#1#2%
      \expandafter\pgfutil@firstoftwo
    \else
      \expandafter\pgfutil@secondoftwo
    \fi}
\fi

%%
%% generic tunable arrow for components that have no "variable" thing
%%
\def\ctikztunablearrow{\pgfutil@ifnextchar[{\ctikztunablearrow@full}{\ctikztunablearrow@simple}}%
\def\ctikztunablearrow@simple{\ctikztunablearrow@full[]}%
\def\ctikztunablearrow@full[#1]#2#3#4#5{%
    % add tunable arrow to a component
    % relative thickness, relative length, rotation from axis, name of the component
    \scope
    \draw
    \pgfextra{\pgfcirc@set@arrows{tunable}{}{latexslim}
    \pgfsetlinewidth{#2\pgflinewidth}} [#1]
        let \p1=($(#5.north east)-(#5.south west)$), \p2=($(#5.east)-(#5.west)$),
        \n1 = {veclen(\x1,\y1)},
        \n2 = {atan2(\y2,\x2)} in
        % node[above]{\n1, \n2}
        % notice that some node has the "center" on one side, so
        % midway from east to west is a safer bet for the center
        ($(#5.west)!0.5!(#5.east)$) ++({\n2+(#4)}:{-0.5*(\n1)*(#3)}) -- ++({\n2+(#4)}:{(\n1)*(#3)});
    \endscope
}
%%%---------- close: tex/pgfcircutils
%%%%%%%%%%% Springe nach tex/pgfcircpath
%%%---------- open: tex/pgfcircpath.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.


\def\pgf@circ@direction{0.0}

% swap two coordinates
\def\pgfcirc@swap@coordinates#1#2{%
    coordinate (pgfcirc@tmp@swap) at (#1)
    coordinate (#1) at (#2)
    coordinate (#2) at (pgfcirc@tmp@swap)
}

% Names
\ctikzset{name/.style = { n={#1} } } %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@@@
\ctikzset{n/.code = {
	\pgfkeys{/tikz/circuitikz/bipole/name={#1}}
}}

% Reflect the node along
\ctikzset{mirrored/.is choice}
\ctikzset{mirror value/.initial=1}
\ctikzset{mirrored/true/.code = {\ctikzsetvalof{mirror value}{-1}} }
\ctikzset{mirrored/false/.code = {\ctikzsetvalof{mirror value}{1}} }
\ctikzset{mirror/.style = {/tikz/circuitikz/mirrored=true}}

% Invert node along path
\ctikzset{inverted/.is choice}
\ctikzset{invert value/.initial=1}
\ctikzset{inverted/true/.code = {\ctikzsetvalof{invert value}{-1}\pgf@circuit@bipole@invertedtrue}}
\ctikzset{inverted/false/.code = {\ctikzsetvalof{invert value}{1}\pgf@circuit@bipole@invertedfalse}}
\ctikzset{invert/.style = {/tikz/circuitikz/inverted=true}}
\newif\ifpgf@circuit@bipole@inverted
\ctikzset{bipole/inverted/.is if=pgf@circuit@bipole@inverted}

\newif\ifpgf@circuit@bipole@voltage@backward
\ctikzset{bipole/voltage/direction/.is choice}
\ctikzset{bipole/voltage/direction/forward/.code={\pgf@circuit@bipole@voltage@backwardfalse}}
\ctikzset{bipole/voltage/direction/backward/.code={\pgf@circuit@bipole@voltage@backwardtrue}}

% Initialize paths
\def\pgfcircresetpath{
    \ctikzset{bipole/name=, bipole/label/name=, bipole/label/position=90, ,bipole/annotation/name=, bipole/annotation/position=-90,
        bipole/inverted=false, bipole/kind=,
        bipole/voltage/direction=backward, bipole/voltage/label/name=, bipole/voltage/position=below,
        bipole/nodes/left=none, bipole/nodes/right=none, bipole/is voltage=false,bipole/is voltageoutsideofsymbol=false,bipole/is strokedsymbol=false,
        bipole/is current=false, bipole/current/label/name=, bipole/current/x position=after,
        bipole/current/y position=above, bipole/current/direction=forward,
        mirrored=false
    }
}

%
% expandable IF for the extra nodes (thanks to Henri Menke)
% see https://chat.stackexchange.com/transcript/message/56560808#56560808
%
\def\pgfcirc@if@has@i{%
    \ifpgfcirc@has@i
        \expandafter\pgfutil@firstoftwo
    \else
        \expandafter\pgfutil@secondoftwo
    \fi}
\def\pgfcirc@if@has@v{%
    \ifpgfcirc@has@v
        \expandafter\pgfutil@firstoftwo
    \else
        \expandafter\pgfutil@secondoftwo
    \fi}
\def\pgfcirc@if@has@f{%
    \ifpgfcirc@has@f
        \expandafter\pgfutil@firstoftwo
    \else
        \expandafter\pgfutil@secondoftwo
    \fi}



%% Generic bipole path
\def\pgf@circ@bipole@path#1#2{
    % Create a bipole path from the shapes defined with \pgfcircdeclarebipole
    % or \pgfcircdeclarebipolescaled; the node shapes are named with a "shape"
    % appended to the main (path-style) name
    % #1 path-style node name
    % #2 the argument passed from the to-path structure; don't touch
    %
    % Example:
    % \def\pgf@circ@capacitor@path#1{\pgf@circ@bipole@path{capacitor}{#1}}
    %
    \pgf@circ@bipole@path@base{shape}{}{#1}{#2}
}
%%
%% ultra-generic bipole path
%% I am not sure what the last argument is needed for, but don't touch it or everything explodes
%%
\def\pgf@circ@bipole@path@base#1#2#3#4{%
    %
    % Create a path-style component based on a node-style shape
    % #1: postfix to be added to the name path to obtain the main shape name
    % #2: text to be passed as text to the node
    % #3: name of the bipole component
    % #4: this will be filled by the argument of the to-path
    %
    \pgfextra{
        \ctikzset{bipole/kind = #3}
        \edef\pgf@temp{\ctikzvalof{bipole/name}}
        \def\pgf@circ@temp{}
        \ifx\pgf@temp\pgf@circ@temp % if it has not a name
            \pgfmathrandominteger{\pgf@circ@rand}{1000}{9999}
            \ctikzset{bipole/name = pgfcirc@#3\pgf@circ@rand} % create it (re-usage should not create problem, but...)
            \edef\pgfcirc@a@prefix{pgfcirc}% do not pollute the namespace for nothing
        \else
            \edef\pgfcirc@a@prefix{\ctikzvalof{bipole/name}}% for exporting v-i-f anchors
        \fi
    }
    % save start and stop values
    % notice that we DO NOT MOVE the path position at all!
    coordinate (\ctikzvalof{bipole/name}start) at (\tikztostart)
    coordinate (\ctikzvalof{bipole/name}end) at (\tikztotarget)
    \pgfextra{
        % find the direction (angle) of the path
        \pgfmathanglebetweenpoints{\pgfpointanchor{\ctikzvalof{bipole/name}start}{center}}
            {\pgfpointanchor{\ctikzvalof{bipole/name}end}{center}}
        \edef\pgf@circ@direction{\pgfmathresult}
        % the global macro  pgfcirc@whatever-direction is accessible as \ctikzgetdirection{whatever}
        % this gives access to the element path direction
        \expandafter\xdef\csname pgfcirc@\pgfcirc@a@prefix-direction\endcsname{\pgf@circ@direction}
    }
    % position the component in the middle of the path. We DO NOT MOVE the current position!
    node[#3#1, rotate=\pgf@circ@direction, yscale=\ctikzvalof{mirror value},
        xscale=\ctikzvalof{invert value}] (\ctikzvalof{bipole/name})
        at ($(\tikztostart) ! .5 ! (\tikztotarget)$) {#2}
    % set start and end labels
    \ifpgf@circuit@bipole@inverted
        \ifcsname pgf@anchor@#3#1@pathstart\endcsname%if special path-anchors are defined, use them!
            coordinate	(pgfcirc@anchorstartnode) at (\ctikzvalof{bipole/name}.pathend)
            coordinate	(pgfcirc@anchorendnode) at (\ctikzvalof{bipole/name}.pathstart)
        \else
            coordinate	(pgfcirc@anchorstartnode) at (\ctikzvalof{bipole/name}.right)
            coordinate	(pgfcirc@anchorendnode) at (\ctikzvalof{bipole/name}.left)
        \fi
        \else
        \ifcsname pgf@anchor@#3#1@pathstart\endcsname%if special path-anchors are defined, use them!
            coordinate	(pgfcirc@anchorstartnode) at (\ctikzvalof{bipole/name}.pathstart)
            coordinate	(pgfcirc@anchorendnode) at (\ctikzvalof{bipole/name}.pathend)
        \else
            coordinate	(pgfcirc@anchorstartnode) at (\ctikzvalof{bipole/name}.left)
            coordinate	(pgfcirc@anchorendnode) at (\ctikzvalof{bipole/name}.right)
        \fi
    \fi
    % draw the leads unless it's an open circuit
    % stop at the component
    \pgfextra{\def\pgf@temp{open}\def\pgf@circ@temp{#3}}
    \ifx\pgf@temp\pgf@circ@temp  % if it is an open do nothing
    \else
        % it is important to start the path with -- to have correct line joins!
        -- (pgfcirc@anchorstartnode)
    \fi
    % Add all the "ornaments": labels, annotations, voltages, currents and flows
    \drawpoles
    \pgf@circ@ifkeyempty{bipole/label/name}\else\pgf@circ@drawlabels{label}\fi
    \pgf@circ@ifkeyempty{bipole/annotation/name}\else\pgf@circ@drawlabels{annotation}\fi
    % the following  must be made in their own path scope to avoid crash in TikZ 3.1.8/3.1.8a
    % it should be logically safe for older version too --- even if TikZ reverted the change
    % use explandable ifs too, thanks to Henri Menke
    {\pgfcirc@if@has@v{\pgf@circ@drawvoltage}{}}%
    {\pgfcirc@if@has@i{\pgf@circ@drawcurrent}{}}%
    {\pgfcirc@if@has@f{\pgf@circ@drawflow}{}}%
    % finish the path from the component to the final target
    % you never know --- re-set \pgf@temp to detect open
    \pgfextra{\def\pgf@temp{open}\def\pgf@circ@temp{#3}}
    \ifx\pgf@temp\pgf@circ@temp  % if it is an open do nothing
        (\tikztotarget)
    \else
        (pgfcirc@anchorendnode)  -- (\tikztotarget)
    \fi
    % reset internal circuit keys
    \pgfextra{\pgfcircresetpath}
    %draw pending nodes an path
    \tikztonodes
}

%% Macros for path and style activation for bipoles or path-style

\def\comnpatname{\ifpgf@circuit@compat *\else\fi}
\def\compattikzset#1{%
    % \typeout{BIPOLEDEF:\space \detokenize{#1}}%
    \tikzset{\comnpatname#1}}
%
% this is used for components that are mainly node-style but have a path-style form
%
\def\pgfcirc@node@to@path#1#2#3{%
    % add a path-style component based on a node-style one without mangling the name
    % of the shape.
    % #1: node-type shape name (existing)
    % #2: path-type name (to be created)
    % #3: additional options to add to the path style
    %
    \expandafter\def\csname pgf@circ@#1@path\endcsname##1{\pgf@circ@bipole@path@base{}{##1}{#1}{}}%
    \compattikzset{#2/.style = {\circuitikzbasekey,
        /tikz/to path=\csname pgf@circ@#1@path\endcsname{##1},
        #3}}%
    \ctikzset{bipoles/#1/height/.initial=1}%
}
%
% this one is for normal definition: path to style, directly
% the first parameter (#1) here is l,v,i (l=..., v=..., i=...)
% the last parameter are options to be inserted in the "to path" definition
%
\def\pgfcirc@path@to@style#1#2#3#4{% using #1 as label, assign \pgf@circ@#2@path to style #3
    \compattikzset{#3/.style={\circuitikzbasekey, #4, /tikz/to path=\csname pgf@circ@#2@path\endcsname, #1={##1}}}%
}
% this one create a alias style from a node definition
\def\pgfcirc@node@to@style#1#2#3#4{% using #1 as label, assign \pgf@circ@bipole@path{#2} to style #3
    \compattikzset{#3/.style={\circuitikzbasekey, #4, /tikz/to path=\pgf@circ@bipole@path{#2}, #1={##1}}}%
}
% this create an alias style
\def\pgfcirc@style@to@style#1#2{% alias style #1 to style #2
    \compattikzset{#2/.style={\comnpatname #1={##1}}}%
}
% this create an alias style, changing the labelling
\def\pgfcirc@style@to@style@label#1#2#3{% alias style #1 to style #2
    \compattikzset{#2/.style={\comnpatname #1, #3={##1}}}%
}
% create a bipole
\def\pgfcirc@activate@bipole#1#2#3#4{% path name, base node name, style name
    \expandafter\def\csname pgf@circ@#2@path\endcsname##1{\pgf@circ@bipole@path{#3}{##1}}%
    \pgfcirc@path@to@style{#1}{#2}{#4}{}% no options here, let's see
}
\def\pgfcirc@activate@bipole@simple#1#2{\pgfcirc@activate@bipole{#1}{#2}{#2}{#2}}
% create a bipole with options
\def\pgfcirc@activate@bipole@opt#1#2#3#4#5{% path name, base node name, style name
    \expandafter\def\csname pgf@circ@#2@path\endcsname##1{\pgf@circ@bipole@path{#3}{##1}}%
    \pgfcirc@path@to@style{#1}{#2}{#4}{#5}% no options here, let's see
}
\def\pgfcirc@activate@bipole@simple@opt#1#2#3{\pgfcirc@activate@bipole@opt{#1}{#2}{#2}{#2}{#3}}


%% New system, for simple object
%% \pgfcirc@activate@bipole@simple{l}{mass}
%% New system, different names
%% The old system is the following
%% 1 - define just the pgf@circ@path@whatever#1
%% (see for example the variable one)
%% 2 - set the style
%% \compattikzset{resistor/.style= {\circuitikzbasekey, /tikz/to path=\pgf@circ@resistor@path, l={#1}}}

%% Path definition with the new mechanism have been moved to where the nodes
%% are defined.

%% Handling of terminals%<<<

\ctikzset{bipole/nodes/.is family}
\ctikzset{bipole/nodes/left/.initial=none}
\ctikzset{bipole/nodes/right/.initial=none}
\tikzset{bipole nodes/.style n args={2}{%
    \circuitikzbasekey/bipole/nodes/left=#1,
    \circuitikzbasekey/bipole/nodes/right=#2%
    }
}

%% Easily usable styles

\ctikzset{o-o/.style = {\circuitikzbasekey/bipole/nodes/left=ocirc, \circuitikzbasekey/bipole/nodes/right=ocirc}}
\ctikzset{-o/.style = {\circuitikzbasekey/bipole/nodes/left=none, \circuitikzbasekey/bipole/nodes/right=ocirc}}
\ctikzset{o-/.style = {\circuitikzbasekey/bipole/nodes/left=ocirc, \circuitikzbasekey/bipole/nodes/right=none}}
\ctikzset{*-o/.style = {\circuitikzbasekey/bipole/nodes/left=circ, \circuitikzbasekey/bipole/nodes/right=ocirc}}
\ctikzset{o-*/.style = {\circuitikzbasekey/bipole/nodes/left=ocirc, \circuitikzbasekey/bipole/nodes/right=circ}}
\ctikzset{d-o/.style = {\circuitikzbasekey/bipole/nodes/left=diamondpole, \circuitikzbasekey/bipole/nodes/right=ocirc}}
\ctikzset{o-d/.style = {\circuitikzbasekey/bipole/nodes/left=ocirc, \circuitikzbasekey/bipole/nodes/right=diamondpole}}
\ctikzset{*-/.style = {\circuitikzbasekey/bipole/nodes/left=circ, \circuitikzbasekey/bipole/nodes/right=none}}
\ctikzset{-*/.style = {\circuitikzbasekey/bipole/nodes/left=none, \circuitikzbasekey/bipole/nodes/right=circ}}
\ctikzset{d-/.style = {\circuitikzbasekey/bipole/nodes/left=diamondpole, \circuitikzbasekey/bipole/nodes/right=none}}
\ctikzset{-d/.style = {\circuitikzbasekey/bipole/nodes/left=none, \circuitikzbasekey/bipole/nodes/right=diamondpole}}
\ctikzset{*-*/.style = {\circuitikzbasekey/bipole/nodes/left=circ, \circuitikzbasekey/bipole/nodes/right=circ}}
\ctikzset{d-*/.style = {\circuitikzbasekey/bipole/nodes/left=diamondpole, \circuitikzbasekey/bipole/nodes/right=circ}}
\ctikzset{*-d/.style = {\circuitikzbasekey/bipole/nodes/left=circ, \circuitikzbasekey/bipole/nodes/right=diamondpole}}
\ctikzset{d-d/.style = {\circuitikzbasekey/bipole/nodes/left=diamondpole, \circuitikzbasekey/bipole/nodes/right=diamondpole}}

% rectjoinfill workarounds

\ctikzset{.-/.style = {\circuitikzbasekey/bipole/nodes/left=rectjoinfill, \circuitikzbasekey/bipole/nodes/right=none}}
\ctikzset{.-*/.style = {\circuitikzbasekey/bipole/nodes/left=rectjoinfill, \circuitikzbasekey/bipole/nodes/right=circ}}
\ctikzset{.-o/.style = {\circuitikzbasekey/bipole/nodes/left=rectjoinfill, \circuitikzbasekey/bipole/nodes/right=ocirc}}
\ctikzset{.-d/.style = {\circuitikzbasekey/bipole/nodes/left=rectjoinfill, \circuitikzbasekey/bipole/nodes/right=diamondpole}}
\ctikzset{-./.style = {\circuitikzbasekey/bipole/nodes/left=none, \circuitikzbasekey/bipole/nodes/right=rectjoinfill}}
\ctikzset{o-./.style = {\circuitikzbasekey/bipole/nodes/left=ocirc, \circuitikzbasekey/bipole/nodes/right=rectjoinfill}}
\ctikzset{*-./.style = {\circuitikzbasekey/bipole/nodes/left=circ, \circuitikzbasekey/bipole/nodes/right=rectjoinfill}}
\ctikzset{d-./.style = {\circuitikzbasekey/bipole/nodes/left=diamondpole, \circuitikzbasekey/bipole/nodes/right=rectjoinfill}}
\ctikzset{.-./.style = {\circuitikzbasekey/bipole/nodes/left=rectjoinfill, \circuitikzbasekey/bipole/nodes/right=rectjoinfill}}

\tikzset{reversed/.style = {\circuitikzbasekey/bipole/inverted=true}}

\def\drawpoles{
    \pgfextra{ \edef\pgf@circ@temp{\ctikzvalof{bipole/nodes/left}} \def\pgf@temp{none}}
    \ifx\pgf@temp\pgf@circ@temp\else(\tikztostart) node[\pgf@circ@temp] {}\fi
    \pgfextra{ \edef\pgf@circ@temp{\ctikzvalof{bipole/nodes/right}} }
    \ifx\pgf@temp\pgf@circ@temp\else(\tikztotarget) node[\pgf@circ@temp] {}\fi
}
% %>>>

%%
%% Definition of path for transistors
%%
% Transistor like bipoles

\def\pgf@circ@trans@path#1#2{
    \pgfextra{
        \edef\pgf@temp{\ctikzvalof{bipole/name}}
        \def\pgf@circ@temp{#2}
        \ifx\pgf@temp\pgf@circ@temp % if it has not a name
            \pgfmathrandominteger{\pgf@circ@rand}{1000}{9999}
            \ctikzset{bipole/name = trans\pgf@circ@rand} % create it
        \fi
    }
    \ifpgf@circuit@bipole@inverted
        (\tikztostart) node[coordinate] (\ctikzvalof{bipole/name}end) {}
        (\tikztotarget) node[coordinate] (\ctikzvalof{bipole/name}start) {}
    \else
        (\tikztostart) node[coordinate] (\ctikzvalof{bipole/name}start) {}
        (\tikztotarget) node[coordinate] (\ctikzvalof{bipole/name}end) {}
    \fi
    \pgfextra{
        \pgfmathanglebetweenpoints{\pgfpointanchor{\ctikzvalof{bipole/name}start}{center}}
        {\pgfpointanchor{\ctikzvalof{bipole/name}end}{center}}
        \pgfmathadd{\pgfmathresult}{-90}
        \pgfmathround{\pgfmathresult}
        \edef\pgf@circ@direction{\pgfmathresult}
    }
    ($(\tikztostart) ! .5 ! (\tikztotarget)$)
    node[#1, /tikz/rotate=\pgf@circ@direction, xscale=\ctikzvalof{mirror value}]
    (\ctikzvalof{bipole/name}) {}
    node {\ctikzvalof{bipole/label/name}}
    \ifcsname pgf@anchor@#1@pathstart\endcsname%if special path-anchors are defined, use them!
        (\ctikzvalof{bipole/name}start.center) --(\ctikzvalof{bipole/name}.pathstart)
        (\ctikzvalof{bipole/name}.pathend)  -- (\ctikzvalof{bipole/name}end.center)
    \else
        (\ctikzvalof{bipole/name}start.center) --(\ctikzvalof{bipole/name}.left)
        (\ctikzvalof{bipole/name}.right)  -- (\ctikzvalof{bipole/name}end.center)
    \fi
    \drawpoles
    \pgfextra{
        \pgfcircresetpath
    }
    (\tikztotarget) 	\tikztonodes  % and go on!
}

\def\pgf@circ@definetranspath#1{
	\compattikzset{T#1/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@trans@path{#1}{}, l=##1}}
}

%
% vim: set fdm=marker fmr=%<<<,%>>>:
%%%---------- close: tex/pgfcircpath

%%%%%%%%%%% Springe nach tex/pgfcircshapes
%%%---------- open: tex/pgfcircshapes.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.
%
% This file has folding marks for vim (See last line).
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Other shapes

%% Nothing: empty shape%<<<

\pgfdeclareshape{emptyshape}{
    \savedanchor{\northeast}{%
        \pgf@x=.5\wd\pgfnodeparttextbox%
        \pgf@y=.5\ht\pgfnodeparttextbox%
    }
    % geo anchors based on north-east
    \pgfcirc@northeast@symmetric@geoanchors
    \anchor{text}{\pgfpoint{-.5\wd\pgfnodeparttextbox}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}}
    \anchor{center}{
        \pgfpointorigin
    }
}%
%>>>

%% Poles%<<<
%
% Provision for changing opacity. Only expert use, see the manual.
%
\ctikzset{poles/open fill opacity/.initial=1.0}% better not touch it
\tikzset{open poles opacity/.code={%
        \ctikzset{poles/open fill opacity=#1}%
}}
\ctikzset{poles/full fill opacity/.initial=1.0}% better not touch it
\tikzset{full poles opacity/.code={%
        \ctikzset{poles/full fill opacity=#1}%

}}

%
% Provision for changing default background
%

\ctikzset{open poles fill/.initial={white}}

%% Full terminal

\pgfdeclareshape{circ}{
    \anchor{center}{
        \pgfpointorigin
    }
    \savedanchor\northwest{%
        \pgf@y=\ctikzvalof{nodes width}\pgf@circ@Rlen
        \pgf@x=-\pgf@y
    }
    \anchor{center}{ \pgf@y=0pt \pgf@x=0pt }
    % geo anchors based on north-west
    \pgfcirc@northwest@symmetric@geoanchors
    \anchorborder{
        \pgf@circ@res@left=\pgf@x
        \pgf@circ@res@up=\pgf@y
        \pgfpointborderellipse{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}
        }{\pgfpoint{\ctikzvalof{nodes width}*\pgf@circ@Rlen}{\ctikzvalof{nodes width}*\pgf@circ@Rlen}}
    }
    \pgf@circ@draw@component{
            \pgfpathcircle{\pgfpointorigin}{\ctikzvalof{nodes width}*\pgf@circ@Rlen}
            \pgf@circ@setcolor
            \pgf@circ@fill@strokecolor
            \pgfsetfillopacity{\ctikzvalof{poles/full fill opacity}}% normally 1.0
            \pgfusepath{draw,fill}
    }
}

%% Empty round terminal

\pgfdeclareshape{ocirc}{
    \anchor{center}{
        \pgfpointorigin
    }
    \savedanchor\northwest{%
        \pgf@y=\ctikzvalof{nodes width}\pgf@circ@Rlen
        \pgf@x=-\pgf@y
    }
    \anchor{center}{ \pgf@y=0pt \pgf@x=0pt }
    % geo anchors based on north-west
    \pgfcirc@northwest@symmetric@geoanchors
    \anchorborder{
        \pgf@circ@res@left=\pgf@x
        \pgf@circ@res@up=\pgf@y
        \pgfpointborderellipse{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}
        }{\pgfpoint{\ctikzvalof{nodes width}*\pgf@circ@Rlen}{\ctikzvalof{nodes width}*\pgf@circ@Rlen}}
    }
    \pgf@circ@draw@component{
        \pgfpathcircle{\pgfpointorigin}{\ctikzvalof{nodes width}*\pgf@circ@Rlen}
        \pgf@circ@setcolor
        \pgfsetfillopacity{\ctikzvalof{poles/open fill opacity}}% normally 1.0
        \ifx\tikz@fillcolor\pgfutil@empty
            % set the default fill color to white
            \pgfsetfillcolor{\ctikzvalof{open poles fill}}
            % ...but override it if the class is defined!
            % note that this element has no class, but will inherit it when used
            % into another component
            \pgf@circ@setifdefinedfill{draw, fill}{draw, fill}
        \else
            \pgfsetfillcolor{\tikz@fillcolor}
        \fi
        \pgfusepath{draw,fill}
    }
}

%% Diamond terminal

\pgfdeclareshape{diamondpole}{
    \anchor{center}{
        \pgfpointorigin
    }
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@y}{sqrt(2)*\ctikzvalof{nodes width}*\pgf@circ@Rlen}
        \pgf@x=-\pgf@y
    }
    \anchor{center}{ \pgf@y=0pt \pgf@x=0pt }
    % geo anchors based on north-west
    \pgfcirc@northwest@symmetric@geoanchors
    \anchorborder{
        % \typeout{IN\space X:\the\pgf@x\space Y:\the\pgf@y}
        \pgfmathsetmacro{\@@switchx}{ifthenelse(\pgf@x>0,1,-1)}
        \pgfmathsetmacro{\@@switchy}{ifthenelse(\pgf@y>0,1,-1)}
        \pgfmathsetlength{\pgf@xa}{abs(\pgf@x)}
        \pgfmathsetlength{\pgf@ya}{abs(\pgf@y)}
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        % \typeout{MID\space X:\the\pgf@xa\space Y:\the\pgf@ya\space L:\the\pgf@circ@res@up}
        % \typeout{MID\space SX:\@@switchx\space SY:\@@switchy}
        \pgfpointintersectionoflines
            {\pgfpointorigin}{\pgfqpoint{\pgf@xa}{\pgf@ya}}
            {\pgfqpoint{0pt}{\pgf@circ@res@up}}{\pgfqpoint{\pgf@circ@res@up}{0pt}}
        % \typeout{CROSS \space X:\the\pgf@x\space Y:\the\pgf@y}
        \pgf@x=\@@switchx\pgf@x
        \pgf@y=\@@switchy\pgf@y
    }
    \pgf@circ@draw@component{
        \pgfmathsetlength{\pgf@circ@res@temp}{\ctikzvalof{nodes width}*\pgf@circ@Rlen}
        \pgftransformrotate{45}
        \pgfpathrectanglecorners
        {\pgfpoint{-\pgf@circ@res@temp}{-\pgf@circ@res@temp}}
        {\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@temp}}
        \pgf@circ@setcolor
        \pgf@circ@fill@strokecolor
        \pgfsetfillopacity{\ctikzvalof{poles/full fill opacity}}% normally 1.0
        \pgfusepath{draw,fill}
    }
}

%% Diamond terminal, unfilled

\pgfdeclareshape{odiamondpole}{
    \anchor{center}{
        \pgfpointorigin
    }
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@y}{sqrt(2)*\ctikzvalof{nodes width}*\pgf@circ@Rlen}
        \pgf@x=-\pgf@y
    }
    \anchor{center}{ \pgf@y=0pt \pgf@x=0pt }
    % geo anchors based on north-west
    \pgfcirc@northwest@symmetric@geoanchors
    \anchorborder{
        % \typeout{IN\space X:\the\pgf@x\space Y:\the\pgf@y}
        \pgfmathsetmacro{\@@switchx}{ifthenelse(\pgf@x>0,1,-1)}
        \pgfmathsetmacro{\@@switchy}{ifthenelse(\pgf@y>0,1,-1)}
        \pgfmathsetlength{\pgf@xa}{abs(\pgf@x)}
        \pgfmathsetlength{\pgf@ya}{abs(\pgf@y)}
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        % \typeout{MID\space X:\the\pgf@xa\space Y:\the\pgf@ya\space L:\the\pgf@circ@res@up}
        % \typeout{MID\space SX:\@@switchx\space SY:\@@switchy}
        \pgfpointintersectionoflines
            {\pgfpointorigin}{\pgfqpoint{\pgf@xa}{\pgf@ya}}
            {\pgfqpoint{0pt}{\pgf@circ@res@up}}{\pgfqpoint{\pgf@circ@res@up}{0pt}}
        % \typeout{CROSS \space X:\the\pgf@x\space Y:\the\pgf@y}
        \pgf@x=\@@switchx\pgf@x
        \pgf@y=\@@switchy\pgf@y
    }
    \pgf@circ@draw@component{
        \pgfmathsetlength{\pgf@circ@res@temp}{\ctikzvalof{nodes width}*\pgf@circ@Rlen}
        \pgftransformrotate{45}
        \pgfpathrectanglecorners
        {\pgfpoint{-\pgf@circ@res@temp}{-\pgf@circ@res@temp}}
        {\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@temp}}
        \pgf@circ@setcolor
        \pgfsetfillopacity{\ctikzvalof{poles/open fill opacity}}% normally 1.0
        \ifx\tikz@fillcolor\pgfutil@empty
            % set the default fill color to white
            \pgfsetfillcolor{\ctikzvalof{open poles fill}}
            % ...but override it if the class is defined!
            % note that this element has no class, but will inherit it when used
            % into another component
            \pgf@circ@setifdefinedfill{draw, fill}{draw, fill}
        \else
            \pgfsetfillcolor{\tikz@fillcolor}
        \fi
        \pgfusepath{draw,fill}
    }
}

%% square terminal, filled

\pgfdeclareshape{squarepole}{
    \anchor{center}{
        \pgfpointorigin
    }
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@y}{\ctikzvalof{nodes width}*\pgf@circ@Rlen}
        \pgf@x=-\pgf@y
    }
    \anchor{center}{ \pgf@y=0pt \pgf@x=0pt }
    % geo anchors based on north-west
    \pgfcirc@northwest@symmetric@geoanchors
    \anchorborder{
        \pgf@xa=\pgf@x
        \pgf@ya=\pgf@y
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfpointborderrectangle
            {\pgfqpoint{\pgf@xa}{\pgf@ya}}
            {\pgfqpoint{\pgf@circ@res@up}{\pgf@circ@res@up}}
    }
    \pgf@circ@draw@component{
        \pgfmathsetlength{\pgf@circ@res@temp}{\ctikzvalof{nodes width}*\pgf@circ@Rlen}
        \pgfpathrectanglecorners
        {\pgfpoint{-\pgf@circ@res@temp}{-\pgf@circ@res@temp}}
        {\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@temp}}
        \pgf@circ@setcolor
        \pgf@circ@fill@strokecolor
        \pgfsetfillopacity{\ctikzvalof{poles/full fill opacity}}% normally 1.0
        \pgfusepath{draw,fill}
    }
}
%% square terminal, unfilled

\pgfdeclareshape{osquarepole}{
    \anchor{center}{
        \pgfpointorigin
    }
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@y}{\ctikzvalof{nodes width}*\pgf@circ@Rlen}
        \pgf@x=-\pgf@y
    }
    \anchor{center}{ \pgf@y=0pt \pgf@x=0pt }
    % geo anchors based on north-west
    \pgfcirc@northwest@symmetric@geoanchors
    \anchorborder{
        \pgf@xa=\pgf@x
        \pgf@ya=\pgf@y
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfpointborderrectangle
            {\pgfqpoint{\pgf@xa}{\pgf@ya}}
            {\pgfqpoint{\pgf@circ@res@up}{\pgf@circ@res@up}}
    }
    \pgf@circ@draw@component{
        \pgfmathsetlength{\pgf@circ@res@temp}{\ctikzvalof{nodes width}*\pgf@circ@Rlen}
        \pgfpathrectanglecorners
        {\pgfpoint{-\pgf@circ@res@temp}{-\pgf@circ@res@temp}}
        {\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@temp}}
        \pgf@circ@setcolor
        \pgfsetfillopacity{\ctikzvalof{poles/open fill opacity}}% normally 1.0
        \ifx\tikz@fillcolor\pgfutil@empty
            % set the default fill color to white
            \pgfsetfillcolor{\ctikzvalof{open poles fill}}
            % ...but override it if the class is defined!
            % note that this element has no class, but will inherit it when used
            % into another component
            \pgf@circ@setifdefinedfill{draw, fill}{draw, fill}
        \else
            \pgfsetfillcolor{\tikz@fillcolor}
        \fi
        \pgfusepath{draw,fill}
    }
}

%% Fill for correct rectangular joins

\pgfdeclareshape{rectjoinfill}{
    \savedanchor{\northeast}{%
        \pgf@x=.5\pgflinewidth%
        \pgf@y=.5\pgflinewidth%
    }
    % geo anchors based on north-east
    \pgfcirc@northeast@symmetric@geoanchors
    \anchor{center}{
        \pgfpointorigin
    }
    \anchorborder{
        \pgf@circ@res@left=\pgf@x
        \pgf@circ@res@up=\pgf@y
    }
    \pgf@circ@draw@component{
        \pgfpathrectanglecorners
        {\pgfpoint{0}{.5\pgflinewidth}}
        {\pgfpoint{0}{-.5\pgflinewidth}}
        \pgf@circ@setcolor
        \pgf@circ@fill@strokecolor
        \pgfusepath{draw,fill}
    }
}
% %>>>

%% Arrows%<<<
%% transistor arrow

\def\pgf@circ@find@linescale{
    % find the scale inverse of the scale factor: line width do not scale
    % with scale=..., transform shape so we have to counteract it.
    \iftikz@fullytransformed % this is true if `transform shape` is active
        % from @Circumscribe https://tex.stackexchange.com/a/474035/38080
        % Note that this trick is not working inside a `spy` environment...
        \pgfgettransformentries{\scaleA}{\scaleB}{\scaleC}{\scaleD}{\whatevs}{\whatevs}%
        \pgfmathsetmacro{\@@factor}{1.0/sqrt(abs(\scaleA*\scaleD-\scaleB*\scaleC))}%
    \else
        \pgfmathsetmacro{\@@factor}{1.0}
    \fi
}

\pgfdeclareshape{trarrow}{%
    % this arrow is only filled but grows with the linewidth, more or less
    % like currarrow do
    \savedanchor{\northeast}{%
        \pgf@circ@res@step = \pgf@circ@Rlen
        \pgf@circ@find@linescale
        \divide \pgf@circ@res@step by \ctikzvalof{current arrow scale}
        \pgfpoint{0.7*\pgf@circ@res@step +0.5*\@@factor*\pgflinewidth}
            {0.8*\pgf@circ@res@step+0.7593*\@@factor*\pgflinewidth}
    }
    % The arrow size should be more or less the same of a currarrow, which is
    % both filled and stroke, for backward output compatibility (more or less)
    %
    %      angle \beta       W is \pgf@circ@Rlen/\ctikzvalof{current arrow scale}
    %    |-\__               currarrow as the tip at (W,0)
    %    |    |              and the upper tail at (-0.7*W, 0.8*W)
    %    |    \__            it then "overshoot" do to the linew width L
    %    |       \__ xangle \alpha
    %    ---0------->
    %
    %   \beta = atan(0.7/0.8)  \alpha=atan(0.8/1.7)
    %   tip overshoot is (L/2)/sin(\alpha) = 1.743*L only in x direction
    %   tail overshoot is -(L/2) in x, and (L/2)/sin(\beta) = 0.7539*L in y
    %
    \savedanchor{\northwest}{%
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by \ctikzvalof{current arrow scale}
        \pgf@circ@find@linescale
        \pgfpoint{-0.7*\pgf@circ@res@step -0.5*\@@factor*\pgflinewidth}
            {0.8*\pgf@circ@res@step+0.7593*\@@factor*\pgflinewidth}
    }
    \savedanchor{\tip}{%
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by \ctikzvalof{current arrow scale}
        \pgf@circ@find@linescale
        \pgfpoint{\pgf@circ@res@step + 1.743*\@@factor*\pgflinewidth}{0pt}
    }
    \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{north east}{\northeast}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast\pgf@y=-\pgf@y}
    \anchor{south west}{\northeast\pgf@y=-\pgf@y\pgf@x=-\pgf@x}
    \anchor{center}{
        \pgfpointorigin
    }
    \anchor{tip}{
        \tip
    }
    \anchor{btip}{% this anchor is behind the tip of half a linewidth
        \tip
        \pgf@circ@find@linescale
        \pgf@circ@res@temp=\@@factor\pgflinewidth
        \advance\pgf@x by -.5\pgf@circ@res@temp
    }
    \pgf@circ@draw@component{
        \northwest
        \pgf@circ@res@up=\pgf@y
        \pgf@circ@res@left=\pgf@x
        \tip
        \pgf@circ@res@step = \pgf@x
        %
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{1\pgf@circ@res@step}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up}}
        \pgfpathclose
        \pgf@circ@fill@strokecolor
        \pgfusepath{fill} % just fill
    }
}

%% Current arrow

%% we need a phantom version of this shape for advanced v-i-f
%% use strange names to keep ot private
\newif\ifpgfcirc@really@draw@currarrow\pgfcirc@really@draw@currarrowtrue
\ctikzset{phantom@currarrow/.code=\pgfcirc@really@draw@currarrowfalse}
\ctikzset{normal@currarrow/.code=\pgfcirc@really@draw@currarrowtrue}

\pgfdeclareshape{currarrow}{
    \savedanchor{\northeast}{%
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by \ctikzvalof{current arrow scale}
        \pgf@x=.5\pgf@circ@res@step
        \pgf@y=\pgf@x%
    }
    \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{north east}{\northeast}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast\pgf@y=-\pgf@y}
    \anchor{south west}{\northeast\pgf@y=-\pgf@y\pgf@x=-\pgf@x}
    \anchor{center}{
        \pgfpointorigin
    }
    \anchor{tip}{
        \pgfpointorigin
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by \ctikzvalof{current arrow scale}
        \pgf@x	=\pgf@circ@res@step
    }
    \pgf@circ@draw@component{
        \ifpgfcirc@really@draw@currarrow
            \pgf@circ@reset@arrows@rounded
            \pgf@circ@res@step = \pgf@circ@Rlen
            \divide \pgf@circ@res@step by \ctikzvalof{current arrow scale}

            \pgfpathmoveto{\pgfpoint{-.7\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{-.7\pgf@circ@res@step}{-.8\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{1\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{-.7\pgf@circ@res@step}{.8\pgf@circ@res@step}}
            \pgfpathclose
            \pgf@circ@setcolor
            \pgf@circ@fill@strokecolor
            \pgfusepath{draw,fill}
        \fi
    }
}

%% Flow arrow
%% we need a phantom version of this shape for advanced v-i-f
%% use strange names to keep ot private
\newif\ifpgfcirc@really@draw@flowarrow\pgfcirc@really@draw@flowarrowtrue
\ctikzset{phantom@flowarrow/.code=\pgfcirc@really@draw@flowarrowfalse}
\ctikzset{normal@flowarrow/.code=\pgfcirc@really@draw@flowarrowtrue}

\pgfdeclareshape{flowarrow}{
    \savedanchor{\northeast}{%
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by \ctikzvalof{current arrow scale}
        \pgf@y=.5\pgf@circ@res@step
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by 4
        \pgf@x=\pgf@circ@res@step%
    }
    \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{north east}{\northeast}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast\pgf@y=-\pgf@y}
    \anchor{south west}{\northeast\pgf@y=-\pgf@y\pgf@x=-\pgf@x}
    \anchor{text}{% text centered above
        \pgfpointorigin
        \pgfpoint{-.5\wd\pgfnodeparttextbox}{\dimexpr.5\dp\pgfnodeparttextbox+.5\ht\pgfnodeparttextbox}
    }
    \anchor{center}{
        \pgfpointorigin
    }
    \anchor{tip}{
        \pgfpointorigin
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by \ctikzvalof{current arrow scale}
        \pgf@x	=\pgf@circ@res@step
    }
    \pgf@circ@draw@component{
        \ifpgfcirc@really@draw@flowarrow
            \pgf@circ@reset@arrows@rounded
            \pgf@circ@res@step = \pgf@circ@Rlen
            \divide \pgf@circ@res@step by 4
            \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{0pt}}
            \pgf@circ@setcolor
            \pgfusepath{draw}
            \pgf@circ@fill@strokecolor
            \pgftransformshift{\pgfpoint{\pgf@circ@res@step}{0pt}}
            \pgfnode{currarrow}{tip}{}{}{\pgfusepath{fill}}
        \fi
    }
}

%% Input arrow

\pgfdeclareshape{inputarrow}{
    \savedanchor{\northeast}{% this is really not northeast, really -northwest
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by \ctikzvalof{current arrow scale}
        \pgf@y=.5\pgf@circ@res@step
        \pgf@x=1.7\pgf@circ@res@step
    }
    \anchor{north}{\northeast\pgf@x=0cm\relax}
    \anchor{east}{\northeast\pgf@y=0cm\relax\pgf@x=0cm\relax}
    \anchor{south}{\northeast\pgf@y=-\pgf@y \pgf@x=0cm\relax}
    \anchor{west}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x}
    \anchor{north east}{\northeast\pgf@x=0cm\relax}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast\pgf@y=-\pgf@y\pgf@x=0cm\relax}
    \anchor{south west}{\northeast\pgf@y=-\pgf@y\pgf@x=-\pgf@x}
    \savedanchor{\tip}{
        \pgfpointorigin
    }
    \anchor{center}{
        \tip
    }
    \anchor{tip}{
        \tip
    }
    \pgf@circ@draw@component{
        \pgf@circ@reset@arrows@rounded
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by 16
        \pgfpathmoveto{\pgfpoint{-1.7\pgf@circ@res@step}{0pt}}
        \pgfpathlineto{\pgfpoint{-1.7\pgf@circ@res@step}{-.8\pgf@circ@res@step}}
        \pgfpathlineto{\pgfpoint{0pt}{0pt}}
        \pgfpathlineto{\pgfpoint{-1.7\pgf@circ@res@step}{.8\pgf@circ@res@step}}
        \pgfpathclose
        \pgf@circ@setcolor
        \pgf@circ@fill@strokecolor
        \pgfusepath{fill}
    }
}
% %>>>

%% boxes%<<<
%% box

\pgfdeclareshape{box}{
    \anchor{center}{
        \pgfpointorigin
    }
    \pgf@circ@draw@component{
        \pgf@circ@res@step = \ctikzvalof{bipoles/twoport/width}\pgf@circ@Rlen
        \pgf@circ@res@step = 0.5\pgf@circ@res@step
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathrectanglecorners{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@step}}{\pgfpoint{\pgf@circ@res@step}{-\pgf@circ@res@step}}
        \pgf@circ@draworfill
    }
}

%% box scaled with blocks

\pgfdeclareshape{blockbox}{
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{blocks/scale}\pgf@circ@Rlen}}
    \anchor{center}{
        \pgfpointorigin
    }
    \pgf@circ@draw@component{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{blocks/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step = \ctikzvalof{bipoles/twoport/width}\pgf@circ@scaled@Rlen
        \pgf@circ@res@step = 0.5\pgf@circ@res@step
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathrectanglecorners{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@step}}{\pgfpoint{\pgf@circ@res@step}{-\pgf@circ@res@step}}
        \pgf@circ@draworfill
    }
}
% %>>>

%% crossings%<<<
% full nodes for wire crossing
% styling for the vertical wire (default: do none)
\ctikzset{crossing vertical/relative thickness/.initial=1}
\ctikzset{crossing vertical/color/.initial=default}
\ctikzset{crossing vertical/dash/.initial=default}

\pgfdeclareshape{jump crossing}
{
    \savedanchor\northwest{%
        \pgf@y=\ctikzvalof{bipoles/crossing/size}\pgf@circ@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\pgf@y
    }
    \anchor{center}{ \pgf@y=0pt \pgf@x=0pt }
    \pgfcirc@northwest@symmetric@geoanchors
    \pgf@circ@draw@component{
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        % horizontal jumper
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{0.4\pgf@circ@res@left}{0pt}}
        \pgfpatharc{0}{-180}{0.4*\pgf@circ@res@left}
        \pgfsetbeveljoin
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfusepath{draw}
        % vertical, broken path
        % styling of vertical line
        \pgfsetlinewidth{\ctikzvalof{crossing vertical/relative thickness}\pgflinewidth}
        \pgf@circ@subset@color@dash{crossing vertical}
        %
        \pgfpathmoveto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{0.5\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{0pt}{0.3\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
        \pgfusepath{draw}
    }
}
\pgfdeclareshape{plain crossing}
{
    \savedanchor\northwest{%
        \pgf@y=\ctikzvalof{bipoles/crossing/size}\pgf@circ@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\pgf@y
    }
    \anchor{center}{ \pgf@y=0pt \pgf@x=0pt }
    \pgfcirc@northwest@symmetric@geoanchors
    \pgf@circ@draw@component{
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        % horizontal jumper
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfusepath{draw}
        % vertical, broken path
        % styling of vertical line
        \pgfsetlinewidth{\ctikzvalof{crossing vertical/relative thickness}\pgflinewidth}
        \pgf@circ@subset@color@dash{crossing vertical}
        %
        \pgfpathmoveto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{0.1\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{0pt}{0.1\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
        \pgfusepath{draw}
    }
}
% %>>>

%% Connectors (BNC and IEC connectors; see https://github.com/circuitikz/circuitikz/issues/611)%<<<

% define new class
\ctikzset{connectors/scale/.initial=1.0}
\ctikzset{connectors/fill/.initial=none}
\ctikzset{connectors/thickness/.initial=none}
% parameters. To have round sockets, 3*height==2*width
\ctikzset{bipoles/iecconn/height/.initial=.2}
\ctikzset{bipoles/iecconn/width/.initial=.3}
% objects
\pgfcircdeclarebipolescaled{connectors}
{
    \anchor{plug center}{\northeast\pgf@y=0pt\divide\pgf@x by 3 }
    \anchor{socket center}{\northeast\pgf@y=0pt\pgf@x=-0.333333\pgf@x}
    % put the node text above and centered
    \anchor{text}{\pgfextracty{\pgf@circ@res@up}{\northeast}
        \pgfpoint{-.5\wd\pgfnodeparttextbox}{
            \dimexpr.5\ht\pgfnodeparttextbox+\pgf@circ@res@up\relax
        }
    }
}
{\ctikzvalof{bipoles/iecconn/height}}%symmetrical
{iecconn}
{\ctikzvalof{bipoles/iecconn/height}}
{\ctikzvalof{bipoles/iecconn/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left/3}{\pgf@circ@res@up}}
    \pgfpatharc{90}{-90}{0.66666\pgf@circ@res@left and \pgf@circ@res@up}
    \pgfusepath{draw}
    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left/3}{\pgf@circ@res@up/2}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down/2}}
    \pgf@circ@fill@strokecolor
    \pgfusepath{draw, fill}
}
\pgfcirc@activate@bipole@simple{l}{iecconn}
\pgfcirc@style@to@style{iecconn}{iec connector}

\long\def\pgfcirc@declare@iecsocket#1#2#3{% #1 name, #2 anchors, #3 drawing code
    \pgfdeclareshape{#1}{%
        \savedmacro{\ctikzclass}{\edef\ctikzclass{connectors}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \savedanchor\northwest{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@y=\ctikzvalof{bipoles/iecconn/height}\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@x=-\ctikzvalof{bipoles/iecconn/width}\pgf@circ@scaled@Rlen
            \divide\pgf@x by 6
        }
        \pgfcirc@northwest@symmetric@geoanchors
        #2%
        \pgf@circ@draw@component{%
            \pgf@circ@scaled@Rlen=\scaledRlen
            \pgfstartlinewidth=\pgflinewidth
            \northwest
            \pgf@circ@res@up=\pgf@y
            \pgf@circ@res@left=\pgf@x
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            #3%
            \pgfusepath{draw}
        }
    }
}

\long\def\pgfcirc@declare@iecplug#1#2{% #1 name, #2 anchors (drawing code is the same)
    \pgfdeclareshape{#1}{%
        \savedmacro{\ctikzclass}{\edef\ctikzclass{connectors}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \savedanchor\northwest{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@y=\ctikzvalof{bipoles/iecconn/height}\pgf@circ@scaled@Rlen
            \pgf@y=.25\pgf@y
            \pgf@x=-\ctikzvalof{bipoles/iecconn/width}\pgf@circ@scaled@Rlen
            \divide\pgf@x by 3
        }
        \pgfcirc@northwest@symmetric@geoanchors
        \anchor{plug center}{\pgfpointorigin}
        #2%
        \pgf@circ@draw@component{%
            \pgf@circ@scaled@Rlen=\scaledRlen
            \pgfstartlinewidth=\pgflinewidth
            \northwest
            \pgf@circ@res@up=\pgf@y
            \pgf@circ@res@left=\pgf@x
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{-\pgf@circ@res@left}{-\pgf@circ@res@up}}
            \pgf@circ@setcolor
            \pgf@circ@fill@strokecolor
            \pgfusepath{draw, fill}
        }
    }
}

\pgfcirc@declare@iecsocket{iecsocketR}{%
    % notice: center is on the left side
    \anchor{center}{\northwest\pgf@y=0pt}
    \anchor{socket center}{\northwest\pgf@y=0pt}
    % put the node text above and to the left, ignore depth
    \anchor{text}{%
        \pgfextractx{\pgf@circ@res@left}{\northwest}
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfpoint{-\pgf@circ@res@left}{%
            .5\ht\pgfnodeparttextbox+\pgf@circ@res@up
        }%
    }%
}{% drawing
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpatharc{90}{270}{2\pgf@circ@res@left and \pgf@circ@res@up}
}
\pgfcirc@declare@iecsocket{iecsocketL}{%
    % notice: center is on the left side
    \anchor{center}{\northwest\pgf@y=0pt}
    \anchor{socket center}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    % put the node text above and to the left, ignore depth
    \anchor{text}{%
        \pgfextractx{\pgf@circ@res@left}{\northwest}
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfpoint{-\wd\pgfnodeparttextbox+\pgf@circ@res@left}{%
            .5\ht\pgfnodeparttextbox+\pgf@circ@res@up
        }%
    }%
}{% drawing
    \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpatharc{90}{-90}{2\pgf@circ@res@left and \pgf@circ@res@up}
}

\pgfcirc@declare@iecplug{iecplugL}{%
        % notice: center is on the left side
        \anchor{center}{\northwest\pgf@y=0pt}
        % put the node text above and to the right, ignore depth
        % the text is higher to match the iec socket position
        \anchor{text}{%
            \pgfextractx{\pgf@circ@res@left}{\northwest}
            \pgfextracty{\pgf@circ@res@up}{\northwest}
            \pgfpoint{-\wd\pgfnodeparttextbox+\pgf@circ@res@left}{
              .5\ht\pgfnodeparttextbox+2\pgf@circ@res@up
            }
        }
}
\pgfcirc@declare@iecplug{iecplugR}{%
        % notice: center is on the left side
        \anchor{center}{\northwest\pgf@y=0pt}
        % put the node text above and to the right, ignore depth
        % the text is higher to match the iec socket position
        \anchor{text}{%
            \pgfextractx{\pgf@circ@res@left}{\northwest}
            \pgfextracty{\pgf@circ@res@up}{\northwest}
            \pgfpoint{-\pgf@circ@res@left}{
              .5\ht\pgfnodeparttextbox+2\pgf@circ@res@up
            }
        }
}
% BNC connector

\pgfdeclareshape{bnc}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{connectors}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{
        \pgfpointorigin
    }
    % BNC size is 2.5 times the size of the internal "ocirc", when class scale is=1
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{nodes width}\pgf@circ@scaled@Rlen
        \pgf@y=2.5\pgf@y
        \pgf@x=-\pgf@y
    }
    % center is on the opening
    \anchor{center}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{zero}{\pgfpointorigin}
    \anchor{hot}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{shield}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    % geo-anchors
    \pgfcirc@northwest@symmetric@geoanchors
    % put the node text above and centered
    \anchor{text}{\pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfpoint{-.5\wd\pgfnodeparttextbox}{
            \dimexpr.5\dp\pgfnodeparttextbox+.5\ht\pgfnodeparttextbox+\pgf@circ@res@up\relax
        }
    }
    \anchorborder{
        \pgf@circ@res@left=\pgf@x
        \pgf@circ@res@up=\pgf@y
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfpointborderellipse{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}
        }{\pgfpoint{2.5*\ctikzvalof{nodes width}*\pgf@circ@scaled@Rlen}{2.5*\ctikzvalof{nodes width}*\pgf@circ@scaled@Rlen}}
    }
    \pgf@circ@draw@component{
        \pgfextracty{\pgf@circ@res@other}{\northwest}
        \pgfmathsetlength{\pgf@circ@res@step}{\ctikzvalof{nodes width}*\scaledRlen}
        \pgfstartlinewidth=\pgflinewidth
        \pgf@circ@setlinewidth{bipoles}{\pgflinewidth}
        \pgf@circ@setcolor
        % external circle
        \pgfscope
            % clipping path: first a rectangle bigger then the shape
            % to avoid problems with the line thickness
            \pgfpathrectanglecorners{\pgfpoint{-2\pgf@circ@res@other}{-2\pgf@circ@res@other}}
                {\pgfpoint{2\pgf@circ@res@other}{2\pgf@circ@res@other}}
            % next the opening to the right
            \pgfpathrectanglecorners{\pgfpoint{-\pgf@circ@res@step}{-\pgf@circ@res@step}}
                {\pgfpoint{2\pgf@circ@res@other}{\pgf@circ@res@step}}
            % do the difference and clip before drawing
            \pgfseteorule
            \pgfusepath{clip}
            \pgfpathcircle{\pgfpointorigin}{\pgf@circ@res@other}
            \pgfusepath{draw}
        \endpgfscope
        % internal circle
        \pgfpathcircle{\pgfpointorigin}{\pgf@circ@res@step}
        \pgf@circ@draworfill
        % and the contact line to the right
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfusepath{draw}
    }
}
% %>>>

% vim: set fdm=marker fmr=%<<<,%>>>:
%%%---------- close: tex/pgfcircshapes
%%%%%%%%%%% Springe nach tex/pgfcircmonopoles
%%%---------- open: tex/pgfcircmonopoles.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Monopoles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%
%% Grounds
%%%%%%%%%%%%%


% grounds and power supplies%<<<1

\ctikzset{monopoles/.is family}
\ctikzset{monopoles/ground/width/.initial=.25}
\ctikzset{monopoles/ground/connectionthickness/.initial=1}
\ctikzset{monopoles/ground/thickness/.initial=2}
\ctikzset{monopoles/rground/thickness/.initial=2}
\ctikzset{monopoles/tground/thickness/.initial=3}
\ctikzset{monopoles/vcc/width/.initial=.2}
\ctikzset{monopoles/vcc/arrow/.initial=legacy}
\ctikzset{monopoles/vee/arrow/.initial=legacy}
\ctikzset{monopoles/match/width/.initial=.4}
\ctikzset{monopoles/chassis/width/.initial=.25}
\ctikzset{monopoles/alternative chassis/width/.initial=.25}
\ctikzset{monopoles/equipotentiality/width/.initial=.25}
\ctikzset{monopoles/antenna/width/.initial=.25}
\ctikzset{monopoles/antenna/label/xanchor/.initial=.4}
\ctikzset{monopoles/antenna/label/yanchor/.initial=.75}
\ctikzset{monopoles/txantenna/label/xanchor/.initial=.4}
\ctikzset{monopoles/txantenna/label/yanchor/.initial=.75}
\ctikzset{monopoles/txantenna/width/.initial=.25}
\ctikzset{monopoles/rxantenna/label/xanchor/.initial=.4}
\ctikzset{monopoles/rxantenna/label/yanchor/.initial=.75}
\ctikzset{monopoles/rxantenna/width/.initial=.25}
\ctikzset{monopoles/bareantenna/width/.initial=.25}
\ctikzset{monopoles/bareantenna/label/xanchor/.initial=1}
\ctikzset{monopoles/bareantenna/label/yanchor/.initial=0.5}
\ctikzset{monopoles/dinantenna/width/.initial=.2}
\ctikzset{monopoles/dinantenna/height/.initial=.6}
\ctikzset{monopoles/waves/width/.initial=0.5}%
%>>>

%% Node shapes for grounds and power supply%<<<

%% Ground symbol
% #1 -> name
% #2 -> width
% #3 -> depth
% #4 -> code
\long\def\pgf@circ@declareground#1#2#3#4{
    \pgfdeclareshape{#1}{
        \savedmacro{\ctikzclass}{\edef\ctikzclass{grounds}}  % class of these components
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \savedanchor{\southeast}{
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@x=\ctikzvalof{monopoles/ground/width}\pgf@circ@scaled@Rlen
            \pgf@x=#2\pgf@x
            \pgf@y=\ctikzvalof{monopoles/ground/width}\pgf@circ@scaled@Rlen
            \pgf@y=-#3\pgf@y
        }
        \anchor{north}{\pgfpointorigin}
        \anchor{north east}{\southeast\pgf@y=0pt\relax}
        \anchor{east}{\southeast\pgf@y=.5\pgf@y}
        \anchor{south east}{\southeast}
        \anchor{south}{\southeast\pgf@x=0pt\relax}
        \anchor{south west}{\southeast\pgf@x=-\pgf@x}
        \anchor{west}{\southeast\pgf@y=.5\pgf@y\pgf@x=-\pgf@x}
        \anchor{north west}{\southeast\pgf@y=0pt\pgf@x=-\pgf@x}
        \anchor{left}{\pgfpointorigin}
        \anchor{right}{\pgfpointorigin}
        \anchor{center}{\pgfpointorigin}
        \pgf@circ@draw@component{
            \pgf@circ@scaled@Rlen=\scaledRlen
            \pgf@circ@res@step=\ctikzvalof{monopoles/ground/width}\pgf@circ@scaled@Rlen
            \pgfscope
                \pgfstartlinewidth=\pgflinewidth
                #4
            \endpgfscope
        }
    }
}


\pgf@circ@declareground{ground}{0.6}{1.6}{
    \pgfsetlinewidth{\ctikzvalof{monopoles/ground/connectionthickness}\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpoint{0pt}{-1.2\pgf@circ@res@step}}
    \pgfusepath{draw}
    \pgf@circ@setlinewidth{monopoles/ground}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{-.6\pgf@circ@res@step}{-1.2\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@step}{-1.2\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{-.4\pgf@circ@res@step}{-1.4\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@step}{-1.4\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{-.25\pgf@circ@res@step}{-1.6\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.25\pgf@circ@res@step}{-1.6\pgf@circ@res@step}}
    \pgfusepath{draw}
}

\pgf@circ@declareground{tlground}{0.6}{0.4}{
    \pgf@circ@setlinewidth{monopoles/ground}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{-.6\pgf@circ@res@step}{0pt}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@step}{0pt}}
    \pgfpathmoveto{\pgfpoint{-.4\pgf@circ@res@step}{-0.2\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@step}{-0.2\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{-.25\pgf@circ@res@step}{-0.4\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.25\pgf@circ@res@step}{-0.4\pgf@circ@res@step}}
    \pgfusepath{draw}
}


\pgf@circ@declareground{rground}{0.6}{1}{
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpoint{0pt}{-\pgf@circ@res@step}}
    \pgfusepath{draw}

    \pgfstartlinewidth=\pgflinewidth
    \pgf@circ@setlinewidth{monopoles/rground}{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{-.6\pgf@circ@res@step}{-\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@step}{-\pgf@circ@res@step}}
    \pgfsetroundcap\pgfusepath{draw}
}

\pgf@circ@declareground{tground}{0.6}{0}{
    \pgfpathmoveto{\pgfpointorigin}
    \pgfusepath{draw}

    \pgfstartlinewidth=\pgflinewidth
    \pgf@circ@setlinewidth{monopoles/tground}{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{-.6\pgf@circ@res@step}{0pt}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@step}{0pt}}
    \pgfusepath{draw}
}

\pgf@circ@declareground{sground}{0.6}{1.8}{
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpoint{0pt}{-\pgf@circ@res@step}}
    \pgfusepath{draw}

    \pgfstartlinewidth=\pgflinewidth
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{-.6\pgf@circ@res@step}{-\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@step}{-\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{0}{-1.8\pgf@circ@res@step}}
    \pgfpathclose
    \pgf@circ@draworfill
}

% noiseless ground
\pgf@circ@declareground{nground}{0.9}{1.6}{
    \pgfsetlinewidth{\ctikzvalof{monopoles/ground/connectionthickness}\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpoint{0pt}{-1.2\pgf@circ@res@step}}
    \pgfusepath{draw}
    \pgf@circ@setlinewidth{monopoles/ground}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{-.6\pgf@circ@res@step}{-1.2\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@step}{-1.2\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{-.4\pgf@circ@res@step}{-1.4\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@step}{-1.4\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{-.25\pgf@circ@res@step}{-1.6\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.25\pgf@circ@res@step}{-1.6\pgf@circ@res@step}}
    \pgfusepath{draw}
    \pgfpathmoveto{\pgfpoint{0.9\pgf@circ@res@step}{-1.6\pgf@circ@res@step}}
    \pgfpatharc{0}{180}{0.9\pgf@circ@res@step}
    \pgfusepath{draw}
}

% protective ground
\pgf@circ@declareground{pground}{0.9}{1.8}{
    \pgf@circ@setlinewidth{monopoles/ground}{\pgfstartlinewidth}
    \pgfpathcircle{\pgfpoint{0pt}{-0.9\pgf@circ@res@step}}{0.9\pgf@circ@res@step}
    \pgf@circ@draworfill
    \pgfsetlinewidth{\ctikzvalof{monopoles/ground/connectionthickness}\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpoint{0pt}{-1\pgf@circ@res@step}}
    \pgfusepath{draw}
    \pgf@circ@setlinewidth{monopoles/ground}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{-.6\pgf@circ@res@step}{-1\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@step}{-1\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{-.4\pgf@circ@res@step}{-1.2\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@step}{-1.2\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{-.25\pgf@circ@res@step}{-1.4\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.25\pgf@circ@res@step}{-1.4\pgf@circ@res@step}}
    \pgfusepath{draw}
}

% chassis ground
\pgf@circ@declareground{cground}{1}{2}{
    \pgfsetlinewidth{\ctikzvalof{monopoles/ground/connectionthickness}\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpoint{0pt}{-1.5\pgf@circ@res@step}}
    \pgfusepath{draw}
    \pgf@circ@setlinewidth{monopoles/ground}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{-1.00\pgf@circ@res@step}{-2.10\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{-0.75\pgf@circ@res@step}{-1.50\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{ 0.75\pgf@circ@res@step}{-1.50\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{ 0.50\pgf@circ@res@step}{-2.10\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{ 0.00\pgf@circ@res@step}{-1.50\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{-0.25\pgf@circ@res@step}{-2.10\pgf@circ@res@step}}
    \pgfusepath{draw}
}

% Contributed by @fotesan https://github.com/fotesan
% european ground
\pgf@circ@declareground{eground}{1.1}{1.7}{
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpoint{0pt}{-\pgf@circ@res@step}}
    \pgfusepath{draw}

    \pgfstartlinewidth=\pgflinewidth
    \pgf@circ@setlinewidth{monopoles/tground}{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{-1\pgf@circ@res@step}{-\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{1\pgf@circ@res@step}{-\pgf@circ@res@step}}
    \pgfusepath{draw}

    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{-1.1\pgf@circ@res@step}{-1.7\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{-.6\pgf@circ@res@step}{-1\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{-.6\pgf@circ@res@step}{-1.7\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{-.1\pgf@circ@res@step}{-1\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{-.1\pgf@circ@res@step}{-1.7\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@step}{-1\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{.4\pgf@circ@res@step}{-1.7\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@step}{-1\pgf@circ@res@step}}
    \pgfusepath{draw}
}

\pgf@circ@declareground{eground2}{1.1}{1.7}{
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpoint{0pt}{-\pgf@circ@res@step}}
    \pgfusepath{draw}

    \pgfstartlinewidth=\pgflinewidth
    \pgf@circ@setlinewidth{monopoles/tground}{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{-1\pgf@circ@res@step}{-\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{1\pgf@circ@res@step}{-\pgf@circ@res@step}}
    \pgfusepath{draw}

    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{-1.1\pgf@circ@res@step}{-1.7\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{-.4\pgf@circ@res@step}{-1\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{-.45\pgf@circ@res@step}{-1.7\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.25\pgf@circ@res@step}{-1\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{.2\pgf@circ@res@step}{-1.7\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@step}{-1\pgf@circ@res@step}}
    \pgfusepath{draw}
}

%%%%%%%%%%%%%%%%%%
%% Power supplies
%%%%%%%%%%%%%%%%%%

% Vcc
\pgfdeclareshape{vcc}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{power supplies}}  % class of these components
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \saveddimen{\scaledwidth}{% thanks to @Schrödinger's cat on https://tex.stackexchange.com/a/506249/38080
        \pgfgettransformentries{\tmpa}{\tmpb}{\tmpc}{\tmpd}{\tmp}{\tmp}%
        \pgfmathsetmacro{\gscale}{sqrt(abs(\tmpa*\tmpd-\tmpb*\tmpc))}% abs should not be needed
        \pgfmathsetlength{\pgf@x}{(\ctikzvalof{\ctikzclass/scale}*\gscale*\ctikzvalof{monopoles/vcc/width})*\pgf@circ@Rlen}%
    }
    \savedanchor{\northeast}{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/vcc/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@circ@res@step
        \pgf@y=3\pgf@x%
    }
    \anchor{north}{\northeast\pgf@x=0cm\relax}
    \anchor{east}{\northeast\pgf@y=0.5\pgf@y\relax}
    \anchor{south}{\pgfpointorigin}
    \anchor{west}{\northeast\pgf@y=0.5\pgf@y\pgf@x=-\pgf@x}
    \anchor{north east}{\northeast}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast\pgf@y=0pt\relax}
    \anchor{south west}{\northeast\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{center}{\pgfpointorigin}
    \anchor{left}{\pgfpointorigin}
    \anchor{right}{\pgfpointorigin}
    \anchor{text}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/vcc/width}\pgf@circ@scaled@Rlen
        \pgfpathmoveto{\pgfpoint{-.5\wd\pgfnodeparttextbox}{2\pgf@circ@res@step+2\ht\pgfnodeparttextbox}}
        \pgfpathmoveto{\pgfpoint{.5\wd\pgfnodeparttextbox}{2\pgf@circ@res@step+2\ht\pgfnodeparttextbox}}
        \pgf@x=0pt
        \pgf@y=2\pgf@circ@res@step
        \advance \pgf@y by 0.5\ht\pgfnodeparttextbox
        \pgf@x=-.5\wd\pgfnodeparttextbox
    }
    \pgf@circ@draw@component{
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{monopoles/vcc/width}\pgf@circ@scaled@Rlen
        \pgfscope
            \edef\pgf@circ@temp{\ctikzvalof{monopoles/vcc/arrow}}\edef\pgf@temp{legacy}
            \ifx\pgf@temp\pgf@circ@temp
                \pgfstartlinewidth=\pgflinewidth
                \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

                \pgfpathmoveto{\pgfpoint{-0.5\pgf@circ@res@step}{.8\pgf@circ@res@step}}
                \pgfpathlineto{\pgfpoint{0}{1.5\pgf@circ@res@step}}
                \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@step}{.8\pgf@circ@res@step}}
                \pgfusepath{draw}

                \pgfsetlinewidth{\pgfstartlinewidth}
            \else
            \pgfsetarrowsend{\pgf@circ@temp}
        \fi
        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpoint{0pt}{1.5\pgf@circ@res@step}}
        \pgfusepath{draw}
    \endpgfscope
    }
}

% Vee
\pgfdeclareshape{vee}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{power supplies}}  % class of these components
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \saveddimen{\scaledwidth}{% thanks to @Schrödinger's cat on https://tex.stackexchange.com/a/506249/38080
        \pgfgettransformentries{\tmpa}{\tmpb}{\tmpc}{\tmpd}{\tmp}{\tmp}%
        \pgfmathsetmacro{\gscale}{sqrt(abs(\tmpa*\tmpd-\tmpb*\tmpc))}% abs should not be needed
        \pgfmathsetlength{\pgf@x}{(\ctikzvalof{\ctikzclass/scale}*\gscale*\ctikzvalof{monopoles/vcc/width})*\pgf@circ@Rlen}%
    }
    \savedanchor{\northeast}{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/vcc/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@circ@res@step
        \pgf@y=-3\pgf@x%
    }
    \anchor{south}{\northeast\pgf@x=0cm\relax}
    \anchor{east}{\northeast\pgf@y=0.5\pgf@y\relax}
    \anchor{north}{\pgfpointorigin}
    \anchor{west}{\northeast\pgf@y=0.5\pgf@y\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast}
    \anchor{south west}{\northeast\pgf@x=-\pgf@x}
    \anchor{north east}{\northeast\pgf@y=0pt\relax}
    \anchor{north west}{\northeast\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{center}{\pgfpointorigin}
    \anchor{left}{\pgfpointorigin}
    \anchor{right}{\pgfpointorigin}
    \anchor{text}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/vcc/width}\pgf@circ@scaled@Rlen
        \pgfpathmoveto{\pgfpoint{-.5\wd\pgfnodeparttextbox}{-2\pgf@circ@res@step-2\ht\pgfnodeparttextbox}}
        \pgfpathmoveto{\pgfpoint{.5\wd\pgfnodeparttextbox}{-2\pgf@circ@res@step-2\ht\pgfnodeparttextbox}}
        \pgf@x=0pt
        \pgf@y=-2\pgf@circ@res@step
        \advance \pgf@y by -1.5\ht\pgfnodeparttextbox
        \pgf@x=-.5\wd\pgfnodeparttextbox
    }

    \pgf@circ@draw@component{
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{monopoles/vcc/width}\pgf@circ@scaled@Rlen
        \pgfscope
            \edef\pgf@circ@temp{\ctikzvalof{monopoles/vee/arrow}}\edef\pgf@temp{legacy}
            \ifx\pgf@temp\pgf@circ@temp

                \pgfstartlinewidth=\pgflinewidth
                \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

                \pgfpathmoveto{\pgfpoint{-0.5\pgf@circ@res@step}{-.8\pgf@circ@res@step}}
                \pgfpathlineto{\pgfpoint{0}{-1.5\pgf@circ@res@step}}
                \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@step}{-.8\pgf@circ@res@step}}
                \pgfusepath{draw}
                \pgfsetlinewidth{\pgfstartlinewidth}
            \else
                \pgfsetarrowsend{\pgf@circ@temp}
            \fi
            \pgfpathmoveto{\pgfpointorigin}
            \pgfpathlineto{\pgfpoint{0pt}{-1.5\pgf@circ@res@step}}
            \pgfusepath{draw}
        \endpgfscope
    }
}% %>>>


%% This are strange, and probably wrong FIXME
% \compattikzset{vdd/.style = {\comnpatname vcc = #1}}
% \compattikzset{vss/.style = {\comnpatname vee = #1}}
\pgfcirc@style@to@style{vcc}{vdd}
\pgfcirc@style@to@style{vee}{vss}


%%%%%%%%%%%%%%
%% RF bipoles and monopoles
%%%%%%%%%%%%%%

%% RF bipoles and monopoles settings %<<<1
\ctikzset{bipoles/mstline/height/.initial=0.3}
\ctikzset{bipoles/mstline/width/.initial=1.2}
\pgfkeys{/tikz/mstlinelen/.add code={}{\ctikzset{bipoles/mstline/width=#1}}}
\ctikzset{monopoles/msport/width/.initial=.5}
\ctikzset{monopoles/msrstub/height/.initial=1.0}
\ctikzset{monopoles/msrstub/width/.initial=0.6}%
%>>>

%% Node shapes for RF bipoles%<<<
\ctikzset{bipoles/tline/height/.initial=.3}
\ctikzset{bipoles/tline/width/.initial=.6}
\newif\ifpgf@circ@bare@tline
\ctikzset{bipoles/tline/bare/.is if=pgf@circ@bare@tline}
\pgfcircdeclarebipolescaled{RF}
{
    \savedmacro{\recessright}{\edef\recessright{\ifpgf@circ@bare@tline -0.4\else 0.0\fi}}
    \anchor{center right}{\northeast \advance\pgf@x by -0.4\pgf@y\pgf@y=0pt}
    \anchor{top right}{\northeast \advance\pgf@x by -0.4\pgf@y}
    \anchor{bottom right}{\northeast \advance\pgf@x by -0.4\pgf@y\pgf@y=-\pgf@y}
    \anchor{center left}{\northeast \advance\pgf@x by -0.4\pgf@y\pgf@x=-\pgf@x\pgf@y=0pt}
    \anchor{top left}{\northeast \advance\pgf@x by -0.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{bottom left}{\northeast \advance\pgf@x by -0.4\pgf@y\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
    \anchor{right}{\northeast \advance\pgf@x by \recessright\pgf@y\pgf@y=0pt}
}
{\ctikzvalof{bipoles/tline/height}}
{tline}
{\ctikzvalof{bipoles/tline/height}}
{\ctikzvalof{bipoles/tline/width}}
{
    \pgf@circ@res@step=.4\pgf@circ@res@up % the size of the ellipsis is proportional to the height
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@step}{\pgf@circ@res@up}}
        \pgfpatharc{-90}{90}{-\pgf@circ@res@step and -\pgf@circ@res@up}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{\pgf@circ@res@down}}
        \pgfpatharc{-90}{90}{\pgf@circ@res@step and \pgf@circ@res@up}
        \pgf@circ@draworfill
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{\pgf@circ@res@up}}
        \pgfpatharc{-90}{90}{-\pgf@circ@res@step and -\pgf@circ@res@up}
        \pgfusepath{stroke}
    \endpgfscope
    \ifpgf@circ@bare@tline\else
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@step}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfusepath{stroke}
    \fi
}

% microstrip transmission line
\pgfcircdeclarebipolescaled{RF}
{}
{\ctikzvalof{bipoles/mstline/height}}
{mstline}
{\ctikzvalof{bipoles/mstline/height}}
{\ctikzvalof{bipoles/mstline/width}}
{
    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@draworfill
}% %>>>

%% Path definitions for RF path objects%<<<
\pgfcirc@activate@bipole@simple{l}{mstline}
\pgfcirc@activate@bipole@simple{l}{tline}
\pgfcirc@style@to@style{tline}{transmission line}
\pgfcirc@style@to@style{tline}{TL}
% %>>>

%% Node shapes for RF monopoles%<<<

% Legacy tlinestub
% Contributed by Leonardo Azzinnari
\pgfdeclareshape{tlinestub}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor{\northeast}{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step = \ctikzvalof{bipoles/tline/width} \pgf@circ@scaled@Rlen
        \pgf@x=1.2\pgf@circ@res@step
        \pgf@circ@res@step = \ctikzvalof{bipoles/tline/width} \pgf@circ@scaled@Rlen
        \pgf@y=.2\pgf@circ@res@step%
    }
    % the center is on the left side of the shape for facility of usage
    \anchor{north}{\northeast\pgf@x=0.5\pgf@x\relax}
    \anchor{east}{\northeast\pgf@y=0cm\relax}
    \anchor{south}{\northeast\pgf@y=-\pgf@y \pgf@x=0.5\pgf@x\relax}
    \anchor{west}{\pgfpointorigin}
    \anchor{north east}{\northeast}
    \anchor{north west}{\northeast\pgf@x=0cm\relax}
    \anchor{south east}{\northeast\pgf@y=-\pgf@y}
    \anchor{south west}{\northeast\pgf@x=0cm\pgf@y=-\pgf@y}
    \anchor{center}{\pgfpointorigin}
    % this is not exact, but it's better than nothing
    \anchor{text}{\northeast\pgf@xa=\pgf@x\pgf@ya=\pgf@y
        \pgfpoint{\dimexpr-.5\wd\pgfnodeparttextbox+.8\pgf@xa}
        {\dimexpr-.5\dp\pgfnodeparttextbox+.5\ht\pgfnodeparttextbox+\pgf@ya}}
    \pgf@circ@draw@component{
        \pgfstartlinewidth=\pgflinewidth

        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{bipoles/tline/width}\pgf@circ@scaled@Rlen

        \pgfscope
            \pgfpathmoveto{\pgfpoint{0.5\pgf@circ@res@step}{0.25\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{1.5\pgf@circ@res@step}{0.25\pgf@circ@res@step}}
            \pgfpatharc{90}{-90}{0.125\pgf@circ@res@step and 0.25\pgf@circ@res@step}
            \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@step}{-0.25\pgf@circ@res@step}}
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfpatharc{90}{-90}{-0.125\pgf@circ@res@step and -0.25\pgf@circ@res@step}
            \pgf@circ@draworfill
            \pgfpathmoveto{\pgfpoint{0.5\pgf@circ@res@step}{0.25\pgf@circ@res@step}}
            \pgfpatharc{90}{-90}{0.125\pgf@circ@res@step and 0.25\pgf@circ@res@step}
            \pgfusepath{stroke}
        \endpgfscope
        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@step}{0pt}}
        \pgfusepath{draw}
    }
}

%% New antennas without tails

% main body of antennas
\def\pgf@circ@antennabody{%
    \pgfstartlinewidth=\pgflinewidth
    \pgf@circ@scaled@Rlen=\scaledRlen
    \pgf@circ@setcolor
    \pgf@circ@res@step=\ctikzvalof{monopoles/bareantenna/width}\pgf@circ@scaled@Rlen
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@step}{2\pgf@circ@res@step}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{2\pgf@circ@res@step}}
        \pgfsetbeveljoin
        \pgfpathclose
        \pgf@circ@draworfill
    \endpgfscope
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpoint{0pt}{2\pgf@circ@res@step}}
    \pgfusepath{draw}
}

% Waves for the antennas.
\def\pgf@circ@antennawaves{%
    \pgfscope
    % define a triangle for clipping the waves
    \pgfpathmoveto{\pgfpoint{0pt}{\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{4.2\pgf@circ@res@step}{3\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{4.2\pgf@circ@res@step}{-1\pgf@circ@res@step}}
    \pgfpathclose
    \pgfusepath{clip}
    % ...and build the waves as clipped circles
    \pgf@circ@count@a=8\pgf@circ@res@other=0.5\pgf@circ@res@step
    \pgfmathloop%
    \ifnum\pgf@circ@count@a>2
        \pgfpathcircle{\pgfpoint{0pt}{\pgf@circ@res@step}}{\the\pgf@circ@count@a*\pgf@circ@res@other}
        \advance\pgf@circ@count@a-1\relax%
        \repeatpgfmathloop
        \pgfusepath{draw}
    \endpgfscope
}

% additional shape with the waves
\pgfdeclareshape{waves}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor{\northeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/waves/width}\pgf@circ@scaled@Rlen
        \pgf@x=\pgf@circ@res@step
        \pgf@y=\pgf@circ@res@step
    }
    \anchor{text}{
        \northeast
        \pgf@y=\dimexpr\pgf@y+.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \anchor{top}{\northeast\pgf@x=0pt}
    \anchor{right}{\northeast\pgf@y=0pt}
    \anchor{left}{\northeast\pgf@x=-\pgf@x\pgf@y=0pt}
    \anchor{bottom}{\northeast\pgf@y=-\pgf@y\pgf@x=0pt}
    \anchor{north}{\northeast\pgf@x=0pt}
    \anchor{north east}{\northeast}
    \anchor{east}{\northeast\pgf@y=0pt}
    \anchor{south east}{\northeast\pgf@y=-\pgf@y}
    \anchor{south}{\northeast\pgf@y=-\pgf@y\pgf@x=0pt}
    \anchor{south west}{\northeast\pgf@y=-\pgf@y\pgf@x=-\pgf@x}
    \anchor{west}{\northeast\pgf@x=-\pgf@x\pgf@y=0pt}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \pgf@circ@draw@component{
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{monopoles/waves/width}\pgf@circ@scaled@Rlen
        \pgf@circ@res@step=0.5\pgf@circ@res@step
        \pgf@circ@setcolor
        \pgfscope
        % define a triangle for clipping the waves
        \pgfpathmoveto{\pgfpoint{-2\pgf@circ@res@step}{0pt}}
        \pgfpathlineto{\pgfpoint{2.1\pgf@circ@res@step}{2\pgf@circ@res@step}}
        \pgfpathlineto{\pgfpoint{2.1\pgf@circ@res@step}{-2\pgf@circ@res@step}}
        \pgfpathclose
        \pgfusepath{clip}
        % ...and build the waves as clipped circles
        \c@pgf@counta=8\pgf@circ@res@other=0.5\pgf@circ@res@step
        \pgfmathloop%
        \ifnum\c@pgf@counta>1
            \pgfpathcircle{\pgfpoint{-2\pgf@circ@res@step}{0pt}}{\the\c@pgf@counta*\pgf@circ@res@other}
            \advance\c@pgf@counta-1\relax%
            \repeatpgfmathloop
            \pgfusepath{draw}
        \endpgfscope
    }
}

% the four types of antennas: simple, din, TX, RX. Notice that you can flip them...
%
\pgfdeclareshape{bareantenna}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor{\northeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/bareantenna/width}\pgf@circ@scaled@Rlen
        \pgf@x=\pgf@circ@res@step
        \pgf@y=2\pgf@circ@res@step
    }
    \anchor{text}{
        \northeast
        \pgf@x=\ctikzvalof{monopoles/bareantenna/label/xanchor}\pgf@x
        \pgf@y=\ctikzvalof{monopoles/bareantenna/label/yanchor}\pgf@y
        \pgf@y=\dimexpr\pgf@y+.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \anchor{top}{\northeast\pgf@x=0pt}
    \anchor{right}{\northeast\pgf@y=0.5\pgf@y}
    \anchor{left}{\northeast\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{bottom}{\pgfpointorigin}
    \anchor{north}{\northeast\pgf@x=0pt}
    \anchor{east}{\northeast\pgf@y=0.5\pgf@y}
    \anchor{west}{\northeast\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{south}{\pgfpointorigin}
    \anchor{north east}{\northeast}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast\pgf@y=0pt\relax}
    \anchor{south west}{\northeast\pgf@y=0pt\pgf@x=-\pgf@x}
    \pgf@circ@draw@component{
        \pgf@circ@antennabody
    }
}
%
\pgfdeclareshape{dinantenna}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor{\northeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/dinantenna/width}\pgf@circ@scaled@Rlen
        \pgf@circ@res@other=\ctikzvalof{monopoles/dinantenna/height}\pgf@circ@scaled@Rlen
        \pgf@x=\pgf@circ@res@step
        \pgf@y=\pgf@circ@res@other
    }
    \anchor{text}{
        \northeast
        \pgf@y=\dimexpr.5\pgf@y+.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \anchor{top}{\northeast\pgf@x=0pt}
    \anchor{right}{\northeast\pgf@y=0.5\pgf@y}
    \anchor{left}{\northeast\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{bottom}{\pgfpointorigin}
    \anchor{north}{\northeast\pgf@x=0pt}
    \anchor{east}{\northeast\pgf@y=0.5\pgf@y}
    \anchor{west}{\northeast\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{south}{\pgfpointorigin}
    \anchor{north east}{\northeast}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast\pgf@y=0pt\relax}
    \anchor{south west}{\northeast\pgf@y=0pt\pgf@x=-\pgf@x}
    \pgf@circ@draw@component{
        \pgfstartlinewidth=\pgflinewidth
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@setcolor
        \pgf@circ@res@right=\ctikzvalof{monopoles/dinantenna/width}\pgf@circ@scaled@Rlen
        \pgf@circ@res@up=\ctikzvalof{monopoles/dinantenna/height}\pgf@circ@scaled@Rlen
        \pgfscope
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfpathmoveto{\pgfpointorigin}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpathmoveto{\pgfpoint{0pt}{0.5\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{-\pgf@circ@res@right}{\pgf@circ@res@up}}
            \pgfpathmoveto{\pgfpoint{0pt}{0.5\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
            \pgfpathmoveto{\pgfpoint{0pt}{0.5\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfusepath{draw}
        \endpgfscope
    }
}

\pgfdeclareshape{bareTXantenna}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor{\northeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/bareantenna/width}\pgf@circ@scaled@Rlen
        \pgf@x=\pgf@circ@res@step
        \pgf@y=2\pgf@circ@res@step
    }
    \savedanchor{\savedwaves}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/bareantenna/width}\pgf@circ@scaled@Rlen
        \pgf@x=4.2\pgf@circ@res@step
        \pgf@y=\pgf@circ@res@step
    }
    \anchor{text}{
        \northeast
        \pgf@x=\ctikzvalof{monopoles/bareantenna/label/xanchor}\pgf@x
        \pgf@y=\ctikzvalof{monopoles/bareantenna/label/yanchor}\pgf@y
        \pgf@x=\dimexpr-\pgf@x-\wd\pgfnodeparttextbox\relax
        \pgf@y=\dimexpr\pgf@y+.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \anchor{waves}{\savedwaves}
    \anchor{top}{\northeast\pgf@x=0pt}
    \anchor{right}{\northeast\pgf@y=0.5\pgf@y}
    \anchor{left}{\northeast\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{bottom}{\pgfpointorigin}
    \anchor{north}{\northeast\pgf@x=0pt}
    \anchor{east}{\northeast\pgf@y=0.5\pgf@y}
    \anchor{west}{\northeast\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{south}{\pgfpointorigin}
    \anchor{north east}{\northeast}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast\pgf@y=0pt\relax}
    \anchor{south west}{\northeast\pgf@y=0pt\pgf@x=-\pgf@x}
    \pgf@circ@draw@component{
        \pgf@circ@antennabody
        \pgf@circ@antennawaves
    }
}

\pgfdeclareshape{bareRXantenna}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor{\northeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/bareantenna/width}\pgf@circ@scaled@Rlen
        \pgf@x=\pgf@circ@res@step
        \pgf@y=2\pgf@circ@res@step
    }
    \savedanchor{\savedwaves}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/bareantenna/width}\pgf@circ@scaled@Rlen
        \pgf@x=-4.2\pgf@circ@res@step
        \pgf@y=\pgf@circ@res@step
    }
    \anchor{text}{
        \northeast
        \pgf@x=\ctikzvalof{monopoles/bareantenna/label/xanchor}\pgf@x
        \pgf@y=\ctikzvalof{monopoles/bareantenna/label/yanchor}\pgf@y
        \pgf@y=\dimexpr\pgf@y+.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \anchor{waves}{\savedwaves}
    \anchor{top}{\northeast\pgf@x=0pt}
    \anchor{right}{\northeast\pgf@y=0.5\pgf@y}
    \anchor{left}{\northeast\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{bottom}{\pgfpointorigin}
    \anchor{north}{\northeast\pgf@x=0pt}
    \anchor{east}{\northeast\pgf@y=0.5\pgf@y}
    \anchor{west}{\northeast\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{south}{\pgfpointorigin}
    \anchor{north east}{\northeast}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast\pgf@y=0pt\relax}
    \anchor{south west}{\northeast\pgf@y=0pt\pgf@x=-\pgf@x}
    \pgf@circ@draw@component{
        \pgf@circ@antennabody
        \pgftransformxshift{-5.2\pgf@circ@res@step}
        \pgf@circ@antennawaves
    }
}

%%% dynodes (see https://github.com/circuitikz/circuitikz/issues/469)
\ctikzset{monopoles/dynode/width/.initial=0.4}
\ctikzset{monopoles/dynode/height/.initial=0.8}
\ctikzset{monopoles/dynode/arc pos/.initial=0.5}
\ctikzset{monopoles/dynode/arc angle/.initial=30}
\ctikzset{monopoles/dynode/top width/.initial=1.0}

\pgfdeclareshape{dynode}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{tubes}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor{\northeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=\ctikzvalof{monopoles/dynode/width}\pgf@circ@scaled@Rlen
        \pgf@x=0.5\pgf@x
        \pgf@y=\ctikzvalof{monopoles/dynode/height}\pgf@circ@scaled@Rlen
    }
    \savedanchor{\arcpos}{% bottom part of the arc pos
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=0pt
        \pgf@y=\ctikzvalof{monopoles/dynode/height}\pgf@circ@scaled@Rlen
        \pgf@y=\ctikzvalof{monopoles/dynode/arc pos}\pgf@y
    }
    \savedanchor{\topright}{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=\ctikzvalof{monopoles/dynode/width}\pgf@circ@scaled@Rlen
        \pgf@x=\ctikzvalof{monopoles/dynode/top width}\pgf@x
        \pgf@x=0.5\pgf@x
        \pgf@y=\ctikzvalof{monopoles/dynode/height}\pgf@circ@scaled@Rlen
    }
    \anchor{arc}{\arcpos}
    \anchor{top right}{\topright}
    \anchor{top left}{\topright\pgf@x=-\pgf@x}
    \anchor{text}{
        \northeast
        \advance\pgf@x by 4pt\relax
        \pgf@y=\dimexpr0.5\pgf@y+.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \anchor{top}{\northeast\pgf@x=0pt}
    \anchor{right}{\northeast\pgf@y=0.5\pgf@y}
    \anchor{left}{\northeast\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{bottom}{\pgfpointorigin}
    \anchor{north}{\northeast\pgf@x=0pt}
    \anchor{east}{\northeast\pgf@y=0.5\pgf@y}
    \anchor{west}{\northeast\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{south}{\pgfpointorigin}
    \anchor{north east}{\northeast}
    \anchor{north west}{\northeast\pgf@x=-\pgf@x}
    \anchor{south east}{\northeast\pgf@y=0pt\relax}
    \anchor{south west}{\northeast\pgf@y=0pt\pgf@x=-\pgf@x}
    \pgf@circ@draw@component{
        \pgfstartlinewidth=\pgflinewidth
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@setcolor
        \northeast
        \pgf@circ@res@right=\pgf@x
        \pgf@circ@res@up=\pgf@y
        \arcpos
        \pgf@circ@res@step=\pgf@y
        % top
        \pgfscope
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfpathmoveto{\pgfpoint{-\ctikzvalof{monopoles/dynode/top width}*\pgf@circ@res@right}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\ctikzvalof{monopoles/dynode/top width}*\pgf@circ@res@right}{\pgf@circ@res@up}}
            \pgfusepath{draw}
        \endpgfscope
        % arc
        \edef\@@angle{\ctikzvalof{monopoles/dynode/arc angle}}
        \ifnum90=\@@angle\else % avoid divisions by zero
            % radius
            \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@res@right/cos(\@@angle)}
            % start angle y position
            \pgfmathsetlength{\pgf@circ@res@step}{\pgf@circ@res@step+\pgf@circ@res@other*(1-sin(\@@angle))}
            \pgfsetlinewidth{\pgfstartlinewidth}
            \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\pgf@circ@res@step}}
            \pgfpatharc{-180+\@@angle}{-\@@angle}{\pgf@circ@res@other}
        \fi
        % tail
        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfusepath{draw}
    }
}
% Microstrip monopoles

\pgfdeclareshape{mslstub}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor{\southeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=\ctikzvalof{bipoles/mstline/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@y=\ctikzvalof{bipoles/mstline/height}\pgf@circ@scaled@Rlen
        \pgf@y=-.5\pgf@y
    }
    \savedanchor{\northwest}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=\ctikzvalof{bipoles/mstline/width}\pgf@circ@scaled@Rlen
        \pgf@x=-.5\pgf@x
        \pgf@y=\ctikzvalof{bipoles/mstline/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
    }
    \anchor{north}{\northwest\pgf@x=0pt\relax}
    \anchor{north east}{\northwest\pgf@x=-\pgf@x}
    \anchor{east}{\southeast\pgf@y=0pt\relax}
    \anchor{south east}{\southeast}
    \anchor{south}{\southeast\pgf@x=0pt\relax}
    \anchor{south west}{\southeast\pgf@x=-\pgf@x}
    \anchor{west}{\northwest\pgf@y=0pt\relax}
    \anchor{north west}{\northwest}
    %
    \anchor{center}{\northwest\pgf@y=0pt\relax}
    \anchor{left}{\northwest\pgf@y=0pt\relax}
    \anchor{right}{\southeast\pgf@y=0pt\relax}
    % put the node text above and centered
    \anchor{text}{\pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfpoint{-.5\wd\pgfnodeparttextbox}{
            \dimexpr.5\dp\pgfnodeparttextbox+.5\ht\pgfnodeparttextbox+\pgf@circ@res@up\relax
        }
    }
    \pgf@circ@draw@component{
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfextractx{\pgf@circ@res@right}{\southeast}
        \pgfextractx{\pgf@circ@res@left}{\northwest}
        \pgfextracty{\pgf@circ@res@down}{\southeast}
        \pgfmathsetlength{\pgf@circ@res@step}{0.25*\pgf@circ@res@up}
        \pgfstartlinewidth=\pgflinewidth
        \pgfscope
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgf@circ@draworfill
        \endpgfscope
    }
}

\pgfdeclareshape{msrstub}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor{\southeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=\ctikzvalof{monopoles/msrstub/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@y=0pt\relax
    }
    \savedanchor{\northwest}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=\ctikzvalof{monopoles/msrstub/width}\pgf@circ@scaled@Rlen
        \pgf@x=-.5\pgf@x
        \pgf@y=\ctikzvalof{monopoles/msrstub/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
    }
    \anchor{north}{\northwest\pgf@x=0pt\relax}
    \anchor{north east}{\northwest\pgf@x=-\pgf@x}
    \anchor{east}{\southeast\pgf@y=0pt\relax}
    \anchor{south east}{\southeast}
    \anchor{south}{\southeast\pgf@x=0pt\relax}
    \anchor{south west}{\southeast\pgf@x=-\pgf@x}
    \anchor{west}{\northwest\pgf@y=0pt\relax}
    \anchor{north west}{\northwest}
    %
    \anchor{center}{\pgfpointorigin}
    \anchor{left}{\pgfpointorigin}
    \anchor{right}{\pgfpointorigin}
    % put the node text above and centered
    \anchor{text}{\pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfpoint{-.5\wd\pgfnodeparttextbox}{
            \dimexpr.5\dp\pgfnodeparttextbox+.5\ht\pgfnodeparttextbox+\pgf@circ@res@up\relax
        }
    }
    \pgf@circ@draw@component{
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfextractx{\pgf@circ@res@right}{\southeast}
        \pgfextractx{\pgf@circ@res@left}{\northwest}
        \pgfextracty{\pgf@circ@res@down}{\southeast}
        \pgfmathsetlength{\pgf@circ@res@step}{0.25*\pgf@circ@res@up}
        \pgfstartlinewidth=\pgflinewidth
        \pgfscope
            \pgfpathmoveto{\pgfpointorigin}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@step}}
            \pgfusepath{draw}
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfpathmoveto{\pgfpointpolar{135}{\pgf@circ@res@step}}
            \pgfpatharc{135}{45}{\pgf@circ@res@step}
            \pgfpathlineto{\pgfpointpolar{45}{\pgf@circ@res@up}}
            \pgfpatharc{45}{135}{\pgf@circ@res@up}
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope
    }
}

\pgfdeclareshape{msport}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor{\southeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=\ctikzvalof{monopoles/msport/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@y=\ctikzvalof{bipoles/mstline/height}\pgf@circ@scaled@Rlen
        \pgf@y=-.5\pgf@y
    }
    \savedanchor{\northwest}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=\ctikzvalof{monopoles/msport/width}\pgf@circ@scaled@Rlen
        \pgf@x=-.5\pgf@x
        \pgf@y=\ctikzvalof{bipoles/mstline/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
    }
    \anchor{north}{\northwest\pgf@x=0pt\relax}
    \anchor{north east}{\northwest\pgf@x=-\pgf@x}
    \anchor{east}{\southeast\pgf@y=0pt\relax}
    \anchor{south east}{\southeast}
    \anchor{south}{\southeast\pgf@x=0pt\relax}
    \anchor{south west}{\southeast\pgf@x=-\pgf@x}
    \anchor{west}{\northwest\pgf@y=0pt\relax}
    \anchor{north west}{\northwest}
    %
    \anchor{center}{\northwest\pgf@y=0pt\relax}
    \anchor{left}{\northwest\pgf@y=0pt\relax}
    \anchor{right}{\southeast\pgf@y=0pt\relax}
    % put the node text above and centered
    \anchor{text}{\pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfpoint{-.5\wd\pgfnodeparttextbox}{
            \dimexpr-.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
        }
    }
    \pgf@circ@draw@component{
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfextractx{\pgf@circ@res@right}{\southeast}
        \pgfextractx{\pgf@circ@res@left}{\northwest}
        \pgfextracty{\pgf@circ@res@down}{\southeast}
        \pgfmathsetlength{\pgf@circ@res@step}{0.5*\pgf@circ@res@up}
        \pgfstartlinewidth=\pgflinewidth
        \pgfscope
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@step}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@step}{\pgf@circ@res@down}}
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope
    }
}

% Legacy antennas (with tails)
\def\pgf@circ@shift@antenna@xy#1#2{%
    \pgf@y=\dimexpr\pgf@y+#2\pgf@circ@res@step
    \pgf@x=\dimexpr\pgf@x+#1\pgf@circ@res@step
\relax}

% Legacy antenna
\pgfdeclareshape{antenna}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor{\northeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/antenna/width}\pgf@circ@scaled@Rlen
        \pgf@x=\pgf@circ@res@step%-0.5\pgflinewidth
        \pgf@y=4\pgf@circ@res@step
    }
    \anchor{north}{\northeast\pgf@circ@res@step=\pgf@x\pgf@x=0cm\pgf@circ@shift@antenna@xy{0}{2}}
    \anchor{east}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=0cm\pgf@circ@shift@antenna@xy{0}{3}\relax}
    \anchor{south}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=-\pgf@y \pgf@x=0cm\pgf@circ@shift@antenna@xy{0}{4}\relax}
    \anchor{west}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=0cm\pgf@x=-\pgf@x\pgf@circ@shift@antenna@xy{0}{3}}
    \anchor{north east}{\northeast\pgf@circ@res@step=\pgf@x\pgf@circ@shift@antenna@xy{0}{2}}
    \anchor{north west}{\northeast\pgf@circ@res@step=\pgf@x\pgf@x=-\pgf@x\pgf@circ@shift@antenna@xy{0}{2}}
    \anchor{south east}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=-\pgf@y\pgf@circ@shift@antenna@xy{0}{4}}
    \anchor{south west}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=-\pgf@y\pgf@x=-\pgf@x\pgf@circ@shift@antenna@xy{0}{4}}
    \anchor{text}{
        \northeast
        \pgf@x=\ctikzvalof{monopoles/antenna/label/xanchor}\pgf@x
        \pgf@y=\ctikzvalof{monopoles/antenna/label/yanchor}\pgf@y
    }
    \pgf@circ@draw@component{
        \pgfstartlinewidth=\pgflinewidth
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{monopoles/antenna/width}\pgf@circ@scaled@Rlen

        \pgftransformxshift{ -4\pgf@circ@res@step }

        \pgfpathmoveto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{0pt}}
        \pgfpathlineto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}

        \pgfusepath{draw}

        \pgfscope
            \pgfpathmoveto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{5\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{4\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{3\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}
            \pgf@circ@setcolor
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfusepath{draw}
        \endpgfscope
        \pgfsetlinewidth{\pgfstartlinewidth}

    }
}

% Legacy TX antenna
\pgfdeclareshape{txantenna}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor{\northeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/antenna/width}\pgf@circ@scaled@Rlen
        \pgf@x=\pgf@circ@res@step%-0.5\pgflinewidth
        \pgf@y=4\pgf@circ@res@step
    }
    \anchor{north}{\northeast\pgf@circ@res@step=\pgf@x\pgf@x=0cm\pgf@circ@shift@antenna@xy{2}{2}}
    \anchor{east}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=0cm\pgf@circ@shift@antenna@xy{4}{3}\relax}
    \anchor{south}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=-\pgf@y \pgf@x=0cm\pgf@circ@shift@antenna@xy{2}{4}\relax}
    \anchor{west}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=0cm\pgf@x=-\pgf@x\pgf@circ@shift@antenna@xy{1}{3}}
    \anchor{north east}{\northeast\pgf@circ@res@step=\pgf@x\pgf@circ@shift@antenna@xy{4}{2}}
    \anchor{north west}{\northeast\pgf@circ@res@step=\pgf@x\pgf@x=-\pgf@x\pgf@circ@shift@antenna@xy{1}{2}}
    \anchor{south east}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=-\pgf@y\pgf@circ@shift@antenna@xy{4}{4}}
    \anchor{south west}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=-\pgf@y\pgf@x=-\pgf@x\pgf@circ@shift@antenna@xy{1}{4}}
    \anchor{text}{
        \northeast
        \pgf@x=\ctikzvalof{monopoles/txantenna/label/xanchor}\pgf@x
        \pgf@y=\ctikzvalof{monopoles/txantenna/label/yanchor}\pgf@y
    }
    \pgf@circ@draw@component{
        \pgfstartlinewidth=\pgflinewidth
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{monopoles/txantenna/width}\pgf@circ@scaled@Rlen

        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpoint{4\pgf@circ@res@step}{0pt}}
        \pgfpathmoveto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{0pt}}
        \pgfpathlineto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}

        \pgfusepath{draw}

        \pgfscope
            \pgfpathmoveto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{5\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{4\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{3\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}
            \pgf@circ@setcolor
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfusepath{draw}
        \endpgfscope
        \pgfpathmoveto{\pgfpoint{5.5\pgf@circ@res@step}{6\pgf@circ@res@step}}
        %        \pgfpatharc{60}{-60}{\pgf@circ@res@step and \pgf@circ@res@step}
        \pgfpatharc{30}{-30}{2\pgf@circ@res@step}         \pgfpathmoveto{\pgfpoint{6\pgf@circ@res@step}{6.25\pgf@circ@res@step}}
        \pgfpatharc{30}{-30}{2.5\pgf@circ@res@step}
        \pgfpathmoveto{\pgfpoint{6.5\pgf@circ@res@step}{6.5\pgf@circ@res@step}}
        \pgfpatharc{30}{-30}{3\pgf@circ@res@step}
        \pgfpathmoveto{\pgfpoint{7\pgf@circ@res@step}{6.75\pgf@circ@res@step}}
        \pgfpatharc{30}{-30}{3.5\pgf@circ@res@step}
        \pgfpathmoveto{\pgfpoint{7.5\pgf@circ@res@step}{7\pgf@circ@res@step}}
        \pgfpatharc{30}{-30}{4\pgf@circ@res@step}
        \pgfusepath{draw}
        \pgfsetlinewidth{\pgfstartlinewidth}

    }
}

% Legacy RX antenna
\pgfdeclareshape{rxantenna}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor{\northeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step=\ctikzvalof{monopoles/antenna/width}\pgf@circ@scaled@Rlen
        \pgf@x=\pgf@circ@res@step%-0.5\pgflinewidth
        \pgf@y=4\pgf@circ@res@step
    }
    \anchor{north}{\northeast\pgf@circ@res@step=\pgf@x\pgf@x=0cm\pgf@circ@shift@antenna@xy{2}{2}}
    \anchor{east}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=0cm\pgf@circ@shift@antenna@xy{4}{3}\relax}
    \anchor{south}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=-\pgf@y \pgf@x=0cm\pgf@circ@shift@antenna@xy{2}{4}\relax}
    \anchor{west}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=0cm\pgf@x=-\pgf@x\pgf@circ@shift@antenna@xy{1}{3}}
    \anchor{north east}{\northeast\pgf@circ@res@step=\pgf@x\pgf@circ@shift@antenna@xy{4}{2}}
    \anchor{north west}{\northeast\pgf@circ@res@step=\pgf@x\pgf@x=-\pgf@x\pgf@circ@shift@antenna@xy{1}{2}}
    \anchor{south east}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=-\pgf@y\pgf@circ@shift@antenna@xy{4}{4}}
    \anchor{south west}{\northeast\pgf@circ@res@step=\pgf@x\pgf@y=-\pgf@y\pgf@x=-\pgf@x\pgf@circ@shift@antenna@xy{1}{4}}
    \anchor{text}{
        \northeast
        \pgf@x=\ctikzvalof{monopoles/rxantenna/label/xanchor}\pgf@x
        \pgf@y=\ctikzvalof{monopoles/rxantenna/label/yanchor}\pgf@y
    }
    \pgf@circ@draw@component{
        \pgfstartlinewidth=\pgflinewidth
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{monopoles/rxantenna/width}\pgf@circ@scaled@Rlen

        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpoint{4\pgf@circ@res@step}{0pt}}
        \pgfpathmoveto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{0pt}}
        \pgfpathlineto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}

        \pgfusepath{draw}

        \pgfscope
            \pgfpathmoveto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{5\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{4\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{3\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{4\pgf@circ@res@step-0.5\pgflinewidth}{6\pgf@circ@res@step}}
            \pgf@circ@setcolor
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfusepath{draw}
        \endpgfscope

        \pgfpathmoveto{\pgfpoint{6\pgf@circ@res@step}{7\pgf@circ@res@step}}
        %             \pgfpatharc{60}{-60}{\pgf@circ@res@step and \pgf@circ@res@step}
        \pgfpatharc{150}{210}{4\pgf@circ@res@step}              \pgfpathmoveto{\pgfpoint{6.5\pgf@circ@res@step}{6.75\pgf@circ@res@step}}
        \pgfpatharc{150}{210}{3.5\pgf@circ@res@step}
        \pgfpathmoveto{\pgfpoint{7\pgf@circ@res@step}{6.5\pgf@circ@res@step}}
        \pgfpatharc{150}{210}{3\pgf@circ@res@step}
        \pgfpathmoveto{\pgfpoint{7.5\pgf@circ@res@step}{6.25\pgf@circ@res@step}}
        \pgfpatharc{150}{210}{2.5\pgf@circ@res@step}
        \pgfpathmoveto{\pgfpoint{8\pgf@circ@res@step}{6\pgf@circ@res@step}}
        \pgfpatharc{150}{210}{2\pgf@circ@res@step}
        \pgfusepath{draw}
        \pgfsetlinewidth{\pgfstartlinewidth}
    }
}

% Legacy match
\pgfdeclareshape{match}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{RF}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor{\northeast}{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step = \ctikzvalof{monopoles/match/width} \pgf@circ@scaled@Rlen
        \pgf@x=2\pgf@circ@res@step
        \pgf@circ@res@step = \ctikzvalof{monopoles/match/width} \pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@circ@res@step%
    }
    % the center is on the left side of the shape for facility of usage
    \anchor{north}{\northeast\pgf@x=0.5\pgf@x\relax}
    \anchor{east}{\northeast\pgf@y=0cm\relax}
    \anchor{south}{\northeast\pgf@y=0pt\pgf@x=0.5\pgf@x\relax}
    \anchor{west}{\pgfpointorigin}
    \anchor{north east}{\northeast}
    \anchor{north west}{\northeast\pgf@x=0cm\relax}
    \anchor{south east}{\northeast\pgf@y=0pt\relax}
    \anchor{south west}{\pgfpointorigin}
    \anchor{center}{
        \pgfpointorigin
    }
    \anchor{text}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=\ctikzvalof{monopoles/match/width}\pgf@circ@scaled@Rlen
        \pgf@x=1.5\pgf@x
        \advance \pgf@x by -.5\wd\pgfnodeparttextbox
        \pgf@y=-1.5\ht\pgfnodeparttextbox
    }
    \pgf@circ@draw@component{
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{monopoles/match/width}\pgf@circ@scaled@Rlen

        \pgfscope
            \pgfpathmoveto{\pgfpointorigin}
            \pgfpathlineto{\pgfpoint{2\pgf@circ@res@step}{0pt}}
            \pgfusepath{draw}

            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{2\pgf@circ@res@step}{0.5\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{2\pgf@circ@res@step}{0}}
            \pgf@circ@fill@strokecolor
            \pgfusepath{fill}

            \pgfsetlinewidth{\pgfstartlinewidth}
        \endpgfscope
    }
}
% %>>>

% vim: set fdm=marker fmr=%<<<,%>>>:
%%%---------- close: tex/pgfcircmonopoles
%%%%%%%%%%% Springe nach tex/pgfcircbipoles
%%%---------- open: tex/pgfcircbipoles.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Standard bipole shapes declarations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Generic macro and flags for bipoles %<<<
% Fixing tunable directions
\newif\ifpgf@circ@fixtunable@dir
\ctikzset{bipoles/fix tunable direction/.is if=pgf@circ@fixtunable@dir}
\ctikzset{bipoles/fix tunable direction=true}
% choosing several arrows
\pgf@circ@declare@family@arrows{tunable}
\pgf@circ@declare@family@arrows{wiper}
\pgf@circ@declare@family@arrows{switch}
\pgf@circ@declare@family@arrows{gto gate}
\pgf@circ@declare@family@arrows{opto}

%>>>


%%%%%%%%%%%%%%%%%%%%%%%%
% Resistive components: generics, resistors, wires
%%%%%%%%%%%%%%%%%%%%%%%%

%% Definitions for resistive components %<<<

% Zig Zag resistors
\ctikzset{resistors/zigs/.initial=3}
\ctikzset{resistors/width/.code={%
    \ctikzset{bipoles/resistor/width=#1}%
    \ctikzset{bipoles/vresistor/width=#1}%
    \ctikzset{bipoles/potentiometer/width=#1}%
    \ctikzset{bipoles/resistivesens/width=#1}%
    \ctikzset{bipoles/photoresistor/width=#1}%
    \ctikzset{bipoles/thermistor/width=#1}%
    \ctikzset{bipoles/thermistorntc/width=#1}%
    \ctikzset{bipoles/thermistorptc/width=#1}%
    \ctikzset{bipoles/varistor/width=#1}%
    \ctikzset{bipoles/generic/width=#1}%
    \ctikzset{bipoles/generic potentiometer/width=#1}%
    \ctikzset{bipoles/ageneric/width=#1}%
    \ctikzset{bipoles/tgeneric/width=#1}%
    \ctikzset{bipoles/ldresistor/width=#1}%
    \ctikzset{bipoles/ldgeneric/width=#1}%
}}
\ctikzset{wiper pos/.code={%
    \ctikzset{bipoles/potentiometer/wiper pos=#1}%
    \ctikzset{bipoles/generic potentiometer/wiper pos=#1}%
}}
% zigzag resistor
\ctikzset{bipoles/resistor/height/.initial=.3}
\ctikzset{bipoles/resistor/width/.initial=.8}
\ctikzset{bipoles/potentiometer/height/.initial=.8}
\ctikzset{bipoles/potentiometer/height 2/.initial=.3}
\ctikzset{bipoles/potentiometer/width/.initial=.8}
\ctikzset{bipoles/potentiometer/wiper pos/.initial=.5}
\ctikzset{bipoles/vresistor/height/.initial=.6}
\ctikzset{bipoles/vresistor/width/.initial=.8}
\ctikzset{bipoles/resistivesens/height/.initial=.6}
\ctikzset{bipoles/resistivesens/width/.initial=.8}
\ctikzset{bipoles/ldresistor/height/.initial=.8}
\ctikzset{bipoles/ldresistor/width/.initial=.8}
\ctikzset{bipoles/ldresistor/internal scale/.initial=.8}
% square resistors
\ctikzset{bipoles/photoresistor/height/.initial=.6}
\ctikzset{bipoles/photoresistor/height 2/.initial=.3}
\ctikzset{bipoles/photoresistor/width/.initial=.8}
\ctikzset{bipoles/thermistor/main/.initial=.7}
\ctikzset{bipoles/thermistor/height/.initial=.428}%.3/.7
\ctikzset{bipoles/thermistorntc/width/.initial=.8}
\ctikzset{bipoles/thermistorntc/main/.initial=.7}
\ctikzset{bipoles/thermistorntc/height/.initial=.428}%.3/.7
\ctikzset{bipoles/thermistorntc/height 2/.initial=.75}%.3/.7
\ctikzset{bipoles/thermistorptc/width/.initial=.8}
\ctikzset{bipoles/thermistorptc/main/.initial=.7}
\ctikzset{bipoles/thermistorptc/height/.initial=.428}%.3/.7
\ctikzset{bipoles/thermistorptc/height 2/.initial=.75}%.3/.7
\ctikzset{bipoles/thermistor/width/.initial=.8}
\ctikzset{bipoles/varistor/main/.initial=.7}
\ctikzset{bipoles/varistor/height/.initial=.428}%.3/.7
\ctikzset{bipoles/varistor/width/.initial=.8}
\ctikzset{bipoles/generic/height/.initial=.30}
\ctikzset{bipoles/generic/width/.initial=.80}
\ctikzset{bipoles/generic potentiometer/height/.initial=.80}
\ctikzset{bipoles/generic potentiometer/height 2/.initial=.30}
\ctikzset{bipoles/generic potentiometer/width/.initial=.80}
\ctikzset{bipoles/generic potentiometer/wiper pos/.initial=.5}
\ctikzset{bipoles/ageneric/height/.initial=.30}
\ctikzset{bipoles/tgeneric/height/.initial=.70}
\ctikzset{bipoles/tgeneric/width/.initial=.80}
\ctikzset{bipoles/ageneric/width/.initial=.80}
\ctikzset{bipoles/memristor/height/.initial=.30}
\ctikzset{bipoles/memristor/wave height/.initial=.5}
\ctikzset{bipoles/memristor/width/.initial=.80}
\ctikzset{bipoles/ldgeneric/height/.initial=.8}
\ctikzset{bipoles/ldgeneric/width/.initial=.8}
\ctikzset{bipoles/ldgeneric/internal scale/.initial=.8}

\newif\ifpgf@circuit@europeanresistor
\ctikzset{resistor/.is choice}
\ctikzset{resistor/american/.code = \pgf@circuit@europeanresistorfalse }
\ctikzset{resistor/european/.code = \pgf@circuit@europeanresistortrue }
\tikzset{american resistors/.style = {\circuitikzbasekey/resistor = american}}
\tikzset{european resistors/.style = {\circuitikzbasekey/resistor = european}}%

% wires (open, shorts, ...)

\ctikzset{bipoles/open/height/.initial=.3} %necessary for curly voltages
\ctikzset{bipoles/open/width/.initial=.3} %necessary for curly voltages
\ctikzset{bipoles/open/voltage/straight label distance/.initial=0}
\ctikzset{bipoles/open/voltage/distance from node/.initial=.2}
\ctikzset{bipoles/short/height/.initial=.1} %dummy height for voltage positioning
\ctikzset{bipoles/short/width/.initial=.1} %dummy width for voltage positioning
% multiwire
\ctikzset{bipoles/multiwire/height/.initial=0.4}
\ctikzset{bipoles/multiwire/width/.initial=0.2}
\ctikzset{bipoles/multiwire/spacing/.initial=0.05}
% crossing wires
\ctikzset{bipoles/crossing/size/.initial=.2}

%%>>>

%% Shapes for generic, resistives and wires components %<<<
%% Short circuit

%%% NOTICE that the short is really NOT drawn; we trust the fact that its
%%% natural length is zero.
\pgfcircdeclarebipole
{% fix the anchor border to add a bit of space for voltage and labels
    % it uses the dummy width and height
    \anchorborder{%
        \ifpgf@circuit@bipole@inverted
            \pgf@circ@res@left=-\pgf@x
            \pgf@circ@res@up=-\pgf@y
        \else
            \pgf@circ@res@left=\pgf@x
            \pgf@circ@res@up=\pgf@y
        \fi
        \ifdim\pgf@circ@res@up>0cm
            \pgf@x=\ctikzvalof{bipoles/short/width}\pgf@circ@Rlen
            \pgf@y=\ctikzvalof{bipoles/short/height}\pgf@circ@Rlen
            \pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            {\pgfpoint{\pgf@x}{\pgf@y}}
        \else
            \pgf@x=-\ctikzvalof{bipoles/short/width}\pgf@circ@Rlen
            \pgf@y=-\ctikzvalof{bipoles/short/height}\pgf@circ@Rlen
            \pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            {\pgfpoint{-\pgf@x}{-\pgf@y}}
        \fi
    }
}
{0}
{short}
{0}
{0}
{}

%% Open circuit
\pgfcircdeclarebipole
{}
{\ctikzvalof{bipoles/open/height}}
{open}
{\ctikzvalof{bipoles/open/height}}
{\ctikzvalof{bipoles/open/width}}
{}

% multiwire(s)
\pgfcircdeclarebipole
{}
{\ctikzvalof{bipoles/multiwire/height}}
{multiwire}
{\ctikzvalof{bipoles/multiwire/height}}
{\ctikzvalof{bipoles/multiwire/width}}
{
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
}

\pgfcircdeclarebipole
{}
{\ctikzvalof{bipoles/multiwire/height}}
{bmultiwire}
{\ctikzvalof{bipoles/multiwire/height}}
{\ctikzvalof{bipoles/multiwire/width}}
{
    \pgf@circ@res@other=\ctikzvalof{bipoles/multiwire/spacing}\pgf@circ@Rlen
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@other}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
}

\pgfcircdeclarebipole
{}
{\ctikzvalof{bipoles/multiwire/height}}
{tmultiwire}
{\ctikzvalof{bipoles/multiwire/height}}
{\ctikzvalof{bipoles/multiwire/width}}
{
    \pgf@circ@res@other=\ctikzvalof{bipoles/multiwire/spacing}\pgf@circ@Rlen
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@other}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left+2\pgf@circ@res@other}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{2\pgf@circ@res@other}{\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
}

%%%%%%%%%%%%%%%%
%% Crossing
%%%%%%%%%%%%%%%%

%% crossing bipole (but see also nodes)
\pgfcircdeclarebipole
{}
{\ctikzvalof{bipoles/crossing/size}}
{crossing}
{\ctikzvalof{bipoles/crossing/size}}
{\ctikzvalof{bipoles/crossing/size}}{
    \pgfscope
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{0.4\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgfpatharc{0}{-180}{0.4*\pgf@circ@res@left}
        \pgfsetbeveljoin
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
        \pgfusepath{draw}
    \endpgfscope
}
%
%
%% Generic bipole - used as resistor by some
\pgfcircdeclarebipolescaled{resistors}
{}
{\ctikzvalof{bipoles/generic/height}}
{generic}
{\ctikzvalof{bipoles/generic/height}}
{\ctikzvalof{bipoles/generic/width}}
{
    % \pgf@circ@debug@colors
    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@draworfill
}

%
% generic crossed, suggested by Radványi Patrik Tamás <patrikradvanyi@gmail.com>
% inherit "generic" properties
%
\pgfcircdeclarebipolescaled{resistors}
{}
{\ctikzvalof{bipoles/generic/height}}
{xgeneric}
{\ctikzvalof{bipoles/generic/height}}
{\ctikzvalof{bipoles/generic/width}}
{
    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@draworfill
    % cross it
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfusepath{draw}
}
%
% generic slashed, suggested by Jana on TeX.stackexchange.com
% https://tex.stackexchange.com/questions/711702/european-relay-with-circuitikz
% inherit "generic" properties
%
\pgfcircdeclarebipolescaled{resistors}
{}
{\ctikzvalof{bipoles/generic/height}}
{sgeneric}
{\ctikzvalof{bipoles/generic/height}}
{\ctikzvalof{bipoles/generic/width}}
{
    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@draworfill
    % slash it
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfusepath{draw}
}
%% Generic empty tunable
\pgfcircdeclarebipolescaled{resistors}
{
    \anchor{wiper}{\northeast\pgf@x=-0.5\pgf@x\pgf@y=-\pgf@y}
    \anchor{W}{\northeast\pgf@x=-0.5\pgf@x\pgf@y=-\pgf@y}
    \anchor{tip}{\northeast\pgf@x=0.5\pgf@x}
}
{\ctikzvalof{bipoles/tgeneric/height}}
{tgeneric}
{\ctikzvalof{bipoles/tgeneric/height}}
{\ctikzvalof{bipoles/tgeneric/width}}
{
    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{.4\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{.4\pgf@circ@res@down}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@draworfill
    \pgfscope
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfcirc@set@arrows{tunable}{}{latexslim}
        \ifpgf@circ@fixtunable@dir
            \pgfpathmoveto{\pgfpoint{.5\pgf@circ@res@left}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{-.5\pgf@circ@res@left}{\pgf@circ@res@up}}
        \else
            \pgfpathmoveto{\pgfpoint{.5\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{-.5\pgf@circ@res@left}{\pgf@circ@res@down}}
        \fi
        \pgfusepath{draw}
    \endpgfscope
}

%% Generic asymmetric bipole
\pgfcircdeclarebipolescaled{resistors}
{}
{\ctikzvalof{bipoles/ageneric/height}}
{ageneric}
{\ctikzvalof{bipoles/ageneric/height}}
{\ctikzvalof{bipoles/ageneric/width}}
{
    \pgfscope
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@draworfill
    \endpgfscope

    \pgfpathrectanglecorners{\pgfpoint{.7\pgf@circ@res@right}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{stroke,fill}
}

%% Memristor
\pgfcircdeclarebipolescaled{resistors}
{}
{\ctikzvalof{bipoles/memristor/height}}
{memristor}
{\ctikzvalof{bipoles/memristor/height}}
{\ctikzvalof{bipoles/memristor/width}}
{
    \pgf@circ@res@step = \ctikzvalof{bipoles/resistor/width}\pgf@circ@scaled@Rlen
    \divide \pgf@circ@res@step by 14

    \pgfscope
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@draworfill
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.72*\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.72*\pgf@circ@res@left}{\ctikzvalof{bipoles/memristor/wave height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{.35*\pgf@circ@res@left}{\ctikzvalof{bipoles/memristor/wave height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{.35*\pgf@circ@res@left}{-\ctikzvalof{bipoles/memristor/wave height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{-.05*\pgf@circ@res@left}{-\ctikzvalof{bipoles/memristor/wave height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{-.05*\pgf@circ@res@left}{\ctikzvalof{bipoles/memristor/wave height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{.42*\pgf@circ@res@right}{\ctikzvalof{bipoles/memristor/wave height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{.42*\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.8*\pgf@circ@res@right}{0pt}}

    \pgfusepath{draw}

    \pgfpathrectanglecorners{\pgfpoint{.7\pgf@circ@res@right}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{stroke,fill}
}

%% Photoresistor
\pgfcircdeclarebipolescaled{resistors}
{% anchor for light arrows
    \anchor{arrows}{\northeast\pgf@x=0.575\pgf@x\pgf@y=1.1\pgf@y}%
}
{\ctikzvalof{bipoles/photoresistor/height 2}}
{photoresistor}
{\ctikzvalof{bipoles/photoresistor/height}}
{\ctikzvalof{bipoles/photoresistor/width}}
{
    \pgfscope
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}{\pgfpoint{\pgf@circ@res@right}{-\pgf@circ@res@down}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@draworfill
    \endpgfscope

    \pgfscope
        \pgf@circ@set@optoarrow@style
        \pgfpathmoveto{\pgfpoint{.7\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.3\pgf@circ@res@right}{-1.2\pgf@circ@res@down}}
        \pgfusepath{draw}
        \pgfpathmoveto{\pgfpoint{.45\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.05\pgf@circ@res@right}{-1.2\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
}



%% Thermistor
\pgfcircdeclarebipolescaled{resistors}
{% anchor for labelling the type of dependency
    \anchor{label}{%
        \southwest
        \pgf@x=0.4\pgf@x
        \pgf@y=1.2\pgf@y
    }%
    \pgfcirc@border@extend@updown{1}{1.2}
    \anchor{wiper}{\northeast\pgf@x=-\pgf@x\pgf@y=-1.2\pgf@y}
    \anchor{W}{\northeast\pgf@x=-\pgf@x\pgf@y=-1.2\pgf@y}
    \anchor{tip}{\northeast}
}
{\ctikzvalof{bipoles/thermistor/height}}
{thermistor}
{\ctikzvalof{bipoles/thermistor/height}}
{\ctikzvalof{bipoles/thermistor/width}}
{
    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\ctikzvalof{bipoles/thermistor/main}\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{-\ctikzvalof{bipoles/thermistor/main}\pgf@circ@res@up}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@draworfill
    \pgf@circ@set@relative@thickness{modifier thickness}
    \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@left}{-\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@left}{1.2\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{1.2\pgf@circ@res@down}}
    \pgfusepath{draw}
}

%% Thermistor PTC
\pgfcircdeclarebipolescaled{resistors}
{}
{\ctikzvalof{bipoles/thermistorptc/height 2}}
{thermistorptc}
{\ctikzvalof{bipoles/thermistorptc/height}}
{\ctikzvalof{bipoles/thermistorptc/width}}
{
    \pgfscope
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\ctikzvalof{bipoles/thermistorptc/main}\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{-\ctikzvalof{bipoles/thermistorptc/main}\pgf@circ@res@up}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@draworfill
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@left}{-\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope

    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfsetarrowsend{latexslim}
    \pgfpathmoveto{\pgfpoint{.62\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{.62\pgf@circ@res@left}{.7\pgf@circ@res@down}}
    \pgfusepath{draw}
    \pgfpathmoveto{\pgfpoint{.45\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{.45\pgf@circ@res@left}{.7\pgf@circ@res@down}}
    \pgfusepath{draw}
    \pgf@circ@text@strokecolor
    \pgftext[top,x=.85\pgf@circ@res@left,y=.75\pgf@circ@res@down]{\pgf@circ@font@tiny$\vartheta$}
}

%% Thermistor NTC
\pgfcircdeclarebipolescaled{resistors}
{}
{\ctikzvalof{bipoles/thermistorntc/height 2}}
{thermistorntc}
{\ctikzvalof{bipoles/thermistorntc/height}}
{\ctikzvalof{bipoles/thermistorntc/width}}
{
    \pgfscope
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\ctikzvalof{bipoles/thermistorntc/main}\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{-\ctikzvalof{bipoles/thermistorntc/main}\pgf@circ@res@up}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@draworfill
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@left}{-\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope

    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfsetarrowsend{latexslim}
    \pgfpathmoveto{\pgfpoint{.62\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{.62\pgf@circ@res@left}{.7\pgf@circ@res@down}}
    \pgfusepath{draw}
    \pgfpathmoveto{\pgfpoint{.45\pgf@circ@res@left}{.7\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{.45\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfusepath{draw}
    \pgf@circ@text@strokecolor
    \pgftext[top,x=.85\pgf@circ@res@left,y=.75\pgf@circ@res@down]{\pgf@circ@font@tiny$\vartheta$}
}

%% Varistor
\pgfcircdeclarebipolescaled{resistors}
{
    \pgfcirc@border@extend@updown{1}{1.4}
}
{\ctikzvalof{bipoles/varistor/height}}
{varistor}
{\ctikzvalof{bipoles/varistor/height}}
{\ctikzvalof{bipoles/varistor/width}}
{
    \pgfscope
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\ctikzvalof{bipoles/varistor/main}\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{-\ctikzvalof{bipoles/varistor/main}\pgf@circ@res@up}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@draworfill
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@left}{-\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
    \pgf@circ@text@strokecolor
    \pgftext[top,x=.65\pgf@circ@res@left,y=1.2\pgf@circ@res@down]{{\pgf@circ@font@tiny\textsf{U}}}
}
%% MOV
\pgfcircdeclarebipolescaled{resistors}
{
    \pgfcirc@border@extend@updown{1.2}{1.2}
}
{\ctikzvalof{bipoles/varistor/height}}
{mov}
{\ctikzvalof{bipoles/varistor/height}}
{\ctikzvalof{bipoles/varistor/width}}
{
    \pgfscope
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\ctikzvalof{bipoles/varistor/main}\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{-\ctikzvalof{bipoles/varistor/main}\pgf@circ@res@up}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@draworfill
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@left}{-1.1\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{-0.7\pgf@circ@res@left}{-1.1\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{0.7\pgf@circ@res@left}{1.1\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{1.1\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
}
%% Generic tunable
\pgfcircdeclarebipolescaled{resistors}
{
    \savedanchor{\wiper}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@ya=\ctikzvalof{bipoles/generic potentiometer/height}\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@ya
            \pgf@xa=\ctikzvalof{bipoles/generic potentiometer/width}\pgf@circ@scaled@Rlen
            \pgfmathsetlength{\pgf@x}{(\ctikzvalof{bipoles/generic potentiometer/wiper pos}-0.5)*\pgf@xa}
        }
    \anchor{wiper}{\wiper}
    \anchor{W}{\wiper}
    \anchor{tip}{\wiper\pgf@xa=\pgf@x\southwest\pgf@x=\pgf@xa\pgf@y=-\pgf@y}
}
{\ctikzvalof{bipoles/generic potentiometer/height 2}}
{genericpotentiometer}
{\ctikzvalof{bipoles/generic potentiometer/height}}
{\ctikzvalof{bipoles/generic potentiometer/width}}
{

    \pgf@circ@res@step = \ctikzvalof{bipoles/resistor/width}\pgf@circ@scaled@Rlen
    \divide \pgf@circ@res@step by 14

    \pgfscope
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@down}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@draworfill
    \endpgfscope
    \pgfscope
        %\pgfsetlinewidth{\pgfstartlinewidth}
        \pgfcirc@set@arrows{wiper}{}{latexslim}
        \pgfextractx{\pgf@circ@res@other}{\wiper}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{-\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
}

%% european style LDR
\pgfcircdeclarebipolescaled{resistors}
{% anchor for light arrows
    \anchor{arrows}{\northeast\pgf@x=1.6\pgf@x\pgf@y=1.4\pgf@y}%
    \savedmacro{\zigs}{\edef\zigs{\ctikzvalof{resistors/zigs}}}
}
{\ctikzvalof{bipoles/ldgeneric/height}}
{ldgeneric}
{\ctikzvalof{bipoles/ldgeneric/height}}
{\ctikzvalof{bipoles/ldgeneric/width}}
{%
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
        \pgf@circ@draworfill
    \endpgfscope
    \pgfscope
        % arrows
        \pgf@circ@set@optoarrow@style
        \pgfpathmoveto{\pgfpoint{1.4\pgf@circ@res@right}{1.4\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0.8\pgf@circ@res@right}{0.8\pgf@circ@res@up}}
        \pgfusepath{draw}
        \pgfpathmoveto{\pgfpoint{1.6\pgf@circ@res@right}{1.2\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{1.0\pgf@circ@res@right}{0.6\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
    \edef\@@intscale{\ctikzvalof{bipoles/ldgeneric/internal scale}}%
    \pgfmathsetmacro{\@@hscale}{0.5*\@@intscale}%
    \pgftransformscale{\@@intscale}% the end of the bipole will deactivate it
    % the generic will be reduced by @@intscale; let's undo the scaling to
    % connect the leads to the end of the component.
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left/\@@intscale-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{+0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{+0pt}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right/\@@intscale+\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{+0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{+0pt}}
    \pgftransformationadjustments
    \pgfmathsetlength{\pgf@circ@res@step}{\ctikzvalof{bipoles/ldgeneric/width}*\scaledRlen+\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}
    \pgfusepath{draw}
    \pgfscope
        % reset the up at the "generic" thing
        \pgf@circ@res@up=\ctikzvalof{bipoles/generic/height}\pgf@circ@scaled@Rlen
        \pgf@circ@res@up=0.5\pgf@circ@res@up
        \pgf@circ@res@down=-\pgf@circ@res@up
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfusepath{draw}
    \endpgfscope
}%

%% Zig-zag resistors
\def\pgf@circ@zigzag#1{%
    \divide \pgf@circ@res@step by \numexpr4*\zigs\relax

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{\pgf@circ@res@zero}}
    \pgf@circ@res@other = \pgf@circ@res@left
    \pgf@circ@count@a=\zigs\relax
    % first half zig
    \advance\pgf@circ@res@other by \pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{-#1\pgf@circ@res@down}}
    \pgfmathloop%
    \advance\pgf@circ@count@a by -1\relax% Loop zigs -1 times
    \ifnum\pgf@circ@count@a>0
        \advance\pgf@circ@res@other by 2\pgf@circ@res@step
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{#1\pgf@circ@res@down}}
        \advance\pgf@circ@res@other by 2\pgf@circ@res@step
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{-#1\pgf@circ@res@down}}
    \repeatpgfmathloop%
    % last zig and a half
    \advance\pgf@circ@res@other by 2\pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{#1\pgf@circ@res@down}}
    \advance\pgf@circ@res@other by \pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@zero}}
    \pgfsetbeveljoin
    \pgfusepath{draw}
}

%% Resistor
\pgfcircdeclarebipolescaled{resistors}
{
\savedmacro{\zigs}{\edef\zigs{\ctikzvalof{resistors/zigs}}}
}
{\ctikzvalof{bipoles/resistor/height}}
{resistor}
{\ctikzvalof{bipoles/resistor/height}}
{\ctikzvalof{bipoles/resistor/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments
    \pgfmathsetlength{\pgf@circ@res@step}{\ctikzvalof{bipoles/resistor/width}*\scaledRlen+\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}
    \pgf@circ@zigzag{1}
}


%% Variable resistor
\pgfcircdeclarebipolescaled{resistors}
{
\savedmacro{\zigs}{\edef\zigs{\ctikzvalof{resistors/zigs}}}
\anchor{wiper}{\northeast\pgf@x=-0.4\pgf@x\pgf@y=-\pgf@y}
\anchor{W}{\northeast\pgf@x=-0.4\pgf@x\pgf@y=-\pgf@y}
\anchor{tip}{\northeast\pgf@x=0.4\pgf@x}
}
{\ctikzvalof{bipoles/vresistor/height}}
{vresistor}
{\ctikzvalof{bipoles/vresistor/height}}
{\ctikzvalof{bipoles/vresistor/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments
    \pgfmathsetlength{\pgf@circ@res@step}{\ctikzvalof{bipoles/vresistor/width}*\scaledRlen+\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}
    \pgf@circ@zigzag{.5}

    \pgfscope
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfcirc@set@arrows{tunable}{}{latexslim}
        \ifpgf@circ@fixtunable@dir
            \pgfpathmoveto{\pgfpoint{-.4\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@right}{\pgf@circ@res@up}}
        \else
            \pgfpathmoveto{\pgfpoint{.4\pgf@circ@res@right}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{-.4\pgf@circ@res@right}{\pgf@circ@res@down}}
        \fi
        \pgfusepath{draw}
    \endpgfscope
}

%% Potentiometer
\pgfcircdeclarebipolescaled{resistors}
{
    \savedanchor{\wiper}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@ya=\ctikzvalof{bipoles/potentiometer/height}\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@ya
            \pgf@xa=\ctikzvalof{bipoles/potentiometer/width}\pgf@circ@scaled@Rlen
            \pgfmathsetlength{\pgf@x}{(\ctikzvalof{bipoles/potentiometer/wiper pos}-0.5)*\pgf@xa}
        }
    \anchor{wiper}{\wiper}
    \anchor{W}{\wiper}
    \savedmacro{\zigs}{\edef\zigs{\ctikzvalof{resistors/zigs}}}
    \anchor{tip}{\wiper\pgf@xa=\pgf@x\southwest\pgf@x=\pgf@xa\pgf@y=-\pgf@y}
}
{\ctikzvalof{bipoles/potentiometer/height 2}}
{potentiometer}
{\ctikzvalof{bipoles/potentiometer/height}}
{\ctikzvalof{bipoles/potentiometer/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments
    \pgfmathsetlength{\pgf@circ@res@step}{\ctikzvalof{bipoles/potentiometer/width}*\scaledRlen+\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}
    \pgf@circ@zigzag{1}

    \pgfscope
        %\pgfsetlinewidth{\pgfstartlinewidth}
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfcirc@set@arrows{wiper}{}{latexslim}
        \pgfextractx{\pgf@circ@res@other}{\wiper}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{-\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
}

%% Resistive sensor
\pgfcircdeclarebipolescaled{resistors}
{% anchor for labelling the type of dependency
    \anchor{label}{\southwest\pgf@x=0.4\pgf@x}%
    \savedmacro{\zigs}{\edef\zigs{\ctikzvalof{resistors/zigs}}}
    \anchor{wiper}{\northeast\pgf@x=-0.9\pgf@x\pgf@y=-\pgf@y}
    \anchor{W}{\northeast\pgf@x=-0.9\pgf@x\pgf@y=-\pgf@y}
    \anchor{tip}{\northeast\pgf@x=0.4\pgf@x}
}
{\ctikzvalof{bipoles/resistivesens/height}}
{resistivesens}
{\ctikzvalof{bipoles/resistivesens/height}}
{\ctikzvalof{bipoles/resistivesens/width}}
{%
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments
    \pgfmathsetlength{\pgf@circ@res@step}{\ctikzvalof{bipoles/resistivesens/width}*\scaledRlen+\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}
    \pgf@circ@zigzag{.5}

    \pgfscope
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfpathmoveto{\pgfpoint{.4\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-.4\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{-.9\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
}%

%% american style LDR
\pgfcircdeclarebipolescaled{resistors}
{% anchor for light arrows
    \anchor{arrows}{\northeast\pgf@x=1.6\pgf@x\pgf@y=1.4\pgf@y}%
    \savedmacro{\zigs}{\edef\zigs{\ctikzvalof{resistors/zigs}}}
    % \pgfcirc@border@extend@full{1.2}{1.2}{1.2}{1.2}
}
{\ctikzvalof{bipoles/ldresistor/height}}
{ldresistor}
{\ctikzvalof{bipoles/ldresistor/height}}
{\ctikzvalof{bipoles/ldresistor/width}}
{%
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
        \pgf@circ@draworfill
    \endpgfscope
    \pgfscope
        % arrows
        \pgf@circ@set@optoarrow@style
        \pgfpathmoveto{\pgfpoint{1.4\pgf@circ@res@right}{1.4\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0.8\pgf@circ@res@right}{0.8\pgf@circ@res@up}}
        \pgfusepath{draw}
        \pgfpathmoveto{\pgfpoint{1.6\pgf@circ@res@right}{1.2\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{1.0\pgf@circ@res@right}{0.6\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
    \edef\@@intscale{\ctikzvalof{bipoles/ldresistor/internal scale}}%
    \pgfmathsetmacro{\@@hscale}{0.5*\@@intscale}%
    \pgftransformscale{\@@intscale}% the end of the bipole will deactivate it
    % the zigzag will be reduced by @@intscale; let's undo the scaling to
    % connect the leads to the end of the component.
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left/\@@intscale-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{+0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{+0pt}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right/\@@intscale+\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{+0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{+0pt}}
    \pgftransformationadjustments
    \pgfmathsetlength{\pgf@circ@res@step}{\ctikzvalof{bipoles/ldresistor/width}*\scaledRlen+\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}
    \pgf@circ@zigzag{\@@hscale}
}%


%>>>

%% Paths for resistive components: generic, resistors and wires% %<<<

%% GENERICS
\def\pgf@circ@empty@path#1{}
\pgfcirc@activate@bipole@simple{l}{generic}
\pgfcirc@activate@bipole@simple{l}{ageneric}
\pgfcirc@activate@bipole@simple{l}{tgeneric}
\pgfcirc@activate@bipole@simple{l}{xgeneric}
\pgfcirc@activate@bipole@simple{l}{sgeneric}
\pgfcirc@activate@bipole@simple{l}{fullgeneric}
\pgfcirc@activate@bipole@simple{l}{tfullgeneric}
\pgfcirc@activate@bipole@simple{l}{short}
\pgfcirc@activate@bipole@simple{l}{open}

%% wires and crossings

\pgfcirc@activate@bipole@simple{l}{crossing}
\pgfcirc@style@to@style{crossing}{xing}
\pgfcirc@activate@bipole@simple{l}{multiwire}
\pgfcirc@activate@bipole@simple{l}{bmultiwire}
\pgfcirc@activate@bipole@simple{l}{tmultiwire}

% automatically switching path --- to be defined manually
\def\pgf@circ@resistor@path#1{\ifpgf@circuit@europeanresistor\pgf@circ@bipole@path{generic}{#1}\else\pgf@circ@bipole@path{resistor}{#1}\fi}
\pgfcirc@path@to@style{l}{resistor}{resistor}{}
\pgfcirc@node@to@style{l}{resistor}{american resistor}{}
\pgfcirc@node@to@style{l}{generic}{european resistor}{}
\pgfcirc@style@to@style{resistor}{R}

\def\pgf@circ@vresistor@path#1{\ifpgf@circuit@europeanresistor\pgf@circ@bipole@path{tgeneric}{#1}\else\pgf@circ@bipole@path{vresistor}{#1}\fi}
\pgfcirc@path@to@style{l}{vresistor}{variable resistor}{}
\pgfcirc@node@to@style{l}{vresistor}{variable american resistor}{}
\pgfcirc@node@to@style{l}{tgeneric}{variable european resistor}{}
\pgfcirc@style@to@style{variable resistor}{vR}

\def\pgf@circ@resistivesens@path#1{\ifpgf@circuit@europeanresistor\pgf@circ@bipole@path{thermistor}{#1}\else\pgf@circ@bipole@path{resistivesens}{#1}\fi}
\pgfcirc@path@to@style{l}{resistivesens}{resistive sensor}{}
\pgfcirc@node@to@style{l}{resistivesens}{american resistive sensor}{}
\pgfcirc@node@to@style{l}{thermistor}{european resistive sensor}{}
\pgfcirc@style@to@style{resistive sensor}{sR}

\def\pgf@circ@ldresistor@path#1{\ifpgf@circuit@europeanresistor\pgf@circ@bipole@path{ldgeneric}{#1}\else\pgf@circ@bipole@path{ldresistor}{#1}\fi}
\pgfcirc@path@to@style{l}{ldresistor}{light dependent resistor}{}
\pgfcirc@node@to@style{l}{ldresistor}{american light dependent resistor}{}
\pgfcirc@node@to@style{l}{ldgeneric}{european light dependent resistor}{}
\pgfcirc@style@to@style{light dependent resistor}{ldR}

\def\pgf@circ@potentiometer@path#1{\ifpgf@circuit@europeanresistor\pgf@circ@bipole@path{genericpotentiometer}{#1}\else\pgf@circ@bipole@path{potentiometer}{#1}\fi}
\pgfcirc@path@to@style{l}{potentiometer}{potentiometer}{}
\pgfcirc@node@to@style{l}{potentiometer}{american potentiometer}{}
\pgfcirc@node@to@style{l}{genericpotentiometer}{european potentiometer}{}
\pgfcirc@style@to@style{potentiometer}{pR}

\pgfcirc@activate@bipole@simple{l}{thermistor}
\pgfcirc@style@to@style{thermistor}{thR}
\pgfcirc@activate@bipole{l}{thermistorptc}{thermistorptc}{thermistor ptc}
\pgfcirc@style@to@style{thermistor ptc}{thRp}
\pgfcirc@activate@bipole{l}{thermistorntc}{thermistorntc}{thermistor ntc}
\pgfcirc@style@to@style{thermistor ntc}{thRn}
\pgfcirc@activate@bipole@simple{l}{photoresistor}
\pgfcirc@style@to@style{photoresistor}{phR}
\pgfcirc@activate@bipole@simple{l}{varistor}
\pgfcirc@activate@bipole@simple{l}{mov}
\pgfcirc@activate@bipole@simple{l}{memristor}
\pgfcirc@style@to@style{memristor}{Mr}%
% %>>>

%%%%%%%%%%%%%%
%% Capacitors
%%%%%%%%%%%%%

%% Definitions for Capacitors%<<<1
\ctikzset{bipoles/capacitor/height/.initial=.6}
\ctikzset{bipoles/capacitor/width/.initial=.2}
\ctikzset{bipoles/ecapacitor/height/.initial=.5}
\ctikzset{bipoles/ecapacitor/width/.initial=.2}
\ctikzset{bipoles/ecapacitor/font/.initial=\pgf@circ@font@sixbm}
%%% pcapacitor is deprecated
\ctikzset{bipoles/pcapacitor/height/.initial=.6}
\ctikzset{bipoles/pcapacitor/width/.initial=.2}
\ctikzset{bipoles/pcapacitor/bend width/.initial=1.1}
\ctikzset{bipoles/ccapacitor/height/.initial=.6}
\ctikzset{bipoles/ccapacitor/width/.initial=.2}
\ctikzset{bipoles/ccapacitor/bend width/.initial=1.1}
\ctikzset{bipoles/vcapacitor/height/.initial=.6}
\ctikzset{bipoles/vcapacitor/width/.initial=.2}
\ctikzset{bipoles/vcapacitor/tunable width/.initial=3}
\ctikzset{bipoles/vcapacitor/capacitor width/.code={%
        \pgfutil@packagewarning{circuitikz}{vcapacitor/capacitor width deprecated; ignored}%
}}% deprecated
% piezoelectric (double size by default)
\ctikzset{bipoles/piezoelectric/height/.initial=.7}
\ctikzset{bipoles/piezoelectric/width/.initial=.4}%
% constant phase element (double size by default)
\ctikzset{bipoles/cpe/height/.initial=.6}
\ctikzset{bipoles/cpe/width/.initial=.4}
%
% style settings
%
\ctikzset{capacitors/width/.code={%
    \pgfmathsetmacro{\pgfcirc@@double}{2*#1}%
    \ctikzset{bipoles/.cd,
    capacitor/width=#1, ecapacitor/width=#1, ccapacitor/width=#1,
    vcapacitor/width=#1,
    piezoelectric/width=\pgfcirc@@double,
    cpe/width=\pgfcirc@@double,
}}}
\ctikzset{capacitors/height/.code={%
    \ctikzset{bipoles/.cd,
    capacitor/height=#1, ecapacitor/height=#1, ccapacitor/height=#1,
    vcapacitor/height=#1,
    piezoelectric/height=#1,
    cpe/height=#1,
}}}
\def\pgfcirc@maybe@fill@straight@capacitor{%
    \pgfscope
        \pgfpathrectanglecorners
        {\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        {\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgf@circ@maybefill
    \endpgfscope
}
%>>>

%% Shapes for capacitors%<<<
%% Plain Capacitor
\pgfcircdeclarebipolescaled{capacitors}
{}
{\ctikzvalof{bipoles/capacitor/height}}
{capacitor}
{\ctikzvalof{bipoles/capacitor/height}}
{\ctikzvalof{bipoles/capacitor/width}}
{
    \pgfcirc@maybe@fill@straight@capacitor

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{draw}

}

%% Capacitive sensor
\pgfcircdeclarebipolescaled{capacitors}
{
    \anchor{label}{\southwest\pgf@x=2.6\pgf@x\pgf@y=1.2\pgf@y}%
    \pgfcirc@border@extend@full{2.6}{1}{4.4}{1.2}
    \anchor{wiper}{\northeast\pgf@x=-4.4\pgf@x\pgf@y=-1.2\pgf@y}
    \anchor{W}{\northeast\pgf@x=-4.4\pgf@x\pgf@y=-1.2\pgf@y}
    \anchor{tip}{\northeast\pgf@x=2.6\pgf@x}
}
{\ctikzvalof{bipoles/capacitor/height}}
{capacitivesens}
{\ctikzvalof{bipoles/capacitor/height}}
{\ctikzvalof{bipoles/capacitor/width}}
{
    \pgfcirc@maybe@fill@straight@capacitor
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{draw}
    \pgfscope
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfpathmoveto{\pgfpoint{2.6\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-2.6\pgf@circ@res@right}{1.2\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{-4.4\pgf@circ@res@right}{1.2\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
}

%% Polar Capacitor (DEPRECATED)
\pgfcircdeclarebipolescaled{capacitors}
{}
{\ctikzvalof{bipoles/pcapacitor/height}}
{polarcapacitor}
{\ctikzvalof{bipoles/pcapacitor/height}}
{\ctikzvalof{bipoles/pcapacitor/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfutil@packagewarning{circuitikz}{polar capacitor has been deprecated; change to curved capacitor (see manual)}%

    \pgfscope
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left+ \ctikzvalof{bipoles/pcapacitor/bend width}\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgftransformrotate{-90}
        \pgfpathsine{\pgfpoint{\pgf@circ@res@up}{-\ctikzvalof{bipoles/pcapacitor/bend width}\pgf@circ@res@left}}
        \pgfpathcosine{\pgfpoint{\pgf@circ@res@up}{\ctikzvalof{bipoles/pcapacitor/bend width}\pgf@circ@res@left}}
        \pgfusepath{draw}
    \endpgfscope

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{draw}
}


%% Curved capacitor
% see https://tex.stackexchange.com/questions/509594/polar-capacitor-orientation-in-circuitikz-seems-wrong
% for a rationale
%
\pgfcircdeclarebipolescaled{capacitors}
{}
{\ctikzvalof{bipoles/ccapacitor/height}}
{ccapacitor}
{\ctikzvalof{bipoles/ccapacitor/height}}
{\ctikzvalof{bipoles/ccapacitor/width}}
{
    \pgfscope
        \pgfscope
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
            \pgftransformrotate{-90}
            \pgfpathsine{\pgfpoint{\pgf@circ@res@up}{-\ctikzvalof{bipoles/ccapacitor/bend width}\pgf@circ@res@right}}
            \pgfpathcosine{\pgfpoint{\pgf@circ@res@up}{\ctikzvalof{bipoles/pcapacitor/bend width}\pgf@circ@res@right}}
            \pgftransformrotate{90}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathclose{}
            \pgf@circ@maybefill
        \endpgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfscope
            % \pgfsetcolor{red}
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
            \pgftransformrotate{-90}
            \pgfpathsine{\pgfpoint{\pgf@circ@res@up}{-\ctikzvalof{bipoles/ccapacitor/bend width}\pgf@circ@res@right}}
            \pgfpathcosine{\pgfpoint{\pgf@circ@res@up}{\ctikzvalof{bipoles/pcapacitor/bend width}\pgf@circ@res@right}}
            \pgfusepath{draw}
        \endpgfscope
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
    % extend wire to the curved capacitor
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\ctikzvalof{bipoles/pcapacitor/bend width}\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
}

%% Electrolytic Capacitor
\pgfcircdeclarebipolescaled{capacitors}
{}
{\ctikzvalof{bipoles/ecapacitor/height}}
{ecapacitor}
{\ctikzvalof{bipoles/ecapacitor/height}}
{\ctikzvalof{bipoles/ecapacitor/width}}
{
    \pgfscope
        \pgfsetrectcap
        % % % Draw plus pole
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgf@circ@draworfill
        % % Draw minus pole
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgf@circ@setcolor
        \pgf@circ@fill@strokecolor
        \pgfusepath{draw,fill}
    \endpgfscope
    % % plus pole annotation
    \pgf@circ@text@strokecolor
    \pgftext[right,at=\pgfpoint{1.2\pgf@circ@res@left}{.6\pgf@circ@res@up}]
    {\ctikzvalof{bipoles/ecapacitor/font} $+$}
}

%% Variable Capacitor
\pgfcircdeclarebipolescaled{capacitors}
{
    \saveddimen{\tunablewidth}{%
        \pgfmathsetlength{\pgf@x}{\ctikzvalof{bipoles/vcapacitor/tunable width}*
            \ctikzvalof{bipoles/vcapacitor/width}*0.5*
            \ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
    }
    \anchor{wiper}{\northeast\pgf@x=-\tunablewidth\pgf@y=-\pgf@y}
    \anchor{W}{\northeast\pgf@x=-\tunablewidth\pgf@y=-\pgf@y}
    \anchor{tip}{\northeast\pgf@x=\tunablewidth}
}
{\ctikzvalof{bipoles/vcapacitor/height}}
{vcapacitor}
{\ctikzvalof{bipoles/vcapacitor/height}}
{\ctikzvalof{bipoles/vcapacitor/width}}
{
    \pgfcirc@maybe@fill@straight@capacitor
    \pgf@circ@res@step = \ctikzvalof{bipoles/vcapacitor/tunable width} \pgf@circ@res@right

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{-\pgf@circ@res@right}{\pgf@circ@res@down}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{draw}

    \pgfscope
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfcirc@set@arrows{tunable}{}{latexslim}
        \ifpgf@circ@fixtunable@dir
            \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@up}}
        \else
            \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@down}}
        \fi
        \pgfusepath{draw}
    \endpgfscope

    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfusepath{draw}
}


%% Piezoelectric Element

\pgfcircdeclarebipolescaled{capacitors}
{}
{\ctikzvalof{bipoles/piezoelectric/height}}
{piezoelectric}
{\ctikzvalof{bipoles/piezoelectric/height}}
{\ctikzvalof{bipoles/piezoelectric/width}}
{
    % \pgf@circ@res@step = \ctikzvalof{bipoles/piezoelectric/width}\pgf@circ@Rlen
    % \divide \pgf@circ@res@step by 5

    %% Outer markings
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{draw}

    %% Inner Box
    \pgf@circ@res@step = \pgf@circ@res@right \divide \pgf@circ@res@step by 10
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathrectanglecorners
            {\pgfpoint{\pgf@circ@res@left+4*\pgf@circ@res@step}{\pgf@circ@res@up-\pgf@circ@res@step}}
            {\pgfpoint{\pgf@circ@res@right-4*\pgf@circ@res@step}{\pgf@circ@res@down+\pgf@circ@res@step}}
        \pgf@circ@draworfill
    \endpgfscope
}

% Ferroelectric capacitor, suggested by Mayeul Cantan
% (see https://github.com/circuitikz/circuitikz/issues/515)
\pgfcircdeclarebipolescaled{capacitors}
{
    \anchor{curve right}{\southwest\pgf@x=-1.8\pgf@x\pgf@y=\pgf@y}%
    \anchor{curve left}{\southwest\pgf@x=1.8\pgf@x\pgf@y=-\pgf@y}%
    \anchor{kink right}{\southwest\pgf@x=-1.8\pgf@x\pgf@y=0.5\pgf@y}%
    \anchor{kink left}{\southwest\pgf@x=1.8\pgf@x\pgf@y=-0.5\pgf@y}%
    \pgfcirc@border@extend@full{1.8}{1}{1.8}{1}
}
{\ctikzvalof{bipoles/capacitor/height}}
{ferrocap}
{\ctikzvalof{bipoles/capacitor/height}}
{\ctikzvalof{bipoles/capacitor/width}}
{
    \pgfcirc@maybe@fill@straight@capacitor

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{draw}
    \pgfscope
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfsetcornersarced{\pgfpoint{0.2\pgf@circ@res@right}{0.2\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{-1.8\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-1.8\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{1.8\pgf@circ@res@right}{0.5\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{1.8\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
}

%% Constant phase element
\pgfcircdeclarebipolescaled{capacitors}
{}
{\ctikzvalof{bipoles/cpe/height}}
{cpe}
{\ctikzvalof{bipoles/cpe/height}}
{\ctikzvalof{bipoles/cpe/width}}
{
    \pgfscope
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpointorigin}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfpathclose
        \pgf@circ@maybefill
    \endpgfscope

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpointorigin}
    \pgfusepath{draw}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpointorigin}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}

    \pgfpathmoveto{\pgfpoint{0pt}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
    \pgfusepath{draw}
}

% %>>>

%% Paths for capacitors%<<<
\pgfcirc@activate@bipole@simple{l}{capacitor}
\pgfcirc@style@to@style{capacitor}{C}
\pgfcirc@activate@bipole@simple{l}{ecapacitor}
\pgfcirc@style@to@style{ecapacitor}{eC}
\pgfcirc@style@to@style{ecapacitor}{elko}
\pgfcirc@activate@bipole{l}{polarcapacitor}{polarcapacitor}{polar capacitor}
%% polar capacitor is deprecated, use curved capacitor instead
\pgfcirc@style@to@style{polar capacitor}{pC}
\pgfcirc@activate@bipole{l}{ccapacitor}{ccapacitor}{curved capacitor}
\pgfcirc@style@to@style{curved capacitor}{cC}
\pgfcirc@activate@bipole{l}{vcapacitor}{vcapacitor}{variable capacitor}
\pgfcirc@style@to@style{variable capacitor}{vC}
\pgfcirc@activate@bipole@simple{l}{piezoelectric}
\pgfcirc@style@to@style{piezoelectric}{PZ}
\pgfcirc@activate@bipole{l}{capacitivesens}{capacitivesens}{capacitive sensor}
\pgfcirc@style@to@style{capacitive sensor}{sC}
\pgfcirc@activate@bipole@simple{l}{ferrocap}
\pgfcirc@style@to@style{ferrocap}{feC}
\pgfcirc@activate@bipole@simple{l}{cpe}
% %>>>

%%%%%%%%%%%%%%%
%% Inductors
%%%%%%%%%%%%%%%

% Definitions of Inductors%<<<1

\ctikzset{inductors/coils/.code={%
    \ctikzset{bipoles/cuteinductor/coils=#1}%
    \ctikzset{bipoles/cutechoke/coils=#1}%
    \ctikzset{bipoles/americaninductor/coils=#1}%
    \ctikzset{bipoles/vcuteinductor/coils=#1}%
    \ctikzset{bipoles/vamericaninductor/coils=#1}%
}}
\ctikzset{inductors/width/.code={%
    \ctikzset{bipoles/cuteinductor/width=#1}%
    \ctikzset{bipoles/cutechoke/width=#1}%
    \ctikzset{bipoles/americaninductor/width=#1}%
    \ctikzset{bipoles/vcuteinductor/width=#1}%
    \ctikzset{bipoles/vamericaninductor/width=#1}%
    \ctikzset{bipoles/fullgeneric/width=#1}%
    \ctikzset{bipoles/tfullgeneric/width=#1}%
}}
\ctikzset{bipoles/cuteinductor/height/.initial=.3}
\ctikzset{bipoles/cuteinductor/lower coil height/.initial=.15}
\ctikzset{bipoles/cuteinductor/width/.initial=.6}
\ctikzset{bipoles/cuteinductor/coils/.initial=5}
\ctikzset{bipoles/cuteinductor/coil aspect/.initial=.5}%percentage of inductor width, which is covered by lower coil
%% Cute choke settings
\ctikzset{bipoles/cutechoke/height/.initial=.3}
\ctikzset{bipoles/cutechoke/lower coil height/.initial=.15}
\ctikzset{bipoles/cutechoke/width/.initial=.6}
\ctikzset{bipoles/cutechoke/coils/.initial=5}
\ctikzset{bipoles/cutechoke/coil aspect/.initial=.5}%percentage of choke width, which is covered by lower coil
\ctikzset{bipoles/cutechoke/cstep/.initial=.3}
\ctikzset{bipoles/cutechoke/cdist/.initial=1.3}
\ctikzset{bipoles/cutechoke/cthick/.initial=1}
\newif\ifpgf@circuit@bipole@twolineschoke
\pgf@circuit@bipole@twolineschokefalse
\pgfkeys{/tikz/onelinechoke/.add code={}{\pgf@circuit@bipole@twolineschokefalse}}
\ctikzset{onelinechoke/.add code={}{\pgf@circuit@bipole@twolineschokefalse}}
\pgfkeys{/tikz/twolineschoke/.add code={}{\pgf@circuit@bipole@twolineschoketrue}}
\ctikzset{twolineschoke/.add code={}{\pgf@circuit@bipole@twolineschoketrue}}
%
% generic core anchor settings
\ctikzset{bipoles/inductors/core distance/.initial={2pt}}
\ctikzset{bipoles/inductors/dot x distance/.initial={4pt}}
\ctikzset{bipoles/inductors/dot y distance/.initial={1pt}}
\def\pgfcir@basic@core@anchors{%
    \saveddimen{\coredistance}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{bipoles/inductors/core distance}}}
    \saveddimen{\dotXdistance}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{bipoles/inductors/dot x distance}}}
    \saveddimen{\dotYdistance}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{bipoles/inductors/dot y distance}}}
    \anchor{core east}{%
        \northeast\advance\pgf@y by\coredistance
    }
    \anchor{core west}{%
        \northeast\advance\pgf@y by\coredistance\pgf@x=-\pgf@x
    }
    \anchor{ll dot}{%
        \southwestborder
        \advance\pgf@x by -\dotXdistance
        \advance\pgf@y by -\dotYdistance
    }
    \anchor{ul dot}{%
        \northeastborder
        \advance\pgf@x by \dotXdistance\pgf@x=-\pgf@x
        \advance\pgf@y by \dotYdistance
    }
    \anchor{lr dot}{%
        \southwestborder
        \advance\pgf@x by -\dotXdistance\pgf@x=-\pgf@x
        \advance\pgf@y by -\dotYdistance
    }
    \anchor{ur dot}{%
        \northeastborder
        \advance\pgf@x by \dotXdistance
        \advance\pgf@y by \dotYdistance
    }
}
%
\ctikzset{bipoles/americaninductor/height/.initial=.3}
\ctikzset{bipoles/americaninductor/height 2/.initial=.1}
\ctikzset{bipoles/americaninductor/width/.initial=.8}
\ctikzset{bipoles/americaninductor/coils/.initial=4}
\ctikzset{bipoles/americaninductor/coil height/.initial=.15}
\ctikzset{bipoles/vcuteinductor/height/.initial=.6}
\ctikzset{bipoles/vcuteinductor/lower coil height/.initial=.3}
\ctikzset{bipoles/vcuteinductor/width/.initial=.6}
\ctikzset{bipoles/vcuteinductor/coils/.initial=5}
\ctikzset{bipoles/vcuteinductor/coil aspect/.initial=.5}%percentage of inductor width, which is covered by lower coil
\ctikzset{bipoles/vamericaninductor/height/.initial=.6}
\ctikzset{bipoles/vamericaninductor/height 2/.initial=.2}
\ctikzset{bipoles/vamericaninductor/width/.initial=.8}
\ctikzset{bipoles/vamericaninductor/coils/.initial=4}
\ctikzset{bipoles/vamericaninductor/coil height/.initial=.15}
\ctikzset{bipoles/tfullgeneric/height/.initial=.70}
\ctikzset{bipoles/tfullgeneric/width/.initial=.80}
\ctikzset{bipoles/fullgeneric/height/.initial=.30}
\ctikzset{bipoles/fullgeneric/width/.initial=.80}
\ctikzset{inductor/.is choice}
\ctikzset{inductor/cute/.code={\ctikzsetvalof{inductor}{cute}}}
\ctikzset{inductor/european/.code={\ctikzsetvalof{inductor}{european}}}
\ctikzset{inductor/american/.code={\ctikzsetvalof{inductor}{american}}}

\tikzset{american inductors/.style = {\circuitikzbasekey/inductor = american}}
\tikzset{european inductors/.style = {\circuitikzbasekey/inductor = european}}
\tikzset{cute inductors/.style = {\circuitikzbasekey/inductor = cute}}
\tikzset{american ports/.style = {\circuitikzbasekey/logic ports = american}}
\tikzset{european ports/.style = {\circuitikzbasekey/logic ports = european}}

%%>>>

%% Shapes for inductors%<<<
%% cute inductor
\pgfcircdeclarebipolescaled{inductors}
{
    \savedanchor{\midtap}{%
        \pgf@x=0pt\relax
        \pgfmathsetlength{\pgf@y}{%
            (mod(\ctikzvalof{bipoles/cuteinductor/coils},2) ?%
            \ctikzvalof{bipoles/cuteinductor/height} :% even
            -\ctikzvalof{bipoles/cuteinductor/lower coil height}) %odd
            *\pgf@circ@scaled@Rlen/2
        }
    }
    \anchor{midtap}{\midtap}
    \pgfcir@basic@core@anchors
    }
{\ctikzvalof{bipoles/cuteinductor/lower coil height}}
{cuteinductor}
{\ctikzvalof{bipoles/cuteinductor/height}}
{\ctikzvalof{bipoles/cuteinductor/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments

    \pgfmathsetlength{\pgf@circ@res@other}%width of small coil
    {0.5*\ctikzvalof{bipoles/cuteinductor/coil aspect}*\ctikzvalof{bipoles/cuteinductor/width}*\scaledRlen/(\ctikzvalof{bipoles/cuteinductor/coils}-1)}


    \pgfmathsetlength{\pgf@circ@res@step}
    {(\ctikzvalof{bipoles/cuteinductor/width}*\scaledRlen+\pgfhorizontaltransformationadjustment\pgflinewidth+(\ctikzvalof{bipoles/cuteinductor/coils}-1)*2*\pgf@circ@res@other)/\ctikzvalof{bipoles/cuteinductor/coils}/2}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{-\pgfverticaltransformationadjustment*0.4*\pgfstartlinewidth}}%correct value would be 0.5 but arcs are not really flat, therefore 0.4 is better is (almost) all cases
    \foreach \x in {2,...,\ctikzvalof{bipoles/cuteinductor/coils}}
    {
        \pgfpatharc{180}{0}{\pgf@circ@res@step and \pgf@circ@res@up}
        \pgfpatharc{0}{-180}{\pgf@circ@res@other and -\pgf@circ@res@down}
    }
    \pgfpatharc{180}{0}{\pgf@circ@res@step and \pgf@circ@res@up}
    \pgfsetbuttcap
    \pgfsetbeveljoin
    \pgfusepath{stroke}
}

%% cute inductive sensor
\pgfcircdeclarebipolescaled{inductors}
{% anchor for labelling the type of dependency
    \anchor{label}{\southwest\pgf@x=0.8\pgf@x\pgf@y=2.6\pgf@y}%
    \savedanchor{\midtap}{%
        \pgf@x=0pt\relax
        \pgfmathsetlength{\pgf@y}{%
            (mod(\ctikzvalof{bipoles/cuteinductor/coils},2) ?%
            \ctikzvalof{bipoles/cuteinductor/height} :% even
            -\ctikzvalof{bipoles/cuteinductor/lower coil height}) %odd
            *\pgf@circ@scaled@Rlen/2
        }
    }
    \anchor{midtap}{\midtap}
    \pgfcirc@border@extend@full{1}{2}{1.6}{2.6}
    \pgfcir@basic@core@anchors
    \anchor{wiper}{\southwest\pgf@x=1.6\pgf@x\pgf@y=2.6\pgf@y}
    \anchor{W}{\southwest\pgf@x=1.6\pgf@x\pgf@y=2.6\pgf@y}
    \anchor{tip}{\northeast\pgf@x=0.8\pgf@x\pgf@y=2\pgf@y}
}
{\ctikzvalof{bipoles/cuteinductor/lower coil height}}
{scuteinductor}
{\ctikzvalof{bipoles/cuteinductor/height}}
{\ctikzvalof{bipoles/cuteinductor/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments

    \pgfmathsetlength{\pgf@circ@res@other}%width of small coil
    {0.5*\ctikzvalof{bipoles/cuteinductor/coil aspect}*\ctikzvalof{bipoles/cuteinductor/width}*\scaledRlen/(\ctikzvalof{bipoles/cuteinductor/coils}-1)}


    \pgfmathsetlength{\pgf@circ@res@step}
    {(\ctikzvalof{bipoles/cuteinductor/width}*\scaledRlen+\pgfhorizontaltransformationadjustment\pgflinewidth+(\ctikzvalof{bipoles/cuteinductor/coils}-1)*2*\pgf@circ@res@other)/\ctikzvalof{bipoles/cuteinductor/coils}/2}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{-\pgfverticaltransformationadjustment*0.4*\pgfstartlinewidth}}%correct value would be 0.5 but arcs are not really flat, therefore 0.4 is better is (almost) all cases
    \foreach \x in {2,...,\ctikzvalof{bipoles/cuteinductor/coils}}
    {
        \pgfpatharc{180}{0}{\pgf@circ@res@step and \pgf@circ@res@up}
        \pgfpatharc{0}{-180}{\pgf@circ@res@other and -\pgf@circ@res@down}
    }
    \pgfpatharc{180}{0}{\pgf@circ@res@step and \pgf@circ@res@up}
    \pgfsetbuttcap
    \pgfsetbeveljoin
    \pgfusepath{stroke}
    \pgfscope
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfpathmoveto{\pgfpoint{.8\pgf@circ@res@right}{2\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-.8\pgf@circ@res@right}{2.6\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{-1.6\pgf@circ@res@right}{2.6\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
}

%% cute choke
\pgfcircdeclarebipolescaled{inductors}
{
    \savedanchor{\midtap}{%
        \pgf@x=0pt\relax
        \pgfmathsetlength{\pgf@y}{%
            (mod(\ctikzvalof{bipoles/cuteinductor/coils},2) ?%
            \ctikzvalof{bipoles/cuteinductor/height} :% even
            -\ctikzvalof{bipoles/cuteinductor/lower coil height}) %odd
            *\pgf@circ@scaled@Rlen/2
        }
    }
    \anchor{midtap}{\midtap}
}
{\ctikzvalof{bipoles/cutechoke/lower coil height}}
{cutechoke}
{\ctikzvalof{bipoles/cutechoke/height}}
{\ctikzvalof{bipoles/cutechoke/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments

    \pgfmathsetlength{\pgf@circ@res@other}%width of small coil
    {0.5*\ctikzvalof{bipoles/cutechoke/coil aspect}*\ctikzvalof{bipoles/cutechoke/width}*\scaledRlen/(\ctikzvalof{bipoles/cutechoke/coils}-1)}


    \pgfmathsetlength{\pgf@circ@res@step}
    {(\ctikzvalof{bipoles/cutechoke/width}*\scaledRlen+\pgfhorizontaltransformationadjustment\pgflinewidth+(\ctikzvalof{bipoles/cutechoke/coils}-1)*2*\pgf@circ@res@other)/\ctikzvalof{bipoles/cutechoke/coils}/2}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{-\pgfverticaltransformationadjustment*0.4*\pgfstartlinewidth}}%correct value would be 0.5 but arcs are not really flat, therefore 0.4 is better is (almost) all cases
    \foreach \x in {2,...,\ctikzvalof{bipoles/cutechoke/coils}}
    {
        \pgfpatharc{180}{0}{\pgf@circ@res@step and \pgf@circ@res@up}
        \pgfpatharc{0}{-180}{\pgf@circ@res@other and -\pgf@circ@res@down}
    }
    \pgfpatharc{180}{0}{\pgf@circ@res@step and \pgf@circ@res@up}
    \pgfsetbuttcap
    \pgfsetbeveljoin
    \pgfusepath{stroke}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{-\pgfverticaltransformationadjustment*0.4*\pgfstartlinewidth+\ctikzvalof{bipoles/cutechoke/cdist}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgfverticaltransformationadjustment*0.4*\pgfstartlinewidth+\ctikzvalof{bipoles/cutechoke/cdist}\pgf@circ@res@up}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfsetlinewidth{\ctikzvalof{bipoles/cutechoke/cthick}\pgflinewidth}
    \pgfusepath{stroke}

    \ifpgf@circuit@bipole@twolineschoke
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{-\pgfverticaltransformationadjustment*0.4*\pgfstartlinewidth+\ctikzvalof{bipoles/cutechoke/cdist}\pgf@circ@res@up+\ctikzvalof{bipoles/cutechoke/cstep}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgfverticaltransformationadjustment*0.4*\pgfstartlinewidth+\ctikzvalof{bipoles/cutechoke/cdist}\pgf@circ@res@up+\ctikzvalof{bipoles/cutechoke/cstep}\pgf@circ@res@up}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfsetlinewidth{\ctikzvalof{bipoles/cutechoke/cthick}\pgflinewidth}
        \pgfusepath{stroke}
    \fi
}

%% variable cute inductor
\pgfcircdeclarebipolescaled{inductors}
{
    \savedanchor{\midtap}{%
        \pgf@x=0pt\relax
        \pgfmathsetlength{\pgf@y}{%
            (mod(\ctikzvalof{bipoles/cuteinductor/coils},2) ?%
            \ctikzvalof{bipoles/cuteinductor/height} :% even
            -\ctikzvalof{bipoles/cuteinductor/lower coil height}) %odd
            *\pgf@circ@scaled@Rlen/2
        }
    }
    \anchor{midtap}{\midtap}
    \saveddimen{\coredistance}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{bipoles/inductors/core distance}}}
    \anchor{core east}{%
        \northeast\pgf@y=0.5\pgf@y\advance\pgf@y by\coredistance
    }
    \anchor{core west}{%
        \northeast\pgf@y=0.5\pgf@y\advance\pgf@y by\coredistance\pgf@x=-\pgf@x
    }
    \anchor{wiper}{\southwest\pgf@x=0.4\pgf@x\pgf@y=\pgf@y}
    \anchor{W}{\southwest\pgf@x=0.4\pgf@x\pgf@y=\pgf@y}
    \anchor{tip}{\northeast\pgf@x=0.4\pgf@x}
}
{\ctikzvalof{bipoles/vcuteinductor/lower coil height}}
{vcuteinductor}
{\ctikzvalof{bipoles/vcuteinductor/height}}
{\ctikzvalof{bipoles/vcuteinductor/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments

    \pgfmathsetlength{\pgf@circ@res@other}%width of small coil
    {0.5*\ctikzvalof{bipoles/vcuteinductor/coil aspect}*\ctikzvalof{bipoles/vcuteinductor/width}*\scaledRlen/(\ctikzvalof{bipoles/vcuteinductor/coils}-1)}


    \pgfmathsetlength{\pgf@circ@res@step}
    {(\ctikzvalof{bipoles/vcuteinductor/width}*\scaledRlen+\pgfhorizontaltransformationadjustment\pgflinewidth+(\ctikzvalof{bipoles/vcuteinductor/coils}-1)*2*\pgf@circ@res@other)/\ctikzvalof{bipoles/vcuteinductor/coils}/2}

    \pgfscope
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfcirc@set@arrows{tunable}{}{latexslim}
        \pgfpathmoveto{\pgfpoint{.4\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{-\pgfverticaltransformationadjustment*0.4*\pgfstartlinewidth}}%correct value would be 0.5 but arcs are not really flat, therefore 0.4 is better is (almost) all cases
    \foreach \x in {2,...,\ctikzvalof{bipoles/vcuteinductor/coils}}
    {
        \pgfpatharc{180}{0}{\pgf@circ@res@step and .5\pgf@circ@res@up}
        \pgfpatharc{0}{-180}{\pgf@circ@res@other and -.5\pgf@circ@res@down}
    }
    \pgfpatharc{180}{0}{\pgf@circ@res@step and .5\pgf@circ@res@up}
    \pgfsetbuttcap
    \pgfsetbeveljoin
    \pgfusepath{stroke}
}

%% american inductor
\pgfcircdeclarebipolescaled{inductors}
{
    \savedanchor{\midtap}{%
        \pgf@x=0pt\relax
        \pgfmathsetlength{\pgf@y}{%
            (mod(\ctikzvalof{bipoles/americaninductor/coils},2) ?%
            2*\ctikzvalof{bipoles/americaninductor/coil height} :% even
            0) %odd
            *\pgf@circ@scaled@Rlen/2
        }
    }
    \anchor{midtap}{\midtap}
    \pgfcir@basic@core@anchors
}
{\ctikzvalof{bipoles/americaninductor/height 2}}
{americaninductor}
{\ctikzvalof{bipoles/americaninductor/height}}
{\ctikzvalof{bipoles/americaninductor/width}}
{
    \pgf@circ@res@step=\ctikzvalof{bipoles/americaninductor/width}\pgf@circ@scaled@Rlen
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments
    \advance \pgf@circ@res@step by \pgfhorizontaltransformationadjustment\pgflinewidth
    \divide \pgf@circ@res@step by \ctikzvalof{bipoles/americaninductor/coils}
    \divide \pgf@circ@res@step by 2
    \pgf@circ@res@other = \ctikzvalof{bipoles/americaninductor/coil height}\pgf@circ@scaled@Rlen

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{-\pgfverticaltransformationadjustment*0.4*\pgfstartlinewidth}}%correct value would be 0.5 but arcs are not really flat, therefore 0.4 is better is (almost) all cases
    \foreach \x in {1,...,\ctikzvalof{bipoles/americaninductor/coils}}
    {
        \pgfpatharc{180}{0}{\pgf@circ@res@step and  \pgf@circ@res@other}
    }
    \pgfsetbuttcap
    \pgfsetbeveljoin
    \pgfusepath{stroke}
}


%% american inductive sensor
\pgfcircdeclarebipolescaled{inductors}
{% anchor for labelling the type of dependency
    \anchor{label}{\southwest\pgf@x=0.8\pgf@x\pgf@y=2.6\pgf@y}%
    \savedanchor{\midtap}{%
        \pgf@x=0pt\relax
        \pgfmathsetlength{\pgf@y}{%
            (mod(\ctikzvalof{bipoles/americaninductor/coils},2) ?%
            2*\ctikzvalof{bipoles/americaninductor/coil height} :% even
            0) %odd
            *\pgf@circ@scaled@Rlen/2
        }
    }
    \anchor{midtap}{\midtap}
    \pgfcirc@border@extend@full{1}{2}{1.6}{2.6}
    \pgfcir@basic@core@anchors
    \anchor{wiper}{\southwest\pgf@x=1.6\pgf@x\pgf@y=2.6\pgf@y}
    \anchor{W}{\southwest\pgf@x=1.6\pgf@x\pgf@y=2.6\pgf@y}
    \anchor{tip}{\northeast\pgf@x=0.8\pgf@x\pgf@y=2\pgf@y}
}
{\ctikzvalof{bipoles/americaninductor/height 2}}
{samericaninductor}
{\ctikzvalof{bipoles/americaninductor/height}}
{\ctikzvalof{bipoles/americaninductor/width}}
{
    \pgf@circ@res@step=\ctikzvalof{bipoles/americaninductor/width}\pgf@circ@scaled@Rlen
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments
    \advance \pgf@circ@res@step by \pgfhorizontaltransformationadjustment\pgflinewidth
    \divide \pgf@circ@res@step by \ctikzvalof{bipoles/americaninductor/coils}
    \divide \pgf@circ@res@step by 2
    \pgf@circ@res@other = \ctikzvalof{bipoles/americaninductor/coil height}\pgf@circ@scaled@Rlen

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{-\pgfverticaltransformationadjustment*0.4*\pgfstartlinewidth}}%correct value would be 0.5 but arcs are not really flat, therefore 0.4 is better is (almost) all cases
    \foreach \x in {1,...,\ctikzvalof{bipoles/americaninductor/coils}}
    {
        \pgfpatharc{180}{0}{\pgf@circ@res@step and  \pgf@circ@res@other}
    }
    \pgfsetbuttcap
    \pgfsetbeveljoin
    \pgfusepath{stroke}
    \pgfscope
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfpathmoveto{\pgfpoint{.8\pgf@circ@res@right}{2\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-.8\pgf@circ@res@right}{2.6\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{-1.6\pgf@circ@res@right}{2.6\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
}

%% variable american inductor
\pgfcircdeclarebipolescaled{inductors}
{
    \savedanchor{\midtap}{%
        \pgf@x=0pt\relax
        \pgfmathsetlength{\pgf@y}{%
            (mod(\ctikzvalof{bipoles/vamericaninductor/coils},2) ?%
            2*\ctikzvalof{bipoles/vamericaninductor/coil height} :% even
            0) %odd
            *\pgf@circ@scaled@Rlen/2
        }
    }
    \anchor{midtap}{\midtap}
    \saveddimen{\coredistance}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{bipoles/inductors/core distance}}}
    \anchor{core east}{%
        \northeast\pgf@y=0.5\pgf@y\advance\pgf@y by\coredistance
    }
    \anchor{core west}{%
        \northeast\pgf@y=0.5\pgf@y\advance\pgf@y by\coredistance\pgf@x=-\pgf@x
    }
    \anchor{wiper}{\southwest\pgf@x=0.4\pgf@x\pgf@y=\pgf@y}
    \anchor{W}{\southwest\pgf@x=0.4\pgf@x\pgf@y=\pgf@y}
    \anchor{tip}{\northeast\pgf@x=0.4\pgf@x}
}
{\ctikzvalof{bipoles/vamericaninductor/height 2}}
{vamericaninductor}
{\ctikzvalof{bipoles/vamericaninductor/height}}
{\ctikzvalof{bipoles/vamericaninductor/width}}
{
    \pgf@circ@res@step=\ctikzvalof{bipoles/vamericaninductor/width}\pgf@circ@scaled@Rlen
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments
    \advance \pgf@circ@res@step by \pgfhorizontaltransformationadjustment\pgflinewidth
    \divide \pgf@circ@res@step by \ctikzvalof{bipoles/vamericaninductor/coils}
    \divide \pgf@circ@res@step by 2
    \pgf@circ@res@other = \ctikzvalof{bipoles/vamericaninductor/coil height}\pgf@circ@scaled@Rlen

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{-\pgfverticaltransformationadjustment*0.4*\pgfstartlinewidth}}%correct value would be 0.5 but arcs are not really flat, therefore 0.4 is better is (almost) all cases
    \foreach \x in {1,...,\ctikzvalof{bipoles/vamericaninductor/coils}}
    {
        \pgfpatharc{180}{0}{\pgf@circ@res@step and  \pgf@circ@res@other}
    }
    \pgfsetbuttcap
    \pgfsetbeveljoin
    \pgfusepath{stroke}

    \pgfscope
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfcirc@set@arrows{tunable}{}{latexslim}
        \pgfpathmoveto{\pgfpoint{.4\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{-.4\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}

%% Generic bipole, filled - used as inductor by some
\pgfcircdeclarebipolescaled{inductors}
{
    \anchor{midtap}{\northeast\pgf@x=0pt\relax}
    \pgfcir@basic@core@anchors
}
{\ctikzvalof{bipoles/fullgeneric/height}}
{fullgeneric}
{\ctikzvalof{bipoles/fullgeneric/height}}
{\ctikzvalof{bipoles/fullgeneric/width}}
{
    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgf@circ@fill@strokecolor
    \pgfusepath{draw,fill}
}

%% Generic sensor, filled - used as inductive sensor by some
\pgfcircdeclarebipolescaled{inductors}
{% anchor for labelling the type of dependency
    \anchor{label}{\southwest\pgf@x=0.4\pgf@x\pgf@y=2\pgf@y}%
    \anchor{midtap}{\northeast\pgf@x=0pt\relax}
    \pgfcirc@border@extend@full{1}{2}{1}{2}
    \pgfcir@basic@core@anchors
    \anchor{wiper}{\northeast\pgf@x=-\pgf@x\pgf@y=-2\pgf@y}
    \anchor{W}{\northeast\pgf@x=-\pgf@x\pgf@y=-2\pgf@y}
    \anchor{tip}{\northeast\pgf@y=2\pgf@y}
}
{\ctikzvalof{bipoles/fullgeneric/height}}
{sfullgeneric}
{\ctikzvalof{bipoles/fullgeneric/height}}
{\ctikzvalof{bipoles/fullgeneric/width}}
{

    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@fill@strokecolor
    \pgfusepath{draw,fill}
    \pgfscope
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@left}{-2\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@left}{2\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{2\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
}

%% Generic full tunable
\pgfcircdeclarebipolescaled{inductors}
{
    \anchor{midtap}{\northeast\pgf@x=0pt\relax}
    \saveddimen{\coredistance}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{bipoles/inductors/core distance}}}
    \anchor{core east}{%
        \northeast\pgf@y=0.4\pgf@y\advance\pgf@y by \coredistance
    }
    \anchor{core west}{%
        \northeast\pgf@y=0.4\pgf@y\advance\pgf@y by \coredistance\pgf@x=-\pgf@x
    }
    \anchor{wiper}{\northeast\pgf@x=-0.5\pgf@x\pgf@y=-\pgf@y}
    \anchor{W}{\northeast\pgf@x=-0.5\pgf@x\pgf@y=-\pgf@y}
    \anchor{tip}{\northeast\pgf@x=0.5\pgf@x}
}
{\ctikzvalof{bipoles/tfullgeneric/height}}
{tfullgeneric}
{\ctikzvalof{bipoles/tfullgeneric/height}}
{\ctikzvalof{bipoles/tfullgeneric/width}}
{
    \pgf@circ@res@step = \ctikzvalof{bipoles/resistor/width}\pgf@circ@Rlen
    \divide \pgf@circ@res@step by 14

    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{.4\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{.4\pgf@circ@res@down}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@fill@strokecolor
    \pgfusepath{draw,fill}

    \pgfscope
        \pgf@circ@set@relative@thickness{modifier thickness}
        \pgfcirc@set@arrows{tunable}{}{latexslim}
        \ifpgf@circ@fixtunable@dir
            \pgfpathmoveto{\pgfpoint{.5\pgf@circ@res@left}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{-.5\pgf@circ@res@left}{\pgf@circ@res@up}}
        \else
            \pgfpathmoveto{\pgfpoint{.5\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{-.5\pgf@circ@res@left}{\pgf@circ@res@down}}
        \fi
        \pgfusepath{draw}
    \endpgfscope
}
% %>>>

%% Paths for Inductors%<<<
%% these are complex because of the three-way set
%% should be simplified
\def\pgf@circ@inductor@path#1{%
    \pgfextra{
        \edef\pgf@circ@temp{\ctikzvalof{inductor}}%
        \def\pgf@temp{european}%
    }
    \ifx\pgf@temp\pgf@circ@temp%
        \pgf@circ@europeaninductor@path{#1}%
    \else%
        \pgfextra{  \def\pgf@temp{cute} }%
        \ifx\pgf@temp\pgf@circ@temp%
            \pgf@circ@cuteinductor@path{#1}%
        \else%
            \pgf@circ@americaninductor@path{#1}%
        \fi%
    \fi%
}
\pgfcirc@path@to@style{l}{inductor}{inductor}{}
\pgfcirc@style@to@style{inductor}{L}
\pgfcirc@activate@bipole{l}{europeaninductor}{fullgeneric}{european inductor}
\pgfcirc@activate@bipole{l}{americaninductor}{americaninductor}{american inductor}
\pgfcirc@activate@bipole{l}{cuteinductor}{cuteinductor}{cute inductor}

\def\pgf@circ@vinductor@path#1{
    \pgfextra{
        \edef\pgf@circ@temp{\ctikzvalof{inductor}}%
        \def\pgf@temp{european}%
    }
    \ifx\pgf@temp\pgf@circ@temp%
        \pgf@circ@veuropeaninductor@path{#1}%
    \else%
        \pgfextra{  \def\pgf@temp{cute} }%
        \ifx\pgf@temp\pgf@circ@temp%
            \pgf@circ@vcuteinductor@path{#1}%
        \else%
            \pgf@circ@vamericaninductor@path{#1}%
        \fi%
    \fi%
}
\pgfcirc@path@to@style{l}{vinductor}{variable inductor}{}
\pgfcirc@style@to@style{variable inductor}{vL}
\pgfcirc@activate@bipole{l}{veuropeaninductor}{tfullgeneric}{variable european inductor}
\pgfcirc@activate@bipole{l}{vamericaninductor}{vamericaninductor}{variable american inductor}
\pgfcirc@activate@bipole{l}{vcuteinductor}{vcuteinductor}{variable cute inductor}

\def\pgf@circ@inductivesens@path#1{%
    \pgfextra{
        \edef\pgf@circ@temp{\ctikzvalof{inductor}}%
        \def\pgf@temp{european}%
    }
    \ifx\pgf@temp\pgf@circ@temp%
        \pgf@circ@europeaninductivesens@path{#1}%
    \else%
        \pgfextra{  \def\pgf@temp{cute} }%
        \ifx\pgf@temp\pgf@circ@temp%
            \pgf@circ@cuteinductivesens@path{#1}%
        \else%
            \pgf@circ@americaninductivesens@path{#1}%
        \fi%
    \fi%
}
\pgfcirc@path@to@style{l}{inductivesens}{inductive sensor}{}
\pgfcirc@style@to@style{inductive sensor}{sL}
\pgfcirc@activate@bipole{l}{europeaninductivesens}{sfullgeneric}{european inductive sensor}
\pgfcirc@activate@bipole{l}{americaninductivesens}{samericaninductor}{american inductive sensor}
\pgfcirc@activate@bipole{l}{cuteinductivesens}{scuteinductor}{cute inductive sensor}

\pgfcirc@activate@bipole{l}{cutechoke}{cutechoke}{cute choke}
% %>>>

%%%%%%%%%%%
%% Sources (batteries, independent, dependents and so on
%%%%%%%%%%%

% Definitions for Sources%<<<1

\ctikzset{bipoles/esource/height/.initial=.60}
\ctikzset{bipoles/esource/width/.initial=.60}
\ctikzset{bipoles/pvsource/height/.initial=.60}
\ctikzset{bipoles/pvsource/width/.initial=.60}
\ctikzset{bipoles/pvmodule/height/.initial=.60}
\ctikzset{bipoles/pvmodule/width/.initial=1.20}
\ctikzset{bipoles/isource/height/.initial=.60}
\ctikzset{bipoles/isource/width/.initial=.60}
\ctikzset{bipoles/oosource/height/.initial=.60}
\ctikzset{bipoles/oosource/width/.initial=.60}
\ctikzset{bipoles/oosource/circlesize/.initial=.65}%circlesize+circleoffset should be =1
\ctikzset{bipoles/oosource/circleoffset/.initial=.35}%circlesize+circleoffset should be =1
\ctikzset{bipoles/dcisource/angle/.initial=80}
\ctikzset{bipoles/dcisource/height/.initial=.60}
\ctikzset{bipoles/dcisource/width/.initial=.60}
\ctikzset{bipoles/dcvsource/height/.initial=.60}
\ctikzset{bipoles/dcvsource/width/.initial=.60}
\ctikzset{bipoles/vsourcetri/height/.initial=.60}
\ctikzset{bipoles/vsourcetri/width/.initial=.60}
\ctikzset{bipoles/isourceam/height/.initial=.60}
\ctikzset{bipoles/isourceam/width/.initial=.60}
\ctikzset{bipoles/vsource/height/.initial=.60}
\ctikzset{bipoles/vsource/width/.initial=.60}
\ctikzset{bipoles/vsourceam/height/.initial=.60}
\ctikzset{bipoles/vsourceam/width/.initial=.60}
\ctikzset{bipoles/vsourceam/margin/.initial=.7}
\ctikzset{bipoles/isourcesin/angle/.initial=90}
\ctikzset{bipoles/isourcesin/height/.initial=.60}
\ctikzset{bipoles/isourcesin/width/.initial=.60}
\ctikzset{bipoles/vsourcesin/height/.initial=.60}
\ctikzset{bipoles/vsourcesin/width/.initial=.60}
\ctikzset{bipoles/vsourcesquare/height/.initial=.60}
\ctikzset{bipoles/vsourcesquare/width/.initial=.60}
\ctikzset{bipoles/cisource/height/.initial=.7}
\ctikzset{bipoles/cisource/width/.initial=.7}
\ctikzset{bipoles/cisourceam/height/.initial=.7}
\ctikzset{bipoles/cisourceam/width/.initial=.7}
\ctikzset{bipoles/ecsource/height/.initial=.7}
\ctikzset{bipoles/ecsource/width/.initial=.7}
\ctikzset{bipoles/cvsource/height/.initial=.7}
\ctikzset{bipoles/cvsource/width/.initial=.7}
\ctikzset{bipoles/cvsourceam/height/.initial=.7}
\ctikzset{bipoles/cvsourceam/width/.initial=.7}
\ctikzset{bipoles/cvsourceam/margin/.initial=.7}
\ctikzset{bipoles/cvsourceam/text scale/.initial=1}
\ctikzset{bipoles/cisourcesin/width/.initial=.7}
\ctikzset{bipoles/cvsourcesin/height/.initial=.7}
\ctikzset{bipoles/cvsourcesin/width/.initial=.7}
\ctikzset{bipoles/battery/height/.initial=.6}
\ctikzset{bipoles/battery/width/.initial=.3}
\ctikzset{bipoles/battery1/height/.initial=.6}
\ctikzset{bipoles/battery1/width/.initial=.3}
\ctikzset{bipoles/battery2/height/.initial=.6}
\ctikzset{bipoles/battery2/width/.initial=.3}
% noise sources
\ctikzset{bipoles/noise sources/fillcolor/.initial=gray!50}

% for special symbols in the sources: sin, square, triangle, delta, wye, eyw, zig, etc.
\ctikzset{sources/symbol/thickness/.initial={1}}
\ctikzset{csources/symbol/thickness/.initial={1}}
\ctikzset{sources/symbol/rotate/.initial={90}}
\ctikzset{csources/symbol/rotate/.initial={90}}

% % % ootransformer
\ctikzset{bipoles/oosourcetrans/height/.initial=.6}
\ctikzset{bipoles/oosourcetrans/width/.initial=.6}
\ctikzset{bipoles/oosourcetrans/circlesize/.initial=.6}%circlesize+circleoffset should be =1
\ctikzset{bipoles/oosourcetrans/circleoffset/.initial=.4}%circlesize+circleoffset should be =1
\ctikzset{bipoles/oosourcetrans/vectorgroupscale/.initial=1}

% % % oootransformer
\ctikzset{bipoles/ooosource/height/.initial=.6}
\ctikzset{bipoles/ooosource/circlesize/.initial=.55}%circlesize+circleoffset should be =1
\ctikzset{bipoles/ooosource/circleoffset/.initial=.45}%circlesize+circleoffset should be =1
\ctikzset{bipoles/ooosource/vectorgroupscale/.initial=1}

% % % primary windings
\newif\ifpgf@circ@prim@delta
\newif\ifpgf@circ@prim@wye
\newif\ifpgf@circ@prim@eyw
\newif\ifpgf@circ@prim@zig
\pgfkeys{tikz/prim/.is choice}
\pgfkeys{tikz/prim/delta/.add code={}{\pgf@circ@prim@deltatrue}}
\pgfkeys{tikz/prim/wye/.add code={}{\pgf@circ@prim@wyetrue}}
\pgfkeys{tikz/prim/eyw/.add code={}{\pgf@circ@prim@eywtrue}}
\pgfkeys{tikz/prim/zig/.add code={}{\pgf@circ@prim@zigtrue}}

% % % secondary windings
\newif\ifpgf@circ@sec@delta
\newif\ifpgf@circ@sec@wye
\newif\ifpgf@circ@sec@eyw
\newif\ifpgf@circ@sec@zig
\pgfkeys{tikz/sec/.is choice}
\pgfkeys{tikz/sec/delta/.add code={}{\pgf@circ@sec@deltatrue}}
\pgfkeys{tikz/sec/wye/.add code={}{\pgf@circ@sec@wyetrue}}
\pgfkeys{tikz/sec/eyw/.add code={}{\pgf@circ@sec@eywtrue}}
\pgfkeys{tikz/sec/zig/.add code={}{\pgf@circ@sec@zigtrue}}

% % % tertiary windings (ooosource)
\newif\ifpgf@circ@tert@delta
\newif\ifpgf@circ@tert@wye
\newif\ifpgf@circ@tert@eyw
\newif\ifpgf@circ@tert@zig
\pgfkeys{tikz/tert/.is choice}
\pgfkeys{tikz/tert/delta/.add code={}{\pgf@circ@tert@deltatrue}}
\pgfkeys{tikz/tert/wye/.add code={}{\pgf@circ@tert@wyetrue}}
\pgfkeys{tikz/tert/eyw/.add code={}{\pgf@circ@tert@eywtrue}}
\pgfkeys{tikz/tert/zig/.add code={}{\pgf@circ@tert@zigtrue}}%

% nullator and norator
\ctikzset{bipoles/nullator/height/.initial=.30}
\ctikzset{bipoles/nullator/width/.initial=.60}
\ctikzset{bipoles/norator/height/.initial=.25}
\ctikzset{bipoles/norator/width/.initial=.60}%must be greater than 2*height

%%>>>

%% Nodes definitions for sources%<<<

%% Battery
\pgfcircdeclarebipolescaled{batteries}
{}
{\ctikzvalof{bipoles/battery/height}}
{battery}
{\ctikzvalof{bipoles/battery/height}}
{\ctikzvalof{bipoles/battery/width}}
{
    \pgf@circ@res@step = \ctikzvalof{bipoles/battery/width}\pgf@circ@scaled@Rlen
    \divide \pgf@circ@res@step by 6

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \ifpgf@circ@fixbatteries
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{.5\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@step}{\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{.5\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \else
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@step}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@step}{.5\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{.5\pgf@circ@res@down}}
    \fi
    \pgfusepath{draw}
}


%% Battery 1 % poles with equl thickness

\pgfcircdeclarebipolescaled{batteries}
{}
{\ctikzvalof{bipoles/battery1/height}}
{battery1}
{\ctikzvalof{bipoles/battery1/height}}
{\ctikzvalof{bipoles/battery1/width}}
{
    \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@right}{0}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0}}
    \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@left}{0}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfusepath{draw}

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \ifpgf@circ@fixbatteries
        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.33\pgf@circ@res@right}{\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@left}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.33\pgf@circ@res@left}{.5\pgf@circ@res@down}}
    \else
        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@right}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.33\pgf@circ@res@right}{.5\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.33\pgf@circ@res@left}{\pgf@circ@res@down}}
    \fi
    \pgfusepath{draw}
}

%% Battery 2 % negative pole thicker

\pgfcircdeclarebipolescaled{batteries}
{}
{\ctikzvalof{bipoles/battery2/height}}
{battery2}
{\ctikzvalof{bipoles/battery2/height}}
{\ctikzvalof{bipoles/battery2/width}}
{
    \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@right}{0}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0}}
    \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@left}{0}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfusepath{draw}

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \ifpgf@circ@fixbatteries
        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.33\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgfusepath{draw}
        \pgfsetlinewidth{3\pgflinewidth}
        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@left}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.33\pgf@circ@res@left}{.5\pgf@circ@res@down}}
    \else
        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.33\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfusepath{draw}
        \pgfsetlinewidth{3\pgflinewidth}
        \pgfpathmoveto{\pgfpoint{.33\pgf@circ@res@right}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.33\pgf@circ@res@right}{.5\pgf@circ@res@down}}
    \fi
    \pgfusepath{draw}
}

%%%
%%% https://xkcd.com/2818/
%%% Also https://chat.stackexchange.com/transcript/message/64238058#64238058
%%%
\pgfcircdeclarebipolescaled{batteries}
{}
{\ctikzvalof{bipoles/battery/height}}
{baertty}
{\ctikzvalof{bipoles/battery/height}}
{\ctikzvalof{bipoles/battery/width}}
{
    \pgf@circ@res@step = \ctikzvalof{bipoles/battery/width}\pgf@circ@scaled@Rlen
    \divide \pgf@circ@res@step by 6
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{.5\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{.5\pgf@circ@res@down}}
    \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@step}{.5\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{-\pgf@circ@res@step}{.5\pgf@circ@res@down}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@down}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{draw}
}
\pgfcirc@activate@bipole@simple@opt{v}{baertty}{\circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}

%%%%%%%%%%%
%% Round and diamond sources
%%%%%%%%%%%

% % % symbol drawing macros (NOT for delta, wye, eyw, zig)
\def\pgf@circ@sources@symbol@setup{% called in a pgfscope
    \edef\@@@auto{auto}\edef\@@@rotate{\ctikzvalof{\ctikzclass/symbol/rotate}}
    \ifx\@@@auto\@@@rotate
        \pgfgettransformentries\a\b\temp\temp\temp\temp
        \pgfmathsetmacro{\@@@rotate}{-atan2(\b,\a)}
    \fi
    \pgftransformrotate{\@@@rotate}%
    \pgf@circ@set@relative@thickness{symbol/thickness}%
}

%% Independent voltage source
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/vsource/height}}
{vsource}
{\ctikzvalof{bipoles/vsource/height}}
{\ctikzvalof{bipoles/vsource/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfusepath{draw}
}


%% macros for the sources with plus and minus internally
%% To change the internal symbols of the voltage source american style
\ctikzset{bipoles/vsourceam/inner plus/.initial={$+$}}
% In the mayority of fonts, the size of - is smaller than +, so we have
% unaligned signs when positioned independently.
% See https://github.com/circuitikz/circuitikz/issues/721
\ctikzset{bipoles/vsourceam/inner minus/.initial={$\vphantom{+}-$}}
%%
%% add the possibility to change the orientation of signs
\ctikzset{sources/symbol/sign rotation/.initial=default}% default, auto, or value
%% this should be more or less equivalent to \ctikzset{sources/symbol/sign rotation=90}, but it's font-dependent,
%% so you never know. Let's keep the traditional one here.
\def\pgf@circ@vsources@signs@default{%
    \ifpgf@circ@oldvoltagedirection
        \pgftext[bottom,rotate=90,y=\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@down]{\ctikzvalof{bipoles/vsourceam/inner plus}}%
        \pgftext[top,rotate=90,y=\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@up]{\ctikzvalof{bipoles/vsourceam/inner minus}}%
    \else
        \pgftext[bottom,rotate=90,y=\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@down]{\ctikzvalof{bipoles/vsourceam/inner minus}}%
        \pgftext[top,rotate=90,y=\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@up]{\ctikzvalof{bipoles/vsourceam/inner plus}}%
    \fi
}
\def\pgf@circ@vsources@sign@auto@or@fix{%
    \pgfgettransformentries\a\b\temp\temp\temp\temp
    \pgfmathsetmacro{\rot}{-atan2(\b,\a)}
    % the distance here is choosen so that it seems ok with standard fonts... probably, it must be changed.
    \pgfmathsetlength{\pgf@circ@res@temp}{%
        \ctikzvalof{bipoles/vsourceam/margin}*\pgf@circ@res@up
        -0.5*height("\ctikzvalof{bipoles/vsourceam/inner plus}")}
    \ifx\@@rotmode\@@auto
        \pgfmathsetmacro{\innerrot}{abs(\rot)<46?0:(abs(\rot)>134?0:90)}
    \else
        \ifx\@@rotmode\@@straight
            \pgfmathsetmacro{\innerrot}{\rot}
        \else
            \pgfmathsetmacro{\innerrot}{\@@rotmode}
        \fi
    \fi
    \ifpgf@circ@oldvoltagedirection
        \pgfscope
            \pgftransformxshift{\pgf@circ@res@temp}
            \pgftext[rotate=\innerrot]{\ctikzvalof{bipoles/vsourceam/inner plus}}
        \endpgfscope
        \pgfscope
            \pgftransformxshift{-\pgf@circ@res@temp}
            \pgftext[rotate=\innerrot]{\ctikzvalof{bipoles/vsourceam/inner minus}}
        \endpgfscope
    \else
        \pgfscope
            \pgftransformxshift{\pgf@circ@res@temp}
            \pgftext[rotate=\innerrot]{\ctikzvalof{bipoles/vsourceam/inner minus}}
        \endpgfscope
        \pgfscope
            \pgftransformxshift{-\pgf@circ@res@temp}
            \pgftext[rotate=\innerrot]{\ctikzvalof{bipoles/vsourceam/inner plus}}
        \endpgfscope
    \fi
}
\def\pgf@circ@vsources@draw@signs{%
    \edef\@@auto{auto}\edef\@@default{default}\edef\@@straight{straight}%
    \edef\@@rotmode{\ctikzvalof{sources/symbol/sign rotation}}%
    \ifx\@@rotmode\@@default
        \pgf@circ@vsources@signs@default
    \else
        \pgf@circ@vsources@sign@auto@or@fix
    \fi
}

%% Independent voltage source - American style
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/vsourceam/height}}
{vsourceAM}
{\ctikzvalof{bipoles/vsourceam/height}}
{\ctikzvalof{bipoles/vsourceam/width}}
{

    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
        \pgf@circ@draworfill
    \endpgfscope
    \pgf@circ@text@strokecolor
    \pgf@circ@vsources@draw@signs
}

%% Independent sinusoidal voltage source
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/vsourcesin/height}}
{vsourcesin}
{\ctikzvalof{bipoles/vsourcesin/height}}
{\ctikzvalof{bipoles/vsourcesin/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill

    \pgf@circ@res@up = .5\pgf@circ@res@up
    \pgfscope
        \pgf@circ@sources@symbol@setup
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@up}{0cm}}
        \pgfpathsine{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{.5\pgf@circ@res@up}{-.5\pgf@circ@res@up}}
        \pgfpathsine{\pgfpoint{.5\pgf@circ@res@up}{-.5\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}

% Square Voltage source -  contributed by Alistair Kwan
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/vsourcesquare/height}}
{vsourcesquare}
{\ctikzvalof{bipoles/vsourcesquare/height}}
{\ctikzvalof{bipoles/vsourcesquare/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill
    \pgf@circ@res@up = .5\pgf@circ@res@up
    \pgfscope
        \pgf@circ@sources@symbol@setup
        \pgfpathmoveto{\pgfpoint{-1\pgf@circ@res@up}{0cm}}
        \pgfpathlineto{\pgfpoint{-1\pgf@circ@res@up}{1\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0\pgf@circ@res@up}{1\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0\pgf@circ@res@up}{-1\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{1\pgf@circ@res@up}{-1\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{1\pgf@circ@res@up}{0\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}

% Triangle Voltage source - contributed by Ralf Farkas
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/vsourcetri/height}}
{vsourcetri}
{\ctikzvalof{bipoles/vsourcetri/height}}
{\ctikzvalof{bipoles/vsourcetri/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill

    \pgf@circ@res@up = .5\pgf@circ@res@up
    \pgfscope
        \pgf@circ@sources@symbol@setup
        \pgfpathmoveto{\pgfpoint{-1\pgf@circ@res@up}{0cm}}
        \pgfpathlineto{\pgfpoint{-0.5\pgf@circ@res@up}{0.75\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@up}{-0.75\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{1\pgf@circ@res@up}{0\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}

%% PV Source
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/pvsource/height}}
{pvsource}
{\ctikzvalof{bipoles/pvsource/height}}
{\ctikzvalof{bipoles/pvsource/width}}
{
    \pgfpointorigin
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@up}}
    \pgf@circ@draworfill

    \pgfpathmoveto{\pgfpoint{.15\pgf@circ@res@right}{0}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0}}
    \pgfpathmoveto{\pgfpoint{.15\pgf@circ@res@left}{0}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfusepath{draw}

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{.15\pgf@circ@res@left}{.4\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{.15\pgf@circ@res@left}{.4\pgf@circ@res@down}}

    \pgfpathmoveto{\pgfpoint{.15\pgf@circ@res@right}{.6\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{.15\pgf@circ@res@right}{.6\pgf@circ@res@down}}
    \pgfusepath{draw}

    %Arrow Part
    \pgfscope
        \pgfsetarrowsend{latex}
        \pgfpathmoveto{\pgfpointadd{\pgfpoint{.3\pgf@circ@res@left}{0}}{\pgfpointpolar{-45}{2.2\pgf@circ@res@up}}}
        \pgfpathlineto{\pgfpointadd{\pgfpoint{.3\pgf@circ@res@left}{0}}{\pgfpointpolar{-45}{1.3\pgf@circ@res@up}}}
        \pgfusepath{draw}
        \pgfpathmoveto{\pgfpointadd{\pgfpoint{0}{0.3\pgf@circ@res@up}}{\pgfpointpolar{-45}{2.2\pgf@circ@res@up}}}
        \pgfpathlineto{\pgfpointadd{\pgfpoint{0}{0.3\pgf@circ@res@up}}{\pgfpointpolar{-45}{1.3\pgf@circ@res@up}}}
        \pgfusepath{draw}
    \endpgfscope

}

%% PV Module - contributed by Andre Alves
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/pvmodule/height}}
{pvmodule}
{\ctikzvalof{bipoles/pvmodule/height}}
{\ctikzvalof{bipoles/pvmodule/width}}
{

    % Draw rectangle
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathclose
    \pgf@circ@draworfill

    % Draw triangle
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@right}{0}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgf@circ@draworfill
    \pgfusepath{draw}
}

%% Empty Source
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/esource/height}}
{esource}
{\ctikzvalof{bipoles/esource/height}}
{\ctikzvalof{bipoles/esource/width}}
{
    \pgfpointorigin
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill
}

%% DC Current Source with open shape
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/dcisource/height}}
{dcisource}
{\ctikzvalof{bipoles/dcisource/height}}
{\ctikzvalof{bipoles/dcisource/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpointorigin}
    \pgfscope
        \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
        \pgf@circ@maybefill
    \endpgfscope
    \edef\@@angle{\ctikzvalof{bipoles/dcisource/angle}}
    \pgfpathmoveto{\pgfpointpolar{\@@angle}{\pgf@circ@res@up}}
    \pgfpatharc{\@@angle}{-\@@angle}{\pgf@circ@res@up}
    \pgfpathmoveto{\pgfpointpolar{180-\@@angle}{\pgf@circ@res@up}}
    \pgfpatharc{180-\@@angle}{180+\@@angle}{\pgf@circ@res@up}
    \pgfusepath{draw}

    \pgfpathmoveto{\pgfpoint{.7\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfusepath{draw}
    \pgfscope
        \pgftransformshift{\pgfpoint{.5\pgf@circ@res@right}{\pgf@circ@res@zero}}
        \pgfnode{currarrow}{center}{}{}{\pgfusepath{stroke}}
    \endpgfscope
}

%% DC-Voltage source
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/dcvsource/height}}
{dcvsource}
{\ctikzvalof{bipoles/dcvsource/height}}
{\ctikzvalof{bipoles/dcvsource/width}}
{
    \pgfpointorigin
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill
    \pgfpathmoveto{\pgfpoint{.2\pgf@circ@res@up}{.5\pgf@circ@res@left}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@up}{.5\pgf@circ@res@right}}
    \pgfpathmoveto{\pgfpoint{.2\pgf@circ@res@down}{.5\pgf@circ@res@left}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@down}{.5\pgf@circ@res@right}}
    \pgfusepath{draw}
}

%% Independent current source
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/isource/height}}
{isource}
{\ctikzvalof{bipoles/isource/height}}
{\ctikzvalof{bipoles/isource/width}}
{
    \pgfpointorigin
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@down}}
    \pgf@circ@draworfill
}

%% Independent double oo source
\pgfcircdeclarebipolescaled{sources}
{
    \anchor{centerprim}{
        \northeast
        \pgf@y=0pt\relax
        \pgf@x=-\ctikzvalof{bipoles/oosource/circleoffset}\pgf@x
    }
    \anchor{centersec}{
        \northeast
        \pgf@y=0pt\relax
        \pgf@x=\ctikzvalof{bipoles/oosource/circleoffset}\pgf@x
    }
}
{\ctikzvalof{bipoles/oosource/height}}
{oosource}
{\ctikzvalof{bipoles/oosource/height}}
{\ctikzvalof{bipoles/oosource/width}}
{
    \pgfpointorigin
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathcircle{\pgfpoint{\ctikzvalof{bipoles/oosource/circleoffset}\pgf@circ@res@left}{0}}
        {\ctikzvalof{bipoles/oosource/circlesize}\pgf@circ@res@left}
    \pgf@circ@maybefill
    \pgfpathcircle{\pgfpoint{\ctikzvalof{bipoles/oosource/circleoffset}\pgf@circ@res@right}{0}}
        {\ctikzvalof{bipoles/oosource/circlesize}\pgf@circ@res@right}
    \pgf@circ@draworfill
    \pgfpathcircle{\pgfpoint{\ctikzvalof{bipoles/oosource/circleoffset}\pgf@circ@res@left}{0}}
        {\ctikzvalof{bipoles/oosource/circlesize}\pgf@circ@res@left}
    \pgfusepath{draw}
}

% % % winding symbols
\ctikzset{sources/symbol/delta scale/.initial={1}}
\ctikzset{sources/symbol/wye scale/.initial={1}}
\ctikzset{sources/symbol/eyw scale/.initial={1}}
\ctikzset{sources/symbol/zig scale/.initial={1}}
% triangle
\def\pgf@circ@delta#1{
    \pgfscope
        \pgftransformscale{-.015*\ctikzvalof{\ctikzclass/symbol/delta scale}*\pgf@circ@res@left*#1}
        \def\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@direction\pgf@nil}
            \pgftransformrotate{-\pgfcircmathresult}

        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@set@relative@thickness{symbol/thickness}
        % \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        % \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
        % \pgfpathlineto{\pgfpoint{0}{.866\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpointpolar{90}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpointpolar{-30}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpointpolar{-150}{\pgf@circ@res@up}}
        \pgfpathclose
        \pgfusepath{stroke}
    \endpgfscope
}

% star
\def\pgf@circ@wye#1{
    \pgfscope
        \pgftransformscale{-.015*\ctikzvalof{\ctikzclass/symbol/wye scale}*\pgf@circ@res@left*#1}
        \def\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@direction\pgf@nil}
            \pgftransformrotate{-\pgfcircmathresult}

        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@set@relative@thickness{symbol/thickness}
        \pgfpathmoveto{\pgfpoint{0}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpointorigin}
        \pgfpathlineto{\pgfpointpolar{-30}{\pgf@circ@res@down}}
        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpointpolar{-150}{\pgf@circ@res@down}}
        \pgfusepath{stroke}
    \endpgfscope
}

% reverse star
\def\pgf@circ@eyw#1{
	\pgfscope
		\pgftransformscale{-.015*\ctikzvalof{\ctikzclass/symbol/eyw scale}*\pgf@circ@res@left*#1}
		\def\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@direction\pgf@nil}
			\pgftransformrotate{-\pgfcircmathresult}

		\pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
		\pgf@circ@set@relative@thickness{symbol/thickness}
		\pgfpathmoveto{\pgfpoint{0}{\pgf@circ@res@up}}
		\pgfpathlineto{\pgfpointorigin}
		\pgfpathlineto{\pgfpointpolar{30}{\pgf@circ@res@down}}
		\pgfpathmoveto{\pgfpointorigin}
		\pgfpathlineto{\pgfpointpolar{150}{\pgf@circ@res@down}}
		\pgfusepath{stroke}
	\endpgfscope
}

% zigzag
\def\pgf@circ@zig#1{
    \pgfscope
        \pgftransformscale{-.015*\ctikzvalof{\ctikzclass/symbol/zig scale}*\pgf@circ@res@left*#1}
        \def\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@direction\pgf@nil}
            \pgftransformrotate{-\pgfcircmathresult}

        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@set@relative@thickness{symbol/thickness}
        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpointpolar{90}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpointpolar{60}{\pgf@circ@res@up}}

        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpointpolar{210}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpointpolar{0}{\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpointpolar{330}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpointpolar{-60}{\pgf@circ@res@up}}
        \pgfusepath{stroke}
    \endpgfscope
}

% % % % round three-phase transformer
\pgfcircdeclarebipolescaled{sources}
{
    \anchor{centerprim}{
        \northeast
        \pgf@y=0pt\relax
        \pgf@x=-\ctikzvalof{bipoles/oosourcetrans/circleoffset}\pgf@x
    }
    \anchor{centersec}{
        \northeast
        \pgf@y=0pt\relax
        \pgf@x=\ctikzvalof{bipoles/oosourcetrans/circleoffset}\pgf@x
    }
    \anchor{symbolprim}{
        \northeast
        \pgf@y=0pt\relax
        \pgf@x=-\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@x
    }
    \anchor{symbolsec}{
        \northeast
        \pgf@y=0pt\relax
        \pgf@x=\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@x
    }
}
{\ctikzvalof{bipoles/oosourcetrans/height}}
{oosourcetrans}
{\ctikzvalof{bipoles/oosourcetrans/height}}
{\ctikzvalof{bipoles/oosourcetrans/width}}
{

    \pgfpointorigin
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathcircle{\pgfpoint{\ctikzvalof{bipoles/oosourcetrans/circleoffset}\pgf@circ@res@left}{0}}
        {\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@circ@res@left}
    \pgf@circ@maybefill
    \pgfpathcircle{\pgfpoint{\ctikzvalof{bipoles/oosourcetrans/circleoffset}\pgf@circ@res@right}{0}}
        {\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@circ@res@right}
    \pgf@circ@draworfill
    \pgfpathcircle{\pgfpoint{\ctikzvalof{bipoles/oosourcetrans/circleoffset}\pgf@circ@res@left}{0}}
        {\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@circ@res@left}
    \pgfusepath{draw}
    % % %     % draw inner symbols
    %%primary winding
    \ifpgf@circ@prim@delta
        \pgfscope
            \pgftransformxshift{\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@circ@res@left}
            \pgf@circ@delta{\ctikzvalof{bipoles/oosourcetrans/vectorgroupscale}}
        \endpgfscope

    \else\ifpgf@circ@prim@wye
        \pgfscope
            \pgftransformxshift{\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@circ@res@left}
            \pgf@circ@wye{\ctikzvalof{bipoles/oosourcetrans/vectorgroupscale}}
        \endpgfscope

        \else\ifpgf@circ@prim@eyw
        \pgfscope
        \pgftransformxshift{\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@circ@res@left}
        \pgf@circ@eyw{\ctikzvalof{bipoles/oosourcetrans/vectorgroupscale}}
        \endpgfscope

    \else\ifpgf@circ@prim@zig
        \pgfscope
            \pgftransformxshift{\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@circ@res@left}
            \pgf@circ@zig{\ctikzvalof{bipoles/oosourcetrans/vectorgroupscale}}
        \endpgfscope
    \fi\fi\fi\fi

    %%secondary winding
    \ifpgf@circ@sec@delta
        \pgfscope
            \pgftransformxshift{\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@circ@res@right}
            \pgf@circ@delta{\ctikzvalof{bipoles/oosourcetrans/vectorgroupscale}}
        \endpgfscope

    \else\ifpgf@circ@sec@wye
        \pgfscope
            \pgftransformxshift{\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@circ@res@right}
            \pgf@circ@wye{\ctikzvalof{bipoles/oosourcetrans/vectorgroupscale}}
        \endpgfscope

        \else\ifpgf@circ@sec@eyw
        \pgfscope
        \pgftransformxshift{\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@circ@res@right}
        \pgf@circ@eyw{\ctikzvalof{bipoles/oosourcetrans/vectorgroupscale}}
        \endpgfscope

    \else\ifpgf@circ@sec@zig
        \pgfscope
            \pgftransformxshift{\ctikzvalof{bipoles/oosourcetrans/circlesize}\pgf@circ@res@right}
            \pgf@circ@zig{\ctikzvalof{bipoles/oosourcetrans/vectorgroupscale}}
        \endpgfscope
    \fi\fi\fi\fi
}


% % % % ooosource for three phase transformer
\pgfcircdeclarebipolescaled{sources}
{
    \anchor{right}{
            \northeast
            \pgf@y=0pt
            \pgfmathparse{
                \ctikzvalof{bipoles/ooosource/circleoffset}* sin(30) +
    %%the sqrt must be > 0, the circles have to intersect
                sqrt(
                    pow(\ctikzvalof{bipoles/ooosource/circlesize},2) -
                    pow(\ctikzvalof{bipoles/ooosource/circleoffset}*cos(30),2)
                )
            }
            \pgf@x=\pgfmathresult\pgf@x
    }
    \anchor{east}{
            \northeast
            \pgf@y=0pt
    }
    \savedanchor{\centerprim}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=-\ctikzvalof{bipoles/ooosource/circleoffset}\pgf@circ@res@other
            \pgf@y=0pt
            \pgf@x=.5\pgf@circ@res@other
    }
    \anchor{centerprim}{
            \centerprim
    }
    \savedanchor{\centersec}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=-\ctikzvalof{bipoles/ooosource/circleoffset}\pgf@circ@res@other
            \pgfpointpolar{60}{.5\pgf@circ@res@other}
            \pgf@y=-\pgf@y
            \pgf@x=-\pgf@x
    }
    \anchor{centersec}{
            \centersec
    }
    \savedanchor{\centertert}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=-\ctikzvalof{bipoles/ooosource/circleoffset}\pgf@circ@res@other
            \pgfpointpolar{60}{.5\pgf@circ@res@other}
            \pgf@y=\pgf@y
            \pgf@x=-\pgf@x
    }
    \anchor{centertert}{
            \centertert
    }
    % add some anchors in case the are needed :)
    \anchor{prim1}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@other
            \pgfpointadd{\centerprim}{\pgfpointpolar{135}{.5\pgf@circ@res@other}}
    }
    \anchor{prim2}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@other
            \pgfpointadd{\centerprim}{\pgfpointpolar{-135}{.5\pgf@circ@res@other}}
    }
    \anchor{sec1}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@other
            \pgfpointadd{\centersec}{\pgfpointpolar{0}{.5\pgf@circ@res@other}}
    }
    \anchor{sec2}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@other
            \pgfpointadd{\centersec}{\pgfpointpolar{45}{.5\pgf@circ@res@other}}
    }
    \anchor{sec3}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@other
            \pgfpointadd{\centersec}{\pgfpointpolar{90}{.5\pgf@circ@res@other}}
    }
    \anchor{tert1}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@other
            \pgfpointadd{\centertert}{\pgfpointpolar{0}{.5\pgf@circ@res@other}}
    }
    \anchor{tert2}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@other
            \pgfpointadd{\centertert}{\pgfpointpolar{-45}{.5\pgf@circ@res@other}}
    }
    \anchor{tert3}{
            \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@other
            \pgfpointadd{\centertert}{\pgfpointpolar{-90}{.5\pgf@circ@res@other}}
    }
    % symbol "center" anchors
    \anchor{symbolprim}{
        \northeast
        \pgf@y=0pt
        \pgf@x=-0.6\pgf@x
    }
    \anchor{symbolsec}{
        \northeast
        \pgf@ya=\pgf@y
        \pgf@xa=\pgf@x
        \pgfpointpolar{60}{0.6\pgf@ya}
    }
    \anchor{symboltert}{
        \northeast
        \pgf@ya=\pgf@y
        \pgf@xa=\pgf@x
        \pgfpointpolar{-60}{0.6\pgf@ya}
    }
}
{\ctikzvalof{bipoles/ooosource/height}}
{ooosource}
{\ctikzvalof{bipoles/ooosource/height}}
{\ctikzvalof{bipoles/ooosource/height}}
{
%     \pgf@circ@res@other = \ctikzvalof{bipoles/ooosource/vectorgroup} \pgf@circ@scaled@Rlen

%     % filling
%     left
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathcircle{\pgfpoint{\ctikzvalof{bipoles/ooosource/circleoffset}\pgf@circ@res@left}{0}}{\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@left}
    \pgf@circ@maybefill

    % up
    \pgfscope
        \pgfpointorigin
        \pgfpathcircle{\pgfpointpolar{60}{\ctikzvalof{bipoles/ooosource/circleoffset}\pgf@circ@res@right}}{\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@right}
        \pgf@circ@maybefill
    \endpgfscope
%     down
    \pgfscope
        \pgfpointorigin
        \pgfpathcircle{\pgfpointpolar{-60}{\ctikzvalof{bipoles/ooosource/circleoffset}\pgf@circ@res@right}}{\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@right}
        \pgf@circ@draworfill
    \endpgfscope

%     drawing
    % left
    \pgfpathcircle{\pgfpoint{\ctikzvalof{bipoles/ooosource/circleoffset}\pgf@circ@res@left}{0}}{\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@left}
    \pgfusepath{draw}

    % up
    \pgfscope
        \pgfpointorigin
        \pgfpathcircle{\pgfpointpolar{60}{\ctikzvalof{bipoles/ooosource/circleoffset}\pgf@circ@res@right}}{\ctikzvalof{bipoles/ooosource/circlesize}\pgf@circ@res@right}
        \pgfusepath{draw}
    \endpgfscope

% % %     draw inner symbols

% %     primary winding
    \ifpgf@circ@prim@delta
        \pgfscope
            \pgftransformxshift{.6\pgf@circ@res@left}
            \pgf@circ@delta{\ctikzvalof{bipoles/ooosource/vectorgroupscale}}
        \endpgfscope

    \else\ifpgf@circ@prim@wye
        \pgfscope
            \pgftransformxshift{.6\pgf@circ@res@left}
            \pgf@circ@wye{\ctikzvalof{bipoles/ooosource/vectorgroupscale}}
        \endpgfscope

        \else\ifpgf@circ@prim@eyw
        \pgfscope
        \pgftransformxshift{.6\pgf@circ@res@left}
        \pgf@circ@eyw{\ctikzvalof{bipoles/ooosource/vectorgroupscale}}
        \endpgfscope

    \else\ifpgf@circ@prim@zig
        \pgfscope
            \pgftransformxshift{.6\pgf@circ@res@left}
            \pgf@circ@zig{\ctikzvalof{bipoles/ooosource/vectorgroupscale}}
        \endpgfscope
    \fi\fi\fi\fi

% %     secondary winding
    \ifpgf@circ@sec@delta
        \pgfscope
            \pgfpointorigin
            \pgftransformshift{\pgfpointpolar{60}{0.6\pgf@circ@res@right}}
            \pgf@circ@delta{\ctikzvalof{bipoles/ooosource/vectorgroupscale}}
        \endpgfscope

    \else\ifpgf@circ@sec@wye
        \pgfscope
            \pgftransformshift{\pgfpointpolar{60}{0.6\pgf@circ@res@right}}
            \pgf@circ@wye{\ctikzvalof{bipoles/ooosource/vectorgroupscale}}
        \endpgfscope

        \else\ifpgf@circ@sec@eyw
        \pgfscope
        \pgftransformshift{\pgfpointpolar{60}{0.6\pgf@circ@res@right}}
        \pgf@circ@eyw{\ctikzvalof{bipoles/ooosource/vectorgroupscale}}
        \endpgfscope

    \else\ifpgf@circ@sec@zig
        \pgfscope
            \pgftransformshift{\pgfpointpolar{60}{0.6\pgf@circ@res@right}}
            \pgf@circ@zig{\ctikzvalof{bipoles/ooosource/vectorgroupscale}}
        \endpgfscope
    \fi\fi\fi\fi

% %     tertiary winding
    \ifpgf@circ@tert@delta
        \pgfscope
            \pgftransformshift{\pgfpointpolar{-60}{0.6\pgf@circ@res@right}}
            \pgf@circ@delta{\ctikzvalof{bipoles/ooosource/vectorgroupscale}}
        \endpgfscope

    \else\ifpgf@circ@tert@wye
        \pgfscope
            \pgftransformshift{\pgfpointpolar{-60}{0.6\pgf@circ@res@right}}
            \pgf@circ@wye{\ctikzvalof{bipoles/ooosource/vectorgroupscale}}
        \endpgfscope

        \else\ifpgf@circ@tert@eyw
        \pgfscope
        \pgftransformshift{\pgfpointpolar{-60}{0.6\pgf@circ@res@right}}
        \pgf@circ@eyw{\ctikzvalof{bipoles/ooosource/vectorgroupscale}}
        \endpgfscope

    \else\ifpgf@circ@tert@zig
        \pgfscope
            \pgftransformshift{\pgfpointpolar{-60}{0.6\pgf@circ@res@right}}
            \pgf@circ@zig{\ctikzvalof{bipoles/ooosource/vectorgroupscale}}
        \endpgfscope
    \fi\fi\fi\fi
}

%% Independent current source - American
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/isourceam/height}}
{isourceAM}
{\ctikzvalof{bipoles/isourceam/height}}
{\ctikzvalof{bipoles/isourceam/width}}
{
    \pgfpointorigin
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill

    \pgfpathmoveto{\pgfpoint{.7\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfusepath{draw}
    \pgfscope
        \pgftransformshift{\pgfpoint{.5\pgf@circ@res@right}{\pgf@circ@res@zero}}
        \pgfnode{currarrow}{center}{}{}{\pgfusepath{stroke}}
    \endpgfscope
}

%% Independent sinusoidal current source with open shape
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/isource/height}}
{isourcesin}
{\ctikzvalof{bipoles/isource/height}}
{\ctikzvalof{bipoles/isource/width}}
{
    \pgfpointorigin
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
        \pgf@circ@maybefill
    \endpgfscope
    \edef\@@angle{\ctikzvalof{bipoles/isourcesin/angle}}
    \pgfpathmoveto{\pgfpointpolar{\@@angle}{\pgf@circ@res@up}}
    \pgfpatharc{\@@angle}{-\@@angle}{\pgf@circ@res@up}
    \pgfpathmoveto{\pgfpointpolar{180-\@@angle}{\pgf@circ@res@up}}
    \pgfpatharc{180-\@@angle}{180+\@@angle}{\pgf@circ@res@up}
    \pgfusepath{draw}

    \pgf@circ@res@up = .5\pgf@circ@res@up
    \pgfscope
        \pgf@circ@sources@symbol@setup
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@up}{0cm}}
        \pgfpathsine{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{.5\pgf@circ@res@up}{-.5\pgf@circ@res@up}}
        \pgfpathsine{\pgfpoint{.5\pgf@circ@res@up}{-.5\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}

%% Empty controlled source
\pgfcircdeclarebipolescaled{csources}
{}
{\ctikzvalof{bipoles/ecsource/height}}
{ecsource}
{\ctikzvalof{bipoles/ecsource/height}}
{\ctikzvalof{bipoles/ecsource/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
    \pgfpathclose
    \pgf@circ@draworfill
}

%% Controlled voltage source
\pgfcircdeclarebipolescaled{csources}
{}
{\ctikzvalof{bipoles/cvsource/height}}
{cvsource}
{\ctikzvalof{bipoles/cvsource/height}}
{\ctikzvalof{bipoles/cvsource/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
    \pgfpathclose
    \pgf@circ@draworfill

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfusepath{draw}
}

%% To change the internal symbols of the controlled voltage source american style
\ctikzset{bipoles/cvsourceam/inner plus/.initial={$+$}}
% In the mayority of fonts, the size of - is smaller than +, so we have
% unaligned signs when positioned independently.
% See https://github.com/circuitikz/circuitikz/issues/721
\ctikzset{bipoles/cvsourceam/inner minus/.initial={$\vphantom{+}-$}}
%% Controlled voltage source - American
\pgfcircdeclarebipolescaled{csources}
{}
{\ctikzvalof{bipoles/cvsourceam/height}}
{cvsourceAM}
{\ctikzvalof{bipoles/cvsourceam/height}}
{\ctikzvalof{bipoles/cvsourceam/width}}
{
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
        \pgfpathclose
        \pgf@circ@draworfill
    \endpgfscope
    \pgf@circ@text@strokecolor
    \pgf@circ@vsources@draw@signs
}

%% Controlled sinusoidal voltage source
\pgfcircdeclarebipolescaled{csources}
{}
{\ctikzvalof{bipoles/cvsourcesin/height}}
{cvsourcesin}
{\ctikzvalof{bipoles/cvsourcesin/height}}
{\ctikzvalof{bipoles/cvsourcesin/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfscope
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
        \pgfpathclose
        \pgf@circ@draworfill
    \endpgfscope

    \pgf@circ@res@up = .5\pgf@circ@res@up
    \pgfscope
        \pgf@circ@sources@symbol@setup
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@up}{0cm}}
        \pgfpathsine{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{.5\pgf@circ@res@up}{-.5\pgf@circ@res@up}}
        \pgfpathsine{\pgfpoint{.5\pgf@circ@res@up}{-.5\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}

%% Controlled sinusoidal current source
\pgfcircdeclarebipolescaled{csources}
{}
{\ctikzvalof{bipoles/cvsourcesin/height}}
{cisourcesin}
{\ctikzvalof{bipoles/cvsourcesin/height}}
{\ctikzvalof{bipoles/cvsourcesin/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfscope
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
        \pgfpathclose
        \pgf@circ@draworfill
    \endpgfscope

    \pgf@circ@res@up = .5\pgf@circ@res@up
    \pgfscope
        \pgf@circ@sources@symbol@setup
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@up}{0cm}}
        \pgfpathsine{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{.5\pgf@circ@res@up}{-.5\pgf@circ@res@up}}
        \pgfpathsine{\pgfpoint{.5\pgf@circ@res@up}{-.5\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}

%% Controlled current source
\pgfcircdeclarebipolescaled{csources}
{}
{\ctikzvalof{bipoles/cisource/height}}
{cisource}
{\ctikzvalof{bipoles/cisource/height}}
{\ctikzvalof{bipoles/cisource/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
    \pgfpathclose
    \pgf@circ@draworfill

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
    \pgfusepath{draw}
}

%% Controlled current source - American
\pgfcircdeclarebipolescaled{csources}
{}
{\ctikzvalof{bipoles/cisourceam/height}}
{cisourceAM}
{\ctikzvalof{bipoles/cisourceam/height}}
{\ctikzvalof{bipoles/cisourceam/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
    \pgfpathclose
    \pgf@circ@draworfill
    \pgfpathmoveto{\pgfpoint{.7\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfusepath{draw}
    \pgfscope
        \pgftransformshift{\pgfpoint{.5\pgf@circ@res@right}{\pgf@circ@res@zero}}
        \pgfnode{currarrow}{center}{}{}{\pgfusepath{stroke}}
    \endpgfscope
}

%% Cute Independent voltage source
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/vsource/height}}
{vsourceC}
{\ctikzvalof{bipoles/vsource/height}}
{\ctikzvalof{bipoles/vsource/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill
    \pgfmathsetmacro{\@@thicker}{3*\ctikzvalof{bipoles/thickness}}
    \pgfsetlinewidth{\@@thicker\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfsetroundcap\pgfusepath{draw}
}

%% Cute Independent current source
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/isource/height}}
{isourceC}
{\ctikzvalof{bipoles/isource/height}}
{\ctikzvalof{bipoles/isource/width}}
{
    \pgfpointorigin
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill
    \pgfmathsetmacro{\@@thicker}{3*\ctikzvalof{bipoles/thickness}}
    \pgfsetlinewidth{\@@thicker\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{.6\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{.6\pgf@circ@res@down}}
    \pgfsetroundcap\pgfusepath{draw}
}

%% Cute Controlled voltage source
\pgfcircdeclarebipolescaled{csources}
{}
{\ctikzvalof{bipoles/cvsource/height}}
{cvsourceC}
{\ctikzvalof{bipoles/cvsource/height}}
{\ctikzvalof{bipoles/cvsource/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgf@circ@draworfill
    \pgfmathsetmacro{\@@thicker}{3*\ctikzvalof{bipoles/thickness}}
    \pgfsetlinewidth{\@@thicker\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfsetroundcap\pgfusepath{draw}
}

%% Cute Controlled current source
\pgfcircdeclarebipolescaled{csources}
{}
{\ctikzvalof{bipoles/cisource/height}}
{cisourceC}
{\ctikzvalof{bipoles/cisource/height}}
{\ctikzvalof{bipoles/cisource/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgf@circ@draworfill
    \pgfmathsetmacro{\@@thicker}{3*\ctikzvalof{bipoles/thickness}}
    \pgfsetlinewidth{\@@thicker\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@zero}{.6\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{.6\pgf@circ@res@down}}
    \pgfsetroundcap\pgfusepath{draw}
}

%%  Noise voltage source
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/vsource/height}}
{vsourceN}
{\ctikzvalof{bipoles/vsource/height}}
{\ctikzvalof{bipoles/vsource/width}}
{
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
        %
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=0.125\pgf@circ@scaled@Rlen\relax
        \edef\pgf@noise@temp{dashed}
        \edef\pgf@noise@fill{\ctikzvalof{bipoles/noise sources/fillcolor}}
        \ifx\pgf@noise@temp\pgf@noise@fill
            % fillable in this case
            \pgf@circ@draworfillandclip
            \pgfmathsetmacro{\@@thinner}{.5*\ctikzvalof{bipoles/thickness}}
            \pgfsetlinewidth{\@@thinner\pgfstartlinewidth}
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \advance\pgf@circ@res@up by \pgf@circ@res@step\advance\pgf@circ@res@down by \pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \advance\pgf@circ@res@up by \pgf@circ@res@step\advance\pgf@circ@res@down by \pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \advance\pgf@circ@res@up by \pgf@circ@res@step\advance\pgf@circ@res@down by \pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            %
            \advance\pgf@circ@res@up by -4\pgf@circ@res@step \advance\pgf@circ@res@down by -4\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \advance\pgf@circ@res@up by -\pgf@circ@res@step\advance\pgf@circ@res@down by -\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \advance\pgf@circ@res@up by -\pgf@circ@res@step\advance\pgf@circ@res@down by -\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgfusepath{draw}
        \else
            \pgfsetfillcolor{\pgf@noise@fill}
            \pgfusepath{draw,fill}
        \fi
    \endpgfscope
    \pgfmathsetmacro{\@@thicker}{3*\ctikzvalof{bipoles/thickness}}
    \pgfsetlinewidth{\@@thicker\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfsetroundcap\pgfusepath{draw}
}
%% Noise current source

\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/isource/height}}
{isourceN}
{\ctikzvalof{bipoles/isource/height}}
{\ctikzvalof{bipoles/isource/width}}
{
    \pgfpointorigin
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
        %
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=0.125\pgf@circ@scaled@Rlen\relax
        \edef\pgf@noise@temp{dashed}
        \edef\pgf@noise@fill{\ctikzvalof{bipoles/noise sources/fillcolor}}
        \ifx\pgf@noise@temp\pgf@noise@fill
            % fillable in this case
            \pgf@circ@draworfillandclip
            \pgfmathsetmacro{\@@thinner}{.5*\ctikzvalof{bipoles/thickness}}
            \pgfsetlinewidth{\@@thinner\pgfstartlinewidth}
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \advance\pgf@circ@res@up by \pgf@circ@res@step\advance\pgf@circ@res@down by \pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \advance\pgf@circ@res@up by \pgf@circ@res@step\advance\pgf@circ@res@down by \pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \advance\pgf@circ@res@up by \pgf@circ@res@step\advance\pgf@circ@res@down by \pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            %
            \advance\pgf@circ@res@up by -4\pgf@circ@res@step \advance\pgf@circ@res@down by -4\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \advance\pgf@circ@res@up by -\pgf@circ@res@step\advance\pgf@circ@res@down by -\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \advance\pgf@circ@res@up by -\pgf@circ@res@step\advance\pgf@circ@res@down by -\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgfusepath{draw}
        \else
            \pgfsetfillcolor{\pgf@noise@fill}
            \pgfusepath{draw,fill}
        \fi
    \endpgfscope
    \pgfmathsetmacro{\@@thicker}{3*\ctikzvalof{bipoles/thickness}}
    \pgfsetlinewidth{\@@thicker\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{.6\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{.6\pgf@circ@res@down}}
    \pgfsetroundcap\pgfusepath{draw}
}

% nullator
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/nullator/height}}
{nullator}
{\ctikzvalof{bipoles/nullator/height}}
{\ctikzvalof{bipoles/nullator/width}}
{
    \pgfpointorigin
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill
}
% norator
\pgfcircdeclarebipolescaled{sources}
{}
{\ctikzvalof{bipoles/norator/height}}
{norator}
{\ctikzvalof{bipoles/norator/height}}
{\ctikzvalof{bipoles/norator/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@res@other=\dimexpr\pgf@circ@res@right-\pgf@circ@res@up\relax
    \pgfmathsetmacro{\@@angle}{atan2(\pgf@circ@res@other,\pgf@circ@res@up)}
    % \typeout{ANGLE\space\@@angle}
    \pgfmathsetlength{\pgf@circ@res@step}{\pgf@circ@res@up*cos(\@@angle)}
    \pgfmathsetlength{\pgf@circ@res@temp}{\pgf@circ@res@up*sin(\@@angle)}
    % right semicircle
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other-\pgf@circ@res@step}{\pgf@circ@res@temp}}
    \pgfpatharc{180-\@@angle}{-180+\@@angle}{\pgf@circ@res@up}
    % connect to left semicircle
    \pgfpathlineto
        {\pgfpoint{-\pgf@circ@res@other+\pgf@circ@res@step}{\pgf@circ@res@temp}}
    % left semicircle
    \pgfpatharc{\@@angle}{360-\@@angle}{\pgf@circ@res@up}
    % connect to right semicircle
    \pgfpathlineto
        {\pgfpoint{\pgf@circ@res@other-\pgf@circ@res@step}{\pgf@circ@res@temp}}
    \pgfpathclose
    \pgf@circ@draworfill
}

% %>>>

%% Paths definitions for Sources%<<<

%% Batteries

\pgfcirc@activate@bipole@simple@opt{v}{battery}{\circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
\pgfcirc@activate@bipole@opt{v}{batteryone}{battery1}{battery1}{\circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
\pgfcirc@activate@bipole@opt{v}{batterytwo}{battery2}{battery2}{\circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
%% Sources: voltage

\pgfcirc@activate@bipole@opt{v}{vsource}{vsource}{european voltage source}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
\pgfcirc@activate@bipole@opt{v}{vsourceam}{vsourceAM}{american voltage source}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=false}
\pgfcirc@style@to@style{\ifpgf@circuit@europeanvoltage european \else american \fi voltage source}{voltage source}
\pgfcirc@style@to@style{voltage source}{vsource}
\pgfcirc@style@to@style{voltage source}{V}

\pgfcirc@activate@bipole@opt{v}{cvsource}{cvsource}{european controlled voltage source}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
\pgfcirc@activate@bipole@opt{v}{cvsourceam}{cvsourceAM}{american controlled voltage source}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=false}
\pgfcirc@style@to@style{\ifpgf@circuit@europeanvoltage european \else american \fi controlled voltage source}{controlled voltage source}
\pgfcirc@style@to@style{controlled voltage source}{cvsource}
\pgfcirc@style@to@style{controlled voltage source}{controlled vsource}
\pgfcirc@style@to@style{controlled voltage source}{cV}

\pgfcirc@activate@bipole@simple@opt{v}{esource}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}

\pgfcirc@activate@bipole@opt{v}{ecsource}{ecsource}{empty controlled source}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
\pgfcirc@style@to@style{empty controlled source}{ecsource}

\pgfcirc@activate@bipole@opt{v}{vsourcesin}{vsourcesin}{sinusoidal voltage source}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
\pgfcirc@style@to@style{sinusoidal voltage source}{vsourcesin}
\pgfcirc@style@to@style{sinusoidal voltage source}{sV}

\pgfcirc@activate@bipole@opt{v}{cvsourcesin}{cvsourcesin}{controlled sinusoidal voltage source}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
\pgfcirc@style@to@style{controlled sinusoidal voltage source}{cvsourcesin}
\pgfcirc@style@to@style{controlled sinusoidal voltage source}{controlled vsourcesin}
\pgfcirc@style@to@style{controlled sinusoidal voltage source}{csV}

\pgfcirc@activate@bipole@opt{v}{vsourcesquare}{vsourcesquare}{square voltage source}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
\pgfcirc@style@to@style{square voltage source}{vsourcesquare}
\pgfcirc@style@to@style{square voltage source}{sqV}

\pgfcirc@activate@bipole@opt{v}{vsourcetri}{vsourcetri}{triangle voltage source}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
\pgfcirc@style@to@style{triangle voltage source}{vsourcetri}
\pgfcirc@style@to@style{triangle voltage source}{tV}

\pgfcirc@activate@bipole@simple@opt{v}{pvsource}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}

\pgfcirc@activate@bipole@simple@opt{v}{pvmodule}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}

\pgfcirc@activate@bipole@simple@opt{v}{dcvsource}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}

\pgfcirc@activate@bipole@opt{v}{oosource}{oosource}{voosource}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}

\pgfcirc@activate@bipole@simple@opt{v}{ooosource}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}

\pgfcirc@activate@bipole@simple@opt{v}{oosourcetrans}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}

\pgfcirc@activate@bipole@opt{v}{vsourceC}{vsourceC}{cute european voltage source}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
\pgfcirc@style@to@style{cute european voltage source}{vsourceC}
\pgfcirc@style@to@style{cute european voltage source}{ceV}

\pgfcirc@activate@bipole@opt{v}{cvsourceC}{cvsourceC}{cute european controlled voltage source}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
\pgfcirc@style@to@style{cute european controlled voltage source}{cvsourceC}
\pgfcirc@style@to@style{cute european controlled voltage source}{cceV}

\pgfcirc@activate@bipole@opt{v}{vsourceN}{vsourceN}{noise voltage source}{%
    \circuitikzbasekey/bipole/is voltage=true,
    \circuitikzbasekey/bipole/is voltageoutsideofsymbol=true}
\pgfcirc@style@to@style{noise voltage source}{vsourceN}
\pgfcirc@style@to@style{noise voltage source}{nV}

%% Sources: current

\pgfcirc@activate@bipole@opt{i}{isource}{isource}{european current source}{%
    \circuitikzbasekey/bipole/is current=true}
\pgfcirc@activate@bipole@opt{i}{isourceam}{isourceAM}{american current source}{%
    \circuitikzbasekey/bipole/is current=true}
\pgfcirc@style@to@style{\ifpgf@circuit@europeancurrent european \else american \fi current source}{current source}
\pgfcirc@style@to@style{current source}{isource}
\pgfcirc@style@to@style{current source}{I}

\pgfcirc@activate@bipole@opt{i}{cisource}{cisource}{european controlled current source}{%
    \circuitikzbasekey/bipole/is current=true}
\pgfcirc@activate@bipole@opt{i}{cisourceam}{cisourceAM}{american controlled current source}{%
    \circuitikzbasekey/bipole/is current=true}
\pgfcirc@style@to@style{\ifpgf@circuit@europeanvoltage european \else american \fi controlled current source}{controlled current source}
\pgfcirc@style@to@style{controlled current source}{cisource}
\pgfcirc@style@to@style{controlled current source}{controlled isource}
\pgfcirc@style@to@style{controlled current source}{cI}

\pgfcirc@activate@bipole@opt{i}{isourcesin}{isourcesin}{sinusoidal current source}{%
    \circuitikzbasekey/bipole/is current=true}
\pgfcirc@style@to@style{sinusoidal current source}{isourcesin}
\pgfcirc@style@to@style{sinusoidal current source}{sI}

\pgfcirc@activate@bipole@opt{i}{cisourcesin}{cisourcesin}{controlled sinusoidal current source}{%
    \circuitikzbasekey/bipole/is current=true}
\pgfcirc@style@to@style{controlled sinusoidal current source}{cisourcesin}
\pgfcirc@style@to@style{controlled sinusoidal current source}{controlled isourcesin}
\pgfcirc@style@to@style{controlled sinusoidal current source}{csI}

\pgfcirc@activate@bipole@simple@opt{i}{dcisource}{%
    \circuitikzbasekey/bipole/is current=true}

\pgfcirc@activate@bipole@opt{i}{oosource}{oosource}{ioosource}{%
    \circuitikzbasekey/bipole/is current=true}

\pgfcirc@activate@bipole@opt{i}{isourceC}{isourceC}{cute european current source}{%
    \circuitikzbasekey/bipole/is current=true}
\pgfcirc@style@to@style{cute european current source}{isourceC}
\pgfcirc@style@to@style{cute european current source}{ceI}

\pgfcirc@activate@bipole@opt{i}{cisourceC}{cisourceC}{cute european controlled current source}{%
    \circuitikzbasekey/bipole/is current=true}
\pgfcirc@style@to@style{cute european controlled current source}{cisourceC}
\pgfcirc@style@to@style{cute european controlled current source}{cceI}

\pgfcirc@activate@bipole@opt{i}{isourceN}{isourceN}{noise current source}{%
    \circuitikzbasekey/bipole/is current=true}
\pgfcirc@style@to@style{noise current source}{isourceN}
\pgfcirc@style@to@style{noise current source}{nI}

% norator, nullator
\pgfcirc@activate@bipole@simple{l}{nullator}
\pgfcirc@activate@bipole@simple{l}{norator}

% build alias with voltage and current directions (legacy)

\def\pgf@temp#1{
    \pgfcirc@style@to@style@label{voltage source}{V#1}{v#1}
    \pgfcirc@style@to@style@label{controlled voltage source}{cV#1}{v#1}
    \pgfcirc@style@to@style@label{sinusoidal voltage source}{sV#1}{v#1}
    \pgfcirc@style@to@style@label{controlled sinusoidal voltage source}{csV#1}{v#1}
}
\pgf@temp{_>} \pgf@temp{_<} \pgf@temp{^>} \pgf@temp{^<}
\pgf@temp{>} \pgf@temp{<} \pgf@temp{^} \pgf@temp{_}
\def\pgf@temp#1{
    \pgfcirc@style@to@style@label{current source}{I#1}{i#1}
    \pgfcirc@style@to@style@label{controlled current source}{cI#1}{i#1}
    \pgfcirc@style@to@style@label{sinusoidal current source}{sI#1}{i#1}
    \pgfcirc@style@to@style@label{controlled sinusoidal current source}{csI#1}{i#1}
}
\pgf@temp{_>} \pgf@temp{_<} \pgf@temp{^>} \pgf@temp{^<}
\pgf@temp{>_} \pgf@temp{<_} \pgf@temp{>^} \pgf@temp{<^}
\pgf@temp{>} \pgf@temp{<} \pgf@temp{^} \pgf@temp{_}
% %>>>


%%%%%%%%%%%%%%
%% Diodes
%%%%%%%%%%%%%%

% Definitions for diodes%<<<1

\ctikzset{bipoles/diode/height/.initial=.50}
\ctikzset{bipoles/diode/width/.initial=.40}
% for horizontally-double-sided diodes, like tvs diodes (transorb)
\ctikzset{bipoles/ddiode/width/.initial=.80}% must be 2*diode width
% for vertically taller diodes
\ctikzset{bipoles/bidirectionaldiode/height/.initial=1.1}
\ctikzset{bipoles/bidirectionaldiode/width/.initial=1}
\ctikzset{bipoles/bidirectionaldiode/diode width left/.initial=.3}
\ctikzset{bipoles/bidirectionaldiode/diode width right/.initial=.3}
\ctikzset{bipoles/varcap/height/.initial=.50}
\ctikzset{bipoles/varcap/width/.initial=.45}

\ctikzset{tripoles/thyristor/height/.initial=1.10}
\ctikzset{tripoles/thyristor/height 2/.initial=.5}
\ctikzset{tripoles/thyristor/width/.initial=1.0}
\ctikzset{tripoles/thyristor/diode height/.initial=.5}
\ctikzset{tripoles/thyristor/diode width left/.initial=.4}
\ctikzset{tripoles/thyristor/diode width right/.initial=.3}
\ctikzset{tripoles/thyristor/gate height/.initial=0.0} % legacy 0
\ctikzset{tripoles/thyristor/gate kink/.initial=1.0} % legacy 1.0
\ctikzset{tripoles/thyristor/gto space up/.initial=0.5} % legacy 0.5
\ctikzset{tripoles/thyristor/gto space down/.initial=0.0} % legacy 0.0
\ctikzset{tripoles/thyristor/gto bar width/.initial=0.2} % legacy 0.2

\ctikzset{tripoles/triac/height/.initial=1.1}
\ctikzset{tripoles/triac/width/.initial=1}
\ctikzset{tripoles/triac/diode width left/.initial=.3}
\ctikzset{tripoles/triac/diode width right/.initial=.3}
\ctikzset{tripoles/triac/gate kink/.initial=1}

\ctikzset{thyristor style/.is choice}
\ctikzset{thyristor style/legacy/.code={%
    \ctikzset{tripoles/thyristor/height=1.1}%
    \ctikzset{tripoles/thyristor/height 2=.5}%
    \ctikzset{tripoles/thyristor/width=1.0}%
    \ctikzset{tripoles/thyristor/diode height=.5}%
    \ctikzset{tripoles/thyristor/diode width left=.4}%
    \ctikzset{tripoles/thyristor/diode width right=.3}%
    \ctikzset{tripoles/thyristor/gate height=0.0}%
    \ctikzset{tripoles/thyristor/gate kink=1.0}%
    \ctikzset{tripoles/thyristor/gto space up=0.5}%
    \ctikzset{tripoles/thyristor/gto space down=0.0}%
    \ctikzset{tripoles/thyristor/gto bar width=0.2}%
    \ctikzset{tripoles/triac/gate kink=1}%
}}
\ctikzset{thyristor style/compact/.code={%
    \ctikzset{tripoles/thyristor/height=0.8}% legacy 1.1
    \ctikzset{tripoles/thyristor/height 2=.5}%
    \ctikzset{tripoles/thyristor/width=1.0}%
    \ctikzset{tripoles/thyristor/diode height=.5}%
    \ctikzset{tripoles/thyristor/diode width left=.4}%
    \ctikzset{tripoles/thyristor/diode width right=.4}%legacy 0.3
    \ctikzset{tripoles/thyristor/gate height=0.5}% legacy 0
    \ctikzset{tripoles/thyristor/gate kink=0.7}% legacy 1.0
    \ctikzset{tripoles/thyristor/gto space up=0.25}% legacy 0.5
    \ctikzset{tripoles/thyristor/gto space down=0.25}% legacy 0.0
    \ctikzset{tripoles/thyristor/gto bar width=0.2}%
    \ctikzset{tripoles/triac/gate kink=.7}%
}}

%
% Flipping arrows in LED and photodiodes
%
\newif\ifpgf@led@fliparrows
\newif\ifpgf@pd@fliparrows
\pgf@led@fliparrowsfalse
\pgf@pd@fliparrowsfalse
%
% by default the arrows start (LED) and go (PD) to the anode.
%
\ctikzset{led arrows from anode/.code=\pgf@led@fliparrowsfalse}
\ctikzset{pd arrows to anode/.code=\pgf@pd@fliparrowsfalse}
%
% but they can start form the cathode (LED) or go to it (PD)
%
\ctikzset{led arrows from cathode/.code=\pgf@led@fliparrowstrue}
\ctikzset{pd arrows to cathode/.code=\pgf@pd@fliparrowstrue}

\newif\ifpgf@circuit@strokediode
\newif\ifpgf@circuit@fulldiode
\pgf@circuit@strokediodefalse
\pgf@circuit@fulldiodefalse

\ctikzset{diode/.is choice}
\ctikzset{diode/empty/.code =  \pgf@circuit@fulldiodefalse\pgf@circuit@strokediodefalse}%default
\ctikzset{diode/full/.code =   \pgf@circuit@fulldiodetrue\pgf@circuit@strokediodefalse}
\ctikzset{diode/stroke/.code = \pgf@circuit@fulldiodefalse\pgf@circuit@strokediodetrue}

\tikzset{full diodes/.style = { \circuitikzbasekey/diode = full}}
\tikzset{empty diodes/.style = { \circuitikzbasekey/diode = empty}}
\tikzset{stroke diodes/.style = { \circuitikzbasekey/diode = stroke}}

%%>>>

%% Node components for diodes %<<<1

% beware, this shift to the left the coordinates
\def\pgf@circ@fulldiode@triangle@shift{%
        \pgftransformxshift{\pgf@circ@res@left}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
        \pgf@circ@fill@strokecolor
        \pgfusepath{draw,fill}
        % \pgf@circ@debug@colors
}

%% Black generic diode
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/diode/height}}
{fulldiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgf@circ@fulldiode@triangle@shift
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
}

%% Black Zener diode
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/diode/height}}
{fullzdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@fulldiode@triangle@shift
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-.6\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfusepath{draw}
}

%% Black alternative zigzag Zener diode
\pgfcircdeclarebipolescaled{diodes}
{% fix the anchor border
    \pgfcirc@border@extend@updown{1.3}{1.3}
}
{\ctikzvalof{bipoles/diode/height}}
{fullzzdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@fulldiode@triangle@shift
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-1.8\pgf@circ@res@left}{\pgf@circ@res@down-0.5\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-0.2\pgf@circ@res@left}{\pgf@circ@res@up-0.5\pgf@circ@res@down}}
    \pgfusepath{draw}
}

%% Black Schottky diode
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/diode/height}}
{fullsdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@fulldiode@triangle@shift
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.6\pgf@circ@res@left}{.6\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-.6\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-1.4\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-1.4\pgf@circ@res@left}{.6\pgf@circ@res@up}}
    \pgfusepath{draw}
}

%% Black tunnel diode
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/diode/height}}
{fulltdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@fulldiode@triangle@shift
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.6\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-.6\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfusepath{draw}
}
% the styling of optical arrows is defined in pgfcirc.define.tex because
% they are common to phototransistors

%
% draw LED arrows
%
\def\pgf@circ@draw@ledarrows{%
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgf@circ@fill@strokecolor
    \pgf@circ@set@optoarrow@style
    \ifpgf@led@fliparrows
        \pgfpathmoveto{\pgfpoint{0pt}{0.8\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-0.6\pgf@circ@res@right}{1.8\pgf@circ@res@up}}
        \pgfusepath{draw}
        \pgfpathmoveto{\pgfpoint{0.6\pgf@circ@res@right}{0.6\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{1.6\pgf@circ@res@up}}
        \pgfusepath{draw}
    \else
        \pgfpathmoveto{\pgfpoint{-0.4\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0.6\pgf@circ@res@right}{2\pgf@circ@res@up}}
        \pgfusepath{draw}
        \pgfpathmoveto{\pgfpoint{0.2\pgf@circ@res@right}{0.8\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{1.2\pgf@circ@res@right}{1.8\pgf@circ@res@up}}
        \pgfusepath{draw}
    \fi
}
%
% ---and photodiode arrows
%
\def\pgf@circ@draw@pdarrows{%
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgf@circ@fill@strokecolor
    \pgf@circ@set@optoarrow@style
    \ifpgf@pd@fliparrows
        \pgfpathmoveto{\pgfpoint{-0.6\pgf@circ@res@right}{1.8\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{0.8\pgf@circ@res@up}}
        \pgfusepath{draw}
        \pgfpathmoveto{\pgfpoint{0pt}{1.6\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0.6\pgf@circ@res@right}{0.6\pgf@circ@res@up}}
        \pgfusepath{draw}
    \else
        \pgfpathmoveto{\pgfpoint{0.6\pgf@circ@res@right}{2\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-0.4\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfusepath{draw}
        \pgfpathmoveto{\pgfpoint{1.2\pgf@circ@res@right}{1.8\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0.2\pgf@circ@res@right}{0.8\pgf@circ@res@up}}
        \pgfusepath{draw}
    \fi
}
%
% --and laser diode arrows - contributed by Andre Alves
%
\def\pgf@circ@draw@laserarrows{%
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgf@circ@fill@strokecolor
    \pgf@circ@set@optoarrow@style
    \pgfpathmoveto{\pgfpoint{-0.4\pgf@circ@res@right}{1.1\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{-0.4\pgf@circ@res@right}{2.1\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfpathmoveto{\pgfpoint{0.2\pgf@circ@res@right}{1.1\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.2\pgf@circ@res@right}{2.1\pgf@circ@res@up}}
    \pgfusepath{draw}
}

\def\pgf@circ@generate@diode@saved@arrows#1#2#3#4#5{%
    \savedanchor{\arrows}{%
        \pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen
        \pgf@ya=\ctikzvalof{bipoles/diode/height}\pgf@circ@scaled@Rlen
        \pgf@xa=\ctikzvalof{bipoles/diode/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@xa\pgf@y=.5\pgf@ya
        \csname ifpgf@#5@fliparrows\endcsname
            \pgf@x=#1\pgf@x\pgf@y=#2\pgf@y
        \else
            \pgf@x=#3\pgf@x\pgf@y=#4\pgf@y
        \fi
    }
}
%% Black light emitting diode
\pgfcircdeclarebipolescaled{diodes}
{% fix the anchor border
    \pgfcirc@border@extend@updown{1.8}{1}
    \pgf@circ@generate@diode@saved@arrows{-0.2}{2.0}{1.0}{2.0}{led}
    \anchor{arrows}{\arrows}
}
{\ctikzvalof{bipoles/diode/height}}
{fulllediode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgf@circ@fulldiode@triangle@shift
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgf@circ@draw@ledarrows
}

%% Black laser diode - contributed by Andre Alves
\pgfcircdeclarebipolescaled{diodes}
{% fix the anchor border
    \pgfcirc@border@extend@updown{1.8}{1}
    \pgf@circ@generate@diode@saved@arrows{-0.1}{2.2}{-0.1}{2.2}{pd}%pd or led dosen't matter
    \anchor{arrows}{\arrows}
}
{\ctikzvalof{bipoles/diode/height}}
{fulllaserdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgf@circ@fulldiode@triangle@shift
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfusepath{draw}
    \pgf@circ@draw@laserarrows
}

%% Black photodiode
\pgfcircdeclarebipolescaled{diodes}
{% fix the anchor border
    \pgfcirc@border@extend@updown{1.8}{1}
    \pgf@circ@generate@diode@saved@arrows{-0.2}{2.0}{1.0}{2.0}{pd}
    \anchor{arrows}{\arrows}
}
{\ctikzvalof{bipoles/diode/height}}
{fullpdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgf@circ@fulldiode@triangle@shift
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgf@circ@draw@pdarrows
}

%% Black varcap
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/varcap/height}}
{fullvarcap}
{\ctikzvalof{bipoles/varcap/height}}
{\ctikzvalof{bipoles/varcap/width}}
{
    \pgf@circ@res@temp=\ctikzvalof{bipoles/thickness}\pgfstartlinewidth
    \pgfsetlinewidth{\pgf@circ@res@temp}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{0pt}}
    \pgf@circ@fill@strokecolor
    \pgfusepath{draw,fill}
    %
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
}

%% Code for the diode triangle
\def\pgf@circ@basicdiodeshape{
    % \pgfscope
        \pgftransformxshift{\pgf@circ@res@left}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
        \pgfpathclose
        \pgf@circ@draworfill
        \pgfscope
            % to allow filling, we need to draw explicitly the stroke here.
            \pgfsetlinewidth{\pgfstartlinewidth}
            \ifpgf@circuit@bipole@strokedsymbol
                \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
                \pgfpathlineto{\pgfpoint{0pt}{0pt}}
                \pgfusepath{draw}
            \fi
        \endpgfscope
    % \endpgfscope
}

%% Empty generic diode
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/diode/height}}
{emptydiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgf@circ@basicdiodeshape
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
}

%% Empty Zener diode
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/diode/height}}
{emptyzdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfscope
        \pgf@circ@basicdiodeshape
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-0.6\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}

%% Empty alternative zigzag Zener diode
\pgfcircdeclarebipolescaled{diodes}
{% fix the anchor border
    \pgfcirc@border@extend@updown{1.3}{1.3}
}
{\ctikzvalof{bipoles/diode/height}}
{emptyzzdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfscope
        \pgf@circ@basicdiodeshape
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-1.8\pgf@circ@res@left}{\pgf@circ@res@down-0.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-0.2\pgf@circ@res@left}{\pgf@circ@res@up-0.5\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
}
%% Empty Schottky diode
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/diode/height}}
{emptysdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgf@circ@basicdiodeshape
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.6\pgf@circ@res@left}{.6\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-.6\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-1.4\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-1.4\pgf@circ@res@left}{.6\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope

}

%% Empty tunnel diode
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/diode/height}}
{emptytdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgf@circ@basicdiodeshape
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.6\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-.6\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}

%% Empty light emitting diode
\pgfcircdeclarebipolescaled{diodes}
{% fix the anchor border
    \pgfcirc@border@extend@updown{1.8}{1}
    \pgf@circ@generate@diode@saved@arrows{-0.2}{2.0}{1.0}{2.0}{led}
    \anchor{arrows}{\arrows}
}
{\ctikzvalof{bipoles/diode/height}}
{emptylediode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgf@circ@basicdiodeshape
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}

    \pgf@circ@draw@ledarrows
}

%% Empty laser diode - contributed by Andre Alves
\pgfcircdeclarebipolescaled{diodes}
{% fix the anchor border
    \pgfcirc@border@extend@updown{1.8}{1}
    \pgf@circ@generate@diode@saved@arrows{-0.1}{2.2}{-0.1}{2.2}{pd}%pd or led dosen't matter
    \anchor{arrows}{\arrows}
}
{\ctikzvalof{bipoles/diode/height}}
{emptylaserdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgf@circ@basicdiodeshape
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfusepath{draw}

    \pgf@circ@draw@laserarrows
}

%% Empty photodiode
\pgfcircdeclarebipolescaled{diodes}
{% fix the anchor border
    \pgfcirc@border@extend@updown{1.8}{1}
    \pgf@circ@generate@diode@saved@arrows{-0.2}{2.0}{1.0}{2.0}{pd}
    \anchor{arrows}{\arrows}
}
{\ctikzvalof{bipoles/diode/height}}
{emptypdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgf@circ@basicdiodeshape
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}

    \pgf@circ@draw@pdarrows
}

%% Empty varcap
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/varcap/height}}
{emptyvarcap}
{\ctikzvalof{bipoles/varcap/height}}
{\ctikzvalof{bipoles/varcap/width}}
{
    \pgf@circ@res@temp=\ctikzvalof{bipoles/thickness}\pgfstartlinewidth
    \pgfsetlinewidth{\pgf@circ@res@temp}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    % \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{0pt}}
    \pgfpathclose
    \pgf@circ@draworfill
    \pgfscope
        % to allow filling, we need to draw explicitily the stroke here.
        \pgfsetlinewidth{\pgfstartlinewidth}
        \ifpgf@circuit@bipole@strokedsymbol
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{0pt}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0pt}}
            \pgfusepath{draw}
        \fi
    \endpgfscope
    %
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-2\pgf@circ@res@temp}{\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
}

%% Transorbs
%% Empty zigzag TVS diode (transorb)
\pgfcircdeclarebipolescaled{diodes}
{% fix the anchor border
    \pgfcirc@border@extend@updown{1.3}{1.3}
}
{\ctikzvalof{bipoles/diode/height}}
{emptytvsdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/ddiode/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgfscope
            \pgftransformxscale{0.5}
            \pgftransformxshift{\pgf@circ@res@left}
            \pgf@circ@basicdiodeshape
        \endpgfscope
        \pgfscope
            \pgftransformxscale{-0.5}
            \pgftransformxshift{\pgf@circ@res@left}
            \pgf@circ@basicdiodeshape
        \endpgfscope
        \pgfpathmoveto{\pgfpoint{0.4\pgf@circ@res@left}{1.3\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{0.4\pgf@circ@res@right}{1.3\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope
}
%% Black zigzag TVS diode (transorb)
\pgfcircdeclarebipolescaled{diodes}
{% fix the anchor border
    \pgfcirc@border@extend@updown{1.3}{1.3}
}
{\ctikzvalof{bipoles/diode/height}}
{fulltvsdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/ddiode/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgftransformxscale{0.5}
        \pgftransformxshift{\pgf@circ@res@left}
        \pgf@circ@fulldiode@triangle@shift
    \endpgfscope
    \pgfscope
        \pgftransformxscale{-0.5}
        \pgftransformxshift{\pgf@circ@res@left}
        \pgf@circ@fulldiode@triangle@shift
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{0.4\pgf@circ@res@left}{1.3\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.4\pgf@circ@res@right}{1.3\pgf@circ@res@down}}
    \pgfusepath{draw}
}

%% Black Shockley diode
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/diode/height}}
{fullshdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathclose
        \pgf@circ@fill@strokecolor
        \pgfusepath{draw,fill}
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
}
%% Empty generic diode
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/diode/height}}
{emptyshdiode}
{\ctikzvalof{bipoles/diode/height}}
{\ctikzvalof{bipoles/diode/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfscope
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathclose
        \pgf@circ@draworfill
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
}

%% Empty bidirectionaldiode
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/bidirectionaldiode/height}}
{emptybidirectionaldiode}
{\ctikzvalof{bipoles/bidirectionaldiode/height}}
{\ctikzvalof{bipoles/bidirectionaldiode/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgf@circ@res@other = \ctikzvalof{bipoles/bidirectionaldiode/diode width left}\pgf@circ@res@left
    \pgf@circ@res@step = \ctikzvalof{bipoles/bidirectionaldiode/diode width right}\pgf@circ@res@right

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}
    \pgfpathlineto{\pgfpoint{0.95\pgf@circ@res@step}{0.707*(\pgf@circ@res@other-\pgf@circ@res@step)}} % sqrt(1/2)
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{-1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
    \pgfpathlineto{\pgfpoint{0.95\pgf@circ@res@other}{-0.707*(\pgf@circ@res@other-\pgf@circ@res@step)}} % sqrt(1/2)
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{-1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}}

    \pgf@circ@draworfill

    \pgfsetlinewidth{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0pt}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}

    \pgfusepath{draw}
}

%% Full bidirectionaldiode
\pgfcircdeclarebipolescaled{diodes}
{}
{\ctikzvalof{bipoles/bidirectionaldiode/height}}
{fullbidirectionaldiode}
{\ctikzvalof{bipoles/bidirectionaldiode/height}}
{\ctikzvalof{bipoles/bidirectionaldiode/width}}
{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgf@circ@res@other = \ctikzvalof{bipoles/bidirectionaldiode/diode width left}\pgf@circ@res@left
    \pgf@circ@res@step = \ctikzvalof{bipoles/bidirectionaldiode/diode width right}\pgf@circ@res@right

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}
    \pgfpathlineto{\pgfpoint{0.95\pgf@circ@res@step}{0.707*(\pgf@circ@res@other-\pgf@circ@res@step)}} % sqrt(1/2)
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{-1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
    \pgfpathlineto{\pgfpoint{0.95\pgf@circ@res@other}{-0.707*(\pgf@circ@res@other-\pgf@circ@res@step)}} % sqrt(1/2)
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{-1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}}

    \pgf@circ@fill@strokecolor
    \pgfusepath{draw, fill}

    \pgfsetlinewidth{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0pt}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}

    \pgfusepath{draw}
}

%%% Thyristors in general


\def\pgfcircdeclarethyristor#1#2#3#4{%name, fill (0-> black; 1-empty), gate position (1: catode, -1: anode), extra code
    \pgfcircdeclarebipolescaled{diodes}
    {
        \savedmacro{\gatekink}{\edef\gatekink{\ctikzvalof{tripoles/thyristor/gate kink}}}
        \anchor{gate}{\northeast\pgf@x=\gatekink\pgf@x\pgf@x=#3\pgf@x}
        \anchor{G}{\northeast\pgf@x=\gatekink\pgf@x\pgf@x=#3\pgf@x}
        \anchor{anode}{\southwest\pgf@y=0cm}
        \anchor{cathode}{\northeast\pgf@y=0cm }
    }
    {\ctikzvalof{tripoles/thyristor/height 2}}
    {#1}
    {\ctikzvalof{tripoles/thyristor/height}}
    {\ctikzvalof{tripoles/thyristor/width}}
    {
        \pgf@circ@res@other = \ctikzvalof{tripoles/thyristor/diode width left}\pgf@circ@res@left
        \pgf@circ@res@step = \ctikzvalof{tripoles/thyristor/diode width right}\pgf@circ@res@right

        \pgfscope
            % draw the thick parts here (shifted horizontally)
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            % draw the basic triangle
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}

            \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{-\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{0pt}}
            \pgfpathclose
            \ifnum#2=0\relax
                \pgf@circ@fill@strokecolor
                \pgfusepath{draw,fill}
            \else
                \pgf@circ@draworfill
            \fi
            % draw the vertical bar
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{-\pgf@circ@res@down}}
            \pgfusepath{draw}
        \endpgfscope

        % back to normal linewidth
        % stroke if needed
        \ifpgf@circuit@bipole@strokedsymbol
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}
            \pgfusepath{draw}
        \fi

        % draw the gate thing;
        #4%

        % draw the leads in/out
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0pt}}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}

        \pgfusepath{draw}
    }
}

\def\pgfcirc@thyristor@simplegate{%
    \pgfpathmoveto{\pgfpoint
        {\pgf@circ@res@step}
        {\ctikzvalof{tripoles/thyristor/gate height}*\ctikzvalof{tripoles/thyristor/diode height}*\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/thyristor/gate kink}*\pgf@circ@res@right}
        {\ctikzvalof{tripoles/thyristor/diode height}\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/thyristor/gate kink}*\pgf@circ@res@right}
        {\pgf@circ@res@up}
    }
    \pgfusepath{draw}
}

%% Black thyristor
\pgfcircdeclarethyristor{fullthyristor}{0}{1}{\pgfcirc@thyristor@simplegate}
%% Empty thyristor
\pgfcircdeclarethyristor{emptythyristor}{1}{1}{\pgfcirc@thyristor@simplegate}
%% black and empty GTO (standard: double line symbol, no arrow)

\def\pgfcirc@doublegate@gto@add{
    % connection to gate terminal
    \pgfpathmoveto{\pgfpoint
        {\ctikzvalof{tripoles/thyristor/gate kink}*\pgf@circ@res@right}
        {\ctikzvalof{tripoles/thyristor/diode height}*\pgf@circ@res@up -
        \ctikzvalof{tripoles/thyristor/gto space down}*\ctikzvalof{tripoles/thyristor/diode height}*\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/thyristor/gate kink}*\pgf@circ@res@right}
        {\pgf@circ@res@up}
    }
    \pgfusepath{draw}
    \pgfscope
    \pgfcirc@set@arrows{gto gate}{}{}
    % \pgfsetarrowsstart{latexslim}
    % first (lower) gto line: from body to gate
    \pgfpathmoveto{\pgfpoint
        {\pgf@circ@res@step}
        {(\ctikzvalof{tripoles/thyristor/gate height}-\ctikzvalof{tripoles/thyristor/gto space down})
            *\ctikzvalof{tripoles/thyristor/diode height}*\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/thyristor/gate kink}*\pgf@circ@res@right}
        {\ctikzvalof{tripoles/thyristor/diode height}*\pgf@circ@res@up -
        \ctikzvalof{tripoles/thyristor/gto space down}*\ctikzvalof{tripoles/thyristor/diode height}*\pgf@circ@res@up}
    }
    \pgfusepath{draw}
    % second (higher) gto line: from gate to body
    \pgfpathmoveto{\pgfpoint
        {\ctikzvalof{tripoles/thyristor/gate kink}*\pgf@circ@res@right}
        {\ctikzvalof{tripoles/thyristor/diode height}*\pgf@circ@res@up +
        \ctikzvalof{tripoles/thyristor/gto space up}*\ctikzvalof{tripoles/thyristor/diode height}*\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {\pgf@circ@res@step}
        {(\ctikzvalof{tripoles/thyristor/gate height}+\ctikzvalof{tripoles/thyristor/gto space up})
            *\ctikzvalof{tripoles/thyristor/diode height}*\pgf@circ@res@up}
    }
    \pgfusepath{draw}
    \endpgfscope
}
\pgfcircdeclarethyristor{fullgto}{0}{1}{\pgfcirc@doublegate@gto@add}
\pgfcircdeclarethyristor{emptygto}{1}{1}{\pgfcirc@doublegate@gto@add}

\def\pgfcirc@bargate@gto@add{%
    \pgfpathmoveto{\pgfpoint
        {\pgf@circ@res@step}
        {\ctikzvalof{tripoles/thyristor/gate height}*\ctikzvalof{tripoles/thyristor/diode height}*\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/thyristor/gate kink}*\pgf@circ@res@right}
        {\ctikzvalof{tripoles/thyristor/diode height}\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/thyristor/gate kink}*\pgf@circ@res@right}
        {\pgf@circ@res@up}
    }
    % draw bar line.
    \pgfpathmoveto{\pgfpoint
        {(\ctikzvalof{tripoles/thyristor/gate kink}-\ctikzvalof{tripoles/thyristor/gto bar width})*\pgf@circ@res@right}
        {(1+\ctikzvalof{tripoles/thyristor/diode height})*0.5*\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {(\ctikzvalof{tripoles/thyristor/gate kink}+\ctikzvalof{tripoles/thyristor/gto bar width})*\pgf@circ@res@right}
        {(1+\ctikzvalof{tripoles/thyristor/diode height})*0.5*\pgf@circ@res@up}
    }
    \pgfusepath{draw}
}

\pgfcircdeclarethyristor{fullgtobar}{0}{1}{\pgfcirc@bargate@gto@add}
\pgfcircdeclarethyristor{emptygtobar}{1}{1}{\pgfcirc@bargate@gto@add}

%% Thyristors with anode-connected gate

\def\pgfcirc@thyristor@anodegate{%
    \pgfpathmoveto{\pgfpoint
        {\pgf@circ@res@other}
        {\ctikzvalof{tripoles/thyristor/gate height}*\ctikzvalof{tripoles/thyristor/diode height}*\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/thyristor/gate kink}*\pgf@circ@res@left}
        {\ctikzvalof{tripoles/thyristor/diode height}\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/thyristor/gate kink}*\pgf@circ@res@left}
        {\pgf@circ@res@up}
    }
    \pgfusepath{draw}
}

%% Black PUT
\pgfcircdeclarethyristor{fullput}{0}{-1}{\pgfcirc@thyristor@anodegate}
%% Empty PUT
\pgfcircdeclarethyristor{emptyput}{1}{-1}{\pgfcirc@thyristor@anodegate}
%% black and empty GTO (standard: double line symbol, no arrow)

\def\pgfcirc@anodebargate@gto@add{%
    \pgfpathmoveto{\pgfpoint
        {\pgf@circ@res@other}
        {\ctikzvalof{tripoles/thyristor/gate height}*\ctikzvalof{tripoles/thyristor/diode height}*\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/thyristor/gate kink}*\pgf@circ@res@left}
        {\ctikzvalof{tripoles/thyristor/diode height}\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/thyristor/gate kink}*\pgf@circ@res@left}
        {\pgf@circ@res@up}
    }
    % draw bar line.
    \pgfpathmoveto{\pgfpoint
        {(\ctikzvalof{tripoles/thyristor/gate kink}-\ctikzvalof{tripoles/thyristor/gto bar width})*\pgf@circ@res@left}
        {(1+\ctikzvalof{tripoles/thyristor/diode height})*0.5*\pgf@circ@res@up}
    }
    \pgfpathlineto{\pgfpoint
        {(\ctikzvalof{tripoles/thyristor/gate kink}+\ctikzvalof{tripoles/thyristor/gto bar width})*\pgf@circ@res@left}
        {(1+\ctikzvalof{tripoles/thyristor/diode height})*0.5*\pgf@circ@res@up}
    }
    \pgfusepath{draw}
}

\pgfcircdeclarethyristor{fullagtobar}{0}{-1}{\pgfcirc@anodebargate@gto@add}
\pgfcircdeclarethyristor{emptyagtobar}{1}{-1}{\pgfcirc@anodebargate@gto@add}

% Triacs

\def\pgfcircdeclaretriac#1#2{%name, fill (0-> black; 1-empty)
    \pgfcircdeclarebipolescaled{diodes}
    {
        \savedmacro{\gatekink}{\edef\gatekink{\ctikzvalof{tripoles/triac/gate kink}}}
        \anchor{gate}{\northeast\pgf@x=\gatekink\pgf@x}
        \anchor{G}{\northeast\pgf@x=\gatekink\pgf@x}
        \anchor{anode}{\southwest\pgf@y=0cm}
        \anchor{cathode}{\northeast\pgf@y=0cm }
    }
    {\ctikzvalof{tripoles/triac/height}}
    {#1}
    {\ctikzvalof{tripoles/triac/height}}
    {\ctikzvalof{tripoles/triac/width}}
    {
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

        \pgf@circ@res@other = \ctikzvalof{tripoles/triac/diode width left}\pgf@circ@res@left
        \pgf@circ@res@step = \ctikzvalof{tripoles/triac/diode width right}\pgf@circ@res@right

        % diodes forms
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfpathlineto{\pgfpoint{0.95\pgf@circ@res@step}{0.707*(\pgf@circ@res@other-\pgf@circ@res@step)}} % sqrt(1/2)
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{-1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
        \pgfpathlineto{\pgfpoint{0.95\pgf@circ@res@other}{-0.707*(\pgf@circ@res@other-\pgf@circ@res@step)}} % sqrt(1/2)
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{-1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}}

        \ifnum#2=0\relax
            \pgf@circ@fill@strokecolor
            \pgfusepath{draw,fill}
        \else
            \pgf@circ@draworfill
        \fi

        \pgfsetlinewidth{\pgfstartlinewidth}

        % draw gate
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{-0.707*(\pgf@circ@res@other-\pgf@circ@res@step)}} % sqrt(1/2)
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/triac/gate kink}*\pgf@circ@res@right}
            {-1.414*(\pgf@circ@res@other-\pgf@circ@res@step)}} % sqrt(1/2)
        \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/triac/gate kink}*\pgf@circ@res@right}{\pgf@circ@res@up}} % sqrt(1/2)

        % draw leads
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0pt}}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}

        \pgfusepath{draw}

    }
}

\pgfcircdeclaretriac{fulltriac}{0}
\pgfcircdeclaretriac{emptytriac}{1}

% end of shape definitions for diodes%>>>

%% Paths definitions for Diodes%<<<

\def\pgfcirc@tmp@generatediodes#1#2{
    \pgfcirc@activate@bipole{l}{#1diode}{#1diode}{#1 diode}
    \pgfcirc@style@to@style{#1 diode}{D#2}
    \pgfcirc@activate@bipole{l}{#1zdiode}{#1zdiode}{#1 Zener diode}
    \pgfcirc@style@to@style{#1 Zener diode}{zD#2}
    \pgfcirc@activate@bipole{l}{#1zzdiode}{#1zzdiode}{#1 ZZener diode}
    \pgfcirc@style@to@style{#1 ZZener diode}{zzD#2}
    \pgfcirc@activate@bipole{l}{#1sdiode}{#1sdiode}{#1 Schottky diode}
    \pgfcirc@style@to@style{#1 Schottky diode}{sD#2}
    \pgfcirc@activate@bipole{l}{#1tdiode}{#1tdiode}{#1 tunnel diode}
    \pgfcirc@style@to@style{#1 tunnel diode}{tD#2}
    \pgfcirc@activate@bipole{l}{#1lediode}{#1lediode}{#1 led}
    \pgfcirc@style@to@style{#1 led}{leD#2}
    \pgfcirc@activate@bipole{l}{#1laserdiode}{#1laserdiode}{#1 laser diode}
    \pgfcirc@style@to@style{#1 laser diode}{lasD#2}
    \pgfcirc@activate@bipole{l}{#1pdiode}{#1pdiode}{#1 photodiode}
    \pgfcirc@style@to@style{#1 photodiode}{pD#2}
    \pgfcirc@activate@bipole{l}{#1varcap}{#1varcap}{#1 varcap}
    \pgfcirc@style@to@style{#1 varcap}{VC#2}
    \pgfcirc@activate@bipole{l}{#1tvsdiode}{#1tvsdiode}{#1 TVS diode}
    \pgfcirc@style@to@style{#1 TVS diode}{tvsD#2}
    \pgfcirc@activate@bipole{l}{#1shdiode}{#1shdiode}{#1 Shockley diode}
    \pgfcirc@style@to@style{#1 Shockley diode}{shD#2}
    \pgfcirc@activate@bipole{l}{#1bidirectionaldiode}{#1bidirectionaldiode}{#1 bidirectionaldiode}
    \pgfcirc@style@to@style{#1 bidirectionaldiode}{biD#2}
    \pgfcirc@activate@bipole{l}{#1thyristor}{#1thyristor}{#1 thyristor}
    \pgfcirc@style@to@style{#1 thyristor}{Ty#2}
    \pgfcirc@activate@bipole{l}{#1put}{#1put}{#1 put}
    \pgfcirc@style@to@style{#1 put}{PUT#2}
    \pgfcirc@activate@bipole{l}{#1gto}{#1gto}{#1 gto}
    \pgfcirc@style@to@style{#1 gto}{GTO#2}
    \pgfcirc@activate@bipole{l}{#1gtobar}{#1gtobar}{#1 gtobar}
    \pgfcirc@style@to@style{#1 gtobar}{GTOb#2}
    \pgfcirc@activate@bipole{l}{#1agtobar}{#1agtobar}{#1 agtobar}
    \pgfcirc@style@to@style{#1 agtobar}{aGTOb#2}
    \pgfcirc@activate@bipole{l}{#1triac}{#1triac}{#1 triac}
    \pgfcirc@style@to@style{#1 triac}{Tr#2}
}
\pgfcirc@tmp@generatediodes{full}{*}
\pgfcirc@tmp@generatediodes{empty}{o}
\def\pgfcirc@tmp@generatestrokeddiodes#1#2{
    \pgfcirc@node@to@style{l}{emptydiode}{#1 diode}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 diode}{D#2}
    \pgfcirc@node@to@style{l}{emptyzdiode}{#1 Zener diode}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 Zener diode}{zD#2}
    \pgfcirc@node@to@style{l}{emptyzzdiode}{#1 ZZener diode}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 ZZener diode}{zzD#2}
    \pgfcirc@node@to@style{l}{emptysdiode}{#1 Schottky diode}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 Schottky diode}{sD#2}
    \pgfcirc@node@to@style{l}{emptytdiode}{#1 tunnel diode}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 tunnel diode}{tD#2}
    \pgfcirc@node@to@style{l}{emptylediode}{#1 led}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 led}{leD#2}
    \pgfcirc@node@to@style{l}{emptylaserdiode}{#1 laser diode}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 laser diode}{lasD#2}
    \pgfcirc@node@to@style{l}{emptypdiode}{#1 photodiode}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 photodiode}{pD#2}
    \pgfcirc@node@to@style{l}{emptyvarcap}{#1 varcap}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 varcap}{VC#2}
    \pgfcirc@node@to@style{l}{emptytvsdiode}{#1 TVS diode}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 TVS diode}{tvsD#2}
    \pgfcirc@node@to@style{l}{emptyshdiode}{#1 Shockley diode}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 Shockley diode}{shD#2}
    \pgfcirc@node@to@style{l}{emptybidirectionaldiode}{#1 bidirectionaldiode}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 bidirectionaldiode}{biD#2}
    \pgfcirc@node@to@style{l}{emptythyristor}{#1 thyristor}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 thyristor}{Ty#2}
    \pgfcirc@node@to@style{l}{emptyput}{#1 put}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 put}{PUT#2}
    \pgfcirc@node@to@style{l}{emptygto}{#1 gto}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 gto}{GTO#2}
    \pgfcirc@node@to@style{l}{emptygtobar}{#1 gtobar}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 gtobar}{GTOb#2}
    \pgfcirc@node@to@style{l}{emptyagtobar}{#1 agtobar}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 agtobar}{aGTOb#2}
    \pgfcirc@node@to@style{l}{emptytriac}{#1 triac}{\circuitikzbasekey/bipole/is strokedsymbol=true}
    \pgfcirc@style@to@style{#1 triac}{Tr#2}
}
\pgfcirc@tmp@generatestrokeddiodes{stroke}{-}
\def\pgfcircdiodestylemacro{\ifpgf@circuit@strokediode stroke \else\ifpgf@circuit@fulldiode full \else empty \fi\fi}
% these are auto-switching styles
\pgfcirc@style@to@style{\pgfcircdiodestylemacro diode}{diode}
\pgfcirc@style@to@style{diode}{D}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro Zener diode}{Zener diode}
\pgfcirc@style@to@style{Zener diode}{zD}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro ZZener diode}{ZZener diode}
\pgfcirc@style@to@style{ZZener diode}{zzD}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro Schottky diode}{Schottky diode}
\pgfcirc@style@to@style{Schottky diode}{sD}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro tunnel diode}{tunnel diode}
\pgfcirc@style@to@style{tunnel diode}{tD}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro led}{led}
\pgfcirc@style@to@style{led}{leD}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro photodiode}{photodiode}
\pgfcirc@style@to@style{photodiode}{pD}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro laser diode}{laser diode}
\pgfcirc@style@to@style{laser diode}{lasD}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro varcap}{varcap}
\pgfcirc@style@to@style{varcap}{VC}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro TVS diode}{TVS diode}
\pgfcirc@style@to@style{TVS diode}{tvsD}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro Shockley diode}{Shockley diode}
\pgfcirc@style@to@style{Shockley diode}{shD}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro bidirectionaldiode}{bidirectionaldiode}
\pgfcirc@style@to@style{bidirectionaldiode}{biD}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro thyristor}{thyristor}
\pgfcirc@style@to@style{thyristor}{Ty}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro put}{put}
\pgfcirc@style@to@style{put}{PUT}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro gto}{gto}
\pgfcirc@style@to@style{gto}{GTO}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro gtobar}{gtobar}
\pgfcirc@style@to@style{gtobar}{GTOb}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro agtobar}{agtobar}
\pgfcirc@style@to@style{agtobar}{aGTOb}
\pgfcirc@style@to@style{\pgfcircdiodestylemacro triac}{triac}
\pgfcirc@style@to@style{triac}{Tr}
% %>>>

%%%%%%%%%%%%%
%% switches, buttons and jumpers
%%%%%%%%%%%%%

%% Definitions for switches%<<<1

\ctikzset{bipoles/spst/height/.initial=.35}
\ctikzset{bipoles/spst/width/.initial=.35}
\ctikzset{bipoles/spst/depth/.initial=.2}
\ctikzset{bipoles/nos/height/.initial=.3}
\ctikzset{bipoles/nos/width/.initial=.35}
\ctikzset{bipoles/nos/depth/.initial=.2}
\ctikzset{bipoles/ncs/height/.initial=.35}
\ctikzset{bipoles/ncs/width/.initial=.35}
\ctikzset{bipoles/ncs/depth/.initial=.2}
\ctikzset{bipoles/pushbutton/height/.initial=.5}
\ctikzset{bipoles/pushbutton/height 2/.initial=.2}
\ctikzset{bipoles/pushbutton/width/.initial=.50}
%%% reed switch
\ctikzset{bipoles/reed/height/.initial=.4}
\ctikzset{bipoles/reed/width/.initial=.8}% 0.35 in nos
\ctikzset{bipoles/reed/depth/.initial=.4}
%% Cute switches
\ctikzset{bipoles/cuteswitch/shape/.initial={ocirc}}
\ctikzset{bipoles/cuteswitch/height/.initial=.6}
\ctikzset{bipoles/cuteswitch/height 2/.initial=.2}
\ctikzset{bipoles/cuteswitch/width/.initial=.50}
\ctikzset{bipoles/cuteswitch/thickness/.initial=1}

\ctikzset{tripoles/spdt/width/.initial=.85}
\ctikzset{tripoles/spdt/height/.initial=.45}
\ctikzset{tripoles/spdt/margin/.initial=.45}

\ctikzset{tripoles/toggleswitch/height/.initial=.8}
\ctikzset{tripoles/toggleswitch/height 2/.initial=.0}
\ctikzset{tripoles/toggleswitch/width/.initial=.80}
%% arrow configurability
\ctikzset{switch arrows/.is family}
\ctikzset{switch arrows/relative thickness/.initial=1}
\ctikzset{switch arrows/color/.initial=default}
\ctikzset{switch arrows/dash/.initial=default}
\def\pgf@circ@set@switcharrow@style{%
    % You *must* be sure that this is called inside a \pgfscope!
    \pgfsetlinewidth{\ctikzvalof{switch arrows/relative thickness}\pgflinewidth}
    \pgf@circ@subset@color@dash{switch arrows}
    \pgfcirc@set@arrows{switch}{}{latexslim}
    }
\def\pgf@circ@savedanchor@trad@midlever#1#2{% #1 -> name #2 -> relative height
    \savedanchor\midlever{% this is the full height of the "handle" of switch
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{bipoles/#1/height}\pgf@circ@scaled@Rlen
        \pgf@x=0pt\pgf@y=0.5\pgf@y
    }
    \anchor{mid}{\midlever\pgf@y=#2\pgf@y}
}
%%>>>

%% Shapes Node for bipoles switches and similar things%<<<
%% (Closing) SPST
\pgfcircdeclarebipolescaled{switches}
{
    \pgf@circ@savedanchor@trad@midlever{spst}{0.6}
}
{\ctikzvalof{bipoles/spst/depth}}
{cspst}
{\ctikzvalof{bipoles/spst/height}}
{\ctikzvalof{bipoles/spst/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfscope
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{90}{1.2\pgf@circ@res@right}}
        \pgfpatharc{90}{-20}{1.2\pgf@circ@res@right}
        \pgf@circ@set@switcharrow@style
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

%% Opening SPST
\pgfcircdeclarebipolescaled{switches}
{
    \pgf@circ@savedanchor@trad@midlever{spst}{0.6}
}
{\ctikzvalof{bipoles/spst/depth}}
{ospst}
{\ctikzvalof{bipoles/spst/height}}
{\ctikzvalof{bipoles/spst/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfscope
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{-10}{1.2\pgf@circ@res@right}}
        \pgfpatharc{-10}{90}{1.2\pgf@circ@res@right}
        \pgf@circ@set@switcharrow@style
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

%% Normal open Switch
\pgfcircdeclarebipolescaled{switches}
{
        \pgf@circ@savedanchor@trad@midlever{nos}{0.5}
}
{\ctikzvalof{bipoles/nos/depth}}
{nos}
{\ctikzvalof{bipoles/nos/height}}
{\ctikzvalof{bipoles/nos/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfsetbuttcap
    \pgfusepath{draw}
}

%% Normal closed Switch
\pgfcircdeclarebipolescaled{switches}
{
        \pgf@circ@savedanchor@trad@midlever{ncs}{0.5}
}
{\ctikzvalof{bipoles/ncs/depth}}
{ncs}
{\ctikzvalof{bipoles/ncs/height}}
{\ctikzvalof{bipoles/ncs/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
}

% Opening normal closed Switch
\pgfcircdeclarebipolescaled{switches}
{
        \pgf@circ@savedanchor@trad@midlever{ncs}{0.5}
}
{\ctikzvalof{bipoles/ncs/depth}}
{oncs}
{\ctikzvalof{bipoles/ncs/height}}
{\ctikzvalof{bipoles/ncs/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{-10}{.9\pgf@circ@res@right}}
        \pgfpatharc{-10}{95}{.9\pgf@circ@res@right}
        \pgf@circ@set@switcharrow@style
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

%% Closing normal closed Switch
\pgfcircdeclarebipolescaled{switches}
{
        \pgf@circ@savedanchor@trad@midlever{ncs}{0.5}
}
{\ctikzvalof{bipoles/ncs/depth}}
{cncs}
{\ctikzvalof{bipoles/ncs/height}}
{\ctikzvalof{bipoles/ncs/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{90}{.9\pgf@circ@res@right}}
        \pgfpatharc{90}{-35}{.9\pgf@circ@res@right}
        \pgf@circ@set@switcharrow@style
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

%% Opening normal open Switch
\pgfcircdeclarebipolescaled{switches}
{
        \pgf@circ@savedanchor@trad@midlever{ncs}{0.5}
}
{\ctikzvalof{bipoles/ncs/depth}}
{onos}
{\ctikzvalof{bipoles/ncs/height}}
{\ctikzvalof{bipoles/ncs/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{.4\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{-10}{.9\pgf@circ@res@right}}
        \pgfpatharc{-10}{95}{.9\pgf@circ@res@right}
        \pgf@circ@set@switcharrow@style
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

%% Closing normal open Switch
\pgfcircdeclarebipolescaled{switches}
{
        \pgf@circ@savedanchor@trad@midlever{ncs}{0.5}
}
{\ctikzvalof{bipoles/ncs/depth}}
{cnos}
{\ctikzvalof{bipoles/ncs/height}}
{\ctikzvalof{bipoles/ncs/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{.4\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{90}{.9\pgf@circ@res@right}}
        \pgfpatharc{90}{-35}{.9\pgf@circ@res@right}
        \pgf@circ@set@switcharrow@style
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

%% Push Button
\pgfcircdeclarebipolescaled{switches}
{
    \anchor{tip}{\northeast\pgf@x=0pt\relax}
    % we can use the generic here, the "bar" is related to bipoles/*/height
    \pgf@circ@savedanchor@trad@midlever{pushbutton}{0.5}
}
{\ctikzvalof{bipoles/pushbutton/height 2}}
{pushbutton}
{\ctikzvalof{bipoles/pushbutton/height}}
{\ctikzvalof{bipoles/pushbutton/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{.5\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{.5\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{0}{.5\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0}{\pgf@circ@res@up}}
    \pgfusepath{draw}

    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
    \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
}

%% Normally closed Push Button
\pgfcircdeclarebipolescaled{switches}
{
    \anchor{tip}{\northeast\pgf@x=0pt\relax}
    \savedanchor{\nodeheight}{
        \pgf@x=0pt\pgf@y=\ctikzvalof{nodes width}\pgf@circ@Rlen
    }
    \anchor{mid}{\nodeheight\pgf@y=-\pgf@y}
    % \pgf@circ@savedanchor@trad@midlever{pushbutton}{0.5}
}
{\ctikzvalof{bipoles/pushbutton/height 2}}
{ncpushbutton}
{\ctikzvalof{bipoles/pushbutton/height}}
{\ctikzvalof{bipoles/pushbutton/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    % This is the radius of the "ocirc" shape (see pgfcircshapes.tex)
    % Warning, if the nodes will have a class, we have to touch this.
    \pgf@circ@res@temp=\ctikzvalof{nodes width}\pgf@circ@Rlen
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@temp}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgf@circ@res@temp}}
    \pgfpathmoveto{\pgfpoint{0}{-\pgf@circ@res@temp}}
    \pgfpathlineto{\pgfpoint{0}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    %
    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
    \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
}
%% Push Button (normally closed but now open :-) see
%% https://github.com/circuitikz/circuitikz/issues/128#issuecomment-731771299
\pgfcircdeclarebipolescaled{switches}
{
    \savedanchor{\nodeheight}{
        \pgf@x=0pt\pgf@y=\ctikzvalof{nodes width}\pgf@circ@Rlen
    }
    \anchor{tip}{
        \nodeheight\pgf@circ@res@temp=\pgf@y
        \northeast\divide\pgf@y by 2\advance\pgf@y by \pgf@circ@res@temp
        \pgf@x=0pt\relax
    }
    \anchor{mid}{\nodeheight}
}
{\ctikzvalof{bipoles/pushbutton/height 2}}
{pushbuttonc}
{\ctikzvalof{bipoles/pushbutton/height}}
{\ctikzvalof{bipoles/pushbutton/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@res@temp=\ctikzvalof{nodes width}\pgf@circ@Rlen
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@temp}}
    \pgfpathmoveto{\pgfpoint{0}{\pgf@circ@res@temp}}
    \pgfpathlineto{\pgfpoint{0}{\pgf@circ@res@up/2+\pgf@circ@res@temp}}
    \pgfusepath{draw}

    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
    \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
}

%% Normally closed Push Button now open
\pgfcircdeclarebipolescaled{switches}
{
    \savedanchor{\nodeheight}{
        \pgf@x=0pt\pgf@y=\ctikzvalof{nodes width}\pgf@circ@Rlen
    }
    \anchor{tip}{
        \nodeheight\pgf@circ@res@temp=\pgf@y
        \northeast\divide\pgf@y by 2\advance\pgf@y by \pgf@circ@res@temp
        \pgf@x=0pt\relax
    }
    \anchor{mid}{\northeast\pgf@x=0pt\pgf@y=-0.5\pgf@y}
}
{\ctikzvalof{bipoles/pushbutton/height 2}}
{ncpushbuttono}
{\ctikzvalof{bipoles/pushbutton/height}}
{\ctikzvalof{bipoles/pushbutton/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    % This is the radius of the "ocirc" shape (see pgfcircshapes.tex)
    % Warning, if the nodes will have a class, we have to touch this.
    \pgf@circ@res@temp=\ctikzvalof{nodes width}\pgf@circ@Rlen
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up/2}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgf@circ@res@up/2}}
    \pgfpathmoveto{\pgfpoint{0}{-\pgf@circ@res@up/2}}
    \pgfpathlineto{\pgfpoint{0}{\pgf@circ@res@up/2+\pgf@circ@res@temp}}
    \pgfusepath{draw}
    %
    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
    \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw}}
}
%%% reed switches
\pgfcircdeclarebipolescaled{switches}
{
        \pgf@circ@savedanchor@trad@midlever{nos}{0.5}
}
{\ctikzvalof{bipoles/reed/depth}}
{reed}
{\ctikzvalof{bipoles/reed/height}}
{\ctikzvalof{bipoles/reed/width}}
{
    % this is designed to be the same as a "nos".
    \pgfmathsetmacro{\@@tmpx}{0.9*\ctikzvalof{bipoles/nos/width}/\ctikzvalof{bipoles/reed/width}}
    \pgfmathsetmacro{\@@tmpy}{\ctikzvalof{bipoles/nos/height}/\ctikzvalof{bipoles/reed/height}}
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        % eclosure
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@up}{\pgf@circ@res@up}}
        \pgfpatharc{90}{-90}{\pgf@circ@res@up}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@up}{-\pgf@circ@res@up}}
        \pgfpatharc{270}{90}{\pgf@circ@res@up}
        \pgfpathclose
        \pgf@circ@draworfill
        % switch
        \pgfpathmoveto{\pgfpoint{\@@tmpx\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{\@@tmpx\pgf@circ@res@right}{\@@tmpy\pgf@circ@res@up}}
        % connection lines
        \pgfsetbuttcap
        \pgfusepath{draw}
    \endpgfscope
    % connection lines
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{\@@tmpx\pgf@circ@res@left}{0pt}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\@@tmpx\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
}

% cute switch "to" shapes help function
% #1 -> name
% #2 -> barposition
% #3 -> arrowcode
\long\def\pgfcircdeclarecutesw#1#2#3{
    \pgfcircdeclarebipolescaled{switches}
    {
        \savedanchor\midlever{
            % these values are calculated when we create the definition of the shape.
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@y=\ctikzvalof{bipoles/cuteswitch/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@temp=\ctikzvalof{nodes width}\pgf@circ@scaled@Rlen
            \pgf@circ@res@temp=\ctikzvalof{bipoles/cuteswitch/thickness}\pgf@circ@res@temp
            \pgf@circ@res@down = -.5\pgf@y
            \pgf@circ@res@up = .5\pgf@y
            \pgfextracty{\pgf@circ@res@other}{#2}
            \pgf@x=0pt
            \pgf@y=.5\pgf@circ@res@other
        }
        % radius of the connector
        % This is the radius of the "ocirc" shape (see pgfcircshapes.tex)
        % If cnnecting nodes are scaled, we have to modify this
        \saveddimen{\radius}{\pgfmathsetlength\pgf@x{\pgf@circ@Rlen*\ctikzvalof{nodes width}}}
        % shapename
        \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
        % shape type
        \savedmacro{\cshape}{\def\cshape{\ctikzvalof{bipoles/cuteswitch/shape}}}
        % mid of the lever, to stack switches
        \anchor{mid}{\midlever}
        \anchor{cout}{\northeast \pgf@y=0cm}
        \anchor{cin}{\southwest\pgf@y=0cm}
        \anchor{out}{\northeast \pgf@y=0cm\advance\pgf@x by \radius}
        \anchor{in}{\southwest\pgf@y=0cm\advance\pgf@x by -\radius}
    }
    {\ctikzvalof{bipoles/cuteswitch/height 2}}
    {#1}
    {\ctikzvalof{bipoles/cuteswitch/height}}
    {\ctikzvalof{bipoles/cuteswitch/width}}{
        \pgfscope
        % This is the radius of the "ocirc" shape (see pgfcircshapes.tex)
        % If connecting nodes are scaled, we have to modify this
        \pgf@circ@res@temp=\ctikzvalof{nodes width}\pgf@circ@Rlen
        \pgf@circ@res@temp=\ctikzvalof{bipoles/cuteswitch/thickness}\pgf@circ@res@temp
        \pgfsetlinewidth{2\pgf@circ@res@temp}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{#2}
        \pgfsetroundcap\pgfusepath{draw}
        \endpgfscope
        \pgfscope % arrow
            \pgf@circ@fill@strokecolor
            #3%
        \endpgfscope
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfnode{\cshape}{center}{}{\thisshape-in}{\pgfusepath{draw}}
        \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
        \pgfnode{\cshape}{center}{}{\thisshape-out}{\pgfusepath{draw}}
    }
}

%% closed cute switch
\pgfcircdeclarecutesw{cuteclosedswitch}
    {\pgfpoint{\pgf@circ@res@right}{1.5\pgf@circ@res@temp}}
    {}

%% open cute switch
\pgfcircdeclarecutesw{cuteopenswitch}
    {\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    {}

%% closing cute switch
\pgfcircdeclarecutesw{cuteclosingswitch}
    {\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    {
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}} % in node
    \pgfpathmoveto{\pgfpointpolar{70}{1.2\pgf@circ@res@right}}
    \pgfpatharc{70}{-10}{1.2\pgf@circ@res@right}
    \pgf@circ@set@switcharrow@style
    \pgfusepath{draw}
    }

%% opening cute switch
\pgfcircdeclarecutesw{cuteopeningswitch}
    {\pgfpoint{\pgf@circ@res@right}{1.5\pgf@circ@res@temp}}
    {
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}} % in node
    \pgfpathmoveto{\pgfpointpolar{-10}{1.2\pgf@circ@res@right}}
    \pgfpatharc{-10}{60}{1.2\pgf@circ@res@right}
    \pgf@circ@set@switcharrow@style
    \pgfusepath{draw}
    }

\pgfcircdeclarebipole{
    \anchor{out 1}{\northeast\pgf@y=0pt\relax}
    \anchor{out 2}{\northeast\pgf@y=.8\pgf@y}
    \anchor{in}{\northeast\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{mid}{\northeast\pgf@x=0.2\pgf@x\pgf@y=0.25\pgf@y}
}
{\ctikzvalof{tripoles/toggleswitch/height 2}}
{toggleswitch}
{\ctikzvalof{tripoles/toggleswitch/height}}
{\ctikzvalof{tripoles/toggleswitch/width}}
{

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.3\pgf@circ@res@left}{0pt}}
    \pgfusepath{draw}
    \pgfscope
        \pgfpathmoveto{\pgfpoint{.3\pgf@circ@res@left}{0pt}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right}{.5\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.5\pgf@circ@res@right}{0}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{.8\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{.5\pgf@circ@res@right}{.8\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{.5\pgf@circ@res@right}{.15\pgf@circ@res@up}}
    \pgfusepath{draw}


    \pgfpathmoveto{\pgfpoint{.2\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}

    \pgfsetdash{{.08\pgf@circ@res@up}{.04\pgf@circ@res@up}{.7\pgf@circ@res@up}{.04\pgf@circ@res@up}{.8\pgf@circ@res@up}}{0cm}
    \pgfpathmoveto{\pgfpoint{0}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0}{.8\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@left}{.6\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0}{.4\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0}{.2\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfsetdash{}{0cm}
}

% %>>>

%% Shape nodes for switches (non-bipoles)%<<<

%%%%%%%%%%%%%
%% switches
%%%%%%%%%%%%%

% Legacy spdt
\pgfdeclareshape{spdt}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{switches}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/spdt/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/spdt/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \pgfcirc@northwest@symmetric@geoanchors
    \anchor{in}{\northwest\pgf@y=0pt}
    \anchor{out 1}{\northwest\pgf@x=-\pgf@x}
    % this is "by eye", it'll be wrong with non-standard ocirc
    \anchor{mid}{\northwest\pgf@x=0pt\pgf@y=0.37\pgf@y}
    \anchor{out 2}{\northwest\pgf@x=-\pgf@x \pgf@y=-\pgf@y}
    \anchor{center}{\pgf@y=0pt\pgf@x=0pt}
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@res@other = \ctikzvalof{tripoles/spdt/margin}\pgf@circ@res@left
        %
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@down}}
        %
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfusepath{draw}
        \pgfscope
            \pgftransformshift{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@up}}
            \pgfnode{ocirc}{center}{}{spdt1}{\pgfusepath{stroke}}
        \endpgfscope
        \pgfscope
            \pgftransformshift{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@down}}
            \pgfnode{ocirc}{center}{}{}{\pgfusepath{stroke}}
        \endpgfscope
        \pgfscope
            \pgftransformshift{\pgfpoint{\pgf@circ@res@other}{0pt}}
            \pgfnode{ocirc}{center}{}{spdt2}{\pgfusepath{stroke}}
        \endpgfscope
        \pgfscope
            \pgfpathmoveto{\pgfpointshapeborder{spdt2}{\pgfpointorigin}}
            \pgfpathlineto{
                \pgfpointadd{\pgfpointshapeborder{spdt1}{\pgfpoint{-\pgf@circ@res@other}{-100pt}}}
                {\pgfpoint{-.05\pgf@circ@res@up}{-.05\pgf@circ@res@up}}
            }
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgfusepath{draw}
        \endpgfscope
    }
}


% cute switch "node" shapes, matching with cute "to" shapes
% #1 -> name
% #2 -> barposition
% #3 -> arrowcode
\long\def\pgfcircdeclarecutespdt#1#2#3{
    \pgfdeclareshape{#1}
    {
        \savedmacro{\ctikzclass}{\edef\ctikzclass{switches}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \savedanchor\northwest{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@y=\ctikzvalof{bipoles/cuteswitch/height}\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@x=-\ctikzvalof{tripoles/spdt/width}\pgf@circ@scaled@Rlen
            \pgf@x=.25\pgf@x
        }
        \savedanchor\midlever{
            % these values are calculated when we create the definition of the shape.
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@y=\ctikzvalof{bipoles/cuteswitch/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@temp=\ctikzvalof{nodes width}\pgf@circ@scaled@Rlen
            \pgf@circ@res@temp=\ctikzvalof{bipoles/cuteswitch/thickness}\pgf@circ@res@temp
            \pgf@circ@res@down = -.5\pgf@y
            \pgf@circ@res@up = .5\pgf@y
            \pgfextracty{\pgf@circ@res@other}{#2}
            \pgf@x=0pt
            \pgf@y=.5\pgf@circ@res@other
        }
        % radius of the connector
        % This is the radius of the "ocirc" shape (see pgfcircshapes.tex)
        \saveddimen{\radius}{\pgfmathsetlength\pgf@x{\pgf@circ@Rlen*\ctikzvalof{nodes width}}}
        % shapename
        \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
        % shape type
        \savedmacro{\cshape}{\def\cshape{\ctikzvalof{bipoles/cuteswitch/shape}}}
        % mid of the lever, to stack switches
        \anchor{mid}{\midlever}
        % center anchors
        \anchor{cin}{ \northwest \pgf@y=0pt}
        \anchor{cout 1}{ \northwest \pgf@x=-\pgf@x }
        \anchor{cout 2}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
        % horizontal angles
        \anchor{in}{ \northwest \pgf@y=0pt\advance\pgf@x by -\radius}
        \anchor{out 1}{ \northwest \pgf@x=-\pgf@x \advance\pgf@x by \radius}
        \anchor{out 2}{ \northwest \pgf@x=-\pgf@x \advance\pgf@x by \radius \pgf@y=-\pgf@y }

        \anchor{center}{ \pgf@y=0pt \pgf@x=0pt }
        \anchor{east}{ \northwest \pgf@y=0pt \pgf@x=-\pgf@x  }
        \anchor{west}{ \northwest \pgf@y=0pt }
        \anchor{south}{ \northwest \pgf@x=0pt \pgf@y=-\pgf@y }
        \anchor{north}{ \northwest \pgf@x=0pt }
        \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
        \anchor{north east}{ \northwest \pgf@x=-\pgf@x }
        \anchor{north west}{ \northwest }
        \anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }

        \pgf@circ@draw@component{
            \pgf@circ@setcolor
            \northwest
            \pgf@circ@res@up = \pgf@y
            \pgf@circ@res@down = -\pgf@y
            \pgf@circ@res@right = -\pgf@x
            \pgf@circ@res@left = \pgf@x

            \pgfscope
            % This is the radius of the "ocirc" shape (see pgfcircshapes.tex)
            \pgf@circ@res@temp=\radius\relax
            \pgf@circ@res@temp=\ctikzvalof{bipoles/cuteswitch/thickness}\pgf@circ@res@temp
            \pgfsetlinewidth{2\pgf@circ@res@temp}
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
            \pgfpathlineto{#2}
            \pgfsetroundcap\pgfusepath{draw}
            \endpgfscope
            \pgfscope % arrow
                \pgf@circ@fill@strokecolor
                #3%
            \endpgfscope
            % terminals
            \pgfscope
            \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
            \pgfnode{\cshape}{center}{}{\thisshape-out 1}{\pgfusepath{stroke}}
            \endpgfscope
            \pgfscope
            \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgfnode{\cshape}{center}{}{\thisshape-out 2}{\pgfusepath{stroke}}
            \endpgfscope
            \pgfscope
            \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
            \pgfnode{\cshape}{center}{}{\thisshape-in}{\pgfusepath{stroke}}
            \endpgfscope

        }
    }
}

\pgfcircdeclarecutespdt{cute spdt up}
{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up-1.5\pgf@circ@res@temp}}
{}

\pgfcircdeclarecutespdt{cute spdt mid}
{\pgfpoint{\pgf@circ@res@right}{0pt}}
{}

\pgfcircdeclarecutespdt{cute spdt down}
{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down+1.5\pgf@circ@res@temp}}
{}

\pgfcircdeclarecutespdt{cute spdt up arrow}
{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up-1.5\pgf@circ@res@temp}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgflinewidth}
    \pgfsetlinewidth{\ctikzvalof{switch arrows/relative thickness}\pgflinewidth}
    \pgf@circ@subset@color@dash{switch arrows}
    \pgfcirc@set@arrows{switch}{}{latexslim}
    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}} % in node
    \pgfpathmoveto{\pgfpointpolar{70}{1.5\pgf@circ@res@right}}
    \pgfpatharc{70}{-50}{1.5\pgf@circ@res@right}
    \pgfusepath{draw}
}

\pgfcircdeclarecutespdt{cute spdt mid arrow}
{\pgfpoint{\pgf@circ@res@right}{0pt}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgflinewidth}
    \pgfsetlinewidth{\ctikzvalof{switch arrows/relative thickness}\pgflinewidth}
    \pgf@circ@subset@color@dash{switch arrows}
    \pgfcirc@set@arrows{switch}{latexslim}{latexslim}
    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}} % in node
    \pgfpathmoveto{\pgfpointpolar{-60}{1.5\pgf@circ@res@right}}
    \pgfpatharc{-60}{60}{1.5\pgf@circ@res@right}
    \pgfusepath{draw}
}

\pgfcircdeclarecutespdt{cute spdt down arrow}
{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down+1.5\pgf@circ@res@temp}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgflinewidth}
    \pgfsetlinewidth{\ctikzvalof{switch arrows/relative thickness}\pgflinewidth}
    \pgf@circ@subset@color@dash{switch arrows}
    \pgfcirc@set@arrows{switch}{}{latexslim}
    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}} % in node
    \pgfpathmoveto{\pgfpointpolar{-50}{1.5\pgf@circ@res@right}}
    \pgfpatharc{-50}{70}{1.5\pgf@circ@res@right}
    \pgfusepath{draw}
}
% %>>>

%% Paths Switches and buttons%<<<

\pgfcirc@activate@bipole{l}{cspst}{cspst}{closing switch}
\pgfcirc@style@to@style{closing switch}{switch}
\pgfcirc@style@to@style{closing switch}{cspst}
\pgfcirc@style@to@style{switch}{spst}
\pgfcirc@activate@bipole{l}{ospst}{ospst}{opening switch}
\pgfcirc@style@to@style{opening switch}{ospst}

\pgfcirc@activate@bipole@simple{l}{nos}
\pgfcirc@style@to@style{nos}{normal open switch}
\pgfcirc@activate@bipole@simple{l}{ncs}
\pgfcirc@style@to@style{ncs}{normal closed switch}
\pgfcirc@activate@bipole@simple{l}{oncs}
\pgfcirc@style@to@style{oncs}{opening normal closed switch}
\pgfcirc@activate@bipole@simple{l}{cncs}
\pgfcirc@style@to@style{cncs}{closing normal closed switch}
\pgfcirc@activate@bipole@simple{l}{onos}
\pgfcirc@style@to@style{onos}{opening normal open switch}
\pgfcirc@activate@bipole@simple{l}{cnos}
\pgfcirc@style@to@style{cnos}{closing normal open switch}

\pgfcirc@activate@bipole{l}{pushbutton}{pushbutton}{push button}
\pgfcirc@style@to@style{push button}{nopb}
\pgfcirc@style@to@style{push button}{normally open push button}
\pgfcirc@activate@bipole{l}{ncpushbutton}{ncpushbutton}{ncpb}
\pgfcirc@style@to@style{ncpb}{normally closed push button}
\pgfcirc@activate@bipole{l}{pushbuttonc}{pushbuttonc}{nopbc}
\pgfcirc@style@to@style{nopbc}{normally open push button closed}
\pgfcirc@activate@bipole{l}{ncpushbuttono}{ncpushbuttono}{ncpbo}
\pgfcirc@style@to@style{ncpbo}{normally closed push button open}

\pgfcirc@activate@bipole{l}{toggleswitch}{toggleswitch}{toggle switch}
\pgfcirc@activate@bipole@simple{l}{reed}

\pgfcirc@activate@bipole{l}{cuteclosedswitch}{cuteclosedswitch}{cute closed switch}
\pgfcirc@style@to@style{cute closed switch}{ccsw}
\pgfcirc@activate@bipole{l}{cuteopenswitch}{cuteopenswitch}{cute open switch}
\pgfcirc@style@to@style{cute open switch}{cosw}
\pgfcirc@activate@bipole{l}{cuteclosingswitch}{cuteclosingswitch}{cute closing switch}
\pgfcirc@style@to@style{cute closing switch}{ccgsw}
\pgfcirc@activate@bipole{l}{cuteopeningswitch}{cuteopeningswitch}{cute opening switch}
\pgfcirc@style@to@style{cute opening switch}{cogsw}% %>>>

%% Proximity switch auxiliary shapes%<<<
%% proximeter shape, for usage with switches
\ctikzset{proximeter/width/.initial=0.3}
\ctikzset{proximeter/hlines thickness/.initial=0.5}
\ctikzset{proximeter/hlines position/.initial=0.3}
\pgfdeclareshape{proximeter}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{switches}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedmacro{\hlinepos}{\edef\hlinepos{\ctikzvalof{proximeter/hlines position}}}
    \savedanchor\northeast{%
        \pgfmathsetlength{\pgf@y}{\ctikzvalof{proximeter/width}*\ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
        \pgf@x=\pgf@y
    }
    \anchor{center}{\pgfpointorigin}
    % geo anchors based on north-east
    \pgfcirc@northeast@symmetric@geoanchors
    \anchor{text}{%
        \northeast
        \pgf@x=\dimexpr -.5\wd\pgfnodeparttextbox\relax
        \advance\pgf@y by .6\ht\pgfnodeparttextbox\relax
    }
    \anchor{hlines ne}{%
        \northeast
        \pgf@y=\hlinepos\pgf@y
        \advance\pgf@x by -\pgf@y
    }
    \anchor{hlines nw}{%
        \northeast
        \pgf@y=\hlinepos\pgf@y
        \advance\pgf@x by -\pgf@y\pgf@x=-\pgf@x
    }
    \anchor{hlines se}{%
        \northeast
        \pgf@y=\hlinepos\pgf@y
        \advance\pgf@x by -\pgf@y
        \pgf@y=-\pgf@y
    }
    \anchor{hlines sw}{%
        \northeast
        \pgf@y=\hlinepos\pgf@y
        \advance\pgf@x by -\pgf@y\pgf@x=-\pgf@x
        \pgf@y=-\pgf@y
    }
    \anchorborder{
        % \typeout{IN\space X:\the\pgf@x\space Y:\the\pgf@y}
        \pgfmathsetmacro{\@@switchx}{ifthenelse(\pgf@x>0,1,-1)}
        \pgfmathsetmacro{\@@switchy}{ifthenelse(\pgf@y>0,1,-1)}
        \pgfmathsetlength{\pgf@xa}{abs(\pgf@x)}
        \pgfmathsetlength{\pgf@ya}{abs(\pgf@y)}
        \pgfextracty{\pgf@circ@res@up}{\northeast}
        % \typeout{MID\space X:\the\pgf@xa\space Y:\the\pgf@ya\space L:\the\pgf@circ@res@up}
        % \typeout{MID\space SX:\@@switchx\space SY:\@@switchy}
        \pgfpointintersectionoflines
            {\pgfpointorigin}{\pgfqpoint{\pgf@xa}{\pgf@ya}}
            {\pgfqpoint{0pt}{\pgf@circ@res@up}}{\pgfqpoint{\pgf@circ@res@up}{0pt}}
        % \typeout{CROSS \space X:\the\pgf@x\space Y:\the\pgf@y}
        \pgf@x=\@@switchx\pgf@x
        \pgf@y=\@@switchy\pgf@y
    }
    \pgf@circ@draw@component{
        \northeast\pgf@circ@res@temp=\pgf@y
        \pgf@circ@setcolor
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@temp}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@temp}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@temp}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{-\pgf@circ@res@temp}}
        \pgfpathclose
        \pgf@circ@draworfill
        \pgfsetlinewidth{\ctikzvalof{proximeter/hlines thickness}*\pgflinewidth}
        \pgfmathsetlength{\pgf@circ@res@up}{\hlinepos*\pgf@circ@res@temp}
        \pgfmathsetlength{\pgf@circ@res@right}{\pgf@circ@res@temp-\pgf@circ@res@up}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{-\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgf@circ@res@up}}
        \pgfusepath{draw}
    }

}
\pgfcirc@node@to@path{proximeter}{inline proximeter}{}
% %>>>

% jumpers: definitions and code %<<<
% definitons for jumpers
\ctikzset{bipoles/jumper/width/.initial=0.4}
\ctikzset{bipoles/tjumper/width/.initial=0.6}% normally is less than 0.4*2
\ctikzset{tjumper connections/.initial=00}% bare-bare
\ctikzset{bipoles/jumper/height/.initial=0.4}
\ctikzset{bipoles/jumper/depth/.initial=0.1}
\ctikzset{bipoles/jumper/shape/.initial=ocirc}
\ctikzset{bipoles/jumper/curvature/.initial=2}  % curvature of the arc
\ctikzset{bipoles/jumper/open shift/.initial=3} % displacement to open the arc

% jumpers
% simple jumpers
% #1 -> name
% #2 -> height of the link arc (0 means no link, 1 closed, 2 open)
\long\def\pgfcircdeclarejumper#1#2{
    \pgfcircdeclarebipolescaled{switches}
        {
            % This is the radius of the "ocirc" shape (see pgfcircshapes.tex)
            \saveddimen{\radius}{\pgfmathsetlength\pgf@x{\pgf@circ@Rlen*\ctikzvalof{nodes width}}}
            % shapename
            \savedmacro{\thisshape}{\edef\thisshape{\tikz@fig@name}}
            % shape type
            \savedmacro{\cshape}{\edef\cshape{\ctikzvalof{bipoles/jumper/shape}}}
            % arc characteristics (can vary, must be saved...)
            \savedmacro{\curvature}{\edef\curvature{\ctikzvalof{bipoles/jumper/curvature}}}
            \savedmacro{\openshift}{\edef\openshift{\ctikzvalof{bipoles/jumper/open shift}}}
            %
            \anchor{cout}{\northeast \pgf@y=0cm}
            \anchor{cin}{\southwest\pgf@y=0cm}
            \anchor{out}{\northeast \pgf@y=0cm\advance\pgf@x by \radius}
            \anchor{in}{\southwest\pgf@y=0cm\advance\pgf@x by -\radius}
            \anchor{text}{\northeast
                \pgf@x=\dimexpr -.5\wd\pgfnodeparttextbox\relax
                \advance\pgf@y by .6\ht\pgfnodeparttextbox\relax
            }
            \anchor{top arc}{\northeast
                \pgf@circ@res@other=\pgf@x
                \pgf@circ@res@temp=\radius
                \ifnum #2=1 \edef\@@b{1}\else\edef\@@b{\openshift}\fi
                \pgfpointcurveattime{0.5}
                    {\pgfpoint{-0.9\pgf@circ@res@other}{{(\@@b)*\radius}}}
                    {\pgfpoint{-0.5\pgf@circ@res@other}{{(\@@b+\curvature)*\radius}}}
                    {\pgfpoint{0.5\pgf@circ@res@other}{{(\@@b+\curvature)*\radius}}}
                    {\pgfpoint{0.9\pgf@circ@res@other}{{(\@@b)*\radius}}}
            }
        }
        {\ctikzvalof{bipoles/jumper/depth}}
        {#1}
        {\ctikzvalof{bipoles/jumper/height}}
        {\ctikzvalof{bipoles/jumper/width}}{
            %
            \ifnum #2=0 \else
                \ifnum #2=1 \edef\@@b{1}\else\edef\@@b{\openshift}\fi
                \pgfpathmoveto{\pgfpoint{0.9*\pgf@circ@res@left}{(\@@b)*\radius}}
                \pgfpathcurveto
                    {\pgfpoint{.5\pgf@circ@res@left}{(\@@b+\curvature)*\radius}}
                    {\pgfpoint{.5\pgf@circ@res@right}{(\@@b+\curvature)*\radius}}
                    {\pgfpoint{0.9*\pgf@circ@res@right}{(\@@b)*\radius}}
                \pgfusepath{draw}
            \fi
            \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
            \pgfnode{\cshape}{center}{}{\thisshape-in}{\pgfusepath{draw}}
            \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
            \pgfnode{\cshape}{center}{}{\thisshape-out}{\pgfusepath{draw}}
        }
}
\pgfcircdeclarejumper{bjumper}{0}
\pgfcircdeclarejumper{cjumper}{1}
\pgfcircdeclarejumper{ojumper}{2}
\pgfcirc@activate@bipole{l}{bjumper}{bjumper}{bare jumper}
\pgfcirc@activate@bipole{l}{ojumper}{ojumper}{open jumper}
\pgfcirc@activate@bipole{l}{cjumper}{cjumper}{closed jumper}
% jumpers
% three pins (two-ways) jumpers
% #1 -> name
% #2 -> height of the first link arc (0 means no link, 1 closed, 2 open)
% #3 -> height of the second link arc (0 means no link, 1 closed, 2 open)
\def\pgf@circ@tjumper@splitstatus#1#2\relax{%split the two values
    \edef\@@a{#1}\edef\@@b{#2}%
}
\pgfcircdeclarebipolescaled{switches}
    {
        % This is the radius of the "ocirc" shape (see pgfcircshapes.tex)
        \saveddimen{\radius}{\pgfmathsetlength\pgf@x{\pgf@circ@Rlen*\ctikzvalof{nodes width}}}
        % shapename
        \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
        % shape type
        \savedmacro{\cshape}{\def\cshape{\ctikzvalof{bipoles/jumper/shape}}}
        % arc characteristics (can vary, must be saved...)
        \savedmacro{\curvature}{\edef\curvature{\ctikzvalof{bipoles/jumper/curvature}}}
        \savedmacro{\openshift}{\edef\openshift{\ctikzvalof{bipoles/jumper/open shift}}}
        \savedmacro{\jumpertype}{\edef\jumpertype{\ctikzvalof{tjumper connections}}}
        %
        \anchor{cout}{\northeast \pgf@y=0cm}
        \anchor{cin}{\southwest\pgf@y=0cm}
        \anchor{ctap}{\pgf@x=0cm\pgf@y=0cm}
        \anchor{out}{\northeast \pgf@y=0cm\advance\pgf@x by \radius}
        \anchor{in}{\southwest\pgf@y=0cm\advance\pgf@x by -\radius}
        \anchor{tap}{\pgf@x=0cm\pgf@y=0cm\advance\pgf@y by -\radius}
        \anchor{top arc left}{\northeast
            \pgf@circ@res@other=-\pgf@x
            \pgf@circ@res@temp=\pgf@x
            %
            % read the status of the jumper
            %
            \expandafter\pgf@circ@tjumper@splitstatus\jumpertype\relax% a bit of magic...
            \edef\@@S{S}%the "S" letter
            \ifx\@@a\@@S %span, it's in the center
                \ifnum \@@b=0\pgfpointorigin\else % no arc, anchor on the center-base
                    \ifnum \@@b=2 \edef\@@b{\openshift} \else \edef\@bb{1}\relax \fi
                    \pgfpointcurveattime{0.5}
                        {\pgfpoint{0.9*\pgf@circ@res@other}{(\@@b)*\radius}}
                        {\pgfpoint{.5*\pgf@circ@res@other}{(\@@b+\curvature)*\radius}}
                        {\pgfpoint{.5*\pgf@circ@res@temp}{(\@@b+\curvature)*\radius}}
                        {\pgfpoint{0.9*\pgf@circ@res@temp}{(\@@b)*\radius}}
                \fi
            \else
                % adjust the lengths of the gap, if needed
                \ifnum \@@a=2 \edef\@@a{\openshift} \else \edef\@aa{1} \relax \fi
                \ifnum \@@b=2 \edef\@@b{\openshift} \else \edef\@bb{1} \relax \fi
                % left join
                \ifnum \@@a=0 \pgfpoint{0.475*\pgf@circ@res@other}{0pt}\else
                    \pgfpointcurveattime{0.5}
                        {\pgfpoint{0.95*\pgf@circ@res@other}{\@@a*\radius}}
                        {\pgfpoint{.75*\pgf@circ@res@other}{(\@@a+\curvature)*\radius}}
                        {\pgfpoint{.25*\pgf@circ@res@other}{(\@@a+\curvature)*\radius}}
                        {\pgfpoint{0.05*\pgf@circ@res@other}{\@@a*\radius}}
                \fi
            \fi
        }
        \anchor{top arc right}{\northeast
            \pgf@circ@res@other=-\pgf@x
            \pgf@circ@res@temp=\pgf@x
            %
            % read the status of the jumper
            %
            \expandafter\pgf@circ@tjumper@splitstatus\jumpertype\relax% a bit of magic...
            \edef\@@S{S}%the "S" letter
            \ifx\@@a\@@S %span, it's in the center
                \ifnum \@@b=0\pgfpointorigin\else % no arc, anchor on the center-base
                    \ifnum \@@b=2 \edef\@@b{\openshift} \else \edef\@bb{1}\relax \fi
                    \pgfpointcurveattime{0.5}
                        {\pgfpoint{0.9*\pgf@circ@res@other}{(\@@b)*\radius}}
                        {\pgfpoint{.5*\pgf@circ@res@other}{(\@@b+\curvature)*\radius}}
                        {\pgfpoint{.5*\pgf@circ@res@temp}{(\@@b+\curvature)*\radius}}
                        {\pgfpoint{0.9*\pgf@circ@res@temp}{(\@@b)*\radius}}
                \fi
            \else
                % adjust the lengths of the gap, if needed
                \ifnum \@@a=2 \edef\@@a{\openshift} \else \edef\@aa{1} \relax \fi
                \ifnum \@@b=2 \edef\@@b{\openshift} \else \edef\@bb{1} \relax \fi
                % right join
                \ifnum \@@b=0 \pgfpoint{0.475*\pgf@circ@res@temp}{0pt}\else
                    \pgfpointcurveattime{0.5}
                        {\pgfpoint{0.95*\pgf@circ@res@temp}{\@@b*\radius}}
                        {\pgfpoint{.75\pgf@circ@res@temp}{(\@@b+\curvature)*\radius}}
                        {\pgfpoint{.25\pgf@circ@res@temp}{(\@@b+\curvature)*\radius}}
                        {\pgfpoint{0.05*\pgf@circ@res@temp}{\@@b*\radius}}
                \fi
            \fi
        }
    }
    {\ctikzvalof{bipoles/jumper/depth}}
    {tjumper}
    {\ctikzvalof{bipoles/jumper/height}}
    {\ctikzvalof{bipoles/tjumper/width}}{
        %
        % read the status of the jumper
        %
        \expandafter\pgf@circ@tjumper@splitstatus\jumpertype\relax% a bit of magic...
        \edef\@@S{S}%the "S" letter
        \ifx\@@a\@@S %span
            \ifnum \@@b=0 \else
                \ifnum \@@b=2 \edef\@@b{\openshift} \else \edef\@bb{1}\relax \fi
                \pgfpathmoveto{\pgfpoint{0.9*\pgf@circ@res@left}{(\@@b)*\radius}}
                \pgfpathcurveto
                    {\pgfpoint{.5\pgf@circ@res@left}{(\@@b+\curvature)*\radius}}
                    {\pgfpoint{.5\pgf@circ@res@right}{(\@@b+\curvature)*\radius}}
                    {\pgfpoint{0.9*\pgf@circ@res@right}{(\@@b)*\radius}}
                \pgfusepath{draw}
            \fi
        \else
        % let's do the connection, if needed
            % adjust the lengths of the gap, if needed
            \ifnum \@@a=2 \edef\@@a{\openshift} \else \edef\@aa{1} \relax \fi
            \ifnum \@@b=2 \edef\@@b{\openshift} \else \edef\@bb{1} \relax \fi
            % left arc
            \ifnum \@@a=0 \else
                \pgfpathmoveto{\pgfpoint{0.95*\pgf@circ@res@left}{\@@a*\radius}}
                \pgfpathcurveto
                    {\pgfpoint{.75\pgf@circ@res@left}{(\@@a+\curvature)*\radius}}
                    {\pgfpoint{.25\pgf@circ@res@left}{(\@@a+\curvature)*\radius}}
                    {\pgfpoint{0.05*\pgf@circ@res@left}{\@@a*\radius}}
                \pgfusepath{draw}
            \fi
            % right arc
            \ifnum \@@b=0 \else
                \pgfpathmoveto{\pgfpoint{0.95*\pgf@circ@res@right}{\@@b*\radius}}
                \pgfpathcurveto
                    {\pgfpoint{.75\pgf@circ@res@right}{(\@@b+\curvature)*\radius}}
                    {\pgfpoint{.25\pgf@circ@res@right}{(\@@b+\curvature)*\radius}}
                    {\pgfpoint{0.05*\pgf@circ@res@right}{\@@b*\radius}}
                \pgfusepath{draw}
            \fi
        \fi
        % draw the poles (always filled!)
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfnode{\cshape}{center}{}{\thisshape-in}{\pgfusepath{draw}}
        \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfnode{\cshape}{center}{}{\thisshape-tap}{\pgfusepath{draw}}
        \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfnode{\cshape}{center}{}{\thisshape-out}{\pgfusepath{draw}}
    }

\pgfcirc@activate@bipole{l}{tjumper}{tjumper}{three-pins jumper}

% %>>>

% solder jumpers: definitions and code %<<<
\ctikzset{bipoles/solder jumper/width/.initial=0.36}
\ctikzset{bipoles/solder jumper/height/.initial=0.3} % must be less than width, otherwise no gap!
\ctikzset{bipoles/solder jumper/close height/.initial=0.6}% fraction of the vertical gap filled
\ctikzset{bipoles/double solder jumper/width/.initial=0.57}
%
\def\pgfcirc@base@solder@jumper{%
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@up}{\pgf@circ@res@up}}
    \pgfpatharc{90}{270}{\pgf@circ@res@up}
    \pgfpathclose
    \pgfusepath{draw,fill}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@up}{\pgf@circ@res@up}}
    \pgfpatharc{90}{-90}{\pgf@circ@res@up}
    \pgfpathclose
    \pgfusepath{draw,fill}
}
% simple solder jumpers
% #1 -> name
% #2 -> open or close (0 means open, 1 closed)
\long\def\pgfcircdeclaresolderjumper#1#2{
    \pgfcircdeclarebipolescaled{switches}
        {
            \anchor{out}{\northeast \pgf@y=0cm}
            \anchor{in}{\southwest\pgf@y=0cm}
            \anchor{text}{\northeast
                \pgf@x=\dimexpr -.5\wd\pgfnodeparttextbox\relax
                \advance\pgf@y by .6\ht\pgfnodeparttextbox\relax
            }
        }
        {\ctikzvalof{bipoles/solder jumper/height}}
        {#1}
        {\ctikzvalof{bipoles/solder jumper/height}}
        {\ctikzvalof{bipoles/solder jumper/width}}{
            %
            \pgfcirc@base@solder@jumper
            \ifnum #2=0 \else
                \pgfpathrectanglecorners
                {\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@up}
                    {\ctikzvalof{bipoles/solder jumper/close height}\pgf@circ@res@up}}
                {\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@up}
                    {\ctikzvalof{bipoles/solder jumper/close height}\pgf@circ@res@down}}
                \pgfusepath{fill, draw}
            \fi
        }
}
\pgfcircdeclaresolderjumper{osjumper}{0}
\pgfcircdeclaresolderjumper{csjumper}{1}
\pgfcirc@activate@bipole{l}{osjumper}{osjumper}{open solder jumper}
\pgfcirc@activate@bipole{l}{csjumper}{csjumper}{closed solder jumper}
% three pins (two-ways) solder jumpers
% #1 -> name
% #2 -> first side open or closed
% #3 -> second side open or closed
\long\def\pgfcircdeclaredoublesolderjumper#1#2#3{
    \pgfcircdeclarebipolescaled{switches}
        {
            %
            \anchor{out}{\northeast \pgf@y=0cm}
            \anchor{in}{\southwest\pgf@y=0cm}
            \anchor{tap}{\northeast\pgf@x=0cm}
            \anchor{tap up}{\northeast\pgf@x=0cm}
            \anchor{tap down}{\northeast\pgf@x=0cm\pgf@y=-\pgf@y}
            \anchor{text}{\northeast
                \pgf@x=\dimexpr -.5\wd\pgfnodeparttextbox\relax
                \advance\pgf@y by .6\ht\pgfnodeparttextbox\relax
            }
        }
        {\ctikzvalof{bipoles/solder jumper/height}}
        {#1}
        {\ctikzvalof{bipoles/solder jumper/height}}
        {\ctikzvalof{bipoles/double solder jumper/width}}
        {
            \pgfcirc@base@solder@jumper
            \pgfpathrectanglecorners
                {\pgfpoint{-.5\pgf@circ@res@up}{\pgf@circ@res@up}}
                {\pgfpoint{.5\pgf@circ@res@up}{\pgf@circ@res@down}}
                \pgfusepath{fill, draw}
            \ifnum #2=0 \else
                \pgfpathrectanglecorners
                    {\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@up}{\ctikzvalof{bipoles/solder jumper/close height}\pgf@circ@res@up}}
                    {\pgfpoint{-.5\pgf@circ@res@up}{\ctikzvalof{bipoles/solder jumper/close height}\pgf@circ@res@down}}
                    \pgfusepath{fill, draw}
            \fi
            \ifnum #3=0 \else
                \pgfpathrectanglecorners
                    {\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@up}{\ctikzvalof{bipoles/solder jumper/close height}\pgf@circ@res@up}}
                    {\pgfpoint{.5\pgf@circ@res@up}{\ctikzvalof{bipoles/solder jumper/close height}\pgf@circ@res@down}}
                    \pgfusepath{fill, draw}
            \fi
        }
}
%
\pgfcircdeclaredoublesolderjumper{odsjumper}{0}{0}
\pgfcircdeclaredoublesolderjumper{ldsjumper}{1}{0}
\pgfcircdeclaredoublesolderjumper{rdsjumper}{0}{1}
\pgfcircdeclaredoublesolderjumper{cdsjumper}{1}{1}
\pgfcirc@activate@bipole{l}{odsjumper}{odsjumper}{open double solder jumper}
\pgfcirc@activate@bipole{l}{ldsjumper}{ldsjumper}{left double solder jumper}
\pgfcirc@activate@bipole{l}{rdsjumper}{rdsjumper}{right double solder jumper}
\pgfcirc@activate@bipole{l}{cdsjumper}{cdsjumper}{closed double solder jumper}

% %>>>

%%%%%%%%%%%%%%%%%
%% Instruments
%%%%%%%%%%%%%%%%%

%% Definitions for Instruments %<<<1
\ctikzset{bipoles/ammeter/height/.initial=.60}
\ctikzset{bipoles/ammeter/width/.initial=.60}
\ctikzset{bipoles/ohmmeter/height/.initial=.60}
\ctikzset{bipoles/ohmmeter/width/.initial=.60}
\ctikzset{bipoles/voltmeter/height/.initial=.60}
\ctikzset{bipoles/voltmeter/width/.initial=.60}
\ctikzset{bipoles/smeter/height/.initial=.60}
\ctikzset{bipoles/smeter/width/.initial=.60}
\ctikzset{bipoles/smeter/voltage/additional shift/.initial=1}
\ctikzset{bipoles/qmeter/depth/.initial=.40}
\ctikzset{bipoles/qmeter/height/.initial=.80}
\ctikzset{bipoles/qmeter/width/.initial=.60}
% this must be specified for each one
\ctikzset{bipoles/qvprobe/voltage/additional shift/.initial=.5}
\ctikzset{bipoles/qiprobe/voltage/additional shift/.initial=.5}
\ctikzset{bipoles/qpprobe/voltage/additional shift/.initial=.5}
\ctikzset{bipoles/iloop/width/.initial=.40}
\ctikzset{bipoles/iloop/height/.initial=.60}
% currtap see https://github.com/circuitikz/circuitikz/issues/807
\ctikzset{bipoles/currtap/height/.initial=0.4}
\ctikzset{bipoles/currtap/dot size/.initial=0.5}
\ctikzset{bipoles/currtap/fill/.initial=default}
\ctikzset{bipoles/currtap/dash/.initial=none}
\ctikzset{bipoles/currtap/color/.initial=default}
\ctikzset{bipoles/currtap/thickness/.initial=default}

\ctikzset{bipoles/oscope/height/.initial=.60}
\ctikzset{bipoles/oscope/width/.initial=.60}
\ctikzset{bipoles/oscope/voltage/additional shift/.initial=1}


% option to not rotate the new (Romano's) instruments
\newif\ifpgf@circuit@straightinstruments\pgf@circuit@straightinstrumentstrue
\pgfkeys{/tikz/straight instruments/.add code={}{\pgf@circuit@straightinstrumentstrue}}
\ctikzset{straight instruments/.add code={}{\pgf@circuit@straightinstrumentstrue}}
\pgfkeys{/tikz/rotated instruments/.add code={}{\pgf@circuit@straightinstrumentsfalse}}
\ctikzset{rotated instruments/.add code={}{\pgf@circuit@straightinstrumentsfalse}}
%%>>>

%% Node shapes for instruments%<<<

% % METERINGSHAPE
\long\def\drawmeteringcircle{
    \def\pgf@circ@temp{right}
    \ifx\tikz@res@label@pos\pgf@circ@temp
        \pgf@circ@res@step=-1.2\pgf@circ@res@up
    \else
        \def\pgf@circ@temp{below}
        \ifx\tikz@res@label@pos\pgf@circ@temp
            \pgf@circ@res@step=-1.2\pgf@circ@res@up
        \else
            \pgf@circ@res@step=1.2\pgf@circ@res@up
        \fi
    \fi
    %draw connections to circle
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathmoveto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfusepath{draw}
    %draw circle
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathcircle{\pgfpointorigin}{.9\pgf@circ@res@up}
        \pgf@circ@draworfill
    \endpgfscope
    %draw arrow
    \pgfscope
        \pgfsetarrowsend{latex}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}

%AMPEREMETER
\pgfcircdeclarebipolescaled{instruments}
{}
{\ctikzvalof{bipoles/ammeter/height}}
{ammeter}
{\ctikzvalof{bipoles/ammeter/height}}
{\ctikzvalof{bipoles/ammeter/width}}
{
    \drawmeteringcircle
    \pgfnode{circle}{center}{\pgf@circ@font@bold{A}}{}{}
}
%OHMMETER
\pgfcircdeclarebipolescaled{instruments}
{}
{\ctikzvalof{bipoles/ohmmeter/height}}
{ohmmeter}
{\ctikzvalof{bipoles/ohmmeter/height}}
{\ctikzvalof{bipoles/ohmmeter/width}}
{
    \drawmeteringcircle
    \pgfnode{circle}{center}{\boldmath$\Omega$}{}{}
}
%VOLTMETER
\pgfcircdeclarebipolescaled{instruments}
{}
{\ctikzvalof{bipoles/voltmeter/height}}
{voltmeter}
{\ctikzvalof{bipoles/voltmeter/height}}
{\ctikzvalof{bipoles/voltmeter/width}}
{
    \drawmeteringcircle
    \pgfnode{circle}{center}{\pgf@circ@font@bold{V}}{}{}

}

% oscilloscope, suggested by @nobrl https://github.com/circuitikz/circuitikz/issues/176
%
% oscilloscope waveforms

\ctikzset{%
    bipoles/oscope/waveform/sin/.code={%
        \pgfpathmoveto{\pgfpoint{-0.6cm}{0cm}}
        \pgfpathsine{\pgfpoint{0.3cm}{0.4cm}}
        \pgfpathcosine{\pgfpoint{0.3cm}{-0.4cm}}
        \pgfpathsine{\pgfpoint{0.3cm}{-0.4cm}}
        \pgfpathcosine{\pgfpoint{0.3cm}{0.4cm}}
        \pgfusepath{draw}
    },
    bipoles/oscope/waveform/ramps/.code={%
        \pgfpathmoveto{\pgfpoint{-0.75cm}{-0.25cm}}
        \pgfpathlineto{\pgfpoint{-0.05cm}{0.25cm}}
        \pgfpathlineto{\pgfpoint{-0.05cm}{-0.25cm}}
        \pgfpathlineto{\pgfpoint{0.65cm}{0.25cm}}
        \pgfpathlineto{\pgfpoint{0.65cm}{-0.25cm}}
        \pgfusepath{draw}
    },
    bipoles/oscope/waveform/square/.code={%
        \pgfpathmoveto{\pgfpoint{-0.75cm}{-0.25cm}}
        \pgfpathlineto{\pgfpoint{-0.6cm}{-0.25cm}}
        \pgfpathlineto{\pgfpoint{-0.6cm}{0.25cm}}
        \pgfpathlineto{\pgfpoint{0cm}{0.25cm}}
        \pgfpathlineto{\pgfpoint{0cm}{-0.25cm}}
        \pgfpathlineto{\pgfpoint{0.6cm}{-0.25cm}}
        \pgfpathlineto{\pgfpoint{0.6cm}{0.25cm}}
        \pgfpathlineto{\pgfpoint{0.75cm}{0.25cm}}
        \pgfusepath{draw}
    },
    bipoles/oscope/waveform/triangle/.code={%
        \pgfpathmoveto{\pgfpoint{-0.75cm}{0cm}}
        \pgfpathlineto{\pgfpoint{-0.6cm}{-0.25cm}}
        \pgfpathlineto{\pgfpoint{-0.3cm}{0.25cm}}
        \pgfpathlineto{\pgfpoint{0cm}{-0.25cm}}
        \pgfpathlineto{\pgfpoint{0.3cm}{0.25cm}}
        \pgfpathlineto{\pgfpoint{0.6cm}{-0.25cm}}
        \pgfpathlineto{\pgfpoint{0.75cm}{0cm}}
        \pgfusepath{draw}
    },
    bipoles/oscope/waveform/zero/.code={
        \pgfpathmoveto{\pgfpoint{-0.75cm}{0cm}}
        \pgfpathlineto{\pgfpoint{0.75cm}{0cm}}
        \pgfusepath{draw}
        },%
    bipoles/oscope/waveform/lissajous/.code={%
        \pgfpathellipse{\pgfpoint{0cm}{0cm}}
            {\pgfpoint{0.5cm}{0.35cm}}{\pgfpoint{-0.3cm}{0.2cm}}
        \pgfusepath{draw}
    },
    bipoles/oscope/waveform/none/.code={},%
}
% default waveform (backward compatible)
\ctikzset{bipoles/oscope/waveform/.initial=ramps}

\pgfcircdeclarebipolescaled{instruments}
{
    \anchor{in 1}{\southwest\pgf@y=0.75\pgf@y\pgf@x=0.4\pgf@x}
    \anchor{in 2}{\southwest\pgf@y=0.75\pgf@y\pgf@x=-0.4\pgf@x}
    % put the node text above and centered
    \anchor{text}{\pgfextracty{\pgf@circ@res@up}{\northeast}
        \pgfpoint{-.5\wd\pgfnodeparttextbox}{
            \dimexpr.5\dp\pgfnodeparttextbox+.5\ht\pgfnodeparttextbox+\pgf@circ@res@up\relax
        }
    }
}
{\ctikzvalof{bipoles/oscope/height}}
{oscope}
{\ctikzvalof{bipoles/oscope/height}}
{\ctikzvalof{bipoles/oscope/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfextracty{\pgf@circ@res@up}{\northeast}
    \pgfextractx{\pgf@circ@res@right}{\northeast}
    \pgfextractx{\pgf@circ@res@left}{\southwest}
    \pgfextracty{\pgf@circ@res@down}{\southwest}
    \pgfmathsetlength{\pgf@circ@res@step}{0.25*\pgf@circ@res@up}
    \pgfscope
        \pgfsetcornersarced{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@step}}
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgf@circ@draworfill
    \endpgfscope
    % get the rotation
    \ifpgf@circuit@straightinstruments
        \pgfgettransformentries\a\b\temp\temp\temp\temp
        \pgfmathsetmacro{\rot}{-atan2(\b,\a)}
    \else
        \edef\rot{0}
    \fi
    % and unrotate the scope
    \pgfscope
        \pgftransformrotate{\rot}
        % grid
        \pgfscope
            \pgfsetlinewidth{0.5\pgfstartlinewidth}
            \pgfpathmoveto{\pgfpoint{0.75\pgf@circ@res@left}{0.25\pgf@circ@res@down}}
            % the "almost one" make the grid complete most of the time --- beware of antialiasing
            \pgfpathgrid[stepx=0.995\pgf@circ@res@step, stepy=0.995\pgf@circ@res@step]%
            {\pgfpoint{0.75\pgf@circ@res@left}{0.5\pgf@circ@res@down}}
            {\pgfpoint{0.75\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
            \pgfsetstrokeopacity{0.5}
            \pgfusepath{draw}
        \endpgfscope
        % function displayed
        \pgfscope
            \pgfmathsetmacro{\@@scalex}{\pgf@circ@res@right/1cm}
            \pgfmathsetmacro{\@@scaley}{\pgf@circ@res@up/1cm}
            \pgftransformxscale{\@@scalex}
            \pgftransformyscale{\@@scaley}
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfkeys{\circuitikzbasekey/bipoles/oscope/waveform/\ctikzvalof{bipoles/oscope/waveform}}
        \endpgfscope
    \endpgfscope
}
% generic round meter with always horizontal text, no arrow
\pgfcircdeclarebipolescaled{instruments}
{}
{\ctikzvalof{bipoles/esource/height}}
{rmeter}
{\ctikzvalof{bipoles/esource/height}}
{\ctikzvalof{bipoles/esource/width}}
{
    \pgfpointorigin
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
        \pgf@circ@draworfill
    \endpgfscope
    % draw the text label
    % get the rotation
    \ifpgf@circuit@straightinstruments
        \pgfgettransformentries\a\b\temp\temp\temp\temp
        \pgfmathsetmacro{\rot}{-atan2(\b,\a)}
    \else
        \edef\rot{0}
    \fi
    % and unrotate the scope
    \pgfscope
    \pgf@circ@text@strokecolor
        \pgftransformrotate{\rot}
        \pgftext[center,x=0,y=0]{\ctikzvalof{bipoles/twoport/text}}
    \endpgfscope
}

% generic round meter with always horizontal text, with arrow
\pgfcircdeclarebipolescaled{instruments}
{}
{\ctikzvalof{bipoles/esource/height}}
{rmeterwa}
{\ctikzvalof{bipoles/esource/height}}
{\ctikzvalof{bipoles/esource/width}}
{
    \pgfpointorigin
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
        \pgf@circ@draworfill
    \endpgfscope
    % draw the text label
    % get the rotation
    \ifpgf@circuit@straightinstruments
        \pgfgettransformentries\a\b\temp\temp\temp\temp
        \pgfmathsetmacro{\rot}{-atan2(\b,\a)}
    \else
        \edef\rot{0}
    \fi
    % and unrotate the scope
    \pgfscope
        \pgftransformrotate{\rot}
        \pgf@circ@setcolor
        \pgfsetlinewidth{\pgfstartlinewidth}
        % arrow: create  a center hole to have better visual
        \pgfscope
            % clipping path: first a rectangle bigger then the shape
            % to avoid problems with the line thickness
            \pgfpathrectanglecorners{\pgfpoint{2\pgf@circ@res@left}{2\pgf@circ@res@down}}
            {\pgfpoint{2\pgf@circ@res@right}{2\pgf@circ@res@up}}
            % next open a circle into it
            \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{.6\pgf@circ@res@up}}{\pgfpoint{.6\pgf@circ@res@left}{0}}
            % do the difference and clip before drawing
            \pgfseteorule
            \pgfusepath{clip}
            \pgfsetarrowsend{latexslim}
            % the arrow is better if it has a bit of breath and it's not 45º
            \pgfpathmoveto{\pgfpoint{.8\pgf@circ@res@left}{1.2\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{.8\pgf@circ@res@right}{1.2\pgf@circ@res@up}}
            \pgfusepath{draw}
        \endpgfscope
        \pgf@circ@text@strokecolor
        \pgftext[center]{\ctikzvalof{bipoles/twoport/text}}
    \endpgfscope
}

% generic square meter with always horizontal text
\pgfcircdeclarebipolescaled{instruments}
{
    \anchor{in 1}{\southwest\pgf@y=0.75\pgf@y\pgf@x=0.4\pgf@x}
    \anchor{in 2}{\southwest\pgf@y=0.75\pgf@y\pgf@x=-0.4\pgf@x}
    % put the node text above and centered
    \anchor{text}{\pgfextracty{\pgf@circ@res@up}{\northeast}
        \pgfpoint{-.5\wd\pgfnodeparttextbox}{
            \dimexpr.5\dp\pgfnodeparttextbox+.5\ht\pgfnodeparttextbox+\pgf@circ@res@up\relax
        }
    }
}
{\ctikzvalof{bipoles/smeter/height}}
{smeter}
{\ctikzvalof{bipoles/smeter/height}}
{\ctikzvalof{bipoles/smeter/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfextracty{\pgf@circ@res@up}{\northeast}
    \pgfextractx{\pgf@circ@res@right}{\northeast}
    \pgfextractx{\pgf@circ@res@left}{\southwest}
    \pgfextracty{\pgf@circ@res@down}{\southwest}
    \pgfmathsetlength{\pgf@circ@res@step}{0.25*\pgf@circ@res@up}
    \pgfscope
        \pgfsetcornersarced{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@step}}
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgf@circ@draworfill
    \endpgfscope
    % get the rotation
    \ifpgf@circuit@straightinstruments
        \pgfgettransformentries\a\b\temp\temp\temp\temp
        \pgfmathsetmacro{\rot}{-atan2(\b,\a)}
    \else
        \edef\rot{0}
    \fi
    % and unrotate the scope
    \pgfscope
        \pgftransformrotate{\rot}
        % the metering window
        \pgfscope
            \def\@starta{105}\def\@stopa{75}
            \pgfsetlinewidth{\pgfstartlinewidth}
            \pgftransformshift{\pgfpoint{0pt}{-1.8\pgf@circ@res@up}}
            \pgfpathmoveto{\pgfpointpolar{\@starta}{2\pgf@circ@res@up}}
            \pgfpatharc{\@starta}{\@stopa}{2\pgf@circ@res@up}
            \pgfpathlineto{\pgfpointpolar{\@stopa}{2.5\pgf@circ@res@up}}
            \pgfpatharc{\@stopa}{\@starta}{2.5\pgf@circ@res@up}
            \pgfpathclose
            \pgfpathmoveto{\pgfpointpolar{80}{2\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpointpolar{80}{2.4\pgf@circ@res@up}}
            \pgfusepath{draw}
        \endpgfscope
        \pgf@circ@text@strokecolor
        \pgftext[center, y=0.5\pgf@circ@res@down]{\ctikzvalof{bipoles/twoport/text}}
    \endpgfscope
}

% probes qucs style:
% #1 : name
% #2 : extra code
\long\def\pgfcirc@qucsprobe#1#2{
    \pgfcircdeclarebipolescaled{instruments}
    {
        \anchor{v+}{\southwest\pgf@x=0.6\pgf@x}
        \anchor{v-}{\southwest\pgf@x=-0.6\pgf@x}
        % put the node text above and centered
        \anchor{text}{\pgfextracty{\pgf@circ@res@up}{\northeast}
            \pgfpoint{-.5\wd\pgfnodeparttextbox}{
                \dimexpr.5\dp\pgfnodeparttextbox+.5\ht\pgfnodeparttextbox+\pgf@circ@res@up\relax
            }
        }
    }
    {\ctikzvalof{bipoles/qmeter/depth}}
    {#1}
    {\ctikzvalof{bipoles/qmeter/height}}
    {\ctikzvalof{bipoles/qmeter/width}}
    {
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfextracty{\pgf@circ@res@up}{\northeast}
        \pgfextractx{\pgf@circ@res@right}{\northeast}
        \pgfextractx{\pgf@circ@res@left}{\southwest}
        \pgfextracty{\pgf@circ@res@down}{\southwest}
        \pgfmathsetlength{\pgf@circ@res@step}{0.25*\pgf@circ@res@up}
        \pgfscope
            \pgfscope
                \pgfsetcornersarced{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@step}}
                \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
                \pgf@circ@draworfill
            \endpgfscope
            \def\@starta{103}\def\@stopa{77}
            \pgfsetlinewidth{\pgfstartlinewidth}
            \pgfscope
                \pgftransformshift{\pgfpoint{0pt}{-1.7\pgf@circ@res@up}}
                \pgfpathmoveto{\pgfpointpolar{\@starta}{2.1\pgf@circ@res@up}}
                \pgfpatharc{\@starta}{\@stopa}{2.1\pgf@circ@res@up}
                \pgfpathlineto{\pgfpointpolar{\@stopa}{2.5\pgf@circ@res@up}}
                \pgfpatharc{\@stopa}{\@starta}{2.5\pgf@circ@res@up}
                \pgfpathclose
                \pgfpathmoveto{\pgfpointpolar{83}{2.1\pgf@circ@res@up}}
                \pgfpathlineto{\pgfpointpolar{83}{2.4\pgf@circ@res@up}}
                \pgfusepath{draw}
                \pgf@circ@draworfill
            \endpgfscope
            #2%
        \endpgfscope
    }
}

\pgfcirc@qucsprobe{qiprobe}{
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
    \pgfnode{currarrow}{center}{}{}{}
}

\pgfcirc@qucsprobe{qvprobe}{
    \pgfmathsetlength{\pgf@circ@res@other}{\ctikzvalof{nodes width}*\pgf@circ@scaled@Rlen}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@left}{0pt}}
    \pgfpathcircle{\pgfpoint{.6\pgf@circ@res@left+\pgf@circ@res@other}{0pt}}{\pgf@circ@res@other}
    \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathcircle{\pgfpoint{.6\pgf@circ@res@right-\pgf@circ@res@other}{0pt}}{\pgf@circ@res@other}
    \pgfusepath{draw}
    \pgfscope
        % "+" and "-", drawn so that they scale correctly
        \pgfsetlinewidth{2\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@left+\pgf@circ@res@other}{-1.5\pgf@circ@res@other}}
        \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@left+\pgf@circ@res@other}{-3.5\pgf@circ@res@other}}
        \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@left+0\pgf@circ@res@other}{-2.5\pgf@circ@res@other}}
        \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@left+2\pgf@circ@res@other}{-2.5\pgf@circ@res@other}}
        \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@right+0\pgf@circ@res@other}{-2.5\pgf@circ@res@other}}
        \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right-2\pgf@circ@res@other}{-2.5\pgf@circ@res@other}}
        \pgfusepath{draw}
    \endpgfscope
}

\pgfcirc@qucsprobe{qpprobe}{
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
    \pgfnode{currarrow}{center}{}{}{}
    \pgfmathsetlength{\pgf@circ@res@other}{\ctikzvalof{nodes width}*\pgf@circ@scaled@Rlen}
    \pgfpathcircle{\pgfpoint{.6\pgf@circ@res@left}{-3\pgf@circ@res@other}}{\pgf@circ@res@other}
    \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@left}{-4\pgf@circ@res@other}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathcircle{\pgfpoint{.6\pgf@circ@res@right}{-3\pgf@circ@res@other}}{\pgf@circ@res@other}
    \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@right}{-4\pgf@circ@res@other}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{draw}
    \pgfscope
        % "+" and "-", drawn so that they scale correctly
        \pgfsetlinewidth{2\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@left+3\pgf@circ@res@other}{-2\pgf@circ@res@other}}
        \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@left+3\pgf@circ@res@other}{-4\pgf@circ@res@other}}
        \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@left+2\pgf@circ@res@other}{-3\pgf@circ@res@other}}
        \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@left+4\pgf@circ@res@other}{-3\pgf@circ@res@other}}
        \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@right-4\pgf@circ@res@other}{-3\pgf@circ@res@other}}
        \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right-2\pgf@circ@res@other}{-3\pgf@circ@res@other}}
        \pgfusepath{draw}
    \endpgfscope
}

% current loop for oscope and similar: stylized
\pgfcircdeclarebipolescaled{instruments}
{
    \anchor{i}{\northeast\pgf@x=0pt\relax}
    \anchor{text}{
        \pgfextracty{\pgf@circ@res@up}{\northeast}
        \pgfextractx{\pgf@circ@res@left}{\northeast}
        \pgfpoint{-.5\wd\pgfnodeparttextbox+\pgf@circ@res@left}{
            \dimexpr.5\dp\pgfnodeparttextbox+.5\ht\pgfnodeparttextbox+\pgf@circ@res@up\relax
        }
    }
}
{\ctikzvalof{bipoles/iloop/height}}
{iloop}
{\ctikzvalof{bipoles/iloop/height}}
{\ctikzvalof{bipoles/iloop/width}}
{
    \pgfextracty{\pgf@circ@res@up}{\northeast}
    \pgfextractx{\pgf@circ@res@right}{\northeast}
    \pgf@circ@res@down=-\pgf@circ@res@up
    \pgf@circ@res@left=-\pgf@circ@res@right
    \pgfscope
        \pgfstartlinewidth=\pgflinewidth
        \pgf@circ@setcolor
        % external ellipse
        \pgfscope
            \pgf@circ@setlinewidth{bipoles}{\pgflinewidth}
            % clipping path: first a rectangle bigger then the shape
            % to avoid problems with the line thickness
            \pgfpathrectanglecorners{\pgfpoint{2\pgf@circ@res@left}{2\pgf@circ@res@down}}
            {\pgfpoint{2\pgf@circ@res@right}{2\pgf@circ@res@up}}
            % next the opening to the left
            \pgfpathrectanglecorners{\pgfpoint{2\pgf@circ@res@left}{.1\pgf@circ@res@down}}
            {\pgfpoint{0pt}{.1\pgf@circ@res@up}}
            % do the difference and clip before drawing
            \pgfseteorule
            \pgfusepath{clip}
            \pgfpathellipse{\pgfpointorigin}{
                \pgfpoint{0pt}{0.8\pgf@circ@res@up}}{
            \pgfpoint{0.4\pgf@circ@res@right}{0pt}}
            \pgfusepath{draw}
        \endpgfscope
        % internal wire
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{0.3\pgf@circ@res@right}{0pt}}
        \pgfpathmoveto{\pgfpoint{0.5\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        % and the contact line up
        \pgfpathmoveto{\pgfpoint{0pt}{0.8\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}

% current loop for oscope and similar: real (double connection)
\pgfcircdeclarebipolescaled{instruments}
{
    \anchor{i+}{
        \pgfextracty{\pgf@circ@res@up}{\northeast}
        \pgfextractx{\pgf@circ@res@right}{\northeast}
        \pgf@circ@res@step=0.4\pgf@circ@res@right
        \pgf@circ@res@other=0.8\pgf@circ@res@up
        \pgfpointpolar{105}{\pgf@circ@res@step and \pgf@circ@res@other}
        \pgf@y=\pgf@circ@res@up
    }
    \anchor{i-}{
        \pgfextracty{\pgf@circ@res@up}{\northeast}
        \pgfextractx{\pgf@circ@res@right}{\northeast}
        \pgf@circ@res@step=0.4\pgf@circ@res@right
        \pgf@circ@res@other=0.8\pgf@circ@res@up
        \pgfpointpolar{75}{\pgf@circ@res@step and \pgf@circ@res@other}
        \pgf@y=\pgf@circ@res@up
    }
    \anchor{text}{
        \pgfextracty{\pgf@circ@res@up}{\northeast}
        \pgfextractx{\pgf@circ@res@left}{\northeast}
        \pgfpoint{-.5\wd\pgfnodeparttextbox+\pgf@circ@res@left}{
            \dimexpr.5\dp\pgfnodeparttextbox+.5\ht\pgfnodeparttextbox+\pgf@circ@res@up\relax
        }
    }
}
{\ctikzvalof{bipoles/iloop/height}}
{iloop2}
{\ctikzvalof{bipoles/iloop/height}}
{\ctikzvalof{bipoles/iloop/width}}
{
    \pgfextracty{\pgf@circ@res@up}{\northeast}
    \pgfextractx{\pgf@circ@res@right}{\northeast}
    \pgf@circ@res@down=-\pgf@circ@res@up
    \pgf@circ@res@left=-\pgf@circ@res@right
    % must be the same than internal i+ and i- anchors definition
    \pgf@circ@res@step=0.4\pgf@circ@res@right
    \pgf@circ@res@other=0.8\pgf@circ@res@up
    \def\@plus{\pgfpointpolar{105}{\pgf@circ@res@step and \pgf@circ@res@other}}
    \def\@minus{\pgfpointpolar{75}{\pgf@circ@res@step and \pgf@circ@res@other}}
    \pgfscope
        \pgfstartlinewidth=\pgflinewidth
        \pgf@circ@setcolor
        % external ellipse
        \pgfscope
            \pgf@circ@setlinewidth{bipoles}{\pgflinewidth}
            % clipping path: first a rectangle bigger then the shape
            % to avoid problems with the line thickness
            \pgfpathrectanglecorners{\pgfpoint{2\pgf@circ@res@left}{2\pgf@circ@res@down}}
            {\pgfpoint{2\pgf@circ@res@right}{2\pgf@circ@res@up}}
            % next the opening to the left
            \pgfpathrectanglecorners{\pgfpoint{2\pgf@circ@res@left}{.1\pgf@circ@res@down}}
            {\pgfpoint{0pt}{.1\pgf@circ@res@up}}
            % do the difference and clip before drawing
            \pgfseteorule
            \pgfusepath{clip}
            \pgfpathmoveto{\@plus}
            \pgfpatharc{105}{435}{\pgf@circ@res@step and \pgf@circ@res@other}
            \pgfusepath{draw}
        \endpgfscope
        % internal wire
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{0.3\pgf@circ@res@right}{0pt}}
        \pgfpathmoveto{\pgfpoint{0.5\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        % and the contact line up
        % I use ...left and ---right as temporal lengths here to avoid defining more
        \pgfextractx{\pgf@circ@res@left}{\@plus}
        \pgfextractx{\pgf@circ@res@right}{\@minus}
        \pgfpathmoveto{\@plus}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathmoveto{\@minus}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}
%% currtap
\pgfcircdeclarebipolescaled{instruments}
{
    \savedmacro{\@@dotsize}{\def\@@dotsize{\ctikzvalof{bipoles/currtap/dot size}}}
    \anchor{tap}{\northeast\pgf@x=0pt\pgf@y=\@@dotsize\pgf@y\pgf@y=-\pgf@y}
}
{\ctikzvalof{bipoles/currtap/height}}
{currtap}
{\ctikzvalof{bipoles/currtap/height}}
{\ctikzvalof{bipoles/currtap/height}}
{
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{0.95\pgf@circ@res@left}{0pt}}
    \pgfpatharc{180}{0}{0.95\pgf@circ@res@right}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
    \pgf@circ@subset@color@dash{bipoles/currtap}
    \pgf@circ@subset@thickness{bipoles/currtap}
    \pgfusepath{draw}
    \pgfpathcircle{\pgfpoint{0pt}{0pt}}{\@@dotsize*\pgf@circ@res@up}
    \pgf@circ@subset@fill@or@draw{bipoles/currtap}
}
% %>>>

% Path definitions for Instruments%<<<

\pgfcirc@activate@bipole@simple{l}{ammeter}
\pgfcirc@activate@bipole@simple{l}{ohmmeter}
\pgfcirc@activate@bipole@simple{l}{voltmeter}
\pgfcirc@activate@bipole@simple{l}{oscope}
\pgfcirc@activate@bipole@simple{l}{rmeter}
\pgfcirc@activate@bipole@simple{l}{rmeterwa}
\pgfcirc@activate@bipole@simple{l}{smeter}
\pgfcirc@activate@bipole@simple{l}{iloop}
\pgfcirc@activate@bipole{l}{ilooptwo}{iloop2}{iloop2}
\pgfcirc@activate@bipole@simple{l}{currtap}
\pgfcirc@activate@bipole@simple{l}{qvprobe}
\pgfcirc@activate@bipole@simple{l}{qiprobe}
\pgfcirc@activate@bipole@simple{l}{qpprobe}
% %>>>

%%%%%%%%%%%%%%%%%%%%%%%
%% MECHANICAL SYMBOLS
%%%%%%%%%%%%%%%%%%%%%%%

%% Settings for Mechanical section%<<<1
\ctikzset{/tikz/circuitikz/tripoles/elmech/height/.initial=.8}
\ctikzset{/tikz/circuitikz/tripoles/elmech/width/.initial=.6}
\ctikzset{bipoles/spring/height/.initial=.5}
\ctikzset{bipoles/spring/width/.initial=.5}
\ctikzset{bipoles/inerter/height/.initial=.7}
\ctikzset{bipoles/inerter/width/.initial=.175}
\ctikzset{bipoles/mass/height/.initial=.55}
\ctikzset{bipoles/mass/box height/.initial=.4}
\ctikzset{bipoles/mass/width/.initial=.5}

\ctikzset{bipoles/damper/height/.initial=.35}
\ctikzset{bipoles/damper/length/.initial=.3}
\ctikzset{bipoles/damper/width/.initial=.4}
%%>>>

%% Node shapes Mechanical analog system%<<<
%% mechanical capacitance - stiffness/spring

\pgfcircdeclarebipolescaled{mechanicals}
{}
{\ctikzvalof{bipoles/spring/height}}
{spring}
{\ctikzvalof{bipoles/spring/height}}
{\ctikzvalof{bipoles/spring/width}}{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments

    \pgfmathsetlength{\pgf@circ@res@step}
    {(\ctikzvalof{bipoles/spring/width}*\pgf@circ@scaled@Rlen+\pgfhorizontaltransformationadjustment*.5*\pgflinewidth)/16}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*0.5*\pgflinewidth}{\pgf@circ@res@zero}}
    \pgfsetcornersarced{\pgfpoint{.5\pgf@circ@res@up}{.5\pgf@circ@res@up}}
    \pgf@circ@res@other = \pgf@circ@res@left
    \advance\pgf@circ@res@other by \pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@up}}
    \advance\pgf@circ@res@other by 2\pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@down}}
    \advance\pgf@circ@res@other by 2\pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@up}}
    \advance\pgf@circ@res@other by 2\pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@down}}
    \advance\pgf@circ@res@other by 2\pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@up}}
    \advance\pgf@circ@res@other by 2\pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@down}}
    \advance\pgf@circ@res@other by 2\pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@up}}
    \advance\pgf@circ@res@other by 2\pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@down}}
    \advance\pgf@circ@res@other by \pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@zero}}
    \pgfsetbuttcap
    \pgfsetbeveljoin
    \pgfusepath{stroke}
}

%% mechanical capacitance - inerter
\pgfcircdeclarebipolescaled{mechanicals}
{}
{\ctikzvalof{bipoles/inerter/height}}
{inerter}
{\ctikzvalof{bipoles/inerter/height}}
{\ctikzvalof{bipoles/inerter/width}}
{
    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@draworfill
}


%% mechanical inductance - mass
\pgfcircdeclarebipolescaled{mechanicals}
{}
{\ctikzvalof{bipoles/mass/box height}}
{mass}
{\ctikzvalof{bipoles/mass/height}}
{\ctikzvalof{bipoles/mass/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgftransformationadjustments
    \pgfpathrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        {\pgfpoint{-2\pgf@circ@res@down}{-2\pgf@circ@res@down}}
    \pgf@circ@draworfill

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfsetrectcap
    \pgfsetmiterjoin
    \pgfusepath{stroke}
}

%% mechanical resistor - damper
\pgfcircdeclarebipolescaled{mechanicals}
{}
{\ctikzvalof{bipoles/damper/height}}
{damper}
{\ctikzvalof{bipoles/damper/height}}
{\ctikzvalof{bipoles/damper/width}}
{
    \pgfpathrectanglecorners{\pgfpoint{\ctikzvalof{bipoles/damper/length}\pgf@circ@res@right}{\pgf@circ@res@down}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgf@circ@maybefill

    % line into the damper
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/damper/length}\pgf@circ@res@right}
        {\pgf@circ@res@zero}}
    \pgfusepath{stroke}

    % damper box
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}

    \pgfsetrectcap
    \pgfsetmiterjoin
    \pgfusepath{stroke}

    % damper vertical element
    \pgfpathmoveto{\pgfpoint{\ctikzvalof{bipoles/damper/length}\pgf@circ@res@right}
        {.8\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/damper/length}\pgf@circ@res@right}
        {.8\pgf@circ@res@up}}
    \pgfsetbuttcap
    \pgfusepath{stroke}

}
%% mechanical viscoelastic element, suggested by @alex
%% in https://tex.stackexchange.com/questions/484268/combined-spring-damper-in-circuitikz
\pgfcircdeclarebipolescaled{mechanicals}
{}                                   % extra anchors
{\ctikzvalof{bipoles/damper/height}} % depth (under the path line)
{viscoe}                             % name
{\ctikzvalof{bipoles/damper/height}} % height (above the path line)
{\ctikzvalof{bipoles/damper/width}}  % width
{ % draw the bipole
    \pgfpathrectanglecorners{\pgfpoint{\ctikzvalof{bipoles/damper/length}\pgf@circ@res@right}{\pgf@circ@res@down}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgf@circ@maybefill

    % spring into the damper
    \pgfscope
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfsetcornersarced{\pgfpoint{.25\pgf@circ@res@up}{.25\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.75\pgf@circ@res@left}{.75\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.5\pgf@circ@res@left}{-.75\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.25\pgf@circ@res@left}{.75\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{-.75\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/damper/length}\pgf@circ@res@right}{.75\pgf@circ@res@up}}
        \pgfusepath{stroke}
    \endpgfscope
    % damper box
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}

    \pgfsetrectcap
    \pgfsetmiterjoin
    \pgfusepath{stroke}

    % damper vertical element
    \pgfpathmoveto{\pgfpoint{\ctikzvalof{bipoles/damper/length}\pgf@circ@res@right}
        {.8\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/damper/length}\pgf@circ@res@right}
        {.8\pgf@circ@res@up}}
    \pgfsetbuttcap
    \pgfusepath{stroke}

}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% electromechanical device (motor/generator)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\pgfdeclareshape{elmech}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{electromechanicals}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor\northwest{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/elmech/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/elmech/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{center}{
        \pgfpointorigin
    }
    \anchor{text}{
        \pgfpointorigin
        \advance \pgf@x by -.5\wd\pgfnodeparttextbox
        \advance \pgf@y by -.5\ht\pgfnodeparttextbox
    }
    \anchor{left}{%
        \northwest
        \pgf@y=0pt
    }
    \anchor{right}{%
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{top}{
        \northwest
        \pgf@x=0pt
    }
    \anchor{pathstart}{
        \northwest
        \pgf@x=0pt
    }
    \anchor{pathend}{
        \northwest
        \pgf@x=0pt
        \pgf@y=-\pgf@y
    }
    \anchor{bottom}{
        \northwest
        \pgf@x=0pt
        \pgf@y=-\pgf@y
    }
    \anchor{center}{
        \pgf@y=0pt
        \pgf@x=0pt
    }
    \anchor{east}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{west}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{south}{
        \northwest
        \pgf@x=0pt
        \pgf@y=-\pgf@y
    }
    \anchor{north}{
        \northwest
        \pgf@x=0pt
    }
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northwest \pgf@x=-\pgf@x }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
    \anchorborder{%
        \@tempdima=\pgf@x\@tempdimb=\pgf@y
        \northwest\pgf@circ@res@other=-\pgf@x
        \pgfpointborderellipse{\pgfqpoint{\@tempdima}{\@tempdimb}}{\pgfqpoint{\pgf@circ@res@other}{\pgf@circ@res@other}}
    }
    \anchor{block north west}{\northwest\pgf@x=0.5\pgf@x}
    \anchor{block south west}{\northwest\pgf@x=0.5\pgf@x\pgf@y=-\pgf@y}
    \anchor{block north east}{\northwest\pgf@x=-0.5\pgf@x}
    \anchor{block south east}{\northwest\pgf@x=-0.5\pgf@x\pgf@y=-\pgf@y}
    \anchor{block up right}{
        \northwest
        % remember that pgf@x is negative
        % center of the block is at 0.5*H+W*cos(30)/2
        \pgf@y=\dimexpr0.5\pgf@y - 0.433\pgf@x\relax
        \pgf@x=-0.5\pgf@x
    }
    \anchor{block up left}{
        \northwest
        % remember that pgf@x is negative
        % center of the block is at 0.5*H+W*cos(30)/2
        \pgf@y=\dimexpr0.5\pgf@y - 0.433\pgf@x\relax
        \pgf@x=0.5\pgf@x
    }
    \anchor{block down right}{
        \northwest
        % remember that pgf@x is negative
        % center of the block is at 0.5*H+W*cos(30)/2
        \pgf@y=\dimexpr0.5\pgf@y - 0.433\pgf@x\relax
        \pgf@y=-\pgf@y
        \pgf@x=-0.5\pgf@x
    }
    \anchor{block down left}{
        \northwest
        % remember that pgf@x is negative
        % center of the block is at 0.5*H+W*cos(30)/2
        \pgf@y=\dimexpr0.5\pgf@y - 0.433\pgf@x\relax
        \pgf@y=-\pgf@y
        \pgf@x=0.5\pgf@x
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{tripoles/elmech/width}\pgf@circ@scaled@Rlen
        \pgf@circ@res@up=\ctikzvalof{tripoles/elmech/height}\pgf@circ@scaled@Rlen
        \pgfscope
            \pgfstartlinewidth=\pgflinewidth
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfscope % clip the bar: whole size minus the circle
                \pgfpathrectanglecorners{\pgfpoint{-.5\pgf@circ@res@step}{-.5\pgf@circ@res@up}}{\pgfpoint{.5\pgf@circ@res@step}{.5\pgf@circ@res@up}}
                \pgfpathcircle{\pgfpoint{0}{0}} {0.5\pgf@circ@res@step}
                \pgfseteorule
                \pgfusepath{clip}
                \pgfpathrectangle{\pgfpoint{-.25\pgf@circ@res@step}{-.5\pgf@circ@res@up}}{\pgfpoint{.5\pgf@circ@res@step}{\pgf@circ@res@up}}
                \pgf@circ@fill@strokecolor
                \pgfusepath{fill, draw}
            \endpgfscope
            \pgfpathcircle{\pgfpoint{0}{0}} {0.5\pgf@circ@res@step}
            \ifx\tikz@fillcolor\pgfutil@empty
                % set the default fill color to white
                \pgfsetfillcolor{white}
                % ...but override it if the class is defined!
                \pgf@circ@setifdefinedfill{draw, fill}{draw, fill}
            \else
                \pgfsetfillcolor{\tikz@fillcolor}
                \pgfusepath{draw, fill}
            \fi
        \endpgfscope
    }
}

% %>>>

%% Path definitions for Mechanical%<<<

\pgf@circ@definetranspath{elmech}
\pgfcirc@activate@bipole@simple{l}{spring}
\pgfcirc@activate@bipole@simple{l}{inerter}
\pgfcirc@activate@bipole@simple{l}{mass}
\pgfcirc@activate@bipole@simple{l}{damper}
\pgfcirc@activate@bipole@simple{l}{viscoe}
% %>>>

%%%%%%%%%%%%%%%%%%%%%%%%%
%% Miscellaneous bipoles
%%%%%%%%%%%%%%%%%%%%%%%%%

% settings for microphone, loudspeaker, fuses and misc%<<<1

\ctikzset{bipoles/loudspeaker/height/.initial=.8}
\ctikzset{bipoles/loudspeaker/depth/.initial=.3}
\ctikzset{bipoles/loudspeaker/width/.initial=.8}
\ctikzset{bipoles/mic/height/.initial=1.2}
\ctikzset{bipoles/mic/depth/.initial=.1}
\ctikzset{bipoles/mic/width/.initial=.8}%
\ctikzset{bipoles/tlmic/width/.initial=.5}% it MUST be mic width *5/8
\ctikzset{bipoles/mic/bar thickness/.initial=1}

% arresters, fuses, relais, lamps, etc

\ctikzset{bipoles/european gas filled surge arrester/height/.initial=.30}
\ctikzset{bipoles/european gas filled surge arrester/width/.initial=.80}
\ctikzset{bipoles/european gas filled surge arrester/inside/.initial=.30}
\ctikzset{bipoles/american gas filled surge arrester/height/.initial=.60}
\ctikzset{bipoles/american gas filled surge arrester/width/.initial=.60}
\ctikzset{bipoles/american gas filled surge arrester/inside/.initial=.15}
\ctikzset{bipoles/american gas filled surge arrester/dot x/.initial=.25}
\ctikzset{bipoles/american gas filled surge arrester/dot y/.initial=.45}
% fuses: normal, asymmetric, wiggle
\ctikzset{bipoles/american gas filled surge arrester/size/.initial=.1}
\ctikzset{bipoles/fuse/height/.initial=.20}
\ctikzset{bipoles/fuse/width/.initial=.50}
\ctikzset{bipoles/afuse/height/.initial=.20}
\ctikzset{bipoles/afuse/width/.initial=.50}
\ctikzset{bipoles/lamp/height/.initial=.60}
\ctikzset{bipoles/lamp/width/.initial=.60}
\ctikzset{bipoles/wfuse/height/.initial=.20}
\ctikzset{bipoles/wfuse/width/.initial=.50}
\ctikzset{bipoles/wfuse/shape/.initial=ocirc}
\newif\ifpgf@circ@wfuse@dots\pgf@circ@wfuse@dotstrue
\ctikzset{bipoles/wfuse/dots/.is choice}
\ctikzset{bipoles/wfuse/dots/.is if=pgf@circ@wfuse@dots}
%
\ctikzset{bipoles/relais/height/.initial=.8}
\ctikzset{bipoles/relais/width/.initial=.3}
%
\ctikzset{bipoles/bulb/height/.initial=.8}
\ctikzset{bipoles/bulb/width/.initial=.8}
% suggested by @bogger33, see https://github.com/circuitikz/circuitikz/issues/793
\ctikzset{bipoles/neonlampcc/height/.initial=.60}
\ctikzset{bipoles/neonlampac/height/.initial=.60}
\pgf@circ@declare@family@arrows{sparkgap}
\newif\ifpgf@sparkgap@dot
\newif\ifpgf@sparkgap@circle
\ctikzset{sparkgap/circle/.is if=pgf@sparkgap@circle}
\ctikzset{sparkgap/dot/.is if=pgf@sparkgap@dot}
\ctikzset{sparkgap/gap/.initial=.05}
\ctikzset{bipoles/sparkgap/height/.initial=.60}
%
\ctikzset{bipoles/squid/height/.initial=.60}
\ctikzset{bipoles/squid/width/.initial=.60}
\ctikzset{bipoles/barrier/height/.initial=.60}
\ctikzset{bipoles/barrier/width/.initial=.60}
\ctikzset{bipoles/openbarrier/gap/.initial=0.5}
\ctikzset{bipoles/thermocouple/height/.initial=.250}
\ctikzset{bipoles/thermocouple/height 2/.initial=.60}
\ctikzset{bipoles/thermocouple/width/.initial=.140}
\newif\ifpgf@circuit@europeangfsurgearrester
\ctikzset{gas filled surge arrester choice/.is choice}
\ctikzset{gas filled surge arrester choice/european/.code= {\pgf@circuit@europeangfsurgearrestertrue}}
\ctikzset{gas filled surge arrester choice/american/.code= {\pgf@circuit@europeangfsurgearresterfalse}}

\tikzset{american gas filled surge arrester set/.style = {\circuitikzbasekey/gas filled surge arrester choice=american}}
\tikzset{european gas filled surge arrester set/.style = {\circuitikzbasekey/gas filled surge arrester choice=european}}
%%>>>

%% Node shapes for miscellaneous symbols %<<<
%% loudspeaker and microphone

\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/loudspeaker/depth}}
{loudspeaker}
{\ctikzvalof{bipoles/loudspeaker/height}}
{\ctikzvalof{bipoles/loudspeaker/width}}{

    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{.4\pgf@circ@res@up}}
    {\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathmoveto{\pgfpoint{0.5\pgf@circ@res@left}{.4\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.8\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.8\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@right}{.4\pgf@circ@res@up}}
    \pgfpathclose
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgf@circ@draworfill
}

\def\pgf@circ@draw@mic@bar#1{%relative length of the bar
    \pgfsetroundcap
    \pgfsetlinewidth{\ctikzvalof{bipoles/mic/bar thickness}\pgflinewidth}%
    % adjust the vertical position; the symbol looks better if the circle touch the bar
    \pgfpathmoveto{\pgfpoint{#1\pgf@circ@res@left}{\pgf@circ@res@up+0.4\pgflinewidth}}
    \pgfpathlineto{\pgfpoint{#1\pgf@circ@res@right}{\pgf@circ@res@up+0.4\pgflinewidth}}
    \pgfusepath{draw}
}

\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/mic/depth}}
{mic}
{\ctikzvalof{bipoles/mic/height}}
{\ctikzvalof{bipoles/mic/width}}{

    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathcircle{\pgfpoint{0pt}{.6\pgf@circ@res@up}}{.4\pgf@circ@res@up}
        \pgf@circ@draworfill
        \pgf@circ@draw@mic@bar{.6}
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{-.2\pgf@circ@res@up}{0pt}}
    % 0.25358 is 0.6-0.4*cos(30)
    \pgfpathlineto{\pgfpoint{-.2\pgf@circ@res@up}{.25358\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{.2\pgf@circ@res@up}{.25358\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{.2\pgf@circ@res@up}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
}
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/tlmic/width}}
{tlmic}
{\ctikzvalof{bipoles/tlmic/width}}
{\ctikzvalof{bipoles/tlmic/width}}{

    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathcircle{\pgfpoint{0pt}{0pt}}{\pgf@circ@res@up}
    \pgf@circ@draworfill
    \pgf@circ@draw@mic@bar{1}
}

%% european gas filled surge arrester
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/european gas filled surge arrester/height}}
{european gas filled surge arrester}
{\ctikzvalof{bipoles/european gas filled surge arrester/height}}
{\ctikzvalof{bipoles/european gas filled surge arrester/width}}
{

    \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgf@circ@draworfill

    \pgfscope
        \pgfsetarrowsend{latexslim}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/european gas filled surge arrester/inside}\pgf@circ@res@left}{0pt}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfusepath{draw}

    \endpgfscope
}

%% american gas filled surge arrester
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/american gas filled surge arrester/height}}
{american gas filled surge arrester}
{\ctikzvalof{bipoles/american gas filled surge arrester/height}}
{\ctikzvalof{bipoles/american gas filled surge arrester/width}}{

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpointorigin \pgf@circ@res@other =  \pgf@x  \advance \pgf@circ@res@other by -\pgf@circ@res@up
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@zero}}
    \pgfusepath{draw}

    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathcircle{\pgfpointorigin}{.9\pgf@circ@res@up}
        \pgf@circ@draworfill
    \endpgfscope

    \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfusepath{draw}

    \pgfscope
        \pgfsetarrowsend{latex}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/american gas filled surge arrester/inside}\pgf@circ@res@right}{\pgf@circ@res@zero}}
        \pgfusepath{draw}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/american gas filled surge arrester/inside}\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgfusepath{draw}
    \endpgfscope{}

    \pgfpathcircle{\pgfpoint{\ctikzvalof{bipoles/american gas filled surge arrester/dot x}\pgf@circ@res@left}{\ctikzvalof{bipoles/american gas filled surge arrester/dot y}\pgf@circ@res@down}}{\ctikzvalof{bipoles/american gas filled surge arrester/size}\pgf@circ@res@down}
    \pgfusepath{fill}
}

%% thermocouple
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/thermocouple/height 2}}
{thermocouple}
{\ctikzvalof{bipoles/thermocouple/height}}
{\ctikzvalof{bipoles/thermocouple/width}}
{
    \pgfsetrectcap
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{.5\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{.5\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0}}
    \pgfusepath{draw}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfsetroundcap
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{.5\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0}{\pgf@circ@res@down}}
    \pgfusepath{draw}
}
%% fuse
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/fuse/height}}
{fuse}
{\ctikzvalof{bipoles/fuse/height}}
{\ctikzvalof{bipoles/fuse/width}}
{
    \pgfscope
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@draworfill
    \endpgfscope

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0}}
    \pgfusepath{draw}

}
%% asymmetric fuse
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/afuse/height}}
{afuse}
{\ctikzvalof{bipoles/afuse/height}}
{\ctikzvalof{bipoles/afuse/width}}
{
    \pgfscope
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgf@circ@draworfill
    \endpgfscope

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0}}
    \pgfusepath{draw}

    \pgfpathrectanglecorners{\pgfpoint{.7\pgf@circ@res@right}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgf@circ@fill@strokecolor
    \pgfusepath{stroke,fill}
}
%% wiggly fuse
\pgfcircdeclarebipolescaled{misc}
{
    \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
    \savedmacro{\cshape}{\def\cshape{\ctikzvalof{bipoles/wfuse/shape}}}
}
{\ctikzvalof{bipoles/wfuse/height}}
{wfuse}
{\ctikzvalof{bipoles/wfuse/height}}
{\ctikzvalof{bipoles/wfuse/width}}
{
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpatharc{0}{180}{.5\pgf@circ@res@left}
    \pgfpatharc{0}{-180}{.5\pgf@circ@res@left}
    \pgfusepath{draw}
    \ifpgf@circ@wfuse@dots
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfnode{\cshape}{center}{}{\thisshape-left}{\pgfusepath{draw}}
        \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
        \pgfnode{\cshape}{center}{}{\thisshape-right}{\pgfusepath{draw}}
    \fi
}

%% Relais
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/relais/height}}
{relais}
{\ctikzvalof{bipoles/relais/height}}
{\ctikzvalof{bipoles/relais/width}}
{
	\pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
	\pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
	\pgf@circ@draworfill
	\pgfscope
	\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
	\pgfusepath{draw}
	\endpgfscope
}

%% SQUID added by Cor Molenaar 5 March 2010
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/squid/height}}
{squid}
{\ctikzvalof{bipoles/squid/height}}
{\ctikzvalof{bipoles/squid/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgfpathmoveto{\pgfpoint{0.35*\pgf@circ@res@left}{1.35*\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.35*\pgf@circ@res@right}{0.65*\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{0.35*\pgf@circ@res@left}{0.65*\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.35*\pgf@circ@res@right}{1.35*\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{0.35*\pgf@circ@res@left}{1.35*\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.35*\pgf@circ@res@right}{0.65*\pgf@circ@res@down}}
    \pgfpathmoveto{\pgfpoint{0.35*\pgf@circ@res@left}{0.65*\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.35*\pgf@circ@res@right}{1.35*\pgf@circ@res@down}}

    \pgfusepath{draw}
}

% Generic barrier added by Cor Molenaar 5 March 2010
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/barrier/height}}
{barrier}
{\ctikzvalof{bipoles/barrier/height}}
{\ctikzvalof{bipoles/barrier/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{0.35*\pgf@circ@res@left}{0.35*\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.35*\pgf@circ@res@right}{0.35*\pgf@circ@res@down}}
    \pgfpathmoveto{\pgfpoint{0.35*\pgf@circ@res@left}{0.35*\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.35*\pgf@circ@res@right}{0.35*\pgf@circ@res@up}}

    \pgfusepath{draw}
}

%
% open version of the barrier symbol
% suggested by Radványi Patrik Tamás <patrikradvanyi@gmail.com>
%
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/barrier/height}}
{openbarrier}
{\ctikzvalof{bipoles/barrier/height}}
{\ctikzvalof{bipoles/barrier/width}}
{
    % this is set with normal wire linewidth
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/openbarrier/gap}*\pgf@circ@res@left}{0pt}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/openbarrier/gap}*\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}

    % do the cross part
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{0.35*\pgf@circ@res@left}{0.35*\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.35*\pgf@circ@res@right}{0.35*\pgf@circ@res@down}}
    \pgfpathmoveto{\pgfpoint{0.35*\pgf@circ@res@left}{0.35*\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.35*\pgf@circ@res@right}{0.35*\pgf@circ@res@up}}

    \pgfusepath{draw}
}
%% Lamp
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/lamp/height}}
{lamp}
{\ctikzvalof{bipoles/lamp/height}}
{\ctikzvalof{bipoles/lamp/width}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}

    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill
    \pgfpathmoveto{\pgfpoint{.7071*\pgf@circ@res@left}{.7071*\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{.7071*\pgf@circ@res@right}{.7071*\pgf@circ@res@down}}
    \pgfpathmoveto{\pgfpoint{.7071*\pgf@circ@res@left}{.7071*\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{.7071*\pgf@circ@res@right}{.7071*\pgf@circ@res@up}}
    \pgfusepath{draw}
}

%% bulb
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/bulb/height}}
{bulb}
{\ctikzvalof{bipoles/bulb/height}}
{\ctikzvalof{bipoles/bulb/width}}
{%
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{0.8\pgf@circ@res@up}}{\pgfpoint{0.8\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpathlineto{\pgfpoint{0.4\pgf@circ@res@left}{\pgf@circ@res@zero}}
    \pgfpatharc{0}{-180}{0.4*\pgf@circ@res@left}
    \pgfsetbeveljoin
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
    \pgfusepath{draw}
}%
% neon lamps, suggested by @bogger33 https://github.com/circuitikz/circuitikz/issues/793
% implemented by Romano
% double-cathode (capacitor) style
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/neonlampcc/height}}
{neonlampcc}
{\ctikzvalof{bipoles/neonlampcc/height}}
{\ctikzvalof{bipoles/neonlampcc/height}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill
    %% leads in
    \pgfsetlinewidth{\pgfstartlinewidth}
    \def\@@w{0.2}\def\@@h{0.6}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{\@@w\pgf@circ@res@left}{0pt}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\@@w\pgf@circ@res@right}{0pt}}
    %% "capacitor style" symbol
    \pgfusepath{draw}
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\@@w\pgf@circ@res@right}{\@@h\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\@@w\pgf@circ@res@right}{\@@h\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\@@w\pgf@circ@res@left}{\@@h\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\@@w\pgf@circ@res@left}{\@@h\pgf@circ@res@up}}
    \pgfusepath{draw}
    %% dot
    \pgftransformshift{\pgfpoint{\@@w\pgf@circ@res@left-3*\ctikzvalof{nodes width}\pgf@circ@Rlen}
        {\@@h\pgf@circ@res@down + 2*\ctikzvalof{nodes width}\pgf@circ@Rlen}}
    \pgfnode{circ}{center}{}{}{\pgfusepath{draw,fill}}
}
% anode-cathode style
\pgfcircdeclarebipolescaled{misc}
{}
{\ctikzvalof{bipoles/neonlampac/height}}
{neonlampac}
{\ctikzvalof{bipoles/neonlampac/height}}
{\ctikzvalof{bipoles/neonlampac/height}}
{
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
    \pgf@circ@draworfill
    %% leads in
    \pgfsetlinewidth{\pgfstartlinewidth}
    \def\@@w{0.5}\def\@@h{0.5}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{\@@w\pgf@circ@res@left}{0pt}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\@@w\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
    %% one terminal is a straight plate
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\@@w\pgf@circ@res@left}{\@@h\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\@@w\pgf@circ@res@left}{\@@h\pgf@circ@res@up}}
    \pgfusepath{draw}
    %% the other is an "ocirc" shape
    \pgftransformshift{\pgfpoint{\@@w\pgf@circ@res@right}{0pt}}
    \pgfnode{ocirc}{center}{}{}{\pgfusepath{draw,fill}}
    %% dot
    \pgftransformshift{\pgfpoint{-\@@w\pgf@circ@res@right}{\@@h\pgf@circ@res@down}}
    \pgfnode{circ}{center}{}{}{\pgfusepath{draw,fill}}
}
% spark gap, suggested by @bogger33 https://github.com/circuitikz/circuitikz/issues/800
\pgfcircdeclarebipolescaled{misc}
{
    \savedmacro{\changeh}{\edef\changeh{\ifpgf@sparkgap@circle 1 \else 0.5 \fi}}
    \pgfcirc@border@extend@updown{\changeh}{\changeh}
}
{\ctikzvalof{bipoles/sparkgap/height}}
{sparkgap}
{\ctikzvalof{bipoles/sparkgap/height}}
{\ctikzvalof{bipoles/sparkgap/height}}{
    % circle (if requested)
    \pgfscope
        \ifpgf@sparkgap@circle
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfpathcircle{\pgfpointorigin}{\pgf@circ@res@up}
            \pgf@circ@draworfill
        \fi
    \endpgfscope
    % arrows
    \pgfscope
        \pgfcirc@set@arrows{sparkgap}{}{Triangle[scale=2]}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{sparkgap/gap}\pgf@circ@res@right}{0pt}}
        \pgfusepath{draw}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{sparkgap/gap}\pgf@circ@res@left}{0pt}}
        \pgfusepath{draw}
    \endpgfscope{}
    % dot (if requested)
    \ifpgf@sparkgap@dot
        \pgftransformshift{\pgfpoint
            {\ctikzvalof{sparkgap/gap}\pgf@circ@res@left-1*\ctikzvalof{nodes width}\pgf@circ@Rlen}
            {-4*\ctikzvalof{nodes width}\pgf@circ@Rlen}}
        \pgfnode{circ}{center}{}{}{\pgfusepath{draw,fill}}
    \fi
}

%>>>

%% Path definitions for Miscellaneous%<<<

\pgfcirc@activate@bipole@simple{l}{lamp}
\pgfcirc@activate@bipole@simple{l}{neonlampcc}
\pgfcirc@activate@bipole@simple{l}{neonlampac}
\pgfcirc@activate@bipole@simple{l}{sparkgap}
\pgfcirc@activate@bipole@simple{l}{bulb}
\pgfcirc@activate@bipole@simple{l}{squid}
\pgfcirc@activate@bipole@simple{l}{barrier}
\pgfcirc@activate@bipole@simple{l}{openbarrier}
\pgfcirc@activate@bipole@simple{l}{thermocouple}
\pgfcirc@activate@bipole@simple{l}{fuse}
\pgfcirc@activate@bipole{l}{afuse}{afuse}{asymmetric fuse}
\pgfcirc@style@to@style{asymmetric fuse}{afuse}
\pgfcirc@activate@bipole@simple{l}{wfuse}
\pgfcirc@activate@bipole{l}{wfuse}{wfuse}{wiggly fuse}
\pgfcirc@activate@bipole@simple{l}{relais}
\def\pgf@circ@gfsurgearrester@path#1{\ifpgf@circuit@europeangfsurgearrester\pgf@circ@europeangfsurgearrester@path{#1}\else\pgf@circ@americangfsurgearrester@path{#1}\fi}
\pgfcirc@activate@bipole{l}{europeangfsurgearrester}{european gas filled surge arrester}{european gas filled surge arrester}
\pgfcirc@activate@bipole{l}{americangfsurgearrester}{american gas filled surge arrester}{american gas filled surge arrester}
\pgfcirc@path@to@style{l}{gfsurgearrester}{gas filled surge arrester}{}
\pgfcirc@path@to@style{l}{gfsurgearrester}{gf surge arrester}{}
\pgfcirc@activate@bipole@simple{l}{mic}
\pgfcirc@activate@bipole@simple{l}{tlmic}
\pgfcirc@activate@bipole@simple{l}{loudspeaker}
% %>>>

%% Buzzer and reverse buzzer %<<<
\ctikzset{bipoles/buzzer/height/.initial=0.6}
\ctikzset{bipoles/buzzer/width/.initial=.4}%
\ctikzset{bipoles/buzzer/span/.initial=.6}%

\pgfcircdeclarebipolescaled{misc}
{}
{0}
{buzzer}
{\ctikzvalof{bipoles/buzzer/height}}
{\ctikzvalof{bipoles/buzzer/width}}{
    % this is the height of the semicircle
    \pgf@circ@res@other=\dimexpr\pgf@circ@res@up-\pgf@circ@res@right\relax
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@other}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@other}}
        \pgfpatharc{0}{180}{\pgf@circ@res@right}
        \pgfpathclose
        \pgf@circ@draworfill
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\ctikzvalof{bipoles/buzzer/span}*\pgf@circ@res@left}{\pgf@circ@res@other}}
    \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/buzzer/span}*\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathmoveto{\pgfpoint{\ctikzvalof{bipoles/buzzer/span}*\pgf@circ@res@right}{\pgf@circ@res@other}}
    \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/buzzer/span}*\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
}
\pgfcirc@activate@bipole@simple{l}{buzzer}
%
\pgfcircdeclarebipolescaled{misc}
{}
{0}
{rbuzzer}
{\ctikzvalof{bipoles/buzzer/height}}
{\ctikzvalof{bipoles/buzzer/width}}{
    % this is the height of the semicircle
    \pgf@circ@res@other=\dimexpr\pgf@circ@res@up-\pgf@circ@res@right\relax
    % this is the height where the pins touch the semicircle
    \pgfmathsetlength\pgf@circ@res@temp{\pgf@circ@res@up-
        \pgf@circ@res@right*sqrt(1-\ctikzvalof{bipoles/buzzer/span}*\ctikzvalof{bipoles/buzzer/span})}
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpatharc{0}{-180}{\pgf@circ@res@right}
        \pgfpathclose
        \pgf@circ@draworfill
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\ctikzvalof{bipoles/buzzer/span}*\pgf@circ@res@left}{\pgf@circ@res@temp}}
    \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/buzzer/span}*\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathmoveto{\pgfpoint{\ctikzvalof{bipoles/buzzer/span}*\pgf@circ@res@right}{\pgf@circ@res@temp}}
    \pgfpathlineto{\pgfpoint{\ctikzvalof{bipoles/buzzer/span}*\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfusepath{draw}
}
\pgfcirc@activate@bipole@simple{l}{rbuzzer}
% %>>>

% end of pgfcircbipoles.tex
% vim: set fdm=marker fmr=%<<<,%>>>:
%%%---------- close: tex/pgfcircbipoles
%%%%%%%%%%% Springe nach tex/pgfcirctripoles
%%%---------- open: tex/pgfcirctripoles.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Tripoles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Logic Ports
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Settings for Logic ports%<<<1
%% beware that the third option is in IEEE ports in pgfcircmultipoles.tex

% switches for logic gates
%
\pgfkeys{/tikz/number inputs/.initial=0}
\pgfkeys{/tikz/number inputs/.default=0}
% by default, use the default font (and color, etc.)
\ctikzset{european ports font/.initial={}}
\newif\ifpgf@circuit@europeanlogicport
\ctikzset{logic ports/.is choice}
\ctikzset{logic ports/european/.code= {\pgf@circuit@europeanlogicporttrue
    \tikzset{and port/.style={shape=european and port}}%
    \tikzset{or port/.style={shape=european or port}}%
    \tikzset{xor port/.style={shape=european xor port}}%
    \tikzset{buffer port/.style={shape=european buffer port}}%
    \tikzset{not port/.style={shape=european not port}}%
    \tikzset{nand port/.style={shape=european nand port}}%
    \tikzset{nor port/.style={shape=european nor port}}%
    \tikzset{xnor port/.style={shape=european xnor port}}%
    \tikzset{blank port/.style={shape=european blank port}}%
    \tikzset{blank not port/.style={shape=european blank not port}}%
    % there is no Schmitt ports in european style (yet)
    \tikzset{schmitt port/.style={shape=schmitt}}%
    \tikzset{invschmitt port/.style={shape=invschmitt}}%
}}
\ctikzset{logic ports/american/.code= {\pgf@circuit@europeanlogicportfalse
    \tikzset{and port/.style={shape=american and port}}%
    \tikzset{or port/.style={shape=american or port}}%
    \tikzset{xor port/.style={shape=american xor port}}%
    \tikzset{buffer port/.style={shape=american buffer port}}%
    \tikzset{not port/.style={shape=american not port}}%
    \tikzset{nand port/.style={shape=american nand port}}%
    \tikzset{nor port/.style={shape=american nor port}}%
    \tikzset{xnor port/.style={shape=american xnor port}}%
    \tikzset{schmitt port/.style={shape=schmitt}}%
    \tikzset{invschmitt port/.style={shape=invschmitt}}%
    %%% there are no blank ports for american (no sense to have them)
    \tikzset{blank port/.style={shape=european blank port}}%
    \tikzset{blank not port/.style={shape=european blank not port}}%
}}

\ctikzset{logic ports origin/.is choice}
\ctikzset{logic ports origin/legacy/.code={
    \ctikzset{tripoles/american and port/origin/.initial=0.8}%
    \ctikzset{tripoles/american nand port/origin/.initial=0.8}%
    \ctikzset{tripoles/american nor port/origin/.initial=0.8}%
    \ctikzset{tripoles/american or port/origin/.initial=0.8}%
    \ctikzset{tripoles/american xor port/origin/.initial=0.8}%
    \ctikzset{tripoles/american xnor port/origin/.initial=0.8}%
    \ctikzset{tripoles/european and port/origin/.initial=0.8}%
    \ctikzset{tripoles/european nand port/origin/.initial=0.8}%
    \ctikzset{tripoles/european or port/origin/.initial=0.8}%
    \ctikzset{tripoles/european nor port/origin/.initial=0.8}%
    \ctikzset{tripoles/european xor port/origin/.initial=0.8}%
    \ctikzset{tripoles/european xnor port/origin/.initial=0.8}%
    \ctikzset{tripoles/european buffer port/origin/.initial=0.8}%
    \ctikzset{tripoles/european not port/origin/.initial=0.8}%
    \ctikzset{tripoles/european blank port/origin/.initial=0.8}%
    \ctikzset{tripoles/european blank not port/origin/.initial=0.8}%
    }%
}
\ctikzset{logic ports origin/center/.code={%
    \ctikzset{tripoles/american and port/origin/.initial=0}%
    \ctikzset{tripoles/american nand port/origin/.initial=0}%
    \ctikzset{tripoles/american nor port/origin/.initial=0}%
    \ctikzset{tripoles/american or port/origin/.initial=0}%
    \ctikzset{tripoles/american xor port/origin/.initial=0}%
    \ctikzset{tripoles/american xnor port/origin/.initial=0}%
    \ctikzset{tripoles/european and port/origin/.initial=0}%
    \ctikzset{tripoles/european nand port/origin/.initial=0}%
    \ctikzset{tripoles/european or port/origin/.initial=0}%
    \ctikzset{tripoles/european nor port/origin/.initial=0}%
    \ctikzset{tripoles/european xor port/origin/.initial=0}%
    \ctikzset{tripoles/european xnor port/origin/.initial=0}%
    \ctikzset{tripoles/european buffer port/origin/.initial=0}%
    \ctikzset{tripoles/european not port/origin/.initial=0}%
    \ctikzset{tripoles/european blank port/origin/.initial=0}%
    \ctikzset{tripoles/european blank not port/origin/.initial=0}%
    }%
}

\newif\ifpgfcirc@roundy@or@shapes\pgfcirc@roundy@or@shapesfalse
\ctikzset{american or shape/.is choice}
\ctikzset{american or shape/roundy/.code={\pgfcirc@roundy@or@shapestrue}}
\ctikzset{american or shape/pointy/.code={\pgfcirc@roundy@or@shapesfalse}}

\newif\ifpgfcirc@draw@input@leads\pgfcirc@draw@input@leadstrue
\ctikzset{logic ports draw input leads/.is choice}
\ctikzset{logic ports draw input leads/true/.code={\pgfcirc@draw@input@leadstrue}}
\ctikzset{logic ports draw input leads/false/.code={\pgfcirc@draw@input@leadsfalse}}
\tikzset{input leads/.code={\pgfcirc@draw@input@leadstrue}}
\tikzset{no input leads/.code={\pgfcirc@draw@input@leadsfalse}}

\newif\ifpgfcirc@draw@output@leads\pgfcirc@draw@output@leadstrue
\ctikzset{logic ports draw output leads/.is choice}
\ctikzset{logic ports draw output leads/true/.code={\pgfcirc@draw@output@leadstrue}}
\ctikzset{logic ports draw output leads/false/.code={\pgfcirc@draw@output@leadsfalse}}
\tikzset{output leads/.code={\pgfcirc@draw@output@leadstrue}}
\tikzset{no output leads/.code={\pgfcirc@draw@output@leadsfalse}}

\ctikzset{logic ports draw leads/.is choice}
\ctikzset{logic ports draw leads/true/.code={\pgfcirc@draw@output@leadstrue\pgfcirc@draw@input@leadstrue}}
\ctikzset{logic ports draw leads/false/.code={\pgfcirc@draw@output@leadsfalse\pgfcirc@draw@input@leadsfalse}}
\tikzset{all leads/.code={\pgfcirc@draw@output@leadstrue\pgfcirc@draw@input@leadstrue}}
\tikzset{no leads/.code={\pgfcirc@draw@output@leadsfalse\pgfcirc@draw@input@leadsfalse}}

% adding a different style of xnor port
% see https://github.com/circuitikz/circuitikz/issues/467
\ctikzset{european xnor style/.is choice}
\ctikzset{european xnor style/default/.code={%
    \pgfcircdeclareeurologicport{xnor}{$=1$}{\pgf@circ@res@count}{not}}%
}
\ctikzset{european xnor style/direct/.code={%
    \pgfcircdeclareeurologicport{xnor}{$=$}{\pgf@circ@res@count}{}}%
}


% old, legacy keys that should be killed over
\ctikzset{bipoles/buffer/height/.initial=1}
\ctikzset{bipoles/buffer/width/.initial=1}
\ctikzset{bipoles/not port/width/.initial=1}
\ctikzset{bipoles/not port/height/.initial=.8}
\ctikzset{bipoles/not port/circle width/.initial=.15}

\ctikzset{tripoles/american and port/width/.initial=1.1}
\ctikzset{tripoles/american and port/height/.initial=.8}
\ctikzset{tripoles/american and port/port width/.initial=.7}
\ctikzset{tripoles/american and port/input height/.initial=.5}
\ctikzset{tripoles/american nand port/width/.initial=1.1}
\ctikzset{tripoles/american nand port/height/.initial=.8}
\ctikzset{tripoles/american nand port/port width/.initial=.7}
\ctikzset{tripoles/american nand port/circle width/.initial=.15}
\ctikzset{tripoles/american nand port/input height/.initial=.5}
\ctikzset{tripoles/american or port/width/.initial=1.1}
\ctikzset{tripoles/american or port/height/.initial=.8}
\ctikzset{tripoles/american or port/port width/.initial=.7}
\ctikzset{tripoles/american or port/input height/.initial=.5}
\ctikzset{tripoles/american or port/input skip/.initial=.25}
\ctikzset{tripoles/american or port/aaa/.initial=.6}
\ctikzset{tripoles/american or port/bbb/.initial=.4}
\ctikzset{tripoles/american or port/ccc/.initial=.5}
\ctikzset{tripoles/american or port/ddd/.initial=.0}
\ctikzset{tripoles/american nor port/width/.initial=1.1}
\ctikzset{tripoles/american nor port/height/.initial=.8}
\ctikzset{tripoles/american nor port/port width/.initial=.7}
\ctikzset{tripoles/american nor port/input height/.initial=.5}
\ctikzset{tripoles/american nor port/input skip/.initial=.25}
\ctikzset{tripoles/american nor port/circle width/.initial=.15}
\ctikzset{tripoles/american nor port/aaa/.initial=.6}
\ctikzset{tripoles/american nor port/bbb/.initial=.4}
\ctikzset{tripoles/american nor port/ccc/.initial=.5}
\ctikzset{tripoles/american nor port/ddd/.initial=.0}
\ctikzset{tripoles/american xor port/width/.initial=1.1}
\ctikzset{tripoles/american xor port/height/.initial=.8}
\ctikzset{tripoles/american xor port/port width/.initial=.7}
\ctikzset{tripoles/american xor port/input height/.initial=.5}
\ctikzset{tripoles/american xor port/input skip/.initial=.15}
\ctikzset{tripoles/american xor port/distance/.initial=.1}
\ctikzset{tripoles/american xnor port/width/.initial=1.1}
\ctikzset{tripoles/american xnor port/height/.initial=.8}
\ctikzset{tripoles/american xnor port/port width/.initial=.7}
\ctikzset{tripoles/american xnor port/input height/.initial=.5}
\ctikzset{tripoles/american xnor port/input skip/.initial=.15}
\ctikzset{tripoles/american xnor port/distance/.initial=.1}
\ctikzset{tripoles/american xnor port/circle width/.initial=.15}
\ctikzset{tripoles/american and port/origin/.initial=0.8}
\ctikzset{tripoles/american and port/inputs/.initial=2}
% variable number of inputs
\ctikzset{tripoles/american nand port/origin/.initial=0.8}
\ctikzset{tripoles/american nand port/inputs/.initial=2}
\ctikzset{tripoles/american nor port/origin/.initial=0.8}
\ctikzset{tripoles/american nor port/inputs/.initial=2}
\ctikzset{tripoles/american nor port/angle/.initial=70}
\ctikzset{tripoles/american nor port/inner/.initial=0.3}
\ctikzset{tripoles/american or port/origin/.initial=0.8}
\ctikzset{tripoles/american or port/inputs/.initial=2}
\ctikzset{tripoles/american or port/angle/.initial=70}
\ctikzset{tripoles/american or port/inner/.initial=0.3}
\ctikzset{tripoles/american xor port/origin/.initial=0.8}
\ctikzset{tripoles/american xor port/inputs/.initial=2}
\ctikzset{tripoles/american xor port/angle/.initial=70}
\ctikzset{tripoles/american xor port/inner/.initial=0.3}
\ctikzset{tripoles/american xnor port/origin/.initial=0.8}
\ctikzset{tripoles/american xnor port/inputs/.initial=2}
\ctikzset{tripoles/american xnor port/angle/.initial=70}
\ctikzset{tripoles/american xnor port/inner/.initial=0.3}
%
\ctikzset{tripoles/european and port/width/.initial=1.4}
\ctikzset{tripoles/european and port/height/.initial=.65}
\ctikzset{tripoles/european and port/reserved/.initial=.6}
\ctikzset{tripoles/european and port/input height/.initial=.6}
\ctikzset{tripoles/european or port/width/.initial=1.4}
\ctikzset{tripoles/european or port/height/.initial=.65}
\ctikzset{tripoles/european or port/reserved/.initial=.6}
\ctikzset{tripoles/european or port/input height/.initial=.6}
\ctikzset{tripoles/european xor port/width/.initial=1.4}
\ctikzset{tripoles/european xor port/height/.initial=.65}
\ctikzset{tripoles/european xor port/reserved/.initial=.6}
\ctikzset{tripoles/european xor port/input height/.initial=.6}
\ctikzset{tripoles/european nand port/width/.initial=1.4}
\ctikzset{tripoles/european nand port/not height/.initial=.3}
\ctikzset{tripoles/european nand port/not width/.initial=.9}
\ctikzset{tripoles/european nand port/height/.initial=.65}
\ctikzset{tripoles/european nand port/reserved/.initial=.6}
\ctikzset{tripoles/european nand port/input height/.initial=.6}
\ctikzset{tripoles/european buffer port/width/.initial=1.4}
\ctikzset{tripoles/european buffer port/not height/.initial=.3}
\ctikzset{tripoles/european buffer port/not width/.initial=.9}
\ctikzset{tripoles/european buffer port/height/.initial=.65}
\ctikzset{tripoles/european buffer port/reserved/.initial=.6}
\ctikzset{tripoles/european buffer port/input height/.initial=0}
\ctikzset{tripoles/european not port/width/.initial=1.4}
\ctikzset{tripoles/european not port/not height/.initial=.3}
\ctikzset{tripoles/european not port/not width/.initial=.9}
\ctikzset{tripoles/european not port/height/.initial=.65}
\ctikzset{tripoles/european not port/reserved/.initial=.6}
\ctikzset{tripoles/european not port/input height/.initial=0}
\ctikzset{tripoles/european xnor port/width/.initial=1.4}
\ctikzset{tripoles/european xnor port/not height/.initial=.3}
\ctikzset{tripoles/european xnor port/not width/.initial=.9}
\ctikzset{tripoles/european xnor port/height/.initial=.65}
\ctikzset{tripoles/european xnor port/reserved/.initial=.6}
\ctikzset{tripoles/european xnor port/input height/.initial=.6}
\ctikzset{tripoles/european nor port/width/.initial=1.4}
\ctikzset{tripoles/european nor port/not height/.initial=.3}
\ctikzset{tripoles/european nor port/not width/.initial=.9}
\ctikzset{tripoles/european nor port/height/.initial=.65}
\ctikzset{tripoles/european nor port/reserved/.initial=.6}
\ctikzset{tripoles/european nor port/input height/.initial=.6}
% variable number of inputs
\ctikzset{tripoles/european and port/origin/.initial=0.8}
\ctikzset{tripoles/european and port/inputs/.initial=2}
\ctikzset{tripoles/european nand port/origin/.initial=0.8}
\ctikzset{tripoles/european nand port/inputs/.initial=2}
\ctikzset{tripoles/european or port/origin/.initial=0.8}
\ctikzset{tripoles/european or port/inputs/.initial=2}
\ctikzset{tripoles/european nor port/origin/.initial=0.8}
\ctikzset{tripoles/european nor port/inputs/.initial=2}
\ctikzset{tripoles/european xor port/origin/.initial=0.8}
\ctikzset{tripoles/european xor port/inputs/.initial=2}
\ctikzset{tripoles/european xnor port/origin/.initial=0.8}
\ctikzset{tripoles/european xnor port/inputs/.initial=2}
\ctikzset{tripoles/european buffer port/origin/.initial=0.8}
\ctikzset{tripoles/european buffer port/inputs/.initial=1}%
\ctikzset{tripoles/european not port/origin/.initial=0.8}
\ctikzset{tripoles/european not port/inputs/.initial=1}%
%% "blank" ports
\ctikzset{tripoles/european blank port/width/.initial=1.4}
\ctikzset{tripoles/european blank port/height/.initial=.65}
\ctikzset{tripoles/european blank port/reserved/.initial=.6}
\ctikzset{tripoles/european blank port/input height/.initial=.6}
\ctikzset{tripoles/european blank not port/width/.initial=1.4}
\ctikzset{tripoles/european blank not port/not height/.initial=.3}
\ctikzset{tripoles/european blank not port/not width/.initial=.9}
\ctikzset{tripoles/european blank not port/height/.initial=.65}
\ctikzset{tripoles/european blank not port/reserved/.initial=.6}
\ctikzset{tripoles/european blank not port/input height/.initial=.6}
\ctikzset{tripoles/european blank port/origin/.initial=0.8}
\ctikzset{tripoles/european blank port/inputs/.initial=2}
\ctikzset{tripoles/european blank not port/origin/.initial=0.8}
\ctikzset{tripoles/european blank not port/inputs/.initial=2}
%%% parameters that are not used anymore after multi-input
%%% gates --- left for compatibility of source code.
\ctikzset{tripoles/american xor port/aaa/.initial=.6}
\ctikzset{tripoles/american xor port/bbb/.initial=.4}
\ctikzset{tripoles/american xor port/ccc/.initial=.5}
\ctikzset{tripoles/american xor port/ddd/.initial=.0}
\ctikzset{tripoles/american xnor port/aaa/.initial=.6}
\ctikzset{tripoles/american xnor port/bbb/.initial=.4}
\ctikzset{tripoles/american xnor port/ccc/.initial=.5}
\ctikzset{tripoles/american xnor port/ddd/.initial=.0}
%%>>>

%% Node shapes for Logic ports%<<<
%%
%% Code from John Kormylo at tex.stackexchange.com
%% See https://tex.stackexchange.com/questions/372993/is-it-possible-to-implement-multiple-input-logic-ports-with-circuitikz
%% Integration and fixes from Romano Giannetti and TheTeXnician <38565529+TheTeXnician@users.noreply.github.com>
%%

\newcount\pgf@circ@res@count% reserve global register

\def\pgf@circ@logicport@input#1% #1 = \pgfmathcounter
{%
    \pgfextracty{\pgf@circ@res@up}{\northeast}%
    \step
    \pgf@circ@res@step=\dimexpr 2\pgf@y -2\pgf@circ@res@up\relax
    \advance\pgf@y by -#1\pgf@circ@res@step\relax
}%

% #1 = \pgfmathcounter #2=type #3 specificic port
% type is 1 for and,nand; 2 for or,nor; 3 for xor,xnor, 4 for european.
\def\pgf@circ@logicport@baseinput#1#2#3%
{%
    % and and nand
    \ifnum #2=1\relax
        \pgfextracty{\pgf@circ@res@up}{\northeast}%
        \pgfextractx{\pgf@circ@res@left}{\southwest}%
        \step
        \pgf@circ@res@step=\dimexpr 2\pgf@y -2\pgf@circ@res@up\relax
        \advance\pgf@y by -#1\pgf@circ@res@step\relax
        \pgf@x=\ctikzvalof{tripoles/american #3 port/port width}\pgf@circ@res@left
    \fi
    % or and nor
    \ifnum #2=2\relax
        \pgfextracty{\pgf@circ@res@up}{\northeast}%
        \pgfextractx{\pgf@circ@res@left}{\southwest}%
        \pgfextractx{\pgf@circ@res@right}{\northeast}%
        \step
        \pgf@circ@res@step=\dimexpr 2\pgf@y -2\pgf@circ@res@up\relax
        \advance\pgf@y by -#1\pgf@circ@res@step\relax
        \edef\pgf@circ@math@angle{\ctikzvalof{tripoles/american #3 port/angle}}%
        \pgf@circ@res@other=\ctikzvalof{tripoles/american #3 port/inner}\pgf@circ@res@right
        \pgfmathsetlengthmacro{\pgf@circ@math@xradius}{\pgf@circ@res@other /(1 - cos(\pgf@circ@math@angle)}%
        \pgfmathsetlengthmacro{\pgf@circ@math@yradius}{\pgf@circ@res@up /sin(\pgf@circ@math@angle)}%
        \pgf@circ@res@other=\ctikzvalof{tripoles/american #3 port/port width}\pgf@circ@res@right
        \pgfmathsetlengthmacro{\pgf@circ@math@xorigin}{\pgf@circ@res@other + \pgf@circ@math@xradius*cos(\pgf@circ@math@angle)}%
        \pgf@circ@res@temp=\pgf@y
        \pgfmathsetmacro{\pgf@circ@math@angle}{asin(\pgf@circ@res@temp/\pgf@circ@math@yradius)}%
        \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@math@xradius*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
        \pgf@x=\pgf@circ@res@other
    \fi
    % xor and xnor
    \ifnum #2=3\relax
        \pgfextracty{\pgf@circ@res@up}{\northeast}%
        \pgfextractx{\pgf@circ@res@left}{\southwest}%
        \pgfextractx{\pgf@circ@res@right}{\northeast}%
        \pgfkeysgetvalue{/tikz/circuitikz/tripoles/american #3 port/angle}{\pgf@circ@math@angle}%
        \pgf@circ@res@other=\ctikzvalof{tripoles/american #3 port/inner}\pgf@circ@res@right
        \pgfmathsetlengthmacro{\pgf@circ@math@xradius}{\pgf@circ@res@other /(1 - cos(\pgf@circ@math@angle)}%
        \pgfmathsetlengthmacro{\pgf@circ@math@yradius}{\pgf@circ@res@up / sin(\pgf@circ@math@angle))}%
        \pgf@circ@res@other=\ctikzvalof{tripoles/american #3 port/port width}\pgf@circ@res@right
        \pgfmathsetlengthmacro{\pgf@circ@math@xorigin}{\pgf@circ@res@other + \pgf@circ@math@xradius*cos(\pgf@circ@math@angle)}%
        \pgf@circ@res@temp=\ctikzvalof{tripoles/american #3 port/distance}\pgf@circ@res@right
        \pgfmathsetlengthmacro{\pgf@circ@math@distance}{\pgf@circ@res@temp}
        % this compensates for the effect of the line width on the gap between the arcs
        \pgfmathsetlengthmacro{\pgf@circ@math@yradiusA}{\pgf@circ@math@yradius -2\pgflinewidth}%
        \pgfmathsetlengthmacro{\pgf@circ@math@xradiusA}{\pgf@circ@math@xradius -2\pgflinewidth}%

        \step
        \pgf@circ@res@step=\dimexpr 2\pgf@y -2\pgf@circ@res@up\relax
        \advance\pgf@y by -#1\pgf@circ@res@step\relax
         \pgf@circ@res@temp=\pgf@y
            \pgfmathsetmacro{\pgf@circ@math@angle}{asin(\pgf@circ@res@temp  / \pgf@circ@math@yradiusA)}%
        \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@math@xradiusA*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
        \advance\pgf@circ@res@other by -\pgf@circ@math@distance
        \pgf@x=\pgf@circ@res@other
    \fi
    % european
    \ifnum #2=4\relax
        \pgfextracty{\pgf@circ@res@up}{\northeast}%
        \pgfextractx{\pgf@circ@res@other}{\left}%
        \step
        \pgf@circ@res@step=\dimexpr 2\pgf@y -2\pgf@circ@res@up\relax
        \advance\pgf@y by -#1\pgf@circ@res@step\relax
        \pgf@x=\pgf@circ@res@other
    \fi
}%

%%% american
\long\def\pgfcircdeclarelogicport#1#2#3{%
    \pgfdeclareshape{american #1 port}%
    {%
        \savedmacro{\ctikzclass}{\edef\ctikzclass{logic ports}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \savedmacro\resize{% automatic
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@circ@res@up = \ctikzvalof{tripoles/american #1 port/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@up = .5\pgf@circ@res@up
            \pgf@circ@res@down = -\pgf@circ@res@up
            \pgf@circ@res@right = \ctikzvalof{tripoles/american #1 port/width}\pgf@circ@scaled@Rlen
            \pgf@circ@res@right = .5\pgf@circ@res@right
            \pgf@circ@res@left = -\pgf@circ@res@right
    }%
    \savedmacro\inputs{% get number of inputs
        \pgf@circ@res@count=\pgfkeysvalueof{/tikz/number inputs}\relax%
        \ifnum\pgf@circ@res@count=0
            \pgf@circ@res@count=\ctikzvalof{tripoles/american #1 port/inputs}\relax%
        \fi
        \ifnum\pgf@circ@res@count<2 \pgf@circ@res@count=2\fi
        \ifnum\pgf@circ@res@count>16 \pgf@circ@res@count=16\fi
        \def\inputs{\the\pgf@circ@res@count}%
    }%
    \savedanchor\step{% 1/2 gap at edges
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step = \ctikzvalof{tripoles/american #1 port/height}\pgf@circ@scaled@Rlen
        \divide\pgf@circ@res@step by \pgf@circ@res@count
        \pgfpoint{\pgf@circ@res@left}{\dimexpr\pgf@circ@res@up+0.5\pgf@circ@res@step}%
    }%
    \savedanchor\northeast{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \savedanchor\southwest{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    \savedanchor\left{\pgfpoint{\ctikzvalof{tripoles/american #1 port/port width}\pgf@circ@res@left}{0pt}}
    \savedanchor\right{\pgfpoint{\ctikzvalof{tripoles/american #1 port/port width}\pgf@circ@res@right}{0pt}}
    \savedanchor\origin{\pgfpoint{\ctikzvalof{tripoles/american #1 port/origin}\pgf@circ@res@right}{0pt}}

    \anchor{center}{\origin}% for backwards compatibility
    \anchor{text}{\pgfpoint{-.5\wd\pgfnodeparttextbox}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}}

    % create input anchors
    \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@american #1 port\endcsname{%
        \pgfmathloop%
        \ifnum\pgfmathcounter>\pgf@circ@res@count%
    \else%
        %\pgfutil@ifundefined{pgf@anchor@american #1 port@in \pgfmathcounter}{%
        \expandafter\xdef\csname pgf@anchor@american #1 port@in \pgfmathcounter\endcsname{%
            \noexpand\pgf@circ@logicport@input{\pgfmathcounter}% defined above
        }%
        \expandafter\xdef\csname pgf@anchor@american #1 port@bin \pgfmathcounter\endcsname{%
            \noexpand\pgf@circ@logicport@baseinput{\pgfmathcounter}{#2}{#1}% defined above
        }%
        %}{}%
        \repeatpgfmathloop%
    }

    \anchor{out}{\northeast\pgf@y=0pt}
    \anchor{bout}{\right\pgf@y=0pt}


    \anchor{left}{\left}% edges of component minus leads
    \anchor{right}{\right}

    \anchor{north east}{\northeast}% see \Compass macro
    \anchor{south west}{\southwest}
    \anchor{north}{\pgfextracty{\pgf@circ@res@up}{\northeast}%
    \pgfpoint{0cm}{\pgf@circ@res@up}}
    \anchor{north west}{\pgfextracty{\pgf@circ@res@up}{\northeast}%
        \pgfextractx{\pgf@circ@res@left}{\southwest}%
    \pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \anchor{west}{\pgfextractx{\pgf@circ@res@left}{\southwest}%
    \pgfpoint{\pgf@circ@res@left}{0cm}}
    \anchor{south}{\pgfextracty{\pgf@circ@res@down}{\southwest}%
    \pgfpoint{0cm}{\pgf@circ@res@down}}
    \anchor{south east}{\pgfextracty{\pgf@circ@res@down}{\southwest}%
        \pgfextractx{\pgf@circ@res@right}{\northeast}%
    \pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \anchor{east}{\pgfextractx{\pgf@circ@res@right}{\northeast}%
    \pgfpoint{\pgf@circ@res@right}{0cm}}

    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        % \pgf@circ@debug@colors
        #3%
    }
}
}
%%% american and %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfcircdeclarelogicport{and}{1}{
    \pgfextracty{\pgf@circ@res@temp}{\step}%
    \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
    \pgf@circ@res@count = \inputs\relax
    \ifpgfcirc@draw@input@leads
        %input leads
        \loop\ifnum\pgf@circ@res@count>0
            \advance\pgf@circ@res@temp by -\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/american and port/port width}\pgf@circ@res@left}
            {\pgf@circ@res@temp}}
            \advance\pgf@circ@res@count by -1
        \repeat
    \fi
    % output lead
    \ifpgfcirc@draw@output@leads
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/american and port/port width}\pgf@circ@res@right} {0pt}}
        \pgfusepath{draw}
    \fi


    \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
    \pgf@circ@res@other=\ctikzvalof{tripoles/american and port/port width}\pgf@circ@res@left

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@down}}
    \pgfpatharc{-90}{90}{-2\pgf@circ@res@other and \pgf@circ@res@up}
    \pgfpathclose
    \pgf@circ@draworfill
    }
%%% american nand %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \pgfcircdeclarelogicport{nand}{1}{
    \pgfextracty{\pgf@circ@res@temp}{\step}%
    \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
    \pgf@circ@res@count = \inputs\relax
    \ifpgfcirc@draw@input@leads
        %input leads
        \loop\ifnum\pgf@circ@res@count>0
            \advance\pgf@circ@res@temp by -\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/american nand port/port width}\pgf@circ@res@left}
            {\pgf@circ@res@temp}}
            \advance\pgf@circ@res@count by -1
        \repeat
    \fi

    \ifpgfcirc@draw@output@leads
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/american nand port/port width}\pgf@circ@res@right} {0pt}}
        \pgfusepath{draw}
    \fi
    \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
    \pgf@circ@res@step = \ctikzvalof{tripoles/american nand port/circle width}\pgf@circ@res@right
    \pgf@circ@res@other = \ctikzvalof{tripoles/american nand port/port width}\pgf@circ@res@right
    \pgf@circ@res@temp = \dimexpr 2\pgf@circ@res@other - \pgf@circ@res@step\relax

    \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@down}}
    \pgfpatharc{-90}{90}{\pgf@circ@res@temp and \pgf@circ@res@up}
    \pgfpathclose

    \pgfpathellipse
    {\pgfpoint{\pgf@circ@res@other-.5\pgf@circ@res@step}{0pt}}
    {\pgfpoint{.5\pgf@circ@res@step}{0pt}}
    {\pgfpoint{0pt}{.5\pgf@circ@res@step}}

    \pgf@circ@draworfill
}
%%% american nor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfcircdeclarelogicport{nor}{2}{
    \edef\pgf@circ@math@angle{\ctikzvalof{tripoles/american nor port/angle}}%
    \pgf@circ@res@other=\ctikzvalof{tripoles/american nor port/inner}\pgf@circ@res@right
    \pgfmathsetlengthmacro{\pgf@circ@math@xradius}{\pgf@circ@res@other /(1 - cos(\pgf@circ@math@angle)}%
    \pgfmathsetlengthmacro{\pgf@circ@math@yradius}{\pgf@circ@res@up /sin(\pgf@circ@math@angle)}%
    \pgf@circ@res@other=\ctikzvalof{tripoles/american nor port/port width}\pgf@circ@res@right
    \pgfmathsetlengthmacro{\pgf@circ@math@xorigin}{\pgf@circ@res@other + \pgf@circ@math@xradius*cos(\pgf@circ@math@angle)}%

    \pgfextracty{\pgf@circ@res@temp}{\step}%
    \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
    \pgf@circ@res@count = \inputs\relax
    \ifpgfcirc@draw@input@leads
        %input leads
        \loop\ifnum\pgf@circ@res@count>0
            \advance\pgf@circ@res@temp by -\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
            \pgfmathsetmacro{\pgf@circ@math@angle}{asin(\pgf@circ@res@temp/\pgf@circ@math@yradius)}%
            \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@math@xradius*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@temp}}%
            \advance\pgf@circ@res@count by -1
        \repeat
    \fi

    \pgf@circ@res@other=\ctikzvalof{tripoles/american nor port/port width}\pgf@circ@res@right
    \ifpgfcirc@draw@output@leads
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfusepath{draw}
    \fi

    \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}

    \edef\pgf@circ@math@angle{\ctikzvalof{tripoles/american nor port/angle}}%
    \pgf@circ@res@step = \ctikzvalof{tripoles/american nor port/circle width}\pgf@circ@res@right
    \pgf@circ@res@temp = \dimexpr 2\pgf@circ@res@other - \pgf@circ@res@step\relax
    \advance\pgf@circ@res@other by -\pgf@circ@res@step

    % main shape
    \ifpgfcirc@roundy@or@shapes
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}% for symmetry
        \pgfpatharc{0}{90}{\pgf@circ@res@temp and \pgf@circ@res@up}%
        \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradius and \pgf@circ@math@yradius}%
        \pgfpatharc{-90}{0}{\pgf@circ@res@temp and \pgf@circ@res@up}%
        \pgfpathclose
    \else
        \pgfmathsetlength{\pgf@circ@res@temp}{\pgf@circ@math@xradius*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@up}}
        \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradius and \pgf@circ@math@yradius}%
        \pgfpathcurveto{\pgfpoint{0.3\pgf@circ@res@right}{\pgf@circ@res@down}}{\pgfpoint{0.3\pgf@circ@res@right}{0.5\pgf@circ@res@down}}{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfpathcurveto{\pgfpoint{0.3\pgf@circ@res@right}{0.5\pgf@circ@res@up}}{\pgfpoint{0.3\pgf@circ@res@right}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@up}}
        \pgfpathclose
    \fi

    % not dot
    \pgfpathellipse
    {\pgfpoint{\pgf@circ@res@other+.5\pgf@circ@res@step}{0pt}}
    {\pgfpoint{.5\pgf@circ@res@step}{0pt}}
    {\pgfpoint{0pt}{.5\pgf@circ@res@step}}

    \pgf@circ@draworfill
}
%%% american or %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfcircdeclarelogicport{or}{2}{
    \edef\pgf@circ@math@angle{\ctikzvalof{tripoles/american or port/angle}}%
    \pgf@circ@res@other=\ctikzvalof{tripoles/american or port/inner}\pgf@circ@res@right
    \pgfmathsetlengthmacro{\pgf@circ@math@xradius}{\pgf@circ@res@other /(1 - cos(\pgf@circ@math@angle)}%
    \pgfmathsetlengthmacro{\pgf@circ@math@yradius}{\pgf@circ@res@up /sin(\pgf@circ@math@angle)}%
    \pgf@circ@res@other=\ctikzvalof{tripoles/american or port/port width}\pgf@circ@res@right
    \pgfmathsetlengthmacro{\pgf@circ@math@xorigin}{\pgf@circ@res@other + \pgf@circ@math@xradius*cos(\pgf@circ@math@angle)}%

    \pgfextracty{\pgf@circ@res@temp}{\step}%
    \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
    \pgf@circ@res@count = \inputs\relax
    \ifpgfcirc@draw@input@leads
        %input leads
        \loop\ifnum\pgf@circ@res@count>0
            \advance\pgf@circ@res@temp by -\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
            \pgfmathsetmacro{\pgf@circ@math@angle}{asin(\pgf@circ@res@temp/\pgf@circ@math@yradius)}%
            \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@math@xradius*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@temp}}%
            \advance\pgf@circ@res@count by -1
        \repeat
    \fi

    \pgf@circ@res@other=\ctikzvalof{tripoles/american or port/port width}\pgf@circ@res@right
    \ifpgfcirc@draw@output@leads
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfusepath{draw}
    \fi

    \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}

    \edef\pgf@circ@math@angle{\ctikzvalof{tripoles/american or port/angle}}%

    % main shape
    \ifpgfcirc@roundy@or@shapes
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}% for symmetry
        \pgfpatharc{0}{90}{2\pgf@circ@res@other and \pgf@circ@res@up}%
        \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradius and \pgf@circ@math@yradius}%
        \pgfpatharc{-90}{0}{2\pgf@circ@res@other and \pgf@circ@res@up}%
        \pgfpathclose
    \else
        \pgfmathsetlength{\pgf@circ@res@temp}{\pgf@circ@math@xradius*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@up}}
        \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradius and \pgf@circ@math@yradius}%
        \pgfpathcurveto{\pgfpoint{0.3\pgf@circ@res@right}{\pgf@circ@res@down}}{\pgfpoint{0.3\pgf@circ@res@right}{0.5\pgf@circ@res@down}}{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfpathcurveto{\pgfpoint{0.3\pgf@circ@res@right}{0.5\pgf@circ@res@up}}{\pgfpoint{0.3\pgf@circ@res@right}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@up}}
        \pgfpathclose
    \fi

    \pgf@circ@draworfill
}
%%% american xor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfcircdeclarelogicport{xor}{3}{
    \pgfkeysgetvalue{/tikz/circuitikz/tripoles/american xor port/angle}{\pgf@circ@math@angle}%
    \pgf@circ@res@other=\ctikzvalof{tripoles/american xor port/inner}\pgf@circ@res@right
    \pgfmathsetlengthmacro{\pgf@circ@math@xradius}{\pgf@circ@res@other /(1 - cos(\pgf@circ@math@angle)}%
    \pgfmathsetlengthmacro{\pgf@circ@math@yradius}{\pgf@circ@res@up / sin(\pgf@circ@math@angle))}%
    \pgf@circ@res@other=\ctikzvalof{tripoles/american xor port/port width}\pgf@circ@res@right
    \pgfmathsetlengthmacro{\pgf@circ@math@xorigin}{\pgf@circ@res@other + \pgf@circ@math@xradius*cos(\pgf@circ@math@angle)}%
    \pgf@circ@res@temp=\ctikzvalof{tripoles/american xor port/distance}\pgf@circ@res@right
    \pgfmathsetlengthmacro{\pgf@circ@math@distance}{\pgf@circ@res@temp}
    % this compensates for the effect of the line width on the gap between the arcs
    \pgfmathsetlengthmacro{\pgf@circ@math@yradiusA}{\pgf@circ@math@yradius -2\pgflinewidth}%
    \pgfmathsetlengthmacro{\pgf@circ@math@xradiusA}{\pgf@circ@math@xradius -2\pgflinewidth}%

    \pgfextracty{\pgf@circ@res@temp}{\step}%
    \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
    \pgf@circ@res@count = \inputs\relax
    \ifpgfcirc@draw@input@leads
        %input leads
        \loop\ifnum\pgf@circ@res@count>0
            \advance\pgf@circ@res@temp by -\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
            \pgfmathsetmacro{\pgf@circ@math@angle}{asin(\pgf@circ@res@temp  / \pgf@circ@math@yradiusA)}%
            \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@math@xradiusA*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
            \advance\pgf@circ@res@other by -\pgf@circ@math@distance
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@temp}}%
            \advance\pgf@circ@res@count by -1
        \repeat
    \fi

    \pgf@circ@res@other=\ctikzvalof{tripoles/american xor port/port width}\pgf@circ@res@right
    \ifpgfcirc@draw@output@leads
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfusepath{draw}
    \fi

    \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}

    \edef\pgf@circ@math@angle{\ctikzvalof{tripoles/american xor port/angle}}%

    % main shape
    \ifpgfcirc@roundy@or@shapes
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}% for symmetry
        \pgfpatharc{0}{90}{2\pgf@circ@res@other and \pgf@circ@res@up}%
        \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradius and \pgf@circ@math@yradius}%
        \pgfpatharc{-90}{0}{2\pgf@circ@res@other and \pgf@circ@res@up}%
        \pgfpathclose
    \else
        \pgfmathsetlength{\pgf@circ@res@temp}{\pgf@circ@math@xradius*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@up}}
        \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradius and \pgf@circ@math@yradius}%
        \pgfpathcurveto{\pgfpoint{0.3\pgf@circ@res@right}{\pgf@circ@res@down}}{\pgfpoint{0.3\pgf@circ@res@right}{0.5\pgf@circ@res@down}}{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfpathcurveto{\pgfpoint{0.3\pgf@circ@res@right}{0.5\pgf@circ@res@up}}{\pgfpoint{0.3\pgf@circ@res@right}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@up}}
        \pgfpathclose
    \fi
    \pgf@circ@draworfill

    \pgfmathsetlength{\pgf@circ@res@temp}{(\pgf@circ@math@yradiusA)*sin(\pgf@circ@math@angle)}%

    \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other-\pgf@circ@math@distance}{\pgf@circ@res@temp}}% first arc
    \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradiusA and \pgf@circ@math@yradiusA}%

    \pgfusepath{draw}
}
%%% american xnor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfcircdeclarelogicport{xnor}{3}{
    \pgfkeysgetvalue{/tikz/circuitikz/tripoles/american xnor port/angle}{\pgf@circ@math@angle}%
    \pgf@circ@res@other=\ctikzvalof{tripoles/american xnor port/inner}\pgf@circ@res@right
    \pgfmathsetlengthmacro{\pgf@circ@math@xradius}{\pgf@circ@res@other /(1 - cos(\pgf@circ@math@angle)}%
    \pgfmathsetlengthmacro{\pgf@circ@math@yradius}{\pgf@circ@res@up / sin(\pgf@circ@math@angle))}%
    \pgf@circ@res@other=\ctikzvalof{tripoles/american xnor port/port width}\pgf@circ@res@right
    \pgfmathsetlengthmacro{\pgf@circ@math@xorigin}{\pgf@circ@res@other + \pgf@circ@math@xradius*cos(\pgf@circ@math@angle)}%
    \pgf@circ@res@temp=\ctikzvalof{tripoles/american xor port/distance}\pgf@circ@res@right
    \pgfmathsetlengthmacro{\pgf@circ@math@distance}{\pgf@circ@res@temp}
    % this compensates for the effect of the line width on the gap between the arcs
    \pgfmathsetlengthmacro{\pgf@circ@math@yradiusA}{\pgf@circ@math@yradius -2\pgflinewidth}%
    \pgfmathsetlengthmacro{\pgf@circ@math@xradiusA}{\pgf@circ@math@xradius -2\pgflinewidth}%

    \pgfextracty{\pgf@circ@res@temp}{\step}%
    \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
    \pgf@circ@res@count = \inputs\relax
    \ifpgfcirc@draw@input@leads
        %input leads
        \loop\ifnum\pgf@circ@res@count>0
            \advance\pgf@circ@res@temp by -\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
            \pgfmathsetmacro{\pgf@circ@math@angle}{asin(\pgf@circ@res@temp  / \pgf@circ@math@yradiusA)}%
            \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@math@xradiusA*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
            \advance\pgf@circ@res@other by -\pgf@circ@math@distance
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@temp}}%
            \advance\pgf@circ@res@count by -1
        \repeat
    \fi

    \pgf@circ@res@other=\ctikzvalof{tripoles/american xnor port/port width}\pgf@circ@res@right
    \ifpgfcirc@draw@output@leads
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfusepath{draw}
    \fi

    \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}

    \edef\pgf@circ@math@angle{\ctikzvalof{tripoles/american xnor port/angle}}%
    \pgf@circ@res@step = \ctikzvalof{tripoles/american xnor port/circle width}\pgf@circ@res@right
    \pgf@circ@res@temp = \dimexpr 2\pgf@circ@res@other - \pgf@circ@res@step\relax
    \advance\pgf@circ@res@other by -\pgf@circ@res@step

    % main shape
    \ifpgfcirc@roundy@or@shapes
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{0pt}}% for symmetry
        \pgfpatharc{0}{90}{\pgf@circ@res@temp and \pgf@circ@res@up}%
        \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradius and \pgf@circ@math@yradius}%
        \pgfpatharc{-90}{0}{\pgf@circ@res@temp and \pgf@circ@res@up}%
        \pgfpathclose
    \else
        \pgfmathsetlength{\pgf@circ@res@temp}{\pgf@circ@math@xradius*cos(\pgf@circ@math@angle)-\pgf@circ@math@xorigin}%
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@up}}
        \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradius and \pgf@circ@math@yradius}%
        \pgfpathcurveto{\pgfpoint{0.3\pgf@circ@res@right}{\pgf@circ@res@down}}{\pgfpoint{0.3\pgf@circ@res@right}{0.5\pgf@circ@res@down}}{\pgfpoint{\pgf@circ@res@other}{0pt}}
        \pgfpathcurveto{\pgfpoint{0.3\pgf@circ@res@right}{0.5\pgf@circ@res@up}}{\pgfpoint{0.3\pgf@circ@res@right}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@up}}
        \pgfpathclose
    \fi

    \pgfpathellipse
    {\pgfpoint{\pgf@circ@res@other+.5\pgf@circ@res@step}{0pt}}
    {\pgfpoint{.5\pgf@circ@res@step}{0pt}}
    {\pgfpoint{0pt}{.5\pgf@circ@res@step}}
    \pgf@circ@draworfill

    \pgf@circ@res@other=\ctikzvalof{tripoles/american xnor port/port width}\pgf@circ@res@left
    \pgfmathsetlength{\pgf@circ@res@temp}{(\pgf@circ@math@yradiusA)*sin(\pgf@circ@math@angle)}%

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other-\pgf@circ@math@distance}{\pgf@circ@res@temp}}% first arc
    \pgfpatharc{\pgf@circ@math@angle}{-\pgf@circ@math@angle}{\pgf@circ@math@xradiusA and \pgf@circ@math@yradiusA}%

    \pgfusepath{draw}
}

%%% Original one-input ports

\pgfdeclareshape{american not port}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{logic ports}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{bipoles/not port/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{bipoles/not port/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{in}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{in 1}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{left}{
        \northwest
        \pgf@x=0.7\pgf@x
        \pgf@y=0pt
    }
    \anchor{bin}{
        \northwest
        \pgf@x=0.7\pgf@x
        \pgf@y=0pt
    }
    \anchor{bin 1}{
        \northwest
        \pgf@y=0pt
        \pgf@x=0.7\pgf@x
    }
    \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{right}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-0.7\pgf@x
    }
    \anchor{bout}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-0.7\pgf@x
    }
    \anchor{center}{
        \pgfpointorigin
    }
    \anchor{east}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{west}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{south}{
        \northwest
        \pgf@x=0pt
        \pgf@y=-\pgf@y
    }
    \anchor{north}{
        \northwest
        \pgf@x=0pt
    }
    \anchor{south west}{
        \northwest
        \pgf@y=-\pgf@y
    }
    \anchor{north east}{
        \northwest
        \pgf@x=-\pgf@x
    }
    \anchor{north west}{
        \northwest
    }
    \anchor{south east}{
        \northwest
        \pgf@x=-\pgf@x
        \pgf@y=-\pgf@y
    }
    \anchorborder{% this is used when the node is used as a path element
        \pgf@xa=\pgf@x
        \pgf@ya=\pgf@y
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfextractx{\pgf@circ@res@left}{\northwest}
        \pgfpointborderrectangle{\pgfpoint{\pgf@xa}{\pgf@ya}}
            {\pgfpoint{-\pgf@circ@res@left}{\pgf@circ@res@up}}
    }
    \anchor{text}{%
        % centered and a bit to the left (it's a triangle)!
        \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor

        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x

        \pgf@circ@res@other = \ctikzvalof{bipoles/not port/circle width}\pgf@circ@res@right

        \pgfscope
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgftransformxshift{.7\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=.7\pgf@circ@res@step

            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step-\pgf@circ@res@other}{0pt}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@step-\pgf@circ@res@other}{0pt}}
            \pgf@circ@draworfill
            \pgfpathellipse
            {\pgfpoint{\pgf@circ@res@step-.5\pgf@circ@res@other}{0pt}}
            {\pgfpoint{.5\pgf@circ@res@other}{0pt}}
            {\pgfpoint{0pt}{.5\pgf@circ@res@other}}
            \pgf@circ@draworfill
        \endpgfscope

        \ifpgfcirc@draw@input@leads
            %input leads
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
            \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@left}{0pt}}
        \fi

        \ifpgfcirc@draw@output@leads
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
            \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right}{0pt}}
        \fi

        \pgfusepath{draw}
    }
}

\pgfdeclareshape{american buffer port}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{logic ports}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{bipoles/not port/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{bipoles/not port/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{in}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{in 1}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{left}{
        \northwest
        \pgf@x=0.7\pgf@x
        \pgf@y=0pt
    }
    \anchor{bin}{
        \northwest
        \pgf@x=0.7\pgf@x
        \pgf@y=0pt
    }
    \anchor{bin 1}{
        \northwest
        \pgf@y=0pt
        \pgf@x=0.7\pgf@x
    }
    \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{right}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-0.7\pgf@x
    }
    \anchor{bout}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-0.7\pgf@x
    }
    \anchor{center}{
        \pgfpointorigin
    }
    \anchor{east}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{west}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{south}{
        \northwest
        \pgf@x=0pt
        \pgf@y=-\pgf@y
    }
    \anchor{north}{
        \northwest
        \pgf@x=0pt
    }
    \anchor{south west}{
        \northwest
        \pgf@y=-\pgf@y
    }
    \anchor{north east}{
        \northwest
        \pgf@x=-\pgf@x
    }
    \anchor{north west}{
        \northwest
    }
    \anchor{south east}{
        \northwest
        \pgf@x=-\pgf@x
        \pgf@y=-\pgf@y
    }
    \anchorborder{% this is used when the node is used as a path element
        \pgf@xa=\pgf@x
        \pgf@ya=\pgf@y
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfextractx{\pgf@circ@res@left}{\northwest}
        \pgfpointborderrectangle{\pgfpoint{\pgf@xa}{\pgf@ya}}
            {\pgfpoint{-\pgf@circ@res@left}{\pgf@circ@res@up}}
    }
    \anchor{text}{%
        % centered and a bit to the left (it's a triangle)!
        \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor

        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x

        \pgfscope
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgftransformxshift{.7\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=.7\pgf@circ@res@step

            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{0pt}}
            \pgf@circ@draworfill
        \endpgfscope

        \ifpgfcirc@draw@input@leads
            %input leads
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
            \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@left}{0pt}}
        \fi

        \ifpgfcirc@draw@output@leads
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
            \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right}{0pt}}
        \fi

        \pgfusepath{draw}
    }
}
\pgfdeclareshape{invschmitt}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{logic ports}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{bipoles/not port/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{bipoles/not port/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{in}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{in 1}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{left}{
        \northwest
        \pgf@y=0pt
        \pgf@x=0.7\pgf@x
    }
    \anchor{bin}{
        \northwest
        \pgf@y=0pt
        \pgf@x=0.7\pgf@x
    }
    \anchor{bin 1}{
        \northwest
        \pgf@y=0pt
        \pgf@x=0.7\pgf@x
    }
    \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{right}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-0.7\pgf@x
    }
    \anchor{bout}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-0.7\pgf@x
    }
    \anchor{center}{
        \pgfpointorigin
    }
    \anchor{east}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{west}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{south}{
        \northwest
        \pgf@x=0pt
        \pgf@y=-\pgf@y
    }
    \anchor{north}{
        \northwest
        \pgf@x=0pt
    }
    \anchor{south west}{
        \northwest
        \pgf@y=-\pgf@y
    }
    \anchor{north east}{
        \northwest
        \pgf@x=-\pgf@x
    }
    \anchor{north west}{
        \northwest
    }
    \anchor{south east}{
        \northwest
        \pgf@x=-\pgf@x
        \pgf@y=-\pgf@y
    }
    \anchorborder{% this is used when the node is used as a path element
        \pgf@xa=\pgf@x
        \pgf@ya=\pgf@y
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfextractx{\pgf@circ@res@left}{\northwest}
        \pgfpointborderrectangle{\pgfpoint{\pgf@xa}{\pgf@ya}}
            {\pgfpoint{-\pgf@circ@res@left}{\pgf@circ@res@up}}
    }
    \anchor{text}{%
        % centered and a bit to the left (it's a triangle)!
        \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor

        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x

        \pgf@circ@res@other = \ctikzvalof{bipoles/not port/circle width}\pgf@circ@res@right

        \pgfscope
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgftransformxshift{.7\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=.7\pgf@circ@res@step

            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step-\pgf@circ@res@other}{0pt}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
            \pgfpathclose
            \pgf@circ@draworfill
            \pgfpathellipse
            {\pgfpoint{\pgf@circ@res@step-.5\pgf@circ@res@other}{0pt}}
            {\pgfpoint{.5\pgf@circ@res@other}{0pt}}
            {\pgfpoint{0pt}{.5\pgf@circ@res@other}}
            \pgf@circ@draworfill
        \endpgfscope

        \ifpgfcirc@draw@input@leads
            %input leads
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
            \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@left}{0pt}}
        \fi

        \ifpgfcirc@draw@output@leads
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
            \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right}{0pt}}
        \fi
        \pgfusepath{draw}
        %draw inner shape

        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}

        \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@left}{.3\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@left}{.3\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@left}{.3\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.05\pgf@circ@res@left}{.3\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{.4\pgf@circ@res@left}{.3\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{.25\pgf@circ@res@left}{.3\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{.25\pgf@circ@res@left}{.3\pgf@circ@res@up}}
        \pgfusepath{draw}

    }
}

\pgfdeclareshape{schmitt}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{logic ports}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{bipoles/not port/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{bipoles/not port/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{in}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{in 1}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{left}{
        \northwest
        \pgf@y=0pt
        \pgf@x=0.7\pgf@x
    }
    \anchor{bin}{
        \northwest
        \pgf@y=0pt
        \pgf@x=0.7\pgf@x
    }
    \anchor{bin 1}{
        \northwest
        \pgf@y=0pt
        \pgf@x=0.7\pgf@x
    }
    \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{right}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-.7\pgf@x
    }
    \anchor{bout}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-.7\pgf@x
    }
    \anchor{center}{
        \pgfpointorigin
    }
    \anchor{east}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{west}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{south}{
        \northwest
        \pgf@x=0pt
        \pgf@y=-\pgf@y
    }
    \anchor{north}{
        \northwest
        \pgf@x=0pt
    }
    \anchor{south west}{
        \northwest
        \pgf@y=-\pgf@y
    }
    \anchor{north east}{
        \northwest
        \pgf@x=-\pgf@x
    }
    \anchor{north west}{
        \northwest
    }
    \anchor{south east}{
        \northwest
        \pgf@x=-\pgf@x
        \pgf@y=-\pgf@y
    }
    \anchorborder{% this is used when the node is used as a path element
        \pgf@xa=\pgf@x
        \pgf@ya=\pgf@y
        \pgfextracty{\pgf@circ@res@up}{\northwest}
        \pgfextractx{\pgf@circ@res@left}{\northwest}
        \pgfpointborderrectangle{\pgfpoint{\pgf@xa}{\pgf@ya}}
            {\pgfpoint{-\pgf@circ@res@left}{\pgf@circ@res@up}}
    }
    \anchor{text}{%
        % centered and a bit to the left (it's a triangle)!
        \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor


        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x

        \pgfscope
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgftransformxshift{.7\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=.7\pgf@circ@res@step

            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope

        \ifpgfcirc@draw@input@leads
            %input leads
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
            \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@left}{0pt}}
        \fi

        \ifpgfcirc@draw@output@leads
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
            \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right-\pgf@circ@res@other}{0pt}}
        \fi
        \pgfusepath{draw}
        %draw inner shape

        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}

        \pgfpathmoveto{\pgfpoint{.6\pgf@circ@res@left}{.3\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@left}{.3\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@left}{.3\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{.05\pgf@circ@res@left}{.3\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{.4\pgf@circ@res@left}{.3\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{.25\pgf@circ@res@left}{.3\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{.25\pgf@circ@res@left}{.3\pgf@circ@res@up}}
        \pgfusepath{draw}

    }
}


%%% start european logic ports, from John Kormylo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%

% #1 - name
% #2 - text inside
% #3 - number of inputs
% #4 = is it a not?
%
% option to add a circle for not-output, see
% https://github.com/circuitikz/circuitikz/issues/385
%
\newif\ifpgf@circ@european@port@circle\pgf@circ@european@port@circlefalse
\newif\ifpgf@circ@european@port@circle@ieee\pgf@circ@european@port@circle@ieeefalse
\ctikzset{tripoles/european not shape/.initial=ocirc}
\ctikzset{tripoles/european not symbol/.is choice}
\ctikzset{tripoles/european not symbol/triangle/.code={\pgf@circ@european@port@circlefalse}}
\ctikzset{tripoles/european not symbol/circle/.code={%
\pgf@circ@european@port@circletrue\pgf@circ@european@port@circle@ieeefalse\ctikzset{tripoles/european not shape=ocirc}}}
\ctikzset{tripoles/european not symbol/ieee circle/.code={%
\pgf@circ@european@port@circletrue\pgf@circ@european@port@circle@ieeetrue\ctikzset{tripoles/european not shape=notcirc}}}

\long\def\pgfcircdeclareeurologicport#1#2#3#4{
    \pgfdeclareshape{european #1 port}
    {
        \savedmacro{\ctikzclass}{\edef\ctikzclass{logic ports}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \saveddimen{\boutshift}{%
            \edef\pgf@temp{not}
            \edef\pgf@circ@temp{#4}
            \ifx\pgf@temp\pgf@circ@temp % is a not
                \ifpgf@circ@european@port@circle
                    \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
                    \edef\pgf@temp{ocirc}
                    \edef\pgf@circ@temp{\ctikzvalof{tripoles/european not shape}}
                    \ifx\pgf@temp\pgf@circ@temp % it's ocirc
                        \pgfmathsetlength{\pgf@x}{2*\ctikzvalof{nodes width}*\pgf@circ@Rlen}
                    \else % it's ieee not circ
                        \pgf@circ@notradius % defined together with ieeestd ports
                        \pgf@x=2\pgf@circ@res@temp
                    \fi
                \else
                    \pgf@x=0pt
                \fi
            \else
                \pgf@x=0pt
            \fi
        }
        \savedmacro\resize{% automatic
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@circ@res@up = \ctikzvalof{tripoles/european #1 port/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@up = .5\pgf@circ@res@up
            \pgf@circ@res@down = -\pgf@circ@res@up
            \pgf@circ@res@right = \ctikzvalof{tripoles/european #1 port/width}\pgf@circ@scaled@Rlen
            \pgf@circ@res@right = .5\pgf@circ@res@right
            \pgf@circ@res@left = -\pgf@circ@res@right
        }%
        \savedmacro\inputs{% get number of inputs
            \pgf@circ@res@count=\pgfkeysvalueof{/tikz/number inputs}\relax%
            \ifnum\pgf@circ@res@count=0
                \pgf@circ@res@count=\ctikzvalof{tripoles/european #1 port/inputs}\relax%
            \fi
        \ifnum\pgf@circ@res@count<2 \pgf@circ@res@count=2\fi
    \ifnum\pgf@circ@res@count>16 \pgf@circ@res@count=16\fi
        \def\inputs{\the\pgf@circ@res@count}%
    }%
    \savedanchor\step{% 1/2 gap at edges
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@step = \ctikzvalof{tripoles/european #1 port/height}\pgf@circ@scaled@Rlen
        \divide\pgf@circ@res@step by #3
        \pgfpoint{\pgf@circ@res@left}{\dimexpr\pgf@circ@res@up+0.5\pgf@circ@res@step}%
    }%
    \savedanchor\northeast{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}%
    \savedanchor\southwest{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}%
    \savedanchor\left{\pgfpoint{\ctikzvalof{tripoles/european #1 port/reserved}\pgf@circ@res@left}{0pt}}%
    \savedanchor\right{\pgfpoint{\ctikzvalof{tripoles/european #1 port/reserved}\pgf@circ@res@right}{0pt}}%
    \savedanchor\origin{\pgfpoint{\ctikzvalof{tripoles/european #1 port/origin}\pgf@circ@res@right}{0pt}}%

    \anchor{center}{\origin}% for backwards compatibility
    % the text anchor overlaps the logic symbol
    \anchor{text}{\pgfpoint{-.5\wd\pgfnodeparttextbox}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}}%
    % create input anchors
    \ifnum#3=1\relax
        \anchor{in}{\southwest\pgfpoint{\pgf@x}{0pt}}% or \step
        \anchor{in 1}{\southwest\pgfpoint{\pgf@x}{0pt}}% or \step
        \anchor{bin}{\left\pgfpoint{\pgf@x}{0pt}}% or \step
        \anchor{bin 1}{\left\pgfpoint{\pgf@x}{0pt}}% or \step
    \else
        \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@european #1 port\endcsname{%
            \pgfmathloop%
            \ifnum\pgfmathcounter>#3
        \else%
            %\pgfutil@ifundefined{pgf@anchor@european #1 port@in \pgfmathcounter}{% redundant
            \expandafter\xdef\csname pgf@anchor@european #1 port@in \pgfmathcounter\endcsname{%
                \noexpand\pgf@circ@logicport@input{\pgfmathcounter}% defined above
            }%
            \expandafter\xdef\csname pgf@anchor@european #1 port@bin \pgfmathcounter\endcsname{%
                \noexpand\pgf@circ@logicport@baseinput{\pgfmathcounter}{4}{#1}% defined above
            }%
            %}{}%
            \repeatpgfmathloop%
        }
    \fi
    \anchor{out}{\northeast\pgf@y=0pt}
    \anchor{bout}{\right\advance\pgf@x by \boutshift\pgf@y=0pt}

    \anchor{left}{\left}% edges of component minus leads
    \anchor{right}{\right\advance\pgf@x by \boutshift\pgf@y=0pt}

    \anchor{north east}{\northeast}% see \Compass macro
    \anchor{south west}{\southwest}
    \anchor{north}{\pgfextracty{\pgf@circ@res@up}{\northeast}%
    \pgfpoint{0cm}{\pgf@circ@res@up}}
    \anchor{north west}{\pgfextracty{\pgf@circ@res@up}{\northeast}%
        \pgfextractx{\pgf@circ@res@left}{\southwest}%
    \pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \anchor{west}{\pgfextractx{\pgf@circ@res@left}{\southwest}%
    \pgfpoint{\pgf@circ@res@left}{0cm}}
    \anchor{south}{\pgfextracty{\pgf@circ@res@down}{\southwest}%
    \pgfpoint{0cm}{\pgf@circ@res@down}}
    \anchor{south east}{\pgfextracty{\pgf@circ@res@down}{\southwest}%
        \pgfextractx{\pgf@circ@res@right}{\northeast}%
    \pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \anchor{east}{\pgfextractx{\pgf@circ@res@right}{\northeast}%
    \pgfpoint{\pgf@circ@res@right}{0cm}}

    \anchorborder{% this is used when the node is used as a path element
        \pgf@xa=\pgf@x
        \pgf@ya=\pgf@y
        \pgfextracty{\pgf@circ@res@up}{\northeast}
        \pgfextractx{\pgf@circ@res@right}{\northeast}
        \pgfpointborderrectangle{\pgfpoint{\pgf@xa}{\pgf@ya}}
            {\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgfstartlinewidth=\pgflinewidth
        \pgfscope
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgfpathrectanglecorners
            {\pgfpoint{\ctikzvalof{tripoles/european #1 port/reserved}\pgf@circ@res@left}{\pgf@circ@res@up}}
            {\pgfpoint{\ctikzvalof{tripoles/european #1 port/reserved}\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgf@circ@draworfill
        \endpgfscope
        \ifpgfcirc@draw@input@leads
            %input leads
            \ifnum#3=1\relax
                \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}%
                \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/european #1 port/reserved}\pgf@circ@res@left}{0pt}}%
            \else
                \pgfextracty{\pgf@circ@res@temp}{\step}%
                \pgf@circ@res@step = \dimexpr 2\pgf@circ@res@temp -2\pgf@circ@res@up\relax
                %\pgf@circ@res@count = #3\relax% redundant
                \loop\ifnum\pgf@circ@res@count>0
                    \advance\pgf@circ@res@temp by -\pgf@circ@res@step
                    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
                    \pgfpathlineto{\pgfpoint
                        {\ctikzvalof{tripoles/european #1 port/reserved}\pgf@circ@res@left}
                    {\pgf@circ@res@temp}}
                    \advance\pgf@circ@res@count by -1
                \repeat
            \fi
            \pgfusepath{draw}
        \fi
        %
        \ifpgfcirc@draw@output@leads
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
            \pgfpathlineto{ \pgfpoint{\ctikzvalof{tripoles/european #1 port/reserved}\pgf@circ@res@right}{0pt}}
            \pgfusepath{draw}
        \fi
        %
        \edef\pgf@temp{not}
        \edef\pgf@circ@temp{#4}
        \ifx\pgf@temp\pgf@circ@temp % is a not
            \ifpgf@circ@european@port@circle
                \pgfscope
                    \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
                    \pgftransformxshift{\ctikzvalof{tripoles/european #1 port/reserved}\pgf@circ@res@right}
                    % reset  linewidth for IEEE ports, otherwise they will multiply...
                    \ifpgf@circ@european@port@circle@ieee\pgfsetlinewidth{\pgfstartlinewidth}\fi
                    \pgfnode{\ctikzvalof{tripoles/european not shape}}{west}{}{NOT}{\pgfusepath{stroke}}
                \endpgfscope
            \else
                \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/european #1 port/not width}\pgf@circ@res@right}{0pt}}
                \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/european #1 port/reserved}\pgf@circ@res@right}%
                {\ctikzvalof{tripoles/european #1 port/not height}\pgf@circ@res@up}}
                \pgfusepath{draw}
            \fi
        \fi
        \pgf@circ@text@strokecolor
        \pgfpathmoveto{\pgfpointorigin}
        \pgfscope
            % text is always in standard direction
            \pgftransformresetnontranslations
            \pgftext{\ctikzvalof{european ports font}#2}%
        \endpgfscope
        }
    }
}
\pgfcircdeclareeurologicport{and}{\&}{\pgf@circ@res@count}{}
\pgfcircdeclareeurologicport{or}{$\ge 1$}{\pgf@circ@res@count}{}
\pgfcircdeclareeurologicport{xor}{$=1$}{\pgf@circ@res@count}{}
\pgfcircdeclareeurologicport{not}{$1$}{1}{not}
\pgfcircdeclareeurologicport{buffer}{$1$}{1}{}
\pgfcircdeclareeurologicport{nand}{\&}{\pgf@circ@res@count}{not}
\pgfcircdeclareeurologicport{nor}{$\ge 1$}{\pgf@circ@res@count}{not}
\pgfcircdeclareeurologicport{xnor}{$=1$}{\pgf@circ@res@count}{not}
\pgfcircdeclareeurologicport{blank}{}{\pgf@circ@res@count}{}
\pgfcircdeclareeurologicport{blank not}{}{\pgf@circ@res@count}{not}
%% end european logic ports
% %>>>

%% IEEE standard logic ports module%<<<

%%
%% Original multi-input code from John Kormylo at tex.stackexchange.com
%% Help by TheTeXnician <38565529+TheTeXnician@users.noreply.github.com>
%% Suggested idea and example code by Jason Sachs <jmsachs@gmail.com>
%% Please see https://github.com/circuitikz/circuitikz/issues/383 for a lot of details
%% Most of the code, all errors and bugs by Romano Giannetti <romano.giannetti@gmail.com>
%% Everything is in the same place here --- more or less; first step to move towards
%% a module interface for circutikz
%%

% base settings for ieeestd ports.

\ctikzset{ieeestd ports/.is family}
% baselen is relative to pgfcirc@Rlen as ever; scaled if the class says so.
% the value of 0.4 is the standard pin distance for a port with height=num pins
% and matches the chip distance
\ctikzset{ieeestd ports/baselen/.initial=0.4}
% these are in term of baselen; width depends on height (fixed proportions)
\ctikzset{ieeestd ports/height/.initial=2}
\ctikzset{ieeestd ports/pin length/.initial=0.7}
% the standard "not" circle should be 1/6.5 of height (diameter);
% so radius/baselen=1/3.25/2    --- using 0.1 and no scaling is as a pole
\ctikzset{ieeestd ports/not radius/.initial=0.154}
\ctikzset{ieeestd ports/not radius fill/.initial=1}% change ony if you know why
% the suggested xnor distance is is 1.24, so 1.25/3.25/2
% xor/xnor leads go full in in IEEE; let this be optional
\ctikzset{ieeestd ports/xor bar distance/.initial=0.192}%
\ctikzset{ieeestd ports/xor leads in/.initial=1}%
%
% base size of a small external schmitt symbol
%
\ctikzset{ieeestd ports/schmitt symbol size/.initial=0.3}%
%
% input management
% we are using the same /tikz/number inputs than the legacy ports
%
\tikzset{/tikz/inner inputs/.initial=0} % using 0 means that all inputs are inner
%
% integrate with the other logic ports
%
%
\newif\ifpgf@circuit@ieeelogicport\pgf@circuit@ieeelogicportfalse
\ctikzset{logic ports/ieee/.code= {%
    \pgf@circuit@ieeelogicporttrue
    \pgf@circuit@europeanlogicportfalse
    \tikzset{and port/.style={shape=ieeestd and port}}%
    \tikzset{or port/.style={shape=ieeestd or port}}%
    \tikzset{xor port/.style={shape=ieeestd xor port}}%
    \tikzset{buffer port/.style={shape=ieeestd buffer port}}%
    \tikzset{not port/.style={shape=ieeestd not port}}%
    \tikzset{nand port/.style={shape=ieeestd nand port}}%
    \tikzset{nor port/.style={shape=ieeestd nor port}}%
    \tikzset{xnor port/.style={shape=ieeestd xnor port}}%
    \tikzset{schmitt port/.style={shape=ieeestd schmitt port}}%
    \tikzset{invschmitt port/.style={shape=ieeestd invschmitt port}}%
}}
% add code to be compatible with the other ports
\ctikzset{logic ports/european/.add code={\pgf@circuit@ieeelogicportfalse}}
\ctikzset{logic ports/american/.add code={\pgf@circuit@ieeelogicportfalse}}
\tikzset{ieee ports/.style = {\circuitikzbasekey/logic ports = ieee}}
%
% the base angle for the or port. See the drawings. This will not change with height
%
\pgfmathsetmacro{\pgf@circ@orangle}{atan(3.25/6.5)}
% \typeout{ANGLE-IS\space\pgf@circ@orangle}
\def\pgf@circ@ieeeport@input#1% #1 = \pgfmathcounter
{%
    \ifnum#1>\inputs
        \PackageError{circuitikz}{%
            You requested input pin #1 for logic port shape \thisshape\space \MessageBreak
            which has been defined with \inputs\space pins%
        }{Please check the manual about logic ports; if you press return I'll try to continue}
    \fi
    \pgfmathsetlength{\pgf@circ@res@up}{(\inputs/2)*\pind+0.5*\pind}% pin "0", above the rack/port
    \pgfextractx{\pgf@circ@res@left}{\bodyleft}
    \pgf@circ@res@step=\pind
    \pgf@y=\pgf@circ@res@up\advance\pgf@y by -#1\pgf@circ@res@step\relax
    \pgf@x=\pgf@circ@res@left\advance\pgf@x by -\pinlen
}%

% #1 = \pgfmathcounter #2=type
% type is 1 for and,nand; 2 for or,nor; 3 for xor,xnor
\def\pgf@circ@ieeeport@baseinput#1#2%
{%
    \ifnum#1>\inputs
        \PackageError{circuitikz}{%
            You requested border input pin #1 for logic port shape \thisshape\space \MessageBreak
            which has been defined with \inputs\space pins%
        }{Please check the manual about logic ports; if you press return I'll try to continue}
    \fi
    % Find the vertical position (this is the same for any port)
    \pgfmathsetlength{\pgf@circ@res@up}{(\inputs/2)*\pind+0.5*\pind}% pin "0", above the rack/port
    \pgf@circ@res@step=\pind\advance\pgf@circ@res@up by -#1\pgf@circ@res@step\relax
    % rack (extended) pins; they are the same for all the ports
    % call K = (inputs-inner)/2, rounded up; pins on the rack are:
    %      above: 1..K (included)
    %      below: inputs-K..inputs
    % Find the pins on the rack; they are 1...
    \pgf@circ@count@a=\numexpr (\inputs - \inners)/2\relax       % =K; numexpr rounds up!
    \pgf@circ@count@b=\numexpr \inputs - \pgf@circ@count@a +1 \relax % =inputs - K +1
    % border anchors for rack should be ok
    \pgfextractx{\pgf@circ@res@left}{\topleft}
    \pgfextractx{\pgf@circ@res@right}{\bodyleft}
    \pgf@y=\pgf@circ@res@up\pgf@x=\pgf@circ@res@left
    % we have finished if we are in the rack
    \ifnum #1 > \pgf@circ@count@a \ifnum #1 < \pgf@circ@count@b
        % we are on the inner ports; we have to do the hard work here
        % and and nand
        \ifnum #2=1
            \relax % It's an and/nand, all border ports are on the rack line
        \fi
        % or and nor
        \ifnum #2=2
            \pgfmathsetlength{\pgf@x}{\pgf@circ@res@right-2*\stdH*(1-cos(atan(\pgf@circ@res@up/(2*\stdH))))}
        \fi
        % xor and xnor
        \ifnum #2=3\relax
            \pgfmathsetlength{\pgf@x}{\pgf@circ@res@right-\xorbar-2*\stdH*(1-cos(atan(\pgf@circ@res@up/(2*\stdH))))}
        \fi
    \fi\fi
}%
% inner base ports for xor types port
% #1 = \pgfmathcounter #2=type
% type is 1 for and,nand; 2 for or,nor; 3 for xor,xnor
\def\pgf@circ@ieeeport@innerbaseinput#1%
{%
    \ifnum#1>\inputs
        \PackageError{circuitikz}{%
            You requested border input pin #1 for logic port shape \thisshape\space \MessageBreak
            which has been defined with \inputs\space pins%
        }{Please check the manual about logic ports; if you press return I'll try to continue}
    \fi
    % Find the vertical position (this is the same for any port)
    \pgfmathsetlength{\pgf@circ@res@up}{(\inputs/2)*\pind+0.5*\pind}% pin "0", above the rack/port
    \pgf@circ@res@step=\pind\advance\pgf@circ@res@up by -#1\pgf@circ@res@step\relax
    % rack (extended) pins; they are the same for all the ports
    % call K = (inputs-inner)/2, rounded up; pins on the rack are:
    %      above: 1..K (included)
    %      below: inputs-K..inputs
    % Find the pins on the rack; they are 1...
    \pgf@circ@count@a=\numexpr (\inputs - \inners)/2\relax       % =K; numexpr rounds up!
    \pgf@circ@count@b=\numexpr \inputs - \pgf@circ@count@a +1 \relax % =inputs - K +1
    % border anchors for rack should be ok
    \pgfextractx{\pgf@circ@res@left}{\topleft}
    \pgfextractx{\pgf@circ@res@right}{\bodyleft}
    \pgf@y=\pgf@circ@res@up\pgf@x=\pgf@circ@res@left
    % we have finished if we are in the rack
    \ifnum #1 > \pgf@circ@count@a \ifnum #1 < \pgf@circ@count@b
        % we are on the inner ports; we have to do the hard work here
        \pgfmathsetlength{\pgf@x}{\pgf@circ@res@right-2*\stdH*(1-cos(atan(\pgf@circ@res@up/(2*\stdH))))}
    \fi\fi
}%

%%% macro to find basic lenghts --- they leave it in \pgf@circ@res@temp
\def\pgf@circ@ieeestd@baselen{%
    \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
    \pgfmathsetlength{\pgf@circ@res@temp}{\ctikzvalof{ieeestd ports/baselen}*\pgf@circ@scaled@Rlen}
}
\def\pgf@circ@ieeestd@stdH{%
    \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
    \pgfmathsetlength{\pgf@circ@res@temp}{0.5*\ctikzvalof{ieeestd ports/baselen}*
        \ctikzvalof{ieeestd ports/height}*\pgf@circ@scaled@Rlen}
}
\def\pgf@circ@ieeestd@pinlen{%
    \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
    \pgfmathsetlength{\pgf@circ@res@temp}{\ctikzvalof{ieeestd ports/baselen}*
        \ctikzvalof{ieeestd ports/pin length}*\pgf@circ@scaled@Rlen}
}
\def\pgf@circ@ieeestd@xorbar{%
    \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
    \pgfmathsetlength{\pgf@circ@res@temp}{\ctikzvalof{ieeestd ports/baselen}*
        \ctikzvalof{ieeestd ports/xor bar distance}*\pgf@circ@scaled@Rlen}
}
%% Not circle
\def\pgf@circ@notradius{
    \pgf@circ@ieeestd@stdH % got the standard length. Notice that his is 3.25H for IEEE
    \pgfmathsetlength{\pgf@circ@res@temp}{\ctikzvalof{ieeestd ports/not radius}*\pgf@circ@res@temp}
    % \typeout{NOTRADIUS\space\the\pgf@circ@res@temp}
}
%% Find (in ...@other) the height of the rack
\def\pgf@circ@findrackH{%
    \pgf@circ@count@a=\pgfkeysvalueof{/tikz/number inputs}\relax%
    \pgf@circ@count@b=\pgfkeysvalueof{/tikz/inner inputs}\relax%
    \ifnum\pgf@circ@count@a=0 \pgf@circ@count@a=2\fi  % default pins
    \ifnum\pgf@circ@count@a<2 \pgf@circ@count@a=2\fi %
    \ifnum\pgf@circ@count@b=0 \pgf@circ@count@b=\pgf@circ@count@a\fi%
    \pgf@circ@ieeestd@stdH
    \multiply\pgf@circ@res@temp by 2\relax% full height
    \divide\pgf@circ@res@temp by \pgf@circ@count@b % the pin spacing
    \pgfmathsetlength{\pgf@circ@res@other}{(\pgf@circ@count@a/2)*\pgf@circ@res@temp} %top of the rack/port
    % \typeout{RACK-\thisshape\space\the\pgf@circ@res@other}
}
%%
\def\pgf@circ@find@ieeeport@up{% leave it in up
    % Normal port limits
    \pgf@circ@ieeestd@stdH
    \pgfmathsetlength{\pgf@circ@res@up}{\pgf@circ@res@temp}
    % rack top size
    \pgf@circ@findrackH
    \ifdim\pgf@circ@res@other > \pgf@circ@res@up
        \pgf@circ@res@up=\pgf@circ@res@other
    \else
    \fi
}
\def\pgf@circ@find@ieeeport@left#1{% leave it in left; #1 is type
    % Normal port limits
    \pgf@circ@ieeestd@stdH
    \pgfmathsetlength{\pgf@circ@res@left}{8*\pgf@circ@res@temp/6.5}
    \pgf@circ@res@right=\pgf@circ@res@left % save the border value
    \pgf@circ@res@step=\pgf@circ@res@temp % save the stdH value
    \pgf@circ@ieeestd@pinlen\advance\pgf@circ@res@left by \pgf@circ@res@temp
    % \typeout{LEFT1-\thisshape\space L\space\the\pgf@circ@res@left\space R\space\the\pgf@circ@res@right}
    % this is the normal left border
    % For the or or xor port, the limit can be the pointy thing (in case the
    % pinlen is zero or too small)
    % add to the body margin the or/nor peak:
    \ifnum #1 > 1\relax% "or", "nor", "xor", "xnor" gates.
        \pgfmathsetlength{\pgf@circ@res@other}{2*\pgf@circ@res@step*(1-cos(\pgf@circ@orangle))}
        \advance\pgf@circ@res@right by \pgf@circ@res@other
        % \typeout{LEFT2-\thisshape\space L\space\the\pgf@circ@res@left\space R\space\the\pgf@circ@res@right}
    \fi
    % add to the body margin the xor/xnor distance
    \ifnum #1 = 3\relax% "xor" or "xnor" gates.
        \pgf@circ@ieeestd@xorbar
        \advance\pgf@circ@res@right by \pgf@circ@res@temp
        % \typeout{LEFT3-\thisshape\space L\space\the\pgf@circ@res@left\space R\space\the\pgf@circ@res@right}
    \fi
    % and if this exceeds the normal margin, this is it
    % \typeout{LEFT4-\thisshape\space L\space\the\pgf@circ@res@left\space R\space\the\pgf@circ@res@right}
    \ifdim \pgf@circ@res@right > \pgf@circ@res@left
        \pgf@circ@res@left=\pgf@circ@res@right
    \fi
    % \typeout{LEFT5-\thisshape\space L\space\the\pgf@circ@res@left\space R\space\the\pgf@circ@res@right}
    \pgf@circ@res@left=-\pgf@circ@res@left
}
\def\pgf@circ@find@ieeeport@right#1{% leave it in right; #1 is plain or negated
    % Normal port limits
    \pgf@circ@ieeestd@stdH
    \pgfmathsetlength{\pgf@circ@res@right}{8*\pgf@circ@res@temp/6.5}
    \pgf@circ@notradius
    \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@res@right+2*#1*\pgf@circ@res@temp}
    \pgf@circ@ieeestd@pinlen\advance\pgf@circ@res@right by \pgf@circ@res@temp
    \ifdim\pgf@circ@res@other > \pgf@circ@res@right
        \pgf@circ@res@right=\pgf@circ@res@other
    \fi
}
\def\pgf@circ@find@ieeeport@not@right#1{% leave it in right; #1 is plain or negated
    % Normal port limits
    \pgf@circ@ieeestd@stdH
    % notice 0.8660254 is cos(30)
    \pgfmathsetlength{\pgf@circ@res@right}{0.8660254*\pgf@circ@res@temp}
    \pgf@circ@notradius
    \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@res@right+2*#1*\pgf@circ@res@temp}
    \pgf@circ@ieeestd@pinlen\advance\pgf@circ@res@right by \pgf@circ@res@temp
    \ifdim\pgf@circ@res@other > \pgf@circ@res@right
        \pgf@circ@res@right=\pgf@circ@res@other
    \fi
}


%%% ieeestd multi-input ports
%%% #1: name
%%% #2: type: 1 for and,nand; 2 for or,nor; 3 for xor,xnor
%%% #3: polarity: 0 for direct, 1 for inverted (not at the output)
%%% #4: drawing for the port
\long\def\pgfcircdeclareieeeport#1#2#3#4{%
    \pgfdeclareshape{ieeestd #1 port}%
    {%
        \savedmacro{\ctikzclass}{\edef\ctikzclass{logic ports}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
        \saveddimen{\baselen}{%
            \pgf@circ@ieeestd@baselen\pgf@x=\pgf@circ@res@temp
        }
        \saveddimen{\stdH}{% This is HALF the height of the inner port
            \pgf@circ@ieeestd@stdH\pgf@x=\pgf@circ@res@temp
        }
        \saveddimen{\notdiameter}{
            \pgf@circ@notradius\pgf@x=2\pgf@circ@res@temp
        }
        \saveddimen{\pind}{% pin distance;
            \pgf@circ@count@a=\pgfkeysvalueof{/tikz/number inputs}\relax%
            \pgf@circ@count@b=\pgfkeysvalueof{/tikz/inner inputs}\relax%
            \ifnum\pgf@circ@count@a=0 \pgf@circ@count@a=2\fi  % default pins
            \ifnum\pgf@circ@count@a<2 \pgf@circ@count@a=2\fi %
            \ifnum\pgf@circ@count@b=0 \pgf@circ@count@b=\pgf@circ@count@a\fi%
            \pgf@circ@ieeestd@stdH\pgf@x=2\pgf@circ@res@temp % full height
            \divide\pgf@x by \pgf@circ@count@b
        }
        \saveddimen{\pinlen}{%
            \pgf@circ@ieeestd@pinlen\pgf@x=\pgf@circ@res@temp
        }
        \saveddimen{\xorbar}{%
            \pgf@circ@ieeestd@xorbar\pgf@x=\pgf@circ@res@temp
        }
        % anchors for the body (no pins included here)
        \savedanchor{\bodyleft}{% This DOES NOT take into account the pointy or/xor thing
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{-8*\pgf@circ@res@temp/6.5}
            \pgfmathsetlength{\pgf@y}{\pgf@circ@res@temp}
        }
        \savedanchor{\topleft}{%
            \pgf@circ@ieeestd@xorbar\pgf@circ@res@right=\pgf@circ@res@temp % save \xorbar
            \pgf@circ@ieeestd@stdH
            \pgf@circ@res@other=0pt\relax
            \ifnum #2 = 2\relax% "or" or "nor" gates.
                \pgfmathsetlength{\pgf@circ@res@other}{2*\pgf@circ@res@temp*(1-cos(\pgf@circ@orangle))}
            \fi
            \ifnum #2 = 3\relax% "xor" or "xnor" gates.
                \pgfmathsetlength{\pgf@circ@res@other}{2*\pgf@circ@res@temp*(1-cos(\pgf@circ@orangle))
                    +\pgf@circ@res@right}
            \fi
            \pgfmathsetlength{\pgf@x}{-8*\pgf@circ@res@temp/6.5-\pgf@circ@res@other}
            \pgfmathsetlength{\pgf@y}{\pgf@circ@res@temp}
        }
        \savedanchor{\bodyright}{% This DOES NOT take into account the "NOT" circle
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{8*\pgf@circ@res@temp/6.5}
            \pgfmathsetlength{\pgf@y}{-\pgf@circ@res@temp}
        }
        \savedanchor{\bottomright}{% This DOES take into account the "NOT" circle
            \pgf@circ@notradius\pgf@circ@res@other=\pgf@circ@res@temp
            \pgf@circ@ieeestd@stdH
            % #3 is =1 if the port is a negated output one
            \pgfmathsetlength{\pgf@x}{8*\pgf@circ@res@temp/6.5+#3*2*\pgf@circ@res@other}
            \pgfmathsetlength{\pgf@y}{-\pgf@circ@res@temp}
        }
        % geographical anchors --- must be rectangulars!
        \savedanchor{\northwest}{%
            \pgf@circ@find@ieeeport@up
            \pgf@circ@find@ieeeport@left{#2}
            % \typeout{ANCH5-\thisshape\space L\space\the\pgf@circ@res@left\space U\space\the\pgf@circ@res@up}
            \pgf@x=\pgf@circ@res@left
            \pgf@y=\pgf@circ@res@up
        }
        \savedanchor{\southwest}{%
            \pgf@circ@find@ieeeport@up
            \pgf@circ@find@ieeeport@left{#2}
            \pgf@x=\pgf@circ@res@left
            \pgf@y=-\pgf@circ@res@up
        }
        \savedanchor{\southeast}{%
            \pgf@circ@find@ieeeport@up
            \pgf@circ@find@ieeeport@right{#3}
            \pgf@x=\pgf@circ@res@right
            \pgf@y=-\pgf@circ@res@up
        }
        \savedanchor{\northeast}{%
            \pgf@circ@find@ieeeport@up
            \pgf@circ@find@ieeeport@right{#3}
            \pgf@x=\pgf@circ@res@right
            \pgf@y=\pgf@circ@res@up
        }
        \savedmacro\inputs{% get number of inputs
            \pgf@circ@count@a=\pgfkeysvalueof{/tikz/number inputs}\relax
            \ifnum\pgf@circ@count@a=0\pgf@circ@count@a=2\fi    % default
            \ifnum\pgf@circ@count@a<2 \pgf@circ@count@a=2\fi   % minimum pins
            % \ifnum\pgf@circ@count@a>16 \pgf@circ@count@a=16\fi
            \def\inputs{\the\pgf@circ@count@a}%
        }%
        \savedmacro\inners{% get number of "inner" inputs (for racks)
            \pgf@circ@count@a=\pgfkeysvalueof{/tikz/number inputs}\relax
            \pgf@circ@count@b=\pgfkeysvalueof{/tikz/inner inputs}\relax
            \ifnum\pgf@circ@count@a=0 \pgf@circ@count@a=2\fi  % default pins
            \ifnum\pgf@circ@count@a<2 \pgf@circ@count@a=2\fi  % minimum pins
            \ifnum\pgf@circ@count@b=0 \pgf@circ@count@b=\pgf@circ@count@a\fi
            % \typeout{INNER is \the\pgf@circ@count@b}%
            % \ifnum\pgf@circ@count@a>16 \pgf@circ@count@a=16\fi
            \def\inners{\the\pgf@circ@count@b}%
        }%
        \anchor{center}{\pgfpointorigin}
        \anchor{text}{
            \ifpgf@circ@center@text
                \pgfpoint{-.5\wd\pgfnodeparttextbox}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}
            \else
                \pgf@circ@ieeestd@stdH
                \pgfmathsetlength{\pgf@circ@res@left}{-8*\pgf@circ@res@temp/6.5} % left border
                \pgfpoint{\pgf@circ@res@left + \ctikzvalof{left text distance}}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}
            \fi
        }
        % create input anchors
        \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@ieeestd #1 port\endcsname{%
            \pgf@circ@count@a=\inputs
            \pgfmathloop%
            \ifnum\pgfmathcounter>\pgf@circ@count@a%
            \else%
            %\pgfutil@ifundefined{pgf@anchor@american #1 port@in \pgfmathcounter}{%
            \expandafter\xdef\csname pgf@anchor@ieeestd #1 port@in \pgfmathcounter\endcsname{%
                \noexpand\pgf@circ@ieeeport@input{\pgfmathcounter}% defined above
            }%
            \expandafter\xdef\csname pgf@anchor@ieeestd #1 port@bin \pgfmathcounter\endcsname{%
                \noexpand\pgf@circ@ieeeport@baseinput{\pgfmathcounter}{#2}% defined above
            }%
            \ifnum #2 = 3\relax % xor/xnor inner border pins
                \expandafter\xdef\csname pgf@anchor@ieeestd #1 port@ibin \pgfmathcounter\endcsname{%
                    \noexpand\pgf@circ@ieeeport@innerbaseinput{\pgfmathcounter}% defined above
                }%
            \fi
            %}{}%
            \repeatpgfmathloop%
        }
        % output anchor
        \anchor{out}{%
            \pgfextractx{\pgf@circ@res@other}{\bodyright}   %body border, without not ball
            \advance\pgf@circ@res@other by\pinlen
            \pgfextractx{\pgf@circ@res@temp}{\bottomright}   %body + ball border
            \ifdim \pgf@circ@res@temp > \pgf@circ@res@other
                \pgf@circ@res@other = \pgf@circ@res@temp % do not enter in the ball...
            \fi
            \pgf@x=\pgf@circ@res@other\pgf@y=0pt
        }
        \anchor{bout}{\bottomright\pgf@y=0pt}

        \anchor{body right}{\bodyright\pgf@y=0pt}
        \anchor{right}{\bottomright\pgf@y=0pt}
        \anchor{body left}{\bodyleft\pgf@y=0pt}% central edge of the body
        \anchor{left}{% central edge of the component
            \bodyleft\pgf@y=0pt
            \ifnum #2=3\relax
                \advance\pgf@x by -\xorbar
            \fi
        }
        \anchor{up}{%
            \bodyleft
            \ifnum #2 > 1 % pointy shapes
                \pgf@circ@ieeestd@stdH
                % horizontal coordinate where the right semicircle starts
                \pgfmathsetlength{\pgf@circ@res@other}{-8*\pgf@circ@res@temp/6.5+2*\pgf@circ@res@temp*cos(\pgf@circ@orangle)}
                % vertical drop of the circle at the above coordinate
                \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@circ@res@temp*(1-cos(atan(\pgf@circ@res@other/(2*\pgf@circ@res@temp))))}
                \advance \pgf@y by -\pgf@circ@res@step
            \fi
            \pgf@x=0pt
        }
        \anchor{down}{%
            \bodyleft
            \ifnum #2 > 1 % pointy shapes
                \pgf@circ@ieeestd@stdH
                % horizontal coordinate where the right semicircle starts
                \pgfmathsetlength{\pgf@circ@res@other}{-8*\pgf@circ@res@temp/6.5+2*\pgf@circ@res@temp*cos(\pgf@circ@orangle)}
                % vertical drop of the circle at the above coordinate
                \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@circ@res@temp*(1-cos(atan(\pgf@circ@res@other/(2*\pgf@circ@res@temp))))}
                \advance \pgf@y by -\pgf@circ@res@step
            \fi
            \pgf@y=-\pgf@y\pgf@x=0pt
        }

        % geographical anchors
        \anchor{nw}{\northwest}
        \anchor{ne}{\northeast}
        \anchor{se}{\southeast}
        \anchor{sw}{\southwest}
        \anchor{north west}{\northwest}
        \anchor{north east}{\northeast}
        \anchor{south east}{\southeast}
        \anchor{south west}{\southwest}
        % over 0,0 even if asymmetric
        % will break if the geocoords are not rectangular
        \anchor{n}{\northwest\pgf@x=0pt\relax}
        \anchor{e}{\northeast\pgf@y=0pt\relax}
        \anchor{s}{\southwest\pgf@x=0pt\relax}
        \anchor{w}{\northwest\pgf@y=0pt\relax}
        \anchor{north}{\northwest\pgf@x=0pt\relax}
        \anchor{east}{\northeast\pgf@y=0pt\relax}
        \anchor{south}{\southwest\pgf@x=0pt\relax}
        \anchor{west}{\northwest\pgf@y=0pt\relax}

        \pgf@circ@draw@component{
            \pgfscope
                \pgf@circ@setcolor
                #4%
            \endpgfscope
            % output lead:
            \pgfextractx{\pgf@circ@res@right}{\bottomright} %body+ball border
            \pgfextractx{\pgf@circ@res@other}{\bodyright}   %body border, without "not" ball
            \advance\pgf@circ@res@other by \pinlen\relax
            \ifdim \pgf@circ@res@other > \pgf@circ@res@right
                \ifpgfcirc@draw@output@leads
                    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}
                    \pgfusepath{draw}
                \fi
            \fi
            \ifnum #3=1\relax\pgfscope
                \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{0pt}}
                \pgfnode{notcirc}{east}{}{\thisshape-not}{\pgfusepath{stroke}}
            \endpgfscope\fi
        }
    }
}

%%% #1 direct name #2 negated name #3 type #4 drawing (without output)
\long\def\pgfcircdeclareieeeportpair#1#2#3#4{%
    \pgfcircdeclareieeeport{#1}{#3}{0}{#4}% direct
    \pgfcircdeclareieeeport{#2}{#3}{1}{#4}% negated
}
%
% ieeestd "and" and "nand"
%
\pgfcircdeclareieeeportpair{and}{nand}{1}{%
    \pgf@circ@count@a = \inputs\relax
    \pgfmathsetlength{\pgf@circ@res@up}{(\inputs/2)*\pind} %top of the rack/port
    \pgfmathsetlength{\pgf@circ@res@temp}{\pgf@circ@res@up+0.5*\pind}
    \pgfextractx{\pgf@circ@res@left}{\bodyleft}
    \pgfextracty{\pgf@circ@res@down}{\bodyleft}
    \ifpgfcirc@draw@input@leads
        %input leads --- all the same for AND ports
        \loop\ifnum\pgf@circ@count@a>0
        \advance\pgf@circ@res@temp by -\pind
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}%
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pinlen}{\pgf@circ@res@temp}}%
        \advance\pgf@circ@count@a by -1
        \repeat
    \fi
    \pgfusepath{draw}
    %% Body. let's start from the top left
    \pgfscope
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfpathmoveto{\pgfpoint{-8*\stdH/6.5}{\stdH}}
        \pgfpathlineto{\pgfpoint{1.5*\stdH/6.5}{\stdH}}
        \pgfpatharc{90}{-90}{\stdH}
        \pgfpathlineto{\pgfpoint{-8*\stdH/6.5}{-\stdH}}
        \pgfpathclose
        \pgf@circ@draworfill
        % rack now; skip if not needed.
        % \typeout{WHAT\space \inputs\space \inners}
        \ifnum\inputs>\inners
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up}}
            \pgfusepath{draw}
        \fi
    \endpgfscope
}
%
% or/nor and xor/xnor are practically the same. Let factor out everything
% the argument #1 is put just before the drawing of the inner pins
% the argument #2 is put after the drawing of the body
%
\long\def\pgf@circ@ieeeport@orxor#1#2{%
    \pgf@circ@count@a = \inputs\relax
    \pgfmathsetlength{\pgf@circ@res@up}{(\inputs/2)*\pind} %top of the rack/port
    \pgfmathsetlength{\pgf@circ@res@temp}{\pgf@circ@res@up+0.5*\pind}
    \pgfextractx{\pgf@circ@res@left}{\bodyleft}
    \pgfextracty{\pgf@circ@res@down}{\bodyleft}
    % rack (extended) pins; they are the same for all the ports
    % call K = (inputs-inner)/2, rounded up; pins on the rack are:
    %      above: 1..K (included)
    %      below: inputs-K..inputs
    % Find the pins on the rack; they are 1...
    \pgf@circ@count@b=\numexpr (\inputs - \inners)/2\relax       % =K; numexpr rounds up!
    \pgf@circ@count@c=\numexpr \inputs - \pgf@circ@count@b +1 \relax % =inputs - K +1
    \ifpgfcirc@draw@input@leads
        %input leads --- for or ports
        \loop\ifnum\pgf@circ@count@a>0
        \pgfextractx{\pgf@circ@res@right}{\topleft}
        \advance\pgf@circ@res@temp by -\pind
        % this is the height; let's find the "right" position
        \ifnum \pgf@circ@count@a > \pgf@circ@count@b \ifnum \pgf@circ@count@a < \pgf@circ@count@c
            % inner pins
            % \typeout{INNER\space\pgf@circ@count@a}
            \pgfmathsetlength{\pgf@circ@res@right}{\pgf@circ@res@left-2*\stdH*(1-cos(atan(\pgf@circ@res@temp/(2*\stdH))))}
            % hook for xor/xnor
            #1%
        \fi\fi
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@temp}}%
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pinlen}{\pgf@circ@res@temp}}%
        \pgfusepath{draw}
        \advance\pgf@circ@count@a by -1
        \repeat
    \fi
    %% Body. let's start from the top left
    \pgfscope
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        % it should start here, but with this trick the close comes out better.
        % \pgfpathmoveto{\pgfpoint{-8*\stdH/6.5-2*\stdH*(1-cos(\pgf@circ@orangle))}{\stdH}}
        \pgfpathmoveto{\pgfpoint{-8*\stdH/6.5}{\stdH}}
        \pgfpathlineto{\pgfpoint{8*\stdH/6.5-2*\stdH*cos(\pgf@circ@orangle)}{\stdH}} %
        \pgfpatharcto{2*\stdH}{2*\stdH}{0}{0}{0}{\pgfpoint{8*\stdH/6.5}{0pt}}
        \pgfpatharcto{2*\stdH}{2*\stdH}{0}{0}{0}{\pgfpoint{8*\stdH/6.5-2*\stdH*cos(\pgf@circ@orangle)}{-\stdH}}
        \pgfpathlineto{\pgfpoint{-8*\stdH/6.5-2*\stdH*(1-cos(\pgf@circ@orangle))}{-\stdH}}
        %% this should be 2 and 2; but the round part is not a perfect circle that way
        %% so the 2.15 is ajusted "by taste" to touch the anchors exactly.
        \pgfpatharcto{2*\stdH}{2.2*\stdH}{0}{0}{1}{\pgfpoint{-8*\stdH/6.5-2*\stdH*(1-cos(\pgf@circ@orangle))}{\stdH}}
        \pgfpathclose
        \pgf@circ@draworfill
        % hook for xor/xnor
        #2%
        % rack now; skip if not needed.
        % \typeout{WHAT\space \inputs\space \inners}
        \ifnum\inputs>\inners
            \pgfextractx{\pgf@circ@res@left}{\topleft}
            \pgfextracty{\pgf@circ@res@down}{\topleft}
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up}}
            \pgfusepath{draw}
        \fi
    \endpgfscope
}
%
% ieeestd "or" and "nor"
%
\pgfcircdeclareieeeportpair{or}{nor}{2}{%
    \pgf@circ@ieeeport@orxor{}{}
}
\pgfcircdeclareieeeportpair{xor}{xnor}{3}{%
    \pgf@circ@ieeeport@orxor{
        \edef\@@tmp{\ctikzvalof{ieeestd ports/xor leads in}}
        \ifnum\@@tmp=0\relax
            % move pin start to the left to leave the xor gap free (not standard)
            \advance\pgf@circ@res@right by -\xorbar
        \fi
        }{%
        % add the xor/xnor bar
        \pgfpathmoveto{\pgfpoint{-\xorbar-8*\stdH/6.5-2*\stdH*(1-cos(\pgf@circ@orangle))}{-\stdH}}
        % see the comment on the main body about the 2.2
        \pgfpatharcto{2*\stdH}{2.2*\stdH}{0}{0}{1}{\pgfpoint{-\xorbar -8*\stdH/6.5-2*\stdH*(1-cos(\pgf@circ@orangle))}{\stdH}}
        \pgfusepath{draw}
    }
}
%
% Buffer and inverters
%
% #1: name
% #2: polarity
% #3: content
\long\def\pgfcircdeclareieeebufferport#1#2#3{%
    \pgfdeclareshape{ieeestd #1 port}%
    {%
        \savedmacro{\ctikzclass}{\edef\ctikzclass{logic ports}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
        \saveddimen{\baselen}{%
            \pgf@circ@ieeestd@baselen\pgf@x=\pgf@circ@res@temp
        }
        \saveddimen{\stdH}{% This is HALF the height of the inner port
            \pgf@circ@ieeestd@stdH\pgf@x=\pgf@circ@res@temp
        }
        \saveddimen{\notdiameter}{
            \pgf@circ@notradius\pgf@x=2\pgf@circ@res@temp
        }
        \saveddimen{\pinlen}{%
            \pgf@circ@ieeestd@pinlen\pgf@x=\pgf@circ@res@temp
        }
        % anchors for the body (no pins included here)
        % Notice that 0.8660254 is cos(30)
        \savedanchor{\bodyleft}{% This DOES NOT take into account the pointy or/xor thing
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{-0.8660254*\pgf@circ@res@temp}
            \pgfmathsetlength{\pgf@y}{\pgf@circ@res@temp}
        }
        \savedanchor{\topleft}{%
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{-0.8660254*\pgf@circ@res@temp}
            \pgfmathsetlength{\pgf@y}{\pgf@circ@res@temp}
        }
        \savedanchor{\bodyright}{% This DOES NOT take into account the "NOT" circle
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{0.8660254*\pgf@circ@res@temp}
            \pgfmathsetlength{\pgf@y}{\pgf@circ@res@temp}
        }
        \savedanchor{\bottomright}{% This DOES take into account the "NOT" circle
            \pgf@circ@notradius\pgf@circ@res@other=\pgf@circ@res@temp
            \pgf@circ@ieeestd@stdH
            % #2 is =1 if the port is a negated output one
            \pgfmathsetlength{\pgf@x}{0.8660254*\pgf@circ@res@temp+#2*2*\pgf@circ@res@other}
            \pgfmathsetlength{\pgf@y}{-\pgf@circ@res@temp}
        }
        % geographical anchors --- must be rectangulars!
        \savedanchor{\northwest}{%
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{-0.8660254*\pgf@circ@res@temp}
            \pgfmathsetlength{\pgf@y}{\pgf@circ@res@temp}
        }
        \savedanchor{\southwest}{%
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{-0.8660254*\pgf@circ@res@temp}
            \pgfmathsetlength{\pgf@y}{-\pgf@circ@res@temp}
        }
        \savedanchor{\southeast}{%
            \pgf@circ@ieeestd@stdH
            \pgf@circ@res@up=\pgf@circ@res@temp
            \pgf@circ@find@ieeeport@not@right{#2}
            \pgf@x=\pgf@circ@res@right
            \pgf@y=-\pgf@circ@res@up
        }
        \savedanchor{\northeast}{%
            \pgf@circ@ieeestd@stdH
            \pgf@circ@res@up=\pgf@circ@res@temp
            \pgf@circ@find@ieeeport@not@right{#2}
            \pgf@x=\pgf@circ@res@right
            \pgf@y=\pgf@circ@res@up
        }
        \anchor{center}{\pgfpointorigin}
        \anchor{text}{
            \ifpgf@circ@center@text
                \pgfpoint{-.5\wd\pgfnodeparttextbox}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}
            \else
                \pgf@circ@ieeestd@stdH
                \pgfpoint{-0.8660254*\pgf@circ@res@temp + \ctikzvalof{left text distance}}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}
            \fi
        }
        % input anchors
        \anchor{in}{\bodyleft\pgf@y=0pt\advance\pgf@x by-\pinlen}
        \anchor{in 1}{\bodyleft\pgf@y=0pt\advance\pgf@x by-\pinlen}
        \anchor{bin}{\bodyleft\pgf@y=0pt\relax}
        \anchor{bin 1}{\bodyleft\pgf@y=0pt\relax}
        % output anchors
        \anchor{out}{%
            \pgfextractx{\pgf@circ@res@other}{\bodyright}   %body border, without not ball
            \advance\pgf@circ@res@other by\pinlen
            \pgfextractx{\pgf@circ@res@temp}{\bottomright}   %body + ball border
            \ifdim \pgf@circ@res@temp > \pgf@circ@res@other
                \pgf@circ@res@other = \pgf@circ@res@temp % do not enter in the ball...
            \fi
            \pgf@x=\pgf@circ@res@other\pgf@y=0pt
        }
        \anchor{bout}{\bottomright\pgf@y=0pt}

        \anchor{body right}{\bodyright\pgf@y=0pt}
        \anchor{right}{\bottomright\pgf@y=0pt}
        \anchor{body left}{\bodyleft\pgf@y=0pt}% central edge of the body
        \anchor{left}{\bodyleft\pgf@y=0pt}
        \anchor{up}{%
            \bodyleft
            \pgf@y=+0.5\pgf@y\pgf@x=0pt
        }
        \anchor{down}{%
            \bodyleft
            \pgf@y=-0.5\pgf@y\pgf@x=0pt
        }
        % this is for when it's used as a bipole
        % we use the enclosing rectangle (see below)
        \anchorborder{%
            %% This (commented out) is the correct border anchor. But if we use the correct
            %% border anchor there is no horizontal space for the label ;-) because
            %% the triangle is too steep. So we will use a simple square border
            %%
            %% find the border anchor of a triangle (like a not port or an
            %% amplifier) ---
            %%
            %%      -----^ up
            %%     I --- |
            %%     I    -|--
            %%left I     |  ---    right
            %% ----I-----|-------I-----
            %%
            %%
            %\pgf@xa=\pgf@x
            %% it's simmetrical w/ vertical side, use only positive y
            %\pgfmathsetmacro{\@@switchy}{ifthenelse(\pgf@y>0,1,-1)}
            %\pgfmathsetlength{\pgf@ya}{abs(\pgf@y)}
            %\pgfextracty{\pgf@circ@res@up}{\bodyleft}
            %\pgfextractx{\pgf@circ@res@left}{\bodyleft}
            %\pgfextractx{\pgf@circ@res@right}{\bodyright}
            %% limit angle for the left (vertical) side
            %\pgfmathsetmacro{\@@phimax}{atan2(\pgf@circ@res@up,\pgf@circ@res@left)}
            %\pgfmathsetmacro{\@@phi}{atan2(\pgf@ya,\pgf@xa)}
            %\pgfmathsetmacro{\@@leftside}{ifthenelse(\@@phi>\@@phimax,1,0)}
            %% find the border
            %\ifnum\@@leftside>0
            %    % vertical side
            %    \pgfpointborderrectangle{\pgfpoint{\pgf@xa}{\pgf@ya}}
            %        {\pgfpoint{-\pgf@circ@res@left}{\pgf@circ@res@up}}
            %\else
            %    % triangle upper line
            %    \pgfpointintersectionoflines
            %        {\pgfpointorigin}{\pgfqpoint{\pgf@xa}{\pgf@ya}}
            %        {\pgfqpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfqpoint{\pgf@circ@res@right}{0pt}}
            %\fi
            %% readjust y sign
            %\pgf@y=\@@switchy\pgf@y
            %
            % this is the square border to position the path label with a bit of horizontal space
            %
            \pgf@xa=\pgf@x
            \pgf@ya=\pgf@y
            \pgfextracty{\pgf@circ@res@up}{\bodyleft}
            \pgfextractx{\pgf@circ@res@left}{\bodyleft}
            \pgfpointborderrectangle{\pgfpoint{\pgf@xa}{\pgf@ya}}
                {\pgfpoint{-\pgf@circ@res@left}{\pgf@circ@res@up}}
        }
        % geographical anchors
        \anchor{nw}{\northwest}
        \anchor{ne}{\northeast}
        \anchor{se}{\southeast}
        \anchor{sw}{\southwest}
        \anchor{north west}{\northwest}
        \anchor{north east}{\northeast}
        \anchor{south east}{\southeast}
        \anchor{south west}{\southwest}
        % over 0,0 even if asymmetric
        % will break if the geocoords are not rectangular
        \anchor{n}{\northwest\pgf@x=0pt\relax}
        \anchor{e}{\northeast\pgf@y=0pt\relax}
        \anchor{s}{\southwest\pgf@x=0pt\relax}
        \anchor{w}{\northwest\pgf@y=0pt\relax}
        \anchor{north}{\northwest\pgf@x=0pt\relax}
        \anchor{east}{\northeast\pgf@y=0pt\relax}
        \anchor{south}{\southwest\pgf@x=0pt\relax}
        \anchor{west}{\northwest\pgf@y=0pt\relax}

        \pgf@circ@draw@component{
            \pgfscope
                \pgf@circ@setcolor
                #3%
            \endpgfscope
            % output lead:
            \pgfextractx{\pgf@circ@res@right}{\bottomright} %body+ball border
            \pgfextractx{\pgf@circ@res@other}{\bodyright}   %body border, without "not" ball
            \advance\pgf@circ@res@other by \pinlen\relax
            \ifdim \pgf@circ@res@other > \pgf@circ@res@right
                \ifpgfcirc@draw@output@leads
                    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}
                    \pgfusepath{draw}
                \fi
            \fi
            \ifnum #2=1\relax\pgfscope
                \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{0pt}}
                \pgfnode{notcirc}{east}{}{\thisshape-not}{\pgfusepath{stroke}}
            \endpgfscope\fi
        }
    }
}

%%% #1 direct name #2 negated name #3 drawing (without output)
\long\def\pgfcircdeclareieeebufferportpair#1#2#3{%
    \pgfcircdeclareieeebufferport{#1}{0}{#3}% direct
    \pgfcircdeclareieeebufferport{#2}{1}{#3}% negated
}

\pgfcircdeclareieeebufferportpair{buffer}{not}{%
    \pgfextractx{\pgf@circ@res@left}{\bodyleft}
    \pgfextracty{\pgf@circ@res@up}{\bodyleft}
    \pgfextractx{\pgf@circ@res@right}{\bodyright}
    % \draw input pin
    \ifpgfcirc@draw@input@leads
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pinlen}{0pt}}
        \pgfusepath{draw}
    \fi
    \pgfscope
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up}}
        \pgfpathclose
        \pgf@circ@draworfill
    \endpgfscope
}

\pgfcircdeclareieeebufferportpair{schmitt}{invschmitt}{%
    \pgfextractx{\pgf@circ@res@left}{\bodyleft}
    \pgfextracty{\pgf@circ@res@up}{\bodyleft}
    \pgfextractx{\pgf@circ@res@right}{\bodyright}
    % \draw input pin
    \ifpgfcirc@draw@input@leads
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pinlen}{0pt}}
        \pgfusepath{draw}
    \fi
    \pgfscope
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up}}
        \pgfpathclose
        \pgf@circ@draworfill
    \endpgfscope
    % draw schmitt symbol in normal line thickness
    \pgfpathmoveto{\pgfpoint{0.75*\pgf@circ@res@left}{-0.25*\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.50*\pgf@circ@res@left}{-0.25*\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.50*\pgf@circ@res@left}{0.25*\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.00*\pgf@circ@res@left}{0.25*\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{0.25*\pgf@circ@res@left}{0.25*\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.25*\pgf@circ@res@left}{-0.25*\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.5*\pgf@circ@res@left}{-0.25*\pgf@circ@res@up}}
    \pgfusepath{draw}
}


\pgfdeclareshape{schmitt symbol}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{logic ports}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor\northwest{%
        \pgf@circ@ieeestd@stdH
        \pgf@y=\ctikzvalof{ieeestd ports/schmitt symbol size}\pgf@circ@res@temp
        \pgf@x=-1.5\pgf@y
    }
    \anchor{center}{\pgf@y=0pt \pgf@x=0pt}
    \anchor{east}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{e}{\northwest\pgf@y=0pt \pgf@x=-\pgf@x}
    \anchor{west}{\northwest\pgf@y=0pt}
    \anchor{w}{\northwest \pgf@y=0pt}
    \anchor{south}{\northwest \pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{s}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{north}{\northwest\pgf@x=0pt}
    \anchor{n}{\northwest\pgf@x=0pt}
    \anchor{south west}{\northwest\pgf@y=-\pgf@y}
    \anchor{north east}{\northwest\pgf@x=-\pgf@x}
    \anchor{north west}{\northwest}
    \anchor{south east}{\northwest\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
    \pgf@circ@draw@component{
        \pgfscope
            \pgf@circ@setcolor
            \pgfextractx{\pgf@circ@res@left}{\northwest}
            \pgfextracty{\pgf@circ@res@up}{\northwest}
            \pgf@circ@res@left=0.7\pgf@circ@res@left
            \pgf@circ@res@up=0.7\pgf@circ@res@up
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left/3}{-\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left/3}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{-\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@left/3}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{-\pgf@circ@res@left/3}{-\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up}}
            \pgfusepath{draw}
        \endpgfscope
    }
}

\pgfdeclareshape{notcirc}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{logic ports}}
    \savedanchor\northwest{%
        \pgf@circ@notradius
        \pgf@y=\pgf@circ@res@temp
        \pgf@x=-\pgf@y
    }
    \pgfcirc@northwest@symmetric@geoanchors
    \anchor{center}{\pgfpointorigin}
    \anchorborder{
        \pgf@circ@res@left=\pgf@x
        \pgf@circ@res@up=\pgf@y
        \northwest\pgf@circ@res@temp=\pgf@y
        \pgfpointborderellipse{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}%
        {\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@temp}}
    }
    \pgf@circ@draw@component{
        \pgfscope
            \northwest\pgf@circ@res@temp=\pgf@y
            \pgf@circ@setcolor
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgfpathcircle{\pgfpointorigin}{\pgf@circ@res@temp}
            \ifx\tikz@fillcolor\pgfutil@empty
                % set the default fill color to white
                \pgfsetfillcolor{white}
                % ...but override it if the class is defined!
                \pgf@circ@setifdefinedfill{draw, fill}{draw, fill}
            \else
                \pgfsetfillcolor{\tikz@fillcolor}
            \fi
            \pgfsetfillopacity{\ctikzvalof{ieeestd ports/not radius fill}}% normally 1.0
            \pgfusepath{draw,fill}
        \endpgfscope
    }
}

%%%% Transmission gates
% tgates are only ieee style for now
\tikzset{%
    tgate/.style ={shape=ieee tgate},
    double tgate/.style ={shape=ieee double tgate},
}
\ctikzset{tgate scale/.initial=0.7}
% Buffer and inverters
%
% #1: name
% #2: 1: one-not, 2:double-not
% #3: content
\long\def\pgfcircdeclareieeetgate#1#2#3{%
    \pgfdeclareshape{ieee #1}%
    {%
        \savedmacro{\ctikzclass}{\edef\ctikzclass{logic ports}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
        \saveddimen{\baselen}{%
            \pgf@circ@ieeestd@baselen\pgf@x=\pgf@circ@res@temp
        }
        \saveddimen{\stdH}{% This is HALF the height of the inner port
            \pgf@circ@ieeestd@stdH\pgf@x=\pgf@circ@res@temp
        }
        \saveddimen{\notdiameter}{
            \pgf@circ@notradius\pgf@x=2\pgf@circ@res@temp
        }
        \saveddimen{\notradius}{
            \pgf@circ@notradius\pgf@x=\pgf@circ@res@temp
        }
        \saveddimen{\pinlen}{%
            \pgf@circ@ieeestd@pinlen\pgf@x=\pgf@circ@res@temp
        }
        % anchors for the body (no pins included here)
        % Notice that 0.8660254 is cos(30)
        \savedanchor{\bodyleft}{% This DOES NOT take into account the pointy or/xor thing
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{-2*0.8660254*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
            \pgfmathsetlength{\pgf@y}{#2*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
        }
        \savedanchor{\topleft}{%
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{-2*0.8660254*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
            \pgfmathsetlength{\pgf@y}{#2*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
        }
        \savedanchor{\bodyright}{%
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{2*0.8660254*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
            \pgfmathsetlength{\pgf@y}{#2*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
        }
        \savedanchor{\bottomright}{% Here it is the same as \bodyright
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{2*0.8660254*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
            \pgfmathsetlength{\pgf@y}{#2*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
        }
        % geographical anchors --- must be rectangulars!
        \savedanchor{\northwest}{%
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{-2*0.8660254*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
            \pgfmathsetlength{\pgf@y}{#2*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
        }
        \savedanchor{\southwest}{%
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{-2*0.8660254*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
            \pgfmathsetlength{\pgf@y}{-#2*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
        }
        \savedanchor{\southeast}{%
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{2*0.8660254*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
            \pgfmathsetlength{\pgf@y}{-#2*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
        }
        \savedanchor{\northeast}{%
            \pgf@circ@ieeestd@stdH
            \pgfmathsetlength{\pgf@x}{2*0.8660254*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
            \pgfmathsetlength{\pgf@y}{#2*\pgf@circ@res@temp*\ctikzvalof{tgate scale}}
        }
        \anchor{center}{\pgfpointorigin}
        \anchor{text}{
            \ifpgf@circ@center@text
                \pgfpoint{-.5\wd\pgfnodeparttextbox}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}
            \else
                \pgf@circ@ieeestd@stdH
                \pgfpoint{-0.8660254*\pgf@circ@res@temp + \ctikzvalof{left text distance}}{\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox}
            \fi
        }
        % input anchors
        \anchor{in}{\bodyleft\pgf@y=0pt\advance\pgf@x by-\pinlen}
        \anchor{in 1}{\bodyleft\pgf@y=0pt\advance\pgf@x by-\pinlen}
        \anchor{bin}{\bodyleft\pgf@y=0pt\relax}
        \anchor{bin 1}{\bodyleft\pgf@y=0pt\relax}
        % gates
        \anchor{gate}{\bodyleft\pgf@circ@res@up=\pgf@y
            \pgf@x=0pt\pgfmathsetlength{\pgf@y}{-(#2-1)*0.5*\pgf@circ@res@up-\pinlen}}
        \anchor{bgate}{\bodyleft\pgf@circ@res@up=\pgf@y
            \pgf@x=0pt\pgfmathsetlength{\pgf@y}{-(#2-1)*0.5*\pgf@circ@res@up}}
        % gate (up) (2.1547 = 1+1/cos(30)
        \anchor{notgate}{\bodyleft\pgf@circ@res@up=\pgf@y
            \pgf@x=0pt\relax
            \pgfmathsetlength{\pgf@circ@res@temp}{2.1547*\notradius}
            \ifdim\pinlen>\pgf@circ@res@temp
                \pgfmathsetlength{\pgf@y}{(#2-1)*0.5*\pgf@circ@res@up+\pinlen}
            \else
                \pgf@y=\pgf@circ@res@temp
            \fi
        }
        \anchor{bnotgate}{\bodyleft\pgf@circ@res@up=\pgf@y
            \pgf@x=0pt\pgfmathsetlength{\pgf@y}{(#2-1)*0.5*\pgf@circ@res@up+2.1547*\notradius}}

        % output anchors
        \anchor{out}{%
            \pgfextractx{\pgf@circ@res@other}{\bodyright}   %body border, without not ball
            \advance\pgf@circ@res@other by\pinlen
            \pgfextractx{\pgf@circ@res@temp}{\bottomright}   %body + ball border
            \ifdim \pgf@circ@res@temp > \pgf@circ@res@other
                \pgf@circ@res@other = \pgf@circ@res@temp % do not enter in the ball...
            \fi
            \pgf@x=\pgf@circ@res@other\pgf@y=0pt
        }
        \anchor{bout}{\bottomright\pgf@y=0pt}

        \anchor{body right}{\bodyright\pgf@y=0pt}
        \anchor{right}{\bottomright\pgf@y=0pt}
        \anchor{body left}{\bodyleft\pgf@y=0pt}% central edge of the body
        \anchor{left}{\bodyleft\pgf@y=0pt}
        \anchor{up}{%
            \bodyleft
            \pgf@x=0pt
            \ifnum#2=1\relax
                \pgf@y=0pt
            \else
                \pgf@y=.5\pgf@y
            \fi
            \advance\pgf@y by \notdiameter
        }
        \anchor{down}{%
            \bodyleft
            \pgf@x=0pt
            \ifnum#2=1\relax
                \pgf@y=0pt
            \else
                \pgf@y=-.5\pgf@y
            \fi
        }
        % this is for when it's used as a bipole
        % we use the enclosing rectangle (see below)
        \anchorborder{%
            %
            % this is the square border to position the path label with a bit of horizontal space
            %
            \pgf@xa=\pgf@x
            \pgf@ya=\pgf@y
            \pgfextracty{\pgf@circ@res@up}{\bodyleft}
            \pgfextractx{\pgf@circ@res@left}{\bodyleft}
            \pgfpointborderrectangle{\pgfpoint{\pgf@xa}{\pgf@ya}}
                {\pgfpoint{-\pgf@circ@res@left}{\pgf@circ@res@up}}
        }
        % geographical anchors
        \anchor{nw}{\northwest}
        \anchor{ne}{\northeast}
        \anchor{se}{\southeast}
        \anchor{sw}{\southwest}
        \anchor{north west}{\northwest}
        \anchor{north east}{\northeast}
        \anchor{south east}{\southeast}
        \anchor{south west}{\southwest}
        % over 0,0 even if asymmetric
        % will break if the geocoords are not rectangular
        \anchor{n}{\northwest\pgf@x=0pt\relax}
        \anchor{e}{\northeast\pgf@y=0pt\relax}
        \anchor{s}{\southwest\pgf@x=0pt\relax}
        \anchor{w}{\northwest\pgf@y=0pt\relax}
        \anchor{north}{\northwest\pgf@x=0pt\relax}
        \anchor{east}{\northeast\pgf@y=0pt\relax}
        \anchor{south}{\southwest\pgf@x=0pt\relax}
        \anchor{west}{\northwest\pgf@y=0pt\relax}

        \pgf@circ@draw@component{
            \pgfscope
                \pgf@circ@setcolor
                \pgfextractx{\pgf@circ@res@left}{\bodyleft}
                \pgfextracty{\pgf@circ@res@up}{\bodyleft}
                \pgfextractx{\pgf@circ@res@right}{\bodyright}
                % \draw input pins
                \ifpgfcirc@draw@input@leads
                    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pinlen}{0pt}}
                    % gate (down)
                    \pgfpathmoveto{\pgfpoint{0pt}{-(#2-1)*0.5*\pgf@circ@res@up}}
                    \pgfpathlineto{\pgfpoint{0pt}{-(#2-1)*0.5*\pgf@circ@res@up-\pinlen}}
                    % gate (up) (2.1547 = 1+1/cos(30)
                    \pgfmathsetlength{\pgf@circ@res@temp}{2.1547*\notradius}
                    \ifdim\pinlen>\pgf@circ@res@temp
                        \pgfpathmoveto{\pgfpoint{0pt}{(#2-1)*0.5*\pgf@circ@res@up+\pgf@circ@res@temp}}
                        \pgfpathlineto{\pgfpoint{0pt}{(#2-1)*0.5*\pgf@circ@res@up+\pinlen}}
                    \fi
                    \pgfusepath{draw}
                \fi
                #3%
            \endpgfscope
            % output lead:
            \pgfextractx{\pgf@circ@res@right}{\bottomright} %body+ball border
            \pgfextractx{\pgf@circ@res@other}{\bodyright}   %body border, without "not" ball
            \advance\pgf@circ@res@other by \pinlen\relax
            \ifdim \pgf@circ@res@other > \pgf@circ@res@right
                \ifpgfcirc@draw@output@leads
                    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{0pt}}
                    \pgfusepath{draw}
                \fi
            \fi
        }
    }
}

\pgfcircdeclareieeetgate{tgate}{1}{%
    \pgfscope
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up}}
        \pgfpathclose
        \pgf@circ@draworfill
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgf@circ@res@up}}
        \pgfpathclose
        \pgf@circ@draworfill
    \endpgfscope
    \pgfscope
        % 1.1547 is 1/cos(30)
        \pgftransformshift{\pgfpoint{0pt}{1.1547*\notradius}}
        \pgfnode{notcirc}{center}{}{\thisshape-not}{\pgfusepath{stroke}}
    \endpgfscope
}

\pgfcircdeclareieeetgate{double tgate}{2}{%
    \pgfscope
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathclose
        \pgf@circ@draworfill
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathclose
        \pgf@circ@draworfill
        % bottom triangles
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{-.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathclose
        \pgf@circ@draworfill
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{-\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{-.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathclose
        \pgf@circ@draworfill
    \endpgfscope
    \pgfscope
        % 1.1547 is 1/cos(30)
        \pgftransformshift{\pgfpoint{0pt}{.5*\pgf@circ@res@up+1.1547*\notradius}}
        \pgfnode{notcirc}{center}{}{\thisshape-not}{\pgfusepath{stroke}}
    \endpgfscope
}% %>>>

%% Path-style definitions for logical ports%<<<
%
% create path-style element for one input --- one output logical ports
%
\def\pgfcirc@port@node@to@path#1#2{%
    %
    % add a logic port path style component --- we need to suppress leads
    % and use the correct center
    %
    \pgfcirc@node@to@path{#1}{#2}{/tikz/no leads, \circuitikzbasekey/logic ports origin=center}%
}
\pgfcirc@port@node@to@path{not port}{inline not}
\pgfcirc@port@node@to@path{buffer port}{inline buffer}
\pgfcirc@port@node@to@path{schmitt port}{inline schmitt}
\pgfcirc@port@node@to@path{invschmitt port}{inline invschmitt}

\pgfcirc@port@node@to@path{tgate}{inline tgate}
\pgfcirc@port@node@to@path{double tgate}{inline double tgate}
% %>>>

%%%%%%%%%%%%%%%%%%%%%%%%
%% Transistors
%%%%%%%%%%%%%%%%%%%%%%%%

% Settings for Transistors %<<<1

\newif\ifpgf@circuit@trans@depletiontype
\pgf@circuit@trans@depletiontypefalse

\newif\ifpgf@circuit@mos@arrows
\ctikzset{tripoles/mos style/.is choice}
\ctikzset{tripoles/mos style/no arrows/.code={\pgf@circuit@mos@arrowsfalse}}
\ctikzset{tripoles/mos style/arrows/.code={\pgf@circuit@mos@arrowstrue}}
\pgfkeys{/tikz/arrowmos/.add code={}{\pgf@circuit@mos@arrowstrue}}
\pgfkeys{/tikz/noarrowmos/.add code={}{\pgf@circuit@mos@arrowsfalse}}

% Fixed label positions
\newif\ifpgf@circuit@transisors@fixlabels
\pgf@circuit@transisors@fixlabelstrue
\pgfkeys{/tikz/center transistors text/.add code={}{\pgf@circuit@transisors@fixlabelstrue}}
\ctikzset{fix transistors text/.add code={}{\pgf@circuit@transisors@fixlabelstrue}}
\pgfkeys{/tikz/legacy transistors text/.add code={}{\pgf@circuit@transisors@fixlabelsfalse}}
\ctikzset{legacy transistors text/.add code={}{\pgf@circuit@transisors@fixlabelsfalse}}

% Option solderdot for fet
\newif\ifpgf@circuit@fet@solderdot
\pgfkeys{/tikz/solderdot/.add code={}{\pgf@circuit@fet@solderdottrue}}
\ctikzset{solderdot/.add code={}{\pgf@circuit@fet@solderdottrue}}
\pgfkeys{/tikz/nosolderdot/.add code={}{\pgf@circuit@fet@solderdotfalse}}
\ctikzset{nosolderdot/.add code={}{\pgf@circuit@fet@solderdotfalse}}

%%%% activate doublegate
\newif\ifpgf@circuit@fet@doublegate
\pgfkeys{/tikz/doublegate/.add code={}{\pgf@circuit@fet@doublegatetrue}}
\ctikzset{doublegate/.add code={}{\pgf@circuit@fet@doublegatetrue}}
\pgfkeys{/tikz/nodoublegate/.add code={}{\pgf@circuit@fet@doublegatefalse}}
\ctikzset{nodoublegate/.add code={}{\pgf@circuit@fet@doublegatefalse}}

% Option bodydiode for fet
\newif\ifpgf@circuit@fet@bodydiode
\pgfkeys{/tikz/bodydiode/.add code={}{\pgf@circuit@fet@bodydiodetrue}}
\ctikzset{bodydiode/.add code={}{\pgf@circuit@fet@bodydiodetrue}}
\pgfkeys{/tikz/nobodydiode/.add code={}{\pgf@circuit@fet@bodydiodefalse}}
\ctikzset{nobodydiode/.add code={}{\pgf@circuit@fet@bodydiodefalse}}

% Option draw fet without gate connection
\newif\ifpgf@circuit@bpt@drawgate
\pgf@circuit@bpt@drawgatetrue
\pgfkeys{/tikz/nogate/.add code={}{\pgf@circuit@bpt@drawgatefalse}}
\ctikzset{nogate/.add code={}{\pgf@circuit@bpt@drawgatefalse}}
\pgfkeys{/tikz/nobase/.add code={}{\pgf@circuit@bpt@drawgatefalse}}
\ctikzset{nobase/.add code={}{\pgf@circuit@bpt@drawgatefalse}}

% Option draw bpt with schottky base
\newif\ifpgf@circuit@bpt@schottky
\pgf@circuit@bpt@schottkyfalse
\pgfkeys{/tikz/schottky base/.add code={}{\pgf@circuit@bpt@schottkytrue}}
\ctikzset{schottky base/.add code={}{\pgf@circuit@bpt@schottkytrue}}
\pgfkeys{/tikz/no schottky base/.add code={}{\pgf@circuit@bpt@schottkyfalse}}
\ctikzset{no schottky base/.add code={}{\pgf@circuit@bpt@schottkyfalse}}
\ctikzset{tripoles/schottky base size/.initial=0.05}

% Option to add ferroelectric symbol
\newif\ifpgf@circuit@tr@ferroel
\pgf@circuit@tr@ferroelfalse
\pgfkeys{/tikz/ferroel gate/.add code={}{\pgf@circuit@tr@ferroeltrue}}
\ctikzset{ferroel gate/.add code={}{\pgf@circuit@tr@ferroeltrue}}
\pgfkeys{/tikz/no ferroel gate/.add code={}{\pgf@circuit@tr@ferroelfalse}}
\ctikzset{no ferroel gate/.add code={}{\pgf@circuit@tr@ferroelfalse}}


% Option draw bpt without base connection
\newif\ifpgf@circuit@bpt@drawbase
\pgf@circuit@bpt@drawbasetrue
\pgfkeys{/tikz/nobase/.add code={}{\pgf@circuit@bpt@drawbasefalse}}
\ctikzset{nobase/.add code={}{\pgf@circuit@bpt@drawbasefalse}}
\pgfkeys{/tikz/nogate/.add code={}{\pgf@circuit@bpt@drawbasefalse}}
\ctikzset{nogate/.add code={}{\pgf@circuit@bpt@drawbasefalse}}

% Option draw bpt with optical input
\newif\ifpgf@circuit@bpt@drawphoto
\pgf@circuit@bpt@drawphotofalse
\pgfkeys{/tikz/photo/.add code={}{\pgf@circuit@bpt@drawphototrue}}
\ctikzset{photo/.add code={}{\pgf@circuit@bpt@drawphototrue}}
\pgfkeys{/tikz/photo/.add code={}{\pgf@circuit@bpt@drawphototrue}}
\ctikzset{photo/.add code={}{\pgf@circuit@bpt@drawphototrue}}

% Option draw fet without bulk connection -- Added by Burak Kelleci
\newif\ifpgf@circuit@bpt@drawbulk
\pgfkeys{/tikz/bulk/.add code={}{\pgf@circuit@bpt@drawbulktrue}}
\ctikzset{bulk/.add code={}{\pgf@circuit@bpt@drawbulktrue}}
\pgfkeys{/tikz/nobulk/.add code={}{\pgf@circuit@bpt@drawbulkfalse}}
\ctikzset{nobulk/.add code={}{\pgf@circuit@bpt@drawbulkfalse}}

% Option draw pmos with empty circle
\newif\ifpgf@circuit@pmos@emptycircle
\pgf@circuit@pmos@emptycirclefalse
\ctikzset{tripoles/pmos style/.is choice}
\pgfkeys{/tikz/emptycircle/.add code={}{\pgf@circuit@pmos@emptycircletrue}}
\ctikzset{tripoles/pmos style/emptycircle/.add code={}{\pgf@circuit@pmos@emptycircletrue}}
% Option draw pmos with no circle
\newif\ifpgf@circuit@pmos@nocircle
\pgf@circuit@pmos@nocirclefalse
\pgfkeys{/tikz/nocircle/.add code={}{\pgf@circuit@pmos@nocircletrue}}
\ctikzset{tripoles/pmos style/nocircle/.add code={}{\pgf@circuit@pmos@nocircletrue}}
% back to normal
\pgfkeys{/tikz/fullcircle/.add code={}{\pgf@circuit@pmos@emptycirclefalse\pgf@circuit@pmos@nocirclefalse}}
\ctikzset{tripoles/pmos style/fullcircle/.add code={}{\pgf@circuit@pmos@emptycirclefalse\pgf@circuit@pmos@nocirclefalse}}
% arrows at the end, the correct way
\newif\ifpgf@circuit@trans@arrowatend
\pgf@circuit@trans@arrowatendfalse
\ctikzset{transistors/arrow pos/.is choice}
\ctikzset{transistors/arrow pos/legacy/.code={\pgf@circuit@trans@arrowatendfalse}}
\ctikzset{transistors/arrow pos/end/.code={\pgf@circuit@trans@arrowatendtrue}}

\newif\ifpgf@circuit@trans@ntype
\pgf@circuit@trans@ntypetrue %default true
%\newif\ifpgf@circuit@trans@ptype
%\ctikzset{tripoles/nmos/.add code={\pgf@circuit@trans@ntypetrue}}
\ctikzset{tripoles/nmos/width/.initial=.7}
\ctikzset{tripoles/nmos/gate height/.initial=.35}
\ctikzset{tripoles/nmos/base height/.initial=.5}
\ctikzset{tripoles/nmos/conn height/.initial=0}
\ctikzset{tripoles/nmos/height/.initial=1.1}
\ctikzset{tripoles/nmos/base width/.initial=.5}
\ctikzset{tripoles/nmos/gate width/.initial=.62}
\ctikzset{tripoles/nmos/arrow pos/.initial=.6}
\ctikzset{tripoles/nmos/bodydiode scale/.initial=.3}
\ctikzset{tripoles/nmos/bodydiode distance/.initial=.3}
\ctikzset{tripoles/nmos/bodydiode conn/.initial=.6}
\ctikzset{tripoles/nmos/curr direction/.initial=1}

\ctikzset{tripoles/pmos/width/.initial=.7}
\ctikzset{tripoles/pmos/gate height/.initial=.35}
\ctikzset{tripoles/pmos/base height/.initial=.5}
\ctikzset{tripoles/pmos/conn height/.initial=0}
\ctikzset{tripoles/pmos/height/.initial=1.1}
\ctikzset{tripoles/pmos/base width/.initial=.5}
\ctikzset{tripoles/pmos/gate width/.initial=.62}
\ctikzset{tripoles/pmos/arrow pos/.initial=.4}
\ctikzset{tripoles/pmos/bodydiode scale/.initial=.3}
\ctikzset{tripoles/pmos/bodydiode distance/.initial=.3}
\ctikzset{tripoles/pmos/bodydiode conn/.initial=.6}
\ctikzset{tripoles/pmos/curr direction/.initial=-1}

\ctikzset{tripoles/nmosd/width/.initial=.7}
\ctikzset{tripoles/nmosd/gate height/.initial=.35}
\ctikzset{tripoles/nmosd/base height/.initial=.5}
\ctikzset{tripoles/nmosd/conn height/.initial=0}
\ctikzset{tripoles/nmosd/height/.initial=1.1}
\ctikzset{tripoles/nmosd/base width/.initial=.5}
\ctikzset{tripoles/nmosd/gate width/.initial=.62}
\ctikzset{tripoles/nmosd/arrow pos/.initial=.6}
\ctikzset{tripoles/nmosd/bodydiode scale/.initial=.3}
\ctikzset{tripoles/nmosd/bodydiode distance/.initial=.3}
\ctikzset{tripoles/nmosd/bodydiode conn/.initial=.6}
\ctikzset{tripoles/nmosd/curr direction/.initial=1}
\ctikzset{tripoles/nmosd/depletion width/.initial=.1}
\ctikzset{tripoles/nmosd/depletion color/.initial=default}

\ctikzset{tripoles/pmosd/width/.initial=.7}
\ctikzset{tripoles/pmosd/gate height/.initial=.35}
\ctikzset{tripoles/pmosd/base height/.initial=.5}
\ctikzset{tripoles/pmosd/conn height/.initial=0}
\ctikzset{tripoles/pmosd/height/.initial=1.1}
\ctikzset{tripoles/pmosd/base width/.initial=.5}
\ctikzset{tripoles/pmosd/gate width/.initial=.62}
\ctikzset{tripoles/pmosd/arrow pos/.initial=.4}
\ctikzset{tripoles/pmosd/bodydiode scale/.initial=.3}
\ctikzset{tripoles/pmosd/bodydiode distance/.initial=.3}
\ctikzset{tripoles/pmosd/bodydiode conn/.initial=.6}
\ctikzset{tripoles/pmosd/curr direction/.initial=-1}
\ctikzset{tripoles/pmosd/depletion width/.initial=.1}
\ctikzset{tripoles/pmosd/depletion color/.initial=default}
\ctikzset{tripoles/hemt/width/.initial=.7}
\ctikzset{tripoles/hemt/gate height/.initial=.35}
\ctikzset{tripoles/hemt/base height/.initial=.5}
\ctikzset{tripoles/hemt/conn height/.initial=0}
\ctikzset{tripoles/hemt/height/.initial=1.1}
\ctikzset{tripoles/hemt/base width/.initial=.5}
\ctikzset{tripoles/hemt/gate width/.initial=.5}% the horizontal position is the same
\ctikzset{tripoles/hemt/bodydiode scale/.initial=.3}
\ctikzset{tripoles/hemt/bodydiode distance/.initial=.3}
\ctikzset{tripoles/hemt/bodydiode conn/.initial=.6}
\ctikzset{tripoles/hemt/curr direction/.initial=1}
%% New parameters
\ctikzset{tripoles/hemt/curr direction/.initial=1}
\ctikzset{tripoles/hemt/gate asym/.initial=0}
\newif\ifpgf@circ@hemt@split
\ctikzset{tripoles/hemt/split gate/.is if=pgf@circ@hemt@split}
\ctikzset{tripoles/hemt/source arrow/.initial=0}

\ctikzset{tripoles/nfet/width/.initial=.7}
\ctikzset{tripoles/nfet/gate height/.initial=.35}
\ctikzset{tripoles/nfet/base height/.initial=.5}
\ctikzset{tripoles/nfet/conn height/.initial=0}
\ctikzset{tripoles/nfet/height/.initial=1.1}
\ctikzset{tripoles/nfet/base width/.initial=.5}
\ctikzset{tripoles/nfet/gate width/.initial=.62}
\ctikzset{tripoles/nfet/bodydiode scale/.initial=.3}
\ctikzset{tripoles/nfet/bodydiode distance/.initial=.3}
\ctikzset{tripoles/nfet/bodydiode conn/.initial=.6}
\ctikzset{tripoles/nfet/curr direction/.initial=1}

\ctikzset{tripoles/pfet/width/.initial=.7}
\ctikzset{tripoles/pfet/gate height/.initial=.35}
\ctikzset{tripoles/pfet/base height/.initial=.5}
\ctikzset{tripoles/pfet/conn height/.initial=0}
\ctikzset{tripoles/pfet/height/.initial=1.1}
\ctikzset{tripoles/pfet/base width/.initial=.5}
\ctikzset{tripoles/pfet/gate width/.initial=.62}
\ctikzset{tripoles/pfet/bodydiode scale/.initial=.3}
\ctikzset{tripoles/pfet/bodydiode distance/.initial=.3}
\ctikzset{tripoles/pfet/bodydiode conn/.initial=.6}
\ctikzset{tripoles/pfet/curr direction/.initial=-1}

\ctikzset{tripoles/nfetd/width/.initial=.7}
\ctikzset{tripoles/nfetd/gate height/.initial=.35}
\ctikzset{tripoles/nfetd/base height/.initial=.5}
\ctikzset{tripoles/nfetd/conn height/.initial=0}
\ctikzset{tripoles/nfetd/height/.initial=1.1}
\ctikzset{tripoles/nfetd/base width/.initial=.5}
\ctikzset{tripoles/nfetd/gate width/.initial=.62}
\ctikzset{tripoles/nfetd/bodydiode scale/.initial=.3}
\ctikzset{tripoles/nfetd/bodydiode distance/.initial=.3}
\ctikzset{tripoles/nfetd/bodydiode conn/.initial=.6}
\ctikzset{tripoles/nfetd/curr direction/.initial=1}

\ctikzset{tripoles/pfetd/width/.initial=.7}
\ctikzset{tripoles/pfetd/gate height/.initial=.35}
\ctikzset{tripoles/pfetd/base height/.initial=.5}
\ctikzset{tripoles/pfetd/conn height/.initial=0}
\ctikzset{tripoles/pfetd/height/.initial=1.1}
\ctikzset{tripoles/pfetd/base width/.initial=.5}
\ctikzset{tripoles/pfetd/gate width/.initial=.62}
\ctikzset{tripoles/pfetd/bodydiode scale/.initial=.3}
\ctikzset{tripoles/pfetd/bodydiode distance/.initial=.3}
\ctikzset{tripoles/pfetd/bodydiode conn/.initial=.6}
\ctikzset{tripoles/pfetd/curr direction/.initial=-1}

\ctikzset{tripoles/nigfete/width/.initial=.7}
\ctikzset{tripoles/nigfete/gate height/.initial=.35}
\ctikzset{tripoles/nigfete/base height/.initial=.5}
\ctikzset{tripoles/nigfete/conn height/.initial=.35}
\ctikzset{tripoles/nigfete/height/.initial=1.1}
\ctikzset{tripoles/nigfete/base width/.initial=.5}
\ctikzset{tripoles/nigfete/gate width/.initial=.62}
\ctikzset{tripoles/nigfete/bodydiode scale/.initial=.3}
\ctikzset{tripoles/nigfete/bodydiode distance/.initial=.3}
\ctikzset{tripoles/nigfete/bodydiode conn/.initial=.6}
\ctikzset{tripoles/nigfete/curr direction/.initial=1}

\ctikzset{tripoles/nigfetd/width/.initial=.7}
\ctikzset{tripoles/nigfetd/gate height/.initial=.35}
\ctikzset{tripoles/nigfetd/base height/.initial=.5}
\ctikzset{tripoles/nigfetd/conn height/.initial=.35}
\ctikzset{tripoles/nigfetd/height/.initial=1.1}
\ctikzset{tripoles/nigfetd/base width/.initial=.5}
\ctikzset{tripoles/nigfetd/gate width/.initial=.62}
\ctikzset{tripoles/nigfetd/bodydiode scale/.initial=.3}
\ctikzset{tripoles/nigfetd/bodydiode distance/.initial=.3}
\ctikzset{tripoles/nigfetd/bodydiode conn/.initial=.6}
\ctikzset{tripoles/nigfetd/curr direction/.initial=1}

\ctikzset{tripoles/nigfetebulk/width/.initial=.7}
\ctikzset{tripoles/nigfetebulk/gate height/.initial=.35}
\ctikzset{tripoles/nigfetebulk/base height/.initial=.5}
\ctikzset{tripoles/nigfetebulk/conn height/.initial=.35}
\ctikzset{tripoles/nigfetebulk/height/.initial=1.1}
\ctikzset{tripoles/nigfetebulk/base width/.initial=.5}
\ctikzset{tripoles/nigfetebulk/gate width/.initial=.62}
\ctikzset{tripoles/nigfetebulk/bodydiode scale/.initial=.3}
\ctikzset{tripoles/nigfetebulk/bodydiode distance/.initial=.3}
\ctikzset{tripoles/nigfetebulk/bodydiode conn/.initial=.6}
\ctikzset{tripoles/nigfetebulk/curr direction/.initial=1}

\ctikzset{tripoles/pigfete/width/.initial=.7}
\ctikzset{tripoles/pigfete/gate height/.initial=.35}
\ctikzset{tripoles/pigfete/base height/.initial=.5}
\ctikzset{tripoles/pigfete/conn height/.initial=.35}
\ctikzset{tripoles/pigfete/height/.initial=1.1}
\ctikzset{tripoles/pigfete/base width/.initial=.5}
\ctikzset{tripoles/pigfete/gate width/.initial=.62}
\ctikzset{tripoles/pigfete/bodydiode scale/.initial=.3}
\ctikzset{tripoles/pigfete/bodydiode distance/.initial=.3}
\ctikzset{tripoles/pigfete/bodydiode conn/.initial=.6}
\ctikzset{tripoles/pigfete/curr direction/.initial=-1}

\ctikzset{tripoles/pigfetd/width/.initial=.7}
\ctikzset{tripoles/pigfetd/gate height/.initial=.35}
\ctikzset{tripoles/pigfetd/base height/.initial=.5}
\ctikzset{tripoles/pigfetd/conn height/.initial=.35}
\ctikzset{tripoles/pigfetd/height/.initial=1.1}
\ctikzset{tripoles/pigfetd/base width/.initial=.5}
\ctikzset{tripoles/pigfetd/gate width/.initial=.62}
\ctikzset{tripoles/pigfetd/bodydiode scale/.initial=.3}
\ctikzset{tripoles/pigfetd/bodydiode distance/.initial=.3}
\ctikzset{tripoles/pigfetd/bodydiode conn/.initial=.6}
\ctikzset{tripoles/pigfetd/curr direction/.initial=-1}

\ctikzset{tripoles/pigfetebulk/width/.initial=.7}
\ctikzset{tripoles/pigfetebulk/gate height/.initial=.35}
\ctikzset{tripoles/pigfetebulk/conn height/.initial=.35}
\ctikzset{tripoles/pigfetebulk/base height/.initial=.5}
\ctikzset{tripoles/pigfetebulk/height/.initial=1.1}
\ctikzset{tripoles/pigfetebulk/base width/.initial=.5}
\ctikzset{tripoles/pigfetebulk/gate width/.initial=.62}
\ctikzset{tripoles/pigfetebulk/bodydiode scale/.initial=.3}
\ctikzset{tripoles/pigfetebulk/bodydiode distance/.initial=.3}
\ctikzset{tripoles/pigfetebulk/bodydiode conn/.initial=.6}
\ctikzset{tripoles/pigfetebulk/curr direction/.initial=-1}

\ctikzset{tripoles/npn/width/.initial=.6}
\ctikzset{tripoles/npn/base height/.initial=.45}
\ctikzset{tripoles/npn/base height 2/.initial=.15}
\ctikzset{tripoles/npn/base height/.initial=.4}
\ctikzset{tripoles/npn/conn height/.initial=0}
\ctikzset{tripoles/npn/height/.initial=1.1}
\ctikzset{tripoles/npn/base width/.initial=.5}
\ctikzset{tripoles/npn/arrow pos/.initial=.5}
\ctikzset{tripoles/npn/bodydiode scale/.initial=.3}
\ctikzset{tripoles/npn/bodydiode distance/.initial=.3}
\ctikzset{tripoles/npn/bodydiode conn/.initial=.6}
\ctikzset{tripoles/npn/curr direction/.initial=1}

\ctikzset{tripoles/pnp/width/.initial=.6}
\ctikzset{tripoles/pnp/base height/.initial=.45}
\ctikzset{tripoles/pnp/base height 2/.initial=.15}
\ctikzset{tripoles/pnp/base height/.initial=.4}
\ctikzset{tripoles/pnp/conn height/.initial=0}
\ctikzset{tripoles/pnp/height/.initial=1.1}
\ctikzset{tripoles/pnp/base width/.initial=.5}
\ctikzset{tripoles/pnp/arrow pos/.initial=.5}
\ctikzset{tripoles/pnp/bodydiode scale/.initial=.3}
\ctikzset{tripoles/pnp/bodydiode distance/.initial=.3}
\ctikzset{tripoles/pnp/bodydiode conn/.initial=.6}
\ctikzset{tripoles/pnp/curr direction/.initial=-1}

\ctikzset{tripoles/pigbt/width/.initial=.6}
\ctikzset{tripoles/pigbt/gate height/.initial=.45}
\ctikzset{tripoles/pigbt/gate height 2/.initial=.15}
\ctikzset{tripoles/pigbt/base height/.initial=.4}
\ctikzset{tripoles/pigbt/outer base height/.initial=.4}
\ctikzset{tripoles/pigbt/outer base thickness/.initial=1}
\ctikzset{tripoles/pigbt/conn height/.initial=0}
\ctikzset{tripoles/pigbt/height/.initial=1.1}
\ctikzset{tripoles/pigbt/gate width/.initial=.62}
\ctikzset{tripoles/pigbt/base width/.initial=.5}
\ctikzset{tripoles/pigbt/bodydiode scale/.initial=.3}
\ctikzset{tripoles/pigbt/bodydiode distance/.initial=.3}
\ctikzset{tripoles/pigbt/bodydiode conn/.initial=.6}
\ctikzset{tripoles/pigbt/curr direction/.initial=-1}

\ctikzset{tripoles/nigbt/width/.initial=.6}
\ctikzset{tripoles/nigbt/gate height/.initial=.45}
\ctikzset{tripoles/nigbt/gate height 2/.initial=.15}
\ctikzset{tripoles/nigbt/base height/.initial=.4}
\ctikzset{tripoles/nigbt/outer base height/.initial=.4}
\ctikzset{tripoles/nigbt/outer base thickness/.initial=1}
\ctikzset{tripoles/nigbt/conn height/.initial=0}
\ctikzset{tripoles/nigbt/height/.initial=1.1}
\ctikzset{tripoles/nigbt/gate width/.initial=.62}
\ctikzset{tripoles/nigbt/base width/.initial=.5}
\ctikzset{tripoles/nigbt/bodydiode scale/.initial=.3}
\ctikzset{tripoles/nigbt/bodydiode distance/.initial=.3}
\ctikzset{tripoles/nigbt/bodydiode conn/.initial=.6}
\ctikzset{tripoles/nigbt/curr direction/.initial=1}

\ctikzset{tripoles/Lpigbt/width/.initial=.6}
\ctikzset{tripoles/Lpigbt/gate height/.initial=.45}
\ctikzset{tripoles/Lpigbt/gate height 2/.initial=.15}
\ctikzset{tripoles/Lpigbt/base height/.initial=.4}
\ctikzset{tripoles/Lpigbt/outer base height/.initial=.4}
\ctikzset{tripoles/Lpigbt/outer base thickness/.initial=1}
\ctikzset{tripoles/Lpigbt/conn height/.initial=.4}
\ctikzset{tripoles/Lpigbt/height/.initial=1.1}
\ctikzset{tripoles/Lpigbt/gate width/.initial=.62}
\ctikzset{tripoles/Lpigbt/base width/.initial=.5}
\ctikzset{tripoles/Lpigbt/bodydiode scale/.initial=.3}
\ctikzset{tripoles/Lpigbt/bodydiode distance/.initial=.3}
\ctikzset{tripoles/Lpigbt/bodydiode conn/.initial=.6}
\ctikzset{tripoles/Lpigbt/curr direction/.initial=-1}

\ctikzset{tripoles/Lnigbt/width/.initial=.6}
\ctikzset{tripoles/Lnigbt/gate height/.initial=.45}
\ctikzset{tripoles/Lnigbt/gate height 2/.initial=.15}
\ctikzset{tripoles/Lnigbt/base height/.initial=.4}
\ctikzset{tripoles/Lnigbt/outer base height/.initial=.4}
\ctikzset{tripoles/Lnigbt/outer base thickness/.initial=1}
\ctikzset{tripoles/Lnigbt/conn height/.initial=.4}
\ctikzset{tripoles/Lnigbt/height/.initial=1.1}
\ctikzset{tripoles/Lnigbt/gate width/.initial=.62}
\ctikzset{tripoles/Lnigbt/base width/.initial=.5}
\ctikzset{tripoles/Lnigbt/bodydiode scale/.initial=.3}
\ctikzset{tripoles/Lnigbt/bodydiode distance/.initial=.3}
\ctikzset{tripoles/Lnigbt/bodydiode conn/.initial=.6}
\ctikzset{tripoles/Lnigbt/curr direction/.initial=1}

\ctikzset{tripoles/igbt/outer base height/.code={
    \ctikzset{tripoles/nigbt/outer base height/.initial=#1}
    \ctikzset{tripoles/pigbt/outer base height/.initial=#1}
    \ctikzset{tripoles/Lnigbt/outer base height/.initial=#1}
    \ctikzset{tripoles/Lpigbt/outer base height/.initial=#1}
    \ctikzset{tripoles/Lnigbt/conn height/.initial=#1}
    \ctikzset{tripoles/Lpigbt/conn height/.initial=#1}
}}
\ctikzset{tripoles/igbt/outer base thickness/.code={
    \ctikzset{tripoles/nigbt/outer base thickness=#1}
    \ctikzset{tripoles/pigbt/outer base thickness=#1}
    \ctikzset{tripoles/Lnigbt/outer base thickness=#1}
    \ctikzset{tripoles/Lpigbt/outer base thickness=#1}
}}

\ctikzset{tripoles/njfet/width/.initial=.7}
\ctikzset{tripoles/njfet/gate height/.initial=.5}
\ctikzset{tripoles/njfet/gate height 2/.initial=.35}
\ctikzset{tripoles/njfet/gate width/.initial=.5}
\ctikzset{tripoles/njfet/base width/.initial=.5}
\ctikzset{tripoles/njfet/conn height/.initial=.35}% at the exterior
\ctikzset{tripoles/njfet/union height/.initial=.35}% at the gate
\ctikzset{tripoles/njfet/conn kink/.initial=1}% 1=no kink
\ctikzset{tripoles/njfet/height/.initial=1.1}
\ctikzset{tripoles/njfet/bodydiode scale/.initial=.3}
\ctikzset{tripoles/njfet/bodydiode distance/.initial=.3}
\ctikzset{tripoles/njfet/bodydiode conn/.initial=.6}
\ctikzset{tripoles/njfet/curr direction/.initial=1}

\ctikzset{tripoles/pjfet/width/.initial=.7}
\ctikzset{tripoles/pjfet/gate height/.initial=.5}
\ctikzset{tripoles/pjfet/gate height 2/.initial=.35}
\ctikzset{tripoles/pjfet/gate width/.initial=.5}
\ctikzset{tripoles/pjfet/base width/.initial=.5}
\ctikzset{tripoles/pjfet/conn height/.initial=.35}
\ctikzset{tripoles/pjfet/union height/.initial=.35}% at the gate
\ctikzset{tripoles/pjfet/conn kink/.initial=1}% 1=no kink
\ctikzset{tripoles/pjfet/height/.initial=1.1}
\ctikzset{tripoles/pjfet/bodydiode scale/.initial=.3}
\ctikzset{tripoles/pjfet/bodydiode distance/.initial=.3}
\ctikzset{tripoles/pjfet/bodydiode conn/.initial=.6}
\ctikzset{tripoles/pjfet/curr direction/.initial=-1}

\ctikzset{tripoles/nujt/width/.initial=.7}
\ctikzset{tripoles/nujt/gate height/.initial=.5}
\ctikzset{tripoles/nujt/gate height 2/.initial=.35}
\ctikzset{tripoles/nujt/gate width/.initial=.5}
\ctikzset{tripoles/nujt/base width/.initial=.5}
\ctikzset{tripoles/nujt/conn height/.initial=.35}
\ctikzset{tripoles/nujt/union height/.initial=0}% at the gate
\ctikzset{tripoles/nujt/conn kink/.initial=.82}% to match the circle position
\ctikzset{tripoles/nujt/height/.initial=1.1}
\ctikzset{tripoles/nujt/bodydiode scale/.initial=.3}
\ctikzset{tripoles/nujt/bodydiode distance/.initial=.3}
\ctikzset{tripoles/nujt/bodydiode conn/.initial=.6}
\ctikzset{tripoles/nujt/curr direction/.initial=1}

\ctikzset{tripoles/pujt/width/.initial=.7}
\ctikzset{tripoles/pujt/gate height/.initial=.5}
\ctikzset{tripoles/pujt/gate height 2/.initial=.35}
\ctikzset{tripoles/pujt/gate width/.initial=.5}
\ctikzset{tripoles/pujt/base width/.initial=.5}
\ctikzset{tripoles/pujt/conn height/.initial=.35}
\ctikzset{tripoles/pujt/union height/.initial=0}% at the gate
\ctikzset{tripoles/pujt/conn kink/.initial=.82}% to match the circle position
\ctikzset{tripoles/pujt/height/.initial=1.1}
\ctikzset{tripoles/pujt/bodydiode scale/.initial=.3}
\ctikzset{tripoles/pujt/bodydiode distance/.initial=.3}
\ctikzset{tripoles/pujt/bodydiode conn/.initial=.6}
\ctikzset{tripoles/pujt/curr direction/.initial=-1}

\ctikzset{tripoles/isfet/width/.initial=1}
\ctikzset{tripoles/isfet/gate height/.initial=.35}
\ctikzset{tripoles/isfet/base height/.initial=.5}
\ctikzset{tripoles/isfet/height/.initial=1.1}
\ctikzset{tripoles/isfet/base width/.initial=.3}
\ctikzset{tripoles/isfet/gate width/.initial=.5}
\ctikzset{tripoles/isfet/conn height/.initial=0}
\ctikzset{tripoles/isfet/wave width/.initial=.16}
\ctikzset{tripoles/isfet/wave amp/.initial=.06}
\ctikzset{tripoles/isfet/waves y sep/.initial=.22}
\ctikzset{tripoles/isfet/waves x sep/.initial=.8}
\ctikzset{tripoles/isfet/bodydiode scale/.initial=.3}
\ctikzset{tripoles/isfet/bodydiode distance/.initial=.3}
\ctikzset{tripoles/isfet/bodydiode conn/.initial=.6}
\ctikzset{tripoles/isfet/curr direction/.initial=1}
%
% graphene FET
%
\ctikzset{tripoles/pgfet/width/.initial=.6}
\ctikzset{tripoles/pgfet/gate height/.initial=.5}
\ctikzset{tripoles/pgfet/gate height 2/.initial=0.25}  % must be "gate height"/2
\ctikzset{tripoles/pgfet/base height/.initial=.5}  % must be "gate height"
\ctikzset{tripoles/pgfet/outer base height/.initial=.25} % must be "gate height 2"
\ctikzset{tripoles/pgfet/outer base thickness/.initial=1}
\ctikzset{tripoles/pgfet/conn height/.initial=0}
\ctikzset{tripoles/pgfet/height/.initial=1.1}
\ctikzset{tripoles/pgfet/gate width/.initial=.5}
\ctikzset{tripoles/pgfet/base width/.initial=0.36084} % must be "gate height"*cos(60)/(2*width)
\ctikzset{tripoles/pgfet/bodydiode scale/.initial=.3}
\ctikzset{tripoles/pgfet/bodydiode distance/.initial=.6}
\ctikzset{tripoles/pgfet/bodydiode conn/.initial=.6}
\ctikzset{tripoles/pgfet/curr direction/.initial=-1}

\ctikzset{tripoles/ngfet/width/.initial=.6}
\ctikzset{tripoles/ngfet/gate height/.initial=.5}
\ctikzset{tripoles/ngfet/gate height 2/.initial=0.25}  % must be "gate height"/2
\ctikzset{tripoles/ngfet/base height/.initial=.5}  % must be "gate height"
\ctikzset{tripoles/ngfet/outer base height/.initial=.25} % must be "gate height 2"
\ctikzset{tripoles/ngfet/outer base thickness/.initial=1}
\ctikzset{tripoles/ngfet/conn height/.initial=0}
\ctikzset{tripoles/ngfet/height/.initial=1.1}
\ctikzset{tripoles/ngfet/gate width/.initial=.5}
\ctikzset{tripoles/ngfet/base width/.initial=0.36084} % must be "gate height"*cos(60)/(2*width)
\ctikzset{tripoles/ngfet/bodydiode scale/.initial=.3}
\ctikzset{tripoles/ngfet/bodydiode distance/.initial=.6}
\ctikzset{tripoles/ngfet/bodydiode conn/.initial=.6}
\ctikzset{tripoles/ngfet/curr direction/.initial=1}
%
% multi-emitter and multi-collector BJTs by Romano Giannetti
%
\ctikzset{tripoles/bjt/emitters/.initial=1}
\ctikzset{tripoles/bjt/collectors/.initial=1}
\pgfkeys{/tikz/emitters/.add code={}{\ctikzset{tripoles/bjt/emitters=#1}}}
\pgfkeys{/tikz/collectors/.add code={}{\ctikzset{tripoles/bjt/collectors=#1}}}
\ctikzset{tripoles/bjt/pins width/.initial=0.3}
\pgfkeys{/tikz/bjt pins width/.add code={}{\ctikzset{tripoles/bjt/pins width=#1}}}
\ctikzset{tripoles/bjt/multi height/.initial=.5}
\pgfkeys{/tikz/bjt multi height/.add code={}{\ctikzset{tripoles/bjt/multi height/.initial=#1}}}
%
\ctikzset{tripoles/bjt/width/.initial=.3}
\ctikzset{tripoles/bjt/base height 2/.initial=.4}
\ctikzset{tripoles/bjt/base height/.initial=1.1}
\ctikzset{tripoles/bjt/height/.initial=.4}
\ctikzset{tripoles/bjt/base width/.initial=1}
\ctikzset{tripoles/bjt/arrow pos/.initial=.5}
% do NOT touch these two!
\ctikzset{tripoles/bjt/npn/curr direction/.initial=1}
\ctikzset{tripoles/bjt/pnp/curr direction/.initial=-1}


%
% definitions for transistor circles
%
\ctikzset{transistor circle/.is family}
\ctikzset{transistor circle/relative thickness/.initial=1}
\ctikzset{transistor circle/color/.initial=default}
\ctikzset{transistor circle/dash/.initial=default}
\ctikzset{transistor circle/scale circle radius/.initial=1}
\ctikzset{transistor circle/default base in/.initial=0.9}
\ctikzset{transistor circle/njfet base in/.initial=1.05}
\ctikzset{transistor circle/pjfet base in/.initial=1.05}
\ctikzset{transistor circle/isfet base in/.initial=0.65}

\newif\ifpgf@circ@trcircle\pgf@circ@trcirclefalse
\ctikzset{tr circle/.is if=pgf@circ@trcircle}
\tikzset{tr circle/.is if=pgf@circ@trcircle}
% partial borders styles
% this can be "none" or 4 numbers saying the style for each part:
% 0 --- nothing, 1 --- solid, 2 --- dashed
\ctikzset{transistor circle/partial borders/.initial=none}       % Value none for normal borders
\ctikzset{transistor circle/partial border dash/.initial={{2pt}{2pt}}}
%
% body diode style
\ctikzset{transistor bodydiode/.is family}
\ctikzset{transistor bodydiode/relative thickness/.initial=1}
\ctikzset{transistor bodydiode/color/.initial=default}
\ctikzset{transistor bodydiode/dash/.initial=default}
\ctikzset{transistor bodydiode/dot scale/.initial=0.7}
\ctikzset{transistor solderdot scale/.initial=0.7}
% this is unfortunate, but needed for backward compatibility
\ctikzset{transistor bodydiode/scale/.code={%
    \ctikzset{tripoles/nmos/bodydiode scale=#1}%
    \ctikzset{tripoles/pmos/bodydiode scale=#1}%
    \ctikzset{tripoles/nmosd/bodydiode scale=#1}%
    \ctikzset{tripoles/pmosd/bodydiode scale=#1}%
    \ctikzset{tripoles/hemt/bodydiode scale=#1}%
    \ctikzset{tripoles/nfet/bodydiode scale=#1}%
    \ctikzset{tripoles/pfet/bodydiode scale=#1}%
    \ctikzset{tripoles/nfetd/bodydiode scale=#1}%
    \ctikzset{tripoles/pfetd/bodydiode scale=#1}%
    \ctikzset{tripoles/nigfete/bodydiode scale=#1}%
    \ctikzset{tripoles/nigfetd/bodydiode scale=#1}%
    \ctikzset{tripoles/nigfetebulk/bodydiode scale=#1}%
    \ctikzset{tripoles/pigfete/bodydiode scale=#1}%
    \ctikzset{tripoles/pigfetd/bodydiode scale=#1}%
    \ctikzset{tripoles/pigfetebulk/bodydiode scale=#1}%
    \ctikzset{tripoles/npn/bodydiode scale=#1}%
    \ctikzset{tripoles/pnp/bodydiode scale=#1}%
    \ctikzset{tripoles/pigbt/bodydiode scale=#1}%
    \ctikzset{tripoles/nigbt/bodydiode scale=#1}%
    \ctikzset{tripoles/Lpigbt/bodydiode scale=#1}%
    \ctikzset{tripoles/Lnigbt/bodydiode scale=#1}%
    \ctikzset{tripoles/njfet/bodydiode scale=#1}%
    \ctikzset{tripoles/pjfet/bodydiode scale=#1}%
    \ctikzset{tripoles/nujt/bodydiode scale=#1}%
    \ctikzset{tripoles/pujt/bodydiode scale=#1}%
    \ctikzset{tripoles/isfet/bodydiode scale=#1}%
    \ctikzset{tripoles/pgfet/bodydiode scale=#1}%
    \ctikzset{tripoles/ngfet/bodydiode scale=#1}%
}}
%%>>>


%% definitions of transistor shapes%<<<
%
% draw partial transistor outline
%
\def\pgf@circ@trcircle@split#1#2#3#4\relax{%split the six numbers
    \edef\@@a{#1}\edef\@@b{#2}\edef\@@c{#3}\edef\@@d{#4}%
}
\def\pgf@circ@trcircle@setdash{%
    \edef\@@dash{\ctikzvalof{transistor circle/partial border dash}}%
    % \typeout{DASH:\@@dash}%
    \expandafter\pgfsetdash\expandafter{\@@dash}{0pt}%
}
% this is the same as the tubes' one, but let's keep it separated
\def\pgf@circ@trcircle@draw@style#1{%
    \ifcase#1
        \pgfusepath{discard}% case 0, will discard the path
    \or
        \pgfsetdash{}{0pt}\pgfusepath{draw}% case 1, solid
    \or
        \pgf@circ@trcircle@setdash\pgfusepath{draw}% case 2, dashed
    \else
        \pgfutil@packagewarning{circuitikz}{Transistor circle draw style not known!}%
        \pgfusepath{draw}%
    \fi
}
%
% add a circle to the transistor:
\def\pgf@circ@trcircle@draw@partial#1{%
    \expandafter\pgf@circ@trcircle@split#1\relax
    % \typeout{PARTIAL: \@@a:\@@b:\@@c:\@@d}
    \pgfscope % right side upper arc
        \pgfpathmoveto{\pgfpoint{\circleleft+\circleradius}{\circleradius}}
        \pgfpatharc{90}{0}{\circleradius}
        \pgf@circ@trcircle@draw@style{\@@a}
    \endpgfscope
    \pgfscope % right side lower arc
        \pgfpathmoveto{\pgfpoint{\circleleft+2*\circleradius}{0pt}}
        \pgfpatharc{0}{-90}{\circleradius}
        \pgf@circ@trcircle@draw@style{\@@b}
    \endpgfscope
    \pgfscope % left side lower arc
        \pgfpathmoveto{\pgfpoint{\circleleft+\circleradius}{-\circleradius}}
        \pgfpatharc{-90}{-180}{\circleradius}
        \pgf@circ@trcircle@draw@style{\@@c}
    \endpgfscope
    \pgfscope % left side upper arc
        \pgfpathmoveto{\pgfpoint{\circleleft}{0pt}}
        \pgfpatharc{-180}{-270}{\circleradius}
        \pgf@circ@trcircle@draw@style{\@@d}
    \endpgfscope
}
%
\def\pgfcirc@transistorcircle{
    \ifpgf@circ@trcircle
    \pgfscope
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfsetlinewidth{\ctikzvalof{transistor circle/relative thickness}\pgflinewidth}
        \pgf@circ@subset@color@dash{transistor circle}
        % radius of the circle
        % \pgfmathsetlength{\pgf@circ@res@temp}{((#2+\extrabodydiodelen)-(#1)+(#3)*(#3)/((#2+\extrabodydiodelen)-(#1)))/2}
        % \pgfpathcircle{\pgfpoint{#1+\pgf@circ@res@temp}{0pt}}{\pgf@circ@res@temp}
        \pgfpathcircle{\pgfpoint{\circleleft+\circleradius}{0pt}}{\circleradius}
        \edef\@@partial{\ctikzvalof{transistor circle/partial borders}}
        \ifx\@@partial\pgf@nonetext
            % Circle fill and draw if it's not partial... for speed
            \pgf@circ@draworfill
        \else
            % otherwise, just fill and do the partial fill
            \pgf@circ@maybefill
            \pgf@circ@trcircle@draw@partial{\@@partial}
        \fi
    \endpgfscope
    \fi
}

% add a ferroelectric squish to transistors

\def\pgfcirc@ferroelectric#1#2{% #1 -> transistor type, #2 horizontal enlargment (prop to ...@left),
    \ifpgf@circuit@tr@ferroel\pgfscope
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgf@circ@set@relative@thickness{modifier thickness}
        % base-gate center and width of the sigmoid
        \pgfmathsetlength{\pgf@circ@res@other}
        {0.5*(\ctikzvalof{tripoles/#1/gate width}+\ctikzvalof{tripoles/#1/base width}-(#2))*\pgf@circ@res@left}
        \pgfmathsetlength{\pgf@circ@res@temp}
        {1.2*abs(\ctikzvalof{tripoles/#1/gate width}-\ctikzvalof{tripoles/#1/base width}+0.5*(#2))*\pgf@circ@res@left}
        \pgfsetcornersarced{\pgfpoint{-0.2\pgf@circ@res@temp}{-0.2\pgf@circ@res@temp}}
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@other+\pgf@circ@res@temp}
            {1.1*\ctikzvalof{tripoles/#1/base height}*\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\pgf@circ@res@other+\pgf@circ@res@temp}
            {0.5*\ctikzvalof{tripoles/#1/base height}*\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\pgf@circ@res@other-\pgf@circ@res@temp}
            {0.5*\ctikzvalof{tripoles/#1/base height}*\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint
            {\pgf@circ@res@other-\pgf@circ@res@temp}
            {1.1*\ctikzvalof{tripoles/#1/base height}*\pgf@circ@res@down}}
        \pgfusepath{draw}
    \endpgfscope\fi
}

\ctikzset{tr gap fill/.initial=none}
\tikzset{tr gap fill/.style={\circuitikzbasekey/tr gap fill={#1}}}
% fill the gap in relevant transistors
\def\pgfcirc@fillgategap#1{% #1 transistor type
    \edef\@@@none{none}\edef\@@@color{\ctikzvalof{tr gap fill}}% always exists
    \ifx\@@@none\@@@color\relax\else
        \begingroup % save the value of @res: other, step, temp
        \edef\@@@doit{1}% draw it, set to zero if we give up
        % ok, we have the color here. we have to get center position, with and height
        % normally is gate height; but in igbt is outer base height (grrrr)
        \pgfkeysifdefined{\circuitikzbasekey/tripoles/#1/outer base height}{
            % yes, it's an IGBT
            \pgfmathsetlength{\pgf@circ@res@other}{\ctikzvalof{tripoles/#1/outer base height}*\pgf@circ@res@up}
        }{
            %no. Let's try with gate height
             \pgfkeysifdefined{\circuitikzbasekey/tripoles/#1/gate height}{
                 % yes, go for it
                \pgfmathsetlength{\pgf@circ@res@other}{\ctikzvalof{tripoles/#1/gate height}*\pgf@circ@res@up}
            }{
                %no, give up, let value to 0
                \edef\@@@doit{0}
            }
        }
        % now we have to find x1 and x2: these are base width and gate width
        % if do not have one of that, bail out.
        \pgfkeysifdefined{\circuitikzbasekey/tripoles/#1/gate width}{
                \pgfmathsetlength{\pgf@circ@res@temp}{\ctikzvalof{tripoles/#1/gate width}*\pgf@circ@res@left}
            }{
                \edef\@@@doit{0}
            }
        \pgfkeysifdefined{\circuitikzbasekey/tripoles/#1/base width}{
                \pgfmathsetlength{\pgf@circ@res@step}{\ctikzvalof{tripoles/#1/base width}*\pgf@circ@res@left}
            }{
                \edef\@@@doit{0}
            }
        % if found, draw it.
        \ifnum\@@@doit>0\relax
            \pgfscope
                \pgfsetfillcolor{\@@@color}
                \pgfsetcolor{\@@@color}
                \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@other}}{\pgfpoint{\pgf@circ@res@step}{-\pgf@circ@res@other}}
                \pgfusepath{fill, draw}
            \endpgfscope
        \fi
        \endgroup
    \fi
}

\long\def\pgfcircdeclaretransistor#1#2#3{
    \pgfdeclareshape{#1}
    {
        \savedmacro{\ctikzclass}{\edef\ctikzclass{transistors}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \savedmacro{\circlebase}{
            \pgfkeysifdefined{\circuitikzbasekey/transistor circle/#1 base in}%
            {% yes, we have it
                \edef\circlebase{\ctikzvalof{transistor circle/#1 base in}}%
            }{% no, use default
                \edef\circlebase{\ctikzvalof{transistor circle/default base in}}
            }}
        % \savedmacro{\thistypeoftr}{\edef\thistypeoftr{#1}}
        \saveddimen{\extrabodydiodelen}{
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \ifpgf@circuit@fet@bodydiode
                % try to put the text to the right of the flyback diode
                \pgfmathsetlength{\pgf@x}{(
                    \ctikzvalof{tripoles/#1/bodydiode distance}*
                    \ctikzvalof{tripoles/#1/width} +
                    \ctikzvalof{tripoles/#1/bodydiode scale}*
                    \ctikzvalof{bipoles/diode/height}/2
                )*\pgf@circ@scaled@Rlen}
            \else
                \pgf@x=0pt\relax
            \fi
        }
        \savedmacro{\scalecircleradius}{
            \edef\scalecircleradius{\ctikzvalof{transistor circle/scale circle radius}}
        }
        \saveddimen{\circleradius}{
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            % repeat the extrabodydiodelen (grrr)
            \ifpgf@circuit@fet@bodydiode
                % try to put the text to the right of the flyback diode
                \pgfmathsetlength{\pgf@circ@res@other}{(
                    \ctikzvalof{tripoles/#1/bodydiode distance}*
                    \ctikzvalof{tripoles/#1/width} +
                    \ctikzvalof{tripoles/#1/bodydiode scale}*
                    \ctikzvalof{bipoles/diode/height}/2
                )*\pgf@circ@scaled@Rlen}
            \else
                \pgf@circ@res@other=0pt\relax
            \fi
            % left
            \pgf@xa=-\ctikzvalof{tripoles/#1/width}\pgf@circ@scaled@Rlen
            \pgf@xa=\circlebase\pgf@xa % this is the base point of the circle
            % northeast
            \pgf@yb=\ctikzvalof{tripoles/#1/height}\pgf@circ@scaled@Rlen % y of the left point of circle
            \pgf@yb=.5\pgf@yb
            \pgf@xb=\pgf@circ@res@other % this is the x of the right points of the circle
            %
            \pgf@yb=\ctikzvalof{tripoles/#1/bodydiode conn}\pgf@yb %this is #3 of the circle
            % find the radius of the circle
            \pgfmathsetlength{\pgf@x}{((\pgf@xb)-(\pgf@xa)+(\pgf@yb)*(\pgf@yb)/((\pgf@xb)-(\pgf@xa)))/2*\scalecircleradius}
        }
        \saveddimen{\circleleft}{
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@xa=-\ctikzvalof{tripoles/#1/width}\pgf@circ@scaled@Rlen
            \pgf@x=\circlebase\pgf@xa
        }
        \anchor{circle center}{
            \pgf@y=0pt\pgf@x=\circleleft\advance\pgf@x by\circleradius
        }
        \anchor{circle top}{
            \pgf@y=\circleradius\pgf@x=\circleleft\advance\pgf@x by\circleradius
        }
        \anchor{circle bottom}{
            \pgf@y=-\circleradius\pgf@x=\circleleft\advance\pgf@x by\circleradius
        }
        \anchor{circle left}{
            \pgf@y=0pt\pgf@x=\circleleft
        }
        \anchor{circle right}{
            \pgf@y=0pt\pgf@x=\circleleft
            \advance\pgf@x by \circleradius\advance\pgf@x by \circleradius
        }
        \savedanchor{\centergap}{% this is the center position between gate and base
            % get "left"
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@xa=-\ctikzvalof{tripoles/#1/width}\pgf@circ@scaled@Rlen
            \pgfkeysifdefined{\circuitikzbasekey/tripoles/#1/gate width}{
                % yes, we have a separated gate
                \pgfmathsetlength{\pgf@x}
                {0.5*(\ctikzvalof{tripoles/#1/gate width}+\ctikzvalof{tripoles/#1/base width})*\pgf@xa}
            }{
                % no, use just the base
                \pgfmathsetlength{\pgf@x}
                {\ctikzvalof{tripoles/#1/base width}*\pgf@xa}
            }
            \pgf@y=0pt\relax
        }
        \anchor{centergap}{\centergap}
        \anchor{center}{
            \pgfpointorigin
        }
        \savedanchor\northeast{% upper right
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@y=\ctikzvalof{tripoles/#1/height}\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@x=0pt
        }
        \savedanchor\left{%center left
            \pgf@y=0pt
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@x=-\ctikzvalof{tripoles/#1/width}\pgf@circ@scaled@Rlen
        }
        \savedanchor\right{
            \pgf@x=0pt\pgf@y=0pt
            \ifpgf@circ@trcircle
            % repeat the \circleradius computation (GRRRR)
                \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
                % repeat the extrabodydiodelen (grrr)
                \ifpgf@circuit@fet@bodydiode
                    % try to put the text to the right of the flyback diode
                    \pgfmathsetlength{\pgf@circ@res@other}{(
                        \ctikzvalof{tripoles/#1/bodydiode distance}*
                        \ctikzvalof{tripoles/#1/width} +
                        \ctikzvalof{tripoles/#1/bodydiode scale}*
                        \ctikzvalof{bipoles/diode/height}/2
                    )*\pgf@circ@scaled@Rlen}
                \else
                    \pgf@circ@res@other=0pt\relax
                \fi
                % left
                \pgf@xa=-\ctikzvalof{tripoles/#1/width}\pgf@circ@scaled@Rlen
                \pgf@xa=\circlebase\pgf@xa % this is the base point of the circle
                % northeast
                \pgf@yb=\ctikzvalof{tripoles/#1/height}\pgf@circ@scaled@Rlen % y of the left point of circle
                \pgf@yb=.5\pgf@yb
                \pgf@xb=\pgf@circ@res@other % this is the x of the right points of the circle
                %
                \pgf@yb=\ctikzvalof{tripoles/#1/bodydiode conn}\pgf@yb %this is #3 of the circle
                % find the radius of the circle
                \pgfmathsetlength{\pgf@circ@res@other}{((\pgf@xb)-(\pgf@xa)+(\pgf@yb)*(\pgf@yb)/((\pgf@xb)-(\pgf@xa)))/2*\scalecircleradius}
                % repeat the circleleft computation
                \pgf@xa=-\ctikzvalof{tripoles/#1/width}\pgf@circ@scaled@Rlen
                \pgf@xb=\circlebase\pgf@xa
                \pgfmathsetlength{\pgf@x}{\pgf@xb+2*\pgf@circ@res@other}
            \fi
        }
        \anchor{text}{
            \northeast
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \ifpgf@circuit@transisors@fixlabels
                \ifpgf@circuit@fet@bodydiode
                    \advance \pgf@x by \extrabodydiodelen
                \fi
                \ifpgf@circ@trcircle
                    \left\pgf@xa=\pgf@x
                    \pgfmathsetlength{\pgf@x}{\circleleft+2*\circleradius}
                    % \advance \pgf@x by \circleradius
                \fi
                % add a bit of space to avoid central (substrate) terminal if drawn
                \advance\pgf@x by 0.05\pgf@circ@scaled@Rlen\relax
                \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
            \else
                \pgf@y=.7\pgf@y
                \pgf@x= \pgf@circ@scaled@Rlen
                \pgf@x=0.1\pgf@x
            \fi
        }
        \anchor{pathstart}{ % south
            \northeast
            \pgf@y=-\pgf@y
        }
        \anchor{pathend}{
            \northeast
        }
        \anchor{north}{
            \northeast
            \pgf@circ@res@step=\pgf@y
            \left
            \pgf@y=\pgf@circ@res@step
            \pgf@x=.5\pgf@x
        }
        \anchor{west}{
            \left
        }
        \anchor{left}{
            \left
        }
        \anchor{east}{
            \northeast
            \pgf@y=0pt
        }
        \anchor{right}{
            \right
        }
        \anchor{south}{
            \northeast
            \pgf@circ@res@step=\pgf@y
            \left
            \pgf@y=-\pgf@circ@res@step
            \pgf@x=.5\pgf@x
        }
        \anchor{south west}{
            \northeast
            \pgf@circ@res@step=\pgf@y
            \left
            \pgf@y=-\pgf@circ@res@step
        }
        \anchor{north east}{
            \northeast
        }
        \anchor{north west}{
            \northeast
            \pgf@circ@res@step=\pgf@y
            \left
            \pgf@y=\pgf@circ@res@step
        }
        \anchor{south east}{
            \northeast
            \pgf@y=-\pgf@y
        }
        \anchor{B}{
            \northeast
            \pgf@circ@res@step=\ctikzvalof{tripoles/#1/conn height}\pgf@y
            \left
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@circ@res@step
        }
        \anchor{base}{
            \northeast
            \pgf@circ@res@step=\ctikzvalof{tripoles/#1/conn height}\pgf@y
            \left
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@circ@res@step
        }
        \anchor{bulk}{ %added by Burak Kelleci
            \northeast
            \pgf@circ@res@step=\ctikzvalof{tripoles/#1/conn height}\pgf@y
            \right
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@circ@res@step
        }
        \anchor{nobulk}{ %added by Burak Kelleci
            \left
            \pgf@x=\ctikzvalof{tripoles/#1/base width}\pgf@x
        }
        \anchor{G}{
            \northeast
            \pgf@circ@res@step=\ctikzvalof{tripoles/#1/conn height}\pgf@y
            \left
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@circ@res@step
        }
        \anchor{G1}{
            \northeast
            \pgf@circ@res@step=\ctikzvalof{tripoles/#1/conn height}\pgf@y
            \left
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@circ@res@step
        }
        \anchor{G2}{
            \northeast
            \pgf@circ@res@step=\ctikzvalof{tripoles/#1/conn height}\pgf@y
            \pgf@circ@res@step=-0.3333333\pgf@circ@res@step
            \left
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@circ@res@step
        }
        \anchor{gate}{
            \northeast
            \pgf@circ@res@step=\ctikzvalof{tripoles/#1/conn height}\pgf@y
            \left
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@circ@res@step
        }
        \anchor{gate1}{
            \northeast
            \pgf@circ@res@step=\ctikzvalof{tripoles/#1/conn height}\pgf@y
            \left
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@circ@res@step
        }
        \anchor{gate2}{
            \northeast
            \pgf@circ@res@step=\ctikzvalof{tripoles/#1/conn height}\pgf@y
            \pgf@circ@res@step=-0.3333333\pgf@circ@res@step
            \left
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@circ@res@step
        }
        \anchor{nobase}{
            \left
            \pgf@x=\ctikzvalof{tripoles/#1/base width}\pgf@x
        }
        \anchor{circle base}{
            \left
            \pgf@x=\circlebase\pgf@x
        }
        \anchor{nogate}{
            \left
            \pgf@x=\ctikzvalof{tripoles/#1/gate width}\pgf@x
        }
        \anchor{E}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@y
        }
        \anchor{emitter}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@y
        }
        \anchor{C}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/curr direction}\pgf@y
        }
        \anchor{collector}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/curr direction}\pgf@y
        }
        \anchor{S}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@y
        }
        \anchor{source}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@y
        }
        \anchor{D}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/curr direction}\pgf@y
        }
        \anchor{drain}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/curr direction}\pgf@y
        }
        \anchor{body C in}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/curr direction}\pgf@y
            \pgf@y=\ctikzvalof{tripoles/#1/bodydiode conn}\pgf@y
        }
        \anchor{circle C}{
            \left
            \pgf@xa=\circlebase\pgf@x % this is #1 of the circle
            \northeast
            \pgf@xb=\pgf@x %this is #2 of the circle
            \pgf@yb=\ctikzvalof{tripoles/#1/bodydiode conn}\pgf@y %this is #3 of the circle
            % the base of the triangle is x_2 - x_1 - r
            \pgfmathsetlength{\pgf@circ@res@other}{\pgf@xb-\pgf@xa-\circleradius}
            % so let's go with the height
            \pgfmathsetlength{\pgf@ya}{sqrt(abs(\circleradius*\circleradius-\pgf@circ@res@other*\pgf@circ@res@other))}
            % finally, direction
            \pgf@y=\ctikzvalof{tripoles/#1/curr direction}\pgf@ya
        }
        \anchor{circle E}{
            \left
            \pgf@xa=\circlebase\pgf@x % this is #1 of the circle
            \northeast
            \pgf@xb=\pgf@x %this is #2 of the circle
            \pgf@yb=\ctikzvalof{tripoles/#1/bodydiode conn}\pgf@y %this is #3 of the circle
            % the base of the triangle is x_2 - x_1 - r
            \pgfmathsetlength{\pgf@circ@res@other}{\pgf@xb-\pgf@xa-\circleradius}
            % so let's go with the height
            \pgfmathsetlength{\pgf@ya}{sqrt(abs(\circleradius*\circleradius-\pgf@circ@res@other*\pgf@circ@res@other))}
            % finally, direction
            % finally, direction
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@ya
        }
        \anchor{body E in}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/#1/curr direction}\pgf@y
            \pgf@y=\ctikzvalof{tripoles/#1/bodydiode conn}\pgf@y
        }
        \anchor{body C out}{
            \northeast
            \pgf@ya=\ctikzvalof{tripoles/#1/curr direction}\pgf@y
            \pgf@ya=\ctikzvalof{tripoles/#1/bodydiode conn}\pgf@ya
            \pgf@y=\pgf@ya
            \left
            \pgf@x=-\ctikzvalof{tripoles/#1/bodydiode distance}\pgf@x
            \pgf@y=\pgf@ya
        }
        \anchor{body E out}{
            \northeast
            \pgf@ya=-\ctikzvalof{tripoles/#1/curr direction}\pgf@y
            \pgf@ya=\ctikzvalof{tripoles/#1/bodydiode conn}\pgf@ya
            \pgf@y=\pgf@ya
            \left
            \pgf@x=-\ctikzvalof{tripoles/#1/bodydiode distance}\pgf@x
            \pgf@y=\pgf@ya
        }
        #2%
        \pgf@circ@draw@component{
            \pgftransformationadjustments
            \pgf@circ@setcolor
            %
            \ifnum \ctikzvalof{tripoles/#1/curr direction} > 0
                \pgf@circuit@trans@ntypetrue
            \else
                \pgf@circuit@trans@ntypefalse
            \fi
            \northeast
            \pgf@circ@res@up = \pgf@y
            \pgf@circ@res@down = -\pgf@y
            \pgf@circ@res@right = \pgf@x
            \left
            \pgf@circ@res@left = \pgf@x
            \pgf@circ@scaled@Rlen=\scaledRlen
            %
            #3%
            % BODY DIODE
            \ifpgf@circuit@fet@bodydiode
                \drawbodydiode{#1}
            \fi
            %
        }
    }
}

\def\drawdobydiodedot#1#2{
    % retrieve dot scale
    \edef\@@tmp{\ctikzvalof{transistor bodydiode/dot scale}}
    \ifdim\@@tmp pt>0pt
        \pgfscope
            \pgftransformshift{\pgfpoint{\pgf@circ@res@right}
                {\ctikzvalof{tripoles/#1/bodydiode conn}#2}}
            \pgftransformscale{\@@tmp}
            % I'm not sure why this is needed, but...
            \pgf@circ@maybe@color{transistor bodydiode/color}
            \pgfnode{circ}{center}{}{}{\pgfusepath{draw,fill}}
        \endpgfscope
    \fi
}

\long\def\drawbodydiode#1{
    \pgfsetlinewidth{\ctikzvalof{transistor bodydiode/relative thickness}\pgflinewidth}
    \pgf@circ@subset@color@dash{transistor bodydiode}
    \pgfscope
        \pgftransformshift{\pgfpoint{-\ctikzvalof{tripoles/#1/bodydiode distance}\pgf@circ@res@left}{\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgftransformrotate{90}
        % diode scale and bodydiode scale interacts. We want the size of the diode
        % proportional to the transistor, so we will:
        % 1) undo diode scale 2) apply transistor scale (using the current class) 3) apply bodydiode scale
        \pgfmathsetmacro{\@@BDscale}{\ctikzvalof{tripoles/#1/bodydiode scale}* \ctikzvalof{\ctikzclass/scale}/\ctikzvalof{diodes/scale}}
        \pgftransformscale{\@@BDscale}
        \ifpgf@circuit@fulldiode
            % I'm not sure why this is needed, but...
            \pgf@circ@maybe@color{transistor bodydiode/color}
            \pgfnode{fulldiodeshape}{center}{}{pgf@bodydiode}{\pgfusepath{fill}}
        \else
            \pgfnode{emptydiodeshape}{center}{}{pgf@bodydiode}{\pgfusepath{fill}}
        \fi
    \endpgfscope
    % Draw stroke line
    \ifpgf@circuit@strokediode
        \pgfpathmoveto{\pgfpointanchor{pgf@bodydiode}{west}}
        \pgfpathlineto{\pgfpointanchor{pgf@bodydiode}{east}}
        \pgfusepath{stroke}
    \fi
    %Draw upper connection to body diode
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/#1/bodydiode conn}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{-\ctikzvalof{tripoles/#1/bodydiode distance}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/#1/bodydiode conn}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpointanchor{pgf@bodydiode}{east}}
    \pgfusepath{draw}
    \drawdobydiodedot{#1}{\pgf@circ@res@up}
    %Draw lower connection to body diode
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/#1/bodydiode conn}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{-\ctikzvalof{tripoles/#1/bodydiode distance}\pgf@circ@res@left}{\ctikzvalof{tripoles/#1/bodydiode conn}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpointanchor{pgf@bodydiode}{west}}
    \pgfusepath{draw}
    \drawdobydiodedot{#1}{\pgf@circ@res@down}
}

\long\def\declarebpt#1{
    \pgfcircdeclaretransistor{#1}{
        \anchor{inner up}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/base height}\pgf@y
        }
        \anchor{inner down}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/#1/base height}\pgf@y
        }
        \anchor{arrows}{
            \northeast
            \pgf@circ@res@up = \pgf@y
            \left
            \pgf@circ@res@left = \pgf@x
            \pgf@x=\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left
            \advance\pgf@x by 0.6\pgf@circ@res@left
            \pgf@y=0.2\pgf@circ@res@up
        }
        }{
        % add the circle if requested (before everything else, so we can fill it)
        \pgfcirc@transistorcircle

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
        {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/#1/base height 2}\pgf@circ@res@up}}
        \pgfusepath{draw}

        % drawing base
        \pgfscope
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down}}
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \ifpgf@circuit@bpt@schottky
                % upper
                \pgfpathmoveto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
                    {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up}}
                \pgfpathlineto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
                    {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up+
                    \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}}
                \pgfpathlineto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left+
                        \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}
                    {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up+
                        \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}}
                \pgfpathlineto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left+
                        \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}
                    {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up}}
                % % lower
                \pgfpathmoveto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
                    {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down}}
                \pgfpathlineto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
                    {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down-
                    \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}}
                \pgfpathlineto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left-
                        \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}
                    {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down-
                    \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}}
                \pgfpathlineto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left-
                        \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}
                    {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down}}
                \fi
            \pgfusepath{draw}
        \endpgfscope

        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/#1/base height 2}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
        {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
        \pgfusepath{draw}
        %draw arrow depending on type of transistor
        \pgfscope
            \pgfslopedattimetrue
            \pgfallowupsidedownattimetrue
            \pgfresetnontranslationattimefalse
            \edef\@@anchor{center}
            \ifpgf@circuit@trans@ntype
                \ifpgf@circuit@trans@arrowatend
                    \edef\@@anchor{btip}
                    \pgftransformlineattime{1.0}{%
                        \pgfpoint%
                        {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}%
                        {\ctikzvalof{tripoles/#1/base height 2}\pgf@circ@res@down}%
                        }{%
                        \pgfpoint{\pgf@circ@res@right}%
                        {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down}%
                    }
                \else
                    \pgftransformlineattime{\ctikzvalof{tripoles/#1/arrow pos}}{%
                        \pgfpoint%
                        {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}%
                        {\ctikzvalof{tripoles/#1/base height 2}\pgf@circ@res@down}%
                        }{%
                        \pgfpoint{\pgf@circ@res@right}%
                        {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down}%
                    }
                \fi
            \else % p-type
                \ifpgf@circuit@trans@arrowatend
                    \edef\@@anchor{tip}
                    \pgftransformlineattime{1.0}{%
                        \pgfpoint{\pgf@circ@res@right}%
                        {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up}%
                        }{%
                        \pgfpoint{\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}%
                        {\ctikzvalof{tripoles/#1/base height 2}\pgf@circ@res@up}%
                    }
                \else
                    \pgftransformlineattime{\ctikzvalof{tripoles/#1/arrow pos}}{%
                        \pgfpoint{\pgf@circ@res@right}%
                        {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up}%
                        }{%
                        \pgfpoint{\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}%
                        {\ctikzvalof{tripoles/#1/base height 2}\pgf@circ@res@up}%
                    }
                \fi
            \fi
            \pgfnode{trarrow}{\@@anchor}{}{}{\pgfusepath{stroke}}
        \endpgfscope

        \ifpgf@circuit@bpt@drawphoto
            \pgfscope
                \pgf@circ@fill@strokecolor
                \pgf@circ@set@optoarrow@style
                \pgfpathmoveto{\pgfpoint
                    {(0.5+\ctikzvalof{tripoles/#1/base width})*\pgf@circ@res@left}
                    {0.3\pgf@circ@res@up}}
                \pgfpathlineto{\pgfpoint
                    {(0.05+\ctikzvalof{tripoles/#1/base width})*\pgf@circ@res@left}
                    {0.1\pgf@circ@res@up}}
                \pgfusepath{draw}
                \pgfpathmoveto{\pgfpoint
                    {(0.5+\ctikzvalof{tripoles/#1/base width})*\pgf@circ@res@left}
                    {0.1\pgf@circ@res@up}}
                \pgfpathlineto{\pgfpoint
                    {(0.05+\ctikzvalof{tripoles/#1/base width})*\pgf@circ@res@left}
                    {-0.1\pgf@circ@res@up}}
                \pgfusepath{draw}
            \endpgfscope
            \else
            \ifpgf@circuit@bpt@drawbase
                \pgfpathmoveto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
                {\pgf@circ@res@up+\pgf@circ@res@down}}
                \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}{\pgf@circ@res@up+\pgf@circ@res@down}}
                \pgfusepath{draw}
            \fi
        \fi
    }
}

\declarebpt{npn}
\declarebpt{pnp}
%
% multi-emitter and multi-collector BJTs by Romano Giannetti
%
\def\pgf@circ@bjt@C@anchor#1{% #1: collector number
    \pgfextractx{\pgf@circ@res@temp}{\basedimension}
    \pgfextracty{\pgf@circ@res@other}{\basedimension}
    \ifnum\cdir>0 % NPN, above
        \pgfpoint{\pgf@circ@res@temp}{%
        \pgf@circ@res@other+\pgfverticaltransformationadjustment*.5*\pgflinewidth+(#1-1)*\multistep}
    \else % PNP, below
        \pgfpoint{\pgf@circ@res@temp}{%
        -\pgf@circ@res@other-\pgfverticaltransformationadjustment*.5*\pgflinewidth-(#1-1)*\multistep}
    \fi
}
\def\pgf@circ@bjt@E@anchor#1{% #1: collector number
    \pgfextractx{\pgf@circ@res@temp}{\basedimension}
    \pgfextracty{\pgf@circ@res@other}{\basedimension}
    \ifnum\cdir<0 % PNP, above
        \pgfpoint{\pgf@circ@res@temp}{%
        \pgf@circ@res@other+\pgfverticaltransformationadjustment*.5*\pgflinewidth+(#1-1)*\multistep}
    \else % PNP, below
        \pgfpoint{\pgf@circ@res@temp}{%
        -\pgf@circ@res@other-\pgfverticaltransformationadjustment*.5*\pgflinewidth-(#1-1)*\multistep}
    \fi
}

\long\def\declarebjt#1{
    \pgfdeclareshape{bjt#1}{
        \savedmacro{\ctikzclass}{\edef\ctikzclass{transistors}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        % \cdir is 1 for npn, -1 for pnp
        \savedmacro{\cdir}{\edef\cdir{\ctikzvalof{tripoles/bjt/#1/curr direction}}}
        \savedmacro{\numE}{\edef\numE{\ctikzvalof{tripoles/bjt/emitters}}}
        \savedmacro{\numC}{\edef\numC{\ctikzvalof{tripoles/bjt/collectors}}}
        % step up or down for the additional C/Es
        \saveddimen{\multistep}{\pgfmathsetlength{\pgf@x}{%
            \ctikzvalof{tripoles/bjt/height}*\ctikzvalof{tripoles/bjt/multi height}*
            \ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}}
        \saveddimen{\external}{\pgfmathsetlength{\pgf@x}{%
            \ctikzvalof{tripoles/bjt/pins width}*\ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}}
        \savedanchor\basedimension{% these are the dimensions if nC=1 y nE=1
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@y=\ctikzvalof{tripoles/bjt/height}\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@x=\ctikzvalof{tripoles/bjt/width}\pgf@circ@scaled@Rlen
            \pgf@x=.5\pgf@x
        }
        \savedanchor\northeast{% upper right
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgfmathsetlength{\pgf@circ@res@step}{%
                \ctikzvalof{tripoles/bjt/height}*\ctikzvalof{tripoles/bjt/multi height}*
                \ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
            \ifnum\cdir> 0
                \edef\numup{\numC}\edef\numdown{\numE}
            \else
                \edef\numup{\numE}\edef\numdown{\numC}
            \fi
            \pgfmathsetlength{\pgf@y}{0.5*\ctikzvalof{tripoles/bjt/height}\pgf@circ@scaled@Rlen
                + (\numup-1)*\pgf@circ@res@step+\pgfverticaltransformationadjustment*.5*\pgflinewidth
                + \ctikzvalof{tripoles/bjt/pins width}*\ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
            \pgf@x=\ctikzvalof{tripoles/bjt/width}\pgf@circ@scaled@Rlen
            \pgf@x=.5\pgf@x
        }
        \savedanchor\southeast{% lower right
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgfmathsetlength{\pgf@circ@res@step}{%
                \ctikzvalof{tripoles/bjt/height}*\ctikzvalof{tripoles/bjt/multi height}*
                \ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
            \ifnum\cdir> 0
                \edef\numup{\numC}\edef\numdown{\numE}
            \else
                \edef\numup{\numE}\edef\numdown{\numC}
            \fi
            \pgfmathsetlength{\pgf@y}{-0.5*\ctikzvalof{tripoles/bjt/height}\pgf@circ@scaled@Rlen
                - (\numdown-1)*\pgf@circ@res@step-\pgfverticaltransformationadjustment*.5*\pgflinewidth
                - \ctikzvalof{tripoles/bjt/pins width}*\ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
            \pgf@x=\ctikzvalof{tripoles/bjt/width}\pgf@circ@scaled@Rlen
            \pgf@x=.5\pgf@x
        }
        \savedanchor\southwest{% lower left
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgfmathsetlength{\pgf@circ@res@step}{%
                \ctikzvalof{tripoles/bjt/height}*\ctikzvalof{tripoles/bjt/multi height}*
                \ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
            \ifnum\cdir> 0
                \edef\numup{\numC}\edef\numdown{\numE}
            \else
                \edef\numup{\numE}\edef\numdown{\numC}
            \fi
            \pgfmathsetlength{\pgf@y}{-0.5*\ctikzvalof{tripoles/bjt/height}\pgf@circ@scaled@Rlen
                - (\numdown-1)*\pgf@circ@res@step-\pgfverticaltransformationadjustment*.5*\pgflinewidth
                - \ctikzvalof{tripoles/bjt/pins width}*\ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
            \pgfmathsetlength{\pgf@x}{-0.5*\ctikzvalof{tripoles/bjt/width}*\pgf@circ@scaled@Rlen
                - \ctikzvalof{tripoles/bjt/pins width}*\ctikzvalof{\ctikzclass/scale}*\pgf@circ@Rlen}
        }
        \anchor{center}{\pgfpointorigin}
        \anchor{north}{\northeast\pgf@x=0cm\relax}
        \anchor{east}{\northeast\pgf@y=0cm\relax}
        \anchor{south}{\southwest\pgf@x=0cm\relax}
        \anchor{west}{\southwest\pgf@y=0cm}
        \anchor{north east}{\northeast}
        \anchor{north west}{\northeast\pgf@ya=\pgf@y\southwest\pgf@y=\pgf@ya}
        \anchor{south west}{\southwest}
        \anchor{south east}{\southeast}

        \anchor{text}{\northeast\pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax}
        \anchor{B}{\northeast\pgf@y=0cm\pgf@x=-\pgf@x\advance\pgf@x by -\external}
        \anchor{base}{\basedimension\pgf@y=0cm\pgf@x=-\pgf@x\advance\pgf@x by -\external}
        \anchor{nobase}{\basedimension\pgf@y=0cm\pgf@x=-\pgf@x}
        % center of the base "bar"
        \anchor{cbase}{\basedimension\pgf@x=-\pgf@x
            \pgfmathsetlength{\pgf@y}{\cdir*(\numC-\numE)*\multistep/2}%
        }
        % geometrical centers
        \anchor{vcenter}{\pgf@x=0cm\relax
            \pgfmathsetlength{\pgf@y}{\cdir*(\numC-\numE)*\multistep/2}%
        }
        \anchor{gcenter}{%
            \northeast\pgf@xa=0.5\pgf@x
            \southwest\advance\pgf@xa by 0.5\pgf@x
            \pgf@x=\pgf@xa
            \pgfmathsetlength{\pgf@y}{\cdir*(\numC-\numE)*\multistep/2}%
        }
        % external connections
        \anchor{E}{
            \ifnum\cdir>0% npn, emitter down
            \southeast
            \else
            \northeast
            \fi
        }% first emitter
        \anchor{emitter}{\ifnum\cdir>0\southeast\else\northeast\fi}% first emitter
        \anchor{C}{\ifnum\cdir<0\southeast\else\northeast\fi}
        \anchor{collector}{\ifnum\cdir<0\southeast\else\northeast\fi}

        \pgf@circ@draw@component{
            \pgftransformationadjustments
            \pgf@circ@setcolor
            %
            % set the type and up and down number of connections
            %
            \ifnum\cdir> 0
                \pgf@circuit@trans@ntypetrue
                \edef\numup{\numC}
                \edef\numdown{\numE}
            \else
                \pgf@circuit@trans@ntypefalse
                \edef\numup{\numE}
                \edef\numdown{\numC}
            \fi
            \basedimension
            \pgf@circ@res@up = \pgf@y
            \pgf@circ@res@down = -\pgf@y
            \pgf@circ@res@right = \pgf@x
            \pgf@circ@res@left = -\pgf@x
            \pgf@circ@scaled@Rlen=\scaledRlen
            \pgf@circ@res@step=\multistep
            %
            % set arrow positions options
            %
            \edef\@@anchor{center}\edef\@@pos{\ctikzvalof{tripoles/#1/arrow pos}}
            \ifpgf@circuit@trans@arrowatend
                \edef\@@pos{1.0}
                \ifpgf@circuit@trans@ntype % arrow is toward outside, push it a bit
                    \edef\@@anchor{btip}
                \else
                    \edef\@@anchor{tip}
                \fi
            \fi
            %
            % Drawing upper connections
            %
            \pgfscope
            \pgf@circ@count@a=\numup\relax
            \pgfmathloop%
            \ifnum\pgf@circ@count@a>0
            \advance\pgf@circ@count@a-1\relax
            \pgfmathsetlength{\pgf@circ@res@other}{\the\pgf@circ@count@a*\multistep}%
            \ifnum\pgf@circ@count@a=\numexpr\numup-1\relax % draw the external pin connection
            \pgfpathmoveto{\pgfpoint
                {\pgf@circ@res@right}%
                {\pgf@circ@res@up+\external+\pgfverticaltransformationadjustment*.5*\pgflinewidth+\pgf@circ@res@other}}%
            \pgfpathlineto{\pgfpoint
                {\pgf@circ@res@right}%
                {\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth+\pgf@circ@res@other}}%
            \else
            \pgfpathmoveto{\pgfpoint
                {\pgf@circ@res@right}%
                {\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth+\pgf@circ@res@other}}%
            \fi
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left}%
                {\ctikzvalof{tripoles/bjt/base height 2}\pgf@circ@res@up+\pgf@circ@res@other}}%
            \pgfsetroundcap % better when connecting to sloped lines
            \pgfusepath{draw}
            \ifpgf@circuit@trans@ntype\else % it's a PNP; draw arrow
            \pgfscope
                \pgfslopedattimetrue
                \pgfallowupsidedownattimetrue
                \pgfresetnontranslationattimefalse
                \pgftransformlineattime{\@@pos}{%
                    \pgfpoint
                        {\pgf@circ@res@right}%
                        {\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth+\pgf@circ@res@other}%
                    }{\pgfpoint
                        {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left}%
                        {\ctikzvalof{tripoles/bjt/base height 2}\pgf@circ@res@up+\pgf@circ@res@other}%
                    }
                    \pgfnode{trarrow}{\@@anchor}{}{}{\pgfusepath{stroke}}
            \endpgfscope
            \fi
            \repeatpgfmathloop
            \endpgfscope
            %
            % Drawing base
            %
            \pgfscope
                \pgfpathmoveto{\pgfpoint
                    {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left}
                    {\ctikzvalof{tripoles/bjt/base height}\pgf@circ@res@up+(\numup-1)*\multistep}}
                \pgfpathlineto{\pgfpoint
                    {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left}
                    {\ctikzvalof{tripoles/bjt/base height}\pgf@circ@res@down-(\numdown-1)*\multistep}}
                \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
                \ifpgf@circuit@bpt@schottky
                    % upper
                    \pgfpathmoveto{\pgfpoint
                        {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left}
                        {\ctikzvalof{tripoles/bjt/base height}\pgf@circ@res@up+(\numup-1)*\multistep}}
                    \pgfpathlineto{\pgfpoint
                        {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left}
                        {\ctikzvalof{tripoles/bjt/base height}\pgf@circ@res@up+(\numup-1)*\multistep+
                        \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}}
                    \pgfpathlineto{\pgfpoint
                        {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left+
                            \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}
                        {\ctikzvalof{tripoles/bjt/base height}\pgf@circ@res@up+(\numup-1)*\multistep+
                            \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}}
                    \pgfpathlineto{\pgfpoint
                        {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left+
                            \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}
                        {\ctikzvalof{tripoles/bjt/base height}\pgf@circ@res@up+(\numup-1)*\multistep}}
                    % lower
                    \pgfpathmoveto{\pgfpoint
                        {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left}
                        {\ctikzvalof{tripoles/bjt/base height}\pgf@circ@res@down-(\numdown-1)*\multistep}}
                    \pgfpathlineto{\pgfpoint
                        {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left}
                        {\ctikzvalof{tripoles/bjt/base height}\pgf@circ@res@down-(\numdown-1)*\multistep-
                        \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}}
                    \pgfpathlineto{\pgfpoint
                        {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left-
                            \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}
                        {\ctikzvalof{tripoles/bjt/base height}\pgf@circ@res@down-(\numdown-1)*\multistep-
                        \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}}
                    \pgfpathlineto{\pgfpoint
                        {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left-
                            \ctikzvalof{tripoles/schottky base size}\pgf@circ@scaled@Rlen}
                        {\ctikzvalof{tripoles/bjt/base height}\pgf@circ@res@down-(\numdown-1)*\multistep}}
                \fi
                \pgfsetroundcap % I like it more...
                \pgfusepath{draw}
            \endpgfscope
            %
            % draw base external connection
            %
            \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left}{0pt}}
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left-\external}{0pt}}
            \pgfusepath{draw}
            %
            % Drawing lower connections
            %
            \pgfscope
            \pgf@circ@count@a=\numdown\relax
            \pgfmathloop%
            \ifnum\pgf@circ@count@a>0
            \advance\pgf@circ@count@a-1\relax
            \pgfmathsetlength{\pgf@circ@res@other}{\the\pgf@circ@count@a*\multistep}%
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left}
                {\ctikzvalof{tripoles/bjt/base height 2}\pgf@circ@res@down-\pgf@circ@res@other}}
            \pgfpathlineto{\pgfpoint
                {\pgf@circ@res@right}
                {\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth-\pgf@circ@res@other}}
            \ifnum\pgf@circ@count@a=\numexpr\numdown-1\relax % draw the external pin connection
            \pgfpathlineto{\pgfpoint
                {\pgf@circ@res@right}
                {\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth-\pgf@circ@res@other-\external}}
            \fi
            \pgfsetroundcap % better when connecting to sloped lines
            \pgfusepath{draw}
            \ifpgf@circuit@trans@ntype % it's a NPN; draw arrow
            \pgfscope
                \pgfslopedattimetrue
                \pgfallowupsidedownattimetrue
                \pgfresetnontranslationattimefalse
                \pgftransformlineattime{\@@pos}{%
                    \pgfpoint
                        {\ctikzvalof{tripoles/bjt/base width}\pgf@circ@res@left}%
                        {\ctikzvalof{tripoles/bjt/base height 2}\pgf@circ@res@down-\pgf@circ@res@other}%
                    }{\pgfpoint
                        {\pgf@circ@res@right}%
                        {\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth-\pgf@circ@res@other}%
                    }
                    \pgfnode{trarrow}{\@@anchor}{}{}{\pgfusepath{stroke}}
            \endpgfscope
            \fi
            \repeatpgfmathloop
            \endpgfscope
        }
        % \pgf@sh@s@<name of the shape here> contains all the code for the shape
        % and is executed just before a node is drawn.
        \expandafter\pgfutil@g@addto@macro\csname pgf@sh@s@bjt#1\endcsname{%
            % Start with the maximum collector number and go backwards.
            \pgf@circ@count@a=\numC\relax
            \pgfmathloop%
            \ifnum\pgf@circ@count@a>0
                % we will create two anchors per pin: the "normal one" like `pin 1` for the
                % electrical contact, and the "border one" like `bpin 1` for labels.
                % they will coincide if `external pins width` is set to 0.
                \expandafter\xdef\csname pgf@anchor@bjt#1@C\the\pgf@circ@count@a\endcsname{%
                    \noexpand\pgf@circ@bjt@C@anchor{\the\pgf@circ@count@a}%
                }
            \advance\pgf@circ@count@a by -1\relax%
            \repeatpgfmathloop%
            % and emitters
            \pgf@circ@count@a=\numE\relax
            \pgfmathloop%
            \ifnum\pgf@circ@count@a>0
                % we will create two anchors per pin: the "normal one" like `pin 1` for the
                % electrical contact, and the "border one" like `bpin 1` for labels.
                % they will coincide if `external pins width` is set to 0.
                \expandafter\xdef\csname pgf@anchor@bjt#1@E\the\pgf@circ@count@a\endcsname{%
                    \noexpand\pgf@circ@bjt@E@anchor{\the\pgf@circ@count@a}%
                }
            \advance\pgf@circ@count@a by -1\relax%
            \repeatpgfmathloop%
            }%
    }
}

\declarebjt{npn}
\declarebjt{pnp}

% end of multi-bjts

\long\def\declareigbt#1{
    \pgfcircdeclaretransistor{#1}{
        \anchor{inner up}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/gate height}\pgf@y
        }
        \anchor{inner down}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/#1/gate height}\pgf@y
        }
        \anchor{nobase}{
            \left
            \pgf@x=\ctikzvalof{tripoles/#1/gate width}\pgf@x
        }
    }
    {
        % add the circle if requested (before everything else, so we can fill it)
        \pgfcirc@transistorcircle
        % fill the gap color if requested
        \pgfcirc@fillgategap{#1}
        %draw upper connection
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
        {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@up}}
        \pgfusepath{draw}

        %draw thicker gate lines
        \pgfscope
            \pgfscope
                \pgfpathmoveto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
                {\ctikzvalof{tripoles/#1/outer base height}\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5\pgflinewidth}}
                \pgfpathlineto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
                {\ctikzvalof{tripoles/#1/outer base height}\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5\pgflinewidth}}
                % set the normal thickness
                \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
                \edef\@@extrat{\ctikzvalof{tripoles/#1/outer base thickness}}
                \pgfsetlinewidth{\@@extrat\pgflinewidth}
                \pgfusepath{draw}
            \endpgfscope
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5\pgflinewidth}}
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5\pgflinewidth}}
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgfusepath{draw}
        \endpgfscope
        %draw lower connection
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
        {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
        \pgfusepath{draw}
        %draw arrow depending on type of transistor
        \pgfscope
            \pgfslopedattimetrue
            \pgfallowupsidedownattimetrue
            \pgfresetnontranslationattimefalse
            \ifpgf@circuit@trans@arrowatend
                \ifpgf@circuit@trans@ntype
                    \edef\@@anchor{btip}\edef\@@pos{1.0}
                \else
                    \edef\@@anchor{tip}\edef\@@pos{1.0}
                \fi
            \else
                \edef\@@anchor{center}\edef\@@pos{0.5}
            \fi
            \ifpgf@circuit@trans@ntype
                \pgftransformlineattime{\@@pos}{%
                    \pgfpoint%
                    {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}%
                    {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@down}%
                    }{%
                    \pgfpoint{\pgf@circ@res@right}%
                    {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@down}%
                }
            \else
                \pgftransformlineattime{\@@pos}{%
                    \pgfpoint{\pgf@circ@res@right}%
                    {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@up}%
                    }{%
                    \pgfpoint{\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}%
                    {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@up}%
                }
            \fi
            \pgfnode{trarrow}{\@@anchor}{}{}{\pgfusepath{stroke}}
        \endpgfscope
        %draw gate
        \ifpgf@circuit@bpt@drawgate
            \ifpgf@circuit@trans@ntype
                \pgfpathmoveto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
                {\ctikzvalof{tripoles/#1/conn height}\pgf@circ@res@down}}
                \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}%
                {\ctikzvalof{tripoles/#1/conn height}\pgf@circ@res@down}}
            \else
                \pgfpathmoveto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
                {\ctikzvalof{tripoles/#1/conn height}\pgf@circ@res@up}}
                \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}%
                {\ctikzvalof{tripoles/#1/conn height}\pgf@circ@res@up}}
            \fi
        \fi
        \pgfusepath{draw}
    }
}

\declareigbt{pigbt}
\declareigbt{nigbt}
\declareigbt{Lnigbt}
\declareigbt{Lpigbt}

% Graphene FET, See https://github.com/circuitikz/circuitikz/issues/496
\long\def\declaregfet#1{
    \pgfcircdeclaretransistor{#1}{
        \anchor{inner up}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/gate height}\pgf@y
        }
        \anchor{inner down}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/#1/gate height}\pgf@y
        }
        \anchor{outer hex up}{
            \left
            \pgf@xa=\ctikzvalof{tripoles/#1/base width}\pgf@x
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/gate height 2}\pgf@y
            \pgf@x=-\pgf@xa
        }
        \anchor{outer hex down}{
            \left
            \pgf@xa=\ctikzvalof{tripoles/#1/base width}\pgf@x
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/gate height 2}\pgf@y
            \pgf@y=-\pgf@y
            \pgf@x=-\pgf@xa
        }
        \anchor{inner hex up}{
            \left
            \pgf@xa=\ctikzvalof{tripoles/#1/base width}\pgf@x
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/gate height 2}\pgf@y
            \pgf@x=\pgf@xa
        }
        \anchor{inner hex down}{
            \left
            \pgf@xa=\ctikzvalof{tripoles/#1/base width}\pgf@x
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/gate height 2}\pgf@y
            \pgf@y=-\pgf@y
            \pgf@x=\pgf@xa
        }
        \anchor{right}{
            \northeast\pgf@y=0pt\relax
            \pgfmathsetlength{\pgf@xa}{\ctikzvalof{tripoles/#1/base width}*
                \ctikzvalof{tripoles/#1/width}*\pgf@circ@scaled@Rlen}
            \advance \pgf@x by \pgf@xa
        }
        \anchor{text}{% need a different text: no circle, shift to the right
            \northeast
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \ifpgf@circuit@transisors@fixlabels
                \ifpgf@circuit@fet@bodydiode
                    \advance \pgf@x by \extrabodydiodelen
                \else
                    \pgfmathsetlength{\pgf@xa}{\ctikzvalof{tripoles/#1/base width}*
                        \ctikzvalof{tripoles/#1/width}*\pgf@circ@scaled@Rlen}
                    \advance \pgf@x by \pgf@xa
                \fi
                % no circle for gfets
                % add a bit of space to avoid central (substrate) terminal if drawn
                \advance\pgf@x by 0.05\pgf@circ@scaled@Rlen\relax
                \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
            \else
                \pgf@y=.7\pgf@y
                \pgf@x= \pgf@circ@scaled@Rlen
                \pgf@x=0.1\pgf@x
            \fi
        }
    }
    {
        % no circle for gfets (clearly!)
        %draw upper connection to hexagon
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
            {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}
            {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
        \pgfusepath{draw}
        % draw (fillable) hexagon
        \pgfscope
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
                {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
                {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint
                 {-\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
                 {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint
                 {-\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
                 {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
                 {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
                {-\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@up}}
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope
        %draw thicker gate lines
        \pgfscope
            \pgfscope
                \pgfpathmoveto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
                {\ctikzvalof{tripoles/#1/outer base height}\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5\pgflinewidth}}
                \pgfpathlineto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
                {\ctikzvalof{tripoles/#1/outer base height}\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5\pgflinewidth}}
                % set the normal thickness
                \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
                \edef\@@extrat{\ctikzvalof{tripoles/#1/outer base thickness}}
                \pgfsetlinewidth{\@@extrat\pgflinewidth}
                \pgfusepath{draw}
            \endpgfscope
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5\pgflinewidth}}
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5\pgflinewidth}}
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgfusepath{draw}
        \endpgfscope
        %draw arrow depending on type of transistor
        \pgfscope
            \pgfslopedattimetrue
            \pgfallowupsidedownattimetrue
            \pgfresetnontranslationattimefalse
            \ifpgf@circuit@trans@arrowatend
                \ifpgf@circuit@trans@ntype
                    \edef\@@anchor{btip}\edef\@@pos{1.0}
                \else
                    \edef\@@anchor{tip}\edef\@@pos{1.0}
                \fi
            \else
                \edef\@@anchor{center}\edef\@@pos{0.5}
            \fi
            \ifpgf@circuit@trans@ntype
                \pgftransformlineattime{\@@pos}{%
                    \pgfpoint%
                    {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}%
                    {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@down}%
                    }{%
                    \pgfpoint{\pgf@circ@res@right}%
                    {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@down}%
                }
            \else
                \pgftransformlineattime{\@@pos}{%
                    \pgfpoint{\pgf@circ@res@right}%
                    {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@up}%
                    }{%
                    \pgfpoint{\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}%
                    {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@up}%
                }
            \fi
            \pgfnode{trarrow}{\@@anchor}{}{}{\pgfusepath{stroke}}
        \endpgfscope
        %draw gate
        \ifpgf@circuit@trans@ntype
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/conn height}\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}%
            {\ctikzvalof{tripoles/#1/conn height}\pgf@circ@res@down}}
        \else
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/conn height}\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}%
            {\ctikzvalof{tripoles/#1/conn height}\pgf@circ@res@up}}
        \fi
        \pgfusepath{draw}
    }
}

\declaregfet{pgfet}
\declaregfet{ngfet}

% Plain MOSes

\pgfcircdeclaretransistor{nmos}{
        \anchor{inner up}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/nmos/gate height}\pgf@y
        }
        \anchor{inner down}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/nmos/gate height}\pgf@y
        }
    }{%
    % add the circle if requested (before everything else, so we can fill it)
    \pgfcirc@transistorcircle
    % fill the gap color if requested
    \pgfcirc@fillgategap{nmos}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/nmos/gate height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/nmos/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/nmos/gate height}\pgf@circ@res@up}}

    \pgfpathmoveto{\pgfpoint
        {\ctikzvalof{tripoles/nmos/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/nmos/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/nmos/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
    \pgfusepath{draw}

    \pgfscope
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/nmos/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/nmos/base height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/nmos/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/nmos/base height}\pgf@circ@res@down}}
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/nmos/gate width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/nmos/gate height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/nmos/gate width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/nmos/gate height}\pgf@circ@res@down}}
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfusepath{draw}
    \endpgfscope
    \ifpgf@circuit@mos@arrows
        \pgfscope
            \ifpgf@circuit@trans@arrowatend
                \pgftransformshift{\pgfpoint
                    {\pgf@circ@res@right}%
                    {\ctikzvalof{tripoles/pmos/gate height}\pgf@circ@res@down}%
                }
                \pgfnode{trarrow}{btip}{}{}{\pgfusepath{stroke}}
            \else
                \pgfslopedattimetrue
                \pgfallowupsidedownattimetrue
                \pgfresetnontranslationattimefalse
                \pgftransformlineattime{\ctikzvalof{tripoles/nmos/arrow pos}}{%
                    \pgfpoint%
                    {\ctikzvalof{tripoles/nmos/gate width}\pgf@circ@res@left}%
                    {\ctikzvalof{tripoles/nmos/gate height}\pgf@circ@res@down}%
                    }{%
                    \pgfpoint
                    {\pgf@circ@res@right}%
                    {\ctikzvalof{tripoles/nmos/gate height}\pgf@circ@res@down}%
                }
                \pgfnode{currarrow}{center}{}{}{\pgfusepath{stroke}}
            \fi
        \endpgfscope
    \fi

    \ifpgf@circuit@bpt@drawgate
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/nmos/gate width}\pgf@circ@res@left}
        {\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}{\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfusepath{draw}
    \fi

    \ifpgf@circuit@bpt@drawbulk % added by Burak Kelleci
        \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/nmos/base width}\pgf@circ@res@left}
                {\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}
                {\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfusepath{draw}
    \fi

    \pgfcirc@ferroelectric{nmos}{0}
}

\pgfcircdeclaretransistor{pmos}{
        \anchor{inner up}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/pmos/gate height}\pgf@y
        }
        \anchor{inner down}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/pmos/gate height}\pgf@y
        }
    }{%
    % add the circle if requested (before everything else, so we can fill it)
    \pgfcirc@transistorcircle
    % fill the gap color if requested
    \pgfcirc@fillgategap{nmos}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/pmos/gate height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/pmos/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/pmos/gate height}\pgf@circ@res@up}}
    \pgfusepath{draw}

    \ifpgf@circuit@mos@arrows
        \pgfscope
            \ifpgf@circuit@trans@arrowatend
                \pgftransformshift{\pgfpoint
                    {\ctikzvalof{tripoles/pmos/base width}\pgf@circ@res@left}%
                    {\ctikzvalof{tripoles/pmos/gate height}\pgf@circ@res@up}%
                }
                \pgftransformrotate{180}
                \pgfnode{trarrow}{tip}{}{}{\pgfusepath{stroke}}
            \else
                \pgfslopedattimetrue
                \pgfallowupsidedownattimetrue
                \pgfresetnontranslationattimefalse
                \pgftransformlineattime{\ctikzvalof{tripoles/pmos/arrow pos}}{%
                    \pgfpoint%
                    {\pgf@circ@res@right}%
                    {\ctikzvalof{tripoles/pmos/gate height}\pgf@circ@res@up}%
                    }{%
                    \pgfpoint
                    {\ctikzvalof{tripoles/pmos/gate width}\pgf@circ@res@left}%
                    {\ctikzvalof{tripoles/pmos/gate height}\pgf@circ@res@up}%
                }
                \pgfnode{currarrow}{center}{}{}{\pgfusepath{stroke}}
            \fi
        \endpgfscope
    \fi

    \pgfscope
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/pmos/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/pmos/base height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/pmos/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/pmos/base height}\pgf@circ@res@down}}
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/pmos/gate width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/pmos/gate height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/pmos/gate width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/pmos/gate height}\pgf@circ@res@down}}
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfusepath{draw}
    \endpgfscope

    \pgfpathmoveto{\pgfpoint
        {\ctikzvalof{tripoles/pmos/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/pmos/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/pmos/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth}}


    \pgfusepath{draw}
    \ifpgf@circuit@bpt@drawgate
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/pmos/gate width}\pgf@circ@res@left}
        {\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}{\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfusepath{draw}
    \fi

    \ifpgf@circuit@bpt@drawbulk % added by Burak Kelleci
        \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/pmos/base width}\pgf@circ@res@left}
                {\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}
                {\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfusepath{draw}
    \fi

    \ifpgf@circuit@pmos@nocircle\else
        % we are not scaling the circle with the MOS --- I think it's better to have it
        % coherent with the poles/nodes of the rest of the circuit.
        \pgfpathcircle{\pgfpoint
            {\ctikzvalof{tripoles/pmos/gate width}\pgf@circ@res@left - \ctikzvalof{nodes width}*\pgf@circ@Rlen}
        {\pgf@circ@res@up+\pgf@circ@res@down}}{\ctikzvalof{nodes width}*\pgf@circ@Rlen}
        \ifpgf@circuit@pmos@emptycircle
            \pgfsetfillcolor{white}
        \fi
        \pgfusepath{draw,fill}
    \fi

    \pgfcirc@ferroelectric{pmos}{0}
}

%%% depletion MOSFET (simplified symbols)

\long\def\pgfcirc@filldraw@depletion#1{%
    \ifx\tikz@fillcolor\pgfutil@empty
        % if there is no explicit fill check the specific key
        \edef\@@tmp{\ctikzvalof{tripoles/#1/depletion color}}\edef\@@none{none}%
        \ifx\@@tmp\@@none % if  it's none
            \pgfusepath{draw}%
        \else
            \edef\@@default{default}%
            \ifx\@@tmp\@@default % fill with the pen color
                \pgf@circ@fill@strokecolor
                \pgfusepath{draw, fill}%
            \else
                \pgfsetfillcolor{\@@tmp}%
                \pgfusepath{draw, fill}%
            \fi
        \fi
    \else
        \pgfsetfillcolor{\tikz@fillcolor}%
        \pgfusepath{draw, fill}%
    \fi
}

\pgfcircdeclaretransistor{nmosd}{
        \anchor{inner up}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/nmosd/gate height}\pgf@y
        }
        \anchor{inner down}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/nmosd/gate height}\pgf@y
        }
        \anchor{nobulk}{ %override
            \left
            \pgf@circ@res@temp=\ctikzvalof{tripoles/nmosd/depletion width}\pgf@x
            \pgf@x=\ctikzvalof{tripoles/nmosd/base width}\pgf@x
            \advance\pgf@x by -\pgf@circ@res@temp
        }
    }{%
    % draw depletion channel
    % add the circle if requested (before everything else, so we can fill it)
    \pgfcirc@transistorcircle
    % fill the gap color if requested
    \pgfcirc@fillgategap{nmos}
    \pgfscope
        \pgfpathrectanglecorners
        {\pgfpoint
        {\ctikzvalof{tripoles/nmosd/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/nmosd/gate height}\pgf@circ@res@up}}
        {\pgfpoint
        {(\ctikzvalof{tripoles/nmosd/base width} - \ctikzvalof{tripoles/nmosd/depletion width})*\pgf@circ@res@left}
        {-\ctikzvalof{tripoles/nmosd/gate height}\pgf@circ@res@up}}
        \pgfcirc@filldraw@depletion{nmosd}
    \endpgfscope
    % draw drain and source terminals
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\ctikzvalof{tripoles/nmosd/gate height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/nmosd/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/nmosd/gate height}\pgf@circ@res@up}}

    \pgfpathmoveto{\pgfpoint
        {\ctikzvalof{tripoles/nmosd/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/nmosd/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/nmosd/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
    \pgfusepath{draw}

    \pgfscope
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/nmosd/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/nmosd/base height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/nmosd/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/nmosd/base height}\pgf@circ@res@down}}
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/nmosd/gate width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/nmosd/gate height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/nmosd/gate width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/nmosd/gate height}\pgf@circ@res@down}}
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfusepath{draw}
    \endpgfscope
    \ifpgf@circuit@mos@arrows
        \pgfscope
            \ifpgf@circuit@trans@arrowatend
                \pgftransformshift{\pgfpoint
                    {\pgf@circ@res@right}%
                    {\ctikzvalof{tripoles/pmosd/gate height}\pgf@circ@res@down}%
                }
                \pgfnode{trarrow}{btip}{}{}{\pgfusepath{stroke}}
            \else
                \pgfslopedattimetrue
                \pgfallowupsidedownattimetrue
                \pgfresetnontranslationattimefalse
                \pgftransformlineattime{\ctikzvalof{tripoles/nmosd/arrow pos}}{%
                    \pgfpoint%
                    {\ctikzvalof{tripoles/nmosd/gate width}\pgf@circ@res@left}%
                    {\ctikzvalof{tripoles/nmosd/gate height}\pgf@circ@res@down}%
                    }{%
                    \pgfpoint
                    {\pgf@circ@res@right-\ctikzvalof{tripoles/nmosd/depletion width}*\pgf@circ@res@left}%
                    {\ctikzvalof{tripoles/nmosd/gate height}\pgf@circ@res@down}%
                }
                \pgfnode{currarrow}{center}{}{}{\pgfusepath{stroke}}
            \fi
        \endpgfscope
    \fi

    \ifpgf@circuit@bpt@drawgate
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/nmosd/gate width}\pgf@circ@res@left}
        {\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}{\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfusepath{draw}
    \fi

    \ifpgf@circuit@bpt@drawbulk % added by Burak Kelleci
        \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/nmosd/base width}\pgf@circ@res@left-\ctikzvalof{tripoles/nmosd/depletion width}*\pgf@circ@res@left}
                {\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}
                {\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfusepath{draw}
    \fi

    \pgfcirc@ferroelectric{nmosd}{\ctikzvalof{tripoles/nmosd/depletion width}}
}

\pgfcircdeclaretransistor{pmosd}{
        \anchor{inner up}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/pmosd/gate height}\pgf@y
        }
        \anchor{inner down}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/pmosd/gate height}\pgf@y
        }
        \anchor{nobulk}{ %override
            \left
            \pgf@circ@res@temp=\ctikzvalof{tripoles/pmosd/depletion width}\pgf@x
            \pgf@x=\ctikzvalof{tripoles/pmosd/base width}\pgf@x
            \advance\pgf@x by -\pgf@circ@res@temp
        }
    }{%
    % add the circle if requested (before everything else, so we can fill it)
    \pgfcirc@transistorcircle
    % fill the gap color if requested
    \pgfcirc@fillgategap{nmos}
    % draw depletion channel
    \pgfscope
        \pgfpathrectanglecorners
        {\pgfpoint
        {\ctikzvalof{tripoles/pmosd/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/pmosd/gate height}\pgf@circ@res@up}}
        {\pgfpoint
        {(\ctikzvalof{tripoles/pmosd/base width} - \ctikzvalof{tripoles/pmosd/depletion width})*\pgf@circ@res@left}
        {-\ctikzvalof{tripoles/pmosd/gate height}\pgf@circ@res@up}}
        \pgfcirc@filldraw@depletion{pmosd}
    \endpgfscope
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/pmosd/gate height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/pmosd/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/pmosd/gate height}\pgf@circ@res@up}}
    \pgfusepath{draw}

    \ifpgf@circuit@mos@arrows
        \pgfscope
            \ifpgf@circuit@trans@arrowatend
                \pgftransformshift{\pgfpoint
                    {\ctikzvalof{tripoles/pmosd/base width}\pgf@circ@res@left-\ctikzvalof{tripoles/nmosd/depletion width}*\pgf@circ@res@left}%
                    {\ctikzvalof{tripoles/pmosd/gate height}\pgf@circ@res@up}%
                }
                \pgftransformrotate{180}
                \pgfnode{trarrow}{tip}{}{}{\pgfusepath{stroke}}
            \else
                \pgfslopedattimetrue
                \pgfallowupsidedownattimetrue
                \pgfresetnontranslationattimefalse
                \pgftransformlineattime{\ctikzvalof{tripoles/pmosd/arrow pos}}{%
                    \pgfpoint%
                    {\pgf@circ@res@right-\ctikzvalof{tripoles/nmosd/depletion width}*\pgf@circ@res@left}%
                    {\ctikzvalof{tripoles/pmosd/gate height}\pgf@circ@res@up}%
                    }{%
                    \pgfpoint
                    {\ctikzvalof{tripoles/pmosd/gate width}\pgf@circ@res@left}%
                    {\ctikzvalof{tripoles/pmosd/gate height}\pgf@circ@res@up}%
                }
                \pgfnode{currarrow}{center}{}{}{\pgfusepath{stroke}}
            \fi
        \endpgfscope
    \fi

    \pgfscope
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/pmosd/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/pmosd/base height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/pmosd/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/pmosd/base height}\pgf@circ@res@down}}
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/pmosd/gate width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/pmosd/gate height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/pmosd/gate width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/pmosd/gate height}\pgf@circ@res@down}}
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfusepath{draw}
    \endpgfscope

    \pgfpathmoveto{\pgfpoint
        {\ctikzvalof{tripoles/pmosd/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/pmosd/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/pmosd/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth}}


    \pgfusepath{draw}
    \ifpgf@circuit@bpt@drawgate
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/pmosd/gate width}\pgf@circ@res@left}
        {\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}{\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfusepath{draw}
    \fi

    \ifpgf@circuit@bpt@drawbulk % added by Burak Kelleci
        \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/pmosd/base width}\pgf@circ@res@left-\ctikzvalof{tripoles/nmosd/depletion width}*\pgf@circ@res@left}
                {\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}
                {\pgf@circ@res@up+\pgf@circ@res@down}}
        \pgfusepath{draw}
    \fi

    \ifpgf@circuit@pmos@nocircle\else
        % we are not scaling the circle with the MOS --- I think it's better to have it
        % coherent with the poles/nodes of the rest of the circuit.
        \pgfpathcircle{\pgfpoint
            {\ctikzvalof{tripoles/pmosd/gate width}\pgf@circ@res@left - \ctikzvalof{nodes width}*\pgf@circ@Rlen}
        {\pgf@circ@res@up+\pgf@circ@res@down}}{\ctikzvalof{nodes width}*\pgf@circ@Rlen}
        \ifpgf@circuit@pmos@emptycircle
            \pgfsetfillcolor{white}
        \fi
        \pgfusepath{draw,fill}
    \fi

    \pgfcirc@ferroelectric{pmosd}{\ctikzvalof{tripoles/pmosd/depletion width}}
}
%% HEMT FET Transistor
\def\pgf@circ@hemt@gate@anchor@helper{%
    \northeast
    \pgf@circ@res@up = \pgf@y
    \pgf@circ@res@down = -\pgf@y
    \pgfmathsetlength{\pgf@circ@res@step}{{(1+\gateasym)*\pgf@circ@res@up+(1-\gateasym)*\pgf@circ@res@down}}
    \left
    \pgf@y=\pgf@circ@res@step
}
\pgfcircdeclaretransistor{hemt}{
        \savedmacro{\gateasym}{\edef\gateasym{\ctikzvalof{tripoles/hemt/gate asym}}}
        \anchor{inner up}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/hemt/gate height}\pgf@y
        }
        \anchor{inner down}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/hemt/gate height}\pgf@y
        }
        % override gate/base anchors
        \anchor{G}{\pgf@circ@hemt@gate@anchor@helper}
        \anchor{gate}{\pgf@circ@hemt@gate@anchor@helper}
        \anchor{nogate}{\pgf@circ@hemt@gate@anchor@helper\pgf@x=\ctikzvalof{tripoles/hemt/base width}\pgf@x}
        \anchor{B}{\pgf@circ@hemt@gate@anchor@helper}
        \anchor{base}{\pgf@circ@hemt@gate@anchor@helper}
        \anchor{nobase}{\pgf@circ@hemt@gate@anchor@helper\pgf@x=\ctikzvalof{tripoles/hemt/base width}\pgf@x}
    }{%
    % add the circle if requested (before everything else, so we can fill it)
    \pgfcirc@transistorcircle
    % upper connection
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/hemt/gate height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/hemt/gate height}\pgf@circ@res@up}}
    % lower connection
    \pgfpathmoveto{\pgfpoint
        {\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/hemt/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
        {\ctikzvalof{tripoles/hemt/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint
        {\pgf@circ@res@right}{\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
    \pgfusepath{draw}
    \pgfscope
        \edef\@@tmp{\ctikzvalof{tripoles/hemt/source arrow}}
        \ifnum\@@tmp=0 \else
            \ifpgf@circuit@trans@arrowatend
                \ifnum\@@tmp > 0 %
                    \pgftransformshift{\pgfpoint
                        {\pgf@circ@res@right}
                        {\ctikzvalof{tripoles/hemt/gate height}\pgf@circ@res@down}}
                \else
                    \pgftransformshift{\pgfpoint
                        {\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
                        {\ctikzvalof{tripoles/hemt/gate height}\pgf@circ@res@down}}
                        \ifnum\@@tmp < 0 \pgftransformrotate{180}\fi
                \fi
                    \pgfnode{trarrow}{tip}{}{}{\pgfusepath{stroke}}
            \else
                % the position here is a bit strange...
                \pgftransformshift{\pgfpoint
                    {0.5*\pgf@circ@res@right+0.5*\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
                    {\ctikzvalof{tripoles/hemt/gate height}\pgf@circ@res@down}}
                    \ifnum\@@tmp < 0 \pgftransformrotate{180}\fi
                    \pgfnode{trarrow}{center}{}{}{\pgfusepath{stroke}}
            \fi
        \fi
    \endpgfscope
    \pgfscope
        % draw gate (base) bar
        \ifpgf@circ@hemt@split
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
                {\ctikzvalof{tripoles/hemt/base height}\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
                {(1.1+\gateasym)*\pgf@circ@res@up +
                 (0.9-\gateasym)*\pgf@circ@res@down}}
            \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
                {(1.05+\gateasym)*\pgf@circ@res@up +
                 (0.95-\gateasym)*\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
                {(0.95+\gateasym)*\pgf@circ@res@up +
                 (1.05-\gateasym)*\pgf@circ@res@down}}
            \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
                {(0.9+\gateasym)*\pgf@circ@res@up +
                 (1.1-\gateasym)*\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/hemt/base height}\pgf@circ@res@down}}
        \else
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/hemt/base height}\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/hemt/base height}\pgf@circ@res@down}}
        \fi
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfusepath{draw}
    \endpgfscope
    % draw the gate horizontal segment
    \ifpgf@circuit@bpt@drawgate
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/hemt/base width}\pgf@circ@res@left}
        {(1+\gateasym)*\pgf@circ@res@up+(1-\gateasym)*\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}
            {(1+\gateasym)*\pgf@circ@res@up+(1-\gateasym)*\pgf@circ@res@down}}
        \pgfusepath{draw}
    \fi
}
\tikzset{GaN hemt/.style={hemt,
        circuitikz/tripoles/hemt/base height=0.6,%length of the "base" vertical bar
        circuitikz/tripoles/hemt/gate height=0.5,%distance of the S/D terminals
        circuitikz/tripoles/hemt/bodydiode conn=0.85,% attachment point of body diode
        circuitikz/tripoles/hemt/gate asym=-0.1,% slightly down
        circuitikz/tripoles/hemt/split gate=true,% split gate
        circuitikz/tripoles/hemt/source arrow=1,% right-facing arrow
    },
}

\long\def\drawfetcore#1{
    \pgftransformationadjustments
    % add the circle if requested (before everything else, so we can fill it)
    \pgfcirc@transistorcircle
    % fill the gap color if requested
    \pgfcirc@fillgategap{#1}

    %top connection
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfscope
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up}}
        \ifpgf@circuit@trans@depletiontype
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down}}
        \else

            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up*0.45}}
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@up*0.25}}
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down*0.25}}
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/nfet/base height}\pgf@circ@res@down*0.45}}
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/base height}\pgf@circ@res@down}}
        \fi
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfusepath{draw}
    \endpgfscope
    %Bulk connection line
    \pgfpathmoveto{\pgfpoint
        {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
    {\pgf@circ@res@up+\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}
    {\pgf@circ@res@up+\pgf@circ@res@down}}

    %bottom connection
    \pgfpathmoveto{\pgfpoint
        {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
    \pgfusepath{draw}

    %draw thick gate line
    \pgfscope%%% gate line
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
        \ifpgf@circuit@fet@doublegate
            \edef\@@gateconnheight{(\ctikzvalof{tripoles/#1/conn height})}
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
                {\@@gateconnheight*\pgf@circ@res@up/3}}
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
                {\@@gateconnheight*\pgf@circ@res@down/3}}
        \fi
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
        \pgfusepath{draw}
    \endpgfscope

    % arrows
    \pgfscope
        \pgfslopedattimetrue
        \pgfallowupsidedownattimetrue
        \pgfresetnontranslationattimefalse
        \ifpgf@circuit@trans@arrowatend
                \ifpgf@circuit@trans@ntype
                    \edef\@@anchor{tip}
                    \edef\@@pos{1.0}
                \else
                    \edef\@@anchor{btip}
                    \edef\@@pos{0.0}
                \fi
        \else
            \edef\@@anchor{center}\edef\@@pos{0.6}
        \fi
        \pgftransformlineattime{\@@pos}{%
            \pgfpoint
            {\pgf@circ@res@right}%
            {\pgf@circ@res@up+\pgf@circ@res@down}%
            }{%
            \pgfpoint%
            {\ctikzvalof{tripoles/#1/base width}\pgf@circ@res@left}%
            {\pgf@circ@res@up+\pgf@circ@res@down}%
        }
        \ifpgf@circuit@trans@ntype
        \else
            \pgftransformrotate{180}
        \fi
        \pgfnode{trarrow}{\@@anchor}{}{}{\pgfusepath{stroke}}
    \endpgfscope

    % GATE CONNECTION
    \ifpgf@circuit@bpt@drawgate
        \pgfscope %% gate connection
            \ifpgf@circuit@trans@ntype
                \edef\@@gateconnheight{(\ctikzvalof{tripoles/#1/conn height})}
            \else
                \edef\@@gateconnheight{(-\ctikzvalof{tripoles/#1/conn height})}
            \fi
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
                {\@@gateconnheight*\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint
                {\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}
                {\@@gateconnheight*\pgf@circ@res@down}}
            \ifpgf@circuit@fet@doublegate
                \pgfpathmoveto{\pgfpoint
                    {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
                    {-\@@gateconnheight*\pgf@circ@res@down/3}}
                \pgfpathlineto{\pgfpoint
                    {\pgf@circ@res@left-\pgfhorizontaltransformationadjustment*.5*\pgflinewidth}
                    {-\@@gateconnheight*\pgf@circ@res@down/3}}
            \fi
            \pgfusepath{draw}
        \endpgfscope
    \fi

    \pgfcirc@ferroelectric{#1}{0}

}

\long\def\pgfdeclaretransistorwrapperaddbulk#1#2#3{
    \pgfcircdeclaretransistor{#1}{
        \anchor{bulk}{\left\pgf@x=0pt}
        \anchor{B}{\left\pgf@x=0pt}%override Base anchor from npn&igbt
        \anchor{inner up}{
            \northeast
            \pgf@y=\ctikzvalof{tripoles/#1/gate height}\pgf@y
        }
        \anchor{inner down}{
            \northeast
            \pgf@y=-\ctikzvalof{tripoles/#1/gate height}\pgf@y
        }
        #2%
    }
    {#3}
}

\pgfdeclaretransistorwrapperaddbulk{nfet}{}{%
	\pgf@circuit@trans@depletiontypefalse
	\drawfetcore{nfet}
}

\pgfdeclaretransistorwrapperaddbulk{pfet}{}{%
    \pgf@circuit@trans@depletiontypefalse
    \drawfetcore{pfet}
}

\pgfdeclaretransistorwrapperaddbulk{nfetd}{}{%
	\pgf@circuit@trans@depletiontypetrue
	\drawfetcore{nfetd}
}

\pgfdeclaretransistorwrapperaddbulk{pfetd}{}{%
    \pgf@circuit@trans@depletiontypetrue
    \drawfetcore{pfetd}
}
% N-CHANNEL IGFET ENHANCEMENT TYPE
\pgfdeclaretransistorwrapperaddbulk{nigfete}{}{%
    \pgf@circuit@trans@depletiontypefalse
    \drawfetcore{nigfete}

    % SOURCE CONNECTION
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{draw}

    % SOLDER DOT at source-bulk connection
    \ifpgf@circuit@fet@solderdot
        \pgfscope
            \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{
            \ctikzvalof{tripoles/nigfete/gate height}\pgf@circ@res@down}}
            \pgftransformscale{\ctikzvalof{transistor solderdot scale}}
            \pgfnode{circ}{center}{}{}{}
    \endpgfscope{}
\fi
}

% N-CHANNEL IGFET ENHANCEMENT TYPE with Bulk connector
\pgfdeclaretransistorwrapperaddbulk{nigfetebulk}{}{%
    \pgf@circuit@trans@depletiontypefalse
    \drawfetcore{nigfetebulk}
    % SOLDER DOT at source-bulk connection
    \ifpgf@circuit@fet@solderdot
        \pgfscope
            \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{
            \ctikzvalof{tripoles/nigfetebulk/gate height}\pgf@circ@res@down}}
            \pgftransformscale{\ctikzvalof{transistor solderdot scale}}
            \pgfnode{circ}{center}{}{}{}
        \endpgfscope{}
    \fi
}

% N-CHANNEL IGFET DEPLETION TYPE
\pgfdeclaretransistorwrapperaddbulk{nigfetd}{}{%
    \pgf@circuit@trans@depletiontypetrue
    \drawfetcore{nigfetd}

    % SOURCE CONNECTION
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{draw}

    % SOLDER DOT at source-bulk connection
    \ifpgf@circuit@fet@solderdot
        \pgfscope
            \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{
            \ctikzvalof{tripoles/nigfete/gate height}\pgf@circ@res@down}}
            \pgftransformscale{\ctikzvalof{transistor solderdot scale}}
            \pgfnode{circ}{center}{}{}{}
        \endpgfscope{}
    \fi
}

% P-CHANNEL IGFET ENHANCEMENT TYPE
\pgfdeclaretransistorwrapperaddbulk{pigfete}{}{%
    \pgf@circuit@trans@depletiontypefalse
    \drawfetcore{pigfete}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}

    % SOURCE CONNECTION
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}


    % SOLDER DOT at source-bulk connection
    \ifpgf@circuit@fet@solderdot
        \pgfscope
            \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{
            \ctikzvalof{tripoles/pigfete/gate height}\pgf@circ@res@up}}
            \pgftransformscale{\ctikzvalof{transistor solderdot scale}}
            \pgfnode{circ}{center}{}{}{}
        \endpgfscope
    \fi
}

% P-CHANNEL IGFET ENHANCEMENT TYPE with bulk connector
\pgfdeclaretransistorwrapperaddbulk{pigfetebulk}{}{%
    \pgf@circuit@trans@depletiontypefalse
    \drawfetcore{pigfetebulk}
}

% P-CHANNEL IGFET DEPLETION TYPE
\pgfdeclaretransistorwrapperaddbulk{pigfetd}{}{%
    \pgf@circuit@trans@depletiontypetrue
    \drawfetcore{pigfetd}

    % SOURCE CONNECTION
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}


    % SOLDER DOT at source-bulk connection
    \ifpgf@circuit@fet@solderdot
        \pgfscope
            \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{
            \ctikzvalof{tripoles/nigfete/gate height}\pgf@circ@res@up}}
            \pgftransformscale{\ctikzvalof{transistor solderdot scale}}
            \pgfnode{circ}{center}{}{}{}
        \endpgfscope{}
    \fi
}

%%% uni-junction transistors: jfets, ujts

\long\def\pgfcircdeclarejunctiontransistor#1#2#3{% name, extra anchors, extra draw
    \pgfcircdeclaretransistor{#1}{
            \anchor{inner up}{
                \northeast
                \pgf@y=\ctikzvalof{tripoles/#1/gate height 2}\pgf@y
            }
            \anchor{inner down}{
                \northeast
                \pgf@y=-\ctikzvalof{tripoles/#1/gate height 2}\pgf@y
            }
            \anchor{kink}{
                \northeast
                \pgf@ya=-\ctikzvalof{tripoles/#1/gate height 2}\pgf@y
                \left
                \pgf@y=\ctikzvalof{tripoles/#1/curr direction}\pgf@ya
                \pgf@x=\ctikzvalof{tripoles/#1/conn kink}\pgf@x
            }
            % extra anchors (or override)
            #2%
        }{%
        % add the circle if requested (before everything else, so we can fill it)
        \pgfcirc@transistorcircle

        % get direction
        \edef\@@dir{\ctikzvalof{tripoles/#1/curr direction}}

        % draw drain/source connections: up
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
        {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@up}}

        % down
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
        {\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
        \pgfusepath{draw}

        \pgfscope
            \pgfpathmoveto{\pgfpoint
                {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint
                {\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/#1/gate height}\pgf@circ@res@down}}
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgfusepath{draw}
        \endpgfscope

        % arrow
        \pgfscope
            \pgfslopedattimetrue
            \pgfallowupsidedownattimetrue
            \pgfresetnontranslationattimefalse
            \ifpgf@circuit@trans@arrowatend
                \ifnum\@@dir>0
                    \edef\@@anchor{tip}\edef\@@pos{1.0}
                \else
                    \edef\@@anchor{btip}\edef\@@pos{1.0}
                \fi
            \else
                \ifnum\@@dir>0
                    \edef\@@anchor{center}\edef\@@pos{0.6}
                \else
                    \edef\@@anchor{center}\edef\@@pos{0.4}
                \fi
            \fi
            % find x1, x2 and y for the base arrow
            \ifnum\@@dir>0
                \pgf@circ@res@step=\ctikzvalof{tripoles/#1/conn kink}\pgf@circ@res@left
                \pgf@circ@res@other=\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left
                \pgf@circ@res@zero=\ctikzvalof{tripoles/#1/union height}\pgf@circ@res@down
                \pgf@circ@res@temp=\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@down
            \else
                \pgf@circ@res@step=\ctikzvalof{tripoles/#1/gate width}\pgf@circ@res@left
                \pgf@circ@res@other=\ctikzvalof{tripoles/#1/conn kink}\pgf@circ@res@left
                \pgf@circ@res@zero=\ctikzvalof{tripoles/#1/gate height 2}\pgf@circ@res@up
                \pgf@circ@res@temp=\ctikzvalof{tripoles/#1/union height}\pgf@circ@res@up
            \fi
            %
            % gate line (called emitter in UJT)
            %
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@temp}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@zero}}
            %
            % horizontal gate line
            %
            \ifpgf@circuit@bpt@drawgate
                \ifnum\@@dir>0
                    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@temp}}
                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}
                \else
                    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@zero}}
                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
                \fi
            \fi
            \pgfusepath{draw}
            %
            % gate arrows (called emitter in UJT)
            %
            \pgftransformlineattime{\@@pos}{%
                \pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@temp}
                }{%
                \pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@zero}
            }
            \pgfnode{trarrow}{\@@anchor}{}{}{\pgfusepath{stroke}}
            %
            % gate line (called emitter in UJT)
            %
        \endpgfscope

        % extra drawings
        #3%
    }
}

% NJFET and PJFET

\pgfcircdeclarejunctiontransistor{njfet}{}{}
\pgfcircdeclarejunctiontransistor{pjfet}{}{}

\def\@ujtanchoroverride#1{
    \savedanchor{\ujtrealemitter}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/#1/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y %north anchor height
        % kink AND conn height, they're the same
        \pgf@y=-\ctikzvalof{tripoles/#1/gate height 2}\pgf@y
        \pgf@y=\ctikzvalof{tripoles/#1/curr direction}\pgf@y
        % horizontal
        \pgf@x=-\ctikzvalof{tripoles/#1/width}\pgf@circ@scaled@Rlen % left
        \ifpgf@circuit@bpt@drawgate\else
            \pgf@x=\ctikzvalof{tripoles/#1/conn kink}\pgf@x
        \fi
    }
    \anchor{E}{\ujtrealemitter}
    \anchor{emitter}{\ujtrealemitter}
    \anchor{B2}{\northeast\pgf@y=-\pgf@y}
    \anchor{B1}{\northeast}
}


\pgfcircdeclarejunctiontransistor{nujt}{\@ujtanchoroverride{nujt}}{}
\pgfcircdeclarejunctiontransistor{pujt}{\@ujtanchoroverride{pujt}}{}


\pgfdeclaretransistorwrapperaddbulk{isfet}{
    }{%
    % add the circle if requested (before everything else, so we can fill it)
    \pgfcirc@transistorcircle
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
    % DRAIN CONNECTION
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/isfet/gate height}\pgf@circ@res@up}}
    % DRAIN
    \pgfpathlineto{\pgfpoint
        {\ctikzvalof{tripoles/isfet/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/isfet/gate height}\pgf@circ@res@up}}
    \pgfusepath{draw}

    % GATE, DEPLETION TYPE
    \pgfscope %% added
        \pgfpathmoveto{\pgfpoint
            {\ctikzvalof{tripoles/isfet/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/isfet/base height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/isfet/base width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/isfet/base height}\pgf@circ@res@down}}
        \pgf@circ@setlinewidth{tripoles}{\pgflinewidth} %% added
        \pgfusepath{draw} %% added
    \endpgfscope %% added

    % BULK
    \pgfpathmoveto{\pgfpoint
        {\ctikzvalof{tripoles/isfet/base width}\pgf@circ@res@left}
    {\pgf@circ@res@up+\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+.5\pgflinewidth}
    {\pgf@circ@res@up+\pgf@circ@res@down}}

    % SOURCE
    \pgfpathmoveto{\pgfpoint
        {\ctikzvalof{tripoles/isfet/base width}\pgf@circ@res@left}
    {\ctikzvalof{tripoles/isfet/gate height}\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}
    {\ctikzvalof{tripoles/isfet/gate height}\pgf@circ@res@down}}
    % SOURCE CONNECTION
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down-\pgfverticaltransformationadjustment*.5*\pgflinewidth}}
    \pgfusepath{draw}

    % SOLDER DOT at source-bulk connection
    \ifpgf@circuit@fet@solderdot
        \pgfscope
            \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{
            \ctikzvalof{tripoles/nigfete/gate height}\pgf@circ@res@down}}
            \pgftransformscale{\ctikzvalof{transistor solderdot scale}}
            \pgfnode{circ}{center}{}{}{}
        \endpgfscope{}
    \fi
    % ARROW
    \pgfscope
        \pgfslopedattimetrue
        \pgfallowupsidedownattimetrue
        \pgfresetnontranslationattimefalse
        \ifpgf@circuit@trans@arrowatend
            \edef\@@anchor{tip}\edef\@@pos{1.0}
        \else
            \edef\@@anchor{center}\edef\@@pos{0.6}
        \fi
        \pgftransformlineattime{\@@pos}{%
            \pgfpoint
            {\pgf@circ@res@right}%
            {\pgf@circ@res@up+\pgf@circ@res@down}%
            }{%
            \pgfpoint%
            {\ctikzvalof{tripoles/isfet/base width}\pgf@circ@res@left}%
            {\pgf@circ@res@up+\pgf@circ@res@down}%
        }
        \pgfnode{trarrow}{\@@anchor}{}{}{\pgfusepath{stroke}}
    \endpgfscope
    \pgfusepath{draw}

    % Wavy lines
    \pgfscope
        \pgfpathmoveto{\pgfpoint{-\ctikzvalof{tripoles/isfet/waves x sep}\pgf@circ@res@up}{\ctikzvalof{tripoles/isfet/waves y sep}\pgf@circ@res@up}}
        \pgfpathsine{\pgfpoint{-\ctikzvalof{tripoles/isfet/wave width}\pgf@circ@res@up}{-\ctikzvalof{tripoles/isfet/wave amp}\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{-\ctikzvalof{tripoles/isfet/wave width}\pgf@circ@res@up}{\ctikzvalof{tripoles/isfet/wave amp}\pgf@circ@res@up}}
        \pgfpathsine{\pgfpoint{-\ctikzvalof{tripoles/isfet/wave width}\pgf@circ@res@up}{\ctikzvalof{tripoles/isfet/wave amp}\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{-\ctikzvalof{tripoles/isfet/wave width}\pgf@circ@res@up}{-\ctikzvalof{tripoles/isfet/wave amp}\pgf@circ@res@up}}
        \pgfusepath{draw}

        \pgfpathmoveto{\pgfpoint{-\ctikzvalof{tripoles/isfet/waves x sep}\pgf@circ@res@up}{0cm}}
        \pgfpathsine{\pgfpoint{-\ctikzvalof{tripoles/isfet/wave width}\pgf@circ@res@up}{-\ctikzvalof{tripoles/isfet/wave amp}\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{-\ctikzvalof{tripoles/isfet/wave width}\pgf@circ@res@up}{\ctikzvalof{tripoles/isfet/wave amp}\pgf@circ@res@up}}
        \pgfpathsine{\pgfpoint{-\ctikzvalof{tripoles/isfet/wave width}\pgf@circ@res@up}{\ctikzvalof{tripoles/isfet/wave amp}\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{-\ctikzvalof{tripoles/isfet/wave width}\pgf@circ@res@up}{-\ctikzvalof{tripoles/isfet/wave amp}\pgf@circ@res@up}}
        \pgfusepath{draw}

        \pgfpathmoveto{\pgfpoint{-\ctikzvalof{tripoles/isfet/waves x sep}\pgf@circ@res@up}{-\ctikzvalof{tripoles/isfet/waves y sep}\pgf@circ@res@up}}
        \pgfpathsine{\pgfpoint{-\ctikzvalof{tripoles/isfet/wave width}\pgf@circ@res@up}{-\ctikzvalof{tripoles/isfet/wave amp}\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{-\ctikzvalof{tripoles/isfet/wave width}\pgf@circ@res@up}{\ctikzvalof{tripoles/isfet/wave amp}\pgf@circ@res@up}}
        \pgfpathsine{\pgfpoint{-\ctikzvalof{tripoles/isfet/wave width}\pgf@circ@res@up}{\ctikzvalof{tripoles/isfet/wave amp}\pgf@circ@res@up}}
        \pgfpathcosine{\pgfpoint{-\ctikzvalof{tripoles/isfet/wave width}\pgf@circ@res@up}{-\ctikzvalof{tripoles/isfet/wave amp}\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}

% end of transistors
% %>>>

%% Transistor's path definitions%<<<

\pgf@circ@definetranspath{nmos}
\pgf@circ@definetranspath{pmos}
\pgf@circ@definetranspath{nmosd}
\pgf@circ@definetranspath{pmosd}
\pgf@circ@definetranspath{hemt}
\pgf@circ@definetranspath{npn}
\pgf@circ@definetranspath{pnp}
\pgf@circ@definetranspath{nfet}
\pgf@circ@definetranspath{nigfete}
\pgf@circ@definetranspath{nigfetd}
\pgf@circ@definetranspath{nigfetebulk}
\pgf@circ@definetranspath{pfet}
\pgf@circ@definetranspath{pigfete}
\pgf@circ@definetranspath{pigfetd}
\pgf@circ@definetranspath{pigfetebulk}
\pgf@circ@definetranspath{njfet}
\pgf@circ@definetranspath{pjfet}
\pgf@circ@definetranspath{pigbt}
\pgf@circ@definetranspath{nigbt}
\pgf@circ@definetranspath{Lpigbt}
\pgf@circ@definetranspath{Lnigbt}% %>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Amplifiers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Settings for Amplifiers%<<<1
%
% switches for op amps
% changing input polarity
%
\newif\ifpgf@circuit@oa@iplusup\pgf@circuit@oa@iplusupfalse
\pgfkeys{/tikz/noinv input up/.add code={}{\pgf@circuit@oa@iplusuptrue}}
\ctikzset{noinv input up/.add code={}{\pgf@circuit@oa@iplusuptrue}}
\pgfkeys{/tikz/noinv input down/.add code={}{\pgf@circuit@oa@iplusupfalse}}
\ctikzset{noinv input down/.add code={}{\pgf@circuit@oa@iplusupfalse}}
%
% changing output polarity (for fully diff objects)
%
\newif\ifpgf@circuit@oa@oplusup\pgf@circuit@oa@oplusuptrue
\pgfkeys{/tikz/noinv output up/.add code={}{\pgf@circuit@oa@oplusuptrue}}
\ctikzset{noinv output up/.add code={}{\pgf@circuit@oa@oplusuptrue}}
\pgfkeys{/tikz/noinv output down/.add code={}{\pgf@circuit@oa@oplusupfalse}}
\ctikzset{noinv output down/.add code={}{\pgf@circuit@oa@oplusupfalse}}

% Operational amplifier
\ctikzset{tripoles/op amp/width/.initial=1.7}              % Total width
\ctikzset{tripoles/op amp/port width/.initial=.7}          % Terminals length
\ctikzset{tripoles/op amp/height/.initial=1.4}             % Total height
\ctikzset{tripoles/op amp/input height/.initial=.5}        % Input port vertical separation
\ctikzset{tripoles/op amp/up pos/.initial=.45}             % Top and bottom anchor position
\ctikzset{tripoles/op amp/font/.initial=\pgf@circ@font@tenbm}  % Absolute font size needed!

% Fully differential operational amplifier
\ctikzset{tripoles/fd op amp/width/.initial=1.7}           % Total width
\ctikzset{tripoles/fd op amp/port width/.initial=.7}       % Terminals length
\ctikzset{tripoles/fd op amp/height/.initial=1.4}          % Total height
\ctikzset{tripoles/fd op amp/input height/.initial=.5}     % Input port vertical separation
\ctikzset{tripoles/fd op amp/output height/.initial=.5}    % Output port vertical separation
\ctikzset{tripoles/fd op amp/up pos/.initial=.45}          % Top and bottom anchor position
\ctikzset{tripoles/fd op amp/font/.initial=\pgf@circ@font@tenbm}  % Absolute font size needed!

\ctikzset{tripoles/en amp/width/.initial=1.7}
\ctikzset{tripoles/en amp/port width/.initial=.7}
\ctikzset{tripoles/en amp/height/.initial=1.6}
\ctikzset{tripoles/en amp/input height/.initial=.3}
\ctikzset{tripoles/en amp/up pos/.initial=.45}
\ctikzset{tripoles/en amp/font/.initial=\pgf@circ@font@tenbm}   % Absolute font size needed!
\ctikzset{tripoles/en amp/font2/.initial=\pgf@circ@font@twelve}  % Absolute font size needed!
\ctikzset{tripoles/en amp/text/.initial={$\mathstrut{\triangleright}\,{\infty}$}}
\tikzset{
    en amp text/.code = {%
        \ctikzsetvalof{tripoles/en amp/text}{#1}%
    },
    en amp text A/.code = {%
        \ctikzsetvalof{tripoles/en amp/text}{$\mathstrut{\triangleright}\,\mathrm{A}$}%
    },
}

% Transconductance amplifier
\ctikzset{tripoles/gm amp/width/.initial=1.7}              % Total width
\ctikzset{tripoles/gm amp/port width/.initial=.7}          % Terminals length
\ctikzset{tripoles/gm amp/height/.initial=1.4}             % Left side of the trapezoid
\ctikzset{tripoles/gm amp/height 2/.initial=0.5}           % Right side of the trapezoid
\ctikzset{tripoles/gm amp/input height/.initial=.5}        % Input port vertical separation
\ctikzset{tripoles/gm amp/up pos/.initial=.45}             % Top and bottom anchor position
\ctikzset{tripoles/gm amp/font/.initial=\pgf@circ@font@tenbm}  % Absolute font size needed!

% Instrumentation amplifier
\ctikzset{tripoles/inst amp/width/.initial=1.7}            % Total width
\ctikzset{tripoles/inst amp/port width/.initial=.7}        % Terminals length
\ctikzset{tripoles/inst amp/height/.initial=1.4}           % Left side of the trapezoid
\ctikzset{tripoles/inst amp/height 2/.initial=0.6}         % Right side of the trapezoid
\ctikzset{tripoles/inst amp/input height/.initial=.5}      % Input ports vertical separation
\ctikzset{tripoles/inst amp/up pos/.initial=.4}            % Top and bottom anchor position
\ctikzset{tripoles/inst amp/refv pos/.initial=.7}          % Top and bottom voltage reference position
\ctikzset{tripoles/inst amp/font/.initial=\pgf@circ@font@tenbm}  % Absolute font size needed!

% Instrumentation amplifier with differential output
\ctikzset{tripoles/fd inst amp/width/.initial=1.7}         % Total width
\ctikzset{tripoles/fd inst amp/port width/.initial=.7}     % Terminals length
\ctikzset{tripoles/fd inst amp/height/.initial=1.4}        % Left side of the trapezoid
\ctikzset{tripoles/fd inst amp/height 2/.initial=0.6}      % Right side of the trapezoid
\ctikzset{tripoles/fd inst amp/input height/.initial=.5}   % Input ports vertical separation
\ctikzset{tripoles/fd inst amp/output height/.initial=.5}  % Output ports vertical separation
\ctikzset{tripoles/fd inst amp/up pos/.initial=.4}         % Top and bottom anchor position
\ctikzset{tripoles/fd inst amp/refv pos/.initial=.7}       % Top and bottom voltage reference position
\ctikzset{tripoles/fd inst amp/font/.initial=\pgf@circ@font@tenbm}  % Absolute font size needed!

% Instrumentation amplifier with gain resistor terminals
\ctikzset{tripoles/inst amp ra/width/.initial=2.4}         % Total width
\ctikzset{tripoles/inst amp ra/port width/.initial=.7}     % Terminals length
\ctikzset{tripoles/inst amp ra/height/.initial=2.9}        % Left side of the trapezoid
\ctikzset{tripoles/inst amp ra/height 2/.initial=0.4}      % Right side of the trapezoid
\ctikzset{tripoles/inst amp ra/input height/.initial=.7}   % Input ports vertical separation
\ctikzset{tripoles/inst amp ra/up pos/.initial=.4}         % Top and bottom anchor position
\ctikzset{tripoles/inst amp ra/refv pos/.initial=.7}       % Top and bottom voltage reference position
\ctikzset{tripoles/inst amp ra/ra pos/.initial=.6}         % Gain resistor terminals vertical separation
\ctikzset{tripoles/inst amp ra/font/.initial=\pgf@circ@font@tenbm}  % Absolute font size needed!

% Plain amplifier
\ctikzset{tripoles/plain amp/width/.initial=1.7}           % Total width
\ctikzset{tripoles/plain amp/port width/.initial=.7}       % Terminals length
\ctikzset{tripoles/plain amp/height/.initial=1.4}          % Total height
\ctikzset{tripoles/plain amp/input height/.initial=.5}     % Input ports vertical separation
\ctikzset{tripoles/plain amp/up pos/.initial=.45}          % Top and bottom anchor position

% changing fonts and symbols of amplifiers
\ctikzset{amplifiers/symbol font/.code={%
        \ctikzset{tripoles/inst amp ra/font=#1}%
        \ctikzset{tripoles/fd inst amp/font=#1}%
        \ctikzset{tripoles/inst amp/font=#1}%
        \ctikzset{tripoles/gm amp/font=#1}%
        \ctikzset{tripoles/en amp/font=#1}%
        \ctikzset{tripoles/fd op amp/font=#1}%
        \ctikzset{tripoles/op amp/font=#1}%
}}
\ctikzset{amplifiers/plus/.initial={$+$}}
% In the mayority of fonts, the size of - is smaller than +, so we have
% unaligned signs when positioned independently.
% See https://github.com/circuitikz/circuitikz/issues/721
\ctikzset{amplifiers/minus/.initial={$\vphantom{+}-$}}
\tikzset{amp symbol font/.code={%
        \ctikzset{amplifiers/symbol font={#1}}%
    }
}
\tikzset{amp plus/.code={\ctikzsetvalof{amplifiers/plus}{#1}}}
\tikzset{amp minus/.code={\ctikzsetvalof{amplifiers/minus}{#1}}}
\def\pgf@circ@ampli@plus{\ctikzvalof{amplifiers/plus}}
\def\pgf@circ@ampli@minus{\ctikzvalof{amplifiers/minus}}
%%>>>

%% Nodes for amplifiers%<<<
%% operational and instrumentation amplifiers

\pgfdeclareshape{op amp}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{amplifiers}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/op amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \savedanchor\left{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@y=0pt
    }
    \anchor{south}{
        \northwest
        \pgf@y=-\pgf@y
        \pgf@x=0pt
    }
    \anchor{north}{
        \northwest
        \pgf@x=0pt
    }
    \savedanchor\left{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@y=0pt
    }
    \savedanchor\inOneFixed{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/op amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/op amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{in up}{
        \inOneFixed
    }
    \anchor{in down}{
        \inOneFixed
        \pgf@y=-\pgf@y
    }
    \savedanchor\inOne{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/op amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/op amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    \ifpgf@circuit@oa@iplusup\pgf@y=-\pgf@y\fi
    }
    \anchor{-}{
        \inOne
    }
    \anchor{+}{
        \inOne
        \pgf@y=-\pgf@y
    }
    \savedanchor\up{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/op amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfpointlineattime{
            \ctikzvalof{tripoles/op amp/up pos}}{
            \pgfpoint{
            \ctikzvalof{tripoles/op amp/port width}\pgf@circ@res@left}
        {\pgf@circ@res@up}}
        {\pgfpoint{\ctikzvalof{tripoles/op amp/port width}\pgf@circ@res@right}{0pt}}
    }
    \anchor{up}{
        \up
    }
    \anchor{down}{
        \up
        \pgf@y=-\pgf@y
    }
    \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{west}{
        \left
    }
    \anchor{east}{
        \left
        \pgf@x=-\pgf@x
    }

    % support for border anchors
    \savedanchor\leftedge{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x = \ctikzvalof{tripoles/op amp/port width}\pgf@x
        \pgf@y=0pt
    }
    \anchor{leftedge}{\leftedge}
    \anchor{rightedge}{\leftedge \pgf@x =-\pgf@x }
    \anchor{bin up}{
        \inOneFixed
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bin down}{
        \inOneFixed
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b-}{
        \inOne
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b+}{
        \inOne
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bout}{
        \leftedge
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    % end border anchors
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northwest \pgf@x=-\pgf@x }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }

    \anchor{text}{
        \ifpgf@circ@center@text
            \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \else
            \leftedge
            \pgfmathsetlength{\pgf@x}{\pgf@x + \ctikzvalof{left text distance}}
        \fi
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }

    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@scaled@Rlen=\scaledRlen
				% Triangle
        \pgfscope
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgftransformxshift{\ctikzvalof{tripoles/op amp/port width}\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=\ctikzvalof{tripoles/op amp/port width}\pgf@circ@res@step
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope
				% Negative input terminal
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
            {\ctikzvalof{tripoles/op amp/input height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/op amp/port width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/op amp/input height}\pgf@circ@res@up}}
				% Positive input terminal
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
            {\ctikzvalof{tripoles/op amp/input height}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/op amp/port width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/op amp/input height}\pgf@circ@res@down}}
        % Output terminal
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/op amp/port width}\pgf@circ@res@right}{0pt}}
        \pgfsetrectcap
        \pgfusepath{draw}
        \pgf@circ@text@strokecolor
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/op amp/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/op amp/input height}\pgf@circ@res@up}]{\ctikzvalof{tripoles/op amp/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@plus\else\pgf@circ@ampli@minus\fi}
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/op amp/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/op amp/input height}\pgf@circ@res@down}]{\ctikzvalof{tripoles/op amp/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@minus\else\pgf@circ@ampli@plus\fi}
    }
}

% Op amp shape as in european standard EN 60617
\pgfdeclareshape{en amp}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{amplifiers}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/en amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/en amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \savedanchor\left{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/en amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@y=0pt
    }
    \anchor{south}{
        \northwest
        \pgf@y=-\pgf@y
        \pgf@x=0pt
    }
    \anchor{north}{
        \northwest
        \pgf@x=0pt
    }
    \savedanchor\inOneFixed{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/en amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/en amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/en amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{in up}{
        \inOneFixed
    }
    \anchor{in down}{
        \inOneFixed
        \pgf@y=-\pgf@y
    }
    \savedanchor\inOne{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/en amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/en amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/en amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    \ifpgf@circuit@oa@iplusup\pgf@y=-\pgf@y\fi
    }
    \anchor{-}{
        \inOne
    }
    \anchor{+}{
        \inOne
        \pgf@y=-\pgf@y
    }
    \anchor{up}{
        \northwest
        \pgf@x=0pt
    }
    \anchor{down}{
        \northwest
        \pgf@x=0pt
        \pgf@y=-\pgf@y
    }
    \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{west}{
        \left
    }
    \anchor{east}{
        \left
        \pgf@x=-\pgf@x
    }
    % support for border anchors
    \savedanchor\leftedge{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/en amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x = \ctikzvalof{tripoles/en amp/port width}\pgf@x
        \pgf@y=0pt
    }
    \anchor{leftedge}{\leftedge}
    \anchor{rightedge}{\leftedge \pgf@x =-\pgf@x }
    \anchor{bin up}{
        \inOneFixed
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bin down}{
        \inOneFixed
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b-}{
        \inOne
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b+}{
        \inOne
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bout}{
        \leftedge
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    % end border anchors
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northwest \pgf@x=-\pgf@x }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
    \anchor{text}{
        \ifpgf@circ@center@text
            \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \else
            \leftedge
            \pgfmathsetlength{\pgf@x}{\pgf@x + \ctikzvalof{left text distance}}
        \fi
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }

    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@scaled@Rlen=\scaledRlen

        \pgfscope
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/en amp/port width}\pgf@circ@res@left}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/en amp/port width}\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/en amp/port width}\pgf@circ@res@right}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/en amp/port width}\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope

        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
            {\ctikzvalof{tripoles/en amp/input height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/en amp/port width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/en amp/input height}\pgf@circ@res@up}}

        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
            {\ctikzvalof{tripoles/en amp/input height}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/en amp/port width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/en amp/input height}\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right}{0pt}}
        \pgfsetrectcap
        \pgfusepath{draw}
        \pgf@circ@text@strokecolor
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/en amp/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/en amp/input height}\pgf@circ@res@up}]{\ctikzvalof{tripoles/en amp/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@plus\else\pgf@circ@ampli@minus\fi}
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/en amp/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/en amp/input height}\pgf@circ@res@down}]{\ctikzvalof{tripoles/en amp/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@minus\else\pgf@circ@ampli@plus\fi}
        \pgftext[top, y=-.5ex, at=\pgfpoint{0pt}{\pgf@circ@res@up}]{\hbox{\ctikzvalof{tripoles/en amp/font2}\ctikzvalof{tripoles/en amp/text}}}
    }
}

% Fully differential output op amp
% Contributed by Kristofer M. Monisit
\pgfdeclareshape{fd op amp}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{amplifiers}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/fd op amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \savedanchor\outline{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/fd op amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    \ifpgf@circuit@oa@oplusup\else\pgf@y=-\pgf@y\fi
    }
    \anchor{south}{
        \northwest
        \pgf@y=-\pgf@y\pgf@x=0pt\relax
    }
    \anchor{north}{
        \northwest\pgf@x=0pt\relax
    }
    \savedanchor\left{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@y=0pt
    }
    \savedanchor\inOneFixed{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/fd op amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/fd op amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{in up}{
        \inOneFixed
    }
    \anchor{in down}{
        \inOneFixed
        \pgf@y=-\pgf@y
    }
    \savedanchor\inOne{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/fd op amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/fd op amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    \ifpgf@circuit@oa@iplusup\pgf@y=-\pgf@y\fi
    }
    \anchor{-}{
        \inOne
    }
    \anchor{+}{
        \inOne
        \pgf@y=-\pgf@y
    }
    \savedanchor\up{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/fd op amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfpointlineattime{
            \ctikzvalof{tripoles/fd op amp/up pos}}{
            \pgfpoint{
            \ctikzvalof{tripoles/fd op amp/port width}\pgf@circ@res@left}
        {\pgf@circ@res@up}}
        {\pgfpoint{\ctikzvalof{tripoles/fd op amp/port width}\pgf@circ@res@right}{0pt}}
    }
    \anchor{up}{
        \up
    }
    \anchor{down}{
        \up
        \pgf@y=-\pgf@y
    }
    \anchor{out up}{
        \northwest
        \pgf@y=\ctikzvalof{tripoles/fd op amp/output height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/port width}\pgf@x
    }
    \anchor{out down}{
        \northwest
        \pgf@y=-\ctikzvalof{tripoles/fd op amp/output height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/port width}\pgf@x
    }
    \anchor{out +}{
        \outline
        \pgf@y=\ctikzvalof{tripoles/fd op amp/output height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/port width}\pgf@x
    }
    \anchor{out -}{
        \outline
        \pgf@y=-\ctikzvalof{tripoles/fd op amp/output height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/port width}\pgf@x
    }
    % support for border anchors
    \savedanchor\leftedge{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x = \ctikzvalof{tripoles/fd op amp/port width}\pgf@x
        \pgf@y=0pt
    }
    \anchor{leftedge}{\leftedge}
    \anchor{rightedge}{\leftedge \pgf@x =-\pgf@x }
    \anchor{bin up}{
        \inOneFixed
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bin down}{
        \inOneFixed
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b-}{
        \inOne
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b+}{
        \inOne
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bout}{
        \leftedge
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{bout +}{
        \outline
        \pgf@xa=\pgf@x\pgf@ya=\pgf@y
        \pgfpointlineattime{\ctikzvalof{tripoles/fd op amp/output height}}
            {\pgfpoint{\pgf@xa}{0pt}}
            {\pgfpoint{0pt}{\pgf@ya}}
    }
    \anchor{bout -}{
        \outline
        \pgf@xa=\pgf@x\pgf@ya=\pgf@y
        \pgfpointlineattime{\ctikzvalof{tripoles/fd op amp/output height}}
            {\pgfpoint{\pgf@xa}{0pt}}
            {\pgfpoint{0pt}{\pgf@ya}}
        \pgf@y=-\pgf@y
    }
    \anchor{bout up}{
        \northwest
        \pgf@xa=\pgf@x\pgf@ya=\pgf@y
        \pgfpointlineattime{\ctikzvalof{tripoles/fd op amp/output height}}
            {\pgfpoint{\pgf@xa}{0pt}}
            {\pgfpoint{0pt}{\pgf@ya}}
    }
    \anchor{bout down}{
        \northwest
        \pgf@xa=\pgf@x\pgf@ya=\pgf@y
        \pgfpointlineattime{\ctikzvalof{tripoles/fd op amp/output height}}
            {\pgfpoint{\pgf@xa}{0pt}}
            {\pgfpoint{0pt}{\pgf@ya}}
        \pgf@y=-\pgf@y
    }
    % end border anchors
    \anchor{west}{
        \left
    }
    \anchor{east}{
        \left
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/port width}\pgf@x
    }
    \anchor{out}{% should not be used
        \left
        \pgf@x=-\ctikzvalof{tripoles/fd op amp/port width}\pgf@x
    }
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northwest \pgf@x=-\ctikzvalof{tripoles/fd op amp/port width}\pgf@x }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northwest \pgf@x=-\ctikzvalof{tripoles/fd op amp/port width}\pgf@x \pgf@y=-\pgf@y }
    \anchor{text}{
        \ifpgf@circ@center@text
            \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \else
            \leftedge
            \pgfmathsetlength{\pgf@x}{\pgf@x + \ctikzvalof{left text distance}}
        \fi
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor

        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@scaled@Rlen=\scaledRlen

        % Triangle
        % Includes output terminals in the traingular shape
        % to ensure that diagonal joins are properly displayed
        % we first draw the main triangle and the leads with normal thickness,
        % and the redraw the main triangle with the component shape
        \pgfscope
            % shift origin a bit to ease calculations
            \pgftransformxshift{\ctikzvalof{tripoles/fd op amp/port width}\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=\ctikzvalof{tripoles/fd op amp/port width}\pgf@circ@res@step

            % Initial point (right vertex)
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}

            % Negative output terminal
            \pgfpathlineto{\pgfpointlineattime{\ctikzvalof{tripoles/fd op amp/output height}}{\pgfpoint{\pgf@circ@res@step}{0pt}}{\pgfpoint{0pt}{\pgf@circ@res@up}}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{\ctikzvalof{tripoles/fd op amp/output height}\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpointlineattime{\ctikzvalof{tripoles/fd op amp/output height}}{\pgfpoint{\pgf@circ@res@step}{0pt}}{\pgfpoint{0pt}{\pgf@circ@res@up}}}

            % Top vertex
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}

            % Bottom vertex
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}

            % Positive output terminal
            \pgfpathlineto{\pgfpointlineattime{\ctikzvalof{tripoles/fd op amp/output height}}{\pgfpoint{\pgf@circ@res@step}{0pt}}{\pgfpoint{0pt}{\pgf@circ@res@down}}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{\ctikzvalof{tripoles/fd op amp/output height}\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpointlineattime{\ctikzvalof{tripoles/fd op amp/output height}}{\pgfpoint{\pgf@circ@res@step}{0pt}}{\pgfpoint{0pt}{\pgf@circ@res@down}}}

            % Right vertex
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{0pt}}

            \pgfpathclose
            \pgfusepath{stroke}

            % ok, now we'll redraw the triangle with the class specific
            % thickness and optionally fill

            \pgfscope
                \pgf@circ@setlinewidth{quadpoles}{\pgflinewidth}

                % Initial point (right vertex)
                \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
                % Top vertex
                \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
                % Bottom vertex
                \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}

                \pgfpathclose
                \pgf@circ@draworfill
            \endpgfscope % thick and fill
        \endpgfscope % shift

        % Negative input terminal
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
            {\ctikzvalof{tripoles/fd op amp/input height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/fd op amp/port width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/fd op amp/input height}\pgf@circ@res@up}}

        % Positive input terminal
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
            {\ctikzvalof{tripoles/fd op amp/input height}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/fd op amp/port width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/fd op amp/input height}\pgf@circ@res@down}}
        \pgfsetrectcap
        \pgfusepath{draw}
        \pgf@circ@text@strokecolor
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/fd op amp/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/fd op amp/input height}\pgf@circ@res@up}]{\ctikzvalof{tripoles/fd op amp/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@plus\else\pgf@circ@ampli@minus\fi}
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/fd op amp/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/fd op amp/input height}\pgf@circ@res@down}]{\ctikzvalof{tripoles/fd op amp/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@minus\else\pgf@circ@ampli@plus\fi}
        % Negative output terminal label
        \pgftext[right, bottom, x=3pt, y=1pt, at=\pgfpoint{0pt}{0.425\pgf@circ@res@down}]{\ctikzvalof{tripoles/fd op amp/font} \ifpgf@circuit@oa@oplusup\pgf@circ@ampli@minus\else\pgf@circ@ampli@plus\fi}
        % Positive output terminal label
        \pgftext[right, top, x=3pt, y=-1pt, at=\pgfpoint{0pt}{0.425\pgf@circ@res@up}]{\ctikzvalof{tripoles/fd op amp/font} \ifpgf@circuit@oa@oplusup\pgf@circ@ampli@plus\else\pgf@circ@ampli@minus\fi}
    }
}


% Instrumentation amplifier with differential output
\pgfdeclareshape{fd inst amp}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{amplifiers}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    % when tikz calls the anchor it wants the relative position in the lengths
    % \pgf@x  \pgf@y
    % \pgfpoint* functions set that variables
    % anchors are visible outside and run on use
    \anchor{center}{\pgfpointorigin}
    % savedanchors are internals and run on node creation (not use)
    % bounding-box top left
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/fd inst amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd inst amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{nw}{
        \northwest
    }
    \anchor{south}{
        \northwest
        \pgf@y=-\pgf@y\pgf@x=0pt\relax
    }
    \anchor{north}{
        \northwest\pgf@x=0pt\relax
    }
    \savedanchor\left{%
        \pgf@y=0pt
    }
    \anchor{leftedge}
    {\left
        \pgf@x = \ctikzvalof{tripoles/fd inst amp/port width}\pgf@x
    }
    \savedanchor\inOneFixed{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
          \pgf@y=\ctikzvalof{tripoles/fd inst amp/height}\pgf@circ@scaled@Rlen
          \pgf@y=.5\pgf@y
          \pgf@y=\ctikzvalof{tripoles/fd inst amp/input height}\pgf@y
          \pgf@x=-\ctikzvalof{tripoles/fd inst amp/width}\pgf@circ@scaled@Rlen
          \pgf@x=.5\pgf@x
    }
    \anchor{in up}{
        \inOneFixed
    }
    \anchor{in down}{
        \inOneFixed
        \pgf@y=-\pgf@y
    }
    \savedanchor\inOne{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/fd inst amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/fd inst amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd inst amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \ifpgf@circuit@oa@iplusup\pgf@y=-\pgf@y\fi
    }
    \anchor{-}{
        \inOne
    }
    \anchor{+}{
        \inOne
        \pgf@y=-\pgf@y
    }
    \savedanchor\up{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/fd inst amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd inst amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfpointlineattime{
            \ctikzvalof{tripoles/fd inst amp/up pos}}{
            \pgfpoint{
            \ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@left}
        {\pgf@circ@res@up}}
        {\pgfpoint{\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@right}{\ctikzvalof{tripoles/fd inst amp/height 2}\pgf@circ@res@up}}
    }
    \anchor{up}{
        \up
    }
    \anchor{down}{
        \up
        \pgf@y=-\pgf@y
    }
    % reference voltage input anchors.
    \savedanchor\refv{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/fd inst amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd inst amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfpointlineattime{
            \ctikzvalof{tripoles/fd inst amp/refv pos}}{
            \pgfpoint{
            \ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@left}
        {\pgf@circ@res@up}}
        {\pgfpoint{\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@right}{\ctikzvalof{tripoles/fd inst amp/height 2}\pgf@circ@res@up}}
    }
    % we need both because they are normally drawn under the amp, and if you
    % mirror it vertically you need them
    \anchor{refv up}{
        \refv
    }
    \anchor{refv down}{
        \refv
        \pgf@y=-\pgf@y
    }
    \savedanchor\outport{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/fd inst amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/fd inst amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd inst amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=-.5\pgf@x
        \ifpgf@circuit@oa@oplusup\else\pgf@y=-\pgf@y\fi
    }
    \anchor{out}{
        \outport
        \pgf@y=0pt
    }
    \anchor{out +}{
        \outport
    }
    \anchor{out -}{
        \outport
        \pgf@y=-\pgf@y
    }
    \savedanchor\outportfixed{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/fd inst amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/fd inst amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/fd inst amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=-.5\pgf@x
    }
    \anchor{out up}{
        \outportfixed
    }
    \anchor{out down}{
        \outportfixed
        \pgf@y=-\pgf@y
    }
    % support for border anchors
    \savedanchor\leftedge{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/fd inst amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x = \ctikzvalof{tripoles/fd inst amp/port width}\pgf@x
        \pgf@y=0pt
    }
    \anchor{leftedge}{\leftedge}
    \anchor{rightedge}{\leftedge \pgf@x =-\pgf@x }
    \anchor{bin up}{
        \inOneFixed
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bin down}{
        \inOneFixed
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b-}{
        \inOne
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b+}{
        \inOne
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bout}{
        \leftedge
        \pgf@x=-\pgf@x \pgf@y=0pt
    }
    \anchor{bout +}{
        \outport
        \pgf@ya=\pgf@y \leftedge \pgf@x=-\pgf@x \pgf@y=\pgf@ya
    }
    \anchor{bout -}{
        \outport
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@x=-\pgf@x \pgf@y=\pgf@ya
    }
    \anchor{bout up}{
        \outportfixed
        \pgf@ya=\pgf@y \leftedge \pgf@x=-\pgf@x \pgf@y=\pgf@ya
    }
    \anchor{bout down}{
        \outportfixed
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@x=-\pgf@x \pgf@y=\pgf@ya
    }
    % end border anchors
    %
    \anchor{west}{
        \left
    }
    \anchor{east}{
        \left
        \pgf@x=-\pgf@x
    }
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northwest \pgf@x=-\pgf@x }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
    \anchor{text}{
        \ifpgf@circ@center@text
            \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \else
            \leftedge
            \pgfmathsetlength{\pgf@x}{\pgf@x + \ctikzvalof{left text distance}}
        \fi
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }

    % let's start drawing the component
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        %
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@scaled@Rlen=\scaledRlen
        % main component, normally in thicker lines
        \pgfscope
            \newdimen\pgf@circ@res@right@double
            \pgf@circ@res@right@double=2\pgf@circ@res@right
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgftransformxshift{\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@step
            %first point (near output)
            \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@right@double}{0}}
            %from the exit to the top (short side)... (note that the .6 must be copied in \up and \refv anchors
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@right@double}{\ctikzvalof{tripoles/fd inst amp/height 2}\pgf@circ@res@up}}
            % and then to the input "front up", "down", to the output short side "down"
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@right@double}{\ctikzvalof{tripoles/fd inst amp/height 2}\pgf@circ@res@down}}
            % ...and close
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope

        % input terminal up
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
        {\ctikzvalof{tripoles/fd inst amp/input height}\pgf@circ@res@up}}
        %
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/fd inst amp/input height}\pgf@circ@res@up}}
        %

        % input terminal down
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
        {\ctikzvalof{tripoles/fd inst amp/input height}\pgf@circ@res@down}}
        %
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/fd inst amp/input height}\pgf@circ@res@down}}

        % output leads down and up
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\ctikzvalof{tripoles/fd inst amp/output height}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@right}{\ctikzvalof{tripoles/fd inst amp/output height}\pgf@circ@res@down}} %

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\ctikzvalof{tripoles/fd inst amp/output height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@right}{\ctikzvalof{tripoles/fd inst amp/output height}\pgf@circ@res@up}} %
        %
        \pgfsetrectcap
        \pgfusepath{draw}
        \pgf@circ@text@strokecolor
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/fd inst amp/input height}\pgf@circ@res@up}]{\ctikzvalof{tripoles/fd inst amp/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@plus\else\pgf@circ@ampli@minus\fi}
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/fd inst amp/input height}\pgf@circ@res@down}]{\ctikzvalof{tripoles/fd inst amp/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@minus\else\pgf@circ@ampli@plus\fi}
        \pgftext[right, at=\pgfpoint{\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@right}{\ctikzvalof{tripoles/fd inst amp/output height}\pgf@circ@res@down}]{\ctikzvalof{tripoles/fd inst amp/font}\ifpgf@circuit@oa@oplusup\pgf@circ@ampli@minus\space\else\pgf@circ@ampli@plus\space\fi}
        \pgftext[right, at=\pgfpoint{\ctikzvalof{tripoles/fd inst amp/port width}\pgf@circ@res@right}{\ctikzvalof{tripoles/fd inst amp/output height}\pgf@circ@res@up}]{\ctikzvalof{tripoles/fd inst amp/font}\ifpgf@circuit@oa@oplusup\pgf@circ@ampli@plus\space\else\pgf@circ@ampli@minus\space\fi}
    }
}

% Transconductance amplifier (Transkonduktanzverstärker)
\pgfdeclareshape{gm amp}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{amplifiers}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/gm amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/gm amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{south}{
        \northwest
        \pgf@y=-\pgf@y
    }
    \anchor{north}{
        \northwest
    }
    \savedanchor\left{%
        \pgf@y=0pt
    }
    \anchor{leftedge}
    {\left
        \pgf@x = \ctikzvalof{tripoles/op amp/port width}\pgf@x
    }
    \savedanchor\inOneFixed{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/gm amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/gm amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/gm amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{in up}{
        \inOneFixed
    }
    \anchor{in down}{
        \inOneFixed
        \pgf@y=-\pgf@y
    }
    \savedanchor\inOne{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/gm amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/gm amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/gm amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \ifpgf@circuit@oa@iplusup\pgf@y=-\pgf@y\fi
    }
    \anchor{-}{
        \inOne
    }
    \anchor{+}{
        \inOne
        \pgf@y=-\pgf@y
    }
        \savedanchor\up{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/gm amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/gm amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfpointlineattime{
            \ctikzvalof{tripoles/gm amp/up pos}}{
            \pgfpoint{
            \ctikzvalof{tripoles/gm amp/port width}\pgf@circ@res@left}
        {\pgf@circ@res@up}}
        {\pgfpoint{\ctikzvalof{tripoles/gm amp/port width}\pgf@circ@res@right}{\ctikzvalof{tripoles/gm amp/height 2}\pgf@circ@res@up}}
    }
    \anchor{up}{
        \up
    }
    \anchor{down}{
        \up
        \pgf@y=-\pgf@y
    }
    \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    % support for border anchors
    \savedanchor\leftedge{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/gm amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x = \ctikzvalof{tripoles/gm amp/port width}\pgf@x
        \pgf@y=0pt
    }
    \anchor{leftedge}{\leftedge}
    \anchor{rightedge}{\leftedge \pgf@x =-\pgf@x }
    \anchor{bin up}{
        \inOneFixed
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bin down}{
        \inOneFixed
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b-}{
        \inOne
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b+}{
        \inOne
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bout}{
        \leftedge
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    % end border anchors
    \anchor{west}{
        \left
    }
    \anchor{east}{
        \left
        \pgf@x=-\pgf@x
    }
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northwest \pgf@x=-\pgf@x }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }

    \anchor{text}{
        \ifpgf@circ@center@text
            \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \else
            \leftedge
            \pgfmathsetlength{\pgf@x}{\pgf@x + \ctikzvalof{left text distance}}
        \fi
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor

        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@scaled@Rlen=\scaledRlen

        \pgfscope
            \newdimen\pgf@circ@res@right@double
						\pgf@circ@res@right@double=2\pgf@circ@res@right

            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgftransformxshift{\ctikzvalof{tripoles/gm amp/port width}\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=\ctikzvalof{tripoles/gm amp/port width}\pgf@circ@res@step
            %Umrandung:
            \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/gm amp/port width}\pgf@circ@res@right@double}{0}} %geändert startpunkt neu am ausgangsstrich
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/gm amp/port width}\pgf@circ@res@right@double}{\ctikzvalof{tripoles/gm amp/height 2}\pgf@circ@res@up}}%vom Ausgang nach oben
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}} %neu ecke links oben nach rechts oben
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}} %bei deneigängen runter
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/gm amp/port width}\pgf@circ@res@right@double}{\ctikzvalof{tripoles/gm amp/height 2}\pgf@circ@res@down}}%ecke links unten nach rechts unten
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope

        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
            {\ctikzvalof{tripoles/gm amp/input height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/gm amp/port width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/gm amp/input height}\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
            {\ctikzvalof{tripoles/gm amp/input height}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/gm amp/port width}\pgf@circ@res@left}
            {\ctikzvalof{tripoles/gm amp/input height}\pgf@circ@res@down}}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/gm amp/port width}\pgf@circ@res@right}{0pt}} %
        \pgfsetrectcap
        \pgfusepath{draw}
        \pgf@circ@text@strokecolor
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/gm amp/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/gm amp/input height}\pgf@circ@res@up}]{\ctikzvalof{tripoles/gm amp/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@plus\else\pgf@circ@ampli@minus\fi}
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/gm amp/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/gm amp/input height}\pgf@circ@res@down}]{\ctikzvalof{tripoles/gm amp/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@minus\else\pgf@circ@ampli@plus\fi}
    }
}

% Instrumentation amplifier
\pgfdeclareshape{inst amp}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{amplifiers}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    % when tikz calls the anchor it wants the relative position in the lengths
    % \pgf@x  \pgf@y
    % \pgfpoint* functions set that variables
    % anchors are visible outside and run on use
    \anchor{center}{\pgfpointorigin}
    % savedanchors are internals and run on node creation (not use)
    % bounding-box top left
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/inst amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/inst amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{nw}{
        \northwest
    }
    \anchor{south}{
        \northwest
        \pgf@y=-\pgf@y
    }
    \anchor{north}{
        \northwest
    }
    \savedanchor\left{%
        \pgf@y=0pt
    }
    \anchor{leftedge}
    {\left
        \pgf@x = \ctikzvalof{tripoles/op amp/port width}\pgf@x
    }
    \savedanchor\inOneFixed{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
          \pgf@y=\ctikzvalof{tripoles/inst amp/height}\pgf@circ@scaled@Rlen
          \pgf@y=.5\pgf@y
          \pgf@y=\ctikzvalof{tripoles/inst amp/input height}\pgf@y
          \pgf@x=-\ctikzvalof{tripoles/inst amp/width}\pgf@circ@scaled@Rlen
          \pgf@x=.5\pgf@x
    }
    \anchor{in up}{
        \inOneFixed
    }
    \anchor{in down}{
        \inOneFixed
        \pgf@y=-\pgf@y
    }
    \savedanchor\inOne{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/inst amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/inst amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/inst amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \ifpgf@circuit@oa@iplusup\pgf@y=-\pgf@y\fi
    }
    \anchor{-}{
        \inOne
    }
    \anchor{+}{
        \inOne
        \pgf@y=-\pgf@y
    }
    \savedanchor\up{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/inst amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/inst amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfpointlineattime{
            \ctikzvalof{tripoles/inst amp/up pos}}{
            \pgfpoint{
            \ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@left}
        {\pgf@circ@res@up}}
        {\pgfpoint{\ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@right}{\ctikzvalof{tripoles/inst amp/height 2}\pgf@circ@res@up}}
    }
    \anchor{up}{
        \up
    }
    \anchor{down}{
        \up
        \pgf@y=-\pgf@y
    }
    % reference voltage input anchors.
    \savedanchor\refv{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/inst amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/inst amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfpointlineattime{
            \ctikzvalof{tripoles/inst amp/refv pos}}{
            \pgfpoint{
            \ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@left}
        {\pgf@circ@res@up}}
        {\pgfpoint{\ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@right}{\ctikzvalof{tripoles/inst amp/height 2}\pgf@circ@res@up}}
    }
    % we need both because they are normally drawn under the amp, and if you
    % mirror it vertically you need them
    \anchor{refv up}{
        \refv
    }
    \anchor{refv down}{
        \refv
        \pgf@y=-\pgf@y
    }
    \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    % support for border anchors
    \savedanchor\leftedge{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/inst amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x = \ctikzvalof{tripoles/inst amp/port width}\pgf@x
        \pgf@y=0pt
    }
    \anchor{leftedge}{\leftedge}
    \anchor{rightedge}{\leftedge \pgf@x =-\pgf@x }
    \anchor{bin up}{
        \inOneFixed
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bin down}{
        \inOneFixed
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b-}{
        \inOne
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b+}{
        \inOne
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bout}{
        \leftedge
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    % end border anchors
    \anchor{west}{
        \left
    }
    \anchor{east}{
        \left
        \pgf@x=-\pgf@x
    }
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northwest \pgf@x=-\pgf@x }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }

    \anchor{text}{
        \ifpgf@circ@center@text
            \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \else
            \leftedge
            \pgfmathsetlength{\pgf@x}{\pgf@x + \ctikzvalof{left text distance}}
        \fi
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }

    % let's start drawing the component
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        %
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@scaled@Rlen=\scaledRlen

        % main component, normally in thicker lines
        \pgfscope
            \newdimen\pgf@circ@res@right@double
						\pgf@circ@res@right@double=2\pgf@circ@res@right

            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgftransformxshift{\ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=\ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@step
            %first point (near output)
            \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@right@double}{0}}
            %from the exit to the top (short side)... (note that the .6 must be copied in \up and \refv anchors
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@right@double}{\ctikzvalof{tripoles/inst amp/height 2}\pgf@circ@res@up}}
            % and then to the input "front up", "down", to the output short side "down"
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@right@double}{\ctikzvalof{tripoles/inst amp/height 2}\pgf@circ@res@down}}
            % ...and close
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope

        % Negative input terminal
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
        {\ctikzvalof{tripoles/inst amp/input height}\pgf@circ@res@up}}
        %
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/inst amp/input height}\pgf@circ@res@up}}
        %

        % Positive input terminal
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
        {\ctikzvalof{tripoles/inst amp/input height}\pgf@circ@res@down}}
        %
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/inst amp/input height}\pgf@circ@res@down}}

        % Output terminal
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@right}{0pt}} %
        %
        \pgfsetrectcap
        \pgfusepath{draw}
        \pgf@circ@text@strokecolor
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/inst amp/input height}\pgf@circ@res@up}]{\ctikzvalof{tripoles/inst amp/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@plus\else\pgf@circ@ampli@minus\fi}
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/inst amp/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/inst amp/input height}\pgf@circ@res@down}]{\ctikzvalof{tripoles/inst amp/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@minus\else\pgf@circ@ampli@plus\fi}
    }
}

% Instrumentation amplifier with terminals for gain resistance between inputs
\pgfdeclareshape{inst amp ra}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{amplifiers}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    % bounding-box top left
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/inst amp ra/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/inst amp ra/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{nw}{
        \northwest
    }
    \anchor{south}{
        \northwest
        \pgf@y=-\pgf@y\pgf@x=0pt\relax
    }
    \anchor{north}{
        \northwest\pgf@x=0pt\relax
    }
    \savedanchor\left{%
        \pgf@y=0pt
    }
    \anchor{leftedge}
    {\left
        \pgf@x = \ctikzvalof{tripoles/op amp/port width}\pgf@x
    }
    % inputs (+-)
    \savedanchor\inOneFixed{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
          \pgf@y=\ctikzvalof{tripoles/inst amp ra/height}\pgf@circ@scaled@Rlen
          \pgf@y=.5\pgf@y
          \pgf@y=\ctikzvalof{tripoles/inst amp ra/input height}\pgf@y
          \pgf@x=-\ctikzvalof{tripoles/inst amp ra/width}\pgf@circ@scaled@Rlen
          \pgf@x=.5\pgf@x
    }
    \anchor{in up}{
        \inOneFixed
    }
    \anchor{in down}{
        \inOneFixed
        \pgf@y=-\pgf@y
    }
    \savedanchor\inOne{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/inst amp ra/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/inst amp ra/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/inst amp ra/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \ifpgf@circuit@oa@iplusup\pgf@y=-\pgf@y\fi
    }
    \anchor{-}{
        \inOne
    }
    \anchor{+}{
        \inOne
        \pgf@y=-\pgf@y
    }
    % R ampli anchors. They are by default at 20% more than R-length distance
    % you can change that with the `ra pos` key (use 0.5 for one-R).
    \savedanchor\raOneFixed{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\pgf@circ@scaled@Rlen
        \pgf@y=\ctikzvalof{tripoles/inst amp ra/ra pos}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/inst amp ra/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{ra up}{
        \raOneFixed
    }
    \anchor{ra down}{
        \raOneFixed
        \pgf@y=-\pgf@y
    }
    \savedanchor\raOne{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\pgf@circ@scaled@Rlen
        \pgf@y=\ctikzvalof{tripoles/inst amp ra/ra pos}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/inst amp ra/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \ifpgf@circuit@oa@iplusup\pgf@y=-\pgf@y\fi
    }
    \anchor{ra-}{
        \raOne
    }
    \anchor{ra+}{
        \raOne
        \pgf@y=-\pgf@y
    }
    % power supplies
    \savedanchor\up{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/inst amp ra/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/inst amp ra/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfpointlineattime{
            \ctikzvalof{tripoles/inst amp ra/up pos}}{
            \pgfpoint{
            \ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@left}
        {\pgf@circ@res@up}}
        {\pgfpoint{\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@right}{\ctikzvalof{tripoles/inst amp ra/height 2}\pgf@circ@res@up}}
    }
    \anchor{up}{
        \up
    }
    \anchor{down}{
        \up
        \pgf@y=-\pgf@y
    }
    % reference voltage input anchors.
    \savedanchor\refv{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/inst amp ra/height}\pgf@circ@scaled@Rlen
        \pgf@y=0.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/inst amp ra/width}\pgf@circ@scaled@Rlen
        \pgf@x=0.5\pgf@x
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfpointlineattime{
            \ctikzvalof{tripoles/inst amp ra/refv pos}}{
            \pgfpoint{
            \ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@left}
        {\pgf@circ@res@up}}
        {\pgfpoint{\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@right}{\ctikzvalof{tripoles/inst amp ra/height 2}\pgf@circ@res@up}}
    }
    % we need both because they are normally drawn under the amp, and if you
    % mirror it vertically you need them
    \anchor{refv up}{
        \refv
    }
    \anchor{refv down}{
        \refv
        \pgf@y=-\pgf@y
    }
    \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    % support for border anchors
    \savedanchor\leftedge{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/inst amp ra/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x = \ctikzvalof{tripoles/inst amp ra/port width}\pgf@x
        \pgf@y=0pt
    }
    \anchor{leftedge}{\leftedge}
    \anchor{rightedge}{\leftedge \pgf@x =-\pgf@x }
    \anchor{bin up}{
        \inOneFixed
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bin down}{
        \inOneFixed
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b-}{
        \inOne
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b+}{
        \inOne
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bra up}{
        \raOneFixed
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bra down}{
        \raOneFixed
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bra-}{
        \raOne
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bra+}{
        \raOne
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bout}{
        \leftedge
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    % end border anchors
    \anchor{west}{
        \left
    }
    \anchor{east}{
        \left
        \pgf@x=-\pgf@x
    }
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northwest \pgf@x=-\pgf@x }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }

    \anchor{text}{
        \ifpgf@circ@center@text
            \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \else
            \leftedge
            \pgfmathsetlength{\pgf@x}{\pgf@x + \ctikzvalof{left text distance}}
        \fi
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }

    % drawing of the component
    \pgf@circ@draw@component{
        \pgf@circ@setcolor

        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@scaled@Rlen=\scaledRlen

        \newdimen\pgf@circ@res@right@double
				\pgf@circ@res@right@double=2\pgf@circ@res@right

        % main component, normally in thicker lines
        \pgfscope
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgftransformxshift{\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@step
            %primer punto: la linea de salida (lado componente)
            \pgfpathmoveto{\pgfpoint{\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@right@double}{0}}
            %from the exit to the top (short side)... (note that the .6 must be copied in \up anchor
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@right@double}{\ctikzvalof{tripoles/inst amp ra/height 2}\pgf@circ@res@up}}
            % and then to the input "front up", "down", to the output short side "down"
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@right@double}{\ctikzvalof{tripoles/inst amp ra/height 2}\pgf@circ@res@down}}
            % ...and close
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope

        % ra terminal -
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
        {\ctikzvalof{tripoles/inst amp ra/ra pos}\pgf@circ@scaled@Rlen}}
        %
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/inst amp ra/ra pos}\pgf@circ@scaled@Rlen}}
        % ra terminal +
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
        {-\ctikzvalof{tripoles/inst amp ra/ra pos}\pgf@circ@scaled@Rlen}}
        %
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@left}
        {-\ctikzvalof{tripoles/inst amp ra/ra pos}\pgf@circ@scaled@Rlen}}

        % Negative input terminal
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
        {\ctikzvalof{tripoles/inst amp ra/input height}\pgf@circ@res@up}}
        %
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/inst amp ra/input height}\pgf@circ@res@up}}
        %

        % Positive input terminal
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
        {\ctikzvalof{tripoles/inst amp ra/input height}\pgf@circ@res@down}}
        %
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/inst amp ra/input height}\pgf@circ@res@down}}

        % Output terminal
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@right}{0pt}} %
        %
        \pgfsetrectcap
        \pgfusepath{draw}
        \pgf@circ@text@strokecolor
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/inst amp ra/input height}\pgf@circ@res@up}]{\ctikzvalof{tripoles/inst amp ra/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@plus\else\pgf@circ@ampli@minus\fi}
        \pgftext[left, at=\pgfpoint{\ctikzvalof{tripoles/inst amp ra/port width}\pgf@circ@res@left}{\ctikzvalof{tripoles/inst amp ra/input height}\pgf@circ@res@down}]{\ctikzvalof{tripoles/inst amp ra/font} \ifpgf@circuit@oa@iplusup\pgf@circ@ampli@minus\else\pgf@circ@ampli@plus\fi}
    }
}

% Buffer
% Contributed by Danilo Piazzalunga
\pgfdeclareshape{buffer}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{amplifiers}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{bipoles/buffer/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{bipoles/buffer/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{east}{ \northwest \pgf@y=0pt \pgf@x=-\pgf@x  }
    \anchor{west}{ \northwest \pgf@y=0pt }
    \anchor{south}{ \northwest \pgf@x=0pt \pgf@y=-\pgf@y }
    \anchor{north}{ \northwest \pgf@x=0pt }
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northwest \pgf@x=-\pgf@x }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
    \savedanchor\left{%
        \pgf@y=0pt
    }
    \anchor{in}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{bin}{
        \northwest
        \pgf@y=0pt
        \pgf@x=0.7\pgf@x
    }
    \anchor{bout}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-0.7\pgf@x
    }

    \anchor{text}{
        \ifpgf@circ@center@text
            \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \else
            \northwest
            \pgfmathsetlength{\pgf@x}{0.7*\pgf@x + \ctikzvalof{left text distance}}
        \fi
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }

    \pgf@circ@draw@component{
        \pgf@circ@setcolor

        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgfscope
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgftransformxshift{.7\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=.7\pgf@circ@res@step

            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@left}{0pt}}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{.7\pgf@circ@res@right}{0pt}}

        \pgfusepath{draw}
    }
}

% plain amplifier, no symbols
\pgfdeclareshape{plain amp}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{amplifiers}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/plain amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/plain amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{east}{ \northwest \pgf@y=0pt \pgf@x=-\pgf@x  }
    \anchor{west}{ \northwest \pgf@y=0pt }
    \anchor{south}{ \northwest \pgf@x=0pt \pgf@y=-\pgf@y }
    \anchor{north}{ \northwest \pgf@x=0pt }
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northwest \pgf@x=-\pgf@x }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
    \savedanchor\left{%
        \pgf@y=0pt
    }
    \savedanchor\inOne{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/plain amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/plain amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/plain amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \ifpgf@circuit@oa@iplusup\pgf@y=-\pgf@y\fi
    }
    \savedanchor\inOneFixed{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/plain amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@y=\ctikzvalof{tripoles/plain amp/input height}\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/plain amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{-}{
        \inOne
    }
    \anchor{+}{
        \inOne
        \pgf@y=-\pgf@y
    }
    \anchor{in up}{
        \inOneFixed
    }
    \anchor{in down}{
        \inOneFixed
        \pgf@y=-\pgf@y
    }
    % support for border anchors
    \savedanchor\leftedge{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/plain amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x = \ctikzvalof{tripoles/plain amp/port width}\pgf@x
        \pgf@y=0pt
    }
    \anchor{leftedge}{\leftedge}
    \anchor{rightedge}{\leftedge \pgf@x =-\pgf@x }
    \anchor{bin up}{
        \inOneFixed
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bin down}{
        \inOneFixed
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b-}{
        \inOne
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{b+}{
        \inOne
        \pgf@y=-\pgf@y
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bout}{
        \leftedge
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    % end border anchors
    \savedanchor\up{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/plain amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/plain amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfpointlineattime{
            \ctikzvalof{tripoles/plain amp/up pos}}{
            \pgfpoint{
            \ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@left}
        {\pgf@circ@res@up}}
        {\pgfpoint{\ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@right}{0pt}}
    }
    \anchor{up}{
        \up
    }
    \anchor{down}{
        \up
        \pgf@y=-\pgf@y
    }
    \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }

    \anchor{text}{
        \ifpgf@circ@center@text
            \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \else
            \leftedge
            \pgfmathsetlength{\pgf@x}{\pgf@x + \ctikzvalof{left text distance}}
        \fi
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }

    \pgf@circ@draw@component{
        \pgf@circ@setcolor

        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x

        \pgfscope
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgftransformxshift{\ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=\ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@step

            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
        {\ctikzvalof{tripoles/plain amp/input height}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/plain amp/input height}\pgf@circ@res@up}}


        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
        {\ctikzvalof{tripoles/plain amp/input height}\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@left}
        {\ctikzvalof{tripoles/plain amp/input height}\pgf@circ@res@down}}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@right}{0pt}}

        \pgfusepath{draw}
    }
}

% plain amplifier, no symbols, one input
\pgfdeclareshape{plain mono amp}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{amplifiers}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \anchor{center}{\pgfpointorigin}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/plain amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/plain amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{east}{ \northwest \pgf@y=0pt \pgf@x=-\pgf@x  }
    \anchor{west}{ \northwest \pgf@y=0pt }
    \anchor{south}{ \northwest \pgf@x=0pt \pgf@y=-\pgf@y }
    \anchor{north}{ \northwest \pgf@x=0pt }
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northwest \pgf@x=-\pgf@x }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
    \savedanchor\left{%
        \pgf@y=0pt
    }
    \savedanchor\inOne{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/plain amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@y=0pt\relax
    }
    \anchor{in}{
        \inOne
    }
    % support for border anchors
    \savedanchor\leftedge{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/plain amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x = \ctikzvalof{tripoles/plain amp/port width}\pgf@x
        \pgf@y=0pt
    }
    \anchor{leftedge}{\leftedge}
    \anchor{rightedge}{\leftedge \pgf@x =-\pgf@x }
    \anchor{bin}{
        \inOne
        \pgf@ya=\pgf@y \leftedge \pgf@y=\pgf@ya
    }
    \anchor{bout}{
        \leftedge
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    % end border anchors
    \savedanchor\up{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/plain amp/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/plain amp/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfpointlineattime{
            \ctikzvalof{tripoles/plain amp/up pos}}{
            \pgfpoint{
            \ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@left}
        {\pgf@circ@res@up}}
        {\pgfpoint{\ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@right}{0pt}}
    }
    \anchor{up}{
        \up
    }
    \anchor{down}{
        \up
        \pgf@y=-\pgf@y
    }
    \anchor{out}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }

    \anchor{text}{
        \ifpgf@circ@center@text
            \pgf@x=\dimexpr -.6\wd\pgfnodeparttextbox\relax
        \else
            \leftedge
            \pgfmathsetlength{\pgf@x}{\pgf@x + \ctikzvalof{left text distance}}
        \fi
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor

        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x

        \pgfscope
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgftransformxshift{\ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@left}
            \pgf@circ@res@step=\pgf@circ@res@right
            \advance\pgf@circ@res@step by -\pgf@circ@res@left
            \pgf@circ@res@step=\ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@step

            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{0pt}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down}}
            \pgfpathclose
            \pgf@circ@draworfill
        \endpgfscope
        \pgfpathmoveto{\pgfpoint
            {\pgf@circ@res@left}
        {0pt}}
        \pgfpathlineto{\pgfpoint
            {\ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@left}
        {0pt}}

        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{tripoles/plain amp/port width}\pgf@circ@res@right}{0pt}}

        \pgfusepath{draw}
    }
}% %>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Tubes and magnetron
%%%%%%%%%%%%%%%%%%%%%%%%

% Settings Electronic tubes: diodetube, triode, tetrode and pentode%<<<1
\ctikzset{tubes/width/.initial=1}                    % relative width
\ctikzset{tubes/height/.initial=1.4}                 % relative height
\ctikzset{tubes/tube radius/.initial=0.40}           % radius of tube circle
\ctikzset{tubes/anode distance/.initial=0.40}        % distance from center
\ctikzset{tubes/anode width/.initial=0.40}           % width of an anode/plate
\ctikzset{tubes/grid protrusion/.initial=0.25}       % distance from center
\ctikzset{tubes/grid dashes/.initial=5}              % number of grid dashes
\ctikzset{tubes/grid separation/.initial=0.2}        % separation between grids
\ctikzset{tubes/grid shift/.initial=0.0}             % y shift grids from center
\ctikzset{tubes/cathode distance/.initial=0.40}      % distance from grid
\ctikzset{tubes/cathode width/.initial=0.40}         % width of an cathode
\ctikzset{tubes/cathode corners/.initial=0.06}       % corners of the cathode wire
\ctikzset{tubes/cathode right extend/.initial=0.075} % extension at the right side
\ctikzset{tubes/filament distance/.initial=0.1}      % distance from cathode
\ctikzset{tubes/filament angle/.initial=15}          % Angle from centerpoint
% partial borders styles
% this can be "none" or 6 numbers saying the style for each part:
% 0 --- nothing, 1 --- solid, 2 --- dashed
\ctikzset{tubes/partial borders/.initial=none}       % Value none for normal borders
\ctikzset{tubes/partial border dash/.initial={{2pt}{2pt}}}

\ctikzset{/tikz/circuitikz/tripoles/magnetron/width/.initial=1}

\newif\ifpgf@circuit@tubes@filament\pgf@circuit@tubes@filamentfalse
\pgfkeys{/tikz/filament/.add code={}{\pgf@circuit@tubes@filamenttrue}}
\ctikzset{tubes/filament/.add code={}{\pgf@circuit@tubes@filamenttrue}}
\newif\ifpgf@circuit@tubes@nocathode\pgf@circuit@tubes@nocathodefalse
\pgfkeys{/tikz/nocathode/.add code={}{\pgf@circuit@tubes@nocathodetrue}}
\ctikzset{tubes/nocathode/.add code={}{\pgf@circuit@tubes@nocathodetrue}}
\newif\ifpgf@circuit@tubes@fullcathode\pgf@circuit@tubes@fullcathodefalse
\pgfkeys{/tikz/fullcathode/.add code={}{\pgf@circuit@tubes@fullcathodetrue}}
\ctikzset{tubes/fullcathode/.add code={}{\pgf@circuit@tubes@fullcathodetrue}}%
%>>>

%% Node shapes for tubes & co%<<<

%%%%%%%%%%%%%%%%%%%
%% Magnetron
%%%%%%%%%%%%%%%%%%%

\pgfdeclareshape{magnetron}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{tubes}}  % class of these components
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor\northwest{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/magnetron/width}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x=-\ctikzvalof{tripoles/magnetron/width}\pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
    }
    \anchor{center}{
        \pgfpointorigin
    }
    \anchor{anode}{
        \northwest
        \pgf@x=0pt
        \pgf@y=-\pgf@y
    }
    \anchor{cathode1}{
        \northwest
        \pgf@circ@res@step=\pgf@y
        \pgfmathparse{cos(105)}
        \pgf@x=\pgfmathresult\pgf@circ@res@step
        \pgfmathparse{sin(105)}
        \pgf@y=\pgfmathresult\pgf@circ@res@step
        %\pgfpointorigin
        %\pgfpathmoveto{\pgfpointpolar{105}{\pgf@circ@res@step}}%not working in a scaled tikzpicture
    }
    \anchor{cathode2}{
        \northwest
        \pgf@circ@res@step=\pgf@y
        \pgfmathparse{cos(75)}
        \pgf@x=\pgfmathresult\pgf@circ@res@step
        \pgfmathparse{sin(75)}
        \pgf@y=\pgfmathresult\pgf@circ@res@step
        %\pgfpointorigin
        %\pgfpathmoveto{\pgfpointpolar{75}{\pgf@circ@res@step}}%not working in a scaled tikzpicture
    }
    \anchor{text}{
        \pgfpointorigin
        \advance \pgf@x by -.5\wd\pgfnodeparttextbox
        \advance \pgf@y by -.5\ht\pgfnodeparttextbox
    }
    \anchor{left}{%
        \northwest
        \pgf@y=0pt
    }
    \anchor{right}{%
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{top}{
        \northwest
        \pgf@x=0pt
    }
    \anchor{pathstart}{
        \northwest
        \pgf@x=0pt
    }
    \anchor{pathend}{
        \northwest
        \pgf@x=0pt
        \pgf@y=-\pgf@y
    }
    \anchor{bottom}{
        \northwest
        \pgf@x=0pt
        \pgf@y=-\pgf@y
    }
    \anchor{center}{
        \pgf@y=0pt
        \pgf@x=0pt
    }
    \anchor{east}{
        \northwest
        \pgf@y=0pt
        \pgf@x=-\pgf@x
    }
    \anchor{west}{
        \northwest
        \pgf@y=0pt
    }
    \anchor{south}{
        \northwest
        \pgf@x=0pt
        \pgf@y=-\pgf@y
    }
    \anchor{north}{
        \northwest
        \pgf@x=0pt
    }
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northwest \pgf@x=-\pgf@x }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{tripoles/magnetron/width}\pgf@circ@scaled@Rlen
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfmathsetlength{\pgf@circ@res@other}{sin(15)*\pgf@circ@res@up}

        \pgfscope
            \pgfstartlinewidth=\pgflinewidth
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            %create outer circle
            \pgfpathcircle{\pgfpoint{0}{0}} {\pgf@circ@res@right}
            \pgf@circ@draworfill
            %create chambers
            \foreach \angle in {45,135,225,315}{
                \pgfpathmoveto{ \pgfpointpolar{\angle}{0.6\pgf@circ@res@right}}
                \pgfpathlineto{ \pgfpointpolar{\angle}{\pgf@circ@res@right}}
            }
            \pgfsetroundcap
            \pgfusepath{draw}
            \pgfscope
                %draw connection from outside
                %anode
                \pgfsetlinewidth{\pgfstartlinewidth}
                \pgfpathmoveto{\pgfpoint{0\pgf@circ@res@left}{\pgf@circ@res@down}}
                \pgfpathlineto{\pgfpoint{0\pgf@circ@res@right}{.5\pgf@circ@res@down}}
                %cathodes
                \pgfpathmoveto{\pgfpointpolar{105}{\pgf@circ@res@up}}
                \pgfpathlineto{\pgfpoint{-\pgf@circ@res@other}{.5\pgf@circ@res@up}}
                \pgfpathmoveto{\pgfpointpolar{75}{\pgf@circ@res@up}}
                \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{.5\pgf@circ@res@up}}
                \pgfsetbuttcap
                \pgfusepath{draw}
            \endpgfscope
            %create cathode
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{.5\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{0}{.15\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{-\pgf@circ@res@other}{.5\pgf@circ@res@up}}
            \pgfusepath{draw}
            %create anode
            \pgfpathmoveto{\pgfpoint{0.3\pgf@circ@res@left}{.5\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{0.3\pgf@circ@res@right}{.5\pgf@circ@res@down}}

            \pgfsetbuttcap
            \pgfusepath{draw}
        \endpgfscope
    }
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Electronic tubes, submitted by J. op den Brouw
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% draw partial tube outline
%
\def\pgf@circ@tubes@split#1#2#3#4#5#6\relax{%split the six numbers
    \edef\@@a{#1}\edef\@@b{#2}\edef\@@c{#3}\edef\@@d{#4}\edef\@@e{#5}\edef\@@f{#6}%
}
\def\pgf@circ@tubes@setdash{%
    \edef\@@dash{\ctikzvalof{tubes/partial border dash}}%
    % \typeout{DASH:\@@dash}%
    \expandafter\pgfsetdash\expandafter{\@@dash}{0pt}%
}
% this is the same as the transistor circles' one, but let's keep it separated
\def\pgf@circ@tubes@draw@style#1{%
    \ifcase#1
        \pgfusepath{discard}% case 0, will discard the path
    \or
        \pgfsetdash{}{0pt}\pgfusepath{draw}% case 1, solid
    \or
        \pgf@circ@tubes@setdash\pgfusepath{draw}% case 2, dashed
    \else
        \pgfutil@packagewarning{circuitikz}{Tube border draw style not known!}%
        \pgfusepath{draw}%
    \fi
}
\def\pgf@circ@tubes@draw@partial#1{%
    \expandafter\pgf@circ@tubes@split#1\relax
    % \typeout{PARTIAL: \@@a:\@@b:\@@c:\@@d:\@@e:\@@f}
    \ifdim\ctikzvalof{tubes/width}pt>\ctikzvalof{tubes/height}pt\relax
        % horizontal tube
        \pgfutil@tempdima=\pgf@circ@res@right
        \advance\pgfutil@tempdima by -\pgf@circ@res@up
        \pgfscope % left side upper arc
            \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{0pt}}
            \pgfpatharc{180}{90}{\pgf@circ@res@up}
            \pgf@circ@tubes@draw@style{\@@a}
        \endpgfscope
        \pgfscope % upper horizontal part
            \pgfpathmoveto{\pgfpoint{-\pgfutil@tempdima}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgfutil@tempdima}{\pgf@circ@res@up}}
            \pgf@circ@tubes@draw@style{\@@b}
        \endpgfscope
        \pgfscope % right side upper arc
            \pgfpathmoveto{\pgfpoint{\pgfutil@tempdima}{\pgf@circ@res@up}}
            \pgfpatharc{90}{0}{\pgf@circ@res@up}
            \pgf@circ@tubes@draw@style{\@@c}
        \endpgfscope
        \pgfscope % right side lower arc
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
            \pgfpatharc{0}{-90}{\pgf@circ@res@up}
            \pgf@circ@tubes@draw@style{\@@d}
        \endpgfscope
        \pgfscope % lower horizontal part
            \pgfpathmoveto{\pgfpoint{\pgfutil@tempdima}{-\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{-\pgfutil@tempdima}{-\pgf@circ@res@up}}
            \pgf@circ@tubes@draw@style{\@@e}
        \endpgfscope
        \pgfscope % left side lower arc
            \pgfpathmoveto{\pgfpoint{-\pgfutil@tempdima}{-\pgf@circ@res@up}}
            \pgfpatharc{270}{180}{\pgf@circ@res@up}
            \pgf@circ@tubes@draw@style{\@@f}
        \endpgfscope
    \else
        % vertical tube
        \pgfutil@tempdima=\pgf@circ@res@up
        \advance\pgfutil@tempdima by -\pgf@circ@res@right
        \pgfscope % left side upper arc
            \pgfpathmoveto{\pgfpoint{0pt}{\pgf@circ@res@up}}
            \pgfpatharc{90}{0}{\pgf@circ@res@right}
            \pgf@circ@tubes@draw@style{\@@a}
        \endpgfscope
        \pgfscope % right vertical part
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgfutil@tempdima}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgfutil@tempdima}}
            \pgf@circ@tubes@draw@style{\@@b}
        \endpgfscope
        \pgfscope % right side lower arc
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{-\pgfutil@tempdima}}
            \pgfpatharc{0}{-90}{\pgf@circ@res@right}
            \pgf@circ@tubes@draw@style{\@@c}
        \endpgfscope
        \pgfscope % right side lower arc
            \pgfpathmoveto{\pgfpoint{0pt}{-\pgf@circ@res@up}}
            \pgfpatharc{-90}{-180}{\pgf@circ@res@right}
            \pgf@circ@tubes@draw@style{\@@d}
        \endpgfscope
        \pgfscope % left vertical part
            \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{-\pgfutil@tempdima}}
            \pgfpathlineto{\pgfpoint{-\pgf@circ@res@right}{\pgfutil@tempdima}}
            \pgf@circ@tubes@draw@style{\@@e}
        \endpgfscope
        \pgfscope % left side upper arc
            \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\pgfutil@tempdima}}
            \pgfpatharc{180}{90}{\pgf@circ@res@right}
            \pgf@circ@tubes@draw@style{\@@f}
        \endpgfscope
    \fi
}
% Draw tube outline
\def\pgf@circ@tubes@drawtube{%
    \ifdim\ctikzvalof{tubes/width}pt>\ctikzvalof{tubes/height}pt\relax
        % horizontal tube
        \pgfpathmoveto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfutil@tempdima=\pgf@circ@res@right
        \advance\pgfutil@tempdima by -\pgf@circ@res@up
        \pgfpathlineto{\pgfpoint{\pgfutil@tempdima}{\pgf@circ@res@up}}
        \pgfpatharc{90}{-90}{\pgf@circ@res@up}
        \pgfpathlineto{\pgfpoint{-\pgfutil@tempdima}{-\pgf@circ@res@up}}
        \pgfpatharc{270}{90}{\pgf@circ@res@up}
    \else
        % vertical tube
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{0pt}}
        \pgfutil@tempdima=\pgf@circ@res@up
        \advance\pgfutil@tempdima by -\pgf@circ@res@right
        \pgfpathlineto{\pgfpoint{-\pgf@circ@res@right}{\pgfutil@tempdima}}
        \pgfpatharc{180}{0}{\pgf@circ@res@right}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgfutil@tempdima}}
        \pgfpatharc{180}{0}{-\pgf@circ@res@right}
    \fi
    \pgfpathclose
    \edef\@@partial{\ctikzvalof{tubes/partial borders}}
    \ifx\@@partial\pgf@nonetext
        % Tube fill and draw if it's not partial... for speed
        \pgf@circ@draworfill
    \else
        % otherwise, just fill and do the partial fill
        \pgf@circ@maybefill
        \pgf@circ@tubes@draw@partial{\@@partial}
        %
    \fi
}

\long\def\pgfcirctubedrawanodestd{% Standard anode code (one anode)
    % Anode (or plate)
    \pgfpathmoveto{\pgfpoint{0pt}{\pgf@circ@res@up}} % north
    \pgfpathlineto{\pgfpoint{0pt}{\ctikzvalof{tubes/anode distance}\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{-\ctikzvalof{tubes/anode width}\pgf@circ@res@right}{\ctikzvalof{tubes/anode distance}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\ctikzvalof{tubes/anode width}\pgf@circ@res@right}{\ctikzvalof{tubes/anode distance}\pgf@circ@res@up}}
}
\long\def\pgfcirctubedrawcathodestd{% Standard cathode code (one cathode)
    % Cathode
    \ifpgf@circuit@tubes@nocathode
        \pgf@circuit@tubes@nocathodefalse
    \else
        \pgfsetcornersarced{\pgfpoint{\ctikzvalof{tubes/cathode corners}\pgf@circ@res@up}{\ctikzvalof{tubes/cathode corners}\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{-\ctikzvalof{tubes/cathode width}\pgf@circ@res@right}{-\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{-\ctikzvalof{tubes/cathode width}\pgf@circ@res@right}{-\ctikzvalof{tubes/cathode distance}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{tubes/cathode width}\pgf@circ@res@right}{-\ctikzvalof{tubes/cathode distance}\pgf@circ@res@up}}
        \ifpgf@circuit@tubes@fullcathode
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tubes/cathode width}\pgf@circ@res@right}{-\pgf@circ@res@up}}
            \pgf@circuit@tubes@fullcathodefalse
        \else
            \pgfpathlineto{\pgfpoint{\ctikzvalof{tubes/cathode width}\pgf@circ@res@right}{-\ctikzvalof{tubes/cathode distance}\pgf@circ@res@up-\ctikzvalof{tubes/cathode right extend}\pgf@circ@res@up}}
        \fi
    \fi
}

%% generic macro to create a tube. Most of them will use the standard macro for
%% anode and cathode (see above)
\long\def\pgfcircdeclaretubegeneric#1#2#3#4#5#6{% name, anchors, grid, anode, cathode variable anchors
    \pgfdeclareshape{#1}{
        \savedmacro{\ctikzclass}{\edef\ctikzclass{tubes}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \savedanchor\northwest{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@circ@res@up=\ctikzvalof{tubes/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@right=\ctikzvalof{tubes/width}\pgf@circ@scaled@Rlen
            % x and y should be half the Rlen
            \pgf@y=\pgf@circ@res@up
            \pgf@y=.5\pgf@y
            \pgf@x=-\pgf@circ@res@right
            \pgf@x=.5\pgf@x
        }
        \savedanchor\tubene{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@circ@res@temp=\ctikzvalof{tubes/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=\ctikzvalof{tubes/width}\pgf@circ@scaled@Rlen
            \pgf@circ@res@up=\ctikzvalof{tubes/tube radius}\pgf@circ@res@temp
            \pgf@circ@res@right=\ctikzvalof{tubes/tube radius}\pgf@circ@res@other
            \pgf@y=\pgf@circ@res@up
            \pgf@x=\pgf@circ@res@right
        }
        \savedanchor\tubesquarene{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@circ@res@temp=\ctikzvalof{tubes/height}\pgf@circ@scaled@Rlen
            \pgf@circ@res@other=\ctikzvalof{tubes/width}\pgf@circ@scaled@Rlen
            \pgf@circ@res@up=\ctikzvalof{tubes/tube radius}\pgf@circ@res@temp
            \pgf@circ@res@right=\ctikzvalof{tubes/tube radius}\pgf@circ@res@other
            \ifdim\ctikzvalof{tubes/width}pt>\ctikzvalof{tubes/height}pt\relax
                % horizontal
                \pgf@y=\pgf@circ@res@up
                \pgf@x=\pgf@circ@res@right\advance\pgf@x by -\pgf@circ@res@up
            \else
                % vertical
                \pgf@x=\pgf@circ@res@right
                \pgf@y=\pgf@circ@res@up\advance\pgf@y by -\pgf@circ@res@right
            \fi
        }
        \savedmacro{\tubes@filament@angle}{\edef\tubes@filament@angle{\ctikzvalof{tubes/filament angle}}}
        \savedmacro{\tubes@filament@distance}{\edef\tubes@filament@distance{\ctikzvalof{tubes/filament distance}}}
        \savedmacro{\tubes@tube@radius}{\edef\tubes@tube@radius{\ctikzvalof{tubes/tube radius}}}
        \savedmacro{\tubes@cathode@width}{\edef\tubes@cathode@width{\ctikzvalof{tubes/cathode width}}}
        \savedmacro{\tubes@cathode@distance}{\edef\tubes@cathode@distance{\ctikzvalof{tubes/cathode distance}}}
        \anchor{tube ne}{\tubene}
        \anchor{tubesq ne}{\tubesquarene}
        % tube shape anchors: geo
        \anchor{tube top}{\tubene\pgf@x=0pt\relax}
        \anchor{tube bottom}{\tubene\pgf@x=0pt\pgf@y=-\pgf@y}
        \anchor{tube right}{\tubene\pgf@y=0pt\relax}
        \anchor{tube left}{\tubene\pgf@y=0pt\pgf@x=-\pgf@x}
        % tube shape straight part anchors
        \anchor{tube top right}{\tubesquarene}
        \anchor{tube bottom right}{\tubesquarene\pgf@y=-\pgf@y}
        \anchor{tube top left}{\tubesquarene\pgf@x=-\pgf@x}
        \anchor{tube bottom left}{\tubesquarene\pgf@y=-\pgf@y\pgf@x=-\pgf@x}
        % tube shape centers
        \anchor{tube top center}{\tubesquarene\pgf@x=0pt\relax}
        \anchor{tube bottom center}{\tubesquarene\pgf@y=-\pgf@y\pgf@x=0pt\relax}
        \anchor{tube right center}{\tubesquarene\pgf@y=0pt\relax}
        \anchor{tube left center}{\tubesquarene\pgf@x=-\pgf@x\pgf@y=0pt\relax}
        % rest of anchors
        \anchor{center}{\pgfpointorigin}
        % geo anchors based on north-west
        \pgfcirc@northwest@symmetric@geoanchors
        % text anchor
        \anchor{text}{%
            \northwest\pgf@x=-\pgf@x
            \pgf@y=-.5\ht\pgfnodeparttextbox
        }
        % specific anchors
        \anchor{anode} {%
            \northwest
            \pgf@x=0pt
        }
        \anchor{cathode}{%
            \northwest
            \pgf@y=-\pgf@y
            \pgf@x=\tubes@cathode@width\pgf@x
        }
        \anchor{cathode 1}{%
            \northwest
            \pgf@y=-\pgf@y
            \pgf@x=\tubes@cathode@width\pgf@x
        }
        \anchor{cathode 2}{%
            \northwest
            \pgf@y=-\pgf@y
            \pgf@x=-\tubes@cathode@width\pgf@x
        }
        \anchor{filament 1}{%
            \northwest
            \pgfmathparse{(\tubes@tube@radius*sin(\tubes@filament@angle)}
            \pgf@x=\pgfmathresult\pgf@x
            \pgf@y=-\pgf@y
        }
        \anchor{filament 2}{%
            \northwest
            \pgfmathparse{(\tubes@tube@radius*sin(\tubes@filament@angle)}
            \pgf@x=-\pgfmathresult\pgf@x
            \pgf@y=-\pgf@y
        }
        \anchor{filament center}{%
            \northwest
            \pgf@ya=0.5\pgf@y
            \pgf@ya=-\tubes@cathode@distance\pgf@y
            \advance\pgf@ya by -\tubes@filament@distance\pgf@y
            \pgf@x=0pt\pgf@y=\pgf@ya
        }

        % Extra anchors
        #2%

        \pgf@circ@draw@component{
                % Line width for tripoles
                \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
                \pgf@circ@scaled@Rlen=\scaledRlen

                % Setup to draw tube
                \pgf@circ@res@up=\ctikzvalof{tubes/height}\pgf@circ@scaled@Rlen
                \pgf@circ@res@right=\ctikzvalof{tubes/width}\pgf@circ@scaled@Rlen
                \pgf@circ@res@up=\ctikzvalof{tubes/tube radius}\pgf@circ@res@up
                \pgf@circ@res@right=\ctikzvalof{tubes/tube radius}\pgf@circ@res@right

                % Tube outline
                \pgf@circ@tubes@drawtube

                % Setup to draw grid, filament, anode and cathode
                \pgf@circ@res@up=\ctikzvalof{tubes/height}\pgf@circ@scaled@Rlen
                \pgf@circ@res@right=\ctikzvalof{tubes/width}\pgf@circ@scaled@Rlen
                \pgf@circ@res@up=0.5\pgf@circ@res@up
                \pgf@circ@res@right=0.5\pgf@circ@res@right

                % Grid drawing
                #3%

                % Filament (is not drawn by default)
                \ifpgf@circuit@tubes@filament
                    \pgf@circ@res@temp=-\ctikzvalof{tubes/cathode distance}\pgf@circ@res@up
                    \advance\pgf@circ@res@temp by -\ctikzvalof{tubes/filament distance}\pgf@circ@res@up
                    \pgfmathparse{(\ctikzvalof{tubes/tube radius}*sin(\ctikzvalof{tubes/filament angle})}
                    \pgf@xa=\pgfmathresult\pgf@circ@res@right
                    \pgfmathparse{\ctikzvalof{tubes/tube radius}+\ctikzvalof{tubes/tube radius}*cos(\ctikzvalof{tubes/filament angle}}
                    \pgf@ya=\pgfmathresult\pgf@circ@res@up
                    \pgfpathmoveto{\pgfpoint{0pt}{\pgf@circ@res@temp}}
                    \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
                    \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@circ@res@up}}
                    \pgfpathmoveto{\pgfpoint{0pt}{\pgf@circ@res@temp}}
                    \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
                    \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@circ@res@up}}
                    \pgf@circuit@tubes@filamentfalse
                \fi

                % Anode (or plate)
                #4
                % Cathode
                #5
                % Draw the background
                \pgfusepath{draw}
        }
        #6
    }
}

%% The diode (tube), triode, tetrode and pentode only differ in the
%% number of grids. So we construct a generic declare function in
%% which we can put code for the grid anchors and grid drawing code
%% \pgfcircdeclaretube{tube name}{grid anchors}{grid drawing code}
\long\def\pgfcircdeclaretube#1#2#3{% name, anchors, grid
    \pgfcircdeclaretubegeneric{#1}{#2}{#3}{\pgfcirctubedrawanodestd}{\pgfcirctubedrawcathodestd}{}
}

\pgfcircdeclaretube{diodetube}{}{} % shape diode already exists

\pgfcircdeclaretube{triode}
{
	\anchor{grid} {% should not be used
		\northwest
		\pgf@y=\ctikzvalof{tubes/grid shift}\pgf@y
	}
	\anchor{control} {%
		\northwest
		\pgf@y=\ctikzvalof{tubes/grid shift}\pgf@y
	}
}
{
	% Grid protrusion
	\pgf@xa=-\ctikzvalof{tubes/tube radius}\pgf@circ@res@right
	\advance\pgf@xa by -\ctikzvalof{tubes/grid protrusion}\pgf@circ@res@right
	\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\ctikzvalof{tubes/grid shift}\pgf@circ@res@up}}
	\pgfpathlineto{\pgfpoint{\pgf@xa}{\ctikzvalof{tubes/grid shift}\pgf@circ@res@up}}
	% Grid dashes: calculations
	\pgf@xb=2\pgf@circ@res@right
	\pgf@circ@res@step=\ctikzvalof{tubes/tube radius}\pgf@xb
	\pgf@circ@count@a=\ctikzvalof{tubes/grid dashes}  % dashes*2+1
	\multiply\pgf@circ@count@a by 2\relax
	\advance\pgf@circ@count@a by 1\relax
	\advance\pgf@circ@res@step by -\pgf@xa
	\divide\pgf@circ@res@step by \pgf@circ@count@a
	% Grid dashes: draw
	\pgf@circ@res@temp=\pgf@xa
	\pgf@circ@count@a=\ctikzvalof{tubes/grid dashes}
	\loop
	\advance\pgf@circ@res@temp by\pgf@circ@res@step
	\pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\ctikzvalof{tubes/grid shift}\pgf@circ@res@up}}
	\advance\pgf@circ@res@temp by\pgf@circ@res@step
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@temp}{\ctikzvalof{tubes/grid shift}\pgf@circ@res@up}}
	\advance\pgf@circ@count@a by-1
	\ifnum\pgf@circ@count@a>0\relax
	\repeat
}

\pgfcircdeclaretube{tetrode}
{
	\anchor{grid} {% should not be used
		\northwest
		\pgfutil@tempdima=\pgf@y
		\pgf@y=-\ctikzvalof{tubes/grid separation}\pgf@y
		\pgf@y=0.5\pgf@y
		\advance\pgf@y by \ctikzvalof{tubes/grid shift}\pgfutil@tempdima
	}
	\anchor{control} {%
		\northwest
		\pgfutil@tempdima=\pgf@y
		\pgf@y=-\ctikzvalof{tubes/grid separation}\pgf@y
		\pgf@y=0.5\pgf@y
		\advance\pgf@y by \ctikzvalof{tubes/grid shift}\pgfutil@tempdima
	}
	\anchor{screen} {%
		\northwest
		\pgfutil@tempdima=\pgf@y
		\pgf@y=\ctikzvalof{tubes/grid separation}\pgf@y
		\pgf@y=0.5\pgf@y
		\advance\pgf@y by \ctikzvalof{tubes/grid shift}\pgfutil@tempdima
	}
}
{
	% Grid x/y points
	\pgf@xa=-\ctikzvalof{tubes/tube radius}\pgf@circ@res@right
	\advance\pgf@xa by -\ctikzvalof{tubes/grid protrusion}\pgf@circ@res@right
	\pgfutil@tempdima=\ctikzvalof{tubes/grid separation}\pgf@circ@res@up
	\pgfutil@tempdimb=-\pgfutil@tempdima
	\pgfutil@tempdima=0.5\pgfutil@tempdima
	\advance\pgfutil@tempdima by \ctikzvalof{tubes/grid shift}\pgf@circ@res@up
	\pgfutil@tempdimb=0.5\pgfutil@tempdimb
	\advance\pgfutil@tempdimb by \ctikzvalof{tubes/grid shift}\pgf@circ@res@up
	% Grid protrusion
	\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\pgfutil@tempdimb}}
	\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgfutil@tempdimb}}
	\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\pgfutil@tempdima}}
	\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgfutil@tempdima}}
	% Grid dashes: calculations
	\pgf@xb=2\pgf@circ@res@right
	\pgf@circ@res@step=\ctikzvalof{tubes/tube radius}\pgf@xb
	\pgf@circ@count@a=\ctikzvalof{tubes/grid dashes}  % dashes*2+1
	\multiply\pgf@circ@count@a by 2\relax
	\advance\pgf@circ@count@a by 1\relax
	\advance\pgf@circ@res@step by -\pgf@xa
	\divide\pgf@circ@res@step by \pgf@circ@count@a
	% Grid dashes: draw
	\pgf@circ@res@temp=\pgf@xa
	\pgf@circ@count@a=\ctikzvalof{tubes/grid dashes}
	\loop
	\advance\pgf@circ@res@temp by\pgf@circ@res@step
	\pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\pgfutil@tempdima}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@temp+\pgf@circ@res@step}{\pgfutil@tempdima}}
	\pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\pgfutil@tempdimb}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@temp+\pgf@circ@res@step}{\pgfutil@tempdimb}}
	\advance\pgf@circ@res@temp by\pgf@circ@res@step
	\advance\pgf@circ@count@a by-1
	\ifnum\pgf@circ@count@a>0\relax
	\repeat
}

\pgfcircdeclaretube{pentode}
{
	\anchor{grid} {% should not be used
		\northwest
		\pgfutil@tempdima=\pgf@y
		\pgf@y=-\ctikzvalof{tubes/grid separation}\pgf@y
		\advance\pgf@y by \ctikzvalof{tubes/grid shift}\pgfutil@tempdima
	}
	\anchor{control} {%
		\northwest
		\pgfutil@tempdima=\pgf@y
		\pgf@y=-\ctikzvalof{tubes/grid separation}\pgf@y
		\advance\pgf@y by \ctikzvalof{tubes/grid shift}\pgfutil@tempdima
	}
	\anchor{screen} {%
		\northwest
		\pgf@y=\ctikzvalof{tubes/grid shift}\pgf@y
	}
	\anchor{suppressor} {%
		\northwest
		\pgfutil@tempdima=\pgf@y
		\pgf@y=\ctikzvalof{tubes/grid separation}\pgf@y
		\advance\pgf@y by \ctikzvalof{tubes/grid shift}\pgfutil@tempdima
	}
}
{
	% Grid x/y points
	\pgf@xa=-\ctikzvalof{tubes/tube radius}\pgf@circ@res@right
	\advance\pgf@xa by -\ctikzvalof{tubes/grid protrusion}\pgf@circ@res@right
	\pgfutil@tempdima=\ctikzvalof{tubes/grid separation}\pgf@circ@res@up
	\pgfutil@tempdimb=-\pgfutil@tempdima
	\advance\pgfutil@tempdima by \ctikzvalof{tubes/grid shift}\pgf@circ@res@up
	\advance\pgfutil@tempdimb by \ctikzvalof{tubes/grid shift}\pgf@circ@res@up
	\pgf@circ@res@other=\ctikzvalof{tubes/grid shift}\pgf@circ@res@up
	% Grid protrusion
	\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\pgfutil@tempdimb}}
	\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgfutil@tempdimb}}
	\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\pgfutil@tempdima}}
	\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgfutil@tempdima}}
	\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\pgf@circ@res@other}}
	\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@circ@res@other}}
	% Grid dashes: calculations
	\pgf@xb=2\pgf@circ@res@right
	\pgf@circ@res@step=\ctikzvalof{tubes/tube radius}\pgf@xb
	\pgf@circ@count@a=\ctikzvalof{tubes/grid dashes}  % dashes*2+1
	\multiply\pgf@circ@count@a by 2\relax
	\advance\pgf@circ@count@a by 1\relax
	\advance\pgf@circ@res@step by -\pgf@xa
	\divide\pgf@circ@res@step by \pgf@circ@count@a
	% Grid dashes: draw
	\pgf@circ@res@temp=\pgf@xa
	\pgf@circ@count@a=\ctikzvalof{tubes/grid dashes}
	\loop
	\advance\pgf@circ@res@temp by\pgf@circ@res@step
	\pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\pgfutil@tempdima}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@temp+\pgf@circ@res@step}{\pgfutil@tempdima}}
	\pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\pgfutil@tempdimb}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@temp+\pgf@circ@res@step}{\pgfutil@tempdimb}}
	\pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@other}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@temp+\pgf@circ@res@step}{\pgf@circ@res@other}}
	\advance\pgf@circ@res@temp by\pgf@circ@res@step
	\advance\pgf@circ@count@a by-1
	\ifnum\pgf@circ@count@a>0\relax
	\repeat
}

\pgfcircdeclaretube{pentode suppressor to cathode}
{
	\anchor{grid} {% should not be used
		\northwest
		\pgfutil@tempdima=\pgf@y
		\pgf@y=-\ctikzvalof{tubes/grid separation}\pgf@y
		\advance\pgf@y by \ctikzvalof{tubes/grid shift}\pgfutil@tempdima
	}
	\anchor{control} {%
		\northwest
		\pgfutil@tempdima=\pgf@y
		\pgf@y=-\ctikzvalof{tubes/grid separation}\pgf@y
		\advance\pgf@y by \ctikzvalof{tubes/grid shift}\pgfutil@tempdima
	}
	\anchor{screen} {%
		\northwest
		\pgf@y=\ctikzvalof{tubes/grid shift}\pgf@y
	}
}
{
	% Grid x/y points
	\pgf@xa=-\ctikzvalof{tubes/tube radius}\pgf@circ@res@right
	\advance\pgf@xa by -\ctikzvalof{tubes/grid protrusion}\pgf@circ@res@right
	\pgfutil@tempdima=\ctikzvalof{tubes/grid separation}\pgf@circ@res@up
	\pgfutil@tempdimb=-\pgfutil@tempdima
	\advance\pgfutil@tempdima by \ctikzvalof{tubes/grid shift}\pgf@circ@res@up
	\advance\pgfutil@tempdimb by \ctikzvalof{tubes/grid shift}\pgf@circ@res@up
	\pgf@circ@res@other=\ctikzvalof{tubes/grid shift}\pgf@circ@res@up
	% Grid protrusion
	\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\pgfutil@tempdimb}}
	\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgfutil@tempdimb}}
	\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\pgf@circ@res@other}}
	\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@circ@res@other}}
	% Grid dashes: calculations
	\pgf@xb=2\pgf@circ@res@right
	\pgf@circ@res@step=\ctikzvalof{tubes/tube radius}\pgf@xb
	\pgf@circ@count@a=\ctikzvalof{tubes/grid dashes}  % dashes*2+1
	\multiply\pgf@circ@count@a by 2\relax
	\advance\pgf@circ@count@a by 1\relax
	\advance\pgf@circ@res@step by -\pgf@xa
	\divide\pgf@circ@res@step by \pgf@circ@count@a
	% Grid dashes: draw
	\pgf@circ@res@temp=\pgf@xa
	\pgf@circ@count@a=\ctikzvalof{tubes/grid dashes}
	\loop
	\advance\pgf@circ@res@temp by\pgf@circ@res@step
	\ifnum\pgf@circ@count@a>1\relax
	\pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\pgfutil@tempdimb}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@temp+\pgf@circ@res@step}{\pgfutil@tempdimb}}
	\pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@other}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@temp+\pgf@circ@res@step}{\pgf@circ@res@other}}
	\fi
	\pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\pgfutil@tempdima}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@temp+\pgf@circ@res@step}{\pgfutil@tempdima}}
	\advance\pgf@circ@res@temp by\pgf@circ@res@step
	\advance\pgf@circ@count@a by-1
	\ifnum\pgf@circ@count@a>0\relax
	\repeat
	% Grid: connection from suppressor to cathode
	\pgfsetcornersarced{\pgfpoint{\ctikzvalof{tubes/cathode corners}\pgf@circ@res@up}{\ctikzvalof{tubes/cathode corners}\pgf@circ@res@up}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@temp}{\pgfutil@tempdima-2*\ctikzvalof{tubes/grid separation}\pgf@circ@res@up}}
	\pgfpathlineto{\pgfpoint{\ctikzvalof{tubes/cathode width}\pgf@circ@res@right-0.4142136*\ctikzvalof{tubes/cathode corners}\pgf@circ@res@right}{-\ctikzvalof{tubes/cathode distance}\pgf@circ@res@up-0.4142136*\ctikzvalof{tubes/cathode corners}\pgf@circ@res@up}}

}%
%
% multi-anode tube, added by Romano for version 1.6.8, suggested by @bogger33 on GitHub
% see https://github.com/circuitikz/circuitikz/issues/785
%
\ctikzset{tubes/anodes/.initial=3}  % number of anodes. Ignored in most tubes.
\newif\ifpgf@circuit@tubes@anodedot\pgf@circuit@tubes@anodedotfalse
\pgfkeys{/tikz/anodedot/.add code={}{\pgf@circuit@tubes@anodedottrue}}
\ctikzset{tubes/anodedot/.add code={}{\pgf@circuit@tubes@anodedottrue}}
\newif\ifpgf@circuit@tubes@nogrid\pgf@circuit@tubes@nogridfalse
\pgfkeys{/tikz/nogrid/.add code={}{\pgf@circuit@tubes@nogridtrue}}
\ctikzset{tubes/nogrid/.add code={}{\pgf@circuit@tubes@nogridtrue}}
\newif\ifpgf@circuit@tubes@nixieanode\pgf@circuit@tubes@nixieanodefalse
\pgfkeys{/tikz/nixieanode/.add code={}{\pgf@circuit@tubes@nixieanodetrue}}
\ctikzset{tubes/nixieanode/.add code={}{\pgf@circuit@tubes@nixieanodetrue}}
\long\def\pgfcirctubedraw@multi@anode{% Separate to override in matubes
    % Anodes (or plates)
    % Use saved len/anchors to find the first drawn position.
    \pgf@circ@res@temp=\anodelen\divide\pgf@circ@res@temp by 2 % half the anode length
    \firstanodepos\pgf@circ@res@other=\pgf@x
    \advance\pgf@circ@res@other by \pgf@circ@res@temp
    \pgf@circ@count@a=0
    \loop
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other}{\pgf@circ@res@up}} % north
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\ctikzvalof{tubes/anode distance}\pgf@circ@res@up}}
        \ifpgf@circuit@tubes@anodedot
            \pgfpathcircle{\pgfpoint{\pgf@circ@res@other}{\ctikzvalof{tubes/anode distance}\pgf@circ@res@up-0.5*\circlelen}}{\circlelen}
        \else
            % this is the horizontal line of the anode
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@other-\pgf@circ@res@temp}{\ctikzvalof{tubes/anode distance}\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@other+\pgf@circ@res@temp}{\ctikzvalof{tubes/anode distance}\pgf@circ@res@up}}
        \fi
        \advance\pgf@circ@res@other by 4\pgf@circ@res@temp
        \advance\pgf@circ@count@a by 1
    \ifnum\pgf@circ@count@a<\Nanodes\relax
    \repeat
}
\long\def\pgfcirctubedraw@cathode@or@nixie{%
    \ifpgf@circuit@tubes@nixieanode
        \pgfpathmoveto{\pgfpoint{0pt}{-\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{-\ctikzvalof{tubes/cathode distance}\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{-\ctikzvalof{tubes/cathode width}\pgf@circ@res@right}{-\ctikzvalof{tubes/cathode distance}\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\ctikzvalof{tubes/cathode width}\pgf@circ@res@right}{-\ctikzvalof{tubes/cathode distance}\pgf@circ@res@up}}
    \else
        \pgfcirctubedrawcathodestd
    \fi
}
\pgfcircdeclaretubegeneric{matube}
{% anchors
    \savedmacro{\Nanodes}{\edef\Nanodes{\ctikzvalof{tubes/anodes}}}
    \savedanchor\firstanodepos{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@up=\ctikzvalof{tubes/height}\pgf@circ@scaled@Rlen
        \pgf@circ@res@right=\ctikzvalof{tubes/width}\pgf@circ@scaled@Rlen
        \pgf@circ@res@right=\ctikzvalof{tubes/anode width}\pgf@circ@res@right
        % x and y are one half
        \pgf@y=\pgf@circ@res@up
        \pgf@y=.5\pgf@y
        \pgf@x=-\pgf@circ@res@right
        \pgf@x=.5\pgf@x
    }
    \saveddimen\anodelen{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@circ@res@right=\ctikzvalof{tubes/width}\pgf@circ@scaled@Rlen % full width, left to right
        % the length of one of the N anodes is the full width divided by 2*N+1
        \pgfmathsetlength\pgf@x{\ctikzvalof{tubes/anode width}*\pgf@circ@res@right/(2*\Nanodes-1)}
    }
    \saveddimen\circlelen{%
        \pgf@x=\ctikzvalof{nodes width}\pgf@circ@Rlen
    }
    \anchor{grid} {% should not be used
        \northwest
        \pgf@y=\ctikzvalof{tubes/grid shift}\pgf@y
    }
    \anchor{control} {%
        \northwest
        \pgf@y=\ctikzvalof{tubes/grid shift}\pgf@y
    }
    \anchor{nixie a}{%
        \northwest\pgf@x=0pt\pgf@y=-\pgf@y
    }
}
{% grid
    \ifpgf@circuit@tubes@nogrid\else
    % Grid protrusion
    \pgf@xa=-\ctikzvalof{tubes/tube radius}\pgf@circ@res@right
    \advance\pgf@xa by -\ctikzvalof{tubes/grid protrusion}\pgf@circ@res@right
    \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@right}{\ctikzvalof{tubes/grid shift}\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@xa}{\ctikzvalof{tubes/grid shift}\pgf@circ@res@up}}
    % Grid dashes: calculations
    \pgf@xb=2\pgf@circ@res@right
    \pgf@circ@res@step=\ctikzvalof{tubes/tube radius}\pgf@xb
    \pgf@circ@count@a=\ctikzvalof{tubes/grid dashes}  % dashes*2+1
    \multiply\pgf@circ@count@a by 2\relax
    \advance\pgf@circ@count@a by 1\relax
    \advance\pgf@circ@res@step by -\pgf@xa
    \divide\pgf@circ@res@step by \pgf@circ@count@a
    % Grid dashes: draw
    \pgf@circ@res@temp=\pgf@xa
    \pgf@circ@count@a=\ctikzvalof{tubes/grid dashes}
    \loop
    \advance\pgf@circ@res@temp by\pgf@circ@res@step
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp}{\ctikzvalof{tubes/grid shift}\pgf@circ@res@up}}
    \advance\pgf@circ@res@temp by\pgf@circ@res@step
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@temp}{\ctikzvalof{tubes/grid shift}\pgf@circ@res@up}}
    \advance\pgf@circ@count@a by-1
    \ifnum\pgf@circ@count@a>0\relax
    \repeat
    \fi
}
{\pgfcirctubedraw@multi@anode}% anodes
{\pgfcirctubedraw@cathode@or@nixie}% cathode
{% extra dynamics anchors
    \pgfutil@g@addto@macro\pgf@sh@s@matube{%
        % Start with the maximum pin number and go backwards.
        \pgf@circ@count@a=\Nanodes\relax
        \pgfmathloop%
        \ifnum\pgf@circ@count@a>0
        \expandafter\xdef\csname pgf@anchor@matube@anode\space\the\pgf@circ@count@a\endcsname{%
            \noexpand\pgf@circ@ma@anode@anchor{\the\pgf@circ@count@a}%
        }
        \expandafter\xdef\csname pgf@anchor@matube@nixie\space k\the\pgf@circ@count@a\endcsname{%
            \noexpand\pgf@circ@ma@anode@anchor{\the\pgf@circ@count@a}%
        }
        \advance\pgf@circ@count@a by -1\relax%
        \repeatpgfmathloop%
    }%
}
\def\pgf@circ@ma@anode@anchor#1{
    \firstanodepos
    \pgf@circ@res@temp=\pgf@x
    \pgfmathsetlength\pgf@x{\pgf@circ@res@temp + (0.5 + 2*(#1 -1))*\anodelen}
}



%>>>

% vim: set fdm=marker fmr=%<<<,%>>>:
%%%---------- close: tex/pgfcirctripoles
%%%%%%%%%%% Springe nach tex/pgfcircquadpoles
%%%---------- open: tex/pgfcircquadpoles.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Quadripoles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Setting for Transformers and similar quadpoles%<<<1

\ctikzset{quadpoles/transformer/inner/.initial=0.4}
\ctikzset{quadpoles/transformer/width/.initial=1.5}
\ctikzset{quadpoles/transformer/width1/.initial=.4}
\ctikzset{quadpoles/transformer/height/.initial=1.5}
\ctikzset{quadpoles/transformer/height1/.initial=.8}
\ctikzset{quadpoles/transformer core/inner/.initial=0.4}
\ctikzset{quadpoles/transformer core/width/.initial=1.5}
\ctikzset{quadpoles/transformer core/height/.initial=1.5}
\ctikzset{quadpoles/transformer core/core height/.initial=.5}
\ctikzset{quadpoles/transformer core/core width/.initial=.05}
\ctikzset{transformer core/relative thickness/.initial=1}
\ctikzset{transformer core/color/.initial=default}
\ctikzset{transformer core/dash/.initial=default}
\ctikzset{quadpoles/gyrator/inner/.initial=0.4}
\ctikzset{quadpoles/gyrator/width/.initial=1.5}
\ctikzset{quadpoles/gyrator/height/.initial=1.5}
\ctikzset{quadpoles/fourport/width/.initial=1.3}
\ctikzset{quadpoles/fourport/height/.initial=1.3}
\ctikzset{quadpoles/coupler/width/.initial=1.3}
\ctikzset{quadpoles/coupler/height/.initial=1.3}
\ctikzset{quadpoles/coupler2/width/.initial=1.3}
\ctikzset{quadpoles/coupler2/height/.initial=1.3}
\ctikzset{quadpoles/double bipole/inner/.initial=0.4}
\ctikzset{quadpoles/double bipole/width/.initial=1.5}
\ctikzset{quadpoles/double bipole/width1/.initial=.4}
\ctikzset{quadpoles/double bipole/height/.initial=1.5}
\ctikzset{quadpoles/double bipole/height1/.initial=.8}

\ctikzset{quadpoles style/.is choice}
\ctikzset{quadpoles style/inward/.code={% default value
        \ctikzset{quadpoles/transformer/inner=0.4}%
        \ctikzset{quadpoles/transformer/width=1.5}%
        \ctikzset{quadpoles/transformer core/inner=0.4}%
        \ctikzset{quadpoles/transformer core/width=1.5}%
        \ctikzset{quadpoles/gyrator/inner=0.4}%
        \ctikzset{quadpoles/gyrator/width=1.5}%
        \ctikzset{quadpoles/double bipole/inner=0.4}%
        \ctikzset{quadpoles/double bipole/width=1.5}%
    }%
}
\ctikzset{quadpoles style/inline/.code={% now horizontal baffle
        \ctikzset{quadpoles/transformer/inner=1}%
        \ctikzset{quadpoles/transformer/width=0.6}%
        \ctikzset{quadpoles/transformer core/inner=1}%
        \ctikzset{quadpoles/transformer core/width=0.6}%
        \ctikzset{quadpoles/gyrator/inner=1} % FIXME
        \ctikzset{quadpoles/gyrator/width=0.6}%
        \ctikzset{quadpoles/double bipole/inner=1}%
        \ctikzset{quadpoles/double bipole/width=0.6}%
    }%
}
%%>>>

%% Node shapes for quadpoles (basically transformers)%<<<

\long\def\pgfcircdeclarequadpole#1#2#3{
    \pgfdeclareshape{#1}
    {
        \savedmacro{\ctikzclass}{\edef\ctikzclass{inductors}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        % shapename
        \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
        \savedmacro{\stretto}{\def\stretto{\ctikzvalof{quadpoles/#1/inner}}}
        \savedanchor\northwest{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@y=\ctikzvalof{quadpoles/#1/height}\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@x=.5\pgf@circ@scaled@Rlen
            \pgf@x=-\ctikzvalof{quadpoles/#1/width}\pgf@x
        }
        %% we define the upper right (positive coord) inner and outer dots (on the side of B1)
        \savedanchor{\innerdot}{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@xa=.5\pgf@circ@scaled@Rlen
            \pgf@xa=-\ctikzvalof{quadpoles/#1/width}\pgf@xa
            % by default use the cute inductor size
            \pgfmathsetlength\pgf@x{-\stretto*\pgf@xa-\ctikzvalof{bipoles/cuteinductor/height}*\pgf@circ@scaled@Rlen/2}
            % check if it's american
            \edef\pgf@circ@temp{\ctikzvalof{inductor}}
            \edef\pgf@temp{american}
            \ifx\pgf@circ@temp\pgf@temp
                \pgfmathsetlength\pgf@x{-\stretto*\pgf@xa-\ctikzvalof{bipoles/americaninductor/height}*\pgf@circ@scaled@Rlen/2}
            \fi
            % check if it's european
            \edef\pgf@temp{european}
            \ifx\pgf@circ@temp\pgf@temp
                \pgfmathsetlength\pgf@x{-\stretto*\pgf@xa-\ctikzvalof{bipoles/fullgeneric/height}*\pgf@circ@scaled@Rlen/2}
            \fi
            \pgfmathsetlength\pgf@y{0.5*\pgf@circ@scaled@Rlen}
        }
        \savedanchor{\outerdot}{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@xa=.5\pgf@circ@scaled@Rlen
            \pgf@xa=-\ctikzvalof{quadpoles/#1/width}\pgf@xa
            % by default use the cute inductor size
            \pgfmathsetlength\pgf@x{-\stretto*\pgf@xa+\ctikzvalof{bipoles/cuteinductor/height}*\pgf@circ@scaled@Rlen/2}
            % check if it's american
            \edef\pgf@circ@temp{\ctikzvalof{inductor}}
            \edef\pgf@temp{american}
            \ifx\pgf@circ@temp\pgf@temp
                \pgfmathsetlength\pgf@x{-\stretto*\pgf@xa+\ctikzvalof{bipoles/americaninductor/height}*\pgf@circ@scaled@Rlen/2}
            \fi
            % check if it's european
            \edef\pgf@temp{european}
            \ifx\pgf@circ@temp\pgf@temp
                \pgfmathsetlength\pgf@x{-\stretto*\pgf@xa+\ctikzvalof{bipoles/fullgeneric/height}*\pgf@circ@scaled@Rlen/2}
            \fi
            \pgfmathsetlength\pgf@y{0.5*\pgf@circ@scaled@Rlen}
        }
        % geographical
        \anchor{center}{\northwest\pgf@x=0pt\pgf@y=0pt}
        \pgfcirc@northwest@symmetric@geoanchors
        \anchor{base}{\northwest\pgf@x=0pt}
        % external wires
        \anchor{A2}{\northwest\pgf@y=-\pgf@y}
        \anchor{B1}{\northwest\pgf@x=-\pgf@x}
        \anchor{A1}{\northwest}
        \anchor{B2}{\northwest\pgf@x=-\pgf@x \pgf@y=-\pgf@y}
        %% dot's anchors
        \anchor{inner dot A1}{\innerdot\pgf@x=-\pgf@x}
        \anchor{outer dot A1}{\outerdot\pgf@x=-\pgf@x}
        \anchor{inner dot A2}{\innerdot\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
        \anchor{outer dot A2}{\outerdot\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
        \anchor{inner dot B1}{\innerdot}
        \anchor{outer dot B1}{\outerdot}
        \anchor{inner dot B2}{\innerdot\pgf@y=-\pgf@y}
        \anchor{outer dot B2}{\outerdot\pgf@y=-\pgf@y}
        % text above
        \anchor{text}{
            \northwest
            \pgf@x=\dimexpr -.5\wd\pgfnodeparttextbox\relax
            \advance\pgf@y by .6\ht\pgfnodeparttextbox\relax
        }
        #3%
        \pgf@circ@draw@component{
            \pgf@circ@setcolor

            \northwest
            \pgf@circ@res@up = \pgf@y
            \pgf@circ@res@down = -\pgf@y
            \pgf@circ@res@right = -\pgf@x
            \pgf@circ@res@left = \pgf@x
            #2%
        }
    }
}


% these are deprecated anchors (really I do not know what they are --- Romano.)
% They are here for compatibility, I suppose. Don't use.
\def\pgf@circ@drawtransformerbasicanchor{
    % \ctikzvalof{quadpoles/trans/height}
    \anchor{AA2}{
        \northwest
        \pgf@x=\ctikzvalof{quadpoles/transformer/width1}\pgf@x
        \pgf@x=.7\pgf@x
        \pgf@y=-\pgf@y
        \pgf@y=\ctikzvalof{quadpoles/transformer/height1}\pgf@y
    }
    \anchor{BB1}{
        \northwest
        \pgf@x=-\pgf@x
        \pgf@x=\ctikzvalof{quadpoles/transformer/width1}\pgf@x
        \pgf@x=.7\pgf@x
        \pgf@y=\ctikzvalof{quadpoles/transformer/height1}\pgf@y
    }
    \anchor{AA1}{
        \northwest
        \pgf@x=\ctikzvalof{quadpoles/transformer/width1}\pgf@x
        \pgf@x=.7\pgf@x
        \pgf@y=\ctikzvalof{quadpoles/transformer/height1}\pgf@y
    }
    \anchor{BB2}{
        \northwest
        \pgf@x=-\pgf@x
        \pgf@x=\ctikzvalof{quadpoles/transformer/width1}\pgf@x
        \pgf@x=.7\pgf@x
        \pgf@y=-\pgf@y
        \pgf@y=\ctikzvalof{quadpoles/transformer/height1}\pgf@y
    }
}

%% Null styles that can be used to change individually the L1 and L2
%% inductors of the transformer.

\ctikzset{transformer L1/.style={}}
\ctikzset{transformer L2/.style={}}

\def\pgf@circ@drawtransformerbasicbody{
    \pgfscope
        \pgfslopedattimetrue
        \pgfallowupsidedownattimetrue
        \pgftransformlineattime{.5}{%
            \pgfpoint%
            {\stretto\pgf@circ@res@left}%
            {\pgf@circ@res@up}%
            }{%
            \pgfpoint
            {\stretto\pgf@circ@res@left}%
            {\pgf@circ@res@down}%
        }

        \pgfkeys{\circuitikzbasekey/.cd, transformer L1}
        \edef\pgf@circ@temp{\ctikzvalof{inductor}}%
        \def\pgf@temp{european}%
        \ifx\pgf@temp\pgf@circ@temp%
            \pgfnode{fullgenericshape}{center}{}{\thisshape-L1}{\pgfusepath{stroke}}
        \else%
            \def\pgf@temp{cute}
            \ifx\pgf@temp\pgf@circ@temp%
                \pgfnode{cuteinductorshape}{center}{}{\thisshape-L1}{\pgfusepath{stroke}}
            \else%
                \pgfnode{americaninductorshape}{center}{}{\thisshape-L1}{\pgfusepath{stroke}}
            \fi%
        \fi%


    \endpgfscope
    \pgfscope
        \pgfslopedattimetrue
        \pgfallowupsidedownattimetrue
        \pgftransformlineattime{.5}{%
            \pgfpoint%
            {\stretto\pgf@circ@res@right}%
            {\pgf@circ@res@down}%
            }{%
            \pgfpoint
            {\stretto\pgf@circ@res@right}%
            {\pgf@circ@res@up}%
        }

        \pgfkeys{\circuitikzbasekey/.cd, transformer L2}
        \edef\pgf@circ@temp{\ctikzvalof{inductor}}%
        \def\pgf@temp{european}%
        \ifx\pgf@temp\pgf@circ@temp%
            \pgfnode{fullgenericshape}{center}{}{\thisshape-L2}{\pgfusepath{stroke}}
        \else%
            \def\pgf@temp{cute}
            \ifx\pgf@temp\pgf@circ@temp%
                \pgfnode{cuteinductorshape}{center}{}{\thisshape-L2}{\pgfusepath{stroke}}
            \else%
                \pgfnode{americaninductorshape}{center}{}{\thisshape-L2}{\pgfusepath{stroke}}
            \fi%
        \fi%

    \endpgfscope

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\stretto\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpointanchor{\thisshape-L1}{b}}

    \pgfpathmoveto{\pgfpointanchor{\thisshape-L1}{a}}
    \pgfpathlineto{\pgfpoint{\stretto\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\stretto\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpointanchor{\thisshape-L2}{a}}

    \pgfpathmoveto{\pgfpointanchor{\thisshape-L2}{b}}
    \pgfpathlineto{\pgfpoint{\stretto\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}

    \pgfusepath{draw}

}


\pgfcircdeclarequadpole{transformer}{
    \pgf@circ@drawtransformerbasicbody
}{\pgf@circ@drawtransformerbasicanchor}

\pgfcircdeclarequadpole{transformer core}{

    \pgf@circ@drawtransformerbasicbody

    % use the chocke line thickness
    \pgfsetlinewidth{\ctikzvalof{bipoles/cutechoke/cthick}*\ctikzvalof{transformer core/relative thickness}*\pgflinewidth}
    \pgf@circ@subset@color@dash{transformer core}

    % Find the distance from center for the lines representing the core
    % the 2.5 is for backward compatibility --- the distance was calculated as a fraction
    % of the whole component, now as a fraction of the distance between coils, to be
    % compatible with the quadpoles "inner" style.
    \pgfmathsetlength{\pgf@circ@res@other}{2.5*\stretto*\ctikzvalof{quadpoles/transformer core/core width}*\pgf@circ@res@right}

    \pgfpathmoveto{\pgfpoint%
        {\pgf@circ@res@other}%
        {\ctikzvalof{quadpoles/transformer core/core height}\pgf@circ@res@down}%
    }
    \pgfpathlineto{
        \pgfpoint%
        {\pgf@circ@res@other}%
        {\ctikzvalof{quadpoles/transformer core/core height}\pgf@circ@res@up}%
    }

    %% this should be just -\pgf@circ@res@other, but in case someone define an asymmetric trafo someday...
    \pgfmathsetlength{\pgf@circ@res@other}{2.5*\stretto*\ctikzvalof{quadpoles/transformer core/core width}*\pgf@circ@res@left}
    \pgfpathmoveto{\pgfpoint%
        {\pgf@circ@res@other}%
        {\ctikzvalof{quadpoles/transformer core/core height}\pgf@circ@res@down}%
    }
    \pgfpathlineto{
        \pgfpoint%
        {\pgf@circ@res@other}%
        {\ctikzvalof{quadpoles/transformer core/core height}\pgf@circ@res@up}%
    }

    \pgf@circ@setlinewidth{bipoles}{\pgflinewidth}
    \pgfusepath{draw}
}{\pgf@circ@drawtransformerbasicanchor}


\pgfcircdeclarequadpole{gyrator}{

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\stretto\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\stretto\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\stretto\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\stretto\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}

    \pgfusepath{draw}

    \pgf@circ@setlinewidth{quadpoles}{\pgflinewidth}
    \pgfmathsetlength{\pgf@circ@res@other}{min(.7*\stretto*\pgf@circ@res@up, .8*\pgf@circ@res@right)} % radius
    \pgfpathmoveto{\pgfpoint{\stretto\pgf@circ@res@left}{-\pgf@circ@res@other}}
    \pgfpatharc{-90}{90}{\pgf@circ@res@other}
    \pgfpathclose
    \pgf@circ@draworfill

    \pgfpathmoveto{\pgfpoint{\stretto\pgf@circ@res@right}{\pgf@circ@res@other}}
    \pgfpatharc{90}{270}{\pgf@circ@res@other}
    \pgfpathclose
    \pgf@circ@draworfill
}{}
% %>>>

% Node shapes for generic double bipoles %<<<
%
\long\def\pgfcircdeclaredbipole#1#2#3{
    \pgfdeclareshape{#1}
    {
        \savedmacro{\ctikzclass}{\edef\ctikzclass{misc}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        % shapename
        \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
        \savedmacro{\stretto}{\def\stretto{\ctikzvalof{quadpoles/#1/inner}}}
        \savedanchor\northwest{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@y=\ctikzvalof{quadpoles/#1/height}\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@x=.5\pgf@circ@scaled@Rlen
            \pgf@x=-\ctikzvalof{quadpoles/#1/width}\pgf@x
        }
        %% we define the upper right (positive coord) inner and outer dot (near B1)
        %% in the generic case, we just place the dot position in a fixed spot
        %% we do not know the width of the component there...
        \savedanchor{\innerdot}{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@xa=.5\pgf@circ@scaled@Rlen
            \pgf@xa=-\ctikzvalof{quadpoles/#1/width}\pgf@xa
            \pgfmathsetlength\pgf@x{-0.5*\stretto*\pgf@xa}
            \pgfmathsetlength\pgf@y{0.5*\pgf@circ@scaled@Rlen}
        }
        \savedanchor{\outerdot}{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@xa=.5\pgf@circ@scaled@Rlen
            \pgf@xa=-\ctikzvalof{quadpoles/#1/width}\pgf@xa
            \pgfmathsetlength\pgf@x{-1.5*\stretto*\pgf@xa}
            \pgfmathsetlength\pgf@y{0.5*\pgf@circ@scaled@Rlen}
        }
        % geographical
        \anchor{center}{\northwest\pgf@x=0pt\pgf@y=0pt}
        \pgfcirc@northwest@symmetric@geoanchors
        \anchor{base}{\northwest\pgf@x=0pt}
        % external wires
        \anchor{A2}{\northwest\pgf@y=-\pgf@y}
        \anchor{B1}{\northwest\pgf@x=-\pgf@x}
        \anchor{A1}{\northwest}
        \anchor{B2}{\northwest\pgf@x=-\pgf@x \pgf@y=-\pgf@y}
        %% dot's anchors
        \anchor{inner dot A1}{\innerdot\pgf@x=-\pgf@x}
        \anchor{outer dot A1}{\outerdot\pgf@x=-\pgf@x}
        \anchor{inner dot A2}{\innerdot\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
        \anchor{outer dot A2}{\outerdot\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
        \anchor{inner dot B1}{\innerdot}
        \anchor{outer dot B1}{\outerdot}
        \anchor{inner dot B2}{\innerdot\pgf@y=-\pgf@y}
        \anchor{outer dot B2}{\outerdot\pgf@y=-\pgf@y}
        % text above
        \anchor{text}{
            \northwest
            \pgf@x=\dimexpr -.5\wd\pgfnodeparttextbox\relax
            \advance\pgf@y by .6\ht\pgfnodeparttextbox\relax
        }
        #3%
        \pgf@circ@draw@component{
            \pgf@circ@setcolor
            \northwest
            \pgf@circ@res@up = \pgf@y
            \pgf@circ@res@down = -\pgf@y
            \pgf@circ@res@right = -\pgf@x
            \pgf@circ@res@left = \pgf@x
            #2%
        }
    }
}

\ctikzset{every double bipole L/.style={}}
\ctikzset{every double bipole R/.style={}}
\ctikzset{double bipole L/.initial=genericshape}
\ctikzset{double bipole R/.initial=vsourceAMshape}
\newif\ifpgf@circ@dbipoleL@invert\pgf@circ@dbipoleL@invertfalse
\newif\ifpgf@circ@dbipoleR@invert\pgf@circ@dbipoleR@invertfalse
\ctikzset{double bipole L invert/.is if=pgf@circ@dbipoleL@invert}
\ctikzset{double bipole R invert/.is if=pgf@circ@dbipoleR@invert}

\def\pgf@circ@drawdbipolebasicbody{
    \pgfscope
        \ifpgf@circ@dbipoleL@invert
            \pgf@circ@res@temp=\pgf@circ@res@down
            \pgf@circ@res@other=\pgf@circ@res@up
        \else
            \pgf@circ@res@temp=\pgf@circ@res@up
            \pgf@circ@res@other=\pgf@circ@res@down
        \fi
        \pgfslopedattimetrue
        \pgfallowupsidedownattimetrue
        \pgftransformlineattime{.5}{%
            \pgfpoint%
            {\stretto\pgf@circ@res@left}%
            {\pgf@circ@res@temp}%
        }{%
            \pgfpoint
            {\stretto\pgf@circ@res@left}%
            {\pgf@circ@res@other}%
        }
        \pgfkeys{\circuitikzbasekey/.cd,  every double bipole L}
        \edef\pgf@circ@temp{\ctikzvalof{double bipole L}}%
        \pgfnode{\pgf@circ@temp}{center}{}{\thisshape-L}{\pgfusepath{stroke}}
    \endpgfscope
    \pgfscope
        \ifpgf@circ@dbipoleR@invert
            \pgf@circ@res@temp=\pgf@circ@res@down
            \pgf@circ@res@other=\pgf@circ@res@up
        \else
            \pgf@circ@res@temp=\pgf@circ@res@up
            \pgf@circ@res@other=\pgf@circ@res@down
        \fi
        \pgfslopedattimetrue
        \pgfallowupsidedownattimetrue
        \pgftransformlineattime{.5}{%
            \pgfpoint%
            {\stretto\pgf@circ@res@right}%
            {\pgf@circ@res@other}%
        }{%
            \pgfpoint
            {\stretto\pgf@circ@res@right}%
            {\pgf@circ@res@temp}%
        }
        %
        \pgfkeys{\circuitikzbasekey/.cd, every double bipole R}
        \edef\pgf@circ@temp{\ctikzvalof{double bipole R}}%
        \pgfnode{\pgf@circ@temp}{center}{}{\thisshape-R}{\pgfusepath{stroke}}
    \endpgfscope
    %
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\stretto\pgf@circ@res@left}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpointanchor{\thisshape-L}{\ifpgf@circ@dbipoleL@invert a\else b\fi}}
    %
    \pgfpathmoveto{\pgfpointanchor{\thisshape-L}{\ifpgf@circ@dbipoleL@invert b\else a\fi}}
    \pgfpathlineto{\pgfpoint{\stretto\pgf@circ@res@left}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
    %
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\stretto\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpointanchor{\thisshape-R}{\ifpgf@circ@dbipoleR@invert b\else a\fi}}
    %
    \pgfpathmoveto{\pgfpointanchor{\thisshape-R}{\ifpgf@circ@dbipoleR@invert a\else b\fi}}
    \pgfpathlineto{\pgfpoint{\stretto\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
    \pgfusepath{draw}
}
\pgfcircdeclaredbipole{double bipole}{
    \pgf@circ@drawdbipolebasicbody
}{}


% %>>>

%%%%%%%%%%%%%%%%%%%
%% Block diagrams
%%%%%%%%%%%%%%%%%%%

% Definitions and options for blocks (twoports and so)%<<<1

\ctikzset{bipoles/twoport/width/.initial=.7}
\ctikzset{bipoles/twoport/height/.initial=.7}
\ctikzset{bipoles/twoport/text/.initial=}
\ctikzset{bipoles/twoportsplit/width/.initial=.7}
\ctikzset{bipoles/twoportsplit/height/.initial=.7}
\ctikzset{bipoles/twoport/text in/.initial=}
\ctikzset{bipoles/twoport/text out/.initial=}
\ctikzset{text/.style={t=#1}}
\ctikzset{t/.code={%
        \ctikzsetvalof{bipoles/twoport/text}{#1}%
}}
\ctikzset{text in/.style={t1=#1}}
\ctikzset{t1/.code={%
        \ctikzsetvalof{bipoles/twoport/text in}{#1}%
}}
\ctikzset{text out/.style={t2=#1}}
\ctikzset{t2/.code={%
        \ctikzsetvalof{bipoles/twoport/text out}{#1}%
}}
\ctikzset{bipoles/vco/width/.initial=.7}
\ctikzset{bipoles/bandpass/width/.initial=.7}
\ctikzset{bipoles/bandstop/width/.initial=.7}
\ctikzset{bipoles/highpass/width/.initial=.7}
\ctikzset{bipoles/highpass2/width/.initial=.7}
\ctikzset{bipoles/lowpass/width/.initial=.7}
\ctikzset{bipoles/lowpass2/width/.initial=.7}
\ctikzset{bipoles/allpass/width/.initial=.7}
\ctikzset{bipoles/adc/width/.initial=.7}
\ctikzset{bipoles/dac/width/.initial=.7}
\ctikzset{bipoles/dsp/width/.initial=.7}
\ctikzset{bipoles/fft/width/.initial=.7}
\ctikzset{bipoles/amp/width/.initial=.7}
\ctikzset{bipoles/iamp/width/.initial=.7}
\ctikzset{bipoles/vamp/width/.initial=.7}
\ctikzset{bipoles/piattenuator/width/.initial=.7}
\ctikzset{bipoles/vpiattenuator/width/.initial=.7}
\ctikzset{bipoles/tattenuator/width/.initial=.7}
\ctikzset{bipoles/vtattenuator/width/.initial=.7}
\ctikzset{bipoles/phaseshifter/width/.initial=.7}
\ctikzset{bipoles/vphaseshifter/width/.initial=.7}
\ctikzset{bipoles/detector/width/.initial=.7}
\ctikzset{bipoles/saturation/width/.initial=.7}
\ctikzset{bipoles/sigmoid/width/.initial=.7}
\ctikzset{bipoles/allornothing/width/.initial=.7}
\ctikzset{tripoles/mixer/width/.initial=0.7}
\ctikzset{tripoles/adder/width/.initial=0.7}
\ctikzset{tripoles/circulator/width/.initial=.7}
\ctikzset{tripoles/oscillator/width/.initial=.7}
\ctikzset{bipoles/fiber/width/.initial=.7}

\ctikzset{tripoles/wilkinson/height/.initial=1.3}
\ctikzset{tripoles/wilkinson/width/.initial=1.3}

\ctikzset{tripoles/splitter/height/.initial=1.3}
\ctikzset{tripoles/splitter/width/.initial=1.3}

\ctikzset{tripoles/genericsplitter/height/.initial=1.3}
\ctikzset{tripoles/genericsplitter/width/.initial=1.3}

\ctikzset{tripoles/mzm/height/.initial=1.3}
\ctikzset{tripoles/mzm/width/.initial=1.3}

% Option ">" for twoports
\newif\ifpgf@circuit@inputarrow
\ctikzset{>/.add code={}{\pgf@circuit@inputarrowtrue}}
\ctikzset{inputarrow/.is choice}
\ctikzset{inputarrow/true/.code={\pgf@circuit@inputarrowtrue}}
\ctikzset{inputarrow/false/.code={\pgf@circuit@inputarrowfalse}}

% Option "boxed" for nodes and twoports
\newif\ifpgf@circuit@boxed
\newif\ifpgf@circuit@boxedcircled\pgf@circuit@boxedcircledtrue
\pgfkeys{/tikz/boxed/.add code={}{\pgf@circuit@boxedtrue\pgf@circuit@boxedcircledtrue}}
\ctikzset{boxed/.add code={}{\pgf@circuit@boxedtrue\pgf@circuit@boxedcircledtrue}}
\pgfkeys{/tikz/box/.add code={}{\pgf@circuit@boxedtrue\pgf@circuit@boxedcircledtrue}}
\ctikzset{box/.add code={}{\pgf@circuit@boxedtrue\pgf@circuit@boxedcircledtrue}}
% boxed, no circle
\pgfkeys{/tikz/boxed only/.add code={}{\pgf@circuit@boxedtrue\pgf@circuit@boxedcircledfalse}}
\ctikzset{boxed only/.add code={}{\pgf@circuit@boxedtrue\pgf@circuit@boxedcircledfalse}}
\pgfkeys{/tikz/box only/.add code={}{\pgf@circuit@boxedtrue\pgf@circuit@boxedcircledfalse}}
\ctikzset{box only/.add code={}{\pgf@circuit@boxedtrue\pgf@circuit@boxedcircledfalse}}

% Option "dashed" for nodes and twoports
\newif\ifpgf@circuit@dashed
\pgfkeys{/tikz/dashed/.add code={}{\pgf@circuit@dashedtrue}}
\ctikzset{dashed/.add code={}{\pgf@circuit@dashedtrue}}%
% Also draw internal things dashed
\newif\ifpgf@circuit@full@dashed
\ctikzset{inner blocks dashed/.is if=pgf@circuit@full@dashed}%
% Default block dash
\ctikzset{dashed blocks pattern/.initial={{0.1cm}{0.1cm}}}
%
% powerelectronic blocks
\ctikzset{bipoles/sacdc/width/.initial=.7}
\ctikzset{bipoles/sdcac/width/.initial=.7}
\ctikzset{bipoles/sdcdc/width/.initial=.7}
\ctikzset{bipoles/tacdc/width/.initial=.7}
\ctikzset{bipoles/tdcac/width/.initial=.7}
\ctikzset{quadpoles/gridnode/width/.initial=.7} %not sure if quadpole?

%>>>

%% Node shapes definition for path-style block diagrams%<<<

%% Draw the two-port fillable box
\def\pgf@circ@twoportbox{%
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}%
        \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}%
        \pgf@circ@draworfill
    \endpgfscope
}
\def\pgf@circ@inputarrow{%
    \ifpgf@circuit@inputarrow
        {%
            % Remove this: the line will overrun the tip, resulting in bad look. See issue #613, thanks to Laurenz Preindl
            % \advance \pgf@circ@res@left by -.5\ctikzvalof{bipoles/thickness}\pgfstartlinewidth
            \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}%
            \pgfnode{inputarrow}{tip}{}{pgf@inputarrow}{\pgfusepath{fill}}%
        }%
    \fi
}
%%% blocks additional anchors
\ctikzset{block left anchors pos/.initial=0.5}
\ctikzset{block right anchors pos/.initial=0.5}
\ctikzset{block lateral anchors pos/.code={
    \ctikzset{block left anchors pos=#1}%
    \ctikzset{block right anchors pos=#1}%
}}
\def\pgcirc@twoport@additional@anchors{%
    \savedmacro{\blockleftanchorpos}{\edef\blockleftanchorpos{\ctikzvalof{block left anchors pos}}}
    \savedmacro{\blockrightanchorpos}{\edef\blockrightanchorpos{\ctikzvalof{block right anchors pos}}}
    \anchor{right down}{\northeast\pgf@y=-\blockrightanchorpos\pgf@y}
    \anchor{left down}{\northeast\pgf@x=-\pgf@x\pgf@y=-\blockleftanchorpos\pgf@y}
    \anchor{left up}{\northeast\pgf@x=-\pgf@x\pgf@y=\blockleftanchorpos\pgf@y}
    \anchor{right up}{\northeast\pgf@y=\blockrightanchorpos\pgf@y}
    \anchor{up}{\northeast\pgf@x=0pt\relax}
    \anchor{down}{\northeast\pgf@y=-\pgf@y\pgf@x=0pt\relax}
}

%%% definition to help define the blocks. Notice that the height, width, etc are different, so we can't
%%% simplify more...
\def\pfgcirc@twoport@get@symbol@rotation{
    %%% put the needed rotation in \@@rotation
    \def\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@direction\pgf@nil}
    \def\@@rotation{0}
    \ifnum \pgfcircmathresult > 45 \ifnum \pgfcircmathresult < 135
        \def\@@rotation{270}
    \fi\fi
    \ifnum \pgfcircmathresult > 134 \ifnum \pgfcircmathresult < 225
        \def\@@rotation{180}
    \fi\fi
    \ifnum \pgfcircmathresult > 224 \ifnum \pgfcircmathresult < 315
        \def\@@rotation{90}
    \fi\fi
}
%
\def\pfgcirc@twoport@rotate@inner@symbol{%
    % rotate inner symbol
    \pfgcirc@twoport@get@symbol@rotation
    \pgftransformrotate{\@@rotation}
}
% enact dashing if needed
\def\pgfcirc@twoport@maybedash{%
    \ifpgf@circuit@dashed
    \edef\@@tmp{\ctikzvalof{dashed blocks pattern}}
    \expandafter\pgfsetdash\expandafter{\@@tmp}{0cm}
    \fi
}
% debug
\def\@@printrot{%
    \pgfsetcolor{red}
    \pgftext[center,x=0,y=0,]{\tiny\ttfamily\pgf@circ@direction > \@@rotation}
}
%
\def\pgfcirc@twoport@setup#1{%
    \pgf@circ@res@step = #1\pgf@circ@scaled@Rlen%6 is the real width parameter
    \divide \pgf@circ@res@step by 2
    \pgfsetdash{}{0pt}	% always draw solid line for inner symbol
    \pgfsetarrows{-}
    % let set the dash for the next operations
    \pgfcirc@twoport@maybedash
}
%
\def\pgfcirc@twoport@draw@sine#1#2{% #1 -> y shift; #2 -> crossed out if != 0
    % draw inner sine waves; ...res@step must be defined
    \pgfscope
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgftransformyshift{#1\pgf@circ@res@step}
        \pgfpathmoveto{\pgfpoint{-.5\pgf@circ@res@step}{0\pgf@circ@res@step}}
        \pgfpathsine{\pgfpoint{.25\pgf@circ@res@step}{.25\pgf@circ@res@step}}
        \pgfpathcosine{\pgfpoint{.25\pgf@circ@res@step}{-.25\pgf@circ@res@step}}
        \pgfpathsine{\pgfpoint{.25\pgf@circ@res@step}{-.25\pgf@circ@res@step}}
        \pgfpathcosine{\pgfpoint{.25\pgf@circ@res@step}{.25\pgf@circ@res@step}}
        \ifnum #2=0\else
            \pgfpathmoveto{\pgfpoint{0.15\pgf@circ@res@step}{0.15\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpoint{-0.15\pgf@circ@res@step}{-0.15\pgf@circ@res@step}}
        \fi
        \pgfusepath{draw}
    \endpgfscope
}
%
\def\pgfcirc@twoport@draw@splitline{%
    \pgfscope
        \pgfcirc@twoport@maybedash
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
        \pgfusepath{draw}
    \endpgfscope
}
%
\long\def\pgfcirc@define@twoports#1#2#3#4#5#6#7{
\pgfcircdeclarebipolescaled{#1}
    {
        \pgcirc@twoport@additional@anchors
        #2
    }
    {#3}
    {#4}
    {#5}
    {#6}
    {
        \pgfcirc@twoport@setup{#6}
        % draw outer box
        \pgf@circ@twoportbox
        % draw solid line for inner symbol if no box is drawn and not fully dashed
        \ifpgf@circuit@full@dashed\else\pgfsetdash{}{0pt}\fi
        \pgf@circ@inputarrow
        \pfgcirc@twoport@rotate@inner@symbol
        #7
    }
}
%
\long\def\pgfcirc@define@twoports@norotate#1#2#3#4#5#6#7{
\pgfcircdeclarebipolescaled{#1}
    {
        \pgcirc@twoport@additional@anchors
        #2
    }
    {#3}
    {#4}
    {#5}
    {#6}
    {
        \pgfcirc@twoport@setup{#6}
        % draw outer box
        \pgf@circ@twoportbox
        % draw solid line for inner symbol if no box is drawn and not fully dashed
        \ifpgf@circuit@full@dashed\else\pgfsetdash{}{0pt}\fi
        \pgf@circ@inputarrow
        #7
    }
}
%% Generic two port box
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/twoport/height}}
{twoport}
{\ctikzvalof{bipoles/twoport/height}}
{\ctikzvalof{bipoles/twoport/width}}
{
    % draw inner symbol
    \pgf@circ@text@strokecolor
    \pgftext[center,x=0,y=0]{\ctikzvalof{bipoles/twoport/text}}

}
%% twoport split
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/twoportsplit/height}}
{twoportsplit}
{\ctikzvalof{bipoles/twoportsplit/height}}
{\ctikzvalof{bipoles/twoportsplit/width}}
{
    %get texts
    \def\pgfcirc@tin{\ctikzvalof{bipoles/twoport/text in}}
    \def\pgfcirc@tout{\ctikzvalof{bipoles/twoport/text out}}
    % shuffle text depending on rotation
    \pgfcirc@twoport@draw@splitline
    %
    \pgf@circ@text@strokecolor
    \ifnum\@@rotation<145
        \pgftext[center,x=0.45\pgf@circ@res@left,y=0.45\pgf@circ@res@up]{\pgfcirc@tin}
        \pgftext[center,x=0.45\pgf@circ@res@right,y=0.45\pgf@circ@res@down]{\pgfcirc@tout}
    \else
        \pgftext[center,x=0.45\pgf@circ@res@left,y=0.45\pgf@circ@res@up]{\pgfcirc@tout}
        \pgftext[center,x=0.45\pgf@circ@res@right,y=0.45\pgf@circ@res@down]{\pgfcirc@tin}
    \fi
}
%% bandpass filter
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/bandpass/width}}
{bandpass}
{\ctikzvalof{bipoles/bandpass/width}}
{\ctikzvalof{bipoles/bandpass/width}}
{
    \pgfcirc@twoport@draw@sine{0.5}{1}
    \pgfcirc@twoport@draw@sine{0.0}{0}
    \pgfcirc@twoport@draw@sine{-0.5}{1}
}
%% bandstop filter
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/bandstop/width}}
{bandstop}
{\ctikzvalof{bipoles/bandstop/width}}
{\ctikzvalof{bipoles/bandstop/width}}
{
    \pgfcirc@twoport@draw@sine{0.5}{0}
    \pgfcirc@twoport@draw@sine{0.0}{1}
    \pgfcirc@twoport@draw@sine{-0.5}{0}
}
%% highpass filter
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/highpass/width}}
{highpass}
{\ctikzvalof{bipoles/highpass/width}}
{\ctikzvalof{bipoles/highpass/width}}
{
    \pgfcirc@twoport@draw@sine{0.5}{0}
    \pgfcirc@twoport@draw@sine{0.0}{1}
    \pgfcirc@twoport@draw@sine{-0.5}{1}
}
%% highpass2 filter ---simplyfied with just two waves
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/highpass2/width}}
{highpass2}
{\ctikzvalof{bipoles/highpass2/width}}
{\ctikzvalof{bipoles/highpass2/width}}
{
    \pgfcirc@twoport@draw@sine{0.25}{0}
    \pgfcirc@twoport@draw@sine{-0.25}{1}
}
%% lowpass filter
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/lowpass/width}}
{lowpass}
{\ctikzvalof{bipoles/lowpass/width}}
{\ctikzvalof{bipoles/lowpass/width}}
{
    \pgfcirc@twoport@draw@sine{0.5}{1}
    \pgfcirc@twoport@draw@sine{0.0}{1}
    \pgfcirc@twoport@draw@sine{-0.5}{0}
}
%% lowpass2 filter: simplyfied with just two waves
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/lowpass2/width}}
{lowpass2}
{\ctikzvalof{bipoles/lowpass2/width}}
{\ctikzvalof{bipoles/lowpass2/width}}
{
    \pgfcirc@twoport@draw@sine{0.25}{1}
    \pgfcirc@twoport@draw@sine{-0.25}{0}
}
%% allpass filter
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/allpass/width}}
{allpass}
{\ctikzvalof{bipoles/allpass/width}}
{\ctikzvalof{bipoles/allpass/width}}
{
    \pgfcirc@twoport@draw@sine{0.5}{0}
    \pgfcirc@twoport@draw@sine{0.0}{0}
    \pgfcirc@twoport@draw@sine{-0.5}{0}
}
%% ADC
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/adc/width}}
{adc}
{\ctikzvalof{bipoles/adc/width}}
{\ctikzvalof{bipoles/adc/width}}
{
    \pgfcirc@twoport@draw@splitline
    %
    \pgf@circ@text@strokecolor
    \ifnum\@@rotation<145
        \pgftext[center,x=0.45\pgf@circ@res@left,y=0.45\pgf@circ@res@up]{A}
        \pgftext[center,x=0.45\pgf@circ@res@right,y=0.45\pgf@circ@res@down]{D}
    \else
        \pgftext[center,x=0.45\pgf@circ@res@left,y=0.45\pgf@circ@res@up]{D}
        \pgftext[center,x=0.45\pgf@circ@res@right,y=0.45\pgf@circ@res@down]{A}
    \fi
}

%% DAC
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/dac/width}}
{dac}
{\ctikzvalof{bipoles/dac/width}}
{\ctikzvalof{bipoles/dac/width}}
{
    \pgfcirc@twoport@draw@splitline
    %
    \pgf@circ@text@strokecolor
    \ifnum\@@rotation<145
        \pgftext[center,x=0.45\pgf@circ@res@left,y=0.45\pgf@circ@res@up]{D}
        \pgftext[center,x=0.45\pgf@circ@res@right,y=0.45\pgf@circ@res@down]{A}
    \else
        \pgftext[center,x=0.45\pgf@circ@res@left,y=0.45\pgf@circ@res@up]{A}
        \pgftext[center,x=0.45\pgf@circ@res@right,y=0.45\pgf@circ@res@down]{D}
    \fi
}

%% DSP
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/dsp/width}}
{dsp}
{\ctikzvalof{bipoles/dsp/width}}
{\ctikzvalof{bipoles/dsp/width}}
{
    \pgf@circ@text@strokecolor
    \pgftext[center,x=0,y=0]{\textsf{DSP}}
}
%% FFT
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/fft/width}}
{fft}
{\ctikzvalof{bipoles/fft/width}}
{\ctikzvalof{bipoles/fft/width}}
{
    \pgf@circ@text@strokecolor
    \pgftext[center,x=0,y=0]{\textsf{FFT}}
}
%% pi attenuator
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/piattenuator/width}}
{piattenuator}
{\ctikzvalof{bipoles/piattenuator/width}}
{\ctikzvalof{bipoles/piattenuator/width}}
{
    % draw inner symbol
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{0.4\pgf@circ@res@left}{0.4\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.4\pgf@circ@res@left}{0.4\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{0.4\pgf@circ@res@right}{0.4\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.4\pgf@circ@res@right}{0.4\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{0.6\pgf@circ@res@left}{0.4\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.6\pgf@circ@res@right}{0.4\pgf@circ@res@up}}
    \pgfusepath{draw}
}
%% variable pi attenuator
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/vpiattenuator/width}}
{vpiattenuator}
{\ctikzvalof{bipoles/vpiattenuator/width}}
{\ctikzvalof{bipoles/vpiattenuator/width}}
{
    % draw inner symbol
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{0.4\pgf@circ@res@left}{0.4\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.4\pgf@circ@res@left}{0.4\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{0.4\pgf@circ@res@right}{0.4\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.4\pgf@circ@res@right}{0.4\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{0.6\pgf@circ@res@left}{0.4\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.6\pgf@circ@res@right}{0.4\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfcirc@set@arrows{tunable}{}{latex}
    \pgfpathmoveto{\pgfpoint{0.7\pgf@circ@res@left}{0.5\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.7\pgf@circ@res@right}{0.8\pgf@circ@res@up}}
    \pgfusepath{draw}
}
%% T attenuator
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/tattenuator/width}}
{tattenuator}
{\ctikzvalof{bipoles/tattenuator/width}}
{\ctikzvalof{bipoles/tattenuator/width}}
{
    % draw inner symbol
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{0pt}{0.4\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0pt}{0.4\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{0.6\pgf@circ@res@left}{0.4\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.6\pgf@circ@res@right}{0.4\pgf@circ@res@up}}
    \pgfusepath{draw}
}
%% variable T attenuator
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/vtattenuator/width}}
{vtattenuator}
{\ctikzvalof{bipoles/vtattenuator/width}}
{\ctikzvalof{bipoles/vtattenuator/width}}
{
    % draw inner symbol
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{0pt}{0.4\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0pt}{0.4\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{0.6\pgf@circ@res@left}{0.4\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.6\pgf@circ@res@right}{0.4\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfcirc@set@arrows{tunable}{}{latex}
    \pgfpathmoveto{\pgfpoint{0.7\pgf@circ@res@left}{0.5\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.7\pgf@circ@res@right}{0.8\pgf@circ@res@up}}
    \pgfusepath{draw}
}
%% phase shifter
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/phaseshifter/width}}
{phaseshifter}
{\ctikzvalof{bipoles/phaseshifter/width}}
{\ctikzvalof{bipoles/phaseshifter/width}}
{
    % inner symbol
    \pgf@circ@text@strokecolor
    \pgftext[center,x=0,y=0]{\Large$\varphi$}
}
%% variable phase shifter
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/phaseshifter/width}}
{vphaseshifter}
{\ctikzvalof{bipoles/vphaseshifter/width}}
{\ctikzvalof{bipoles/vphaseshifter/width}}
{
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfcirc@set@arrows{tunable}{}{latex}
    \pgfpathmoveto{\pgfpoint{0.75\pgf@circ@res@left}{0.65\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.7\pgf@circ@res@right}{0.65\pgf@circ@res@up}}
    \pgfusepath{draw}
    % inner symbol
    \pgf@circ@text@strokecolor
    \pgftext[center,x=0,y=0]{\Large$\varphi$}
}
%% detector
\pgfcirc@define@twoports@norotate{blocks}
{}
{\ctikzvalof{bipoles/detector/width}}
{detector}
{\ctikzvalof{bipoles/detector/width}}
{\ctikzvalof{bipoles/detector/width}}
{
    % draw inner stuff
    \pgfsetlinewidth{0.8\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{0.75\pgf@circ@res@left}{0}}
    \pgfpathlineto{\pgfpoint{0.75\pgf@circ@res@right}{0}}
    \pgfusepath{draw}
    \ifpgf@circuit@fulldiode
        \pgfmathparse{2\pgf@circ@res@up / \pgf@circ@scaled@Rlen / \ctikzvalof{bipoles/generic/width}}
        \pgftransformscale{\pgfmathresult}
        \pgfnode{fulldiodeshape}{center}{}{pgf@fulldiode}{\pgfusepath{fill}}
    \else
        \pgfmathparse{2\pgf@circ@res@up / \pgf@circ@scaled@Rlen / \ctikzvalof{bipoles/resistor/width}}
        \pgftransformscale{\pgfmathresult}
        \pgfnode{emptydiodeshape}{center}{}{pgf@emptydiode}{\pgfusepath{fill}}
    \fi
}
%% saturation block, contributed by P.Sacco <paul.sacco@estaca,eu>
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/saturation/width}}
{saturation}
{\ctikzvalof{bipoles/saturation/width}}
{\ctikzvalof{bipoles/saturation/width}}
{
    \pgfsetlinewidth{1.2\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpoint{.4\pgf@circ@res@step}{.4\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{0.65\pgf@circ@res@step}{.4\pgf@circ@res@step}}
    %
    \pgfpathmoveto{\pgfpointorigin}
    \pgfpathlineto{\pgfpoint{-.4\pgf@circ@res@step}{-.4\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{-0.65\pgf@circ@res@step}{-.4\pgf@circ@res@step}}
    \pgfusepath{draw}
}
%% sigmoid
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/sigmoid/width}}
{sigmoid}
{\ctikzvalof{bipoles/sigmoid/width}}
{\ctikzvalof{bipoles/sigmoid/width}}
{
    \pgfsetlinewidth{1.2\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{-.65\pgf@circ@res@step}{-.4\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{-.45\pgf@circ@res@step}{-.4\pgf@circ@res@step}}
    \pgfpathparabola{\pgfpointorigin}{\pgfpoint{.45\pgf@circ@res@step}{.4\pgf@circ@res@step}}
    %
    \pgfpathmoveto{\pgfpoint{.65\pgf@circ@res@step}{.4\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{.45\pgf@circ@res@step}{.4\pgf@circ@res@step}}
    \pgfpathparabola{\pgfpointorigin}{\pgfpoint{-.45\pgf@circ@res@step}{-.4\pgf@circ@res@step}}
    \pgfusepath{draw}
}
%% all-or-nothing (comparator) block
\pgfcirc@define@twoports{blocks}
{}
{\ctikzvalof{bipoles/allornothing/width}}
{allornothing}
{\ctikzvalof{bipoles/allornothing/width}}
{\ctikzvalof{bipoles/allornothing/width}}
{
    \pgfsetlinewidth{1.2\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{-0.55\pgf@circ@res@step}{-.4\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{+0pt}{-.4\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{+0pt}{.4\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{0.55\pgf@circ@res@step}{.4\pgf@circ@res@step}}
    \pgfusepath{draw}
}
%% converters help function
%% definition for styling the DC symbols (GitHub issue #680)
\ctikzset{blocks dc in segments/.initial=1}
\ctikzset{blocks dc out segments/.initial=1}
\ctikzset{blocks dc segments/.code={%
        \ctikzset{blocks dc in segments=#1}%
        \ctikzset{blocks dc out segments=#1}%
    }
}
\def\pgf@circ@twoport@converter@dc#1#2{%
    \pgfscope
    \pgftransformshift{\pgfpoint{#1\pgf@circ@res@step}{#2\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{-0.25\pgf@circ@res@step}{0.125\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{0.25\pgf@circ@res@step}{0.125\pgf@circ@res@step}}
    \pgfusepath{draw}
    \ifpgf@circuit@full@dashed\else % do not apply the specific dash if fully dashing
        \edef\@@up{\ctikzvalof{blocks dc in segments}}
        \edef\@@down{\ctikzvalof{blocks dc out segments}}
        \ifdim\dimexpr#1\pgf@circ@res@step\relax<0pt
            \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@res@step/(4*\@@up-2)}
        \else
            \pgfmathsetlength{\pgf@circ@res@other}{\pgf@circ@res@step/(4*\@@down-2)}
        \fi
        \pgfsetdash{{\pgf@circ@res@other}{\pgf@circ@res@other}}{0pt}
    \fi
    \pgfpathmoveto{\pgfpoint{-0.25\pgf@circ@res@step}{-0.125\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{0.25\pgf@circ@res@step}{-0.125\pgf@circ@res@step}}
    \pgfusepath{draw}
    \endpgfscope
}
\def\pgf@circ@twoport@converter@dc@up{%
    \pgf@circ@twoport@converter@dc{-0.5}{0.5}
}
\def\pgf@circ@twoport@converter@dc@down{%
    \pgf@circ@twoport@converter@dc{0.5}{-0.5}
}
\def\pgf@circ@twoport@converter@ac#1#2{%
    \pgfscope
    \pgftransformshift{\pgfpoint{#1\pgf@circ@res@step}{#2\pgf@circ@res@step}}
    \pgfpathmoveto{\pgfpoint{-.31\pgf@circ@res@step}{0\pgf@circ@res@step}}
    \pgfpathsine{\pgfpoint{.17\pgf@circ@res@step}{.17\pgf@circ@res@step}}
    \pgfpathcosine{\pgfpoint{.17\pgf@circ@res@step}{-.17\pgf@circ@res@step}}
    \pgfpathsine{\pgfpoint{.17\pgf@circ@res@step}{-.17\pgf@circ@res@step}}
    \pgfpathcosine{\pgfpoint{.17\pgf@circ@res@step}{.17\pgf@circ@res@step}}
    \pgfusepath{draw}
    \endpgfscope
}
\def\pgf@circ@twoport@converter@ac@up{%
    \pgf@circ@twoport@converter@ac{-0.45}{0.5}
    }
\def\pgf@circ@twoport@converter@ac@down{%
    \pgf@circ@twoport@converter@ac{0.45}{-0.5}
}
\def\pgf@circ@twoport@converter@tac@up{%
    \pgf@circ@twoport@converter@ac{-0.45}{0.65}
    \pgf@circ@twoport@converter@ac{-0.45}{0.5}
    \pgf@circ@twoport@converter@ac{-0.45}{0.35}
}
\def\pgf@circ@twoport@converter@tac@down{%
    \pgf@circ@twoport@converter@ac{0.45}{-0.65}
    \pgf@circ@twoport@converter@ac{0.45}{-0.5}
    \pgf@circ@twoport@converter@ac{0.45}{-0.35}
}
%% single phase ac/dc converter
\pgfcirc@define@twoports{blocks}
{
    % these two are left for backward compatibiliyt
    \anchor{dc1}{\northeast\pgf@y=.4\pgf@y}
    \anchor{dc2}{\northeast\pgf@y=-.4\pgf@y}
    % better
    \anchor{ac up in}{\northeast\pgf@y=.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac down in}{\northeast\pgf@y=-.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{dc up out}{\northeast\pgf@y=.4\pgf@y}
    \anchor{dc down out}{\northeast\pgf@y=-.4\pgf@y}
}
{\ctikzvalof{bipoles/sacdc/width}}
{sacdc}
{\ctikzvalof{bipoles/sacdc/width}}
{\ctikzvalof{bipoles/sacdc/width}}
{
    \pgfcirc@twoport@draw@splitline
    \ifnum\@@rotation<145 % swap dc/ac for "backward" and "up" symbol
        \pgf@circ@twoport@converter@ac@up
        \pgf@circ@twoport@converter@dc@down
    \else
        \pgf@circ@twoport@converter@dc@up
        \pgf@circ@twoport@converter@ac@down
    \fi
}
%% dc/dc converter
\pgfcirc@define@twoports{blocks}
{
    % these two are left for backward compatibiliyt
    \anchor{dc1}{\northeast\pgf@y=.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{dc2}{\northeast\pgf@y=-.4\pgf@y\pgf@x=-\pgf@x}
    % better
    \anchor{dc up in}{\northeast\pgf@y=.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{dc down in}{\northeast\pgf@y=-.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{dc up out}{\northeast\pgf@y=.4\pgf@y}
    \anchor{dc down out}{\northeast\pgf@y=-.4\pgf@y}
}
{\ctikzvalof{bipoles/sdcdc/width}}
{sdcdc}
{\ctikzvalof{bipoles/sdcdc/width}}
{\ctikzvalof{bipoles/sdcdc/width}}
{
    \pgfcirc@twoport@draw@splitline
    % No need to switch here
    \pgf@circ@twoport@converter@dc@up
    \pgf@circ@twoport@converter@dc@down
}
%% single phase dc/ac converter
\pgfcirc@define@twoports{blocks}
{
    % these two are left for backward compatibiliyt
    \anchor{dc1}{\northeast\pgf@y=.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{dc2}{\northeast\pgf@y=-.4\pgf@y\pgf@x=-\pgf@x}
    % better
    \anchor{dc up in}{\northeast\pgf@y=.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{dc down in}{\northeast\pgf@y=-.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac up out}{\northeast\pgf@y=.4\pgf@y}
    \anchor{ac down out}{\northeast\pgf@y=-.4\pgf@y}
}
{\ctikzvalof{bipoles/sdcac/width}}
{sdcac}
{\ctikzvalof{bipoles/sdcac/width}}
{\ctikzvalof{bipoles/sdcac/width}}
{
    \pgfcirc@twoport@draw@splitline
    \ifnum\@@rotation<145 % swap dc/ac for "backward" and "up" symbol
        \pgf@circ@twoport@converter@dc@up
        \pgf@circ@twoport@converter@ac@down
    \else
        \pgf@circ@twoport@converter@ac@up
        \pgf@circ@twoport@converter@dc@down
    \fi
}
%% single phase ac/ac converter
\pgfcirc@define@twoports{blocks}
{
    \anchor{ac up in}{\northeast\pgf@y=.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac down in}{\northeast\pgf@y=-.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac up out}{\northeast\pgf@y=.4\pgf@y}
    \anchor{ac down out}{\northeast\pgf@y=-.4\pgf@y}
}
{\ctikzvalof{bipoles/sdcac/width}}
{sacac}
{\ctikzvalof{bipoles/sdcac/width}}
{\ctikzvalof{bipoles/sdcac/width}}
{
    \pgfcirc@twoport@draw@splitline
    \pgf@circ@twoport@converter@ac@up
    \pgf@circ@twoport@converter@ac@down
}
%% threephase ac/dc converter
\pgfcirc@define@twoports{blocks}
{
    % legacy, let for compatibility
    \anchor{dc1}{\northeast\pgf@y=.4\pgf@y}
    \anchor{dc2}{\northeast\pgf@y=-.4\pgf@y}
    \anchor{ac1}{\northeast\pgf@y=.6\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac2}{\northeast\pgf@y=0\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac3}{\northeast\pgf@y=-.6\pgf@y\pgf@x=-\pgf@x}
    %better
    \anchor{dc up out}{\northeast\pgf@y=.4\pgf@y}
    \anchor{dc down out}{\northeast\pgf@y=-.4\pgf@y}
    \anchor{ac up in}{\northeast\pgf@y=.6\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac mid in}{\northeast\pgf@y=0\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac down in}{\northeast\pgf@y=-.6\pgf@y\pgf@x=-\pgf@x}
}
{\ctikzvalof{bipoles/tacdc/width}}
{tacdc}
{\ctikzvalof{bipoles/tacdc/width}}
{\ctikzvalof{bipoles/tacdc/width}}
{
    \pgfcirc@twoport@draw@splitline
    \ifnum\@@rotation<145 % swap dc/ac for "backward" and "up" symbol
        \pgf@circ@twoport@converter@tac@up
        \pgf@circ@twoport@converter@dc@down
    \else
        \pgf@circ@twoport@converter@dc@up
        \pgf@circ@twoport@converter@tac@down
    \fi
}
%% threephase dc/ac converter
\pgfcirc@define@twoports{blocks}
{
    % legacy, let for compatibility
    \anchor{dc1}{\northeast\pgf@y=.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{dc2}{\northeast\pgf@y=-.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac1}{\northeast\pgf@y=.6\pgf@y}
    \anchor{ac2}{\northeast\pgf@y=0\pgf@y}
    \anchor{ac3}{\northeast\pgf@y=-.6\pgf@y}
    %better
    \anchor{dc up in}{\northeast\pgf@y=.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{dc down in}{\northeast\pgf@y=-.4\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac up out}{\northeast\pgf@y=.6\pgf@y}
    \anchor{ac mid out}{\northeast\pgf@y=0\pgf@y}
    \anchor{ac down out}{\northeast\pgf@y=-.6\pgf@y}
}
{\ctikzvalof{bipoles/tdcac/width}}
{tdcac}
{\ctikzvalof{bipoles/tdcac/width}}
{\ctikzvalof{bipoles/tdcac/width}}
{
    \pgfcirc@twoport@draw@splitline
    \ifnum\@@rotation<145 % swap dc/ac for "backward" and "up" symbol
        \pgf@circ@twoport@converter@dc@up
        \pgf@circ@twoport@converter@tac@down
    \else
        \pgf@circ@twoport@converter@tac@up
        \pgf@circ@twoport@converter@dc@down
    \fi
}
%% threephase ac/ac converter
\pgfcirc@define@twoports{blocks}
{
    \anchor{ac up in}{\northeast\pgf@y=.6\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac mid in}{\northeast\pgf@y=0\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac down in}{\northeast\pgf@y=-.6\pgf@y\pgf@x=-\pgf@x}
    \anchor{ac up out}{\northeast\pgf@y=.6\pgf@y}
    \anchor{ac mid out}{\northeast\pgf@y=0\pgf@y}
    \anchor{ac down out}{\northeast\pgf@y=-.6\pgf@y}
}
{\ctikzvalof{bipoles/tdcac/width}}
{tacac}
{\ctikzvalof{bipoles/tdcac/width}}
{\ctikzvalof{bipoles/tdcac/width}}
{
    \pgfcirc@twoport@draw@splitline
    \pgf@circ@twoport@converter@tac@down
    \pgf@circ@twoport@converter@tac@up
}
%%%% Non-square blocks. We do not use the standard macros
%%%% this one is adapted to do the boxed thing
%
\long\def\pgfcirc@define@twoports@boxed#1#2#3#4#5#6#7{
\pgfcircdeclarebipolescaled{#1}
    {
        \savedmacro{\componentisboxed}{\edef\componentisboxed{\ifpgf@circuit@boxed 1\else 0\fi}}
        \pgcirc@twoport@additional@anchors
        #2
    }
    {#3}
    {#4}
    {#5}
    {#6}
    {
    \pgf@circ@res@step=#6\pgf@circ@scaled@Rlen %6 is the real width parameter
    \pgfsetdash{}{0pt}	% always draw solid line for inner symbol
    \pgfsetarrows{-}
    \pgfcirc@twoport@maybedash
    % draw outer box
    \ifpgf@circuit@boxed
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfnode{blockbox}{center}{}{pgf@box}{\pgfusepath{draw}}
        \pgf@circ@draworfill
    \fi
    \pgf@circ@inputarrow
    \ifpgf@circuit@boxed
        \pgfsetlinewidth{\pgfstartlinewidth}
        % draw solid line for inner symbol if no box is drawn and not fully dashed
        \ifpgf@circuit@full@dashed\else\pgfsetdash{}{0pt}\fi
        \pgf@circ@res@step=.7\pgf@circ@res@step % scale amp symbol when inside a box
    \else
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \fi
    #7
    }
}
%% voltage controled oscillator
\pgfcirc@define@twoports@boxed{blocks}
{}
{\ctikzvalof{bipoles/vco/width}}
{vco}
{\ctikzvalof{bipoles/twoport/width}}
{\ctikzvalof{bipoles/vco/width}}
{
    % ok, this is a bit of incoherence
    \divide \pgf@circ@res@step by 2
    % draw circle
    \pgfscope
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
        \pgfpathcircle{\pgfpoint{0}{0}} {\pgf@circ@res@step}
        \pgf@circ@draworfill
    \endpgfscope
    \pfgcirc@twoport@rotate@inner@symbol
    \pgfcirc@twoport@draw@sine{0}{0}
}
%% amplifier, iamplifier, and vamplifier
%% Amplifier %% Beware, not using the generic twoport(s) macros.
\pgfcirc@define@twoports@boxed{blocks}
{
    \anchor{up}{%
        \northeast\pgf@x=0pt\relax
        \ifnum\componentisboxed=0
            \pgf@y=0.55\pgf@y
        \fi
    }
    \anchor{down}{%
        \northeast\pgf@x=0pt\pgf@y=-\pgf@y\relax
        \ifnum\componentisboxed=0
            \pgf@y=0.55\pgf@y
        \fi
    }
}
{\ifpgf@circuit@boxed\ctikzvalof{bipoles/twoport/width}\else\ctikzvalof{bipoles/amp/width}\fi}
{amp}
{\ifpgf@circuit@boxed\ctikzvalof{bipoles/twoport/width}\else\ctikzvalof{bipoles/amp/width}\fi}
{\ifpgf@circuit@boxed\ctikzvalof{bipoles/twoport/width}\else\ctikzvalof{bipoles/amp/width}\fi}
{
    % draw triangle
    \pgfpathmoveto{\pgfpoint{-0.5\pgf@circ@res@step}{0.55\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@step}{0}}
    \pgfpathlineto{\pgfpoint{-0.5\pgf@circ@res@step}{-0.55\pgf@circ@res@step}}
    \pgfpathclose
    \pgf@circ@draworfill
    \pfgcirc@twoport@get@symbol@rotation
    % draw inner text
    \pgf@circ@text@strokecolor
    \ifnum\@@rotation=180
        \pgftransformrotate{180}
        \pgftext[center,x=0.12\pgf@circ@res@step,y=0]{\ctikzvalof{bipoles/twoport/text}}
    \else
        \pgftext[center,x=-0.12\pgf@circ@res@step,y=0]{\ctikzvalof{bipoles/twoport/text}}
    \fi
}
%% Instrumentation amplifier %% Beware, not using the generic twoport(s) macros.
\pgfcirc@define@twoports@boxed{blocks}
{
    \anchor{up}{%
        \northeast\pgf@x=0pt\relax
        \ifnum\componentisboxed=0
            \pgf@y=0.75\pgf@y
        \fi
    }
    \anchor{down}{%
        \northeast\pgf@x=0pt\pgf@y=-\pgf@y\relax
        \ifnum\componentisboxed=0
            \pgf@y=0.75\pgf@y
        \fi
    }
}
{\ifpgf@circuit@boxed\ctikzvalof{bipoles/twoport/width}\else\ctikzvalof{bipoles/amp/width}\fi}
{iamp}
{\ifpgf@circuit@boxed\ctikzvalof{bipoles/twoport/width}\else\ctikzvalof{bipoles/amp/width}\fi}
{\ifpgf@circuit@boxed\ctikzvalof{bipoles/twoport/width}\else\ctikzvalof{bipoles/amp/width}\fi}
{
    % draw blunt triangle
    \pgfpathmoveto{\pgfpoint{-0.5\pgf@circ@res@step}{0.55\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@step}{0.2\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@step}{-0.2\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{-0.5\pgf@circ@res@step}{-0.55\pgf@circ@res@step}}
    \pgfpathclose
    \pgf@circ@draworfill
    \pfgcirc@twoport@get@symbol@rotation
    % draw inner text
    \pgf@circ@text@strokecolor
    \ifnum\@@rotation=180
        \pgftransformrotate{180}
        \pgftext[center,x=0.12\pgf@circ@res@step,y=0]{\ctikzvalof{bipoles/twoport/text}}
    \else
        \pgftext[center,x=-0.12\pgf@circ@res@step,y=0]{\ctikzvalof{bipoles/twoport/text}}
    \fi
}
%% variable amplifier %% Beware, not using the generic twoport(s) macros.
\pgfcirc@define@twoports@boxed{blocks}
{
    \anchor{up}{%
        \northeast\pgf@x=0pt\relax
        \ifnum\componentisboxed=0
            \pgf@y=0.55\pgf@y
        \fi
    }
    \anchor{down}{%
        \northeast\pgf@x=0pt\pgf@y=-\pgf@y\relax
        \ifnum\componentisboxed=0
            \pgf@y=0.55\pgf@y
        \fi
    }
}
{\ifpgf@circuit@boxed\ctikzvalof{bipoles/twoport/width}\else\ctikzvalof{bipoles/amp/width}\fi}
{vamp}
{\ifpgf@circuit@boxed\ctikzvalof{bipoles/twoport/width}\else\ctikzvalof{bipoles/amp/width}\fi}
{\ifpgf@circuit@boxed\ctikzvalof{bipoles/twoport/width}\else\ctikzvalof{bipoles/amp/width}\fi}
{
    % draw triangle
    \pgfpathmoveto{\pgfpoint{-0.5\pgf@circ@res@step}{0.55\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@step}{0}}
    \pgfpathlineto{\pgfpoint{-0.5\pgf@circ@res@step}{-0.55\pgf@circ@res@step}}
    \pgfpathclose
    \pgf@circ@draworfill
    \pfgcirc@twoport@get@symbol@rotation
    % draw arrow
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfcirc@set@arrows{tunable}{}{latex}
    \pgfpathmoveto{\pgfpoint{-0.8\pgf@circ@res@step}{-0.5\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{0.6\pgf@circ@res@step}{0.6\pgf@circ@res@step}}
    \pgfusepath{draw}
    % draw inner text
    \pgf@circ@text@strokecolor
    \ifnum\@@rotation=180
        \pgftransformrotate{180}
        \pgftext[center,x=0.12\pgf@circ@res@step,y=0]{\ctikzvalof{bipoles/twoport/text}}
    \else
        \pgftext[center,x=-0.12\pgf@circ@res@step,y=0]{\ctikzvalof{bipoles/twoport/text}}
    \fi
}

%% optical fiber
\pgfcirc@define@twoports@norotate{blocks}
{}
{\ctikzvalof{bipoles/fiber/width}}
{fiber}
{\ctikzvalof{bipoles/fiber/width}}
{\ctikzvalof{bipoles/fiber/width}}
{
	\pgfpathcircle{\pgfpoint{0.2\pgf@circ@res@left}{0.4\pgf@circ@res@up}}{0.4\pgf@circ@res@up}
	\pgfpathcircle{\pgfpoint{0\pgf@circ@res@left}{0.4\pgf@circ@res@up}}{0.4\pgf@circ@res@up}
        \pgfpathcircle{\pgfpoint{-0.2\pgf@circ@res@left}{0.4\pgf@circ@res@up}}{0.4\pgf@circ@res@up}
	\pgfusepath{draw}
        % always use basic line width for this
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
	\pgfusepath{draw}
}

\pgfcirc@activate@bipole@simple{l}{fiber}
%
% %>>>

%% Path definitions for Blocks%<<<

\pgfcirc@activate@bipole@simple{l}{twoport}
\pgfcirc@activate@bipole@simple{l}{twoportsplit}
\pgfcirc@activate@bipole@simple{l}{vco}
\pgfcirc@activate@bipole@simple{l}{bandpass}
\pgfcirc@activate@bipole@simple{l}{bandstop}
\pgfcirc@activate@bipole@simple{l}{highpass}
\pgfcirc@activate@bipole@simple{l}{highpass2}
\pgfcirc@activate@bipole@simple{l}{lowpass}
\pgfcirc@activate@bipole@simple{l}{lowpass2}
\pgfcirc@activate@bipole@simple{l}{allpass}
\pgfcirc@activate@bipole@simple{l}{adc}
\pgfcirc@activate@bipole@simple{l}{dac}
\pgfcirc@activate@bipole@simple{l}{dsp}
\pgfcirc@activate@bipole@simple{l}{fft}
\pgfcirc@activate@bipole@simple{l}{amp}
\pgfcirc@activate@bipole@simple{l}{iamp}
\pgfcirc@activate@bipole@simple{l}{vamp}
\pgfcirc@activate@bipole@simple{l}{piattenuator}
\pgfcirc@activate@bipole@simple{l}{vpiattenuator}
\pgfcirc@activate@bipole@simple{l}{tattenuator}
\pgfcirc@activate@bipole@simple{l}{vtattenuator}
\pgfcirc@activate@bipole@simple{l}{phaseshifter}
\pgfcirc@activate@bipole@simple{l}{vphaseshifter}
\pgfcirc@activate@bipole@simple{l}{detector}
\pgfcirc@activate@bipole@simple{l}{saturation}
\pgfcirc@activate@bipole@simple{l}{sigmoid}
\pgfcirc@activate@bipole@simple{l}{allornothing}
\pgfcirc@activate@bipole@simple{l}{fiber}
\pgfcirc@activate@bipole@simple{l}{sacdc}
\pgfcirc@activate@bipole@simple{l}{sdcac}
\pgfcirc@activate@bipole@simple{l}{sdcdc}
\pgfcirc@activate@bipole@simple{l}{sacac}
\pgfcirc@activate@bipole@simple{l}{tacdc}
\pgfcirc@activate@bipole@simple{l}{tdcac}
\pgfcirc@activate@bipole@simple{l}{tacac}
% %>>>

%% Node shapes for  Block elements %<<<
%
% utility macro for the anchors
\def\pgf@circ@circular@rf@anchors#1{%
    \savedanchor\northwest{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \ifpgf@circuit@boxed
            \pgf@y=\ctikzvalof{bipoles/twoport/width}\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@x=-\ctikzvalof{bipoles/twoport/width}\pgf@circ@scaled@Rlen
            \pgf@x=.5\pgf@x
        \else
            \pgf@y=\ctikzvalof{tripoles/#1/width}\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@x=-\ctikzvalof{tripoles/#1/width}\pgf@circ@scaled@Rlen
            \pgf@x=.5\pgf@x
        \fi
    }
    % border anchors
    \anchorborder{
        \pgf@circ@res@left=\pgf@x
        \pgf@circ@res@up=\pgf@y
        \ifnum\componentisboxed=0
            \pgfpointborderellipse{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}
            }{\pgfpoint{\ctikzvalof{tripoles/#1/width}*\scaledRlen/2}{\ctikzvalof{tripoles/#1/width}*\scaledRlen/2}}
        \else
            \pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}
            }{\pgfpoint{\ctikzvalof{tripoles/#1/width}*\scaledRlen/2}{\ctikzvalof{tripoles/#1/width}*\scaledRlen/2}}
        \fi
    }
    \pgfcirc@northwest@symmetric@geoanchors
    \anchor{geocenter}{\pgfpointorigin}
    \anchor{up}{\northwest\pgf@x=0pt}
    \anchor{down}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    % Deprecated number anchors
    \anchor{1}{\northwest\pgf@y=0pt}
    \anchor{2}{\northwest\pgf@y=-\pgf@y\pgf@x=0pt}
    \anchor{3}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{4}{\northwest\pgf@y=\pgf@y\pgf@x=0pt}
    % input output anchors (also quite bad)
    \anchor{in 1}{\northwest\pgf@y=0pt}
    \anchor{in1}{\northwest\pgf@y=0pt}
    \anchor{in}{\northwest\pgf@y=0pt}
    \anchor{in 2}{\northwest\pgf@y=-\pgf@y\pgf@x=0pt}
    \anchor{in2}{\northwest\pgf@y=-\pgf@y\pgf@x=0pt}
    \anchor{out}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{left down}{\northwest\pgf@y=-0.5\pgf@y}
    \anchor{right down}{\northwest\pgf@x=-\pgf@x\pgf@y=-0.5\pgf@y}
    \anchor{right up}{\northwest\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{left up}{\northwest\pgf@y=0.5\pgf@y}
    \anchor{text}{\northwest
        \advance\pgf@y\dimexpr-.5\dp\pgfnodeparttextbox+.5\ht\pgfnodeparttextbox\relax
        \pgf@x=-.5\wd\pgfnodeparttextbox\relax}
}
% draw the body rectangle and circle if and when needed
\def\pgf@circ@circular@rf@box@circle{%
    \pgfstartlinewidth=\pgflinewidth
    % draw outer box
    \ifpgf@circuit@boxed
        \pgfnode{blockbox}{center}{}{pgf@box}{\pgfusepath{draw}}
    \fi
    % draw outer circle
    \ifpgf@circuit@boxed
        \pgf@circ@res@step=.7\pgf@circ@res@step
        % draw solid line for inner symbol if no box is drawn and not fully dashed
        \ifpgf@circuit@full@dashed\else\pgfsetdash{}{0pt}\fi
    \else
        \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \fi
    \ifpgf@circuit@boxedcircled
        \pgfpathcircle{\pgfpoint{0}{0}} {0.5\pgf@circ@res@step}
    \fi
    \pgf@circ@draworfill
}
%
\pgfdeclareshape{mixer}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{blocks}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedmacro{\componentisboxed}{\edef\componentisboxed{\ifpgf@circuit@boxed 1\else 0\fi}}
    % build the anchor set
    \anchor{center}{\pgfpointorigin}
    \pgf@circ@circular@rf@anchors{mixer}
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{tripoles/mixer/width}\pgf@circ@scaled@Rlen
        \pgfscope
            \pgf@circ@circular@rf@box@circle
            % draw inner stuff
            % draw solid line for inner symbol if no box is drawn and not fully dashed
            \ifpgf@circuit@full@dashed\else\pgfsetdash{}{0pt}\fi
            \pgfsetlinewidth{\pgfstartlinewidth}
            \pgfpathmoveto{\pgfpointorigin}
            \pgfpathmoveto{\pgfpointpolar{135}{0.5\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpointpolar{-45}{0.5\pgf@circ@res@step}}
            \pgfpathmoveto{\pgfpointorigin}
            \pgfpathmoveto{\pgfpointpolar{45}{0.5\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpointpolar{-135}{0.5\pgf@circ@res@step}}
            \pgfusepath{draw}
        \endpgfscope
    }
}

\pgfdeclareshape{adder}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{blocks}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedmacro{\componentisboxed}{\edef\componentisboxed{\ifpgf@circuit@boxed 1\else 0\fi}}
    % build the anchor set
    \anchor{center}{\pgfpointorigin}
    \pgf@circ@circular@rf@anchors{adder}
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{tripoles/adder/width}\pgf@circ@scaled@Rlen
        \pgfscope
            \pgf@circ@circular@rf@box@circle
            % draw inner stuff
            % draw solid line for inner symbol if no box is drawn and not fully dashed
            \ifpgf@circuit@full@dashed\else\pgfsetdash{}{0pt}\fi
            \pgfsetlinewidth{\pgfstartlinewidth}
            \pgfpathmoveto{\pgfpointorigin}
            \pgfpathmoveto{\pgfpointpolar{0}{0.3\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpointpolar{180}{0.3\pgf@circ@res@step}}
            \pgfpathmoveto{\pgfpointorigin}
            \pgfpathmoveto{\pgfpointpolar{90}{0.3\pgf@circ@res@step}}
            \pgfpathlineto{\pgfpointpolar{270}{0.3\pgf@circ@res@step}}
            \pgf@circ@setlinewidth{tripoles}{\pgflinewidth}
            \pgfusepath{draw}
        \endpgfscope
    }
}

\pgfdeclareshape{oscillator}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{blocks}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedmacro{\componentisboxed}{\edef\componentisboxed{\ifpgf@circuit@boxed 1\else 0\fi}}
    % build the anchor set --- the center of an oscillator is on the  right
    \anchor{center}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \pgf@circ@circular@rf@anchors{oscillator}
    % border anchors
    \anchor{text}{
        \pgf@x=-2\pgf@x
        \advance \pgf@x by -.5\wd\pgfnodeparttextbox
        \advance \pgf@y by -1.5\ht\pgfnodeparttextbox
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{tripoles/oscillator/width}\pgf@circ@scaled@Rlen{}
        \pgfscope
            \pgf@circ@circular@rf@box@circle
            % draw inner sine waves
            % draw solid line for inner symbol if no box is drawn and not fully dashed
            \ifpgf@circuit@full@dashed\else\pgfsetdash{}{0pt}\fi
            \pgfsetlinewidth{\pgfstartlinewidth}
            \pgfsetcornersarced{\pgfpointorigin}% do not use rounded corners!
            \pgfpathmoveto{\pgfpoint{-0.3\pgf@circ@res@step}{0\pgf@circ@res@step}}
            \pgfpathsine{\pgfpoint{.15\pgf@circ@res@step}{.15\pgf@circ@res@step}}
            \pgfpathcosine{\pgfpoint{.15\pgf@circ@res@step}{-.15\pgf@circ@res@step}}
            \pgfpathsine{\pgfpoint{.15\pgf@circ@res@step}{-.15\pgf@circ@res@step}}
            \pgfpathcosine{\pgfpoint{.15\pgf@circ@res@step}{.15\pgf@circ@res@step}}
            \pgfusepath{draw}
        \endpgfscope
    }
}

\pgfdeclareshape{circulator}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{blocks}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedmacro{\componentisboxed}{\edef\componentisboxed{\ifpgf@circuit@boxed 1\else 0\fi}}
    % build the anchor set
    \anchor{center}{\pgfpointorigin}
    \pgf@circ@circular@rf@anchors{circulator}
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{tripoles/circulator/width}\pgf@circ@scaled@Rlen
        \pgfscope
            \pgf@circ@circular@rf@box@circle
            % inner arrow
            % draw solid line for inner symbol if no box is drawn and not fully dashed
            \ifpgf@circuit@full@dashed\else\pgfsetdash{}{0pt}\fi
            \pgfsetlinewidth{\pgfstartlinewidth}
            \pgfsetarrowsend{latex}
            \pgfpathmoveto{\pgfpoint{-0.25\pgf@circ@res@step}{0}}
            \pgfpatharc{180}{-90} {0.25\pgf@circ@res@step}
            \pgfpathlineto{\pgfpoint{-5pt}{-0.2\pgf@circ@res@step}}
            \pgfusepath{draw}
            \endpgfscope
        }
}

%% gridnode
\pgfdeclareshape{gridnode}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{blocks}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor\northwest{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@y=\ctikzvalof{quadpoles/gridnode/width}\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@x=-\ctikzvalof{quadpoles/gridnode/width}\pgf@circ@scaled@Rlen
            \pgf@x=.5\pgf@x
    }
    \pgfcirc@northwest@symmetric@geoanchors
    \anchor{center}{\pgfpointorigin}
    \anchor{up}{\northwest\pgf@x=0pt}
    \anchor{down}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{right}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{left}{\northwest\pgf@y=0pt}
    \anchor{left down}{\northwest\pgf@y=-0.5\pgf@y}
    \anchor{right down}{\northwest\pgf@x=-\pgf@x\pgf@y=-0.5\pgf@y}
    \anchor{right up}{\northwest\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{left up}{\northwest\pgf@y=0.5\pgf@y}
    \anchor{text}{
        \pgf@x=-2\pgf@x
        \advance \pgf@x by -.5\wd\pgfnodeparttextbox
        \advance \pgf@y by -1.5\ht\pgfnodeparttextbox
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step=\ctikzvalof{quadpoles/gridnode/width}\pgf@circ@scaled@Rlen
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@res@step = \ctikzvalof{quadpoles/gridnode/width}\pgf@circ@scaled@Rlen
        \divide \pgf@circ@res@step by 2
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgf@circ@res@other = \pgf@circ@res@left
        \advance\pgf@circ@res@other by \pgf@circ@res@step
        \pgfcirc@twoport@maybedash
        % draw outer box
        \pgf@circ@twoportbox
        \pgf@circ@inputarrow
        \pgfsetdash{}{0pt}	% always draw solid line for inner symbol
        \pgfsetarrows{-} %never draw arrows
        \pgfsetlinewidth{0.05mm}
        % draw grid
        \foreach \line in {-1,-.5,...,1}
        {
            \pgfpathmoveto{\pgfpoint{\line\pgf@circ@res@right}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\line\pgf@circ@res@up}}
            %
            \pgfpathmoveto{\pgfpoint{\line\pgf@circ@res@right}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\line\pgf@circ@res@down}}
        }
        %prevent from draw the inner cross twice
        \foreach \line in {-.5,0,...,.5}
        {
            \pgfpathmoveto{\pgfpoint{\line\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\line\pgf@circ@res@up}}
            %
            \pgfpathmoveto{\pgfpoint{\line\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\line\pgf@circ@res@down}}
        }
        \pgfusepath{draw}
    }
}


% Wilkinson divider
\pgfdeclareshape{wilkinson}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{blocks}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/wilkinson/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x= \pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x=-\ctikzvalof{tripoles/wilkinson/width}\pgf@x
    }
    \pgfcirc@northwest@symmetric@geoanchors
    \anchor{up}{\northwest\pgf@x=0pt}
    \anchor{down}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{right}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{left}{\northwest\pgf@y=0pt}
    \anchor{center}{\pgfpointorigin}
    \anchor{in}{\northwest\pgf@y=0pt}
    \anchor{out1}{\northwest\pgf@x=-\pgf@x\pgf@y=-0.5\pgf@y}
    \anchor{out2}{\northwest\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{left down}{\northwest\pgf@y=-0.5\pgf@y}
    \anchor{right down}{\northwest\pgf@x=-\pgf@x\pgf@y=-0.5\pgf@y}
    \anchor{right up}{\northwest\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{left up}{\northwest\pgf@y=0.5\pgf@y}
    \anchor{text}{
        \northwest
        \advance \pgf@y by 0.5\ht\pgfnodeparttextbox
        \pgf@x=-.5\wd\pgfnodeparttextbox
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgf@circ@scaled@Rlen=\scaledRlen
        %
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        %
        \pgfstartlinewidth=\pgflinewidth
        % draw outer box
        \pgf@circ@twoportbox
        \pgf@circ@inputarrow
        % draw inner stuff
        \pgfsetdash{}{0pt}	% always draw solid line for inner symbol
        \pgfsetarrows{-} %never draw arrows
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0.5\pgf@circ@res@down}}
        \pgfusepath{draw}
        \pgfsetdash{}{0pt}	% always draw solid line for inner symbol
        % draw inner resisitor - european or american style is recognised
        {
            \pgftransformshift{\pgfpoint{0.5\pgf@circ@res@right}{0pt}}
            \pgftransformrotate{90}
            % calculate size of resistor
            \ifpgf@circuit@europeanresistor
                \pgfmathparse{\pgf@circ@res@up / \pgf@circ@scaled@Rlen / \ctikzvalof{bipoles/generic/width} / 2}
                \pgftransformscale{\pgfmathresult}
                \pgfnode{genericshape}{center}{}{wilk@int@R}{\pgfusepath{fill}}
            \else
                \pgfmathparse{\pgf@circ@res@up / \pgf@circ@scaled@Rlen / \ctikzvalof{bipoles/resistor/width} / 2}
                \pgftransformscale{\pgfmathresult}
                \pgfnode{resistorshape}{center}{}{wilk@int@R}{\pgfusepath{fill}}
            \fi
        }
        \pgfpathmoveto{\pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpointanchor{wilk@int@R}{right}}
        \pgfpathmoveto{\pgfpointanchor{wilk@int@R}{left}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@down}}
        \pgfusepath{draw}
    }
}

%% resistive splitter
\pgfdeclareshape{splitter}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{blocks}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/splitter/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x= \pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x=-\ctikzvalof{tripoles/splitter/width}\pgf@x
    }
    \pgfcirc@northwest@symmetric@geoanchors
    \anchor{center}{\pgfpointorigin}
    \anchor{up}{\northwest\pgf@x=0pt}
    \anchor{down}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{right}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{left}{\northwest\pgf@y=0pt}
    \anchor{in}{\northwest\pgf@y=0pt}
    \anchor{out1}{\northwest\pgf@x=-\pgf@x\pgf@y=-0.5\pgf@y}
    \anchor{out2}{\northwest\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{left down}{\northwest\pgf@y=-0.5\pgf@y}
    \anchor{right down}{\northwest\pgf@x=-\pgf@x\pgf@y=-0.5\pgf@y}
    \anchor{right up}{\northwest\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{left up}{\northwest\pgf@y=0.5\pgf@y}
    \anchor{text}{
        \northwest
        \advance \pgf@y by 0.5\ht\pgfnodeparttextbox
        \pgf@x=-.5\wd\pgfnodeparttextbox
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgf@circ@scaled@Rlen=\scaledRlen
        %
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        %
        \pgfstartlinewidth=\pgflinewidth
        % draw outer box
        \pgf@circ@twoportbox
        \pgf@circ@inputarrow
        % draw inner stuff
        \pgfsetdash{}{0pt}	% always draw solid line for inner symbol
        \pgfsetarrows{-} %never draw arrows
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{0.5\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0.5\pgf@circ@res@down}}
        \pgfusepath{draw}
        %
        \pgfsetdash{}{0pt}	% always draw solid line for inner symbol
        % draw inner resisitors - european or american style is recognised
        \foreach \respt/\resang/\linepta/\lineptb in %
        { \pgfpoint{0.5\pgf@circ@res@right}{0pt}/90/%
            \pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@up}/\pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@down},%
          \pgfpoint{0}{0.25\pgf@circ@res@up}/25/%
            \pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@up}/\pgfpoint{0.5\pgf@circ@res@left}{0},%
          \pgfpoint{0}{0.25\pgf@circ@res@down}/-25/%
            \pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@down}/\pgfpoint{0.5\pgf@circ@res@left}{0}}
        {
            {
                \pgftransformshift{\respt}
                \pgftransformrotate{\resang}
                % calculate size of resistor
                \ifpgf@circuit@europeanresistor
                    \pgfmathparse{\pgf@circ@res@up / \pgf@circ@scaled@Rlen / \ctikzvalof{bipoles/generic/width} / 2}
                    \pgftransformscale{\pgfmathresult}
                    \pgfnode{genericshape}{center}{}{wilk@int@R}{\pgfusepath{fill}}
                \else
                    \pgfmathparse{\pgf@circ@res@up / \pgf@circ@scaled@Rlen / \ctikzvalof{bipoles/resistor/width} / 2}
                    \pgftransformscale{\pgfmathresult}
                    \pgfnode{resistorshape}{center}{}{wilk@int@R}{\pgfusepath{fill}}
                \fi
            }
            \pgfpathmoveto{\linepta}
            \pgfpathlineto{\pgfpointanchor{wilk@int@R}{right}}
            \pgfpathmoveto{\pgfpointanchor{wilk@int@R}{left}}
            \pgfpathlineto{\lineptb}
            \pgfusepath{draw}
        }
    }
}

%% generic splitter
\pgfdeclareshape{genericsplitter}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{blocks}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/genericsplitter/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x= \pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x=-\ctikzvalof{tripoles/genericsplitter/width}\pgf@x
    }
    \pgfcirc@northwest@symmetric@geoanchors
    \anchor{center}{\pgfpointorigin}
    \anchor{up}{\northwest\pgf@x=0pt}
    \anchor{down}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{right}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{left}{\northwest\pgf@y=0pt}
    \anchor{in}{\northwest\pgf@y=0pt}
    \anchor{out1}{\northwest\pgf@x=-\pgf@x\pgf@y=-0.5\pgf@y}
    \anchor{out2}{\northwest\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{left down}{\northwest\pgf@y=-0.5\pgf@y}
    \anchor{right down}{\northwest\pgf@x=-\pgf@x\pgf@y=-0.5\pgf@y}
    \anchor{right up}{\northwest\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{left up}{\northwest\pgf@y=0.5\pgf@y}
    \anchor{text}{
        \northwest
        \pgf@y=-.5\ht\pgfnodeparttextbox
        \pgf@x=-.2\wd\pgfnodeparttextbox
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgf@circ@scaled@Rlen=\scaledRlen
        %
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        %
        \pgfstartlinewidth=\pgflinewidth
        % draw outer box
        \pgf@circ@twoportbox
        \pgf@circ@inputarrow
        % draw inner stuff
        \pgfsetdash{}{0pt}	% always draw solid line for inner symbol
        \pgfsetarrows{-} %never draw arrows
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
        \pgfpathmoveto{\pgfpoint{0.5\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0.5\pgf@circ@res@down}}
        \pgfusepath{draw}
        %
        \pgfsetdash{}{0pt}	% always draw solid line for inner symbol
        % draw inner resisitors - european or american style is recognised
        \foreach \linepta/\lineptb in %
        { \pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@up}/\pgfpoint{0.5\pgf@circ@res@left}{0},%
          \pgfpoint{0.5\pgf@circ@res@right}{0.5\pgf@circ@res@down}/\pgfpoint{0.5\pgf@circ@res@left}{0}}
        {
            \pgfpathmoveto{\linepta}
            \pgfpathlineto{\lineptb}
            \pgfusepath{draw}
        }
    }
}

%% couplers generics
\long\def\pgfcircdeclarefourport#1#2{
    \pgfdeclareshape{#1}{
        \savedmacro{\ctikzclass}{\edef\ctikzclass{blocks}}
        \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
        \savedanchor\northwest{%
            \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            \pgf@y=\ctikzvalof{quadpoles/#1/height}\pgf@circ@scaled@Rlen
            \pgf@y=.5\pgf@y
            \pgf@x=.5\pgf@circ@scaled@Rlen
            \pgf@x=-\ctikzvalof{quadpoles/#1/width}\pgf@x
        }
        \pgfcirc@northwest@symmetric@geoanchors
        \anchor{center}{\pgfpointorigin}
        \anchor{up}{\northwest\pgf@x=0pt}
        \anchor{down}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
        \anchor{right}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
        \anchor{left}{\northwest\pgf@y=0pt}
        \anchor{port1}{\northwest\pgf@y=-0.5\pgf@y}
        \anchor{port2}{\northwest\pgf@x=-\pgf@x\pgf@y=-0.5\pgf@y}
        \anchor{port3}{\northwest\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
        \anchor{port4}{\northwest\pgf@y=0.5\pgf@y}
        \anchor{left down}{\northwest\pgf@y=-0.5\pgf@y}
        \anchor{right down}{\northwest\pgf@x=-\pgf@x\pgf@y=-0.5\pgf@y}
        \anchor{right up}{\northwest\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
        \anchor{left up}{\northwest\pgf@y=0.5\pgf@y}
        %1,2,3,4 are deprecated
        \anchor{1}{\northwest\pgf@y=-0.5\pgf@y}
        \anchor{2}{\northwest\pgf@x=-\pgf@x\pgf@y=-0.5\pgf@y}
        \anchor{3}{\northwest\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
        \anchor{4}{\northwest\pgf@y=0.5\pgf@y}
        \anchor{text}{
            \northwest
            \advance \pgf@y by 0.5\ht\pgfnodeparttextbox
            \pgf@x=-.5\wd\pgfnodeparttextbox
        }
        \pgf@circ@draw@component{
            \pgf@circ@setcolor
            \northwest
            \pgf@circ@res@up = \pgf@y
            \pgf@circ@res@down = -\pgf@y
            \pgf@circ@res@right = -\pgf@x
            \pgf@circ@res@left = \pgf@x
            \pgf@circ@scaled@Rlen=\scaledRlen
            %
            \pgfstartlinewidth=\pgflinewidth
            % draw outer box
            \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
            \pgfpathrectanglecorners{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
            \pgf@circ@draworfill
            % draw inner stuff
            #2%
            % draw inner text
            \pgf@circ@text@strokecolor
            \pgftext[center,x=-0.15\pgf@circ@res@step,y=0]{\ctikzvalof{bipoles/twoport/text}}
        }
    }
}

% four-port
\pgfcircdeclarefourport{fourport}{}

% straight coupler
\pgfcircdeclarefourport{coupler}{
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0.5\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0.5\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0.5\pgf@circ@res@down}}
    \pgfusepath{draw}

    \pgfpathmoveto{\pgfpoint{0.7\pgf@circ@res@left}{0.4\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{0.7\pgf@circ@res@right}{0.4\pgf@circ@res@up}}
    \pgfsetarrows{latex-latex}
    \pgfusepath{draw}
    \pgfpathmoveto{\pgfpoint{0.7\pgf@circ@res@left}{0.4\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{0.7\pgf@circ@res@right}{0.4\pgf@circ@res@down}}
    \pgfsetarrows{latex-latex}
    \pgfusepath{draw}
}

% "bended" coupler
\pgfcircdeclarefourport{coupler2}{
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0.5\pgf@circ@res@up}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0.5\pgf@circ@res@up}}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0.5\pgf@circ@res@down}}
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0.5\pgf@circ@res@down}}
    \pgfusepath{draw}

    \pgfscope
        \pgfpathmoveto{\pgfpoint{0.1\pgf@circ@res@left}{0pt}}
        \pgfpatharc{0}{90} {0.4\pgf@circ@res@up}
        \pgfsetarrowsend{latex}
        \pgfusepath{draw}
    \endpgfscope
    \pgfscope
        \pgfpathmoveto{\pgfpoint{0.1\pgf@circ@res@left}{0pt}}
        \pgfpatharc{0}{-90} {0.4\pgf@circ@res@up}
        \pgfsetarrowsend{latex}
        \pgfusepath{draw}
    \endpgfscope
    \pgfscope
        \pgfpathmoveto{\pgfpoint{0.1\pgf@circ@res@right}{0pt}}
        \pgfpatharc{180}{90} {0.4\pgf@circ@res@up}
        \pgfsetarrowsend{latex}
        \pgfusepath{draw}
    \endpgfscope
    \pgfscope
        \pgfpathmoveto{\pgfpoint{0.1\pgf@circ@res@right}{0pt}}
        \pgfpatharc{-180}{-90} {0.4\pgf@circ@res@up}
        \pgfsetarrowsend{latex}
        \pgfusepath{draw}
    \endpgfscope
}

% mach zehnder modulator
\pgfdeclareshape{mzm}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{blocks}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{tripoles/mzm/height}\pgf@circ@scaled@Rlen
        \pgf@y=.5\pgf@y
        \pgf@x= \pgf@circ@scaled@Rlen
        \pgf@x=.5\pgf@x
        \pgf@x=-\ctikzvalof{tripoles/mzm/width}\pgf@x
    }
    \pgfcirc@northwest@symmetric@geoanchors
    \anchor{center}{\pgfpointorigin}
    \anchor{in}{ \northwest \pgf@y=0pt }
    \anchor{mod}{ \northwest \pgf@x=0pt }
    \anchor{out}{ \northwest \pgf@x=-\pgf@x \pgf@y=0pt }
    \anchor{text}{
        \northwest
        \advance \pgf@y by 0.5\ht\pgfnodeparttextbox
        \pgf@x=-.5\wd\pgfnodeparttextbox
    }
    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgf@circ@scaled@Rlen=\scaledRlen
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgfstartlinewidth=\pgflinewidth
        % draw outer box
        \pgf@circ@twoportbox
        \pgf@circ@inputarrow
        % draw inner stuff
        \pfgcirc@twoport@rotate@inner@symbol
        % draw inner symbol
        \ifpgf@circuit@full@dashed\else\pgfsetdash{}{0pt}\fi
        \pgfsetarrows{-} %never draw arrows
        \pgfsetlinewidth{\pgfstartlinewidth}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{0.75\pgf@circ@res@left}{\pgf@circ@res@zero}}
        %
        \pgfpathmoveto{\pgfpoint{0.75\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@left}{0.25\pgf@circ@res@up}}
        %
        \pgfpathmoveto{\pgfpoint{0.75\pgf@circ@res@left}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@left}{0.25\pgf@circ@res@down}}
        %
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{0.75\pgf@circ@res@right}{\pgf@circ@res@zero}}
        %
        \pgfpathmoveto{\pgfpoint{0.75\pgf@circ@res@right}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@right}{0.25\pgf@circ@res@up}}
        %
        \pgfpathmoveto{\pgfpoint{0.75\pgf@circ@res@right}{\pgf@circ@res@zero}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@right}{0.25\pgf@circ@res@down}}
        %
        \pgfpathmoveto{\pgfpoint{0.5\pgf@circ@res@right}{0.25\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@left}{0.25\pgf@circ@res@up}}
        %
        \pgfpathmoveto{\pgfpoint{0.5\pgf@circ@res@right}{0.25\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{0.5\pgf@circ@res@left}{0.25\pgf@circ@res@down}}
        %
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@zero}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@zero}{0.35\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0.25\pgf@circ@res@right}{0.1\pgf@circ@res@up}}
        \pgfusepath{draw}
        }
}
% %>>>

% vim: set fdm=marker fmr=%<<<,%>>>:
%%%---------- close: tex/pgfcircquadpoles
%%%%%%%%%%% Springe nach tex/pgfcircmultipoles
%%%---------- open: tex/pgfcircmultipoles.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Chips and Rotary Switches
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Definitions for Chips and Rotary switches (multipoles) %<<<1
%
\ctikzset{multipoles/thickness/.initial=2}
\ctikzset{multipoles/font/.initial=\pgf@circ@font@tiny}
\ctikzset{multipoles/draw only pins/.initial={all}}
\ctikzset{multipoles/draw only left pins/.initial={all}}
\ctikzset{multipoles/draw only right pins/.initial={all}}
\ctikzset{multipoles/draw only top pins/.initial={all}}
\ctikzset{multipoles/draw only bottom pins/.initial={all}}
\pgfqkeys{/tikz}{draw only pins/.add code={}{\ctikzset{multipoles/draw only pins={#1}}}}
\pgfqkeys{/tikz}{draw only left pins/.add code={}{\ctikzset{multipoles/draw only left pins={#1}}}}
\pgfqkeys{/tikz}{draw only right pins/.add code={}{\ctikzset{multipoles/draw only right pins={#1}}}}
\pgfqkeys{/tikz}{draw only top pins/.add code={}{\ctikzset{multipoles/draw only top pins={#1}}}}
\pgfqkeys{/tikz}{draw only bottom pins/.add code={}{\ctikzset{multipoles/draw only bottom pins={#1}}}}
% DIP (dual in line package) chips
\ctikzset{multipoles/dipchip/width/.initial=1.2}
\ctikzset{multipoles/dipchip/num pins/.initial=8}
\ctikzset{multipoles/dipchip/pin spacing/.initial=0.4}
\pgfkeys{/tikz/num pins/.add code={}{\ctikzset{multipoles/dipchip/num pins=#1}}}
% QFP (quad flat package) chips
\ctikzset{multipoles/qfpchip/num pins/.initial=8}
\ctikzset{multipoles/qfpchip/pin spacing/.initial=0.4}
\pgfkeys{/tikz/num pins/.add code={}{\ctikzset{multipoles/qfpchip/num pins=#1}}}
% chip numbers
\newif\ifpgf@circuit@chip@shownumbers\pgf@circuit@chip@shownumberstrue
\pgfkeys{/tikz/show numbers/.add code={}{\pgf@circuit@chip@shownumberstrue}}
\ctikzset{show numbers/.add code={}{\pgf@circuit@chip@shownumberstrue}}
\pgfkeys{/tikz/hide numbers/.add code={}{\pgf@circuit@chip@shownumbersfalse}}
\ctikzset{hide numbers/.add code={}{\pgf@circuit@chip@shownumbersfalse}}
\newif\ifpgf@circuit@chip@straightnumbers\pgf@circuit@chip@straightnumberstrue
\pgfkeys{/tikz/straight numbers/.add code={}{\pgf@circuit@chip@straightnumberstrue}}
\ctikzset{straight numbers/.add code={}{\pgf@circuit@chip@straightnumberstrue}}
\pgfkeys{/tikz/rotated numbers/.add code={}{\pgf@circuit@chip@straightnumbersfalse}}
\ctikzset{rotated numbers/.add code={}{\pgf@circuit@chip@straightnumbersfalse}}
% external chip pins
\ctikzset{multipoles/external pins thickness/.initial=1}
\ctikzset{multipoles/external pins width/.initial=0.2}
\ctikzset{multipoles/external pad fraction/.initial=0}
\pgfkeys{/tikz/external pins width/.add code={}{\ctikzset{multipoles/external pins width=#1}}}
\pgfkeys{/tikz/external pad fraction/.add code={}{\ctikzset{multipoles/external pad fraction=#1}}}
% topmarks
\newif\ifpgf@circuit@chip@topmark\pgf@circuit@chip@topmarktrue
\pgfkeys{/tikz/topmark/.add code={}{\pgf@circuit@chip@topmarktrue}}
\ctikzset{topmark/.add code={}{\pgf@circuit@chip@topmarktrue}}
\pgfkeys{/tikz/no topmark/.add code={}{\pgf@circuit@chip@topmarkfalse}}
\ctikzset{no topmark/.add code={}{\pgf@circuit@chip@topmarkfalse}}

% rotary switch by Romano
\ctikzset{multipoles/rotary/thickness/.initial=1}
\ctikzset{multipoles/rotary/shape/.initial=ocirc}
\ctikzset{multipoles/rotary/channels/.initial=5}
\ctikzset{multipoles/rotary/angle/.initial=60}
\ctikzset{multipoles/rotary/wiper/.initial=20}
\ctikzset{multipoles/rotary/arrow/.is choice}
\newif\ifpgf@circ@rotaryarrow\pgf@circ@rotaryarrowfalse
\newif\ifpgf@circ@rotaryarrow@cw\pgf@circ@rotaryarrow@cwfalse
\newif\ifpgf@circ@rotaryarrow@ccw\pgf@circ@rotaryarrow@ccwfalse
\ctikzset{multipoles/rotary/arrow/none/.code={\pgf@circ@rotaryarrowfalse\pgf@circ@rotaryarrow@cwfalse\pgf@circ@rotaryarrow@ccwfalse}}
\ctikzset{multipoles/rotary/arrow/both/.code={\pgf@circ@rotaryarrowtrue\pgf@circ@rotaryarrow@cwtrue\pgf@circ@rotaryarrow@ccwtrue}}
\ctikzset{multipoles/rotary/arrow/cw/.code={\pgf@circ@rotaryarrowtrue\pgf@circ@rotaryarrow@cwtrue\pgf@circ@rotaryarrow@ccwfalse}}
\ctikzset{multipoles/rotary/arrow/ccw/.code={\pgf@circ@rotaryarrowtrue\pgf@circ@rotaryarrow@cwfalse\pgf@circ@rotaryarrow@ccwtrue}}

\tikzset{%
    rotary switch/.style args={#1in#2wiper#3}{%
        shape=rotaryswitch,
        /tikz/circuitikz/multipoles/rotary/channels=#1,
        /tikz/circuitikz/multipoles/rotary/angle=#2,
        /tikz/circuitikz/multipoles/rotary/wiper=#3,
    },
    rotary switch -/.style args={#1in#2wiper#3}{
        rotary switch=#1 in #2 wiper #3,
        /tikz/circuitikz/multipoles/rotary/arrow=none,
    },
    rotary switch <-/.style args={#1in#2wiper#3}{
        rotary switch=#1 in #2 wiper #3,
        /tikz/circuitikz/multipoles/rotary/arrow=ccw,
    },
    rotary switch ->/.style args={#1in#2wiper#3}{
        rotary switch=#1 in #2 wiper #3,
        /tikz/circuitikz/multipoles/rotary/arrow=cw,
    },
    rotary switch <->/.style args={#1in#2wiper#3}{
        rotary switch=#1 in #2 wiper #3,
        /tikz/circuitikz/multipoles/rotary/arrow=both,
    },
    % Notice that these should be the same as the initial values of the keys
    rotary switch/.default={5 in 60 wiper 20},
    rotary switch -/.default={5 in 60 wiper 20},
    rotary switch <-/.default={5 in 60 wiper 20},
    rotary switch ->/.default={5 in 60 wiper 20},
    rotary switch <->/.default={5 in 60 wiper 20},
}
%%>>>

%% Nodes definitions for chips%<<<

%%%%%%%%%
%% Chips
%%%%%%%%%

% let's use the same shifts everywhere, no magic numbers
\def\pgf@circ@dip@pin@shift{0.5}
\def\pgf@circ@qfp@pin@shift{0.25}

% derived from https://tex.stackexchange.com/a/146753/38080
% original author Mark Wibrow
% Thanks also to John Kormylo https://tex.stackexchange.com/a/372996/38080
% a lot of thanks to @marmot  for the un-rotation hint
% https://tex.stackexchange.com/a/473571/38080
% modifications for 'draw only pins' by Jonathan P. Spratte

% DIP (dual in line package) chips

% helper macro to set the anchors inside a loop (to expand the current count)
\pgfutil@protected\def\pgf@circ@make@dippin@anchor#1%
  {%
    \expandafter\gdef\csname pgf@anchor@dipchip@pin #1\endcsname
      {%
        \pgf@circ@if@num@in@list\pgf@circ@pins@list{#1}
          {\pgf@circ@dippinanchor{#1}{1}}
          {\pgf@circ@dippinanchor{#1}{0}}%
      }%
    \expandafter\gdef\csname pgf@anchor@dipchip@bpin #1\endcsname
      {\pgf@circ@dippinanchor{#1}{0}}%
  }

\pgfdeclareshape{dipchip}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{chips}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedmacro\numpins{%
            \pgf@circ@count@a=\ctikzvalof{multipoles/dipchip/num pins}%
            \def\numpins{\the\pgf@circ@count@a}
    }
    \savedmacro\pgf@circ@pins@list
      {%
        \pgfkeysgetvalue
          {\circuitikzbasekey/multipoles/draw only pins}\pgf@circ@temp
        \expandafter\pgf@circ@set@list
          \expandafter\pgf@circ@pins@list
          \expandafter{\pgf@circ@temp}%
      }%
    \savedanchor\centerpoint{%
        \pgf@x=-.5\wd\pgfnodeparttextbox%
        \pgf@y=-.5\ht\pgfnodeparttextbox%
        \advance\pgf@y by+.5\dp\pgfnodeparttextbox%
    }%
    \savedanchor\origin{\pgfpoint{0pt}{0pt}}
    \anchor{center}{\origin}
    \anchor{text}{\centerpoint}% to adjust text
    \saveddimen\height{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{((\numpins)
        *\ctikzvalof{multipoles/dipchip/pin spacing})*\pgf@circ@scaled@Rlen/2}%
    }%
    \saveddimen{\chipspacing}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{\pgf@circ@scaled@Rlen*\ctikzvalof{multipoles/dipchip/pin spacing}}}
    \saveddimen{\width}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{\pgf@circ@scaled@Rlen*\ctikzvalof{multipoles/dipchip/width}}}
    \saveddimen{\extshift}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{\pgf@circ@scaled@Rlen*\ctikzvalof{multipoles/external pins width}}}
    % standard anchors
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@y{0.5*((\numpins)
        *\ctikzvalof{multipoles/dipchip/pin spacing})*\pgf@circ@scaled@Rlen/2}%
        \pgfmathsetlength\pgf@x{-0.5*\pgf@circ@scaled@Rlen*\ctikzvalof{multipoles/dipchip/width}}
    }
    \anchor{dot}{\northwest
        \pgfmathsetlength\pgf@x{\pgf@x + 0.3*\chipspacing}
        \pgfmathsetlength\pgf@y{\pgf@y - 0.3*\chipspacing}
    }
    \anchor{nw}{\northwest}
    \anchor{ne}{\northwest\pgf@x=-\pgf@x}
    \anchor{se}{\northwest\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
    \anchor{sw}{\northwest\pgf@y=-\pgf@y}
    \anchor{north west}{\northwest}
    \anchor{north east}{\northwest\pgf@x=-\pgf@x}
    \anchor{south east}{\northwest\pgf@x=-\pgf@x \pgf@y=-\pgf@y}
    \anchor{south west}{\northwest\pgf@y=-\pgf@y}
    \anchor{n}{\northwest\pgf@x=0pt }
    \anchor{e}{\northwest\pgf@x=-\pgf@x\pgf@y=0pt }
    \anchor{s}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{w}{\northwest\pgf@y=0pt }
    \anchor{north}{\northwest\pgf@x=0pt }
    \anchor{east}{\northwest\pgf@x=-\pgf@x\pgf@y=0pt }
    \anchor{south}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{west}{\northwest\pgf@y=0pt }
    % start drawing
    \pgf@circ@draw@component{%
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step = \ctikzvalof{multipoles/dipchip/pin spacing}\pgf@circ@scaled@Rlen
        \pgf@circ@res@other = \ctikzvalof{multipoles/external pins width}\pgf@circ@scaled@Rlen
        \pgfscope% (for the line width)
        \pgf@circ@setlinewidth{multipoles}{\pgflinewidth}
        \pgfpathrectanglecorners{\pgfpoint{-\width/2}{-\height/2}}{\pgfpoint{\width/2}{\height/2}}%
        \pgf@circ@draworfill
        %% upside mark
        \ifpgf@circuit@chip@topmark
            \pgfpathmoveto{\pgfpoint{0.2*\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpatharc{0}{180}{0.2*\pgf@circ@res@left}
        \fi
        \pgfusepath{stroke}%
        \pgf@circ@setcolor
        % Adding the pin number
        \ifpgf@circuit@chip@shownumbers
            \pgf@circ@count@a=\numpins\relax
            \divide\pgf@circ@count@a by 2 \pgf@circ@count@b=\pgf@circ@count@a
            % thanks to @marmot: https://tex.stackexchange.com/a/473571/38080
            \ifpgf@circuit@chip@straightnumbers
                \pgfgettransformentries\a\b\temp\temp\temp\temp
                \pgfmathsetmacro{\rot}{-atan2(\b,\a)}
                \pgfmathtruncatemacro{\quadrant}{mod(4+int(360+(\rot+45)/90),4)}
            \else
                \pgfmathsetmacro{\rot}{0}
                \pgfmathsetmacro{\quadrant}{0}
            \fi
            \def\pgf@circ@strut{\vrule width 0pt height 1em depth 0.4em\relax}
            \pgfscope\pgf@circ@text@strokecolor
            \def\mytext{\ctikzvalof{multipoles/font}\space\pgf@circ@strut\the\pgf@circ@count@c\space}
            \pgfmathloop%
            \ifnum\pgf@circ@count@a>0
                \ifcase\quadrant % rotation 0
                    % left
                    \pgf@circ@count@c=\pgf@circ@count@a
                    \pgftext[left,
                        at=\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                    % right
                    \pgf@circ@count@c=\numexpr2*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                    \pgftext[right,
                        at=\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                \or % rotation -90
                    % left
                    \pgf@circ@count@c=\pgf@circ@count@a
                    \pgftext[top,
                        at=\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                    % right
                    \pgf@circ@count@c=\numexpr2*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                    \pgftext[bottom,
                        at=\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                \or %rotation 180
                    % left
                    \pgf@circ@count@c=\pgf@circ@count@a
                    \pgftext[right,
                        at=\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                    % right
                    \pgf@circ@count@c=\numexpr2*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                    \pgftext[left,
                        at=\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                \or % rotation +90
                    % left
                    \pgf@circ@count@c=\pgf@circ@count@a
                    \pgftext[bottom,
                        at=\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                    % right
                    \pgf@circ@count@c=\numexpr2*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                    \pgftext[top,
                        at=\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                \fi
                \advance\pgf@circ@count@a-1\relax%
                \repeatpgfmathloop
                \endpgfscope % for color of text
            \fi
            \endpgfscope
            % draw external pins or pads
            \ifdim\pgf@circ@res@other>0pt
            \ifpgfcirc@draw@input@leads
            \pgfscope
                \pgfsetlinewidth{\ctikzvalof{multipoles/external pins thickness}\pgflinewidth}
                \pgf@circ@count@a=\numpins\relax
                \divide\pgf@circ@count@a by 2 \pgf@circ@count@b=\pgf@circ@count@a
                \edef\padfrac{\ctikzvalof{multipoles/external pad fraction}}
                \ifnum\padfrac>0
                    \pgf@circ@res@temp=\pgf@circ@res@step\divide\pgf@circ@res@temp by \padfrac
                \fi
                \pgfmathloop%
                \ifnum\pgf@circ@count@a>0
                    % left side
                    \pgf@circ@if@num@in@list\pgf@circ@pins@list\pgf@circ@count@a
                      {%
                        \ifnum\padfrac>0
                          % pads
                          \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                          \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgf@circ@res@other}{\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                          \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgf@circ@res@other}{-\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                          \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        \else
                          % pins
                          \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                          \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgf@circ@res@other}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        \fi
                      }
                      {}%
                    % right side
                    \pgf@circ@if@num@in@list\pgf@circ@pins@list{\numpins+1-\pgf@circ@count@a}
                      {%
                        \ifnum\padfrac>0
                          % pads
                          \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                          \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@other}{\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                          \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@other}{-\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                          \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        \else
                          % pins
                          \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                          \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@other}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        \fi
                      }
                      {}%
                    \advance\pgf@circ@count@a by -1\relax%
                \repeatpgfmathloop
                \pgfusepath{stroke}
            \endpgfscope
            \fi
            \fi
        }%
        \pgfutil@g@addto@macro\pgf@sh@s@dipchip{%
          \pgf@circ@count@a=\numpins
          \pgfmathloop
            \ifnum\pgf@circ@count@a>0
            % we will create two anchors per pin: the "normal one" like `pin 1` for the
            % electrical contact, and the "border one" like `bpin 1` for labels.
            % they will coincide if `external pins width` is set to 0.
            % see the helper function above the start of the shape definition (by Jonathan P. Spratte)
            \expandafter\pgf@circ@make@dippin@anchor\expandafter{\the\pgf@circ@count@a}%
            \advance\pgf@circ@count@a by -1\relax
          \repeatpgfmathloop
        }%
        }

% QFP (quad flat package) chips
% helper macro to set the anchors inside a loop (to expand the current count)
\pgfutil@protected\def\pgf@circ@make@qfppin@anchor#1%
  {%
    \expandafter\gdef\csname pgf@anchor@qfpchip@pin #1\endcsname
      {%
        \pgf@circ@if@num@in@list\pgf@circ@pins@list{#1}
          {\pgf@circ@qfppinanchor{#1}{1}}
          {\pgf@circ@qfppinanchor{#1}{0}}%
      }%
    \expandafter\gdef\csname pgf@anchor@qfpchip@bpin #1\endcsname
      {\pgf@circ@qfppinanchor{#1}{0}}%
  }

\pgfdeclareshape{qfpchip}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{chips}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedmacro\numpins{%
            \pgf@circ@count@a=\ctikzvalof{multipoles/qfpchip/num pins}%
            \def\numpins{\the\pgf@circ@count@a}
    }
    \savedmacro\pgf@circ@pins@list
      {% some magic here, thanks to Jonathan P. Spratte
        \pgfkeysgetvalue
          {\circuitikzbasekey/multipoles/draw only pins}\pgf@circ@temp
        \expandafter\pgf@circ@set@list
          \expandafter\pgf@circ@pins@list
          \expandafter{\pgf@circ@temp}%
      }%
    \savedanchor\centerpoint{%
        \pgf@x=-.5\wd\pgfnodeparttextbox%
        \pgf@y=-.5\ht\pgfnodeparttextbox%
        \advance\pgf@y by+.5\dp\pgfnodeparttextbox%
    }%
    \savedanchor\origin{\pgfpoint{0pt}{0pt}}
    \anchor{center}{\origin}
    \anchor{text}{\centerpoint}% to adjust text
    \saveddimen\height{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{((\numpins+2)
        *\ctikzvalof{multipoles/qfpchip/pin spacing})*\pgf@circ@scaled@Rlen/4}%
    }%
    \saveddimen\width{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{((\numpins+2)
        *\ctikzvalof{multipoles/qfpchip/pin spacing})*\pgf@circ@scaled@Rlen/4}%
    }%
    \saveddimen{\chipspacing}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{\pgf@circ@scaled@Rlen*\ctikzvalof{multipoles/qfpchip/pin spacing}}}
    \saveddimen{\extshift}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{\pgf@circ@scaled@Rlen*\ctikzvalof{multipoles/external pins width}}}
    % standard anchors
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@y{0.5*((\numpins+2)
        *\ctikzvalof{multipoles/qfpchip/pin spacing})*\pgf@circ@scaled@Rlen/4}%
        \pgf@x=-\pgf@y
    }
    \anchor{dot}{\northwest
        \pgfmathsetlength\pgf@x{\pgf@x + 0.3*\chipspacing}
        \pgfmathsetlength\pgf@y{\pgf@y - 0.3*\chipspacing}
    }
    \anchor{nw}{\northwest}
    \anchor{ne}{\northwest\pgf@x=-\pgf@x}
    \anchor{se}{\northwest\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
    \anchor{sw}{\northwest\pgf@y=-\pgf@y}
    \anchor{north west}{\northwest}
    \anchor{north east}{\northwest\pgf@x=-\pgf@x}
    \anchor{south east}{\northwest\pgf@x=-\pgf@x \pgf@y=-\pgf@y}
    \anchor{south west}{\northwest\pgf@y=-\pgf@y}
    \anchor{n}{\northwest\pgf@x=0pt }
    \anchor{e}{\northwest\pgf@x=-\pgf@x\pgf@y=0pt }
    \anchor{s}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{w}{\northwest\pgf@y=0pt }
    \anchor{north}{\northwest\pgf@x=0pt }
    \anchor{east}{\northwest\pgf@x=-\pgf@x\pgf@y=0pt }
    \anchor{south}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{west}{\northwest\pgf@y=0pt }
    % start drawing
    \pgf@circ@draw@component{%
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step = \ctikzvalof{multipoles/qfpchip/pin spacing}\pgf@circ@scaled@Rlen
        \pgf@circ@res@other = \ctikzvalof{multipoles/external pins width}\pgf@circ@scaled@Rlen
        \pgfscope% (for the line width)
        \pgf@circ@setlinewidth{multipoles}{\pgflinewidth}
        %% upside mark
        \ifpgf@circuit@chip@topmark
            \pgfpathmoveto{\pgfpoint{-\width/2}{\height/2-\pgf@circ@res@step/2}}
            \pgfpathlineto{\pgfpoint{-\width/2+\pgf@circ@res@step/2}{\height/2}}
        \else
            \pgfpathmoveto{\pgfpoint{-\width/2}{\height/2}}
        \fi
        %% rest of the shape
        \pgfpathlineto{\pgfpoint{\width/2}{\height/2}}
        \pgfpathlineto{\pgfpoint{\width/2}{-\height/2}}
        \pgfpathlineto{\pgfpoint{-\width/2}{-\height/2}}
        \pgfpathclose
        \pgf@circ@draworfill
        % Adding the pin number
        \pgf@circ@setcolor
        \ifpgf@circuit@chip@shownumbers
            \pgf@circ@count@a=\numpins%
            \divide\pgf@circ@count@a by 4 \pgf@circ@count@b=\pgf@circ@count@a
            % thanks to @marmot: https://tex.stackexchange.com/a/473571/38080
            \ifpgf@circuit@chip@straightnumbers
                \pgfgettransformentries\a\b\temp\temp\temp\temp
                \pgfmathsetmacro{\rot}{-atan2(\b,\a)}
                \pgfmathtruncatemacro{\quadrant}{mod(4+int(360+(\rot+45)/90),4)}
            \else
                \pgfmathsetmacro{\rot}{0}
                \pgfmathsetmacro{\quadrant}{0}
            \fi
            \def\pgf@circ@strut{\vrule width 0pt height 1em depth 0.4em\relax}
            \def\mytext{\ctikzvalof{multipoles/font}\space\pgf@circ@strut\the\pgf@circ@count@c\space}
            \pgfscope\pgf@circ@text@strokecolor
            \pgfmathloop%
            \ifnum\pgf@circ@count@a>0
                \ifcase\quadrant % rotation 0
                    % left
                    \pgf@circ@count@c=\pgf@circ@count@a
                    \pgftext[left,
                        at=\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                    % bottom
                    \pgf@circ@count@c=\numexpr\pgf@circ@count@b+\pgf@circ@count@a\relax
                    \pgftext[bottom,
                        at=\pgfpoint{\pgf@circ@res@left-(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@down},
                        rotate=\rot]{\mytext}
                    % right
                    \pgf@circ@count@c=\numexpr3*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                    \pgftext[right,
                        at=\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                    % top
                    \pgf@circ@count@c=\numexpr3*\pgf@circ@count@b+\pgf@circ@count@a\relax
                    \pgftext[top,
                        at=\pgfpoint{\pgf@circ@res@right+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@up},
                        rotate=\rot]{\mytext}
                \or % rotation -90
                    % left
                    \pgf@circ@count@c=\pgf@circ@count@a
                    \pgftext[top,
                        at=\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                    % bottom
                    \pgf@circ@count@c=\numexpr\pgf@circ@count@b+\pgf@circ@count@a\relax
                    \pgftext[left,
                        at=\pgfpoint{\pgf@circ@res@left-(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@down},
                        rotate=\rot]{\mytext}
                    % right
                    \pgf@circ@count@c=\numexpr3*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                    \pgftext[bottom,
                        at=\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                    % top
                    \pgf@circ@count@c=\numexpr3*\pgf@circ@count@b+\pgf@circ@count@a\relax
                    \pgftext[right,
                        at=\pgfpoint{\pgf@circ@res@right+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@up},
                        rotate=\rot]{\mytext}
                \or %rotation 180
                    % left
                    \pgf@circ@count@c=\pgf@circ@count@a
                    \pgftext[right,
                        at=\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                    % bottom
                    \pgf@circ@count@c=\numexpr\pgf@circ@count@b+\pgf@circ@count@a\relax
                    \pgftext[top,
                        at=\pgfpoint{\pgf@circ@res@left-(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@down},
                        rotate=\rot]{\mytext}
                    % right
                    \pgf@circ@count@c=\numexpr3*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                    \pgftext[left,
                        at=\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                    % top
                    \pgf@circ@count@c=\numexpr3*\pgf@circ@count@b+\pgf@circ@count@a\relax
                    \pgftext[bottom,
                        at=\pgfpoint{\pgf@circ@res@right+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@up},
                        rotate=\rot]{\mytext}
                \or % rotation +90
                    % left
                    \pgf@circ@count@c=\pgf@circ@count@a
                    \pgftext[bottom,
                        at=\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                    % bottom
                    \pgf@circ@count@c=\numexpr\pgf@circ@count@b+\pgf@circ@count@a\relax
                    \pgftext[right,
                        at=\pgfpoint{\pgf@circ@res@left-(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@down},
                        rotate=\rot]{\mytext}
                    % right
                    \pgf@circ@count@c=\numexpr3*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                    \pgftext[top,
                        at=\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                        rotate=\rot]{\mytext}
                    % top
                    \pgf@circ@count@c=\numexpr3*\pgf@circ@count@b+\pgf@circ@count@a\relax
                    \pgftext[left,
                        at=\pgfpoint{\pgf@circ@res@right+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@up},
                        rotate=\rot]{\mytext}
                \fi
                \advance\pgf@circ@count@a-1\relax%
                \repeatpgfmathloop
                \endpgfscope % for the text labels
            \fi
            \endpgfscope
            \ifdim\pgf@circ@res@other>0pt
            \ifpgfcirc@draw@input@leads
            \pgfscope
                \pgfsetlinewidth{\ctikzvalof{multipoles/external pins thickness}\pgflinewidth}
                \pgf@circ@count@a=\numpins%
                \divide\pgf@circ@count@a by 4 \pgf@circ@count@b=\pgf@circ@count@a
                \pgfmathloop%
                \ifnum\pgf@circ@count@a>0
                    \edef\padfrac{\ctikzvalof{multipoles/external pad fraction}}
                    \ifnum\padfrac>0
                        \pgf@circ@res@temp=\pgf@circ@res@step\divide\pgf@circ@res@temp by \padfrac
                        % left side pads
                        \pgf@circ@if@num@in@list\pgf@circ@pins@list\pgf@circ@count@a
                        {%
                            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgf@circ@res@other}{\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgf@circ@res@other}{-\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        }{}%
                        % bottom side pads
                        \pgf@circ@if@num@in@list\pgf@circ@pins@list{\numpins/4+\pgf@circ@count@a}
                        {%
                            \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@temp+\pgf@circ@res@left-(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@down}}
                            \pgfpathlineto{\pgfpoint{-\pgf@circ@res@temp+\pgf@circ@res@left-(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@down-\pgf@circ@res@other}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@temp+\pgf@circ@res@left-(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@down-\pgf@circ@res@other}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@temp+\pgf@circ@res@left-(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@down}}
                        }{}%
                        % right side pads
                        \pgf@circ@if@num@in@list\pgf@circ@pins@list{3*\numpins/4+1-\pgf@circ@count@a}
                        {%
                            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@other}{\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@other}{-\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgf@circ@res@temp+\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        }{}%
                        % top side pads
                        \pgf@circ@if@num@in@list\pgf@circ@pins@list{3*\numpins/4+\pgf@circ@count@a}
                        {%
                            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@temp+\pgf@circ@res@right+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@up}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@temp+\pgf@circ@res@right+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@up+\pgf@circ@res@other}}
                            \pgfpathlineto{\pgfpoint{-\pgf@circ@res@temp+\pgf@circ@res@right+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@up+\pgf@circ@res@other}}
                            \pgfpathlineto{\pgfpoint{-\pgf@circ@res@temp+\pgf@circ@res@right+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@up}}
                        }{}%
                    \else
                        % left side pins
                        \pgf@circ@if@num@in@list\pgf@circ@pins@list\pgf@circ@count@a
                        {%
                            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgf@circ@res@other}{\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        }{}%
                        % bottom side pins
                        \pgf@circ@if@num@in@list\pgf@circ@pins@list{\numpins/4+\pgf@circ@count@a}
                        {%
                            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left-(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@down}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@down-\pgf@circ@res@other}}
                        }{}%
                        % right side pins
                        \pgf@circ@if@num@in@list\pgf@circ@pins@list{3*\numpins/4+1-\pgf@circ@count@a}
                        {%
                            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@other}{\pgf@circ@res@up+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        }{}%
                        % top side pins
                        \pgf@circ@if@num@in@list\pgf@circ@pins@list{3*\numpins/4+\pgf@circ@count@a}
                        {%
                            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@up}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+(\pgf@circ@qfp@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}{\pgf@circ@res@up+\pgf@circ@res@other}}
                        }{}%
                    \fi
                    \advance\pgf@circ@count@a-1\relax%
                \repeatpgfmathloop
                \pgfusepath{stroke}
            \endpgfscope
            \fi
            \fi
        }%
        % \pgf@sh@s@<name of the shape here> contains all the code for the shape
        % and is executed just before a node is drawn.
        \pgfutil@g@addto@macro\pgf@sh@s@qfpchip{%
            % Start with the maximum pin number and go backwards.
            \pgf@circ@count@a=\numpins%
            \pgfmathloop%
            \ifnum\pgf@circ@count@a>0
                \expandafter\pgf@circ@make@qfppin@anchor\expandafter{\the\pgf@circ@count@a}%
                \advance\pgf@circ@count@a-1\relax%
            \repeatpgfmathloop%
            }%
        }

%% anchors for DIP
\def\pgf@circ@dippinanchor#1#2{% #1: pin number #2: 0 for border pin, 1 for external pin
    \c@pgf@countc=\numpins\relax
    \divide\c@pgf@countc by 2
    \ifnum #1 > \the\c@pgf@countc
        % right side
        \pgfpoint{\width/2+#2*\extshift}{-\height/2+(\pgf@circ@dip@pin@shift-\c@pgf@countc+#1-1)*\chipspacing}
    \else
        \pgfpoint{-\width/2-#2*\extshift}{\height/2+(\pgf@circ@dip@pin@shift-#1)*\chipspacing}
\fi
}

%% anchors for QFP
\def\pgf@circ@qfppinanchor#1#2{% #1: pin number #2: 0 for border pin, 1 for external pin
    \c@pgf@countc=\numpins\relax
    \divide\c@pgf@countc by 4
    \ifnum #1 > \the\c@pgf@countc
        \c@pgf@countb=\c@pgf@countc \multiply \c@pgf@countb by 2
        \ifnum #1 > \the\c@pgf@countb
            \c@pgf@countb=\c@pgf@countc \multiply \c@pgf@countb by 3
            \ifnum #1 > \the\c@pgf@countb
                % 3*npins/4 < pin, top side
                \pgfpoint{\width/2+(\pgf@circ@qfp@pin@shift+\c@pgf@countb-#1)*\chipspacing}{\height/2+#2*\extshift}%
            \else
                % 2*npins/4 < pin <= 3*npins/4, right side
                \pgfpoint{\width/2+#2*\extshift}{\height/2+(\pgf@circ@qfp@pin@shift-\c@pgf@countb+#1-1)*\chipspacing}%
            \fi
        \else
            %  npins/4 < pin <= 2*npins/4, bottom side
            \pgfpoint{\width/2+(\pgf@circ@qfp@pin@shift-\c@pgf@countb+#1-1)*\chipspacing}{-\height/2-#2*\extshift}%
        \fi
    \else
        % <= npins/4, left side
        \pgfpoint{-\width/2-#2*\extshift}{\height/2+(\pgf@circ@qfp@pin@shift-#1)*\chipspacing}%
    \fi
}% %>>>

%% Nodes definition for rotaryswitch%<<<

%%%%%%%%%%%%%%%%%
%% Rotary Switch
%%%%%%%%%%%%%%%%%

\pgfdeclareshape{rotaryswitch}
{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{switches}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor\northeast{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        % this strange value makes the 2-pole rotary switch equal to the 2 poles cute spdt
        % the magic number is 0.25/cos(35)
        % try to recalculate it for the actual switch
        \pgf@circ@res@temp=\ctikzvalof{tripoles/spdt/width}\pgf@circ@scaled@Rlen
        \pgf@circ@res@temp=.3052\pgf@circ@res@temp
        \edef\a{\ctikzvalof{multipoles/rotary/angle}}
        \edef\r{\ctikzvalof{nodes width}}
        \pgfmathsetlength{\pgf@y}{\r*\pgf@circ@scaled@Rlen +(\a>90 ? 2 : 2*sin(\a))*\pgf@circ@res@temp}
        \pgfmathsetlength{\pgf@x}{\r*\pgf@circ@scaled@Rlen + \pgf@circ@res@temp}
    }
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        % this strange value makes the 2-pole rotary switch equal to the 2 poles cute spdt
        % the magic number is 0.25/cos(35)
        % try to recalculate it for the actual switch
        \pgf@circ@res@temp=\ctikzvalof{tripoles/spdt/width}\pgf@circ@scaled@Rlen
        \pgf@circ@res@temp=.3052\pgf@circ@res@temp
        \edef\a{\ctikzvalof{multipoles/rotary/angle}}
        \edef\r{\ctikzvalof{nodes width}}
        \pgfmathsetlength{\pgf@y}{\r*\pgf@circ@scaled@Rlen +(\a>90 ? 2 : 2*sin(\a))*\pgf@circ@res@temp}
        \pgfmathsetlength{\pgf@x}{-\r*\pgf@circ@scaled@Rlen - (\a<90 ? 1 : 1-2*cos(\a))*\pgf@circ@res@temp}
    }
    \savedanchor\central{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        % this strange value makes the 2-pole rotary switch equal to the 2 poles cute spdt
        % the magic number is 0.25/cos(35)
        % try to recalculate it for the actual switch
        \pgf@circ@res@temp=\ctikzvalof{tripoles/spdt/width}\pgf@circ@scaled@Rlen
        \pgf@circ@res@temp=.3052\pgf@circ@res@temp
        \edef\a{\ctikzvalof{multipoles/rotary/angle}}
        \edef\r{\ctikzvalof{nodes width}}
        \pgfmathsetlength{\pgf@y}{\r*\pgf@circ@scaled@Rlen +(\a>90 ? 2 : 2*sin(\a))*\pgf@circ@res@temp}
        \pgfmathsetlength{\pgf@x}{(\a<90 ? 0 : cos(\a))*\pgf@circ@res@temp}
    }
    % external square limits
    \savedanchor\extnorthwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@x=-\ctikzvalof{tripoles/spdt/width}\pgf@circ@scaled@Rlen
        % this strange value makes the 2-pole rotary switch equal to the 2 poles cute spdt
        \pgf@x=.3052\pgf@x % the magic number is 0.25/cos(35)
        \pgf@x=2.5\pgf@x % external square size
        \pgf@y=-\pgf@x %square thing when angle=180?
    }
    \saveddimen{\width}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{0.3052*\pgf@circ@scaled@Rlen*\ctikzvalof{tripoles/spdt/width}}}
    % radius of the connector
    % This is the radius of the "ocirc" shape (see pgfcircshapes.tex)
    \saveddimen{\radius}{\pgfmathsetlength\pgf@x{\pgf@circ@Rlen*\ctikzvalof{nodes width}}}
    % shapename
    \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
    % shape type
    \savedmacro{\cshape}{\def\cshape{\ctikzvalof{multipoles/rotary/shape}}}
    \savedmacro{\channels}{\def\channels{\ctikzvalof{multipoles/rotary/channels}}}
    \savedmacro{\angle}{\def\angle{\ctikzvalof{multipoles/rotary/angle}}}
    \savedmacro{\wiper}{\def\wiper{\ctikzvalof{multipoles/rotary/wiper}}}
    \savedmacro{\stepa}{\pgfmathsetmacro{\stepa}{2*\ctikzvalof{multipoles/rotary/angle}/(\ctikzvalof{multipoles/rotary/channels}-1)}}
    % mid of the lever, to stack switches
    %\anchor{mid}{\midlever}
    \anchor{mid}{\northwest
        \pgf@circ@res@temp=-\pgf@x
        \pgfmathsetlength{\pgf@x}{\pgf@circ@res@temp*(-1+cos(\wiper))}
        \pgfmathsetlength{\pgf@y}{\pgf@circ@res@temp*sin(\wiper)}
    }
    %
    % Notice that the "in" anchors must mimic "ext center", otherwise they are
    % wrong for angles > 90 degrees!
    %
    % center anchors
    \anchor{cin}{ \pgf@y=0pt \pgf@x=0pt \advance\pgf@x by -\width}
    % horizontal angles
    \anchor{in}{ \pgf@y=0pt \pgf@x=0pt \advance\pgf@x by -\width \advance\pgf@x by -\radius}
    \anchor{ain}{ \pgf@y=0pt \pgf@x=0pt \advance\pgf@x by -\width \advance\pgf@x by -\radius}

    \anchor{center}{ \central \pgf@y=0pt }
    \anchor{east}{ \northeast \pgf@y=0pt }
    \anchor{west}{ \northwest \pgf@y=0pt }
    \anchor{south}{ \central \pgf@y=-\pgf@y }
    \anchor{north}{ \central }
    \anchor{south west}{ \northwest \pgf@y=-\pgf@y }
    \anchor{north east}{ \northeast }
    \anchor{north west}{ \northwest }
    \anchor{south east}{ \northeast \pgf@y=-\pgf@y }

    \anchor{ext center}{ \pgf@y=0pt \pgf@x=0pt \advance\pgf@x by -\width}
    \anchor{ext east}{ \extnorthwest \pgf@y=0pt \pgf@x=-\pgf@x \advance\pgf@x by -\width}
    \anchor{ext west}{ \extnorthwest \pgf@y=0pt \advance\pgf@x by -\width}
    \anchor{ext south}{ \extnorthwest \pgf@x=0pt \pgf@y=-\pgf@y \advance\pgf@x by -\width}
    \anchor{ext north}{ \extnorthwest \pgf@x=0pt \advance\pgf@x by -\width}
    \anchor{ext south west}{ \extnorthwest \pgf@y=-\pgf@y \advance\pgf@x by -\width}
    \anchor{ext north east}{ \extnorthwest \pgf@x=-\pgf@x \advance\pgf@x by -\width}
    \anchor{ext north west}{ \extnorthwest \advance\pgf@x by -\width}
    \anchor{ext south east}{ \extnorthwest \pgf@x=-\pgf@x \pgf@y=-\pgf@y \advance\pgf@x by -\width}

    \pgf@circ@draw@component{
        \pgf@circ@setcolor
        \pgf@circ@res@right = \width
        \pgf@circ@res@left = -\width

        \pgfscope %wiper
        % This is the radius of the "ocirc" shape (see pgfcircshapes.tex)
        \pgf@circ@res@temp=\radius\relax
        \pgf@circ@res@temp=\ctikzvalof{multipoles/rotary/thickness}\pgf@circ@res@temp
        \pgfsetlinewidth{2\pgf@circ@res@temp}
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@circ@res@left}{0pt}}{\pgfpointpolar{\wiper}{2\pgf@circ@res@right}}}
        \pgfsetroundcap\pgfusepath{draw}
        \endpgfscope

        \ifpgf@circ@rotaryarrow
            \pgfscope % arrow
                \pgfcirc@set@arrows{switch}{\ifpgf@circ@rotaryarrow@ccw latexslim\fi}{\ifpgf@circ@rotaryarrow@cw latexslim\fi}
                \pgf@circ@setlinewidth{bipoles}{\pgflinewidth}
                \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}} % center of cin node
                \pgftransformrotate{\wiper}
                \pgfpathmoveto{\pgfpointpolar{50}{1.0\pgf@circ@res@right}}
                \pgfpatharc{50}{-50}{1.0\pgf@circ@res@right}
                \ifpgf@circ@rotaryarrow@ccw
                    \ifpgf@circ@rotaryarrow@cw
                        % both here, maintain values
                        \relax
                    \else
                        % only ccw: remove end arrow
                        \pgfsetarrowsend{}
                    \fi
                \else
                    \ifpgf@circ@rotaryarrow@cw
                        % only cw: remove start arrow
                        \pgfsetarrowsstart{}
                    \else
                        % none: shouldn't happen
                        \relax
                    \fi
                \fi
                \pgfusepath{draw}
            \endpgfscope
        \fi

        % \typeout{CHANNELS\space\channels\space ANGLE\space\angle STEPA\space\stepa}
        \pgf@circ@count@a=\channels\relax
        \pgfmathsetmacro{\currenta}{-\angle}
        \pgfmathloop%
        \ifnum\pgf@circ@count@a>0
            % \typeout{LOOPIN\space\space\the\pgf@circ@count@a\space CURRENTA\space\currenta\space RIGHT\space\the\pgf@circ@res@right}
            \pgfscope
                \pgftransformshift{\pgfpointadd{\pgfpoint{\pgf@circ@res@left}{0pt}}{\pgfpointpolar{\currenta}{2\pgf@circ@res@right}}}
                \pgfnode{\cshape}{center}{}{\thisshape-out \the\pgf@circ@count@a}{\pgfusepath{stroke}}
            \endpgfscope
            \pgfmathsetmacro{\currenta}{\currenta+\stepa}
            % \typeout{LOOPOUT\space\the\pgf@circ@count@a\space CURRENTA\space\currenta\space RIGHT\space\the\pgf@circ@res@right}
            \advance\pgf@circ@count@a by -1\relax%
        \repeatpgfmathloop

        \pgfscope % input
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfnode{\cshape}{center}{}{\thisshape-in}{\pgfusepath{stroke}}
        \endpgfscope
    }
    % \pgf@sh@s@<name of the shape here> contains all the code for the shape
    % and is executed just before a node is drawn.
    \pgfutil@g@addto@macro\pgf@sh@s@rotaryswitch{%
        % Start with the maximum pin number and go backwards.
        \pgf@circ@count@a=\channels\relax
        \pgfmathloop%
        \ifnum\pgf@circ@count@a>0
        % we will create two anchors per pin: the "normal one" like `pin 1` for the
        % electrical contact, and the "border one" like `bpin 1` for labels.
        % they will coincide if `external pins width` is set to 0.
        \expandafter\xdef\csname pgf@anchor@rotaryswitch@out\space\the\pgf@circ@count@a\endcsname{%
            \noexpand\pgf@circ@rotaryanchor{\the\pgf@circ@count@a}{1}{0}%
        }
        \expandafter\xdef\csname pgf@anchor@rotaryswitch@cout\space\the\pgf@circ@count@a\endcsname{%
            \noexpand\pgf@circ@rotaryanchor{\the\pgf@circ@count@a}{0}{0}%
        }
        \expandafter\xdef\csname pgf@anchor@rotaryswitch@aout\space\the\pgf@circ@count@a\endcsname{%
            \noexpand\pgf@circ@rotaryanchor{\the\pgf@circ@count@a}{0}{1}%
        }
        \expandafter\xdef\csname pgf@anchor@rotaryswitch@sqout\space\the\pgf@circ@count@a\endcsname{%
            \noexpand\pgf@circ@rotarysqanchor{\the\pgf@circ@count@a}%
        }
        \advance\pgf@circ@count@a by -1\relax%
        \repeatpgfmathloop%
    }%
}

\def\pgf@circ@rotaryanchor#1#2#3{% #1: numero del pin; #2: 1 - x pos, 0 - center; #3 0: inner, 1 outer
    \pgf@circ@res@temp=\width
    \pgfmathsetmacro{\myangle}{\angle-(#1-1)*\stepa}
    \pgfmathsetlength{\pgf@x}{2*(\pgf@circ@res@temp+#3*\radius/2)*cos(\myangle))+#2*\radius}
    \pgfmathsetlength{\pgf@y}{2*(\pgf@circ@res@temp+#3*\radius/2)*sin(\myangle)}
    \advance\pgf@x by -\pgf@circ@res@temp
}

\def\pgf@circ@rotarysqanchor#1{% external square anchors
    \pgf@circ@res@temp=\width
    \pgfmathsetmacro{\myangle}{\angle-(#1-1)*\stepa}
    \pgfpointborderrectangle{\pgfpointpolar{\myangle}{1pt}}{\pgfpoint{2.5\pgf@circ@res@temp}{2.5\pgf@circ@res@temp}}
    \advance\pgf@x by -\pgf@circ@res@temp
}% %>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%
% Seven segments displays
%%%%%%%%%%%%%%%%%%%%%%%%%%

% Definitions for seven segment displays by RGtti%<<<1

\newif\ifpgf@circ@sevenseg@dot
\newif\ifpgf@circ@sevenseg@box
\def\pgf@circ@sevenseg@dotstate{empty}
\ctikzset{seven seg/.is family}
\ctikzset{seven seg/dot/.is choice}
% none means no dot, not space for it. Empty means no dot, but space
\ctikzset{seven seg/dot/none/.code={\pgf@circ@sevenseg@dotfalse}}
\ctikzset{seven seg/dot/empty/.code={\pgf@circ@sevenseg@dottrue\def\pgf@circ@sevenseg@dotstate{empty}}}
\ctikzset{seven seg/dot/off/.code={\pgf@circ@sevenseg@dottrue\def\pgf@circ@sevenseg@dotstate{off}}}
\ctikzset{seven seg/dot/on/.code={\pgf@circ@sevenseg@dottrue\def\pgf@circ@sevenseg@dotstate{on}}}
%
\ctikzset{seven seg/width/.initial=0.4}% relative to \pgf@circ@Rlen
\ctikzset{seven seg/thickness/.initial=4pt}% segment thickness
\ctikzset{seven seg/segment sep/.initial=0.2pt}% gap between segments
\ctikzset{seven seg/box sep/.initial=1pt}% external box gap
\ctikzset{seven seg/color on/.initial=red}% color for segment "on"
\ctikzset{seven seg/color off/.initial=gray!20!white} % ...and "off"
\ctikzset{seven seg/box/.is choice}
\ctikzset{seven seg/box/off/.code={\pgf@circ@sevenseg@boxfalse}}
\ctikzset{seven seg/box/on/.code={\pgf@circ@sevenseg@boxtrue}}

\ctikzset{seven seg/bits/.initial=0000000}

\ctikzset{seven seg/value/.code={%
    \edef\@@tmp{#1}%
    \edef\@@n{0} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1111110}\fi
    \edef\@@n{1} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=0110000}\fi
    \edef\@@n{2} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1101101}\fi
    \edef\@@n{3} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1111001}\fi
    \edef\@@n{4} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=0110011}\fi
    \edef\@@n{5} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1011011}\fi
    \edef\@@n{6} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1011111}\fi
    \edef\@@n{7} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1110000}\fi
    \edef\@@n{8} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1111111}\fi
    \edef\@@n{9} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1111011}\fi
    \edef\@@n{10}\ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1110111}\fi
    \edef\@@n{11}\ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=0011111}\fi
    \edef\@@n{12}\ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1001110}\fi
    \edef\@@n{13}\ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=0111101}\fi
    \edef\@@n{14}\ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1001111}\fi
    \edef\@@n{15}\ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1000111}\fi
    \edef\@@n{A} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1110111}\fi
    \edef\@@n{B} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=0011111}\fi
    \edef\@@n{C} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1001110}\fi
    \edef\@@n{D} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=0111101}\fi
    \edef\@@n{E} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1001111}\fi
    \edef\@@n{F} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1000111}\fi
    \edef\@@n{a} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1110111}\fi
    \edef\@@n{b} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=0011111}\fi
    \edef\@@n{c} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1001110}\fi
    \edef\@@n{d} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=0111101}\fi
    \edef\@@n{e} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1001111}\fi
    \edef\@@n{f} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=1000111}\fi
    \edef\@@n{-} \ifx\@@tmp\@@n\relax\ctikzset{seven seg/bits=0000001}\fi
}}

\tikzset{%
    seven segment val/.style args={#1dot#2box#3}{%
        shape=bare7seg,
        /tikz/circuitikz/seven seg/value=#1,
        /tikz/circuitikz/seven seg/dot=#2,
        /tikz/circuitikz/seven seg/box=#3,
    },
    seven segment bits/.style args={#1dot#2box#3}{%
        shape=bare7seg,
        /tikz/circuitikz/seven seg/bits=#1,
        /tikz/circuitikz/seven seg/dot=#2,
        /tikz/circuitikz/seven seg/box=#3,
    },
}
%%>>>

%% Nodes definitions for 7-segment display%<<<
\pgfdeclareshape{bare7seg}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{displays}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedmacro{\dotstatus}{\edef\dotstatus{\pgf@circ@sevenseg@dotstate}}
    \saveddimen{\dotspace}{% the dot is on the right, and occupy the same as the thickness
        \ifpgf@circ@sevenseg@dot
            \pgfmathsetlength{\pgf@x}{\ctikzvalof{seven seg/thickness}}
        \else
            \pgf@x=0pt
        \fi
    }
    % The object extension is more or less (-width/2,-width) to (width/2,width)
    % and adjusted for line thickness (both sides) and eventually the dot
    \saveddimen{\width}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength{\pgf@x}{\ctikzvalof{seven seg/width}*\pgf@circ@scaled@Rlen}}
    \saveddimen{\gap}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{seven seg/segment sep}}}
    \saveddimen{\boxgap}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{seven seg/box sep}}}
    \savedanchor{\southwest}{% both negative
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength{\pgf@x}{-0.5*\ctikzvalof{seven seg/width}*\pgf@circ@scaled@Rlen
        -0.5*\ctikzvalof{seven seg/thickness}-\ctikzvalof{seven seg/box sep}}
        \pgfmathsetlength{\pgf@y}{-\ctikzvalof{seven seg/width}*\pgf@circ@scaled@Rlen
        -0.5*\ctikzvalof{seven seg/thickness}-\ctikzvalof{seven seg/box sep}}
    }
    \savedanchor{\northeast}{% both positive
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \ifpgf@circ@sevenseg@dot
            \pgfmathsetlength{\pgf@circ@res@other}{\ctikzvalof{seven seg/thickness}}
        \else
            \pgf@circ@res@other=0pt
        \fi
        \pgfmathsetlength{\pgf@x}{0.5*\ctikzvalof{seven seg/width}*\pgf@circ@scaled@Rlen
        +0.5*\ctikzvalof{seven seg/thickness}+\pgf@circ@res@other+\ctikzvalof{seven seg/box sep}}
        \pgfmathsetlength{\pgf@y}{\ctikzvalof{seven seg/width}*\pgf@circ@scaled@Rlen
        +0.5*\ctikzvalof{seven seg/thickness}+\ctikzvalof{seven seg/box sep}}
    }
    \savedanchor{\topright}{% anchor without the box sep and the thickness
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength{\pgf@x}{0.5*\ctikzvalof{seven seg/width}*\pgf@circ@scaled@Rlen}
        \pgfmathsetlength{\pgf@y}{\ctikzvalof{seven seg/width}*\pgf@circ@scaled@Rlen}
    }
    \anchor{center}{\pgfpointorigin}
    \anchor{north west}{\southwest\pgf@y=-\pgf@y}
    \anchor{north east}{\northeast}
    \anchor{south east}{\northeast\pgf@y=-\pgf@y}
    \anchor{south west}{\southwest}
    \anchor{north}{\northeast\pgf@x=0pt}
    \anchor{east}{\northeast\pgf@y=0pt}
    \anchor{south}{\southwest\pgf@x=0pt}
    \anchor{west}{\southwest\pgf@y=0pt}
    \anchor{a}{\topright\pgf@x=0pt}
    \anchor{b}{\topright\pgf@y=0.5\pgf@y}
    \anchor{c}{\topright\pgf@y=-0.5\pgf@y}
    \anchor{d}{\topright\pgf@y=-\pgf@y\pgf@x=0pt}
    \anchor{e}{\topright\pgf@x=-\pgf@x\pgf@y=-0.5\pgf@y}
    \anchor{f}{\topright\pgf@x=-\pgf@x\pgf@y=0.5\pgf@y}
    \anchor{g}{\pgfpointorigin}
    \anchor{dot}{\topright\pgf@y=-\pgf@y\advance\pgf@x by \dotspace}
    \pgf@circ@draw@component{%
        \southwest % I do not want the dot here, it will stick out
        \pgf@circ@res@up = -\pgf@y
        \pgf@circ@res@down = \pgf@y
        \pgf@circ@res@right = \pgf@x
        \pgf@circ@res@left = -\pgf@x
        \pgfscope
        \pgf@circ@setlinewidth{multipoles}{\pgflinewidth}
        \pgf@circ@setcolor
        \pgfpathrectanglecorners%
        {\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
        {\pgfpoint{\pgf@circ@res@left+\dotspace}{\pgf@circ@res@up}}
        \ifpgf@circ@sevenseg@box
            \pgf@circ@draworfill
        \else
            \pgf@circ@maybefill
        \fi
        \endpgfscope
        \edef\bits{\ctikzvalof{seven seg/bits}}
        \pgfscope
            \pfg@circ@sseg@drawbits{\bits}
        \endpgfscope
        \pgfscope
            \ifpgf@circ@sevenseg@dot
                \pgf@circ@sseg@drawdots
            \fi
        \endpgfscope
    }
}

\def\pgf@circ@sseg@splitbits#1#2#3#4#5#6#7\relax{%split the seven bits
    \edef\@@a{#1}\edef\@@b{#2}\edef\@@c{#3}\edef\@@d{#4}\edef\@@e{#5}\edef\@@f{#6}\edef\@@g{#7}%
}
\def\pgf@circ@sseg@drawone#1#2#3#4#5{% #1 on off the x1, y1, x2 , y2
    \ifnum #1 > 0\relax
        \pgfsetcolor{\ctikzvalof{seven seg/color on}}
    \else
        \pgfsetcolor{\ctikzvalof{seven seg/color off}}
    \fi
    \pgfpathmoveto{\pgfpoint{#2}{#3}}
    \pgfpathlineto{\pgfpoint{#4}{#5}}
    \pgfusepath{draw}
}
\def\pfg@circ@sseg@drawbits#1{% #1 must be 7 bits
    \expandafter\pgf@circ@sseg@splitbits#1\relax% a bit of magic...
    \pgfmathsetlength{\pgf@circ@res@other}{0.5*\ctikzvalof{seven seg/thickness}}
    \pgfsetlinewidth{\ctikzvalof{seven seg/thickness}}
    % \pgfsetroundcap
    \pgfsetarrowsstart{Triangle Cap[]}
    \pgfsetarrowsend{Triangle Cap[]}
    % segments
    \pgf@circ@sseg@drawone{\@@a}{-\width/2+\gap}{\width}{\width/2-\gap}{\width}
    \pgf@circ@sseg@drawone{\@@b}{\width/2}{\width-\gap}{\width/2}{0pt+\gap}
    \pgf@circ@sseg@drawone{\@@c}{\width/2}{0pt-\gap}{\width/2}{-\width+\gap}
    \pgf@circ@sseg@drawone{\@@d}{\width/2-\gap}{-\width}{-\width/2+\gap}{-\width}
    \pgf@circ@sseg@drawone{\@@e}{-\width/2}{-\width+\gap}{-\width/2}{0pt-\gap}
    \pgf@circ@sseg@drawone{\@@f}{-\width/2}{0pt+\gap}{-\width/2}{\width-\gap}
    \pgf@circ@sseg@drawone{\@@g}{-\width/2+\gap}{0pt}{\width/2-\gap}{0pt}
}
\def\pgf@circ@sseg@drawdots{% dots
    \edef\what{empty}
    \ifx\what\pgf@circ@sevenseg@dotstate
        % do nothing
    \else
        \pgfmathsetlength{\pgf@circ@res@other}{0.5*\ctikzvalof{seven seg/thickness}}
        \edef\what{off}
        \ifx\what\pgf@circ@sevenseg@dotstate
            % dot off
            \pgfsetfillcolor{\ctikzvalof{seven seg/color off}}
            \pgfsetcolor{\ctikzvalof{seven seg/color off}}
        \else
            % dot on
            \pgfsetfillcolor{\ctikzvalof{seven seg/color on}}
            \pgfsetcolor{\ctikzvalof{seven seg/color on}}
        \fi
        \pgfpathcircle{\pgfpoint{\width/2+2*\pgf@circ@res@other}{-\width}}{\pgf@circ@res@other}
        \pgfusepath{draw,fill}
    \fi
}
% %>>>

%%%%%%%%%%%%%%%%%%%%%%%%
%% Flip-flops and muxdemuxes
%%%%%%%%%%%%%%%%%%%%%%%%

% Settings for flip flops and muxdemxes%<<<1

%% flip-flop specific keys (most others are the same as chips)

\ctikzset{multipoles/flipflop/font/.initial=\pgf@circ@font@small}
\ctikzset{multipoles/flipflop/fontud/.initial=\pgf@circ@font@tiny}
\ctikzset{multipoles/flipflop/width/.initial=1.2}
\ctikzset{multipoles/flipflop/pin spacing/.initial=0.6}
\ctikzset{multipoles/flipflop/clock wedge size/.initial=0.2}

%% muxdemuxes internal keys

\ctikzset{multipoles/muxdemux/base len/.initial=0.4}
\ctikzset{multipoles/muxdemux/Lh/.initial=8.0}
\ctikzset{multipoles/muxdemux/Rh/.initial=6.0}
\ctikzset{multipoles/muxdemux/w/.initial=3.0}
\ctikzset{multipoles/muxdemux/inset w/.initial=0.0}
\ctikzset{multipoles/muxdemux/inset Lh/.initial=0.0}
\ctikzset{multipoles/muxdemux/inset Rh/.initial=0.0}
\ctikzset{multipoles/muxdemux/NL/.initial=8}
\ctikzset{multipoles/muxdemux/NR/.initial=1}
\ctikzset{multipoles/muxdemux/NB/.initial=3}
\ctikzset{multipoles/muxdemux/NT/.initial=0}
\ctikzset{multipoles/muxdemux/square pins/.initial=0}%
\ctikzset{multipoles/muxdemux/bgpicture/.code={}}%

% Thanks to @marmot
% this should automatically create a key in this subfamily
\pgfkeys{\circuitikzbasekey/multipoles/muxdemux/label/.is family,
    \circuitikzbasekey/multipoles/muxdemux/label,
    .unknown/.code = {
        \pgfkeyssetvalue{\pgfkeyscurrentpath/\pgfkeyscurrentname}{#1}
    }
}
\tikzset{muxdemux def/.code=\pgfqkeys{\circuitikzbasekey/multipoles/muxdemux}{#1}}
\tikzset{muxdemux label/.code=\pgfqkeys{\circuitikzbasekey/multipoles/muxdemux/label}{#1}}
% external (class-like) muxdemux settings for labels
\ctikzset{muxdemux/inner label font/.initial=\pgf@circ@font@tiny}
\ctikzset{muxdemux/outer label font/.initial=\pgf@circ@font@tiny}
\ctikzset{muxdemux/border label font/.initial=\pgf@circ@font@tiny}
\ctikzset{muxdemux/inner label xsep/.initial=2pt}
\ctikzset{muxdemux/inner label ysep/.initial=2pt}
\ctikzset{muxdemux/outer label xsep/.initial=2pt}
\ctikzset{muxdemux/outer label ysep/.initial=2pt}
\ctikzset{muxdemux/border label xsep/.initial=2pt}
\ctikzset{muxdemux/border label ysep/.initial=2pt}
\ctikzset{muxdemux/inner label sep/.code={%
        \ctikzset{muxdemux/inner label xsep=#1}%
        \ctikzset{muxdemux/inner label ysep=#1}%
}}
\ctikzset{muxdemux/outer label sep/.code={%
        \ctikzset{muxdemux/outer label xsep=#1}%
        \ctikzset{muxdemux/outer label ysep=#1}%
}}
\ctikzset{muxdemux/border label sep/.code={%
        \ctikzset{muxdemux/border label xsep=#1}%
        \ctikzset{muxdemux/border label ysep=#1}%
}}
\ctikzset{muxdemux/clock wedge size/.initial=0.2}
%>>>

%% Node shapes definitions for flip flops%<<<

% Flip flops are a specialized kind of dipchip.
% they have a class by themselves

%% flip flop definitions --- by default empty
%% pin texts
\ctikzset{multipoles/flipflop/t1/.initial={}}
\ctikzset{multipoles/flipflop/t2/.initial={}}
\ctikzset{multipoles/flipflop/t3/.initial={}}
\ctikzset{multipoles/flipflop/t4/.initial={}}
\ctikzset{multipoles/flipflop/t5/.initial={}}
\ctikzset{multipoles/flipflop/t6/.initial={}}
\ctikzset{multipoles/flipflop/tu/.initial={}}
\ctikzset{multipoles/flipflop/td/.initial={}}
% pin clock wedge flags
\ctikzset{multipoles/flipflop/c1/.initial={0}}
\ctikzset{multipoles/flipflop/c2/.initial={0}}
\ctikzset{multipoles/flipflop/c3/.initial={0}}
\ctikzset{multipoles/flipflop/c4/.initial={0}}
\ctikzset{multipoles/flipflop/c5/.initial={0}}
\ctikzset{multipoles/flipflop/c6/.initial={0}}
\ctikzset{multipoles/flipflop/cu/.initial={0}}
\ctikzset{multipoles/flipflop/cd/.initial={0}}
% pin negation circle flags
\ctikzset{multipoles/flipflop/n1/.initial={0}}
\ctikzset{multipoles/flipflop/n2/.initial={0}}
\ctikzset{multipoles/flipflop/n3/.initial={0}}
\ctikzset{multipoles/flipflop/n4/.initial={0}}
\ctikzset{multipoles/flipflop/n5/.initial={0}}
\ctikzset{multipoles/flipflop/n6/.initial={0}}
\ctikzset{multipoles/flipflop/nu/.initial={0}}
\ctikzset{multipoles/flipflop/nd/.initial={0}}


% Thanks to @marmot
\tikzset{flipflop def/.code=\pgfqkeys{\circuitikzbasekey/multipoles/flipflop}{#1}}

% default set of flip flops
\tikzset{
    % async
    latch/.style={flipflop, flipflop def={t1=D, t6=Q, t3=CLK, t4=\ctikztextnot{Q}}},
    flipflop SR/.style={flipflop, flipflop def={t1=S, t3=R, t6=Q, t4=\ctikztextnot{Q}}},
    % sync
    flipflop D/.style={flipflop, flipflop def={t1=D, t6=Q, c3=1, t4=\ctikztextnot{Q}}},
    flipflop T/.style={flipflop, flipflop def={t1=T, t6=Q, c3=1, t4=\ctikztextnot{Q}}},
    flipflop JK/.style={flipflop, flipflop def={t1=J, t3=K, c2=1, t6=Q, t4=\ctikztextnot{Q}}},
    % additional features
    add async SR/.style={flipflop def={tu={\ctikztextnot{SET}}, td={\ctikztextnot{RST}}}},
    dot on notQ/.style={flipflop def={t4={Q}, n4=1}},
}

%
% commodity macro to draw the clock wedges. They leave the size of the
% wedge in \pgf@circ@res@temp so that a possible label can be displaced.
%
\def\pgf@circ@do@wedge@left{
    \pgf@circ@res@temp=0pt\relax
    \ifnum\ctikzvalof{multipoles/flipflop/c\the\pgf@circ@count@c}>0
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step+\wedge}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+\wedge}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step-\wedge}}
        \pgfusepath{stroke}
        \pgf@circ@res@temp=\wedge
    \fi
}
\def\pgf@circ@do@wedge@right{
    \pgf@circ@res@temp=0pt\relax
    \ifnum\ctikzvalof{multipoles/flipflop/c\the\pgf@circ@count@c}>0
        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step+\wedge}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\wedge}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step-\wedge}}
        \pgfusepath{stroke}
        \pgf@circ@res@temp=-\wedge
    \fi
}
\def\pgf@circ@do@wedge@up{
    \pgf@circ@res@temp=0pt\relax
    \ifnum\ctikzvalof{multipoles/flipflop/cu}>0
        \pgfpathmoveto{\pgfpoint{-\wedge}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up-\wedge}}
        \pgfpathlineto{\pgfpoint{\wedge}{\pgf@circ@res@up}}
        \pgfusepath{stroke}
        \pgf@circ@res@temp=-\wedge
    \fi
}
\def\pgf@circ@do@wedge@down{
    \pgf@circ@res@temp=0pt\relax
    \ifnum\ctikzvalof{multipoles/flipflop/cd}>0
        \pgfpathmoveto{\pgfpoint{-\wedge}{\pgf@circ@res@down}}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down+\wedge}}
        \pgfpathlineto{\pgfpoint{\wedge}{\pgf@circ@res@down}}
        \pgfusepath{stroke}
        \pgf@circ@res@temp=\wedge
    \fi
}
% generic flip-flop shape
\pgfdeclareshape{flipflop}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{flipflops}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
    \savedmacro\numpins{\def\numpins{6}}
    \savedanchor\centerpoint{%
        \pgf@x=-.5\wd\pgfnodeparttextbox%
        \pgf@y=-.5\ht\pgfnodeparttextbox%
        \advance\pgf@y by+.5\dp\pgfnodeparttextbox%
    }%
    \savedanchor\origin{\pgfpoint{0pt}{0pt}}
    \anchor{center}{\origin}
    \anchor{text}{\centerpoint}% to adjust text
    \saveddimen\height{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{((\numpins)
        *\ctikzvalof{multipoles/flipflop/pin spacing})*\pgf@circ@scaled@Rlen/2}%
    }%
    \saveddimen{\chipspacing}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{\pgf@circ@scaled@Rlen*\ctikzvalof{multipoles/flipflop/pin spacing}}}
    \saveddimen{\width}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{\pgf@circ@scaled@Rlen*\ctikzvalof{multipoles/flipflop/width}}}
    \saveddimen{\extshift}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{\pgf@circ@scaled@Rlen*\ctikzvalof{multipoles/external pins width}}}
    % standard anchors
    \savedanchor\northwest{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@y{0.5*((\numpins)
        *\ctikzvalof{multipoles/flipflop/pin spacing})*\pgf@circ@scaled@Rlen/2}%
        \pgfmathsetlength\pgf@x{-0.5*\pgf@circ@scaled@Rlen*\ctikzvalof{multipoles/flipflop/width}}
    }
    \anchor{dot}{\northwest
        \pgfmathsetlength\pgf@x{\pgf@x + 0.3*\chipspacing}
        \pgfmathsetlength\pgf@y{\pgf@y - 0.3*\chipspacing}
    }
    \anchor{nw}{\northwest}
    \anchor{ne}{\northwest\pgf@x=-\pgf@x}
    \anchor{se}{\northwest\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
    \anchor{sw}{\northwest\pgf@y=-\pgf@y}
    \anchor{north west}{\northwest}
    \anchor{north east}{\northwest\pgf@x=-\pgf@x}
    \anchor{south east}{\northwest\pgf@x=-\pgf@x \pgf@y=-\pgf@y}
    \anchor{south west}{\northwest\pgf@y=-\pgf@y}
    \anchor{n}{\northwest\pgf@x=0pt }
    \anchor{e}{\northwest\pgf@x=-\pgf@x\pgf@y=0pt }
    \anchor{s}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{w}{\northwest\pgf@y=0pt }
    \anchor{north}{\northwest\pgf@x=0pt }
    \anchor{east}{\northwest\pgf@x=-\pgf@x\pgf@y=0pt }
    \anchor{south}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{west}{\northwest\pgf@y=0pt }
    % upper and lower pin
    \anchor{up}{\northwest\pgf@x=0pt\advance\pgf@y by\extshift }
    \anchor{down}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y\advance\pgf@y by-\extshift}
    \anchor{bup}{\northwest\pgf@x=0pt }
    \anchor{bdown}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    % start drawing
    \pgf@circ@draw@component{%
        \northwest
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@right = -\pgf@x
        \pgf@circ@res@left = \pgf@x
        \pgf@circ@scaled@Rlen=\scaledRlen
        \pgf@circ@res@step = \ctikzvalof{multipoles/flipflop/pin spacing}\pgf@circ@scaled@Rlen
        \pgf@circ@res@other = \ctikzvalof{multipoles/external pins width}\pgf@circ@scaled@Rlen
        \pgf@circ@setcolor
        \pgfscope% (for the line width)
            \pgf@circ@setlinewidth{multipoles}{\pgflinewidth}
            \pgfpathrectanglecorners{\pgfpoint{-\width/2}{-\height/2}}{\pgfpoint{\width/2}{\height/2}}%
            \pgf@circ@draworfill
            \pgfusepath{stroke}%
        \endpgfscope
        % Adding the pin number
        \pgf@circ@count@a=\numpins\relax
        \divide\pgf@circ@count@a by 2 \pgf@circ@count@b=\pgf@circ@count@a
        % thanks to @marmot: https://tex.stackexchange.com/a/473571/38080
        \ifpgf@circuit@chip@straightnumbers
            \pgfgettransformentries\a\b\temp\temp\temp\temp
            \pgfmathsetmacro{\rot}{-atan2(\b,\a)}
            \pgfmathtruncatemacro{\quadrant}{mod(4+int(360+(\rot+45)/90),4)}
        \else
            \pgfmathsetmacro{\rot}{0}
            \pgfmathsetmacro{\quadrant}{0}
        \fi
        \def\pgf@circ@strut{\vrule width 0pt height 1em depth 0.4em\relax}
        \pgfscope\pgf@circ@text@strokecolor
        % text
        \def\mytext{\ctikzvalof{multipoles/flipflop/font}\space
                \ctikzvalof{multipoles/flipflop/t\the\pgf@circ@count@c}%
                \pgf@circ@strut\space}
        % \typeout{TEXT\space\mytext}
        \pgfmathloop%
        \def\wedge{\ctikzvalof{multipoles/flipflop/clock wedge size}\pgf@circ@res@step}
        \pgf@circ@res@temp=0pt\relax
        \ifnum\pgf@circ@count@a>0
            \ifcase\quadrant % rotation 0
                % left
                \pgf@circ@count@c=\pgf@circ@count@a
                \pgf@circ@do@wedge@left
                % \typeout{TEXT Left Q1\space\mytext}
                \pgftext[left,
                    at=\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@temp}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                    rotate=\rot]{\mytext}
                % right
                \pgf@circ@count@c=\numexpr2*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                \pgf@circ@do@wedge@right
                \pgftext[right,
                    at=\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@temp}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                    rotate=\rot]{\mytext}
            \or % rotation -90
                % left
                \pgf@circ@count@c=\pgf@circ@count@a
                \pgf@circ@do@wedge@left
                \pgftext[top,
                    at=\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@temp}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                    rotate=\rot]{\mytext}
                % right
                \pgf@circ@count@c=\numexpr2*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                \pgf@circ@do@wedge@right
                \pgftext[bottom,
                    at=\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@temp}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                    rotate=\rot]{\mytext}
            \or %rotation 180
                % left
                \pgf@circ@count@c=\pgf@circ@count@a
                \pgf@circ@do@wedge@left
                \pgftext[right,
                    at=\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@temp}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                    rotate=\rot]{\mytext}
                % right
                \pgf@circ@count@c=\numexpr2*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                \pgf@circ@do@wedge@right
                \pgftext[left,
                    at=\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@temp}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                    rotate=\rot]{\mytext}
            \or % rotation +90
                % left
                \pgf@circ@count@c=\pgf@circ@count@a
                \pgf@circ@do@wedge@left
                \pgftext[bottom,
                    at=\pgfpoint{\pgf@circ@res@left+\pgf@circ@res@temp}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                    rotate=\rot]{\mytext}
                % right
                \pgf@circ@count@c=\numexpr2*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                \pgf@circ@do@wedge@right
                \pgftext[top,
                    at=\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@temp}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step},
                    rotate=\rot]{\mytext}
            \fi
            \advance\pgf@circ@count@a-1\relax%
            \repeatpgfmathloop
            % Now the up and down text
            % up
            \def\mytext{\ctikzvalof{multipoles/flipflop/fontud}\space\pgf@circ@strut\ctikzvalof{multipoles/flipflop/tu}\space}
            \pgf@circ@do@wedge@up
            \ifcase\quadrant % rotation 0
                \pgftext[top,
                    at=\pgfpoint{0pt}{\pgf@circ@res@up+\pgf@circ@res@temp},
                    rotate=\rot]{\mytext}
            \or % rotation -90
                \pgftext[right,
                    at=\pgfpoint{0pt}{\pgf@circ@res@up+\pgf@circ@res@temp},
                    rotate=\rot]{\mytext}
            \or %rotation 180
                \pgftext[bottom,
                    at=\pgfpoint{0pt}{\pgf@circ@res@up+\pgf@circ@res@temp},
                    rotate=\rot]{\mytext}
            \or % rotation +90
                \pgftext[left,
                    at=\pgfpoint{0pt}{\pgf@circ@res@up+\pgf@circ@res@temp},
                    rotate=\rot]{\mytext}
            \fi
            % down
            \def\mytext{\ctikzvalof{multipoles/flipflop/fontud}\space\pgf@circ@strut\ctikzvalof{multipoles/flipflop/td}\space}
            \pgf@circ@do@wedge@down
            \ifcase\quadrant % rotation 0
                \pgftext[bottom,
                    at=\pgfpoint{0pt}{\pgf@circ@res@down+\pgf@circ@res@temp},
                    rotate=\rot]{\mytext}
            \or % rotation -90
                \pgftext[left,
                    at=\pgfpoint{0pt}{\pgf@circ@res@down+\pgf@circ@res@temp},
                    rotate=\rot]{\mytext}
            \or %rotation 180
                \pgftext[top,
                    at=\pgfpoint{0pt}{\pgf@circ@res@down+\pgf@circ@res@temp},
                    rotate=\rot]{\mytext}
            \or % rotation +90
                \pgftext[right,
                    at=\pgfpoint{0pt}{\pgf@circ@res@down+\pgf@circ@res@temp},
                    rotate=\rot]{\mytext}
            \fi
            \endpgfscope % for text labels
            % external pins
            \ifdim\pgf@circ@res@other>0pt
            \pgfscope
                \pgfsetlinewidth{\ctikzvalof{multipoles/external pins thickness}\pgflinewidth}
                \pgf@circ@count@a=\numpins\relax
                \divide\pgf@circ@count@a by 2 \pgf@circ@count@b=\pgf@circ@count@a
                \pgfmathloop%
                \ifnum\pgf@circ@count@a>0
                    % left side pins
                    \pgf@circ@count@c=\pgf@circ@count@a
                    %% we draw the pin only if it's defined either a text, a clock wedge or a not pin
                    %% Or'ing tests in core TeX is tough
                    \edef\@@or{0}
                    % Just expand the key the minimum needed
                    \edef\@@tmp{x\unexpandedvalueof{/tikz/circuitikz/multipoles/flipflop/t\the\pgf@circ@count@c}}\edef\@@x{x}
                    \ifx\@@tmp\@@x\else\edef\@@or{1}\fi
                    \edef\@@tmp{\ctikzvalof{multipoles/flipflop/c\the\pgf@circ@count@c}}
                    \ifnum\@@tmp>0\edef\@@or{1}\fi
                    \edef\@@tmp{\ctikzvalof{multipoles/flipflop/n\the\pgf@circ@count@c}}
                    \ifnum\@@tmp>0\edef\@@or{1}\fi
                    \ifnum\@@or>0
                        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\pgf@circ@res@other}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        \pgfusepath{stroke}
                    \fi
                    % right side pins
                    \pgf@circ@count@c=\numexpr2*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                    \edef\@@or{0}
                    \edef\@@tmp{x\unexpandedvalueof{/tikz/circuitikz/multipoles/flipflop/t\the\pgf@circ@count@c}}\edef\@@x{x}
                    \ifx\@@tmp\@@x\else\edef\@@or{1}\fi
                    \edef\@@tmp{\ctikzvalof{multipoles/flipflop/c\the\pgf@circ@count@c}}
                    \ifnum\@@tmp>0\edef\@@or{1}\fi
                    \edef\@@tmp{\ctikzvalof{multipoles/flipflop/n\the\pgf@circ@count@c}}
                    \ifnum\@@tmp>0\edef\@@or{1}\fi
                    % \typeout{TEST\space\@@tmp\space\@@x}
                    \ifnum\@@or>0
                        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\pgf@circ@res@other}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        \pgfusepath{stroke}
                    \fi
                    \advance\pgf@circ@count@a by -1\relax%
                \repeatpgfmathloop
                % up side
                \edef\@@or{0}
                \edef\@@tmp{x\unexpandedvalueof{/tikz/circuitikz/multipoles/flipflop/tu}}\edef\@@x{x}
                \ifx\@@tmp\@@x\else\edef\@@or{1}\fi
                \edef\@@tmp{\ctikzvalof{multipoles/flipflop/cu}}
                \ifnum\@@tmp>0\edef\@@or{1}\fi
                \edef\@@tmp{\ctikzvalof{multipoles/flipflop/nu}}
                \ifnum\@@tmp>0\edef\@@or{1}\fi
                % \typeout{TEST\space\@@tmp\space\@@x}
                \ifnum\@@or>0
                    \pgfpathmoveto{\pgfpoint{0pt}{\pgf@circ@res@up}}
                    \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up+\pgf@circ@res@other}}
                    \pgfusepath{stroke}
                \fi
                % down side
                \edef\@@or{0}
                \edef\@@tmp{x\unexpandedvalueof{/tikz/circuitikz/multipoles/flipflop/td}}\edef\@@x{x}
                \ifx\@@tmp\@@x\else\edef\@@or{1}\fi
                \edef\@@tmp{\ctikzvalof{multipoles/flipflop/cd}}
                \ifnum\@@tmp>0\edef\@@or{1}\fi
                \edef\@@tmp{\ctikzvalof{multipoles/flipflop/nd}}
                \ifnum\@@tmp>0\edef\@@or{1}\fi
                % \typeout{TEST\space\@@tmp\space\@@x}
                \ifnum\@@or>0
                    \pgfpathmoveto{\pgfpoint{0pt}{\pgf@circ@res@down}}
                    \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@down-\pgf@circ@res@other}}
                    \pgfusepath{stroke}
                \fi
            \endpgfscope
            \fi % external pin width >0
            %
            % draw "inverting" circles on outputs, they must be last
            %
            \pgfscope
                \ifpgf@circuit@ieeelogicport
                    \def\@@notcirc{notcirc}
                \else
                    \ifpgf@circ@european@port@circle@ieee
                        \def\@@notcirc{notcirc}
                    \else
                        \def\@@notcirc{ocirc}
                    \fi
                \fi
                \pgfsetlinewidth{\ctikzvalof{multipoles/external pins thickness}\pgflinewidth}
                \pgf@circ@count@a=\numpins\relax
                \divide\pgf@circ@count@a by 2 \pgf@circ@count@b=\pgf@circ@count@a
                \pgfmathloop%
                \ifnum\pgf@circ@count@a>0
                    % left side pins
                    \pgf@circ@count@c=\pgf@circ@count@a
                    \edef\@@tmp{\ctikzvalof{multipoles/flipflop/n\the\pgf@circ@count@c}}
                    \ifnum\@@tmp>0\pgfscope
                        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        \pgfnode{\@@notcirc}{east}{}{\thisshape-N\the\pgf@circ@count@c}{\pgfusepath{stroke}}
                    \endpgfscope\fi
                    % right side pins
                    \pgf@circ@count@c=\numexpr2*\pgf@circ@count@b-\pgf@circ@count@a+1\relax
                    \edef\@@tmp{\ctikzvalof{multipoles/flipflop/n\the\pgf@circ@count@c}}
                    \ifnum\@@tmp>0\pgfscope
                        \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(\pgf@circ@dip@pin@shift-\the\pgf@circ@count@a)*\pgf@circ@res@step}}
                        \pgfnode{\@@notcirc}{west}{}{\thisshape-N\the\pgf@circ@count@c}{\pgfusepath{stroke}}
                    \endpgfscope\fi
                    \advance\pgf@circ@count@a by -1\relax%
                \repeatpgfmathloop
                % up side
                \edef\@@tmp{\ctikzvalof{multipoles/flipflop/nu}}
                \ifnum\@@tmp>0\pgfscope
                    \pgftransformshift{\pgfpoint{0pt}{\pgf@circ@res@up}}
                    \pgfnode{\@@notcirc}{south}{}{\thisshape-Nu}{\pgfusepath{stroke}}
                \endpgfscope\fi
                % down side
                \edef\@@tmp{\ctikzvalof{multipoles/flipflop/nd}}
                \ifnum\@@tmp>0\pgfscope
                    \pgftransformshift{\pgfpoint{0pt}{\pgf@circ@res@down}}
                    \pgfnode{\@@notcirc}{north}{}{\thisshape-Nd}{\pgfusepath{stroke}}
                \endpgfscope\fi
            \endpgfscope
        }%
        % \pgf@sh@s@<name of the shape here> contains all the code for the shape
        % and is executed just before a node is drawn.
        \pgfutil@g@addto@macro\pgf@sh@s@flipflop{%
            % Start with the maximum pin number and go backwards.
            \pgf@circ@count@a=\numpins\relax
            \pgfmathloop%
            \ifnum\pgf@circ@count@a>0
                % we will create two anchors per pin: the "normal one" like `pin 1` for the
                % electrical contact, and the "border one" like `bpin 1` for labels.
                % they will coincide if `external pins width` is set to 0.
                \expandafter\xdef\csname pgf@anchor@flipflop@pin\space\the\pgf@circ@count@a\endcsname{%
                    \noexpand\pgf@circ@dippinanchor{\the\pgf@circ@count@a}{1}%
                }
                \expandafter\xdef\csname pgf@anchor@flipflop@bpin\space\the\pgf@circ@count@a\endcsname{%
                    \noexpand\pgf@circ@dippinanchor{\the\pgf@circ@count@a}{0}%
                }
                \advance\pgf@circ@count@a by -1\relax%
                \repeatpgfmathloop%
            }%
}

% clock wedge shape, for using in other shapes like muxdemuxes
\pgfdeclareshape{clockwedge}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{flipflops}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor{\northeast}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength{\pgf@circ@res@step}{\ctikzvalof{multipoles/flipflop/clock wedge size}*\ctikzvalof{multipoles/flipflop/pin spacing}*\pgf@circ@scaled@Rlen}
        \pgf@y=\pgf@circ@res@step
        \pgf@x=\pgf@circ@res@step
    }
    \anchor{center}{\pgfpointorigin}
    \anchor{north west}{\northeast\pgf@x=0pt }
    \anchor{north east}{\northeast}
    \anchor{south east}{\northeast\pgf@y=-\pgf@y}
    \anchor{south west}{\northeast\pgf@y=-\pgf@y\pgf@x=0pt }
    \anchor{north}{\northeast\pgf@x=0.5\pgf@x }
    \anchor{east}{\northeast\pgf@y=0pt }
    \anchor{south}{\northeast\pgf@x=0.5\pgf@x\pgf@y=-\pgf@y}
    \anchor{west}{\pgfpointorigin}
    \anchor{nw}{\northeast\pgf@x=0pt }
    \anchor{ne}{\northeast}
    \anchor{se}{\northeast\pgf@y=-\pgf@y}
    \anchor{sw}{\northeast\pgf@y=-\pgf@y\pgf@x=0pt }
    \anchor{n}{\northeast\pgf@x=0.5\pgf@x }
    \anchor{e}{\northeast\pgf@y=0pt }
    \anchor{s}{\northeast\pgf@x=0.5\pgf@x\pgf@y=-\pgf@y}
    \anchor{w}{\pgfpointorigin}
    \anchor{left}{\pgfpointorigin}
    \anchor{right}{\northeast\pgf@y=0pt }
    \anchor{text}{\northeast\advance \pgf@x by 2pt
        \pgf@y=\dimexpr.5\dp\pgfnodeparttextbox-.5\ht\pgfnodeparttextbox\relax}% to adjust text
    \pgf@circ@draw@component{%
        \northeast
        \pgf@circ@res@up=\pgf@y
        \pgf@circ@res@right=\pgf@x
        \pgfpathmoveto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathlineto{\pgfpoint{0pt}{-\pgf@circ@res@up}}
        \pgfusepath{stroke}
    }
}

% %>>>

%% Node shapes for mux-demuxes%<<<

%
% MUX-DEMUXES
%
% predefined muxdemux shapes (see manual)
%
\tikzset{demux/.style={muxdemux, muxdemux def={Lh=4, Rh=8, NL=1, NB=3, NR=8}}}
\tikzset{one bit adder/.style={muxdemux,
         muxdemux def={Lh=4, NL=2, Rh=2, NR=1, NB=1, w=1.5,
         inset w=0.5, inset Lh=2, inset Rh=1.5}}}
\tikzset{ALU/.style={muxdemux,
         muxdemux def={Lh=5, NL=2, Rh=2, NR=1, NB=2, NT=1, w=2,
         inset w=1, inset Lh=2, inset Rh=0, square pins=1}}}
%generic mux-demux shape
% helper macros to set the anchors inside a loop (to expand the current count)
% left
\pgfutil@protected\def\pgf@circ@make@muxdemux@L@anchor#1%
  {%
    \expandafter\gdef\csname pgf@anchor@muxdemux@lpin #1\endcsname
      {%
        \pgf@circ@if@num@in@list\pgf@circ@Lpins@list{#1}
          {\pgf@circ@muxdemux@L@anchor{#1}{1}}
          {\pgf@circ@muxdemux@L@anchor{#1}{0}}%
      }%
    \expandafter\gdef\csname pgf@anchor@muxdemux@blpin #1\endcsname
      {\pgf@circ@muxdemux@L@anchor{#1}{0}}%
  }
% right
\pgfutil@protected\def\pgf@circ@make@muxdemux@R@anchor#1%
  {%
    \expandafter\gdef\csname pgf@anchor@muxdemux@rpin #1\endcsname
      {%
        \pgf@circ@if@num@in@list\pgf@circ@Rpins@list{#1}
          {\pgf@circ@muxdemux@R@anchor{#1}{1}}
          {\pgf@circ@muxdemux@R@anchor{#1}{0}}%
      }%
    \expandafter\gdef\csname pgf@anchor@muxdemux@brpin #1\endcsname
      {\pgf@circ@muxdemux@R@anchor{#1}{0}}%
  }
% bottom
\pgfutil@protected\def\pgf@circ@make@muxdemux@B@anchor#1%
  {%
    \expandafter\gdef\csname pgf@anchor@muxdemux@bpin #1\endcsname
      {%
        \pgf@circ@if@num@in@list\pgf@circ@Bpins@list{#1}
          {\pgf@circ@muxdemux@B@anchor{#1}{1}}
          {\pgf@circ@muxdemux@B@anchor{#1}{0}}%
      }%
    \expandafter\gdef\csname pgf@anchor@muxdemux@bbpin #1\endcsname
      {\pgf@circ@muxdemux@B@anchor{#1}{0}}%
  }
% top
\pgfutil@protected\def\pgf@circ@make@muxdemux@T@anchor#1%
  {%
    \expandafter\gdef\csname pgf@anchor@muxdemux@tpin #1\endcsname
      {%
        \pgf@circ@if@num@in@list\pgf@circ@Tpins@list{#1}
          {\pgf@circ@muxdemux@T@anchor{#1}{1}}
          {\pgf@circ@muxdemux@T@anchor{#1}{0}}%
      }%
    \expandafter\gdef\csname pgf@anchor@muxdemux@btpin #1\endcsname
      {\pgf@circ@muxdemux@T@anchor{#1}{0}}%
  }
%% put some label somewhere
\def\pgf@circ@muxdemux@label@xy#1#2#3#4#5#6#7{%
    % #1: which label: L,R,T,B or the outer ones with U/D/R/L
    % #2: rotation
    % #3: scale pad x
    % #4: scale pad y
    % #5: text position
    % #6: operation on label text
    % #7: type: inner, outer, border
    % uses external variables \pgf@circ@count@a unless it's zero, in which case omit it
    \ifnum\pgf@circ@count@a=0
        \edef\@@thislabel{\circuitikzbasekey/multipoles/muxdemux/label/#1}
    \else
        \edef\@@thislabel{\circuitikzbasekey/multipoles/muxdemux/label/#1\the\pgf@circ@count@a}
    \fi
    \pgfkeysifdefined{\@@thislabel}{%
        \pgfscope
            \pgftransformrotate{#2}
            \pgfmathsetlength\pgf@circ@res@zero{\pgfkeysvalueof{\circuitikzbasekey/muxdemux/#7 label xsep}}
            \pgfmathsetlength\pgf@circ@res@other{\pgfkeysvalueof{\circuitikzbasekey/muxdemux/#7 label ysep}}
            %%% temp is added when we have wedges; it's a bit of a hack but it works if #3,#4 are -1,0,+1
            \pgftransformxshift{(#3)*(\pgf@circ@res@zero+\pgf@circ@res@temp)}
            \pgftransformyshift{(#4)*(\pgf@circ@res@other+\pgf@circ@res@temp)}
            % Ok, now we have the point in the correct position, we add the label
                \pgftext[#5]{\pgfkeysvalueof{\circuitikzbasekey/muxdemux/#7 label font}%
                \expandafter\csname#6\endcsname{\pgfkeysvalueof{\@@thislabel}}}
        \endpgfscope
    }{}
}
%% put a clock wedge here
\def\pgf@circ@muxdemux@clockwedge#1#2{%
    % #1: which label: cL,cR,cT,cB
    % #2: rotation
    % uses external variables \pgf@circ@count@a
    \edef\@@thislabel{\circuitikzbasekey/multipoles/muxdemux/label/#1\the\pgf@circ@count@a}
    \pgfkeysifdefined{\@@thislabel}{%
        \edef\value{\pgfkeysvalueof{\@@thislabel}}
        \ifnum\value=0
            \pgf@circ@res@temp=0pt
        \else\pgfscope
            \pgftransformrotate{#2}
            \pgfpathmoveto{\pgfpoint{+0pt}{-\clockwedge}}
            \pgfpathlineto{\pgfpoint{\clockwedge}{+0pt}}
            \pgfpathlineto{\pgfpoint{+0pt}{\clockwedge}}
            \pgfusepath{draw}
        \endpgfscope
            \pgf@circ@res@temp=\clockwedge
        \fi
    }{}
}
%% put a negation here
\def\pgf@circ@muxdemux@not@ball#1#2{%
    % #1: which label: nL,nR,nT,nB
    % #2: anchor
    % uses external variables \pgf@circ@count@a
    \edef\@@thislabel{\circuitikzbasekey/multipoles/muxdemux/label/#1\the\pgf@circ@count@a}
    \pgfkeysifdefined{\@@thislabel}{%
        \edef\value{\pgfkeysvalueof{\@@thislabel}}
        \ifnum\value=0
        \else
            \pgfnode{\@@notcirc}{#2}{}{\thisshape-#1\the\pgf@circ@count@a}{\pgfusepath{stroke}}
        \fi
    }{}
}
%% put a negation wedge here
\def\pgf@circ@muxdemux@not@wedge#1#2#3#4#5{%
    % #1: which label: wi/wp with L,R,T,B
    % #2: anchor
    % #3: xscale
    % #4: yscale
    % #5: rotation
    % uses external variables \pgf@circ@count@a
    \edef\@@thislabel{\circuitikzbasekey/multipoles/muxdemux/label/#1\the\pgf@circ@count@a}
    \pgfkeysifdefined{\@@thislabel}{%
        \edef\value{\pgfkeysvalueof{\@@thislabel}}
        \ifnum\value=0
        \else\pgfscope
            \pgftransformrotate{#5}
            \pgftransformxscale{#3}
            \pgftransformyscale{#4}
            \pgftransformyscale{\value}% to flip
            \pgfnode{wedgeinv}{#2}{}{\thisshape-#1\the\pgf@circ@count@a}{\pgfusepath{stroke}}
        \endpgfscope\fi
    }{}
}
%
\pgfdeclareshape{muxdemux}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{muxdemuxes}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
    % pins on the four sides
    \savedmacro\NL{\edef\NL{\ctikzvalof{multipoles/muxdemux/NL}}}
    \savedmacro\NR{\edef\NR{\ctikzvalof{multipoles/muxdemux/NR}}}
    \savedmacro\NT{\edef\NT{\ctikzvalof{multipoles/muxdemux/NT}}}
    \savedmacro\NB{\edef\NB{\ctikzvalof{multipoles/muxdemux/NB}}}
    \savedmacro\squarepins{\edef\squarepins{\ctikzvalof{multipoles/muxdemux/square pins}}}
    % pin lists
    \savedmacro\pgf@circ@Lpins@list
      {%
        \pgfkeysgetvalue
          {\circuitikzbasekey/multipoles/draw only left pins}\pgf@circ@temp
        \expandafter\pgf@circ@set@list
          \expandafter\pgf@circ@Lpins@list
          \expandafter{\pgf@circ@temp}%
      }%
    \savedmacro\pgf@circ@Rpins@list
      {%
        \pgfkeysgetvalue
          {\circuitikzbasekey/multipoles/draw only right pins}\pgf@circ@temp
        \expandafter\pgf@circ@set@list
          \expandafter\pgf@circ@Rpins@list
          \expandafter{\pgf@circ@temp}%
      }%
    \savedmacro\pgf@circ@Tpins@list
      {%
        \pgfkeysgetvalue
          {\circuitikzbasekey/multipoles/draw only top pins}\pgf@circ@temp
        \expandafter\pgf@circ@set@list
          \expandafter\pgf@circ@Tpins@list
          \expandafter{\pgf@circ@temp}%
      }%
    \savedmacro\pgf@circ@Bpins@list
      {%
        \pgfkeysgetvalue
          {\circuitikzbasekey/multipoles/draw only bottom pins}\pgf@circ@temp
        \expandafter\pgf@circ@set@list
          \expandafter\pgf@circ@Bpins@list
          \expandafter{\pgf@circ@temp}%
      }%
    % topleft and topright sizes
    \savedanchor{\topleft}{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@y{\ctikzvalof{multipoles/muxdemux/base len}*\ctikzvalof{multipoles/muxdemux/Lh}*\pgf@circ@scaled@Rlen/2}
        \pgfmathsetlength\pgf@x{-\ctikzvalof{multipoles/muxdemux/base len}*\ctikzvalof{multipoles/muxdemux/w}*\pgf@circ@scaled@Rlen/2}
    }
    \savedanchor{\topright}{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@y{\ctikzvalof{multipoles/muxdemux/base len}*\ctikzvalof{multipoles/muxdemux/Rh}*\pgf@circ@scaled@Rlen/2}
        \pgfmathsetlength\pgf@x{\ctikzvalof{multipoles/muxdemux/base len}*\ctikzvalof{multipoles/muxdemux/w}*\pgf@circ@scaled@Rlen/2}
    }
    \savedanchor{\insetnortheast}{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@y{\ctikzvalof{multipoles/muxdemux/base len}*\ctikzvalof{multipoles/muxdemux/inset Lh}*\pgf@circ@scaled@Rlen/2}
        \pgfmathsetlength\pgf@x{-\ctikzvalof{multipoles/muxdemux/base len}*
        (\ctikzvalof{multipoles/muxdemux/w}-2*\ctikzvalof{multipoles/muxdemux/inset w})*\pgf@circ@scaled@Rlen/2}
    }
    \saveddimen{\insethright}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{\ctikzvalof{multipoles/muxdemux/base len}*\ctikzvalof{multipoles/muxdemux/inset Rh}*\pgf@circ@scaled@Rlen/2}}
    \saveddimen{\extshift}{
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{\pgf@circ@scaled@Rlen*\ctikzvalof{multipoles/external pins width}}}
    \savedanchor{\northwest}{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@y{\ctikzvalof{multipoles/muxdemux/base len}*max(\ctikzvalof{multipoles/muxdemux/Rh},\ctikzvalof{multipoles/muxdemux/Lh})*\pgf@circ@scaled@Rlen/2}
        \pgfmathsetlength\pgf@x{-\ctikzvalof{multipoles/muxdemux/base len}*\ctikzvalof{multipoles/muxdemux/w}*\pgf@circ@scaled@Rlen/2}
    }
    \anchor{nw}{\northwest}
    \anchor{ne}{\northwest\pgf@x=-\pgf@x}
    \anchor{se}{\northwest\pgf@x=-\pgf@x\pgf@y=-\pgf@y}
    \anchor{sw}{\northwest\pgf@y=-\pgf@y}
    \anchor{north west}{\northwest}
    \anchor{north east}{\northwest\pgf@x=-\pgf@x}
    \anchor{south east}{\northwest\pgf@x=-\pgf@x \pgf@y=-\pgf@y}
    \anchor{south west}{\northwest\pgf@y=-\pgf@y}
    \anchor{n}{\northwest\pgf@x=0pt }
    \anchor{e}{\northwest\pgf@x=-\pgf@x\pgf@y=0pt }
    \anchor{s}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{w}{\northwest\pgf@y=0pt }
    \anchor{north}{\northwest\pgf@x=0pt }
    \anchor{east}{\northwest\pgf@x=-\pgf@x\pgf@y=0pt }
    \anchor{south}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchor{west}{\northwest\pgf@y=0pt }
    \anchor{center}{\pgfpointorigin}
    \anchor{top right}{\topright}
    \anchor{bottom right}{\topright\pgf@y=-\pgf@y}
    \anchor{right}{\topright\pgf@y=0pt\relax}
    \anchor{top left}{\topleft}
    \anchor{bottom left}{\topleft\pgf@y=-\pgf@y}
    \anchor{left}{\topleft\pgf@y=0pt\relax}
    \anchor{top}{\topright\pgf@ya=\pgf@y \topleft \advance\pgf@y by \pgf@ya
        \divide\pgf@y by 2 \pgf@x=0pt\relax}
    \anchor{bottom}{\topright\pgf@ya=\pgf@y \topleft \advance\pgf@y by \pgf@ya
        \divide\pgf@y by 2 \pgf@y=-\pgf@y \pgf@x=0pt\relax}
    \anchor{inset top right}{\pgf@ya=\insethright\insetnortheast\advance\pgf@y by -0.5\pgf@ya}
    \anchor{inset bottom right}{\pgf@ya=\insethright\insetnortheast\advance\pgf@y by -0.5\pgf@ya\pgf@y=-\pgf@y}
    \anchor{inset right}{\insetnortheast\pgf@y=0pt\relax}
    \anchor{inset top left}{\insetnortheast\pgf@ya=\pgf@y\topleft\pgf@y=\pgf@ya}
    \anchor{inset bottom left}{\insetnortheast\pgf@ya=\pgf@y\topleft\pgf@y=-\pgf@ya}
    \anchor{inset left}{\topleft\pgf@y=0pt\relax}
    \anchor{inset bottom}{\topleft\pgf@xa=\pgf@x\pgf@ya=\insethright
        \insetnortheast\pgf@xb=\pgf@x\pgf@yb=\pgf@x
        \pgfpoint{(\pgf@xa+\pgf@xb)/2}{-\pgf@ya+\pgf@yb/2}}
    \anchor{inset top}{\topleft\pgf@xa=\pgf@x\pgf@ya=\insethright
        \insetnortheast\pgf@xb=\pgf@x\pgf@yb=\pgf@x
        \pgfpoint{(\pgf@xa+\pgf@xb)/2}{\pgf@ya-\pgf@yb/2}}
    \anchor{inset center}{\topleft\pgf@xa=\pgf@x\insetnortheast
        \advance\pgf@x by \pgf@xa \divide\pgf@x by 2 \pgf@y=0pt\relax}
    \anchor{narrow center}{\insetnortheast\pgf@xa=\pgf@x\topright
        \advance\pgf@x by \pgf@xa \divide\pgf@x by 2\pgf@y=0pt\relax}
    \anchor{center up}{\topright\pgf@ya=\pgf@y \topleft \advance\pgf@y by \pgf@ya
        \divide\pgf@y by 2
        \pgf@yb = \insethright \advance\pgf@y by \pgf@yb
        \divide\pgf@y by 2 \pgf@x=0pt\relax}
    \anchor{center down}{\topright\pgf@ya=\pgf@y \topleft \advance\pgf@y by \pgf@ya
        \divide\pgf@y by 2
        \pgf@yb = \insethright \advance\pgf@y by \pgf@yb
        \divide\pgf@y by 2 \pgf@y=-\pgf@y \pgf@x=0pt\relax}
    \anchor{text}{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgfmathsetlength\pgf@x{\ctikzvalof{multipoles/muxdemux/base len}*
          \ctikzvalof{multipoles/muxdemux/inset w}*\pgf@circ@scaled@Rlen/2}
        \advance\pgf@x by -.5\wd\pgfnodeparttextbox%
        \pgf@y=-.5\ht\pgfnodeparttextbox%
        \advance\pgf@y by+.5\dp\pgfnodeparttextbox%
    }%
    \pgf@circ@draw@component{%
        \topleft
        \pgf@circ@res@up = \pgf@y
        \pgf@circ@res@down = -\pgf@y
        \pgf@circ@res@left = \pgf@x
        \topright
        \pgf@circ@res@other = \pgf@y
        \pgf@circ@res@right = \pgf@x
        \insetnortheast
        \pgf@circ@res@step = \pgf@x
        \pgf@circ@res@temp = \pgf@y
        %
        % draw the (user-selectable) background
        %
        \pgfscope
            \pgfmathsetmacro{\@@scalex}{\pgf@circ@res@right/1cm}
            % It's better not to change the scale in an asymmetric way
            % \pgfmathsetmacro{\@@scaley}{\pgf@circ@res@up/1cm}
            \pgftransformxscale{\@@scalex}
            \pgftransformyscale{\@@scalex}
            \pgf@circ@setlinewidth{multipoles}{\pgfstartlinewidth}
            \pgfkeys{\circuitikzbasekey/multipoles/muxdemux/bgpicture}
        \endpgfscope
        %
        % external block
        %
        \pgfscope% (for the line width)
            \pgf@circ@setlinewidth{multipoles}{\pgflinewidth}
            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@other}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{-\pgf@circ@res@other}}
            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}
            % inset, starting down
            \ifdim\pgf@circ@res@temp>0pt % inset
                % \typeout{INSETw\space\the\pgf@circ@res@right\space x\space\the\pgf@circ@res@step\space  y\space\the\pgf@circ@res@temp}
                \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{-\pgf@circ@res@temp}}
                \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{-\insethright}}
                \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{\insethright}}
                \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@temp}}
            \fi
            \pgfpathclose
        \pgf@circ@draworfill
        \endpgfscope
        % now we have to draw the pins, if needed
        \ifdim\extshift>0pt\ifpgfcirc@draw@input@leads\pgfscope % let's avoid too much indent
        % Ok, we have to draw the leads (a.k.a. pins)
            \pgfsetlinewidth{\ctikzvalof{multipoles/external pins thickness}\pgflinewidth}
            % We mimic the anchors here --- probably there is a better way
            % left pins
            \ifnum\NL>0\relax % not indented, closed on \repeatpgfmathloop
            \pgf@circ@count@a=\NL\relax
            \pgf@circ@count@b=\NL \divide\pgf@circ@count@b by 2 % see https://tex.stackexchange.com/questions/146523/why-does-numexpr-integer-division-round-rather-than-truncate
            \topleft\pgf@circ@res@left=\pgf@x \pgf@circ@res@up=\pgf@y
            \insetnortheast\pgf@circ@res@right=\pgf@x \pgf@circ@res@down=\pgf@y
            \ifdim\pgf@circ@res@down>0pt % check if we have an inset
            % we have to check oddity
                \ifodd\NL
                    \ifnum\NL=1
                        % only centerpin, step should not be used, but anyway...
                        \pgfmathsetlength{\pgf@circ@res@step}{2*(\pgf@circ@res@up-\pgf@circ@res@down)/(\NL)}
                    \else
                        \pgfmathsetlength{\pgf@circ@res@step}{2*(\pgf@circ@res@up-\pgf@circ@res@down)/(\NL-1)}
                    \fi
                \else
                    \pgfmathsetlength{\pgf@circ@res@step}{2*(\pgf@circ@res@up-\pgf@circ@res@down)/\NL}
                \fi
            \else % no inset
                \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@circ@res@up/\NL}
            \fi
            \pgfmathloop%
            \ifnum\pgf@circ@count@a>0
                %%%%% check if we want to draw this pin
                \pgf@circ@if@num@in@list\pgf@circ@Lpins@list\pgf@circ@count@a{%
                \ifdim\pgf@circ@res@down>0pt % check if we have an inset
                    \ifnum\pgf@circ@count@a>\pgf@circ@count@b\relax
                        % for lower pins we have to shift them down
                        % \typeout{DEBUGTEST1\space #1\space entering\space \NL}
                        \ifodd\NL
                            % odd number of pins
                            \ifnum\pgf@circ@count@a=\numexpr\the\pgf@circ@count@b+1\relax
                                % centerpin!
                                \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
                                \ifnum\squarepins>0
                                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\extshift}{0pt}}
                                \else
                                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\extshift}{0pt}}
                                \fi
                            \else
                                \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a+1)*\pgf@circ@res@step-2*\pgf@circ@res@down}}
                                \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\extshift}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a+1)*\pgf@circ@res@step-2*\pgf@circ@res@down}}
                            \fi
                        \else
                            % even numer of pins: just go down
                            \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a)*\pgf@circ@res@step-2*\pgf@circ@res@down}}
                            \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\extshift}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a)*\pgf@circ@res@step-2*\pgf@circ@res@down}}
                        \fi
                    \else
                        % nothing need for #1<=NL/2
                        \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a)*\pgf@circ@res@step}}
                        \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\extshift}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a)*\pgf@circ@res@step}}
                    \fi
                \else
                % no inset
                    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a)*\pgf@circ@res@step}}
                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left-\extshift}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a)*\pgf@circ@res@step}}
                \fi
                %%%%%
                }{}% close the pin list check
                \advance\pgf@circ@count@a by -1\relax%
            \repeatpgfmathloop\fi%
            % right pins
            \ifnum\NR>0\pgf@circ@count@a=\NR\relax
            \pgfmathloop%
            \topright\pgf@circ@res@right=\pgf@x \pgf@circ@res@up=\pgf@y
            \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@circ@res@up/\NR}
            \ifnum\pgf@circ@count@a>0
                %%%%% check if we want to draw this pin
                \pgf@circ@if@num@in@list\pgf@circ@Rpins@list\pgf@circ@count@a{%
                \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a)*\pgf@circ@res@step}}
                \pgfpathlineto{\pgfpoint{\pgf@circ@res@right+\extshift}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a)*\pgf@circ@res@step}}
                }{}%
            \advance\pgf@circ@count@a by -1\relax%
            \repeatpgfmathloop\fi%
            % bottom pins
            \ifnum\NB>0\pgf@circ@count@a=\NB\relax %%%
            \pgfmathloop%
            \topleft\pgf@circ@res@left=\pgf@x \pgf@circ@res@up=\pgf@y
            \topright\pgf@circ@res@right=\pgf@x \pgf@circ@res@down=\pgf@y
            \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@circ@res@right/\NB}
            \pgfmathsetlength{\pgf@circ@res@other}{(\pgf@circ@res@down-\pgf@circ@res@up)/(\pgf@circ@res@right-\pgf@circ@res@left)*\pgf@circ@res@step}
            \ifnum\pgf@circ@count@a>0
                %%%%% check if we want to draw this pin
                \pgf@circ@if@num@in@list\pgf@circ@Bpins@list\pgf@circ@count@a{%
                \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left+(\pgf@circ@count@a-0.5)*\pgf@circ@res@step}
                {-\pgf@circ@res@down+(\NB-\pgf@circ@count@a+0.5)*\pgf@circ@res@other}}
                \ifnum\squarepins>0
                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+(\pgf@circ@count@a-0.5)*\pgf@circ@res@step}
                    {-max(\pgf@circ@res@down, \pgf@circ@res@up)-\extshift}}
                \else
                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+(\pgf@circ@count@a-0.5)*\pgf@circ@res@step}
                    {-\pgf@circ@res@down+(\NB-\pgf@circ@count@a+0.5)*\pgf@circ@res@other-\extshift}}
                \fi
                }{}%
            \advance\pgf@circ@count@a by -1\relax%
            \repeatpgfmathloop\fi%
            % top pins
            \ifnum\NT>0\pgf@circ@count@a=\NT\relax
            \pgfmathloop%
            \topleft\pgf@circ@res@left=\pgf@x \pgf@circ@res@up=\pgf@y
            \topright\pgf@circ@res@right=\pgf@x \pgf@circ@res@down=\pgf@y
            \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@circ@res@right/\NT}
            \pgfmathsetlength{\pgf@circ@res@other}{(\pgf@circ@res@down-\pgf@circ@res@up)/(\pgf@circ@res@right-\pgf@circ@res@left)*\pgf@circ@res@step}
            \ifnum\pgf@circ@count@a>0
                %%%%% check if we want to draw this pin
                \pgf@circ@if@num@in@list\pgf@circ@Tpins@list\pgf@circ@count@a{%
                \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left+(\pgf@circ@count@a-0.5)*\pgf@circ@res@step}
                {\pgf@circ@res@down-(\NT-\pgf@circ@count@a+0.5)*\pgf@circ@res@other}}
                \ifnum\squarepins>0
                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+(\pgf@circ@count@a-0.5)*\pgf@circ@res@step}
                    {max(\pgf@circ@res@down, \pgf@circ@res@up)+\extshift}}
                \else
                    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left+(\pgf@circ@count@a-0.5)*\pgf@circ@res@step}
                    {\pgf@circ@res@down-(\NT-\pgf@circ@count@a+0.5)*\pgf@circ@res@other+\extshift}}
                \fi
                }{}%
            \advance\pgf@circ@count@a by -1\relax%
            \repeatpgfmathloop\fi%
        % end drawing pins; stroke them
        \pgfusepath{stroke}
        \endpgfscope\fi\fi
        %%%% Labels. Added by Romano 14/10/2023.
        % manage labels. This is independent from the drawing of pins; redo the loops. Surely
        % there is a better way; but it's complex to factor out code. Let's go the KISS way.
        \ifpgf@circuit@chip@straightnumbers
            \pgfgettransformentries\a\b\temp\temp\temp\temp
            \pgfmathsetmacro{\rot}{-atan2(\b,\a)}
            \pgfmathtruncatemacro{\quadrant}{mod(4+int(360+(\rot+45)/90),4)}
        \else
            \pgfmathsetmacro{\rot}{0}
            \pgfmathsetmacro{\quadrant}{0}
        \fi
        % clockwedge size
        \pgfmathsetlength{\pgf@circ@res@temp}{\ctikzvalof{muxdemux/clock wedge size}*\ctikzvalof{multipoles/muxdemux/base len}*\scaledRlen}
        \edef\clockwedge{\the\pgf@circ@res@temp}
        % select which negation ball to use
        \ifpgf@circuit@ieeelogicport
            \def\@@notcirc{circleinv}
        \else
            \ifpgf@circ@european@port@circle@ieee
                \def\@@notcirc{circleinv}
            \else
                \def\@@notcirc{ocirc}
            \fi
        \fi
        %% border labels
        \pgf@circ@res@temp=0pt
        \pgf@circ@count@a=0
        % go to north
        \topleft\pgf@circ@res@left=\pgf@x \pgf@circ@res@up=\pgf@y
        \pgfscope
        \pgftransformshift{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \ifnum\quadrant=2
            \pgf@circ@muxdemux@label@xy{N}{180}{0}{-1}{top}{pgfcirc@nop}{border}% type, rot, pad x, pad y, text pos, op, type
            \pgf@circ@muxdemux@label@xy{Ni}{180}{0}{1}{bottom}{pgfcirc@nop}{border}%
        \else
            \pgf@circ@muxdemux@label@xy{N}{0}{0}{1}{bottom}{pgfcirc@nop}{border}%
            \pgf@circ@muxdemux@label@xy{Ni}{0}{0}{-1}{top}{pgfcirc@nop}{border}%
        \fi
        \endpgfscope
        % go south!
        \pgfscope
        \pgftransformshift{\pgfpoint{0pt}{-\pgf@circ@res@up}}
        \ifnum\quadrant=2
            \pgf@circ@muxdemux@label@xy{S}{180}{0}{1}{bottom}{pgfcirc@nop}{border}% type, rot, pad x, pad y, text pos, op, type
            \pgf@circ@muxdemux@label@xy{Si}{180}{0}{-1}{top}{pgfcirc@nop}{border}%
        \else
            \pgf@circ@muxdemux@label@xy{S}{0}{0}{-1}{top}{pgfcirc@nop}{border}% type, rot, pad x, pad y, text pos, op, type
            \pgf@circ@muxdemux@label@xy{Si}{0}{0}{1}{bottom}{pgfcirc@nop}{border}%
        \fi
        \endpgfscope
        % go west!
        \pgfscope
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \ifnum\quadrant=3
            \pgf@circ@muxdemux@label@xy{W}{-90}{0}{-1}{top}{pgfcirc@nop}{border}% type, rot, pad x, pad y, text pos, op, type
            \pgf@circ@muxdemux@label@xy{Wi}{-90}{0}{1}{bottom}{pgfcirc@nop}{border}%
        \else
            \pgf@circ@muxdemux@label@xy{W}{90}{0}{1}{bottom}{pgfcirc@nop}{border}%
            \pgf@circ@muxdemux@label@xy{Wi}{90}{0}{-1}{top}{pgfcirc@nop}{border}%
        \fi
        \endpgfscope
        % go east!
        \pgfscope
        \pgftransformshift{\pgfpoint{-\pgf@circ@res@left}{0pt}}
        \ifnum\quadrant=3
            \pgf@circ@muxdemux@label@xy{E}{-90}{0}{1}{bottom}{pgfcirc@nop}{border}% type, rot, pad x, pad y, text pos, op, type
            \pgf@circ@muxdemux@label@xy{Ei}{-90}{0}{-1}{top}{pgfcirc@nop}{border}%
        \else
            \pgf@circ@muxdemux@label@xy{E}{90}{0}{-1}{top}{pgfcirc@nop}{border}%
            \pgf@circ@muxdemux@label@xy{Ei}{90}{0}{1}{bottom}{pgfcirc@nop}{border}%
        \fi
        \endpgfscope
        % start exploring all the pins. We repeat the steps to position the coordinate on every pin.
        % left pins
        \ifnum\NL>0\relax
            \pgf@circ@count@a=\NL\relax
            \pgf@circ@count@b=\NL \divide\pgf@circ@count@b by 2 % see https://tex.stackexchange.com/questions/146523/why-does-numexpr-integer-division-round-rather-than-truncate
            \topleft\pgf@circ@res@left=\pgf@x \pgf@circ@res@up=\pgf@y
            \insetnortheast\pgf@circ@res@right=\pgf@x \pgf@circ@res@down=\pgf@y
            \ifdim\pgf@circ@res@down>0pt % check if we have an inset
            % we have to check oddity
                \ifodd\NL
                    \ifnum\NL=1
                        % only centerpin, step should not be used, but anyway...
                        \pgfmathsetlength{\pgf@circ@res@step}{2*(\pgf@circ@res@up-\pgf@circ@res@down)/(\NL)}
                    \else
                        \pgfmathsetlength{\pgf@circ@res@step}{2*(\pgf@circ@res@up-\pgf@circ@res@down)/(\NL-1)}
                    \fi
                \else
                    \pgfmathsetlength{\pgf@circ@res@step}{2*(\pgf@circ@res@up-\pgf@circ@res@down)/\NL}
                \fi
            \else % no inset
                \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@circ@res@up/\NL}
            \fi
            \pgfmathloop%
                \ifnum\pgf@circ@count@a>0
                \pgfscope
                \ifdim\pgf@circ@res@down>0pt % check if we have an inset
                    \ifnum\pgf@circ@count@a>\pgf@circ@count@b\relax
                        % for lower pins we have to shift them down
                        \ifodd\NL
                            % odd number of pins
                            \ifnum\pgf@circ@count@a=\numexpr\the\pgf@circ@count@b+1\relax
                                % centerpin!
                                \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{0pt}}
                            \else
                                \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a+1)*\pgf@circ@res@step-2*\pgf@circ@res@down}}
                            \fi
                        \else
                            % even numer of pins: just go down
                            \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a)*\pgf@circ@res@step-2*\pgf@circ@res@down}}
                        \fi
                    \else
                        % nothing need for #1<=NL/2
                        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a)*\pgf@circ@res@step}}
                    \fi
                \else
                % no inset
                    \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a)*\pgf@circ@res@step}}
                \fi
                % put the not ball/wedges if needed
                \pgf@circ@muxdemux@not@ball{nL}{east}
                \pgf@circ@muxdemux@not@wedge{wiL}{east}{1}{1}{0}
                \pgf@circ@muxdemux@not@wedge{woL}{west}{-1}{1}{0}
                % \fi
                \pgf@circ@muxdemux@clockwedge{cL}{0}
                %% put the labels
                \ifcase\quadrant % rotation 0; left label are at the left
                    \pgf@circ@muxdemux@label@xy{L}{0}{1}{0}{left}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{LU}{0}{-1}{1}{bottom}{llap}{outer}%
                    \pgf@circ@muxdemux@label@xy{LD}{0}{-1}{-1}{top}{llap}{outer}%
                \or %rotation -90; left labels are at the top
                    \pgf@circ@muxdemux@label@xy{L}{90}{0}{-1}{top}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{LU}{90}{-1}{1}{bottom}{llap}{outer}%
                    \pgf@circ@muxdemux@label@xy{LD}{90}{1}{1}{bottom}{rlap}{outer}%
                \or %rotation 180; left labels are at the right
                    \pgf@circ@muxdemux@label@xy{L}{180}{-1}{0}{right}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{LU}{180}{1}{1}{bottom}{rlap}{outer}%
                    \pgf@circ@muxdemux@label@xy{LD}{180}{1}{-1}{top}{rlap}{outer}%
                \or %rotation +90; left labels are at the bottom
                    \pgf@circ@muxdemux@label@xy{L}{-90}{0}{1}{bottom}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{LU}{-90}{-1}{-1}{top}{llap}{outer}%
                    \pgf@circ@muxdemux@label@xy{LD}{-90}{1}{-1}{top}{rlap}{outer}%
                \fi
            \endpgfscope
            \advance\pgf@circ@count@a by -1\relax%
            \repeatpgfmathloop
        \fi
        %% right pins
        \ifnum\NR>0\pgf@circ@count@a=\NR\relax
            \pgfmathloop%
            \topright\pgf@circ@res@right=\pgf@x \pgf@circ@res@up=\pgf@y
            \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@circ@res@up/\NR}
            \ifnum\pgf@circ@count@a>0
            \pgfscope
                \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up+(0.5-\pgf@circ@count@a)*\pgf@circ@res@step}}
                % put the not ball/wedge if needed
                \pgf@circ@muxdemux@not@ball{nR}{west}
                \pgf@circ@muxdemux@not@wedge{wiR}{east}{-1}{1}{0}
                \pgf@circ@muxdemux@not@wedge{woR}{west}{1}{1}{0}
                % put the clock wedge if needed
                \pgf@circ@muxdemux@clockwedge{cR}{180}
                \ifcase\quadrant % rotation 0; right label are at the right
                    \pgf@circ@muxdemux@label@xy{R}{0}{-1}{0}{right}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{RU}{0}{1}{1}{bottom}{rlap}{outer}%
                    \pgf@circ@muxdemux@label@xy{RD}{0}{1}{-1}{top}{rlap}{outer}%
                \or %rotation -90; right labels are at the bottom
                    \pgf@circ@muxdemux@label@xy{R}{90}{0}{1}{bottom}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{RU}{90}{-1}{-1}{top}{llap}{outer}%
                    \pgf@circ@muxdemux@label@xy{RD}{90}{1}{-1}{top}{rlap}{outer}%
                \or %rotation 180; right labels are at the left
                    \pgf@circ@muxdemux@label@xy{R}{180}{1}{0}{left}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{RU}{180}{-1}{1}{bottom}{llap}{outer}%
                    \pgf@circ@muxdemux@label@xy{RD}{180}{-1}{-1}{top}{llap}{outer}%
                \or %rotation +90; right labels are at the top
                    \pgf@circ@muxdemux@label@xy{R}{-90}{0}{-1}{top}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{RU}{-90}{-1}{1}{bottom}{llap}{outer}%
                    \pgf@circ@muxdemux@label@xy{RD}{-90}{1}{1}{bottom}{rlap}{outer}%
                \fi
            \endpgfscope
            \advance\pgf@circ@count@a by -1\relax%
            \repeatpgfmathloop
        \fi
        %% bottom pins
        \ifnum\NB>0\pgf@circ@count@a=\NB\relax %%%
            \pgfmathloop%
            \topleft\pgf@circ@res@left=\pgf@x \pgf@circ@res@up=\pgf@y
            \topright\pgf@circ@res@right=\pgf@x \pgf@circ@res@down=\pgf@y
            \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@circ@res@right/\NB}
            \pgfmathsetlength{\pgf@circ@res@other}{(\pgf@circ@res@down-\pgf@circ@res@up)/(\pgf@circ@res@right-\pgf@circ@res@left)*\pgf@circ@res@step}
            \ifnum\pgf@circ@count@a>0
            \pgfscope
                \pgftransformshift{\pgfpoint{\pgf@circ@res@left+(\pgf@circ@count@a-0.5)*\pgf@circ@res@step}
                        {-\pgf@circ@res@down+(\NB-\pgf@circ@count@a+0.5)*\pgf@circ@res@other}}
                % put the not ball/wedge if needed
                \pgf@circ@muxdemux@not@ball{nB}{north}
                \pgf@circ@muxdemux@not@wedge{wiB}{east}{1}{1}{90}
                \pgf@circ@muxdemux@not@wedge{woB}{west}{-1}{1}{90}
                % put the clock wedge if needed
                \pgf@circ@muxdemux@clockwedge{cB}{90}
                \ifcase\quadrant % rotation 0; bottom label are at the bottom
                    \pgf@circ@muxdemux@label@xy{B}{0}{0}{1}{bottom}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{BL}{0}{-1}{-1}{top}{llap}{outer}%
                    \pgf@circ@muxdemux@label@xy{BR}{0}{1}{-1}{top}{rlap}{outer}%
                \or %rotation -90; bottom labels are at the left
                    \pgf@circ@muxdemux@label@xy{B}{90}{1}{0}{left}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{BL}{90}{-1}{1}{bottom}{llap}{outer}%
                    \pgf@circ@muxdemux@label@xy{BR}{90}{-1}{-1}{top}{llap}{outer}%
                \or %rotation 180; bottom labels are at the top
                    \pgf@circ@muxdemux@label@xy{B}{180}{0}{-1}{top}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{BL}{180}{-1}{1}{bottom}{llap}{outer}%
                    \pgf@circ@muxdemux@label@xy{BR}{180}{1}{1}{bottom}{rlap}{outer}%
                \or %rotation +90; bottom labels are at the right
                    \pgf@circ@muxdemux@label@xy{B}{-90}{-1}{0}{right}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{BL}{-90}{1}{1}{bottom}{rlap}{outer}%
                    \pgf@circ@muxdemux@label@xy{BR}{-90}{1}{-1}{top}{rlap}{outer}%
                \fi
            \endpgfscope
            \advance\pgf@circ@count@a by -1\relax%
            \repeatpgfmathloop
        \fi
        %% top pins
        \ifnum\NT>0\pgf@circ@count@a=\NT\relax
            \pgfmathloop%
            \topleft\pgf@circ@res@left=\pgf@x \pgf@circ@res@up=\pgf@y
            \topright\pgf@circ@res@right=\pgf@x \pgf@circ@res@down=\pgf@y
            \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@circ@res@right/\NT}
            \pgfmathsetlength{\pgf@circ@res@other}{(\pgf@circ@res@down-\pgf@circ@res@up)/(\pgf@circ@res@right-\pgf@circ@res@left)*\pgf@circ@res@step}
            \ifnum\pgf@circ@count@a>0
            \pgfscope
                \pgftransformshift{\pgfpoint{\pgf@circ@res@left+(\pgf@circ@count@a-0.5)*\pgf@circ@res@step}
                {\pgf@circ@res@down-(\NT-\pgf@circ@count@a+0.5)*\pgf@circ@res@other}}
                % put the not ball/wedge if needed
                \pgf@circ@muxdemux@not@ball{nT}{south}
                \pgf@circ@muxdemux@not@wedge{wiT}{east}{1}{-1}{-90}
                \pgf@circ@muxdemux@not@wedge{woT}{west}{-1}{-1}{-90}
                % put the clock wedge if needed
                \pgf@circ@muxdemux@clockwedge{cT}{-90}
                \ifcase\quadrant % rotation 0; top label are at the top
                    \pgf@circ@muxdemux@label@xy{T}{0}{0}{-1}{top}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{TL}{0}{-1}{1}{bottom}{llap}{outer}%
                    \pgf@circ@muxdemux@label@xy{TR}{0}{1}{1}{bottom}{rlap}{outer}%
                \or %rotation -90; top labels are at the right
                    \pgf@circ@muxdemux@label@xy{T}{90}{-1}{0}{right}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{TL}{90}{1}{1}{bottom}{rlap}{outer}%
                    \pgf@circ@muxdemux@label@xy{TR}{90}{1}{-1}{top}{rlap}{outer}%
                \or %rotation 180; top labels are at the bottom
                    \pgf@circ@muxdemux@label@xy{T}{180}{0}{1}{bottom}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{TL}{180}{-1}{-1}{top}{llap}{outer}%
                    \pgf@circ@muxdemux@label@xy{TR}{180}{1}{-1}{top}{rlap}{outer}%
                \or %rotation +90; top labels are at the left
                    \pgf@circ@muxdemux@label@xy{T}{-90}{1}{0}{left}{pgfcirc@nop}{inner}% type, rot, pad x, pad y, text pos, op, type
                    \pgf@circ@res@temp=0pt
                    \pgf@circ@muxdemux@label@xy{TL}{-90}{-1}{1}{bottom}{llap}{outer}%
                    \pgf@circ@muxdemux@label@xy{TR}{-90}{-1}{-1}{top}{llap}{outer}%
                \fi
            \endpgfscope
            \advance\pgf@circ@count@a by -1\relax%
            \repeatpgfmathloop
        \fi
    }
    % let's start adding anchors
    \pgfutil@g@addto@macro\pgf@sh@s@muxdemux{%
        % left side anchors
        \pgf@circ@count@a=\NL\relax
        % \typeout{STARTGENERATINGLEFT\space\the\pgf@circ@count@a\space FOR\space\thisshape\space\NL}
        \pgfmathloop%
        \ifnum\pgf@circ@count@a>0
        % \typeout{GENERATINGLEFT\space\the\pgf@circ@count@a\space FOR\space\thisshape\space\NL}
            % we will create two anchors per pin: the "normal one" like `lpin 1` for the
            % external leads, and the "border one" like `blpin 1` for internal ones.
            % they will coincide if `external pins width` is set to 0.
            \expandafter\pgf@circ@make@muxdemux@L@anchor\expandafter{\the\pgf@circ@count@a}%
            \advance\pgf@circ@count@a by -1\relax%
        \repeatpgfmathloop%
        % right anchors
        \pgf@circ@count@a=\NR\relax
        \pgfmathloop%
        \ifnum\pgf@circ@count@a>0
            % we will create two anchors per pin: the "normal one" like `rpin 1` for the
            % external leads, and the "border one" like `brpin 1` for internal ones.
            % they will coincide if `external pins width` is set to 0.
            \expandafter\pgf@circ@make@muxdemux@R@anchor\expandafter{\the\pgf@circ@count@a}%
            \advance\pgf@circ@count@a by -1\relax%
        \repeatpgfmathloop%
        % bottom anchors
        \pgf@circ@count@a=\NB\relax
        \pgfmathloop%
        \ifnum\pgf@circ@count@a>0
            % we will create two anchors per pin: the "normal one" like `bpin 1` for the
            % external leads, and the "border one" like `bbpin 1` for internal ones.
            % they will coincide if `external pins width` is set to 0.
            \expandafter\pgf@circ@make@muxdemux@B@anchor\expandafter{\the\pgf@circ@count@a}%
            \advance\pgf@circ@count@a by -1\relax%
        \repeatpgfmathloop%
        % top anchors
        \pgf@circ@count@a=\NT\relax
        \pgfmathloop%
        \ifnum\pgf@circ@count@a>0
            % we will create two anchors per pin: the "normal one" like `tpin 1` for the
            % external leads, and the "border one" like `btpin 1` for internal ones.
            % they will coincide if `external pins width` is set to 0.
            \expandafter\pgf@circ@make@muxdemux@T@anchor\expandafter{\the\pgf@circ@count@a}%
            \advance\pgf@circ@count@a by -1\relax%
        \repeatpgfmathloop%
    }%
}

%% left anchors for muxdemux

\def\pgf@circ@muxdemux@L@anchor#1#2{% #1: pin number #2: 0 for border pin, 1 for external pin
    \topleft
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    \insetnortheast
    \pgf@xb=\pgf@x
    \pgf@yb=\pgf@y
    \ifnum#1>\NL
        \PackageError{circuitikz}{%
            You requested left pin #1 for mux/demux shape \thisshape\space \MessageBreak
            which has been defined with \NL\space left pins%
        }{Please check the manual about mux/demux shapes; if you press return I'll try to continue}
    \fi
    \pgf@circ@count@a=\NL \divide\pgf@circ@count@a by 2 % see https://tex.stackexchange.com/questions/146523/why-does-numexpr-integer-division-round-rather-than-truncate
    % \typeout{LEFT \the\pgf@xa \space \the\pgf@ya \space \NL}
    \ifnum\NL>1
        \ifdim\pgf@yb>0pt % check if we have an inset
        % we have to check oddity
            \ifodd\NL
                \pgfmathsetlength{\pgf@circ@res@step}{2*(\pgf@ya-\pgf@yb)/(\NL-1)}
            \else
                \pgfmathsetlength{\pgf@circ@res@step}{2*(\pgf@ya-\pgf@yb)/\NL}
            \fi
        \else % no inset
            \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@ya/\NL}
        \fi
        \ifdim\pgf@yb>0pt % check if we have an inset
            \ifnum#1>\pgf@circ@count@a\relax
                % for lower pins we have to shift them down
                % \typeout{DEBUGTEST1\space #1\space entering\space \NL}
                \ifodd\NL
                    % odd number of pins
                    \ifnum#1=\numexpr\the\pgf@circ@count@a+1\relax
                        % centerpin!
                        \ifnum#2=0\relax
                            \pgfpoint{\pgf@xb}{0pt}
                        \else
                            \ifnum\squarepins>0
                                \pgfpoint{\pgf@xa-#2*\extshift}{0pt}
                            \else
                                \pgfpoint{\pgf@xb-#2*\extshift}{0pt}
                            \fi
                        \fi
                    \else
                        \pgfpoint{\pgf@xa-#2*\extshift}{\pgf@ya+(0.5-#1+1)*\pgf@circ@res@step-2*\pgf@yb}
                    \fi
                \else
                    % even numer of pins: just go down
                    \pgfpoint{\pgf@xa-#2*\extshift}{\pgf@ya+(0.5-#1)*\pgf@circ@res@step-2*\pgf@yb}
                \fi
            \else
                % nothing need for #1<=NL/2
                \pgfpoint{\pgf@xa-#2*\extshift}{\pgf@ya+(0.5-#1)*\pgf@circ@res@step}
            \fi
        \else
        % no inset
            \pgfpoint{\pgf@xa-#2*\extshift}{\pgf@ya+(0.5-#1)*\pgf@circ@res@step}
        \fi
    \else
        \pgfpoint{\pgf@xa-#2*\extshift}{0pt}
    \fi
}

% right anchors
\def\pgf@circ@muxdemux@R@anchor#1#2{% #1: pin number #2: 0 for border pin, 1 for external pin
    \topright
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    \ifnum#1>\NR
        \PackageError{circuitikz}{%
            You requested right pin #1 for mux/demux shape \thisshape\space \MessageBreak
            which has been defined with \NR\space right pins%
        }{Please check the manual about mux/demux shapes; if you press return I'll try to continue}
    \fi
    \ifnum\NR>1
        \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@ya/\NR}
        \pgfpoint{\pgf@xa+#2*\extshift}{\pgf@ya+(0.5-#1)*\pgf@circ@res@step}
    \else
        \pgfpoint{\pgf@xa+#2*\extshift}{0pt}
    \fi
}

% bottom anchors
\def\pgf@circ@muxdemux@B@anchor#1#2{% #1: pin number #2: 0 for border pin, 1 for external pin
    \topleft
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    \topright
    \pgf@xb=\pgf@x
    \pgf@yb=\pgf@y
    \ifnum#1>\NB
        \PackageError{circuitikz}{%
            You requested bottom pin #1 for mux/demux shape \thisshape\space \MessageBreak
            which has been defined with \NB\space bottom pins%
        }{Please check the manual about mux/demux shapes; if you press return I'll try to continue}
    \fi
    \ifnum\NB>0
        % \typeout{DEBUGTESTtopleft\space\the\pgf@ya \space topright\space\the\pgf@yb \space\NB}
        \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@xb/\NB}
        \pgfmathsetlength{\pgf@circ@res@other}{(\pgf@yb-\pgf@ya)/(\pgf@xb-\pgf@xa)*\pgf@circ@res@step}
        \pgfmathsetlength\pgf@x{\pgf@xa+(#1-0.5)*\pgf@circ@res@step}
        \ifnum#2=0\relax
            \pgfmathsetlength\pgf@y{-\pgf@yb+(\NB-#1+0.5)*\pgf@circ@res@other}
        \else
            \ifnum\squarepins>0\relax
                \pgfmathsetlength\pgf@y{-max(\pgf@ya,\pgf@yb)-\extshift}
            \else
                \pgfmathsetlength\pgf@y{-\pgf@yb+(\NB-#1+0.5)*\pgf@circ@res@other-\extshift}
            \fi
        \fi
    \else
        % should not happen, give the same as pin 1 anyway
        \ifnum#2=0\relax
        \pgfpoint{0pt}{-\pgf@yb+(\pgf@yb-\pgf@ya)/2}
        \else
            \pgfpoint{0pt}{-max(\pgf@ya,\pgf@yb)-\extshift}
        \fi
    \fi
}

% top anchors
\def\pgf@circ@muxdemux@T@anchor#1#2{% #1: pin number #2: 0 for border pin, 1 for external pin
    \topleft
    \pgf@xa=\pgf@x
    \pgf@ya=\pgf@y
    \topright
    \pgf@xb=\pgf@x
    \pgf@yb=\pgf@y
    \ifnum#1>\NT
        \PackageError{circuitikz}{%
            You requested top pin #1 for mux/demux shape \thisshape\space \MessageBreak
            which has been defined with \NT\space top pins%
        }{Please check the manual about mux/demux shapes; if you press return I'll try to continue}
    \fi
    \ifnum\NT>0
        \pgfmathsetlength{\pgf@circ@res@step}{2*\pgf@xb/\NT}
        \pgfmathsetlength{\pgf@circ@res@other}{(\pgf@yb-\pgf@ya)/(\pgf@xb-\pgf@xa)*\pgf@circ@res@step}
        \pgfmathsetlength\pgf@x{\pgf@xa+(#1-0.5)*\pgf@circ@res@step}
        \ifnum#2=0\relax
            \pgfmathsetlength\pgf@y{\pgf@yb-(\NT-#1+0.5)*\pgf@circ@res@other}
        \else
            \ifnum\squarepins>0
                \pgfmathsetlength\pgf@y{max(\pgf@ya,\pgf@yb)+\extshift}
            \else
                \pgfmathsetlength\pgf@y{\pgf@yb-(\NT-#1+0.5)*\pgf@circ@res@other+\extshift}
            \fi
        \fi
    \else
        % should not happen, give the same as pin 1 anyway
        \ifnum#2=0\relax
        \pgfpoint{0pt}{\pgf@yb-(\pgf@yb-\pgf@ya)/2}
        \else
            \pgfpoint{0pt}{max(\pgf@ya,\pgf@yb)+\extshift}
        \fi
    \fi
}
% %>>>

%% definitions and shape for wedgeinv and circleinv%<<<

\ctikzset{wedge inversion mark/width/.initial = 0.2}
\ctikzset{wedge inversion mark/height/.initial = 0.1}
\pgfdeclareshape{wedgeinv}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{muxdemuxes}}
    \saveddimen{\scaledRlen}{\pgfmathsetlength{\pgf@x}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}}
    \savedanchor\northeast{%
        \pgfmathsetlength{\pgf@circ@scaled@Rlen}{\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
        \pgf@y=\ctikzvalof{wedge inversion mark/height}\pgf@circ@scaled@Rlen
        \pgf@x=\ctikzvalof{wedge inversion mark/width}\pgf@circ@scaled@Rlen
    }
    \anchor{center}{\pgfpointorigin}
    \anchor{top}{\northeast\pgf@x=0pt\relax}
    \anchor{apex}{\northeast\pgf@y=0pt\relax}
    \anchor{base}{\pgfpointorigin}
    \anchor{mid}{\northeast\pgf@x=0.5\pgf@x\pgf@y=0.5\pgf@y}
    % not standard geoanchors, south west is the same as 0,0...
    \anchor{right}{\northeast\pgf@y=0pt\relax}
    \anchor{east}{\northeast\pgf@y=0pt\relax}
    \anchor{e}{\northeast\pgf@y=0pt\relax}
    \anchor{left}{\pgfpointorigin}
    \anchor{west}{\pgfpointorigin}
    \anchor{w}{\pgfpointorigin}
    \anchor{south}{\northeast\pgf@y=0pt\pgf@x=0.5\pgf@x}
    \anchor{s}{\northeast\pgf@y=0pt\pgf@x=0.5\pgf@x}
    \anchor{north}{\northeast\pgf@x=0.5\pgf@x}
    \anchor{n}{\northeast\pgf@x=0.5\pgf@x}
    \anchor{south west}{\pgfpointorigin}
    \anchor{sw}{\pgfpointorigin}
    \anchor{north east}{\northeast}
    \anchor{ne}{\northeast}
    \anchor{north west}{\northeast\pgf@x=0pt\relax}
    \anchor{nw}{\northeast\pgf@x=0pt\relax}
    \anchor{south east}{\northeast\pgf@y=0pt\relax}
    \anchor{se}{\northeast\pgf@y=0pt\relax}
    %
    \pgf@circ@draw@component{
        \northeast\pgf@circ@res@up=\pgf@y\pgf@circ@res@right=\pgf@x
        \pgfsetbeveljoin % otherwise it sticks often "inside" the component
        \pgfpathmoveto{\pgfpointorigin}
        \pgfpathlineto{\pgfpoint{0pt}{\pgf@circ@res@up}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfpathclose
        \pgfusepath{draw}
    }
}
% this is *almost* the same as notcirc, but scales with muxdemuxes and
% has the default anchor to the left side
\pgfdeclareshape{circleinv}{
    \savedmacro{\ctikzclass}{\edef\ctikzclass{muxdemuxes}}
    \savedanchor\northwest{%
        \pgf@circ@notradius
        \pgf@y=\pgf@circ@res@temp
        \pgf@x=-\pgf@y
    }
    \pgfcirc@northwest@symmetric@geoanchors
    %% use the left side as default anchor
    \anchor{center}{\northwest\pgf@y=0pt}
    \anchor{geocenter}{\pgfpointorigin}
    \anchor{base}{\northwest\pgf@y=0pt}
    \anchor{apex}{\northwest\pgf@y=0pt\pgf@x=-\pgf@x}
    \anchor{mid}{\northwest\pgf@x=0pt}
    \anchor{top}{\northwest\pgf@x=0pt}
    \anchor{bottom}{\northwest\pgf@x=0pt\pgf@y=-\pgf@y}
    \anchorborder{
        \pgf@circ@res@left=\pgf@x
        \pgf@circ@res@up=\pgf@y
        \northwest\pgf@circ@res@temp=\pgf@y
        \pgfpointborderellipse{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}%
        {\pgfpoint{\pgf@circ@res@temp}{\pgf@circ@res@temp}}
    }
    \pgf@circ@draw@component{
        \pgfscope
            \northwest\pgf@circ@res@temp=\pgf@y
            \pgf@circ@setcolor
            \pgf@circ@setlinewidth{multipoles}{\pgflinewidth}
            \pgfpathcircle{\pgfpointorigin}{\pgf@circ@res@temp}
            \ifx\tikz@fillcolor\pgfutil@empty
                % set the default fill color to white
                \pgfsetfillcolor{white}
                % ...but override it if the class is defined!
                \pgf@circ@setifdefinedfill{draw, fill}{draw, fill}
            \else
                \pgfsetfillcolor{\tikz@fillcolor}
            \fi
            \pgfusepath{draw,fill}
        \endpgfscope
    }
}
%% %>>>

% vim: set fdm=marker fmr=%<<<,%>>>:
%%%---------- close: tex/pgfcircmultipoles

%%%%%%%%%%% Springe nach tex/pgfcirclabel
%%%---------- open: tex/pgfcirclabel.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Bipole label positioning

%% bipole labels and annotation extra style

\ctikzset{bipole label style/.style={}}
\tikzset{bipole label style/.code={
        \ctikzset{bipole label style/.style={#1}}
}}
\tikzset{bipole label append style/.code={
        \ctikzset{bipole label style/.append style={#1}}
}}
\ctikzset{bipole annotation style/.style={}}
\tikzset{bipole annotation style/.code={
        \ctikzset{bipole annotation style/.style={#1}}
}}
\tikzset{bipole annotation append style/.code={
        \ctikzset{bipole annotation style/.append style={#1}}
}}

\ctikzset{label distance/.initial={0pt}}
\ctikzset{annotation distance/.initial={0pt}}

%% Options
\ctikzset{label/.style = { l={#1} } }
\ctikzset{l/.code = {
        \pgfkeys{/tikz/circuitikz/bipole/label/name={#1}}
        \ctikzsetvalof{bipole/label/unit}{}
        \ifpgf@circ@siunitx
            \pgf@circ@handleSI{#1}
            \ifpgf@circ@siunitx@res
                \edef\pgf@temp{\pgf@circ@handleSI@val}
                \pgfkeyslet{/tikz/circuitikz/bipole/label/name}{\pgf@temp}
                \edef\pgf@temp{\pgf@circ@handleSI@unit}
                \pgfkeyslet{/tikz/circuitikz/bipole/label/unit}{\pgf@temp}
            \else
        \fi
        \else
    \fi
}}

\ctikzset{label above/.code = {
        l={#1},
    \circuitikzbasekey/bipole/label/position=90 }
}

\ctikzset{l^/.style = {
        l={#1},
    \circuitikzbasekey/bipole/label/position=90 }
}

\ctikzset{label below/.code = {
        l={#1},
    \circuitikzbasekey/bipole/label/position=-90 }
}

\ctikzset{l_/.style = {
        l={#1},
    \circuitikzbasekey/bipole/label/position=-90 }
}

\ctikzset{annotation/.style = { a={#1} } }
\ctikzset{a/.code = {
    \pgfkeys{/tikz/circuitikz/bipole/annotation/name={#1}}
    \ctikzsetvalof{bipole/annotation/unit}{}
    \ifpgf@circ@siunitx
        \pgf@circ@handleSI{#1}
        \ifpgf@circ@siunitx@res
            \edef\pgf@temp{\pgf@circ@handleSI@val}
            \pgfkeyslet{/tikz/circuitikz/bipole/annotation/name}{\pgf@temp}
            \edef\pgf@temp{\pgf@circ@handleSI@unit}
            \pgfkeyslet{/tikz/circuitikz/bipole/annotation/unit}{\pgf@temp}
        \else
        \fi
    \else
    \fi
}}

\ctikzset{annotation above/.code = {
        a={#1},
    \circuitikzbasekey/bipole/annotation/position=90 }
}

\ctikzset{a^/.style = {
        a={#1},
    \circuitikzbasekey/bipole/annotation/position=90 }
}

\ctikzset{annotation below/.code = {
        a={#1},
    \circuitikzbasekey/bipole/annotation/position=-90 }
}
\ctikzset{a_/.style = {
        a={#1},
    \circuitikzbasekey/bipole/annotation/position=-90 }
}

% This is to adjust spacing for the labels so that they are not cramped on components
\def\pgf@circ@ls{.75ex} % labelspace to have just one point to change

\def\pgf@circ@drawlabels#1{
    \pgfextra{
        % This function will be called with argument #1 equal
        % to "label" or "annotation" form pgfcircpath.tex.
        % pgf@circ@direction is the direction of the path,
        % its value is set in pgfcircpath.tex
        \pgfmathsubtract{\pgf@circ@direction}{90}
        \pgfmathround{\pgfmathresult} % avoid precision loss errors
        \edef\pgf@circ@labanc{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}

        \edef\pgf@circ@temp{\ctikzvalof{bipole/#1/position}}
        \ifnum \pgf@circ@temp < 0
                \pgfmathadd{\pgf@circ@labanc}{180}
                \edef\pgf@circ@labanc{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
        \fi
        % \typeout{INI: TEMP\space\pgf@circ@temp\space LABANC\space\pgf@circ@labanc}
        %
        % normalize the angle values
        %
        \pgfmathmod{\pgf@circ@labanc}{360}
        \edef\pgf@circ@labanc{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
        %
        \ifpgf@circuit@bipole@inverted
                \pgfmathadd{\pgf@circ@temp}{180} %If shape is inverted, use opposite anchor
                \edef\pgf@circ@temp{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
        \fi
        %
        \ifnum \ctikzvalof{mirror value} = -1
                \pgfmathadd{\pgf@circ@temp}{180} %If shape is mirrored, use opposite anchor
                \edef\pgf@circ@temp{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
        \fi
        % \typeout{FIN: TEMP\space\pgf@circ@temp\space LABANC\space\pgf@circ@labanc}
    }
    %Firstly, place a coordinate directly at the edge of the shape
    (\ctikzvalof{bipole/name}.\pgf@circ@temp) coordinate (pgfcirc@labelcoor)
    %now decide, which labels should be drawn
    \pgfextra{
            \edef\pgf@temp{\ctikzvalof{label/align}}
            \def\pgf@circ@temp{straight}
    }
    \ifx\pgf@temp\pgf@circ@temp %straight
            \pgf@circ@drawreglabels{#1}
    \else
            \pgfextra{\def\pgf@circ@temp{rotate}}
            \ifx\pgf@temp\pgf@circ@temp %rotate
                    \pgf@circ@drawrotlabels{#1}
            \else% smart
                    \pgf@circ@drawsmartlabels{#1}
            \fi
    \fi
}


\def\pgf@circ@drawsmartlabels#1{
    \pgfextra{
        \pgfmathmod{\pgf@circ@direction}{90}
        \edef\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
    }
    \ifnum \pgfcircmathresult > 20
    \ifnum \pgfcircmathresult < 70
        \pgf@circ@drawrotlabels{#1}
    \else
        \pgf@circ@drawreglabels{#1}
    \fi
    \else
        \pgf@circ@drawreglabels{#1}
    \fi
    }


\def\pgf@circ@drawrotlabels#1{
    \pgfextra{
        % scale the distances in function of zoom, so that they are not
        % dependent on it but on font size. Thanks to @marmot
        % https://tex.stackexchange.com/a/476018/38080
        % the coefficient is adjusted so that the distance is more or less
        % the same for rotated labels and straight ones (although it will
        % depend on the font, so it's not exact).
        \pgfgettransformentries{\tmpa}{\tmpb}{\tmpc}{\tmpd}{\tmp}{\tmp}%
        \pgfmathsetmacro{\myscale}{sqrt(abs(\tmpa*\tmpd-\tmpb*\tmpc))}% abs should not be needed
        % \typeout{ROT\tmpa\space\tmpb\space\tmpc\space\tmpd\space\myscale}
        \pgfmathsetlength\pgf@circ@res@temp{1.5*\pgf@circ@ls/\myscale+\ctikzvalof{#1 distance}/\myscale}
        \ifnum \ctikzvalof{bipole/#1/position}>0
        %we need some more space for placement below, due to mid-anchor
            \else % we do not have <= in \ifnum...
                \pgf@circ@res@temp=1.5\pgf@circ@res@temp
        \fi
        %Calculate rotation of the label from direction and strip decimals
        \pgfmathsetmacro{\pgfcirclabrot}{round(\pgf@circ@direction)}
        \edef\pgfcirclabrot{\expandafter\pgf@circ@stripdecimals\pgfcirclabrot\pgf@nil}
        % rotate the label at second or third quadrant:
        \ifnum \pgfcirclabrot > 90 \ifnum \pgfcirclabrot < 270
                \pgfmathsubtract{\pgf@circ@direction}{180}
                \edef\pgfcirclabrot{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
                %invert the space relationships due to rotated strings
                \ifnum \ctikzvalof{bipole/#1/position}>0
                        \pgf@circ@res@temp=1.5\pgf@circ@res@temp
                \fi
        \fi\fi
        \pgfmathparse{\ctikzvalof{bipole/#1/position}>0?\pgf@circ@direction+90:\pgf@circ@direction-90}%
        \edef\pgf@circ@labposangle{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}%
        \expandafter\xdef\csname pgfcirc@\pgfcirc@a@prefix#1-direction\endcsname{\pgfcirclabrot}%
        \expandafter\xdef\csname pgfcirc@\pgfcirc@a@prefix-#1-anchor\endcsname{mid}%
    }
    % reset cm is not working correctly here
    % relative ++ movement disrupt to[] +()
    ($(pgfcirc@labelcoor)+(\pgf@circ@labposangle:\the\pgf@circ@res@temp)$) coordinate(pgfcirc@labelcoor)
    node[anchor=mid, rotate=\pgfcirclabrot, \circuitikzbasekey/bipole #1 style]
    (\ctikzvalof{bipole/name}#1){\pgf@circ@finallabels{#1}}
}

\def\pgf@circ@drawreglabels#1{
    %Now calculate all shape positions
    %Use mid-anchor at x-axis and base-anchor at y-axis, respectively.
    %All points between will be addressed by angled-anchors:
    \pgfextra{
        % scale ex-distance to make it independent on scale
        % thanks @marmot see https://tex.stackexchange.com/a/476018/38080
        \pgfgettransformentries{\tmpa}{\tmpb}{\tmpc}{\tmpd}{\tmp}{\tmp}%
        \pgfmathsetmacro{\myscale}{sqrt(abs(\tmpa*\tmpd-\tmpb*\tmpc))}% abs should not be needed
        % \typeout{ROT\tmpa\space\tmpb\space\tmpc\space\tmpd\space\myscale}
        \pgfmathsetlength\pgf@circ@res@temp{\pgf@circ@ls/\myscale+\ctikzvalof{#1 distance}/\myscale}
        \pgfmathadd{\pgf@circ@labanc}{90}
        \pgfmathround{\pgfmathresult}
        \def\pgf@circ@labanctext{\pgf@circ@labanc}
        \edef\pgf@circ@temp{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
        \pgfmathparse{mod(\pgf@circ@temp,180)>135?mod(\pgf@circ@temp,180)-180:mod(\pgf@circ@temp,180)}
        \edef\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
    }
    %Values around 90 are at both y-axis
    \ifnum \pgfcircmathresult > 84 \ifnum \pgfcircmathresult< 96
        \pgfextra{\edef\pgf@circ@labpos{\expandafter\pgf@circ@stripdecimals\pgf@circ@direction\pgf@nil}}
        \ifnum \pgf@circ@labpos > 180
            \ifnum \ctikzvalof{bipole/#1/position} > 0
                    \pgfextra{\def\pgf@circ@labanctext{mid west}}
            \else
                    \pgfextra{\def\pgf@circ@labanctext{mid east}}
            \fi
        \else
            \ifnum \ctikzvalof{bipole/#1/position} > 0
                    \pgfextra{\def\pgf@circ@labanctext{mid east}}
            \else
                    \pgfextra{\def\pgf@circ@labanctext{mid west}}
            \fi
        \fi
    \fi\fi
    %Values between -5 and 5 are at pos /neg x-axis
        \ifnum \pgfcircmathresult <6 \ifnum \pgfcircmathresult > -6
            \ifnum \ctikzvalof{bipole/#1/position} < 0
                \ifnum \pgf@circ@labanc > 90
                    % using base coordinate instead of south to naturally align
                    % symbols with descendants; but this invalidate the effect of
                    % the inner sep, so recover it by shifting the anchor
                    % reset cm is not working sometime, use @marmot solution
                    % see https://tex.stackexchange.com/a/476018/38080
                    %  notice that relative ++ movement disrupt to[] +()
                ($(pgfcirc@labelcoor)+(-\pgf@circ@labanc:\pgf@circ@res@temp)$) coordinate(pgfcirc@labelcoor)
                    \pgfextra{\def\pgf@circ@labanctext{base}}%base
                \else
                    \pgfextra{\def\pgf@circ@labanctext{north}}%north
                \fi
             \else
                \ifnum \pgf@circ@labanc < 90
                    % shift, as above
                ($(pgfcirc@labelcoor)+(-\pgf@circ@labanc:\pgf@circ@res@temp)$) coordinate(pgfcirc@labelcoor)
                    \pgfextra{\def\pgf@circ@labanctext{base}}%base
                \else
                    \ifnum \pgf@circ@labanc > 180
                        % this shouldn't  happen, but somehow it does (270 degree anchors)
                        % shift, as above
                    ($(pgfcirc@labelcoor)+(-\pgf@circ@labanc:\pgf@circ@res@temp)$) coordinate(pgfcirc@labelcoor)
                         \pgfextra{\def\pgf@circ@labanctext{base}}%base
                    \else
                      \pgfextra{\def\pgf@circ@labanctext{north}}%north
                   \fi
                \fi
            \fi
        \fi\fi
    \pgfextra{%
        \expandafter\xdef\csname pgfcirc@\pgfcirc@a@prefix#1-direction\endcsname{0}%
        \expandafter\xdef\csname pgfcirc@\pgfcirc@a@prefix-#1-anchor\endcsname{\pgf@circ@labanctext}%
    }
    (pgfcirc@labelcoor) node[anchor=\pgf@circ@labanctext,
    inner sep=0.5\pgf@circ@res@temp, outer sep=0pt, \circuitikzbasekey/bipole #1 style,
        ](\ctikzvalof{bipole/name}#1){\strut\pgf@circ@finallabels{#1}%
    }
}

\def\pgf@circ@finallabels#1{%
    \edef\pgf@temp{}%
    \edef\pgf@circ@temp{\ctikzvalof{bipole/#1/unit}}%
    \ifx\pgf@temp\pgf@circ@temp%
        \ctikzvalof{bipole/#1/name}%
    \else%
        $\SI{\ctikzvalof{bipole/#1/name}}{\ctikzvalof{bipole/#1/unit}}$%
    \fi%
}


%%%% Stacked labels
%
% stacked labels by Romano Giannetti romano@rgtti.com
% heavily based on Claudo Fiandrinos's https://tex.stackexchange.com/a/65792/38080
% \expandafter trick inspired by Matthew Leingang's https://tex.stackexchange.com/a/12272/38080
%
% labels are in a tabular, globally aligned:
%        vertically with key l2 valign (default c)
%        c: center t: top b: bottom
%        horizontally with key l2 align (default l)
%        l: left c: centered r: right
% you can switch sides using l2_=... and l2^=...
% syntax is l2_ = line1 and line2 (same for l2^)
%
\ctikzset{%
    l2 valign/.store in=\pgfcirc@ltwo@valign, l2 valign=c,
    l2 halign/.store in=\pgfcirc@ltwo@halign, l2 halign=l,
}
\ctikzset{l2base/.code n args={2}{
  \pgfkeys{/tikz/circuitikz/bipole/label/name=%
        \bgroup
        \setlength{\tabcolsep}{2pt}%
        \def\pgfcirc@ltwo@tabu{\tabular[\pgfcirc@ltwo@valign]}%
        \expandafter\pgfcirc@ltwo@tabu\expandafter{\pgfcirc@ltwo@halign}%
        #1\\ #2%
        \endtabular
        \egroup
    }%
}}
\ctikzset{l2/.style args={#1and#2}{
        l2base={#1}{#2},
    \circuitikzbasekey/bipole/label/position=90 }
}
\ctikzset{l2 above/.style args={#1and#2}{
        l2base={#1}{#2},
    \circuitikzbasekey/bipole/label/position=90 }
}
\ctikzset{l2^/.style args={#1and#2}{
        l2base={#1}{#2},
    \circuitikzbasekey/bipole/label/position=90 }
}
\ctikzset{l2 below/.style args={#1and#2}{
        l2base={#1}{#2},
    \circuitikzbasekey/bipole/label/position=-90 }
}
\ctikzset{l2_/.style args={#1and#2}{
        l2base={#1}{#2},
    \circuitikzbasekey/bipole/label/position=-90 }
}
%
% the same for annotations
%
\ctikzset{%
    a2 valign/.store in=\pgfcirc@atwo@valign, a2 valign=c,
    a2 halign/.store in=\pgfcirc@atwo@halign, a2 halign=r,
}
\ctikzset{a2base/.code n args={2}{
  \pgfkeys{/tikz/circuitikz/bipole/annotation/name=%
        \bgroup
        \setlength{\tabcolsep}{2pt}%
        \def\pgfcirc@atwo@tabu{\tabular[\pgfcirc@atwo@valign]}%
        \expandafter\pgfcirc@atwo@tabu\expandafter{\pgfcirc@atwo@halign}%
        #1\\ #2%
        \endtabular
        \egroup
    }%
}}
\ctikzset{a2/.style args={#1and#2}{
        a2base={#1}{#2},
    \circuitikzbasekey/bipole/annotation/position=-90 }
}
\ctikzset{a2 above/.style args={#1and#2}{
        a2base={#1}{#2},
    \circuitikzbasekey/bipole/annotation/position=-90 }
}
\ctikzset{a2^/.style args={#1and#2}{
        a2base={#1}{#2},
    \circuitikzbasekey/bipole/annotation/position=-90 }
}
\ctikzset{a2 below/.style args={#1and#2}{
        a2base={#1}{#2},
    \circuitikzbasekey/bipole/annotation/position=90 }
}
\ctikzset{a2_/.style args={#1and#2}{
        a2base={#1}{#2},
    \circuitikzbasekey/bipole/annotation/position=90 }
}

%%%---------- close: tex/pgfcirclabel
%%%%%%%%%%% Springe nach tex/pgfcircvoltage
%%%---------- open: tex/pgfcircvoltage.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%  Voltage management

%% styles%<<<
\ctikzset{bipole voltage style/.style={}}
\tikzset{bipole voltage style/.code={
        \ctikzset{bipole voltage style/.style={#1}}
}}
\tikzset{bipole voltage append style/.code={
        \ctikzset{bipole voltage style/.append style={#1}}
}}

\ctikzset{v^>/.style = {
        v={#1},
        \circuitikzbasekey/bipole/voltage/direction = forward,
        \circuitikzbasekey/bipole/voltage/position = above
    }
}

\ctikzset{v^</.style = {
        v={#1},
        \circuitikzbasekey/bipole/voltage/direction = backward,
        \circuitikzbasekey/bipole/voltage/position = above
    }
}

\ctikzset{v_>/.style = {
        v={#1},
        \circuitikzbasekey/bipole/voltage/direction = forward,
        \circuitikzbasekey/bipole/voltage/position = below
    }
}

\ctikzset{v_</.style = {
        v={#1},
        \circuitikzbasekey/bipole/voltage/direction = backward,
        \circuitikzbasekey/bipole/voltage/position = below
    }
}

\ctikzset{v_/.style = {v={#1}, \circuitikzbasekey/bipole/voltage/position = below} }
\ctikzset{v^/.style = {v={#1}, \circuitikzbasekey/bipole/voltage/position  = above} }
\ctikzset{v>/.style = {v={#1}, \circuitikzbasekey/bipole/voltage/direction = forward} }
\ctikzset{v</.style = {v={#1}, \circuitikzbasekey/bipole/voltage/direction = backward} }%

\newif\ifpgfcirc@do@v@symbols\pgfcirc@do@v@symbolstrue
\ctikzset{no v symbols/.code={\pgfcirc@do@v@symbolsfalse}}
\ctikzset{v symbols/.code={\pgfcirc@do@v@symbolstrue}}

% Default position varies whether the component is a voltage source
% or not
\ctikzset{v/.code = {
        \pgfcirc@has@vtrue
        \ifpgf@circuit@bipole@override@source@vif
            \pgf@circuit@bipole@isvoltagefalse
            \pgf@circuit@bipole@iscurrentfalse
        \fi
        \ifpgf@circuit@bipole@isvoltage
            \pgfkeys{\circuitikzbasekey/bipole/voltage/position=above,
            \circuitikzbasekey/bipole/voltage/direction=forward}
        \else
            \ifpgf@circ@oldvoltagedirection
                \pgfkeys{\circuitikzbasekey/bipole/voltage/position=below,
                \circuitikzbasekey/bipole/voltage/direction=backward}
            \else
                \pgfkeys{\circuitikzbasekey/bipole/voltage/position=below,
                \circuitikzbasekey/bipole/voltage/direction=forward}
            \fi
        \fi
        \ifpgf@circ@oldvoltagedirection
            \ifpgf@circuit@bipole@iscurrent\ifpgf@circ@fixbatteries
                \pgfkeys{\circuitikzbasekey/bipole/voltage/position=below,
                \circuitikzbasekey/bipole/voltage/direction=forward}
        \fi\fi
        \else
        \ifpgf@circuit@bipole@iscurrent
            \ifpgf@circuit@bipole@current@backward
                \pgfkeys{\circuitikzbasekey/bipole/voltage/position=below,
                \circuitikzbasekey/bipole/voltage/direction=forward}
            \else
                \pgfkeys{\circuitikzbasekey/bipole/voltage/position=below,
                \circuitikzbasekey/bipole/voltage/direction=backward}
            \fi\fi\fi
            \pgfkeys{/tikz/circuitikz/bipole/voltage/label/name={#1}}
            \ctikzsetvalof{bipole/voltage/label/unit}{}
            \ifpgf@circ@siunitx
                \pgf@circ@handleSI{#1}
                \ifpgf@circ@siunitx@res
                    \edef\pgf@temp{\pgf@circ@handleSI@val}
                    \pgfkeyslet{/tikz/circuitikz/bipole/voltage/label/name}{\pgf@temp}
                    \edef\pgf@temp{\pgf@circ@handleSI@unit}
                    \pgfkeyslet{/tikz/circuitikz/bipole/voltage/label/unit}{\pgf@temp}
                \else
            \fi
            \else
        \fi
    }
}
% %>>>

% american voltage font selection and symbol definition
% the default font command is {} --- nothing
\def\pgf@circ@avfont{\ctikzvalof{voltage/american font}}
%
% In the mayority of fonts, the size of - is smaller than +, so we have
% unaligned signs when positioned independently.
% See https://github.com/circuitikz/circuitikz/issues/721
% plus and minus symbols (default is $+$ and $\vphantom{+}-$, see pgfcirc.defines.tex)
%
\def\pgf@circ@avplus{\ctikzvalof{voltage/american plus}}
\def\pgf@circ@avminus{\ctikzvalof{voltage/american minus}}

%%
\def\setscaledRlenforclass{%
    \csname pgf@sh@ma@\ctikzvalof{bipole/name}\endcsname
    \ifdefined\ctikzclass
        \edef\pgf@temp{/tikz/circuitikz/\ctikzclass/scale}
        \pgfkeysifdefined{\pgf@temp}
            {\pgf@circ@scaled@Rlen=\ctikzvalof{\ctikzclass/scale}\pgf@circ@Rlen}
            {\pgf@circ@scaled@Rlen=\pgf@circ@Rlen}
    \else
        \pgf@circ@scaled@Rlen=\pgf@circ@Rlen
    \fi
}

%% Output routine for generic bipoles%<<<
% put this to true to see the voltage label coordinate anchors
\newif\ifpgf@circ@debugv\pgf@circ@debugvfalse

\def\pgf@circ@drawvoltagegeneric{
    \pgfextra{
        % \typeout{KIND:\ctikzvalof{bipole/kind}\space RLEN:\the\pgf@circ@Rlen\space SCALED:\the\pgf@circ@scaled@Rlen}
        \ifnum \ctikzvalof{mirror value}=-1
            \ifpgf@circuit@bipole@inverted
                \def\distfromline{\ctikzvalof{voltage/distance from line}\pgf@circ@scaled@Rlen}
            \else
                \def\distfromline{-\ctikzvalof{voltage/distance from line}\pgf@circ@scaled@Rlen}
            \fi
        \else
            \ifpgf@circuit@bipole@inverted
                    \def\distfromline{-\ctikzvalof{voltage/distance from line}\pgf@circ@scaled@Rlen}
                \else
                    \def\distfromline{\ctikzvalof{voltage/distance from line}\pgf@circ@scaled@Rlen}
            \fi
        \fi
        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@voltage@angle{90}
        \else
            \def\pgf@circ@voltage@angle{-90}
        \fi
        \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/distance from node}
        \pgfkeysifdefined{\pgf@temp}
            { \edef\distancefromnode{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/distance from node}} }
            { \edef\distancefromnode{\ctikzvalof{voltage/distance from node}} }
        \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/bump b}
        \pgfkeysifdefined{\pgf@temp}
            { \edef\bumpb{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/bump b}} }
            { \edef\bumpb{\ctikzvalof{voltage/bump b}} }
        \edef\shiftv{\ctikzvalof{voltage/shift}}
        % additional per-bipole voltage shift (internal)
        \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/additional shift}
        \pgfkeysifdefined{\pgf@temp}
        {
            \edef\addvshift{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/additional shift}}
        }
        {
            \edef\addvshift{0}
        }
        \newdimen{\absvshift}
        \pgfmathsetlength{\absvshift}{(1+\shiftv+\addvshift)*(\distfromline)}
        % reset anchor if american and open
        \ifpgf@circuit@europeanvoltage
        \else
            \ifx\@@kind\@@open
                \def\pgf@circ@bipole@voltage@label@anchor{center}
            \fi
        \fi
        \ifpgf@circuit@bipole@voltage@raised
            \def\pgf@circ@bipole@voltage@label@anchor{center}
            \pgfmathsetlength{\absvshift}{\absvshift+sign(\absvshift)*height{"Q"}} % with the current font.
        \fi
        % apply the same shift to open "straight" voltage as raised
        \ifpgf@circuit@bipole@voltage@straight
            \ifx\@@kind\@@open
                \def\pgf@circ@bipole@voltage@label@anchor{center}
                \pgfmathsetlength{\absvshift}{\absvshift+sign(\absvshift)*height{"Q"}} % with the current font.
            \fi
        \fi
    }
    % %\pgf@circ@Rlen/\ctikzvalof{current arrow scale} is equal to the length of the currarrow
    %absolute move, minimum space is length of arrowhead
    coordinate (pgfcirc@midtmp) at ($(\tikztostart) ! \pgf@circ@Rlen/\ctikzvalof{current arrow scale} ! (pgfcirc@anchorstartnode)$)
    coordinate (pgfcirc@midtmp) at ($(pgfcirc@midtmp) ! \distancefromnode ! (pgfcirc@anchorstartnode)$)
    coordinate (pgfcirc@Vfrom@flat) at (pgfcirc@midtmp)
    %absolute move, minimum space is length of arrowhead
    coordinate (pgfcirc@midtmp) at ($(\tikztotarget) ! \pgf@circ@Rlen/\ctikzvalof{current arrow scale} ! (pgfcirc@anchorendnode)$)
    coordinate (pgfcirc@midtmp) at ($(pgfcirc@midtmp) ! \distancefromnode ! (pgfcirc@anchorendnode)$)
    coordinate (pgfcirc@Vto@flat) at (pgfcirc@midtmp)
    coordinate (pgfcirc@mid) at ($(pgfcirc@Vfrom@flat)!0.5!(pgfcirc@Vto@flat)$)

    \ifpgf@circuit@bipole@voltage@below
    % see comments for the "above" part (similar)
        \ifpgf@circuit@europeanvoltage
            \ifpgf@circuit@bipole@voltage@straight
                coordinate (pgfcirc@bottom) at (\ctikzvalof{bipole/name}.-90)
                coordinate (pgfcirc@Vto1) at ($(pgfcirc@mid)+(pgfcirc@bottom)-(pgfcirc@Vfrom@flat)$)
                coordinate (pgfcirc@Vfrom1) at ($(pgfcirc@mid)+(pgfcirc@bottom)-(pgfcirc@Vto@flat)$)
                coordinate (\pgfcirc@a@prefix-Vto)   at ($(pgfcirc@Vto1) ! \absvshift!90 :  (pgfcirc@Vfrom1)$)
                coordinate (\pgfcirc@a@prefix-Vfrom) at ($(pgfcirc@Vfrom1) ! \absvshift!-90 :  (pgfcirc@Vto1)$)
                coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vto)!0.5!(\pgfcirc@a@prefix-Vfrom) $)
                coordinate (pgfcirc@Vdir) at (\pgfcirc@a@prefix-Vto)
            \else
                coordinate (\pgfcirc@a@prefix-Vto)   at ($(pgfcirc@Vto@flat) ! \absvshift!90 :  (pgfcirc@anchorendnode)$)
                coordinate (\pgfcirc@a@prefix-Vfrom) at ($(pgfcirc@Vfrom@flat) ! \absvshift!-90 :  (pgfcirc@anchorstartnode)$)
                coordinate (pgfcirc@Vcont1t) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.-110)$)
                coordinate (pgfcirc@Vcont2t) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.-70)$)
                coordinate (\pgfcirc@a@prefix-Vcont1) at ($(pgfcirc@Vcont1t) ! -\absvshift!90 : (pgfcirc@Vcont2t)$)
                coordinate (\pgfcirc@a@prefix-Vcont2) at ($(pgfcirc@Vcont2t) ! -\absvshift!-90 : (pgfcirc@Vcont1t)$)
                coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vcont2)!0.5!(\pgfcirc@a@prefix-Vcont1)$)
                coordinate (pgfcirc@Vdir) at (\pgfcirc@a@prefix-Vcont2)
            \fi
        \else
            % we are in case of american here
            coordinate (\pgfcirc@a@prefix-Vto) at ($(pgfcirc@Vto@flat) ! \absvshift!90 :  (pgfcirc@anchorendnode)$)
            coordinate (\pgfcirc@a@prefix-Vfrom) at ($(pgfcirc@Vfrom@flat) ! \absvshift!-90 :  (pgfcirc@anchorstartnode)$)
            coordinate (pgfcirc@bottom) at (\ctikzvalof{bipole/name}.-90)
            coordinate (pgfcirc@Vdir0) at ($(pgfcirc@mid)+(pgfcirc@bottom)-(pgfcirc@Vfrom@flat)$)
            coordinate (\pgfcirc@a@prefix-Vlab) at ($(pgfcirc@bottom) !  \absvshift!-90 : (pgfcirc@Vdir0)$)
            coordinate (pgfcirc@Vdir) at ($(pgfcirc@mid)+(\pgfcirc@a@prefix-Vlab)-(pgfcirc@Vfrom@flat)$)
            \ifpgf@circuit@bipole@voltage@raised
                % move the from and to up to the level of Vlab
                coordinate (\pgfcirc@a@prefix-Vto) at ($(\pgfcirc@a@prefix-Vlab)+(pgfcirc@Vto@flat)-(pgfcirc@mid)$)
                coordinate (\pgfcirc@a@prefix-Vfrom) at ($(\pgfcirc@a@prefix-Vlab)+(pgfcirc@Vfrom@flat)-(pgfcirc@mid)$)
            \fi
        \fi
    \else
        \ifpgf@circuit@europeanvoltage
            \ifpgf@circuit@bipole@voltage@straight
                coordinate (pgfcirc@top) at (\ctikzvalof{bipole/name}.90)
                % move parallel to the component line at pgfcirc@top distance
                coordinate (pgfcirc@Vto1) at ($(pgfcirc@mid)+(pgfcirc@top)-(pgfcirc@Vfrom@flat)$)
                coordinate (pgfcirc@Vfrom1) at ($(pgfcirc@mid)+(pgfcirc@top)-(pgfcirc@Vto@flat)$)
                % add the extra distance
                coordinate (\pgfcirc@a@prefix-Vto)   at ($(pgfcirc@Vto1) ! \absvshift!-90 :  (pgfcirc@Vfrom1)$)
                coordinate (\pgfcirc@a@prefix-Vfrom) at ($(pgfcirc@Vfrom1) ! \absvshift!90 :  (pgfcirc@Vto1)$)
                coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vto)!0.5!(\pgfcirc@a@prefix-Vfrom) $)
                % direction line to shift the label later
                coordinate (pgfcirc@Vdir) at (\pgfcirc@a@prefix-Vto)
            \else
                % european voltages here
                coordinate (\pgfcirc@a@prefix-Vto) at ($(pgfcirc@Vto@flat) ! -\absvshift!90 :  (pgfcirc@anchorendnode)$)
                coordinate (\pgfcirc@a@prefix-Vfrom) at ($(pgfcirc@Vfrom@flat) ! -\absvshift!-90 :  (pgfcirc@anchorstartnode)$)
                % identify the two control points for the "arc" of the voltage
                coordinate (pgfcirc@Vcont1t) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.110)$)
                coordinate (pgfcirc@Vcont2t) at ($(\ctikzvalof{bipole/name}.center) ! \bumpb ! (\ctikzvalof{bipole/name}.70)$)
                % and shift them a bit
                coordinate (\pgfcirc@a@prefix-Vcont1) at ($(pgfcirc@Vcont1t) ! \absvshift!90 : (pgfcirc@Vcont2t)$)
                coordinate (\pgfcirc@a@prefix-Vcont2) at ($(pgfcirc@Vcont2t) ! \absvshift!-90 : (pgfcirc@Vcont1t)$)
                coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vcont2)!0.5!(\pgfcirc@a@prefix-Vcont1)$)
                % direction line to shift the label later
                coordinate (pgfcirc@Vdir) at (\pgfcirc@a@prefix-Vcont2)
            \fi
        \else
            % we are in case of american here
            coordinate (\pgfcirc@a@prefix-Vto) at ($(pgfcirc@Vto@flat) ! \absvshift!-90 :  (pgfcirc@anchorendnode)$)
            coordinate (\pgfcirc@a@prefix-Vfrom) at ($(pgfcirc@Vfrom@flat) ! \absvshift!90 :  (pgfcirc@anchorstartnode)$)
            coordinate (pgfcirc@top) at (\ctikzvalof{bipole/name}.90)
            % move parallel to the component line
            coordinate (pgfcirc@Vdir0) at ($(pgfcirc@mid)+(pgfcirc@top)-(pgfcirc@Vfrom@flat)$)
            % and add the extra distance
            coordinate (\pgfcirc@a@prefix-Vlab) at ($(pgfcirc@top) !  \absvshift!90 : (pgfcirc@Vdir0)$)
            coordinate (pgfcirc@Vdir) at ($(pgfcirc@mid)+(\pgfcirc@a@prefix-Vlab)-(pgfcirc@Vfrom@flat)$)
            \ifpgf@circuit@bipole@voltage@raised
                % move the from and to up to the level of Vlab
                coordinate (\pgfcirc@a@prefix-Vto) at ($(\pgfcirc@a@prefix-Vlab)+(pgfcirc@Vto@flat)-(pgfcirc@mid)$)
                coordinate (\pgfcirc@a@prefix-Vfrom) at ($(\pgfcirc@a@prefix-Vlab)+(pgfcirc@Vfrom@flat)-(pgfcirc@mid)$)
            \fi
        \fi
    \fi
    \ifx\@@kind\@@open
        coordinate (\pgfcirc@a@prefix-Vto) at (pgfcirc@Vto@flat)
        coordinate (\pgfcirc@a@prefix-Vfrom) at (pgfcirc@Vfrom@flat)
    \fi
    \ifpgf@circ@debugv
        node [ocirc, fill=red] at (pgfcirc@anchorstartnode) {}
        node [ocirc, fill=blue] at (pgfcirc@anchorendnode) {}
        node [ocirc, fill=green] at (\pgfcirc@a@prefix-Vto) {}
        node [ocirc, fill=yellow] at (\pgfcirc@a@prefix-Vfrom) {}
        node [odiamondpole, fill=green!50!black] at (pgfcirc@Vto@flat) {}
        node [odiamondpole, fill=orange] at (pgfcirc@Vfrom@flat) {}
        \ifpgf@circuit@europeanvoltage
            \ifpgf@circuit@bipole@voltage@straight
            \else
                node [osquarepole, fill=red] at (\pgfcirc@a@prefix-Vcont1) {}
                node [osquarepole, fill=blue] at (\pgfcirc@a@prefix-Vcont2) {}
            \fi
        \fi
    \fi

    %
    % Now we draw the voltage things (only if not empty --- in which case we have been
    % called just to set the anchors)
    %
    \pgf@circ@ifkeyempty{bipole/voltage/label/name}\else
    \ifpgfcirc@do@v@symbols
    \ifpgf@circuit@europeanvoltage
        \ifpgf@circuit@bipole@voltage@straight
            \ifpgf@circuit@bipole@voltage@backward
                (\pgfcirc@a@prefix-Vto) --(\pgfcirc@a@prefix-Vfrom) node[currarrow, sloped,  allow upside down, pos=1,anchor=tip] {}
            \else
                (\pgfcirc@a@prefix-Vfrom) --(\pgfcirc@a@prefix-Vto) node[currarrow, sloped,  allow upside down, pos=1,anchor=tip] {}
            \fi
        \else
            \ifpgf@circuit@bipole@voltage@backward
                (\pgfcirc@a@prefix-Vto) .. controls (\pgfcirc@a@prefix-Vcont2)  and (\pgfcirc@a@prefix-Vcont1) ..
                node[currarrow, sloped,  allow upside down, pos=1, anchor=tip] {}
                (\pgfcirc@a@prefix-Vfrom)
            \else
                (\pgfcirc@a@prefix-Vfrom) .. controls (\pgfcirc@a@prefix-Vcont1)  and (\pgfcirc@a@prefix-Vcont2) ..
                node[currarrow, sloped,  allow upside down, pos=1, anchor=tip] {}
                (\pgfcirc@a@prefix-Vto)
            \fi
        \fi
    \else % american
        \ifpgf@circuit@bipole@voltage@backward
            \ifpgf@circ@oldvoltagedirection
                (\pgfcirc@a@prefix-Vfrom) node[inner sep=0, node font=\pgf@circ@avfont,
                    anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avplus}
                (\pgfcirc@a@prefix-Vto) node[inner sep=0, node font=\pgf@circ@avfont,
                    anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avminus}
            \else
                (\pgfcirc@a@prefix-Vfrom) node[inner sep=0, node font=\pgf@circ@avfont,
                    anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avminus}
                (\pgfcirc@a@prefix-Vto) node[inner sep=0, node font=\pgf@circ@avfont,
                    anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avplus}
            \fi
            \else
            \ifpgf@circ@oldvoltagedirection
                (\pgfcirc@a@prefix-Vfrom) node[inner sep=0, node font=\pgf@circ@avfont,
                    anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avminus}
                (\pgfcirc@a@prefix-Vto) node[inner sep=0, node font=\pgf@circ@avfont,
                    anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avplus}
            \else
                (\pgfcirc@a@prefix-Vfrom) node[inner sep=0, node font=\pgf@circ@avfont,
                    anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avplus}
                (\pgfcirc@a@prefix-Vto) node[inner sep=0, node font=\pgf@circ@avfont,
                    anchor=\pgf@circ@bipole@voltage@label@anchor]{\pgf@circ@avminus}
            \fi
        \fi
    \fi
    \fi % closing the ...symbol
    \fi % Closing the ...ifempty
}
% %>>>

%% Output routine for voltage sources%<<<
% (ugly) workaround for https://github.com/circuitikz/circuitikz/issues/747
\ctikzset{voltage shift sources adjust/.initial=0.5} % coefficient added "by feel". Sorry.
\def\pgf@circ@drawvoltagegenerator{
    % the following is affected indirectly by voltage/shift, you can move the arrow with voltage/bump a.
    % it's not perfect, but I can't find the way to do it correctly...
    \pgfextra{
        \edef\shiftv{\ctikzvalof{voltage/shift}}
        % distance along the 60-120 axis
        \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/bump a}
        \pgfkeysifdefined{\pgf@temp}
        {
            \edef\bumpa{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/bump a}}
        }
        {
            \edef\bumpa{\ctikzvalof{voltage/bump a}}
        }
        % additional per-bipole voltage shift (internal)
        \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/additional shift}
        \pgfkeysifdefined{\pgf@temp}
        {
            \edef\addvshift{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/additional shift}}
        }
        {
            \edef\addvshift{0}
        }
        \pgfmathsetmacro{\bumpaplus}{\bumpa + \ctikzvalof{voltage shift sources adjust}*\shiftv}
    }
    \ifpgf@circuit@bipole@voltage@below
        coordinate (pgfcirc@Vfrom0) at ($(\ctikzvalof{bipole/name}.center) ! \bumpaplus ! (\ctikzvalof{bipole/name}.-120)$)
        coordinate (pgfcirc@Vto0) at ($(\ctikzvalof{bipole/name}.center) ! \bumpaplus ! (\ctikzvalof{bipole/name}.-60)$)
        coordinate (\pgfcirc@a@prefix-Vfrom) at ($ (pgfcirc@Vfrom0) ! \addvshift! -90: (pgfcirc@Vto0) $)
        coordinate (\pgfcirc@a@prefix-Vto) at ($ (pgfcirc@Vto0) ! \addvshift! 90: (pgfcirc@Vfrom0) $)
    \else
        coordinate (pgfcirc@Vfrom0) at ($ (\ctikzvalof{bipole/name}.center) ! \bumpaplus ! (\ctikzvalof{bipole/name}.120)$)
        coordinate (pgfcirc@Vto0) at ($ (\ctikzvalof{bipole/name}.center) ! \bumpaplus ! (\ctikzvalof{bipole/name}.60)$)
        coordinate (\pgfcirc@a@prefix-Vfrom) at ($ (pgfcirc@Vfrom0) ! \addvshift! 90: (pgfcirc@Vto0) $)
        coordinate (\pgfcirc@a@prefix-Vto) at ($ (pgfcirc@Vto0) ! \addvshift! -90: (pgfcirc@Vfrom0) $)
    \fi
    coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vto)!0.5!(\pgfcirc@a@prefix-Vfrom) $)
    coordinate (pgfcirc@Vdir) at (\pgfcirc@a@prefix-Vto)
    \pgf@circ@ifkeyempty{bipole/voltage/label/name}\else
    \ifpgfcirc@do@v@symbols
    \ifpgf@circuit@europeanvoltage
        \ifpgf@circuit@bipole@voltage@backward
            (\pgfcirc@a@prefix-Vto)  -- node[currarrow, sloped,  allow upside down, pos=1, anchor=tip] {} (\pgfcirc@a@prefix-Vfrom)
        \else
            (\pgfcirc@a@prefix-Vfrom)  -- node[currarrow, sloped,  allow upside down, pos=1, anchor=tip] {} (\pgfcirc@a@prefix-Vto)
        \fi
        \else% american voltage
        \ifpgf@circuit@bipole@voltageoutsideofsymbol
            % if it is a battery, must put + and -

            \ifpgf@circ@fixbatteries
                \ifpgf@circuit@bipole@voltage@backward
                    (\pgfcirc@a@prefix-Vfrom)  node[node font=\pgf@circ@avfont] {\pgf@circ@avplus}
                    (\pgfcirc@a@prefix-Vto) node[node font=\pgf@circ@avfont] {\pgf@circ@avminus}
                \else
                    (\pgfcirc@a@prefix-Vfrom)  node[node font=\pgf@circ@avfont] {\pgf@circ@avminus}
                    (\pgfcirc@a@prefix-Vto) node[node font=\pgf@circ@avfont] {\pgf@circ@avplus}
                \fi
                \else
                \ifpgf@circuit@bipole@voltage@backward
                    (\pgfcirc@a@prefix-Vfrom)  node[node font=\pgf@circ@avfont] {\pgf@circ@avminus}
                    (\pgfcirc@a@prefix-Vto) node[node font=\pgf@circ@avfont] {\pgf@circ@avplus}
                \else
                    (\pgfcirc@a@prefix-Vfrom)  node[node font=\pgf@circ@avfont] {\pgf@circ@avplus}
                    (\pgfcirc@a@prefix-Vto) node[node font=\pgf@circ@avfont] {\pgf@circ@avminus}
                \fi
            \fi
        \fi
    \fi
    \fi % closes ... ifsymbol
    \fi % closes ...ifempty
}
% %>>>

%% Output routine (main entry point) %<<<
%% this is the entry point
%%
%% locally used dimensions
\newdimen{\pgfcirc@labelshift}
\newif\ifpgfcirc@v@curved % helper if --- true only if voltages are curved
\def\pgf@circ@drawvoltage{% node name
    \pgfextra{%
        % set the helper if...curved
        \ifpgf@circuit@europeanvoltage
            \ifpgf@circuit@bipole@voltage@straight
                \pgfcirc@v@curvedfalse
            \else
                \pgfcirc@v@curvedtrue
            \fi
        \else
            \pgfcirc@v@curvedfalse
        \fi
        % \typeout{V routine called with prefix: \pgfcirc@a@prefix}
        % Label anchors WARNING: indentation is probably wrong
        \edef\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@direction\pgf@nil}
        \ifnum\pgfcircmathresult >4 \ifnum\pgfcircmathresult <86
        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@bipole@voltage@label@anchor{north west}
        \else
            \def\pgf@circ@bipole@voltage@label@anchor{south east}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >85 \ifnum\pgfcircmathresult <95
        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@bipole@voltage@label@anchor{west}
        \else
            \def\pgf@circ@bipole@voltage@label@anchor{east}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >94 \ifnum\pgfcircmathresult <176
        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@bipole@voltage@label@anchor{south west}
        \else \def\pgf@circ@bipole@voltage@label@anchor{north east}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >175 \ifnum\pgfcircmathresult <185
        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@bipole@voltage@label@anchor{south}
        \else\def\pgf@circ@bipole@voltage@label@anchor{north}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >184 \ifnum\pgfcircmathresult <266
        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@bipole@voltage@label@anchor{south east}
        \else\def\pgf@circ@bipole@voltage@label@anchor{north west}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >265 \ifnum\pgfcircmathresult <275
        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@bipole@voltage@label@anchor{east}
        \else \def\pgf@circ@bipole@voltage@label@anchor{west}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >274 \ifnum\pgfcircmathresult <356
        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@bipole@voltage@label@anchor{north east}
        \else\def\pgf@circ@bipole@voltage@label@anchor{south west}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >-1 \ifnum\pgfcircmathresult <5
        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@bipole@voltage@label@anchor{north}
        \else\def\pgf@circ@bipole@voltage@label@anchor{south}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >355 \ifnum\pgfcircmathresult <361
        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@bipole@voltage@label@anchor{north}
        \else\def\pgf@circ@bipole@voltage@label@anchor{south}
        \fi
        \fi\fi

        % export anchor position (if not needed, is always the same macro)
        \expandafter\xdef\csname pgfcirc@\pgfcirc@a@prefix-Vlab-anchor\endcsname{\pgf@circ@bipole@voltage@label@anchor}
        % this must be set *before* changing for mirroring and inverting; in that case
        % the xscale/yscale parameters take it into account
        \ifpgf@circuit@bipole@voltage@below
            \def\pgf@circ@bipole@voltage@label@where{-90}
        \else
            \def\pgf@circ@bipole@voltage@label@where{90}
        \fi

        % magic to counteract the scale and yscale effects (there should be a better way...)
        \ifnum \ctikzvalof{mirror value}=-1
            \ifpgf@circuit@bipole@voltage@below
                \pgf@circuit@bipole@voltage@belowfalse
            \else
                \pgf@circuit@bipole@voltage@belowtrue
            \fi
        \fi

        \ifpgf@circuit@bipole@inverted
            \ifpgf@circuit@bipole@voltage@below
                \pgf@circuit@bipole@voltage@belowfalse
            \else
                \pgf@circuit@bipole@voltage@belowtrue
            \fi
        \fi

        % take into account scaling
        \setscaledRlenforclass
        % set the macro for detecting open
        \edef\@@kind{\ctikzvalof{bipole/kind}}\edef\@@open{open}
        % start voltage label adjustment
        \ifpgf@circuit@europeanvoltage
            \ifpgf@circuit@bipole@voltage@straight
                % check for straight
                \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/straight label distance}
                \pgfkeysifdefined{\pgf@temp}{%
                    \edef\labeldist{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/straight label distance}}%
                    % \typeout{ST:ADJUSTED\space for\space \ctikzvalof{bipole/kind} \space at \space \stdist}
                }{\edef\labeldist{\ctikzvalof{voltage/straight label distance}}}
                \ifpgf@circ@debugv\edef\whichtypeshift{STR}\fi
                % do not labelshift for legacy straight open; 1.4 makes the shift null
                \ifx\@@kind\@@open\ifpgf@adjust@open@voltage\else\edef\labeldist{1.4}\fi\fi
            \else
                % check for european
                \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/european label distance}
                \pgfkeysifdefined{\pgf@temp}{%
                    \edef\labeldist{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/european label distance}}%
                    % \typeout{EU:ADJUSTED\space for\space \ctikzvalof{bipole/kind} \space at \space \eudist}
                }{ \edef\labeldist{\ctikzvalof{voltage/european label distance}}}
                \ifpgf@circ@debugv\edef\whichtypeshift{EUR}\fi
            \fi
        \else
            % check for american
            \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/voltage/american label distance}
            \pgfkeysifdefined{\pgf@temp}{%
                \ifpgf@circuit@bipole@voltage@raised
                    % do not apply the shift if we are using raised american style
                    \edef\labeldist{1.4}% default value
                \else
                    \edef\labeldist{\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/voltage/american label distance}}%
                \fi
                % \typeout{AL:ADJUSTED\space for\space \ctikzvalof{bipole/kind} \space at \space \aldist}
            }{\edef\labeldist{\ctikzvalof{voltage/american label distance}}}
            \ifpgf@circ@debugv\edef\whichtypeshift{AME}\fi
        \fi
        % find the height of the bipole or use a default value
        \edef\pgf@temp{/tikz/circuitikz/bipoles/\ctikzvalof{bipole/kind}/height}
        \pgfkeysifdefined{\pgf@temp}
            {\pgfmathsetmacro{\partheightf}{0.5*\ctikzvalof{bipoles/\ctikzvalof{bipole/kind}/height}}
             \edef\partheight{\partheightf\pgf@circ@scaled@Rlen}}
            {\edef\partheight{(.5\pgf@circ@scaled@Rlen)}} %fallback to fixed value
        \ifpgf@circuit@bipole@isvoltage
            \pgfmathsetlength{\pgfcirc@labelshift}{(\labeldist-1.2)*\partheight}
        \else
            \pgfmathsetlength{\pgfcirc@labelshift}{(\labeldist-1.4)*\partheight}
        \fi
        % the value for the european was by default 1.4
        \pgfsetcornersarced{\pgfpointorigin}% do not use rounded corners!
        % stop the detection of open if I do not want special treatment
        \ifpgf@adjust@open@voltage\else\edef\@@open{this-will-nEver-match}\fi
        % \typeout{KIND\space\@@kind}
    }%end pgfextra

    \ifpgf@circuit@bipole@isvoltage
        \pgf@circ@drawvoltagegenerator
        % add fake cont1 and cont2 anchors for export
        coordinate (\pgfcirc@a@prefix-Vcont1) at ($(\pgfcirc@a@prefix-Vfrom) !0.5! (\pgfcirc@a@prefix-Vto)$)
        coordinate (\pgfcirc@a@prefix-Vcont2) at ($(\pgfcirc@a@prefix-Vfrom) !0.5! (\pgfcirc@a@prefix-Vto)$)
    \else
        \pgf@circ@drawvoltagegeneric
    \fi
    % % debugging
    % \pgfextra{%
    %     \typeout{LABEL\space KIND:\@@kind\space EU:\the\pgfcirc@eushift\space AL:\the\pgfcirc@alshift\space
    %         DIRECTION:\pgf@circ@bipole@voltage@label@where}
    %     \pgf@circ@debugvtrue}

    % move a bit if requested
    coordinate (\pgfcirc@a@prefix-Vlab) at ($(\pgfcirc@a@prefix-Vlab) ! \pgfcirc@labelshift ! \pgf@circ@bipole@voltage@label@where :(pgfcirc@Vdir)$)

    % check for the case of american AND open
    \ifpgf@circuit@europeanvoltage
    \else
        \ifx\@@kind\@@open
        % override pgfcirc@Vlab
            coordinate (\pgfcirc@a@prefix-Vlab) at ($(pgfcirc@Vfrom@flat)!0.5!(pgfcirc@Vto@flat)$)
        \fi
    \fi

    \ifpgf@circ@debugv
            node [odiamondpole, color=blue] at (\pgfcirc@a@prefix-Vlab) {}
            node [odiamondpole, color=red] at (pgfcirc@Vdir) {}
            node [overlay, red, font=\tiny, anchor=south east, align=right] at(pgfcirc@Vdir)
            {\whichtypeshift:\the\pgfcirc@labelshift\\ DIR:\pgf@circ@bipole@voltage@label@where}
    \fi

    % put the node only if it's not empty
    \pgf@circ@ifkeyempty{bipole/voltage/label/name}\else
        node [anchor=\pgf@circ@bipole@voltage@label@anchor, inner sep=2pt,
        \circuitikzbasekey/bipole voltage style](\ctikzvalof{bipole/name}voltage)
        at (\pgfcirc@a@prefix-Vlab) {\pgf@circ@finallabels{voltage/label}}
    \fi

    \ifpgfcirc@v@curved\else
        % fake Vcont1 and Vcont2 for when they are exported --- in the middle of Vto and Vfrom
        coordinate (\pgfcirc@a@prefix-Vcont1) at ($(\pgfcirc@a@prefix-Vfrom) !0.5! (\pgfcirc@a@prefix-Vto)$)
        coordinate (\pgfcirc@a@prefix-Vcont2) at ($(\pgfcirc@a@prefix-Vfrom) !0.5! (\pgfcirc@a@prefix-Vto)$)
    \fi
    % revert from and to (and c1 - c2) if needed (simpler than rework the positioning above...)
    \ifpgf@circuit@bipole@voltage@backward
        \pgfcirc@swap@coordinates{\pgfcirc@a@prefix-Vfrom}{\pgfcirc@a@prefix-Vto}
        \pgfcirc@swap@coordinates{\pgfcirc@a@prefix-Vcont1}{\pgfcirc@a@prefix-Vcont2}
    \fi

}%end drawvoltages

% %>>>

%% these should be arguably moved to every component definition...

% special cases for voltage positions%<<<1
% the KIND is the node name without SHAPE
% See the definition above for meaning
% if bipoles/KIND/voltage/straight label distance is not defined, it uses the height
% if bipoles/KIND/voltage/additional shift is not defined, it is 0 (extra distance)
%
\ctikzset{bipoles/generic/voltage/distance from node/.initial=0.4}
\ctikzset{bipoles/generic/voltage/bump b/.initial=2}
%
\ctikzset{bipoles/ageneric/voltage/distance from node/.initial=.4}
\ctikzset{bipoles/ageneric/voltage/bump b/.initial=2}
%
\ctikzset{bipoles/fullgeneric/voltage/distance from node/.initial=.4}
\ctikzset{bipoles/fullgeneric/voltage/bump b/.initial=2}
%
\ctikzset{bipoles/memristor/voltage/distance from node/.initial=.4}
\ctikzset{bipoles/memristor/voltage/bump b/.initial=2}
%
\ctikzset{bipoles/tline/voltage/bump b/.initial=2.4}
%
\ctikzset{bipoles/varistor/voltage/bump b/.initial=2.4}
\ctikzset{bipoles/varistor/voltage/american label distance/.initial=1.8}
%
\ctikzset{bipoles/photoresistor/voltage/bump b/.initial=1.6}
%
\ctikzset{bipoles/thermistor/voltage/bump b/.initial=2.4}
\ctikzset{bipoles/thermistor/voltage/european label distance/.initial=0.8}
\ctikzset{bipoles/thermistorntc/voltage/bump b/.initial=1.6}
\ctikzset{bipoles/thermistorntc/voltage/european label distance/.initial=0.8}
\ctikzset{bipoles/thermistorptc/voltage/bump b/.initial=1.6}
\ctikzset{bipoles/thermistorptc/voltage/european label distance/.initial=0.8}
%
\ctikzset{bipoles/ccapacitor/voltage/bump b/.initial=2.2}
%
\ctikzset{bipoles/emptyzzdiode/voltage/bump b/.initial=2.5}
\ctikzset{bipoles/emptyzzdiode/voltage/european label distance/.initial=1.0}
\ctikzset{bipoles/fullzzdiode/voltage/bump b/.initial=2.5}
\ctikzset{bipoles/fullzzdiode/voltage/european label distance/.initial=1.0}
\ctikzset{bipoles/emptythyristor/voltage/bump b/.initial=2.0}
\ctikzset{bipoles/emptythyristor/voltage/european label distance/.initial=1.2}
\ctikzset{bipoles/fullthyristor/voltage/bump b/.initial=2.0}
\ctikzset{bipoles/fullthyristor/voltage/european label distance/.initial=1.2}
\ctikzset{bipoles/emptytriac/voltage/bump b/.initial=1.8}
\ctikzset{bipoles/emptytriac/voltage/european label distance/.initial=0.8}
\ctikzset{bipoles/fulltriac/voltage/bump b/.initial=1.8}
\ctikzset{bipoles/fulltriac/voltage/european label distance/.initial=0.8}
%
\ctikzset{bipoles/short/voltage/american label distance/.initial=2.8}
\ctikzset{bipoles/open/voltage/distance from node/.initial=0.3}
%
\ctikzset{bipoles/battery/voltage/bump a/.initial=1.4}
\ctikzset{bipoles/vsourceAM/voltage/american label distance/.initial=1.2}
\ctikzset{bipoles/cvsourceAM/voltage/american label distance/.initial=1.2}
%%>>>

% vim: set fdm=marker fmr=%<<<,%>>>:
%%%---------- close: tex/pgfcircvoltage
%%%%%%%%%%% Springe nach tex/pgfcirccurrent
%%%---------- open: tex/pgfcirccurrent.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Current handling

%% styles
\ctikzset{bipole current style/.style={}}
\tikzset{bipole current style/.code={
        \ctikzset{bipole current style/.style={#1}}
}}
\tikzset{bipole current append style/.code={
        \ctikzset{bipole current style/.append style={#1}}
}}

%% Options
\ctikzset{i^>/.style = {
        i={#1},
        \circuitikzbasekey/bipole/current/direction = forward,
        \circuitikzbasekey/bipole/current/x position = after,
        \circuitikzbasekey/bipole/current/y position = above
    }
}

\ctikzset{i_>/.style = {
        i={#1},
        \circuitikzbasekey/bipole/current/direction = forward,
        \circuitikzbasekey/bipole/current/x position = after,
        \circuitikzbasekey/bipole/current/y position = below
    }
}

\ctikzset{i>^/.style = {
        i={#1},
        \circuitikzbasekey/bipole/current/direction = forward,
        \circuitikzbasekey/bipole/current/x position = before,
        \circuitikzbasekey/bipole/current/y position = above
    }
}

\ctikzset{i>_/.style = {
        i={#1},
        \circuitikzbasekey/bipole/current/direction = forward,
        \circuitikzbasekey/bipole/current/x position = before,
        \circuitikzbasekey/bipole/current/y position = below
    }
}

\ctikzset{i^</.style = {
        i={#1},
        \circuitikzbasekey/bipole/current/direction = backward,
        \circuitikzbasekey/bipole/current/x position = after,
        \circuitikzbasekey/bipole/current/y position = above
    }
}

\ctikzset{i_</.style = {
        i={#1},
        \circuitikzbasekey/bipole/current/direction = backward,
        \circuitikzbasekey/bipole/current/x position = after,
        \circuitikzbasekey/bipole/current/y position = below
    }
}

\ctikzset{i<^/.style = {
        i={#1},
        \circuitikzbasekey/bipole/current/direction = backward,
        \circuitikzbasekey/bipole/current/x position = before,
        \circuitikzbasekey/bipole/current/y position = above
    }
}

\ctikzset{i<_/.style = {
        i={#1},
        \circuitikzbasekey/bipole/current/direction = backward,
        \circuitikzbasekey/bipole/current/x position = before,
        \circuitikzbasekey/bipole/current/y position = below
    }
}

\newif\ifpgfcirc@do@i@symbols\pgfcirc@do@i@symbolstrue
\ctikzset{no i symbols/.code={\pgfcirc@do@i@symbolsfalse}}
\ctikzset{i symbols/.code={\pgfcirc@do@i@symbolstrue}}

\ctikzset{i/.code = {
        \pgfcirc@has@itrue
        \ifpgf@circuit@bipole@override@source@vif
            \pgf@circuit@bipole@isvoltagefalse
            \pgf@circuit@bipole@iscurrentfalse
        \fi
        \pgfkeys{\circuitikzbasekey/bipole/current/direction = forward,
            \circuitikzbasekey/bipole/current/x position = after,
        \circuitikzbasekey/bipole/current/y position = above }
        \pgfkeys{/tikz/circuitikz/bipole/current/label/name={#1}}
        \ctikzsetvalof{bipole/current/label/unit}{}
        \ifpgf@circ@siunitx
            \pgf@circ@handleSI{#1}
            \ifpgf@circ@siunitx@res
                \edef\pgf@temp{\pgf@circ@handleSI@val}
                \pgfkeyslet{/tikz/circuitikz/bipole/current/label/name}{\pgf@temp}
                \edef\pgf@temp{\pgf@circ@handleSI@unit}
                \pgfkeyslet{/tikz/circuitikz/bipole/current/label/unit}{\pgf@temp}
            \else
        \fi
        \else
    \fi
    %reverse current direction for voltage sources
    \ifpgf@circ@oldvoltagedirection\else
        \ifpgf@circuit@bipole@isvoltage
            \ifpgf@circuit@bipole@voltage@backward
                \pgfkeys{\circuitikzbasekey/bipole/current/direction = forward,
                    \circuitikzbasekey/bipole/current/x position = after,
                \circuitikzbasekey/bipole/current/y position = below }
            \else
                \pgfkeys{\circuitikzbasekey/bipole/current/direction = backward,
                    \circuitikzbasekey/bipole/current/x position = before,
                \circuitikzbasekey/bipole/current/y position = above }
            \fi\fi\fi
    }
}

\ifpgf@circ@oldvoltagedirection
    \ctikzset{i</.style = { i={#1}, \circuitikzbasekey/bipole/current/direction = backward } }
\else
    \ctikzset{i</.style = { i={#1}, \circuitikzbasekey/bipole/current/direction = backward, \circuitikzbasekey/bipole/current/x position = before } }
\fi
\ctikzset{i_/.style = { i={#1}, \circuitikzbasekey/bipole/current/y position = below } }
\ctikzset{i>/.style = {i={#1}, \circuitikzbasekey/bipole/current/direction = forward } }
\ctikzset{i^/.style = { i={#1}, \circuitikzbasekey/bipole/current/y position = above } }

%% Output routine
\def\pgf@circ@drawcurrent{
    \pgfextra{
        \edef\pgf@circ@rounded@dir{\pgf@circ@direction}
        \def\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@rounded@dir\pgf@nil}

        \ifnum\pgfcircmathresult >4 \ifnum\pgfcircmathresult <86
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{north west} \else \def\pgf@circ@dir{south east}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >85 \ifnum\pgfcircmathresult <95
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{west} \else \def\pgf@circ@dir{east}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >94 \ifnum\pgfcircmathresult <176
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{south west}\else \def\pgf@circ@dir{north east}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >175 \ifnum\pgfcircmathresult <185
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{south}\else\def\pgf@circ@dir{north}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >184 \ifnum\pgfcircmathresult <266
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{south east}\else\def\pgf@circ@dir{north west}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >265 \ifnum\pgfcircmathresult <275
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{east}\else \def\pgf@circ@dir{west}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult >274 \ifnum\pgfcircmathresult <356
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{north east}\else\def\pgf@circ@dir{south west}
        \fi
        \fi\fi
        \ifnum\pgfcircmathresult <5
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{north}\else\def\pgf@circ@dir{south}
        \fi
        \fi
        \ifnum\pgfcircmathresult >355
        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@dir{north}\else\def\pgf@circ@dir{south}
        \fi
        \fi
        % export anchor position (if not needed, is always the same macro)
        \expandafter\xdef\csname pgfcirc@\pgfcirc@a@prefix-Ilab-anchor\endcsname{\pgf@circ@dir}

        \ifpgf@circuit@bipole@current@below
            \def\pgf@circ@bipole@current@label@where{-90}
        \else
            \def\pgf@circ@bipole@current@label@where{+90}
        \fi
    }

    %
    \pgfextra{\def\pgf@temp{short}\edef\pgf@circ@temp{\ctikzvalof{bipole/kind}}}
    \ifx\pgf@circ@temp\pgf@temp%draw current at a short at middle of the line
        coordinate (\pgfcirc@a@prefix-Ifrom) at (\tikztostart)
        coordinate (\pgfcirc@a@prefix-Ito) at (\tikztotarget)
    \else% normal bipole or source
        \ifpgf@circuit@bipole@current@before
            coordinate (\pgfcirc@a@prefix-Ifrom) at (\tikztostart)
            coordinate (\pgfcirc@a@prefix-Ito) at (pgfcirc@anchorstartnode)
        \else
            coordinate (\pgfcirc@a@prefix-Ifrom) at (pgfcirc@anchorendnode)
            coordinate (\pgfcirc@a@prefix-Ito) at (\tikztotarget)
        \fi
    \fi
    \ifpgf@circuit@bipole@current@backward
        \pgfextra{
            \pgfmathsubtract{\pgf@circ@rounded@dir}{180}
            \edef\pgf@circ@rounded@dir{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
        }
    \fi
    coordinate (\pgfcirc@a@prefix-Ipos) at ($(\pgfcirc@a@prefix-Ifrom)! \ctikzvalof{current/distance} !(\pgfcirc@a@prefix-Ito)$)
    % export the current direction
    \pgfextra{\expandafter\xdef\csname pgfcirc@\pgfcirc@a@prefix-Iarrow-direction\endcsname{\pgf@circ@rounded@dir}}
    % if the current label is not empty (in which case we have already all the anchors)
    \pgf@circ@ifkeyempty{bipole/current/label/name}\else
    % put the arrow node
    % if we do not want the arrow, just put an empty node (needed to maintain the exact same distances)
    \ifpgfcirc@do@i@symbols
        node[currarrow, rotate=\pgf@circ@rounded@dir, anchor=center](Iarrow) at (\pgfcirc@a@prefix-Ipos) {}
    \else
        node[currarrow, rotate=\pgf@circ@rounded@dir, anchor=center,
            circuitikz/phantom@currarrow](Iarrow) at (\pgfcirc@a@prefix-Ipos) {}
    \fi
    % put the label
    node[anchor=\pgf@circ@dir, \circuitikzbasekey/bipole current style]
        (\ctikzvalof{bipole/name}current)
        at (Iarrow.\pgf@circ@bipole@current@label@where){\pgf@circ@finallabels{current/label}}
    \fi % end ifempty
    \ifpgf@circuit@bipole@current@backward
        \pgfcirc@swap@coordinates{\pgfcirc@a@prefix-Ifrom}{\pgfcirc@a@prefix-Ito}
    \fi
}

%%%---------- close: tex/pgfcirccurrent
%%%%%%%%%%% Springe nach tex/pgfcircflow
%%%---------- open: tex/pgfcircflow.tex
% Copyright 2018-2024 by Romano Giannetti
% Copyright 2015-2024 by Stefan Lindner
% Copyright 2013-2024 by Stefan Erhardt
% Copyright 2007-2024 by Massimo Redaelli
%
% 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 files gpl-3.0_license.txt and lppl-1-3c_license.txt for more details.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% flow handling


%% styles
\ctikzset{bipole flow style/.style={}}
\tikzset{bipole flow style/.code={
        \ctikzset{bipole flow style/.style={#1}}
}}
\tikzset{bipole flow append style/.code={
        \ctikzset{bipole flow style/.append style={#1}}
}}

%% Options
\ctikzset{f^>/.style = {
        f={#1},
        \circuitikzbasekey/bipole/flow/direction = forward,
        \circuitikzbasekey/bipole/flow/x position = after,
        \circuitikzbasekey/bipole/flow/y position = above
    }
}

\ctikzset{f_>/.style = {
        f={#1},
        \circuitikzbasekey/bipole/flow/direction = forward,
        \circuitikzbasekey/bipole/flow/x position = after,
        \circuitikzbasekey/bipole/flow/y position = below
    }
}

\ctikzset{f>^/.style = {
        f={#1},
        \circuitikzbasekey/bipole/flow/direction = forward,
        \circuitikzbasekey/bipole/flow/x position = before,
        \circuitikzbasekey/bipole/flow/y position = above
    }
}

\ctikzset{f>_/.style = {
        f={#1},
        \circuitikzbasekey/bipole/flow/direction = forward,
        \circuitikzbasekey/bipole/flow/x position = before,
        \circuitikzbasekey/bipole/flow/y position = below
    }
}

\ctikzset{f^</.style = {
        f={#1},
        \circuitikzbasekey/bipole/flow/direction = backward,
        \circuitikzbasekey/bipole/flow/x position = after,
        \circuitikzbasekey/bipole/flow/y position = above
    }
}

\ctikzset{f_</.style = {
        f={#1},
        \circuitikzbasekey/bipole/flow/direction = backward,
        \circuitikzbasekey/bipole/flow/x position = after,
        \circuitikzbasekey/bipole/flow/y position = below
    }
}

\ctikzset{f<^/.style = {
        f={#1},
        \circuitikzbasekey/bipole/flow/direction = backward,
        \circuitikzbasekey/bipole/flow/x position = before,
        \circuitikzbasekey/bipole/flow/y position = above
    }
}

\ctikzset{f<_/.style = {
        f={#1},
        \circuitikzbasekey/bipole/flow/direction = backward,
        \circuitikzbasekey/bipole/flow/x position = before,
        \circuitikzbasekey/bipole/flow/y position = below
    }
}

\ctikzset{f</.style = { f={#1}, \circuitikzbasekey/bipole/flow/direction = backward} }
\ctikzset{f_/.style = { f={#1}, \circuitikzbasekey/bipole/flow/y position = below } }
\ctikzset{f>/.style = { f={#1}, \circuitikzbasekey/bipole/flow/direction = forward } }
\ctikzset{f^/.style = { f={#1}, \circuitikzbasekey/bipole/flow/y position = above } }

\newif\ifpgfcirc@do@f@symbols\pgfcirc@do@f@symbolstrue
\ctikzset{no f symbols/.code={\pgfcirc@do@f@symbolsfalse}}
\ctikzset{f symbols/.code={\pgfcirc@do@f@symbolstrue}}

\ctikzset{f/.code = {
        \pgfcirc@has@ftrue
        \ifpgf@circuit@bipole@override@source@vif
            \pgf@circuit@bipole@isvoltagefalse
            \pgf@circuit@bipole@iscurrentfalse
        \fi
        \pgfkeys{\circuitikzbasekey/bipole/flow/direction = forward,
            \circuitikzbasekey/bipole/flow/x position = after,
        \circuitikzbasekey/bipole/flow/y position = above }
        \pgfkeys{/tikz/circuitikz/bipole/flow/label/name={#1}}
        \ctikzsetvalof{bipole/flow/label/unit}{}
        \ifpgf@circ@siunitx
            \pgf@circ@handleSI{#1}
            \ifpgf@circ@siunitx@res
                \edef\pgf@temp{\pgf@circ@handleSI@val}
                \pgfkeyslet{/tikz/circuitikz/bipole/flow/label/name}{\pgf@temp}
                \edef\pgf@temp{\pgf@circ@handleSI@unit}
                \pgfkeyslet{/tikz/circuitikz/bipole/flow/label/unit}{\pgf@temp}
            \else
        \fi
        \else
    \fi
}
}

%% Output routine

\def\pgf@circ@drawflow{
    \pgfextra{
        \edef\pgf@circ@rounded@dir{\pgf@circ@direction}
        \def\pgfcircmathresult{\expandafter\pgf@circ@stripdecimals\pgf@circ@rounded@dir\pgf@nil}

        \ifnum\pgfcircmathresult >4 \ifnum\pgfcircmathresult <86
                \ifpgf@circuit@bipole@flow@below
                        \def\pgf@circ@dir{north west} \else \def\pgf@circ@dir{south east}
                \fi
        \fi\fi
        \ifnum\pgfcircmathresult >85 \ifnum\pgfcircmathresult <95
                \ifpgf@circuit@bipole@flow@below
                        \def\pgf@circ@dir{west} \else \def\pgf@circ@dir{east}
                \fi
        \fi\fi
        \ifnum\pgfcircmathresult >94 \ifnum\pgfcircmathresult <176
                \ifpgf@circuit@bipole@flow@below
                         \def\pgf@circ@dir{south west}\else \def\pgf@circ@dir{north east}
                \fi
        \fi\fi
        \ifnum\pgfcircmathresult >175 \ifnum\pgfcircmathresult <185
                \ifpgf@circuit@bipole@flow@below
                          \def\pgf@circ@dir{south}\else\def\pgf@circ@dir{north}
                \fi
        \fi\fi
        \ifnum\pgfcircmathresult >184 \ifnum\pgfcircmathresult <266
                \ifpgf@circuit@bipole@flow@below
                         \def\pgf@circ@dir{south east}\else\def\pgf@circ@dir{north west}
                \fi
        \fi\fi
        \ifnum\pgfcircmathresult >265 \ifnum\pgfcircmathresult <275
                \ifpgf@circuit@bipole@flow@below
                         \def\pgf@circ@dir{east}\else \def\pgf@circ@dir{west}
                \fi
        \fi\fi
        \ifnum\pgfcircmathresult >274 \ifnum\pgfcircmathresult <356
                \ifpgf@circuit@bipole@flow@below
                          \def\pgf@circ@dir{north east}\else\def\pgf@circ@dir{south west}
                \fi
        \fi\fi
        \ifnum\pgfcircmathresult <5
                \ifpgf@circuit@bipole@flow@below
                         \def\pgf@circ@dir{north}\else\def\pgf@circ@dir{south}
                \fi
        \fi
        \ifnum\pgfcircmathresult >355
                \ifpgf@circuit@bipole@flow@below
                         \def\pgf@circ@dir{north}\else\def\pgf@circ@dir{south}
                \fi
        \fi

        \ifpgf@circuit@bipole@flow@below
                \def\pgf@circ@bipole@flow@label@where{-90}
        \else
                \def\pgf@circ@bipole@flow@label@where{+90}
        \fi
        % export anchor position (if not needed, is always the same macro)
        \expandafter\xdef\csname pgfcirc@\pgfcirc@a@prefix-Flab-anchor\endcsname{\pgf@circ@dir}
    }

    \pgfextra{\def\pgf@temp{short}\edef\pgf@circ@temp{\ctikzvalof{bipole/kind}}}
    \ifx\pgf@circ@temp\pgf@temp%draw current at a short at middle of the line
        coordinate (pgfcirc@Ffrom@flat) at (\tikztostart)
        coordinate (pgfcirc@Fto@flat) at (\tikztotarget)
    \else% normal bipole or source
        \ifpgf@circuit@bipole@flow@before
            coordinate (pgfcirc@Ffrom@flat) at (\tikztostart)
            coordinate (pgfcirc@Fto@flat) at (pgfcirc@anchorstartnode)
        \else
            coordinate (pgfcirc@Ffrom@flat) at (pgfcirc@anchorendnode)
            coordinate (pgfcirc@Fto@flat) at (\tikztotarget)
        \fi
    \fi
    \pgfextra{
        \newdimen{\absfshift}
        \def\flow@offset{\ctikzvalof{flow/offset}\pgf@circ@Rlen}
        \absfshift=\flow@offset
        \ifpgf@circuit@bipole@flow@backward
            \pgfmathsubtract{\pgf@circ@rounded@dir}{180}
            \edef\pgf@circ@rounded@dir{\expandafter\pgf@circ@stripdecimals\pgfmathresult\pgf@nil}
        \fi
    }
    \ifpgf@circuit@bipole@flow@below
        coordinate (pgfcirc@Ffrom@up) at ($(pgfcirc@Ffrom@flat) ! \absfshift !-90: (pgfcirc@Fto@flat)$)
        coordinate (pgfcirc@Fto@up) at ($(pgfcirc@Fto@flat) ! \absfshift !90: (pgfcirc@Ffrom@flat)$)
    \else
        coordinate (pgfcirc@Ffrom@up) at ($(pgfcirc@Ffrom@flat) ! \absfshift !90: (pgfcirc@Fto@flat)$)
        coordinate (pgfcirc@Fto@up) at ($(pgfcirc@Fto@flat) ! \absfshift !-90: (pgfcirc@Ffrom@flat)$)
    \fi
    coordinate (\pgfcirc@a@prefix-Fpos) at ($(pgfcirc@Ffrom@up) ! \ctikzvalof{flow/distance} !(pgfcirc@Fto@up)$)
    \pgfextra{
        \absfshift=0.25\pgf@circ@Rlen% This is half size of the "flowarrow" shape!
    }
    coordinate (\pgfcirc@a@prefix-Ffrom) at ($(\pgfcirc@a@prefix-Fpos)!\absfshift!(pgfcirc@Ffrom@up)$)
    coordinate (\pgfcirc@a@prefix-Fto) at ($(\pgfcirc@a@prefix-Fpos)!\absfshift!(pgfcirc@Fto@up) $)
    %
    % coordinate (\pgfcirc@a@prefix-Fpos) at
    %     ([yshift=\flow@offset]$(\pgfcirc@a@prefix-Ffrom)! \ctikzvalof{flow/distance} !(\pgfcirc@a@prefix-Fto)$)
    % export the flow direction
    \pgfextra{\expandafter\xdef\csname pgfcirc@\pgfcirc@a@prefix-Farrow-direction\endcsname{\pgf@circ@rounded@dir}}
    % if the flow label is not empty (in which case we have already all the anchors)
    \pgf@circ@ifkeyempty{bipole/flow/label/name}\else
        % the flow arrow is really a node "flowarrow", not a real arrow
        \ifpgfcirc@do@f@symbols
            node[flowarrow, rotate=\pgf@circ@rounded@dir, anchor=center](Farrowpos) at (\pgfcirc@a@prefix-Fpos) {}
        \else
            node[flowarrow, rotate=\pgf@circ@rounded@dir, anchor=center,
                circuitikz/phantom@flowarrow](Farrowpos) at (\pgfcirc@a@prefix-Fpos) {}
        \fi
        node[anchor=\pgf@circ@dir, \circuitikzbasekey/bipole flow style]
        (\ctikzvalof{bipole/name}flow) at (Farrowpos.\pgf@circ@bipole@flow@label@where) {\pgf@circ@finallabels{flow/label}}
    \fi
    % adjust from and to before exporting --- it's much more simple like this then rework the algorithm above
    \ifpgf@circuit@bipole@flow@backward
        \pgfcirc@swap@coordinates{\pgfcirc@a@prefix-Ffrom}{\pgfcirc@a@prefix-Fto}
    \fi

}

%%%---------- close: tex/pgfcircflow

% defaults

\setupmodule
   [current=european,
    voltage=european,
    resistor=american,
    inductor=cute,
    logic=american,
    siunitx=true,
    arrowmos=false]

\processaction
   [\currentmoduleparameter{voltage}]
   [european=>\ctikzset{voltage=european},
    american=>\ctikzset{voltage=american}]

\processaction
   [\currentmoduleparameter{current}]
   [european=>\ctikzset{ current=european},
    american=>\ctikzset{ current=american}]

\processaction
   [\currentmoduleparameter{label}]
   [straight=>\ctikzset{label/align = straight},
    align=>\ctikzset{label/align = rotate},
    smart=>\ctikzset{label/align = smart}]

\processaction
   [\currentmoduleparameter{resistor}]
   [european=>\ctikzset{ resistor=european},
    american=>\ctikzset{ resistor=american}]

\processaction
   [\currentmoduleparameter{inductor}]
   [european=>\ctikzset{ inductor=european},
    american=>\ctikzset{ inductor=american},
    cute=>\ctikzset{ inductor=cute}]

\processaction
   [\currentmoduleparameter{diode}]
   [full=>\ctikzset{ diode=full},
    empty=>\ctikzset{ diode=empty}]

\processaction
   [\currentmoduleparameter{logic}]
   [european=>\ctikzset{ logic ports=european},
    american=>\ctikzset{ logic ports=american}]

% This tiny siunitx emulation layer (REALLY tiny) is practically never
% enabled because recent ConTeXt releases override this file with
% m-circuitikz.tex and in that file it has been removed.

\processaction
   [\currentmoduleparameter{siunitx}]
   [true=>\def\SI#1#2{#1\,#2}
    \def\ampere{\rm{A}}
    \def\volt{\rm{V}}
    \def\ohm{\Omega}
    \def\siemens{\rm{S}}
    \def\farad{\rm{F}}
    \def\henry{\rm{H}}
    \def\second{\rm{s}}
    \def\coulomb{\rm{C}}
    \def\siemens{\rm{S}}
    \def\radians{\rm{rad}}
    \def\milli{\rm{m}}
    \def\micro{\mu}
    \def\nano{\rm{n}}
    \def\pico{\rm{p}}
    \def\kilo{\rm{k}}
    \def\mega{\rm{M}}
    \def\giga{\rm{G}}
    \def\tera{\rm{T}},
    false=>]
%   \s!default=>\pgf@circ@siunitxtrue,

\processaction
   [\currentmoduleparameter{arrowmos}]
   [true=>\pgf@circuit@mos@arrowstrue,
    false=>\pgf@circuit@mos@arrowsfalse]
%   \s!default=>\pgf@circuit@mos@arrowstrue,


\ifpgf@circ@siunitx
 % nothing! siunitx and xstrings don't work in context
\fi


% Context specific

\ctikzset{tripoles/op amp/font/.initial=\switchtobodyfont[small]}


\catcode`\@=\tikzatcode
\catcode`\|=\tikzbarcode
\catcode`\!=\tikzexclaimcode

% define the environment
% thanks to Max Chernoff https://tex.stackexchange.com/a/705683/38080
\let\startcircuitikz\starttikzpicture
\let\stopcircuitikz\stoptikzpicture

\protect

\stopmodule

\endinput
