[GRASS-SVN] r47474 - in grass/trunk: gui/wxpython/gui_modules include lib/nviz lib/ogsf visualization/nviz/src visualization/nviz2/cmd

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 7 08:41:44 EDT 2011


Author: martinl
Date: 2011-08-07 05:41:44 -0700 (Sun, 07 Aug 2011)
New Revision: 47474

Modified:
   grass/trunk/gui/wxpython/gui_modules/wxnviz.py
   grass/trunk/include/gstypes.h
   grass/trunk/include/ogsf_proto.h
   grass/trunk/lib/nviz/map_obj.c
   grass/trunk/lib/ogsf/GP2.c
   grass/trunk/lib/ogsf/GV2.c
   grass/trunk/lib/ogsf/Gp3.c
   grass/trunk/lib/ogsf/Gv3.c
   grass/trunk/lib/ogsf/gp.c
   grass/trunk/lib/ogsf/gpd.c
   grass/trunk/lib/ogsf/gv.c
   grass/trunk/lib/ogsf/gvd.c
   grass/trunk/lib/ogsf/ogsflib.dox
   grass/trunk/visualization/nviz/src/map_obj.c
   grass/trunk/visualization/nviz2/cmd/args.c
   grass/trunk/visualization/nviz2/cmd/local_proto.h
   grass/trunk/visualization/nviz2/cmd/vector.c
Log:
osgflib: thematic mapping for vector lines
	 GV_set_vectmode() renamed to GV_set_style
nviz_cmd: add paramaters for thematic mapping (vlines)


Modified: grass/trunk/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxnviz.py	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/gui/wxpython/gui_modules/wxnviz.py	2011-08-07 12:41:44 UTC (rev 47474)
@@ -807,7 +807,7 @@
         color = Nviz_color_from_str(color_str)
         
         # use memory by default
-        if GV_set_vectmode(id, 1, color, width, flat) < 0:
+        if GV_set_style(id, 1, color, width, flat) < 0:
             return -2
         
         return 1

Modified: grass/trunk/include/gstypes.h
===================================================================
--- grass/trunk/include/gstypes.h	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/include/gstypes.h	2011-08-07 12:41:44 UTC (rev 47474)
@@ -237,10 +237,8 @@
     int (*bgn_read) (), (*end_read) (), (*nxt_line) ();
     struct g_vect *next;
     void *clientdata;
-
-    int thematic_layer;		/* Layer number to use for thematic mapping. <0 == no thematic mapping; 
-				   0 == thematic mapping is unset but initialized; 
-				   >0 use specified layer */
+  
+    gvstyle_thematic *tstyle;  /* thematic mapping */
     gvstyle *style;	/* Vector default look&feel */
     gvstyle *hstyle;	/* IMHO highlight should be per layer basis. */
 } geovect;

Modified: grass/trunk/include/ogsf_proto.h
===================================================================
--- grass/trunk/include/ogsf_proto.h	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/include/ogsf_proto.h	2011-08-07 12:41:44 UTC (rev 47474)
@@ -242,8 +242,10 @@
 int GV_delete_vector(int);
 int GV_load_vector(int, const char *);
 int GV_get_vectname(int, char **);
-int GV_set_vectmode(int, int, int, int, int);
-int GV_get_vectmode(int, int *, int *, int *, int *);
+int GV_set_style(int, int, int, int, int);
+int GV_get_style(int, int *, int *, int *, int *);
+int GV_set_style_thematic(int, int, const char*, const char*);
+int GV_unset_style_thematic(int);
 void GV_set_trans(int, float, float, float);
 int GV_get_trans(int, float *, float *, float *);
 int GV_select_surf(int, int);
@@ -341,6 +343,7 @@
 
 /* Gv3.c */
 geoline *Gv_load_vect(const char *, int *);
+int Gv_load_vect_thematic(geovect *);
 void sub_Vectmem(int);
 
 /* gk.c */

Modified: grass/trunk/lib/nviz/map_obj.c
===================================================================
--- grass/trunk/lib/nviz/map_obj.c	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/lib/nviz/map_obj.c	2011-08-07 12:41:44 UTC (rev 47474)
@@ -101,7 +101,7 @@
 
 	/* initialize display parameters
 	   automatically select all surfaces to draw vector */
