-1

All the versions of the package seem to miss a simple and basic component of very general circuit descriptions (black box model) like quadrupoles or boxes with a single port (but with two terminals highlighting the electrical nature of the device, not just one, as for the component 'twoport'). I would like to draw something like this, is it possible? enter image description here

5
  • They are straight lines.
    – percusse
    Commented Mar 11, 2017 at 18:17
  • @percusse well, also twoport is made up of straight lines only (even fewer), but still is a component
    – Vexx23
    Commented Mar 11, 2017 at 18:26
  • I always just use a named node and place the leads to the edges using calc. But creating a shape with leads preattached is easy enough. Do you want the box to increase in size to fit the text? Commented Mar 11, 2017 at 18:45
  • I mean they are geometric shapes already available in every drawing package. You don't need a circuit library for this.
    – percusse
    Commented Mar 11, 2017 at 19:08
  • @JohnKormylo Yes, I would like to add text inside and above the box (if possible), but also on the wires. Can you explain me further the details of your strategy?
    – Vexx23
    Commented Mar 11, 2017 at 19:33

1 Answer 1

4

Here is how to use a normal rectangular node:

\documentclass{standalone}
\usepackage{circuitikz}

\begin{document}
\begin{circuitikz}% or tikzpicture
\tikzset{quad/.style={draw, thick, minimum height=.8cm, minimum width=.8cm}}
\node[quad] (A) at (0,0) {text};
\draw ($(A.north west)!.5!(A.west)$) to[short,-o] ++(-.2,0)
      ($(A.south west)!.5!(A.west)$) to[short,-o] ++(-.2,0)
      ($(A.north east)!.5!(A.east)$) to[short,-o] ++(.2,0)
      ($(A.south east)!.5!(A.east)$) to[short,-o] ++(.2,0);
\end{circuitikz}
\end{document}

demo


Here is how to create a new shape with built in leads and 4 new anchor points (in1, in2, out1 and out2).

\documentclass{standalone}
\usepackage{circuitikz}

\makeatletter
% ************************** blackbox *****************************
\ctikzset{quadpoles/blackbox/.is family}
\ctikzset{quadpoles/blackbox/height/.initial=.5}
\ctikzset{quadpoles/blackbox/width/.initial=.5}
\ctikzset{quadpoles/blackbox/sep/.initial=2pt}
\ctikzset{quadpoles/blackbox/lead/.initial=.5}

\pgfdeclareshape{blackbox}{
\anchor{center}{\pgfpointorigin}    % within the node, (0,0) is the center

\anchor{text}   % this is used to center the text in the node
    {\pgfpoint{-.5\wd\pgfnodeparttextbox}{-.5\ht\pgfnodeparttextbox}}

\savedmacro{\resize}{\pgf@circ@res@temp=\ctikzvalof{bipoles/length}% scale
  \pgf@circ@res@temp=0.5\pgf@circ@res@temp
  \pgf@circ@res@right=\ctikzvalof{quadpoles/blackbox/width}\pgf@circ@res@temp
  \pgf@circ@res@step=0.5\wd\pgfnodeparttextbox
  \advance\pgf@circ@res@step by \ctikzvalof{quadpoles/blackbox/sep}%
  \ifdim\pgf@circ@res@right<\pgf@circ@res@step \pgf@circ@res@right=\pgf@circ@res@step\fi
  \pgf@circ@res@left=-\pgf@circ@res@right
  \pgf@circ@res@up=\ctikzvalof{quadpoles/blackbox/height}\pgf@circ@res@temp
  \pgf@circ@res@step=0.5\ht\pgfnodeparttextbox
  \advance\pgf@circ@res@step by \ctikzvalof{quadpoles/blackbox/sep}%
  \ifdim\pgf@circ@res@up<\pgf@circ@res@step \pgf@circ@res@up=\pgf@circ@res@step\fi
  \pgf@circ@res@down=-\pgf@circ@res@up
  \pgfstartlinewidth=\pgflinewidth% don't know why this is needed
}

\savedanchor{\northeast}{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@up}}
\savedanchor{\southwest}{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@down}}

