Add ghid_route_style_selector_empty to GHidRouteStyleSelector
[geda-pcb/whiteaudio.git] / src / set.c
blob1f86adb4a09fa6f339645d3265f489dc80cc818b
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 (Coord Grid, bool align)
74 if (Grid >= 1 && Grid <= MAX_GRID)
76 if (align)
78 PCB->GridOffsetX = Crosshair.X % Grid;
79 PCB->GridOffsetY = Crosshair.Y % Grid;
81 PCB->Grid = Grid;
82 if (Settings.DrawGrid)
83 Redraw ();
87 /* ---------------------------------------------------------------------------
88 * sets a new line thickness
90 void
91 SetLineSize (Coord Size)
93 if (Size >= MIN_LINESIZE && Size <= MAX_LINESIZE)
95 Settings.LineThickness = Size;
96 if (TEST_FLAG (AUTODRCFLAG, PCB))
97 FitCrosshairIntoGrid (Crosshair.X, Crosshair.Y);
101 /* ---------------------------------------------------------------------------
102 * sets a new via thickness
104 void
105 SetViaSize (Coord Size, bool Force)
107 if (Force || (Size <= MAX_PINORVIASIZE &&
108 Size >= MIN_PINORVIASIZE &&
109 Size >= Settings.ViaDrillingHole + MIN_PINORVIACOPPER))
111 Settings.ViaThickness = Size;
115 /* ---------------------------------------------------------------------------
116 * sets a new via drilling hole
118 void
119 SetViaDrillingHole (Coord Size, bool Force)
121 if (Force || (Size <= MAX_PINORVIASIZE &&
122 Size >= MIN_PINORVIAHOLE &&
123 Size <= Settings.ViaThickness - MIN_PINORVIACOPPER))
125 Settings.ViaDrillingHole = Size;
129 void
130 pcb_use_route_style (RouteStyleType * rst)
132 Settings.LineThickness = rst->Thick;
133 Settings.ViaThickness = rst->Diameter;
134 Settings.ViaDrillingHole = rst->Hole;
135 Settings.Keepaway = rst->Keepaway;
138 /* ---------------------------------------------------------------------------
139 * sets a keepaway width
141 void
142 SetKeepawayWidth (Coord Width)
144 if (Width <= MAX_LINESIZE)
146 Settings.Keepaway = Width;
150 /* ---------------------------------------------------------------------------
151 * sets a text scaling
153 void
154 SetTextScale (int Scale)
156 if (Scale <= MAX_TEXTSCALE && Scale >= MIN_TEXTSCALE)
158 Settings.TextScale = Scale;
162 /* ---------------------------------------------------------------------------
163 * sets or resets changed flag and redraws status
165 void
166 SetChangedFlag (bool New)
168 if (PCB->Changed != New)
170 PCB->Changed = New;
175 /* ---------------------------------------------------------------------------
176 * sets the crosshair range to the current buffer extents
178 void
179 SetCrosshairRangeToBuffer (void)
181 if (Settings.Mode == PASTEBUFFER_MODE)
183 SetBufferBoundingBox (PASTEBUFFER);
184 SetCrosshairRange (PASTEBUFFER->X - PASTEBUFFER->BoundingBox.X1,
185 PASTEBUFFER->Y - PASTEBUFFER->BoundingBox.Y1,
186 PCB->MaxWidth -
187 (PASTEBUFFER->BoundingBox.X2 - PASTEBUFFER->X),
188 PCB->MaxHeight -
189 (PASTEBUFFER->BoundingBox.Y2 - PASTEBUFFER->Y));
193 /* ---------------------------------------------------------------------------
194 * sets a new buffer number
196 void
197 SetBufferNumber (int Number)
199 if (Number >= 0 && Number < MAX_BUFFER)
201 Settings.BufferNumber = Number;
203 /* do an update on the crosshair range */
204 SetCrosshairRangeToBuffer ();
208 /* ---------------------------------------------------------------------------
211 void
212 SaveMode (void)
214 mode_stack[mode_position] = Settings.Mode;
215 if (mode_position < MAX_MODESTACK_DEPTH - 1)
216 mode_position++;
219 void
220 RestoreMode (void)
222 if (mode_position == 0)
224 Message ("hace: underflow of restore mode\n");
225 return;
227 SetMode (mode_stack[--mode_position]);
231 /* ---------------------------------------------------------------------------
232 * set a new mode and update X cursor
234 void
235 SetMode (int Mode)
237 static bool recursing = false;
238 /* protect the cursor while changing the mode
239 * perform some additional stuff depending on the new mode
240 * reset 'state' of attached objects
242 if (recursing)
243 return;
244 recursing = true;
245 notify_crosshair_change (false);
246 addedLines = 0;
247 Crosshair.AttachedObject.Type = NO_TYPE;
248 Crosshair.AttachedObject.State = STATE_FIRST;
249 Crosshair.AttachedPolygon.PointN = 0;
250 if (PCB->RatDraw)
252 if (Mode == ARC_MODE || Mode == RECTANGLE_MODE ||
253 Mode == VIA_MODE || Mode == POLYGON_MODE ||
254 Mode == POLYGONHOLE_MODE ||
255 Mode == TEXT_MODE || Mode == INSERTPOINT_MODE ||
256 Mode == THERMAL_MODE)
258 Message (_("That mode is NOT allowed when drawing ratlines!\n"));
259 Mode = NO_MODE;
262 if (Settings.Mode == LINE_MODE && Mode == ARC_MODE &&
263 Crosshair.AttachedLine.State != STATE_FIRST)
265 Crosshair.AttachedLine.State = STATE_FIRST;
266 Crosshair.AttachedBox.State = STATE_SECOND;
267 Crosshair.AttachedBox.Point1.X = Crosshair.AttachedBox.Point2.X =
268 Crosshair.AttachedLine.Point1.X;
269 Crosshair.AttachedBox.Point1.Y = Crosshair.AttachedBox.Point2.Y =
270 Crosshair.AttachedLine.Point1.Y;
271 AdjustAttachedObjects ();
273 else if (Settings.Mode == ARC_MODE && Mode == LINE_MODE &&
274 Crosshair.AttachedBox.State != STATE_FIRST)
276 Crosshair.AttachedBox.State = STATE_FIRST;
277 Crosshair.AttachedLine.State = STATE_SECOND;
278 Crosshair.AttachedLine.Point1.X = Crosshair.AttachedLine.Point2.X =
279 Crosshair.AttachedBox.Point1.X;
280 Crosshair.AttachedLine.Point1.Y = Crosshair.AttachedLine.Point2.Y =
281 Crosshair.AttachedBox.Point1.Y;
282 Settings.Mode = Mode;
283 AdjustAttachedObjects ();
285 else
287 if (Settings.Mode == ARC_MODE || Settings.Mode == LINE_MODE)
288 SetLocalRef (0, 0, false);
289 Crosshair.AttachedBox.State = STATE_FIRST;
290 Crosshair.AttachedLine.State = STATE_FIRST;
291 if (Mode == LINE_MODE && TEST_FLAG (AUTODRCFLAG, PCB))
293 if (ResetConnections (true))
295 IncrementUndoSerialNumber ();
296 Draw ();
301 Settings.Mode = Mode;
303 if (Mode == PASTEBUFFER_MODE)
304 /* do an update on the crosshair range */
305 SetCrosshairRangeToBuffer ();
306 else
307 SetCrosshairRange (0, 0, PCB->MaxWidth, PCB->MaxHeight);
309 recursing = false;
311 /* force a crosshair grid update because the valid range
312 * may have changed
314 MoveCrosshairRelative (0, 0);
315 notify_crosshair_change (true);
318 void
319 SetRouteStyle (char *name)
321 char num[10];
323 STYLE_LOOP (PCB);
325 if (name && NSTRCMP (name, style->Name) == 0)
327 sprintf (num, "%d", n + 1);
328 hid_actionl ("RouteStyle", num, NULL);
329 break;
332 END_LOOP;
335 void
336 SetLocalRef (Coord X, Coord Y, bool Showing)
338 static MarkType old;
339 static int count = 0;
341 if (Showing)
343 notify_mark_change (false);
344 if (count == 0)
345 old = Marked;
346 Marked.X = X;
347 Marked.Y = Y;
348 Marked.status = true;
349 count++;
350 notify_mark_change (true);
352 else if (count > 0)
354 notify_mark_change (false);
355 count = 0;
356 Marked = old;
357 notify_mark_change (true);