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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 5 07:49:57 PDT 2016


Author: annakrat
Date: 2016-08-05 07:49:57 -0700 (Fri, 05 Aug 2016)
New Revision: 69093

Added:
   grass/trunk/display/d.vect/legend.c
Modified:
   grass/trunk/display/d.vect/local_proto.h
   grass/trunk/display/d.vect/main.c
Log:
d.vect: move legend code to separate file, author Adam Laza

Added: grass/trunk/display/d.vect/legend.c
===================================================================
--- grass/trunk/display/d.vect/legend.c	                        (rev 0)
+++ grass/trunk/display/d.vect/legend.c	2016-08-05 14:49:57 UTC (rev 69093)
@@ -0,0 +1,75 @@
+#include <grass/gis.h>
+#include <grass/vector.h>
+#include "local_proto.h"
+
+void write_into_legfile(struct Map_info *Map, int type, const char *leglab, const char *name_map, const char *icon,
+                       const char *size, const char *color, const char *fcolor, const char *width, const char *icon_area,
+                       const char *icon_line)
+{
+    int nfeatures;
+    FILE *fd;
+    char *leg_file;
+    char map[GNAME_MAX];
+    char *ptr;
+    strcpy(map, name_map);
+    strtok_r(map, "@", &ptr);
+
+    /* Write into legend file */
+    leg_file = getenv("GRASS_LEGEND_FILE");
+    if (leg_file) {
+        fd = fopen(leg_file, "a");
+
+        /* Point */
+        if (type & GV_POINT){
+            nfeatures = Vect_get_num_primitives(Map, GV_POINT);
+            if (nfeatures > 0) {
+                if (leglab)
+                    fprintf(fd, "%s|", leglab);
+                else
+                    fprintf(fd, "%s|", map);
+                fprintf(fd, "%s|%s|%s|%s|%s", icon, size, color, fcolor, width);
+                fprintf(fd, "|%s|%d\n", "point", nfeatures);
+            }
+        }
+
+        /* Line */
+        if (type & GV_LINE){
+            nfeatures = Vect_get_num_primitives(Map, GV_LINE);
+            if (nfeatures > 0){
+                if (leglab)
+                    fprintf(fd, "%s|", leglab);
+                else
+                    fprintf(fd, "%s|", map);
+                fprintf(fd, "%s|%s|%s|%s|%s", icon_line, size, color, fcolor, width);
+                fprintf(fd, "|%s|%d\n", "line", nfeatures);
+            }
+        }
+
+        /* Area */
+        if (type & GV_AREA){
+            nfeatures = Vect_get_num_primitives(Map, GV_BOUNDARY);
+            if (nfeatures > 0) {
+                if (leglab)
+                    fprintf(fd, "%s|", leglab);
+                else
+                    fprintf(fd, "%s|", map);
+                fprintf(fd, "%s|%s|%s|%s|%s", icon_area, size, color, fcolor, width);
+                fprintf(fd, "|%s|%d\n", "area", nfeatures);
+            }
+        }
+        /* Centroid */
+        if (type & GV_CENTROID){
+            nfeatures = Vect_get_num_primitives(Map, GV_CENTROID);
+            if (nfeatures > 0) {
+                if (leglab)
+                    fprintf(fd, "%s|", leglab);
+                else
+                    fprintf(fd, "%s|", map);
+                fprintf(fd, "%s|%s|%s|%s|%s", icon, size, color, fcolor, width);
+                fprintf(fd, "|%s|%d\n", "centroid", nfeatures);
+            }
+        }
+
+        fclose(fd);
+    }
+}


Property changes on: grass/trunk/display/d.vect/legend.c
___________________________________________________________________
Added: svn:mime-type
   + text/x-csrc
Added: svn:eol-style
   + native

Modified: grass/trunk/display/d.vect/local_proto.h
===================================================================
--- grass/trunk/display/d.vect/local_proto.h	2016-08-05 13:02:45 UTC (rev 69092)
+++ grass/trunk/display/d.vect/local_proto.h	2016-08-05 14:49:57 UTC (rev 69093)
@@ -65,3 +65,8 @@
 
 /* zcoor.c */
 int display_zcoor(struct Map_info *, int, LATTR *);
+
+/* legend.c */
+void write_into_legfile(struct Map_info *, int, const char *, const char *,
+			const char *, const char *, const char *, const char *,
+			const char *, const char *, const char *);

Modified: grass/trunk/display/d.vect/main.c
===================================================================
--- grass/trunk/display/d.vect/main.c	2016-08-05 13:02:45 UTC (rev 69092)
+++ grass/trunk/display/d.vect/main.c	2016-08-05 14:49:57 UTC (rev 69093)
@@ -57,7 +57,6 @@
     struct Option *icon_line_opt, *icon_area_opt;
     struct Flag *id_flag, *cats_acolors_flag, *sqrt_flag;
     char *desc;
