% Copyright 2007-2009 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 file doc/LICENSE for more details.

%% Generic macro for defining a bipole shape
% #1 - lower y-size of the bipole (from the center). If empty, same ad #3
% #2 - #shape is the name of the shape
% #3 - upper y-size of the bipole (from the center)
% #4 - macros drawing the bipole


\newcommand{\pgfcircdeclarebipole}[5][]{
	\pgfdeclareshape{#2shape}{
	
	\savedanchor{\northeast}{
		\pgf@y=#3\pgf@circ@Rlen
		\pgf@y=.5\pgf@y
		\pgf@x=#4\pgf@circ@Rlen
		\pgf@x=.5\pgf@x
	}
	\savedanchor{\northeastborder}{
		\pgf@y=#3\pgf@circ@Rlen
		\pgf@y=.5\pgf@y
		\pgf@y=\ctikzvalof{bipoles/border margin}\pgf@y
		\pgf@x=#4\pgf@circ@Rlen
		\pgf@x=.5\pgf@x
		\pgf@x=\ctikzvalof{bipoles/border margin}\pgf@x
	}
	\savedanchor{\southwestborder}{
		\pgf@y=-#1\pgf@circ@Rlen
		\pgf@y=.5\pgf@y
		\pgf@y=\ctikzvalof{bipoles/border margin}\pgf@y
		\pgf@x=-#4\pgf@circ@Rlen
		\pgf@x=.5\pgf@x
		\pgf@x=\ctikzvalof{bipoles/border margin}\pgf@x
	}
	\savedanchor{\southwest}{
		\pgf@y=-#1\pgf@circ@Rlen
		\pgf@y=.5\pgf@y
		\pgf@x=-#4\pgf@circ@Rlen
		\pgf@x=.5\pgf@x
	}
	\savedanchor{\centerpoint}{
		\pgf@circ@res@down=-#1\pgf@circ@Rlen
		\pgf@circ@res@up=#3\pgf@circ@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}{
		\ifpgf@circuit@bipole@reversed\southwest\else\northeast\fi
		\pgf@x=0cm
	}
	\anchor{ne}{
		\ifpgf@circuit@bipole@reversed\southwest\else\northeast\fi
	}
	\anchor{nw}{
		\ifpgf@circuit@bipole@reversed\southwest\else\northeast\fi
		\pgf@x=-\pgf@x
	}
	\anchor{e}{%
		\ifpgf@circuit@bipole@reversed\else\southwest\northeast\fi
		\pgf@y=0cm
   }
	\anchor{s}{%
		\ifpgf@circuit@bipole@reversed\northeast\else\southwest\fi
		\pgf@x=0cm
   }
	\anchor{se}{%
		\ifpgf@circuit@bipole@reversed\northeast\else\southwest\fi
		\pgf@x=-\pgf@x
   }
	\anchor{sw}{%
		\ifpgf@circuit@bipole@reversed\northeast\else\southwest\fi
   }
	\anchor{w}{
		\ifpgf@circuit@bipole@reversed\northeast\else\southwest\fi
		\pgf@y=0cm
	}
	\anchor{north}{
		\ifpgf@circuit@bipole@reversed\southwest\else\northeast\fi
		\pgf@x=0cm
	}
	\anchor{east}{%
		\ifpgf@circuit@bipole@reversed\southwest\else\northeast\fi
		\pgf@y=0cm
   }
	\anchor{south}{%
		\ifpgf@circuit@bipole@reversed\northeast\else\southwest\fi
		\pgf@x=0cm
   }
	\anchor{west}{
		\ifpgf@circuit@bipole@reversed\northeast\else\southwest\fi
		\pgf@y=0cm
	}
	\anchor{right}{
		\ifpgf@circuit@bipole@reversed\southwest\else\northeast\fi
		\pgf@y=0cm
	}
	\anchor{above}{
		\ifpgf@circuit@bipole@reversed\southwest\else\northeast\fi
		\pgf@x=0cm
	}
	\anchor{left}{%
		\ifpgf@circuit@bipole@reversed\northeast\else\southwest\fi
		\pgf@y=0cm
   }
	\anchor{below}{%
		\ifpgf@circuit@bipole@reversed\northeast\else\southwest\fi
		\pgf@x=0cm                    
   }
	\anchor{a}{%
		\ifpgf@circuit@bipole@reversed\southwest\else\northeast\fi
		\pgf@y=0cm
   }
	\anchor{b} {
		\ifpgf@circuit@bipole@reversed\northeast\else\southwest\fi
		\pgf@y=0cm
	}
	\savedanchor{\textanchor}{%
		\pgf@y=\ht\pgfnodeparttextbox
		\pgf@x=-.5\wd\pgfnodeparttextbox
   }
	\anchor{text}{%
		\textanchor
   }
	\anchorborder{%
		\def\pgf@temp{false}
		\ifpgf@circuit@bipole@reversed\pgf@temp
			\pgf@circ@res@left=-\pgf@x
			\pgf@circ@res@right=-\pgf@y
		\else
			\pgf@circ@res@left=\pgf@x
			\pgf@circ@res@right=\pgf@y
		\fi
		\ifdim\pgf@circ@res@right>0cm
			\pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@right}}{\northeastborder}
		\else
	  		\southwestborder	
	  	\pgfpointborderrectangle{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@right}}{\pgfpoint{-\pgf@x}{-\pgf@y}}
		\fi
	}
	\backgroundpath{	
		\pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/color}}	
		
		\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

 		\pgfstartlinewidth=\pgflinewidth
		
		#5
			
		\pgfsetlinewidth{\pgfstartlinewidth}
	}
	}
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Standard bipole shapes declarations

