Fix typo converting request_debug_draw to return a HID_DRAW structure
[geda-pcb/pcjc2.git] / src / change.c
blob88d4b9f46ceb9910b3140afc1f785780b39847d7
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>
38 #include "global.h"
40 #include "change.h"
41 #include "create.h"
42 #include "crosshair.h"
43 #include "data.h"
44 #include "draw.h"
45 #include "error.h"
46 #include "mymem.h"
47 #include "misc.h"
48 #include "mirror.h"
49 #include "polygon.h"
50 #include "rats.h"
51 #include "remove.h"
52 #include "rtree.h"
53 #include "search.h"
54 #include "select.h"
55 #include "set.h"
56 #include "thermal.h"
57 #include "undo.h"
59 #ifdef HAVE_LIBDMALLOC
60 #include <dmalloc.h>
61 #endif
63 /* ---------------------------------------------------------------------------
64 * some local prototypes
66 static void *ChangePinSize (ElementType *, PinType *);
67 static void *ChangePinClearSize (ElementType *, PinType *);
68 static void *ChangePinMaskSize (ElementType *, PinType *);
69 static void *ChangePadSize (ElementType *, PadType *);
70 static void *ChangePadClearSize (ElementType *, PadType *);
71 static void *ChangePadMaskSize (ElementType *, PadType *);
72 static void *ChangePin2ndSize (ElementType *, PinType *);
73 static void *ChangeElement2ndSize (ElementType *);
74 static void *ChangeViaSize (PinType *);
75 static void *ChangeVia2ndSize (PinType *);
76 static void *ChangeViaClearSize (PinType *);
77 static void *ChangeViaMaskSize (PinType *);
78 static void *ChangeLineSize (LayerType *, LineType *);
79 static void *ChangeLineClearSize (LayerType *, LineType *);
80 static void *ChangePolygonClearSize (LayerType *, PolygonType *);
81 static void *ChangeArcSize (LayerType *, ArcType *);
82 static void *ChangeArcClearSize (LayerType *, ArcType *);
83 static void *ChangeTextSize (LayerType *, TextType *);
84 static void *ChangeElementSize (ElementType *);
85 static void *ChangeElementNameSize (ElementType *);
86 static void *ChangePinName (ElementType *, PinType *);
87 static void *ChangePadName (ElementType *, PadType *);
88 static void *ChangeViaName (PinType *);
89 static void *ChangeLineName (LayerType *, LineType *);
90 static void *ChangeElementName (ElementType *);
91 static void *ChangeTextName (LayerType *, TextType *);
92 static void *ChangeElementSquare (ElementType *);
93 static void *SetElementSquare (ElementType *);
94 static void *ClrElementSquare (ElementType *);
95 static void *ChangeElementOctagon (ElementType *);
96 static void *SetElementOctagon (ElementType *);
97 static void *ClrElementOctagon (ElementType *);
98 static void *ChangePinSquare (ElementType *, PinType *);
99 static void *SetPinSquare (ElementType *, PinType *);
100 static void *ClrPinSquare (ElementType *, PinType *);
101 static void *ChangePinOctagon (ElementType *, PinType *);
102 static void *SetPinOctagon (ElementType *, PinType *);
103 static void *ClrPinOctagon (ElementType *, PinType *);
104 static void *ChangeViaOctagon (PinType *);
105 static void *SetViaOctagon (PinType *);
106 static void *ClrViaOctagon (PinType *);
107 static void *ChangePadSquare (ElementType *, PadType *);
108 static void *SetPadSquare (ElementType *, PadType *);
109 static void *ClrPadSquare (ElementType *, PadType *);
110 static void *ChangeViaThermal (PinType *);
111 static void *ChangePinThermal (ElementType *, PinType *);
112 static void *ChangeLineJoin (LayerType *, LineType *);
113 static void *SetLineJoin (LayerType *, LineType *);
114 static void *ClrLineJoin (LayerType *, LineType *);
115 static void *ChangeArcJoin (LayerType *, ArcType *);
116 static void *SetArcJoin (LayerType *, ArcType *);
117 static void *ClrArcJoin (LayerType *, ArcType *);
118 static void *ChangeTextJoin (LayerType *, TextType *);
119 static void *SetTextJoin (LayerType *, TextType *);
120 static void *ClrTextJoin (LayerType *, TextType *);
121 static void *ChangePolyClear (LayerType *, PolygonType *);
123 /* ---------------------------------------------------------------------------
124 * some local identifiers
126 static int Delta; /* change of size */
127 static int Absolute; /* Absolute size */
128 static char *NewName; /* new name */
129 static ObjectFunctionType ChangeSizeFunctions = {
130 ChangeLineSize,
131 ChangeTextSize,
132 ChangePolyClear,
133 ChangeViaSize,
134 ChangeElementSize, /* changes silk screen line width */
135 ChangeElementNameSize,
136 ChangePinSize,
137 ChangePadSize,
138 NULL,
139 NULL,
140 ChangeArcSize,
141 NULL
143 static ObjectFunctionType Change2ndSizeFunctions = {
144 NULL,
145 NULL,
146 NULL,
147 ChangeVia2ndSize,
148 ChangeElement2ndSize,
149 NULL,
150 ChangePin2ndSize,
151 NULL,
152 NULL,
153 NULL,
154 NULL,
155 NULL
157 static ObjectFunctionType ChangeThermalFunctions = {
158 NULL,
159 NULL,
160 NULL,
161 ChangeViaThermal,
162 NULL,
163 NULL,
164 ChangePinThermal,
165 NULL,
166 NULL,
167 NULL,
168 NULL,
169 NULL
171 static ObjectFunctionType ChangeClearSizeFunctions = {
172 ChangeLineClearSize,
173 NULL,
174 ChangePolygonClearSize, /* just to tell the user not to :-) */
175 ChangeViaClearSize,
176 NULL,
177 NULL,
178 ChangePinClearSize,
179 ChangePadClearSize,
180 NULL,
181 NULL,
182 ChangeArcClearSize,
183 NULL
185 static ObjectFunctionType ChangeNameFunctions = {
186 ChangeLineName,
187 ChangeTextName,
188 NULL,
189 ChangeViaName,
190 ChangeElementName,
191 NULL,
192 ChangePinName,
193 ChangePadName,
194 NULL,
195 NULL,
196 NULL,
197 NULL
199 static ObjectFunctionType ChangeSquareFunctions = {
200 NULL,
201 NULL,
202 NULL,
203 NULL,
204 ChangeElementSquare,
205 NULL,
206 ChangePinSquare,
207 ChangePadSquare,
208 NULL,
209 NULL,
210 NULL,
211 NULL
213 static ObjectFunctionType ChangeJoinFunctions = {
214 ChangeLineJoin,
215 ChangeTextJoin,
216 NULL,
217 NULL,
218 NULL,
219 NULL,
220 NULL,
221 NULL,
222 NULL,
223 NULL,
224 ChangeArcJoin,
225 NULL
227 static ObjectFunctionType ChangeOctagonFunctions = {
228 NULL,
229 NULL,
230 NULL,
231 ChangeViaOctagon,
232 ChangeElementOctagon,
233 NULL,
234 ChangePinOctagon,
235 NULL,
236 NULL,
237 NULL,
238 NULL,
239 NULL
241 static ObjectFunctionType ChangeMaskSizeFunctions = {
242 NULL,
243 NULL,
244 NULL,
245 ChangeViaMaskSize,
246 #if 0
247 ChangeElementMaskSize,
248 #else
249 NULL,
250 #endif
251 NULL,
252 ChangePinMaskSize,
253 ChangePadMaskSize,
254 NULL,
255 NULL,
256 NULL,
257 NULL
259 static ObjectFunctionType SetSquareFunctions = {
260 NULL,
261 NULL,
262 NULL,
263 NULL,
264 SetElementSquare,
265 NULL,
266 SetPinSquare,
267 SetPadSquare,
268 NULL,
269 NULL,
270 NULL,
271 NULL
273 static ObjectFunctionType SetJoinFunctions = {
274 SetLineJoin,
275 SetTextJoin,
276 NULL,
277 NULL,
278 NULL,
279 NULL,
280 NULL,
281 NULL,
282 NULL,
283 NULL,
284 SetArcJoin,
285 NULL
287 static ObjectFunctionType SetOctagonFunctions = {
288 NULL,
289 NULL,
290 NULL,
291 SetViaOctagon,
292 SetElementOctagon,
293 NULL,
294 SetPinOctagon,
295 NULL,
296 NULL,
297 NULL,
298 NULL,
299 NULL
301 static ObjectFunctionType ClrSquareFunctions = {
302 NULL,
303 NULL,
304 NULL,
305 NULL,
306 ClrElementSquare,
307 NULL,
308 ClrPinSquare,
309 ClrPadSquare,
310 NULL,
311 NULL,
312 NULL,
313 NULL
315 static ObjectFunctionType ClrJoinFunctions = {
316 ClrLineJoin,
317 ClrTextJoin,
318 NULL,
319 NULL,
320 NULL,
321 NULL,
322 NULL,
323 NULL,
324 NULL,
325 NULL,
326 ClrArcJoin,
327 NULL
329 static ObjectFunctionType ClrOctagonFunctions = {
330 NULL,
331 NULL,
332 NULL,
333 ClrViaOctagon,
334 ClrElementOctagon,
335 NULL,
336 ClrPinOctagon,
337 NULL,
338 NULL,
339 NULL,
340 NULL,
341 NULL
344 /* ---------------------------------------------------------------------------
345 * changes the thermal on a via
346 * returns TRUE if changed
348 static void *
349 ChangeViaThermal (PinType *Via)
351 AddObjectToClearPolyUndoList (VIA_TYPE, Via, Via, Via, false);
352 RestoreToPolygon (PCB->Data, VIA_TYPE, CURRENT, Via);
353 AddObjectToFlagUndoList (VIA_TYPE, Via, Via, Via);
354 if (!Delta) /* remove the thermals */
355 CLEAR_THERM (INDEXOFCURRENT, Via);
356 else
357 ASSIGN_THERM (INDEXOFCURRENT, Delta, Via);
358 AddObjectToClearPolyUndoList (VIA_TYPE, Via, Via, Via, true);
359 ClearFromPolygon (PCB->Data, VIA_TYPE, CURRENT, Via);
360 DrawVia (Via);
361 return Via;
364 /* ---------------------------------------------------------------------------
365 * changes the thermal on a pin
366 * returns TRUE if changed
368 static void *
369 ChangePinThermal (ElementType *element, PinType *Pin)
371 AddObjectToClearPolyUndoList (PIN_TYPE, element, Pin, Pin, false);
372 RestoreToPolygon (PCB->Data, VIA_TYPE, CURRENT, Pin);
373 AddObjectToFlagUndoList (PIN_TYPE, element, Pin, Pin);
374 if (!Delta) /* remove the thermals */
375 CLEAR_THERM (INDEXOFCURRENT, Pin);
376 else
377 ASSIGN_THERM (INDEXOFCURRENT, Delta, Pin);
378 AddObjectToClearPolyUndoList (PIN_TYPE, element, Pin, Pin, true);
379 ClearFromPolygon (PCB->Data, VIA_TYPE, CURRENT, Pin);
380 DrawPin (Pin);
381 return Pin;
384 /* ---------------------------------------------------------------------------
385 * changes the size of a via
386 * returns TRUE if changed
388 static void *
389 ChangeViaSize (PinType *Via)
391 Coord value = Absolute ? Absolute : Via->Thickness + Delta;
393 if (TEST_FLAG (LOCKFLAG, Via))
394 return (NULL);
395 if (!TEST_FLAG (HOLEFLAG, Via) && value <= MAX_PINORVIASIZE &&
396 value >= MIN_PINORVIASIZE &&
397 value >= Via->DrillingHole + MIN_PINORVIACOPPER &&
398 value != Via->Thickness)
400 AddObjectToSizeUndoList (VIA_TYPE, Via, Via, Via);
401 EraseVia (Via);
402 r_delete_entry (PCB->Data->via_tree, (BoxType *) Via);
403 RestoreToPolygon (PCB->Data, PIN_TYPE, Via, Via);
404 if (Via->Mask)
406 AddObjectToMaskSizeUndoList (VIA_TYPE, Via, Via, Via);
407 Via->Mask += value - Via->Thickness;
409 Via->Thickness = value;
410 SetPinBoundingBox (Via);
411 r_insert_entry (PCB->Data->via_tree, (BoxType *) Via, 0);
412 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
413 DrawVia (Via);
414 return (Via);
416 return (NULL);
419 /* ---------------------------------------------------------------------------
420 * changes the drilling hole of a via
421 * returns TRUE if changed
423 static void *
424 ChangeVia2ndSize (PinType *Via)
426 Coord value = (Absolute) ? Absolute : Via->DrillingHole + Delta;
428 if (TEST_FLAG (LOCKFLAG, Via))
429 return (NULL);
430 if (value <= MAX_PINORVIASIZE &&
431 value >= MIN_PINORVIAHOLE && (TEST_FLAG (HOLEFLAG, Via) ||
432 value <=
433 Via->Thickness - MIN_PINORVIACOPPER)
434 && value != Via->DrillingHole)
436 AddObjectTo2ndSizeUndoList (VIA_TYPE, Via, Via, Via);
437 EraseVia (Via);
438 RestoreToPolygon (PCB->Data, VIA_TYPE, Via, Via);
439 Via->DrillingHole = value;
440 if (TEST_FLAG (HOLEFLAG, Via))
442 AddObjectToSizeUndoList (VIA_TYPE, Via, Via, Via);
443 Via->Thickness = value;
445 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
446 DrawVia (Via);
447 return (Via);
449 return (NULL);
452 /* ---------------------------------------------------------------------------
453 * changes the clearance size of a via
454 * returns TRUE if changed
456 static void *
457 ChangeViaClearSize (PinType *Via)
459 Coord value = (Absolute) ? Absolute : Via->Clearance + Delta;
461 if (TEST_FLAG (LOCKFLAG, Via))
462 return (NULL);
463 value = MIN (MAX_LINESIZE, value);
464 if (value < 0)
465 value = 0;
466 if (Delta < 0 && value < PCB->Bloat * 2)
467 value = 0;
468 if ((Delta > 0 || Absolute) && value < PCB->Bloat * 2)
469 value = PCB->Bloat * 2 + 2;
470 if (Via->Clearance == value)
471 return NULL;
472 RestoreToPolygon (PCB->Data, VIA_TYPE, Via, Via);
473 AddObjectToClearSizeUndoList (VIA_TYPE, Via, Via, Via);
474 EraseVia (Via);
475 r_delete_entry (PCB->Data->via_tree, (BoxType *) Via);
476 Via->Clearance = value;
477 SetPinBoundingBox (Via);
478 r_insert_entry (PCB->Data->via_tree, (BoxType *) Via, 0);
479 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
480 DrawVia (Via);
481 Via->Element = NULL;
482 return (Via);
486 /* ---------------------------------------------------------------------------
487 * changes the size of a pin
488 * returns TRUE if changed
490 static void *
491 ChangePinSize (ElementType *Element, PinType *Pin)
493 Coord value = (Absolute) ? Absolute : Pin->Thickness + Delta;
495 if (TEST_FLAG (LOCKFLAG, Pin))
496 return (NULL);
497 if (!TEST_FLAG (HOLEFLAG, Pin) && value <= MAX_PINORVIASIZE &&
498 value >= MIN_PINORVIASIZE &&
499 value >= Pin->DrillingHole + MIN_PINORVIACOPPER &&
500 value != Pin->Thickness)
502 AddObjectToSizeUndoList (PIN_TYPE, Element, Pin, Pin);
503 AddObjectToMaskSizeUndoList (PIN_TYPE, Element, Pin, Pin);
504 ErasePin (Pin);
505 r_delete_entry (PCB->Data->pin_tree, &Pin->BoundingBox);
506 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
507 Pin->Mask += value - Pin->Thickness;
508 Pin->Thickness = value;
509 /* SetElementBB updates all associated rtrees */
510 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
511 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
512 DrawPin (Pin);
513 return (Pin);
515 return (NULL);
518 /* ---------------------------------------------------------------------------
519 * changes the clearance size of a pin
520 * returns TRUE if changed
522 static void *
523 ChangePinClearSize (ElementType *Element, PinType *Pin)
525 Coord value = (Absolute) ? Absolute : Pin->Clearance + Delta;
527 if (TEST_FLAG (LOCKFLAG, Pin))
528 return (NULL);
529 value = MIN (MAX_LINESIZE, value);
530 if (value < 0)
531 value = 0;
532 if (Delta < 0 && value < PCB->Bloat * 2)
533 value = 0;
534 if ((Delta > 0 || Absolute) && value < PCB->Bloat * 2)
535 value = PCB->Bloat * 2 + 2;
536 if (Pin->Clearance == value)
537 return NULL;
538 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
539 AddObjectToClearSizeUndoList (PIN_TYPE, Element, Pin, Pin);
540 ErasePin (Pin);
541 r_delete_entry (PCB->Data->pin_tree, &Pin->BoundingBox);
542 Pin->Clearance = value;
543 /* SetElementBB updates all associated rtrees */
544 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
545 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
546 DrawPin (Pin);
547 return (Pin);
550 /* ---------------------------------------------------------------------------
551 * changes the size of a pad
552 * returns TRUE if changed
554 static void *
555 ChangePadSize (ElementType *Element, PadType *Pad)
557 Coord value = (Absolute) ? Absolute : Pad->Thickness + Delta;
559 if (TEST_FLAG (LOCKFLAG, Pad))
560 return (NULL);
561 if (value <= MAX_PADSIZE && value >= MIN_PADSIZE && value != Pad->Thickness)
563 AddObjectToSizeUndoList (PAD_TYPE, Element, Pad, Pad);
564 AddObjectToMaskSizeUndoList (PAD_TYPE, Element, Pad, Pad);
565 RestoreToPolygon (PCB->Data, PAD_TYPE, Element, Pad);
566 ErasePad (Pad);
567 r_delete_entry (PCB->Data->pad_tree, &Pad->BoundingBox);
568 Pad->Mask += value - Pad->Thickness;
569 Pad->Thickness = value;
570 /* SetElementBB updates all associated rtrees */
571 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
572 ClearFromPolygon (PCB->Data, PAD_TYPE, Element, Pad);
573 DrawPad (Pad);
574 return (Pad);
576 return (NULL);
579 /* ---------------------------------------------------------------------------
580 * changes the clearance size of a pad
581 * returns TRUE if changed
583 static void *
584 ChangePadClearSize (ElementType *Element, PadType *Pad)
586 Coord value = (Absolute) ? Absolute : Pad->Clearance + Delta;
588 if (TEST_FLAG (LOCKFLAG, Pad))
589 return (NULL);
590 value = MIN (MAX_LINESIZE, value);
591 if (value < 0)
592 value = 0;
593 if (Delta < 0 && value < PCB->Bloat * 2)
594 value = 0;
595 if ((Delta > 0 || Absolute) && value < PCB->Bloat * 2)
596 value = PCB->Bloat * 2 + 2;
597 if (value == Pad->Clearance)
598 return NULL;
599 AddObjectToClearSizeUndoList (PAD_TYPE, Element, Pad, Pad);
600 RestoreToPolygon (PCB->Data, PAD_TYPE, Element, Pad);
601 ErasePad (Pad);
602 r_delete_entry (PCB->Data->pad_tree, &Pad->BoundingBox);
603 Pad->Clearance = value;
604 /* SetElementBB updates all associated rtrees */
605 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
606 ClearFromPolygon (PCB->Data, PAD_TYPE, Element, Pad);
607 DrawPad (Pad);
608 return Pad;
611 /* ---------------------------------------------------------------------------
612 * changes the drilling hole of all pins of an element
613 * returns TRUE if changed
615 static void *
616 ChangeElement2ndSize (ElementType *Element)
618 bool changed = false;
619 Coord value;
621 if (TEST_FLAG (LOCKFLAG, Element))
622 return (NULL);
623 PIN_LOOP (Element);
625 value = (Absolute) ? Absolute : pin->DrillingHole + Delta;
626 if (value <= MAX_PINORVIASIZE &&
627 value >= MIN_PINORVIAHOLE && (TEST_FLAG (HOLEFLAG, pin) ||
628 value <=
629 pin->Thickness -
630 MIN_PINORVIACOPPER)
631 && value != pin->DrillingHole)
633 changed = true;
634 AddObjectTo2ndSizeUndoList (PIN_TYPE, Element, pin, pin);
635 ErasePin (pin);
636 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, pin);
637 pin->DrillingHole = value;
638 if (TEST_FLAG (HOLEFLAG, pin))
640 AddObjectToSizeUndoList (PIN_TYPE, Element, pin, pin);
641 pin->Thickness = value;
643 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, pin);
644 DrawPin (pin);
647 END_LOOP;
648 if (changed)
649 return (Element);
650 else
651 return (NULL);
654 /* ---------------------------------------------------------------------------
655 * changes the drilling hole of a pin
656 * returns TRUE if changed
658 static void *
659 ChangePin2ndSize (ElementType *Element, PinType *Pin)
661 Coord value = (Absolute) ? Absolute : Pin->DrillingHole + Delta;
663 if (TEST_FLAG (LOCKFLAG, Pin))
664 return (NULL);
665 if (value <= MAX_PINORVIASIZE &&
666 value >= MIN_PINORVIAHOLE && (TEST_FLAG (HOLEFLAG, Pin) ||
667 value <=
668 Pin->Thickness - MIN_PINORVIACOPPER)
669 && value != Pin->DrillingHole)
671 AddObjectTo2ndSizeUndoList (PIN_TYPE, Element, Pin, Pin);
672 ErasePin (Pin);
673 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
674 Pin->DrillingHole = value;
675 if (TEST_FLAG (HOLEFLAG, Pin))
677 AddObjectToSizeUndoList (PIN_TYPE, Element, Pin, Pin);
678 Pin->Thickness = value;
680 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
681 DrawPin (Pin);
682 return (Pin);
684 return (NULL);
687 /* ---------------------------------------------------------------------------
688 * changes the size of a line
689 * returns TRUE if changed
691 static void *
692 ChangeLineSize (LayerType *Layer, LineType *Line)
694 Coord value = (Absolute) ? Absolute : Line->Thickness + Delta;
696 if (TEST_FLAG (LOCKFLAG, Line))
697 return (NULL);
698 if (value <= MAX_LINESIZE && value >= MIN_LINESIZE &&
699 value != Line->Thickness)
701 AddObjectToSizeUndoList (LINE_TYPE, Layer, Line, Line);
702 EraseLine (Line);
703 r_delete_entry (Layer->line_tree, (BoxType *) Line);
704 RestoreToPolygon (PCB->Data, LINE_TYPE, Layer, Line);
705 Line->Thickness = value;
706 SetLineBoundingBox (Line);
707 r_insert_entry (Layer->line_tree, (BoxType *) Line, 0);
708 ClearFromPolygon (PCB->Data, LINE_TYPE, Layer, Line);
709 DrawLine (Layer, Line);
710 return (Line);
712 return (NULL);
715 /* ---------------------------------------------------------------------------
716 * changes the clearance size of a line
717 * returns TRUE if changed
719 static void *
720 ChangeLineClearSize (LayerType *Layer, LineType *Line)
722 Coord value = (Absolute) ? Absolute : Line->Clearance + Delta;
724 if (TEST_FLAG (LOCKFLAG, Line) || !TEST_FLAG (CLEARLINEFLAG, Line))
725 return (NULL);
726 value = MIN (MAX_LINESIZE, MAX (value, PCB->Bloat * 2 + 2));
727 if (value != Line->Clearance)
729 AddObjectToClearSizeUndoList (LINE_TYPE, Layer, Line, Line);
730 RestoreToPolygon (PCB->Data, LINE_TYPE, Layer, Line);
731 EraseLine (Line);
732 r_delete_entry (Layer->line_tree, (BoxType *) Line);
733 Line->Clearance = value;
734 if (Line->Clearance == 0)
736 CLEAR_FLAG (CLEARLINEFLAG, Line);
737 Line->Clearance = MIL_TO_COORD(10);
739 SetLineBoundingBox (Line);
740 r_insert_entry (Layer->line_tree, (BoxType *) Line, 0);
741 ClearFromPolygon (PCB->Data, LINE_TYPE, Layer, Line);
742 DrawLine (Layer, Line);
743 return (Line);
745 return (NULL);
748 /* ---------------------------------------------------------------------------
749 * Handle attepts to change the clearance of a polygon.
751 static void *
752 ChangePolygonClearSize (LayerType *Layer, PolygonType *poly)
754 static int shown_this_message = 0;
755 if (!shown_this_message)
757 gui->confirm_dialog (_("To change the clearance of objects in a polygon, "
758 "change the objects, not the polygon.\n"
759 "Hint: To set a minimum clearance for a group of objects, "
760 "select them all then :MinClearGap(Selected,=10,mil)"),
761 "Ok", NULL);
762 shown_this_message = 1;
765 return (NULL);
768 /* ---------------------------------------------------------------------------
769 * changes the size of an arc
770 * returns TRUE if changed
772 static void *
773 ChangeArcSize (LayerType *Layer, ArcType *Arc)
775 Coord value = (Absolute) ? Absolute : Arc->Thickness + Delta;
777 if (TEST_FLAG (LOCKFLAG, Arc))
778 return (NULL);
779 if (value <= MAX_LINESIZE && value >= MIN_LINESIZE &&
780 value != Arc->Thickness)
782 AddObjectToSizeUndoList (ARC_TYPE, Layer, Arc, Arc);
783 EraseArc (Arc);
784 r_delete_entry (Layer->arc_tree, (BoxType *) Arc);
785 RestoreToPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
786 Arc->Thickness = value;
787 SetArcBoundingBox (Arc);
788 r_insert_entry (Layer->arc_tree, (BoxType *) Arc, 0);
789 ClearFromPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
790 DrawArc (Layer, Arc);
791 return (Arc);
793 return (NULL);
796 /* ---------------------------------------------------------------------------
797 * changes the clearance size of an arc
798 * returns TRUE if changed
800 static void *
801 ChangeArcClearSize (LayerType *Layer, ArcType *Arc)
803 Coord value = (Absolute) ? Absolute : Arc->Clearance + Delta;
805 if (TEST_FLAG (LOCKFLAG, Arc) || !TEST_FLAG (CLEARLINEFLAG, Arc))
806 return (NULL);
807 value = MIN (MAX_LINESIZE, MAX (value, PCB->Bloat * 2 + 2));
808 if (value != Arc->Clearance)
810 AddObjectToClearSizeUndoList (ARC_TYPE, Layer, Arc, Arc);
811 EraseArc (Arc);
812 r_delete_entry (Layer->arc_tree, (BoxType *) Arc);
813 RestoreToPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
814 Arc->Clearance = value;
815 if (Arc->Clearance == 0)
817 CLEAR_FLAG (CLEARLINEFLAG, Arc);
818 Arc->Clearance = MIL_TO_COORD(10);
820 SetArcBoundingBox (Arc);
821 r_insert_entry (Layer->arc_tree, (BoxType *) Arc, 0);
822 ClearFromPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
823 DrawArc (Layer, Arc);
824 return (Arc);
826 return (NULL);
829 /* ---------------------------------------------------------------------------
830 * changes the scaling factor of a text object
831 * returns TRUE if changed
833 static void *
834 ChangeTextSize (LayerType *Layer, TextType *Text)
836 int value = (Absolute != 0 ? 0 : Text->Scale) +
837 (double)(Absolute != 0 ? Absolute : Delta)
838 / (double)FONT_CAPHEIGHT * 100.;
840 if (TEST_FLAG (LOCKFLAG, Text))
841 return (NULL);
842 if (value <= MAX_TEXTSCALE && value >= MIN_TEXTSCALE &&
843 value != Text->Scale)
845 AddObjectToSizeUndoList (TEXT_TYPE, Layer, Text, Text);
846 EraseText (Layer, Text);
847 r_delete_entry (Layer->text_tree, (BoxType *) Text);
848 RestoreToPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
849 Text->Scale = value;
850 SetTextBoundingBox (&PCB->Font, Text);
851 r_insert_entry (Layer->text_tree, (BoxType *) Text, 0);
852 ClearFromPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
853 DrawText (Layer, Text);
854 return (Text);
856 return (NULL);
859 /* ---------------------------------------------------------------------------
860 * changes the scaling factor of an element's outline
861 * returns TRUE if changed
863 static void *
864 ChangeElementSize (ElementType *Element)
866 Coord value;
867 bool changed = false;
869 if (TEST_FLAG (LOCKFLAG, Element))
870 return (NULL);
871 if (PCB->ElementOn)
872 EraseElement (Element);
873 ELEMENTLINE_LOOP (Element);
875 value = (Absolute) ? Absolute : line->Thickness + Delta;
876 if (value <= MAX_LINESIZE && value >= MIN_LINESIZE &&
877 value != line->Thickness)
879 AddObjectToSizeUndoList (ELEMENTLINE_TYPE, Element, line, line);
880 line->Thickness = value;
881 changed = true;
884 END_LOOP;
885 ARC_LOOP (Element);
887 value = (Absolute) ? Absolute : arc->Thickness + Delta;
888 if (value <= MAX_LINESIZE && value >= MIN_LINESIZE &&
889 value != arc->Thickness)
891 AddObjectToSizeUndoList (ELEMENTARC_TYPE, Element, arc, arc);
892 arc->Thickness = value;
893 changed = true;
896 END_LOOP;
897 if (PCB->ElementOn)
899 DrawElement (Element);
901 if (changed)
902 return (Element);
903 return (NULL);
906 /* ---------------------------------------------------------------------------
907 * changes the scaling factor of a elementname object
908 * returns TRUE if changed
910 static void *
911 ChangeElementNameSize (ElementType *Element)
913 int value = (Absolute != 0 ? 0 : DESCRIPTION_TEXT (Element).Scale) +
914 (double)(Absolute != 0 ? Absolute : Delta)
915 / (double)FONT_CAPHEIGHT * 100.;
917 if (TEST_FLAG (LOCKFLAG, &Element->Name[0]))
918 return (NULL);
919 if (value <= MAX_TEXTSCALE && value >= MIN_TEXTSCALE)
921 EraseElementName (Element);
922 ELEMENTTEXT_LOOP (Element);
924 AddObjectToSizeUndoList (ELEMENTNAME_TYPE, Element, text, text);
925 r_delete_entry (PCB->Data->name_tree[n], (BoxType *) text);
926 text->Scale = value;
927 SetTextBoundingBox (&PCB->Font, text);
928 r_insert_entry (PCB->Data->name_tree[n], (BoxType *) text, 0);
930 END_LOOP;
931 DrawElementName (Element);
932 return (Element);
934 return (NULL);
937 /* ---------------------------------------------------------------------------
938 * changes the name of a via
940 static void *
941 ChangeViaName (PinType *Via)
943 char *old = Via->Name;
945 if (TEST_FLAG (DISPLAYNAMEFLAG, Via))
947 ErasePinName (Via);
948 Via->Name = NewName;
949 DrawPinName (Via);
951 else
952 Via->Name = NewName;
953 return (old);
956 /* ---------------------------------------------------------------------------
957 * changes the name of a pin
959 static void *
960 ChangePinName (ElementType *Element, PinType *Pin)
962 char *old = Pin->Name;
964 (void) Element; /* get rid of 'unused...' warnings */
965 if (TEST_FLAG (DISPLAYNAMEFLAG, Pin))
967 ErasePinName (Pin);
968 Pin->Name = NewName;
969 DrawPinName (Pin);
971 else
972 Pin->Name = NewName;
973 return (old);
976 /* ---------------------------------------------------------------------------
977 * changes the name of a pad
979 static void *
980 ChangePadName (ElementType *Element, PadType *Pad)
982 char *old = Pad->Name;
984 (void) Element; /* get rid of 'unused...' warnings */
985 if (TEST_FLAG (DISPLAYNAMEFLAG, Pad))
987 ErasePadName (Pad);
988 Pad->Name = NewName;
989 DrawPadName (Pad);
991 else
992 Pad->Name = NewName;
993 return (old);
996 /* ---------------------------------------------------------------------------
997 * changes the name of a line
999 static void *
1000 ChangeLineName (LayerType *Layer, LineType *Line)
1002 char *old = Line->Number;
1004 (void) Layer;
1005 Line->Number = NewName;
1006 return (old);
1009 /* ---------------------------------------------------------------------------
1010 * changes the layout-name of an element
1013 char *
1014 ChangeElementText (PCBType *pcb, DataType *data, ElementType *Element, int which, char *new_name)
1016 char *old = Element->Name[which].TextString;
1018 #ifdef DEBUG
1019 printf("In ChangeElementText, updating old TextString %s to %s\n", old, new_name);
1020 #endif
1022 if (pcb && which == NAME_INDEX (pcb))
1023 EraseElementName (Element);
1025 r_delete_entry (data->name_tree[which],
1026 & Element->Name[which].BoundingBox);
1028 Element->Name[which].TextString = new_name;
1029 SetTextBoundingBox (&PCB->Font, &Element->Name[which]);
1031 r_insert_entry (data->name_tree[which],
1032 & Element->Name[which].BoundingBox, 0);
1034 if (pcb && which == NAME_INDEX (pcb))
1035 DrawElementName (Element);
1037 return old;
1040 static void *
1041 ChangeElementName (ElementType *Element)
1043 if (TEST_FLAG (LOCKFLAG, &Element->Name[0]))
1044 return (NULL);
1045 if (NAME_INDEX (PCB) == NAMEONPCB_INDEX)
1047 if (TEST_FLAG (UNIQUENAMEFLAG, PCB) &&
1048 UniqueElementName (PCB->Data, NewName) != NewName)
1050 Message (_("Error: The name \"%s\" is not unique!\n"), NewName);
1051 return ((char *) -1);
1055 return ChangeElementText (PCB, PCB->Data, Element, NAME_INDEX (PCB), NewName);
1058 /* ---------------------------------------------------------------------------
1059 * sets data of a text object and calculates bounding box
1060 * memory must have already been allocated
1061 * the one for the new string is allocated
1062 * returns true if the string has been changed
1064 static void *
1065 ChangeTextName (LayerType *Layer, TextType *Text)
1067 char *old = Text->TextString;
1069 if (TEST_FLAG (LOCKFLAG, Text))
1070 return (NULL);
1071 EraseText (Layer, Text);
1072 RestoreToPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
1073 Text->TextString = NewName;
1075 /* calculate size of the bounding box */
1076 SetTextBoundingBox (&PCB->Font, Text);
1077 ClearFromPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
1078 DrawText (Layer, Text);
1079 return (old);
1082 /* ---------------------------------------------------------------------------
1083 * changes the name of a layout; memory has to be already allocated
1085 bool
1086 ChangeLayoutName (char *Name)
1088 free (PCB->Name);
1089 PCB->Name = Name;
1090 hid_action ("PCBChanged");
1091 return (true);
1094 /* ---------------------------------------------------------------------------
1095 * changes the side of the board an element is on
1096 * returns TRUE if done
1098 bool
1099 ChangeElementSide (ElementType *Element, Coord yoff)
1101 if (TEST_FLAG (LOCKFLAG, Element))
1102 return (false);
1103 EraseElement (Element);
1104 AddObjectToMirrorUndoList (ELEMENT_TYPE, Element, Element, Element, yoff);
1105 MirrorElementCoordinates (PCB->Data, Element, yoff);
1106 DrawElement (Element);
1107 return (true);
1110 /* ---------------------------------------------------------------------------
1111 * changes the name of a layer; memory has to be already allocated
1113 bool
1114 ChangeLayerName (LayerType *Layer, char *Name)
1116 free (CURRENT->Name);
1117 CURRENT->Name = Name;
1118 hid_action ("LayersChanged");
1119 return (true);
1122 /* ---------------------------------------------------------------------------
1123 * changes the clearance flag of a line
1125 static void *
1126 ChangeLineJoin (LayerType *Layer, LineType *Line)
1128 if (TEST_FLAG (LOCKFLAG, Line))
1129 return (NULL);
1130 EraseLine (Line);
1131 if (TEST_FLAG(CLEARLINEFLAG, Line))
1133 AddObjectToClearPolyUndoList (LINE_TYPE, Layer, Line, Line, false);
1134 RestoreToPolygon (PCB->Data, LINE_TYPE, Layer, Line);
1136 AddObjectToFlagUndoList (LINE_TYPE, Layer, Line, Line);
1137 TOGGLE_FLAG (CLEARLINEFLAG, Line);
1138 if (TEST_FLAG(CLEARLINEFLAG, Line))
1140 AddObjectToClearPolyUndoList (LINE_TYPE, Layer, Line, Line, true);
1141 ClearFromPolygon (PCB->Data, LINE_TYPE, Layer, Line);
1143 DrawLine (Layer, Line);
1144 return (Line);
1147 /* ---------------------------------------------------------------------------
1148 * sets the clearance flag of a line
1150 static void *
1151 SetLineJoin (LayerType *Layer, LineType *Line)
1153 if (TEST_FLAG (LOCKFLAG, Line) || TEST_FLAG (CLEARLINEFLAG, Line))
1154 return (NULL);
1155 return ChangeLineJoin (Layer, Line);
1158 /* ---------------------------------------------------------------------------
1159 * clears the clearance flag of a line
1161 static void *
1162 ClrLineJoin (LayerType *Layer, LineType *Line)
1164 if (TEST_FLAG (LOCKFLAG, Line) || !TEST_FLAG (CLEARLINEFLAG, Line))
1165 return (NULL);
1166 return ChangeLineJoin (Layer, Line);
1169 /* ---------------------------------------------------------------------------
1170 * changes the clearance flag of an arc
1172 static void *
1173 ChangeArcJoin (LayerType *Layer, ArcType *Arc)
1175 if (TEST_FLAG (LOCKFLAG, Arc))
1176 return (NULL);
1177 EraseArc (Arc);
1178 if (TEST_FLAG (CLEARLINEFLAG, Arc))
1180 RestoreToPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
1181 AddObjectToClearPolyUndoList (ARC_TYPE, Layer, Arc, Arc, false);
1183 AddObjectToFlagUndoList (ARC_TYPE, Layer, Arc, Arc);
1184 TOGGLE_FLAG (CLEARLINEFLAG, Arc);
1185 if (TEST_FLAG (CLEARLINEFLAG, Arc))
1187 ClearFromPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
1188 AddObjectToClearPolyUndoList (ARC_TYPE, Layer, Arc, Arc, true);
1190 DrawArc (Layer, Arc);
1191 return (Arc);
1194 /* ---------------------------------------------------------------------------
1195 * sets the clearance flag of an arc
1197 static void *
1198 SetArcJoin (LayerType *Layer, ArcType *Arc)
1200 if (TEST_FLAG (LOCKFLAG, Arc) || TEST_FLAG (CLEARLINEFLAG, Arc))
1201 return (NULL);
1202 return ChangeArcJoin (Layer, Arc);
1205 /* ---------------------------------------------------------------------------
1206 * clears the clearance flag of an arc
1208 static void *
1209 ClrArcJoin (LayerType *Layer, ArcType *Arc)
1211 if (TEST_FLAG (LOCKFLAG, Arc) || !TEST_FLAG (CLEARLINEFLAG, Arc))
1212 return (NULL);
1213 return ChangeArcJoin (Layer, Arc);
1216 /* ---------------------------------------------------------------------------
1217 * changes the clearance flag of a text
1219 static void *
1220 ChangeTextJoin (LayerType *Layer, TextType *Text)
1222 if (TEST_FLAG (LOCKFLAG, Text))
1223 return (NULL);
1224 EraseText (Layer, Text);
1225 if (TEST_FLAG(CLEARLINEFLAG, Text))
1227 AddObjectToClearPolyUndoList (TEXT_TYPE, Layer, Text, Text, false);
1228 RestoreToPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
1230 AddObjectToFlagUndoList (LINE_TYPE, Layer, Text, Text);
1231 TOGGLE_FLAG (CLEARLINEFLAG, Text);
1232 if (TEST_FLAG(CLEARLINEFLAG, Text))
1234 AddObjectToClearPolyUndoList (TEXT_TYPE, Layer, Text, Text, true);
1235 ClearFromPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
1237 DrawText (Layer, Text);
1238 return (Text);
1241 /* ---------------------------------------------------------------------------
1242 * sets the clearance flag of a text
1244 static void *
1245 SetTextJoin (LayerType *Layer, TextType *Text)
1247 if (TEST_FLAG (LOCKFLAG, Text) || TEST_FLAG (CLEARLINEFLAG, Text))
1248 return (NULL);
1249 return ChangeTextJoin (Layer, Text);
1252 /* ---------------------------------------------------------------------------
1253 * clears the clearance flag of a text
1255 static void *
1256 ClrTextJoin (LayerType *Layer, TextType *Text)
1258 if (TEST_FLAG (LOCKFLAG, Text) || !TEST_FLAG (CLEARLINEFLAG, Text))
1259 return (NULL);
1260 return ChangeTextJoin (Layer, Text);
1263 /* ---------------------------------------------------------------------------
1264 * changes the square flag of all pins on an element
1266 static void *
1267 ChangeElementSquare (ElementType *Element)
1269 void *ans = NULL;
1271 if (TEST_FLAG (LOCKFLAG, Element))
1272 return (NULL);
1273 PIN_LOOP (Element);
1275 ans = ChangePinSquare (Element, pin);
1277 END_LOOP;
1278 PAD_LOOP (Element);
1280 ans = ChangePadSquare (Element, pad);
1282 END_LOOP;
1283 return (ans);
1286 /* ---------------------------------------------------------------------------
1287 * sets the square flag of all pins on an element
1289 static void *
1290 SetElementSquare (ElementType *Element)
1292 void *ans = NULL;
1294 if (TEST_FLAG (LOCKFLAG, Element))
1295 return (NULL);
1296 PIN_LOOP (Element);
1298 ans = SetPinSquare (Element, pin);
1300 END_LOOP;
1301 PAD_LOOP (Element);
1303 ans = SetPadSquare (Element, pad);
1305 END_LOOP;
1306 return (ans);
1309 /* ---------------------------------------------------------------------------
1310 * clears the square flag of all pins on an element
1312 static void *
1313 ClrElementSquare (ElementType *Element)
1315 void *ans = NULL;
1317 if (TEST_FLAG (LOCKFLAG, Element))
1318 return (NULL);
1319 PIN_LOOP (Element);
1321 ans = ClrPinSquare (Element, pin);
1323 END_LOOP;
1324 PAD_LOOP (Element);
1326 ans = ClrPadSquare (Element, pad);
1328 END_LOOP;
1329 return (ans);
1332 /* ---------------------------------------------------------------------------
1333 * changes the octagon flags of all pins of an element
1335 static void *
1336 ChangeElementOctagon (ElementType *Element)
1338 void *result = NULL;
1340 if (TEST_FLAG (LOCKFLAG, Element))
1341 return (NULL);
1342 PIN_LOOP (Element);
1344 ChangePinOctagon (Element, pin);
1345 result = Element;
1347 END_LOOP;
1348 return (result);
1351 /* ---------------------------------------------------------------------------
1352 * sets the octagon flags of all pins of an element
1354 static void *
1355 SetElementOctagon (ElementType *Element)
1357 void *result = NULL;
1359 if (TEST_FLAG (LOCKFLAG, Element))
1360 return (NULL);
1361 PIN_LOOP (Element);
1363 SetPinOctagon (Element, pin);
1364 result = Element;
1366 END_LOOP;
1367 return (result);
1370 /* ---------------------------------------------------------------------------
1371 * clears the octagon flags of all pins of an element
1373 static void *
1374 ClrElementOctagon (ElementType *Element)
1376 void *result = NULL;
1378 if (TEST_FLAG (LOCKFLAG, Element))
1379 return (NULL);
1380 PIN_LOOP (Element);
1382 ClrPinOctagon (Element, pin);
1383 result = Element;
1385 END_LOOP;
1386 return (result);
1389 /* ---------------------------------------------------------------------------
1390 * changes the square flag of a pad
1392 static void *
1393 ChangePadSquare (ElementType *Element, PadType *Pad)
1395 if (TEST_FLAG (LOCKFLAG, Pad))
1396 return (NULL);
1397 ErasePad (Pad);
1398 AddObjectToClearPolyUndoList (PAD_TYPE, Element, Pad, Pad, false);
1399 RestoreToPolygon (PCB->Data, PAD_TYPE, Element, Pad);
1400 AddObjectToFlagUndoList (PAD_TYPE, Element, Pad, Pad);
1401 TOGGLE_FLAG (SQUAREFLAG, Pad);
1402 AddObjectToClearPolyUndoList (PAD_TYPE, Element, Pad, Pad, true);
1403 ClearFromPolygon (PCB->Data, PAD_TYPE, Element, Pad);
1404 DrawPad (Pad);
1405 return (Pad);
1408 /* ---------------------------------------------------------------------------
1409 * sets the square flag of a pad
1411 static void *
1412 SetPadSquare (ElementType *Element, PadType *Pad)
1415 if (TEST_FLAG (LOCKFLAG, Pad) || TEST_FLAG (SQUAREFLAG, Pad))
1416 return (NULL);
1418 return (ChangePadSquare (Element, Pad));
1422 /* ---------------------------------------------------------------------------
1423 * clears the square flag of a pad
1425 static void *
1426 ClrPadSquare (ElementType *Element, PadType *Pad)
1429 if (TEST_FLAG (LOCKFLAG, Pad) || !TEST_FLAG (SQUAREFLAG, Pad))
1430 return (NULL);
1432 return (ChangePadSquare (Element, Pad));
1436 /* ---------------------------------------------------------------------------
1437 * changes the square flag of a pin
1439 static void *
1440 ChangePinSquare (ElementType *Element, PinType *Pin)
1442 if (TEST_FLAG (LOCKFLAG, Pin))
1443 return (NULL);
1444 ErasePin (Pin);
1445 AddObjectToClearPolyUndoList (PIN_TYPE, Element, Pin, Pin, false);
1446 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
1447 AddObjectToFlagUndoList (PIN_TYPE, Element, Pin, Pin);
1448 TOGGLE_FLAG (SQUAREFLAG, Pin);
1449 AddObjectToClearPolyUndoList (PIN_TYPE, Element, Pin, Pin, true);
1450 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
1451 DrawPin (Pin);
1452 return (Pin);
1455 /* ---------------------------------------------------------------------------
1456 * sets the square flag of a pin
1458 static void *
1459 SetPinSquare (ElementType *Element, PinType *Pin)
1461 if (TEST_FLAG (LOCKFLAG, Pin) || TEST_FLAG (SQUAREFLAG, Pin))
1462 return (NULL);
1464 return (ChangePinSquare (Element, Pin));
1467 /* ---------------------------------------------------------------------------
1468 * clears the square flag of a pin
1470 static void *
1471 ClrPinSquare (ElementType *Element, PinType *Pin)
1473 if (TEST_FLAG (LOCKFLAG, Pin) || !TEST_FLAG (SQUAREFLAG, Pin))
1474 return (NULL);
1476 return (ChangePinSquare (Element, Pin));
1479 /* ---------------------------------------------------------------------------
1480 * changes the octagon flag of a via
1482 static void *
1483 ChangeViaOctagon (PinType *Via)
1485 if (TEST_FLAG (LOCKFLAG, Via))
1486 return (NULL);
1487 EraseVia (Via);
1488 AddObjectToClearPolyUndoList (VIA_TYPE, Via, Via, Via, false);
1489 RestoreToPolygon (PCB->Data, VIA_TYPE, Via, Via);
1490 AddObjectToFlagUndoList (VIA_TYPE, Via, Via, Via);
1491 TOGGLE_FLAG (OCTAGONFLAG, Via);
1492 AddObjectToClearPolyUndoList (VIA_TYPE, Via, Via, Via, true);
1493 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
1494 DrawVia (Via);
1495 return (Via);
1498 /* ---------------------------------------------------------------------------
1499 * sets the octagon flag of a via
1501 static void *
1502 SetViaOctagon (PinType *Via)
1504 if (TEST_FLAG (LOCKFLAG, Via) || TEST_FLAG (OCTAGONFLAG, Via))
1505 return (NULL);
1507 return (ChangeViaOctagon (Via));
1510 /* ---------------------------------------------------------------------------
1511 * clears the octagon flag of a via
1513 static void *
1514 ClrViaOctagon (PinType *Via)
1516 if (TEST_FLAG (LOCKFLAG, Via) || !TEST_FLAG (OCTAGONFLAG, Via))
1517 return (NULL);
1519 return (ChangeViaOctagon (Via));
1522 /* ---------------------------------------------------------------------------
1523 * changes the octagon flag of a pin
1525 static void *
1526 ChangePinOctagon (ElementType *Element, PinType *Pin)
1528 if (TEST_FLAG (LOCKFLAG, Pin))
1529 return (NULL);
1530 ErasePin (Pin);
1531 AddObjectToClearPolyUndoList (PIN_TYPE, Element, Pin, Pin, false);
1532 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
1533 AddObjectToFlagUndoList (PIN_TYPE, Element, Pin, Pin);
1534 TOGGLE_FLAG (OCTAGONFLAG, Pin);
1535 AddObjectToClearPolyUndoList (PIN_TYPE, Element, Pin, Pin, true);
1536 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
1537 DrawPin (Pin);
1538 return (Pin);
1541 /* ---------------------------------------------------------------------------
1542 * sets the octagon flag of a pin
1544 static void *
1545 SetPinOctagon (ElementType *Element, PinType *Pin)
1547 if (TEST_FLAG (LOCKFLAG, Pin) || TEST_FLAG (OCTAGONFLAG, Pin))
1548 return (NULL);
1550 return (ChangePinOctagon (Element, Pin));
1553 /* ---------------------------------------------------------------------------
1554 * clears the octagon flag of a pin
1556 static void *
1557 ClrPinOctagon (ElementType *Element, PinType *Pin)
1559 if (TEST_FLAG (LOCKFLAG, Pin) || !TEST_FLAG (OCTAGONFLAG, Pin))
1560 return (NULL);
1562 return (ChangePinOctagon (Element, Pin));
1565 /* ---------------------------------------------------------------------------
1566 * changes the hole flag of a via
1568 bool
1569 ChangeHole (PinType *Via)
1571 if (TEST_FLAG (LOCKFLAG, Via))
1572 return (false);
1573 EraseVia (Via);
1574 AddObjectToFlagUndoList (VIA_TYPE, Via, Via, Via);
1575 AddObjectToMaskSizeUndoList (VIA_TYPE, Via, Via, Via);
1576 r_delete_entry (PCB->Data->via_tree, (BoxType *) Via);
1577 RestoreToPolygon (PCB->Data, VIA_TYPE, Via, Via);
1578 TOGGLE_FLAG (HOLEFLAG, Via);
1580 if (TEST_FLAG (HOLEFLAG, Via))
1582 /* A tented via becomes an minimally untented hole. An untented
1583 via retains its mask clearance. */
1584 if (Via->Mask > Via->Thickness)
1586 Via->Mask = (Via->DrillingHole
1587 + (Via->Mask - Via->Thickness));
1589 else if (Via->Mask < Via->DrillingHole)
1591 Via->Mask = Via->DrillingHole + 2 * MASKFRAME;
1594 else
1596 Via->Mask = (Via->Thickness
1597 + (Via->Mask - Via->DrillingHole));
1600 SetPinBoundingBox (Via);
1601 r_insert_entry (PCB->Data->via_tree, (BoxType *) Via, 0);
1602 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
1603 DrawVia (Via);
1604 Draw ();
1605 return (true);
1608 /* ---------------------------------------------------------------------------
1609 * changes the nopaste flag of a pad
1611 bool
1612 ChangePaste (PadType *Pad)
1614 if (TEST_FLAG (LOCKFLAG, Pad))
1615 return (false);
1616 ErasePad (Pad);
1617 AddObjectToFlagUndoList (PAD_TYPE, Pad, Pad, Pad);
1618 TOGGLE_FLAG (NOPASTEFLAG, Pad);
1619 DrawPad (Pad);
1620 Draw ();
1621 return (true);
1624 /* ---------------------------------------------------------------------------
1625 * changes the CLEARPOLY flag of a polygon
1627 static void *
1628 ChangePolyClear (LayerType *Layer, PolygonType *Polygon)
1630 if (TEST_FLAG (LOCKFLAG, Polygon))
1631 return (NULL);
1632 AddObjectToClearPolyUndoList (POLYGON_TYPE, Layer, Polygon, Polygon, true);
1633 AddObjectToFlagUndoList (POLYGON_TYPE, Layer, Polygon, Polygon);
1634 TOGGLE_FLAG (CLEARPOLYFLAG, Polygon);
1635 InitClip (PCB->Data, Layer, Polygon);
1636 DrawPolygon (Layer, Polygon);
1637 return (Polygon);
1640 /* ----------------------------------------------------------------------
1641 * changes the side of all selected and visible elements
1642 * returns true if anything has changed
1644 bool
1645 ChangeSelectedElementSide (void)
1647 bool change = false;
1649 /* setup identifiers */
1650 if (PCB->PinOn && PCB->ElementOn)
1651 ELEMENT_LOOP (PCB->Data);
1653 if (TEST_FLAG (SELECTEDFLAG, element))
1655 change |= ChangeElementSide (element, 0);
1658 END_LOOP;
1659 if (change)
1661 Draw ();
1662 IncrementUndoSerialNumber ();
1664 return (change);
1667 /* ----------------------------------------------------------------------
1668 * changes the thermals on all selected and visible pins
1669 * and/or vias. Returns true if anything has changed
1671 bool
1672 ChangeSelectedThermals (int types, int therm_style)
1674 bool change = false;
1676 Delta = therm_style;
1677 change = SelectedOperation (&ChangeThermalFunctions, false, types);
1678 if (change)
1680 Draw ();
1681 IncrementUndoSerialNumber ();
1683 return (change);
1686 /* ----------------------------------------------------------------------
1687 * changes the size of all selected and visible object types
1688 * returns true if anything has changed
1690 bool
1691 ChangeSelectedSize (int types, Coord Difference, bool fixIt)
1693 bool change = false;
1695 /* setup identifiers */
1696 Absolute = (fixIt) ? Difference : 0;
1697 Delta = Difference;
1699 change = SelectedOperation (&ChangeSizeFunctions, false, types);
1700 if (change)
1702 Draw ();
1703 IncrementUndoSerialNumber ();
1705 return (change);
1708 /* ----------------------------------------------------------------------
1709 * changes the clearance size of all selected and visible objects
1710 * returns true if anything has changed
1712 bool
1713 ChangeSelectedClearSize (int types, Coord Difference, bool fixIt)
1715 bool change = false;
1717 /* setup identifiers */
1718 Absolute = (fixIt) ? Difference : 0;
1719 Delta = Difference;
1720 if (TEST_FLAG (SHOWMASKFLAG, PCB))
1721 change = SelectedOperation (&ChangeMaskSizeFunctions, false, types);
1722 else
1723 change = SelectedOperation (&ChangeClearSizeFunctions, false, types);
1724 if (change)
1726 Draw ();
1727 IncrementUndoSerialNumber ();
1729 return (change);
1732 /* --------------------------------------------------------------------------
1733 * changes the 2nd size (drilling hole) of all selected and visible objects
1734 * returns true if anything has changed
1736 bool
1737 ChangeSelected2ndSize (int types, Coord Difference, bool fixIt)
1739 bool change = false;
1741 /* setup identifiers */
1742 Absolute = (fixIt) ? Difference : 0;
1743 Delta = Difference;
1744 change = SelectedOperation (&Change2ndSizeFunctions, false, types);
1745 if (change)
1747 Draw ();
1748 IncrementUndoSerialNumber ();
1750 return (change);
1753 /* ----------------------------------------------------------------------
1754 * changes the clearance flag (join) of all selected and visible lines
1755 * and/or arcs. Returns true if anything has changed
1757 bool
1758 ChangeSelectedJoin (int types)
1760 bool change = false;
1762 change = SelectedOperation (&ChangeJoinFunctions, false, types);
1763 if (change)
1765 Draw ();
1766 IncrementUndoSerialNumber ();
1768 return (change);
1771 /* ----------------------------------------------------------------------
1772 * changes the clearance flag (join) of all selected and visible lines
1773 * and/or arcs. Returns true if anything has changed
1775 bool
1776 SetSelectedJoin (int types)
1778 bool change = false;
1780 change = SelectedOperation (&SetJoinFunctions, false, types);
1781 if (change)
1783 Draw ();
1784 IncrementUndoSerialNumber ();
1786 return (change);
1789 /* ----------------------------------------------------------------------
1790 * changes the clearance flag (join) of all selected and visible lines
1791 * and/or arcs. Returns true if anything has changed
1793 bool
1794 ClrSelectedJoin (int types)
1796 bool change = false;
1798 change = SelectedOperation (&ClrJoinFunctions, false, types);
1799 if (change)
1801 Draw ();
1802 IncrementUndoSerialNumber ();
1804 return (change);
1807 /* ----------------------------------------------------------------------
1808 * changes the square-flag of all selected and visible pins or pads
1809 * returns true if anything has changed
1811 bool
1812 ChangeSelectedSquare (int types)
1814 bool change = false;
1816 change = SelectedOperation (&ChangeSquareFunctions, false, types);
1817 if (change)
1819 Draw ();
1820 IncrementUndoSerialNumber ();
1822 return (change);
1825 /* ----------------------------------------------------------------------
1826 * sets the square-flag of all selected and visible pins or pads
1827 * returns true if anything has changed
1829 bool
1830 SetSelectedSquare (int types)
1832 bool change = false;
1834 change = SelectedOperation (&SetSquareFunctions, false, types);
1835 if (change)
1837 Draw ();
1838 IncrementUndoSerialNumber ();
1840 return (change);
1843 /* ----------------------------------------------------------------------
1844 * clears the square-flag of all selected and visible pins or pads
1845 * returns true if anything has changed
1847 bool
1848 ClrSelectedSquare (int types)
1850 bool change = false;
1852 change = SelectedOperation (&ClrSquareFunctions, false, types);
1853 if (change)
1855 Draw ();
1856 IncrementUndoSerialNumber ();
1858 return (change);
1861 /* ----------------------------------------------------------------------
1862 * changes the octagon-flag of all selected and visible pins and vias
1863 * returns true if anything has changed
1865 bool
1866 ChangeSelectedOctagon (int types)
1868 bool change = false;
1870 change = SelectedOperation (&ChangeOctagonFunctions, false, types);
1871 if (change)
1873 Draw ();
1874 IncrementUndoSerialNumber ();
1876 return (change);
1879 /* ----------------------------------------------------------------------
1880 * sets the octagon-flag of all selected and visible pins and vias
1881 * returns true if anything has changed
1883 bool
1884 SetSelectedOctagon (int types)
1886 bool change = false;
1888 change = SelectedOperation (&SetOctagonFunctions, false, types);
1889 if (change)
1891 Draw ();
1892 IncrementUndoSerialNumber ();
1894 return (change);
1897 /* ----------------------------------------------------------------------
1898 * clears the octagon-flag of all selected and visible pins and vias
1899 * returns true if anything has changed
1901 bool
1902 ClrSelectedOctagon (int types)
1904 bool change = false;
1906 change = SelectedOperation (&ClrOctagonFunctions, false, types);
1907 if (change)
1909 Draw ();
1910 IncrementUndoSerialNumber ();
1912 return (change);
1915 /* ----------------------------------------------------------------------
1916 * changes the hole-flag of all selected and visible vias
1917 * returns true if anything has changed
1919 bool
1920 ChangeSelectedHole (void)
1922 bool change = false;
1924 if (PCB->ViaOn)
1925 VIA_LOOP (PCB->Data);
1927 if (TEST_FLAG (SELECTEDFLAG, via))
1928 change |= ChangeHole (via);
1930 END_LOOP;
1931 if (change)
1933 Draw ();
1934 IncrementUndoSerialNumber ();
1936 return (change);
1939 /* ----------------------------------------------------------------------
1940 * changes the no paste-flag of all selected and visible pads
1941 * returns true if anything has changed
1943 bool
1944 ChangeSelectedPaste (void)
1946 bool change = false;
1948 ALLPAD_LOOP (PCB->Data);
1950 if (TEST_FLAG (SELECTEDFLAG, pad))
1951 change |= ChangePaste (pad);
1953 ENDALL_LOOP;
1954 if (change)
1956 Draw ();
1957 IncrementUndoSerialNumber ();
1959 return (change);
1963 /* ---------------------------------------------------------------------------
1964 * changes the size of the passed object
1965 * Returns true if anything is changed
1967 bool
1968 ChangeObjectSize (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
1969 Coord Difference, bool fixIt)
1971 bool change;
1973 /* setup identifier */
1974 Absolute = (fixIt) ? Difference : 0;
1975 Delta = Difference;
1976 change =
1977 (ObjectOperation (&ChangeSizeFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL);
1978 if (change)
1980 Draw ();
1981 IncrementUndoSerialNumber ();
1983 return (change);
1986 /* ---------------------------------------------------------------------------
1987 * changes the clearance size of the passed object
1988 * Returns true if anything is changed
1990 bool
1991 ChangeObjectClearSize (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
1992 Coord Difference, bool fixIt)
1994 bool change;
1996 /* setup identifier */
1997 Absolute = (fixIt) ? Difference : 0;
1998 Delta = Difference;
1999 if (TEST_FLAG (SHOWMASKFLAG, PCB))
2000 change =
2001 (ObjectOperation (&ChangeMaskSizeFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2002 NULL);
2003 else
2004 change =
2005 (ObjectOperation (&ChangeClearSizeFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2006 NULL);
2007 if (change)
2009 Draw ();
2010 IncrementUndoSerialNumber ();
2012 return (change);
2015 /* ---------------------------------------------------------------------------
2016 * changes the thermal of the passed object
2017 * Returns true if anything is changed
2020 bool
2021 ChangeObjectThermal (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
2022 int therm_type)
2024 bool change;
2026 Delta = Absolute = therm_type;
2027 change =
2028 (ObjectOperation (&ChangeThermalFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2029 NULL);
2030 if (change)
2032 Draw ();
2033 IncrementUndoSerialNumber ();
2035 return (change);
2038 /* ---------------------------------------------------------------------------
2039 * changes the 2nd size of the passed object
2040 * Returns true if anything is changed
2042 bool
2043 ChangeObject2ndSize (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
2044 Coord Difference, bool fixIt, bool incundo)
2046 bool change;
2048 /* setup identifier */
2049 Absolute = (fixIt) ? Difference : 0;
2050 Delta = Difference;
2051 change =
2052 (ObjectOperation (&Change2ndSizeFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2053 NULL);
2054 if (change)
2056 Draw ();
2057 if (incundo)
2058 IncrementUndoSerialNumber ();
2060 return (change);
2063 /* ---------------------------------------------------------------------------
2064 * changes the mask size of the passed object
2065 * Returns true if anything is changed
2067 bool
2068 ChangeObjectMaskSize (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
2069 Coord Difference, bool fixIt)
2071 bool change;
2073 /* setup identifier */
2074 Absolute = (fixIt) ? Difference : 0;
2075 Delta = Difference;
2076 change =
2077 (ObjectOperation (&ChangeMaskSizeFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2078 NULL);
2079 if (change)
2081 Draw ();
2082 IncrementUndoSerialNumber ();
2084 return (change);
2087 /* ---------------------------------------------------------------------------
2088 * changes the name of the passed object
2089 * returns the old name
2091 * The allocated memory isn't freed because the old string is used
2092 * by the undo module.
2094 void *
2095 ChangeObjectName (int Type, void *Ptr1, void *Ptr2, void *Ptr3, char *Name)
2097 void *result;
2098 /* setup identifier */
2099 NewName = Name;
2100 result = ObjectOperation (&ChangeNameFunctions, Type, Ptr1, Ptr2, Ptr3);
2101 Draw ();
2102 return (result);
2105 /* ---------------------------------------------------------------------------
2106 * changes the clearance-flag of the passed object
2107 * Returns true if anything is changed
2109 bool
2110 ChangeObjectJoin (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2112 if (ObjectOperation (&ChangeJoinFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2114 Draw ();
2115 IncrementUndoSerialNumber ();
2116 return (true);
2118 return (false);
2121 /* ---------------------------------------------------------------------------
2122 * sets the clearance-flag of the passed object
2123 * Returns true if anything is changed
2125 bool
2126 SetObjectJoin (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2128 if (ObjectOperation (&SetJoinFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2130 Draw ();
2131 IncrementUndoSerialNumber ();
2132 return (true);
2134 return (false);
2137 /* ---------------------------------------------------------------------------
2138 * clears the clearance-flag of the passed object
2139 * Returns true if anything is changed
2141 bool
2142 ClrObjectJoin (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2144 if (ObjectOperation (&ClrJoinFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2146 Draw ();
2147 IncrementUndoSerialNumber ();
2148 return (true);
2150 return (false);
2153 /* ---------------------------------------------------------------------------
2154 * changes the square-flag of the passed object
2155 * Returns true if anything is changed
2157 bool
2158 ChangeObjectSquare (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2160 if (ObjectOperation (&ChangeSquareFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2161 NULL)
2163 Draw ();
2164 IncrementUndoSerialNumber ();
2165 return (true);
2167 return (false);
2170 /* ---------------------------------------------------------------------------
2171 * sets the square-flag of the passed object
2172 * Returns true if anything is changed
2174 bool
2175 SetObjectSquare (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2177 if (ObjectOperation (&SetSquareFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2179 Draw ();
2180 IncrementUndoSerialNumber ();
2181 return (true);
2183 return (false);
2186 /* ---------------------------------------------------------------------------
2187 * clears the square-flag of the passed object
2188 * Returns true if anything is changed
2190 bool
2191 ClrObjectSquare (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2193 if (ObjectOperation (&ClrSquareFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2195 Draw ();
2196 IncrementUndoSerialNumber ();
2197 return (true);
2199 return (false);
2202 /* ---------------------------------------------------------------------------
2203 * changes the octagon-flag of the passed object
2204 * Returns true if anything is changed
2206 bool
2207 ChangeObjectOctagon (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2209 if (ObjectOperation (&ChangeOctagonFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2210 NULL)
2212 Draw ();
2213 IncrementUndoSerialNumber ();
2214 return (true);
2216 return (false);
2219 /* ---------------------------------------------------------------------------
2220 * sets the octagon-flag of the passed object
2221 * Returns true if anything is changed
2223 bool
2224 SetObjectOctagon (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2226 if (ObjectOperation (&SetOctagonFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2228 Draw ();
2229 IncrementUndoSerialNumber ();
2230 return (true);
2232 return (false);
2235 /* ---------------------------------------------------------------------------
2236 * clears the octagon-flag of the passed object
2237 * Returns true if anything is changed
2239 bool
2240 ClrObjectOctagon (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2242 if (ObjectOperation (&ClrOctagonFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2244 Draw ();
2245 IncrementUndoSerialNumber ();
2246 return (true);
2248 return (false);
2251 /* ---------------------------------------------------------------------------
2252 * queries the user for a new object name and changes it
2254 * The allocated memory isn't freed because the old string is used
2255 * by the undo module.
2257 void *
2258 QueryInputAndChangeObjectName (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2260 char *name = NULL;
2261 char msg[513];
2263 /* if passed an element name, make it an element reference instead */
2264 if (Type == ELEMENTNAME_TYPE)
2266 Type = ELEMENT_TYPE;
2267 Ptr2 = Ptr1;
2268 Ptr3 = Ptr1;
2270 switch (Type)
2272 case LINE_TYPE:
2273 name = gui->prompt_for (_("Linename:"),
2274 EMPTY (((LineType *) Ptr2)->Number));
2275 break;
2277 case VIA_TYPE:
2278 name = gui->prompt_for (_("Vianame:"),
2279 EMPTY (((PinType *) Ptr2)->Name));
2280 break;
2282 case PIN_TYPE:
2283 sprintf (msg, _("%s Pin Name:"), EMPTY (((PinType *) Ptr2)->Number));
2284 name = gui->prompt_for (msg, EMPTY (((PinType *) Ptr2)->Name));
2285 break;
2287 case PAD_TYPE:
2288 sprintf (msg, _("%s Pad Name:"), EMPTY (((PadType *) Ptr2)->Number));
2289 name = gui->prompt_for (msg, EMPTY (((PadType *) Ptr2)->Name));
2290 break;
2292 case TEXT_TYPE:
2293 name = gui->prompt_for (_("Enter text:"),
2294 EMPTY (((TextType *) Ptr2)->TextString));
2295 break;
2297 case ELEMENT_TYPE:
2298 name = gui->prompt_for (_("Elementname:"),
2299 EMPTY (ELEMENT_NAME
2300 (PCB, (ElementType *) Ptr2)));
2301 break;
2303 if (name)
2305 /* NB: ChangeObjectName takes ownership of the passed memory */
2306 char *old = (char *)ChangeObjectName (Type, Ptr1, Ptr2, Ptr3, name);
2307 if (old != (char *) -1)
2309 AddObjectToChangeNameUndoList (Type, Ptr1, Ptr2, Ptr3, old);
2310 IncrementUndoSerialNumber ();
2312 Draw ();
2313 return (Ptr3);
2315 return (NULL);
2318 /* ---------------------------------------------------------------------------
2319 * changes the maximum size of a layout
2320 * adjusts the scrollbars
2321 * releases the saved pixmap if necessary
2322 * and adjusts the cursor confinement box
2324 void
2325 ChangePCBSize (Coord Width, Coord Height)
2327 PCB->MaxWidth = Width;
2328 PCB->MaxHeight = Height;
2330 /* crosshair range is different if pastebuffer-mode
2331 * is enabled
2333 if (Settings.Mode == PASTEBUFFER_MODE)
2334 SetCrosshairRange (PASTEBUFFER->X - PASTEBUFFER->BoundingBox.X1,
2335 PASTEBUFFER->Y - PASTEBUFFER->BoundingBox.Y1,
2336 MAX (0,
2337 Width - (PASTEBUFFER->BoundingBox.X2 -
2338 PASTEBUFFER->X)), MAX (0,
2339 Height -
2340 (PASTEBUFFER->
2341 BoundingBox.Y2 -
2342 PASTEBUFFER->
2343 Y)));
2344 else
2345 SetCrosshairRange (0, 0, Width, Height);
2346 hid_action ("PCBChanged");
2349 /* ---------------------------------------------------------------------------
2350 * changes the mask size of a pad
2351 * returns TRUE if changed
2353 static void *
2354 ChangePadMaskSize (ElementType *Element, PadType *Pad)
2356 Coord value = (Absolute) ? Absolute : Pad->Mask + Delta;
2358 value = MAX (value, 0);
2359 if (value == Pad->Mask && Absolute == 0)
2360 value = Pad->Thickness;
2361 if (value != Pad->Mask)
2363 AddObjectToMaskSizeUndoList (PAD_TYPE, Element, Pad, Pad);
2364 ErasePad (Pad);
2365 r_delete_entry (PCB->Data->pad_tree, &Pad->BoundingBox);
2366 Pad->Mask = value;
2367 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
2368 DrawPad (Pad);
2369 return (Pad);
2371 return (NULL);
2374 /* ---------------------------------------------------------------------------
2375 * changes the mask size of a pin
2376 * returns TRUE if changed
2378 static void *
2379 ChangePinMaskSize (ElementType *Element, PinType *Pin)
2381 Coord value = (Absolute) ? Absolute : Pin->Mask + Delta;
2383 value = MAX (value, 0);
2384 if (value == Pin->Mask && Absolute == 0)
2385 value = Pin->Thickness;
2386 if (value != Pin->Mask)
2388 AddObjectToMaskSizeUndoList (PIN_TYPE, Element, Pin, Pin);
2389 ErasePin (Pin);
2390 r_delete_entry (PCB->Data->pin_tree, &Pin->BoundingBox);
2391 Pin->Mask = value;
2392 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
2393 DrawPin (Pin);
2394 return (Pin);
2396 return (NULL);
2399 /* ---------------------------------------------------------------------------
2400 * changes the mask size of a via
2401 * returns TRUE if changed
2403 static void *
2404 ChangeViaMaskSize (PinType *Via)
2406 Coord value;
2408 value = (Absolute) ? Absolute : Via->Mask + Delta;
2409 value = MAX (value, 0);
2410 if (value != Via->Mask)
2412 AddObjectToMaskSizeUndoList (VIA_TYPE, Via, Via, Via);
2413 EraseVia (Via);
2414 r_delete_entry (PCB->Data->via_tree, &Via->BoundingBox);
2415 Via->Mask = value;
2416 SetPinBoundingBox (Via);
2417 r_insert_entry (PCB->Data->via_tree, &Via->BoundingBox, 0);
2418 DrawVia (Via);
2419 return (Via);
2421 return (NULL);