1 ;;; gEDA - GPL Electronic Design Automation
2 ;;; gnetlist - gEDA Netlist
3 ;;; Copyright (C) 1998-2008 Ales Hvezda
4 ;;; Copyright (C) 1998-2008 gEDA Contributors (see ChangeLog for details)
6 ;;; This program is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 2 of the License, or
9 ;;; (at your option) any later version.
11 ;;; This program is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with this program; if not, write to the Free Software
18 ;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 ;; PCB forward annotation script
22 (use-modules (ice-9 regex))
23 (use-modules (ice-9 format))
25 ;; This is a list of attributes which are propogated to the pcb
26 ;; elements. Note that refdes, value, and footprint need not be
28 (define pcbfwd:element-attrs
31 "manufacturer_part_number"
36 (define (pcbfwd:quote-string s)
38 (regexp-substitute/global #f "\"" s 'pre "\\\"" 'post)
42 (define (pcbfwd:pinfmt pin)
43 (format #f "~a-~a" (car pin) (car (cdr pin)))
46 (define (pcbfwd:each-pin net pins port)
47 (if (not (null? pins))
48 (let ((pin (car pins)))
49 (format port "Netlist(Add,~a,~a)~%" net (pcbfwd:pinfmt pin))
50 (pcbfwd:each-pin net (cdr pins) port))))
52 (define (pcbfwd:each-net netnames port)
53 (if (not (null? netnames))
54 (let ((netname (car netnames)))
55 (pcbfwd:each-pin netname (gnetlist:get-all-connections netname) port)
56 (pcbfwd:each-net (cdr netnames) port))))
58 (define (pcbfwd:each-attr refdes attrs port)
59 (if (not (null? attrs))
60 (let ((attr (car attrs)))
61 (format port "ElementSetAttr(~a,~a,~a)~%"
62 (pcbfwd:quote-string refdes)
63 (pcbfwd:quote-string attr)
64 (pcbfwd:quote-string (gnetlist:get-package-attribute refdes attr)))
65 (pcbfwd:each-attr refdes (cdr attrs) port))))
67 ;; write out the pins for a particular component
68 (define pcbfwd:component_pins
69 (lambda (port package pins)
70 (if (and (not (null? package)) (not (null? pins)))
77 (display "ChangePinName(" port)
78 (display (pcbfwd:quote-string package) port)
81 (set! pinnum (gnetlist:get-attribute-by-pinnumber package pin "pinnumber"))
86 (set! label (gnetlist:get-attribute-by-pinnumber package pin "pinlabel"))
87 (if (string=? label "unknown")
90 (display (pcbfwd:quote-string label) port)
93 (pcbfwd:component_pins port package (cdr pins))
99 (define (pcbfwd:each-element elements port)
100 (if (not (null? elements))
101 (let* ((refdes (car elements))
102 (value (gnetlist:get-package-attribute refdes "value"))
103 (footprint (gnetlist:get-package-attribute refdes "footprint"))
106 (format port "ElementList(Need,~a,~a,~a)~%"
107 (pcbfwd:quote-string refdes)
108 (pcbfwd:quote-string footprint)
109 (pcbfwd:quote-string value))
110 (pcbfwd:each-attr refdes pcbfwd:element-attrs port)
111 (pcbfwd:component_pins port refdes (gnetlist:get-pins refdes))
113 (pcbfwd:each-element (cdr elements) port))))
115 (define (pcbfwd output-filename)
116 (let ((port (open-output-file output-filename)))
117 (format port "Netlist(Freeze)\n")
118 (format port "Netlist(Clear)\n")
119 (pcbfwd:each-net (gnetlist:get-all-unique-nets "dummy") port)
120 (format port "Netlist(Sort)\n")
121 (format port "Netlist(Thaw)\n")
122 (format port "ElementList(Start)\n")
123 (pcbfwd:each-element packages port)
124 (format port "ElementList(Done)\n")
125 (close-output-port port)))