1 /*!
2  * \file src/global.h
3  *
4  * \brief Definition of types.
5  *
6  * <hr>
7  *
8  * <h1><b>Copyright.</b></h1>\n
9  *
10  * PCB, interactive printed circuit board design
11  *
12  * Copyright (C) 1994,1995,1996, 2004 Thomas Nau
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
27  *
28  * Contact addresses for paper mail and Email:
29  * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
30  * Thomas.Nau@rz.uni-ulm.de
31  *
32  * <hr>
33  *
34  * Change History:
35  *
36  * 10/11/96 11:37 AJF Added support for a Text() driver function.
37  * This was done out of a pressing need to force text to be printed on the
38  * silkscreen layer. Perhaps the design is not the best.
39  */
40 
41 #ifndef	PCB_GLOBAL_H
42 #define	PCB_GLOBAL_H
43 
44 #ifdef HAVE_CONFIG_H
45 #include "config.h"
46 #endif
47 
48 #include "const.h"
49 #include "macro.h"
50 
51 #include "flags.h"
52 
53 #include <locale.h>
54 #ifdef HAVE_STDINT_H
55 #include <stdint.h>
56 #endif
57 #include <stdio.h>
58 #include <stdlib.h>
59 #include <string.h>
60 #include <strings.h>
61 #include <stdarg.h>
62 #include <math.h>
63 #include <ctype.h>
64 #include <sys/types.h>
65 #include <stdbool.h>
66 #include <glib.h>
67 
68 /* Forward declarations for structures the HIDs need.  */
69 typedef struct BoxType BoxType;
70 typedef struct polygon_st PolygonType;
71 typedef struct pad_st PadType;
72 typedef struct pin_st PinType;
73 typedef struct rtree rtree_t;
74 typedef struct AttributeListType AttributeListType;
75 
76 typedef struct unit Unit;
77 typedef struct increments Increments;
78 
79 typedef COORD_TYPE Coord;	/*!< pcb base unit. */
80 typedef double Angle;		/*!< Degrees. */
81 
82 #include "hid.h"
83 #include "polyarea.h"
84 
85 /* Internationalization support. */
86 #include "gettext.h"
87 
88 #if defined (ENABLE_NLS)
89 /* When an empty string is used for msgid, the functions may return a nonempty
90    string. */
91 # define _(S) (S[0] != '\0') ? gettext(S) : S
92 # define N_(S) gettext_noop(S)
93 # define C_(C, S) pgettext(C, S)
94 #else
95 # define _(S) S
96 # define N_(S) S
97 # define C_(C, S) S
98 #endif /* ENABLE_NLS */
99 
100 /*!
101  * \brief This is used by the lexer/parser.
102  */
103 typedef struct {
104   int ival;
105   Coord bval;
106   double dval;
107   char has_units;
108 } PLMeasure;
109 
110 #ifndef XtSpecificationRelease
111 typedef unsigned int Cardinal;
112 /*typedef unsigned int	Pixel;*/
113 typedef char *String;
114 typedef short Position;
115 typedef short Dimension;
116 #endif
117 typedef unsigned char BYTE;
118 
119 
120 
121 #ifndef __GNUC__
122 #define __FUNCTION1(a,b) a ":" #b
123 #define __FUNCTION2(a,b) __FUNCTION1(a,b)
124 #define __FUNCTION__ __FUNCTION2(__FILE__,__LINE__)
125 #endif
126 
127 
128 /* ---------------------------------------------------------------------------
129  * Macros to annotate branch-prediction information.
130  * Taken from GLib 2.16.3 (LGPL 2).G_ / g_ prefixes have
131  * been removed to avoid namespace clashes.
132  */
133 
134 /* The LIKELY and UNLIKELY macros let the programmer give hints to
135  * the compiler about the expected result of an expression. Some compilers
136  * can use this information for optimizations.
137  *
138  * The PCB_BOOLEAN_EXPR macro is intended to trigger a gcc warning when
139  * putting assignments inside the test.
140  */
141 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
142 #define PCB_BOOLEAN_EXPR(expr)                   \
143  __extension__ ({                             \
144    int _boolean_var_;                         \
145    if (expr)                                  \
146       _boolean_var_ = 1;                      \
147    else                                       \
148       _boolean_var_ = 0;                      \
149    _boolean_var_;                             \
150 })
151 #define LIKELY(expr) (__builtin_expect (PCB_BOOLEAN_EXPR(expr), 1))
152 #define UNLIKELY(expr) (__builtin_expect (PCB_BOOLEAN_EXPR(expr), 0))
153 #else
154 #define LIKELY(expr) (expr)
155 #define UNLIKELY(expr) (expr)
156 #endif
157 
158 
159 /* ---------------------------------------------------------------------------
160  * Do not change the following definitions even if they're not very
161  * nice.  It allows us to have functions act on these "base types" and
162  * not need to know what kind of actual object they're working on.
163  */
164 
165 /* Any object that uses the "object flags" defined in const.h, or
166    exists as an object on the pcb, MUST be defined using this as the
167    first fields, either directly or through ANYLINEFIELDS.  */
168 #define ANYOBJECTFIELDS			\
169 	BoxType		BoundingBox;	\
170 	long int	ID;		\
171 	FlagType	Flags;		\
172 	//	struct LibraryEntryType *net
173 
174 /* Lines, pads, and rats all use this so they can be cross-cast.  */
175 #define	ANYLINEFIELDS			\
176 	ANYOBJECTFIELDS;		\
177 	Coord		Thickness,      \
178                         Clearance;      \
179 	PointType	Point1,		\
180 			Point2
181 
182 /* ---------------------------------------------------------------------------
183  * some useful values of our widgets
184  */
185 
186 /*!
187  * \brief Holds information about output window.
188  */
189 typedef struct
190 {
191   hidGC bgGC, /*!< Background; changed from some routines. */
192     fgGC, /*!< Foreground; changed from some routines. */
193     pmGC; /*!< Depth 1 pixmap GC to store clip. */
194 }
195 OutputType;
196 
197 /*!
198  * \brief Layer group.
199  *
200  * A layer group identifies layers which are always switched on/off
201  * together.
202  */
203 typedef struct
204 {
205   Cardinal Number[MAX_GROUP], /*!< Number of entries per groups. */
206     Entries[MAX_GROUP][MAX_ALL_LAYER];
207 } LayerGroupType;
208 
209 /*!
210  * \brief A bounding box.
211  */
212 struct BoxType
213 {
214   Coord X1, Y1; /*!< Upper left corner. */
215   Coord X2, Y2; /*!< Lower right corner. */
216 };
217 
218 typedef struct
219 {
220   Coord x, y;
221   Coord width, height;
222 } RectangleType;
223 
224 typedef struct
225 {
226   char *name;
227   char *value;
228 } AttributeType;
229 
230 struct AttributeListType
231 {
232   int Number, Max;
233   AttributeType *List;
234 };
235 
236 /* ---------------------------------------------------------------------------
237  * the basic object types supported by PCB
238  */
239 
240 /*!
241  * \brief All on-pcb objects (elements, lines, pads, vias, rats, etc)
242  * are based on this.
243  */
244 typedef struct {
245   ANYOBJECTFIELDS;
246 } AnyObjectType;
247 
248 /*!
249  * \brief A line/polygon point.
250  */
251 typedef struct
252 {
253   Coord X, Y, X2, Y2; /*!< So Point type can be cast as BoxType. */
254   long int ID;
255 } PointType;
256 
257 /*!
258  * \brief Lines, rats, pads, etc.
259  */
260 typedef struct {
261   ANYLINEFIELDS;
262 } AnyLineObjectType;
263 
264 /*!
265  * \brief Holds information about one line.
266  */
267 typedef struct
268 {
269   ANYLINEFIELDS;
270   char *Number;
271 } LineType;
272 
273 typedef struct
274 {
275   ANYOBJECTFIELDS;
276   int Scale; /*!< Text scaling in percent. */
277   Coord X; /*!< X-coordinate of origin. */
278   Coord Y; /*!< Y-coordinate of origin. */
279   BYTE Direction;
280   char *TextString; /*!< String. */
281   void *Element;
282 } TextType;
283 
284 /*!
285  * \brief Holds information about a polygon.
286  */
287 struct polygon_st
288 {
289   ANYOBJECTFIELDS;
290   Cardinal PointN; /*!< Number of points in polygon. */
291   Cardinal PointMax; /*!< Max number from malloc(). */
292   POLYAREA *Clipped; /*!< The clipped region of this polygon. */
293   PLINE *NoHoles; /*!< The polygon broken into hole-less regions */
294   int NoHolesValid; /*!< Is the NoHoles polygon up to date? */
295   PointType *Points; /*!< Data. */
296   Cardinal *HoleIndex; /*!< Index of hole data within the Points array. */
297   Cardinal HoleIndexN; /*!< Number of holes in polygon. */
298   Cardinal HoleIndexMax; /*!< Max number from malloc(). */
299 
300 };
301 
302 /*!
303  * \brief Holds information about arcs.
304  */
305 typedef struct
306 {
307   ANYOBJECTFIELDS;
308   Coord Thickness, Clearance;
309   PointType Point1;
310   PointType Point2;
311   Coord Width; /*!< Length of axis */
312   Coord Height; /*!< Width of axis */
313   Coord X; /*!< X-value of the center coordinates. */
314   Coord Y; /*!< Y-value of the center coordinates. */
315   Angle StartAngle; /*!< The start angle in degrees. */
316   Angle Delta; /*!< The described angle in degrees. */
317 } ArcType;
318 
319 struct rtree
320 {
321   struct rtree_node *root;
322   int size; /*!< Number of entries in tree */
323 };
324 
325 /*!
326  * \brief Holds information about one layer. */
327 typedef struct
328 {
329   LayertypeType Type; /*!< LT_* from hid.h */
330   char *Name; /*!< Layer name. */
331   Cardinal LineN; /*!< Number of lines. */
332   Cardinal TextN; /*!< Labels. */
333   Cardinal PolygonN; /*!< Polygons. */
334   Cardinal ArcN; /*!< Arcs. */
335   GList *Line;
336   GList *Text;
337   GList *Polygon;
338   GList *Arc;
339   rtree_t *line_tree, *text_tree, *polygon_tree, *arc_tree;
340   bool On; /*!< Visible flag. */
341   char *Color, /*!< Color. */
342    *SelectedColor;
343   AttributeListType Attributes;
344   int no_drc; /*!< Whether to ignore the layer when checking the design
345     rules */
346 }
347 LayerType;
348 
349 /*!
350  * \brief A rat line.
351  */
352 typedef struct
353 {
354   ANYLINEFIELDS;
355   Cardinal group1; /*!< The layer group each point is on. */
356   Cardinal group2; /*!< The layer group each point is on. */
357 } RatType;
358 
359 /*!
360  * \brief A SMD pad.
361  */
362 struct pad_st
363 {
364   ANYLINEFIELDS;
365   Coord Mask;
366   char *Name, *Number; /*!< 'Line'. */
367   void *Element;
368   void *Spare;
369 };
370 
371 /*!
372  * \brief A pin.
373  */
374 struct pin_st
375 {
376   ANYOBJECTFIELDS;
377   Coord Thickness;
378   Coord Clearance;
379   Coord Mask;
380   Coord DrillingHole; /*!< Diameter of the drill hole. */
381   Coord X; /*!< X-value of the center coordinates. */
382   Coord Y; /*!< Y-value of the center coordinates. */
383   char *Name;
384   char *Number;
385   void *Element;
386   void *Spare;
387   Cardinal BuriedFrom;
388   Cardinal BuriedTo;
389 };
390 
391 /* This is the extents of a Pin or Via, depending on whether it's a
392    hole or not.  */
393 #define PIN_SIZE(pinptr) (TEST_FLAG(HOLEFLAG, (pinptr)) \
394 			  ? (pinptr)->DrillingHole \
395 			  : (pinptr)->Thickness)
396 
397 /*!
398  * \brief An element.
399  */
400 typedef struct
401 {
402   ANYOBJECTFIELDS;
403   TextType Name[MAX_ELEMENTNAMES];
404     /*!< The elements names;
405      * - description text,
406      * - name on PCB second,
407      * - value third.
408      * see macro.h.
409      */
410   Coord MarkX; /*!< X-value of the position mark. */
411   Coord MarkY; /*!< Y-value of the position mark. */
412   Cardinal PinN; /*!< Number of pins. */
413   Cardinal PadN; /*!< Number of pads. */
414   Cardinal LineN; /*!< Number of lines. */
415   Cardinal ArcN; /*!< Number of arcs. */
416   GList *Pin;
417   GList *Pad;
418   GList *Line;
419   GList *Arc;
420   BoxType VBox;
421   AttributeListType Attributes;
422 } ElementType;
423 
424 /* ---------------------------------------------------------------------------
425  * symbol and font related stuff
426  */
427 /*!
428  * \brief A single symbol.
429  */
430 typedef struct
431 {
432   LineType *Line;
433   bool Valid;
434   Cardinal LineN; /*!< Number of lines. */
435   Cardinal LineMax;
436   Coord Width; /*!< Width of cell. */
437   Coord Height; /*!< Height of cell. */
438   Coord Delta; /*!< Distance to next symbol. */
439 } SymbolType;
440 
441 /*!
442  * \brief Complete set of symbols.
443  */
444 typedef struct
445 {
446   Coord MaxHeight; /*!< Maximum cell width. */
447   Coord MaxWidth; /*!< Maximum cell height. */
448   BoxType DefaultSymbol; /*!< The default symbol is a filled box. */
449   SymbolType Symbol[MAX_FONTPOSITION + 1];
450   bool Valid;
451 } FontType;
452 
453 /*!
454  * \brief Holds all objects.
455  */
456 typedef struct
457 {
458   Cardinal ViaN; /*!< Number of vias. */
459   Cardinal ElementN; /*!< Number of elements. */
460   Cardinal RatN; /*!< Number of rat-lines. */
461   int LayerN; /*!< Number of layers in this board. */
462   GList *Via;
463   GList *Element;
464   GList *Rat;
465   rtree_t *via_tree, *element_tree, *pin_tree, *pad_tree, *name_tree[3],	/* for element names */
466    *rat_tree;
467   struct PCBType *pcb;
468   LayerType Layer[MAX_ALL_LAYER];
469   int polyClip;
470 } DataType;
471 
472 /*!
473  * \brief Holds drill information.
474  */
475 typedef struct
476 {
477   Coord DrillSize; /*!< This drill's diameter. */
478   Cardinal ElementN; /*!< The number of elements using this drill size. */
479   Cardinal ElementMax; /*!< Max. number of elements from malloc(). */
480   Cardinal PinCount; /*!< Number of pins drilled this size. */
481   Cardinal ViaCount; /*!< Number of vias drilled this size. */
482   Cardinal UnplatedCount; /*!< Number of these holes that are unplated. */
483   Cardinal PinN; /*!< Number of drill coordinates in the list. */
484   Cardinal PinMax; /*!< Max. number of coordinates from malloc(). */
485   PinType **Pin; /*!< Coordinates to drill. */
486   ElementType **Element; /*!< A pointer to an array of element pointers. */
487 } DrillType;
488 
489 /*!
490  * \brief Holds a range of Drill Infos.
491  */
492 typedef struct
493 {
494   Cardinal DrillN; /*!< Number of drill sizes. */
495   Cardinal DrillMax; /*!< Max. number from malloc(). */
496   DrillType *Drill; /*!< Plated holes. */
497 } DrillInfoType;
498 
499 typedef struct
500 {
501   Coord Thick; /*!< Line thickness. */
502   Coord Diameter; /*!< Via diameter. */
503   Coord Hole; /*!< Via drill hole. */
504   Coord ViaMask; /*!< Solder mask clearance. */
505   Coord Keepaway; /*!< Min. separation from other nets. */
506   char *Name;
507   int index;
508 } RouteStyleType;
509 
510 /*!
511  * \brief Structure used by library routines.
512  */
513 typedef struct
514 {
515   char *ListEntry; /*!< The string for the selection box. */
516   char *AllocatedMemory; /*!< Pointer to allocated memory;
517     all others point to parts of the string. */
518   char *Template; /*!< m4 template name. */
519   char *Package; /*!< Package. */
520   char *Value; /*!< The value field. */
521   char *Description; /*!< Some descriptional text. */
522 } LibraryEntryType;
523 
524 /*!
525  * \brief .
526  *
527  * If the internal flag is set, the only field that is valid is Name,
528  * and the struct is allocated with malloc instead of
529  * CreateLibraryEntry.  These "internal" entries are used for
530  * electrical paths that aren't yet assigned to a real net.
531  */
532 typedef struct
533 {
534   char *Name; /*!< Name of the menu entry. */
535   char *directory; /*!< Directory name library elements are from. */
536   char *Style; /*!< Routing style. */
537   Cardinal EntryN; /*!< Number of objects. */
538   Cardinal EntryMax; /*!< Number of reserved memory locations. */
539   LibraryEntryType *Entry; /*!< The entries. */
540   char flag; /*!< Used by the netlist window to enable/disable nets. */
541   char internal; /*!< If set, this is an internal-only entry, not
542                   * part of the global netlist. */
543 } LibraryMenuType;
544 
545 typedef struct
546 {
547   Cardinal MenuN; /*!< Number of objects. */
548   Cardinal MenuMax; /*!< Number of reserved memory locations. */
549   LibraryMenuType *Menu; /*!< The entries. */
550 } LibraryType;
551 
552 
553 /*!
554  * \brief The PCBType struct holds information about board layout most
555  * of which is saved with the layout.
556  *
557  * A new PCB layout struct is first initialized with values from the
558  * user configurable \c Settings struct and then reset to the saved
559  * layout values when a layout is loaded.
560  *
561  * This struct is also used for the remove list and for buffer handling.
562  */
563 typedef struct PCBType
564 {
565   long ID; /*!< See macro.h. */
566   FlagType Flags;
567   char *Name, /*!< Name of board. */
568    *Filename, /*!< Name of file (from load). */
569    *PrintFilename, /*!< From print dialog. */
570    *Netlistname, /*!< Name of netlist file. */
571     ThermStyle; /*!< Type of thermal to place with thermal tool. */
572   bool Changed, /*!< Layout has been changed. */
573     ViaOn, /*!< Visibility flag for vias. */
574     ElementOn, /*!< Visibility flag for elements. */
575     RatOn, /*!< Visibility flag for rat lines. */
576     InvisibleObjectsOn,
577     PinOn, /*!< Visibility flag for pins. */
578     SilkActive, /*!< Active layer is actually silk. */
579     RatDraw; /*!< We're drawing rats. */
580   char *ViaColor, /*!< Via color. */
581    *ViaSelectedColor, /*!< Selected via color. */
582     *PinColor, /*!< Pin color. */
583     *PinSelectedColor, /*!< Selected pin color. */
584     *PinNameColor, /*!< Pin name color. */
585     *ElementColor, /*!< Element color. */
586     *RatColor, /*!< Rat line color. */
587     *InvisibleObjectsColor, /*!< Invisible objects color. */
588     *InvisibleMarkColor, /*!< Invisible mark color. */
589     *ElementSelectedColor, /*!< Selected elements color. */
590     *RatSelectedColor, /*!< Selected rat line color. */
591     *ConnectedColor, /*!< Connected color. */
592     *FoundColor, /*!< Found color. */
593     *WarnColor, /*!< Warning color. */
594     *MaskColor; /*!< Mask color. */
595   long CursorX, /*!< Cursor position as saved with layout (X value). */
596     CursorY, /*!< Cursor position as saved with layout (Y value). */
597     Clipping;
598   Coord Bloat, /*!< DRC bloat size saved with layout. */
599     Shrink, /*!< DRC shrink size saved with layout. */
600     minWid, /*!< DRC minimum width size saved with layout. */
601     minSlk, /*!< DRC minimum silk size saved with layout. */
602     minDrill, /*!< DRC minimum drill size saved with layout. */
603     minRing; /*!< DRC minimum annular ring size saved with layout. */
604   Coord GridOffsetX, /*!< As saved with layout (X value). */
605     GridOffsetY, /*!< As saved with layout (Y value). */
606     MaxWidth, /*!< Maximum allowed width size. */
607     MaxHeight; /*!< Maximum allowed height size. */
608 
609   Coord Grid; /*!< Used grid with offsets. */
610   double IsleArea, /*!< Minimum poly island to retain. */
611     ThermScale; /*!< Scale factor used with thermals. */
612   FontType Font;
613   LayerGroupType LayerGroups;
614   RouteStyleType RouteStyle[NUM_STYLES];
615   LibraryType NetlistLib;
616   AttributeListType Attributes;
617   DataType *Data; /*!< Entire database. */
618 
619   bool is_footprint; /*!< If set, the user has loaded a footprint, not a pcb. */
620 }
621 PCBType;
622 
623 /*!
624  * \brief Information about the paste buffer.
625  */
626 typedef struct
627 {
628   Coord X; /*!< Offset (X value). */
629   Coord Y; /*!< Offset (Y value). */
630   BoxType BoundingBox;
631   DataType *Data; /*!< Data; not all members of PCBType are used. */
632 } BufferType;
633 
634 /* ---------------------------------------------------------------------------
635  * some types for cursor drawing, setting of block and lines
636  * as well as for merging of elements
637  */
638 
639 /*!
640  * \brief Rubberband lines for element moves.
641  */
642 typedef struct
643 {
644   LayerType *Layer; /*!< Layer that holds the line. */
645   LineType *Line; /*!< The line itself. */
646   PointType *MovedPoint; /*!< And finally the point. */
647 } RubberbandType;
648 
649 /*!
650  * \brief Current marked line.
651  */
652 typedef struct
653 {
654   PointType Point1; /*!< Start position. */
655   PointType Point2; /*!< End position. */
656   long int State;
657   bool draw;
658 } AttachedLineType;
659 
660 /*!
661  * \brief Currently marked block.
662  */
663 typedef struct
664 {
665   PointType Point1; /*!< Start position. */
666   PointType Point2; /*!< End position. */
667   long int State;
668   bool otherway;
669 } AttachedBoxType;
670 
671 /*!
672  * \brief Currently attached object.
673  */
674 typedef struct
675 {
676   Coord X; /*!< Saved position when MOVE_MODE (X value). */
677   Coord Y; /*!< Saved position when MOVE_MODE (Y value). */
678   BoxType BoundingBox;
679   long int Type, /*!< Object type. */
680     State;
681   void *Ptr1; /*!< Pointer to data, see search.c. */
682   void *Ptr2; /*!< Pointer to data, see search.c. */
683   void *Ptr3; /*!< Pointer to data, see search.c. */
684   Cardinal RubberbandN, /*!< Number of lines in array. */
685     RubberbandMax;
686   RubberbandType *Rubberband;
687 } AttachedObjectType;
688 
689 enum crosshair_shape
690 {
691   Basic_Crosshair_Shape = 0,  /*!< 4-ray. */
692   Union_Jack_Crosshair_Shape, /*!< 8-ray. */
693   Dozen_Crosshair_Shape,      /*!< 12-ray. */
694   Crosshair_Shapes_Number
695 };
696 
697 /*!
698  * \brief Holds cursor information.
699  */
700 typedef struct
701 {
702   hidGC GC; /*!< GC for cursor drawing. */
703   hidGC AttachGC; /*!< GC for displaying buffer contents. */
704   Coord X; /*!< Position in PCB coordinates (X value). */
705   Coord Y; /*!< Position in PCB coordinates (Y value). */
706   Coord MinX; /*!< Lowest coordinates (X value). */
707   Coord MinY; /*!< Lowest coordinates (Y value). */
708   Coord MaxX; /*!< Highest coordinates (X value). */
709   Coord MaxY; /*!< Highest coordinates (Y value). */
710   AttachedLineType AttachedLine; /*!< Data of new lines. */
711   AttachedBoxType AttachedBox;
712   PolygonType AttachedPolygon;
713   AttachedObjectType AttachedObject; /*!< Data of attached objects. */
714   enum crosshair_shape shape; /*!< Shape of Crosshair. */
715 } CrosshairType;
716 
717 typedef struct
718 {
719   bool status;
720   Coord X, Y;
721 } MarkType;
722 
723 /*!
724  * \brief Our resources.
725  *
726  * Most of them are used as default when a new design is started.
727  */
728 typedef struct
729 {
730   const Unit *grid_unit;
731   Increments *increments;
732 
733   int verbose;
734 
735   char *BlackColor,
736     *WhiteColor,
737     *BackgroundColor, /*!< Background color. */
738     *CrosshairColor, /*!< Crosshair color. */
739     *CrossColor, /*!< Cross color. */
740     *ViaColor, /*!< Via color. */
741     *ViaSelectedColor, /*!< Selected via color. */
742     *PinColor, /*!< Pin color. */
743     *PinSelectedColor, /*!< Selected pin color. */
744     *PinNameColor, /*!< Pin name color. */
745     *ElementColor, /*!< Element color. */
746     *RatColor, /*!< Rat color. */
747     *InvisibleObjectsColor, /*!< Invisible objects color. */
748     *InvisibleMarkColor, /*!< Invisible mark color. */
749     *ElementSelectedColor, /*!< Selected element color. */
750     *RatSelectedColor, /*!< Selected rat color. */
751     *ConnectedColor, /*!< Connected color. */
752     *FoundColor, /*!< Found color. */
753     *OffLimitColor,
754     *GridColor, /*!< Grid color. */
755     *LayerColor[MAX_LAYER],
756     *LayerSelectedColor[MAX_LAYER],
757     *WarnColor, /*!< Warning color. */
758     *MaskColor; /*!< Mask color. */
759   Coord ViaThickness, /*!< Default via thickness value. */
760     ViaDrillingHole, /*!< Default via drill hole value. */
761     ViaMaskAperture, /*!< Default solder mask aperture value. */
762     LineThickness, /*!< Default line thickness value. */
763     RatThickness, /*!< Default rat thickness value. */
764     Keepaway, /*!< Default keepaway value. */
765     MaxWidth, /*!< Default size of a new layout (X value). */
766     MaxHeight, /*!< Default size of a new layout (Y value). */
767     AlignmentDistance,
768     Bloat, /*!< Default drc size for bloat. */
769     Shrink, /*!< Default drc size for shrink. */
770     minWid, /*!< Default drc size for minimum trace width. */
771     minSlk, /*!< Default drc size for minumum silk width. */
772     minDrill, /*!< Default drc size for minimum drill size. */
773     minRing; /*!< Default drc size for minimum annular ring. */
774   int TextScale; /*!< Text scaling in %. */
775   Coord Grid; /*!< Grid in pcb-units. */
776   double IsleArea; /*!< Polygon min area. */
777   Coord PasteAdjust; /*!< Paste adjustment. */
778   int PinoutNameLength, /*!< Max displayed length of a pinname. */
779     Volume, /*!< The speakers volume -100 .. 100. */
780     CharPerLine, /*!< Width of an output line in characters. */
781     Mode, /*!< Currently active mode. */
782     BufferNumber; /*!< Number of the current buffer. */
783   int BackupInterval; /*!< Time between two backups in seconds. */
784   char *DefaultLayerName[MAX_LAYER],
785    *FontCommand, /*!< Command for font file loading. */
786    *FileCommand, /*!< Command for file loading. */
787    *ElementCommand, /*!< Command for element file loading. */
788    *PrintFile,
789    *LibraryCommandDir,
790    *LibraryCommand,
791    *LibraryContentsCommand,
792    *LibraryTree, /*!< Path to library tree. */
793    *SaveCommand,
794    *LibraryFilename,
795    *FontFile, /*!< Name of default font file. */
796    *Groups, /*!< String with layergroups. */
797    *Routes, /*!< String with route styles. */
798    *FilePath,
799    *RatPath,
800    *RatCommand,
801    *FontPath,
802    *PinoutFont,
803    *ElementPath,
804    *LibraryPath,
805    *Size, /*!< Geometry string for size. */
806    *BackgroundImage, /*!< PPM file for board background. */
807    *ScriptFilename, /*!< PCB Actions script to execute on startup. */
808    *ActionString, /*!< PCB Actions string to execute on startup. */
809    *FabAuthor, /*!< Full name of author for FAB drawings. */
810    *GnetlistProgram, /*!< gnetlist program name. */
811    *MakeProgram, /*!< make program name. */
812    *InitialLayerStack; /*!< If set, the initial layer stack is set to this. */
813   Coord PinoutOffsetX; /*!< Offset of origin (X value). */
814   Coord PinoutOffsetY; /*!< Offset of origin (Y value). */
815   Coord PinoutTextOffsetX; /*!< Offset of text from pin center (X value). */
816   Coord PinoutTextOffsetY; /*!< Offset of text from pin center (Y value). */
817   RouteStyleType RouteStyle[NUM_STYLES]; /*!< Default routing styles. */
818   LayerGroupType LayerGroups; /*!< Default layer groups. */
819   bool ClearLine,
820     FullPoly,
821     UniqueNames, /*!< Force unique names. */
822     SnapPin, /*!< Snap to pins and pads. */
823     ShowBottomSide, /*!< Mirror output. */
824     SaveLastCommand, /*!< Save the last command entered by user. */
825     SaveInTMP, /*!< Always save data in /tmp. */
826     SaveMetricOnly, /*!< Save with mm suffix only, not mil/mm hybrid. */
827     DrawGrid, /*!< Draw grid points. */
828     RatWarn, /*!< Rats nest has set warnings. */
829     StipplePolygons, /*!< Draw polygons with stipple. */
830     AllDirectionLines, /*!< Enable lines to all directions. */
831     RubberBandMode, /*!< Move, rotate use rubberband connections. */
832     SwapStartDirection,/*!< Change starting direction after each click. */
833     ShowDRC, /*!< Show drc region on crosshair. */
834     AutoDRC, /*!< . */
835     ShowNumber, /*!< Pinout shows number. */
836     OrthogonalMoves, /*!< . */
837     ResetAfterElement, /*!< Reset connections after each element. */
838     liveRouting, /*!< Autorouter shows tracks in progress. */
839     AutoBuriedVias,
840     RingBellWhenFinished,
841       /*!< flag if a signal should be produced when searching of
842        * connections is done. */
843     AutoPlace;
844       /*!< Flag which says we should force placement of the windows on
845        * startup. */
846 }
847 SettingType;
848 
849 /*!
850  * \brief Pointer to low-level copy, move and rotate functions.
851  */
852 typedef struct
853 {
854   void *(*Line) (LayerType *, LineType *);
855   void *(*Text) (LayerType *, TextType *);
856   void *(*Polygon) (LayerType *, PolygonType *);
857   void *(*Via) (PinType *);
858   void *(*Element) (ElementType *);
859   void *(*ElementName) (ElementType *);
860   void *(*Pin) (ElementType *, PinType *);
861   void *(*Pad) (ElementType *, PadType *);
862   void *(*LinePoint) (LayerType *, LineType *, PointType *);
863   void *(*Point) (LayerType *, PolygonType *, PointType *);
864   void *(*Arc) (LayerType *, ArcType *);
865   void *(*Rat) (RatType *);
866 } ObjectFunctionType;
867 
868 /* ---------------------------------------------------------------------------
869  * structure used by device drivers
870  */
871 
872 
873 /*!
874  * \brief Holds a connection.
875  */
876 typedef struct
877 {
878   Coord X; /*!< Coordinate of connection (X value). */
879   Coord Y; /*!< Coordinate of connection (Y value). */
880   long int type; /*!< Type of object in ptr1 - 3. */
881   void *ptr1; /*!< The object of the connection. */
882   void *ptr2; /*!< The object of the connection. */
883   Cardinal group; /*!< The layer group of the connection. */
884   LibraryMenuType *menu; /*!< The netmenu this *SHOULD* belong to. */
885 } ConnectionType;
886 
887 /*!
888  * \brief Holds a net of connections.
889  */
890 typedef struct
891 {
892   Cardinal ConnectionN; /*!< The number of connections contained. */
893   Cardinal ConnectionMax; /*!< Max connections from malloc. */
894   ConnectionType *Connection;
895   RouteStyleType *Style;
896 } NetType;
897 
898 /*!
899  * \brief Holds a list of nets.
900  */
901 typedef struct
902 {
903   Cardinal NetN; /*!< The number of subnets contained. */
904   Cardinal NetMax; /*!< Max subnets from malloc. */
905   NetType *Net;
906 } NetListType;
907 
908 /*!
909  * \brief Holds a list of net lists.
910  */
911 typedef struct
912 {
913   Cardinal NetListN; /*!< The number of net lists contained. */
914   Cardinal NetListMax; /*!< Max net lists from malloc. */
915   NetListType *NetList;
916 } NetListListType;
917 
918 /*!
919  * \brief Holds a generic list of pointers.
920  */
921 typedef struct
922 {
923   Cardinal PtrN; /*!< The number of pointers contained. */
924   Cardinal PtrMax; /*!< Max subnets from malloc. */
925   void **Ptr;
926 } PointerListType;
927 
928 typedef struct
929 {
930   Cardinal BoxN; /*!< The number of boxes contained. */
931   Cardinal BoxMax; /*!< Max boxes from malloc. */
932   BoxType *Box;
933 } BoxListType;
934 
935 
936 /* ---------------------------------------------------------------------------
937  * define supported types of undo operations
938  * note these must be separate bits now
939  */
940 #define	UNDO_CHANGENAME			0x0001	/*!< Change of names. */
941 #define	UNDO_MOVE			0x0002	/*!< Moving objects. */
942 #define	UNDO_REMOVE			0x0004	/*!< Removing objects. */
943 #define	UNDO_REMOVE_POINT		0x0008	/*!< Removing polygon/... points. */
944 #define	UNDO_INSERT_POINT		0x0010	/*!< Inserting polygon/... points. */
945 #define	UNDO_REMOVE_CONTOUR		0x0020	/*!< Removing a contour from a polygon. */
946 #define	UNDO_INSERT_CONTOUR		0x0040	/*!< Inserting a contour from a polygon. */
947 #define	UNDO_ROTATE			0x0080	/*!< Rotations. */
948 #define	UNDO_CREATE			0x0100	/*!< Creation of objects. */
949 #define	UNDO_MOVETOLAYER		0x0200	/*!< Moving objects to. */
950 #define	UNDO_FLAG			0x0400	/*!< Toggling SELECTED flag. */
951 #define	UNDO_CHANGESIZE			0x0800	/*!< Change size of object. */
952 #define	UNDO_CHANGE2NDSIZE		0x1000	/*!< Change 2ndSize of object. */
953 #define	UNDO_MIRROR			0x2000	/*!< Change side of board. */
954 #define	UNDO_CHANGECLEARSIZE		0x4000	/*!< Change clearance size. */
955 #define	UNDO_CHANGEMASKSIZE		0x8000	/*!< Change mask size. */
956 #define	UNDO_CHANGEANGLES	       0x10000	/*!< Change arc angles. */
957 #define	UNDO_LAYERCHANGE	       0x20000	/*!< Layer new/delete/move. */
958 #define	UNDO_CLEAR		       0x40000	/*!< Clear/restore to polygons. */
959 #define	UNDO_NETLISTCHANGE	       0x80000	/*!< Netlist change. */
960 #define UNDO_CHANGESETVIALAYERS        0x100000  /*!< Buried data change. */
961 /* ---------------------------------------------------------------------------
962  */
963 #if (__GNUC__ * 1000 + __GNUC_MINOR__) > 2007
964 #define ATTRIBUTE_UNUSED __attribute__((unused))
965 #else
966 #define ATTRIBUTE_UNUSED
967 #endif
968 
969 /* ---------------------------------------------------------------------------
970  * Macros called by various action routines to show usage or to report
971  * a syntax error and fail
972  */
973 #define AUSAGE(x) Message (_("Usage:\n%s\n"), _(x##_syntax))
974 #define AFAIL(x) { Message (_("Syntax error.  Usage:\n%s\n"), _(x##_syntax)); return 1; }
975 
976 /* ---------------------------------------------------------------------------
977  * Variables with absolute paths to various directories.  These are deduced
978  * at runtime to allow pcb to be relocatable
979  */
980 extern char *bindir;       /*!< The dir in which PCB installation was found. */
981 extern char *pcblibdir;    /*!< The system M4 fp directory. */
982 extern char *pcblibpath;   /*!< The search path for M4 fps. */
983 extern char *pcbtreedir;   /*!< The system newlib fp directory. */
984 extern char *pcbtreepath;  /*!< The search path for newlib fps. */
985 extern char *exec_prefix;
986 extern char *homedir;
987 
988 #endif /* PCB_GLOBAL_H  */
989