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.

On TeXample, Martin Scharrer contributed an excellent d-flipflop example that simplifies circuit drawing to a two step-process of

  1. Place the part:

    % Place FFs  
    \foreach \m in {0,...,\N}  
          \node [shape=dff] (DFF\m) at ($ 3*(\m,0) $) {Bit \#\m};
    
  2. Connect the nets

The d-flip flop uses a \pgfdeclareshape command and involves 120-lines of code. It's possible to save the d-flip-flop in its own file that looks something like the following:

\makeatletter  
  % D flip-flops (DFFs) and shift register  
  % Original Author: Martin Scharrer  
  % Data Flip Flip (DFF) shape  
 \pgfdeclareshape{dff}{  
    %... details omitted, available elsewhere  
 }

 % Define styles, etc  
 \tikzset{  
    every dff node/.style=%... details omitted, available elsewhere  
 }  
 \makeatother

This may be a tall order, but is there a tool, similar to TikZit, that is stable under Windows and allows creation, and editing of graphics saved in this manner?

share|improve this question
    
As far as I know there isn't one, but it would be create to have one. Some vector graphic tools can produce TikZ (or PGF) I heard, but I doubt they can produce a full shape declaration. You could, however, use it to at least do the backgroundpath etc. part of the shapre. –  Martin Scharrer Feb 23 '11 at 14:29
    
(To get a block of code formated inside a list, you have to intend it by 8 spaces.) –  Caramdir Feb 23 '11 at 21:25
1  
Thanks to you both. I should mention that there is a related question here. I've tested most, but while they export (verbosely) to tex, few import. –  SmileAndNod Feb 23 '11 at 22:35
add comment

1 Answer

up vote 1 down vote accepted

As an interim solution to this question, I've settled on using the \matrix command to position coordinates. Eventually I would like to see a simple graphical utility or other such parser that can take a VHDL template or schematic symbol and automatically generate the source-code for the IC, using the following as a template:

%% An IC is essentially a matrix with connection points (coordinates) at its upper, lower, left and right edges.
%% The matrix command facilitates this nicely using nodes combined with the label option
%% The matrix command for any IC can be placed in a custom command for reuse: 
%% Use the folllowing as a template
\newcommand{\drawff}[2]{%
    \matrix (DFF#1) [draw,very thick,inner sep=0pt,outer sep=0pt,column sep=2pt,label distance=0.6ex, 
        font=\sffamily\scriptsize,
        ampersand replacement=\&] at #2 {
            % Top Row:
            \& \& \& \& \& \node [coordinate,label=270:R] (R#1) {}; \& \& \& \& \& \&\\
            % Left and right rows:
            \& \& \& \& \& \& \& \& \& \& \& \\[1ex]
            \node [coordinate,label=0:D] (D#1) {};
            \& \& \& \& \& \& \& \& \& \& \& \node [coordinate,label=180:Q] (Q#1) {}; \\[6ex]
            \node [coordinate,label=0:CE] (CE#1) {};
            \& \& \& \& \& \& \& \& \& \& \& \\
            \& \& \& \& \& \& \& \& \& \& \&
                \node [coordinate,label=180:$\overline{\text{Q}}$] (Qb#1) {}; \\
            \node [label=0:$\large >$,anchor=west] (CLK#1) {};
            \& \& \& \& \& \& \& \& \& \& \& \\[1ex]
            % Bottom row:
            \& \& \& \& \& \node [coordinate,label=90:S] (S#1) {}; \& \& \& \& \& \&\\
    } ;
}

Once the symbols are defined, graphical software that manipulates a grid can define coordinates where ICs and I/O markers are to be placed. The output of this software should look something like:

{[start chain=placements]
%% Place the parts

% D registers, with labels
%% Step 1: anchor placement (a graphical editor should be able to handle this)
    \foreach \m in {0,...,\N}
        \node [coordinate] (tlDFF\m) at ($ 3*(\m,0) $) {};

% 'Reset' port label
    \path (tlDFF0) +(-2,+2.5) coordinate (reset)   node [anchor=east] {reset};

% 'Set' port label
    \path (tlDFF0) +(-2,-2.5) coordinate (set)   node [anchor=east] {set};

% Clock port label
    \path (tlDFF0) +(-2,-3) coordinate (clock) node [anchor=east] {clock};

% Clock enable port label
    \path (tlDFF0) +(-2,-3.5) coordinate (clocken)   node [anchor=east] {clock enable};
}

The third task would be simply to place the appropriate symbols at the coordinates. This is just a matter of picking unique names, and placing the shape as follows:

\foreach \m in {0,...,\N}
    \drawff{\m}{(tlDFF\m)};

%% annotate the ics as desired
\foreach \m in {0,...,\N}
    \node [fit=(DFF\m),font=\sffamily\scriptsize] {Bit \#\m};

%% Place input and output ports, junctions, etc:
    % data in- and output port
    \path [ultra thick] (D0) -- +(-1,0) node [anchor=east] (in0) {input} ;
    \path [ultra thick] (Q\N) -- +(1,0) node [anchor=west] (out\N) {output};

Finally, connect the nets with wires. The graphical routine need only be able to identify what coordinate is being referenced when the user clicks on a specific location in the image. Drawing can be accomplished using the \chainin command, similar to that shown below:

{[start chain=nets]
%% Connect the nets

% Connect reset lines
    \chainin (reset);
    {[start branch=reset] 
        \foreach \m in {0,...,\N} 
            \chainin (R\m) [join=with reset by {hv path,tip}];
    }

% Connect FFs (Q1 with D1, etc.)    
\chainin (in0);
\chainin (D0) [join= by ultra thick];

    \foreach \m in {1,...,\N} {[start branch=qd\p\m] % Note that it starts with 1, not 0
        \chainin (Q\p);
        \chainin (D\m) [join=by ultra thick];
        \global\let\p\m
    }

\chainin (Q\N);
\chainin (out\N) [join= by ultra thick];

% Connect set lines
    \chainin (set);
    {[start branch=set] 
        \foreach \m in {0,...,\N} 
            \chainin (S\m) [join=with set by {hv path,tip}];
    }

% Connect clock lines
    \chainin (clock);
    {[start branch=clk]
        \foreach \m in {0,...,\N} 
            \chainin (CLK\m) [join=with clock by {Z path=-0.55,tip}];
    }

% Connect clock-enable lines
    \chainin (clocken);
    {[start branch=clken]
        \foreach \m in {0,...,\N}  
            \chainin (CE\m) [join=with clocken by {Z path=-0.75,tip}];    
    }
}

Any reports of progress in this matter are appreciated!

share|improve this answer
add comment

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.