4 * PCB, interactive printed circuit board design
5 * Copyright (C) 1994,1995,1996, 2004 Thomas Nau
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * Contact addresses for paper mail and Email:
22 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
23 * Thomas.Nau@rz.uni-ulm.de
27 /* definition of types
31 * 10/11/96 11:37 AJF Added support for a Text() driver function.
32 * This was done out of a pressing need to force text to be printed on the
33 * silkscreen layer. Perhaps the design is not the best.
56 #include <sys/types.h>
60 /* Forward declarations for structures the HIDs need. */
61 typedef struct BoxType BoxType
;
62 typedef struct polygon_st PolygonType
;
63 typedef struct pad_st PadType
;
64 typedef struct pin_st PinType
;
65 typedef struct drc_violation_st DrcViolationType
;
66 typedef struct rtree rtree_t
;
67 typedef struct AttributeListType AttributeListType
;
69 typedef struct unit Unit
;
70 typedef struct increments Increments
;
72 typedef COORD_TYPE Coord
; /* pcb base unit */
73 typedef double Angle
; /* degrees */
78 /* Internationalization support. */
81 # define _(S) gettext(S)
82 # if defined(gettext_noop)
83 # define N_(S) gettext_noop(S)
90 # define textdomain(S) (S)
91 # define gettext(S) (S)
92 # define dgettext(D, S) (S)
93 # define dcgettext(D, S, T) (S)
94 # define bindtextdomain(D, Dir) (D)
95 #endif /* ENABLE_NLS */
97 /* This is used by the lexer/parser */
105 #ifndef XtSpecificationRelease
106 typedef unsigned int Cardinal
;
107 /*typedef unsigned int Pixel;*/
108 typedef char *String
;
109 typedef short Position
;
110 typedef short Dimension
;
112 typedef unsigned char BYTE
;
114 /* Nobody should know about the internals of this except the macros in
115 macros.h that access it. This structure must be simple-assignable
119 unsigned long f
; /* generic flags */
120 unsigned char t
[(MAX_LAYER
+ 1) / 2]; /* thermals */
124 #define __FUNCTION1(a,b) a ":" #b
125 #define __FUNCTION2(a,b) __FUNCTION1(a,b)
126 #define __FUNCTION__ __FUNCTION2(__FILE__,__LINE__)
130 /* ---------------------------------------------------------------------------
131 * Macros to annotate branch-prediction information.
132 * Taken from GLib 2.16.3 (LGPL 2).G_ / g_ prefixes have
133 * been removed to avoid namespace clashes.
136 /* The LIKELY and UNLIKELY macros let the programmer give hints to
137 * the compiler about the expected result of an expression. Some compilers
138 * can use this information for optimizations.
140 * The PCB_BOOLEAN_EXPR macro is intended to trigger a gcc warning when
141 * putting assignments inside the test.
143 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
144 #define PCB_BOOLEAN_EXPR(expr) \
153 #define LIKELY(expr) (__builtin_expect (PCB_BOOLEAN_EXPR(expr), 1))
154 #define UNLIKELY(expr) (__builtin_expect (PCB_BOOLEAN_EXPR(expr), 0))
156 #define LIKELY(expr) (expr)
157 #define UNLIKELY(expr) (expr)
161 /* ---------------------------------------------------------------------------
162 * Do not change the following definitions even if they're not very
163 * nice. It allows us to have functions act on these "base types" and
164 * not need to know what kind of actual object they're working on.
167 /* Any object that uses the "object flags" defined in const.h, or
168 exists as an object on the pcb, MUST be defined using this as the
169 first fields, either directly or through ANYLINEFIELDS. */
170 #define ANYOBJECTFIELDS \
171 BoxType BoundingBox; \
174 // struct LibraryEntryType *net
176 /* Lines, pads, and rats all use this so they can be cross-cast. */
177 #define ANYLINEFIELDS \
184 /* ---------------------------------------------------------------------------
185 * some useful values of our widgets
187 typedef struct /* holds information about output window */
189 hidGC bgGC
, /* background and foreground; */
190 fgGC
, /* changed from some routines */
191 pmGC
; /* depth 1 pixmap GC to store clip */
195 /* ----------------------------------------------------------------------
196 * layer group. A layer group identifies layers which are always switched
201 Cardinal Number
[MAX_LAYER
], /* number of entries per groups */
202 Entries
[MAX_LAYER
][MAX_LAYER
+ 2];
205 struct BoxType
/* a bounding box */
207 Coord X1
, Y1
; /* upper left */
208 Coord X2
, Y2
; /* and lower right corner */
223 struct AttributeListType
229 /* ---------------------------------------------------------------------------
230 * the basic object types supported by PCB
233 /* All on-pcb objects (elements, lines, pads, vias, rats, etc) are
239 typedef struct /* a line/polygon point */
241 Coord X
, Y
, X2
, Y2
; /* so Point type can be cast as BoxType */
245 /* Lines, rats, pads, etc. */
250 typedef struct /* holds information about one line */
259 int Scale
; /* text scaling in percent */
260 Coord X
, Y
; /* origin */
262 char *TextString
; /* string */
266 struct polygon_st
/* holds information about a polygon */
269 Cardinal PointN
, /* number of points in polygon */
270 PointMax
; /* max number from malloc() */
271 POLYAREA
*Clipped
; /* the clipped region of this polygon */
272 PLINE
*NoHoles
; /* the polygon broken into hole-less regions */
273 int NoHolesValid
; /* Is the NoHoles polygon up to date? */
274 PointType
*Points
; /* data */
275 Cardinal
*HoleIndex
; /* Index of hole data within the Points array */
276 Cardinal HoleIndexN
; /* number of holes in polygon */
277 Cardinal HoleIndexMax
; /* max number from malloc() */
281 typedef struct /* holds information about arcs */
284 Coord Thickness
, Clearance
;
287 Coord Width
, Height
, /* length of axis */
288 X
, Y
; /* center coordinates */
289 Angle StartAngle
, Delta
; /* the two limiting angles in degrees */
294 struct rtree_node
*root
;
295 int size
; /* number of entries in tree */
298 typedef struct /* holds information about one layer */
300 char *Name
; /* layer name */
301 Cardinal LineN
, /* number of lines */
303 PolygonN
, /* polygons */
309 rtree_t
*line_tree
, *text_tree
, *polygon_tree
, *arc_tree
;
310 bool On
; /* visible flag */
311 char *Color
, /* color */
313 AttributeListType Attributes
;
314 int no_drc
; /* whether to ignore the layer when checking the design rules */
318 typedef struct /* a rat-line */
321 Cardinal group1
, group2
; /* the layer group each point is on */
324 struct pad_st
/* a SMD pad */
328 char *Name
, *Number
; /* 'Line' */
336 Coord Thickness
, Clearance
, Mask
, DrillingHole
;
337 Coord X
, Y
; /* center and diameter */
343 /* This is the extents of a Pin or Via, depending on whether it's a
345 #define PIN_SIZE(pinptr) (TEST_FLAG(HOLEFLAG, (pinptr)) \
346 ? (pinptr)->DrillingHole \
347 : (pinptr)->Thickness)
352 TextType Name
[MAX_ELEMENTNAMES
]; /* the elements names; */
353 /* description text */
354 /* name on PCB second, */
357 Coord MarkX
, MarkY
; /* position mark */
358 Cardinal PinN
; /* number of pins */
359 Cardinal PadN
; /* number of pads */
360 Cardinal LineN
; /* number of lines */
361 Cardinal ArcN
; /* number of arcs */
367 AttributeListType Attributes
;
370 /* ---------------------------------------------------------------------------
371 * symbol and font related stuff
373 typedef struct /* a single symbol */
377 Cardinal LineN
, /* number of lines */
379 Coord Width
, Height
, /* size of cell */
380 Delta
; /* distance to next symbol */
383 typedef struct /* complete set of symbols */
385 Coord MaxHeight
, /* maximum cell width and height */
387 BoxType DefaultSymbol
; /* the default symbol is a filled box */
388 SymbolType Symbol
[MAX_FONTPOSITION
+ 1];
392 typedef struct /* holds all objects */
394 Cardinal ViaN
, /* number of vias */
395 ElementN
, /* and elements */
396 RatN
; /* and rat-lines */
397 int LayerN
; /* number of layers in this board */
401 rtree_t
*via_tree
, *element_tree
, *pin_tree
, *pad_tree
, *name_tree
[3], /* for element names */
404 LayerType Layer
[MAX_LAYER
+ 2]; /* add 2 silkscreen layers */
408 typedef struct /* holds drill information */
410 Coord DrillSize
; /* this drill's diameter */
411 Cardinal ElementN
, /* the number of elements using this drill size */
412 ElementMax
, /* max number of elements from malloc() */
413 PinCount
, /* number of pins drilled this size */
414 ViaCount
, /* number of vias drilled this size */
415 UnplatedCount
, /* number of these holes that are unplated */
416 PinN
, /* number of drill coordinates in the list */
417 PinMax
; /* max number of coordinates from malloc() */
418 PinType
**Pin
; /* coordinates to drill */
419 ElementType
**Element
; /* a pointer to an array of element pointers */
422 typedef struct /* holds a range of Drill Infos */
424 Cardinal DrillN
, /* number of drill sizes */
425 DrillMax
; /* max number from malloc() */
426 DrillType
*Drill
; /* plated holes */
431 Coord Thick
, /* line thickness */
432 Diameter
, /* via diameter */
433 Hole
, /* via drill hole */
434 Keepaway
; /* min. separation from other nets */
439 /* ---------------------------------------------------------------------------
440 * structure used by library routines
444 char *ListEntry
; /* the string for the selection box */
445 char *AllocatedMemory
, /* pointer to allocated memory; all others */
446 /* point to parts of the string */
447 *Template
, /* m4 template name */
448 *Package
, /* package */
449 *Value
, /* the value field */
450 *Description
; /* some descritional text */
453 /* If the internal flag is set, the only field that is valid is Name,
454 and the struct is allocated with malloc instead of
455 CreateLibraryEntry. These "internal" entries are used for
456 electrical paths that aren't yet assigned to a real net. */
460 char *Name
, /* name of the menu entry */
461 *directory
, /* Directory name library elements are from */
462 *Style
; /* routing style */
463 Cardinal EntryN
, /* number of objects */
464 EntryMax
; /* number of reserved memory locations */
465 LibraryEntryType
*Entry
; /* the entries */
466 char flag
; /* used by the netlist window to enable/disable nets */
467 char internal
; /* if set, this is an internal-only entry, not
468 part of the global netlist. */
473 Cardinal MenuN
; /* number of objects */
474 Cardinal MenuMax
; /* number of reserved memory locations */
475 LibraryMenuType
*Menu
; /* the entries */
479 /* The PCBType struct holds information about board layout most of which is
480 | saved with the layout. A new PCB layout struct is first initialized
481 | with values from the user configurable Settings struct and then reset
482 | to the saved layout values when a layout is loaded.
483 | This struct is also used for the remove list and for buffer handling
485 typedef struct PCBType
487 long ID
; /* see macro.h */
489 char *Name
, /* name of board */
490 *Filename
, /* name of file (from load) */
491 *PrintFilename
, /* from print dialog */
492 *Netlistname
, /* name of netlist file */
493 ThermStyle
; /* type of thermal to place with thermal tool */
494 bool Changed
, /* layout has been changed */
495 ViaOn
, /* visibility flags */
496 ElementOn
, RatOn
, InvisibleObjectsOn
, PinOn
, SilkActive
, /* active layer is actually silk */
497 RatDraw
; /* we're drawing rats */
498 char *ViaColor
, /* some colors */
505 *InvisibleObjectsColor
,
507 *ElementSelectedColor
,
508 *RatSelectedColor
, *ConnectedColor
, *WarnColor
, *MaskColor
;
509 long CursorX
, /* cursor position as saved with layout */
511 Coord Bloat
, /* drc sizes saved with layout */
512 Shrink
, minWid
, minSlk
, minDrill
, minRing
;
513 Coord GridOffsetX
, /* as saved with layout */
515 /* TODO: Set this always to MAX_COORD, no saving needed.
516 Kept for compatibility and until the GUI code can deal
517 with the dynamic extent. */
518 Coord MaxWidth
, MaxHeight
; /* allowed size */
519 Coord ExtentMinX
, ExtentMinY
, /* extent, defined by the outline layer */
520 ExtentMaxX
, ExtentMaxY
;
522 Coord Grid
; /* used grid with offsets */
523 double IsleArea
, /* minimum poly island to retain */
524 ThermScale
; /* scale factor used with thermals */
526 LayerGroupType LayerGroups
;
527 RouteStyleType RouteStyle
[NUM_STYLES
];
528 LibraryType NetlistLib
;
529 AttributeListType Attributes
;
530 DataType
*Data
; /* entire database */
532 bool is_footprint
; /* If set, the user has loaded a footprint, not a pcb. */
536 typedef struct /* information about the paste buffer */
538 Coord X
, Y
; /* offset */
540 DataType
*Data
; /* data; not all members of PCBType */
544 /* ---------------------------------------------------------------------------
545 * some types for cursor drawing, setting of block and lines
546 * as well as for merging of elements
548 typedef struct /* rubberband lines for element moves */
550 LayerType
*Layer
; /* layer that holds the line */
551 LineType
*Line
; /* the line itself */
552 PointType
*MovedPoint
; /* and finally the point */
555 typedef struct /* current marked line */
557 PointType Point1
, /* start- and end-position */
563 typedef struct /* currently marked block */
565 PointType Point1
, /* start- and end-position */
571 typedef struct /* currently attached object */
573 Coord X
, Y
; /* saved position when MOVE_MODE */
575 long int Type
, /* object type */
577 void *Ptr1
, /* three pointers to data, see */
578 *Ptr2
, /* search.c */
580 Cardinal RubberbandN
, /* number of lines in array */
582 RubberbandType
*Rubberband
;
583 } AttachedObjectType
;
587 Basic_Crosshair_Shape
= 0, /* 4-ray */
588 Union_Jack_Crosshair_Shape
, /* 8-ray */
589 Dozen_Crosshair_Shape
, /* 12-ray */
590 Crosshair_Shapes_Number
593 typedef struct /* holds cursor information */
595 hidGC GC
, /* GC for cursor drawing */
596 AttachGC
; /* and for displaying buffer contents */
597 Coord X
, Y
, /* position in PCB coordinates */
598 MinX
, MinY
, /* lowest and highest coordinates */
600 AttachedLineType AttachedLine
; /* data of new lines... */
601 AttachedBoxType AttachedBox
;
602 PolygonType AttachedPolygon
;
603 AttachedObjectType AttachedObject
; /* data of attached objects */
604 enum crosshair_shape shape
; /* shape of crosshair */
613 /* ---------------------------------------------------------------------------
615 * most of them are used as default when a new design is started
617 typedef struct /* some resources... */
619 const Unit
*grid_unit
;
620 Increments
*increments
;
624 char *BlackColor
, *WhiteColor
, *BackgroundColor
, /* background and cursor color ... */
625 *CrosshairColor
, /* different object colors */
634 *InvisibleObjectsColor
,
636 *ElementSelectedColor
,
641 *LayerColor
[MAX_LAYER
],
642 *LayerSelectedColor
[MAX_LAYER
], *WarnColor
, *MaskColor
;
643 Coord ViaThickness
, /* some preset values */
644 ViaDrillingHole
, LineThickness
, RatThickness
, Keepaway
, /* default size of a new layout */
646 AlignmentDistance
, Bloat
, /* default drc sizes */
647 Shrink
, minWid
, minSlk
, minDrill
, minRing
;
648 int TextScale
; /* text scaling in % */
649 Coord Grid
; /* grid in pcb-units */
650 double IsleArea
; /* polygon min area */
651 int PinoutNameLength
, /* max displayed length of a pinname */
652 Volume
, /* the speakers volume -100..100 */
653 CharPerLine
, /* width of an output line in characters */
654 Mode
, /* currently active mode */
655 BufferNumber
; /* number of the current buffer */
656 int BackupInterval
; /* time between two backups in seconds */
657 char *DefaultLayerName
[MAX_LAYER
], *FontCommand
, /* commands for file loading... */
658 *FileCommand
, *ElementCommand
, *PrintFile
, *LibraryCommandDir
, *LibraryCommand
, *LibraryContentsCommand
, *LibraryTree
, /* path to library tree */
659 *SaveCommand
, *LibraryFilename
, *FontFile
, /* name of default font file */
660 *Groups
, /* string with layergroups */
661 *Routes
, /* string with route styles */
662 *FilePath
, *RatPath
, *RatCommand
, *FontPath
, *PinoutFont
, *ElementPath
, *LibraryPath
, *Size
, /* geometry string for size */
663 *BackgroundImage
, /* PPM file for board background */
664 *ScriptFilename
, /* PCB Actions script to execute on startup */
665 *ActionString
, /* PCB Actions string to execute on startup */
666 *FabAuthor
, /* Full name of author for FAB drawings */
667 *GnetlistProgram
, /* gnetlist program name */
668 *MakeProgram
, /* make program name */
669 *InitialLayerStack
; /* If set, the initial layer stack is set to this */
670 Coord PinoutOffsetX
, /* offset of origin */
672 Coord PinoutTextOffsetX
, /* offset of text from pin center */
674 RouteStyleType RouteStyle
[NUM_STYLES
]; /* default routing styles */
675 LayerGroupType LayerGroups
; /* default layer groups */
676 bool ClearLine
, FullPoly
,
677 UniqueNames
, /* force unique names */
678 SnapPin
, /* snap to pins and pads */
679 ShowSolderSide
, /* mirror output */
680 SaveLastCommand
, /* save the last command entered by user */
681 SaveInTMP
, /* always save data in /tmp */
682 DrawGrid
, /* draw grid points */
683 RatWarn
, /* rats nest has set warnings */
684 StipplePolygons
, /* draw polygons with stipple */
685 AllDirectionLines
, /* enable lines to all directions */
686 RubberBandMode
, /* move, rotate use rubberband connections */
687 SwapStartDirection
, /* change starting direction after each click */
688 ShowDRC
, /* show drc region on crosshair */
690 ShowNumber
, /* pinout shows number */
691 OrthogonalMoves
, /* */
692 ResetAfterElement
, /* reset connections after each element */
693 liveRouting
, /* autorouter shows tracks in progress */
694 RingBellWhenFinished
, /* flag if a signal should be */
695 /* produced when searching of */
696 /* connections is done */
697 AutoPlace
; /* flag which says we should force placement of the
698 windows on startup */
702 /* ----------------------------------------------------------------------
703 * pointer to low-level copy, move and rotate functions
707 void *(*Line
) (LayerType
*, LineType
*);
708 void *(*Text
) (LayerType
*, TextType
*);
709 void *(*Polygon
) (LayerType
*, PolygonType
*);
710 void *(*Via
) (PinType
*);
711 void *(*Element
) (ElementType
*);
712 void *(*ElementName
) (ElementType
*);
713 void *(*Pin
) (ElementType
*, PinType
*);
714 void *(*Pad
) (ElementType
*, PadType
*);
715 void *(*LinePoint
) (LayerType
*, LineType
*, PointType
*);
716 void *(*Point
) (LayerType
*, PolygonType
*, PointType
*);
717 void *(*Arc
) (LayerType
*, ArcType
*);
718 void *(*Rat
) (RatType
*);
719 } ObjectFunctionType
;
721 /* ---------------------------------------------------------------------------
722 * structure used by device drivers
725 typedef struct /* holds a connection */
727 Coord X
, Y
; /* coordinate of connection */
728 long int type
; /* type of object in ptr1 - 3 */
729 void *ptr1
, *ptr2
; /* the object of the connection */
730 Cardinal group
; /* the layer group of the connection */
731 LibraryMenuType
*menu
; /* the netmenu this *SHOULD* belong too */
734 typedef struct /* holds a net of connections */
736 Cardinal ConnectionN
, /* the number of connections contained */
737 ConnectionMax
; /* max connections from malloc */
738 ConnectionType
*Connection
;
739 RouteStyleType
*Style
;
742 typedef struct /* holds a list of nets */
744 Cardinal NetN
, /* the number of subnets contained */
745 NetMax
; /* max subnets from malloc */
749 typedef struct /* holds a list of net lists */
751 Cardinal NetListN
, /* the number of net lists contained */
752 NetListMax
; /* max net lists from malloc */
753 NetListType
*NetList
;
756 typedef struct /* holds a generic list of pointers */
758 Cardinal PtrN
, /* the number of pointers contained */
759 PtrMax
; /* max subnets from malloc */
765 Cardinal BoxN
, /* the number of boxes contained */
766 BoxMax
; /* max boxes from malloc */
771 struct drc_violation_st
778 Coord measured_value
;
779 Coord required_value
;
781 long int *object_id_list
;
782 int *object_type_list
;
785 /* ---------------------------------------------------------------------------
786 * define supported types of undo operations
787 * note these must be separate bits now
789 #define UNDO_CHANGENAME 0x0001 /* change of names */
790 #define UNDO_MOVE 0x0002 /* moving objects */
791 #define UNDO_REMOVE 0x0004 /* removing objects */
792 #define UNDO_REMOVE_POINT 0x0008 /* removing polygon/... points */
793 #define UNDO_INSERT_POINT 0x0010 /* inserting polygon/... points */
794 #define UNDO_REMOVE_CONTOUR 0x0020 /* removing a contour from a polygon */
795 #define UNDO_INSERT_CONTOUR 0x0040 /* inserting a contour from a polygon */
796 #define UNDO_ROTATE 0x0080 /* rotations */
797 #define UNDO_CREATE 0x0100 /* creation of objects */
798 #define UNDO_MOVETOLAYER 0x0200 /* moving objects to */
799 #define UNDO_FLAG 0x0400 /* toggling SELECTED flag */
800 #define UNDO_CHANGESIZE 0x0800 /* change size of object */
801 #define UNDO_CHANGE2NDSIZE 0x1000 /* change 2ndSize of object */
802 #define UNDO_MIRROR 0x2000 /* change side of board */
803 #define UNDO_CHANGECLEARSIZE 0x4000 /* change clearance size */
804 #define UNDO_CHANGEMASKSIZE 0x8000 /* change mask size */
805 #define UNDO_CHANGEANGLES 0x10000 /* change arc angles */
806 #define UNDO_LAYERCHANGE 0x20000 /* layer new/delete/move */
807 #define UNDO_CLEAR 0x40000 /* clear/restore to polygons */
808 #define UNDO_NETLISTCHANGE 0x80000 /* netlist change */
811 /* ---------------------------------------------------------------------------
812 * add a macro for wrapping RCS ID's in so that ident will still work
813 * but we won't get as many compiler warnings
817 #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
818 #endif /* GCC_VERSION */
820 #if GCC_VERSION > 2007
821 #define ATTRIBUTE_UNUSED __attribute__((unused))
823 #define ATTRIBUTE_UNUSED
826 /* ---------------------------------------------------------------------------
827 * Macros called by various action routines to show usage or to report
828 * a syntax error and fail
830 #define AUSAGE(x) Message ("Usage:\n%s\n", (x##_syntax))
831 #define AFAIL(x) { Message ("Syntax error. Usage:\n%s\n", (x##_syntax)); return 1; }
833 /* ---------------------------------------------------------------------------
834 * Variables with absolute paths to various directories. These are deduced
835 * at runtime to allow pcb to be relocatable
837 extern char *bindir
; /* The dir in which PCB installation was found */
838 extern char *pcblibdir
; /* The system M4 fp directory */
839 extern char *pcblibpath
; /* The search path for M4 fps */
840 extern char *pcbtreedir
; /* The system newlib fp directory */
841 extern char *pcbtreepath
; /* The search path for newlib fps */
842 extern char *exec_prefix
;
843 extern char *homedir
;
845 #endif /* PCB_GLOBAL_H */