#usage "Convert a CAM job to a script to export IMAGE data" "
"
" "
"Tip: Assign a funktion key with"
" "
"
"
"ASSIGN Shift+Ctrl+Alt+I 'run cam2image;';"
"
"
"or ASSIGN Shift+Ctrl+Alt+I 'run cam2image myjob.cam monochrome 150 .bmp;';"
"
"
"or ASSIGN Shift+Ctrl+Alt+I 'run cam2image myjob.cam color 300 .tif;';"
"
\n" +
"If the layer list is empty after starting this ULP,
" +
"you did not start it from the proper editor window (SCH/BRD).
" +
"CAM jobs for the layout have to be started from the Layout Editor, " +
"jobs for a schematic from the Schematic Editor. " +
"CAM Jobs can be edited and saved by the CAM processor only.";
// *** functions ***
void editsec(int sec) {
string num;
sprintf(num, "%d", sec);
dlgDialog("Section Editor") {
dlgLabel("Section " + num);
dlgHBoxLayout {
dlgPushButton("+OK") dlgAccept();
dlgPushButton("-Cancel") dlgReject();
dlgStretch(1);
}
};
return;
}
void commandPrint(string sectab) {
string h;
string Path = filedir(sectab);
string File_Name = filesetext(filename(sectab), "");
string Extension = fileext(sectab);
string expfilename;
if (Path) { // check filename in CAM-Job *** 23.02.2005 alf@cadsoft.de
if (!File_Name) {
expfilename = Path + filesetext(filename(file_name), "") + Extension;
}
else {
expfilename = Path + File_Name + Extension;
}
}
else {
expfilename = file_name + Extension;
}
sprintf(h, "EXPORT IMAGE '%s%s' %s %d;\n", expfilename, filetype[selfiletype], monochrome, Resolution);
cmd += h;
return;
}
void viewDescript(void) {
string ds;
for (int n = 1 ; n < descrCnt; n++ ) {
if (ds[0] = ' ') {
ds = descriptionLine[n];
ds[0] = ' ';
descriptionLine[n] = ds;
}
}
descriptionLine[0] = "
");
dlgLabel("no Layers selected\nin this CAM-Job/Section!\nLoad a correct Job.");
}
}
dlgSpacing(10);
}
dlgStretch(1);
}
dlgStretch(1);
tpn++;
}
} // ************ End of TAB | SHEET ***********
dlgTabPage("&Help") {
dlgSpacing(10);
dlgHBoxLayout {
dlgSpacing(10);
dlgVBoxLayout {
dlgHBoxLayout {
dlgLabel(Eagle);
dlgSpacing(10);
dlgVBoxLayout {
dlgLabel(EAGLE_SIGNATURE);
dlgSpacing(10);
if (description) {
dlgHBoxLayout {
dlgPushButton("&Show Job Description") viewDescript();
dlgStretch(1);
}
}
else dlgLabel("CAM Job description is EMPTY");
}
dlgStretch(1);
}
dlgSpacing(10);
dlgLabel(help);
dlgStretch(1);
}
}
}
} // ************ End of all TABs ***********
dlgHBoxLayout {
dlgLabel("FileType");
dlgComboBox(filetype, selfiletype);
dlgSpacing(15);
dlgCheckBox("Monochrome", sel_monochrome);
dlgSpacing(15);
dlgLabel("Resolution DPI");
dlgIntEdit(Resolution, 50, 600);
dlgStretch(1);
}
dlgHBoxLayout {
dlgStretch(0);
dlgPushButton("+OK") dlgAccept();
dlgStretch(0);
dlgPushButton("-Cancel") dlgReject();
dlgStretch(1);
dlgPushButton("&Load CAM-File") {
CAMfileName = dlgFileOpen("select a File", path_cam[0]+"/*.cam", "");
if (CAMfileName) {
exit ("run '" + filesetext(argv[0], "") + "' '" + CAMfileName + "';\n");
}
}
dlgStretch(1);
}
};
if (Result == 0) exit (0);
if (sel_monochrome) monochrome = "MONOCHROME";
else monochrome = "";
if (test) cmd = "# generatet by " + argv[0] + " from " + CAMfileName + "\n";
for (int tpn = 1; tpn <= sx; tpn++) {
string layer[] ;
int n = 0;
int ln = strsplit(layer, sec_Layers[tpn], ' ');
if (test) cmd += "# Section: " + sec_Name[tpn] + "\n";
if(board) {
cmd += "SET DISPLAY_MODE REAL;\n";
cmd += "RATSNEST;\n";
cmd += "DISPLAY NONE ";
for (int x = 0; x < ln; x++) {
int num = strtod(layer[x]);
if (num < 90 || num > 100) {
if (useLayer[num]) {
sprintf(s, " %3s", layer[x]);
cmd += s;
if(num == 21) cmd += " -23 -25 -27 -51";
if(num == 22) cmd += " -24 -26 -28 -52";
n++;
}
}
}
cmd += ";\n";
commandPrint(sec_Out_put[tpn]);
}
if(schematic) {
cmd += "DISPLAY NONE ";
for (int x = 0; x < ln; x++) {
int num = strtod(layer[x]);
if (useLayer[num]) {
if (num >= 90) {
sprintf(s, " %3s", layer[x]);
cmd += s;
n++;
}
}
}
cmd += ";\n";
string sh;
string shn;
switch (sheetprint) {
case 0 : schematic(S) {
S.sheets(SH) {
sprintf(sh, "EDIT '.s%d';\n", SH.number);
cmd += sh;
sprintf(shn, "_s%d", SH.number);
commandPrint(shn);
}
}
break;
case 1 : for (int prn = sheetprint_from[tpn]; prn <= sheetprint_to[tpn]; prn++) {
sprintf(sh, "EDIT '.s%d';\n", prn);
cmd += sh;
sprintf(shn, "_s%d", prn);
commandPrint(shn);
}
break;
case 2 : sprintf(sh, "EDIT '.s%d';\n", sec_Sheet[tpn]);
cmd += sh;
sprintf(shn, "_s%d", sec_Sheet[tpn]);
commandPrint(shn);
break;
case 3 : sprintf(sh, "EDIT '.s%s';\n", actualsheet);
cmd += sh;
sprintf(shn, ".s%s", actualsheet);
commandPrint(shn);
break;
}
}
}
cmd += "DISPLAY ";
if(board) {
for(int l = 1; l < 90; l++) {
if (useLayer[l]) {
if (lVisible[l]) {
sprintf(s, " %d", l);
cmd += s;
}
else {
sprintf(s, " -%d", l);
cmd += s;
}
}
}
for(l = 100; l < 256; l++) {
if (useLayer[l]) {
if (lVisible[l]) {
sprintf(s, " %d", l);
cmd += s;
}
else {
sprintf(s, " -%d", l);
cmd += s;
}
}
}
cmd += ";\n";
}
if(schematic) {
for(int l = 91; l < 256; l++) {
if (useLayer[l]) {
if (lVisible[l]) {
sprintf(s, " %d", l);
cmd += s;
}
else {
sprintf(s, " -%d", l);
cmd += s;
}
}
}
cmd += ";\n";
sprintf(s, "EDIT '.s%s';\n", actualsheet);
cmd += s;
}
if (test) { dlgMessageBox(cmd, "OK", "Cancel"); exit (0);}
exit (cmd);