pcb 4.1.1
An interactive printed circuit board layout editor.
|
00001 00041 #ifndef PCB_GLOBAL_H 00042 #define PCB_GLOBAL_H 00043 00044 #ifdef HAVE_CONFIG_H 00045 #include "config.h" 00046 #endif 00047 00048 #include "const.h" 00049 #include "macro.h" 00050 00051 #include <locale.h> 00052 #ifdef HAVE_STDINT_H 00053 #include <stdint.h> 00054 #endif 00055 #include <stdio.h> 00056 #include <stdlib.h> 00057 #include <string.h> 00058 #include <strings.h> 00059 #include <stdarg.h> 00060 #include <math.h> 00061 #include <ctype.h> 00062 #include <sys/types.h> 00063 #include <stdbool.h> 00064 #include <glib.h> 00065 00066 /* Forward declarations for structures the HIDs need. */ 00067 typedef struct BoxType BoxType; 00068 typedef struct polygon_st PolygonType; 00069 typedef struct pad_st PadType; 00070 typedef struct pin_st PinType; 00071 typedef struct drc_violation_st DrcViolationType; 00072 typedef struct rtree rtree_t; 00073 typedef struct AttributeListType AttributeListType; 00074 00075 typedef struct unit Unit; 00076 typedef struct increments Increments; 00077 00078 typedef COORD_TYPE Coord; 00079 typedef double Angle; 00081 #include "hid.h" 00082 #include "polyarea.h" 00083 00084 /* Internationalization support. */ 00085 #include "gettext.h" 00086 00087 #if defined (ENABLE_NLS) 00088 /* When an empty string is used for msgid, the functions may return a nonempty 00089 string. */ 00090 # define _(S) (S[0] != '\0') ? gettext(S) : S 00091 # define N_(S) gettext_noop(S) 00092 # define C_(C, S) pgettext(C, S) 00093 #else 00094 # define _(S) S 00095 # define N_(S) S 00096 # define C_(C, S) S 00097 #endif /* ENABLE_NLS */ 00098 00102 typedef struct { 00103 int ival; 00104 Coord bval; 00105 double dval; 00106 char has_units; 00107 } PLMeasure; 00108 00109 #ifndef XtSpecificationRelease 00110 typedef unsigned int Cardinal; 00111 /*typedef unsigned int Pixel;*/ 00112 typedef char *String; 00113 typedef short Position; 00114 typedef short Dimension; 00115 #endif 00116 typedef unsigned char BYTE; 00117 00124 typedef struct 00125 { 00126 unsigned long f; /* generic flags */ 00127 unsigned char t[(MAX_LAYER + 1) / 2]; /* thermals */ 00128 } FlagType; 00129 00130 #ifndef __GNUC__ 00131 #define __FUNCTION1(a,b) a ":" #b 00132 #define __FUNCTION2(a,b) __FUNCTION1(a,b) 00133 #define __FUNCTION__ __FUNCTION2(__FILE__,__LINE__) 00134 #endif 00135 00136 00137 /* --------------------------------------------------------------------------- 00138 * Macros to annotate branch-prediction information. 00139 * Taken from GLib 2.16.3 (LGPL 2).G_ / g_ prefixes have 00140 * been removed to avoid namespace clashes. 00141 */ 00142 00143 /* The LIKELY and UNLIKELY macros let the programmer give hints to 00144 * the compiler about the expected result of an expression. Some compilers 00145 * can use this information for optimizations. 00146 * 00147 * The PCB_BOOLEAN_EXPR macro is intended to trigger a gcc warning when 00148 * putting assignments inside the test. 00149 */ 00150 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) 00151 #define PCB_BOOLEAN_EXPR(expr) \ 00152 __extension__ ({ \ 00153 int _boolean_var_; \ 00154 if (expr) \ 00155 _boolean_var_ = 1; \ 00156 else \ 00157 _boolean_var_ = 0; \ 00158 _boolean_var_; \ 00159 }) 00160 #define LIKELY(expr) (__builtin_expect (PCB_BOOLEAN_EXPR(expr), 1)) 00161 #define UNLIKELY(expr) (__builtin_expect (PCB_BOOLEAN_EXPR(expr), 0)) 00162 #else 00163 #define LIKELY(expr) (expr) 00164 #define UNLIKELY(expr) (expr) 00165 #endif 00166 00167 00168 /* --------------------------------------------------------------------------- 00169 * Do not change the following definitions even if they're not very 00170 * nice. It allows us to have functions act on these "base types" and 00171 * not need to know what kind of actual object they're working on. 00172 */ 00173 00174 /* Any object that uses the "object flags" defined in const.h, or 00175 exists as an object on the pcb, MUST be defined using this as the 00176 first fields, either directly or through ANYLINEFIELDS. */ 00177 #define ANYOBJECTFIELDS \ 00178 BoxType BoundingBox; \ 00179 long int ID; \ 00180 FlagType Flags; \ 00181 // struct LibraryEntryType *net 00182 00183 /* Lines, pads, and rats all use this so they can be cross-cast. */ 00184 #define ANYLINEFIELDS \ 00185 ANYOBJECTFIELDS; \ 00186 Coord Thickness, \ 00187 Clearance; \ 00188 PointType Point1, \ 00189 Point2 00190 00191 /* --------------------------------------------------------------------------- 00192 * some useful values of our widgets 00193 */ 00194 00198 typedef struct 00199 { 00200 hidGC bgGC, 00201 fgGC, 00202 pmGC; 00203 } 00204 OutputType; 00205 00212 typedef struct 00213 { 00214 Cardinal Number[MAX_GROUP], 00215 Entries[MAX_GROUP][MAX_ALL_LAYER]; 00216 } LayerGroupType; 00217 00221 struct BoxType 00222 { 00223 Coord X1, Y1; 00224 Coord X2, Y2; 00225 }; 00226 00227 typedef struct 00228 { 00229 Coord x, y; 00230 Coord width, height; 00231 } RectangleType; 00232 00233 typedef struct 00234 { 00235 char *name; 00236 char *value; 00237 } AttributeType; 00238 00239 struct AttributeListType 00240 { 00241 int Number, Max; 00242 AttributeType *List; 00243 }; 00244 00245 /* --------------------------------------------------------------------------- 00246 * the basic object types supported by PCB 00247 */ 00248 00253 typedef struct { 00254 ANYOBJECTFIELDS; 00255 } AnyObjectType; 00256 00260 typedef struct 00261 { 00262 Coord X, Y, X2, Y2; 00263 long int ID; 00264 } PointType; 00265 00269 typedef struct { 00270 ANYLINEFIELDS; 00271 } AnyLineObjectType; 00272 00276 typedef struct 00277 { 00278 ANYLINEFIELDS; 00279 char *Number; 00280 } LineType; 00281 00282 typedef struct 00283 { 00284 ANYOBJECTFIELDS; 00285 int Scale; 00286 Coord X; 00287 Coord Y; 00288 BYTE Direction; 00289 char *TextString; 00290 void *Element; 00291 } TextType; 00292 00296 struct polygon_st 00297 { 00298 ANYOBJECTFIELDS; 00299 Cardinal PointN; 00300 Cardinal PointMax; 00301 POLYAREA *Clipped; 00302 PLINE *NoHoles; 00303 int NoHolesValid; 00304 PointType *Points; 00305 Cardinal *HoleIndex; 00306 Cardinal HoleIndexN; 00307 Cardinal HoleIndexMax; 00309 }; 00310 00314 typedef struct 00315 { 00316 ANYOBJECTFIELDS; 00317 Coord Thickness, Clearance; 00318 PointType Point1; 00319 PointType Point2; 00320 Coord Width; 00321 Coord Height; 00322 Coord X; 00323 Coord Y; 00324 Angle StartAngle; 00325 Angle Delta; 00326 } ArcType; 00327 00328 struct rtree 00329 { 00330 struct rtree_node *root; 00331 int size; 00332 }; 00333 00336 typedef struct 00337 { 00338 LayertypeType Type; 00339 char *Name; 00340 Cardinal LineN; 00341 Cardinal TextN; 00342 Cardinal PolygonN; 00343 Cardinal ArcN; 00344 GList *Line; 00345 GList *Text; 00346 GList *Polygon; 00347 GList *Arc; 00348 rtree_t *line_tree, *text_tree, *polygon_tree, *arc_tree; 00349 bool On; 00350 char *Color, 00351 *SelectedColor; 00352 AttributeListType Attributes; 00353 int no_drc; 00355 } 00356 LayerType; 00357 00361 typedef struct 00362 { 00363 ANYLINEFIELDS; 00364 Cardinal group1; 00365 Cardinal group2; 00366 } RatType; 00367 00371 struct pad_st 00372 { 00373 ANYLINEFIELDS; 00374 Coord Mask; 00375 char *Name, *Number; 00376 void *Element; 00377 void *Spare; 00378 }; 00379 00383 struct pin_st 00384 { 00385 ANYOBJECTFIELDS; 00386 Coord Thickness; 00387 Coord Clearance; 00388 Coord Mask; 00389 Coord DrillingHole; 00390 Coord X; 00391 Coord Y; 00392 char *Name; 00393 char *Number; 00394 void *Element; 00395 void *Spare; 00396 Cardinal BuriedFrom; 00397 Cardinal BuriedTo; 00398 }; 00399 00400 /* This is the extents of a Pin or Via, depending on whether it's a 00401 hole or not. */ 00402 #define PIN_SIZE(pinptr) (TEST_FLAG(HOLEFLAG, (pinptr)) \ 00403 ? (pinptr)->DrillingHole \ 00404 : (pinptr)->Thickness) 00405 00409 typedef struct 00410 { 00411 ANYOBJECTFIELDS; 00412 TextType Name[MAX_ELEMENTNAMES]; 00419 Coord MarkX; 00420 Coord MarkY; 00421 Cardinal PinN; 00422 Cardinal PadN; 00423 Cardinal LineN; 00424 Cardinal ArcN; 00425 GList *Pin; 00426 GList *Pad; 00427 GList *Line; 00428 GList *Arc; 00429 BoxType VBox; 00430 AttributeListType Attributes; 00431 } ElementType; 00432 00433 /* --------------------------------------------------------------------------- 00434 * symbol and font related stuff 00435 */ 00439 typedef struct 00440 { 00441 LineType *Line; 00442 bool Valid; 00443 Cardinal LineN; 00444 Cardinal LineMax; 00445 Coord Width; 00446 Coord Height; 00447 Coord Delta; 00448 } SymbolType; 00449 00453 typedef struct 00454 { 00455 Coord MaxHeight; 00456 Coord MaxWidth; 00457 BoxType DefaultSymbol; 00458 SymbolType Symbol[MAX_FONTPOSITION + 1]; 00459 bool Valid; 00460 } FontType; 00461 00465 typedef struct 00466 { 00467 Cardinal ViaN; 00468 Cardinal ElementN; 00469 Cardinal RatN; 00470 int LayerN; 00471 GList *Via; 00472 GList *Element; 00473 GList *Rat; 00474 rtree_t *via_tree, *element_tree, *pin_tree, *pad_tree, *name_tree[3], /* for element names */ 00475 *rat_tree; 00476 struct PCBType *pcb; 00477 LayerType Layer[MAX_ALL_LAYER]; 00478 int polyClip; 00479 } DataType; 00480 00484 typedef struct 00485 { 00486 Coord DrillSize; 00487 Cardinal ElementN; 00488 Cardinal ElementMax; 00489 Cardinal PinCount; 00490 Cardinal ViaCount; 00491 Cardinal UnplatedCount; 00492 Cardinal PinN; 00493 Cardinal PinMax; 00494 PinType **Pin; 00495 ElementType **Element; 00496 } DrillType; 00497 00501 typedef struct 00502 { 00503 Cardinal DrillN; 00504 Cardinal DrillMax; 00505 DrillType *Drill; 00506 } DrillInfoType; 00507 00508 typedef struct 00509 { 00510 Coord Thick; 00511 Coord Diameter; 00512 Coord Hole; 00513 Coord Keepaway; 00514 char *Name; 00515 int index; 00516 } RouteStyleType; 00517 00521 typedef struct 00522 { 00523 char *ListEntry; 00524 char *AllocatedMemory; 00526 char *Template; 00527 char *Package; 00528 char *Value; 00529 char *Description; 00530 } LibraryEntryType; 00531 00540 typedef struct 00541 { 00542 char *Name; 00543 char *directory; 00544 char *Style; 00545 Cardinal EntryN; 00546 Cardinal EntryMax; 00547 LibraryEntryType *Entry; 00548 char flag; 00549 char internal; 00551 } LibraryMenuType; 00552 00553 typedef struct 00554 { 00555 Cardinal MenuN; 00556 Cardinal MenuMax; 00557 LibraryMenuType *Menu; 00558 } LibraryType; 00559 00560 00571 typedef struct PCBType 00572 { 00573 long ID; 00574 FlagType Flags; 00575 char *Name, 00576 *Filename, 00577 *PrintFilename, 00578 *Netlistname, 00579 ThermStyle; 00580 bool Changed, 00581 ViaOn, 00582 ElementOn, 00583 RatOn, 00584 InvisibleObjectsOn, 00585 PinOn, 00586 SilkActive, 00587 RatDraw; 00588 char *ViaColor, 00589 *ViaSelectedColor, 00590 *PinColor, 00591 *PinSelectedColor, 00592 *PinNameColor, 00593 *ElementColor, 00594 *RatColor, 00595 *InvisibleObjectsColor, 00596 *InvisibleMarkColor, 00597 *ElementSelectedColor, 00598 *RatSelectedColor, 00599 *ConnectedColor, 00600 *FoundColor, 00601 *WarnColor, 00602 *MaskColor; 00603 long CursorX, 00604 CursorY, 00605 Clipping; 00606 Coord Bloat, 00607 Shrink, 00608 minWid, 00609 minSlk, 00610 minDrill, 00611 minRing; 00612 Coord GridOffsetX, 00613 GridOffsetY, 00614 MaxWidth, 00615 MaxHeight; 00617 Coord Grid; 00618 double IsleArea, 00619 ThermScale; 00620 FontType Font; 00621 LayerGroupType LayerGroups; 00622 RouteStyleType RouteStyle[NUM_STYLES]; 00623 LibraryType NetlistLib; 00624 AttributeListType Attributes; 00625 DataType *Data; 00627 bool is_footprint; 00628 } 00629 PCBType; 00630 00634 typedef struct 00635 { 00636 Coord X; 00637 Coord Y; 00638 BoxType BoundingBox; 00639 DataType *Data; 00640 } BufferType; 00641 00642 /* --------------------------------------------------------------------------- 00643 * some types for cursor drawing, setting of block and lines 00644 * as well as for merging of elements 00645 */ 00646 00650 typedef struct 00651 { 00652 LayerType *Layer; 00653 LineType *Line; 00654 PointType *MovedPoint; 00655 } RubberbandType; 00656 00660 typedef struct 00661 { 00662 PointType Point1; 00663 PointType Point2; 00664 long int State; 00665 bool draw; 00666 } AttachedLineType; 00667 00671 typedef struct 00672 { 00673 PointType Point1; 00674 PointType Point2; 00675 long int State; 00676 bool otherway; 00677 } AttachedBoxType; 00678 00682 typedef struct 00683 { 00684 Coord X; 00685 Coord Y; 00686 BoxType BoundingBox; 00687 long int Type, 00688 State; 00689 void *Ptr1; 00690 void *Ptr2; 00691 void *Ptr3; 00692 Cardinal RubberbandN, 00693 RubberbandMax; 00694 RubberbandType *Rubberband; 00695 } AttachedObjectType; 00696 00697 enum crosshair_shape 00698 { 00699 Basic_Crosshair_Shape = 0, 00700 Union_Jack_Crosshair_Shape, 00701 Dozen_Crosshair_Shape, 00702 Crosshair_Shapes_Number 00703 }; 00704 00708 typedef struct 00709 { 00710 hidGC GC; 00711 hidGC AttachGC; 00712 Coord X; 00713 Coord Y; 00714 Coord MinX; 00715 Coord MinY; 00716 Coord MaxX; 00717 Coord MaxY; 00718 AttachedLineType AttachedLine; 00719 AttachedBoxType AttachedBox; 00720 PolygonType AttachedPolygon; 00721 AttachedObjectType AttachedObject; 00722 enum crosshair_shape shape; 00723 } CrosshairType; 00724 00725 typedef struct 00726 { 00727 bool status; 00728 Coord X, Y; 00729 } MarkType; 00730 00736 typedef struct 00737 { 00738 const Unit *grid_unit; 00739 Increments *increments; 00740 00741 int verbose; 00742 00743 char *BlackColor, 00744 *WhiteColor, 00745 *BackgroundColor, 00746 *CrosshairColor, 00747 *CrossColor, 00748 *ViaColor, 00749 *ViaSelectedColor, 00750 *PinColor, 00751 *PinSelectedColor, 00752 *PinNameColor, 00753 *ElementColor, 00754 *RatColor, 00755 *InvisibleObjectsColor, 00756 *InvisibleMarkColor, 00757 *ElementSelectedColor, 00758 *RatSelectedColor, 00759 *ConnectedColor, 00760 *FoundColor, 00761 *OffLimitColor, 00762 *GridColor, 00763 *LayerColor[MAX_LAYER], 00764 *LayerSelectedColor[MAX_LAYER], 00765 *WarnColor, 00766 *MaskColor; 00767 Coord ViaThickness, 00768 ViaDrillingHole, 00769 LineThickness, 00770 RatThickness, 00771 Keepaway, 00772 MaxWidth, 00773 MaxHeight, 00774 AlignmentDistance, 00775 Bloat, 00776 Shrink, 00777 minWid, 00778 minSlk, 00779 minDrill, 00780 minRing; 00781 int TextScale; 00782 Coord Grid; 00783 double IsleArea; 00784 Coord PasteAdjust; 00785 int PinoutNameLength, 00786 Volume, 00787 CharPerLine, 00788 Mode, 00789 BufferNumber; 00790 int BackupInterval; 00791 char *DefaultLayerName[MAX_LAYER], 00792 *FontCommand, 00793 *FileCommand, 00794 *ElementCommand, 00795 *PrintFile, 00796 *LibraryCommandDir, 00797 *LibraryCommand, 00798 *LibraryContentsCommand, 00799 *LibraryTree, 00800 *SaveCommand, 00801 *LibraryFilename, 00802 *FontFile, 00803 *Groups, 00804 *Routes, 00805 *FilePath, 00806 *RatPath, 00807 *RatCommand, 00808 *FontPath, 00809 *PinoutFont, 00810 *ElementPath, 00811 *LibraryPath, 00812 *Size, 00813 *BackgroundImage, 00814 *ScriptFilename, 00815 *ActionString, 00816 *FabAuthor, 00817 *GnetlistProgram, 00818 *MakeProgram, 00819 *InitialLayerStack; 00820 Coord PinoutOffsetX; 00821 Coord PinoutOffsetY; 00822 Coord PinoutTextOffsetX; 00823 Coord PinoutTextOffsetY; 00824 RouteStyleType RouteStyle[NUM_STYLES]; 00825 LayerGroupType LayerGroups; 00826 bool ClearLine, 00827 FullPoly, 00828 UniqueNames, 00829 SnapPin, 00830 ShowBottomSide, 00831 SaveLastCommand, 00832 SaveInTMP, 00833 SaveMetricOnly, 00834 DrawGrid, 00835 RatWarn, 00836 StipplePolygons, 00837 AllDirectionLines, 00838 RubberBandMode, 00839 SwapStartDirection, 00840 ShowDRC, 00841 AutoDRC, 00842 ShowNumber, 00843 OrthogonalMoves, 00844 ResetAfterElement, 00845 liveRouting, 00846 AutoBuriedVias, 00847 RingBellWhenFinished, 00850 AutoPlace; 00853 } 00854 SettingType; 00855 00859 typedef struct 00860 { 00861 void *(*Line) (LayerType *, LineType *); 00862 void *(*Text) (LayerType *, TextType *); 00863 void *(*Polygon) (LayerType *, PolygonType *); 00864 void *(*Via) (PinType *); 00865 void *(*Element) (ElementType *); 00866 void *(*ElementName) (ElementType *); 00867 void *(*Pin) (ElementType *, PinType *); 00868 void *(*Pad) (ElementType *, PadType *); 00869 void *(*LinePoint) (LayerType *, LineType *, PointType *); 00870 void *(*Point) (LayerType *, PolygonType *, PointType *); 00871 void *(*Arc) (LayerType *, ArcType *); 00872 void *(*Rat) (RatType *); 00873 } ObjectFunctionType; 00874 00875 /* --------------------------------------------------------------------------- 00876 * structure used by device drivers 00877 */ 00878 00879 00883 typedef struct 00884 { 00885 Coord X; 00886 Coord Y; 00887 long int type; 00888 void *ptr1; 00889 void *ptr2; 00890 Cardinal group; 00891 LibraryMenuType *menu; 00892 } ConnectionType; 00893 00897 typedef struct 00898 { 00899 Cardinal ConnectionN; 00900 Cardinal ConnectionMax; 00901 ConnectionType *Connection; 00902 RouteStyleType *Style; 00903 } NetType; 00904 00908 typedef struct 00909 { 00910 Cardinal NetN; 00911 Cardinal NetMax; 00912 NetType *Net; 00913 } NetListType; 00914 00918 typedef struct 00919 { 00920 Cardinal NetListN; 00921 Cardinal NetListMax; 00922 NetListType *NetList; 00923 } NetListListType; 00924 00928 typedef struct 00929 { 00930 Cardinal PtrN; 00931 Cardinal PtrMax; 00932 void **Ptr; 00933 } PointerListType; 00934 00935 typedef struct 00936 { 00937 Cardinal BoxN; 00938 Cardinal BoxMax; 00939 BoxType *Box; 00940 } BoxListType; 00941 00942 struct drc_violation_st 00943 { 00944 char *title; 00945 char *explanation; 00946 Coord x, y; 00947 Angle angle; 00948 int have_measured; 00949 Coord measured_value; 00950 Coord required_value; 00951 int object_count; 00952 long int *object_id_list; 00953 int *object_type_list; 00954 }; 00955 00956 /* --------------------------------------------------------------------------- 00957 * define supported types of undo operations 00958 * note these must be separate bits now 00959 */ 00960 #define UNDO_CHANGENAME 0x0001 00961 #define UNDO_MOVE 0x0002 00962 #define UNDO_REMOVE 0x0004 00963 #define UNDO_REMOVE_POINT 0x0008 00964 #define UNDO_INSERT_POINT 0x0010 00965 #define UNDO_REMOVE_CONTOUR 0x0020 00966 #define UNDO_INSERT_CONTOUR 0x0040 00967 #define UNDO_ROTATE 0x0080 00968 #define UNDO_CREATE 0x0100 00969 #define UNDO_MOVETOLAYER 0x0200 00970 #define UNDO_FLAG 0x0400 00971 #define UNDO_CHANGESIZE 0x0800 00972 #define UNDO_CHANGE2NDSIZE 0x1000 00973 #define UNDO_MIRROR 0x2000 00974 #define UNDO_CHANGECLEARSIZE 0x4000 00975 #define UNDO_CHANGEMASKSIZE 0x8000 00976 #define UNDO_CHANGEANGLES 0x10000 00977 #define UNDO_LAYERCHANGE 0x20000 00978 #define UNDO_CLEAR 0x40000 00979 #define UNDO_NETLISTCHANGE 0x80000 00980 #define UNDO_CHANGESETVIALAYERS 0x100000 00981 /* --------------------------------------------------------------------------- 00982 */ 00983 #if (__GNUC__ * 1000 + __GNUC_MINOR__) > 2007 00984 #define ATTRIBUTE_UNUSED __attribute__((unused)) 00985 #else 00986 #define ATTRIBUTE_UNUSED 00987 #endif 00988 00989 /* --------------------------------------------------------------------------- 00990 * Macros called by various action routines to show usage or to report 00991 * a syntax error and fail 00992 */ 00993 #define AUSAGE(x) Message (_("Usage:\n%s\n"), _(x##_syntax)) 00994 #define AFAIL(x) { Message (_("Syntax error. Usage:\n%s\n"), _(x##_syntax)); return 1; } 00995 00996 /* --------------------------------------------------------------------------- 00997 * Variables with absolute paths to various directories. These are deduced 00998 * at runtime to allow pcb to be relocatable 00999 */ 01000 extern char *bindir; 01001 extern char *pcblibdir; 01002 extern char *pcblibpath; 01003 extern char *pcbtreedir; 01004 extern char *pcbtreepath; 01005 extern char *exec_prefix; 01006 extern char *homedir; 01007 01008 #endif /* PCB_GLOBAL_H */