48 #define dprintf if(DEBUG) printf
50 #define A2I(a,b) (((a & 0xff) << 8) + (b & 0xff))
55 static void parse_G_code(gerb_file_t *fd, gerb_state_t *state,
57 static void parse_D_code(gerb_file_t *fd, gerb_state_t *state,
59 static int parse_M_code(gerb_file_t *fd,
gerbv_image_t *image);
60 static void parse_rs274x(gint levelOfRecursion, gerb_file_t *fd,
63 gchar *directoryPath);
64 static int parse_aperture_definition(gerb_file_t *fd,
65 gerbv_aperture_t *aperture,
67 static void calc_cirseg_sq(
struct gerbv_net *net,
int cw,
68 double delta_cp_x,
double delta_cp_y);
69 static void calc_cirseg_mq(
struct gerbv_net *net,
int cw,
70 double delta_cp_x,
double delta_cp_y);
73 static void gerber_update_any_running_knockout_measurements(
gerbv_image_t *image);
75 static void gerber_calculate_final_justify_effects (
gerbv_image_t *image);
77 gboolean knockoutMeasure = FALSE;
78 gdouble knockoutLimitXmin, knockoutLimitYmin, knockoutLimitXmax,
81 cairo_matrix_t currentMatrix;
89 currentNet->
next = newNet;
91 newNet->
layer = layer;
95 newNet->
state = state;
103 gerber_create_new_aperture (
gerbv_image_t *image,
int *indexNumber,
108 for (i = 0; i <= APERTURE_MAX; i++) {
110 image->
aperture[i] = g_new0 (gerbv_aperture_t, 1);
111 image->
aperture[i]->type = apertureType;
112 image->
aperture[i]->parameter[0] = parameter1;
113 image->
aperture[i]->parameter[1] = parameter2;
135 gchar *directoryPath) {
136 int read, coord, len, polygonPoints=0;
137 double x_scale = 0.0, y_scale = 0.0;
138 double delta_cp_x = 0.0, delta_cp_y = 0.0;
139 double aperture_sizeX, aperture_sizeY;
141 gboolean foundEOF = FALSE;
145 while ((read = gerb_fgetc(fd)) != EOF) {
152 switch ((
char)(read & 0xff)) {
154 dprintf(
"... Found G code\n");
158 dprintf(
"... Found D code\n");
162 dprintf(
"... Found M code\n");
163 switch(parse_M_code(fd, image)) {
170 gerbv_stats_add_error(stats->error_list,
172 _(
"Unknown M code found"),
177 dprintf(
"... Found X code\n");
179 coord = gerb_fgetint(fd, &len);
182 switch ((image->
format->x_int + image->
format->x_dec) - len) {
203 state->curr_x += coord;
205 state->curr_x = coord;
209 dprintf(
"... Found Y code\n");
211 coord = gerb_fgetint(fd, &len);
214 switch ((image->
format->y_int + image->
format->y_dec) - len) {
235 state->curr_y += coord;
237 state->curr_y = coord;
241 dprintf(
"... Found I code\n");
243 coord = gerb_fgetint(fd, &len);
246 switch ((image->
format->y_int + image->
format->y_dec) - len) {
266 state->delta_cp_x = coord;
270 dprintf(
"... Found J code\n");
272 coord = gerb_fgetint(fd, &len);
275 switch ((image->
format->y_int + image->
format->y_dec) - len) {
295 state->delta_cp_y = coord;
299 dprintf(
"... Found %% code\n");
301 parse_rs274x(levelOfRecursion, fd, image, state, curr_net, stats, directoryPath);
303 int c = gerb_fgetc(fd);
304 while ((c ==
'\n')||(c ==
'\r')||(c ==
' ')||(c ==
'\t')||(c == 0))
306 if(c == EOF || c ==
'%')
313 dprintf(
"... Found * code\n");
315 if (state->changed == 0)
break;
323 state->prev_x = state->curr_x;
324 state->prev_y = state->curr_y;
327 curr_net = gerber_create_new_net (curr_net, state->
layer, state->state);
332 if (image && image->
format ){
333 x_scale = pow(10.0, (
double)image->
format->x_dec);
334 y_scale = pow(10.0, (
double)image->
format->y_dec);
338 curr_net->
start_x = (double)state->prev_x / x_scale;
339 curr_net->
start_y = (
double)state->prev_y / y_scale;
340 curr_net->
stop_x = (double)state->curr_x / x_scale;
341 curr_net->
stop_y = (
double)state->curr_y / y_scale;
342 delta_cp_x = (double)state->delta_cp_x / x_scale;
343 delta_cp_y = (
double)state->delta_cp_y / y_scale;
344 switch (state->interpolation) {
346 curr_net->
cirseg = g_new0 (gerbv_cirseg_t,1);
348 calc_cirseg_mq(curr_net, 1, delta_cp_x, delta_cp_y);
350 calc_cirseg_sq(curr_net, 1, delta_cp_x, delta_cp_y);
353 curr_net->
cirseg = g_new0 (gerbv_cirseg_t,1);
355 calc_cirseg_mq(curr_net, 0, delta_cp_x, delta_cp_y);
357 calc_cirseg_sq(curr_net, 0, delta_cp_x, delta_cp_y);
363 state->parea_start_node = curr_net;
364 state->in_parea_fill = 1;
367 boundingBox.
left = HUGE_VAL;
368 boundingBox.
right = -HUGE_VAL;
369 boundingBox.
top = -HUGE_VAL;
370 boundingBox.
bottom = HUGE_VAL;
374 state->parea_start_node->boundingBox = boundingBox;
376 state->parea_start_node = NULL;
377 state->in_parea_fill = 0;
387 if (state->in_parea_fill && state->parea_start_node) {
401 curr_net = gerber_create_new_net (curr_net, state->
layer, state->state);
403 state->parea_start_node->boundingBox = boundingBox;
404 state->parea_start_node = curr_net;
406 curr_net = gerber_create_new_net (curr_net, state->
layer, state->state);
407 curr_net->
start_x = (double)state->prev_x / x_scale;
408 curr_net->
start_y = (
double)state->prev_y / y_scale;
409 curr_net->
stop_x = (double)state->curr_x / x_scale;
410 curr_net->
stop_y = (
double)state->curr_y / y_scale;
412 boundingBox.
left = HUGE_VAL;
413 boundingBox.
right = -HUGE_VAL;
414 boundingBox.
top = -HUGE_VAL;
415 boundingBox.
bottom = HUGE_VAL;
432 ((state->delta_cp_x == 0.0) && (state->delta_cp_y == 0.0)))
443 state->interpolation = state->prev_interpolation;
448 curr_net->
layer = state->layer;
450 state->delta_cp_x = 0.0;
451 state->delta_cp_y = 0.0;
452 curr_net->
aperture = state->curr_aperture;
459 state->prev_x = state->curr_x;
460 state->prev_y = state->curr_y;
466 if ((curr_net->
aperture == 0) && !state->in_parea_fill)
472 double repeat_off_X = 0.0, repeat_off_Y = 0.0;
475 if (!state->in_parea_fill) {
476 dprintf(
" In parse_D_code, adding 1 to D_list ...\n");
477 int retcode = gerbv_stats_increment_D_list_count(stats->D_code_list,
482 string = g_strdup_printf(_(
"Found undefined D code D%d in file \"%s\""),
485 gerbv_stats_add_error(stats->error_list,
502 repeat_off_X = (state->layer->stepAndRepeat.X - 1) *
503 state->layer->stepAndRepeat.dist_X;
504 repeat_off_Y = (state->layer->stepAndRepeat.Y - 1) *
505 state->layer->stepAndRepeat.dist_Y;
507 cairo_matrix_init (¤tMatrix, 1, 0, 0, 1, 0, 0);
509 cairo_matrix_translate (¤tMatrix, image->
info->offsetA,
510 image->
info->offsetB);
512 cairo_matrix_rotate (¤tMatrix, image->
info->imageRotation);
516 cairo_matrix_rotate (¤tMatrix, state->layer->rotation);
520 cairo_matrix_scale (¤tMatrix, state->state->scaleA,
521 state->state->scaleB);
523 cairo_matrix_translate (¤tMatrix, state->state->offsetA,
524 state->state->offsetB);
526 switch (state->state->mirrorState) {
527 case GERBV_MIRROR_STATE_FLIPA:
528 cairo_matrix_scale (¤tMatrix, -1, 1);
530 case GERBV_MIRROR_STATE_FLIPB:
531 cairo_matrix_scale (¤tMatrix, 1, -1);
533 case GERBV_MIRROR_STATE_FLIPAB:
534 cairo_matrix_scale (¤tMatrix, -1, -1);
540 if (state->state->axisSelect == GERBV_AXIS_SELECT_SWAPAB) {
544 cairo_matrix_rotate (¤tMatrix, 3 * M_PI / 2);
545 cairo_matrix_scale (¤tMatrix, 1, -1);
551 gerbv_simplified_amacro_t *ls = image->
aperture[curr_net->
aperture]->simplified;
554 gdouble offsetx = 0, offsety = 0, widthx = 0, widthy = 0;
555 gboolean calculatedAlready = FALSE;
558 offsetx=ls->parameter[CIRCLE_CENTER_X];
559 offsety=ls->parameter[CIRCLE_CENTER_Y];
560 widthx=widthy=ls->parameter[CIRCLE_DIAMETER];
562 int pointCounter,numberOfPoints;
563 numberOfPoints = (int) ls->parameter[OUTLINE_NUMBER_OF_POINTS];
565 for (pointCounter = 0; pointCounter <= numberOfPoints; pointCounter++) {
566 gerber_update_min_and_max (&boundingBox,
568 ls->parameter[pointCounter * 2 + OUTLINE_FIRST_X],
570 ls->parameter[pointCounter * 2 + OUTLINE_FIRST_Y],
573 calculatedAlready = TRUE;
575 offsetx = ls->parameter[POLYGON_CENTER_X];
576 offsety = ls->parameter[POLYGON_CENTER_Y];
577 widthx = widthy = ls->parameter[POLYGON_DIAMETER];
579 offsetx = ls->parameter[MOIRE_CENTER_X];
580 offsety = ls->parameter[MOIRE_CENTER_Y];
581 widthx = widthy = ls->parameter[MOIRE_OUTSIDE_DIAMETER];
583 offsetx = ls->parameter[THERMAL_CENTER_X];
584 offsety = ls->parameter[THERMAL_CENTER_Y];
585 widthx = widthy = ls->parameter[THERMAL_OUTSIDE_DIAMETER];
587 widthx = widthy = ls->parameter[LINE20_LINE_WIDTH];
588 gerber_update_min_and_max (&boundingBox,
590 ls->parameter[LINE20_START_X],
592 ls->parameter[LINE20_START_Y],
593 widthx/2,widthx/2,widthy/2,widthy/2);
594 gerber_update_min_and_max (&boundingBox,
596 ls->parameter[LINE20_END_X],
598 ls->parameter[LINE20_END_Y],
599 widthx/2,widthx/2,widthy/2,widthy/2);
600 calculatedAlready = TRUE;
602 gdouble largestDimension = sqrt (ls->parameter[LINE21_WIDTH]/2 *
603 ls->parameter[LINE21_WIDTH]/2 + ls->parameter[LINE21_HEIGHT/2] *
604 ls->parameter[LINE21_HEIGHT]/2);
606 offsetx = ls->parameter[LINE21_CENTER_X];
607 offsety = ls->parameter[LINE21_CENTER_Y];
608 widthx = widthy=largestDimension;
610 gdouble largestDimension = sqrt (ls->parameter[LINE22_WIDTH]/2 *
611 ls->parameter[LINE22_WIDTH]/2 + ls->parameter[LINE22_HEIGHT/2] *
612 ls->parameter[LINE22_HEIGHT]/2);
614 offsetx = ls->parameter[LINE22_LOWER_LEFT_X] +
615 ls->parameter[LINE22_WIDTH]/2;
616 offsety = ls->parameter[LINE22_LOWER_LEFT_Y] +
617 ls->parameter[LINE22_HEIGHT]/2;
618 widthx = widthy=largestDimension;
621 if (!calculatedAlready) {
622 gerber_update_min_and_max (&boundingBox,
623 curr_net->
stop_x + offsetx,
624 curr_net->
stop_y + offsety,
625 widthx/2,widthx/2,widthy/2,widthy/2);
636 aperture_sizeY = aperture_sizeX;
640 aperture_sizeX = aperture_sizeY = 0;
647 gdouble angleDiff = curr_net->
cirseg->angle2 - curr_net->
cirseg->angle1;
648 gint i, steps = abs(angleDiff);
649 for (i=0; i<=steps; i++){
650 gdouble tempX = curr_net->
cirseg->cp_x + curr_net->
cirseg->width / 2.0 *
651 cos ((curr_net->
cirseg->angle1 +
652 (angleDiff * i) / steps)*M_PI/180);
653 gdouble tempY = curr_net->
cirseg->cp_y + curr_net->
cirseg->width / 2.0 *
654 sin ((curr_net->
cirseg->angle1 +
655 (angleDiff * i) / steps)*M_PI/180);
656 gerber_update_min_and_max (&boundingBox,
658 aperture_sizeX/2,aperture_sizeX/2,
659 aperture_sizeY/2,aperture_sizeY/2);
669 gerber_update_min_and_max (&boundingBox,
671 aperture_sizeX/2,aperture_sizeX/2,
672 aperture_sizeY/2,aperture_sizeY/2);
674 gerber_update_min_and_max (&boundingBox,
676 aperture_sizeX/2,aperture_sizeX/2,
677 aperture_sizeY/2,aperture_sizeY/2);
684 gerber_update_image_min_max(&boundingBox, repeat_off_X, repeat_off_Y, image);
687 if (knockoutMeasure) {
688 if (boundingBox.
left < knockoutLimitXmin)
689 knockoutLimitXmin = boundingBox.
left;
690 if (boundingBox.
right+repeat_off_X > knockoutLimitXmax)
691 knockoutLimitXmax = boundingBox.
right+repeat_off_X;
692 if (boundingBox.
bottom < knockoutLimitYmin)
693 knockoutLimitYmin = boundingBox.
bottom;
694 if (boundingBox.
top+repeat_off_Y > knockoutLimitYmax)
695 knockoutLimitYmax = boundingBox.
top+repeat_off_Y;
698 if (!state->in_parea_fill) {
701 boundingBox.
left = HUGE_VAL;
702 boundingBox.
right = -HUGE_VAL;
703 boundingBox.
bottom = HUGE_VAL;
704 boundingBox.
top = -HUGE_VAL;
716 string = g_strdup_printf(_(
"Found unknown character (whitespace?) [%d]%c"),
718 gerbv_stats_add_error(stats->error_list,
739 gerb_state_t *state = NULL;
743 gboolean foundEOF = FALSE;
750 setlocale(LC_NUMERIC,
"C" );
756 state = g_new0 (gerb_state_t, 1);
763 GERB_FATAL_ERROR(_(
"malloc image failed"));
768 GERB_FATAL_ERROR(_(
"malloc gerbv_stats failed"));
772 state->layer = image->
layers;
773 state->state = image->
states;
774 curr_net->
layer = state->layer;
775 curr_net->
state = state->state;
780 dprintf(
"In parse_gerb, starting to parse file...\n");
785 string = g_strdup_printf(_(
"Missing Gerber EOF code in file \"%s\""), fd->filename);
786 gerbv_stats_add_error(stats->error_list,
794 dprintf(
" ... done parsing Gerber file\n");
795 gerber_update_any_running_knockout_measurements (image);
796 gerber_calculate_final_justify_effects(image);
813 gboolean found_binary = FALSE;
814 gboolean found_ADD = FALSE;
815 gboolean found_D0 = FALSE;
816 gboolean found_D2 = FALSE;
817 gboolean found_M0 = FALSE;
818 gboolean found_M2 = FALSE;
819 gboolean found_star = FALSE;
820 gboolean found_X = FALSE;
821 gboolean found_Y = FALSE;
823 dprintf (
"gerber_is_rs274x_p(%p, %p), fd->fd = %p\n", fd, returnFoundBinary, fd->fd);
824 buf = (
char *) g_malloc(MAXL);
826 GERB_FATAL_ERROR(_(
"malloc buf failed while checking for rs274x"));
828 while (fgets(buf, MAXL, fd->fd) != NULL) {
829 dprintf (
"buf = \"%s\"\n", buf);
836 for (i = 0; i < len; i++) {
837 if (!isprint((
int) buf[i]) && (buf[i] !=
'\r') &&
838 (buf[i] !=
'\n') && (buf[i] !=
'\t')) {
840 dprintf (
"found_binary (%d)\n", buf[i]);
843 if (g_strstr_len(buf, len,
"%ADD")) {
845 dprintf (
"found_ADD\n");
847 if (g_strstr_len(buf, len,
"D00") || g_strstr_len(buf, len,
"D0")) {
849 dprintf (
"found_D0\n");
851 if (g_strstr_len(buf, len,
"D02") || g_strstr_len(buf, len,
"D2")) {
853 dprintf (
"found_D2\n");
855 if (g_strstr_len(buf, len,
"M00") || g_strstr_len(buf, len,
"M0")) {
857 dprintf (
"found_M0\n");
859 if (g_strstr_len(buf, len,
"M02") || g_strstr_len(buf, len,
"M2")) {
861 dprintf (
"found_M2\n");
863 if (g_strstr_len(buf, len,
"*")) {
865 dprintf (
"found_star\n");
868 if ((letter = g_strstr_len(buf, len,
"X")) != NULL) {
869 if (isdigit((
int) letter[1])) {
871 dprintf (
"found_X\n");
874 if ((letter = g_strstr_len(buf, len,
"Y")) != NULL) {
875 if (isdigit((
int) letter[1])) {
877 dprintf (
"found_Y\n");
884 *returnFoundBinary = found_binary;
887 if ((found_D0 || found_D2 || found_M0 || found_M2) &&
888 found_ADD && found_star && (found_X || found_Y))
908 gboolean found_binary = FALSE;
909 gboolean found_ADD = FALSE;
910 gboolean found_D0 = FALSE;
911 gboolean found_D2 = FALSE;
912 gboolean found_M0 = FALSE;
913 gboolean found_M2 = FALSE;
914 gboolean found_star = FALSE;
915 gboolean found_X = FALSE;
916 gboolean found_Y = FALSE;
920 GERB_FATAL_ERROR(_(
"malloc buf failed while checking for rs274d"));
922 while (fgets(buf, MAXL, fd->fd) != NULL) {
928 for (i = 0; i < len; i++) {
929 if (!isprint( (
int) buf[i]) && (buf[i] !=
'\r') &&
930 (buf[i] !=
'\n') && (buf[i] !=
'\t')) {
935 if (g_strstr_len(buf, len,
"%ADD")) {
938 if (g_strstr_len(buf, len,
"D00") || g_strstr_len(buf, len,
"D0")) {
941 if (g_strstr_len(buf, len,
"D02") || g_strstr_len(buf, len,
"D2")) {
944 if (g_strstr_len(buf, len,
"M00") || g_strstr_len(buf, len,
"M0")) {
947 if (g_strstr_len(buf, len,
"M02") || g_strstr_len(buf, len,
"M2")) {
950 if (g_strstr_len(buf, len,
"*")) {
954 if ((letter = g_strstr_len(buf, len,
"X")) != NULL) {
956 if (isdigit( (
int) letter[1])) {
960 if ((letter = g_strstr_len(buf, len,
"Y")) != NULL) {
962 if (isdigit( (
int) letter[1])) {
971 if ((found_D0 || found_D2 || found_M0 || found_M2) &&
972 !found_ADD && found_star && (found_X || found_Y) &&
994 op_int=gerb_fgetint(fd, NULL);
1018 while ((c != EOF) && (c !=
'*')) {
1036 state->prev_interpolation = state->interpolation;
1048 if (gerb_fgetc(fd) ==
'D') {
1049 int a = gerb_fgetint(fd, NULL);
1050 if ((a >= 0) && (a <= APERTURE_MAX)) {
1051 state->curr_aperture = a;
1053 string = g_strdup_printf(_(
"Found aperture D%d out of bounds while parsing G code in file \"%s\""),
1055 gerbv_stats_add_error(stats->error_list,
1062 string = g_strdup_printf(_(
"Found unexpected code after G54 in file \"%s\""), fd->filename);
1063 gerbv_stats_add_error(stats->error_list,
1076 state->state = gerbv_image_return_new_netstate (state->state);
1081 state->state = gerbv_image_return_new_netstate (state->state);
1102 string = g_strdup_printf(_(
"Encountered unknown G code G%d in file \"%s\""), op_int, fd->filename);
1103 gerbv_stats_add_error(stats->error_list,
1108 string = g_strdup_printf(_(
"Ignorning unknown G code G%d"), op_int);
1109 gerbv_stats_add_error(stats->error_list,
1134 a = gerb_fgetint(fd, NULL);
1135 dprintf(
" In parse_D_code, found D number = %d ...\n", a);
1138 string = g_strdup_printf(_(
"Found invalid D00 code in file \"%s\""), fd->filename);
1139 gerbv_stats_add_error(stats->error_list,
1162 if ((a >= 0) && (a <= APERTURE_MAX)) {
1163 state->curr_aperture = a;
1166 string = g_strdup_printf(_(
"Found out of bounds aperture D%d in file \"%s\""),
1168 gerbv_stats_add_error(stats->error_list,
1191 op_int=gerb_fgetint(fd, NULL);
1204 string = g_strdup_printf(_(
"Encountered unknown M code M%d in file \"%s\""),
1205 op_int, fd->filename);
1206 gerbv_stats_add_error(stats->error_list,
1211 string = g_strdup_printf(_(
"Ignorning unknown M code M%d"), op_int);
1212 gerbv_stats_add_error(stats->error_list,
1225 parse_rs274x(gint levelOfRecursion, gerb_file_t *fd,
gerbv_image_t *image,
1227 gchar *directoryPath)
1232 gerbv_aperture_t *a = NULL;
1233 gerbv_amacro_t *tmp_amacro;
1235 gdouble scale = 1.0;
1241 op[0] = gerb_fgetc(fd);
1242 op[1] = gerb_fgetc(fd);
1244 if ((op[0] == EOF) || (op[1] == EOF)) {
1245 string = g_strdup_printf(_(
"Unexpected EOF found in file \"%s\""), fd->filename);
1246 gerbv_stats_add_error(stats->error_list,
1253 switch (A2I(op[0], op[1])){
1259 op[0] = gerb_fgetc(fd);
1260 op[1] = gerb_fgetc(fd);
1261 state->state = gerbv_image_return_new_netstate (state->state);
1263 if ((op[0] == EOF) || (op[1] == EOF)) {
1264 string = g_strdup_printf(_(
"Unexpected EOF found in file \"%s\""), fd->filename);
1265 gerbv_stats_add_error(stats->error_list,
1272 if (((op[0] ==
'A') && (op[1] ==
'Y')) ||
1273 ((op[0] ==
'B') && (op[1] ==
'X'))) {
1274 state->state->axisSelect = GERBV_AXIS_SELECT_SWAPAB;
1276 state->state->axisSelect = GERBV_AXIS_SELECT_NOSELECT;
1279 op[0] = gerb_fgetc(fd);
1280 op[1] = gerb_fgetc(fd);
1282 if ((op[0] == EOF) || (op[1] == EOF)) {
1283 string = g_strdup_printf(_(
"Unexpected EOF found in file \"%s\""), fd->filename);
1284 gerbv_stats_add_error(stats->error_list,
1291 if (((op[0] ==
'A') && (op[1] ==
'Y')) ||
1292 ((op[0] ==
'B') && (op[1] ==
'X'))) {
1293 state->state->axisSelect = GERBV_AXIS_SELECT_SWAPAB;
1295 state->state->axisSelect = GERBV_AXIS_SELECT_NOSELECT;
1302 switch (gerb_fgetc(fd)) {
1313 string = g_strdup_printf(_(
"EagleCad bug detected: Undefined handling of zeros in format code in file \"%s\""),
1315 gerbv_stats_add_error(stats->error_list,
1320 string = g_strdup_printf(_(
"Defaulting to omitting leading zeros"));
1321 gerbv_stats_add_error(stats->error_list,
1330 switch (gerb_fgetc(fd)) {
1338 string = g_strdup_printf(_(
"Invalid coordinate type defined in format code in file \"%s\""),
1340 gerbv_stats_add_error(stats->error_list,
1345 string = g_strdup_printf(_(
"Defaulting to absolute coordinates"));
1346 gerbv_stats_add_error(stats->error_list,
1353 op[0] = gerb_fgetc(fd);
1354 while((op[0] !=
'*')&&(op[0] != EOF)) {
1357 op[0] = (char)gerb_fgetc(fd);
1358 image->
format->lim_seqno = op[0] -
'0';
1361 op[0] = (char)gerb_fgetc(fd);
1362 image->
format->lim_gf = op[0] -
'0';
1365 op[0] = (char)gerb_fgetc(fd);
1366 image->
format->lim_pf = op[0] -
'0';
1369 op[0] = (char)gerb_fgetc(fd);
1370 image->
format->lim_mf = op[0] -
'0';
1373 op[0] = gerb_fgetc(fd);
1374 if ((op[0] <
'0') || (op[0] >
'6')) {
1375 string = g_strdup_printf(_(
"Illegal format size %c in file \"%s\""),
1376 (
char)op[0], fd->filename);
1377 gerbv_stats_add_error(stats->error_list,
1383 image->
format->x_int = op[0] -
'0';
1384 op[0] = gerb_fgetc(fd);
1385 if ((op[0] <
'0') || (op[0] >
'6')) {
1386 string = g_strdup_printf(_(
"Illegal format size %c in file \"%s\""),
1387 (
char)op[0], fd->filename);
1388 gerbv_stats_add_error(stats->error_list,
1394 image->
format->x_dec = op[0] -
'0';
1397 op[0] = gerb_fgetc(fd);
1398 if ((op[0] <
'0') || (op[0] >
'6')) {
1399 string = g_strdup_printf(_(
"Illegal format size %c in file \"%s\""),
1400 (
char)op[0], fd->filename);
1401 gerbv_stats_add_error(stats->error_list,
1407 image->
format->y_int = op[0] -
'0';
1408 op[0] = gerb_fgetc(fd);
1409 if ((op[0] <
'0') || (op[0] >
'6')) {
1410 string = g_strdup_printf(_(
"Illegal format size %c in file \"%s\""),
1411 (
char)op[0], fd->filename);
1412 gerbv_stats_add_error(stats->error_list,
1418 image->
format->y_dec = op[0] -
'0';
1421 string = g_strdup_printf(_(
"Illegal format statement [%c] in file \"%s\""),
1422 op[0], fd->filename);
1423 gerbv_stats_add_error(stats->error_list,
1428 string = g_strdup_printf(_(
"Ignoring invalid format statement"));
1429 gerbv_stats_add_error(stats->error_list,
1435 op[0] = gerb_fgetc(fd);
1439 op[0] = gerb_fgetc(fd);
1440 state->state = gerbv_image_return_new_netstate (state->state);
1442 while ((op[0] !=
'*')&&(op[0] != EOF)) {
1446 readValue = gerb_fgetint(fd, NULL);
1447 if (readValue == 1) {
1448 if (state->state->mirrorState == GERBV_MIRROR_STATE_FLIPB)
1449 state->state->mirrorState=GERBV_MIRROR_STATE_FLIPAB;
1451 state->state->mirrorState=GERBV_MIRROR_STATE_FLIPA;
1455 readValue = gerb_fgetint(fd, NULL);
1456 if (readValue == 1) {
1457 if (state->state->mirrorState == GERBV_MIRROR_STATE_FLIPA)
1458 state->state->mirrorState=GERBV_MIRROR_STATE_FLIPAB;
1460 state->state->mirrorState=GERBV_MIRROR_STATE_FLIPB;
1464 string = g_strdup_printf(_(
"Wrong character in mirror: %c"), op[0]);
1465 gerbv_stats_add_error(stats->error_list,
1471 op[0] = gerb_fgetc(fd);
1475 op[0] = gerb_fgetc(fd);
1476 op[1] = gerb_fgetc(fd);
1478 if ((op[0] == EOF) || (op[1] == EOF))
1479 gerbv_stats_add_error(stats->error_list,
1481 _(
"Unexpected EOF found"),
1483 switch (A2I(op[0],op[1])) {
1485 state->state = gerbv_image_return_new_netstate (state->state);
1489 state->state = gerbv_image_return_new_netstate (state->state);
1493 string = g_strdup_printf(_(
"Illegal unit: %c%c"), op[0], op[1]);
1494 gerbv_stats_add_error(stats->error_list,
1502 op[0] = gerb_fgetc(fd);
1504 while ((op[0] !=
'*')&&(op[0] != EOF)) {
1507 state->state->offsetA = gerb_fgetdouble(fd) / scale;
1510 state->state->offsetB = gerb_fgetdouble(fd) / scale;
1513 string = g_strdup_printf(_(
"Wrong character in offset: %c"), op[0]);
1514 gerbv_stats_add_error(stats->error_list,
1520 op[0] = gerb_fgetc(fd);
1525 gchar *includeFilename = gerb_fgetstring(fd,
'*');
1527 if (includeFilename) {
1529 if (!g_path_is_absolute(includeFilename)) {
1530 fullPath = g_build_filename (directoryPath, includeFilename, NULL);
1532 fullPath = g_strdup (includeFilename);
1534 if (levelOfRecursion < 10) {
1535 gerb_file_t *includefd = NULL;
1537 includefd = gerb_fopen(fullPath);
1540 gerb_fclose(includefd);
1542 string = g_strdup_printf(_(
"In file \"%s\", included file \"%s\" cannot be found"),
1543 fd->filename, fullPath);
1544 gerbv_stats_add_error(stats->error_list,
1552 string = g_strdup_printf(_(
"Parser encountered more than 10 levels of include file recursion which is not allowed by the RS-274X spec"));
1553 gerbv_stats_add_error(stats->error_list,
1564 op[0] = gerb_fgetc(fd);
1566 while ((op[0] !=
'*')&&(op[0] != EOF)) {
1569 image->
info->offsetA = gerb_fgetdouble(fd) / scale;
1572 image->
info->offsetB = gerb_fgetdouble(fd) / scale;
1575 string = g_strdup_printf(_(
"Wrong character in image offset %c in file \"%s\""),
1576 op[0], fd->filename);
1577 gerbv_stats_add_error(stats->error_list,
1583 op[0] = gerb_fgetc(fd);
1587 state->state = gerbv_image_return_new_netstate (state->state);
1588 if (gerb_fgetc(fd) ==
'A')
1589 state->state->
scaleA = gerb_fgetdouble(fd);
1592 if (gerb_fgetc(fd) ==
'B')
1593 state->state->scaleB = gerb_fgetdouble(fd);
1603 op[0] = gerb_fgetc(fd);
1604 op[1] = gerb_fgetc(fd);
1606 if ((op[0] == EOF) || (op[1] == EOF)) {
1607 string = g_strdup_printf(_(
"Unexpected EOF found in file \"%s\""), fd->filename);
1608 gerbv_stats_add_error(stats->error_list,
1614 switch (A2I(op[0],op[1])) {
1616 image->info->encoding = GERBV_ENCODING_ASCII;
1619 image->info->encoding = GERBV_ENCODING_EBCDIC;
1622 image->info->encoding = GERBV_ENCODING_BCD;
1625 image->info->encoding = GERBV_ENCODING_ISO_ASCII;
1628 image->info->encoding = GERBV_ENCODING_EIA;
1631 string = g_strdup_printf(_(
"Unknown input code (IC): %c%c in file \"%s\""),
1632 op[0], op[1], fd->filename);
1633 gerbv_stats_add_error(stats->error_list,
1643 op[0] = gerb_fgetc(fd);
1644 image->
info->imageJustifyTypeA = GERBV_JUSTIFY_LOWERLEFT;
1645 image->
info->imageJustifyTypeB = GERBV_JUSTIFY_LOWERLEFT;
1646 image->
info->imageJustifyOffsetA = 0.0;
1647 image->
info->imageJustifyOffsetB = 0.0;
1648 while ((op[0] !=
'*')&&(op[0] != EOF)) {
1651 op[0] = gerb_fgetc(fd);
1653 image->
info->imageJustifyTypeA = GERBV_JUSTIFY_CENTERJUSTIFY;
1654 }
else if (op[0] ==
'L') {
1655 image->
info->imageJustifyTypeA = GERBV_JUSTIFY_LOWERLEFT;
1658 image->
info->imageJustifyOffsetA = gerb_fgetdouble(fd) / scale;
1662 op[0] = gerb_fgetc(fd);
1664 image->
info->imageJustifyTypeB = GERBV_JUSTIFY_CENTERJUSTIFY;
1665 }
else if (op[0] ==
'L') {
1666 image->
info->imageJustifyTypeB = GERBV_JUSTIFY_LOWERLEFT;
1669 image->
info->imageJustifyOffsetB = gerb_fgetdouble(fd) / scale;
1673 string = g_strdup_printf(_(
"Wrong character %c in image justify in file \"%s\""),
1674 op[0], fd->filename);
1675 gerbv_stats_add_error(stats->error_list,
1681 op[0] = gerb_fgetc(fd);
1685 image->info->name = gerb_fgetstring(fd,
'*');
1689 for (ano = 0; ano < 3; ano++) {
1690 op[0] = gerb_fgetc(fd);
1692 string = g_strdup_printf(_(
"Unexpected EOF while reading image polarity (IP) in file \"%s\""),
1694 gerbv_stats_add_error(stats->error_list,
1700 str[ano] = (char)op[0];
1703 if (strncmp(str,
"POS", 3) == 0)
1705 else if (strncmp(str,
"NEG", 3) == 0)
1708 string = g_strdup_printf(_(
"Unknown polarity: %c%c%c"), str[0], str[1], str[2]);
1709 gerbv_stats_add_error(stats->error_list,
1717 tmp = gerb_fgetint(fd, NULL) % 360;
1719 image->
info->imageRotation = 0.0;
1721 image->
info->imageRotation = M_PI / 2.0;
1722 else if (tmp == 180)
1723 image->
info->imageRotation = M_PI;
1724 else if (tmp == 270)
1725 image->
info->imageRotation = 3.0 * M_PI / 2.0;
1727 string = g_strdup_printf(_(
"Image rotation must be 0, 90, 180 or 270 (is actually %d)"), tmp);
1728 gerbv_stats_add_error(stats->error_list,
1736 image->info->plotterFilm = gerb_fgetstring(fd,
'*');
1741 a = (gerbv_aperture_t *) g_new0 (gerbv_aperture_t,1);
1743 ano = parse_aperture_definition(fd, a, image, scale);
1747 else if ((ano >= 0) && (ano <= APERTURE_MAX)) {
1748 a->unit = state->state->unit;
1750 dprintf(
" In parse_rs274x, adding new aperture to aperture list ...\n");
1751 gerbv_stats_add_aperture(stats->aperture_list,
1755 gerbv_stats_add_to_D_list(stats->D_code_list,
1757 if (ano < APERTURE_MIN) {
1758 string = g_strdup_printf(_(
"Aperture number out of bounds %d in file \"%s\""),
1763 string = g_strdup_printf(_(
"Aperture number out of bounds %d in file \"%s\""),
1765 gerbv_stats_add_error(stats->error_list,
1775 tmp_amacro = image->amacro;
1776 image->
amacro = parse_aperture_macro(fd);
1778 image->
amacro->next = tmp_amacro;
1780 print_program(image->
amacro);
1783 string = g_strdup_printf(_(
"Failed to parse aperture macro in file \"%s\""),
1785 gerbv_stats_add_error(stats->error_list,
1795 state->layer = gerbv_image_return_new_layer (state->layer);
1796 state->layer->
name = gerb_fgetstring(fd,
'*');
1799 state->layer = gerbv_image_return_new_layer (state->layer);
1800 switch (gerb_fgetc(fd)) {
1808 string = g_strdup_printf(_(
"Unknown Layer Polarity %c in file \"%s\""),
1809 op[0], fd->filename);
1810 gerbv_stats_add_error(stats->error_list,
1818 state->layer = gerbv_image_return_new_layer (state->layer);
1819 gerber_update_any_running_knockout_measurements (image);
1821 knockoutMeasure = FALSE;
1822 op[0] = gerb_fgetc(fd);
1824 state->layer->knockout.type = GERBV_KNOCKOUT_TYPE_NOKNOCKOUT;
1826 }
else if (op[0] ==
'C') {
1828 }
else if (op[0] ==
'D') {
1831 string = g_strdup_printf(_(
"Knockout must supply a polarity (C, D, or *) in file \"%s\""),
1833 gerbv_stats_add_error(stats->error_list,
1839 state->layer->knockout.lowerLeftX = 0.0;
1840 state->layer->knockout.lowerLeftY = 0.0;
1841 state->layer->knockout.width = 0.0;
1842 state->layer->knockout.height = 0.0;
1843 state->layer->knockout.border = 0.0;
1844 state->layer->knockout.firstInstance = TRUE;
1845 op[0] = gerb_fgetc(fd);
1846 while ((op[0] !=
'*')&&(op[0] != EOF)) {
1849 state->layer->knockout.type = GERBV_KNOCKOUT_TYPE_FIXEDKNOCK;
1850 state->layer->knockout.lowerLeftX = gerb_fgetdouble(fd) / scale;
1853 state->layer->knockout.type = GERBV_KNOCKOUT_TYPE_FIXEDKNOCK;
1854 state->layer->knockout.lowerLeftY = gerb_fgetdouble(fd) / scale;
1857 state->layer->knockout.type = GERBV_KNOCKOUT_TYPE_FIXEDKNOCK;
1858 state->layer->knockout.width = gerb_fgetdouble(fd) / scale;
1861 state->layer->knockout.type = GERBV_KNOCKOUT_TYPE_FIXEDKNOCK;
1862 state->layer->knockout.height = gerb_fgetdouble(fd) / scale;
1865 state->layer->knockout.type = GERBV_KNOCKOUT_TYPE_BORDER;
1866 state->layer->knockout.border = gerb_fgetdouble(fd) / scale;
1869 knockoutMeasure = TRUE;
1870 knockoutLimitXmin = HUGE_VAL;
1871 knockoutLimitYmin = HUGE_VAL;
1872 knockoutLimitXmax = -HUGE_VAL;
1873 knockoutLimitYmax = -HUGE_VAL;
1874 knockoutLayer = state->layer;
1877 string = g_strdup_printf(_(
"Unknown variable in knockout in file \"%s\""),
1879 gerbv_stats_add_error(stats->error_list,
1885 op[0] = gerb_fgetc(fd);
1890 state->layer = gerbv_image_return_new_layer (state->layer);
1891 op[0] = gerb_fgetc(fd);
1893 state->layer->stepAndRepeat.X = 1;
1894 state->layer->stepAndRepeat.Y = 1;
1895 state->layer->stepAndRepeat.dist_X = 0.0;
1896 state->layer->stepAndRepeat.dist_Y = 0.0;
1899 while ((op[0] !=
'*')&&(op[0] != EOF)) {
1902 state->layer->stepAndRepeat.X = gerb_fgetint(fd, NULL);
1905 state->layer->stepAndRepeat.Y = gerb_fgetint(fd, NULL);
1908 state->layer->stepAndRepeat.dist_X = gerb_fgetdouble(fd) / scale;
1911 state->layer->stepAndRepeat.dist_Y = gerb_fgetdouble(fd) / scale;
1914 string = g_strdup_printf(_(
"Step-and-repeat parameter error in file \"%s\""),
1916 gerbv_stats_add_error(stats->error_list,
1928 if(state->layer->stepAndRepeat.X == 0)
1929 state->layer->stepAndRepeat.X = 1;
1930 if(state->layer->stepAndRepeat.Y == 0)
1931 state->layer->stepAndRepeat.Y = 1;
1933 op[0] = gerb_fgetc(fd);
1938 state->layer = gerbv_image_return_new_layer (state->layer);
1940 state->layer->
rotation = gerb_fgetdouble(fd) * M_PI / 180;
1941 op[0] = gerb_fgetc(fd);
1943 string = g_strdup_printf(_(
"Error in layer rotation command in file \"%s\""),
1945 gerbv_stats_add_error(stats->error_list,
1953 string = g_strdup_printf(_(
"Unknown RS-274X extension found %%%c%c%% in file \"%s\""),
1954 op[0], op[1], fd->filename);
1955 gerbv_stats_add_error(stats->error_list,
1964 int c = gerb_fgetc(fd);
1965 while ((c != EOF) && (c !=
'*'))
1981 static macro_stack_t *
1982 new_stack(
unsigned int stack_size)
1986 s = (macro_stack_t *) g_new0 (macro_stack_t,1);
1987 s->stack = (
double *) g_new0 (
double, stack_size);
1994 free_stack(macro_stack_t *s)
2007 push(macro_stack_t *s,
double val)
2009 s->stack[s->sp++] = val;
2015 pop(macro_stack_t *s,
double *value)
2022 *value = s->stack[--s->sp];
2029 simplify_aperture_macro(gerbv_aperture_t *aperture, gdouble scale)
2031 const int extra_stack_size = 10;
2033 gerbv_instruction_t *ip;
2034 int handled = 1, nuf_parameters = 0, i, j, clearOperatorUsed = FALSE;
2036 double tmp[2] = {0.0, 0.0};
2038 gerbv_simplified_amacro_t *sam;
2040 if (aperture == NULL)
2041 GERB_FATAL_ERROR(_(
"aperture NULL in simplify aperture macro"));
2043 if (aperture->amacro == NULL)
2044 GERB_FATAL_ERROR(_(
"aperture->amacro NULL in simplify aperture macro"));
2047 s = new_stack(aperture->amacro->nuf_push + extra_stack_size);
2049 GERB_FATAL_ERROR(_(
"malloc stack failed"));
2052 lp = g_new (
double,APERTURE_PARAMETERS_MAX);
2054 memcpy(lp, aperture->parameter,
sizeof(
double) * APERTURE_PARAMETERS_MAX);
2056 for(ip = aperture->amacro->program; ip != NULL; ip = ip->next) {
2057 switch(ip->opcode) {
2061 push(s, ip->data.fval);
2064 push(s, lp[ip->data.ival - 1]);
2067 if (pop(s, &tmp[0]) < 0)
2068 GERB_FATAL_ERROR(_(
"Tried to pop an empty stack"));
2069 lp[ip->data.ival - 1] = tmp[0];
2072 if (pop(s, &tmp[0]) < 0)
2073 GERB_FATAL_ERROR(_(
"Tried to pop an empty stack"));
2074 if (pop(s, &tmp[1]) < 0)
2075 GERB_FATAL_ERROR(_(
"Tried to pop an empty stack"));
2076 push(s, tmp[1] + tmp[0]);
2079 if (pop(s, &tmp[0]) < 0)
2080 GERB_FATAL_ERROR(_(
"Tried to pop an empty stack"));
2081 if (pop(s, &tmp[1]) < 0)
2082 GERB_FATAL_ERROR(_(
"Tried to pop an empty stack"));
2083 push(s, tmp[1] - tmp[0]);
2086 if (pop(s, &tmp[0]) < 0)
2087 GERB_FATAL_ERROR(_(
"Tried to pop an empty stack"));
2088 if (pop(s, &tmp[1]) < 0)
2089 GERB_FATAL_ERROR(_(
"Tried to pop an empty stack"));
2090 push(s, tmp[1] * tmp[0]);
2093 if (pop(s, &tmp[0]) < 0)
2094 GERB_FATAL_ERROR(_(
"Tried to pop an empty stack"));
2095 if (pop(s, &tmp[1]) < 0)
2096 GERB_FATAL_ERROR(_(
"Tried to pop an empty stack"));
2097 push(s, tmp[1] / tmp[0]);
2105 switch(ip->data.ival) {
2107 dprintf(
" Aperture macro circle [1] (");
2114 dprintf(
" Aperture macro outline [4] (");
2122 nuf_parameters = ((int)s->stack[1] + 1) * 2 + 3;
2125 dprintf(
" Aperture macro polygon [5] (");
2130 dprintf(
" Aperture macro moiré [6] (");
2135 dprintf(
" Aperture macro thermal [7] (");
2141 dprintf(
" Aperture macro line 20/2 (");
2146 dprintf(
" Aperture macro line 21 (");
2151 dprintf(
" Aperture macro line 22 (");
2160 if (nuf_parameters > APERTURE_PARAMETERS_MAX) {
2161 GERB_COMPILE_ERROR(_(
"Number of parameters to aperture macro (%d) "
2162 "are more than gerbv is able to store (%d)"),
2163 nuf_parameters, APERTURE_PARAMETERS_MAX);
2164 nuf_parameters = APERTURE_PARAMETERS_MAX;
2171 sam = g_new (gerbv_simplified_amacro_t, 1);
2174 memset(sam->parameter, 0,
2175 sizeof(
double) * APERTURE_PARAMETERS_MAX);
2176 memcpy(sam->parameter, s->stack,
2177 sizeof(
double) * nuf_parameters);
2182 if (fabs(sam->parameter[0]) < 0.001)
2183 clearOperatorUsed = TRUE;
2184 sam->parameter[1]/=scale;
2185 sam->parameter[2]/=scale;
2186 sam->parameter[3]/=scale;
2189 if (fabs(sam->parameter[0]) < 0.001)
2190 clearOperatorUsed = TRUE;
2191 for (j=2; j<nuf_parameters-1; j++){
2192 sam->parameter[j]/=scale;
2196 if (fabs(sam->parameter[0]) < 0.001)
2197 clearOperatorUsed = TRUE;
2198 sam->parameter[2]/=scale;
2199 sam->parameter[3]/=scale;
2200 sam->parameter[4]/=scale;
2203 sam->parameter[0]/=scale;
2204 sam->parameter[1]/=scale;
2205 sam->parameter[2]/=scale;
2206 sam->parameter[3]/=scale;
2207 sam->parameter[4]/=scale;
2208 sam->parameter[6]/=scale;
2209 sam->parameter[7]/=scale;
2212 sam->parameter[0]/=scale;
2213 sam->parameter[1]/=scale;
2214 sam->parameter[2]/=scale;
2215 sam->parameter[3]/=scale;
2216 sam->parameter[4]/=scale;
2219 if (fabs(sam->parameter[0]) < 0.001)
2220 clearOperatorUsed = TRUE;
2221 sam->parameter[1]/=scale;
2222 sam->parameter[2]/=scale;
2223 sam->parameter[3]/=scale;
2224 sam->parameter[4]/=scale;
2225 sam->parameter[5]/=scale;
2229 if (fabs(sam->parameter[0]) < 0.001)
2230 clearOperatorUsed = TRUE;
2231 sam->parameter[1]/=scale;
2232 sam->parameter[2]/=scale;
2233 sam->parameter[3]/=scale;
2234 sam->parameter[4]/=scale;
2244 if (aperture->simplified == NULL) {
2245 aperture->simplified = sam;
2247 gerbv_simplified_amacro_t *tmp_sam;
2248 tmp_sam = aperture->simplified;
2249 while (tmp_sam->next != NULL) {
2250 tmp_sam = tmp_sam->next;
2252 tmp_sam->next = sam;
2256 for (i = 0; i < nuf_parameters; i++) {
2257 dprintf(
"%f, ", s->stack[i]);
2280 aperture->parameter[0]= (gdouble) clearOperatorUsed;
2287 parse_aperture_definition(gerb_file_t *fd, gerbv_aperture_t *aperture,
2293 gerbv_amacro_t *curr_amacro;
2294 gerbv_amacro_t *amacro = image->
amacro;
2299 if (gerb_fgetc(fd) !=
'D') {
2300 string = g_strdup_printf(_(
"Found AD code with no following 'D' in file \"%s\""),
2302 gerbv_stats_add_error(stats->error_list,
2313 ano = gerb_fgetint(fd, NULL);
2318 ad = gerb_fgetstring(fd,
'*');
2319 token = strtok(ad,
",");
2321 if (token == NULL) {
2322 string = g_strdup_printf(_(
"Invalid aperture definition in file \"%s\""),
2324 gerbv_stats_add_error(stats->error_list,
2331 if (strlen(token) == 1) {
2353 curr_amacro = amacro;
2354 while (curr_amacro) {
2355 if ((strlen(curr_amacro->name) == strlen(token)) &&
2356 (strcmp(curr_amacro->name, token) == 0)) {
2357 aperture->amacro = curr_amacro;
2360 curr_amacro = curr_amacro->next;
2367 for (token = strtok(NULL,
"X"), i = 0; token != NULL;
2368 token = strtok(NULL,
"X"), i++) {
2369 if (i == APERTURE_PARAMETERS_MAX) {
2370 string = g_strdup_printf(_(
"Maximum number of allowed parameters exceeded in aperture %d in file \"%s\""),
2372 gerbv_stats_add_error(stats->error_list,
2381 tempHolder = strtod(token, NULL);
2386 tempHolder /= scale;
2389 aperture->parameter[i] = tempHolder;
2391 string = g_strdup_printf(_(
"Failed to read all parameters exceeded in aperture %d"), ano);
2392 gerbv_stats_add_error(stats->error_list,
2397 aperture->parameter[i] = 0.0;
2401 aperture->nuf_parameters = i;
2406 dprintf(
"Simplifying aperture %d using aperture macro \"%s\"\n", ano,
2407 aperture->amacro->name);
2408 simplify_aperture_macro(aperture, scale);
2409 dprintf(
"Done simplifying\n");
2420 calc_cirseg_sq(
struct gerbv_net *net,
int cw,
2421 double delta_cp_x,
double delta_cp_y)
2423 double d1x, d1y, d2x, d2y;
2466 GERB_COMPILE_ERROR(_(
"Unknow quadrant value while converting to cw"));
2491 GERB_COMPILE_ERROR(_(
"Strange quadrant: %d"), quadrant);
2502 alfa = atan2(d1y, d1x);
2503 beta = atan2(d2y, d2x);
2508 net->
cirseg->width = alfa < beta ?
2509 2 * (d1x / cos(alfa)) : 2 * (d2x / cos(beta));
2510 net->
cirseg->height = alfa > beta ?
2511 2 * (d1y / sin(alfa)) : 2 * (d2y / sin(beta));
2513 if (alfa < 0.000001 && beta < 0.000001) {
2517 #define RAD2DEG(a) (a * 180 / M_PI)
2521 net->
cirseg->angle1 = RAD2DEG(alfa);
2522 net->
cirseg->angle2 = RAD2DEG(beta);
2525 net->
cirseg->angle1 = 180.0 - RAD2DEG(alfa);
2526 net->
cirseg->angle2 = 180.0 - RAD2DEG(beta);
2529 net->
cirseg->angle1 = 180.0 + RAD2DEG(alfa);
2530 net->
cirseg->angle2 = 180.0 + RAD2DEG(beta);
2533 net->
cirseg->angle1 = 360.0 - RAD2DEG(alfa);
2534 net->
cirseg->angle2 = 360.0 - RAD2DEG(beta);
2537 GERB_COMPILE_ERROR(_(
"Strange quadrant: %d"), quadrant);
2540 if (net->
cirseg->width < 0.0)
2541 GERB_COMPILE_WARNING(_(
"Negative width [%f] in quadrant %d [%f][%f]"),
2542 net->
cirseg->width, quadrant, alfa, beta);
2544 if (net->
cirseg->height < 0.0)
2545 GERB_COMPILE_WARNING(_(
"Negative height [%f] in quadrant %d [%f][%f]"),
2546 net->
cirseg->height, quadrant, RAD2DEG(alfa), RAD2DEG(beta));
2555 calc_cirseg_mq(
struct gerbv_net *net,
int cw,
2556 double delta_cp_x,
double delta_cp_y)
2558 double d1x, d1y, d2x, d2y;
2572 alfa = atan2(d1y, d1x);
2573 beta = atan2(d2y, d2x);
2575 net->
cirseg->width = sqrt(delta_cp_x*delta_cp_x + delta_cp_y*delta_cp_y);
2576 net->
cirseg->width *= 2.0;
2579 net->
cirseg->angle1 = RAD2DEG(alfa);
2580 net->
cirseg->angle2 = RAD2DEG(beta);
2585 if (net->
cirseg->angle1 < 0.0) {
2586 net->
cirseg->angle1 += 360.0;
2587 net->
cirseg->angle2 += 360.0;
2590 if (net->
cirseg->angle2 < 0.0)
2591 net->
cirseg->angle2 += 360.0;
2593 if(net->
cirseg->angle2 == 0.0)
2594 net->
cirseg->angle2 = 360.0;
2605 net->
cirseg->angle2 -= 360.0;
2608 net->
cirseg->angle2 += 360.0;
2616 gerber_update_any_running_knockout_measurements (
gerbv_image_t *image)
2618 if (knockoutMeasure) {
2619 knockoutLayer->
knockout.lowerLeftX = knockoutLimitXmin;
2620 knockoutLayer->
knockout.lowerLeftY = knockoutLimitYmin;
2621 knockoutLayer->
knockout.width = knockoutLimitXmax - knockoutLimitXmin;
2622 knockoutLayer->
knockout.height = knockoutLimitYmax - knockoutLimitYmin;
2623 knockoutMeasure = FALSE;
2629 gerber_calculate_final_justify_effects(
gerbv_image_t *image)
2631 gdouble translateA = 0.0, translateB = 0.0;
2633 if (image->
info->imageJustifyTypeA != GERBV_JUSTIFY_NOJUSTIFY) {
2634 if (image->
info->imageJustifyTypeA == GERBV_JUSTIFY_CENTERJUSTIFY)
2635 translateA = (image->
info->max_x - image->
info->min_x) / 2.0;
2637 translateA = -image->
info->min_x;
2639 if (image->
info->imageJustifyTypeB != GERBV_JUSTIFY_NOJUSTIFY) {
2640 if (image->
info->imageJustifyTypeB == GERBV_JUSTIFY_CENTERJUSTIFY)
2641 translateB = (image->
info->max_y - image->
info->min_y) / 2.0;
2643 translateB = -image->
info->min_y;
2648 image->
info->min_x += translateA+ image->
info->imageJustifyOffsetA;
2649 image->
info->max_x += translateA+ image->
info->imageJustifyOffsetA;
2650 image->
info->min_y += translateB+ image->
info->imageJustifyOffsetB;
2651 image->
info->max_y += translateB+ image->
info->imageJustifyOffsetB;
2655 image->
info->imageJustifyOffsetActualA = translateA +
2656 image->
info->imageJustifyOffsetA;
2657 image->
info->imageJustifyOffsetActualB = translateB +
2658 image->
info->imageJustifyOffsetB;
2664 if (boundingBox->
left < image->
info->min_x)
2665 image->
info->min_x = boundingBox->
left;
2666 if (boundingBox->
right+repeat_off_X > image->
info->max_x)
2667 image->
info->max_x = boundingBox->
right+repeat_off_X;
2668 if (boundingBox->
bottom < image->
info->min_y)
2670 if (boundingBox->
top+repeat_off_Y > image->
info->max_y)
2671 image->
info->max_y = boundingBox->
top+repeat_off_Y;
2676 gdouble x, gdouble y, gdouble apertureSizeX1,
2677 gdouble apertureSizeX2,gdouble apertureSizeY1,
2678 gdouble apertureSizeY2)
2680 gdouble ourX1 = x - apertureSizeX1, ourY1 = y - apertureSizeY1;
2681 gdouble ourX2 = x + apertureSizeX2, ourY2 = y + apertureSizeY2;
2687 cairo_matrix_transform_point (¤tMatrix, &ourX1, &ourY1);
2688 cairo_matrix_transform_point (¤tMatrix, &ourX2, &ourY2);
2692 if(boundingBox->
left > ourX1)
2693 boundingBox->
left = ourX1;
2694 if(boundingBox->
left > ourX2)
2695 boundingBox->
left = ourX2;
2696 if(boundingBox->
right < ourX1)
2697 boundingBox->
right = ourX1;
2698 if(boundingBox->
right < ourX2)
2699 boundingBox->
right = ourX2;
2700 if(boundingBox->
bottom > ourY1)
2701 boundingBox->
bottom = ourY1;
2702 if(boundingBox->
bottom > ourY2)
2703 boundingBox->
bottom = ourY2;
2704 if(boundingBox->
top < ourY1)
2705 boundingBox->
top = ourY1;
2706 if(boundingBox->
top < ourY2)
2707 boundingBox->
top = ourY2;