forked from robertstarr/ulp_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanelize.ulp
141 lines (126 loc) · 4.09 KB
/
panelize.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
#usage "<b>Generate name layers to panelize board</b>\n"
"<p>"
"Generates a command sequence which copies the name texts (support spin-flag) "
"of all elements of your layout into newly generated layers (125 and 126). "
"After running the ULP you can GROUP, CUT and PASTE your layout "
"to get an array of several boards. Make sure all layers are displayed before."
"<p>"
"The duplicated name texts in the new layers will not be changed. "
"Please notice that you have to deactivate layers 25 and 26 if you use "
"the CAM processor e.g. for generating gerber data. Instead, you have to activate "
"the new layers 125 and 126. Thus you get an identical silk screen for all "
"your layouts in this array."
"<p>"
"<b>Texts must be SMASHed before we can duplicate them!</b> "
"<p>"
"<author>Author: [email protected]</author>"
// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED
#require 4.1106;
// 6.12.2004 Text with Spin-Flag [email protected]
// 28.06.2006 accept Sigle-Quote on end of name of element [email protected]
int offset = 100;
string tcolor = "yellow";
string bcolor = "magenta";
int used_name_layers[];
string used_name_[];
string cmd_header;
string cmd = "\nSET UNDO_LOG OFF;\nGRID MIL;\n"; // advisable for speed reasons
string h;
string check_single_quote(string s) { // 2006.06.28
int l = strlen(s);
if (s[l-1] == '\'') s+="'";
return s;
}
void test(void) {
string txt = "Used Layers for >NAME\n";
for (int n = 0; n < 256; n++) {
if(used_name_layers[n]) {
sprintf(h, "Layer %3d count %d\t%s\n", n, used_name_layers[n], used_name_[n]);
txt += h;
}
}
if (dlgMessageBox(txt, "OK", "Cancel") != 0) exit(-1);
return;
}
void header(void) {
for (int n = 0; n < 256; n++) {
if(used_name_layers[n]) {
sprintf(h, "layer %d _%s;\n", n + offset, used_name_[n]);
cmd_header += h;
if (n & 1) sprintf(h, "set color_layer %d %s;\n", n + offset, tcolor);
else sprintf(h, "set color_layer %d %s;\n", n + offset, bcolor);
cmd_header += h;
}
}
}
void Text(string Ename, int Tlayer, int Tx, int Ty, int Tsize, real Tangle, int Tratio, int Tmirror, int Tspin) {
sprintf(h, "Change Layer %d;\n", Tlayer + offset);
cmd += h;
sprintf(h, "Change Size %5.3f;\n", u2mil(Tsize));
cmd += h;
sprintf(h, "Change Ratio %d;\n", Tratio);
cmd += h;
string mirr, spin;
if (Tmirror) mirr = "M";
else mirr = "";
if (Tspin) spin = "S";
else spin = "";
sprintf(h, "Text '%s' %s%sR%.1f (%5.3f %5.3f);\n", check_single_quote(Ename), spin, mirr, Tangle, u2mil(Tx), u2mil(Ty));
cmd += h;
return;
}
if (board) {
UL_TEXT txt;
board(B) {
B.layers(L) {
used_name_[L.number] = L.name;
}
header();
B.elements(E) { // smashed texts
E.texts(T) {
if (T.value == E.name) {
used_name_layers[T.layer]++;
Text(E.name, T.layer, T.x, T.y, T.size, T.angle, T.ratio, T.mirror, T.spin);
}
}
E.package.texts(T) { // unsmashed texts
if (T.value == E.name) {
used_name_layers[T.layer]++;
Text(E.name, T.layer, T.x, T.y, T.size, T.angle, T.ratio, T.mirror, T.spin);
}
}
E.attributes(A) {
if (A.display == ATTRIBUTE_DISPLAY_FLAG_VALUE) {
if (A.name == "LABEL") {
txt = A.text;
used_name_layers[txt.layer]++;
Text(A.value, txt.layer, txt.x, txt.y, txt.size, txt.angle, txt.ratio, txt.mirror, txt.spin);
}
}
}
}
}
// test();
cmd += "SET UNDO_LOG ON;\nGRID LAST;\n";
header();
cmd_header += cmd;
cmd = cmd_header;
// EditBox
int Result = dlgDialog("Descriptions") {
dlgHBoxLayout {
dlgVBoxLayout { dlgSpacing(500); }
dlgTextEdit(cmd);
}
dlgHBoxLayout {
dlgPushButton("+Execute") dlgAccept();
dlgSpacing(100);
dlgPushButton("-Cancel") dlgReject();
}
};
if (Result == 0) exit(0);
exit(cmd);
}
else {
dlgMessageBox("\n Start this ULP in a Board \n");
exit (0);
}