[GRASS-SVN] r46782 - in grass/trunk: include lib/ogsf visualization/nviz2/cmd

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 26 04:19:32 EDT 2011


Author: martinl
Date: 2011-06-26 01:19:32 -0700 (Sun, 26 Jun 2011)
New Revision: 46782

Modified:
   grass/trunk/include/gsurf.h
   grass/trunk/include/ogsf_proto.h
   grass/trunk/lib/ogsf/GP2.c
   grass/trunk/lib/ogsf/Gp3.c
   grass/trunk/lib/ogsf/gp.c
   grass/trunk/lib/ogsf/gpd.c
   grass/trunk/visualization/nviz2/cmd/args.c
   grass/trunk/visualization/nviz2/cmd/vector.c
Log:
wxNviz: OGSF: thematic points mapping (size, width, marker)
	nviz_cmd updated


Modified: grass/trunk/include/gsurf.h
===================================================================
--- grass/trunk/include/gsurf.h	2011-06-26 08:07:39 UTC (rev 46781)
+++ grass/trunk/include/gsurf.h	2011-06-26 08:19:32 UTC (rev 46782)
@@ -1,17 +1,13 @@
 /*!
-   \file gsurf.h
+   \file include/gsurf.h
 
    \brief OGSF library - main header
 
-   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 (January 1993)
  */
 

Modified: grass/trunk/include/ogsf_proto.h
===================================================================
--- grass/trunk/include/ogsf_proto.h	2011-06-26 08:07:39 UTC (rev 46781)
+++ grass/trunk/include/ogsf_proto.h	2011-06-26 08:19:32 UTC (rev 46782)
@@ -77,6 +77,7 @@
 void GP_alldraw_site(void);
 int GP_Set_ClientData(int, void *);
 void *GP_Get_ClientData(int);
+int GP_str_to_marker(const char *);
 
 /* GS2.c */
 void void_func(void);

Modified: grass/trunk/lib/ogsf/GP2.c
===================================================================
--- grass/trunk/lib/ogsf/GP2.c	2011-06-26 08:07:39 UTC (rev 46781)
+++ grass/trunk/lib/ogsf/GP2.c	2011-06-26 08:19:32 UTC (rev 46782)
@@ -1,5 +1,5 @@
 /*!
-   \file GP2.c
+   \file lib/ogsf/GP2.c
 
    \brief OGSF library - loading and manipulating point sets (higher level functions)
 
@@ -9,7 +9,8 @@
    (>=v2). Read the file COPYING that comes with GRASS for details.
 
    \author Bill Brown USACERL (January 1994)
-   \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 June 2011)
  */
 
 #include <stdlib.h>
@@ -17,6 +18,7 @@
 
 #include <grass/gis.h>
 #include <grass/gstypes.h>
+#include <grass/glocale.h>
 
 #include "gsget.h"
 
@@ -198,7 +200,7 @@
    Note: char array is allocated by G_store()
 
    \param id point set id
-   \param[out] &filename point set filename
+   \param[out] filename point set filename
 
    \return -1 on error (point set not found)
    \return 1 on success
@@ -223,6 +225,7 @@
 
    \param id point set id
 
+   \return 1 on success
    \return -1 on error (point set not found)
  */
 int GP_get_style(int id, int *color, int *width, float *size, int *symbol)
@@ -246,6 +249,18 @@
 /*!
    \brief Set point set style
 
+   Supported icon symbols (markers):
+    - ST_X
+    - ST_BOX
+    - ST_SPHERE
+    - ST_CUBE
+    - ST_DIAMOND
+    - ST_DEC_TREE
+    - ST_CON_TREE
+    - ST_ASTER
+    - ST_GYRO
+    - ST_HISTOGRAM
+
    \param id point set id
    \param color icon color
    \param width icon line width
@@ -302,12 +317,17 @@
 
     if(!gp->tstyle)
 	gp->tstyle = (gvstyle_thematic *)G_malloc(sizeof(gvstyle_thematic));
+    G_zero(gp->tstyle, sizeof(gvstyle_thematic));
     
     gp->tstyle->layer = layer;
-    gp->tstyle->color_column = G_store(color);
-    gp->tstyle->symbol_column = G_store(symbol);
-    gp->tstyle->size_column = G_store(size);
-    gp->tstyle->width_column = G_store(width);
+    if (color)
+	gp->tstyle->color_column = G_store(color);
+    if (symbol)
+	gp->tstyle->symbol_column = G_store(symbol);
+    if (size)
+	gp->tstyle->size_column = G_store(size);
+    if (width)
+	gp->tstyle->width_column = G_store(width);
 
     Gp_load_sites_thematic(gp);
 
@@ -351,13 +371,14 @@
 /*!
    \brief Get z-mode
 
+   \todo Who's using this?
+   
    \param id point set id
-   \param[out] use_z use z
+   \param[out] use_z non-zero code to use z
 
    \return -1 on error (invalid point set id)
    \return 1 on success
  */
