load.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. \file load.cpp
  3. \brief Experimental C++ wxWidgets Nviz prototype -- load data layers
  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. extern "C" {
  14. #include <grass/glocale.h>
  15. }
  16. /*!
  17. \brief Load raster map (surface)
  18. \param name raster map name
  19. \param color_name raster map for color (NULL for color_value)
  20. \param color_value color string (named color or RGB triptet)
  21. \return object id
  22. \return -1 on failure
  23. */
  24. int Nviz::LoadSurface(const char* name, const char *color_name, const char *color_value)
  25. {
  26. char *mapset;
  27. int id;
  28. mapset = G_find_cell2 (name, "");
  29. if (mapset == NULL) {
  30. G_warning(_("Raster map <%s> not found"),
  31. name);
  32. return -1;
  33. }
  34. /* topography */
  35. id = Nviz_new_map_obj(MAP_OBJ_SURF,
  36. G_fully_qualified_name(name, mapset), 0.0,
  37. data);
  38. if (color_name) { /* check for color map */
  39. mapset = G_find_cell2 (color_name, "");
  40. if (mapset == NULL) {
  41. G_warning(_("Raster map <%s> not found"),
  42. color_name);
  43. GS_delete_surface(id);
  44. return -1;
  45. }
  46. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
  47. G_fully_qualified_name(color_name, mapset), -1.0,
  48. data);
  49. }
  50. else if (color_value) { /* check for color value */
  51. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
  52. NULL, Nviz_color_from_str(color_value),
  53. data);
  54. }
  55. else { /* use by default elevation map for coloring */
  56. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
  57. G_fully_qualified_name(name, mapset), -1.0,
  58. data);
  59. }
  60. /*
  61. if (i > 1)
  62. set_default_wirecolors(data, i);
  63. */
  64. /* focus on loaded data */
  65. Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1);
  66. G_debug(1, "Nviz::LoadRaster(): name=%s -> id=%d", name, id);
  67. return id;
  68. }
  69. /*!
  70. \brief Unload surface
  71. \param id surface id
  72. \return 1 on success
  73. \return 0 on failure
  74. */
  75. int Nviz::UnloadSurface(int id)
  76. {
  77. if (!GS_surf_exists(id)) {
  78. return 0;
  79. }
  80. G_debug(1, "Nviz::UnloadSurface(): id=%d", id);
  81. if (GS_delete_surface(id) < 0)
  82. return 0;
  83. return 1;
  84. }
  85. /*!
  86. \brief Load vector map overlay
  87. \param name vector map name
  88. \return object id
  89. \return -1 on failure
  90. */
  91. int Nviz::LoadVector(const char *name)
  92. {
  93. int id;
  94. char *mapset;
  95. if (GS_num_surfs() == 0) { /* load base surface if no loaded */
  96. int *surf_list, nsurf;
  97. Nviz_new_map_obj(MAP_OBJ_SURF, NULL, 0.0, data);
  98. surf_list = GS_get_surf_list(&nsurf);
  99. GS_set_att_const(surf_list[0], ATT_TRANSP, 255);
  100. }
  101. mapset = G_find_vector2 (name, "");
  102. if (mapset == NULL) {
  103. G_warning(_("Vector map <%s> not found"),
  104. name);
  105. }
  106. id = Nviz_new_map_obj(MAP_OBJ_VECT,
  107. G_fully_qualified_name(name, mapset), 0.0,
  108. data);
  109. G_debug(1, "Nviz::LoadVector(): name=%s -> id=%d", name, id);
  110. return id;
  111. }
  112. /*!
  113. \brief Unload vector
  114. \param id surface id
  115. \return 1 on success
  116. \return 0 on failure
  117. */
  118. int Nviz::UnloadVector(int id)
  119. {
  120. if (!GV_vect_exists(id)) {
  121. return 0;
  122. }
  123. G_debug(1, "Nviz::UnloadVector(): id=%d", id);
  124. if (GV_delete_vector(id) < 0)
  125. return 0;
  126. return 1;
  127. }