PGF에 대한 학습을 위해 아래와 같이 선택 스위치를 사용하여 다중 포트를 갖는 노드 모양을 만들고 싶습니다.
이것은 특정 개수의 앵커(3개 입력 + 1개 출력)에 대해 이 노드를 생성하려는 시도이며 처음에는 만족스럽습니다.
\documentclass[border=5pt]{standalone}
\usepackage{blindtext}
\usepackage{calc}
\usepackage{ifthen}
\usepackage{tikz}
\usepackage{lipsum}
\usetikzlibrary{calc,shapes,arrows,positioning,patterns,fit,shapes.arrows, fadings,arrows.meta}
\usetikzlibrary{decorations.text}
\usetikzlibrary{decorations.pathmorphing,calc,shadows.blur,shadings, , backgrounds}
\usepackage{circuitikz}
\pgfdeclarelayer{background layer}
\pgfdeclarelayer{foreground layer}
\pgfsetlayers{background,background layer,main,foreground layer}
\makeatletter
\pgfkeys{/tikz/ilength/.initial = 2cm}
\pgfkeys{/tikz/olength/.initial = 2cm}
\pgfkeys{/tikz/hspace/.initial = 1.5cm}
\pgfkeys{/tikz/port length ratio/.initial = 0.2}
\pgfkeys{/tikz/output len to output port ratio/.initial = 0.6}
\pgfkeys{/tikz/select/.initial = 1} %for multiswitch control
\newlength\portlen
\pgfdeclareshape{killer}{
\anchor{center}{\pgfpointorigin}
\anchor{middle}{\pgfpointorigin}
\anchor{text}{\pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}
%-------------------
%----------------------
\savedanchor\kcenter{\pgfpointorigin}
\savedanchor\knorthwest{\pgfpoint{-0.5*\pgfkeysvalueof{/tikz/hspace}}{0.5*\pgfkeysvalueof{/tikz/ilength}}}%
\savedanchor\ksouthwest{\pgfpoint{-0.5*\pgfkeysvalueof{/tikz/hspace}}{-0.5*\pgfkeysvalueof{/tikz/ilength}}}%
\savedanchor\knortheast{\pgfpoint{0.5*\pgfkeysvalueof{/tikz/hspace}}{0.5*\pgfkeysvalueof{/tikz/olength}}}%
\savedanchor\ksoutheast{\pgfpoint{0.5*\pgfkeysvalueof{/tikz/hspace}}{-0.5*\pgfkeysvalueof{/tikz/olength}}}%
\anchor{north west}{\knorthwest}
\anchor{south west}{\ksouthwest}
\anchor{north east}{\knortheast}
\anchor{south east}{\ksoutheast}
\savedanchor\knorth{\pgfpoint{0cm}{0.25*\pgfkeysvalueof{/tikz/ilength}+0.25*\pgfkeysvalueof{/tikz/olength}}}%
\savedanchor\ksouth{\pgfpoint{0cm}{-0.25*\pgfkeysvalueof{/tikz/ilength}-0.25*\pgfkeysvalueof{/tikz/olength}}}%
\savedanchor\keast{\pgfpoint{0.5*\pgfkeysvalueof{/tikz/hspace}}{0cm}}%
\savedanchor\kwest{\pgfpoint{-0.5*\pgfkeysvalueof{/tikz/hspace}}{0cm}}%
\anchor{north}{\knorth}
\anchor{north}{\knorth}
\anchor{east}{\keast}
\anchor{west}{\kwest}
%--------------------------
\savedanchor\porti{\pgfpoint{0.5*\pgfkeysvalueof{/tikz/hspace}}{
0.5*\pgfkeysvalueof{/tikz/olength}*\pgfkeysvalueof{/tikz/output len to output port ratio} - 0*0.5*\pgfkeysvalueof{/tikz/olength}*\pgfkeysvalueof{/tikz/output len to output port ratio}}
}%
\savedanchor\portii{\pgfpoint{0.5*\pgfkeysvalueof{/tikz/hspace}}{
0.5*\pgfkeysvalueof{/tikz/olength}*\pgfkeysvalueof{/tikz/output len to output port ratio} - 1*0.5*\pgfkeysvalueof{/tikz/olength}*\pgfkeysvalueof{/tikz/output len to output port ratio}}
}%
\savedanchor\portiii{\pgfpoint{0.5*\pgfkeysvalueof{/tikz/hspace}}{
0.5*\pgfkeysvalueof{/tikz/olength}*\pgfkeysvalueof{/tikz/output len to output port ratio} - 2*0.5*\pgfkeysvalueof{/tikz/olength}*\pgfkeysvalueof{/tikz/output len to output port ratio}}
}%
\savedanchor\inp{\pgfpoint{-0.5*\pgfkeysvalueof{/tikz/hspace}}{0cm}
}%
\anchor{port 1}{\porti}
\anchor{port 2}{\portii}
\anchor{port 3}{\portiii}
\anchor{input}{\inp}
\backgroundpath{%
%
\pgfpathmoveto{\knorthwest}%
\pgfpathlineto{\ksouthwest}%
\pgfpathlineto{\ksoutheast}%
\pgfpathlineto{\knortheast}%
\pgfpathclose%
%----------------
}
\foregroundpath{
\pgfmathsetlength{\portlen}{\pgfkeysvalueof{/tikz/hspace}*0.5*\pgfkeysvalueof{/tikz/port length ratio}}
\pgfpathmoveto{\inp}
\pgfpathlineto{\inp \advance \pgf@x by \portlen}
\pgfsetarrows{{Stealth[width=1.5mm]}-}
\pgfpathlineto{\pgfpoint{0.5*\pgfkeysvalueof{/tikz/hspace}-\portlen}{
0.5*\pgfkeysvalueof{/tikz/olength}*\pgfkeysvalueof{/tikz/output len to output port ratio} - (\pgfkeysvalueof{/tikz/select}-1)*0.5*\pgfkeysvalueof{/tikz/olength}*\pgfkeysvalueof{/tikz/output len to output port ratio}
}}
\pgfusepath{stroke}
\pgfsetarrows{-}
\pgfpathmoveto{\porti}
\pgfpathlineto{\porti \advance \pgf@x by -\portlen}
\pgfpathmoveto{\portii}
\pgfpathlineto{\portii \advance \pgf@x by -\portlen}
\pgfpathmoveto{\portiii}
\pgfpathlineto{\portiii \advance \pgf@x by -\portlen}
}}
\makeatother
\begin{document}
\begin{tikzpicture}
\node [killer,draw=blue,scale=1, port length ratio=0.4,ilength=1.2cm] (A) {};
\node [killer,draw=blue,fill=green,scale=1,select=3, port length ratio=0.4, left = of A] (B) {};
\end{tikzpicture}
\end{document}
그러나 명령을 사용하기 위해 pgf 매뉴얼을 읽는 데 몇 시간이 걸렸음에도 불구하고 이 노드에 대한 앵커 경계를 그리는 데 실패했습니다. \anchorborder{}
어쩌면 작동 방식을 이해할 수 없었을 수도 있습니다. 어쨌든 앵커 경계 문제를 우회하고 다음 단계는 \pgfkeys{/tikz/number of input ports/.initial = 4}
논리 게이트와 같은 키를 사용하여 입력 포트(앵커) 수를 제어하는 것입니다 . 나는 나에게 혼란스러운 \csname ..... \endcsname
및 같은 명령을 사용하는 것이 종종 필요하다는 것을 알고 \expandafter
있으며 게다가 이미 사용하려고 시도했지만 헛된 것입니다.
마지막으로, 미리 정의된 노드를 사용하는 것을 제외하고 내 코드를 수정하라는 어떠한 제안도 환영합니다.