-/* Who's using this? */
 int GP_get_zmode(int id, int *use_z)
 {
     geosite *gp;
@@ -373,10 +394,10 @@
 }
 
 /*!
-   \brief Set trans ?
+   \brief Set transformation params
 
    \param id point set id
-   \param xtrans,ytrans,ztrans x/y/z trans values
+   \param xtrans,ytrans,ztrans x/y/z values
  */
 void GP_set_trans(int id, float xtrans, float ytrans, float ztrans)
 {
@@ -396,10 +417,10 @@
 }
 
 /*!
-   \brief Get trans
+   \brief Get transformation params
 
    \param id point set id
-   \param xtrans,ytrans,ztrans x/y/z trans values
+   \param[out] xtrans,ytrans,ztrans x/y/z values
  */
 void GP_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
 {
@@ -420,7 +441,7 @@
 }
 
 /*!
-   \brief Select surface
+   \brief Select surface for given point set
 
    \param hp point set id
    \param hs surface id
@@ -435,7 +456,7 @@
     G_debug(3, "GP_select_surf(%d,%d)", hp, hs);
 
     if (GP_surf_is_selected(hp, hs)) {
-	return (1);
+	return 1;
     }
 
     gp = gp_get_site(hp);
@@ -608,3 +629,54 @@
 
     return NULL;
 }
+
+/*!
+  \brief Determine point marker symbol for string
+
+  Supported markers:
+    - ST_X
+    - ST_BOX
+    - ST_SPHERE
+    - ST_CUBE
+    - ST_DIAMOND
+    - ST_DEC_TREE
+    - ST_CON_TREE
+    - ST_ASTER
+    - ST_GYRO
+    - ST_HISTOGRAM
+
+  \param str string buffer
+
+  \return marker code (default: ST_SPHERE)
+*/
+int GP_str_to_marker(const char *str)
+{
+    int marker;
+
+    if (strcmp(str, "x") == 0)
+	marker = ST_X;
+    else if (strcmp(str, "box") == 0)
+	marker = ST_BOX;
+    else if (strcmp(str, "sphere") == 0)
+	marker = ST_SPHERE;
+    else if (strcmp(str, "cube") == 0)
+	marker = ST_CUBE;
+    else if (strcmp(str, "diamond") == 0)
+	marker = ST_DIAMOND;
+    else if (strcmp(str, "dec_tree") == 0)
+	marker = ST_DEC_TREE;
+    else if (strcmp(str, "con_tree") == 0)
+	marker = ST_CON_TREE;
+    else if (strcmp(str, "aster") == 0)
+	marker = ST_ASTER;
+    else if (strcmp(str, "gyro") == 0)
+	marker = ST_GYRO;
+    else if (strcmp(str, "histogram") == 0)
+	marker = ST_HISTOGRAM;
+    else {
+	G_warning(_("Unknown icon marker, using \"sphere\""));
+	marker = ST_SPHERE;
+    }
+
+    return marker;
+}

Modified: grass/trunk/lib/ogsf/Gp3.c
===================================================================
--- grass/trunk/lib/ogsf/Gp3.c	2011-06-26 08:07:39 UTC (rev 46781)
+++ grass/trunk/lib/ogsf/Gp3.c	2011-06-26 08:19:32 UTC (rev 46782)
@@ -1,19 +1,18 @@
 /*!
-   \file Gp3.c
+   \file lib/ogsf/Gp3.c
 
    \brief OGSF library - loading point 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, GMSL/University of Illinois (January 1994)
-   \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 June 2011)
  */
 
 #include <stdlib.h>
