34 #include <glib/gstdio.h>
39 #define dprintf if(DEBUG) printf
41 #define round(x) floor(x+0.5)
44 export_rs274x_write_macro (FILE *fd, gerbv_aperture_t *currentAperture,
45 gint apertureNumber) {
46 gerbv_simplified_amacro_t *ls = currentAperture->simplified;
49 fprintf(fd,
"%%AMMACRO%d*\n",apertureNumber);
52 fprintf(fd,
"1,%d,%f,%f,%f*\n",(
int) ls->parameter[CIRCLE_EXPOSURE],
53 ls->parameter[CIRCLE_DIAMETER],ls->parameter[CIRCLE_CENTER_X],
54 ls->parameter[CIRCLE_CENTER_Y]);
58 int numberOfPoints = (int) ls->parameter[OUTLINE_NUMBER_OF_POINTS];
60 fprintf(fd,
"4,%d,%d,\n",(
int) ls->parameter[OUTLINE_EXPOSURE],
63 for (pointCounter=0; pointCounter <= numberOfPoints; pointCounter++) {
64 fprintf(fd,
"%f,%f,",ls->parameter[pointCounter * 2 + OUTLINE_FIRST_X],
65 ls->parameter[pointCounter * 2 + OUTLINE_FIRST_Y]);
67 fprintf(fd,
"%f*\n",ls->parameter[pointCounter * 2 + OUTLINE_FIRST_X]);
70 fprintf(fd,
"5,%d,%d,%f,%f,%f,%f*\n",(
int) ls->parameter[POLYGON_EXPOSURE],
71 (
int) ls->parameter[POLYGON_NUMBER_OF_POINTS],
72 ls->parameter[POLYGON_CENTER_X],ls->parameter[POLYGON_CENTER_Y],
73 ls->parameter[POLYGON_DIAMETER],ls->parameter[POLYGON_ROTATION]);
76 fprintf(fd,
"6,%f,%f,%f,%f,%f,%d,%f,%f,%f*\n",ls->parameter[MOIRE_CENTER_X],
77 ls->parameter[MOIRE_CENTER_Y],ls->parameter[MOIRE_OUTSIDE_DIAMETER],
78 ls->parameter[MOIRE_CIRCLE_THICKNESS],ls->parameter[MOIRE_GAP_WIDTH],
79 (
int) ls->parameter[MOIRE_NUMBER_OF_CIRCLES],ls->parameter[MOIRE_CROSSHAIR_THICKNESS],
80 ls->parameter[MOIRE_CROSSHAIR_LENGTH],ls->parameter[MOIRE_ROTATION]);
83 fprintf(fd,
"7,%f,%f,%f,%f,%f,%f*\n",ls->parameter[THERMAL_CENTER_X],
84 ls->parameter[THERMAL_CENTER_Y],ls->parameter[THERMAL_OUTSIDE_DIAMETER],
85 ls->parameter[THERMAL_INSIDE_DIAMETER],ls->parameter[THERMAL_CROSSHAIR_THICKNESS],
86 ls->parameter[THERMAL_ROTATION]);
89 fprintf(fd,
"20,%d,%f,%f,%f,%f,%f,%f*\n",(
int) ls->parameter[LINE20_EXPOSURE],
90 ls->parameter[LINE20_LINE_WIDTH],ls->parameter[LINE20_START_X],
91 ls->parameter[LINE20_START_Y],ls->parameter[LINE20_END_X],
92 ls->parameter[LINE20_END_Y],ls->parameter[LINE20_ROTATION]);
95 fprintf(fd,
"21,%d,%f,%f,%f,%f,%f*\n",(
int) ls->parameter[LINE21_EXPOSURE],
96 ls->parameter[LINE21_WIDTH],ls->parameter[LINE21_HEIGHT],
97 ls->parameter[LINE21_CENTER_X],ls->parameter[LINE21_CENTER_Y],
98 ls->parameter[LINE21_ROTATION]);
101 fprintf(fd,
"22,%d,%f,%f,%f,%f,%f*\n",(
int) ls->parameter[LINE22_EXPOSURE],
102 ls->parameter[LINE22_WIDTH],ls->parameter[LINE22_HEIGHT],
103 ls->parameter[LINE22_LOWER_LEFT_X],ls->parameter[LINE22_LOWER_LEFT_Y],
104 ls->parameter[LINE22_ROTATION]);
110 fprintf(fd,
"%%ADD%dMACRO%d*%%\n",apertureNumber,apertureNumber);
114 export_rs274x_write_apertures (FILE *fd,
gerbv_image_t *image) {
115 gerbv_aperture_t *currentAperture;
116 gint numberOfRequiredParameters=0,numberOfOptionalParameters=0,i,j;
120 for (i=APERTURE_MIN; i<APERTURE_MAX; i++) {
121 gboolean writeAperture=TRUE;
123 currentAperture = image->
aperture[i];
125 if (!currentAperture)
128 switch (currentAperture->type) {
130 fprintf(fd,
"%%ADD%d",i);
132 numberOfRequiredParameters = 1;
133 numberOfOptionalParameters = 2;
136 fprintf(fd,
"%%ADD%d",i);
138 numberOfRequiredParameters = 2;
139 numberOfOptionalParameters = 2;
142 fprintf(fd,
"%%ADD%d",i);
144 numberOfRequiredParameters = 2;
145 numberOfOptionalParameters = 2;
148 fprintf(fd,
"%%ADD%d",i);
150 numberOfRequiredParameters = 2;
151 numberOfOptionalParameters = 3;
154 export_rs274x_write_macro (fd, currentAperture, i);
163 for (j=0; j<(numberOfRequiredParameters + numberOfOptionalParameters); j++) {
164 if ((j < numberOfRequiredParameters) || (currentAperture->parameter[j] != 0)) {
168 fprintf(fd,
"%.4f",currentAperture->parameter[j]);
171 fprintf(fd,
"*%%\n");
181 fprintf(fd,
"%%LPC*%%\n");
183 fprintf(fd,
"%%LPD*%%\n");
199 gboolean insidePolygon=FALSE;
203 setlocale(LC_NUMERIC,
"C");
205 if (transform != NULL) {
206 thisTransform = transform;
210 thisTransform = &identityTransform;
212 if ((fd = g_fopen(filename,
"w")) == NULL) {
213 GERB_MESSAGE(_(
"Can't open file for writing: %s"), filename);
221 fprintf(fd,
"G04 This is an RS-274x file exported by *\n");
222 fprintf(fd,
"G04 gerbv version %s *\n",VERSION);
223 fprintf(fd,
"G04 More information is available about gerbv at *\n");
224 fprintf(fd,
"G04 http://gerbv.geda-project.org/ *\n");
225 fprintf(fd,
"G04 --End of header info--*\n");
226 fprintf(fd,
"%%MOIN*%%\n");
227 fprintf(fd,
"%%FSLAX34Y34*%%\n");
231 if ((image->
info->offsetA > 0.0) || (image->
info->offsetB > 0.0))
232 fprintf(fd,
"%%IOA%fB%f*%%\n",image->
info->offsetA,image->
info->offsetB);
235 fprintf(fd,
"%%IPNEG*%%\n");
237 fprintf(fd,
"%%IPPOS*%%\n");
239 if (image->
info->name)
240 fprintf(fd,
"%%IN%s*%%\n",image->
info->name);
242 if (image->
info->plotterFilm)
243 fprintf(fd,
"%%PF%s*%%\n",image->
info->plotterFilm);
245 if ((image->
info->imageRotation != 0.0)||(thisTransform->
rotation != 0.0))
246 fprintf(fd,
"%%IR%d*%%\n",(
int) ((image->
info->imageRotation + thisTransform->
rotation)*180/M_PI)%360);
247 if ((image->
info->imageJustifyTypeA != GERBV_JUSTIFY_NOJUSTIFY) ||
248 (image->
info->imageJustifyTypeB != GERBV_JUSTIFY_NOJUSTIFY)) {
249 fprintf(fd,
"%%IJA");
250 if (image->
info->imageJustifyTypeA == GERBV_JUSTIFY_CENTERJUSTIFY)
253 fprintf(fd,
"%.4f",image->
info->imageJustifyOffsetA);
255 if (image->
info->imageJustifyTypeB == GERBV_JUSTIFY_CENTERJUSTIFY)
258 fprintf(fd,
"%.4f",image->
info->imageJustifyOffsetB);
259 fprintf(fd,
"*%%\n");
263 if ((fabs(thisTransform->
scaleX - 1) > 0.00001) ||
264 (fabs(thisTransform->
scaleY - 1) > 0.00001)) {
265 fprintf(fd,
"%%SFA%.4fB%.4f*%%\n",thisTransform->
scaleX,thisTransform->
scaleY);
273 fprintf(fd,
"G04 --Define apertures--*\n");
274 export_rs274x_write_apertures (fd, image);
277 fprintf(fd,
"G04 --Start main section--*\n");
278 gint currentAperture = 0;
284 for (currentNet = image->
netlist->
next; currentNet; currentNet = currentNet->
next){
286 if (currentNet->
layer != oldLayer)
287 export_rs274x_write_layer_change (oldLayer, currentNet->
layer, fd);
290 if (currentNet->
state != oldState)
291 export_rs274x_write_state_change (oldState, currentNet->
state, fd);
296 if ((currentNet->
aperture != currentAperture)&&
298 fprintf(fd,
"G54D%02d*\n",currentNet->
aperture);
299 currentAperture = currentNet->
aperture;
302 oldLayer = currentNet->
layer;
303 oldState = currentNet->
state;
305 long xVal,yVal,endX,endY,centerX,centerY;
314 xVal = (long) round(currentNet->
start_x * 10000.0);
315 yVal = (long) round(currentNet->
start_y * 10000.0);
316 fprintf(fd,
"G01X%07ldY%07ldD02*\n",xVal,yVal);
318 xVal = (long) round(currentNet->
stop_x * 10000.0);
319 yVal = (long) round(currentNet->
stop_y * 10000.0);
320 fprintf(fd,
"G01X%07ldY%07ld",xVal,yVal);
323 fprintf(fd,
"D02*\n");
325 fprintf(fd,
"D01*\n");
327 fprintf(fd,
"D03*\n");
334 xVal = (long) round(currentNet->
start_x * 10000.0);
335 yVal = (long) round(currentNet->
start_y * 10000.0);
336 fprintf(fd,
"G01X%07ldY%07ldD02*\n",xVal,yVal);
338 centerX= (long) round((currentNet->
cirseg->cp_x - currentNet->
start_x) * 10000.0);
339 centerY= (long) round((currentNet->
cirseg->cp_y - currentNet->
start_y) * 10000.0);
340 endX = (long) round(currentNet->
stop_x * 10000.0);
341 endY = (long) round(currentNet->
stop_y * 10000.0);
345 fprintf(fd,
"G75*\n");
347 if (currentNet->
cirseg->angle2 > currentNet->
cirseg->angle1)
353 fprintf(fd,
"X%07ldY%07ldI%07ldJ%07ld",endX,endY,centerX,centerY);
355 fprintf(fd,
"X%07ldY%07ld",endX,endY);
358 fprintf(fd,
"D02*\n");
360 fprintf(fd,
"D01*\n");
362 fprintf(fd,
"D03*\n");
365 fprintf(fd,
"G36*\n");
366 insidePolygon = TRUE;
369 fprintf(fd,
"G37*\n");
370 insidePolygon = FALSE;
377 fprintf(fd,
"M02*\n");
383 setlocale(LC_NUMERIC,
"");