-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathnormalize-text.ulp
More file actions
221 lines (189 loc) · 7.46 KB
/
normalize-text.ulp
File metadata and controls
221 lines (189 loc) · 7.46 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
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
/****************************************************************************************
* *
* Normalize silkscreen text sizes *
* *
* Filename: normalize-text.ulp *
* Version: 1.0 *
* Author: Tennessee Carmel-Veilleux <veilleux@ameth.org> *
* Date: March 31st 2005 *
* Company: Entreprises Ten Tech *
* * *
* This ULP program smashes all texts on the silkscreen layers. It then normalizes the *
* texts so that they all have the same size and thickness. Ratio is calculated from *
* the desired thickness. *
* *
****************************************************************************************/
#usage "<b>Normalize silkscreen text sizes v1.0</b><HR>\n"
"<p>This ULP program smashes all texts on the silkscreen layers. It then normalizes the "
"texts so that they all have the same size and thickness. Ratio is calculated from "
"the desired thickness.</p>"
"<author>Author: Tennessee Carmel-Veilleux (veilleux@ameth.org)</author>"
#require 4.13
string VERSION = "1.0";
int result = 0; // Dialog result
string str; // Temporary string
string cmd = "SET UNDO_LOG OFF;\n"; // Script command to execute
real text_size = 40.0; // Text size for all texts
real text_thickness = 8.0; // Text thickness for all texts
int text_ratio; // Calculated text ratio
int NUM_LAYERS = 8;
int silk_screen_layers[] = {LAYER_TPLACE, LAYER_BPLACE, LAYER_TNAMES,
LAYER_BNAMES, LAYER_TVALUES, LAYER_BVALUES,
LAYER_TDOCU, LAYER_BDOCU};
enum {UNIT_MIL, UNIT_MM};
int units = UNIT_MIL;
/* ------------- UTILITY FUNCTIONS --------------- */
//
// Redisplays the layers that were visible when the ULP was started
//
void ResetVisible(UL_BOARD B) {
sprintf(str, "DISP NONE;\nDISP ");
cmd += str;
B.layers(L) {
if (L.visible) {
sprintf(str, "%d ", L.number);
cmd += str;
}
}
cmd += ";\n";
}
//
// Returns 1 if a layer is a silkscreen layer
//
int SilkScreenText(int layer) {
int i;
int found = 0;
for (i = 0; i < NUM_LAYERS; i++) {
if (layer == silk_screen_layers[i]) found = 1;
}
return found;
}
//
// Resizes a text element to the specified size and ratio
//
void ResizeText(UL_TEXT T, real size, int ratio) {
if (SilkScreenText(T.layer)) {
switch (units) {
case UNIT_MIL:
sprintf(str,"CHANGE SIZE %.3f (%.3f %.3f);\nCHANGE RATIO %d (%.3f %.3f);\n",
size, u2mil(T.x), u2mil(T.y), ratio, u2mil(T.x), u2mil(T.y));
break;
case UNIT_MM:
sprintf(str,"CHANGE SIZE %.3f (%.3f %.3f);\nCHANGE RATIO %d (%.3f %.3f);\n",
size, u2mm(T.x), u2mm(T.y), ratio, u2mm(T.x), u2mm(T.y));
break;
}
cmd += str;
}
}
//
// Smashes all parts that have an associated package on the board and resize
// all text to SIZE and RATIO.
//
void ProcessTexts(real size, int ratio) {
// Display the origins of components
switch (units) {
case UNIT_MIL:
sprintf(str,"GRID MIL 1;\n");
break;
case UNIT_MM:
sprintf(str,"GRID MM 0.1;\n");
break;
}
cmd += str;
cmd += "DISPLAY NONE tPlace bPlace;\n";
board(B) {
B.elements(E) {
if (E.package) {
// Smash the package to make sure text is CHANGE-able
switch (units) {
case UNIT_MIL:
sprintf(str,"SMASH (%.3f %.3f);\n", u2mil(E.x), u2mil(E.y));
break;
case UNIT_MM:
sprintf(str,"SMASH (%.3f %.3f);\n", u2mm(E.x), u2mm(E.y));
break;
}
cmd += str;
// Change smashed texts
E.texts(T) {
ResizeText(T, size, ratio);
}
// Change unsmashed texts
E.package.texts(T) {
ResizeText(T, size, ratio);
}
}
}
// Change all manually-added texts
B.texts(T) {
ResizeText(T, size, ratio);
}
ResetVisible(B);
}
cmd += "GRID LAST;\nSET UNDO_LOG ON;\n";
}
/* ------------- MAIN ROUTINE --------------- */
if (board) {
result = dlgDialog("Normalize silkscreen text sizes") {
sprintf(str,"<qt><H3><P>Normalize silkscreen text sizes %s</P></H3>"+
"<P><B>By Tennessee Carmel-Veilleux (veilleux@ameth.org)</B></P>"+
"<HR><P>This ULP normalizes all the text on the silkscreen layers to "+
"the specified size and thickness. The ratio is automatically calculated " +
"from the size and thickness.</P></qt>", VERSION);
dlgLabel(str);
// Options
dlgHBoxLayout {
dlgGroup("Output units") {
dlgRadioButton("m&il",units) {text_size = 40.0; text_thickness = 0.008; dlgRedisplay(); }
dlgRadioButton("&mm",units) {text_size = 1.0; text_thickness = 0.2; dlgRedisplay(); }
}
dlgSpacing(20);
dlgGridLayout {
dlgCell(0,0) dlgLabel("Text size:");
dlgCell(0,1) dlgRealEdit(text_size,0.5,2000.0);
dlgCell(1,0) dlgLabel("Text Thickness:");
dlgCell(1,1) dlgRealEdit(text_thickness,0.05,500.0);
}
}
// Buttons
dlgHBoxLayout {
dlgStretch(1);
dlgPushButton("+Normalize") dlgAccept();
dlgPushButton("-Cancel") dlgReject();
}
};
if (!result) exit(0);
text_ratio = int(round((text_thickness / text_size) * 100.0)) + 1;
if (text_ratio > 31) {
text_ratio = 31;
dlgMessageBox("!<qt><P><B>Ratio clipped to 31 !</B></P>"+
"<P>Make sure that text thickness is not too large for proper ratio.</P></qt>");
}
if (units == UNIT_MM) {
if (text_size > 5.0) {
text_size = 5.0;
dlgMessageBox("!<qt><P><B>Text size clipped to 5.0mm !</B></P></qt>");
}
}
ProcessTexts(text_size, text_ratio);
// EditBox
result = dlgDialog("Edit and execute script") {
dlgHBoxLayout {
dlgSpacing(500); // Force width of dialog to 500
}
dlgTextEdit(cmd);
dlgHBoxLayout {
dlgPushButton("+Execute") dlgAccept();
dlgPushButton("-Cancel") dlgReject();
}
};
// Execute script if it was accepted
if (!result)
exit(0);
else
exit(cmd);
} else {
dlgMessageBox(":You must run this ULP in board !");
exit(1);
}