如何改进PGF中数字电路的创建?

如何改进PGF中数字电路的创建?

我目前正在设计一个硬件,并希望将其记录在 Latex 文档中。幸运的是,有circuitikzpgf可以使用。我感兴趣的构建块不包含在内,circuitikz所以我决定遵循创建多极组件的指南这里。以下是我已经画好的方块:在此处输入图片描述

以下是解码器的代码示例:

\usepackage{tikz}
\usepackage{circuitikz}

\usetikzlibrary{calc,positioning,shapes.misc}

\tikzstyle{bus} = [near end, rotate=-110, strike out, draw, scale=0.6]
\def \busx {0.5pt}
\def \busy {2.5pt}

% ---------------
% Decoder
% ---------------
\pgfpoint{-1.8cm}{-1.0cm}
\pgfgetlastxy{\xdcsub}{\ydcsub}
\pgfpoint{-1.4cm}{-1.0cm}
\pgfgetlastxy{\xdcand}{\ydcand}
\pgfpoint{-1.0cm}{-1.0cm}
\pgfgetlastxy{\xdcor}{\ydcor}
\pgfpoint{-0.6cm}{-1.0cm}
\pgfgetlastxy{\xdcxor}{\ydcxor}
\pgfpoint{-0.2cm}{-1.0cm}
\pgfgetlastxy{\xdcnot}{\ydcnot}

\pgfpoint{0.2cm}{-1.0cm}
\pgfgetlastxy{\xdcdir}{\ydcdir}
\pgfpoint{0.6cm}{-1.0cm}
\pgfgetlastxy{\xdcrot}{\ydcrot}
\pgfpoint{1.0cm}{-1.0cm}
\pgfgetlastxy{\xdcar}{\ydcar}
\pgfpoint{1.4cm}{-1.0cm}
\pgfgetlastxy{\xdcmul}{\ydcmul}
\pgfpoint{1.8cm}{-1.0cm}
\pgfgetlastxy{\xdcop}{\ydcop}

\pgfpoint{0cm}{1.0cm}
\pgfgetlastxy{\xinop}{\yinop}

\pgfdeclareshape{decoder}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
\inheritanchor[from=rectangle]{north west}
\inheritanchor[from=rectangle]{south east}
\inheritanchor[from=rectangle]{south west}
\inheritanchor[from=rectangle]{north east}
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{base}
\inheritanchor[from=rectangle]{base east}
\inheritanchor[from=rectangle]{base west}
\inheritanchor[from=rectangle]{mid}
\inheritanchor[from=rectangle]{mid east}
\inheritanchor[from=rectangle]{mid west}
\anchor{center}{\pgfpointorigin}

\savedanchor\pindcsub{\pgfpoint{\xdcsub}{\ydcsub - 0.5cm}}
\anchor{sub}{\pindcsub}
\savedanchor\pindcand{\pgfpoint{\xdcand}{\ydcand - 0.5cm}}
\anchor{and}{\pindcand}
\savedanchor\pindcor{\pgfpoint{\xdcor}{\ydcor - 0.5cm}}
\anchor{or}{\pindcor}
\savedanchor\pindcxor{\pgfpoint{\xdcxor}{\ydcxor - 0.5cm}}
\anchor{xor}{\pindcxor}
\savedanchor\pindcnot{\pgfpoint{\xdcnot}{\ydcnot - 0.5cm}}
\anchor{not}{\pindcnot}
\savedanchor\pindcdir{\pgfpoint{\xdcdir}{\ydcdir - 0.5cm}}
\anchor{dir}{\pindcdir}
\savedanchor\pindcrot{\pgfpoint{\xdcrot}{\ydcrot - 0.5cm}}
\anchor{rot}{\pindcrot}
\savedanchor\pindcar{\pgfpoint{\xdcar}{\ydcar - 0.5cm}}
\anchor{ar}{\pindcar}
\savedanchor\pindcmul{\pgfpoint{\xdcmul}{\ydcmul - 0.5cm}}
\anchor{mul}{\pindcmul}
\savedanchor\pindcop{\pgfpoint{\xdcop}{\ydcop - 0.5cm}}
\anchor{s}{\pindcop}