%% Resistor
\pgfcircdeclarebipole[\ctikzvalof{bipoles/resistor/height}]{resistor}{\ctikzvalof{bipoles/resistor/height}}{\ctikzvalof{bipoles/resistor/width}}{
		\pgf@circ@res@step = \ctikzvalof{bipoles/resistor/width}\pgf@circ@Rlen
		\divide \pgf@circ@res@step by 12

		\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 

		\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
		\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}}
		\pgfusepath{draw} 
}


%% Potentiometer

\pgfcircdeclarebipole[\ctikzvalof{bipoles/potentiometer/height}]{potentiometer}{\ctikzvalof{bipoles/potentiometer/height}}{\ctikzvalof{bipoles/potentiometer/width}}{
		\pgf@circ@res@step = \ctikzvalof{bipoles/potentiometer/width}\pgf@circ@Rlen
		\divide \pgf@circ@res@step by 12
		\def\myfrac{.5}

		\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

		\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 
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\myfrac\pgf@circ@res@up}}
		\advance\pgf@circ@res@other by 2\pgf@circ@res@step 
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\myfrac\pgf@circ@res@down}}
		\advance\pgf@circ@res@other by 2\pgf@circ@res@step
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\myfrac\pgf@circ@res@up}}
		\advance\pgf@circ@res@other by 2\pgf@circ@res@step
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\myfrac\pgf@circ@res@down}}
		\advance\pgf@circ@res@other by 2\pgf@circ@res@step
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\myfrac\pgf@circ@res@up}}
		\advance\pgf@circ@res@other by 2\pgf@circ@res@step
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{\myfrac\pgf@circ@res@down}}
		\advance\pgf@circ@res@other by \pgf@circ@res@step
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
		\pgfusepath{draw}
		
		\pgfscope
		\pgfsetarrowsend{to}
		\pgfpathmoveto{\pgfpoint{.4\pgf@circ@res@other}{\pgf@circ@res@up}}
		\pgfpathlineto{\pgfpoint{-.4\pgf@circ@res@other}{\pgf@circ@res@down}}
		\pgfusepath{draw}
		\endpgfscope
}



%% Capacitor

\pgfcircdeclarebipole[\ctikzvalof{bipoles/capacitor/height}]{capacitor}{\ctikzvalof{bipoles/capacitor/height}}{\ctikzvalof{bipoles/capacitor/width}}{
		\pgf@circ@res@step = \ctikzvalof{bipoles/capacitor/width}\pgf@circ@Rlen
		\divide \pgf@circ@res@step by 5

		\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\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}
}

%% Battery

\pgfcircdeclarebipole[\ctikzvalof{bipoles/battery/height}]{battery}{\ctikzvalof{bipoles/battery/height}}{\ctikzvalof{bipoles/battery/width}}{
		\pgf@circ@res@step = \ctikzvalof{bipoles/battery/width}\pgf@circ@Rlen
		\divide \pgf@circ@res@step by 6

		\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\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}{\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}}

		\pgfusepath{draw}
}



