Kaynağa Gözat

d.vect: move legend code to separate file, author Adam Laza

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@69093 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 8 yıl önce
ebeveyn
işleme
861649e2b2
3 değiştirilmiş dosya ile 84 ekleme ve 82 silme
  1. 75 0
      display/d.vect/legend.c
  2. 5 0
      display/d.vect/local_proto.h
  3. 4 82
      display/d.vect/main.c

+ 75 - 0
display/d.vect/legend.c

@@ -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);
+    }
+}

+ 5 - 0
display/d.vect/local_proto.h

@@ -65,3 +65,8 @@ int display_vert(struct Map_info *, int, LATTR *, double);
 
 /* 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 *);

+ 4 - 82
display/d.vect/main.c

@@ -57,7 +57,6 @@ int main(int argc, char **argv)
     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,9 +64,6 @@ int main(int argc, char **argv)
     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 */
@@ -457,84 +453,10 @@ int main(int argc, char **argv)
 		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