Procházet zdrojové kódy

vlib: store alternative color tables to `vcolr2/mapset/name`

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47867 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa před 13 roky
rodič
revize
4e31098139

+ 4 - 1
include/vect/dig_defines.h

@@ -12,7 +12,6 @@
 #define GV_FATAL_PRINT   1
 #define GV_FATAL_RETURN  2
 
-/*! \brief Vector directory layout, element names */
 /*! \brief Name of vector directory */
 #define GV_DIRECTORY    "vector"	
 /*! \brief Format description, data location (OGR) */
@@ -33,6 +32,10 @@
 #define GV_CIDX_ELEMENT "cidx"
 /*! \brief External format (OGR), feature index */
 #define GV_FIDX_ELEMENT "fidx"
+/*! \brief Color table */
+#define GV_COLR_ELEMENT "colr"
+/*! \brief Name of directory for alternative color tables */
+#define GV_COLR2_DIRECTORY "vcolr2"
 
 /*! \brief Endian check
 

+ 15 - 10
lib/vector/Vlib/color_read.c

@@ -14,6 +14,7 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/vector.h>
+#include <grass/glocale.h>
 
 /*!
   \brief Read color table of vector map
@@ -39,6 +40,7 @@
 int Vect_read_colors(const char *name, const char *mapset,
 		     struct Colors *colors)
 {
+    int ret;
     char buf[GPATH_MAX];
     char xname[GNAME_MAX];
     
@@ -51,15 +53,18 @@ int Vect_read_colors(const char *name, const char *mapset,
     
     name = xname;
 
-    if (strcmp(mapset, G_mapset()) == 0)
-	/* look for the regular color table */
-	sprintf(buf, "vector/%s/colr", name);
-    else	
+    if (strcmp(mapset, G_mapset()) == 0) {
+        /* look for the regular color table */
+	sprintf(buf, "%s/%s/%s", GV_DIRECTORY, name, GV_COLR_ELEMENT);
+        ret = Rast__read_colors(buf, "", mapset, colors);
+    }
+    else {
 	/* look for secondary color table in current mapset */
-	sprintf(buf, "vector/%s/colr2", name);
-    
-    if (Rast__read_colors(buf, "", mapset, colors) >= 0)
-	return 1;
-    
-    return 0;
+	sprintf(buf, "%s/%s/%s", GV_COLR2_DIRECTORY, mapset, name);
+        ret = Rast__read_colors(buf, "", G_mapset(), colors);
+    }
+    if (ret == -2)
+	return 0;
+
+    return ret;
 }

+ 5 - 4
lib/vector/Vlib/color_remove.c

@@ -14,6 +14,7 @@
 #include <string.h>
 
 #include <grass/gis.h>
+#include <grass/vector.h>
 
 /*!
   \brief Remove color table of raster map
@@ -38,12 +39,12 @@ int Vect_remove_colors(const char *name, const char *mapset)
     }
 
     /* get rid of existing colr2, if any */
-    sprintf(element, "vector/%s", name);
-    stat = G_remove(element, "colr2");
+    sprintf(element, "%s/%s", GV_COLR2_DIRECTORY, mapset);
+    stat = G_remove(element, name);
 
     if (strcmp(mapset, G_mapset()) == 0) {
-	sprintf(element, "vector/%s", name);
-	stat = G_remove(element, "colr");
+	sprintf(element, "%s/%s", GV_DIRECTORY, name);
+	stat = G_remove(element, GV_COLR_ELEMENT);
     }
     
     return stat;

+ 11 - 11
lib/vector/Vlib/color_write.c

@@ -59,32 +59,32 @@
 void Vect_write_colors(const char *name, const char *mapset,
 		       struct Colors *colors)
 {
-    char element[GPATH_MAX], *cname;
+    char element[GPATH_MAX];
+    const char *cname;
     char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
     FILE *fd;
-	
+    
     if (G_name_is_fully_qualified(name, xname, xmapset)) {
 	if (strcmp(xmapset, mapset) != 0)
 	    G_fatal_error(_("Qualified name <%s> doesn't match mapset <%s>"),
 			  name, mapset);
 	name = xname;
+	mapset = xmapset;
     }
-
+    
     /*
-      if mapset is current mapset, remove colr2 file (created by pre 3.0 grass)
-      and then write original color table
+      if mapset is current mapset, write original color table
       else write secondary color table
     */
     if (strcmp(mapset, G_mapset()) == 0) {
-	/* get rid of existing colr2, if any */
-	sprintf(element, "vector/%s/colr2", name);
-	G_remove(element, name); 
-	cname = "colr";
+	cname = GV_COLR_ELEMENT;
+	sprintf(element, "%s/%s", GV_DIRECTORY, name);
     }
     else {
-	cname = "colr2";
+	cname = name;
+	sprintf(element, "%s/%s", GV_COLR2_DIRECTORY, mapset);
     }
-    sprintf(element, "vector/%s", name);
+
     if (!(fd = G_fopen_new(element, cname)))
 	G_fatal_error(_("Unable to create <%s> file for map <%s>"),
 		      element, name);

+ 0 - 3
vector/v.colors/main.c

@@ -190,9 +190,6 @@ int main(int argc, char *argv[])
     if (!mapset)
 	G_fatal_error(_("Vector map <%s> not found"), name);
     
-    if (strcmp(mapset, G_mapset()) != 0)
-      G_fatal_error(_("Module currently allows to modify only vector maps from the current mapset"));
-
     stat = -1;
     if (remove) {
 	stat = Vect_remove_colors(name, mapset);