Remove calls to SaveFindFlag()
[geda-pcb/pcjc2.git] / src / set.c
blobf1b6c94b6370b39d88f224fb9e983a3936ee3dd4
1 /*
2 * COPYRIGHT
4 * PCB, interactive printed circuit board design
5 * Copyright (C) 1994,1995,1996 Thomas Nau
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.
21 * Contact addresses for paper mail and Email:
22 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
23 * Thomas.Nau@rz.uni-ulm.de
28 /* routines to update widgets and global settings
29 * (except output window and dialogs)
32 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
36 #include <math.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #ifdef HAVE_STRING_H
40 #include <string.h>
41 #endif
43 #include "global.h"
45 #include "action.h"
46 #include "buffer.h"
47 #include "compat.h"
48 #include "crosshair.h"
49 #include "data.h"
50 #include "draw.h"
51 #include "error.h"
52 #include "find.h"
53 #include "misc.h"
54 #include "move.h"
55 #include "set.h"
56 #include "undo.h"
57 #include "pcb-printf.h"
59 #ifdef HAVE_LIBDMALLOC
60 #include <dmalloc.h>
61 #endif
63 static int mode_position = 0;
64 static int mode_stack[MAX_MODESTACK_DEPTH];
66 /* ---------------------------------------------------------------------------
67 * sets cursor grid with respect to grid offset values
69 void
70 SetGrid (Coord Grid, bool align)
72 char *grid_string;
73 if (Grid >= 1 && Grid <= MAX_GRID)
75 if (align)
77 PCB->GridOffsetX = Crosshair.X % Grid;
78 PCB->GridOffsetY = Crosshair.Y % Grid;
80 PCB->Grid = Grid;
81 grid_string = pcb_g_strdup_printf ("%mr", Grid);
82 if (grid_string)
83 AttributePut (PCB, "PCB::grid::size", grid_string);
84 g_free (grid_string);
85 if (Settings.DrawGrid)
86 Redraw ();
90 /* ---------------------------------------------------------------------------
91 * sets a new line thickness
93 void
94 SetLineSize (Coord Size)
96 if (Size >= MIN_LINESIZE && Size <= MAX_LINESIZE)
98 Settings.LineThickness = Size;
99 if (TEST_FLAG (AUTODRCFLAG, PCB))
100 FitCrosshairIntoGrid (Crosshair.X, Crosshair.Y);
104 /* ---------------------------------------------------------------------------
105 * sets a new via thickness
107 void
108 SetViaSize (Coord Size, bool Force)
110 if (Force || (Size <= MAX_PINORVIASIZE &&
111 Size >= MIN_PINORVIASIZE &&
112 Size >= Settings.ViaDrillingHole + MIN_PINORVIACOPPER))
114 Settings.ViaThickness = Size;
118 /* ---------------------------------------------------------------------------
119 * sets a new via drilling hole
121 void
122 SetViaDrillingHole (Coord Size, bool Force)
124 if (Force || (Size <= MAX_PINORVIASIZE &&
125 Size >= MIN_PINORVIAHOLE &&
126 Size <= Settings.ViaThickness - MIN_PINORVIACOPPER))
128 Settings.ViaDrillingHole = Size;
132 void
133 pcb_use_route_style (RouteStyleType * rst)
135 Settings.LineThickness = rst->Thick;
136 Settings.ViaThickness = rst->Diameter;
137 Settings.ViaDrillingHole = rst->Hole;
138 Settings.Keepaway = rst->Keepaway;
141 /* ---------------------------------------------------------------------------
142 * sets a keepaway width
144 void
145 SetKeepawayWidth (Coord Width)
147 if (Width <= MAX_LINESIZE)
149 Settings.Keepaway = Width;
153 /* ---------------------------------------------------------------------------
154 * sets a text scaling
156 void
157 SetTextScale (int Scale)
159 if (Scale <= MAX_TEXTSCALE && Scale >= MIN_TEXTSCALE)
161 Settings.TextScale = Scale;
165 /* ---------------------------------------------------------------------------
166 * sets or resets changed flag and redraws status
168 void
169 SetChangedFlag (bool New)
171 if (PCB->Changed != New)
173 PCB->Changed = New;
178 /* ---------------------------------------------------------------------------
179 * sets the crosshair range to the current buffer extents
181 void
182 SetCrosshairRangeToBuffer (void)
184 if (Settings.Mode == PASTEBUFFER_MODE)
186 SetBufferBoundingBox (PASTEBUFFER);
187 SetCrosshairRange (PASTEBUFFER->X - PASTEBUFFER->BoundingBox.X1,
188 PASTEBUFFER->Y - PASTEBUFFER->BoundingBox.Y1,
189 PCB->MaxWidth -
190 (PASTEBUFFER->BoundingBox.X2 - PASTEBUFFER->X),
191 PCB->MaxHeight -
192 (PASTEBUFFER->BoundingBox.Y2 - PASTEBUFFER->Y));
196 /* ---------------------------------------------------------------------------
197 * sets a new buffer number
199 void
200 SetBufferNumber (int Number)
202 if (Number >= 0 && Number < MAX_BUFFER)
204 Settings.BufferNumber = Number;
206 /* do an update on the crosshair range */
207 SetCrosshairRangeToBuffer ();
211 /* ---------------------------------------------------------------------------
214 void
215 SaveMode (void)
217 mode_stack[mode_position] = Settings.Mode;
218 if (mode_position < MAX_MODESTACK_DEPTH - 1)
219 mode_position++;
222 void
223 RestoreMode (void)
225 if (mode_position == 0)
227 Message ("hace: underflow of restore mode\n");
228 return;
230 SetMode (mode_stack[--mode_position]);
234 /* ---------------------------------------------------------------------------
235 * set a new mode and update X cursor
237 void
238 SetMode (int Mode)
240 static bool recursing = false;
241 /* protect the cursor while changing the mode
242 * perform some additional stuff depending on the new mode
243 * reset 'state' of attached objects
245 if (recursing)
246 return;
247 recursing = true;
248 notify_crosshair_change (false);
249 addedLines = 0;
250 Crosshair.AttachedObject.Type = NO_TYPE;
251 Crosshair.AttachedObject.State = STATE_FIRST;
252 Crosshair.AttachedPolygon.PointN = 0;
253 if (PCB->RatDraw)
255 if (Mode == ARC_MODE || Mode == RECTANGLE_MODE ||
256 Mode == VIA_MODE || Mode == POLYGON_MODE ||
257 Mode == POLYGONHOLE_MODE ||
258 Mode == TEXT_MODE || Mode == INSERTPOINT_MODE ||
259 Mode == THERMAL_MODE)
261 Message (_("That mode is NOT allowed when drawing ratlines!\n"));
262 Mode = NO_MODE;
265 if (Settings.Mode == LINE_MODE && Mode == ARC_MODE &&
266 Crosshair.AttachedLine.State != STATE_FIRST)
268 Crosshair.AttachedLine.State = STATE_FIRST;
269 Crosshair.AttachedBox.State = STATE_SECOND;
270 Crosshair.AttachedBox.Point1.X = Crosshair.AttachedBox.Point2.X =
271 Crosshair.AttachedLine.Point1.X;
272 Crosshair.AttachedBox.Point1.Y = Crosshair.AttachedBox.Point2.Y =
273 Crosshair.AttachedLine.Point1.Y;
274 AdjustAttachedObjects ();
276 else if (Settings.Mode == ARC_MODE && Mode == LINE_MODE &&
277 Crosshair.AttachedBox.State != STATE_FIRST)
279 Crosshair.AttachedBox.State = STATE_FIRST;
280 Crosshair.AttachedLine.State = STATE_SECOND;
281 Crosshair.AttachedLine.Point1.X = Crosshair.AttachedLine.Point2.X =
282 Crosshair.AttachedBox.Point1.X;
283 Crosshair.AttachedLine.Point1.Y = Crosshair.AttachedLine.Point2.Y =
284 Crosshair.AttachedBox.Point1.Y;
285 Settings.Mode = Mode;
286 AdjustAttachedObjects ();
288 /* Cancel rubberband move */
289 else if (Settings.Mode == MOVE_MODE)
290 MoveObjectAndRubberband (Crosshair.AttachedObject.Type,
291 Crosshair.AttachedObject.Ptr1,
292 Crosshair.AttachedObject.Ptr2,
293 Crosshair.AttachedObject.Ptr3,
294 0, 0);
295 else
297 if (Settings.Mode == ARC_MODE || Settings.Mode == LINE_MODE)
298 SetLocalRef (0, 0, false);
299 Crosshair.AttachedBox.State = STATE_FIRST;
300 Crosshair.AttachedLine.State = STATE_FIRST;
301 if (Mode == LINE_MODE && TEST_FLAG (AUTODRCFLAG, PCB))
303 if (ResetConnections (true, FOUNDFLAG))
305 IncrementUndoSerialNumber ();
306 Draw ();
311 Settings.Mode = Mode;
313 if (Mode == PASTEBUFFER_MODE)
314 /* do an update on the crosshair range */
315 SetCrosshairRangeToBuffer ();
316 else
317 SetCrosshairRange (0, 0, PCB->MaxWidth, PCB->MaxHeight);
319 recursing = false;
321 /* force a crosshair grid update because the valid range
322 * may have changed
324 MoveCrosshairRelative (0, 0);
325 notify_crosshair_change (true);
328 void
329 SetRouteStyle (char *name)
331 char num[10];
333 STYLE_LOOP (PCB);
335 if (name && NSTRCMP (name, style->Name) == 0)
337 sprintf (num, "%d", n + 1);
338 hid_actionl ("RouteStyle", num, NULL);
339 break;
342 END_LOOP;
345 void
346 SetLocalRef (Coord X, Coord Y, bool Showing)
348 static MarkType old;
349 static int count = 0;
351 if (Showing)
353 notify_mark_change (false);
354 if (count == 0)
355 old = Marked;
356 Marked.X = X;
357 Marked.Y = Y;
358 Marked.status = true;
359 count++;
360 notify_mark_change (true);
362 else if (count > 0)
364 notify_mark_change (false);
365 count = 0;
366 Marked = old;
367 notify_mark_change (true);