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
;
310 line_callback (const BoxType
* b
, void *cl
)
312 LineType
*line
= (LineType
*) b
;
313 struct line_info
*i
= (struct line_info
*) cl
;
315 if (line
->Point1
.X
== i
->X1
&&
316 line
->Point2
.X
== i
->X2
&&
317 line
->Point1
.Y
== i
->Y1
&& line
->Point2
.Y
== i
->Y2
)
319 i
->ans
= (LineType
*) (-1);
322 /* check the other point order */
323 if (line
->Point1
.X
== i
->X1
&&
324 line
->Point2
.X
== i
->X2
&&
325 line
->Point1
.Y
== i
->Y1
&& line
->Point2
.Y
== i
->Y2
)
327 i
->ans
= (LineType
*) (-1);
330 if (line
->Point2
.X
== i
->X1
&&
331 line
->Point1
.X
== i
->X2
&&
332 line
->Point2
.Y
== i
->Y1
&& line
->Point1
.Y
== i
->Y2
)
334 i
->ans
= (LineType
*) - 1;
337 /* remove unnecessary line points */
338 if (line
->Thickness
== i
->Thickness
339 /* don't merge lines if the clear flags differ */
340 && TEST_FLAG (CLEARLINEFLAG
, line
) == TEST_FLAG (CLEARLINEFLAG
, i
))
342 if (line
->Point1
.X
== i
->X1
&& line
->Point1
.Y
== i
->Y1
)
344 i
->test
.Point1
.X
= line
->Point2
.X
;
345 i
->test
.Point1
.Y
= line
->Point2
.Y
;
346 i
->test
.Point2
.X
= i
->X2
;
347 i
->test
.Point2
.Y
= i
->Y2
;
348 if (IsPointOnLine (i
->X1
, i
->Y1
, 0.0, &i
->test
))
354 else if (line
->Point2
.X
== i
->X1
&& line
->Point2
.Y
== i
->Y1
)
356 i
->test
.Point1
.X
= line
->Point1
.X
;
357 i
->test
.Point1
.Y
= line
->Point1
.Y
;
358 i
->test
.Point2
.X
= i
->X2
;
359 i
->test
.Point2
.Y
= i
->Y2
;
360 if (IsPointOnLine (i
->X1
, i
->Y1
, 0.0, &i
->test
))
366 else if (line
->Point1
.X
== i
->X2
&& line
->Point1
.Y
== i
->Y2
)
368 i
->test
.Point1
.X
= line
->Point2
.X
;
369 i
->test
.Point1
.Y
= line
->Point2
.Y
;
370 i
->test
.Point2
.X
= i
->X1
;
371 i
->test
.Point2
.Y
= i
->Y1
;
372 if (IsPointOnLine (i
->X2
, i
->Y2
, 0.0, &i
->test
))
378 else if (line
->Point2
.X
== i
->X2
&& line
->Point2
.Y
== i
->Y2
)
380 i
->test
.Point1
.X
= line
->Point1
.X
;
381 i
->test
.Point1
.Y
= line
->Point1
.Y
;
382 i
->test
.Point2
.X
= i
->X1
;
383 i
->test
.Point2
.Y
= i
->Y1
;
384 if (IsPointOnLine (i
->X2
, i
->Y2
, 0.0, &i
->test
))
395 /* ---------------------------------------------------------------------------
396 * creates a new line on a layer and checks for overlap and extension
399 CreateDrawnLineOnLayer (LayerType
*Layer
,
402 Coord Thickness
, Coord Clearance
,
405 struct line_info info
;
408 search
.X1
= MIN (X1
, X2
);
409 search
.X2
= MAX (X1
, X2
);
410 search
.Y1
= MIN (Y1
, Y2
);
411 search
.Y2
= MAX (Y1
, Y2
);
412 if (search
.Y2
== search
.Y1
)
414 if (search
.X2
== search
.X1
)
420 info
.Thickness
= Thickness
;
422 info
.test
.Thickness
= 0;
423 info
.test
.Flags
= NoFlags ();
425 /* prevent stacking of duplicate lines
426 * and remove needless intermediate points
427 * verify that the layer is on the board first!
429 if (setjmp (info
.env
) == 0)
431 r_search (Layer
->line_tree
, &search
, NULL
, line_callback
, &info
);
432 return CreateNewLineOnLayer (Layer
, X1
, Y1
, X2
, Y2
,
433 Thickness
, Clearance
, Flags
);
436 if ((void *) info
.ans
== (void *) (-1))
437 return NULL
; /* stacked line */
438 /* remove unnecessary points */
441 /* must do this BEFORE getting new line memory */
442 MoveObjectToRemoveUndoList (LINE_TYPE
, Layer
, info
.ans
, info
.ans
);
443 X1
= info
.test
.Point1
.X
;
444 X2
= info
.test
.Point2
.X
;
445 Y1
= info
.test
.Point1
.Y
;
446 Y2
= info
.test
.Point2
.Y
;
448 return CreateNewLineOnLayer (Layer
, X1
, Y1
, X2
, Y2
,
449 Thickness
, Clearance
, Flags
);
453 CreateNewLineOnLayer (LayerType
*Layer
,
456 Coord Thickness
, Coord Clearance
,
461 Line
= GetLineMemory (Layer
);
466 CLEAR_FLAG (RATFLAG
, Line
);
467 Line
->Thickness
= Thickness
;
468 Line
->Clearance
= Clearance
;
471 Line
->Point1
.ID
= ID
++;
474 Line
->Point2
.ID
= ID
++;
475 SetLineBoundingBox (Line
);
476 if (!Layer
->line_tree
)
477 Layer
->line_tree
= r_create_tree (NULL
, 0, 0);
478 r_insert_entry (Layer
->line_tree
, (BoxType
*) Line
, 0);
482 /* ---------------------------------------------------------------------------
483 * creates a new rat-line
486 CreateNewRat (DataType
*Data
, Coord X1
, Coord Y1
,
487 Coord X2
, Coord Y2
, Cardinal group1
,
488 Cardinal group2
, Coord Thickness
, FlagType Flags
)
490 RatType
*Line
= GetRatMemory (Data
);
497 SET_FLAG (RATFLAG
, Line
);
498 Line
->Thickness
= Thickness
;
501 Line
->Point1
.ID
= ID
++;
504 Line
->Point2
.ID
= ID
++;
505 Line
->group1
= group1
;
506 Line
->group2
= group2
;
507 SetLineBoundingBox ((LineType
*) Line
);
509 Data
->rat_tree
= r_create_tree (NULL
, 0, 0);
510 r_insert_entry (Data
->rat_tree
, &Line
->BoundingBox
, 0);
514 /* ---------------------------------------------------------------------------
515 * creates a new arc on a layer
518 CreateNewArcOnLayer (LayerType
*Layer
,
523 Angle dir
, Coord Thickness
,
524 Coord Clearance
, FlagType Flags
)
530 if (arc
->X
== X1
&& arc
->Y
== Y1
&& arc
->Width
== width
&&
531 NormalizeAngle (arc
->StartAngle
) == NormalizeAngle (sa
) &&
533 return (NULL
); /* prevent stacked arcs */
536 Arc
= GetArcMemory (Layer
);
542 Arc
->Thickness
= Thickness
;
543 Arc
->Clearance
= Clearance
;
547 Arc
->Height
= height
;
548 Arc
->StartAngle
= sa
;
550 SetArcBoundingBox (Arc
);
551 if (!Layer
->arc_tree
)
552 Layer
->arc_tree
= r_create_tree (NULL
, 0, 0);
553 r_insert_entry (Layer
->arc_tree
, (BoxType
*) Arc
, 0);
558 /* ---------------------------------------------------------------------------
559 * creates a new polygon from the old formats rectangle data
562 CreateNewPolygonFromRectangle (LayerType
*Layer
,
567 PolygonType
*polygon
= CreateNewPolygon (Layer
, Flags
);
571 CreateNewPointInPolygon (polygon
, X1
, Y1
);
572 CreateNewPointInPolygon (polygon
, X2
, Y1
);
573 CreateNewPointInPolygon (polygon
, X2
, Y2
);
574 CreateNewPointInPolygon (polygon
, X1
, Y2
);
575 SetPolygonBoundingBox (polygon
);
576 if (!Layer
->polygon_tree
)
577 Layer
->polygon_tree
= r_create_tree (NULL
, 0, 0);
578 r_insert_entry (Layer
->polygon_tree
, (BoxType
*) polygon
, 0);
582 /* ---------------------------------------------------------------------------
583 * creates a new text on a layer
586 CreateNewText (LayerType
*Layer
, FontType
*PCBFont
,
588 unsigned Direction
, int Scale
, char *TextString
, FlagType Flags
)
592 if (TextString
== NULL
)
595 text
= GetTextMemory (Layer
);
599 /* copy values, width and height are set by drawing routine
600 * because at this point we don't know which symbols are available
604 text
->Direction
= Direction
;
607 text
->TextString
= strdup (TextString
);
609 /* calculate size of the bounding box */
610 SetTextBoundingBox (PCBFont
, text
);
612 if (!Layer
->text_tree
)
613 Layer
->text_tree
= r_create_tree (NULL
, 0, 0);
614 r_insert_entry (Layer
->text_tree
, (BoxType
*) text
, 0);
618 /* ---------------------------------------------------------------------------
619 * creates a new polygon on a layer
622 CreateNewPolygon (LayerType
*Layer
, FlagType Flags
)
624 PolygonType
*polygon
= GetPolygonMemory (Layer
);
627 polygon
->Flags
= Flags
;
629 polygon
->Clipped
= NULL
;
630 polygon
->NoHoles
= NULL
;
631 polygon
->NoHolesValid
= 0;
635 /* ---------------------------------------------------------------------------
636 * creates a new point in a polygon
639 CreateNewPointInPolygon (PolygonType
*Polygon
, Coord X
, Coord Y
)
641 PointType
*point
= GetPointMemoryInPolygon (Polygon
);
650 /* ---------------------------------------------------------------------------
651 * creates a new hole in a polygon
654 CreateNewHoleInPolygon (PolygonType
*Polygon
)
656 Cardinal
*holeindex
= GetHoleIndexMemoryInPolygon (Polygon
);
657 *holeindex
= Polygon
->PointN
;
661 /* ---------------------------------------------------------------------------
662 * creates an new element
663 * memory is allocated if needed
666 CreateNewElement (DataType
*Data
, ElementType
*Element
,
669 char *Description
, char *NameOnPCB
, char *Value
,
670 Coord TextX
, Coord TextY
, BYTE Direction
,
671 int TextScale
, FlagType TextFlags
, bool uniqueName
)
674 printf("Entered CreateNewElement.....\n");
678 Element
= GetElementMemory (Data
);
680 /* copy values and set additional information */
681 TextScale
= MAX (MIN_TEXTSCALE
, TextScale
);
682 AddTextToElement (&DESCRIPTION_TEXT (Element
), PCBFont
, TextX
, TextY
,
683 Direction
, Description
, TextScale
, TextFlags
);
685 NameOnPCB
= UniqueElementName (Data
, NameOnPCB
);
686 AddTextToElement (&NAMEONPCB_TEXT (Element
), PCBFont
, TextX
, TextY
,
687 Direction
, NameOnPCB
, TextScale
, TextFlags
);
688 AddTextToElement (&VALUE_TEXT (Element
), PCBFont
, TextX
, TextY
,
689 Direction
, Value
, TextScale
, TextFlags
);
690 DESCRIPTION_TEXT (Element
).Element
= Element
;
691 NAMEONPCB_TEXT (Element
).Element
= Element
;
692 VALUE_TEXT (Element
).Element
= Element
;
693 Element
->Flags
= Flags
;
697 printf(" .... Leaving CreateNewElement.\n");
703 /* ---------------------------------------------------------------------------
704 * creates a new arc in an element
707 CreateNewArcInElement (ElementType
*Element
,
709 Coord Width
, Coord Height
,
710 Angle angle
, Angle delta
, Coord Thickness
)
714 arc
= g_slice_new0 (ArcType
);
715 Element
->Arc
= g_list_append (Element
->Arc
, arc
);
718 /* set Delta (0,360], StartAngle in [0,360) */
724 angle
= NormalizeAngle (angle
);
725 delta
= NormalizeAngle (delta
);
733 arc
->Height
= Height
;
734 arc
->StartAngle
= angle
;
736 arc
->Thickness
= Thickness
;
741 /* ---------------------------------------------------------------------------
742 * creates a new line for an element
745 CreateNewLineInElement (ElementType
*Element
,
755 line
= g_slice_new0 (LineType
);
756 Element
->Line
= g_list_append (Element
->Line
, line
);
764 line
->Thickness
= Thickness
;
765 line
->Flags
= NoFlags ();
770 /* ---------------------------------------------------------------------------
771 * creates a new pin in an element
774 CreateNewPin (ElementType
*Element
,
776 Coord Thickness
, Coord Clearance
, Coord Mask
,
777 Coord DrillingHole
, char *Name
, char *Number
,
780 PinType
*pin
= GetPinMemory (Element
);
785 pin
->Thickness
= Thickness
;
786 pin
->Clearance
= Clearance
;
788 pin
->Name
= STRDUP (Name
);
789 pin
->Number
= STRDUP (Number
);
791 CLEAR_FLAG (WARNFLAG
, pin
);
792 SET_FLAG (PINFLAG
, pin
);
794 pin
->Element
= Element
;
797 * If there is no vendor drill map installed, this will simply
798 * return DrillingHole.
800 pin
->DrillingHole
= vendorDrillMap (DrillingHole
);
802 /* Unless we should not map drills on this element, map them! */
803 if (vendorIsElementMappable (Element
))
805 if (pin
->DrillingHole
< MIN_PINORVIASIZE
)
807 Message (_("%m+Did not map pin #%s (%s) drill hole because %$mS is below the minimum allowed size\n"),
808 Settings
.grid_unit
->allow
, UNKNOWN (Number
), UNKNOWN (Name
), pin
->DrillingHole
);
809 pin
->DrillingHole
= DrillingHole
;
811 else if (pin
->DrillingHole
> MAX_PINORVIASIZE
)
813 Message (_("%m+Did not map pin #%s (%s) drill hole because %$mS is above the maximum allowed size\n"),
814 Settings
.grid_unit
->allow
, UNKNOWN (Number
), UNKNOWN (Name
), pin
->DrillingHole
);
815 pin
->DrillingHole
= DrillingHole
;
817 else if (!TEST_FLAG (HOLEFLAG
, pin
)
818 && (pin
->DrillingHole
> pin
->Thickness
- MIN_PINORVIACOPPER
))
820 Message (_("%m+Did not map pin #%s (%s) drill hole because %$mS does not leave enough copper\n"),
821 Settings
.grid_unit
->allow
, UNKNOWN (Number
), UNKNOWN (Name
), pin
->DrillingHole
);
822 pin
->DrillingHole
= DrillingHole
;
827 pin
->DrillingHole
= DrillingHole
;
830 if (pin
->DrillingHole
!= DrillingHole
)
832 Message (_("%m+Mapped pin drill hole to %$mS from %$mS per vendor table\n"),
833 Settings
.grid_unit
->allow
, pin
->DrillingHole
, DrillingHole
);
839 /* ---------------------------------------------------------------------------
840 * creates a new pad in an element
843 CreateNewPad (ElementType
*Element
,
844 Coord X1
, Coord Y1
, Coord X2
,
845 Coord Y2
, Coord Thickness
, Coord Clearance
,
846 Coord Mask
, char *Name
, char *Number
, FlagType Flags
)
848 PadType
*pad
= GetPadMemory (Element
);
851 if (X1
> X2
|| (X1
== X2
&& Y1
> Y2
))
865 pad
->Thickness
= Thickness
;
866 pad
->Clearance
= Clearance
;
868 pad
->Name
= STRDUP (Name
);
869 pad
->Number
= STRDUP (Number
);
871 CLEAR_FLAG (WARNFLAG
, pad
);
873 pad
->Element
= Element
;
877 /* ---------------------------------------------------------------------------
878 * creates a new textobject as part of an element
879 * copies the values to the appropriate text object
882 AddTextToElement (TextType
*Text
, FontType
*PCBFont
,
884 unsigned Direction
, char *TextString
, int Scale
, FlagType Flags
)
886 free (Text
->TextString
);
887 Text
->TextString
= (TextString
&& *TextString
) ? strdup (TextString
) : NULL
;
890 Text
->Direction
= Direction
;
894 /* calculate size of the bounding box */
895 SetTextBoundingBox (PCBFont
, Text
);
899 /* ---------------------------------------------------------------------------
900 * creates a new line in a symbol
903 CreateNewLineInSymbol (SymbolType
*Symbol
,
905 Coord X2
, Coord Y2
, Coord Thickness
)
907 LineType
*line
= Symbol
->Line
;
909 /* realloc new memory if necessary and clear it */
910 if (Symbol
->LineN
>= Symbol
->LineMax
)
912 Symbol
->LineMax
+= STEP_SYMBOLLINE
;
913 line
= (LineType
*)realloc (line
, Symbol
->LineMax
* sizeof (LineType
));
915 memset (line
+ Symbol
->LineN
, 0, STEP_SYMBOLLINE
* sizeof (LineType
));
919 line
= line
+ Symbol
->LineN
++;
924 line
->Thickness
= Thickness
;
928 /* ---------------------------------------------------------------------------
929 * parses a file with font information and installs it into the provided PCB
930 * checks directories given as colon separated list by resource fontPath
931 * if the fonts filename doesn't contain a directory component
934 CreateDefaultFont (PCBType
*pcb
)
936 if (ParseFont (&pcb
->Font
, Settings
.FontFile
))
937 Message (_("Can't find font-symbol-file '%s'\n"), Settings
.FontFile
);
940 /* ---------------------------------------------------------------------------
941 * adds a new line to the rubberband list of 'Crosshair.AttachedObject'
942 * if Layer == 0 it is a rat line
945 CreateNewRubberbandEntry (LayerType
*Layer
,
946 LineType
*Line
, PointType
*MovedPoint
)
948 RubberbandType
*ptr
= GetRubberbandMemory ();
950 /* we toggle the RUBBERENDFLAG of the line to determine if */
951 /* both points are being moved. */
952 TOGGLE_FLAG (RUBBERENDFLAG
, Line
);
955 ptr
->MovedPoint
= MovedPoint
;
959 /* ---------------------------------------------------------------------------
960 * Add a new net to the netlist menu
963 CreateNewNet (LibraryType
*lib
, char *name
, char *style
)
965 LibraryMenuType
*menu
;
968 sprintf (temp
, " %s", name
);
969 menu
= GetLibraryMenuMemory (lib
);
970 menu
->Name
= strdup (temp
);
971 menu
->flag
= 1; /* net is enabled by default */
972 if (style
== NULL
|| NSTRCMP ("(unknown)", style
) == 0)
975 menu
->Style
= strdup (style
);
979 /* ---------------------------------------------------------------------------
980 * Add a connection to the net
983 CreateNewConnection (LibraryMenuType
*net
, char *conn
)
985 LibraryEntryType
*entry
= GetLibraryEntryMemory (net
);
987 entry
->ListEntry
= STRDUP (conn
);
991 /* ---------------------------------------------------------------------------
992 * Add an attribute to a list.
995 CreateNewAttribute (AttributeListType
*list
, char *name
, char *value
)
997 if (list
->Number
>= list
->Max
)
1000 list
->List
= (AttributeType
*)realloc (list
->List
, list
->Max
* sizeof (AttributeType
));
1002 list
->List
[list
->Number
].name
= STRDUP (name
);
1003 list
->List
[list
->Number
].value
= STRDUP (value
);
1005 return &list
->List
[list
->Number
- 1];