[GRASS-SVN] r51968 - grass/branches/releasebranch_6_4/display/d.vect

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 4 02:33:21 PDT 2012


Author: mmetz
Date: 2012-06-04 02:33:20 -0700 (Mon, 04 Jun 2012)
New Revision: 51968

Modified:
   grass/branches/releasebranch_6_4/display/d.vect/attr.c
   grass/branches/releasebranch_6_4/display/d.vect/dir.c
   grass/branches/releasebranch_6_4/display/d.vect/label.c
   grass/branches/releasebranch_6_4/display/d.vect/local_proto.h
   grass/branches/releasebranch_6_4/display/d.vect/main.c
   grass/branches/releasebranch_6_4/display/d.vect/plot1.c
   grass/branches/releasebranch_6_4/display/d.vect/topo.c
Log:
d.vect: display area labels also when centroids are not displayed (backport from trunk)

Modified: grass/branches/releasebranch_6_4/display/d.vect/attr.c
===================================================================
--- grass/branches/releasebranch_6_4/display/d.vect/attr.c	2012-06-04 08:16:50 UTC (rev 51967)
+++ grass/branches/releasebranch_6_4/display/d.vect/attr.c	2012-06-04 09:33:20 UTC (rev 51968)
@@ -54,7 +54,7 @@
 	else if (ltype == -2)
 	    break;
 	
-	if (!(type & ltype))
+	if (!(type & ltype) && !((type & GV_AREA) && (ltype & GV_CENTROID)))
 	    continue;		/* used for both lines and labels */
 
 	R_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);

Modified: grass/branches/releasebranch_6_4/display/d.vect/dir.c
===================================================================
--- grass/branches/releasebranch_6_4/display/d.vect/dir.c	2012-06-04 08:16:50 UTC (rev 51967)
+++ grass/branches/releasebranch_6_4/display/d.vect/dir.c	2012-06-04 09:33:20 UTC (rev 51968)
@@ -5,10 +5,13 @@
 #include <grass/glocale.h>
 #include "plot.h"
 
+/* arrow heads will be drawn at 25,50,75% of the line length */
+#define PERC_OF_LINE 25
+
 int dir(struct Map_info *Map, int type, struct cat_list *Clist, int chcat)
 {
     int ltype, dsize;
-    double len, x, y, angle, msize;
+    double len, x, y, angle, msize, dist;
     struct line_pnts *Points;
     struct line_cats *Cats;
 
@@ -62,17 +65,13 @@
 
 	len = Vect_line_length(Points);
 
-	Vect_point_on_line(Points, len * 0.25, &x, &y, NULL, &angle, NULL);
-	G_debug(3, "plot direction: %f, %f", x, y);
-	G_plot_icon(x, y, G_ICON_ARROW, angle, msize);
-
-	Vect_point_on_line(Points, len * 0.5, &x, &y, NULL, &angle, NULL);
-	G_debug(3, "plot direction: %f, %f", x, y);
-	G_plot_icon(x, y, G_ICON_ARROW, angle, msize);
-
-	Vect_point_on_line(Points, len * 0.75, &x, &y, NULL, &angle, NULL);
-	G_debug(3, "plot direction: %f, %f", x, y);
-	G_plot_icon(x, y, G_ICON_ARROW, angle, msize);
+	for (dist = PERC_OF_LINE / 100.0; dist <= 1.0 - PERC_OF_LINE / 100.0;
+	     dist += PERC_OF_LINE / 100.0) {
+	    Vect_point_on_line(Points, len * dist, &x, &y, NULL, &angle,
+			       NULL);
+	    G_debug(4, "plot direction: %f, %f", x, y);
+	    G_plot_icon(x, y, G_ICON_ARROW, angle, msize);
+	}
     }
 
 

Modified: grass/branches/releasebranch_6_4/display/d.vect/label.c
===================================================================
--- grass/branches/releasebranch_6_4/display/d.vect/label.c	2012-06-04 08:16:50 UTC (rev 51967)
+++ grass/branches/releasebranch_6_4/display/d.vect/label.c	2012-06-04 09:33:20 UTC (rev 51968)
@@ -5,7 +5,7 @@
 #include <grass/glocale.h>
 #include "plot.h"
 
-int label(struct Map_info *Map, int type, int do_area,
+int label(struct Map_info *Map, int type,
 	  struct cat_list *Clist, LATTR * lattr, int chcat)
 {
     int i, ltype;
@@ -30,7 +30,7 @@
 	    return 0;
 	}
 
-	if (!(type & ltype))
+	if (!(type & ltype) && !((type & GV_AREA) && (ltype & GV_CENTROID)))
 	    continue;		/* used for both lines and labels */
 
 	R_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);

