Root/genkicat/sym2xps

1#!/bin/sh -e
2#
3# sym2xps - Convert a symbol from a Kicad library to Postscript with expanded
4# pin types
5#
6# Copyright 2012 by Werner Almesberger
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13
14
15usage()
16{
17    echo "usage: $0 library symbol unit tmpdir outfile" 1>&2
18    exit 1
19}
20
21
22lib=$1
23sym=$2
24unit=$3
25tmp=$4
26out=$5
27
28[ "$lib" ] && [ "$sym" ] && [ "$unit" ] && [ "$tmp" ] && [ "$out" ] || usage
29
30[ -r "$lib" ] || {
31    echo "$lib: not found" 1>&2
32    exit 1
33}
34
35grep "^DEF $sym " "$lib" >/dev/null || grep "^DEF ~$sym " "$lib" >/dev/null || {
36    echo "\"$sym\" not found in $lib" 1>&2
37    exit 1
38}
39
40[ "${tmp#/}" = "$tmp" ] && tmp=`pwd`/$tmp
41[ "${out#/}" = "$out" ] && out=`pwd`/$out
42
43mkdir "$tmp"
44
45trap "rm -rf '$tmp'" 0
46
47expand-pintype "$lib" "$tmp"/tmp.lib
48
49cat <<EOF >"$tmp"/tmp.pro
50[eeschema]
51version=1
52[eeschema/libraries]
53LibName1=./tmp
54EOF
55
56X=6000
57Y=4000
58
59#
60# @@@ Known bug: doesn't handle spaces in component names (F1) well.
61# Example: usb_a_plug.lib had F1 "USB_A_PLUG " 0 ...
62#
63
64sed "\@^DEF $sym @,/^ENDDEF/p;d" "$lib" |
65  awk '/^F. / { if ($1 == "F0") sub(/"$/, "?\"", $2);
66    print substr($1, 1, 1), substr($1, 2, 1), $2,
67    $6, '$X'+$3, '$Y'+$4, $5, " 0000", $8, $9 }' >"$tmp"/fx.tmp
68#F field_number "text" orientation posX posY size Flags (see below)
69#F0 reference posx posy text_size text_orient visibile htext_justify vtext_justify
70
71cat <<EOF >"$tmp"/tmp.sch
72EESchema Schematic File Version 2 date Mon Mar 26 09:29:33 2012
73LIBS:dummy
74EELAYER 43 0
75EELAYER END
76\$Descr A4 0 0
77\$EndDescr
78\$Comp
79L X$sym ??
80U $unit 1 00000000
81P $X $Y
82`cat "$tmp"/fx.tmp`
83    $unit $X $Y
84    1 0 0 -1
85\$EndComp
86\$EndSCHEMATC
87EOF
88
89cd "$tmp"
90#eeschema --plot=ps "$tmp/tmp.sch"
91eeplot -o "$tmp/tmp.eps" "$tmp/tmp.pro"
92mv "$tmp/tmp.eps" "$out"
93

Archive Download this file

Branches:
master



interactive