[mapserver-commits] r10261 - in trunk/mapserver: . mapscript/php

svn at osgeo.org svn at osgeo.org
Tue Jun 29 09:08:39 EDT 2010


Author: aboudreault
Date: 2010-06-29 13:08:39 +0000 (Tue, 29 Jun 2010)
New Revision: 10261

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapfile.c
   trunk/mapserver/mapscript/php/style.c
Log:
PHP/MapScript: Fixed updateFromString functions to resolve symbol names (#3273)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2010-06-28 16:01:30 UTC (rev 10260)
+++ trunk/mapserver/HISTORY.TXT	2010-06-29 13:08:39 UTC (rev 10261)
@@ -14,6 +14,8 @@
 Current Version (SVN trunk):
 ----------------------------
 
+- PHP/MapScript: Fixed updateFromString functions to resolve symbol names (#3273)
+
 - PHP/MapScript: ability to use the php clone keyword (#3472)
 
 - Modified mapserver units enum order to fix some problems with external softwares (#3173)

Modified: trunk/mapserver/mapfile.c
===================================================================
--- trunk/mapserver/mapfile.c	2010-06-28 16:01:30 UTC (rev 10260)
+++ trunk/mapserver/mapfile.c	2010-06-29 13:08:39 UTC (rev 10261)
@@ -65,7 +65,7 @@
 static int loadGrid( layerObj *pLayer );
 static int loadStyle(styleObj *style);
 static void writeStyle(FILE* stream, int indent, styleObj *style);
-
+static int msResolveSymbolNames(mapObj *map);
 /*
 ** Symbol to string static arrays needed for writing map files.
 ** Must be kept in sync with enumerations and defines found in mapserver.h.
@@ -2304,8 +2304,13 @@
       break; /* for string loads */
     case(SYMBOL):
       if((symbol = getSymbol(3, MS_NUMBER,MS_STRING,MS_BINDING)) == -1) return(MS_FAILURE);
-      if(symbol == MS_NUMBER)
+      if(symbol == MS_NUMBER) {
+        if (style->symbolname != NULL) {
+          msFree(style->symbolname);
+          style->symbolname = NULL;
+        }
 	style->symbol = (int) msyynumber;
+      }
       else if(symbol == MS_STRING)
       {
         if (style->symbolname != NULL)
@@ -2890,6 +2895,7 @@
 
 int msUpdateClassFromString(classObj *class, char *string, int url_string)
 {
+  int k;
   if(!class || !string) return MS_FAILURE;
 
   msAcquireLock( TLOCK_PARSER );
@@ -2910,6 +2916,29 @@
   msReleaseLock( TLOCK_PARSER );
 
   msyylex_destroy();
+
+  /* step through styles and labels to resolve symbol names */
+  /* class styles */
+  for(k=0; k<class->numstyles; k++) {
+      if(class->styles[k]->symbolname) {
+          if((class->styles[k]->symbol =  msGetSymbolIndex(&(class->layer->map->symbolset), class->styles[k]->symbolname, MS_TRUE)) == -1) {
+              msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class, style %d of layer %s.", "msUpdateClassFromString()", class->styles[k]->symbolname, k, class->layer->name);
+              return MS_FAILURE;
+          }
+      }
+  }
+
+  /* label styles */
+  for(k=0; k<class->label.numstyles; k++) {
+      if(class->label.styles[k]->symbolname) {
+          if((class->label.styles[k]->symbol =  msGetSymbolIndex(&(class->layer->map->symbolset), class->label.styles[k]->symbolname, MS_TRUE)) == -1) {
+              msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class, label style %d of layer %s.", 
+                         "msUpdateClassFromString()", class->label.styles[k]->symbolname, k, class->layer->name);
+              return MS_FAILURE;
+          }
+      }
+  }
+
   return MS_SUCCESS;
 }
 
@@ -3556,6 +3585,8 @@
 
 int msUpdateLayerFromString(layerObj *layer, char *string, int url_string)
 {
+  int j, k;
+
   if(!layer || !string) return MS_FAILURE;
 
   msAcquireLock( TLOCK_PARSER );
@@ -3576,6 +3607,32 @@
   msReleaseLock( TLOCK_PARSER );
 
   msyylex_destroy();
+
+  /* step through classes to resolve symbol names */
+  for(j=0; j<layer->numclasses; j++) {
+
+      /* class styles */
+      for(k=0; k<layer->class[j]->numstyles; k++) {
+          if(layer->class[j]->styles[k]->symbolname) {
+              if((layer->class[j]->styles[k]->symbol =  msGetSymbolIndex(&(layer->map->symbolset), layer->class[j]->styles[k]->symbolname, MS_TRUE)) == -1) {
+                  msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class %d, style %d of layer %s.", "msUpdateLayerFromString()", layer->class[j]->styles[k]->symbolname, j, k, layer->name);
+                  return MS_FAILURE;
+              }
+          }
+      }
+
+      /* label styles */
+      for(k=0; k<layer->class[j]->label.numstyles; k++) {
+          if(layer->class[j]->label.styles[k]->symbolname) {
+              if((layer->class[j]->label.styles[k]->symbol =  msGetSymbolIndex(&(layer->map->symbolset), layer->class[j]->label.styles[k]->symbolname, MS_TRUE)) == -1) {
+                  msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class %d, label style %d of layer %s.", 
+                             "msUpdateLayerFromString()", layer->class[j]->label.styles[k]->symbolname, j, k, layer->name);
+                  return MS_FAILURE;
+              }
+          }
+      }          
+  }
+
   return MS_SUCCESS;
 }
 
@@ -4973,32 +5030,7 @@
 
       if(loadSymbolSet(&(map->symbolset), map) == -1) return MS_FAILURE;
 
-      /* step through layers and classes to resolve symbol names */
-      for(i=0; i<map->numlayers; i++) {
-        for(j=0; j<GET_LAYER(map, i)->numclasses; j++) {
-
-          /* class styles */
-	  for(k=0; k<GET_LAYER(map, i)->class[j]->numstyles; k++) {
-            if(GET_LAYER(map, i)->class[j]->styles[k]->symbolname) {
-              if((GET_LAYER(map, i)->class[j]->styles[k]->symbol =  msGetSymbolIndex(&(map->symbolset), GET_LAYER(map, i)->class[j]->styles[k]->symbolname, MS_TRUE)) == -1) {
-                msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class %d, style %d of layer %s.", "msLoadMap()", GET_LAYER(map, i)->class[j]->styles[k]->symbolname, j, k, GET_LAYER(map, i)->name);
-                return MS_FAILURE;
-              }
-            }
-          }
-
-          /* label styles */
-          for(k=0; k<GET_LAYER(map, i)->class[j]->label.numstyles; k++) {
-            if(GET_LAYER(map, i)->class[j]->label.styles[k]->symbolname) {
-              if((GET_LAYER(map, i)->class[j]->label.styles[k]->symbol =  msGetSymbolIndex(&(map->symbolset), GET_LAYER(map, i)->class[j]->label.styles[k]->symbolname, MS_TRUE)) == -1) {
-                msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class %d, label style %d of layer %s.", 
-                                       "msLoadMap()", GET_LAYER(map, i)->class[j]->label.styles[k]->symbolname, j, k, GET_LAYER(map, i)->name);
-                return MS_FAILURE;
-              }
-            }
-          }          
-        }
-      }
+      if (msResolveSymbolNames(map) == MS_FAILURE) return MS_FAILURE;
       
       /*backwards compatibility symbol to style merging*/
       for(i=0; i<map->numlayers; i++) {
@@ -5245,6 +5277,9 @@
 
   if (mappath != NULL) free(mappath);
   msyylex_destroy();
+
+  if (msResolveSymbolNames(map) == MS_FAILURE) return NULL;
+
   return map;
 }
 
@@ -5760,3 +5795,36 @@
         resultcache->usegetshape = MS_FALSE;
     }
 }