@@ -90,7 +89,7 @@
 	    {
 		G_warning(_("Unable to read vector map <%s>"),
 			  G_fully_qualified_name(name, mapset));
-		return (NULL);
+		return NULL;
 	    }
 	case -2:		/* EOF */
 	    {
@@ -205,13 +204,13 @@
 	G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
 		      Fi->database, Fi->driver);
     
-    gpt = gp->points;
-    npts = 0;
     G_message(_("Loading thematic points layer <%s>..."),
 	      G_fully_qualified_name(gp->filename, mapset));
-    for(;gpt; gpt = gpt->next) {
+    npts = 0;
+    for(gpt = gp->points; gpt; gpt = gpt->next) {
 	gpt->style = (gvstyle *) G_malloc(sizeof(gvstyle));
 	G_zero(gpt->style, sizeof(gvstyle));
+	
 	/* use default style */
 	gpt->style->color  = gp->style->color;
 	gpt->style->symbol = gp->style->symbol;
@@ -223,20 +222,47 @@
 	    continue;
 
 	/* color */
-	nvals = db_select_value(driver, Fi->table, Fi->key, cat, gp->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);
-	    gpt->style->color = gp->style->color;
+	if (gp->tstyle->color_column) {
+	    nvals = db_select_value(driver, Fi->table, Fi->key, cat, gp->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);
+		gpt->style->color = gp->style->color;
+	    }
+	    else {
+		gpt->style->color = (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) +
+		    ((int)((blu) << 16) & BLU_MASK);
+	    }
 	}
-	else {
-	    gpt->style->color = (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) +
-		((int)((blu) << 16) & BLU_MASK);
+
+	/* size */
+	if (gp->tstyle->size_column) {
+	    nvals = db_select_value(driver, Fi->table, Fi->key, cat, gp->tstyle->size_column, &value);
+	    if (nvals < 1)
+		continue;
+	    gpt->style->size = db_get_value_int(&value);
 	}
 
+	/* width */
+	if (gp->tstyle->width_column) {
+	    nvals = db_select_value(driver, Fi->table, Fi->key, cat, gp->tstyle->width_column, &value);
+	    if (nvals < 1)
+		continue;
+	    gpt->style->width = db_get_value_int(&value);
+	}
+
+	/* symbol/marker */
+	if (gp->tstyle->symbol_column) {
+	    nvals = db_select_value(driver, Fi->table, Fi->key, cat, gp->tstyle->symbol_column, &value);
+	    if (nvals < 1)
+		continue;
+	    str = db_get_value_string(&value);
+	    gpt->style->symbol = GP_str_to_marker(str);
+	}
+	
 	npts++;
     }
     

Modified: grass/trunk/lib/ogsf/gp.c
===================================================================
--- grass/trunk/lib/ogsf/gp.c	2011-06-26 08:07:39 UTC (rev 46781)
+++ grass/trunk/lib/ogsf/gp.c	2011-06-26 08:19:32 UTC (rev 46782)
@@ -1,17 +1,13 @@
 /*!
-   \file gp.c
+   \file lib/ogsf/gp.c
 
-   \brief OGSF library - loading and manipulating point sets
+   \brief OGSF library - loading and manipulating point 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, GMSL/University of Illinois (January 1994)
    \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
  */
@@ -41,11 +37,11 @@
 
     for (gp = Site_top; gp; gp = gp->next) {
 	if (gp->gsite_id == id) {
-	    return (gp);
+	    return gp;
 	}
     }
 
-    return (NULL);
+    return NULL;
 }
 
 /*!
@@ -68,7 +64,7 @@
 	}
     }
 
-    return (NULL);
+    return NULL;
 }
 
 /*!
@@ -85,7 +81,7 @@
 
     G_debug(5, "gp_num_sites(): n=%d", i);
 
-    return (i);
+    return i;
 }
 
 /*!
@@ -101,14 +97,14 @@
     G_debug(5, "gp_get_last_site");
 
     if (!Site_top) {
-	return (NULL);
+	return NULL;
     }
 
     for (lp = Site_top; lp->next; lp = lp->next) ;
 
     G_debug(5, " last site id: %d", lp->gsite_id);
 
-    return (lp);
+    return lp;
 }
 
 /*!
@@ -125,7 +121,7 @@
 
     np = (geosite *) G_malloc(sizeof(geosite));	/* G_fatal_error */
     if (!np) {
-	return (NULL);
+	return NULL;
     }
     G_zero(np, sizeof(geosite));
     
