Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to change the appearance of the var make contact symbol from the TikZ circuit library as follows (i.e. add the second circle) and add a "closed" option as shown in the following (handmade) picture:

Make contact graphics

share|improve this question

1 Answer 1

up vote 4 down vote accepted

The easiest way is to copy the definition of the shape from the library and modify it to suit your needs. The library in question is pgflibraryshapes.gates.ee.IEC.code.tex (for the IEC version). There are shape definitions there for the different shapes, you can simply copy the one that you want to modify to your own file and make the modifications there. You simply change the name of the declared shape to what you want and then you just need to modify the \backgroundpath. The default \backgroundpath looks like:

\backgroundpath{
\pgf@process{\pgfpointadd{\northeast}{
    \pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
\pgf@xa=-\pgf@x \pgf@ya=0pt
\pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgf@xc=\pgf@xa
\pgfutil@tempdima=2\pgf@xb%
\pgfutil@tempdima=0.083333\pgfutil@tempdima%
\advance\pgf@xa by \pgfutil@tempdima
% Circle
{\pgfpathcircle{\pgfqpoint{\pgf@xa}{0pt}}{\pgfutil@tempdima}}
% Height
% Start point
\pgf@process{\pgfpointnormalised{\pgfpointdiff{\pgfqpoint{\pgf@xa}{0pt}}{\pgfqpoint{\pgf@xb}{\pgf@yb}}}}
\pgf@xc=\pgf@x
\pgf@yc=\pgf@y
\pgfpathmoveto{\pgfpointadd{\pgfqpoint{\pgf@xa}{0pt}}{%
    \pgfpointscale{\pgfutil@tempdima}{\pgfqpoint{\pgf@xc}{\pgf@yc}}}}
\pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
}

To get the final circle, add {\pgfpathcircle{\pgfqpoint{\pgf@xb}{0pt}}{\pgfutil@tempdima}} at the very end.

To get a closed version, change the \pgf@yb in the \pgfpathlineto to \pgfutil@tempdima. Make sure you wrap the definitions in \makeatletter ... \makeatother.

Edit: I hadn't tested it sufficiently, the anchors need some updating in order for it to work well in a path. The circle we add influences the right border. We can make some minor adjustments to make it work again. Note that the original border is already a rectangle, so not completely a correct border. This kind of object is used in straight paths though, so as long as the rectangle is the right size, using it as a border isn;t a big problem. There are a few modifications, so I'll just add the complete shape definition.

\pgfdeclareshape{var make open contact IEC}
{
  \savedanchor\northeast{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgf@x=\pgf@xa%
    \advance\pgf@x by .5\pgf@xb%
    \pgf@xc=\pgf@x%
    \advance\pgf@xc by\pgf@xa%
    \pgfutil@tempdima=2\pgf@xc%
    \pgfutil@tempdima=0.083333\pgfutil@tempdima%
    \advance\pgf@x by\pgfutil@tempdima%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}%
    \pgf@y=\pgf@ya%
    \advance\pgf@y by\pgf@yb%
    \advance\pgf@y by\pgfutil@tempdima%
  }
  \savedanchor\southwest{%
    \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}%
    \pgf@x=-.5\pgf@xa%
    \advance\pgf@x by -.5\pgf@xb%
    \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}%
    \pgf@y=-\pgf@ya%
    \pgf@xc=0.083333\pgf@x%
    \advance\pgf@y by\pgf@xc%
  }

  \anchor{center}{\pgfpointorigin}
  \inheritanchor[from=rectangle ee]{north}
  \inheritanchor[from=rectangle ee]{south}
  \inheritanchor[from=rectangle ee]{east}
  \inheritanchor[from=rectangle ee]{west}
  \inheritanchor[from=rectangle ee]{north east}
  \inheritanchor[from=rectangle ee]{north west}
  \inheritanchor[from=rectangle ee]{south east}
  \inheritanchor[from=rectangle ee]{south west}
  \inheritanchor[from=rectangle ee]{input}
  \inheritanchor[from=rectangle ee]{output}

  \anchorborder{%
    \ifdim\pgf@y<0pt%
      % tricky... simpilfy to the origin...
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \pgf@process{\southwest}%
    \pgf@xa=\pgf@x%
    \pgf@ya=\pgf@y
    \pgf@process{\pgfpointborderrectangle{\pgfqpoint{\pgf@xc}{\the\pgf@yc}}{\pgfqpoint{-\pgf@xa}{-\pgf@ya}}}%
    \else%
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \pgf@process{\pgfpointborderrectangle{\pgfqpoint{\pgf@xc}{\the\pgf@yc}}{\northeast}}%
    \fi%
  }

  \backgroundpath{ \pgf@process{\pgfpointadd{\northeast}{
        \pgfpointscale{-1}{\pgfpoint{\pgfkeysvalueof{/pgf/outer
              xsep}}{\pgfkeysvalueof{/pgf/outer ysep}}}}}
    \pgf@xa=-\pgf@x \pgf@ya=0pt \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    \pgf@xc=\pgf@xa \pgfutil@tempdima=2\pgf@xb%
    \pgfutil@tempdima=0.083333\pgfutil@tempdima%
    \advance\pgf@xa by \pgfutil@tempdima
    \advance\pgf@xb by-\pgfutil@tempdima
    % Circle
    {\pgfpathcircle{\pgfqpoint{\pgf@xa}{0pt}}{\pgfutil@tempdima}}
    % Height
    % Start point
    \pgf@process{\pgfpointnormalised{\pgfpointdiff{\pgfqpoint{\pgf@xa}{0pt}}{\pgfqpoint{\pgf@xb}{\pgf@yb}}}}
    \pgf@xc=\pgf@x
    \pgf@yc=\pgf@y
    \pgfpathmoveto{\pgfpointadd{\pgfqpoint{\pgf@xa}{0pt}}{%
        \pgfpointscale{\pgfutil@tempdima}{\pgfqpoint{\pgf@xc}{\pgf@yc}}}}
    \pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
    {\pgfpathcircle{\pgfqpoint{\pgf@xb}{0pt}}{\pgfutil@tempdima}}
  }
}

This is the open version, you can change the \pgfpathlineto like discussed before to get the closed version.

share|improve this answer
    
Thanks. I tried it. However the second line starts in the second circle not on the right of it (as in my picture). Perhaps one has to fill the second circle? I don't see how to do that. –  student Apr 13 '12 at 10:31
    
@student: I hadn't tested it completely (hardly at all actually) and the changed anchor slipped my mind. The updated code should work as expected. –  Roelof Spijker Apr 13 '12 at 11:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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