setup.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*!
  2. \file lib/display/setup.c
  3. \brief Display Driver - setup
  4. (C) 2006-2011 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Glynn Clements <glynn gclements.plus.com> (original contributor)
  8. \author Huidae Cho <grass4u gmail.com>
  9. */
  10. #include <string.h>
  11. #include <grass/gis.h>
  12. #include <grass/raster.h>
  13. #include <grass/display.h>
  14. #include "driver.h"
  15. /*!
  16. \brief Graphics frame setup
  17. This is a high level D call. It does a full setup for the current
  18. graphics frame.
  19. Note: Connection to driver must already be made.
  20. Sets the source coordinate system to the current region, and
  21. adjusts the destination coordinate system to preserve the aspect
  22. ratio.
  23. Performs a full setup for the current graphics frame:
  24. - Makes sure there is a current graphics frame (will create a full-screen
  25. one, if not);
  26. - Sets the region coordinates so that the graphics frame and the active
  27. module region agree (may change active module region to do this); and
  28. - Performs graphic frame/region coordinate conversion initialization.
  29. If <b>clear</b> is true, the frame is cleared (same as running
  30. <i>d.erase</i>.) Otherwise, it is not cleared.
  31. \param clear 1 to clear frame (visually and coordinates)
  32. */
  33. void D_setup(int clear)
  34. {
  35. struct Cell_head region;
  36. double dt, db, dl, dr;
  37. D_get_window(&dt, &db, &dl, &dr);
  38. G_get_set_window(&region);
  39. Rast_set_window(&region);
  40. D_do_conversions(&region, dt, db, dl, dr);
  41. if (clear)
  42. D_erase(DEFAULT_BG_COLOR);
  43. }
  44. /*!
  45. \brief Graphics frame setup
  46. Sets the source coordinate system to match the
  47. destination coordinate system, so that D_* functions use the same
  48. coordinate system as R_* functions.
  49. If <b>clear</b> is true, the frame is cleared (same as running
  50. <i>d.erase</i>). Otherwise, it is not cleared.
  51. \param clear non-zero code to clear the frame
  52. */
  53. void D_setup_unity(int clear)
  54. {
  55. double dt, db, dl, dr;
  56. D_get_window(&dt, &db, &dl, &dr);
  57. D_set_src(dt, db, dl, dr);
  58. D_set_dst(dt, db, dl, dr);
  59. D_update_conversions();
  60. if (clear)
  61. D_erase(DEFAULT_BG_COLOR);
  62. }
  63. /*!
  64. \brief Sets source coordinate system
  65. Sets the source coordinate system to its arguments, and if
  66. the <b>fit</b> argument is non-zero, adjusts the destination coordinate
  67. system to preserve the aspect ratio.
  68. If <b>clear</b> is true, the frame is cleared (same as running
  69. <i>d.erase</i>). Otherwise, it is not cleared.
  70. \param clear non-zero code to clear the frame
  71. \param fit non-zero code to adjust destination coordinate system
  72. \param s_top
  73. \param s_bottom
  74. \param s_left
  75. \param s_right
  76. */
  77. void D_setup2(int clear, int fit, double st, double sb, double sl, double sr)
  78. {
  79. double dt, db, dl, dr;
  80. D_get_window(&dt, &db, &dl, &dr);
  81. D_set_src(st, sb, sl, sr);
  82. D_set_dst(dt, db, dl, dr);
  83. if (fit)
  84. D_fit_d_to_u();
  85. D_update_conversions();
  86. if (clear)
  87. D_erase(DEFAULT_BG_COLOR);
  88. }
  89. /*!
  90. \brief Get driver output file
  91. \return file name or NULL if not defined
  92. */
  93. const char *D_get_file(void)
  94. {
  95. return COM_Graph_get_file();
  96. }