1 ; gEDA - GNU Electronic Design Automation
3 ; Copyright (C) 2000-2001 Stefan Petersen (spe@stacken.kth.se)
7 ; This program is free software; you can redistribute it and/or modify
8 ; it under the terms of the GNU General Public License as published by
9 ; the Free Software Foundation; either version 2 of the License, or
10 ; (at your option) any later version.
12 ; This program is distributed in the hope that it will be useful,
13 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ; GNU General Public License for more details.
17 ; You should have received a copy of the GNU General Public License
18 ; along with this program; if not, write to the Free Software
19 ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
22 (define *last-aperture-type* '())
26 (define (net:get-start net)
28 (define (net:get-stop net)
30 (define (net:get-aperture net)
32 (define (net:get-interpolation net)
34 (define (net:get-cirseg net)
37 (define (aperture:get-number aperture)
38 (list-ref aperture 0))
39 (define (aperture:get-type aperture)
40 (list-ref aperture 1))
41 (define (aperture:get-sizes aperture)
42 (list-tail aperture 2))
44 (define (ps-preamble info port)
46 (display "%generated by gerbv\n\n" port)
47 (display "/inch {72 mul} def\n" port)
48 (display "/mm {25.4 div inch} def\n" port)
50 (display "1.5 inch 3 inch translate\n" port)
52 (if (equal? (assoc-ref info 'polarity) 'positive)
54 (display "/Black {0 setgray} def\n" port)
55 (display "/White {1 setgray} def\n" port))
57 (display "/Black {1 setgray} def % Polarity reversed\n" port)
58 (display "/White {0 setgray} def\n" port)))
60 (display "/circle { % x y id od\n" port)
61 (display " gsave\n" port)
62 (display " 3 index 3 index moveto\n" port)
63 (display " 3 index 3 index 3 2 roll % Fix arguments\n" port)
64 (display " 2 div % d given, need r\n" port)
65 (display " 0 360 arc Black fill % outer\n" port)
66 (display " 2 div % d given, need r\n" port)
67 (display " 0 360 arc White fill %inner\n" port)
68 (display "grestore\n" port)
69 (display "} def\n" port)
71 (display "/rectangle { % x y xl yl\n" port)
72 (display " gsave\n" port)
73 (display " newpath\n" port)
74 (display " 1 setlinewidth\n" port)
75 (display " 3 index 2 index 2 div sub\n" port)
76 (display " 3 index 2 index 2 div add moveto\n" port)
77 (display " 1 index 0 rlineto\n" port) ; ->
78 (display " dup -1 mul 0 exch rlineto\n" port) ; \!/
79 (display " 1 index -1 mul 0 rlineto\n" port) ; <-
80 (display " dup 0 exch rlineto\n" port) ; /!\
81 (display " pop pop pop pop closepath Black fill\n" port)
82 (display " grestore\n" port)
83 (display "} def\n" port)
85 ; Make box for inverted print outs. Make it little bigger than limits.
86 (display "gsave 72 setlinewidth newpath\n" port)
87 (let ((min-x (number->string (- (assoc-ref info 'min-x) 200)))
88 (min-y (number->string (- (assoc-ref info 'min-y) 200)))
89 (max-x (number->string (+ (assoc-ref info 'max-x) 200)))
90 (max-y (number->string (+ (assoc-ref info 'max-y) 200)))
91 (unit (assoc-ref info 'unit)))
92 (display (string-append max-x " " unit " ") port)
93 (display (string-append max-y " " unit " moveto\n") port)
94 (display (string-append max-x " " unit " ") port)
95 (display (string-append min-y " " unit " lineto\n") port)
96 (display (string-append min-x " " unit " ") port)
97 (display (string-append min-y " " unit " lineto\n") port)
98 (display (string-append min-x " " unit " ") port)
99 (display (string-append max-y " " unit " lineto\n") port))
100 (display "closepath White fill grestore\n" port)
103 (define (print-ps-element element aperture format info port)
104 (let* ((x (car (net:get-stop element)))
105 (y (cdr (net:get-stop element)))
106 (aperture-type (car (net:get-aperture element)))
107 (aperture-state (cdr (net:get-aperture element)))
108 (unit (assoc-ref info 'unit)))
109 (cond ((eq? aperture-state 'exposure-off)
110 (handle-line-aperture aperture-type aperture unit port)
111 (print-position x y unit port)
112 (display " moveto\n" port))
113 ((eq? aperture-state 'exposure-on)
114 (handle-line-aperture aperture-type aperture unit port)
115 (print-position x y unit port)
116 (display " lineto\n" port))
117 ((eq? aperture-state 'exposure-flash)
118 (print-position x y unit port)
120 (print-flash-aperture aperture-type aperture unit port)))
124 (define (print-position x y unit port)
125 (display x port) ; X axis
129 (display y port) ; Y axis
133 (define (handle-line-aperture aperture-type aperture unit port)
134 (cond ((null? *last-aperture-type*) ; First time
135 (set! *last-aperture-type* aperture-type)
138 (display " setlinewidth\n" port))
139 ((not (eq? *last-aperture-type* aperture-type)) ; new aperture
140 (display "stroke\n" port)
141 (display *last-x* port) ; X Axis
145 (display *last-y* port)
148 (display " moveto\n" port)
149 (display (get-aperture-size aperture-type aperture) port)
152 (display " setlinewidth\n" port)
153 (set! *last-aperture-type* aperture-type))))
156 (define (print-flash-aperture aperture-type aperture unit port)
157 (let* ((aperture-description (assv aperture-type aperture))
158 (type (aperture:get-type aperture-description))
159 (sizes (aperture:get-sizes aperture-description)))
163 (display (car sizes) port)
168 (display (car sizes) port)
172 (display (cadr sizes) port)
178 (display " circle" port))
180 (display " rectangle " port))
182 (display " rectangle % oval" port))
184 (display " moveto % polygon" port))
186 (display " moveto % macro" port))
188 (display " moveto %unknown" port))))
191 (define (get-aperture-size aperture-type aperture)
192 (let ((aperture-desc (assv aperture-type aperture)))
194 (car (aperture:get-sizes aperture-desc)))))
197 (define (generate-ps netlist aperture info format port)
198 (ps-preamble info port)
199 (for-each (lambda (element)
200 (print-ps-element element aperture format info port))
202 (display "stroke\nshowpage\n" port))
205 (define (main netlist aperture info format filename)
206 (display "Warning! This backend is incomplete and known ")
207 (display "to generate incorrect PostScript files\n")
208 (let ((outfile (string-append filename ".ps")))
209 (display (string-append "Output file will be " outfile "\n"))
210 (call-with-output-file outfile
212 (generate-ps (reverse netlist) aperture info format port)))))