使用 circuitikz 绘制跳线/针头/桥接器

使用 circuitikz 绘制跳线/针头/桥接器

如何使用 circuitikz 绘制跳线/针头/桥?查看 kicad 中的跳线

答案1

更新在我改变主意之后,我也添加焊接跳线;它们将会出现在 1.6.1 中。

实施跳线;在我看来,焊接跳线更多的是 PCB 符号而不是电路符号(描述功能而不是形状;跳线的实现可以是焊接跳线或引脚跳线,但功能是相同的。如果您愿意,可以使用不同类型的极点来区分这两者,例如引脚跳线使用开口极点,而焊接型使用填充极点,可能更小。)。

它们将在下一版本中出现;同时,你可以使用它们添加此加载(非常)最近的circuitikz

\makeatletter
\ctikzset{bipoles/jumper/width/.initial=0.4}
\ctikzset{bipoles/tjumper/width/.initial=0.6}% normally is less than 0.4*2
\ctikzset{tjumper connections/.initial=00}% bare-bare
\ctikzset{bipoles/jumper/height/.initial=0.4}
\ctikzset{bipoles/jumper/depth/.initial=0.1}
\ctikzset{bipoles/jumper/shape/.initial=ocirc}
\ctikzset{bipoles/jumper/curvature/.initial=2}  % curvature of the arc
\ctikzset{bipoles/jumper/open shift/.initial=3} % displacement to open the arc

