update.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * \file lib/vector/diglib/update.c
  3. *
  4. * \brief Vector library - update topology (lower level functions)
  5. *
  6. * Lower level functions for reading/writing/manipulating vectors.
  7. *
  8. * (C) 2001 by the GRASS Development Team
  9. *
  10. * This program is free software under the GNU General Public License
  11. * (>=v2). Read the file COPYING that comes with GRASS for details.
  12. *
  13. * \author Radim Blazek
  14. */
  15. #include <stdlib.h>
  16. #include <grass/vector.h>
  17. /*!
  18. \brief Reset number of updated lines
  19. \param Plus pointer to Plus_head structure
  20. */
  21. void dig_line_reset_updated(struct Plus_head *Plus)
  22. {
  23. Plus->uplist.n_uplines = 0;
  24. }
  25. /*!
  26. \brief Add new line to updated
  27. \param Plus pointer to Plus_head structure
  28. \param line line id
  29. \param offset line offset (negative offset is ignored)
  30. */
  31. void dig_line_add_updated(struct Plus_head *Plus, int line, off_t offset)
  32. {
  33. G_debug(3, "dig_line_add_updated(): line = %d", line);
  34. /* undo/redo in the digitizer needs all steps,
  35. * disable check */
  36. #if 0
  37. int i;
  38. /* Check if already in list */
  39. for (i = 0; i < Plus->uplist.n_uplines; i++) {
  40. if (Plus->uplist.uplines[i] == line) {
  41. G_debug(3, "\tskipped");
  42. return;
  43. }
  44. }
  45. #endif
  46. /* Alloc space if needed */
  47. if (Plus->uplist.n_uplines == Plus->uplist.alloc_uplines) {
  48. Plus->uplist.alloc_uplines += 1000;
  49. Plus->uplist.uplines =
  50. (int *)G_realloc(Plus->uplist.uplines,
  51. Plus->uplist.alloc_uplines * sizeof(int));
  52. Plus->uplist.uplines_offset =
  53. (off_t *)G_realloc(Plus->uplist.uplines_offset,
  54. Plus->uplist.alloc_uplines * sizeof(off_t));
  55. }
  56. Plus->uplist.uplines[Plus->uplist.n_uplines] = line;
  57. Plus->uplist.uplines_offset[Plus->uplist.n_uplines] = offset;
  58. Plus->uplist.n_uplines++;
  59. }
  60. /*!
  61. \brief Reset number of updated nodes
  62. \param Plus pointer to Plus_head structure
  63. */
  64. void dig_node_reset_updated(struct Plus_head *Plus)
  65. {
  66. Plus->uplist.n_upnodes = 0;
  67. }
  68. /*!
  69. \brief Add node to updated
  70. \param Plus pointer to Plus_head structure
  71. \param node node id
  72. */
  73. void dig_node_add_updated(struct Plus_head *Plus, int node)
  74. {
  75. int i;
  76. G_debug(3, "dig_node_add_updated(): node = %d", node);
  77. /* Check if already in list */
  78. for (i = 0; i < Plus->uplist.n_upnodes; i++) {
  79. if (abs(Plus->uplist.upnodes[i]) == abs(node)) {
  80. G_debug(3, "\tskipped");
  81. return;
  82. }
  83. }
  84. /* Alloc space if needed */
  85. if (Plus->uplist.n_upnodes == Plus->uplist.alloc_upnodes) {
  86. Plus->uplist.alloc_upnodes += 1000;
  87. Plus->uplist.upnodes =
  88. (int *)G_realloc(Plus->uplist.upnodes,
  89. Plus->uplist.alloc_upnodes * sizeof(int));
  90. }
  91. Plus->uplist.upnodes[Plus->uplist.n_upnodes] = node;
  92. Plus->uplist.n_upnodes++;
  93. }