+
+static int msResolveSymbolNames(mapObj* map)
+{
+    int i, j, k;
+    /* step through layers and classes to resolve symbol names */
+    for(i=0; i<map->numlayers; i++) {
+        for(j=0; j<GET_LAYER(map, i)->numclasses; j++) {
+          
+            /* class styles */
+            for(k=0; k<GET_LAYER(map, i)->class[j]->numstyles; k++) {
+                if(GET_LAYER(map, i)->class[j]->styles[k]->symbolname) {
+                    if((GET_LAYER(map, i)->class[j]->styles[k]->symbol =  msGetSymbolIndex(&(map->symbolset), GET_LAYER(map, i)->class[j]->styles[k]->symbolname, MS_TRUE)) == -1) {
+                        msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class %d, style %d of layer %s.", "msLoadMap()", GET_LAYER(map, i)->class[j]->styles[k]->symbolname, j, k, GET_LAYER(map, i)->name);
+                        return MS_FAILURE;
+                    }
+                }
+            }
+
+            /* label styles */
+            for(k=0; k<GET_LAYER(map, i)->class[j]->label.numstyles; k++) {
+                if(GET_LAYER(map, i)->class[j]->label.styles[k]->symbolname) {
+                    if((GET_LAYER(map, i)->class[j]->label.styles[k]->symbol =  msGetSymbolIndex(&(map->symbolset), GET_LAYER(map, i)->class[j]->label.styles[k]->symbolname, MS_TRUE)) == -1) {
+                        msSetError(MS_MISCERR, "Undefined symbol \"%s\" in class %d, label style %d of layer %s.", 
+                                   "msLoadMap()", GET_LAYER(map, i)->class[j]->label.styles[k]->symbolname, j, k, GET_LAYER(map, i)->name);
+                        return MS_FAILURE;
+                    }
+                }
+            }          
+        }
+    }
+
+    return MS_SUCCESS;
+}

