[GRASS-SVN] r47526 - grass/trunk/display/d.vect

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Aug 10 06:13:18 EDT 2011


Author: martinl
Date: 2011-08-10 03:13:18 -0700 (Wed, 10 Aug 2011)
New Revision: 47526

Modified:
   grass/trunk/display/d.vect/area.c
   grass/trunk/display/d.vect/lines.c
   grass/trunk/display/d.vect/local_proto.h
   grass/trunk/display/d.vect/main.c
   grass/trunk/display/d.vect/shape.c
Log:
d.vect: add initial support for color tables
	minor code clean up


Modified: grass/trunk/display/d.vect/area.c
===================================================================
--- grass/trunk/display/d.vect/area.c	2011-08-10 10:12:18 UTC (rev 47525)
+++ grass/trunk/display/d.vect/area.c	2011-08-10 10:13:18 UTC (rev 47526)
@@ -14,11 +14,12 @@
 #include "local_proto.h"
 
 int display_area(struct Map_info *Map, struct cat_list *Clist, const struct Cell_head *window,
-		 const struct color_rgb *bcolor, const struct color_rgb *fcolor, int chcat, int id_flag, 
-		 int table_colors_flag, int cats_color_flag, const char *rgb_column,
-		 int default_width, const char *width_column, double width_scale,
-		 int z_color_flag, const char *z_style,
-		 dbCatValArray *cvarr_rgb, dbCatValArray *cvarr_width, int nrec_width)
+		 const struct color_rgb *bcolor, const struct color_rgb *fcolor, int chcat,
+		 int id_flag, int table_colors_flag, int cats_color_flag, 
+		 int default_width, double width_scale,
+		 struct Colors *zcolors,
+		 dbCatValArray *cvarr_rgb, struct Colors *colors,
+		 dbCatValArray *cvarr_width, int nrec_width)
 {
     int num, area, isle, n_isles, n_points;
     double xl, yl;
@@ -28,25 +29,21 @@
     int cat, centroid;
     int red, grn, blu;
 
-    dbCatVal *cv_rgb, *cv_width;
-
-    int i, rgb;	     
-    char colorstring[12];	/* RRR:GGG:BBB */
-    unsigned char which;
+    int i, custom_rgb, found, nerror_rgb;
     int width;
-
-    centroid = 0;
-    cv_rgb = cv_width = NULL;
-    rgb = 0;
-
+    struct bound_box box;
+    
     if (Vect_level(Map) < 2) {
 	G_warning(_("Unable to display areas, topology not available. "
 		    "Please try to rebuild topology using "
 		    "v.build or v.build.all."));
 	return 1;
     }
-    
+
     G_debug(1, "display areas:");
+    
+    nerror_rgb = 0;
+    centroid = 0;
     Points = Vect_new_line_struct();
     APoints = Vect_new_line_struct();
     n_ipoints_alloc = 10;
@@ -57,14 +54,11 @@
     Cats = Vect_new_cats_struct();
     
     num = Vect_get_num_areas(Map);
-    G_debug(2, "n_areas = %d", num);
+    G_debug(2, "\tn_areas = %d", num);
 
     for (area = 1; area <= num; area++) {
-	int i;
-	struct bound_box box;
+	G_debug(3, "\tarea = %d", area);
 
-	G_debug(3, "area = %d", area);
-
 	if (!Vect_area_alive(Map, area))
 	    continue;
 
@@ -72,7 +66,6 @@
 	Vect_get_area_box(Map, area, &box);
 	if (box.N < window->south || box.S > window->north ||
 	    box.E < window->west || box.W > window->east) {
-
 	    if (window->proj != PROJECTION_LL)
 		continue;
 	    else { /* out of bounds for -180 to 180, try 0 to 360 as well */
@@ -82,17 +75,16 @@
 		    continue;
 	    }
 	}
-
-	/* check category: where_opt or cat_opt used */
+	
+	custom_rgb = FALSE;
+		
+	found = FALSE;
 	if (chcat) {		
 	    if (id_flag) {
 		if (!(Vect_cat_in_cat_list(area, Clist)))
 		    continue;
 	    }
 	    else {
-		int found;
-		
-		found = FALSE;
 		centroid = Vect_get_area_centroid(Map, area);
 		G_debug(3, "centroid = %d", centroid);
 		if (centroid < 1)
@@ -112,20 +104,18 @@
 		
 		if (!found)
 		    continue;
-	    }			/* end else */
-	}			/* end if id_flag */
+	    }
+	}
 	else if (Clist->field > 0) {
-	    int found;
-
 	    found = FALSE;
 	    centroid = Vect_get_area_centroid(Map, area);
-	    G_debug(3, "centroid = %d", centroid);
+	    G_debug(3, "\tcentroid = %d", centroid);
 	    if (centroid < 1)
 		continue;
 	    Vect_read_line(Map, NULL, Cats, centroid);
 
 	    for (i = 0; i < Cats->n_cats; i++) {
-		G_debug(3, "  centroid = %d, field = %d, cat = %d", centroid,
+		G_debug(3, "\tcentroid = %d, field = %d, cat = %d", centroid,
 			Cats->field[i], Cats->cat[i]);
 		if (Cats->field[i] == Clist->field) {
 		    found = TRUE;
@@ -138,11 +128,9 @@
 		continue;
 	}
 
-	G_debug(3, "display area %d", area);
-
 	/* fill */
 	Vect_get_area_points(Map, area, APoints);
-	G_debug(3, "n_points = %d", APoints->n_points);
+	G_debug(3, "\tn_points = %d", APoints->n_points);
 	Vect_reset_line(Points);
 	Vect_append_points(Points, APoints, GV_FORWARD);
 
@@ -173,138 +161,41 @@
 	}
 
 	/* z height colors */
-	if (z_color_flag && Vect_is_3d(Map)) {
-	    struct bound_box box;
-	    double zval;
-	    struct Colors colors;
-
-	    Vect_get_map_box(Map, &box);
-	    zval = Points->z[0];
-	    G_debug(3,
-		    "display area %d, centroid %d, cat %d, x: %f, y: %f, z: %f",
-		    area, centroid, cat, Points->x[0], Points->y[0],
-		    Points->z[0]);
-	    rgb = 1;
-	    Rast_make_fp_colors(&colors, z_style, box.B, box.T);
-	    Rast_get_color(&zval, &red, &grn, &blu, &colors, DCELL_TYPE);
-	    G_debug(3, "b %d, g: %d, r %d", blu, grn, red);
+	if (zcolors) {
+	    if (Rast_get_d_color(&Points->z[0], &red, &grn, &blu, zcolors) == 1)
+		custom_rgb = TRUE;
+	    else
+		custom_rgb = FALSE;
 	}
 
+        /* custom colors */
 	if (table_colors_flag) {
-	    centroid = Vect_get_area_centroid(Map, area);
-	    if (cat >= 0) {
-		G_debug(3, "display area %d, centroid %d, cat %d", area,
-			centroid, cat);
-
-		/* Read RGB colors from db for current area # */
-		if (db_CatValArray_get_value(cvarr_rgb, cat, &cv_rgb) !=
-		    DB_OK) {
-		    rgb = 0;
-		}
-		else {
-		    sprintf(colorstring, "%s", db_get_string(cv_rgb->val.s));
-
-		    if (*colorstring != '\0') {
-
-			G_debug(3, "area %d: colorstring: %s", area,
-				colorstring);
-
-			if (G_str_to_color(colorstring, &red, &grn, &blu) ==
-			    1) {
-			    rgb = 1;
-			    G_debug(3, "area:%d  cat %d r:%d g:%d b:%d", area,
-				    cat, red, grn, blu);
-			}
-			else {
-			    rgb = 0;
-			    G_warning(_("Error in color definition column (%s), area %d "
-				       "with cat %d: colorstring [%s]"),
-				      rgb_column, area, cat, colorstring);
-			}
-		    }
-		    else {
-			G_warning(_("Error in color definition column (%s), area %d with cat %d"),
-				  rgb_column, area, cat);
-			rgb = 0;
-		    }
-		}
-	    }			/* end if cat */
-	    else {
-		rgb = 0;
-	    }
-	}			/* end if table_colors_flag */
-
+	    custom_rgb = get_table_color(cat, area, colors, cvarr_rgb,
+					 &red, &grn, &blu, &nerror_rgb);
+	}
+	
 	/* random colors */
 	if (cats_color_flag) {
-	    rgb = 0;
-	    centroid = Vect_get_area_centroid(Map, area);
-	    if (Clist->field > 0) {
-		if (cat >= 0) {
-		    G_debug(3, "display area %d, centroid %d, cat %d", area,
-			    centroid, cat);
-		    /* fetch color number from category */
-		    which = (cat % palette_ncolors);
-		    G_debug(3, "cat:%d which color:%d r:%d g:%d b:%d", cat,
-			    which, palette[which].R, palette[which].G,
-			    palette[which].B);
-		    rgb = 1;
-		    red = palette[which].R;
-		    grn = palette[which].G;
-		    blu = palette[which].B;
-		}
-	    }
-	    else if (Cats->n_cats > 0) {
-		/* fetch color number from layer */
-		which = (Cats->field[0] % palette_ncolors);
-		G_debug(3, "layer:%d which color:%d r:%d g:%d b:%d",
-			Cats->field[0], which, palette[which].R,
-			palette[which].G, palette[which].B);
-
-		rgb = 1;
-		red = palette[which].R;
-		grn = palette[which].G;
-		blu = palette[which].B;
-	    }
+	    custom_rgb = get_cat_color(area, Cats, Clist,
+				       &red, &grn, &blu);
 	}
-
+	
+	/* line width */
 	if (nrec_width) {
-	    centroid = Vect_get_area_centroid(Map, area);
-	    if (cat >= 0) {
-		G_debug(3, "display area %d, centroid %d, cat %d", area,
-			centroid, cat);
-
-		/* Read line width from db for current area # */
-		if (db_CatValArray_get_value(cvarr_width, cat, &cv_width) !=
-		    DB_OK) {
-		    width = default_width;
-		}
-		else {
-		    width =
-			width_scale * (cvarr_width->ctype ==
-				       DB_C_TYPE_INT ? cv_width->val.
-				       i : (int)cv_width->val.d);
-		    if (width < 0) {
-			G_warning(_("Error in line width column (%s), element %d "
-				   "with cat %d: line width [%d]"),
-				  width_column, area, cat, width);
-			width = default_width;
-		    }
-		}
-	    }			/* end if cat */
-	    else {
-		width = default_width;
-	    }
-
+	    width = (int) get_property(cat, area, cvarr_width,
+				       (double) width_scale,
+				       (double) default_width);
+	    
 	    D_line_width(width);
-	}			/* end if nrec_width */
-
-	if (fcolor || (z_color_flag && Vect_is_3d(Map))) {
-	    if (!table_colors_flag && !cats_color_flag && !z_color_flag) {
+	}
+	
+	if (fcolor || zcolors) {
+	    if (!table_colors_flag && !cats_color_flag && !zcolors) {
 		D_RGB_color(fcolor->r, fcolor->g, fcolor->b);
 		D_polygon_abs(Points->x, Points->y, Points->n_points);
 	    }
 	    else {
-		if (rgb) {
+		if (custom_rgb) {
 		    D_RGB_color((unsigned char)red, (unsigned char)grn,
 				(unsigned char)blu);
 		}
@@ -319,23 +210,21 @@
 
 	/* boundary */
 	if (bcolor) {
-	    int i;
-
-	    if (rgb) {
+	    if (custom_rgb) {
 		D_RGB_color((unsigned char)red, (unsigned char)grn,
 			    (unsigned char)blu);
 	    }
 	    else {
 		D_RGB_color(bcolor->r, bcolor->g, bcolor->b);
 	    }
-	    /*use different user defined render methods */
+	    /* use different user defined render methods */
 	    D_polyline_abs(APoints->x, APoints->y, APoints->n_points);
 	    for (i = 0; i < n_isles; i++) {
-		/*use different user defined render methods */
+		/* use different user defined render methods */
 		D_polyline_abs(IPoints[i]->x, IPoints[i]->y, IPoints[i]->n_points);
 	    }
 	}
-    }				/* end for */
+    }
 
     Vect_destroy_line_struct(Points);
     Vect_destroy_line_struct(APoints);

Modified: grass/trunk/display/d.vect/lines.c
===================================================================
--- grass/trunk/display/d.vect/lines.c	2011-08-10 10:12:18 UTC (rev 47525)
+++ grass/trunk/display/d.vect/lines.c	2011-08-10 10:13:18 UTC (rev 47526)
@@ -38,39 +38,33 @@
 
 int display_lines(struct Map_info *Map, int type, struct cat_list *Clist,
 		  const struct color_rgb *color, const struct color_rgb *fcolor, int chcat,
-		  const char *symbol_name,  double size, const char *size_column, int sqrt_flag, const char *rot_column,
-		  int id_flag, int table_colors_flag, int cats_color_flag, const char *rgb_column,
-		  int default_width, const char *width_column, double width_scale,
-		  int z_color_flag, const char *z_style,
-		  dbCatValArray *cvarr_rgb, dbCatValArray *cvarr_width, int nrec_width,
+		  const char *symbol_name, double size, int sqrt_flag,
+		  int id_flag, int table_colors_flag, int cats_color_flag, 
+		  int default_width, double width_scale,
+		  struct Colors* zcolors,
+		  dbCatValArray *cvarr_rgb, struct Colors *colors,
+		  dbCatValArray *cvarr_width, int nrec_width,
 		  dbCatValArray *cvarr_size, int nrec_size,
 		  dbCatValArray *cvarr_rot, int nrec_rot)
 
 {
-    int i, ltype, nlines, line, cat;
+    int i, ltype, nlines, line, cat, found;
     double *x, *y;
     struct line_pnts *Points;
     struct line_cats *Cats;
     double x0, y0;
 
-    dbCatVal *cv_rgb, *cv_width, *cv_size, *cv_rot;
     int nerror_rgb;
     int n_points, n_lines, n_centroids, n_boundaries, n_faces;
     
     int custom_rgb;
-    char colorstring[12];	/* RRR:GGG:BBB */
     int red, grn, blu;
     RGBA_Color *line_color, *fill_color, *primary_color;
-    unsigned char which;
     int width;
     SYMBOL *Symb;
     double var_size, rotation;
-    struct bound_box box;
-    struct Colors colors;
     
     Symb = NULL;
-    custom_rgb = FALSE;
-    cv_rgb = cv_width = cv_size = cv_rot = NULL;
     cat = -1;
     nlines = 0;
     
@@ -79,18 +73,7 @@
 		    "Please try to rebuild topology using "
 		    "v.build or v.build.all."));
     }
-
-    if (z_color_flag) {
-	if (!Vect_is_3d(Map)) {
-	    G_warning(_("Vector map is not 3D. Unable to colorize features based on z-coordinates."));
-	    z_color_flag = 0;
-	}
-	else {
-	    Vect_get_map_box(Map, &box);
-	    Rast_make_fp_colors(&colors, z_style, box.B, box.T);
-	}
-    }
-    
+  
     var_size = size;
     rotation = 0.0;
     nerror_rgb = 0;
@@ -122,18 +105,18 @@
     Points = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
 
-    if (!(nrec_size || nrec_rot) ) {
+    /* dynamic symbols for points */
+    if (!(nrec_size || nrec_rot)) {
 	Symb = S_read(symbol_name);
 	if (!Symb)
-	    G_warning(_("Unable to read symbol, unable to display points"));
+	    G_warning(_("Unable to read symbol <%s>, unable to display points"),
+		      symbol_name);
 	else
 	    S_stroke(Symb, size, 0.0, 0);
     }
     
     Vect_rewind(Map);
 
-    /* Is it necessary to reset line/label color in each loop ? */
-
     if (color && !table_colors_flag && !cats_color_flag)
 	D_RGB_color(color->r, color->g, color->b);
 
@@ -144,8 +127,10 @@
     n_points = n_lines = 0;
     n_centroids = n_boundaries = 0;
     n_faces = 0;
-    while (1) {
+    while (TRUE) {
 	line++;
+	custom_rgb = FALSE;
+	
 	if (Vect_level(Map) >= 2) {
 	    if (line > nlines)
 		break;
@@ -168,10 +153,9 @@
 
 	if (Points->n_points == 0)
 	    continue;
-
+	
+	found = FALSE;
 	if (chcat) {
-	    int found = 0;
-
 	    if (id_flag) {	/* use line id */
 		if (!(Vect_cat_in_cat_list(line, Clist)))
 		    continue;
@@ -180,7 +164,7 @@
 		for (i = 0; i < Cats->n_cats; i++) {
 		    if (Cats->field[i] == Clist->field &&
 			Vect_cat_in_cat_list(Cats->cat[i], Clist)) {
-			found = 1;
+			found = TRUE;
 			break;
 		    }
 		}
@@ -189,11 +173,9 @@
 	    }
 	}
 	else if (Clist->field > 0) {
-	    int found = 0;
-
 	    for (i = 0; i < Cats->n_cats; i++) {
 		if (Cats->field[i] == Clist->field) {
-		    found = 1;
+		    found = TRUE;
 		    break;
 		}
 	    }
@@ -202,134 +184,43 @@
 		continue;
 	}
 
+	G_debug(3, "\tdisplay feature %d, cat %d", line, cat);
+	
 	/* z height colors */
-	if (z_color_flag) {
-	    custom_rgb = TRUE;
-	    Rast_get_color(&Points->z[0], &red, &grn, &blu, &colors, DCELL_TYPE);
-	    G_debug(3, "\tb: %d, g: %d, r: %d", blu, grn, red);
+	if (zcolors) {
+	    if (Rast_get_d_color(&Points->z[0], &red, &grn, &blu, zcolors) == 1)
+		custom_rgb = TRUE;
+	    else
+		custom_rgb = FALSE;
 	}
-	
-	if (table_colors_flag) {
+
+	if (table_colors_flag || nrec_width > 0 || nrec_size > 0 || nrec_rot > 0)
 	    /* only first category */
 	    Vect_cat_get(Cats, 
-			 (Clist->field > 0 ? Clist->field :
-			  (Cats->n_cats >
-			   0 ? Cats->field[0] : 1)), &cat);
-
-	    if (cat >= 0) {
-		G_debug(3, "display element %d, cat %d", line, cat);
-
-		/* Read RGB colors from db for current area # */
-		if (db_CatValArray_get_value(cvarr_rgb, cat, &cv_rgb) !=
-		    DB_OK) {
-		    custom_rgb = FALSE;
-		}
-		else {
-		    sprintf(colorstring, "%s", db_get_string(cv_rgb->val.s));
-
-		    if (*colorstring != '\0') {
-			G_debug(3, "element %d: colorstring: %s", line,
-				colorstring);
-
-			if (G_str_to_color(colorstring, &red, &grn, &blu) ==
-			    1) {
-			    custom_rgb = TRUE;
-			    G_debug(3, "element:%d  cat %d r:%d g:%d b:%d",
-				    line, cat, red, grn, blu);
-			}
-			else {
-			    custom_rgb = FALSE;
-			    G_important_message(_("Error in color definition column '%s', feature id %d "
-						  "with cat %d: colorstring '%s'"),
-						rgb_column, line, cat, colorstring);
-			    nerror_rgb++;
-			}
-		    }
-		    else {
-			custom_rgb = FALSE;
-			G_important_message(_("Error in color definition column '%s', feature id %d "
-					      "with cat %d"),
-					    rgb_column, line, cat);
-			nerror_rgb++;
-		    }
-		}
-	    }			/* end if cat */
-	    else {
-		custom_rgb = FALSE;
-	    }
-	}			/* end if table_colors_flag */
-
-
+			 (Clist->field > 0 ? Clist->field : (Cats->n_cats > 0 ? Cats->field[0] : 1)),
+			 &cat);
+	
+	/* custom colors */
+	if (table_colors_flag) {
+	    custom_rgb = get_table_color(cat, line, colors, cvarr_rgb,
+					 &red, &grn, &blu, &nerror_rgb);
+	}
+	
 	/* random colors */
 	if (cats_color_flag) {
-	    custom_rgb = FALSE;
-	    if (Clist->field > 0) {
-		Vect_cat_get(Cats, Clist->field, &cat);
-		if (cat >= 0) {
-		    G_debug(3, "display element %d, cat %d", line, cat);
-		    /* fetch color number from category */
-		    which = (cat % palette_ncolors);
-		    G_debug(3, "cat:%d which color:%d r:%d g:%d b:%d", cat,
-			    which, palette[which].R, palette[which].G,
-			    palette[which].B);
-
-		    custom_rgb = TRUE;
-		    red = palette[which].R;
-		    grn = palette[which].G;
-		    blu = palette[which].B;
-		}
-	    }
-	    else if (Cats->n_cats > 0) {
-		/* fetch color number from layer */
-		which = (Cats->field[0] % palette_ncolors);
-		G_debug(3, "layer:%d which color:%d r:%d g:%d b:%d",
-			Cats->field[0], which, palette[which].R,
-			palette[which].G, palette[which].B);
-
-		custom_rgb = TRUE;
-		red = palette[which].R;
-		grn = palette[which].G;
-		blu = palette[which].B;
-	    }
+	    custom_rgb = get_cat_color(line, Cats, Clist,
+				       &red, &grn, &blu);
 	}
 
-
+	/* line width */
 	if (nrec_width) {
-	    /* only first category */
-	    Vect_cat_get(Cats,
-			 (Clist->field > 0 ? Clist->field :
-			  (Cats->n_cats >
-			   0 ? Cats->field[0] : 1)), &cat);
-
-	    if (cat >= 0) {
-		G_debug(3, "display element %d, cat %d", line, cat);
-
-		/* Read line width from db for current area # */
-		if (db_CatValArray_get_value(cvarr_width, cat, &cv_width) !=
-		    DB_OK) {
-		    width = default_width;
-		}
-		else {
-		    width =
-			width_scale * (cvarr_width->ctype ==
-				       DB_C_TYPE_INT ? cv_width->val.i
-				       : (int)cv_width->val.d);
-		    if (width < 0) {
-			G_warning(_("Error in line width column (%s), element %d "
-				   "with cat %d: line width [%d]"),
-				  width_column, line, cat, width);
-			width = default_width;
-		    }
-		}
-	    }		/* end if cat */
-	    else {
-		width = default_width;
-	    }
-
+	    width = (int) get_property(cat, line, cvarr_width,
+				       (double) width_scale,
+				       (double) default_width);
+	    
 	    D_line_width(width);
-	}		/* end if nrec_width */
+	}
 
-
 	/* enough of the prep work, lets start plotting stuff */
 	x = Points->x;
 	y = Points->y;
@@ -342,77 +233,24 @@
 	    y0 = y[0];
 
 	    /* skip if the point is outside of the display window */
-	    /*      xy<0 tests make it go ever-so-slightly faster */
+	    /* xy < 0 tests make it go ever-so-slightly faster */
 	    if (x0 > D_get_u_east() || x0 < D_get_u_west() ||
 		y0 < D_get_u_south() || y0 > D_get_u_north())
 		continue;
 
 	    /* dynamic symbol size */
-	    if (nrec_size) {
-		/* only first category */
-		Vect_cat_get(Cats,
-			     (Clist->field > 0 ? Clist->field :
-			      (Cats->n_cats > 0 ?
-			       Cats->field[0] : 1)), &cat);
-
-		if (cat >= 0) {
-		    G_debug(3, "display element %d, cat %d", line, cat);
-
-		    /* Read symbol size from db for current symbol # */
-		    if (db_CatValArray_get_value(cvarr_size, cat, &cv_size) !=
-			DB_OK) {
-			var_size = size;
-		    }
-		    else {
-			var_size = size *
-			    (cvarr_size->ctype == DB_C_TYPE_INT ?
-			     (double)cv_size->val.i : cv_size->val.d);
-
-			if (var_size < 0.0) {
-			    G_warning(_("Error in symbol size column (%s), element %d "
-					"with cat %d: symbol size [%f]"),
-				      size_column, line, cat, var_size);
-			    var_size = size;
-			}
-		    }
-		}		/* end if cat */
-		else {
-		    var_size = size;
-		}
-	    }		/* end if nrec_size */
-
+	    if (nrec_size)
+		var_size = get_property(cat, line, cvarr_size, size, size);
+	    
             if (sqrt_flag)
                 var_size = sqrt(var_size);
 
 	    /* dynamic symbol rotation */
-	    if (nrec_rot) {
-		/* only first category */
-		Vect_cat_get(Cats,
-			     (Clist->field > 0 ? Clist->field :
-			      (Cats->n_cats > 0 ?
-			       Cats->field[0] : 1)), &cat);
-
-		if (cat >= 0) {
-		    G_debug(3, "display element %d, cat %d", line, cat);
-
-		    /* Read symbol rotation from db for current symbol # */
-		    if (db_CatValArray_get_value(cvarr_rot, cat, &cv_rot) !=
-			DB_OK) {
-			rotation = 0.0;
-		    }
-		    else {
-			rotation =
-			    (cvarr_rot->ctype == DB_C_TYPE_INT ?
-			     (double)cv_rot->val.i : cv_rot->val.d);
-		    }
-		}		/* end if cat */
-		else {
-		    rotation = 0.0;
-		}
-	    }		/* end if nrec_rot */
-
+	    if (nrec_rot)
+		rotation = get_property(cat, line, cvarr_rot, 1.0, 0.0);
+	    
 	    if(nrec_size || nrec_rot) {
-		G_debug(3, ". dynamic symbol: cat=%d  size=%.2f  rotation=%.2f",
+		G_debug(3, "\tdynamic symbol: cat=%d  size=%.2f  rotation=%.2f",
 			cat, var_size, rotation);
 
 		/* symbol stroking is cumulative, so we need to reread it each time */
@@ -420,11 +258,12 @@
 		    G_free(Symb);
 		Symb = S_read(symbol_name);
 		if (Symb == NULL)
-		    G_warning(_("Unable to read symbol, unable to display points"));
+		    G_warning(_("Unable to read symbol <%s>, unable to display points"),
+			      symbol_name);
 		else
 		    S_stroke(Symb, var_size, rotation, 0);
 	    }
-
+	    
 	    /* use random or RGB column color if given, otherwise reset */
 	    /* centroids always use default color to stand out from underlying area */
 	    if (custom_rgb && (ltype != GV_CENTROID)) {
@@ -440,8 +279,8 @@
 	    var_size = size;
 	    rotation = 0.0;
 	}
-	else if (color || custom_rgb || (z_color_flag && Vect_is_3d(Map))) {
-	    if (!table_colors_flag && !cats_color_flag && !z_color_flag)
+	else if (color || custom_rgb || zcolors) {
+	    if (!table_colors_flag && !cats_color_flag && !zcolors)
 		D_RGB_color(color->r, color->g, color->b);
 	    else {
 		if (custom_rgb)
@@ -454,7 +293,7 @@
 	    /* Plot the lines */
 	    if (Points->n_points == 1)	/* line with one coor */
 		D_polydots_abs(x, y, Points->n_points);
-	    else		/*use different user defined render methods */
+	    else		/* use different user defined render methods */
 		D_polyline_abs(x, y, Points->n_points);
 	}
 	
@@ -479,10 +318,12 @@
 	}
     }
     
+    /*
     if (nerror_rgb > 0) {
 	G_warning(_("Error in color definition column '%s': %d features affected"),
 		  rgb_column, nerror_rgb);
     }
+    */
     
     if (n_points > 0) 
 	G_verbose_message(_("%d points plotted"), n_points);
@@ -501,5 +342,5 @@
     G_free(fill_color);
     G_free(primary_color);
 
-    return 0;			/* not reached */
+    return 0;
 }

Modified: grass/trunk/display/d.vect/local_proto.h
===================================================================
--- grass/trunk/display/d.vect/local_proto.h	2011-08-10 10:12:18 UTC (rev 47525)
+++ grass/trunk/display/d.vect/local_proto.h	2011-08-10 10:13:18 UTC (rev 47526)
@@ -13,10 +13,10 @@
 /* area.c */
 int display_area(struct Map_info *, struct cat_list *, const struct Cell_head *,
 		 const struct color_rgb *, const struct color_rgb *, int, int,
-		 int, int, const char *,
-		 int, const char *, double,
-		 int, const char *,
-		 dbCatValArray *, dbCatValArray *, int);
+		 int, int,
+		 int, double,
+		 struct Colors *,
+		 dbCatValArray *, struct Colors *, dbCatValArray *, int);
 
 /* dir.c */
 int display_dir(struct Map_info *, int, struct cat_list *, int);
@@ -29,11 +29,11 @@
 /* lines.c */
 int display_lines(struct Map_info *, int, struct cat_list *,
 		  const struct color_rgb *, const struct color_rgb *, int,
-		  const char *, double, const char *, int, const char *,
-		  int, int, int, const char *,
-		  int, const char *, double,
-		  int, const char *,
-		  dbCatValArray *, dbCatValArray *, int,
+		  const char *, double, int,
+		  int, int, int, 
+		  int, double,
+		  struct Colors *,
+		  dbCatValArray *, struct Colors *, dbCatValArray *, int,
 		  dbCatValArray *, int, dbCatValArray *, int);
 
 /* shape.c */
@@ -43,6 +43,11 @@
 		  int, int, int, char *,
 		  int, char *, double,
 		  int, char *);
+int get_table_color(int, int, struct Colors *, dbCatValArray *,
+		    int *, int *, int *, int *);
+int get_cat_color(int, const struct line_cats *, const struct cat_list *,
+		  int *, int *, int *);
+double get_property(int, int, dbCatValArray *, double, double);
 
 /* opt.c */
 int option_to_display(const struct Option *);

Modified: grass/trunk/display/d.vect/main.c
===================================================================
--- grass/trunk/display/d.vect/main.c	2011-08-10 10:12:18 UTC (rev 47525)
+++ grass/trunk/display/d.vect/main.c	2011-08-10 10:13:18 UTC (rev 47526)
@@ -3,6 +3,7 @@
  *
  * MODULE:       d.vect
  * AUTHOR(S):    CERL, Radim Blazek, others
+ *               Updated to GRASS7 by Martin Landa <landa.martin gmail.com>
  * PURPOSE:      Display the vector map in map display
  * COPYRIGHT:    (C) 2004-2009, 2011 by the GRASS Development Team
  *
@@ -172,8 +173,7 @@
     rgbcol_opt->key = "rgb_column";
     rgbcol_opt->guisection = _("Colors");
     rgbcol_opt->description = _("Name of color definition column (for use with -a flag)");
-    rgbcol_opt->answer = "GRASSRGB";
-
+    
     zcol_opt = G_define_option();
     zcol_opt->key = "zcolor";
     zcol_opt->key_desc = "style";
@@ -194,15 +194,15 @@
     wcolumn_opt = G_define_standard_option(G_OPT_DB_COLUMN);
     wcolumn_opt->key = "width_column";
     wcolumn_opt->guisection = _("Lines");
-    wcolumn_opt->description =
-	_("Name of column for line widths (these values will be scaled by wscale)");
+    wcolumn_opt->label = _("Name of numeric column containing line width");
+    wcolumn_opt->description = _("These values will be scaled by width_scale");
 
     wscale_opt = G_define_option();
     wscale_opt->key = "width_scale";
     wscale_opt->type = TYPE_DOUBLE;
     wscale_opt->answer = "1";
     wscale_opt->guisection = _("Lines");
-    wscale_opt->description = _("Scale factor for wcolumn");
+    wscale_opt->description = _("Scale factor for width_column");
 
     /* Symbols */
     icon_opt = G_define_option();
@@ -338,7 +338,7 @@
     table_acolors_flag->key = 'a';
     table_acolors_flag->guisection = _("Colors");
     table_acolors_flag->description =
-	_("Get colors from map table column (of form RRR:GGG:BBB)");
+	_("Get colors from color table or attribute column (see 'rgb_column')");
 
     cats_acolors_flag = G_define_flag();
     cats_acolors_flag->key = 'c';
@@ -355,7 +355,7 @@
 
     zcol_flag = G_define_flag();
     zcol_flag->key = 'z';
-    zcol_flag->description = _("Colorize features according to z-coordinate");
+    zcol_flag->description = _("Colorize features according to z-coordinate (only for 3D vector maps)");
     zcol_flag->guisection = _("Colors");
 
     sqrt_flag = G_define_flag();
@@ -480,8 +480,10 @@
 	if (display & DISP_SHAPE) {
 	    stat += display_shape(&Map, type, Clist, &window,
 				  has_color ? &color : NULL, has_fcolor ? &fcolor : NULL, chcat,
-				  icon_opt->answer, size, sizecolumn_opt->answer, sqrt_flag->answer ? 1 : 0, rotcolumn_opt->answer,
-				  id_flag->answer ? 1 : 0, table_acolors_flag->answer ? 1 : 0, cats_acolors_flag->answer ? 1 : 0, rgbcol_opt->answer,
+				  icon_opt->answer, size, sizecolumn_opt->answer,
+				  sqrt_flag->answer ? 1 : 0, rotcolumn_opt->answer,
+				  id_flag->answer ? 1 : 0, table_acolors_flag->answer ? 1 : 0,
+				  cats_acolors_flag->answer ? 1 : 0, rgbcol_opt->answer,
 				  default_width,  wcolumn_opt->answer, width_scale,
 				  zcol_flag->answer ? 1 : 0, zcol_opt->answer);
 	    

Modified: grass/trunk/display/d.vect/shape.c
===================================================================
--- grass/trunk/display/d.vect/shape.c	2011-08-10 10:12:18 UTC (rev 47525)
+++ grass/trunk/display/d.vect/shape.c	2011-08-10 10:13:18 UTC (rev 47526)
@@ -1,5 +1,6 @@
 #include <grass/vector.h>
 #include <grass/dbmi.h>
+#include <grass/raster.h>
 #include <grass/glocale.h>
 
 #include "local_proto.h"
@@ -9,18 +10,20 @@
 		  const char *icon, double size, const char *size_column, int sqrt_flag, const char *rot_column, /* lines only */
 		  int id_flag, int table_colors_flag, int cats_colors_flag, char *rgb_column,
 		  int default_width, char *width_column, double width_scale,
-		  int z_color_flag, char *z_column)
+		  int z_color_flag, char *z_style)
 {
     int open_db, field, i, stat;
     dbCatValArray cvarr_rgb, cvarr_width, cvarr_size, cvarr_rot;
     struct field_info *fi;
     dbDriver *driver;
-    int nrec_rgb, nrec_width, nrec_size, nrec_rot;
-
+    int nrec_rgb, nrec_width, nrec_size, nrec_rot, has_color_table;
+    struct Colors colors, zcolors;
+    struct bound_box box;
+    
     stat = 0;
     nrec_rgb = nrec_width = nrec_size = nrec_rot = 0;
     
-    open_db = table_colors_flag || width_column || size_column || rot_column;
+    open_db = (table_colors_flag && rgb_column) || width_column || size_column || rot_column;
     if (open_db) {
 	field = Clist->field > 0 ? Clist->field : 1;
 	fi = Vect_get_field(Map, field);
@@ -36,32 +39,37 @@
     }
     
     if (table_colors_flag) {
-	/* for reading RRR:GGG:BBB color strings from table */
-	if (!rgb_column || *rgb_column == '\0')
-	    G_fatal_error(_("Color definition column not specified"));
-	
-	db_CatValArray_init(&cvarr_rgb);
-
-	nrec_rgb = db_select_CatValArray(driver, fi->table, fi->key,
-					 rgb_column, NULL, &cvarr_rgb);
-
-	G_debug(3, "nrec_rgb (%s) = %d", rgb_column, nrec_rgb);
-
-	if (cvarr_rgb.ctype != DB_C_TYPE_STRING)
-	    G_fatal_error(_("Color definition column (%s) not a string. "
-			    "Column must be of form RRR:GGG:BBB where RGB values range 0-255."),
-			  rgb_column);
-
-
-	if (nrec_rgb < 0)
-	    G_fatal_error(_("Unable to select data (%s) from table"),
-			  rgb_column);
-
-	G_debug(2, "\n%d records selected from table", nrec_rgb);
-
-	for (i = 0; i < cvarr_rgb.n_values; i++) {
-	    G_debug(4, "cat = %d  %s = %s", cvarr_rgb.value[i].cat,
-		    rgb_column, db_get_string(cvarr_rgb.value[i].val.s));
+	/* fisrt search for color table */
+	has_color_table = Vect_read_colors(Vect_get_name(Map), Vect_get_mapset(Map),
+					   &colors);
+	if (!has_color_table) {
+	    /* read RRR:GGG:BBB color strings from table */
+	    if (!rgb_column || *rgb_column == '\0')
+		G_fatal_error(_("Color definition column not specified"));
+	    
+	    db_CatValArray_init(&cvarr_rgb);
+	    
+	    nrec_rgb = db_select_CatValArray(driver, fi->table, fi->key,
+					     rgb_column, NULL, &cvarr_rgb);
+	    
+	    G_debug(3, "nrec_rgb (%s) = %d", rgb_column, nrec_rgb);
+	    
+	    if (cvarr_rgb.ctype != DB_C_TYPE_STRING)
+		G_fatal_error(_("Color definition column (%s) not a string. "
+				"Column must be of form RRR:GGG:BBB where RGB values range 0-255."),
+			      rgb_column);
+	    
+	    if (nrec_rgb < 0)
+		G_fatal_error(_("Unable to select data (%s) from table"),
+			      rgb_column);
+	    
+	    G_debug(2, "\n%d records selected from table", nrec_rgb);
+	    /*
+	    for (i = 0; i < cvarr_rgb.n_values; i++) {
+		G_debug(4, "cat = %d  %s = %s", cvarr_rgb.value[i].cat,
+			rgb_column, db_get_string(cvarr_rgb.value[i].val.s));
+	    }
+	    */
 	}
     }
 
@@ -161,24 +169,160 @@
     if (open_db)
 	db_close_database_shutdown_driver(driver);
 
+    if (z_color_flag) {
+	if (!Vect_is_3d(Map)) {
+	    G_warning(_("Vector map is not 3D. Unable to colorize features based on z-coordinates."));
+	    z_color_flag = 0;
+	}
+	else {
+	    Vect_get_map_box(Map, &box);
+	    Rast_make_fp_colors(&zcolors, z_style, box.B, box.T);
+	}
+    }
+
     stat = 0;
     if (type & GV_AREA)
 	stat += display_area(Map, Clist, window, 
 			     bcolor, fcolor, chcat,
 			     id_flag, table_colors_flag, cats_colors_flag,
-			     rgb_column, default_width, width_column, width_scale,
-			     z_color_flag, z_column,
-			     &cvarr_rgb, &cvarr_width, nrec_width);
+			     default_width, width_scale,
+			     z_color_flag ? &zcolors : NULL,
+			     &cvarr_rgb, has_color_table ? &colors : NULL,
+			     &cvarr_width, nrec_width);
 			     
     
     stat += display_lines(Map, type, Clist,
 			  bcolor, fcolor, chcat,
-			  icon, size, size_column, sqrt_flag, rot_column,
+			  icon, size, sqrt_flag,
 			  id_flag, table_colors_flag, cats_colors_flag,
-			  rgb_column, default_width, width_column, width_scale,
-			  z_color_flag, z_column,
-			  &cvarr_rgb, &cvarr_width, nrec_width,
-			  &cvarr_size, nrec_size, &cvarr_rot, nrec_rot);
+			  default_width, width_scale,
+			  z_color_flag ? &zcolors : NULL,
+			  &cvarr_rgb, has_color_table ? &colors : NULL,
+			  &cvarr_width, nrec_width,
+			  &cvarr_size, nrec_size,
+			  &cvarr_rot, nrec_rot);
     
     return stat;
 }
+
+int get_table_color(int cat, int line,
+		    struct Colors *colors, dbCatValArray *cvarr,
+		    int *red, int *grn, int *blu, int *nerror)
+{
+    int custom_rgb, nerror_rgb;
+    char colorstring[12];	/* RRR:GGG:BBB */
+    
+    dbCatVal *cv;
+
+    *nerror = nerror_rgb = 0;
+    custom_rgb = FALSE;
+    cv = NULL;
+
+    if (cat < 0)
+	return custom_rgb;
+    
+    if (colors) {
+	/* read color table */
+	if (Rast_get_c_color(&cat, red, grn, blu, colors) == 1) {
+	    custom_rgb = TRUE;
+	    G_debug(3, "\tb: %d, g: %d, r: %d", *blu, *grn, *red);
+	}
+    }
+    else {
+	/* read RGB colors from db for current area # */
+	if (db_CatValArray_get_value(cvarr, cat, &cv) == DB_OK) {
+	    sprintf(colorstring, "%s", db_get_string(cv->val.s));
+	    if (*colorstring != '\0') {
+		G_debug(3, "element %d: colorstring: %s", line,
+			colorstring);
+		
+		if (G_str_to_color(colorstring, red, grn, blu) == 1) {
+		    custom_rgb = TRUE;
+		    G_debug(3, "element:%d  cat %d r:%d g:%d b:%d",
+			    line, cat, *red, *grn, *blu);
+		}
+		else {
+		    G_important_message(_("Error in color definition (%s) - feature %d with category %d"),
+					colorstring, line, cat);
+		    nerror_rgb++;
+		}
+	    }
+	    else {
+		G_important_message(_("Error in color definition (%s) - feature %d with category %d"),
+				    colorstring, line, cat);
+		nerror_rgb++;
+	    }
+	}
+    }
+
+    *nerror = nerror_rgb;
+    
+    return custom_rgb;
+}
+
+int get_cat_color(int line, const struct line_cats *Cats, const struct cat_list *Clist,
+		  int *red, int *grn, int *blu)
+{
+    int custom_rgb;
+    unsigned char which;
+    int cat;
+    
+    custom_rgb = FALSE;
+    if (Clist->field > 0) {
+	Vect_cat_get(Cats, Clist->field, &cat);
+	if (cat >= 0) {
+	    G_debug(3, "display element %d, cat %d", line, cat);
+	    /* fetch color number from category */
+	    which = (cat % palette_ncolors);
+	    G_debug(3, "cat:%d which color:%d r:%d g:%d b:%d", cat,
+		    which, palette[which].R, palette[which].G,
+		    palette[which].B);
+	    
+	    custom_rgb = TRUE;
+	    *red = palette[which].R;
+	    *grn = palette[which].G;
+	    *blu = palette[which].B;
+	}
+    }
+    else if (Cats->n_cats > 0) {
+	/* fetch color number from layer */
+	which = (Cats->field[0] % palette_ncolors);
+	G_debug(3, "layer:%d which color:%d r:%d g:%d b:%d",
+		Cats->field[0], which, palette[which].R,
+		palette[which].G, palette[which].B);
+	
+	custom_rgb = TRUE;
+	*red = palette[which].R;
+	*grn = palette[which].G;
+	*blu = palette[which].B;
+    }
+
+    return custom_rgb;
+}
+
+double get_property(int cat, int line, dbCatValArray *cvarr, double scale, double default_value)
+{
+    double value;
+    dbCatVal *cv;
+
+    cv = NULL;
+
+    if (cat < 0)
+	return default_value;
+    
+    /* Read line width from db for current area # */
+    if (db_CatValArray_get_value(cvarr, cat, &cv) != DB_OK) {
+	value = default_value;
+    }
+    else {
+	value = scale * (cvarr->ctype ==
+			 DB_C_TYPE_INT ? (double) cv->val.i : cv->val.d);
+	if (value < 0) {
+	    G_important_message(_("Invalid negative value - feature %d with category %d"),
+				line, cat);
+	    value = default_value;
+	}
+    }
+
+    return value;
+}



More information about the grass-commit mailing list