GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
GV2.c
Go to the documentation of this file.
1 
19 #include <stdlib.h>
20 #include <string.h>
21 
22 #include <grass/gis.h>
23 #include <grass/gstypes.h>
24 
25 #include "gsget.h"
26 
27 static int Vect_ID[MAX_VECTS];
28 static int Next_vect = 0;
29 
38 int GV_vect_exists(int id)
39 {
40  int i, found = 0;
41 
42  G_debug(3, "GV_vect_exists");
43 
44  if (NULL == gv_get_vect(id)) {
45  return (0);
46  }
47 
48  for (i = 0; i < Next_vect && !found; i++) {
49  if (Vect_ID[i] == id) {
50  found = 1;
51  }
52  }
53 
54  return (found);
55 }
56 
63 int GV_new_vector(void)
64 {
65  geovect *nv;
66 
67  if (Next_vect < MAX_VECTS) {
68  nv = gv_get_new_vect();
69  gv_set_defaults(nv);
70  Vect_ID[Next_vect] = nv->gvect_id;
71  ++Next_vect;
72 
73  G_debug(3, "GV_new_vector(): id=%d", nv->gvect_id);
74 
75  return (nv->gvect_id);
76  }
77 
78  return (-1);
79 }
80 
86 int GV_num_vects(void)
87 {
88  return (gv_num_vects());
89 }
90 
101 int *GV_get_vect_list(int *numvects)
102 {
103  int i, *ret;
104 
105  *numvects = Next_vect;
106 
107  if (Next_vect) {
108  ret = (int *)G_malloc(Next_vect * sizeof(int));
109  if (!ret) {
110  return (NULL);
111  }
112 
113  for (i = 0; i < Next_vect; i++) {
114  ret[i] = Vect_ID[i];
115  }
116 
117  return (ret);
118  }
119 
120  return (NULL);
121 }
122 
131 int GV_delete_vector(int id)
132 {
133  int i, j, found = 0;
134 
135  G_debug(3, "GV_delete_vect");
136 
137  if (GV_vect_exists(id)) {
138  gv_delete_vect(id);
139 
140  for (i = 0; i < Next_vect && !found; i++) {
141  if (Vect_ID[i] == id) {
142  found = 1;
143 
144  for (j = i; j < Next_vect; j++) {
145  Vect_ID[j] = Vect_ID[j + 1];
146  }
147  }
148  }
149 
150  if (found) {
151  --Next_vect;
152  return (1);
153  }
154  }
155 
156  return (-1);
157 }
158 
174 int GV_load_vector(int id, const char *filename)
175 {
176  geovect *gv;
177 
178  if (NULL == (gv = gv_get_vect(id))) {
179  return (-1);
180  }
181 
182  if (gv->lines) {
183  gv_free_vectmem(gv);
184  }
185 
186  gv->filename = G_store(filename);
187 
188  if ((gv->lines = Gv_load_vect(filename, &(gv->n_lines)))) {
189  return (1);
190  }
191 
192  return (-1);
193 }
194 
206 int GV_get_vectname(int id, char **filename)
207 {
208  geovect *gv;
209 
210  if (NULL == (gv = gv_get_vect(id))) {
211  return (-1);
212  }
213 
214  *filename = G_store(gv->filename);
215 
216  return (1);
217 }
218 
231 int GV_set_vectmode(int id, int mem, int color, int width, int flat)
232 {
233  geovect *gv;
234 
235  if (NULL == (gv = gv_get_vect(id))) {
236  return (-1);
237  }
238 
239  gv->use_mem = mem;
240  gv->color = color;
241  gv->width = width;
242  gv->flat_val = flat;
243 
244  return (1);
245 }
246 
259 int GV_get_vectmode(int id, int *mem, int *color, int *width, int *flat)
260 {
261  geovect *gv;
262 
263  if (NULL == (gv = gv_get_vect(id))) {
264  return (-1);
265  }
266 
267  *mem = gv->use_mem;
268  *color = gv->color;
269  *width = gv->width;
270  *flat = gv->flat_val;
271 
272  return (1);
273 }
274 
281 void GV_set_trans(int id, float xtrans, float ytrans, float ztrans)
282 {
283  geovect *gv;
284 
285  G_debug(3, "GV_set_trans");
286 
287  gv = gv_get_vect(id);
288 
289  if (gv) {
290  gv->x_trans = xtrans;
291  gv->y_trans = ytrans;
292  gv->z_trans = ztrans;
293  }
294 
295  return;
296 }
297 
304 int GV_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
305 {
306  geovect *gv;
307 
308  gv = gv_get_vect(id);
309 
310  if (gv) {
311  *xtrans = gv->x_trans;
312  *ytrans = gv->y_trans;
313  *ztrans = gv->z_trans;
314 
315  return (1);
316  }
317 
318  return (-1);
319 }
320 
331 int GV_select_surf(int hv, int hs)
332 {
333  geovect *gv;
334 
335  if (GV_surf_is_selected(hv, hs)) {
336  return (1);
337  }
338 
339  gv = gv_get_vect(hv);
340 
341  if (gv && GS_surf_exists(hs)) {
342  gv->drape_surf_id[gv->n_surfs] = hs;
343  gv->n_surfs += 1;
344 
345  return (1);
346  }
347 
348  return (-1);
349 }
350 
360 int GV_unselect_surf(int hv, int hs)
361 {
362  geovect *gv;
363  int i, j;
364 
365  if (!GV_surf_is_selected(hv, hs)) {
366  return (1);
367  }
368 
369  gv = gv_get_vect(hv);
370 
371  if (gv) {
372  for (i = 0; i < gv->n_surfs; i++) {
373  if (gv->drape_surf_id[i] == hs) {
374  for (j = i; j < gv->n_surfs - 1; j++) {
375  gv->drape_surf_id[j] = gv->drape_surf_id[j + 1];
376  }
377 
378  gv->n_surfs -= 1;
379 
380  return (1);
381  }
382  }
383  }
384 
385  return (-1);
386 }
387 
397 int GV_surf_is_selected(int hv, int hs)
398 {
399  int i;
400  geovect *gv;
401 
402  gv = gv_get_vect(hv);
403 
404  if (gv) {
405  for (i = 0; i < gv->n_surfs; i++) {
406  if (hs == gv->drape_surf_id[i]) {
407  return (1);
408  }
409  }
410  }
411 
412  return (0);
413 }
414 
420 void GV_draw_vect(int vid)
421 {
422  geosurf *gs;
423  geovect *gv;
424  int i;
425 
426  gv = gv_get_vect(vid);
427 
428  if (gv) {
429  for (i = 0; i < gv->n_surfs; i++) {
430  gs = gs_get_surf(gv->drape_surf_id[i]);
431 
432  if (gs) {
433  gvd_vect(gv, gs, 0);
434  }
435  }
436  }
437 
438  return;
439 }
440 
444 void GV_alldraw_vect(void)
445 {
446  int id;
447 
448  for (id = 0; id < Next_vect; id++) {
449  GV_draw_vect(Vect_ID[id]);
450  }
451 
452  return;
453 }
454 
460 void GV_draw_fastvect(int vid)
461 {
462  geosurf *gs;
463  geovect *gv;
464  int i;
465 
466  gv = gv_get_vect(vid);
467 
468  if (gv) {
469  for (i = 0; i < gv->n_surfs; i++) {
470  gs = gs_get_surf(gv->drape_surf_id[i]);
471 
472  if (gs) {
473  gvd_vect(gv, gs, 1);
474  }
475  }
476  }
477 
478  return;
479 }
480 
490 int GV_Set_ClientData(int id, void *clientd)
491 {
492  geovect *gv;
493 
494  gv = gv_get_vect(id);
495  if (gv) {
496  gv->clientdata = clientd;
497 
498  return (1);
499  }
500 
501  return (-1);
502 }
503 
512 void *GV_Get_ClientData(int id)
513 {
514  geovect *gv;
515 
516  gv = gv_get_vect(id);
517 
518  if (gv) {
519  return (gv->clientdata);
520  }
521 
522  return (NULL);
523 }
int * GV_get_vect_list(int *numvects)
Get list of vector sets.
Definition: GV2.c:101
int GV_load_vector(int id, const char *filename)
Load vector set.
Definition: GV2.c:174
void gv_delete_vect(int id)
Delete vector set (unload)
Definition: gv.c:230
char * G_store(const char *s)
Copy string to allocated memory.
Definition: store.c:32
geoline * Gv_load_vect(const char *grassname, int *nlines)
Load vector map to memory.
Definition: Gv3.c:45
int GV_get_vectmode(int id, int *mem, int *color, int *width, int *flat)
Get vector set mode.
Definition: GV2.c:259
int GS_surf_exists(int id)
Definition: GS2.c:194
tuple width
int GV_vect_exists(int id)
Check if vector set exists.
Definition: GV2.c:38
void * GV_Get_ClientData(int id)
Get client data.
Definition: GV2.c:512
int GV_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
Get trans ?
Definition: GV2.c:304
int gvd_vect(geovect *gv, geosurf *gs, int do_fast)
Draw vector set.
Definition: gvd.c:83
void GV_alldraw_vect(void)
Draw all vector sets.
Definition: GV2.c:444
void GV_draw_fastvect(int vid)
Draw vector sets.
Definition: GV2.c:460
tuple id
self.OnVectorSurface(event)
Definition: tools.py:3426
int GV_surf_is_selected(int hv, int hs)
Check if surface is selected.
Definition: GV2.c:397
int GV_delete_vector(int id)
Delete vector set from list.
Definition: GV2.c:131
tuple color
Definition: tools.py:1703
int gv_set_defaults(geovect *gv)
Set attributes of vector set to default values.
Definition: gv.c:180
int GV_get_vectname(int id, char **filename)
Get vector map name.
Definition: GV2.c:206
int GV_unselect_surf(int hv, int hs)
Unselect surface.
Definition: GV2.c:360
int GV_num_vects(void)
Get number of available vector sets.
Definition: GV2.c:86
int GV_Set_ClientData(int id, void *clientd)
Set client data.
Definition: GV2.c:490
geosurf * gs_get_surf(int id)
Get geosurf struct.
Definition: gs.c:62
geovect * gv_get_vect(int id)
Get vector set.
Definition: gv.c:37
return NULL
Definition: dbfopen.c:1394
void GV_draw_vect(int vid)
Draw vector set.
Definition: GV2.c:420
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
int GV_new_vector(void)
Register new vector set.
Definition: GV2.c:63
geovect * gv_get_new_vect(void)
Allocate memory for new vector set.
Definition: gv.c:119
int gv_num_vects(void)
Get number of loaded vector sets.
Definition: gv.c:80
void gv_free_vectmem(geovect *fv)
Free allocated memory.
Definition: gv.c:301
int GV_select_surf(int hv, int hs)
Select surface identified by hs to have vector identified by hv draped over it.
Definition: GV2.c:331
void GV_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
Definition: GV2.c:281
int GV_set_vectmode(int id, int mem, int color, int width, int flat)
Set vector set mode.
Definition: GV2.c:231