7 * PCB, interactive printed circuit board design
8 * Copyright (C) 1994,1995,1996, 2005 Thomas Nau
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 * Contact addresses for paper mail and Email:
25 * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
26 * Thomas.Nau@rz.uni-ulm.de
33 * - lists for pins and vias, lines, arcs, pads and for polygons are created.
34 * Every object that has to be checked is added to its list.
35 * Coarse searching is accomplished with the data rtrees.
36 * - there's no 'speed-up' mechanism for polygons because they are not used
37 * as often as other objects
38 * - the maximum distance between line and pin ... would depend on the angle
39 * between them. To speed up computation the limit is set to one half
40 * of the thickness of the objects (cause of square pins).
42 * PV: means pin or via (objects that connect layers)
43 * LO: all non PV objects (layer objects like lines, arcs, polygons, pads)
45 * 1. first, the LO or PV at the given coordinates is looked up
46 * 2. all LO connections to that PV are looked up next
47 * 3. lookup of all LOs connected to LOs from (2).
48 * This step is repeated until no more new connections are found.
49 * 4. lookup all PVs connected to the LOs from (2) and (3)
50 * 5. start again with (1) for all new PVs from (4)
52 * Intersection of line <--> circle:
53 * - calculate the signed distance from the line to the center,
54 * return false if abs(distance) > R
55 * - get the distance from the line <--> distancevector intersection to
56 * (X1,Y1) in range [0,1], return true if 0 <= distance <= 1
57 * - depending on (r > 1.0 or r < 0.0) check the distance of X2,Y2 or X1,Y1
60 * Intersection of line <--> line:
61 * - see the description of 'LineLineIntersect()'
64 /* routines to find connections between pins, vias, lines...
78 #ifdef HAVE_SYS_TIMES_H
79 #include <sys/times.h>
84 #include "crosshair.h"
98 #ifdef HAVE_LIBDMALLOC
109 /* ---------------------------------------------------------------------------
113 #define EXPAND_BOUNDS(p) if (Bloat > 0) {\
114 (p)->BoundingBox.X1 -= Bloat; \
115 (p)->BoundingBox.X2 += Bloat; \
116 (p)->BoundingBox.Y1 -= Bloat; \
117 (p)->BoundingBox.Y2 += Bloat;}
119 #define SEPARATE(FP) \
123 for (i = Settings.CharPerLine; i; i--) \
128 #define PADLIST_ENTRY(L,I) \
129 (((PadTypePtr *)PadList[(L)].Data)[(I)])
131 #define LINELIST_ENTRY(L,I) \
132 (((LineTypePtr *)LineList[(L)].Data)[(I)])
134 #define ARCLIST_ENTRY(L,I) \
135 (((ArcTypePtr *)ArcList[(L)].Data)[(I)])
137 #define RATLIST_ENTRY(I) \
138 (((RatTypePtr *)RatList.Data)[(I)])
140 #define POLYGONLIST_ENTRY(L,I) \
141 (((PolygonTypePtr *)PolygonList[(L)].Data)[(I)])
143 #define PVLIST_ENTRY(I) \
144 (((PinTypePtr *)PVList.Data)[(I)])
146 #define IS_PV_ON_RAT(PV, Rat) \
147 (IsPointOnLineEnd((PV)->X,(PV)->Y, (Rat)))
149 #define IS_PV_ON_ARC(PV, Arc) \
150 (TEST_FLAG(SQUAREFLAG, (PV)) ? \
152 (PV)->X -MAX(((PV)->Thickness+1)/2 +Bloat,0), (PV)->Y -MAX(((PV)->Thickness+1)/2 +Bloat,0), \
153 (PV)->X +MAX(((PV)->Thickness+1)/2 +Bloat,0), (PV)->Y +MAX(((PV)->Thickness+1)/2 +Bloat,0), \
155 IsPointOnArc((PV)->X,(PV)->Y,MAX((PV)->Thickness/2.0 + fBloat,0.0), (Arc)))
157 #define IS_PV_ON_PAD(PV,Pad) \
158 ( IsPointInPad((PV)->X, (PV)->Y, MAX((PV)->Thickness/2 +Bloat,0), (Pad)))
160 #define LENGTH_TO_HUMAN(value) (Settings.grid_units_mm ? ((value) / 100000.0 * 25.4) : ((value) / 100.0))
161 #define LENGTH_DIGITS (Settings.grid_units_mm ? 4 : 2)
162 #define LENGTH_UNITS_STRING (Settings.grid_units_mm ? "mm" : "mils")
165 static DrcViolationType
166 *pcb_drc_violation_new (char *title
,
171 double measured_value
,
172 double required_value
,
174 const char *value_units
,
176 long int *object_id_list
,
177 int *object_type_list
)
179 DrcViolationType
*violation
= malloc (sizeof (DrcViolationType
));
181 violation
->title
= strdup (title
);
182 violation
->explanation
= strdup (explanation
);
185 violation
->angle
= angle
;
186 violation
->have_measured
= have_measured
;
187 violation
->measured_value
= measured_value
;
188 violation
->required_value
= required_value
;
189 violation
->value_digits
= value_digits
;
190 violation
->value_units
= value_units
;
191 violation
->object_count
= object_count
;
192 violation
->object_id_list
= object_id_list
;
193 violation
->object_type_list
= object_type_list
;
199 pcb_drc_violation_free (DrcViolationType
*violation
)
201 free (violation
->title
);
202 free (violation
->explanation
);
206 static char drc_dialog_message
[289] = {0};
208 reset_drc_dialog_message(void)
210 drc_dialog_message
[0] = 0;
211 if (gui
->drc_gui
!= NULL
)
213 gui
->drc_gui
->reset_drc_dialog_message ();
217 static void append_drc_dialog_message(const char *fmt
, ...)
218 __attribute__ ((format (printf
, 1, 2)));
221 append_drc_dialog_message(const char *fmt
, ...)
223 size_t len
= strlen (drc_dialog_message
),
224 remained
= sizeof (drc_dialog_message
) - len
- 1;
227 #ifdef HAVE_VSNPRINTF
228 vsnprintf (drc_dialog_message
+ len
, remained
, fmt
, ap
);
230 vsprintf (drc_dialog_message
+ len
, fmt
, ap
);
235 static void GotoError (void);
238 append_drc_violation (DrcViolationType
*violation
)
240 if (gui
->drc_gui
!= NULL
)
242 gui
->drc_gui
->append_drc_violation (violation
);
246 /* Fallback to formatting the violation message as text */
247 append_drc_dialog_message ("%s\n", violation
->title
);
248 append_drc_dialog_message (_("near (%.*f, %.*f)\n"),
249 LENGTH_DIGITS
, LENGTH_TO_HUMAN (violation
->x
),
250 LENGTH_DIGITS
, LENGTH_TO_HUMAN (violation
->y
));
254 if (gui
->drc_gui
== NULL
|| gui
->drc_gui
->log_drc_violations
)
256 Message (_("WARNING! Design Rule error - %s\n"), violation
->title
);
257 Message (_("near location (%.*f, %.*f)\n"),
258 LENGTH_DIGITS
, LENGTH_TO_HUMAN (violation
->x
),
259 LENGTH_DIGITS
, LENGTH_TO_HUMAN (violation
->y
));
263 * message when asked about continuing DRC checks after next
264 * violation is found.
266 #define DRC_CONTINUE _("Press Next to continue DRC checking")
267 #define DRC_NEXT _("Next")
268 #define DRC_CANCEL _("Cancel")
271 throw_drc_dialog(void)
275 if (gui
->drc_gui
!= NULL
)
277 r
= gui
->drc_gui
->throw_drc_dialog ();
281 /* Fallback to formatting the violation message as text */
282 append_drc_dialog_message (DRC_CONTINUE
);
283 r
= gui
->confirm_dialog (drc_dialog_message
, DRC_CANCEL
, DRC_NEXT
);
284 reset_drc_dialog_message();
289 /* ---------------------------------------------------------------------------
292 * the two 'dummy' structs for PVs and Pads are necessary for creating
293 * connection lists which include the element's name
297 void **Data
; /* pointer to index data */
298 Cardinal Location
, /* currently used position */
299 DrawLocation
, Number
, /* number of objects in list */
302 ListType
, *ListTypePtr
;
304 /* ---------------------------------------------------------------------------
305 * some local identifiers
307 static float fBloat
= 0.0;
308 static LocationType Bloat
= 0;
309 static int TheFlag
= FOUNDFLAG
;
310 static int OldFlag
= FOUNDFLAG
;
311 static void *thing_ptr1
, *thing_ptr2
, *thing_ptr3
;
312 static int thing_type
;
313 static Boolean User
= False
; /* user action causing this */
314 static Boolean drc
= False
; /* whether to stop if finding something not found */
315 static Boolean IsBad
= False
;
316 static Cardinal drcerr_count
; /* count of drc errors */
317 static Cardinal TotalP
, TotalV
, NumberOfPads
[2];
318 static ListType LineList
[MAX_LAYER
], /* list of objects to */
319 PolygonList
[MAX_LAYER
], ArcList
[MAX_LAYER
], PadList
[2], RatList
, PVList
;
321 /* ---------------------------------------------------------------------------
322 * some local prototypes
324 static Boolean
LookupLOConnectionsToPVList (Boolean
);
325 static Boolean
LookupLOConnectionsToLOList (Boolean
);
326 static Boolean
LookupPVConnectionsToLOList (Boolean
);
327 static Boolean
LookupPVConnectionsToPVList (void);
328 static Boolean
LookupLOConnectionsToLine (LineTypePtr
, Cardinal
, Boolean
);
329 static Boolean
LookupLOConnectionsToPad (PadTypePtr
, Cardinal
);
330 static Boolean
LookupLOConnectionsToPolygon (PolygonTypePtr
, Cardinal
);
331 static Boolean
LookupLOConnectionsToArc (ArcTypePtr
, Cardinal
);
332 static Boolean
LookupLOConnectionsToRatEnd (PointTypePtr
, Cardinal
);
333 static Boolean
IsRatPointOnLineEnd (PointTypePtr
, LineTypePtr
);
334 static Boolean
ArcArcIntersect (ArcTypePtr
, ArcTypePtr
);
335 static Boolean
PrepareNextLoop (FILE *);
336 static Boolean
PrintElementConnections (ElementTypePtr
, FILE *, Boolean
);
337 static Boolean
ListsEmpty (Boolean
);
338 static Boolean
DoIt (Boolean
, Boolean
);
339 static void PrintElementNameList (ElementTypePtr
, FILE *);
340 static void PrintConnectionElementName (ElementTypePtr
, FILE *);
341 static void PrintConnectionListEntry (char *, ElementTypePtr
,
343 static void PrintPadConnections (Cardinal
, FILE *, Boolean
);
344 static void PrintPinConnections (FILE *, Boolean
);
345 static Boolean
PrintAndSelectUnusedPinsAndPadsOfElement (ElementTypePtr
,
347 static void DrawNewConnections (void);
348 static void ResetConnections (Boolean
);
349 static void DumpList (void);
350 static void LocateError (LocationType
*, LocationType
*);
351 static void BuildObjectList (int *, long int **, int **);
352 static void GotoError (void);
353 static Boolean
DRCFind (int, void *, void *, void *);
354 static Boolean
ListStart (int, void *, void *, void *);
355 static Boolean
LOTouchesLine (LineTypePtr Line
, Cardinal LayerGroup
);
356 static Boolean
PVTouchesLine (LineTypePtr line
);
357 static Boolean
SetThing (int, void *, void *, void *);
359 /* ---------------------------------------------------------------------------
360 * some of the 'pad' routines are the same as for lines because the 'pad'
361 * struct starts with a line struct. See global.h for details
364 LinePadIntersect (LineTypePtr Line
, PadTypePtr Pad
)
366 return LineLineIntersect ((Line
), (LineTypePtr
)Pad
);
370 ArcPadIntersect (ArcTypePtr Arc
, PadTypePtr Pad
)
372 return LineArcIntersect ((LineTypePtr
) (Pad
), (Arc
));
376 ADD_PV_TO_LIST (PinTypePtr Pin
)
379 AddObjectToFlagUndoList (Pin
->Element
? PIN_TYPE
: VIA_TYPE
,
380 Pin
->Element
? Pin
->Element
: Pin
, Pin
, Pin
);
381 SET_FLAG (TheFlag
, Pin
);
382 PVLIST_ENTRY (PVList
.Number
) = Pin
;
385 if (PVList
.Number
> PVList
.Size
)
386 printf ("ADD_PV_TO_LIST overflow! num=%d size=%d\n", PVList
.Number
,
389 if (drc
&& !TEST_FLAG (SELECTEDFLAG
, Pin
))
390 return (SetThing (PIN_TYPE
, Pin
->Element
, Pin
, Pin
));
395 ADD_PAD_TO_LIST (Cardinal L
, PadTypePtr Pad
)
398 AddObjectToFlagUndoList (PAD_TYPE
, Pad
->Element
, Pad
, Pad
);
399 SET_FLAG (TheFlag
, Pad
);
400 PADLIST_ENTRY ((L
), PadList
[(L
)].Number
) = Pad
;
401 PadList
[(L
)].Number
++;
403 if (PadList
[(L
)].Number
> PadList
[(L
)].Size
)
404 printf ("ADD_PAD_TO_LIST overflow! lay=%d, num=%d size=%d\n", L
,
405 PadList
[(L
)].Number
, PadList
[(L
)].Size
);
407 if (drc
&& !TEST_FLAG (SELECTEDFLAG
, Pad
))
408 return (SetThing (PAD_TYPE
, Pad
->Element
, Pad
, Pad
));
413 ADD_LINE_TO_LIST (Cardinal L
, LineTypePtr Ptr
)
416 AddObjectToFlagUndoList (LINE_TYPE
, LAYER_PTR (L
), (Ptr
), (Ptr
));
417 SET_FLAG (TheFlag
, (Ptr
));
418 LINELIST_ENTRY ((L
), LineList
[(L
)].Number
) = (Ptr
);
419 LineList
[(L
)].Number
++;
421 if (LineList
[(L
)].Number
> LineList
[(L
)].Size
)
422 printf ("ADD_LINE_TO_LIST overflow! lay=%d, num=%d size=%d\n", L
,
423 LineList
[(L
)].Number
, LineList
[(L
)].Size
);
425 if (drc
&& !TEST_FLAG (SELECTEDFLAG
, (Ptr
)))
426 return (SetThing (LINE_TYPE
, LAYER_PTR (L
), (Ptr
), (Ptr
)));
431 ADD_ARC_TO_LIST (Cardinal L
, ArcTypePtr Ptr
)
434 AddObjectToFlagUndoList (ARC_TYPE
, LAYER_PTR (L
), (Ptr
), (Ptr
));
435 SET_FLAG (TheFlag
, (Ptr
));
436 ARCLIST_ENTRY ((L
), ArcList
[(L
)].Number
) = (Ptr
);
437 ArcList
[(L
)].Number
++;
439 if (ArcList
[(L
)].Number
> ArcList
[(L
)].Size
)
440 printf ("ADD_ARC_TO_LIST overflow! lay=%d, num=%d size=%d\n", L
,
441 ArcList
[(L
)].Number
, ArcList
[(L
)].Size
);
443 if (drc
&& !TEST_FLAG (SELECTEDFLAG
, (Ptr
)))
444 return (SetThing (ARC_TYPE
, LAYER_PTR (L
), (Ptr
), (Ptr
)));
449 ADD_RAT_TO_LIST (RatTypePtr Ptr
)
452 AddObjectToFlagUndoList (RATLINE_TYPE
, (Ptr
), (Ptr
), (Ptr
));
453 SET_FLAG (TheFlag
, (Ptr
));
454 RATLIST_ENTRY (RatList
.Number
) = (Ptr
);
457 if (RatList
.Number
> RatList
.Size
)
458 printf ("ADD_RAT_TO_LIST overflow! num=%d size=%d\n",
459 RatList
.Number
, RatList
.Size
);
461 if (drc
&& !TEST_FLAG (SELECTEDFLAG
, (Ptr
)))
462 return (SetThing (RATLINE_TYPE
, (Ptr
), (Ptr
), (Ptr
)));
467 ADD_POLYGON_TO_LIST (Cardinal L
, PolygonTypePtr Ptr
)
470 AddObjectToFlagUndoList (POLYGON_TYPE
, LAYER_PTR (L
), (Ptr
), (Ptr
));
471 SET_FLAG (TheFlag
, (Ptr
));
472 POLYGONLIST_ENTRY ((L
), PolygonList
[(L
)].Number
) = (Ptr
);
473 PolygonList
[(L
)].Number
++;
475 if (PolygonList
[(L
)].Number
> PolygonList
[(L
)].Size
)
476 printf ("ADD_ARC_TO_LIST overflow! lay=%d, num=%d size=%d\n", L
,
477 PolygonList
[(L
)].Number
, PolygonList
[(L
)].Size
);
479 if (drc
&& !TEST_FLAG (SELECTEDFLAG
, (Ptr
)))
480 return (SetThing (POLYGON_TYPE
, LAYER_PTR (L
), (Ptr
), (Ptr
)));
485 PinLineIntersect (PinTypePtr PV
, LineTypePtr Line
)
487 /* IsLineInRectangle already has Bloat factor */
488 return TEST_FLAG (SQUAREFLAG
,
489 PV
) ? IsLineInRectangle (PV
->X
- (PV
->Thickness
+ 1) / 2,
490 PV
->Y
- (PV
->Thickness
+ 1) / 2,
491 PV
->X
+ (PV
->Thickness
+ 1) / 2,
492 PV
->Y
+ (PV
->Thickness
+ 1) / 2,
493 Line
) : IsPointInPad (PV
->X
,
506 SetThing (int type
, void *ptr1
, void *ptr2
, void *ptr3
)
512 if (type
== PIN_TYPE
&& ptr1
== NULL
)
515 thing_type
= VIA_TYPE
;
521 BoxBoxIntersection (BoxTypePtr b1
, BoxTypePtr b2
)
523 if (b2
->X2
< b1
->X1
|| b2
->X1
> b1
->X2
)
525 if (b2
->Y2
< b1
->Y1
|| b2
->Y1
> b1
->Y2
)
531 PadPadIntersect (PadTypePtr p1
, PadTypePtr p2
)
533 return LinePadIntersect ((LineTypePtr
) p1
, p2
);
536 static inline Boolean
537 PV_TOUCH_PV (PinTypePtr PV1
, PinTypePtr PV2
)
542 t1
= MAX (PV1
->Thickness
/ 2.0 + fBloat
, 0);
543 t2
= MAX (PV2
->Thickness
/ 2.0 + fBloat
, 0);
544 if (IsPointOnPin (PV1
->X
, PV1
->Y
, t1
, PV2
)
545 || IsPointOnPin (PV2
->X
, PV2
->Y
, t2
, PV1
))
547 if (!TEST_FLAG (SQUAREFLAG
, PV1
) || !TEST_FLAG (SQUAREFLAG
, PV2
))
549 /* check for square/square overlap */
554 t2
= PV2
->Thickness
/ 2.0;
559 return BoxBoxIntersection (&b1
, &b2
);
562 /* ---------------------------------------------------------------------------
563 * releases all allocated memory
566 FreeLayoutLookupMemory (void)
570 for (i
= 0; i
< max_layer
; i
++)
572 MYFREE (LineList
[i
].Data
);
573 MYFREE (ArcList
[i
].Data
);
574 MYFREE (PolygonList
[i
].Data
);
576 MYFREE (PVList
.Data
);
577 MYFREE (RatList
.Data
);
581 FreeComponentLookupMemory (void)
583 MYFREE (PadList
[0].Data
);
584 MYFREE (PadList
[1].Data
);
587 /* ---------------------------------------------------------------------------
588 * allocates memory for component related stacks ...
589 * initializes index and sorts it by X1 and X2
592 InitComponentLookup (void)
596 /* initialize pad data; start by counting the total number
597 * on each of the two possible layers
599 NumberOfPads
[COMPONENT_LAYER
] = NumberOfPads
[SOLDER_LAYER
] = 0;
600 ALLPAD_LOOP (PCB
->Data
);
602 if (TEST_FLAG (ONSOLDERFLAG
, pad
))
603 NumberOfPads
[SOLDER_LAYER
]++;
605 NumberOfPads
[COMPONENT_LAYER
]++;
608 for (i
= 0; i
< 2; i
++)
610 /* allocate memory for working list */
612 (void **) MyCalloc (NumberOfPads
[i
], sizeof (PadTypePtr
),
613 "InitComponentLookup()");
615 /* clear some struct members */
616 PadList
[i
].Location
= 0;
617 PadList
[i
].DrawLocation
= 0;
618 PadList
[i
].Number
= 0;
619 PadList
[i
].Size
= NumberOfPads
[i
];
623 /* ---------------------------------------------------------------------------
624 * allocates memory for component related stacks ...
625 * initializes index and sorts it by X1 and X2
628 InitLayoutLookup (void)
632 /* initialize line arc and polygon data */
633 for (i
= 0; i
< max_layer
; i
++)
635 LayerTypePtr layer
= LAYER_PTR (i
);
639 /* allocate memory for line pointer lists */
641 (void **) MyCalloc (layer
->LineN
, sizeof (LineTypePtr
),
642 "InitLayoutLookup()");
643 LineList
[i
].Size
= layer
->LineN
;
648 (void **) MyCalloc (layer
->ArcN
, sizeof (ArcTypePtr
),
649 "InitLayoutLookup()");
650 ArcList
[i
].Size
= layer
->ArcN
;
654 /* allocate memory for polygon list */
657 PolygonList
[i
].Data
= (void **) MyCalloc (layer
->PolygonN
,
658 sizeof (PolygonTypePtr
),
659 "InitLayoutLookup()");
660 PolygonList
[i
].Size
= layer
->PolygonN
;
663 /* clear some struct members */
664 LineList
[i
].Location
= 0;
665 LineList
[i
].DrawLocation
= 0;
666 LineList
[i
].Number
= 0;
667 ArcList
[i
].Location
= 0;
668 ArcList
[i
].DrawLocation
= 0;
669 ArcList
[i
].Number
= 0;
670 PolygonList
[i
].Location
= 0;
671 PolygonList
[i
].DrawLocation
= 0;
672 PolygonList
[i
].Number
= 0;
675 if (PCB
->Data
->pin_tree
)
676 TotalP
= PCB
->Data
->pin_tree
->size
;
679 if (PCB
->Data
->via_tree
)
680 TotalV
= PCB
->Data
->via_tree
->size
;
683 /* allocate memory for 'new PV to check' list and clear struct */
684 PVList
.Data
= (void **) MyCalloc (TotalP
+ TotalV
, sizeof (PinTypePtr
),
685 "InitLayoutLookup()");
686 PVList
.Size
= TotalP
+ TotalV
;
688 PVList
.DrawLocation
= 0;
690 /* Initialize ratline data */
691 RatList
.Data
= (void **) MyCalloc (PCB
->Data
->RatN
, sizeof (RatTypePtr
),
692 "InitLayoutLookup()");
693 RatList
.Size
= PCB
->Data
->RatN
;
694 RatList
.Location
= 0;
695 RatList
.DrawLocation
= 0;
707 LOCtoPVline_callback (const BoxType
* b
, void *cl
)
709 LineTypePtr line
= (LineTypePtr
) b
;
710 struct pv_info
*i
= (struct pv_info
*) cl
;
712 if (!TEST_FLAG (TheFlag
, line
) && PinLineIntersect (&i
->pv
, line
))
714 if (ADD_LINE_TO_LIST (i
->layer
, line
))
721 LOCtoPVarc_callback (const BoxType
* b
, void *cl
)
723 ArcTypePtr arc
= (ArcTypePtr
) b
;
724 struct pv_info
*i
= (struct pv_info
*) cl
;
726 if (!TEST_FLAG (TheFlag
, arc
) && IS_PV_ON_ARC (&i
->pv
, arc
))
728 if (ADD_ARC_TO_LIST (i
->layer
, arc
))
735 LOCtoPVpad_callback (const BoxType
* b
, void *cl
)
737 PadTypePtr pad
= (PadTypePtr
) b
;
738 struct pv_info
*i
= (struct pv_info
*) cl
;
740 if (!TEST_FLAG (TheFlag
, pad
) && IS_PV_ON_PAD (&i
->pv
, pad
) &&
741 ADD_PAD_TO_LIST (TEST_FLAG (ONSOLDERFLAG
, pad
) ? SOLDER_LAYER
:
742 COMPONENT_LAYER
, pad
))
748 LOCtoPVrat_callback (const BoxType
* b
, void *cl
)
750 RatTypePtr rat
= (RatTypePtr
) b
;
751 struct pv_info
*i
= (struct pv_info
*) cl
;
753 if (!TEST_FLAG (TheFlag
, rat
) && IS_PV_ON_RAT (&i
->pv
, rat
) &&
754 ADD_RAT_TO_LIST (rat
))
759 LOCtoPVpoly_callback (const BoxType
* b
, void *cl
)
761 PolygonTypePtr polygon
= (PolygonTypePtr
) b
;
762 struct pv_info
*i
= (struct pv_info
*) cl
;
764 /* if the pin doesn't have a therm and polygon is clearing
765 * then it can't touch due to clearance, so skip the expensive
766 * test. If it does have a therm, you still need to test
767 * because it might not be inside the polygon, or it could
768 * be on an edge such that it doesn't actually touch.
770 if (!TEST_FLAG (TheFlag
, polygon
) && (TEST_THERM (i
->layer
, &i
->pv
)
771 || !TEST_FLAG (CLEARPOLYFLAG
,
773 || !i
->pv
.Clearance
))
775 float wide
= 0.5 * i
->pv
.Thickness
+ fBloat
;
776 wide
= MAX (wide
, 0);
777 if (TEST_FLAG (SQUAREFLAG
, &i
->pv
))
779 LocationType x1
= i
->pv
.X
- (i
->pv
.Thickness
+ 1 + Bloat
) / 2;
780 LocationType x2
= i
->pv
.X
+ (i
->pv
.Thickness
+ 1 + Bloat
) / 2;
781 LocationType y1
= i
->pv
.Y
- (i
->pv
.Thickness
+ 1 + Bloat
) / 2;
782 LocationType y2
= i
->pv
.Y
+ (i
->pv
.Thickness
+ 1 + Bloat
) / 2;
783 if (IsRectangleInPolygon (x1
, y1
, x2
, y2
, polygon
)
784 && ADD_POLYGON_TO_LIST (i
->layer
, polygon
))
787 else if (TEST_FLAG (OCTAGONFLAG
, &i
->pv
))
789 POLYAREA
*oct
= OctagonPoly (i
->pv
.X
, i
->pv
.Y
, i
->pv
.Thickness
/ 2);
790 if (isects (oct
, polygon
, True
)
791 && ADD_POLYGON_TO_LIST (i
->layer
, polygon
))
794 else if (IsPointInPolygon (i
->pv
.X
, i
->pv
.Y
, wide
,
796 && ADD_POLYGON_TO_LIST (i
->layer
, polygon
))
802 /* ---------------------------------------------------------------------------
803 * checks if a PV is connected to LOs, if it is, the LO is added to
804 * the appropriate list and the 'used' flag is set
807 LookupLOConnectionsToPVList (Boolean AndRats
)
812 /* loop over all PVs currently on list */
813 while (PVList
.Location
< PVList
.Number
)
815 /* get pointer to data */
816 info
.pv
= *(PVLIST_ENTRY (PVList
.Location
));
817 EXPAND_BOUNDS (&info
.pv
);
820 if (setjmp (info
.env
) == 0)
821 r_search (PCB
->Data
->pad_tree
, (BoxType
*) & info
.pv
, NULL
,
822 LOCtoPVpad_callback
, &info
);
826 /* now all lines, arcs and polygons of the several layers */
827 for (layer
= 0; layer
< max_layer
; layer
++)
830 /* add touching lines */
831 if (setjmp (info
.env
) == 0)
832 r_search (LAYER_PTR (layer
)->line_tree
, (BoxType
*) & info
.pv
,
833 NULL
, LOCtoPVline_callback
, &info
);
836 /* add touching arcs */
837 if (setjmp (info
.env
) == 0)
838 r_search (LAYER_PTR (layer
)->arc_tree
, (BoxType
*) & info
.pv
,
839 NULL
, LOCtoPVarc_callback
, &info
);
842 /* check all polygons */
843 if (setjmp (info
.env
) == 0)
844 r_search (LAYER_PTR (layer
)->polygon_tree
, (BoxType
*) & info
.pv
,
845 NULL
, LOCtoPVpoly_callback
, &info
);
849 /* Check for rat-lines that may intersect the PV */
852 if (setjmp (info
.env
) == 0)
853 r_search (PCB
->Data
->rat_tree
, (BoxType
*) & info
.pv
, NULL
,
854 LOCtoPVrat_callback
, &info
);
863 /* ---------------------------------------------------------------------------
864 * find all connections between LO at the current list position and new LOs
867 LookupLOConnectionsToLOList (Boolean AndRats
)
870 Cardinal i
, group
, layer
, ratposition
,
871 lineposition
[MAX_LAYER
],
872 polyposition
[MAX_LAYER
], arcposition
[MAX_LAYER
], padposition
[2];
874 /* copy the current LO list positions; the original data is changed
875 * by 'LookupPVConnectionsToLOList()' which has to check the same
876 * list entries plus the new ones
878 for (i
= 0; i
< max_layer
; i
++)
880 lineposition
[i
] = LineList
[i
].Location
;
881 polyposition
[i
] = PolygonList
[i
].Location
;
882 arcposition
[i
] = ArcList
[i
].Location
;
884 for (i
= 0; i
< 2; i
++)
885 padposition
[i
] = PadList
[i
].Location
;
886 ratposition
= RatList
.Location
;
888 /* loop over all new LOs in the list; recurse until no
889 * more new connections in the layergroup were found
897 position
= &ratposition
;
898 for (; *position
< RatList
.Number
; (*position
)++)
900 group
= RATLIST_ENTRY (*position
)->group1
;
901 if (LookupLOConnectionsToRatEnd
902 (&(RATLIST_ENTRY (*position
)->Point1
), group
))
904 group
= RATLIST_ENTRY (*position
)->group2
;
905 if (LookupLOConnectionsToRatEnd
906 (&(RATLIST_ENTRY (*position
)->Point2
), group
))
910 /* loop over all layergroups */
911 for (group
= 0; group
< max_layer
; group
++)
915 for (entry
= 0; entry
< PCB
->LayerGroups
.Number
[group
]; entry
++)
917 layer
= PCB
->LayerGroups
.Entries
[group
][entry
];
919 /* be aware that the layer number equal max_layer
920 * and max_layer+1 have a special meaning for pads
922 if (layer
< max_layer
)
924 /* try all new lines */
925 position
= &lineposition
[layer
];
926 for (; *position
< LineList
[layer
].Number
; (*position
)++)
927 if (LookupLOConnectionsToLine
928 (LINELIST_ENTRY (layer
, *position
), group
, True
))
931 /* try all new arcs */
932 position
= &arcposition
[layer
];
933 for (; *position
< ArcList
[layer
].Number
; (*position
)++)
934 if (LookupLOConnectionsToArc
935 (ARCLIST_ENTRY (layer
, *position
), group
))
938 /* try all new polygons */
939 position
= &polyposition
[layer
];
940 for (; *position
< PolygonList
[layer
].Number
; (*position
)++)
941 if (LookupLOConnectionsToPolygon
942 (POLYGONLIST_ENTRY (layer
, *position
), group
))
947 /* try all new pads */
951 Message (_("bad layer number %d max_layer=%d in find.c\n"),
955 position
= &padposition
[layer
];
956 for (; *position
< PadList
[layer
].Number
; (*position
)++)
957 if (LookupLOConnectionsToPad
958 (PADLIST_ENTRY (layer
, *position
), group
))
964 /* check if all lists are done; Later for-loops
965 * may have changed the prior lists
967 done
= !AndRats
|| ratposition
>= RatList
.Number
;
968 for (layer
= 0; layer
< max_layer
+ 2; layer
++)
970 if (layer
< max_layer
)
972 lineposition
[layer
] >= LineList
[layer
].Number
973 && arcposition
[layer
] >= ArcList
[layer
].Number
974 && polyposition
[layer
] >= PolygonList
[layer
].Number
;
977 && padposition
[layer
- max_layer
] >=
978 PadList
[layer
- max_layer
].Number
;
986 pv_pv_callback (const BoxType
* b
, void *cl
)
988 PinTypePtr pin
= (PinTypePtr
) b
;
989 struct pv_info
*i
= (struct pv_info
*) cl
;
991 if (!TEST_FLAG (TheFlag
, pin
) && PV_TOUCH_PV (&i
->pv
, pin
))
993 if (TEST_FLAG (HOLEFLAG
, pin
))
995 SET_FLAG (WARNFLAG
, pin
);
996 Settings
.RatWarn
= True
;
998 Message (_("WARNING: Hole too close to pin.\n"));
1000 Message (_("WARNING: Hole too close to via.\n"));
1002 if (ADD_PV_TO_LIST (pin
))
1003 longjmp (i
->env
, 1);
1008 /* ---------------------------------------------------------------------------
1009 * searches for new PVs that are connected to PVs on the list
1012 LookupPVConnectionsToPVList (void)
1014 Cardinal save_place
;
1015 struct pv_info info
;
1018 /* loop over all PVs on list */
1019 save_place
= PVList
.Location
;
1020 while (PVList
.Location
< PVList
.Number
)
1022 /* get pointer to data */
1023 info
.pv
= *(PVLIST_ENTRY (PVList
.Location
));
1024 EXPAND_BOUNDS (&info
.pv
);
1025 if (setjmp (info
.env
) == 0)
1026 r_search (PCB
->Data
->via_tree
, (BoxType
*) & info
.pv
, NULL
,
1027 pv_pv_callback
, &info
);
1030 if (setjmp (info
.env
) == 0)
1031 r_search (PCB
->Data
->pin_tree
, (BoxType
*) & info
.pv
, NULL
,
1032 pv_pv_callback
, &info
);
1037 PVList
.Location
= save_place
;
1047 PolygonType polygon
;
1053 pv_line_callback (const BoxType
* b
, void *cl
)
1055 PinTypePtr pv
= (PinTypePtr
) b
;
1056 struct lo_info
*i
= (struct lo_info
*) cl
;
1058 if (!TEST_FLAG (TheFlag
, pv
) && PinLineIntersect (pv
, &i
->line
))
1060 if (TEST_FLAG (HOLEFLAG
, pv
))
1062 SET_FLAG (WARNFLAG
, pv
);
1063 Settings
.RatWarn
= True
;
1064 Message (_("WARNING: Hole too close to line.\n"));
1066 if (ADD_PV_TO_LIST (pv
))
1067 longjmp (i
->env
, 1);
1073 pv_pad_callback (const BoxType
* b
, void *cl
)
1075 PinTypePtr pv
= (PinTypePtr
) b
;
1076 struct lo_info
*i
= (struct lo_info
*) cl
;
1078 if (!TEST_FLAG (TheFlag
, pv
) && IS_PV_ON_PAD (pv
, &i
->pad
))
1080 if (TEST_FLAG (HOLEFLAG
, pv
))
1082 SET_FLAG (WARNFLAG
, pv
);
1083 Settings
.RatWarn
= True
;
1084 Message (_("WARNING: Hole too close to pad.\n"));
1086 if (ADD_PV_TO_LIST (pv
))
1087 longjmp (i
->env
, 1);
1093 pv_arc_callback (const BoxType
* b
, void *cl
)
1095 PinTypePtr pv
= (PinTypePtr
) b
;
1096 struct lo_info
*i
= (struct lo_info
*) cl
;
1098 if (!TEST_FLAG (TheFlag
, pv
) && IS_PV_ON_ARC (pv
, &i
->arc
))
1100 if (TEST_FLAG (HOLEFLAG
, pv
))
1102 SET_FLAG (WARNFLAG
, pv
);
1103 Settings
.RatWarn
= True
;
1104 Message (_("WARNING: Hole touches arc.\n"));
1106 if (ADD_PV_TO_LIST (pv
))
1107 longjmp (i
->env
, 1);
1113 pv_poly_callback (const BoxType
* b
, void *cl
)
1115 PinTypePtr pv
= (PinTypePtr
) b
;
1116 struct lo_info
*i
= (struct lo_info
*) cl
;
1118 /* note that holes in polygons are ok */
1119 if (!TEST_FLAG (TheFlag
, pv
) && (TEST_THERM (i
->layer
, pv
) ||
1120 !TEST_FLAG (CLEARPOLYFLAG
, &i
->polygon
) ||
1123 if (TEST_FLAG (SQUAREFLAG
, pv
))
1125 LocationType x1
, x2
, y1
, y2
;
1126 x1
= pv
->X
- (pv
->Thickness
+ 1 + Bloat
) / 2;
1127 x2
= pv
->X
+ (pv
->Thickness
+ 1 + Bloat
) / 2;
1128 y1
= pv
->Y
- (pv
->Thickness
+ 1 + Bloat
) / 2;
1129 y2
= pv
->Y
+ (pv
->Thickness
+ 1 + Bloat
) / 2;
1130 if (IsRectangleInPolygon (x1
, y1
, x2
, y2
, &i
->polygon
)
1131 && ADD_PV_TO_LIST (pv
))
1132 longjmp (i
->env
, 1);
1134 else if (TEST_FLAG (OCTAGONFLAG
, pv
))
1136 POLYAREA
*oct
= OctagonPoly (pv
->X
, pv
->Y
, pv
->Thickness
/ 2);
1137 if (isects (oct
, &i
->polygon
, True
) && ADD_PV_TO_LIST (pv
))
1138 longjmp (i
->env
, 1);
1142 if (IsPointInPolygon
1143 (pv
->X
, pv
->Y
, pv
->Thickness
* 0.5 + fBloat
, &i
->polygon
)
1144 && ADD_PV_TO_LIST (pv
))
1145 longjmp (i
->env
, 1);
1152 pv_rat_callback (const BoxType
* b
, void *cl
)
1154 PinTypePtr pv
= (PinTypePtr
) b
;
1155 struct lo_info
*i
= (struct lo_info
*) cl
;
1157 /* rats can't cause DRC so there is no early exit */
1158 if (!TEST_FLAG (TheFlag
, pv
) && IS_PV_ON_RAT (pv
, &i
->rat
))
1159 ADD_PV_TO_LIST (pv
);
1163 /* ---------------------------------------------------------------------------
1164 * searches for new PVs that are connected to NEW LOs on the list
1165 * This routine updates the position counter of the lists too.
1168 LookupPVConnectionsToLOList (Boolean AndRats
)
1171 struct lo_info info
;
1173 /* loop over all layers */
1174 for (layer
= 0; layer
< max_layer
; layer
++)
1176 /* do nothing if there are no PV's */
1177 if (TotalP
+ TotalV
== 0)
1179 LineList
[layer
].Location
= LineList
[layer
].Number
;
1180 ArcList
[layer
].Location
= ArcList
[layer
].Number
;
1181 PolygonList
[layer
].Location
= PolygonList
[layer
].Number
;
1185 /* check all lines */
1186 while (LineList
[layer
].Location
< LineList
[layer
].Number
)
1188 info
.line
= *(LINELIST_ENTRY (layer
, LineList
[layer
].Location
));
1189 EXPAND_BOUNDS (&info
.line
);
1190 if (setjmp (info
.env
) == 0)
1191 r_search (PCB
->Data
->via_tree
, (BoxType
*) & info
.line
, NULL
,
1192 pv_line_callback
, &info
);
1195 if (setjmp (info
.env
) == 0)
1196 r_search (PCB
->Data
->pin_tree
, (BoxType
*) & info
.line
, NULL
,
1197 pv_line_callback
, &info
);
1200 LineList
[layer
].Location
++;
1203 /* check all arcs */
1204 while (ArcList
[layer
].Location
< ArcList
[layer
].Number
)
1206 info
.arc
= *(ARCLIST_ENTRY (layer
, ArcList
[layer
].Location
));
1207 EXPAND_BOUNDS (&info
.arc
);
1208 if (setjmp (info
.env
) == 0)
1209 r_search (PCB
->Data
->via_tree
, (BoxType
*) & info
.arc
, NULL
,
1210 pv_arc_callback
, &info
);
1213 if (setjmp (info
.env
) == 0)
1214 r_search (PCB
->Data
->pin_tree
, (BoxType
*) & info
.arc
, NULL
,
1215 pv_arc_callback
, &info
);
1218 ArcList
[layer
].Location
++;
1221 /* now all polygons */
1223 while (PolygonList
[layer
].Location
< PolygonList
[layer
].Number
)
1226 *(POLYGONLIST_ENTRY (layer
, PolygonList
[layer
].Location
));
1227 EXPAND_BOUNDS (&info
.polygon
);
1228 if (setjmp (info
.env
) == 0)
1229 r_search (PCB
->Data
->via_tree
, (BoxType
*) & info
.polygon
, NULL
,
1230 pv_poly_callback
, &info
);
1233 if (setjmp (info
.env
) == 0)
1234 r_search (PCB
->Data
->pin_tree
, (BoxType
*) & info
.polygon
, NULL
,
1235 pv_poly_callback
, &info
);
1238 PolygonList
[layer
].Location
++;
1242 /* loop over all pad-layers */
1243 for (layer
= 0; layer
< 2; layer
++)
1245 /* do nothing if there are no PV's */
1246 if (TotalP
+ TotalV
== 0)
1248 PadList
[layer
].Location
= PadList
[layer
].Number
;
1252 /* check all pads; for a detailed description see
1253 * the handling of lines in this subroutine
1255 while (PadList
[layer
].Location
< PadList
[layer
].Number
)
1257 info
.pad
= *(PADLIST_ENTRY (layer
, PadList
[layer
].Location
));
1258 EXPAND_BOUNDS (&info
.pad
);
1259 if (setjmp (info
.env
) == 0)
1260 r_search (PCB
->Data
->via_tree
, (BoxType
*) & info
.pad
, NULL
,
1261 pv_pad_callback
, &info
);
1264 if (setjmp (info
.env
) == 0)
1265 r_search (PCB
->Data
->pin_tree
, (BoxType
*) & info
.pad
, NULL
,
1266 pv_pad_callback
, &info
);
1269 PadList
[layer
].Location
++;
1273 /* do nothing if there are no PV's */
1274 if (TotalP
+ TotalV
== 0)
1275 RatList
.Location
= RatList
.Number
;
1277 /* check all rat-lines */
1280 while (RatList
.Location
< RatList
.Number
)
1282 info
.rat
= *(RATLIST_ENTRY (RatList
.Location
));
1283 r_search_pt (PCB
->Data
->via_tree
, & info
.rat
.Point1
, 1, NULL
,
1284 pv_rat_callback
, &info
);
1285 r_search_pt (PCB
->Data
->via_tree
, & info
.rat
.Point2
, 1, NULL
,
1286 pv_rat_callback
, &info
);
1287 r_search_pt (PCB
->Data
->pin_tree
, & info
.rat
.Point1
, 1, NULL
,
1288 pv_rat_callback
, &info
);
1289 r_search_pt (PCB
->Data
->pin_tree
, & info
.rat
.Point2
, 1, NULL
,
1290 pv_rat_callback
, &info
);
1299 pv_touch_callback (const BoxType
* b
, void *cl
)
1301 PinTypePtr pin
= (PinTypePtr
) b
;
1302 struct lo_info
*i
= (struct lo_info
*) cl
;
1304 if (!TEST_FLAG (TheFlag
, pin
) && PinLineIntersect (pin
, &i
->line
))
1305 longjmp (i
->env
, 1);
1310 PVTouchesLine (LineTypePtr line
)
1312 struct lo_info info
;
1315 EXPAND_BOUNDS (&info
.line
);
1316 if (setjmp (info
.env
) == 0)
1317 r_search (PCB
->Data
->via_tree
, (BoxType
*) & info
.line
, NULL
,
1318 pv_touch_callback
, &info
);
1321 if (setjmp (info
.env
) == 0)
1322 r_search (PCB
->Data
->pin_tree
, (BoxType
*) & info
.line
, NULL
,
1323 pv_touch_callback
, &info
);
1330 /* ---------------------------------------------------------------------------
1331 * check if two arcs intersect
1332 * first we check for circle intersections,
1333 * then find the actual points of intersection
1334 * and test them to see if they are on both arcs
1336 * consider a, the distance from the center of arc 1
1337 * to the point perpendicular to the intersecting points.
1339 * a = (r1^2 - r2^2 + l^2)/(2l)
1341 * the perpendicular distance to the point of intersection
1344 * d = sqrt(r1^2 - a^2)
1346 * the points of intersection would then be
1348 * x = X1 + a/l dx +- d/l dy
1349 * y = Y1 + a/l dy -+ d/l dx
1351 * where dx = X2 - X1 and dy = Y2 - Y1
1356 ArcArcIntersect (ArcTypePtr Arc1
, ArcTypePtr Arc2
)
1358 register float x
, y
, dx
, dy
, r1
, r2
, a
, d
, l
, t
, t2
;
1359 register LocationType pdx
, pdy
;
1363 pdx
= Arc2
->X
- Arc1
->X
;
1364 pdy
= Arc2
->Y
- Arc1
->Y
;
1365 l
= pdx
* pdx
+ pdy
* pdy
;
1366 t
= MAX (0.5 * Arc1
->Thickness
+ fBloat
, 0.0);
1367 t2
= 0.5 * Arc2
->Thickness
;
1368 /* concentric arcs, simpler intersection conditions */
1371 if ((Arc1
->Width
- t
>= Arc2
->Width
- t2
1372 && Arc1
->Width
- t
<=
1374 || (Arc1
->Width
+ t
>=
1375 Arc2
->Width
- t2
&& Arc1
->Width
+ t
<= Arc2
->Width
+ t2
))
1377 if ((Arc2
->BoundingBox
.X1
+
1378 MAX (Arc2
->Thickness
+ Bloat
,
1379 0) >= Arc1
->BoundingBox
.X1
1380 && Arc2
->BoundingBox
.X1
<=
1381 Arc1
->BoundingBox
.X2
1382 && Arc2
->BoundingBox
.Y1
+
1383 MAX (Arc2
->Thickness
+ Bloat
,
1384 0) >= Arc1
->BoundingBox
.Y1
1385 && Arc2
->BoundingBox
.Y1
<=
1386 Arc1
->BoundingBox
.Y2
)
1387 || (Arc2
->BoundingBox
.X2
+
1388 MAX (Arc2
->Thickness
+
1391 Arc1
->BoundingBox
.X1
1392 && Arc2
->BoundingBox
.X2
<=
1393 Arc1
->BoundingBox
.X2
1394 && Arc2
->BoundingBox
.Y2
+
1395 MAX (Arc2
->Thickness
+
1398 Arc1
->BoundingBox
.Y1
1399 && Arc2
->BoundingBox
.Y2
<= Arc1
->BoundingBox
.Y2
))
1404 r1
= Arc1
->Width
+ t
;
1406 r2
= Arc2
->Width
+ t2
;
1408 a
= 0.5 * (r1
- r2
+ l
) / l
;
1410 /* add a tiny positive number for round-off problems */
1411 d
= r1
- a
* a
+ 1e-5;
1412 /* the circles are too far apart to touch */
1416 x
= Arc1
->X
+ a
* pdx
;
1417 y
= Arc1
->Y
+ a
* pdy
;
1420 if (x
+ dy
>= Arc1
->BoundingBox
.X1
1421 && x
+ dy
<= Arc1
->BoundingBox
.X2
1422 && y
- dx
>= Arc1
->BoundingBox
.Y1
1423 && y
- dx
<= Arc1
->BoundingBox
.Y2
1424 && x
+ dy
>= Arc2
->BoundingBox
.X1
1425 && x
+ dy
<= Arc2
->BoundingBox
.X2
1426 && y
- dx
>= Arc2
->BoundingBox
.Y1
&& y
- dx
<= Arc2
->BoundingBox
.Y2
)
1429 if (x
- dy
>= Arc1
->BoundingBox
.X1
1430 && x
- dy
<= Arc1
->BoundingBox
.X2
1431 && y
+ dx
>= Arc1
->BoundingBox
.Y1
1432 && y
+ dx
<= Arc1
->BoundingBox
.Y2
1433 && x
- dy
>= Arc2
->BoundingBox
.X1
1434 && x
- dy
<= Arc2
->BoundingBox
.X2
1435 && y
+ dx
>= Arc2
->BoundingBox
.Y1
&& y
+ dx
<= Arc2
->BoundingBox
.Y2
)
1438 /* try the end points in case the ends don't actually pierce the outer radii */
1439 box
= GetArcEnds (Arc1
);
1441 box
= GetArcEnds (Arc2
);
1444 ((float) box1
.X1
, (float) box1
.Y1
, t
,
1445 Arc2
) || IsPointOnArc ((float) box1
.X2
, (float) box1
.Y2
, t
, Arc2
))
1449 ((float) box2
.X1
, (float) box2
.Y1
,
1450 MAX (t2
+ fBloat
, 0.0), Arc1
)
1451 || IsPointOnArc ((float) box2
.X2
,
1452 (float) box2
.Y2
, MAX (t2
+ fBloat
, 0.0), Arc1
))
1457 /* ---------------------------------------------------------------------------
1458 * Tests if point is same as line end point
1461 IsRatPointOnLineEnd (PointTypePtr Point
, LineTypePtr Line
)
1463 if ((Point
->X
== Line
->Point1
.X
1464 && Point
->Y
== Line
->Point1
.Y
)
1465 || (Point
->X
== Line
->Point2
.X
&& Point
->Y
== Line
->Point2
.Y
))
1471 form_slanted_rectangle(PointType p
[4],LineTypePtr l
)
1472 /* writes vertices of a squared line */
1474 int dX
= l
->Point2
.X
- l
->Point1
.X
, dY
= l
->Point2
.Y
- l
->Point1
.Y
,
1479 dwx
= w
/ 2; dwy
= 0;
1483 dwx
= 0; dwy
= w
/ 2;
1486 {double r
= sqrt (dX
* (double) dX
+ dY
* (double) dY
) * 2;
1487 dwx
= w
/ r
* dX
; dwy
= w
/ r
* dY
;
1489 p
[0].X
= l
->Point1
.X
- dwx
+ dwy
; p
[0].Y
= l
->Point1
.Y
- dwy
- dwx
;
1490 p
[1].X
= l
->Point1
.X
- dwx
- dwy
; p
[1].Y
= l
->Point1
.Y
- dwy
+ dwx
;
1491 p
[2].X
= l
->Point2
.X
+ dwx
- dwy
; p
[2].Y
= l
->Point2
.Y
+ dwy
+ dwx
;
1492 p
[3].X
= l
->Point2
.X
+ dwx
+ dwy
; p
[3].Y
= l
->Point2
.Y
+ dwy
- dwx
;
1494 /* ---------------------------------------------------------------------------
1495 * checks if two lines intersect
1498 * Let A,B,C,D be 2-space position vectors. Then the directed line
1499 * segments AB & CD are given by:
1501 * AB=A+r(B-A), r in [0,1]
1502 * CD=C+s(D-C), s in [0,1]
1504 * If AB & CD intersect, then
1506 * A+r(B-A)=C+s(D-C), or
1508 * XA+r(XB-XA)=XC+s(XD-XC)
1509 * YA+r(YB-YA)=YC+s(YD-YC) for some r,s in [0,1]
1511 * Solving the above for r and s yields
1513 * (YA-YC)(XD-XC)-(XA-XC)(YD-YC)
1514 * r = ----------------------------- (eqn 1)
1515 * (XB-XA)(YD-YC)-(YB-YA)(XD-XC)
1517 * (YA-YC)(XB-XA)-(XA-XC)(YB-YA)
1518 * s = ----------------------------- (eqn 2)
1519 * (XB-XA)(YD-YC)-(YB-YA)(XD-XC)
1521 * Let I be the position vector of the intersection point, then
1528 * By examining the values of r & s, you can also determine some
1529 * other limiting conditions:
1531 * If 0<=r<=1 & 0<=s<=1, intersection exists
1532 * r<0 or r>1 or s<0 or s>1 line segments do not intersect
1534 * If the denominator in eqn 1 is zero, AB & CD are parallel
1535 * If the numerator in eqn 1 is also zero, AB & CD are coincident
1537 * If the intersection point of the 2 lines are needed (lines in this
1538 * context mean infinite lines) regardless whether the two line
1539 * segments intersect, then
1541 * If r>1, I is located on extension of AB
1542 * If r<0, I is located on extension of BA
1543 * If s>1, I is located on extension of CD
1544 * If s<0, I is located on extension of DC
1546 * Also note that the denominators of eqn 1 & 2 are identical.
1550 LineLineIntersect (LineTypePtr Line1
, LineTypePtr Line2
)
1552 register float dx
, dy
, dx1
, dy1
, s
, r
;
1553 if (TEST_FLAG (SQUAREFLAG
, Line1
))/* pretty reckless recursion */
1555 PointType p
[4];form_slanted_rectangle(p
,Line1
);
1556 return IsLineInQuadrangle(p
,Line2
);
1558 /* here come only round Line1 because IsLineInQuadrangle()
1559 calls LineLineIntersect() with first argument rounded*/
1560 if (TEST_FLAG (SQUAREFLAG
, Line2
))
1562 PointType p
[4];form_slanted_rectangle(p
,Line2
);
1563 return IsLineInQuadrangle(p
,Line1
);
1565 /* now all lines are round */
1568 if (Line1
->BoundingBox
.X1
- Bloat
> Line2
->BoundBoxing
.X2
1569 || Line1
->BoundingBox
.X2
+ Bloat
< Line2
->BoundingBox
.X1
1570 || Line1
->BoundingBox
.Y1
- Bloat
< Line2
->BoundingBox
.Y2
1571 || Line1
->BoundingBox
.Y2
+ Bloat
< Line2
->BoundingBox
.Y1
)
1575 /* setup some constants */
1576 dx
= (float) (Line1
->Point2
.X
- Line1
->Point1
.X
);
1577 dy
= (float) (Line1
->Point2
.Y
- Line1
->Point1
.Y
);
1578 dx1
= (float) (Line1
->Point1
.X
- Line2
->Point1
.X
);
1579 dy1
= (float) (Line1
->Point1
.Y
- Line2
->Point1
.Y
);
1580 s
= dy1
* dx
- dx1
* dy
;
1583 dx
* (float) (Line2
->Point2
.Y
-
1585 dy
* (float) (Line2
->Point2
.X
- Line2
->Point1
.X
);
1587 /* handle parallel lines */
1590 /* at least one of the two end points of one segment
1591 * has to have a minimum distance to the other segment
1593 * a first quick check is to see if the distance between
1594 * the two lines is less then their half total thickness
1596 register float distance
;
1598 /* perhaps line 1 is really just a point */
1599 if ((dx
== 0) && (dy
== 0))
1603 MAX (Line1
->Thickness
/ 2 +
1605 (PadTypePtr
) Line2
);
1606 s
= s
* s
/ (dx
* dx
+ dy
* dy
);
1611 (Line1
->Thickness
+ Line2
->Thickness
) + fBloat
, 0.0);
1612 distance
*= distance
;
1615 if (IsPointInPad (Line2
->Point1
.
1625 || IsPointInPad (Line2
->
1631 / 2 + Bloat
, 0), (PadTypePtr
) Line1
))
1633 return ((IsPointInPad (Line1
->Point1
.
1643 || IsPointInPad (Line1
->
1649 / 2 + Bloat
, 0), (PadTypePtr
) Line2
)));
1656 (float) (Line2
->Point2
.X
-
1658 dx1
* (float) (Line2
->Point2
.Y
- Line2
->Point1
.Y
)) / r
;
1660 /* intersection is at least on AB */
1661 if (r
>= 0.0 && r
<= 1.0)
1663 if (s
>= 0.0 && s
<= 1.0)
1666 /* intersection on AB and extension of CD */
1674 (PadTypePtr
)Line1
) :
1678 MAX (0.5 * Line2
->Thickness
+ fBloat
, 0.0), (PadTypePtr
)Line1
));
1681 /* intersection is at least on CD */
1682 if (s
>= 0.0 && s
<= 1.0)
1684 /* intersection on CD and extension of AB */
1689 MAX (Line1
->Thickness
/
1691 (PadTypePtr
)Line2
) :
1695 MAX (Line1
->Thickness
/ 2.0 + fBloat
, 0.0), (PadTypePtr
)Line2
));
1698 /* no intersection of zero-width lines but maybe of thick lines;
1699 * Must check each end point to exclude intersection
1701 if (IsPointInPad (Line1
->Point1
.X
, Line1
->Point1
.Y
,
1702 Line1
->Thickness
/ 2.0 + fBloat
, (PadTypePtr
)Line2
))
1704 if (IsPointInPad (Line1
->Point2
.X
, Line1
->Point2
.Y
,
1705 Line1
->Thickness
/ 2.0 + fBloat
, (PadTypePtr
)Line2
))
1707 if (IsPointInPad (Line2
->Point1
.X
, Line2
->Point1
.Y
,
1708 Line2
->Thickness
/ 2.0 + fBloat
, (PadTypePtr
)Line1
))
1710 return IsPointInPad (Line2
->Point2
.X
, Line2
->Point2
.Y
,
1711 Line2
->Thickness
/ 2.0 + fBloat
, (PadTypePtr
)Line1
);
1715 /*---------------------------------------------------
1717 * Check for line intersection with an arc
1719 * Mostly this is like the circle/line intersection
1720 * found in IsPointOnLine (search.c) see the detailed
1721 * discussion for the basics there.
1723 * Since this is only an arc, not a full circle we need
1724 * to find the actual points of intersection with the
1725 * circle, and see if they are on the arc.
1727 * To do this, we translate along the line from the point Q
1728 * plus or minus a distance delta = sqrt(Radius^2 - d^2)
1729 * but it's handy to normalize with respect to l, the line
1730 * length so a single projection is done (e.g. we don't first
1733 * The projection is now of the form
1735 * Px = X1 + (r +- r2)(X2 - X1)
1736 * Py = Y1 + (r +- r2)(Y2 - Y1)
1738 * Where r2 sqrt(Radius^2 l^2 - d^2)/l^2
1739 * note that this is the variable d, not the symbol d described in IsPointOnLine
1740 * (variable d = symbol d * l)
1742 * The end points are hell so they are checked individually
1745 LineArcIntersect (LineTypePtr Line
, ArcTypePtr Arc
)
1747 register float dx
, dy
, dx1
, dy1
, l
, d
, r
, r2
, Radius
;
1750 dx
= (float) (Line
->Point2
.X
- Line
->Point1
.X
);
1751 dy
= (float) (Line
->Point2
.Y
- Line
->Point1
.Y
);
1752 dx1
= (float) (Line
->Point1
.X
- Arc
->X
);
1753 dy1
= (float) (Line
->Point1
.Y
- Arc
->Y
);
1754 l
= dx
* dx
+ dy
* dy
;
1755 d
= dx
* dy1
- dy
* dx1
;
1758 /* use the larger diameter circle first */
1760 Arc
->Width
+ MAX (0.5 * (Arc
->Thickness
+ Line
->Thickness
) + fBloat
, 0.0);
1762 r2
= Radius
* l
- d
;
1763 /* projection doesn't even intersect circle when r2 < 0 */
1766 /* check the ends of the line in case the projected point */
1767 /* of intersection is beyond the line end */
1769 (Line
->Point1
.X
, Line
->Point1
.Y
,
1770 MAX (0.5 * Line
->Thickness
+ fBloat
, 0.0), Arc
))
1773 (Line
->Point2
.X
, Line
->Point2
.Y
,
1774 MAX (0.5 * Line
->Thickness
+ fBloat
, 0.0), Arc
))
1779 Radius
= -(dx
* dx1
+ dy
* dy1
);
1780 r
= (Radius
+ r2
) / l
;
1781 if (r
>= 0 && r
<= 1
1782 && IsPointOnArc (Line
->Point1
.X
+ r
* dx
,
1783 Line
->Point1
.Y
+ r
* dy
,
1784 MAX (0.5 * Line
->Thickness
+ fBloat
, 0.0), Arc
))
1786 r
= (Radius
- r2
) / l
;
1787 if (r
>= 0 && r
<= 1
1788 && IsPointOnArc (Line
->Point1
.X
+ r
* dx
,
1789 Line
->Point1
.Y
+ r
* dy
,
1790 MAX (0.5 * Line
->Thickness
+ fBloat
, 0.0), Arc
))
1792 /* check arc end points */
1793 box
= GetArcEnds (Arc
);
1794 if (IsPointInPad (box
->X1
, box
->Y1
, Arc
->Thickness
* 0.5 + fBloat
, (PadTypePtr
)Line
))
1796 if (IsPointInPad (box
->X2
, box
->Y2
, Arc
->Thickness
* 0.5 + fBloat
, (PadTypePtr
)Line
))
1802 LOCtoArcLine_callback (const BoxType
* b
, void *cl
)
1804 LineTypePtr line
= (LineTypePtr
) b
;
1805 struct lo_info
*i
= (struct lo_info
*) cl
;
1807 if (!TEST_FLAG (TheFlag
, line
) && LineArcIntersect (line
, &i
->arc
))
1809 if (ADD_LINE_TO_LIST (i
->layer
, line
))
1810 longjmp (i
->env
, 1);
1816 LOCtoArcArc_callback (const BoxType
* b
, void *cl
)
1818 ArcTypePtr arc
= (ArcTypePtr
) b
;
1819 struct lo_info
*i
= (struct lo_info
*) cl
;
1821 if (!arc
->Thickness
)
1823 if (!TEST_FLAG (TheFlag
, arc
) && ArcArcIntersect (&i
->arc
, arc
))
1825 if (ADD_ARC_TO_LIST (i
->layer
, arc
))
1826 longjmp (i
->env
, 1);
1832 LOCtoArcPad_callback (const BoxType
* b
, void *cl
)
1834 PadTypePtr pad
= (PadTypePtr
) b
;
1835 struct lo_info
*i
= (struct lo_info
*) cl
;
1837 if (!TEST_FLAG (TheFlag
, pad
) && i
->layer
==
1838 (TEST_FLAG (ONSOLDERFLAG
, pad
) ? SOLDER_LAYER
: COMPONENT_LAYER
)
1839 && ArcPadIntersect (&i
->arc
, pad
) && ADD_PAD_TO_LIST (i
->layer
, pad
))
1840 longjmp (i
->env
, 1);
1844 /* ---------------------------------------------------------------------------
1845 * searches all LOs that are connected to the given arc on the given
1846 * layergroup. All found connections are added to the list
1848 * the notation that is used is:
1849 * Xij means Xj at arc i
1852 LookupLOConnectionsToArc (ArcTypePtr Arc
, Cardinal LayerGroup
)
1855 LocationType xlow
, xhigh
;
1856 struct lo_info info
;
1858 /* the maximum possible distance */
1859 xlow
= Arc
->BoundingBox
.X1
- MAX (MAX_PADSIZE
, MAX_LINESIZE
) / 2;
1860 xhigh
= Arc
->BoundingBox
.X2
+ MAX (MAX_PADSIZE
, MAX_LINESIZE
) / 2;
1863 EXPAND_BOUNDS (&info
.arc
);
1864 /* loop over all layers of the group */
1865 for (entry
= 0; entry
< PCB
->LayerGroups
.Number
[LayerGroup
]; entry
++)
1869 layer
= PCB
->LayerGroups
.Entries
[LayerGroup
][entry
];
1871 /* handle normal layers */
1872 if (layer
< max_layer
)
1874 PolygonTypePtr polygon
;
1878 if (setjmp (info
.env
) == 0)
1879 r_search (LAYER_PTR (layer
)->line_tree
, &info
.arc
.BoundingBox
,
1880 NULL
, LOCtoArcLine_callback
, &info
);
1884 if (setjmp (info
.env
) == 0)
1885 r_search (LAYER_PTR (layer
)->arc_tree
, &info
.arc
.BoundingBox
,
1886 NULL
, LOCtoArcArc_callback
, &info
);
1890 /* now check all polygons */
1892 polygon
= PCB
->Data
->Layer
[layer
].Polygon
;
1893 for (; i
< PCB
->Data
->Layer
[layer
].PolygonN
; i
++, polygon
++)
1894 if (!TEST_FLAG (TheFlag
, polygon
) && IsArcInPolygon (Arc
, polygon
)
1895 && ADD_POLYGON_TO_LIST (layer
, polygon
))
1900 info
.layer
= layer
- max_layer
;
1901 if (setjmp (info
.env
) == 0)
1902 r_search (PCB
->Data
->pad_tree
, &info
.arc
.BoundingBox
, NULL
,
1903 LOCtoArcPad_callback
, &info
);
1912 LOCtoLineLine_callback (const BoxType
* b
, void *cl
)
1914 LineTypePtr line
= (LineTypePtr
) b
;
1915 struct lo_info
*i
= (struct lo_info
*) cl
;
1917 if (!TEST_FLAG (TheFlag
, line
) && LineLineIntersect (&i
->line
, line
))
1919 if (ADD_LINE_TO_LIST (i
->layer
, line
))
1920 longjmp (i
->env
, 1);
1926 LOCtoLineArc_callback (const BoxType
* b
, void *cl
)
1928 ArcTypePtr arc
= (ArcTypePtr
) b
;
1929 struct lo_info
*i
= (struct lo_info
*) cl
;
1931 if (!arc
->Thickness
)
1933 if (!TEST_FLAG (TheFlag
, arc
) && LineArcIntersect (&i
->line
, arc
))
1935 if (ADD_ARC_TO_LIST (i
->layer
, arc
))
1936 longjmp (i
->env
, 1);
1942 LOCtoLineRat_callback (const BoxType
* b
, void *cl
)
1944 RatTypePtr rat
= (RatTypePtr
) b
;
1945 struct lo_info
*i
= (struct lo_info
*) cl
;
1947 if (!TEST_FLAG (TheFlag
, rat
))
1949 if ((rat
->group1
== i
->layer
)
1950 && IsRatPointOnLineEnd (&rat
->Point1
, &i
->line
))
1952 if (ADD_RAT_TO_LIST (rat
))
1953 longjmp (i
->env
, 1);
1955 else if ((rat
->group2
== i
->layer
)
1956 && IsRatPointOnLineEnd (&rat
->Point2
, &i
->line
))
1958 if (ADD_RAT_TO_LIST (rat
))
1959 longjmp (i
->env
, 1);
1966 LOCtoLinePad_callback (const BoxType
* b
, void *cl
)
1968 PadTypePtr pad
= (PadTypePtr
) b
;
1969 struct lo_info
*i
= (struct lo_info
*) cl
;
1971 if (!TEST_FLAG (TheFlag
, pad
) && i
->layer
==
1972 (TEST_FLAG (ONSOLDERFLAG
, pad
) ? SOLDER_LAYER
: COMPONENT_LAYER
)
1973 && LinePadIntersect (&i
->line
, pad
) && ADD_PAD_TO_LIST (i
->layer
, pad
))
1974 longjmp (i
->env
, 1);
1978 /* ---------------------------------------------------------------------------
1979 * searches all LOs that are connected to the given line on the given
1980 * layergroup. All found connections are added to the list
1982 * the notation that is used is:
1983 * Xij means Xj at line i
1986 LookupLOConnectionsToLine (LineTypePtr Line
, Cardinal LayerGroup
,
1990 struct lo_info info
;
1993 info
.layer
= LayerGroup
;
1994 EXPAND_BOUNDS (&info
.line
)
1995 /* add the new rat lines */
1996 if (setjmp (info
.env
) == 0)
1997 r_search (PCB
->Data
->rat_tree
, &info
.line
.BoundingBox
, NULL
,
1998 LOCtoLineRat_callback
, &info
);
2002 /* loop over all layers of the group */
2003 for (entry
= 0; entry
< PCB
->LayerGroups
.Number
[LayerGroup
]; entry
++)
2007 layer
= PCB
->LayerGroups
.Entries
[LayerGroup
][entry
];
2009 /* handle normal layers */
2010 if (layer
< max_layer
)
2012 PolygonTypePtr polygon
;
2016 if (setjmp (info
.env
) == 0)
2017 r_search (LAYER_PTR (layer
)->line_tree
, (BoxType
*) & info
.line
,
2018 NULL
, LOCtoLineLine_callback
, &info
);
2022 if (setjmp (info
.env
) == 0)
2023 r_search (LAYER_PTR (layer
)->arc_tree
, (BoxType
*) & info
.line
,
2024 NULL
, LOCtoLineArc_callback
, &info
);
2027 /* now check all polygons */
2031 polygon
= PCB
->Data
->Layer
[layer
].Polygon
;
2032 for (; i
< PCB
->Data
->Layer
[layer
].PolygonN
; i
++, polygon
++)
2034 (TheFlag
, polygon
) && IsLineInPolygon (Line
, polygon
)
2035 && ADD_POLYGON_TO_LIST (layer
, polygon
))
2041 /* handle special 'pad' layers */
2042 info
.layer
= layer
- max_layer
;
2043 if (setjmp (info
.env
) == 0)
2044 r_search (PCB
->Data
->pad_tree
, &info
.line
.BoundingBox
, NULL
,
2045 LOCtoLinePad_callback
, &info
);
2054 LOT_Linecallback (const BoxType
* b
, void *cl
)
2056 LineTypePtr line
= (LineTypePtr
) b
;
2057 struct lo_info
*i
= (struct lo_info
*) cl
;
2059 if (!TEST_FLAG (TheFlag
, line
) && LineLineIntersect (&i
->line
, line
))
2060 longjmp (i
->env
, 1);
2065 LOT_Arccallback (const BoxType
* b
, void *cl
)
2067 ArcTypePtr arc
= (ArcTypePtr
) b
;
2068 struct lo_info
*i
= (struct lo_info
*) cl
;
2070 if (!arc
->Thickness
)
2072 if (!TEST_FLAG (TheFlag
, arc
) && LineArcIntersect (&i
->line
, arc
))
2073 longjmp (i
->env
, 1);
2078 LOT_Padcallback (const BoxType
* b
, void *cl
)
2080 PadTypePtr pad
= (PadTypePtr
) b
;
2081 struct lo_info
*i
= (struct lo_info
*) cl
;
2083 if (!TEST_FLAG (TheFlag
, pad
) && i
->layer
==
2084 (TEST_FLAG (ONSOLDERFLAG
, pad
) ? SOLDER_LAYER
: COMPONENT_LAYER
)
2085 && LinePadIntersect (&i
->line
, pad
))
2086 longjmp (i
->env
, 1);
2091 LOTouchesLine (LineTypePtr Line
, Cardinal LayerGroup
)
2095 struct lo_info info
;
2098 /* the maximum possible distance */
2101 EXPAND_BOUNDS (&info
.line
);
2103 /* loop over all layers of the group */
2104 for (entry
= 0; entry
< PCB
->LayerGroups
.Number
[LayerGroup
]; entry
++)
2106 Cardinal layer
= PCB
->LayerGroups
.Entries
[LayerGroup
][entry
];
2108 /* handle normal layers */
2109 if (layer
< max_layer
)
2111 PolygonTypePtr polygon
;
2113 /* find the first line that touches coordinates */
2115 if (setjmp (info
.env
) == 0)
2116 r_search (LAYER_PTR (layer
)->line_tree
, (BoxType
*) & info
.line
,
2117 NULL
, LOT_Linecallback
, &info
);
2120 if (setjmp (info
.env
) == 0)
2121 r_search (LAYER_PTR (layer
)->arc_tree
, (BoxType
*) & info
.line
,
2122 NULL
, LOT_Arccallback
, &info
);
2126 /* now check all polygons */
2128 polygon
= PCB
->Data
->Layer
[layer
].Polygon
;
2129 for (; i
< PCB
->Data
->Layer
[layer
].PolygonN
; i
++, polygon
++)
2130 if (!TEST_FLAG (TheFlag
, polygon
)
2131 && IsLineInPolygon (Line
, polygon
))
2136 /* handle special 'pad' layers */
2137 info
.layer
= layer
- max_layer
;
2138 if (setjmp (info
.env
) == 0)
2139 r_search (PCB
->Data
->pad_tree
, &info
.line
.BoundingBox
, NULL
,
2140 LOT_Padcallback
, &info
);
2156 LOCtoRat_callback (const BoxType
* b
, void *cl
)
2158 LineTypePtr line
= (LineTypePtr
) b
;
2159 struct rat_info
*i
= (struct rat_info
*) cl
;
2161 if (!TEST_FLAG (TheFlag
, line
) &&
2162 ((line
->Point1
.X
== i
->Point
->X
&&
2163 line
->Point1
.Y
== i
->Point
->Y
) ||
2164 (line
->Point2
.X
== i
->Point
->X
&& line
->Point2
.Y
== i
->Point
->Y
)))
2166 if (ADD_LINE_TO_LIST (i
->layer
, line
))
2167 longjmp (i
->env
, 1);
2172 PolygonToRat_callback (const BoxType
* b
, void *cl
)
2174 PolygonTypePtr polygon
= (PolygonTypePtr
) b
;
2175 struct rat_info
*i
= (struct rat_info
*) cl
;
2177 if (!TEST_FLAG (TheFlag
, polygon
) && polygon
->Clipped
&&
2178 (i
->Point
->X
== polygon
->Clipped
->contours
->head
.point
[0]) &&
2179 (i
->Point
->Y
== polygon
->Clipped
->contours
->head
.point
[1]))
2181 if (ADD_POLYGON_TO_LIST (i
->layer
, polygon
))
2182 longjmp (i
->env
, 1);
2188 LOCtoPad_callback (const BoxType
* b
, void *cl
)
2190 PadTypePtr pad
= (PadTypePtr
) b
;
2191 struct rat_info
*i
= (struct rat_info
*) cl
;
2193 if (!TEST_FLAG (TheFlag
, pad
) && i
->layer
==
2194 (TEST_FLAG (ONSOLDERFLAG
, pad
) ? SOLDER_LAYER
: COMPONENT_LAYER
)
2195 && (((pad
->Point1
.X
== i
->Point
->X
&& pad
->Point1
.Y
== i
->Point
->Y
)) ||
2196 ((pad
->Point2
.X
== i
->Point
->X
&& pad
->Point2
.Y
== i
->Point
->Y
)))
2197 && ADD_PAD_TO_LIST (i
->layer
, pad
))
2198 longjmp (i
->env
, 1);
2202 /* ---------------------------------------------------------------------------
2203 * searches all LOs that are connected to the given rat-line on the given
2204 * layergroup. All found connections are added to the list
2206 * the notation that is used is:
2207 * Xij means Xj at line i
2210 LookupLOConnectionsToRatEnd (PointTypePtr Point
, Cardinal LayerGroup
)
2213 struct rat_info info
;
2216 /* loop over all layers of this group */
2217 for (entry
= 0; entry
< PCB
->LayerGroups
.Number
[LayerGroup
]; entry
++)
2221 layer
= PCB
->LayerGroups
.Entries
[LayerGroup
][entry
];
2222 /* handle normal layers
2223 rats don't ever touch
2227 if (layer
< max_layer
)
2230 if (setjmp (info
.env
) == 0)
2231 r_search_pt (LAYER_PTR (layer
)->line_tree
, Point
, 1, NULL
,
2232 LOCtoRat_callback
, &info
);
2235 if (setjmp (info
.env
) == 0)
2236 r_search_pt (LAYER_PTR (layer
)->polygon_tree
, Point
, 1,
2237 NULL
, PolygonToRat_callback
, &info
);
2241 /* handle special 'pad' layers */
2242 info
.layer
= layer
- max_layer
;
2243 if (setjmp (info
.env
) == 0)
2244 r_search_pt (PCB
->Data
->pad_tree
, Point
, 1, NULL
,
2245 LOCtoPad_callback
, &info
);
2254 LOCtoPadLine_callback (const BoxType
* b
, void *cl
)
2256 LineTypePtr line
= (LineTypePtr
) b
;
2257 struct lo_info
*i
= (struct lo_info
*) cl
;
2259 if (!TEST_FLAG (TheFlag
, line
) && LinePadIntersect (line
, &i
->pad
))
2261 if (ADD_LINE_TO_LIST (i
->layer
, line
))
2262 longjmp (i
->env
, 1);
2268 LOCtoPadArc_callback (const BoxType
* b
, void *cl
)
2270 ArcTypePtr arc
= (ArcTypePtr
) b
;
2271 struct lo_info
*i
= (struct lo_info
*) cl
;
2273 if (!arc
->Thickness
)
2275 if (!TEST_FLAG (TheFlag
, arc
) && ArcPadIntersect (arc
, &i
->pad
))
2277 if (ADD_ARC_TO_LIST (i
->layer
, arc
))
2278 longjmp (i
->env
, 1);
2284 LOCtoPadPoly_callback (const BoxType
* b
, void *cl
)
2286 PolygonTypePtr polygon
= (PolygonTypePtr
) b
;
2287 struct lo_info
*i
= (struct lo_info
*) cl
;
2290 if (!TEST_FLAG (TheFlag
, polygon
) &&
2291 (!TEST_FLAG (CLEARPOLYFLAG
, polygon
) || !i
->pad
.Clearance
))
2293 if (IsPadInPolygon (&i
->pad
, polygon
) &&
2294 ADD_POLYGON_TO_LIST (i
->layer
, polygon
))
2295 longjmp (i
->env
, 1);
2301 LOCtoPadRat_callback (const BoxType
* b
, void *cl
)
2303 RatTypePtr rat
= (RatTypePtr
) b
;
2304 struct lo_info
*i
= (struct lo_info
*) cl
;
2306 if (!TEST_FLAG (TheFlag
, rat
))
2308 if (rat
->group1
== i
->layer
&&
2309 ((rat
->Point1
.X
== i
->pad
.Point1
.X
2310 && rat
->Point1
.Y
== i
->pad
.Point1
.Y
)
2311 || (rat
->Point1
.X
== i
->pad
.Point2
.X
2312 && rat
->Point1
.Y
== i
->pad
.Point2
.Y
)))
2314 if (ADD_RAT_TO_LIST (rat
))
2315 longjmp (i
->env
, 1);
2317 else if (rat
->group2
== i
->layer
&&
2318 ((rat
->Point2
.X
== i
->pad
.Point1
.X
2319 && rat
->Point2
.Y
== i
->pad
.Point1
.Y
)
2320 || (rat
->Point2
.X
== i
->pad
.Point2
.X
2321 && rat
->Point2
.Y
== i
->pad
.Point2
.Y
)))
2323 if (ADD_RAT_TO_LIST (rat
))
2324 longjmp (i
->env
, 1);
2331 LOCtoPadPad_callback (const BoxType
* b
, void *cl
)
2333 PadTypePtr pad
= (PadTypePtr
) b
;
2334 struct lo_info
*i
= (struct lo_info
*) cl
;
2336 if (!TEST_FLAG (TheFlag
, pad
) && i
->layer
==
2337 (TEST_FLAG (ONSOLDERFLAG
, pad
) ? SOLDER_LAYER
: COMPONENT_LAYER
)
2338 && PadPadIntersect (pad
, &i
->pad
) && ADD_PAD_TO_LIST (i
->layer
, pad
))
2339 longjmp (i
->env
, 1);
2343 /* ---------------------------------------------------------------------------
2344 * searches all LOs that are connected to the given pad on the given
2345 * layergroup. All found connections are added to the list
2348 LookupLOConnectionsToPad (PadTypePtr Pad
, Cardinal LayerGroup
)
2351 struct lo_info info
;
2353 if (!TEST_FLAG (SQUAREFLAG
, Pad
))
2354 return (LookupLOConnectionsToLine ((LineTypePtr
) Pad
, LayerGroup
, False
));
2357 EXPAND_BOUNDS (&info
.pad
);
2358 /* add the new rat lines */
2359 info
.layer
= LayerGroup
;
2360 if (setjmp (info
.env
) == 0)
2361 r_search (PCB
->Data
->rat_tree
, &info
.pad
.BoundingBox
, NULL
,
2362 LOCtoPadRat_callback
, &info
);
2366 /* loop over all layers of the group */
2367 for (entry
= 0; entry
< PCB
->LayerGroups
.Number
[LayerGroup
]; entry
++)
2371 layer
= PCB
->LayerGroups
.Entries
[LayerGroup
][entry
];
2372 /* handle normal layers */
2373 if (layer
< max_layer
)
2377 if (setjmp (info
.env
) == 0)
2378 r_search (LAYER_PTR (layer
)->line_tree
, &info
.pad
.BoundingBox
,
2379 NULL
, LOCtoPadLine_callback
, &info
);
2383 if (setjmp (info
.env
) == 0)
2384 r_search (LAYER_PTR (layer
)->arc_tree
, &info
.pad
.BoundingBox
,
2385 NULL
, LOCtoPadArc_callback
, &info
);
2389 if (setjmp (info
.env
) == 0)
2390 r_search (LAYER_PTR (layer
)->polygon_tree
, &info
.pad
.BoundingBox
,
2391 NULL
, LOCtoPadPoly_callback
, &info
);
2397 /* handle special 'pad' layers */
2398 info
.layer
= layer
- max_layer
;
2399 if (setjmp (info
.env
) == 0)
2400 r_search (PCB
->Data
->pad_tree
, (BoxType
*) & info
.pad
, NULL
,
2401 LOCtoPadPad_callback
, &info
);
2411 LOCtoPolyLine_callback (const BoxType
* b
, void *cl
)
2413 LineTypePtr line
= (LineTypePtr
) b
;
2414 struct lo_info
*i
= (struct lo_info
*) cl
;
2416 if (!TEST_FLAG (TheFlag
, line
) && IsLineInPolygon (line
, &i
->polygon
))
2418 if (ADD_LINE_TO_LIST (i
->layer
, line
))
2419 longjmp (i
->env
, 1);
2425 LOCtoPolyArc_callback (const BoxType
* b
, void *cl
)
2427 ArcTypePtr arc
= (ArcTypePtr
) b
;
2428 struct lo_info
*i
= (struct lo_info
*) cl
;
2430 if (!arc
->Thickness
)
2432 if (!TEST_FLAG (TheFlag
, arc
) && IsArcInPolygon (arc
, &i
->polygon
))
2434 if (ADD_ARC_TO_LIST (i
->layer
, arc
))
2435 longjmp (i
->env
, 1);
2441 LOCtoPolyPad_callback (const BoxType
* b
, void *cl
)
2443 PadTypePtr pad
= (PadTypePtr
) b
;
2444 struct lo_info
*i
= (struct lo_info
*) cl
;
2446 if (!TEST_FLAG (TheFlag
, pad
) && i
->layer
==
2447 (TEST_FLAG (ONSOLDERFLAG
, pad
) ? SOLDER_LAYER
: COMPONENT_LAYER
)
2448 && IsPadInPolygon (pad
, &i
->polygon
))
2450 if (ADD_PAD_TO_LIST (i
->layer
, pad
))
2451 longjmp (i
->env
, 1);
2457 LOCtoPolyRat_callback (const BoxType
* b
, void *cl
)
2459 RatTypePtr rat
= (RatTypePtr
) b
;
2460 struct lo_info
*i
= (struct lo_info
*) cl
;
2462 if (!TEST_FLAG (TheFlag
, rat
))
2464 if ((rat
->Point1
.X
== (i
->polygon
.Clipped
->contours
->head
.point
[0]) &&
2465 rat
->Point1
.Y
== (i
->polygon
.Clipped
->contours
->head
.point
[1]) &&
2466 rat
->group1
== i
->layer
) ||
2467 (rat
->Point2
.X
== (i
->polygon
.Clipped
->contours
->head
.point
[0]) &&
2468 rat
->Point2
.Y
== (i
->polygon
.Clipped
->contours
->head
.point
[1]) &&
2469 rat
->group2
== i
->layer
))
2470 if (ADD_RAT_TO_LIST (rat
))
2471 longjmp (i
->env
, 1);
2477 /* ---------------------------------------------------------------------------
2478 * looks up LOs that are connected to the given polygon
2479 * on the given layergroup. All found connections are added to the list
2482 LookupLOConnectionsToPolygon (PolygonTypePtr Polygon
, Cardinal LayerGroup
)
2485 struct lo_info info
;
2487 if (!Polygon
->Clipped
)
2489 info
.polygon
= *Polygon
;
2490 EXPAND_BOUNDS (&info
.polygon
);
2491 info
.layer
= LayerGroup
;
2493 if (setjmp (info
.env
) == 0)
2494 r_search (PCB
->Data
->rat_tree
, (BoxType
*) & info
.polygon
, NULL
,
2495 LOCtoPolyRat_callback
, &info
);
2498 /* loop over all layers of the group */
2499 for (entry
= 0; entry
< PCB
->LayerGroups
.Number
[LayerGroup
]; entry
++)
2503 layer
= PCB
->LayerGroups
.Entries
[LayerGroup
][entry
];
2505 /* handle normal layers */
2506 if (layer
< max_layer
)
2508 PolygonTypePtr polygon
;
2510 /* check all polygons */
2512 polygon
= PCB
->Data
->Layer
[layer
].Polygon
;
2513 for (i
= 0; i
< PCB
->Data
->Layer
[layer
].PolygonN
; i
++, polygon
++)
2514 if (!TEST_FLAG (TheFlag
, polygon
)
2515 && IsPolygonInPolygon (polygon
, Polygon
)
2516 && ADD_POLYGON_TO_LIST (layer
, polygon
))
2520 /* check all lines */
2521 if (setjmp (info
.env
) == 0)
2522 r_search (LAYER_PTR (layer
)->line_tree
,
2523 (BoxType
*) & info
.polygon
, NULL
,
2524 LOCtoPolyLine_callback
, &info
);
2527 /* check all arcs */
2528 if (setjmp (info
.env
) == 0)
2529 r_search (LAYER_PTR (layer
)->arc_tree
, (BoxType
*) & info
.polygon
,
2530 NULL
, LOCtoPolyArc_callback
, &info
);
2536 info
.layer
= layer
- max_layer
;
2537 if (setjmp (info
.env
) == 0)
2538 r_search (PCB
->Data
->pad_tree
, (BoxType
*) & info
.polygon
,
2539 NULL
, LOCtoPolyPad_callback
, &info
);
2547 /* ---------------------------------------------------------------------------
2548 * checks if an arc has a connection to a polygon
2550 * - first check if the arc can intersect with the polygon by
2551 * evaluating the bounding boxes
2552 * - check the two end points of the arc. If none of them matches
2553 * - check all segments of the polygon against the arc.
2556 IsArcInPolygon (ArcTypePtr Arc
, PolygonTypePtr Polygon
)
2558 BoxTypePtr Box
= (BoxType
*) Arc
;
2560 /* arcs with clearance never touch polys */
2561 if (TEST_FLAG (CLEARPOLYFLAG
, Polygon
) && TEST_FLAG (CLEARLINEFLAG
, Arc
))
2563 if (!Polygon
->Clipped
)
2565 if (Box
->X1
<= Polygon
->Clipped
->contours
->xmax
+ Bloat
2566 && Box
->X2
>= Polygon
->Clipped
->contours
->xmin
- Bloat
2567 && Box
->Y1
<= Polygon
->Clipped
->contours
->ymax
+ Bloat
2568 && Box
->Y2
>= Polygon
->Clipped
->contours
->ymin
- Bloat
)
2572 if (!(ap
= ArcPoly (Arc
, Arc
->Thickness
+ Bloat
)))
2573 return False
; /* error */
2574 return isects (ap
, Polygon
, True
);
2579 /* ---------------------------------------------------------------------------
2580 * checks if a line has a connection to a polygon
2582 * - first check if the line can intersect with the polygon by
2583 * evaluating the bounding boxes
2584 * - check the two end points of the line. If none of them matches
2585 * - check all segments of the polygon against the line.
2588 IsLineInPolygon (LineTypePtr Line
, PolygonTypePtr Polygon
)
2590 BoxTypePtr Box
= (BoxType
*) Line
;
2593 /* lines with clearance never touch polygons */
2594 if (TEST_FLAG (CLEARPOLYFLAG
, Polygon
) && TEST_FLAG (CLEARLINEFLAG
, Line
))
2596 if (!Polygon
->Clipped
)
2598 if (TEST_FLAG(SQUAREFLAG
,Line
)&&(Line
->Point1
.X
==Line
->Point2
.X
||Line
->Point1
.Y
==Line
->Point2
.Y
))
2600 BDimension wid
= (Line
->Thickness
+ Bloat
+ 1) / 2;
2601 LocationType x1
, x2
, y1
, y2
;
2603 x1
= MIN (Line
->Point1
.X
, Line
->Point2
.X
) - wid
;
2604 y1
= MIN (Line
->Point1
.Y
, Line
->Point2
.Y
) - wid
;
2605 x2
= MAX (Line
->Point1
.X
, Line
->Point2
.X
) + wid
;
2606 y2
= MAX (Line
->Point1
.Y
, Line
->Point2
.Y
) + wid
;
2607 return IsRectangleInPolygon (x1
, y1
, x2
, y2
, Polygon
);
2609 if (Box
->X1
<= Polygon
->Clipped
->contours
->xmax
+ Bloat
2610 && Box
->X2
>= Polygon
->Clipped
->contours
->xmin
- Bloat
2611 && Box
->Y1
<= Polygon
->Clipped
->contours
->ymax
+ Bloat
2612 && Box
->Y2
>= Polygon
->Clipped
->contours
->ymin
- Bloat
)
2614 if (!(lp
= LinePoly (Line
, Line
->Thickness
+ Bloat
)))
2615 return FALSE
; /* error */
2616 return isects (lp
, Polygon
, True
);
2621 /* ---------------------------------------------------------------------------
2622 * checks if a pad connects to a non-clearing polygon
2624 * The polygon is assumed to already have been proven non-clearing
2627 IsPadInPolygon (PadTypePtr pad
, PolygonTypePtr polygon
)
2629 return IsLineInPolygon ((LineTypePtr
) pad
, polygon
);
2632 /* ---------------------------------------------------------------------------
2633 * checks if a polygon has a connection to a second one
2635 * First check all points out of P1 against P2 and vice versa.
2636 * If both fail check all lines of P1 against the ones of P2
2639 IsPolygonInPolygon (PolygonTypePtr P1
, PolygonTypePtr P2
)
2641 if (!P1
->Clipped
|| !P2
->Clipped
)
2643 assert (P1
->Clipped
->contours
);
2644 assert (P2
->Clipped
->contours
);
2646 /* first check if both bounding boxes intersect. If not, return quickly */
2647 if (P1
->Clipped
->contours
->xmin
- Bloat
> P2
->Clipped
->contours
->xmax
||
2648 P1
->Clipped
->contours
->xmax
+ Bloat
< P2
->Clipped
->contours
->xmin
||
2649 P1
->Clipped
->contours
->ymin
- Bloat
> P2
->Clipped
->contours
->ymax
||
2650 P1
->Clipped
->contours
->ymax
+ Bloat
< P2
->Clipped
->contours
->ymin
)
2653 /* first check un-bloated case */
2654 if (isects (P1
->Clipped
, P2
, False
))
2657 /* now the difficult case of bloated */
2661 for (c
= P1
->Clipped
->contours
; c
; c
= c
->next
)
2664 VNODE
*v
= &c
->head
;
2665 if (c
->xmin
- Bloat
<= P2
->Clipped
->contours
->xmax
&&
2666 c
->xmax
+ Bloat
>= P2
->Clipped
->contours
->xmin
&&
2667 c
->ymin
- Bloat
<= P2
->Clipped
->contours
->ymax
&&
2668 c
->ymax
+ Bloat
>= P2
->Clipped
->contours
->ymin
)
2671 line
.Point1
.X
= v
->point
[0];
2672 line
.Point1
.Y
= v
->point
[1];
2673 line
.Thickness
= 2 * Bloat
;
2675 line
.Flags
= NoFlags ();
2676 for (v
= v
->next
; v
!= &c
->head
; v
= v
->next
)
2678 line
.Point2
.X
= v
->point
[0];
2679 line
.Point2
.Y
= v
->point
[1];
2680 SetLineBoundingBox (&line
);
2681 if (IsLineInPolygon (&line
, P2
))
2683 line
.Point1
.X
= line
.Point2
.X
;
2684 line
.Point1
.Y
= line
.Point2
.Y
;
2693 /* ---------------------------------------------------------------------------
2694 * writes the several names of an element to a file
2697 PrintElementNameList (ElementTypePtr Element
, FILE * FP
)
2699 static DynamicStringType cname
, pname
, vname
;
2701 CreateQuotedString (&cname
, EMPTY (DESCRIPTION_NAME (Element
)));
2702 CreateQuotedString (&pname
, EMPTY (NAMEONPCB_NAME (Element
)));
2703 CreateQuotedString (&vname
, EMPTY (VALUE_NAME (Element
)));
2704 fprintf (FP
, "(%s %s %s)\n", cname
.Data
, pname
.Data
, vname
.Data
);
2707 /* ---------------------------------------------------------------------------
2708 * writes the several names of an element to a file
2711 PrintConnectionElementName (ElementTypePtr Element
, FILE * FP
)
2713 fputs ("Element", FP
);
2714 PrintElementNameList (Element
, FP
);
2718 /* ---------------------------------------------------------------------------
2719 * prints one {pin,pad,via}/element entry of connection lists
2722 PrintConnectionListEntry (char *ObjName
, ElementTypePtr Element
,
2723 Boolean FirstOne
, FILE * FP
)
2725 static DynamicStringType oname
;
2727 CreateQuotedString (&oname
, ObjName
);
2729 fprintf (FP
, "\t%s\n\t{\n", oname
.Data
);
2732 fprintf (FP
, "\t\t%s ", oname
.Data
);
2734 PrintElementNameList (Element
, FP
);
2736 fputs ("(__VIA__)\n", FP
);
2740 /* ---------------------------------------------------------------------------
2741 * prints all found connections of a pads to file FP
2742 * the connections are stacked in 'PadList'
2745 PrintPadConnections (Cardinal Layer
, FILE * FP
, Boolean IsFirst
)
2750 if (!PadList
[Layer
].Number
)
2753 /* the starting pad */
2756 ptr
= PADLIST_ENTRY (Layer
, 0);
2758 PrintConnectionListEntry (UNKNOWN (ptr
->Name
), NULL
, True
, FP
);
2760 printf ("Skipping NULL ptr in 1st part of PrintPadConnections\n");
2763 /* we maybe have to start with i=1 if we are handling the
2764 * starting-pad itself
2766 for (i
= IsFirst
? 1 : 0; i
< PadList
[Layer
].Number
; i
++)
2768 ptr
= PADLIST_ENTRY (Layer
, i
);
2770 PrintConnectionListEntry (EMPTY (ptr
->Name
), ptr
->Element
, False
, FP
);
2772 printf ("Skipping NULL ptr in 2nd part of PrintPadConnections\n");
2776 /* ---------------------------------------------------------------------------
2777 * prints all found connections of a pin to file FP
2778 * the connections are stacked in 'PVList'
2781 PrintPinConnections (FILE * FP
, Boolean IsFirst
)
2791 /* the starting pin */
2792 pv
= PVLIST_ENTRY (0);
2793 PrintConnectionListEntry (EMPTY (pv
->Name
), NULL
, True
, FP
);
2796 /* we maybe have to start with i=1 if we are handling the
2797 * starting-pin itself
2799 for (i
= IsFirst
? 1 : 0; i
< PVList
.Number
; i
++)
2801 /* get the elements name or assume that its a via */
2802 pv
= PVLIST_ENTRY (i
);
2803 PrintConnectionListEntry (EMPTY (pv
->Name
), pv
->Element
, False
, FP
);
2807 /* ---------------------------------------------------------------------------
2808 * checks if all lists of new objects are handled
2811 ListsEmpty (Boolean AndRats
)
2816 empty
= (PVList
.Location
>= PVList
.Number
);
2818 empty
= empty
&& (RatList
.Location
>= RatList
.Number
);
2819 for (i
= 0; i
< max_layer
&& empty
; i
++)
2820 empty
= empty
&& LineList
[i
].Location
>= LineList
[i
].Number
2821 && ArcList
[i
].Location
>= ArcList
[i
].Number
2822 && PolygonList
[i
].Location
>= PolygonList
[i
].Number
;
2826 /* ---------------------------------------------------------------------------
2827 * loops till no more connections are found
2830 DoIt (Boolean AndRats
, Boolean AndDraw
)
2832 Boolean
new = False
;
2835 /* lookup connections; these are the steps (2) to (4)
2836 * from the description
2838 new = LookupPVConnectionsToPVList ();
2840 new = LookupLOConnectionsToPVList (AndRats
);
2842 new = LookupLOConnectionsToLOList (AndRats
);
2844 new = LookupPVConnectionsToLOList (AndRats
);
2846 DrawNewConnections ();
2848 while (!new && !ListsEmpty (AndRats
));
2854 /* returns True if nothing un-found touches the passed line
2855 * returns False if it would touch something not yet found
2856 * doesn't include rat-lines in the search
2860 lineClear (LineTypePtr line
, Cardinal group
)
2862 if (LOTouchesLine (line
, group
))
2864 if (PVTouchesLine (line
))
2869 /* ---------------------------------------------------------------------------
2870 * prints all unused pins of an element to file FP
2873 PrintAndSelectUnusedPinsAndPadsOfElement (ElementTypePtr Element
, FILE * FP
)
2875 Boolean first
= True
;
2877 static DynamicStringType oname
;
2879 /* check all pins in element */
2883 if (!TEST_FLAG (HOLEFLAG
, pin
))
2885 /* pin might have bee checked before, add to list if not */
2886 if (!TEST_FLAG (TheFlag
, pin
) && FP
)
2889 if (ADD_PV_TO_LIST (pin
))
2892 number
= PadList
[COMPONENT_LAYER
].Number
2893 + PadList
[SOLDER_LAYER
].Number
+ PVList
.Number
;
2894 /* the pin has no connection if it's the only
2895 * list entry; don't count vias
2897 for (i
= 0; i
< PVList
.Number
; i
++)
2898 if (!PVLIST_ENTRY (i
)->Element
)
2902 /* output of element name if not already done */
2905 PrintConnectionElementName (Element
, FP
);
2909 /* write name to list and draw selected object */
2910 CreateQuotedString (&oname
, EMPTY (pin
->Name
));
2911 fprintf (FP
, "\t%s\n", oname
.Data
);
2912 SET_FLAG (SELECTEDFLAG
, pin
);
2916 /* reset found objects for the next pin */
2917 if (PrepareNextLoop (FP
))
2924 /* check all pads in element */
2927 /* lookup pad in list */
2928 /* pad might has bee checked before, add to list if not */
2929 if (!TEST_FLAG (TheFlag
, pad
) && FP
)
2932 if (ADD_PAD_TO_LIST (TEST_FLAG (ONSOLDERFLAG
, pad
)
2933 ? SOLDER_LAYER
: COMPONENT_LAYER
, pad
))
2936 number
= PadList
[COMPONENT_LAYER
].Number
2937 + PadList
[SOLDER_LAYER
].Number
+ PVList
.Number
;
2938 /* the pin has no connection if it's the only
2939 * list entry; don't count vias
2941 for (i
= 0; i
< PVList
.Number
; i
++)
2942 if (!PVLIST_ENTRY (i
)->Element
)
2946 /* output of element name if not already done */
2949 PrintConnectionElementName (Element
, FP
);
2953 /* write name to list and draw selected object */
2954 CreateQuotedString (&oname
, EMPTY (pad
->Name
));
2955 fprintf (FP
, "\t%s\n", oname
.Data
);
2956 SET_FLAG (SELECTEDFLAG
, pad
);
2960 /* reset found objects for the next pin */
2961 if (PrepareNextLoop (FP
))
2967 /* print separator if element has unused pins or pads */
2970 fputs ("}\n\n", FP
);
2976 /* ---------------------------------------------------------------------------
2977 * resets some flags for looking up the next pin/pad
2980 PrepareNextLoop (FILE * FP
)
2984 /* reset found LOs for the next pin */
2985 for (layer
= 0; layer
< max_layer
; layer
++)
2987 LineList
[layer
].Location
= LineList
[layer
].Number
= 0;
2988 ArcList
[layer
].Location
= ArcList
[layer
].Number
= 0;
2989 PolygonList
[layer
].Location
= PolygonList
[layer
].Number
= 0;
2992 /* reset found pads */
2993 for (layer
= 0; layer
< 2; layer
++)
2994 PadList
[layer
].Location
= PadList
[layer
].Number
= 0;
2997 PVList
.Number
= PVList
.Location
= 0;
2998 RatList
.Number
= RatList
.Location
= 0;
3003 /* ---------------------------------------------------------------------------
3004 * finds all connections to the pins of the passed element.
3005 * The result is written to file FP
3006 * Returns True if operation was aborted
3009 PrintElementConnections (ElementTypePtr Element
, FILE * FP
, Boolean AndDraw
)
3011 PrintConnectionElementName (Element
, FP
);
3013 /* check all pins in element */
3016 /* pin might have been checked before, add to list if not */
3017 if (TEST_FLAG (TheFlag
, pin
))
3019 PrintConnectionListEntry (EMPTY (pin
->Name
), NULL
, True
, FP
);
3020 fputs ("\t\t__CHECKED_BEFORE__\n\t}\n", FP
);
3023 if (ADD_PV_TO_LIST (pin
))
3025 DoIt (True
, AndDraw
);
3026 /* printout all found connections */
3027 PrintPinConnections (FP
, True
);
3028 PrintPadConnections (COMPONENT_LAYER
, FP
, False
);
3029 PrintPadConnections (SOLDER_LAYER
, FP
, False
);
3030 fputs ("\t}\n", FP
);
3031 if (PrepareNextLoop (FP
))
3036 /* check all pads in element */
3040 /* pad might have been checked before, add to list if not */
3041 if (TEST_FLAG (TheFlag
, pad
))
3043 PrintConnectionListEntry (EMPTY (pad
->Name
), NULL
, True
, FP
);
3044 fputs ("\t\t__CHECKED_BEFORE__\n\t}\n", FP
);
3047 layer
= TEST_FLAG (ONSOLDERFLAG
, pad
) ? SOLDER_LAYER
: COMPONENT_LAYER
;
3048 if (ADD_PAD_TO_LIST (layer
, pad
))
3050 DoIt (True
, AndDraw
);
3051 /* print all found connections */
3052 PrintPadConnections (layer
, FP
, True
);
3053 PrintPadConnections (layer
==
3054 (COMPONENT_LAYER
? SOLDER_LAYER
: COMPONENT_LAYER
),
3056 PrintPinConnections (FP
, False
);
3057 fputs ("\t}\n", FP
);
3058 if (PrepareNextLoop (FP
))
3062 fputs ("}\n\n", FP
);
3066 /* ---------------------------------------------------------------------------
3067 * draws all new connections which have been found since the
3068 * routine was called the last time
3071 DrawNewConnections (void)
3076 /* decrement 'i' to keep layerstack order */
3077 for (i
= max_layer
- 1; i
!= -1; i
--)
3079 Cardinal layer
= LayerStack
[i
];
3081 if (PCB
->Data
->Layer
[layer
].On
)
3083 /* draw all new lines */
3084 position
= LineList
[layer
].DrawLocation
;
3085 for (; position
< LineList
[layer
].Number
; position
++)
3086 DrawLine (LAYER_PTR (layer
), LINELIST_ENTRY (layer
, position
), 0);
3087 LineList
[layer
].DrawLocation
= LineList
[layer
].Number
;
3089 /* draw all new arcs */
3090 position
= ArcList
[layer
].DrawLocation
;
3091 for (; position
< ArcList
[layer
].Number
; position
++)
3092 DrawArc (LAYER_PTR (layer
), ARCLIST_ENTRY (layer
, position
), 0);
3093 ArcList
[layer
].DrawLocation
= ArcList
[layer
].Number
;
3095 /* draw all new polygons */
3096 position
= PolygonList
[layer
].DrawLocation
;
3097 for (; position
< PolygonList
[layer
].Number
; position
++)
3099 (LAYER_PTR (layer
), POLYGONLIST_ENTRY (layer
, position
), 0);
3100 PolygonList
[layer
].DrawLocation
= PolygonList
[layer
].Number
;
3104 /* draw all new pads */
3106 for (i
= 0; i
< 2; i
++)
3108 position
= PadList
[i
].DrawLocation
;
3110 for (; position
< PadList
[i
].Number
; position
++)
3111 DrawPad (PADLIST_ENTRY (i
, position
), 0);
3112 PadList
[i
].DrawLocation
= PadList
[i
].Number
;
3115 /* draw all new PVs; 'PVList' holds a list of pointers to the
3116 * sorted array pointers to PV data
3118 while (PVList
.DrawLocation
< PVList
.Number
)
3120 PinTypePtr pv
= PVLIST_ENTRY (PVList
.DrawLocation
);
3122 if (TEST_FLAG (PINFLAG
, pv
))
3127 else if (PCB
->ViaOn
)
3129 PVList
.DrawLocation
++;
3131 /* draw the new rat-lines */
3134 position
= RatList
.DrawLocation
;
3135 for (; position
< RatList
.Number
; position
++)
3136 DrawRat (RATLIST_ENTRY (position
), 0);
3137 RatList
.DrawLocation
= RatList
.Number
;
3141 /* ---------------------------------------------------------------------------
3142 * find all connections to pins within one element
3145 LookupElementConnections (ElementTypePtr Element
, FILE * FP
)
3147 /* reset all currently marked connections */
3149 TheFlag
= FOUNDFLAG
;
3150 ResetConnections (True
);
3151 InitConnectionLookup ();
3152 PrintElementConnections (Element
, FP
, True
);
3153 SetChangedFlag (True
);
3154 if (Settings
.RingBellWhenFinished
)
3156 FreeConnectionLookupMemory ();
3157 IncrementUndoSerialNumber ();
3162 /* ---------------------------------------------------------------------------
3163 * find all connections to pins of all element
3166 LookupConnectionsToAllElements (FILE * FP
)
3168 /* reset all currently marked connections */
3170 TheFlag
= FOUNDFLAG
;
3171 ResetConnections (False
);
3172 InitConnectionLookup ();
3174 ELEMENT_LOOP (PCB
->Data
);
3176 /* break if abort dialog returned True */
3177 if (PrintElementConnections (element
, FP
, False
))
3180 if (Settings
.ResetAfterElement
&& n
!= 1)
3181 ResetConnections (False
);
3184 if (Settings
.RingBellWhenFinished
)
3186 ResetConnections (False
);
3187 FreeConnectionLookupMemory ();
3188 ClearAndRedrawOutput ();
3191 /*---------------------------------------------------------------------------
3192 * add the starting object to the list of found objects
3195 ListStart (int type
, void *ptr1
, void *ptr2
, void *ptr3
)
3203 if (ADD_PV_TO_LIST ((PinTypePtr
) ptr2
))
3210 if (ADD_RAT_TO_LIST ((RatTypePtr
) ptr1
))
3217 int layer
= GetLayerNumber (PCB
->Data
,
3218 (LayerTypePtr
) ptr1
);
3220 if (ADD_LINE_TO_LIST (layer
, (LineTypePtr
) ptr2
))
3227 int layer
= GetLayerNumber (PCB
->Data
,
3228 (LayerTypePtr
) ptr1
);
3230 if (ADD_ARC_TO_LIST (layer
, (ArcTypePtr
) ptr2
))
3237 int layer
= GetLayerNumber (PCB
->Data
,
3238 (LayerTypePtr
) ptr1
);
3240 if (ADD_POLYGON_TO_LIST (layer
, (PolygonTypePtr
) ptr2
))
3247 PadTypePtr pad
= (PadTypePtr
) ptr2
;
3250 (ONSOLDERFLAG
, pad
) ? SOLDER_LAYER
: COMPONENT_LAYER
, pad
))
3259 /* ---------------------------------------------------------------------------
3260 * looks up all connections from the object at the given coordinates
3261 * the TheFlag (normally 'FOUNDFLAG') is set for all objects found
3262 * the objects are re-drawn if AndDraw is true
3263 * also the action is marked as undoable if AndDraw is true
3266 LookupConnection (LocationType X
, LocationType Y
, Boolean AndDraw
,
3267 BDimension Range
, int which_flag
)
3269 void *ptr1
, *ptr2
, *ptr3
;
3273 /* check if there are any pins or pads at that position */
3277 = SearchObjectByLocation (LOOKUP_FIRST
, &ptr1
, &ptr2
, &ptr3
, X
, Y
, Range
);
3278 if (type
== NO_TYPE
)
3282 SearchObjectByLocation
3283 (LOOKUP_MORE
, &ptr1
, &ptr2
, &ptr3
, X
, Y
, Range
);
3284 if (type
== NO_TYPE
)
3286 if (type
& SILK_TYPE
)
3288 int laynum
= GetLayerNumber (PCB
->Data
,
3289 (LayerTypePtr
) ptr1
);
3291 /* don't mess with silk objects! */
3292 if (laynum
>= max_layer
)
3298 name
= ConnectionName (type
, ptr1
, ptr2
);
3299 hid_actionl ("NetlistShow", name
, NULL
);
3302 TheFlag
= which_flag
;
3304 InitConnectionLookup ();
3306 /* now add the object to the appropriate list and start scanning
3307 * This is step (1) from the description
3309 ListStart (type
, ptr1
, ptr2
, ptr3
);
3310 DoIt (True
, AndDraw
);
3312 IncrementUndoSerialNumber ();
3318 if (AndDraw
&& Settings
.RingBellWhenFinished
)
3320 FreeConnectionLookupMemory ();
3323 /* ---------------------------------------------------------------------------
3324 * find connections for rats nesting
3325 * assumes InitConnectionLookup() has already been done
3329 (int type
, void *ptr1
, void *ptr2
, void *ptr3
, Boolean undo
,
3334 ListStart (type
, ptr1
, ptr2
, ptr3
);
3335 DoIt (AndRats
, False
);
3339 /* ---------------------------------------------------------------------------
3340 * find all unused pins of all element
3343 LookupUnusedPins (FILE * FP
)
3345 /* reset all currently marked connections */
3347 SaveUndoSerialNumber ();
3348 ResetConnections (True
);
3349 RestoreUndoSerialNumber ();
3350 InitConnectionLookup ();
3352 ELEMENT_LOOP (PCB
->Data
);
3354 /* break if abort dialog returned True;
3355 * passing NULL as filedescriptor discards the normal output
3357 if (PrintAndSelectUnusedPinsAndPadsOfElement (element
, FP
))
3362 if (Settings
.RingBellWhenFinished
)
3364 FreeConnectionLookupMemory ();
3365 IncrementUndoSerialNumber ();
3370 /* ---------------------------------------------------------------------------
3371 * resets all used flags of pins and vias
3374 ResetFoundPinsViasAndPads (Boolean AndDraw
)
3376 Boolean change
= False
;
3379 VIA_LOOP (PCB
->Data
);
3381 if (TEST_FLAG (TheFlag
, via
))
3384 AddObjectToFlagUndoList (VIA_TYPE
, via
, via
, via
);
3385 CLEAR_FLAG (TheFlag
, via
);
3392 ELEMENT_LOOP (PCB
->Data
);
3396 if (TEST_FLAG (TheFlag
, pin
))
3399 AddObjectToFlagUndoList (PIN_TYPE
, element
, pin
, pin
);
3400 CLEAR_FLAG (TheFlag
, pin
);
3409 if (TEST_FLAG (TheFlag
, pad
))
3412 AddObjectToFlagUndoList (PAD_TYPE
, element
, pad
, pad
);
3413 CLEAR_FLAG (TheFlag
, pad
);
3424 SetChangedFlag (True
);
3427 IncrementUndoSerialNumber ();
3433 /* ---------------------------------------------------------------------------
3434 * resets all used flags of LOs
3437 ResetFoundLinesAndPolygons (Boolean AndDraw
)
3439 Boolean change
= False
;
3442 RAT_LOOP (PCB
->Data
);
3444 if (TEST_FLAG (TheFlag
, line
))
3447 AddObjectToFlagUndoList (RATLINE_TYPE
, line
, line
, line
);
3448 CLEAR_FLAG (TheFlag
, line
);
3455 COPPERLINE_LOOP (PCB
->Data
);
3457 if (TEST_FLAG (TheFlag
, line
))
3460 AddObjectToFlagUndoList (LINE_TYPE
, layer
, line
, line
);
3461 CLEAR_FLAG (TheFlag
, line
);
3463 DrawLine (layer
, line
, 0);
3468 COPPERARC_LOOP (PCB
->Data
);
3470 if (TEST_FLAG (TheFlag
, arc
))
3473 AddObjectToFlagUndoList (ARC_TYPE
, layer
, arc
, arc
);
3474 CLEAR_FLAG (TheFlag
, arc
);
3476 DrawArc (layer
, arc
, 0);
3481 COPPERPOLYGON_LOOP (PCB
->Data
);
3483 if (TEST_FLAG (TheFlag
, polygon
))
3486 AddObjectToFlagUndoList (POLYGON_TYPE
, layer
, polygon
, polygon
);
3487 CLEAR_FLAG (TheFlag
, polygon
);
3489 DrawPolygon (layer
, polygon
, 0);
3496 SetChangedFlag (True
);
3499 IncrementUndoSerialNumber ();
3505 /* ---------------------------------------------------------------------------
3506 * resets all found connections
3509 ResetConnections (Boolean AndDraw
)
3512 SaveUndoSerialNumber ();
3513 ResetFoundPinsViasAndPads (AndDraw
);
3515 RestoreUndoSerialNumber ();
3516 ResetFoundLinesAndPolygons (AndDraw
);
3519 /*----------------------------------------------------------------------------
3520 * Dumps the list contents
3527 for (i
= 0; i
< 2; i
++)
3529 PadList
[i
].Number
= 0;
3530 PadList
[i
].Location
= 0;
3531 PadList
[i
].DrawLocation
= 0;
3535 PVList
.Location
= 0;
3537 for (i
= 0; i
< max_layer
; i
++)
3539 LineList
[i
].Location
= 0;
3540 LineList
[i
].DrawLocation
= 0;
3541 LineList
[i
].Number
= 0;
3542 ArcList
[i
].Location
= 0;
3543 ArcList
[i
].DrawLocation
= 0;
3544 ArcList
[i
].Number
= 0;
3545 PolygonList
[i
].Location
= 0;
3546 PolygonList
[i
].DrawLocation
= 0;
3547 PolygonList
[i
].Number
= 0;
3550 RatList
.Location
= 0;
3551 RatList
.DrawLocation
= 0;
3554 /*-----------------------------------------------------------------------------
3555 * Check for DRC violations on a single net starting from the pad or pin
3556 * sees if the connectivity changes when everything is bloated, or shrunk
3559 DRCFind (int What
, void *ptr1
, void *ptr2
, void *ptr3
)
3563 long int *object_id_list
;
3564 int *object_type_list
;
3565 DrcViolationType
*violation
;
3567 if (PCB
->Shrink
!= 0)
3569 Bloat
= -PCB
->Shrink
;
3570 fBloat
= (float) -PCB
->Shrink
;
3571 TheFlag
= DRCFLAG
| SELECTEDFLAG
;
3572 ListStart (What
, ptr1
, ptr2
, ptr3
);
3574 /* ok now the shrunk net has the SELECTEDFLAG set */
3576 TheFlag
= FOUNDFLAG
;
3577 ListStart (What
, ptr1
, ptr2
, ptr3
);
3580 drc
= True
; /* abort the search if we find anything not already found */
3581 if (DoIt (True
, False
))
3584 /* make the flag changes undoable */
3585 TheFlag
= FOUNDFLAG
| SELECTEDFLAG
;
3586 ResetConnections (False
);
3589 Bloat
= -PCB
->Shrink
;
3590 fBloat
= (float) -PCB
->Shrink
;
3591 TheFlag
= SELECTEDFLAG
;
3592 RestoreUndoSerialNumber ();
3593 ListStart (What
, ptr1
, ptr2
, ptr3
);
3596 ListStart (What
, ptr1
, ptr2
, ptr3
);
3597 TheFlag
= FOUNDFLAG
;
3606 LocateError (&x
, &y
);
3607 BuildObjectList (&object_count
, &object_id_list
, &object_type_list
);
3608 violation
= pcb_drc_violation_new (_("Potential for broken trace"),
3609 _("Insufficient overlap between objects can lead to broken tracks\n"
3610 "due to registration errors with old wheel style photo-plotters."),
3612 0, /* ANGLE OF ERROR UNKNOWN */
3613 FALSE
, /* MEASUREMENT OF ERROR UNKNOWN */
3614 0, /* MAGNITUDE OF ERROR UNKNOWN */
3615 LENGTH_TO_HUMAN(PCB
->Shrink
),
3617 LENGTH_UNITS_STRING
,
3621 append_drc_violation (violation
);
3622 pcb_drc_violation_free (violation
);
3623 free (object_id_list
);
3624 free (object_type_list
);
3626 if (!throw_drc_dialog())
3628 IncrementUndoSerialNumber ();
3633 /* now check the bloated condition */
3635 ResetConnections (False
);
3636 TheFlag
= FOUNDFLAG
;
3637 ListStart (What
, ptr1
, ptr2
, ptr3
);
3639 fBloat
= (float) PCB
->Bloat
;
3641 while (DoIt (True
, False
))
3644 /* make the flag changes undoable */
3645 TheFlag
= FOUNDFLAG
| SELECTEDFLAG
;
3646 ResetConnections (False
);
3651 RestoreUndoSerialNumber ();
3652 TheFlag
= SELECTEDFLAG
;
3653 ListStart (What
, ptr1
, ptr2
, ptr3
);
3656 TheFlag
= FOUNDFLAG
;
3657 ListStart (What
, ptr1
, ptr2
, ptr3
);
3659 fBloat
= (float) PCB
->Bloat
;
3664 LocateError (&x
, &y
);
3665 BuildObjectList (&object_count
, &object_id_list
, &object_type_list
);
3666 violation
= pcb_drc_violation_new (_("Copper areas too close"),
3667 _("Circuits that are too close may bridge during imaging, etching,\n"
3668 "plating, or soldering processes resulting in a direct short."),
3670 0, /* ANGLE OF ERROR UNKNOWN */
3671 FALSE
, /* MEASUREMENT OF ERROR UNKNOWN */
3672 0, /* MAGNITUDE OF ERROR UNKNOWN */
3673 LENGTH_TO_HUMAN(PCB
->Bloat
),
3675 LENGTH_UNITS_STRING
,
3679 append_drc_violation (violation
);
3680 pcb_drc_violation_free (violation
);
3681 free (object_id_list
);
3682 free (object_type_list
);
3685 if (!throw_drc_dialog())
3687 IncrementUndoSerialNumber ();
3689 /* highlight the rest of the encroaching net so it's not reported again */
3690 TheFlag
|= SELECTEDFLAG
;
3693 ListStart (thing_type
, thing_ptr1
, thing_ptr2
, thing_ptr3
);
3698 fBloat
= (float) PCB
->Bloat
;
3699 ListStart (What
, ptr1
, ptr2
, ptr3
);
3703 TheFlag
= FOUNDFLAG
| SELECTEDFLAG
;
3704 ResetConnections (False
);
3708 /*----------------------------------------------------------------------------
3709 * set up a temporary flag to use
3712 SaveFindFlag (int NewFlag
)
3718 /*----------------------------------------------------------------------------
3722 RestoreFindFlag (void)
3727 /* DRC clearance callback */
3730 drc_callback (DataTypePtr data
, LayerTypePtr layer
, PolygonTypePtr polygon
,
3731 int type
, void *ptr1
, void *ptr2
)
3736 long int *object_id_list
;
3737 int *object_type_list
;
3738 DrcViolationType
*violation
;
3740 LineTypePtr line
= (LineTypePtr
) ptr2
;
3741 ArcTypePtr arc
= (ArcTypePtr
) ptr2
;
3742 PinTypePtr pin
= (PinTypePtr
) ptr2
;
3743 PadTypePtr pad
= (PadTypePtr
) ptr2
;
3752 if (line
->Clearance
< 2 * PCB
->Bloat
)
3754 AddObjectToFlagUndoList (type
, ptr1
, ptr2
, ptr2
);
3755 SET_FLAG (TheFlag
, line
);
3756 message
= _("Line with insufficient clearance inside polygon\n");
3761 if (arc
->Clearance
< 2 * PCB
->Bloat
)
3763 AddObjectToFlagUndoList (type
, ptr1
, ptr2
, ptr2
);
3764 SET_FLAG (TheFlag
, arc
);
3765 message
= _("Arc with insufficient clearance inside polygon\n");
3770 if (pad
->Clearance
< 2 * PCB
->Bloat
)
3771 if (IsPadInPolygon(pad
,polygon
))
3773 AddObjectToFlagUndoList (type
, ptr1
, ptr2
, ptr2
);
3774 SET_FLAG (TheFlag
, pad
);
3775 message
= _("Pad with insufficient clearance inside polygon\n");
3780 if (pin
->Clearance
< 2 * PCB
->Bloat
)
3782 AddObjectToFlagUndoList (type
, ptr1
, ptr2
, ptr2
);
3783 SET_FLAG (TheFlag
, pin
);
3784 message
= _("Pin with insufficient clearance inside polygon\n");
3789 if (pin
->Clearance
&& pin
->Clearance
< 2 * PCB
->Bloat
)
3791 AddObjectToFlagUndoList (type
, ptr1
, ptr2
, ptr2
);
3792 SET_FLAG (TheFlag
, pin
);
3793 message
= _("Via with insufficient clearance inside polygon\n");
3798 Message ("hace: Bad Plow object in callback\n");
3803 AddObjectToFlagUndoList (POLYGON_TYPE
, layer
, polygon
, polygon
);
3804 SET_FLAG (FOUNDFLAG
, polygon
);
3805 DrawPolygon (layer
, polygon
, 0);
3806 DrawObject (type
, ptr1
, ptr2
, 0);
3808 LocateError (&x
, &y
);
3809 BuildObjectList (&object_count
, &object_id_list
, &object_type_list
);
3810 violation
= pcb_drc_violation_new (message
,
3811 _("Circuits that are too close may bridge during imaging, etching,\n"
3812 "plating, or soldering processes resulting in a direct short."),
3814 0, /* ANGLE OF ERROR UNKNOWN */
3815 FALSE
, /* MEASUREMENT OF ERROR UNKNOWN */
3816 0, /* MAGNITUDE OF ERROR UNKNOWN */
3817 LENGTH_TO_HUMAN(PCB
->Bloat
),
3819 LENGTH_UNITS_STRING
,
3823 append_drc_violation (violation
);
3824 pcb_drc_violation_free (violation
);
3825 free (object_id_list
);
3826 free (object_type_list
);
3827 if (!throw_drc_dialog())
3832 IncrementUndoSerialNumber ();
3837 /*-----------------------------------------------------------------------------
3838 * Check for DRC violations
3839 * see if the connectivity changes when everything is bloated, or shrunk
3846 long int *object_id_list
;
3847 int *object_type_list
;
3848 DrcViolationType
*violation
;
3852 reset_drc_dialog_message();
3856 SaveStackAndVisibility ();
3857 ResetStackAndVisibility ();
3858 hid_action ("LayersChanged");
3859 InitConnectionLookup ();
3861 TheFlag
= FOUNDFLAG
| DRCFLAG
| SELECTEDFLAG
;
3863 ResetConnections (True
);
3867 ELEMENT_LOOP (PCB
->Data
);
3871 if (!TEST_FLAG (DRCFLAG
, pin
)
3872 && DRCFind (PIN_TYPE
, (void *) element
, (void *) pin
, (void *) pin
))
3884 /* count up how many pads have no solderpaste openings */
3885 if (TEST_FLAG (NOPASTEFLAG
, pad
))
3888 if (!TEST_FLAG (DRCFLAG
, pad
)
3889 && DRCFind (PAD_TYPE
, (void *) element
, (void *) pad
, (void *) pad
))
3901 VIA_LOOP (PCB
->Data
);
3903 if (!TEST_FLAG (DRCFLAG
, via
)
3904 && DRCFind (VIA_TYPE
, (void *) via
, (void *) via
, (void *) via
))
3912 TheFlag
= (IsBad
) ? DRCFLAG
: (FOUNDFLAG
| DRCFLAG
| SELECTEDFLAG
);
3913 ResetConnections (False
);
3914 TheFlag
= SELECTEDFLAG
;
3915 /* check minimum widths and polygon clearances */
3918 COPPERLINE_LOOP (PCB
->Data
);
3920 /* check line clearances in polygons */
3921 PlowsPolygon (PCB
->Data
, LINE_TYPE
, layer
, line
, drc_callback
);
3924 if (line
->Thickness
< PCB
->minWid
)
3926 AddObjectToFlagUndoList (LINE_TYPE
, layer
, line
, line
);
3927 SET_FLAG (TheFlag
, line
);
3928 DrawLine (layer
, line
, 0);
3930 SetThing (LINE_TYPE
, layer
, line
, line
);
3931 LocateError (&x
, &y
);
3932 BuildObjectList (&object_count
, &object_id_list
, &object_type_list
);
3933 violation
= pcb_drc_violation_new (_("Line width is too thin"),
3934 _("Process specifications dictate a minimum feature-width\n"
3935 "that can reliably be reproduced"),
3937 0, /* ANGLE OF ERROR UNKNOWN */
3938 TRUE
, /* MEASUREMENT OF ERROR KNOWN */
3939 LENGTH_TO_HUMAN(line
->Thickness
),
3940 LENGTH_TO_HUMAN(PCB
->minWid
),
3942 LENGTH_UNITS_STRING
,
3946 append_drc_violation (violation
);
3947 pcb_drc_violation_free (violation
);
3948 free (object_id_list
);
3949 free (object_type_list
);
3950 if (!throw_drc_dialog())
3955 IncrementUndoSerialNumber ();
3963 COPPERARC_LOOP (PCB
->Data
);
3965 PlowsPolygon (PCB
->Data
, ARC_TYPE
, layer
, arc
, drc_callback
);
3968 if (arc
->Thickness
< PCB
->minWid
)
3970 AddObjectToFlagUndoList (ARC_TYPE
, layer
, arc
, arc
);
3971 SET_FLAG (TheFlag
, arc
);
3972 DrawArc (layer
, arc
, 0);
3974 SetThing (ARC_TYPE
, layer
, arc
, arc
);
3975 LocateError (&x
, &y
);
3976 BuildObjectList (&object_count
, &object_id_list
, &object_type_list
);
3977 violation
= pcb_drc_violation_new (_("Arc width is too thin"),
3978 _("Process specifications dictate a minimum feature-width\n"
3979 "that can reliably be reproduced"),
3981 0, /* ANGLE OF ERROR UNKNOWN */
3982 TRUE
, /* MEASUREMENT OF ERROR KNOWN */
3983 LENGTH_TO_HUMAN(arc
->Thickness
),
3984 LENGTH_TO_HUMAN(PCB
->minWid
),
3986 LENGTH_UNITS_STRING
,
3990 append_drc_violation (violation
);
3991 pcb_drc_violation_free (violation
);
3992 free (object_id_list
);
3993 free (object_type_list
);
3994 if (!throw_drc_dialog())
3999 IncrementUndoSerialNumber ();
4007 ALLPIN_LOOP (PCB
->Data
);
4009 PlowsPolygon (PCB
->Data
, PIN_TYPE
, element
, pin
, drc_callback
);
4012 if (!TEST_FLAG (HOLEFLAG
, pin
) &&
4013 pin
->Thickness
- pin
->DrillingHole
< 2 * PCB
->minRing
)
4015 AddObjectToFlagUndoList (PIN_TYPE
, element
, pin
, pin
);
4016 SET_FLAG (TheFlag
, pin
);
4019 SetThing (PIN_TYPE
, element
, pin
, pin
);
4020 LocateError (&x
, &y
);
4021 BuildObjectList (&object_count
, &object_id_list
, &object_type_list
);
4022 violation
= pcb_drc_violation_new (_("Pin annular ring too small"),
4023 _("Annular rings that are too small may erode during etching,\n"
4024 "resulting in a broken connection"),
4026 0, /* ANGLE OF ERROR UNKNOWN */
4027 TRUE
, /* MEASUREMENT OF ERROR KNOWN */
4028 LENGTH_TO_HUMAN((pin
->Thickness
- pin
->DrillingHole
) / 2),
4029 LENGTH_TO_HUMAN(PCB
->minRing
),
4031 LENGTH_UNITS_STRING
,
4035 append_drc_violation (violation
);
4036 pcb_drc_violation_free (violation
);
4037 free (object_id_list
);
4038 free (object_type_list
);
4039 if (!throw_drc_dialog())
4044 IncrementUndoSerialNumber ();
4047 if (pin
->DrillingHole
< PCB
->minDrill
)
4049 AddObjectToFlagUndoList (PIN_TYPE
, element
, pin
, pin
);
4050 SET_FLAG (TheFlag
, pin
);
4053 SetThing (PIN_TYPE
, element
, pin
, pin
);
4054 LocateError (&x
, &y
);
4055 BuildObjectList (&object_count
, &object_id_list
, &object_type_list
);
4056 violation
= pcb_drc_violation_new (_("Pin drill size is too small"),
4057 _("Process rules dictate the minimum drill size which can be used"),
4059 0, /* ANGLE OF ERROR UNKNOWN */
4060 TRUE
, /* MEASUREMENT OF ERROR KNOWN */
4061 LENGTH_TO_HUMAN(pin
->DrillingHole
),
4062 LENGTH_TO_HUMAN(PCB
->minDrill
),
4064 LENGTH_UNITS_STRING
,
4068 append_drc_violation (violation
);
4069 pcb_drc_violation_free (violation
);
4070 free (object_id_list
);
4071 free (object_type_list
);
4072 if (!throw_drc_dialog())
4077 IncrementUndoSerialNumber ();
4085 ALLPAD_LOOP (PCB
->Data
);
4087 PlowsPolygon (PCB
->Data
, PAD_TYPE
, element
, pad
, drc_callback
);
4090 if (pad
->Thickness
< PCB
->minWid
)
4092 AddObjectToFlagUndoList (PAD_TYPE
, element
, pad
, pad
);
4093 SET_FLAG (TheFlag
, pad
);
4096 SetThing (PAD_TYPE
, element
, pad
, pad
);
4097 LocateError (&x
, &y
);
4098 BuildObjectList (&object_count
, &object_id_list
, &object_type_list
);
4099 violation
= pcb_drc_violation_new (_("Pad is too thin"),
4100 _("Pads which are too thin may erode during etching,\n"
4101 "resulting in a broken or unreliable connection"),
4103 0, /* ANGLE OF ERROR UNKNOWN */
4104 TRUE
, /* MEASUREMENT OF ERROR KNOWN */
4105 LENGTH_TO_HUMAN(pad
->Thickness
),
4106 LENGTH_TO_HUMAN(PCB
->minWid
),
4108 LENGTH_UNITS_STRING
,
4112 append_drc_violation (violation
);
4113 pcb_drc_violation_free (violation
);
4114 free (object_id_list
);
4115 free (object_type_list
);
4116 if (!throw_drc_dialog())
4121 IncrementUndoSerialNumber ();
4129 VIA_LOOP (PCB
->Data
);
4131 PlowsPolygon (PCB
->Data
, VIA_TYPE
, via
, via
, drc_callback
);
4134 if (!TEST_FLAG (HOLEFLAG
, via
) &&
4135 via
->Thickness
- via
->DrillingHole
< 2 * PCB
->minRing
)
4137 AddObjectToFlagUndoList (VIA_TYPE
, via
, via
, via
);
4138 SET_FLAG (TheFlag
, via
);
4141 SetThing (VIA_TYPE
, via
, via
, via
);
4142 LocateError (&x
, &y
);
4143 BuildObjectList (&object_count
, &object_id_list
, &object_type_list
);
4144 violation
= pcb_drc_violation_new (_("Via annular ring too small"),
4145 _("Annular rings that are too small may erode during etching,\n"
4146 "resulting in a broken connection"),
4148 0, /* ANGLE OF ERROR UNKNOWN */
4149 TRUE
, /* MEASUREMENT OF ERROR KNOWN */
4150 LENGTH_TO_HUMAN((via
->Thickness
- via
->DrillingHole
) / 2),
4151 LENGTH_TO_HUMAN(PCB
->minRing
),
4153 LENGTH_UNITS_STRING
,
4157 append_drc_violation (violation
);
4158 pcb_drc_violation_free (violation
);
4159 free (object_id_list
);
4160 free (object_type_list
);
4161 if (!throw_drc_dialog())
4166 IncrementUndoSerialNumber ();
4169 if (via
->DrillingHole
< PCB
->minDrill
)
4171 AddObjectToFlagUndoList (VIA_TYPE
, via
, via
, via
);
4172 SET_FLAG (TheFlag
, via
);
4175 SetThing (VIA_TYPE
, via
, via
, via
);
4176 LocateError (&x
, &y
);
4177 BuildObjectList (&object_count
, &object_id_list
, &object_type_list
);
4178 violation
= pcb_drc_violation_new (_("Via drill size is too small"),
4179 _("Process rules dictate the minimum drill size which can be used"),
4181 0, /* ANGLE OF ERROR UNKNOWN */
4182 TRUE
, /* MEASUREMENT OF ERROR KNOWN */
4183 LENGTH_TO_HUMAN(via
->DrillingHole
),
4184 LENGTH_TO_HUMAN(PCB
->minDrill
),
4186 LENGTH_UNITS_STRING
,
4190 append_drc_violation (violation
);
4191 pcb_drc_violation_free (violation
);
4192 free (object_id_list
);
4193 free (object_type_list
);
4194 if (!throw_drc_dialog())
4199 IncrementUndoSerialNumber ();
4206 FreeConnectionLookupMemory ();
4207 TheFlag
= FOUNDFLAG
;
4211 /* check silkscreen minimum widths outside of elements */
4212 /* XXX - need to check text and polygons too! */
4213 TheFlag
= SELECTEDFLAG
;
4216 SILKLINE_LOOP (PCB
->Data
);
4218 if (line
->Thickness
< PCB
->minSlk
)
4220 SET_FLAG (TheFlag
, line
);
4221 DrawLine (layer
, line
, 0);
4223 SetThing (LINE_TYPE
, layer
, line
, line
);
4224 LocateError (&x
, &y
);
4225 BuildObjectList (&object_count
, &object_id_list
, &object_type_list
);
4226 violation
= pcb_drc_violation_new (_("Silk line is too thin"),
4227 _("Process specifications dictate a minimum silkscreen feature-width\n"
4228 "that can reliably be reproduced"),
4230 0, /* ANGLE OF ERROR UNKNOWN */
4231 TRUE
, /* MEASUREMENT OF ERROR KNOWN */
4232 LENGTH_TO_HUMAN(line
->Thickness
),
4233 LENGTH_TO_HUMAN(PCB
->minSlk
),
4235 LENGTH_UNITS_STRING
,
4239 append_drc_violation (violation
);
4240 pcb_drc_violation_free (violation
);
4241 free (object_id_list
);
4242 free (object_type_list
);
4243 if (!throw_drc_dialog())
4253 /* check silkscreen minimum widths inside of elements */
4254 /* XXX - need to check text and polygons too! */
4255 TheFlag
= SELECTEDFLAG
;
4258 ELEMENT_LOOP (PCB
->Data
);
4261 ELEMENTLINE_LOOP (element
);
4263 if (line
->Thickness
< PCB
->minSlk
)
4274 SET_FLAG (TheFlag
, element
);
4275 DrawElement (element
, 0);
4277 SetThing (ELEMENT_TYPE
, element
, element
, element
);
4278 LocateError (&x
, &y
);
4279 BuildObjectList (&object_count
, &object_id_list
, &object_type_list
);
4281 title
= _("Element %s has %i silk lines which are too thin");
4282 name
= UNKNOWN (NAMEONPCB_NAME (element
));
4284 /* -4 is for the %s and %i place-holders */
4285 /* +11 is the max printed length for a 32 bit integer */
4286 /* +1 is for the \0 termination */
4287 buflen
= strlen (title
) - 4 + strlen (name
) + 11 + 1;
4288 buffer
= malloc (buflen
);
4289 snprintf (buffer
, buflen
, title
, name
, tmpcnt
);
4291 violation
= pcb_drc_violation_new (buffer
,
4292 _("Process specifications dictate a minimum silkscreen\n"
4293 "feature-width that can reliably be reproduced"),
4295 0, /* ANGLE OF ERROR UNKNOWN */
4296 0, /* MINIMUM OFFENDING WIDTH UNKNOWN */
4297 TRUE
, /* MEASUREMENT OF ERROR KNOWN */
4298 LENGTH_TO_HUMAN(PCB
->minSlk
),
4300 LENGTH_UNITS_STRING
,
4305 append_drc_violation (violation
);
4306 pcb_drc_violation_free (violation
);
4307 free (object_id_list
);
4308 free (object_type_list
);
4309 if (!throw_drc_dialog())
4322 IncrementUndoSerialNumber ();
4326 RestoreStackAndVisibility ();
4327 hid_action ("LayersChanged");
4328 gui
->invalidate_all ();
4332 Message (_("Warning: %d pad%s the nopaste flag set.\n"),
4334 nopastecnt
> 1 ? "s have" : " has");
4336 return IsBad
? -drcerr_count
: drcerr_count
;
4339 /*----------------------------------------------------------------------------
4340 * Locate the coordinatates of offending item (thing)
4343 LocateError (LocationType
*x
, LocationType
*y
)
4349 LineTypePtr line
= (LineTypePtr
) thing_ptr3
;
4350 *x
= (line
->Point1
.X
+ line
->Point2
.X
) / 2;
4351 *y
= (line
->Point1
.Y
+ line
->Point2
.Y
) / 2;
4356 ArcTypePtr arc
= (ArcTypePtr
) thing_ptr3
;
4363 PolygonTypePtr polygon
= (PolygonTypePtr
) thing_ptr3
;
4365 (polygon
->Clipped
->contours
->xmin
+
4366 polygon
->Clipped
->contours
->xmax
) / 2;
4368 (polygon
->Clipped
->contours
->ymin
+
4369 polygon
->Clipped
->contours
->ymax
) / 2;
4375 PinTypePtr pin
= (PinTypePtr
) thing_ptr3
;
4382 PadTypePtr pad
= (PadTypePtr
) thing_ptr3
;
4383 *x
= (pad
->Point1
.X
+ pad
->Point2
.X
) / 2;
4384 *y
= (pad
->Point1
.Y
+ pad
->Point2
.Y
) / 2;
4389 ElementTypePtr element
= (ElementTypePtr
) thing_ptr3
;
4390 *x
= element
->MarkX
;
4391 *y
= element
->MarkY
;
4400 /*----------------------------------------------------------------------------
4401 * Build a list of the of offending items by ID. (Currently just "thing")
4404 BuildObjectList (int *object_count
, long int **object_id_list
, int **object_type_list
)
4407 *object_id_list
= NULL
;
4419 *object_id_list
= malloc (sizeof (long int));
4420 *object_type_list
= malloc (sizeof (int));
4421 **object_id_list
= ((AnyObjectType
*)thing_ptr3
)->ID
;
4422 **object_type_list
= thing_type
;
4431 /*----------------------------------------------------------------------------
4432 * center the display to show the offending item (thing)
4439 LocateError (&X
, &Y
);
4446 ChangeGroupVisibility (GetLayerNumber
4447 (PCB
->Data
, (LayerTypePtr
) thing_ptr1
), True
,
4450 CenterDisplay (X
, Y
, False
);
4454 InitConnectionLookup (void)
4456 InitComponentLookup ();
4457 InitLayoutLookup ();
4461 FreeConnectionLookupMemory (void)
4463 FreeComponentLookupMemory ();
4464 FreeLayoutLookupMemory ();