GRASS Programmer's Manual  6.4.2(2012)
GV2.c
Go to the documentation of this file.
00001 
00019 #include <stdlib.h>
00020 #include <string.h>
00021 
00022 #include <grass/gis.h>
00023 #include <grass/gstypes.h>
00024 
00025 #include "gsget.h"
00026 
00027 static int Vect_ID[MAX_VECTS];
00028 static int Next_vect = 0;
00029 
00038 int GV_vect_exists(int id)
00039 {
00040     int i, found = 0;
00041 
00042     G_debug(3, "GV_vect_exists");
00043 
00044     if (NULL == gv_get_vect(id)) {
00045         return (0);
00046     }
00047 
00048     for (i = 0; i < Next_vect && !found; i++) {
00049         if (Vect_ID[i] == id) {
00050             found = 1;
00051         }
00052     }
00053 
00054     return (found);
00055 }
00056 
00063 int GV_new_vector(void)
00064 {
00065     geovect *nv;
00066 
00067     if (Next_vect < MAX_VECTS) {
00068         nv = gv_get_new_vect();
00069         gv_set_defaults(nv);
00070         Vect_ID[Next_vect] = nv->gvect_id;
00071         ++Next_vect;
00072 
00073         G_debug(3, "GV_new_vector(): id=%d", nv->gvect_id);
00074 
00075         return (nv->gvect_id);
00076     }
00077 
00078     return (-1);
00079 }
00080 
00086 int GV_num_vects(void)
00087 {
00088     return (gv_num_vects());
00089 }
00090 
00101 int *GV_get_vect_list(int *numvects)
00102 {
00103     int i, *ret;
00104 
00105     *numvects = Next_vect;
00106 
00107     if (Next_vect) {
00108         ret = (int *)G_malloc(Next_vect * sizeof(int));
00109         if (!ret) {
00110             return (NULL);
00111         }
00112 
00113         for (i = 0; i < Next_vect; i++) {
00114             ret[i] = Vect_ID[i];
00115         }
00116 
00117         return (ret);
00118     }
00119 
00120     return (NULL);
00121 }
00122 
00131 int GV_delete_vector(int id)
00132 {
00133     int i, j, found = 0;
00134 
00135     G_debug(3, "GV_delete_vect");
00136 
00137     if (GV_vect_exists(id)) {
00138         gv_delete_vect(id);
00139 
00140         for (i = 0; i < Next_vect && !found; i++) {
00141             if (Vect_ID[i] == id) {
00142                 found = 1;
00143 
00144                 for (j = i; j < Next_vect; j++) {
00145                     Vect_ID[j] = Vect_ID[j + 1];
00146                 }
00147             }
00148         }
00149 
00150         if (found) {
00151             --Next_vect;
00152             return (1);
00153         }
00154     }
00155 
00156     return (-1);
00157 }
00158 
00174 int GV_load_vector(int id, const char *filename)
00175 {
00176     geovect *gv;
00177 
00178     if (NULL == (gv = gv_get_vect(id))) {
00179         return (-1);
00180     }
00181 
00182     if (gv->lines) {
00183         gv_free_vectmem(gv);
00184     }
00185 
00186     gv->filename = G_store(filename);
00187 
00188     if ((gv->lines = Gv_load_vect(filename, &(gv->n_lines)))) {
00189         return (1);
00190     }
00191 
00192     return (-1);
00193 }
00194 
00206 int GV_get_vectname(int id, char **filename)
00207 {
00208     geovect *gv;
00209 
00210     if (NULL == (gv = gv_get_vect(id))) {
00211         return (-1);
00212     }
00213 
00214     *filename = G_store(gv->filename);
00215 
00216     return (1);
00217 }
00218 
00231 int GV_set_vectmode(int id, int mem, int color, int width, int flat)
00232 {
00233     geovect *gv;
00234 
00235     if (NULL == (gv = gv_get_vect(id))) {
00236         return (-1);
00237     }
00238 
00239     gv->use_mem = mem;
00240     gv->color = color;
00241     gv->width = width;
00242     gv->flat_val = flat;
00243 
00244     return (1);
00245 }
00246 
00259 int GV_get_vectmode(int id, int *mem, int *color, int *width, int *flat)
00260 {
00261     geovect *gv;
00262 
00263     if (NULL == (gv = gv_get_vect(id))) {
00264         return (-1);
00265     }
00266 
00267     *mem = gv->use_mem;
00268     *color = gv->color;
00269     *width = gv->width;
00270     *flat = gv->flat_val;
00271 
00272     return (1);
00273 }
00274 
00281 void GV_set_trans(int id, float xtrans, float ytrans, float ztrans)
00282 {
00283     geovect *gv;
00284 
00285     G_debug(3, "GV_set_trans");
00286 
00287     gv = gv_get_vect(id);
00288 
00289     if (gv) {
00290         gv->x_trans = xtrans;
00291         gv->y_trans = ytrans;
00292         gv->z_trans = ztrans;
00293     }
00294 
00295     return;
00296 }
00297 
00304 int GV_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
00305 {
00306     geovect *gv;
00307 
00308     gv = gv_get_vect(id);
00309 
00310     if (gv) {
00311         *xtrans = gv->x_trans;
00312         *ytrans = gv->y_trans;
00313         *ztrans = gv->z_trans;
00314 
00315         return (1);
00316     }
00317 
00318     return (-1);
00319 }
00320 
00331 int GV_select_surf(int hv, int hs)
00332 {
00333     geovect *gv;
00334 
00335     if (GV_surf_is_selected(hv, hs)) {
00336         return (1);
00337     }
00338 
00339     gv = gv_get_vect(hv);
00340 
00341     if (gv && GS_surf_exists(hs)) {
00342         gv->drape_surf_id[gv->n_surfs] = hs;
00343         gv->n_surfs += 1;
00344 
00345         return (1);
00346     }
00347 
00348     return (-1);
00349 }
00350 
00360 int GV_unselect_surf(int hv, int hs)
00361 {
00362     geovect *gv;
00363     int i, j;
00364 
00365     if (!GV_surf_is_selected(hv, hs)) {
00366         return (1);
00367     }
00368 
00369     gv = gv_get_vect(hv);
00370 
00371     if (gv) {
00372         for (i = 0; i < gv->n_surfs; i++) {
00373             if (gv->drape_surf_id[i] == hs) {
00374                 for (j = i; j < gv->n_surfs - 1; j++) {
00375                     gv->drape_surf_id[j] = gv->drape_surf_id[j + 1];
00376                 }
00377 
00378                 gv->n_surfs -= 1;
00379 
00380                 return (1);
00381             }
00382         }
00383     }
00384 
00385     return (-1);
00386 }
00387 
00397 int GV_surf_is_selected(int hv, int hs)
00398 {
00399     int i;
00400     geovect *gv;
00401 
00402     gv = gv_get_vect(hv);
00403 
00404     if (gv) {
00405         for (i = 0; i < gv->n_surfs; i++) {
00406             if (hs == gv->drape_surf_id[i]) {
00407                 return (1);
00408             }
00409         }
00410     }
00411 
00412     return (0);
00413 }
00414 
00420 void GV_draw_vect(int vid)
00421 {
00422     geosurf *gs;
00423     geovect *gv;
00424     int i;
00425 
00426     gv = gv_get_vect(vid);
00427 
00428     if (gv) {
00429         for (i = 0; i < gv->n_surfs; i++) {
00430             gs = gs_get_surf(gv->drape_surf_id[i]);
00431 
00432             if (gs) {
00433                 gvd_vect(gv, gs, 0);
00434             }
00435         }
00436     }
00437 
00438     return;
00439 }
00440 
00444 void GV_alldraw_vect(void)
00445 {
00446     int id;
00447 
00448     for (id = 0; id < Next_vect; id++) {
00449         GV_draw_vect(Vect_ID[id]);
00450     }
00451 
00452     return;
00453 }
00454 
00460 void GV_draw_fastvect(int vid)
00461 {
00462     geosurf *gs;
00463     geovect *gv;
00464     int i;
00465 
00466     gv = gv_get_vect(vid);
00467 
00468     if (gv) {
00469         for (i = 0; i < gv->n_surfs; i++) {
00470             gs = gs_get_surf(gv->drape_surf_id[i]);
00471 
00472             if (gs) {
00473                 gvd_vect(gv, gs, 1);
00474             }
00475         }
00476     }
00477 
00478     return;
00479 }
00480 
00490 int GV_Set_ClientData(int id, void *clientd)
00491 {
00492     geovect *gv;
00493 
00494     gv = gv_get_vect(id);
00495     if (gv) {
00496         gv->clientdata = clientd;
00497 
00498         return (1);
00499     }
00500 
00501     return (-1);
00502 }
00503 
00512 void *GV_Get_ClientData(int id)
00513 {
00514     geovect *gv;
00515 
00516     gv = gv_get_vect(id);
00517 
00518     if (gv) {
00519         return (gv->clientdata);
00520     }
00521 
00522     return (NULL);
00523 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines