(no commit message)
[geda-pcb/pcjc2.git] / src / change.c
blob59bf4a47a0ddc286af26666c5cdffb508270da07
1 /*
2 * COPYRIGHT
4 * PCB, interactive printed circuit board design
5 * Copyright (C) 1994,1995,1996, 2005 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
27 /* functions used to change object properties
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <setjmp.h>
39 #include "global.h"
41 #include "change.h"
42 #include "create.h"
43 #include "crosshair.h"
44 #include "data.h"
45 #include "draw.h"
46 #include "error.h"
47 #include "mymem.h"
48 #include "misc.h"
49 #include "mirror.h"
50 #include "polygon.h"
51 #include "rats.h"
52 #include "remove.h"
53 #include "rtree.h"
54 #include "search.h"
55 #include "select.h"
56 #include "set.h"
57 #include "thermal.h"
58 #include "undo.h"
60 #ifdef HAVE_LIBDMALLOC
61 #include <dmalloc.h>
62 #endif
64 /* ---------------------------------------------------------------------------
65 * some local prototypes
67 static void *ChangePinSize (ElementType *, PinType *);
68 static void *ChangePinClearSize (ElementType *, PinType *);
69 static void *ChangePinMaskSize (ElementType *, PinType *);
70 static void *ChangePadSize (ElementType *, PadType *);
71 static void *ChangePadClearSize (ElementType *, PadType *);
72 static void *ChangePadMaskSize (ElementType *, PadType *);
73 static void *ChangePin2ndSize (ElementType *, PinType *);
74 static void *ChangeElement2ndSize (ElementType *);
75 static void *ChangeViaSize (PinType *);
76 static void *ChangeVia2ndSize (PinType *);
77 static void *ChangeViaClearSize (PinType *);
78 static void *ChangeViaMaskSize (PinType *);
79 static void *ChangeLineSize (LayerType *, LineType *);
80 static void *ChangeLineClearSize (LayerType *, LineType *);
81 static void *ChangePolygonClearSize (LayerType *, PolygonType *);
82 static void *ChangeArcSize (LayerType *, ArcType *);
83 static void *ChangeArcClearSize (LayerType *, ArcType *);
84 static void *ChangeTextSize (LayerType *, TextType *);
85 static void *ChangeElementSize (ElementType *);
86 static void *ChangeElementNameSize (ElementType *);
87 static void *ChangePinName (ElementType *, PinType *);
88 static void *ChangePadName (ElementType *, PadType *);
89 static void *ChangeViaName (PinType *);
90 static void *ChangeLineName (LayerType *, LineType *);
91 static void *ChangeElementName (ElementType *);
92 static void *ChangeTextName (LayerType *, TextType *);
93 static void *ChangeElementSquare (ElementType *);
94 static void *SetElementSquare (ElementType *);
95 static void *ClrElementSquare (ElementType *);
96 static void *ChangeElementOctagon (ElementType *);
97 static void *SetElementOctagon (ElementType *);
98 static void *ClrElementOctagon (ElementType *);
99 static void *ChangePinSquare (ElementType *, PinType *);
100 static void *SetPinSquare (ElementType *, PinType *);
101 static void *ClrPinSquare (ElementType *, PinType *);
102 static void *ChangePinOctagon (ElementType *, PinType *);
103 static void *SetPinOctagon (ElementType *, PinType *);
104 static void *ClrPinOctagon (ElementType *, PinType *);
105 static void *ChangeViaOctagon (PinType *);
106 static void *SetViaOctagon (PinType *);
107 static void *ClrViaOctagon (PinType *);
108 static void *ChangePadSquare (ElementType *, PadType *);
109 static void *SetPadSquare (ElementType *, PadType *);
110 static void *ClrPadSquare (ElementType *, PadType *);
111 static void *ChangeViaThermal (PinType *);
112 static void *ChangePinThermal (ElementType *, PinType *);
113 static void *ChangeLineJoin (LayerType *, LineType *);
114 static void *SetLineJoin (LayerType *, LineType *);
115 static void *ClrLineJoin (LayerType *, LineType *);
116 static void *ChangeArcJoin (LayerType *, ArcType *);
117 static void *SetArcJoin (LayerType *, ArcType *);
118 static void *ClrArcJoin (LayerType *, ArcType *);
119 static void *ChangeTextJoin (LayerType *, TextType *);
120 static void *SetTextJoin (LayerType *, TextType *);
121 static void *ClrTextJoin (LayerType *, TextType *);
122 static void *ChangePolyClear (LayerType *, PolygonType *);
124 /* ---------------------------------------------------------------------------
125 * some local identifiers
127 static int Delta; /* change of size */
128 static int Absolute; /* Absolute size */
129 static char *NewName; /* new name */
130 static ObjectFunctionType ChangeSizeFunctions = {
131 ChangeLineSize,
132 ChangeTextSize,
133 ChangePolyClear,
134 ChangeViaSize,
135 ChangeElementSize, /* changes silk screen line width */
136 ChangeElementNameSize,
137 ChangePinSize,
138 ChangePadSize,
139 NULL,
140 NULL,
141 ChangeArcSize,
142 NULL
144 static ObjectFunctionType Change2ndSizeFunctions = {
145 NULL,
146 NULL,
147 NULL,
148 ChangeVia2ndSize,
149 ChangeElement2ndSize,
150 NULL,
151 ChangePin2ndSize,
152 NULL,
153 NULL,
154 NULL,
155 NULL,
156 NULL
158 static ObjectFunctionType ChangeThermalFunctions = {
159 NULL,
160 NULL,
161 NULL,
162 ChangeViaThermal,
163 NULL,
164 NULL,
165 ChangePinThermal,
166 NULL,
167 NULL,
168 NULL,
169 NULL,
170 NULL
172 static ObjectFunctionType ChangeClearSizeFunctions = {
173 ChangeLineClearSize,
174 NULL,
175 ChangePolygonClearSize, /* just to tell the user not to :-) */
176 ChangeViaClearSize,
177 NULL,
178 NULL,
179 ChangePinClearSize,
180 ChangePadClearSize,
181 NULL,
182 NULL,
183 ChangeArcClearSize,
184 NULL
186 static ObjectFunctionType ChangeNameFunctions = {
187 ChangeLineName,
188 ChangeTextName,
189 NULL,
190 ChangeViaName,
191 ChangeElementName,
192 NULL,
193 ChangePinName,
194 ChangePadName,
195 NULL,
196 NULL,
197 NULL,
198 NULL
200 static ObjectFunctionType ChangeSquareFunctions = {
201 NULL,
202 NULL,
203 NULL,
204 NULL,
205 ChangeElementSquare,
206 NULL,
207 ChangePinSquare,
208 ChangePadSquare,
209 NULL,
210 NULL,
211 NULL,
212 NULL
214 static ObjectFunctionType ChangeJoinFunctions = {
215 ChangeLineJoin,
216 ChangeTextJoin,
217 NULL,
218 NULL,
219 NULL,
220 NULL,
221 NULL,
222 NULL,
223 NULL,
224 NULL,
225 ChangeArcJoin,
226 NULL
228 static ObjectFunctionType ChangeOctagonFunctions = {
229 NULL,
230 NULL,
231 NULL,
232 ChangeViaOctagon,
233 ChangeElementOctagon,
234 NULL,
235 ChangePinOctagon,
236 NULL,
237 NULL,
238 NULL,
239 NULL,
240 NULL
242 static ObjectFunctionType ChangeMaskSizeFunctions = {
243 NULL,
244 NULL,
245 NULL,
246 ChangeViaMaskSize,
247 #if 0
248 ChangeElementMaskSize,
249 #else
250 NULL,
251 #endif
252 NULL,
253 ChangePinMaskSize,
254 ChangePadMaskSize,
255 NULL,
256 NULL,
257 NULL,
258 NULL
260 static ObjectFunctionType SetSquareFunctions = {
261 NULL,
262 NULL,
263 NULL,
264 NULL,
265 SetElementSquare,
266 NULL,
267 SetPinSquare,
268 SetPadSquare,
269 NULL,
270 NULL,
271 NULL,
272 NULL
274 static ObjectFunctionType SetJoinFunctions = {
275 SetLineJoin,
276 SetTextJoin,
277 NULL,
278 NULL,
279 NULL,
280 NULL,
281 NULL,
282 NULL,
283 NULL,
284 NULL,
285 SetArcJoin,
286 NULL
288 static ObjectFunctionType SetOctagonFunctions = {
289 NULL,
290 NULL,
291 NULL,
292 SetViaOctagon,
293 SetElementOctagon,
294 NULL,
295 SetPinOctagon,
296 NULL,
297 NULL,
298 NULL,
299 NULL,
300 NULL
302 static ObjectFunctionType ClrSquareFunctions = {
303 NULL,
304 NULL,
305 NULL,
306 NULL,
307 ClrElementSquare,
308 NULL,
309 ClrPinSquare,
310 ClrPadSquare,
311 NULL,
312 NULL,
313 NULL,
314 NULL
316 static ObjectFunctionType ClrJoinFunctions = {
317 ClrLineJoin,
318 ClrTextJoin,
319 NULL,
320 NULL,
321 NULL,
322 NULL,
323 NULL,
324 NULL,
325 NULL,
326 NULL,
327 ClrArcJoin,
328 NULL
330 static ObjectFunctionType ClrOctagonFunctions = {
331 NULL,
332 NULL,
333 NULL,
334 ClrViaOctagon,
335 ClrElementOctagon,
336 NULL,
337 ClrPinOctagon,
338 NULL,
339 NULL,
340 NULL,
341 NULL,
342 NULL
345 /* ---------------------------------------------------------------------------
346 * changes the thermal on a via
347 * returns TRUE if changed
349 static void *
350 ChangeViaThermal (PinType *Via)
352 AddObjectToClearPolyUndoList (VIA_TYPE, Via, Via, Via, false);
353 RestoreToPolygon (PCB->Data, VIA_TYPE, CURRENT, Via);
354 AddObjectToFlagUndoList (VIA_TYPE, Via, Via, Via);
355 if (!Delta) /* remove the thermals */
356 CLEAR_THERM (INDEXOFCURRENT, Via);
357 else
358 ASSIGN_THERM (INDEXOFCURRENT, Delta, Via);
359 AddObjectToClearPolyUndoList (VIA_TYPE, Via, Via, Via, true);
360 ClearFromPolygon (PCB->Data, VIA_TYPE, CURRENT, Via);
361 DrawVia (Via);
362 return Via;
365 /* ---------------------------------------------------------------------------
366 * changes the thermal on a pin
367 * returns TRUE if changed
369 static void *
370 ChangePinThermal (ElementType *element, PinType *Pin)
372 AddObjectToClearPolyUndoList (PIN_TYPE, element, Pin, Pin, false);
373 RestoreToPolygon (PCB->Data, VIA_TYPE, CURRENT, Pin);
374 AddObjectToFlagUndoList (PIN_TYPE, element, Pin, Pin);
375 if (!Delta) /* remove the thermals */
376 CLEAR_THERM (INDEXOFCURRENT, Pin);
377 else
378 ASSIGN_THERM (INDEXOFCURRENT, Delta, Pin);
379 AddObjectToClearPolyUndoList (PIN_TYPE, element, Pin, Pin, true);
380 ClearFromPolygon (PCB->Data, VIA_TYPE, CURRENT, Pin);
381 DrawPin (Pin);
382 return Pin;
385 /* ---------------------------------------------------------------------------
386 * changes the size of a via
387 * returns TRUE if changed
389 static void *
390 ChangeViaSize (PinType *Via)
392 Coord value = Absolute ? Absolute : Via->Thickness + Delta;
394 if (TEST_FLAG (LOCKFLAG, Via))
395 return (NULL);
396 if (!TEST_FLAG (HOLEFLAG, Via) && value <= MAX_PINORVIASIZE &&
397 value >= MIN_PINORVIASIZE &&
398 value >= Via->DrillingHole + MIN_PINORVIACOPPER &&
399 value != Via->Thickness)
401 AddObjectToSizeUndoList (VIA_TYPE, Via, Via, Via);
402 EraseVia (Via);
403 r_delete_entry (PCB->Data->via_tree, (BoxType *) Via);
404 RestoreToPolygon (PCB->Data, PIN_TYPE, Via, Via);
405 if (Via->Mask)
407 AddObjectToMaskSizeUndoList (VIA_TYPE, Via, Via, Via);
408 Via->Mask += value - Via->Thickness;
410 Via->Thickness = value;
411 SetPinBoundingBox (Via);
412 r_insert_entry (PCB->Data->via_tree, (BoxType *) Via, 0);
413 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
414 DrawVia (Via);
415 return (Via);
417 return (NULL);
420 /* ---------------------------------------------------------------------------
421 * changes the drilling hole of a via
422 * returns TRUE if changed
424 static void *
425 ChangeVia2ndSize (PinType *Via)
427 Coord value = (Absolute) ? Absolute : Via->DrillingHole + Delta;
429 if (TEST_FLAG (LOCKFLAG, Via))
430 return (NULL);
431 if (value <= MAX_PINORVIASIZE &&
432 value >= MIN_PINORVIAHOLE && (TEST_FLAG (HOLEFLAG, Via) ||
433 value <=
434 Via->Thickness - MIN_PINORVIACOPPER)
435 && value != Via->DrillingHole)
437 AddObjectTo2ndSizeUndoList (VIA_TYPE, Via, Via, Via);
438 EraseVia (Via);
439 RestoreToPolygon (PCB->Data, VIA_TYPE, Via, Via);
440 Via->DrillingHole = value;
441 if (TEST_FLAG (HOLEFLAG, Via))
443 AddObjectToSizeUndoList (VIA_TYPE, Via, Via, Via);
444 Via->Thickness = value;
446 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
447 DrawVia (Via);
448 return (Via);
450 return (NULL);
453 /* ---------------------------------------------------------------------------
454 * changes the clearance size of a via
455 * returns TRUE if changed
457 static void *
458 ChangeViaClearSize (PinType *Via)
460 Coord value = (Absolute) ? Absolute : Via->Clearance + Delta;
462 if (TEST_FLAG (LOCKFLAG, Via))
463 return (NULL);
464 value = MIN (MAX_LINESIZE, value);
465 if (value < 0)
466 value = 0;
467 if (Delta < 0 && value < PCB->Bloat * 2)
468 value = 0;
469 if ((Delta > 0 || Absolute) && value < PCB->Bloat * 2)
470 value = PCB->Bloat * 2 + 2;
471 if (Via->Clearance == value)
472 return NULL;
473 RestoreToPolygon (PCB->Data, VIA_TYPE, Via, Via);
474 AddObjectToClearSizeUndoList (VIA_TYPE, Via, Via, Via);
475 EraseVia (Via);
476 r_delete_entry (PCB->Data->via_tree, (BoxType *) Via);
477 Via->Clearance = value;
478 SetPinBoundingBox (Via);
479 r_insert_entry (PCB->Data->via_tree, (BoxType *) Via, 0);
480 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
481 DrawVia (Via);
482 Via->Element = NULL;
483 return (Via);
487 /* ---------------------------------------------------------------------------
488 * changes the size of a pin
489 * returns TRUE if changed
491 static void *
492 ChangePinSize (ElementType *Element, PinType *Pin)
494 Coord value = (Absolute) ? Absolute : Pin->Thickness + Delta;
496 if (TEST_FLAG (LOCKFLAG, Pin))
497 return (NULL);
498 if (!TEST_FLAG (HOLEFLAG, Pin) && value <= MAX_PINORVIASIZE &&
499 value >= MIN_PINORVIASIZE &&
500 value >= Pin->DrillingHole + MIN_PINORVIACOPPER &&
501 value != Pin->Thickness)
503 AddObjectToSizeUndoList (PIN_TYPE, Element, Pin, Pin);
504 AddObjectToMaskSizeUndoList (PIN_TYPE, Element, Pin, Pin);
505 ErasePin (Pin);
506 r_delete_entry (PCB->Data->pin_tree, &Pin->BoundingBox);
507 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
508 Pin->Mask += value - Pin->Thickness;
509 Pin->Thickness = value;
510 /* SetElementBB updates all associated rtrees */
511 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
512 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
513 DrawPin (Pin);
514 return (Pin);
516 return (NULL);
519 /* ---------------------------------------------------------------------------
520 * changes the clearance size of a pin
521 * returns TRUE if changed
523 static void *
524 ChangePinClearSize (ElementType *Element, PinType *Pin)
526 Coord value = (Absolute) ? Absolute : Pin->Clearance + Delta;
528 if (TEST_FLAG (LOCKFLAG, Pin))
529 return (NULL);
530 value = MIN (MAX_LINESIZE, value);
531 if (value < 0)
532 value = 0;
533 if (Delta < 0 && value < PCB->Bloat * 2)
534 value = 0;
535 if ((Delta > 0 || Absolute) && value < PCB->Bloat * 2)
536 value = PCB->Bloat * 2 + 2;
537 if (Pin->Clearance == value)
538 return NULL;
539 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
540 AddObjectToClearSizeUndoList (PIN_TYPE, Element, Pin, Pin);
541 ErasePin (Pin);
542 r_delete_entry (PCB->Data->pin_tree, &Pin->BoundingBox);
543 Pin->Clearance = value;
544 /* SetElementBB updates all associated rtrees */
545 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
546 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
547 DrawPin (Pin);
548 return (Pin);
551 /* ---------------------------------------------------------------------------
552 * changes the size of a pad
553 * returns TRUE if changed
555 static void *
556 ChangePadSize (ElementType *Element, PadType *Pad)
558 Coord value = (Absolute) ? Absolute : Pad->Thickness + Delta;
560 if (TEST_FLAG (LOCKFLAG, Pad))
561 return (NULL);
562 if (value <= MAX_PADSIZE && value >= MIN_PADSIZE && value != Pad->Thickness)
564 AddObjectToSizeUndoList (PAD_TYPE, Element, Pad, Pad);
565 AddObjectToMaskSizeUndoList (PAD_TYPE, Element, Pad, Pad);
566 RestoreToPolygon (PCB->Data, PAD_TYPE, Element, Pad);
567 ErasePad (Pad);
568 r_delete_entry (PCB->Data->pad_tree, &Pad->BoundingBox);
569 Pad->Mask += value - Pad->Thickness;
570 Pad->Thickness = value;
571 /* SetElementBB updates all associated rtrees */
572 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
573 ClearFromPolygon (PCB->Data, PAD_TYPE, Element, Pad);
574 DrawPad (Pad);
575 return (Pad);
577 return (NULL);
580 /* ---------------------------------------------------------------------------
581 * changes the clearance size of a pad
582 * returns TRUE if changed
584 static void *
585 ChangePadClearSize (ElementType *Element, PadType *Pad)
587 Coord value = (Absolute) ? Absolute : Pad->Clearance + Delta;
589 if (TEST_FLAG (LOCKFLAG, Pad))
590 return (NULL);
591 value = MIN (MAX_LINESIZE, value);
592 if (value < 0)
593 value = 0;
594 if (Delta < 0 && value < PCB->Bloat * 2)
595 value = 0;
596 if ((Delta > 0 || Absolute) && value < PCB->Bloat * 2)
597 value = PCB->Bloat * 2 + 2;
598 if (value == Pad->Clearance)
599 return NULL;
600 AddObjectToClearSizeUndoList (PAD_TYPE, Element, Pad, Pad);
601 RestoreToPolygon (PCB->Data, PAD_TYPE, Element, Pad);
602 ErasePad (Pad);
603 r_delete_entry (PCB->Data->pad_tree, &Pad->BoundingBox);
604 Pad->Clearance = value;
605 /* SetElementBB updates all associated rtrees */
606 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
607 ClearFromPolygon (PCB->Data, PAD_TYPE, Element, Pad);
608 DrawPad (Pad);
609 return Pad;
612 /* ---------------------------------------------------------------------------
613 * changes the drilling hole of all pins of an element
614 * returns TRUE if changed
616 static void *
617 ChangeElement2ndSize (ElementType *Element)
619 bool changed = false;
620 Coord value;
622 if (TEST_FLAG (LOCKFLAG, Element))
623 return (NULL);
624 PIN_LOOP (Element);
626 value = (Absolute) ? Absolute : pin->DrillingHole + Delta;
627 if (value <= MAX_PINORVIASIZE &&
628 value >= MIN_PINORVIAHOLE && (TEST_FLAG (HOLEFLAG, pin) ||
629 value <=
630 pin->Thickness -
631 MIN_PINORVIACOPPER)
632 && value != pin->DrillingHole)
634 changed = true;
635 AddObjectTo2ndSizeUndoList (PIN_TYPE, Element, pin, pin);
636 ErasePin (pin);
637 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, pin);
638 pin->DrillingHole = value;
639 if (TEST_FLAG (HOLEFLAG, pin))
641 AddObjectToSizeUndoList (PIN_TYPE, Element, pin, pin);
642 pin->Thickness = value;
644 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, pin);
645 DrawPin (pin);
648 END_LOOP;
649 if (changed)
650 return (Element);
651 else
652 return (NULL);
655 /* ---------------------------------------------------------------------------
656 * changes the drilling hole of a pin
657 * returns TRUE if changed
659 static void *
660 ChangePin2ndSize (ElementType *Element, PinType *Pin)
662 Coord value = (Absolute) ? Absolute : Pin->DrillingHole + Delta;
664 if (TEST_FLAG (LOCKFLAG, Pin))
665 return (NULL);
666 if (value <= MAX_PINORVIASIZE &&
667 value >= MIN_PINORVIAHOLE && (TEST_FLAG (HOLEFLAG, Pin) ||
668 value <=
669 Pin->Thickness - MIN_PINORVIACOPPER)
670 && value != Pin->DrillingHole)
672 AddObjectTo2ndSizeUndoList (PIN_TYPE, Element, Pin, Pin);
673 ErasePin (Pin);
674 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
675 Pin->DrillingHole = value;
676 if (TEST_FLAG (HOLEFLAG, Pin))
678 AddObjectToSizeUndoList (PIN_TYPE, Element, Pin, Pin);
679 Pin->Thickness = value;
681 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
682 DrawPin (Pin);
683 return (Pin);
685 return (NULL);
688 /* ---------------------------------------------------------------------------
689 * changes the size of a line
690 * returns TRUE if changed
692 static void *
693 ChangeLineSize (LayerType *Layer, LineType *Line)
695 Coord value = (Absolute) ? Absolute : Line->Thickness + Delta;
697 if (TEST_FLAG (LOCKFLAG, Line))
698 return (NULL);
699 if (value <= MAX_LINESIZE && value >= MIN_LINESIZE &&
700 value != Line->Thickness)
702 AddObjectToSizeUndoList (LINE_TYPE, Layer, Line, Line);
703 EraseLine (Line);
704 r_delete_entry (Layer->line_tree, (BoxType *) Line);
705 RestoreToPolygon (PCB->Data, LINE_TYPE, Layer, Line);
706 Line->Thickness = value;
707 SetLineBoundingBox (Line);
708 r_insert_entry (Layer->line_tree, (BoxType *) Line, 0);
709 ClearFromPolygon (PCB->Data, LINE_TYPE, Layer, Line);
710 DrawLine (Layer, Line);
711 return (Line);
713 return (NULL);
716 /* ---------------------------------------------------------------------------
717 * changes the clearance size of a line
718 * returns TRUE if changed
720 static void *
721 ChangeLineClearSize (LayerType *Layer, LineType *Line)
723 Coord value = (Absolute) ? Absolute : Line->Clearance + Delta;
725 if (TEST_FLAG (LOCKFLAG, Line) || !TEST_FLAG (CLEARLINEFLAG, Line))
726 return (NULL);
727 value = MIN (MAX_LINESIZE, MAX (value, PCB->Bloat * 2 + 2));
728 if (value != Line->Clearance)
730 AddObjectToClearSizeUndoList (LINE_TYPE, Layer, Line, Line);
731 RestoreToPolygon (PCB->Data, LINE_TYPE, Layer, Line);
732 EraseLine (Line);
733 r_delete_entry (Layer->line_tree, (BoxType *) Line);
734 Line->Clearance = value;
735 if (Line->Clearance == 0)
737 CLEAR_FLAG (CLEARLINEFLAG, Line);
738 Line->Clearance = MIL_TO_COORD(10);
740 SetLineBoundingBox (Line);
741 r_insert_entry (Layer->line_tree, (BoxType *) Line, 0);
742 ClearFromPolygon (PCB->Data, LINE_TYPE, Layer, Line);
743 DrawLine (Layer, Line);
744 return (Line);
746 return (NULL);
749 /* ---------------------------------------------------------------------------
750 * Handle attepts to change the clearance of a polygon.
752 static void *
753 ChangePolygonClearSize (LayerType *Layer, PolygonType *poly)
755 static int shown_this_message = 0;
756 if (!shown_this_message)
758 gui->confirm_dialog (_("To change the clearance of objects in a polygon, "
759 "change the objects, not the polygon.\n"
760 "Hint: To set a minimum clearance for a group of objects, "
761 "select them all then :MinClearGap(Selected,=10,mil)"),
762 "Ok", NULL);
763 shown_this_message = 1;
766 return (NULL);
769 /* ---------------------------------------------------------------------------
770 * changes the size of an arc
771 * returns TRUE if changed
773 static void *
774 ChangeArcSize (LayerType *Layer, ArcType *Arc)
776 Coord value = (Absolute) ? Absolute : Arc->Thickness + Delta;
778 if (TEST_FLAG (LOCKFLAG, Arc))
779 return (NULL);
780 if (value <= MAX_LINESIZE && value >= MIN_LINESIZE &&
781 value != Arc->Thickness)
783 AddObjectToSizeUndoList (ARC_TYPE, Layer, Arc, Arc);
784 EraseArc (Arc);
785 r_delete_entry (Layer->arc_tree, (BoxType *) Arc);
786 RestoreToPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
787 Arc->Thickness = value;
788 SetArcBoundingBox (Arc);
789 r_insert_entry (Layer->arc_tree, (BoxType *) Arc, 0);
790 ClearFromPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
791 DrawArc (Layer, Arc);
792 return (Arc);
794 return (NULL);
797 /* ---------------------------------------------------------------------------
798 * changes the clearance size of an arc
799 * returns TRUE if changed
801 static void *
802 ChangeArcClearSize (LayerType *Layer, ArcType *Arc)
804 Coord value = (Absolute) ? Absolute : Arc->Clearance + Delta;
806 if (TEST_FLAG (LOCKFLAG, Arc) || !TEST_FLAG (CLEARLINEFLAG, Arc))
807 return (NULL);
808 value = MIN (MAX_LINESIZE, MAX (value, PCB->Bloat * 2 + 2));
809 if (value != Arc->Clearance)
811 AddObjectToClearSizeUndoList (ARC_TYPE, Layer, Arc, Arc);
812 EraseArc (Arc);
813 r_delete_entry (Layer->arc_tree, (BoxType *) Arc);
814 RestoreToPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
815 Arc->Clearance = value;
816 if (Arc->Clearance == 0)
818 CLEAR_FLAG (CLEARLINEFLAG, Arc);
819 Arc->Clearance = MIL_TO_COORD(10);
821 SetArcBoundingBox (Arc);
822 r_insert_entry (Layer->arc_tree, (BoxType *) Arc, 0);
823 ClearFromPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
824 DrawArc (Layer, Arc);
825 return (Arc);
827 return (NULL);
830 /* ---------------------------------------------------------------------------
831 * changes the scaling factor of a text object
832 * returns TRUE if changed
834 static void *
835 ChangeTextSize (LayerType *Layer, TextType *Text)
837 int value = (Absolute != 0 ? 0 : Text->Scale) +
838 (double)(Absolute != 0 ? Absolute : Delta)
839 / (double)FONT_CAPHEIGHT * 100.;
841 if (TEST_FLAG (LOCKFLAG, Text))
842 return (NULL);
843 if (value <= MAX_TEXTSCALE && value >= MIN_TEXTSCALE &&
844 value != Text->Scale)
846 AddObjectToSizeUndoList (TEXT_TYPE, Layer, Text, Text);
847 EraseText (Layer, Text);
848 r_delete_entry (Layer->text_tree, (BoxType *) Text);
849 RestoreToPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
850 Text->Scale = value;
851 SetTextBoundingBox (&PCB->Font, Text);
852 r_insert_entry (Layer->text_tree, (BoxType *) Text, 0);
853 ClearFromPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
854 DrawText (Layer, Text);
855 return (Text);
857 return (NULL);
860 /* ---------------------------------------------------------------------------
861 * changes the scaling factor of an element's outline
862 * returns TRUE if changed
864 static void *
865 ChangeElementSize (ElementType *Element)
867 Coord value;
868 bool changed = false;
870 if (TEST_FLAG (LOCKFLAG, Element))
871 return (NULL);
872 if (PCB->ElementOn)
873 EraseElement (Element);
874 ELEMENTLINE_LOOP (Element);
876 value = (Absolute) ? Absolute : line->Thickness + Delta;
877 if (value <= MAX_LINESIZE && value >= MIN_LINESIZE &&
878 value != line->Thickness)
880 AddObjectToSizeUndoList (ELEMENTLINE_TYPE, Element, line, line);
881 line->Thickness = value;
882 changed = true;
885 END_LOOP;
886 ARC_LOOP (Element);
888 value = (Absolute) ? Absolute : arc->Thickness + Delta;
889 if (value <= MAX_LINESIZE && value >= MIN_LINESIZE &&
890 value != arc->Thickness)
892 AddObjectToSizeUndoList (ELEMENTARC_TYPE, Element, arc, arc);
893 arc->Thickness = value;
894 changed = true;
897 END_LOOP;
898 if (PCB->ElementOn)
900 DrawElement (Element);
902 if (changed)
903 return (Element);
904 return (NULL);
907 /* ---------------------------------------------------------------------------
908 * changes the scaling factor of a elementname object
909 * returns TRUE if changed
911 static void *
912 ChangeElementNameSize (ElementType *Element)
914 int value = (Absolute != 0 ? 0 : DESCRIPTION_TEXT (Element).Scale) +
915 (double)(Absolute != 0 ? Absolute : Delta)
916 / (double)FONT_CAPHEIGHT * 100.;
918 if (TEST_FLAG (LOCKFLAG, &Element->Name[0]))
919 return (NULL);
920 if (value <= MAX_TEXTSCALE && value >= MIN_TEXTSCALE)
922 EraseElementName (Element);
923 ELEMENTTEXT_LOOP (Element);
925 AddObjectToSizeUndoList (ELEMENTNAME_TYPE, Element, text, text);
926 r_delete_entry (PCB->Data->name_tree[n], (BoxType *) text);
927 text->Scale = value;
928 SetTextBoundingBox (&PCB->Font, text);
929 r_insert_entry (PCB->Data->name_tree[n], (BoxType *) text, 0);
931 END_LOOP;
932 DrawElementName (Element);
933 return (Element);
935 return (NULL);
938 /* ---------------------------------------------------------------------------
939 * changes the name of a via
941 static void *
942 ChangeViaName (PinType *Via)
944 char *old = Via->Name;
946 if (TEST_FLAG (DISPLAYNAMEFLAG, Via))
948 ErasePinName (Via);
949 Via->Name = NewName;
950 DrawPinName (Via);
952 else
953 Via->Name = NewName;
954 return (old);
957 /* ---------------------------------------------------------------------------
958 * changes the name of a pin
960 static void *
961 ChangePinName (ElementType *Element, PinType *Pin)
963 char *old = Pin->Name;
965 (void) Element; /* get rid of 'unused...' warnings */
966 if (TEST_FLAG (DISPLAYNAMEFLAG, Pin))
968 ErasePinName (Pin);
969 Pin->Name = NewName;
970 DrawPinName (Pin);
972 else
973 Pin->Name = NewName;
974 return (old);
977 /* ---------------------------------------------------------------------------
978 * changes the name of a pad
980 static void *
981 ChangePadName (ElementType *Element, PadType *Pad)
983 char *old = Pad->Name;
985 (void) Element; /* get rid of 'unused...' warnings */
986 if (TEST_FLAG (DISPLAYNAMEFLAG, Pad))
988 ErasePadName (Pad);
989 Pad->Name = NewName;
990 DrawPadName (Pad);
992 else
993 Pad->Name = NewName;
994 return (old);
997 /* ---------------------------------------------------------------------------
998 * changes the name of a line
1000 static void *
1001 ChangeLineName (LayerType *Layer, LineType *Line)
1003 char *old = Line->Number;
1005 (void) Layer;
1006 Line->Number = NewName;
1007 return (old);
1010 /* ---------------------------------------------------------------------------
1011 * changes the layout-name of an element
1014 char *
1015 ChangeElementText (PCBType *pcb, DataType *data, ElementType *Element, int which, char *new_name)
1017 char *old = Element->Name[which].TextString;
1019 #ifdef DEBUG
1020 printf("In ChangeElementText, updating old TextString %s to %s\n", old, new_name);
1021 #endif
1023 if (pcb && which == NAME_INDEX (pcb))
1024 EraseElementName (Element);
1026 r_delete_entry (data->name_tree[which],
1027 & Element->Name[which].BoundingBox);
1029 Element->Name[which].TextString = new_name;
1030 SetTextBoundingBox (&PCB->Font, &Element->Name[which]);
1032 r_insert_entry (data->name_tree[which],
1033 & Element->Name[which].BoundingBox, 0);
1035 if (pcb && which == NAME_INDEX (pcb))
1036 DrawElementName (Element);
1038 return old;
1041 static void *
1042 ChangeElementName (ElementType *Element)
1044 if (TEST_FLAG (LOCKFLAG, &Element->Name[0]))
1045 return (NULL);
1046 if (NAME_INDEX (PCB) == NAMEONPCB_INDEX)
1048 if (TEST_FLAG (UNIQUENAMEFLAG, PCB) &&
1049 UniqueElementName (PCB->Data, NewName) != NewName)
1051 Message (_("Error: The name \"%s\" is not unique!\n"), NewName);
1052 return ((char *) -1);
1056 return ChangeElementText (PCB, PCB->Data, Element, NAME_INDEX (PCB), NewName);
1059 /* ---------------------------------------------------------------------------
1060 * sets data of a text object and calculates bounding box
1061 * memory must have already been allocated
1062 * the one for the new string is allocated
1063 * returns true if the string has been changed
1065 static void *
1066 ChangeTextName (LayerType *Layer, TextType *Text)
1068 char *old = Text->TextString;
1070 if (TEST_FLAG (LOCKFLAG, Text))
1071 return (NULL);
1072 EraseText (Layer, Text);
1073 RestoreToPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
1074 Text->TextString = NewName;
1076 /* calculate size of the bounding box */
1077 SetTextBoundingBox (&PCB->Font, Text);
1078 ClearFromPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
1079 DrawText (Layer, Text);
1080 return (old);
1083 /* ---------------------------------------------------------------------------
1084 * changes the name of a layout; memory has to be already allocated
1086 bool
1087 ChangeLayoutName (char *Name)
1089 free (PCB->Name);
1090 PCB->Name = Name;
1091 hid_action ("PCBChanged");
1092 return (true);
1095 /* ---------------------------------------------------------------------------
1096 * changes the side of the board an element is on
1097 * returns TRUE if done
1099 bool
1100 ChangeElementSide (ElementType *Element, Coord yoff)
1102 if (TEST_FLAG (LOCKFLAG, Element))
1103 return (false);
1104 EraseElement (Element);
1105 AddObjectToMirrorUndoList (ELEMENT_TYPE, Element, Element, Element, yoff);
1106 MirrorElementCoordinates (PCB->Data, Element, yoff);
1107 DrawElement (Element);
1108 return (true);
1111 /* ---------------------------------------------------------------------------
1112 * changes the name of a layer; memory has to be already allocated
1114 bool
1115 ChangeLayerName (LayerType *Layer, char *Name)
1117 free (CURRENT->Name);
1118 CURRENT->Name = Name;
1119 hid_action ("LayersChanged");
1120 return (true);
1123 /* ---------------------------------------------------------------------------
1124 * changes the clearance flag of a line
1126 static void *
1127 ChangeLineJoin (LayerType *Layer, LineType *Line)
1129 if (TEST_FLAG (LOCKFLAG, Line))
1130 return (NULL);
1131 EraseLine (Line);
1132 if (TEST_FLAG(CLEARLINEFLAG, Line))
1134 AddObjectToClearPolyUndoList (LINE_TYPE, Layer, Line, Line, false);
1135 RestoreToPolygon (PCB->Data, LINE_TYPE, Layer, Line);
1137 AddObjectToFlagUndoList (LINE_TYPE, Layer, Line, Line);
1138 TOGGLE_FLAG (CLEARLINEFLAG, Line);
1139 if (TEST_FLAG(CLEARLINEFLAG, Line))
1141 AddObjectToClearPolyUndoList (LINE_TYPE, Layer, Line, Line, true);
1142 ClearFromPolygon (PCB->Data, LINE_TYPE, Layer, Line);
1144 DrawLine (Layer, Line);
1145 return (Line);
1148 /* ---------------------------------------------------------------------------
1149 * sets the clearance flag of a line
1151 static void *
1152 SetLineJoin (LayerType *Layer, LineType *Line)
1154 if (TEST_FLAG (LOCKFLAG, Line) || TEST_FLAG (CLEARLINEFLAG, Line))
1155 return (NULL);
1156 return ChangeLineJoin (Layer, Line);
1159 /* ---------------------------------------------------------------------------
1160 * clears the clearance flag of a line
1162 static void *
1163 ClrLineJoin (LayerType *Layer, LineType *Line)
1165 if (TEST_FLAG (LOCKFLAG, Line) || !TEST_FLAG (CLEARLINEFLAG, Line))
1166 return (NULL);
1167 return ChangeLineJoin (Layer, Line);
1170 /* ---------------------------------------------------------------------------
1171 * changes the clearance flag of an arc
1173 static void *
1174 ChangeArcJoin (LayerType *Layer, ArcType *Arc)
1176 if (TEST_FLAG (LOCKFLAG, Arc))
1177 return (NULL);
1178 EraseArc (Arc);
1179 if (TEST_FLAG (CLEARLINEFLAG, Arc))
1181 RestoreToPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
1182 AddObjectToClearPolyUndoList (ARC_TYPE, Layer, Arc, Arc, false);
1184 AddObjectToFlagUndoList (ARC_TYPE, Layer, Arc, Arc);
1185 TOGGLE_FLAG (CLEARLINEFLAG, Arc);
1186 if (TEST_FLAG (CLEARLINEFLAG, Arc))
1188 ClearFromPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
1189 AddObjectToClearPolyUndoList (ARC_TYPE, Layer, Arc, Arc, true);
1191 DrawArc (Layer, Arc);
1192 return (Arc);
1195 /* ---------------------------------------------------------------------------
1196 * sets the clearance flag of an arc
1198 static void *
1199 SetArcJoin (LayerType *Layer, ArcType *Arc)
1201 if (TEST_FLAG (LOCKFLAG, Arc) || TEST_FLAG (CLEARLINEFLAG, Arc))
1202 return (NULL);
1203 return ChangeArcJoin (Layer, Arc);
1206 /* ---------------------------------------------------------------------------
1207 * clears the clearance flag of an arc
1209 static void *
1210 ClrArcJoin (LayerType *Layer, ArcType *Arc)
1212 if (TEST_FLAG (LOCKFLAG, Arc) || !TEST_FLAG (CLEARLINEFLAG, Arc))
1213 return (NULL);
1214 return ChangeArcJoin (Layer, Arc);
1217 /* ---------------------------------------------------------------------------
1218 * changes the clearance flag of a text
1220 static void *
1221 ChangeTextJoin (LayerType *Layer, TextType *Text)
1223 if (TEST_FLAG (LOCKFLAG, Text))
1224 return (NULL);
1225 EraseText (Layer, Text);
1226 if (TEST_FLAG(CLEARLINEFLAG, Text))
1228 AddObjectToClearPolyUndoList (TEXT_TYPE, Layer, Text, Text, false);
1229 RestoreToPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
1231 AddObjectToFlagUndoList (LINE_TYPE, Layer, Text, Text);
1232 TOGGLE_FLAG (CLEARLINEFLAG, Text);
1233 if (TEST_FLAG(CLEARLINEFLAG, Text))
1235 AddObjectToClearPolyUndoList (TEXT_TYPE, Layer, Text, Text, true);
1236 ClearFromPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
1238 DrawText (Layer, Text);
1239 return (Text);
1242 /* ---------------------------------------------------------------------------
1243 * sets the clearance flag of a text
1245 static void *
1246 SetTextJoin (LayerType *Layer, TextType *Text)
1248 if (TEST_FLAG (LOCKFLAG, Text) || TEST_FLAG (CLEARLINEFLAG, Text))
1249 return (NULL);
1250 return ChangeTextJoin (Layer, Text);
1253 /* ---------------------------------------------------------------------------
1254 * clears the clearance flag of a text
1256 static void *
1257 ClrTextJoin (LayerType *Layer, TextType *Text)
1259 if (TEST_FLAG (LOCKFLAG, Text) || !TEST_FLAG (CLEARLINEFLAG, Text))
1260 return (NULL);
1261 return ChangeTextJoin (Layer, Text);
1264 /* ---------------------------------------------------------------------------
1265 * changes the square flag of all pins on an element
1267 static void *
1268 ChangeElementSquare (ElementType *Element)
1270 void *ans = NULL;
1272 if (TEST_FLAG (LOCKFLAG, Element))
1273 return (NULL);
1274 PIN_LOOP (Element);
1276 ans = ChangePinSquare (Element, pin);
1278 END_LOOP;
1279 PAD_LOOP (Element);
1281 ans = ChangePadSquare (Element, pad);
1283 END_LOOP;
1284 return (ans);
1287 /* ---------------------------------------------------------------------------
1288 * sets the square flag of all pins on an element
1290 static void *
1291 SetElementSquare (ElementType *Element)
1293 void *ans = NULL;
1295 if (TEST_FLAG (LOCKFLAG, Element))
1296 return (NULL);
1297 PIN_LOOP (Element);
1299 ans = SetPinSquare (Element, pin);
1301 END_LOOP;
1302 PAD_LOOP (Element);
1304 ans = SetPadSquare (Element, pad);
1306 END_LOOP;
1307 return (ans);
1310 /* ---------------------------------------------------------------------------
1311 * clears the square flag of all pins on an element
1313 static void *
1314 ClrElementSquare (ElementType *Element)
1316 void *ans = NULL;
1318 if (TEST_FLAG (LOCKFLAG, Element))
1319 return (NULL);
1320 PIN_LOOP (Element);
1322 ans = ClrPinSquare (Element, pin);
1324 END_LOOP;
1325 PAD_LOOP (Element);
1327 ans = ClrPadSquare (Element, pad);
1329 END_LOOP;
1330 return (ans);
1333 /* ---------------------------------------------------------------------------
1334 * changes the octagon flags of all pins of an element
1336 static void *
1337 ChangeElementOctagon (ElementType *Element)
1339 void *result = NULL;
1341 if (TEST_FLAG (LOCKFLAG, Element))
1342 return (NULL);
1343 PIN_LOOP (Element);
1345 ChangePinOctagon (Element, pin);
1346 result = Element;
1348 END_LOOP;
1349 return (result);
1352 /* ---------------------------------------------------------------------------
1353 * sets the octagon flags of all pins of an element
1355 static void *
1356 SetElementOctagon (ElementType *Element)
1358 void *result = NULL;
1360 if (TEST_FLAG (LOCKFLAG, Element))
1361 return (NULL);
1362 PIN_LOOP (Element);
1364 SetPinOctagon (Element, pin);
1365 result = Element;
1367 END_LOOP;
1368 return (result);
1371 /* ---------------------------------------------------------------------------
1372 * clears the octagon flags of all pins of an element
1374 static void *
1375 ClrElementOctagon (ElementType *Element)
1377 void *result = NULL;
1379 if (TEST_FLAG (LOCKFLAG, Element))
1380 return (NULL);
1381 PIN_LOOP (Element);
1383 ClrPinOctagon (Element, pin);
1384 result = Element;
1386 END_LOOP;
1387 return (result);
1390 /* ---------------------------------------------------------------------------
1391 * changes the square flag of a pad
1393 static void *
1394 ChangePadSquare (ElementType *Element, PadType *Pad)
1396 if (TEST_FLAG (LOCKFLAG, Pad))
1397 return (NULL);
1398 ErasePad (Pad);
1399 AddObjectToClearPolyUndoList (PAD_TYPE, Element, Pad, Pad, false);
1400 RestoreToPolygon (PCB->Data, PAD_TYPE, Element, Pad);
1401 AddObjectToFlagUndoList (PAD_TYPE, Element, Pad, Pad);
1402 TOGGLE_FLAG (SQUAREFLAG, Pad);
1403 AddObjectToClearPolyUndoList (PAD_TYPE, Element, Pad, Pad, true);
1404 ClearFromPolygon (PCB->Data, PAD_TYPE, Element, Pad);
1405 DrawPad (Pad);
1406 return (Pad);
1409 /* ---------------------------------------------------------------------------
1410 * sets the square flag of a pad
1412 static void *
1413 SetPadSquare (ElementType *Element, PadType *Pad)
1416 if (TEST_FLAG (LOCKFLAG, Pad) || TEST_FLAG (SQUAREFLAG, Pad))
1417 return (NULL);
1419 return (ChangePadSquare (Element, Pad));
1423 /* ---------------------------------------------------------------------------
1424 * clears the square flag of a pad
1426 static void *
1427 ClrPadSquare (ElementType *Element, PadType *Pad)
1430 if (TEST_FLAG (LOCKFLAG, Pad) || !TEST_FLAG (SQUAREFLAG, Pad))
1431 return (NULL);
1433 return (ChangePadSquare (Element, Pad));
1437 /* ---------------------------------------------------------------------------
1438 * changes the square flag of a pin
1440 static void *
1441 ChangePinSquare (ElementType *Element, PinType *Pin)
1443 if (TEST_FLAG (LOCKFLAG, Pin))
1444 return (NULL);
1445 ErasePin (Pin);
1446 AddObjectToClearPolyUndoList (PIN_TYPE, Element, Pin, Pin, false);
1447 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
1448 AddObjectToFlagUndoList (PIN_TYPE, Element, Pin, Pin);
1449 TOGGLE_FLAG (SQUAREFLAG, Pin);
1450 AddObjectToClearPolyUndoList (PIN_TYPE, Element, Pin, Pin, true);
1451 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
1452 DrawPin (Pin);
1453 return (Pin);
1456 /* ---------------------------------------------------------------------------
1457 * sets the square flag of a pin
1459 static void *
1460 SetPinSquare (ElementType *Element, PinType *Pin)
1462 if (TEST_FLAG (LOCKFLAG, Pin) || TEST_FLAG (SQUAREFLAG, Pin))
1463 return (NULL);
1465 return (ChangePinSquare (Element, Pin));
1468 /* ---------------------------------------------------------------------------
1469 * clears the square flag of a pin
1471 static void *
1472 ClrPinSquare (ElementType *Element, PinType *Pin)
1474 if (TEST_FLAG (LOCKFLAG, Pin) || !TEST_FLAG (SQUAREFLAG, Pin))
1475 return (NULL);
1477 return (ChangePinSquare (Element, Pin));
1480 /* ---------------------------------------------------------------------------
1481 * changes the octagon flag of a via
1483 static void *
1484 ChangeViaOctagon (PinType *Via)
1486 if (TEST_FLAG (LOCKFLAG, Via))
1487 return (NULL);
1488 EraseVia (Via);
1489 AddObjectToClearPolyUndoList (VIA_TYPE, Via, Via, Via, false);
1490 RestoreToPolygon (PCB->Data, VIA_TYPE, Via, Via);
1491 AddObjectToFlagUndoList (VIA_TYPE, Via, Via, Via);
1492 TOGGLE_FLAG (OCTAGONFLAG, Via);
1493 AddObjectToClearPolyUndoList (VIA_TYPE, Via, Via, Via, true);
1494 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
1495 DrawVia (Via);
1496 return (Via);
1499 /* ---------------------------------------------------------------------------
1500 * sets the octagon flag of a via
1502 static void *
1503 SetViaOctagon (PinType *Via)
1505 if (TEST_FLAG (LOCKFLAG, Via) || TEST_FLAG (OCTAGONFLAG, Via))
1506 return (NULL);
1508 return (ChangeViaOctagon (Via));
1511 /* ---------------------------------------------------------------------------
1512 * clears the octagon flag of a via
1514 static void *
1515 ClrViaOctagon (PinType *Via)
1517 if (TEST_FLAG (LOCKFLAG, Via) || !TEST_FLAG (OCTAGONFLAG, Via))
1518 return (NULL);
1520 return (ChangeViaOctagon (Via));
1523 /* ---------------------------------------------------------------------------
1524 * changes the octagon flag of a pin
1526 static void *
1527 ChangePinOctagon (ElementType *Element, PinType *Pin)
1529 if (TEST_FLAG (LOCKFLAG, Pin))
1530 return (NULL);
1531 ErasePin (Pin);
1532 AddObjectToClearPolyUndoList (PIN_TYPE, Element, Pin, Pin, false);
1533 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
1534 AddObjectToFlagUndoList (PIN_TYPE, Element, Pin, Pin);
1535 TOGGLE_FLAG (OCTAGONFLAG, Pin);
1536 AddObjectToClearPolyUndoList (PIN_TYPE, Element, Pin, Pin, true);
1537 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
1538 DrawPin (Pin);
1539 return (Pin);
1542 /* ---------------------------------------------------------------------------
1543 * sets the octagon flag of a pin
1545 static void *
1546 SetPinOctagon (ElementType *Element, PinType *Pin)
1548 if (TEST_FLAG (LOCKFLAG, Pin) || TEST_FLAG (OCTAGONFLAG, Pin))
1549 return (NULL);
1551 return (ChangePinOctagon (Element, Pin));
1554 /* ---------------------------------------------------------------------------
1555 * clears the octagon flag of a pin
1557 static void *
1558 ClrPinOctagon (ElementType *Element, PinType *Pin)
1560 if (TEST_FLAG (LOCKFLAG, Pin) || !TEST_FLAG (OCTAGONFLAG, Pin))
1561 return (NULL);
1563 return (ChangePinOctagon (Element, Pin));
1566 /* ---------------------------------------------------------------------------
1567 * changes the hole flag of a via
1569 bool
1570 ChangeHole (PinType *Via)
1572 if (TEST_FLAG (LOCKFLAG, Via))
1573 return (false);
1574 EraseVia (Via);
1575 AddObjectToFlagUndoList (VIA_TYPE, Via, Via, Via);
1576 AddObjectToMaskSizeUndoList (VIA_TYPE, Via, Via, Via);
1577 r_delete_entry (PCB->Data->via_tree, (BoxType *) Via);
1578 RestoreToPolygon (PCB->Data, VIA_TYPE, Via, Via);
1579 TOGGLE_FLAG (HOLEFLAG, Via);
1581 if (TEST_FLAG (HOLEFLAG, Via))
1583 /* A tented via becomes an minimally untented hole. An untented
1584 via retains its mask clearance. */
1585 if (Via->Mask > Via->Thickness)
1587 Via->Mask = (Via->DrillingHole
1588 + (Via->Mask - Via->Thickness));
1590 else if (Via->Mask < Via->DrillingHole)
1592 Via->Mask = Via->DrillingHole + 2 * MASKFRAME;
1595 else
1597 Via->Mask = (Via->Thickness
1598 + (Via->Mask - Via->DrillingHole));
1601 SetPinBoundingBox (Via);
1602 r_insert_entry (PCB->Data->via_tree, (BoxType *) Via, 0);
1603 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
1604 DrawVia (Via);
1605 Draw ();
1606 return (true);
1609 /* ---------------------------------------------------------------------------
1610 * changes the nopaste flag of a pad
1612 bool
1613 ChangePaste (PadType *Pad)
1615 if (TEST_FLAG (LOCKFLAG, Pad))
1616 return (false);
1617 ErasePad (Pad);
1618 AddObjectToFlagUndoList (PAD_TYPE, Pad, Pad, Pad);
1619 TOGGLE_FLAG (NOPASTEFLAG, Pad);
1620 DrawPad (Pad);
1621 Draw ();
1622 return (true);
1625 /* ---------------------------------------------------------------------------
1626 * changes the CLEARPOLY flag of a polygon
1628 static void *
1629 ChangePolyClear (LayerType *Layer, PolygonType *Polygon)
1631 if (TEST_FLAG (LOCKFLAG, Polygon))
1632 return (NULL);
1633 AddObjectToClearPolyUndoList (POLYGON_TYPE, Layer, Polygon, Polygon, true);
1634 AddObjectToFlagUndoList (POLYGON_TYPE, Layer, Polygon, Polygon);
1635 TOGGLE_FLAG (CLEARPOLYFLAG, Polygon);
1636 InitClip (PCB->Data, Layer, Polygon);
1637 DrawPolygon (Layer, Polygon);
1638 return (Polygon);
1641 /* ----------------------------------------------------------------------
1642 * changes the side of all selected and visible elements
1643 * returns true if anything has changed
1645 bool
1646 ChangeSelectedElementSide (void)
1648 bool change = false;
1650 /* setup identifiers */
1651 if (PCB->PinOn && PCB->ElementOn)
1652 ELEMENT_LOOP (PCB->Data);
1654 if (TEST_FLAG (SELECTEDFLAG, element))
1656 change |= ChangeElementSide (element, 0);
1659 END_LOOP;
1660 if (change)
1662 Draw ();
1663 IncrementUndoSerialNumber ();
1665 return (change);
1668 /* ----------------------------------------------------------------------
1669 * changes the thermals on all selected and visible pins
1670 * and/or vias. Returns true if anything has changed
1672 bool
1673 ChangeSelectedThermals (int types, int therm_style)
1675 bool change = false;
1677 Delta = therm_style;
1678 change = SelectedOperation (&ChangeThermalFunctions, false, types);
1679 if (change)
1681 Draw ();
1682 IncrementUndoSerialNumber ();
1684 return (change);
1687 /* ----------------------------------------------------------------------
1688 * changes the size of all selected and visible object types
1689 * returns true if anything has changed
1691 bool
1692 ChangeSelectedSize (int types, Coord Difference, bool fixIt)
1694 bool change = false;
1696 /* setup identifiers */
1697 Absolute = (fixIt) ? Difference : 0;
1698 Delta = Difference;
1700 change = SelectedOperation (&ChangeSizeFunctions, false, types);
1701 if (change)
1703 Draw ();
1704 IncrementUndoSerialNumber ();
1706 return (change);
1709 /* ----------------------------------------------------------------------
1710 * changes the clearance size of all selected and visible objects
1711 * returns true if anything has changed
1713 bool
1714 ChangeSelectedClearSize (int types, Coord Difference, bool fixIt)
1716 bool change = false;
1718 /* setup identifiers */
1719 Absolute = (fixIt) ? Difference : 0;
1720 Delta = Difference;
1721 if (TEST_FLAG (SHOWMASKFLAG, PCB))
1722 change = SelectedOperation (&ChangeMaskSizeFunctions, false, types);
1723 else
1724 change = SelectedOperation (&ChangeClearSizeFunctions, false, types);
1725 if (change)
1727 Draw ();
1728 IncrementUndoSerialNumber ();
1730 return (change);
1733 /* --------------------------------------------------------------------------
1734 * changes the 2nd size (drilling hole) of all selected and visible objects
1735 * returns true if anything has changed
1737 bool
1738 ChangeSelected2ndSize (int types, Coord Difference, bool fixIt)
1740 bool change = false;
1742 /* setup identifiers */
1743 Absolute = (fixIt) ? Difference : 0;
1744 Delta = Difference;
1745 change = SelectedOperation (&Change2ndSizeFunctions, false, types);
1746 if (change)
1748 Draw ();
1749 IncrementUndoSerialNumber ();
1751 return (change);
1754 /* ----------------------------------------------------------------------
1755 * changes the clearance flag (join) of all selected and visible lines
1756 * and/or arcs. Returns true if anything has changed
1758 bool
1759 ChangeSelectedJoin (int types)
1761 bool change = false;
1763 change = SelectedOperation (&ChangeJoinFunctions, false, types);
1764 if (change)
1766 Draw ();
1767 IncrementUndoSerialNumber ();
1769 return (change);
1772 /* ----------------------------------------------------------------------
1773 * changes the clearance flag (join) of all selected and visible lines
1774 * and/or arcs. Returns true if anything has changed
1776 bool
1777 SetSelectedJoin (int types)
1779 bool change = false;
1781 change = SelectedOperation (&SetJoinFunctions, false, types);
1782 if (change)
1784 Draw ();
1785 IncrementUndoSerialNumber ();
1787 return (change);
1790 /* ----------------------------------------------------------------------
1791 * changes the clearance flag (join) of all selected and visible lines
1792 * and/or arcs. Returns true if anything has changed
1794 bool
1795 ClrSelectedJoin (int types)
1797 bool change = false;
1799 change = SelectedOperation (&ClrJoinFunctions, false, types);
1800 if (change)
1802 Draw ();
1803 IncrementUndoSerialNumber ();
1805 return (change);
1808 /* ----------------------------------------------------------------------
1809 * changes the square-flag of all selected and visible pins or pads
1810 * returns true if anything has changed
1812 bool
1813 ChangeSelectedSquare (int types)
1815 bool change = false;
1817 change = SelectedOperation (&ChangeSquareFunctions, false, types);
1818 if (change)
1820 Draw ();
1821 IncrementUndoSerialNumber ();
1823 return (change);
1826 /* ----------------------------------------------------------------------
1827 * sets the square-flag of all selected and visible pins or pads
1828 * returns true if anything has changed
1830 bool
1831 SetSelectedSquare (int types)
1833 bool change = false;
1835 change = SelectedOperation (&SetSquareFunctions, false, types);
1836 if (change)
1838 Draw ();
1839 IncrementUndoSerialNumber ();
1841 return (change);
1844 /* ----------------------------------------------------------------------
1845 * clears the square-flag of all selected and visible pins or pads
1846 * returns true if anything has changed
1848 bool
1849 ClrSelectedSquare (int types)
1851 bool change = false;
1853 change = SelectedOperation (&ClrSquareFunctions, false, types);
1854 if (change)
1856 Draw ();
1857 IncrementUndoSerialNumber ();
1859 return (change);
1862 /* ----------------------------------------------------------------------
1863 * changes the octagon-flag of all selected and visible pins and vias
1864 * returns true if anything has changed
1866 bool
1867 ChangeSelectedOctagon (int types)
1869 bool change = false;
1871 change = SelectedOperation (&ChangeOctagonFunctions, false, types);
1872 if (change)
1874 Draw ();
1875 IncrementUndoSerialNumber ();
1877 return (change);
1880 /* ----------------------------------------------------------------------
1881 * sets the octagon-flag of all selected and visible pins and vias
1882 * returns true if anything has changed
1884 bool
1885 SetSelectedOctagon (int types)
1887 bool change = false;
1889 change = SelectedOperation (&SetOctagonFunctions, false, types);
1890 if (change)
1892 Draw ();
1893 IncrementUndoSerialNumber ();
1895 return (change);
1898 /* ----------------------------------------------------------------------
1899 * clears the octagon-flag of all selected and visible pins and vias
1900 * returns true if anything has changed
1902 bool
1903 ClrSelectedOctagon (int types)
1905 bool change = false;
1907 change = SelectedOperation (&ClrOctagonFunctions, false, types);
1908 if (change)
1910 Draw ();
1911 IncrementUndoSerialNumber ();
1913 return (change);
1916 /* ----------------------------------------------------------------------
1917 * changes the hole-flag of all selected and visible vias
1918 * returns true if anything has changed
1920 bool
1921 ChangeSelectedHole (void)
1923 bool change = false;
1925 if (PCB->ViaOn)
1926 VIA_LOOP (PCB->Data);
1928 if (TEST_FLAG (SELECTEDFLAG, via))
1929 change |= ChangeHole (via);
1931 END_LOOP;
1932 if (change)
1934 Draw ();
1935 IncrementUndoSerialNumber ();
1937 return (change);
1940 /* ----------------------------------------------------------------------
1941 * changes the no paste-flag of all selected and visible pads
1942 * returns true if anything has changed
1944 bool
1945 ChangeSelectedPaste (void)
1947 bool change = false;
1949 ALLPAD_LOOP (PCB->Data);
1951 if (TEST_FLAG (SELECTEDFLAG, pad))
1952 change |= ChangePaste (pad);
1954 ENDALL_LOOP;
1955 if (change)
1957 Draw ();
1958 IncrementUndoSerialNumber ();
1960 return (change);
1964 /* ---------------------------------------------------------------------------
1965 * changes the size of the passed object
1966 * Returns true if anything is changed
1968 bool
1969 ChangeObjectSize (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
1970 Coord Difference, bool fixIt)
1972 bool change;
1974 /* setup identifier */
1975 Absolute = (fixIt) ? Difference : 0;
1976 Delta = Difference;
1977 change =
1978 (ObjectOperation (&ChangeSizeFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL);
1979 if (change)
1981 Draw ();
1982 IncrementUndoSerialNumber ();
1984 return (change);
1987 /* ---------------------------------------------------------------------------
1988 * changes the clearance size of the passed object
1989 * Returns true if anything is changed
1991 bool
1992 ChangeObjectClearSize (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
1993 Coord Difference, bool fixIt)
1995 bool change;
1997 /* setup identifier */
1998 Absolute = (fixIt) ? Difference : 0;
1999 Delta = Difference;
2000 if (TEST_FLAG (SHOWMASKFLAG, PCB))
2001 change =
2002 (ObjectOperation (&ChangeMaskSizeFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2003 NULL);
2004 else
2005 change =
2006 (ObjectOperation (&ChangeClearSizeFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2007 NULL);
2008 if (change)
2010 Draw ();
2011 IncrementUndoSerialNumber ();
2013 return (change);
2016 /* ---------------------------------------------------------------------------
2017 * changes the thermal of the passed object
2018 * Returns true if anything is changed
2021 bool
2022 ChangeObjectThermal (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
2023 int therm_type)
2025 bool change;
2027 Delta = Absolute = therm_type;
2028 change =
2029 (ObjectOperation (&ChangeThermalFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2030 NULL);
2031 if (change)
2033 Draw ();
2034 IncrementUndoSerialNumber ();
2036 return (change);
2039 /* ---------------------------------------------------------------------------
2040 * changes the 2nd size of the passed object
2041 * Returns true if anything is changed
2043 bool
2044 ChangeObject2ndSize (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
2045 Coord Difference, bool fixIt, bool incundo)
2047 bool change;
2049 /* setup identifier */
2050 Absolute = (fixIt) ? Difference : 0;
2051 Delta = Difference;
2052 change =
2053 (ObjectOperation (&Change2ndSizeFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2054 NULL);
2055 if (change)
2057 Draw ();
2058 if (incundo)
2059 IncrementUndoSerialNumber ();
2061 return (change);
2064 /* ---------------------------------------------------------------------------
2065 * changes the mask size of the passed object
2066 * Returns true if anything is changed
2068 bool
2069 ChangeObjectMaskSize (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
2070 Coord Difference, bool fixIt)
2072 bool change;
2074 /* setup identifier */
2075 Absolute = (fixIt) ? Difference : 0;
2076 Delta = Difference;
2077 change =
2078 (ObjectOperation (&ChangeMaskSizeFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2079 NULL);
2080 if (change)
2082 Draw ();
2083 IncrementUndoSerialNumber ();
2085 return (change);
2088 /* ---------------------------------------------------------------------------
2089 * changes the name of the passed object
2090 * returns the old name
2092 * The allocated memory isn't freed because the old string is used
2093 * by the undo module.
2095 void *
2096 ChangeObjectName (int Type, void *Ptr1, void *Ptr2, void *Ptr3, char *Name)
2098 void *result;
2099 /* setup identifier */
2100 NewName = Name;
2101 result = ObjectOperation (&ChangeNameFunctions, Type, Ptr1, Ptr2, Ptr3);
2102 Draw ();
2103 return (result);
2106 /* ---------------------------------------------------------------------------
2107 * changes the clearance-flag of the passed object
2108 * Returns true if anything is changed
2110 bool
2111 ChangeObjectJoin (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2113 if (ObjectOperation (&ChangeJoinFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2115 Draw ();
2116 IncrementUndoSerialNumber ();
2117 return (true);
2119 return (false);
2122 /* ---------------------------------------------------------------------------
2123 * sets the clearance-flag of the passed object
2124 * Returns true if anything is changed
2126 bool
2127 SetObjectJoin (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2129 if (ObjectOperation (&SetJoinFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2131 Draw ();
2132 IncrementUndoSerialNumber ();
2133 return (true);
2135 return (false);
2138 /* ---------------------------------------------------------------------------
2139 * clears the clearance-flag of the passed object
2140 * Returns true if anything is changed
2142 bool
2143 ClrObjectJoin (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2145 if (ObjectOperation (&ClrJoinFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2147 Draw ();
2148 IncrementUndoSerialNumber ();
2149 return (true);
2151 return (false);
2154 /* ---------------------------------------------------------------------------
2155 * changes the square-flag of the passed object
2156 * Returns true if anything is changed
2158 bool
2159 ChangeObjectSquare (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2161 if (ObjectOperation (&ChangeSquareFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2162 NULL)
2164 Draw ();
2165 IncrementUndoSerialNumber ();
2166 return (true);
2168 return (false);
2171 /* ---------------------------------------------------------------------------
2172 * sets the square-flag of the passed object
2173 * Returns true if anything is changed
2175 bool
2176 SetObjectSquare (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2178 if (ObjectOperation (&SetSquareFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2180 Draw ();
2181 IncrementUndoSerialNumber ();
2182 return (true);
2184 return (false);
2187 /* ---------------------------------------------------------------------------
2188 * clears the square-flag of the passed object
2189 * Returns true if anything is changed
2191 bool
2192 ClrObjectSquare (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2194 if (ObjectOperation (&ClrSquareFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2196 Draw ();
2197 IncrementUndoSerialNumber ();
2198 return (true);
2200 return (false);
2203 /* ---------------------------------------------------------------------------
2204 * changes the octagon-flag of the passed object
2205 * Returns true if anything is changed
2207 bool
2208 ChangeObjectOctagon (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2210 if (ObjectOperation (&ChangeOctagonFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2211 NULL)
2213 Draw ();
2214 IncrementUndoSerialNumber ();
2215 return (true);
2217 return (false);
2220 /* ---------------------------------------------------------------------------
2221 * sets the octagon-flag of the passed object
2222 * Returns true if anything is changed
2224 bool
2225 SetObjectOctagon (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2227 if (ObjectOperation (&SetOctagonFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2229 Draw ();
2230 IncrementUndoSerialNumber ();
2231 return (true);
2233 return (false);
2236 /* ---------------------------------------------------------------------------
2237 * clears the octagon-flag of the passed object
2238 * Returns true if anything is changed
2240 bool
2241 ClrObjectOctagon (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2243 if (ObjectOperation (&ClrOctagonFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2245 Draw ();
2246 IncrementUndoSerialNumber ();
2247 return (true);
2249 return (false);
2252 /* ---------------------------------------------------------------------------
2253 * queries the user for a new object name and changes it
2255 * The allocated memory isn't freed because the old string is used
2256 * by the undo module.
2258 void *
2259 QueryInputAndChangeObjectName (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2261 char *name = NULL;
2262 char msg[513];
2264 /* if passed an element name, make it an element reference instead */
2265 if (Type == ELEMENTNAME_TYPE)
2267 Type = ELEMENT_TYPE;
2268 Ptr2 = Ptr1;
2269 Ptr3 = Ptr1;
2271 switch (Type)
2273 case LINE_TYPE:
2274 name = gui->prompt_for (_("Linename:"),
2275 EMPTY (((LineType *) Ptr2)->Number));
2276 break;
2278 case VIA_TYPE:
2279 name = gui->prompt_for (_("Vianame:"),
2280 EMPTY (((PinType *) Ptr2)->Name));
2281 break;
2283 case PIN_TYPE:
2284 sprintf (msg, _("%s Pin Name:"), EMPTY (((PinType *) Ptr2)->Number));
2285 name = gui->prompt_for (msg, EMPTY (((PinType *) Ptr2)->Name));
2286 break;
2288 case PAD_TYPE:
2289 sprintf (msg, _("%s Pad Name:"), EMPTY (((PadType *) Ptr2)->Number));
2290 name = gui->prompt_for (msg, EMPTY (((PadType *) Ptr2)->Name));
2291 break;
2293 case TEXT_TYPE:
2294 name = gui->prompt_for (_("Enter text:"),
2295 EMPTY (((TextType *) Ptr2)->TextString));
2296 break;
2298 case ELEMENT_TYPE:
2299 name = gui->prompt_for (_("Elementname:"),
2300 EMPTY (ELEMENT_NAME
2301 (PCB, (ElementType *) Ptr2)));
2302 break;
2304 if (name)
2306 /* NB: ChangeObjectName takes ownership of the passed memory */
2307 char *old = (char *)ChangeObjectName (Type, Ptr1, Ptr2, Ptr3, name);
2308 if (old != (char *) -1)
2310 AddObjectToChangeNameUndoList (Type, Ptr1, Ptr2, Ptr3, old);
2311 IncrementUndoSerialNumber ();
2313 Draw ();
2314 return (Ptr3);
2316 return (NULL);
2319 /* ---------------------------------------------------------------------------
2320 * changes the maximum size of a layout
2321 * adjusts the scrollbars
2322 * releases the saved pixmap if necessary
2323 * and adjusts the cursor confinement box
2325 void
2326 ChangePCBSize (Coord Width, Coord Height)
2328 PCB->MaxWidth = Width;
2329 PCB->MaxHeight = Height;
2331 /* crosshair range is different if pastebuffer-mode
2332 * is enabled
2334 if (Settings.Mode == PASTEBUFFER_MODE)
2335 SetCrosshairRange (PASTEBUFFER->X - PASTEBUFFER->BoundingBox.X1,
2336 PASTEBUFFER->Y - PASTEBUFFER->BoundingBox.Y1,
2337 MAX (0,
2338 Width - (PASTEBUFFER->BoundingBox.X2 -
2339 PASTEBUFFER->X)), MAX (0,
2340 Height -
2341 (PASTEBUFFER->
2342 BoundingBox.Y2 -
2343 PASTEBUFFER->
2344 Y)));
2345 else
2346 SetCrosshairRange (0, 0, Width, Height);
2347 hid_action ("PCBChanged");
2350 /* ---------------------------------------------------------------------------
2351 * changes the mask size of a pad
2352 * returns TRUE if changed
2354 static void *
2355 ChangePadMaskSize (ElementType *Element, PadType *Pad)
2357 Coord value = (Absolute) ? Absolute : Pad->Mask + Delta;
2359 value = MAX (value, 0);
2360 if (value == Pad->Mask && Absolute == 0)
2361 value = Pad->Thickness;
2362 if (value != Pad->Mask)
2364 AddObjectToMaskSizeUndoList (PAD_TYPE, Element, Pad, Pad);
2365 ErasePad (Pad);
2366 r_delete_entry (PCB->Data->pad_tree, &Pad->BoundingBox);
2367 Pad->Mask = value;
2368 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
2369 DrawPad (Pad);
2370 return (Pad);
2372 return (NULL);
2375 /* ---------------------------------------------------------------------------
2376 * changes the mask size of a pin
2377 * returns TRUE if changed
2379 static void *
2380 ChangePinMaskSize (ElementType *Element, PinType *Pin)
2382 Coord value = (Absolute) ? Absolute : Pin->Mask + Delta;
2384 value = MAX (value, 0);
2385 if (value == Pin->Mask && Absolute == 0)
2386 value = Pin->Thickness;
2387 if (value != Pin->Mask)
2389 AddObjectToMaskSizeUndoList (PIN_TYPE, Element, Pin, Pin);
2390 ErasePin (Pin);
2391 r_delete_entry (PCB->Data->pin_tree, &Pin->BoundingBox);
2392 Pin->Mask = value;
2393 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
2394 DrawPin (Pin);
2395 return (Pin);
2397 return (NULL);
2400 /* ---------------------------------------------------------------------------
2401 * changes the mask size of a via
2402 * returns TRUE if changed
2404 static void *
2405 ChangeViaMaskSize (PinType *Via)
2407 Coord value;
2409 value = (Absolute) ? Absolute : Via->Mask + Delta;
2410 value = MAX (value, 0);
2411 if (value != Via->Mask)
2413 AddObjectToMaskSizeUndoList (VIA_TYPE, Via, Via, Via);
2414 EraseVia (Via);
2415 r_delete_entry (PCB->Data->via_tree, &Via->BoundingBox);
2416 Via->Mask = value;
2417 SetPinBoundingBox (Via);
2418 r_insert_entry (PCB->Data->via_tree, &Via->BoundingBox, 0);
2419 DrawVia (Via);
2420 return (Via);
2422 return (NULL);