33 #include <glib/gstdio.h>
38 #define DPRINTF(...) do { if (DEBUG) printf(__VA_ARGS__); } while (0)
40 #define round(x) floor(x+0.5)
43 export_rs274x_write_macro (FILE *fd, gerbv_aperture_t *currentAperture,
44 gint apertureNumber) {
45 gerbv_simplified_amacro_t *ls = currentAperture->simplified;
48 fprintf(fd,
"%%AMMACRO%d*\n",apertureNumber);
51 fprintf(fd,
"1,%d,%f,%f,%f,%f*\n",(
int) ls->parameter[CIRCLE_EXPOSURE],
52 ls->parameter[CIRCLE_DIAMETER],ls->parameter[CIRCLE_CENTER_X],
53 ls->parameter[CIRCLE_CENTER_Y],
54 ls->parameter[CIRCLE_ROTATION]);
58 int numberOfPoints = (int) ls->parameter[OUTLINE_NUMBER_OF_POINTS];
61 fprintf(fd,
"4,%d,%d,",(
int) ls->parameter[OUTLINE_EXPOSURE],
64 for (pointCounter=0; pointCounter <= numberOfPoints; pointCounter++) {
65 fprintf(fd,
"%f,%f,",ls->parameter[pointCounter * 2 + OUTLINE_FIRST_X],
66 ls->parameter[pointCounter * 2 + OUTLINE_FIRST_Y]);
68 fprintf(fd,
"%f*\n",ls->parameter[pointCounter * 2 + OUTLINE_FIRST_X]);
71 fprintf(fd,
"5,%d,%d,%f,%f,%f,%f*\n",(
int) ls->parameter[POLYGON_EXPOSURE],
72 (
int) ls->parameter[POLYGON_NUMBER_OF_POINTS],
73 ls->parameter[POLYGON_CENTER_X],ls->parameter[POLYGON_CENTER_Y],
74 ls->parameter[POLYGON_DIAMETER],ls->parameter[POLYGON_ROTATION]);
77 fprintf(fd,
"6,%f,%f,%f,%f,%f,%d,%f,%f,%f*\n",ls->parameter[MOIRE_CENTER_X],
78 ls->parameter[MOIRE_CENTER_Y],ls->parameter[MOIRE_OUTSIDE_DIAMETER],
79 ls->parameter[MOIRE_CIRCLE_THICKNESS],ls->parameter[MOIRE_GAP_WIDTH],
80 (
int) ls->parameter[MOIRE_NUMBER_OF_CIRCLES],ls->parameter[MOIRE_CROSSHAIR_THICKNESS],
81 ls->parameter[MOIRE_CROSSHAIR_LENGTH],ls->parameter[MOIRE_ROTATION]);
84 fprintf(fd,
"7,%f,%f,%f,%f,%f,%f*\n",ls->parameter[THERMAL_CENTER_X],
85 ls->parameter[THERMAL_CENTER_Y],ls->parameter[THERMAL_OUTSIDE_DIAMETER],
86 ls->parameter[THERMAL_INSIDE_DIAMETER],ls->parameter[THERMAL_CROSSHAIR_THICKNESS],
87 ls->parameter[THERMAL_ROTATION]);
90 fprintf(fd,
"20,%d,%f,%f,%f,%f,%f,%f*\n",(
int) ls->parameter[LINE20_EXPOSURE],
91 ls->parameter[LINE20_LINE_WIDTH],ls->parameter[LINE20_START_X],
92 ls->parameter[LINE20_START_Y],ls->parameter[LINE20_END_X],
93 ls->parameter[LINE20_END_Y],ls->parameter[LINE20_ROTATION]);
96 fprintf(fd,
"21,%d,%f,%f,%f,%f,%f*\n",(
int) ls->parameter[LINE21_EXPOSURE],
97 ls->parameter[LINE21_WIDTH],ls->parameter[LINE21_HEIGHT],
98 ls->parameter[LINE21_CENTER_X],ls->parameter[LINE21_CENTER_Y],
99 ls->parameter[LINE21_ROTATION]);
102 fprintf(fd,
"22,%d,%f,%f,%f,%f,%f*\n",(
int) ls->parameter[LINE22_EXPOSURE],
103 ls->parameter[LINE22_WIDTH],ls->parameter[LINE22_HEIGHT],
104 ls->parameter[LINE22_LOWER_LEFT_X],ls->parameter[LINE22_LOWER_LEFT_Y],
105 ls->parameter[LINE22_ROTATION]);
111 fprintf(fd,
"%%ADD%dMACRO%d*%%\n",apertureNumber,apertureNumber);
115 export_rs274x_write_apertures (FILE *fd,
gerbv_image_t *image) {
116 gerbv_aperture_t *currentAperture;
117 gint numberOfRequiredParameters=0,numberOfOptionalParameters=0,i,j;
121 for (i=APERTURE_MIN; i<APERTURE_MAX; i++) {
122 gboolean writeAperture=TRUE;
124 currentAperture = image->
aperture[i];
126 if (!currentAperture)
129 switch (currentAperture->type) {
131 fprintf(fd,
"%%ADD%d",i);
133 numberOfRequiredParameters = 1;
134 numberOfOptionalParameters = 2;
137 fprintf(fd,
"%%ADD%d",i);
139 numberOfRequiredParameters = 2;
140 numberOfOptionalParameters = 2;
143 fprintf(fd,
"%%ADD%d",i);
145 numberOfRequiredParameters = 2;
146 numberOfOptionalParameters = 2;
149 fprintf(fd,
"%%ADD%d",i);
151 numberOfRequiredParameters = 2;
152 numberOfOptionalParameters = 3;
155 export_rs274x_write_macro (fd, currentAperture, i);
164 for (j=0; j<(numberOfRequiredParameters + numberOfOptionalParameters); j++) {
165 if ((j < numberOfRequiredParameters) || (currentAperture->parameter[j] != 0)) {
169 fprintf(fd,
"%.4f",currentAperture->parameter[j]);
172 fprintf(fd,
"*%%\n");
182 fprintf(fd,
"%%LPC*%%\n");
184 fprintf(fd,
"%%LPD*%%\n");
199 const double decimal_coeff = 1e6;
203 gboolean insidePolygon=FALSE;
207 setlocale(LC_NUMERIC,
"C");
209 if (transform != NULL) {
210 thisTransform = transform;
213 {0,0,1,1,0,FALSE,FALSE,FALSE};
214 thisTransform = &identityTransform;
216 if ((fd = g_fopen(filename,
"w")) == NULL) {
217 GERB_COMPILE_ERROR(_(
"Can't open file for writing: %s"),
226 fprintf(fd,
"G04 This is an RS-274x file exported by *\n");
227 fprintf(fd,
"G04 gerbv version %s *\n",VERSION);
228 fprintf(fd,
"G04 More information is available about gerbv at *\n");
229 fprintf(fd,
"G04 https://gerbv.github.io/ *\n");
230 fprintf(fd,
"G04 --End of header info--*\n");
231 fprintf(fd,
"%%MOIN*%%\n");
232 fprintf(fd,
"%%FSLAX36Y36*%%\n");
236 if ((image->
info->offsetA > 0.0) || (image->
info->offsetB > 0.0))
237 fprintf(fd,
"%%IOA%fB%f*%%\n",image->
info->offsetA,image->
info->offsetB);
240 fprintf(fd,
"%%IPNEG*%%\n");
242 fprintf(fd,
"%%IPPOS*%%\n");
244 if (image->
info->name)
245 fprintf(fd,
"%%IN%s*%%\n",image->
info->name);
247 if (image->
info->plotterFilm)
248 fprintf(fd,
"%%PF%s*%%\n",image->
info->plotterFilm);
251 if ((image->
info->imageRotation != 0.0)
252 || (thisTransform->
rotation != 0.0))
253 fprintf(fd,
"%%IR%d*%%\n",
254 (
int)round(RAD2DEG(image->
info->imageRotation))%360);
256 if ((image->
info->imageJustifyTypeA != GERBV_JUSTIFY_NOJUSTIFY)
257 || (image->
info->imageJustifyTypeB != GERBV_JUSTIFY_NOJUSTIFY)) {
258 fprintf(fd,
"%%IJA");
259 if (image->
info->imageJustifyTypeA == GERBV_JUSTIFY_CENTERJUSTIFY)
262 fprintf(fd,
"%.4f",image->
info->imageJustifyOffsetA);
264 if (image->
info->imageJustifyTypeB == GERBV_JUSTIFY_CENTERJUSTIFY)
267 fprintf(fd,
"%.4f",image->
info->imageJustifyOffsetB);
268 fprintf(fd,
"*%%\n");
272 if (fabs(thisTransform->
scaleX - 1) > GERBV_PRECISION_LINEAR_INCH
273 || fabs(thisTransform->
scaleY - 1) > GERBV_PRECISION_LINEAR_INCH) {
274 fprintf(fd,
"%%SFA%.4fB%.4f*%%\n",thisTransform->
scaleX,thisTransform->
scaleY);
282 fprintf(fd,
"G04 --Define apertures--*\n");
283 export_rs274x_write_apertures (fd, image);
286 fprintf(fd,
"G04 --Start main section--*\n");
287 gint currentAperture = 0;
293 for (currentNet = image->
netlist->
next; currentNet; currentNet = currentNet->
next){
295 if (currentNet->
layer != oldLayer)
296 export_rs274x_write_layer_change (oldLayer, currentNet->
layer, fd);
299 if (currentNet->
state != oldState)
300 export_rs274x_write_state_change (oldState, currentNet->
state, fd);
305 if ((currentNet->
aperture != currentAperture)&&
307 fprintf(fd,
"G54D%02d*\n",currentNet->
aperture);
308 currentAperture = currentNet->
aperture;
311 oldLayer = currentNet->
layer;
312 oldState = currentNet->
state;
314 long xVal,yVal,endX,endY,centerX,centerY;
323 xVal = (long) round(currentNet->
start_x * decimal_coeff);
324 yVal = (long) round(currentNet->
start_y * decimal_coeff);
325 fprintf(fd,
"G01X%07ldY%07ldD02*\n",xVal,yVal);
327 xVal = (long) round(currentNet->
stop_x * decimal_coeff);
328 yVal = (long) round(currentNet->
stop_y * decimal_coeff);
329 fprintf(fd,
"G01X%07ldY%07ld",xVal,yVal);
332 fprintf(fd,
"D02*\n");
334 fprintf(fd,
"D01*\n");
336 fprintf(fd,
"D03*\n");
343 xVal = (long) round(currentNet->
start_x * decimal_coeff);
344 yVal = (long) round(currentNet->
start_y * decimal_coeff);
345 fprintf(fd,
"G01X%07ldY%07ldD02*\n",xVal,yVal);
347 centerX= (long) round((currentNet->
cirseg->cp_x - currentNet->
start_x) * decimal_coeff);
348 centerY= (long) round((currentNet->
cirseg->cp_y - currentNet->
start_y) * decimal_coeff);
349 endX = (long) round(currentNet->
stop_x * decimal_coeff);
350 endY = (long) round(currentNet->
stop_y * decimal_coeff);
354 fprintf(fd,
"G75*\n");
363 fprintf(fd,
"X%07ldY%07ldI%07ldJ%07ld",endX,endY,centerX,centerY);
365 fprintf(fd,
"X%07ldY%07ld",endX,endY);
368 fprintf(fd,
"D02*\n");
370 fprintf(fd,
"D01*\n");
372 fprintf(fd,
"D03*\n");
375 fprintf(fd,
"G36*\n");
376 insidePolygon = TRUE;
379 fprintf(fd,
"G37*\n");
380 insidePolygon = FALSE;
387 fprintf(fd,
"M02*\n");
393 setlocale(LC_NUMERIC,
"");
gboolean gerbv_export_rs274x_file_from_image(const gchar *filename, gerbv_image_t *inputImage, gerbv_user_transformation_t *transform)
Export an image to a new file in RS274X format.
void gerbv_destroy_image(gerbv_image_t *image)
Free an image structure.
gerbv_image_t * gerbv_image_duplicate_image(gerbv_image_t *sourceImage, gerbv_user_transformation_t *transform)
Duplicate an existing image and return the new copy.
The main header file for the libgerbv library.
@ GERBV_APERTURE_STATE_OFF
@ GERBV_APERTURE_STATE_ON
@ GERBV_APTYPE_MACRO_LINE20
@ GERBV_APTYPE_MACRO_LINE21
@ GERBV_APTYPE_MACRO_OUTLINE
@ GERBV_APTYPE_MACRO_CIRCLE
@ GERBV_APTYPE_MACRO_POLYGON
@ GERBV_APTYPE_MACRO_THERMAL
@ GERBV_APTYPE_MACRO_LINE22
@ GERBV_APTYPE_MACRO_MOIRE
@ GERBV_INTERPOLATION_LINEARx01
@ GERBV_INTERPOLATION_PAREA_START
@ GERBV_INTERPOLATION_LINEARx001
@ GERBV_INTERPOLATION_CW_CIRCULAR
@ GERBV_INTERPOLATION_PAREA_END
@ GERBV_INTERPOLATION_LINEARx10
@ GERBV_INTERPOLATION_CCW_CIRCULAR
@ GERBV_INTERPOLATION_LINEARx1
gerbv_aperture_t * aperture[APERTURE_MAX]
gerbv_netstate_t * states
gerbv_image_info_t * info
gerbv_polarity_t polarity
gerbv_aperture_state_t aperture_state
gerbv_interpolation_t interpolation