3

I'm tryng to make new shapes with the help of makeshape package, and I'm having a lot of problems with new options.

Here, an example:

    \makeatletter

    \def\pgf@izquierda{izquierda}
    \def\pgf@posicion@manivela{izquierda} % by default

    % To use with PGF:
    \def\pgfsetposicionmanivela#1{\def\pgf@posicion@manivela{#1}}

    % To use with Tikz:
    \tikzoption{posicion manivela}{\pgfsetposicionmanivela{#1}}

    %% Declaración de la forma:

    \pgfdeclareshape{valvula de esfera}{

      \setpaths{\valvulaanchor}{%
        \valvulaborder
        % La manivela de la válvula:
        \pgfpathmoveto{\pgfpoint{0em}{0em}}
          \pgfpathlineto{\pgfpoint{0em}{1.5\pgf@ya}}
          \ifx\pgf@posicion@manivela\pgf@izquierda
            \pgfpathlineto{\pgfpoint{-\pgf@xa}{1.5\pgf@ya}}
        \else
            \pgfpathlineto{\pgfpoint{\pgf@xa}{1.5\pgf@ya}}
        \fi
      }

      \inheritsavedanchors[from=valvula de compuerta]
      \inheritanchorborder[from=valvula de compuerta]

      \inheritanchor[from=valvula de compuerta]{center} % si no está, da error
      \inheritanchor[from=valvula de compuerta]{c}
      \inheritanchor[from=valvula de compuerta]{ur}
      \inheritanchor[from=valvula de compuerta]{r}
      \inheritanchor[from=valvula de compuerta]{dr}
      \inheritanchor[from=valvula de compuerta]{dl}
      \inheritanchor[from=valvula de compuerta]{l}
      \inheritanchor[from=valvula de compuerta]{ul}

      % De la manivela de la válvula
      \inheritanchor[from=valvula de compuerta]{tc}
      \inheritanchor[from=valvula de compuerta]{tl}
      \inheritanchor[from=valvula de compuerta]{tr}

      \anchor{tm}{\northeast \pgf@x=\pgf@x \pgf@y=1.5\pgf@y}
      \ifx\pgf@posicion@manivela\pgf@izquierda
        \anchor{tm}{\northeast \pgf@x=-\pgf@x \pgf@y=1.5\pgf@y}
      \fi

    }

    \makeatother

\makeatletter

%% Declaración de la forma:

\pgfdeclareshape{valvula de compuerta}{

  \setpaths{\valvulaanchor}{%
    \valvulaborder
    % La manivela de la válvula:
      \pgfpathmoveto{\pgfpoint{0em}{0em}}
      \pgfpathlineto{\pgfpoint{0em}{1.5\pgf@ya}}
      \pgfpathmoveto{\pgfpoint{-\pgf@xa}{1.5\pgf@ya}}
      \pgfpathlineto{\pgfpoint{\pgf@xa}{1.5\pgf@ya}}
  }

  \inheritsavedanchors[from=valvula]
  \inheritanchorborder[from=valvula]

  \inheritanchor[from=valvula]{center} % si no está da error
  \inheritanchor[from=valvula]{c}
  \inheritanchor[from=valvula]{ur}
  \inheritanchor[from=valvula]{r}
  \inheritanchor[from=valvula]{dr}
  \inheritanchor[from=valvula]{dl}
  \inheritanchor[from=valvula]{l}
  \inheritanchor[from=valvula]{ul}

  % De la manivela de la válvula
  \anchor{tc}{\northeast \pgf@x=0\pgf@x \pgf@y=1.5\pgf@y}
  \anchor{tr}{\northeast \pgf@x=\pgf@x \pgf@y=1.5\pgf@y}
  \anchor{tl}{\northeast \pgf@x=-\pgf@x \pgf@y=1.5\pgf@y}

}

\makeatother

%-------------------------------------------------------------------------------
% Necesario el paquete makeshape
%-------------------------------------------------------------------------------

\makeatletter

%% Constante para la forma valvula:
\def\gap{4pt}

%% Anchor path:

\def\valvulaanchor{ % Obtiene la caja de texto correcta:

  \pgf@xa=\ctbnex
    \pgf@ya=\ctbney

    % Crea el margen para la forma:
    \advance\pgf@xa by \gap
    \advance\pgf@ya by \gap
    % Corrige minheight y minwidth, y outerxsep o outerysep:
    \mincorrect{\pgf@xa}{\pgfshapeminwidth}
    \advance\pgf@xa\pgfshapeouterxsep
    \mincorrect{\pgf@ya}{\pgfshapeminheight}
    \advance\pgf@ya\pgfshapeouterysep
  % Dibuja el anchor con \pgfusepath{stroke}:
  \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
  \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
  \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
  \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
  \pgfpathclose %\pgfusepath{stroke}

}

%% Background path:

\def\valvulaborder{ % Obtiene la caja de texto correcta:

    \pgf@xa=\ctbnex
    \pgf@ya=\ctbney

    % Crea el margen para la forma:
    \advance\pgf@xa by \gap
    \advance\pgf@ya by \gap
        % Corrige minheight y minwidth, y outerxsep o outerysep:
    \mincorrect{\pgf@xa}{\pgfshapeminwidth}
    \mincorrect{\pgf@ya}{\pgfshapeminheight}
    % Dibuja el triángulo derecho:
    \pgfpathmoveto{\pgfpoint{0em}{0em}}
    \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
  \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
    \pgfpathclose
    \ifpgf@color@derecha % Será una opcion de relleno.
      \pgfsetfillcolor{\pgf@colorl@lateral@derecho}
      \pgfusepath{fill,stroke}
    \fi
    % Triángulo izquierdo:
    \pgfpathmoveto{\pgfpoint{0em}{0em}}
    \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
  \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
    \pgfpathclose
    \ifpgf@color@izquierda % Será una opcion de relleno.
      \pgfsetfillcolor{\pgf@colorl@lateral@izquierdo}
      \pgfusepath{fill,stroke}
    \fi

}

%% Declaración de la forma:

\pgfdeclareshape{valvula}{

  \setpaths{\valvulaanchor}{\valvulaborder}

  \savedanchor{\northeast}{
      \pgf@x = \ctbnex
      \pgf@y = \ctbney
      \advance\pgf@x by \gap
      \advance\pgf@y by \gap
      \mincorrect{\pgf@x}{\pgfshapeminwidth}
      \mincorrect{\pgf@y}{\pgfshapeminheight}
      \advance\pgf@x\pgfshapeouterxsep
      \advance\pgf@y\pgfshapeouterysep
  }

  % Anchors:
  \anchor{c}{\northeast \pgf@x=0pt \pgf@y=0pt}
  \anchor{ur}{\northeast}
  \anchor{r}{\northeast \pgf@y=0pt}
  \anchor{dr}{\northeast \pgf@y=-\pgf@y}
  \anchor{dl}{\northeast \pgf@x=-\pgf@x \pgf@y=-\pgf@y}
  \anchor{l}{\northeast \pgf@x=-\pgf@x \pgf@y=0pt}
  \anchor{ul}{\northeast \pgf@x=-\pgf@x}

}

\newif\ifpgf@color@derecha
\pgf@color@derechafalse
\newif\ifpgf@color@izquierda
\pgf@color@izquierdafalse

% Para usar con PGF:
\def\pgfsetcolorderecha#1{%
  \def\pgf@colorl@lateral@derecho{#1}
  \pgf@color@derechatrue
}
%
\def\pgfsetcolorizquierda#1{%
  \def\pgf@colorl@lateral@izquierdo{#1}
  \pgf@color@izquierdatrue
}

% Para usar con Tikz:
\tikzoption{color derecha}{\pgfsetcolorderecha{#1}}
\tikzoption{color izquierda}{\pgfsetcolorizquierda{#1}}

\makeatother

\documentclass[a4paper,10pt]{article}
\usepackage[left=23mm,right=23mm,top=25mm,bottom=25mm]{geometry}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{microtype}

\usepackage[spanish,es-nodecimaldot]{babel}
\renewcommand\shorthandsspanish{} % evita conflictos con tikz
\spanishdecimal{,} %\decimalpoint

\usepackage{newpxtext,newpxmath} % palatino con símbolos matemáticos (compatible amsmath)
%\usepackage{beramono} % oara usar con listings

\usepackage[usenames,x11names,dvipsnames,svgnames]{xcolor}
\usepackage{colortbl}
\usepackage{tabu}
\usepackage{xspace}
\usepackage{enumitem}
\usepackage{verbatim,fancyvrb} % fancy verbatim
\usepackage[pstricks]{fancyvrb-ex}
\usepackage[hyphens]{url}
\usepackage{hyperref}
\usepackage[multiple]{footmisc} %@ múltiples footnotes

\usepackage{tikz}
\usepackage{pagecolor} % http://ctan.org/pkg/{pagecolor,lipsum}
\usetikzlibrary{decorations,decorations.text,backgrounds,matrix}
\usetikzlibrary{shapes.multipart}
\usepackage{makeshape}

\tikzset{
  st texto/.style={
    font=\sffamily\footnotesize,
    circle,black,fill=white,inner sep=0.1em
  },
  st valvula/.style={
    draw=blue,minimum width=6mm,minimum height=3mm,line width=0.2mm
  },
  st linea nodo/.style={line width=0.1mm,latex-,orange}
}

\input{valvula.tex}
\input{valvula-de-compuerta.tex}
\input{valvula-de-esfera.tex}

\begin{document}

\begin{tikzpicture}[
  x=1mm,y=1mm,remember picture, overlay,shift={(current page.center)}
]

\begin{scope}[shift={(-50,0)}]

  \node[%
    valvula de compuerta,st valvula,
    color izquierda=yellow!50,color derecha=cyan!25
  ] (v2) at (0,0) {};

  %\draw[st linea nodo] (v2.c) -- ++(270:10.15) node[st texto] {c};
  %
  %\draw[st linea nodo] (v2.r) -- ++(0:10) node[st texto] {r};
  %\draw[st linea nodo] (v2.ur) -- ++(45:10) node[st texto] {ur};
  %\draw[st linea nodo] (v2.dr) -- ++(-45:10) node[st texto] {dr};
  %
  %\draw[st linea nodo] (v2.l) -- ++(180:10) node[st texto] {l};
  %\draw[st linea nodo] (v2.ul) -- ++(135:10) node[st texto] {ul};
  %\draw[st linea nodo] (v2.dl) -- ++(225:10) node[st texto] {dl};
  %
  \draw[st linea nodo] (v2.tc) -- ++(90:10) node[st texto] {tc};
  \draw[st linea nodo] (v2.tr) -- ++(70:10) node[st texto] {tr};
  \draw[st linea nodo] (v2.tl) -- ++(110:10) node[st texto] {tl};

\end{scope}


\begin{scope}[shift={(0,0)}]

  \node[%
    valvula de esfera,st valvula,posicion manivela=izquierda,
    color izquierda=yellow!50,color derecha=cyan!25
  ] (v3) at (0,0) {};

  \draw[st linea nodo] (v3.tc) -- ++(90:10) node[st texto] {tc};
  %\draw[st linea nodo] (v3.tm) -- ++(110:10) node[st texto] {tm};
  \draw[st linea nodo] (v3.tl) -- ++(110:10) node[st texto] {tl};

\end{scope}


\begin{scope}[shift={(50,0)}]

  \node[%
    valvula de esfera,st valvula,posicion manivela=derecha, % defecto
    color izquierda=yellow!50,color derecha=cyan!25
  ] (v4) at (0,0) {};

  \draw[st linea nodo] (v4.tc) -- ++(90:10) node[st texto] {tc};
  %\draw[st linea nodo] (v4.tm) -- ++(70:10) node[st texto] {tm};
  \draw[st linea nodo] (v4.tr) -- ++(70:10) node[st texto] {tr};

\end{scope}


\end{tikzpicture}

\end{document}

I'm desperated because \ifx works properly into \setpaths, but not in the last \anchor.

\documentclass[a4paper,10pt]{article}
\usepackage{filecontents}
\begin{filecontents*}{valvula.tex}
    \makeatletter

    \def\pgf@izquierda{izquierda}
    \def\pgf@posicion@manivela{izquierda} % by default

    % To use with PGF:
    \def\pgfsetposicionmanivela#1{\def\pgf@posicion@manivela{#1}}

    % To use with Tikz:
    \tikzoption{posicion manivela}{\pgfsetposicionmanivela{#1}}

    %% Declaración de la forma:

    \pgfdeclareshape{valvula de esfera}{
      \setpaths{\valvulaanchor}{%
        \valvulaborder
        % La manivela de la válvula:
        \pgfpathmoveto{\pgfpoint{0em}{0em}}
          \pgfpathlineto{\pgfpoint{0em}{1.5\pgf@ya}}
          \ifx\pgf@posicion@manivela\pgf@izquierda
            \pgfpathlineto{\pgfpoint{-\pgf@xa}{1.5\pgf@ya}}
        \else
            \pgfpathlineto{\pgfpoint{\pgf@xa}{1.5\pgf@ya}}
        \fi
      }
      \inheritsavedanchors[from=valvula de compuerta]
      \inheritanchorborder[from=valvula de compuerta]
      %\inheritanchor[from=valvula de compuerta]{center} % si no está, da error
      \inheritanchor[from=valvula de compuerta]{c}
      \inheritanchor[from=valvula de compuerta]{ur}
      \inheritanchor[from=valvula de compuerta]{r}
      \inheritanchor[from=valvula de compuerta]{dr}
      \inheritanchor[from=valvula de compuerta]{dl}
      \inheritanchor[from=valvula de compuerta]{l}
      \inheritanchor[from=valvula de compuerta]{ul}
      % De la manivela de la válvula
      \anchor{tc}{\northeast  \pgf@x=0\pgf@x  \pgf@y=1.5\pgf@y}
      \anchor{tr}{\northeast \pgf@x=\pgf@x \pgf@y=1.5\pgf@y}
      \anchor{tl}{\northeast \pgf@x=-\pgf@x \pgf@y=1.5\pgf@y}
      \anchor{tm}{\northeast \pgf@x=\pgf@x \pgf@y=1.5\pgf@y}
      \ifx\pgf@posicion@manivela\pgf@izquierda
        \anchor{tm}{\northeast \pgf@x=-\pgf@x \pgf@y=1.5\pgf@y}
      \fi
    }

    \makeatother

\makeatletter

%% Declaración de la forma:

\pgfdeclareshape{valvula de compuerta}{
  \setpaths{\valvulaanchor}{%
    \valvulaborder
    % La manivela de la válvula:
      \pgfpathmoveto{\pgfpoint{0em}{0em}}
      \pgfpathlineto{\pgfpoint{0em}{1.5\pgf@ya}}
      \pgfpathmoveto{\pgfpoint{-\pgf@xa}{1.5\pgf@ya}}
      \pgfpathlineto{\pgfpoint{\pgf@xa}{1.5\pgf@ya}}
  }
  \inheritsavedanchors[from=valvula]
  \inheritanchorborder[from=valvula]
  %\inheritanchor[from=valvula]{center} % si no está da error
  \inheritanchor[from=valvula]{c}
  \inheritanchor[from=valvula]{ur}
  \inheritanchor[from=valvula]{r}
  \inheritanchor[from=valvula]{dr}
  \inheritanchor[from=valvula]{dl}
  \inheritanchor[from=valvula]{l}
  \inheritanchor[from=valvula]{ul}
  % De la manivela de la válvula
  \anchor{tc}{\northeast  \pgf@x=0\pgf@x  \pgf@y=1.5\pgf@y}
  \anchor{tr}{\northeast \pgf@x=\pgf@x \pgf@y=1.5\pgf@y}
  \anchor{tl}{\northeast \pgf@x=-\pgf@x \pgf@y=1.5\pgf@y}
}

\makeatother

%-------------------------------------------------------------------------------
% Necesario el paquete makeshape
%-------------------------------------------------------------------------------

\makeatletter

%% Constante para la forma valvula:
\def\gap{4pt}

%% Anchor path:

\def\valvulaanchor{ % Obtiene la caja de texto correcta:

  \pgf@xa=\ctbnex
    \pgf@ya=\ctbney

    % Crea el margen para la forma:
    \advance\pgf@xa by \gap
    \advance\pgf@ya by \gap
    % Corrige minheight y minwidth, y outerxsep o outerysep:
    \mincorrect{\pgf@xa}{\pgfshapeminwidth}
    \advance\pgf@xa\pgfshapeouterxsep
    \mincorrect{\pgf@ya}{\pgfshapeminheight}
    \advance\pgf@ya\pgfshapeouterysep
  % Dibuja el anchor con \pgfusepath{stroke}:
  \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
  \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
  \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
  \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
  \pgfpathclose %\pgfusepath{stroke}

}

%% Background path:

\def\valvulaborder{ % Obtiene la caja de texto correcta:

    \pgf@xa=\ctbnex
    \pgf@ya=\ctbney

    % Crea el margen para la forma:
    \advance\pgf@xa by \gap
    \advance\pgf@ya by \gap
        % Corrige minheight y minwidth, y outerxsep o outerysep:
    \mincorrect{\pgf@xa}{\pgfshapeminwidth}
    \mincorrect{\pgf@ya}{\pgfshapeminheight}
    % Dibuja el triángulo derecho:
    \pgfpathmoveto{\pgfpoint{0em}{0em}}
    \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
  \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
    \pgfpathclose
    \ifpgf@color@derecha % Será una opcion de relleno.
      \pgfsetfillcolor{\pgf@colorl@lateral@derecho}
      \pgfusepath{fill,stroke}
    \fi
    % Triángulo izquierdo:
    \pgfpathmoveto{\pgfpoint{0em}{0em}}
    \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
  \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
    \pgfpathclose
    \ifpgf@color@izquierda % Será una opcion de relleno.
      \pgfsetfillcolor{\pgf@colorl@lateral@izquierdo}
      \pgfusepath{fill,stroke}
    \fi

}

%% Declaración de la forma:

\pgfdeclareshape{valvula}{

  \setpaths{\valvulaanchor}{\valvulaborder}

  \savedanchor{\northeast}{
      \pgf@x = \ctbnex
      \pgf@y = \ctbney
      \advance\pgf@x by \gap
      \advance\pgf@y by \gap
      \mincorrect{\pgf@x}{\pgfshapeminwidth}
      \mincorrect{\pgf@y}{\pgfshapeminheight}
      \advance\pgf@x\pgfshapeouterxsep
      \advance\pgf@y\pgfshapeouterysep
  }

  % Anchors:
  \anchor{c}{\northeast \pgf@x=0pt \pgf@y=0pt}
  \anchor{ur}{\northeast}
  \anchor{r}{\northeast \pgf@y=0pt}
  \anchor{dr}{\northeast \pgf@y=-\pgf@y}
  \anchor{dl}{\northeast \pgf@x=-\pgf@x \pgf@y=-\pgf@y}
  \anchor{l}{\northeast \pgf@x=-\pgf@x \pgf@y=0pt}
  \anchor{ul}{\northeast \pgf@x=-\pgf@x}

}

\newif\ifpgf@color@derecha
\pgf@color@derechafalse
\newif\ifpgf@color@izquierda
\pgf@color@izquierdafalse

% Para usar con PGF:
\def\pgfsetcolorderecha#1{%
  \def\pgf@colorl@lateral@derecho{#1}
  \pgf@color@derechatrue
}
%
\def\pgfsetcolorizquierda#1{%
  \def\pgf@colorl@lateral@izquierdo{#1}
  \pgf@color@izquierdatrue
}

% Para usar con Tikz:
\tikzoption{color derecha}{\pgfsetcolorderecha{#1}}
\tikzoption{color izquierda}{\pgfsetcolorizquierda{#1}}
\makeatother
\end{filecontents*}

\usepackage[left=23mm,right=23mm,top=25mm,bottom=25mm]{geometry}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{microtype}

\usepackage[spanish,es-nodecimaldot]{babel}
\renewcommand\shorthandsspanish{} % evita conflictos con tikz
\spanishdecimal{,} %\decimalpoint

\usepackage{newpxtext,newpxmath} % palatino con símbolos matemáticos (compatible amsmath)
%\usepackage{beramono} % oara usar con listings

\usepackage[usenames,x11names,dvipsnames,svgnames]{xcolor}
\usepackage{hyperref}

\usepackage{tikz}
% \usetikzlibrary{decorations,decorations.text,backgrounds,matrix}
%  \usetikzlibrary{shapes.multipart}

\usepackage{makeshape}

\tikzset{
  st texto/.style={
    font=\sffamily\footnotesize,
    circle,black,fill=white,inner sep=0.1em
  },
  st valvula/.style={
    draw=blue,minimum width=6mm,minimum height=3mm,line width=0.2mm
  },
  st linea nodo/.style={line width=0.1mm,latex-,orange}
}

\input{valvula.tex}
% \input{valvula-de-compuerta.tex}
% \input{valvula-de-esfera.tex}

\begin{document}

\begin{tikzpicture}[
  x=1mm,y=1mm,remember picture, overlay,shift={(current page.center)}
]

\begin{scope}[shift={(0,0)}]

  \node[%
    valvula de esfera,st valvula,posicion manivela=izquierda,
    color izquierda=yellow!50,color derecha=cyan!25
  ] (v3) at (0,0) {};

  \draw[st linea nodo] (v3.tc) -- ++(90:10) node[st texto] {tc};
  \draw[st linea nodo] (v3.tm) -- ++(110:10) node[st texto] {tm};

\end{scope}


\begin{scope}[shift={(50,0)}]

  \node[%
    valvula de esfera,st valvula,posicion manivela=derecha, % defecto
    color izquierda=yellow!50,color derecha=cyan!25
  ] (v4) at (0,0) {};

  \draw[st linea nodo] (v4.tc) -- ++(90:10) node[st texto] {tc};
  \draw[st linea nodo] (v4.tm) -- ++(70:10) node[st texto] (ntm) {tm};

  %
  \node[above of= ntm,red,align=center] (comentm) {Here tm should\\ be at right};
  \path (comentm) edge[red,out=0,in=90,-latex] (v4.tr);

\end{scope}


\end{tikzpicture}

\end{document}

enter image description here

3
  • 1
    Could you please provide a complete code, not just a fragment? Even if one adds a preamble, one would need the definition of valvula de compuerta since you use \inheritsavedanchors[from=valvula de compuerta] and so on and so forth.
    – user121799
    Feb 23, 2019 at 18:03
  • I've added the overall code.
    – aguivald
    Feb 23, 2019 at 18:35
  • Not really, you need to tell others which piece goes in what file. And you load a lot of stuff that is not related to the problem. There is an obvious problem that you are using the center anchor that has not been defined, and then there is a more tricky problem related to the tc and so on anchors.
    – user121799
    Feb 23, 2019 at 18:44

1 Answer 1

3

Thanks for updating your code. I base this revision on your new code, which you should move to the question. The issue is that the \ifx before the anchor does not get executed any more. So you need to move the \ifx into the anchor.

  \anchor{tm}{\ifx\pgf@posicion@manivela\pgf@izquierda
    \northeast \pgf@x=-\pgf@x \pgf@y=1.5\pgf@y
    \else
    \northeast \pgf@x=\pgf@x \pgf@y=1.5\pgf@y   
  \fi}

Here is the full code.

\documentclass[a4paper,10pt]{article}
\usepackage{filecontents}
\begin{filecontents*}{valvula.tex}
    \makeatletter

    \def\pgf@izquierda{izquierda}
    \def\pgf@posicion@manivela{izquierda} % by default

    % To use with PGF:
    \def\pgfsetposicionmanivela#1{\edef\pgf@posicion@manivela{#1}}

    % To use with Tikz:
    \tikzoption{posicion manivela}{\pgfsetposicionmanivela{#1}}

    %% Declaración de la forma:

    \pgfdeclareshape{valvula de esfera}{
      \setpaths{\valvulaanchor}{%
        \valvulaborder
        % La manivela de la válvula:
        \pgfpathmoveto{\pgfpoint{0em}{0em}}
          \pgfpathlineto{\pgfpoint{0em}{1.5\pgf@ya}}
          \ifx\pgf@posicion@manivela\pgf@izquierda
            \pgfpathlineto{\pgfpoint{-\pgf@xa}{1.5\pgf@ya}}
        \else
            \pgfpathlineto{\pgfpoint{\pgf@xa}{1.5\pgf@ya}}
        \fi
      }
      \inheritsavedanchors[from=valvula de compuerta]
      \inheritanchorborder[from=valvula de compuerta]
      %\inheritanchor[from=valvula de compuerta]{center} % si no está, da error
      \inheritanchor[from=valvula de compuerta]{c}
      \inheritanchor[from=valvula de compuerta]{ur}
      \inheritanchor[from=valvula de compuerta]{r}
      \inheritanchor[from=valvula de compuerta]{dr}
      \inheritanchor[from=valvula de compuerta]{dl}
      \inheritanchor[from=valvula de compuerta]{l}
      \inheritanchor[from=valvula de compuerta]{ul}
      % De la manivela de la válvula
      \anchor{tc}{\northeast  \pgf@x=0\pgf@x  \pgf@y=1.5\pgf@y}
      \anchor{tr}{\northeast \pgf@x=\pgf@x \pgf@y=1.5\pgf@y}
      \anchor{tl}{\northeast \pgf@x=-\pgf@x \pgf@y=1.5\pgf@y}      
      \anchor{tm}{\ifx\pgf@posicion@manivela\pgf@izquierda
        \northeast \pgf@x=-\pgf@x \pgf@y=1.5\pgf@y
        \else
        \northeast \pgf@x=\pgf@x \pgf@y=1.5\pgf@y   
      \fi}
    }

    \makeatother

\makeatletter

%% Declaración de la forma:

\pgfdeclareshape{valvula de compuerta}{
  \setpaths{\valvulaanchor}{%
    \valvulaborder
    % La manivela de la válvula:
      \pgfpathmoveto{\pgfpoint{0em}{0em}}
      \pgfpathlineto{\pgfpoint{0em}{1.5\pgf@ya}}
      \pgfpathmoveto{\pgfpoint{-\pgf@xa}{1.5\pgf@ya}}
      \pgfpathlineto{\pgfpoint{\pgf@xa}{1.5\pgf@ya}}
  }
  \inheritsavedanchors[from=valvula]
  \inheritanchorborder[from=valvula]
  %\inheritanchor[from=valvula]{center} % si no está da error
  \inheritanchor[from=valvula]{c}
  \inheritanchor[from=valvula]{ur}
  \inheritanchor[from=valvula]{r}
  \inheritanchor[from=valvula]{dr}
  \inheritanchor[from=valvula]{dl}
  \inheritanchor[from=valvula]{l}
  \inheritanchor[from=valvula]{ul}
  % De la manivela de la válvula
  \anchor{tc}{\northeast  \pgf@x=0\pgf@x  \pgf@y=1.5\pgf@y}
  \anchor{tr}{\northeast \pgf@x=\pgf@x \pgf@y=1.5\pgf@y}
  \anchor{tl}{\northeast \pgf@x=-\pgf@x \pgf@y=1.5\pgf@y}
}

\makeatother

%-------------------------------------------------------------------------------
% Necesario el paquete makeshape
%-------------------------------------------------------------------------------

\makeatletter

%% Constante para la forma valvula:
\def\gap{4pt}

%% Anchor path:

\def\valvulaanchor{ % Obtiene la caja de texto correcta:

  \pgf@xa=\ctbnex
    \pgf@ya=\ctbney

    % Crea el margen para la forma:
    \advance\pgf@xa by \gap
    \advance\pgf@ya by \gap
    % Corrige minheight y minwidth, y outerxsep o outerysep:
    \mincorrect{\pgf@xa}{\pgfshapeminwidth}
    \advance\pgf@xa\pgfshapeouterxsep
    \mincorrect{\pgf@ya}{\pgfshapeminheight}
    \advance\pgf@ya\pgfshapeouterysep
  % Dibuja el anchor con \pgfusepath{stroke}:
  \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
  \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
  \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
  \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
  \pgfpathclose %\pgfusepath{stroke}

}

%% Background path:

\def\valvulaborder{ % Obtiene la caja de texto correcta:

    \pgf@xa=\ctbnex
    \pgf@ya=\ctbney

    % Crea el margen para la forma:
    \advance\pgf@xa by \gap
    \advance\pgf@ya by \gap
        % Corrige minheight y minwidth, y outerxsep o outerysep:
    \mincorrect{\pgf@xa}{\pgfshapeminwidth}
    \mincorrect{\pgf@ya}{\pgfshapeminheight}
    % Dibuja el triángulo derecho:
    \pgfpathmoveto{\pgfpoint{0em}{0em}}
    \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
  \pgfpathlineto{\pgfpoint{\pgf@xa}{-\pgf@ya}}
    \pgfpathclose
    \ifpgf@color@derecha % Será una opcion de relleno.
      \pgfsetfillcolor{\pgf@colorl@lateral@derecho}
      \pgfusepath{fill,stroke}
    \fi
    % Triángulo izquierdo:
    \pgfpathmoveto{\pgfpoint{0em}{0em}}
    \pgfpathlineto{\pgfpoint{-\pgf@xa}{\pgf@ya}}
  \pgfpathlineto{\pgfpoint{-\pgf@xa}{-\pgf@ya}}
    \pgfpathclose
    \ifpgf@color@izquierda % Será una opcion de relleno.
      \pgfsetfillcolor{\pgf@colorl@lateral@izquierdo}
      \pgfusepath{fill,stroke}
    \fi

}

%% Declaración de la forma:

\pgfdeclareshape{valvula}{

  \setpaths{\valvulaanchor}{\valvulaborder}

  \savedanchor{\northeast}{
      \pgf@x = \ctbnex
      \pgf@y = \ctbney
      \advance\pgf@x by \gap
      \advance\pgf@y by \gap
      \mincorrect{\pgf@x}{\pgfshapeminwidth}
      \mincorrect{\pgf@y}{\pgfshapeminheight}
      \advance\pgf@x\pgfshapeouterxsep
      \advance\pgf@y\pgfshapeouterysep
  }

  % Anchors:
  \anchor{c}{\northeast \pgf@x=0pt \pgf@y=0pt}
  \anchor{ur}{\northeast}
  \anchor{r}{\northeast \pgf@y=0pt}
  \anchor{dr}{\northeast \pgf@y=-\pgf@y}
  \anchor{dl}{\northeast \pgf@x=-\pgf@x \pgf@y=-\pgf@y}
  \anchor{l}{\northeast \pgf@x=-\pgf@x \pgf@y=0pt}
  \anchor{ul}{\northeast \pgf@x=-\pgf@x}

}

\newif\ifpgf@color@derecha
\pgf@color@derechafalse
\newif\ifpgf@color@izquierda
\pgf@color@izquierdafalse

% Para usar con PGF:
\def\pgfsetcolorderecha#1{%
  \def\pgf@colorl@lateral@derecho{#1}
  \pgf@color@derechatrue
}
%
\def\pgfsetcolorizquierda#1{%
  \def\pgf@colorl@lateral@izquierdo{#1}
  \pgf@color@izquierdatrue
}

% Para usar con Tikz:
\tikzoption{color derecha}{\pgfsetcolorderecha{#1}}
\tikzoption{color izquierda}{\pgfsetcolorizquierda{#1}}
\makeatother
\end{filecontents*}

\usepackage[left=23mm,right=23mm,top=25mm,bottom=25mm]{geometry}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{microtype}

\usepackage[spanish,es-nodecimaldot]{babel}
\renewcommand\shorthandsspanish{} % evita conflictos con tikz
\spanishdecimal{,} %\decimalpoint

\usepackage{newpxtext,newpxmath} % palatino con símbolos matemáticos (compatible amsmath)
%\usepackage{beramono} % oara usar con listings

\usepackage[usenames,x11names,dvipsnames,svgnames]{xcolor}
\usepackage{hyperref}

\usepackage{tikz}
% \usetikzlibrary{decorations,decorations.text,backgrounds,matrix}
%  \usetikzlibrary{shapes.multipart}

\usepackage{makeshape}

\tikzset{
  st texto/.style={
    font=\sffamily\footnotesize,
    circle,black,fill=white,inner sep=0.1em
  },
  st valvula/.style={
    draw=blue,minimum width=6mm,minimum height=3mm,line width=0.2mm
  },
  st linea nodo/.style={line width=0.1mm,latex-,orange}
}

\input{valvula.tex}
% \input{valvula-de-compuerta.tex}
% \input{valvula-de-esfera.tex}

\begin{document}

\begin{tikzpicture}[
  x=1mm,y=1mm,remember picture, overlay,shift={(current page.center)}
]

\begin{scope}[shift={(0,0)}]

  \node[%
    valvula de esfera,st valvula,posicion manivela=izquierda,
    color izquierda=yellow!50,color derecha=cyan!25
  ] (v3) at (0,0) {};

  \draw[st linea nodo] (v3.tc) -- ++(90:10) node[st texto] {tc};
  \draw[st linea nodo] (v3.tm) -- ++(110:10) node[st texto] {tm};

\end{scope}


\begin{scope}[shift={(50,0)},posicion manivela=derecha]

  \node[%
    valvula de esfera,st valvula, % defecto
    color izquierda=yellow!50,color derecha=cyan!25
  ] (v4) at (0,0) {};

  \draw[st linea nodo] (v4.tc) -- ++(90:10) node[st texto] {tc};
  \draw[st linea nodo] (v4.tm) -- ++(70:10) node[st texto] (ntm) {tm};

  %
  \node[above of= ntm,red,align=center] (comentm) {Here tm should\\ be at right};
  \path (comentm) edge[red,out=0,in=90,-latex] (v4.tr);

\end{scope}


\end{tikzpicture}

\end{document}

enter image description here

10
  • Thank you so much for your answer, I'm gratefully for that. However, I supposed that I didn't a good explanation of the problem. The commented lines \draw[st linea nodo] (v3.tm) -- ++(110:10) node[st texto] {tm}; , and the same for v4 should be put tm at left and at right, respectively, but the second \ifx doesn't work.
    – aguivald
    Feb 23, 2019 at 22:13
  • And I'm sorry for my bad English language.
    – aguivald
    Feb 23, 2019 at 22:14
  • This is an example or the error:
    – aguivald
    Feb 23, 2019 at 22:55
  • I didn't exactly know how to post your requirement. It's in the following post.
    – aguivald
    Feb 23, 2019 at 22:58
  • 1
    Of course. I've just clicked in the check mark. Again, thank you very much.
    – aguivald
    Feb 24, 2019 at 0:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .