TransWikia.com

How can I draw a line segment from an anchor node inside a pic?

TeX - LaTeX Asked by Anisio Braga on March 31, 2021

I’m trying to draw a line from an anchor node inside a configurable object constructed as a TikZ pic, but it doesn’t work. Is there an explanation and solution for this?

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

begin{document}
% --- Manômetro ---------------------
tikzset{pics/manometer/.style={code={
      tikzset{manometer/.cd,#1}
      defpv##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{}{kilopascal}}; % 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}

Manometer without and with an internal port connection

One Answer

Avoid circuitikz elements inside a tikz pic. Here is a rather minimal example producing a similar error as the original code.

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}

The source of the problem seems to be the naming of nodes. If you don't name the concrete instance of mypic, i.e., if you remove (p), then the error disappears.

As an alternative, use plain tikz and draw the hand of the manometer with tikz commands. This shouldn't be more difficult than using circuitikz elements for situations they were not intended for.

Correct answer by gernot on March 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP