File: xcircuit.h

package info (click to toggle)
xcircuit 2.0a6-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,960 kB
  • ctags: 3,202
  • sloc: ansic: 30,529; makefile: 51; sh: 2
file content (640 lines) | stat: -rw-r--r-- 18,904 bytes parent folder | download
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
/*-------------------------------------------------------------------------*/
/* xcircuit.h 								   */
/*-------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------*/
/*      written by Tim Edwards, 8/20/93    				   */
/*-------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------*/
/* Definition shortcuts 						   */
/*-------------------------------------------------------------------------*/

#define XtnSetArg(a,b)  	XtSetArg(wargs[n], a, b); n++
#define abs(a)			((a) < 0 ? -(a) : (a))
#define sign(a)			((a) <= 0 ? -1 : 1)
#define max(a,b)		((a) < (b) ? (b) : (a))
#define min(a,b)		((a) < (b) ? (a) : (b))
#define Number(a)		(void *)((unsigned int) a)
#define ROT_UNIT (360 / RSTEPS) /* degrees per xcircuit rotational unit */

/*-------------------------------------------------------------------------*/
/* Lengthier define constructs						   */
/*-------------------------------------------------------------------------*/

#define objectdata      areastruct.topobject->thisobject
#define PLIST_INCR(a) \
	a->plist = (genericptr *) realloc (a->plist, \
	(a->parts + 1) * sizeof(genericptr))
#define SELECTTYPE(a)   (*(objectdata->plist + *a))->type
#define SELTOCOLOR(a)	(*(objectdata->plist + *a))->color
#define ENDPART		objectdata->plist + objectdata->parts
#define EDITPART	objectdata->plist + areastruct.editpart

/* conversions from generic to specific types */
/* specifically, from type (generic *) to type (polyptr), etc. */

#define TOPOLY(a)	(*((polyptr *)a))
#define TOLABEL(a)	(*((labelptr *)a))
#define TOOBJINST(a)	(*((objinstptr *)a))
#define TOARC(a)	(*((arcptr *)a))
#define TOSPLINE(a)	(*((splineptr *)a)) 
#define TOPATH(a)	(*((pathptr *)a))

/* conversions from a selection to a specific type */

#define SELTOPOLY(a)	TOPOLY(objectdata->plist + (*a))
#define SELTOLABEL(a)	TOLABEL(objectdata->plist + (*a))
#define SELTOOBJINST(a)	TOOBJINST(objectdata->plist + (*a))
#define SELTOARC(a)	TOARC(objectdata->plist + (*a))
#define SELTOSPLINE(a)	TOSPLINE(objectdata->plist + (*a))
#define SELTOPATH(a)	TOPATH(objectdata->plist + (*a))

/* creation of new elements */

#define NEW_POLY(a,b) \
	PLIST_INCR(b); \
	a = (polyptr *)b->plist + b->parts; \
	*a = (polyptr) malloc(sizeof(polygon)); \
	(*a)->type = POLYGON
#define NEW_LABEL(a,b) \
	PLIST_INCR(b); \
	a = (labelptr *)b->plist + b->parts; \
	*a = (labelptr) malloc(sizeof(label)); \
	(*a)->type = LABEL
#define NEW_OBJINST(a,b) \
	PLIST_INCR(b); \
	a = (objinstptr *)b->plist + b->parts; \
	*a = (objinstptr) malloc(sizeof(objinst)); \
	(*a)->type = OBJECT
#define NEW_ARC(a,b) \
	PLIST_INCR(b); \
	a = (arcptr *)b->plist + b->parts; \
	*a = (arcptr) malloc(sizeof(arc)); \
	(*a)->type = ARC
#define NEW_SPLINE(a,b) \
	PLIST_INCR(b); \
	a = (splineptr *)b->plist + b->parts; \
	*a = (splineptr) malloc(sizeof(spline)); \
	(*a)->type = SPLINE
#define NEW_PATH(a,b) \
	PLIST_INCR(b); \
	a = (pathptr *)b->plist + b->parts; \
	*a = (pathptr) malloc(sizeof(path)); \
	(*a)->type = PATH
		   
