Introduce POLYGONHOLE_MODE for creating holes in polygons
[geda-pcb/gde.git] / src / set.c
blob7a41f73ce1759801d26593ffebc9c16deb0508e0
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, bool 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, bool 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, bool 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 (bool 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 bool 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 == POLYGONHOLE_MODE ||
257 Mode == TEXT_MODE || Mode == INSERTPOINT_MODE ||
258 Mode == THERMAL_MODE)
260 Message (_("That mode is NOT allowed when drawing ratlines!\n"));
261 Mode = NO_MODE;
264 if (Settings.Mode == LINE_MODE && Mode == ARC_MODE &&
265 Crosshair.AttachedLine.State != STATE_FIRST)
267 Crosshair.AttachedLine.State = STATE_FIRST;
268 Crosshair.AttachedBox.State = STATE_SECOND;
269 Crosshair.AttachedBox.Point1.X = Crosshair.AttachedBox.Point2.X =
270 Crosshair.AttachedLine.Point1.X;
271 Crosshair.AttachedBox.Point1.Y = Crosshair.AttachedBox.Point2.Y =
272 Crosshair.AttachedLine.Point1.Y;
273 AdjustAttachedObjects ();
275 else if (Settings.Mode == ARC_MODE && Mode == LINE_MODE &&
276 Crosshair.AttachedBox.State != STATE_FIRST)
278 Crosshair.AttachedBox.State = STATE_FIRST;
279 Crosshair.AttachedLine.State = STATE_SECOND;
280 Crosshair.AttachedLine.Point1.X = Crosshair.AttachedLine.Point2.X =
281 Crosshair.AttachedBox.Point1.X;
282 Crosshair.AttachedLine.Point1.Y = Crosshair.AttachedLine.Point2.Y =
283 Crosshair.AttachedBox.Point1.Y;
284 Settings.Mode = Mode;
285 AdjustAttachedObjects ();
287 else
289 if (Settings.Mode == ARC_MODE || Settings.Mode == LINE_MODE)
290 SetLocalRef (0, 0, false);
291 Crosshair.AttachedBox.State = STATE_FIRST;
292 Crosshair.AttachedLine.State = STATE_FIRST;
293 if (Mode == LINE_MODE && TEST_FLAG (AUTODRCFLAG, PCB))
295 SaveUndoSerialNumber ();
296 ResetFoundPinsViasAndPads (true);
297 RestoreUndoSerialNumber ();
298 ResetFoundLinesAndPolygons (true);
299 IncrementUndoSerialNumber ();
303 Settings.Mode = Mode;
305 if (Mode == PASTEBUFFER_MODE)
306 /* do an update on the crosshair range */
307 SetCrosshairRangeToBuffer ();
308 else
309 SetCrosshairRange (0, 0, PCB->MaxWidth, PCB->MaxHeight);
311 recursing = false;
313 /* force a crosshair grid update because the valid range
314 * may have changed
316 MoveCrosshairRelative (0, 0);
317 RestoreCrosshair (true);
320 void
321 SetRouteStyle (char *name)
323 char num[10];
325 STYLE_LOOP (PCB);
327 if (name && NSTRCMP (name, style->Name) == 0)
329 sprintf (num, "%d", n + 1);
330 hid_actionl ("RouteStyle", num, NULL);
331 break;
334 END_LOOP;
337 void
338 SetLocalRef (LocationType X, LocationType Y, bool Showing)
340 static MarkType old;
341 static int count = 0;
343 if (Showing)
345 HideCrosshair (true);
346 if (count == 0)
347 old = Marked;
348 Marked.X = X;
349 Marked.Y = Y;
350 Marked.status = true;
351 count++;
352 RestoreCrosshair (false);
354 else if (count > 0)
356 HideCrosshair (false);
357 count = 0;
358 Marked = old;
359 RestoreCrosshair (false);