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
|
#require 4.1105
#usage "en: <b>Export outlines data</b>\n"
"<p>"
"Generates outlines data for a board layout."
"<p>"
"Usage: RUN outlines [ <i>device</i> [ <i>width</i> [ <i>layer</i> [ <i>filename</i> ]]]]"
"<p>"
"<table>"
"<tr><td>device:</td><td>Script | HPGL</td><tr>"
"<tr><td>width:</td><td>outlines width [mm]</td><tr>"
"<tr><td>layer:</td><td>1..16 (0 = active layer)</td><tr>"
"<tr><td>filename:</td><td>output file name</td><tr>"
"</table>"
"<p>"
"<author>Author: support@cadsoft.de</author>",
"de: <b>Konturdaten exportieren</b>\n"
"<p>"
"Erzeugt Konturdaten fr ein Platinenlayout."
"<p>"
"Aufruf: RUN outlines [ <i>device</i> [ <i>width</i> [ <i>layer</i> [ <i>filename</i> ]]]]"
"<p>"
"<table>"
"<tr><td>device:</td><td>Script | HPGL</td><tr>"
"<tr><td>width:</td><td>Breite der Konturlinien [mm]</td><tr>"
"<tr><td>layer:</td><td>1..16 (0 = aktiver Layer)</td><tr>"
"<tr><td>filename:</td><td>Ausgabedatei</td><tr>"
"</table>"
"<p>"
"<author>Autor: support@cadsoft.de</author>"
// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED
/*
Complete the following steps to add a new output device definition:
1. Add a new member to the 'enum { devScript = 1, ...'
2. Add the new (unique!) device name to 'DeviceNames[]'
3. Add the necessary 'case dev...' branches to 'DeviceInit()', 'DeviceDraw()' and 'DeviceEnd()'
*/
string I18N[] = {
"en\v"
"de\v"
,
"ERROR: \v"
"FEHLER: \v"
,
"No board!\v"
"Kein Board!\v"
,
"This program can only work in the board editor.\v"
"Dieses Programm kann nur im Board-Editor angewendet werden.\v"
,
"Illegal width: \v"
"Ungltige Breite: \v"
,
"The <i>width</i> must be greater than zero.\v"
"Die <i>Breite</i> mu grer als 0 sein.\v"
,
"Illegal layer: \v"
"Ungltiger Layer: \v"
,
"The <i>layer</i> must be one of 1..16 or 0 to use the current layer.\v"
"Der <i>Layer</i> mu im Bereich 1..16 liegen, oder 0 sein um den aktuellen Layer zu whlen.\v"
,
"Select a device\v"
"Whlen Sie ein Ausgabegert\v"
,
"There is already a signal named \v"
"Es existiert bereits ein Signal namens \v"
,
" in this board!\v"
" in diesem Board!\v"
,
"Please make sure that there is no such signal in this board.\v"
"Bitte sorgen Sie dafr, da es kein solches Signal in diesem Board gibt.\v"
,
"Illegal device: \v"
"Ungltiges Ausgabegert: \v"
,
"Please select one of the known devices.\v"
"Bitte whlen Sie eines der bekannten Ausgabegerte aus.\v"
,
"No signal layer active!\v"
"Kein Signal-Layer aktiv!\v"
,
"Please activate the signal layer to generate outlines for.\v"
"Bitte aktivieren den Signal-Layer fr den Konturdaten generiert werden sollen.\v"
,
"Invalid layer: \v"
"Ungltiger Layer: \v"
,
"The <i>layer</i> was not found or is not active.\v"
"Der <i>Layer</i> konnte nicht gefunden werden oder ist nicht aktiv.\v"
,
"Outlines Generator\v"
"Konturdaten-Generator\v"
,
"&Width\v"
"&Breite\v"
,
"&Layer\v"
"&Layer\v"
,
"&Output file\v"
"&Ausgabedatei\v"
,
"&Browse\v"
"&Durchsuchen\v"
,
"Save Outlines file\v"
"Konturdaten speichern\v"
,
"+OK\v"
"+OK\v"
,
"No device selected!\v"
"Kein Ausgabegert ausgewhlt!\v"
,
"Please select a device.\v"
"Bitte whlen Sie ein Ausgabegert.\v"
,
"Illegal width: 0\v"
"Ungltige Breite: 0\v"
,
"The <i>width</i> must be greater than zero.\v"
"Die <i>Breite</i> mu grer als Null sein.\v"
,
"-Cancel\v"
"-Abbrechen\v"
,
"About\v"
"Info\v"
};
int Language = strstr(I18N[0], language()) / 3;
string tr(string s)
{
string t = lookup(I18N, s, Language, '\v');
return t ? t : s;
}
void Fatal(string Message, string Details)
{
dlgMessageBox(usage + "<hr><b>" + tr("ERROR: ") + Message + "</b><p>\n" + Details);
exit(1);
}
void Error(string Message, string Details)
{
dlgMessageBox("<b>" + tr("ERROR: ") + Message + "</b><p>\n" + Details);
}
//
// Parmameters
//
string DefaultSuffix = ".out";
string Device;
real Width = 0;
int Layer = 0;
string FileName;
if (!board)
Fatal(tr("No board!"), tr("This program can only work in the board editor."));
if (argv[1]) {
Device = argv[1];
if (argv[2]) {
Width = strtod(argv[2]);
if (Width <= 0)
Fatal(tr("Illegal width: ") + argv[2], tr("The <i>width</i> must be greater than zero."));
if (argv[3]) {
Layer = strtol(argv[3]);
if (Layer < 0 || Layer > 16)
Fatal(tr("Illegal layer: ") + argv[3], tr("The <i>layer</i> must be one of 1..16 or 0 to use the current layer."));
if (argv[4]) {
FileName = argv[4];
}
}
}
}
if (!FileName)
board(B) FileName = filesetext(B.name, DefaultSuffix);
//
// The various output devices
//
enum { devScript = 1, devHPGL };
string DeviceNames[] = { tr("Select a device"), "Script", "HPGL" };
int SelectedDevice;
void DeviceInit(void)
{
// Do anything necessary to initialize the output device
switch (SelectedDevice) {
case devScript:
// TODO make the layer user definable?
printf("layer %d;\nset wire_bend 2; grid mm; change width %f;\n", Layer + 100, Width);
break;
case devHPGL:
break;
}
}
void DeviceDraw(int x1, int y1, int x2, int y2, int state)
{
// Actually draw a line on the output device.
// 'state' is defined as
// 0 = this is the first line of a partial polygon
// 1 = this is a "normal" line (neither the first nor the last one)
// 2 = this is the last line of a partial polygon
switch (SelectedDevice) {
case devScript:
if (state == 0)
printf("wire (%f %f) (%f %f)", u2mm(x1), u2mm(y1), u2mm(x2), u2mm(y2));
else {
printf(" (%f %f)", u2mm(x2), u2mm(y2));
if (state == 2)
printf(";\n");
}
break;
case devHPGL:
if (state == 0)
printf("PU; PA %f %f; PD; PA %f %f;", u2mm(x1), u2mm(y1), u2mm(x2), u2mm(y2));
else {
printf(" PA %f %f", u2mm(x2), u2mm(y2));
if (state == 2)
printf("\n");
}
break;
}
}
void DeviceEnd(void)
{
// Do anything necessary to end output to the device
switch (SelectedDevice) {
case devScript:
break;
case devHPGL:
printf("PU;\n");
break;
}
}
//
// The actual outlines generator
//
string OutlinesSignalName = "_OUTLINES_";
string Pass2 = "PASS_2";
int InPass2 = argv[5] == Pass2;
void GenerateOutlines(void)
{
board(B) {
real f = 20, // mm frame
x1 = u2mm(B.area.x1) - f, y1 = u2mm(B.area.y1) - f,
x2 = u2mm(B.area.x2) + f, y2 = u2mm(B.area.y2) + f;
B.signals(S) {
if (S.name == OutlinesSignalName)
Fatal(tr("There is already a signal named ") + OutlinesSignalName + tr(" in this board!"), tr("Please make sure that there is no such signal in this board."));
}
string Cmd;
sprintf(Cmd, "grid mm;\n"
"window fit;\n"
"change isolate 0;\n"
"change rank 6;\n"
"change pour solid;\n"
"change orphans on;\n"
"layer %d;\n"
"polygon %s %f (%f %f) (%f %f) (%f %f) (%f %f) (%f %f);\n"
"ratsnest;\n"
"run '%s' '%s' '%f' '%d' '%s' '%s';",
Layer,
OutlinesSignalName, Width, x1, y1, x2, y1, x2, y2, x1, y2, x1, y1,
argv[0], Device, Width, Layer, FileName, Pass2);
exit(Cmd);
}
}
void WriteOutlines(void)
{
board(B) {
output(FileName) {
string Cmd;
B.signals(S) {
if (S.name == OutlinesSignalName) {
S.polygons(P) {
int x1 = INT_MAX, y1 = INT_MAX, x2 = INT_MIN, y2 = INT_MIN;
int x0, y0, first = 1;
int FrameWire;
int State;
P.wires(W) {
x1 = min(x1, W.x1);
x2 = max(x2, W.x1);
y1 = min(y1, W.y1);
y2 = max(y2, W.y1);
}
DeviceInit();
P.contours(W) {
if (first) {
// a new partial polygon is starting
x0 = W.x1;
y0 = W.y1;
FrameWire = (x1 == x0 || x2 == x0) && (y1 == y0 || y2 == y0);
State = 0;
first = 0;
}
else if (W.x2 == x0 && W.y2 == y0) {
// this was the last wire of the partial polygon,
// so the next wire (if any) will be the first wire
// of the next partial polygon
State = 2;
first = 1;
}
else
State = 1;
if (!FrameWire)
DeviceDraw(W.x1, W.y1, W.x2, W.y2, State);
}
DeviceEnd();
sprintf(Cmd, "delete (%f %f) (%f %f); window fit;\n", u2mm(x1), u2mm(y1), u2mm(x2), u2mm(y2));
}
break;
}
}
exit(Cmd);
}
}
}
//
// Main program:
//
if (Device) {
int n;
while (DeviceNames[n]) {
if (strupr(DeviceNames[n]) == strupr(Device)) {
SelectedDevice = n;
break;
}
n++;
}
if (!SelectedDevice)
Fatal(tr("Illegal device: ") + Device, tr("Please select one of the known devices."));
}
if (!InPass2) {
string Layers[];
int SelectedLayer = -1;
int ForceDialog = (!Device || !Width);
board(B) {
int n;
B.layers(L) {
if (L.number <= 16 && L.visible) {
if (Layer == L.number)
SelectedLayer = n;
sprintf(Layers[n++], "%d %s", L.number, L.name);
}
}
if (n == 0)
Fatal(tr("No signal layer active!"), tr("Please activate the signal layer to generate outlines for."));
if (!Layer) {
if (n > 1)
ForceDialog = 1;
SelectedLayer = 0;
}
if (SelectedLayer < 0) {
string s;
sprintf(s, "%d", Layer);
Fatal(tr("Invalid layer: ") + s, tr("The <i>layer</i> was not found or is not active."));
}
}
if (ForceDialog) {
dlgDialog(tr("Outlines Generator")) {
dlgGridLayout {
dlgCell(0, 0) dlgLabel("&Device");
dlgCell(0, 1) dlgComboBox(DeviceNames, SelectedDevice) {
// TODO should we generalize this?
if (FileName && SelectedDevice == devScript)
FileName = filesetext(FileName, ".scr");
}
dlgCell(1, 0) dlgLabel(tr("&Width"));
dlgCell(1, 1) dlgRealEdit(Width, 0, 10);
dlgCell(2, 0) dlgLabel(tr("&Layer"));
dlgCell(2, 1) dlgComboBox(Layers, SelectedLayer);
}
dlgHBoxLayout {
dlgLabel(tr("&Output file"));
dlgStringEdit(FileName);
dlgPushButton(tr("&Browse")) {
string fn = dlgFileSave(tr("Save Outlines file"), FileName);
if (fn)
FileName = fn;
}
}
dlgStretch(1);
dlgHBoxLayout {
dlgStretch(1);
dlgPushButton(tr("+OK")) {
if (!SelectedDevice)
Error(tr("No device selected!"), tr("Please select a device."));
else if (!Width)
Error(tr("Illegal width: 0"), tr("The <i>width</i> must be greater than zero."));
else
dlgAccept();
}
dlgPushButton(tr("-Cancel")) { dlgReject(); exit(1); }
dlgPushButton(tr("About")) dlgMessageBox(usage);
}
};
}
Device = DeviceNames[SelectedDevice];
Layer = strtol(Layers[SelectedLayer]);
GenerateOutlines();
}
else
WriteOutlines();
|