Browse Source

full RGB support for the setcolor instruction (https://trac.osgeo.org/grass/ticket/192) & document hidden setcolor functionality; i18n

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47707 15284696-431f-4ddb-bdfa-cd5b030d7da7
Hamish Bowman 13 years ago
parent
commit
c692835751
2 changed files with 34 additions and 44 deletions
  1. 4 3
      ps/ps.map/ps.map.html
  2. 30 41
      ps/ps.map/r_instructions.c

+ 4 - 3
ps/ps.map/ps.map.html

@@ -1160,11 +1160,12 @@ EXAMPLE:
 	<B>setcolor</B> 2,5,8 white
 	<B>setcolor</B> 2,5,8 white
 	<B>setcolor</B> 10 green
 	<B>setcolor</B> 10 green
 </PRE>
 </PRE>
-Of course,
-<EM>setcolor</EM>
+Of course, <EM>setcolor</EM>
 can be requested more than once to override the default color for additional
 can be requested more than once to override the default color for additional
 categories.  More than one category can be changed for each request by listing
 categories.  More than one category can be changed for each request by listing
-all the category values separated by commas (but with no spaces).
+all the category values separated by commas (but with no spaces). Also ranges
+can be included, for example "1,2,6-10,12". Colors for "<tt>null</tt>" and the
+"<tt>default</tt>" (i.e. out-of-range) color may also be reassigned.
 <P>
 <P>
 
 
 
 

+ 30 - 41
ps/ps.map/r_instructions.c

@@ -3,7 +3,6 @@
 #include <grass/colors.h>
 #include <grass/colors.h>
 #include <grass/imagery.h>
 #include <grass/imagery.h>
 #include <grass/glocale.h>
 #include <grass/glocale.h>
-
 #include "local_proto.h"
 #include "local_proto.h"
 
 
 #define KEY(x) (strcmp(key,x)==0)
 #define KEY(x) (strcmp(key,x)==0)
@@ -60,11 +59,11 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		fclose(inputfd);
 		fclose(inputfd);
 
 
 	    if (sscanf(data, "%s", name) != 1) {
 	    if (sscanf(data, "%s", name) != 1) {
-		error(key, data, "no file specified");
+		error(key, data, _("no file specified"));
 		inputfd = stdin;
 		inputfd = stdin;
 	    }
 	    }
 	    else if ((inputfd = fopen(name, "r")) == NULL) {
 	    else if ((inputfd = fopen(name, "r")) == NULL) {
-		error(key, data, "unable to open");
+		error(key, data, _("unable to open"));
 		inputfd = stdin;
 		inputfd = stdin;
 	    }
 	    }
 	    else
 	    else
@@ -95,7 +94,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		}
 		}
 	    }
 	    }
 	    else {
 	    else {
-		error(key, data, "illegal maploc request");
+		error(key, data, _("illegal maploc request"));
 		gobble_input();
 		gobble_input();
 	    }
 	    }
 	    continue;
 	    continue;