-	GV_set_vectmode(new_id, 1, 0xFF0000, 2, 0);
+	GV_set_style(new_id, 1, 0xFF0000, 2, 0);
 	surf_list = GS_get_surf_list(&num_surfs);
 	if (num_surfs) {
 	    for (i = 0; i < num_surfs; i++) {

Modified: grass/trunk/lib/ogsf/GP2.c
===================================================================
--- grass/trunk/lib/ogsf/GP2.c	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/lib/ogsf/GP2.c	2011-08-07 12:41:44 UTC (rev 47474)
@@ -247,7 +247,7 @@
 }
 
 /*!
-   \brief Set point set style
+   \brief Set point style
 
    Supported icon symbols (markers):
     - ST_X

Modified: grass/trunk/lib/ogsf/GV2.c
===================================================================
--- grass/trunk/lib/ogsf/GV2.c	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/lib/ogsf/GV2.c	2011-08-07 12:41:44 UTC (rev 47474)
@@ -72,10 +72,10 @@
 
 	G_debug(3, "GV_new_vector(): id=%d", nv->gvect_id);
 
-	return (nv->gvect_id);
+	return nv->gvect_id;
     }
 
-    return (-1);
+    return -1;
 }
 
 /*!
@@ -217,7 +217,7 @@
 }
 
 /*!
-   \brief Set vector set mode
+   \brief Set vector style
 
    \param id vector set id
    \param mem non-zero for use memory
@@ -228,12 +228,12 @@
    \return -1 on error (invalid vector set id)
    \return 1 on success
  */
-int GV_set_vectmode(int id, int mem, int color, int width, int flat)
+int GV_set_style(int id, int mem, int color, int width, int flat)
 {
     geovect *gv;
 
     if (NULL == (gv = gv_get_vect(id))) {
-	return (-1);
+	return -1;
     }
 
     gv->use_mem = mem;
@@ -241,27 +241,28 @@
     gv->style->color = color;
     gv->style->width = width;
 
-    return (1);
+    return 1;
 }
 
+
 /*!
-   \brief Get vector set mode
+   \brief Get vector style
 
    \param id vector set id
-   \param[out] mem
+   \param[out] mem non-zero for use memory
    \param[out] color color value
-   \param[out] width
-   \param[out] flat
+   \param[out] width line width
+   \param[out] flat non-zero for flat mode
 
    \return -1 on error (invalid vector set id)
    \return 1 on success
  */
-int GV_get_vectmode(int id, int *mem, int *color, int *width, int *flat)
+int GV_get_style(int id, int *mem, int *color, int *width, int *flat)
 {
     geovect *gv;
 
     if (NULL == (gv = gv_get_vect(id))) {
-	return (-1);
+	return -1;
     }
 
     *mem = gv->use_mem;
@@ -269,10 +270,72 @@
     *width = gv->style->width;
     *flat = gv->flat_val;
 
-    return (1);
+    return 1;
 }
 
 /*!
+   \brief Set vector set style for thematic mapping
+   
+   Updates also style for each geoline.
+   
+   \param id vector set id
+   \param layer layer number for thematic mapping
+   \param color color column
+   \param width width column
+   
+   \return 1 on success
+   \return -1 on error (point set not found)
+ */
+int GV_set_style_thematic(int id, int layer, const char* color, const char* width)
+{
+    geovect *gv;
+
+    if (NULL == (gv = gv_get_vect(id))) {
+	return -1;
+    }
+
+    if(!gv->tstyle)
+	gv->tstyle = (gvstyle_thematic *)G_malloc(sizeof(gvstyle_thematic));
+    G_zero(gv->tstyle, sizeof(gvstyle_thematic));
+    
+    gv->tstyle->active = 1;
+    gv->tstyle->layer = layer;
+    if (color)
+	gv->tstyle->color_column = G_store(color);
+    if (width)
+	gv->tstyle->width_column = G_store(width);
+
+    Gv_load_vect_thematic(gv);
+
+    return 1;
+}
+
+/*!
+   \brief Make style for thematic mapping inactive
+   
+   \param id vector set id
+
+   \return 1 on success
+   \return -1 on error (point set not found)
+ */
+int GV_unset_style_thematic(int id)
+{
+    geovect *gv;
+
+    G_debug(4, "GV_unset_style_thematic(): id=%d", id);
+
+    if (NULL == (gv = gv_get_vect(id))) {
+	return -1;
+    }
+
+    if (gv->tstyle) {
+	gv->tstyle->active = 0;
+    }
+
+    return 1;
+}
+
+/*!
    \brief Set trans ?
 
    \param id vector set id

Modified: grass/trunk/lib/ogsf/Gp3.c
===================================================================
--- grass/trunk/lib/ogsf/Gp3.c	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/lib/ogsf/Gp3.c	2011-08-07 12:41:44 UTC (rev 47474)
@@ -158,8 +158,6 @@
 /*!
   \brief Load styles for geopoints based on thematic mapping
 
-  \todo Currently only supports color settings
-  
   \param gp pointer to geosite structure
 
   \return number of points defined by thematic mapping

Modified: grass/trunk/lib/ogsf/Gv3.c
===================================================================
--- grass/trunk/lib/ogsf/Gv3.c	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/lib/ogsf/Gv3.c	2011-08-07 12:41:44 UTC (rev 47474)
@@ -1,31 +1,32 @@
 /*!
-   \file Gv3.c
+   \file lib/ogsf/Gv3.c
 
    \brief OGSF library - loading vector sets (lower level functions)
 
    GRASS OpenGL gsurf OGSF Library 
 
-   (C) 1999-2008 by the GRASS Development Team
+   (C) 1999-2008, 2011 by the GRASS Development Team
 
-   This program is free software under the 
-   GNU General Public License (>=v2). 
-   Read the file COPYING that comes with GRASS
-   for details.
+   This program is free software under the GNU General Public License
+   (>=v2). Read the file COPYING that comes with GRASS for details.
 
    \author Bill Brown USACERL (December 1993)
-   \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
+   \author Updated by Martin Landa <landa.martin gmail.com>
+   (doxygenized in May 2008, thematic mapping in August 2011)
  */
 
 #include <stdlib.h>
 
 #include <grass/gis.h>
+#include <grass/colors.h>
 #include <grass/vector.h>
+#include <grass/dbmi.h>
 #include <grass/glocale.h>
 #include <grass/gstypes.h>
 
 /*
    #define TRAK_MEM
- */
+*/
 
 #ifdef TRAK_MEM
 static int Tot_mem = 0;
@@ -281,6 +282,7 @@
  */
 void sub_Vectmem(int minus)
 {
+    G_debug(5, "sub_Vectmem(): minus=%d", minus);
 #ifdef TRAK_MEM
     {
 	Tot_mem -= minus;
@@ -289,3 +291,98 @@
 
     return;
 }
+
+/*!
+  \brief Load styles for geolines based on thematic mapping
+
+  \param gv pointer to geovect structure
+
+  \return number of features defined by thematic mapping
+  \return -1 on error
+*/
+int Gv_load_vect_thematic(geovect *gv)
+{
+    geoline *gvt;
+
+    struct Map_info Map;
+    struct field_info *Fi;
+    
+    int nvals, cat, nlines;
+    int red, blu, grn;
+    const char *str;
+    const char *mapset;
+
+    dbDriver *driver;
+    dbValue value;
+    
+    if(!gv || !gv->tstyle || !gv->filename)
+	return -1;
+
+    mapset = G_find_vector2(gv->filename, "");
+    if (!mapset) {
+	G_fatal_error(_("Vector map <%s> not found"), gv->filename);
+    }
+    
+    Vect_set_open_level(1);
+    if (Vect_open_old(&Map, gv->filename, "") == -1) {
+	G_fatal_error(_("Unable to open vector map <%s>"),
+		      G_fully_qualified_name(gv->filename, mapset));
+    }
+    
+    Fi = Vect_get_field(&Map, gv->tstyle->layer);
+    if (!Fi)
+	G_fatal_error(_("Database connection not defined for layer %d"),
+		      gv->tstyle->layer);
+    
+    driver = db_start_driver_open_database(Fi->driver, Fi->database);
+    if (!driver)
+	G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+		      Fi->database, Fi->driver);
+    
+    G_message(_("Loading thematic vector layer <%s>..."),
+	      G_fully_qualified_name(gv->filename, mapset));
+    nlines = 0;
+    for(gvt = gv->lines; gvt; gvt = gvt->next) {
+	gvt->style = (gvstyle *) G_malloc(sizeof(gvstyle));
+	G_zero(gvt->style, sizeof(gvstyle));
+	
+	/* use default style */
+	gvt->style->color  = gv->style->color;
+	gvt->style->symbol = gv->style->symbol;
+	gvt->style->size   = gv->style->size;
+	gvt->style->width  = gv->style->width;
+	
+	Vect_cat_get(gvt->cats, gv->tstyle->layer, &cat);
+	if (cat < 0)
+	    continue;
+
+	/* color */
+	if (gv->tstyle->color_column) {
+	    nvals = db_select_value(driver, Fi->table, Fi->key, cat, gv->tstyle->color_column, &value);
+	    if (nvals < 1)
+		continue;
+	    str = db_get_value_string(&value);
+	    if (G_str_to_color(str, &red, &grn, &blu) != 1) {
+		G_warning(_("Invalid color definition (%s)"),
+			  str);
+		gvt->style->color = gv->style->color;
+	    }
+	    else {
+		gvt->style->color = (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) +
+		    ((int)((blu) << 16) & BLU_MASK);
+	    }
+	}
+	
+	/* width */
+	if (gv->tstyle->width_column) {
+	    nvals = db_select_value(driver, Fi->table, Fi->key, cat, gv->tstyle->width_column, &value);
+	    if (nvals < 1)
+		continue;
+	    gvt->style->width = db_get_value_int(&value);
+	}
+
+	nlines++;
+    }
+    
+    return nlines;
+}

Modified: grass/trunk/lib/ogsf/gp.c
===================================================================
--- grass/trunk/lib/ogsf/gp.c	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/lib/ogsf/gp.c	2011-08-07 12:41:44 UTC (rev 47474)
@@ -116,9 +116,7 @@
 geosite *gp_get_new_site(void)
 {
     geosite *np, *lp;
-
-    G_debug(5, "gp_get_new_site");
-
+    
     np = (geosite *) G_malloc(sizeof(geosite));	/* G_fatal_error */
     if (!np) {
 	return NULL;
@@ -143,6 +141,8 @@
 	return NULL;
     G_zero(np->hstyle, sizeof (gvstyle));
 
+    G_debug(5, "gp_get_new_site id=%d", np->gsite_id);
+    
     return np;
 }
 
@@ -187,11 +187,11 @@
 {
     float dim;
 
-    G_debug(5, "gp_set_defaults");
-
     if (!gp) {
 	return -1;
     }
+    G_debug(5, "gp_set_defaults() id=%d", gp->gsite_id);
+
     GS_get_longdim(&dim);
 
     gp->style->color = 0xF0F0F0;
@@ -332,7 +332,7 @@
 	fp->points = NULL;
     }
 
-    if(fp->tstyle) {
+    if (fp->tstyle) {
 	G_free(fp->tstyle->color_column);
 	G_free(fp->tstyle->symbol_column);
 	G_free(fp->tstyle->size_column);

Modified: grass/trunk/lib/ogsf/gpd.c
===================================================================
--- grass/trunk/lib/ogsf/gpd.c	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/lib/ogsf/gpd.c	2011-08-07 12:41:44 UTC (rev 47474)
@@ -227,88 +227,77 @@
 	return 0;
     }
 
-    if (gs) {
-	gs_update_curmask(gs);
+    if (!gs)
+	return 1;
 
-	src = gs_get_att_src(gs, ATT_TOPO);
-
-	if (src == CONST_ATT) {
-	    konst = gs->att[ATT_TOPO].constant;
-	    site[Z] = konst;
+    gs_update_curmask(gs);
+    
+    src = gs_get_att_src(gs, ATT_TOPO);
+    
+    if (src == CONST_ATT) {
+	konst = gs->att[ATT_TOPO].constant;
+	site[Z] = konst;
+    }
+    else {
+	buf = gs_get_att_typbuff(gs, ATT_TOPO, 0);
+    }
+    
+    /* Get viewport parameters for view check */
+    gsd_getwindow(window, viewport, modelMatrix, projMatrix);
+    
+    gsd_pushmatrix();
+    gsd_do_scale(1);
+    gsd_translate(gs->x_trans, gs->y_trans, gs->z_trans);
+    gsd_linewidth(gp->style->width);
+    check = 0;
+    
+    for (gpt = gp->points; gpt; gpt = gpt->next) {
+	if (!(++check % CHK_FREQ)) {
+	    if (GS_check_cancel()) {
+		gsd_linewidth(1);
+		gsd_popmatrix();
+		
+		return 0;
+	    }
 	}
-	else {
-	    buf = gs_get_att_typbuff(gs, ATT_TOPO, 0);
+	
+	site[X] = gpt->p3[X] + gp->x_trans - gs->ox;
+	site[Y] = gpt->p3[Y] + gp->y_trans - gs->oy;
+	
+	if (gs_point_is_masked(gs, site)) {
+	    continue;
 	}
-
-	/* Get viewport parameters for view check */
-	gsd_getwindow(window, viewport, modelMatrix, projMatrix);
-
-	gsd_pushmatrix();
-
-	gsd_do_scale(1);
-
-	gsd_translate(gs->x_trans, gs->y_trans, gs->z_trans);
-
-	gsd_linewidth(gp->style->width);
-	check = 0;
-
-	for (gpt = gp->points; gpt; gpt = gpt->next) {
-	    if (!(++check % CHK_FREQ)) {
-		if (GS_check_cancel()) {
-		    gsd_linewidth(1);
-		    gsd_popmatrix();
-
-		    return 0;
-		}
+	
+	if (gpt->highlighted > 0)
+	    gpd_obj(gs, gp->hstyle, site);
+	else if (gp->tstyle && gp->tstyle->active)
+	    gpd_obj(gs, gpt->style, site);
+	else
+	    gpd_obj(gs, gp->style, site);
+	
+	if (src == MAP_ATT) {
+	    if (viewcell_tri_interp(gs, buf, site, 1)) {
+		/* returns 0 if outside or masked */
+		site[Z] += gp->z_trans;
+		
+		if (gsd_checkpoint(site, window,
+				   viewport, modelMatrix, projMatrix))
+		    continue;
 	    }
-
-	    site[X] = gpt->p3[X] + gp->x_trans - gs->ox;
-	    site[Y] = gpt->p3[Y] + gp->y_trans - gs->oy;
-
-	    if (gs_point_is_masked(gs, site)) {
-		continue;
+	}
+	else if (src == CONST_ATT) {
+	    if (gs_point_in_region(gs, site, NULL)) {
+		site[Z] += gp->z_trans;
+		if (gsd_checkpoint(site, window,
+				   viewport, modelMatrix, projMatrix))
+		    continue;
 	    }
-
-	    if (src == MAP_ATT) {
-		if (viewcell_tri_interp(gs, buf, site, 1)) {
-		    /* returns 0 if outside or masked */
-		    site[Z] += gp->z_trans;
-
-		    if (gsd_checkpoint(site, window,
-				       viewport, modelMatrix, projMatrix))
-			continue;
-		    else {
-			if (gpt->highlighted > 0)
-			    gpd_obj(gs, gp->hstyle, site);
-			else if (gp->tstyle && gp->tstyle->active)
-			    gpd_obj(gs, gpt->style, site);
-			else
-			    gpd_obj(gs, gp->style, site);
-		    }
-		}
-	    }
-	    else if (src == CONST_ATT) {
-		if (gs_point_in_region(gs, site, NULL)) {
-		    site[Z] += gp->z_trans;
-		    if (gsd_checkpoint(site, window,
-				       viewport, modelMatrix, projMatrix))
-			continue;
-		    else {
-			if (gpt->highlighted > 0)
-			    gpd_obj(gs, gp->hstyle, site);
-			else if (gp->tstyle)
-			    gpd_obj(gs, gpt->style, site);
-			else
-			    gpd_obj(gs, gp->style, site);
-		    }
-		}
-	    }
 	}
-
-	gsd_linewidth(1);
-	gsd_popmatrix();
     }
 
+    gsd_linewidth(1);
+    gsd_popmatrix();
+    
     return 1;
 }
 

Modified: grass/trunk/lib/ogsf/gv.c
===================================================================
--- grass/trunk/lib/ogsf/gv.c	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/lib/ogsf/gv.c	2011-08-07 12:41:44 UTC (rev 47474)
@@ -1,17 +1,13 @@
 /*!
-   \file gv.c
+   \file lib/ogsf/gv.c
 
    \brief OGSF library - loading and manipulating vector sets (lower level functions)
 
-   GRASS OpenGL gsurf OGSF Library 
+   (C) 1999-2008, 2011 by the GRASS Development Team
 
-   (C) 1999-2008 by the GRASS Development Team
+   This program is free software under the GNU General Public License
+   (>=v2). Read the file COPYING that comes with GRASS for details.
 
-   This program is free software under the 
-   GNU General Public License (>=v2). 
-   Read the file COPYING that comes with GRASS
-   for details.
-
    \author Bill Brown USACERL (November 1993)
    \author Doxygenized by Martin Landa (June 2008)
  */
@@ -42,11 +38,11 @@
 
     for (gv = Vect_top; gv; gv = gv->next) {
 	if (gv->gvect_id == id) {
-	    return (gv);
+	    return gv;
 	}
     }
 
-    return (NULL);
+    return NULL;
 }
 
 /*!
@@ -65,11 +61,11 @@
 
     for (pv = Vect_top; pv; pv = pv->next) {
 	if (pv->gvect_id == id - 1) {
-	    return (pv);
+	    return pv;
 	}
     }
 
-    return (NULL);
+    return NULL;
 }
 
 /*!
@@ -86,7 +82,7 @@
 
     G_debug(5, "gv_num_vects(): num=%d", i);
 
-    return (i);
+    return i;
 }
 
 /*!
@@ -100,14 +96,14 @@
     geovect *lv;
 
     if (!Vect_top) {
-	return (NULL);
+	return NULL;
     }
 
     for (lv = Vect_top; lv->next; lv = lv->next) ;
 
     G_debug(5, "gv_get_last_vect(): id=%d", lv->gvect_id);
 
-    return (lv);
+    return lv;
 }
 
 /*!
@@ -123,8 +119,9 @@
     nv = (geovect *) G_malloc(sizeof(geovect));
     if (!nv) {
 	/* G_fatal_error */
-	return (NULL);
+	return NULL;
     }
+    G_zero(nv, sizeof(geovect));
 
     if ((lv = gv_get_last_vect())) {
 	lv->next = nv;
@@ -134,19 +131,19 @@
 	Vect_top = nv;
 	nv->gvect_id = FIRST_VECT_ID;
     }
-
-    nv->next = NULL;
-
+    
     nv->style = (gvstyle *) G_malloc(sizeof(gvstyle));
     if (NULL == nv->style)
 	return NULL;
+    G_zero(nv->style, sizeof (gvstyle));
     nv->hstyle = (gvstyle *) G_malloc(sizeof(gvstyle));
     if (NULL == nv->hstyle)
 	return NULL;
+    G_zero(nv->hstyle, sizeof (gvstyle));
 
     G_debug(5, "gv_get_new_vect() id=%d", nv->gvect_id);
 
-    return (nv);
+    return nv;
 }
 
 /*!
@@ -188,11 +185,10 @@
 {
     int i;
 
-    G_debug(5, "gv_set_defaults() id=%d", gv->gvect_id);
-
     if (!gv) {
 	return (-1);
     }
+    G_debug(5, "gv_set_defaults() id=%d", gv->gvect_id);
 
     gv->filename = NULL;
     gv->n_lines = gv->n_surfs = gv->use_mem = 0;
@@ -200,20 +196,20 @@
     gv->lines = NULL;
     gv->fastlines = NULL;
     gv->flat_val = 0;
-    gv->thematic_layer = -1;
     gv->style->color = 0xF0F0F0;
     gv->style->width = 1;
     gv->style->next = NULL;
     gv->hstyle->color = 0xFF0000;
     gv->hstyle->width = 2;
     gv->hstyle->next = NULL;
+    gv->tstyle = NULL;
     gv->next = NULL;
 
     for (i = 0; i < MAX_SURFS; i++) {
 	gv->drape_surf_id[i] = 0;
     }
 
-    return (0);
+    return 0;
 }
 
 /*!
@@ -227,12 +223,12 @@
 int gv_init_vect(geovect * gv)
 {
     if (!gv) {
-	return (-1);
+	return -1;
     }
 
     G_debug(5, "gv_init_vect() id=%d", gv->gvect_id);
 
-    return (0);
+    return 0;
 }
 
 /*!
@@ -300,10 +296,10 @@
 	    fv = NULL;
 	}
 
-	return (1);
+	return 1;
     }
 
-    return (-1);
+    return -1;
 }
 
 /*!
@@ -314,8 +310,7 @@
 void gv_free_vectmem(geovect * fv)
 {
     geoline *gln, *tmpln;
-    gvstyle *gvs, *tmpstyle;
-
+    
     G_free((void *)fv->filename);
     fv->filename = NULL;
     if (fv->style)
@@ -335,14 +330,7 @@
 	    }
 
 	    G_free(gln->cats);
-	    if (fv->thematic_layer > -1) {	/* Style also exists for features */
-		for (gvs = gln->style; gvs;) {
-		    tmpstyle = gvs;
-		    gvs = gvs->next;
-		    G_free(tmpstyle);
-		}
-	    }
-
+	    
 	    tmpln = gln;
 	    gln = gln->next;
 	    sub_Vectmem(sizeof(geoline));
@@ -353,6 +341,13 @@
 	fv->lines = NULL;
     }
 
+    if (fv->tstyle) {
+	G_free(fv->tstyle->color_column);
+	G_free(fv->tstyle->symbol_column);
+	G_free(fv->tstyle->size_column);
+	G_free(fv->tstyle->width_column);
+    }
+
     return;
 }
 

Modified: grass/trunk/lib/ogsf/gvd.c
===================================================================
--- grass/trunk/lib/ogsf/gvd.c	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/lib/ogsf/gvd.c	2011-08-07 12:41:44 UTC (rev 47474)
@@ -1,17 +1,13 @@
 /*!
-   \file gvd.c
+   \file lib/ogsf/gvd.c
 
    \brief OGSF library - loading and manipulating vector sets (lower level functions)
 
-   GRASS OpenGL gsurf OGSF Library 
+   (C) 1999-2008, 2011 by the GRASS Development Team
 
-   (C) 1999-2008 by the GRASS Development Team
-
-   This program is free software under the 
-   GNU General Public License (>=v2). 
-   Read the file COPYING that comes with GRASS
-   for details.
-
+   This program is free software under the GNU General Public License
+   (>=v2).  Read the file COPYING that comes with GRASS for details.
+   
    \author Bill Brown USACERL (December 1993)
    \author Doxygenized by Martin Landa (June 2008)
  */
@@ -92,7 +88,7 @@
     G_debug(5, "gvd_vect(): id=%d", gv->gvect_id);
 
     if (GS_check_cancel()) {
-	return (0);
+	return 0;
     }
 
     gs_update_curmask(gs);
@@ -123,8 +119,6 @@
     gsd_translate(gs->x_trans, gs->y_trans, gs->z_trans + fudge);
 
     gsd_colormode(CM_COLOR);
-    gsd_color_func(gv->style->color);
-    gsd_linewidth(gv->style->width);
 
     check = 0;
     if (do_fast) {
@@ -146,12 +140,27 @@
 		gsd_linewidth(1);
 		gsd_popmatrix();
 
-		return (0);
+		return 0;
 	    }
 	}
 
-	if (gln->type == OGSF_LINE) {	/* line */
-	    if (gln->dims == 2) {	/* 2d line */
+	if (gln->highlighted > 0) {
+	    gsd_color_func(gv->hstyle->color);
+	    gsd_linewidth(gv->hstyle->width);
+	}
+	else if (gv->tstyle && gv->tstyle->active) {
+	    gsd_color_func(gln->style->color);
+	    gsd_linewidth(gln->style->width);
+	}
+	else {
+	    gsd_color_func(gv->style->color);
+	    gsd_linewidth(gv->style->width);
+	}
+
+	/* line */
+	if (gln->type == OGSF_LINE) {	
+	    /* 2D line */
+	    if (gln->dims == 2) {	
 		G_debug(5, "gvd_vect(): 2D vector line");
 		for (k = 0; k < gln->npts - 1; k++) {
 		    bgn[X] = gln->p2[k][X] + gv->x_trans - gs->ox;
@@ -200,8 +209,8 @@
 		    }
 		}
 	    }
-	    else {		/* 3D line */
-
+	    /* 3D line */
+	    else {		
 		G_debug(5, "gvd_vect(): 3D vector line");
 		points = (Point3 *) malloc(sizeof(Point3));
 
@@ -220,8 +229,10 @@
 		free(points);
 	    }
 	}
-	else if (gln->type == OGSF_POLYGON) {	/* polygon */
-	    if (gln->dims == 3) {	/* 3D polygon */
+	/* polygon */
+	else if (gln->type == OGSF_POLYGON) {	
+	    /* 3D polygon */
+	    if (gln->dims == 3) {	
 		G_debug(5, "gvd_vect(): draw 3D polygon");
 
 		/* We want at least 3 points */
@@ -257,7 +268,8 @@
 		    G_free(points);
 		}
 	    }
-	    else {		/* 2D polygons */
+	    else {		
+		/* 2D polygons */
 		/* TODO */
 	    }
 	}
@@ -266,7 +278,7 @@
     gsd_linewidth(1);
     gsd_popmatrix();
 
-    return (1);
+    return 1;
 }
 
 /*!

Modified: grass/trunk/lib/ogsf/ogsflib.dox
===================================================================
--- grass/trunk/lib/ogsf/ogsflib.dox	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/lib/ogsf/ogsflib.dox	2011-08-07 12:41:44 UTC (rev 47474)
@@ -386,7 +386,7 @@
 
 - GV_get_vect_list()
 
-- GV_get_vectmode()
+- GV_get_style()
 
 - GV_get_vectname()
 
@@ -402,7 +402,7 @@
 
 - GV_set_trans()
 
-- GV_set_vectmode()
+- GV_set_style()
 
 - GV_surf_is_selected()
 

Modified: grass/trunk/visualization/nviz/src/map_obj.c
===================================================================
--- grass/trunk/visualization/nviz/src/map_obj.c	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/visualization/nviz/src/map_obj.c	2011-08-07 12:41:44 UTC (rev 47474)
@@ -544,7 +544,7 @@
 
 	/* Initialize display parameters */
 	/* automatically select all surfaces to draw vector */
-	GV_set_vectmode(new_id, 1, 0xFF0000, 2, 0);
+	GV_set_style(new_id, 1, 0xFF0000, 2, 0);
 	surf_list = GS_get_surf_list(&num_surfs);
 	if (num_surfs) {
 	    for (i = 0; i < num_surfs; i++) {
@@ -1580,7 +1580,7 @@
 	    int mem, color, width, flat;
 	    char temp[128], *tempname;
 
-	    GV_get_vectmode(id, &mem, &color, &width, &flat);
+	    GV_get_style(id, &mem, &color, &width, &flat);
 	    switch (sv_att_atoi(argv[2])) {
 	    case ATT_COLOR:
 		Tcl_SetResult(interp, int_to_tcl_color(color), TCL_VOLATILE);
@@ -1812,14 +1812,14 @@
 	else {
 
 	    /* Get the old values of color and width and optionally change one of them */
-	    GV_get_vectmode(id, &mem, &col, &width, &flat);
+	    GV_get_style(id, &mem, &col, &width, &flat);
 	    col =
 		(strncmp(argv[2], "color", 5)) ? col :
 		tcl_color_to_int(argv[3]);
 	    width = (strncmp(argv[2], "width", 5)) ? width : atoi(argv[3]);
 	    flat = (strncmp(argv[2], "flat", 5)) ? flat : atoi(argv[3]);
 
-	    GV_set_vectmode(id, 1, col, width, flat);
+	    GV_set_style(id, 1, col, width, flat);
 
 	}
 	break;

Modified: grass/trunk/visualization/nviz2/cmd/args.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/args.c	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/visualization/nviz2/cmd/args.c	2011-08-07 12:41:44 UTC (rev 47474)
@@ -308,6 +308,14 @@
     params->vlines->guisection = _("Vector lines");
     params->vlines->key = "vline";
 
+    params->vline_layer = G_define_standard_option(G_OPT_V_FIELD);
+    params->vline_layer->multiple = YES;
+    params->vline_layer->required = NO;
+    params->vline_layer->description = _("Layer number or name for thematic mapping");
+    params->vline_layer->guisection = _("Vector lines");
+    params->vline_layer->key = "vline_layer";
+    params->vline_layer->answer = "1";
+
     /* line width */
     params->vline_width = G_define_option();
     params->vline_width->key = "vline_width";
@@ -320,6 +328,13 @@
     params->vline_width->options = "1-100";
     params->vline_width->answer = "2";
 
+    params->vline_width_column = G_define_standard_option(G_OPT_DB_COLUMN);
+    params->vline_width_column->multiple = YES;
+    params->vline_width_column->required = NO;
+    params->vline_width_column->label = _("Name of width definition column");
+    params->vline_width_column->key = "vline_width_column";
+    params->vline_width_column->guisection = _("Vector lines");
+
     /* line color */
     params->vline_color = G_define_standard_option(G_OPT_C_FG);
     params->vline_color->multiple = YES;
@@ -329,6 +344,13 @@
     params->vline_color->answer = "blue";
     params->vline_color->guisection = _("Vector lines");
 
+    params->vline_color_column = G_define_standard_option(G_OPT_DB_COLUMN);
+    params->vline_color_column->multiple = YES;
+    params->vline_color_column->required = NO;
+    params->vline_color_column->label = _("Name of color definition column");
+    params->vline_color_column->key = "vline_color_column";
+    params->vline_color_column->guisection = _("Vector lines");
+
     /* line mode */
     params->vline_mode = G_define_option();
     params->vline_mode->key = "vline_mode";

Modified: grass/trunk/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass/trunk/visualization/nviz2/cmd/local_proto.h	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/visualization/nviz2/cmd/local_proto.h	2011-08-07 12:41:44 UTC (rev 47474)
@@ -17,6 +17,7 @@
 	*mode, *res_fine, *res_coarse, *style, *shade, *wire_color, *surface_pos,
     /* vector lines */
 	*vlines, *vline_width, *vline_color, *vline_mode, *vline_height, *vline_pos,
+	*vline_layer, *vline_color_column, *vline_width_column,
     /* vector points */
 	*vpoints, *vpoint_size, *vpoint_marker, *vpoint_color, *vpoint_width, *vpoint_pos,
 	*vpoint_layer, *vpoint_size_column, *vpoint_marker_column, *vpoint_color_column, *vpoint_width_column,

Modified: grass/trunk/visualization/nviz2/cmd/vector.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/vector.c	2011-08-07 09:55:31 UTC (rev 47473)
+++ grass/trunk/visualization/nviz2/cmd/vector.c	2011-08-07 12:41:44 UTC (rev 47474)
@@ -112,22 +112,36 @@
 */
 int vlines_set_attrb(const struct GParams *params)
 {
-    int i, color, width, flat, height;
+    int i, layer, color, width, flat, height;
     int *vect_list, nvects;
+    char *color_column, *width_column;
 
     vect_list = GV_get_vect_list(&nvects);
 
     for (i = 0; i < nvects; i++) {
-	/* mode -- use memory by default */
+	layer = check_thematic(params, TRUE);
+	
 	color = Nviz_color_from_str(params->vline_color->answers[i]);
+	color_column = params->vline_color_column->answers ?
+	    params->vline_color_column->answers[i] : NULL;
 	width = atoi(params->vline_width->answers[i]);
+	width_column = params->vline_width_column->answers ?
+	    params->vline_width_column->answers[i] : NULL;
+	
 	if (strcmp(params->vline_mode->answers[i], "flat") == 0)
 	    flat = 1;
 	else
 	    flat = 0;
-	if (GV_set_vectmode(vect_list[i], 1, color, width, flat) < 0)
+	
+	/* style (mode -- use memory by default) */
+	if (GV_set_style(vect_list[i], TRUE, color, width, flat) < 0)
 	    return 0;
 
+	if (color_column || width_column)
+	    if (GV_set_style_thematic(vect_list[i], layer, color_column,
+				      width_column) < 0)
+		return 0;
+
 	/* height */
 	height = atoi(params->vline_height->answers[i]);
 	if (height > 0)
@@ -171,10 +185,13 @@
 	    params->vpoint_marker_column->answers[i] : NULL;
 	marker = GP_str_to_marker(marker_str);
 	
-	GP_set_style(site_list[i], color, width, size, marker);
+	if (GP_set_style(site_list[i], color, width, size, marker) < 0)
+	    return 0;
+	
 	if (color_column || width_column || size_column || marker_column) {
-	    GP_set_style_thematic(site_list[i], layer, color_column, width_column,
-				  size_column, marker_column);
+	    if (GP_set_style_thematic(site_list[i], layer, color_column, width_column,
+				      size_column, marker_column) < 0)
+		return 0;
 	}
     }
 
@@ -192,11 +209,11 @@
     dbColumn *column;
     
     if (vlines) {
-	map    = params->vlines; /*TODO */
-	layer  = NULL;
-	color  = NULL;
+	map    = params->vlines;
+	layer  = params->vline_layer;
+	color  = params->vline_color_column;
 	size   = NULL;
-	width  = NULL;
+	width  = params->vline_width_column;
 	marker = NULL;
     }
     else {
@@ -229,7 +246,7 @@
 	    if (db_column_Ctype(driver, Fi->table, color->answers[i]) != DB_C_TYPE_STRING)
 		G_fatal_error(_("Data type of color column must be character"));
 	}
-	if (size->answers && size->answers[i]) {
+	if (size && size->answers && size->answers[i]) {
 	    db_get_column(driver, Fi->table, size->answers[i], &column);
 	    if (!column)
 		G_fatal_error(_("Column <%s> in table <%s> not found"),
@@ -249,7 +266,7 @@
 	    if (type != DB_C_TYPE_INT && type != DB_C_TYPE_DOUBLE)
 		G_fatal_error(_("Data type of width column must be numeric"));
 	}
-	if (marker->answers && marker->answers[i]) {
+	if (marker && marker->answers && marker->answers[i]) {
 	    db_get_column(driver, Fi->table, marker->answers[i], &column);
 	    if (!column)
 		G_fatal_error(_("Column <%s> in table <%s> not found"),



More information about the grass-commit mailing list