action.c: UpdatePackage() reloads from disk
[geda-pcb/whiteaudio.git] / src / create.c
blob9ed7caa7b152af492aa5f49e58ab1818d1dc5661
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 create vias, pins ...
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
34 #include <assert.h>
35 #include <memory.h>
36 #include <setjmp.h>
37 #include <stdlib.h>
39 #include "global.h"
41 #include "create.h"
42 #include "data.h"
43 #include "draw.h"
44 #include "error.h"
45 #include "mymem.h"
46 #include "misc.h"
47 #include "parse_l.h"
48 #include "pcb-printf.h"
49 #include "polygon.h"
50 #include "rtree.h"
51 #include "search.h"
52 #include "set.h"
53 #include "undo.h"
54 #include "vendor.h"
56 #ifdef HAVE_LIBDMALLOC
57 #include <dmalloc.h>
58 #endif
60 /* ---------------------------------------------------------------------------
61 * some local identifiers
63 static int ID = 1; /* current object ID; incremented after */
64 /* each creation of an object */
66 static bool be_lenient = false;
68 /* ----------------------------------------------------------------------
69 * some local prototypes
71 static void AddTextToElement (TextType *, FontType *,
72 Coord, Coord, unsigned, char *, int,
73 FlagType);
75 /* ---------------------------------------------------------------------------
76 * Set the lenience mode.
79 void
80 CreateBeLenient (bool v)
82 be_lenient = v;
85 /* ---------------------------------------------------------------------------
86 * creates a new paste buffer
88 DataType *
89 CreateNewBuffer (void)
91 DataType *data;
92 data = (DataType *) calloc (1, sizeof (DataType));
93 data->pcb = (PCBType *) PCB;
94 return data;
97 /* ---------------------------------------------------------------------------
98 * Perhaps PCB should internally just use the Settings colors? For now,
99 * use this to set PCB colors so the config can reassign PCB colors.
101 void
102 pcb_colors_from_settings (PCBType *ptr)
104 int i;
106 /* copy default settings */
107 ptr->ConnectedColor = Settings.ConnectedColor;
108 ptr->ElementColor = Settings.ElementColor;
109 ptr->RatColor = Settings.RatColor;
110 ptr->InvisibleObjectsColor = Settings.InvisibleObjectsColor;
111 ptr->InvisibleMarkColor = Settings.InvisibleMarkColor;
112 ptr->ElementSelectedColor = Settings.ElementSelectedColor;
113 ptr->RatSelectedColor = Settings.RatSelectedColor;
114 ptr->PinColor = Settings.PinColor;
115 ptr->PinSelectedColor = Settings.PinSelectedColor;
116 ptr->PinNameColor = Settings.PinNameColor;
117 ptr->ViaColor = Settings.ViaColor;
118 ptr->ViaSelectedColor = Settings.ViaSelectedColor;
119 ptr->WarnColor = Settings.WarnColor;
120 ptr->MaskColor = Settings.MaskColor;
121 for (i = 0; i < MAX_LAYER; i++)
123 ptr->Data->Layer[i].Color = Settings.LayerColor[i];
124 ptr->Data->Layer[i].SelectedColor = Settings.LayerSelectedColor[i];
126 ptr->Data->Layer[component_silk_layer].Color =
127 Settings.ShowSolderSide ?
128 Settings.InvisibleObjectsColor : Settings.ElementColor;
129 ptr->Data->Layer[component_silk_layer].SelectedColor =
130 Settings.ElementSelectedColor;
131 ptr->Data->Layer[solder_silk_layer].Color =
132 Settings.ShowSolderSide ?
133 Settings.ElementColor : Settings.InvisibleObjectsColor;
134 ptr->Data->Layer[solder_silk_layer].SelectedColor =
135 Settings.ElementSelectedColor;
138 /* ---------------------------------------------------------------------------
139 * creates a new PCB
141 PCBType *
142 CreateNewPCB (bool SetDefaultNames)
144 PCBType *ptr;
145 int i;
147 /* allocate memory, switch all layers on and copy resources */
148 ptr = (PCBType *)calloc (1, sizeof (PCBType));
149 ptr->Data = CreateNewBuffer ();
150 ptr->Data->pcb = (PCBType *) ptr;
151 ptr->Data->polyClip = 1;
153 ptr->ThermStyle = 4;
154 ptr->IsleArea = 2.e8;
155 ptr->SilkActive = false;
156 ptr->RatDraw = false;
157 SET_FLAG (NAMEONPCBFLAG, ptr);
158 if (Settings.ShowNumber)
159 SET_FLAG (SHOWNUMBERFLAG, ptr);
160 if (Settings.AllDirectionLines)
161 SET_FLAG (ALLDIRECTIONFLAG, ptr);
162 ptr->Clipping = 1; /* this is the most useful starting point for now */
163 if (Settings.RubberBandMode)
164 SET_FLAG (RUBBERBANDFLAG, ptr);
165 if (Settings.SwapStartDirection)
166 SET_FLAG (SWAPSTARTDIRFLAG, ptr);
167 if (Settings.UniqueNames)
168 SET_FLAG (UNIQUENAMEFLAG, ptr);
169 if (Settings.SnapPin)
170 SET_FLAG (SNAPPINFLAG, ptr);
171 if (Settings.ClearLine)
172 SET_FLAG (CLEARNEWFLAG, ptr);
173 if (Settings.FullPoly)
174 SET_FLAG (NEWFULLPOLYFLAG, ptr);
175 if (Settings.OrthogonalMoves)
176 SET_FLAG (ORTHOMOVEFLAG, ptr);
177 if (Settings.liveRouting)
178 SET_FLAG (LIVEROUTEFLAG, ptr);
179 if (Settings.ShowDRC)
180 SET_FLAG (SHOWDRCFLAG, ptr);
181 if (Settings.AutoDRC)
182 SET_FLAG (AUTODRCFLAG, ptr);
183 ptr->Grid = Settings.Grid;
184 ptr->LayerGroups = Settings.LayerGroups;
185 STYLE_LOOP (ptr);
187 *style = Settings.RouteStyle[n];
188 style->index = n;
190 END_LOOP;
191 ptr->Zoom = Settings.Zoom;
192 ptr->MaxWidth = Settings.MaxWidth;
193 ptr->MaxHeight = Settings.MaxHeight;
194 ptr->ID = ID++;
195 ptr->ThermScale = 0.5;
197 ptr->Bloat = Settings.Bloat;
198 ptr->Shrink = Settings.Shrink;
199 ptr->minWid = Settings.minWid;
200 ptr->minSlk = Settings.minSlk;
201 ptr->minDrill = Settings.minDrill;
202 ptr->minRing = Settings.minRing;
204 for (i = 0; i < MAX_LAYER; i++)
205 ptr->Data->Layer[i].Name = strdup (Settings.DefaultLayerName[i]);
207 CreateDefaultFont (ptr);
209 return (ptr);
212 /* This post-processing step adds the top and bottom silk layers to a
213 * pre-existing PCB.
216 CreateNewPCBPost (PCBType *pcb, int use_defaults)
218 /* copy default settings */
219 pcb_colors_from_settings (pcb);
221 if (use_defaults)
223 if (ParseGroupString (Settings.Groups, &pcb->LayerGroups, DEF_LAYER))
224 return 1;
226 pcb->Data->Layer[component_silk_layer].Name = strdup ("silk");
227 pcb->Data->Layer[solder_silk_layer].Name = strdup ("silk");
229 return 0;
232 /* ---------------------------------------------------------------------------
233 * creates a new via
235 PinType *
236 CreateNewVia (DataType *Data,
237 Coord X, Coord Y,
238 Coord Thickness, Coord Clearance, Coord Mask,
239 Coord DrillingHole, char *Name, FlagType Flags)
241 PinType *Via;
243 if (!be_lenient)
245 VIA_LOOP (Data);
247 if (Distance (X, Y, via->X, via->Y) <=
248 via->DrillingHole / 2 + DrillingHole / 2)
250 Message (_("%m+Dropping via at %$mD because it's hole would overlap with the via "
251 "at %$mD\n"), Settings.grid_unit->allow, X, Y, via->X, via->Y);
252 return (NULL); /* don't allow via stacking */
255 END_LOOP;
258 Via = GetViaMemory (Data);
260 if (!Via)
261 return (Via);
262 /* copy values */
263 Via->X = X;
264 Via->Y = Y;
265 Via->Thickness = Thickness;
266 Via->Clearance = Clearance;
267 Via->Mask = Mask;
268 Via->DrillingHole = vendorDrillMap (DrillingHole);
269 if (Via->DrillingHole != DrillingHole)
271 Message (_("%m+Mapped via drill hole to %$mS from %$mS per vendor table\n"),
272 Settings.grid_unit->allow, Via->DrillingHole, DrillingHole);
275 Via->Name = STRDUP (Name);
276 Via->Flags = Flags;
277 CLEAR_FLAG (WARNFLAG, Via);
278 SET_FLAG (VIAFLAG, Via);
279 Via->ID = ID++;
282 * don't complain about MIN_PINORVIACOPPER on a mounting hole (pure
283 * hole)
285 if (!TEST_FLAG (HOLEFLAG, Via) &&
286 (Via->Thickness < Via->DrillingHole + MIN_PINORVIACOPPER))
288 Via->Thickness = Via->DrillingHole + MIN_PINORVIACOPPER;
289 Message (_("%m+Increased via thickness to %$mS to allow enough copper"
290 " at %$mD.\n"),
291 Settings.grid_unit->allow, Via->Thickness, Via->X, Via->Y);
294 SetPinBoundingBox (Via);
295 if (!Data->via_tree)
296 Data->via_tree = r_create_tree (NULL, 0, 0);
297 r_insert_entry (Data->via_tree, (BoxType *) Via, 0);
298 return (Via);
301 struct line_info
303 Coord X1, X2, Y1, Y2;
304 Coord Thickness;
305 FlagType Flags;
306 LineType test, *ans;
307 jmp_buf env;
310 static int
311 line_callback (const BoxType * b, void *cl)
313 LineType *line = (LineType *) b;
314 struct line_info *i = (struct line_info *) cl;
316 if (line->Point1.X == i->X1 &&
317 line->Point2.X == i->X2 &&
318 line->Point1.Y == i->Y1 && line->Point2.Y == i->Y2)
320 i->ans = (LineType *) (-1);
321 longjmp (i->env, 1);
323 /* check the other point order */
324 if (line->Point1.X == i->X1 &&
325 line->Point2.X == i->X2 &&
326 line->Point1.Y == i->Y1 && line->Point2.Y == i->Y2)
328 i->ans = (LineType *) (-1);
329 longjmp (i->env, 1);
331 if (line->Point2.X == i->X1 &&
332 line->Point1.X == i->X2 &&
333 line->Point2.Y == i->Y1 && line->Point1.Y == i->Y2)
335 i->ans = (LineType *) - 1;
336 longjmp (i->env, 1);
338 /* remove unnecessary line points */
339 if (line->Thickness == i->Thickness
340 /* don't merge lines if the clear flags differ */
341 && TEST_FLAG (CLEARLINEFLAG, line) == TEST_FLAG (CLEARLINEFLAG, i))
343 if (line->Point1.X == i->X1 && line->Point1.Y == i->Y1)
345 i->test.Point1.X = line->Point2.X;
346 i->test.Point1.Y = line->Point2.Y;
347 i->test.Point2.X = i->X2;
348 i->test.Point2.Y = i->Y2;
349 if (IsPointOnLine (i->X1, i->Y1, 0.0, &i->test))
351 i->ans = line;
352 longjmp (i->env, 1);
355 else if (line->Point2.X == i->X1 && line->Point2.Y == i->Y1)
357 i->test.Point1.X = line->Point1.X;
358 i->test.Point1.Y = line->Point1.Y;
359 i->test.Point2.X = i->X2;
360 i->test.Point2.Y = i->Y2;
361 if (IsPointOnLine (i->X1, i->Y1, 0.0, &i->test))
363 i->ans = line;
364 longjmp (i->env, 1);
367 else if (line->Point1.X == i->X2 && line->Point1.Y == i->Y2)
369 i->test.Point1.X = line->Point2.X;
370 i->test.Point1.Y = line->Point2.Y;
371 i->test.Point2.X = i->X1;
372 i->test.Point2.Y = i->Y1;
373 if (IsPointOnLine (i->X2, i->Y2, 0.0, &i->test))
375 i->ans = line;
376 longjmp (i->env, 1);
379 else if (line->Point2.X == i->X2 && line->Point2.Y == i->Y2)
381 i->test.Point1.X = line->Point1.X;
382 i->test.Point1.Y = line->Point1.Y;
383 i->test.Point2.X = i->X1;
384 i->test.Point2.Y = i->Y1;
385 if (IsPointOnLine (i->X2, i->Y2, 0.0, &i->test))
387 i->ans = line;
388 longjmp (i->env, 1);
392 return 0;
396 /* ---------------------------------------------------------------------------
397 * creates a new line on a layer and checks for overlap and extension
399 LineType *
400 CreateDrawnLineOnLayer (LayerType *Layer,
401 Coord X1, Coord Y1,
402 Coord X2, Coord Y2,
403 Coord Thickness, Coord Clearance,
404 FlagType Flags)
406 struct line_info info;
407 BoxType search;
409 search.X1 = MIN (X1, X2);
410 search.X2 = MAX (X1, X2);
411 search.Y1 = MIN (Y1, Y2);
412 search.Y2 = MAX (Y1, Y2);
413 if (search.Y2 == search.Y1)
414 search.Y2++;
415 if (search.X2 == search.X1)
416 search.X2++;
417 info.X1 = X1;
418 info.X2 = X2;
419 info.Y1 = Y1;
420 info.Y2 = Y2;
421 info.Thickness = Thickness;
422 info.Flags = Flags;
423 info.test.Thickness = 0;
424 info.test.Flags = NoFlags ();
425 info.ans = NULL;
426 /* prevent stacking of duplicate lines
427 * and remove needless intermediate points
428 * verify that the layer is on the board first!
430 if (setjmp (info.env) == 0)
432 r_search (Layer->line_tree, &search, NULL, line_callback, &info);
433 return CreateNewLineOnLayer (Layer, X1, Y1, X2, Y2,
434 Thickness, Clearance, Flags);
437 if ((void *) info.ans == (void *) (-1))
438 return NULL; /* stacked line */
439 /* remove unnecessary points */
440 if (info.ans)
442 /* must do this BEFORE getting new line memory */
443 MoveObjectToRemoveUndoList (LINE_TYPE, Layer, info.ans, info.ans);
444 X1 = info.test.Point1.X;
445 X2 = info.test.Point2.X;
446 Y1 = info.test.Point1.Y;
447 Y2 = info.test.Point2.Y;
449 return CreateNewLineOnLayer (Layer, X1, Y1, X2, Y2,
450 Thickness, Clearance, Flags);
453 LineType *
454 CreateNewLineOnLayer (LayerType *Layer,
455 Coord X1, Coord Y1,
456 Coord X2, Coord Y2,
457 Coord Thickness, Coord Clearance,
458 FlagType Flags)
460 LineType *Line;
462 Line = GetLineMemory (Layer);
463 if (!Line)
464 return (Line);
465 Line->ID = ID++;
466 Line->Flags = Flags;
467 CLEAR_FLAG (RATFLAG, Line);
468 Line->Thickness = Thickness;
469 Line->Clearance = Clearance;
470 Line->Point1.X = X1;
471 Line->Point1.Y = Y1;
472 Line->Point1.ID = ID++;
473 Line->Point2.X = X2;
474 Line->Point2.Y = Y2;
475 Line->Point2.ID = ID++;
476 SetLineBoundingBox (Line);
477 if (!Layer->line_tree)
478 Layer->line_tree = r_create_tree (NULL, 0, 0);
479 r_insert_entry (Layer->line_tree, (BoxType *) Line, 0);
480 return (Line);
483 /* ---------------------------------------------------------------------------
484 * creates a new rat-line
486 RatType *
487 CreateNewRat (DataType *Data, Coord X1, Coord Y1,
488 Coord X2, Coord Y2, Cardinal group1,
489 Cardinal group2, Coord Thickness, FlagType Flags)
491 RatType *Line = GetRatMemory (Data);
493 if (!Line)
494 return (Line);
496 Line->ID = ID++;
497 Line->Flags = Flags;
498 SET_FLAG (RATFLAG, Line);
499 Line->Thickness = Thickness;
500 Line->Point1.X = X1;
501 Line->Point1.Y = Y1;
502 Line->Point1.ID = ID++;
503 Line->Point2.X = X2;
504 Line->Point2.Y = Y2;
505 Line->Point2.ID = ID++;
506 Line->group1 = group1;
507 Line->group2 = group2;
508 SetLineBoundingBox ((LineType *) Line);
509 if (!Data->rat_tree)
510 Data->rat_tree = r_create_tree (NULL, 0, 0);
511 r_insert_entry (Data->rat_tree, &Line->BoundingBox, 0);
512 return (Line);
515 /* ---------------------------------------------------------------------------
516 * creates a new arc on a layer
518 ArcType *
519 CreateNewArcOnLayer (LayerType *Layer,
520 Coord X1, Coord Y1,
521 Coord width,
522 Coord height,
523 Angle sa,
524 Angle dir, Coord Thickness,
525 Coord Clearance, FlagType Flags)
527 ArcType *Arc;
529 ARC_LOOP (Layer);
531 if (arc->X == X1 && arc->Y == Y1 && arc->Width == width &&
532 NormalizeAngle (arc->StartAngle) == NormalizeAngle (sa) &&
533 arc->Delta == dir)
534 return (NULL); /* prevent stacked arcs */
536 END_LOOP;
537 Arc = GetArcMemory (Layer);
538 if (!Arc)
539 return (Arc);
541 Arc->ID = ID++;
542 Arc->Flags = Flags;
543 Arc->Thickness = Thickness;
544 Arc->Clearance = Clearance;
545 Arc->X = X1;
546 Arc->Y = Y1;
547 Arc->Width = width;
548 Arc->Height = height;
549 Arc->StartAngle = sa;
550 Arc->Delta = dir;
551 SetArcBoundingBox (Arc);
552 if (!Layer->arc_tree)
553 Layer->arc_tree = r_create_tree (NULL, 0, 0);
554 r_insert_entry (Layer->arc_tree, (BoxType *) Arc, 0);
555 return (Arc);
559 /* ---------------------------------------------------------------------------
560 * creates a new polygon from the old formats rectangle data
562 PolygonType *
563 CreateNewPolygonFromRectangle (LayerType *Layer,
564 Coord X1, Coord Y1,
565 Coord X2, Coord Y2,
566 FlagType Flags)
568 PolygonType *polygon = CreateNewPolygon (Layer, Flags);
569 if (!polygon)
570 return (polygon);
572 CreateNewPointInPolygon (polygon, X1, Y1);
573 CreateNewPointInPolygon (polygon, X2, Y1);
574 CreateNewPointInPolygon (polygon, X2, Y2);
575 CreateNewPointInPolygon (polygon, X1, Y2);
576 SetPolygonBoundingBox (polygon);
577 if (!Layer->polygon_tree)
578 Layer->polygon_tree = r_create_tree (NULL, 0, 0);
579 r_insert_entry (Layer->polygon_tree, (BoxType *) polygon, 0);
580 return (polygon);
583 /* ---------------------------------------------------------------------------
584 * creates a new text on a layer
586 TextType *
587 CreateNewText (LayerType *Layer, FontType *PCBFont,
588 Coord X, Coord Y,
589 unsigned Direction, int Scale, char *TextString, FlagType Flags)
591 TextType *text;
593 if (TextString == NULL)
594 return NULL;
596 text = GetTextMemory (Layer);
597 if (text == NULL)
598 return NULL;
600 /* copy values, width and height are set by drawing routine
601 * because at this point we don't know which symbols are available
603 text->X = X;
604 text->Y = Y;
605 text->Direction = Direction;
606 text->Flags = Flags;
607 text->Scale = Scale;
608 text->TextString = strdup (TextString);
610 /* calculate size of the bounding box */
611 SetTextBoundingBox (PCBFont, text);
612 text->ID = ID++;
613 if (!Layer->text_tree)
614 Layer->text_tree = r_create_tree (NULL, 0, 0);
615 r_insert_entry (Layer->text_tree, (BoxType *) text, 0);
616 return (text);
619 /* ---------------------------------------------------------------------------
620 * creates a new polygon on a layer
622 PolygonType *
623 CreateNewPolygon (LayerType *Layer, FlagType Flags)
625 PolygonType *polygon = GetPolygonMemory (Layer);
627 /* copy values */
628 polygon->Flags = Flags;
629 polygon->ID = ID++;
630 polygon->Clipped = NULL;
631 polygon->NoHoles = NULL;
632 polygon->NoHolesValid = 0;
633 return (polygon);
636 /* ---------------------------------------------------------------------------
637 * creates a new point in a polygon
639 PointType *
640 CreateNewPointInPolygon (PolygonType *Polygon, Coord X, Coord Y)
642 PointType *point = GetPointMemoryInPolygon (Polygon);
644 /* copy values */
645 point->X = X;
646 point->Y = Y;
647 point->ID = ID++;
648 return (point);
651 /* ---------------------------------------------------------------------------
652 * creates a new hole in a polygon
654 PolygonType *
655 CreateNewHoleInPolygon (PolygonType *Polygon)
657 Cardinal *holeindex = GetHoleIndexMemoryInPolygon (Polygon);
658 *holeindex = Polygon->PointN;
659 return Polygon;
662 /* ---------------------------------------------------------------------------
663 * creates an new element
664 * memory is allocated if needed
666 ElementType *
667 CreateNewElement (DataType *Data, ElementType *Element,
668 FontType *PCBFont,
669 FlagType Flags,
670 char *Description, char *NameOnPCB, char *Value,
671 Coord TextX, Coord TextY, BYTE Direction,
672 int TextScale, FlagType TextFlags, bool uniqueName)
674 #ifdef DEBUG
675 printf("Entered CreateNewElement.....\n");
676 #endif
678 if (!Element)
679 Element = GetElementMemory (Data);
681 /* copy values and set additional information */
682 TextScale = MAX (MIN_TEXTSCALE, TextScale);
683 AddTextToElement (&DESCRIPTION_TEXT (Element), PCBFont, TextX, TextY,
684 Direction, Description, TextScale, TextFlags);
685 if (uniqueName)
686 NameOnPCB = UniqueElementName (Data, NameOnPCB);
687 AddTextToElement (&NAMEONPCB_TEXT (Element), PCBFont, TextX, TextY,
688 Direction, NameOnPCB, TextScale, TextFlags);
689 AddTextToElement (&VALUE_TEXT (Element), PCBFont, TextX, TextY,
690 Direction, Value, TextScale, TextFlags);
691 DESCRIPTION_TEXT (Element).Element = Element;
692 NAMEONPCB_TEXT (Element).Element = Element;
693 VALUE_TEXT (Element).Element = Element;
694 Element->Flags = Flags;
695 Element->ID = ID++;
697 #ifdef DEBUG
698 printf(" .... Leaving CreateNewElement.\n");
699 #endif
701 return (Element);
704 /* ---------------------------------------------------------------------------
705 * creates a new arc in an element
707 ArcType *
708 CreateNewArcInElement (ElementType *Element,
709 Coord X, Coord Y,
710 Coord Width, Coord Height,
711 Angle angle, Angle delta, Coord Thickness)
713 ArcType *arc;
715 arc = g_slice_new0 (ArcType);
716 Element->Arc = g_list_append (Element->Arc, arc);
717 Element->ArcN ++;
719 /* set Delta (0,360], StartAngle in [0,360) */
720 if (delta < 0)
722 delta = -delta;
723 angle -= delta;
725 angle = NormalizeAngle (angle);
726 delta = NormalizeAngle (delta);
727 if (delta == 0)
728 delta = 360;
730 /* copy values */
731 arc->X = X;
732 arc->Y = Y;
733 arc->Width = Width;
734 arc->Height = Height;
735 arc->StartAngle = angle;
736 arc->Delta = delta;
737 arc->Thickness = Thickness;
738 arc->ID = ID++;
739 return arc;
742 /* ---------------------------------------------------------------------------
743 * creates a new line for an element
745 LineType *
746 CreateNewLineInElement (ElementType *Element,
747 Coord X1, Coord Y1,
748 Coord X2, Coord Y2,
749 Coord Thickness)
751 LineType *line;
753 if (Thickness == 0)
754 return NULL;
756 line = g_slice_new0 (LineType);
757 Element->Line = g_list_append (Element->Line, line);
758 Element->LineN ++;
760 /* copy values */
761 line->Point1.X = X1;
762 line->Point1.Y = Y1;
763 line->Point2.X = X2;
764 line->Point2.Y = Y2;
765 line->Thickness = Thickness;
766 line->Flags = NoFlags ();
767 line->ID = ID++;
768 return line;
771 /* ---------------------------------------------------------------------------
772 * creates a new pin in an element
774 PinType *
775 CreateNewPin (ElementType *Element,
776 Coord X, Coord Y,
777 Coord Thickness, Coord Clearance, Coord Mask,
778 Coord DrillingHole, char *Name, char *Number,
779 FlagType Flags)
781 PinType *pin = GetPinMemory (Element);
783 /* copy values */
784 pin->X = X;
785 pin->Y = Y;
786 pin->Thickness = Thickness;
787 pin->Clearance = Clearance;
788 pin->Mask = Mask;
789 pin->Name = STRDUP (Name);
790 pin->Number = STRDUP (Number);
791 pin->Flags = Flags;
792 CLEAR_FLAG (WARNFLAG, pin);
793 SET_FLAG (PINFLAG, pin);
794 pin->ID = ID++;
795 pin->Element = Element;
798 * If there is no vendor drill map installed, this will simply
799 * return DrillingHole.
801 pin->DrillingHole = vendorDrillMap (DrillingHole);
803 /* Unless we should not map drills on this element, map them! */
804 if (vendorIsElementMappable (Element))
806 if (pin->DrillingHole < MIN_PINORVIASIZE)
808 Message (_("%m+Did not map pin #%s (%s) drill hole because %$mS is below the minimum allowed size\n"),
809 Settings.grid_unit->allow, UNKNOWN (Number), UNKNOWN (Name), pin->DrillingHole);
810 pin->DrillingHole = DrillingHole;
812 else if (pin->DrillingHole > MAX_PINORVIASIZE)
814 Message (_("%m+Did not map pin #%s (%s) drill hole because %$mS is above the maximum allowed size\n"),
815 Settings.grid_unit->allow, UNKNOWN (Number), UNKNOWN (Name), pin->DrillingHole);
816 pin->DrillingHole = DrillingHole;
818 else if (!TEST_FLAG (HOLEFLAG, pin)
819 && (pin->DrillingHole > pin->Thickness - MIN_PINORVIACOPPER))
821 Message (_("%m+Did not map pin #%s (%s) drill hole because %$mS does not leave enough copper\n"),
822 Settings.grid_unit->allow, UNKNOWN (Number), UNKNOWN (Name), pin->DrillingHole);
823 pin->DrillingHole = DrillingHole;
826 else
828 pin->DrillingHole = DrillingHole;
831 if (pin->DrillingHole != DrillingHole)
833 Message (_("%m+Mapped pin drill hole to %$mS from %$mS per vendor table\n"),
834 Settings.grid_unit->allow, pin->DrillingHole, DrillingHole);
837 return (pin);
840 /* ---------------------------------------------------------------------------
841 * creates a new pad in an element
843 PadType *
844 CreateNewPad (ElementType *Element,
845 Coord X1, Coord Y1, Coord X2,
846 Coord Y2, Coord Thickness, Coord Clearance,
847 Coord Mask, char *Name, char *Number, FlagType Flags)
849 PadType *pad = GetPadMemory (Element);
851 /* copy values */
852 if (X1 > X2 || (X1 == X2 && Y1 > Y2))
854 pad->Point1.X = X2;
855 pad->Point1.Y = Y2;
856 pad->Point2.X = X1;
857 pad->Point2.Y = Y1;
859 else
861 pad->Point1.X = X1;
862 pad->Point1.Y = Y1;
863 pad->Point2.X = X2;
864 pad->Point2.Y = Y2;
866 pad->Thickness = Thickness;
867 pad->Clearance = Clearance;
868 pad->Mask = Mask;
869 pad->Name = STRDUP (Name);
870 pad->Number = STRDUP (Number);
871 pad->Flags = Flags;
872 CLEAR_FLAG (WARNFLAG, pad);
873 pad->ID = ID++;
874 pad->Element = Element;
875 return (pad);
878 /* ---------------------------------------------------------------------------
879 * creates a new textobject as part of an element
880 * copies the values to the appropriate text object
882 static void
883 AddTextToElement (TextType *Text, FontType *PCBFont,
884 Coord X, Coord Y,
885 unsigned Direction, char *TextString, int Scale, FlagType Flags)
887 free (Text->TextString);
888 Text->TextString = (TextString && *TextString) ? strdup (TextString) : NULL;
889 Text->X = X;
890 Text->Y = Y;
891 Text->Direction = Direction;
892 Text->Flags = Flags;
893 Text->Scale = Scale;
895 /* calculate size of the bounding box */
896 SetTextBoundingBox (PCBFont, Text);
897 Text->ID = ID++;
900 /* ---------------------------------------------------------------------------
901 * creates a new line in a symbol
903 LineType *
904 CreateNewLineInSymbol (SymbolType *Symbol,
905 Coord X1, Coord Y1,
906 Coord X2, Coord Y2, Coord Thickness)
908 LineType *line = Symbol->Line;
910 /* realloc new memory if necessary and clear it */
911 if (Symbol->LineN >= Symbol->LineMax)
913 Symbol->LineMax += STEP_SYMBOLLINE;
914 line = (LineType *)realloc (line, Symbol->LineMax * sizeof (LineType));
915 Symbol->Line = line;
916 memset (line + Symbol->LineN, 0, STEP_SYMBOLLINE * sizeof (LineType));
919 /* copy values */
920 line = line + Symbol->LineN++;
921 line->Point1.X = X1;
922 line->Point1.Y = Y1;
923 line->Point2.X = X2;
924 line->Point2.Y = Y2;
925 line->Thickness = Thickness;
926 return (line);
929 /* ---------------------------------------------------------------------------
930 * parses a file with font information and installs it into the provided PCB
931 * checks directories given as colon separated list by resource fontPath
932 * if the fonts filename doesn't contain a directory component
934 void
935 CreateDefaultFont (PCBType *pcb)
937 if (ParseFont (&pcb->Font, Settings.FontFile))
938 Message (_("Can't find font-symbol-file '%s'\n"), Settings.FontFile);
941 /* ---------------------------------------------------------------------------
942 * adds a new line to the rubberband list of 'Crosshair.AttachedObject'
943 * if Layer == 0 it is a rat line
945 RubberbandType *
946 CreateNewRubberbandEntry (LayerType *Layer,
947 LineType *Line, PointType *MovedPoint)
949 RubberbandType *ptr = GetRubberbandMemory ();
951 /* we toggle the RUBBERENDFLAG of the line to determine if */
952 /* both points are being moved. */
953 TOGGLE_FLAG (RUBBERENDFLAG, Line);
954 ptr->Layer = Layer;
955 ptr->Line = Line;
956 ptr->MovedPoint = MovedPoint;
957 return (ptr);
960 /* ---------------------------------------------------------------------------
961 * Add a new net to the netlist menu
963 LibraryMenuType *
964 CreateNewNet (LibraryType *lib, char *name, char *style)
966 LibraryMenuType *menu;
967 char temp[64];
969 sprintf (temp, " %s", name);
970 menu = GetLibraryMenuMemory (lib);
971 menu->Name = strdup (temp);
972 menu->flag = 1; /* net is enabled by default */
973 if (style == NULL || NSTRCMP ("(unknown)", style) == 0)
974 menu->Style = NULL;
975 else
976 menu->Style = strdup (style);
977 return (menu);
980 /* ---------------------------------------------------------------------------
981 * Add a connection to the net
983 LibraryEntryType *
984 CreateNewConnection (LibraryMenuType *net, char *conn)
986 LibraryEntryType *entry = GetLibraryEntryMemory (net);
988 entry->ListEntry = STRDUP (conn);
989 return (entry);
992 /* ---------------------------------------------------------------------------
993 * Add an attribute to a list.
995 AttributeType *
996 CreateNewAttribute (AttributeListType *list, char *name, char *value)
998 if (list->Number >= list->Max)
1000 list->Max += 10;
1001 list->List = (AttributeType *)realloc (list->List, list->Max * sizeof (AttributeType));
1003 list->List[list->Number].name = STRDUP (name);
1004 list->List[list->Number].value = STRDUP (value);
1005 list->Number++;
1006 return &list->List[list->Number - 1];