%% Inductor

\pgfcircdeclarebipole[\ctikzvalof{bipoles/inductor/height}]{inductor}{\ctikzvalof{bipoles/inductor/height}}{\ctikzvalof{bipoles/inductor/width}}{
	\pgf@circ@res@step=\ctikzvalof{bipoles/inductor/width}\pgf@circ@Rlen
	\divide \pgf@circ@res@step by \ctikzvalof{bipoles/inductor/coils}

	\pgfdecorationsegmentamplitude=\ctikzvalof{bipoles/inductor/height}\pgf@circ@Rlen
	\pgfdecorationsegmentamplitude=.5\pgfdecorationsegmentamplitude
	\pgfdecorationsegmentlength = \pgf@circ@res@step
	\pgfdecorationsegmentaspect=.6
	
	\begin{pgfdecoration}{{coil}{\pgfdecoratedremainingdistance}}
		\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
	\end{pgfdecoration}
		\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\pgfusepath{stroke}	
}




%% Independent voltage source

\pgfcircdeclarebipole[\ctikzvalof{bipoles/vsource/height}]{vsource}{\ctikzvalof{bipoles/vsource/height}}{\ctikzvalof{bipoles/vsource/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

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


%% Independent voltage source - American style

\pgfcircdeclarebipole[\ctikzvalof{bipoles/vsourceam/height}]{vsourceAM}{\ctikzvalof{bipoles/vsourceam/height}}{\ctikzvalof{bipoles/vsourceam/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

	\pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}

	
	\pgftext[bottom,rotate=90,y=\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@down]{$+$}
	\pgftext[top,rotate=90,y=\ctikzvalof{bipoles/vsourceam/margin}\pgf@circ@res@up]{$-$}

	\pgfusepath{draw}
}



%% Independent sinusoidal voltage source

\pgfcircdeclarebipole[\ctikzvalof{bipoles/vsourcesin/height}]{vsourcesin}{\ctikzvalof{bipoles/vsourcesin/height}}{\ctikzvalof{bipoles/vsourcesin/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
	\pgfusepath{draw}		
		
		\pgf@circ@res@up = .5\pgf@circ@res@up
		\pgfscope
			\pgftransformrotate{90}
			\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
}


%% Independent current source

\pgfcircdeclarebipole[\ctikzvalof{bipoles/isource/height}]{isource}{\ctikzvalof{bipoles/isource/height}}{\ctikzvalof{bipoles/isource/width}}{
	\pgfpointorigin
	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
	\pgfpathmoveto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@up}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{\pgf@circ@res@down}}
	\pgfusepath{draw}
}




%% Independent current source - American

\pgfcircdeclarebipole[\ctikzvalof{bipoles/isourceam/height}]{isourceAM}{\ctikzvalof{bipoles/isourceam/height}}{\ctikzvalof{bipoles/isourceam/width}}{
	\pgfpointorigin
	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
	\pgfusepath{draw}

	\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

\pgfcircdeclarebipole[\ctikzvalof{bipoles/isource/height}]{isourcesin}{\ctikzvalof{bipoles/isource/height}}{\ctikzvalof{bipoles/isource/width}}{
	\pgfpointorigin
	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
	\pgfusepath{draw}
	
		\pgf@circ@res@up = .5\pgf@circ@res@up
		\pgfscope
			\pgftransformrotate{90}
			\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 voltage source

\pgfcircdeclarebipole[\ctikzvalof{bipoles/cvsource/height}]{cvsource}{\ctikzvalof{bipoles/cvsource/height}}{\ctikzvalof{bipoles/cvsource/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\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}}
			\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
			\pgfusepath{draw}		
}




%% Controlled voltage source - American

\pgfcircdeclarebipole[\ctikzvalof{bipoles/cvsourceam/height}]{cvsourceAM}{\ctikzvalof{bipoles/cvsourceam/height}}{\ctikzvalof{bipoles/cvsourceam/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\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}}
			\pgftext[bottom,rotate=90,y=\ctikzvalof{bipoles/cvsourceam/margin}\pgf@circ@res@left]{$+$}
			\pgftext[top,rotate=90,y=\ctikzvalof{bipoles/cvsourceam/margin}\pgf@circ@res@right]{$-$}
			\pgfusepath{draw}		
}


%% Controlled sinusoidal voltage source

\pgfcircdeclarebipole[\ctikzvalof{bipoles/cvsourcesin/height}]{cvsourcesin}{\ctikzvalof{bipoles/cvsourcesin/height}}{\ctikzvalof{bipoles/cvsourcesin/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\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}}
			\pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
			\pgfusepath{draw}		
		\endpgfscope	

		\pgf@circ@res@up = .5\pgf@circ@res@up
		\pgfscope
			\pgftransformrotate{90}
			\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

\pgfcircdeclarebipole[\ctikzvalof{bipoles/cvsourcesin/height}]{cisourcesin}{\ctikzvalof{bipoles/cvsourcesin/height}}{\ctikzvalof{bipoles/cvsourcesin/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\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}}
			\pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@zero}}
			\pgfusepath{draw}		
		\endpgfscope	

		\pgf@circ@res@up = .5\pgf@circ@res@up
		\pgfscope
			\pgftransformrotate{90}
			\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

