More stackup changes
[geda-pcb/pcjc2/v2.git] / src / change.c
blobb48e82de30de376cc5b75119d6e0d5d6a3fcb651
1 /*!
2 * \file src/change.c
4 * \brief Functions used to change object properties.
6 * <hr>
8 * <h1><b>Copyright.</b></h1>\n
10 * PCB, interactive printed circuit board design
12 * Copyright (C) 1994,1995,1996, 2005 Thomas Nau
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * Contact addresses for paper mail and Email:
29 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
30 * Thomas.Nau@rz.uni-ulm.de
33 #ifdef HAVE_CONFIG_H
34 #include "config.h"
35 #endif
37 #include <stdlib.h>
38 #include <stdio.h>
40 #include "global.h"
42 #include "change.h"
43 #include "create.h"
44 #include "crosshair.h"
45 #include "data.h"
46 #include "draw.h"
47 #include "error.h"
48 #include "mymem.h"
49 #include "misc.h"
50 #include "mirror.h"
51 #include "polygon.h"
52 #include "rats.h"
53 #include "remove.h"
54 #include "rtree.h"
55 #include "search.h"
56 #include "select.h"
57 #include "set.h"
58 #include "thermal.h"
59 #include "undo.h"
61 #ifdef HAVE_LIBDMALLOC
62 #include <dmalloc.h>
63 #endif
65 /* ---------------------------------------------------------------------------
66 * some local prototypes
68 static void *ChangePinSize (ElementType *, PinType *);
69 static void *ChangePinClearSize (ElementType *, PinType *);
70 static void *ChangePinMaskSize (ElementType *, PinType *);
71 static void *ChangePadSize (ElementType *, PadType *);
72 static void *ChangePadClearSize (ElementType *, PadType *);
73 static void *ChangePadMaskSize (ElementType *, PadType *);
74 static void *ChangePin2ndSize (ElementType *, PinType *);
75 static void *ChangeElement2ndSize (ElementType *);
76 static void *ChangeViaSize (PinType *);
77 static void *ChangeVia2ndSize (PinType *);
78 static void *ChangeViaClearSize (PinType *);
79 static void *ChangeViaMaskSize (PinType *);
80 static void *ChangeLineSize (LayerType *, LineType *);
81 static void *ChangeLineClearSize (LayerType *, LineType *);
82 static void *ChangePolygonClearSize (LayerType *, PolygonType *);
83 static void *ChangeArcSize (LayerType *, ArcType *);
84 static void *ChangeArcClearSize (LayerType *, ArcType *);
85 static void *ChangeTextSize (LayerType *, TextType *);
86 static void *ChangeElementSize (ElementType *);
87 static void *ChangeElementNameSize (ElementType *);
88 static void *ChangePinName (ElementType *, PinType *);
89 static void *ChangePadName (ElementType *, PadType *);
90 static void *ChangeViaName (PinType *);
91 static void *ChangeLineName (LayerType *, LineType *);
92 static void *ChangeElementName (ElementType *);
93 static void *ChangeTextName (LayerType *, TextType *);
94 static void *ChangeElementSquare (ElementType *);
95 static void *SetElementSquare (ElementType *);
96 static void *ClrElementSquare (ElementType *);
97 static void *ChangeElementOctagon (ElementType *);
98 static void *SetElementOctagon (ElementType *);
99 static void *ClrElementOctagon (ElementType *);
100 static void *ChangePinSquare (ElementType *, PinType *);
101 static void *SetPinSquare (ElementType *, PinType *);
102 static void *ClrPinSquare (ElementType *, PinType *);
103 static void *ChangePinOctagon (ElementType *, PinType *);
104 static void *SetPinOctagon (ElementType *, PinType *);
105 static void *ClrPinOctagon (ElementType *, PinType *);
106 static void *ChangeViaOctagon (PinType *);
107 static void *SetViaOctagon (PinType *);
108 static void *ClrViaOctagon (PinType *);
109 static void *ChangePadSquare (ElementType *, PadType *);
110 static void *SetPadSquare (ElementType *, PadType *);
111 static void *ClrPadSquare (ElementType *, PadType *);
112 static void *ChangeViaThermal (PinType *);
113 static void *ChangePinThermal (ElementType *, PinType *);
114 static void *ChangeLineJoin (LayerType *, LineType *);
115 static void *SetLineJoin (LayerType *, LineType *);
116 static void *ClrLineJoin (LayerType *, LineType *);
117 static void *ChangeArcJoin (LayerType *, ArcType *);
118 static void *SetArcJoin (LayerType *, ArcType *);
119 static void *ClrArcJoin (LayerType *, ArcType *);
120 static void *ChangeTextJoin (LayerType *, TextType *);
121 static void *SetTextJoin (LayerType *, TextType *);
122 static void *ClrTextJoin (LayerType *, TextType *);
123 static void *ChangePolyClear (LayerType *, PolygonType *);
125 /* ---------------------------------------------------------------------------
126 * some local identifiers
128 static int Delta; /* change of size */
129 static int Absolute; /* Absolute size */
130 static char *NewName; /* new name */
131 static ObjectFunctionType ChangeSizeFunctions = {
132 ChangeLineSize,
133 ChangeTextSize,
134 ChangePolyClear,
135 ChangeViaSize,
136 ChangeElementSize, /* changes silk screen line width */
137 ChangeElementNameSize,
138 ChangePinSize,
139 ChangePadSize,
140 NULL,
141 NULL,
142 ChangeArcSize,
143 NULL
145 static ObjectFunctionType Change2ndSizeFunctions = {
146 NULL,
147 NULL,
148 NULL,
149 ChangeVia2ndSize,
150 ChangeElement2ndSize,
151 NULL,
152 ChangePin2ndSize,
153 NULL,
154 NULL,
155 NULL,
156 NULL,
157 NULL
159 static ObjectFunctionType ChangeThermalFunctions = {
160 NULL,
161 NULL,
162 NULL,
163 ChangeViaThermal,
164 NULL,
165 NULL,
166 ChangePinThermal,
167 NULL,
168 NULL,
169 NULL,
170 NULL,
171 NULL
173 static ObjectFunctionType ChangeClearSizeFunctions = {
174 ChangeLineClearSize,
175 NULL,
176 ChangePolygonClearSize, /* just to tell the user not to :-) */
177 ChangeViaClearSize,
178 NULL,
179 NULL,
180 ChangePinClearSize,
181 ChangePadClearSize,
182 NULL,
183 NULL,
184 ChangeArcClearSize,
185 NULL
187 static ObjectFunctionType ChangeNameFunctions = {
188 ChangeLineName,
189 ChangeTextName,
190 NULL,
191 ChangeViaName,
192 ChangeElementName,
193 NULL,
194 ChangePinName,
195 ChangePadName,
196 NULL,
197 NULL,
198 NULL,
199 NULL
201 static ObjectFunctionType ChangeSquareFunctions = {
202 NULL,
203 NULL,
204 NULL,
205 NULL,
206 ChangeElementSquare,
207 NULL,
208 ChangePinSquare,
209 ChangePadSquare,
210 NULL,
211 NULL,
212 NULL,
213 NULL
215 static ObjectFunctionType ChangeJoinFunctions = {
216 ChangeLineJoin,
217 ChangeTextJoin,
218 NULL,
219 NULL,
220 NULL,
221 NULL,
222 NULL,
223 NULL,
224 NULL,
225 NULL,
226 ChangeArcJoin,
227 NULL
229 static ObjectFunctionType ChangeOctagonFunctions = {
230 NULL,
231 NULL,
232 NULL,
233 ChangeViaOctagon,
234 ChangeElementOctagon,
235 NULL,
236 ChangePinOctagon,
237 NULL,
238 NULL,
239 NULL,
240 NULL,
241 NULL
243 static ObjectFunctionType ChangeMaskSizeFunctions = {
244 NULL,
245 NULL,
246 NULL,
247 ChangeViaMaskSize,
248 #if 0
249 ChangeElementMaskSize,
250 #else
251 NULL,
252 #endif
253 NULL,
254 ChangePinMaskSize,
255 ChangePadMaskSize,
256 NULL,
257 NULL,
258 NULL,
259 NULL
261 static ObjectFunctionType SetSquareFunctions = {
262 NULL,
263 NULL,
264 NULL,
265 NULL,
266 SetElementSquare,
267 NULL,
268 SetPinSquare,
269 SetPadSquare,
270 NULL,
271 NULL,
272 NULL,
273 NULL
275 static ObjectFunctionType SetJoinFunctions = {
276 SetLineJoin,
277 SetTextJoin,
278 NULL,
279 NULL,
280 NULL,
281 NULL,
282 NULL,
283 NULL,
284 NULL,
285 NULL,
286 SetArcJoin,
287 NULL
289 static ObjectFunctionType SetOctagonFunctions = {
290 NULL,
291 NULL,
292 NULL,
293 SetViaOctagon,
294 SetElementOctagon,
295 NULL,
296 SetPinOctagon,
297 NULL,
298 NULL,
299 NULL,
300 NULL,
301 NULL
303 static ObjectFunctionType ClrSquareFunctions = {
304 NULL,
305 NULL,
306 NULL,
307 NULL,
308 ClrElementSquare,
309 NULL,
310 ClrPinSquare,
311 ClrPadSquare,
312 NULL,
313 NULL,
314 NULL,
315 NULL
317 static ObjectFunctionType ClrJoinFunctions = {
318 ClrLineJoin,
319 ClrTextJoin,
320 NULL,
321 NULL,
322 NULL,
323 NULL,
324 NULL,
325 NULL,
326 NULL,
327 NULL,
328 ClrArcJoin,
329 NULL
331 static ObjectFunctionType ClrOctagonFunctions = {
332 NULL,
333 NULL,
334 NULL,
335 ClrViaOctagon,
336 ClrElementOctagon,
337 NULL,
338 ClrPinOctagon,
339 NULL,
340 NULL,
341 NULL,
342 NULL,
343 NULL
347 * \brief Changes the thermal on a via.
349 * \return TRUE if changed.
351 static void *
352 ChangeViaThermal (PinType *Via)
354 AddObjectToClearPolyUndoList (VIA_TYPE, Via, Via, Via, false);
355 RestoreToPolygon (PCB->Data, VIA_TYPE, CURRENT, Via);
356 AddObjectToFlagUndoList (VIA_TYPE, Via, Via, Via);
357 if (!Delta) /* remove the thermals */
358 CLEAR_THERM (INDEXOFCURRENT, Via);
359 else
360 ASSIGN_THERM (INDEXOFCURRENT, Delta, Via);
361 AddObjectToClearPolyUndoList (VIA_TYPE, Via, Via, Via, true);
362 ClearFromPolygon (PCB->Data, VIA_TYPE, CURRENT, Via);
363 DrawVia (Via);
364 return Via;
368 * \brief Changes the thermal on a pin.
370 * \return TRUE if changed.
372 static void *
373 ChangePinThermal (ElementType *element, PinType *Pin)
375 AddObjectToClearPolyUndoList (PIN_TYPE, element, Pin, Pin, false);
376 RestoreToPolygon (PCB->Data, VIA_TYPE, CURRENT, Pin);
377 AddObjectToFlagUndoList (PIN_TYPE, element, Pin, Pin);
378 if (!Delta) /* remove the thermals */
379 CLEAR_THERM (INDEXOFCURRENT, Pin);
380 else
381 ASSIGN_THERM (INDEXOFCURRENT, Delta, Pin);
382 AddObjectToClearPolyUndoList (PIN_TYPE, element, Pin, Pin, true);
383 ClearFromPolygon (PCB->Data, VIA_TYPE, CURRENT, Pin);
384 DrawPin (Pin);
385 return Pin;
389 * \brief Changes the size of a via.
391 * \return TRUE if changed.
393 static void *
394 ChangeViaSize (PinType *Via)
396 Coord value = Absolute ? Absolute : Via->Thickness + Delta;
398 if (TEST_FLAG (LOCKFLAG, Via))
399 return (NULL);
400 if (!TEST_FLAG (HOLEFLAG, Via) && value <= MAX_PINORVIASIZE &&
401 value >= MIN_PINORVIASIZE &&
402 value >= Via->DrillingHole + MIN_PINORVIACOPPER &&
403 value != Via->Thickness)
405 AddObjectToSizeUndoList (VIA_TYPE, Via, Via, Via);
406 EraseVia (Via);
407 r_delete_entry (PCB->Data->via_tree, (BoxType *) Via);
408 RestoreToPolygon (PCB->Data, PIN_TYPE, Via, Via);
409 if (Via->Mask)
411 AddObjectToMaskSizeUndoList (VIA_TYPE, Via, Via, Via);
412 Via->Mask += value - Via->Thickness;
414 Via->Thickness = value;
415 SetPinBoundingBox (Via);
416 r_insert_entry (PCB->Data->via_tree, (BoxType *) Via, 0);
417 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
418 DrawVia (Via);
419 return (Via);
421 return (NULL);
425 * \brief Changes the drilling hole of a via.
427 * \return TRUE if changed.
429 static void *
430 ChangeVia2ndSize (PinType *Via)
432 Coord value = (Absolute) ? Absolute : Via->DrillingHole + Delta;
434 if (TEST_FLAG (LOCKFLAG, Via))
435 return (NULL);
436 if (value <= MAX_PINORVIASIZE &&
437 value >= MIN_PINORVIAHOLE && (TEST_FLAG (HOLEFLAG, Via) ||
438 value <=
439 Via->Thickness - MIN_PINORVIACOPPER)
440 && value != Via->DrillingHole)
442 AddObjectTo2ndSizeUndoList (VIA_TYPE, Via, Via, Via);
443 EraseVia (Via);
444 RestoreToPolygon (PCB->Data, VIA_TYPE, Via, Via);
445 Via->DrillingHole = value;
446 if (TEST_FLAG (HOLEFLAG, Via))
448 AddObjectToSizeUndoList (VIA_TYPE, Via, Via, Via);
449 Via->Thickness = value;
451 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
452 DrawVia (Via);
453 return (Via);
455 return (NULL);
459 * \brief Changes the clearance size of a via.
461 * \return TRUE if changed.
463 static void *
464 ChangeViaClearSize (PinType *Via)
466 Coord value = (Absolute) ? Absolute : Via->Clearance + Delta;
468 if (TEST_FLAG (LOCKFLAG, Via))
469 return (NULL);
470 value = MIN (MAX_LINESIZE, value);
471 if (value < 0)
472 value = 0;
473 if (Delta < 0 && value < PCB->Bloat * 2)
474 value = 0;
475 if ((Delta > 0 || Absolute) && value < PCB->Bloat * 2)
476 value = PCB->Bloat * 2 + 2;
477 if (Via->Clearance == value)
478 return NULL;
479 RestoreToPolygon (PCB->Data, VIA_TYPE, Via, Via);
480 AddObjectToClearSizeUndoList (VIA_TYPE, Via, Via, Via);
481 EraseVia (Via);
482 r_delete_entry (PCB->Data->via_tree, (BoxType *) Via);
483 Via->Clearance = value;
484 SetPinBoundingBox (Via);
485 r_insert_entry (PCB->Data->via_tree, (BoxType *) Via, 0);
486 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
487 DrawVia (Via);
488 Via->Element = NULL;
489 return (Via);
494 * \brief Changes the size of a pin.
496 * \return TRUE if changed.
498 static void *
499 ChangePinSize (ElementType *Element, PinType *Pin)
501 Coord value = (Absolute) ? Absolute : Pin->Thickness + Delta;
503 if (TEST_FLAG (LOCKFLAG, Pin))
504 return (NULL);
505 if (!TEST_FLAG (HOLEFLAG, Pin) && value <= MAX_PINORVIASIZE &&
506 value >= MIN_PINORVIASIZE &&
507 value >= Pin->DrillingHole + MIN_PINORVIACOPPER &&
508 value != Pin->Thickness)
510 AddObjectToSizeUndoList (PIN_TYPE, Element, Pin, Pin);
511 AddObjectToMaskSizeUndoList (PIN_TYPE, Element, Pin, Pin);
512 ErasePin (Pin);
513 r_delete_entry (PCB->Data->pin_tree, &Pin->BoundingBox);
514 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
515 Pin->Mask += value - Pin->Thickness;
516 Pin->Thickness = value;
517 /* SetElementBB updates all associated rtrees */
518 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
519 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
520 DrawPin (Pin);
521 return (Pin);
523 return (NULL);
527 * \brief Changes the clearance size of a pin.
529 * \return TRUE if changed.
531 static void *
532 ChangePinClearSize (ElementType *Element, PinType *Pin)
534 Coord value = (Absolute) ? Absolute : Pin->Clearance + Delta;
536 if (TEST_FLAG (LOCKFLAG, Pin))
537 return (NULL);
538 value = MIN (MAX_LINESIZE, value);
539 if (value < 0)
540 value = 0;
541 if (Delta < 0 && value < PCB->Bloat * 2)
542 value = 0;
543 if ((Delta > 0 || Absolute) && value < PCB->Bloat * 2)
544 value = PCB->Bloat * 2 + 2;
545 if (Pin->Clearance == value)
546 return NULL;
547 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
548 AddObjectToClearSizeUndoList (PIN_TYPE, Element, Pin, Pin);
549 ErasePin (Pin);
550 r_delete_entry (PCB->Data->pin_tree, &Pin->BoundingBox);
551 Pin->Clearance = value;
552 /* SetElementBB updates all associated rtrees */
553 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
554 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
555 DrawPin (Pin);
556 return (Pin);
560 * \brief Changes the size of a pad.
562 * \return TRUE if changed.
564 static void *
565 ChangePadSize (ElementType *Element, PadType *Pad)
567 Coord value = (Absolute) ? Absolute : Pad->Thickness + Delta;
569 if (TEST_FLAG (LOCKFLAG, Pad))
570 return (NULL);
571 if (value <= MAX_PADSIZE && value >= MIN_PADSIZE && value != Pad->Thickness)
573 AddObjectToSizeUndoList (PAD_TYPE, Element, Pad, Pad);
574 AddObjectToMaskSizeUndoList (PAD_TYPE, Element, Pad, Pad);
575 RestoreToPolygon (PCB->Data, PAD_TYPE, Element, Pad);
576 ErasePad (Pad);
577 r_delete_entry (PCB->Data->pad_tree, &Pad->BoundingBox);
578 Pad->Mask += value - Pad->Thickness;
579 Pad->Thickness = value;
580 /* SetElementBB updates all associated rtrees */
581 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
582 ClearFromPolygon (PCB->Data, PAD_TYPE, Element, Pad);
583 DrawPad (Pad);
584 return (Pad);
586 return (NULL);
590 * \brief Changes the clearance size of a pad.
592 * \return TRUE if changed.
594 static void *
595 ChangePadClearSize (ElementType *Element, PadType *Pad)
597 Coord value = (Absolute) ? Absolute : Pad->Clearance + Delta;
599 if (TEST_FLAG (LOCKFLAG, Pad))
600 return (NULL);
601 value = MIN (MAX_LINESIZE, value);
602 if (value < 0)
603 value = 0;
604 if (Delta < 0 && value < PCB->Bloat * 2)
605 value = 0;
606 if ((Delta > 0 || Absolute) && value < PCB->Bloat * 2)
607 value = PCB->Bloat * 2 + 2;
608 if (value == Pad->Clearance)
609 return NULL;
610 AddObjectToClearSizeUndoList (PAD_TYPE, Element, Pad, Pad);
611 RestoreToPolygon (PCB->Data, PAD_TYPE, Element, Pad);
612 ErasePad (Pad);
613 r_delete_entry (PCB->Data->pad_tree, &Pad->BoundingBox);
614 Pad->Clearance = value;
615 /* SetElementBB updates all associated rtrees */
616 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
617 ClearFromPolygon (PCB->Data, PAD_TYPE, Element, Pad);
618 DrawPad (Pad);
619 return Pad;
623 * \brief Changes the drilling hole of all pins of an element.
625 * \return TRUE if changed.
627 static void *
628 ChangeElement2ndSize (ElementType *Element)
630 bool changed = false;
631 Coord value;
633 if (TEST_FLAG (LOCKFLAG, Element))
634 return (NULL);
635 PIN_LOOP (Element);
637 value = (Absolute) ? Absolute : pin->DrillingHole + Delta;
638 if (value <= MAX_PINORVIASIZE &&
639 value >= MIN_PINORVIAHOLE && (TEST_FLAG (HOLEFLAG, pin) ||
640 value <=
641 pin->Thickness -
642 MIN_PINORVIACOPPER)
643 && value != pin->DrillingHole)
645 changed = true;
646 AddObjectTo2ndSizeUndoList (PIN_TYPE, Element, pin, pin);
647 ErasePin (pin);
648 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, pin);
649 pin->DrillingHole = value;
650 if (TEST_FLAG (HOLEFLAG, pin))
652 AddObjectToSizeUndoList (PIN_TYPE, Element, pin, pin);
653 pin->Thickness = value;
655 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, pin);
656 DrawPin (pin);
659 END_LOOP;
660 if (changed)
661 return (Element);
662 else
663 return (NULL);
667 * \brief Changes the drilling hole of a pin.
669 * \return TRUE if changed.
671 static void *
672 ChangePin2ndSize (ElementType *Element, PinType *Pin)
674 Coord value = (Absolute) ? Absolute : Pin->DrillingHole + Delta;
676 if (TEST_FLAG (LOCKFLAG, Pin))
677 return (NULL);
678 if (value <= MAX_PINORVIASIZE &&
679 value >= MIN_PINORVIAHOLE && (TEST_FLAG (HOLEFLAG, Pin) ||
680 value <=
681 Pin->Thickness - MIN_PINORVIACOPPER)
682 && value != Pin->DrillingHole)
684 AddObjectTo2ndSizeUndoList (PIN_TYPE, Element, Pin, Pin);
685 ErasePin (Pin);
686 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
687 Pin->DrillingHole = value;
688 if (TEST_FLAG (HOLEFLAG, Pin))
690 AddObjectToSizeUndoList (PIN_TYPE, Element, Pin, Pin);
691 Pin->Thickness = value;
693 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
694 DrawPin (Pin);
695 return (Pin);
697 return (NULL);
701 * \brief Changes the size of a line.
703 * \return TRUE if changed.
705 static void *
706 ChangeLineSize (LayerType *Layer, LineType *Line)
708 Coord value = (Absolute) ? Absolute : Line->Thickness + Delta;
710 if (TEST_FLAG (LOCKFLAG, Line))
711 return (NULL);
712 if (value <= MAX_LINESIZE && value >= MIN_LINESIZE &&
713 value != Line->Thickness)
715 AddObjectToSizeUndoList (LINE_TYPE, Layer, Line, Line);
716 EraseLine (Line);
717 r_delete_entry (Layer->line_tree, (BoxType *) Line);
718 RestoreToPolygon (PCB->Data, LINE_TYPE, Layer, Line);
719 Line->Thickness = value;
720 SetLineBoundingBox (Line);
721 r_insert_entry (Layer->line_tree, (BoxType *) Line, 0);
722 ClearFromPolygon (PCB->Data, LINE_TYPE, Layer, Line);
723 DrawLine (Layer, Line);
724 return (Line);
726 return (NULL);
730 * \brief Changes the clearance size of a line.
732 * \return TRUE if changed.
734 static void *
735 ChangeLineClearSize (LayerType *Layer, LineType *Line)
737 Coord value = (Absolute) ? Absolute : Line->Clearance + Delta;
739 if (TEST_FLAG (LOCKFLAG, Line) || !TEST_FLAG (CLEARLINEFLAG, Line))
740 return (NULL);
741 value = MIN (MAX_LINESIZE, MAX (value, PCB->Bloat * 2 + 2));
742 if (value != Line->Clearance)
744 AddObjectToClearSizeUndoList (LINE_TYPE, Layer, Line, Line);
745 RestoreToPolygon (PCB->Data, LINE_TYPE, Layer, Line);
746 EraseLine (Line);
747 r_delete_entry (Layer->line_tree, (BoxType *) Line);
748 Line->Clearance = value;
749 if (Line->Clearance == 0)
751 CLEAR_FLAG (CLEARLINEFLAG, Line);
752 Line->Clearance = MIL_TO_COORD(10);
754 SetLineBoundingBox (Line);
755 r_insert_entry (Layer->line_tree, (BoxType *) Line, 0);
756 ClearFromPolygon (PCB->Data, LINE_TYPE, Layer, Line);
757 DrawLine (Layer, Line);
758 return (Line);
760 return (NULL);
764 * \brief Handle attempts to change the clearance of a polygon.
766 static void *
767 ChangePolygonClearSize (LayerType *Layer, PolygonType *poly)
769 static int shown_this_message = 0;
770 if (!shown_this_message)
772 gui->confirm_dialog (_("To change the clearance of objects in a polygon, "
773 "change the objects, not the polygon.\n"
774 "Hint: To set a minimum clearance for a group of objects, "
775 "select them all then :MinClearGap(Selected,=10,mil)"),
776 "Ok", NULL);
777 shown_this_message = 1;
780 return (NULL);
784 * \brief Changes the size of an arc.
786 * \return TRUE if changed.
788 static void *
789 ChangeArcSize (LayerType *Layer, ArcType *Arc)
791 Coord value = (Absolute) ? Absolute : Arc->Thickness + Delta;
793 if (TEST_FLAG (LOCKFLAG, Arc))
794 return (NULL);
795 if (value <= MAX_LINESIZE && value >= MIN_LINESIZE &&
796 value != Arc->Thickness)
798 AddObjectToSizeUndoList (ARC_TYPE, Layer, Arc, Arc);
799 EraseArc (Arc);
800 r_delete_entry (Layer->arc_tree, (BoxType *) Arc);
801 RestoreToPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
802 Arc->Thickness = value;
803 SetArcBoundingBox (Arc);
804 r_insert_entry (Layer->arc_tree, (BoxType *) Arc, 0);
805 ClearFromPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
806 DrawArc (Layer, Arc);
807 return (Arc);
809 return (NULL);
813 * \brief Changes the clearance size of an arc.
815 * \return TRUE if changed.
817 static void *
818 ChangeArcClearSize (LayerType *Layer, ArcType *Arc)
820 Coord value = (Absolute) ? Absolute : Arc->Clearance + Delta;
822 if (TEST_FLAG (LOCKFLAG, Arc) || !TEST_FLAG (CLEARLINEFLAG, Arc))
823 return (NULL);
824 value = MIN (MAX_LINESIZE, MAX (value, PCB->Bloat * 2 + 2));
825 if (value != Arc->Clearance)
827 AddObjectToClearSizeUndoList (ARC_TYPE, Layer, Arc, Arc);
828 EraseArc (Arc);
829 r_delete_entry (Layer->arc_tree, (BoxType *) Arc);
830 RestoreToPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
831 Arc->Clearance = value;
832 if (Arc->Clearance == 0)
834 CLEAR_FLAG (CLEARLINEFLAG, Arc);
835 Arc->Clearance = MIL_TO_COORD(10);
837 SetArcBoundingBox (Arc);
838 r_insert_entry (Layer->arc_tree, (BoxType *) Arc, 0);
839 ClearFromPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
840 DrawArc (Layer, Arc);
841 return (Arc);
843 return (NULL);
847 * \brief Changes the scaling factor of a text object.
849 * \return TRUE if changed.
851 static void *
852 ChangeTextSize (LayerType *Layer, TextType *Text)
854 int value = (Absolute != 0 ? 0 : Text->Scale) +
855 (double)(Absolute != 0 ? Absolute : Delta)
856 / (double)FONT_CAPHEIGHT * 100.;
858 if (TEST_FLAG (LOCKFLAG, Text))
859 return (NULL);
860 if (value <= MAX_TEXTSCALE && value >= MIN_TEXTSCALE &&
861 value != Text->Scale)
863 AddObjectToSizeUndoList (TEXT_TYPE, Layer, Text, Text);
864 EraseText (Layer, Text);
865 r_delete_entry (Layer->text_tree, (BoxType *) Text);
866 RestoreToPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
867 Text->Scale = value;
868 SetTextBoundingBox (&PCB->Font, Text);
869 r_insert_entry (Layer->text_tree, (BoxType *) Text, 0);
870 ClearFromPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
871 DrawText (Layer, Text);
872 return (Text);
874 return (NULL);
878 * \brief Changes the scaling factor of an element's outline.
880 * \return TRUE if changed.
882 static void *
883 ChangeElementSize (ElementType *Element)
885 Coord value;
886 bool changed = false;
888 if (TEST_FLAG (LOCKFLAG, Element))
889 return (NULL);
890 if (PCB->ElementOn)
891 EraseElement (Element);
892 ELEMENTLINE_LOOP (Element);
894 value = (Absolute) ? Absolute : line->Thickness + Delta;
895 if (value <= MAX_LINESIZE && value >= MIN_LINESIZE &&
896 value != line->Thickness)
898 AddObjectToSizeUndoList (ELEMENTLINE_TYPE, Element, line, line);
899 line->Thickness = value;
900 changed = true;
903 END_LOOP;
904 ARC_LOOP (Element);
906 value = (Absolute) ? Absolute : arc->Thickness + Delta;
907 if (value <= MAX_LINESIZE && value >= MIN_LINESIZE &&
908 value != arc->Thickness)
910 AddObjectToSizeUndoList (ELEMENTARC_TYPE, Element, arc, arc);
911 arc->Thickness = value;
912 changed = true;
915 END_LOOP;
916 if (PCB->ElementOn)
918 DrawElement (Element);
920 if (changed)
921 return (Element);
922 return (NULL);
926 * \brief Changes the scaling factor of a elementname object.
928 * \return TRUE if changed.
930 static void *
931 ChangeElementNameSize (ElementType *Element)
933 int value = (Absolute != 0 ? 0 : DESCRIPTION_TEXT (Element).Scale) +
934 (double)(Absolute != 0 ? Absolute : Delta)
935 / (double)FONT_CAPHEIGHT * 100.;
937 if (TEST_FLAG (LOCKFLAG, &Element->Name[0]))
938 return (NULL);
939 if (value <= MAX_TEXTSCALE && value >= MIN_TEXTSCALE)
941 EraseElementName (Element);
942 ELEMENTTEXT_LOOP (Element);
944 AddObjectToSizeUndoList (ELEMENTNAME_TYPE, Element, text, text);
945 r_delete_entry (PCB->Data->name_tree[n], (BoxType *) text);
946 text->Scale = value;
947 SetTextBoundingBox (&PCB->Font, text);
948 r_insert_entry (PCB->Data->name_tree[n], (BoxType *) text, 0);
950 END_LOOP;
951 DrawElementName (Element);
952 return (Element);
954 return (NULL);
958 * \brief Changes the name of a via.
960 static void *
961 ChangeViaName (PinType *Via)
963 char *old = Via->Name;
965 if (TEST_FLAG (DISPLAYNAMEFLAG, Via))
967 ErasePinName (Via);
968 Via->Name = NewName;
969 DrawPinName (Via);
971 else
972 Via->Name = NewName;
973 return (old);
977 * \brief Changes the name of a pin.
979 static void *
980 ChangePinName (ElementType *Element, PinType *Pin)
982 char *old = Pin->Name;
984 (void) Element; /* get rid of 'unused...' warnings */
985 if (TEST_FLAG (DISPLAYNAMEFLAG, Pin))
987 ErasePinName (Pin);
988 Pin->Name = NewName;
989 DrawPinName (Pin);
991 else
992 Pin->Name = NewName;
993 return (old);
997 * \brief Changes the name of a pad.
999 static void *
1000 ChangePadName (ElementType *Element, PadType *Pad)
1002 char *old = Pad->Name;
1004 (void) Element; /* get rid of 'unused...' warnings */
1005 if (TEST_FLAG (DISPLAYNAMEFLAG, Pad))
1007 ErasePadName (Pad);
1008 Pad->Name = NewName;
1009 DrawPadName (Pad);
1011 else
1012 Pad->Name = NewName;
1013 return (old);
1017 * \brief Changes the name of a line.
1019 static void *
1020 ChangeLineName (LayerType *Layer, LineType *Line)
1022 char *old = Line->Number;
1024 (void) Layer;
1025 Line->Number = NewName;
1026 return (old);
1030 * \brief Changes the layout-name of an element.
1032 * Change the specified text on an element, either on the board (give
1033 * PCB, PCB->Data) or in a buffer (give NULL, Buffer->Data).
1035 * \return The old string is returned, and must be properly freed by the
1036 * caller.
1038 char *
1039 ChangeElementText (PCBType *pcb, DataType *data, ElementType *Element, int which, char *new_name)
1041 char *old = Element->Name[which].TextString;
1043 #ifdef DEBUG
1044 printf("In ChangeElementText, updating old TextString %s to %s\n", old, new_name);
1045 #endif
1047 if (pcb && which == NAME_INDEX (pcb))
1048 EraseElementName (Element);
1050 r_delete_entry (data->name_tree[which],
1051 & Element->Name[which].BoundingBox);
1053 Element->Name[which].TextString = new_name;
1054 SetTextBoundingBox (&PCB->Font, &Element->Name[which]);
1056 r_insert_entry (data->name_tree[which],
1057 & Element->Name[which].BoundingBox, 0);
1059 if (pcb && which == NAME_INDEX (pcb))
1060 DrawElementName (Element);
1062 return old;
1065 static void *
1066 ChangeElementName (ElementType *Element)
1068 if (TEST_FLAG (LOCKFLAG, &Element->Name[0]))
1069 return (NULL);
1070 if (NAME_INDEX (PCB) == NAMEONPCB_INDEX)
1072 if (TEST_FLAG (UNIQUENAMEFLAG, PCB) &&
1073 UniqueElementName (PCB->Data, NewName) != NewName)
1075 Message (_("Error: The name \"%s\" is not unique!\n"), NewName);
1076 return ((char *) -1);
1080 return ChangeElementText (PCB, PCB->Data, Element, NAME_INDEX (PCB), NewName);
1084 * \brief Sets data of a text object and calculates bounding box.
1086 * Memory must have already been allocated.
1087 * The one for the new string is allocated.
1089 * \return True if the string has been changed.
1091 static void *
1092 ChangeTextName (LayerType *Layer, TextType *Text)
1094 char *old = Text->TextString;
1096 if (TEST_FLAG (LOCKFLAG, Text))
1097 return (NULL);
1098 EraseText (Layer, Text);
1099 r_delete_entry (Layer->text_tree, (BoxType *) Text);
1100 RestoreToPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
1101 Text->TextString = NewName;
1103 /* calculate size of the bounding box */
1104 SetTextBoundingBox (&PCB->Font, Text);
1105 r_insert_entry(Layer->text_tree, (BoxType *) Text, 0);
1106 ClearFromPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
1107 DrawText (Layer, Text);
1108 return (old);
1112 * \brief Changes the name of a layout; memory has to be already
1113 * allocated.
1115 bool
1116 ChangeLayoutName (char *Name)
1118 free (PCB->Name);
1119 PCB->Name = Name;
1120 hid_action ("PCBChanged");
1121 return (true);
1125 * \brief Changes the side of the board an element is on.
1127 * \return TRUE if done.
1129 bool
1130 ChangeElementSide (ElementType *Element, Coord yoff)
1132 if (TEST_FLAG (LOCKFLAG, Element))
1133 return (false);
1134 EraseElement (Element);
1135 AddObjectToMirrorUndoList (ELEMENT_TYPE, Element, Element, Element, yoff);
1136 MirrorElementCoordinates (PCB->Data, Element, yoff);
1137 DrawElement (Element);
1138 return (true);
1142 * \brief Changes the name of a layer; memory has to be already
1143 * allocated.
1145 bool
1146 ChangeLayerName (LayerType *Layer, char *Name)
1148 free (CURRENT->Name);
1149 CURRENT->Name = Name;
1150 hid_action ("LayersChanged");
1151 return (true);
1155 * \brief Changes the clearance flag of a line.
1157 static void *
1158 ChangeLineJoin (LayerType *Layer, LineType *Line)
1160 if (TEST_FLAG (LOCKFLAG, Line))
1161 return (NULL);
1162 EraseLine (Line);
1163 if (TEST_FLAG(CLEARLINEFLAG, Line))
1165 AddObjectToClearPolyUndoList (LINE_TYPE, Layer, Line, Line, false);
1166 RestoreToPolygon (PCB->Data, LINE_TYPE, Layer, Line);
1168 AddObjectToFlagUndoList (LINE_TYPE, Layer, Line, Line);
1169 TOGGLE_FLAG (CLEARLINEFLAG, Line);
1170 if (TEST_FLAG(CLEARLINEFLAG, Line))
1172 AddObjectToClearPolyUndoList (LINE_TYPE, Layer, Line, Line, true);
1173 ClearFromPolygon (PCB->Data, LINE_TYPE, Layer, Line);
1175 DrawLine (Layer, Line);
1176 return (Line);
1180 * \brief Sets the clearance flag of a line.
1182 static void *
1183 SetLineJoin (LayerType *Layer, LineType *Line)
1185 if (TEST_FLAG (LOCKFLAG, Line) || TEST_FLAG (CLEARLINEFLAG, Line))
1186 return (NULL);
1187 return ChangeLineJoin (Layer, Line);
1191 * \brief Clears the clearance flag of a line.
1193 static void *
1194 ClrLineJoin (LayerType *Layer, LineType *Line)
1196 if (TEST_FLAG (LOCKFLAG, Line) || !TEST_FLAG (CLEARLINEFLAG, Line))
1197 return (NULL);
1198 return ChangeLineJoin (Layer, Line);
1202 * \brief Changes the clearance flag of an arc.
1204 static void *
1205 ChangeArcJoin (LayerType *Layer, ArcType *Arc)
1207 if (TEST_FLAG (LOCKFLAG, Arc))
1208 return (NULL);
1209 EraseArc (Arc);
1210 if (TEST_FLAG (CLEARLINEFLAG, Arc))
1212 RestoreToPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
1213 AddObjectToClearPolyUndoList (ARC_TYPE, Layer, Arc, Arc, false);
1215 AddObjectToFlagUndoList (ARC_TYPE, Layer, Arc, Arc);
1216 TOGGLE_FLAG (CLEARLINEFLAG, Arc);
1217 if (TEST_FLAG (CLEARLINEFLAG, Arc))
1219 ClearFromPolygon (PCB->Data, ARC_TYPE, Layer, Arc);
1220 AddObjectToClearPolyUndoList (ARC_TYPE, Layer, Arc, Arc, true);
1222 DrawArc (Layer, Arc);
1223 return (Arc);
1227 * \brief Sets the clearance flag of an arc.
1229 static void *
1230 SetArcJoin (LayerType *Layer, ArcType *Arc)
1232 if (TEST_FLAG (LOCKFLAG, Arc) || TEST_FLAG (CLEARLINEFLAG, Arc))
1233 return (NULL);
1234 return ChangeArcJoin (Layer, Arc);
1238 * \brief Clears the clearance flag of an arc.
1240 static void *
1241 ClrArcJoin (LayerType *Layer, ArcType *Arc)
1243 if (TEST_FLAG (LOCKFLAG, Arc) || !TEST_FLAG (CLEARLINEFLAG, Arc))
1244 return (NULL);
1245 return ChangeArcJoin (Layer, Arc);
1249 * \brief Changes the clearance flag of a text.
1251 static void *
1252 ChangeTextJoin (LayerType *Layer, TextType *Text)
1254 if (TEST_FLAG (LOCKFLAG, Text))
1255 return (NULL);
1256 EraseText (Layer, Text);
1257 if (TEST_FLAG(CLEARLINEFLAG, Text))
1259 AddObjectToClearPolyUndoList (TEXT_TYPE, Layer, Text, Text, false);
1260 RestoreToPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
1262 AddObjectToFlagUndoList (TEXT_TYPE, Layer, Text, Text);
1263 TOGGLE_FLAG (CLEARLINEFLAG, Text);
1264 if (TEST_FLAG(CLEARLINEFLAG, Text))
1266 AddObjectToClearPolyUndoList (TEXT_TYPE, Layer, Text, Text, true);
1267 ClearFromPolygon (PCB->Data, TEXT_TYPE, Layer, Text);
1269 DrawText (Layer, Text);
1270 return (Text);
1274 * \brief Sets the clearance flag of a text.
1276 static void *
1277 SetTextJoin (LayerType *Layer, TextType *Text)
1279 if (TEST_FLAG (LOCKFLAG, Text) || TEST_FLAG (CLEARLINEFLAG, Text))
1280 return (NULL);
1281 return ChangeTextJoin (Layer, Text);
1285 * \brief Clears the clearance flag of a text.
1287 static void *
1288 ClrTextJoin (LayerType *Layer, TextType *Text)
1290 if (TEST_FLAG (LOCKFLAG, Text) || !TEST_FLAG (CLEARLINEFLAG, Text))
1291 return (NULL);
1292 return ChangeTextJoin (Layer, Text);
1296 * \brief Changes the square flag of all pins on an element.
1298 static void *
1299 ChangeElementSquare (ElementType *Element)
1301 void *ans = NULL;
1303 if (TEST_FLAG (LOCKFLAG, Element))
1304 return (NULL);
1305 PIN_LOOP (Element);
1307 ans = ChangePinSquare (Element, pin);
1309 END_LOOP;
1310 PAD_LOOP (Element);
1312 ans = ChangePadSquare (Element, pad);
1314 END_LOOP;
1315 return (ans);
1319 * \brief Sets the square flag of all pins on an element.
1321 static void *
1322 SetElementSquare (ElementType *Element)
1324 void *ans = NULL;
1326 if (TEST_FLAG (LOCKFLAG, Element))
1327 return (NULL);
1328 PIN_LOOP (Element);
1330 ans = SetPinSquare (Element, pin);
1332 END_LOOP;
1333 PAD_LOOP (Element);
1335 ans = SetPadSquare (Element, pad);
1337 END_LOOP;
1338 return (ans);
1342 * \brief Clears the square flag of all pins on an element.
1344 static void *
1345 ClrElementSquare (ElementType *Element)
1347 void *ans = NULL;
1349 if (TEST_FLAG (LOCKFLAG, Element))
1350 return (NULL);
1351 PIN_LOOP (Element);
1353 ans = ClrPinSquare (Element, pin);
1355 END_LOOP;
1356 PAD_LOOP (Element);
1358 ans = ClrPadSquare (Element, pad);
1360 END_LOOP;
1361 return (ans);
1365 * \brief Changes the octagon flags of all pins of an element.
1367 static void *
1368 ChangeElementOctagon (ElementType *Element)
1370 void *result = NULL;
1372 if (TEST_FLAG (LOCKFLAG, Element))
1373 return (NULL);
1374 PIN_LOOP (Element);
1376 ChangePinOctagon (Element, pin);
1377 result = Element;
1379 END_LOOP;
1380 return (result);
1384 * \brief Sets the octagon flags of all pins of an element.
1386 static void *
1387 SetElementOctagon (ElementType *Element)
1389 void *result = NULL;
1391 if (TEST_FLAG (LOCKFLAG, Element))
1392 return (NULL);
1393 PIN_LOOP (Element);
1395 SetPinOctagon (Element, pin);
1396 result = Element;
1398 END_LOOP;
1399 return (result);
1403 * \brief Clears the octagon flags of all pins of an element.
1405 static void *
1406 ClrElementOctagon (ElementType *Element)
1408 void *result = NULL;
1410 if (TEST_FLAG (LOCKFLAG, Element))
1411 return (NULL);
1412 PIN_LOOP (Element);
1414 ClrPinOctagon (Element, pin);
1415 result = Element;
1417 END_LOOP;
1418 return (result);
1422 * \brief Changes the square flag of a pad.
1424 static void *
1425 ChangePadSquare (ElementType *Element, PadType *Pad)
1427 if (TEST_FLAG (LOCKFLAG, Pad))
1428 return (NULL);
1429 ErasePad (Pad);
1430 AddObjectToClearPolyUndoList (PAD_TYPE, Element, Pad, Pad, false);
1431 RestoreToPolygon (PCB->Data, PAD_TYPE, Element, Pad);
1432 AddObjectToFlagUndoList (PAD_TYPE, Element, Pad, Pad);
1433 TOGGLE_FLAG (SQUAREFLAG, Pad);
1434 AddObjectToClearPolyUndoList (PAD_TYPE, Element, Pad, Pad, true);
1435 ClearFromPolygon (PCB->Data, PAD_TYPE, Element, Pad);
1436 DrawPad (Pad);
1437 return (Pad);
1441 * \brief Sets the square flag of a pad.
1443 static void *
1444 SetPadSquare (ElementType *Element, PadType *Pad)
1447 if (TEST_FLAG (LOCKFLAG, Pad) || TEST_FLAG (SQUAREFLAG, Pad))
1448 return (NULL);
1450 return (ChangePadSquare (Element, Pad));
1455 * \brief Clears the square flag of a pad.
1457 static void *
1458 ClrPadSquare (ElementType *Element, PadType *Pad)
1461 if (TEST_FLAG (LOCKFLAG, Pad) || !TEST_FLAG (SQUAREFLAG, Pad))
1462 return (NULL);
1464 return (ChangePadSquare (Element, Pad));
1469 * \brief Changes the square flag of a pin.
1471 static void *
1472 ChangePinSquare (ElementType *Element, PinType *Pin)
1474 if (TEST_FLAG (LOCKFLAG, Pin))
1475 return (NULL);
1476 ErasePin (Pin);
1477 AddObjectToClearPolyUndoList (PIN_TYPE, Element, Pin, Pin, false);
1478 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
1479 AddObjectToFlagUndoList (PIN_TYPE, Element, Pin, Pin);
1480 TOGGLE_FLAG (SQUAREFLAG, Pin);
1481 AddObjectToClearPolyUndoList (PIN_TYPE, Element, Pin, Pin, true);
1482 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
1483 DrawPin (Pin);
1484 return (Pin);
1488 * \brief Sets the square flag of a pin.
1490 static void *
1491 SetPinSquare (ElementType *Element, PinType *Pin)
1493 if (TEST_FLAG (LOCKFLAG, Pin) || TEST_FLAG (SQUAREFLAG, Pin))
1494 return (NULL);
1496 return (ChangePinSquare (Element, Pin));
1500 * \brief Clears the square flag of a pin.
1502 static void *
1503 ClrPinSquare (ElementType *Element, PinType *Pin)
1505 if (TEST_FLAG (LOCKFLAG, Pin) || !TEST_FLAG (SQUAREFLAG, Pin))
1506 return (NULL);
1508 return (ChangePinSquare (Element, Pin));
1512 * \brief Changes the octagon flag of a via.
1514 static void *
1515 ChangeViaOctagon (PinType *Via)
1517 if (TEST_FLAG (LOCKFLAG, Via))
1518 return (NULL);
1519 EraseVia (Via);
1520 AddObjectToClearPolyUndoList (VIA_TYPE, Via, Via, Via, false);
1521 RestoreToPolygon (PCB->Data, VIA_TYPE, Via, Via);
1522 AddObjectToFlagUndoList (VIA_TYPE, Via, Via, Via);
1523 TOGGLE_FLAG (OCTAGONFLAG, Via);
1524 AddObjectToClearPolyUndoList (VIA_TYPE, Via, Via, Via, true);
1525 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
1526 DrawVia (Via);
1527 return (Via);
1531 * \brief Sets the octagon flag of a via.
1533 static void *
1534 SetViaOctagon (PinType *Via)
1536 if (TEST_FLAG (LOCKFLAG, Via) || TEST_FLAG (OCTAGONFLAG, Via))
1537 return (NULL);
1539 return (ChangeViaOctagon (Via));
1543 * \brief Clears the octagon flag of a via.
1545 static void *
1546 ClrViaOctagon (PinType *Via)
1548 if (TEST_FLAG (LOCKFLAG, Via) || !TEST_FLAG (OCTAGONFLAG, Via))
1549 return (NULL);
1551 return (ChangeViaOctagon (Via));
1555 * \brief Changes the octagon flag of a pin.
1557 static void *
1558 ChangePinOctagon (ElementType *Element, PinType *Pin)
1560 if (TEST_FLAG (LOCKFLAG, Pin))
1561 return (NULL);
1562 ErasePin (Pin);
1563 AddObjectToClearPolyUndoList (PIN_TYPE, Element, Pin, Pin, false);
1564 RestoreToPolygon (PCB->Data, PIN_TYPE, Element, Pin);
1565 AddObjectToFlagUndoList (PIN_TYPE, Element, Pin, Pin);
1566 TOGGLE_FLAG (OCTAGONFLAG, Pin);
1567 AddObjectToClearPolyUndoList (PIN_TYPE, Element, Pin, Pin, true);
1568 ClearFromPolygon (PCB->Data, PIN_TYPE, Element, Pin);
1569 DrawPin (Pin);
1570 return (Pin);
1574 * \brief Sets the octagon flag of a pin.
1576 static void *
1577 SetPinOctagon (ElementType *Element, PinType *Pin)
1579 if (TEST_FLAG (LOCKFLAG, Pin) || TEST_FLAG (OCTAGONFLAG, Pin))
1580 return (NULL);
1582 return (ChangePinOctagon (Element, Pin));
1586 * \brief Clears the octagon flag of a pin.
1588 static void *
1589 ClrPinOctagon (ElementType *Element, PinType *Pin)
1591 if (TEST_FLAG (LOCKFLAG, Pin) || !TEST_FLAG (OCTAGONFLAG, Pin))
1592 return (NULL);
1594 return (ChangePinOctagon (Element, Pin));
1598 * \brief Changes the hole flag of a via.
1600 bool
1601 ChangeHole (PinType *Via)
1603 if (TEST_FLAG (LOCKFLAG, Via))
1604 return (false);
1605 EraseVia (Via);
1606 AddObjectToFlagUndoList (VIA_TYPE, Via, Via, Via);
1607 AddObjectToMaskSizeUndoList (VIA_TYPE, Via, Via, Via);
1608 r_delete_entry (PCB->Data->via_tree, (BoxType *) Via);
1609 RestoreToPolygon (PCB->Data, VIA_TYPE, Via, Via);
1610 TOGGLE_FLAG (HOLEFLAG, Via);
1612 if (TEST_FLAG (HOLEFLAG, Via))
1614 /* A tented via becomes an minimally untented hole. An untented
1615 via retains its mask clearance. */
1616 if (Via->Mask > Via->Thickness)
1618 Via->Mask = (Via->DrillingHole
1619 + (Via->Mask - Via->Thickness));
1621 else if (Via->Mask < Via->DrillingHole)
1623 Via->Mask = Via->DrillingHole + 2 * MASKFRAME;
1626 else
1628 Via->Mask = (Via->Thickness
1629 + (Via->Mask - Via->DrillingHole));
1632 SetPinBoundingBox (Via);
1633 r_insert_entry (PCB->Data->via_tree, (BoxType *) Via, 0);
1634 ClearFromPolygon (PCB->Data, VIA_TYPE, Via, Via);
1635 DrawVia (Via);
1636 Draw ();
1637 return (true);
1641 * \brief Changes the nopaste flag of a pad.
1643 bool
1644 ChangePaste (PadType *Pad)
1646 if (TEST_FLAG (LOCKFLAG, Pad))
1647 return (false);
1648 ErasePad (Pad);
1649 AddObjectToFlagUndoList (PAD_TYPE, Pad, Pad, Pad);
1650 TOGGLE_FLAG (NOPASTEFLAG, Pad);
1651 DrawPad (Pad);
1652 Draw ();
1653 return (true);
1657 * \brief Changes the CLEARPOLY flag of a polygon.
1659 static void *
1660 ChangePolyClear (LayerType *Layer, PolygonType *Polygon)
1662 if (TEST_FLAG (LOCKFLAG, Polygon))
1663 return (NULL);
1664 AddObjectToClearPolyUndoList (POLYGON_TYPE, Layer, Polygon, Polygon, true);
1665 AddObjectToFlagUndoList (POLYGON_TYPE, Layer, Polygon, Polygon);
1666 TOGGLE_FLAG (CLEARPOLYFLAG, Polygon);
1667 InitClip (PCB->Data, Layer, Polygon);
1668 DrawPolygon (Layer, Polygon);
1669 return (Polygon);
1673 * \brief Changes the side of all selected and visible elements.
1675 * \return True if anything has changed.
1677 bool
1678 ChangeSelectedElementSide (void)
1680 bool change = false;
1682 /* setup identifiers */
1683 if (PCB->PinOn && PCB->ElementOn)
1684 ELEMENT_LOOP (PCB->Data);
1686 if (TEST_FLAG (SELECTEDFLAG, element))
1688 change |= ChangeElementSide (element, 0);
1691 END_LOOP;
1692 if (change)
1694 Draw ();
1695 IncrementUndoSerialNumber ();
1697 return (change);
1701 * \brief Changes the thermals on all selected and visible pins and/or
1702 * vias.
1704 * \return True if anything has changed.
1706 bool
1707 ChangeSelectedThermals (int types, int therm_style)
1709 bool change = false;
1711 Delta = therm_style;
1712 change = SelectedOperation (&ChangeThermalFunctions, false, types);
1713 if (change)
1715 Draw ();
1716 IncrementUndoSerialNumber ();
1718 return (change);
1723 * \brief Changes the thermals on all selected and visible pins and/or
1724 * vias.
1726 * \return True if anything has changed.
1728 bool
1729 ChangeSelectedViaLayers (int from, int to)
1731 bool change = false;
1732 int new_from;
1733 int new_to;
1734 int i;
1736 VIA_LOOP (PCB->Data);
1738 if (TEST_FLAG (LOCKFLAG, via))
1739 continue;
1740 if (TEST_FLAG (SELECTEDFLAG, via))
1743 new_from = (from != -1)?from:via->BuriedFrom;
1744 new_to = (to != -1)?to:via->BuriedTo;
1746 if (new_from == new_to)
1747 continue;
1749 /* special case - changing TH via "from" layer sets "to" layer to bottom layer */
1750 if (!VIA_IS_BURIED (via)
1751 && (to == -1))
1752 new_to = GetMaxBottomLayer ();
1754 for (i=0; i < max_copper_layer; i++)
1756 /* AddObjectToClearPolyUndoList (VIA_TYPE, &(PCB->Data->Layer[i]), via, via, false); not needed? */
1757 RestoreToPolygon (PCB->Data, VIA_TYPE, &(PCB->Data->Layer[i]), via);
1760 AddObjectToSetViaLayersUndoList (via, via, via);
1761 via->BuriedFrom = new_from;
1762 via->BuriedTo = new_to;
1764 if (VIA_IS_BURIED (via))
1766 SanitizeBuriedVia (via);
1767 for (i=0; i < max_copper_layer; i++)
1769 /* AddObjectToClearPolyUndoList (VIA_TYPE, &(PCB->Data->Layer[i]), via, via, true); not needed? */
1770 ClearFromPolygon (PCB->Data, VIA_TYPE, &(PCB->Data->Layer[i]), via);
1772 DrawVia (via);
1774 change = true;
1777 END_LOOP;
1778 if (change)
1780 Draw ();
1781 IncrementUndoSerialNumber ();
1783 return (change);
1787 * \brief Changes the size of all selected and visible object types.
1789 * \return True if anything has changed.
1791 bool
1792 ChangeSelectedSize (int types, Coord Difference, bool fixIt)
1794 bool change = false;
1796 /* setup identifiers */
1797 Absolute = (fixIt) ? Difference : 0;
1798 Delta = Difference;
1800 change = SelectedOperation (&ChangeSizeFunctions, false, types);
1801 if (change)
1803 Draw ();
1804 IncrementUndoSerialNumber ();
1806 return (change);
1810 * \brief Changes the clearance size of all selected and visible objects.
1812 * \return True if anything has changed.
1814 bool
1815 ChangeSelectedClearSize (int types, Coord Difference, bool fixIt)
1817 bool change = false;
1819 /* setup identifiers */
1820 Absolute = (fixIt) ? Difference : 0;
1821 Delta = Difference;
1822 if (TEST_FLAG (SHOWMASKFLAG, PCB))
1823 change = SelectedOperation (&ChangeMaskSizeFunctions, false, types);
1824 else
1825 change = SelectedOperation (&ChangeClearSizeFunctions, false, types);
1826 if (change)
1828 Draw ();
1829 IncrementUndoSerialNumber ();
1831 return (change);
1835 * \brief Changes the 2nd size (drilling hole) of all selected and
1836 * visible objects.
1838 * \return True if anything has changed.
1840 bool
1841 ChangeSelected2ndSize (int types, Coord Difference, bool fixIt)
1843 bool change = false;
1845 /* setup identifiers */
1846 Absolute = (fixIt) ? Difference : 0;
1847 Delta = Difference;
1848 change = SelectedOperation (&Change2ndSizeFunctions, false, types);
1849 if (change)
1851 Draw ();
1852 IncrementUndoSerialNumber ();
1854 return (change);
1858 * \brief Changes the clearance flag (join) of all selected and visible
1859 * lines and/or arcs.
1861 * \return True if anything has changed.
1863 bool
1864 ChangeSelectedJoin (int types)
1866 bool change = false;
1868 change = SelectedOperation (&ChangeJoinFunctions, false, types);
1869 if (change)
1871 Draw ();
1872 IncrementUndoSerialNumber ();
1874 return (change);
1878 * \brief Changes the clearance flag (join) of all selected and visible
1879 * lines and/or arcs.
1881 * \return True if anything has changed.
1883 bool
1884 SetSelectedJoin (int types)
1886 bool change = false;
1888 change = SelectedOperation (&SetJoinFunctions, false, types);
1889 if (change)
1891 Draw ();
1892 IncrementUndoSerialNumber ();
1894 return (change);
1898 * \brief Changes the clearance flag (join) of all selected and visible
1899 * lines and/or arcs.
1901 * \return True if anything has changed.
1903 bool
1904 ClrSelectedJoin (int types)
1906 bool change = false;
1908 change = SelectedOperation (&ClrJoinFunctions, false, types);
1909 if (change)
1911 Draw ();
1912 IncrementUndoSerialNumber ();
1914 return (change);
1918 * \brief Changes the square-flag of all selected and visible pins or
1919 * pads.
1921 * \return True if anything has changed.
1923 bool
1924 ChangeSelectedSquare (int types)
1926 bool change = false;
1928 change = SelectedOperation (&ChangeSquareFunctions, false, types);
1929 if (change)
1931 Draw ();
1932 IncrementUndoSerialNumber ();
1934 return (change);
1938 * \brief Sets the square-flag of all selected and visible pins or pads.
1940 * \return True if anything has changed.
1942 bool
1943 SetSelectedSquare (int types)
1945 bool change = false;
1947 change = SelectedOperation (&SetSquareFunctions, false, types);
1948 if (change)
1950 Draw ();
1951 IncrementUndoSerialNumber ();
1953 return (change);
1957 * \brief Clears the square-flag of all selected and visible pins or
1958 * pads.
1960 * \return True if anything has changed.
1962 bool
1963 ClrSelectedSquare (int types)
1965 bool change = false;
1967 change = SelectedOperation (&ClrSquareFunctions, false, types);
1968 if (change)
1970 Draw ();
1971 IncrementUndoSerialNumber ();
1973 return (change);
1977 * \brief Changes the octagon-flag of all selected and visible pins and
1978 * vias.
1980 * \return True if anything has changed.
1982 bool
1983 ChangeSelectedOctagon (int types)
1985 bool change = false;
1987 change = SelectedOperation (&ChangeOctagonFunctions, false, types);
1988 if (change)
1990 Draw ();
1991 IncrementUndoSerialNumber ();
1993 return (change);
1997 * \brief Sets the octagon-flag of all selected and visible pins and
1998 * vias.
2000 * \return True if anything has changed.
2002 bool
2003 SetSelectedOctagon (int types)
2005 bool change = false;
2007 change = SelectedOperation (&SetOctagonFunctions, false, types);
2008 if (change)
2010 Draw ();
2011 IncrementUndoSerialNumber ();
2013 return (change);
2017 * \brief Clears the octagon-flag of all selected and visible pins and
2018 * vias.
2020 * \return True if anything has changed.
2022 bool
2023 ClrSelectedOctagon (int types)
2025 bool change = false;
2027 change = SelectedOperation (&ClrOctagonFunctions, false, types);
2028 if (change)
2030 Draw ();
2031 IncrementUndoSerialNumber ();
2033 return (change);
2037 * \brief Changes the hole-flag of all selected and visible vias.
2039 * \return True if anything has changed.
2041 bool
2042 ChangeSelectedHole (void)
2044 bool change = false;
2046 if (PCB->ViaOn)
2047 VIA_LOOP (PCB->Data);
2049 if (TEST_FLAG (SELECTEDFLAG, via))
2050 change |= ChangeHole (via);
2052 END_LOOP;
2053 if (change)
2055 Draw ();
2056 IncrementUndoSerialNumber ();
2058 return (change);
2062 * \brief Changes the no paste-flag of all selected and visible pads.
2064 * \return True if anything has changed.
2066 bool
2067 ChangeSelectedPaste (void)
2069 bool change = false;
2071 ALLPAD_LOOP (PCB->Data);
2073 if (TEST_FLAG (SELECTEDFLAG, pad))
2074 change |= ChangePaste (pad);
2076 ENDALL_LOOP;
2077 if (change)
2079 Draw ();
2080 IncrementUndoSerialNumber ();
2082 return (change);
2087 * \brief Changes the size of the passed object.
2089 * \return True if anything is changed.
2091 bool
2092 ChangeObjectSize (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
2093 Coord Difference, bool fixIt)
2095 bool change;
2097 /* setup identifier */
2098 Absolute = (fixIt) ? Difference : 0;
2099 Delta = Difference;
2100 change =
2101 (ObjectOperation (&ChangeSizeFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL);
2102 if (change)
2104 Draw ();
2105 IncrementUndoSerialNumber ();
2107 return (change);
2111 * \brief Changes the clearance size of the passed object.
2113 * \return True if anything is changed.
2115 bool
2116 ChangeObjectClearSize (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
2117 Coord Difference, bool fixIt)
2119 bool change;
2121 /* setup identifier */
2122 Absolute = (fixIt) ? Difference : 0;
2123 Delta = Difference;
2124 if (TEST_FLAG (SHOWMASKFLAG, PCB))
2125 change =
2126 (ObjectOperation (&ChangeMaskSizeFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2127 NULL);
2128 else
2129 change =
2130 (ObjectOperation (&ChangeClearSizeFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2131 NULL);
2132 if (change)
2134 Draw ();
2135 IncrementUndoSerialNumber ();
2137 return (change);
2141 * \brief Changes the thermal of the passed object.
2143 * \return True if anything is changed.
2146 bool
2147 ChangeObjectThermal (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
2148 int therm_type)
2150 bool change;
2152 Delta = Absolute = therm_type;
2153 change =
2154 (ObjectOperation (&ChangeThermalFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2155 NULL);
2156 if (change)
2158 Draw ();
2159 IncrementUndoSerialNumber ();
2161 return (change);
2165 * \brief Changes the thermal of the passed object.
2167 * \return True if anything is changed.
2170 bool
2171 ChangeObjectViaLayers (void *Ptr1, void *Ptr2, void *Ptr3,
2172 int from, int to)
2174 bool change = false;
2175 PinType *via = (PinType *) Ptr1;
2176 int new_from = (from != -1)?from:via->BuriedFrom;
2177 int new_to = (to != -1)?to:via->BuriedTo;
2178 int i;
2180 if (TEST_FLAG (LOCKFLAG, via))
2181 return (NULL);
2183 if ((new_from == new_to)
2184 && new_from != 0)
2185 return false;
2187 /* special case - changing TH via "from" layer sets "to" layer to bottom layer */
2188 if (!VIA_IS_BURIED (via)
2189 && (to == -1))
2190 new_to = GetMaxBottomLayer ();
2192 for (i=0; i < max_copper_layer; i++)
2194 /* AddObjectToClearPolyUndoList (VIA_TYPE, &(PCB->Data->Layer[i]), via, via, false); not needed? */
2195 RestoreToPolygon (PCB->Data, VIA_TYPE, &(PCB->Data->Layer[i]), via);
2198 if (from != -1 || to != -1)
2200 AddObjectToSetViaLayersUndoList (via, via, via);
2201 change = true;
2204 via->BuriedFrom = new_from;
2205 via->BuriedTo = new_to;
2207 if (VIA_IS_BURIED (via))
2209 SanitizeBuriedVia (via);
2210 for (i=0; i < max_copper_layer; i++)
2212 /* AddObjectToClearPolyUndoList (VIA_TYPE, &(PCB->Data->Layer[i]), via, via, true); not needed? */
2213 ClearFromPolygon (PCB->Data, VIA_TYPE, &(PCB->Data->Layer[i]), via);
2215 DrawVia (via);
2218 if (change)
2220 Draw ();
2221 IncrementUndoSerialNumber ();
2223 return (change);
2227 * \brief Changes the 2nd size of the passed object.
2229 * \return True if anything is changed.
2231 bool
2232 ChangeObject2ndSize (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
2233 Coord Difference, bool fixIt, bool incundo)
2235 bool change;
2237 /* setup identifier */
2238 Absolute = (fixIt) ? Difference : 0;
2239 Delta = Difference;
2240 change =
2241 (ObjectOperation (&Change2ndSizeFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2242 NULL);
2243 if (change)
2245 Draw ();
2246 if (incundo)
2247 IncrementUndoSerialNumber ();
2249 return (change);
2253 * \brief Changes the mask size of the passed object.
2255 * \return True if anything is changed.
2257 bool
2258 ChangeObjectMaskSize (int Type, void *Ptr1, void *Ptr2, void *Ptr3,
2259 Coord Difference, bool fixIt)
2261 bool change;
2263 /* setup identifier */
2264 Absolute = (fixIt) ? Difference : 0;
2265 Delta = Difference;
2266 change =
2267 (ObjectOperation (&ChangeMaskSizeFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2268 NULL);
2269 if (change)
2271 Draw ();
2272 IncrementUndoSerialNumber ();
2274 return (change);
2278 * \brief Changes the name of the passed object.
2280 * \warning The allocated memory isn't freed because the old string is used
2281 * by the undo module.
2283 * \return The old name.
2285 void *
2286 ChangeObjectName (int Type, void *Ptr1, void *Ptr2, void *Ptr3, char *Name)
2288 void *result;
2289 /* setup identifier */
2290 NewName = Name;
2291 result = ObjectOperation (&ChangeNameFunctions, Type, Ptr1, Ptr2, Ptr3);
2292 Draw ();
2293 return (result);
2297 * \brief Changes the clearance-flag of the passed object.
2299 * \return True if anything is changed.
2301 bool
2302 ChangeObjectJoin (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2304 if (ObjectOperation (&ChangeJoinFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2306 Draw ();
2307 IncrementUndoSerialNumber ();
2308 return (true);
2310 return (false);
2314 * \brief Sets the clearance-flag of the passed object.
2316 * \return True if anything is changed.
2318 bool
2319 SetObjectJoin (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2321 if (ObjectOperation (&SetJoinFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2323 Draw ();
2324 IncrementUndoSerialNumber ();
2325 return (true);
2327 return (false);
2331 * \brief Clears the clearance-flag of the passed object.
2333 * \return True if anything is changed.
2335 bool
2336 ClrObjectJoin (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2338 if (ObjectOperation (&ClrJoinFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2340 Draw ();
2341 IncrementUndoSerialNumber ();
2342 return (true);
2344 return (false);
2348 * \brief Changes the square-flag of the passed object.
2350 * \return True if anything is changed.
2352 bool
2353 ChangeObjectSquare (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2355 if (ObjectOperation (&ChangeSquareFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2356 NULL)
2358 Draw ();
2359 IncrementUndoSerialNumber ();
2360 return (true);
2362 return (false);
2366 * \brief Sets the square-flag of the passed object.
2368 * \return True if anything is changed.
2370 bool
2371 SetObjectSquare (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2373 if (ObjectOperation (&SetSquareFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2375 Draw ();
2376 IncrementUndoSerialNumber ();
2377 return (true);
2379 return (false);
2383 * \brief Clears the square-flag of the passed object.
2385 * \return True if anything is changed.
2387 bool
2388 ClrObjectSquare (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2390 if (ObjectOperation (&ClrSquareFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2392 Draw ();
2393 IncrementUndoSerialNumber ();
2394 return (true);
2396 return (false);
2400 * \brief Changes the octagon-flag of the passed object.
2402 * \return True if anything is changed.
2404 bool
2405 ChangeObjectOctagon (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2407 if (ObjectOperation (&ChangeOctagonFunctions, Type, Ptr1, Ptr2, Ptr3) !=
2408 NULL)
2410 Draw ();
2411 IncrementUndoSerialNumber ();
2412 return (true);
2414 return (false);
2418 * \brief Sets the octagon-flag of the passed object.
2420 * \return True if anything is changed.
2422 bool
2423 SetObjectOctagon (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2425 if (ObjectOperation (&SetOctagonFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2427 Draw ();
2428 IncrementUndoSerialNumber ();
2429 return (true);
2431 return (false);
2435 * \brief Clears the octagon-flag of the passed object.
2437 * \return True if anything is changed.
2439 bool
2440 ClrObjectOctagon (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2442 if (ObjectOperation (&ClrOctagonFunctions, Type, Ptr1, Ptr2, Ptr3) != NULL)
2444 Draw ();
2445 IncrementUndoSerialNumber ();
2446 return (true);
2448 return (false);
2452 * \bief Queries the user for a new object name and changes it.
2454 * \warning The allocated memory isn't freed because the old string is used
2455 * by the undo module.
2457 void *
2458 QueryInputAndChangeObjectName (int Type, void *Ptr1, void *Ptr2, void *Ptr3)
2460 char *name = NULL;
2461 char msg[513];
2463 /* if passed an element name, make it an element reference instead */
2464 if (Type == ELEMENTNAME_TYPE)
2466 Type = ELEMENT_TYPE;
2467 Ptr2 = Ptr1;
2468 Ptr3 = Ptr1;
2470 switch (Type)
2472 case LINE_TYPE:
2473 name = gui->prompt_for (_("Linename:"),
2474 EMPTY (((LineType *) Ptr2)->Number));
2475 break;
2477 case VIA_TYPE:
2478 name = gui->prompt_for (_("Vianame:"),
2479 EMPTY (((PinType *) Ptr2)->Name));
2480 break;
2482 case PIN_TYPE:
2483 sprintf (msg, _("%s Pin Name:"), EMPTY (((PinType *) Ptr2)->Number));
2484 name = gui->prompt_for (msg, EMPTY (((PinType *) Ptr2)->Name));
2485 break;
2487 case PAD_TYPE:
2488 sprintf (msg, _("%s Pad Name:"), EMPTY (((PadType *) Ptr2)->Number));
2489 name = gui->prompt_for (msg, EMPTY (((PadType *) Ptr2)->Name));
2490 break;
2492 case TEXT_TYPE:
2493 name = gui->prompt_for (_("Enter text:"),
2494 EMPTY (((TextType *) Ptr2)->TextString));
2495 break;
2497 case ELEMENT_TYPE:
2498 name = gui->prompt_for (_("Elementname:"),
2499 EMPTY (ELEMENT_NAME
2500 (PCB, (ElementType *) Ptr2)));
2501 break;
2503 if (name)
2505 /* NB: ChangeObjectName takes ownership of the passed memory */
2506 char *old = (char *)ChangeObjectName (Type, Ptr1, Ptr2, Ptr3, name);
2507 if (old != (char *) -1)
2509 AddObjectToChangeNameUndoList (Type, Ptr1, Ptr2, Ptr3, old);
2510 IncrementUndoSerialNumber ();
2512 Draw ();
2513 return (Ptr3);
2515 return (NULL);
2519 * \brief Changes the maximum size of a layout, adjusts the scrollbars,
2520 * releases the saved pixmap if necessary and adjusts the cursor
2521 * confinement box.
2523 void
2524 ChangePCBSize (Coord Width, Coord Height)
2526 PCB->MaxWidth = Width;
2527 PCB->MaxHeight = Height;
2529 /* crosshair range is different if pastebuffer-mode
2530 * is enabled
2532 if (Settings.Mode == PASTEBUFFER_MODE)
2533 SetCrosshairRange (PASTEBUFFER->X - PASTEBUFFER->BoundingBox.X1,
2534 PASTEBUFFER->Y - PASTEBUFFER->BoundingBox.Y1,
2535 MAX (0,
2536 Width - (PASTEBUFFER->BoundingBox.X2 -
2537 PASTEBUFFER->X)), MAX (0,
2538 Height -
2539 (PASTEBUFFER->
2540 BoundingBox.Y2 -
2541 PASTEBUFFER->
2542 Y)));
2543 else
2544 SetCrosshairRange (0, 0, Width, Height);
2545 hid_action ("PCBChanged");
2549 * \brief Changes the mask size of a pad.
2551 * \return TRUE if changed.
2553 static void *
2554 ChangePadMaskSize (ElementType *Element, PadType *Pad)
2556 Coord value = (Absolute) ? Absolute : Pad->Mask + Delta;
2558 value = MAX (value, 0);
2559 if (value == Pad->Mask && Absolute == 0)
2560 value = Pad->Thickness;
2561 if (value != Pad->Mask)
2563 AddObjectToMaskSizeUndoList (PAD_TYPE, Element, Pad, Pad);
2564 ErasePad (Pad);
2565 r_delete_entry (PCB->Data->pad_tree, &Pad->BoundingBox);
2566 Pad->Mask = value;
2567 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
2568 DrawPad (Pad);
2569 return (Pad);
2571 return (NULL);
2575 * \brief Changes the mask size of a pin.
2577 * \return TRUE if changed.
2579 static void *
2580 ChangePinMaskSize (ElementType *Element, PinType *Pin)
2582 Coord value = (Absolute) ? Absolute : Pin->Mask + Delta;
2584 value = MAX (value, 0);
2585 if (value == Pin->Mask && Absolute == 0)
2586 value = Pin->Thickness;
2587 if (value != Pin->Mask)
2589 AddObjectToMaskSizeUndoList (PIN_TYPE, Element, Pin, Pin);
2590 ErasePin (Pin);
2591 r_delete_entry (PCB->Data->pin_tree, &Pin->BoundingBox);
2592 Pin->Mask = value;
2593 SetElementBoundingBox (PCB->Data, Element, &PCB->Font);
2594 DrawPin (Pin);
2595 return (Pin);
2597 return (NULL);
2601 * \brief Changes the mask size of a via.
2603 * \return TRUE if changed.
2605 static void *
2606 ChangeViaMaskSize (PinType *Via)
2608 Coord value;
2610 value = (Absolute) ? Absolute : Via->Mask + Delta;
2611 value = MAX (value, 0);
2612 if (value != Via->Mask)
2614 AddObjectToMaskSizeUndoList (VIA_TYPE, Via, Via, Via);
2615 EraseVia (Via);
2616 r_delete_entry (PCB->Data->via_tree, &Via->BoundingBox);
2617 Via->Mask = value;
2618 SetPinBoundingBox (Via);
2619 r_insert_entry (PCB->Data->via_tree, &Via->BoundingBox, 0);
2620 DrawVia (Via);
2621 return (Via);
2623 return (NULL);