@@ -109,36 +108,27 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 	    n = sscanf(data, "%d", &copies);
 	    n = sscanf(data, "%d", &copies);
 	    if (n != 1 || copies < 1 || copies > 20) {
 	    if (n != 1 || copies < 1 || copies > 20) {
 		ps_copies = 1;
 		ps_copies = 1;
-		error(key, data, "illegal copies request");
+		error(key, data, _("illegal copies request"));
 	    }
 	    }
 	    ps_copies = copies;
 	    ps_copies = copies;
 	    continue;
 	    continue;
 	}
 	}
 
 
 	if (KEY("setcolor")) {
 	if (KEY("setcolor")) {
-	    float R, G, B;
-	    int r, g, b;
-	    int color;
+	    int ret, r, g, b;
 	    int count;
 	    int count;
 	    DCELL *val_list;
 	    DCELL *val_list;
 	    DCELL dmin, dmax;
 	    DCELL dmin, dmax;
 	    char colorbuf[100];
 	    char colorbuf[100];
 	    char catsbuf[100];
 	    char catsbuf[100];
 
 
-	    if (PS->cell_fd < 0) {
-		error(key, data, "no raster map selected yet");
-		continue;
-	    }
+	    if (PS->cell_fd < 0)
+		error(key, data, _("no raster map selected yet"));
+
 	    if (sscanf(data, "%s %[^\n]", catsbuf, colorbuf) == 2) {
 	    if (sscanf(data, "%s %[^\n]", catsbuf, colorbuf) == 2) {
-		color = get_color_number(colorbuf);
-		if (color < 0) {
-		    error(key, data, "illegal color");
-		    continue;
-		}
-		get_color_rgb(color, &R, &G, &B);
-		r = 255.0 * R;
-		g = 255.0 * G;
-		b = 255.0 * B;
+		ret = G_str_to_color(colorbuf, &r, &g, &b);
+		if (ret != 1)
+		    error(key, colorbuf, _("illegal color request")); 
 
 
 		if (strncmp(catsbuf, "null", 4) == 0) {
 		if (strncmp(catsbuf, "null", 4) == 0) {
 		    Rast_set_null_value_color(r, g, b, &(PS->colors));
 		    Rast_set_null_value_color(r, g, b, &(PS->colors));
@@ -148,10 +138,9 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		    Rast_set_default_color(r, g, b, &(PS->colors));
 		    Rast_set_default_color(r, g, b, &(PS->colors));
 		    continue;
 		    continue;
 		}
 		}
-		if ((count = parse_val_list(catsbuf, &val_list)) < 0) {
-		    error(key, data, "illegal value list");
-		    continue;
-		}
+		if ((count = parse_val_list(catsbuf, &val_list)) < 0)
+		    error(key, data, _("illegal value list"));
+
 		for (i = 0; i < count; i += 2) {
 		for (i = 0; i < count; i += 2) {
 		    dmin = val_list[i];
 		    dmin = val_list[i];
 		    dmax = val_list[i + 1];
 		    dmax = val_list[i + 1];
@@ -186,7 +175,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 	if (KEY("scalebar")) {
 	if (KEY("scalebar")) {
 	    if (G_projection() == PROJECTION_LL) {
 	    if (G_projection() == PROJECTION_LL) {
 		error(key, data,
 		error(key, data,
-		      "scalebar is not appropriate for this projection");
+		      _("scalebar is not appropriate for this projection"));
 		gobble_input();
 		gobble_input();
 	    }
 	    }
 	    PS->do_scalebar = 1;
 	    PS->do_scalebar = 1;
@@ -194,7 +183,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		strcpy(sb->type, "f");	/* default to fancy scalebar */
 		strcpy(sb->type, "f");	/* default to fancy scalebar */
 	    read_scalebar();
 	    read_scalebar();
 	    if (sb->length <= 0.) {
 	    if (sb->length <= 0.) {
-		error(key, data, "Bad scalebar length");
+		error(key, data, _("Bad scalebar length"));
 		gobble_input();
 		gobble_input();
 	    }
 	    }
 	    continue;
 	    continue;
@@ -210,7 +199,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		read_text(east, north, text);
 		read_text(east, north, text);
 	    else {
 	    else {
 		gobble_input();
 		gobble_input();
-		error(key, data, "illegal text request");
+		error(key, data, _("illegal text request"));
 	    }
 	    }
 	    continue;
 	    continue;
 	}
 	}
@@ -224,7 +213,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		read_point(e, n);
 		read_point(e, n);
 	    else {
 	    else {
 		gobble_input();
 		gobble_input();
-		error(key, data, "illegal point request");
+		error(key, data, _("illegal point request"));
 	    }
 	    }
 	    continue;
 	    continue;
 	}
 	}
@@ -238,7 +227,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		read_eps(e, n);
 		read_eps(e, n);
 	    else {
 	    else {
 		gobble_input();
 		gobble_input();
-		error(key, data, "illegal eps request");
+		error(key, data, _("illegal eps request"));
 	    }
 	    }
 	    continue;
 	    continue;
 	}
 	}
@@ -255,7 +244,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		read_line(e1, n1, e2, n2);
 		read_line(e1, n1, e2, n2);
 	    else {
 	    else {
 		gobble_input();
 		gobble_input();
-		error(key, data, "illegal line request");
+		error(key, data, _("illegal line request"));
 	    }
 	    }
 	    continue;
 	    continue;
 	}
 	}
