我想根据“ifpgfckedged”参数定义节点的“最小宽度”。但是这没有正确设置,因为在 \tikzset 期间“ifpgfckedged”检查失败。我在这里附上了代码。
%D Latch
\makeatletter
% Define default text labels inside full adder
\pgfkeys{/pgf/.cd,
latch dff label/.initial=Latch,%
latch d label/.initial=,%
latch q label/.initial=,
latch ck label/.initial=,
latch ck edged/.is if=pgfckedged,%
\tikzset{latch/port labels/.style={font=\sffamily\small}}%
\newif\ifpgfckedged
% D Latch shape
\pgfdeclareshape{dlatch}{%
\savedmacro\operatorparameters{%
\pgfmathsetlengthmacro\minimumwidth{\pgfkeysvalueof{/pgf/minimum width}}%
\pgfmathsetlengthmacro\minimumheight{\pgfkeysvalueof{/pgf/minimum height}}%
\pgfmathsetlengthmacro\spec{max(\minimumwidth , \minimumheight)/8}%
\addtosavedmacro{\spec}%
}%
\savedanchor\northeast{%
\pgfmathsetlength\pgf@x{\pgfshapeminwidth}%
\pgfmathsetlength\pgf@y{\pgfshapeminheight}%
\pgf@x=0.5\pgf@x
\pgf@y=0.5\pgf@y
}
% This is redundant, but makes some things easier:
\savedanchor\southwest{%
\pgfmathsetlength\pgf@x{\pgfshapeminwidth}%
\pgfmathsetlength\pgf@y{\pgfshapeminheight}%
\pgf@x=-0.5\pgf@x
\pgf@y=-0.5\pgf@y
}%
% Inherit from rectangle
\inheritanchorborder[from=rectangle]
% Define same anchor a normal rectangle has
\anchor{center}{\pgfpointorigin}
\anchor{north}{\northeast \pgf@x=0pt}
\anchor{east}{\northeast \pgf@y=0pt}
\anchor{south}{\southwest \pgf@x=0pt}
\anchor{west}{\southwest \pgf@y=0pt}
\anchor{north east}{\northeast}
\anchor{north west}{\northeast \pgf@x=-\pgf@x}
\anchor{south west}{\southwest}
\anchor{south east}{\southwest \pgf@x=-\pgf@x}
\anchor{text}{
\pgfpointorigin
\advance\pgf@x by -.5\wd\pgfnodeparttextbox%
\advance\pgf@y by -.5\ht\pgfnodeparttextbox%
\advance\pgf@y by +.5\dp\pgfnodeparttextbox%
}
\anchor{D}{
\pgf@process{\southwest}%
\operatorparameters%
\pgfmathsetlength\pgf@xa{\spec}
\advance\pgf@x by -\pgf@xa
\pgf@y=0pt%
\pgf@x=\pgf@x%
}
\anchor{CK}{
\pgf@process{\northeast}%
\pgf@x=0\pgf@x%
\pgf@y=1\pgf@y%
}
\anchor{Q}{
\pgf@process{\northeast}%
\operatorparameters%
\pgfmathsetlength\pgf@xa{\spec}
\advance\pgf@x by \pgf@xa
\pgf@y=0\pgf@y%
\pgf@x=\pgf@x%
}
% Draw the rectangle box and the port labels
\backgroundpath{
\operatorparameters%
% Rectangle box
\pgfpathrectanglecorners{\southwest}{\northeast}
\csname pgf@anchor@dlatch@D\endcsname%
\pgf@xa=\pgf@x \pgf@ya=\pgf@y
\pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfmathsetlength\pgf@x{\spec}
\advance\pgf@xb by \pgf@x
\pgfpathmoveto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\csname pgf@anchor@dlatch@CK\endcsname%
\pgf@xa=\pgf@x \pgf@ya=\pgf@y
\pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfmathsetlength\pgf@y{\spec}
\advance\pgf@yb by \pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
% Draw the angle (>) for clock input, if required
\ifpgfckedged%
\csname pgf@anchor@dlatch@CK\endcsname%
\pgf@xa=\pgf@x \pgf@ya=0.5\pgf@yb %Check
\pgf@process{\northeast}%
\pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfpathmoveto{\pgfpoint{\pgf@x}{\pgf@y}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgf@process{\southwest}%
\pgfpathlineto{\pgfpoint{\pgf@x}{\pgf@yb}}
\pgfkeys{
/pgf/minimum width=1.5cm}
\else%
\pgfkeys{
/pgf/minimum width=0.75cm}
\fi%
\csname pgf@anchor@dlatch@Q\endcsname%
\pgf@xa=\pgf@x \pgf@ya=\pgf@y
\pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfmathsetlength\pgf@x{\spec}
\advance\pgf@xb by -\pgf@x
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
% Draw port labels
\pgfusepath{stroke}
}
\foregroundpath{
{
\operatorparameters%
% Draw port labels
\begingroup
\tikzset{latch/port labels} % Use font from this style
\tikz@textfont%
\pgf@anchor@dlatch@center%
\pgftext[rotate=90,base,at={\pgfpoint{0\pgf@x}{0\pgf@y}}]{%
\raisebox{-0.5ex}{
\pgfkeysvalueof{/pgf/latch dff label}
}%
}
\pgf@anchor@dlatch@D%
\pgftext[left,base,at={\pgfpoint{\pgf@x+\spec+\radius}{\pgf@y}}]{%
\raisebox{-.5ex}{\pgfkeysvalueof{/pgf/latch d label}}%
}%
\pgf@anchor@dlatch@CK%
\pgftext[left,base,at={\pgfpoint{\pgf@x+\spec+\radius}{\pgf@y}}]{%
\raisebox{-.5ex}{\pgfkeysvalueof{/pgf/latch ck label}}%
}%
\pgf@anchor@dlatch@Q%
\pgftext[right,base,at={\pgfpoint{\pgf@x-\spec-\radius}{\pgf@y}}]{%
\raisebox{-.5ex}{\pgfkeysvalueof{/pgf/latch q label}}%
}%
\endgroup
}%
}%
}%
\tikzset{add font/.code={\expandafter\def\expandafter\tikz@textfont\expandafter{\tikz@textfont#1}}}
\tikzset{every dlatch node/.style={draw,minimum height=2cm,inner sep=1mm,outer sep=0pt,cap=round,add font=\sffamily}}
\ifpgfckedged%
\tikzset{every dlatch node/.append style={minimum width=1.5cm}}
\else%
\tikzset{every dlatch node/.append style={minimum width=0.75cm}}
\fi%
\makeatother
我缩短了代码以突出我的要求:
%D Latch
\makeatletter
% Define default text labels inside full adder
\pgfkeys{/pgf/.cd,
latch dff label/.initial=Latch,%
latch d label/.initial=,%
latch q label/.initial=,
latch ck label/.initial=,
latch ck edged/.is if=pgfckedged,%
\tikzset{latch/port labels/.style={font=\sffamily\small}}%
\newif\ifpgfckedged
% D Latch shape
\pgfdeclareshape{dlatch}{%
%.....
}
\ifpgfckedged%
\tikzset{every dlatch node/.append style={minimum width=1.5cm}}
\else%
\tikzset{every dlatch node/.append style={minimum width=0.75cm}}
\fi%
\makeatother
当我尝试调用节点时,最小宽度规范未设置
\begin{tikzpicture}
\draw(0,0)node[latch ck edged, dlatch, anchor=CK]{};
\end{tikzpicture}
注意:“latch ck edged”是调用“ifpgfckedged”的参数。