Corrected a long-standing error in which ending text with a literal
[xcircuit.git] / xcircuit.h
blob359e138c47b8cac2f3c05dd10d987a5d0f66f77c
1 /*----------------------------------------------------------------------*/
2 /* xcircuit.h */
3 /* Copyright (c) 2002 Tim Edwards, Johns Hopkins University */
4 /*----------------------------------------------------------------------*/
6 /*----------------------------------------------------------------------*/
7 /* written by Tim Edwards, 8/20/93 */
8 /*----------------------------------------------------------------------*/
10 #ifndef HAVE_U_CHAR
11 typedef unsigned char u_char;
12 typedef unsigned short u_short;
13 typedef unsigned int u_int;
14 typedef unsigned long u_long;
15 typedef unsigned long long u_long_long;
16 #endif
18 #ifdef XC_WIN32
19 #ifdef TCL_WRAPPER
20 #include "tkwin32.h"
21 #else
22 #include "xcwin32.h"
23 #endif
24 #endif
26 #ifdef HAVE_CAIRO
27 #include <cairo/cairo.h>
28 #endif
30 /*----------------------------------------------------------------------*/
31 /* portable definition to prevent unused variables warning */
32 /*----------------------------------------------------------------------*/
34 #define UNUSED(x) (void) x
36 /*----------------------------------------------------------------------*/
37 /* Graphics functions defined for X11 */
38 /*----------------------------------------------------------------------*/
40 #ifdef HAVE_CAIRO
42 #define SetForeground(display, gc, fg) xc_cairo_set_color(fg)
43 typedef cairo_surface_t xcImage;
45 #else /* !HAVE_CAIRO */
47 typedef XImage xcImage;
48 #define DrawLine XDrawLine
49 #define DrawLines XDrawLines
50 #define DrawPoint XDrawPoint
51 #define FillPolygon XFillPolygon
53 #define SetForeground(dpy, gc, fg) XSetForeground(dpy, gc, colorlist[fg].color.pixel)
54 #define SetBackground(dpy, gc, bg) XSetBackground(dpy, gc, colorlist[bg].color.pixel)
55 #define SetThinLineAttributes XSetLineAttributes
56 #define SetLineAttributes(a, b, c, d, e, f) \
57 XSetLineAttributes(a, b, ((c) >= 1.55 ? (int)(c + 0.45) : 0), d, e, f)
58 #define SetDashes XSetDashes
59 #define SetFillStyle XSetFillStyle
60 #define SetStipple(a,b,c) XSetStipple(a,b,STIPPLE[c])
62 #endif /* !HAVE_CAIRO */
64 #define flusharea()
66 /*----------------------------------------------------------------------*/
67 /* Redefinition of fprintf() allows redirection of output to a console */
68 /* in the Tcl interpreter-based version. */
69 /*----------------------------------------------------------------------*/
71 #ifdef TCL_WRAPPER
72 #define Fprintf tcl_printf
73 #define Flush tcl_stdflush
74 #else
75 #define Fprintf fprintf
76 #define Flush fflush
77 #endif
79 #ifdef TCL_WRAPPER
80 #define malloc Tcl_Alloc
81 /* (see definition of my_calloc in the asg subdirectory) */
82 /* #define calloc(a,b) Tcl_Alloc(a * b) */
83 #define free(a) Tcl_Free((char *)(a))
84 #define realloc(a,b) Tcl_Realloc((char *)(a), b)
85 #undef strdup
86 #define strdup Tcl_Strdup
87 extern char *Tcl_Strdup(const char *);
88 #endif
90 /*----------------------------------------------------------------------*/
91 /* Deal with 32/64 bit processors based on autoconf results. */
92 /*----------------------------------------------------------------------*/
94 #ifndef SIZEOF_VOID_P
95 #error "SIZEOF_VOID_P undefined!"
96 #endif
97 #ifndef SIZEOF_UNSIGNED_INT
98 #error "SIZEOF_UNSIGNED_INT undefined!"
99 #endif
100 #ifndef SIZEOF_UNSIGNED_LONG
101 #error "SIZEOF_UNSIGNED_LONG undefined!"
102 #endif
103 #ifndef SIZEOF_UNSIGNED_LONG_LONG
104 #error "SIZEOF_UNSIGNED_LONG_LONG undefined!"
105 #endif
107 #if SIZEOF_VOID_P == SIZEOF_UNSIGNED_INT
108 #define Number(a) (void *)((u_int) a)
109 typedef u_int pointertype;
110 #elif SIZEOF_VOID_P == SIZEOF_UNSIGNED_LONG
111 #define Number(a) (void *)((u_long) a)
112 typedef u_long pointertype;
113 #elif SIZEOF_VOID_P == SIZEOF_UNSIGNED_LONG_LONG
114 #define Number(a) (void *)((u_long_long) a)
115 typedef u_long_long pointertype;
116 #else
117 ERROR: Cannot compile without knowing the size of a pointer. See xcircuit.h.
118 #endif
120 /*----------------------------------------------------------------------*/
121 /* Basic element types */
122 /* */
123 /* These values determine how a genericptr should be cast into one of */
124 /* labelptr, polyptr, etc. To query the element type, use the macros */
125 /* ELEMENTTYPE(), IS_LABEL(), IS_POLYGON(), etc. These macros mask the */
126 /* bit field. Note that an element marked with REMOVE_TAG will not be */
127 /* recognized as any valid element, but otherwise, querying the type is */
128 /* transparent to other bit settings (such as NETLIST_INVALID). */
129 /*----------------------------------------------------------------------*/
131 /* Single-bit flags */
132 #define OBJINST 0x01
133 #define LABEL 0x02
134 #define POLYGON 0x04
135 #define ARC 0x08
136 #define SPLINE 0x10
137 #define PATH 0x20
138 #define GRAPHIC 0x40
139 #define ARRAY 0x80 /* reserved; unused, for now. */
141 #define REMOVE_TAG 0x100 /* element to be removed from netlist */
142 #define NETLIST_INVALID 0x200 /* this element invalidates the netlist */
143 #define SELECT_HIDE 0x400 /* this element cannot be selected */
144 #define DRAW_HIDE 0x800 /* this element is not drawn. */
146 /* Bit fields */
147 #define ALL_TYPES (OBJINST | LABEL | POLYGON | ARC | SPLINE | PATH \
148 | GRAPHIC | ARRAY)
149 #define VALID_TYPES (REMOVE_TAG | ALL_TYPES)
151 /*----------------------------------------------------------------------*/
152 /* Definition shortcuts */
153 /*----------------------------------------------------------------------*/
155 #define XtnSetArg(a,b) XtSetArg(wargs[n], a, b); n++
156 #define abs(a) ((a) < 0 ? -(a) : (a))
157 #define sign(a) ((a) <= 0 ? -1 : 1)
158 #ifndef min
159 #define max(a,b) ((a) < (b) ? (b) : (a))
160 #define min(a,b) ((a) < (b) ? (a) : (b))
161 #endif
163 /*----------------------------------------------------------------------*/
164 /* Lengthier define constructs */
165 /*----------------------------------------------------------------------*/
167 /* Names used for convenience throughout the source code */
169 #define eventmode areawin->event_mode
170 #define topobject areawin->topinstance->thisobject
171 #define hierobject areawin->hierstack->thisinst->thisobject
173 #define PLIST_INCR(a) \
174 (a)->plist = (genericptr *) realloc ((a)->plist, \
175 ((a)->parts + 1) * sizeof(genericptr))
177 #define ENDPART topobject->plist + topobject->parts - 1
178 #define EDITPART topobject->plist + *areawin->selectlist
180 /* Type checks (argument "a" is type genericptr) */
182 #define ELEMENTTYPE(a) ((a)->type & VALID_TYPES)
184 #define IS_POLYGON(a) (ELEMENTTYPE(a) == POLYGON)
185 #define IS_LABEL(a) (ELEMENTTYPE(a) == LABEL)
186 #define IS_OBJINST(a) (ELEMENTTYPE(a) == OBJINST)
187 #define IS_ARC(a) (ELEMENTTYPE(a) == ARC)
188 #define IS_SPLINE(a) (ELEMENTTYPE(a) == SPLINE)
189 #define IS_PATH(a) (ELEMENTTYPE(a) == PATH)
190 #define IS_GRAPHIC(a) (ELEMENTTYPE(a) == GRAPHIC)
191 #define IS_ARRAY(a) (ELEMENTTYPE(a) == ARRAY)
193 /* Conversions from generic to specific types */
194 /* specifically, from type (genericptr *) to type (polyptr), etc. */
196 #define TOPOLY(a) (*((polyptr *)(a)))
197 #define TOLABEL(a) (*((labelptr *)(a)))
198 #define TOOBJINST(a) (*((objinstptr *)(a)))
199 #define TOARC(a) (*((arcptr *)(a)))
200 #define TOSPLINE(a) (*((splineptr *)(a)))
201 #define TOPATH(a) (*((pathptr *)(a)))
202 #define TOGRAPHIC(a) (*((graphicptr *)(a)))
203 #define TOGENERIC(a) (*((genericptr *)(a)))
205 /* conversions from a selection to a specific type */
207 #define SELTOGENERICPTR(a) ((areawin->hierstack == NULL) ? \
208 (topobject->plist + *(a)) : \
209 (hierobject->plist + *(a)))
211 #define SELTOPOLY(a) TOPOLY(SELTOGENERICPTR(a))
212 #define SELTOLABEL(a) TOLABEL(SELTOGENERICPTR(a))
213 #define SELTOOBJINST(a) TOOBJINST(SELTOGENERICPTR(a))
214 #define SELTOARC(a) TOARC(SELTOGENERICPTR(a))
215 #define SELTOSPLINE(a) TOSPLINE(SELTOGENERICPTR(a))
216 #define SELTOPATH(a) TOPATH(SELTOGENERICPTR(a))
217 #define SELTOGRAPHIC(a) TOGRAPHIC(SELTOGENERICPTR(a))
218 #define SELTOGENERIC(a) TOGENERIC(SELTOGENERICPTR(a))
220 #define SELECTTYPE(a) ((SELTOGENERIC(a))->type & ALL_TYPES)
221 #define SELTOCOLOR(a) ((SELTOGENERIC(a))->color)
224 /* creation of new elements */
226 #define NEW_POLY(a,b) \
227 PLIST_INCR(b); \
228 a = (polyptr *)b->plist + b->parts; \
229 *a = (polyptr) malloc(sizeof(polygon)); \
230 b->parts++; \
231 (*a)->type = POLYGON
232 #define NEW_LABEL(a,b) \
233 PLIST_INCR(b); \
234 a = (labelptr *)b->plist + b->parts; \
235 *a = (labelptr) malloc(sizeof(label)); \
236 b->parts++; \
237 (*a)->type = LABEL
238 #define NEW_OBJINST(a,b) \
239 PLIST_INCR(b); \
240 a = (objinstptr *)b->plist + b->parts; \
241 *a = (objinstptr) malloc(sizeof(objinst)); \
242 b->parts++; \
243 (*a)->type = OBJINST
244 #define NEW_ARC(a,b) \
245 PLIST_INCR(b); \
246 a = (arcptr *)b->plist + b->parts; \
247 *a = (arcptr) malloc(sizeof(arc)); \
248 b->parts++; \
249 (*a)->type = ARC
250 #define NEW_SPLINE(a,b) \
251 PLIST_INCR(b); \
252 a = (splineptr *)b->plist + b->parts; \
253 *a = (splineptr) malloc(sizeof(spline)); \
254 b->parts++; \
255 (*a)->type = SPLINE
256 #define NEW_PATH(a,b) \
257 PLIST_INCR(b); \
258 a = (pathptr *)b->plist + b->parts; \
259 *a = (pathptr) malloc(sizeof(path)); \
260 b->parts++; \
261 (*a)->type = PATH
262 #define NEW_GRAPHIC(a,b) \
263 PLIST_INCR(b); \
264 a = (graphicptr *)b->plist + b->parts; \
265 *a = (graphicptr) malloc(sizeof(graphic)); \
266 b->parts++; \
267 (*a)->type = GRAPHIC
269 /*----------------------------------------------------------------------*/
271 typedef struct {
272 float x, y;
273 } XfPoint;
275 typedef struct {
276 long x, y;
277 } XlPoint;
279 typedef struct {
280 short width, ascent, descent, base;
281 int maxwidth;
282 } TextExtents;
284 typedef struct {
285 float *padding; /* Allocated array of padding info per line */
286 XPoint *tbreak; /* Position in text to stop */
287 short dostop; /* Location (index) in text to stop */
288 short line; /* Stop line number, if using dostop or tbreak. */
289 } TextLinesInfo;
291 /*----------------------------------------------------------------------*/
292 /* Implementation-specific definitions */
293 /*----------------------------------------------------------------------*/
295 #define LIBS 5 /* initial number of library pages */
296 #define PAGES 10 /* default number of top-level pages */
297 #define SCALEFAC 1.5 /* zoom in/out scaling multiplier */
298 #define SUBSCALE 0.67 /* ratio of subscript size to normal script size */
299 #define SBARSIZE 13 /* Pixel size of the scrollbar */
300 #define RSTEPS 72 /* Number of points defining a circle approx. */
301 #define SPLINESEGS 20 /* Number of points per spline approximation */
302 #define DELBUFSIZE 10 /* Number of delete events to save for undeleting */
303 #define MINAUTOSCALE 0.75 /* Won't automatically scale closer than this */
304 #define MAXCHANGES 20 /* Number of changes to induce a temp file save */
305 #define STIPPLES 8 /* Number of predefined stipple patterns */
306 #define PADSPACE 10 /* Spacing of pinlabels from their origins */
308 #ifdef HAVE_XPM
309 #define TBBORDER 1 /* border around toolbar buttons */
310 #endif
312 #define TOPLEVEL 0
313 #define SINGLE 1
315 #define INTSEGS (SPLINESEGS - 2)
316 #define LASTSEG (SPLINESEGS - 3)
318 #define NOFILENAME (char *)(-1)
320 #define FONTHEIGHT(y) (y->ascent + y->descent + 6)
321 #define ROWHEIGHT FONTHEIGHT(appdata.xcfont)
322 #define FILECHARASCENT (appdata.filefont->ascent)
323 #define FILECHARHEIGHT (FILECHARASCENT + appdata.filefont->descent)
324 #define LISTHEIGHT 200
325 #define TEXTHEIGHT 28 /* Height of xcircuit vectored font at nominal size */
326 #define BASELINE 40 /* Height of baseline */
327 #define DEFAULTGRIDSPACE 32
328 #define DEFAULTSNAPSPACE 16
330 /*----------------------------------------------------------------------*/
332 #define RADFAC 0.0174532925199 /* (pi / 180) */
333 #define INVRFAC 57.295779 /* (180 / pi) */
335 /*----------------------------------------------------------------------*/
337 #define INCHSCALE 0.375 /* Scale of .25 inches to PostScript units */
338 #define CMSCALE 0.35433071 /* Scale of .5 cm to PostScript units */
339 #define IN_CM_CONVERT 28.3464567 /* 72 (in) / 2.54 (cm/in) */
341 /*----------------------------------------------------------------------*/
342 /* Event mode definitions (state of drawing area) */
343 /*----------------------------------------------------------------------*/
345 typedef enum editmode {
346 NORMAL_MODE = 0, /* On the drawing page, none of the situations below */
347 UNDO_MODE, /* In the process of an undo/redo operation */
348 MOVE_MODE, /* In the process of moving elements */
349 COPY_MODE, /* In the process of copying elements */
350 PAN_MODE, /* In the process of panning to follow the cursor */
351 SELAREA_MODE, /* Area selection box */
352 RESCALE_MODE, /* Interactive element rescaling box */
353 CATALOG_MODE, /* On a library page, library directory, or page directory */
354 CATTEXT_MODE, /* Editing an existing object name in the library */
355 FONTCAT_MODE, /* Accessing the font character page from TEXT_MODE */
356 EFONTCAT_MODE, /* Accessing the font character page from ETEXT_MODE */
357 TEXT_MODE, /* Creating a new label */
358 WIRE_MODE, /* Creating a new polygon (wire) */
359 BOX_MODE, /* Creating a new box */
360 ARC_MODE, /* Creating a new arc */
361 SPLINE_MODE, /* Creating a new spline */
362 ETEXT_MODE, /* Editing an exiting label */
363 EPOLY_MODE, /* Editing an existing polygon */
364 EARC_MODE, /* Editing an existing arc */
365 ESPLINE_MODE, /* Editing an existing spline */
366 EPATH_MODE, /* Editing an existing path */
367 EINST_MODE, /* Editing an instance (from the level above) */
368 ASSOC_MODE, /* Choosing an associated schematic or symbol */
369 CATMOVE_MODE /* Moving objects in or between libraries */
370 } event_mode_t;
372 /*----------------------------------------------------------------------*/
373 /* File loading modes */
374 /*----------------------------------------------------------------------*/
376 enum loadmodes {IMPORT = 1, PSBKGROUND, SCRIPT, RECOVER,
377 #ifdef ASG
378 IMPORTSPICE,
379 #endif
380 #ifdef HAVE_CAIRO
381 IMPORTGRAPHIC,
382 #endif
383 LOAD_MODES
386 /*----------------------------------------------------------------------*/
387 /* Text anchoring styles and other parameters (bitmask) */
388 /*----------------------------------------------------------------------*/
390 #define NOTLEFT 1 /* Center or right anchoring */
391 #define RIGHT 2 /* Right anchoring */
392 #define NOTBOTTOM 4 /* Middle or top anchoring */
393 #define TOP 8 /* Top anchoring */
394 #define FLIPINV 16 /* 1 if text is flip-invariant */
395 #define PINVISIBLE 32 /* 1 if pin visible outside of object */
396 #define PINNOOFFSET 64 /* 0 if pin label offset from position */
397 #define LATEXLABEL 128 /* 1 if label is in LaTeX syntax */
398 #define JUSTIFYRIGHT 256 /* Right text justification */
399 #define JUSTIFYBOTH 512 /* Right and left text justification */
400 #define TEXTCENTERED 1024 /* Centered text */
402 #define RLANCHORFIELD 3 /* right-left anchoring bit field */
403 #define TBANCHORFIELD 12 /* top-bottom anchoring bit field */
404 #define NONANCHORFIELD 2032 /* everything but anchoring fields */
405 #define NONJUSTIFFIELD 255 /* everything but justification fields */
407 /*----------------------------------------------------------------------*/
408 /* Text string part: types */
409 /*----------------------------------------------------------------------*/
411 #define TEXT_STRING 0 /* data is a text string */
412 #define SUBSCRIPT 1 /* start subscript; no data */
413 #define SUPERSCRIPT 2 /* start superscript; no data */
414 #define NORMALSCRIPT 3 /* stop super-/subscript; no data */
415 #define UNDERLINE 4 /* start underline; no data */
416 #define OVERLINE 5 /* start overline; no data */
417 #define NOLINE 6 /* stop over-/underline; no data */
418 #define TABSTOP 7 /* insert tab stop position */
419 #define TABFORWARD 8 /* insert tab stop position */
420 #define TABBACKWARD 9 /* insert tab stop position */
421 #define HALFSPACE 10 /* insert half-space; no data */
422 #define QTRSPACE 11 /* insert quarter space; no data */
423 #define RETURN 12 /* carriage-return character; no data */
424 #define FONT_NAME 13 /* inline font designator; data = font name */
425 #define FONT_SCALE 14 /* font scale change; data = scale */
426 #define FONT_COLOR 15 /* font color change; data = color */
427 #define MARGINSTOP 16 /* declare a width limit for the text */
428 #define KERN 17 /* set new kern values; data = kern x, y */
429 #define PARAM_START 18 /* bounds a parameter; data = param key */
430 #define PARAM_END 19 /* bounds a parameter; no data */
432 /* Actions translated to keystates (numbering continues from above) */
434 #define TEXT_RETURN 20
435 #define TEXT_HOME 21
436 #define TEXT_END 22
437 #define TEXT_SPLIT 23
438 #define TEXT_DOWN 24
439 #define TEXT_UP 25
440 #define TEXT_LEFT 26
441 #define TEXT_RIGHT 27
442 #define TEXT_DELETE 28
443 #define TEXT_DEL_PARAM 29
445 #define SPECIAL 63 /* used only when called from menu */
446 #define NULL_TYPE 255 /* used as a placeholder */
448 /*----------------------------------------------------------------------*/
449 /* Reset modes */
450 /*----------------------------------------------------------------------*/
452 #define SAVE 1
453 #define DESTROY 2
455 /*----------------------------------------------------------------------*/
456 /* Coordinate display types */
457 /*----------------------------------------------------------------------*/
459 #define DEC_INCH 0
460 #define FRAC_INCH 1
461 #define CM 2
462 #define INTERNAL 3
464 /*----------------------------------------------------------------------*/
465 /* Library types */
466 /*----------------------------------------------------------------------*/
468 #define FONTENCODING -1 /* Used only by libopen() */
469 #define FONTLIB 0
470 #define PAGELIB 1
471 #define LIBLIB 2
472 #define LIBRARY 3
473 #define USERLIB (xobjs.numlibs + LIBRARY - 1)
475 /*----------------------------------------------------------------------*/
476 /* Object instance styles */
477 /*----------------------------------------------------------------------*/
479 #define LINE_INVARIANT 1 /* Linewidth is invariant w.r.t. scale */
480 #define INST_NONETLIST 2 /* Instance is not netlistable */
482 /*----------------------------------------------------------------------*/
483 /* Box styles */
484 /*----------------------------------------------------------------------*/
486 #define NORMAL 0
487 #define UNCLOSED 1
488 #define DASHED 2
489 #define DOTTED 4
490 #define NOBORDER 8
491 #define FILLED 16
492 #define STIP0 32
493 #define STIP1 64
494 #define STIP2 128
495 #define FILLSOLID 224 /* = 32 + 64 + 128 */
496 #ifdef OPAQUE
497 #undef OPAQUE
498 #endif
499 #define OPAQUE 256
500 #define BBOX 512
501 #define SQUARECAP 1024
502 #define CLIPMASK 2048
503 #define FIXEDBBOX 4096
505 /*----------------------------------------------------------------------*/
506 /* Box edit styles */
507 /*----------------------------------------------------------------------*/
509 #define NONE 0
510 #define MANHATTAN 1
511 #define RHOMBOIDX 2
512 #define RHOMBOIDY 4
513 #define RHOMBOIDA 8
515 /*----------------------------------------------------------------------*/
516 /* Path edit styles */
517 /*----------------------------------------------------------------------*/
519 #define TANGENTS 1 /* (NORMAL = 0) */
521 /*----------------------------------------------------------------------*/
522 /* Cycle points (selected points) (flag bits, can be OR'd together) */
523 /*----------------------------------------------------------------------*/
525 #define EDITX 0x01
526 #define EDITY 0x02
527 #define LASTENTRY 0x04
528 #define PROCESS 0x08
529 #define REFERENCE 0x10
530 #define ANTIXY 0x20 /* For matched-tangent curves */
532 /*----------------------------------------------------------------------*/
533 /* Arc creation and edit styles */
534 /*----------------------------------------------------------------------*/
536 #define CENTER 1
537 #define RADIAL 2
539 /*----------------------------------------------------------------------*/
540 /* Delete/undelete draw-mode styles */
541 /*----------------------------------------------------------------------*/
543 #define ERASE 1
544 #define DRAW 1
546 /*----------------------------------------------------------------------*/
547 /* Schematic object types and pin label types */
548 /*----------------------------------------------------------------------*/
550 #define PRIMARY 0 /* Primary (master) schematic page */
551 #define SECONDARY 1 /* Secondary (slave) schematic page */
552 #define TRIVIAL 2 /* Symbol as non-schematic element */
553 #define SYMBOL 3 /* Symbol associated with a schematic */
554 #define FUNDAMENTAL 4 /* Standalone symbol */
555 #define NONETWORK 5 /* Do not netlist this object */
556 #define GLYPH 6 /* Symbol is a font glyph */
558 #define LOCAL 1
559 #define GLOBAL 2
560 #define INFO 3
562 #define HIERARCHY_LIMIT 256 /* Stop if recursion goes this deep */
564 /*----------------------------------------------------------------------*/
565 /* Save types. This list incorporates "ALL_PAGES", below. */
566 /*----------------------------------------------------------------------*/
568 #define CURRENT_PAGE 0 /* Current page + all associated pages */
569 #define NO_SUBCIRCUITS 1 /* Current page w/o subcircuit pages */
571 /*----------------------------------------------------------------------*/
572 /* Modes used when ennumerating page totals. */
573 /*----------------------------------------------------------------------*/
575 #define INDEPENDENT 0
576 #define DEPENDENT 1
577 #define TOTAL_PAGES 2
578 #define LINKED_PAGES 3
579 #define PAGE_DEPEND 4
580 #define ALL_PAGES 5
582 /*----------------------------------------------------------------------*/
583 /* Color scheme styles (other than NORMAL) */
584 /*----------------------------------------------------------------------*/
586 #define INVERSE 1
588 /*----------------------------------------------------------------------*/
589 /* Cursor definitions */
590 /*----------------------------------------------------------------------*/
592 #define NUM_CURSORS 11
594 #define ARROW appcursors[0]
595 #define CROSS appcursors[1]
596 #define SCISSORS appcursors[2]
597 #define COPYCURSOR appcursors[3]
598 #define ROTATECURSOR appcursors[4]
599 #define EDCURSOR appcursors[5]
600 #define TEXTPTR appcursors[6]
601 #define CIRCLE appcursors[7]
602 #define QUESTION appcursors[8]
603 #define WAITFOR appcursors[9]
604 #define HAND appcursors[10]
606 #define DEFAULTCURSOR (*areawin->defaultcursor)
608 /*----------------------------------------------------------------------*/
609 /* integer and floating-point coordinate list structures */
610 /*----------------------------------------------------------------------*/
612 typedef XPoint* pointlist;
613 typedef XfPoint* fpointlist;
615 /*----------------------------------------------------------------------*/
616 /* Allowed parameterization types */
617 /*----------------------------------------------------------------------*/
619 enum paramwhich {
620 P_NUMERIC = 0, /* uncommitted numeric parameter */
621 P_SUBSTRING,
622 P_POSITION_X,
623 P_POSITION_Y,
624 P_STYLE,
625 P_ANCHOR,
626 P_ANGLE1,
627 P_ANGLE2,
628 P_RADIUS,
629 P_MINOR_AXIS,
630 P_ROTATION,
631 P_SCALE,
632 P_LINEWIDTH,
633 P_COLOR,
634 P_EXPRESSION,
635 P_POSITION, /* mode only, not a real parameter */
636 NUM_PARAM_TYPES
639 /*----------------------------------------------------------------------*/
640 /* Labels are constructed of strings and executables */
641 /*----------------------------------------------------------------------*/
643 typedef struct _stringpart *stringptr;
645 typedef struct _stringpart {
646 stringptr nextpart;
647 u_char type;
648 union {
649 u_char *string;
650 int color;
651 int font;
652 int width;
653 int flags;
654 float scale;
655 short kern[2];
656 } data;
657 } stringpart;
659 /*----------------------------------------------------------------------*/
660 /* structures of all main elements which can be displayed & manipulated */
661 /*----------------------------------------------------------------------*/
663 /*----------------------------------------------------------------------*/
664 /* Object & object instance parameter structure */
665 /* (Add types as necessary) */
666 /*----------------------------------------------------------------------*/
668 enum paramtypes {XC_INT = 0, XC_FLOAT, XC_STRING, XC_EXPR};
670 /* Object parameters: general key:value parameter model */
671 /* Note that this really should be a hash table, not a linked list. . . */
673 typedef struct _oparam *oparamptr;
675 typedef struct _oparam {
676 char * key; /* name of the parameter */
677 u_char type; /* type is from paramtypes list above */
678 u_char which; /* what the parameter represents (P_*) */
679 union {
680 stringpart *string; /* xcircuit label type */
681 char *expr; /* TCL (string) expression */
682 int ivalue; /* also covers type short int by typecasting */
683 float fvalue;
684 } parameter; /* default or substitution value */
685 oparamptr next; /* next parameter in linked list */
686 } oparam;
688 /* Element parameters: reference back to the object's parameters */
689 /* These parameters are forward-substituted when descending into */
690 /* an object instance. */
691 /* Note that this really should be a hash table, not a linked list. . . */
693 typedef struct _eparam *eparamptr;
695 typedef struct _eparam {
696 char * key; /* name of the parameter */
697 u_char flags; /* namely, bit declaring an indirect parameter */
698 union {
699 int pointno; /* point number in point array, for polygons */
700 short pathpt[2]; /* element number and point number, for paths */
701 char *refkey; /* parameter reference key, for instances */
702 } pdata;
703 eparamptr next; /* next parameter in linked list */
704 } eparam;
706 #define P_INDIRECT 0x01 /* indirect parameter indicator */
708 /*----------------------------------------------------------------------*/
709 /* Generic element type is a superset of all elements. */
710 /*----------------------------------------------------------------------*/
712 typedef struct {
713 u_short type; /* type is LABEL, POLYGON, etc., from below */
714 int color;
715 eparamptr passed;
716 } generic, *genericptr; /* (convenience function for retypecasting) */
718 /*----------------------------------------------------------------------*/
719 /* selection-mechanism structures */
720 /*----------------------------------------------------------------------*/
722 typedef struct {
723 short number;
724 genericptr *element;
725 short *idx;
726 } uselection;
728 typedef struct {
729 short number;
730 u_char flags;
731 } pointselect;
733 /*----------------------------------------------------------------------*/
734 /* Bounding box */
735 /*----------------------------------------------------------------------*/
737 typedef struct {
738 XPoint lowerleft;
739 Dimension width, height;
740 } BBox;
742 /*----------------------------------------------------------------------*/
743 /* Object instance type */
744 /*----------------------------------------------------------------------*/
746 typedef struct _xcobject *objectptr;
748 typedef struct {
749 u_short type;
750 int color;
751 eparamptr passed; /* numerical parameters passed from above */
752 u_short style;
753 XPoint position;
754 float rotation;
755 float scale;
756 objectptr thisobject;
757 oparamptr params; /* parameter substitutions for this instance */
758 BBox bbox; /* per-instance bounding box information */
759 BBox *schembbox; /* Extra bounding box for pin labels */
760 } objinst, *objinstptr;
762 /* Linked-list for objects */
764 typedef struct _objlist *objlistptr;
766 typedef struct _objlist {
767 int libno; /* library in which object appears */
768 objectptr thisobject; /* pointer to the object */
769 objlistptr next;
770 } objlist;
772 /* Linked-list for object instances */
774 typedef struct _pushlist *pushlistptr;
776 typedef struct _pushlist {
777 objinstptr thisinst;
778 char *clientdata; /* general-purpose record */
779 pushlistptr next;
780 } pushlist;
782 /* Same as above, but for the list of instances in a library, so it */
783 /* needs an additional record showing whether or not the instance is */
784 /* "virtual" (not the primary library instance of the object) */
786 typedef struct _liblist *liblistptr;
788 typedef struct _liblist {
789 objinstptr thisinst;
790 u_char virtual;
791 liblistptr next;
792 } liblist;
794 /*----------------------------------------------------------------------*/
795 /* Generalized graphic object (Tcl/Tk only) */
796 /*----------------------------------------------------------------------*/
798 typedef struct {
799 u_short type;
800 int color; /* foreground, for bitmaps only */
801 eparamptr passed; /* numerical parameters passed from above */
802 XPoint position;
803 float rotation;
804 float scale;
805 xcImage *source; /* source data */
806 #ifndef HAVE_CAIRO
807 xcImage *target; /* target (scaled) data */
808 float trot; /* target rotation */
809 float tscale; /* target scale (0 = uninitialized) */
810 Pixmap clipmask; /* clipmask for non-manhattan rotations */
811 Boolean valid; /* does target need to be regenerated? */
812 #endif /* !HAVE_CAIRO */
813 } graphic, *graphicptr;
815 /*----------------------------------------------------------------------*/
816 /* Label */
817 /*----------------------------------------------------------------------*/
819 typedef struct {
820 u_short type;
821 int color;
822 eparamptr passed; /* numerical parameters passed from above */
823 pointselect *cycle; /* Edit position(s), or NULL */
824 XPoint position;
825 float rotation;
826 float scale;
827 u_short anchor;
828 u_char pin;
829 stringpart *string;
830 } label, *labelptr;
832 /*----------------------------------------------------------------------*/
833 /* Polygon */
834 /*----------------------------------------------------------------------*/
836 typedef struct {
837 u_short type;
838 int color;
839 eparamptr passed; /* numerical parameters passed from above */
840 u_short style;
841 float width;
842 pointselect *cycle; /* Edit position(s), or NULL */
843 short number;
844 pointlist points;
845 } polygon, *polyptr;
847 /*----------------------------------------------------------------------*/
848 /* Bezier Curve */
849 /*----------------------------------------------------------------------*/
851 typedef struct {
852 u_short type;
853 int color;
854 eparamptr passed; /* numerical parameters passed from above */
855 u_short style;
856 float width;
857 pointselect *cycle; /* Edit position(s), or NULL */
858 XPoint ctrl[4];
859 /* the following are for rendering only */
860 XfPoint points[INTSEGS];
861 } spline, *splineptr;
863 /*----------------------------------------------------------------------*/
864 /* Arc */
865 /*----------------------------------------------------------------------*/
867 typedef struct {
868 u_short type;
869 int color;
870 eparamptr passed; /* numerical parameters passed from above */
871 u_short style;
872 float width;
873 pointselect *cycle; /* Edit position(s), or NULL */
874 short radius; /* x-axis radius */
875 short yaxis; /* y-axis radius */
876 float angle1; /* endpoint angles, in degrees */
877 float angle2;
878 XPoint position;
879 /* the following are for rendering only */
880 short number;
881 XfPoint points[RSTEPS + 1];
882 } arc, *arcptr;
884 /*----------------------------------------------------------------------*/
885 /* Path */
886 /*----------------------------------------------------------------------*/
888 typedef struct {
889 u_short type;
890 int color;
891 eparamptr passed; /* numerical parameters passed from above */
892 u_short style;
893 float width;
894 short parts;
895 genericptr *plist; /* to be retypecast to polygon, arc, or spline */
896 } path, *pathptr;
898 /*----------------------------------------------------------------------*/
899 /* selection from top-level object */
900 /*----------------------------------------------------------------------*/
902 /*----------------------------------------------------------------------*/
903 /* Undo mechanism definitions */
904 /*----------------------------------------------------------------------*/
906 enum UNDO_MODES {UNDO_DONE = 0, UNDO_MORE, MODE_CONNECT, MODE_RECURSE_WIDE,
907 MODE_RECURSE_NARROW};
909 typedef struct _selection *selectionptr;
911 typedef struct _selection {
912 int selects;
913 short *selectlist;
914 objinstptr thisinst;
915 selectionptr next;
916 } selection;
918 #define select_element(a) recurse_select_element(a, UNDO_MORE)
919 #define select_add_element(a) recurse_select_element(a, UNDO_DONE)
921 #define easydraw(a, b) geneasydraw(a, b, topobject, areawin->topinstance)
923 /*----------------------------------------------------------------------*/
924 /* Netlist structures for schematic capture */
925 /*----------------------------------------------------------------------*/
927 /* Structure to hold net and subnet IDs for a bus */
929 typedef struct {
930 int netid;
931 int subnetid;
932 } buslist;
934 /* Structure mimicking the top part of a Polylist or Labellist */
935 /* when we just want the netlist information and don't care */
936 /* which one we're looking at. */
938 typedef struct {
939 union {
940 int id;
941 buslist *list;
942 } net;
943 int subnets;
944 } Genericlist;
946 /* Linked polygon list */
948 typedef struct _Polylist *PolylistPtr;
949 typedef struct _Polylist
951 union {
952 int id; /* A single net ID, if subnets == 0 */
953 buslist *list; /* List of net and subnet IDs for a bus */
954 } net;
955 int subnets; /* Number of subnets; 0 if no subnets */
956 objectptr cschem; /* Schematic containing the polygon */
957 polyptr poly;
958 PolylistPtr next; /* Next polygon in the linked list */
959 } Polylist;
961 /* Linked label list */
963 typedef struct _Labellist *LabellistPtr;
964 typedef struct _Labellist
966 union {
967 int id; /* A single net ID, if subnets == 0 */
968 buslist *list; /* List of net and subnet IDs for a bus */
969 } net;
970 int subnets; /* Number of subnets; 0 if no subnets */
971 objectptr cschem; /* Schematic containing the label */
972 objinstptr cinst; /* Specific label instance, if applicable */
973 labelptr label;
974 LabellistPtr next;
975 } Labellist;
977 /* List of object's networks by (flattened) name */
979 typedef struct _Netname *NetnamePtr;
980 typedef struct _Netname
982 int netid;
983 stringpart *localpin;
984 NetnamePtr next;
985 } Netname;
987 /* List of object's I/O ports */
989 typedef struct _Portlist *PortlistPtr;
990 typedef struct _Portlist
992 int portid;
993 int netid;
994 PortlistPtr next;
995 } Portlist;
997 /* List of calls to instances of objects */
998 /* or subcircuit objects. */
1000 typedef struct _Calllist *CalllistPtr;
1001 typedef struct _Calllist
1003 objectptr cschem; /* Schematic containing the instance called */
1004 objinstptr callinst; /* Instance called */
1005 objectptr callobj; /* Object of instance called */
1006 char *devname; /* if non-null, name of device in netlist */
1007 int devindex; /* if non-negative, index of device in netlist */
1008 PortlistPtr ports;
1009 CalllistPtr next;
1010 } Calllist;
1012 /* PCB netlist structures */
1014 struct Pnet {
1015 int numnets;
1016 int *netidx;
1017 struct Pnet *next;
1020 struct Pstr {
1021 stringpart *string;
1022 struct Pstr *next;
1025 struct Ptab {
1026 objectptr cschem;
1027 struct Pnet *nets;
1028 struct Pstr *pins;
1029 struct Ptab *next;
1032 /*----------------------------------------------------------------------*/
1033 /* Information needed to highlight a net */
1034 /*----------------------------------------------------------------------*/
1036 typedef struct {
1037 Genericlist *netlist;
1038 objinstptr thisinst;
1039 } Highlight;
1041 /*----------------------------------------------------------------------*/
1042 /* Main object structure */
1043 /*----------------------------------------------------------------------*/
1045 typedef struct _xcobject {
1046 char name[80];
1047 u_short changes; /* Number of unsaved changes to object */
1048 Boolean hidden;
1049 float viewscale;
1050 XPoint pcorner; /* position relative to window */
1051 BBox bbox; /* bounding box information (excluding */
1052 /* parameterized elements) */
1053 short parts;
1054 genericptr *plist; /* to be retypecast to label, polygon, etc. */
1055 oparamptr params; /* list of parameters, with default values */
1057 Highlight highlight; /* net to be highlighted on redraw */
1058 u_char schemtype;
1059 objectptr symschem; /* schematic page support */
1060 Boolean valid; /* Is current netlist valid? */
1061 Boolean traversed; /* Flag to indicate object was processed */
1062 LabellistPtr labels; /* Netlist pins */
1063 PolylistPtr polygons; /* Netlist wires */
1064 PortlistPtr ports; /* Netlist ports */
1065 CalllistPtr calls; /* Netlist subcircuits and connections */
1066 Boolean infolabels; /* TRUE if object contains info-labels */
1067 NetnamePtr netnames; /* Local names for flattening */
1068 /* (this probably shouldn't be here. . .) */
1069 } object;
1071 /*----------------------------------------------------------------------*/
1072 /* Transformation matrices */
1073 /* Works like this (see also PostScript reference manual): */
1074 /* [x' y' 1] = [x y 1] * | a d 0 | */
1075 /* | b e 0 | */
1076 /* | c f 1 | */
1077 /*----------------------------------------------------------------------*/
1079 typedef struct _matrix *Matrixptr;
1081 typedef struct _matrix {
1082 float a, b, c, d, e, f;
1083 Matrixptr nextmatrix;
1084 } Matrix;
1086 /*----------------------------------------------------------------------*/
1087 /* Some convenience functions for matrix manipulation */
1088 /*----------------------------------------------------------------------*/
1090 #define DCTM areawin->MatStack
1092 /*----------------------------------------------------------------------*/
1093 /* button tap/press definitions */
1094 /*----------------------------------------------------------------------*/
1096 #define PRESSTIME 200 /* milliseconds of push to be a "press" */
1098 /*----------------------------------------------------------------------*/
1099 /* object name alias structures */
1100 /*----------------------------------------------------------------------*/
1102 typedef struct _stringlist *slistptr;
1104 typedef struct _stringlist {
1105 char *alias;
1106 slistptr next;
1107 } stringlist;
1109 typedef struct _alias *aliasptr;
1111 typedef struct _alias {
1112 objectptr baseobj; /* pointer to object (actual name) */
1113 slistptr aliases; /* linked list of alias names */
1114 aliasptr next;
1115 } alias;
1117 /*----------------------------------------------------------------------*/
1118 /* To facilitate compiling the Tcl/Tk version, we make some convenient */
1119 /* definitions for types "xc..." and "Xc..." which can be mapped both */
1120 /* to X and Xt or to Tk functions and types. */
1121 /*----------------------------------------------------------------------*/
1123 #ifdef TCL_WRAPPER
1125 #define xcWidget Tk_Window
1126 #define xcWidgetList Tk_Window *
1127 #define xcAddEventHandler(a,b,c,d,e) Tk_CreateEventHandler(a,b,d,e)
1128 #define xcRemoveEventHandler(a,b,c,d,e) Tk_DeleteEventHandler(a,b,d,e)
1129 #define xcEventHandler Tk_EventProc *
1130 #define xcWindow Tk_WindowId
1131 #define xcIsRealized Tk_IsMapped /* not sure this is right */
1132 #define xcScreen Tk_Screen
1133 #define xcParent Tk_Parent
1134 #define xcDispatchEvent(a) Tk_HandleEvent(a)
1135 #define xcAddTimeOut(a, b, c, d) Tcl_CreateTimerHandler((int)(b), c, d)
1136 #define xcRemoveTimeOut Tcl_DeleteTimerHandler
1137 #define xcTimeOutProc Tcl_TimerProc *
1138 #define xcIntervalId Tcl_TimerToken
1140 #else
1142 #define xcWidget Widget
1143 #define xcWidgetList WidgetList
1144 #define xcAddEventHandler XtAddEventHandler
1145 #define xcRemoveEventHandler XtRemoveEventHandler
1146 #define xcEventHandler XtEventHandler
1147 #define xcWindow XtWindow
1148 #define xcIsRealized XtIsRealized
1149 #define xcScreen XtScreen
1150 #define xcParent XtParent
1151 #define xcDispatchEvent(a) XtDispatchEvent(a)
1152 #define xcAddTimeOut XtAppAddTimeOut
1153 #define xcRemoveTimeOut XtRemoveTimeOut
1154 #define xcTimeOutProc XtTimerCallbackProc
1155 #define xcIntervalId XtIntervalId
1156 #ifndef ClientData
1157 #define ClientData XtPointer
1158 #endif
1159 #endif
1161 /*----------------------------------------------------------------------*/
1162 /* structures for managing the popup prompt widgets */
1163 /*----------------------------------------------------------------------*/
1165 typedef struct {
1166 xcWidget button;
1167 int foreground;
1168 void (*buttoncall)();
1169 void *dataptr;
1170 } buttonsave;
1172 typedef struct {
1173 xcWidget popup; /* Popup widget */
1174 xcWidget textw; /* Text entry widget */
1175 xcWidget filew; /* File list window */
1176 xcWidget scroll; /* Scrollbar widget */
1177 void (*setvalue)(); /* Callback function */
1178 buttonsave *buttonptr; /* Button widget calling popup */
1179 char *filter; /* Extension filter for highlighting */
1180 /* files. NULL for no file window. */
1181 /* NULL-string for no highlights. */
1182 } popupstruct;
1184 typedef struct {
1185 xcWidget textw;
1186 xcWidget buttonw;
1187 void (*setvalue)();
1188 void *dataptr;
1189 } propstruct;
1191 typedef struct {
1192 char *filename;
1193 int filetype;
1194 } fileliststruct;
1196 enum {DIRECTORY = 0, MATCH, NONMATCH}; /* file types */
1198 /*----------------------------------------------------------------------*/
1199 /* Initial Resource Management */
1200 /*----------------------------------------------------------------------*/
1202 typedef struct {
1203 /* schematic layout colors */
1204 Pixel globalcolor, localcolor, infocolor, ratsnestcolor;
1206 /* non-schematic layout color(s) */
1207 Pixel fixedbboxpix, bboxpix, clipcolor;
1209 /* color scheme 1 */
1210 Pixel fg, bg;
1211 Pixel gridpix, snappix, selectpix, axespix;
1212 Pixel buttonpix, filterpix, auxpix, barpix, parampix;
1214 /* color scheme 2 */
1215 Pixel fg2, bg2;
1216 Pixel gridpix2, snappix2, selectpix2, axespix2;
1217 Pixel buttonpix2, auxpix2, parampix2;
1219 int width, height, timeout;
1220 XFontStruct *filefont;
1222 #ifndef TCL_WRAPPER
1223 XFontStruct *xcfont, *textfont, *titlefont, *helpfont;
1224 #endif
1226 } ApplicationData, *ApplicationDataPtr;
1228 /*----------------------------------------------------------------------*/
1229 /* Macros for GC color and function handling */
1230 /*----------------------------------------------------------------------*/
1232 #define XTopSetForeground(a) if (a == DEFAULTCOLOR) SetForeground(dpy, \
1233 areawin->gc, FOREGROUND); else SetForeground(dpy, areawin->gc, a)
1235 #define XcTopSetForeground(z) XTopSetForeground(z); areawin->gccolor = \
1236 ((z) == DEFAULTCOLOR) ? FOREGROUND : (z)
1238 #define XcSetForeground(z) SetForeground(dpy, areawin->gc, z); \
1239 areawin->gccolor = z
1241 /*----------------------------------------------------------------------*/
1242 /* Structure for maintaining list of colors */
1243 /*----------------------------------------------------------------------*/
1245 typedef struct {
1246 xcWidget cbutton;
1247 XColor color;
1248 } colorindex;
1250 /*----------------------------------------------------------------------*/
1251 /* Font information structure */
1252 /*----------------------------------------------------------------------*/
1253 /* Flags: bit description */
1254 /* 0 bold = 1, normal = 0 */
1255 /* 1 italic = 1, normal = 0 */
1256 /* 2 <reserved, possibly for narrow font type> */
1257 /* 3 drawn = 1, PostScript = 0 */
1258 /* 4 <reserved, possibly for LaTeX font type> */
1259 /* 5 special encoding = 1, Standard Encoding = 0 */
1260 /* 6 ISOLatin1 = 2, ISOLatin2 = 3 */
1261 /* 7+ <reserved for other encoding schemes> */
1262 /*----------------------------------------------------------------------*/
1264 typedef struct {
1265 char *psname;
1266 char *family;
1267 float scale;
1268 u_short flags;
1269 objectptr *encoding;
1270 #ifdef HAVE_CAIRO
1271 const char **utf8encoding;
1272 cairo_font_face_t *font_face;
1273 unsigned long glyph_index[256];
1274 double glyph_top[256];
1275 double glyph_bottom[256];
1276 double glyph_advance[256];
1277 #endif /* HAVE_CAIRO */
1278 } fontinfo;
1280 /*----------------------------------------------------------------------*/
1282 typedef struct {
1283 char *name;
1284 BBox bbox;
1285 } psbkground;
1287 /*----------------------------------------------------------------------*/
1288 /* Key macro information */
1289 /*----------------------------------------------------------------------*/
1291 typedef struct _keybinding *keybindingptr;
1293 typedef struct _keybinding {
1294 xcWidget window; /* per-window function, or NULL */
1295 int keywstate;
1296 int function;
1297 short value;
1298 keybindingptr nextbinding;
1299 } keybinding;
1301 /*----------------------------------------------------------------------*/
1302 /* Enumeration of functions available for binding to keys/buttons */
1303 /* IMPORTANT! Do not alter this list without also fixing the text */
1304 /* in keybindings.c! */
1305 /*----------------------------------------------------------------------*/
1307 enum {
1308 XCF_ENDDATA = -2, XCF_SPACER /* -1 */,
1309 XCF_Page /* 0 */, XCF_Anchor /* 1 */,
1310 XCF_Superscript /* 2 */, XCF_Subscript /* 3 */,
1311 XCF_Normalscript /* 4 */, XCF_Font /* 5 */,
1312 XCF_Boldfont /* 6 */, XCF_Italicfont /* 7 */,
1313 XCF_Normalfont /* 8 */, XCF_Underline /* 9 */,
1314 XCF_Overline /* 10 */, XCF_ISO_Encoding /* 11 */,
1315 XCF_Halfspace /* 12 */, XCF_Quarterspace /* 13 */,
1316 XCF_Special /* 14 */, XCF_TabStop /* 15 */,
1317 XCF_TabForward /* 16 */, XCF_TabBackward /* 17 */,
1318 XCF_Text_Return /* 18 */, XCF_Text_Delete /* 19 */,
1319 XCF_Text_Right /* 20 */, XCF_Text_Left /* 21 */,
1320 XCF_Text_Up /* 22 */, XCF_Text_Down /* 23 */,
1321 XCF_Text_Split /* 24 */, XCF_Text_Home /* 25 */,
1322 XCF_Text_End /* 26 */, XCF_Linebreak /* 27 */,
1323 XCF_Parameter /* 28 */, XCF_Edit_Param /* 29 */,
1324 XCF_ChangeStyle /* 30 */, XCF_Edit_Delete /* 31 */,
1325 XCF_Edit_Insert /* 32 */, XCF_Edit_Append /* 33 */,
1326 XCF_Edit_Next /* 34 */, XCF_Attach /* 35 */,
1327 XCF_Next_Library /* 36 */, XCF_Library_Directory /* 37 */,
1328 XCF_Library_Move /* 38 */, XCF_Library_Copy /* 39 */,
1329 XCF_Library_Edit /* 40 */, XCF_Library_Delete /* 41 */,
1330 XCF_Library_Duplicate /* 42 */, XCF_Library_Hide /* 43 */,
1331 XCF_Library_Virtual /* 44 */, XCF_Page_Directory /* 45 */,
1332 XCF_Library_Pop /* 46 */, XCF_Virtual /* 47 */,
1333 XCF_Help /* 48 */, XCF_Redraw /* 49 */,
1334 XCF_View /* 50 */, XCF_Zoom_In /* 51 */,
1335 XCF_Zoom_Out /* 52 */, XCF_Pan /* 53 */,
1336 XCF_Double_Snap /* 54 */, XCF_Halve_Snap /* 55 */,
1337 XCF_Write /* 56 */, XCF_Rotate /* 57 */,
1338 XCF_Flip_X /* 58 */, XCF_Flip_Y /* 59 */,
1339 XCF_Snap /* 60 */, XCF_SnapTo /* 61 */,
1340 XCF_Pop /* 62 */, XCF_Push /* 63 */,
1341 XCF_Delete /* 64 */, XCF_Select /* 65 */,
1342 XCF_Box /* 66 */, XCF_Arc /* 67 */,
1343 XCF_Text /* 68 */, XCF_Exchange /* 69 */,
1344 XCF_Copy /* 70 */, XCF_Move /* 71 */,
1345 XCF_Join /* 72 */, XCF_Unjoin /* 73 */,
1346 XCF_Spline /* 74 */, XCF_Edit /* 75 */,
1347 XCF_Undo /* 76 */, XCF_Redo /* 77 */,
1348 XCF_Select_Save /* 78 */, XCF_Unselect /* 79 */,
1349 XCF_Dashed /* 80 */, XCF_Dotted /* 81 */,
1350 XCF_Solid /* 82 */, XCF_Prompt /* 83 */,
1351 XCF_Dot /* 84 */, XCF_Wire /* 85 */,
1352 XCF_Cancel /* 86 */, XCF_Nothing /* 87 */,
1353 XCF_Exit /* 88 */, XCF_Netlist /* 89 */,
1354 XCF_Swap /* 90 */, XCF_Pin_Label /* 91 */,
1355 XCF_Pin_Global /* 92 */, XCF_Info_Label /* 93 */,
1356 XCF_Graphic /* 94 */, XCF_SelectBox /* 95 */,
1357 XCF_Connectivity /* 96 */, XCF_Continue_Element /* 97 */,
1358 XCF_Finish_Element /* 98 */, XCF_Continue_Copy /* 99 */,
1359 XCF_Finish_Copy /* 100 */, XCF_Finish /* 101 */,
1360 XCF_Cancel_Last /* 102 */, XCF_Sim /* 103 */,
1361 XCF_SPICE /* 104 */, XCF_PCB /* 105 */,
1362 XCF_SPICEflat /* 106 */, XCF_Rescale /* 107 */,
1363 XCF_Reorder /* 108 */, XCF_Color /* 109 */,
1364 XCF_Margin_Stop /* 110 */, XCF_Text_Delete_Param /* 111 */,
1365 NUM_FUNCTIONS
1368 /*----------------------------------------------------------------------*/
1369 /* Per-drawing-page parameters */
1370 /*----------------------------------------------------------------------*/
1372 typedef struct {
1373 /* per-drawing-page parameters */
1374 objinstptr pageinst;
1375 char *filename; /* file to save as */
1376 u_char idx; /* page index */
1377 psbkground background; /* background rendered file info */
1378 float wirewidth;
1379 float outscale;
1380 float gridspace;
1381 float snapspace;
1382 short orient;
1383 short pmode;
1384 short coordstyle;
1385 XPoint drawingscale;
1386 XPoint pagesize; /* size of page to print on */
1387 XPoint margins;
1388 } Pagedata;
1390 /*----------------------------------------------------------------------*/
1391 /* Structure holding information about graphic images used. These hold */
1392 /* the original data for the images, and may be shared. */
1393 /*----------------------------------------------------------------------*/
1395 typedef struct {
1396 xcImage *image;
1397 int refcount;
1398 char *filename;
1399 } Imagedata;
1401 /*----------------------------------------------------------------------*/
1402 /* The main globally-accessible data structure. This structure holds */
1403 /* all the critical data needed by the drawing window */
1404 /*----------------------------------------------------------------------*/
1406 typedef struct _windowdata *XCWindowDataPtr;
1408 typedef struct _windowdata {
1410 XCWindowDataPtr next; /* next window in list */
1412 /* widgets and X11 parameters */
1413 xcWidget area;
1414 xcWidget scrollbarh, scrollbarv;
1415 int panx, pany;
1416 Window window;
1417 GC gc;
1418 #ifndef HAVE_CAIRO
1419 Pixmap clipmask;
1420 Pixmap pbuf; /* clipmask buffer for hierarchical clipping */
1421 signed char clipped;
1422 GC cmgc;
1423 #endif /* !HAVE_CAIRO */
1424 int gccolor;
1425 xcIntervalId time_id;
1426 Boolean redraw_needed;
1427 Boolean redraw_ongoing;
1428 #ifdef HAVE_CAIRO
1429 cairo_surface_t *surface;
1430 cairo_t *cr; /* cairo_drawing context */
1431 cairo_pattern_t *fixed_pixmap; /* pixmap holding the background data of */
1432 /* all fixed element. ie. not including the */
1433 /* element currently being edited. */
1434 #else /* HAVE_CAIRO */
1435 Pixmap fixed_pixmap;
1436 #endif /* HAVE_CAIRO */
1437 /* global page parameters */
1438 short width, height;
1439 short page;
1440 float vscale; /* proper scale */
1441 XPoint pcorner; /* page position */
1443 /* global option defaults */
1444 float textscale;
1445 float linewidth;
1446 float zoomfactor;
1447 short psfont;
1448 u_short anchor;
1449 u_short style;
1450 int color;
1451 short filter; /* selection filter */
1452 Boolean manhatn;
1453 Boolean boxedit;
1454 Boolean pathedit;
1455 Boolean snapto;
1456 Boolean bboxon;
1457 Boolean center;
1458 Boolean gridon;
1459 Boolean axeson;
1460 Boolean invert;
1461 Boolean mapped; /* indicates if window is drawable */
1462 char buschar; /* Character indicating vector notation */
1463 Boolean editinplace;
1464 Boolean pinpointon;
1465 Boolean pinattach; /* keep wires attached to pins when moving objinsts */
1466 Boolean showclipmasks; /* draw clipmask shape outlines */
1467 #ifndef TCL_WRAPPER
1468 #ifdef HAVE_XPM
1469 Boolean toolbar_on;
1470 #endif
1471 #endif
1473 /* buffers and associated variables */
1474 XPoint save, origin;
1475 short selects;
1476 short *selectlist;
1477 short attachto;
1478 short lastlibrary;
1479 short textpos;
1480 short textend;
1481 objinstptr topinstance;
1482 objectptr editstack;
1483 Matrixptr MatStack;
1484 pushlistptr stack;
1485 pushlistptr hierstack;
1486 event_mode_t event_mode;
1487 char *lastbackground;
1488 Cursor *defaultcursor;
1489 } XCWindowData;
1491 /* Record for undo function */
1493 typedef struct _undostack *Undoptr;
1495 typedef struct _undostack {
1496 Undoptr next; /* next record in undo stack */
1497 Undoptr last; /* double-linked for "redo" function */
1498 u_int type; /* type of event */
1499 short idx; /* counter for undo event */
1500 objinstptr thisinst; /* instance of object in which event occurred */
1501 XCWindowData *window;/* window in which event occurred */
1502 int idata; /* simple undedicated integer datum */
1503 char *undodata; /* free space to be malloc'd */
1504 /* (size dependent on "type") */
1505 } Undostack;
1507 /* This whole thing needs to be cleaned up. . . now I've got objects in */
1508 /* "library" which are repeated both in the "instlist" pair and the */
1509 /* "thisobject" pointer in each instance. The instance is repeated on */
1510 /* the library page. Ideally, the instance list should only exist on */
1511 /* the library page, and not be destroyed on every call to "composelib" */
1513 typedef struct {
1514 short number;
1515 objectptr *library;
1516 liblistptr instlist; /* List of instances */
1517 } Library;
1519 typedef struct _Technology *TechPtr;
1521 typedef struct _Technology {
1522 u_char flags; /* Flags for library page (changed, read-only) */
1523 char *technology; /* Namespace name (without the "::") */
1524 char *filename; /* Library file associated with technology */
1525 TechPtr next; /* Linked list */
1526 } Technology;
1528 /* Known flags for library pages */
1530 #define TECH_CHANGED 0x01
1531 #define TECH_READONLY 0x02 /* Technology file not writable */
1532 #define TECH_IMPORTED 0x04 /* Loaded only part of file */
1533 #define TECH_REPLACE 0x08 /* Replace instances when reading */
1534 #define TECH_REPLACE_TEMP 0x10 /* Temporary store */
1535 #define TECH_USED 0x20 /* Temporary marker flag */
1536 #define TECH_PREFER 0x40 /* Prefer technology on name conflict */
1538 /*----------------------------------------------------------------------*/
1539 /* A convenient structure for holding all the object lists */
1540 /*----------------------------------------------------------------------*/
1542 typedef struct {
1543 char *libsearchpath; /* list of directories to search */
1544 char *filesearchpath; /* list of directories to search */
1545 char *tempfile;
1546 char *tempdir;
1547 Boolean retain_backup;
1548 xcIntervalId timeout_id;
1549 int save_interval;
1550 Boolean filefilter; /* Is the file list filtered? */
1551 Boolean hold; /* allow HOLD modifiers on buttons */
1552 Boolean showtech; /* Write technology names in library */
1553 u_short new_changes;
1554 signed char suspend; /* suspend graphics updates if TRUE */
1555 short numlibs;
1556 short pages;
1557 Pagedata **pagelist;
1558 Undoptr undostack; /* actions to undo */
1559 Undoptr redostack; /* actions to redo */
1560 Library fontlib;
1561 Library *userlibs;
1562 TechPtr technologies;
1563 objinstptr *libtop;
1564 Imagedata *imagelist;
1565 short images;
1566 XCWindowData *windowlist; /* linked list of known windows */
1567 } Globaldata;
1570 /*-------------------------------------------------------------------------*/
1571 /* Track state of the ghostscript renderer */
1572 /*-------------------------------------------------------------------------*/
1574 typedef enum {
1575 GS_INIT, /* Initial state; gs is idle. */
1576 GS_PENDING, /* Drawing in progress; gs is busy. */
1577 GS_READY /* Drawing done; gs is waiting for "next". */
1578 } gs_state_t;
1581 /*-------------------------------------------------------------------------*/
1582 /* For the eventmodes (ARC_MODE, EARC_MODE, SPLINE_MODE, etc) the drawing */
1583 /* and/or redrawing of the elements is centralized in functions */
1584 /* corresponding to the eventmode name (arc_mode_draw, spline_mode_draw, */
1585 /* etc.). Depending on the state these functions clear, draw or whatever */
1586 /* is needed. A description of the options follows below */
1587 /* fixed_pixmap refers to the background pixmap without the element(s) */
1588 /* currently being edited. */
1589 /*-------------------------------------------------------------------------*/
1591 typedef enum {
1592 xcDRAW_INIT, /* Initalize fixed_pixmap and draw the element(s) */
1593 /* element(s) currently being edited, including */
1594 /* edit lines. */
1596 xcDRAW_EDIT, /* Draw the currently edited element(s), including */
1597 /* edit lines. */
1599 xcDRAW_FINAL, /* Draw the finalized element(s), without edit */
1600 /* lines to the fixed_pixmap */
1602 xcDRAW_EMPTY, /* Refresh the screen by drawing the fixed_pixmap */
1603 /* This essentially clear the edited elements */
1605 xcREDRAW_FORCED /* Redraws everything, including edit lines. Only */
1606 /* used in drawarea. This one should be called */
1607 /* when something has changed (eg. zoom). */
1608 /* It will redraw the fixed_pixmap */
1609 } xcDrawType;
1611 /*----------------------------------------------------------------------*/
1612 /* structures previously defined in menudefs.h */
1613 /*----------------------------------------------------------------------*/
1614 /*----------------------------------------------------------------------*/
1615 /* Menu Definitions for hierarchical pulldown menus */
1616 /*----------------------------------------------------------------------*/
1618 #ifndef TCL_WRAPPER
1620 typedef struct _menustruct *menuptr;
1622 typedef struct _menustruct {
1623 char *name;
1624 menuptr submenu;
1625 short size;
1626 XtCallbackProc func;
1627 void *passeddata;
1628 } menustruct;
1630 /*----------------------------------------------------------------------*/
1631 /* Structure for calling routines from the Toolbar icons */
1632 /*----------------------------------------------------------------------*/
1634 typedef struct _toolbarstruct *toolbarptr;
1636 typedef struct _toolbarstruct {
1637 char *name;
1638 char **icon_data;
1639 XtCallbackProc func;
1640 void *passeddata;
1641 char *hint;
1642 } toolbarstruct;
1644 #endif
1645 /* Menus and Toolbars are taken care of entirely by scripts in the Tcl/ */
1646 /* Tk version of xcircuit. */
1647 /*----------------------------------------------------------------------*/