forked from robertstarr/ulp_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod-duplicate.ulp
437 lines (364 loc) · 12.1 KB
/
mod-duplicate.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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
#usage "<b>Duplicate placement and routing of a hierarchical module</b>\n"
"<p>"
"This program duplicates the board placement and routing of a module "
"from a source hierarchical module. The ULP displays and allows the "
"user to select the source module placement to duplicate from and "
"desitination module is duplicated with X/Y offsets currently set.<p>"
"<author>http://www.bobstarr.net</author>"
//////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015, Robert E. Starr (http://www.bobstarr.net)
//
// REVISION HISTORY:
//
// v1.00 - 02/25/2015 (RES) - Initial Release
//
//////////////////////////////////////////////////////////////////////////////
//
// 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.00";
string fileName;
string configFilename = "mod-duplicate.cfg";
// Variables below are stored/recalled from config file
real offsetX = 0.0;
real offsetY = 0.0;
string powerSig[];
int nPowerSigCnt;
int fScriptExec = 1; // execute script automatically after generating
int nSelSrc, nSrcCnt;
int nSelDest, nDestCnt;
int nIDCount;
string strSrc, strSrcMod[];
string strDest, strDestMod[];
/* Common power signals to route, add more as needed */
powerSig[nPowerSigCnt++] = "VDD";
powerSig[nPowerSigCnt++] = "VSS";
powerSig[nPowerSigCnt++] = "V+";
powerSig[nPowerSigCnt++] = "V-";
powerSig[nPowerSigCnt++] = "+5V";
powerSig[nPowerSigCnt++] = "+3V3";
powerSig[nPowerSigCnt++] = "+15V";
//powerSig[nPowerSigCnt++] = "-15V";
powerSig[nPowerSigCnt++] = "GND";
powerSig[nPowerSigCnt++] = "AGND";
powerSig[nPowerSigCnt++] = "CGND";
//////////////////////////////////////////////////////////////////////////////
void LoadConfigSettings()
{
string a[];
int n;
// Should be 5 lines of data in config file
if ((n = fileread(a, filedir(argv[0])+configFilename)) == 3)
{
int i = 0;
offsetX = strtod(a[i++]);
offsetY = strtod(a[i++]);
fScriptExec = strtol(a[i++]);
}
}
void SaveConfigSettings()
{
// save the config settings
output(filedir(argv[0])+configFilename, "wt")
{
printf("%f\n", offsetX);
printf("%f\n", offsetY);
printf("%d\n", fScriptExec);
}
}
string GetStyle(int n)
{
if (n == 0)
return "CONTINUOUS";
else if (n == 1)
return "LONGDASH";
else if (n == 2)
return "SHORTDASH";
else if (n == 3)
return "DASHDOT";
return "";
}
string GetViaShape(int n)
{
if (n == 0)
return "SQUARE";
else if (n == 1)
return "ROUND";
else if (n == 2)
return "OCTAGON";
return "";
}
string GetPour(int n)
{
if (n == 0)
return "SOLID";
else if (n == 1)
return "HATCH";
else if (n == 2)
return "CUTOUT";
return "";
}
int IsPowerSignal(string name)
{
int i;
int found = 0;
for(i=0; i < nPowerSigCnt; i++)
{
if (name == powerSig[i])
{
found = 1;
break;
}
}
return found;
}
int DuplicatePlacement(UL_BOARD B)
{
int i;
int cnt = 0;
string pid[];
string name;
printf("#\n# Duplicate module '%s' PLACEMENT from '%s'\n#\n", strDest, strSrc);
printf("GRID MIL\n");
B.elements(E)
{
if (strstr(E.name, strSrc + ':') == 0)
{
string component = strsub(E.name,strlen(strSrc) + 1);
sprintf(name, "%s:%s", strDest, component);
printf("MOVE %s (%5.4f %5.4f);\n", name, u2mil(E.x) + offsetX, u2mil(E.y) + offsetY);
printf("ROTATE =R%f %s;\n", E.angle, name);
if (E.mirror)
printf("MIRROR %s;\n", name);
++cnt;
}
}
return cnt;
}
int DuplicateRoute(UL_BOARD B)
{
int i;
int cnt = 0;
int pwrsig;
string pid[];
string name;
real dx,dy;
real x1, y1, x2, y2, x3, y3;
real xc, yc;
printf("#\n# Duplicate module '%s' ROUTING from '%s'\n#\n", strDest, strSrc);
printf("GRID MIL\n");
printf("SET WIRE_BEND 2\n");
dx = offsetX;
dy = offsetY;
B.signals(S)
{
printf("# DEBUG '%s' '%s'\n", S.name, strSrc);
if (strstr(S.name, strSrc + ':') == 0)
{
string net = strsub(S.name,strlen(strSrc) + 1);
/* sprintf(name, "%s:%s", strDest, net); */
/*** DUPLICATE WIRES ***/
S.wires(W)
{
if (W.width) /* airwire check */
{
if(!W.arc)
{
/* Handle simple line case */
printf("CHANGE LAYER %d\n", W.layer);
printf("CHANGE STYLE %s;\n", GetStyle(W.style));
printf("WIRE '%s' %f (%f %f) (%f %f)\n",
name, u2mil(W.width),
u2mil(W.x1)+dx, u2mil(W.y1)+dy,
u2mil(W.x2)+dx, u2mil(W.y2)+dy);
}
else
{
/* Handle ARC case */
x1 = u2mil(W.arc.x1)+dx;
y1 = u2mil(W.arc.y1)+dy;
xc = u2mil(W.arc.xc)+dx;
yc = u2mil(W.arc.yc)+dy;
x2 = u2mil(2*W.arc.xc - W.arc.x1)+dx;
y2 = u2mil(2*W.arc.yc - W.arc.y1)+dy;
x3 = u2mil(W.arc.x2)+dx;
y3 = u2mil(W.arc.y2)+dy;
printf("CHANGE LAYER %d\n", W.arc.layer);
printf("CHANGE WIDTH %f\n", u2mil(W.arc.width));
printf("CHANGE STYLE %s;\n", GetStyle(W.style));
printf("ARC '%s' CCW (%f %f) (%f %f) (%f %f)\n",
name, x1, y1, x2, y2, x3, y3);
}
}
}
/*** DUPLICATE VIAS ***/
S.vias(V)
{
printf("CHANGE DRILL %f\n", u2mil(V.drill));
printf("VIA '%s' %f %s (%f %f)\n",
name, u2mil(V.diameter[1]), GetViaShape(V.shape[1]),
u2mil(V.x)+dx, u2mil(V.y)+dy);
}
/*** DUPLICATE POLYGONS ***/
S.polygons(P)
{
printf("CHANGE LAYER %d;\n", P.layer);
printf("CHANGE ISOLATE %f;\n",u2mil(P.isolate));
printf("CHANGE RANK %d;\n", P.rank);
printf("CHANGE ORPHANS %s;\n", P.orphans ? "ON" : "OFF");
printf("CHANGE POUR %s;\n", GetPour(P.pour));
printf("CHANGE RANK %d;\n", P.rank);
printf("CHANGE SPACING %f;\n", u2mil(P.spacing));
printf("CHANGE THERMALS %s;\n", P.thermals ? "ON" : "OFF");
printf("POLYGON %s %f", name, u2mil(P.width));
P.wires(W)
{
x1 = u2mil(W.x1)+dx;
y1 = u2mil(W.y1)+dy;
x2 = u2mil(W.x2)+dx;
y2 = u2mil(W.y2)+dy;
printf(" (%f %f)",x1,y1);
}
printf(" (%f %f);\n",x2,y2);
}
++cnt;
}
}
return cnt;
}
void OnComboChangeSource()
{
strSrc = strSrcMod[nSelSrc];
}
void OnComboChangeDest()
{
strDest = strDestMod[nSelDest];
}
int MainAppDialog()
{
int nResult = dlgDialog("Module Duplicate Placement")
{
string title = "Module Duplicate Placement v" + Version;
dlgVBoxLayout
{
dlgSpacing(5);
dlgGroup(title)
{
dlgVBoxLayout
{
dlgGroup("Source/Destination")
{
dlgGridLayout
{
dlgCell(1,0) dlgLabel("Source module to duplicate placement from");
dlgCell(1,1) dlgComboBox(strSrcMod, nSelSrc) OnComboChangeSource();
dlgCell(2,0) dlgLabel("Destination module to place with offset");
dlgCell(2,1) dlgComboBox(strDestMod, nSelDest) OnComboChangeDest();
}
}
dlgGridLayout
{
dlgCell(1,0) dlgLabel("X-Offset");
dlgCell(1,1) dlgRealEdit(offsetX);
dlgCell(2,0) dlgLabel("Y-Offset");
dlgCell(2,1) dlgRealEdit(offsetY);
}
}
}
}
dlgHBoxLayout
{
dlgPushButton("OK") dlgAccept();
dlgPushButton("-Cancel") dlgReject();
dlgCheckBox("&Execute Script", fScriptExec);
}
};
return nResult;
}
//////////////////////////////////////////////////////////////////////////////
// Script Entry Point
if (board) board(B)
{
LoadConfigSettings();
project.schematic(S)
{
S.allparts(P)
{
// Module instances
if (P.modulepart)
{
P.modulepart.instances(I)
{
//printf("# DEBUG %s is a virtual part from %s in module %s with part instance on sheet %d\n",
// P.name, P.modulepart.name, P.module.name, I.sheet);
if (P.device.package)
{
string key[];
int n = strsplit(key, P.name, ':');
if (n > 1)
{
string modulename = "";
for (int i = 0; i < n - 1; i++)
{
if (modulename == "")
{
modulename = key[i];
}
else
{
sprintf(modulename,"%s:%s",modulename,key[i]);
}
/* Collect unique module names */
if (!lookup(strSrcMod, modulename, 0))
{
strSrcMod[nSrcCnt++] = modulename;
strDestMod[nDestCnt++] = modulename;
}
}
}
}
}
}
}
}
if (nDestCnt < 2)
{
dlgMessageBox("\n Must have at least two module instances \n");
exit(0);
}
nSelSrc = 0;
strSrc = strSrcMod[nSelSrc];
nSelDest = 1;
strDest = strDestMod[nSelDest];
if (MainAppDialog() == 0)
{
SaveConfigSettings();
exit(0);
}
fileName = filesetext(B.name, "_ModDupPlace.scr");
output(fileName)
{
printf("#\n# Generated by mod-duplicate.ulp\n#\n");
printf("# '%s at %s;\n", B.name, t2string(time()));
printf("# '%s;\n#\n", EAGLE_SIGNATURE);
int cnt = 0;
cnt = DuplicatePlacement(B);
if (cnt)
DuplicateRoute(B);
printf("RATSNEST;\n");
printf("GRID LAST;\n");
SaveConfigSettings();
if (fScriptExec && cnt)
exit("SCRIPT '" + fileName + "';");
else
exit(0);
}
}
else
{
dlgMessageBox("\n Start this ULP in a Board \n");
exit (0);
}