vertex.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /**
  2. \file vdigit/vertex.cpp
  3. \brief wxvdigit - 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-2009 by Martin Landa, and the GRASS development team
  8. \author Martin Landa <landa.martin gmail.com>
  9. */
  10. extern "C" {
  11. #include <grass/vedit.h>
  12. }
  13. #include "driver.h"
  14. #include "digit.h"
  15. /**
  16. \brief Move vertex
  17. \param x,y,z coordinates (z is used only if map is 3d)
  18. \param move_x,move_y,move_z direction for moving vertex
  19. \param bgmap map of background map or NULL
  20. \param snap snap mode (see vector/v.edit/lib/vedit.h)
  21. \param thresh_coords threshold value to identify vertex position
  22. \param thresh_snap threshold value to snap moved vertex
  23. \param 1 vertex moved
  24. \param 0 nothing changed
  25. \param -1 error
  26. */
  27. int Digit::MoveVertex(double x, double y, double z,
  28. double move_x, double move_y, double move_z,
  29. const char *bgmap, int snap,
  30. double thresh_coords, double thresh_snap) {
  31. int ret;
  32. int changeset, nlines;
  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. display->DisplayMsg();
  38. return -1;
  39. }
  40. if (display->selected.ids->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. display->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. nlines = Vect_get_num_lines(display->mapInfo);
  57. changeset = AddActionsBefore();
  58. /* move only first found vertex in bbox */
  59. ret = Vedit_move_vertex(display->mapInfo, BgMap, nbgmaps,
  60. display->selected.ids,
  61. point, thresh_coords, thresh_snap,
  62. move_x, move_y, move_z,
  63. 1, snap);
  64. if (ret > 0) {
  65. AddActionsAfter(changeset, nlines);
  66. }
  67. else {
  68. changesets.erase(changeset);
  69. }
  70. if (ret > 0 && settings.breakLines) {
  71. BreakLineAtIntersection(Vect_get_num_lines(display->mapInfo), NULL, changeset);
  72. }
  73. if (BgMap && BgMap[0]) {
  74. Vect_close(BgMap[0]);
  75. }
  76. Vect_destroy_line_struct(point);
  77. return ret;
  78. }
  79. /**
  80. \brief Add or remove vertex
  81. Shape of line/boundary is not changed when adding new vertex.
  82. \param add add or remove vertex?
  83. \param x,y,z coordinates (z is used only if map is 3d
  84. \param thresh threshold value to identify vertex position
  85. \param 1 vertex added/removed
  86. \param 0 nothing changed
  87. \param -1 error
  88. */
  89. int Digit::ModifyLineVertex(int add, double x, double y, double z,
  90. double thresh)
  91. {
  92. int ret;
  93. int changeset, nlines;
  94. struct line_pnts *point;
  95. if (!display->mapInfo) {
  96. display->DisplayMsg();
  97. return -1;
  98. }
  99. if (display->selected.ids->n_values != 1)
  100. return 0;
  101. point = Vect_new_line_struct();
  102. Vect_append_point(point, x, y, z);
  103. nlines = Vect_get_num_lines(display->mapInfo);
  104. changeset = AddActionsBefore();
  105. if (add) {
  106. ret = Vedit_add_vertex(display->mapInfo, display->selected.ids,
  107. point, thresh);
  108. }
  109. else {
  110. ret = Vedit_remove_vertex(display->mapInfo, display->selected.ids,
  111. point, thresh);
  112. }
  113. if (ret > 0) {
  114. AddActionsAfter(changeset, nlines);
  115. }
  116. else {
  117. changesets.erase(changeset);
  118. }
  119. if (!add && ret > 0 && settings.breakLines) {
  120. BreakLineAtIntersection(Vect_get_num_lines(display->mapInfo), NULL, changeset);
  121. }
  122. Vect_destroy_line_struct(point);
  123. return ret;
  124. }