/*-------------------------------------------------------------------------*/

typedef unsigned char		uchar;

typedef struct {
   float x, y;
} XfPoint;

typedef struct {
   long x, y;
} XlPoint;

/*-------------------------------------------------------------------------*/
/* Implementation-specific definitions 					   */
/*-------------------------------------------------------------------------*/

#define LIBS	    2 /* number of library pages 			*/
#define PAGES      10 /* default number of top-level pages 		*/
#define FONTS	   14 /* default number of predefined fonts 		*/
#define SCALEFAC  1.5 /* zoom in/out scaling multiplier 		*/
#define SUBSCALE 0.67 /* ratio of subscript size to normal script size 	*/
#define SBARSIZE   13 /* Pixel size of the scrollbar 			*/
#define RSTEPS     72 /* Number of allowed rotation positions 		*/
#define SPLINESEGS 20 /* Number of points per spline approximation 	*/
#define DELBUFSIZE 10 /* Number of delete events to save for undeleting */
#define MINAUTOSCALE 0.75 /* Won't automatically scale closer than this */

#ifdef SCHEMA
#define PADSPACE   20 /* Spacing of pinlabels from their origins	*/
#endif

#define TOPLEVEL	0
#define SINGLE		1

#define INTSEGS		(SPLINESEGS - 2)
#define LASTSEG		(SPLINESEGS - 3)

#define ROWHEIGHT  (areastruct.textstruct->ascent + \
		    areastruct.textstruct->descent + 6)
#define LISTHEIGHT 200
#define TEXTHEIGHT 28 /* Height of xcircuit vectored font at nominal size */
#define HALFHEIGHT 14 /* Half of TEXTHEIGHT */

/*-----------------------------------------------------------------------*/

#define INVRFAC 57.295779       /* 180 / pi */

/*-----------------------------------------------------------------------*/

#define INCHSCALE 0.375     /* Scale of .25 inches to PostScript units */
#define CMSCALE 0.35433071  /* Scale of .5 cm to PostScript units */
#define IN_CM_CONVERT 28.3464567	/* 72 (in) / 2.54 (cm/in) */

/*-------------------------------------------------------------------------*/
/* Event mode definitions (state of drawing area)			   */
/*-------------------------------------------------------------------------*/

#define NORMAL_MODE 	0
#define PRESS_MODE 	1
#define POPUP_MODE	2
#define DELETE_MODE 	3
#define COPY_MODE 	4 
#define COPY2_MODE 	5 
#define ROTATE_MODE     6
#define PUSH_MODE       7
#define EDIT_MODE       8
#define SELAREA_MODE    9
#define SELAREA2_MODE   10
#define DESEL_MODE      11
#define PAN_MODE        12
#define CATPAN_MODE     13
#define CATALOG_MODE    14
#define CATTEXT_MODE    15
#define TEXT0_MODE      16
#define TEXT1_MODE	17
#define TEXT2_MODE      18
#define TEXT3_MODE      19
#define WIRE_MODE       20 
#define BOX0_MODE       21
#define BOX_MODE        22
#define EBOX_MODE       23
#define ARC0_MODE       24
#define ARC_MODE        25
#define EARC_MODE       26
#define SPLINE0_MODE    27
#define SPLINE_MODE     28
#define ESPLINE_MODE    29

/*-------------------------------------------------------------------------*/
/* Text justification styles						   */
/*-------------------------------------------------------------------------*/

#define NOTLEFT		1
#define RIGHT		2
#define NOTBOTTOM	4
#define TOP		8
#define FLIPINV		16

/*-------------------------------------------------------------------------*/
/* Text script styles						   	   */
/*-------------------------------------------------------------------------*/

#define TEXT_ESC	27  /* escape character for defining text controls */
#define CONTROL_START	32  /* first character used by controls */
#define SUBSCRIPT	32
#define SUPERSCRIPT	33
#define NORMALSCRIPT	34
#define UNDERLINE	35
#define OVERLINE	36
#define NOLINE		37
#define BACKSPACE	38
#define HALFSPACE	39
#define QTRSPACE	40

