1 /*!
2  * \file src/const.h
3  *
4  * \brief Global source constants.
5  *
6  * <hr>
7  *
8  * PCB, interactive printed circuit board design
9  *
10  * Copyright (C) 1994,1995,1996 Thomas Nau
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along
23  * with this program; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * Contact addresses for paper mail and Email:
27  * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
28  * Thomas.Nau@rz.uni-ulm.de
29  */
30 
31 #ifndef	PCB_CONST_H
32 #define	PCB_CONST_H
33 
34 #include <limits.h>
35 #include <math.h>
36 
37 #include "globalconst.h"
38 
39 /* ---------------------------------------------------------------------------
40  * integer codings for the board sides.
41  */
42 #define BOTTOM_SIDE             0
43 #define TOP_SIDE                1
44 
45 
46 /*!
47  * Layer Stack.
48  *
49  * The situation is not ideal, because on top of the ordinary layer stack
50  * there are two (both) silk layers. It was a hack to separate these and
51  * probably done to easier iterate through non-silk layers, only. As we have
52  * layer types now, iterating through any kind of distinct layer type has
53  * become simple, see LAYER_TYPE_LOOP() in macro.h.
54  *
55  * Accordingly, the separation of these two silk layers should go away, they
56  * should return to be "normal" layers. One might want to have more than two
57  * silk layers, after all.
58  *
59  * Anyways, here's the current setup:
60  *
61  *   Copper layer 0             \
62  *   Copper layer 1             |
63  *   Outline layer              >- in unspecified order
64  *   Routing layer              |
65  *   (...additional layers...)  /     <== max_copper_layer
66  *   Bottom silk layer
67  *   Top silk layer                   <== max_copper_layer + SILK_LAYER
68  *   (...unused layers...)
69  *   (last layer - 2)                 <== MAX_LAYER
70  *   (last layer - 1)
71  *   (last layer)                     <== MAX_ALL_LAYER
72  *                                        ( == MAX_LAYER + SILK_LAYER)
73  *
74  * With all layers in use (rarely the case), max_copper_layer == MAX_LAYER.
75  *
76  * \note Position on the layer stack does not decide whether a layer is on the
77  *       top side, on the bottom side or in between. Each layer is part of a
78  *       layer group, and this group represents the physical layer, like top,
79  *       inner or bottom.
80  */
81 
82 
83 /* ---------------------------------------------------------------------------
84  * the layer-numbers of the two additional special (silkscreen) layers
85  * 'bottom' and 'top'. The offset of MAX_LAYER is not added
86  */
87 #define SILK_LAYER              2
88 #define BOTTOM_SILK_LAYER       0
89 #define TOP_SILK_LAYER          1
90 
91 /* ---------------------------------------------------------------------------
92  * the resulting maximum number of layers, including additional silk layers
93  */
94 #define MAX_ALL_LAYER           (MAX_LAYER + SILK_LAYER)
95 
96 /* ---------------------------------------------------------------------------
97  * misc constants
98  */
99 #define	MARK_SIZE		MIL_TO_COORD(50)	/*!< relative marker size */
100 #define	UNDO_WARNING_SIZE	(1024*1024)	/*!< warning limit of undo */
101 #define	USERMEDIANAME		"user defined"	/*!< label of default media */
102 
103 /* ---------------------------------------------------------------------------
104  * some math constants
105  */
106 #ifndef	M_PI
107 #define	M_PI			3.14159265358979323846
108 #endif
109 #ifndef M_SQRT1_2
110 #define M_SQRT1_2 		0.707106781	/*!< 1/sqrt(2) */
111 #endif
112 #define	M180			(M_PI/180.0)
113 #define RAD_TO_DEG		(180.0/M_PI)
114 #define	TAN_22_5_DEGREE_2	0.207106781	/*!< 0.5*tan(22.5) */
115 #define COS_22_5_DEGREE		0.923879533	/*!< cos(22.5) */
116 #define	TAN_30_DEGREE		0.577350269	/*!< tan(30) */
117 #define	TAN_60_DEGREE		1.732050808	/*!< tan(60) */
118 #define LN_2_OVER_2		0.346573590
119 
120 /* PCB/physical unit conversions */
121 #define COORD_TO_MIL(n)	((n) / 25400.0)
122 #define MIL_TO_COORD(n)	((n) * 25400.0)
123 #define COORD_TO_MM(n)	((n) / 1000000.0)
124 #define MM_TO_COORD(n)	((n) * 1000000.0)
125 #define COORD_TO_INCH(n)	(COORD_TO_MIL(n) / 1000.0)
126 #define INCH_TO_COORD(n)	(MIL_TO_COORD(n) * 1000.0)
127 
128 /* These need to be carefully written to avoid overflows, and return
129    a Coord type.  */
130 #define SCALE_TEXT(COORD,TEXTSCALE) ((Coord)((COORD) * ((double)(TEXTSCALE) / 100.0)))
131 #define UNSCALE_TEXT(COORD,TEXTSCALE) ((Coord)((COORD) * (100.0 / (double)(TEXTSCALE))))
132 
133 /* ---------------------------------------------------------------------------
134  * modes
135  */
136 #define	NO_MODE			0	/*!< no mode selected */
137 #define	VIA_MODE		1	/*!< draw vias */
138 #define	LINE_MODE		2	/*!< draw lines */
139 #define	RECTANGLE_MODE		3	/*!< create rectangles */
140 #define	POLYGON_MODE		4	/*!< draw filled polygons */
141 #define	PASTEBUFFER_MODE	5	/*!< paste objects from buffer */
142 #define	TEXT_MODE		6	/*!< create text objects */
143 #define	ROTATE_MODE		102	/*!< rotate objects */
144 #define	REMOVE_MODE		103	/*!< remove objects */
145 #define	MOVE_MODE		104	/*!< move objects */
146 #define	COPY_MODE		105	/*!< copy objects */
147 #define	INSERTPOINT_MODE	106	/*!< insert point into line/polygon */
148 #define	RUBBERBANDMOVE_MODE	107	/*!< move objects and attached lines */
149 #define THERMAL_MODE            108	/*!< toggle thermal layer flag */
150 #define ARC_MODE                109	/*!< draw arcs */
151 #define ARROW_MODE		110	/*!< selection with arrow mode */
152 #define PAN_MODE                0	/*!< same as no mode */
153 #define LOCK_MODE               111	/*!< lock/unlock objects */
154 #define	POLYGONHOLE_MODE	112	/*!< cut holes in filled polygons */
155 
156 /* ---------------------------------------------------------------------------
157  * object flags
158  */
159 
160 /* %start-doc pcbfile ~objectflags
161 @node Object Flags
162 @section Object Flags
163 
164 Note that object flags can be given numerically (like @code{0x0147})
165 or symbolically (like @code{"found,showname,square"}.  Some numeric
166 values are reused for different object types.  The table below lists
167 the numeric value followed by the symbolic name.
168 
169 @table @code
170 @item 0x0001 pin
171 If set, this object is a pin.  This flag is for internal use only.
172 @item 0x0002 via
173 Likewise, for vias.
174 @item 0x0004 found
175 If set, this object has been found by @code{FindConnection()}.
176 @item 0x0008 hole
177 For pins and vias, this flag means that the pin or via is a hole
178 without a copper annulus.
179 @item 0x0008 nopaste
180 For pads, set to prevent a solderpaste stencil opening for the
181 pad.  Primarily used for pads used as fiducials.
182 @item 0x0010 rat
183 If set for a line, indicates that this line is a rat line instead of a
184 copper trace.
185 @item 0x0010 pininpoly
186 For pins and pads, this flag is used internally to indicate that the
187 pin or pad overlaps a polygon on some layer.
188 @item 0x0010 clearpoly
189 For polygons, this flag means that pins and vias will normally clear
190 these polygons (thus, thermals are required for electrical
191 connection).  When clear, polygons will solidly connect to pins and
192 vias.
193 @item 0x0010 hidename
194 For elements, when set the name of the element is hidden.
195 @item 0x0020 showname
196 For elements, when set the names of pins are shown.
197 @item 0x0020 clearline
198 For lines and arcs, the line/arc will clear polygons instead of
199 connecting to them.
200 @item 0x0020 fullpoly
201 For polygons, the full polygon is drawn (i.e. all parts instead of only the biggest one).
202 @item 0x0040 selected
203 Set when the object is selected.
204 @item 0x0080 onsolder
205 For elements and pads, indicates that they are on the solder side.
206 @item 0x0080 auto
207 For lines and vias, indicates that these were created by the
208 autorouter.
209 @item 0x0100 square
210 For pins and pads, indicates a square (vs round) pin/pad.
211 @item 0x0200 rubberend
212 For lines, used internally for rubber band moves.
213 @item 0x0200 warn
214 For pins, vias, and pads, set to indicate a warning.
215 @item 0x0400 usetherm
216 Obsolete, indicates that pins/vias should be drawn with thermal
217 fingers.
218 @item 0x0400
219 Obsolete, old files used this to indicate lines drawn on silk.
220 @item 0x0800 octagon
221 Draw pins and vias as octagons.
222 @item 0x1000 drc
223 Set for objects that fail DRC.
224 @item 0x2000 lock
225 Set for locked objects.
226 @item 0x4000 edge2
227 For pads, indicates that the second point is closer to the edge.  For
228 pins, indicates that the pin is closer to a horizontal edge and thus
229 pinout text should be vertical.
230 @item 0x8000 marker
231 Marker used internally to avoid revisiting an object.
232 @item 0x10000 connected
233 If set, this object has been as physically connected by @code{FindConnection()}.
234 @end table
235 %end-doc */
236 
237 #define NOFLAG                  0x0000
238 #define PINFLAG                 0x0001  /*!< is a pin */
239 #define VIAFLAG                 0x0002  /*!< is a via */
240 #define FOUNDFLAG               0x0004  /*!< used by 'FindConnection()' */
241 #define HOLEFLAG                0x0008  /*!< pin or via is only a hole */
242 #define NOPASTEFLAG             0x0008  /*!< pad should not receive
243                                              solderpaste.  This is to
244                                              support fiducials */
245 #define RATFLAG                 0x0010  /*!< indicates line is a rat line */
246 #define PININPOLYFLAG           0x0010  /*!< pin found inside poly - same as */
247                                         /*!< rat line since not used on lines */
248 #define CLEARPOLYFLAG           0x0010  /*!< pins/vias clear these polygons */
249 #define HIDENAMEFLAG            0x0010  /*!< hide the element name */
250 #define DISPLAYNAMEFLAG         0x0020  /*!< display the names of pins/pads
251                                              of an element */
252 #define CLEARLINEFLAG           0x0020  /*!< line doesn't touch polygons */
253 #define FULLPOLYFLAG            0x0020  /*!< full polygon is drawn (i.e. all parts instead of only the biggest one) */
254 #define SELECTEDFLAG            0x0040  /*!< object has been selected */
255 #define ONSOLDERFLAG            0x0080  /*!< element is on bottom side */
256 #define AUTOFLAG                0x0080  /*!< line/via created by auto-router */
257 #define SQUAREFLAG              0x0100  /*!< pin is square, not round */
258 #define RUBBERENDFLAG           0x0200  /*!< indicates one end already rubber
259                                              banding same as warn flag
260                                              since pins/pads won't use it */
261 #define WARNFLAG                0x0200  /*!< Warning for pin/via/pad */
262 #define USETHERMALFLAG          0x0400  /*!< draw pin, via with thermal fingers */
263 #define ONSILKFLAG              0x0400  /*!< old files use this to indicate silk */
264 #define OCTAGONFLAG             0x0800  /*!< draw pin/via as octagon instead of round */
265 #define DRCFLAG                 0x1000  /*!< flag like FOUND flag for DRC checking */
266 #define LOCKFLAG                0x2000  /*!< object locked in place */
267 #define EDGE2FLAG               0x4000  /*!< Padr.Point2 is closer to outside edge
268                                              also pinout text for pins is vertical */
269 #define VISITFLAG               0x8000  /*!< marker to avoid re-visiting an object */
270 #define CONNECTEDFLAG          0x10000  /*!< flag like FOUND flag, but used to identify physically connected objects (not rats) */
271 
272 
273 #define NOCOPY_FLAGS (FOUNDFLAG | CONNECTEDFLAG)
274 
275 /* ---------------------------------------------------------------------------
276  * PCB flags
277  */
278 
279 /* %start-doc pcbfile ~pcbflags
280 @node PCBFlags
281 @section PCBFlags
282 @table @code
283 @item 0x00001
284 Pinout displays pin numbers instead of pin names.
285 @item 0x00002
286 Use local reference for moves, by setting the mark at the beginning of
287 each move.
288 @item 0x00004
289 When set, only polygons and their clearances are drawn, to see if
290 polygons have isolated regions.
291 @item 0x00008
292 Display DRC region on crosshair.
293 @item 0x00010
294 Do all move, mirror, rotate with rubberband connections.
295 @item 0x00020
296 Display descriptions of elements, instead of refdes.
297 @item 0x00040
298 Display names of elements, instead of refdes.
299 @item 0x00080
300 Auto-DRC flag.  When set, PCB doesn't let you place copper that
301 violates DRC.
302 @item 0x00100
303 Enable 'all-direction' lines.
304 @item 0x00200
305 Switch starting angle after each click.
306 @item 0x00400
307 Force unique names on board.
308 @item 0x00800
309 New lines/arc clear polygons.
310 @item 0x01000
311 Crosshair snaps to pins and pads.
312 @item 0x02000
313 Show the solder mask layer.
314 @item 0x04000
315 Draw with thin lines.
316 @item 0x08000
317 Move items orthogonally.
318 @item 0x10000
319 Draw autoroute paths real-time.
320 @item 0x20000
321 New polygons are full ones.
322 @item 0x40000
323 Names are locked, the mouse cannot select them.
324 @item 0x80000
325 Everything but names are locked, the mouse cannot select anything else.
326 @item 0x100000
327 New polygons are full polygons.
328 @item 0x200000
329 When set, element names are not drawn.
330 @end table
331 %end-doc */
332 
333 #define	PCB_FLAGS		0x000fffff	/* all used flags */
334 
335 #define SHOWNUMBERFLAG          0x00000001
336 #define LOCALREFFLAG            0x00000002
337 #define CHECKPLANESFLAG         0x00000004
338 #define SHOWDRCFLAG             0x00000008
339 #define RUBBERBANDFLAG		0x00000010
340 #define	DESCRIPTIONFLAG		0x00000020
341 #define	NAMEONPCBFLAG		0x00000040
342 #define AUTODRCFLAG             0x00000080
343 #define	ALLDIRECTIONFLAG	0x00000100
344 #define SWAPSTARTDIRFLAG        0x00000200
345 #define UNIQUENAMEFLAG		0x00000400
346 #define CLEARNEWFLAG		0x00000800
347 #define SNAPPINFLAG             0x00001000
348 #define SHOWMASKFLAG            0x00002000
349 #define THINDRAWFLAG            0x00004000
350 #define ORTHOMOVEFLAG           0x00008000
351 #define LIVEROUTEFLAG           0x00010000
352 #define THINDRAWPOLYFLAG        0x00020000
353 #define LOCKNAMESFLAG           0x00040000
354 #define ONLYNAMESFLAG           0x00080000
355 #define NEWFULLPOLYFLAG         0x00100000
356 #define HIDENAMESFLAG           0x00200000
357 #define AUTOBURIEDVIASFLAG      0x00400000
358 
359 /* ---------------------------------------------------------------------------
360  * object types
361  */
362 #define	NO_TYPE			0x00000	/*!< no object */
363 #define	VIA_TYPE		0x00001
364 #define	ELEMENT_TYPE		0x00002
365 #define	LINE_TYPE		0x00004
366 #define	POLYGON_TYPE		0x00008
367 #define	TEXT_TYPE		0x00010
368 #define RATLINE_TYPE		0x00020
369 
370 #define	PIN_TYPE		0x00100	/*!< objects that are part */
371 #define	PAD_TYPE		0x00200	/*!< 'pin' of SMD element */
372 #define	ELEMENTNAME_TYPE	0x00400	/*!< of others */
373 #define	POLYGONPOINT_TYPE	0x00800
374 #define	LINEPOINT_TYPE		0x01000
375 #define ELEMENTLINE_TYPE        0x02000
376 #define ARC_TYPE                0x04000
377 #define ELEMENTARC_TYPE		0x08000
378 
379 #define LOCKED_TYPE 		0x10000	/*!< used to tell search to include locked items. */
380 #define NET_TYPE		0x20000 /*!< used to select whole net. */
381 #define ARCPOINT_TYPE		0x40000
382 
383 #define PIN_TYPES     (VIA_TYPE | PIN_TYPE)
384 #define LOCK_TYPES    (VIA_TYPE | LINE_TYPE | ARC_TYPE | POLYGON_TYPE | ELEMENT_TYPE \
385                       | TEXT_TYPE | ELEMENTNAME_TYPE | LOCKED_TYPE)
386 
387 #define	ALL_TYPES		(~0)	/*!< all bits set */
388 
389 #endif
390