-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAttachNetNameFromTrackNPadToPolygon.pas
115 lines (100 loc) · 4.91 KB
/
AttachNetNameFromTrackNPadToPolygon.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{..............................................................................}
{ Attach the net name from a track or a pad to a polygon }
{ }
{ The script behaves differently depending on the location where }
{ the user clicks }
{ 1. if the user clicks at a point where there is a track or a pad }
{ that overlaps with a polygon, the polygon will take on the }
{ net name of the pad or the track. A pad has a higher priority }
{ than a track }
{ 2. if the user clicks at a point where there is only polygon, the }
{ script will ask the user to click at a track or a pad. Upon }
{ successful completion of the task, the net name of the pad or }
{ the track is transferred to the polygon. }
{ }
{ Click on an empty space to end the script }
{ Version 2.0 }
{..............................................................................}
{ Author: Yifeng Qiu @ Lumileds }
{..............................................................................}
Procedure AttachNetNameFromTrackNPadToPolygon;
Var
Board : IPCB_Board;
Prim : IPCB_Primitive;
PadObject : IPCB_Pad;
Polygon : IPCB_Polygon;
Layer : TLayer;
x,y, : TCoord;
i : Integer;
Rect : TCoordRect;
Iterator : IPCB_SpatialIterator;
FoundTrack: Boolean;
FoundPad : Boolean;
Begin
Pcbserver.PreProcess;
Try
Board := PCBServer.GetCurrentPCBBoard;
If Not Assigned(Board) Then
Begin
ShowMessage('The Current Document is not a Altium PCB Document.');
Exit;
End;
Layer := Board.CurrentLayer;
Repeat
FoundTrack := False;
FoundPad := False;
Board.ChooseLocation(x,y, 'Choose a polygon');
//ShowMessage('Pad X:' + CoordUnitToString(x, eMM) + ' Pad Y:' + CoordUnitToString(y, eMM));
Polygon := Board.GetObjectAtXYAskUserIfAmbiguous(x,y, MkSet(ePolyObject),
MkSet(Layer),
eEditAction_Select);
if Polygon = nil then exit;
{ Define a very small rectangle around the selected point, then find all the
tracks and pads intersecting this rectangle}
Iterator := Board.SpatialIterator_Create;
Iterator.AddFilter_LayerSet(MkSet(Layer));
Iterator.AddFilter_Area((x-2), (y-2), (x+2), (y+2));
Iterator.AddFilter_ObjectSet(MkSet(ePadObject, eTrackObject, eArcObject));
Prim := Iterator.FirstPCBObject;
while Prim <> nil do
Begin
// if the object is a pad, the pad's net name is used and
// the loop stops
if (Prim.ObjectID = ePadObject) then
Begin
FoundPad := True;
Polygon.Net := Prim.Net;
break;
End
else if (Prim.ObjectID = eTrackObject) or (Prim.ObjectID = eArcObject) then
Begin
if FoundTrack = False then
Begin
FoundTrack := True;
Polygon.Net := Prim.Net;
// only the first track or arc is used; the loop
// continues until the list is depleted or a pad
// is found
End
End;
Prim := Iterator.NextPCBObject;
End;
Board.SpatialIterator_Destroy(Iterator);
if (FoundPad = False) and (FoundTrack = False) then
Begin
Board.ChooseLocation(x,y, 'Choose a pad, a track or an arc');
Prim := Board.GetObjectAtXYAskUserIfAmbiguous(x,y,
MkSet(eTrackObject, eArcObject, ePadObject),
MkSet(Layer),
eEditAction_Select);
if Prim <> nil then
Polygon.Net := Prim.Net;
End;
Client.SendMessage('PCB:Zoom', 'Action=Redraw', 255, Client.CurrentView);
// click on the board to exit or RMB
Until (Polygon = Nil);
Finally
Pcbserver.PostProcess;
Client.SendMessage('PCB:Zoom', 'Action=Redraw', 255, Client.CurrentView);
End;
End;