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 ...
48 #include "pcb-printf.h"
56 #ifdef HAVE_LIBDMALLOC
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,
75 /* ---------------------------------------------------------------------------
76 * Set the lenience mode.
80 CreateBeLenient (bool v
)
85 /* ---------------------------------------------------------------------------
86 * creates a new paste buffer
89 CreateNewBuffer (void)
92 data
= (DataType
*) calloc (1, sizeof (DataType
));
93 data
->pcb
= (PCBType
*) PCB
;
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.
102 pcb_colors_from_settings (PCBType
*ptr
)
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 /* ---------------------------------------------------------------------------
142 CreateNewPCB (bool SetDefaultNames
)
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;
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
;
187 *style
= Settings
.RouteStyle
[n
];
191 ptr
->MaxWidth
= Settings
.MaxWidth
;
192 ptr
->MaxHeight
= Settings
.MaxHeight
;
194 ptr
->ThermScale
= 0.5;
196 ptr
->Bloat
= Settings
.Bloat
;
197 ptr
->Shrink
= Settings
.Shrink
;
198 ptr
->minWid
= Settings
.minWid
;
199 ptr
->minSlk
= Settings
.minSlk
;
200 ptr
->minDrill
= Settings
.minDrill
;
201 ptr
->minRing
= Settings
.minRing
;
203 for (i
= 0; i
< MAX_LAYER
; i
++)
204 ptr
->Data
->Layer
[i
].Name
= strdup (Settings
.DefaultLayerName
[i
]);
206 CreateDefaultFont (ptr
);
211 /* This post-processing step adds the top and bottom silk layers to a
215 CreateNewPCBPost (PCBType
*pcb
, int use_defaults
)
217 /* copy default settings */
218 pcb_colors_from_settings (pcb
);
222 if (ParseGroupString (Settings
.Groups
, &pcb
->LayerGroups
, DEF_LAYER
))
225 pcb
->Data
->Layer
[component_silk_layer
].Name
= strdup ("silk");
226 pcb
->Data
->Layer
[solder_silk_layer
].Name
= strdup ("silk");
231 /* ---------------------------------------------------------------------------
235 CreateNewVia (DataType
*Data
,
237 Coord Thickness
, Coord Clearance
, Coord Mask
,
238 Coord DrillingHole
, char *Name
, FlagType Flags
)
246 if (Distance (X
, Y
, via
->X
, via
->Y
) <=
247 via
->DrillingHole
/ 2 + DrillingHole
/ 2)
249 Message (_("%m+Dropping via at %$mD because it's hole would overlap with the via "
250 "at %$mD\n"), Settings
.grid_unit
->allow
, X
, Y
, via
->X
, via
->Y
);
251 return (NULL
); /* don't allow via stacking */
257 Via
= GetViaMemory (Data
);
264 Via
->Thickness
= Thickness
;
265 Via
->Clearance
= Clearance
;
267 Via
->DrillingHole
= vendorDrillMap (DrillingHole
);
268 if (Via
->DrillingHole
!= DrillingHole
)
270 Message (_("%m+Mapped via drill hole to %$mS from %$mS per vendor table\n"),
271 Settings
.grid_unit
->allow
, Via
->DrillingHole
, DrillingHole
);
274 Via
->Name
= STRDUP (Name
);
276 CLEAR_FLAG (WARNFLAG
, Via
);
277 SET_FLAG (VIAFLAG
, Via
);
281 * don't complain about MIN_PINORVIACOPPER on a mounting hole (pure
284 if (!TEST_FLAG (HOLEFLAG
, Via
) &&
285 (Via
->Thickness
< Via
->DrillingHole
+ MIN_PINORVIACOPPER
))
287 Via
->Thickness
= Via
->DrillingHole
+ MIN_PINORVIACOPPER
;
288 Message (_("%m+Increased via thickness to %$mS to allow enough copper"
290 Settings
.grid_unit
->allow
, Via
->Thickness
, Via
->X
, Via
->Y
);
293 SetPinBoundingBox (Via
);
295 Data
->via_tree
= r_create_tree (NULL
, 0, 0);
296 r_insert_entry (Data
->via_tree
, (BoxType
*) Via
, 0);
302 Coord X1
, X2
, Y1
, Y2
;
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);
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);
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;
338 /* remove unnecessary line points */
339 if (line
->Thickness
== i
->Thickness
&&
340 /* don't merge lines if the clearances differ */
341 line
->Clearance
== i
->Clearance
&&
342 /* don't merge lines if the clear flags differ */
343 TEST_FLAG (CLEARLINEFLAG
, line
) == TEST_FLAG (CLEARLINEFLAG
, i
))
345 if (line
->Point1
.X
== i
->X1
&& line
->Point1
.Y
== i
->Y1
)
347 i
->test
.Point1
.X
= line
->Point2
.X
;
348 i
->test
.Point1
.Y
= line
->Point2
.Y
;
349 i
->test
.Point2
.X
= i
->X2
;
350 i
->test
.Point2
.Y
= i
->Y2
;
351 if (IsPointOnLine (i
->X1
, i
->Y1
, 0.0, &i
->test
))
357 else if (line
->Point2
.X
== i
->X1
&& line
->Point2
.Y
== i
->Y1
)
359 i
->test
.Point1
.X
= line
->Point1
.X
;
360 i
->test
.Point1
.Y
= line
->Point1
.Y
;
361 i
->test
.Point2
.X
= i
->X2
;
362 i
->test
.Point2
.Y
= i
->Y2
;
363 if (IsPointOnLine (i
->X1
, i
->Y1
, 0.0, &i
->test
))
369 else if (line
->Point1
.X
== i
->X2
&& line
->Point1
.Y
== i
->Y2
)
371 i
->test
.Point1
.X
= line
->Point2
.X
;
372 i
->test
.Point1
.Y
= line
->Point2
.Y
;
373 i
->test
.Point2
.X
= i
->X1
;
374 i
->test
.Point2
.Y
= i
->Y1
;
375 if (IsPointOnLine (i
->X2
, i
->Y2
, 0.0, &i
->test
))
381 else if (line
->Point2
.X
== i
->X2
&& line
->Point2
.Y
== i
->Y2
)
383 i
->test
.Point1
.X
= line
->Point1
.X
;
384 i
->test
.Point1
.Y
= line
->Point1
.Y
;
385 i
->test
.Point2
.X
= i
->X1
;
386 i
->test
.Point2
.Y
= i
->Y1
;
387 if (IsPointOnLine (i
->X2
, i
->Y2
, 0.0, &i
->test
))
398 /* ---------------------------------------------------------------------------
399 * creates a new line on a layer and checks for overlap and extension
402 CreateDrawnLineOnLayer (LayerType
*Layer
,
405 Coord Thickness
, Coord Clearance
,
408 struct line_info info
;
411 search
.X1
= MIN (X1
, X2
);
412 search
.X2
= MAX (X1
, X2
);
413 search
.Y1
= MIN (Y1
, Y2
);
414 search
.Y2
= MAX (Y1
, Y2
);
415 if (search
.Y2
== search
.Y1
)
417 if (search
.X2
== search
.X1
)
423 info
.Thickness
= Thickness
;
424 info
.Clearance
= Clearance
;
426 info
.test
.Thickness
= 0;
427 info
.test
.Flags
= NoFlags ();
429 /* prevent stacking of duplicate lines
430 * and remove needless intermediate points
431 * verify that the layer is on the board first!
433 if (setjmp (info
.env
) == 0)
435 r_search (Layer
->line_tree
, &search
, NULL
, line_callback
, &info
);
436 return CreateNewLineOnLayer (Layer
, X1
, Y1
, X2
, Y2
,
437 Thickness
, Clearance
, Flags
);
440 if ((void *) info
.ans
== (void *) (-1))
441 return NULL
; /* stacked line */
442 /* remove unnecessary points */
445 /* must do this BEFORE getting new line memory */
446 MoveObjectToRemoveUndoList (LINE_TYPE
, Layer
, info
.ans
, info
.ans
);
447 X1
= info
.test
.Point1
.X
;
448 X2
= info
.test
.Point2
.X
;
449 Y1
= info
.test
.Point1
.Y
;
450 Y2
= info
.test
.Point2
.Y
;
452 return CreateNewLineOnLayer (Layer
, X1
, Y1
, X2
, Y2
,
453 Thickness
, Clearance
, Flags
);
457 CreateNewLineOnLayer (LayerType
*Layer
,
460 Coord Thickness
, Coord Clearance
,
465 Line
= GetLineMemory (Layer
);
470 CLEAR_FLAG (RATFLAG
, Line
);
471 Line
->Thickness
= Thickness
;
472 Line
->Clearance
= Clearance
;
475 Line
->Point1
.ID
= ID
++;
478 Line
->Point2
.ID
= ID
++;
479 SetLineBoundingBox (Line
);
480 if (!Layer
->line_tree
)
481 Layer
->line_tree
= r_create_tree (NULL
, 0, 0);
482 r_insert_entry (Layer
->line_tree
, (BoxType
*) Line
, 0);
486 /* ---------------------------------------------------------------------------
487 * creates a new rat-line
490 CreateNewRat (DataType
*Data
, Coord X1
, Coord Y1
,
491 Coord X2
, Coord Y2
, Cardinal group1
,
492 Cardinal group2
, Coord Thickness
, FlagType Flags
)
494 RatType
*Line
= GetRatMemory (Data
);
501 SET_FLAG (RATFLAG
, Line
);
502 Line
->Thickness
= Thickness
;
505 Line
->Point1
.ID
= ID
++;
508 Line
->Point2
.ID
= ID
++;
509 Line
->group1
= group1
;
510 Line
->group2
= group2
;
511 SetLineBoundingBox ((LineType
*) Line
);
513 Data
->rat_tree
= r_create_tree (NULL
, 0, 0);
514 r_insert_entry (Data
->rat_tree
, &Line
->BoundingBox
, 0);
518 /* ---------------------------------------------------------------------------
519 * creates a new arc on a layer
522 CreateNewArcOnLayer (LayerType
*Layer
,
527 Angle dir
, Coord Thickness
,
528 Coord Clearance
, FlagType Flags
)
534 if (arc
->X
== X1
&& arc
->Y
== Y1
&& arc
->Width
== width
&&
535 NormalizeAngle (arc
->StartAngle
) == NormalizeAngle (sa
) &&
537 return (NULL
); /* prevent stacked arcs */
540 Arc
= GetArcMemory (Layer
);
546 Arc
->Thickness
= Thickness
;
547 Arc
->Clearance
= Clearance
;
551 Arc
->Height
= height
;
552 Arc
->StartAngle
= sa
;
554 SetArcBoundingBox (Arc
);
555 if (!Layer
->arc_tree
)
556 Layer
->arc_tree
= r_create_tree (NULL
, 0, 0);
557 r_insert_entry (Layer
->arc_tree
, (BoxType
*) Arc
, 0);
562 /* ---------------------------------------------------------------------------
563 * creates a new polygon from the old formats rectangle data
566 CreateNewPolygonFromRectangle (LayerType
*Layer
,
571 PolygonType
*polygon
= CreateNewPolygon (Layer
, Flags
);
575 CreateNewPointInPolygon (polygon
, X1
, Y1
);
576 CreateNewPointInPolygon (polygon
, X2
, Y1
);
577 CreateNewPointInPolygon (polygon
, X2
, Y2
);
578 CreateNewPointInPolygon (polygon
, X1
, Y2
);
579 SetPolygonBoundingBox (polygon
);
580 if (!Layer
->polygon_tree
)
581 Layer
->polygon_tree
= r_create_tree (NULL
, 0, 0);
582 r_insert_entry (Layer
->polygon_tree
, (BoxType
*) polygon
, 0);
586 /* ---------------------------------------------------------------------------
587 * creates a new text on a layer
590 CreateNewText (LayerType
*Layer
, FontType
*PCBFont
,
592 unsigned Direction
, int Scale
, char *TextString
, FlagType Flags
)
596 if (TextString
== NULL
)
599 text
= GetTextMemory (Layer
);
603 /* copy values, width and height are set by drawing routine
604 * because at this point we don't know which symbols are available
608 text
->Direction
= Direction
;
611 text
->TextString
= strdup (TextString
);
613 /* calculate size of the bounding box */
614 SetTextBoundingBox (PCBFont
, text
);
616 if (!Layer
->text_tree
)
617 Layer
->text_tree
= r_create_tree (NULL
, 0, 0);
618 r_insert_entry (Layer
->text_tree
, (BoxType
*) text
, 0);
622 /* ---------------------------------------------------------------------------
623 * creates a new polygon on a layer
626 CreateNewPolygon (LayerType
*Layer
, FlagType Flags
)
628 PolygonType
*polygon
= GetPolygonMemory (Layer
);
631 polygon
->Flags
= Flags
;
633 polygon
->Clipped
= NULL
;
634 polygon
->NoHoles
= NULL
;
635 polygon
->NoHolesValid
= 0;
639 /* ---------------------------------------------------------------------------
640 * creates a new point in a polygon
643 CreateNewPointInPolygon (PolygonType
*Polygon
, Coord X
, Coord Y
)
645 PointType
*point
= GetPointMemoryInPolygon (Polygon
);
654 /* ---------------------------------------------------------------------------
655 * creates a new hole in a polygon
658 CreateNewHoleInPolygon (PolygonType
*Polygon
)
660 Cardinal
*holeindex
= GetHoleIndexMemoryInPolygon (Polygon
);
661 *holeindex
= Polygon
->PointN
;
665 /* ---------------------------------------------------------------------------
666 * creates an new element
667 * memory is allocated if needed
670 CreateNewElement (DataType
*Data
, ElementType
*Element
,
673 char *Description
, char *NameOnPCB
, char *Value
,
674 Coord TextX
, Coord TextY
, BYTE Direction
,
675 int TextScale
, FlagType TextFlags
, bool uniqueName
)
678 printf("Entered CreateNewElement.....\n");
682 Element
= GetElementMemory (Data
);
684 /* copy values and set additional information */
685 TextScale
= MAX (MIN_TEXTSCALE
, TextScale
);
686 AddTextToElement (&DESCRIPTION_TEXT (Element
), PCBFont
, TextX
, TextY
,
687 Direction
, Description
, TextScale
, TextFlags
);
689 NameOnPCB
= UniqueElementName (Data
, NameOnPCB
);
690 AddTextToElement (&NAMEONPCB_TEXT (Element
), PCBFont
, TextX
, TextY
,
691 Direction
, NameOnPCB
, TextScale
, TextFlags
);
692 AddTextToElement (&VALUE_TEXT (Element
), PCBFont
, TextX
, TextY
,
693 Direction
, Value
, TextScale
, TextFlags
);
694 DESCRIPTION_TEXT (Element
).Element
= Element
;
695 NAMEONPCB_TEXT (Element
).Element
= Element
;
696 VALUE_TEXT (Element
).Element
= Element
;
697 Element
->Flags
= Flags
;
701 printf(" .... Leaving CreateNewElement.\n");
707 /* ---------------------------------------------------------------------------
708 * creates a new arc in an element
711 CreateNewArcInElement (ElementType
*Element
,
713 Coord Width
, Coord Height
,
714 Angle angle
, Angle delta
, Coord Thickness
)
718 arc
= g_slice_new0 (ArcType
);
719 Element
->Arc
= g_list_append (Element
->Arc
, arc
);
722 /* set Delta (0,360], StartAngle in [0,360) */
728 angle
= NormalizeAngle (angle
);
729 delta
= NormalizeAngle (delta
);
737 arc
->Height
= Height
;
738 arc
->StartAngle
= angle
;
740 arc
->Thickness
= Thickness
;
745 /* ---------------------------------------------------------------------------
746 * creates a new line for an element
749 CreateNewLineInElement (ElementType
*Element
,
759 line
= g_slice_new0 (LineType
);
760 Element
->Line
= g_list_append (Element
->Line
, line
);
768 line
->Thickness
= Thickness
;
769 line
->Flags
= NoFlags ();
774 /* ---------------------------------------------------------------------------
775 * creates a new pin in an element
778 CreateNewPin (ElementType
*Element
,
780 Coord Thickness
, Coord Clearance
, Coord Mask
,
781 Coord DrillingHole
, char *Name
, char *Number
,
784 PinType
*pin
= GetPinMemory (Element
);
789 pin
->Thickness
= Thickness
;
790 pin
->Clearance
= Clearance
;
792 pin
->Name
= STRDUP (Name
);
793 pin
->Number
= STRDUP (Number
);
795 CLEAR_FLAG (WARNFLAG
, pin
);
796 SET_FLAG (PINFLAG
, pin
);
798 pin
->Element
= Element
;
801 * If there is no vendor drill map installed, this will simply
802 * return DrillingHole.
804 pin
->DrillingHole
= vendorDrillMap (DrillingHole
);
806 /* Unless we should not map drills on this element, map them! */
807 if (vendorIsElementMappable (Element
))
809 if (pin
->DrillingHole
< MIN_PINORVIASIZE
)
811 Message (_("%m+Did not map pin #%s (%s) drill hole because %$mS is below the minimum allowed size\n"),
812 Settings
.grid_unit
->allow
, UNKNOWN (Number
), UNKNOWN (Name
), pin
->DrillingHole
);
813 pin
->DrillingHole
= DrillingHole
;
815 else if (pin
->DrillingHole
> MAX_PINORVIASIZE
)
817 Message (_("%m+Did not map pin #%s (%s) drill hole because %$mS is above the maximum allowed size\n"),
818 Settings
.grid_unit
->allow
, UNKNOWN (Number
), UNKNOWN (Name
), pin
->DrillingHole
);
819 pin
->DrillingHole
= DrillingHole
;
821 else if (!TEST_FLAG (HOLEFLAG
, pin
)
822 && (pin
->DrillingHole
> pin
->Thickness
- MIN_PINORVIACOPPER
))
824 Message (_("%m+Did not map pin #%s (%s) drill hole because %$mS does not leave enough copper\n"),
825 Settings
.grid_unit
->allow
, UNKNOWN (Number
), UNKNOWN (Name
), pin
->DrillingHole
);
826 pin
->DrillingHole
= DrillingHole
;
831 pin
->DrillingHole
= DrillingHole
;
834 if (pin
->DrillingHole
!= DrillingHole
)
836 Message (_("%m+Mapped pin drill hole to %$mS from %$mS per vendor table\n"),
837 Settings
.grid_unit
->allow
, pin
->DrillingHole
, DrillingHole
);
843 /* ---------------------------------------------------------------------------
844 * creates a new pad in an element
847 CreateNewPad (ElementType
*Element
,
848 Coord X1
, Coord Y1
, Coord X2
,
849 Coord Y2
, Coord Thickness
, Coord Clearance
,
850 Coord Mask
, char *Name
, char *Number
, FlagType Flags
)
852 PadType
*pad
= GetPadMemory (Element
);
855 if (X1
> X2
|| (X1
== X2
&& Y1
> Y2
))
869 pad
->Thickness
= Thickness
;
870 pad
->Clearance
= Clearance
;
872 pad
->Name
= STRDUP (Name
);
873 pad
->Number
= STRDUP (Number
);
875 CLEAR_FLAG (WARNFLAG
, pad
);
877 pad
->Element
= Element
;
881 /* ---------------------------------------------------------------------------
882 * creates a new textobject as part of an element
883 * copies the values to the appropriate text object
886 AddTextToElement (TextType
*Text
, FontType
*PCBFont
,
888 unsigned Direction
, char *TextString
, int Scale
, FlagType Flags
)
890 free (Text
->TextString
);
891 Text
->TextString
= (TextString
&& *TextString
) ? strdup (TextString
) : NULL
;
894 Text
->Direction
= Direction
;
898 /* calculate size of the bounding box */
899 SetTextBoundingBox (PCBFont
, Text
);
903 /* ---------------------------------------------------------------------------
904 * creates a new line in a symbol
907 CreateNewLineInSymbol (SymbolType
*Symbol
,
909 Coord X2
, Coord Y2
, Coord Thickness
)
911 LineType
*line
= Symbol
->Line
;
913 /* realloc new memory if necessary and clear it */
914 if (Symbol
->LineN
>= Symbol
->LineMax
)
916 Symbol
->LineMax
+= STEP_SYMBOLLINE
;
917 line
= (LineType
*)realloc (line
, Symbol
->LineMax
* sizeof (LineType
));
919 memset (line
+ Symbol
->LineN
, 0, STEP_SYMBOLLINE
* sizeof (LineType
));
923 line
= line
+ Symbol
->LineN
++;
928 line
->Thickness
= Thickness
;
932 /* ---------------------------------------------------------------------------
933 * parses a file with font information and installs it into the provided PCB
934 * checks directories given as colon separated list by resource fontPath
935 * if the fonts filename doesn't contain a directory component
938 CreateDefaultFont (PCBType
*pcb
)
940 if (ParseFont (&pcb
->Font
, Settings
.FontFile
))
941 Message (_("Can't find font-symbol-file '%s'\n"), Settings
.FontFile
);
944 /* ---------------------------------------------------------------------------
945 * adds a new line to the rubberband list of 'Crosshair.AttachedObject'
946 * if Layer == 0 it is a rat line
949 CreateNewRubberbandEntry (LayerType
*Layer
,
950 LineType
*Line
, PointType
*MovedPoint
)
952 RubberbandType
*ptr
= GetRubberbandMemory ();
954 /* we toggle the RUBBERENDFLAG of the line to determine if */
955 /* both points are being moved. */
956 TOGGLE_FLAG (RUBBERENDFLAG
, Line
);
959 ptr
->MovedPoint
= MovedPoint
;
963 /* ---------------------------------------------------------------------------
964 * Add a new net to the netlist menu
967 CreateNewNet (LibraryType
*lib
, char *name
, char *style
)
969 LibraryMenuType
*menu
;
972 sprintf (temp
, " %s", name
);
973 menu
= GetLibraryMenuMemory (lib
);
974 menu
->Name
= strdup (temp
);
975 menu
->flag
= 1; /* net is enabled by default */
976 if (style
== NULL
|| NSTRCMP ("(unknown)", style
) == 0)
979 menu
->Style
= strdup (style
);
983 /* ---------------------------------------------------------------------------
984 * Add a connection to the net
987 CreateNewConnection (LibraryMenuType
*net
, char *conn
)
989 LibraryEntryType
*entry
= GetLibraryEntryMemory (net
);
991 entry
->ListEntry
= STRDUP (conn
);
995 /* ---------------------------------------------------------------------------
996 * Add an attribute to a list.
999 CreateNewAttribute (AttributeListType
*list
, char *name
, char *value
)
1001 if (list
->Number
>= list
->Max
)
1004 list
->List
= (AttributeType
*)realloc (list
->List
, list
->Max
* sizeof (AttributeType
));
1006 list
->List
[list
->Number
].name
= STRDUP (name
);
1007 list
->List
[list
->Number
].value
= STRDUP (value
);
1009 return &list
->List
[list
->Number
- 1];