forked from robertstarr/ulp_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
attrib-add.ulp
333 lines (290 loc) · 9.67 KB
/
attrib-add.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
#usage "<b>Add attribute to group selected part(s) in a schematic</b><p>"
"A number of predefined attributes are defined for use with bom-ex.ulp<p>"
"<author>http://www.bobstarr.net</author>";
//////////////////////////////////////////////////////////////////////////////
//
// ADD ATTRIBUTE
//
// Copyright (C) 2009-2010, Robert E. Starr (http://www.bobstarr.net)
//
// REVISION HISTORY:
//
// v1.02 - 03/31/2010 Added BOM control attribute options
//
// v1.03 - 04/02/2010 Added logic to toggle "Display" checkbox automatically
// depending on the attribute combo type selected.
//
// v1.04 - 04/11/2010 Corrected bug with "Display On/Off" option.
//
// v1.05 - 04/14/2010 Added addtional display options.
//
// v1.06 - 09/20/2011 Added FREQ attribute
//
// v1.07 - 01/30/2012 Fixed ingroup() usage for Eagle v6.
//
// v1.08 - 05/08/2012 Corrected bugs with ingroup() usage for Eagle v6.2
//
// v1.09 - 10/10/2013 Added option to remove attributes for group.
//
//////////////////////////////////////////////////////////////////////////////
//
// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND,
// EXPRESSED OR IMPLIED. IF YOU DON'T LIKE IT, DON'T USE IT!
//
//////////////////////////////////////////////////////////////////////////////
string Version = "1.09";
string fileName;
int fDisplay = 1;
string strCmd; // script command text
string strAttrName;
string strAttrValue;
string strAttribs[] = {
"PARTNO", // 0 part number (mfg specific)
"BOM", // 1 BOM options for bom-ex.ulp
"DNP", // 2 do not place (T=TRUE/F=FALSE)
"PLACE", // 3 optional place message text
"TOL", // 4 tolerance (1%, 5%, etc)
"TC", // 5 temp coefficient (caps, NPO, X7R, etc)
"VOLT", // 6 voltage rating (caps, etc)
"RATE", // 7 rating (watts, etc)
"COLOR", // 8 color (for leds, etc)
"LABEL", // 9 label (for buttons, switches, etc)
"TYPE", // 10 type field
"SIZE", // 11 package or other size code (0805, etc)
"LOAD", // 12 load field
"FREQ", // 13 xtal frequencies and such
"OPT" // 14 generic option text
};
// some common values for attributes above
string strVal0 = "?";
string strVal1 = "EXCLUDE:INCLUDE";
string strVal2 = "T:F";
string strVal3 = "(DNP):DO NOT PLACE:HAND PLACE";
string strVal4 = "1%:5%:10%:20%";
string strVal5 = "NPO:"
"C0G:"
"X5F:X5P:X5R:X5S:X5T:X5U:X5V:"
"X6F:X6P:X6R:X6S:X6T:X6U:X6V:"
"X7F:X7P:X7R:X7S:X7T:X7U:X7V:"
"Y5F:Y5P:Y5R:Y5S:Y5T:Y5U:Y5V:"
"Y6F:Y6P:Y6R:Y5S:Y6T:Y6U:Y6V:"
"Y7F:Y7P:Y7R:Y7S:Y7T:Y7U:Y7V:"
"Z5F:Z5P:Z5R:Z5S:Z5T:Z5U:Z5V:"
"Z6F:Z6P:Z6R:Z5S:Z6T:Z6U:Z6V:"
"Z7F:Z7P:Z7R:Z7S:Z7T:Z7U:Z7V";
string strVal6 = "2.5V:3V:4V:6V:6.3V:8V:10V:12.5V:16V:20V:25V:30V:35V:50V:60V:63V:75V:80V:100V:125V";
string strVal7 = "1/4W:1/2W:1W:2W:3W:4W:5W:10W";
string strVal8 = "RED:GRN:ORG:YEL:BLU:AMB";
string strVal9 = "RESET:POWER:ON/OFF:LEVEL:GAIN";
string strVal10 = "TANT:LYTIC:POLY:MICA:SUPERCAP";
string strVal11 = "(0402):(0603):(0805):(1005):(1206):(1210):(1508):(2010):(2012):(2512)";
string strVal12 = "1A:2A:3A:4A:5A:10A:20A:25A";
string strVal13 = "8MHz:16MHz";
string strVal14 = "?";
string strValues[];
int nSelAttr = 0; // combo box selection
int nSelValue = 0; // combo box selection
//////////////////////////////////////////////////////////////////////////////
// Combo Selection Change Notification Handlers
void OnComboChangeValue()
{
strAttrValue = strValues[nSelValue];
}
void OnComboChangeAttr()
{
strAttrName = strAttribs[nSelAttr];
switch(nSelAttr)
{
case 0:
strsplit(strValues, strVal0, ':');
break;
case 1:
strsplit(strValues, strVal1, ':');
break;
case 2:
strsplit(strValues, strVal2, ':');
break;
case 3:
strsplit(strValues, strVal3, ':');
break;
case 4:
strsplit(strValues, strVal4, ':');
break;
case 5:
strsplit(strValues, strVal5, ':');
break;
case 6:
strsplit(strValues, strVal6, ':');
break;
case 7:
strsplit(strValues, strVal7, ':');
break;
case 8:
strsplit(strValues, strVal8, ':');
break;
case 9:
strsplit(strValues, strVal9, ':');
break;
case 10:
strsplit(strValues, strVal10, ':');
break;
case 11:
strsplit(strValues, strVal11, ':');
break;
case 12:
strsplit(strValues, strVal12, ':');
break;
case 13:
strsplit(strValues, strVal13, ':');
break;
case 14:
strsplit(strValues, strVal14, ':');
break;
}
strAttrValue = strValues[0];
// Set the current radio button selection according
// to the attribute type the use is adding.
switch(nSelAttr)
{
case 0: // PARTNO
case 1: // BOM
fDisplay = 0; // Display=off
break;
case 2: // DNP
fDisplay = 0; // Display=None
break;
default:
fDisplay = 1; // Display=Value
break;
}
}
//////////////////////////////////////////////////////////////////////////////
// Get count of items selected
int GetSelCount(UL_SCHEMATIC sch)
{
int cnt = 0;
sch.parts(P)
{
P.instances(I)
{
if (ingroup(I))
{
// make sure it has a package and name
if (P.device.package && P.name)
++cnt;
}
}
}
return cnt;
}
//////////////////////////////////////////////////////////////////////////////
// Script Entry Point
if (schematic)
{
schematic(SCH)
{
fileName = filesetext(SCH.name, "_AddAttrib.scr");
string title = "Add Attribute - v" + Version;
OnComboChangeAttr();
if (GetSelCount(SCH) == 0)
{
dlgMessageBox("No items selected!");
exit(0);
}
int nResult = dlgDialog(title)
{
dlgHBoxLayout
{
dlgGroup("Attribute")
{
dlgGridLayout
{
dlgCell(1,0) dlgLabel("Name");
dlgCell(1,1) dlgStringEdit(strAttrName);
dlgCell(1,2) dlgComboBox(strAttribs, nSelAttr) OnComboChangeAttr();
dlgCell(3,0) dlgLabel("Value");
dlgCell(3,1) dlgStringEdit(strAttrValue)
dlgCell(3,2) dlgComboBox(strValues, nSelValue) OnComboChangeValue();
}
}
dlgVBoxLayout
{
dlgGroup("Display")
{
dlgRadioButton("Off", fDisplay);
dlgRadioButton("Value", fDisplay);
dlgRadioButton("Name", fDisplay);
}
dlgStretch(1);
}
}
dlgHBoxLayout
{
dlgPushButton("Add") dlgAccept(1);
dlgPushButton("Remove") dlgAccept(2);
dlgPushButton("-Cancel") dlgReject();
}
};
if (!nResult)
exit(0);
int cnt = 0;
int sheetswitched;
strCmd = "";
SCH.sheets(S)
{
sheetswitched = 0;
S.parts(P)
{
P.instances(I)
{
if (ingroup(I))
{
// make sure it has a package and name
if (P.device.package && P.name)
{
// Add attribute to group
if (nResult == 1)
{
string tmp;
if (sheetswitched == 0)
{
sprintf(tmp, "EDIT .s%d;\n", S.number);
strCmd += tmp;
sheetswitched = 1;
}
string disp;
if (fDisplay == 0)
disp = "OFF";
else if (fDisplay == 1)
disp = "VALUE";
else
disp = "NAME";
sprintf(tmp, "CHANGE DISPLAY %s;\n", disp);
strCmd += tmp;
sprintf(tmp, "ATTRIBUTE %s %s '%s';\n", P.name, strAttrName, strAttrValue);
strCmd += tmp;
++cnt;
}
else if (nResult == 2) // remove attribute from group
{
string tmp;
sprintf(tmp, "ATTRIBUTE %s %s DELETE;\n", P.name, strAttrName);
strCmd += tmp;
++cnt;
}
}
}
}
}
}
if (!cnt)
dlgMessageBox("No items selected!");
// dlgMessageBox(strCmd);
exit(strCmd);
}
}
else
{
dlgMessageBox("Start this ULP in Schematic!", "OK");
}
// End-Of-File