#define FONT_START	100   /* character of first inline font designator */

/*-------------------------------------------------------------------------*/
/* Reset modes								   */
/*-------------------------------------------------------------------------*/

#define SAVE		1
#define DESTROY		2

/*-------------------------------------------------------------------------*/
/* Coordinate display types						   */
/*-------------------------------------------------------------------------*/

#define DEC_INCH	0
#define FRAC_INCH	1
#define CM		2

/*-------------------------------------------------------------------------*/
/* Library types							   */
/*-------------------------------------------------------------------------*/

#define USERLIB		0
#define LIBRARY		1

/*-------------------------------------------------------------------------*/
/* Box styles								   */
/*-------------------------------------------------------------------------*/

#define NORMAL 0
#define UNCLOSED 1
#define DASHED 2
#define DOTTED 4
#define NOBORDER 8
#define FILLED 16
#define STIP0 32
#define STIP1 64
#define STIP2 128
#define FILLSOLID 224  /* = 32 + 64 + 128 */
#define OPAQUE 256

/*-------------------------------------------------------------------------*/
/* Box edit styles							   */
/*-------------------------------------------------------------------------*/

#define MANHATTAN 1
#define RHOMBOIDX 2
#define RHOMBOIDY 4
#define RHOMBOIDA 8

#define NONE  0
#define LASTX 1
#define NEXTX 2
#define LASTY 4
#define NEXTY 8

/*-------------------------------------------------------------------------*/
/* Arc creation and edit styles						   */
/*-------------------------------------------------------------------------*/

#define CENTER 1
#define RADIAL 2

/*-------------------------------------------------------------------------*/
/* Delete/undelete draw-mode styles					   */
/*-------------------------------------------------------------------------*/

#define ERASE 1
#define DRAW  1

/*-------------------------------------------------------------------------*/
/* Schematic object types and pin label types	   			   */
/*-------------------------------------------------------------------------*/

#ifdef SCHEMA

#define SCHEMATIC 0
#define FUNDAMENTAL 1
#define SYMBOL 2

#define LOCAL 1
#define GLOBAL 2

#endif

/*-------------------------------------------------------------------------*/
/* Color scheme styles (other than NORMAL)				   */
/*-------------------------------------------------------------------------*/

#define INVERSE		1

/*-------------------------------------------------------------------------*/
/* Cursor definitions 							   */
/*-------------------------------------------------------------------------*/

#define NUM_CURSORS	9

#define ARROW 		appcursors[0]
#define CROSS 		appcursors[1]
#define SCISSORS 	appcursors[2]
#define COPYCURSOR	appcursors[3]
#define ROTATECURSOR    appcursors[4]
#define EDCURSOR	appcursors[5]
#define TEXTPTR 	appcursors[6]
#define CIRCLE		appcursors[7]
#define QUESTION	appcursors[8]

/*-------------------------------------------------------------------------*/
/* selection-mechanism structures					   */
/*-------------------------------------------------------------------------*/

typedef XPoint* pointlist;
typedef XfPoint* fpointlist;

/*-------------------------------------------------------------------------*/
/* select types */
/*-------------------------------------------------------------------------*/

#define	OBJECT	1
#define LABEL	2
#define POLYGON	4
#define ARC	8
#define SPLINE  16
#define PATH	32
#define ANY	63  /* for selection mechanism only */

/*-------------------------------------------------------------------------*/
/* Vector-drawn font character structure				   */
/*-------------------------------------------------------------------------*/

#define MAXSEGS 29	/* Maximum number of segments per character part */

typedef struct {
   short        width;
   short        parts;
   short        number[3];
   pointlist    points[3];
} alpha, *alphaptr;

/*--------------------------------------------------------------------------*/
/* structures of all the main elements which can be displayed & manipulated */
/*--------------------------------------------------------------------------*/

typedef struct _object *objectptr;

typedef struct {
   uchar	type;		/* type is LABEL, POLYGON, etc., from below */
   int		color;
} generic, *genericptr;		/* (convenience function for retypecasting) */

