Changes between Version 8 and Version 9 of EagleCraftRobo


Ignore:
Timestamp:
Jan 11, 2011 1:36:18 PM (13 years ago)
Author:
sgk
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • EagleCraftRobo

    v8 v9  
    3636== The code ==
    3737
    38 https://gist.github.com/703363>
     38最新のコードは、[https://gist.github.com/703363 Github]にあります。
     39
     40The latest code is on [https://gist.github.com/703363 Github].
    3941
    4042{{{
    4143#!c
    4244//
    43 // Export the EAGLE cream layers to DXF for the Craft-ROBO cutting machine.
     45// Export the EAGLE cream layers to DXF for the Craft-ROBO cutting plotter.
    4446//
    4547// Copyright (c) 2010 Switch Science, Inc.
    4648//
     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
     56real SHRINK_WIDTH = 0.15;               // unit: mm
     57real MIN_CORNERRADIUS = 0.05;           // unit: mm
     58
     59// Flags
     60int CORNERCUT = 0;                      // boolean
     61int OVERCUT = 0;                        // boolean
    4762
    4863string HEADER =
     
    5469"$ACADVER\n"
    5570"  1\n"
    56 "AC1014\n"
    57 "  9\n"
    58 "$HANDSEED\n"
    59 "  5\n"
    60 "FFFF\n"
     71"AC1013\n"
    6172"  9\n"
    6273"$MEASUREMENT\n"
     
    7384"  0\n"
    7485"LWPOLYLINE\n"
    75 "  5\n"
    76 "%d\n"                                  // id
    77 "100\n"
    78 "AcDbEntity\n"
    79 "  8\n"
    80 "0\n"
     86"  8\n"
     87"0\n"                                   // layer
    8188" 62\n"
    82 "7\n"
    83 "100\n"
    84 "AcDbPolyline\n"
     89"7\n"                                   // color
    8590" 90\n"
    8691"%d\n"                                  // number of points
    8792" 70\n"
    88 "0\n";
    89 
    90 string POINT =
     93"%d\n";                                 // 0=open 1=close
     94
     95string POLYLINE_POINT =
    9196" 10\n"
    9297"%f\n"
    9398" 20\n"
    94 "%f\n"
    95 " 30\n"
    96 "0.0\n";
     99"%f\n";
     100
     101string 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
     115string 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
     131string 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
    97142
    98143string TRAILER =
     
    102147"EOF\n";
    103148
    104 void processLayer(UL_BOARD B, int layer) {
     149int
     150processLayer(UL_BOARD B, int layer) {
     151  int count = 0;
    105152  int cream = (layer == LAYER_TOP ? LAYER_TCREAM : LAYER_BCREAM);
    106   int id = 100;
    107153  printf("%s", HEADER);
    108154  B.elements(E) {
     
    111157        real x = C.smd.x / 10000.0;
    112158        real y = C.smd.y / 10000.0;
    113         real w = C.smd.dx[cream] / 10000.0 / 2;
    114         real h = C.smd.dy[cream] / 10000.0 / 2;
     159        real w = C.smd.dx[cream] / 10000.0 / 2 - SHRINK_WIDTH;
     160        real h = C.smd.dy[cream] / 10000.0 / 2 - SHRINK_WIDTH;
    115161        real a = C.smd.angle / 180 * PI;
    116162        real wc = w * cos(a);
     
    118164        real ws = w * sin(a);
    119165        real hc = h * cos(a);
    120         printf(POLYLINE, id++, 6);      // 6 points
    121         printf(POINT, x + wc - hs, y + ws + hc);        // a
    122         printf(POINT, x - wc - hs, y - ws + hc);        // b
    123         printf(POINT, x - wc + hs, y - ws - hc);        // c
    124         printf(POINT, x + wc + hs, y + ws - hc);        // d
    125         printf(POINT, x + wc - hs, y + ws + hc);        // a; close the rectangle
    126         printf(POINT, x - wc - hs, y - ws + hc);        // b; one more line
     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++;
    127215      }
    128216    }
    129217  }
    130218  printf("%s", TRAILER);
     219  return count;
    131220}
    132221
     222
     223for (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
    133231board(B) {
    134   output(filesetext(B.name, "-tcream.dxf")) processLayer(B, LAYER_TOP);
    135   output(filesetext(B.name, "-bcream.dxf")) processLayer(B, LAYER_BOTTOM);
     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);
    136239}
    137240}}}