Modified: grass/branches/releasebranch_6_4/display/d.vect/local_proto.h
===================================================================
--- grass/branches/releasebranch_6_4/display/d.vect/local_proto.h	2012-06-04 08:16:50 UTC (rev 51967)
+++ grass/branches/releasebranch_6_4/display/d.vect/local_proto.h	2012-06-04 09:33:20 UTC (rev 51968)
@@ -2,12 +2,12 @@
 
 FILE *open_vect(char *, char *);
 int close_vect(FILE *);
-int plot1(struct Map_info *, int, int, struct cat_list *,
+int plot1(struct Map_info *, int, struct cat_list *,
 	  const struct color_rgb *, const struct color_rgb *, int, char *,
 	  double, char *, char *, int, int, int, char *, int, char *, double,
 	  int, char *);
-int label(struct Map_info *, int, int, struct cat_list *, LATTR *, int);
-int topo(struct Map_info *, int, int, LATTR *);
+int label(struct Map_info *, int, struct cat_list *, LATTR *, int);
+int topo(struct Map_info *, int, LATTR *);
 int dir(struct Map_info *, int, struct cat_list *, int);
 int darea(struct Map_info *, struct cat_list *, const struct color_rgb *,
 	  const struct color_rgb *, int, int, int, int, struct Cell_head *,

Modified: grass/branches/releasebranch_6_4/display/d.vect/main.c
===================================================================
--- grass/branches/releasebranch_6_4/display/d.vect/main.c	2012-06-04 08:16:50 UTC (rev 51967)
+++ grass/branches/releasebranch_6_4/display/d.vect/main.c	2012-06-04 09:33:20 UTC (rev 51968)
@@ -27,58 +27,14 @@
 #include "plot.h"
 #include "local_proto.h"
 
-/* adopted from r.colors */
-static char *icon_files(void)
-{
-    char *list = NULL, path[4096], path_i[4096];
-    size_t len = 0, l;
-    DIR *dir, *dir_i;
-    struct dirent *d, *d_i;
+static int cmp(const void *, const void *);
+static char *icon_files(void);
 
-    sprintf(path, "%s/etc/symbol", G_gisbase());
-
-    dir = opendir(path);
-    if (!dir)
-	return NULL;
-
-    /*loop over etc/symbol */
-    while ((d = readdir(dir))) {
-	if (d->d_name[0] == '.')
-	    continue;
-
-	sprintf(path_i, "%s/etc/symbol/%s", G_gisbase(), d->d_name);
-	dir_i = opendir(path_i);
-
-	if (!dir_i)
-	    continue;
-
-	/*loop over each directory in etc/symbols */
-	while ((d_i = readdir(dir_i))) {
-	    if (d_i->d_name[0] == '.')
-		continue;
-
-	    l = strlen(d->d_name) + strlen(d_i->d_name) + 3;
-	    list = G_realloc(list, len + l);
-	    sprintf(list + len, "%s/%s,", d->d_name, d_i->d_name);
-	    len += l - 1;
-	}
-
-	closedir(dir_i);
-    }
-
-    closedir(dir);
-
-    if (len)
-	list[len - 1] = 0;
-
-    return list;
-}
-
 int main(int argc, char **argv)
 {
     char *mapset;
     int ret, level;
-    int i, stat = 0, type, area, display;
+    int i, stat = 0, type, display;
     int chcat = 0;
     int r, g, b;
     int has_color, has_fcolor;
@@ -538,32 +494,7 @@
 	    G_warning(_("%d errors in cat option"), ret);
     }
 
-    i = 0;
-    type = 0;
-    area = FALSE;
-    while (type_opt->answers[i]) {
-	switch (type_opt->answers[i][0]) {
-	case 'p':
-	    type |= GV_POINT;
-	    break;
-	case 'l':
-	    type |= GV_LINE;
-	    break;
-	case 'b':
-	    type |= GV_BOUNDARY;
-	    break;
-	case 'f':
-	    type |= GV_FACE;
-	    break;
-	case 'c':
-	    type |= GV_CENTROID;
-	    break;
-	case 'a':
-	    area = TRUE;
-	    break;
-	}
-	i++;
-    }
+    type = Vect_option_to_types(type_opt); 
 
     i = 0;
     display = 0;
@@ -674,7 +605,7 @@
 	if (!wcolumn_opt->answer)
 	    D_line_width(default_width);
 
-	if (area) {
+	if (type & GV_AREA) {
 	    if (level >= 2) {
 		if (display & DISP_SHAPE) {
 		    stat = darea(&Map, Clist,
@@ -699,7 +630,7 @@
 		G_warning(_("Unable to display lines by id, topology not available"));
 	    }
 	    else {
-		stat = plot1(&Map, type, area, Clist,
+		stat = plot1(&Map, type, Clist,
 			     has_color ? &color : NULL,
 			     has_fcolor ? &fcolor : NULL, chcat, icon_opt->answer,
 			     size, sizecolumn_opt->answer, rotcolumn_opt->answer,
@@ -726,7 +657,7 @@
 	    R_line_width(0);
 
 	if (display & DISP_CAT)
-	    stat = label(&Map, type, area, Clist, &lattr, chcat);
+	    stat = label(&Map, type, Clist, &lattr, chcat);
 
 	if (display & DISP_ATTR)
 	    stat =
@@ -737,7 +668,7 @@
 
 	if (display & DISP_TOPO) {
 	    if (level >= 2)
-		stat = topo(&Map, type, area, &lattr);
+		stat = topo(&Map, type, &lattr);
 	    else
 		G_warning(_("Unable to display topology, not available"));
 	}
@@ -760,3 +691,78 @@
 
     exit(stat);
 }
+
+int cmp(const void *a, const void *b) 
+{
+    return (strcmp(*(char **)a, *(char **)b));
+}
+
+/* adopted from r.colors */
+char *icon_files(void)
+{
+    char **list, *ret;
+    char buf[GNAME_MAX], path[GPATH_MAX], path_i[GPATH_MAX];
+    int i, count;
+    size_t len;
+    DIR *dir, *dir_i;
+    struct dirent *d, *d_i;
+
+    list = NULL;
+    len = 0;
+    sprintf(path, "%s/etc/symbol", G_gisbase());
+
+    dir = opendir(path);
+    if (!dir)
+	return NULL;
+
+    count = 0;
+    
+    /* loop over etc/symbol */
+    while ((d = readdir(dir))) {
+	if (d->d_name[0] == '.')
+	    continue;
+
+	sprintf(path_i, "%s/etc/symbol/%s", G_gisbase(), d->d_name);
+	dir_i = opendir(path_i);
+
+	if (!dir_i)
+	    continue;
+
+	/* loop over each directory in etc/symbols */
+	while ((d_i = readdir(dir_i))) {
+	    if (d_i->d_name[0] == '.')
+		continue;
+	    
+	    list = G_realloc(list, (count + 1) * sizeof(char *));
+	    
+	    sprintf(buf, "%s/%s", d->d_name, d_i->d_name);
+	    list[count++] = G_store(buf);
+	    
+	    len += strlen(d->d_name) + strlen(d_i->d_name) + 2; /* '/' + ',' */
+	}
+
+	closedir(dir_i);
+    }
+
+    closedir(dir);
+
+    qsort(list, count, sizeof(char *), cmp);
+    
+    if (len > 0) {
+	ret = G_malloc((len + 1) * sizeof(char)); /* \0 */
+	*ret = '\0';
+	for (i = 0; i < count; i++) {
+	    if (i > 0)
+		strcat(ret, ",");
+	    strcat(ret, list[i]);
+	    G_free(list[i]);
+	}
+	G_free(list);
+    }
+    else {
+	ret = G_store("");
+    }
+    
+    return ret;
+}
+

Modified: grass/branches/releasebranch_6_4/display/d.vect/plot1.c
===================================================================
--- grass/branches/releasebranch_6_4/display/d.vect/plot1.c	2012-06-04 08:16:50 UTC (rev 51967)
+++ grass/branches/releasebranch_6_4/display/d.vect/plot1.c	2012-06-04 09:33:20 UTC (rev 51968)
@@ -126,7 +126,7 @@
 /* *************************************************************** */
 /* *************************************************************** */
 /* *************************************************************** */
-int plot1(struct Map_info *Map, int type, int area, struct cat_list *Clist,
+int plot1(struct Map_info *Map, int type, struct cat_list *Clist,
 	  const struct color_rgb *color, const struct color_rgb *fcolor,
 	  int chcat, char *symbol_name, double size, char *size_column,
 	  char *rot_column, int id_flag, int table_colors_flag,

Modified: grass/branches/releasebranch_6_4/display/d.vect/topo.c
===================================================================
--- grass/branches/releasebranch_6_4/display/d.vect/topo.c	2012-06-04 08:16:50 UTC (rev 51967)
+++ grass/branches/releasebranch_6_4/display/d.vect/topo.c	2012-06-04 09:33:20 UTC (rev 51968)
@@ -5,7 +5,7 @@
 #include "plot.h"
 #include <grass/glocale.h>
 
-int topo(struct Map_info *Map, int type, int do_area, LATTR * lattr)
+int topo(struct Map_info *Map, int type, LATTR * lattr)
 {
     int i, ltype, num, el;
     double xl, yl;



More information about the grass-commit mailing list