\pgfcircdeclarebipole[\ctikzvalof{bipoles/cisource/height}]{cisource}{\ctikzvalof{bipoles/cisource/height}}{\ctikzvalof{bipoles/cisource/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\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}}
			\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

\pgfcircdeclarebipole[\ctikzvalof{bipoles/cisourceam/height}]{cisourceAM}{\ctikzvalof{bipoles/cisourceam/height}}{\ctikzvalof{bipoles/cisourceam/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\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}}
			\pgfusepath{draw}		

	\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{draw}}
	\endpgfscope
}

%% Black generic diode

\pgfcircdeclarebipole[\ctikzvalof{bipoles/diode/height}]{fulldiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

	\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}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
		\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}
}

%% Black Zener diode

\pgfcircdeclarebipole[\ctikzvalof{bipoles/diode/height}]{fullzdiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

	\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}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
		\pgfusepath{draw,fill}
		\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@down}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-1.2\pgf@circ@res@left}{\pgf@circ@res@up}}
		\pgfusepath{draw}
	\endpgfscope
}

%% Black Schottky diode

\pgfcircdeclarebipole[\ctikzvalof{bipoles/diode/height}]{fullsdiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{
		
	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\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}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
		\pgfusepath{draw,fill}
		
		\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{.8\pgf@circ@res@down}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-.8\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.2\pgf@circ@res@left}{\pgf@circ@res@up}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-1.2\pgf@circ@res@left}{.8\pgf@circ@res@up}}
		\pgfusepath{draw}
	\endpgfscope

}

%% Black tunnel diode

\pgfcircdeclarebipole[\ctikzvalof{bipoles/diode/height}]{fulltdiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{
		
	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\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}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
		\pgfusepath{draw,fill}

		\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\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-.8\pgf@circ@res@left}{\pgf@circ@res@up}}
		\pgfusepath{draw}
	\endpgfscope
}

%% Black light emitting diode

\pgfcircdeclarebipole[\ctikzvalof{bipoles/diode/height}]{fulllediode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{
		
	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\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}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
		\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}

			\pgfscope
			\pgfsetarrowsend{to}
			\pgfpathmoveto{\pgfpoint{.1\pgf@circ@res@up}{.7\pgf@circ@res@up}}
			\pgfpathlineto{\pgfpoint{.4\pgf@circ@res@up}{\pgf@circ@res@up}}
			\pgfusepath{draw}
			\pgfpathmoveto{\pgfpoint{.4\pgf@circ@res@up}{.5\pgf@circ@res@up}}
			\pgfpathlineto{\pgfpoint{.7\pgf@circ@res@up}{.8\pgf@circ@res@up}}
			\pgfusepath{draw}
			\endpgfscope

}

%% Black photodiode

