GRASS GIS 7 Programmer's Manual  7.0.3(2016)-r00000
gv2.c
Go to the documentation of this file.
1 
16 #include <stdlib.h>
17 #include <string.h>
18 
19 #include <grass/gis.h>
20 #include <grass/ogsf.h>
21 
22 #include "gsget.h"
23 
24 static int Vect_ID[MAX_VECTS];
25 static int Next_vect = 0;
26 
35 int GV_vect_exists(int id)
36 {
37  int i, found = 0;
38 
39  G_debug(3, "GV_vect_exists");
40 
41  if (NULL == gv_get_vect(id)) {
42  return (0);
43  }
44 
45  for (i = 0; i < Next_vect && !found; i++) {
46  if (Vect_ID[i] == id) {
47  found = 1;
48  }
49  }
50 
51  return (found);
52 }
53 
60 int GV_new_vector(void)
61 {
62  geovect *nv;
63 
64  if (Next_vect < MAX_VECTS) {
65  nv = gv_get_new_vect();
66  gv_set_defaults(nv);
67  Vect_ID[Next_vect] = nv->gvect_id;
68  ++Next_vect;
69 
70  G_debug(3, "GV_new_vector(): id=%d", nv->gvect_id);
71 
72  return nv->gvect_id;
73  }
74 
75  return -1;
76 }
77 
83 int GV_num_vects(void)
84 {
85  return (gv_num_vects());
86 }
87 
98 int *GV_get_vect_list(int *numvects)
99 {
100  int i, *ret;
101 
102  *numvects = Next_vect;
103 
104  if (Next_vect) {
105  ret = (int *)G_malloc(Next_vect * sizeof(int));
106  if (!ret) {
107  return (NULL);
108  }
109 
110  for (i = 0; i < Next_vect; i++) {
111  ret[i] = Vect_ID[i];
112  }
113 
114  return (ret);
115  }
116 
117  return (NULL);
118 }
119 
128 int GV_delete_vector(int id)
129 {
130  int i, j, found = 0;
131 
132  G_debug(3, "GV_delete_vect");
133 
134  if (GV_vect_exists(id)) {
135  gv_delete_vect(id);
136 
137  for (i = 0; i < Next_vect && !found; i++) {
138  if (Vect_ID[i] == id) {
139  found = 1;
140 
141  for (j = i; j < Next_vect; j++) {
142  Vect_ID[j] = Vect_ID[j + 1];
143  }
144  }
145  }
146 
147  if (found) {
148  --Next_vect;
149  return (1);
150  }
151  }
152 
153  return (-1);
154 }
155 
171 int GV_load_vector(int id, const char *filename)
172 {
173  geovect *gv;
174 
175  if (NULL == (gv = gv_get_vect(id))) {
176  return (-1);
177  }
178 
179  if (gv->lines) {
180  gv_free_vectmem(gv);
181  }
182 
183  gv->filename = G_store(filename);
184 
185  if ((gv->lines = Gv_load_vect(filename, &(gv->n_lines)))) {
186  return (1);
187  }
188 
189  return (-1);
190 }
191 
203 int GV_get_vectname(int id, char **filename)
204 {
205  geovect *gv;
206 
207  if (NULL == (gv = gv_get_vect(id))) {
208  return (-1);
209  }
210 
211  *filename = G_store(gv->filename);
212 
213  return (1);
214 }
215 
228 int GV_set_style(int id, int mem, int color, int width, int use_z)
229 {
230  geovect *gv;
231 
232  if (NULL == (gv = gv_get_vect(id))) {
233  return -1;
234  }
235 
236  gv->use_mem = mem;
237  gv->use_z = use_z;
238  gv->style->color = color;
239  gv->style->width = width;
240 
241  return 1;
242 }
243 
244 
257 int GV_get_style(int id, int *mem, int *color, int *width, int *use_z)
258 {
259  geovect *gv;
260 
261  if (NULL == (gv = gv_get_vect(id))) {
262  return -1;
263  }
264 
265  *mem = gv->use_mem;
266  *color = gv->style->color;
267  *width = gv->style->width;
268  *use_z = gv->use_z;
269 
270  return 1;
271 }
272 
287 int GV_set_style_thematic(int id, int layer, const char* color, const char* width,
288  struct Colors *color_rules)
289 {
290  geovect *gv;
291 
292  if (NULL == (gv = gv_get_vect(id))) {
293  return -1;
294  }
295 
296  if(!gv->tstyle)
297  gv->tstyle = (gvstyle_thematic *)G_malloc(sizeof(gvstyle_thematic));
298  G_zero(gv->tstyle, sizeof(gvstyle_thematic));
299 
300  gv->tstyle->active = 1;
301  gv->tstyle->layer = layer;
302  if (color)
303  gv->tstyle->color_column = G_store(color);
304  if (width)
305  gv->tstyle->width_column = G_store(width);
306 
307  Gv_load_vect_thematic(gv, color_rules);
308 
309  return 1;
310 }
311 
321 {
322  geovect *gv;
323 
324  G_debug(4, "GV_unset_style_thematic(): id=%d", id);
325 
326  if (NULL == (gv = gv_get_vect(id))) {
327  return -1;
328  }
329 
330  if (gv->tstyle) {
331  gv->tstyle->active = 0;
332  }
333 
334  return 1;
335 }
336 
343 void GV_set_trans(int id, float xtrans, float ytrans, float ztrans)
344 {
345  geovect *gv;
346 
347  G_debug(3, "GV_set_trans");
348 
349  gv = gv_get_vect(id);
350 
351  if (gv) {
352  gv->x_trans = xtrans;
353  gv->y_trans = ytrans;
354  gv->z_trans = ztrans;
355  }
356 
357  return;
358 }
359 
366 int GV_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
367 {
368  geovect *gv;
369 
370  gv = gv_get_vect(id);
371 
372  if (gv) {
373  *xtrans = gv->x_trans;
374  *ytrans = gv->y_trans;
375  *ztrans = gv->z_trans;
376 
377  return (1);
378  }
379 
380  return (-1);
381 }
382 
393 int GV_select_surf(int hv, int hs)
394 {
395  geovect *gv;
396 
397  if (GV_surf_is_selected(hv, hs)) {
398  return (1);
399  }
400 
401  gv = gv_get_vect(hv);
402 
403  if (gv && GS_surf_exists(hs)) {
404  gv->drape_surf_id[gv->n_surfs] = hs;
405  gv->n_surfs += 1;
406 
407  return (1);
408  }
409 
410  return (-1);
411 }
412 
422 int GV_unselect_surf(int hv, int hs)
423 {
424  geovect *gv;
425  int i, j;
426 
427  if (!GV_surf_is_selected(hv, hs)) {
428  return (1);
429  }
430 
431  gv = gv_get_vect(hv);
432 
433  if (gv) {
434  for (i = 0; i < gv->n_surfs; i++) {
435  if (gv->drape_surf_id[i] == hs) {
436  for (j = i; j < gv->n_surfs - 1; j++) {
437  gv->drape_surf_id[j] = gv->drape_surf_id[j + 1];
438  }
439 
440  gv->n_surfs -= 1;
441 
442  return (1);
443  }
444  }
445  }
446 
447  return (-1);
448 }
449 
459 int GV_surf_is_selected(int hv, int hs)
460 {
461  int i;
462  geovect *gv;
463 
464  gv = gv_get_vect(hv);
465 
466  if (gv) {
467  for (i = 0; i < gv->n_surfs; i++) {
468  if (hs == gv->drape_surf_id[i]) {
469  return (1);
470  }
471  }
472  }
473 
474  return (0);
475 }
476 
482 void GV_draw_vect(int vid)
483 {
484  geosurf *gs;
485  geovect *gv;
486  int i;
487 
488  gv = gv_get_vect(vid);
489 
490  if (gv) {
491  for (i = 0; i < gv->n_surfs; i++) {
492  gs = gs_get_surf(gv->drape_surf_id[i]);
493 
494  if (gs) {
495  gvd_vect(gv, gs, 0);
496  }
497  }
498  }
499 
500  return;
501 }
502 
506 void GV_alldraw_vect(void)
507 {
508  int id;
509 
510  for (id = 0; id < Next_vect; id++) {
511  GV_draw_vect(Vect_ID[id]);
512  }
513 
514  return;
515 }
516 
524 void GV_draw_fastvect(int vid)
525 {
526  geosurf *gs;
527  geovect *gv;
528  int i;
529 
530  gv = gv_get_vect(vid);
531 
532  if (gv) {
533  for (i = 0; i < gv->n_surfs; i++) {
534  gs = gs_get_surf(gv->drape_surf_id[i]);
535 
536  if (gs) {
537  gvd_vect(gv, gs, 1);
538  }
539  }
540  }
541 
542  return;
543 }
544 
549 {
550  int id;
551 
552  for (id = 0; id < Next_vect; id++) {
553  GV_draw_fastvect(Vect_ID[id]);
554  }
555 
556  return;
557 }
558 
568 int GV_Set_ClientData(int id, void *clientd)
569 {
570  geovect *gv;
571 
572  gv = gv_get_vect(id);
573  if (gv) {
574  gv->clientdata = clientd;
575 
576  return (1);
577  }
578 
579  return (-1);
580 }
581 
590 void *GV_Get_ClientData(int id)
591 {
592  geovect *gv;
593 
594  gv = gv_get_vect(id);
595 
596  if (gv) {
597  return (gv->clientdata);
598  }
599 
600  return (NULL);
601 }
void * GV_Get_ClientData(int id)
Get client data.
Definition: gv2.c:590
int GV_get_style(int id, int *mem, int *color, int *width, int *use_z)
Get vector style.
Definition: gv2.c:257
void GV_alldraw_fastvect(void)
Draw all loaded vector sets (fast mode)
Definition: gv2.c:548
void gv_delete_vect(int id)
Delete vector set (unload)
Definition: gv.c:239
void G_zero(void *buf, int i)
Zero out a buffer, buf, of length i.
Definition: zero.c:23
int GV_load_vector(int id, const char *filename)
Load vector set.
Definition: gv2.c:171
int GV_set_style_thematic(int id, int layer, const char *color, const char *width, struct Colors *color_rules)
Set vector set style for thematic mapping.
Definition: gv2.c:287
char * G_store(const char *s)
Copy string to allocated memory.
Definition: strings.c:86
void GV_alldraw_vect(void)
Draw all loaded vector sets.
Definition: gv2.c:506
int GV_delete_vector(int id)
Delete vector set from list.
Definition: gv2.c:128
#define NULL
Definition: ccmath.h:32
geoline * Gv_load_vect(const char *grassname, int *nlines)
Load vector map to memory.
Definition: gv3.c:47
int GS_surf_exists(int id)
Definition: gs2.c:195
int gvd_vect(geovect *gv, geosurf *gs, int do_fast)
Draw vector set.
Definition: gvd.c:79
int GV_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
Get trans ?
Definition: gv2.c:366
int GV_Set_ClientData(int id, void *clientd)
Set client data.
Definition: gv2.c:568
int GV_get_vectname(int id, char **filename)
Get vector map name.
Definition: gv2.c:203
int GV_vect_exists(int id)
Check if vector set exists.
Definition: gv2.c:35
void GV_draw_vect(int vid)
Draw vector set.
Definition: gv2.c:482
int GV_unselect_surf(int hv, int hs)
Unselect surface.
Definition: gv2.c:422
int GV_set_style(int id, int mem, int color, int width, int use_z)
Set vector style.
Definition: gv2.c:228
int GV_num_vects(void)
Get number of available vector sets.
Definition: gv2.c:83
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: debug.c:65
void GV_draw_fastvect(int vid)
Draw vector set (fast mode)
Definition: gv2.c:524
int gv_set_defaults(geovect *gv)
Set attributes of vector set to default values.
Definition: gv.c:184
int Gv_load_vect_thematic(geovect *gv, struct Colors *colors)
Load styles for geolines based on thematic mapping.
Definition: gv3.c:313
int GV_surf_is_selected(int hv, int hs)
Check if surface is selected.
Definition: gv2.c:459
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:33
int GV_unset_style_thematic(int id)
Make style for thematic mapping inactive.
Definition: gv2.c:320
void GV_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
Definition: gv2.c:343
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:393
geovect * gv_get_new_vect(void)
Allocate memory for new vector set.
Definition: gv.c:115
int * GV_get_vect_list(int *numvects)
Get list of vector sets.
Definition: gv2.c:98
int gv_num_vects(void)
Get number of loaded vector sets.
Definition: gv.c:76
void gv_free_vectmem(geovect *fv)
Free allocated memory.
Definition: gv.c:310
int GV_new_vector(void)
Register new vector set.
Definition: gv2.c:60