typedef struct {
   uchar	type;
   int		color;
   XPoint	position;
   short	rotation;
   float	scale;
   objectptr	thisobject;
} objinst, *objinstptr;

typedef struct {
   uchar	type;
   int		color;
   XPoint	position;
   short	rotation;
   float	scale;
   short	justify;
#ifdef SCHEMA
   uchar	pin;
#endif
   uchar	*string;
} label, *labelptr;

typedef struct {
   uchar	type;
   int		color;
   short	style;
   float	width;
   short	number;
   pointlist	points;
} polygon, *polyptr;

typedef struct {
   uchar	type;
   int		color;
   short	style;
   float	width;
   XPoint	ctrl[4];
   /* the following are for rendering only */
   XfPoint	points[INTSEGS];
} spline, *splineptr;

typedef struct {
   uchar	type;
   int		color;
   short	style;
   float	width;
   short	radius; 	/* x-axis radius */
   short	yaxis;		/* y-axis radius */
   float	angle1;
   float	angle2;
   XPoint	position;
   /* the following are for rendering only */
   short	number;
   XfPoint	points[RSTEPS + 1];
} arc, *arcptr;

typedef struct {
   uchar	type;
   int		color;
   short	style;
   float	width;
   short	parts;
   genericptr	*plist;		/* to be retypecast to polygon, arc, or spline */
} path, *pathptr;

/*--------------------------------------------------------------------------*/
/* Netlist structures for schematic capture				    */
/* (courtesy of Chow Seong Hwai, 3/20/98)				    */
/*--------------------------------------------------------------------------*/

#ifdef SCHEMA

struct Netlist
{
   polyptr poly;
   int netid;
   struct Netlist *next;
};

struct Pinlist
{
   labelptr pin;
   char *pinx;
   int netid;
   struct Pinlist *next;
};

struct Calllist
{
   objectptr callobj;
   int callno;
   int netid;
   labelptr pin;
   struct Calllist *next;
};

#endif

/*--------------------------------------------------------------------------*/
/* Main object structure						    */
/*--------------------------------------------------------------------------*/

typedef struct _object {
   char		name[80];
   Boolean	hidden;
   XPoint	lowerleft;	/* bounding box */
   Dimension	width, height;  /* information  */
   short	parts;
   genericptr	*plist;		/* to be retypecast to label, polygon, etc. */
#ifdef SCHEMA
   XPoint	lleft2;		 /* bounding box info excluding pins */
   Dimension	width2, height2;

   uchar	schemtype;
   objectptr	symschem;	/* schematic page support */

   struct Netlist   *netlist;
   struct Pinlist   *pinlist;
   struct Calllist  *calllist;
   short traversed;
#endif
} object;

/*--------------------------------------------------------------------------*/
/* Transformation matrices						    */
/*--------------------------------------------------------------------------*/

typedef struct {
   float a, b, c, d, e, f;
} Matrix;

/*-------------------------------------------------------------------------*/
/* Some convenience functions for matrix manipulation			   */
/*-------------------------------------------------------------------------*/

#define DCTM  &areastruct.MatStack[areastruct.MatStackDepth - 1]
#define DCTM2 &areastruct.MatStack[areastruct.MatStackDepth - 2]
#define UPopCTM() areastruct.MatStackDepth--

/*-------------------------------------------------------------------------*/
/* button tap/press definitions 					   */
/*-------------------------------------------------------------------------*/

#define PRESSTIME	150	/* milliseconds of push to be a "press" */

/*-------------------------------------------------------------------------*/
/* structures for managing the popup prompt widgets 			   */
/*-------------------------------------------------------------------------*/

typedef struct {
   Widget	button;
   int		foreground;
   void		(*buttoncall)();
   void		*dataptr;
} buttonsave;

typedef struct {
   Widget	popup;
   Widget	textw;
   void		(*setvalue)();
   buttonsave	*buttonptr;
   Boolean	fileprompt;
} popupstruct;