% jumpers
% simple jumpers
% #1 -> name
% #2 -> height of the link arc (0 means no link, 1 closed, 2 open)
\long\def\pgfcircdeclarejumper#1#2{
    \pgfcircdeclarebipolescaled{switches}
        {
            % This is the radius of the "ocirc" shape (see pgfcircshapes.tex)
            \saveddimen{\radius}{\pgfmathsetlength\pgf@x{\pgf@circ@Rlen*\ctikzvalof{nodes width}}}
            % shapename
            \savedmacro{\thisshape}{\edef\thisshape{\tikz@fig@name}}
            % shape type
            \savedmacro{\cshape}{\edef\cshape{\ctikzvalof{bipoles/jumper/shape}}}
            % arc characteristics (can vary, must be saved...)
            \savedmacro{\curvature}{\edef\curvature{\ctikzvalof{bipoles/jumper/curvature}}}
            \savedmacro{\openshift}{\edef\openshift{\ctikzvalof{bipoles/jumper/open shift}}}
            %
            \anchor{cout}{\northeast \pgf@y=0cm}
            \anchor{cin}{\southwest\pgf@y=0cm}
            \anchor{out}{\northeast \pgf@y=0cm\advance\pgf@x by \radius}
            \anchor{in}{\southwest\pgf@y=0cm\advance\pgf@x by -\radius}
            \anchor{text}{\northeast
                \pgf@x=\dimexpr -.5\wd\pgfnodeparttextbox\relax
                \advance\pgf@y by .6\ht\pgfnodeparttextbox\relax
            }
            \anchor{top arc}{\northeast
                \pgf@circ@res@other=\pgf@x
                \pgf@circ@res@temp=\radius
                \ifnum #2=1 \edef\@@b{1}\else\edef\@@b{\openshift}\fi
                \pgfpointcurveattime{0.5}
                    {\pgfpoint{-0.9\pgf@circ@res@other}{{(\@@b)*\radius}}}
                    {\pgfpoint{-0.5\pgf@circ@res@other}{{(\@@b+\curvature)*\radius}}}
                    {\pgfpoint{0.5\pgf@circ@res@other}{{(\@@b+\curvature)*\radius}}}
                    {\pgfpoint{0.9\pgf@circ@res@other}{{(\@@b)*\radius}}}
            }
        }
        {\ctikzvalof{bipoles/jumper/depth}}
        {#1}
        {\ctikzvalof{bipoles/jumper/height}}
        {\ctikzvalof{bipoles/jumper/width}}{
            %
            \ifnum #2=0 \else
                \ifnum #2=1 \edef\@@b{1}\else\edef\@@b{\openshift}\fi
                \pgfpathmoveto{\pgfpoint{0.9*\pgf@circ@res@left}{(\@@b)*\radius}}
                \pgfpathcurveto
                    {\pgfpoint{.5\pgf@circ@res@left}{(\@@b+\curvature)*\radius}}
                    {\pgfpoint{.5\pgf@circ@res@right}{(\@@b+\curvature)*\radius}}
                    {\pgfpoint{0.9*\pgf@circ@res@right}{(\@@b)*\radius}}
                \pgfusepath{draw}
            \fi
            \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
            \pgfnode{\cshape}{center}{}{\thisshape-in}{\pgfusepath{draw}}
            \pgftransformshift{\pgfpoint{2\pgf@circ@res@right}{0pt}}
            \pgfnode{\cshape}{center}{}{\thisshape-out}{\pgfusepath{draw}}
        }
}
\pgfcircdeclarejumper{bjumper}{0}
\pgfcircdeclarejumper{cjumper}{1}
\pgfcircdeclarejumper{ojumper}{2}
\pgfcirc@activate@bipole{l}{bjumper}{bjumper}{bare jumper}
\pgfcirc@activate@bipole{l}{ojumper}{ojumper}{open jumper}
\pgfcirc@activate@bipole{l}{cjumper}{cjumper}{closed jumper}
% jumpers
% three pins (two-ways) jumpers
% #1 -> name
% #2 -> height of the first link arc (0 means no link, 1 closed, 2 open)
% #3 -> height of the second link arc (0 means no link, 1 closed, 2 open)
\def\pgf@circ@tjumper@splitstatus#1#2\relax{%split the two values
    \edef\@@a{#1}\edef\@@b{#2}%
}
\pgfcircdeclarebipolescaled{switches}
    {
        % This is the radius of the "ocirc" shape (see pgfcircshapes.tex)
        \saveddimen{\radius}{\pgfmathsetlength\pgf@x{\pgf@circ@Rlen*\ctikzvalof{nodes width}}}
        % shapename
        \savedmacro{\thisshape}{\def\thisshape{\tikz@fig@name}}
        % shape type
        \savedmacro{\cshape}{\def\cshape{\ctikzvalof{bipoles/jumper/shape}}}
        % arc characteristics (can vary, must be saved...)
        \savedmacro{\curvature}{\edef\curvature{\ctikzvalof{bipoles/jumper/curvature}}}
        \savedmacro{\openshift}{\edef\openshift{\ctikzvalof{bipoles/jumper/open shift}}}
        \savedmacro{\jumpertype}{\edef\jumpertype{\ctikzvalof{tjumper connections}}}
        %
        \anchor{cout}{\northeast \pgf@y=0cm}
        \anchor{cin}{\southwest\pgf@y=0cm}
        \anchor{ctap}{\pgf@x=0cm\pgf@y=0cm}
        \anchor{out}{\northeast \pgf@y=0cm\advance\pgf@x by \radius}
        \anchor{in}{\southwest\pgf@y=0cm\advance\pgf@x by -\radius}
        \anchor{tap}{\pgf@x=0cm\pgf@y=0cm\advance\pgf@y by -\radius}
        \anchor{top arc left}{\northeast
            \pgf@circ@res@other=-\pgf@x
            \pgf@circ@res@temp=\pgf@x
            %
            % read the status of the jumper
            %
            \expandafter\pgf@circ@tjumper@splitstatus\jumpertype\relax% a bit of magic...
            \edef\@@S{S}%the "S" letter
            \ifx\@@a\@@S %span, it's in the center
                \ifnum \@@b=0\pgfpointorigin\else % no arc, anchor on the center-base
                    \ifnum \@@b=2 \edef\@@b{\openshift} \else \edef\@bb{1}\relax \fi
                    \pgfpointcurveattime{0.5}
                        {\pgfpoint{0.9*\pgf@circ@res@other}{(\@@b)*\radius}}
                        {\pgfpoint{.5*\pgf@circ@res@other}{(\@@b+\curvature)*\radius}}
                        {\pgfpoint{.5*\pgf@circ@res@temp}{(\@@b+\curvature)*\radius}}
                        {\pgfpoint{0.9*\pgf@circ@res@temp}{(\@@b)*\radius}}
                \fi
            \else
                % adjust the lengths of the gap, if needed
                \ifnum \@@a=2 \edef\@@a{\openshift} \else \edef\@aa{1} \relax \fi
                \ifnum \@@b=2 \edef\@@b{\openshift} \else \edef\@bb{1} \relax \fi
                % left join
                \ifnum \@@a=0 \pgfpoint{0.475*\pgf@circ@res@other}{0pt}\else
                    \pgfpointcurveattime{0.5}
                        {\pgfpoint{0.95*\pgf@circ@res@other}{\@@a*\radius}}
                        {\pgfpoint{.75*\pgf@circ@res@other}{(\@@a+\curvature)*\radius}}
                        {\pgfpoint{.25*\pgf@circ@res@other}{(\@@a+\curvature)*\radius}}
                        {\pgfpoint{0.05*\pgf@circ@res@other}{\@@a*\radius}}
                \fi
            \fi
        }
        \anchor{top arc right}{\northeast
            \pgf@circ@res@other=-\pgf@x
            \pgf@circ@res@temp=\pgf@x
            %
            % read the status of the jumper
            %
            \expandafter\pgf@circ@tjumper@splitstatus\jumpertype\relax% a bit of magic...
            \edef\@@S{S}%the "S" letter
            \ifx\@@a\@@S %span, it's in the center
                \ifnum \@@b=0\pgfpointorigin\else % no arc, anchor on the center-base
                    \ifnum \@@b=2 \edef\@@b{\openshift} \else \edef\@bb{1}\relax \fi
                    \pgfpointcurveattime{0.5}
                        {\pgfpoint{0.9*\pgf@circ@res@other}{(\@@b)*\radius}}
                        {\pgfpoint{.5*\pgf@circ@res@other}{(\@@b+\curvature)*\radius}}
                        {\pgfpoint{.5*\pgf@circ@res@temp}{(\@@b+\curvature)*\radius}}
                        {\pgfpoint{0.9*\pgf@circ@res@temp}{(\@@b)*\radius}}
                \fi
            \else
                % adjust the lengths of the gap, if needed
                \ifnum \@@a=2 \edef\@@a{\openshift} \else \edef\@aa{1} \relax \fi
                \ifnum \@@b=2 \edef\@@b{\openshift} \else \edef\@bb{1} \relax \fi
                % right join
                \ifnum \@@b=0 \pgfpoint{0.475*\pgf@circ@res@temp}{0pt}\else
                    \pgfpointcurveattime{0.5}
                        {\pgfpoint{0.95*\pgf@circ@res@temp}{\@@b*\radius}}
                        {\pgfpoint{.75\pgf@circ@res@temp}{(\@@b+\curvature)*\radius}}
                        {\pgfpoint{.25\pgf@circ@res@temp}{(\@@b+\curvature)*\radius}}
                        {\pgfpoint{0.05*\pgf@circ@res@temp}{\@@b*\radius}}
                \fi
            \fi
        }
    }
    {\ctikzvalof{bipoles/jumper/depth}}
    {tjumper}
    {\ctikzvalof{bipoles/jumper/height}}
    {\ctikzvalof{bipoles/tjumper/width}}{
        %
        % read the status of the jumper
        %
        \expandafter\pgf@circ@tjumper@splitstatus\jumpertype\relax% a bit of magic...
        \edef\@@S{S}%the "S" letter
        \ifx\@@a\@@S %span
            \ifnum \@@b=0 \else
                \ifnum \@@b=2 \edef\@@b{\openshift} \else \edef\@bb{1}\relax \fi
                \pgfpathmoveto{\pgfpoint{0.9*\pgf@circ@res@left}{(\@@b)*\radius}}
                \pgfpathcurveto
                    {\pgfpoint{.5\pgf@circ@res@left}{(\@@b+\curvature)*\radius}}
                    {\pgfpoint{.5\pgf@circ@res@right}{(\@@b+\curvature)*\radius}}
                    {\pgfpoint{0.9*\pgf@circ@res@right}{(\@@b)*\radius}}
                \pgfusepath{draw}
            \fi
        \else
        % let's do the connection, if needed
            % adjust the lengths of the gap, if needed
            \ifnum \@@a=2 \edef\@@a{\openshift} \else \edef\@aa{1} \relax \fi
            \ifnum \@@b=2 \edef\@@b{\openshift} \else \edef\@bb{1} \relax \fi
            % left arc
            \ifnum \@@a=0 \else
                \pgfpathmoveto{\pgfpoint{0.95*\pgf@circ@res@left}{\@@a*\radius}}
                \pgfpathcurveto
                    {\pgfpoint{.75\pgf@circ@res@left}{(\@@a+\curvature)*\radius}}
                    {\pgfpoint{.25\pgf@circ@res@left}{(\@@a+\curvature)*\radius}}
                    {\pgfpoint{0.05*\pgf@circ@res@left}{\@@a*\radius}}
                \pgfusepath{draw}
            \fi
            % right arc
            \ifnum \@@b=0 \else
                \pgfpathmoveto{\pgfpoint{0.95*\pgf@circ@res@right}{\@@b*\radius}}
                \pgfpathcurveto
                    {\pgfpoint{.75\pgf@circ@res@right}{(\@@b+\curvature)*\radius}}
                    {\pgfpoint{.25\pgf@circ@res@right}{(\@@b+\curvature)*\radius}}
                    {\pgfpoint{0.05*\pgf@circ@res@right}{\@@b*\radius}}
                \pgfusepath{draw}
            \fi
        \fi
        % draw the poles (always filled!)
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfnode{\cshape}{center}{}{\thisshape-in}{\pgfusepath{draw}}
        \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfnode{\cshape}{center}{}{\thisshape-tap}{\pgfusepath{draw}}
        \pgftransformshift{\pgfpoint{\pgf@circ@res@right}{0pt}}
        \pgfnode{\cshape}{center}{}{\thisshape-out}{\pgfusepath{draw}}
    }

\pgfcirc@activate@bipole{l}{tjumper}{tjumper}{three-pins jumper}

\makeatother

相关内容