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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 14 07:09:50 EDT 2011


Author: martinl
Date: 2011-08-14 04:09:49 -0700 (Sun, 14 Aug 2011)
New Revision: 47622

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: use color table if available
	-a flag used only for rgb_column


Modified: grass/trunk/display/d.vect/area.c
===================================================================
--- grass/trunk/display/d.vect/area.c	2011-08-14 09:57:37 UTC (rev 47621)
+++ grass/trunk/display/d.vect/area.c	2011-08-14 11:09:49 UTC (rev 47622)
@@ -15,7 +15,7 @@
 
 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, 
+		 int id_flag, int cats_color_flag, 
 		 int default_width, double width_scale,
 		 struct Colors *zcolors,
 		 dbCatValArray *cvarr_rgb, struct Colors *colors,
@@ -169,7 +169,7 @@
 	}
 
         /* custom colors */
-	if (table_colors_flag) {
+	if (colors || cvarr_rgb) {
 	    custom_rgb = get_table_color(cat, area, colors, cvarr_rgb,
 					 &red, &grn, &blu, &nerror_rgb);
 	}
@@ -190,7 +190,7 @@
 	}
 	
 	if (fcolor || zcolors) {
-	    if (!table_colors_flag && !cats_color_flag && !zcolors) {
+	    if (!cvarr_rgb && !cats_color_flag && !zcolors) {
 		D_RGB_color(fcolor->r, fcolor->g, fcolor->b);
 		D_polygon_abs(Points->x, Points->y, Points->n_points);
 	    }

Modified: grass/trunk/display/d.vect/lines.c
===================================================================
--- grass/trunk/display/d.vect/lines.c	2011-08-14 09:57:37 UTC (rev 47621)
+++ grass/trunk/display/d.vect/lines.c	2011-08-14 11:09:49 UTC (rev 47622)
@@ -39,7 +39,7 @@
 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, int sqrt_flag,
-		  int id_flag, int table_colors_flag, int cats_color_flag, 
+		  int id_flag, int cats_color_flag, 
 		  int default_width, double width_scale,
 		  struct Colors* zcolors,
 		  dbCatValArray *cvarr_rgb, struct Colors *colors,
@@ -117,7 +117,7 @@
     
     Vect_rewind(Map);
 
-    if (color && !table_colors_flag && !cats_color_flag)
+    if (color && !cvarr_rgb && !cats_color_flag)
 	D_RGB_color(color->r, color->g, color->b);
 
     if (Vect_level(Map) >= 2)
@@ -194,14 +194,15 @@
 		custom_rgb = FALSE;
 	}
 
-	if (table_colors_flag || nrec_width > 0 || nrec_size > 0 || nrec_rot > 0)
+	if (colors || cvarr_rgb ||
+	    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);
 	
 	/* custom colors */
-	if (table_colors_flag) {
+	if (colors || cvarr_rgb) {
 	    custom_rgb = get_table_color(cat, line, colors, cvarr_rgb,
 					 &red, &grn, &blu, &nerror_rgb);
 	}
@@ -280,7 +281,7 @@
 	    rotation = 0.0;
 	}
 	else if (color || custom_rgb || zcolors) {
-	    if (!table_colors_flag && !cats_color_flag && !zcolors)
+	    if (!cvarr_rgb && !cats_color_flag && !zcolors)
 		D_RGB_color(color->r, color->g, color->b);
 	    else {
 		if (custom_rgb)

Modified: grass/trunk/display/d.vect/local_proto.h
===================================================================
--- grass/trunk/display/d.vect/local_proto.h	2011-08-14 09:57:37 UTC (rev 47621)
+++ grass/trunk/display/d.vect/local_proto.h	2011-08-14 11:09:49 UTC (rev 47622)
@@ -13,8 +13,7 @@
 /* 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,
-		 int, double,
+		 int, int, double,
 		 struct Colors *,
 		 dbCatValArray *, struct Colors *, dbCatValArray *, int);
 
@@ -30,8 +29,7 @@
 int display_lines(struct Map_info *, int, struct cat_list *,
 		  const struct color_rgb *, const struct color_rgb *, int,
 		  const char *, double, int,
-		  int, int, int, 
-		  int, double,
+		  int, int, int, double,
 		  struct Colors *,
 		  dbCatValArray *, struct Colors *, dbCatValArray *, int,
 		  dbCatValArray *, int, dbCatValArray *, int);

Modified: grass/trunk/display/d.vect/main.c
===================================================================
--- grass/trunk/display/d.vect/main.c	2011-08-14 09:57:37 UTC (rev 47621)
+++ grass/trunk/display/d.vect/main.c	2011-08-14 11:09:49 UTC (rev 47622)
@@ -173,6 +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_standard_option(G_OPT_M_COLR);
     zcol_opt->key = "zcolor";
@@ -335,7 +336,7 @@
     table_acolors_flag->key = 'a';
     table_acolors_flag->guisection = _("Colors");
     table_acolors_flag->description =
-	_("Get colors from color table or attribute column (see 'rgb_column')");
+	_("Get colors from attribute table (see 'rgb_column' option)");
 
     cats_acolors_flag = G_define_flag();
     cats_acolors_flag->key = 'c';

Modified: grass/trunk/display/d.vect/shape.c
===================================================================
--- grass/trunk/display/d.vect/shape.c	2011-08-14 09:57:37 UTC (rev 47621)
+++ grass/trunk/display/d.vect/shape.c	2011-08-14 11:09:49 UTC (rev 47622)
@@ -16,14 +16,14 @@
     dbCatValArray cvarr_rgb, cvarr_width, cvarr_size, cvarr_rot;
     struct field_info *fi;
     dbDriver *driver;
-    int nrec_rgb, nrec_width, nrec_size, nrec_rot, has_color_table;
+    int nrec_rgb, nrec_width, nrec_size, nrec_rot, have_colors;
     struct Colors colors, zcolors;
     struct bound_box box;
     
     stat = 0;
     nrec_rgb = nrec_width = nrec_size = nrec_rot = 0;
     
-    open_db = (table_colors_flag && rgb_column) || width_column || size_column || rot_column;
+    open_db = table_colors_flag || width_column || size_column || rot_column;
     if (open_db) {
 	field = Clist->field > 0 ? Clist->field : 1;
 	fi = Vect_get_field(Map, field);
@@ -38,39 +38,38 @@
 			  fi->database, fi->driver);
     }
     
+    /* fisrt search for color table */
+    have_colors = Vect_read_colors(Vect_get_name(Map), Vect_get_mapset(Map),
+				   &colors);
+    
     if (table_colors_flag) {
-	/* 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"));
+	/* 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);
 	    
-	    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));
-	    }
-	    */
-	}
+	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));
+	  }
+	*/
     }
 
     if (width_column) {
@@ -184,20 +183,22 @@
     if (type & GV_AREA)
 	stat += display_area(Map, Clist, window, 
 			     bcolor, fcolor, chcat,
-			     id_flag, table_colors_flag, cats_colors_flag,
+			     id_flag, cats_colors_flag,
 			     default_width, width_scale,
 			     z_color_flag ? &zcolors : NULL,
-			     &cvarr_rgb, has_color_table ? &colors : NULL,
+			     table_colors_flag ? &cvarr_rgb : NULL,
+			     have_colors ? &colors : NULL,
 			     &cvarr_width, nrec_width);
 			     
     
     stat += display_lines(Map, type, Clist,
 			  bcolor, fcolor, chcat,
 			  icon, size, sqrt_flag,
-			  id_flag, table_colors_flag, cats_colors_flag,
+			  id_flag, cats_colors_flag,
 			  default_width, width_scale,
 			  z_color_flag ? &zcolors : NULL,
-			  &cvarr_rgb, has_color_table ? &colors : NULL,
+			  table_colors_flag ? &cvarr_rgb : NULL,
+			  have_colors ? &colors : NULL,
 			  &cvarr_width, nrec_width,
 			  &cvarr_size, nrec_size,
 			  &cvarr_rot, nrec_rot);
@@ -228,31 +229,30 @@
 	    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++;
-		}
+
+    /* read RGB colors from db for current area # */
+    if (cvarr && 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;



More information about the grass-commit mailing list