gerber

这里写目录标题

解析G code

static void 
parse_G_code(gerb_file_t *fd, gerb_state_t *state,
		gerbv_image_t *image, long int *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) {
    case 0:  /* Move */
	/* Is this doing anything really? */
	stats->G0++;
	break;
    case 1:  /* Linear Interpolation (1X scale) */
	state->interpolation = GERBV_INTERPOLATION_LINEARx1;
	stats->G1++;
	break;
    case 2:  /* Clockwise Linear Interpolation */
	state->interpolation = GERBV_INTERPOLATION_CW_CIRCULAR;
	stats->G2++;
	break;
    case 3:  /* Counter Clockwise Linear Interpolation */
	state->interpolation = GERBV_INTERPOLATION_CCW_CIRCULAR;
	stats->G3++;
	break;
    case 4:  /* 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;
    case 10: /* Linear Interpolation (10X scale) */
	state->interpolation = GERBV_INTERPOLATION_LINEARx10;
	stats->G10++;
	break;
    case 11: /* Linear Interpolation (0.1X scale) */
	state->interpolation = GERBV_INTERPOLATION_LINEARx01;
	stats->G11++;
	break;
    case 12: /* Linear Interpolation (0.01X scale) */
	state->interpolation = GERBV_INTERPOLATION_LINEARx001;
	stats->G12++;
	break;
    case 36: /* Turn on Polygon Area Fill */
	state->prev_interpolation = state->interpolation;
	state->interpolation = GERBV_INTERPOLATION_PAREA_START;
	state->changed = 1;
	stats->G36++;
	break;
    case 37: /* Turn off Polygon Area Fill */
	state->interpolation = GERBV_INTERPOLATION_PAREA_END;
	state->changed = 1;
	stats->G37++;
	break;
    case 54: /* 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;
    case 55: /* Prepare for flash */
	stats->G55++;
	break;
    case 70: /* Specify inches */
	state->state = gerbv_image_return_new_netstate (state->state);
	state->state->unit = GERBV_UNIT_INCH;
	stats->G70++;
	break;
    case 71: /* Specify millimeters */
	state->state = gerbv_image_return_new_netstate (state->state);
	state->state->unit = GERBV_UNIT_MM;
	stats->G71++;
	break;
    case 74: /* Disable 360 circular interpolation */
	state->mq_on = 0;
	stats->G74++;
	break;
    case 75: /* Enable 360 circular interpolation */
	state->mq_on = 1;
	stats->G75++;
	break;
    case 90: /* Specify absolut format */
	if (format) format->coordinate = GERBV_COORDINATE_ABSOLUTE;
	stats->G90++;
	break;
    case 91: /* 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

static void 
parse_D_code(gerb_file_t *fd, gerb_state_t *state,
		gerbv_image_t *image, long int *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) {
    case 0 : /* 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;
    case 1 : /* Exposure on */
	state->aperture_state = GERBV_APERTURE_STATE_ON;
	state->changed = 1;
	stats->D1++;
	break;
    case 2 : /* Exposure off */
	state->aperture_state = GERBV_APERTURE_STATE_OFF;
	state->changed = 1;
	stats->D2++;
	break;
    case 3 : /* 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

static int
parse_M_code(gerb_file_t *fd, gerbv_image_t *image, long int *line_num_p)
{
    int op_int;
    gerbv_stats_t *stats = image->gerbv_stats;
    
    op_int=gerb_fgetint(fd, NULL);
    
    switch (op_int) {
    case 0:  /* Program stop */
	stats->M0++;
	return 1;
    case 1:  /* Optional stop */
	stats->M1++;
	return 2;
    case 2:  /* End of program */
	stats->M2++;
	return 3;
    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++;
    }
    return 0;
} /* parse_M_code */

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值