Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/examples/xfig/xfiglib.m4

raw
1 .PS
2 # This is the source for a prototype xfig library of electric circuit
3 # elements. Each element is a compound xfig object with corners on grid points.
4 # Connection points (to which lines may be drawn) should also be on grid
5 # points.
6 #
7 # Processing postscript.m4 and this file thought dpic -r gives postscript
8 # output that can be read into CorelDraw and, probably, Adobe Illustrator.
9 #
10
11 log_init
12
13
14 gunit = 1/16 # default xfig grid dimension = (1/16) in
15 divert(-1)
16 define(`elen_',`8*gunit') # default 2-terminal element length
17 define(`dimen_',`8*gunit') # reference dimension for element bodies
18 define(`L_unit',`gunit') # logical gate grid size
19 define(`N_diam',1) # L_unit size of `not' circles
20
21 # grid round and chop
22 define(`g_round',`(int((`$1')/gunit+100000.5 )-100000)*gunit')
23 define(`g_chop', `(int((`$1')/gunit+100000.9999)-100000)*gunit')
24 # snap to grid
25 define(`g_snap',`(g_round((`$1').x),g_round((`$1').y))')
26
27 # Box containing an element. The element must be in a box that is
28 # intersected by a horizontal or vertical line from entry to exit.
29 define(`Xfigbox',`[ S: Here; `$1' ; F: Here
30 if S.y == F.y then { move from (max(S.x,F.x),F.y+g_chop(last[].n.y-F.y)) \
31 to (min(S.x,F.x),F.y-g_chop(F.y-last[].s.y)) } \
32 else { move from (F.x+g_chop(last[].e.x-F.x),max(S.y,F.y))\
33 to (F.x-g_chop(F.x-last[].w.x),min(S.y,F.y))
34 } ] ')
35
36 # Place compound object corners at grid intersections
37 define(`Below',
38 `with .nw at g_snap(ifelse(`$1',,`last []',`$1').sw)-(0,2*gunit)')
39 define(`Right',
40 `with .nw at g_snap(ifelse(`$1',,`last []',`$1').ne)+(2*gunit,0)')
41
42 # for debug
43 define(`prpos',`print (`$1').x/gunit,(`$1').y/gunit')
44 divert(0)dnl
45
46 [ [
47
48 rpoint_(up_ elen_)
49 A:Xfigbox( resistor )
50 Xfigbox( inductor(,W) ) Right
51 Xfigbox( inductor(,W,,M) ) Right
52 Xfigbox( inductor ) Right
53 Xfigbox( inductor(,,,M) ) Right
54 Xfigbox( capacitor(down_ elen_,C) ) Right
55 Xfigbox( capacitor ) Right
56 Xfigbox( diode(down_ elen_) ) Right
57 Xfigbox( diode(down_ elen_,Z) ) Right
58 Xfigbox( diode(down_ elen_,B) ) Right
59 Xfigbox( xtal ) Right
60 Xfigbox( down_ ; { [right_; ground] }; move down_ 3*gunit ) Right
61 Xfigbox( {move down_ gunit}; [right_; ground(,T)] ) Below
62 Xfigbox( move up_ 2*gunit; dot(at last move.c) ) Below
63
64 B:Xfigbox( source ) Below(A)
65 Xfigbox( source(,I) ) Right
66 Xfigbox( source(,AC) ) Right
67 Xfigbox( consource ) Right
68 Xfigbox( consource(,I) ) Right
69 Xfigbox( battery ) Right
70 Xfigbox( battery(,3) ) Right
71 Xfigbox( ebox ) Right
72
73 rpoint_(right_ elen_ from B)
74 C:Xfigbox( switch ) Below(B)
75 Xfigbox( switch(,,O) ) Below
76 D:Xfigbox( switch(,,C) ) Below
77 Xfigbox( amp(right_ elen_*10/8) ) with .nw at C.ne+(gunit,0)
78 D1:Xfigbox( delay ) Right
79 Xfigbox(define(`dimen_',dimen_*6/5)dnl
80 transformer(down_ 6*gunit,L)
81 define(`dimen_',`8*gunit') ) Right
82
83 define(`bi_tr_adj',`with .E at Here
84 line ifelse(`$1',,left,right) gunit*2/3 from last [].B')
85
86 define(`dimen_',`5/6*8*gunit') # Adjust transistors to grid
87 Xfigbox( [move right_ g_chop(29/10*gunit*2)
88 circle rad 29/10*gunit at last move] ) Right
89 up_
90 Xfigbox( {bi_tr bi_tr_adj}; move up_ gunit ) \
91 with .se at (g_round(D1.w.x),g_round(D.s.y))
92 Xfigbox( {bi_tr(,R) bi_tr_adj(R)}; move up_ gunit ) Right
93 Xfigbox( {bi_tr(,,P) bi_tr_adj}; move up_ gunit ) Right
94 Xfigbox( {bi_tr(,R,P) bi_tr_adj(R)}; move up_ gunit ) Right
95
96 define(`dimen_',15/16*8*gunit)
97 define(`fet_adj',`with .S at Here
98 line ifelse(`$1',,left,right) gunit*3/4 from last [].G')
99 define(`fet_move',`move up_ 5*gunit from last [].S-(0,gunit)')
100
101 E:Xfigbox( {j_fet fet_adj}; fet_move ) Below(D)
102 Xfigbox( {j_fet(,R) fet_adj(R)}; fet_move ) Right
103 Xfigbox( {j_fet(,,P,) fet_adj(R)}; fet_move ) Right
104 Xfigbox( {j_fet(,R,P,) fet_adj(R)}; fet_move ) Right
105 Xfigbox( {e_fet(,,,) fet_adj(R)}; fet_move ) Right
106 Xfigbox( {e_fet(,R,,) fet_adj(R)}; fet_move ) Right
107
108 F:Xfigbox( {e_fet(,,P,) fet_adj}; fet_move ) Below(E)
109 Xfigbox( {e_fet(,R,P,) fet_adj(R)}; fet_move ) Right
110 Xfigbox( {d_fet(,,,) fet_adj}; fet_move ) Right
111 Xfigbox( {d_fet(,R,,) fet_adj(R)}; fet_move ) Right
112 Xfigbox( {d_fet(,,P,) fet_adj}; fet_move ) Right
113 Xfigbox( {d_fet(,R,P,) fet_adj(R)}; fet_move ) Right
114
115 right_
116 G:Xfigbox( OR_gate(1) ) Below(F)
117 Xfigbox( NOR_gate ) Right
118 Xfigbox( XOR_gate ) Right
119 Xfigbox( NXOR_gate ) Right
120
121 # input lines for OR-like gates.
122 define(`OR_inlgth',`(-sqrt(OR_rad^2-G_hht^2)+sqrt(OR_rad^2-`$1'^2))*L_unit')
123
124 H:Xfigbox( [ {move right_ gunit}
125 {move from last move-svec_(0,G_hht) to last move+svec_(0,G_hht)}
126 {line right_ OR_inlgth(0)}
127 {line right_ OR_inlgth(2) from Here+svec_(0,2)}
128 {line same from Here-svec_(0,2)}
129 {line right_ OR_inlgth(1) from Here+svec_(0,1)}
130 {line same from Here-svec_(0,1)}] ) Below(G)
131 Xfigbox( [ {move right_ gunit}
132 {move from last move-svec_(0,G_hht) to last move+svec_(0,G_hht)}
133 {line right_ OR_inlgth(0)}
134 {line right_ OR_inlgth(2) from Here+svec_(0,2)}
135 {line same from Here-svec_(0,2)}] ) Right
136 Xfigbox( [ {move right_ gunit}
137 {move from last move-svec_(0,G_hht) to last move+svec_(0,G_hht)}
138 {line right_ OR_inlgth(2) from Here+svec_(0,2)}
139 {line same from Here-svec_(0,2)}] ) Right
140 Xfigbox( [ {move right_ gunit}
141 {move from last move-svec_(0,G_hht) to last move+svec_(0,G_hht)}
142 {line right_ OR_inlgth(0)}] ) Right
143
144 Xfigbox( AND_gate ) Right
145 Xfigbox( NAND_gate ) Right
146 Xfigbox( line right_ L_unit/2; BUFFER_gate ) Right
147 Xfigbox( line right_ L_unit/2; NOT_gate ) Right
148
149 # Deleted because of labels:
150 #right_
151 #textht = 10/72
152 #I:Xfigbox( FlipFlop(D) ) Below(H)
153 # Xfigbox( FlipFlop(T) ) Right
154 #J:Xfigbox( FlipFlop(RS) ) Below(I)
155 # Xfigbox( FlipFlop(JK) ) Right
156
157 ]
158 box invis wid last [].wid+2*gunit ht last [].ht+2*gunit at last []
159 ] with .sw at (1,1)
160 #print last [].wid,last[].ht
161 .PE