main.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. ****************************************************************************
  3. *
  4. * MODULE: d.info
  5. * AUTHOR(S): Glynn Clements
  6. * PURPOSE: Display information about the active display monitor
  7. * COPYRIGHT: (C) 2004-2015 by the GRASS Development Team
  8. *
  9. * This program is free software under the GNU General Public
  10. * License (>=v2). Read the file COPYING that comes with GRASS
  11. * for details.
  12. *
  13. *****************************************************************************/
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <dirent.h>
  17. #include <string.h>
  18. #include <grass/gis.h>
  19. #include <grass/display.h>
  20. #include <grass/glocale.h>
  21. int main(int argc, char *argv[])
  22. {
  23. struct GModule *module;
  24. struct Flag *rflag, *dflag, *fflag, *eflag, *bflag, *gflag;
  25. double st, sb, sl, sr;
  26. double ft, fb, fl, fr;
  27. G_gisinit(argv[0]);
  28. module = G_define_module();
  29. G_add_keyword(_("display"));
  30. G_add_keyword(_("graphics"));
  31. G_add_keyword(_("monitors"));
  32. module->label =
  33. _("Displays information about the active display monitor.");
  34. module->description =
  35. _("Display monitors are maintained by d.mon.");
  36. rflag = G_define_flag();
  37. rflag->key = 'r';
  38. rflag->description =
  39. _("Display screen rectangle (left, right, top, bottom)");
  40. dflag = G_define_flag();
  41. dflag->key = 'd';
  42. dflag->description = _("Display screen dimensions (width, height)");
  43. fflag = G_define_flag();
  44. fflag->key = 'f';
  45. fflag->description = _("Display active frame rectangle");
  46. eflag = G_define_flag();
  47. eflag->key = 'e';
  48. eflag->description = _("Display frame dimensions (width, height)");
  49. bflag = G_define_flag();
  50. bflag->key = 'b';
  51. bflag->description = _("Display screen rectangle of current region");
  52. gflag = G_define_flag();
  53. gflag->key = 'g';
  54. gflag->description =
  55. _("Display geographic coordinates and resolution of entire frame");
  56. G_option_required(rflag, dflag, fflag, eflag, bflag, gflag, NULL);
  57. if (G_parser(argc, argv))
  58. exit(EXIT_FAILURE);
  59. D_open_driver();
  60. if (rflag->answer || dflag->answer)
  61. D_get_screen(&st, &sb, &sl, &sr);
  62. if (fflag->answer || eflag->answer || gflag->answer)
  63. D_get_frame(&ft, &fb, &fl, &fr);
  64. if (rflag->answer)
  65. fprintf(stdout, "screen rectangle: %f %f %f %f\n", sl, sr, st, sb);
  66. if (dflag->answer)
  67. fprintf(stdout, "screen dimensions: %f %f\n", sr - sl, sb - st);
  68. if (fflag->answer)
  69. fprintf(stdout, "frame rectangle: %f %f %f %f\n", fl, fr, ft, fb);
  70. if (eflag->answer)
  71. fprintf(stdout, "frame dimensions: %f %f\n", fr - fl, fb - ft);
  72. if (bflag->answer) {
  73. double t, b, l, r;
  74. D_setup(0);
  75. l = D_get_d_west();
  76. r = D_get_d_east();
  77. t = D_get_d_north();
  78. b = D_get_d_south();
  79. fprintf(stdout, "region: %f %f %f %f\n", l, r, t, b);
  80. }
  81. if (gflag->answer) {
  82. /* outer bounds of the screen (including margins) */
  83. double n, s, e, w;
  84. D_setup(0);
  85. n = D_d_to_u_row(ft);
  86. s = D_d_to_u_row(fb);
  87. w = D_d_to_u_col(fl);
  88. e = D_d_to_u_col(fr);
  89. fprintf(stdout, "n=%f\n", n );
  90. fprintf(stdout, "s=%f\n", s );
  91. fprintf(stdout, "w=%f\n", w );
  92. fprintf(stdout, "e=%f\n", e );
  93. fprintf(stdout, "ewres=%.15g\n", D_get_d_to_u_xconv() );
  94. fprintf(stdout, "nsres=%.15g\n", -D_get_d_to_u_yconv() );
  95. }
  96. D_close_driver();
  97. exit(EXIT_SUCCESS);
  98. }