示例#1
0
void add_layer_to_list(const char *layer, int print)
{
    if (is_layer_in_list(layer))
	return;

    layers = (char **)G_realloc(layers, (num_layers + 2) * sizeof(char *));
    layers[num_layers] = G_store(layer);
    G_str_to_lower(layers[num_layers]);
    if (print) {
	fprintf(stdout, _("Layer %d: %s\n"), num_layers + 1,
		layers[num_layers]);
	fflush(stdout);
    }
    num_layers++;
    layers[num_layers] = NULL;

    return;
}
示例#2
0
void add_circle(struct dxf_file *dxf, struct Map_info *Map)
{
    int code;
    char handle[DXF_BUF_SIZE];	/* entity handle, 16 hexadecimal digits */
    char layer[DXF_BUF_SIZE];	/* layer name */
    int layer_flag = 0;		/* indicates if a layer name has been found */
    int xflag = 0;		/* indicates if a x value has been found */
    int yflag = 0;		/* indicates if a y value has been found */
    int rflag = 0;		/* indicates if a radius has been found */
    double centerx = 0;		/* read in from dxf file */
    double centery = 0;		/* read in from dxf file */
    double radius = 0;		/* read in from dxf file */
    double zcoor = 0;		/* read in from dxf file */
    int arr_size = 0;

    handle[0] = 0;
    strcpy(layer, UNIDENTIFIED_LAYER);

    /* read in lines and process information until a 0 is read in */
    while ((code = dxf_get_code(dxf)) != 0) {
        if (code == -2)
            return;

        switch (code) {
        case 5:		/* entity handle */
            strcpy(handle, dxf_buf);
            break;
        case 8:		/* layer name */
            if (!layer_flag && *dxf_buf) {
                if (flag_list) {
                    if (!is_layer_in_list(dxf_buf))
                        add_layer_to_list(dxf_buf, 1);
                    return;
                }
                /* skip if (opt_layers != NULL && (
                 * (flag_invert == 0 && is_layer_in_list == 0) ||
                 * (flag_invert == 1 && is_layer_in_list == 1)
                 * )
                 */
                if (opt_layers && flag_invert == is_layer_in_list(dxf_buf))
                    return;
                strcpy(layer, dxf_buf);
                layer_flag = 1;
            }
            break;
        case 10:		/* x coordinate */
            centerx = atof(dxf_buf);
            xflag = 1;
            break;
        case 20:		/* y coordinate */
            centery = atof(dxf_buf);
            yflag = 1;
            break;
        case 30:		/* z coordinate */
            zcoor = atof(dxf_buf);
            break;
        case 40:		/* radius */
            radius = atof(dxf_buf);
            rflag = 1;
            break;
        }
    }

    if (xflag && yflag && rflag) {
        arr_size = make_arc(0, centerx, centery, radius, 0.0, 360.0, zcoor);
        write_vect(Map, layer, "CIRCLE", handle, "", arr_size, GV_LINE);
    }

    return;
}
示例#3
0
int add_lwpolyline(struct dxf_file *dxf, struct Map_info *Map)
{
    int code;
    char layer[DXF_BUF_SIZE];
    int layer_flag = 0;		/* indicates if a layer name has been found */
    int polyline_flag = 0;	/* indicates the type of polyline */
    int xflag = 0;		/* indicates if a x value has been found */
    int yflag = 0;		/* indicates if a y value has been found */
    double elevation = 0.0;	/* elevation */
    int arr_size = 0;

    /* variables to create arcs */
    double bulge = 0.0;		/* for arc curves */
    double prev_bulge = 0.0;	/* for arc curves */

    strcpy(layer, UNIDENTIFIED_LAYER);

    /* read in lines and process information until a 0 is read in */
    while ((code = dxf_get_code(dxf)) != 0) {
	if (code == -2)
	    return -1;

	switch (code) {
	case 8:		/* layer name */
	    if (!layer_flag && *dxf_buf) {
		if (flag_list) {
		    if (!is_layer_in_list(dxf_buf)) {
			add_layer_to_list(dxf_buf);
			fprintf(stdout, _("Layer %d: %s\n"), num_layers,
				dxf_buf);
		    }
		    return 0;
		}
		/* skip if layers != NULL && (
		 * (flag_invert == 0 && is_layer_in_list == 0) ||
		 * (flag_invert == 1 && is_layer_in_list == 1)
		 * )
		 */
		if (layers && flag_invert == is_layer_in_list(dxf_buf))
		    return 0;
		strcpy(layer, dxf_buf);
		layer_flag = 1;
	    }
	    break;
	case 10:		/* x coordinate */
	    xpnts[arr_size] = atof(dxf_buf);
	    xflag = 1;
	    break;
	case 20:		/* y coordinate */
	    ypnts[arr_size] = atof(dxf_buf);
	    yflag = 1;
	    break;
	case 38:		/* elevation */
	    elevation = atof(dxf_buf);
	    break;
	case 42:		/* bulge */
	    bulge = atof(dxf_buf);
	    break;
	case 70:		/* polyline flag */
	    /*******************************************************************
	     Polyline flag (bit-coded); default is 0:
	     1 = Closed; 128 = Plinegen
	     ******************************************************************/
	    polyline_flag = atoi(dxf_buf);
	    break;

	case 40:		/* starting width */
	case 41:		/* ending width */
	    break;
	}

	if (xflag && yflag) {
	    arr_size = make_arc_from_polyline(arr_size, bulge, prev_bulge);
	    prev_bulge = bulge;
	    bulge = 0.0;

	    xflag = 0;
	    yflag = 0;
	}
    }

    {
	int i;

	for (i = 0; i < arr_size; i++)
	    zpnts[i] = elevation;
    }

    if (polyline_flag & 1) {
	if (xpnts[0] != xpnts[arr_size - 1] ||
	    ypnts[0] != ypnts[arr_size - 1]) {
	    /* close polyline */
	    xpnts[arr_size] = xpnts[0];
	    ypnts[arr_size] = ypnts[0];
	    zpnts[arr_size] = zpnts[0];
	    arr_size++;

	    /* arr_size incremented to be consistent with polyline_flag != 1 */
	    if (arr_size == ARR_MAX) {
		ARR_MAX += ARR_INCR;
		xpnts = (double *)G_realloc(xpnts, ARR_MAX * sizeof(double));
		ypnts = (double *)G_realloc(ypnts, ARR_MAX * sizeof(double));
		zpnts = (double *)G_realloc(zpnts, ARR_MAX * sizeof(double));
	    }
	}
    }

    write_line(Map, layer, arr_size);

    return 0;
}
示例#4
0
文件: add_text.c 项目: rkrug/grass-ci
void add_text(struct dxf_file *dxf, struct Map_info *Map)
{
    int code;
    char handle[DXF_BUF_SIZE];	/* entity handle, 16 hexadecimal digits */
    char layer[DXF_BUF_SIZE];	/* layer name */
    int layer_flag = 0;		/* indicates if a layer name has been found */
    int xflag = 0;		/* indicates if a x value has been found */
    int yflag = 0;		/* indicates if a y value has been found */
    double height = 1.0;	/* read in from dxf file */
    double angle = 0.0;		/* read in from dxf file */
    char label[DXF_BUF_SIZE];	/* read in from dxf file */
    int label_len = 0;

    handle[0] = 0;
    strcpy(layer, UNIDENTIFIED_LAYER);

    zpnts[0] = 0.0;
    /* read in lines and process information until a 0 is read in */
    while ((code = dxf_get_code(dxf)) != 0) {
        if (code == -2)
            return;

        switch (code) {
        case 1:		/* label value */
            label_len = strlen(dxf_buf);
            strcpy(label, dxf_buf);
            break;
        case 5:		/* entity handle */
            strcpy(handle, dxf_buf);
            break;
        case 8:		/* layer name */
            if (!layer_flag && *dxf_buf) {
                if (flag_list) {
                    if (!is_layer_in_list(dxf_buf))
                        add_layer_to_list(dxf_buf, 1);
                    return;
                }
                /* skip if (opt_layers != NULL && (
                 * (flag_invert == 0 && is_layer_in_list == 0) ||
                 * (flag_invert == 1 && is_layer_in_list == 1)
                 * )
                 */
                if (opt_layers && flag_invert == is_layer_in_list(dxf_buf))
                    return;
                strcpy(layer, dxf_buf);
                layer_flag = 1;
            }
            break;
        case 10:		/* x coordinate */
            xpnts[0] = atof(dxf_buf);
            xflag = 1;
            break;
        case 20:		/* y coordinate */
            ypnts[0] = atof(dxf_buf);
            yflag = 1;
            break;
        case 30:		/* z coordinate */
            zpnts[0] = atof(dxf_buf);
            break;
        case 40:		/* text height */
            height = atof(dxf_buf);
            break;
        case 50:		/* text angle */
            angle = atof(dxf_buf);
            break;

        case 7:		/* text style name */
        case 11:		/* alignment point */
        case 21:		/* alignment point */
        case 31:		/* alignment point */
        case 41:		/* relative x scale factor */
        case 51:		/* oblique angle */
        case 71:		/* text generation flag */
        case 72:		/* horizontal text justification type */
            break;
        }
    }

    if (label_len == 0)
        return;

    if (xflag && yflag) {
        /* TODO */
#if 0
        double theta, length, diag, base1, base2;

        /* now build the points of the box */
        theta = angle * M_PI / 180.;
        length = (label_len - 1) * height;

        /* base angles for polar description of rectangle */
        base1 = M_PI / 2.;
        base2 = atan2(1., (double)(label_len - 1));
        diag = hypot(length, height);

        xpnts[4] = xpnts[0];
        ypnts[4] = ypnts[0];
        zpnts[4] = zpnts[0];

        xpnts[1] = xpnts[0] + (height * cos(theta + base1));
        ypnts[1] = ypnts[0] + (height * sin(theta + base1));
        zpnts[1] = zpnts[0];

        xpnts[2] = xpnts[0] + (diag * cos(theta + base2));
        ypnts[2] = ypnts[0] + (diag * sin(theta + base2));
        zpnts[2] = zpnts[0];

        xpnts[3] = xpnts[0] + (length * cos(theta));
        ypnts[3] = ypnts[0] + (length * sin(theta));
        zpnts[3] = zpnts[0];

        write_vect(Map, layer, "TEXT", handle, "", 5, GV_LINE);
#endif
        write_vect(Map, layer, "TEXT", handle, label, 1, GV_POINT);
    }

    return;
}