Repository navigation
Expand file tree
/
Copy pathspin-all.ulp
More file actions
129 lines (116 loc) · 3.08 KB
/
Copy pathspin-all.ulp
File metadata and controls
129 lines (116 loc) · 3.08 KB
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
#usage "<b>Set spin flag on all (smashed) texts</b>\n"
"<p>"
"Generates a command sequence which set spin flag at all texts."
"RUN spin-all [ON | OFF]<br>"
"If no option used, the default is ON.<br>"
"Option ON OFF are not case sensitive.<br>"
"<p>"
"<author>Author: support@cadsoft.de</author>"
// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED
#require 5.1200
string Version = "1.0"; // 2009-01-15 alf@cadsoft.de
int test = 0;
int onoff = 0;
if (strupr(argv[1]) == "ON") onoff = 0;
if (strupr(argv[1]) == "OFF") onoff = 1;
int tx[], ty[], tl[], ts[], index[];
real ta[];
string tv[];
int cnttext = 0;
int cnt_unsmashed = 0;
int lVisible[];
int changed = 0;
string cmd;
string h;
string scriptfile;
/*** Functions ***/
void header(void) {
sprintf(cmd, "# Exported from %s\n# by %s, %s\n", filesetext(scriptfile, ".brd"), filename(argv[0]), EAGLE_SIGNATURE );
// cmd += "SET UNDO_LOG OFF;\n"; // advisable for speed reasons
cmd += "GRID mm;\n";
}
void addlist(UL_TEXT T) {
ta[cnttext] = T.angle;
tl[cnttext] = T.layer;
tx[cnttext] = T.x;
ty[cnttext] = T.y;
ts[cnttext] = T.spin;
tv[cnttext] = T.value;
cnttext++;
return;
}
if (board) board(B) {
B.layers(L) lVisible[L.number] = L.visible;
scriptfile = filesetext(B.name, ".scr");
header();
B.texts(T) { // Texts in Board
addlist(T);
}
B.elements(E) {
E.texts(T) { // *** smased texts in elements ***
if (T.value) addlist(T); // only texts with value,
}
E.package.texts(T) { // *** non smased
cnt_unsmashed++;
}
}
sort(cnttext, index, tl);
int actlayer = 0;
for(int n = 0; n < cnttext; n++) {
if (actlayer != tl[index[n]]) {
actlayer = tl[index[n]];
sprintf(h, "DISPLAY NONE %d;\n", actlayer);
cmd+=h;
}
if (ts[index[n]] == onoff || ta[index[n]] != 0.0) {
sprintf(h, "ROTATE =SR0 (%.4f %.4f);\n",
u2mm(tx[index[n]]), u2mm(ty[index[n]]) );
cmd += h;
changed++;
}
}
string info;
if (cnt_unsmashed) sprintf(info, "%d unsmached texts found.", cnt_unsmashed);
if (!changed) {
dlgMessageBox("No changes made.\n\n"+info, "OK");
exit(0);
}
// prepare display mode
cmd += "DISPLAY NONE ";
for(int l = 1; l < 255; l++) {
if (lVisible[l]) {
sprintf(h, " %d", l);
cmd += h;
}
}
cmd += ";\n";
cmd += "SET UNDO_LOG ON;\n";
cmd += "GRID LAST;\n";
// EditBox
if (test) {
int Result = dlgDialog("Spin all texts") {
dlgHBoxLayout {
dlgTextEdit(cmd);
dlgVBoxLayout {
dlgSpacing(300);
}
}
dlgHBoxLayout {
dlgSpacing(500);
}
dlgLabel(info);
dlgHBoxLayout {
dlgPushButton("+&Execute") dlgAccept();
dlgPushButton("-&Cancel") dlgReject();
dlgStretch(1);
}
};
if (Result == 0) exit(0);
}
output(scriptfile, "wtD") printf("%s", cmd);
exit("SCRIPT '" + scriptfile + "';");
}
else {
dlgMessageBox("Start this ULP in a board.", "OK");
exit(-1);
}