typedef struct {
   Widget	textw;
   Widget	buttonw;
   void		(*setvalue)();
   void		*dataptr;
} propstruct;

/*-------------------------------------------------------------------------*/
/* Initial Resource Management						   */
/*-------------------------------------------------------------------------*/

typedef struct {
   /* color scheme 1 */
   Pixel	fg, bg;
   Pixel	gridpix, snappix, selectpix, axespix;
   Pixel	buttonpix, querypix;
   Pixel	auxpix, barpix;

   /* color scheme 2 */

   Pixel	fg2, bg2;
   Pixel	gridpix2, snappix2, selectpix2, axespix2;
   Pixel	buttonpix2, querypix2;
   Pixel	auxpix2, barpix2;

   int		width, height;
   XFontStruct	*xcfont;
} ApplicationData, *ApplicationDataPtr;

/*-------------------------------------------------------------------------*/
/* Macros for GC color and function handling				   */
/*-------------------------------------------------------------------------*/

#define XTopSetForeground(a) if (a == DEFAULTCOLOR) XSetForeground(dpy, \
	areastruct.gc, FOREGROUND); else XSetForeground(dpy, areastruct.gc, a)

#define XSetXORFg(a,b) if (a == DEFAULTCOLOR) XSetForeground(dpy, \
	areastruct.gc, FOREGROUND ^ b); else XSetForeground(dpy, areastruct.gc,\
	a ^ b)

#define XcSetFunction(z) XSetFunction(dpy, areastruct.gc, z); \
	areastruct.gctype = z

#define XcSetForeground(z) XTopSetForeground(z); areastruct.gccolor = \
	((z) == DEFAULTCOLOR) ? FOREGROUND : (z)

#define XcSetXORFg(y,z) XSetXORFg(y,z); areastruct.gccolor = \
	((y) == DEFAULTCOLOR) ? (FOREGROUND ^ z) : (y ^ z)

/*-------------------------------------------------------------------------*/
/* Structure for maintaining list of colors				   */
/*-------------------------------------------------------------------------*/

typedef struct {
   Widget	cbutton;
   XColor	color;
} colorindex;

/*-------------------------------------------------------------------------*/
/* the main globally-accessible data structure				   */
/* This structure holds all the critical data needed by the drawing window */
/*-------------------------------------------------------------------------*/

typedef struct {

   /* widgets and X11 parameters */
   Widget	area;
   Widget	scrollbarh, scrollbarv;
   GC 		gc;
   int		gccolor, gctype;
   XFontStruct  *textstruct;
   XtIntervalId time_id;

   /* global page parameters */
   short	width, height;
   short	page, pages;
   float	*vscale;	/* pointer to proper scale */
   XPoint	*lowerleft;

   /* per-drawing-page parameters */
   char		**filename;	/* file to save as */
   float	*wirewidth;
   float	*outscale;
   float	*viewscale;
   short	*orient;
   short	*pmode;
   short	*coordstyle;
   XPoint	*drawingscale;
   XPoint	*pcorner;
   XPoint	*pagesize;	/* size of page to print on */

   /* option defaults */
   float	textscale;
   short	psfont;
   short	justify;
   short	style;
   int		color;
   Boolean	manhatn;
   Boolean	boxedit;
   Boolean	snapto;
   short	snapspace;
   Boolean	gridon;
   short	gridspace;
   Boolean	axeson;
   Boolean	invert;
#ifdef SCHEMA
   Boolean	schemon;
#endif

   /* buffers, pages, and associated variables */
   XPoint	save, origin;
   short	selects;
   short	*selectlist;
   objinstptr	topobject;
   objinstptr	*hierarchy;
   short	hlevels;
   short	builtins, userobjs, deletes;
   objectptr	*library, *userlib, *delbuffer, editstack, *pagelist;
   objectptr	libtop[LIBS];
   float	tempvscale, libvscale;
   XPoint	temppcorner, libpcorner;
   Matrix	*MatStack;
   short	MatStackDepth;
   short	editcycle;
   short	editpart;
} Clientdata, *Clientptr;

/*-------------------------------------------------------------------------*/