hid/gtk: Fix pinout preview rendering for back-side elements
[geda-pcb/pcjc2.git] / src / flags.c
blobde77b68ca7eff3ac238cac06476ebdd9ae28cc9c
1 /* $Id$ */
3 /*
4 * COPYRIGHT
6 * PCB, interactive printed circuit board design
7 * Copyright (C) 2005 DJ Delorie
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
30 #include <math.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #ifdef HAVE_STRING_H
34 #include <string.h>
35 #endif
37 #include "global.h"
38 #include "data.h"
39 #include "pcb-printf.h"
41 #ifdef HAVE_LIBDMALLOC
42 #include <dmalloc.h>
43 #endif
45 RCSID ("$Id$");
47 static int
48 FlagCurrentStyle (int dummy)
50 STYLE_LOOP (PCB);
52 if (style->Thick == Settings.LineThickness &&
53 style->Diameter == Settings.ViaThickness &&
54 style->Hole == Settings.ViaDrillingHole &&
55 style->Keepaway == Settings.Keepaway)
56 return n + 1;
58 END_LOOP;
59 return 0;
62 static int
63 FlagGrid (int dummy)
65 return PCB->Grid > 1;
68 static int
69 FlagGridSize (int dummy)
71 return PCB->Grid;
74 static int
75 FlagUnitsMm (int dummy)
77 static const Unit *u = NULL;
78 if (u == NULL)
79 u = get_unit_struct ("mm");
80 return (Settings.grid_unit == u);
83 static int
84 FlagUnitsMil (int dummy)
86 static const Unit *u = NULL;
87 if (u == NULL)
88 u = get_unit_struct ("mil");
89 return (Settings.grid_unit == u);
92 static int
93 FlagBuffer (int dummy)
95 return (int) (Settings.BufferNumber + 1);
98 static int
99 FlagElementName (int dummy)
101 if (TEST_FLAG (NAMEONPCBFLAG, PCB))
102 return 2;
103 if (TEST_FLAG (DESCRIPTIONFLAG, PCB))
104 return 1;
105 return 3;
108 static int
109 FlagTESTFLAG (int bit)
111 return TEST_FLAG (bit, PCB) ? 1 : 0;
114 static int
115 FlagSETTINGS (int ofs)
117 return *(bool *) ((char *) (&Settings) + ofs);
120 static int
121 FlagMode (int x)
123 if (x == -1)
124 return Settings.Mode;
125 return Settings.Mode == x;
128 static int
129 FlagHaveRegex (int x)
131 #if defined(HAVE_REGCOMP) || defined(HAVE_RE_COMP)
132 return 1;
133 #else
134 return 0;
135 #endif
138 enum {
139 FL_SILK = -6,
140 FL_PINS,
141 FL_RATS,
142 FL_VIAS,
143 FL_BACK,
144 FL_MASK
147 static int
148 FlagLayerShown (int n)
150 switch (n)
152 case FL_SILK:
153 return PCB->ElementOn;
154 case FL_PINS:
155 return PCB->PinOn;
156 case FL_RATS:
157 return PCB->RatOn;
158 case FL_VIAS:
159 return PCB->ViaOn;
160 case FL_BACK:
161 return PCB->InvisibleObjectsOn;
162 case FL_MASK:
163 return TEST_FLAG (SHOWMASKFLAG, PCB);
164 default:
165 if (n >= 0 && n < max_copper_layer)
166 return PCB->Data->Layer[n].On;
168 return 0;
171 static int
172 FlagLayerActive (int n)
174 int current_layer;
175 if (PCB->RatDraw)
176 current_layer = FL_RATS;
177 else if (PCB->SilkActive)
178 current_layer = FL_SILK;
179 else
180 return 0;
182 return current_layer == n;
185 /* The cast to (int) is ONLY valid because we know we are
186 * taking offsets on structures where the offset will fit
187 * in an integer variable. It silences compile warnings on
188 * 64bit machines.
190 #define OffsetOf(a,b) (int)(size_t)(&(((a *)0)->b))
192 HID_Flag flags_flag_list[] = {
193 {"style", FlagCurrentStyle, 0},
194 {"grid", FlagGrid, 0},
195 {"gridsize", FlagGridSize, 0},
196 {"elementname", FlagElementName, 0},
197 {"have_regex", FlagHaveRegex, 0},
199 {"silk_shown", FlagLayerShown, FL_SILK},
200 {"pins_shown", FlagLayerShown, FL_PINS},
201 {"rats_shown", FlagLayerShown, FL_RATS},
202 {"vias_shown", FlagLayerShown, FL_VIAS},
203 {"back_shown", FlagLayerShown, FL_BACK},
204 {"mask_shown", FlagLayerShown, FL_MASK},
205 {"silk_active", FlagLayerActive, FL_SILK},
206 {"rats_active", FlagLayerActive, FL_RATS},
208 {"mode", FlagMode, -1},
209 {"nomode", FlagMode, NO_MODE},
210 {"arcmode", FlagMode, ARC_MODE},
211 {"arrowmode", FlagMode, ARROW_MODE},
212 {"copymode", FlagMode, COPY_MODE},
213 {"insertpointmode", FlagMode, INSERTPOINT_MODE},
214 {"linemode", FlagMode, LINE_MODE},
215 {"lockmode", FlagMode, LOCK_MODE},
216 {"movemode", FlagMode, MOVE_MODE},
217 {"pastebuffermode", FlagMode, PASTEBUFFER_MODE},
218 {"polygonmode", FlagMode, POLYGON_MODE},
219 {"polygonholemode", FlagMode, POLYGONHOLE_MODE},
220 {"rectanglemode", FlagMode, RECTANGLE_MODE},
221 {"removemode", FlagMode, REMOVE_MODE},
222 {"rotatemode", FlagMode, ROTATE_MODE},
223 {"rubberbandmovemode", FlagMode, RUBBERBANDMOVE_MODE},
224 {"textmode", FlagMode, TEXT_MODE},
225 {"thermalmode", FlagMode, THERMAL_MODE},
226 {"viamode", FlagMode, VIA_MODE},
228 {"shownumber", FlagTESTFLAG, SHOWNUMBERFLAG},
229 {"localref", FlagTESTFLAG, LOCALREFFLAG},
230 {"checkplanes", FlagTESTFLAG, CHECKPLANESFLAG},
231 {"showdrc", FlagTESTFLAG, SHOWDRCFLAG},
232 {"rubberband", FlagTESTFLAG, RUBBERBANDFLAG},
233 {"description", FlagTESTFLAG, DESCRIPTIONFLAG},
234 {"nameonpcb", FlagTESTFLAG, NAMEONPCBFLAG},
235 {"autodrc", FlagTESTFLAG, AUTODRCFLAG},
236 {"alldirection", FlagTESTFLAG, ALLDIRECTIONFLAG},
237 {"swapstartdir", FlagTESTFLAG, SWAPSTARTDIRFLAG},
238 {"uniquename", FlagTESTFLAG, UNIQUENAMEFLAG},
239 {"clearnew", FlagTESTFLAG, CLEARNEWFLAG},
240 {"snappin", FlagTESTFLAG, SNAPPINFLAG},
241 {"showmask", FlagTESTFLAG, SHOWMASKFLAG},
242 {"thindraw", FlagTESTFLAG, THINDRAWFLAG},
243 {"orthomove", FlagTESTFLAG, ORTHOMOVEFLAG},
244 {"liveroute", FlagTESTFLAG, LIVEROUTEFLAG},
245 {"thindrawpoly", FlagTESTFLAG, THINDRAWPOLYFLAG},
246 {"locknames", FlagTESTFLAG, LOCKNAMESFLAG},
247 {"onlynames", FlagTESTFLAG, ONLYNAMESFLAG},
248 {"newfullpoly", FlagTESTFLAG, NEWFULLPOLYFLAG},
249 {"hidenames", FlagTESTFLAG, HIDENAMESFLAG},
251 {"fullpoly", FlagSETTINGS, OffsetOf (SettingType, FullPoly)},
252 {"grid_units_mm", FlagUnitsMm, -1},
253 {"grid_units_mil", FlagUnitsMil, -1},
254 {"clearline", FlagSETTINGS, OffsetOf (SettingType, ClearLine)},
255 {"uniquenames", FlagSETTINGS, OffsetOf (SettingType, UniqueNames)},
256 {"showsolderside", FlagSETTINGS, OffsetOf (SettingType, ShowSolderSide)},
257 {"savelastcommand", FlagSETTINGS, OffsetOf (SettingType, SaveLastCommand)},
258 {"saveintmp", FlagSETTINGS, OffsetOf (SettingType, SaveInTMP)},
259 {"drawgrid", FlagSETTINGS, OffsetOf (SettingType, DrawGrid)},
260 {"ratwarn", FlagSETTINGS, OffsetOf (SettingType, RatWarn)},
261 {"stipplepolygons", FlagSETTINGS, OffsetOf (SettingType, StipplePolygons)},
262 {"alldirectionlines", FlagSETTINGS,
263 OffsetOf (SettingType, AllDirectionLines)},
264 {"rubberbandmode", FlagSETTINGS, OffsetOf (SettingType, RubberBandMode)},
265 {"swapstartdirection", FlagSETTINGS,
266 OffsetOf (SettingType, SwapStartDirection)},
267 {"showdrcmode", FlagSETTINGS, OffsetOf (SettingType, ShowDRC)},
268 {"resetafterelement", FlagSETTINGS,
269 OffsetOf (SettingType, ResetAfterElement)},
270 {"ringbellwhenfinished", FlagSETTINGS,
271 OffsetOf (SettingType, RingBellWhenFinished)},
273 {"buffer", FlagBuffer, 0},
277 REGISTER_FLAGS (flags_flag_list)