GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
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  int i;
40 
41  G_debug(3, "dig_line_add_updated(): line = %d", line);
42 
43  /* undo/redo in the digitizer needs all steps,
44  * disable check */
45 #if 0
46  /* Check if already in list */
47  for (i = 0; i < Plus->uplist.n_uplines; i++) {
48  if (Plus->uplist.uplines[i] == line) {
49  G_debug(3, "\tskipped");
50  return;
51  }
52  }
53 #endif
54 
55  /* Alloc space if needed */
56  if (Plus->uplist.n_uplines == Plus->uplist.alloc_uplines) {
57  Plus->uplist.alloc_uplines += 1000;
58  Plus->uplist.uplines =
59  (int *)G_realloc(Plus->uplist.uplines,
60  Plus->uplist.alloc_uplines * sizeof(int));
61  Plus->uplist.uplines_offset =
62  (off_t *)G_realloc(Plus->uplist.uplines_offset,
63  Plus->uplist.alloc_uplines * sizeof(off_t));
64  }
65 
66  Plus->uplist.uplines[Plus->uplist.n_uplines] = line;
67  Plus->uplist.uplines_offset[Plus->uplist.n_uplines] = offset;
68  Plus->uplist.n_uplines++;
69 }
70 
71 /*!
72  \brief Reset number of updated nodes
73 
74  \param Plus pointer to Plus_head structure
75  */
77 {
78  Plus->uplist.n_upnodes = 0;
79 }
80 
81 /*!
82  \brief Add node to updated
83 
84  \param Plus pointer to Plus_head structure
85  \param node node id
86  */
87 void dig_node_add_updated(struct Plus_head *Plus, int node)
88 {
89  int i;
90 
91  G_debug(3, "dig_node_add_updated(): node = %d", node);
92 
93  /* Check if already in list */
94  for (i = 0; i < Plus->uplist.n_upnodes; i++) {
95  if (abs(Plus->uplist.upnodes[i]) == abs(node)) {
96  G_debug(3, "\tskipped");
97  return;
98  }
99  }
100 
101  /* Alloc space if needed */
102  if (Plus->uplist.n_upnodes == Plus->uplist.alloc_upnodes) {
103  Plus->uplist.alloc_upnodes += 1000;
104  Plus->uplist.upnodes =
105  (int *)G_realloc(Plus->uplist.upnodes,
106  Plus->uplist.alloc_upnodes * sizeof(int));
107  }
108 
109  Plus->uplist.upnodes[Plus->uplist.n_upnodes] = node;
110  Plus->uplist.n_upnodes++;
111 }
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