init.cpp 2.6 KB

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