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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
|
/*
* plotPS.c --
*
* This file contains procedures that generate PS-format files
* to describe a section of layout.
*
* *********************************************************************
* * Copyright (C) 1985, 1990 Regents of the University of California. *
* * Permission to use, copy, modify, and distribute this *
* * software and its documentation for any purpose and without *
* * fee is hereby granted, provided that the above copyright *
* * notice appear in all copies. The University of California *
* * makes no representations about the suitability of this *
* * software for any purpose. It is provided "as is" without *
* * express or implied warranty. Export of this software outside *
* * of the United States of America may require an export license. *
* *********************************************************************
*/
#ifndef lint
static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/plot/plotPS.c,v 1.3 2010/06/24 12:37:25 tim Exp $";
#endif /* not lint */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utils/magic.h"
#include "utils/geometry.h"
#include "tiles/tile.h"
#include "utils/hash.h"
#include "database/database.h"
#include "utils/tech.h"
#include "utils/malloc.h"
#include "utils/utils.h"
#include "windows/windows.h"
#include "commands/commands.h"
#include "dbwind/dbwind.h"
#include "textio/textio.h"
/* Records of the following type are used to describe how to generate
* PS output for a particular set of mask layers. Each style
* describes the PS figures to draw for a particular set of
* layers. A single layer may participate in several ps styles.
*/
typedef struct psstyle
{
TileTypeBitMask grs_layers; /* Layers to plot in this style. */
int grs_stipple; /* Index of fill to use. */
int grs_color; /* Index of color to use. */
struct psstyle *grs_next; /* Next style in chain. */
} PSStyle;
typedef struct pspattern
{
int index;
unsigned long stipple[8];
struct pspattern *pat_next;
} PSPattern;
typedef struct pscolor
{
int index;
unsigned char color[4];
struct pscolor *col_next;
} PSColor;
static PSStyle *plotPSStyles = NULL;
static PSPattern *plotPSPatterns = NULL;
static PSColor *plotPSColors = NULL;
int delta, xnmargin, ynmargin, xpmargin, ypmargin;
float fscale;
/* Most of the grs_stipple values are PS stipple numbers. However,
* if a grs_stipple value is less than zero, it means something special.
* The definitions below give the possible alternatives:
*
* CROSS: Draw a thick outline around the tile with
* a cross through it (used for contacts).
* BORDER: Same as CROSS, except draw the outline with
* no cross through it.
* SOLID: This is the same as a solid stipple but renders
* much faster.
*/
#define CROSS -1
#define BORDER -2
#define SOLID -3
/* The definitions below give the integers used for various PS
* line drawing styles (brushes).
*/
#define PS_THIN 1
#define PS_MEDIUM 2
#define PS_THICK 3
/* The variables below are used to pass information from the top-level
* procedure PlotPS down to the lower-level search functions
* that are invoked for pieces of the layout.
*/
static FILE *file; /* File to use for output. */
static PSStyle *curStyle; /* Current style being output. */
static PSColor *curColor; /* Current color being output. */
static PSPattern *curPattern; /* Current pattern being output. */
static int curLineWidth; /* Current line width */
static int curFont; /* Current font */
static TileTypeBitMask curMask; /* Layers currently being searched: this
* is the AND of the mask from curStyle and
* the layers that the user specified.
*/
static Rect bbox; /* Bounding box, in root coordinates, of
* area being plotted.
*/
/* Parameters passed to the plotting process */
static char *defaultBoldFont = "/HelveticaBold";
static char *defaultFont = "/Helvetica";
char *PlotPSIdFont = NULL;
char *PlotPSNameFont = NULL;
char *PlotPSLabelFont = NULL;
int PlotPSIdSize = 8;
int PlotPSNameSize = 12;
int PlotPSLabelSize = 12;
int PlotPSBoundary = 1; /* Print boundaries around all layers */
int PlotPSHeight = 792; /* 11 inches * 72 PS units/inch */
int PlotPSWidth = 612; /* 8.5 inches */
int PlotPSMargin = 72; /* 1 inch */
int curx1, curx2, cury1, cury2; /* Last encountered line */
int curxbot, curybot, curwidth, curheight; /* Last encountered rectangle */
/*
* ----------------------------------------------------------------------------
*
* PSReset()
*
* Plot optimization: Reset buffered line and rectangle to default values
*
* ----------------------------------------------------------------------------
*/
void
PSReset()
{
curxbot = curybot = curwidth = curheight = -2;
curx1 = curx2 = cury1 = cury2 = -2;
}
/*
* ----------------------------------------------------------------------------
* PlotPSTechInit --
*
* Called once at beginning of technology file read-in to initialize
* data structures.
*
* Results:
* None.
*
* Side effects:
* Clears out the list of things to plot.
* ----------------------------------------------------------------------------
*/
void
PlotPSTechInit()
{
int i, j;
PSStyle *style;
PSColor *color;
PSPattern *pattern;
/* Clear out any old information */
for (style = plotPSStyles; style != NULL; style = style->grs_next)
{
freeMagic((char *) style);
}
plotPSStyles = NULL;
for (pattern = plotPSPatterns; pattern != NULL; pattern = pattern->pat_next)
{
freeMagic((char *) pattern);
}
plotPSPatterns = NULL;
for (color = plotPSColors; color != NULL; color = color->col_next)
{
freeMagic((char *) color);
}
plotPSColors = NULL;
if (!PlotPSIdFont)
StrDup(&PlotPSIdFont, defaultFont);
if (!PlotPSNameFont)
StrDup(&PlotPSNameFont, defaultBoldFont);
if (!PlotPSLabelFont)
StrDup(&PlotPSLabelFont, defaultFont);
}
/*
* ----------------------------------------------------------------------------
* PlotPSTechLine --
*
* This procedure is invoked by the technology module once for
* each line in the "ps" subsection of the "plot" section
* of the technology file.
*
* Results:
* Always returns TRUE (otherwise the technology module would
* abort Magic with a fatal error).
*
* Side effects:
* Builds up the table of PS styles.
* ----------------------------------------------------------------------------
*/
bool
PlotPSTechLine(sectionName, argc, argv)
char *sectionName; /* Name of this section (unused). */
int argc; /* Number of arguments on line. */
char *argv[]; /* Pointers to fields of line. */
{
PSStyle *newstyle;
PSColor *newcolor;
PSPattern *newpattern;
int i, color, stipple;
if (argc != 9 && argc != 5 && argc != 3)
{
TechError("\"ps\" lines must have either 9, 5, or 3 arguments.\n");
return TRUE;
}
if (argc == 9) /* pattern definition */
{
newpattern = (PSPattern *) mallocMagic(sizeof(PSPattern));
sscanf(argv[0], "%d", &(newpattern->index));
for(i = 0; i < 8; i++)
{
sscanf(argv[1 + i], "%08lx", &(newpattern->stipple[i]));
}
newpattern->pat_next = plotPSPatterns;
plotPSPatterns = newpattern;
}
else if (argc == 5) /* color definition */
{
int tmpint;
newcolor = (PSColor *) mallocMagic(sizeof(PSColor));
sscanf(argv[0], "%d", &(newcolor->index));
for(i = 0; i < 4; i++)
{
sscanf(argv[1 + i], "%d", &tmpint);
newcolor->color[i] = (unsigned char)(tmpint & 0xff);
}
newcolor->col_next = plotPSColors;
plotPSColors = newcolor;
}
else { /* 3 args: layer definition */
if (!StrIsInt(argv[1]))
{
TechError("2nd field must be an integer\n");
return TRUE;
}
color = atoi(argv[1]);
if (strcmp(argv[2], "X") == 0)
stipple = CROSS;
else if (strcmp(argv[2], "B") == 0)
stipple = BORDER;
else if (strcmp(argv[2], "S") == 0)
stipple = SOLID;
else
{
if (!StrIsInt(argv[2]))
{
TechError("3rd field must be an integer or \"S\", \"X\", or \"B\".\n");
return TRUE;
}
stipple = atoi(argv[2]);
}
newstyle = (PSStyle *) mallocMagic(sizeof(PSStyle));
DBTechNoisyNameMask(argv[0], &newstyle->grs_layers);
/* Replace non-primary contact images with primary images. */
for (i = TT_TECHDEPBASE; i < DBNumTypes; i++)
{
if TTMaskHasType(&newstyle->grs_layers, i)
TTMaskSetMask(&newstyle->grs_layers, &DBLayerTypeMaskTbl[i]);
}
TTMaskAndMask(&newstyle->grs_layers, &DBUserLayerBits);
newstyle->grs_stipple = stipple;
newstyle->grs_color = color;
newstyle->grs_next = plotPSStyles;
plotPSStyles = newstyle;
}
return TRUE;
}
/*
* ----------------------------------------------------------------------------
*
* plotPSFlushRect()
*
* Plot optimization: Draw last buffered rectangle.
*
* ----------------------------------------------------------------------------
*/
void
plotPSFlushRect(style)
int style;
{
if (curwidth > 0)
{
if (style == SOLID)
fprintf(file, "%d %d %d %d ms\n", curxbot, curybot,
curwidth, curheight);
else
fprintf(file, "%d %d %d %d fb\n", curxbot, curybot,
curxbot + curwidth, curybot + curheight);
}
}
/*
* ----------------------------------------------------------------------------
*
* plotPSFlushLine()
*
* Plot optimization: Draw last buffered line.
*
* ----------------------------------------------------------------------------
*/
void
plotPSFlushLine()
{
if (cury1 == cury2)
{
if (curx1 != curx2) /* true only if nothing is buffered */
fprintf(file, "%d %d %d hl\n", curx2 - curx1, curx1, cury1);
}
else if (curx1 == curx2)
fprintf(file, "%d %d %d vl\n", cury2 - cury1, curx1, cury1);
else
fprintf(file, "%d %d %d %d ml\n", curx1, cury1, curx2, cury2);
}
/*
* ----------------------------------------------------------------------------
*
* plotPSLine --
*
* Outputs a line into the current PS file.
*
* Results:
* None.
*
* Side effects:
* I/O.
*
* ----------------------------------------------------------------------------
*/
void
plotPSLine(p1, p2)
Point *p1, *p2; /* Endpoints of line, given in root
* coordinates.
*/
{
int x1, x2, y1, y2, limit, diff;
bool tmptf;
/* Clip the line to the rectangular area being output. First,
* arrange for the first x-coordinate to be the smaller, then
* clip against vertical lines at the x-boundaries.
*/
if (p1->p_x <= p2->p_x)
{
x1 = p1->p_x - bbox.r_xbot;
x2 = p2->p_x - bbox.r_xbot;
y1 = p1->p_y - bbox.r_ybot;
y2 = p2->p_y - bbox.r_ybot;
}
else
{
x1 = p2->p_x - bbox.r_xbot;
x2 = p1->p_x - bbox.r_xbot;
y1 = p2->p_y - bbox.r_ybot;
y2 = p1->p_y - bbox.r_ybot;
}
limit = bbox.r_xtop - bbox.r_xbot;
if ((x1 > limit) || (x2 < 0)) return;
/* Now clip against horizontal lines at the y-boundaries. */
if (y2 < y1)
{
float tmp;
tmp = y2; y2 = y1; y1 = tmp;
tmp = x2; x2 = x1; x1 = tmp;
}
limit = bbox.r_ytop - bbox.r_ybot;
if ((y1 > limit) || (y2 < 0)) return;
/* compare against last output line and merge if possible */
if (((x1 == x2) && (x1 == curx1) && (x2 == curx2)
&& ((tmptf = (y1 == cury2)) || (y2 == cury1))))
{
if (tmptf) cury2 = y2;
else cury1 = y1;
}
else if (((y1 == y2) && (y1 == cury1) && (y2 == cury2)
&& ((tmptf = (x1 == curx2)) || (x2 == curx1))))
{
if (tmptf) curx2 = x2;
else curx1 = x1;
}
else
{
plotPSFlushLine();
curx1 = x1;
curx2 = x2;
cury1 = y1;
cury2 = y2;
}
}
/*
* ----------------------------------------------------------------------------
*
* plotPSRect --
*
* Outputs PS statements to draw a rectangular area as
* an outline with a given line style.
*
* Results:
* None.
*
* Side effects:
* Adds information to the current PS file.
*
* ----------------------------------------------------------------------------
*/
void
plotPSRect(rect, style)
Rect *rect; /* Rectangle to be drawn, in root coords. */
int style;
{
int x, y, w, h;
/* Output all boxes with any part visible. Depend on PostScript to */
/* do the clipping of any boxes crossing the plot boundary. */
x = rect->r_xbot - bbox.r_xbot;
if ((x < 0) || (rect->r_xbot > bbox.r_xtop)) return;
w = rect->r_xtop - rect->r_xbot;
y = rect->r_ybot - bbox.r_ybot;
if ((y < 0) || (rect->r_ybot > bbox.r_ytop)) return;
h = rect->r_ytop - rect->r_ybot;
fprintf(file, "%d %d %d %d m%c\n", x, y, w, h, (style == CROSS) ? 'x' :
(style == SOLID) ? 's' : 'r');
}
/*
* ----------------------------------------------------------------------------
*
* plotPSPaint --
*
* This procedure is invoked once for each paint rectangle in
* the area being plotted.
*
* Results:
* Always returns 0 to keep the search alive.
*
* Side effects:
* Outputs information for the tile, including stipple for its
* interior, and a solid line for any portion of the boundary
* of the tile that is adjacent to a tile NOT in this style.
*
* ----------------------------------------------------------------------------
*/
int
plotPSPaint(tile, cxp)
Tile *tile; /* Tile that's of type to be output. */
TreeContext *cxp; /* Describes search in progress. */
{
Rect tileArea, edge, rootArea;
int xbot, width, ybot, height;
Tile *neighbor;
SearchContext *scx = cxp->tc_scx;
bool tmptf;
TileType ntype;
/* First transform tile coords to root coords */
TiToRect(tile, &tileArea);
GeoTransRect(&scx->scx_trans, &tileArea, &rootArea);
/* See if this tile gets special handling. */
if ((curStyle->grs_stipple == CROSS) || (curStyle->grs_stipple == BORDER))
{
/* Draw tile as a thick outline with a cross from corner
* to corner, and skip the rest of this procedure.
*/
Point ul, lr;
if (curLineWidth != PS_MEDIUM) {
fprintf(file, "l2\n");
curLineWidth = PS_MEDIUM;
}
plotPSRect(&rootArea, curStyle->grs_stipple);
return 0;
}
/* If this is a triangle, output the last rect and deal with this one */
/* individually. */
if (IsSplit(tile))
{
int np, i, j;
TileType dinfo;
Point polyp[5];
plotPSFlushRect(curStyle->grs_stipple);
plotPSFlushLine();
PSReset();
/* Side and direction are altered by geometric transformations */
dinfo = DBTransformDiagonal(TiGetTypeExact(tile), &scx->scx_trans);
/* Use GrClipTriangle() routine to get the n-sided polygon that */
/* results from clipping a triangle to the clip region. */
GrClipTriangle(&rootArea, &bbox, TRUE, dinfo, polyp, &np);
for (i = 0; i < np; i++)
{
polyp[i].p_x -= bbox.r_xbot;
polyp[i].p_y -= bbox.r_ybot;
fprintf(file, "%d %d ", polyp[i].p_x, polyp[i].p_y);
}
fprintf(file, "%d tb\n", np);
if (PlotPSBoundary)
{
if (curLineWidth != PS_THIN) {
fprintf(file, "l1\n");
curLineWidth = PS_THIN;
}
/* Diagonal is always drawn */
for (i = 0; i < np; i++)
{
j = (i + 1) % np;
if (polyp[i].p_x != polyp[j].p_x &&
polyp[i].p_y != polyp[j].p_y)
{
fprintf(file, "%d %d %d %d ml\n", polyp[i].p_x, polyp[i].p_y,
polyp[j].p_x, polyp[j].p_y);
break;
}
}
}
}
else
{
/* This tile gets "normal" processing (i.e. stippling and outlining).
* Clip it to the plotting area and output.
*/
GeoClip(&rootArea, &bbox);
xbot = rootArea.r_xbot - bbox.r_xbot;
width = rootArea.r_xtop - rootArea.r_xbot;
ybot = rootArea.r_ybot - bbox.r_ybot;
height = rootArea.r_ytop - rootArea.r_ybot;
/* compare against last output rectangle and merge if possible */
if ((width == curwidth) && (xbot == curxbot) && ((tmptf = (ybot == curybot
+ curheight)) || (ybot + height == curybot)))
{
curheight += height;
if (!tmptf) curybot = ybot;
}
else if ((height == curheight) && (ybot == curybot) && ((tmptf = (xbot
== curxbot + curwidth)) || (xbot + width == curxbot)))
{
curwidth += width;
if (!tmptf) curxbot = xbot;
}
else
{
plotPSFlushRect(curStyle->grs_stipple);
curheight = height;
curwidth = width;
curxbot = xbot;
curybot = ybot;
}
if (PlotPSBoundary && (curLineWidth != PS_THIN)) {
fprintf(file, "l1\n");
curLineWidth = PS_THIN;
}
}
if (!PlotPSBoundary) return 0; /* No borders */
/* Now output lines for any edges between material of the type
* currently being drawn and material of other types. This is
* done by searching along the tile's borders for neighbors that
* have the wrong types. First, search the tile's bottom border
* (unless it is at infinity).
*
* (This code is essentially a duplicate of selRedisplayFunc())
*/
if (IsSplit(tile) && (!(SplitSide(tile) ^ SplitDirection(tile))))
goto searchleft; /* nothing on bottom of split */
if (tileArea.r_ybot > TiPlaneRect.r_ybot)
{
edge.r_ybot = edge.r_ytop = tileArea.r_ybot;
for (neighbor = LB(tile); LEFT(neighbor) < tileArea.r_xtop;
neighbor = TR(neighbor))
{
ntype = TiGetTopType(neighbor);
if (TTMaskHasType(&curMask, ntype)) continue;
edge.r_xbot = LEFT(neighbor);
edge.r_xtop = RIGHT(neighbor);
if (edge.r_xbot < tileArea.r_xbot) edge.r_xbot = tileArea.r_xbot;
if (edge.r_xtop > tileArea.r_xtop) edge.r_xtop = tileArea.r_xtop;
GeoTransRect(&scx->scx_trans, &edge, &rootArea);
plotPSLine(&rootArea.r_ll, &rootArea.r_ur);
}
}
/* Now go along the tile's left border, doing the same thing. Ignore
* edges that are at infinity.
*/
searchleft:
if (IsSplit(tile) && SplitSide(tile))
goto searchtop; /* Nothing on left side of tile */
if (tileArea.r_xbot > TiPlaneRect.r_xbot)
{
edge.r_xbot = edge.r_xtop = tileArea.r_xbot;
for (neighbor = BL(tile); BOTTOM(neighbor) < tileArea.r_ytop;
neighbor = RT(neighbor))
{
ntype = TiGetRightType(neighbor);
if (TTMaskHasType(&curMask, ntype)) continue;
edge.r_ybot = BOTTOM(neighbor);
edge.r_ytop = TOP(neighbor);
if (edge.r_ybot < tileArea.r_ybot) edge.r_ybot = tileArea.r_ybot;
if (edge.r_ytop > tileArea.r_ytop) edge.r_ytop = tileArea.r_ytop;
GeoTransRect(&scx->scx_trans, &edge, &rootArea);
plotPSLine(&rootArea.r_ll, &rootArea.r_ur);
}
}
/* Same thing for the tile's top border. */
searchtop:
if (IsSplit(tile) && (SplitSide(tile) ^ SplitDirection(tile)))
goto searchright; /* Nothing on top side of tile */
if (tileArea.r_ytop < TiPlaneRect.r_ytop)
{
edge.r_ybot = edge.r_ytop = tileArea.r_ytop;
for (neighbor = RT(tile); RIGHT(neighbor) > tileArea.r_xbot;
neighbor = BL(neighbor))
{
ntype = TiGetBottomType(neighbor);
if (TTMaskHasType(&curMask, ntype)) continue;
edge.r_xbot = LEFT(neighbor);
edge.r_xtop = RIGHT(neighbor);
if (edge.r_xbot < tileArea.r_xbot) edge.r_xbot = tileArea.r_xbot;
if (edge.r_xtop > tileArea.r_xtop) edge.r_xtop = tileArea.r_xtop;
GeoTransRect(&scx->scx_trans, &edge, &rootArea);
plotPSLine(&rootArea.r_ll, &rootArea.r_ur);
}
}
/* Finally, the right border. */
searchright:
if (IsSplit(tile) && !SplitSide(tile))
return 0; /* Nothing on right side of tile */
if (tileArea.r_xtop < TiPlaneRect.r_xtop)
{
edge.r_xbot = edge.r_xtop = tileArea.r_xtop;
for (neighbor = TR(tile); TOP(neighbor) > tileArea.r_ybot;
neighbor = LB(neighbor))
{
ntype = TiGetLeftType(neighbor);
if (TTMaskHasType(&curMask, ntype)) continue;
edge.r_ybot = BOTTOM(neighbor);
edge.r_ytop = TOP(neighbor);
if (edge.r_ybot < tileArea.r_ybot) edge.r_ybot = tileArea.r_ybot;
if (edge.r_ytop > tileArea.r_ytop) edge.r_ytop = tileArea.r_ytop;
GeoTransRect(&scx->scx_trans, &edge, &rootArea);
plotPSLine(&rootArea.r_ll, &rootArea.r_ur);
}
}
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* plotPSLabelPosition --
*
* Determine the label position, orientation, and approximate bounding box
*
* ----------------------------------------------------------------------------
*/
int
plotPSLabelPosition(scx, label, x, y, p)
SearchContext *scx; /* Describes state of search when label
* was found.
*/
Label *label; /* Label that was found. */
int *x; /* returned x position */
int *y; /* returned y position */
int *p; /* returned orientation */
{
Rect rootArea;
int pos;
/* Mapping from our GEO_xxx positions to PS object types: */
static int psPosition[] =
{
5, /* CENTCENT */
1, /* TOPCENT */
0, /* TOPRIGHT */
4, /* CENTRIGHT */
12, /* BOTRIGHT */
13, /* BOTCENT */
15, /* BOTLEFT */
7, /* CENTLEFT */
3 /* TOPLEFT */
};
GeoTransRect(&scx->scx_trans, &label->lab_rect, &rootArea);
pos = GeoTransPos(&scx->scx_trans, label->lab_just);
switch (pos)
{
case GEO_NORTH:
case GEO_NORTHEAST:
case GEO_NORTHWEST:
*y = (rootArea.r_ytop - bbox.r_ybot);
*y += delta;
break;
case GEO_CENTER:
case GEO_WEST:
case GEO_EAST:
*y = (rootArea.r_ytop + rootArea.r_ybot) / 2 - bbox.r_ybot;
break;
case GEO_SOUTH:
case GEO_SOUTHEAST:
case GEO_SOUTHWEST:
*y = (rootArea.r_ybot - bbox.r_ybot);
*y -= delta;
break;
}
switch (pos)
{
case GEO_WEST:
case GEO_NORTHWEST:
case GEO_SOUTHWEST:
*x = (rootArea.r_xbot - bbox.r_xbot);
*x -= delta;
break;
case GEO_CENTER:
case GEO_NORTH:
case GEO_SOUTH:
*x = (rootArea.r_xtop + rootArea.r_xbot) / 2 - bbox.r_xbot;
break;
case GEO_EAST:
case GEO_NORTHEAST:
case GEO_SOUTHEAST:
*x = (rootArea.r_xtop - bbox.r_xbot);
*x += delta;
break;
}
*p = psPosition[pos];
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* plotPSLabelBounds --
*
* Estimate the bounding box extension based on label strings.
* In reality, we need to know label sizes to compute the scale,
* and we need to know the scale to compute label sizes. However,
* in practice, we can only estimate the label size anyway, so we
* allow for some slop and just wing it.
*
* ----------------------------------------------------------------------------
*/
#define AVGCHARWIDTH 0.7
#define CHARHEIGHT 1.4
int
plotPSLabelBounds(scx, label)
SearchContext *scx; /* Describes state of search when label
* was found.
*/
Label *label; /* Label that was found. */
{
int pspos;
int ls, psxsize, psysize;
int llx, lly, urx, ury;
int psdelta = (int)((float)delta / fscale);
plotPSLabelPosition(scx, label, &llx, &lly, &pspos);
urx = (int)((float)(llx - bbox.r_xtop) / fscale);
ury = (int)((float)(lly - bbox.r_ytop) / fscale);
llx = (int)((float)(bbox.r_xbot - llx) / fscale);
lly = (int)((float)(bbox.r_ybot - lly) / fscale);
ls = strlen(label->lab_text);
psxsize = ls * (int)((float)PlotPSLabelSize * AVGCHARWIDTH);
psysize = (int)((float)PlotPSLabelSize * CHARHEIGHT);
switch (pspos) {
case 0:
ury += psysize + psdelta;
urx += psxsize + psdelta;
break;
case 4:
ury += psysize / 2;
lly += psysize / 2;
urx += psxsize + psdelta;
break;
case 12:
lly += psysize + psdelta;
urx += psxsize + psdelta;
break;
case 13:
lly += psysize + psdelta;
urx += psxsize / 2;
llx += psxsize / 2;
break;
case 15:
lly += psysize + psdelta;
llx += psxsize + psdelta;
break;
case 7:
ury += psysize / 2;
lly += psysize / 2;
llx += psxsize + psdelta;
break;
case 3:
ury += psysize + psdelta;
llx += psxsize + psdelta;
break;
case 1:
ury += psysize + psdelta;
urx += psxsize / 2;
llx += psxsize / 2;
break;
case 5:
ury += psysize / 2;
lly += psysize / 2;
urx += psxsize / 2;
llx += psxsize / 2;
break;
}
if (xpmargin < urx) xpmargin = urx;
if (ypmargin < ury) ypmargin = ury;
if (xnmargin < llx) xnmargin = llx;
if (ynmargin < lly) ynmargin = lly;
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* plotPSLabelBox --
*
* Output the box connected to a label
*
* ----------------------------------------------------------------------------
*/
int
plotPSLabelBox(scx, label)
SearchContext *scx; /* Describes state of search when label
* was found.
*/
Label *label; /* Label that was found. */
{
Rect rootArea;
int x, y;
GeoTransRect(&scx->scx_trans, &label->lab_rect, &rootArea);
/* Output lines marking the label's area. Different things are
* done depending on whether the label is a point, a line, or an
* area.
*/
if (curLineWidth != PS_MEDIUM) {
fprintf(file, "l2\n");
curLineWidth = PS_MEDIUM;
}
if ((rootArea.r_xbot == rootArea.r_xtop) &&
(rootArea.r_ybot == rootArea.r_ytop))
{
/* Point label. Output a cross. */
x = (rootArea.r_xbot - bbox.r_xbot);
y = (rootArea.r_ybot - bbox.r_ybot);
fprintf(file, "%d %d %d pl\n", delta, x, y);
}
else if ((rootArea.r_xbot == rootArea.r_xtop) ||
(rootArea.r_ybot == rootArea.r_ytop))
{
/* Line label. Just draw a medium-thickness line. */
plotPSLine(&rootArea.r_ll, &rootArea.r_ur);
}
else
{
/* Rectangular. Draw lines around the boundary. */
plotPSRect(&rootArea, 0);
}
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* plotPSLabel --
*
* This procedure is invoked once for each label overlapping the
* area being plotted. It generates PS output to describe
* the label.
*
* Results:
* Always returns 0 to keep the search from aborting.
*
* Side effects:
* PS information is output.
*
* ----------------------------------------------------------------------------
*/
int
plotPSLabel(scx, label)
SearchContext *scx; /* Describes state of search when label
* was found.
*/
Label *label; /* Label that was found. */
{
int x, y;
int pspos;
plotPSLabelPosition(scx, label, &x, &y, &pspos);
/* Output the text for the label, if the label is within delta
* of the area we're plotting (a large label could overlap a
* bit of the area but stick out way off-screen too).
*/
if ((x >= -delta) && (y >= -delta) &&
(x <= (bbox.r_xtop - bbox.r_xbot) + delta) &&
(y <= (bbox.r_ytop - bbox.r_ybot) + delta))
{
fprintf(file, "(%s) %d %d %d lb\n", label->lab_text, pspos, x, y);
}
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* plotPSCell --
*
* This procedure is invoked once for each unexpanded cell that
* overlaps the area being plotted.
*
* Results:
* Always returns 0 to keep the search from aborting.
*
* Side effects:
* PS information is output to describe the cell.
*
* ----------------------------------------------------------------------------
*/
int
plotPSCell(scx)
SearchContext *scx; /* Describes cell whose bbox is to
* be plotted.
*/
{
extern bool PlotShowCellNames;
char idName[100];
Rect rootArea;
CellDef *def;
int x, y;
/* Convert the cell's bounding box to root coordinates and then
* draw as a thick outline.
*/
def = scx->scx_use->cu_def;
GeoTransRect(&scx->scx_trans, &def->cd_bbox, &rootArea);
if (curLineWidth != PS_THICK) {
fprintf(file, "l3\n");
curLineWidth = PS_THICK;
}
plotPSRect(&rootArea, 0);
if (!PlotShowCellNames)
return 0;
/* Output the cell definition's name in the top of the bounding box.
* Use a bold font (#3), in a medium size (#2). Make sure that the
* name's positioning point is within the area we're plotting.
*/
x = (rootArea.r_xtop + rootArea.r_xbot - 2*bbox.r_xbot)/2;
y = (2*rootArea.r_ytop + rootArea.r_ybot - 3*bbox.r_ybot)/3;
if ((x >= 0) && (y >= 0) &&
(x <= (bbox.r_xtop - bbox.r_xbot)) &&
(y <= (bbox.r_ytop - bbox.r_ybot)))
{
fprintf(file, "f2 (%s) 5 %d %d lb\n", def->cd_name, x, y);
}
/* Output the cell id in the bottom of the bounding box.
* Use an italic font (#2) in a medium size (#2).
*/
x = (rootArea.r_xtop + rootArea.r_xbot - 2*bbox.r_xbot)/2;
y = (rootArea.r_ytop + 2*rootArea.r_ybot - 3*bbox.r_ybot)/3;
if ((x >= 0) && (y >= 0) &&
(x <= (bbox.r_xtop - bbox.r_xbot)) &&
(y <= (bbox.r_ytop - bbox.r_ybot)))
{
(void) DBPrintUseId(scx, idName, 100, TRUE);
fprintf(file, "f3 (%s) 5 %d %d lb\n", idName, x, y);
}
return 0;
}
/*
* ----------------------------------------------------------------------------
*
* PlotPS --
*
* This procedure generates a PS file to describe an area of
* a layout.
*
* Results:
* None.
*
* Side effects:
* None.
*
* ----------------------------------------------------------------------------
*/
void
PlotPS(fileName, scx, layers, xMask)
char *fileName; /* Name of PS file to write. */
SearchContext *scx; /* The use and area and transformation
* in this describe what to plot.
*/
TileTypeBitMask *layers; /* Tells what layers to plot. Only
* paint layers in this mask, and also
* expanded according to xMask, are
* plotted. If L_LABELS is set, then
* labels on the layers are also
* plotted, if expanded according to
* xMask. If L_CELL is set, then
* subcells that are unexpanded
* according to xMask are plotted as
* bounding boxes.
*/
int xMask; /* An expansion mask, used to indicate
* the window whose expansion status
* will be used to determine
* visibility. Zero means treat
* everything as expanded.
*/
{
int xsize, ysize;
float yscale;
FILE *infile;
int i, j;
int twidth, theight;
char *fontptr, *fptr2, *fptr3;
char line_in[100];
PSReset();
/* Compute a scale factor between our coordinates and PS
* coordinates.
*/
GeoTransRect(&scx->scx_trans, &scx->scx_area, &bbox);
xsize = bbox.r_xtop - bbox.r_xbot;
ysize = bbox.r_ytop - bbox.r_ybot;
fscale = (float)(PlotPSWidth - 2 * PlotPSMargin) / (float)xsize;
yscale = (float)(PlotPSHeight - 2 * PlotPSMargin) / (float)ysize;
if (yscale < fscale) fscale = yscale;
/* Compute a distance equal to 1/8th the size of a typical wire
* (max of thicknesses of routing layers). This is used to offset
* text from labels and to compute cross size for point labels.
*/
if (RtrMetalWidth > RtrPolyWidth)
delta = RtrMetalWidth / 8;
else delta = RtrPolyWidth / 8;
if (delta == 0) delta = 1;
/* Go through labels once to estimate the bounding box, including labels */
xnmargin = ynmargin = xpmargin = ypmargin = 0;
if (TTMaskHasType(layers, L_LABEL))
{
curMask = *layers;
TTMaskSetType(&curMask, TT_SPACE);
(void) DBTreeSrLabels(scx, &curMask, xMask, (TerminalPath *) NULL,
TF_LABEL_ATTACH, plotPSLabelBounds, (ClientData) NULL);
fscale = (float)(PlotPSWidth - 2 * PlotPSMargin - xnmargin - xpmargin)
/ (float)(xsize);
yscale = (float)(PlotPSHeight - 2 * PlotPSMargin - ynmargin - ypmargin)
/ (float)(ysize);
if (yscale < fscale) fscale = yscale;
}
twidth = (xsize * fscale) + xnmargin + xpmargin;
theight = (ysize * fscale) + ynmargin + ypmargin;
/* Open the PS file and output header information. */
file = PaOpen(fileName, "w", (char *) NULL, ".", (char *) NULL,
(char **) NULL);
if (file == NULL)
{
TxError("Couldn't write PS file \"%s\".\n", fileName);
return;
}
fprintf(file, "%%!PS-Adobe-3.0 EPSF-3.0\n");
fprintf(file, "%%%%BoundingBox: %d %d %d %d\n",
PlotPSMargin, PlotPSMargin, twidth + PlotPSMargin,
theight + PlotPSMargin);
fontptr = PlotPSIdFont;
fprintf(file, "%%%%DocumentNeededResources: font %s", fontptr);
if (!Match(fptr2 = PlotPSNameFont, fontptr));
fprintf(file, " font %s", fptr2);
if (!Match(fptr3 = PlotPSLabelFont, fontptr))
if (!Match(fptr3, fptr2))
fprintf(file, " font %s", fptr3);
fprintf(file, "\n");
fprintf(file, "%%%%EndComments\n");
/* Insert the prolog here */
infile = PaOpen("magicps", "r", ".pro", ".", SysLibPath, NULL);
if (infile != NULL)
while(fgets(line_in, 99, infile) != NULL)
fputs(line_in, file);
else
fprintf(file, "\npostscript_prolog_is_missing\n\n");
/* Insert the font definitions here. */
fprintf(file, "/f1 { %.3f %s sf } def\n", (float)PlotPSLabelSize / fscale,
PlotPSLabelFont);
fprintf(file, "/f2 { %.3f %s sf } def\n", (float)PlotPSNameSize / fscale,
PlotPSNameFont);
fprintf(file, "/f3 { %.3f %s sf } def\n", (float)PlotPSIdSize / fscale,
PlotPSIdFont);
/* Insert the color and stipple definitions here. */
for (curColor = plotPSColors; curColor != NULL;
curColor = curColor->col_next)
{
fprintf(file, "/col%d {%.3f %.3f %.3f %.3f sc} bind def\n",
curColor->index,
(float)curColor->color[0] / 255.0,
(float)curColor->color[1] / 255.0,
(float)curColor->color[2] / 255.0,
(float)curColor->color[3] / 255.0);
}
for (curPattern = plotPSPatterns; curPattern != NULL;
curPattern = curPattern->pat_next)
{
fprintf(file, "{<");
for (j = 0; j < 8; j++)
fprintf(file, "%08lx%08lx", curPattern->stipple[j], curPattern->stipple[j]);
fprintf(file, ">} %d dp\n", curPattern->index);
}
fprintf(file, "%%%%EndResource\n%%%%EndProlog\n\n");
fprintf(file, "%%%%Page: 1 1\n");
fprintf(file, "/pgsave save def bop\n");
fprintf(file, "%% 0 0 offsets\nninit\n");
fprintf(file, "%d %d translate\n", PlotPSMargin + xnmargin, PlotPSMargin
+ ynmargin);
fprintf(file, "%.3f %.3f scale\nminit\n", fscale, fscale);
fprintf(file, "0 0 %d %d gsave rectclip\n", xsize, ysize);
fprintf(file, "l2\nsp\n\n");
curLineWidth = PS_MEDIUM;
/* For each PS style, find all the paint layers that belong
* to that style and put plot information into the file.
*/
for (curStyle = plotPSStyles; curStyle != NULL;
curStyle = curStyle->grs_next)
{
fprintf(file, "col%d\n", curStyle->grs_color);
if (curStyle->grs_stipple >= 0)
fprintf(file, "%d sl\n", curStyle->grs_stipple);
TTMaskAndMask3(&curMask, layers, &curStyle->grs_layers);
(void) DBTreeSrTiles(scx, &curMask, xMask, plotPSPaint,
(ClientData) NULL);
plotPSFlushRect(curStyle->grs_stipple);
plotPSFlushLine();
PSReset();
}
/* Output subcell bounding boxes, if they are wanted. */
if (TTMaskHasType(layers, L_CELL))
{
(void) DBTreeSrCells(scx, xMask, plotPSCell, (ClientData) NULL);
plotPSFlushRect(BORDER);
plotPSFlushLine();
}
/* Output label boxes followed by labels */
if (TTMaskHasType(layers, L_LABEL))
{
curMask = *layers;
TTMaskSetType(&curMask, TT_SPACE);
(void) DBTreeSrLabels(scx, &curMask, xMask, (TerminalPath *) NULL,
TF_LABEL_ATTACH, plotPSLabelBox, (ClientData) NULL);
plotPSFlushRect(BORDER);
plotPSFlushLine();
PSReset();
fprintf(file, "grestore\n"); /* end clipping rectangle */
fprintf(file, "f1 0 setgray\n"); /* set font, set color to black */
curMask = *layers;
TTMaskSetType(&curMask, TT_SPACE);
(void) DBTreeSrLabels(scx, &curMask, xMask, (TerminalPath *) NULL,
TF_LABEL_ATTACH, plotPSLabel, (ClientData) NULL);
}
else
{
fprintf(file, "grestore\n"); /* end clipping rectangle */
}
/* Output trailer information into the file, and close it. */
fprintf(file, "pgsave restore showpage\n\n");
fprintf(file, "%%%%Trailer\nMAGICsave restore\n%%%%EOF\n");
fclose(file);
return;
}
|