Move _draw_line() routine from draw.c into HID_DRAW API
[geda-pcb/pcjc2.git] / src / flags.c
blob1383e990b4ed47cb43ce1433b7974f219f7eb340
1 /*
2 * COPYRIGHT
4 * PCB, interactive printed circuit board design
5 * Copyright (C) 2005 DJ Delorie
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., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 #include <math.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #ifdef HAVE_STRING_H
32 #include <string.h>
33 #endif
35 #include "global.h"
36 #include "data.h"
37 #include "pcb-printf.h"
39 #include <glib.h>
41 #ifdef HAVE_LIBDMALLOC
42 #include <dmalloc.h>
43 #endif
45 static int
46 FlagCurrentStyle (void *data)
48 STYLE_LOOP (PCB);
50 if (style->Thick == Settings.LineThickness &&
51 style->Diameter == Settings.ViaThickness &&
52 style->Hole == Settings.ViaDrillingHole &&
53 style->Keepaway == Settings.Keepaway)
54 return n + 1;
56 END_LOOP;
57 return 0;
60 static int
61 FlagGrid (void *data)
63 return PCB->Grid > 1;
66 static int
67 FlagGridSize (void *data)
69 return PCB->Grid;
72 static int
73 FlagUnitsMm (void *data)
75 static const Unit *u = NULL;
76 if (u == NULL)
77 u = get_unit_struct ("mm");
78 return (Settings.grid_unit == u);
81 static int
82 FlagUnitsMil (void *data)
84 static const Unit *u = NULL;
85 if (u == NULL)
86 u = get_unit_struct ("mil");
87 return (Settings.grid_unit == u);
90 static int
91 FlagBuffer (void *data)
93 return (int) (Settings.BufferNumber + 1);
96 static int
97 FlagElementName (void *data)
99 if (TEST_FLAG (NAMEONPCBFLAG, PCB))
100 return 2;
101 if (TEST_FLAG (DESCRIPTIONFLAG, PCB))
102 return 1;
103 return 3;
106 static int
107 FlagTESTFLAG (void *data)
109 int bit = GPOINTER_TO_INT (data);
110 return TEST_FLAG (bit, PCB) ? 1 : 0;
113 static int
114 FlagSETTINGS (void *data)
116 size_t ofs = (size_t)data;
117 return *(bool *) ((char *)(&Settings) + ofs);
120 static int
121 FlagMode (void *data)
123 int x = GPOINTER_TO_INT (data);
124 if (x == -1)
125 return Settings.Mode;
126 return Settings.Mode == x;
129 static int
130 FlagHaveRegex (void *data)
132 #if defined(HAVE_REGCOMP) || defined(HAVE_RE_COMP)
133 return 1;
134 #else
135 return 0;
136 #endif
139 enum {
140 FL_SILK = -6,
141 FL_PINS,
142 FL_RATS,
143 FL_VIAS,
144 FL_BACK,
145 FL_MASK
148 static int
149 FlagLayerShown (void *data)
151 int n = GPOINTER_TO_INT (data);
152 switch (n)
154 case FL_SILK:
155 return PCB->ElementOn;
156 case FL_PINS:
157 return PCB->PinOn;
158 case FL_RATS:
159 return PCB->RatOn;
160 case FL_VIAS:
161 return PCB->ViaOn;
162 case FL_BACK:
163 return PCB->InvisibleObjectsOn;
164 case FL_MASK:
165 return TEST_FLAG (SHOWMASKFLAG, PCB);
166 default:
167 if (n >= 0 && n < max_copper_layer)
168 return PCB->Data->Layer[n].On;
170 return 0;
173 static int
174 FlagLayerActive (void *data)
176 int test_layer = GPOINTER_TO_INT (data);
177 int current_layer;
178 if (PCB->RatDraw)
179 current_layer = FL_RATS;
180 else if (PCB->SilkActive)
181 current_layer = FL_SILK;
182 else
183 return 0;
185 return current_layer == test_layer;
188 #define OFFSET_POINTER(a, b) (&(((a *)0)->b))
190 HID_Flag flags_flag_list[] = {
191 {"style", FlagCurrentStyle, NULL},
192 {"grid", FlagGrid, NULL},
193 {"gridsize", FlagGridSize, NULL},
194 {"elementname", FlagElementName, NULL},
195 {"have_regex", FlagHaveRegex, NULL},
197 {"silk_shown", FlagLayerShown, GINT_TO_POINTER (FL_SILK)},
198 {"pins_shown", FlagLayerShown, GINT_TO_POINTER (FL_PINS)},
199 {"rats_shown", FlagLayerShown, GINT_TO_POINTER (FL_RATS)},
200 {"vias_shown", FlagLayerShown, GINT_TO_POINTER (FL_VIAS)},
201 {"back_shown", FlagLayerShown, GINT_TO_POINTER (FL_BACK)},
202 {"mask_shown", FlagLayerShown, GINT_TO_POINTER (FL_MASK)},
204 {"silk_active", FlagLayerActive, GINT_TO_POINTER (FL_SILK)},
205 {"rats_active", FlagLayerActive, GINT_TO_POINTER (FL_RATS)},
207 {"mode", FlagMode, GINT_TO_POINTER (-1)},
208 {"nomode", FlagMode, GINT_TO_POINTER (NO_MODE)},
209 {"arcmode", FlagMode, GINT_TO_POINTER (ARC_MODE)},
210 {"arrowmode", FlagMode, GINT_TO_POINTER (ARROW_MODE)},
211 {"copymode", FlagMode, GINT_TO_POINTER (COPY_MODE)},
212 {"insertpointmode", FlagMode, GINT_TO_POINTER (INSERTPOINT_MODE)},
213 {"linemode", FlagMode, GINT_TO_POINTER (LINE_MODE)},
214 {"lockmode", FlagMode, GINT_TO_POINTER (LOCK_MODE)},
215 {"movemode", FlagMode, GINT_TO_POINTER (MOVE_MODE)},
216 {"pastebuffermode", FlagMode, GINT_TO_POINTER (PASTEBUFFER_MODE)},
217 {"polygonmode", FlagMode, GINT_TO_POINTER (POLYGON_MODE)},
218 {"polygonholemode", FlagMode, GINT_TO_POINTER (POLYGONHOLE_MODE)},
219 {"rectanglemode", FlagMode, GINT_TO_POINTER (RECTANGLE_MODE)},
220 {"removemode", FlagMode, GINT_TO_POINTER (REMOVE_MODE)},
221 {"rotatemode", FlagMode, GINT_TO_POINTER (ROTATE_MODE)},
222 {"rubberbandmovemode", FlagMode, GINT_TO_POINTER (RUBBERBANDMOVE_MODE)},
223 {"textmode", FlagMode, GINT_TO_POINTER (TEXT_MODE)},
224 {"thermalmode", FlagMode, GINT_TO_POINTER (THERMAL_MODE)},
225 {"viamode", FlagMode, GINT_TO_POINTER (VIA_MODE)},
227 {"shownumber", FlagTESTFLAG, GINT_TO_POINTER (SHOWNUMBERFLAG)},
228 {"localref", FlagTESTFLAG, GINT_TO_POINTER (LOCALREFFLAG)},
229 {"checkplanes", FlagTESTFLAG, GINT_TO_POINTER (CHECKPLANESFLAG)},
230 {"showdrc", FlagTESTFLAG, GINT_TO_POINTER (SHOWDRCFLAG)},
231 {"rubberband", FlagTESTFLAG, GINT_TO_POINTER (RUBBERBANDFLAG)},
232 {"description", FlagTESTFLAG, GINT_TO_POINTER (DESCRIPTIONFLAG)},
233 {"nameonpcb", FlagTESTFLAG, GINT_TO_POINTER (NAMEONPCBFLAG)},
234 {"autodrc", FlagTESTFLAG, GINT_TO_POINTER (AUTODRCFLAG)},
235 {"alldirection", FlagTESTFLAG, GINT_TO_POINTER (ALLDIRECTIONFLAG)},
236 {"swapstartdir", FlagTESTFLAG, GINT_TO_POINTER (SWAPSTARTDIRFLAG)},
237 {"uniquename", FlagTESTFLAG, GINT_TO_POINTER (UNIQUENAMEFLAG)},
238 {"clearnew", FlagTESTFLAG, GINT_TO_POINTER (CLEARNEWFLAG)},
239 {"snappin", FlagTESTFLAG, GINT_TO_POINTER (SNAPPINFLAG)},
240 {"showmask", FlagTESTFLAG, GINT_TO_POINTER (SHOWMASKFLAG)},
241 {"thindraw", FlagTESTFLAG, GINT_TO_POINTER (THINDRAWFLAG)},
242 {"orthomove", FlagTESTFLAG, GINT_TO_POINTER (ORTHOMOVEFLAG)},
243 {"liveroute", FlagTESTFLAG, GINT_TO_POINTER (LIVEROUTEFLAG)},
244 {"thindrawpoly", FlagTESTFLAG, GINT_TO_POINTER (THINDRAWPOLYFLAG)},
245 {"locknames", FlagTESTFLAG, GINT_TO_POINTER (LOCKNAMESFLAG)},
246 {"onlynames", FlagTESTFLAG, GINT_TO_POINTER (ONLYNAMESFLAG)},
247 {"newfullpoly", FlagTESTFLAG, GINT_TO_POINTER (NEWFULLPOLYFLAG)},
248 {"hidenames", FlagTESTFLAG, GINT_TO_POINTER (HIDENAMESFLAG)},
250 {"grid_units_mm", FlagUnitsMm, NULL},
251 {"grid_units_mil", FlagUnitsMil, NULL},
253 {"fullpoly", FlagSETTINGS, OFFSET_POINTER (SettingType, FullPoly)},
254 {"clearline", FlagSETTINGS, OFFSET_POINTER (SettingType, ClearLine)},
255 {"uniquenames", FlagSETTINGS, OFFSET_POINTER (SettingType, UniqueNames)},
256 {"showsolderside", FlagSETTINGS, OFFSET_POINTER (SettingType, ShowSolderSide)},
257 {"savelastcommand", FlagSETTINGS, OFFSET_POINTER (SettingType, SaveLastCommand)},
258 {"saveintmp", FlagSETTINGS, OFFSET_POINTER (SettingType, SaveInTMP)},
259 {"drawgrid", FlagSETTINGS, OFFSET_POINTER (SettingType, DrawGrid)},
260 {"ratwarn", FlagSETTINGS, OFFSET_POINTER (SettingType, RatWarn)},
261 {"stipplepolygons", FlagSETTINGS, OFFSET_POINTER (SettingType, StipplePolygons)},
262 {"alldirectionlines", FlagSETTINGS, OFFSET_POINTER (SettingType, AllDirectionLines)},
263 {"rubberbandmode", FlagSETTINGS, OFFSET_POINTER (SettingType, RubberBandMode)},
264 {"swapstartdirection", FlagSETTINGS, OFFSET_POINTER (SettingType, SwapStartDirection)},
265 {"showdrcmode", FlagSETTINGS, OFFSET_POINTER (SettingType, ShowDRC)},
266 {"resetafterelement", FlagSETTINGS, OFFSET_POINTER (SettingType, ResetAfterElement)},
267 {"ringbellwhenfinished", FlagSETTINGS, OFFSET_POINTER (SettingType, RingBellWhenFinished)},
269 {"buffer", FlagBuffer, NULL},
273 REGISTER_FLAGS (flags_flag_list)