File: plotMain.c

package info (click to toggle)
magic 8.3.105%2Bds.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 17,128 kB
  • sloc: ansic: 175,615; sh: 7,634; tcl: 4,536; lisp: 2,554; makefile: 946; cpp: 587; python: 389; csh: 148; awk: 140
file content (649 lines) | stat: -rw-r--r-- 15,856 bytes parent folder | download | duplicates (2)
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
/*
 * plotMain.c --
 *
 * This is the central file in the plot module.  It contains tables
 * that define the various styles of plotting that are available, and
 * also contains central technology-file reading routines.
 *
 *     *********************************************************************
 *     * 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/plotMain.c,v 1.1.1.1 2008/02/03 20:43:50 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 "plot/plotInt.h"
#include "textio/textio.h"
#include "utils/utils.h"

/* Magic can generate plots in several different ways, e.g. as a
 * Gremlin file or as a direct raster plot to a Versatec printer.
 * For each style of plot, there is a subsection of the plot section
 * of technology files.  The tables below define the names of those
 * subsections, and the procedures to call to handle lines within
 * those subsections.  To add a new style of plot, extend the tables
 * below and then modify the procedure CmdPlot to actually invoke
 * the top-level plotting routine.
 */

/* Note (10/8/04):  All of the plot styles except PostScript and PNM	*/
/* have been removed in the default compilation.  However, they should	*/
/* remain in the following lists so that magic doesn't complain when	*/
/* encountering these styles in the technology file.			*/

static char *plotStyles[] =		/* Names of tech subsections. */
{
    "postscript",
    "pnm",
    "gremlin",
    "versatec",
    "colorversatec",
    "pixels",
    NULL
};

/* These names need to match the plot types enumerated in plotInt.h */
static char *plotTypeNames[] =
{
    "versatec_color",
    "versatec_bw",
    "hprtl",
    "hpgl2",
    NULL
};


static void (*plotInitProcs[])() =	/* Initialization procedures for
					 * each style.
					 */
{
    PlotPSTechInit,
    PlotPNMTechInit,
    PlotGremlinTechInit,
    PlotVersTechInit,
    PlotColorVersTechInit,
    PlotPixTechInit,
    NULL
};

static bool (*plotLineProcs[])() =	/* Proc to call for each line in
					 * relevant subsection of tech file.
					 */
{
    PlotPSTechLine,
    PlotPNMTechLine,
    PlotGremlinTechLine,
    PlotVersTechLine,
    PlotColorVersTechLine,
    PlotPixTechLine,
    NULL
};

static void (*plotFinalProcs[])() =	/* Proc to call at end of reading
					 * tech files.
					 */
{
    NULL,
    PlotPNMTechFinal,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
};

static int plotCurStyle = -1;		/* Current style being processed in
					 * technology file.  -1 means no
					 * "style" line seen yet.  -2 means
					 * skipping to next "style" line.
					 */

bool PlotShowCellNames = TRUE;		/* TRUE if cell names and use-ids
					 * should be printed inside cell
					 * bounding boxes; if this is FALSE,
					 * then only the bounding box is
					 * drawn.
					 */


/*
 * ----------------------------------------------------------------------------
 *	PlotTechInit --
 *
 * 	Called once at beginning of technology file read-in to initialize
 *	data structures.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Calls the initialization procedures (if any) for each of the
 *	various styles of plotting.
 * ----------------------------------------------------------------------------
 */

void
PlotTechInit()
{
    int i;

    PlotRastInit();

    plotCurStyle = -1;
    for (i = 0; plotStyles[i] != NULL; i++)
    {
	if (plotInitProcs[i] != NULL)
	    (*(plotInitProcs[i]))();
    }
}

/*
 * ----------------------------------------------------------------------------
 *	PlotTechLine --
 *
 * 	This procedure is invoked by the technology module once for
 *	each line in the "plot" section of the technology file.  It
 *	processes "style x" lines directly, to change the current style
 *	of plot information.  For other lines, it just passes the lines
 *	onto the procedure for the current style.
 *
 * Results:
 *	Returns whatever the handler for the current style returns when
 *	we call it.
 *
 * Side effects:
 *	Builds up plot technology information.
 * ----------------------------------------------------------------------------
 */

