Changes between Version 8 and Version 9 of EagleCraftRobo
- Timestamp:
- Jan 11, 2011 1:36:18 PM (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
EagleCraftRobo
v8 v9 36 36 == The code == 37 37 38 https://gist.github.com/703363> 38 最新のコードは、[https://gist.github.com/703363 Github]にあります。 39 40 The latest code is on [https://gist.github.com/703363 Github]. 39 41 40 42 {{{ 41 43 #!c 42 44 // 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. 44 46 // 45 47 // Copyright (c) 2010 Switch Science, Inc. 46 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 47 62 48 63 string HEADER = … … 54 69 "$ACADVER\n" 55 70 " 1\n" 56 "AC1014\n" 57 " 9\n" 58 "$HANDSEED\n" 59 " 5\n" 60 "FFFF\n" 71 "AC1013\n" 61 72 " 9\n" 62 73 "$MEASUREMENT\n" … … 73 84 " 0\n" 74 85 "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 81 88 " 62\n" 82 "7\n" 83 "100\n" 84 "AcDbPolyline\n" 89 "7\n" // color 85 90 " 90\n" 86 91 "%d\n" // number of points 87 92 " 70\n" 88 " 0\n";89 90 string PO INT =93 "%d\n"; // 0=open 1=close 94 95 string POLYLINE_POINT = 91 96 " 10\n" 92 97 "%f\n" 93 98 " 20\n" 94 "%f\n" 95 " 30\n" 96 "0.0\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 97 142 98 143 string TRAILER = … … 102 147 "EOF\n"; 103 148 104 void processLayer(UL_BOARD B, int layer) { 149 int 150 processLayer(UL_BOARD B, int layer) { 151 int count = 0; 105 152 int cream = (layer == LAYER_TOP ? LAYER_TCREAM : LAYER_BCREAM); 106 int id = 100;107 153 printf("%s", HEADER); 108 154 B.elements(E) { … … 111 157 real x = C.smd.x / 10000.0; 112 158 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; 115 161 real a = C.smd.angle / 180 * PI; 116 162 real wc = w * cos(a); … … 118 164 real ws = w * sin(a); 119 165 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++; 127 215 } 128 216 } 129 217 } 130 218 printf("%s", TRAILER); 219 return count; 131 220 } 132 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 133 231 board(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); 136 239 } 137 240 }}}