%  bloques.sty
%       package based on tikz for control diagrams in power electronics.
%       version 1.0
% 	    author:  Alejandro Garces
%		            alejandrogarces@gmail.com
% License: LPPL
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.



\usepackage{tikz}
\usepgflibrary{shapes.misc}
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,shadows}

\newcommand{\xdistancia}{1.5cm}
\newcommand{\ydistancia}{1.2cm}
\newcommand{\minaltura}{0.7cm}
\newcommand{\tamano}{\footnotesize}
\newcommand{\colorfondo}{white}
\newcommand{\colortexto}{black}
\newcommand{\colorlinea}{black}
\newcommand{\sombra}{0}
\newcommand{\ancholinea}{thick}

\newcommand{\bShadow}{\renewcommand{\sombra}{1}}
\newcommand{\bColorB}[1]{\renewcommand{\colorfondo}{#1}}
\newcommand{\bColorT}[1]{\renewcommand{\colortexto}{#1}}
\newcommand{\bColorL}[1]{\renewcommand{\colorlinea}{#1}}
\newcommand{\ydistance}[1]{\renewcommand{\ydistancia}{#1}}



\newcommand{\bStart}[1]{\node [] (NODO1) {\tamano{#1}};}

\newcommand{\bPlusDown}[1]{
	\node [draw=\colorlinea, circle,minimum size=1.5em, right of=NODO1, node distance= \xdistancia,\ancholinea, fill=\colorfondo,
	       drop shadow={opacity=\sombra}] (SUMA) {};
  \node [draw=gray!50, cross out, minimum size=1.0em, right of=NODO1, node distance= \xdistancia, thin] {};	
  \node [left of = SUMA, node distance = 0.45em] () { \color{\colortexto}\tiny{$+$}};
  \node [below of = SUMA, node distance = 0.45em] () { \color{\colortexto}\tiny{$+$}};
	\draw [-latex,\colorlinea] (NODO1) -- (SUMA);	
	\node [below of = SUMA, node distance =  \ydistancia] (VARIABLE) {\tamano{#1}};
	\draw [-latex, \colorlinea] (VARIABLE) -- (SUMA);			
	\node  at (SUMA) [anchor = west] (NODO1) {};	
}


\newcommand{\bPlusUp}[1]{
	\node [draw=\colorlinea, circle,minimum size=1.5em, right of=NODO1, node distance= \xdistancia,\ancholinea, fill=\colorfondo,
	       drop shadow={opacity=\sombra}] (SUMA) {};
  \node [draw=gray!50, cross out, minimum size=1.0em, right of=NODO1, node distance= \xdistancia, thin, draw=gray!50] {};	
  \node [left of = SUMA, node distance = 0.45em] () { \color{\colortexto}\tiny{$+$}};
  \node [above of = SUMA, node distance = 0.45em] () { \color{\colortexto}\tiny{$+$}};
	\draw [-latex, \colorlinea] (NODO1) -- (SUMA);	
	\node [above of = SUMA, node distance =  \ydistancia] (VARIABLE) {\tamano{#1}};
	\draw [-latex, \colorlinea] (VARIABLE) -- (SUMA);			
	\node  at (SUMA) [anchor = west] (NODO1) {};	
}


\newcommand{\bMinusDown}[1]{
	\node [draw=\colorlinea, circle,minimum size=1.5em, right of=NODO1, node distance= \xdistancia,\ancholinea, fill=\colorfondo,
	       drop shadow={opacity=\sombra}] (SUMA) {};
  \node [cross out, minimum size=1.0em, right of=NODO1, node distance= \xdistancia,  thin, draw=gray!50] {};	
  \node [left of = SUMA, node distance = 0.45em] () { \color{\colortexto}\tiny{$+$}};
  \node [below of = SUMA, node distance = 0.45em] () { \color{\colortexto}\tiny{$-$}};
	\draw [-latex,\colorlinea] (NODO1) -- (SUMA);	
	\node [below of = SUMA, node distance =  \ydistancia] (VARIABLE) {\tamano{#1}};
	\draw [-latex,\colorlinea] (VARIABLE) -- (SUMA);			
	\node  at (SUMA) [anchor = west] (NODO1) {};
	
}


\newcommand{\bMinusUp}[1]{
	\node [draw=\colorlinea, circle,minimum size=1.5em, right of=NODO1, node distance= \xdistancia,\ancholinea, fill=\colorfondo,
	       drop shadow={opacity=\sombra}] (SUMA) {};
  \node [thin, cross out, minimum size=1.0em, right of=NODO1, node distance= \xdistancia, draw=gray!50] {};	
  \node [left of = SUMA, node distance = 0.45em] () { \color{\colortexto}\tiny{$+$}};
  \node [above of = SUMA, node distance = 0.45em] () { \color{\colortexto}\tiny{$-$}};
	\draw [-latex, \colorlinea] (NODO1) -- (SUMA);	
	\node [above of = SUMA, node distance =  \ydistancia] (VARIABLE) {\tamano{#1}};
	\draw [-latex, \colorlinea] (VARIABLE) -- (SUMA);			
	\node  at (SUMA) [anchor = west] (NODO1) {};
}

\newcommand{\bEnd}[1]{
	\node [right of = NODO1, node distance = 1.7cm] (F) {#1};
	\draw [-latex,\colorlinea] (NODO1) -- (F);
	\node  at (F) [anchor = west] (NODO1) {};
}


\newcommand{\bGain}[1]{		
	\node [draw=\colorlinea, rectangle, right of = NODO1, node distance= \xdistancia, minimum height = \minaltura, 
	       \ancholinea, fill=\colorfondo,drop shadow={opacity=\sombra}] (NODO2) { \color{\colortexto}\tamano{#1}};	
	\draw [-latex, \colorlinea] (NODO1)--(NODO2);
	\node  at (NODO2.east) [anchor = east] (NODO1) {};
	
}


\newcommand{\bGainPlus}[2]{

	\node [draw=\colorlinea, circle,minimum size=1.5em, right of=NODO1, node distance= \xdistancia,\ancholinea, fill=\colorfondo,
	       drop shadow={opacity=\sombra}] (SUMA) {};
  \node [thin, cross out, minimum size=1.0em, right of=NODO1, node distance= \xdistancia, draw=gray!50] {};	
  \node [left of = SUMA, node distance = 0.45em] () { \color{\colortexto}\tiny{$+$}};
  \node [below of = SUMA, node distance = 0.45em] () { \color{\colortexto}\tiny{$+$}};
	\draw [-latex, \colorlinea] (NODO1) -- (SUMA);	
						
  \node [draw=\colorlinea, rectangle, below of = SUMA, node distance =  \xdistancia,xshift=-0.3cm, minimum height = \minaltura,\ancholinea, 
         fill=\colorfondo,drop shadow={opacity=\sombra}, anchor = east] (NODOG) {\color{\colortexto}\tamano{#2}};
  \node [left of = NODOG, node distance =  \xdistancia] (VARIABLE) {\tamano{#1}};  	
	\draw [-latex, \colorlinea] (VARIABLE) -- (NODOG);
	\draw [-latex, \colorlinea] (NODOG) -| (SUMA);			
	\node  at (SUMA) [anchor = west] (NODO1) {};
}

\newcommand{\bGainMinus}[2]{

	\node [draw=\colorlinea, circle,minimum size=1.5em, right of=NODO1, node distance= \xdistancia,\ancholinea, fill=\colorfondo,
	       drop shadow={opacity=\sombra}] (SUMA) {};
  \node [thin, cross out, minimum size=1.0em, right of=NODO1, node distance= \xdistancia, draw=gray!50] {};	
  \node [left of = SUMA, node distance = 0.45em] () { \color{\colortexto}\tiny{$+$}};
  \node [below of = SUMA, node distance = 0.45em] () { \color{\colortexto}\tiny{$-$}};
	\draw [-latex, \colorlinea] (NODO1) -- (SUMA);	
						
  \node [draw=\colorlinea, rectangle, below of = SUMA, node distance =  \xdistancia,xshift=-0.3cm, minimum height = \minaltura,\ancholinea, 
         fill=\colorfondo,drop shadow={opacity=\sombra}, anchor = east] (NODOG) {\color{\colortexto}\tamano{#2}};
  \node [left of = NODOG, node distance =  \xdistancia] (VARIABLE) {\tamano{#1}};  	
	\draw [-latex, \colorlinea] (VARIABLE) -- (NODOG);
	\draw [-latex, \colorlinea] (NODOG) -| (SUMA);			
	\node  at (SUMA) [anchor = west] (NODO1) {};
}


\newcommand{\bMinusF}[1]{
	\node [draw=\colorlinea, circle,minimum size=1.5em, right of=NODO1, node distance= \xdistancia,\ancholinea, fill=\colorfondo,
	       drop shadow={opacity=\sombra}] (#1) {};
  \node [draw, cross out, minimum size=1.0em, right of=NODO1, node distance= \xdistancia, thin, draw=gray!50] {};	
  \node [left of = #1, node distance = 0.45em] () { \color{\colortexto}\tiny{$+$}};
  \node [below of = #1, node distance = 0.45em] () { \color{\colortexto}\tiny{$-$}};
	\draw [-latex, \colorlinea] (NODO1) -- (#1);			
	\node  at (#1) [anchor = west] (NODO1) {};	
	
}


\newcommand{\bPlusF}[1]{
	\node [draw=\colorlinea, circle,minimum size=1.5em, right of=NODO1, node distance= \xdistancia,\ancholinea, fill=\colorfondo,
	       drop shadow={opacity=\sombra}] (#1) {};
  \node [thin, cross out, minimum size=1.0em, right of=NODO1, node distance= \xdistancia, draw=gray!50] {};	
  \node [left of = #1, node distance = 0.45em] () { \color{\colortexto}\tiny{$+$}};
  \node [below of = #1, node distance = 0.45em] () { \color{\colortexto}\tiny{$+$}};
	\draw [-latex, \colorlinea] (NODO1) -- (#1);			
	\node  at (#1) [anchor = west] (NODO1) {};	
	
}


\newcommand{\bFeedBack}[2]{		
	\node [draw=\colorlinea, rectangle, below left of = NODO1, node distance =  \ydistancia, minimum height = \minaltura,\ancholinea, 
         fill=\colorfondo,drop shadow={opacity=\sombra}, anchor = west] (NODOG) {\color{\colortexto}\tamano{#1}};	
  \draw [-latex, \colorlinea] (NODO1) -- +(0.5,0) |- (NODOG);
	\draw [-latex, \colorlinea] (NODOG) -| (#2);     	
}


\newcommand{\bCrossGain}[3]{		
	\node [draw=\colorlinea, rectangle, above right of = #2, minimum height = \minaltura,\ancholinea, 
         fill=\colorfondo,drop shadow={opacity=\sombra}, anchor = west] (NODOG) {\color{\colortexto}\tamano{#1}};	
  \draw [-latex, \colorlinea] (#2) |- (NODOG);
	\draw [-latex, \colorlinea] (NODOG) -| (#3);     	
}


\newcommand{\bNewStart}[2]{
	\node at #2 (NODO1) {\tamano{#1}};
}


\newcommand{\bMarkNode}[1]{
	\node at (NODO1) (#1) {};
}


\newcommand{\bMarkNodeUp}[1]{
	\node[above of = NODO1, node distance =  \ydistancia] (#1) {};
}


\newcommand{\bMarkNodeDown}[1]{
	\node[below of = NODO1,node distance =  \ydistancia] (#1) {};
}

