%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% bar primitives
\newcommand{\barRect}[6][fillstyle=solid]
{
  {\psframe[linestyle=none,fillcolor=#6,#1](#2,#3)(#4,#5)}
}
% - - - - - -
\newcommand{\xtd}{0}
\newcommand{\ytd}{0}
\newcommand{\xtda}{0}
\newcommand{\ytda}{0}
\newcommand{\xtdb}{0}
\newcommand{\ytdb}{0}

\newcommand{\barTDRect}[6][fillstyle=solid]
{
%
 \psframe[linestyle=solid,fillcolor=#6,#1](#2,#3)(#4,#5)

 % let's draw polygons: left and upper
 % left-> (#4;#3)(#4+\bdar\tdhor;#3+\dbar\tdver)
 %        (#4+\dbar\tdhor;#5+\dbar\tdver)(#4;#5)
 % right->(#4;#5)(#4+\dbar\tdhor;#5+\dbar\tdver)
 %        (#3+\dbar\tdhor;#5+\dbar\tdver)(#2;#3)
 %

 \FPmul{\xtd}{\dbar}{\tdhor}
 \FPmul{\ytd}{\dbar}{\tdver}

 \FPfadd{\xtda}{#2}{\xtd}
 \FPfadd{\xtdb}{#4}{\xtd}
 \FPfadd{\ytda}{#3}{\ytd}
 \FPfadd{\ytdb}{#5}{\ytd}

 \pspolygon[linestyle=solid,fillcolor=#6,#1](#4,#3)(\xtdb,\ytda)(\xtdb,\ytdb)(#4,#5)(#4,#3)
 \pspolygon[linestyle=solid,fillcolor=#6,#1](#4,#5)(\xtdb,\ytdb)(\xtda,\ytdb)(#2,#5)(#4,#5)
}

\newcommand{\elRx}{0}
\newcommand{\elRy}{0}
\newcommand{\barCylinder}[6][none]
{
 \FPmul{\xtd}{\dbar}{\tdx}
 \FPmul{\ytd}{\dbar}{\tdy}

 \FPdiv{\elRx}{\dbar}{2}
 \FPdiv{\elRy}{\ytd}{2}

 \ifthenelse{\bdorientation = \bdvert}
 {
   \FPfadd{\tmpvar}{#2}{#4}
   \FPdiv{\xtda}{\tmpvar}{2} % Xcenter of the bottom ellipse
   \FPdiv{\tmpvar}{\ytd}{2}
   \FPfadd{\ytda}{\tmpvar}{#3} % Ycenter of the bottom ellipse
   % Draw the bottom ellipse
   \psellipse[fillstyle=solid,fillcolor=#6](\xtda,\ytda)(\elRx,\elRy)
   \FPdiv{\tmpvar}{\ytd}{2}
   \FPfadd{\ytdb}{\tmpvar}{#5} % Ycenter of the top ellipse
   % Draw the rectangle
   \psframe[fillstyle=solid,fillcolor=#6,linecolor=#6](#2,\ytda)(#4,\ytdb)
   \psline(#2,\ytda)(#2,\ytdb)
   \psline(#4,\ytda)(#4,\ytdb)
   % Draw the top ellipse
   \psellipse[fillstyle=solid,fillcolor=#6](\xtda,\ytdb)(\elRx,\elRy)
 }
 { \FPfadd{\tmpvar}{#3}{#5}
   \FPdiv{\ytda}{\tmpvar}{2}
   \FPdiv{\tmpvar}{\ytd}{2}
   \FPfadd{\xtda}{\tmpvar}{#2}
   % Draw the left ellipse
   \psellipse[fillstyle=solid,fillcolor=#6](\xtda,\ytda,)(\elRy,\elRx)
   \FPdiv{\tmpvar}{\ytd}{2}
   \FPfadd{\ytdb}{\tmpvar}{#4}
   % Draw the rectangle
   \psframe[fillstyle=solid,fillcolor=#6,linecolor=#6](\xtda,#3)(\ytdb,#5)
   \psline(\xtda,#3)(\ytdb,#3)
   \psline(\xtda,#5)(\ytdb,#5)
   % Draw the right ellipse
   \psellipse[fillstyle=solid,fillcolor=#6](\ytdb,\ytda)(\elRy,\elRx)
 }
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%