Modified: trunk/mapserver/mapscript/php/style.c
===================================================================
--- trunk/mapserver/mapscript/php/style.c	2010-06-28 16:01:30 UTC (rev 10260)
+++ trunk/mapserver/mapscript/php/style.c	2010-06-29 13:08:39 UTC (rev 10261)
@@ -164,11 +164,10 @@
         return;
     }
     PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
-    
+
     php_style = (php_style_object *) zend_object_store_get_object(zobj TSRMLS_CC);
     
     IF_SET_LONG("symbol", php_style->style->symbol, value)
-    else IF_SET_STRING("symbolname", php_style->style->symbolname, value)
     else IF_SET_DOUBLE("size", php_style->style->size, value)
     else IF_SET_DOUBLE("minsize", php_style->style->minsize, value)
     else IF_SET_DOUBLE("maxsize", php_style->style->maxsize, value)
@@ -185,6 +184,11 @@
     else IF_SET_LONG("opacity", php_style->style->opacity, value)
     else if (STRING_EQUAL("symbolname", property))
     {
+        convert_to_string(value);
+        if (php_style->style->symbolname) free(php_style->style->symbolname);    
+        if (Z_STRVAL_P(value))                        
+            php_style->style->symbolname = strdup(Z_STRVAL_P(value));     
+
         /* The parent can be a classObj or a labelCacheMemberObj */
         if (Z_OBJCE_P(php_style->parent.val) == mapscript_ce_class)
         {
@@ -210,9 +214,13 @@
             php_map = (php_map_object *) zend_object_store_get_object(php_labelcachemember->parent.val TSRMLS_CC);
         }
 
-        styleObj_setSymbolByName(php_style->style,
-                                 php_map->map,
-                                 php_style->style->symbolname);
+        if (styleObj_setSymbolByName(php_style->style,
+                                     php_map->map,
+                                     php_style->style->symbolname) == -1)
+        {
+            mapscript_throw_exception("Symbol not found." TSRMLS_CC);
+            return;
+        }
     }
     else if ( (STRING_EQUAL("color", property)) ||
               (STRING_EQUAL("outlinecolor", property)) ||
@@ -235,6 +243,9 @@
     char *snippet;
     long snippet_len;
     int status = MS_FAILURE;
+    zval retval;
+    zval *args[2];
+    zval function_name;
     php_style_object *php_style;
 
     PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
@@ -252,8 +263,22 @@
         mapscript_throw_mapserver_exception("" TSRMLS_CC);
         return;
     }
+    
+    ZVAL_LONG(&retval, status);
 
-    RETURN_LONG(status);
+    /* verify the symbol if needed */
+    if (php_style->style->symbolname) 
+    {
+        MAKE_STD_ZVAL(args[0]);
+        MAKE_STD_ZVAL(args[1]);
+        ZVAL_STRING(args[0], "symbolname", 1);
+        ZVAL_STRING(args[1], php_style->style->symbolname, 1);
+        MAPSCRIPT_CALL_METHOD(zobj, "__set", retval, 2, args);
+        zval_ptr_dtor(&args[0]);
+        zval_ptr_dtor(&args[1]);
+    }
+
+    RETURN_LONG(Z_LVAL(retval));
 }
 /* }}} */
 



More information about the mapserver-commits mailing list