\pgfcircdeclarebipole[\ctikzvalof{bipoles/diode/height}]{fullpdiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\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}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
		\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}

			\pgfscope
			\pgfsetarrowsend{to}
			\pgfpathmoveto{\pgfpoint{.4\pgf@circ@res@up}{\pgf@circ@res@up}}
			\pgfpathlineto{\pgfpoint{.1\pgf@circ@res@up}{.7\pgf@circ@res@up}}
			\pgfusepath{draw}
			\pgfpathmoveto{\pgfpoint{.7\pgf@circ@res@up}{.8\pgf@circ@res@up}}
			\pgfpathlineto{\pgfpoint{.4\pgf@circ@res@up}{.5\pgf@circ@res@up}}
			\pgfusepath{draw}
			\endpgfscope
}

%% Black varcap

\pgfcircdeclarebipole[\ctikzvalof{bipoles/varcap/height}]{fullvarcap}{\ctikzvalof{bipoles/varcap/height}}{\ctikzvalof{bipoles/varcap/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\pgfscope
		\pgftransformxshift{\pgf@circ@res@left}
		\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\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-.8\pgf@circ@res@left}{0pt}}
		\pgfusepath{draw,fill}
	
		\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{\pgf@circ@res@down}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{\pgf@circ@res@up}}
		\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}}
		\pgfusepath{draw}
		
	\endpgfscope
}

%% Empty generic diode

\pgfcircdeclarebipole[\ctikzvalof{bipoles/diode/height}]{emptydiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{


	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

	\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}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
		\pgfusepath{draw}
	\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

\pgfcircdeclarebipole[\ctikzvalof{bipoles/diode/height}]{emptyzdiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

	\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}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
		\pgfusepath{draw}
		\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@down}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{\pgf@circ@res@up}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-1.2\pgf@circ@res@left}{\pgf@circ@res@up}}
		\pgfusepath{draw}
	\endpgfscope
}

%% Empty Schottky diode

\pgfcircdeclarebipole[\ctikzvalof{bipoles/diode/height}]{emptysdiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{
		
	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\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}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
		\pgfusepath{draw}
		
		\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{.8\pgf@circ@res@down}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-.8\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.2\pgf@circ@res@left}{\pgf@circ@res@up}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-1.2\pgf@circ@res@left}{.8\pgf@circ@res@up}}
		\pgfusepath{draw}
	\endpgfscope

}

%% Empty tunnel diode

\pgfcircdeclarebipole[\ctikzvalof{bipoles/diode/height}]{emptytdiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{
		
	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\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}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
		\pgfusepath{draw}

		\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\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-.8\pgf@circ@res@left}{\pgf@circ@res@up}}
		\pgfusepath{draw}
	\endpgfscope
}

%% Empty light emitting diode

\pgfcircdeclarebipole[\ctikzvalof{bipoles/diode/height}]{emptylediode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{
		
	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\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}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
		\pgfusepath{draw}
	\endpgfscope
		\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
		\pgfusepath{draw}

			\pgfscope
			\pgfsetarrowsend{to}
			\pgfpathmoveto{\pgfpoint{.1\pgf@circ@res@up}{.7\pgf@circ@res@up}}
			\pgfpathlineto{\pgfpoint{.4\pgf@circ@res@up}{\pgf@circ@res@up}}
			\pgfusepath{draw}
			\pgfpathmoveto{\pgfpoint{.4\pgf@circ@res@up}{.5\pgf@circ@res@up}}
			\pgfpathlineto{\pgfpoint{.7\pgf@circ@res@up}{.8\pgf@circ@res@up}}
			\pgfusepath{draw}
			\endpgfscope
}

%% Empty photodiode

\pgfcircdeclarebipole[\ctikzvalof{bipoles/diode/height}]{emptypdiode}{\ctikzvalof{bipoles/diode/height}}{\ctikzvalof{bipoles/diode/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\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}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-\pgf@circ@res@left}{0pt}}
		\pgfusepath{draw}
	\endpgfscope
		\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
		\pgfusepath{draw}

			\pgfscope
			\pgfsetarrowsend{to}
			\pgfpathmoveto{\pgfpoint{.4\pgf@circ@res@up}{\pgf@circ@res@up}}
			\pgfpathlineto{\pgfpoint{.1\pgf@circ@res@up}{.7\pgf@circ@res@up}}
			\pgfusepath{draw}
			\pgfpathmoveto{\pgfpoint{.7\pgf@circ@res@up}{.8\pgf@circ@res@up}}
			\pgfpathlineto{\pgfpoint{.4\pgf@circ@res@up}{.5\pgf@circ@res@up}}
			\pgfusepath{draw}
			\endpgfscope
}

