如何正确地将新选项应用于 makeshape 包的 \pgfdeclareshape

如何正确地将新选项应用于 makeshape 包的 \pgfdeclareshape

我正在尝试借助 makeshape 包来制作新的形状,但在使用新选项时遇到了很多问题。

这里举个例子:

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

我很绝望,因为 \ifx 在 \setpaths 中可以正常工作,但在最后的 \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}

在此处输入图片描述

答案1

感谢您更新代码。我根据您的新代码进行了此修订,您应该将其移至问题。问题是\ifx锚点之前的不再执行。因此您需要将移至\ifx锚点中。

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

以下是完整的代码。

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

在此处输入图片描述

相关内容