\savedanchor\piniop{\pgfpoint{\xinop}{\yinop + 0.5cm}}
\anchor{iop}{\piniop}

\foregroundpath{
    \pgfsetlinewidth{0.8pt}
    \pgfpathrectanglecorners{\pgfpoint{2.2cm}{1.0cm}}{\pgfpoint{-2.2cm}{-1.0cm}}
    \pgfusepath{draw}

    \pgfsetlinewidth{0.4pt}
    {\fontfamily{phv}\selectfont
    \pgftext[at={\pgfpointorigin}]{\large Decoder}

    \pgftext[top,at={\pgfpoint{\xinop - 0.1cm}{\yinop - 0.3cm}},rotate=90]{\scriptsize OP}
    \draw[line width=1pt] (\xinop,\yinop) -- node[bus,rotate=90] (bus) {} ++(0,0.5cm);
    \node[circle] at ($(bus.west)+(\busx-2pt,\busy-8pt)$) {\tiny 5};

    \pgftext[bottom,at={\pgfpoint{\xdcsub + 0.1cm}{\ydcsub + 0.3cm}},rotate=90]{\scriptsize SUB}
    \draw (\xdcsub,\ydcsub) -- ++(0,-0.5cm);

    \pgftext[bottom,at={\pgfpoint{\xdcand + 0.1cm}{\ydcand + 0.3cm}},rotate=90]{\scriptsize AND}
    \draw (\xdcand,\ydcand) -- ++(0,-0.5cm);

    \pgftext[bottom,at={\pgfpoint{\xdcor + 0.1cm}{\ydcor + 0.3cm}},rotate=90]{\scriptsize OR}
    \draw (\xdcor,\ydcor) -- ++(0,-0.5cm);

    \pgftext[bottom,at={\pgfpoint{\xdcxor + 0.1cm}{\ydcxor + 0.3cm}},rotate=90]{\scriptsize XOR}
    \draw (\xdcxor,\ydcxor) -- ++(0,-0.5cm);

    \pgftext[bottom,at={\pgfpoint{\xdcnot + 0.1cm}{\ydcnot + 0.3cm}},rotate=90]{\scriptsize NOT}
    \draw (\xdcnot,\ydcnot) -- ++(0,-0.5cm);

    \pgftext[bottom,at={\pgfpoint{\xdcdir + 0.1cm}{\ydcdir + 0.3cm}},rotate=90]{\scriptsize DIR}
    \draw (\xdcdir,\ydcdir) -- ++(0,-0.5cm);

    \pgftext[bottom,at={\pgfpoint{\xdcrot + 0.1cm}{\ydcrot + 0.3cm}},rotate=90]{\scriptsize ROT}
    \draw (\xdcrot,\ydcrot) -- ++(0,-0.5cm);

    \pgftext[bottom,at={\pgfpoint{\xdcar + 0.1cm}{\ydcar + 0.3cm}},rotate=90]{\scriptsize AR}
    \draw (\xdcar,\ydcar) -- ++(0,-0.5cm);

    \pgftext[bottom,at={\pgfpoint{\xdcmul + 0.1cm}{\ydcmul + 0.3cm}},rotate=90]{\scriptsize MUL}
    \draw (\xdcmul,\ydcmul) -- ++(0,-0.5cm);

    \pgftext[bottom,at={\pgfpoint{\xdcop + 0.1cm}{\ydcop + 0.3cm}},rotate=90]{\scriptsize RES}
    \draw[line width=1pt] (\xdcop,\ydcop) -- node[bus,rotate=90] (bus) {} ++(0,-0.5cm);
    \node[circle] at ($(bus.west)+(-\busx-2pt,\busy)$) {\tiny 3};
    }
}
}

其他的也有类似的结构。我现在想知道是否有一种更简洁/更自动化的方式来创建这些块,因为它们的制作极其耗时。

相关内容