%% Empty varcap

\pgfcircdeclarebipole[\ctikzvalof{bipoles/varcap/height}]{emptyvarcap}{\ctikzvalof{bipoles/varcap/height}}{\ctikzvalof{bipoles/varcap/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
	\pgfscope
		\pgftransformxshift{\pgf@circ@res@left}
		\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\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-.8\pgf@circ@res@left}{0pt}}
		\pgfusepath{draw}
	
		\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{\pgf@circ@res@down}}
		\pgfpathlineto{\pgfpoint{\pgf@circ@res@right-.8\pgf@circ@res@left}{\pgf@circ@res@up}}
		\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}}
		\pgfusepath{draw}
		
	\endpgfscope
}

%% Closing SPST

\pgfcircdeclarebipole[\ctikzvalof{bipoles/interr/height 2}]{cspst}{\ctikzvalof{bipoles/interr/height}}{\ctikzvalof{bipoles/interr/width}}{

			\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
		
			\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
			\pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right}{\pgf@circ@res@up}}
			\pgfpathmoveto{\pgfpoint{.9\pgf@circ@res@left}{.9\pgf@circ@res@up}}
            \pgfpatharc{65}{15}{\pgfkeysvalueof{/tikz/circuitikz/bipoles/interr/width}\pgf@circ@Rlen}
			\pgfsetarrowsend{to}
			\pgfusepath{draw}	

}

%% Opening SPST

\pgfcircdeclarebipole[\ctikzvalof{bipoles/interr/height 2}]{ospst}{\ctikzvalof{bipoles/interr/height}}{\ctikzvalof{bipoles/interr/width}}{

			\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
		
			\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
			\pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right}{\pgf@circ@res@up}}
			\pgfpathmoveto{\pgfpoint{.3\pgf@circ@res@right}{.1\pgf@circ@res@down}}
            \pgfpatharc{15}{65}{\pgfkeysvalueof{/tikz/circuitikz/bipoles/interr/width}\pgf@circ@Rlen}
			\pgfsetarrowsend{to}
			\pgfusepath{draw}	

}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Ammeter

\pgfcircdeclarebipole[\ctikzvalof{bipoles/ammeter/height}]{ammeter}{\ctikzvalof{bipoles/ammeter/height}}{\ctikzvalof{bipoles/ammeter/width}}{
	\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

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

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

		\pgfscope
			\pgfpathcircle{\pgfpointorigin}{\pgf@circ@res@up}
			\pgfusepath{draw}		
		\endpgfscope	

	\pgfsetlinewidth{\pgfstartlinewidth}

	\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{.8\pgf@circ@res@up}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{.8\pgf@circ@res@down}}
	\pgfusepath{draw}
	\pgfnode{circle}{center}{\textbf{A}}{}{}
	\pgfscope
		\pgftransformshift{\pgfpoint{-\pgf@circ@res@other}{.8\pgf@circ@res@up}}
		\pgftransformrotate{45}
		\pgfnode{currarrow}{center}{}{}{\pgfusepath{stroke}}
	\endpgfscope
	
	\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@zero}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
	\pgfusepath{draw}

	\pgfusepath{stroke}	
}

%% Voltmeter

\pgfcircdeclarebipole[\ctikzvalof{bipoles/voltmeter/height}]{voltmeter}{\ctikzvalof{bipoles/voltmeter/height}}{\ctikzvalof{bipoles/voltmeter/width}}{
	\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

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

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

		\pgfscope
			\pgfpathcircle{\pgfpointorigin}{\pgf@circ@res@up}
			\pgfusepath{draw}		
		\endpgfscope	

	\pgfsetlinewidth{\pgfstartlinewidth}

	\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{.8\pgf@circ@res@up}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@other}{.8\pgf@circ@res@down}}
	\pgfusepath{draw}
	\pgfnode{circle}{center}{\textbf{V}}{}{}
	\pgfscope
		\pgftransformshift{\pgfpoint{-\pgf@circ@res@other}{.8\pgf@circ@res@up}}
		\pgftransformrotate{45}
		\pgfnode{currarrow}{center}{}{}{\pgfusepath{stroke}}
	\endpgfscope
	
	\pgfpathmoveto{\pgfpoint{-\pgf@circ@res@other}{\pgf@circ@res@zero}}
	\pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@zero}}
	\pgfusepath{draw}

	\pgfusepath{stroke}	
}

