GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
vector/diglib/update.c
Go to the documentation of this file.
1 
2 /**
3  * \file lib/vector/diglib/update.c
4  *
5  * \brief Vector library - update topology (lower level functions)
6  *
7  * Lower level functions for reading/writing/manipulating vectors.
8  *
9  * (C) 2001 by the GRASS Development Team
10  *
11  * This program is free software under the GNU General Public License
12  * (>=v2). Read the file COPYING that comes with GRASS for details.
13  *
14  * \author Radim Blazek
15  */
16 
17 #include <stdlib.h>
18 #include <grass/vector.h>
19 
20 /*!
21  \brief Reset number of updated lines
22 
23  \param Plus pointer to Plus_head structure
24  */
26 {
27  Plus->uplist.n_uplines = 0;
28 }
29 
30 /*!
31  \brief Add new line to updated
32 
33  \param Plus pointer to Plus_head structure
34  \param line line id
35  \param offset line offset (negative offset is ignored)
36  */
37 void dig_line_add_updated(struct Plus_head *Plus, int line, off_t offset)
38 {
39  G_debug(3, "dig_line_add_updated(): line = %d", line);
40 
41  /* undo/redo in the digitizer needs all steps,
42  * disable check */
43 #if 0
44  int i;
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 =
58  (int *)G_realloc(Plus->uplist.uplines,
59  Plus->uplist.alloc_uplines * sizeof(int));
60  Plus->uplist.uplines_offset =
61  (off_t *)G_realloc(Plus->uplist.uplines_offset,
62  Plus->uplist.alloc_uplines * sizeof(off_t));
63  }
64 
65  Plus->uplist.uplines[Plus->uplist.n_uplines] = line;
66  Plus->uplist.uplines_offset[Plus->uplist.n_uplines] = offset;
67  Plus->uplist.n_uplines++;
68 }
69 
70 /*!
71  \brief Reset number of updated nodes
72 
73  \param Plus pointer to Plus_head structure
74  */
76 {
77  Plus->uplist.n_upnodes = 0;
78 }
79 
80 /*!
81  \brief Add node to updated
82 
83  \param Plus pointer to Plus_head structure
84  \param node node id
85  */
86 void dig_node_add_updated(struct Plus_head *Plus, int node)
87 {
88  int i;
89 
90  G_debug(3, "dig_node_add_updated(): node = %d", node);
91 
92  /* Check if already in list */
93  for (i = 0; i < Plus->uplist.n_upnodes; i++) {
94  if (abs(Plus->uplist.upnodes[i]) == abs(node)) {
95  G_debug(3, "\tskipped");
96  return;
97  }
98  }
99 
100  /* Alloc space if needed */
101  if (Plus->uplist.n_upnodes == Plus->uplist.alloc_upnodes) {
102  Plus->uplist.alloc_upnodes += 1000;
103  Plus->uplist.upnodes =
104  (int *)G_realloc(Plus->uplist.upnodes,
105  Plus->uplist.alloc_upnodes * sizeof(int));
106  }
107 
108  Plus->uplist.upnodes[Plus->uplist.n_upnodes] = node;
109  Plus->uplist.n_upnodes++;
110 }
int n_uplines
Number of updated lines.
Definition: dig_structs.h:1201
int * uplines
Array of updated lines.
Definition: dig_structs.h:1187
void dig_node_reset_updated(struct Plus_head *Plus)
Reset number of updated nodes.
void dig_node_add_updated(struct Plus_head *Plus, int node)
Add node to updated.
off_t * uplines_offset
Array of updated lines - offset.
Definition: dig_structs.h:1193
void dig_line_add_updated(struct Plus_head *Plus, int line, off_t offset)
Add new line to updated.
Basic topology-related info.
Definition: dig_structs.h:784
int alloc_upnodes
Allocated array of nodes.
Definition: dig_structs.h:1209
int n_upnodes
number of updated nodes
Definition: dig_structs.h:1213
int alloc_uplines
Allocated array of lines.
Definition: dig_structs.h:1197
void dig_line_reset_updated(struct Plus_head *Plus)
Reset number of updated lines.
#define G_realloc(p, n)
Definition: defs/gis.h:114
int * upnodes
Array of updated nodes.
Definition: dig_structs.h:1205
struct Plus_head::@10 uplist
List of updated lines/nodes.
int G_debug(int, const char *,...) __attribute__((format(printf