bool
PlotTechLine(sectionName, argc, argv)
    char *sectionName;		/* Name of this section. */
    int argc;			/* Number of arguments on line. */
    char *argv[];		/* Pointers to fields of line. */
{
    int i;

    if (strcmp(argv[0], "style") == 0)
    {
	if (argc != 2)
	{
	    TechError("\"style\" lines must have exactly two arguments\n");
	    return TRUE;
	}

	/* Change the style of plot for which information is being read. */

	plotCurStyle = -2;
	for (i = 0; plotStyles[i] != NULL; i++)
	{
	    if (strcmp(argv[1], plotStyles[i]) == 0)
	    {
		plotCurStyle = i;
		break;
	    }
	}

	if (plotCurStyle == -2)
	{
	    TechError("Plot style \"%s\" doesn't exist.  Ignoring.\n",
		    argv[1]);
	}
	return TRUE;
    }

    /* Not a new style.  Just farm out this line to the handler for the
     * current style.
     */

    if (plotCurStyle == -1)
    {
	TechError("Must declare a plot style before anything else.\n");
	plotCurStyle = -2;
	return TRUE;
    }
    else if (plotCurStyle == -2)
	return TRUE;

    if (plotLineProcs[plotCurStyle] == NULL)
	return TRUE;
    return (*(plotLineProcs[plotCurStyle]))(sectionName, argc, argv);
}

/*
 * ----------------------------------------------------------------------------
 *	PlotTechFinal --
 *
 * 	Called once at the end of technology file read-in.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Calls the finalization procedures (if any) for each of the
 *	various style of plotting.
 * ----------------------------------------------------------------------------
 */

void
PlotTechFinal()
{
    int i;

    plotCurStyle = -1;
    for (i = 0; plotStyles[i] != NULL; i++)
    {
	if (plotFinalProcs[i] != NULL)
	    (*(plotFinalProcs[i]))();
    }
}

/*
 * ----------------------------------------------------------------------------
 *
 * PlotPrintParams --
 *
 * 	Print out a list of all the plotting parameters and their
 *	current values.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Stuff gets printed.
 *
 * ----------------------------------------------------------------------------
 */

void
PlotPrintParams()
{
    TxPrintf("General plotting parameters are:\n");
    TxPrintf("    showCellNames: %s\n", PlotShowCellNames ? "true" : "false");
    TxPrintf("");
    TxPrintf("Postscript plotting parameters are:\n");
    TxPrintf("    PS_cellIdFont:  \"%s\"\n", PlotPSIdFont);
    TxPrintf("    PS_cellNameFont:\"%s\"\n", PlotPSNameFont);
    TxPrintf("    PS_labelFont:   \"%s\"\n", PlotPSLabelFont);
    TxPrintf("    PS_cellIdSize:  %d\n", PlotPSIdSize);
    TxPrintf("    PS_cellNameSize:%d\n", PlotPSNameSize);
    TxPrintf("    PS_labelSize:   %d\n", PlotPSLabelSize);
    TxPrintf("    PS_boundary:   %s\n",  PlotPSBoundary ? "true" : "false");
    TxPrintf("    PS_width:       %d (%.3f in)\n", PlotPSWidth,
		(float)PlotPSWidth / 72);
    TxPrintf("    PS_height:      %d (%.3f in)\n", PlotPSHeight,
		(float)PlotPSHeight / 72);
    TxPrintf("    PS_margin:      %d (%.3f in)\n", PlotPSMargin,
		(float)PlotPSMargin / 72);

    TxPrintf("");
    TxPrintf("PNM plotting parameters are:\n");
    TxPrintf("    pnmmaxmem: %d KB\n", PlotPNMmaxmem);
    TxPrintf("    pnmdownsample: %d\n", PlotPNMdownsample);
    TxPrintf("    pnmbackground: %d\n", PlotPNMBG);

#ifdef VERSATEC
    TxPrintf("    pnmplotRTL: %s\n", PlotPNMRTL ? "true" : "false");
    TxPrintf("");
    TxPrintf("HP/Versatec plotting parameters are:\n");
    TxPrintf("    cellIdFont:    \"%s\"\n", PlotVersIdFont);
    TxPrintf("    cellNameFont:  \"%s\"\n", PlotVersNameFont);
    TxPrintf("    directory:     \"%s\"\n", PlotTempDirectory);
    TxPrintf("    dotsPerInch:   %d\n", PlotVersDotsPerInch);
    TxPrintf("    labelFont:     \"%s\"\n", PlotVersLabelFont);
    TxPrintf("    printer:       \"%s\"\n", PlotVersPrinter);
    TxPrintf("    spoolCommand:  \"%s\"\n", PlotVersCommand);
    TxPrintf("    swathHeight:   %d\n", PlotVersSwathHeight);
    TxPrintf("    width:         %d\n", PlotVersWidth);
    TxPrintf("    plotType:      %s\n", plotTypeNames[PlotVersPlotType]);
#endif
#ifdef LLNL
    TxPrintf("");
    TxPrintf("Pixel plotting parameters are:\n");
    TxPrintf("    pixheight:   %d\n", PlotPixHeight);
    TxPrintf("    pixwidth:         %d\n", PlotPixWidth);
#endif /* LLNL */
}

