setup.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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_frame(&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. D_set_clip_window_to_screen_window();
  42. if (clear)
  43. D_erase(DEFAULT_BG_COLOR);
  44. D_set_clip_window_to_map_window();
  45. }
  46. /*!
  47. \brief Graphics frame setup
  48. Sets the source coordinate system to match the
  49. destination coordinate system, so that D_* functions use the same
  50. coordinate system as R_* functions.
  51. If <b>clear</b> is true, the frame is cleared (same as running
  52. <i>d.erase</i>). Otherwise, it is not cleared.
  53. \param clear non-zero code to clear the frame
  54. */
  55. void D_setup_unity(int clear)
  56. {
  57. double dt, db, dl, dr;
  58. D_get_frame(&dt, &db, &dl, &dr);
  59. D_set_src(dt, db, dl, dr);
  60. D_set_dst(dt, db, dl, dr);
  61. D_update_conversions();
  62. D_set_clip_window_to_screen_window();
  63. if (clear)
  64. D_erase(DEFAULT_BG_COLOR);
  65. D_set_clip_window_to_map_window();
  66. }
  67. /*!
  68. \brief Sets source coordinate system
  69. Sets the source coordinate system to its arguments, and if
  70. the <b>fit</b> argument is non-zero, adjusts the destination coordinate
  71. system to preserve the aspect ratio.
  72. If <b>clear</b> is true, the frame is cleared (same as running
  73. <i>d.erase</i>). Otherwise, it is not cleared.
  74. \param clear non-zero code to clear the frame
  75. \param fit non-zero code to adjust destination coordinate system
  76. \param s_top
  77. \param s_bottom
  78. \param s_left
  79. \param s_right
  80. */
  81. void D_setup2(int clear, int fit, double st, double sb, double sl, double sr)
  82. {
  83. double dt, db, dl, dr;
  84. D_get_frame(&dt, &db, &dl, &dr);
  85. D_set_src(st, sb, sl, sr);
  86. D_set_dst(dt, db, dl, dr);
  87. if (fit)
  88. D_fit_d_to_u();
  89. D_update_conversions();
  90. D_set_clip_window_to_screen_window();
  91. if (clear)
  92. D_erase(DEFAULT_BG_COLOR);
  93. D_set_clip_window_to_map_window();
  94. }
  95. /*!
  96. \brief Get driver output file
  97. \return file name or NULL if not defined
  98. */
  99. const char *D_get_file(void)
  100. {
  101. return COM_Graph_get_file();
  102. }