Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/libSLD.m4

raw
1 divert(-1)
2
3 libSLD.m4 Draft macros for single-line diagram elements
4
5 * Circuit_macros Version 11.0, copyright (c) 2026 J. D. Aplevich under *
6 * the LaTeX Project Public Licence in file Licence.txt. The files of *
7 * this distribution may be redistributed or modified provided that this *
8 * copyright notice is included and provided that modifications are clearly *
9 * marked to distinguish them from this distribution. There is no warranty *
10 * whatsoever for these files. *
11
12 ==========================================================================
13
14 # These *DRAFT* definitions are for single-line diagram (SLD) elements
15 # with or without attached circuit breakers or slashes. Many other elements
16 # applicable to SLD drawings are already in libcct.m4. The contributions
17 # and suggestions of Benjamin Vilmann and Peter Jan Randewijk are
18 # acknowledged with thanks.
19
20 # The line
21 # include(libSLD.m4)
22 # loads these definitions for use in a diagram.
23
24 # Notes for 1-terminal SLD elements:
25 # Argument 1 is normally the linespec of the stem to set the direction
26 # and length.; e.g., D1: sl_disk draws a default disk with stem named D1.
27 # For a 0-length stem (which has undefined direction):
28 # arg1 can also be U, D, L, R (for up, down, left, right),
29 # or a number to set the direction in degrees, optionally followed by
30 # `at position' to set the position (Here by default).
31 # Zero-length stem examples: sl_box(U), sl_box(45 at Here+(1,0))
32 # Argument 2 contains semicolon (;)-separated key-value attributes
33 # of the element head as applicable: e.g., name=Carol; text="Stop"; lgth=expr
34 # If argument 3 is blank then a plain stem is drawn as described below.
35 # The element body (head) can be named with name= . The default name is Head.
36 # The head is overlaid with or contained in a [] block.
37
38 # Notes for 2-terminal SLD elements:
39 # These obey the normal Circuit_macro two-terminal conventions.
40 # They can be labelled using rlabel() or llabel() as well as directly.
41 # Argument 2 contains key-value pairs to customize the element body,
42 # e.g., name=Name; text="text"; wdth=expr; ...
43 # Except for sl_drawout and sl_breaker which do not have series breakers
44 # or slashes, nonblank arguments 3 and 4 put a breaker slash symbol
45 # in the input and output respectively as described below.
46
47 # Notes for attached breakers and slashes:
48 # Nonblank arguments 3 and 4 of the two-terminal elements and argument 3 of
49 # the 1-terminal elements specify a breaker in the input, output,
50 # and stem respectivlely. A non-blank argument is C for a default
51 # closed breaker in the stem, O for an open breaker, or X, /, or \ to
52 # put these symbols in the box; if the argument begins with S: or Sn:
53 # (where n is an integer) then an n-line slash symbol is drawn rather
54 # than a breaker; otherwise or in addition, key-value pairs specify
55 # details of the object. The separation of the breaker or slash
56 # from the element body or head is given by parameter sl_breakersep_
57 # or key sep=expr. If this key is in the body or head keys then it
58 # applies to both 2-terminal stem lines; it can also be given for each
59 # stem individually.
60
61 # Notes for composite elements within a [ ] block:
62 # The current transformer macro sl_ct has internal labels defined as
63 # appropriate to the element. The macro sl_transormer3 has 3 principal
64 # termianls and other defined points. Macro sl_busbar has internal
65 # labels P1 to Pnp, Start, and End.
66
67 define(`sldlib_')
68 ifdef(`libcct_',,`include(libcct.m4)divert(-1)')
69
70 # Default size parameters. These can be redefined in a diagram source.
71
72 define(`sl_breakersize_',`dimen_*3/16') # breaker box size
73 define(`sl_breakersep_',`dimen_/2') # breaker separation from body
74 define(`sl_ttboxlen_',`dimen_*3/4') # inline box length
75 define(`sl_ttboxwid_',`dimen_*3/4') # inline box width
76 define(`sl_sboxlen_',`dimen_*2/3') # stem box length
77 define(`sl_sboxwid_',`dimen_*2/3') # stem box wid
78 define(`sl_diskdia_',`dimen_*2/3') # sl_disk diam
79 define(`sl_chevronsiz_',`dimen_/4') # sl_drawout (chevron) size
80 define(`sl_loadwid_',`dimen_*0.32') # load width
81 define(`sl_loadlen_',`dimen_*0.45') # load length
82 define(`sl_transcale_',1) # transformer body scale factor
83 define(`sl_busthick_',linethick*2) # sl_bus line thickness
84 define(`sl_busindent_',`min(dimen_/5,rp_len/5)') # busbar end indent
85
86 # One-terminal elements ###################################################
87
88 `sl_disk( stem linespec, keys, breaker or Sn:slash)
89 keys: name=Name;
90 text="text";
91 diam=expr;
92 circle=other circle attributes; eg shade'
93 `default breaker name Br'
94 define(`sl_disk',
95 `sl_eleminit_(`$1')
96 pushkeys_(`$2',`name:Head:N; circle::N; text::N; diam:sl_diskdia_')dnl
97 ifelse(`$3',,
98 `m4name: circle diam m4diam \
99 at last line.end + vec_(m4diam/2,0) m4circle m4text
100 [ box invis wid_ m4diam ht_ m4diam ] at last circle
101 line from last line.end to last line.start',
102 `m4_one(`sl_disk',$@)') dnl
103 popdef(`m4name', `m4circle', `m4text', `m4diam') ')
104
105 `sl_box( stem linespec, keys, breaker or Sn:slash)
106 keys: name=Name; lgth=expr; wdth=expr;
107 text="text";
108 box= box attributes; (e.g. shade "red")'
109 `default breaker name Br'
110 define(`sl_box',
111 `sl_eleminit_(`$1')
112 pushkeys_(`$2',`name:Head:N; wdth:sl_sboxwid_; lgth:sl_sboxlen_; box::N;
113 text::N')dnl
114 ifelse(`$3',,
115 `line from last line.end to last line.start
116 { m4name: [S:Here; lbox(m4lgth,m4wdth,m4box)] \
117 with .S at last line.start }
118 ifelse(m4text,,,`{m4text at last []}')',
119 `m4_one(`sl_box',$@)') dnl
120 popdef(`m4name', `m4wdth', `m4lgth', `m4box', `m4text') ')
121
122 `sl_grid( stem linespec, keys, breaker or Sn:slash)
123 keys: name=Name; lgth=expr; wdth=expr;'
124 `default breaker name Br'
125 define(`sl_grid',
126 `sl_eleminit_(`$1')
127 pushkeys_(`$2',`name:Head:N; wdth:sl_sboxwid_; lgth:sl_sboxlen_; box::N')dnl
128 ifelse(`$3',,
129 `line from last line.end to last line.start
130 { m4name: [ S:Here
131 { lbox(m4lgth,m4wdth) }
132 { line to rvec_(m4lgth/2, m4wdth/2)
133 line to rvec_(m4lgth/2,-m4wdth/2) }
134 { line to rvec_(m4lgth/2,-m4wdth/2)
135 line to rvec_(m4lgth/2, m4wdth/2) }
136 { line from rvec_(0,m4wdth/2) to rvec_(m4lgth,-m4wdth/2) }
137 line from rvec_(0,-m4wdth/2) to rvec_(m4lgth,m4wdth/2)
138 ] with .S at last line.start } ',
139 `m4_one(`sl_grid',$@)') dnl
140 popdef(`m4name', `m4wdth', `m4lgth', `m4box') ')
141
142 `sl_load( stem linespec, keys, breaker or Sn:slash)
143 keys: name=Name; lgth=expr; wdth=expr;
144 head= arrowhead attributes;
145 default breaker name is Br'
146 define(`sl_load',
147 `sl_eleminit_(`$1')
148 pushkeys_(`$2',`name:Head:N; wdth:sl_loadwid_; lgth:sl_loadlen_; head::N')dnl
149 ifelse(`$3',,
150 `line from last line.end to last line.start
151 { m4name: [S:Here; line to rvec_(0,m4wdth/2) \
152 then to rvec_(m4lgth,0) then to rvec_(0,-m4wdth/2) \
153 then to Here m4head ] with .S at last line.start } ',
154 `m4_one(`sl_load',$@)') dnl
155 popdef(`m4name', `m4wdth', `m4lgth', `m4head') ')
156
157 `sl_meterbox( stem linespec, keys, breaker or Sn:slash)
158 keys: sl_box attributes
159 default breaker name is Br'
160 define(`sl_meterbox',
161 `sl_eleminit_(`$1')
162 pushkeys_(`$2',`name:Head:N; wdth:sl_ttboxwid_; lgth:sl_ttboxlen_; box::N;
163 text::N')dnl
164 ifelse(`$3',,
165 `line from last line.end to last line.start
166 {m4name: [S:Here;
167 { B: rotbox( m4lgth, m4wdth, m4box ) with .W at S }
168 a = rp_ang*rtod_
169 if (abs(a-90) < 45) || (abs(a-180) < 45) || (abs(a+180) < 45) then {
170 C: rvec_(m4lgth*2/5,0)
171 line from rvec_(m4lgth*4/5,m4wdth/2) to rvec_(m4lgth*4/5,-m4wdth/2) } \
172 else { C: rvec_(m4lgth*3/5,0)
173 line from rvec_(m4lgth/5,m4wdth/2) to rvec_(m4lgth/5,-m4wdth/2) }
174 ifelse(m4text,,,`m4text at C')
175 ] with .S at last line.start}',
176 `m4_one(`sl_meterbox',$@)') dnl
177 popdef(`m4name', `m4wdth', `m4lgth', `m4box', `m4text') ')
178
179 `sl_generator( stem linespec, keys,
180 breaker or Sn:slash)
181 keys:
182 name= head name;
183 type=AC|WT|BS|StatG|PV|Y|Delta;
184 (type PV): sl_box keys name, lgth, wdth,
185 text,box;
186 (otherwise): sl_disk body keys name,
187 text, diam, circle;
188 default breaker name is Br
189 Arg5 can be Y;name=Name with default
190 name headname_Y,
191 or Delta;name=Name with
192 default name headname_D'
193 define(`sl_generator',
194 `pushkeys_(`$2',`type:AC:N; name:Head:N; lgth:sl_sboxlen_; wdth:m4lgth/2;
195 box::N; text::N')dnl
196 ifelse(m4type,PV,
197 `sl_box(`$1',wdth=m4lgth*0.6;`$2',`$3')
198 {line from m4name.S+vec_(0,m4wdth*0.45) \
199 to m4name.S+vec_(m4wdth/2,0) \
200 then to m4name.S+vec_(0,-m4wdth*0.45)}',
201 `sl_disk($@)
202 m4lcd = last circle.diam
203 { ifinstr(m4type,AC,
204 `{ ACsymbol(at last circle,,,R) }',
205 m4type,Y,
206 `pushkey_(`$3',name,m4name`'_Y,N)dnl
207 {m4name:Ysymbol(with .N at last circle,size=m4lcd/4) } popdef(`m4name')',
208 m4type,Delta,
209 `pushkey_(`$3',name,m4name`'_Y,N)dnl
210 {m4name:Deltasymbol(with .N at last circle,size=m4lcd/4) }dnl
211 popdef(`m4name')',
212 m4type,WT,
213 `{ Windturbine(with .N at last circle.c,size=m4lcd*0.9) }',
214 m4type,BS,
215 `{ m4angt = rp_ang; battery(up_ m4lcd*3/4 with .c at m4name.c)
216 cross(at m4name.c+(m4lcd/4,m4lcd/5),m4lcd/6)
217 line right_ m4lcd/6 with .c at m4name.c+(m4lcd/4,-m4lcd/6)
218 point_(m4angt) }',
219 m4type,StatG,
220 `{ m4angt= rp_ang; pushdef(`dimen_',m4lcd*2)
221 diode(right_ dimen_/6 with .c at m4name.c,DK)
222 popdef(`dimen_') point_(m4angt)}')
223 [ box invis wid_ m4lcd ht_ m4lcd ] at last circle }') dnl
224 popdef(`m4type',`m4name', `m4lgth', `m4wdth', `m4box', `m4text')')
225
226 `sl_syncmeter( stem linespec, keys, breaker or Sn:slash)'
227 `default breaker name Br'
228 define(`sl_syncmeter',`sl_disk($@)
229 { Syncsymb(at last circle)
230 m4lcd = last circle.diam
231 [ box invis wid_ m4lcd ht_ m4lcd ] at last circle } popdef(`m4thype')')
232
233 `sl_lamp( stem linespec, keys, breaker or Sn:slash)'
234 `default breaker name Br'
235 define(`sl_lamp',`sl_disk($@)
236 { line from last circle.ne to last circle.sw
237 line from last circle.nw to last circle.se
238 m4lcd = last circle.diam
239 [ box invis wid_ m4lcd ht_ m4lcd ] at last circle } ')
240
241 # One-terminal utilities ##################################################
242
243 `Syncsymb(at position, rad)
244 Symbol for sync meter'
245 define(`Syncsymb',`[ define(`m4ssrad',`ifelse(`$2',,(dimen_/4),`($2)')')dnl
246 Origin: Here
247 {arc <-> ht arrowht/2 wid arrowwid*2/3 \
248 from Rect_(m4ssrad,30) to Rect_(m4ssrad,150) with .c at Here}
249 line from (0,m4ssrad) to (0,-m4ssrad/2)
250 `$3' ] with .Origin ifelse(`$1',,`at Here',`$1')')
251
252
253 `Windturbine(at position, keys, U|D|L|R|degrees)
254 keys: size=expr; color="color string"
255 Arg3: drawing direction (default: Right)'
256 define(`Windturbine',`[
257 pushkeys_(`$2',`size:sl_diskdia_:;color:"black":N')dnl
258 setdir_(`$3',R)
259 C: Here; N: C
260 circle diam m4size/18 at C colored m4color
261 for t = 30 to 360 by 120 do {
262 tr = t*dtor_
263 spline 0.55 thick 0.2 shaded m4color outlined m4color \
264 from M4wt(4,-0.8) to M4wt(1.810794,-0.921724)
265 Loopover_(`M4LO',`continue to M4LO',
266 M4wt(1.135237,-0.069654), M4wt(1.777783,1.339647),
267 M4wt(4.198063,2.031772), M4wt(5.033839,2.04),
268 M4wt(5.598904,2.029888), M4wt(17.372737,0.390951),
269 M4wt(18.164674,0.024408), M4wt(17.639221,-0.537401), M4wt(4,-0.8)) }
270 `$4'; resetdir_ popdef(`m4color',`m4size') ] ifelse(`$1',,`at Here',`$1')')
271 define(`M4wt',`(vec_(rot_(`$1',`$2',tr))*m4size/36)')
272
273 `sl_eleminit_(linespec or (for zero length)
274 U|D|L|R|number [at location])'
275 define(`sl_eleminit_',
276 `ifelse(regexp(`$1',^ *[UDLR0123456789]),-1,
277 `eleminit_(`$1',dimen_)',
278 `pushdef(`M4pos',`ifinstr(`$1',` at ',`patsubst(`$1',^.* at *)')')dnl
279 ifelse(M4pos,,,`move to M4pos;') setdir_(patsubst(`$1',` at.*'))
280 line invis from Here to Here popdef(`M4pos')')')
281
282 # Two-terminal elements ###################################################
283
284 `sl_transformer(linespec,
285 keys,
286 input breaker keys,
287 output breaker keys
288 type S input circle inner object,
289 type S output circle inner object)
290 keys:
291 name=body name (default Body);
292 scale=expr; (body size factor: default 1)
293 type=I|S|A[R]
294 (type=I) cycles=n; (default 4)
295 core= A[ir]|M[n]|P[n]|K[n]
296 n=integer (default 2 lines)
297 (type=S) body=circle attributes;
298 Note arg5 and arg6
299 (type=A) body=circle attributes ;
300 type AR means right orientation
301 (breaker default names are BrI, BrO)
302 Args 3 and 4 specify input and output stem objects
303 (breakers or slash symbols);
304 Args 5 and 6 for the input and output circles are
305 name=symbol name; (optional)
306 Y for a Y symbol
307 YN for a Y symbol with ground
308 Default name for a Y in arg5 is Body_Y1; in
309 arg6 it is Body_Y2
310 Delta for a Delta symbol
311 Default name for arg5 is Body_D1; in
312 arg6 it is Body_D2
313 otherwise other customization commands in
314 a {} pair. '
315 define(`sl_transformer',
316 `pushkeys_(`$2',name:Body:N; type:I:N; cycles:4:N; core::N; body::N;
317 scale:sl_transcale_; )define(`m4scf',(m4scale*1.3))dnl
318 ifinstr(m4type,S,
319 `define(`m4blgth',sourcerad_*3.5*m4scf)',
320 m4type,A,
321 `define(`m4blgth',sourcerad_*3*m4scf)',
322 `ifelse(ifinstr(m4core,M,T,m4core,P,T,m4core,K,T),T,
323 `define(`m4nL',ifelse(len(m4core),1,2,substr(m4core,1)))dnl
324 define(`m4blgth',(dimen_/8 + dimen_/12 + (m4nL-1)*dimen_/16)*m4scf)',dnl
325 `define(`m4blgth',(dimen_/8 + dimen_/12)*m4scf)')')dnl
326 ifelse(`$3'`$4',,
327 `ifinstr(m4type,S,
328 `pushdef(`sourcerad_',sourcerad_*m4scf)dnl
329 source(`$1',G,,,m4body,m4name); C: last [].c popdef(`sourcerad_')
330 ifelse(`$5',,,`m4DY(`$5',, 1,m4name.C1,sl_diskdia_*0.18,rp_ang*rtod_)')
331 ifelse(`$6',,,`m4DY(`$6',-,2,m4name.C2,sl_diskdia_*0.18,rp_ang*rtod_)')',
332 m4type,A,
333 `eleminit_(`$1'); C: last line.c
334 { line to rvec_(rp_len/2-m4blgth/2,0); round
335 pushdef(`m4R',ifinstr(m4type,R,-))dnl
336 {m4name: [ C2: circle rad m4blgth/3 m4body at (0,0)
337 Arc: arc ifinstr(m4type,R,c)`'cw \
338 from C2-vec_(m4blgth/3*2,0) to C2+vec_(0,m4R`'m4blgth/3) \
339 with .c at C2-vec_(0,m4R`'m4blgth/2) ] \
340 with .C2 at rvec_(m4blgth/3*2,0)} popdef(`m4R')
341 line from rvec_(m4blgth,0) to rvec_(rp_len/2+m4blgth/2,0) }
342 line invis to rvec_(rp_len,0)',
343 `eleminit_(`$1'); C: last line.c; m4atmp = rp_ang; m4slen = rp_len
344 { line to rvec_((m4slen-m4blgth)/2,0)
345 {m4name: [ linewid = linewid*m4scf
346 {L1: inductor(to vec_(0,-m4cycles*dimen_/8),,m4cycles,m4core)}
347 point_(m4atmp)
348 L2: inductor(from vec_(m4blgth/m4scf,-m4cycles*dimen_/8) \
349 to vec_(m4blgth/m4scf,0),,m4cycles)
350 point_(m4atmp) ] with .L1.c at Here}
351 line from rvec_(m4blgth,0) to rvec_((m4slen+m4blgth)/2,0) }
352 line invis to rvec_(rp_len,0)')',
353 `m4_two(`sl_transformer',m4blgth,$@)')
354 popdef(`m4name', `m4type', `m4cycles', `m4core', `m4body', `m4scale') ')
355 define(`m4trground',
356 `if pmod(drawdir_(`$1'),180)==0 then {
357 line from `$2' to `$2'+(0,-sourcerad_*5/4*m4scf); ground(,T) } \
358 else {
359 line from `$2' to `$2'+(sourcerad_*3/2*m4scf,0); corner; ground } ')
360
361 `sl_transformer3(linespec,
362 keys,
363 breaker1:breaker2:breaker3,
364 symbol1:symbol2:symbol3)
365 keys:
366 name=Name;
367 type=S|C; (default S)
368 scale=expr;
369 direct=L|R;
370 body=circle attributes; '
371 define(`sl_transformer3',
372 `[ pushkeys_(`$2',name:Body:N; scale:sl_transcale_; direct:L:N; body::N;
373 type:S:N )dnl
374 ifelse(m4type,S,
375 `m4trAr(`m4Br',patsubst(`$3',:,`,'))m4trAr(`m4Sy',patsubst(`$4',:,`,'))dnl
376 pushdef(`sl_breakersep_',sl_breakersep_*2/3)dnl
377 sl_transformer($1,type=S;name=m4name;scale=m4scale;$2,
378 m4Br1,m4Br2,m4Sy1,m4Sy2)
379 Tstart: last line.start; C1: m4name.C1; m4atmp = rp_ang
380 Tend: last line.end; C2: m4name.C2
381 define(`m4R',`ifinstr(m4direct,R,-)')dnl
382 C3: m4name.C1+vec_(Rect_(m4name.C1.rad*3/2,m4R`'60))
383 move to C3+vec_(0,m4R`'m4name.C1.rad)
384 Tc: rvec_(0,m4R`'m4name.C1.diam`'ifelse(m4Br3,,/3))
385 sl_disk(from Tc to Here,
386 diam=m4name.C1.diam;name=C3;circle=m4body;`$2',m4Br3)
387 m4DY(m4Sy3,,3,C3,C3.diam*0.18,rp_ang*rtod_); popdef(`sl_breakersep_')
388 point_(m4atmp)',
389 `pushdef(`m4rad',`sl_diskdia_/6*m4scale')dnl
390 eleminit_(`$1',m4rad*8)
391 Tstart: Here
392 line to rvec_(rp_len/2-m4rad*2,0); round
393 Arc: arc cw to rvec_(m4rad*4,0) with .c at rvec_(m4rad*2,0)
394 round; line to rvec_(rp_len/2-m4rad*2,0)
395 Tend: Here
396 C: circle rad m4rad at Arc.c
397 line from C+vec_(0,-m4rad) to C+vec_(0,-m4rad*3)
398 Tc: Here popdef(`m4rad') ')
399 popdef(`m4name',`m4scale',`m4direct',`m4body',`m4type') ]')
400 define(`m4trAr',`define(`$1'`1',$2)define(`$1'`2',$3)define(`$1'`3',$4)')
401
402 `m4DY(symbol,neg,number,loc,size,angle)
403 Insert Delta or Y symbol'
404 define(`m4DY',
405 `pushkey_(`$1',name,m4name`'_`'ifinstr(`$1',Delta,D,Y)`$3',N)dnl
406 define(`m4ang',``$6'`'ifelse(`$2',-,+180)')dnl
407 define(`m4sn',m4name)popdef(`m4name')dnl
408 ifinstr(`$1',Delta,
409 `{m4sn: Deltasymbol(with .N at `$4',size=`$5',m4ang-180)} ',
410 `$1',Y,
411 `{m4sn: Ysymbol(with .N at `$4',size=`$5',m4ang)}
412 ifinstr(`$1',N,`{m4trground(m4ang,m4sn.N)}') ',
413 `{`$1'}')')
414
415 `Two-terminal box'
416 `sl_ttbox(linespec,keys,breaker keys,breaker keys)
417 keys= lgth=expr; wdth=expr; box=attributes;
418 supp=additional rotbox commands;
419 name=body name (default Body);
420 text="text";
421 (breaker default names BrI, BrO)'
422 define(`sl_ttbox',
423 `pushkeys_(`$2',`lgth:sl_ttboxlen_; wdth:sl_ttboxwid_;
424 name:Body:N; box::N; text::N; supp::N')dnl
425 ifelse(`$3'`$4',,
426 `eleminit_(`$1')
427 {line to rvec_((rp_len-m4lgth)/2,0)
428 {m4name: rotbox(m4lgth,m4wdth,m4box,,m4supp) \
429 with .W at Here }
430 ifelse(m4text,,,`{m4text at rvec_(m4lgth/2,0)};') dnl
431 line from rvec_(m4lgth,0) to rvec_((rp_len+m4lgth)/2,0)}
432 line invis to rvec_(rp_len,0) ',
433 `m4_two(`sl_ttbox',m4lgth,$@)') dnl
434 popdef(`m4lgth', `m4wdth', `m4name', `m4box', `m4text', `m4supp') ')
435
436 `sl_rectifier(ttbox args)'
437 define(`sl_rectifier',
438 `pushkeys_(`$2',`lgth:sl_ttboxlen_; wdth:sl_ttboxwid_; name:Body:N')dnl
439 sl_ttbox($@)
440 { line from m4name.ne to m4name.sw
441 AC: ACsymbol(at m4name.c+(-m4lgth/6, m4wdth/4),,,R)
442 DC: DCsymbol(at m4name.c+( m4lgth/6,-m4wdth/4),,,R) } dnl
443 popdef(`m4lgth',`m4wdth',`m4name') ')
444
445 `sl_inverter(ttbox args)'
446 define(`sl_inverter',
447 `pushkeys_(`$2',`lgth:sl_ttboxlen_; wdth:sl_ttboxwid_; name:Body:N')dnl
448 sl_ttbox($@)
449 { line from m4name.ne to m4name.sw
450 DC: DCsymbol(at m4name.c+(-m4lgth/6, m4wdth/4),,,R)
451 AC: ACsymbol(at m4name.c+( m4lgth/6,-m4wdth/4),,,R) } dnl
452 popdef(`m4lgth',`m4wdth',`m4name') ')
453
454 `m4_one( `elementname',
455 linespec (placeholder not used),
456 body keys,
457 breaker keys or S[n]: keys )'
458 `Draw the breaker slash in the element stem'
459 define(`m4_one',
460 `pushkeys_(`$4',lgth:sl_breakersize_; sep:-1)define(`m4s_p',`ifelse(m4sep,(-1),
461 `pushkey_(`$3',sep,sl_breakersep_)`'m4sep`'popdef(`m4sep')',m4sep)')dnl
462 M4end: last line.end
463 {ifelse(regexp(`$4',^ *S),-1,
464 `ifelse(`$4',,,
465 `line to last line.end-vec_(m4lgth+m4s_p,0)
466 pushdef(`m4bri',`ifelse(`$4',C,,`$4',O,`box=fill_(0)')')dnl
467 sl_breaker(to rvec_(m4lgth,0),`$4';m4bri;name=Br) popdef(`m4bri')')
468 $1(to M4end,`$3')',
469 `{ $1(to M4end,`$3') }
470 ifelse(`$4',,,
471 `define(`m4in',`ifelse(`$4',S,1,`$4',S:,1,
472 `patsubst(`$4',.*S\([0-9][0-9]*\):?.*,\1)')')dnl
473 define(`m4inkey',`patsubst(`$4',^ *S[0-9]*:?)') pushkey_(m4inkey,name,SL,N)
474 sl_slash(at M4end-vec_(m4lgth+m4s_p*2/3,0),
475 m4inkey;name=m4name,m4in:) popdef(`m4name')')')}
476 popdef(`m4lgth',`m4sep')')
477
478 `sl_breaker(linespec, type=[A|C][D]; ttbox keys)
479 C is for curved breaker
480 D is for sl_drawout with two chevrons
481 Default body name is Br'
482 define(`sl_breaker',
483 `pushkeys_(`$2',`lgth:sl_breakersize_; wdth:sl_breakersize_;
484 name:Br:N; type:A:N')dnl
485 ifinstr(ifinstr(m4type,CD,T,m4type,DC,T),T,
486 `m4ch_two(`cbreaker',`$1',,,m4name)',
487 m4type,C,
488 `cbreaker(`$1',,,m4name)',
489 m4type,D,
490 `m4ch_two(`sl_ttbox',`$1',
491 lgth=m4lgth;wdth=m4wdth;`$2'ifinstr(`$2',name=,;name=m4name))',
492 `$2',X;,
493 `sl_ttbox(`$1',supp=line from NW to SE
494 line from NE to SW;lgth=m4lgth;wdth=m4wdth;`$2';name=m4name)',
495 `$2',/;,
496 `sl_ttbox(`$1',
497 supp=line from SE to NW;lgth=m4lgth;wdth=m4wdth;`$2';name=m4name)',
498 `$2',\;,
499 `sl_ttbox(`$1',
500 supp=line from NE to SW;lgth=m4lgth;wdth=m4wdth;`$2';name=m4name)',
501 `sl_ttbox(`$1',lgth=m4lgth;wdth=m4wdth;`$2')' ) dnl
502 popdef(`m4lgth', `m4wdth', `m4name', `m4type') ')
503
504 `sl_reactor(linespec,keys,breaker keys,breaker keys)
505 keys=
506 name=Name (body name, default Body);
507 diam=expr;
508 Default breakers BrI, BrO'
509 define(`sl_reactor',
510 `pushkeys_(`$2',`diam:sl_diskdia_*2/3;name:Body:N')dnl
511 ifelse(`$3'`$4',,
512 `eleminit_(`$1')
513 { line to rvec_(rp_len/2,0) then to rvec_(rp_len/2,-m4diam/2); round
514 arc rad m4diam/2 cw from Here to rvec_(m4diam/2,m4diam/2) \
515 with .c at rvec_(0,m4diam/2); round
516 line to rvec_(rp_len/2-m4diam/2,0) }
517 {m4name: [ box invis ht m4diam wid m4diam ] at rvec_(rp_len/2,0)}
518 line invis to rvec_(rp_len,0) ',
519 `m4_two(`sl_reactor',m4diam,$@)') dnl
520 popdef(`m4diam',`m4name') ')
521
522 `sl_drawout(linespec, keys, R)
523 Drawout (i.e. plugin) chevron element;
524 keys: type=T; (truncated leads)
525 lgth=expr; (body size)
526 wdth=expr;
527 name=Name; (body name)
528 line= line attributes (e.g. thick 2)
529 arg3=R reverse direction'
530 define(`sl_drawout',
531 `pushkeys_(`$2',`lgth:sl_chevronsiz_; wdth:sl_chevronsiz_; type::N;
532 name:Body:N; line::N')dnl
533 eleminit_(`$1',ifelse(m4type,T,m4lgth))
534 ifelse(`$3',R,`{M4ds: Here; move to last line.end; rp_ang = rp_ang+pi_')
535 {line to rvec_(rp_len/2,0)
536 m4name: [
537 S: Here; {line from rvec_(-m4lgth/2,m4wdth/2) to Here then
538 to rvec_(-m4lgth/2,-m4wdth/2) m4line }
539 E: rvec_(m4lgth/2,0); line from rvec_(0,m4wdth/2) to E then
540 to rvec_(0,-m4wdth/2) m4line ] with .S at Here
541 ifelse(m4type,T,,
542 line from last [].E to last [].E+vec_((rp_len-m4lgth)/2,0))}
543 ifelse(`$3',R,`rp_ang = rp_ang-pi_; move to M4ds}')
544 line invis to rvec_(rp_len,0) dnl
545 popdef(`m4lgth', `m4wdth', `m4type', `m4name', `m4line') ')
546
547 # Two-terminal utilities ##################################################
548
549 `Breakers or slashes in the input and output lines:
550 `m4_two(`2-term element macroname in quotes',
551 body length,
552 linespec,
553 body keys,
554 [Sn:] input breaker or slash keys,
555 [Sn:] output breaker or slash keys)'
556 In args 5 and 6 a prefix S: or Sn: draws slashes
557 (Default breaker names are BrI and BrO)
558 (Default slash names are SLI and SLO)'
559 define(`m4_two',
560 `pushkeys_(`$4',lgth:ifelse(`$2',,sl_ttboxlen_*2,`$2'); sep:-1)dnl
561 define(`m4s_pI',`ifelse(m4sep,(-1),
562 `pushkey_(`$5',sep,sl_breakersep_) m4sep popdef(`m4sep')',m4sep)')dnl
563 define(`m4s_pO',`ifelse(m4sep,(-1),
564 `pushkey_(`$6',sep,sl_breakersep_) m4sep popdef(`m4sep')',m4sep)')dnl
565 ifelse(regexp(`$5',^ *S),-1,
566 `define(`m4il',`ifelse(`$5',,0,
567 `pushkeys_(`$5',lgth:sl_breakersize_) m4lgth popdef(`m4lgth')')')dnl
568 define(`m4ol',`ifelse(`$6',,0,
569 `pushkey_(`$6',lgth,sl_breakersize_) m4lgth popdef(`m4lgth')')')dnl
570 eleminit_(`$3',max(elen_,m4lgth+m4il*3.5+m4ol*3.5+m4s_pI+m4s_pO))
571 M4end: last line.end
572 { line to last line.c-vec_((m4lgth + m4il + m4ol + m4s_pI+m4s_pO)/2,0)
573 pushdef(`m4bri',`ifelse(`$5',,,`$5',C,,`$5',O,`box=fill_(0)')')dnl
574 ifelse(`$5',,,`sl_breaker(to rvec_(m4il,0),`$5';m4bri;name=BrI)
575 line to rvec_(m4s_pI,0)')
576 $1(to rvec_(m4lgth,0),`$4',,,`$7',`$8')
577 pushdef(`m4bro',`ifelse(`$6',,,`$6',C,,`$6',O,`box=fill_(0)')')dnl
578 ifelse(`$6',,,`line to rvec_(m4s_pO,0)
579 sl_breaker(to rvec_(m4ol,0),`$6';m4bro;name=BrO)')
580 line to M4end popdef(`m4bri', `m4bro') }',
581 `eleminit_(`$3',max(elen_,m4lgth+(m4s_pI+m4s_pO)*2)) ; dnl slashes
582 M4end: last line.end
583 { $1(to M4end,`$4',,,`$7',`$8') }
584 ifelse(`$5',,,`define(`m4in',`ifelse(`$5',S,1,`$5',S:,1,
585 `patsubst(`$5',.*S\([0-9][0-9]*\):?.*,\1)')')dnl
586 define(`m4inkey',`patsubst(`$5',^ *S[0-9]*:?)')dnl
587 pushkey_(m4inkey,name,SLI,N)dnl
588 {sl_slash(at rvec_(rp_len/2-m4lgth/2-m4s_pI,0),
589 m4inkey;name=m4name,m4in:)} popdef(`m4name')')
590 ifelse(`$6',,,`define(`m4on',`ifelse(`$6',S,1,`$6',S:,1,
591 `patsubst(`$6',.*S\([0-9][0-9]*\):*.*,\1)')')dnl
592 define(`m4onkey',`patsubst(`$6',^ *S[0-9]*:?)')dnl
593 pushkey_(m4onkey,name,SLO,N)dnl
594 {sl_slash(at rvec_(rp_len/2+m4lgth/2+m4s_pO,0),
595 m4onkey;name=m4name,m4on:)} popdef(`m4name')') ')
596 line invis to M4end popdef(`m4lgth', `m4sep') ')
597
598 `Chevrons in the input and output lines:'
599 `m4ch_two(`2-term element macroname in quotes',
600 linespec,
601 body keys)'
602 define(`m4ch_two',
603 `define(`m4bl',`setkey_(`$3',lgth,dimen_*3/8) m4lgth')popdef(`m4lgth')dnl
604 eleminit_(`$2',dimen_*2)
605 M4start: Here; M4end: last line.end
606 M4elem: $1(to rvec_(m4bl+2*sl_chevronsiz_,0) with .c at last line.c,`$3')
607 sl_drawout(from last line.start-vec_(sl_chevronsiz_,0) to last line.start,
608 type=T,R)
609 line from last line.start to M4start
610 sl_drawout(from M4elem.end to M4elem.end+vec_(sl_chevronsiz_,0),type=T)
611 line to M4end
612 line invis from M4start to M4end')
613
614 # Composite elements ###################################################
615
616 `sl_ct( at position, keys, R|L|U|D|degrees )
617 keys:
618 type=L|N|S[n] (default L;
619 Sn draws n slashes, default 2)
620 scale=expr (default 1);
621 grnd=degrees (type S or N);
622 stemlgth=expr (type L or S);
623 sep=expr (type S slashes to head separation);
624 type=N omits the stem and slashes
625 type=Sn draws n slashes, e.g., type=S2
626 Arg3 sets the stem direction'
627 define(`sl_ct',`[ Origin: Here
628 pushkeys_(`$2', type:L:N; scale:1; grnd::N ) dnl
629 define(`m4scf',`(m4scale*1.2)')dnl
630 setdir_(`$3',R)
631 ifinstr(m4type,L,`define(`m4lw',`dimen_/8*m4scf')dnl
632 L: inductor(to vec_(2*m4lw,0) with .c at Origin,,2,,m4lw); C: L.c
633 pushkey_(`$2',stemlgth,dimen_/5)dnl
634 line from L.start to L.start+vec_(0,-m4stemlgth)
635 Tstart: Here
636 line from L.end to L.end+vec_(0,-m4stemlgth)
637 Tend: Here
638 line from L.c to L.c+vec_(0,-m4stemlgth)
639 Tc: Here popdef(`m4stemlgth')',
640 m4type,S,
641 `C: circle rad sourcerad_*m4scale*0.5 at Origin
642 pushkeys_(`$2',stemlgth:C.rad*6; sep:C.rad*2)dnl
643 Stem: line from C to C+vec_(m4stemlgth,0) chop C.rad chop 0; Tc: Here
644 ifelse(m4grnd,,,`ground(at C+(Rect_(C.rad,m4grnd)),,,m4grnd)'); \
645 pushdef(`m4n',`ifelse(m4type,S,2,`eval(patsubst(m4type,.*S))')')dnl
646 sl_slash(at C+vec_(C.rad+m4sep,0),,m4n:rp_ang*rtod_)
647 popdef(`m4stemlgth',`m4sep',`m4n')',
648 m4type,N,
649 `C: circle rad sourcerad_*m4scale*0.5 at Origin
650 ifelse(m4grnd,,,`ground(at C+(Rect_(C.rad,m4grnd)),,,m4grnd)') ')
651 resetdir_ popdef(`m4type', `m4scale', `m4grnd' )
652 ] with .Origin ifelse(`$1',,at Here,`$1') ')
653
654 `sl_busbar( linespec, np, keys )
655 Labels P1, P2 ... Pnp are defined on the line.
656 keys: line=line attributes;
657 port=D; (dotted ports)
658 indent=expr;
659 (distance of points from Start and End)
660 The bus extends beyond the first and last points
661 by the indent value (default) sl_busindent_'
662 define(`sl_busbar',
663 `define(`m4npoints',`ifelse(`$2',,2,`$2')')dnl
664 pushkeys_(`$3',`line:thick sl_busthick_:N; port::N; indent:sl_busindent_')dnl
665 [ tmp_ang = rp_ang
666 eleminit_(`$1',(m4npoints-1)*dimen_)
667 Start: last line.start; End: last line.end
668 Line: line from Start to End m4line; C: Line.c
669 M: move from Start to End chop m4indent
670 for_(1,m4npoints,1,
671 `P`'m4x: (m4x-1)/(m4npoints-1) between M.start and M.end dnl
672 ifinstr(m4port,D,` ;dot(at P`'m4x)')')
673 point_(tmp_ang) ] popdef(`m4line', `m4port', `m4indent') ')
674
675 `sl_slash( at position, keys, [n:]R|L|U|D|degrees)
676 keys:
677 lines=line attributes;
678 size=expr (default ht dimen_/3); '
679 define(`sl_slash',`[ C: Here
680 pushkeys_(`$2',lines::N; size:dimen_/3 )dnl
681 define(`m4nsl',`ifelse(`$3',,1,`ifinstr(`$3',:,patsubst(`$3',:.*),1)')')dnl
682 pushdef(`m4ACd',`ifinstr(`$3',:,`patsubst(`$3',.*:)',`$3')')dnl
683 setdir_(ifelse(m4ACd,,`ifdef(`m4a_',rp_ang*rtod_,0)',m4ACd))
684 dx = m4size/2.5
685 for_(1,m4nsl,1, `{ line to vec_(m4size/sqrt(3),m4size) m4lines \
686 with .c at C+vec_((m4x-(1+m4nsl)/2)*dx,0) } ')
687 resetdir_ popdef(`m4lines', `m4size',`m4ACd')
688 `$8' ] ifelse(`$1',,at Here,`$1')')
689
690 # #######################################################################
691
692 divert(0)dnl