staticvoidparse_G_code(gerb_file_t*fd,gerb_state_t*state,gerbv_image_t*image,longint*line_num_p){int op_int;gerbv_format_t*format = image->format;gerbv_stats_t*stats = image->gerbv_stats;gerbv_error_list_t*error_list = stats->error_list;int c;
op_int=gerb_fgetint(fd,NULL);/* Emphasize text with new line '\n' in the beginning */dprintf("\n Found G%02d at line %ld (%s)\n",
op_int,*line_num_p,gerber_g_code_name(op_int));switch(op_int){case0:/* Move *//* Is this doing anything really? */
stats->G0++;break;case1:/* Linear Interpolation (1X scale) */
state->interpolation = GERBV_INTERPOLATION_LINEARx1;
stats->G1++;break;case2:/* Clockwise Linear Interpolation */
state->interpolation = GERBV_INTERPOLATION_CW_CIRCULAR;
stats->G2++;break;case3:/* Counter Clockwise Linear Interpolation */
state->interpolation = GERBV_INTERPOLATION_CCW_CIRCULAR;
stats->G3++;break;case4:/* Ignore Data Block *//* Don't do anything, just read 'til * *//* SDB asks: Should we look for other codes while reading G04 in case
* user forgot to put * at end of comment block? */do{
c =gerb_fgetc(fd);}while(c !=EOF&& c !='*');
stats->G4++;break;case10:/* Linear Interpolation (10X scale) */
state->interpolation = GERBV_INTERPOLATION_LINEARx10;
stats->G10++;break;case11:/* Linear Interpolation (0.1X scale) */
state->interpolation = GERBV_INTERPOLATION_LINEARx01;
stats->G11++;break;case12:/* Linear Interpolation (0.01X scale) */
state->interpolation = GERBV_INTERPOLATION_LINEARx001;
stats->G12++;break;case36:/* Turn on Polygon Area Fill */
state->prev_interpolation = state->interpolation;
state->interpolation = GERBV_INTERPOLATION_PAREA_START;
state->changed =1;
stats->G36++;break;case37:/* Turn off Polygon Area Fill */
state->interpolation = GERBV_INTERPOLATION_PAREA_END;
state->changed =1;
stats->G37++;break;case54:/* Tool prepare *//* XXX Maybe uneccesary??? */if(gerb_fgetc(fd)=='D'){int a =gerb_fgetint(fd,NULL);if((a >=0)&&(a <= APERTURE_MAX)){
state->curr_aperture = a;}else{gerbv_stats_printf(error_list, GERBV_MESSAGE_ERROR,-1,_("Found aperture D%02d out of bounds while parsing ""G code at line %ld in file \"%s\""),
a,*line_num_p, fd->filename);}}else{gerbv_stats_printf(error_list, GERBV_MESSAGE_ERROR,-1,_("Found unexpected code after G54 ""at line %ld in file \"%s\""),*line_num_p, fd->filename);/* TODO: insert error count here */}
stats->G54++;break;case55:/* Prepare for flash */
stats->G55++;break;case70:/* Specify inches */
state->state =gerbv_image_return_new_netstate(state->state);
state->state->unit = GERBV_UNIT_INCH;
stats->G70++;break;case71:/* Specify millimeters */
state->state =gerbv_image_return_new_netstate(state->state);
state->state->unit = GERBV_UNIT_MM;
stats->G71++;break;case74:/* Disable 360 circular interpolation */
state->mq_on =0;
stats->G74++;break;case75:/* Enable 360 circular interpolation */
state->mq_on =1;
stats->G75++;break;case90:/* Specify absolut format */if(format) format->coordinate = GERBV_COORDINATE_ABSOLUTE;
stats->G90++;break;case91:/* Specify incremental format */if(format) format->coordinate = GERBV_COORDINATE_INCREMENTAL;
stats->G91++;break;default:gerbv_stats_printf(error_list, GERBV_MESSAGE_ERROR,-1,_("Encountered unknown G code G%02d ""at line %ld in file \"%s\""),
op_int,*line_num_p, fd->filename);gerbv_stats_printf(error_list, GERBV_MESSAGE_WARNING,-1,_("Ignorning unknown G code G%02d"), op_int);
stats->G_unknown++;/* TODO: insert error count here */break;}return;}/* parse_G_code */
解析D code
staticvoidparse_D_code(gerb_file_t*fd,gerb_state_t*state,gerbv_image_t*image,longint*line_num_p){int a;gerbv_stats_t*stats = image->gerbv_stats;gerbv_error_list_t*error_list = stats->error_list;
a =gerb_fgetint(fd,NULL);dprintf(" Found D%02d code at line %ld\n", a,*line_num_p);switch(a){case0:/* Invalid code */gerbv_stats_printf(error_list, GERBV_MESSAGE_ERROR,-1,_("Found invalid D00 code at line %ld in file \"%s\""),*line_num_p, fd->filename);
stats->D_error++;break;case1:/* Exposure on */
state->aperture_state = GERBV_APERTURE_STATE_ON;
state->changed =1;
stats->D1++;break;case2:/* Exposure off */
state->aperture_state = GERBV_APERTURE_STATE_OFF;
state->changed =1;
stats->D2++;break;case3:/* Flash aperture */
state->aperture_state = GERBV_APERTURE_STATE_FLASH;
state->changed =1;
stats->D3++;break;default:/* Aperture in use */if((a >=0)&&(a <= APERTURE_MAX)){
state->curr_aperture = a;}else{gerbv_stats_printf(error_list, GERBV_MESSAGE_ERROR,-1,_("Found out of bounds aperture D%02d ""at line %ld in file \"%s\""),
a,*line_num_p, fd->filename);
stats->D_error++;}
state->changed =0;break;}return;}/* parse_D_code */
解析M code
staticintparse_M_code(gerb_file_t*fd,gerbv_image_t*image,longint*line_num_p){int op_int;gerbv_stats_t*stats = image->gerbv_stats;
op_int=gerb_fgetint(fd,NULL);switch(op_int){case0:/* Program stop */
stats->M0++;return1;case1:/* Optional stop */
stats->M1++;return2;case2:/* End of program */
stats->M2++;return3;default:gerbv_stats_printf(stats->error_list, GERBV_MESSAGE_ERROR,-1,_("Encountered unknown M%02d code at line %ld in file \"%s\""),
op_int,*line_num_p, fd->filename);gerbv_stats_printf(stats->error_list, GERBV_MESSAGE_WARNING,-1,_("Ignorning unknown M%02d code"), op_int);
stats->M_unknown++;}return0;}/* parse_M_code */