2

Are there DAC and DAC shapes in circuitikz? You know, the irregular pentagon (line assure/rectangle with a triangular side).

Trying to write a \pgfdeclareshape for it, but wondered if someone already had done it.

One thin is if you try to draw lines to/from it, it takes the bounding rectangle. Also have a \tip anchor for the tip of the "triangle part".

\tikzstyle{rectangulo}=[
    draw, fill=#1, very thick, regular polygon, regular polygon sides=4,
    text width=1cm, minimum width=2.25cm, minimum height=1.5cm,
    outer sep=0, inner sep=0
]

\tikzstyle{DAC}=[
    draw, fill=#1, very thick,
    text width=1cm, minimum width=2.25cm, minimum height=1.5cm,
    outer sep=0, inner sep=0%,
%    path (-0.75cm,-0.75cm) 
%      -- (-1.50cm, 0     ) 
%      -- (-0.75cm, 0.75cm) 
%      -- ( 0.75cm, 0.75cm) 
%      -- ( 0.75cm,-0.75cm) 
%      -- cycle;
]

\newcommand{\blocksDAC}[3]{%
 \coordinate (D) at (#1,#2);
 \node[rectangulo=pink!30, 
       outer sep=0] (#3) at (D) {};
 \beginpgfgraphicnamed{#3}
   \node[DAC=purple!10, shift=(D), draw=green, fill=none, name path=#3] (CCC)  {}
        (-0.75cm,-0.75cm) 
     -- (-1.50cm, 0     ) 
     -- (-0.75cm, 0.75cm) 
     -- ( 0.75cm, 0.75cm) 
     -- ( 0.75cm,-0.75cm) 
     -- cycle;
   \node[font=\Large] (Badc) at (D) {\texttt{ADC}};
  \endpgfgraphicnamed
}%\blocksDAC

%------------------------------------------------------------------------------
\begin{document}
%------------------------------------------------------------------------------

\begin{center}
 \begin{tikzpicture}[line width=0.5mm] 
   \blocksDAC{0}{-2}{Bdac}
   \draw (Bdac) -- (5,0);
  \end{tikzpicture}
\end{center}

%------------------------------------------------------------------------------
\ end{document}
%------------------------------------------------------------------------------
  • I saw something on GitHub, but he wasn't using \declareshape. Note, Circuitikz makes it very easy to create bipoles, but it uses certain conventions regarding size which differ entirely from how TikZ does it (where components expand if you put text inside them). – John Kormylo Jan 10 '15 at 2:48
1

Would this be close to what you seek? I found the model in here ADC. Since circuitikz was mentioned, the solution modifies one of the circuitikz two-terminal element called generic into two macros called myADC and myDAC, both assuming two arguments <name> and <color>, respectively. The syntax is same as the circuitikz syntax, shown below

\draw (x1,y1) to[generic,color=white,name=<name>] (x2,y2);
\myadc{<name>}{<color>}  % To replace the generic element

enter image description here

Code

\documentclass[border=5mm]{standalone}  
\usepackage[american,siunitx]{circuitikz}


\newcommand{\myDAC}[2] % #1=name, #2=color
{
\draw[fill=#2] (#1)  +(-16.5pt,0pt) --+(-6pt,6pt) --+(16.5pt,6pt) --+(16.5pt,-6pt) --+(-6pt,-6pt) --cycle;
\draw[] (#1)node{\tiny DAC};
}

\newcommand{\myADC}[2] % #1 = name, #2=color
{
\draw[fill=#2] (#1)  +(-16.5pt,0pt) --+(-6pt,6pt) --+(16.5pt,6pt) --+(16.5pt,-6pt) --+(-6pt,-6pt) --cycle;
\draw[] (#1)node[]{\tiny ADC};
}

\begin{document}  
%http://en.wikipedia.org/wiki/Analog-to-digital_converter

\begin{circuitikz}

\draw (3,4) to[generic,color=white,name=ADC] (5,4);
\myADC{ADC}{pink!30} 

\draw (3,2) to[generic,color=white,name=DAC] (5,2);
\myDAC{DAC}{pink!30} 

\end{circuitikz}

\end{document}
0

This creates both bipole ADC and differential ADC using standard circuitikz shape definitions.

circuit

\documentclass{standalone}
\usepackage{circuitikz}

% normally defined in components.tex

\newlength{\ResUp} \newlength{\ResDown}
\newlength{\ResLeft} \newlength{\ResRight}
\newlength{\ResRadius} \newlength{\ResMiddle}

\makeatletter
\def\TikzBipolePath#1#2{\pgf@circ@bipole@path{#1}{#2}}
\def\CircDirection{\pgf@circ@direction}
\pgf@circ@Rlen = \pgfkeysvalueof{/tikz/circuitikz/bipoles/length}
\let\ResLen=\pgf@circ@Rlen
\makeatother

\newcommand{\Compass}% define anchors for compass points
{\anchor{north east}{\northeast}
\anchor{south west}{\southwest}
\anchor{north}{\pgfextracty{\ResUp}{\northeast}\pgfpoint{0cm}{\ResUp}}
\anchor{north west}{\pgfextracty{\ResUp}{\northeast}\pgfextractx{\ResLeft}{\southwest}\pgfpoint{\ResLeft}{\ResUp}}
\anchor{west}{\pgfextractx{\ResLeft}{\sosuthwest}\pgfpoint{\ResLeft}{0cm}}
\anchor{south}{\pgfextracty{\ResDown}{\southwest}\pgfpoint{0cm}{\ResDown}}
\anchor{south east}{\pgfextracty{\ResDown}{\southwest}\pgfextractx{\ResRight}{\northeast}\pgfpoint{\ResRight}{\ResDown}}
\anchor{east}{\pgfextractx{\ResRight}{\northeast}\pgfpoint{\ResRight}{0cm}}}

% ***************************** ADC *********************************
% extra anchors out,in1,in2,vref

\ctikzset{bipoles/ADC/width/.initial=1}
\ctikzset{bipoles/ADC/height/.initial=.5}
\ctikzset{bipoles/ADC/middle/.initial=-.25}
\ctikzset{bipoles/ADC/part/.initial=ADC}

\def\drawADC{% used by both bipole and node
  \ResRight=\ctikzvalof{bipoles/ADC/width}\ResLen
  \ResRight=0.5\ResRight
  \ResLeft=-\ResRight
  \ResUp=\ctikzvalof{bipoles/ADC/height}\ResLen
  \ResUp=0.5\ResUp
  \ResDown=-\ResUp
  \ResMiddle=\ctikzvalof{bipoles/ADC/middle}\ResLen
  \pgfpathmoveto{\pgfpoint{\ResLeft}{0pt}}
  \pgfpathlineto{\pgfpoint{\ResMiddle}{\ResUp}}
  \pgfpathlineto{\pgfpoint{\ResRight}{\ResUp}}
  \pgfpathlineto{\pgfpoint{\ResRight}{\ResDown}}
  \pgfpathlineto{\pgfpoint{\ResMiddle}{\ResDown}}
  \pgfpathlineto{\pgfpoint{\ResLeft}{0pt}}
  \pgfpathclose
  \pgfusepath{draw}
  \pgftext{\texttt{\ctikzvalof{bipoles/ADC/part}}}
}

\pgfcircdeclarebipole{}% no extra anchors for bipole version
  {\ctikzvalof{bipoles/ADC/height}}
  {ADC}
  {\ctikzvalof{bipoles/ADC/height}}
  {\ctikzvalof{bipoles/ADC/width}}
  {\pgfsetlinewidth{\ctikzvalof{bipoles/thickness}\pgfstartlinewidth}\drawADC}

\def\ADCpath#1{\TikzBipolePath{ADC}{#1}}
\tikzset{ADC/.style = {\circuitikzbasekey, /tikz/to path=\ADCpath, l_=#1}}

\pgfdeclareshape{dADC}{%
\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}{   % called automatically
  \ResRight=\ctikzvalof{bipoles/ADC/width}\ResLen
  \ResRight=0.5\ResRight
  \ResLeft=-\ResRight
  \ResUp=\ctikzvalof{bipoles/ADC/height}\ResLen
  \ResUp=0.5\ResUp
  \ResDown=-\ResUp
  \ResMiddle=\ctikzvalof{bipoles/ADC/middle}\ResLen
  \ResRadius=\ResMiddle% location of in1 and in2
  \advance\ResRadius by \ResLeft
  \ResRadius=0.5\ResRadius
}% while these can be used for savedanchors, they will be fogotten by anchors

\savedanchor{\northeast}{\pgfpoint{\ResRight}{\ResUp}}
\savedanchor{\southwest}{\pgfpoint{\ResLeft}{\ResDown}}

\savedanchor\InOne{\pgfpoint{\ResRadius}{0.5\ResUp}}
\savedanchor\InTwo{\pgfpoint{\ResRadius}{0.5\ResDown}}
\savedanchor\Out{\pgfpoint{\ResRight}{0pt}}
\savedanchor\Vref{\pgfpoint{0pt}{\ResDown}}

\Compass% standard anchors

\anchor{in1}{\InOne}
\anchor{in2}{\InTwo}
\anchor{out}{\Out}
\anchor{vref}{\Vref}

\foregroundpath{
  \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgflinewidth}
  \drawADC}
}

\begin{document}
\begin{circuitikz}
\draw (0,0) to[ADC,o-*] (2,0);
\node[dADC] (ADC1) at (1,2) {};
\draw (ADC1.in1) -- +(-.5,0) node[left]{in1}
      (ADC1.in2) -- +(-.5,0) node[left]{in2}
      (ADC1.out) -- +(.5,0) node[right]{out}
      (ADC1.vref) -- +(0,-.5) node[below]{vref};
\end{circuitikz}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.