-    char *leg_file;
     
     struct cat_list *Clist;
     LATTR lattr;
@@ -65,10 +64,7 @@
     struct Cell_head window;
     struct bound_box box;
     double overlap;
-    int gv_point, gv_line, gv_boundary, gv_centroid;
 
-    FILE *fd;
-
     stat = 0;
     /* Initialize the GIS calls */
     G_gisinit(argv[0]);
@@ -457,84 +453,10 @@
 		stat += display_dir(&Map, type, Clist, chcat, size);
 	}
 
-        /* Write into legend file */
-        leg_file = getenv("GRASS_LEGEND_FILE");
-        if (leg_file) {
-            fd = fopen(leg_file, "a");
-            
-            /* Point */
-            if (strstr(type_opt->answer, "point") != NULL){
-                gv_point = Vect_get_num_primitives(&Map, GV_POINT);
-                if (gv_point > 0) {
-                    if (leglab_opt->answer)
-                        fprintf(fd, "%s|", leglab_opt->answer);
-                    else {
-                        char map[128];
-                        char *ptr;
-                        strcpy(map, map_opt->answer);
-                        strtok_r(map, "@", &ptr);
-                        fprintf(fd, "%s|", map);
-                    }
-                    fprintf(fd, "%s|%s|%s|%s|%s", icon_opt->answer, size_opt->answer, color_opt->answer, fcolor_opt->answer, width_opt->answer);
-                    fprintf(fd, "|%s|%d\n", "point", gv_point);
-                }
-            }
-            
-            /* Line */
-            if (strstr(type_opt->answer, "line") != NULL){
-                gv_line = Vect_get_num_primitives(&Map, GV_LINE);
-                if (gv_line > 0){
-                    if (leglab_opt->answer)
-                        fprintf(fd, "%s|", leglab_opt->answer);
-                    else {
-                        char map[128];
-                        char *ptr;
-                        strcpy(map, map_opt->answer);
-                        strtok_r(map, "@", &ptr);
-                        fprintf(fd, "%s|", map);
-                    }
-                    fprintf(fd, "%s|%s|%s|%s|%s", icon_line_opt->answer, size_opt->answer, color_opt->answer, fcolor_opt->answer, width_opt->answer);
-                    fprintf(fd, "|%s|%d\n", "line", gv_line);
-                }
-            }
-            
-            /* Area */
-            if (strstr(type_opt->answer, "area") != NULL){
-                gv_boundary = Vect_get_num_primitives(&Map, GV_BOUNDARY);
-                if (gv_boundary > 0) {
-                    if (leglab_opt->answer)
-                        fprintf(fd, "%s|", leglab_opt->answer);
-                    else {
-                        char map[128];
-                        char *ptr;
-                        strcpy(map, map_opt->answer);
-                        strtok_r(map, "@", &ptr);
-                        fprintf(fd, "%s|", map);
-                    }
-                    fprintf(fd, "%s|%s|%s|%s|%s", icon_area_opt->answer, size_opt->answer, color_opt->answer, fcolor_opt->answer, width_opt->answer);
-                    fprintf(fd, "|%s|%d\n", "area", gv_boundary);
-                }
-            }
-            /* Centroid */
-            if (strstr(type_opt->answer, "centroid") != NULL){
-                gv_centroid = Vect_get_num_primitives(&Map, GV_CENTROID);
-                if (gv_centroid > 0) {
-                    if (leglab_opt->answer)
-                        fprintf(fd, "%s|", leglab_opt->answer);
-                    else {
-                        char map[128];
-                        char *ptr;
-                        strcpy(map, map_opt->answer);
-                        strtok_r(map, "@", &ptr);
-                        fprintf(fd, "%s|", map);
-                    }
-                    fprintf(fd, "%s|%s|%s|%s|%s", icon_opt->answer, size_opt->answer, color_opt->answer, fcolor_opt->answer, width_opt->answer);
-                    fprintf(fd, "|%s|%d\n", "centroid", gv_centroid);
-                }
-            }
-            
-            fclose(fd);
-        }
+	write_into_legfile(&Map, type, leglab_opt->answer, map_name,
+			   icon_opt->answer, size_opt->answer, color_opt->answer,
+			   fcolor_opt->answer, width_opt->answer, icon_area_opt->answer,
+			   icon_line_opt->answer);
 
 	/* reset line width: Do we need to get line width from display
 	 * driver (not implemented)?  It will help restore previous line



More information about the grass-commit mailing list