File: gschem2pcb

package info (click to toggle)
geda-gnetlist 20050313-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,092 kB
  • ctags: 702
  • sloc: lisp: 5,519; ansic: 3,809; sh: 3,647; makefile: 291
file content (123 lines) | stat: -rwxr-xr-x 4,132 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/sh

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#JM Routoure
#17/01/2000


# Create a PCB file and a netlist for the pcb program
# Usage : gschem2pcb filename.sch
#		-> gives two files : filename.net (the netlist) and
#			filename.pcb (the board)
# It needs gawk and sed and also the gnet-PCBboard.scm in the scheme
# directory of gEDA
# It also needs a modification of the common.m4 file of the pcb program:
# at the end of the common.m4 program. The include keyword must be replace by :
#
#
#include(/usr/X11R6/lib/X11/pcb/m4/connector.inc)
#include(/usr/X11R6/lib/X11/pcb/m4/dil.inc)
#include(/usr/X11R6/lib/X11/pcb/m4/misc.inc)
#include(/usr/X11R6/lib/X11/pcb/m4/plcc.inc)
#include(/usr/X11R6/lib/X11/pcb/m4/to.inc)
#include(/usr/X11R6/lib/X11/pcb/m4/qfp.inc)


if [ -z  $1 ]; then
	echo "You must indicate a file generated by gschem"
	echo
       	exit 1
	fi

# Search for the beginning of the filename assuming it ends by .sch
FILENAME=`echo "$1" | sed 's/.sch//g' `
PCBFILENAME=$FILENAME.pcb

# test if a .pcb file exists
if [ -e $PCBFILENAME ]; then
	#	echo " The file $PCBFILENAME.pcb exits "
	
	PCBNEWFILENAME=$FILENAME.new.pcb
	PCBTEMPFILENAME=$FILENAME.temp.pcb
	NETFILENAME=$FILENAME.net
	LISTFILE=$FILENAME.list
	NEWLISTFILE=$FILENAME.new.list
	
	gnetlist -g PCB -o $NETFILENAME $1  
	gnetlist -g PCBboard -o $PCBTEMPFILENAME $1 
	echo
	awk 'BEGIN {FS=","}
		/^PKG_*/{
		footprint=$1
		sub(/PKG_/,"",footprint)
		sub(/\(.*$/,"",footprint)
		name=$2
		value=substr($3,0,length($3)-1)
		printf("Error: the footprint %s for the device %s does not exist\n",footprint,$2,value)
		}' $PCBTEMPFILENAME
	awk '/^Element\(.*/{printf("%s\t%s\t\n",$3,$4)}' $PCBFILENAME|sort > $LISTFILE
	awk '/^Element\(.*/{printf("%s\t%s\t\n",$3,$4)}' $PCBTEMPFILENAME|sort > $NEWLISTFILE
	UREF=`diff $NEWLISTFILE $LISTFILE | awk '/</{printf("%s\n",$2)}' -`
	#Search for UREF if $PCBTEMPFILENAME and create $PCBNEWFILENAME
	#Header of the pcb file
	head -n 5 $PCBTEMPFILENAME > $PCBNEWFILENAME
	for f in `echo $UREF`; do
		echo "Find new element $f"
                LINE=`grep -n ^Element.\*$f $PCBTEMPFILENAME|sed 's/:.*$//g' `
		awk -v line=$LINE '{if (NR>=line)
					{print
					if ($1==")") exit}
					}' $PCBTEMPFILENAME >> $PCBNEWFILENAME
					
	done
	# End of the pcb file
	tail -n 24 $PCBTEMPFILENAME >> $PCBNEWFILENAME
	
	# Un peu de mnage (in french in the texte)
	rm $PCBTEMPFILENAME $NEWLISTFILE $LISTFILE
else 
	
	NETFILENAME=$FILENAME.net
	# Creation of the netlist file
	echo
	gnetlist -g PCB -o $NETFILENAME $1 
	gnetlist -g PCBboard -o $PCBFILENAME $1 
	# Test if a footprint has not been found
	awk 'BEGIN {FS=","}
		/^PKG_*/{
		footprint=$1
		sub(/PKG_/,"",footprint)
		sub(/\(.*$/,"",footprint)
		name=$2
		value=substr($3,0,length($3)-1)
		printf("Error: the footprint %s for the device %s does not exist\n",footprint,$2,value)
		}' $PCBFILENAME

	exit 0
fi

# Creation of the pcb file

# Creation of the different elements. It uses the footprint attribute in 
# gschem to see what the footprint is.
# see .inc files of pcb to understand the name of the footprint. Here are some tips :
# naming of device in pcb is something like PKG_XX(Description, Uref, value)
# where XX is the name of the footprint.
# optional argument can be use : for the Dual in line footprint we have
# PKG_DIL( Description, Uref, value, Number of pin, Width) 
# the device attribute in gschem should then be DIL  8 300 and no space char
# should be present in the name,uref and device attributes !