Pass r_NoHolesPolygonDicer a POLYAREA *, not a PLINE *
[geda-pcb/gde.git] / src / set.c
blob912db04b923a94a77c614344daaf62d113ecdfc0
1 /* $Id$ */
3 /*
4 * COPYRIGHT
6 * PCB, interactive printed circuit board design
7 * Copyright (C) 1994,1995,1996 Thomas Nau
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.
23 * Contact addresses for paper mail and Email:
24 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
25 * Thomas.Nau@rz.uni-ulm.de
30 /* routines to update widgets and global settings
31 * (except output window and dialogs)
34 #ifdef HAVE_CONFIG_H
35 #include "config.h"
36 #endif
38 #include <math.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #ifdef HAVE_STRING_H
42 #include <string.h>
43 #endif
45 #include "global.h"
47 #include "action.h"
48 #include "buffer.h"
49 #include "compat.h"
50 #include "crosshair.h"
51 #include "data.h"
52 #include "draw.h"
53 #include "error.h"
54 #include "find.h"
55 #include "misc.h"
56 #include "set.h"
57 #include "undo.h"
59 #ifdef HAVE_LIBDMALLOC
60 #include <dmalloc.h>
61 #endif
63 RCSID ("$Id$");
65 static int mode_position = 0;
66 static int mode_stack[MAX_MODESTACK_DEPTH];
68 /* ---------------------------------------------------------------------------
69 * sets cursor grid with respect to grid offset values
71 void
72 SetGrid (float Grid, Boolean align)
74 if (Grid >= 1 && Grid <= MAX_GRID)
76 if (align)
78 PCB->GridOffsetX =
79 Crosshair.X - (int) (Crosshair.X / Grid) * Grid + 0.5;
80 PCB->GridOffsetY =
81 Crosshair.Y - (int) (Crosshair.Y / Grid) * Grid + 0.5;
83 PCB->Grid = Grid;
84 if (Settings.DrawGrid)
85 UpdateAll ();
89 /* ---------------------------------------------------------------------------
90 * sets a new line thickness
92 void
93 SetLineSize (BDimension Size)
95 if (Size >= MIN_LINESIZE && Size <= MAX_LINESIZE)
97 Settings.LineThickness = Size;
98 if (TEST_FLAG (AUTODRCFLAG, PCB))
99 FitCrosshairIntoGrid (Crosshair.X, Crosshair.Y);
103 /* ---------------------------------------------------------------------------
104 * sets a new via thickness
106 void
107 SetViaSize (BDimension Size, Boolean Force)
109 if (Force || (Size <= MAX_PINORVIASIZE &&
110 Size >= MIN_PINORVIASIZE &&
111 Size >= Settings.ViaDrillingHole + MIN_PINORVIACOPPER))
113 Settings.ViaThickness = Size;
117 /* ---------------------------------------------------------------------------
118 * sets a new via drilling hole
120 void
121 SetViaDrillingHole (BDimension Size, Boolean Force)
123 if (Force || (Size <= MAX_PINORVIASIZE &&
124 Size >= MIN_PINORVIAHOLE &&
125 Size <= Settings.ViaThickness - MIN_PINORVIACOPPER))
127 Settings.ViaDrillingHole = Size;
131 void
132 pcb_use_route_style (RouteStyleType * rst)
134 Settings.LineThickness = rst->Thick;
135 Settings.ViaThickness = rst->Diameter;
136 Settings.ViaDrillingHole = rst->Hole;
137 Settings.Keepaway = rst->Keepaway;
140 /* ---------------------------------------------------------------------------
141 * sets a keepaway width
143 void
144 SetKeepawayWidth (BDimension Width)
146 if (Width <= MAX_LINESIZE)
148 Settings.Keepaway = Width;
152 /* ---------------------------------------------------------------------------
153 * sets a text scaling
155 void
156 SetTextScale (Dimension Scale)
158 if (Scale <= MAX_TEXTSCALE && Scale >= MIN_TEXTSCALE)
160 Settings.TextScale = Scale;
164 /* ---------------------------------------------------------------------------
165 * sets or resets changed flag and redraws status
167 void
168 SetChangedFlag (Boolean New)
170 if (PCB->Changed != New)
172 PCB->Changed = New;
177 /* ---------------------------------------------------------------------------
178 * sets the crosshair range to the current buffer extents
180 void
181 SetCrosshairRangeToBuffer (void)
183 if (Settings.Mode == PASTEBUFFER_MODE)
185 SetBufferBoundingBox (PASTEBUFFER);
186 SetCrosshairRange (PASTEBUFFER->X - PASTEBUFFER->BoundingBox.X1,
187 PASTEBUFFER->Y - PASTEBUFFER->BoundingBox.Y1,
188 PCB->MaxWidth -
189 (PASTEBUFFER->BoundingBox.X2 - PASTEBUFFER->X),
190 PCB->MaxHeight -
191 (PASTEBUFFER->BoundingBox.Y2 - PASTEBUFFER->Y));
195 /* ---------------------------------------------------------------------------
196 * sets a new buffer number
198 void
199 SetBufferNumber (int Number)
201 if (Number >= 0 && Number < MAX_BUFFER)
203 Settings.BufferNumber = Number;
205 /* do an update on the crosshair range */
206 SetCrosshairRangeToBuffer ();
210 /* ---------------------------------------------------------------------------
213 void
214 SaveMode (void)
216 mode_stack[mode_position] = Settings.Mode;
217 if (mode_position < MAX_MODESTACK_DEPTH - 1)
218 mode_position++;
221 void
222 RestoreMode (void)
224 if (mode_position == 0)
226 Message ("hace: underflow of restore mode\n");
227 return;
229 SetMode (mode_stack[--mode_position]);
233 /* ---------------------------------------------------------------------------
234 * set a new mode and update X cursor
236 void
237 SetMode (int Mode)
239 static Boolean recursing = False;
240 /* protect the cursor while changing the mode
241 * perform some additional stuff depending on the new mode
242 * reset 'state' of attached objects
244 if (recursing)
245 return;
246 recursing = True;
247 HideCrosshair (True);
248 addedLines = 0;
249 Crosshair.AttachedObject.Type = NO_TYPE;
250 Crosshair.AttachedObject.State = STATE_FIRST;
251 Crosshair.AttachedPolygon.PointN = 0;
252 if (PCB->RatDraw)
254 if (Mode == ARC_MODE || Mode == RECTANGLE_MODE ||
255 Mode == VIA_MODE || Mode == POLYGON_MODE ||
256 Mode == TEXT_MODE || Mode == INSERTPOINT_MODE ||
257 Mode == THERMAL_MODE)
259 Message (_("That mode is NOT allowed when drawing ratlines!\n"));
260 Mode = NO_MODE;
263 if (Settings.Mode == LINE_MODE && Mode == ARC_MODE &&
264 Crosshair.AttachedLine.State != STATE_FIRST)
266 Crosshair.AttachedLine.State = STATE_FIRST;
267 Crosshair.AttachedBox.State = STATE_SECOND;
268 Crosshair.AttachedBox.Point1.X = Crosshair.AttachedBox.Point2.X =
269 Crosshair.AttachedLine.Point1.X;
270 Crosshair.AttachedBox.Point1.Y = Crosshair.AttachedBox.Point2.Y =
271 Crosshair.AttachedLine.Point1.Y;
272 AdjustAttachedObjects ();
274 else if (Settings.Mode == ARC_MODE && Mode == LINE_MODE &&
275 Crosshair.AttachedBox.State != STATE_FIRST)
277 Crosshair.AttachedBox.State = STATE_FIRST;
278 Crosshair.AttachedLine.State = STATE_SECOND;
279 Crosshair.AttachedLine.Point1.X = Crosshair.AttachedLine.Point2.X =
280 Crosshair.AttachedBox.Point1.X;
281 Crosshair.AttachedLine.Point1.Y = Crosshair.AttachedLine.Point2.Y =
282 Crosshair.AttachedBox.Point1.Y;
283 Settings.Mode = Mode;
284 AdjustAttachedObjects ();
286 else
288 if (Settings.Mode == ARC_MODE || Settings.Mode == LINE_MODE)
289 SetLocalRef (0, 0, False);
290 Crosshair.AttachedBox.State = STATE_FIRST;
291 Crosshair.AttachedLine.State = STATE_FIRST;
292 if (Mode == LINE_MODE && TEST_FLAG (AUTODRCFLAG, PCB))
294 SaveUndoSerialNumber ();
295 ResetFoundPinsViasAndPads (True);
296 RestoreUndoSerialNumber ();
297 ResetFoundLinesAndPolygons (True);
298 IncrementUndoSerialNumber ();
302 Settings.Mode = Mode;
304 if (Mode == PASTEBUFFER_MODE)
305 /* do an update on the crosshair range */
306 SetCrosshairRangeToBuffer ();
307 else
308 SetCrosshairRange (0, 0, PCB->MaxWidth, PCB->MaxHeight);
310 recursing = False;
312 /* force a crosshair grid update because the valid range
313 * may have changed
315 MoveCrosshairRelative (0, 0);
316 RestoreCrosshair (True);
319 void
320 SetRouteStyle (char *name)
322 char num[10];
324 STYLE_LOOP (PCB);
326 if (name && NSTRCMP (name, style->Name) == 0)
328 sprintf (num, "%d", n + 1);
329 hid_actionl ("RouteStyle", num, NULL);
330 break;
333 END_LOOP;
336 void
337 SetLocalRef (LocationType X, LocationType Y, Boolean Showing)
339 static MarkType old;
340 static int count = 0;
342 if (Showing)
344 HideCrosshair (True);
345 if (count == 0)
346 old = Marked;
347 Marked.X = X;
348 Marked.Y = Y;
349 Marked.status = True;
350 count++;
351 RestoreCrosshair (False);
353 else if (count > 0)
355 HideCrosshair (False);
356 count = 0;
357 Marked = old;
358 RestoreCrosshair (False);