comparison ueda/uschem-print/printpage.c @ 0:cd92449fdb51

initial import of ueda and ifctf-part-lib from ifctfvax CVS
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 20 Jul 2015 00:24:37 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:cd92449fdb51
1 #include <sys/types.h>
2 #include <stdio.h>
3 #include <strings.h>
4 #include "../libuschem/schemstruct.h"
5 #include "../libuschem/graphsym.h"
6
7 extern FILE *reopen_schem_for_graphblocks();
8 extern char *get_compinst_attr();
9 extern char *pinname_to_pinnumber();
10
11 extern struct schem **schem_pages;
12 extern int npages;
13
14 struct schem *schem_being_printed;
15 FILE *schemfile_for_graphblocks;
16
17 static enum {LINEWIDTH_UNDEF, LINEWIDTH_NET, LINEWIDTH_BUS} pagelevel_linewidth;
18
19 print_schem_page(pageno)
20 int pageno; /* zero-based */
21 {
22 register struct schem *schem;
23 register struct schemobj *obj;
24
25 schem = schem_pages[pageno];
26 schem_being_printed = schem;
27 schemfile_for_graphblocks = reopen_schem_for_graphblocks(schem);
28 printf("%%%%Page: %s %d\n", schem->orig_filename, pageno + 1);
29 puts("save $uschem begin");
30 printf("/drawingsize_x %d def\n", schem->graph_xsize);
31 printf("/drawingsize_y %d def\n", schem->graph_ysize);
32 puts("setscale");
33 pagelevel_linewidth = LINEWIDTH_UNDEF;
34 reset_decor_font();
35 for (obj = schem->obj_next; obj != (struct schemobj *) schem;
36 obj = obj->obj_next)
37 print_schem_obj(obj);
38 if (schemfile_for_graphblocks)
39 fclose(schemfile_for_graphblocks);
40 puts("end restore showpage");
41 return(0);
42 }
43
44 print_schem_obj(obj)
45 register struct schemobj *obj;
46 {
47 switch (obj->obj_type) {
48 case OBJTYPE_COMPINST:
49 if (!obj->compobj_isgraph)
50 return;
51 /* FALL THRU */
52 case OBJTYPE_GRAPHSYM:
53 print_graph_compinst(obj);
54 return;
55 case OBJTYPE_GRAPHNET:
56 if (pagelevel_linewidth != LINEWIDTH_NET) {
57 puts("netlinewidth setlinewidth");
58 pagelevel_linewidth = LINEWIDTH_NET;
59 }
60 print_graphnet(obj);
61 print_obj_decors(obj);
62 return;
63 case OBJTYPE_NETLINE:
64 if (pagelevel_linewidth != LINEWIDTH_NET) {
65 puts("netlinewidth setlinewidth");
66 pagelevel_linewidth = LINEWIDTH_NET;
67 }
68 printf("%d %d moveto %d %d lineto stroke\n", obj->lineobj_x1,
69 obj->lineobj_y1, obj->lineobj_x2, obj->lineobj_y2);
70 print_obj_decors(obj);
71 return;
72 case OBJTYPE_BUSSEG:
73 if (pagelevel_linewidth != LINEWIDTH_BUS) {
74 puts("buslinewidth setlinewidth");
75 pagelevel_linewidth = LINEWIDTH_BUS;
76 }
77 printf("%d %d moveto %d %d lineto stroke\n", obj->lineobj_x1,
78 obj->lineobj_y1, obj->lineobj_x2, obj->lineobj_y2);
79 print_obj_decors(obj);
80 return;
81 case OBJTYPE_GRAPHBLOCK:
82 print_graphblock(obj->graphblockobj_body);
83 return;
84 }
85 }
86
87 print_graph_compinst(obj)
88 register struct schemobj *obj;
89 {
90 register struct graphsym *gs;
91 char *slot;
92
93 gs = obj->compobj_graphsym;
94 printf("save %d %d translate", obj->compobj_x, obj->compobj_y);
95 if (obj->compobj_rotate)
96 printf(" %d rotate", obj->compobj_rotate);
97 putchar('\n');
98 printf("/mirrored %s def\n", obj->compobj_mirror ? "true" : "false");
99 if (gs->gs_varpins) {
100 if (obj->obj_type != OBJTYPE_COMPINST) {
101 fprintf(stderr,
102 "%s: line %d: symbol \"%s\" has variable pins; may not be used w/o component\n",
103 schem_being_printed->orig_filename,
104 obj->obj_lineno, gs->gs_name);
105 exit(1);
106 }
107 slot = get_compinst_attr(obj, "slot");
108 define_varpins(gs, obj->compobj_mclcomp, slot);
109 }
110 printf("symbols /%s get exec restore\n", gs->gs_name);
111 print_obj_decors(obj);
112 }
113
114 define_varpins(gs, comp, slot)
115 struct graphsym *gs;
116 struct component *comp;
117 char *slot;
118 {
119 register struct graphsym_pindef *pin;
120 register char *cp;
121
122 puts("/pins [");
123 for (pin = gs->gs_pins; pin; pin = pin->gspd_next)
124 if (pin->gspd_pinnumber && !strcmp(pin->gspd_pinnumber, "%d")) {
125 if (pin->gspd_pinname)
126 cp = pinname_to_pinnumber(comp,
127 pin->gspd_pinname, slot);
128 else {
129 fprintf(stderr,
130 "Symbol %s: variable pin has no pinname attribute\n",
131 gs->gs_name);
132 cp = NULL;
133 }
134 putchar(' ');
135 if (cp)
136 emit_ps_string(cp);
137 else {
138 putchar('(');
139 putchar(')');
140 }
141 putchar('\n');
142 }
143 puts("] def");
144 }
145
146 print_graphnet(obj)
147 struct schemobj *obj;
148 {
149 register struct netpoint *netpt;
150 register int first;
151
152 for (netpt = obj->netobj_points, first = 1; netpt;
153 netpt = netpt->netpt_next) {
154 if (!netpt->netpt_coord_valid) {
155 fprintf(stderr,
156 "%s: line %d: GraphNet contains Pin w/o coordinates, not printed\n",
157 schem_being_printed->orig_filename,
158 obj->obj_lineno);
159 puts("newpath"); /* kludge in lieu of abort */
160 return;
161 }
162 printf("%d %d %s\n", netpt->netpt_x, netpt->netpt_y,
163 first ? "moveto" : "lineto");
164 first = 0;
165 }
166 puts("stroke");
167 /* connection dots */
168 for (netpt = obj->netobj_points, first = 1; netpt;
169 netpt = netpt->netpt_next, first = 0)
170 switch (netpt->netpt_type) {
171 case NETPT_TYPE_PIN:
172 case NETPT_TYPE_PSEUDO:
173 if (first || !netpt->netpt_next)
174 continue;
175 /* FALL THRU */
176 case NETPT_TYPE_TJOIN:
177 printf("%d %d conndot\n", netpt->netpt_x,
178 netpt->netpt_y);
179 continue;
180 }
181 }
182
183 print_graphblock(blk)
184 register struct graphblock *blk;
185 {
186 puts("save");
187 switch (blk->type) {
188 case GRAPHBLOCK_TYPE_PS:
189 write_graphblock_to_file(blk, schemfile_for_graphblocks,
190 stdout);
191 break;
192 case GRAPHBLOCK_TYPE_GSCHEM:
193 print_gschem_code_graphblk(schemfile_for_graphblocks, blk,
194 schem_being_printed->orig_filename);
195 break;
196 default:
197 fprintf(stderr,
198 "Fatal internal error: unknown graphblock type %d (from %s line %d)\n",
199 blk->type, schem_being_printed->orig_filename,
200 blk->lineno);
201 exit(1);
202 }
203 puts("restore");
204 }