/*! \brief Graphics frame setup Sets the source coordinate system to match the destination coordinate system, so that D_* functions use the same coordinate system as R_* functions. If <b>clear</b> is true, the frame is cleared (same as running <i>d.erase</i>). Otherwise, it is not cleared. \param clear non-zero code to clear the frame */ void D_setup_unity(int clear) { double dt, db, dl, dr; D_get_window(&dt, &db, &dl, &dr); D_set_src(dt, db, dl, dr); D_set_dst(dt, db, dl, dr); D_update_conversions(); if (clear) D_erase(DEFAULT_BG_COLOR); }
/*! \brief Graphics frame setup This is a high level D call. It does a full setup for the current graphics frame. Note: Connection to driver must already be made. Sets the source coordinate system to the current region, and adjusts the destination coordinate system to preserve the aspect ratio. Performs a full setup for the current graphics frame: - Makes sure there is a current graphics frame (will create a full-screen one, if not); - Sets the region coordinates so that the graphics frame and the active module region agree (may change active module region to do this); and - Performs graphic frame/region coordinate conversion initialization. If <b>clear</b> is true, the frame is cleared (same as running <i>d.erase</i>.) Otherwise, it is not cleared. \param clear 1 to clear frame (visually and coordinates) */ void D_setup(int clear) { struct Cell_head region; double dt, db, dl, dr; D_get_window(&dt, &db, &dl, &dr); G_get_set_window(®ion); Rast_set_window(®ion); D_do_conversions(®ion, dt, db, dl, dr); if (clear) D_erase(DEFAULT_BG_COLOR); }
/*! \brief Sets source coordinate system Sets the source coordinate system to its arguments, and if the <b>fit</b> argument is non-zero, adjusts the destination coordinate system to preserve the aspect ratio. If <b>clear</b> is true, the frame is cleared (same as running <i>d.erase</i>). Otherwise, it is not cleared. \param clear non-zero code to clear the frame \param fit non-zero code to adjust destination coordinate system \param s_top \param s_bottom \param s_left \param s_right */ void D_setup2(int clear, int fit, double st, double sb, double sl, double sr) { double dt, db, dl, dr; D_get_window(&dt, &db, &dl, &dr); D_set_src(st, sb, sl, sr); D_set_dst(dt, db, dl, dr); if (fit) D_fit_d_to_u(); D_update_conversions(); if (clear) D_erase(DEFAULT_BG_COLOR); }
int main(int argc, char *argv[]) { struct GModule *module; struct Option *start_opt, *select_opt, *stop_opt, *output_opt, *width_opt, *height_opt, *bgcolor_opt, *res_opt; struct Flag *list_flag, *selected_flag, *select_flag, *release_flag, *cmd_flag, *truecolor_flag, *update_flag, *x_flag, *sfile_flag; int nopts, ret; const char *mon; G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("graphics")); G_add_keyword(_("monitors")); module->description = _("Controls graphics display monitors from the command line."); start_opt = G_define_option(); start_opt->key = "start"; start_opt->type = TYPE_STRING; start_opt->description = _("Name of monitor to start"); start_opt->options = "wx0,wx1,wx2,wx3,wx4,wx5,wx6,wx7,png,ps,html,cairo"; start_opt->guisection = _("Manage"); stop_opt = G_define_option(); stop_opt->key = "stop"; stop_opt->type = TYPE_STRING; stop_opt->description = _("Name of monitor to stop"); stop_opt->options = "wx0,wx1,wx2,wx3,wx4,wx5,wx6,wx7,png,ps,html,cairo"; stop_opt->guisection = _("Manage"); select_opt = G_define_option(); select_opt->key = "select"; select_opt->type = TYPE_STRING; select_opt->description = _("Name of monitor to select"); select_opt->options = "wx0,wx1,wx2,wx3,wx4,wx5,wx6,wx7,png,ps,html,cairo"; select_opt->guisection = _("Manage"); width_opt = G_define_option(); width_opt->key = "width"; width_opt->label = _("Width for display monitor if not set by GRASS_RENDER_WIDTH"); width_opt->description = _("Default value: 720"); width_opt->type = TYPE_INTEGER; width_opt->key_desc = "value"; width_opt->guisection = _("Settings"); height_opt = G_define_option(); height_opt->key = "height"; height_opt->label = _("Height for display monitor if not set by GRASS_RENDER_HEIGHT"); height_opt->description = _("Default value: 480"); height_opt->type = TYPE_INTEGER; height_opt->key_desc = "value"; height_opt->guisection = _("Settings"); res_opt = G_define_option(); res_opt->key = "resolution"; res_opt->label = _("Dimensions of display monitor versus current size"); res_opt->description = _("Example: resolution=2 enlarge display monitor twice to 1280x960"); res_opt->type = TYPE_INTEGER; res_opt->key_desc = "value"; res_opt->guisection = _("Settings"); bgcolor_opt = G_define_standard_option(G_OPT_CN); bgcolor_opt->key = "bgcolor"; bgcolor_opt->label = _("Background color"); bgcolor_opt->answer = DEFAULT_BG_COLOR; bgcolor_opt->guisection = _("Settings"); output_opt = G_define_standard_option(G_OPT_F_OUTPUT); output_opt->required = NO; output_opt->label = _("Name for output file (when starting new monitor)"); output_opt->description = _("Ignored for 'wx' monitors"); output_opt->guisection = _("Settings"); list_flag = G_define_flag(); list_flag->key = 'l'; list_flag->description = _("List running monitors and exit"); list_flag->guisection = _("Print"); selected_flag = G_define_flag(); selected_flag->key = 'p'; selected_flag->description = _("Print name of currently selected monitor and exit"); selected_flag->guisection = _("Print"); cmd_flag = G_define_flag(); cmd_flag->key = 'c'; cmd_flag->description = _("Print commands for currently selected monitor and exit"); cmd_flag->guisection = _("Print"); sfile_flag = G_define_flag(); sfile_flag->key = 'g'; sfile_flag->description = _("Print path to support files of currently selected monitor and exit"); select_flag = G_define_flag(); select_flag->key = 's'; select_flag->description = _("Do not automatically select when starting"); select_flag->guisection = _("Manage"); release_flag = G_define_flag(); release_flag->key = 'r'; release_flag->description = _("Release and stop currently selected monitor and exit"); release_flag->guisection = _("Manage"); truecolor_flag = G_define_flag(); truecolor_flag->key = 't'; truecolor_flag->description = _("Disable true colors"); truecolor_flag->guisection = _("Settings"); update_flag = G_define_flag(); update_flag->key = 'u'; update_flag->label = _("Open output file in update mode"); update_flag->description = _("Requires --overwrite flag"); update_flag->guisection = _("Settings"); x_flag = G_define_flag(); x_flag->key = 'x'; x_flag->label = _("Launch light-weight wx monitor without toolbars and statusbar"); x_flag->description = _("Requires 'start=wx0-7'"); x_flag->guisection = _("Settings"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); if (x_flag->answer && start_opt->answer && strncmp(start_opt->answer, "wx", 2) != 0) G_warning(_("Flag -%c has effect only for wx monitors (%s=wx0-7)"), x_flag->key, start_opt->key); if (selected_flag->answer || release_flag->answer || cmd_flag->answer || sfile_flag->answer) { if (list_flag->answer) G_warning(_("Flag -%c ignored"), list_flag->key); mon = G_getenv_nofatal("MONITOR"); if (mon) { if (selected_flag->answer) { G_verbose_message(_("Currently selected monitor:")); fprintf(stdout, "%s\n", mon); } else if (cmd_flag->answer) { G_message(_("List of commands for monitor <%s>:"), mon); list_cmd(mon, stdout); } else if (sfile_flag->answer) { list_files(mon, stdout); } else if (mon) { /* release */ G_unsetenv("MONITOR"); G_verbose_message(_("Monitor <%s> released"), mon); ret = stop_mon(mon); } } else G_important_message(_("No monitor selected")); exit(EXIT_SUCCESS); } if (list_flag->answer) { print_list(stdout); exit(EXIT_SUCCESS); } nopts = 0; if (start_opt->answer) nopts++; if (stop_opt->answer) nopts++; if (select_opt->answer) nopts++; if (nopts != 1) G_fatal_error(_("Either <%s>, <%s> or <%s> must be given"), start_opt->key, stop_opt->key, select_opt->key); if (output_opt->answer && (!start_opt->answer || strncmp(start_opt->answer, "wx", 2) == 0)) G_warning(_("Option <%s> ignored"), output_opt->key); if (start_opt->answer) { int width, height; width = width_opt->answer ? atoi(width_opt->answer) : 0; height = height_opt->answer ? atoi(height_opt->answer) : 0; if (width < 1) { char *env_width = getenv("GRASS_RENDER_WIDTH"); if (env_width) width = atoi(env_width); } if (height < 1) { char *env_height = getenv("GRASS_RENDER_HEIGHT"); if (env_height) height = atoi(env_height); } if (width < 1) width = DEFAULT_WIDTH; if (height < 1) height = DEFAULT_HEIGHT; if (res_opt->answer) { int res; res = atoi(res_opt->answer); width *= res; height *= res; } G_debug(1, "Monitor width/height = %d/%d", width, height); ret = start_mon(start_opt->answer, output_opt->answer, !select_flag->answer, width, height, bgcolor_opt->answer, !truecolor_flag->answer, x_flag->answer, update_flag->answer); if (output_opt->answer && !update_flag->answer) { D_open_driver(); D_setup_unity(0); D_erase(bgcolor_opt->answer); D_close_driver(); } } if (stop_opt->answer) ret = stop_mon(stop_opt->answer); if (select_opt->answer) ret = select_mon(select_opt->answer); if (ret != 0) exit(EXIT_FAILURE); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { int text_height; int text_width; struct Categories cats; struct Range range; struct Colors pcolors; char title[GNAME_MAX]; double tt, tb, tl, tr; double t, b, l, r; struct GModule *module; struct Option *opt1; struct Option *opt2, *bg_opt; struct Option *opt4; struct Option *opt5; struct Flag *flag1; struct Flag *flag2; struct Flag *flag3; /* Initialize the GIS calls */ G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("display")); G_add_keyword(_("histogram")); G_add_keyword(_("statistics")); module->description = _("Displays a histogram in the form of a pie or bar chart " "for a user-specified raster map."); opt1 = G_define_standard_option(G_OPT_R_MAP); opt1->description = _("Raster map for which histogram will be displayed"); opt4 = G_define_option(); opt4->key = "style"; opt4->description = _("Indicate if a pie or bar chart is desired"); opt4->type = TYPE_STRING; opt4->required = NO; opt4->options = "pie,bar"; opt4->answer = "bar"; /* The color option specifies the color for the labels, tic-marks, * and borders of the chart. */ opt2 = G_define_standard_option(G_OPT_C); opt2->label = _("Color for text and axes"); bg_opt = G_define_standard_option(G_OPT_CN); bg_opt->key = "bgcolor"; bg_opt->label = _("Background color"); bg_opt->answer = DEFAULT_BG_COLOR; #ifdef CAN_DO_AREAS opt3 = G_define_option(); opt3->key = "type"; opt3->description = _("Indicate if cell counts or map areas should be displayed"); opt3->type = TYPE_STRING; opt3->required = NO; opt3->answer = "count"; opt3->options = "count,area"; #endif opt5 = G_define_option(); opt5->key = "nsteps"; opt5->description = _("Number of steps to divide the data range into (fp maps only)"); opt5->type = TYPE_INTEGER; opt5->required = NO; opt5->answer = "255"; flag1 = G_define_flag(); flag1->key = 'n'; flag1->description = _("Display information for null cells"); flag3 = G_define_flag(); flag3->key = 'c'; flag3->description = _("Report for ranges defined in cats file (fp maps only)"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); map_name = opt1->answer; color = D_parse_color(opt2->answer, FALSE); type = COUNT; #ifdef CAN_DO_AREAS if (strcmp(opt3->answer, "count") == 0) type = COUNT; else type = AREA; #endif if (strcmp(opt4->answer, "bar") == 0) style = BAR; else style = PIE; if (sscanf(opt5->answer, "%d", &nsteps) != 1) G_fatal_error(_("Invalid number of steps: %s"), opt5->answer); cat_ranges = flag3->answer; if (cat_ranges && nsteps != 255) G_warning(_("When -C flag is set, the nsteps argument is ignored")); nodata = flag1->answer; if (Rast_read_colors(map_name, "", &pcolors) == -1) G_fatal_error(_("Color file for <%s> not available"), map_name); if (Rast_read_cats(map_name, "", &cats) == -1) G_fatal_error(_("Category file for <%s> not available"), map_name); if (Rast_read_range(map_name, "", &range) == -1) G_fatal_error(_("Range information for <%s> not available"), map_name); /* get the distribution statistics */ get_stats(map_name, &dist_stats); /* set up the graphics driver and initialize its color-table */ D_open_driver(); D_setup_unity(0); /* 0 = don't clear frame */ D_get_src(&t, &b, &l, &r); /* clear the frame, if requested to do so */ if (strcmp(bg_opt->answer, "none") != 0) D_erase(bg_opt->answer); /* draw a title for */ sprintf(title, "%s", map_name); text_height = (b - t) * 0.05; text_width = (r - l) * 0.05 * 0.50; D_text_size(text_width, text_height); D_get_text_box(title, &tt, &tb, &tl, &tr); D_pos_abs(l + (r - l) / 2 - (tr - tl) / 2, t + (b - t) * 0.07); D_use_color(color); D_text(title); /* plot the distributrion statistics */ if (style == PIE) pie(&dist_stats, &pcolors); else bar(&dist_stats, &pcolors); D_save_command(G_recreate_command()); D_close_driver(); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { int ret; struct GModule *module; struct Option *gisdbase_opt, *location_opt, *mapset_opt; struct Flag *f_add, *f_list; char *gisdbase_old, *location_old, *mapset_old; char *gisdbase_new, *location_new, *mapset_new; char *gis_lock; char *mapset_old_path, *mapset_new_path; char *lock_prog; char path[GPATH_MAX]; char *shell, *monitor; struct MON_CAP *cap; G_gisinit(argv[0]); module = G_define_module(); module->keywords = _("general, settings"); module->label = _("Changes current mapset."); module->description = _("Optionally create new mapset or list available mapsets in given location."); mapset_opt = G_define_option(); mapset_opt->key = "mapset"; mapset_opt->type = TYPE_STRING; mapset_opt->required = NO; mapset_opt->multiple = NO; mapset_opt->description = _("Name of mapset where to switch"); mapset_opt->guisection = _("Settings"); location_opt = G_define_option(); location_opt->key = "location"; location_opt->type = TYPE_STRING; location_opt->required = NO; location_opt->multiple = NO; location_opt->description = _("Location name (not location path)"); location_opt->guisection = _("Settings"); gisdbase_opt = G_define_option(); gisdbase_opt->key = "gisdbase"; gisdbase_opt->type = TYPE_STRING; gisdbase_opt->required = NO; gisdbase_opt->multiple = NO; gisdbase_opt->key_desc = "path"; gisdbase_opt->description = _("GIS data directory (full path to the directory where the new location is)"); gisdbase_opt->guisection = _("Settings"); f_add = G_define_flag(); f_add->key = 'c'; f_add->description = _("Create mapset if it doesn't exist"); f_add->answer = FALSE; f_add->guisection = _("Create"); f_list = G_define_flag(); f_list->key = 'l'; f_list->description = _("List available mapsets"); f_list->guisection = _("Print"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); if (!mapset_opt->answer && !f_list->answer) G_fatal_error(_("Either mapset= or -l must be used")); /* Store original values */ gisdbase_old = G__getenv("GISDBASE"); location_old = G__getenv("LOCATION_NAME"); mapset_old = G__getenv("MAPSET"); G_asprintf(&mapset_old_path, "%s/%s/%s", gisdbase_old, location_old, mapset_old); monitor = G__getenv("MONITOR"); /* New values */ if (gisdbase_opt->answer) gisdbase_new = gisdbase_opt->answer; else gisdbase_new = gisdbase_old; if (location_opt->answer) location_new = location_opt->answer; else location_new = location_old; if (f_list->answer) { char **ms; int nmapsets; G__setenv("LOCATION_NAME", location_new); G__setenv("GISDBASE", gisdbase_new); ms = G_available_mapsets(); for (nmapsets = 0; ms[nmapsets]; nmapsets++) { if (G__mapset_permissions(ms[nmapsets]) > 0) { fprintf(stdout, "%s ", ms[nmapsets]); } } fprintf(stdout, "\n"); exit(EXIT_SUCCESS); } mapset_new = mapset_opt->answer; G_asprintf(&mapset_new_path, "%s/%s/%s", gisdbase_new, location_new, mapset_new); /* TODO: this should be checked better (repeated '/' etc.) */ if (strcmp(mapset_old_path, mapset_new_path) == 0) G_fatal_error(_("<%s> is already the current mapset"), mapset_new); /* Check if the mapset exists and user is owner */ G_debug(2, "check : %s", mapset_new_path); ret = G__mapset_permissions2(gisdbase_new, location_new, mapset_new); switch (ret) { case 0: G_fatal_error(_("You don't have permission to use this mapset")); break; case -1: if (f_add->answer == TRUE) { G_debug(2, "Mapset %s doesn't exist, attempting to create it", mapset_new); G_make_mapset(gisdbase_new, location_new, mapset_new); } else G_fatal_error(_("The mapset does not exist. Use -c flag to create it.")); break; default: break; } /* Check if the mapset is in use */ gis_lock = getenv("GIS_LOCK"); if (!gis_lock) G_fatal_error(_("Unable to read GIS_LOCK environment variable")); G_asprintf(&lock_prog, "%s/etc/lock", G_gisbase()); sprintf(path, "%s/.gislock", mapset_new_path); G_debug(2, path); ret = G_spawn(lock_prog, lock_prog, path, gis_lock, NULL); G_debug(2, "lock result = %d", ret); G_free(lock_prog); /* Warning: the value returned by system() is not that returned by exit() in executed program * e.g. exit(1) -> 256 (multiplied by 256) */ if (ret != 0) G_fatal_error(_("%s is currently running GRASS in selected mapset or lock file cannot be checked"), G_whoami()); /* Erase monitors */ G_message(_("Erasing monitors...")); while ((cap = R_parse_monitorcap(MON_NEXT, "")) != NULL) { G__setenv("MONITOR", cap->name); R__open_quiet(); if (R_open_driver() == 0) { D_erase(DEFAULT_BG_COLOR); D_add_to_list("d.erase"); R_close_driver(); R_release_driver(); } } if (monitor) G_setenv("MONITOR", monitor); /* Clean temporary directory */ sprintf(path, "%s/etc/clean_temp", G_gisbase()); G_verbose_message(_("Cleaning up temporary files...")); G_spawn(path, "clean_temp", NULL); /* Reset variables */ G_setenv("GISDBASE", gisdbase_new); G_setenv("LOCATION_NAME", location_new); G_setenv("MAPSET", mapset_new); /* Remove old lock */ sprintf(path, "%s/.gislock", mapset_old_path); remove(path); G_free(mapset_old_path); G_important_message(_("Your shell continues to use the history for the old mapset")); if ((shell = getenv("SHELL"))) { if (strstr(shell, "bash")) { G_important_message(_("You can switch the history by commands:\n" "history -w; history -r %s/.bash_history; HISTFILE=%s/.bash_history"), mapset_new_path, mapset_new_path); } else if (strstr(shell, "tcsh")) { G_important_message(_("You can switch the history by commands:\n" "history -S; history -L %s/.history; setenv histfile=%s/.history"), mapset_new_path, mapset_new_path); } } G_message(_("Your current mapset is <%s>"), mapset_new); G_free(mapset_new_path); return (EXIT_SUCCESS); }