init.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 <clocale>
  13. #include "nviz.h"
  14. static void swap_gl();
  15. /*!
  16. \brief Initialize Nviz class instance
  17. */
  18. Nviz::Nviz()
  19. {
  20. setlocale(LC_NUMERIC, "C");
  21. G_gisinit(""); /* GRASS functions */
  22. G_set_verbose(0); // TODO: read progress info
  23. GS_libinit();
  24. /* GVL_libinit(); TODO */
  25. GS_set_swap_func(swap_gl);
  26. data = (nv_data*) G_malloc(sizeof (nv_data));
  27. /* GLCanvas */
  28. glCanvas = NULL;
  29. G_debug(1, "Nviz::Nviz()");
  30. }
  31. /*!
  32. \brief Destroy Nviz class instance
  33. */
  34. Nviz::~Nviz()
  35. {
  36. G_free((void *) data);
  37. data = NULL;
  38. glCanvas = NULL;
  39. }
  40. /*!
  41. \brief Associate display with render window
  42. \return 1 on success
  43. \return 0 on failure
  44. */
  45. int Nviz::SetDisplay(void *display)
  46. {
  47. glCanvas = (wxGLCanvas *) display;
  48. // glCanvas->SetCurrent();
  49. G_debug(1, "Nviz::SetDisplay()");
  50. return 1;
  51. }
  52. void Nviz::InitView()
  53. {
  54. /* initialize nviz data */
  55. Nviz_init_data(data);
  56. /* define default attributes for map objects */
  57. Nviz_set_attr_default();
  58. /* set background color */
  59. Nviz_set_bgcolor(data, Nviz_color_from_str("white")); /* TODO */
  60. /* initialize view */
  61. Nviz_init_view();
  62. /* set default lighting model */
  63. SetLightsDefault();
  64. /* clear window */
  65. GS_clear(data->bgcolor);
  66. G_debug(1, "Nviz::InitView()");
  67. return;
  68. }
  69. /*!
  70. \brief Reset session
  71. Unload all data layers
  72. @todo vector, volume
  73. */
  74. void Nviz::Reset()
  75. {
  76. int i;
  77. int *surf_list, nsurfs;
  78. surf_list = GS_get_surf_list(&nsurfs);
  79. for (i = 0; i < nsurfs; i++) {
  80. GS_delete_surface(surf_list[i]);
  81. }
  82. }
  83. void swap_gl()
  84. {
  85. return;
  86. }
  87. /*!
  88. \brief Set background color
  89. \param color_str color string
  90. */
  91. void Nviz::SetBgColor(const char *color_str)
  92. {
  93. data->bgcolor = Nviz_color_from_str(color_str);
  94. return;
  95. }