如何在 TikZ-circuits.ee.IEC 符号中获取可选参数?

如何在 TikZ-circuits.ee.IEC 符号中获取可选参数?

晚上好,

因此在下面的代码中,我有“新的”电路符号,名为“转换器”。

简而言之:我使用“通用圆圈”,但我没有向他展示;我在其上画了一个 pgf 矩形,至少画了一条“十字线”。我不知道这是否是获得这样的电路符号的最佳方法,但我没有更好的想法来绘制它(没有“通用矩形”)。

好的,第二个是关键字‘change’,它改变了两个文本标签(图中:“AC”<--->“DC”)。

所以我的问题是

我希望将符号内的文本作为可选参数,例如

  • 转换器={x}{abc}

  • 转换器={AC}{DC},如图所示。

但我不知道如何进行编程。

你有什么想法吗?(你对总体改进有什么建议吗?)

感谢您的阅读和关注。

在此处输入图片描述

\documentclass[margin=5mm, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}

\usepackage{amsmath, amssymb}

%CIRCUIT SYMBOL converter %%%%%%%%%%%%%%%%%
\newif\ifchange
\tikzoption{change}[true]{\changetrue}

\tikzset{circuit declare symbol = converter}
\tikzset{set converter graphic = converter IEC graphic}
\tikzset{converter IEC graphic/.style=
  {transform shape, circuit symbol lines, circuit symbol size = width
2.5 height 2.5, draw=none, rounded corners=2.25pt,
   shape=generic circle IEC, /pgf/generic circle IEC/before
background=
    {
     %CROSSLINE
     \pgfpathmoveto{\pgfpoint{-0.8pt}{-0.8pt}}
     \pgfpathlineto{\pgfpoint{0.8pt}{0.8pt}}
     %RECTNAGLE
    \pgfpathrectangle{\pgfpoint{-1pt}{-1pt}}{\pgfpoint{2.0pt}{2.0pt}}
     \pgfusepath{stroke} 
     \pgfusepathqstroke %?
     % TEXT INSIDE THE SYMBOL
     \pgfgettransform\savedtransform
     \pgftransformshift{\pgfpoint{0.45pt}{-0.45pt}}
     \pgftransformresetnontranslations
     \pgftransformscale{0.075\tikzcircuitssizeunit}
     \pgftext{\bf{\ifchange{DC}\else{AC}\fi}}
     \pgfsettransform\savedtransform
     \pgftransformshift{\pgfpoint{-0.45pt}{0.45pt}}
     \pgftransformresetnontranslations
     \pgftransformscale{0.075\tikzcircuitssizeunit}
     \pgftext{\bf{\ifchange{AC}\else{DC}\fi}}
     \pgfsettransform\savedtransform
     }}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%===========
\begin{document}
%===========

\begin{tikzpicture}[circuit ee IEC, font=\sffamily\footnotesize]
%converter
\draw (0,0) to [converter={info'={converter}, info={Text}}] (2,0);
%converter - Polaritätsumkehr
\draw (0,2) to [converter={info={converter, change}}, change] (2,2);

%huge/ small
\draw (3,0) to [converter={info'={huge}},change,huge circuit symbols] (5,0);
\draw (3,1) to [converter={info={small}},change,small circuit symbols] (5,1);

%upside 1
\draw (7,0) to [converter] (7,2);
%upside 2
\draw (8,2) to [converter] (8,0);
%crossed
\draw (9,0) to [converter={info' sloped={3.5V$_{\_}$}, info sloped={5V$_{\sim}$}}, change] (11,2);
%crossed 2
\draw (13,2) to [converter, change] (11,0);

\end{tikzpicture}
%===========
\end{document}
%===========

答案1

我将“更改”替换为“从...转换”和“转换为...转换”。

\documentclass[margin=5mm, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{circuits.ee.IEC}

\usepackage{amsmath, amssymb}

%CIRCUIT SYMBOL converter %%%%%%%%%%%%%%%%%
\tikzset{circuit declare symbol = converter}
\tikzset{set converter graphic = converter IEC graphic}
\tikzset{convert from/.initial=AC,
         convert from/.default=AC,
         convert to/.initial=DC,
         convert to/.default=DC}
\tikzset{converter IEC graphic/.style=
  {transform shape, circuit symbol lines, circuit symbol size = width
2.5 height 2.5, draw=none, rounded corners=2.25pt,
   shape=generic circle IEC, /pgf/generic circle IEC/before
background=
    {
     %CROSSLINE
     \pgfpathmoveto{\pgfpoint{-0.8pt}{-0.8pt}}
     \pgfpathlineto{\pgfpoint{0.8pt}{0.8pt}}
     %RECTNAGLE
     \pgfpathrectangle{\pgfpoint{-1pt}{-1pt}}{\pgfpoint{2.0pt}{2.0pt}}
     \pgfusepath{stroke} 
     \pgfusepathqstroke %?
     % TEXT INSIDE THE SYMBOL
     \pgfgettransform\savedtransform
     \pgftransformshift{\pgfpoint{0.45pt}{-0.45pt}}
     \pgftransformresetnontranslations
     \pgftransformscale{0.075\tikzcircuitssizeunit}
     \pgftext{\bf{\pgfkeysvalueof{/tikz/convert to}}}
     \pgfsettransform\savedtransform
     \pgftransformshift{\pgfpoint{-0.45pt}{0.45pt}}
     \pgftransformresetnontranslations
     \pgftransformscale{0.075\tikzcircuitssizeunit}
     \pgftext{\bf{\pgfkeysvalueof{/tikz/convert from}}}
     \pgfsettransform\savedtransform
     }}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%===========
\begin{document}
%===========

\begin{tikzpicture}[circuit ee IEC, font=\sffamily\footnotesize]
%converter
\draw (0,0) to [converter={info'={converter AC$\rightarrow$DC}, info={Text},
  convert from={AC}, convert to={DC}}] (2,0);
%converter - Polaritätsumkehr
\draw (0,2) to [converter={info={converter DC$\rightarrow$AC},
  convert from={DC}, convert to={AC}}] (2,2);

%huge/ small
\draw (3,0) to [converter={info'={huge}, convert from={DC}, convert to={AC}},
  huge circuit symbols] (5,0);
\draw (3,1) to [converter={info={small}, convert from={DC}, convert to={AC}},
  small circuit symbols] (5,1);

%upside 1
\draw (7,0) to [converter] (7,2);
%upside 2
\draw (8,2) to [converter] (8,0);
%crossed
\draw (9,0) to [converter={info' sloped={3.5V$_{\_}$}, info sloped={5V$_{\sim}$},
  convert from={DC}, convert to={AC}}] (11,2);
%crossed 2
\draw (13,2) to [converter={convert from={DC}, convert to={AC}}] (11,0);

\end{tikzpicture}
%===========
\end{document}
%===========

转换器

相关内容