如何从图片内的锚节点绘制线段?

如何从图片内的锚节点绘制线段?

我试图从可配置对象(构造为 TikZ 图片)内的锚节点绘制一条线,但不起作用。对此有解释和解决方案吗?

\documentclass[10pt]{standalone}
\usepackage[siunitx,american, RPvoltages]{circuitikz}  

\begin{document}
% --- Manômetro ---------------------
\tikzset{pics/manometer/.style={code={
      \tikzset{manometer/.cd,#1}
      \def\pv##1{\pgfkeysvalueof{/tikz/manometer/##1}}% local object variable
      %------------------------------
%--- case
  \filldraw [thin,fill=\pv{case color}, opacity=0.95] (0,0) circle (2.05cm); 
  \draw [semithick, white,opacity=0.95] (0,0) circle (1.85cm); 
% --- Tubo de Bourdon interno
  \pv{bourdon}[double=white, line width=0.5pt,double distance=2mm,opacity=0.95, rounded corners, cap=round] (-90:1.95) --++(90:0.5) arc(270:20:1.4cm) coordinate(ptb);

  \pv{bourdon}(ptb) -- (0,0);
  \filldraw[black,thin,fill=white, opacity=0.9] (0,0) circle (1.8cm); 

% --- pressure port node for an external reference
  \node (-port) at (0,-1.78){} ;
%--- escala
  \foreach \angle / \label in 
    {225/0, 200/10, 175/20, 150/30, 125/40, 100/50, 75/60,  50/70, 25/80, 0/90,-25/100 } 
  { 
    \draw[line width=1pt] (\angle:1.6cm) -- (\angle:1.8cm); 
    \draw (\angle:1.3cm) node{\textsf{\label}}; 
  } 

  \draw (-90:0.75cm) node{\SI{}{\kilo\pascal}}; % unidade

  \foreach \angle  in {225,222.5, ..., -25} {\draw[thin] (\angle:1.7cm) -- (\angle:1.8cm);} 
  \foreach \angle  in {225,212.5, ..., -25} {\draw[thin] (\angle:1.65cm) -- (\angle:1.8cm);} 

  \draw[circle,ultra thick,-latex] (0,0) to[short,*-](225-\pv{value}*2.5:1.1cm); % Valor indicado 
  \draw[fill=black,rounded corners] (0,0) -- (225-\pv{value}*2.5-30:-5mm) -- +(225-\pv{value}*2.5-90:5mm) --  cycle;

  \node[draw,circle, fill=gray!10, opacity=0.85] at(0,0){};
    }
  }, % end of code
  manometer/.cd,
  value/.initial=30,
  case color/.initial=cyan!60!gray,
  port color/.initial=green!30!black,
  pressure port/.initial=\draw, %\path % to hide pressure port
  bourdon/.initial=\draw, %\path % to hide bourdon tube
} % End of Manometer

\begin{tikzpicture} 
% defining a pic with name P01
% The problem is that the connection port is outside of the object.
\pic [local bounding box=P01] at (0,0) {manometer={value=50, port color=olive!50!gray, pressure port=\draw, bourdon=\path}};

  \draw[color=green!50!black, double=cyan!1, line width=2mm, double distance=1mm, opacity=0.95, rounded corners] (P01.-90) --++(0,-1) --++(-2,0) ;


%--- Following is the desired method using an internal node reference  to connect the object but  the following error occurs:
% Package pgf Error: No shape named `pgfcirc@short2122start' is known. ...gray, pressure port=\draw, bourdon=\path}}

\pic (P02) at (5,0) {manometer={value=50, pressure port=\draw, bourdon=\draw}};
\draw[color=green!50!black, double=cyan!1, line width=2mm, double distance=1mm, opacity=0.95, rounded corners] (P02-port) --++(0,-1) --++(2,0) ;

\end{tikzpicture}%
\end{document}

不带和带有内部端口连接的压力计

答案1

避免使用circuitikztikz 图片内的元素。这是一个相当简单的示例,会产生与原始代码类似的错误。

\documentclass{standalone}
\usepackage{circuitikz}  
\tikzset{pics/mypic/.style={code={\draw (0,0) to[short](1,0);}}}
\begin{document}
\begin{tikzpicture}
\pic (p) {mypic};
\end{tikzpicture}
\end{document}

问题的根源似乎是节点的命名。如果您不命名的具体实例mypic,即删除(p),则错误会消失。

作为替代方案,使用纯 tikz 并使用 tikz 命令绘制压力计指针。这应该不会比circuitikz在非预期情况下使用元素更困难。

相关内容