init.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. \file init.cpp
  3. \brief Experimental C++ wxWidgets Nviz prototype -- initialization
  4. Used by wxGUI Nviz extension.
  5. Copyright: (C) by the GRASS Development Team
  6. This program is free software under the GNU General Public
  7. License (>=v2). Read the file COPYING that comes with GRASS
  8. for details.
  9. \author Martin Landa <landa.martin gmail.com> (Google SoC 2008)
  10. \date 2008
  11. */
  12. #include "nviz.h"
  13. static void swap_gl();
  14. /*!
  15. \brief Initialize Nviz class instance
  16. */
  17. Nviz::Nviz()
  18. {
  19. G_gisinit(""); /* GRASS functions */
  20. G_set_verbose(0); // TODO: read progress info
  21. GS_libinit();
  22. /* GVL_libinit(); TODO */
  23. GS_set_swap_func(swap_gl);
  24. data = (nv_data*) G_malloc(sizeof (nv_data));
  25. /* GLCanvas */
  26. glCanvas = NULL;
  27. G_debug(1, "Nviz::Nviz()");
  28. }
  29. /*!
  30. \brief Destroy Nviz class instance
  31. */
  32. Nviz::~Nviz()
  33. {
  34. G_free((void *) data);
  35. data = NULL;
  36. glCanvas = NULL;
  37. }
  38. /*!
  39. \brief Associate display with render window
  40. \return 1 on success
  41. \return 0 on failure
  42. */
  43. int Nviz::SetDisplay(void *display)
  44. {
  45. glCanvas = (wxGLCanvas *) display;
  46. // glCanvas->SetCurrent();
  47. G_debug(1, "Nviz::SetDisplay()");
  48. return 1;
  49. }
  50. void Nviz::InitView()
  51. {
  52. /* initialize nviz data */
  53. Nviz_init_data(data);
  54. /* define default attributes for map objects */
  55. Nviz_set_attr_default();
  56. /* set background color */
  57. Nviz_set_bgcolor(data, Nviz_color_from_str("white")); /* TODO */
  58. /* initialize view */
  59. Nviz_init_view();
  60. /* set default lighting model */
  61. SetLightsDefault();
  62. /* clear window */
  63. GS_clear(data->bgcolor);
  64. G_debug(1, "Nviz::InitView()");
  65. return;
  66. }
  67. /*!
  68. \brief Reset session
  69. Unload all data layers
  70. @todo vector, volume
  71. */
  72. void Nviz::Reset()
  73. {
  74. int i;
  75. int *surf_list, nsurfs;
  76. surf_list = GS_get_surf_list(&nsurfs);
  77. for (i = 0; i < nsurfs; i++) {
  78. GS_delete_surface(surf_list[i]);
  79. }
  80. }
  81. void swap_gl()
  82. {
  83. return;
  84. }
  85. /*!
  86. \brief Set background color
  87. \param color_str color string
  88. */
  89. void Nviz::SetBgColor(const char *color_str)
  90. {
  91. data->bgcolor = Nviz_color_from_str(color_str);
  92. return;
  93. }