GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-381f661b3f
vector/diglib/update.c
Go to the documentation of this file.
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 
16 #include <stdlib.h>
17 #include <grass/vector.h>
18 
19 /*!
20  \brief Reset number of updated lines
21 
22  \param Plus pointer to Plus_head structure
23  */
25 {
26  Plus->uplist.n_uplines = 0;
27 }
28 
29 /*!
30  \brief Add new line to updated
31 
32  \param Plus pointer to Plus_head structure
33  \param line line id
34  \param offset line offset (negative offset is ignored)
35  */
36 void dig_line_add_updated(struct Plus_head *Plus, int line, off_t offset)
37 {
38  G_debug(3, "dig_line_add_updated(): line = %d", line);
39 
40  /* undo/redo in the digitizer needs all steps,
41  * disable check */
42 #if 0
43  int i;
44 
45  /* Check if already in list */
46  for (i = 0; i < Plus->uplist.n_uplines; i++) {
47  if (Plus->uplist.uplines[i] == line) {
48  G_debug(3, "\tskipped");
49  return;
50  }
51  }
52 #endif
53 
54  /* Alloc space if needed */
55  if (Plus->uplist.n_uplines == Plus->uplist.alloc_uplines) {
56  Plus->uplist.alloc_uplines += 1000;
57  Plus->uplist.uplines = (int *)G_realloc(
58  Plus->uplist.uplines, Plus->uplist.alloc_uplines * sizeof(int));
59  Plus->uplist.uplines_offset =
60  (off_t *)G_realloc(Plus->uplist.uplines_offset,
61  Plus->uplist.alloc_uplines * sizeof(off_t));
62  }
63 
64  Plus->uplist.uplines[Plus->uplist.n_uplines] = line;
65  Plus->uplist.uplines_offset[Plus->uplist.n_uplines] = offset;
66  Plus->uplist.n_uplines++;
67 }
68 
69 /*!
70  \brief Reset number of updated nodes
71 
72  \param Plus pointer to Plus_head structure
73  */
75 {
76  Plus->uplist.n_upnodes = 0;
77 }
78 
79 /*!
80  \brief Add node to updated
81 
82  \param Plus pointer to Plus_head structure
83  \param node node id
84  */
85 void dig_node_add_updated(struct Plus_head *Plus, int node)
86 {
87  int i;
88 
89  G_debug(3, "dig_node_add_updated(): node = %d", node);
90 
91  /* Check if already in list */
92  for (i = 0; i < Plus->uplist.n_upnodes; i++) {
93  if (abs(Plus->uplist.upnodes[i]) == abs(node)) {
94  G_debug(3, "\tskipped");
95  return;
96  }
97  }
98 
99  /* Alloc space if needed */
100  if (Plus->uplist.n_upnodes == Plus->uplist.alloc_upnodes) {
101  Plus->uplist.alloc_upnodes += 1000;
102  Plus->uplist.upnodes = (int *)G_realloc(
103  Plus->uplist.upnodes, Plus->uplist.alloc_upnodes * sizeof(int));
104  }
105 
106  Plus->uplist.upnodes[Plus->uplist.n_upnodes] = node;
107  Plus->uplist.n_upnodes++;
108 }
#define G_realloc(p, n)
Definition: defs/gis.h:96
int G_debug(int, const char *,...) __attribute__((format(printf
Basic topology-related info.
Definition: dig_structs.h:769
int alloc_upnodes
Allocated array of nodes.
Definition: dig_structs.h:1193
int n_upnodes
number of updated nodes
Definition: dig_structs.h:1197
int * upnodes
Array of updated nodes.
Definition: dig_structs.h:1189
int alloc_uplines
Allocated array of lines.
Definition: dig_structs.h:1181
int * uplines
Array of updated lines.
Definition: dig_structs.h:1171
struct Plus_head::@10 uplist
List of updated lines/nodes.
off_t * uplines_offset
Array of updated lines - offset.
Definition: dig_structs.h:1177
int n_uplines
Number of updated lines.
Definition: dig_structs.h:1185
void dig_line_add_updated(struct Plus_head *Plus, int line, off_t offset)
Add new line to updated.
void dig_node_reset_updated(struct Plus_head *Plus)
Reset number of updated nodes.
void dig_line_reset_updated(struct Plus_head *Plus)
Reset number of updated lines.
void dig_node_add_updated(struct Plus_head *Plus, int node)
Add node to updated.