%% Short circuit

\pgfcircdeclarebipole[0]{short}{0}{0}{ }

%% Open circuit

\pgfcircdeclarebipole[\ctikzvalof{bipoles/open/height}]{open}{\ctikzvalof{bipoles/open/height}}{\ctikzvalof{bipoles/open/width}}{

}

%% Generic bipole - used as resistor by some (bleah)

\pgfcircdeclarebipole[\ctikzvalof{bipoles/generic/height}]{generic}{\ctikzvalof{bipoles/generic/height}}{\ctikzvalof{bipoles/generic/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}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
		\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
					
		\pgfusepath{draw} 
}


%% Generic bipole, filled - used as inductor by some (bleah)

\pgfcircdeclarebipole[\ctikzvalof{bipoles/fullgeneric/height}]{fullgeneric}{\ctikzvalof{bipoles/fullgeneric/height}}{\ctikzvalof{bipoles/fullgeneric/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}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
		\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
					
		\pgfusepath{fill} 
}


%% Generic asymmetric bipole 

\pgfcircdeclarebipole[\ctikzvalof{bipoles/ageneric/height}]{ageneric}{\ctikzvalof{bipoles/ageneric/height}}{\ctikzvalof{bipoles/ageneric/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}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
		\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
					
		\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}		
}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Handling of terminals


%% Easily usable styles

\tikzset{*-/.style =  {\circuitikzbasekey/bipole/nodes/left=full, \circuitikzbasekey/bipole/nodes/right=none}}
\tikzset{*-o/.style = {\circuitikzbasekey/bipole/nodes/left=full, \circuitikzbasekey/bipole/nodes/right=empty}}
\tikzset{*-*/.style = {\circuitikzbasekey/bipole/nodes/left=full, \circuitikzbasekey/bipole/nodes/right=full}}
\tikzset{o-/.style = {\circuitikzbasekey/bipole/nodes/left=empty, \circuitikzbasekey/bipole/nodes/right=none}}
\tikzset{o-o/.style = {\circuitikzbasekey/bipole/nodes/left=empty, \circuitikzbasekey/bipole/nodes/right=empty}}
\tikzset{o-*/.style = {\circuitikzbasekey/bipole/nodes/left=empty, \circuitikzbasekey/bipole/nodes/right=full}}
\tikzset{-o/.style = {\circuitikzbasekey/bipole/nodes/left=none, \circuitikzbasekey/bipole/nodes/right=empty}}
\tikzset{-*/.style = {\circuitikzbasekey/bipole/nodes/left=none, \circuitikzbasekey/bipole/nodes/right=full}}

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


%% The output routine

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















\pgfdeclareshape{not port}
	{
	  \anchor{center}{\pgfpointorigin}
	  \savedanchor\northwest{%
		\pgf@y= \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
		\pgf@y=\pgfkeysvalueof{/tikz/circuitikz/bipoles/not port/height}\pgf@y
		\pgf@y=.5\pgf@y
		\pgf@x= \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
		\pgf@x=-\pgfkeysvalueof{/tikz/circuitikz/bipoles/not port/width}\pgf@x
		\pgf@x=.5\pgf@x
	  }
	  \anchor{south}{
		\northwest
		\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
	  }
	  
	  \backgroundpath{			
			\pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/color}}	
			
			
			\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 = \pgfkeysvalueof{/tikz/circuitikz/bipoles/not port/circle width}\pgf@circ@res@right
						
	\pgfscope
		\pgfsetlinewidth{2\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}}
		\pgfusepath{draw}
		\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}}
		\pgfusepath{draw}
	\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}
	  
	  }
	}





%% Lamp

\pgfcircdeclarebipole[\ctikzvalof{bipoles/lamp/height}]{lamp}{\ctikzvalof{bipoles/lamp/height}}{\ctikzvalof{bipoles/lamp/width}}{

	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

	\pgfpathellipse{\pgfpointorigin}{\pgfpoint{0}{\pgf@circ@res@up}}{\pgfpoint{\pgf@circ@res@left}{0}}
	\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}
}



\endinput