/*
 * ----------------------------------------------------------------------------
 *
 * PlotSetParam --
 *
 * 	This procedure is called to change the value of one
 *	of the plotting parameters.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Whichever parameter is named by "name" is set to "value".
 *	The interpretation of "value" depends on the parameter.
 *
 * ----------------------------------------------------------------------------
 */

typedef enum {
	SHOWCELLNAMES=0,
	PSCELLIDFONT,
	PSNAMEFONT,
	PSLABELFONT,
	PSIDSIZE,
	PSNAMESIZE,
	PSLABELSIZE,
	PSBOUNDARY,
	PSWIDTH,
	PSHEIGHT,
	PSMARGIN,
#ifdef VERSATEC
	CELLIDFONT,
	CELLNAMEFONT,
	LABELFONT,
	DIRECTORY,
	DOTSPERINCH,
	PRINTER,
	SPOOLCOMMAND,
	SWATHHEIGHT,
	WIDTH,
	PLOTTYPE,
	PNMRTL,
#endif
#ifdef LLNL
	PIXWIDTH,
	PIXHEIGHT,
#endif
	PNMMAXMEM,
	PNMDOWNSAMPLE,
	PNMBACKGROUND
} PlotParameterOptions;

void
PlotSetParam(name, value)
    char *name;			/* Name of a parameter. */
    char *value;		/* New value for the parameter. */
{
    int indx, i;
    static char *tfNames[] = { "false", "true", 0 };
    static char *paramNames[] =
    {
	"showcellnames",
	"ps_cellidfont",
	"ps_namefont",
	"ps_labelfont",
	"ps_cellidsize",
	"ps_namesize",
	"ps_labelsize",
	"ps_boundary",
	"ps_width",
	"ps_height",
	"ps_margin",
#ifdef VERSATEC
	"cellidfont",
	"cellnamefont",
	"labelfont",
	"directory",
	"dotsperinch",
	"printer",
	"spoolcommand",
	"swathheight",
	"width",
	"plottype",
	"pnmplotRTL",	  /* PNM output piped through an HP plotter */
#endif
#ifdef LLNL
	"pixwidth",
	"pixheight",
#endif
	"pnmmaxmem",
	"pnmdownsample",
	"pnmbackground",
	NULL
    };

    indx = Lookup(name, paramNames);
    if (indx < 0)
    {
	TxError("\"%s\" isn't a valid plot parameter.\n", name);
	PlotPrintParams();
	return;
    }

    i = atoi(value);
    switch (indx)
    {
	case SHOWCELLNAMES:
	    i = Lookup(value, tfNames);
	    if (i < 0)
	    {
		TxError("ShowCellNames can only be \"true\" or \"false\".\n");
		return;
	    }
	    PlotShowCellNames = i;
	    break;
	case PSCELLIDFONT:
	    StrDup(&PlotPSIdFont, value);
	    break;
	case PSNAMEFONT:
	    StrDup(&PlotPSNameFont, value);
	    break;
	case PSLABELFONT:
	    StrDup(&PlotPSLabelFont, value);
	    break;
	case PSIDSIZE:
	    if (!StrIsInt(value) || (i <= 0))
	    {
		TxError("PS_cellIdSize must be an integer greater than zero.\n");
		return;
	    }
	    else PlotPSIdSize = i;
	    break;
	case PSNAMESIZE:
	    if (!StrIsInt(value) || (i <= 0))
	    {
		TxError("PS_cellNameSize must be an integer greater than zero.\n");
		return;
	    }
	    else PlotPSNameSize = i;
	    break;
	case PSLABELSIZE:
	    if (!StrIsInt(value) || (i <= 0))
	    {
		TxError("PS_labelSize must be an integer greater than zero.\n");
		return;
	    }
	    else PlotPSLabelSize = i;
	    break;
        case PSBOUNDARY:
	    i = Lookup(value, tfNames);
	    if (i < 0)
	    {
		TxError("PS_boundary can only be \"true\" or \"false\".\n");
		return;
	    }
	    PlotPSBoundary = i;
	    break;
	case PSWIDTH:
	    if (!StrIsInt(value) || (i <= 0))
	    {
		TxError("PS_Width must be an integer greater than zero.\n");
		return;
	    }
	    else PlotPSWidth = i;
	    break;
	case PSHEIGHT:
	    if (!StrIsInt(value) || (i <= 0))
	    {
		TxError("PS_Height must be an integer greater than zero.\n");
		return;
	    }
	    else PlotPSHeight = i;
	    break;
	case PSMARGIN:
	    if (!StrIsInt(value) || (i < 0))
	    {
		TxError("PS_Margin must be an integer greater than or equal to zero.\n");
		return;
	    }
	    else PlotPSMargin = i;
	    break;

#ifdef VERSATEC
	case CELLIDFONT:
	    StrDup(&PlotVersIdFont, value);
	    break;
	case CELLNAMEFONT:
	    StrDup(&PlotVersNameFont, value);
	    break;
	case LABELFONT:
	    StrDup(&PlotVersLabelFont, value);
	    break;
	case DIRECTORY:
	    StrDup(&PlotTempDirectory, value);
	    break;
	case DOTSPERINCH:
	    if (!StrIsInt(value) || (i <= 0))
	    {
		TxError("DotsPerInch must be an integer greater than zero.\n");
		return;
	    }
	    else PlotVersDotsPerInch = i;
	    break;
	case PRINTER:
	    StrDup(&PlotVersPrinter, value);
	    break;
	case PLOTTYPE:
	    i = Lookup(value, plotTypeNames);
	    if (i < 0)
	    {
		int j;

		TxError("%s is not a supported plot type.  Plot types are:\n");
		for (j = 0 ; plotTypeNames[j] != NULL; j++)
		{
		    TxError("\t%s\n", plotTypeNames[j]);
		}
		return;
	    }
	    PlotVersPlotType = i;
	    switch(PlotVersPlotType)
	    {
		case VERSATEC_COLOR:
		    PlotVersDotsPerInch = 215;
		    PlotVersWidth = 7904;
		    break;
		case VERSATEC_BW:
		    PlotVersDotsPerInch = 215;
		    PlotVersWidth = 7904;
		    break;
		case HPRTL:
		    PlotVersDotsPerInch = 316;
		    PlotVersWidth = 2400;
		    break;
		case HPGL2:
		    PlotVersDotsPerInch = 300;
		    PlotVersWidth = 10650;
		    break;
	    }
	    break;
	case SPOOLCOMMAND:
	    StrDup(&PlotVersCommand, value);
	    break;
	case SWATHHEIGHT:
	    if (!StrIsInt(value) || (i <= 0))
	    {
		TxError("SwathHeight must be an integer greater than zero.\n");
		return;
	    }
	    else PlotVersSwathHeight= i;
	    break;
	case WIDTH:
	    if (!StrIsInt(value) || (i <= 0))
	    {
		TxError("Width must be an integer greater than zero.\n");
		return;
	    }
	    else PlotVersWidth = i;
	    break;

	case PNMRTL:
	    i = Lookup(value, tfNames);
	    if (i < 0)
	    {
		TxError("pnmplotRTL can only be \"true\" or \"false\".\n");
		return;
	    }
	    PlotPNMRTL = i;
	    break;

#endif /* VERSATEC */

#ifdef LLNL

	case PIXWIDTH:
	    if (!StrIsInt(value) || (i <= 0))
	    {
		TxError("PixWidth must be an integer greater than zero.\n");
		return;
	    }
	    else PlotPixWidth = i;
	    break;
	case PIXHEIGHT:
	    if (!StrIsInt(value) || (i <= 0))
	    {
		TxError("PixHeight must be an integer greater than zero.\n");
		return;
	    }
	    else PlotPixHeight = i;
	    break;

#endif /* LLNL */

        case PNMMAXMEM:
  	    if (!StrIsInt(value) || (i <= 0))
	    {
	        TxError("pnmmaxmem must be an integer greater than zero.\n");
		return;
	    }
	    else PlotPNMmaxmem = i;
	    break;

        case PNMDOWNSAMPLE:
  	    if (!StrIsInt(value) || (i < 0))
	    {
	        TxError("pnmdownsample must be an integer zero or larger.\n");
		return;
	    }
	    else PlotPNMdownsample = i;
	    break;

        case PNMBACKGROUND:
  	    if (!StrIsInt(value) || (i < 0) || (i > 255))
	    {
	        TxError("pnmbackground must be an integer 0-255.\n");
		return;
	    }
	    else PlotPNMBG = (unsigned char)i;
	    break;
    }
}