% 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.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Quadripoles

\long\def\pgfcircdeclarequadpole#1#2{
	\pgfdeclareshape{#1}
	{
	  \anchor{center}{
	  	\northwest
		\pgf@x=0pt
	  }
	  \savedanchor\northwest{%
		\pgf@y= \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
		\pgf@y=\pgfkeysvalueof{/tikz/circuitikz/quadpoles/#1/height}\pgf@y
		\pgf@y=.5\pgf@y
		\pgf@x= \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
		\pgf@x=.5\pgf@x
		\pgf@x=-\pgfkeysvalueof{/tikz/circuitikz/quadpoles/#1/width}\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{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
	  }
	  \anchor{north}{
	  	\northwest
		\pgf@x=0pt
	  }
	  \anchor{base}{
	  	\northwest
		\pgf@x=0pt	  	
	  }
	  \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@Rlen=\pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
			
			#2
	  
	  }
	}
}



\def\pgf@circ@drawtransformerbasic{

\def\stretto{.4}
	\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}%
			}
			
			\edef\pgf@circ@temp{\ctikzvalof{inductor}}%
			\def\pgf@temp{european}%
			\ifx\pgf@temp\pgf@circ@temp%
				\pgfnode{fullgenericshape}{center}{}{pgf@inductor1}{\pgfusepath{stroke}}
			\else%
				\def\pgf@temp{cute}
				\ifx\pgf@temp\pgf@circ@temp%
					\pgfnode{cuteinductorshape}{center}{}{pgf@inductor1}{\pgfusepath{stroke}}
				\else%
					\pgfnode{americaninductorshape}{center}{}{pgf@inductor1}{\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}%
			}

			\edef\pgf@circ@temp{\ctikzvalof{inductor}}%
			\def\pgf@temp{european}%
			\ifx\pgf@temp\pgf@circ@temp%
				\pgfnode{fullgenericshape}{center}{}{pgf@inductor2}{\pgfusepath{stroke}}
			\else%
				\def\pgf@temp{cute} 
				\ifx\pgf@temp\pgf@circ@temp%
					\pgfnode{cuteinductorshape}{center}{}{pgf@inductor2}{\pgfusepath{stroke}}
				\else%
					\pgfnode{americaninductorshape}{center}{}{pgf@inductor2}{\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{pgf@inductor1}{b}}
	
	\pgfpathmoveto{\pgfpointanchor{pgf@inductor1}{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{pgf@inductor2}{a}}
	
	\pgfpathmoveto{\pgfpointanchor{pgf@inductor2}{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@drawtransformerbasic

}

\pgfcircdeclarequadpole{transformer core}{

	\pgf@circ@drawtransformerbasic
	
	\pgfmoveto{\pgfpoint%
					{\ctikzvalof{quadpoles/transformer core/core width}\pgf@circ@res@right}%
					{\ctikzvalof{quadpoles/transformer core/core height}\pgf@circ@res@down}%
					}
	\pgflineto{
				\pgfpoint
					{\ctikzvalof{quadpoles/transformer core/core width}\pgf@circ@res@right}%
					{\ctikzvalof{quadpoles/transformer core/core height}\pgf@circ@res@up}%
					}

	\pgfmoveto{\pgfpoint%
					{\ctikzvalof{quadpoles/transformer core/core width}\pgf@circ@res@left}%
					{\ctikzvalof{quadpoles/transformer core/core height}\pgf@circ@res@down}%
					}
	\pgflineto{
				\pgfpoint
					{\ctikzvalof{quadpoles/transformer core/core width}\pgf@circ@res@left}%
					{\ctikzvalof{quadpoles/transformer core/core height}\pgf@circ@res@up}%
					}					
	
	\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgflinewidth}
	\pgfusepath{draw}
}


\pgfcircdeclarequadpole{gyrator}{

	\def\stretto{.4}
	
	\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}
	
	\pgfsetlinewidth{2\pgflinewidth}
	\pgfpathmoveto{\pgfpoint{\stretto\pgf@circ@res@left}{.7*\stretto\pgf@circ@res@down}}
	\pgfpatharc{90}{270}{.7*\stretto\pgf@circ@res@down}
	
	\pgfpathmoveto{\pgfpoint{\stretto\pgf@circ@res@right}{.7*\stretto\pgf@circ@res@up}}
	\pgfpatharc{-90}{90}{.7*\stretto\pgf@circ@res@down}
	\pgfusepath{draw}

}
