vertex.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. \file vertex.cpp
  3. \brief Vertex manipulation
  4. This program is free software under the GNU General Public
  5. License (>=v2). Read the file COPYING that comes with GRASS
  6. for details.
  7. (C) 2008 by The GRASS development team
  8. \author Martin Landa <landa.martin gmail.com>
  9. \date 2008
  10. */
  11. extern "C" {
  12. #include <grass/vedit.h>
  13. }
  14. #include "driver.h"
  15. #include "digit.h"
  16. /**
  17. \brief Move vertex
  18. \param x,y,z coordinates (z is used only if map is 3d)
  19. \param move_x,move_y,move_z direction for moving vertex
  20. \param bgmap map of background map or NULL
  21. \param snap snap mode (see vector/v.edit/lib/vedit.h)
  22. \param thresh_coords threshold value to identify vertex position
  23. \param thresh_snap threshold value to snap moved vertex
  24. \param 1 vertex moved
  25. \param 0 nothing changed
  26. \param -1 error
  27. */
  28. int Digit::MoveVertex(double x, double y, double z,
  29. double move_x, double move_y, double move_z,
  30. const char *bgmap, int snap,
  31. double thresh_coords, double thresh_snap) {
  32. int ret;
  33. struct line_pnts *point;
  34. struct Map_info **BgMap; /* backgroud vector maps */
  35. int nbgmaps; /* number of registrated background maps */
  36. if (!display->mapInfo) {
  37. DisplayMsg();
  38. return -1;
  39. }
  40. if (display->selected.values->n_values != 1)
  41. return 0;
  42. BgMap = NULL;
  43. nbgmaps = 0;
  44. if (bgmap && strlen(bgmap) > 0) {
  45. BgMap = OpenBackgroundVectorMap(bgmap);
  46. if (!BgMap) {
  47. BackgroundMapMsg(bgmap);
  48. return -1;
  49. }
  50. else {
  51. nbgmaps = 1;
  52. }
  53. }
  54. point = Vect_new_line_struct();
  55. Vect_append_point(point, x, y, z);
  56. /* register changeset */
  57. // AddActionToChangeset(changesets.size(), REWRITE, display->selected.values->value[0]);
  58. /* move only first found vertex in bbox */
  59. ret = Vedit_move_vertex(display->mapInfo, BgMap, nbgmaps,
  60. display->selected.values,
  61. point, thresh_coords, thresh_snap,
  62. move_x, move_y, move_z,
  63. 1, snap);
  64. if (settings.breakLines && ret > 0) {
  65. BreakLineAtIntersection(Vect_get_num_lines(display->mapInfo), NULL);
  66. }
  67. /* TODO
  68. if (ret > 0) {
  69. changesets[changesets.size()-1][0].line = Vect_get_num_lines(display->mapInfo);
  70. }
  71. else {
  72. changesets.erase(changesets.size()-1);
  73. }
  74. */
  75. if (BgMap && BgMap[0]) {
  76. Vect_close(BgMap[0]);
  77. }
  78. Vect_destroy_line_struct(point);
  79. return ret;
  80. }
  81. /**
  82. \brief Add or remove vertex
  83. Shape of line/boundary is not changed when adding new vertex.
  84. \param add add or remove vertex?
  85. \param x,y,z coordinates (z is used only if map is 3d
  86. \param thresh threshold value to identify vertex position
  87. \param 1 vertex added/removed
  88. \param 0 nothing changed
  89. \param -1 error
  90. */
  91. int Digit::ModifyLineVertex(int add, double x, double y, double z,
  92. double thresh)
  93. {
  94. int ret;
  95. struct line_pnts *point;
  96. if (!display->mapInfo) {
  97. DisplayMsg();
  98. return -1;
  99. }
  100. if (display->selected.values->n_values != 1)
  101. return 0;
  102. point = Vect_new_line_struct();
  103. Vect_append_point(point, x, y, z);
  104. /* register changeset */
  105. // AddActionToChangeset(changesets.size(), REWRITE, display->selected.values->value[0]);
  106. if (add) {
  107. ret = Vedit_add_vertex(display->mapInfo, display->selected.values,
  108. point, thresh);
  109. }
  110. else {
  111. ret = Vedit_remove_vertex(display->mapInfo, display->selected.values,
  112. point, thresh);
  113. }
  114. /* TODO
  115. if (ret > 0) {
  116. changesets[changesets.size()-1][0].line = Vect_get_num_lines(display->mapInfo);
  117. }
  118. else {
  119. changesets.erase(changesets.size()-1);
  120. }
  121. */
  122. Vect_destroy_line_struct(point);
  123. return ret;
  124. }