// **** Usage is HTML formatted text #usage "Eagle to PostScript Schematic Export Tool " "

" "USAGE: Load any schematic and execute the ULP in the eagle." "

" "SUMMARY: This ULP can convert an Eagle CAD schematic into a Postscript file " "which can then be searched for text or converted into a text-searchable PDF." "

" "AUTHORS:
" " v1.1 - juergen.messerer (at) freesurf.ch
" " v2.x - dane.ulp (at) lewisinnovative.com
" "
" "

" "(See ULP Header for Changelog)" // **** VERSION and ABOUT are C formatted strings string VERSION = "Export Schematic to Postscript, v2.1"; string ABOUT = "This ULP converts an Eagle CAD schematic into a Postscript file " "which can then be searched for text or converted to text-searchable PDF.\n" + "\n" + "Limitations:\n" + "Currently only tested for Letter and 11x17 paper formats. " + "Both Portrait and Landscape orientations are supported.\n" + "\n" + "Version History (see ULP Header for changelog):\n" + " v1.1 - juergen.messerer (at) freesurf.ch\n" + " v2.x - dane.ulp (at) lewisinnovative.com\n"; /* ========================================================================== * License: This file is released under the license of the * GNU Public license Version 2. * * * Change Log: * * Apr 2008: v2.1 (dane) * - Fixed a few errors in ULP settings dialog widget * * Apr 2008: v2.0 - Adapted heavily by dane: * - added crude font size scaling (works for Ghostscript v8.61) * (font scaling crude, and may not suite all platforms) * - supports paper sizes Letter and 11x17 (Portrait and Landscape) * (previous paper sizes removed since I cannot test them) * - supports paper orientations Portrait and Landscape * - added page-scaling (none, shrink-only, and fit-to-page) * - added aspect ratio preservation (during page-scaling) * - added "export only visible layers" * - now exports PS-Adobe-3.0 postscript instead of PS-Adobe-2.1 * - added "About" tab * - various other small 'tweaks' here and there * * 06.12.2006: Bug in text arrangement with a rotation of 270 degrees (line 299) * Changed the margin offset from 50 to 15 * * 29.11.2006: Release Version 1.0 * * 02.10.2006: Init version * * ==========================================================================*/ /* ========================================================================== * ==========================================================================*/ string monthArray[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; int colorLUT[]; string g_FontBoxArray[] = { "Arial", "Courier", "Gothic", "Helvetica", "Helvetica-Bold", "Sans-Serif", "Times-Roman" }; real g_FontScaler[] = { 1.3, 1.3, 1.3, 1.3, 1.3, 1.3, 1.3 }; real rFontScaleFactor = 1.3; // for some reason texts are output too small... int g_selFont = 4; string g_FontStr = g_FontBoxArray[g_selFont]; string g_comboBoxArray[] = { "Custom", "Letter (8.5\" x 11\")", "11x17 (11\" x 17\")" }; string g_sheetSizeArray[] = { "Custom", "Letter", "11x17" }; real g_sheetSizes[] = { // X Y // thousanths of an inch 1.0, 1.0, // custom 8.5, 11.0, // letter 11.0, 17.0 // 11x17 }; int g_selSheetSize = 2; // initially selects "11x17" string g_sheetOrientationArray[] = { "Portrait", "Landscape" }; int g_selRotation = 1; // initially selects landscape string g_sheetScaling[] = { "None", "Shrink Only", "Shrink or Stretch" }; int g_selScaleDrawing = 1; // defaults to shrink only string g_sheetScalingAspect[] = { "No", "Yes" }; int g_selScaleDrawingAspect = 1; // defaults to yes string g_sheetOutputVisibleOnly[] = { "All Layers", "Visible Layers Only" }; int g_selOutputVisibleOnly = 1; // defaults to yes real g_sheetWidth = 8.5; real g_sheetHeight = 11.0; real g_leftOff = 0.25; real g_rightOff = 0.25; real g_topOff = 0.25; real g_bottomOff = 0.25; real bb_llx, bb_lly, bb_urx, bb_ury; real crop_llx, crop_lly, crop_urx, crop_ury, crop_width, crop_height; string dbgStr; int true = 1; int false = 0; int minimum( int x1, int x2 ) { if( x1 < x2 ) return x1; else return x2; } int maximum( int x1, int x2 ) { if( x1 > x2 ) return x1; else return x2; } //------------------------------------------------------ // check for visibility //------------------------------------------------------ int isvisible( int layer ) { if (g_selOutputVisibleOnly) { schematic(S) S.layers(L) if (layer == L.number) return L.visible; } else return 1; } //------------------------------------------------------ // replace special chars like '(',')','\' //------------------------------------------------------ string replaceSpecialChars( string strText, char chr ) { string newText = ""; string partStr[]; int ii = 0; int n = strsplit( partStr, strText, chr ); if( n == 1 ) return strText; for( ii = 0; ii < n; ii++ ) { newText += partStr[ii]; if( ii < (n-1) ) { switch(chr) { case '(': newText += "\\("; break; case ')': newText += "\\)"; break; case '\\': newText += "\\\\"; break; } } } return newText; } //------------------------------------------------------ // checking for special chars like '(',')','\' //------------------------------------------------------ string checkSpecialChars( string strText ) { strText = replaceSpecialChars( strText, '\\' ); strText = replaceSpecialChars( strText, '(' ); strText = replaceSpecialChars( strText, ')' ); return strText; } //------------------------------------------------------ // writing general wires //------------------------------------------------------ void write_wires( UL_WIRE W ) { real r_RGB = (colorLUT[W.layer]& 0xFF0000)>>16; real g_RGB = (colorLUT[W.layer]& 0x00FF00)>>8; real b_RGB = colorLUT[W.layer]& 0x0000FF ; int lineCap = 1; if (!isvisible(W.layer)) return; switch( W.cap ) { case CAP_FLAT: lineCap = 0; break; case CAP_ROUND: lineCap = 1; break; default: lineCap = 1; break; } if( W.style == WIRE_STYLE_LONGDASH || W.style == WIRE_STYLE_SHORTDASH || W.style == WIRE_STYLE_DASHDOT ) { W.pieces(P) printf("%d %d %d %d %d %.1f %.1f %.1f drawWire\n", P.x1, P.y1, P.x2, P.y2, P.width, r_RGB/255, g_RGB/255, b_RGB/255); } else { if (W.arc) { if( W.arc.angle1 < W.arc.angle2 ) { printf("%d %d %d %d %.1f %.1f %.1f %.1f %.1f drawArc\n", W.arc.xc, W.arc.yc, W.arc.radius, W.arc.width, W.arc.angle1, W.arc.angle2, r_RGB/255, g_RGB/255, b_RGB/255); } else { printf("%d %d %d %d %.1f %.1f %.1f %.1f %.1f drawArcn\n", W.arc.xc, W.arc.yc, W.arc.radius, W.arc.width, W.arc.angle1, W.arc.angle2, r_RGB/255, g_RGB/255, b_RGB/255); } } else { printf("%d %d %d %d %d %.1f %.1f %.1f drawWire\n", W.x1, W.y1, W.x2, W.y2, W.width, r_RGB/255, g_RGB/255, b_RGB/255); // sprintf(dbgStr, "%d %d %d %d %d %.1f %.1f %.1f drawWire\n", W.x1, W.y1, // W.x2, W.y2, W.width, // r_RGB/255, g_RGB/255, b_RGB/255); // dlgMessageBox(dbgStr,"Okay"); } } } //------------------------------------------------------ // writing general rectangles //------------------------------------------------------ void write_rectangles( UL_RECTANGLE R ) { real r_RGB = (colorLUT[R.layer]& 0xFF0000)>>16; real g_RGB = (colorLUT[R.layer]& 0x00FF00)>>8; real b_RGB = colorLUT[R.layer]& 0x0000FF ; if (!isvisible(R.layer)) return; //printf( "%.1f rotate\n", R.angle); printf( "%d %d %d %d %.1f %.1f %.1f %.1f drawRect\n", R.x1, R.y1, R.x2, R.y2, R.angle, r_RGB/255, g_RGB/255, b_RGB/255); } //------------------------------------------------------ // writing general texts //------------------------------------------------------ void write_texts( UL_TEXT T ) { real r_RGB = (colorLUT[T.layer]& 0xFF0000)>>16; real g_RGB = (colorLUT[T.layer]& 0x00FF00)>>8; real b_RGB = colorLUT[T.layer]& 0x0000FF ; string newText = checkSpecialChars(T.value); int posX = T.x; int posY = T.y; int minX = 0; int maxX = 0; int minY = 0; int maxY = 0; int count = 0; string bla; int textAngle = T.angle; if (!isvisible(T.layer)) return; //Get MinX MaxX MinY MaxY T.wires(W) { int tmpMinX = minX; int tmpMaxX = maxX; int tmpMinY = minY; int tmpMaxY = maxY; tmpMinX = minimum( W.x1, W.x2); tmpMinY = minimum( W.y1, W.y2); tmpMaxX = maximum( W.x1, W.x2); tmpMaxY = maximum( W.y1, W.y2); if(count <= 0) { minX = tmpMinX; minY = tmpMinY; maxX = tmpMaxX; maxY = tmpMaxY; } else { minX = minimum( tmpMinX, minX); minY = minimum( tmpMinY, minY); maxX = maximum( tmpMaxX, maxX); maxY = maximum( tmpMaxY, maxY); } count++; } if( T.mirror > 0 ) { switch( textAngle ) { case 0: posX = minX; break; case 90: posX += T.size; break; case 180: textAngle = 0; posY = minY; break; case 270: textAngle = 90; posY = minY; break; } } else { switch( textAngle ) { case 90: posX = maxX; break; case 180: textAngle = 0; posX = minX; posY = minY; break; case 270: textAngle = 90; posY = minY; posX = maxX; break; } } //sprintf(bla, "Val: %s MinX: %d MinY: %d MaxX: %d MaxY: %d", T.value, minX, minY, maxX, maxY ); //dlgMessageBox(bla,"Okay"); // real rNewSize = T.size * rFontScaleFactor; // too small without this for some reason ... printf( "%d %d %d %d %.1f %.1f %.1f (%s) drawText\n", posX, posY, T.size, textAngle, r_RGB/255, g_RGB/255, b_RGB/255, newText ); } //------------------------------------------------------ // writing general circles //------------------------------------------------------ void write_circles( UL_CIRCLE C ) { real r_RGB = (colorLUT[C.layer]& 0xFF0000)>>16; real g_RGB = (colorLUT[C.layer]& 0x00FF00)>>8; real b_RGB = colorLUT[C.layer]& 0x0000FF ; if (!isvisible(C.layer)) return; printf("%d %d %d %d %.1f %.1f %.1f drawCircle\n", C.x, C.y, C.radius, C.width, r_RGB/255, g_RGB/255, b_RGB/255); } //------------------------------------------------------ // writing elements of the busses for a sheet //------------------------------------------------------ void write_segments( UL_SEGMENT SEG ) { real r_RGB = 0.0; real g_RGB = 0.0; real b_RGB = 0.0; SEG.wires(W) { r_RGB = (colorLUT[W.layer]& 0xFF0000)>>16; g_RGB = (colorLUT[W.layer]& 0x00FF00)>>8; b_RGB = colorLUT[W.layer]& 0x0000FF ; write_wires(W); } SEG.junctions(J) { printf("%d %d %d %.1f %.1f %.1f drawFilledCircle\n", J.x, J.y, J.diameter, r_RGB/255, g_RGB/255, b_RGB/255); } SEG.texts(T) { write_texts(T); } } //------------------------------------------------------ // write general polygons //------------------------------------------------------ void write_polygons( UL_POLYGON P ) { int count = 0; real r_RGB = 0.0; real g_RGB = 0.0; real b_RGB = 0.0; r_RGB = (colorLUT[P.layer]& 0xFF0000)>>16; g_RGB = (colorLUT[P.layer]& 0x00FF00)>>8; b_RGB = colorLUT[P.layer]& 0x0000FF ; printf( "\n %c Start drawing a polygon\n", '%' ); printf( "newpath\n" ); P.wires(W) { if( count == 0) { printf( "%d EU %d EU moveto\n", W.x1, W.y1); printf( "%d EU %d EU lineto\n", W.x2, W.y2); } else { printf( "%d EU %d EU lineto\n", W.x1, W.y1); printf( "%d EU %d EU lineto\n", W.x2, W.y2); } ++count; } printf( "closepath\n" ); printf( "gsave\n" ); printf( " %f %f %f setrgbcolor\n", r_RGB/255, g_RGB/255, b_RGB/255 ); printf( "fill\n" ); printf( "grestore\n" ); printf( " %c Stop drawing a polygon\n\n", '%' ); } //------------------------------------------------------ // writing elements of the busses for a sheet //------------------------------------------------------ void write_sheet_busses( UL_SHEET SH ) { SH.busses(B) { B.segments(SEG) { write_segments(SEG); } } } //------------------------------------------------------ // writing elements of the nets for a sheet //------------------------------------------------------ void write_sheet_nets( UL_SHEET SH ) { SH.nets(N) { N.segments(SEG) { write_segments(SEG); } } } //------------------------------------------------------ // writing elements of the polygons for a sheet //------------------------------------------------------ void write_sheet_polygons( UL_SHEET SH ) { SH.polygons(P) { write_polygons(P); } } //------------------------------------------------------ // writing elements of the rectangles for a sheet //------------------------------------------------------ void write_sheet_rectangles( UL_SHEET SH ) { SH.rectangles(R) { write_rectangles(R); } } //------------------------------------------------------ // writing elements of the circles for a sheet //------------------------------------------------------ void write_sheet_circles( UL_SHEET SH ) { SH.circles(C) { write_circles(C); } } //------------------------------------------------------ //write the text items of a sheet //------------------------------------------------------ void write_sheet_texts( UL_SHEET SH ) { SH.texts(T) { write_texts(T); } } //------------------------------------------------------ //write the parts of a sheet //------------------------------------------------------ void write_sheet_parts( UL_SHEET SH ) { SH.parts(P) { P.instances(I) { I.gate.symbol.polygons(P) { write_polygons(P); } I.gate.symbol.circles(C) { write_circles(C); } I.gate.symbol.rectangles(R) { write_rectangles(R); } I.gate.symbol.pins(P) { P.wires(W) { write_wires(W); } P.circles(C) { write_circles(C); } P.texts(T) { T.wires(W) { write_wires(W); } } } I.gate.symbol.wires(W) { write_wires(W); } I.gate.symbol.texts(T) { if(T.layer == LAYER_NAMES || T.layer == LAYER_VALUES) { write_texts(T); } else { T.wires(W) { write_wires(W); } } } I.texts(T) { write_texts(T); } } } } //------------------------------------------------------ //write the text items of a sheet //------------------------------------------------------ void write_sheet_wires( UL_SHEET SH ) { SH.wires(W) { write_wires(W); } } //------------------------------------------------------ //write postscripts inline functions //------------------------------------------------------ void write_ps_functions( ) { string functions = "%c Coordinate transfer: \n\n"; functions += "%c NOTE the smallest grid size is 0.1um; 1in = 254,000 grid points\n"; functions += "/EU { 254 div 0.072 mul } def\n"; functions += "/inch { 72 mul } def\n\n"; functions += "%c page size information (setup clipping region [pre-rotation]):\n"; functions += "/LeftMargin %0.4f inch def\n"; functions += "/BotMargin %0.4f inch def\n"; functions += "/PageWidth %0.4f inch def\n"; functions += "/PageHeight %0.4f inch def\n"; // functions += "/LeftMargin exch def\n"; // functions += "/BotMargin exch def\n"; // functions += "/PageWidth exch def\n"; // functions += "/PageHeight exch def\n"; // functions += "/MinDrawX 0 EU def\n"; // functions += "/MinDrawY 0 EU def\n"; // functions += "/MaxDrawX 2725119 EU def\n"; // functions += "/MaxDrawY 3983839 EU def\n"; functions += "\n/SetupDrawingRegion\n"; functions += "{\n"; functions += " newpath\n"; functions += " LeftMargin BotMargin moveto\n"; functions += " 0 PageHeight rlineto\n"; functions += " PageWidth 0 rlineto\n"; functions += " 0 PageHeight neg rlineto\n"; functions += " closepath clip\n\n"; functions += " LeftMargin BotMargin translate\n\n"; functions += "} def\n\n"; functions += "%c Drawing functions:\n\n"; functions += "%c Line style:\n"; functions += " 1 setlinejoin\n\n"; functions += "/drawWire { %c draw a line\n"; functions += " /b_RGB exch def\n"; functions += " /g_RGB exch def\n"; functions += " /r_RGB exch def\n"; functions += " /lw exch def\n"; functions += " /y2 exch def\n"; functions += " /x2 exch def\n"; functions += " /y1 exch def\n"; functions += " /x1 exch def\n"; //functions += " gsave\n"; functions += " newpath\n"; functions += " x1 EU y1 EU moveto\n"; functions += " x2 EU y2 EU lineto\n"; functions += " lw EU setlinewidth\n"; functions += " r_RGB g_RGB b_RGB setrgbcolor\n"; functions += " stroke\n"; //functions += " grestore\n"; functions += "} def\n\n"; // Draw an empty rectangle functions += "/drawRect {\n"; functions += " newpath\n"; functions += " /b_RGB exch def\n"; functions += " /g_RGB exch def\n"; functions += " /r_RGB exch def\n"; functions += " /angle exch def\n"; functions += " /y2 exch def\n"; functions += " /x2 exch def\n"; functions += " /y1 exch def\n"; functions += " /x1 exch def\n"; functions += " /w2 x2 x1 sub 2 div EU def\n"; functions += " /h2 y2 y1 sub 2 div EU def\n"; functions += " gsave\n"; functions += " x1 x2 add 2 div EU y1 y2 add 2 div EU translate\n"; functions += " angle rotate\n"; functions += " newpath\n"; functions += " w2 h2 moveto\n"; functions += " w2 neg h2 lineto\n"; functions += " w2 neg h2 neg lineto\n"; functions += " w2 h2 neg lineto\n"; functions += " closepath\n"; functions += " r_RGB g_RGB b_RGB setrgbcolor\n"; functions += " fill\n"; functions += " grestore\n"; functions += "} def\n\n"; // Draw a filled circle functions += "/drawFilledCircle {\n"; functions += " /b_RGB exch def\n"; functions += " /g_RGB exch def\n"; functions += " /r_RGB exch def\n"; functions += " /dia exch def\n"; functions += " /y exch def\n"; functions += " /x exch def\n"; functions += " x EU y EU dia 2 div EU 0 360 arc\n"; //functions += " gsave\n"; functions += " r_RGB g_RGB b_RGB setrgbcolor\n"; functions += " fill\n"; functions += " stroke\n"; //functions += " grestore\n"; functions += "} def\n\n"; // Draw an empty circle functions += "/drawCircle { %c draw a circle\n"; functions += " /b_RGB exch def\n"; functions += " /g_RGB exch def\n"; functions += " /r_RGB exch def\n"; functions += " /lw exch def\n"; functions += " /rd exch def\n"; functions += " /y exch def\n"; functions += " /x exch def\n"; //functions += " gsave\n"; functions += " newpath\n"; functions += " lw EU setlinewidth\n"; functions += " x EU y EU rd EU 0 360 arc\n"; functions += " r_RGB g_RGB b_RGB setrgbcolor\n"; functions += " stroke\n"; //functions += " grestore\n"; functions += "} def\n\n"; // Draw a text string functions += "/drawText {\n"; functions += " /text exch def\n"; functions += " /b_RGB exch def\n"; functions += " /g_RGB exch def\n"; functions += " /r_RGB exch def\n"; functions += " /angle exch def\n"; functions += " /size exch def\n"; functions += " /posY exch def\n"; functions += " /posX exch def\n"; functions += " /%s findfont\n"; functions += " size EU %0.3f mul scalefont\n"; // include our own crude font scaling functions += " setfont\n"; functions += " gsave\n"; functions += " posX EU posY EU translate\n"; functions += " angle rotate\n"; functions += " r_RGB g_RGB b_RGB setrgbcolor\n"; functions += " 0 0 moveto\n"; functions += " text show\n"; functions += " grestore\n"; functions += "} def\n\n"; // Draw an arc functions += "/drawArc {\n"; functions += " /b_RGB exch def\n"; functions += " /g_RGB exch def\n"; functions += " /r_RGB exch def\n"; functions += " /angle2 exch def\n"; functions += " /angle1 exch def\n"; functions += " /width exch def\n"; functions += " /radius exch def\n"; functions += " /yc exch def\n"; functions += " /xc exch def\n"; //functions += " gsave\n"; functions += " newpath\n"; functions += " width EU setlinewidth\n"; functions += " xc EU yc EU radius EU angle1 angle2 arc\n"; functions += " stroke\n"; //functions += " grestore\n"; functions += "} def\n\n"; functions += "/setLongDash { [10 5 10 5] 0 setdash }def\n\n"; functions += "/setShortDash { [5 5 5 5] 0 setdash }def\n\n"; functions += "/setDashDot { [10 5 1 5] 0 setdash }def\n\n"; functions += "\n%c%cEndProcSet\n\n"; printf(functions, '%', '%', '%', crop_llx/72, crop_lly/72, crop_width/72, crop_height/72, // page size '%', '%', '%', '%', g_FontStr, rFontScaleFactor, // drawText '%', '%' ); // endprocset } //------------------------------------------------------ //write postscript header //------------------------------------------------------ void write_ps_header( UL_SCHEMATIC SCH ) { int t = time(); int pageCount = 0; // string header = "%c!PS-Adobe-2.1\n"; string header = "%c!PS-Adobe-3.0\n"; header += "%c%cTitle: EAGLE Drawing: %s\n"; header += "%c%cCreator: %s\n"; header += "%c%cCreationDate: %02d-%s-%d %02d:%02d:%02d\n"; // header += "%c%cDocumentFonts: %s\n"; // older format header += "%c%cDocumentNeededResources: font %s\n"; // newer format header += "%c%cDocumentPaperSizes: %s\n"; header += "%c%cBoundingBox: %0.0f %0.0f %0.0f %0.0f\n"; header += "%c%cPages: %d\n"; header += "%c%cPageOrder: Ascend\n"; header += "%c%cDocumentData: Clean7Bit\n"; header += "%c%cOrientation: %s\n"; header += "%c%cEndComments\n"; header += "%c%cBeginProcSet: schematic.pro\n\n"; SCH.sheets(S) { pageCount++; } printf(header, '%', '%', '%', SCH.name, // title '%', '%', VERSION, // creator '%', '%', t2day(t), monthArray[t2month(t)], t2year(t), t2hour(t), t2minute(t), t2second(t), '%', '%', g_FontStr, // font used '%', '%', g_sheetSizeArray[g_selSheetSize], // paper size '%', '%', bb_llx, bb_lly, bb_urx, bb_ury, // bounding box '%', '%', pageCount, // page count '%', '%', // page order '%', '%', // doc data '%', '%', g_sheetOrientationArray[g_selRotation], // orientation '%', '%', // endcomments '%', '%' ); SCH.sheets(S) { //printf("\%\ X1:%d Y1:%d X2:%d Y2:%d\n", S.area.x1, S.area.y1, S.area.x2, S.area.y2); // For test reason } } //------------------------------------------------------ //write index of modules //------------------------------------------------------ void write_ps_schematics( string fileName ) { real x_scaleFactor, y_scaleFactor; // sprintf(dbgStr, "g_selRotation = %d", g_selRotation); // dlgMessageBox(dbgStr,"Okay"); // set sheet size if (g_selSheetSize > 0) { g_sheetWidth = g_sheetSizes[(g_selSheetSize*2) ]; g_sheetHeight = g_sheetSizes[(g_selSheetSize*2)+1]; } // setup bounding and crop borders if (!g_selRotation) { bb_urx = (g_sheetWidth * 72); bb_ury = (g_sheetHeight * 72); } else { bb_urx = (g_sheetHeight * 72); bb_ury = (g_sheetWidth * 72); } // sprintf(dbgStr, "bb_urx = %0.4f\nbb_ury = %0.4f", bb_urx, bb_ury); // dlgMessageBox(dbgStr,"Okay"); bb_llx = 0; bb_lly = 0; crop_llx = g_leftOff * 72; crop_lly = g_bottomOff * 72; crop_urx = bb_urx - (g_rightOff * 72); crop_ury = bb_ury - (g_topOff * 72); crop_width = crop_urx - crop_llx; crop_height = crop_ury - crop_lly; // start output output(fileName, "Fwt") { if(schematic) { schematic(SCH) { write_ps_header( SCH ); write_ps_functions(); SCH.layers(L) { colorLUT[L.number] = palette(L.color); //printf("%c Layer %3d %s: %d %06x\n", '%',L.number, L.name, L.color, palette(L.color));// For test reason } SCH.sheets(SH) { printf("\n%c%cPage: Page_%d %d", '%', '%', SH.number, SH.number); printf(" %c(Page_%d Size (before scaling): %0.4f\"w x %0.4f\"h)\n\n", '%', SH.number, u2inch(SH.area.x2) - u2inch(SH.area.x1), u2inch(SH.area.y2) - u2inch(SH.area.y1)); // Setup Page Rotation if (g_selRotation) { printf("90 rotate\n"); printf("%0.0f %0.0f translate\n", 0.0, -(bb_ury-1)); } // Setup Page Cropping Region printf("SetupDrawingRegion\n"); // Setup Page Scaling if (g_selScaleDrawing > 0) // some kind of fitting selected { // calculate scaleFactor if (g_selRotation) { y_scaleFactor = crop_width / (u2inch(SH.area.x2 - SH.area.x1) * 72); x_scaleFactor = crop_height / (u2inch(SH.area.y2 - SH.area.y1) * 72); } else { x_scaleFactor = crop_width / (u2inch(SH.area.x2 - SH.area.x1) * 72); y_scaleFactor = crop_height / (u2inch(SH.area.y2 - SH.area.y1) * 72); } // sprintf(dbgStr, "x_scalefactor = %0.4f / %0.4f = %0.4f\ny_scalefactor = %0.4f / %0.4f = %0.4f", // crop_width/72, u2inch(SH.area.x2 - SH.area.x1), x_scaleFactor, // crop_height/72, u2inch(SH.area.y2 - SH.area.y1), y_scaleFactor); // dlgMessageBox(dbgStr,"Okay"); // maintain aspect ratio if (g_selScaleDrawingAspect) { if (x_scaleFactor < y_scaleFactor) y_scaleFactor = x_scaleFactor; // x needs more shrinking else x_scaleFactor = y_scaleFactor; // y needs more shrinking } // shrink only? if (g_selScaleDrawing==1) // shrink only) { if (x_scaleFactor > 1) x_scaleFactor = 1; if (y_scaleFactor > 1) y_scaleFactor = 1; } // print scaling instructions printf("%0.5f %0.5f scale\n", x_scaleFactor, y_scaleFactor); } // Print the page contents printf("\n"); write_sheet_texts( SH ); write_sheet_wires( SH ); write_sheet_nets( SH ); write_sheet_busses( SH ); write_sheet_rectangles( SH ); write_sheet_polygons( SH ); write_sheet_circles( SH ); write_sheet_parts( SH ); // Show the results printf("\nshowpage\n\n"); } printf("%c EndSCHEMATIC\n", '%'); } } } } //------------------------------------------------------ // Global mod_ and lib_name //------------------------------------------------------ string sch_name ; //------------------------------------------------------ // Select the path where the schematic will be saved //------------------------------------------------------ void openSchematicPath( string startPath ) { string dirName = ""; string stringArray[]; dirName = dlgDirectory("Select a directory", startPath); if( dirName != "" ) { schematic(S) { int n = 0; string tmpName = S.name; int nr = strsplit(stringArray, tmpName, '/'); sch_name = dirName + "/" + stringArray[nr-1]; sprintf(sch_name, "%s%4d-%2d%2d.ps", strsub(sch_name , 0, strlen(sch_name) - 4), t2year(time()), t2month(time())+1, t2day(time())); } } } //------------------------------------------------------ // main program //------------------------------------------------------ int result; int space = 10; string ref; string titleStr; sprintf(titleStr, "%s", VERSION); if (schematic) { schematic(S) { sprintf(sch_name, "%s_%04d-%02d%02d.ps", strsub(S.name, 0, strlen(S.name) - 4), t2year(time()), t2month(time())+1, t2day(time())); // sch_name = strsub(S.name, 0, strlen(S.name) - 4) + ".ps"; } } else { dlgMessageBox("Please run from schematic editor." ); exit(EXIT_FAILURE); } result = dlgDialog(titleStr) { // setup inital values.. g_sheetWidth = g_sheetSizes[(g_selSheetSize*2) ]; g_sheetHeight = g_sheetSizes[(g_selSheetSize*2)+1]; rFontScaleFactor = g_FontScaler[g_selFont]; // display the widget dlgTabWidget { //=====================TAB1============================================================= dlgTabPage("General") { dlgHBoxLayout { dlgSpacing(400); // define the minimum window width } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgGroup("Output Filename") { dlgHBoxLayout { dlgSpacing(space); dlgLabel("Export to file:"); dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgStringEdit(sch_name); dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgStretch(1); dlgPushButton("Browse") openSchematicPath("C:\\"); dlgSpacing(space); } } dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgGroup("Page Scaling") { dlgHBoxLayout { dlgSpacing(space); dlgLabel("Fit Pages To Output Paper Size?"); dlgSpacing(space); dlgComboBox(g_sheetScaling, g_selScaleDrawing) {} dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgLabel("Maintain Aspect Ratio?"); dlgSpacing(space); dlgComboBox(g_sheetScalingAspect, g_selScaleDrawingAspect) {} dlgSpacing(space); } } dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgGroup("Miscellaneous") { dlgHBoxLayout { dlgSpacing(space); dlgLabel("Export Text Font:"); dlgSpacing(space); dlgComboBox(g_FontBoxArray, g_selFont) { g_FontStr = g_FontBoxArray[g_selFont]; rFontScaleFactor = g_FontScaler[g_selFont]; } dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgStretch(3); dlgLabel("Font Scaling:"); dlgSpacing(space); dlgRealEdit(rFontScaleFactor); dlgSpacing(space); dlgSpacing(space); dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgLabel("Export Layer Selection:"); dlgSpacing(space); dlgComboBox(g_sheetOutputVisibleOnly, g_selOutputVisibleOnly) {} dlgSpacing(space); } } dlgSpacing(space); } dlgSpacing(space); dlgStretch(1); } //=====================TAB2============================================================= dlgTabPage("Paper Size") { dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgGroup("Paper Selection") { dlgHBoxLayout { dlgSpacing(space); dlgLabel("Page Size:"); dlgSpacing(space); dlgComboBox(g_comboBoxArray, g_selSheetSize) { // grab the predefined size if (g_selSheetSize > 0) { g_sheetWidth = g_sheetSizes[(g_selSheetSize*2) ]; g_sheetHeight = g_sheetSizes[(g_selSheetSize*2)+1]; } else // allow the user to enter the new size { dlgDialog("User Defined Paper Size") { dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgLabel("User Defined Width (inches):"); dlgSpacing(space); dlgRealEdit(g_sheetWidth, 0.0, 99.9); dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgLabel("User Defined Height (inches):"); dlgSpacing(space); dlgRealEdit(g_sheetHeight, 0.0, 99.9); dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgPushButton("Okay") dlgAccept(); dlgSpacing(space); } }; } } dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgLabel("Orientation:"); dlgSpacing(space); dlgComboBox(g_sheetOrientationArray, g_selRotation) {} dlgSpacing(space); } } dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgGroup("Margins (inches)") { dlgHBoxLayout { dlgStretch(2); dlgLabel("Top"); dlgStretch(2); } dlgHBoxLayout { dlgStretch(2); dlgRealEdit(g_topOff, 0.0, 99.9); dlgStretch(2); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgLabel("Left"); dlgSpacing(space); dlgRealEdit(g_leftOff, 0.0, 99.9); dlgStretch(2); dlgRealEdit(g_rightOff, 0.0, 99.9); dlgSpacing(space); dlgLabel("Right"); dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgStretch(2); dlgRealEdit(g_bottomOff, 0.0, 99.9); dlgStretch(2); } dlgHBoxLayout { dlgStretch(2); dlgLabel("Bottom"); dlgStretch(2); } } dlgSpacing(space); } dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); } dlgSpacing(space); dlgStretch(1); } //=====================TAB3============================================================= dlgTabPage("About") { dlgSpacing(space); dlgHBoxLayout { dlgSpacing(space); dlgTextView(ABOUT); dlgSpacing(space); } dlgSpacing(space); }; //=====================ENDOFTABS============================================================= } dlgHBoxLayout { dlgStretch(1); dlgPushButton("+OK") dlgAccept(); dlgSpacing(space); dlgPushButton("-Cancel") dlgReject(); dlgSpacing(space); } }; if(result) { write_ps_schematics(sch_name); } else dlgMessageBox("Canceled!" ); exit(EXIT_SUCCESS);