Corrected (maybe) an error in the old Xt code that must have been
[xcircuit.git] / xcircuit.h
blob84a75ee697e3513efb4429e37b603ced6e03cade
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 */
481 /*----------------------------------------------------------------------*/
482 /* Box styles */
483 /*----------------------------------------------------------------------*/
485 #define NORMAL 0
486 #define UNCLOSED 1
487 #define DASHED 2
488 #define DOTTED 4
489 #define NOBORDER 8
490 #define FILLED 16
491 #define STIP0 32
492 #define STIP1 64
493 #define STIP2 128
494 #define FILLSOLID 224 /* = 32 + 64 + 128 */
495 #ifdef OPAQUE
496 #undef OPAQUE
497 #endif
498 #define OPAQUE 256
499 #define BBOX 512
500 #define SQUARECAP 1024
501 #define CLIPMASK 2048
502 #define FIXEDBBOX 4096
504 /*----------------------------------------------------------------------*/
505 /* Box edit styles */
506 /*----------------------------------------------------------------------*/
508 #define NONE 0
509 #define MANHATTAN 1
510 #define RHOMBOIDX 2
511 #define RHOMBOIDY 4
512 #define RHOMBOIDA 8
514 /*----------------------------------------------------------------------*/
515 /* Path edit styles */
516 /*----------------------------------------------------------------------*/
518 #define TANGENTS 1 /* (NORMAL = 0) */
520 /*----------------------------------------------------------------------*/
521 /* Cycle points (selected points) (flag bits, can be OR'd together) */
522 /*----------------------------------------------------------------------*/
524 #define EDITX 0x01
525 #define EDITY 0x02
526 #define LASTENTRY 0x04
527 #define PROCESS 0x08
528 #define REFERENCE 0x10
529 #define ANTIXY 0x20 /* For matched-tangent curves */
531 /*----------------------------------------------------------------------*/
532 /* Arc creation and edit styles */
533 /*----------------------------------------------------------------------*/
535 #define CENTER 1
536 #define RADIAL 2
538 /*----------------------------------------------------------------------*/
539 /* Delete/undelete draw-mode styles */
540 /*----------------------------------------------------------------------*/
542 #define ERASE 1
543 #define DRAW 1
545 /*----------------------------------------------------------------------*/
546 /* Schematic object types and pin label types */
547 /*----------------------------------------------------------------------*/
549 #define PRIMARY 0 /* Primary (master) schematic page */
550 #define SECONDARY 1 /* Secondary (slave) schematic page */
551 #define TRIVIAL 2 /* Symbol as non-schematic element */
552 #define SYMBOL 3 /* Symbol associated with a schematic */
553 #define FUNDAMENTAL 4 /* Standalone symbol */
554 #define NONETWORK 5 /* Do not netlist this object */
555 #define GLYPH 6 /* Symbol is a font glyph */
557 #define LOCAL 1
558 #define GLOBAL 2
559 #define INFO 3
561 #define HIERARCHY_LIMIT 256 /* Stop if recursion goes this deep */
563 /*----------------------------------------------------------------------*/
564 /* Save types. This list incorporates "ALL_PAGES", below. */
565 /*----------------------------------------------------------------------*/
567 #define CURRENT_PAGE 0 /* Current page + all associated pages */
568 #define NO_SUBCIRCUITS 1 /* Current page w/o subcircuit pages */
570 /*----------------------------------------------------------------------*/
571 /* Modes used when ennumerating page totals. */
572 /*----------------------------------------------------------------------*/
574 #define INDEPENDENT 0
575 #define DEPENDENT 1
576 #define TOTAL_PAGES 2
577 #define LINKED_PAGES 3
578 #define PAGE_DEPEND 4
579 #define ALL_PAGES 5
581 /*----------------------------------------------------------------------*/
582 /* Color scheme styles (other than NORMAL) */
583 /*----------------------------------------------------------------------*/
585 #define INVERSE 1
587 /*----------------------------------------------------------------------*/
588 /* Cursor definitions */
589 /*----------------------------------------------------------------------*/
591 #define NUM_CURSORS 11
593 #define ARROW appcursors[0]
594 #define CROSS appcursors[1]
595 #define SCISSORS appcursors[2]
596 #define COPYCURSOR appcursors[3]
597 #define ROTATECURSOR appcursors[4]
598 #define EDCURSOR appcursors[5]
599 #define TEXTPTR appcursors[6]
600 #define CIRCLE appcursors[7]
601 #define QUESTION appcursors[8]
602 #define WAITFOR appcursors[9]
603 #define HAND appcursors[10]
605 #define DEFAULTCURSOR (*areawin->defaultcursor)
607 /*----------------------------------------------------------------------*/
608 /* integer and floating-point coordinate list structures */
609 /*----------------------------------------------------------------------*/
611 typedef XPoint* pointlist;
612 typedef XfPoint* fpointlist;
614 /*----------------------------------------------------------------------*/
615 /* Allowed parameterization types */
616 /*----------------------------------------------------------------------*/
618 enum paramwhich {
619 P_NUMERIC = 0, /* uncommitted numeric parameter */
620 P_SUBSTRING,
621 P_POSITION_X,
622 P_POSITION_Y,
623 P_STYLE,
624 P_ANCHOR,
625 P_ANGLE1,
626 P_ANGLE2,
627 P_RADIUS,
628 P_MINOR_AXIS,
629 P_ROTATION,
630 P_SCALE,
631 P_LINEWIDTH,
632 P_COLOR,
633 P_EXPRESSION,
634 P_POSITION, /* mode only, not a real parameter */
635 NUM_PARAM_TYPES
638 /*----------------------------------------------------------------------*/
639 /* Labels are constructed of strings and executables */
640 /*----------------------------------------------------------------------*/
642 typedef struct _stringpart *stringptr;
644 typedef struct _stringpart {
645 stringptr nextpart;
646 u_char type;
647 union {
648 u_char *string;
649 int color;
650 int font;
651 int width;
652 int flags;
653 float scale;
654 short kern[2];
655 } data;
656 } stringpart;
658 /*----------------------------------------------------------------------*/
659 /* structures of all main elements which can be displayed & manipulated */
660 /*----------------------------------------------------------------------*/
662 /*----------------------------------------------------------------------*/
663 /* Object & object instance parameter structure */
664 /* (Add types as necessary) */
665 /*----------------------------------------------------------------------*/
667 enum paramtypes {XC_INT = 0, XC_FLOAT, XC_STRING, XC_EXPR};
669 /* Object parameters: general key:value parameter model */
670 /* Note that this really should be a hash table, not a linked list. . . */
672 typedef struct _oparam *oparamptr;
674 typedef struct _oparam {
675 char * key; /* name of the parameter */
676 u_char type; /* type is from paramtypes list above */
677 u_char which; /* what the parameter represents (P_*) */
678 union {
679 stringpart *string; /* xcircuit label type */
680 char *expr; /* TCL (string) expression */
681 int ivalue; /* also covers type short int by typecasting */
682 float fvalue;
683 } parameter; /* default or substitution value */
684 oparamptr next; /* next parameter in linked list */
685 } oparam;
687 /* Element parameters: reference back to the object's parameters */
688 /* These parameters are forward-substituted when descending into */
689 /* an object instance. */
690 /* Note that this really should be a hash table, not a linked list. . . */
692 typedef struct _eparam *eparamptr;
694 typedef struct _eparam {
695 char * key; /* name of the parameter */
696 u_char flags; /* namely, bit declaring an indirect parameter */
697 union {
698 int pointno; /* point number in point array, for polygons */
699 short pathpt[2]; /* element number and point number, for paths */
700 char *refkey; /* parameter reference key, for instances */
701 } pdata;
702 eparamptr next; /* next parameter in linked list */
703 } eparam;
705 #define P_INDIRECT 0x01 /* indirect parameter indicator */
707 /*----------------------------------------------------------------------*/
708 /* Generic element type is a superset of all elements. */
709 /*----------------------------------------------------------------------*/
711 typedef struct {
712 u_short type; /* type is LABEL, POLYGON, etc., from below */
713 int color;
714 eparamptr passed;
715 } generic, *genericptr; /* (convenience function for retypecasting) */
717 /*----------------------------------------------------------------------*/
718 /* selection-mechanism structures */
719 /*----------------------------------------------------------------------*/
721 typedef struct {
722 short number;
723 genericptr *element;
724 short *idx;
725 } uselection;
727 typedef struct {
728 short number;
729 u_char flags;
730 } pointselect;
732 /*----------------------------------------------------------------------*/
733 /* Bounding box */
734 /*----------------------------------------------------------------------*/
736 typedef struct {
737 XPoint lowerleft;
738 Dimension width, height;
739 } BBox;
741 /*----------------------------------------------------------------------*/
742 /* Object instance type */
743 /*----------------------------------------------------------------------*/
745 typedef struct _xcobject *objectptr;
747 typedef struct {
748 u_short type;
749 int color;
750 eparamptr passed; /* numerical parameters passed from above */
751 u_short style;
752 XPoint position;
753 float rotation;
754 float scale;
755 objectptr thisobject;
756 oparamptr params; /* parameter substitutions for this instance */
757 BBox bbox; /* per-instance bounding box information */
758 BBox *schembbox; /* Extra bounding box for pin labels */
759 } objinst, *objinstptr;
761 /* Linked-list for objects */
763 typedef struct _objlist *objlistptr;
765 typedef struct _objlist {
766 int libno; /* library in which object appears */
767 objectptr thisobject; /* pointer to the object */
768 objlistptr next;
769 } objlist;
771 /* Linked-list for object instances */
773 typedef struct _pushlist *pushlistptr;
775 typedef struct _pushlist {
776 objinstptr thisinst;
777 char *clientdata; /* general-purpose record */
778 pushlistptr next;
779 } pushlist;
781 /* Same as above, but for the list of instances in a library, so it */
782 /* needs an additional record showing whether or not the instance is */
783 /* "virtual" (not the primary library instance of the object) */
785 typedef struct _liblist *liblistptr;
787 typedef struct _liblist {
788 objinstptr thisinst;
789 u_char virtual;
790 liblistptr next;
791 } liblist;
793 /*----------------------------------------------------------------------*/
794 /* Generalized graphic object (Tcl/Tk only) */
795 /*----------------------------------------------------------------------*/
797 typedef struct {
798 u_short type;
799 int color; /* foreground, for bitmaps only */
800 eparamptr passed; /* numerical parameters passed from above */
801 XPoint position;
802 float rotation;
803 float scale;
804 xcImage *source; /* source data */
805 #ifndef HAVE_CAIRO
806 xcImage *target; /* target (scaled) data */
807 float trot; /* target rotation */
808 float tscale; /* target scale (0 = uninitialized) */
809 Pixmap clipmask; /* clipmask for non-manhattan rotations */
810 Boolean valid; /* does target need to be regenerated? */
811 #endif /* !HAVE_CAIRO */
812 } graphic, *graphicptr;
814 /*----------------------------------------------------------------------*/
815 /* Label */
816 /*----------------------------------------------------------------------*/
818 typedef struct {
819 u_short type;
820 int color;
821 eparamptr passed; /* numerical parameters passed from above */
822 pointselect *cycle; /* Edit position(s), or NULL */
823 XPoint position;
824 float rotation;
825 float scale;
826 u_short anchor;
827 u_char pin;
828 stringpart *string;
829 } label, *labelptr;
831 /*----------------------------------------------------------------------*/
832 /* Polygon */
833 /*----------------------------------------------------------------------*/
835 typedef struct {
836 u_short type;
837 int color;
838 eparamptr passed; /* numerical parameters passed from above */
839 u_short style;
840 float width;
841 pointselect *cycle; /* Edit position(s), or NULL */
842 short number;
843 pointlist points;
844 } polygon, *polyptr;
846 /*----------------------------------------------------------------------*/
847 /* Bezier Curve */
848 /*----------------------------------------------------------------------*/
850 typedef struct {
851 u_short type;
852 int color;
853 eparamptr passed; /* numerical parameters passed from above */
854 u_short style;
855 float width;
856 pointselect *cycle; /* Edit position(s), or NULL */
857 XPoint ctrl[4];
858 /* the following are for rendering only */
859 XfPoint points[INTSEGS];
860 } spline, *splineptr;
862 /*----------------------------------------------------------------------*/
863 /* Arc */
864 /*----------------------------------------------------------------------*/
866 typedef struct {
867 u_short type;
868 int color;
869 eparamptr passed; /* numerical parameters passed from above */
870 u_short style;
871 float width;
872 pointselect *cycle; /* Edit position(s), or NULL */
873 short radius; /* x-axis radius */
874 short yaxis; /* y-axis radius */
875 float angle1; /* endpoint angles, in degrees */
876 float angle2;
877 XPoint position;
878 /* the following are for rendering only */
879 short number;
880 XfPoint points[RSTEPS + 1];
881 } arc, *arcptr;
883 /*----------------------------------------------------------------------*/
884 /* Path */
885 /*----------------------------------------------------------------------*/
887 typedef struct {
888 u_short type;
889 int color;
890 eparamptr passed; /* numerical parameters passed from above */
891 u_short style;
892 float width;
893 short parts;
894 genericptr *plist; /* to be retypecast to polygon, arc, or spline */
895 } path, *pathptr;
897 /*----------------------------------------------------------------------*/
898 /* selection from top-level object */
899 /*----------------------------------------------------------------------*/
901 /*----------------------------------------------------------------------*/
902 /* Undo mechanism definitions */
903 /*----------------------------------------------------------------------*/
905 enum UNDO_MODES {UNDO_DONE = 0, UNDO_MORE, MODE_CONNECT, MODE_RECURSE_WIDE,
906 MODE_RECURSE_NARROW};
908 typedef struct _selection *selectionptr;
910 typedef struct _selection {
911 int selects;
912 short *selectlist;
913 objinstptr thisinst;
914 selectionptr next;
915 } selection;
917 #define select_element(a) recurse_select_element(a, UNDO_MORE)
918 #define select_add_element(a) recurse_select_element(a, UNDO_DONE)
920 #define easydraw(a, b) geneasydraw(a, b, topobject, areawin->topinstance)
922 /*----------------------------------------------------------------------*/
923 /* Netlist structures for schematic capture */
924 /*----------------------------------------------------------------------*/
926 /* Structure to hold net and subnet IDs for a bus */
928 typedef struct {
929 int netid;
930 int subnetid;
931 } buslist;
933 /* Structure mimicking the top part of a Polylist or Labellist */
934 /* when we just want the netlist information and don't care */
935 /* which one we're looking at. */
937 typedef struct {
938 union {
939 int id;
940 buslist *list;
941 } net;
942 int subnets;
943 } Genericlist;
945 /* Linked polygon list */
947 typedef struct _Polylist *PolylistPtr;
948 typedef struct _Polylist
950 union {
951 int id; /* A single net ID, if subnets == 0 */
952 buslist *list; /* List of net and subnet IDs for a bus */
953 } net;
954 int subnets; /* Number of subnets; 0 if no subnets */
955 objectptr cschem; /* Schematic containing the polygon */
956 polyptr poly;
957 PolylistPtr next; /* Next polygon in the linked list */
958 } Polylist;
960 /* Linked label list */
962 typedef struct _Labellist *LabellistPtr;
963 typedef struct _Labellist
965 union {
966 int id; /* A single net ID, if subnets == 0 */
967 buslist *list; /* List of net and subnet IDs for a bus */
968 } net;
969 int subnets; /* Number of subnets; 0 if no subnets */
970 objectptr cschem; /* Schematic containing the label */
971 objinstptr cinst; /* Specific label instance, if applicable */
972 labelptr label;
973 LabellistPtr next;
974 } Labellist;
976 /* List of object's networks by (flattened) name */
978 typedef struct _Netname *NetnamePtr;
979 typedef struct _Netname
981 int netid;
982 stringpart *localpin;
983 NetnamePtr next;
984 } Netname;
986 /* List of object's I/O ports */
988 typedef struct _Portlist *PortlistPtr;
989 typedef struct _Portlist
991 int portid;
992 int netid;
993 PortlistPtr next;
994 } Portlist;
996 /* List of calls to instances of objects */
997 /* or subcircuit objects. */
999 typedef struct _Calllist *CalllistPtr;
1000 typedef struct _Calllist
1002 objectptr cschem; /* Schematic containing the instance called */
1003 objinstptr callinst; /* Instance called */
1004 objectptr callobj; /* Object of instance called */
1005 char *devname; /* if non-null, name of device in netlist */
1006 int devindex; /* if non-negative, index of device in netlist */
1007 PortlistPtr ports;
1008 CalllistPtr next;
1009 } Calllist;
1011 /* PCB netlist structures */
1013 struct Pnet {
1014 int numnets;
1015 int *netidx;
1016 struct Pnet *next;
1019 struct Pstr {
1020 stringpart *string;
1021 struct Pstr *next;
1024 struct Ptab {
1025 objectptr cschem;
1026 struct Pnet *nets;
1027 struct Pstr *pins;
1028 struct Ptab *next;
1031 /*----------------------------------------------------------------------*/
1032 /* Information needed to highlight a net */
1033 /*----------------------------------------------------------------------*/
1035 typedef struct {
1036 Genericlist *netlist;
1037 objinstptr thisinst;
1038 } Highlight;
1040 /*----------------------------------------------------------------------*/
1041 /* Main object structure */
1042 /*----------------------------------------------------------------------*/
1044 typedef struct _xcobject {
1045 char name[80];
1046 u_short changes; /* Number of unsaved changes to object */
1047 Boolean hidden;
1048 float viewscale;
1049 XPoint pcorner; /* position relative to window */
1050 BBox bbox; /* bounding box information (excluding */
1051 /* parameterized elements) */
1052 short parts;
1053 genericptr *plist; /* to be retypecast to label, polygon, etc. */
1054 oparamptr params; /* list of parameters, with default values */
1056 Highlight highlight; /* net to be highlighted on redraw */
1057 u_char schemtype;
1058 objectptr symschem; /* schematic page support */
1059 Boolean valid; /* Is current netlist valid? */
1060 Boolean traversed; /* Flag to indicate object was processed */
1061 LabellistPtr labels; /* Netlist pins */
1062 PolylistPtr polygons; /* Netlist wires */
1063 PortlistPtr ports; /* Netlist ports */
1064 CalllistPtr calls; /* Netlist subcircuits and connections */
1065 Boolean infolabels; /* TRUE if object contains info-labels */
1066 NetnamePtr netnames; /* Local names for flattening */
1067 /* (this probably shouldn't be here. . .) */
1068 } object;
1070 /*----------------------------------------------------------------------*/
1071 /* Transformation matrices */
1072 /* Works like this (see also PostScript reference manual): */
1073 /* [x' y' 1] = [x y 1] * | a d 0 | */
1074 /* | b e 0 | */
1075 /* | c f 1 | */
1076 /*----------------------------------------------------------------------*/
1078 typedef struct _matrix *Matrixptr;
1080 typedef struct _matrix {
1081 float a, b, c, d, e, f;
1082 Matrixptr nextmatrix;
1083 } Matrix;
1085 /*----------------------------------------------------------------------*/
1086 /* Some convenience functions for matrix manipulation */
1087 /*----------------------------------------------------------------------*/
1089 #define DCTM areawin->MatStack
1091 /*----------------------------------------------------------------------*/
1092 /* button tap/press definitions */
1093 /*----------------------------------------------------------------------*/
1095 #define PRESSTIME 200 /* milliseconds of push to be a "press" */
1097 /*----------------------------------------------------------------------*/
1098 /* object name alias structures */
1099 /*----------------------------------------------------------------------*/
1101 typedef struct _stringlist *slistptr;
1103 typedef struct _stringlist {
1104 char *alias;
1105 slistptr next;
1106 } stringlist;
1108 typedef struct _alias *aliasptr;
1110 typedef struct _alias {
1111 objectptr baseobj; /* pointer to object (actual name) */
1112 slistptr aliases; /* linked list of alias names */
1113 aliasptr next;
1114 } alias;
1116 /*----------------------------------------------------------------------*/
1117 /* To facilitate compiling the Tcl/Tk version, we make some convenient */
1118 /* definitions for types "xc..." and "Xc..." which can be mapped both */
1119 /* to X and Xt or to Tk functions and types. */
1120 /*----------------------------------------------------------------------*/
1122 #ifdef TCL_WRAPPER
1124 #define xcWidget Tk_Window
1125 #define xcWidgetList Tk_Window *
1126 #define xcAddEventHandler(a,b,c,d,e) Tk_CreateEventHandler(a,b,d,e)
1127 #define xcRemoveEventHandler(a,b,c,d,e) Tk_DeleteEventHandler(a,b,d,e)
1128 #define xcEventHandler Tk_EventProc *
1129 #define xcWindow Tk_WindowId
1130 #define xcIsRealized Tk_IsMapped /* not sure this is right */
1131 #define xcScreen Tk_Screen
1132 #define xcParent Tk_Parent
1133 #define xcDispatchEvent(a) Tk_HandleEvent(a)
1134 #define xcAddTimeOut(a, b, c, d) Tcl_CreateTimerHandler((int)(b), c, d)
1135 #define xcRemoveTimeOut Tcl_DeleteTimerHandler
1136 #define xcTimeOutProc Tcl_TimerProc *
1137 #define xcIntervalId Tcl_TimerToken
1139 #else
1141 #define xcWidget Widget
1142 #define xcWidgetList WidgetList
1143 #define xcAddEventHandler XtAddEventHandler
1144 #define xcRemoveEventHandler XtRemoveEventHandler
1145 #define xcEventHandler XtEventHandler
1146 #define xcWindow XtWindow
1147 #define xcIsRealized XtIsRealized
1148 #define xcScreen XtScreen
1149 #define xcParent XtParent
1150 #define xcDispatchEvent(a) XtDispatchEvent(a)
1151 #define xcAddTimeOut XtAppAddTimeOut
1152 #define xcRemoveTimeOut XtRemoveTimeOut
1153 #define xcTimeOutProc XtTimerCallbackProc
1154 #define xcIntervalId XtIntervalId
1155 #ifndef ClientData
1156 #define ClientData XtPointer
1157 #endif
1158 #endif
1160 /*----------------------------------------------------------------------*/
1161 /* structures for managing the popup prompt widgets */
1162 /*----------------------------------------------------------------------*/
1164 typedef struct {
1165 xcWidget button;
1166 int foreground;
1167 void (*buttoncall)();
1168 void *dataptr;
1169 } buttonsave;
1171 typedef struct {
1172 xcWidget popup; /* Popup widget */
1173 xcWidget textw; /* Text entry widget */
1174 xcWidget filew; /* File list window */
1175 xcWidget scroll; /* Scrollbar widget */
1176 void (*setvalue)(); /* Callback function */
1177 buttonsave *buttonptr; /* Button widget calling popup */
1178 char *filter; /* Extension filter for highlighting */
1179 /* files. NULL for no file window. */
1180 /* NULL-string for no highlights. */
1181 } popupstruct;
1183 typedef struct {
1184 xcWidget textw;
1185 xcWidget buttonw;
1186 void (*setvalue)();
1187 void *dataptr;
1188 } propstruct;
1190 typedef struct {
1191 char *filename;
1192 int filetype;
1193 } fileliststruct;
1195 enum {DIRECTORY = 0, MATCH, NONMATCH}; /* file types */
1197 /*----------------------------------------------------------------------*/
1198 /* Initial Resource Management */
1199 /*----------------------------------------------------------------------*/
1201 typedef struct {
1202 /* schematic layout colors */
1203 Pixel globalcolor, localcolor, infocolor, ratsnestcolor;
1205 /* non-schematic layout color(s) */
1206 Pixel fixedbboxpix, bboxpix, clipcolor;
1208 /* color scheme 1 */
1209 Pixel fg, bg;
1210 Pixel gridpix, snappix, selectpix, axespix;
1211 Pixel buttonpix, filterpix, auxpix, barpix, parampix;
1213 /* color scheme 2 */
1214 Pixel fg2, bg2;
1215 Pixel gridpix2, snappix2, selectpix2, axespix2;
1216 Pixel buttonpix2, auxpix2, parampix2;
1218 int width, height, timeout;
1219 XFontStruct *filefont;
1221 #ifndef TCL_WRAPPER
1222 XFontStruct *xcfont, *textfont, *titlefont, *helpfont;
1223 #endif
1225 } ApplicationData, *ApplicationDataPtr;
1227 /*----------------------------------------------------------------------*/
1228 /* Macros for GC color and function handling */
1229 /*----------------------------------------------------------------------*/
1231 #define XTopSetForeground(a) if (a == DEFAULTCOLOR) SetForeground(dpy, \
1232 areawin->gc, FOREGROUND); else SetForeground(dpy, areawin->gc, a)
1234 #define XcTopSetForeground(z) XTopSetForeground(z); areawin->gccolor = \
1235 ((z) == DEFAULTCOLOR) ? FOREGROUND : (z)
1237 #define XcSetForeground(z) SetForeground(dpy, areawin->gc, z); \
1238 areawin->gccolor = z
1240 /*----------------------------------------------------------------------*/
1241 /* Structure for maintaining list of colors */
1242 /*----------------------------------------------------------------------*/
1244 typedef struct {
1245 xcWidget cbutton;
1246 XColor color;
1247 } colorindex;
1249 /*----------------------------------------------------------------------*/
1250 /* Font information structure */
1251 /*----------------------------------------------------------------------*/
1252 /* Flags: bit description */
1253 /* 0 bold = 1, normal = 0 */
1254 /* 1 italic = 1, normal = 0 */
1255 /* 2 <reserved, possibly for narrow font type> */
1256 /* 3 drawn = 1, PostScript = 0 */
1257 /* 4 <reserved, possibly for LaTeX font type> */
1258 /* 5 special encoding = 1, Standard Encoding = 0 */
1259 /* 6 ISOLatin1 = 2, ISOLatin2 = 3 */
1260 /* 7+ <reserved for other encoding schemes> */
1261 /*----------------------------------------------------------------------*/
1263 typedef struct {
1264 char *psname;
1265 char *family;
1266 float scale;
1267 u_short flags;
1268 objectptr *encoding;
1269 #ifdef HAVE_CAIRO
1270 const char **utf8encoding;
1271 cairo_font_face_t *font_face;
1272 unsigned long glyph_index[256];
1273 double glyph_top[256];
1274 double glyph_bottom[256];
1275 double glyph_advance[256];
1276 #endif /* HAVE_CAIRO */
1277 } fontinfo;
1279 /*----------------------------------------------------------------------*/
1281 typedef struct {
1282 char *name;
1283 BBox bbox;
1284 } psbkground;
1286 /*----------------------------------------------------------------------*/
1287 /* Key macro information */
1288 /*----------------------------------------------------------------------*/
1290 typedef struct _keybinding *keybindingptr;
1292 typedef struct _keybinding {
1293 xcWidget window; /* per-window function, or NULL */
1294 int keywstate;
1295 int function;
1296 short value;
1297 keybindingptr nextbinding;
1298 } keybinding;
1300 /*----------------------------------------------------------------------*/
1301 /* Enumeration of functions available for binding to keys/buttons */
1302 /* IMPORTANT! Do not alter this list without also fixing the text */
1303 /* in keybindings.c! */
1304 /*----------------------------------------------------------------------*/
1306 enum {
1307 XCF_ENDDATA = -2, XCF_SPACER /* -1 */,
1308 XCF_Page /* 0 */, XCF_Anchor /* 1 */,
1309 XCF_Superscript /* 2 */, XCF_Subscript /* 3 */,
1310 XCF_Normalscript /* 4 */, XCF_Font /* 5 */,
1311 XCF_Boldfont /* 6 */, XCF_Italicfont /* 7 */,
1312 XCF_Normalfont /* 8 */, XCF_Underline /* 9 */,
1313 XCF_Overline /* 10 */, XCF_ISO_Encoding /* 11 */,
1314 XCF_Halfspace /* 12 */, XCF_Quarterspace /* 13 */,
1315 XCF_Special /* 14 */, XCF_TabStop /* 15 */,
1316 XCF_TabForward /* 16 */, XCF_TabBackward /* 17 */,
1317 XCF_Text_Return /* 18 */, XCF_Text_Delete /* 19 */,
1318 XCF_Text_Right /* 20 */, XCF_Text_Left /* 21 */,
1319 XCF_Text_Up /* 22 */, XCF_Text_Down /* 23 */,
1320 XCF_Text_Split /* 24 */, XCF_Text_Home /* 25 */,
1321 XCF_Text_End /* 26 */, XCF_Linebreak /* 27 */,
1322 XCF_Parameter /* 28 */, XCF_Edit_Param /* 29 */,
1323 XCF_ChangeStyle /* 30 */, XCF_Edit_Delete /* 31 */,
1324 XCF_Edit_Insert /* 32 */, XCF_Edit_Append /* 33 */,
1325 XCF_Edit_Next /* 34 */, XCF_Attach /* 35 */,
1326 XCF_Next_Library /* 36 */, XCF_Library_Directory /* 37 */,
1327 XCF_Library_Move /* 38 */, XCF_Library_Copy /* 39 */,
1328 XCF_Library_Edit /* 40 */, XCF_Library_Delete /* 41 */,
1329 XCF_Library_Duplicate /* 42 */, XCF_Library_Hide /* 43 */,
1330 XCF_Library_Virtual /* 44 */, XCF_Page_Directory /* 45 */,
1331 XCF_Library_Pop /* 46 */, XCF_Virtual /* 47 */,
1332 XCF_Help /* 48 */, XCF_Redraw /* 49 */,
1333 XCF_View /* 50 */, XCF_Zoom_In /* 51 */,
1334 XCF_Zoom_Out /* 52 */, XCF_Pan /* 53 */,
1335 XCF_Double_Snap /* 54 */, XCF_Halve_Snap /* 55 */,
1336 XCF_Write /* 56 */, XCF_Rotate /* 57 */,
1337 XCF_Flip_X /* 58 */, XCF_Flip_Y /* 59 */,
1338 XCF_Snap /* 60 */, XCF_SnapTo /* 61 */,
1339 XCF_Pop /* 62 */, XCF_Push /* 63 */,
1340 XCF_Delete /* 64 */, XCF_Select /* 65 */,
1341 XCF_Box /* 66 */, XCF_Arc /* 67 */,
1342 XCF_Text /* 68 */, XCF_Exchange /* 69 */,
1343 XCF_Copy /* 70 */, XCF_Move /* 71 */,
1344 XCF_Join /* 72 */, XCF_Unjoin /* 73 */,
1345 XCF_Spline /* 74 */, XCF_Edit /* 75 */,
1346 XCF_Undo /* 76 */, XCF_Redo /* 77 */,
1347 XCF_Select_Save /* 78 */, XCF_Unselect /* 79 */,
1348 XCF_Dashed /* 80 */, XCF_Dotted /* 81 */,
1349 XCF_Solid /* 82 */, XCF_Prompt /* 83 */,
1350 XCF_Dot /* 84 */, XCF_Wire /* 85 */,
1351 XCF_Cancel /* 86 */, XCF_Nothing /* 87 */,
1352 XCF_Exit /* 88 */, XCF_Netlist /* 89 */,
1353 XCF_Swap /* 90 */, XCF_Pin_Label /* 91 */,
1354 XCF_Pin_Global /* 92 */, XCF_Info_Label /* 93 */,
1355 XCF_Graphic /* 94 */, XCF_SelectBox /* 95 */,
1356 XCF_Connectivity /* 96 */, XCF_Continue_Element /* 97 */,
1357 XCF_Finish_Element /* 98 */, XCF_Continue_Copy /* 99 */,
1358 XCF_Finish_Copy /* 100 */, XCF_Finish /* 101 */,
1359 XCF_Cancel_Last /* 102 */, XCF_Sim /* 103 */,
1360 XCF_SPICE /* 104 */, XCF_PCB /* 105 */,
1361 XCF_SPICEflat /* 106 */, XCF_Rescale /* 107 */,
1362 XCF_Reorder /* 108 */, XCF_Color /* 109 */,
1363 XCF_Margin_Stop /* 110 */, XCF_Text_Delete_Param /* 111 */,
1364 NUM_FUNCTIONS
1367 /*----------------------------------------------------------------------*/
1368 /* Per-drawing-page parameters */
1369 /*----------------------------------------------------------------------*/
1371 typedef struct {
1372 /* per-drawing-page parameters */
1373 objinstptr pageinst;
1374 char *filename; /* file to save as */
1375 u_char idx; /* page index */
1376 psbkground background; /* background rendered file info */
1377 float wirewidth;
1378 float outscale;
1379 float gridspace;
1380 float snapspace;
1381 short orient;
1382 short pmode;
1383 short coordstyle;
1384 XPoint drawingscale;
1385 XPoint pagesize; /* size of page to print on */
1386 XPoint margins;
1387 } Pagedata;
1389 /*----------------------------------------------------------------------*/
1390 /* Structure holding information about graphic images used. These hold */
1391 /* the original data for the images, and may be shared. */
1392 /*----------------------------------------------------------------------*/
1394 typedef struct {
1395 xcImage *image;
1396 int refcount;
1397 char *filename;
1398 } Imagedata;
1400 /*----------------------------------------------------------------------*/
1401 /* The main globally-accessible data structure. This structure holds */
1402 /* all the critical data needed by the drawing window */
1403 /*----------------------------------------------------------------------*/
1405 typedef struct _windowdata *XCWindowDataPtr;
1407 typedef struct _windowdata {
1409 XCWindowDataPtr next; /* next window in list */
1411 /* widgets and X11 parameters */
1412 xcWidget area;
1413 xcWidget scrollbarh, scrollbarv;
1414 int panx, pany;
1415 Window window;
1416 GC gc;
1417 #ifndef HAVE_CAIRO
1418 Pixmap clipmask;
1419 Pixmap pbuf; /* clipmask buffer for hierarchical clipping */
1420 signed char clipped;
1421 GC cmgc;
1422 #endif /* !HAVE_CAIRO */
1423 int gccolor;
1424 xcIntervalId time_id;
1425 Boolean redraw_needed;
1426 Boolean redraw_ongoing;
1427 #ifdef HAVE_CAIRO
1428 cairo_surface_t *surface;
1429 cairo_t *cr; /* cairo_drawing context */
1430 cairo_pattern_t *fixed_pixmap; /* pixmap holding the background data of */
1431 /* all fixed element. ie. not including the */
1432 /* element currently being edited. */
1433 #else /* HAVE_CAIRO */
1434 Pixmap fixed_pixmap;
1435 #endif /* HAVE_CAIRO */
1436 /* global page parameters */
1437 short width, height;
1438 short page;
1439 float vscale; /* proper scale */
1440 XPoint pcorner; /* page position */
1442 /* global option defaults */
1443 float textscale;
1444 float linewidth;
1445 float zoomfactor;
1446 short psfont;
1447 u_short anchor;
1448 u_short style;
1449 int color;
1450 short filter; /* selection filter */
1451 Boolean manhatn;
1452 Boolean boxedit;
1453 Boolean pathedit;
1454 Boolean snapto;
1455 Boolean bboxon;
1456 Boolean center;
1457 Boolean gridon;
1458 Boolean axeson;
1459 Boolean invert;
1460 Boolean mapped; /* indicates if window is drawable */
1461 char buschar; /* Character indicating vector notation */
1462 Boolean editinplace;
1463 Boolean pinpointon;
1464 Boolean pinattach; /* keep wires attached to pins when moving objinsts */
1465 Boolean showclipmasks; /* draw clipmask shape outlines */
1466 #ifndef TCL_WRAPPER
1467 #ifdef HAVE_XPM
1468 Boolean toolbar_on;
1469 #endif
1470 #endif
1472 /* buffers and associated variables */
1473 XPoint save, origin;
1474 short selects;
1475 short *selectlist;
1476 short attachto;
1477 short lastlibrary;
1478 short textpos;
1479 short textend;
1480 objinstptr topinstance;
1481 objectptr editstack;
1482 Matrixptr MatStack;
1483 pushlistptr stack;
1484 pushlistptr hierstack;
1485 event_mode_t event_mode;
1486 char *lastbackground;
1487 Cursor *defaultcursor;
1488 } XCWindowData;
1490 /* Record for undo function */
1492 typedef struct _undostack *Undoptr;
1494 typedef struct _undostack {
1495 Undoptr next; /* next record in undo stack */
1496 Undoptr last; /* double-linked for "redo" function */
1497 u_int type; /* type of event */
1498 short idx; /* counter for undo event */
1499 objinstptr thisinst; /* instance of object in which event occurred */
1500 XCWindowData *window;/* window in which event occurred */
1501 int idata; /* simple undedicated integer datum */
1502 char *undodata; /* free space to be malloc'd */
1503 /* (size dependent on "type") */
1504 } Undostack;
1506 /* This whole thing needs to be cleaned up. . . now I've got objects in */
1507 /* "library" which are repeated both in the "instlist" pair and the */
1508 /* "thisobject" pointer in each instance. The instance is repeated on */
1509 /* the library page. Ideally, the instance list should only exist on */
1510 /* the library page, and not be destroyed on every call to "composelib" */
1512 typedef struct {
1513 short number;
1514 objectptr *library;
1515 liblistptr instlist; /* List of instances */
1516 } Library;
1518 typedef struct _Technology *TechPtr;
1520 typedef struct _Technology {
1521 u_char flags; /* Flags for library page (changed, read-only) */
1522 char *technology; /* Namespace name (without the "::") */
1523 char *filename; /* Library file associated with technology */
1524 TechPtr next; /* Linked list */
1525 } Technology;
1527 /* Known flags for library pages */
1529 #define TECH_CHANGED 0x01
1530 #define TECH_READONLY 0x02 /* Technology file not writable */
1531 #define TECH_IMPORTED 0x04 /* Loaded only part of file */
1532 #define TECH_REPLACE 0x08 /* Replace instances when reading */
1533 #define TECH_REPLACE_TEMP 0x10 /* Temporary store */
1534 #define TECH_USED 0x20 /* Temporary marker flag */
1536 /*----------------------------------------------------------------------*/
1537 /* A convenient structure for holding all the object lists */
1538 /*----------------------------------------------------------------------*/
1540 typedef struct {
1541 char *libsearchpath; /* list of directories to search */
1542 char *filesearchpath; /* list of directories to search */
1543 char *tempfile;
1544 char *tempdir;
1545 Boolean retain_backup;
1546 xcIntervalId timeout_id;
1547 int save_interval;
1548 Boolean filefilter; /* Is the file list filtered? */
1549 Boolean hold; /* allow HOLD modifiers on buttons */
1550 Boolean showtech; /* Write technology names in library */
1551 u_short new_changes;
1552 signed char suspend; /* suspend graphics updates if TRUE */
1553 short numlibs;
1554 short pages;
1555 Pagedata **pagelist;
1556 Undoptr undostack; /* actions to undo */
1557 Undoptr redostack; /* actions to redo */
1558 Library fontlib;
1559 Library *userlibs;
1560 TechPtr technologies;
1561 objinstptr *libtop;
1562 Imagedata *imagelist;
1563 short images;
1564 XCWindowData *windowlist; /* linked list of known windows */
1565 } Globaldata;
1568 /*-------------------------------------------------------------------------*/
1569 /* Track state of the ghostscript renderer */
1570 /*-------------------------------------------------------------------------*/
1572 typedef enum {
1573 GS_INIT, /* Initial state; gs is idle. */
1574 GS_PENDING, /* Drawing in progress; gs is busy. */
1575 GS_READY /* Drawing done; gs is waiting for "next". */
1576 } gs_state_t;
1579 /*-------------------------------------------------------------------------*/
1580 /* For the eventmodes (ARC_MODE, EARC_MODE, SPLINE_MODE, etc) the drawing */
1581 /* and/or redrawing of the elements is centralized in functions */
1582 /* corresponding to the eventmode name (arc_mode_draw, spline_mode_draw, */
1583 /* etc.). Depending on the state these functions clear, draw or whatever */
1584 /* is needed. A description of the options follows below */
1585 /* fixed_pixmap refers to the background pixmap without the element(s) */
1586 /* currently being edited. */
1587 /*-------------------------------------------------------------------------*/
1589 typedef enum {
1590 xcDRAW_INIT, /* Initalize fixed_pixmap and draw the element(s) */
1591 /* element(s) currently being edited, including */
1592 /* edit lines. */
1594 xcDRAW_EDIT, /* Draw the currently edited element(s), including */
1595 /* edit lines. */
1597 xcDRAW_FINAL, /* Draw the finalized element(s), without edit */
1598 /* lines to the fixed_pixmap */
1600 xcDRAW_EMPTY, /* Refresh the screen by drawing the fixed_pixmap */
1601 /* This essentially clear the edited elements */
1603 xcREDRAW_FORCED /* Redraws everything, including edit lines. Only */
1604 /* used in drawarea. This one should be called */
1605 /* when something has changed (eg. zoom). */
1606 /* It will redraw the fixed_pixmap */
1607 } xcDrawType;
1609 /*----------------------------------------------------------------------*/
1610 /* structures previously defined in menudefs.h */
1611 /*----------------------------------------------------------------------*/
1612 /*----------------------------------------------------------------------*/
1613 /* Menu Definitions for hierarchical pulldown menus */
1614 /*----------------------------------------------------------------------*/
1616 #ifndef TCL_WRAPPER
1618 typedef struct _menustruct *menuptr;
1620 typedef struct _menustruct {
1621 char *name;
1622 menuptr submenu;
1623 short size;
1624 XtCallbackProc func;
1625 void *passeddata;
1626 } menustruct;
1628 /*----------------------------------------------------------------------*/
1629 /* Structure for calling routines from the Toolbar icons */
1630 /*----------------------------------------------------------------------*/
1632 typedef struct _toolbarstruct *toolbarptr;
1634 typedef struct _toolbarstruct {
1635 char *name;
1636 char **icon_data;
1637 XtCallbackProc func;
1638 void *passeddata;
1639 char *hint;
1640 } toolbarstruct;
1642 #endif
1643 /* Menus and Toolbars are taken care of entirely by scripts in the Tcl/ */
1644 /* Tk version of xcircuit. */
1645 /*----------------------------------------------------------------------*/