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 format))
24 ;; This is a list of attributes which are propogated to the pcb
25 ;; elements. Note that refdes, value, and footprint need not be
27 (define pcbfwd:element-attrs
30 "manufacturer_part_number"
35 (define (pcbfwd:pinfmt pin)
36 (format #f "~a-~a" (car pin) (car (cdr pin)))
39 (define (pcbfwd:each-pin net pins port)
40 (if (not (null? pins))
41 (let ((pin (car pins)))
42 (format port "Netlist(Add,~a,~a)~%" net (pcbfwd:pinfmt pin))
43 (pcbfwd:each-pin net (cdr pins) port))))
45 (define (pcbfwd:each-net netnames port)
46 (if (not (null? netnames))
47 (let ((netname (car netnames)))
48 (pcbfwd:each-pin netname (gnetlist:get-all-connections netname) port)
49 (pcbfwd:each-net (cdr netnames) port))))
51 (define (pcbfwd:each-attr refdes attrs port)
52 (if (not (null? attrs))
53 (let ((attr (car attrs)))
54 (format port "ElementSetAttr(~a,~a,~a)~%"
57 (gnetlist:get-package-attribute refdes attr))
58 (pcbfwd:each-attr refdes (cdr attrs) port))))
60 ;; write out the pins for a particular component
61 (define pcbfwd:component_pins
62 (lambda (port package pins)
63 (if (and (not (null? package)) (not (null? pins)))
70 (display "ChangePinName(" port)
71 (display package port)
74 (set! pinnum (gnetlist:get-attribute-by-pinnumber package pin "pinnumber"))
79 (set! label (gnetlist:get-attribute-by-pinnumber package pin "pinlabel"))
80 (if (string=? label "unknown")
86 (pcbfwd:component_pins port package (cdr pins))
92 (define (pcbfwd:each-element elements port)
93 (if (not (null? elements))
94 (let* ((refdes (car elements))
95 (value (gnetlist:get-package-attribute refdes "value"))
96 (footprint (gnetlist:get-package-attribute refdes "footprint"))
99 (format port "ElementList(Need,~a,~a,~a)~%" refdes footprint value)
100 (pcbfwd:each-attr refdes pcbfwd:element-attrs port)
101 (pcbfwd:component_pins port refdes (gnetlist:get-pins refdes))
103 (pcbfwd:each-element (cdr elements) port))))
105 (define (pcbfwd output-filename)
106 (let ((port (open-output-file output-filename)))
107 (format port "Netlist(Freeze)\n")
108 (format port "Netlist(Clear)\n")
109 (pcbfwd:each-net (gnetlist:get-all-unique-nets "dummy") port)
110 (format port "Netlist(Sort)\n")
111 (format port "Netlist(Thaw)\n")
112 (format port "ElementList(Start)\n")
113 (pcbfwd:each-element packages port)
114 (format port "ElementList(Done)\n")
115 (close-output-port port)))