int driver_refresh(void) { setup(); G_setup_plot(D_get_d_north(), D_get_d_south(), D_get_d_west(), D_get_d_east(), driver_move_abs, driver_cont_abs); return 1; }
int D_set_clip_window_to_map_window(void) { D_set_clip_window((int)D_get_d_north(), (int)D_get_d_south(), (int)D_get_d_west(), (int)D_get_d_east() ); return 0; }
int driver_open(void) { double n, s, e, w; if (Tcl_Eval(Toolbox, "create_screen") != TCL_OK) G_warning("create_screen: %s", Tcl_GetStringResult(Toolbox)); setup(); n = D_d_to_u_row(D_get_d_north()); s = D_d_to_u_row(D_get_d_south()); w = D_d_to_u_col(D_get_d_west()); e = D_d_to_u_col(D_get_d_east()); Scale = (n - s) / (D_get_d_south() - D_get_d_north()); G_setup_plot(D_get_d_north(), D_get_d_south(), D_get_d_west(), D_get_d_east(), driver_move_abs, driver_cont_abs); return 1; }
/* *************************************************************** */ int plot1(struct Map_info *Map, int type, int area, struct cat_list *Clist, const struct color_rgb *color, const struct color_rgb *fcolor, int chcat, SYMBOL * Symb, int size, int id_flag, int table_colors_flag, int cats_color_flag, char *rgb_column, int default_width, char *width_column, double width_scale) { int i, ltype, nlines = 0, line, cat = -1; double *x, *y; struct line_pnts *Points, *PPoints; struct line_cats *Cats; double msize; int x0, y0; struct field_info *fi = NULL; dbDriver *driver = NULL; dbCatValArray cvarr_rgb, cvarr_width; dbCatVal *cv_rgb = NULL, *cv_width = NULL; int nrec_rgb = 0, nrec_width = 0; int open_db; int custom_rgb = FALSE; char colorstring[12]; /* RRR:GGG:BBB */ int red, grn, blu; RGBA_Color *line_color, *fill_color, *primary_color; unsigned char which; int width; line_color = G_malloc(sizeof(RGBA_Color)); fill_color = G_malloc(sizeof(RGBA_Color)); primary_color = G_malloc(sizeof(RGBA_Color)); primary_color->a = RGBA_COLOR_OPAQUE; /* change function prototype to pass RGBA_Color instead of color_rgb? */ if (color) { line_color->r = color->r; line_color->g = color->g; line_color->b = color->b; line_color->a = RGBA_COLOR_OPAQUE; } else line_color->a = RGBA_COLOR_NONE; if (fcolor) { fill_color->r = fcolor->r; fill_color->g = fcolor->g; fill_color->b = fcolor->b; fill_color->a = RGBA_COLOR_OPAQUE; } else fill_color->a = RGBA_COLOR_NONE; msize = size * (D_d_to_u_col(2.0) - D_d_to_u_col(1.0)); /* do it better */ Points = Vect_new_line_struct(); PPoints = Vect_new_line_struct(); Cats = Vect_new_cats_struct(); open_db = table_colors_flag || width_column; if (open_db) { fi = Vect_get_field(Map, (Clist->field > 0 ? Clist->field : 1)); if (fi == NULL) { G_fatal_error(_("Database connection not defined for layer %d"), (Clist->field > 0 ? Clist->field : 1)); } driver = db_start_driver_open_database(fi->driver, fi->database); if (driver == NULL) G_fatal_error(_("Unable to open database <%s> by driver <%s>"), fi->database, fi->driver); } if (table_colors_flag) { /* for reading RRR:GGG:BBB color strings from table */ if (rgb_column == NULL || *rgb_column == '\0') G_fatal_error(_("Color definition column not specified")); db_CatValArray_init(&cvarr_rgb); nrec_rgb = db_select_CatValArray(driver, fi->table, fi->key, rgb_column, NULL, &cvarr_rgb); G_debug(3, "nrec_rgb (%s) = %d", rgb_column, nrec_rgb); if (cvarr_rgb.ctype != DB_C_TYPE_STRING) G_fatal_error(_("Color definition column (%s) not a string. " "Column must be of form RRR:GGG:BBB where RGB values range 0-255."), rgb_column); if (nrec_rgb < 0) G_fatal_error(_("Cannot select data (%s) from table"), rgb_column); G_debug(2, "\n%d records selected from table", nrec_rgb); for (i = 0; i < cvarr_rgb.n_values; i++) { G_debug(4, "cat = %d %s = %s", cvarr_rgb.value[i].cat, rgb_column, db_get_string(cvarr_rgb.value[i].val.s)); } } if (width_column) { if (*width_column == '\0') G_fatal_error(_("Line width column not specified.")); db_CatValArray_init(&cvarr_width); nrec_width = db_select_CatValArray(driver, fi->table, fi->key, width_column, NULL, &cvarr_width); G_debug(3, "nrec_width (%s) = %d", width_column, nrec_width); if (cvarr_width.ctype != DB_C_TYPE_INT && cvarr_width.ctype != DB_C_TYPE_DOUBLE) G_fatal_error(_("Line width column (%s) not a number."), width_column); if (nrec_width < 0) G_fatal_error(_("Cannot select data (%s) from table"), width_column); G_debug(2, "\n%d records selected from table", nrec_width); for (i = 0; i < cvarr_width.n_values; i++) { G_debug(4, "cat = %d %s = %d", cvarr_width.value[i].cat, width_column, (cvarr_width.ctype == DB_C_TYPE_INT ? cvarr_width.value[i].val. i : (int)cvarr_width.value[i].val.d)); } } if (open_db) db_close_database_shutdown_driver(driver); Vect_rewind(Map); /* Is it necessary to reset line/label color in each loop ? */ if (color && !table_colors_flag && !cats_color_flag) D_RGB_color(color->r, color->g, color->b); if (Vect_level(Map) >= 2) nlines = Vect_get_num_lines(Map); line = 0; while (1) { if (Vect_level(Map) >= 2) { line++; if (line > nlines) return 0; if (!Vect_line_alive(Map, line)) continue; ltype = Vect_read_line(Map, Points, Cats, line); } else { ltype = Vect_read_next_line(Map, Points, Cats); switch (ltype) { case -1: fprintf(stderr, _("\nERROR: vector map - can't read\n")); return -1; case -2: /* EOF */ return 0; } } if (!(type & ltype)) continue; if (chcat) { int found = 0; if (id_flag) { /* use line id */ if (!(Vect_cat_in_cat_list(line, Clist))) continue; } else { for (i = 0; i < Cats->n_cats; i++) { if (Cats->field[i] == Clist->field && Vect_cat_in_cat_list(Cats->cat[i], Clist)) { found = 1; break; } } if (!found) continue; } } else if (Clist->field > 0) { int found = 0; for (i = 0; i < Cats->n_cats; i++) { if (Cats->field[i] == Clist->field) { found = 1; break; } } /* lines with no category will be displayed */ if (Cats->n_cats > 0 && !found) continue; } if (table_colors_flag) { /* only first category */ cat = Vect_get_line_cat(Map, line, (Clist->field > 0 ? Clist->field : (Cats->n_cats > 0 ? Cats->field[0] : 1))); if (cat >= 0) { G_debug(3, "display element %d, cat %d", line, cat); /* Read RGB colors from db for current area # */ if (db_CatValArray_get_value(&cvarr_rgb, cat, &cv_rgb) != DB_OK) { custom_rgb = FALSE; } else { sprintf(colorstring, "%s", db_get_string(cv_rgb->val.s)); if (*colorstring != '\0') { G_debug(3, "element %d: colorstring: %s", line, colorstring); if (G_str_to_color(colorstring, &red, &grn, &blu) == 1) { custom_rgb = TRUE; G_debug(3, "element:%d cat %d r:%d g:%d b:%d", line, cat, red, grn, blu); } else { custom_rgb = FALSE; G_warning(_("Error in color definition column (%s), element %d " "with cat %d: colorstring [%s]"), rgb_column, line, cat, colorstring); } } else { custom_rgb = FALSE; G_warning(_("Error in color definition column (%s), element %d with cat %d"), rgb_column, line, cat); } } } /* end if cat */ else { custom_rgb = FALSE; } } /* end if table_colors_flag */ /* random colors */ if (cats_color_flag) { custom_rgb = FALSE; if (Clist->field > 0) { cat = Vect_get_line_cat(Map, line, Clist->field); if (cat >= 0) { G_debug(3, "display element %d, cat %d", line, cat); /* fetch color number from category */ which = (cat % palette_ncolors); G_debug(3, "cat:%d which color:%d r:%d g:%d b:%d", cat, which, palette[which].R, palette[which].G, palette[which].B); custom_rgb = TRUE; red = palette[which].R; grn = palette[which].G; blu = palette[which].B; } } else if (Cats->n_cats > 0) { /* fetch color number from layer */ which = (Cats->field[0] % palette_ncolors); G_debug(3, "layer:%d which color:%d r:%d g:%d b:%d", Cats->field[0], which, palette[which].R, palette[which].G, palette[which].B); custom_rgb = TRUE; red = palette[which].R; grn = palette[which].G; blu = palette[which].B; } } if (nrec_width) { /* only first category */ cat = Vect_get_line_cat(Map, line, (Clist->field > 0 ? Clist->field : (Cats->n_cats > 0 ? Cats->field[0] : 1))); if (cat >= 0) { G_debug(3, "display element %d, cat %d", line, cat); /* Read line width from db for current area # */ if (db_CatValArray_get_value(&cvarr_width, cat, &cv_width) != DB_OK) { width = default_width; } else { width = width_scale * (cvarr_width.ctype == DB_C_TYPE_INT ? cv_width->val. i : (int)cv_width->val.d); if (width < 0) { G_warning(_("Error in line width column (%s), element %d " "with cat %d: line width [%d]"), width_column, line, cat, width); width = default_width; } } } /* end if cat */ else { width = default_width; } D_line_width(width); } /* end if nrec_width */ /* enough of the prep work, lets start plotting stuff */ x = Points->x; y = Points->y; if ((ltype & GV_POINTS) && Symb != NULL) { if (!(color || fcolor || custom_rgb)) continue; x0 = D_u_to_d_col(x[0]); y0 = D_u_to_d_row(y[0]); /* skip if the point is outside of the display window */ /* xy<0 tests make it go ever-so-slightly faster */ if (x0 < 0 || y0 < 0 || x0 > D_get_d_east() || x0 < D_get_d_west() || y0 > D_get_d_south() || y0 < D_get_d_north()) continue; /* use random or RGB column color if given, otherwise reset */ /* centroids always use default color to stand out from underlying area */ if (custom_rgb && (ltype != GV_CENTROID)) { primary_color->r = (unsigned char)red; primary_color->g = (unsigned char)grn; primary_color->b = (unsigned char)blu; D_symbol2(Symb, x0, y0, primary_color, line_color); } else D_symbol(Symb, x0, y0, line_color, fill_color); } else if (color || custom_rgb) { if (!table_colors_flag && !cats_color_flag) D_RGB_color(color->r, color->g, color->b); else { if (custom_rgb) D_RGB_color((unsigned char)red, (unsigned char)grn, (unsigned char)blu); else D_RGB_color(color->r, color->g, color->b); } /* Plot the lines */ if (Points->n_points == 1) /* line with one coor */ D_polydots_abs(x, y, Points->n_points); else /*use different user defined render methods */ D_polyline_abs(x, y, Points->n_points); } } Vect_destroy_line_struct(Points); Vect_destroy_cats_struct(Cats); return 0; /* not reached */ }
void D_set_clip_window_to_map_window(void) { D_set_clip_window( D_get_d_north(), D_get_d_south(), D_get_d_west(), D_get_d_east()); }
int main(int argc, char *argv[]) { const char *name; char outfile[GNAME_MAX]; int fd, projection; char buf[512], buf1[1024], buf2[1024]; int screen_x, screen_y; int i, k; int frame_start = 0; double e1, e2, n1, n2; RASTER_MAP_TYPE data_type; struct Cell_head window; struct { struct Option *opt1, *route, *name, *output, *dist, *ht, *frames, *start; struct Flag *f, *c, *k, *o, *e; } parm; struct GModule *module; G_gisinit(argv[0]); /* Set description */ module = G_define_module(); G_add_keyword(_("miscellaneous")); G_add_keyword(_("graphics")); G_add_keyword(_("raster")); G_add_keyword(_("raster3d")); G_add_keyword(_("vector")); G_add_keyword(_("visualization")); module->description = _("Creates fly-through script to run in NVIZ."); parm.opt1 = G_define_standard_option(G_OPT_R_INPUT); parm.output = G_define_standard_option(G_OPT_F_OUTPUT); parm.output->description = _("Name of output script"); parm.name = G_define_option(); parm.name->key = "name"; parm.name->type = TYPE_STRING; parm.name->required = NO; parm.name->description = _("Prefix of output images (default = NVIZ)"); parm.route = G_define_option(); parm.route->key = "route"; parm.route->type = TYPE_STRING; parm.route->required = NO; parm.route->multiple = YES; parm.route->key_desc = "east,north"; parm.route->description = _("Route coordinates (east,north)"); parm.dist = G_define_option(); parm.dist->key = "dist"; parm.dist->type = TYPE_DOUBLE; parm.dist->required = YES; parm.dist->description = _("Camera layback distance (in map units)"); parm.ht = G_define_option(); parm.ht->key = "ht"; parm.ht->type = TYPE_DOUBLE; parm.ht->required = YES; parm.ht->description = _("Camera height above terrain"); parm.frames = G_define_option(); parm.frames->key = "frames"; parm.frames->type = TYPE_INTEGER; parm.frames->required = YES; parm.frames->description = _("Number of frames"); parm.start = G_define_option(); parm.start->key = "start"; parm.start->type = TYPE_INTEGER; parm.start->required = NO; parm.start->description = _("Start frame number (default=0)"); parm.f = G_define_flag(); parm.f->key = 'f'; parm.f->description = _("Full render -- Save images"); parm.c = G_define_flag(); parm.c->key = 'c'; parm.c->description = _("Fly at constant elevation (ht)"); parm.k = G_define_flag(); parm.k->key = 'k'; parm.k->description = _("Include command in the script to output a KeyFrame file"); parm.o = G_define_flag(); parm.o->key = 'o'; parm.o->description = _("Render images off-screen"); parm.e = G_define_flag(); parm.e->key = 'e'; parm.e->description = _("Enable vector and sites drawing"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); /* check arguments */ if (!parm.route->answer) G_fatal_error(_("Either -i flag and/or route parameter must be used")); /* get GRASS parameters */ G_get_window(&window); projection = G_projection(); D_do_conversions(&window, 0, 1, 0, 1); /* setup screen coords */ screen_x = ((int)D_get_d_west() + (int)D_get_d_east()) / 2; screen_y = ((int)D_get_d_north() + (int)D_get_d_south()) / 2; /* get camera parameters */ DIST = atof(parm.dist->answer); HT = atof(parm.ht->answer); no_frames = atoi(parm.frames->answer); if (parm.start->answer) frame_start = atoi(parm.start->answer); if (parm.c->answer) height_flag = 1; if (parm.k->answer) key_frames = 1; if (parm.o->answer && !parm.f->answer) G_fatal_error(_("Off-screen only available with full render mode")); if (parm.o->answer) off_screen = 1; /* Initialize coords */ e1 = e2 = n1 = n2 = -9999.; G_begin_distance_calculations(); /* Open Input File for reading */ name = parm.opt1->answer; /* Open Raster File */ fd = Rast_open_old(name, ""); /* Set Image name */ if (parm.name->answer) sprintf(img_name, "%s", parm.name->answer); else sprintf(img_name, "NVIZ"); /* Open ASCII file for output */ /* append ".nvscr" to filename if it doesn't already have it */ strncpy(outfile, parm.output->answer, GNAME_MAX - 7); outfile[GNAME_MAX - 7] = '\0'; /* strncpy() doesn't null terminate the string */ if (strcmp(&outfile[strlen(outfile) - 6], ".nvscr") != 0) strcat(outfile, ".nvscr"); if (NULL == (fp = fopen(outfile, "w"))) G_fatal_error(_("Unable to open file <%s>"), outfile); /* Get Raster Type */ data_type = Rast_get_map_type(fd); /* Done with file */ /* Output initial startup stuff */ sprintf(buf1, "## REGION: n=%f s=%f e=%f w=%f\n## Input=%s Dist=%f Ht=%f\n", window.north, window.south, window.east, window.west, outfile, DIST, HT); sprintf(buf2, "\nset FRAMES %d\n", no_frames); strcat(buf1, buf2); fprintf(fp, "%s", buf1); sprintf(buf1, "SendScriptLine \"Nclear_keys\""); sprintf(buf2, "\nSendScriptLine \"Nupdate_frames\""); strcat(buf1, buf2); fprintf(fp, "%s", buf1); sprintf(buf1, "\nSendScriptLine \"Nset_numsteps $FRAMES\""); sprintf(buf2, "\nSendScriptLine \"Nupdate_frames\"\n"); strcat(buf1, buf2); fprintf(fp, "%s", buf1); /* Use Linear mode for smooth frame transition */ sprintf(buf1, "\nSendScriptLine \"Nset_interp_mode linear\""); sprintf(buf2, "\nSendScriptLine \"Nupdate_frames\"\n\n"); strcat(buf1, buf2); fprintf(fp, "%s", buf1); /* eanble vector and sites drawing */ if (parm.e->answer) { sprintf(buf1, "\nSendScriptLine \"Nshow_vect on\""); sprintf(buf2, "\nSendScriptLine \"Nshow_sites on\"\n\n"); strcat(buf1, buf2); fprintf(fp, "%s", buf1); } /* Coords from Command Line */ for (i = 0; parm.route->answers[i]; i += 2) { /* Test for number coordinate pairs */ k = i; } if (k < 6) { /* Only one coordinate pair supplied */ G_fatal_error(_("You must provide at least four points %d"), k); } else { for (i = 0; i <= k - 2; i += 2) { sscanf(parm.route->answers[i], "%lf", &e1); sscanf(parm.route->answers[i + 1], "%lf", &n1); sscanf(parm.route->answers[i + 2], "%lf", &e2); sscanf(parm.route->answers[i + 3], "%lf", &n2); /* Get profile info */ do_profile(e1, e2, n1, n2, name, fd, data_type); /* Get last coord */ if (i == k - 2) do_profile(e2, e2, n2, n2, name, fd, data_type); } } /* done with coordinates */ /* Output final part of script */ /* generate key-frame script */ if (key_frames) { strcpy(buf, outfile); buf[strlen(outfile) - 6] = '\0'; /* skip extension */ strcat(buf, ".kanim"); fprintf(fp, "\n## The following saves the animation to a format\n"); fprintf(fp, "## suitable for editing with the kanimator panel\n"); fprintf(fp, "SendScriptLine \"Nprint_keys %s\"\n", buf); fprintf(fp, "puts \"Saving Key Frame file %s\"\n", buf); } /* output off-screen option */ if (off_screen) { fprintf(fp, "\n## Off screen rendering enabled \n"); fprintf(fp, "## Ensure main window is minimized before running\n"); fprintf(fp, "SendScriptLine \"Noff_screen 1\"\n"); } fprintf(fp, "\n\nset num %d", frame_start); fprintf(fp, "\n\nfor {set frame 1} {$frame <= $FRAMES} {incr frame} {"); if (parm.f->answer) { /* Full render and save */ fprintf(fp, "\nset name %s", img_name); fprintf(fp, "\nset num2 [format \"\%%04d\" $num]"); fprintf(fp, "\nappend name $num2 \".ppm\""); fprintf(fp, "\nSendScriptLine \"Ndo_framestep $frame 1\""); fprintf(fp, "\nSendScriptLine \"Nwrite_ppm $name \""); fprintf(fp, "\nincr num"); }
int main(int argc, char **argv) { char *mapset; int ret, level; int i, stat = 0, type, display; int chcat = 0; int r, g, b; int has_color, has_fcolor; struct color_rgb color, fcolor; double size; int default_width; double width_scale; int verbose = FALSE; double minreg, maxreg, reg; char map_name[128]; struct GModule *module; struct Option *map_opt; struct Option *color_opt, *fcolor_opt, *rgbcol_opt, *zcol_opt; struct Option *type_opt, *display_opt; struct Option *icon_opt, *size_opt, *sizecolumn_opt, *rotcolumn_opt; struct Option *where_opt; struct Option *field_opt, *cat_opt, *lfield_opt; struct Option *lcolor_opt, *bgcolor_opt, *bcolor_opt; struct Option *lsize_opt, *font_opt, *xref_opt, *yref_opt; struct Option *attrcol_opt, *maxreg_opt, *minreg_opt; struct Option *width_opt, *wcolumn_opt, *wscale_opt; struct Option *render_opt; struct Flag *verbose_flag; /* please remove before GRASS 7 released */ struct Flag *id_flag, *table_acolors_flag, *cats_acolors_flag, *x_flag, *zcol_flag; struct cat_list *Clist; int *cats, ncat; LATTR lattr; struct Map_info Map; struct field_info *fi; dbDriver *driver; dbHandle handle; struct Cell_head window; BOUND_BOX box; double overlap; /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); module->keywords = _("display, vector"); module->description = _("Displays user-specified vector map " "in the active graphics frame."); map_opt = G_define_standard_option(G_OPT_V_MAP); display_opt = G_define_option(); display_opt->key = "display"; display_opt->type = TYPE_STRING; display_opt->required = YES; display_opt->multiple = YES; display_opt->answer = "shape"; display_opt->options = "shape,cat,topo,dir,attr,zcoor"; display_opt->description = _("Display"); display_opt->descriptions = _("shape;Display geometry of features;" "cat;Display category numbers of features;" "topo;Display topology information (nodes, edges);" "dir;Display direction of linear features;" "attr;Display selected attribute based on 'attrcol';" "zcoor;Display z-coordinate of features (only for 3D vector maps)"); /* Query */ type_opt = G_define_standard_option(G_OPT_V_TYPE); type_opt->answer = "point,line,boundary,centroid,area,face"; type_opt->options = "point,line,boundary,centroid,area,face"; type_opt->guisection = _("Selection"); field_opt = G_define_standard_option(G_OPT_V_FIELD); field_opt->label = _("Layer number (if -1, all layers are displayed)"); field_opt->gisprompt = "old_layer,layer,layer_all"; field_opt->guisection = _("Selection"); cat_opt = G_define_standard_option(G_OPT_V_CATS); cat_opt->guisection = _("Selection"); where_opt = G_define_standard_option(G_OPT_WHERE); where_opt->guisection = _("Selection"); /* Colors */ color_opt = G_define_option(); color_opt->key = "color"; color_opt->type = TYPE_STRING; color_opt->answer = DEFAULT_FG_COLOR; color_opt->label = _("Feature color"); color_opt->guisection = _("Colors"); color_opt->gisprompt = "old_color,color,color_none"; color_opt->description = _("Either a standard GRASS color, R:G:B triplet, or \"none\""); fcolor_opt = G_define_option(); fcolor_opt->key = "fcolor"; fcolor_opt->type = TYPE_STRING; fcolor_opt->answer = "200:200:200"; fcolor_opt->label = _("Area fill color"); fcolor_opt->guisection = _("Colors"); fcolor_opt->gisprompt = "old_color,color,color_none"; fcolor_opt->description = _("Either a standard GRASS color, R:G:B triplet, or \"none\""); rgbcol_opt = G_define_standard_option(G_OPT_COLUMN); rgbcol_opt->key = "rgb_column"; rgbcol_opt->guisection = _("Colors"); rgbcol_opt->description = _("Name of color definition column (for use with -a flag)"); rgbcol_opt->answer = "GRASSRGB"; zcol_opt = G_define_option(); zcol_opt->key = "zcolor"; zcol_opt->key_desc = "style"; zcol_opt->type = TYPE_STRING; zcol_opt->required = NO; zcol_opt->description = _("Type of color table (for use with -z flag)"); zcol_opt->answer = "terrain"; zcol_opt->guisection = _("Colors"); /* Lines */ width_opt = G_define_option(); width_opt->key = "width"; width_opt->type = TYPE_INTEGER; width_opt->answer = "0"; width_opt->guisection = _("Lines"); width_opt->description = _("Line width"); wcolumn_opt = G_define_standard_option(G_OPT_COLUMN); wcolumn_opt->key = "wcolumn"; wcolumn_opt->guisection = _("Lines"); wcolumn_opt->description = _("Name of column for line widths (these values will be scaled by wscale)"); wscale_opt = G_define_option(); wscale_opt->key = "wscale"; wscale_opt->type = TYPE_DOUBLE; wscale_opt->answer = "1"; wscale_opt->guisection = _("Lines"); wscale_opt->description = _("Scale factor for wcolumn"); /* Symbols */ icon_opt = G_define_option(); icon_opt->key = "icon"; icon_opt->type = TYPE_STRING; icon_opt->required = NO; icon_opt->multiple = NO; icon_opt->guisection = _("Symbols"); icon_opt->answer = "basic/x"; /* This could also use ->gisprompt = "old,symbol,symbol" instead of ->options */ icon_opt->options = icon_files(); icon_opt->description = _("Point and centroid symbol"); size_opt = G_define_option(); size_opt->key = "size"; size_opt->type = TYPE_DOUBLE; size_opt->answer = "5"; size_opt->guisection = _("Symbols"); size_opt->label = _("Symbol size"); size_opt->description = _("When used with the size_column option this becomes the scale factor"); sizecolumn_opt = G_define_standard_option(G_OPT_COLUMN); sizecolumn_opt->key = "size_column"; sizecolumn_opt->guisection = _("Symbols"); sizecolumn_opt->description = _("Name of numeric column containing symbol size"); rotcolumn_opt = G_define_standard_option(G_OPT_COLUMN); rotcolumn_opt->key = "rot_column"; rotcolumn_opt->guisection = _("Symbols"); rotcolumn_opt->label = _("Name of numeric column containing symbol rotation angle"); rotcolumn_opt->description = _("Measured in degrees CCW from east"); /* Labels */ lfield_opt = G_define_standard_option(G_OPT_V_FIELD); lfield_opt->key = "llayer"; lfield_opt->guisection = _("Labels"); lfield_opt->description = _("Layer number for labels (default: the given layer number)"); attrcol_opt = G_define_standard_option(G_OPT_COLUMN); attrcol_opt->key = "attrcol"; attrcol_opt->multiple = NO; /* or fix attr.c, around line 102 */ attrcol_opt->guisection = _("Labels"); attrcol_opt->description = _("Name of column to be displayed"); lcolor_opt = G_define_option(); lcolor_opt->key = "lcolor"; lcolor_opt->type = TYPE_STRING; lcolor_opt->answer = "red"; lcolor_opt->label = _("Label color"); lcolor_opt->guisection = _("Labels"); lcolor_opt->gisprompt = "old_color,color,color"; lcolor_opt->description = _("Either a standard color name or R:G:B triplet"); bgcolor_opt = G_define_option(); bgcolor_opt->key = "bgcolor"; bgcolor_opt->type = TYPE_STRING; bgcolor_opt->answer = "none"; bgcolor_opt->guisection = _("Labels"); bgcolor_opt->label = _("Label background color"); bgcolor_opt->gisprompt = "old_color,color,color_none"; bgcolor_opt->description = _("Either a standard GRASS color, R:G:B triplet, or \"none\""); bcolor_opt = G_define_option(); bcolor_opt->key = "bcolor"; bcolor_opt->type = TYPE_STRING; bcolor_opt->answer = "none"; bcolor_opt->guisection = _("Labels"); bcolor_opt->label = _("Label border color"); bcolor_opt->gisprompt = "old_color,color,color_none"; bcolor_opt->description = _("Either a standard GRASS color, R:G:B triplet, or \"none\""); lsize_opt = G_define_option(); lsize_opt->key = "lsize"; lsize_opt->type = TYPE_INTEGER; lsize_opt->answer = "8"; lsize_opt->guisection = _("Labels"); lsize_opt->description = _("Label size (pixels)"); font_opt = G_define_option(); font_opt->key = "font"; font_opt->type = TYPE_STRING; font_opt->guisection = _("Labels"); font_opt->description = _("Font name"); xref_opt = G_define_option(); xref_opt->key = "xref"; xref_opt->type = TYPE_STRING; xref_opt->guisection = _("Labels"); xref_opt->answer = "left"; xref_opt->options = "left,center,right"; xref_opt->description = _("Label horizontal justification"); yref_opt = G_define_option(); yref_opt->key = "yref"; yref_opt->type = TYPE_STRING; yref_opt->guisection = _("Labels"); yref_opt->answer = "center"; yref_opt->options = "top,center,bottom"; yref_opt->description = _("Label vertical justification"); minreg_opt = G_define_option(); minreg_opt->key = "minreg"; minreg_opt->type = TYPE_DOUBLE; minreg_opt->required = NO; minreg_opt->description = _("Minimum region size (average from height and width) " "when map is displayed"); maxreg_opt = G_define_option(); maxreg_opt->key = "maxreg"; maxreg_opt->type = TYPE_DOUBLE; maxreg_opt->required = NO; maxreg_opt->description = _("Maximum region size (average from height and width) " "when map is displayed"); render_opt = G_define_option(); render_opt->key = "render"; render_opt->type = TYPE_STRING; render_opt->required = NO; render_opt->multiple = NO; render_opt->answer = "c"; render_opt->options = "g,r,d,c,l"; render_opt->description = _("Rendering method for filled polygons"); render_opt->descriptions = _("g;use the libgis render functions (features: clipping);" "r;use the raster graphics library functions (features: polylines);" "d;use the display library basic functions (features: polylines);" "c;use the display library clipping functions (features: clipping);" "l;use the display library culling functions (features: culling, polylines)"); /* please remove before GRASS 7 released */ verbose_flag = G_define_flag(); verbose_flag->key = 'v'; verbose_flag->description = _("Run verbosely"); /* Colors */ table_acolors_flag = G_define_flag(); table_acolors_flag->key = 'a'; table_acolors_flag->guisection = _("Colors"); table_acolors_flag->description = _("Get colors from map table column (of form RRR:GGG:BBB)"); cats_acolors_flag = G_define_flag(); cats_acolors_flag->key = 'c'; cats_acolors_flag->guisection = _("Colors"); cats_acolors_flag->description = _("Random colors according to category number " "(or layer number if 'layer=-1' is given)"); /* Query */ id_flag = G_define_flag(); id_flag->key = 'i'; id_flag->guisection = _("Selection"); id_flag->description = _("Use values from 'cats' option as feature id"); x_flag = G_define_flag(); x_flag->key = 'x'; x_flag->description = _("Don't add to list of vectors and commands in monitor " "(it won't be drawn if the monitor is refreshed)"); zcol_flag = G_define_flag(); zcol_flag->key = 'z'; zcol_flag->description = _("Colorize polygons according to z height"); zcol_flag->guisection = _("Colors"); /* Check command line */ if (G_parser(argc, argv)) exit(EXIT_FAILURE); if (G_strcasecmp(render_opt->answer, "g") == 0) render = RENDER_GPP; else if (G_strcasecmp(render_opt->answer, "r") == 0) render = RENDER_RPA; else if (G_strcasecmp(render_opt->answer, "d") == 0) render = RENDER_DP; else if (G_strcasecmp(render_opt->answer, "c") == 0) render = RENDER_DPC; else if (G_strcasecmp(render_opt->answer, "l") == 0) render = RENDER_DPL; else render = RENDER_GPP; /* please remove -v flag before GRASS 7 released */ if (verbose_flag->answer) { G_putenv("GRASS_VERBOSE", "3"); G_warning(_("The '-v' flag is superseded and will be removed " "in future. Please use '--verbose' instead.")); } /* but keep this */ if (G_verbose() > G_verbose_std()) verbose = TRUE; G_get_set_window(&window); if (R_open_driver() != 0) G_fatal_error(_("No graphics device selected")); /* Read map options */ /* Check min/max region */ reg = ((window.east - window.west) + (window.north - window.south)) / 2; if (minreg_opt->answer) { minreg = atof(minreg_opt->answer); if (reg < minreg) { G_message(_("Region size is lower than minreg, nothing displayed.")); D_add_to_list(G_recreate_command()); exit(EXIT_SUCCESS); } } if (maxreg_opt->answer) { maxreg = atof(maxreg_opt->answer); if (reg > maxreg) { G_message(_("Region size is greater than maxreg, nothing displayed.")); D_add_to_list(G_recreate_command()); exit(EXIT_SUCCESS); } } G_strcpy(map_name, map_opt->answer); default_width = atoi(width_opt->answer); if (default_width < 0) default_width = 0; width_scale = atof(wscale_opt->answer); if (table_acolors_flag->answer && cats_acolors_flag->answer) { cats_acolors_flag->answer = '\0'; G_warning(_("The '-c' and '-a' flags cannot be used together, " "the '-c' flag will be ignored!")); } color = G_standard_color_rgb(WHITE); ret = G_str_to_color(color_opt->answer, &r, &g, &b); if (ret == 1) { has_color = 1; color.r = r; color.g = g; color.b = b; } else if (ret == 2) { /* none */ has_color = 0; } else if (ret == 0) { /* error */ G_fatal_error(_("Unknown color: [%s]"), color_opt->answer); } fcolor = G_standard_color_rgb(WHITE); ret = G_str_to_color(fcolor_opt->answer, &r, &g, &b); if (ret == 1) { has_fcolor = 1; fcolor.r = r; fcolor.g = g; fcolor.b = b; } else if (ret == 2) { /* none */ has_fcolor = 0; } else if (ret == 0) { /* error */ G_fatal_error(_("Unknown color: '%s'"), fcolor_opt->answer); } size = atof(size_opt->answer); /* Make sure map is available */ mapset = G_find_vector2(map_name, ""); if (mapset == NULL) G_fatal_error(_("Vector map <%s> not found"), map_name); /* if where_opt was specified select categories from db * otherwise parse cat_opt */ Clist = Vect_new_cat_list(); Clist->field = atoi(field_opt->answer); /* open vector */ level = Vect_open_old(&Map, map_name, mapset); if (where_opt->answer) { if (Clist->field < 1) G_fatal_error(_("'layer' must be > 0 for 'where'.")); chcat = 1; if ((fi = Vect_get_field(&Map, Clist->field)) == NULL) G_fatal_error(_("Database connection not defined")); if (fi != NULL) { driver = db_start_driver(fi->driver); if (driver == NULL) G_fatal_error(_("Unable to start driver <%s>"), fi->driver); db_init_handle(&handle); db_set_handle(&handle, fi->database, NULL); if (db_open_database(driver, &handle) != DB_OK) G_fatal_error(_("Unable to open database <%s>"), fi->database); ncat = db_select_int(driver, fi->table, fi->key, where_opt->answer, &cats); db_close_database(driver); db_shutdown_driver(driver); Vect_array_to_cat_list(cats, ncat, Clist); } } else if (cat_opt->answer) { if (Clist->field < 1) G_fatal_error(_("'layer' must be > 0 for 'cats'.")); chcat = 1; ret = Vect_str_to_cat_list(cat_opt->answer, Clist); if (ret > 0) G_warning(_("%d errors in cat option"), ret); } type = Vect_option_to_types(type_opt); i = 0; display = 0; while (display_opt->answers[i]) { switch (display_opt->answers[i][0]) { case 's': display |= DISP_SHAPE; break; case 'c': display |= DISP_CAT; break; case 't': display |= DISP_TOPO; break; case 'd': display |= DISP_DIR; break; case 'a': display |= DISP_ATTR; break; case 'z': display |= DISP_ZCOOR; break; } i++; } /* Read label options */ if (lfield_opt->answer != NULL) lattr.field = atoi(lfield_opt->answer); else lattr.field = Clist->field; lattr.color.R = lattr.color.G = lattr.color.B = 255; if (G_str_to_color(lcolor_opt->answer, &r, &g, &b)) { lattr.color.R = r; lattr.color.G = g; lattr.color.B = b; } lattr.has_bgcolor = 0; if (G_str_to_color(bgcolor_opt->answer, &r, &g, &b) == 1) { lattr.has_bgcolor = 1; lattr.bgcolor.R = r; lattr.bgcolor.G = g; lattr.bgcolor.B = b; } lattr.has_bcolor = 0; if (G_str_to_color(bcolor_opt->answer, &r, &g, &b) == 1) { lattr.has_bcolor = 1; lattr.bcolor.R = r; lattr.bcolor.G = g; lattr.bcolor.B = b; } lattr.size = atoi(lsize_opt->answer); lattr.font = font_opt->answer; switch (xref_opt->answer[0]) { case 'l': lattr.xref = LLEFT; break; case 'c': lattr.xref = LCENTER; break; case 'r': lattr.xref = LRIGHT; break; } switch (yref_opt->answer[0]) { case 't': lattr.yref = LTOP; break; case 'c': lattr.yref = LCENTER; break; case 'b': lattr.yref = LBOTTOM; break; } D_setup(0); G_setup_plot(D_get_d_north(), D_get_d_south(), D_get_d_west(), D_get_d_east(), D_move_abs, D_cont_abs); if (verbose) G_message(_("Plotting ...")); if (level >= 2) Vect_get_map_box(&Map, &box); if (level >= 2 && (window.north < box.S || window.south > box.N || window.east < box.W || window.west > G_adjust_easting(box.E, &window))) { G_message(_("The bounding box of the map is outside the current region, " "nothing drawn.")); stat = 0; } else { overlap = G_window_percentage_overlap(&window, box.N, box.S, box.E, box.W); G_debug(1, "overlap = %f \n", overlap); if (overlap < 1) Vect_set_constraint_region(&Map, window.north, window.south, window.east, window.west, PORT_DOUBLE_MAX, -PORT_DOUBLE_MAX); /* default line width */ if (!wcolumn_opt->answer) D_line_width(default_width); if (type & GV_AREA) { if (level >= 2) { if (display & DISP_SHAPE) { stat = darea(&Map, Clist, has_color ? &color : NULL, has_fcolor ? &fcolor : NULL, chcat, (int)id_flag->answer, table_acolors_flag->answer, cats_acolors_flag->answer, &window, rgbcol_opt->answer, default_width, wcolumn_opt->answer, width_scale, zcol_flag->answer, zcol_opt->answer); } if (wcolumn_opt->answer) D_line_width(default_width); } else G_warning(_("Unable to display areas, topology not available")); } if (display & DISP_SHAPE) { if (id_flag->answer && level < 2) { G_warning(_("Unable to display lines by id, topology not available")); } else { stat = plot1(&Map, type, Clist, has_color ? &color : NULL, has_fcolor ? &fcolor : NULL, chcat, icon_opt->answer, size, sizecolumn_opt->answer, rotcolumn_opt->answer, (int)id_flag->answer, table_acolors_flag->answer, cats_acolors_flag->answer, rgbcol_opt->answer, default_width, wcolumn_opt->answer, width_scale, zcol_flag->answer, zcol_opt->answer); if (wcolumn_opt->answer) D_line_width(default_width); } } if (has_color) { R_RGB_color(color.r, color.g, color.b); if (display & DISP_DIR) stat = dir(&Map, type, Clist, chcat, size); } /* reset line width: Do we need to get line width from display * driver (not implemented)? It will help restore previous line * width (not just 0) determined by another module (e.g., * d.linewidth). */ if (!wcolumn_opt->answer) R_line_width(0); if (display & DISP_CAT) stat = label(&Map, type, Clist, &lattr, chcat); if (display & DISP_ATTR) stat = attr(&Map, type, attrcol_opt->answer, Clist, &lattr, chcat); if (display & DISP_ZCOOR) stat = zcoor(&Map, type, &lattr); if (display & DISP_TOPO) { if (level >= 2) stat = topo(&Map, type, &lattr); else G_warning(_("Unable to display topology, not available")); } } if (!x_flag->answer) { D_add_to_list(G_recreate_command()); D_set_dig_name(G_fully_qualified_name(map_name, mapset)); D_add_to_dig_list(G_fully_qualified_name(map_name, mapset)); } R_close_driver(); if (verbose) G_done_msg(" "); Vect_close(&Map); Vect_destroy_cat_list(Clist); exit(stat); }