int do_symbol(char *buff) { double xper, yper; int size; int ix, iy; char *symb_name; SYMBOL *Symb; char *line_color_str, *fill_color_str; RGBA_Color *line_color, *fill_color; int R, G, B, ret; line_color = G_malloc(sizeof(RGBA_Color)); fill_color = G_malloc(sizeof(RGBA_Color)); symb_name = G_malloc(sizeof(char) * strlen(buff) + 1); /* well, it won't be any bigger than this */ line_color_str = G_malloc(sizeof(char) * strlen(buff) + 1); fill_color_str = G_malloc(sizeof(char) * strlen(buff) + 1); G_debug(3, "do_symbol() [%s]", buff); /* set default colors so colors are optional */ strcpy(line_color_str, DEFAULT_FG_COLOR); strcpy(fill_color_str, "grey"); if (sscanf (buff, "%*s %s %d %lf %lf %s %s", symb_name, &size, &xper, &yper, line_color_str, fill_color_str) < 4) { G_warning(_("Problem parsing command [%s]"), buff); return (-1); } if (mapunits) { ix = (int)(D_u_to_d_col(xper) + 0.5); iy = (int)(D_u_to_d_row(yper) + 0.5); /* consider size in map units too? maybe as percentage of display? perhaps use "size * D_get_u_to_d_yconv()" to convert */ } else { if (xper < 0. || yper < 0. || xper > 100. || yper > 100.) return (-1); ix = l + (int)(xper * xincr); iy = b - (int)(yper * yincr); } /* parse line color */ ret = G_str_to_color(line_color_str, &R, &G, &B); line_color->r = (unsigned char)R; line_color->g = (unsigned char)G; line_color->b = (unsigned char)B; if (ret == 1) { /* here alpha is only used as an on/off switch, otherwise unused by the display drivers */ line_color->a = RGBA_COLOR_OPAQUE; } else if (ret == 2) line_color->a = RGBA_COLOR_NONE; else { G_warning(_("[%s]: No such color"), line_color_str); return (-1); } /* parse fill color */ ret = G_str_to_color(fill_color_str, &R, &G, &B); fill_color->r = (unsigned char)R; fill_color->g = (unsigned char)G; fill_color->b = (unsigned char)B; if (ret == 1) fill_color->a = RGBA_COLOR_OPAQUE; else if (ret == 2) fill_color->a = RGBA_COLOR_NONE; else { G_warning(_("[%s]: No such color"), fill_color_str); return (-1); } Symb = S_read(symb_name); if (Symb == NULL) { G_warning(_("Cannot read symbol, cannot display points")); return (-1); } else S_stroke(Symb, size, rotation, 0); D_symbol(Symb, ix, iy, line_color, fill_color); /* restore previous d.graph draw color */ if (last_color.a == RGBA_COLOR_OPAQUE) R_RGB_color(last_color.r, last_color.g, last_color.b); else if (last_color.a == RGBA_COLOR_NONE) D_raster_use_color(D_parse_color(DEFAULT_BG_COLOR, 0)); else /* unset or bad */ R_RGB_color(line_color->r, line_color->g, line_color->b); G_free(symb_name); G_free(line_color_str); G_free(fill_color_str); G_free(line_color); G_free(fill_color); return (0); }
int draw_n_arrow(double east, double north, double rotation, char *lbl, int rot_with_text, double fontsize, char *n_arrow_num, double line_width) { double x_pos, y_pos; double t, b, l, r; double tt, tb, tl, tr; /* text box */ SYMBOL *Symb; RGBA_Color *line_color, *fill_color; int R, G, B; double x0, y0; char icon[64]; double symbol_size; /* Establish text size */ if (fontsize > 0) D_text_size(fontsize, fontsize); D_setup_unity(0); D_get_src(&t, &b, &l, &r); x_pos = l + (int)(east * (r - l) / 100.); y_pos = t + (int)((100. - north) * (b - t) / 100.); if (line_width > 0) D_line_width(line_width); if (fontsize > 0) { /* draw the label (default "N") */ if (rot_with_text) D_text_rotation(rotation * 180.0 / M_PI); D_get_text_box(lbl, &tt, &tb, &tl, &tr); D_use_color(text_color); /* positions manually tuned */ switch (n_arrow_num[0]) { case '1': D_pos_abs(x_pos - sin(rotation) * 50 - (tr + tl) / 2, y_pos - cos(rotation) * 50 - (tb + tt) / 2); D_text(lbl); break; case '3': D_pos_abs(x_pos - sin(rotation) * 60 - (tr + tl) / 2, y_pos - cos(rotation) * 60 - (tb + tt) / 2); D_text(lbl); break; case '4': D_pos_abs(x_pos - sin(rotation) * 45 - (tr + tl) / 2, y_pos - cos(rotation) * 45 - (tb + tt) / 2); D_text(lbl); break; case '7': D_pos_abs(x_pos - sin(rotation) * 70 - (tr + tl) / 2, y_pos - cos(rotation) * 70 - (tb + tt) / 2); D_text(lbl); break; case '8': D_pos_abs(x_pos - sin(rotation) * 60 - (tr + tl) / 2, y_pos - cos(rotation) * 60 - (tb + tt) / 2); D_text(lbl); break; case '9': D_pos_abs(x_pos - sin(rotation) * 55 - (tr + tl) / 2, y_pos - cos(rotation) * 55 - (tb + tt) / 2); D_text(lbl); break; case 'f': D_pos_abs(x_pos - sin(rotation) * 55 - (tr + tl) / 2, y_pos - cos(rotation) * 55 - (tb + tt) / 2); D_text(lbl); break; case 'b': D_pos_abs(x_pos - sin(rotation) * 48.5 - (tr + tl) / 2, y_pos - cos(rotation) * 48.5 - (tb + tt) / 2); D_text(lbl); break; case 'a': D_pos_abs(x_pos - sin(rotation) * 50 - (tr + tl) / 2, y_pos - cos(rotation) * 50 - (tb + tt) / 2); D_text(lbl); break; case 's': D_pos_abs(x_pos - sin(rotation) * 50 - (tr + tl) / 2, y_pos - cos(rotation) * 50 - (tb + tt) / 2); D_text(lbl); break; case '2': case '5': case '6': break; default: G_fatal_error(_("Could not parse symbol")); } } /* display the north arrow symbol */ line_color = G_malloc(sizeof(RGBA_Color)); fill_color = G_malloc(sizeof(RGBA_Color)); if (D_color_number_to_RGB(fg_color, &R, &G, &B) == 0) line_color->a = RGBA_COLOR_TRANSPARENT; else line_color->a = RGBA_COLOR_OPAQUE; line_color->r = (unsigned char)R; line_color->g = (unsigned char)G; line_color->b = (unsigned char)B; if (D_color_number_to_RGB(bg_color, &R, &G, &B) == 0) fill_color->a = RGBA_COLOR_TRANSPARENT; else fill_color->a = RGBA_COLOR_OPAQUE; fill_color->r = (unsigned char)R; fill_color->g = (unsigned char)G; fill_color->b = (unsigned char)B; /* sizes manually tuned */ switch (n_arrow_num[0]) { case '1': symbol_size = 35.; break; case '2': symbol_size = 19.; break; case '3': symbol_size = 20.; break; case '4': symbol_size = 15.; break; case '5': case '6': symbol_size = 14.; break; case '7': symbol_size = 23.; break; case '8': case '9': symbol_size = 17.; break; case 'b': symbol_size = 80.; break; case 'f': symbol_size = 100.; break; case 'a': if (n_arrow_num[5] == '2') symbol_size = 53.; else symbol_size = 70.; break; case 's': symbol_size = 80.; break; default: G_fatal_error(_("Could not parse symbol")); } x0 = D_d_to_u_col(x_pos); y0 = D_d_to_u_row(y_pos); if (n_arrow_num[0] == 'b') strcpy(icon, "n_arrows/basic_compass"); else if (n_arrow_num[0] == 'f') strcpy(icon, "n_arrows/fancy_compass"); else if (n_arrow_num[0] == 'a' && n_arrow_num[5] == '1') strcpy(icon, "basic/arrow1"); else if (n_arrow_num[0] == 'a' && n_arrow_num[5] == '2') strcpy(icon, "basic/arrow2"); else if (n_arrow_num[0] == 'a' && n_arrow_num[5] == '3') strcpy(icon, "basic/arrow3"); else if (n_arrow_num[0] == 's') strcpy(icon, "extra/4pt_star"); else { strcpy(icon, "n_arrows/n_arrow"); strncat(icon, n_arrow_num, 32); } Symb = S_read(icon); if (!Symb) G_fatal_error(_("Could not read symbol \"%s\""), icon); S_stroke(Symb, symbol_size, rotation * (180 / M_PI), 0); D_symbol(Symb, x0, y0, line_color, fill_color); if (line_width > 0) D_line_width(0); G_free(Symb); G_free(line_color); G_free(fill_color); return 0; }
int draw_n_arrow(double east, double north, double fontsize, char *n_arrow_num, double line_width) { double x_pos, y_pos; double t, b, l, r; double tt, tb, tl, tr; /* text box*/ SYMBOL *Symb; RGBA_Color *line_color, *fill_color; int R, G, B; double x0, y0; char icon[64]; double symbol_size; /* Establish text size */ if (fontsize > 0) D_text_size(fontsize, fontsize); D_setup_unity(0); D_get_src(&t, &b, &l, &r); x_pos = east * (r - l) / 100.; y_pos = (100. - north) * (b - t) / 100.; if (line_width > 0) D_line_width(line_width); if (fontsize > 0) { /* draw the "N" */ D_get_text_box("N", &tt, &tb, &tl, &tr); D_use_color(fg_color); /* positions manually tuned */ switch (n_arrow_num[0]) { case '1': D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 45); D_text("N"); break; case '3': D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 60); D_text("N"); break; case '4': D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 45); D_text("N"); break; case '7': D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 70); D_text("N"); break; case '9': case 'f': D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 55); D_text("N"); break; case 'b': D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 48.5); D_text("N"); break; case '2': case '5': case '6': case '8': break; default: G_fatal_error(_("Could not parse symbol")); } } /* display the north arrow symbol */ line_color = G_malloc(sizeof(RGBA_Color)); fill_color = G_malloc(sizeof(RGBA_Color)); if (D_color_number_to_RGB(fg_color, &R, &G, &B) == 0) /* fall back to black on failure */ G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B); line_color->r = (unsigned char)R; line_color->g = (unsigned char)G; line_color->b = (unsigned char)B; line_color->a = RGBA_COLOR_OPAQUE; if (D_color_number_to_RGB(bg_color, &R, &G, &B) == 0) /* fall back to black on failure */ G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B); fill_color->r = (unsigned char)R; fill_color->g = (unsigned char)G; fill_color->b = (unsigned char)B; fill_color->a = RGBA_COLOR_OPAQUE; if (n_arrow_num[0] == '2' || n_arrow_num[0] == '9') fill_color->a = RGBA_COLOR_TRANSPARENT; /* sizes manually tuned */ switch (n_arrow_num[0]) { case '1': symbol_size = 35.; break; case '2': symbol_size = 19.; break; case '3': symbol_size = 20.; break; case '4': symbol_size = 15.; break; case '5': case '6': symbol_size = 14.; break; case '7': symbol_size = 23.; break; case '8': case '9': symbol_size = 17.; break; case 'b': symbol_size = 80.; break; case 'f': symbol_size = 100.; break; default: G_fatal_error(_("Could not parse symbol")); } x0 = D_d_to_u_col(x_pos); y0 = D_d_to_u_row(y_pos); if (n_arrow_num[0] == 'b') strcpy(icon, "n_arrows/basic_compass"); else if (n_arrow_num[0] == 'f') strcpy(icon, "n_arrows/fancy_compass"); else { strcpy(icon, "n_arrows/n_arrow"); strncat(icon, n_arrow_num, 32); } Symb = S_read(icon); if(!Symb) G_fatal_error(_("Could not read symbol \"%s\""), icon); S_stroke(Symb, symbol_size, 0.0, 0); D_symbol(Symb, x0, y0, line_color, fill_color); if (line_width > 0) D_line_width(0); G_free(Symb); G_free(line_color); G_free(fill_color); return 0; }
int display_lines(struct Map_info *Map, struct cat_list *Clist, int chcat, const char *symbol_name, double size, int default_width, dbCatValArray * cvarr, double *breaks, int nbreaks, const struct color_rgb *colors, const struct color_rgb *bcolor) { int ltype, line, nlines; struct line_pnts *Points; struct line_cats *Cats; int n_points, n_lines, n_centroids, n_boundaries, n_faces; RGBA_Color *primary_color, *secondary_color; SYMBOL *Symb; Symb = NULL; double breakval = 0.0; int cat; dbCatVal *cv = NULL; int i; primary_color = G_malloc(sizeof(RGBA_Color)); primary_color->a = RGBA_COLOR_OPAQUE; secondary_color = G_malloc(sizeof(RGBA_Color)); secondary_color->a = RGBA_COLOR_OPAQUE; Points = Vect_new_line_struct(); Cats = Vect_new_cats_struct(); /* dynamic symbols for points */ Symb = S_read(symbol_name); if (!Symb) G_warning(_("Unable to read symbol <%s>, unable to display points"), symbol_name); else S_stroke(Symb, size, 0.0, 0); Vect_rewind(Map); nlines = -1; line = 0; n_points = n_lines = 0; n_centroids = n_boundaries = 0; n_faces = 0; while (TRUE) { line++; if (nlines > -1) { if (line > nlines) break; ltype = Vect_read_line(Map, Points, Cats, line); } else { ltype = Vect_read_next_line(Map, Points, Cats); if (ltype == -1) { G_fatal_error(_("Unable to read vector map")); } else if ((ltype == -2)) { /* EOF */ break; } } cat = *Cats->cat; if (cat >= 0) { G_debug(3, "display line %d, cat %d", line, cat); /* Get value of data for this area */ if (db_CatValArray_get_value(cvarr, cat, &cv) != DB_OK) { G_debug(3, "No value found for cat %i", cat); } else { db_CatValArray_get_value(cvarr, cat, &cv); breakval = (cvarr->ctype == 2 ? cv->val.i : cv->val.d); } } /* find out into which class breakval falls */ i = 0; while (breakval > breaks[i] && i < nbreaks) i++; primary_color->r = colors[i].r; primary_color->g = colors[i].g; primary_color->b = colors[i].b; if (bcolor !=NULL) { secondary_color->r = bcolor->r; secondary_color->g = bcolor->g; secondary_color->b = bcolor->b; } else secondary_color->a = 0; draw_line(ltype, line, Points, Cats, chcat, size, default_width, Clist, Symb, primary_color, &n_points, &n_lines, &n_centroids, &n_boundaries, &n_faces, secondary_color); } if (n_points > 0) G_verbose_message(n_ ("%d point plotted", "%d points plotted", n_points), n_points); if (n_lines > 0) G_verbose_message(n_("%d line plotted", "%d lines plotted", n_lines), n_lines); if (n_centroids > 0) G_verbose_message(n_ ("%d centroid plotted", "%d centroids plotted", n_centroids), n_centroids); if (n_boundaries > 0) G_verbose_message(n_ ("%d boundary plotted", "%d boundaries plotted", n_boundaries), n_boundaries); if (n_faces > 0) G_verbose_message(n_("%d face plotted", "%d faces plotted", n_faces), n_faces); Vect_destroy_line_struct(Points); Vect_destroy_cats_struct(Cats); G_free(primary_color); return 0; }