如何使用 tikz-pgf 在新形状中定义新的锚点边框

如何使用 tikz-pgf 在新形状中定义新的锚点边框

我正在尝试通过在 pgf-tikz 中定义新形状来构建一个符号库。说实话,这对我来说是一项艰巨的任务,因为我不了解很多代码。幸运的是,多亏了这些网站和 @marmot,我一步步几乎完成了任务。但现在,我在锚点边框方面遇到了问题。这里是代码及其相应的不言自明的结果。

\documentclass[border=2mm]{standalone}
\usepackage{tikz,makeshape}
\usetikzlibrary{calc}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{filecontents}
\begin{filecontents*}{contador.tex}

\makeatletter

\def\gap{0pt}
\newlength{\an@ctdordiv} \an@ctdordiv=5mm

%% Anchor path:

\def\generalanchor{} % No es necesario, el nodo no llevará texto.

%% Background path:

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

  % La parte anterior no es necesaria, no llevará texto el nodo
  % Triángulo izquierdo:
  %
  \pgfpathrectanglecorners{\pgfpoint{-\an@ctdordiv}{-\an@ctdordiv}}
                          {\pgfpoint{ \an@ctdordiv}{ \an@ctdordiv}}

  \ifx\tikz@fillcolor\empty
    \pgfusepath{stroke,clip}
  \else
    \pgfsetfillcolor{\tikz@fillcolor}
    % La opción clip evita los picos del triángulo sobresaliendo.
    \pgfusepath{fill,stroke,clip}
  \fi
  %
  % Línea diagonal
  %
  \pgfsetbeveljoin
  \pgfmoveto{\pgfpoint{-\an@ctdordiv}{-\an@ctdordiv}}
  \pgflineto{\pgfpoint{ \an@ctdordiv}{ \an@ctdordiv}}

}

%% Declaración de la forma:

\pgfdeclareshape{contador divisionario}{

  \setpaths{\generalanchor}{\contdivborder}

  \savedanchor{\centerpoint}{
      \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}{\centerpoint \pgf@x=0pt \pgf@y=0pt}
  %
  \anchor{u}{\centerpoint \pgf@x=0pt \pgf@y= \an@ctdordiv}
  \anchor{d}{\centerpoint \pgf@x=0pt \pgf@y=-\an@ctdordiv}
  \anchor{r}{\centerpoint \pgf@x= \an@ctdordiv \pgf@y=0pt}
  \anchor{l}{\centerpoint \pgf@x=-\an@ctdordiv \pgf@y=0pt}
  %
  \anchor{ur}{\centerpoint \pgf@x= \an@ctdordiv \pgf@y= \an@ctdordiv}
  \anchor{dr}{\centerpoint \pgf@x= \an@ctdordiv \pgf@y=-\an@ctdordiv}
  \anchor{ul}{\centerpoint \pgf@x=-\an@ctdordiv \pgf@y= \an@ctdordiv}
  \anchor{dl}{\centerpoint \pgf@x=-\an@ctdordiv \pgf@y=-\an@ctdordiv}

}

\makeatother


\end{filecontents*}

\tikzset{
    st texto/.style={
        font=\scriptsize\tiny,align=center,anchor=north,
        black,inner sep=0.0em
    },
    st valvula/.style={
        node contents={},
        draw,minimum width=3mm,minimum height=2.85mm,line width=0.1mm,inner sep=0em,scale=2
    },
    st linea nodo/.style={line width=0.1mm,latex-,orange,shorten >= 0.5em},
}

\input{contador.tex}

\begin{document}

    \begin{tikzpicture}[x=1mm,y=1mm,remember picture]

  %%

    \path (0,0) node (wrong) [%
    contador divisionario,st valvula,
    fill=cyan!50,line width=1mm
  ];

  \draw[st linea nodo] (wrong.r) -- ++(0:10) node[st texto] {r};

  \node[circle,minimum size=4mm,draw=red] (circwrong) at (wrong.r) {};
  \node[st texto] (txtwrong) at ([shift={(10,-5)}]wrong.r) {
    anchor in\\ the center\\ of the line\\ I don't need\\ this!
  };
  \draw[-latex,line width=0.1mm] (txtwrong) edge[out=90,in=-20] (circwrong);

  %%

    \path (40,0) node (correct) [%
    contador divisionario,st valvula,
    fill=cyan!50,line width=1mm
  ];

  \draw[st linea nodo] ([shift={(0.5,0)}]correct.r) -- ++(0:10) node[st texto] {r};

  \node[circle,minimum size=4mm,draw=green] (circcorrect) at (correct.r) {};
  \node[st texto] (txtcorrect) at ([shift={(10,-5)}]correct.r) {
      anchor in\\ the border\\ of the line\\ What I want!
  };
  \draw[-latex,line width=0.1mm] (txtcorrect) edge[out=90,in=-20] (circcorrect);

  %%

    \path (80,0) node (correct2) [%
    contador divisionario,st valvula,
    fill=cyan!50,line width=2mm
  ];

  \draw[st linea nodo] ([shift={(1,0)}]correct2.r) -- ++(0:10) node[st texto] {r};

  \node[circle,minimum size=4mm,draw=green] (circcorrect2) at (correct2.r) {};
  \node[st texto] (txtcorrect2) at ([shift={(10,-5)}]correct2.r) {
    anchor in\\ the border\\ of the line\\ What I want!
  };
  \draw[-latex,line width=0.1mm] (txtcorrect2) edge[out=90,in=-20] (circcorrect2);

    \end{tikzpicture}

\end{document}

在此处输入图片描述

我查阅了很多例子,但还是不明白。请问有人能帮我吗?提前谢谢!

相关内容