@@ -147,7 +143,7 @@
 	return NULL;
     G_zero(np->hstyle, sizeof (gvstyle));
 
-    return (np);
+    return np;
 }
 
 /*!
@@ -212,6 +208,8 @@
 /*!
    \brief Initialize geosite struct
 
+   \todo Currently does nothing
+
    \param gp pointer to geosite struct
 
    \return -1 on failure
@@ -222,10 +220,10 @@
     G_debug(5, "gp_init_site");
 
     if (!gp) {
-	return (-1);
+	return -1;
     }
 
-    return (0);
+    return 0;
 }
 
 /*!
@@ -297,11 +295,11 @@
 	return (1);
     }
 
-    return (-1);
+    return -1;
 }
 
 /*!
-   \brief Free geosite
+   \brief Free geosite (lower level)
 
    \param fp pointer to geosite struct
  */

Modified: grass/trunk/lib/ogsf/gpd.c
===================================================================
--- grass/trunk/lib/ogsf/gpd.c	2011-06-26 08:07:39 UTC (rev 46781)
+++ grass/trunk/lib/ogsf/gpd.c	2011-06-26 08:19:32 UTC (rev 46782)
@@ -332,7 +332,7 @@
     GLint window[4];
 
     if (GS_check_cancel()) {
-	return (0);
+	return 0;
     }
 
     gsd_getwindow(window, viewport, modelMatrix, projMatrix);

Modified: grass/trunk/visualization/nviz2/cmd/args.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/args.c	2011-06-26 08:07:39 UTC (rev 46781)
+++ grass/trunk/visualization/nviz2/cmd/args.c	2011-06-26 08:19:32 UTC (rev 46782)
@@ -439,7 +439,7 @@
     params->vpoint_marker->multiple = YES;
     params->vpoint_marker->description = _("Icon marker");
     params->vpoint_marker->options =
-	"x,sphere,diamond,cube,box,gyro,aster,histogram";
+	"x,box,sphere,cube,diamond,dec_tree,con_tree,aster,gyro,histogram";
     params->vpoint_marker->answer = "sphere";
     params->vpoint_marker->guisection = _("Vector points");
 

Modified: grass/trunk/visualization/nviz2/cmd/vector.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/vector.c	2011-06-26 08:07:39 UTC (rev 46781)
+++ grass/trunk/visualization/nviz2/cmd/vector.c	2011-06-26 08:19:32 UTC (rev 46782)
@@ -169,26 +169,8 @@
 	marker_str = params->vpoint_marker->answers[i];
 	marker_column = params->vpoint_marker_column->answers ?
 	    params->vpoint_marker_column->answers[i] : NULL;
-
-	if (strcmp(marker_str, "x") == 0)
-	    marker = ST_X;
-	else if (strcmp(marker_str, "sphere") == 0)
-	    marker = ST_SPHERE;
-	else if (strcmp(marker_str, "diamond") == 0)
-	    marker = ST_DIAMOND;
-	else if (strcmp(marker_str, "cube") == 0)
-	    marker = ST_CUBE;
-	else if (strcmp(marker_str, "box") == 0)
-	    marker = ST_BOX;
-	else if (strcmp(marker_str, "gyro") == 0)
-	    marker = ST_GYRO;
-	else if (strcmp(marker_str, "aster") == 0)
-	    marker = ST_ASTER;
-	else if (strcmp(marker_str, "histogram") == 0)
-	    marker = ST_HISTOGRAM;
-	else
-	    G_fatal_error(_("Unknown icon marker"));
-
+	marker = GP_str_to_marker(marker_str);
+	
 	GP_set_style(site_list[i], color, width, size, marker);
 	if (color_column || width_column || size_column || marker_column) {
 	    GP_set_style_thematic(site_list[i], layer, color_column, width_column,
@@ -273,7 +255,7 @@
 		G_fatal_error(_("Column <%s> in table <%s> not found"),
 			      marker->answers[i], Fi->table);
 	  
-	  type = db_column_Ctype(driver, Fi->table, width->answers[i]);
+	  type = db_column_Ctype(driver, Fi->table, marker->answers[i]);
 	    if (db_column_Ctype(driver, Fi->table, marker->answers[i]) != DB_C_TYPE_STRING)
 		G_fatal_error(_("Data type of marker column must be character"));
 	}



More information about the grass-commit mailing list