2012-03-31 00:53:51 +03:00
|
|
|
#!/bin/sh -e
|
|
|
|
#
|
|
|
|
# sym2xps - Convert a symbol from a Kicad library to Postscript with expanded
|
|
|
|
# pin types
|
|
|
|
#
|
|
|
|
# Copyright 2012 by Werner Almesberger
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
usage()
|
|
|
|
{
|
2012-04-12 05:10:42 +03:00
|
|
|
echo "usage: $0 library symbol unit tmpdir outfile" 1>&2
|
2012-03-31 00:53:51 +03:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lib=$1
|
|
|
|
sym=$2
|
2012-04-12 05:10:42 +03:00
|
|
|
unit=$3
|
|
|
|
tmp=$4
|
|
|
|
out=$5
|
2012-03-31 00:53:51 +03:00
|
|
|
|
2012-04-12 05:52:43 +03:00
|
|
|
[ "$lib" ] && [ "$sym" ] && [ "$unit" ] && [ "$tmp" ] && [ "$out" ] || usage
|
2012-03-31 00:53:51 +03:00
|
|
|
|
|
|
|
[ -r "$lib" ] || {
|
|
|
|
echo "$lib: not found" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2012-04-17 15:53:51 +03:00
|
|
|
grep "^DEF $sym " "$lib" >/dev/null || grep "^DEF ~$sym " "$lib" >/dev/null || {
|
2012-03-31 00:53:51 +03:00
|
|
|
echo "\"$sym\" not found in $lib" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
[ "${tmp#/}" = "$tmp" ] && tmp=`pwd`/$tmp
|
|
|
|
[ "${out#/}" = "$out" ] && out=`pwd`/$out
|
|
|
|
|
|
|
|
mkdir "$tmp"
|
|
|
|
|
|
|
|
trap "rm -rf '$tmp'" 0
|
|
|
|
|
|
|
|
expand-pintype "$lib" "$tmp"/tmp.lib
|
|
|
|
|
|
|
|
cat <<EOF >"$tmp"/tmp.pro
|
|
|
|
[eeschema]
|
|
|
|
version=1
|
|
|
|
[eeschema/libraries]
|
|
|
|
LibName1=./tmp
|
|
|
|
EOF
|
|
|
|
|
|
|
|
X=6000
|
|
|
|
Y=4000
|
|
|
|
|
2016-09-04 19:01:37 +03:00
|
|
|
#
|
|
|
|
# @@@ Known bug: doesn't handle spaces in component names (F1) well.
|
|
|
|
# Example: usb_a_plug.lib had F1 "USB_A_PLUG " 0 ...
|
|
|
|
#
|
|
|
|
|
2012-04-12 06:05:12 +03:00
|
|
|
sed "\@^DEF $sym @,/^ENDDEF/p;d" "$lib" |
|
2012-04-13 00:09:55 +03:00
|
|
|
awk '/^F. / { if ($1 == "F0") sub(/"$/, "?\"", $2);
|
2012-04-12 05:45:29 +03:00
|
|
|
print substr($1, 1, 1), substr($1, 2, 1), $2,
|
|
|
|
$6, '$X'+$3, '$Y'+$4, $5, " 0000", $8, $9 }' >"$tmp"/fx.tmp
|
|
|
|
#F field_number "text" orientation posX posY size Flags (see below)
|
|
|
|
#F0 reference posx posy text_size text_orient visibile htext_justify vtext_justify
|
|
|
|
|
2012-03-31 00:53:51 +03:00
|
|
|
cat <<EOF >"$tmp"/tmp.sch
|
|
|
|
EESchema Schematic File Version 2 date Mon Mar 26 09:29:33 2012
|
|
|
|
LIBS:dummy
|
|
|
|
EELAYER 43 0
|
|
|
|
EELAYER END
|
2016-09-04 19:01:37 +03:00
|
|
|
\$Descr A4 0 0
|
|
|
|
\$EndDescr
|
2012-03-31 00:53:51 +03:00
|
|
|
\$Comp
|
|
|
|
L X$sym ??
|
2012-04-12 05:10:42 +03:00
|
|
|
U $unit 1 00000000
|
2012-03-31 00:53:51 +03:00
|
|
|
P $X $Y
|
2012-04-12 05:45:29 +03:00
|
|
|
`cat "$tmp"/fx.tmp`
|
2012-04-12 05:10:42 +03:00
|
|
|
$unit $X $Y
|
2012-03-31 00:53:51 +03:00
|
|
|
1 0 0 -1
|
|
|
|
\$EndComp
|
|
|
|
\$EndSCHEMATC
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cd "$tmp"
|
2016-09-04 19:01:37 +03:00
|
|
|
#eeschema --plot=ps "$tmp/tmp.sch"
|
|
|
|
eeplot -o "$tmp/tmp.pdf" "$tmp/tmp.pro"
|
|
|
|
pdftops "$tmp/tmp.pdf" "$tmp/tmp.ps"
|
|
|
|
mv "$tmp/tmp.ps" "$out"
|