Changes between Version 9 and Version 10 of EagleCraftRobo


Ignore:
Timestamp:
Dec 14, 2011 1:02:45 PM (12 years ago)
Author:
sgk
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • EagleCraftRobo

    v9 v10  
    3636== The code ==
    3737
    38 最新のコードは、[https://gist.github.com/703363 Github]にあります。
     38最新のコードは、[https://github.com/SWITCHSCIENCE/ssci-eagle-public/blob/master/cream-dxf.ulp Github]にあります。
    3939
    40 The latest code is on [https://gist.github.com/703363 Github].
    41 
    42 {{{
    43 #!c
    44 //
    45 // Export the EAGLE cream layers to DXF for the Craft-ROBO cutting plotter.
    46 //
    47 // Copyright (c) 2010 Switch Science, Inc.
    48 //
    49 // Type "run cream-dxf" in the board editor window.
    50 // Options:
    51 //   -o    Add one more line segment for pads to make sure the cut.
    52 //   -c    Cut off corners of pads. The resulting pads are octagons.
    53 //
    54 
    55 // Configuration
    56 real SHRINK_WIDTH = 0.15;               // unit: mm
    57 real MIN_CORNERRADIUS = 0.05;           // unit: mm
    58 
    59 // Flags
    60 int CORNERCUT = 0;                      // boolean
    61 int OVERCUT = 0;                        // boolean
    62 
    63 string HEADER =
    64 "  0\n"
    65 "SECTION\n"
    66 "  2\n"
    67 "HEADER\n"
    68 "  9\n"
    69 "$ACADVER\n"
    70 "  1\n"
    71 "AC1013\n"
    72 "  9\n"
    73 "$MEASUREMENT\n"
    74 " 70\n"
    75 "     1\n"                              // unit: mm
    76 "  0\n"
    77 "ENDSEC\n"
    78 "  0\n"
    79 "SECTION\n"
    80 "  2\n"
    81 "ENTITIES\n";
    82 
    83 string POLYLINE =
    84 "  0\n"
    85 "LWPOLYLINE\n"
    86 "  8\n"
    87 "0\n"                                   // layer
    88 " 62\n"
    89 "7\n"                                   // color
    90 " 90\n"
    91 "%d\n"                                  // number of points
    92 " 70\n"
    93 "%d\n";                                 // 0=open 1=close
    94 
    95 string POLYLINE_POINT =
    96 " 10\n"
    97 "%f\n"
    98 " 20\n"
    99 "%f\n";
    100 
    101 string LINE =
    102 "  0\n"
    103 "LINE\n"
    104 "  8\n"
    105 "0\n"                                   // layer
    106 " 10\n"
    107 "%f\n"                                  // start x
    108 " 20\n"
    109 "%f\n"                                  // start y
    110 " 11\n"
    111 "%f\n"                                  // end x
    112 " 21\n"
    113 "%f\n";                                 // end y
    114 
    115 string ARC =
    116 "  0\n"
    117 "ARC\n"
    118 "  8\n"
    119 "0\n"                                   // layer
    120 " 10\n"
    121 "%f\n"                                  // center x
    122 " 20\n"
    123 "%f\n"                                  // center y
    124 " 40\n"
    125 "%f\n"                                  // radius
    126 " 50\n"
    127 "%f\n"                                  // start angle
    128 " 51"
    129 "%f\n";                                 // end angle
    130 
    131 string CIRCLE =
    132 "  0\n"
    133 "CIRCLE\n"
    134 "  8\n"
    135 "0\n"                                   // layer
    136 " 10\n"
    137 "%f\n"                                  // center x
    138 " 20\n"
    139 "%f\n"                                  // center y
    140 " 40\n"
    141 "%f\n";                                 // radius
    142 
    143 string TRAILER =
    144 "  0\n"
    145 "ENDSEC\n"
    146 "  0\n"
    147 "EOF\n";
    148 
    149 int
    150 processLayer(UL_BOARD B, int layer) {
    151   int count = 0;
    152   int cream = (layer == LAYER_TOP ? LAYER_TCREAM : LAYER_BCREAM);
    153   printf("%s", HEADER);
    154   B.elements(E) {
    155     E.package.contacts(C) {
    156       if (C.smd && C.smd.layer == layer) {
    157         real x = C.smd.x / 10000.0;
    158         real y = C.smd.y / 10000.0;
    159         real w = C.smd.dx[cream] / 10000.0 / 2 - SHRINK_WIDTH;
    160         real h = C.smd.dy[cream] / 10000.0 / 2 - SHRINK_WIDTH;
    161         real a = C.smd.angle / 180 * PI;
    162         real wc = w * cos(a);
    163         real hs = h * sin(a);
    164         real ws = w * sin(a);
    165         real hc = h * cos(a);
    166 
    167         real r = max(min(w, h) * C.smd.roundness / 100, MIN_CORNERRADIUS);
    168         if (CORNERCUT && h > r && w > r) {
    169           real rc = r * cos(a);
    170           real rs = r * sin(a);
    171           if (OVERCUT) {
    172             printf(POLYLINE, 10, 0);            // 10 points, open polyline
    173             printf(POLYLINE_POINT, x + wc, y + ws);                     // (w, 0)
    174             printf(POLYLINE_POINT, x + wc - hs + rs, y + ws + hc - rc); // (w, h-r)
    175             printf(POLYLINE_POINT, x + wc - rc - hs, y + ws - rs + hc); // (w-r, h)
    176             printf(POLYLINE_POINT, x - wc + rc - hs, y - ws + rs + hc); // (-w+r, h)
    177             printf(POLYLINE_POINT, x - wc - hs + rs, y - ws + hc - rc); // (-w, h-r)
    178             printf(POLYLINE_POINT, x - wc + hs - rs, y - ws - hc + rc); // (-w, -h+r)
    179             printf(POLYLINE_POINT, x - wc + rc + hs, y - ws + rs - hc); // (-w+r, -h)
    180             printf(POLYLINE_POINT, x + wc - rc + hs, y + ws - rs - hc); // (w-r, -h)
    181             printf(POLYLINE_POINT, x + wc + hs - rs, y + ws - hc + rc); // (w, -h+r)
    182             printf(POLYLINE_POINT, x + wc - hs + rs, y + ws + hc - rc); // (w, h-r)
    183           } else {
    184             printf(POLYLINE, 9, 1);             // 9 points, close polyline
    185             printf(POLYLINE_POINT, x + wc, y + ws);                     // (w, 0)
    186             printf(POLYLINE_POINT, x + wc - hs + rs, y + ws + hc - rc); // (w, h-r)
    187             printf(POLYLINE_POINT, x + wc - rc - hs, y + ws - rs + hc); // (w-r, h)
    188             printf(POLYLINE_POINT, x - wc + rc - hs, y - ws + rs + hc); // (-w+r, h)
    189             printf(POLYLINE_POINT, x - wc - hs + rs, y - ws + hc - rc); // (-w, h-r)
    190             printf(POLYLINE_POINT, x - wc + hs - rs, y - ws - hc + rc); // (-w, -h+r)
    191             printf(POLYLINE_POINT, x - wc + rc + hs, y - ws + rs - hc); // (-w+r, -h)
    192             printf(POLYLINE_POINT, x + wc - rc + hs, y + ws - rs - hc); // (w-r, -h)
    193             printf(POLYLINE_POINT, x + wc + hs - rs, y + ws - hc + rc); // (w, -h+r)
    194           }
    195         } else {
    196           if (OVERCUT) {
    197             printf(POLYLINE, 6, 0);             // 6 points, open polyline
    198             printf(POLYLINE_POINT, x + wc, y + ws);             // ( w,  0)
    199             printf(POLYLINE_POINT, x + wc - hs, y + ws + hc);   // ( w,  h)
    200             printf(POLYLINE_POINT, x - wc - hs, y - ws + hc);   // (-w,  h)
    201             printf(POLYLINE_POINT, x - wc + hs, y - ws - hc);   // (-w, -h)
    202             printf(POLYLINE_POINT, x + wc + hs, y + ws - hc);   // ( w, -h)
    203             printf(POLYLINE_POINT, x + wc - hs, y + ws + hc);   // ( w,  h)
    204           } else {
    205             printf(POLYLINE, 5, 1);             // 5 points, close polyline
    206             printf(POLYLINE_POINT, x + wc, y + ws);             // ( w,  0)
    207             printf(POLYLINE_POINT, x + wc - hs, y + ws + hc);   // ( w,  h)
    208             printf(POLYLINE_POINT, x - wc - hs, y - ws + hc);   // (-w,  h)
    209             printf(POLYLINE_POINT, x - wc + hs, y - ws - hc);   // (-w, -h)
    210             printf(POLYLINE_POINT, x + wc + hs, y + ws - hc);   // ( w, -h)
    211           }
    212         }
    213 
    214         count++;
    215       }
    216     }
    217   }
    218   printf("%s", TRAILER);
    219   return count;
    220 }
    221 
    222 
    223 for (int i = 1; i < argc; i++) {
    224   if (argv[i] == "-c")
    225     CORNERCUT = 1;
    226   else
    227   if (argv[i] == "-o")
    228     OVERCUT = 1;
    229 }
    230 
    231 board(B) {
    232   int t, b;
    233   output(filesetext(B.name, "-tcream.dxf")) t = processLayer(B, LAYER_TOP);
    234   output(filesetext(B.name, "-bcream.dxf")) b = processLayer(B, LAYER_BOTTOM);
    235 
    236   string message;
    237   sprintf(message, ";DXF files generated with %d+%d objects", t, b);
    238   dlgMessageBox(message);
    239 }
    240 }}}
     40The latest code is on [https://github.com/SWITCHSCIENCE/ssci-eagle-public/blob/master/cream-dxf.ulp Github].
    24141
    24242'''(2010/11/11 - sgk)'''