@@ -272,7 +261,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		read_rectangle(e1, n1, e2, n2);
 		read_rectangle(e1, n1, e2, n2);
 	    else {
 	    else {
 		gobble_input();
 		gobble_input();
-		error(key, data, "illegal rectangle request");
+		error(key, data, _("illegal rectangle request"));
 	    }
 	    }
 	    continue;
 	    continue;
 	}
 	}
@@ -283,7 +272,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		read_comment(name);
 		read_comment(name);
 		break;
 		break;
 	    case 2:
 	    case 2:
-		error(key, data, "illegal comments request");
+		error(key, data, _("illegal comments request"));
 		break;
 		break;
 	    default:
 	    default:
 		read_comment("");
 		read_comment("");
@@ -299,7 +288,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		strcpy(PS->scaletext, data);
 		strcpy(PS->scaletext, data);
 	    else {
 	    else {
 		PS->scaletext[0] = 0;
 		PS->scaletext[0] = 0;
-		error(key, data, "illegal scale request");
+		error(key, data, _("illegal scale request"));
 	    }
 	    }
 	    continue;
 	    continue;
 	}
 	}
@@ -330,7 +319,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 
 
 	if (KEY("outline")) {
 	if (KEY("outline")) {
 	    if (PS->cell_fd < 0) {
 	    if (PS->cell_fd < 0) {
-		error(key, data, "no raster map selected yet");
+		error(key, data, _("no raster map selected yet"));
 		gobble_input();
 		gobble_input();
 	    }
 	    }
 	    else
 	    else
@@ -359,7 +348,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		read_group();
 		read_group();
 	    }
 	    }
 	    else
 	    else
-		error(key, data, "group not found");
+		error(key, data, _("group not found"));
 	    continue;
 	    continue;
 	}
 	}
 
 
@@ -401,7 +390,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 	    sscanf(data, "%d", &(PS->grid));
 	    sscanf(data, "%d", &(PS->grid));
 	    if (PS->grid < 0) {
 	    if (PS->grid < 0) {
 		PS->grid = 0;
 		PS->grid = 0;
-		error(key, data, "illegal grid spacing");
+		error(key, data, _("illegal grid spacing"));
 		gobble_input();
 		gobble_input();
 	    }
 	    }
 	    else
 	    else
@@ -412,7 +401,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 	if (KEY("geogrid")) {
 	if (KEY("geogrid")) {
 	    if (G_projection() == PROJECTION_XY) {
 	    if (G_projection() == PROJECTION_XY) {
 		error(key, data,
 		error(key, data,
-		      "geogrid is not available for this projection");
+		      _("geogrid is not available for this projection"));
 		gobble_input();
 		gobble_input();
 	    }
 	    }
 	    /*          if (G_projection() == PROJECTION_LL)
 	    /*          if (G_projection() == PROJECTION_LL)
@@ -422,7 +411,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 	    sscanf(data, "%d %s", &(PS->geogrid), PS->geogridunit);
 	    sscanf(data, "%d %s", &(PS->geogrid), PS->geogridunit);
 	    if (PS->geogrid < 0) {
 	    if (PS->geogrid < 0) {
 		PS->geogrid = 0;
 		PS->geogrid = 0;
-		error(key, data, "illegal geo-grid spacing");
+		error(key, data, _("illegal geo-grid spacing"));
 		gobble_input();
 		gobble_input();
 	    }
 	    }
 	    else
 	    else
@@ -454,11 +443,11 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
 		continue;
 		continue;
 	    }
 	    }
 	    else {
 	    else {
-		error(key, data, "illegal color request");
+		error(key, data, _("illegal color request"));
 	    }
 	    }
 	}
 	}
 
 
 	if (*key)
 	if (*key)
-	    error(key, "", "illegal request");
+	    error(key, "", _("illegal request"));
     }
     }
 }
 }