GRASS Programmer's Manual  6.4.2(2012)
GP2.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 Site_ID[MAX_SITES];
00028 static int Next_site = 0;
00029 
00038 int GP_site_exists(int id)
00039 {
00040     int i, found = 0;
00041 
00042     if (NULL == gp_get_site(id)) {
00043         return (0);
00044     }
00045 
00046     for (i = 0; i < Next_site && !found; i++) {
00047         if (Site_ID[i] == id) {
00048             found = 1;
00049         }
00050     }
00051 
00052     G_debug(3, "GP_site_exists(): found=%d", found);
00053 
00054     return (found);
00055 }
00056 
00063 int GP_new_site(void)
00064 {
00065     geosite *np;
00066 
00067     if (Next_site < MAX_SITES) {
00068         np = gp_get_new_site();
00069         gp_set_defaults(np);
00070         Site_ID[Next_site] = np->gsite_id;
00071         ++Next_site;
00072 
00073         G_debug(3, "GP_new_site() id=%d", np->gsite_id);
00074 
00075         return (np->gsite_id);
00076     }
00077 
00078     return (-1);
00079 }
00080 
00086 int GP_num_sites(void)
00087 {
00088     return (gp_num_sites());
00089 }
00090 
00101 int *GP_get_site_list(int *numsites)
00102 {
00103     int i, *ret;
00104 
00105     *numsites = Next_site;
00106 
00107     if (Next_site) {
00108         ret = (int *)G_malloc(Next_site * sizeof(int)); /* G_fatal_error */
00109         if (!ret) {
00110             return (NULL);
00111         }
00112 
00113         for (i = 0; i < Next_site; i++) {
00114             ret[i] = Site_ID[i];
00115         }
00116 
00117         return (ret);
00118     }
00119 
00120     return (NULL);
00121 }
00122 
00131 int GP_delete_site(int id)
00132 {
00133     int i, j, found = 0;
00134 
00135     G_debug(3, "GP_delete_site(): id=%d", id);
00136 
00137     if (GP_site_exists(id)) {
00138         gp_delete_site(id);
00139 
00140         for (i = 0; i < Next_site && !found; i++) {
00141             if (Site_ID[i] == id) {
00142                 found = 1;
00143                 for (j = i; j < Next_site; j++) {
00144                     Site_ID[j] = Site_ID[j + 1];
00145                 }
00146             }
00147         }
00148 
00149         if (found) {
00150             --Next_site;
00151             return (1);
00152         }
00153     }
00154 
00155     return (-1);
00156 }
00157 
00173 int GP_load_site(int id, const char *filename)
00174 {
00175     geosite *gp;
00176 
00177     if (NULL == (gp = gp_get_site(id))) {
00178         return (-1);
00179     }
00180 
00181     if (gp->points) {
00182         gp_free_sitemem(gp);
00183     }
00184 
00185     gp->filename = G_store(filename);
00186 
00187     gp->points = Gp_load_sites(filename, &(gp->n_sites),
00188                                &(gp->has_z), &(gp->has_att));
00189 
00190     if (gp->points) {
00191         return (1);
00192     }
00193 
00194     return (-1);
00195 }
00196 
00208 int GP_get_sitename(int id, char **filename)
00209 {
00210     geosite *gp;
00211 
00212     if (NULL == (gp = gp_get_site(id))) {
00213         return (-1);
00214     }
00215 
00216     *filename = G_store(gp->filename);
00217 
00218     return (1);
00219 }
00220 
00224 int GP_get_sitemode(int id, int *atmod, int *color, int *width, float *size,
00225                     int *marker)
00226 {
00227     geosite *gp;
00228 
00229     if (NULL == (gp = gp_get_site(id))) {
00230         return (-1);
00231     }
00232 
00233     *atmod = gp->attr_mode;
00234     *color = gp->color;
00235     *width = gp->width;
00236     *marker = gp->marker;
00237     *size = gp->size;
00238 
00239     return (1);
00240 }
00241 
00254 int GP_set_sitemode(int id, int atmod, int color, int width, float size,
00255                     int marker)
00256 {
00257     geosite *gp;
00258 
00259     if (NULL == (gp = gp_get_site(id))) {
00260         return (-1);
00261     }
00262 
00263     gp->attr_mode = atmod;      /* FIX this - probably should be seperate */
00264     gp->color = color;
00265     gp->width = width;
00266     gp->marker = marker;
00267     gp->size = size;
00268 
00269     return (1);
00270 }
00271 
00284 int GP_attmode_color(int id, const char *filename)
00285 {
00286     geosite *gp;
00287 
00288     if (NULL == (gp = gp_get_site(id))) {
00289         return (-1);
00290     }
00291 
00292     if (!gp->has_att) {
00293         return (0);
00294     }
00295 
00296     if (Gp_set_color(filename, gp->points)) {
00297         gp->attr_mode = ST_ATT_COLOR;
00298         return (1);
00299     }
00300 
00301     return (-1);
00302 }
00303 
00312 int GP_attmode_none(int id)
00313 {
00314     geosite *gp;
00315 
00316     if (NULL == (gp = gp_get_site(id))) {
00317         return (-1);
00318     }
00319 
00320     gp->attr_mode = ST_ATT_NONE;
00321 
00322     return (1);
00323 }
00324 
00335 int GP_set_zmode(int id, int use_z)
00336 {
00337     geosite *gp;
00338 
00339     if (NULL == (gp = gp_get_site(id))) {
00340         return (-1);
00341     }
00342 
00343     if (use_z) {
00344         if (gp->has_z) {
00345             gp->use_z = 1;
00346             return (1);
00347         }
00348 
00349         return (0);
00350     }
00351 
00352     gp->use_z = 0;
00353     return (1);
00354 }
00355 
00365 int GP_get_zmode(int id, int *use_z)
00366 {
00367     geosite *gp;
00368 
00369     if (NULL == (gp = gp_get_site(id))) {
00370         return (-1);
00371     }
00372 
00373     *use_z = gp->use_z;
00374     return (1);
00375 }
00376 
00383 void GP_set_trans(int id, float xtrans, float ytrans, float ztrans)
00384 {
00385     geosite *gp;
00386 
00387     G_debug(3, "GP_set_trans(): id=%d trans=%f,%f,%f",
00388             id, xtrans, ytrans, ztrans);
00389 
00390     gp = gp_get_site(id);
00391     if (gp) {
00392         gp->x_trans = xtrans;
00393         gp->y_trans = ytrans;
00394         gp->z_trans = ztrans;
00395     }
00396 
00397     return;
00398 }
00399 
00406 void GP_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
00407 {
00408     geosite *gp;
00409 
00410     gp = gp_get_site(id);
00411 
00412     if (gp) {
00413         *xtrans = gp->x_trans;
00414         *ytrans = gp->y_trans;
00415         *ztrans = gp->z_trans;
00416     }
00417 
00418     G_debug(3, "GP_get_trans(): id=%d, trans=%f,%f,%f",
00419             id, *xtrans, *ytrans, *ztrans);
00420 
00421     return;
00422 }
00423 
00433 int GP_select_surf(int hp, int hs)
00434 {
00435     geosite *gp;
00436 
00437     if (GP_surf_is_selected(hp, hs)) {
00438         return (1);
00439     }
00440 
00441     gp = gp_get_site(hp);
00442 
00443     if (gp && GS_surf_exists(hs)) {
00444         gp->drape_surf_id[gp->n_surfs] = hs;
00445         gp->n_surfs += 1;
00446         return (1);
00447     }
00448 
00449     return (-1);
00450 }
00451 
00461 int GP_unselect_surf(int hp, int hs)
00462 {
00463     geosite *gp;
00464     int i, j;
00465 
00466     if (!GP_surf_is_selected(hp, hs)) {
00467         return (1);
00468     }
00469 
00470     gp = gp_get_site(hp);
00471 
00472     if (gp) {
00473         for (i = 0; i < gp->n_surfs; i++) {
00474             if (gp->drape_surf_id[i] == hs) {
00475                 for (j = i; j < gp->n_surfs - 1; j++) {
00476                     gp->drape_surf_id[j] = gp->drape_surf_id[j + 1];
00477                 }
00478 
00479                 gp->n_surfs -= 1;
00480                 return (1);
00481             }
00482         }
00483     }
00484 
00485     return (-1);
00486 }
00487 
00497 int GP_surf_is_selected(int hp, int hs)
00498 {
00499     int i;
00500     geosite *gp;
00501 
00502     gp = gp_get_site(hp);
00503 
00504     if (gp) {
00505         for (i = 0; i < gp->n_surfs; i++) {
00506             if (hs == gp->drape_surf_id[i]) {
00507                 return (1);
00508             }
00509         }
00510     }
00511 
00512     return (0);
00513 }
00514 
00520 void GP_draw_site(int id)
00521 {
00522     geosurf *gs;
00523     geosite *gp;
00524     int i;
00525     float n, yo, xo, e;
00526 
00527     gp = gp_get_site(id);
00528     GS_get_region(&n, &yo, &xo, &e);
00529 
00530     /* kind of sloppy - maybe site files should have an origin, too */
00531     if (gp) {
00532         if (gp->use_z && gp->has_z) {
00533             gpd_3dsite(gp, xo, yo, 0);
00534         }
00535         else {
00536             for (i = 0; i < gp->n_surfs; i++) {
00537                 gs = gs_get_surf(gp->drape_surf_id[i]);
00538 
00539                 if (gs) {
00540                     gpd_2dsite(gp, gs, 0);
00541 #ifdef TRACE_GP_FUNCS
00542                     G_debug(3, "Drawing site %d on Surf %d", id,
00543                             gp->drape_surf_id[i]);
00544                     print_site_fields(gp);
00545 #endif
00546                 }
00547             }
00548         }
00549     }
00550 
00551     return;
00552 }
00553 
00557 void GP_alldraw_site(void)
00558 {
00559     int id;
00560 
00561     for (id = 0; id < Next_site; id++) {
00562         GP_draw_site(Site_ID[id]);
00563     }
00564 
00565     return;
00566 }
00567 
00577 int GP_Set_ClientData(int id, void *clientd)
00578 {
00579     geosite *gp;
00580 
00581     gp = gp_get_site(id);
00582 
00583     if (gp) {
00584         gp->clientdata = clientd;
00585         return (1);
00586     }
00587 
00588     return (-1);
00589 }
00590 
00599 void *GP_Get_ClientData(int id)
00600 {
00601     geosite *gp;
00602 
00603     gp = gp_get_site(id);
00604     if (gp) {
00605         return (gp->clientdata);
00606     }
00607 
00608     return (NULL);
00609 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines