2 * ************************** README *******************
4 * If the file format is modified in any way, update
5 * PCB_FILE_VERSION in file.h
7 * ************************** README *******************
14 * PCB, interactive printed circuit board design
15 * Copyright (C) 1994,1995,1996 Thomas Nau
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 * Contact addresses for paper mail and Email:
32 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
33 * Thomas.Nau@rz.uni-ulm.de
37 /* grammar to parse ASCII input of PCB description
58 #ifdef HAVE_LIBDMALLOC
59 # include <dmalloc.h> /* see http://dmalloc.com */
62 static LayerType
*Layer
;
63 static PolygonType
*Polygon
;
64 static SymbolType
*Symbol
;
66 static LibraryMenuType
*Menu
;
67 static bool LayerFlag
[MAX_LAYER
+ 2];
69 extern
char *yytext
; /* defined by LEX */
70 extern PCBType
*yyPCB
;
71 extern DataType
*yyData
;
72 extern ElementType
*yyElement
;
73 extern FontType
*yyFont
;
74 extern
int yylineno
; /* linenumber */
75 extern
char *yyfilename
; /* in this file */
77 static char *layer_group_string
;
79 static AttributeListType
*attr_list
;
81 int yyerror(const char *s
);
83 static int check_file_version
(int);
85 static void do_measure
(PLMeasure
*m
, Coord i
, double d
, int u
);
86 #define M(r,f,d) do_measure (&(r), f, d, 1)
88 /* Macros for interpreting what "measure" means - integer value only,
89 old units (mil), or new units (cmil). */
90 #define IV(m) integer_value (m)
91 #define OU(m) old_units (m)
92 #define NU(m) new_units (m)
94 static int integer_value
(PLMeasure m
);
95 static Coord old_units
(PLMeasure m
);
96 static Coord new_units
(PLMeasure m
);
99 #define YYERROR_VERBOSE 1
107 %
union /* define YYSTACK type */
116 %token
<number
> FLOATING
/* line thickness, coordinates ... */
117 %token
<integer
> INTEGER CHAR_CONST
/* flags ... */
118 %token
<string> STRING
/* element names ... */
120 %token T_FILEVERSION T_PCB T_LAYER T_VIA T_RAT T_LINE T_ARC T_RECTANGLE T_TEXT T_ELEMENTLINE
121 %token T_ELEMENT T_PIN T_PAD T_GRID T_FLAGS T_SYMBOL T_SYMBOLLINE T_CURSOR
122 %token T_ELEMENTARC T_MARK T_GROUPS T_STYLES T_POLYGON T_POLYGON_HOLE T_NETLIST T_NET T_CONN
123 %token T_AREA T_THERMAL T_DRC T_ATTRIBUTE
124 %token T_UMIL T_CMIL T_MIL T_IN T_NM T_UM T_MM T_M T_KM T_PX
125 %type
<integer
> symbolid
126 %type
<string> opt_string
127 %type
<flagtype
> flags
128 %type
<number
> number
129 %type
<measure
> measure
140 /* %start-doc pcbfile 00pcb
144 A special note about units: Older versions of @code{pcb} used mils
145 (1/1000 inch) as the base unit; a value of 500 in the file meant
146 half an inch. Newer versions uses a "high resolution" syntax,
147 where the base unit is 1/100 of a mil (0.000010 inch); a value of 500 in
148 the file means 5 mils. As a general rule, the variants of each entry
149 listed below which use square brackets are the high resolution formats
150 and use the 1/100 mil units, and the ones with parentheses are the older
151 variants and use 1 mil units. Note that when multiple variants
152 are listed, the most recent (and most preferred) format is the first
155 Symbolic and numeric flags (SFlags and NFlags) are described in
162 /* reset flags for 'used layers';
163 * init font and data pointers
169 Message
("illegal fileformat\n");
172 for
(i
= 0; i
< MAX_LAYER
+ 2; i
++)
173 LayerFlag
[i
] = false
;
174 yyFont
= &yyPCB
->Font
;
175 yyData
= yyPCB
->Data
;
178 layer_group_string
= NULL
;
194 PCBType
*pcb_save
= PCB
;
196 if
(layer_group_string
== NULL
)
197 layer_group_string
= Settings.Groups
;
198 CreateNewPCBPost
(yyPCB
, 0);
199 if
(ParseGroupString
(layer_group_string
, &yyPCB
->LayerGroups
, yyData
->LayerN
))
201 Message
("illegal layer-group string\n");
204 /* initialize the polygon clipping now since
205 * we didn't know the layer grouping before.
208 ALLPOLYGON_LOOP
(yyData
);
210 InitClip
(yyData
, layer
, polygon
);
216 |
{ PreLoadElementPCB
();
217 layer_group_string
= NULL
; }
219 { LayerFlag
[0] = true
;
222 PostLoadElementPCB
();
228 /* reset flags for 'used layers';
229 * init font and data pointers
233 if
(!yyData ||
!yyFont
)
235 Message
("illegal fileformat\n");
238 for
(i
= 0; i
< MAX_LAYER
+ 2; i
++)
239 LayerFlag
[i
] = false
;
253 /* mark all symbols invalid */
258 Message
("illegal fileformat\n");
261 yyFont
->Valid
= false
;
262 for
(i
= 0; i
<= MAX_FONTPOSITION
; i
++)
263 free
(yyFont
->Symbol
[i
].Line
);
264 bzero
(yyFont
->Symbol
, sizeof
(yyFont
->Symbol
));
268 yyFont
->Valid
= true
;
273 /* %start-doc pcbfile FileVersion
281 File format version. This version number represents the date when the pcb file
282 format was last changed.
285 Any version of pcb build from sources equal to or newer
286 than this number should be able to read the file. If this line is not present
287 in the input file then file format compatibility is not checked.
294 T_FILEVERSION
'[' INTEGER
']'
296 if
(check_file_version
($3) != 0)
303 /* %start-doc pcbfile PCB
306 PCB ["Name" Width Height]
307 PCB ("Name" Width Height]
313 Name of the PCB project
318 If you don't specify the size of the board, a very large default is
324 : T_PCB
'(' STRING
')'
327 yyPCB
->MaxWidth
= MAX_COORD
;
328 yyPCB
->MaxHeight
= MAX_COORD
;
330 | T_PCB
'(' STRING measure measure
')'
333 yyPCB
->MaxWidth
= OU
($4);
334 yyPCB
->MaxHeight
= OU
($5);
336 | T_PCB
'[' STRING measure measure
']'
339 yyPCB
->MaxWidth
= NU
($4);
340 yyPCB
->MaxHeight
= NU
($5);
344 /* %start-doc pcbfile Grid
347 Grid [Step OffsetX OffsetY Visible]
348 Grid (Step OffsetX OffsetY Visible)
349 Grid (Step OffsetX OffsetY)
354 Distance from one grid point to adjacent points. This value may be a
355 floating point number for the first two variants.
356 @item OffsetX OffsetY
357 The "origin" of the grid. Normally zero.
359 If non-zero, the grid will be visible on the screen.
370 : T_GRID
'(' measure measure measure
')'
372 yyPCB
->Grid
= OU
($3);
373 yyPCB
->GridOffsetX
= OU
($4);
374 yyPCB
->GridOffsetY
= OU
($5);
378 : T_GRID
'(' measure measure measure INTEGER
')'
380 yyPCB
->Grid
= OU
($3);
381 yyPCB
->GridOffsetX
= OU
($4);
382 yyPCB
->GridOffsetY
= OU
($5);
384 Settings.DrawGrid
= true
;
386 Settings.DrawGrid
= false
;
391 : T_GRID
'[' measure measure measure INTEGER
']'
393 yyPCB
->Grid
= NU
($3);
394 yyPCB
->GridOffsetX
= NU
($4);
395 yyPCB
->GridOffsetY
= NU
($5);
397 Settings.DrawGrid
= true
;
399 Settings.DrawGrid
= false
;
403 /* %start-doc pcbfile Cursor
412 Location of the cursor when the board was saved.
413 As of November 2012 the cursor position is not written to file anymore.
414 Older versions of pcb ignore the absence of this line in the pcb file.
416 The current zoom factor. Note that a zoom factor of "0" means 1 mil
417 per screen pixel, N means @math{2^N} mils per screen pixel, etc. The
418 first variant accepts floating point numbers. The special value
419 "1000" means "zoom to fit"
421 This field is ignored by PCB.
427 : T_CURSOR
'(' measure measure number
')'
429 yyPCB
->CursorX
= OU
($3);
430 yyPCB
->CursorY
= OU
($4);
432 | T_CURSOR
'[' measure measure number
']'
434 yyPCB
->CursorX
= NU
($3);
435 yyPCB
->CursorY
= NU
($4);
440 /* %start-doc pcbfile PolyArea
448 Minimum area of polygon island to retain. If a polygon has clearances that cause an isolated island to be created, then will only be retained if the area exceeds this minimum area.
455 | T_AREA
'[' number
']'
457 /* Read in cmil^2 for now; in future this should be a noop. */
458 yyPCB
->IsleArea
= MIL_TO_COORD
(MIL_TO_COORD
($3) / 100.0) / 100.0;
463 /* %start-doc pcbfile Thermal
471 Relative size of thermal fingers. A value of 1.0 makes the finger
472 width twice the clearance gap width (measured across the gap, not
473 diameter). The normal value is 0.5, which results in a finger width
474 the same as the clearance gap width.
482 | T_THERMAL
'[' number
']'
484 yyPCB
->ThermScale
= $3;
488 /* %start-doc pcbfile DRC
491 DRC [Bloat Shrink Line Silk Drill Ring]
492 DRC [Bloat Shrink Line Silk]
493 DRC [Bloat Shrink Line]
498 Minimum spacing between copper.
500 Minimum copper overlap to guarantee connectivity.
502 Minimum line thickness.
504 Minimum silk thickness.
508 Minimum width of the annular ring around pins and vias.
521 : T_DRC
'[' measure measure measure
']'
523 yyPCB
->Bloat
= NU
($3);
524 yyPCB
->Shrink
= NU
($4);
525 yyPCB
->minWid
= NU
($5);
526 yyPCB
->minRing
= NU
($5);
531 : T_DRC
'[' measure measure measure measure
']'
533 yyPCB
->Bloat
= NU
($3);
534 yyPCB
->Shrink
= NU
($4);
535 yyPCB
->minWid
= NU
($5);
536 yyPCB
->minSlk
= NU
($6);
537 yyPCB
->minRing
= NU
($5);
542 : T_DRC
'[' measure measure measure measure measure measure
']'
544 yyPCB
->Bloat
= NU
($3);
545 yyPCB
->Shrink
= NU
($4);
546 yyPCB
->minWid
= NU
($5);
547 yyPCB
->minSlk
= NU
($6);
548 yyPCB
->minDrill
= NU
($7);
549 yyPCB
->minRing
= NU
($8);
553 /* %start-doc pcbfile Flags
561 A number, whose value is normally given in hex, individual bits of which
562 represent pcb-wide flags as defined in @ref{PCBFlags}.
569 : T_FLAGS
'(' INTEGER
')'
571 yyPCB
->Flags
= MakeFlags
($3 & PCB_FLAGS
);
573 | T_FLAGS
'(' STRING
')'
575 yyPCB
->Flags
= string_to_pcbflags
($3, yyerror);
580 /* %start-doc pcbfile Groups
589 Encodes the layer grouping information. Each group is separated by a
590 colon, each member of each group is separated by a comma. Group
591 members are either numbers from @code{1}..@var{N} for each layer, and
592 the letters @code{c} or @code{s} representing the component side and
593 solder side of the board. Including @code{c} or @code{s} marks that
594 group as being the top or bottom side of the board.
597 Groups("1,2,c:3:4:5,6,s:7,8")
605 : T_GROUPS
'(' STRING
')'
607 layer_group_string
= $3;
612 /* %start-doc pcbfile Styles
621 Encodes the four routing styles @code{pcb} knows about. The four styles
622 are separated by colons. Each style consists of five parameters as follows:
626 The name of the style.
628 Width of lines and arcs.
630 Copper diameter of pins and vias.
632 Drill diameter of pins and vias.
634 Minimum spacing to other nets. If omitted, 10 mils is the default.
641 Styles("Signal,10,40,20:Power,25,60,35:Fat,40,60,35:Skinny,8,36,20")
642 Styles["Logic,1000,3600,2000,1000:Power,2500,6000,3500,1000:
643 @ @ @ Line,4000,6000,3500,1000:Breakout,600,2402,1181,600"]
647 Note that strings in actual files cannot span lines; the above example
648 is split across lines only to make it readable.
653 : T_STYLES
'(' STRING
')'
655 if
(ParseRouteString
($3, &yyPCB
->RouteStyle
[0], "mil"))
657 Message
("illegal route-style string\n");
661 | T_STYLES
'[' STRING
']'
663 if
(ParseRouteString
($3, &yyPCB
->RouteStyle
[0], "cmil"))
665 Message
("illegal route-style string\n");
679 | pcbdefinitions pcbdefinition
684 |
{ attr_list
= & yyPCB
->Attributes
; } attribute
699 /* %start-doc pcbfile Via
702 Via [X Y Thickness Clearance Mask Drill "Name" SFlags]
703 Via (X Y Thickness Clearance Mask Drill "Name" NFlags)
704 Via (X Y Thickness Clearance Drill "Name" NFlags)
705 Via (X Y Thickness Drill "Name" NFlags)
706 Via (X Y Thickness "Name" NFlags)
711 coordinates of center
713 outer diameter of copper annulus
715 add to thickness to get clearance diameter
717 diameter of solder mask opening
721 string, name of via (vias have names?)
723 symbolic or numerical flags
731 /* x, y, thickness, clearance, mask, drilling-hole, name, flags */
732 : T_VIA
'[' measure measure measure measure measure measure STRING flags
']'
734 CreateNewVia
(yyData
, NU
($3), NU
($4), NU
($5), NU
($6), NU
($7),
741 /* x, y, thickness, clearance, mask, drilling-hole, name, flags */
742 : T_VIA
'(' measure measure measure measure measure measure STRING INTEGER
')'
744 CreateNewVia
(yyData
, OU
($3), OU
($4), OU
($5), OU
($6), OU
($7), OU
($8), $9,
752 /* x, y, thickness, clearance, drilling-hole, name, flags */
753 : T_VIA
'(' measure measure measure measure measure STRING INTEGER
')'
755 CreateNewVia
(yyData
, OU
($3), OU
($4), OU
($5), OU
($6),
756 OU
($5) + OU
($6), OU
($7), $8, OldFlags
($9));
762 /* x, y, thickness, drilling-hole, name, flags */
763 : T_VIA
'(' measure measure measure measure STRING INTEGER
')'
765 CreateNewVia
(yyData
, OU
($3), OU
($4), OU
($5), 2*GROUNDPLANEFRAME
,
766 OU
($5) + 2*MASKFRAME
, OU
($6), $7, OldFlags
($8));
772 /* old format: x, y, thickness, name, flags */
773 : T_VIA
'(' measure measure measure STRING INTEGER
')'
775 Coord hole
= (OU
($5) * DEFAULT_DRILLINGHOLE
);
777 /* make sure that there's enough copper left */
778 if
(OU
($5) - hole
< MIN_PINORVIACOPPER
&&
779 OU
($5) > MIN_PINORVIACOPPER
)
780 hole
= OU
($5) - MIN_PINORVIACOPPER
;
782 CreateNewVia
(yyData
, OU
($3), OU
($4), OU
($5), 2*GROUNDPLANEFRAME
,
783 OU
($5) + 2*MASKFRAME
, hole
, $6, OldFlags
($7));
788 /* %start-doc pcbfile Rat
791 Rat [X1 Y1 Group1 X2 Y2 Group2 SFlags]
792 Rat (X1 Y1 Group1 X2 Y2 Group2 NFlags)
797 The endpoints of the rat line.
799 The layer group each end is connected on.
801 Symbolic or numeric flags.
809 : T_RAT
'[' measure measure INTEGER measure measure INTEGER flags
']'
811 CreateNewRat
(yyData
, NU
($3), NU
($4), NU
($6), NU
($7), $5, $8,
812 Settings.RatThickness
, $9);
814 | T_RAT
'(' measure measure INTEGER measure measure INTEGER INTEGER
')'
816 CreateNewRat
(yyData
, OU
($3), OU
($4), OU
($6), OU
($7), $5, $8,
817 Settings.RatThickness
, OldFlags
($9));
821 /* %start-doc pcbfile Layer
824 Layer (LayerNum "Name") (
825 @ @ @ @dots{} contents @dots{}
831 The layer number. Layers are numbered sequentially, starting with 1.
832 The last two layers (9 and 10 by default) are solder-side silk and
833 component-side silk, in that order.
837 The contents of the layer, which may include attributes, lines, arcs, rectangles,
845 : T_LAYER
'(' INTEGER STRING opt_string
')' '('
847 if
($3 <= 0 ||
$3 > MAX_LAYER
+ 2)
849 yyerror("Layernumber out of range");
854 yyerror("Layernumber used twice");
857 Layer
= &yyData
->Layer
[$3-1];
859 /* memory for name is already allocated */
861 if
(Layer
->Name
== NULL
)
862 Layer
->Name
= strdup
("");
863 LayerFlag
[$3-1] = true
;
864 if
(yyData
->LayerN
+ 2 < $3)
865 yyData
->LayerN
= $3 - 2;
877 | layerdefinitions layerdefinition
887 /* x1, y1, x2, y2, flags */
888 | T_RECTANGLE
'(' measure measure measure measure INTEGER
')'
890 CreateNewPolygonFromRectangle
(Layer
,
891 OU
($3), OU
($4), OU
($3) + OU
($5), OU
($4) + OU
($6), OldFlags
($7));
896 |
{ attr_list
= & Layer
->Attributes
; } attribute
899 /* %start-doc pcbfile Line
902 Line [X1 Y1 X2 Y2 Thickness Clearance SFlags]
903 Line (X1 Y1 X2 Y2 Thickness Clearance NFlags)
904 Line (X1 Y1 X2 Y2 Thickness NFlags)
909 The end points of the line
911 The width of the line
913 The amount of space cleared around the line when the line passes
914 through a polygon. The clearance is added to the thickness to get the
915 thickness of the clear; thus the space between the line and the
916 polygon is @math{Clearance/2} wide.
918 Symbolic or numeric flags
926 /* x1, y1, x2, y2, thickness, clearance, flags */
927 : T_LINE
'[' measure measure measure measure measure measure flags
']'
929 CreateNewLineOnLayer
(Layer
, NU
($3), NU
($4), NU
($5), NU
($6),
930 NU
($7), NU
($8), $9);
935 /* x1, y1, x2, y2, thickness, clearance, flags */
936 : T_LINE
'(' measure measure measure measure measure measure INTEGER
')'
938 CreateNewLineOnLayer
(Layer
, OU
($3), OU
($4), OU
($5), OU
($6),
939 OU
($7), OU
($8), OldFlags
($9));
944 /* x1, y1, x2, y2, thickness, flags */
945 : T_LINE
'(' measure measure measure measure measure measure
')'
947 /* eliminate old-style rat-lines */
948 if
((IV
($8) & RATFLAG
) == 0)
949 CreateNewLineOnLayer
(Layer
, OU
($3), OU
($4), OU
($5), OU
($6), OU
($7),
950 200*GROUNDPLANEFRAME
, OldFlags
(IV
($8)));
954 /* %start-doc pcbfile Arc
957 Arc [X Y Width Height Thickness Clearance StartAngle DeltaAngle SFlags]
958 Arc (X Y Width Height Thickness Clearance StartAngle DeltaAngle NFlags)
959 Arc (X Y Width Height Thickness StartAngle DeltaAngle NFlags)
964 Coordinates of the center of the arc.
966 The width and height, from the center to the edge. The bounds of the
967 circle of which this arc is a segment, is thus @math{2*Width} by
970 The width of the copper trace which forms the arc.
972 The amount of space cleared around the arc when the line passes
973 through a polygon. The clearance is added to the thickness to get the
974 thickness of the clear; thus the space between the arc and the polygon
975 is @math{Clearance/2} wide.
977 The angle of one end of the arc, in degrees. In PCB, an angle of zero
978 points left (negative X direction), and 90 degrees points down
979 (positive Y direction).
981 The sweep of the arc. This may be negative. Positive angles sweep
984 Symbolic or numeric flags.
992 /* x, y, width, height, thickness, clearance, startangle, delta, flags */
993 : T_ARC
'[' measure measure measure measure measure measure number number flags
']'
995 CreateNewArcOnLayer
(Layer
, NU
($3), NU
($4), NU
($5), NU
($6), $9, $10,
996 NU
($7), NU
($8), $11);
1001 /* x, y, width, height, thickness, clearance, startangle, delta, flags */
1002 : T_ARC
'(' measure measure measure measure measure measure number number INTEGER
')'
1004 CreateNewArcOnLayer
(Layer
, OU
($3), OU
($4), OU
($5), OU
($6), $9, $10,
1005 OU
($7), OU
($8), OldFlags
($11));
1010 /* x, y, width, height, thickness, startangle, delta, flags */
1011 : T_ARC
'(' measure measure measure measure measure measure number INTEGER
')'
1013 CreateNewArcOnLayer
(Layer
, OU
($3), OU
($4), OU
($5), OU
($5), IV
($8), $9,
1014 OU
($7), 200*GROUNDPLANEFRAME
, OldFlags
($10));
1018 /* %start-doc pcbfile Text
1021 Text [X Y Direction Scale "String" SFlags]
1022 Text (X Y Direction Scale "String" NFlags)
1023 Text (X Y Direction "String" NFlags)
1028 The location of the upper left corner of the text.
1030 0 means text is drawn left to right, 1 means up, 2 means right to left
1031 (i.e. upside down), and 3 means down.
1033 Size of the text, as a percentage of the ``default'' size of of the
1034 font (the default font is about 40 mils high). Default is 100 (40
1039 Symbolic or numeric flags.
1047 /* x, y, direction, text, flags */
1048 : T_TEXT
'(' measure measure number STRING INTEGER
')'
1050 /* use a default scale of 100% */
1051 CreateNewText
(Layer
,yyFont
,OU
($3), OU
($4), $5, 100, $6, OldFlags
($7));
1057 /* x, y, direction, scale, text, flags */
1058 : T_TEXT
'(' measure measure number number STRING INTEGER
')'
1060 if
($8 & ONSILKFLAG
)
1062 LayerType
*lay
= &yyData
->Layer
[yyData
->LayerN
+
1063 (($8 & ONSOLDERFLAG
) ? SOLDER_LAYER
: COMPONENT_LAYER
)];
1065 CreateNewText
(lay
,yyFont
, OU
($3), OU
($4), $5, $6, $7,
1069 CreateNewText
(Layer
, yyFont
, OU
($3), OU
($4), $5, $6, $7,
1075 /* x, y, direction, scale, text, flags */
1076 : T_TEXT
'[' measure measure number number STRING flags
']'
1078 /* FIXME: shouldn't know about .f */
1079 /* I don't think this matters because anything with hi_format
1080 * will have the silk on its own layer in the file rather
1081 * than using the ONSILKFLAG and having it in a copper layer.
1082 * Thus there is no need for anything besides the 'else'
1083 * part of this code.
1085 if
($8.f
& ONSILKFLAG
)
1087 LayerType
*lay
= &yyData
->Layer
[yyData
->LayerN
+
1088 (($8.f
& ONSOLDERFLAG
) ? SOLDER_LAYER
: COMPONENT_LAYER
)];
1090 CreateNewText
(lay
, yyFont
, NU
($3), NU
($4), $5, $6, $7, $8);
1093 CreateNewText
(Layer
, yyFont
, NU
($3), NU
($4), $5, $6, $7, $8);
1098 /* %start-doc pcbfile Polygon
1102 @ @ @ @dots{} (X Y) @dots{}
1103 @ @ @ @dots{} [X Y] @dots{}
1105 @ @ @ @ @ @ @dots{} (X Y) @dots{}
1106 @ @ @ @ @ @ @dots{} [X Y] @dots{}
1114 Symbolic or numeric flags.
1116 Coordinates of each vertex. You must list at least three coordinates.
1118 Defines a hole within the polygon's outer contour. There may be zero or more such sections.
1124 : /* flags are passed in */
1125 T_POLYGON
'(' flags
')' '('
1127 Polygon
= CreateNewPolygon
(Layer
, $3);
1132 Cardinal contour
, contour_start
, contour_end
;
1133 bool bad_contour_found
= false
;
1135 for
(contour
= 0; contour
<= Polygon
->HoleIndexN
; contour
++)
1137 contour_start
= (contour
== 0) ?
1138 0 : Polygon
->HoleIndex
[contour
- 1];
1139 contour_end
= (contour
== Polygon
->HoleIndexN
) ?
1141 Polygon
->HoleIndex
[contour
];
1142 if
(contour_end
- contour_start
< 3)
1143 bad_contour_found
= true
;
1146 if
(bad_contour_found
)
1148 Message
("WARNING parsing file '%s'\n"
1150 " description: 'ignored polygon (< 3 points in a contour)'\n",
1151 yyfilename
, yylineno
);
1152 DestroyObject
(yyData
, POLYGON_TYPE
, Layer
, Polygon
, Polygon
);
1156 SetPolygonBoundingBox
(Polygon
);
1157 if
(!Layer
->polygon_tree
)
1158 Layer
->polygon_tree
= r_create_tree
(NULL
, 0, 0);
1159 r_insert_entry
(Layer
->polygon_tree
, (BoxType
*) Polygon
, 0);
1166 | polygonholes polygonhole
1170 : T_POLYGON_HOLE
'('
1172 CreateNewHoleInPolygon
(Polygon
);
1179 | polygonpoint polygonpoints
1184 : '(' measure measure
')'
1186 CreateNewPointInPolygon
(Polygon
, OU
($2), OU
($3));
1188 |
'[' measure measure
']'
1190 CreateNewPointInPolygon
(Polygon
, NU
($2), NU
($3));
1194 /* %start-doc pcbfile Element
1197 Element [SFlags "Desc" "Name" "Value" MX MY TX TY TDir TScale TSFlags] (
1198 Element (NFlags "Desc" "Name" "Value" MX MY TX TY TDir TScale TNFlags) (
1199 Element (NFlags "Desc" "Name" "Value" TX TY TDir TScale TNFlags) (
1200 Element (NFlags "Desc" "Name" TX TY TDir TScale TNFlags) (
1201 Element ("Desc" "Name" TX TY TDir TScale TNFlags) (
1202 @ @ @ @dots{} contents @dots{}
1208 Symbolic or numeric flags, for the element as a whole.
1210 Numeric flags, for the element as a whole.
1212 The description of the element. This is one of the three strings
1213 which can be displayed on the screen.
1215 The name of the element, usually the reference designator.
1217 The value of the element.
1219 The location of the element's mark. This is the reference point
1220 for placing the element and its pins and pads.
1222 The upper left corner of the text (one of the three strings).
1224 The relative direction of the text. 0 means left to right for
1225 an unrotated element, 1 means up, 2 left, 3 down.
1227 Size of the text, as a percentage of the ``default'' size of of the
1228 font (the default font is about 40 mils high). Default is 100 (40
1231 Symbolic or numeric flags, for the text.
1233 Numeric flags, for the text.
1236 Elements may contain pins, pads, element lines, element arcs,
1237 attributes, and (for older elements) an optional mark. Note that
1238 element definitions that have the mark coordinates in the element
1239 line, only support pins and pads which use relative coordinates. The
1240 pin and pad coordinates are relative to the mark. Element definitions
1241 which do not include the mark coordinates in the element line, may
1242 have a Mark definition in their contents, and only use pin and pad
1243 definitions which use absolute coordinates.
1249 | element_1.3
.4_format
1251 | element_1.7_format
1256 /* element_flags, description, pcb-name,
1257 * text_x, text_y, text_direction, text_scale, text_flags
1259 : T_ELEMENT
'(' STRING STRING measure measure INTEGER
')' '('
1261 yyElement
= CreateNewElement
(yyData
, yyFont
, NoFlags
(),
1262 $3, $4, NULL
, OU
($5), OU
($6), $7, 100, NoFlags
(), false
);
1267 elementdefinitions
')'
1269 SetElementBoundingBox
(yyData
, yyElement
, yyFont
);
1273 element_1.3
.4_format
1274 /* element_flags, description, pcb-name,
1275 * text_x, text_y, text_direction, text_scale, text_flags
1277 : T_ELEMENT
'(' INTEGER STRING STRING measure measure measure measure INTEGER
')' '('
1279 yyElement
= CreateNewElement
(yyData
, yyFont
, OldFlags
($3),
1280 $4, $5, NULL
, OU
($6), OU
($7), IV
($8), IV
($9), OldFlags
($10), false
);
1285 elementdefinitions
')'
1287 SetElementBoundingBox
(yyData
, yyElement
, yyFont
);
1292 /* element_flags, description, pcb-name, value,
1293 * text_x, text_y, text_direction, text_scale, text_flags
1295 : T_ELEMENT
'(' INTEGER STRING STRING STRING measure measure measure measure INTEGER
')' '('
1297 yyElement
= CreateNewElement
(yyData
, yyFont
, OldFlags
($3),
1298 $4, $5, $6, OU
($7), OU
($8), IV
($9), IV
($10), OldFlags
($11), false
);
1304 elementdefinitions
')'
1306 SetElementBoundingBox
(yyData
, yyElement
, yyFont
);
1311 /* element_flags, description, pcb-name, value, mark_x, mark_y,
1312 * text_x, text_y, text_direction, text_scale, text_flags
1314 : T_ELEMENT
'(' INTEGER STRING STRING STRING measure measure
1315 measure measure number number INTEGER
')' '('
1317 yyElement
= CreateNewElement
(yyData
, yyFont
, OldFlags
($3),
1318 $4, $5, $6, OU
($7) + OU
($9), OU
($8) + OU
($10),
1319 $11, $12, OldFlags
($13), false
);
1320 yyElement
->MarkX
= OU
($7);
1321 yyElement
->MarkY
= OU
($8);
1328 SetElementBoundingBox
(yyData
, yyElement
, yyFont
);
1333 /* element_flags, description, pcb-name, value, mark_x, mark_y,
1334 * text_x, text_y, text_direction, text_scale, text_flags
1336 : T_ELEMENT
'[' flags STRING STRING STRING measure measure
1337 measure measure number number flags
']' '('
1339 yyElement
= CreateNewElement
(yyData
, yyFont
, $3,
1340 $4, $5, $6, NU
($7) + NU
($9), NU
($8) + NU
($10),
1341 $11, $12, $13, false
);
1342 yyElement
->MarkX
= NU
($7);
1343 yyElement
->MarkY
= NU
($8);
1350 SetElementBoundingBox
(yyData
, yyElement
, yyFont
);
1354 /* %start-doc pcbfile ElementLine
1357 ElementLine [X1 Y1 X2 Y2 Thickness]
1358 ElementLine (X1 Y1 X2 Y2 Thickness)
1363 Coordinates of the endpoints of the line. These are relative to the
1364 Element's mark point for new element formats, or absolute for older
1367 The width of the silk for this line.
1372 /* %start-doc pcbfile ElementArc
1375 ElementArc [X Y Width Height StartAngle DeltaAngle Thickness]
1376 ElementArc (X Y Width Height StartAngle DeltaAngle Thickness)
1381 Coordinates of the center of the arc. These are relative to the
1382 Element's mark point for new element formats, or absolute for older
1385 The width and height, from the center to the edge. The bounds of the
1386 circle of which this arc is a segment, is thus @math{2*Width} by
1389 The angle of one end of the arc, in degrees. In PCB, an angle of zero
1390 points left (negative X direction), and 90 degrees points down
1391 (positive Y direction).
1393 The sweep of the arc. This may be negative. Positive angles sweep
1396 The width of the silk line which forms the arc.
1401 /* %start-doc pcbfile Mark
1410 Coordinates of the Mark, for older element formats that don't have
1411 the mark as part of the Element line.
1418 | elementdefinitions elementdefinition
1427 /* x1, y1, x2, y2, thickness */
1428 | T_ELEMENTLINE
'[' measure measure measure measure measure
']'
1430 CreateNewLineInElement
(yyElement
, NU
($3), NU
($4), NU
($5), NU
($6), NU
($7));
1432 /* x1, y1, x2, y2, thickness */
1433 | T_ELEMENTLINE
'(' measure measure measure measure measure
')'
1435 CreateNewLineInElement
(yyElement
, OU
($3), OU
($4), OU
($5), OU
($6), OU
($7));
1437 /* x, y, width, height, startangle, anglediff, thickness */
1438 | T_ELEMENTARC
'[' measure measure measure measure number number measure
']'
1440 CreateNewArcInElement
(yyElement
, NU
($3), NU
($4), NU
($5), NU
($6), $7, $8, NU
($9));
1442 /* x, y, width, height, startangle, anglediff, thickness */
1443 | T_ELEMENTARC
'(' measure measure measure measure number number measure
')'
1445 CreateNewArcInElement
(yyElement
, OU
($3), OU
($4), OU
($5), OU
($6), $7, $8, OU
($9));
1448 | T_MARK
'[' measure measure
']'
1450 yyElement
->MarkX
= NU
($3);
1451 yyElement
->MarkY
= NU
($4);
1453 | T_MARK
'(' measure measure
')'
1455 yyElement
->MarkX
= OU
($3);
1456 yyElement
->MarkY
= OU
($4);
1458 |
{ attr_list
= & yyElement
->Attributes
; } attribute
1463 | relementdefs relementdef
1471 /* x1, y1, x2, y2, thickness */
1472 | T_ELEMENTLINE
'[' measure measure measure measure measure
']'
1474 CreateNewLineInElement
(yyElement
, NU
($3) + yyElement
->MarkX
,
1475 NU
($4) + yyElement
->MarkY
, NU
($5) + yyElement
->MarkX
,
1476 NU
($6) + yyElement
->MarkY
, NU
($7));
1478 | T_ELEMENTLINE
'(' measure measure measure measure measure
')'
1480 CreateNewLineInElement
(yyElement
, OU
($3) + yyElement
->MarkX
,
1481 OU
($4) + yyElement
->MarkY
, OU
($5) + yyElement
->MarkX
,
1482 OU
($6) + yyElement
->MarkY
, OU
($7));
1484 /* x, y, width, height, startangle, anglediff, thickness */
1485 | T_ELEMENTARC
'[' measure measure measure measure number number measure
']'
1487 CreateNewArcInElement
(yyElement
, NU
($3) + yyElement
->MarkX
,
1488 NU
($4) + yyElement
->MarkY
, NU
($5), NU
($6), $7, $8, NU
($9));
1490 | T_ELEMENTARC
'(' measure measure measure measure number number measure
')'
1492 CreateNewArcInElement
(yyElement
, OU
($3) + yyElement
->MarkX
,
1493 OU
($4) + yyElement
->MarkY
, OU
($5), OU
($6), $7, $8, OU
($9));
1495 |
{ attr_list
= & yyElement
->Attributes
; } attribute
1498 /* %start-doc pcbfile Pin
1501 Pin [rX rY Thickness Clearance Mask Drill "Name" "Number" SFlags]
1502 Pin (rX rY Thickness Clearance Mask Drill "Name" "Number" NFlags)
1503 Pin (aX aY Thickness Drill "Name" "Number" NFlags)
1504 Pin (aX aY Thickness Drill "Name" NFlags)
1505 Pin (aX aY Thickness "Name" NFlags)
1510 coordinates of center, relative to the element's mark
1512 absolute coordinates of center.
1514 outer diameter of copper annulus
1516 add to thickness to get clearance diameter
1518 diameter of solder mask opening
1526 symbolic or numerical flags
1528 numerical flags only
1534 /* x, y, thickness, clearance, mask, drilling hole, name,
1536 : T_PIN
'[' measure measure measure measure measure measure STRING STRING flags
']'
1538 CreateNewPin
(yyElement
, NU
($3) + yyElement
->MarkX
,
1539 NU
($4) + yyElement
->MarkY
, NU
($5), NU
($6), NU
($7), NU
($8), $9,
1546 /* x, y, thickness, clearance, mask, drilling hole, name,
1548 : T_PIN
'(' measure measure measure measure measure measure STRING STRING INTEGER
')'
1550 CreateNewPin
(yyElement
, OU
($3) + yyElement
->MarkX
,
1551 OU
($4) + yyElement
->MarkY
, OU
($5), OU
($6), OU
($7), OU
($8), $9,
1552 $10, OldFlags
($11));
1559 /* x, y, thickness, drilling hole, name, number, flags */
1560 : T_PIN
'(' measure measure measure measure STRING STRING INTEGER
')'
1562 CreateNewPin
(yyElement
, OU
($3), OU
($4), OU
($5), 2*GROUNDPLANEFRAME
,
1563 OU
($5) + 2*MASKFRAME
, OU
($6), $7, $8, OldFlags
($9));
1570 /* x, y, thickness, drilling hole, name, flags */
1571 : T_PIN
'(' measure measure measure measure STRING INTEGER
')'
1575 sprintf
(p_number
, "%d", pin_num
++);
1576 CreateNewPin
(yyElement
, OU
($3), OU
($4), OU
($5), 2*GROUNDPLANEFRAME
,
1577 OU
($5) + 2*MASKFRAME
, OU
($6), $7, p_number
, OldFlags
($8));
1584 /* old format: x, y, thickness, name, flags
1585 * drilling hole is 40% of the diameter
1587 : T_PIN
'(' measure measure measure STRING INTEGER
')'
1589 Coord hole
= OU
($5) * DEFAULT_DRILLINGHOLE
;
1592 /* make sure that there's enough copper left */
1593 if
(OU
($5) - hole
< MIN_PINORVIACOPPER
&&
1594 OU
($5) > MIN_PINORVIACOPPER
)
1595 hole
= OU
($5) - MIN_PINORVIACOPPER
;
1597 sprintf
(p_number
, "%d", pin_num
++);
1598 CreateNewPin
(yyElement
, OU
($3), OU
($4), OU
($5), 2*GROUNDPLANEFRAME
,
1599 OU
($5) + 2*MASKFRAME
, hole
, $6, p_number
, OldFlags
($7));
1604 /* %start-doc pcbfile Pad
1607 Pad [rX1 rY1 rX2 rY2 Thickness Clearance Mask "Name" "Number" SFlags]
1608 Pad (rX1 rY1 rX2 rY2 Thickness Clearance Mask "Name" "Number" NFlags)
1609 Pad (aX1 aY1 aX2 aY2 Thickness "Name" "Number" NFlags)
1610 Pad (aX1 aY1 aX2 aY2 Thickness "Name" NFlags)
1614 @item rX1 rY1 rX2 rY2
1615 Coordinates of the endpoints of the pad, relative to the element's
1616 mark. Note that the copper extends beyond these coordinates by half
1617 the thickness. To make a square or round pad, specify the same
1619 @item aX1 aY1 aX2 aY2
1620 Same, but absolute coordinates of the endpoints of the pad.
1624 add to thickness to get clearance width.
1626 width of solder mask opening.
1632 symbolic or numerical flags
1634 numerical flags only
1640 /* x1, y1, x2, y2, thickness, clearance, mask, name , pad number, flags */
1641 : T_PAD
'[' measure measure measure measure measure measure measure STRING STRING flags
']'
1643 CreateNewPad
(yyElement
, NU
($3) + yyElement
->MarkX
,
1644 NU
($4) + yyElement
->MarkY
,
1645 NU
($5) + yyElement
->MarkX
,
1646 NU
($6) + yyElement
->MarkY
, NU
($7), NU
($8), NU
($9),
1654 /* x1, y1, x2, y2, thickness, clearance, mask, name , pad number, flags */
1655 : T_PAD
'(' measure measure measure measure measure measure measure STRING STRING INTEGER
')'
1657 CreateNewPad
(yyElement
,OU
($3) + yyElement
->MarkX
,
1658 OU
($4) + yyElement
->MarkY
, OU
($5) + yyElement
->MarkX
,
1659 OU
($6) + yyElement
->MarkY
, OU
($7), OU
($8), OU
($9),
1660 $10, $11, OldFlags
($12));
1667 /* x1, y1, x2, y2, thickness, name , pad number, flags */
1668 : T_PAD
'(' measure measure measure measure measure STRING STRING INTEGER
')'
1670 CreateNewPad
(yyElement
,OU
($3),OU
($4),OU
($5),OU
($6),OU
($7), 2*GROUNDPLANEFRAME
,
1671 OU
($7) + 2*MASKFRAME
, $8, $9, OldFlags
($10));
1678 /* x1, y1, x2, y2, thickness, name and flags */
1679 : T_PAD
'(' measure measure measure measure measure STRING INTEGER
')'
1683 sprintf
(p_number
, "%d", pin_num
++);
1684 CreateNewPad
(yyElement
,OU
($3),OU
($4),OU
($5),OU
($6),OU
($7), 2*GROUNDPLANEFRAME
,
1685 OU
($7) + 2*MASKFRAME
, $8,p_number
, OldFlags
($9));
1690 flags
: INTEGER
{ $$
= OldFlags
($1); }
1691 | STRING
{ $$
= string_to_flags
($1, yyerror); }
1699 /* %start-doc pcbfile Symbol
1702 Symbol [Char Delta] (
1703 Symbol (Char Delta) (
1704 @ @ @ @dots{} symbol lines @dots{}
1710 The character or numerical character value this symbol represents.
1711 Characters must be in single quotes.
1713 Additional space to allow after this character.
1718 symbol
: symbolhead symboldata
')'
1720 symbolhead
: T_SYMBOL
'[' symbolid measure
']' '('
1722 if
($3 <= 0 ||
$3 > MAX_FONTPOSITION
)
1724 yyerror("fontposition out of range");
1727 Symbol
= &yyFont
->Symbol
[$3];
1730 yyerror("symbol ID used twice");
1733 Symbol
->Valid
= true
;
1734 Symbol
->Delta
= NU
($4);
1736 | T_SYMBOL
'(' symbolid measure
')' '('
1738 if
($3 <= 0 ||
$3 > MAX_FONTPOSITION
)
1740 yyerror("fontposition out of range");
1743 Symbol
= &yyFont
->Symbol
[$3];
1746 yyerror("symbol ID used twice");
1749 Symbol
->Valid
= true
;
1750 Symbol
->Delta
= OU
($4);
1761 | symboldata symboldefinition
1762 | symboldata hiressymbol
1765 /* %start-doc pcbfile SymbolLine
1768 SymbolLine [X1 Y1 X2 Y2 Thickness]
1769 SymbolLine (X1 Y1 X2 Y2 Thickness)
1774 The endpoints of this line.
1776 The width of this line.
1782 /* x1, y1, x2, y2, thickness */
1783 : T_SYMBOLLINE
'(' measure measure measure measure measure
')'
1785 CreateNewLineInSymbol
(Symbol
, OU
($3), OU
($4), OU
($5), OU
($6), OU
($7));
1789 /* x1, y1, x2, y2, thickness */
1790 : T_SYMBOLLINE
'[' measure measure measure measure measure
']'
1792 CreateNewLineInSymbol
(Symbol
, NU
($3), NU
($4), NU
($5), NU
($6), NU
($7));
1796 /* %start-doc pcbfile Netlist
1800 @ @ @ @dots{} nets @dots{}
1806 pcbnetlist
: pcbnetdef
1810 /* net(...) net(...) ... */
1811 : T_NETLIST
'(' ')' '('
1825 /* %start-doc pcbfile Net
1828 Net ("Name" "Style") (
1829 @ @ @ @dots{} connects @dots{}
1835 The name of this net.
1837 The routing style that should be used when autorouting this net.
1843 /* name style pin pin ... */
1844 : T_NET
'(' STRING STRING
')' '('
1846 Menu
= CreateNewNet
(&yyPCB
->NetlistLib
, $3, $4);
1863 /* %start-doc pcbfile Connect
1871 The name of a pin or pad which is included in this net. Pin and Pad
1872 names are named by the refdes and pin name, like @code{"U14-7"} for
1873 pin 7 of U14, or @code{"T4-E"} for pin E of T4.
1879 : T_CONN
'(' STRING
')'
1881 CreateNewConnection
(Menu
, $3);
1886 /* %start-doc pcbfile Attribute
1889 Attribute ("Name" "Value")
1892 Attributes allow boards and elements to have arbitrary data attached
1893 to them, which is not directly used by PCB itself but may be of use by
1894 other programs or users.
1898 The name of the attribute
1901 The value of the attribute. Values are always stored as strings, even
1902 if the value is interpreted as, for example, a number.
1909 : T_ATTRIBUTE
'(' STRING STRING
')'
1911 CreateNewAttribute
(attr_list
, $3, $4 ?
$4 : (char *)"");
1917 opt_string
: STRING
{ $$
= $1; }
1918 |
/* empty */ { $$
= 0; }
1922 : FLOATING
{ $$
= $1; }
1923 | INTEGER
{ $$
= $1; }
1927 /* Default unit (no suffix) is cmil */
1928 : number
{ do_measure
(&$$
, $1, MIL_TO_COORD
($1) / 100.0, 0); }
1929 | number T_UMIL
{ M
($$
, $1, MIL_TO_COORD
($1) / 100000.0); }
1930 | number T_CMIL
{ M
($$
, $1, MIL_TO_COORD
($1) / 100.0); }
1931 | number T_MIL
{ M
($$
, $1, MIL_TO_COORD
($1)); }
1932 | number T_IN
{ M
($$
, $1, INCH_TO_COORD
($1)); }
1933 | number T_NM
{ M
($$
, $1, MM_TO_COORD
($1) / 1000000.0); }
1934 | number T_PX
{ M
($$
, $1, MM_TO_COORD
($1) / 1000000.0); }
1935 | number T_UM
{ M
($$
, $1, MM_TO_COORD
($1) / 1000.0); }
1936 | number T_MM
{ M
($$
, $1, MM_TO_COORD
($1)); }
1937 | number T_M
{ M
($$
, $1, MM_TO_COORD
($1) * 1000.0); }
1938 | number T_KM
{ M
($$
, $1, MM_TO_COORD
($1) * 1000000.0); }
1943 /* ---------------------------------------------------------------------------
1944 * error routine called by parser library
1946 int yyerror(const char * s
)
1948 Message
("ERROR parsing file '%s'\n"
1950 " description: '%s'\n",
1951 yyfilename
, yylineno
, s
);
1961 check_file_version
(int ver
)
1963 if
( ver
> PCB_FILE_VERSION
) {
1964 Message
("ERROR: The file you are attempting to load is in a format\n"
1965 "which is too new for this version of pcb. To load this file\n"
1966 "you need a version of pcb which is >= %d. If you are\n"
1967 "using a version built from git source, the source date\n"
1968 "must be >= %d. This copy of pcb can only read files\n"
1969 "up to file version %d.\n", ver
, ver
, PCB_FILE_VERSION
);
1977 do_measure
(PLMeasure
*m
, Coord i
, double d
, int u
)
1980 m
->bval
= round
(d
);
1986 integer_value
(PLMeasure m
)
1989 yyerror("units ignored here");
1994 old_units
(PLMeasure m
)
1998 return round
(MIL_TO_COORD
(m.ival
));
2002 new_units
(PLMeasure m
)
2006 return round
(MIL_TO_COORD
(m.ival
) / 100.0);