\anchor{north east}{\northeast}
\anchor{south west}{\southwest}
\anchor{north}{\pgfextracty{\pgf@circ@res@up}{\northeast}\pgfpoint{0cm}{\pgf@circ@res@up}}
\anchor{north west}{\pgfextracty{\pgf@circ@res@up}{\northeast}\pgfextractx{\pgf@circ@res@left}{\southwest}\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@up}}
\anchor{west}{\pgfextractx{\pgf@circ@res@left}{\sosuthwest}\pgfpoint{\pgf@circ@res@left}{0cm}}
\anchor{south}{\pgfextracty{\pgf@circ@res@down}{\southwest}\pgfpoint{0cm}{\pgf@circ@res@down}}
\anchor{south east}{\pgfextracty{\pgf@circ@res@down}{\southwest}\pgfextractx{\pgf@circ@res@right}{\northeast}\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@down}}
\anchor{east}{\pgfextractx{\pgf@circ@res@right}{\northeast}\pgfpoint{\pgf@circ@res@right}{0cm}}

\savedanchor{\inone}{%
  \pgf@circ@res@step=-\ctikzvalof{quadpoles/blackbox/lead}\pgf@circ@res@temp
  \advance\pgf@circ@res@step by \pgf@circ@res@left
  \pgfpoint{\pgf@circ@res@step}{0.5\pgf@circ@res@up}
}
\anchor{in1}{\inone}

\savedanchor{\intwo}{%
  \pgf@circ@res@step=-\ctikzvalof{quadpoles/blackbox/lead}\pgf@circ@res@temp
  \advance\pgf@circ@res@step by \pgf@circ@res@left
  \pgfpoint{\pgf@circ@res@step}{0.5\pgf@circ@res@down}
}
\anchor{in2}{\intwo}

\savedanchor{\outone}{%
  \pgf@circ@res@step=\ctikzvalof{quadpoles/blackbox/lead}\pgf@circ@res@temp
  \advance\pgf@circ@res@step by \pgf@circ@res@right
  \pgfpoint{\pgf@circ@res@step}{0.5\pgf@circ@res@up}
}
\anchor{out1}{\outone}

\savedanchor{\outtwo}{%
  \pgf@circ@res@step=\ctikzvalof{quadpoles/blackbox/lead}\pgf@circ@res@temp
  \advance\pgf@circ@res@step by \pgf@circ@res@right
  \pgfpoint{\pgf@circ@res@step}{0.5\pgf@circ@res@down}
}
\anchor{out2}{\outtwo}

\foregroundpath{% border and leads drawn here
  \pgfextractx{\pgf@circ@res@right}{\northeast}
  \pgfextracty{\pgf@circ@res@up}{\northeast}
    \pgfextractx{\pgf@circ@res@left}{\southwest}
    \pgfextracty{\pgf@circ@res@down}{\southwest}

  \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}%
  \pgfpathrectanglecorners{\southwest}{\northeast}%
  \pgfusepath{draw}%
  \pgfscope
    \pgfsetlinewidth{\pgfstartlinewidth}%
    \pgfpathmoveto{\inone}%
    \pgfextracty{\pgf@circ@res@step}{\inone}%
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@step}}%
    \pgfpathmoveto{\intwo}%
    \pgfextracty{\pgf@circ@res@step}{\intwo}%
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@left}{\pgf@circ@res@step}}%
    \pgfpathmoveto{\outone}%
    \pgfextracty{\pgf@circ@res@step}{\outone}%
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@step}}%
    \pgfpathmoveto{\outtwo}%
    \pgfextracty{\pgf@circ@res@step}{\outtwo}%
    \pgfpathlineto{\pgfpoint{\pgf@circ@res@right}{\pgf@circ@res@step}}%
    \pgfusepath{draw}%
  \endpgfscope
}}
\makeatother

\begin{document}
\begin{circuitikz}% or tikzpicture
\node[blackbox] (A) at (0,0) {text};
\node[blackbox,anchor=in1] (B) at (A.out1) {more text};
\end{circuitikz}
\end{document}

shape

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .