-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathselect5.ulp
421 lines (399 loc) · 15.7 KB
/
select5.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
//======================================================
// SELECT v 1.0.4
//
// Eagle v5.7 or later is required. Only the Board and Schematic editors are supported
//
// Selects components or nets listed at the command line and filter/subtract/add or make new group
//
// This software is released under the BSD 4-clause license:
//
// Copyright (c) 2010-2011, Damhave Systems
// All rights reserved.
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the distribution.
// * Neither the name of the Damhave Systems nor the names of its contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
// BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
// OF SUCH DAMAGE.
//======================================================
#require 7.0200
#usage "<B>Selects components or nets listed at the command line</B>"
"<P>"
"The component or nets specified at the commandline can be added or subtract from the existing group, filter the existing group, or define a new group.<br>"
"The components/nets are specified as a space separated list of exact names, names with wildcards (see the eagle SHOW command) or by using a regular expressions or any combination.<br>"
"The selection can also be saved or loaded from a specifed file. The .sel extension is automatically added to the filename. The save/load/clear of a selection are experimental features"
" - sometimes the selection of nets cannot be cleared from within the ulp, maybe a missing refresh.<br><br><br>"
"<b>Usage:</b>"
"<blockquote>run select [-c]{flag} {component}|{device type}|{package}|{value}<br>"
"run select -n{flag} {net}|{class type}<br>"
"run select > filename<br>"
"run select < filename</blockquote>"
"<b>Flags:</b>"
"<blockquote>a: add to existing group<br>"
"c: select Components<br>"
"d: select components of specified Device type<br>"
"e: use regular Expressions (regex) instead of wildcards<br>"
"f: Filter existing group<br>"
"k: Keep nets when filtering components and vice versa<br>"
"l: select nets/signals of specified cLass<br>"
"n: select nets/signals<br>"
"p: select components with specified Packages<br>"
"s: Subtract from existing group<br>"
"v: select components with specified Values<br>"
"<I>The existing group is cleared unless one of the flags -a, -s or -f are used.<br>"
"The -c flag is default set if no -n is specified</I></blockquote>"
"<P>"
"<b>Examples:</b><br><br>"
"Select all resistors and capacitors:"
"<blockquote>run select -c R* C*</blockquote>"
"or"
"<blockquote>run select R* C*</blockquote>"
"Select all resistors in 0603:"
"<blockquote>run select -c R* C*<br>"
"run select -fp *0603*</blockquote>"
"Select all LM358MX devices:"
"<blockquote>run select -d LM358MX</blockquote>"
"Select all 100nF capacitors:"
"<blockquote>run select C*<br>"
"run select -fv 100nF</blockquote>"
"Select all RESET nets/signals:"
"<blockquote>run select -n *RESET*</blockquote>"
"Select all positive supply nets:"
"<blockquote>run select -n *+*V*</blockquote>"
"Select all negative supply nets:"
"<blockquote>run select -n *-*V*</blockquote>"
"Clear the selection group:"
"<blockquote>run select</blockquote>"
"Save the selection C1, C2, C3, C4 in the file decoupling.sel:"
"<blockquote>run select C1 C2 C3 C4<br>"
"run select > decoupling</blockquote>"
"Load the selection group from the file decoupling.sel:"
"<blockquote>run select < decoupling</blockquote>"
"Rotate all LEDs 45 degrees:"
"<blockquote>run select -cd *LED*<br>"
"rotate R45<ENTER><br>"
"<RIGHT MOUSE CLICK><ROTATE GROUP></blockquote>"
"Change all 0805 capactors to 0603:"
"<blockquote>run select -p *0805*<br>"
"run select -cf C*<br>"
"change package 'C0603K'<ENTER><br>"
"<RIGHT MOUSE CLICK><CHANGE GROUP></blockquote>"
"<b>Hints:</b><br><br>"
"<I>When using this command as a more advanced show command it can be an advantage in the schematic editor to set the background color to black.<br>"
"This command is best used with the group commands. Select the tool you want and right click in your working area to see the options move group, copy group, change group, smash group, mirror group..</I>"
"<P>"
"Copyright (c) 2010-2011 Damhave Systems"
"<P>"
"<Author>Danny Damhave<br>Damhave Systems<br>www.damhave.com</Author><br><br>"
"This ulp is released under the BSD 4-clause license. See source code for details!"
enum {false, true};
int firstInList = 1, addFlag = false, keepFlag = false, subtractFlag = false, selectClassesFlag = false, selectComponentsFlag = true, selectDeviceTypeFlag=false, regexFlag = false, filterFlag = false, selectNetsFlag = false, selectPackagesFlag = false, selectValuesFlag = false;
int isMatch(string s, string test, int useRegex)
{
string regex = !useRegex ? "^" : test;
if (!useRegex)
{
for(int i = 0; test[i];)
{
switch(test[i])
{
case '[': regex += strsub(test, i, strchr(test, ']', i) - i + 1), i += strchr(test, ']', i) - i + 1; break;
case '?': regex += ".", i++; break;
case '*': regex += ".*", i++; break;
case '+': case '^': case '$': case '.': case '{': case '}': case '(': case ')': case '|': case '\\':
regex += "\\" + test[i], i++; break;
default: regex += test[i], i++;
}
}
regex +='$';
}
return strxstr(s, regex, 0) == 0;
}
int inList(string name)
{
for(int i = firstInList; i < argc && argv[i] != ""; i++)
{
if (regexFlag)
{
if (isMatch(name, argv[i], regexFlag)) return true;
}
else
{
if (isMatch(strupr(name), strupr(argv[i]), regexFlag)) return true;
}
}
return false;
}
int inListCaseSensitive(string name)
{
for(int i = firstInList; i < argc && argv[i] != ""; i++)
if (isMatch(name, argv[i], regexFlag)) return true;
return false;
}
// ***** The ulp begins here *****
if (!board && !schematic && !dlgMessageBox("Can only be used in the board and schematic editors.\n")) exit(1);
if (EAGLE_VERSION < 5 || (EAGLE_VERSION == 5 && EAGLE_RELEASE < 7) && !dlgMessageBox("Requires Eagle v5.7 or later.\n")) exit(1);
if (argc>firstInList)
{
string flags = argv[firstInList];
if (flags[0] == '-')
{
if (strlen(flags) == 1 && !dlgMessageBox("No flags.\n")) exit(1);
for (int i = 1; flags[i]; i++)
{
switch (flags[i]) // Note: If no -n flag use default -c
{
case 'a' : addFlag = true; break;
case 'c' : selectComponentsFlag = true; break;
case 'd' : selectDeviceTypeFlag = true; break;
case 'e' : regexFlag = true; break;
case 'f' : filterFlag = true; break;
case 'k' : keepFlag = true; break;
case 'l' : selectClassesFlag = true; break;
case 'n' : selectNetsFlag = true, selectComponentsFlag = false; break;
case 'p' : selectPackagesFlag = true; break;
case 's' : subtractFlag = true; break;
case 'v' : selectValuesFlag = true; break;
default : dlgMessageBox("No such flag.\n"); exit(1);
}
}
firstInList++;
if ((addFlag && subtractFlag) || (filterFlag && (addFlag || subtractFlag)) || (selectComponentsFlag && selectNetsFlag) || (selectComponentsFlag && selectClassesFlag) && !dlgMessageBox("Illegal flag combination.\n")) exit(1);
}
else if (flags[0] == '>' || flags[0] == '<') // Check for save/load the selection from file
{
string fName, fDir;
if (flags == ">" || flags == "<") // White space between operator and filename ?
{
if (argc<=firstInList && dlgMessageBox("No filename specified.\n")) exit(1);
fName = fDir + filesetext(argv[firstInList+1], ".sel");
}
else fName = fDir + filesetext(strsub(argv[firstInList], 1), ".sel"); // No space between operator and filename
if (schematic) schematic(S) { fDir = filedir(S.name); } else if (board) board(brd) { fDir = filedir(brd.name); } // Get the path to the project directory
fName = fDir + fName;
if (flags[0] == '>')
{ // Save selection to file
output(fName, "wt")
{
if(schematic) schematic(S)
{
printf("-c");
S.parts(part) { if (ingroup(part)) printf(" %s", part.name); }
printf("\n-n");
S.sheets(sch) { sch.nets(net) { if (ingroup(net)) printf(" %s ", net.name); } }
printf("\n");
}
else if (board) board(brd)
{
printf("-c");
brd.elements(element) { if (ingroup(element)) printf(" %s", element.name); }
printf("\n-n");
brd.signals(signal) { if (ingroup(signal)) printf(" %s", signal.name); }
printf("\n");
}
}
}
else // Load selection from file
{
string lines[], list;
int l, nLines;
if (!filesize(fName) && dlgMessageBox("No such file.\n")) exit(1);
{
nLines = fileread(lines, fName);
if (schematic) schematic(S) { clrgroup(S); S.sheets(sch) { clrgroup(sch); } } // Make sure nothing is selected before the selection is loaded from file
if (board) board(brd) { clrgroup(brd); }
for (l = 0; l < nLines; l++)
{
list = strsub(lines[l], 2)+" "; // Remove -c or -n. The list now has a space in the beginning and at the end
if (strsub(lines[l], 0, 3) == "-c ") // Components ?
{
if(schematic) schematic(S)
{
S.parts(part) { if (strstr(list, " "+part.name+" ")>=0) setgroup(part); }
}
else if (board) board(brd)
{
brd.elements(element) { if (strstr(list, " "+element.name+" ")>=0) setgroup(element); }
}
}
if (strsub(lines[l], 0, 3) == "-n ") // Nets ?
{
if(schematic) schematic(S)
{
S.sheets(sch) { sch.nets(net) { if (strstr(list, " "+net.name+" ")>=0) setgroup(net); } }
}
else if (board) board(brd)
{
brd.signals(signal) { if (strstr(list, " "+signal.name+" ")>=0) setgroup(signal); }
}
}
}
}
}
exit(0); // We are done with the save/load of a selection
}
else; // The default no flags or filename is equivalent to -c
}
status("Selecting Objects...");
if(schematic)
{
if (!addFlag && !subtractFlag && !filterFlag) schematic(S) { clrgroup(S); S.sheets(sch) { clrgroup(sch); } }
if (argc>firstInList)
{
schematic(S)
{
S.sheets(sch) // Currently it seems that groups cannot cover more than the current sheet, so this will maybe work in the future ;-)
{
if (selectClassesFlag)
{
if (!addFlag && !subtractFlag && !keepFlag) sch.parts(part) part.instances(I) clrgroup(I);
sch.nets(net)
{
if (inList(net.class.name))
{
if (filterFlag); else if (addFlag || !subtractFlag) setgroup(net); else if (subtractFlag) clrgroup(net);
}
else if (filterFlag) clrgroup(net);
}
}
else if (selectNetsFlag)
{
if (!addFlag && !subtractFlag && !keepFlag) sch.parts(part) clrgroup(part);
sch.nets(net)
{
if (inList(net.name))
{
if (filterFlag); else if (addFlag || !subtractFlag) setgroup(net); else if (subtractFlag) clrgroup(net);
}
else if (filterFlag) clrgroup(net);
}
}
else if (selectComponentsFlag && !selectDeviceTypeFlag && !selectPackagesFlag && !selectValuesFlag)
{
if (!addFlag && !subtractFlag && !keepFlag) sch.nets(net) clrgroup(net);
sch.parts(part)
{
if (inList(part.name))
{
if (filterFlag); else if (addFlag || !subtractFlag) part.instances(I) setgroup(I); else if (subtractFlag) part.instances(I) clrgroup(I);
}
else if (filterFlag) clrgroup(part);
}
}
else if (selectDeviceTypeFlag)
{
if (!addFlag && !subtractFlag && !keepFlag) sch.nets(net) clrgroup(net);
sch.parts(part)
{
if (inList(part.device.name))
{
if (filterFlag); else if (addFlag || !subtractFlag) setgroup(part); else if (subtractFlag) clrgroup(part);
}
else if (filterFlag) clrgroup(part);
}
}
else if (selectPackagesFlag)
{
if (!addFlag && !subtractFlag && !keepFlag) sch.nets(net) clrgroup(net);
sch.parts(part)
{
if (part.device.package && inList(part.device.package.name)) // not all parts have a package!
{
if (filterFlag); else if (addFlag || !subtractFlag) part.instances(I) setgroup(I); else if (subtractFlag) part.instances(I) clrgroup(I);
}
else if (filterFlag) clrgroup(part);
}
}
else if (selectValuesFlag)
{
if (!addFlag && !subtractFlag && !keepFlag) sch.nets(net) clrgroup(net);
sch.parts(part)
{
if (inListCaseSensitive(part.value))
{
if (filterFlag); else if (addFlag || !subtractFlag) part.instances(I) setgroup(I); else if (subtractFlag) part.instances(I) clrgroup(I);
}
else if (filterFlag) clrgroup(part);
}
}
}
}
}
}
else if(board)
{
if (!addFlag && !subtractFlag && !filterFlag) board(brd) { clrgroup(brd); }
if (argc>firstInList)
{
board(brd)
{
if (selectClassesFlag)
{
if (!addFlag && !subtractFlag && !keepFlag) brd.elements(element) clrgroup(element);
brd.signals(signal)
{
if (inList(signal.class.name))
{
if (filterFlag); else if (addFlag || !subtractFlag) setgroup(signal); else if (subtractFlag) clrgroup(signal);
}
else if (filterFlag) clrgroup(signal);
}
}
else if (selectNetsFlag)
{
if (!addFlag && !subtractFlag && !keepFlag) brd.elements(element) clrgroup(element);
brd.signals(signal)
{
if (inList(signal.name))
{
if (filterFlag); else if (addFlag || !subtractFlag) setgroup(signal); else if (subtractFlag) clrgroup(signal);
}
else if (filterFlag) clrgroup(signal);
}
}
else if (selectComponentsFlag && !selectDeviceTypeFlag && !selectPackagesFlag && !selectValuesFlag)
{
if (!addFlag && !subtractFlag && !keepFlag) brd.signals(signal) clrgroup(signal);
brd.elements(element)
{
if (inList(element.name))
{
if (filterFlag); else if (addFlag || !subtractFlag) setgroup(element); else if (subtractFlag) clrgroup(element);
}
else if (filterFlag) clrgroup(element);
}
}
else if (selectPackagesFlag)
{
if (!addFlag && !subtractFlag && !keepFlag) brd.signals(signal) clrgroup(signal);
brd.elements(element)
{
if (inList(element.package.name))
{
if (filterFlag); else if (addFlag || !subtractFlag) setgroup(element); else if (subtractFlag) clrgroup(element);
}
else if (filterFlag) clrgroup(element);
}
}
else if (selectValuesFlag)
{
if (!addFlag && !subtractFlag && !keepFlag) brd.signals(signal) clrgroup(signal);
brd.elements(element)
{
if (inListCaseSensitive(element.value))
{
if (filterFlag); else if (addFlag || !subtractFlag) setgroup(element); else if (subtractFlag) clrgroup(element);
}
else if (filterFlag) clrgroup(element);
}
}
}
}
}
exit("WINDOW;");