2

I'm trying to create a a new shape (for nodes) based on the \pgfdeclareshape command.

The shape I'd like to define is supposed to represent a register (aka a D-flip-flop) like the ones used in digital architectural schematics. That is, a mere box to which a small '>' symbol has been added near to the lower left corner, just a little above (indicating the clock input). I'd also like to make it possible to define some new anchors on the borders. Like the so-called "D" input and "Q" output, some "R" reset input, etc, everything being optionally displayed or not (and if yes, possibly with a text label) depending on parameters passed at node definition time. Ideally, the size of the '>' symbol, along with the font size of the text labels of all inputs and outputs, would be automatically scaled to the size of the node. For instance these sizes would be proportional to the minimum width or minimum height of the node, the '>' symbol being placed at a specific amount of the height of the main rectangle, like .2 times (20%).

Let's say I'd like the fully-featured new shape to look like that (except the four small horizontal lines that would not be part of the shape itself):

enter image description here

I've tried to imitate the examples I've found in the TikZ/PGF manual (§101 of version 3.0.1) and on the web, like the document example which inherits from the rectangle predefined shape. Alas I can't get my code to work. When I try to define the coordinates of the left down edge of the small '>', using for instance \pgf@xd=\pgf@xa, I get a pdflatex error.

Does anyone have a clue to how to create this shape?

Thanks in advance!

Karim

PS: Below is my sample code. I've indicated with a comment the line that makes pdflatex crash. When I remove it, I can at least get a simple... rectangle. Yes, I know everything is far from over ;)

\documentclass{standalone} \usepackage{tikz} \begin{document} \makeatletter \pgfdeclareshape{register}{ \inheritsavedanchors[from=rectangle] \inheritanchorborder[from=rectangle] \inheritanchor[from=rectangle]{center} \inheritanchor[from=rectangle]{north} \inheritanchor[from=rectangle]{south} \inheritanchor[from=rectangle]{west} \inheritanchor[from=rectangle]{east} \backgroundpath{ % store lower right in xa/ya and upper right in xb/yb \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y % compute starting point of the '>' \pgf@xc=\pgf@xa \pgf@yc=\pgf@ya \advance\pgf@yc by -5pt % this should be a parameter % construct main path \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}} \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}} \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}} \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}} \pgfpathclose \pgf@xd=\pgf@xa } } \makeatother \begin{tikzpicture} \node[draw,shape=register,inner sep=2ex] (x) {D}; \end{tikzpicture} \end{document} 
2
  • Sorry I forgot to indicate the wrong line... so this is it: % this is the line that makes pdflatex crash \pgf@xd=\pgf@xa Commented Aug 13, 2015 at 21:54
  • 1
    Try using \newdimen\pgf@xd, or \newlength\pgf@xd and \setlength{\pgf@xd}{\pgf@xa} instead of \\pgf@xd=\pgf@xa Commented Dec 1, 2015 at 15:16

1 Answer 1

1

At the time when this question was asked neither \pgf@xd nor \pgf@yd where valid dimen registers that were created by PGF which is why

\pgf@xd=\pgf@xa 

didn't work.

Since 2019 both \pgf@xd and \pgf@yd are created by PGF (only \pgf@xd is used in exactly one place) and the code in question should work now.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.