更改 TikZ 电路库中的接触图形并添加关闭选项

更改 TikZ 电路库中的接触图形并添加关闭选项

var make contact是否可以从如下方式更改符号的外观TikZ circuit library(即添加第二个圆圈)并添加“关闭”选项,如下面的(手工制作)图片所示:

制作联系图形

答案1

最简单的方法是从库中复制形状的定义并进行修改以满足您的需要。所讨论的库是pgflibraryshapes.gates.ee.IEC.code.tex(针对 IEC 版本)。那里有不同形状的形状定义,您可以简单地将要修改的形状复制到您自己的文件中并在那里进行修改。您只需将声明的形状的名称更改为您想要的名称,然后只需修改即可\backgroundpath。默认值\backgroundpath如下:

\backgroundpath{
\pgf@process{\pgfpointadd{\northeast}{
    \pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgf@xa=-\pgf@x \pgf@ya=0pt
\pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@xc=\pgf@xa
\pgfutil@tempdima=2\pgf@xb%
\pgfutil@tempdima=0.083333\pgfutil@tempdima%
\advance\pgf@xa by \pgfutil@tempdima
% Circle
{\pgfpathcircle{\pgfqpoint{\pgf@xa}{0pt}}{\pgfutil@tempdima}}
% Height
% Start point
\pgf@process{\pgfpointnormalised{\pgfpointdiff{\pgfqpoint{\pgf@xa}{0pt}}{\pgfqpoint{\pgf@xb}{\pgf@yb}}}}
\pgf@xc=\pgf@x
\pgf@yc=\pgf@y
\pgfpathmoveto{\pgfpointadd{\pgfqpoint{\pgf@xa}{0pt}}{%
    \pgfpointscale{\pgfutil@tempdima}{\pgfqpoint{\pgf@xc}{\pgf@yc}}}}
\pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
}

为了得到最后的圆圈,请{\pgfpathcircle{\pgfqpoint{\pgf@xb}{0pt}}{\pgfutil@tempdima}}在最后添加。

要获取封闭版本,请将\pgf@yb中的更改\pgfpathlineto\pgfutil@tempdima。确保将定义包装在 中\makeatletter ... \makeatother

编辑:我没有充分测试它,锚点需要一些更新才能在路径中正常工作。我们添加的圆圈会影响右边框。我们可以做一些小调整让它再次工作。请注意,原始边框已经是一个矩形,因此不是一个完全正确的边框。不过,这种对象用于直线路径,所以只要矩形大小合适,使用它作为边框就不是什么大问题。有一些修改,所以我只添加完整的形状定义。

\pgfdeclareshape{var make open contact IEC}
{
  \savedanchor\northeast{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgf@x=\pgf@xa%
    \advance\pgf@x by .5\pgf@xb%
    \pgf@xc=\pgf@x%
    \advance\pgf@xc by\pgf@xa%
    \pgfutil@tempdima=2\pgf@xc%
    \pgfutil@tempdima=0.083333\pgfutil@tempdima%
    \advance\pgf@x by\pgfutil@tempdima%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}%
    \pgf@y=\pgf@ya%
    \advance\pgf@y by\pgf@yb%
    \advance\pgf@y by\pgfutil@tempdima%
  }
  \savedanchor\southwest{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgf@x=-.5\pgf@xa%
    \advance\pgf@x by -.5\pgf@xb%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgf@y=-\pgf@ya%
    \pgf@xc=0.083333\pgf@x%
    \advance\pgf@y by\pgf@xc%
  }

  \anchor{center}{\pgfpointorigin}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}

  \anchorborder{%
    \ifdim\pgf@y<0pt%
      % tricky... simpilfy to the origin...
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \pgf@process{\southwest}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y
    \pgf@process{\pgfpointborderrectangle{\pgfqpoint{\pgf@xc}{\the\pgf@yc}}{\pgfqpoint{-\pgf@xa}{-\pgf@ya}}}%
    \else%
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \pgf@process{\pgfpointborderrectangle{\pgfqpoint{\pgf@xc}{\the\pgf@yc}}{\northeast}}%
    \fi%
  }

  \backgroundpath{ \pgf@process{\pgfpointadd{\northeast}{
        \pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer
              xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xa=-\pgf@x \pgf@ya=0pt \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgf@xc=\pgf@xa \pgfutil@tempdima=2\pgf@xb%
    \pgfutil@tempdima=0.083333\pgfutil@tempdima%
    \advance\pgf@xa by \pgfutil@tempdima
    \advance\pgf@xb by-\pgfutil@tempdima
    % Circle
    {\pgfpathcircle{\pgfqpoint{\pgf@xa}{0pt}}{\pgfutil@tempdima}}
    % Height
    % Start point
    \pgf@process{\pgfpointnormalised{\pgfpointdiff{\pgfqpoint{\pgf@xa}{0pt}}{\pgfqpoint{\pgf@xb}{\pgf@yb}}}}
    \pgf@xc=\pgf@x
    \pgf@yc=\pgf@y
    \pgfpathmoveto{\pgfpointadd{\pgfqpoint{\pgf@xa}{0pt}}{%
        \pgfpointscale{\pgfutil@tempdima}{\pgfqpoint{\pgf@xc}{\pgf@yc}}}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
    {\pgfpathcircle{\pgfqpoint{\pgf@xb}{0pt}}{\pgfutil@tempdima}}
  }
}

这是开放版本,您可以更改\pgfpathlineto之前讨论的内容以获取封闭版本。

相关内容