Rev 20 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | reyssat | 1 | #! /bin/sh |
2 | # |
||
3 | # Regeneration of index files. |
||
4 | |||
5 | if [ -z "$1" ]; then |
||
6 | cat <<@ |
||
7 | This script transforms a ps circuit file produced by xcircuit to |
||
8 | the WIMS data file. |
||
9 | |||
10 | Usage: ./ps2data inputfile |
||
11 | |||
12 | Note. In the ps file, a acsource or npn symbol means a component to be |
||
13 | filled. The text string XXX means the annotation of the |
||
14 | nearest component. Use the tap to delimite the drawing zone |
||
15 | which must start by the center (0,0) and goes up and left. |
||
16 | The first component of a pair should be drawn in red. |
||
17 | |||
18 | Each grid in xcircuit is equivant to 0.5 in WIMS data file. |
||
19 | |||
20 | Texts with negative coordinates will be ignored, except if it |
||
15531 | bpr | 21 | starts with the string "DESC: ". In which case the rest of |
20 | reyssat | 22 | the string will be come the description. |
23 | |||
24 | Fixed wires must be put on width 3. Component-dependent dynamic wires |
||
25 | should have width < 3, with no turns and no ending dots, and should |
||
26 | go (overlay) into the component. |
||
27 | |||
28 | The only allowed components are dot, acsource, npn, pnp. |
||
29 | |||
30 | @ |
||
31 | exit |
||
32 | fi |
||
33 | |||
34 | if [ -n "$w_module" ]; then |
||
35 | echo "This script is to be used manually. It should not be run by WIMS." |
||
36 | exit |
||
37 | fi |
||
38 | |||
39 | inp=$1 |
||
40 | [ -f "$inp" ] || inp=$1.ps |
||
41 | [ -f "$inp" ] || exit |
||
42 | |||
43 | current=`pwd` |
||
44 | cd `dirname $0` |
||
45 | homedir=`pwd` |
||
46 | tmpdir=/tmp |
||
47 | cd $current |
||
48 | |||
49 | # Translation size factor |
||
50 | sf=64 |
||
51 | |||
52 | header=$tmpdir/circ-header.ps1 |
||
53 | tail=$tmpdir/circ-tail.ps1 |
||
54 | |||
55 | rm -f $tmpdir/circ-* $2 |
||
56 | |||
57 | awk 'BEGIN {a=0}; |
||
58 | a==1 && length==0 {a++; next}; |
||
59 | a==2 && /^pgsave/ {a++;}; |
||
60 | /^%%Page: 1/ {a=1}; |
||
61 | a<2 {print >"'$header'"}; |
||
62 | a==2 && NF>0 {if($NF ~ /dot|polygon|label|acsource|tap|npn|pnp|scb|sce/) print; |
||
63 | else printf "%s ",$0}; |
||
64 | a>2 {print >"'$tail'"}; |
||
65 | ' $inp |\ |
||
66 | awk 'BEGIN {xrange=yrange=ccnt=tcnt=ext=0;sf='$sf'; |
||
67 | pcnt=0; ppcnt=0; pairer=0; wiring=""; dots=""; pairlist=""; |
||
68 | }; |
||
69 | END { |
||
70 | for(i=0;i<ccnt;i++) for(j=i+1;j<ccnt;j++) { |
||
71 | if(x[i]>x[j] || (x[i]==x[j] && y[i]<y[j])) { |
||
72 | t=x[i]; x[i]=x[j]; x[j]=t; |
||
73 | t=y[i]; y[i]=y[j]; y[j]=t; |
||
74 | t=o[i]; o[i]=o[j]; o[j]=t; |
||
75 | } |
||
76 | } |
||
77 | for(p=0;p<pcnt;p++) { |
||
78 | for(i=0;i<ccnt-1;i++) { |
||
79 | if(op[p]==1 && x[i]==xp[p] && y[i]==yp[p]+96) break; |
||
80 | if(op[p]==0 && x[i]==xp[p]-96 && y[i]==yp[p]) break; |
||
81 | } |
||
82 | if(i>=ccnt-1) continue; |
||
83 | if(op[p]==1) { |
||
84 | if(x[i+1]!=xp[p] || y[i+1]!=yp[p]-96) continue; |
||
85 | } |
||
86 | else { |
||
87 | for(j=i+1;j<ccnt && (x[j]!=xp[p]+96 || y[j]!=yp[p]);j++); |
||
88 | if(j>=ccnt) continue; |
||
89 | if(j>i+1) { |
||
90 | xm=x[j];ym=y[j];om=o[j]; |
||
91 | for(k=i+1;k<j;k++) { |
||
92 | x[k+1]=x[k]; |
||
93 | y[k+1]=y[k]; |
||
94 | o[k+1]=o[k]; |
||
95 | } |
||
96 | x[i+1]=xm; y[i+1]=ym; o[i+1]=om; |
||
97 | } |
||
98 | } |
||
99 | pair[ppcnt]=i; ppcnt++; |
||
100 | } |
||
101 | pairlist=""; if(ppcnt>0) { |
||
102 | pp=""; |
||
103 | for(i=0;i<ppcnt;i++) pp=pp sprintf(",%d",pair[i]+1); |
||
104 | pairlist=sprintf("(%s)",substr(pp,2)); |
||
15531 | bpr | 105 | |
20 | reyssat | 106 | } |
107 | printf "%d\n",ccnt >"/dev/stderr"; |
||
108 | print "\nGenerated from xcircuit ps file.\n" |
||
109 | printf ":%s\n\n", desc; |
||
110 | printf ":%d,%d,%d,%s\n",xrange/sf,yrange/sf,ccnt,pairlist; |
||
111 | for(i=0;i<ccnt;i++) xtt[i]=ytt[i]=-sf; |
||
112 | printf ":"; |
||
113 | for(i=0;i<tcnt;i++) { |
||
114 | dist=160; meet=-1; |
||
115 | for(j=0;j<ccnt;j++) { |
||
116 | d=sqrt((xt[i]+50-x[j])*(xt[i]+50-x[j])+(yt[i]-15-y[j])*(yt[i]-15-y[j])); |
||
117 | if(d<dist) {dist=d; meet=j;} |
||
118 | } |
||
119 | if(meet>=0) { |
||
120 | xtt[meet]=xt[i]; |
||
121 | ytt[meet]=yt[i]; |
||
122 | } |
||
123 | } |
||
124 | for(i=0;i<ccnt;i++) { |
||
125 | printf("%g,%g,%g,%g,%d", |
||
126 | x[i]/sf,y[i]/sf,xtt[i]/sf,ytt[i]/sf,o[i]); |
||
127 | for(j=0;j<ext;j++) { |
||
128 | if(o[i]!=oe[j]) continue; |
||
129 | if(o[i]==0) { |
||
130 | if(ye1[j]!=y[i]) continue; |
||
131 | e1=xe1[j]-x[i]; if(e1<0) e1=-e1; |
||
132 | e2=xe2[j]-x[i]; if(e2<0) e2=-e2; |
||
133 | if(e1>e2) {ee=e1; e1=e2; e2=ee;} |
||
134 | if(e1>=sf) continue; |
||
135 | if(xe1[j]<x[i]) e2=-e2; |
||
136 | printf(",%g",e2/sf); |
||
137 | } |
||
138 | if(o[i]==1) { |
||
139 | if(xe1[j]!=x[i]) continue; |
||
140 | e1=ye1[j]-y[i]; if(e1<0) e1=-e1; |
||
141 | e2=ye2[j]-y[i]; if(e2<0) e2=-e2; |
||
142 | if(e1>e2) {ee=e1; e1=e2; e2=ee;} |
||
143 | if(e1>=sf) continue; |
||
144 | if(ye1[j]<y[i]) e2=-e2; |
||
145 | printf(",%g",e2/sf); |
||
146 | } |
||
147 | } |
||
148 | printf("\n"); |
||
149 | } |
||
150 | printf "\n:%s\n",wiring; |
||
151 | printf ":%s\n",substr(dots,2); |
||
152 | }; |
||
153 | $NF == "scb" && $1 == 1 && $2 == 0 && $3 == 0 {pairer=1; next}; |
||
154 | $NF=="polygon" && $2==3 { |
||
155 | if($(NF-1)==2) { |
||
156 | if(pairer==1) { |
||
157 | xp[pcnt]=($3+$5)/2; |
||
158 | yp[pcnt]=($4+$6)/2; |
||
159 | if($4==$6) op[pcnt]=0; else op[pcnt]=1; |
||
160 | pcnt++; |
||
161 | } |
||
15531 | bpr | 162 | else wiring=wiring sprintf("segment %g,%g,%g,%g,_color_\n", |
20 | reyssat | 163 | $3/sf,$4/sf,$5/sf,$6/sf); |
164 | } |
||
15531 | bpr | 165 | else {wiring=wiring "polyline _color_"; |
20 | reyssat | 166 | for(i=3;i<=NF-2;i++) wiring=wiring sprintf(",%g",$i/sf); |
167 | wiring=wiring "\n"; |
||
168 | } |
||
169 | next}; |
||
170 | $NF=="polygon" && $2<3 && $(NF-1)==2 { |
||
171 | oe[ext]=-1; |
||
172 | if($3==$5) oe[ext]=1; |
||
173 | else if($4==$6) oe[ext]=0; |
||
174 | xe1[ext]=$3;xe2[ext]=$5; |
||
175 | ye1[ext]=$4;ye2[ext]=$6; |
||
176 | ext++; next}; |
||
177 | $NF == "sce" {pairer=0; next;}; |
||
178 | $NF ~ /acsource|npn|pnp/ { |
||
179 | if(($2%180)==90) r=0; else r=1; |
||
180 | x[ccnt]=$3; y[ccnt]=$4; o[ccnt]=r; |
||
181 | ccnt++; |
||
182 | next}; |
||
183 | $NF=="label" && $1 ~ /^\(DESC:/ { |
||
184 | l=length($0); desc=""; aa=0; |
||
185 | for(i=7; i<l; i++) { |
||
186 | c=substr($0,i,1); |
||
187 | if(aa==0 && c==" ") continue; |
||
188 | aa++; |
||
189 | if(c==")") break; |
||
190 | if(c=="\\") {i++; c=substr($0,i,1);} |
||
191 | desc=desc c; |
||
192 | } |
||
193 | next}; |
||
194 | $NF=="label" && ($(NF-1) < 0 || $(NF-2) < 0) {next}; |
||
195 | $NF=="label" && $1=="(XXX)" { |
||
196 | xt[tcnt]=$(NF-2); yt[tcnt]=$(NF-1)+32; |
||
197 | tcnt++; next}; |
||
198 | $NF=="label" && /^\(/ { |
||
199 | l=length($0); text=""; |
||
200 | for(i=2; i<l; i++) { |
||
201 | c=substr($0,i,1); |
||
202 | if(c==")") break; |
||
203 | if(c=="\\") {i++; c=substr($0,i,1);} |
||
204 | text=text c; |
||
205 | } |
||
206 | wiring=wiring sprintf("text _color_,%g,%g,$slib_textsize,%s\n", |
||
207 | $(NF-2)/sf,($(NF-1)+32)/sf,text); |
||
208 | } |
||
209 | $NF=="tap" {if(xrange<$(NF-2)) xrange=$(NF-2); |
||
210 | if(yrange<$(NF-1)) yrange=$(NF-1); next}; |
||
211 | $NF=="dot" { |
||
212 | dots=dots sprintf(",%g,%g",$3/sf,$4/sf); |
||
213 | next};' |
||
214 | |||
215 |