-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContactsRuler.ulp
274 lines (239 loc) · 10.6 KB
/
ContactsRuler.ulp
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//Author:[email protected]
#usage "<html><p>This ULP makes distance measuring between contacts for the footprint easier<br />"
"You can use is in <b>Library and board</b> editors </p>"
"<p>Usage with Library editor:</p>"
"<ul><li>1- Using Group tool, select any 2 of the following: pad, smd, hole and line.</li>"
"<li>2- Run ContactsRuller.ulp</li>"
"<li>3- You will have difference in X and Y in 3 units: mm, mil and inch.</li>"
"<li><strong>Note: Don't select more than 2 objects in the group.</li></ul>"
"<p>Usage with Board editor:</p>"
"<ul><li>1- Using Group tool select the part you want to measure the distance between its pads.</li>"
"<li>2-you will have a dialoug whith check boxe beside each contact name.</li>"
"<li>3-select any 2 contacts.</li>"
"<li>4-Press OK, you will have a dialoug with difference in X and Y in 3 units: mm, mil and inch. </li>"
"<li><strong>Note: Don't select more than 1 part in the group, and don't check more than 2 contacts in the dialoug.</li></ul>"
"<p><strong>Usage:</strong> RUN ContactsRuler.ulp<br />"
"<strong>Author:<a href=\"mailto:[email protected]\">[email protected]</a></strong></p>"
"</html>"
/* LOG
Version Date Author Comment
---------+----------------+--------------+---------------------------------------------------------------
V1.0 5 July 2020 Yahya Tawil First Create. Tested on Version 9.6.2 for Windows (64 bit)
V1.1 8 July 2020 Yahya Tawil Replace footprints() loop member with components(), to keep compatible with old versions
*/
int targets_num = 0;
int target_x[]= {0,0};
int target_y[] ={0,0};
int checked[]={0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
};
int brd_target_x[]={0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
};
int brd_target_y[]={0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0
};
void main(void) {
if(library)
{
library(L)
{
targets_num = 0;
L.packages(F)
{
F.contacts(C)
{
if(targets_num>2)
{
dlgMessageBox(": Select 2 elements only","+OK");
exit(-1);
}
if (C.pad)
{
if (ingroup(C.pad))
{
target_x[targets_num]=C.pad.x;
target_y[targets_num]=C.pad.y;
targets_num++;
//string str;
//sprintf(str,"\tPad: %s, (%f %f)\n",C.name, u2mm(C.pad.x), u2mm(C.pad.y));
//dlgMessageBox(str,"+OK");
}
}
else if (C.smd)
{
if (ingroup(C.smd))
{
target_x[targets_num]=C.smd.x;
target_y[targets_num]=C.smd.y;
targets_num++;
//string str;
//sprintf(str,"\tSmd: %s, (%f %f)\n",C.name, u2mm(C.smd.x), u2mm(C.smd.y));
//dlgMessageBox(str,"+OK");
}
}
}
F.holes(H)
{
if(targets_num>2)
{
dlgMessageBox(": Select 2 elements only","+OK");
exit(-1);
}
if (ingroup(H))
{
target_x[targets_num]=H.x;
target_y[targets_num]=H.y;
targets_num++;
//string str;
//sprintf(str,"\tHole: (%f %f)\n",u2mm(H.x), u2mm(H.y));
//dlgMessageBox(str,"+OK");
}
}
F.wires(W)
{
if(targets_num>2)
{
dlgMessageBox(": Select 2 elements only","+OK");
exit(-1);
}
if (ingroup(W))
{
target_x[targets_num]=W.x1;
target_y[targets_num]=W.y1;
targets_num++;
//string str;
//sprintf(str,"\tHole: (%f %f)\n",u2mm(W.x1), u2mm(W.y1));
//dlgMessageBox(str,"+OK");
}
}
}
if(targets_num<2)
{
dlgMessageBox(": Select 2 objects","+OK");
exit(-1);
}
string str;
string str1;
string str2;
string str3;
real diff_X= u2mm(target_x[1])-u2mm(target_x[0]);
real diff_Y = u2mm(target_y[1])-u2mm(target_y[0]);
sprintf(str1,";mm -> X1-X2= %f, Y1-Y2= %f\n",diff_X,diff_Y);
str += str1;
diff_X= u2inch(target_x[1])-u2inch(target_x[0]);
diff_Y = u2inch(target_y[1])-u2inch(target_y[0]);
sprintf(str2,"inch -> X1-X2= %f, Y1-Y2= %f\n",diff_X,diff_Y);
str += str2;
diff_X= u2mil(target_x[1])-u2mil(target_x[0]);
diff_Y = u2mil(target_y[1])-u2mil(target_y[0]);
sprintf(str3,"mil -> X1-X2= %f, Y1-Y2= %f\n",diff_X,diff_Y);
str += str3;
dlgMessageBox(str,"+OK");
exit(-1);
}
}
if(board)
{
board(B)
{
B.elements(E)
{
if(ingroup(E))
{
//string str;
//sprintf(str,"%s",E.package.name);
//dlgMessageBox(str,"+OK");
dlgDialog("Contacts Ruler ULP")
{
dlgLabel("Select 2 contacts to calculate distance");
dlgGridLayout
{
int col_num=-1;
E.package.contacts(C)
{
if(targets_num%30 == 0) col_num++;
dlgCell(targets_num-(30*col_num), col_num)
{
dlgCheckBox(C.name, checked[targets_num]);
brd_target_x[targets_num]=C.x;
brd_target_y[targets_num++]=C.y;
}
}
}
dlgSpacing(10);
dlgHBoxLayout
{
dlgStretch(1);
dlgPushButton("+OK")
{
int cnt=0;
for(int i=0;i<100;i++)
{
if(checked[i]==1)
{
target_x[cnt]=brd_target_x[i];
target_y[cnt++]=brd_target_y[i];
}
if(cnt>2)
{
dlgMessageBox(": Select 2 objects","+OK");
exit(-1);
}
}
string str;
string str1;
string str2;
string str3;
real diff_X= u2mm(target_x[1])-u2mm(target_x[0]);
real diff_Y = u2mm(target_y[1])-u2mm(target_y[0]);
sprintf(str1,";mm -> X1-X2= %f, Y1-Y2= %f\n",diff_X,diff_Y);
str += str1;
diff_X= u2inch(target_x[1])-u2inch(target_x[0]);
diff_Y = u2inch(target_y[1])-u2inch(target_y[0]);
sprintf(str2,"inch -> X1-X2= %f, Y1-Y2= %f\n",diff_X,diff_Y);
str += str2;
diff_X= u2mil(target_x[1])-u2mil(target_x[0]);
diff_Y = u2mil(target_y[1])-u2mil(target_y[0]);
sprintf(str3,"mil -> X1-X2= %f, Y1-Y2= %f\n",diff_X,diff_Y);
str += str3;
dlgMessageBox(str,"+OK");
dlgAccept();
}
dlgPushButton("Cancel") dlgReject();
}
};
}
}
}
}
if(schematic)
{
dlgMessageBox(": Open this ULP from the library or board Editor","+OK");
exit(-1);
}
}